Relayd bug and uncommitted fix

2015-07-28 Thread trondd
There has been an outstanding relayd bug reported to bugs@ with a patch. 
I've been maintaining this fix locally for some time.  Did it just fall
through the cracks or is there a reason it hasn't been applied?

http://marc.info/?l=openbsd-bugs&m=142644133217938&w=2

I use this functionality as a substitue for SNI.

Tim.



Re: audio: recover after missed interrupts

2015-07-28 Thread Alexey Suslikov
Alexandre Ratchov  caoua.org> writes:

> DPRINTFN(1, "%s: rec ptr wrapped, moving %d blocs\n",
> DPRINTFN(1, "%s: play ptr wrapped, moving %d blocs\n",

"blocs" in above DPRINTFNs should be "blocks", I think.



Re: Do not hide actual error for setusercontext

2015-07-28 Thread Vadim Zhukov
2015-07-28 16:59 GMT+03:00 Ted Unangst :
> Vadim Zhukov wrote:
>> I see no point in hidding underlying error message from user.
>> Found while preparing chroot for doas run tests.
>>
>> Okay?
>
> setusercontext(3) doesn't say anything about setting errno, so it's not clear
> it will always be set or to a correct value.

You're right. I've stepped into the login_cap.c and realized it
doesn't always care about errno. I don't feel myself brave enough to
clean this up, just lets discard the subject diff then. Sorry for the
noise.

--
  WBR,
  Vadim Zhukov



Re: doas keepenv fix

2015-07-28 Thread Ted Unangst
Vadim Zhukov wrote:
> This fixes (as t-run-keepenv-path says) the problem found be Ze Loff:
> http://marc.info/?l=openbsd-misc&m=143807620616845&w=2
> 
> Okay?

ah, oops. that was supposed to be --nextras i think, but it's clearer this
way.

> --
> WBR,
>   Vadim Zhukov
> 
> 
> Index: doas.c
> ===
> RCS file: /cvs/src/usr.bin/doas/doas.c,v
> retrieving revision 1.27
> diff -u -p -r1.27 doas.c
> --- doas.c26 Jul 2015 22:44:33 -  1.27
> +++ doas.c28 Jul 2015 13:02:31 -
> @@ -256,8 +256,10 @@ copyenv(const char **oldenvp, struct rul
>   size_t j;
>   for (j = 0; j < nextras; j++) {
>   if (strcmp(extra[j], safeset[i]) == 0) {
> - extra[j--] = extra[nextras--];
> + nextras--;
> + extra[j] = extra[nextras];
>   extra[nextras] = NULL;
> + j--;
>   }
>   }
>   }
> 



Re: Do not hide actual error for setusercontext

2015-07-28 Thread Ted Unangst
Vadim Zhukov wrote:
> I see no point in hidding underlying error message from user.
> Found while preparing chroot for doas run tests.
> 
> Okay?

setusercontext(3) doesn't say anything about setting errno, so it's not clear
it will always be set or to a correct value.



Re: Do not hide actual error for setusercontext

2015-07-28 Thread Marc Espie
On Tue, Jul 28, 2015 at 04:10:37PM +0300, Vadim Zhukov wrote:
> I see no point in hidding underlying error message from user.
> Found while preparing chroot for doas run tests.
> 
> Okay?
> 
> --
> WBR,
>   Vadim Zhukov
> 
> 
> Index: doas.c
> ===
> RCS file: /cvs/src/usr.bin/doas/doas.c,v
> retrieving revision 1.27
> diff -u -p -r1.27 doas.c
> --- doas.c26 Jul 2015 22:44:33 -  1.27
> +++ doas.c28 Jul 2015 13:08:05 -
> @@ -417,7 +424,7 @@ main(int argc, char **argv, char **envp)
>   if (setusercontext(NULL, pw, target, LOGIN_SETGROUP |
>   LOGIN_SETPRIORITY | LOGIN_SETRESOURCES | LOGIN_SETUMASK |
>   LOGIN_SETUSER) != 0)
> - errx(1, "failed to set user context for target");
> + err(1, "failed to set user context for target");
>  
>   syslog(LOG_AUTHPRIV | LOG_INFO, "%s ran command as %s: %s",
>   myname, pw->pw_name, cmdline);
Okay from me, although tedu@ should have the last word.



Re: softdep by default on AMD64

2015-07-28 Thread Chris Cappuccio
?? ?? [art.is...@yandex.ru] wrote:
> On Fri, Jul 24, 2015 at 07:56:07AM +0100, Nicholas Marriott wrote:
> > "generally reliable" HAHAHAHAHA
> 
> Why irony? It's more or less true for ALL modern computing system.

Think of it as a selling point. OpenBSD ffs softdep: On the cutting
edge of reliability!



Do not hide actual error for setusercontext

2015-07-28 Thread Vadim Zhukov
I see no point in hidding underlying error message from user.
Found while preparing chroot for doas run tests.

Okay?

--
WBR,
  Vadim Zhukov


Index: doas.c
===
RCS file: /cvs/src/usr.bin/doas/doas.c,v
retrieving revision 1.27
diff -u -p -r1.27 doas.c
--- doas.c  26 Jul 2015 22:44:33 -  1.27
+++ doas.c  28 Jul 2015 13:08:05 -
@@ -417,7 +424,7 @@ main(int argc, char **argv, char **envp)
if (setusercontext(NULL, pw, target, LOGIN_SETGROUP |
LOGIN_SETPRIORITY | LOGIN_SETRESOURCES | LOGIN_SETUMASK |
LOGIN_SETUSER) != 0)
-   errx(1, "failed to set user context for target");
+   err(1, "failed to set user context for target");
 
syslog(LOG_AUTHPRIV | LOG_INFO, "%s ran command as %s: %s",
myname, pw->pw_name, cmdline);



doas keepenv fix

2015-07-28 Thread Vadim Zhukov
This fixes (as t-run-keepenv-path says) the problem found be Ze Loff:
http://marc.info/?l=openbsd-misc&m=143807620616845&w=2

Okay?
--
WBR,
  Vadim Zhukov


Index: doas.c
===
RCS file: /cvs/src/usr.bin/doas/doas.c,v
retrieving revision 1.27
diff -u -p -r1.27 doas.c
--- doas.c  26 Jul 2015 22:44:33 -  1.27
+++ doas.c  28 Jul 2015 13:02:31 -
@@ -256,8 +256,10 @@ copyenv(const char **oldenvp, struct rul
size_t j;
for (j = 0; j < nextras; j++) {
if (strcmp(extra[j], safeset[i]) == 0) {
-   extra[j--] = extra[nextras--];
+   nextras--;
+   extra[j] = extra[nextras];
extra[nextras] = NULL;
+   j--;
}
}
}



Re: ppp(4) tweaks

2015-07-28 Thread Stefan Sperling
On Tue, Jul 28, 2015 at 01:50:01PM +0100, Stuart Henderson wrote:
> Users looking for information about PPP on OpenBSD can easily get the
> wrong impression that IPv6 is not supported at all for any PPP interfaces.
> 
> - add Xr to relevant manpages for the other PPP implementations
> - specifically call out the fact that pppoe(4) supports IPv6
> 
> OK?
> 
> Index: ppp.4
> ===
> RCS file: /cvs/src/share/man/man4/ppp.4,v
> retrieving revision 1.15
> diff -u -p -r1.15 ppp.4
> --- ppp.4 1 Oct 2014 10:05:17 -   1.15
> +++ ppp.4 28 Jul 2015 12:45:23 -
> @@ -64,7 +64,9 @@ family; the packet was dropped.
>  .Xr hostname.if 5 ,
>  .Xr ifconfig 8 ,
>  .Xr netstart 8 ,
> +.Xr pppoe 4 ,
>  .Xr pppd 8 ,
> +.Xr pppx 4 ,
>  .Xr pppstats 8
>  .Sh STANDARDS
>  .Rs

I believe we sort SEE ALSO by man section first, then alphabet.

Apart from that, ok with me.

> @@ -81,4 +83,8 @@ device appeared in
>  .Sh BUGS
>  Currently, only the
>  .Xr ip 4
> -protocol is supported.
> +protocol is supported by this device.
> +Note that the
> +.Xr pppoe 4
> +device does support
> +.Xr ip6 4 .
> 



ppp(4) tweaks

2015-07-28 Thread Stuart Henderson
Users looking for information about PPP on OpenBSD can easily get the
wrong impression that IPv6 is not supported at all for any PPP interfaces.

- add Xr to relevant manpages for the other PPP implementations
- specifically call out the fact that pppoe(4) supports IPv6

OK?

Index: ppp.4
===
RCS file: /cvs/src/share/man/man4/ppp.4,v
retrieving revision 1.15
diff -u -p -r1.15 ppp.4
--- ppp.4   1 Oct 2014 10:05:17 -   1.15
+++ ppp.4   28 Jul 2015 12:45:23 -
@@ -64,7 +64,9 @@ family; the packet was dropped.
 .Xr hostname.if 5 ,
 .Xr ifconfig 8 ,
 .Xr netstart 8 ,
+.Xr pppoe 4 ,
 .Xr pppd 8 ,
+.Xr pppx 4 ,
 .Xr pppstats 8
 .Sh STANDARDS
 .Rs
@@ -81,4 +83,8 @@ device appeared in
 .Sh BUGS
 Currently, only the
 .Xr ip 4
-protocol is supported.
+protocol is supported by this device.
+Note that the
+.Xr pppoe 4
+device does support
+.Xr ip6 4 .




azalia: rework buffer position reporting code

2015-07-28 Thread Alexandre Ratchov
This diff simplifies the code that reads the DMA pointer and calls
the audio(4) driver accordingly.

- use simpler (and less) data structures, which makes the code
  shorter.

- if multiple interrupts are missed, call audio(4) as many times as
  we missed interrupts (unless the pointer wrapped, which this is
  undetectable, but upper layer handles it)

- fetch the link fifos size in the interrupt handler, as, according
  to the spec it may change dynamically (i haven't seen such a
  device yet, but this costs nothing).

- Certain devices expose the last offset of the link fifo size
  instead of the fifo size itself, in this case audio(4) stays
  one block off (i.e. we don't recover completely from missed
  interrupts). Fix this by incrementing the reported link fifo
  size if it's odd.

OK?

Index: azalia.c
===
RCS file: /cvs/src/sys/dev/pci/azalia.c,v
retrieving revision 1.221
diff -u -p -u -p -r1.221 azalia.c
--- azalia.c11 May 2015 06:46:21 -  1.221
+++ azalia.c28 Jul 2015 07:36:45 -
@@ -123,11 +123,7 @@ typedef struct {
int bufsize;
uint16_t fmt;
int blk;
-   int nblks;  /* # of blocks in the buffer */
-   u_long swpos;   /* position in the audio(4) layer */
-   u_int last_hwpos;   /* last known lpib */
-   u_long hw_base; /* this + lpib = overall position */
-   u_int pos_offs; /* hardware fifo space */
+   unsigned int swpos; /* position in the audio(4) layer */
 } stream_t;
 #define STR_READ_1(s, r)   \
bus_space_read_1((s)->az->iot, (s)->az->ioh, (s)->regbase + HDA_SD_##r)
@@ -3672,7 +3668,6 @@ azalia_stream_init(stream_t *this, azali
this->intr_bit = 1 << regindex;
this->number = strnum;
this->dir = dir;
-   this->pos_offs = STR_READ_2(this, FIFOS) & 0xff;
 
/* setup BDL buffers */
err = azalia_alloc_dmamem(az, sizeof(bdlist_entry_t) * HDA_BDL_MAX,
@@ -3764,7 +3759,6 @@ azalia_stream_start(stream_t *this)
break;
}
}
-   this->nblks = index;
 
DPRINTFN(1, ("%s: size=%d fmt=0x%4.4x index=%d\n",
__func__, this->bufsize, this->fmt, index));
@@ -3813,7 +3807,7 @@ azalia_stream_halt(stream_t *this)
 int
 azalia_stream_intr(stream_t *this)
 {
-   u_long hwpos, swpos;
+   unsigned int lpib, fifos, hwpos, cnt;
u_int8_t sts;
 
sts = STR_READ_1(this, STS);
@@ -3825,31 +3819,30 @@ azalia_stream_intr(stream_t *this)
this->number, sts, HDA_SD_STS_BITS));
 
if (sts & HDA_SD_STS_BCIS) {
-   hwpos = STR_READ_4(this, LPIB) + this->pos_offs;
-   if (hwpos < this->last_hwpos)
-   this->hw_base += this->blk * this->nblks;
-   this->last_hwpos = hwpos;
-   hwpos += this->hw_base;
-
-   /*
-* We got the interrupt, so we should advance our count.
-* But we might *not* advance the count if software is
-* ahead.
-*/
-   swpos = this->swpos + this->blk;
-
-   if (hwpos >= swpos + this->blk) {
-   DPRINTF(("%s: stream %d: swpos %lu hwpos %lu, adding 
intr\n",
-   __func__, this->number, swpos, hwpos));
+   lpib = STR_READ_4(this, LPIB);
+   fifos = STR_READ_2(this, FIFOS);
+   if (fifos & 1)
+   fifos++;
+   hwpos = lpib;
+   if (this->dir == AUMODE_PLAY)
+   hwpos += fifos + 1;
+   if (hwpos >= this->bufsize)
+   hwpos -= this->bufsize;
+   DPRINTFN(2, ("%s: stream %d, pos = %d -> %d, "
+   "lpib = %u, fifos = %u\n", __func__,
+   this->number, this->swpos, hwpos, lpib, fifos));
+   cnt = 0;
+   while (hwpos - this->swpos >= this->blk) {
this->intr(this->intr_arg);
this->swpos += this->blk;
-   } else if (swpos >= hwpos + this->blk) {
-   DPRINTF(("%s: stream %d: swpos %lu hwpos %lu, ignoring 
intr\n",
-   __func__, this->number, swpos, hwpos));
-   return (1);
+   if (this->swpos == this->bufsize)
+   this->swpos = 0;
+   cnt++;
+   }
+   if (cnt != 1) {
+   DPRINTF(("%s: stream %d: hwpos %u, %u intrs\n",
+   __func__, this->number, this->swpos, cnt));
}
-   this->intr(this->intr_arg);
-   this->swpos += this->blk;
}
return (1);
 }
@@ -4233,10 +4226,7 @@ azalia_trigger_output(void *v, void *sta
az->pstrea

audio: ioctl to fetch snapshot of counters

2015-07-28 Thread Alexandre Ratchov
There are 4 audio counters, and we've one ioctl() to get each. So
userland has to call the ioctl() one by one, and must take care to
handle cases when a counters are inconsistent (i.e. don't belong to
the same time). Inconsistencies are extreamly rare produce so the
code is hard to test.

This diff adds the AUDIO_GETPOS ioctl to fetch a snapshot of all
counters in a single call, and adapts libsndio and audioctl to use
it. The logic doesn't change, only the way counters are fetched
from the kernel, so no behaviour change.

OK?

Index: sys/sys/audioio.h
===
RCS file: /cvs/src/sys/sys/audioio.h,v
retrieving revision 1.22
diff -u -p -u -p -r1.22 audioio.h
--- sys/sys/audioio.h   25 Jun 2015 06:43:46 -  1.22
+++ sys/sys/audioio.h   28 Jul 2015 07:32:45 -
@@ -92,6 +92,13 @@ typedef struct audio_offset {
u_int   unused[2];
 } audio_offset_t;
 
+struct audio_pos {
+   unsigned int play_pos;  /* total bytes played */
+   unsigned int play_xrun; /* bytes of silence inserted */
+   unsigned int rec_pos;   /* total bytes recorded */
+   unsigned int rec_xrun;  /* bytes dropped */
+};
+
 /*
  * Supported audio encodings
  */
@@ -141,6 +148,7 @@ typedef struct audio_encoding {
 #define AUDIO_GETIOFFS _IOR('A', 32, struct audio_offset)
 #define AUDIO_GETOOFFS _IOR('A', 33, struct audio_offset)
 #define AUDIO_GETPROPS _IOR('A', 34, int)
+#define AUDIO_GETPOS   _IOR('A', 35, struct audio_pos)
 #define  AUDIO_PROP_FULLDUPLEX 0x01
 #define  AUDIO_PROP_MMAP   0x02
 #define  AUDIO_PROP_INDEPENDENT0x04
Index: sys/dev/audio.c
===
RCS file: /cvs/src/sys/dev/audio.c,v
retrieving revision 1.134
diff -u -p -u -p -r1.134 audio.c
--- sys/dev/audio.c 24 Jul 2015 08:56:45 -  1.134
+++ sys/dev/audio.c 28 Jul 2015 07:32:46 -
@@ -66,9 +66,9 @@ struct audio_buf {
size_t start;   /* first byte used in the FIFO */
size_t used;/* bytes used in the FIFO */
size_t blksz;   /* DMA block size */
-   unsigned long pos;  /* bytes transferred */
-   unsigned long xrun; /* bytes lost by xruns */
struct selinfo sel; /* to record & wakeup poll(2) */
+   unsigned int pos;   /* bytes transferred */
+   unsigned int xrun;  /* bytes lost by xruns */
int blocking;   /* read/write blocking */
 };
 
@@ -106,6 +106,7 @@ struct audio_softc {
unsigned char silence[4];   /* a sample of silence */
int pause;  /* not trying to start DMA */
int active; /* DMA in process */
+   int offs;   /* offset between play & rec dir */
void (*conv_enc)(unsigned char *, int); /* encode to native */
void (*conv_dec)(unsigned char *, int); /* decode to user */
 #if NWSKBD > 0
@@ -348,7 +349,7 @@ audio_pintr(void *addr)
struct audio_softc *sc = addr;
unsigned char *ptr;
size_t count;
-   int error;
+   int error, nblk, todo;
 
MUTEX_ASSERT_LOCKED(&audio_lock);
if (!(sc->mode & AUMODE_PLAY) || !sc->active) {
@@ -360,6 +361,23 @@ audio_pintr(void *addr)
return;
}
 
+   /*
+* check if record pointer wrapped, see explanation
+* in audio_rintr()
+*/
+   if (sc->mode & AUMODE_RECORD) {
+   sc->offs--;
+   nblk = sc->rec.len / sc->rec.blksz;
+   todo = -sc->offs;
+   if (todo >= nblk) {
+   todo -= todo % nblk;
+   DPRINTFN(1, "%s: rec ptr wrapped, moving %d blocs\n",
+   DEVNAME(sc), todo);
+   while (todo-- > 0)
+   audio_rintr(sc);
+   }
+   }
+
sc->play.pos += sc->play.blksz;
audio_fill_sil(sc, sc->play.data + sc->play.start, sc->play.blksz);
audio_buf_rdiscard(&sc->play, sc->play.blksz);
@@ -402,7 +420,7 @@ audio_rintr(void *addr)
struct audio_softc *sc = addr;
unsigned char *ptr;
size_t count;
-   int error;
+   int error, nblk, todo;
 
MUTEX_ASSERT_LOCKED(&audio_lock);
if (!(sc->mode & AUMODE_RECORD) || !sc->active) {
@@ -414,6 +432,30 @@ audio_rintr(void *addr)
return;
}
 
+   /*
+* Interrupts may be masked by other sub-systems during 320ms
+* and more. During such a delay the hardware doesn't stop
+* playing and the play buffer pointers may wrap, this can't be
+* detected and corrected by low level drivers. This makes the
+* record stream ahead of the play stream; this is detected as a
+* hardware anomaly by userland and cause programs to misbehave.
+*
+* We fix this

Re: audio: recover after missed interrupts

2015-07-28 Thread Mike Larkin
On Mon, Jul 27, 2015 at 07:51:15PM +0200, Alexandre Ratchov wrote:
> Sometimes the system may miss enough audio interrupts for DMA
> pointers to wrap, which makes upper layers misbahave.
> 
> This diff makes the audio driver properly recover, by detecting and
> compensating for the missed interrupts. This requires the hardware
> to expose working DMA pointers and the low-level driver to properly
> invoke the mid-layer call-back accordingly (ex. azalia does it).
> 
> This should fix most cases of audio programs stopping during heavy
> system load or VT switching.
> 
> To test this, please install the latest in-tree libsndio and sndiod
> first.
> 
> OK?

For what it's worth, this seems to fix the two cases of stopped
audio I was seeing.

-ml

> 
> --- sys/dev/audio.c.orig  Thu Jul 23 22:20:38 2015
> +++ sys/dev/audio.c   Thu Jul 23 22:37:32 2015
> @@ -106,6 +106,7 @@ struct audio_softc {
>   unsigned char silence[4];   /* a sample of silence */
>   int pause;  /* not trying to start DMA */
>   int active; /* DMA in process */
> + int offs;   /* offset between play & rec dir */
>   void (*conv_enc)(unsigned char *, int); /* encode to native */
>   void (*conv_dec)(unsigned char *, int); /* decode to user */
>  #if NWSKBD > 0
> @@ -348,7 +349,7 @@ audio_pintr(void *addr)
>   struct audio_softc *sc = addr;
>   unsigned char *ptr;
>   size_t count;
> - int error;
> + int error, nblk, todo;
>  
>   MUTEX_ASSERT_LOCKED(&audio_lock);
>   if (!(sc->mode & AUMODE_PLAY) || !sc->active) {
> @@ -360,6 +361,23 @@ audio_pintr(void *addr)
>   return;
>   }
>  
> + /*
> +  * check if record pointer wrapped, see explanation
> +  * in audio_rintr()
> +  */
> + if (sc->mode & AUMODE_RECORD) {
> + sc->offs--;
> + nblk = sc->rec.len / sc->rec.blksz;
> + todo = -sc->offs;
> + if (todo >= nblk) {
> + todo -= todo % nblk;
> + DPRINTFN(1, "%s: rec ptr wrapped, moving %d blocs\n",
> + DEVNAME(sc), todo);
> + while (todo-- > 0)
> + audio_rintr(sc);
> + }
> + }
> +
>   sc->play.pos += sc->play.blksz;
>   audio_fill_sil(sc, sc->play.data + sc->play.start, sc->play.blksz);
>   audio_buf_rdiscard(&sc->play, sc->play.blksz);
> @@ -402,7 +420,7 @@ audio_rintr(void *addr)
>   struct audio_softc *sc = addr;
>   unsigned char *ptr;
>   size_t count;
> - int error;
> + int error, nblk, todo;
>  
>   MUTEX_ASSERT_LOCKED(&audio_lock);
>   if (!(sc->mode & AUMODE_RECORD) || !sc->active) {
> @@ -414,6 +432,30 @@ audio_rintr(void *addr)
>   return;
>   }
>  
> + /*
> +  * Interrupts may be masked by other sub-systems during 320ms
> +  * and more. During such a delay the hardware doesn't stop
> +  * playing and the play buffer pointers may wrap, this can't be
> +  * detected and corrected by low level drivers. This makes the
> +  * record stream ahead of the play stream; this is detected as a
> +  * hardware anomaly by userland and cause programs to misbehave.
> +  *
> +  * We fix this by advancing play position by an integer count of
> +  * full buffers, so it reaches the record position.
> +  */
> + if (sc->mode & AUMODE_PLAY) {
> + sc->offs++;
> + nblk = sc->play.len / sc->play.blksz;
> + todo = sc->offs;
> + if (todo >= nblk) {
> + todo -= todo % nblk;
> + DPRINTFN(1, "%s: play ptr wrapped, moving %d blocs\n",
> + DEVNAME(sc), todo);
> + while (todo-- > 0)
> + audio_pintr(sc);
> + }
> + }
> +
>   sc->rec.pos += sc->rec.blksz;
>   audio_buf_wcommit(&sc->rec, sc->rec.blksz);
>   if (sc->rec.used == sc->rec.len) {
> @@ -464,6 +506,7 @@ audio_start_do(struct audio_softc *sc)
>   sc->rec.len, sc->rec.blksz);
>  
>   error = 0;
> + sc->offs = 0;
>   if (sc->mode & AUMODE_PLAY) {
>   if (sc->ops->trigger_output) {
>   p.encoding = sc->hw_enc;
>