[patch] Skip background scan if bssid is set

2018-04-28 Thread Jesper Wallin
Hi all,

I recently learned that my AP behaves badly and I have packet loss when
the background scan is running.  I had a small chat with stsp@ about it,
asking if there is a way to disable it.  He kindly explained that if I'm
connected to an AP with a weak signal, it will try to find another AP
with better signal and use that one instead.

Sadly, I only have a single AP at home and this doesn't really solve my
problem.  Though, you can also set a desired bssid to use, to force it
to connect to a single AP.  However, the background scan will still run
even if this is set.

Maybe the background scan has other use-cases that I'm not aware of, if
so, I apologize in advance.  The patch below simply check if a bssid is
specified and if so, skip the background scan.


Regards,
Jesper Wallin


Index: ieee80211.c
===
RCS file: /cvs/src/sys/net80211/ieee80211.c,v
retrieving revision 1.68
diff -u -p -r1.68 ieee80211.c
--- ieee80211.c 28 Apr 2018 14:49:07 -  1.68
+++ ieee80211.c 29 Apr 2018 00:55:43 -
@@ -80,6 +80,14 @@ ieee80211_begin_bgscan(struct ifnet *ifp
ic->ic_state != IEEE80211_S_RUN)
return;
 
+   if (ic->ic_flags & IEEE80211_F_DESBSSID) {
+   if (ifp->if_flags & IFF_DEBUG) {
+   printf("%s: skipping background scan (bssid is set)\n",
+   ifp->if_xname);
+   }
+   return;
+   }
+
if (ic->ic_bgscan_start != NULL && ic->ic_bgscan_start(ic) == 0) {
/*
 * Free the nodes table to ensure we get an up-to-date view



typo in pms.c

2018-04-28 Thread Ryan Lennox
Hi,

caught a typo while digging around in here:

Index: src/sys/dev/pckbc/pms.c
===
RCS file: /cvs/src/sys/dev/pckbc/pms.c,v
retrieving revision 1.85
diff -u -p -u -r1.85 pms.c
--- src/sys/dev/pckbc/pms.c 29 Jan 2018 21:54:11 -  1.85
+++ src/sys/dev/pckbc/pms.c 28 Apr 2018 22:13:40 -
@@ -2448,7 +2448,7 @@ pms_proc_elantech_v3(struct pms_softc *s
}
}
 
-   /* Prevent juming cursor if pad isn't touched or reports garbage. */
+   /* Prevent jumping cursor if pad isn't touched or reports garbage. */
if (w == 0 ||
((x == 0 || y == 0 || x == elantech->max_x || y == elantech->max_y)
&& (x != elantech->old_x || y != elantech->old_y))) {



Re: hashinit(): power of 2 fast path

2018-04-28 Thread Mathieu -
Anton Lindqvist wrote:
> Hi,
> If the elements argument passed to hashinit() is a power of 2 there's no
> need to find the closest power of 2 that can fit all elements since
> elements == hashsize will always be true. During boot of a stock amd64
> kernel running inside vmd 80% of the calls to hashinit() includes a
> power of 2 size.
> 
> Comments? OK?


Hi,

Dunno how much a win it is. But anyhow this will blow in hashfree as
hashsize won't be the same.


Mathieu.



> 
> Index: kern/kern_subr.c
> ===
> RCS file: /cvs/src/sys/kern/kern_subr.c,v
> retrieving revision 1.49
> diff -u -p -r1.49 kern_subr.c
> --- kern/kern_subr.c  14 Feb 2017 10:31:15 -  1.49
> +++ kern/kern_subr.c  28 Apr 2018 20:21:40 -
> @@ -163,8 +163,11 @@ hashinit(int elements, int type, int fla
>  
>   if (elements <= 0)
>   panic("hashinit: bad cnt");
> - for (hashsize = 1; hashsize < elements; hashsize <<= 1)
> - continue;
> + if ((elements & (elements - 1)) == 0)
> + hashsize = elements;
> + else
> + for (hashsize = 1; hashsize < elements; hashsize <<= 1)
> + continue;
>   hashtbl = mallocarray(hashsize, sizeof(*hashtbl), type, flags);
>   if (hashtbl == NULL)
>   return NULL;
> 



hashinit(): power of 2 fast path

2018-04-28 Thread Anton Lindqvist
Hi,
If the elements argument passed to hashinit() is a power of 2 there's no
need to find the closest power of 2 that can fit all elements since
elements == hashsize will always be true. During boot of a stock amd64
kernel running inside vmd 80% of the calls to hashinit() includes a
power of 2 size.

Comments? OK?

Index: kern/kern_subr.c
===
RCS file: /cvs/src/sys/kern/kern_subr.c,v
retrieving revision 1.49
diff -u -p -r1.49 kern_subr.c
--- kern/kern_subr.c14 Feb 2017 10:31:15 -  1.49
+++ kern/kern_subr.c28 Apr 2018 20:21:40 -
@@ -163,8 +163,11 @@ hashinit(int elements, int type, int fla
 
if (elements <= 0)
panic("hashinit: bad cnt");
-   for (hashsize = 1; hashsize < elements; hashsize <<= 1)
-   continue;
+   if ((elements & (elements - 1)) == 0)
+   hashsize = elements;
+   else
+   for (hashsize = 1; hashsize < elements; hashsize <<= 1)
+   continue;
hashtbl = mallocarray(hashsize, sizeof(*hashtbl), type, flags);
if (hashtbl == NULL)
return NULL;



Re: [PATCH] mv -P

2018-04-28 Thread Jesper Wallin
Hi,

Adding a -P to your command might of course be easier, but since you
have -P in rm(1) and -v was added recently, won't this do:

mv newfile "$(rm -Pv oldfile)"


Regards
Jesper Wallin



Re: [PATCH] mv -P

2018-04-28 Thread Theo de Raadt
attila  wrote:
> Hi tech@,
> 
> I frequently want to move a file from one place to another and shred
> the original via the rm(1) -P option.  On several occasions I have
> forgotten about wanting to shred the original file when using mv(1)
> instead (out of habit) and ended up losing the ability to do so easily
> because mv(1) unlinks the original in the cross-filesystem case.
> 
> This patch adds a -P option to mv(1) that does the same thing rm -P
> does in all the cases where it would normally just unlink the source
> file.
> 
> Maybe someone else has shared my "d'oh!" moment after typing mv?
> Maybe this isn't worth it and should just be dealt with using a shell
> alias, but to me this feels cleaner.
> 
> Feedback most welcome as always.

over my dead body.

this is about 500 meters below the bar for adding a new option.



switchd(8): ignore packet_out with dstport = OFP_PORT_ANY

2018-04-28 Thread Ayaka Koshibe
On Fri, Apr 20, 2018 at 10:18:34AM -0700, Ayaka Koshibe wrote:
> Hi,
> 
> switchd(8) sends packet_outs with OFP_PORT_ANY as the dstport, causing
> switches receiving them to disconnect due to validation failure of the said
> message. The comments indicate that looping packets should be ignored, which I
> agree is the expected behavior for a controller implementing a learning
> switch.
> 
> This diff stops switchd(8) from processing packet_ins from looping packets,
> causing them to be dropped as the comment suggests.
> 
> OK?
> 
> 
> Thanks,
> Ayaka
>
ping
>  
> Index: ofp13.c
> ===
> RCS file: /cvs/src/usr.sbin/switchd/ofp13.c,v
> retrieving revision 1.43
> diff -u -p -u -r1.43 ofp13.c
> --- ofp13.c   17 Jan 2017 09:21:50 -  1.43
> +++ ofp13.c   18 Apr 2018 07:43:35 -
> @@ -1082,7 +1082,8 @@ ofp13_packet_in(struct switchd *sc, stru
>* silently drop looping packet
>* (don't use OFP_PORT_INPUT here)
>*/
> - dstport = OFP_PORT_ANY;
> + ret = 0;
> + goto done;
>   } else {
>   addflow = 1;
>   }



remove 2 obsolete libraries from Xenocara

2018-04-28 Thread Matthieu Herrb
Hi,

libXfontcache and libXxf86misc are implementing the client part of X
extensions that have been disabled/removed for a while in the X
server. So builing them or linking to them is useless.

The patch below stops building them in xenocara. A few ports where
using libXxf86misc. Rebuilding them without this library just requires
an update to WANTLIB (patch below, too).

To test make sure you build xenocara with an empty /usr/X11R6 or that
you remove all files removed from sets manually.

PS: This also prepares for the switch to xorgproto and xserver 1.20.

oks?

Index: lib/Makefile
===
RCS file: /cvs/OpenBSD/xenocara/lib/Makefile,v
retrieving revision 1.34
diff -u -p -u -r1.34 Makefile
--- lib/Makefile2 Apr 2018 17:06:02 -   1.34
+++ lib/Makefile28 Apr 2018 17:21:29 -
@@ -40,10 +40,10 @@ SUBDIR= freetype fontconfig libxtrans li
libX11  libXext  libXrender libXft libdmx libfontenc \
libFS libICE libSM libXt \
libXmu libXpm libXaw libXfixes libXcomposite \
-   libXdamage libXcursor libXfont2 libXfontcache \
+   libXdamage libXcursor libXfont2  \
libXi libXinerama libxkbfile libxkbui  \
libXrandr libXRes libXScrnSaver \
-   libXtst libXv libXvMC libXxf86dga libXxf86misc libXxf86vm \
+   libXtst libXv libXvMC libXxf86dga libXxf86vm \
libpciaccess pixman
 
 .if ${XENOCARA_BUILD_GL:L} == "yes"
Index: proto/Makefile
===
RCS file: /cvs/OpenBSD/xenocara/proto/Makefile,v
retrieving revision 1.13
diff -u -p -u -r1.13 Makefile
--- proto/Makefile  13 Apr 2014 11:04:26 -  1.13
+++ proto/Makefile  28 Apr 2018 17:21:29 -
@@ -3,11 +3,11 @@
 .include 
 
 SUBDIR= bigreqsproto compositeproto dmxproto damageproto \
-   fixesproto fontcacheproto fontsproto glproto inputproto \
+   fixesproto fontsproto glproto inputproto \
kbproto pmproto xineramaproto presentproto randrproto \
recordproto renderproto resourceproto scrnsaverproto \
videoproto x11proto xcb-proto xcmiscproto xextproto \
-   xf86bigfontproto xf86dgaproto xf86miscproto \
+   xf86bigfontproto xf86dgaproto \
xf86vidmodeproto
 
 .if ${XENOCARA_BUILD_DRI:L} == "yes"
Index: distrib/sets/lists/xbase/md.alpha
===
RCS file: /cvs/OpenBSD/xenocara/distrib/sets/lists/xbase/md.alpha,v
retrieving revision 1.162
diff -u -p -u -r1.162 md.alpha
--- distrib/sets/lists/xbase/md.alpha   17 Feb 2018 02:32:47 -  1.162
+++ distrib/sets/lists/xbase/md.alpha   28 Apr 2018 17:21:29 -
@@ -160,15 +160,6 @@
 ./usr/X11R6/man/man3/XDGASetViewport.3
 ./usr/X11R6/man/man3/XDGASync.3
 ./usr/X11R6/man/man3/XF86DGA.3
-./usr/X11R6/man/man3/XF86Misc.3
-./usr/X11R6/man/man3/XF86MiscGetKbdSettings.3
-./usr/X11R6/man/man3/XF86MiscGetMouseSettings.3
-./usr/X11R6/man/man3/XF86MiscGetSaver.3
-./usr/X11R6/man/man3/XF86MiscQueryExtension.3
-./usr/X11R6/man/man3/XF86MiscQueryVersion.3
-./usr/X11R6/man/man3/XF86MiscSetKbdSettings.3
-./usr/X11R6/man/man3/XF86MiscSetMouseSettings.3
-./usr/X11R6/man/man3/XF86MiscSetSaver.3
 ./usr/X11R6/man/man3/XF86VM.3
 ./usr/X11R6/man/man3/XF86VidModeDeleteModeLine.3
 ./usr/X11R6/man/man3/XF86VidModeGetAllModeLines.3
Index: distrib/sets/lists/xbase/md.amd64
===
RCS file: /cvs/OpenBSD/xenocara/distrib/sets/lists/xbase/md.amd64,v
retrieving revision 1.176
diff -u -p -u -r1.176 md.amd64
--- distrib/sets/lists/xbase/md.amd64   17 Feb 2018 02:32:47 -  1.176
+++ distrib/sets/lists/xbase/md.amd64   28 Apr 2018 17:21:29 -
@@ -332,15 +332,6 @@
 ./usr/X11R6/man/man3/XDGASetViewport.3
 ./usr/X11R6/man/man3/XDGASync.3
 ./usr/X11R6/man/man3/XF86DGA.3
-./usr/X11R6/man/man3/XF86Misc.3
-./usr/X11R6/man/man3/XF86MiscGetKbdSettings.3
-./usr/X11R6/man/man3/XF86MiscGetMouseSettings.3
-./usr/X11R6/man/man3/XF86MiscGetSaver.3
-./usr/X11R6/man/man3/XF86MiscQueryExtension.3
-./usr/X11R6/man/man3/XF86MiscQueryVersion.3
-./usr/X11R6/man/man3/XF86MiscSetKbdSettings.3
-./usr/X11R6/man/man3/XF86MiscSetMouseSettings.3
-./usr/X11R6/man/man3/XF86MiscSetSaver.3
 ./usr/X11R6/man/man3/XF86VM.3
 ./usr/X11R6/man/man3/XF86VidModeDeleteModeLine.3
 ./usr/X11R6/man/man3/XF86VidModeGetAllModeLines.3
Index: distrib/sets/lists/xbase/md.arm64
===
RCS file: /cvs/OpenBSD/xenocara/distrib/sets/lists/xbase/md.arm64,v
retrieving revision 1.7
diff -u -p -u -r1.7 md.arm64
--- distrib/sets/lists/xbase/md.arm64   17 Feb 2018 02:32:47 -  1.7
+++ distrib/sets/lists/xbase/md.arm64   28 Apr 2018 17:21:29 -
@@ -328,15 +328,6 @@
 ./usr/X11R6/man/man3/XDGASetViewport.3
 ./usr/X11R6/man/man3/XDGASync.3
 ./usr/X11R6/man/man3/XF86DGA.3
-./usr/X11R6/man/man3/XF86Misc.3
-./usr/X11R6/man/man3/XF86MiscGetKbdSettings.3

Re: [PATCH] mv -P

2018-04-28 Thread Ingo Schwarze
Hi,

attila wrote on Sat, Apr 28, 2018 at 11:50:17AM -0500:

> I frequently want to move a file from one place to another and shred
> the original via the rm(1) -P option.

I strongly object to adding another turd on top of the useless
rm(1) -P option; it was recently discussed how useless it is,
search the archives.

Adding new non-standard options to standard utilities needs very
strong reasons and is generally frowned upon.  In this case, there
are very strong reasons - to *not* add this option.

Yours,
  Ingo



[PATCH] mv -P

2018-04-28 Thread attila
Hi tech@,

I frequently want to move a file from one place to another and shred
the original via the rm(1) -P option.  On several occasions I have
forgotten about wanting to shred the original file when using mv(1)
instead (out of habit) and ended up losing the ability to do so easily
because mv(1) unlinks the original in the cross-filesystem case.

This patch adds a -P option to mv(1) that does the same thing rm -P
does in all the cases where it would normally just unlink the source
file.

Maybe someone else has shared my "d'oh!" moment after typing mv?
Maybe this isn't worth it and should just be dealt with using a shell
alias, but to me this feels cleaner.

Feedback most welcome as always.

Pax, -A
--
https://haqistan.net/~attila | attila@{stalphonsos.com,haqistan.net}
pgp: 0x62A729CF | C2CE 2487 03AC 4C2F 101D  09C1 4068 D5D5 62A7 29CF

diff --git a/bin/mv/mv.1 b/bin/mv/mv.1
index b269c67..571eb6a 100644
--- a/bin/mv/mv.1
+++ b/bin/mv/mv.1
@@ -41,10 +41,10 @@
 .Nd move files
 .Sh SYNOPSIS
 .Nm mv
-.Op Fl fiv
+.Op Fl fiPv
 .Ar source target
 .Nm mv
-.Op Fl fiv
+.Op Fl fiPv
 .Ar source ... directory
 .Sh DESCRIPTION
 In its first form, the
@@ -103,6 +103,16 @@ The
 option overrides any previous
 .Fl f
 options.
+.It Fl P
+Overwrite regular files before deleting them,
+in the case where the source and destination are on
+different file systems.
+Files are overwritten once with a random pattern.
+Files with multiple links will be unlinked but not overwritten,
+as the with
+.Xr rm 1
+.Fl P
+option.
 .It Fl v
 Display the source and destination after each move.
 .El
diff --git a/bin/mv/mv.c b/bin/mv/mv.c
index cf8e07b..8831925 100644
--- a/bin/mv/mv.c
+++ b/bin/mv/mv.c
@@ -49,9 +49,11 @@
 #include 
 #include 
 
+#define MAXIMUM(a, b)	(((a) > (b)) ? (a) : (b))
+
 extern char *__progname;
 
-int fflg, iflg, vflg;
+int fflg, iflg, vflg, Pflg;
 int stdin_ok;
 
 extern int cpmain(int argc, char **argv);
@@ -60,6 +62,9 @@ extern int rmmain(int argc, char **argv);
 int	mvcopy(char *, char *);
 int	do_move(char *, char *);
 int	fastcopy(char *, char *, struct stat *);
+int	do_unlink(char *, struct stat *);
+int	rm_overwrite(char *, struct stat *);
+int	pass(int, off_t, char *, size_t);
 void	usage(void);
 
 int
@@ -71,7 +76,7 @@ main(int argc, char *argv[])
 	int ch;
 	char path[PATH_MAX];
 
-	while ((ch = getopt(argc, argv, "ifv")) != -1)
+	while ((ch = getopt(argc, argv, "ifvP")) != -1)
 		switch (ch) {
 		case 'i':
 			fflg = 0;
@@ -84,6 +89,9 @@ main(int argc, char *argv[])
 		case 'v':
 			vflg = 1;
 			break;
+		case 'P':
+			Pflg = 1;
+			break;
 		default:
 			usage();
 		}
@@ -244,7 +252,7 @@ do_move(char *from, char *to)
 	 *	current source file...
 	 */
 	if (!lstat(to, )) {
-		if ((S_ISDIR(sb.st_mode)) ? rmdir(to) : unlink(to)) {
+		if ((S_ISDIR(sb.st_mode)) ? rmdir(to) : do_unlink(to, )) {
 			warn("can't remove %s", to);
 			return (1);
 		}
@@ -299,7 +307,7 @@ fastcopy(char *from, char *to, struct stat *sbp)
 		}
 	if (nread < 0) {
 		warn("%s", from);
-err:		if (unlink(to))
+err:		if (do_unlink(to, NULL))
 			warn("%s: remove", to);
 		(void)close(from_fd);
 		(void)close(to_fd);
@@ -341,7 +349,7 @@ err:		if (unlink(to))
 		return (1);
 	}
 
-	if (unlink(from)) {
+	if (do_unlink(from, sbp)) {
 		warn("%s: remove", from);
 		return (1);
 	}
@@ -384,11 +392,99 @@ mvcopy(char *from, char *to)
 	return (0);
 }
 
+int
+do_unlink(char *file, struct stat *sbp)
+{
+	struct stat sb;
+
+	if (sbp == NULL) {
+		if (lstat(file, )) {
+			warn("%s", file);
+			return (1);
+		}
+		sbp = 
+	}
+	if (Pflg && !rm_overwrite(file, sbp))
+		return (1);
+	if (unlink(file)) {
+		return (1);
+	}
+	return (0);
+}
+
+int
+rm_overwrite(char *file, struct stat *sbp)
+{
+	struct stat sb, sb2;
+	struct statfs fsb;
+	size_t bsize;
+	int fd;
+	char *buf = NULL;
+
+	fd = -1;
+	if (sbp == NULL) {
+		if (lstat(file, ))
+			goto err;
+		sbp = 
+	}
+	if (!S_ISREG(sbp->st_mode))
+		return (1);
+	if (sbp->st_nlink > 1) {
+		warnx("%s (inode %llu): not overwritten due to multiple links",
+		file, (unsigned long long)sbp->st_ino);
+		return (0);
+	}
+	if ((fd = open(file, O_WRONLY|O_NONBLOCK|O_NOFOLLOW, 0)) == -1)
+		goto err;
+	if (fstat(fd, ))
+		goto err;
+	if (sb2.st_dev != sbp->st_dev || sb2.st_ino != sbp->st_ino ||
+	!S_ISREG(sb2.st_mode)) {
+		errno = EPERM;
+		goto err;
+	}
+	if (fstatfs(fd, ) == -1)
+		goto err;
+	bsize = MAXIMUM(fsb.f_iosize, 1024U);
+	if ((buf = malloc(bsize)) == NULL)
+		err(1, "%s: malloc", file);
+
+	if (!pass(fd, sbp->st_size, buf, bsize))
+		goto err;
+	if (fsync(fd))
+		goto err;
+	close(fd);
+	free(buf);
+	if (vflg)
+		(void)fprintf(stderr, "# overwrote %s\n", file);
+	return (1);
+
+err:
+	warn("%s", file);
+	close(fd);
+	free(buf);
+	return (0);
+}
+
+int
+pass(int fd, off_t len, char *buf, size_t bsize)
+{
+	size_t wlen;
+
+	for (; len > 0; len -= wlen) {
+		wlen = len < bsize ? len : bsize;
+		arc4random_buf(buf, wlen);
+		if (write(fd, buf, wlen) != wlen)
+			return (0);
+	}
+	return (1);
+}
+
 

Re: new semapahore implementation using atomics and futexes

2018-04-28 Thread Paul Irofti
On Sun, Apr 22, 2018 at 03:34:45PM +0300, Paul Irofti wrote:
> Hi,
> 
> Here is a new semaphore implementation that uses atomic operations,
> where available, and futexes for locking. 
> 
> The reason we need this is to make semaphores safe for asynchronous
> signals.
> 
> 
> All posixsuite tests (semaphore and sigaction) pass with this.
> They do not with our current implementation.  Unfortunately I can not
> get our sem_timedwait regression test to work.
> 
>   regress/lib/libpthread/semaphore/sem_timedwait
> 
> My investigation so far suggests that the current implementation is
> flawed because it does not respect ERESTART and treats EINTR as if it
> would be equivalent to EAGAIN. The POSIX standard and other
> implementations disagree with that: ERESTART should restart the
> semaphore waiting and EINTR should exit the call. The above regression
> test relies on our current EINTR abuse and I think that is why it fails.
> I added a few helpful printfs to that test in my diff.
> 
> I hope future discussions at the Nantes hackathon will clarify this
> issue.
> 
> 
> Otherwise I have been running with this implementation for a couple of
> weeks. LaTeX, octave, chrome, firefox, thunderbird, vim, mutt, vlc,
> mplayer etc. run just fine.
> 
> I would like to get wider testing to see if there are any defects left
> in the current version. 
> 
> 
> I have also added all the changes in a fork on github.
> 
>   https://github.com/bulibuta/openbsd-src/tree/sem_atomicfutex
> 
> 
> Please test and get back to me if you see any issues.
> 
> Thank you,
> Paul

Here is the same diff adapted to what happened in -current this week.
All required bits are now in, so the current diff neatly contains just the
implementation.


diff --git lib/librthread/Makefile lib/librthread/Makefile
index 4c3e127491d..5dfb140290e 100644
--- lib/librthread/Makefile
+++ lib/librthread/Makefile
@@ -30,12 +30,19 @@ SRCS=   rthread.c \
rthread_rwlock.c \
rthread_rwlockattr.c \
rthread_sched.c \
-   rthread_sem.c \
rthread_sig.c \
rthread_stack.c \
rthread_spin_lock.c \
sched_prio.c
 
+# Architectures that implement atomics
+.if ${MACHINE_ARCH} == "amd64" || ${MACHINE_ARCH} == "i386" || \
+${MACHINE_ARCH} == "mips64" || ${MACHINE_ARCH} == "mips64el"
+SRCS+= rthread_sem_atomic.c
+.else
+SRCS+= rthread_sem.c
+.endif
+
 SRCDIR= ${.CURDIR}/../libpthread
 .include "${SRCDIR}/man/Makefile.inc"
 .include 
diff --git lib/librthread/rthread_sem_atomic.c 
lib/librthread/rthread_sem_atomic.c
new file mode 100644
index 000..4fbc6cb8223
--- /dev/null
+++ lib/librthread/rthread_sem_atomic.c
@@ -0,0 +1,420 @@
+/* $OpenBSD$ */
+/*
+ * Copyright (c) 2004,2005,2013 Ted Unangst 
+ * Copyright (c) 2018 Paul Irofti 
+ * All Rights Reserved.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+#include "rthread.h"
+#include "cancel.h"/* in libc/include */
+#include "synch.h"
+
+#define SHARED_IDENT ((void *)-1)
+
+/* SHA256_DIGEST_STRING_LENGTH includes nul */
+/* "/tmp/" + sha256 + ".sem" */
+#define SEM_PATH_SIZE (5 + SHA256_DIGEST_STRING_LENGTH + 4)
+
+/* long enough to be hard to guess */
+#define SEM_RANDOM_NAME_LEN10
+
+/*
+ * Size of memory to be mmap()'ed by named semaphores.
+ * Should be >= SEM_PATH_SIZE and page-aligned.
+ */
+#define SEM_MMAP_SIZE  _thread_pagesize
+
+/*
+ * Internal implementation of semaphores
+ */
+int
+_sem_wait(sem_t sem, int can_eintr, const struct timespec *abstime,
+int *delayed_cancel)
+{
+   int r = 0;
+   int v = sem->value, ov;
+
+   for (;;) {
+   while ((v = sem->value) > 0) {
+   ov = atomic_cas_uint(>value, v, v - 1);
+   if (ov == v)
+   return 0;
+   }
+   if (r)
+   break;
+
+   atomic_inc_int(>waitcount);
+   r = _twait(>value, 0, CLOCK_REALTIME, abstime);
+   /* ignore interruptions other than cancelation */
+   if ((r == ECANCELED && *delayed_cancel 

Re: free all nodes and set linkstate to down when entering the SCAN state for all drivers

2018-04-28 Thread Paul Irofti
On Sat, Apr 28, 2018 at 05:26:19PM +0200, Peter Hessler wrote:
> Some drivers use their own functions to change the link state for a
> non-background scan, so ensure that they set the link state to down, and
> free all nodes.  This is a follow up to stsp@'s ieee80211.c:r1.68.
> 
> (N.B. the atu driver already calls ieee80211_free_allnodes in this case
> statement, but outside of the diff context)
> 
> Tested on iwm(4)
> 
> OK?

OK

> 
> 
> Index: ic/bwfm.c
> ===
> RCS file: /cvs/openbsd/src/sys/dev/ic/bwfm.c,v
> retrieving revision 1.42
> diff -u -p -u -p -r1.42 bwfm.c
> --- ic/bwfm.c 26 Apr 2018 12:50:07 -  1.42
> +++ ic/bwfm.c 28 Apr 2018 15:01:55 -
> @@ -2294,6 +2294,8 @@ bwfm_newstate(struct ieee80211com *ic, e
>   printf("%s: %s -> %s\n", DEVNAME(sc),
>   ieee80211_state_name[ic->ic_state],
>   ieee80211_state_name[nstate]);
> + ieee80211_set_link_state(ic, LINK_STATE_DOWN);
> + ieee80211_free_allnodes(ic, 1);
>   ic->ic_state = nstate;
>   splx(s);
>   return 0;
> Index: ic/pgt.c
> ===
> RCS file: /cvs/openbsd/src/sys/dev/ic/pgt.c,v
> retrieving revision 1.92
> diff -u -p -u -p -r1.92 pgt.c
> --- ic/pgt.c  28 Apr 2018 14:49:07 -  1.92
> +++ ic/pgt.c  28 Apr 2018 15:17:35 -
> @@ -2937,6 +2937,7 @@ pgt_newstate(struct ieee80211com *ic, en
>   ic->ic_mgt_timer = 0;
>   ic->ic_flags &= ~IEEE80211_F_SIBSS;
>   ieee80211_free_allnodes(ic, 1);
> + ieee80211_set_link_state(ic, LINK_STATE_DOWN);
>   break;
>   case IEEE80211_S_SCAN:
>   ic->ic_if.if_timer = 1;
> @@ -2946,6 +2947,7 @@ pgt_newstate(struct ieee80211com *ic, en
>   else
>   ieee80211_free_allnodes(ic, 1);
>  
> + ieee80211_set_link_state(ic, LINK_STATE_DOWN);
>  #ifndef IEEE80211_STA_ONLY
>   /* Just use any old channel; we override it anyway. */
>   if (ic->ic_opmode == IEEE80211_M_HOSTAP)
> Index: pci/if_iwm.c
> ===
> RCS file: /cvs/openbsd/src/sys/dev/pci/if_iwm.c,v
> retrieving revision 1.227
> diff -u -p -u -p -r1.227 if_iwm.c
> --- pci/if_iwm.c  26 Apr 2018 12:50:07 -  1.227
> +++ pci/if_iwm.c  28 Apr 2018 14:42:26 -
> @@ -5501,6 +5501,10 @@ iwm_scan(struct iwm_softc *sc)
>   printf("%s: %s -> %s\n", ifp->if_xname,
>   ieee80211_state_name[ic->ic_state],
>   ieee80211_state_name[IEEE80211_S_SCAN]);
> + if ((sc->sc_flags & IWM_FLAG_BGSCAN) == 0) {
> + ieee80211_set_link_state(ic, LINK_STATE_DOWN);
> + ieee80211_free_allnodes(ic, 1);
> + }
>   ic->ic_state = IEEE80211_S_SCAN;
>   iwm_led_blink_start(sc);
>   wakeup(>ic_state); /* wake iwm_init() */
> Index: pci/if_iwn.c
> ===
> RCS file: /cvs/openbsd/src/sys/dev/pci/if_iwn.c,v
> retrieving revision 1.202
> diff -u -p -u -p -r1.202 if_iwn.c
> --- pci/if_iwn.c  26 Apr 2018 12:50:07 -  1.202
> +++ pci/if_iwn.c  28 Apr 2018 14:59:42 -
> @@ -1808,6 +1808,10 @@ iwn_newstate(struct ieee80211com *ic, en
>   printf("%s: %s -> %s\n", ifp->if_xname,
>   ieee80211_state_name[ic->ic_state],
>   ieee80211_state_name[nstate]);
> + if ((sc->sc_flags & IWN_FLAG_BGSCAN) == 0) {
> + ieee80211_set_link_state(ic, LINK_STATE_DOWN);
> + ieee80211_free_allnodes(ic, 1);
> + }
>   ic->ic_state = nstate;
>   return 0;
>  
> Index: pci/if_wpi.c
> ===
> RCS file: /cvs/openbsd/src/sys/dev/pci/if_wpi.c,v
> retrieving revision 1.143
> diff -u -p -u -p -r1.143 if_wpi.c
> --- pci/if_wpi.c  26 Apr 2018 12:50:07 -  1.143
> +++ pci/if_wpi.c  28 Apr 2018 14:58:59 -
> @@ -1057,6 +1057,8 @@ wpi_newstate(struct ieee80211com *ic, en
>   printf("%s: %s -> %s\n", ifp->if_xname,
>   ieee80211_state_name[ic->ic_state],
>   ieee80211_state_name[nstate]);
> + ieee80211_set_link_state(ic, LINK_STATE_DOWN);
> + ieee80211_free_allnodes(ic, 1);
>   ic->ic_state = nstate;
>   return 0;
>  
> Index: usb/if_atu.c
> ===
> RCS file: /cvs/openbsd/src/sys/dev/usb/if_atu.c,v
> retrieving revision 1.125
> diff -u -p -u -p -r1.125 if_atu.c
> --- usb/if_atu.c  28 Apr 2018 14:49:07 -  1.125
> +++ usb/if_atu.c  28 Apr 2018 15:17:23 -
> @@ -1221,6 +1221,7 @@ 

Re: free all nodes and set linkstate to down when entering the SCAN state for all drivers

2018-04-28 Thread Stefan Sperling
On Sat, Apr 28, 2018 at 05:26:19PM +0200, Peter Hessler wrote:
> Some drivers use their own functions to change the link state for a
> non-background scan, so ensure that they set the link state to down, and
> free all nodes.  This is a follow up to stsp@'s ieee80211.c:r1.68.
> 
> (N.B. the atu driver already calls ieee80211_free_allnodes in this case
> statement, but outside of the diff context)
> 
> Tested on iwm(4)
> 
> OK?
> 

ok

> 
> Index: ic/bwfm.c
> ===
> RCS file: /cvs/openbsd/src/sys/dev/ic/bwfm.c,v
> retrieving revision 1.42
> diff -u -p -u -p -r1.42 bwfm.c
> --- ic/bwfm.c 26 Apr 2018 12:50:07 -  1.42
> +++ ic/bwfm.c 28 Apr 2018 15:01:55 -
> @@ -2294,6 +2294,8 @@ bwfm_newstate(struct ieee80211com *ic, e
>   printf("%s: %s -> %s\n", DEVNAME(sc),
>   ieee80211_state_name[ic->ic_state],
>   ieee80211_state_name[nstate]);
> + ieee80211_set_link_state(ic, LINK_STATE_DOWN);
> + ieee80211_free_allnodes(ic, 1);
>   ic->ic_state = nstate;
>   splx(s);
>   return 0;
> Index: ic/pgt.c
> ===
> RCS file: /cvs/openbsd/src/sys/dev/ic/pgt.c,v
> retrieving revision 1.92
> diff -u -p -u -p -r1.92 pgt.c
> --- ic/pgt.c  28 Apr 2018 14:49:07 -  1.92
> +++ ic/pgt.c  28 Apr 2018 15:17:35 -
> @@ -2937,6 +2937,7 @@ pgt_newstate(struct ieee80211com *ic, en
>   ic->ic_mgt_timer = 0;
>   ic->ic_flags &= ~IEEE80211_F_SIBSS;
>   ieee80211_free_allnodes(ic, 1);
> + ieee80211_set_link_state(ic, LINK_STATE_DOWN);
>   break;
>   case IEEE80211_S_SCAN:
>   ic->ic_if.if_timer = 1;
> @@ -2946,6 +2947,7 @@ pgt_newstate(struct ieee80211com *ic, en
>   else
>   ieee80211_free_allnodes(ic, 1);
>  
> + ieee80211_set_link_state(ic, LINK_STATE_DOWN);
>  #ifndef IEEE80211_STA_ONLY
>   /* Just use any old channel; we override it anyway. */
>   if (ic->ic_opmode == IEEE80211_M_HOSTAP)
> Index: pci/if_iwm.c
> ===
> RCS file: /cvs/openbsd/src/sys/dev/pci/if_iwm.c,v
> retrieving revision 1.227
> diff -u -p -u -p -r1.227 if_iwm.c
> --- pci/if_iwm.c  26 Apr 2018 12:50:07 -  1.227
> +++ pci/if_iwm.c  28 Apr 2018 14:42:26 -
> @@ -5501,6 +5501,10 @@ iwm_scan(struct iwm_softc *sc)
>   printf("%s: %s -> %s\n", ifp->if_xname,
>   ieee80211_state_name[ic->ic_state],
>   ieee80211_state_name[IEEE80211_S_SCAN]);
> + if ((sc->sc_flags & IWM_FLAG_BGSCAN) == 0) {
> + ieee80211_set_link_state(ic, LINK_STATE_DOWN);
> + ieee80211_free_allnodes(ic, 1);
> + }
>   ic->ic_state = IEEE80211_S_SCAN;
>   iwm_led_blink_start(sc);
>   wakeup(>ic_state); /* wake iwm_init() */
> Index: pci/if_iwn.c
> ===
> RCS file: /cvs/openbsd/src/sys/dev/pci/if_iwn.c,v
> retrieving revision 1.202
> diff -u -p -u -p -r1.202 if_iwn.c
> --- pci/if_iwn.c  26 Apr 2018 12:50:07 -  1.202
> +++ pci/if_iwn.c  28 Apr 2018 14:59:42 -
> @@ -1808,6 +1808,10 @@ iwn_newstate(struct ieee80211com *ic, en
>   printf("%s: %s -> %s\n", ifp->if_xname,
>   ieee80211_state_name[ic->ic_state],
>   ieee80211_state_name[nstate]);
> + if ((sc->sc_flags & IWN_FLAG_BGSCAN) == 0) {
> + ieee80211_set_link_state(ic, LINK_STATE_DOWN);
> + ieee80211_free_allnodes(ic, 1);
> + }
>   ic->ic_state = nstate;
>   return 0;
>  
> Index: pci/if_wpi.c
> ===
> RCS file: /cvs/openbsd/src/sys/dev/pci/if_wpi.c,v
> retrieving revision 1.143
> diff -u -p -u -p -r1.143 if_wpi.c
> --- pci/if_wpi.c  26 Apr 2018 12:50:07 -  1.143
> +++ pci/if_wpi.c  28 Apr 2018 14:58:59 -
> @@ -1057,6 +1057,8 @@ wpi_newstate(struct ieee80211com *ic, en
>   printf("%s: %s -> %s\n", ifp->if_xname,
>   ieee80211_state_name[ic->ic_state],
>   ieee80211_state_name[nstate]);
> + ieee80211_set_link_state(ic, LINK_STATE_DOWN);
> + ieee80211_free_allnodes(ic, 1);
>   ic->ic_state = nstate;
>   return 0;
>  
> Index: usb/if_atu.c
> ===
> RCS file: /cvs/openbsd/src/sys/dev/usb/if_atu.c,v
> retrieving revision 1.125
> diff -u -p -u -p -r1.125 if_atu.c
> --- usb/if_atu.c  28 Apr 2018 14:49:07 -  1.125
> +++ usb/if_atu.c  28 Apr 2018 15:17:23 -
> @@ -1221,6 +1221,7 @@ 

Re: fix scan on run(4)

2018-04-28 Thread Paul Irofti
> I cannot reproduce the problem; run(4) scans fine on my -current machine. 

Yes. Sorry about the noise. I was running an older kernel that did not
include yesterday's diff.



free all nodes and set linkstate to down when entering the SCAN state for all drivers

2018-04-28 Thread Peter Hessler
Some drivers use their own functions to change the link state for a
non-background scan, so ensure that they set the link state to down, and
free all nodes.  This is a follow up to stsp@'s ieee80211.c:r1.68.

(N.B. the atu driver already calls ieee80211_free_allnodes in this case
statement, but outside of the diff context)

Tested on iwm(4)

OK?


Index: ic/bwfm.c
===
RCS file: /cvs/openbsd/src/sys/dev/ic/bwfm.c,v
retrieving revision 1.42
diff -u -p -u -p -r1.42 bwfm.c
--- ic/bwfm.c   26 Apr 2018 12:50:07 -  1.42
+++ ic/bwfm.c   28 Apr 2018 15:01:55 -
@@ -2294,6 +2294,8 @@ bwfm_newstate(struct ieee80211com *ic, e
printf("%s: %s -> %s\n", DEVNAME(sc),
ieee80211_state_name[ic->ic_state],
ieee80211_state_name[nstate]);
+   ieee80211_set_link_state(ic, LINK_STATE_DOWN);
+   ieee80211_free_allnodes(ic, 1);
ic->ic_state = nstate;
splx(s);
return 0;
Index: ic/pgt.c
===
RCS file: /cvs/openbsd/src/sys/dev/ic/pgt.c,v
retrieving revision 1.92
diff -u -p -u -p -r1.92 pgt.c
--- ic/pgt.c28 Apr 2018 14:49:07 -  1.92
+++ ic/pgt.c28 Apr 2018 15:17:35 -
@@ -2937,6 +2937,7 @@ pgt_newstate(struct ieee80211com *ic, en
ic->ic_mgt_timer = 0;
ic->ic_flags &= ~IEEE80211_F_SIBSS;
ieee80211_free_allnodes(ic, 1);
+   ieee80211_set_link_state(ic, LINK_STATE_DOWN);
break;
case IEEE80211_S_SCAN:
ic->ic_if.if_timer = 1;
@@ -2946,6 +2947,7 @@ pgt_newstate(struct ieee80211com *ic, en
else
ieee80211_free_allnodes(ic, 1);
 
+   ieee80211_set_link_state(ic, LINK_STATE_DOWN);
 #ifndef IEEE80211_STA_ONLY
/* Just use any old channel; we override it anyway. */
if (ic->ic_opmode == IEEE80211_M_HOSTAP)
Index: pci/if_iwm.c
===
RCS file: /cvs/openbsd/src/sys/dev/pci/if_iwm.c,v
retrieving revision 1.227
diff -u -p -u -p -r1.227 if_iwm.c
--- pci/if_iwm.c26 Apr 2018 12:50:07 -  1.227
+++ pci/if_iwm.c28 Apr 2018 14:42:26 -
@@ -5501,6 +5501,10 @@ iwm_scan(struct iwm_softc *sc)
printf("%s: %s -> %s\n", ifp->if_xname,
ieee80211_state_name[ic->ic_state],
ieee80211_state_name[IEEE80211_S_SCAN]);
+   if ((sc->sc_flags & IWM_FLAG_BGSCAN) == 0) {
+   ieee80211_set_link_state(ic, LINK_STATE_DOWN);
+   ieee80211_free_allnodes(ic, 1);
+   }
ic->ic_state = IEEE80211_S_SCAN;
iwm_led_blink_start(sc);
wakeup(>ic_state); /* wake iwm_init() */
Index: pci/if_iwn.c
===
RCS file: /cvs/openbsd/src/sys/dev/pci/if_iwn.c,v
retrieving revision 1.202
diff -u -p -u -p -r1.202 if_iwn.c
--- pci/if_iwn.c26 Apr 2018 12:50:07 -  1.202
+++ pci/if_iwn.c28 Apr 2018 14:59:42 -
@@ -1808,6 +1808,10 @@ iwn_newstate(struct ieee80211com *ic, en
printf("%s: %s -> %s\n", ifp->if_xname,
ieee80211_state_name[ic->ic_state],
ieee80211_state_name[nstate]);
+   if ((sc->sc_flags & IWN_FLAG_BGSCAN) == 0) {
+   ieee80211_set_link_state(ic, LINK_STATE_DOWN);
+   ieee80211_free_allnodes(ic, 1);
+   }
ic->ic_state = nstate;
return 0;
 
Index: pci/if_wpi.c
===
RCS file: /cvs/openbsd/src/sys/dev/pci/if_wpi.c,v
retrieving revision 1.143
diff -u -p -u -p -r1.143 if_wpi.c
--- pci/if_wpi.c26 Apr 2018 12:50:07 -  1.143
+++ pci/if_wpi.c28 Apr 2018 14:58:59 -
@@ -1057,6 +1057,8 @@ wpi_newstate(struct ieee80211com *ic, en
printf("%s: %s -> %s\n", ifp->if_xname,
ieee80211_state_name[ic->ic_state],
ieee80211_state_name[nstate]);
+   ieee80211_set_link_state(ic, LINK_STATE_DOWN);
+   ieee80211_free_allnodes(ic, 1);
ic->ic_state = nstate;
return 0;
 
Index: usb/if_atu.c
===
RCS file: /cvs/openbsd/src/sys/dev/usb/if_atu.c,v
retrieving revision 1.125
diff -u -p -u -p -r1.125 if_atu.c
--- usb/if_atu.c28 Apr 2018 14:49:07 -  1.125
+++ usb/if_atu.c28 Apr 2018 15:17:23 -
@@ -1221,6 +1221,7 @@ atu_newstate(struct ieee80211com *ic, en
printf("%s: %s -> %s\n", ifp->if_xname,
ieee80211_state_name[ic->ic_state],
 

Re: Faster msdosfs read

2018-04-28 Thread Martin Pieuchot
On 26/04/18(Thu) 23:06, Landry Breuil wrote:
> On Thu, Apr 26, 2018 at 10:01:25PM +0200, Martin Pieuchot wrote:
> > This is the 4th attempt to implement clustering for msdosfs.  See [0]
> > for the previous story.
> > 
> > This version implements the strict necessary to read a maximum of 64k
> > per read.  Unlike the previous version we no longer mix cluster and
> > block numbers.
> > 
> > This speeds up msdosfs reads significantly.  Regress tests are passing.
> > 
> > I'd appreciate more tests and reviews.
> 
> Well, i see a 2.5x dropout in perfs.. rsyncing a 100mb dir from the same
> usb key:
> 
> sd1 at scsibus4 targ 1 lun 0:  SCSI2 
> 0/direct removable serial.09511624F0417921125B
> sd1: 3689MB, 512 bytes/sector, 728 sectors
> 
> without the diff:
> sent 101,634,811 bytes  received 153 bytes  2,540,870.35 bytes/sec
> 
> with the diff:
> sent 101,634,811 bytes  received 153 bytes  936,727.78 bytes/sec
> sent 101,634,811 bytes  received 153 bytes  928,173.19 bytes/sec
> 
> To be analysed ...

Thanks to landry I now understand why we cannot keep using "block numbers"
as logical value to index buffers.

The VFS clustering code assume that the next logical block number correspond
to the next block on disk.  In the case of FAT it is true for cluster.

So I believe we should commit the diff below.

Index: msdosfs/denode.h
===
RCS file: /cvs/src/sys/msdosfs/denode.h,v
retrieving revision 1.32
diff -u -p -r1.32 denode.h
--- msdosfs/denode.h13 Jun 2017 18:13:18 -  1.32
+++ msdosfs/denode.h28 Apr 2018 14:47:10 -
@@ -142,7 +142,6 @@ struct denode {
struct vnode *de_devvp; /* vnode of blk dev we live on */
uint32_t de_flag;   /* flag bits */
dev_t de_dev;   /* device where direntry lives */
-   daddr_t de_lastr;
uint32_t de_dirclust;   /* cluster of the directory file containing 
this entry */
uint32_t de_diroffset;  /* offset of this entry in the directory 
cluster */
uint32_t de_fndoffset;  /* offset of found dir entry */
Index: msdosfs/msdosfs_fat.c
===
RCS file: /cvs/src/sys/msdosfs/msdosfs_fat.c,v
retrieving revision 1.31
diff -u -p -r1.31 msdosfs_fat.c
--- msdosfs/msdosfs_fat.c   30 Dec 2017 20:47:00 -  1.31
+++ msdosfs/msdosfs_fat.c   28 Apr 2018 14:47:10 -
@@ -1020,14 +1020,12 @@ extendfile(struct denode *dep, uint32_t 
bp = getblk(pmp->pm_devvp, cntobn(pmp, 
cn++),
pmp->pm_bpcluster, 0, 0);
else {
-   bp = getblk(DETOV(dep), de_cn2bn(pmp, 
frcn++),
+   bp = getblk(DETOV(dep), frcn++,
pmp->pm_bpcluster, 0, 0);
/*
 * Do the bmap now, as in msdosfs_write
 */
-   if (pcbmap(dep,
-   de_bn2cn(pmp, bp->b_lblkno),
-   >b_blkno, 0, 0))
+   if (pcbmap(dep, bp->b_lblkno, 
>b_blkno, 0, 0))
bp->b_blkno = -1;
if (bp->b_blkno == -1)
panic("extendfile: pcbmap");
Index: msdosfs/msdosfs_vnops.c
===
RCS file: /cvs/src/sys/msdosfs/msdosfs_vnops.c,v
retrieving revision 1.118
diff -u -p -r1.118 msdosfs_vnops.c
--- msdosfs/msdosfs_vnops.c 28 Apr 2018 03:13:05 -  1.118
+++ msdosfs/msdosfs_vnops.c 28 Apr 2018 14:47:10 -
@@ -78,13 +78,13 @@
 
 static uint32_t fileidhash(uint64_t);
 
+int msdosfs_bmaparray(struct vnode *, daddr_t, daddr_t *, int *);
 int msdosfs_kqfilter(void *);
 int filt_msdosfsread(struct knote *, long);
 int filt_msdosfswrite(struct knote *, long);
 int filt_msdosfsvnode(struct knote *, long);
 void filt_msdosfsdetach(struct knote *);
 
-
 /*
  * Some general notes:
  *
@@ -510,18 +510,14 @@ int
 msdosfs_read(void *v)
 {
struct vop_read_args *ap = v;
-   int error = 0;
-   uint32_t diff;
-   int blsize;
-   int isadir;
-   uint32_t n;
-   long on;
-   daddr_t lbn, rablock, rablkno;
-   struct buf *bp;
struct vnode *vp = ap->a_vp;
struct denode *dep = VTODE(vp);
struct msdosfsmount *pmp = dep->de_pmp;
struct uio *uio = ap->a_uio;
+   int isadir, error = 0;
+   uint32_t n, diff, size, on;
+   struct buf *bp;
+   daddr_t cn, bn;
 
/*
 * If they didn't ask for any data, then we are done.
@@ -536,7 +532,8 @@ 

Re: interface queue transmit mitigation (again)

2018-04-28 Thread Hrvoje Popovski
On 28.3.2018. 11:42, Hrvoje Popovski wrote:
> On 28.3.2018. 3:28, David Gwynne wrote:
>> On Thu, Mar 15, 2018 at 03:25:46PM +0100, Martin Pieuchot wrote:
>>> On 14/03/18(Wed) 13:00, David Gwynne wrote:
 this adds transmit mitigation back to the tree.

 it is basically the same diff as last time. the big difference this
 time is that all the tunnel drivers all defer ip_output calls, which
 avoids having to play games with NET_LOCK in the ifq transmit paths.
>>> Comments inline.
>>>
 +  if (ifq_len(ifq) >= min(4, ifq->ifq_maxlen)) {
>>> Why 4?  DragonFly recently bumped `ifsq_stage_cntmax' to 16.  Did you
>>> try other values?  They also have an XXX comment that this value should
>>> be per-interface.  Why?
>> their default was 4, and they'd done some research on it. if they
>> moved to 16 there would be a reason for it.
> Hi all,
> 
> with this diff i'm getting 1.43Mpps on
> 12 x Intel(R) Xeon(R) CPU E5-2620 v2 @ 2.10GHz, 2400.01 MHz
> 
> with plain kernel i'm getting 1.12Mpps and with older diff's i was
> getting 1.31Mpps ...
> 
> if i execute ifconfig ix0 down while generating traffic over everything stop


I've tested this diff with today's tree and i can't repeat problem with
or without -fretpoline diff.



Re: fix scan on run(4)

2018-04-28 Thread Stefan Sperling
On Sat, Apr 28, 2018 at 02:38:43PM +0300, Paul Irofti wrote:
> Hi,
> 
> Apparently we need to increase the scan count everytime, else we get no
> nodes in the list.
> 
> Found the hardway on mpi's run(4).
> 
> Is there any device that still needs that check?
> 
> Paul

This diff cannot be right since it deletes the call to ieee80211_next_mode().

I cannot reproduce the problem; run(4) scans fine on my -current machine. 

> diff --git sys/net80211/ieee80211_node.c sys/net80211/ieee80211_node.c
> index 70d6419e619..e10d1cab81d 100644
> --- sys/net80211/ieee80211_node.c
> +++ sys/net80211/ieee80211_node.c
> @@ -729,9 +729,7 @@ ieee80211_end_scan(struct ifnet *ifp)
>* current scan results to userspace regardless of mode.
>* This will loop forever except for user-initiated scans.
>*/
> - if (ieee80211_next_mode(ifp) == IEEE80211_MODE_AUTO ||
> - (ic->ic_caps & IEEE80211_C_SCANALLBAND))
> - ic->ic_scan_count++;
> + ic->ic_scan_count++;
>  
>   /*
>* Reset the list of channels to scan and start again.



fix scan on run(4)

2018-04-28 Thread Paul Irofti
Hi,

Apparently we need to increase the scan count everytime, else we get no
nodes in the list.

Found the hardway on mpi's run(4).

Is there any device that still needs that check?

Paul

diff --git sys/net80211/ieee80211_node.c sys/net80211/ieee80211_node.c
index 70d6419e619..e10d1cab81d 100644
--- sys/net80211/ieee80211_node.c
+++ sys/net80211/ieee80211_node.c
@@ -729,9 +729,7 @@ ieee80211_end_scan(struct ifnet *ifp)
 * current scan results to userspace regardless of mode.
 * This will loop forever except for user-initiated scans.
 */
-   if (ieee80211_next_mode(ifp) == IEEE80211_MODE_AUTO ||
-   (ic->ic_caps & IEEE80211_C_SCANALLBAND))
-   ic->ic_scan_count++;
+   ic->ic_scan_count++;
 
/*
 * Reset the list of channels to scan and start again.



Re: Fail early in USB

2018-04-28 Thread Paul Irofti
On Sat, Apr 28, 2018 at 10:33:55AM +0200, Martin Pieuchot wrote:
> If USB transfers aren't completed in order, the stack cannot recover.
> 
> So don't try to continue when this happen and make it clear what the
> problem is.  Currently the kernel panic in many different ways or
> worse enters an infinite loop sometimes after that happened.
> 
> ok?

OK

> 
> Index: usbdi.c
> ===
> RCS file: /cvs/src/sys/dev/usb/usbdi.c,v
> retrieving revision 1.97
> diff -u -p -r1.97 usbdi.c
> --- usbdi.c   3 Feb 2018 13:37:37 -   1.97
> +++ usbdi.c   28 Apr 2018 08:18:18 -
> @@ -769,13 +769,11 @@ usb_transfer_complete(struct usbd_xfer *
>  
>   if (!pipe->repeat) {
>   /* Remove request from queue. */
> + KASSERT(xfer == SIMPLEQ_FIRST(>queue));
> + SIMPLEQ_REMOVE_HEAD(>queue, next);
>  #ifdef DIAGNOSTIC
> - if (xfer != SIMPLEQ_FIRST(>queue))
> - printf("usb_transfer_complete: bad dequeue %p != %p\n",
> - xfer, SIMPLEQ_FIRST(>queue));
>   xfer->busy_free = XFER_FREE;
>  #endif
> - SIMPLEQ_REMOVE_HEAD(>queue, next);
>   }
>   DPRINTFN(5,("usb_transfer_complete: repeat=%d new head=%p\n",
>   pipe->repeat, SIMPLEQ_FIRST(>queue)));



Fail early in USB

2018-04-28 Thread Martin Pieuchot
If USB transfers aren't completed in order, the stack cannot recover.

So don't try to continue when this happen and make it clear what the
problem is.  Currently the kernel panic in many different ways or
worse enters an infinite loop sometimes after that happened.

ok?

Index: usbdi.c
===
RCS file: /cvs/src/sys/dev/usb/usbdi.c,v
retrieving revision 1.97
diff -u -p -r1.97 usbdi.c
--- usbdi.c 3 Feb 2018 13:37:37 -   1.97
+++ usbdi.c 28 Apr 2018 08:18:18 -
@@ -769,13 +769,11 @@ usb_transfer_complete(struct usbd_xfer *
 
if (!pipe->repeat) {
/* Remove request from queue. */
+   KASSERT(xfer == SIMPLEQ_FIRST(>queue));
+   SIMPLEQ_REMOVE_HEAD(>queue, next);
 #ifdef DIAGNOSTIC
-   if (xfer != SIMPLEQ_FIRST(>queue))
-   printf("usb_transfer_complete: bad dequeue %p != %p\n",
-   xfer, SIMPLEQ_FIRST(>queue));
xfer->busy_free = XFER_FREE;
 #endif
-   SIMPLEQ_REMOVE_HEAD(>queue, next);
}
DPRINTFN(5,("usb_transfer_complete: repeat=%d new head=%p\n",
pipe->repeat, SIMPLEQ_FIRST(>queue)));