Re: Add Diffie-Hellman group negotiation to iked

2017-07-18 Thread Tim Stewart
viq  writes:

> On 17-06-25 21:44:24, Tim Stewart wrote:
>> Hi,
>>
>> In this message I've tried to encode everything I've done to allow
>> strongSwan on Android to connect with iked, including the latest patch.
>> I have also verified that it breaks neither initial negotiation nor
>> Child SA rekeying for OpenBSD, Windows, and strongSwan (on Android)
>> clients.
>
>  This patch gets my android phone much closer to being able to negotiate
>  a connection, but there are still issues. Paraphrasing analysis mikeb
>  performed on IRC:
>  android sends incorrect (for us) group, and with this patch we now send
>  a failure message and android retries. But, we don't increment msgid
>  "because we did sa_free and restarted, so we can assume that android
>  thinks that negotiation continues, that's why it re-sends the
>  IKE_SA_INIT"

I'm glad it seems to help, though it's too bad that the patch doesn't
work completely for you.

I haven't really considered msgids--I'll do some more reading to see
what I might be missing there.  I do know that resending an IKE_SA_INIT
message with a different DH group is correct, however, and this does
work on my phone.  For your reference, the first line of my strongSwan
log tells me that I'm using strongSwan 5.5.3 and Android 7.1.1.

I see that you forwarded the iked logs in a reply to this email.  Is
this the full log after a fresh iked startup with no existing SAs?
Also, would it be possible to forward an anonymized config and the
strongSwan logs so that I can compare to mine?  (I can also post my
logs, but I'll have to do it in the next day or two as I'm out of time
for today.)

Good luck!

-TimS

--
Tim Stewart
---
Mail:   t...@stoo.org
Matrix: @tim:stoo.org



Re: armv7 static vectors

2017-07-18 Thread Artturi Alm
On Mon, Jul 10, 2017 at 04:19:12PM +0300, Artturi Alm wrote:
> Hi,
> 
> 
> this diff does seem bigger than it is, because this does move the exception
> handler entrys from arm/exceptions.S to arm/vectors.S, while removing
> a round of useless indirection that was needed more before VBAR, which
> can be found supported even on some V6ses w/extensions(ARM11), so this is
> nothing new or anything that anyone should be afraid of, imo.
> i
> +Before anyone goes liek "you just broke FIQs!", no, i didn't, and depending
> on defines to it, the FIQs might try to get ran on .data section, which is not
> OK, imo., and i have some doubt that no-one has ever enabled that FIQ-support
> on OpenBSD/armv7, so no use-case = no fiq fix in this diff,
> which would likely be less than 10lines of code w/some thought.
> 
> shortly; i added these + to locore0.S:
> 
>   mcr CP15_DACR(r0)
> 
> + /* set VBAR */
> + ldr r0, =vectors
> + mcr CP15_VBAR(r0)
> +
>   /* Enable MMU */
>   mrc CP15_SCTLR(r0)
> + bic r0, r0, #CPU_CONTROL_VECRELOC   /* our vectors are at VBAR */
>   orr r0, r0, #CPU_CONTROL_MMU_ENABLE
>   mcr CP15_SCTLR(r0)
>   CPWAIT(r0)
> 
> 
> and removed the initialization/indirection/special-casing that did still exist
> for the exception handlers/vector_page/systempage.
> 
> 
> Works for me on cubieb2
> -Artturi
> 
> 

Hi,

updated diff below, which does not move/use the C_OBJECT()-define,
and potentially fixes FIQs, if someone was to enable them.
Removes arm/arm/fiq_subr.S as a side-effect to touching FIQs, sry.

-Artturi


diff --git a/sys/arch/arm/arm/arm32_machdep.c b/sys/arch/arm/arm/arm32_machdep.c
index 44ae69fa7f9..09b171373aa 100644
--- a/sys/arch/arm/arm/arm32_machdep.c
+++ b/sys/arch/arm/arm/arm32_machdep.c
@@ -115,62 +115,6 @@ void prefetch_abort_handler(trapframe_t *frame);
 extern void configure  (void);
 
 /*
- * arm32_vector_init:
- *
- * Initialize the vector page, and select whether or not to
- * relocate the vectors.
- *
- * NOTE: We expect the vector page to be mapped at its expected
- * destination.
- */
-void
-arm32_vector_init(vaddr_t va, int which)
-{
-   extern unsigned int page0[], page0_data[];
-   unsigned int *vectors = (unsigned int *) va;
-   unsigned int *vectors_data = vectors + (page0_data - page0);
-   int vec;
-
-   /*
-* Loop through the vectors we're taking over, and copy the
-* vector's insn and data word.
-*/
-   for (vec = 0; vec < ARM_NVEC; vec++) {
-   if ((which & (1 << vec)) == 0) {
-   /* Don't want to take over this vector. */
-   continue;
-   }
-   vectors[vec] = page0[vec];
-   vectors_data[vec] = page0_data[vec];
-   }
-
-   /* Now sync the vectors. */
-   cpu_icache_sync_range(va, (ARM_NVEC * 2) * sizeof(u_int));
-
-   vector_page = va;
-
-   if (va == ARM_VECTORS_HIGH) {
-   /*
-* Assume the MD caller knows what it's doing here, and
-* really does want the vector page relocated.
-*
-* Note: This has to be done here (and not just in
-* cpu_setup()) because the vector page needs to be
-* accessible *before* main() is called.
-* Think ddb(9) ...
-*
-* NOTE: If the CPU control register is not readable,
-* this will totally fail!  We'll just assume that
-* any system that has high vector support has a
-* readable CPU control register, for now.  If we
-* ever encounter one that does not, we'll have to
-* rethink this.
-*/
-   cpu_control(CPU_CONTROL_VECRELOC, CPU_CONTROL_VECRELOC);
-   }
-}
-
-/*
  * Debug function just to park the CPU
  */
 
@@ -228,9 +172,6 @@ cpu_startup()
paddr_t minaddr;
paddr_t maxaddr;
 
-   /* Lock down zero page */
-   vector_page_setprot(PROT_READ | PROT_EXEC);
-
/*
 * Give pmap a chance to set up a few more things now the vm
 * is initialised
diff --git a/sys/arch/arm/arm/arm_machdep.c b/sys/arch/arm/arm/arm_machdep.c
index f5871f3afb5..041507714cd 100644
--- a/sys/arch/arm/arm/arm_machdep.c
+++ b/sys/arch/arm/arm/arm_machdep.c
@@ -87,18 +87,6 @@
 #include 
 
 /*
- * The ARM architecture places the vector page at address 0.
- * Later ARM architecture versions, however, allow it to be
- * relocated to a high address (0x).  This is primarily
- * to support the Fast Context Switch Extension.
- *
- * This variable contains the address of the vector page.  It
- * defaults to 0; it only needs to be initialized if we enable
- * relocated vectors.
- */
-vaddr_tvector_page;
-
-/*
  * Clear registers on exec
  */
 
diff --git a/sys/arch/arm/arm/cpufunc.c 

[patch] httpd: don't add date header if already set

2017-07-18 Thread Nick Owens
hello tech@,

here is a diff that will cause httpd's fcgi code to not set the HTTP 
date header if it has already been set. the code i am using for an fcgi 
server 
(https://github.com/golang/go/blob/master/src/net/http/fcgi/child.go#L102) 
unconditionally sets the Date header, so with httpd there is a
duplicate "Date:" header in responses.

quick glances at lighttpd and apache2 seem to agree with this behavior.

Index: server_fcgi.c
===
RCS file: /cvs/src/usr.sbin/httpd/server_fcgi.c,v
retrieving revision 1.74
diff -u -p -u -p -r1.74 server_fcgi.c
--- server_fcgi.c   21 Jan 2017 11:32:04 -  1.74
+++ server_fcgi.c   18 Jul 2017 21:31:01 -
@@ -661,8 +661,10 @@ server_fcgi_header(struct client *clt, u
}
 
/* Date header is mandatory and should be added as late as possible */
-   if (server_http_time(time(NULL), tmbuf, sizeof(tmbuf)) <= 0 ||
-   kv_add(>http_headers, "Date", tmbuf) == NULL)
+   key.kv_key = "Date";
+   if ((kv = kv_find(>http_headers, )) == NULL &&
+   (server_http_time(time(NULL), tmbuf, sizeof(tmbuf)) <= 0 ||
+   kv_add(>http_headers, "Date", tmbuf) == NULL))
return (-1);
 
/* Write initial header (fcgi might append more) */



Re: armv7 arm/pmap.h unused defines/variables.

2017-07-18 Thread Artturi Alm
On Sun, Jul 09, 2017 at 12:50:47PM +0300, Artturi Alm wrote:
> Hi,
> 
> might have sent this before. at best (or worst, depends how you look at
> things), these could help hide a bug that'd be able to bring everything
> down in flames, altho. i'm not suggesting so, and have in the past ran
> w/asserts to make sure these were invariant, fwiw., now there is more
> of rather pointless variables there, but only these come w/removal of
> just a single if (... && <_nop_check>).
> 
> 
> -Artturi
> 

Ping? am i really the only one who is annoyed seeing these? cant be o_O

-Artturi

> 
> diff --git a/sys/arch/arm/arm/bus_dma.c b/sys/arch/arm/arm/bus_dma.c
> index ce637651800..e1016e3c65c 100644
> --- a/sys/arch/arm/arm/bus_dma.c
> +++ b/sys/arch/arm/arm/bus_dma.c
> @@ -749,8 +749,7 @@ _bus_dmamap_sync(bus_dma_tag_t t, bus_dmamap_t map, 
> bus_addr_t offset,
>* vmspace has not been active since the last time a full
>* cache flush was performed, we don't need to do anything.
>*/
> - if (__predict_false(map->_dm_proc != NULL &&
> - map->_dm_proc->p_vmspace->vm_map.pmap->pm_cstate.cs_cache_d == 0))
> + if (__predict_false(map->_dm_proc != NULL))
>   return;
>  
>   switch (map->_dm_buftype) {
> diff --git a/sys/arch/arm/arm/genassym.cf b/sys/arch/arm/arm/genassym.cf
> index 3937b930c39..c6f6d097476 100644
> --- a/sys/arch/arm/arm/genassym.cf
> +++ b/sys/arch/arm/arm/genassym.cf
> @@ -61,7 +61,6 @@ define  __ARM_FIQ_INDIRECT  1
>  endif
>  
>  export   DOMAIN_CLIENT
> -export   PMAP_DOMAIN_KERNEL
>  
>  ifdef PMAP_INCLUDE_PTE_SYNC
>  define   PMAP_INCLUDE_PTE_SYNC   1
> @@ -86,8 +85,6 @@ member  pcb_tf
>  member   pcb_pagedir
>  member   pcb_pl1vec
>  member   pcb_l1vec
> -member   pcb_dacr
> -member   pcb_cstate
>  member   pcb_flags
>  member   PCB_R8  pcb_un.un_32.pcb32_r8
>  member   PCB_R9  pcb_un.un_32.pcb32_r9
> @@ -112,18 +109,6 @@ struct   vmspace
>  member   vm_map
>  member   VM_PMAP vm_map.pmap
>  
> -unionpmap_cache_state
> -member   cs_tlb_id
> -member   cs_tlb_d
> -member   cs_tlb
> -member   cs_cache_id
> -member   cs_cache_d
> -member   cs_cache
> -member   cs_all
> -
> -struct   pmap
> -member   PMAP_CSTATE pm_cstate
> -
>  struct   uprof
>  member   pr_base
>  member   pr_size
> diff --git a/sys/arch/arm/include/pcb.h b/sys/arch/arm/include/pcb.h
> index 1f63d2bf044..c90aca90436 100644
> --- a/sys/arch/arm/include/pcb.h
> +++ b/sys/arch/arm/include/pcb.h
> @@ -48,8 +48,6 @@ struct pcb_arm32 {
>   paddr_t pcb32_pagedir;  /* PT hooks */
>   pd_entry_t *pcb32_pl1vec;   /* PTR to vector_base L1 entry*/
>   pd_entry_t pcb32_l1vec; /* Value to stuff on ctx sw */
> - u_int   pcb32_dacr; /* Domain Access Control Reg */
> - void*pcb32_cstate;  /* >pm_cstate */
>   /*
>* WARNING!
>* cpuswitch.S relies on pcb32_r8 being quad-aligned in struct pcb
> @@ -68,8 +66,6 @@ struct pcb_arm32 {
>  #define  pcb_pagedir pcb_un.un_32.pcb32_pagedir
>  #define  pcb_pl1vec  pcb_un.un_32.pcb32_pl1vec
>  #define  pcb_l1vec   pcb_un.un_32.pcb32_l1vec
> -#define  pcb_dacrpcb_un.un_32.pcb32_dacr
> -#define  pcb_cstate  pcb_un.un_32.pcb32_cstate
>  
>  /*
>   * WARNING!
> diff --git a/sys/arch/arm/include/pmap.h b/sys/arch/arm/include/pmap.h
> index 83c3395f710..e1b0e0335fc 100644
> --- a/sys/arch/arm/include/pmap.h
> +++ b/sys/arch/arm/include/pmap.h
> @@ -125,54 +125,11 @@ struct l1_ttable;
>  struct l2_dtable;
>  
>  /*
> - * Track cache/tlb occupancy using the following structure
> - */
> -union pmap_cache_state {
> - struct {
> - union {
> - u_int8_t csu_cache_b[2];
> - u_int16_t csu_cache;
> - } cs_cache_u;
> -
> - union {
> - u_int8_t csu_tlb_b[2];
> - u_int16_t csu_tlb;
> - } cs_tlb_u;
> - } cs_s;
> - u_int32_t cs_all;
> -};
> -#define  cs_cache_id cs_s.cs_cache_u.csu_cache_b[0]
> -#define  cs_cache_d  cs_s.cs_cache_u.csu_cache_b[1]
> -#define  cs_cachecs_s.cs_cache_u.csu_cache
> -#define  cs_tlb_id   cs_s.cs_tlb_u.csu_tlb_b[0]
> -#define  cs_tlb_dcs_s.cs_tlb_u.csu_tlb_b[1]
> -#define  cs_tlb  cs_s.cs_tlb_u.csu_tlb
> -
> -/*
> - * Assigned to cs_all to force cacheops to work for a particular pmap
> - */
> -#define  PMAP_CACHE_STATE_ALL0xu
> -
> -/*
> - * This structure is used by machine-dependent code to describe
> - * static mappings of devices, created at bootstrap time.
> - */
> -struct pmap_devmap {
> - vaddr_t pd_va;  /* virtual address */
> - paddr_t pd_pa;  /* physical 

Re: armv7 sunxi i2c+pmic(=shutdown -p)

2017-07-18 Thread Artturi Alm
On Sun, Jul 16, 2017 at 11:13:35PM +0200, Mark Kettenis wrote:
> > Date: Sun, 9 Jul 2017 20:34:29 +0300
> > From: Artturi Alm 
> > 
> > Hi,
> > 
> > revived the diff below, i2c tested via pmic's shutdown(), for working
> > "shutdown -p now" operation.
> > there was only two i2c's w/"status: 'okay'" in the FDT, so not all of
> > them do attach.
> > 
> > related part of dmesg:
> > 
> > com0: console
> > sxitwi0 at simplebus0
> > iic0 at sxitwi0
> > axppmic0 at iic0 addr 0x34: AXP209, ACIN
> > sxitwi1 at simplebus0
> > iic1 at sxitwi1
> > dwge0 at simplebus0
> > 
> > Comments?
> > -Artturi
> 
> It's a pity that the PSCI "firmware" doesn't do an actual shutdown.
> But having i2c support is worth having in its own right.
> 
> A bit of a step backwards to add code under the old-style 4-clause BSD
> license, but I believe that is still acceptable.
> 
> I don't think we'll ever support the Marvell Discovery hardware, so
> I'd just fold the gttwsi_core.c code into sxitwi.c and get rid of the
> GTTWSI_ALLWINNER hack.
> 

done in diff below, hope i understood correctly what you meant.

> A few more comments inline below.
> 
> On my (Allwinner A20) Banana Pi this seems to work, although the
> Ethernet link status LED turns back on shortly after the board powers
> down.  I guess it gets power from the link.  The power LED stays on as
> well, but that is just leakage from the serial console.  The green LED
> that is gpio controllable turns off when the board powers down.
> 
> 
> > ... snip...
> > +
> > +#define DNAME(sc)  ((sc)->sc_dev.dv_xname)
> 
> This macro is unused.

fixed.

> 
> > + ... snip...
> > +u_int  axp20x_get_acin(void);
> 
> This function is unused.

fixed w/omission due no comments to alternative in my last mail.

> 
> > + ... snip...
> > +void
> > +axp20x_shutdown(void)
> > +{
> > +   /* XXX
> > +* if (!i2c_initialized) sxitwi_init(); ?
> > +* or bring back bitbanging gpio 'soft'i2c..
> > +*/
> 
> This comment makes no sense to me.

neither to me anymore, fixed.

> 
> > + ... snip...
> > +
> > +/*efineTWSI_DEBUG
> 
> You messed that one up ;).

fixed:)

> 
> > +#ifdef TWSI_DEBUG
> > +/*
> > + * conditional debugging
> > + */
> > +#defineCD_INIT 0x0001  /* init */
> > +#defineCD_ERR  0x0002  /* errors */
> > +#defineCD_TIMO 0x0004  /* timeout */
> > +#defineCD_INFO 0x0004  /* timeout */
> > +#defineCD_DBG  0x0010  /* just dbg */
> > +#defineCD_SPAM 0x0020  /* verbose boot */
> > +#defineCD_ALL  0x
> > +
> > +int gttwsi_debug = 0 /*| CD_INIT | CD_DBG | CD_SPAM | CD_ALL*/;
> > +
> > +#defineDPRINTF(flg, stmt) \
> > +do { \
> > +   if (gttwsi_debug & (flg)) \
> > +   printf stmt; \
> > +} while (0)
> > +#else
> > +#defineDPRINTF(flg, stmt) do { } while (0)
> > +#endif /* TWSI_DEBUG */
> > +
> > +#define DNAME(sc)  ((sc)->sc_dev.dv_xname)
> 
> We try to avoid elaborate debugging code like this.  I doubt it is
> very useful in this case.

leftover, fixed.

> 
> > + ... snip...
> > +void   gttwsi_config_children(struct device *);
> 
> This function is unused.

fixed.

> 
> > + ... snip...
> > 
> > 


Had no time to do more than compile test for correctness yet, but should
be enough to get told if i misunderstood anything w/regards the fixes,
and there was no really rainy day yet either, so no manuals.
-Artturi


diff --git a/sys/arch/armv7/conf/GENERIC b/sys/arch/armv7/conf/GENERIC
index af71a6c4835..d8762ba394c 100644
--- a/sys/arch/armv7/conf/GENERIC
+++ b/sys/arch/armv7/conf/GENERIC
@@ -99,6 +99,8 @@ ehci* at fdt? # EHCI (shim)
 usb*   at ehci?#flags 0x1
 #ohci* at sunxi?
 #usb*  at ohci?
+sxitwi*at fdt? # Two-Wire Serial Interface
+iic*   at sxitwi?  # I2C bus
 
 # ARM Versatile Express
 sysreg*at fdt?
@@ -148,6 +150,7 @@ mvxhci* at fdt?
 usb*   at mvxhci?
 mvahci*at fdt?
 
+axppmic*   at iic? # axp209 pmic
 crosec*at iic?
 wskbd* at crosec? mux 1
 pcfrtc*at iic?
diff --git a/sys/arch/armv7/conf/RAMDISK b/sys/arch/armv7/conf/RAMDISK
index 56e64893df6..0c5f8aa4e1f 100644
--- a/sys/arch/armv7/conf/RAMDISK
+++ b/sys/arch/armv7/conf/RAMDISK
@@ -99,6 +99,8 @@ ehci* at fdt? # EHCI (shim)
 usb*   at ehci?#flags 0x1
 #ohci* at sunxi?
 #usb*  at ohci?
+sxitwi*at fdt? # Two-Wire Serial Interface
+iic*   at sxitwi?  # I2C bus
 
 # ARM Versatile Express
 sysreg*at fdt?
@@ -145,6 +147,7 @@ mvxhci* at fdt?
 usb*   at mvxhci?
 mvahci*at fdt?
 
+axppmic*   at iic? # axp209 pmic
 crosec*at iic?
 wskbd* 

Re: log max line length

2017-07-18 Thread Theo de Raadt
I like all of these changes.

> We have the same limit for syslog lines in libc, kernel, syslogd
> now.  Do we want a common constant?  Is the name LOG_MAXLINE suitable
> as a global name?  Most constants in sys/syslog.h start with LOG_.
> 
> While there I renamed TBUF_LEN and FMT_LEN to _SIZE as they contain
> a NUL byte.  Change FMT_SIZE to 1024+1 for consistency.  And it
> does not make sense to loop over the format string if there is no
> output space left.
> 
> ok?
> 
> bluhm
> 
> Index: sys/kern/subr_log.c
> ===
> RCS file: /data/mirror/openbsd/cvs/src/sys/kern/subr_log.c,v
> retrieving revision 1.51
> diff -u -p -r1.51 subr_log.c
> --- sys/kern/subr_log.c   18 Jul 2017 22:22:19 -  1.51
> +++ sys/kern/subr_log.c   19 Jul 2017 00:08:25 -
> @@ -418,8 +418,8 @@ dosendsyslog(struct proc *p, const char 
>   size_t i, len;
>   int error;
>  
> - if (nbyte > 8192)
> - nbyte = 8192;
> + if (nbyte > LOG_MAXLINE)
> + nbyte = LOG_MAXLINE;
>  
>   /* Global variable syslogf may change during sleep, use local copy. */
>   fp = syslogf;
> Index: sys/sys/syslog.h
> ===
> RCS file: /data/mirror/openbsd/cvs/src/sys/sys/syslog.h,v
> retrieving revision 1.15
> diff -u -p -r1.15 syslog.h
> --- sys/sys/syslog.h  14 Jul 2014 03:52:04 -  1.15
> +++ sys/sys/syslog.h  19 Jul 2017 00:05:05 -
> @@ -39,6 +39,8 @@
>  
>  #define  LIOCSFD _IOW('l', 127, int) /* set sendsyslog() fd 
> */
>  
> +#define LOG_MAXLINE  8192/* maximum line length */
> +
>  /*
>   * priorities/facilities are encoded into a single 32-bit quantity, where the
>   * bottom 3 bits are the priority (0-7) and the top 28 bits are the facility
> Index: lib/libc/gen/syslog_r.c
> ===
> RCS file: /data/mirror/openbsd/cvs/src/lib/libc/gen/syslog_r.c,v
> retrieving revision 1.16
> diff -u -p -r1.16 syslog_r.c
> --- lib/libc/gen/syslog_r.c   19 Oct 2016 16:09:24 -  1.16
> +++ lib/libc/gen/syslog_r.c   18 Jul 2017 23:50:13 -
> @@ -73,9 +73,9 @@ __vsyslog_r(int pri, struct syslog_data 
>   int cnt;
>   char ch, *p, *t;
>   int saved_errno;
> -#define  TBUF_LEN(8192+1)
> -#define  FMT_LEN 1024
> - char *conp = NULL, *stdp = NULL, tbuf[TBUF_LEN], fmt_cpy[FMT_LEN];
> +#define  TBUF_SIZE   (LOG_MAXLINE+1)
> +#define  FMT_SIZE(1024+1)
> + char *conp = NULL, *stdp = NULL, tbuf[TBUF_SIZE], fmt_cpy[FMT_SIZE];
>   int tbuf_left, fmt_left, prlen;
>  
>  #define  INTERNALLOG LOG_ERR|LOG_CONS|LOG_PERROR|LOG_PID
> @@ -98,7 +98,7 @@ __vsyslog_r(int pri, struct syslog_data 
>   pri |= data->log_fac;
>  
>   p = tbuf;
> - tbuf_left = TBUF_LEN;
> + tbuf_left = TBUF_SIZE;
>  
>  #define  DEC()   \
>   do {\
> @@ -138,7 +138,9 @@ __vsyslog_r(int pri, struct syslog_data 
>   }
>   }
>  
> - for (t = fmt_cpy, fmt_left = FMT_LEN; (ch = *fmt); ++fmt) {
> + for (t = fmt_cpy, fmt_left = FMT_SIZE;
> + (ch = *fmt) != '\0' && fmt_left > 1;
> + ++fmt) {
>   if (ch == '%' && fmt[1] == 'm') {
>   char ebuf[NL_TEXTMAX];
>  
> @@ -152,15 +154,13 @@ __vsyslog_r(int pri, struct syslog_data 
>   t += prlen;
>   fmt_left -= prlen;
>   } else if (ch == '%' && fmt[1] == '%' && fmt_left > 2) {
> + ++fmt;
>   *t++ = '%';
>   *t++ = '%';
> - fmt++;
>   fmt_left -= 2;
>   } else {
> - if (fmt_left > 1) {
> - *t++ = ch;
> - fmt_left--;
> - }
> + *t++ = ch;
> + fmt_left--;
>   }
>   }
>   *t = '\0';
> Index: usr.sbin/syslogd/syslogd.c
> ===
> RCS file: /data/mirror/openbsd/cvs/src/usr.sbin/syslogd/syslogd.c,v
> retrieving revision 1.244
> diff -u -p -r1.244 syslogd.c
> --- usr.sbin/syslogd/syslogd.c28 Apr 2017 14:52:13 -  1.244
> +++ usr.sbin/syslogd/syslogd.c19 Jul 2017 00:03:27 -
> @@ -54,7 +54,7 @@
>   */
>  
>  #define MAX_UDPMSG   1180/* maximum UDP send size */
> -#define MIN_MEMBUF   (MAXLINE * 4)   /* Minimum memory buffer size */
> +#define MIN_MEMBUF   (LOG_MAXLINE * 4) /* Minimum memory buffer size */
>  #define MAX_MEMBUF   (256 * 1024)/* Maximum memory buffer size */
>  #define MAX_MEMBUF_NAME  64  /* Max length of membuf log 
> name */
>  #define MAX_TCPBUF   (256 * 1024)/* Maximum tcp event buffer size */
> @@ -492,8 +492,8 @@ 

log max line length

2017-07-18 Thread Alexander Bluhm
Hi,

We have the same limit for syslog lines in libc, kernel, syslogd
now.  Do we want a common constant?  Is the name LOG_MAXLINE suitable
as a global name?  Most constants in sys/syslog.h start with LOG_.

While there I renamed TBUF_LEN and FMT_LEN to _SIZE as they contain
a NUL byte.  Change FMT_SIZE to 1024+1 for consistency.  And it
does not make sense to loop over the format string if there is no
output space left.

ok?

bluhm

Index: sys/kern/subr_log.c
===
RCS file: /data/mirror/openbsd/cvs/src/sys/kern/subr_log.c,v
retrieving revision 1.51
diff -u -p -r1.51 subr_log.c
--- sys/kern/subr_log.c 18 Jul 2017 22:22:19 -  1.51
+++ sys/kern/subr_log.c 19 Jul 2017 00:08:25 -
@@ -418,8 +418,8 @@ dosendsyslog(struct proc *p, const char 
size_t i, len;
int error;
 
-   if (nbyte > 8192)
-   nbyte = 8192;
+   if (nbyte > LOG_MAXLINE)
+   nbyte = LOG_MAXLINE;
 
/* Global variable syslogf may change during sleep, use local copy. */
fp = syslogf;
Index: sys/sys/syslog.h
===
RCS file: /data/mirror/openbsd/cvs/src/sys/sys/syslog.h,v
retrieving revision 1.15
diff -u -p -r1.15 syslog.h
--- sys/sys/syslog.h14 Jul 2014 03:52:04 -  1.15
+++ sys/sys/syslog.h19 Jul 2017 00:05:05 -
@@ -39,6 +39,8 @@
 
 #defineLIOCSFD _IOW('l', 127, int) /* set sendsyslog() fd 
*/
 
+#define LOG_MAXLINE8192/* maximum line length */
+
 /*
  * priorities/facilities are encoded into a single 32-bit quantity, where the
  * bottom 3 bits are the priority (0-7) and the top 28 bits are the facility
Index: lib/libc/gen/syslog_r.c
===
RCS file: /data/mirror/openbsd/cvs/src/lib/libc/gen/syslog_r.c,v
retrieving revision 1.16
diff -u -p -r1.16 syslog_r.c
--- lib/libc/gen/syslog_r.c 19 Oct 2016 16:09:24 -  1.16
+++ lib/libc/gen/syslog_r.c 18 Jul 2017 23:50:13 -
@@ -73,9 +73,9 @@ __vsyslog_r(int pri, struct syslog_data 
int cnt;
char ch, *p, *t;
int saved_errno;
-#defineTBUF_LEN(8192+1)
-#defineFMT_LEN 1024
-   char *conp = NULL, *stdp = NULL, tbuf[TBUF_LEN], fmt_cpy[FMT_LEN];
+#defineTBUF_SIZE   (LOG_MAXLINE+1)
+#defineFMT_SIZE(1024+1)
+   char *conp = NULL, *stdp = NULL, tbuf[TBUF_SIZE], fmt_cpy[FMT_SIZE];
int tbuf_left, fmt_left, prlen;
 
 #defineINTERNALLOG LOG_ERR|LOG_CONS|LOG_PERROR|LOG_PID
@@ -98,7 +98,7 @@ __vsyslog_r(int pri, struct syslog_data 
pri |= data->log_fac;
 
p = tbuf;
-   tbuf_left = TBUF_LEN;
+   tbuf_left = TBUF_SIZE;
 
 #defineDEC()   \
do {\
@@ -138,7 +138,9 @@ __vsyslog_r(int pri, struct syslog_data 
}
}
 
-   for (t = fmt_cpy, fmt_left = FMT_LEN; (ch = *fmt); ++fmt) {
+   for (t = fmt_cpy, fmt_left = FMT_SIZE;
+   (ch = *fmt) != '\0' && fmt_left > 1;
+   ++fmt) {
if (ch == '%' && fmt[1] == 'm') {
char ebuf[NL_TEXTMAX];
 
@@ -152,15 +154,13 @@ __vsyslog_r(int pri, struct syslog_data 
t += prlen;
fmt_left -= prlen;
} else if (ch == '%' && fmt[1] == '%' && fmt_left > 2) {
+   ++fmt;
*t++ = '%';
*t++ = '%';
-   fmt++;
fmt_left -= 2;
} else {
-   if (fmt_left > 1) {
-   *t++ = ch;
-   fmt_left--;
-   }
+   *t++ = ch;
+   fmt_left--;
}
}
*t = '\0';
Index: usr.sbin/syslogd/syslogd.c
===
RCS file: /data/mirror/openbsd/cvs/src/usr.sbin/syslogd/syslogd.c,v
retrieving revision 1.244
diff -u -p -r1.244 syslogd.c
--- usr.sbin/syslogd/syslogd.c  28 Apr 2017 14:52:13 -  1.244
+++ usr.sbin/syslogd/syslogd.c  19 Jul 2017 00:03:27 -
@@ -54,7 +54,7 @@
  */
 
 #define MAX_UDPMSG 1180/* maximum UDP send size */
-#define MIN_MEMBUF (MAXLINE * 4)   /* Minimum memory buffer size */
+#define MIN_MEMBUF (LOG_MAXLINE * 4) /* Minimum memory buffer size */
 #define MAX_MEMBUF (256 * 1024)/* Maximum memory buffer size */
 #define MAX_MEMBUF_NAME64  /* Max length of membuf log 
name */
 #define MAX_TCPBUF (256 * 1024)/* Maximum tcp event buffer size */
@@ -492,8 +492,8 @@ main(int argc, char *argv[])
 
/* Reserve space for kernel message buffer plus buffer full message. */
linesize = getmsgbufsize() + 64;
-   if (linesize < 

Re: elf.h

2017-07-18 Thread Karel Gardas

Hi,

the diff below is generated by CVS. For this I removed include/elf_abi.h and 
added include/elf.h. I've also merged two _KERNEL sections together and fixed 
platforms ld.so/*/archdep.h files for inclusion of elf_abi.h. Otherwise the 
description from previous version still apply.

Karel

On Fri, 14 Jul 2017 20:44:12 +0200
Karel Gardas  wrote:

> 
> Hi,
> 
> below is another diff of my elf.h cleanup work. I'm still keeping 
> /usr/include/elf_abi.h to not break GHC and all
> Haskell based ports.
> 
> What I have done in this version is went thorough whole spec and check 
> everything in the exec_elf.h. What's not in spec
> I commented out with "not in spec" mark. I've also reordered code to be in a 
> line with spec so curious man can open spec
> and header file side by side and check without jumping here and there either 
> in spec or in file just scroll down both while reading...
> 
> The most important fixes in exec_elf.h were:
> - Elf64 types (Half/Quarter/Shalf), either badly defined or not in spec at all
> - __alpha__ specific type definition is not in spec, hence commented out, 
> hence Alpha may be broken
> - a lot of other fixed here and there. Mostly additions of missing stuff, but 
> some stuff also removed, especially
>   from machines definitions.
> - I've also added clear comments where the following part of the code is 
> specified (URL) to easy checking
> - I've also added a comment where spec. ends in the code and that OS specific 
> or historically usable definitions continue
> - I've moved into OS specific section some values commented out in the spec. 
> section originally -- just to make base
>   compilable and runnable on AMD64

? .cvsignore
Index: distrib/sets/lists/comp/mi
===
RCS file: /cvs/src/distrib/sets/lists/comp/mi,v
retrieving revision 1.1358
diff -u -p -u -r1.1358 mi
--- distrib/sets/lists/comp/mi  2 Jul 2017 07:46:05 -   1.1358
+++ distrib/sets/lists/comp/mi  18 Jul 2017 20:24:42 -
@@ -822,7 +822,7 @@
 ./usr/include/dirent.h
 ./usr/include/disktab.h
 ./usr/include/dlfcn.h
-./usr/include/elf_abi.h
+./usr/include/elf.h
 ./usr/include/endian.h
 ./usr/include/err.h
 ./usr/include/errno.h
Index: games/hangman/ksyms.c
===
RCS file: /cvs/src/games/hangman/ksyms.c,v
retrieving revision 1.10
diff -u -p -u -r1.10 ksyms.c
--- games/hangman/ksyms.c   8 Jan 2016 13:40:05 -   1.10
+++ games/hangman/ksyms.c   18 Jul 2017 20:25:05 -
@@ -18,7 +18,7 @@
 
 #include 
 #include 
-#include 
+#include 
 #include 
 #include 
 #include 
Index: include/Makefile
===
RCS file: /cvs/src/include/Makefile,v
retrieving revision 1.219
diff -u -p -u -r1.219 Makefile
--- include/Makefile17 Apr 2017 15:53:21 -  1.219
+++ include/Makefile18 Jul 2017 20:28:30 -
@@ -11,7 +11,7 @@
 
 FILES= a.out.h ar.h asr.h assert.h bitstring.h blf.h bsd_auth.h \
complex.h cpio.h ctype.h curses.h db.h dirent.h disktab.h \
-   dlfcn.h elf_abi.h err.h errno.h fenv.h float.h fnmatch.h fstab.h fts.h \
+   dlfcn.h elf.h err.h errno.h fenv.h float.h fnmatch.h fstab.h fts.h \
ftw.h getopt.h glob.h grp.h icdb.h ieeefp.h ifaddrs.h inttypes.h \
iso646.h kvm.h langinfo.h libgen.h limits.h link.h link_elf.h \
locale.h login_cap.h math.h md5.h memory.h ndbm.h netdb.h netgroup.h \
Index: include/elf.h
===
RCS file: include/elf.h
diff -N include/elf.h
--- /dev/null   1 Jan 1970 00:00:00 -
+++ include/elf.h   18 Jul 2017 20:28:30 -
@@ -0,0 +1,33 @@
+/* $OpenBSD: elf.h,v 1.4 1996/05/22 07:46:22 etheisen Exp $*/
+/*
+ * Copyright (c) 1996 Erik Theisen
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ *derived from this software without specific prior written permission
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 

Re: /etc/rc: kernel relinking failed

2017-07-18 Thread Theo Buehler
On Tue, Jul 18, 2017 at 11:07:29PM +0200, Hrvoje Popovski wrote:
> On 18.7.2017. 22:59, Theo Buehler wrote:
> > On Tue, Jul 18, 2017 at 10:55:59PM +0200, Hrvoje Popovski wrote:
> >> Hi all,
> >>
> >> i have checkout cvs tree few minutes ago and i'm seeing this log.
> >>
> >> Jul 18 22:47:36 x3550m4 /etc/rc: kernel relinking failed; see
> >> /usr/share/compile/GENERIC.MP/relink.log
> > Sorry, this is my mistake. I completely forgot to make a current.html
> > entry.
> > 
> > You need to build and install a new config(8) before building and
> > installing a new kernel. Will fix this asap.
> > 
> 
> 
> thank you ...

I just committed a current.html entry. The steps are the exact same as
on June 22: https://www.openbsd.org/faq/current.html#r20170622

Thanks for the report and sorry for the inconvenience.



Re: /etc/rc: kernel relinking failed

2017-07-18 Thread Hrvoje Popovski
On 18.7.2017. 22:59, Theo Buehler wrote:
> On Tue, Jul 18, 2017 at 10:55:59PM +0200, Hrvoje Popovski wrote:
>> Hi all,
>>
>> i have checkout cvs tree few minutes ago and i'm seeing this log.
>>
>> Jul 18 22:47:36 x3550m4 /etc/rc: kernel relinking failed; see
>> /usr/share/compile/GENERIC.MP/relink.log
> Sorry, this is my mistake. I completely forgot to make a current.html
> entry.
> 
> You need to build and install a new config(8) before building and
> installing a new kernel. Will fix this asap.
> 


thank you ...



Re: /etc/rc: kernel relinking failed

2017-07-18 Thread Theo Buehler
On Tue, Jul 18, 2017 at 10:55:59PM +0200, Hrvoje Popovski wrote:
> Hi all,
> 
> i have checkout cvs tree few minutes ago and i'm seeing this log.
> 
> Jul 18 22:47:36 x3550m4 /etc/rc: kernel relinking failed; see
> /usr/share/compile/GENERIC.MP/relink.log

Sorry, this is my mistake. I completely forgot to make a current.html
entry.

You need to build and install a new config(8) before building and
installing a new kernel. Will fix this asap.

> 
> 
> here it is:
> 
> http://kosjenka.srce.hr/~hrvoje/zaprocvat/relink.log
> 
> 
> 
> OpenBSD 6.1-current (GENERIC.MP) #8: Tue Jul 18 22:43:03 CEST 2017
> r...@x3550m4.srce.hr:/usr/src/sys/arch/amd64/compile/GENERIC.MP
> real mem = 34314846208 (32725MB)
> avail mem = 33269080064 (31727MB)
> mpath0 at root
> scsibus0 at mpath0: 256 targets
> mainbus0 at root
> bios0 at mainbus0: SMBIOS rev. 2.7 @ 0x7e67b000 (84 entries)
> bios0: vendor IBM version "-[D7E158DUS-2.40]-" date 04/10/2017
> bios0: IBM IBM System x3550 M4 -[791425Z]-
> acpi0 at bios0: rev 2
> acpi0: sleep states S0 S5
> acpi0: tables DSDT FACP TCPA ERST HEST HPET APIC MCFG OEM0 OEM1 SLIT
> SRAT SLIC SSDT SSDT SSDT SSDT DMAR
> acpi0: wakeup devices MRP1(S4) DCC0(S4) MRP3(S4) MRP5(S4) EHC2(S5)
> PEX0(S5) PEX7(S5) EHC1(S5) IP2P(S3) MRPB(S4) MRPC(S4) MRPD(S4) MRPF(S4)
> MRPG(S4) MRPH(S4) MRPI(S4) [...]
> acpitimer0 at acpi0: 3579545 Hz, 24 bits
> acpihpet0 at acpi0: 14318179 Hz
> acpimadt0 at acpi0 addr 0xfee0: PC-AT compat
> cpu0 at mainbus0: apid 0 (boot processor)
> cpu0: Intel(R) Xeon(R) CPU E5-2620 v2 @ 2.10GHz, 2100.29 MHz
> cpu0:
> FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,DS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE,SSE3,PCLMUL,DTES64,MWAIT,DS-CPL,VMX,SMX,EST,TM2,SSSE3,CX16,xTPR,PDCM,PCID,DCA,SSE4.1,SSE4.2,x2APIC,POPCNT,DEADLINE,AES,XSAVE,AVX,F16C,RDRAND,NXE,PAGE1GB,RDTSCP,LONG,LAHF,PERF,ITSC,FSGSBASE,SMEP,ERMS,SENSOR,ARAT
> cpu0: 256KB 64b/line 8-way L2 cache
> cpu0: TSC frequency 2100292710 Hz
> cpu0: smt 0, core 0, package 0
> mtrr: Pentium Pro MTRR support, 10 var ranges, 88 fixed ranges
> cpu0: apic clock running at 99MHz
> cpu0: mwait min=64, max=64, C-substates=0.2.1.1, IBE
> cpu1 at mainbus0: apid 2 (application processor)
> cpu1: Intel(R) Xeon(R) CPU E5-2620 v2 @ 2.10GHz, 2100.00 MHz
> cpu1:
> FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,DS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE,SSE3,PCLMUL,DTES64,MWAIT,DS-CPL,VMX,SMX,EST,TM2,SSSE3,CX16,xTPR,PDCM,PCID,DCA,SSE4.1,SSE4.2,x2APIC,POPCNT,DEADLINE,AES,XSAVE,AVX,F16C,RDRAND,NXE,PAGE1GB,RDTSCP,LONG,LAHF,PERF,ITSC,FSGSBASE,SMEP,ERMS,SENSOR,ARAT
> cpu1: 256KB 64b/line 8-way L2 cache
> cpu1: smt 0, core 1, package 0
> cpu2 at mainbus0: apid 4 (application processor)
> cpu2: Intel(R) Xeon(R) CPU E5-2620 v2 @ 2.10GHz, 2100.00 MHz
> cpu2:
> FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,DS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE,SSE3,PCLMUL,DTES64,MWAIT,DS-CPL,VMX,SMX,EST,TM2,SSSE3,CX16,xTPR,PDCM,PCID,DCA,SSE4.1,SSE4.2,x2APIC,POPCNT,DEADLINE,AES,XSAVE,AVX,F16C,RDRAND,NXE,PAGE1GB,RDTSCP,LONG,LAHF,PERF,ITSC,FSGSBASE,SMEP,ERMS,SENSOR,ARAT
> cpu2: 256KB 64b/line 8-way L2 cache
> cpu2: smt 0, core 2, package 0
> cpu3 at mainbus0: apid 6 (application processor)
> cpu3: Intel(R) Xeon(R) CPU E5-2620 v2 @ 2.10GHz, 2100.00 MHz
> cpu3:
> FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,DS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE,SSE3,PCLMUL,DTES64,MWAIT,DS-CPL,VMX,SMX,EST,TM2,SSSE3,CX16,xTPR,PDCM,PCID,DCA,SSE4.1,SSE4.2,x2APIC,POPCNT,DEADLINE,AES,XSAVE,AVX,F16C,RDRAND,NXE,PAGE1GB,RDTSCP,LONG,LAHF,PERF,ITSC,FSGSBASE,SMEP,ERMS,SENSOR,ARAT
> cpu3: 256KB 64b/line 8-way L2 cache
> cpu3: smt 0, core 3, package 0
> cpu4 at mainbus0: apid 8 (application processor)
> cpu4: Intel(R) Xeon(R) CPU E5-2620 v2 @ 2.10GHz, 2100.00 MHz
> cpu4:
> FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,DS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE,SSE3,PCLMUL,DTES64,MWAIT,DS-CPL,VMX,SMX,EST,TM2,SSSE3,CX16,xTPR,PDCM,PCID,DCA,SSE4.1,SSE4.2,x2APIC,POPCNT,DEADLINE,AES,XSAVE,AVX,F16C,RDRAND,NXE,PAGE1GB,RDTSCP,LONG,LAHF,PERF,ITSC,FSGSBASE,SMEP,ERMS,SENSOR,ARAT
> cpu4: 256KB 64b/line 8-way L2 cache
> cpu4: smt 0, core 4, package 0
> cpu5 at mainbus0: apid 10 (application processor)
> cpu5: Intel(R) Xeon(R) CPU E5-2620 v2 @ 2.10GHz, 2100.00 MHz
> cpu5:
> FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,DS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE,SSE3,PCLMUL,DTES64,MWAIT,DS-CPL,VMX,SMX,EST,TM2,SSSE3,CX16,xTPR,PDCM,PCID,DCA,SSE4.1,SSE4.2,x2APIC,POPCNT,DEADLINE,AES,XSAVE,AVX,F16C,RDRAND,NXE,PAGE1GB,RDTSCP,LONG,LAHF,PERF,ITSC,FSGSBASE,SMEP,ERMS,SENSOR,ARAT
> cpu5: 256KB 64b/line 8-way L2 cache
> cpu5: smt 0, core 5, package 0
> cpu6 at mainbus0: apid 32 (application processor)
> cpu6: Intel(R) Xeon(R) CPU E5-2620 v2 @ 2.10GHz, 2100.00 MHz
> cpu6:
> 

Re: introduction of an additional non-POSIX function in libpthread

2017-07-18 Thread David CARLIER
Sure thing, here an updated diff. Regards.

On 18 July 2017 at 16:22, Ted Unangst  wrote:

> David CARLIER wrote:
> > Hi.
> >
> > I sent a diff originally to a smaller audience but finally decided to
> post
> > it in the mailing list.
> > So it is to introduce the pthread_set_name_np's counterpart so
> > pthread_get_name_np.
> > Some softwares use it (NSPR for example) and anyway internally in my
> > workplace we have multiplatform needing this feature would be nice having
> > this for OpenBSD as well :-)
> >
> > Let me know what you think.
>
> this is fine, it makes sense to have a get function if there's a set
> function. you can combine the man pages, however. no need for two. just
> add a
> sentence to the existing one.
>
Index: lib/libpthread/include/pthread_np.h
===
RCS file: /cvs/src/lib/libpthread/include/pthread_np.h,v
retrieving revision 1.11
diff -u -p -r1.11 pthread_np.h
--- lib/libpthread/include/pthread_np.h 22 Mar 2012 17:21:36 -  1.11
+++ lib/libpthread/include/pthread_np.h 18 Jul 2017 20:50:26 -
@@ -46,6 +46,7 @@ __BEGIN_DECLS
 int pthread_mutexattr_getkind_np(pthread_mutexattr_t);
 int pthread_mutexattr_setkind_np(pthread_mutexattr_t *, int);
 void pthread_set_name_np(pthread_t, const char *);
+void pthread_get_name_np(pthread_t, char *, size_t);
 int pthread_stackseg_np(pthread_t, stack_t *);
 int pthread_main_np(void);
 __END_DECLS
Index: lib/libpthread/man/pthread_set_name_np.3
===
RCS file: /cvs/src/lib/libpthread/man/pthread_set_name_np.3,v
retrieving revision 1.6
diff -u -p -r1.6 pthread_set_name_np.3
--- lib/libpthread/man/pthread_set_name_np.36 Mar 2014 17:42:25 -   
1.6
+++ lib/libpthread/man/pthread_set_name_np.318 Jul 2017 20:50:26 -
@@ -11,6 +11,8 @@
 .In pthread_np.h
 .Ft void
 .Fn pthread_set_name_np "pthread_t thread" "const char *name"
+.Ft void
+.Fn pthread_get_name_np "pthread_t thread" "char *name" "size_t len"
 .Sh DESCRIPTION
 The
 .Fn pthread_set_name_np
@@ -26,6 +28,11 @@ signal.
 The string pointed to by
 .Fa name
 is copied, and so need not be valid for the life of the thread.
+.Fn pthread_get_name_np
+function retrieves
+.Fa name
+associated with
+.Fa thread .
 .Sh SEE ALSO
 .Xr pthreads 3
 .Sh STANDARDS
Index: lib/libpthread/man/pthreads.3
===
RCS file: /cvs/src/lib/libpthread/man/pthreads.3,v
retrieving revision 1.41
diff -u -p -r1.41 pthreads.3
--- lib/libpthread/man/pthreads.3   16 Jul 2013 15:21:11 -  1.41
+++ lib/libpthread/man/pthreads.3   18 Jul 2017 20:50:26 -
@@ -169,6 +169,8 @@ The functions available are as follows:
 Identify the main thread.
 .It Fn pthread_set_name_np
 Set the name of a thread.
+.It Fn pthread_get_name_np
+Get the name of a thread
 .It Fn pthread_stackseg_np
 Return stack size and location.
 .It Fn pthread_yield
@@ -421,6 +423,7 @@ with larger numbers generating more verb
 .Xr pthread_detach 3 ,
 .Xr pthread_equal 3 ,
 .Xr pthread_exit 3 ,
+.Xr pthread_get_name_np 3 ,
 .Xr pthread_getcpuclockid 3 ,
 .Xr pthread_getspecific 3 ,
 .Xr pthread_join 3 ,
Index: lib/librthread/Symbols.map
===
RCS file: /cvs/src/lib/librthread/Symbols.map,v
retrieving revision 1.3
diff -u -p -r1.3 Symbols.map
--- lib/librthread/Symbols.map  27 Feb 2017 07:15:22 -  1.3
+++ lib/librthread/Symbols.map  18 Jul 2017 20:50:26 -
@@ -54,6 +54,7 @@
pthread_detach;
pthread_equal;
pthread_exit;
+   pthread_get_name_np;
pthread_getconcurrency;
pthread_getcpuclockid;
pthread_getprio;
Index: lib/librthread/pthread_np.h
===
RCS file: /cvs/src/lib/librthread/pthread_np.h,v
retrieving revision 1.1
diff -u -p -r1.1 pthread_np.h
--- lib/librthread/pthread_np.h 2 Apr 2016 19:56:53 -   1.1
+++ lib/librthread/pthread_np.h 18 Jul 2017 20:50:26 -
@@ -24,6 +24,7 @@ PROTO_DEPRECATED(pthread_main_np);
 PROTO_DEPRECATED(pthread_mutexattr_getkind_np);
 PROTO_DEPRECATED(pthread_mutexattr_setkind_np);
 PROTO_DEPRECATED(pthread_set_name_np);
+PROTO_DEPRECATED(pthread_get_name_np);
 PROTO_DEPRECATED(pthread_stackseg_np);
 
 #endif /* !_LIBPTHREAD_PTHREAD_NP_H_ */
Index: lib/librthread/rthread_np.c
===
RCS file: /cvs/src/lib/librthread/rthread_np.c,v
retrieving revision 1.19
diff -u -p -r1.19 rthread_np.c
--- lib/librthread/rthread_np.c 7 May 2016 19:05:22 -   1.19
+++ lib/librthread/rthread_np.c 18 Jul 2017 20:50:26 -
@@ -43,6 +43,20 @@ pthread_set_name_np(pthread_t thread, co
strlcpy(thread->name, name, sizeof(thread->name));
 }
 
+void
+pthread_get_name_np(pthread_t thread, char *name, 

/etc/rc: kernel relinking failed

2017-07-18 Thread Hrvoje Popovski
Hi all,

i have checkout cvs tree few minutes ago and i'm seeing this log.

Jul 18 22:47:36 x3550m4 /etc/rc: kernel relinking failed; see
/usr/share/compile/GENERIC.MP/relink.log


here it is:

http://kosjenka.srce.hr/~hrvoje/zaprocvat/relink.log



OpenBSD 6.1-current (GENERIC.MP) #8: Tue Jul 18 22:43:03 CEST 2017
r...@x3550m4.srce.hr:/usr/src/sys/arch/amd64/compile/GENERIC.MP
real mem = 34314846208 (32725MB)
avail mem = 33269080064 (31727MB)
mpath0 at root
scsibus0 at mpath0: 256 targets
mainbus0 at root
bios0 at mainbus0: SMBIOS rev. 2.7 @ 0x7e67b000 (84 entries)
bios0: vendor IBM version "-[D7E158DUS-2.40]-" date 04/10/2017
bios0: IBM IBM System x3550 M4 -[791425Z]-
acpi0 at bios0: rev 2
acpi0: sleep states S0 S5
acpi0: tables DSDT FACP TCPA ERST HEST HPET APIC MCFG OEM0 OEM1 SLIT
SRAT SLIC SSDT SSDT SSDT SSDT DMAR
acpi0: wakeup devices MRP1(S4) DCC0(S4) MRP3(S4) MRP5(S4) EHC2(S5)
PEX0(S5) PEX7(S5) EHC1(S5) IP2P(S3) MRPB(S4) MRPC(S4) MRPD(S4) MRPF(S4)
MRPG(S4) MRPH(S4) MRPI(S4) [...]
acpitimer0 at acpi0: 3579545 Hz, 24 bits
acpihpet0 at acpi0: 14318179 Hz
acpimadt0 at acpi0 addr 0xfee0: PC-AT compat
cpu0 at mainbus0: apid 0 (boot processor)
cpu0: Intel(R) Xeon(R) CPU E5-2620 v2 @ 2.10GHz, 2100.29 MHz
cpu0:
FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,DS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE,SSE3,PCLMUL,DTES64,MWAIT,DS-CPL,VMX,SMX,EST,TM2,SSSE3,CX16,xTPR,PDCM,PCID,DCA,SSE4.1,SSE4.2,x2APIC,POPCNT,DEADLINE,AES,XSAVE,AVX,F16C,RDRAND,NXE,PAGE1GB,RDTSCP,LONG,LAHF,PERF,ITSC,FSGSBASE,SMEP,ERMS,SENSOR,ARAT
cpu0: 256KB 64b/line 8-way L2 cache
cpu0: TSC frequency 2100292710 Hz
cpu0: smt 0, core 0, package 0
mtrr: Pentium Pro MTRR support, 10 var ranges, 88 fixed ranges
cpu0: apic clock running at 99MHz
cpu0: mwait min=64, max=64, C-substates=0.2.1.1, IBE
cpu1 at mainbus0: apid 2 (application processor)
cpu1: Intel(R) Xeon(R) CPU E5-2620 v2 @ 2.10GHz, 2100.00 MHz
cpu1:
FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,DS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE,SSE3,PCLMUL,DTES64,MWAIT,DS-CPL,VMX,SMX,EST,TM2,SSSE3,CX16,xTPR,PDCM,PCID,DCA,SSE4.1,SSE4.2,x2APIC,POPCNT,DEADLINE,AES,XSAVE,AVX,F16C,RDRAND,NXE,PAGE1GB,RDTSCP,LONG,LAHF,PERF,ITSC,FSGSBASE,SMEP,ERMS,SENSOR,ARAT
cpu1: 256KB 64b/line 8-way L2 cache
cpu1: smt 0, core 1, package 0
cpu2 at mainbus0: apid 4 (application processor)
cpu2: Intel(R) Xeon(R) CPU E5-2620 v2 @ 2.10GHz, 2100.00 MHz
cpu2:
FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,DS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE,SSE3,PCLMUL,DTES64,MWAIT,DS-CPL,VMX,SMX,EST,TM2,SSSE3,CX16,xTPR,PDCM,PCID,DCA,SSE4.1,SSE4.2,x2APIC,POPCNT,DEADLINE,AES,XSAVE,AVX,F16C,RDRAND,NXE,PAGE1GB,RDTSCP,LONG,LAHF,PERF,ITSC,FSGSBASE,SMEP,ERMS,SENSOR,ARAT
cpu2: 256KB 64b/line 8-way L2 cache
cpu2: smt 0, core 2, package 0
cpu3 at mainbus0: apid 6 (application processor)
cpu3: Intel(R) Xeon(R) CPU E5-2620 v2 @ 2.10GHz, 2100.00 MHz
cpu3:
FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,DS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE,SSE3,PCLMUL,DTES64,MWAIT,DS-CPL,VMX,SMX,EST,TM2,SSSE3,CX16,xTPR,PDCM,PCID,DCA,SSE4.1,SSE4.2,x2APIC,POPCNT,DEADLINE,AES,XSAVE,AVX,F16C,RDRAND,NXE,PAGE1GB,RDTSCP,LONG,LAHF,PERF,ITSC,FSGSBASE,SMEP,ERMS,SENSOR,ARAT
cpu3: 256KB 64b/line 8-way L2 cache
cpu3: smt 0, core 3, package 0
cpu4 at mainbus0: apid 8 (application processor)
cpu4: Intel(R) Xeon(R) CPU E5-2620 v2 @ 2.10GHz, 2100.00 MHz
cpu4:
FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,DS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE,SSE3,PCLMUL,DTES64,MWAIT,DS-CPL,VMX,SMX,EST,TM2,SSSE3,CX16,xTPR,PDCM,PCID,DCA,SSE4.1,SSE4.2,x2APIC,POPCNT,DEADLINE,AES,XSAVE,AVX,F16C,RDRAND,NXE,PAGE1GB,RDTSCP,LONG,LAHF,PERF,ITSC,FSGSBASE,SMEP,ERMS,SENSOR,ARAT
cpu4: 256KB 64b/line 8-way L2 cache
cpu4: smt 0, core 4, package 0
cpu5 at mainbus0: apid 10 (application processor)
cpu5: Intel(R) Xeon(R) CPU E5-2620 v2 @ 2.10GHz, 2100.00 MHz
cpu5:
FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,DS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE,SSE3,PCLMUL,DTES64,MWAIT,DS-CPL,VMX,SMX,EST,TM2,SSSE3,CX16,xTPR,PDCM,PCID,DCA,SSE4.1,SSE4.2,x2APIC,POPCNT,DEADLINE,AES,XSAVE,AVX,F16C,RDRAND,NXE,PAGE1GB,RDTSCP,LONG,LAHF,PERF,ITSC,FSGSBASE,SMEP,ERMS,SENSOR,ARAT
cpu5: 256KB 64b/line 8-way L2 cache
cpu5: smt 0, core 5, package 0
cpu6 at mainbus0: apid 32 (application processor)
cpu6: Intel(R) Xeon(R) CPU E5-2620 v2 @ 2.10GHz, 2100.00 MHz
cpu6:
FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,DS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE,SSE3,PCLMUL,DTES64,MWAIT,DS-CPL,VMX,SMX,EST,TM2,SSSE3,CX16,xTPR,PDCM,PCID,DCA,SSE4.1,SSE4.2,x2APIC,POPCNT,DEADLINE,AES,XSAVE,AVX,F16C,RDRAND,NXE,PAGE1GB,RDTSCP,LONG,LAHF,PERF,ITSC,FSGSBASE,SMEP,ERMS,SENSOR,ARAT
cpu6: 256KB 64b/line 8-way L2 cache
cpu6: smt 0, core 0, package 1
cpu7 at mainbus0: apid 34 (application processor)
cpu7: Intel(R) Xeon(R) CPU E5-2620 v2 @ 2.10GHz, 

Fix for clang-provoked relocation errors

2017-07-18 Thread Mark Kettenis
The diff below fixes the 

/usr/bin/ld: /tmp/BC-10602a.o: relocation R_X86_64_PC32 against `xxx' can not 
be used when making a shared object; recompile with -fPIC

errors that we see with some ports when compiled with clang.  It is
essentially a diff that was carried for a while in upstream binutils
but was backed out at some point because it broke a corener case on
some other architecture.  I believe that was s390, so it shouldn't
affect us.  But it is still a good reason to be cautious and
thoroughly test this on various architectures.  I've started builds on
armv7 and hppa, and completed a build on amd64.  But it probably
should go through a full ports build on some arcitectures as well.

Note that this diff changes the behaviour of the linker, even with
base gcc.  The change in behaviour is that currently if you declare
but don't initialize a varaible in your program that is also defined
in a shared library, the variable in the shared library gets used.
But with this diff, the copy of the variable in the executable will be
used, even by the shared library.  So if the variable in te shared
library is initialized to a value that isn't zero, that value is lost.
This matches what currently already happens if you initialize the
variable in your program.  I think this is a good thing.


Index: gnu/usr.bin/binutils-2.17/bfd/elflink.c
===
RCS file: /cvs/src/gnu/usr.bin/binutils-2.17/bfd/elflink.c,v
retrieving revision 1.19
diff -u -p -r1.19 elflink.c
--- gnu/usr.bin/binutils-2.17/bfd/elflink.c 3 Sep 2016 09:34:33 -   
1.19
+++ gnu/usr.bin/binutils-2.17/bfd/elflink.c 17 Jul 2017 15:45:20 -
@@ -1180,7 +1180,8 @@ _bfd_elf_merge_symbol (bfd *abfd,
   && (olddef
  || (h->root.type == bfd_link_hash_common
  && (newweak
- || ELF_ST_TYPE (sym->st_info) == STT_FUNC
+ || ELF_ST_TYPE (sym->st_info) == STT_FUNC
+ || (!olddyn && info->executable)
 {
   *override = TRUE;
   newdef = FALSE;



Better ddb support for inteldrm(4)

2017-07-18 Thread Mark Kettenis
Because of the locking changes in the inteldrm(4) update, the code
that swicthes to the console framebuffer is pretty much broken.  The
diff below fixes the issue inteldrm(4) by introducing a new
enter_ddb() "accessop" for wsdisplay(4).  The implementation of this
function should bypass as much of the locking as is feasable. The KMS
drivers can implement this by calling drm_fb_helper_debug_enter().  If
the function isn't implemented it falls back on using show_screen()
which should be sufficient for simple framebuffer drivers like
efifb(4).

I'd like to commit this diff ASAP to make sure we get better bug
reports for panics that happen wile running X.  I'll fix radeondrm(4)
in a followup diff.

Note that you'll end up in a slightly funny state if you enter the ddb
with this diff.  The console framebuffer will be visible but we didn't
do a complete VT switch.  So if you type "continue" X will still e
active, but on a framebuffer you don't see.  You can easily get out of
that sitaution by doing a VT switch to the console and back to X.  But
I can also look at adding a leave_ddb() "accessop" that switches
things back as they were upon leaving ddb.

ok?


Index: dev/wscons/wsdisplay.c
===
RCS file: /cvs/src/sys/dev/wscons/wsdisplay.c,v
retrieving revision 1.126
diff -u -p -r1.126 wsdisplay.c
--- dev/wscons/wsdisplay.c  11 Jan 2017 08:21:33 -  1.126
+++ dev/wscons/wsdisplay.c  18 Jul 2017 18:34:15 -
@@ -2133,6 +2133,30 @@ wsdisplay_switchtoconsole(void)
 }
 
 /*
+ * Switch rhe console display to its ddb screen, avoiding locking
+ * where we can.
+ */
+void
+wsdisplay_enter_ddb(void)
+{
+   struct wsdisplay_softc *sc;
+   struct wsscreen *scr;
+
+   if (wsdisplay_console_device != NULL && cn_tab == _cons) {
+   sc = wsdisplay_console_device;
+   if ((scr = sc->sc_scr[0]) == NULL)
+   return;
+   if (sc->sc_accessops) {
+   (*sc->sc_accessops->enter_ddb)(sc->sc_accesscookie,
+   scr->scr_dconf->emulcookie);
+   } else {
+   (*sc->sc_accessops->show_screen)(sc->sc_accesscookie,
+   scr->scr_dconf->emulcookie, 0, NULL, NULL);
+   }
+   }
+}
+
+/*
  * Deal with the xserver doing driver in userland and thus screwing up suspend
  * and resume by switching away from it at suspend/resume time.
  *
Index: dev/wscons/wsdisplayvar.h
===
RCS file: /cvs/src/sys/dev/wscons/wsdisplayvar.h,v
retrieving revision 1.30
diff -u -p -r1.30 wsdisplayvar.h
--- dev/wscons/wsdisplayvar.h   4 Sep 2016 18:20:34 -   1.30
+++ dev/wscons/wsdisplayvar.h   18 Jul 2017 18:34:15 -
@@ -145,6 +145,7 @@ struct wsdisplay_accessops {
int (*getchar)(void *, int, int, struct wsdisplay_charcell *);
void(*burn_screen)(void *, u_int, u_int);
void(*pollc)(void *, int);
+   void(*enter_ddb)(void *, void *);
 };
 
 /* passed to wscons by the video driver to tell about its capabilities */
@@ -229,6 +230,7 @@ int wsdisplay_cfg_ioctl(struct wsdisplay
  */
 #define WSDISPLAY_NULLSCREEN   -1
 void wsdisplay_switchtoconsole(void);
+void wsdisplay_enter_ddb(void);
 void wsdisplay_suspend(void);
 void wsdisplay_resume(void);
 const struct wsscreen_descr *
Index: dev/pci/drm/i915/i915_drv.c
===
RCS file: /cvs/src/sys/dev/pci/drm/i915/i915_drv.c,v
retrieving revision 1.105
diff -u -p -r1.105 i915_drv.c
--- dev/pci/drm/i915/i915_drv.c 12 Jul 2017 20:12:19 -  1.105
+++ dev/pci/drm/i915/i915_drv.c 18 Jul 2017 18:34:15 -
@@ -1879,6 +1879,7 @@ void  inteldrm_free_screen(void *, void *
 intinteldrm_show_screen(void *, void *, int,
void (*)(void *, int, int), void *);
 void   inteldrm_doswitch(void *);
+void   inteldrm_enter_ddb(void *, void *);
 intinteldrm_load_font(void *, void *, struct wsdisplay_font *);
 intinteldrm_list_font(void *, struct wsdisplay_font *);
 intinteldrm_getchar(void *, int, int, struct wsdisplay_charcell *);
@@ -1908,6 +1909,7 @@ struct wsdisplay_accessops inteldrm_acce
.alloc_screen = inteldrm_alloc_screen,
.free_screen = inteldrm_free_screen,
.show_screen = inteldrm_show_screen,
+   .enter_ddb = inteldrm_enter_ddb,
.getchar = inteldrm_getchar,
.load_font = inteldrm_load_font,
.list_font = inteldrm_list_font,
@@ -2031,6 +2033,20 @@ inteldrm_doswitch(void *v)
 
if (dev_priv->switchcb)
(*dev_priv->switchcb)(dev_priv->switchcbarg, 0, 0);
+}
+
+void
+inteldrm_enter_ddb(void *v, void *cookie)
+{
+   struct inteldrm_softc *dev_priv = v;
+   struct rasops_info *ri = _priv->ro;
+   struct drm_fb_helper *helper = _priv->fbdev->helper;
+
+   if (cookie == ri->ri_active)
+

Re: Remove accents from fortunes

2017-07-18 Thread Theo de Raadt
> Even though our default xterm(1) configuration is robust enough
> that it usually doesn't break anything, I'm not convinced
> indiscriminately printing UTF-8 is a good idea.

The first part of that sentence contains way too much optimism.  xterm
and robust probably do not belong in the same sentence.

Sadly, xterm is unsafe software from 20 years ago which annually has
doubled down on extending the featureset rather than taking moments to
refactor for safety.

I agree about the UTF-8 concerns.  It is getting downright dangerous
to use xterm in non UTF-8, and it feels like something eventually
has to be done to resolve that.



Re: Move {install,upgrade}.site script to the end of installs/upgrades (again)

2017-07-18 Thread Theo de Raadt
This will resolve a few subtle issues with syspatch and kernel
relinking, among other things.

BTW, I would like to take a moment to discourage people from selecting
a different kernel image in /etc/boot.conf with the image command.  Such
a pattern is going to cause increasing problems in the future.

> Originally, the installer executed the {install,upgrade}.site script
> at the end of installs and upgrades. Over time, code was after this
> step and now a list of things happen AFTER this script is executed.
> 
> - make underlying device nodes for softraid devices
> - install the boot-block on disk
> - switch to MP kernel on multi-processor systems
> - update kernel.SHA256
> - relink kernel
> - prepare execution of sysmerge in batch mode on reboot 
> - prepare execution of fw_update on reboot
> - prepare mail with response file to root/admin user
> 
> This diff moves the execution of the {install,upgrade}.site script
> to the end of the install/upgrade process again.
> 
> 
> NOTE: If you use the {install,upgrade}.site functionality, make sure
> your script still works as expected.
> 
> 
> 
> Index: install.sub
> ===
> RCS file: /cvs/src/distrib/miniroot/install.sub,v
> retrieving revision 1.1024
> diff -u -p -p -u -r1.1024 install.sub
> --- install.sub   17 Jul 2017 18:02:31 -  1.1024
> +++ install.sub   17 Jul 2017 18:18:17 -
> @@ -2639,8 +2639,6 @@ finish_up() {
>   )
>   fi
>  
> - [[ -x /mnt/$MODE.site ]] && chroot /mnt /$MODE.site
> -
>   # In case this is a softraid device, make sure all underlying
>   # device nodes exist before installing boot-blocks on disk.
>   make_dev $(bioctl $ROOTDISK 2>/dev/null | sed -n 's/.*<\(.*\)>$/\1/p')
> @@ -2680,6 +2678,8 @@ finish_up() {
>  
>   # Email installer questions and their answers to root on next boot.
>   prep_root_mail /tmp/i/$MODE.resp "$(hostname) $MODE response file"
> +
> + [[ -x /mnt/$MODE.site ]] && chroot /mnt /$MODE.site
>  
>   # Store entropy for the next boot.
>   store_random
> -- 
> -=[rpe]=-
> 



Move {install,upgrade}.site script to the end of installs/upgrades (again)

2017-07-18 Thread Robert Peichaer
Originally, the installer executed the {install,upgrade}.site script
at the end of installs and upgrades. Over time, code was after this
step and now a list of things happen AFTER this script is executed.

- make underlying device nodes for softraid devices
- install the boot-block on disk
- switch to MP kernel on multi-processor systems
- update kernel.SHA256
- relink kernel
- prepare execution of sysmerge in batch mode on reboot 
- prepare execution of fw_update on reboot
- prepare mail with response file to root/admin user

This diff moves the execution of the {install,upgrade}.site script
to the end of the install/upgrade process again.


NOTE: If you use the {install,upgrade}.site functionality, make sure
your script still works as expected.



Index: install.sub
===
RCS file: /cvs/src/distrib/miniroot/install.sub,v
retrieving revision 1.1024
diff -u -p -p -u -r1.1024 install.sub
--- install.sub 17 Jul 2017 18:02:31 -  1.1024
+++ install.sub 17 Jul 2017 18:18:17 -
@@ -2639,8 +2639,6 @@ finish_up() {
)
fi
 
-   [[ -x /mnt/$MODE.site ]] && chroot /mnt /$MODE.site
-
# In case this is a softraid device, make sure all underlying
# device nodes exist before installing boot-blocks on disk.
make_dev $(bioctl $ROOTDISK 2>/dev/null | sed -n 's/.*<\(.*\)>$/\1/p')
@@ -2680,6 +2678,8 @@ finish_up() {
 
# Email installer questions and their answers to root on next boot.
prep_root_mail /tmp/i/$MODE.resp "$(hostname) $MODE response file"
+
+   [[ -x /mnt/$MODE.site ]] && chroot /mnt /$MODE.site
 
# Store entropy for the next boot.
store_random
-- 
-=[rpe]=-



Re: [patch] enable calling chroot(2) after calling pledge(2)

2017-07-18 Thread Theo de Raadt
> > I would like to be able to call chroot(2) in a program that uses pledge(2).
> 
> You need to postpone the pledge(2) calls until after chroot(2).

correct.

> Look at any of the pledged privsep daemons to see how this was dealt with in
> base. Also check the logs to see the refactorings that were made to
> ensure that pledge covers as much ground as possible, even without
> having chroot available when pledged.

correct.  We have taken to calling this methodology 'hoisting' -- the
required state/object creation is moved up ahead of pledge.  carefully.

> > The following (untested) patch makes this possible as part of the "rpath"
> > promise.
> 
> Adding a syscall to a widely used promise allows it in all programs that
> make that promise. Therefore this needs a lot of thought and careful
> investigation.
> 
> Your patch allows more than 350 programs in the base system to call a
> tricky and dangerous thing like chroot(2). Most of them have no business
> doing that...

correct!

and that is why it won't happen.

recently there have been terrorism attacks in Matt Miller's country,
so I think we should call everyone in for interrogation immediately.
that's effectively what the diff proposes -- it significantly
undemines fundamentals for the purpose of 1 program (which we didn't
even see source code for).



Re: introduction of an additional non-POSIX function in libpthread

2017-07-18 Thread Ted Unangst
David CARLIER wrote:
> Hi.
> 
> I sent a diff originally to a smaller audience but finally decided to post
> it in the mailing list.
> So it is to introduce the pthread_set_name_np's counterpart so
> pthread_get_name_np.
> Some softwares use it (NSPR for example) and anyway internally in my
> workplace we have multiplatform needing this feature would be nice having
> this for OpenBSD as well :-)
> 
> Let me know what you think.

this is fine, it makes sense to have a get function if there's a set
function. you can combine the man pages, however. no need for two. just add a
sentence to the existing one.



Re: Remove getopt from vipw

2017-07-18 Thread Theo de Raadt
> As far as I can tell the only thing gained from using getopt is handling
> vipw --
> as vipw takes no flags or arguments, is not intended for non-interactive
> use, and is not POSIX, I don't see a reason -- should be handled. If
> anyone prefers proper handling of -- perhaps
>   if (!( argc == 1 || (argc == 2 && strcmp(argv[1], "--") == 0)))

I disgree strongly, and am glad others dropped your patch.  "--" handling
should never be written by hand.






























































































































































































































































> 
> Also kill a needless include.
> 
> - Matthew Martin
> 
> diff --git vipw.c vipw.c
> index e9595b02198..88a741f1c15 100644
> --- vipw.c
> +++ vipw.c
> @@ -37,7 +37,6 @@
>  #include 
>  #include 
>  #include 
> -#include 
>  #include 
>  #include 
>  
> @@ -49,18 +48,8 @@ main(int argc, char *argv[])
>  {
>   int pfd, tfd;
>   struct stat begin, end;
> - int ch;
>  
> - while ((ch = getopt(argc, argv, "")) != -1) {
> - switch (ch) {
> - default:
> - usage();
> - }
> - }
> - argc -= optind;
> - argv += optind;
> -
> - if (argc != 0)
> + if (argc != 1)
>   usage();
>  
>   if (pledge("stdio rpath wpath cpath fattr proc exec", NULL) == -1)
> 



Re: Reduce NET_LOCK() contention part 2

2017-07-18 Thread Mark Kettenis
> Date: Tue, 18 Jul 2017 16:08:04 +0200
> From: Martin Pieuchot 
> 
> As long as most of the Network Stack run under the NET_LOCK() we want to
> avoid grabbing the lock from different contexts.  Because when multiple
> threads are waiting for the lock, all of them are awaken upon rw_exit().

At some point we should probably make rw_exit() use wakeup_one().  But
I guess that requires some way to guarentee that waiters aren't
starved out by one of them persistently winning the race.

> This not only lead to wasted cycles, it also create a userland starvation
> since kernel threads are preferred by the scheduler.  Making the scheduler
> more clever is not worth it, the stack is still single threaded.
> 
> So I'd like to move as much task as possible grabbing the NET_LOCK() from
> `systq' to `softnetq'.
> 
> Diff below does that for the linkstate and watchdog tasks.

Makes sense to me.

Be aware that grabbing the kernel lock tor run these tasks creates
contention as well.  But that is fine for these tasks which only run
sporadically.

ok kettenis@

> Index: net/if.c
> ===
> RCS file: /cvs/src/sys/net/if.c,v
> retrieving revision 1.505
> diff -u -p -r1.505 if.c
> --- net/if.c  11 Jul 2017 12:51:05 -  1.505
> +++ net/if.c  18 Jul 2017 13:35:26 -
> @@ -1057,10 +1057,10 @@ if_detach(struct ifnet *ifp)
>  
>   /* Remove the watchdog timeout & task */
>   timeout_del(ifp->if_slowtimo);
> - task_del(systq, ifp->if_watchdogtask);
> + task_del(softnettq, ifp->if_watchdogtask);
>  
>   /* Remove the link state task */
> - task_del(systq, ifp->if_linkstatetask);
> + task_del(softnettq, ifp->if_linkstatetask);
>  
>  #if NBPFILTER > 0
>   bpfdetach(ifp);
> @@ -1587,6 +1587,7 @@ if_linkstate_task(void *xifidx)
>   struct ifnet *ifp;
>   int s;
>  
> + KERNEL_LOCK();
>   NET_LOCK(s);
>  
>   ifp = if_get(ifidx);
> @@ -1595,6 +1596,7 @@ if_linkstate_task(void *xifidx)
>   if_put(ifp);
>  
>   NET_UNLOCK(s);
> + KERNEL_UNLOCK();
>  }
>  
>  void
> @@ -1615,7 +1617,7 @@ if_linkstate(struct ifnet *ifp)
>  void
>  if_link_state_change(struct ifnet *ifp)
>  {
> - task_add(systq, ifp->if_linkstatetask);
> + task_add(softnettq, ifp->if_linkstatetask);
>  }
>  
>  /*
> @@ -1631,7 +1633,7 @@ if_slowtimo(void *arg)
>  
>   if (ifp->if_watchdog) {
>   if (ifp->if_timer > 0 && --ifp->if_timer == 0)
> - task_add(systq, ifp->if_watchdogtask);
> + task_add(softnettq, ifp->if_watchdogtask);
>   timeout_add(ifp->if_slowtimo, hz / IFNET_SLOWHZ);
>   }
>   splx(s);
> @@ -1648,10 +1650,12 @@ if_watchdog_task(void *xifidx)
>   if (ifp == NULL)
>   return;
>  
> + KERNEL_LOCK();
>   s = splnet();
>   if (ifp->if_watchdog)
>   (*ifp->if_watchdog)(ifp);
>   splx(s);
> + KERNEL_UNLOCK();
>  
>   if_put(ifp);
>  }
> 
> 



Reduce NET_LOCK() contention part 2

2017-07-18 Thread Martin Pieuchot
As long as most of the Network Stack run under the NET_LOCK() we want to
avoid grabbing the lock from different contexts.  Because when multiple
threads are waiting for the lock, all of them are awaken upon rw_exit().

This not only lead to wasted cycles, it also create a userland starvation
since kernel threads are preferred by the scheduler.  Making the scheduler
more clever is not worth it, the stack is still single threaded.

So I'd like to move as much task as possible grabbing the NET_LOCK() from
`systq' to `softnetq'.

Diff below does that for the linkstate and watchdog tasks.

Index: net/if.c
===
RCS file: /cvs/src/sys/net/if.c,v
retrieving revision 1.505
diff -u -p -r1.505 if.c
--- net/if.c11 Jul 2017 12:51:05 -  1.505
+++ net/if.c18 Jul 2017 13:35:26 -
@@ -1057,10 +1057,10 @@ if_detach(struct ifnet *ifp)
 
/* Remove the watchdog timeout & task */
timeout_del(ifp->if_slowtimo);
-   task_del(systq, ifp->if_watchdogtask);
+   task_del(softnettq, ifp->if_watchdogtask);
 
/* Remove the link state task */
-   task_del(systq, ifp->if_linkstatetask);
+   task_del(softnettq, ifp->if_linkstatetask);
 
 #if NBPFILTER > 0
bpfdetach(ifp);
@@ -1587,6 +1587,7 @@ if_linkstate_task(void *xifidx)
struct ifnet *ifp;
int s;
 
+   KERNEL_LOCK();
NET_LOCK(s);
 
ifp = if_get(ifidx);
@@ -1595,6 +1596,7 @@ if_linkstate_task(void *xifidx)
if_put(ifp);
 
NET_UNLOCK(s);
+   KERNEL_UNLOCK();
 }
 
 void
@@ -1615,7 +1617,7 @@ if_linkstate(struct ifnet *ifp)
 void
 if_link_state_change(struct ifnet *ifp)
 {
-   task_add(systq, ifp->if_linkstatetask);
+   task_add(softnettq, ifp->if_linkstatetask);
 }
 
 /*
@@ -1631,7 +1633,7 @@ if_slowtimo(void *arg)
 
if (ifp->if_watchdog) {
if (ifp->if_timer > 0 && --ifp->if_timer == 0)
-   task_add(systq, ifp->if_watchdogtask);
+   task_add(softnettq, ifp->if_watchdogtask);
timeout_add(ifp->if_slowtimo, hz / IFNET_SLOWHZ);
}
splx(s);
@@ -1648,10 +1650,12 @@ if_watchdog_task(void *xifidx)
if (ifp == NULL)
return;
 
+   KERNEL_LOCK();
s = splnet();
if (ifp->if_watchdog)
(*ifp->if_watchdog)(ifp);
splx(s);
+   KERNEL_UNLOCK();
 
if_put(ifp);
 }



Re: introduction of an additional non-POSIX function in libpthread

2017-07-18 Thread David CARLIER
Yes that s true NetBSD having a variadic like argument as well ... etc ...
I did not have high expectations just wanted to propose ... :-)

On 18 July 2017 at 14:55, Landry Breuil  wrote:

> On Tue, Jul 18, 2017 at 01:43:42PM +0100, David CARLIER wrote:
> > Ah I recognise you you re Mozilla contributor right ? You re probably
> right
> > but that was just an example eventhough I admit it s not extremely widely
> > used ...
>
> Note that you'll have to be careful in your arguments for this function:
>
> - _np prefix is for 'nonportable' so nothing standardises it
> - some oses have getname_np, freebsd has get_name_np
> - linux and netbsd share the function name but not the prototype for
>   setname_mp ?
> - macos enforces the running thread to set its own name
>
> (cf https://stackoverflow.com/a/7989973)
>
> so this looks like a shitshow, and a pretty good reason for not
> having it :)
>
>


Re: introduction of an additional non-POSIX function in libpthread

2017-07-18 Thread Landry Breuil
On Tue, Jul 18, 2017 at 01:43:42PM +0100, David CARLIER wrote:
> Ah I recognise you you re Mozilla contributor right ? You re probably right
> but that was just an example eventhough I admit it s not extremely widely
> used ...

Note that you'll have to be careful in your arguments for this function:

- _np prefix is for 'nonportable' so nothing standardises it
- some oses have getname_np, freebsd has get_name_np
- linux and netbsd share the function name but not the prototype for
  setname_mp ?
- macos enforces the running thread to set its own name

(cf https://stackoverflow.com/a/7989973)

so this looks like a shitshow, and a pretty good reason for not
having it :)



Reducing NET_LOCK() contention

2017-07-18 Thread Martin Pieuchot
When forwarding a lot of traffic with 10G interfaces contention on the
NET_LOCK() is "visible".  Each time you type "ifconfig" you can go grab
a coffee...

The problem has a name: pf_purge_thread().  This thread is created by
default and run even if you don't have PF enabled.  Every `hz' it wakes
up, grab the lock and go to sleep. 

Since the execution of this thread is serialized with the `softnet' task,
it makes more sense to execute it in the same context.  This reduce the
NET_LOCK() contention and implicitly preempt the packet processing.

Diff below improves the situation with PF disabled, I didn't test with
PF enabled.

Index: net/pf.c
===
RCS file: /cvs/src/sys/net/pf.c,v
retrieving revision 1.1037
diff -u -p -r1.1037 pf.c
--- net/pf.c4 Jul 2017 14:10:15 -   1.1037
+++ net/pf.c18 Jul 2017 13:28:10 -
@@ -121,6 +121,10 @@ u_char  pf_tcp_secret[16];
 int pf_tcp_secret_init;
 int pf_tcp_iss_off;
 
+int pf_npurge;
+struct task pf_purge_task = TASK_INITIALIZER(pf_purge, _npurge);
+struct timeout  pf_purge_to = TIMEOUT_INITIALIZER(pf_purge_timeout, NULL);
+
 enum pf_test_status {
PF_TEST_FAIL = -1,
PF_TEST_OK,
@@ -1200,36 +1204,44 @@ pf_purge_expired_rules(void)
 }
 
 void
-pf_purge_thread(void *v)
+pf_purge_timeout(void *unused)
 {
-   int nloops = 0, s;
-
-   for (;;) {
-   tsleep(pf_purge_thread, PWAIT, "pftm", 1 * hz);
-
-   NET_LOCK(s);
+   task_add(softnettq, _purge_task);
+}
 
-   PF_LOCK();
-   /* process a fraction of the state table every second */
-   pf_purge_expired_states(1 + (pf_status.states
-   / pf_default_rule.timeout[PFTM_INTERVAL]));
+void
+pf_purge(void *xnloops)
+{
+   int *nloops = xnloops;
+   int s;
 
-   /* purge other expired types every PFTM_INTERVAL seconds */
-   if (++nloops >= pf_default_rule.timeout[PFTM_INTERVAL]) {
-   pf_purge_expired_src_nodes(0);
-   pf_purge_expired_rules();
-   }
-   PF_UNLOCK();
-   /*
-* Fragments don't require PF_LOCK(), they use their own lock.
-*/
-   if (nloops >= pf_default_rule.timeout[PFTM_INTERVAL]) {
-   pf_purge_expired_fragments();
-   nloops = 0;
-   }
+   KERNEL_LOCK();
+   NET_LOCK(s);
 
-   NET_UNLOCK(s);
+   PF_LOCK();
+   /* process a fraction of the state table every second */
+   pf_purge_expired_states(1 + (pf_status.states
+   / pf_default_rule.timeout[PFTM_INTERVAL]));
+
+   /* purge other expired types every PFTM_INTERVAL seconds */
+   if (++(*nloops) >= pf_default_rule.timeout[PFTM_INTERVAL]) {
+   pf_purge_expired_src_nodes(0);
+   pf_purge_expired_rules();
+   }
+   PF_UNLOCK();
+
+   /*
+* Fragments don't require PF_LOCK(), they use their own lock.
+*/
+   if ((*nloops) >= pf_default_rule.timeout[PFTM_INTERVAL]) {
+   pf_purge_expired_fragments();
+   *nloops = 0;
}
+   NET_UNLOCK(s);
+   KERNEL_UNLOCK();
+
+   if (pf_status.running)
+   timeout_add(_purge_to, 1 * hz);
 }
 
 int32_t
Index: net/pf_ioctl.c
===
RCS file: /cvs/src/sys/net/pf_ioctl.c,v
retrieving revision 1.318
diff -u -p -r1.318 pf_ioctl.c
--- net/pf_ioctl.c  5 Jul 2017 11:40:17 -   1.318
+++ net/pf_ioctl.c  18 Jul 2017 13:29:39 -
@@ -231,16 +231,6 @@ pfattach(int num)
 
/* XXX do our best to avoid a conflict */
pf_status.hostid = arc4random();
-
-   /* require process context to purge states, so perform in a thread */
-   kthread_create_deferred(pf_thread_create, NULL);
-}
-
-void
-pf_thread_create(void *v)
-{
-   if (kthread_create(pf_purge_thread, NULL, NULL, "pfpurge"))
-   panic("pfpurge thread");
 }
 
 int
@@ -1027,6 +1017,7 @@ pfioctl(dev_t dev, u_long cmd, caddr_t a
pf_status.stateid = time_second;
pf_status.stateid = pf_status.stateid << 32;
}
+   timeout_add(_purge_to, 1 * hz);
pf_create_queues();
DPFPRINTF(LOG_NOTICE, "pf: started");
}
@@ -2291,7 +2282,7 @@ pfioctl(dev_t dev, u_long cmd, caddr_t a
pf_default_rule_new.timeout[i];
if (pf_default_rule.timeout[i] == PFTM_INTERVAL &&
pf_default_rule.timeout[i] < old)
-   wakeup(pf_purge_thread);
+   task_add(softnettq, _purge_task);
}
   

Re: connect(2), KERNEL_LOCK() vs socket lock

2017-07-18 Thread Alexander Bluhm
On Tue, Jul 18, 2017 at 09:03:00AM +0200, Martin Pieuchot wrote:
> Diff below extends the scope of the socket lock.  It has been previously
> introduced in sys_connect(), first as NET_LOCK() then renamed, where old
> splsofnet() were used.  But we now need to "move the line up" in order to
> protect fields currently relying on the KERNEL_LOCK().

We were also discussing to move the lock down to the network stack.
Eventually we need locks for the sockets and a lock for the stack.
The first must move up and the latter down.  As we have only one
lock at the moment, I am fine with the upward direction for now.

> Moving the line up means that soconnect() and soconnect2() will now
> assert for the socket lock.

The soconnect2() is only used for local sockets that run with the
kernel lock.  So we could not lock this function.  I guess your
goal is per socket locks, so your change is fine.

> @@ -373,9 +373,10 @@ sys_connect(struct proc *p, void *v, reg
>   if ((error = getsock(p, SCARG(uap, s), )) != 0)
>   return (error);
>   so = fp->f_data;
> + s = solock(so);
>   if (so->so_state & SS_ISCONNECTING) {
> - FRELE(fp, p);
> - return (EALREADY);
> + error = EALREADY;
> + goto out;
>   }
>   error = sockargs(, SCARG(uap, name), SCARG(uap, namelen),
>   MT_SONAME);
> @@ -393,11 +394,8 @@ sys_connect(struct proc *p, void *v, reg
>   if (isdnssocket(so)) {
>   u_int namelen = nam->m_len;
>   error = dns_portcheck(p, so, mtod(nam, void *), );
> - if (error) {
> - FRELE(fp, p);
> - m_freem(nam);
> - return (error);
> - }
> + if (error)
> + goto out;
>   nam->m_len = namelen;
>   }
>  

Now we have a mixture fo goto bad and goto out.  I think everything
before soconnect() should goto out.  Please change the error handling
of sockargs() and pledge_socket() to goto out.

> @@ -135,6 +135,11 @@ fifo_open(void *v)
>   return (error);
>   }
>   fip->fi_readsock = rso;
> + /*
> +  * XXXSMP
> +  * We only lock `wso' because AF_LOCAL sockets are
> +  * still relying on the KERNEL_LOCK().
> +  */
>   if ((error = socreate(AF_LOCAL, , SOCK_STREAM, 0)) != 0) {
>   (void)soclose(rso);
>   free(fip, M_VNODE, sizeof *fip);

Could you move this comment before the solock(wso) line?

> @@ -168,11 +179,12 @@ fifo_open(void *v)
>   goto bad;
>   }
>   if (fip->fi_writers == 1) {
> - fip->fi_readsock->so_state &= 
> ~(SS_CANTRCVMORE|SS_ISDISCONNECTED);
> + rso->so_state &= ~(SS_CANTRCVMORE|SS_ISDISCONNECTED);
>   if (fip->fi_readers > 0)
>   wakeup(>fi_readers);
>   }
>   }
> + sounlock(s);
>   if ((ap->a_mode & O_NONBLOCK) == 0) {
>   if ((ap->a_mode & FREAD) && fip->fi_writers == 0) {
>   VOP_UNLOCK(vp, p);

The goto bad after error = ENXIO has no sounlock().

bluhm



Re: [PATCH] ure improvement

2017-07-18 Thread sc dying
On 2017/07/18 09:12, Martin Pieuchot wrote:
> On 17/07/17(Mon) 15:24, sc dying wrote:
>> On 2017/07/17 08:24, Martin Pieuchot wrote:
>>> On 15/07/17(Sat) 21:16, sc dying wrote:
 - Call usbd_set_config before configuring endpoints in ure_init to fix
an error when re-opening pipes.  I grabbed the code from if_kue.c.
>>>
>>> Which error? Calling usbd_set_config() should be avoid as much as
>>> possible in driver code.
>>
>> Without patch, ure on usb-3 port says this error
>>
>> ure0: usb errors on rx: IOERROR
>>
>> when down the interface and it up.
>
> This is certainly a bug in the way pipe are closed, or more likely in
> xhci(4).  Can you reproduce the problem on ehci(4)?  Do you find
> anything useful if you define XHCI_DEBUG in your kernel?

This problem is not seen on ehci.

On xhci with XHCI_DEBUG, curiously, it does not happen.
I'll look into this.



Re: filt_soread() & socket lock

2017-07-18 Thread Claudio Jeker
On Tue, Jul 18, 2017 at 08:25:38AM +0200, Martin Pieuchot wrote:
> The socket checks in filt_soread() should be atomic.  As found in the
> past week it is not possible to call solock() there because we're not
> allowed to sleep.  However I'd like to prepare the function for future
> locking in order to keep the locking diff minimal.
> 
> ok?

Sure
 
> Index: kern/uipc_socket.c
> ===
> RCS file: /cvs/src/sys/kern/uipc_socket.c,v
> retrieving revision 1.194
> diff -u -p -r1.194 uipc_socket.c
> --- kern/uipc_socket.c13 Jul 2017 16:19:38 -  1.194
> +++ kern/uipc_socket.c18 Jul 2017 06:21:51 -
> @@ -1965,22 +1965,27 @@ int
>  filt_soread(struct knote *kn, long hint)
>  {
>   struct socket *so = kn->kn_fp->f_data;
> + int rv;
>  
>   kn->kn_data = so->so_rcv.sb_cc;
>  #ifdef SOCKET_SPLICE
>   if (isspliced(so))
> - return (0);
> + rv = 0;
> + else
>  #endif /* SOCKET_SPLICE */
>   if (so->so_state & SS_CANTRCVMORE) {
>   kn->kn_flags |= EV_EOF;
>   kn->kn_fflags = so->so_error;
> - return (1);
> + rv = 1;
> + } else if (so->so_error) {  /* temporary udp error */
> + rv = 1;
> + } else if (kn->kn_sfflags & NOTE_LOWAT) {
> + rv = (kn->kn_data >= kn->kn_sdata);
> + } else {
> + rv = (kn->kn_data >= so->so_rcv.sb_lowat);
>   }
> - if (so->so_error)   /* temporary udp error */
> - return (1);
> - if (kn->kn_sfflags & NOTE_LOWAT)
> - return (kn->kn_data >= kn->kn_sdata);
> - return (kn->kn_data >= so->so_rcv.sb_lowat);
> +
> + return rv;
>  }
>  
>  void
> 

-- 
:wq Claudio



Re: Extend the scope of socket lock in soo_stat()

2017-07-18 Thread Claudio Jeker
On Tue, Jul 18, 2017 at 08:42:51AM +0200, Martin Pieuchot wrote:
> `so_state' and `so_rcv' need to be checked atomically, so extend the
> scope of the lock.
> 
> ok?

OK claudio@
 
> Index: kern/sys_socket.c
> ===
> RCS file: /cvs/src/sys/kern/sys_socket.c,v
> retrieving revision 1.30
> diff -u -p -r1.30 sys_socket.c
> --- kern/sys_socket.c 22 Feb 2017 10:20:21 -  1.30
> +++ kern/sys_socket.c 18 Jul 2017 06:41:10 -
> @@ -180,14 +180,13 @@ soo_stat(struct file *fp, struct stat *u
>  
>   memset(ub, 0, sizeof (*ub));
>   ub->st_mode = S_IFSOCK;
> - if ((so->so_state & SS_CANTRCVMORE) == 0 ||
> - so->so_rcv.sb_cc != 0)
> + s = solock(so);
> + if ((so->so_state & SS_CANTRCVMORE) == 0 || so->so_rcv.sb_cc != 0)
>   ub->st_mode |= S_IRUSR | S_IRGRP | S_IROTH;
>   if ((so->so_state & SS_CANTSENDMORE) == 0)
>   ub->st_mode |= S_IWUSR | S_IWGRP | S_IWOTH;
>   ub->st_uid = so->so_euid;
>   ub->st_gid = so->so_egid;
> - s = solock(so);
>   (void) ((*so->so_proto->pr_usrreq)(so, PRU_SENSE,
>   (struct mbuf *)ub, NULL, NULL, p));
>   sounlock(s);
> 

-- 
:wq Claudio



Re: introduction of an additional non-POSIX function in libpthread

2017-07-18 Thread David CARLIER
Oups mistake of mine. good catch

On 18 July 2017 at 14:08, Karel Gardas  wrote:

> Why your patch defines MALLOC_STATS?
>
> -/* #define MALLOC_STATS */
> +#define MALLOC_STATS
>
> On Tue, Jul 18, 2017 at 2:43 PM, David CARLIER  wrote:
> > Ah I recognise you you re Mozilla contributor right ? You re probably
> right
> > but that was just an example eventhough I admit it s not extremely widely
> > used ...
> >
> > On 18 July 2017 at 13:36, Landry Breuil  wrote:
> >
> >> On Tue, Jul 18, 2017 at 01:24:21PM +0100, David CARLIER wrote:
> >> > Hi.
> >> >
> >> > I sent a diff originally to a smaller audience but finally decided to
> >> post
> >> > it in the mailing list.
> >> > So it is to introduce the pthread_set_name_np's counterpart so
> >> > pthread_get_name_np.
> >> > Some softwares use it (NSPR for example) and anyway internally in my
> >> > workplace we have multiplatform needing this feature would be nice
> having
> >> > this for OpenBSD as well :-)
> >>
> >> the js engine uses it:
> >> https://bugzilla.mozilla.org/show_bug.cgi?id=1298451
> >>
> >> but nspr stopped using it or never used it, there's only a reference to
> >> pthread_set_name_np:
> >> https://hg.mozilla.org/projects/nspr/file/tip/pr/src/
> >> pthreads/ptthread.c#l1759
> >>
> >> PR_GetThreadName (just below) returns the 'local' name value, and doesnt
> >> get it from the system.
> >>
> >> Landry
> >>
> >>
>


Re: introduction of an additional non-POSIX function in libpthread

2017-07-18 Thread Karel Gardas
Why your patch defines MALLOC_STATS?

-/* #define MALLOC_STATS */
+#define MALLOC_STATS

On Tue, Jul 18, 2017 at 2:43 PM, David CARLIER  wrote:
> Ah I recognise you you re Mozilla contributor right ? You re probably right
> but that was just an example eventhough I admit it s not extremely widely
> used ...
>
> On 18 July 2017 at 13:36, Landry Breuil  wrote:
>
>> On Tue, Jul 18, 2017 at 01:24:21PM +0100, David CARLIER wrote:
>> > Hi.
>> >
>> > I sent a diff originally to a smaller audience but finally decided to
>> post
>> > it in the mailing list.
>> > So it is to introduce the pthread_set_name_np's counterpart so
>> > pthread_get_name_np.
>> > Some softwares use it (NSPR for example) and anyway internally in my
>> > workplace we have multiplatform needing this feature would be nice having
>> > this for OpenBSD as well :-)
>>
>> the js engine uses it:
>> https://bugzilla.mozilla.org/show_bug.cgi?id=1298451
>>
>> but nspr stopped using it or never used it, there's only a reference to
>> pthread_set_name_np:
>> https://hg.mozilla.org/projects/nspr/file/tip/pr/src/
>> pthreads/ptthread.c#l1759
>>
>> PR_GetThreadName (just below) returns the 'local' name value, and doesnt
>> get it from the system.
>>
>> Landry
>>
>>



Re: introduction of an additional non-POSIX function in libpthread

2017-07-18 Thread David CARLIER
Ah I recognise you you re Mozilla contributor right ? You re probably right
but that was just an example eventhough I admit it s not extremely widely
used ...

On 18 July 2017 at 13:36, Landry Breuil  wrote:

> On Tue, Jul 18, 2017 at 01:24:21PM +0100, David CARLIER wrote:
> > Hi.
> >
> > I sent a diff originally to a smaller audience but finally decided to
> post
> > it in the mailing list.
> > So it is to introduce the pthread_set_name_np's counterpart so
> > pthread_get_name_np.
> > Some softwares use it (NSPR for example) and anyway internally in my
> > workplace we have multiplatform needing this feature would be nice having
> > this for OpenBSD as well :-)
>
> the js engine uses it:
> https://bugzilla.mozilla.org/show_bug.cgi?id=1298451
>
> but nspr stopped using it or never used it, there's only a reference to
> pthread_set_name_np:
> https://hg.mozilla.org/projects/nspr/file/tip/pr/src/
> pthreads/ptthread.c#l1759
>
> PR_GetThreadName (just below) returns the 'local' name value, and doesnt
> get it from the system.
>
> Landry
>
>


Re: intel.4: Typofix

2017-07-18 Thread Klemens Nanni
On Mon, Jul 17, 2017 at 10:38:22PM -0400, Bryan Steele wrote:
> This is an upstream Xorg manual.
> 
> https://lists.x.org/mailman/listinfo/xorg-devel
Reported upstream, thanks.



Re: introduction of an additional non-POSIX function in libpthread

2017-07-18 Thread Landry Breuil
On Tue, Jul 18, 2017 at 01:24:21PM +0100, David CARLIER wrote:
> Hi.
> 
> I sent a diff originally to a smaller audience but finally decided to post
> it in the mailing list.
> So it is to introduce the pthread_set_name_np's counterpart so
> pthread_get_name_np.
> Some softwares use it (NSPR for example) and anyway internally in my
> workplace we have multiplatform needing this feature would be nice having
> this for OpenBSD as well :-)

the js engine uses it:
https://bugzilla.mozilla.org/show_bug.cgi?id=1298451

but nspr stopped using it or never used it, there's only a reference to
pthread_set_name_np:
https://hg.mozilla.org/projects/nspr/file/tip/pr/src/pthreads/ptthread.c#l1759

PR_GetThreadName (just below) returns the 'local' name value, and doesnt
get it from the system.

Landry



Re: SIGBUS short mmap object

2017-07-18 Thread Mark Kettenis
> From: Theo de Raadt 
> Date: Mon, 17 Jul 2017 16:06:05 -0600 (MDT)
> 
> Sorry I disagree.  SIGSEGV is the right answer.  It was not mapped.
> That is segmentation.

Actually it is mapped in the sense that uvm has created mapping
entries for it.  The mapping just isn't backed (because the backing
store was never there, or the file has been truncated in the
meantime).

> A SIGBUS should be delivered when the mode of access is not permitted
> on a valid mapping.

Most of our architectures (but not all) actually return SIGSEGV in
that case.

> I know some other operating systems have gotten extremly sloppy and
> inconsistant in this regard.  And I despise what they did.  It suspect
> they got so used to unaligned-access architectures they then forgot
> the reason why SIGBUS was something else, and wanted to reuse it to
> mean something else before siginfo became popular.  And I think this
> bug came about due to i386 X.

OpenBSD is sloppy as well.  The usual issue of importing from
diffferent vintage NetBSD and FreeBSD is almost certainly at work here.

The SIGBUS for mmap behaviour seems to be lifted straight from the
SunOS 4.1.3 documentation:

  
https://www.freebsd.org/cgi/man.cgi?query=mmap=0=2=SunOS+4.1.3=default=html

Interestingly enough SunOS 5 "allows" both SIGBUS and SIGSEGV:

  
https://www.freebsd.org/cgi/man.cgi?query=mmap=0=2=SunOS+5.10=default=html

Pretty sure things started to diverge in an early stage.  In the old
days, SIGBUS and SIGSEGV simply mapped 1:1 to the VAX MMU traps.  When
different hardware came along with different MMU traps, the trap to
signal mapping simply wasn't always obvious.  Then of course the
introduction of different vm systems caused further divergence.  Your
right that siginfo prompted folks to make further changes.  Was that a
SVR4 thing?

> And if you quote POSIX, I think they are WRONG.  It is irresponsible
> of people to redefine the meanings of objects such that you cannot
> tell what action to take to repair the problem.

Dividing the possible fault scenarios in two classes is always going
to lead to ambiguities.  I suppose that is one of the reasons folks
came up with siginfo.  The competing BSD "solution" of using a sigcode
that encoded the actual hardware trap is pretty much unusable for
writing portable software.

Here's what POSIX has to say about this:

  When an object is mapped, various application accesses to the mapped
  region may result in signals. In this context, SIGBUS is used to
  indicate an error using the mapped object, and SIGSEGV is used to
  indicate a protection violation or misuse of an address:

  * A mapping may be restricted to disallow some types of access.

  * Write attempts to memory that was mapped without write access, or
any access to memory mapped PROT_NONE, shall result in a SIGSEGV
signal.

  * References to unmapped addresses shall result in a SIGSEGV signal.

  * Reference to whole pages within the mapping, but beyond the
current length of the object, shall result in a SIGBUS signal.

  * The size of the object is unaffected by access beyond the end of
the object (even if a SIGBUS is not generated).

I think this is a sensible way of distinguishing between SIGBUS and
SIGSEGV.  It just doesn't match historical practice in BSD land.  And
I can't blame them for following SVR4 here as in BSD land everything
was (and still is) pretty much undocumented.

That said, on many systems (including Linux) the siginfo
implementation is incomplete and sometimes even incorrect.  You cannot
rely on it for writing portable code.  But it is useful for debugging.
The same holds for the mmap SIGBUS behaviour.  The Solaris folks
probably got it right when documenting that either SIGBUS or SIGSEGV
could happen.

Still I think that having more consistency between architectures on
OpenBSD is a good thing.  POSIX provides such a model, even if it
deviates in places from historical behaviour.  I'm not really worried
about those deviations as we don't implement the historical behaviour
consistently anyway.  If you believe that siginfo is a useful thing,
the POSIX interpretation of SIGBUS and SIGSEGV is the only one that
really makes sense.

In other words, I think we should go with bluhm@'s original diff.

> Finally, the diff here only touches 2 architectures.  Which others
> change semantics in some odd way when that uvm diff goes in?

Once we agree on the regression test for this, we can fix the other
archiitectures.



introduction of an additional non-POSIX function in libpthread

2017-07-18 Thread David CARLIER
Hi.

I sent a diff originally to a smaller audience but finally decided to post
it in the mailing list.
So it is to introduce the pthread_set_name_np's counterpart so
pthread_get_name_np.
Some softwares use it (NSPR for example) and anyway internally in my
workplace we have multiplatform needing this feature would be nice having
this for OpenBSD as well :-)

Let me know what you think.

Kind regards.
Index: lib/libc/stdlib/malloc.c
===
RCS file: /cvs/src/lib/libc/stdlib/malloc.c,v
retrieving revision 1.228
diff -u -p -r1.228 malloc.c
--- lib/libc/stdlib/malloc.c10 Jul 2017 09:44:16 -  1.228
+++ lib/libc/stdlib/malloc.c15 Jul 2017 19:54:00 -
@@ -23,7 +23,7 @@
  * can buy me a beer in return. Poul-Henning Kamp
  */
 
-/* #define MALLOC_STATS */
+#define MALLOC_STATS
 
 #include 
 #include  /* PAGE_SHIFT ALIGN */
Index: lib/libpthread/include/pthread_np.h
===
RCS file: /cvs/src/lib/libpthread/include/pthread_np.h,v
retrieving revision 1.11
diff -u -p -r1.11 pthread_np.h
--- lib/libpthread/include/pthread_np.h 22 Mar 2012 17:21:36 -  1.11
+++ lib/libpthread/include/pthread_np.h 15 Jul 2017 19:54:00 -
@@ -46,6 +46,7 @@ __BEGIN_DECLS
 int pthread_mutexattr_getkind_np(pthread_mutexattr_t);
 int pthread_mutexattr_setkind_np(pthread_mutexattr_t *, int);
 void pthread_set_name_np(pthread_t, const char *);
+void pthread_get_name_np(pthread_t, char *, size_t);
 int pthread_stackseg_np(pthread_t, stack_t *);
 int pthread_main_np(void);
 __END_DECLS
Index: lib/libpthread/man/Makefile.inc
===
RCS file: /cvs/src/lib/libpthread/man/Makefile.inc,v
retrieving revision 1.36
diff -u -p -r1.36 Makefile.inc
--- lib/libpthread/man/Makefile.inc 30 Mar 2016 06:38:42 -  1.36
+++ lib/libpthread/man/Makefile.inc 15 Jul 2017 19:54:00 -
@@ -31,6 +31,7 @@ MAN+= \
pthread_detach.3 \
pthread_equal.3 \
pthread_exit.3 \
+   pthread_get_name_np.3 \
pthread_getconcurrency.3 \
pthread_getcpuclockid.3 \
pthread_getspecific.3 \
Index: lib/libpthread/man/pthread_get_name_np.3
===
RCS file: lib/libpthread/man/pthread_get_name_np.3
diff -N lib/libpthread/man/pthread_get_name_np.3
--- /dev/null   1 Jan 1970 00:00:00 -
+++ lib/libpthread/man/pthread_get_name_np.315 Jul 2017 19:54:00 -
@@ -0,0 +1,29 @@
+.Dd $Mdocdate: July 15 2017 $
+.Dt PTHREAD_GET_NAME_NP 3
+.Os
+.Sh NAME
+.Nm pthread_get_name_np
+.Nd get the name of a thread
+.Sh SYNOPSIS
+.In pthread.h
+.In pthread_np.h
+.Ft void
+.Fn pthread_get_name_np "pthread_t thread" "char *name" "size_t len"
+.Sh DESCRIPTION
+The
+.Fn pthread_get_name_np
+function retrieves
+.Fa name associated
+with
+.Fa thread .
+.Pp
+If pthread_set_name_np was not called for this
+.Fa thread
+the name parameter will be empty.
+.Sh SEE ALSO
+.Xr pthreads 3
+.Sh STANDARDS
+The
+.Fn pthread_get_name_np
+function is non-portable and may not be supported with the above
+semantics on other POSIX systems.
Index: lib/libpthread/man/pthreads.3
===
RCS file: /cvs/src/lib/libpthread/man/pthreads.3,v
retrieving revision 1.41
diff -u -p -r1.41 pthreads.3
--- lib/libpthread/man/pthreads.3   16 Jul 2013 15:21:11 -  1.41
+++ lib/libpthread/man/pthreads.3   15 Jul 2017 19:54:00 -
@@ -169,6 +169,8 @@ The functions available are as follows:
 Identify the main thread.
 .It Fn pthread_set_name_np
 Set the name of a thread.
+.It Fn pthread_get_name_np
+Get the name of a thread
 .It Fn pthread_stackseg_np
 Return stack size and location.
 .It Fn pthread_yield
@@ -421,6 +423,7 @@ with larger numbers generating more verb
 .Xr pthread_detach 3 ,
 .Xr pthread_equal 3 ,
 .Xr pthread_exit 3 ,
+.Xr pthread_get_name_np 3 ,
 .Xr pthread_getcpuclockid 3 ,
 .Xr pthread_getspecific 3 ,
 .Xr pthread_join 3 ,
Index: lib/librthread/Symbols.map
===
RCS file: /cvs/src/lib/librthread/Symbols.map,v
retrieving revision 1.3
diff -u -p -r1.3 Symbols.map
--- lib/librthread/Symbols.map  27 Feb 2017 07:15:22 -  1.3
+++ lib/librthread/Symbols.map  15 Jul 2017 19:54:00 -
@@ -54,6 +54,7 @@
pthread_detach;
pthread_equal;
pthread_exit;
+   pthread_get_name_np;
pthread_getconcurrency;
pthread_getcpuclockid;
pthread_getprio;
Index: lib/librthread/pthread_np.h
===
RCS file: /cvs/src/lib/librthread/pthread_np.h,v
retrieving revision 1.1
diff -u -p -r1.1 pthread_np.h
--- lib/librthread/pthread_np.h 2 Apr 2016 19:56:53 -   1.1
+++ lib/librthread/pthread_np.h 15 Jul 2017 19:54:00 

Re: Extend the scope of socket lock in soo_stat()

2017-07-18 Thread Alexander Bluhm
On Tue, Jul 18, 2017 at 08:42:51AM +0200, Martin Pieuchot wrote:
> `so_state' and `so_rcv' need to be checked atomically, so extend the
> scope of the lock.
> 
> ok?

OK bluhm@

> 
> Index: kern/sys_socket.c
> ===
> RCS file: /cvs/src/sys/kern/sys_socket.c,v
> retrieving revision 1.30
> diff -u -p -r1.30 sys_socket.c
> --- kern/sys_socket.c 22 Feb 2017 10:20:21 -  1.30
> +++ kern/sys_socket.c 18 Jul 2017 06:41:10 -
> @@ -180,14 +180,13 @@ soo_stat(struct file *fp, struct stat *u
>  
>   memset(ub, 0, sizeof (*ub));
>   ub->st_mode = S_IFSOCK;
> - if ((so->so_state & SS_CANTRCVMORE) == 0 ||
> - so->so_rcv.sb_cc != 0)
> + s = solock(so);
> + if ((so->so_state & SS_CANTRCVMORE) == 0 || so->so_rcv.sb_cc != 0)
>   ub->st_mode |= S_IRUSR | S_IRGRP | S_IROTH;
>   if ((so->so_state & SS_CANTSENDMORE) == 0)
>   ub->st_mode |= S_IWUSR | S_IWGRP | S_IWOTH;
>   ub->st_uid = so->so_euid;
>   ub->st_gid = so->so_egid;
> - s = solock(so);
>   (void) ((*so->so_proto->pr_usrreq)(so, PRU_SENSE,
>   (struct mbuf *)ub, NULL, NULL, p));
>   sounlock(s);



Re: soo_ioctl() & socket lock

2017-07-18 Thread Alexander Bluhm
On Tue, Jul 18, 2017 at 08:38:56AM +0200, Martin Pieuchot wrote:
> Where soo_ioctl() modifies `so_state', `so_rcv' or `so_snd' it needs the
> socket lock.
> 
> More fields might need the lock in the future but for the moment I'm
> concentrating on fields accessed in the TCP input path.
> 
> ok?

OK bluhm@

> 
> Index: kern/sys_socket.c
> ===
> RCS file: /cvs/src/sys/kern/sys_socket.c,v
> retrieving revision 1.30
> diff -u -p -r1.30 sys_socket.c
> --- kern/sys_socket.c 22 Feb 2017 10:20:21 -  1.30
> +++ kern/sys_socket.c 18 Jul 2017 06:26:15 -
> @@ -78,13 +78,16 @@ soo_ioctl(struct file *fp, u_long cmd, c
>   switch (cmd) {
>  
>   case FIONBIO:
> + s = solock(so);
>   if (*(int *)data)
>   so->so_state |= SS_NBIO;
>   else
>   so->so_state &= ~SS_NBIO;
> - return (0);
> + sounlock(s);
> + break;
>  
>   case FIOASYNC:
> + s = solock(so);
>   if (*(int *)data) {
>   so->so_state |= SS_ASYNC;
>   so->so_rcv.sb_flags |= SB_ASYNC;
> @@ -94,43 +97,47 @@ soo_ioctl(struct file *fp, u_long cmd, c
>   so->so_rcv.sb_flags &= ~SB_ASYNC;
>   so->so_snd.sb_flags &= ~SB_ASYNC;
>   }
> - return (0);
> + sounlock(s);
> + break;
>  
>   case FIONREAD:
>   *(int *)data = so->so_rcv.sb_datacc;
> - return (0);
> + break;
>  
>   case SIOCSPGRP:
>   so->so_pgid = *(int *)data;
>   so->so_siguid = p->p_ucred->cr_ruid;
>   so->so_sigeuid = p->p_ucred->cr_uid;
> - return (0);
> + break;
>  
>   case SIOCGPGRP:
>   *(int *)data = so->so_pgid;
> - return (0);
> + break;
>  
>   case SIOCATMARK:
>   *(int *)data = (so->so_state_RCVATMARK) != 0;
> - return (0);
> - }
> - /*
> -  * Interface/routing/protocol specific ioctls:
> -  * interface and routing ioctls should have a
> -  * different entry since a socket's unnecessary
> -  */
> - if (IOCGROUP(cmd) == 'i') {
> - NET_LOCK(s);
> - error = ifioctl(so, cmd, data, p);
> - NET_UNLOCK(s);
> - return (error);
> + break;
> +
> + default:
> + /*
> +  * Interface/routing/protocol specific ioctls:
> +  * interface and routing ioctls should have a
> +  * different entry since a socket's unnecessary
> +  */
> + if (IOCGROUP(cmd) == 'i') {
> + NET_LOCK(s);
> + error = ifioctl(so, cmd, data, p);
> + NET_UNLOCK(s);
> + return (error);
> + }
> + if (IOCGROUP(cmd) == 'r')
> + return (EOPNOTSUPP);
> + s = solock(so);
> + error = ((*so->so_proto->pr_usrreq)(so, PRU_CONTROL,
> + (struct mbuf *)cmd, (struct mbuf *)data, NULL, p));
> + sounlock(s);
> + break;
>   }
> - if (IOCGROUP(cmd) == 'r')
> - return (EOPNOTSUPP);
> - s = solock(so);
> - error = ((*so->so_proto->pr_usrreq)(so, PRU_CONTROL, 
> - (struct mbuf *)cmd, (struct mbuf *)data, (struct mbuf *)NULL, p));
> - sounlock(s);
>  
>   return (error);
>  }



Re: urndis issues

2017-07-18 Thread Mike Belopuhov
On Thu, Jul 13, 2017 at 14:04 +0200, Mike Belopuhov wrote:
> On Wed, Jul 12, 2017 at 21:04 +, Jonathan Armani wrote:
> > Hi,
> > 
> > Thanks I was cooking the same diff.
> > 
> > Ok armani@
> > 
> 
> Hi, thanks! I want to get rid of printfs though and
> return errors (or unhandled status codes) so that we
> don't paper over them. In theory, all error codes that
> I've seen in the ndis.h from the DDK have the MSB set,
> i.e. (rval & 0x8000) != 0 for those, but doing it
> would be a bit too hackish IMO. However, if we go down
> this road the rval check can be rewritten as:
> 
>   /* Not an error */
>   if ((rval & 0x8000) == 0)
>   rval = RNDIS_STATUS_SUCCESS;
>   else
>   printf("%s: status 0x%x\n", DEVNAME(sc), rval);
> 
> Is this something we want to do?
> 
> I was also going to add sc_link toggled by those status
> codes and check it in the urndis_start like other USB
> Ethernet drivers do, but decided against it cause this
> would break other devices that don't send this message.
>

Hi,

Since I haven't heard anything from any of you, I'm assuming
that the diff below is the way to go (since that's what Artturi
has tested essentially).  I'll wait another day and check this
in tomorrow (July 19).

Cheers,
Mike

> 
> diff --git sys/dev/usb/if_urndis.c sys/dev/usb/if_urndis.c
> index 4af6b55cf05..956207f73a8 100644
> --- sys/dev/usb/if_urndis.c
> +++ sys/dev/usb/if_urndis.c
> @@ -88,10 +88,12 @@ u_int32_t urndis_ctrl_handle_init(struct urndis_softc *,
>  const struct rndis_comp_hdr *);
>  u_int32_t urndis_ctrl_handle_query(struct urndis_softc *,
>  const struct rndis_comp_hdr *, void **, size_t *);
>  u_int32_t urndis_ctrl_handle_reset(struct urndis_softc *,
>  const struct rndis_comp_hdr *);
> +u_int32_t urndis_ctrl_handle_status(struct urndis_softc *,
> +const struct rndis_comp_hdr *);
>  
>  u_int32_t urndis_ctrl_init(struct urndis_softc *);
>  u_int32_t urndis_ctrl_halt(struct urndis_softc *);
>  u_int32_t urndis_ctrl_query(struct urndis_softc *, u_int32_t, void *, size_t,
>  void **, size_t *);
> @@ -233,10 +235,14 @@ urndis_ctrl_handle(struct urndis_softc *sc, struct 
> rndis_comp_hdr *hdr,
>   case REMOTE_NDIS_KEEPALIVE_CMPLT:
>   case REMOTE_NDIS_SET_CMPLT:
>   rval = letoh32(hdr->rm_status);
>   break;
>  
> + case REMOTE_NDIS_INDICATE_STATUS_MSG:
> + rval = urndis_ctrl_handle_status(sc, hdr);
> + break;
> +
>   default:
>   printf("%s: ctrl message error: unknown event 0x%x\n",
>   DEVNAME(sc), letoh32(hdr->rm_type));
>   rval = RNDIS_STATUS_FAILURE;
>   }
> @@ -400,10 +406,42 @@ urndis_ctrl_handle_reset(struct urndis_softc *sc,
>  
>   return rval;
>  }
>  
>  u_int32_t
> +urndis_ctrl_handle_status(struct urndis_softc *sc,
> +const struct rndis_comp_hdr *hdr)
> +{
> + const struct rndis_status_msg   *msg;
> + u_int32_trval;
> +
> + msg = (struct rndis_status_msg *)hdr;
> +
> + rval = letoh32(msg->rm_status);
> +
> + DPRINTF(("%s: urndis_ctrl_handle_status: len %u status 0x%x "
> + "stbuflen %u\n",
> + DEVNAME(sc),
> + letoh32(msg->rm_len),
> + rval,
> + letoh32(msg->rm_stbuflen)));
> +
> + switch (rval) {
> + case RNDIS_STATUS_MEDIA_CONNECT:
> + case RNDIS_STATUS_MEDIA_DISCONNECT:
> + case RNDIS_STATUS_OFFLOAD_CURRENT_CONFIG:
> + rval = RNDIS_STATUS_SUCCESS;
> + break;
> +
> + default:
> + printf("%s: status 0x%x\n", DEVNAME(sc), rval);
> + }
> +
> + return rval;
> +}
> +
> +u_int32_t
>  urndis_ctrl_init(struct urndis_softc *sc)
>  {
>   struct rndis_init_req   *msg;
>   u_int32_trval;
>   struct rndis_comp_hdr   *hdr;



Re: filt_soread() & socket lock

2017-07-18 Thread Alexander Bluhm
On Tue, Jul 18, 2017 at 08:25:38AM +0200, Martin Pieuchot wrote:
>  #ifdef SOCKET_SPLICE
>   if (isspliced(so))
> - return (0);
> + rv = 0;
> + else
>  #endif /* SOCKET_SPLICE */

You could use braces "if {...} else" here to be consistent with the
other if else.

anyway OK bluhm@



Re: SIGBUS short mmap object

2017-07-18 Thread Alexander Bluhm
On Mon, Jul 17, 2017 at 04:06:05PM -0600, Theo de Raadt wrote:
> Finally, the diff here only touches 2 architectures.

Yes, I know.  But why work on the others if the change is not
accepted anyway.

> Where is this coming from?  Is it just to satisfy a regress test?

My concern is only the regress test.  I am totally fine to adapt
the test instead of the kernel.  But I don't know why the test was
written that way.  In general I think commiting tests for bugs or
features someone else should fix later is a bad idea.

This adapts the test to the current behavior.  The SEGV_ACCERR looks
wrong.  Should I try to set SEGV_MAPERR in the kernel?

bluhm

Index: regress/sys/kern/siginfo-fault/siginfo-fault.c
===
RCS file: 
/data/mirror/openbsd/cvs/src/regress/sys/kern/siginfo-fault/siginfo-fault.c,v
retrieving revision 1.4
diff -u -p -r1.4 siginfo-fault.c
--- regress/sys/kern/siginfo-fault/siginfo-fault.c  13 Jul 2017 00:29:14 
-  1.4
+++ regress/sys/kern/siginfo-fault/siginfo-fault.c  18 Jul 2017 09:23:57 
-
@@ -156,7 +156,7 @@ main()
p[3] = 1;
FAIL();
}
-   fail += checksig("mmap file", SIGBUS, BUS_ADRERR, p + 3);
+   fail += checksig("mmap file", SIGSEGV, SEGV_ACCERR, p + 3);
 
return (fail);
 }



Re: [PATCH] ure improvement

2017-07-18 Thread Martin Pieuchot
On 17/07/17(Mon) 15:24, sc dying wrote:
> On 2017/07/17 08:24, Martin Pieuchot wrote:
> > On 15/07/17(Sat) 21:16, sc dying wrote:
> >> This patch does:
> >>
> >> - Enable RX aggregation.
> >
> > Does it work on all chips?
> 
> I don't have all, but it works with mine that have RTL8152 (ver 4c10)
> and RTL8153 (ver 5c20).

That's the two supported chips, so that should be good enough.

> >> - Call usbd_set_config before configuring endpoints in ure_init to fix
> >>an error when re-opening pipes.  I grabbed the code from if_kue.c.
> >
> > Which error? Calling usbd_set_config() should be avoid as much as
> > possible in driver code.
> 
> Without patch, ure on usb-3 port says this error
> 
> ure0: usb errors on rx: IOERROR
> 
> when down the interface and it up.

This is certainly a bug in the way pipe are closed, or more likely in
xhci(4).  Can you reproduce the problem on ehci(4)?  Do you find
anything useful if you define XHCI_DEBUG in your kernel?



Re: [patch] enable calling chroot(2) after calling pledge(2)

2017-07-18 Thread Theo Buehler
On Tue, Jul 18, 2017 at 02:44:12AM +, Matt Miller wrote:
> I would like to be able to call chroot(2) in a program that uses pledge(2).

You need to postpone the pledge(2) calls until after chroot(2). Look at
any of the pledged privsep daemons to see how this was dealt with in
base. Also check the logs to see the refactorings that were made to
ensure that pledge covers as much ground as possible, even without
having chroot available when pledged.

> The following (untested) patch makes this possible as part of the "rpath"
> promise.

Adding a syscall to a widely used promise allows it in all programs that
make that promise. Therefore this needs a lot of thought and careful
investigation.

Your patch allows more than 350 programs in the base system to call a
tricky and dangerous thing like chroot(2). Most of them have no business
doing that...

> Does this seem like a reasonable idea?

If you look at the commit logs for sys/kern/kern_pledge.c and
sys/kern/vfs_syscalls.c, you can see that chroot(2) used to be allowed
with "rpath proc id" in 5.9. It was removed in 6.0 since its semantics
turned out to lead to a lot of complications with the (not yet fully
implemented) whitelisted paths feature of pledge.

> 
> 
> --- sys/kern/kern_pledge.cThu Jun 29 00:10:07 2017
> +++ sys/kern/kern_pledge.c.with_chroot  Mon Jul 17 22:32:43 2017
> @@ -292,6 +292,7 @@
> [SYS_execve] = PLEDGE_EXEC,
> 
> [SYS_chdir] = PLEDGE_RPATH,
> +   [SYS_chroot] = PLEDGE_RPATH,
> [SYS_openat] = PLEDGE_RPATH | PLEDGE_WPATH,
> [SYS_fstatat] = PLEDGE_RPATH | PLEDGE_WPATH,
> [SYS_faccessat] = PLEDGE_RPATH | PLEDGE_WPATH,
> 
> 



connect(2), KERNEL_LOCK() vs socket lock

2017-07-18 Thread Martin Pieuchot
sys_connect() currently relies on the KERNEL_LOCK() to be sure
`so_state' isn't changing while it manipulates the socket.  Since
we want to remove the KERNEL_LOCK() from the Network Stack, we need
a way to guaranty this atomicity.

Diff below extends the scope of the socket lock.  It has been previously
introduced in sys_connect(), first as NET_LOCK() then renamed, where old
splsofnet() were used.  But we now need to "move the line up" in order to
protect fields currently relying on the KERNEL_LOCK().

Moving the line up means that soconnect() and soconnect2() will now
assert for the socket lock.  This will allow to remove superfluous lock-
unlock dances, especially in NFS.

ok?

Index: kern/uipc_socket.c
===
RCS file: /cvs/src/sys/kern/uipc_socket.c,v
retrieving revision 1.194
diff -u -p -r1.194 uipc_socket.c
--- kern/uipc_socket.c  13 Jul 2017 16:19:38 -  1.194
+++ kern/uipc_socket.c  18 Jul 2017 06:46:18 -
@@ -311,11 +311,12 @@ soaccept(struct socket *so, struct mbuf 
 int
 soconnect(struct socket *so, struct mbuf *nam)
 {
-   int s, error;
+   int error;
+
+   soassertlocked(so);
 
if (so->so_options & SO_ACCEPTCONN)
return (EOPNOTSUPP);
-   s = solock(so);
/*
 * If protocol is connection-based, can only connect once.
 * Otherwise, if connected, try to disconnect first.
@@ -329,19 +330,17 @@ soconnect(struct socket *so, struct mbuf
else
error = (*so->so_proto->pr_usrreq)(so, PRU_CONNECT,
NULL, nam, NULL, curproc);
-   sounlock(s);
return (error);
 }
 
 int
 soconnect2(struct socket *so1, struct socket *so2)
 {
-   int s, error;
+   int error;
 
-   s = solock(so1);
+   soassertlocked(so1);
error = (*so1->so_proto->pr_usrreq)(so1, PRU_CONNECT2, NULL,
(struct mbuf *)so2, NULL, curproc);
-   sounlock(s);
return (error);
 }
 
Index: kern/uipc_syscalls.c
===
RCS file: /cvs/src/sys/kern/uipc_syscalls.c,v
retrieving revision 1.153
diff -u -p -r1.153 uipc_syscalls.c
--- kern/uipc_syscalls.c12 Jul 2017 09:25:47 -  1.153
+++ kern/uipc_syscalls.c18 Jul 2017 06:46:18 -
@@ -373,9 +373,10 @@ sys_connect(struct proc *p, void *v, reg
if ((error = getsock(p, SCARG(uap, s), )) != 0)
return (error);
so = fp->f_data;
+   s = solock(so);
if (so->so_state & SS_ISCONNECTING) {
-   FRELE(fp, p);
-   return (EALREADY);
+   error = EALREADY;
+   goto out;
}
error = sockargs(, SCARG(uap, name), SCARG(uap, namelen),
MT_SONAME);
@@ -393,11 +394,8 @@ sys_connect(struct proc *p, void *v, reg
if (isdnssocket(so)) {
u_int namelen = nam->m_len;
error = dns_portcheck(p, so, mtod(nam, void *), );
-   if (error) {
-   FRELE(fp, p);
-   m_freem(nam);
-   return (error);
-   }
+   if (error)
+   goto out;
nam->m_len = namelen;
}
 
@@ -405,11 +403,9 @@ sys_connect(struct proc *p, void *v, reg
if (error)
goto bad;
if ((so->so_state & SS_NBIO) && (so->so_state & SS_ISCONNECTING)) {
-   FRELE(fp, p);
-   m_freem(nam);
-   return (EINPROGRESS);
+   error = EINPROGRESS;
+   goto out;
}
-   s = solock(so);
while ((so->so_state & SS_ISCONNECTING) && so->so_error == 0) {
error = sosleep(so, >so_timeo, PSOCK | PCATCH,
"netcon2", 0);
@@ -423,10 +419,11 @@ sys_connect(struct proc *p, void *v, reg
error = so->so_error;
so->so_error = 0;
}
-   sounlock(s);
 bad:
if (!interrupted)
so->so_state &= ~SS_ISCONNECTING;
+out:
+   sounlock(s);
FRELE(fp, p);
m_freem(nam);
if (error == ERESTART)
Index: miscfs/fifofs/fifo_vnops.c
===
RCS file: /cvs/src/sys/miscfs/fifofs/fifo_vnops.c,v
retrieving revision 1.57
diff -u -p -r1.57 fifo_vnops.c
--- miscfs/fifofs/fifo_vnops.c  8 Jul 2017 09:19:02 -   1.57
+++ miscfs/fifofs/fifo_vnops.c  18 Jul 2017 06:46:18 -
@@ -124,7 +124,7 @@ fifo_open(void *v)
struct fifoinfo *fip;
struct proc *p = ap->a_p;
struct socket *rso, *wso;
-   int error;
+   int s, error;
 
if ((fip = vp->v_fifoinfo) == NULL) {
fip = malloc(sizeof(*fip), M_VNODE, M_WAITOK);
@@ -135,6 +135,11 @@ fifo_open(void *v)
return (error);
}
fip->fi_readsock = rso;
+   /*
+* XXXSMP
+  

Extend the scope of socket lock in soo_stat()

2017-07-18 Thread Martin Pieuchot
`so_state' and `so_rcv' need to be checked atomically, so extend the
scope of the lock.

ok?

Index: kern/sys_socket.c
===
RCS file: /cvs/src/sys/kern/sys_socket.c,v
retrieving revision 1.30
diff -u -p -r1.30 sys_socket.c
--- kern/sys_socket.c   22 Feb 2017 10:20:21 -  1.30
+++ kern/sys_socket.c   18 Jul 2017 06:41:10 -
@@ -180,14 +180,13 @@ soo_stat(struct file *fp, struct stat *u
 
memset(ub, 0, sizeof (*ub));
ub->st_mode = S_IFSOCK;
-   if ((so->so_state & SS_CANTRCVMORE) == 0 ||
-   so->so_rcv.sb_cc != 0)
+   s = solock(so);
+   if ((so->so_state & SS_CANTRCVMORE) == 0 || so->so_rcv.sb_cc != 0)
ub->st_mode |= S_IRUSR | S_IRGRP | S_IROTH;
if ((so->so_state & SS_CANTSENDMORE) == 0)
ub->st_mode |= S_IWUSR | S_IWGRP | S_IWOTH;
ub->st_uid = so->so_euid;
ub->st_gid = so->so_egid;
-   s = solock(so);
(void) ((*so->so_proto->pr_usrreq)(so, PRU_SENSE,
(struct mbuf *)ub, NULL, NULL, p));
sounlock(s);



soo_ioctl() & socket lock

2017-07-18 Thread Martin Pieuchot
Where soo_ioctl() modifies `so_state', `so_rcv' or `so_snd' it needs the
socket lock.

More fields might need the lock in the future but for the moment I'm
concentrating on fields accessed in the TCP input path.

ok?

Index: kern/sys_socket.c
===
RCS file: /cvs/src/sys/kern/sys_socket.c,v
retrieving revision 1.30
diff -u -p -r1.30 sys_socket.c
--- kern/sys_socket.c   22 Feb 2017 10:20:21 -  1.30
+++ kern/sys_socket.c   18 Jul 2017 06:26:15 -
@@ -78,13 +78,16 @@ soo_ioctl(struct file *fp, u_long cmd, c
switch (cmd) {
 
case FIONBIO:
+   s = solock(so);
if (*(int *)data)
so->so_state |= SS_NBIO;
else
so->so_state &= ~SS_NBIO;
-   return (0);
+   sounlock(s);
+   break;
 
case FIOASYNC:
+   s = solock(so);
if (*(int *)data) {
so->so_state |= SS_ASYNC;
so->so_rcv.sb_flags |= SB_ASYNC;
@@ -94,43 +97,47 @@ soo_ioctl(struct file *fp, u_long cmd, c
so->so_rcv.sb_flags &= ~SB_ASYNC;
so->so_snd.sb_flags &= ~SB_ASYNC;
}
-   return (0);
+   sounlock(s);
+   break;
 
case FIONREAD:
*(int *)data = so->so_rcv.sb_datacc;
-   return (0);
+   break;
 
case SIOCSPGRP:
so->so_pgid = *(int *)data;
so->so_siguid = p->p_ucred->cr_ruid;
so->so_sigeuid = p->p_ucred->cr_uid;
-   return (0);
+   break;
 
case SIOCGPGRP:
*(int *)data = so->so_pgid;
-   return (0);
+   break;
 
case SIOCATMARK:
*(int *)data = (so->so_state_RCVATMARK) != 0;
-   return (0);
-   }
-   /*
-* Interface/routing/protocol specific ioctls:
-* interface and routing ioctls should have a
-* different entry since a socket's unnecessary
-*/
-   if (IOCGROUP(cmd) == 'i') {
-   NET_LOCK(s);
-   error = ifioctl(so, cmd, data, p);
-   NET_UNLOCK(s);
-   return (error);
+   break;
+
+   default:
+   /*
+* Interface/routing/protocol specific ioctls:
+* interface and routing ioctls should have a
+* different entry since a socket's unnecessary
+*/
+   if (IOCGROUP(cmd) == 'i') {
+   NET_LOCK(s);
+   error = ifioctl(so, cmd, data, p);
+   NET_UNLOCK(s);
+   return (error);
+   }
+   if (IOCGROUP(cmd) == 'r')
+   return (EOPNOTSUPP);
+   s = solock(so);
+   error = ((*so->so_proto->pr_usrreq)(so, PRU_CONTROL,
+   (struct mbuf *)cmd, (struct mbuf *)data, NULL, p));
+   sounlock(s);
+   break;
}
-   if (IOCGROUP(cmd) == 'r')
-   return (EOPNOTSUPP);
-   s = solock(so);
-   error = ((*so->so_proto->pr_usrreq)(so, PRU_CONTROL, 
-   (struct mbuf *)cmd, (struct mbuf *)data, (struct mbuf *)NULL, p));
-   sounlock(s);
 
return (error);
 }



filt_soread() & socket lock

2017-07-18 Thread Martin Pieuchot
The socket checks in filt_soread() should be atomic.  As found in the
past week it is not possible to call solock() there because we're not
allowed to sleep.  However I'd like to prepare the function for future
locking in order to keep the locking diff minimal.

ok?

Index: kern/uipc_socket.c
===
RCS file: /cvs/src/sys/kern/uipc_socket.c,v
retrieving revision 1.194
diff -u -p -r1.194 uipc_socket.c
--- kern/uipc_socket.c  13 Jul 2017 16:19:38 -  1.194
+++ kern/uipc_socket.c  18 Jul 2017 06:21:51 -
@@ -1965,22 +1965,27 @@ int
 filt_soread(struct knote *kn, long hint)
 {
struct socket *so = kn->kn_fp->f_data;
+   int rv;
 
kn->kn_data = so->so_rcv.sb_cc;
 #ifdef SOCKET_SPLICE
if (isspliced(so))
-   return (0);
+   rv = 0;
+   else
 #endif /* SOCKET_SPLICE */
if (so->so_state & SS_CANTRCVMORE) {
kn->kn_flags |= EV_EOF;
kn->kn_fflags = so->so_error;
-   return (1);
+   rv = 1;
+   } else if (so->so_error) {  /* temporary udp error */
+   rv = 1;
+   } else if (kn->kn_sfflags & NOTE_LOWAT) {
+   rv = (kn->kn_data >= kn->kn_sdata);
+   } else {
+   rv = (kn->kn_data >= so->so_rcv.sb_lowat);
}
-   if (so->so_error)   /* temporary udp error */
-   return (1);
-   if (kn->kn_sfflags & NOTE_LOWAT)
-   return (kn->kn_data >= kn->kn_sdata);
-   return (kn->kn_data >= so->so_rcv.sb_lowat);
+
+   return rv;
 }
 
 void