ksh garbage printing

2014-10-03 Thread Martin Natano
The following patch fixes a bug in ksh I reported some time ago
(http://marc.info/?l=openbsd-bugs&m=137292039914229&w=2). I committed
this patch to Bitrig in December 2013; it seems to work fine so far.

Here the bug report inline for reference.
> Description:
When using a keybinding that starts with ^[ while in history search mode
in ksh, history search is aborted and the rest of the keybinding is
printed at the current cursor position. search-history is implemented
in x_search_hist in bin/ksh/emacs.c. x_search_hist returns on the first
^[ character in the input stream, so the remaining characters of the
escape sequence are interpreted by x_emacs. e.g.: pressing the left
arrow key when in search mode inserts "[D" at the cursor position.
> How-To-Repeat:
set -o emacs
Type ^R.
Use arrow key or home/end.
Some garbage is printed at the cursor position.
> Fix:
unknown
FYI: bash assumes that ^[ is part of a longer keybinding when more
characters arrive in a duration of 0.1 seconds, but that looks like an
ugly solution to me.

Anyone cares to commit (or comment)?

cheers,
natano


---
Only consume ^[ in search mode when not part of an escape sequence

Index: edit.c
===
RCS file: /cvs/src/bin/ksh/edit.c,v
retrieving revision 1.39
diff -u -r1.39 edit.c
--- edit.c  17 Dec 2013 16:37:05 -  1.39
+++ edit.c  3 Oct 2014 20:45:35 -
@@ -17,6 +17,7 @@
 #include 
 #include 
 #include 
+#include 
 
 
 static void x_sigwinch(int);
@@ -145,6 +146,16 @@
 {
while (*s != 0)
shf_putc(*s++, shl_out);
+}
+
+int
+x_avail(void)
+{
+   struct pollfd pfd[1];
+
+   pfd[0].fd = STDIN_FILENO;
+   pfd[0].events = POLLIN;
+   return poll(pfd, 1, 0) == 1;
 }
 
 bool
Index: edit.h
===
RCS file: /cvs/src/bin/ksh/edit.h,v
retrieving revision 1.9
diff -u -r1.9 edit.h
--- edit.h  30 May 2011 17:14:35 -  1.9
+++ edit.h  3 Oct 2014 20:45:35 -
@@ -48,6 +48,7 @@
 void   x_flush(void);
 void   x_putc(int);
 void   x_puts(const char *);
+intx_avail(void);
 bool   x_mode(bool);
 intpromptlen(const char *, const char **);
 intx_do_comment(char *, int, int *);
Index: emacs.c
===
RCS file: /cvs/src/bin/ksh/emacs.c,v
retrieving revision 1.48
diff -u -r1.48 emacs.c
--- emacs.c 17 Dec 2013 16:37:05 -  1.48
+++ emacs.c 3 Oct 2014 20:45:35 -
@@ -884,9 +884,12 @@
if ((c = x_e_getc()) < 0)
return KSTD;
f = kb_find_hist_func(c);
-   if (c == CTRL('['))
+   if (c == CTRL('[')) {
+   /* might be part of an escape sequence */
+   if (x_avail())
+   x_e_ungetc(c);
break;
-   else if (f == x_search_hist)
+   } else if (f == x_search_hist)
offset = x_search(pat, 0, offset);
else if (f == x_del_back) {
if (p == pat) {



[PATCH] Add GeForce GTX 460M PCI ID

2014-10-03 Thread Seth Jackson
Add PCI ID for my GeForce GTX 460M.

Index: pcidevs
===
RCS file: /cvs/src/sys/dev/pci/pcidevs,v
retrieving revision 1.1744
diff -u -p -r1.1744 pcidevs
--- pcidevs 3 Oct 2014 23:59:10 -   1.1744
+++ pcidevs 4 Oct 2014 01:02:08 -
@@ -5617,6 +5617,7 @@ product NVIDIA MCP89_PPB_20x0d9a  MCP89
 product NVIDIA MCP89_PPB_3 0x0d9b  MCP89 PCIE
 product NVIDIA MCP89_OHCI  0x0d9c  MCP89 USB
 product NVIDIA MCP89_EHCI  0x0d9d  MCP89 USB
+product NVIDIA GEFORCEGTX460M  0x0dd1  GeForce GTX 460M
 product NVIDIA GEFORCE_425M0x0df0  GeForce 425M
 product NVIDIA GEFORCEGTX550TI 0x1244  GeForce GTX 550 Ti
 product NVIDIA GEFORCEGTS450_1 0x1245  GeForce GTS 450



Re: splnet() and SIOCSIFADDR

2014-10-03 Thread Alexander Bluhm
On Thu, Sep 11, 2014 at 10:49:33AM +0200, Martin Pieuchot wrote:
> --- netinet6/in6.c26 Aug 2014 21:44:29 -  1.140
> +++ netinet6/in6.c11 Sep 2014 08:45:29 -
> @@ -561,8 +560,10 @@ in6_control(struct socket *so, u_long cm
>   }
>  
>   case SIOCDIFADDR_IN6:
> + s = splsoftnet();
>   in6_purgeaddr(&ia6->ia_ifa);
>   dohooks(ifp->if_addrhooks, 0);
> + splx(s);
>   break;
>  
>   default:

In IPv4 all dohooks(if_addrhooks) are protected by a large splsoftnet().
A few lines above in SIOCAIFADDR_IN6 this is not the case.  The
hook carp_addr_updated() looks like it would need an splsoftnet()
as it is looping over if_addrlist.

But this is not part of this diff.

OK bluhm@



Re: syslogd libevent

2014-10-03 Thread Alexander Bluhm
Hi,

After some preparation, I can convert syslogd to use libevent now.

ok?

bluhm

Index: usr.sbin/syslogd/Makefile
===
RCS file: /data/mirror/openbsd/cvs/src/usr.sbin/syslogd/Makefile,v
retrieving revision 1.5
diff -u -p -u -p -r1.5 Makefile
--- usr.sbin/syslogd/Makefile   4 Jan 2004 08:28:49 -   1.5
+++ usr.sbin/syslogd/Makefile   3 Oct 2014 22:30:00 -
@@ -1,7 +1,8 @@
 #  $OpenBSD: Makefile,v 1.5 2004/01/04 08:28:49 djm Exp $
 
-PROG=  syslogd
-SRCS=  syslogd.c ttymsg.c privsep.c privsep_fdpass.c ringbuf.c
-MAN=   syslogd.8 syslog.conf.5
+PROG = syslogd
+SRCS = syslogd.c ttymsg.c privsep.c privsep_fdpass.c ringbuf.c
+MAN =  syslogd.8 syslog.conf.5
+LDFLAGS =  -levent
 
 .include 
Index: usr.sbin/syslogd/privsep.c
===
RCS file: /data/mirror/openbsd/cvs/src/usr.sbin/syslogd/privsep.c,v
retrieving revision 1.47
diff -u -p -u -p -r1.47 privsep.c
--- usr.sbin/syslogd/privsep.c  3 Oct 2014 21:55:22 -   1.47
+++ usr.sbin/syslogd/privsep.c  3 Oct 2014 23:03:50 -
@@ -171,21 +171,21 @@ priv_init(char *conf, int numeric, int l
close(socks[1]);
 
/* Close descriptors that only the unpriv child needs */
+   if (fd_ctlconn != -1)
+   close(fd_ctlconn);
+   if (fd_ctlsock != -1)
+   close(fd_ctlsock);
+   if (fd_klog != -1)
+   close(fd_klog);
+   if (fd_sendsys != -1)
+   close(fd_sendsys);
+   if (fd_udp != -1)
+   close(fd_udp);
+   if (fd_udp6 != -1)
+   close(fd_udp6);
for (i = 0; i < nunix; i++)
-   if (pfd[PFD_UNIX_0 + i].fd != -1)
-   close(pfd[PFD_UNIX_0 + i].fd);
-   if (pfd[PFD_INET].fd != -1)
-   close(pfd[PFD_INET].fd);
-   if (pfd[PFD_INET6].fd != -1)
-   close(pfd[PFD_INET6].fd);
-   if (pfd[PFD_CTLSOCK].fd != -1)
-   close(pfd[PFD_CTLSOCK].fd);
-   if (pfd[PFD_CTLCONN].fd != -1)
-   close(pfd[PFD_CTLCONN].fd);
-   if (pfd[PFD_KLOG].fd != -1)
-   close(pfd[PFD_KLOG].fd);
-   if (pfd[PFD_SENDSYS].fd != -1)
-   close(pfd[PFD_SENDSYS].fd);
+   if (fd_unix[i] != -1)
+   close(fd_unix[i]);
 
/* Save the config file specified by the child process */
if (strlcpy(config_file, conf, sizeof config_file) >= 
sizeof(config_file))
@@ -371,9 +371,9 @@ priv_init(char *conf, int numeric, int l
 
/* Unlink any domain sockets that have been opened */
for (i = 0; i < nunix; i++)
-   if (pfd[PFD_UNIX_0 + i].fd != -1)
+   if (fd_unix[i] != -1)
(void)unlink(path_unix[i]);
-   if (path_ctlsock != NULL && pfd[PFD_CTLSOCK].fd != -1)
+   if (path_ctlsock != NULL && fd_ctlsock != -1)
(void)unlink(path_ctlsock);
 
if (restart) {
Index: usr.sbin/syslogd/syslogd.c
===
RCS file: /data/mirror/openbsd/cvs/src/usr.sbin/syslogd/syslogd.c,v
retrieving revision 1.127
diff -u -p -u -p -r1.127 syslogd.c
--- usr.sbin/syslogd/syslogd.c  3 Oct 2014 21:55:22 -   1.127
+++ usr.sbin/syslogd/syslogd.c  3 Oct 2014 23:09:30 -
@@ -50,6 +50,7 @@
  * extensive changes by Ralph Campbell
  * more extensive changes by Eric Allman (again)
  * memory buffer logging by Damien Miller
+ * IPv6, libevent by Alexander Bluhm
  */
 
 #defineMAXLINE 1024/* maximum line length */
@@ -81,6 +82,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -248,23 +250,28 @@ size_tctl_reply_offset = 0;   /* Number o
 char   *linebuf;
 int linesize;
 
-voidklog_read_handler(int);
-voidudp_read_handler(int);
-voidunix_read_handler(int);
-
-struct pollfd pfd[N_PFD];
-
-volatile sig_atomic_t MarkSet;
-volatile sig_atomic_t WantDie;
-volatile sig_atomic_t DoInit;
+int fd_ctlsock, fd_ctlconn, fd_klog, fd_sendsys,
+fd_udp, fd_udp6, fd_unix[MAXUNIX];
+struct eventev_ctlaccept, ev_ctlread, ev_ctlwrite, ev_klog, ev_sendsys,
+ev_udp, ev_udp6, ev_unix[MAXUNIX],
+ev_hup, ev_int, ev_quit, ev_term, ev_mark;
+
+voidklog_readcb(int, short, void *);
+voidudp_readcb(int, short, void *);
+voidunix_readcb(int, short, void *);
+voiddie_signalcb(int, short, void *);
+voidmark_timercb(int, short, void *);
+voidinit_signalcb(int, short, void *);
+voidctlsock_acceptcb(int, short, void *);
+voidctlconn_readcb(int, short, void *);
+voidctlconn_writecb(int, short, void *);
+voidctlconn_logto(char *);
+voidctlconn_cleanup(void);
 
 struct filed *cfline(char *, char *);
 void   cvthname(struct sockaddr *, char *, size_t);
 intdecode(const char *, const CODE *);
-void   dodie(int);

Re: armv7: banana pi, Allwinner A20 board

2014-10-03 Thread SASANO Takayoshi
Hi,

> When using
> 
> OpenBSD 5.6 (RAMDISK-SUNXI) #3: Sun Aug 31 18:46:49 EDT 2014
> 
> could you drop into config (pass -c to boot) and try to "disable echi"?

What shoud I do pass "boot -c" string to armv7 kernel?
On i386/amd64 bootloader simply type it but armv7 uses U-Boot.

Tweak uEnv.txt?

-- 
SASANO Takayoshi 



Re: USB stack change needed for xhci(4)

2014-10-03 Thread Mike Larkin
On Fri, Oct 03, 2014 at 07:58:11PM +0200, Mark Kettenis wrote:
> > Date: Thu, 2 Oct 2014 12:20:14 +0200
> > From: Martin Pieuchot 
> > 
> > Our USB stack contains a hack needed for ehci(4) and ohci(4) that
> > breaks xhci(4).   The diff below moves this hack in these drivers,
> > and makes it possible to have a working xhci(4) in GENERIC.
> > 
> > I'd like this diff to be tested on as much machines as possible, because
> > the code path it touches is very sensible.  This also matters if you are
> > using uhci(4)!
> > 
> > Please test and report back.
> 
> Works fine for me on my old i386 Mac mini with usb keyboard and mouse
> and two usb disks.  Diff makes sense to me as well.

Works ok for me on x230.

> 
> ok kettenis@
> 
> > Index: ehci.c
> > ===
> > RCS file: /cvs/src/sys/dev/usb/ehci.c,v
> > retrieving revision 1.168
> > diff -u -p -r1.168 ehci.c
> > --- ehci.c  1 Sep 2014 08:13:02 -   1.168
> > +++ ehci.c  2 Oct 2014 09:30:28 -
> > @@ -99,6 +99,7 @@ struct ehci_pipe {
> >  u_int8_t   ehci_reverse_bits(u_int8_t, int);
> >  
> >  usbd_statusehci_open(struct usbd_pipe *);
> > +intehci_setaddr(struct usbd_device *, int);
> >  void   ehci_poll(struct usbd_bus *);
> >  void   ehci_softintr(void *);
> >  intehci_intr1(struct ehci_softc *);
> > @@ -215,7 +216,7 @@ voidehci_dump_exfer(struct ehci_xfer *
> >  
> >  struct usbd_bus_methods ehci_bus_methods = {
> > .open_pipe = ehci_open,
> > -   .dev_setaddr = usbd_set_address,
> > +   .dev_setaddr = ehci_setaddr,
> > .soft_intr = ehci_softintr,
> > .do_poll = ehci_poll,
> > .allocx = ehci_allocx,
> > @@ -603,6 +604,40 @@ ehci_pcd(struct ehci_softc *sc, struct u
> > xfer->status = USBD_NORMAL_COMPLETION;
> >  
> > usb_transfer_complete(xfer);
> > +}
> > +
> > +/*
> > + * Work around the half configured control (default) pipe when setting
> > + * the address of a device.
> > + *
> > + * Because a single QH is setup per endpoint in ehci_open(), and the
> > + * control pipe is configured before we could have set the address
> > + * of the device or read the wMaxPacketSize of the endpoint, we have
> > + * to re-open the pipe twice here.
> > + */
> > +int
> > +ehci_setaddr(struct usbd_device *dev, int addr)
> > +{
> > +   /* Root Hub */
> > +   if (dev->depth == 0)
> > +   return (0);
> > +
> > +   /* Re-establish the default pipe with the new max packet size. */
> > +   ehci_close_pipe(dev->default_pipe);
> > +   if (ehci_open(dev->default_pipe))
> > +   return (EINVAL);
> > +
> > +   if (usbd_set_address(dev, addr))
> > +   return (1);
> > +
> > +   dev->address = addr;
> > +
> > +   /* Re-establish the default pipe with the new address. */
> > +   ehci_close_pipe(dev->default_pipe);
> > +   if (ehci_open(dev->default_pipe))
> > +   return (EINVAL);
> > +
> > +   return (0);
> >  }
> >  
> >  void
> > Index: ohci.c
> > ===
> > RCS file: /cvs/src/sys/dev/usb/ohci.c,v
> > retrieving revision 1.139
> > diff -u -p -r1.139 ohci.c
> > --- ohci.c  10 Aug 2014 11:18:57 -  1.139
> > +++ ohci.c  2 Oct 2014 09:33:03 -
> > @@ -88,6 +88,7 @@ usbd_status   ohci_alloc_std_chain(struct 
> > struct ohci_soft_td **);
> >  
> >  usbd_statusohci_open(struct usbd_pipe *);
> > +intohci_setaddr(struct usbd_device *, int);
> >  void   ohci_poll(struct usbd_bus *);
> >  void   ohci_softintr(void *);
> >  void   ohci_waitintr(struct ohci_softc *, struct usbd_xfer *);
> > @@ -232,7 +233,7 @@ struct ohci_pipe {
> >  
> >  struct usbd_bus_methods ohci_bus_methods = {
> > .open_pipe = ohci_open,
> > -   .dev_setaddr = usbd_set_address,
> > +   .dev_setaddr = ohci_setaddr,
> > .soft_intr = ohci_softintr,
> > .do_poll = ohci_poll,
> > .allocx = ohci_allocx,
> > @@ -2003,6 +2004,40 @@ ohci_open(struct usbd_pipe *pipe)
> >   bad0:
> > return (USBD_NOMEM);
> >  
> > +}
> > +
> > +/*
> > + * Work around the half configured control (default) pipe when setting
> > + * the address of a device.
> > + *
> > + * Because a single ED is setup per endpoint in ohci_open(), and the
> > + * control pipe is configured before we could have set the address
> > + * of the device or read the wMaxPacketSize of the endpoint, we have
> > + * to re-open the pipe twice here.
> > + */
> > +int
> > +ohci_setaddr(struct usbd_device *dev, int addr)
> > +{
> > +   /* Root Hub */
> > +   if (dev->depth == 0)
> > +   return (0);
> > +
> > +   /* Re-establish the default pipe with the new max packet size. */
> > +   ohci_device_ctrl_close(dev->default_pipe);
> > +   if (ohci_open(dev->default_pipe))
> > +   return (EINVAL);
> > +
> > +   if (usbd_set_address(dev, addr))
> > +   return (1);
> > +
> > +   dev->address = ad

Re: fusefs_quotactl return value

2014-10-03 Thread Ted Unangst
On Fri, Oct 03, 2014 at 20:33, Martin Natano wrote:
> fusefs_quotactl() unconditionally returns zero, despite fusefs not
> supporting quotas. I think it should return EOPNOTSUPP. At least that
> is what cd9660, udf, fuse, msdosfs, tmpfs and nfs do.
> 
> cheers,
> natano
> 
> --- fuse_vfsops.c.origThu Sep 11 14:53:36 2014
> +++ fuse_vfsops.c Thu Sep 11 14:54:24 2014
> @@ -189,7 +189,7 @@
> int fusefs_quotactl(struct mount *mp, int cmds, uid_t uid, caddr_t arg,
> struct proc *p)
> {
> - return (0);
> + return (EOPNOTSUPP);
> }
> 
> int fusefs_statfs(struct mount *mp, struct statfs *sbp, struct proc *p)

My apologies. Your first mail to me got lost in the shuffle. Committed.

(And you did exactly the right thing. Mail the list if a developer
doesn't respond in a reasonable timeframe.)



Re: nofault mappings

2014-10-03 Thread Mark Kettenis
> Date: Tue, 30 Sep 2014 23:12:10 +0200 (CEST)
> From: Mark Kettenis 
> 
> The diff below intorduces a new flag for mmap(2) that creates mappings
> that cannot fault.  Normally, if you mmap a file, and your mapping is
> larger than the mapped file, memory access to full pages beyond the
> end of the file will fault.  Depending on the OS you will get a
> SIGSEGV or SIGBUS and if you don't catch those, you die.  This is
> especially nasty if you use file descriptor passing to share the file
> descriptor with some other process and this other proces ftruncates
> the file without telling you.
> 
> The new xserver that matthieu@ just imported has the new xshm
> extension which mmaps file descriptors passed by clients through file
> descriptor passing.  To protect itself from being trivially DOSed by a
> malicious (or careless) client, it keeps a list of mappings and
> installs a SIGBUS signal handler that checks whether the fault address
> matches any of these mappings.  In that case it mmaps a private
> anonymous page on top of the faulting address and returns.  Since
> OpenBSD generates SIGSEGV instead of SIGBUS in this case, this doesn't
> work for us, so I made sure matthieu@ disabled this functionality for
> now.  But the new xshm extension would actually be a nice thing to
> have as it circumvents certain problems with the traditional xshm
> extension that we have because of privsep.  And file descriptor
> passing is also being used for DRI3 which we may want to support one
> day.  Oh, and Wayland, which some people claim will replace X any day
> now, heavily uses mapping file descriptors passed over sockets as
> well.
> 
> We could of course change the xserver code to also trap SIGSEGV.  But
> this workaround is rather ugly.  So my idea is to make X use this new
> flag and disable the stupid busfault code.
> 
> The diff is remarkably simple.  We already have the infrastructure in
> place to replace mapped pages with anons to support MAP_PRIVATE and
> copy-on-write.  This diff simply leverages that infrastructure to
> replace a page that can't be read from the underlying object by an
> anonymous pages.  Some open issues:
> 
>  * I need to check whether all combinations of flag actually make
>sense.  Should we only support __MAP_NOFAULT with non-anonymous
>mappings?
> 
>  * Should we only fixup the fault for access beyond the end of the
>mapped object (VM_PAGER_BAD) and still fault for actual IO erors
>(VM_PAGER_ERROR)?
> 
>  * Should the flag be exported without the leading underscores since
>we actually want to encourage its use?
> 
> Thoughts?

Even though this diff has been committed, I'm still interested in what
people think about the issues above.

> Index: sys/mman.h
> ===
> RCS file: /cvs/src/sys/sys/mman.h,v
> retrieving revision 1.26
> diff -u -p -r1.26 mman.h
> --- sys/mman.h10 Jul 2014 19:00:23 -  1.26
> +++ sys/mman.h30 Sep 2014 20:34:42 -
> @@ -58,8 +58,9 @@
>  #define  __MAP_NOREPLACE 0x0800  /* fail if address not available */
>  #define  MAP_ANON0x1000  /* allocated from memory, swap space */
>  #define  MAP_ANONYMOUS   MAP_ANON/* alternate POSIX spelling */
> +#define  __MAP_NOFAULT   0x2000
>  
> -#define  MAP_FLAGMASK0x1ff7
> +#define  MAP_FLAGMASK0x3ff7
>  
>  #ifdef _KERNEL
>  /*
> Index: uvm/uvm.h
> ===
> RCS file: /cvs/src/sys/uvm/uvm.h,v
> retrieving revision 1.56
> diff -u -p -r1.56 uvm.h
> --- uvm/uvm.h 11 Jul 2014 16:35:40 -  1.56
> +++ uvm/uvm.h 30 Sep 2014 21:03:43 -
> @@ -90,7 +90,8 @@ struct uvm {
>  #define UVM_ET_SUBMAP0x02/* it is a vm_map submap */
>  #define UVM_ET_COPYONWRITE   0x04/* copy_on_write */
>  #define UVM_ET_NEEDSCOPY 0x08/* needs_copy */
> -#define  UVM_ET_HOLE 0x10/* no backend */
> +#define UVM_ET_HOLE  0x10/* no backend */
> +#define UVM_ET_NOFAULT   0x20/* don't fault */
>  #define UVM_ET_FREEMAPPED0x80/* map entry is on free list (DEBUG) */
>  
>  #define UVM_ET_ISOBJ(E)  (((E)->etype & UVM_ET_OBJ) != 0)
> @@ -98,6 +99,7 @@ struct uvm {
>  #define UVM_ET_ISCOPYONWRITE(E)  (((E)->etype & UVM_ET_COPYONWRITE) != 0)
>  #define UVM_ET_ISNEEDSCOPY(E)(((E)->etype & UVM_ET_NEEDSCOPY) != 0)
>  #define UVM_ET_ISHOLE(E) (((E)->etype & UVM_ET_HOLE) != 0)
> +#define UVM_ET_ISNOFAULT(E)  (((E)->etype & UVM_ET_NOFAULT) != 0)
>  
>  #ifdef _KERNEL
>  
> Index: uvm/uvm_extern.h
> ===
> RCS file: /cvs/src/sys/uvm/uvm_extern.h,v
> retrieving revision 1.119
> diff -u -p -r1.119 uvm_extern.h
> --- uvm/uvm_extern.h  11 Jul 2014 16:35:40 -  1.119
> +++ uvm/uvm_extern.h  30 Sep 2014 20:08:36 -
> @@ -148,14 +148,15 @@ typedef int vm_prot_t;
>  #

fusefs_quotactl return value

2014-10-03 Thread Martin Natano
fusefs_quotactl() unconditionally returns zero, despite fusefs not
supporting quotas. I think it should return EOPNOTSUPP. At least that
is what cd9660, udf, fuse, msdosfs, tmpfs and nfs do.

cheers,
natano

--- fuse_vfsops.c.orig  Thu Sep 11 14:53:36 2014
+++ fuse_vfsops.c   Thu Sep 11 14:54:24 2014
@@ -189,7 +189,7 @@
 int fusefs_quotactl(struct mount *mp, int cmds, uid_t uid, caddr_t arg,
 struct proc *p)
 {
-   return (0);
+   return (EOPNOTSUPP);
 }
 
 int fusefs_statfs(struct mount *mp, struct statfs *sbp, struct proc *p)



Re: USB stack change needed for xhci(4)

2014-10-03 Thread Mark Kettenis
> Date: Thu, 2 Oct 2014 12:20:14 +0200
> From: Martin Pieuchot 
> 
> Our USB stack contains a hack needed for ehci(4) and ohci(4) that
> breaks xhci(4).   The diff below moves this hack in these drivers,
> and makes it possible to have a working xhci(4) in GENERIC.
> 
> I'd like this diff to be tested on as much machines as possible, because
> the code path it touches is very sensible.  This also matters if you are
> using uhci(4)!
> 
> Please test and report back.

Works fine for me on my old i386 Mac mini with usb keyboard and mouse
and two usb disks.  Diff makes sense to me as well.

ok kettenis@

> Index: ehci.c
> ===
> RCS file: /cvs/src/sys/dev/usb/ehci.c,v
> retrieving revision 1.168
> diff -u -p -r1.168 ehci.c
> --- ehci.c1 Sep 2014 08:13:02 -   1.168
> +++ ehci.c2 Oct 2014 09:30:28 -
> @@ -99,6 +99,7 @@ struct ehci_pipe {
>  u_int8_t ehci_reverse_bits(u_int8_t, int);
>  
>  usbd_status  ehci_open(struct usbd_pipe *);
> +int  ehci_setaddr(struct usbd_device *, int);
>  void ehci_poll(struct usbd_bus *);
>  void ehci_softintr(void *);
>  int  ehci_intr1(struct ehci_softc *);
> @@ -215,7 +216,7 @@ void  ehci_dump_exfer(struct ehci_xfer *
>  
>  struct usbd_bus_methods ehci_bus_methods = {
>   .open_pipe = ehci_open,
> - .dev_setaddr = usbd_set_address,
> + .dev_setaddr = ehci_setaddr,
>   .soft_intr = ehci_softintr,
>   .do_poll = ehci_poll,
>   .allocx = ehci_allocx,
> @@ -603,6 +604,40 @@ ehci_pcd(struct ehci_softc *sc, struct u
>   xfer->status = USBD_NORMAL_COMPLETION;
>  
>   usb_transfer_complete(xfer);
> +}
> +
> +/*
> + * Work around the half configured control (default) pipe when setting
> + * the address of a device.
> + *
> + * Because a single QH is setup per endpoint in ehci_open(), and the
> + * control pipe is configured before we could have set the address
> + * of the device or read the wMaxPacketSize of the endpoint, we have
> + * to re-open the pipe twice here.
> + */
> +int
> +ehci_setaddr(struct usbd_device *dev, int addr)
> +{
> + /* Root Hub */
> + if (dev->depth == 0)
> + return (0);
> +
> + /* Re-establish the default pipe with the new max packet size. */
> + ehci_close_pipe(dev->default_pipe);
> + if (ehci_open(dev->default_pipe))
> + return (EINVAL);
> +
> + if (usbd_set_address(dev, addr))
> + return (1);
> +
> + dev->address = addr;
> +
> + /* Re-establish the default pipe with the new address. */
> + ehci_close_pipe(dev->default_pipe);
> + if (ehci_open(dev->default_pipe))
> + return (EINVAL);
> +
> + return (0);
>  }
>  
>  void
> Index: ohci.c
> ===
> RCS file: /cvs/src/sys/dev/usb/ohci.c,v
> retrieving revision 1.139
> diff -u -p -r1.139 ohci.c
> --- ohci.c10 Aug 2014 11:18:57 -  1.139
> +++ ohci.c2 Oct 2014 09:33:03 -
> @@ -88,6 +88,7 @@ usbd_status ohci_alloc_std_chain(struct 
>   struct ohci_soft_td **);
>  
>  usbd_status  ohci_open(struct usbd_pipe *);
> +int  ohci_setaddr(struct usbd_device *, int);
>  void ohci_poll(struct usbd_bus *);
>  void ohci_softintr(void *);
>  void ohci_waitintr(struct ohci_softc *, struct usbd_xfer *);
> @@ -232,7 +233,7 @@ struct ohci_pipe {
>  
>  struct usbd_bus_methods ohci_bus_methods = {
>   .open_pipe = ohci_open,
> - .dev_setaddr = usbd_set_address,
> + .dev_setaddr = ohci_setaddr,
>   .soft_intr = ohci_softintr,
>   .do_poll = ohci_poll,
>   .allocx = ohci_allocx,
> @@ -2003,6 +2004,40 @@ ohci_open(struct usbd_pipe *pipe)
>   bad0:
>   return (USBD_NOMEM);
>  
> +}
> +
> +/*
> + * Work around the half configured control (default) pipe when setting
> + * the address of a device.
> + *
> + * Because a single ED is setup per endpoint in ohci_open(), and the
> + * control pipe is configured before we could have set the address
> + * of the device or read the wMaxPacketSize of the endpoint, we have
> + * to re-open the pipe twice here.
> + */
> +int
> +ohci_setaddr(struct usbd_device *dev, int addr)
> +{
> + /* Root Hub */
> + if (dev->depth == 0)
> + return (0);
> +
> + /* Re-establish the default pipe with the new max packet size. */
> + ohci_device_ctrl_close(dev->default_pipe);
> + if (ohci_open(dev->default_pipe))
> + return (EINVAL);
> +
> + if (usbd_set_address(dev, addr))
> + return (1);
> +
> + dev->address = addr;
> +
> + /* Re-establish the default pipe with the new address. */
> + ohci_device_ctrl_close(dev->default_pipe);
> + if (ohci_open(dev->default_pipe))
> + return (EINVAL);
> +
> + return (0);
>  }
>  
>  /*
> Index: usb_subr.c
> ===
> RCS fil

hack for carp in IPv6 source address selection

2014-10-03 Thread Stefan Sperling
The IPv6 source address selection algorithm breaks ties by performing a
bitwise match of each candidate source address against the destination
address. The longest matching source address wins, regardless of which
interface the source address came from.

In my carp setup, this is causing a problem.

Consider the carp address 2001:DB8:10::14, which is configured on
firewall A (carp master state) and firewall B (carp backup state),
each of which has another address in the same prefix on a non-carp
interface (A has 2001:DB8:10::1 and B has 2001:DB8:10::11).

In this setup, connecting from A to B or from B to A via IPv6 is impossible.
A will use 2001:DB8:10::14 as source address when it sends neighbour
solicitations to B (2001:DB8:10::11). Since 2001:DB8:10::14 is a local
address from B's point of view, B doesn't reply to neighbour solicitations
sent by A. The only currently available workaround is to re-configure
addresses in a way that outsmarts the longest match check such that a
carp address always loses the tie. (Another workaround is to use IPv4
which doesn't have this problem.)

The hack below special-cases carp interfaces: If there is a tie, then a
carp interface is not allowed to win even if it has a longer bitwise match.
(The carp interface is in master state here -- carp interfaces in backup
state are never considered for source addresses in the first place.)

This hack makes communication between A and B work over IPv6 in the
above scenario.

I also considered another solution: Make carp backups treat their
local carp address as a non-local address. However, this would
be a much more invasive change and would also affect IPv4.

Index: in6.c
===
RCS file: /cvs/src/sys/netinet6/in6.c,v
retrieving revision 1.140
diff -u -p -r1.140 in6.c
--- in6.c   26 Aug 2014 21:44:29 -  1.140
+++ in6.c   3 Oct 2014 11:54:52 -
@@ -2029,8 +2029,25 @@ in6_ifawithscope(struct ifnet *oifp, str
}
tlen = in6_matchlen(IFA_IN6(ifa), dst);
matchcmp = tlen - blen;
-   if (matchcmp > 0) /* (8) */
+   if (matchcmp > 0) { /* (8) */
+#if NCARP > 0
+   /* 
+* Don't let carp interfaces win a tie against
+* the output interface based on matchlen.
+* We should only use a carp address if no
+* other interface has a usable address.
+* Otherwise, when communicating from a carp
+* master to a carp slave, the slave won't
+* respond since the carp address is also
+* configured as a local address on the slave.
+* Note that carp interfaces in backup state
+* were already skipped above.
+*/
+   if (ifp->if_type == IFT_CARP)
+   continue;
+#endif
goto replace;
+   }
if (matchcmp < 0) /* (9) */
continue;
if (oifp == ifp) /* (a) */



Re: [patch]lock and unlock like GnuRCS

2014-10-03 Thread Otto Moerbeek
On Thu, Oct 02, 2014 at 12:56:10AM +0100, Nicholas Marriott wrote:

> 
> OTOH, check out what we do with rcs -L and -U...

I kinda like that, because it tells you exactly what it is doing.

-Otto

> 
> 
> On Thu, Oct 02, 2014 at 12:54:13AM +0100, Nicholas Marriott wrote:
> > Matching GNU RCS seems preferable to me but I don't feel strongly about
> > it.
> > 
> > I wouldn't mention this in the man page, it hardly seems like behaviour
> > anyone should (or will need to) rely on.
> > 
> > 
> > On Wed, Oct 01, 2014 at 07:41:52PM -0400, Daniel Dickman wrote:
> > > posix commands (like ls(1) for example) keep the last option when 
> > > mutually exclusive options are specified. does it make sense to keep rcs 
> > > consistent with that convention? also is a man page diff needed?
> > > 
> > > 
> > > > On Oct 1, 2014, at 7:17 PM, Nicholas Marriott 
> > > >  wrote:
> > > > 
> > > > The existing behaviour isn't wildly useful, makes sense to me, ok nicm
> > > > 
> > > > 
> > > >> On Wed, Oct 01, 2014 at 11:33:33PM +0200, Fritjof Bornebusch wrote:
> > > >> Hi tech,
> > > >> 
> > > >> the OpenRCS rcs command produces the following output if -l and -u is 
> > > >> used in the same command:
> > > >> 
> > > >> $ rcs -l1.1 -u1.1 foo.txt
> > > >> RCS file: foo.txt,v
> > > >> 1.1 locked
> > > >> 1.1 unlocked
> > > >> 
> > > >> $ rcs -u1.1 -l1.1 foo.txt
> > > >> RCS file: foo.txt,v
> > > >> 1.1 locked
> > > >> 1.1 unlocked
> > > >> 
> > > >> I've looked at GnuRCS and it has another way to handle these 
> > > >> parameters 
> > > >> (it seems the other BSDs use GnuRCS, too).
> > > >> 
> > > >> Debian 7.5:
> > > >> $ rcs -l1.1 -u1.1 foo.txt
> > > >> RCS file: foo.txt,v
> > > >> rcs: foo.txt,v: no lock set on revision 1.1
> > > >> 1.1 locked
> > > >> 
> > > >> $ rcs -u1.1 -l1.1 foo.txt
> > > >> Segmentation fault
> > > >> 
> > > >> Well, I think the "Segmentation fault" isn't that important :), but 
> > > >> GnuRCS 
> > > >> does not lock and unlock a file by using the same command like OpenRCS.
> > > >> 
> > > >> I think the different implementations of RCS should share the same 
> > > >> behaviour:
> > > >> 
> > > >> $ rcs -l1.1 -u1.1 foo.txt
> > > >> RCS file: foo.txt,v
> > > >> 1.1 locked
> > > >> done
> > > >> 
> > > >> $ rcs -u1.1 -l1.1 foo.txt
> > > >> RCS file: foo.txt,v
> > > >> 1.1 unlocked
> > > >> done
> > > >> 
> > > >> fritjof
> > > >> 
> > > >> 
> > > >> Index: rcsprog.c
> > > >> ===
> > > >> RCS file: /cvs/src/usr.bin/rcs/rcsprog.c,v
> > > >> retrieving revision 1.151
> > > >> diff -u -p -r1.151 rcsprog.c
> > > >> --- rcsprog.c12 Jul 2011 21:00:32 -1.151
> > > >> +++ rcsprog.c3 Aug 2014 15:42:34 -
> > > >> @@ -234,9 +234,10 @@ rcs_main(int argc, char **argv)
> > > >>lkmode = RCS_LOCK_STRICT;
> > > >>break;
> > > >>case 'l':
> > > >> -/* XXX - Check with -u flag. */
> > > >> -lrev = rcs_optarg;
> > > >> -rcsflags |= RCSPROG_LFLAG;
> > > >> +if (!(rcsflags & RCSPROG_UFLAG)) {
> > > >> +lrev = rcs_optarg;
> > > >> +rcsflags |= RCSPROG_LFLAG;
> > > >> +}
> > > >>break;
> > > >>case 'm':
> > > >>if (logstr != NULL)
> > > >> @@ -272,9 +273,10 @@ rcs_main(int argc, char **argv)
> > > >>lkmode = RCS_LOCK_LOOSE;
> > > >>break;
> > > >>case 'u':
> > > >> -/* XXX - Check with -l flag. */
> > > >> -urev = rcs_optarg;
> > > >> -rcsflags |= RCSPROG_UFLAG;
> > > >> +if (!(rcsflags & RCSPROG_LFLAG)) {
> > > >> +urev = rcs_optarg;
> > > >> +rcsflags |= RCSPROG_UFLAG;
> > > >> +}
> > > >>break;
> > > >>case 'V':
> > > >>printf("%s\n", rcs_version);
> > > > 



Re: armv7: banana pi, Allwinner A20 board

2014-10-03 Thread Jonathan Gray
On Thu, Oct 02, 2014 at 09:16:43PM +0200, Patrick Wildt wrote:
> Hi,
> 
> I remember that there has been an issue, only seen on Cortex-A7/A15, like the 
> Allwinner A20.
> 
> The fix for that issue is somewhere here[0].
> 
> Try this[1] kernel and have a look if it has the same issue or not.
> 
> I do not have an A20, so I can’t test it, sorry. But I’ll probably buy 
> this[2][3] one once it’s available.
> 
> \Patrick
> 
> [0] 
> https://github.com/bitrig/bitrig/commit/f1932308435a4b2c3daf0e880dc0adc829f5803d
> [1] https://www.blueri.se/bitrig/armv7/20140925/bsd.rd.SUNXI.umg
> [2] 
> http://www.allnet.de/at/allnet-brand/produkte/neuheiten/p/banana-pi-router-board/
> [3] http://www.sinovoip.com.cn/ecp_view.asp?id=554

Here is a diff against -current that handles the L1 pte bits for v7
in the same manner as L2 as suggested by Patrick.

Note that the armv7 snapshot won't install correctly at the
moment as it is missing etc56.tgz

Index: arm/pmap.c
===
RCS file: /cvs/src/sys/arch/arm/arm/pmap.c,v
retrieving revision 1.46
diff -u -p -r1.46 pmap.c
--- arm/pmap.c  29 Mar 2014 18:09:28 -  1.46
+++ arm/pmap.c  3 Oct 2014 06:54:02 -
@@ -4585,6 +4585,12 @@ pt_entry_t   pte_l1_s_coherent;
 pt_entry_t pte_l2_l_coherent;
 pt_entry_t pte_l2_s_coherent;
 
+pt_entry_t pte_l1_s_prot_ur;
+pt_entry_t pte_l1_s_prot_uw;
+pt_entry_t pte_l1_s_prot_kr;
+pt_entry_t pte_l1_s_prot_kw;
+pt_entry_t pte_l1_s_prot_mask;
+
 pt_entry_t pte_l2_s_prot_ur;
 pt_entry_t pte_l2_s_prot_uw;
 pt_entry_t pte_l2_s_prot_kr;
@@ -4631,6 +4637,12 @@ pmap_pte_init_generic(void)
pte_l2_l_coherent = L2_L_COHERENT_generic;
pte_l2_s_coherent = L2_S_COHERENT_generic;
 
+   pte_l1_s_prot_ur = L1_S_PROT_UR_generic;
+   pte_l1_s_prot_uw = L1_S_PROT_UW_generic;
+   pte_l1_s_prot_kr = L1_S_PROT_KR_generic;
+   pte_l1_s_prot_kw = L1_S_PROT_KW_generic;
+   pte_l1_s_prot_mask = L1_S_PROT_MASK_generic;
+
pte_l2_s_prot_ur = L2_S_PROT_UR_generic;
pte_l2_s_prot_uw = L2_S_PROT_UW_generic;
pte_l2_s_prot_kr = L2_S_PROT_KR_generic;
@@ -4754,6 +4766,12 @@ pmap_pte_init_armv7(void)
pte_l2_l_coherent = L2_L_COHERENT_v7;
pte_l2_s_coherent = L2_S_COHERENT_v7;
 
+   pte_l1_s_prot_ur = L1_S_PROT_UR_v7;
+   pte_l1_s_prot_uw = L1_S_PROT_UW_v7;
+   pte_l1_s_prot_kr = L1_S_PROT_KR_v7;
+   pte_l1_s_prot_kw = L1_S_PROT_KW_v7;
+   pte_l1_s_prot_mask = L1_S_PROT_MASK_v7;
+
pte_l2_s_prot_ur = L2_S_PROT_UR_v7;
pte_l2_s_prot_uw = L2_S_PROT_UW_v7;
pte_l2_s_prot_kr = L2_S_PROT_KR_v7;
@@ -4885,6 +4903,12 @@ pmap_pte_init_xscale(void)
pte_l1_s_coherent = L1_S_COHERENT_xscale;
pte_l2_l_coherent = L2_L_COHERENT_xscale;
pte_l2_s_coherent = L2_S_COHERENT_xscale;
+
+   pte_l1_s_prot_ur = L1_S_PROT_UR_xscale;
+   pte_l1_s_prot_uw = L1_S_PROT_UW_xscale;
+   pte_l1_s_prot_kr = L1_S_PROT_KR_xscale;
+   pte_l1_s_prot_kw = L1_S_PROT_KW_xscale;
+   pte_l1_s_prot_mask = L1_S_PROT_MASK_xscale;
 
pte_l2_s_prot_ur = L2_S_PROT_UR_xscale;
pte_l2_s_prot_uw = L2_S_PROT_UW_xscale;
Index: arm/pmap7.c
===
RCS file: /cvs/src/sys/arch/arm/arm/pmap7.c,v
retrieving revision 1.15
diff -u -p -r1.15 pmap7.c
--- arm/pmap7.c 12 Jul 2014 18:44:41 -  1.15
+++ arm/pmap7.c 3 Oct 2014 06:19:40 -
@@ -3418,6 +3418,12 @@ pt_entry_t   pte_l1_s_coherent;
 pt_entry_t pte_l2_l_coherent;
 pt_entry_t pte_l2_s_coherent;
 
+pt_entry_t pte_l1_s_prot_ur;
+pt_entry_t pte_l1_s_prot_uw;
+pt_entry_t pte_l1_s_prot_kr;
+pt_entry_t pte_l1_s_prot_kw;
+pt_entry_t pte_l1_s_prot_mask;
+
 pt_entry_t pte_l2_s_prot_ur;
 pt_entry_t pte_l2_s_prot_uw;
 pt_entry_t pte_l2_s_prot_kr;
@@ -3463,6 +3469,12 @@ pmap_pte_init_generic(void)
pte_l2_l_coherent = L2_L_COHERENT_generic;
pte_l2_s_coherent = L2_S_COHERENT_generic;
 
+   pte_l1_s_prot_ur = L1_S_PROT_UR_generic;
+   pte_l1_s_prot_uw = L1_S_PROT_UW_generic;
+   pte_l1_s_prot_kr = L1_S_PROT_KR_generic;
+   pte_l1_s_prot_kw = L1_S_PROT_KW_generic;
+   pte_l1_s_prot_mask = L1_S_PROT_MASK_generic;
+
pte_l2_s_prot_ur = L2_S_PROT_UR_generic;
pte_l2_s_prot_uw = L2_S_PROT_UW_generic;
pte_l2_s_prot_kr = L2_S_PROT_KR_generic;
@@ -3505,6 +3517,12 @@ pmap_pte_init_armv7(void)
pte_l1_s_coherent = L1_S_COHERENT_v7;
pte_l2_l_coherent = L2_L_COHERENT_v7;
pte_l2_s_coherent = L2_S_COHERENT_v7;
+
+   pte_l1_s_prot_ur = L1_S_PROT_UR_v7;
+   pte_l1_s_prot_uw = L1_S_PROT_UW_v7;
+   pte_l1_s_prot_kr = L1_S_PROT_KR_v7;
+   pte_l1_s_prot_kw = L1_S_PROT_KW_v7;
+   pte_l1_s_prot_mask = L1_S_PROT_MASK_v7;
 
pte_l2_s_prot_ur = L2_S_PROT_UR_v7;
pte_l2_s_prot_uw = L2_S_PROT_UW_v7;
Index: include/pmap.h
===