arm64 miniroot and ramdisk hooks for raspberry pi 3

2017-02-11 Thread Jonathan Gray
Unlike the TI sitara/OMAP boot rom the raspberry pi boot rom
will fail to read FAT12, the filesystem must be FAT16 or FAT32.

These changes require the raspberrypi-firmware port sent to ports@
to build release along with u-boot-aarch64.

Index: distrib/arm64/miniroot/Makefile
===
RCS file: /cvs/src/distrib/arm64/miniroot/Makefile,v
retrieving revision 1.1
diff -u -p -r1.1 Makefile
--- distrib/arm64/miniroot/Makefile 11 Feb 2017 06:36:03 -  1.1
+++ distrib/arm64/miniroot/Makefile 12 Feb 2017 04:55:01 -
@@ -23,11 +23,19 @@ FFSSTART!=  expr ${MSDOSSTART} + ${MSDOSS
 FS?=   msdos
 PART_ID?=C
 
-NEWFS_ARGS_msdos=-L boot
+NEWFS_ARGS_msdos=-L boot -c1 -F16
 MOUNT_ARGS_msdos=-o-l
 
 PDTB=  /usr/local/share/dtb/arm64
 PUBOOT=/usr/local/share/u-boot
+PRPI=  /usr/local/share/raspberrypi-firmware/boot/
+
+PIFILES=\
+   bootcode.bin \
+   start.elf \
+   fixup.dat \
+   bcm2710-rpi-3-b.dtb \
+   bcm2710-rpi-cm3.dtb
 
 cleandir: clean
 clean:
@@ -49,8 +57,13 @@ do_files:
ln ${MOUNT_POINT}/bsd.rd ${MOUNT_POINT}/bsd
-umount ${MOUNT_POINT}
mount ${MOUNT_ARGS_msdos} ${VND_IDEV} ${MOUNT_POINT}
+.for FILE in ${PIFILES}
+   cp ${PRPI}/${FILE} ${MOUNT_POINT}/
+.endfor
+   cp ${PUBOOT}/rpi_3/u-boot.bin ${MOUNT_POINT}/
mkdir -p ${MOUNT_POINT}/efi/boot
cp /usr/mdec/BOOTAA64.EFI ${MOUNT_POINT}/efi/boot/bootaa64.efi
+   echo 
'arm_control=0x200\nenable_uart=1\ndevice_tree_address=0x100\nkernel=u-boot.bin'
 > ${MOUNT_POINT}/config.txt
 
 rd_setup:
dd if=/dev/zero of=${IMAGE} bs=512 count=${NBLKS}
Index: distrib/arm64/ramdisk/Makefile
===
RCS file: /cvs/src/distrib/arm64/ramdisk/Makefile,v
retrieving revision 1.1
diff -u -p -r1.1 Makefile
--- distrib/arm64/ramdisk/Makefile  23 Jan 2017 02:24:00 -  1.1
+++ distrib/arm64/ramdisk/Makefile  11 Feb 2017 07:16:42 -
@@ -17,6 +17,9 @@ MTREE=${UTILS}/mtree.conf
 DISKTYPE=  rdroot
 MAKEFSARGS_RD= -o disklabel=${DISKTYPE},minfree=0,density=4096
 
+DIRS=\
+   rpi
+
 .ifndef DESTDIR
 all ${IMAGE}:
@echo setenv DESTDIR before making a ramdisk!
@@ -39,6 +42,9 @@ ${BSD_RD}: ${IMAGE} bsd rdsetroot
 ${IMAGE}: ${CBIN}
rm -rf $@.d
install -d -o root -g wheel $@.d
+.for DIR in ${DIRS}
+   mkdir -p $@.d/usr/mdec/${DIR}
+.endfor
mtree -def ${MTREE} -p $@.d -u
TOPDIR=${TOP} CURDIR=${.CURDIR} OBJDIR=${.OBJDIR} REV=${REV} \
TARGDIR=$@.d UTILS=${UTILS} RELEASEDIR=${RELEASEDIR} \
Index: distrib/arm64/ramdisk/install.md
===
RCS file: /cvs/src/distrib/arm64/ramdisk/install.md,v
retrieving revision 1.1
diff -u -p -r1.1 install.md
--- distrib/arm64/ramdisk/install.md23 Jan 2017 02:24:00 -  1.1
+++ distrib/arm64/ramdisk/install.md12 Feb 2017 02:58:37 -
@@ -39,12 +39,23 @@ NEWFSARGS_msdos="-F 16 -L boot"
 MOUNT_ARGS_msdos="-o-l"
 
 md_installboot() {
-   local _disk=/dev/$1
+   local _disk=/dev/$1 _mdec _plat
 
# Mount MSDOS partition, extract U-Boot and copy UEFI boot program
mount ${MOUNT_ARGS_msdos} ${_disk}i /mnt/mnt
mkdir -p /mnt/mnt/efi/boot
cp /mnt/usr/mdec/BOOTAA64.EFI /mnt/mnt/efi/boot/bootaa64.efi
+
+   _plat=rpi
+   _mdec=/usr/mdec/$_plat
+
+   cp $_mdec/{bootcode.bin,start.elf,fixup.dat,*.dtb} /mnt/mnt/
+   cat > /mnt/mnt/config.txt<<-__EOT
+   arm_control=0x200
+   enable_uart=1
+   device_tree_address=0x100
+   kernel=u-boot.bin
+   __EOT
 }
 
 md_prep_fdisk() {
Index: distrib/arm64/ramdisk/list
===
RCS file: /cvs/src/distrib/arm64/ramdisk/list,v
retrieving revision 1.1
diff -u -p -r1.1 list
--- distrib/arm64/ramdisk/list  23 Jan 2017 02:24:00 -  1.1
+++ distrib/arm64/ramdisk/list  11 Feb 2017 07:16:42 -
@@ -116,4 +116,11 @@ SYMLINKinstall.sub 
autoinstall
 SYMLINKinstall.sub install
 SYMLINKinstall.sub upgrade
 
+COPY   /usr/local/share/raspberrypi-firmware/boot/bcm2710-rpi-3-b.dtb 
usr/mdec/rpi/bcm2710-rpi-3-b.dtb
+COPY   /usr/local/share/raspberrypi-firmware/boot/bcm2710-rpi-cm3.dtb 
usr/mdec/rpi/bcm2710-rpi-cm3.dtb
+COPY   /usr/local/share/raspberrypi-firmware/boot/bootcode.bin 
usr/mdec/rpi/bootcode.bin
+COPY   /usr/local/share/raspberrypi-firmware/boot/start.elf 
usr/mdec/rpi/start.elf
+COPY   /usr/local/share/raspberrypi-firmware/boot/fixup.dat 
usr/mdec/rpi/fixup.dat
+COPY   /usr/local/share/u-boot/rpi_3/u-boot.bin usr/mdec/rpi/u-boot.bin
+
 TZ



Re: clang and -Werror vs -Wpointer-sign

2017-02-11 Thread Jonathan Gray
On Wed, Feb 01, 2017 at 10:09:14PM +1100, Jonathan Gray wrote:
> On Mon, Jan 30, 2017 at 07:28:03PM +0100, Stefan Kempf wrote:
> > Jonathan Gray wrote:
> > > Base gcc4 changes the defaults to set -Wno-pointer-sign.
> > > Base clang does not, I'm not sure where in the llvm code to do so.
> > > Base gcc3 does not handle -Wno-pointer-sign.
> >  
> > I think this should turn off -Wpointer-sign off by default.
> > Passing -Wpointer-sign on the command line enables it.
> > Not suitable for upstreaming though.
> 
> Thanks, your patch seems to be against the older version of llvm
> but this works as expected with 4.0 rc1 in tree on arm64.
> 
> ok jsg@

Can we get this in?  Trying to reduce Ms required to build arm64.

> 
> > 
> > Index: gnu/llvm/tools/clang//include/clang/Basic/DiagnosticSemaKinds.td
> > ===
> > RCS file: 
> > /cvs/src/gnu/llvm/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td,v
> > retrieving revision 1.1.1.2
> > diff -u -p -r1.1.1.2 DiagnosticSemaKinds.td
> > --- gnu/llvm/tools/clang//include/clang/Basic/DiagnosticSemaKinds.td
> > 14 Jan 2017 19:55:48 -  1.1.1.2
> > +++ gnu/llvm/tools/clang//include/clang/Basic/DiagnosticSemaKinds.td
> > 30 Jan 2017 18:22:22 -
> > @@ -6332,7 +6332,7 @@ def ext_typecheck_convert_incompatible_p
> >"sending to parameter of different type}0,1"
> >"|%diff{casting $ to type $|casting between types}0,1}2"
> >" converts between pointers to integer types with different sign">,
> > -  InGroup>;
> > +  InGroup>, DefaultIgnore;
> >  def ext_typecheck_convert_incompatible_pointer : ExtWarn<
> >"incompatible pointer types "
> >"%select{%diff{assigning to $ from $|assigning to different types}0,1"
> >  
> > > Below is a patch to add -Wno-pointer-sign to places that use use
> > > -Werror and trigger -Wpointer-sign warnings which breaks the build
> > > when building with clang.  Based on an earlier patch from patrick@
> > > 
> > > Though really the default gcc4 and clang behaviour should be the
> > > same one way or the other.
> > >
> > > Index: lib/libcrypto/Makefile
> > > ===
> > > RCS file: /cvs/src/lib/libcrypto/Makefile,v
> > > retrieving revision 1.14
> > > diff -u -p -r1.14 Makefile
> > > --- lib/libcrypto/Makefile21 Jan 2017 09:38:58 -  1.14
> > > +++ lib/libcrypto/Makefile29 Jan 2017 05:10:50 -
> > > @@ -14,6 +14,9 @@ CLEANFILES=${PC_FILES} ${VERSION_SCRIPT}
> > >  LCRYPTO_SRC= ${.CURDIR}
> > >  
> > >  CFLAGS+= -Wall -Wundef -Werror
> > > +.if ${COMPILER_VERSION:L} != "gcc3"
> > > +CFLAGS+= -Wno-pointer-sign
> > > +.endif
> > >  
> > >  .if !defined(NOPIC)
> > >  CFLAGS+= -DDSO_DLFCN -DHAVE_DLFCN_H -DHAVE_FUNOPEN
> > > Index: lib/librthread/Makefile
> > > ===
> > > RCS file: /cvs/src/lib/librthread/Makefile,v
> > > retrieving revision 1.43
> > > diff -u -p -r1.43 Makefile
> > > --- lib/librthread/Makefile   1 Jun 2016 04:34:18 -   1.43
> > > +++ lib/librthread/Makefile   29 Jan 2017 05:27:29 -
> > > @@ -1,11 +1,16 @@
> > >  #$OpenBSD: Makefile,v 1.43 2016/06/01 04:34:18 tedu Exp $
> > >  
> > > +.include 
> > > +
> > >  LIB=pthread
> > >  LIBCSRCDIR=  ${.CURDIR}/../libc
> > >  
> > >  CFLAGS+=-Wall -g -Werror -Wshadow
> > >  CFLAGS+=-Werror-implicit-function-declaration
> > >  CFLAGS+=-Wsign-compare
> > > +.if ${COMPILER_VERSION:L} != "gcc3"
> > > +CFLAGS+= -Wno-pointer-sign
> > > +.endif
> > >  CFLAGS+=-I${.CURDIR} -include namespace.h \
> > >   -I${LIBCSRCDIR}/arch/${MACHINE_CPU} -I${LIBCSRCDIR}/include
> > >  CDIAGFLAGS=
> > > Index: lib/libtls/Makefile
> > > ===
> > > RCS file: /cvs/src/lib/libtls/Makefile,v
> > > retrieving revision 1.30
> > > diff -u -p -r1.30 Makefile
> > > --- lib/libtls/Makefile   25 Jan 2017 23:53:18 -  1.30
> > > +++ lib/libtls/Makefile   29 Jan 2017 05:32:43 -
> > > @@ -6,6 +6,9 @@ SUBDIR=   man
> > >  .endif
> > >  
> > >  CFLAGS+= -Wall -Werror -Wimplicit
> > > +.if ${COMPILER_VERSION:L} != "gcc3"
> > > +CFLAGS+= -Wno-pointer-sign
> > > +.endif
> > >  CFLAGS+= -DLIBRESSL_INTERNAL
> > >  
> > >  CLEANFILES= ${VERSION_SCRIPT}
> > > Index: usr.sbin/ocspcheck/Makefile
> > > ===
> > > RCS file: /cvs/src/usr.sbin/ocspcheck/Makefile,v
> > > retrieving revision 1.2
> > > diff -u -p -r1.2 Makefile
> > > --- usr.sbin/ocspcheck/Makefile   24 Jan 2017 09:25:27 -  1.2
> > > +++ usr.sbin/ocspcheck/Makefile   29 Jan 2017 05:27:10 -
> > > @@ -1,5 +1,7 @@
> > >  #$OpenBSD: Makefile,v 1.2 2017/01/24 09:25:27 deraadt Exp $
> > >  
> > > +.include 
> > > +
> > >  PROG=ocspcheck
> > >  MAN= ocspcheck.8
> > >  
> > > @@ -15,6 +17,9 @@ CFLAGS+= -Wshadow
> > >  CFLAGS+= -Wtrigraphs
> > >  CFLAG

arm/simplebus: externalize simplebus_attach_node

2017-02-11 Thread Ian Sutton
Currently, we do not have a way to iterate over child FDT nodes, which
is a problem when you have a devices like the USB system on the am335x
(Beaglebone Black):

https://uglyman.kremlin.cc/gitweb/gitweb.cgi?p=bbb-usb.git;a=blob;f=misc/fdt/am335x-boneblack.dts;h=8799dc1d171961d3cd9a941131a82a15bbe445d7;hb=HEAD#l1489

This patch externalizes simplebus_attach_node which probes for drivers
to attach to individual nodes, allowing drivers matching parent nodes to
iterate over their children and call this function on each child. It
works.

For a driver matching parent node property compatible="ti,am33xx-usb"
and another driver matching child node property
compatible="ti,musb-am33xx", we do the following in the parent node
driver's _attach:

155: for (node = OF_child(faa->fa_node); node > 0; node = OF_peer(node))
156: simplebus_attach_node(parent, node);

and get:

amusbss0 at simplebus0: rev 0.13
ammusb0 at simplebus0: rev 0.0  
ammusb1 at simplebus0: rev 0.0
panic: welcome to openbsd 

This is needed for a USB OTG driver for the am335x in the works. 

Ian

Index: simplebusvar.h
===
RCS file: /cvs/src/sys/arch/arm/simplebus/simplebusvar.h,v
retrieving revision 1.1
diff -u -p -r1.1 simplebusvar.h
--- simplebusvar.h  21 Oct 2016 20:09:49 -  1.1
+++ simplebusvar.h  12 Feb 2017 01:27:21 -
@@ -31,3 +31,4 @@ struct simplebus_softc {
 };
 
 extern void simplebus_attach(struct device *, struct device *, void *);
+extern void simplebus_attach_node(struct device *, int);




Re: Implement fork1_to_pid(). It's fork1(), but with pid as argument

2017-02-11 Thread Ossi Herrala
On Sun, Feb 05, 2017 at 04:51:50PM -0800, Philip Guenther wrote:
> On Sun, 5 Feb 2017, Ossi Herrala wrote:
> > init(8) is wanted to have process ID 1. It's also the only process which
> > is assigned non-random PID (well, there's also swapper as PID 0).
> >
> > This patch renames fork1() to fork1_to_pid() and introduces new argument
> > "pid" which can be used to select PID for new process. When pid is 0,
> > random PID is assigned. fork1() is then wrapper to fork1_to_pid() with
> > pid argument being 0. No functional change in fork1().
>
> I wouldn't have a problem with this diff...except it adds a *ninth*
> argument to a function.  fork1() is already really bad with eight
> arguments: we need to break up its uses and refactor it to be less
> confusing and overloaded and not add Yet Another Argument With Magic
> Value.
>

After couple of private mails with guenther@ we came up with the
following patch.

Introduce new flag FORK_PID1 for fork1(9).

This flag is special and only for forking init(8) which wants to be
PID 1.

With this flag in place, it's possible to remove global randompid
variable which was used to control if allocpid() returns random PIDs
or PID 1 for init(8). Now allocpid() can also be simplified.


---
 sys/kern/init_main.c |  6 ++
 sys/kern/kern_fork.c | 22 +-
 sys/sys/proc.h   |  2 +-
 3 files changed, 12 insertions(+), 18 deletions(-)

diff --git a/sys/kern/init_main.c b/sys/kern/init_main.c
index e21a8306854..7324727b415 100644
--- a/sys/kern/init_main.c
+++ b/sys/kern/init_main.c
@@ -437,14 +437,12 @@ main(void *framep)
{
struct proc *initproc;

-   if (fork1(p, FORK_FORK, NULL, 0, start_init, NULL, NULL,
-   &initproc))
+   if (fork1(p, FORK_FORK|FORK_PID1, NULL, 0, start_init, NULL,
+   NULL, &initproc))
panic("fork init");
initprocess = initproc->p_p;
}

-   randompid = 1;
-
/*
 * Create any kernel threads whose creation was deferred because
 * initprocess had not yet been created.
diff --git a/sys/kern/kern_fork.c b/sys/kern/kern_fork.c
index 3ff2085f732..5ed6251d390 100644
--- a/sys/kern/kern_fork.c
+++ b/sys/kern/kern_fork.c
@@ -71,7 +71,6 @@

 intnprocesses = 1; /* process 0 */
 intnthreads = 1;   /* proc 0 */
-intrandompid;  /* when set to 1, pid's go random */
 struct forkstat forkstat;

 void fork_return(void *);
@@ -193,7 +192,11 @@ process_new(struct proc *p, struct process *parent, int 
flags)
(caddr_t)&pr->ps_endcopy - (caddr_t)&pr->ps_startcopy);

process_initialize(pr, p);
-   pr->ps_pid = allocpid();
+
+   if (flags & FORK_PID1)
+   pr->ps_pid = 1;
+   else
+   pr->ps_pid = allocpid();

/* post-copy fixups */
pr->ps_pptr = parent;
@@ -590,19 +593,12 @@ ispidtaken(pid_t pid)
 pid_t
 allocpid(void)
 {
-   static pid_t lastpid;
pid_t pid;

-   if (!randompid) {
-   /* only used early on for system processes */
-   pid = ++lastpid;
-   } else {
-   /* Find an unused pid satisfying lastpid < pid <= PID_MAX */
-   do {
-   pid = arc4random_uniform(PID_MAX - lastpid) + 1 +
-   lastpid;
-   } while (ispidtaken(pid));
-   }
+   /* Find an unused pid satisfying 1 < pid <= PID_MAX */
+   do {
+   pid = 2 + arc4random_uniform(PID_MAX - 1);
+   } while (ispidtaken(pid));

return pid;
 }
diff --git a/sys/sys/proc.h b/sys/sys/proc.h
index 1a1f0966518..5f0b310ff23 100644
--- a/sys/sys/proc.h
+++ b/sys/sys/proc.h
@@ -457,6 +457,7 @@ struct uidinfo *uid_find(uid_t);
 #define FORK_SIGHAND   0x0200
 #define FORK_PTRACE0x0400
 #define FORK_THREAD0x0800
+#define FORK_PID1  0x1000

 #define EXIT_NORMAL0x0001
 #define EXIT_THREAD0x0002
@@ -478,7 +479,6 @@ extern struct proc proc0;   /* Process slot for 
swapper. */
 extern struct process process0;/* Process slot for kernel 
threads. */
 extern int nprocesses, maxprocess; /* Cur and max number of processes. */
 extern int nthreads, maxthread;/* Cur and max number of 
threads. */
-extern int randompid;  /* fork() should create random pid's */

 LIST_HEAD(proclist, proc);
 LIST_HEAD(processlist, process);
--
2.11.0



--
Ossi Herrala



--
Ossi Herrala



Re: ldpad(8): fix deletion of individual attribute values

2017-02-11 Thread Philip Guenther
On Mon, 6 Feb 2017, Robert Klein wrote:
> TL;DR: OpenBSD's ldapd(8) has issues when deleting individual attribute 
> values.  Patch below.

I've committed it with some whitespace and comment style tweaks. Thanks 
for poking on this again!


Philip Guenther




Re: NFS: Kill so_upcall NET_LOCK() recursion

2017-02-11 Thread Christian Weisgerber
On 2017-02-06, Martin Pieuchot  wrote:

> guenther@ pointed out during a2k17 that nfsrv_rcv() already has a way to
> not re-enter the socket layer.  Instead of doing soreceive() directly in
> the receiving path, we notify and wakeup nfsd(8) to do it.
>
> I'd like to do that unconditionally to fix one of the blocking
> recursions.

This more than halves performance for a FreeBSD client _writing_
to an OpenBSD server.  Read performance is not (significantly)
affected.

===> /obsd
dd bs=64k
from NFS
8110515331 bytes transferred in 113.948541 secs (71177000 bytes/sec)
8110515331 bytes transferred in 114.227510 secs (71003170 bytes/sec)
8110515331 bytes transferred in 114.647424 secs (70743110 bytes/sec)

to NFS
8110515331 bytes transferred in 258.461309 secs (31379998 bytes/sec)
8110515331 bytes transferred in 220.057884 secs (36856282 bytes/sec)
8110515331 bytes transferred in 219.894926 secs (36883595 bytes/sec)

===> /bsd   "NFS: Kill so_upcall NET_LOCK() recursion"
dd bs=64k
from NFS
8110515331 bytes transferred in 115.323728 secs (70328244 bytes/sec)
8110515331 bytes transferred in 117.878431 secs (68804066 bytes/sec)
8110515331 bytes transferred in 117.852977 secs (68818926 bytes/sec)

to NFS
8110515331 bytes transferred in 559.963407 secs (14484010 bytes/sec)
8110515331 bytes transferred in 558.174282 secs (14530435 bytes/sec)
8110515331 bytes transferred in 552.301516 secs (14684941 bytes/sec)

-- 
Christian "naddy" Weisgerber  na...@mips.inka.de



Re: reduce the direct fd_ofileflags poking

2017-02-11 Thread Todd C. Miller
On Sat, 11 Feb 2017 01:29:08 -0800, Philip Guenther wrote:

> To simplify the filedesc fd_ofileflags handling, how about if we make 
> falloc() take optional flags to OR into the new fd's ofileflags? That 
> eliminates a quarter of the references to fd_ofileflags.

OK, this seems much better than fiddling with fd_ofileflags after
the fact.

 - todd



Re: asmc: restore keyboard backlight on resume

2017-02-11 Thread Theo de Raadt
>I'm not sure if you choose DVACT_WAKEUP on purpose, another way of doing
>it would be to do a task_add() in DVACT_RESUME.  The difference is that
>the resuming thread is not allowed to sleep in RESUME.  At some point we
>tried to keep the number of WAKEUP low, but I'm not sure if it is still
>relevant today.

Hmm, I don't recall it that way.  The problem with introducing the split
between RESUME and WAKEUP was a long learning curve for deveopers, and so we
cheated a little.  I still prefer the syncronous behaviour of a proper
WAKEUP since studying failure is easier.  Asyncronous event interactions are
highly undebuggable in this scenario.

So I prefer the obviousness of WAKEUP.

ok deraadt

>> Index: sys/dev/isa/asmc.c
>> ===
>> RCS file: /cvs/src/sys/dev/isa/asmc.c,v
>> retrieving revision 1.30
>> diff -u -p -u -p -r1.30 asmc.c
>> --- sys/dev/isa/asmc.c   22 Apr 2016 20:45:53 -  1.30
>> +++ sys/dev/isa/asmc.c   10 Feb 2017 00:40:15 -
>> @@ -92,6 +92,7 @@ void   asmc_update(void *);
>>  int asmc_match(struct device *, void *, void *);
>>  voidasmc_attach(struct device *, struct device *, void *);
>>  int asmc_detach(struct device *, int);
>> +int asmc_activate(struct device *, int);
>>  
>>  /* wskbd hook functions */
>>  voidasmc_backlight(void *);
>> @@ -101,7 +102,7 @@ extern int (*wskbd_get_backlight)(struct
>>  extern int (*wskbd_set_backlight)(struct wskbd_backlight *);
>>  
>>  const struct cfattach asmc_ca = {
>> -sizeof(struct asmc_softc), asmc_match, asmc_attach
>> +sizeof(struct asmc_softc), asmc_match, asmc_attach, NULL, asmc_activate
>>  };
>>  
>>  struct cfdriver asmc_cd = {
>> @@ -355,6 +356,20 @@ asmc_detach(struct device *self, int fla
>>  
>>  task_del(systq, &sc->sc_task_backlight);
>>  asmc_try(sc, ASMC_WRITE, "LKSB", buf, 2);
>> +return 0;
>> +}
>> +
>> +int
>> +asmc_activate(struct device *self, int act)
>> +{
>> +struct asmc_softc *sc = (struct asmc_softc *)self;
>> +
>> +switch (act) {
>> +case DVACT_WAKEUP:
>> +asmc_backlight(sc);
>> +break;
>> +}
>> +
>>  return 0;
>>  }
>>  
>> 
>
>



Re: mira sfer overflow panic (was: Re: 11n support for athn(4))

2017-02-11 Thread Theo Buehler
On Sat, Feb 11, 2017 at 10:31:39AM +, Peter Kay wrote:
> 
> 
> On Thu, Jan 26, 2017 at 10:38:44AM +0100, Stefan Sperling wrote:
> > On Thu, Jan 26, 2017 at 06:36:06AM +, Peter Kay wrote:
> > > sfer overflow
> > 
> > Interesting. This is the first time I've ever seen this panic trigger.
> > 
> > Can you apply this patch and try to trigger it again?
> I've been running with MIRADEBUG since Feb 1st, just now had a different panic
> 
> Bogus long slot station count 0
> 
> Ieee80211_node_leave _11g+0xd0
> 
> Will post details later when I've had chance to ocr the screencaps

Thanks, I think you can spare yourself the trouble of ocr'ing the
screencaps. On February 2nd stsp committed a fix for the refcounting
bugs that led to this panic:
http://cvsweb.openbsd.org/cgi-bin/cvsweb/src/sys/net80211/ieee80211_node.c?rev=1.113&content-type=text/x-cvsweb-markup



Re: mira sfer overflow panic (was: Re: 11n support for athn(4))

2017-02-11 Thread Peter Kay


On Thu, Jan 26, 2017 at 10:38:44AM +0100, Stefan Sperling wrote:
> On Thu, Jan 26, 2017 at 06:36:06AM +, Peter Kay wrote:
> > sfer overflow
> 
> Interesting. This is the first time I've ever seen this panic trigger.
> 
> Can you apply this patch and try to trigger it again?
I've been running with MIRADEBUG since Feb 1st, just now had a different panic

Bogus long slot station count 0

Ieee80211_node_leave _11g+0xd0

Will post details later when I've had chance to ocr the screencaps



reduce the direct fd_ofileflags poking

2017-02-11 Thread Philip Guenther
To simplify the filedesc fd_ofileflags handling, how about if we make 
falloc() take optional flags to OR into the new fd's ofileflags? That 
eliminates a quarter of the references to fd_ofileflags.

While here, make falloc() assert that its return arguments are non-NULL, 
as it doesn't make sense to allocate a larval file but no get a reference 
back with which to mature it, or to allocate an fd but not get back which.

ok?

Philip Guenther


Index: share/man/man9/file.9
===
RCS file: /data/src/openbsd/src/share/man/man9/file.9,v
retrieving revision 1.16
diff -u -p -r1.16 file.9
--- share/man/man9/file.9   23 Nov 2015 17:53:57 -  1.16
+++ share/man/man9/file.9   11 Feb 2017 08:32:51 -
@@ -38,7 +38,7 @@
 .In sys/file.h
 .In sys/filedesc.h
 .Ft int
-.Fn falloc "struct proc *p" "struct file **resultfp" "int *resultfd"
+.Fn falloc "struct proc *p" "int flags" "struct file **resultfp" "int 
*resultfd"
 .Ft int
 .Fn fdrelease "struct proc *p" "int fd"
 .Ft void
@@ -66,17 +66,32 @@ kqueues (see
 .Xr kqueue 2 ) ,
 and various special purpose communication endpoints.
 .Pp
-A new file descriptor is allocated with the function
+A new file and a file descriptor for it are allocated with the function
+.Fn falloc .
+The
+.Fa flags
+argument can be used to set the
+.Dv UF_EXCLOSE
+flag on the new descriptor.
+The larval file and fd are returned via
+.Fa resultfp
+and
+.Fa resultfd ,
+which must not be
+.Dv NULL .
 .Fn falloc
-and freed with
+initializes the new file to have a reference count of two:
+one for the reference from the file descriptor table and one
+for the caller to release with
+.Fn FRELE
+when it done initializing it.
+.Pp
+A file descriptor is freed with
 .Fn fdrelease .
-.Fn falloc
-and
-.Fn fdrelease
-deal with allocating and freeing slots in the file descriptor table,
-expanding the table when necessary and initializing the descriptor.
-It's possible to do those things in smaller steps, but it's not
-recommended to make complicated kernel APIs that require it.
+This releases the reference that it holds to the underlying file;
+if that's the last reference then the file will be freed.
+.\" with
+.\" .Xr closef 9 .
 .Pp
 The files are extracted from the file descriptor table using the
 functions
Index: sys/sys/filedesc.h
===
RCS file: /data/src/openbsd/src/sys/sys/filedesc.h,v
retrieving revision 1.33
diff -u -p -r1.33 filedesc.h
--- sys/sys/filedesc.h  25 Jan 2017 06:15:50 -  1.33
+++ sys/sys/filedesc.h  11 Feb 2017 09:13:34 -
@@ -125,7 +125,7 @@ voidfiledesc_init(void);
 intdupfdopen(struct proc *, int, int);
 intfdalloc(struct proc *p, int want, int *result);
 void   fdexpand(struct proc *);
-intfalloc(struct proc *p, struct file **resultfp, int *resultfd);
+intfalloc(struct proc *_p, int _flags, struct file **_rfp, int *_rfd);
 struct filedesc *fdinit(void);
 struct filedesc *fdshare(struct process *);
 struct filedesc *fdcopy(struct process *);
Index: sys/kern/exec_script.c
===
RCS file: /data/src/openbsd/src/sys/kern/exec_script.c,v
retrieving revision 1.39
diff -u -p -r1.39 exec_script.c
--- sys/kern/exec_script.c  25 Apr 2016 20:00:33 -  1.39
+++ sys/kern/exec_script.c  11 Feb 2017 09:12:08 -
@@ -169,7 +169,7 @@ check_shell:
 #endif
 
fdplock(p->p_fd);
-   error = falloc(p, &fp, &epp->ep_fd);
+   error = falloc(p, 0, &fp, &epp->ep_fd);
fdpunlock(p->p_fd);
if (error)
goto fail;
Index: sys/kern/kern_descrip.c
===
RCS file: /data/src/openbsd/src/sys/kern/kern_descrip.c,v
retrieving revision 1.139
diff -u -p -r1.139 kern_descrip.c
--- sys/kern/kern_descrip.c 24 Jan 2017 04:09:59 -  1.139
+++ sys/kern/kern_descrip.c 11 Feb 2017 09:08:23 -
@@ -895,11 +895,14 @@ fdexpand(struct proc *p)
  * a file descriptor for the process that refers to it.
  */
 int
-falloc(struct proc *p, struct file **resultfp, int *resultfd)
+falloc(struct proc *p, int flags, struct file **resultfp, int *resultfd)
 {
struct file *fp, *fq;
int error, i;
 
+   KASSERT(resultfp != NULL);
+   KASSERT(resultfd != NULL);
+
fdpassertlocked(p->p_fd);
 restart:
if ((error = fdalloc(p, 0, &i)) != 0) {
@@ -929,13 +932,12 @@ restart:
LIST_INSERT_HEAD(&filehead, fp, f_list);
}
p->p_fd->fd_ofiles[i] = fp;
+   p->p_fd->fd_ofileflags[i] |= (flags & UF_EXCLOSE);
fp->f_count = 1;
fp->f_cred = p->p_ucred;
crhold(fp->f_cred);
-   if (resultfp)
-   *resultfp = fp;
-   if (resultfd)
-   *resultfd = i;
+   *resultfp = fp;
+   *resultfd = i;
FREF(fp);
return (0