ASan on OpenBSD

2017-04-30 Thread Greg Steuck
I naively tried to build something with -fsanitize=address using llvm-4.0
port available on OpenBSD 6.1-amd64. I was immediately greeted with:
  clang-4.0: error: unsupported option '-fsanitize=address' for target
  'amd64-unknown-openbsd6.1'

How deep a rat hole does one have to go to port ASan to a new flavour of
BSD? Is OpenBSD going to be particularly painful with its special malloc
and advanced ASLR? Is anybody working on this?

Thanks
Greg


Re: Kill PMAP_UAREA

2017-04-30 Thread Mark Kettenis
> Date: Sun, 30 Apr 2017 21:53:40 +0200
> From: Martin Pieuchot 
> 
> We don't run on ARM < v7 anymore, so this can die.
> 
> ok?

ok kettenis@

> Index: uvm/uvm_glue.c
> ===
> RCS file: /cvs/src/sys/uvm/uvm_glue.c,v
> retrieving revision 1.72
> diff -u -p -r1.72 uvm_glue.c
> --- uvm/uvm_glue.c30 Apr 2017 13:04:49 -  1.72
> +++ uvm/uvm_glue.c30 Apr 2017 19:52:36 -
> @@ -263,12 +263,6 @@ uvm_uarea_alloc(void)
>   no_constraint.ucr_low, no_constraint.ucr_high,
>   0, 0, USPACE/PAGE_SIZE);
>  
> -#ifdef PMAP_UAREA
> - /* Tell the pmap this is a u-area mapping */
> - if (uaddr != 0)
> - PMAP_UAREA(uaddr);
> -#endif
> -
>   return (uaddr);
>  }
>  
> 
> 



Remove KGDB leftover in i386/amd64 GENERIC

2017-04-30 Thread Amit Kulkarni


Index: amd64/conf/GENERIC
===
RCS file: /cvs/src/sys/arch/amd64/conf/GENERIC,v
retrieving revision 1.442
diff -u -p -u -p -r1.442 GENERIC
--- amd64/conf/GENERIC  12 Mar 2017 21:31:18 -  1.442
+++ amd64/conf/GENERIC  30 Apr 2017 19:53:15 -
@@ -19,9 +19,6 @@ optionUSER_PCICONF# user-space PCI co
 option APERTURE# in-kernel aperture driver for XFree86
 option MTRR# CPU memory range attributes control
 
-#optionKGDB# Remote debugger support; exclusive of 
DDB
-#option"KGDB_DEVNAME=\"com\"",KGDBADDR=0x2f8,KGDBRATE=9600
-
 option NTFS# NTFS support
 option HIBERNATE   # Hibernate support
 
Index: i386/conf/GENERIC
===
RCS file: /cvs/src/sys/arch/i386/conf/GENERIC,v
retrieving revision 1.826
diff -u -p -u -p -r1.826 GENERIC
--- i386/conf/GENERIC   13 Jan 2017 20:30:59 -  1.826
+++ i386/conf/GENERIC   30 Apr 2017 19:53:15 -
@@ -20,9 +20,6 @@ optionKVM86   # Kernel Virtual 8086 
emu
 option APERTURE# in-kernel aperture driver for XFree86
 option MTRR# CPU memory range attributes control
 
-#optionKGDB# Remote debugger support; exclusive of 
DDB
-#option"KGDB_DEVNAME=\"com\"",KGDBADDR=0x2f8,KGDBRATE=9600
-
 option NTFS# NTFS support
 option HIBERNATE   # Hibernate support
 



Kill PMAP_UAREA

2017-04-30 Thread Martin Pieuchot
We don't run on ARM < v7 anymore, so this can die.

ok?

Index: uvm/uvm_glue.c
===
RCS file: /cvs/src/sys/uvm/uvm_glue.c,v
retrieving revision 1.72
diff -u -p -r1.72 uvm_glue.c
--- uvm/uvm_glue.c  30 Apr 2017 13:04:49 -  1.72
+++ uvm/uvm_glue.c  30 Apr 2017 19:52:36 -
@@ -263,12 +263,6 @@ uvm_uarea_alloc(void)
no_constraint.ucr_low, no_constraint.ucr_high,
0, 0, USPACE/PAGE_SIZE);
 
-#ifdef PMAP_UAREA
-   /* Tell the pmap this is a u-area mapping */
-   if (uaddr != 0)
-   PMAP_UAREA(uaddr);
-#endif
-
return (uaddr);
 }
 



Kill BSD PZERO lie

2017-04-30 Thread Martin Pieuchot
Back in the old CSRG times, in the 80s, before the introduction of
PCATCH and tsleep(9), PZERO was a clever hack.   The following comment
from sleep() in kern/kern_synch.c 3.1 explains it well:

* The most important effect of pri is that when
* pri<=PZERO a signal cannot disturb the sleep;
* if pri>PZERO signals will be processed.

The reason for such distinction is better explained by a comment in
sys/vmmeter.h, still present in OpenBSD: 

u_int16_t t_dw; /* jobs in ``disk wait'' (neg priority) */

In 2017, "neg priority" translates to a value of ``p_priority'' between 
0 and PZERO.  Back in the old times they were used for "short sleep".
That's why the original getloadavg(3) calculus always included processes
doing a short sleep in the number of running process:

if (p->p_pri < PZERO)
nrun++;

That's why until today we can see a lot of (PZERO + 1) or (PZERO - 1) in
the tree. 

In the 90s everything changed.  tsleep(9) and PCATCH arrived to create
more confusion about what a sleeping priority really means!  In the
version 7.7 of vm/vm_meter.c mckusick@ changed how running processes
where accounted:

if (p->p_pri <= PZERO && p->p_slptime == 0)
nrun++;   

The ``p_slptime'' check means that long sleeping processes (> 1sec) were
no longer included in getloadavg(3).  So in 1990 the kernel already had
processes sleeping for a "long" time with a priority <= PZERO!  PZERO
was already a lie...

The diff below get rids of this lie.  Stop counting sleeping processes
as "running".  There's no way to know if the process is sleeping for a
short period or not.  This eliminate some false positive, for example
when the idling thread or softclock thread are accounted as running.

It also simplifies uvm_total() to just report the number of sleeping
thread.

While here, update vmstat(8) to reflect this change and make it fit in
80chars.  Here's the new output:

 procsmemory   pagediskstraps  cpu
 r   s   avm fre  flt  re  pi  po  fr  sr sd0 sd1  int   sys   cs us sy id
 1  40  922M   3588M 3466   0   0   0   0   0  50  50  353 12810 1314  5  4 91

Index: sys/uvm/uvm_meter.c
===
RCS file: /cvs/src/sys/uvm/uvm_meter.c,v
retrieving revision 1.36
diff -u -p -r1.36 uvm_meter.c
--- sys/uvm/uvm_meter.c 14 Mar 2015 03:38:53 -  1.36
+++ sys/uvm/uvm_meter.c 30 Apr 2017 16:37:08 -
@@ -108,14 +108,14 @@ uvm_loadav(struct loadavg *avg)
 
LIST_FOREACH(p, &allproc, p_list) {
switch (p->p_stat) {
+   case SSTOP:
case SSLEEP:
-   if (p->p_priority > PZERO || p->p_slptime > 1)
-   continue;
-   /* FALLTHROUGH */
+   break;
case SRUN:
case SONPROC:
if (p == p->p_cpu->ci_schedstate.spc_idleproc)
continue;
+   /* FALLTHROUGH */
case SIDL:
nrun++;
if (p->p_cpu)
@@ -136,7 +136,7 @@ uvm_loadav(struct loadavg *avg)
spc->spc_ldavg = (cexp[0] * spc->spc_ldavg +
nrun_cpu[CPU_INFO_UNIT(ci)] * FSCALE *
(FSCALE - cexp[0])) >> FSHIFT;
-   }   
+   }
 }
 
 /*
@@ -254,24 +254,19 @@ uvm_total(struct vmtotal *totalp)
 
/* calculate process statistics */
LIST_FOREACH(p, &allproc, p_list) {
-   if (p->p_flag & P_SYSTEM)
-   continue;
switch (p->p_stat) {
case 0:
continue;
 
case SSLEEP:
case SSTOP:
-   if (p->p_priority <= PZERO)
-   totalp->t_dw++;
-   else if (p->p_slptime < maxslp)
-   totalp->t_sl++;
-   if (p->p_slptime >= maxslp)
-   continue;
+   totalp->t_sl++;
break;
case SRUN:
-   case SIDL:
case SONPROC:
+   if (p == p->p_cpu->ci_schedstate.spc_idleproc)
+   continue;
+   case SIDL:
totalp->t_rq++;
if (p->p_stat == SIDL)
continue;
Index: usr.bin/vmstat/vmstat.8
===
RCS file: /cvs/src/usr.bin/vmstat/vmstat.8,v
retrieving revision 1.37
diff -u -p -r1.37 vmstat.8
--- usr.bin/vmstat/vmstat.8 30 Mar 2016 06:58:06 -  1.37
+++ usr.bin/vmstat/vmstat.8 30 Apr 2017 17:24:17 -
@@ -121,16 +121,11 @@ Information about the numbers of process
 .Bl -tag -width 4n -compact
 .It Li r
 in run queue
-.It Li b
-blocke

Re: Debugger() -> db_enter()

2017-04-30 Thread Mark Kettenis
> Date: Sun, 30 Apr 2017 16:54:15 +0200
> From: Martin Pieuchot 
> 
> I'd like to rename DDB's entry point to be able to filter it out from
> the list of symbols to instrument.  All Elf symbols prefixed with 'db_'
> will be invisible from the dynamic tracing tool I'm working on.
> 
> This consolidate the approach taken by ddb(4) where having a db_printf()
> allows you to instrument/put a break on printf(9).
> 
> ok?

ok kettenis@

> Index: arch/alpha/alpha/db_interface.c
> ===
> RCS file: /cvs/src/sys/arch/alpha/alpha/db_interface.c,v
> retrieving revision 1.22
> diff -u -p -r1.22 db_interface.c
> --- arch/alpha/alpha/db_interface.c   27 Apr 2016 11:03:24 -  1.22
> +++ arch/alpha/alpha/db_interface.c   30 Apr 2017 13:06:42 -
> @@ -220,7 +220,7 @@ db_write_bytes(addr, size, data)
>  }
>  
>  void
> -Debugger()
> +db_enter()
>  {
>  
>   __asm volatile("call_pal 0x81");/* bugchk */
> Index: arch/alpha/alpha/lock_machdep.c
> ===
> RCS file: /cvs/src/sys/arch/alpha/alpha/lock_machdep.c,v
> retrieving revision 1.4
> diff -u -p -r1.4 lock_machdep.c
> --- arch/alpha/alpha/lock_machdep.c   19 Mar 2016 11:34:22 -  1.4
> +++ arch/alpha/alpha/lock_machdep.c   30 Apr 2017 13:06:47 -
> @@ -80,7 +80,7 @@ __mp_lock_spin(struct __mp_lock *mpl)
>  
>   if (nticks == 0) {
>   db_printf("__mp_lock(%p): lock spun out", mpl);
> - Debugger();
> + db_enter();
>   }
>  #endif
>  }
> @@ -128,7 +128,7 @@ __mp_unlock(struct __mp_lock *mpl)
>  #ifdef MP_LOCKDEBUG
>   if (mpl->mpl_cpu != curcpu()) {
>   db_printf("__mp_unlock(%p): not held lock\n", mpl);
> - Debugger();
> + db_enter();
>   }
>  #endif
>  
> @@ -150,7 +150,7 @@ __mp_release_all(struct __mp_lock *mpl)
>  #ifdef MP_LOCKDEBUG
>   if (mpl->mpl_cpu != curcpu()) {
>   db_printf("__mp_release_all(%p): not held lock\n", mpl);
> - Debugger();
> + db_enter();
>   }
>  #endif
>  
> @@ -170,7 +170,7 @@ __mp_release_all_but_one(struct __mp_loc
>  #ifdef MP_LOCKDEBUG
>   if (mpl->mpl_cpu != curcpu()) {
>   db_printf("__mp_release_all_but_one(%p): not held lock\n", mpl);
> - Debugger();
> + db_enter();
>   }
>  #endif
>  
> Index: arch/alpha/alpha/machdep.c
> ===
> RCS file: /cvs/src/sys/arch/alpha/alpha/machdep.c,v
> retrieving revision 1.179
> diff -u -p -r1.179 machdep.c
> --- arch/alpha/alpha/machdep.c30 Apr 2017 13:04:49 -  1.179
> +++ arch/alpha/alpha/machdep.c30 Apr 2017 13:06:57 -
> @@ -762,7 +762,7 @@ nobootinfo:
>   ddb_init();
>  
>   if (boothowto & RB_KDB)
> - Debugger();
> + db_enter();
>  #endif
>   /*
>* Figure out our clock frequency, from RPB fields.
> Index: arch/alpha/dev/sgmap_typedep.c
> ===
> RCS file: /cvs/src/sys/arch/alpha/dev/sgmap_typedep.c,v
> retrieving revision 1.14
> diff -u -p -r1.14 sgmap_typedep.c
> --- arch/alpha/dev/sgmap_typedep.c11 Jul 2014 12:55:32 -  1.14
> +++ arch/alpha/dev/sgmap_typedep.c30 Apr 2017 13:07:12 -
> @@ -222,7 +222,7 @@ __C(SGMAP_TYPE,_load)(bus_dma_tag_t t, b
>  
>  #if defined(SGMAP_DEBUG) && defined(DDB)
>   if (__C(SGMAP_TYPE,_debug) > 1)
> - Debugger();
> + db_enter();
>  #endif
>  
>   if (error == 0) {
> @@ -281,7 +281,7 @@ __C(SGMAP_TYPE,_load_mbuf)(bus_dma_tag_t
>  
>  #if defined(SGMAP_DEBUG) && defined(DDB)
>   if (__C(SGMAP_TYPE,_debug) > 1)
> - Debugger();
> + db_enter();
>  #endif
>  
>   if (error == 0) {
> @@ -358,7 +358,7 @@ __C(SGMAP_TYPE,_load_uio)(bus_dma_tag_t 
>  
>  #if defined(SGMAP_DEBUG) && defined(DDB)
>   if (__C(SGMAP_TYPE,_debug) > 1)
> - Debugger();
> + db_enter();
>  #endif
>  
>   if (error == 0) {
> Index: arch/alpha/tc/scc.c
> ===
> RCS file: /cvs/src/sys/arch/alpha/tc/scc.c,v
> retrieving revision 1.29
> diff -u -p -r1.29 scc.c
> --- arch/alpha/tc/scc.c   2 Jul 2010 17:27:01 -   1.29
> +++ arch/alpha/tc/scc.c   30 Apr 2017 13:07:26 -
> @@ -1084,7 +1084,7 @@ scc_modem_intr(dev)
>   if ((value & ZSRR0_BREAK) && CONSOLE_ON_UNIT(sc->sc_dv.dv_unit)) {
>  #ifdef DDB
>   splx(s);/* spl0()? */
> - Debugger();
> + db_enter();
>   return;
>  #else
>   /* XXX maybe fall back to PROM? */
> Index: arch/amd64/amd64/cpu.c
> ===
> RCS file: /cvs/src/sys/arch/amd64/amd64/cpu.c,v
> retrieving revision 1.102
> diff -u -p -r1.102 cpu.c
> 

Re: Debugger() -> db_enter()

2017-04-30 Thread Theo de Raadt
Sure.  The Mach name has always bothered me.



Debugger() -> db_enter()

2017-04-30 Thread Martin Pieuchot
I'd like to rename DDB's entry point to be able to filter it out from
the list of symbols to instrument.  All Elf symbols prefixed with 'db_'
will be invisible from the dynamic tracing tool I'm working on.

This consolidate the approach taken by ddb(4) where having a db_printf()
allows you to instrument/put a break on printf(9).

ok?

Index: arch/alpha/alpha/db_interface.c
===
RCS file: /cvs/src/sys/arch/alpha/alpha/db_interface.c,v
retrieving revision 1.22
diff -u -p -r1.22 db_interface.c
--- arch/alpha/alpha/db_interface.c 27 Apr 2016 11:03:24 -  1.22
+++ arch/alpha/alpha/db_interface.c 30 Apr 2017 13:06:42 -
@@ -220,7 +220,7 @@ db_write_bytes(addr, size, data)
 }
 
 void
-Debugger()
+db_enter()
 {
 
__asm volatile("call_pal 0x81");/* bugchk */
Index: arch/alpha/alpha/lock_machdep.c
===
RCS file: /cvs/src/sys/arch/alpha/alpha/lock_machdep.c,v
retrieving revision 1.4
diff -u -p -r1.4 lock_machdep.c
--- arch/alpha/alpha/lock_machdep.c 19 Mar 2016 11:34:22 -  1.4
+++ arch/alpha/alpha/lock_machdep.c 30 Apr 2017 13:06:47 -
@@ -80,7 +80,7 @@ __mp_lock_spin(struct __mp_lock *mpl)
 
if (nticks == 0) {
db_printf("__mp_lock(%p): lock spun out", mpl);
-   Debugger();
+   db_enter();
}
 #endif
 }
@@ -128,7 +128,7 @@ __mp_unlock(struct __mp_lock *mpl)
 #ifdef MP_LOCKDEBUG
if (mpl->mpl_cpu != curcpu()) {
db_printf("__mp_unlock(%p): not held lock\n", mpl);
-   Debugger();
+   db_enter();
}
 #endif
 
@@ -150,7 +150,7 @@ __mp_release_all(struct __mp_lock *mpl)
 #ifdef MP_LOCKDEBUG
if (mpl->mpl_cpu != curcpu()) {
db_printf("__mp_release_all(%p): not held lock\n", mpl);
-   Debugger();
+   db_enter();
}
 #endif
 
@@ -170,7 +170,7 @@ __mp_release_all_but_one(struct __mp_loc
 #ifdef MP_LOCKDEBUG
if (mpl->mpl_cpu != curcpu()) {
db_printf("__mp_release_all_but_one(%p): not held lock\n", mpl);
-   Debugger();
+   db_enter();
}
 #endif
 
Index: arch/alpha/alpha/machdep.c
===
RCS file: /cvs/src/sys/arch/alpha/alpha/machdep.c,v
retrieving revision 1.179
diff -u -p -r1.179 machdep.c
--- arch/alpha/alpha/machdep.c  30 Apr 2017 13:04:49 -  1.179
+++ arch/alpha/alpha/machdep.c  30 Apr 2017 13:06:57 -
@@ -762,7 +762,7 @@ nobootinfo:
ddb_init();
 
if (boothowto & RB_KDB)
-   Debugger();
+   db_enter();
 #endif
/*
 * Figure out our clock frequency, from RPB fields.
Index: arch/alpha/dev/sgmap_typedep.c
===
RCS file: /cvs/src/sys/arch/alpha/dev/sgmap_typedep.c,v
retrieving revision 1.14
diff -u -p -r1.14 sgmap_typedep.c
--- arch/alpha/dev/sgmap_typedep.c  11 Jul 2014 12:55:32 -  1.14
+++ arch/alpha/dev/sgmap_typedep.c  30 Apr 2017 13:07:12 -
@@ -222,7 +222,7 @@ __C(SGMAP_TYPE,_load)(bus_dma_tag_t t, b
 
 #if defined(SGMAP_DEBUG) && defined(DDB)
if (__C(SGMAP_TYPE,_debug) > 1)
-   Debugger();
+   db_enter();
 #endif
 
if (error == 0) {
@@ -281,7 +281,7 @@ __C(SGMAP_TYPE,_load_mbuf)(bus_dma_tag_t
 
 #if defined(SGMAP_DEBUG) && defined(DDB)
if (__C(SGMAP_TYPE,_debug) > 1)
-   Debugger();
+   db_enter();
 #endif
 
if (error == 0) {
@@ -358,7 +358,7 @@ __C(SGMAP_TYPE,_load_uio)(bus_dma_tag_t 
 
 #if defined(SGMAP_DEBUG) && defined(DDB)
if (__C(SGMAP_TYPE,_debug) > 1)
-   Debugger();
+   db_enter();
 #endif
 
if (error == 0) {
Index: arch/alpha/tc/scc.c
===
RCS file: /cvs/src/sys/arch/alpha/tc/scc.c,v
retrieving revision 1.29
diff -u -p -r1.29 scc.c
--- arch/alpha/tc/scc.c 2 Jul 2010 17:27:01 -   1.29
+++ arch/alpha/tc/scc.c 30 Apr 2017 13:07:26 -
@@ -1084,7 +1084,7 @@ scc_modem_intr(dev)
if ((value & ZSRR0_BREAK) && CONSOLE_ON_UNIT(sc->sc_dv.dv_unit)) {
 #ifdef DDB
splx(s);/* spl0()? */
-   Debugger();
+   db_enter();
return;
 #else
/* XXX maybe fall back to PROM? */
Index: arch/amd64/amd64/cpu.c
===
RCS file: /cvs/src/sys/arch/amd64/amd64/cpu.c,v
retrieving revision 1.102
diff -u -p -r1.102 cpu.c
--- arch/amd64/amd64/cpu.c  28 Jul 2016 21:57:57 -  1.102
+++ arch/amd64/amd64/cpu.c  30 Apr 2017 13:07:33 -
@@ -619,7 +619,7 @@ cpu_start_secondary(struct cpu_info *ci)
printf("%s: failed to become ready\n", ci->ci_dev->dv_xname);
 #if defined(M

Re: Make mainbus(4) recognize early attribute on arm64

2017-04-30 Thread Patrick Wildt
On Sun, Apr 30, 2017 at 03:04:38PM +0200, Mark Kettenis wrote:
> Here is a diff that makes mainbus(4) behave in a similar way as
> simplebus(4).  Needed for the Firefly-RK3399 since it attaches most
> devices directly on mainbus(4) and need to control the order a bit.
> 
> I dropped the "no device tree" panic.  We really can't get this far
> without having an FDT.
> 
> I'll do a similar diff for armv7 as the RK3288 will need this as well.
> 
> ok?

ok patrick@

> 
> 
> Index: arch/arm64/dev/mainbus.c
> ===
> RCS file: /cvs/src/sys/arch/arm64/dev/mainbus.c,v
> retrieving revision 1.4
> diff -u -p -r1.4 mainbus.c
> --- arch/arm64/dev/mainbus.c  27 Apr 2017 10:23:19 -  1.4
> +++ arch/arm64/dev/mainbus.c  30 Apr 2017 13:00:28 -
> @@ -40,12 +40,14 @@ int mainbus_match_secondary(struct devic
>  
>  struct mainbus_softc {
>   struct devicesc_dev;
> + int  sc_node;
>   bus_space_tag_t  sc_iot;
>   bus_dma_tag_tsc_dmat;
>   int  sc_acells;
>   int  sc_scells;
>   int *sc_ranges;
>   int  sc_rangeslen;
> + int  sc_early;
>  };
>  
>  struct cfattach mainbus_ca = {
> @@ -96,18 +98,17 @@ mainbus_attach(struct device *parent, st
>   char model[128];
>   int node, len;
>  
> - if ((node = OF_peer(0)) == 0)
> - panic("mainbus: no device tree");
> -
>   arm_intr_init_fdt();
>   agtimer_init();
>  
> + sc->sc_node = OF_peer(0);
>   sc->sc_iot = &arm64_bs_tag;
>   sc->sc_dmat = &mainbus_dma_tag;
>   sc->sc_acells = OF_getpropint(OF_peer(0), "#address-cells", 1);
>   sc->sc_scells = OF_getpropint(OF_peer(0), "#size-cells", 1);
>  
> - if ((len = OF_getprop(node, "model", model, sizeof(model))) > 0) {
> + len = OF_getprop(sc->sc_node, "model", model, sizeof(model));
> + if (len > 0) {
>   printf(": %s\n", model);
>   hw_prod = malloc(len, M_DEVBUF, M_NOWAIT);
>   if (hw_prod)
> @@ -126,9 +127,14 @@ mainbus_attach(struct device *parent, st
>   }
>  
>   /* Scan the whole tree. */
> - for (node = OF_child(node); node != 0; node = OF_peer(node))
> + sc->sc_early = 1;
> + for (node = OF_child(sc->sc_node); node != 0; node = OF_peer(node))
>   mainbus_attach_node(self, node, NULL);
>  
> + sc->sc_early = 0;
> + for (node = OF_child(sc->sc_node); node != 0; node = OF_peer(node))
> + mainbus_attach_node(self, node, NULL);
> + 
>   /* Attach secondary CPUs. */
>   mainbus_attach_cpus(self, mainbus_match_secondary);
>  }
> @@ -204,6 +210,7 @@ mainbus_attach_node(struct device *self,
>  int
>  mainbus_match_status(struct device *parent, void *match, void *aux)
>  {
> + struct mainbus_softc *sc = (struct mainbus_softc *)parent;
>   struct fdt_attach_args *fa = aux;
>   struct cfdata *cf = match;
>   char buf[32];
> @@ -212,7 +219,9 @@ mainbus_match_status(struct device *pare
>   strcmp(buf, "disabled") == 0)
>   return 0;
>  
> - return (*cf->cf_attach->ca_match)(parent, match, aux);
> + if (cf->cf_loc[0] == sc->sc_early)
> + return (*cf->cf_attach->ca_match)(parent, match, aux);
> + return 0;
>  }
>  
>  void
> 



Make mainbus(4) recognize early attribute on arm64

2017-04-30 Thread Mark Kettenis
Here is a diff that makes mainbus(4) behave in a similar way as
simplebus(4).  Needed for the Firefly-RK3399 since it attaches most
devices directly on mainbus(4) and need to control the order a bit.

I dropped the "no device tree" panic.  We really can't get this far
without having an FDT.

I'll do a similar diff for armv7 as the RK3288 will need this as well.

ok?


Index: arch/arm64/dev/mainbus.c
===
RCS file: /cvs/src/sys/arch/arm64/dev/mainbus.c,v
retrieving revision 1.4
diff -u -p -r1.4 mainbus.c
--- arch/arm64/dev/mainbus.c27 Apr 2017 10:23:19 -  1.4
+++ arch/arm64/dev/mainbus.c30 Apr 2017 13:00:28 -
@@ -40,12 +40,14 @@ int mainbus_match_secondary(struct devic
 
 struct mainbus_softc {
struct devicesc_dev;
+   int  sc_node;
bus_space_tag_t  sc_iot;
bus_dma_tag_tsc_dmat;
int  sc_acells;
int  sc_scells;
int *sc_ranges;
int  sc_rangeslen;
+   int  sc_early;
 };
 
 struct cfattach mainbus_ca = {
@@ -96,18 +98,17 @@ mainbus_attach(struct device *parent, st
char model[128];
int node, len;
 
-   if ((node = OF_peer(0)) == 0)
-   panic("mainbus: no device tree");
-
arm_intr_init_fdt();
agtimer_init();
 
+   sc->sc_node = OF_peer(0);
sc->sc_iot = &arm64_bs_tag;
sc->sc_dmat = &mainbus_dma_tag;
sc->sc_acells = OF_getpropint(OF_peer(0), "#address-cells", 1);
sc->sc_scells = OF_getpropint(OF_peer(0), "#size-cells", 1);
 
-   if ((len = OF_getprop(node, "model", model, sizeof(model))) > 0) {
+   len = OF_getprop(sc->sc_node, "model", model, sizeof(model));
+   if (len > 0) {
printf(": %s\n", model);
hw_prod = malloc(len, M_DEVBUF, M_NOWAIT);
if (hw_prod)
@@ -126,9 +127,14 @@ mainbus_attach(struct device *parent, st
}
 
/* Scan the whole tree. */
-   for (node = OF_child(node); node != 0; node = OF_peer(node))
+   sc->sc_early = 1;
+   for (node = OF_child(sc->sc_node); node != 0; node = OF_peer(node))
mainbus_attach_node(self, node, NULL);
 
+   sc->sc_early = 0;
+   for (node = OF_child(sc->sc_node); node != 0; node = OF_peer(node))
+   mainbus_attach_node(self, node, NULL);
+   
/* Attach secondary CPUs. */
mainbus_attach_cpus(self, mainbus_match_secondary);
 }
@@ -204,6 +210,7 @@ mainbus_attach_node(struct device *self,
 int
 mainbus_match_status(struct device *parent, void *match, void *aux)
 {
+   struct mainbus_softc *sc = (struct mainbus_softc *)parent;
struct fdt_attach_args *fa = aux;
struct cfdata *cf = match;
char buf[32];
@@ -212,7 +219,9 @@ mainbus_match_status(struct device *pare
strcmp(buf, "disabled") == 0)
return 0;
 
-   return (*cf->cf_attach->ca_match)(parent, match, aux);
+   if (cf->cf_loc[0] == sc->sc_early)
+   return (*cf->cf_attach->ca_match)(parent, match, aux);
+   return 0;
 }
 
 void



patch: choose right compiler in ports

2017-04-30 Thread Marc Espie
This is a work-in-progres, now is the time to shoot holes thru it.

Basically, clang in base comes with libc++, which tends to not be
compatible with stuff compiled with gcc4 or clang from ports.

So I tried designing an interface to choose the most appropriate compiler
for most cases. The only tricky part is that this HAS to plug into modules,
because some modules do choose the compiler for you (e.g., kde5 glue for
instance)

- list CXX11_ARCHS and prop CX11...
allows to do things such as
ONLY_FOR_ARCHS = ${CXX11_ARCHS}
because right now, modern C++ compilers are the ones that support C++11,
even though this might inaccurate at some point. Better name ?
(not set by default, because it might just be that compiling with gcc 4.2.1
may do something reasonable, but not compile all subpackages...)

- WANT_CXX should list the compilers in order of preference (name was
chosen over the more accurate PREFERRED_CXX because, less typing, eh sthen@ ?)
In many cases, this will be
WANT_CXX = base gcc clang
or something like that.
You end up with
CHOSEN_CXX = 
the corresponding choice, as made decided whether your system uses clang
as a base compiler, or whether clang is available as a port, or whether
gcc4 is available as a port.

I renamed an internal variable of modules.port.mk, because
_MODULES_KEEP_GOING is a more accurate name for it.

So far, this interface appears to just drop in for existing usage of
compiler modules.

Again, the names are probably not perfect, but they seem good enough for me.


Index: arch-defines.mk
===
RCS file: /cvs/ports/infrastructure/mk/arch-defines.mk,v
retrieving revision 1.35
diff -u -p -r1.35 arch-defines.mk
--- arch-defines.mk 24 Apr 2017 09:08:06 -  1.35
+++ arch-defines.mk 30 Apr 2017 10:28:11 -
@@ -34,8 +34,10 @@ CLANG_ARCHS = aarch64
 # as well as available for PROPERTIES checks.  XXX list currently inaccurate
 LLVM_ARCHS = aarch64 amd64 arm i386 powerpc mips64 mips64el sparc64
 
+CXX11_ARCHS = ${LLVM_ARCHS} hppa
+
 .for PROP in ALL APM BE LE LP64 CLANG GCC4 GCC3 MONO LLVM \
-   OCAML_NATIVE OCAML_NATIVE_DYNLINK GO
+  CXX11 OCAML_NATIVE OCAML_NATIVE_DYNLINK GO
 .  for A B in ${MACHINE_ARCH} ${ARCH}
 .if !empty(${PROP}_ARCHS:M$A) || !empty(${PROP}_ARCHS:M$B)
 PROPERTIES += ${PROP:L}
Index: bsd.port.mk
===
RCS file: /cvs/ports/infrastructure/mk/bsd.port.mk,v
retrieving revision 1.1342
diff -u -p -r1.1342 bsd.port.mk
--- bsd.port.mk 29 Apr 2017 14:49:38 -  1.1342
+++ bsd.port.mk 30 Apr 2017 10:28:11 -
@@ -270,23 +270,6 @@ _ARCH_DEFINES_INCLUDED = Done
 .  include "${PORTSDIR}/infrastructure/mk/arch-defines.mk"
 .endif
 
-USE_CXX ?= No
-.if ${USE_CXX:L:Mc++11}
-.  if ${PROPERTIES:Mclang}
-# nothing to do
-.  elif ${PROPERTIES:Mllvm}
-# prefer llvm module
-MODULES += lang/clang
-MODCLANG_ARCH ?=   *
-MODCLANG_LANGS +=  c++
-.  else
-# try gcc4
-MODULES += gcc4
-MODGCC4_LANGS +=   c++
-MODGCC4_ARCHS ?=   *
-.  endif
-.endif
-
 .if ${CONFIGURE_STYLE:L:Mautomake} || ${CONFIGURE_STYLE:L:Mautoconf} || \
${CONFIGURE_STYLE:L:Mautoupdate}
 .  if !${CONFIGURE_STYLE:L:Mgnu}
@@ -312,6 +295,8 @@ _MODULES_DONE =
 .  include "${PORTSDIR}/infrastructure/mk/modules.port.mk"
 .endif
 
+WANT_CXX ?= None
+CHOSEN_CXX ?= None
 ###
 ### Variable setup that can happen after modules
 ###
Index: modules.port.mk
===
RCS file: /cvs/ports/infrastructure/mk/modules.port.mk,v
retrieving revision 1.6
diff -u -p -r1.6 modules.port.mk
--- modules.port.mk 17 Apr 2007 15:22:46 -  1.6
+++ modules.port.mk 30 Apr 2017 10:28:11 -
@@ -26,14 +26,14 @@
 # Recursive module support
 #
 
-.undef _MODULES_DONE_ON_THIS_ROUND
+.undef _MODULES_KEEP_GOING
 .for _m in ${MODULES:L}
 .  if "${_m:M*/*}" != ""
 .for _d in ${PORTSDIR_PATH:S/:/ /g}
 .  if empty(_MODULES_DONE:M${_m}) && exists(${_d}/${_m}/${_m:T}.port.mk)
 .include "${_d}/${_m}/${_m:T}.port.mk"
 _MODULES_DONE += ${_m}
-_MODULES_DONE_ON_THIS_ROUND = Yep
+_MODULES_KEEP_GOING = Yep
 .  endif
 .endfor
 .  endif
@@ -41,14 +41,36 @@ _MODULES_DONE_ON_THIS_ROUND = Yep
 .if exists(${PORTSDIR}/infrastructure/mk/${_m}.port.mk)
 .  include "${PORTSDIR}/infrastructure/mk/${_m}.port.mk"
 _MODULES_DONE += ${_m}
-_MODULES_DONE_ON_THIS_ROUND = Yep
+_MODULES_KEEP_GOING = Yep
 .else
 ERRORS += "Fatal: Missing support for module ${_m}."
 .endif
 .  endif
 .endfor
 
+# support for preferred compiler
+.if defined(WANT_CXX) && !defined(CHOSEN_CXX)
+.  for i in ${WANT_CXX}
+.if !defined(CHOSEN_CXX)
+.  if "$i" == "base" && ${PROPERTIES:Mclang}
+CHOSEN_CXX = base
+.  elif "$i" == "clang" && ${PROPERTIES:Mllvm}
+MODULES += lang/clang
+MODCLANG_ARCH ?=   *
+MODCLANG_LANGS +=  c++
+CHO

Small change to 6.1 upgrade guide

2017-04-30 Thread Edd Barrett
Hi,

A friend, who is fairly new to OpenBSD, was having some problems
upgrading the packages on his system.

The problem was that the upgrade guide doesn't make it totally clear
that `pkg_add -u` should be run after applying the configuration
changes. This matters for 6.1 as you need to migrate from pkg.conf(5) to
installurl(5) before `pkg_add -u` will work.

This change tries to make the order of the upgrade steps more explicit.

Makes sense? OK?


Index: faq/upgrade61.html
===
RCS file: /cvs/www/faq/upgrade61.html,v
retrieving revision 1.13
diff -u -p -r1.13 upgrade61.html
--- faq/upgrade61.html  24 Apr 2017 15:45:32 -  1.13
+++ faq/upgrade61.html  30 Apr 2017 09:33:12 -
@@ -35,12 +35,14 @@ For critical or physically remote machin
 local system first.
 
 
-Boot from the install kernel, bsd.rd:
+Start by performing the pre-update steps detailed below.
+Next, boot from the install kernel, bsd.rd:
 use bootable install media, or place the 6.1
 version of bsd.rd in the root of your filesystem and instruct the boot
 loader to boot this kernel.
 Once this kernel is booted, choose the (U)pgrade option and follow the
 prompts.
+Apply the configuration changes and remove the old files detailed below.
 Finish up by upgrading the packages: pkg_add -u.
 
 
-- 
Best Regards
Edd Barrett

http://www.theunixzoo.co.uk