clang -Wpointer-sign

2016-09-24 Thread Mark Kettenis
So clang has this warning turned on by default.  And our codebase is
not clean.  I don't think we intend to fix that anytime soon.  In
fact, I think we deliberately convert between signed and unsigned char
pointers in places.  So I propose to turn this warning off.  Since gcc
recognizes the option we can just unconditionally add -Wno-pointer-sign.

ok?


Index: arch/armv7/conf/Makefile.armv7
===
RCS file: /cvs/src/sys/arch/armv7/conf/Makefile.armv7,v
retrieving revision 1.13
diff -u -p -r1.13 Makefile.armv7
--- arch/armv7/conf/Makefile.armv7  29 Apr 2016 12:44:52 -  1.13
+++ arch/armv7/conf/Makefile.armv7  24 Sep 2016 13:31:55 -
@@ -24,7 +24,7 @@ _archdir?=$S/arch/${_arch}
 INCLUDES=  -nostdinc -I$S -I. -I$S/arch
 CPPFLAGS=  ${INCLUDES} ${IDENT} ${PARAM} -D_KERNEL -D__${_mach}__ -MD -MP
 CWARNFLAGS=-Werror -Wall -Wimplicit-function-declaration \
-   -Wno-main -Wno-uninitialized \
+   -Wno-main -Wno-uninitialized -Wno-pointer-sign \
-Wframe-larger-than=2047
 
 CMACHFLAGS=-ffreestanding -msoft-float -march=armv6 -Wa,-march=armv7a



Re: clang -Wpointer-sign

2016-09-24 Thread Mark Kettenis
> From: "Theo de Raadt" 
> Date: Sat, 24 Sep 2016 10:44:19 -0600
> 
> Please add this to all arch/*/conf/conf/Makefile.* files.
> 
> We are trying to minimize differences between these files.  If
> that effort isn't made, they will eventually wander far apart from
> each other.

Sure.  I'll leave luna88k alone though as I don't think gcc3 had a
-Wpointer-sign option.



More clang warnings in the kernel

2016-09-24 Thread Mark Kettenis
Compiling sys/dev/athn.c fails with:

../../../../dev/ic/athn.c:2182:9: error: shifting a negative signed value is
  undefined [-Werror,-Wshift-negative-value]
reg = RW(reg, AR_AES_MUTE_MASK1_FC1_MGMT,
  ^~~
../../../../dev/ic/athnreg.h:1483:26: note: expanded from macro 'RW'
(((var) & ~field##_M) | SM(field, val))
^~
../../../../dev/ic/athnreg.h:1479:10: note: expanded from macro 'SM'
(((val) << field##_S) & field##_M)
  ~ ^

The whole statement is:

reg = RW(reg, AR_AES_MUTE_MASK1_FC1_MGMT,
~(IEEE80211_FC1_RETRY | IEEE80211_FC1_PWR_MGT |
  IEEE80211_FC1_MORE_DATA));

and the issue is that the IEEE80211_FC1_XXX values are signed
integers, so the bitwise complement of that ends up being a negative
value.  Possible the solution below.  Alternative would be to define
te IEEE80211_FC1_XXX values as unsigned.

Thoughts?


Index: dev/ic/athnreg.h
===
RCS file: /cvs/src/sys/dev/ic/athnreg.h,v
retrieving revision 1.18
diff -u -p -r1.18 athnreg.h
--- dev/ic/athnreg.h10 Jun 2012 21:23:36 -  1.18
+++ dev/ic/athnreg.h24 Sep 2016 14:28:41 -
@@ -1472,11 +1472,11 @@
  */
 /* Mask and Shift (getter). */
 #define MS(val, field) \
-   (((val) & field##_M) >> field##_S)
+   (((uint32_t)(val) & field##_M) >> field##_S)
 
 /* Shift and Mask (setter). */
 #define SM(field, val) \
-   (((val) << field##_S) & field##_M)
+   (((uint32_t)(val) << field##_S) & field##_M)
 
 /* Rewrite. */
 #define RW(var, field, val)\



clang: warning fix for vmt.c

2016-09-24 Thread Mark Kettenis
Using a variable for the format string isn't a godd idea.

ok?


Index: dev/pv/vmt.c
===
RCS file: /cvs/src/sys/dev/pv/vmt.c,v
retrieving revision 1.9
diff -u -p -r1.9 vmt.c
--- dev/pv/vmt.c3 Feb 2016 14:24:05 -   1.9
+++ dev/pv/vmt.c24 Sep 2016 17:08:35 -
@@ -419,7 +419,7 @@ vmt_kvop(void *arg, int op, char *key, c
goto done;
}
 
-   if (vm_rpc_send_rpci_tx(sc, buf) != 0) {
+   if (vm_rpc_send_rpci_tx(sc, "%s", buf) != 0) {
DPRINTF("%s: error sending command: %s\n", DEVNAME(sc), buf);
sc->sc_rpc_error = 1;
error = EIO;



clang dev/pv/hyperv.c

2016-09-24 Thread Mark Kettenis
Another obvious mistake caught by clang.

ok?


Index: dev/pv/hyperv.c
===
RCS file: /cvs/src/sys/dev/pv/hyperv.c,v
retrieving revision 1.16
diff -u -p -r1.16 hyperv.c
--- dev/pv/hyperv.c 20 Sep 2016 10:27:14 -  1.16
+++ dev/pv/hyperv.c 24 Sep 2016 17:04:24 -
@@ -700,7 +700,7 @@ hv_vmbus_connect(struct hv_softc *sc)
sc->sc_revents = (u_long *)((caddr_t)sc->sc_events + (PAGE_SIZE >> 1));
 
sc->sc_monitor[0] = km_alloc(PAGE_SIZE, _any, _zero, _nowait);
-   if (sc->sc_monitor == NULL) {
+   if (sc->sc_monitor[0] == NULL) {
printf(": failed to allocate monitor page 1\n");
goto errout;
}
@@ -710,7 +710,7 @@ hv_vmbus_connect(struct hv_softc *sc)
}
 
sc->sc_monitor[1] = km_alloc(PAGE_SIZE, _any, _zero, _nowait);
-   if (sc->sc_monitor == NULL) {
+   if (sc->sc_monitor[1] == NULL) {
printf(": failed to allocate monitor page 2\n");
goto errout;
}



clang and

2016-09-24 Thread Mark Kettenis
clang warns by default about static functions that are unused.  It
does this even for static inline functions, except when those
functions are defined in a header file.  The RBT code in 
has macros that define static inline functions.  Unfortunately that
means that the inline functions generated by those macros trigger the
warning when they're not used.  The diff below marks them as __unused,
to suppress this warning.  With this change, both gcc and clang only
emit the functions that are actually used.

ok?


Index: sys/tree.h
===
RCS file: /cvs/src/sys/sys/tree.h,v
retrieving revision 1.24
diff -u -p -r1.24 tree.h
--- sys/tree.h  15 Sep 2016 06:07:22 -  1.24
+++ sys/tree.h  24 Sep 2016 15:26:41 -
@@ -823,97 +823,97 @@ int_rb_check(const struct rb_type *, v
 #define RBT_PROTOTYPE(_name, _type, _field, _cmp)  \
 extern const struct rb_type *const _name##_RBT_TYPE;   \
\
-static inline void \
+__unused static inline void\
 _name##_RBT_INIT(struct _name *head)   \
 {  \
_rb_init(>rbh_root);  \
 }  \
\
-static inline struct _type *   \
+__unused static inline struct _type *  \
 _name##_RBT_INSERT(struct _name *head, struct _type *elm)  \
 {  \
return _rb_insert(_name##_RBT_TYPE, >rbh_root, elm);  \
 }  \
\
-static inline struct _type *   \
+__unused static inline struct _type *  \
 _name##_RBT_REMOVE(struct _name *head, struct _type *elm)  \
 {  \
return _rb_remove(_name##_RBT_TYPE, >rbh_root, elm);  \
 }  \
\
-static inline struct _type *   \
+__unused static inline struct _type *  \
 _name##_RBT_FIND(struct _name *head, const struct _type *key)  \
 {  \
return _rb_find(_name##_RBT_TYPE, >rbh_root, key);\
 }  \
\
-static inline struct _type *   \
+__unused static inline struct _type *  \
 _name##_RBT_NFIND(struct _name *head, const struct _type *key) \
 {  \
return _rb_nfind(_name##_RBT_TYPE, >rbh_root, key);   \
 }  \
\
-static inline struct _type *   \
+__unused static inline struct _type *  \
 _name##_RBT_ROOT(struct _name *head)   \
 {  \
return _rb_root(_name##_RBT_TYPE, >rbh_root); \
 }  \
\
-static inline int  \
+__unused static inline int \
 _name##_RBT_EMPTY(struct _name *head)  \
 {  \
return _rb_empty(>rbh_root);  \
 }  \
\
-static inline struct _type *   \
+__unused static inline struct _type *  \
 _name##_RBT_MIN(struct _name *head)\
 {  \
return _rb_min(_name##_RBT_TYPE, 

clang: kern/vfs_subr.c

2016-09-24 Thread Mark Kettenis
Finally a case where clang isn't entirely helpful.  Because vp->v_tag
is an enum, clang thinks its value can't be bigger than 15 and that
the vp->v_tag >= nitems(vtags) check is therefore always false.  But I
think we want to prevent an out-of-bounds access here if the vnode is
corrupted somehow.  Casting to u_int makes the compiler shut up.

ok?


Index: kern/vfs_subr.c
===
RCS file: /cvs/src/sys/kern/vfs_subr.c,v
retrieving revision 1.253
diff -u -p -r1.253 vfs_subr.c
--- kern/vfs_subr.c 16 Sep 2016 03:21:16 -  1.253
+++ kern/vfs_subr.c 24 Sep 2016 17:16:52 -
@@ -2162,8 +2162,9 @@ vfs_vnode_print(void *v, int full,
struct vnode *vp = v;
 
(*pr)("tag %s(%d) type %s(%d) mount %p typedata %p\n",
- vp->v_tag >= nitems(vtags)? "":vtags[vp->v_tag], vp->v_tag,
- vp->v_type >= nitems(vtypes)? "":vtypes[vp->v_type],
+ (u_int)vp->v_tag >= nitems(vtags)? "":vtags[vp->v_tag],
+ vp->v_tag,
+ (u_int)vp->v_type >= nitems(vtypes)? "":vtypes[vp->v_type],
  vp->v_type, vp->v_mount, vp->v_mountedhere);
 
(*pr)("data %p usecount %d writecount %d holdcnt %d numoutput %d\n",



Re: hide RT_TABLEID_MAX behind __BSD_VISIBLE

2016-09-26 Thread Mark Kettenis
> From: j...@wxcvbn.org (Jeremie Courreges-Anglas)
> Date: Mon, 26 Sep 2016 21:13:24 +0200
> 
> AFAIK this is not a standard define, so it should be unconditionally
> reachable.  mkr went fine.
> 
> Thoughts?

ok kettenis@, although perhaps it makes sense to move this #define a
bit further down the file into an existing __BSD_VISIBLE block.

> Index: socket.h
> ===
> RCS file: /cvs/src/sys/sys/socket.h,v
> retrieving revision 1.91
> diff -u -p -p -u -r1.91 socket.h
> --- socket.h  12 Sep 2016 19:41:20 -  1.91
> +++ socket.h  25 Sep 2016 22:55:57 -
> @@ -58,7 +58,9 @@ typedef __sa_family_t   sa_family_t;/* so
>   */
>  
>  /* Maximum number of alternate routing tables */
> +#if __BSD_VISIBLE
>  #define  RT_TABLEID_MAX  255
> +#endif
>  
>  /*
>   * Types
> 
> -- 
> jca | PGP : 0x1524E7EE / 5135 92C1 AD36 5293 2BDF  DDCC 0DFA 74AE 1524 E7EE
> 
> 



Modernize regress/libexec/ld.so/constructor

2016-09-26 Thread Mark Kettenis
Diff below modernizes the C++ code a bit such that the test case
compiles again without warnings.  It also uses CPPFLAGS instead of
CFLAGS such that the c++ compiler actually stands a chance finding the
header files.

Since the tests succeed on amd64, and should succeed on other
architectures, the diff re-enables this test.

ok?


Index: regress/libexec/ld.so/Makefile
===
RCS file: /cvs/src/regress/libexec/ld.so/Makefile,v
retrieving revision 1.16
diff -u -p -r1.16 Makefile
--- regress/libexec/ld.so/Makefile  20 Mar 2016 05:13:22 -  1.16
+++ regress/libexec/ld.so/Makefile  26 Sep 2016 21:35:45 -
@@ -1,7 +1,7 @@
 #  $OpenBSD: Makefile,v 1.16 2016/03/20 05:13:22 guenther Exp $
 
 SUBDIR+= elf hidden weak dlsym dlopen dlclose lazy
-#SUBDIR+= constructor 
+SUBDIR+= constructor 
 SUBDIR+= link-order edgecases initfirst
 SUBDIR+= df_1_noopen randomdata subst dependencies
 SUBDIR+= init-env
Index: regress/libexec/ld.so/constructor/libab/Makefile
===
RCS file: /cvs/src/regress/libexec/ld.so/constructor/libab/Makefile,v
retrieving revision 1.1
diff -u -p -r1.1 Makefile
--- regress/libexec/ld.so/constructor/libab/Makefile1 Feb 2003 19:56:17 
-   1.1
+++ regress/libexec/ld.so/constructor/libab/Makefile26 Sep 2016 21:35:45 
-
@@ -1,6 +1,6 @@
 LIB=ab
 SRCS= ab.C
-CFLAGS=-I${.CURDIR}/../libaa
+CPPFLAGS=-I${.CURDIR}/../libaa
 LDADD=-L../libaa
 LDADD+=-laa
 .include 
Index: regress/libexec/ld.so/constructor/libab/ab.C
===
RCS file: /cvs/src/regress/libexec/ld.so/constructor/libab/ab.C,v
retrieving revision 1.2
diff -u -p -r1.2 ab.C
--- regress/libexec/ld.so/constructor/libab/ab.C18 Feb 2003 13:14:42 
-  1.2
+++ regress/libexec/ld.so/constructor/libab/ab.C26 Sep 2016 21:35:45 
-
@@ -4,9 +4,11 @@
  * $OpenBSD: ab.C,v 1.2 2003/02/18 13:14:42 jmc Exp $
  */
 
-#include "iostream.h"
+#include 
 #include "aa.h"
 #include "ab.h"
+
+using namespace std;
 
 extern int a;
 
Index: regress/libexec/ld.so/constructor/prog1/Makefile
===
RCS file: /cvs/src/regress/libexec/ld.so/constructor/prog1/Makefile,v
retrieving revision 1.1
diff -u -p -r1.1 Makefile
--- regress/libexec/ld.so/constructor/prog1/Makefile1 Feb 2003 19:56:17 
-   1.1
+++ regress/libexec/ld.so/constructor/prog1/Makefile26 Sep 2016 21:35:45 
-
@@ -22,7 +22,7 @@ AB_OBJDIR!=if [ -d $(AB_DIR)/${__obj
 
 
 
-CFLAGS=-I${.CURDIR}/../libab
+CPPFLAGS=-I${.CURDIR}/../libab
 LDADD=
 LDADD+=-lab
 LDADD+=-laa
Index: regress/libexec/ld.so/constructor/prog1/prog1.C
===
RCS file: /cvs/src/regress/libexec/ld.so/constructor/prog1/prog1.C,v
retrieving revision 1.1
diff -u -p -r1.1 prog1.C
--- regress/libexec/ld.so/constructor/prog1/prog1.C 1 Feb 2003 19:56:17 
-   1.1
+++ regress/libexec/ld.so/constructor/prog1/prog1.C 26 Sep 2016 21:35:45 
-
@@ -3,8 +3,11 @@
  *
  * $OpenBSD: prog1.C,v 1.1 2003/02/01 19:56:17 drahn Exp $
  */
-#include "iostream.h"
+#include 
 #include "ab.h"
+
+using namespace std;
+
 BB BBmain("main");
 
 int a;
Index: regress/libexec/ld.so/constructor/prog2/Makefile
===
RCS file: /cvs/src/regress/libexec/ld.so/constructor/prog2/Makefile,v
retrieving revision 1.1
diff -u -p -r1.1 Makefile
--- regress/libexec/ld.so/constructor/prog2/Makefile1 Feb 2003 19:56:17 
-   1.1
+++ regress/libexec/ld.so/constructor/prog2/Makefile26 Sep 2016 21:35:45 
-
@@ -22,7 +22,7 @@ AB_OBJDIR!=if [ -d $(AB_DIR)/${__obj
 
 
 
-CFLAGS=-I${.CURDIR}/../libab
+CPPFLAGS=-I${.CURDIR}/../libab
 LDADD=
 LDADD+=-laa
 LDADD+=-lab
Index: regress/libexec/ld.so/constructor/prog2/prog2.C
===
RCS file: /cvs/src/regress/libexec/ld.so/constructor/prog2/prog2.C,v
retrieving revision 1.1
diff -u -p -r1.1 prog2.C
--- regress/libexec/ld.so/constructor/prog2/prog2.C 1 Feb 2003 19:56:17 
-   1.1
+++ regress/libexec/ld.so/constructor/prog2/prog2.C 26 Sep 2016 21:35:45 
-
@@ -3,8 +3,11 @@
  *
  * $OpenBSD: prog2.C,v 1.1 2003/02/01 19:56:17 drahn Exp $
  */
-#include "iostream.h"
+#include 
 #include "ab.h"
+
+using namespace std;
+
 BB BBmain("main");
 
 int a;



Re: hide RT_TABLEID_MAX behind __BSD_VISIBLE

2016-09-26 Thread Mark Kettenis
> From: Jeremie Courreges-Anglas <j...@wxcvbn.org>
> Date: Mon, 26 Sep 2016 22:19:54 +0200
> 
> Mark Kettenis <mark.kette...@xs4all.nl> writes:
> 
> >> From: j...@wxcvbn.org (Jeremie Courreges-Anglas)
> >> Date: Mon, 26 Sep 2016 21:13:24 +0200
> >> 
> >> AFAIK this is not a standard define, so it should be unconditionally
> >> reachable.  mkr went fine.
> >> 
> >> Thoughts?
> >
> > ok kettenis@, although perhaps it makes sense to move this #define a
> > bit further down the file into an existing __BSD_VISIBLE block.
> 
> Yeah, but I didn't know where to move it.  What about the following?

That's probably the wrong block ;) SOCK_CLOEXEC is likely to end up in
the next POSIX standard, which means we'll have to shuffle around the
#if __BSD_VISIBLE.

I'd put it right after the "struct splice" declaration, with a blank
line before and after.

> Index: socket.h
> ===
> RCS file: /cvs/src/sys/sys/socket.h,v
> retrieving revision 1.91
> diff -u -p -p -u -r1.91 socket.h
> --- socket.h  12 Sep 2016 19:41:20 -  1.91
> +++ socket.h  26 Sep 2016 20:15:49 -
> @@ -57,9 +57,6 @@ typedef __sa_family_t   sa_family_t;/* so
>   * Definitions related to sockets: types, address families, options.
>   */
>  
> -/* Maximum number of alternate routing tables */
> -#define  RT_TABLEID_MAX  255
> -
>  /*
>   * Types
>   */
> @@ -72,16 +69,20 @@ typedef   __sa_family_t   sa_family_t;/* so
>  #define  SOCK_TYPE_MASK  0x000F  /* mask that covers the above */
>  #endif
>  
> +#if __BSD_VISIBLE
>  /*
>   * Socket creation flags
>   */
> -#if __BSD_VISIBLE
>  #define  SOCK_CLOEXEC0x8000  /* set FD_CLOEXEC */
>  #define  SOCK_NONBLOCK   0x4000  /* set O_NONBLOCK */
>  #ifdef _KERNEL
>  #define  SOCK_NONBLOCK_INHERIT   0x2000  /* inherit O_NONBLOCK from 
> listener */
>  #endif
>  #define  SOCK_DNS0x1000  /* set SS_DNS */
> +/*
> + * Maximum number of alternate routing tables
> + */
> +#define  RT_TABLEID_MAX  255
>  #endif /* __BSD_VISIBLE */
>  
>  /*
> 
> -- 
> jca | PGP : 0x1524E7EE / 5135 92C1 AD36 5293 2BDF  DDCC 0DFA 74AE 1524 E7EE
> 



Re: Modernize regress/libexec/ld.so/constructor

2016-09-26 Thread Mark Kettenis
> Date: Mon, 26 Sep 2016 23:54:46 +0200
> From: Alexander Bluhm <alexander.bl...@gmx.net>
> 
> On Mon, Sep 26, 2016 at 11:39:29PM +0200, Mark Kettenis wrote:
> > Diff below modernizes the C++ code a bit such that the test case
> > compiles again without warnings.  It also uses CPPFLAGS instead of
> > CFLAGS such that the c++ compiler actually stands a chance finding the
> > header files.
> > 
> > Since the tests succeed on amd64, and should succeed on other
> > architectures, the diff re-enables this test.
> 
> Also passes on i386.
> You missed the #include "iostream.h" in constructor/libaa/aa.C .

Actually, that one can be removed.  New diff below.  Still ok?

Index: regress/libexec/ld.so/constructor/libaa/aa.C
===
RCS file: /cvs/src/regress/libexec/ld.so/constructor/libaa/aa.C,v
retrieving revision 1.1
diff -u -p -r1.1 aa.C
--- regress/libexec/ld.so/constructor/libaa/aa.C1 Feb 2003 19:56:17 
-   1.1
+++ regress/libexec/ld.so/constructor/libaa/aa.C26 Sep 2016 21:59:21 
-
@@ -4,7 +4,6 @@
  * $OpenBSD: aa.C,v 1.1 2003/02/01 19:56:17 drahn Exp $
  */
 
-#include "iostream.h"
 #include "aa.h"
 int a;
 
Index: regress/libexec/ld.so/constructor/libab/Makefile
===
RCS file: /cvs/src/regress/libexec/ld.so/constructor/libab/Makefile,v
retrieving revision 1.1
diff -u -p -r1.1 Makefile
--- regress/libexec/ld.so/constructor/libab/Makefile1 Feb 2003 19:56:17 
-   1.1
+++ regress/libexec/ld.so/constructor/libab/Makefile26 Sep 2016 21:59:21 
-
@@ -1,6 +1,6 @@
 LIB=ab
 SRCS= ab.C
-CFLAGS=-I${.CURDIR}/../libaa
+CPPFLAGS=-I${.CURDIR}/../libaa
 LDADD=-L../libaa
 LDADD+=-laa
 .include 
Index: regress/libexec/ld.so/constructor/libab/ab.C
===
RCS file: /cvs/src/regress/libexec/ld.so/constructor/libab/ab.C,v
retrieving revision 1.2
diff -u -p -r1.2 ab.C
--- regress/libexec/ld.so/constructor/libab/ab.C18 Feb 2003 13:14:42 
-  1.2
+++ regress/libexec/ld.so/constructor/libab/ab.C26 Sep 2016 21:59:21 
-
@@ -4,9 +4,11 @@
  * $OpenBSD: ab.C,v 1.2 2003/02/18 13:14:42 jmc Exp $
  */
 
-#include "iostream.h"
+#include 
 #include "aa.h"
 #include "ab.h"
+
+using namespace std;
 
 extern int a;
 
Index: regress/libexec/ld.so/constructor/prog1/Makefile
===
RCS file: /cvs/src/regress/libexec/ld.so/constructor/prog1/Makefile,v
retrieving revision 1.1
diff -u -p -r1.1 Makefile
--- regress/libexec/ld.so/constructor/prog1/Makefile1 Feb 2003 19:56:17 
-   1.1
+++ regress/libexec/ld.so/constructor/prog1/Makefile26 Sep 2016 21:59:21 
-
@@ -22,7 +22,7 @@ AB_OBJDIR!=if [ -d $(AB_DIR)/${__obj
 
 
 
-CFLAGS=-I${.CURDIR}/../libab
+CPPFLAGS=-I${.CURDIR}/../libab
 LDADD=
 LDADD+=-lab
 LDADD+=-laa
Index: regress/libexec/ld.so/constructor/prog1/prog1.C
===
RCS file: /cvs/src/regress/libexec/ld.so/constructor/prog1/prog1.C,v
retrieving revision 1.1
diff -u -p -r1.1 prog1.C
--- regress/libexec/ld.so/constructor/prog1/prog1.C 1 Feb 2003 19:56:17 
-   1.1
+++ regress/libexec/ld.so/constructor/prog1/prog1.C 26 Sep 2016 21:59:21 
-
@@ -3,8 +3,11 @@
  *
  * $OpenBSD: prog1.C,v 1.1 2003/02/01 19:56:17 drahn Exp $
  */
-#include "iostream.h"
+#include 
 #include "ab.h"
+
+using namespace std;
+
 BB BBmain("main");
 
 int a;
Index: regress/libexec/ld.so/constructor/prog2/Makefile
===
RCS file: /cvs/src/regress/libexec/ld.so/constructor/prog2/Makefile,v
retrieving revision 1.1
diff -u -p -r1.1 Makefile
--- regress/libexec/ld.so/constructor/prog2/Makefile1 Feb 2003 19:56:17 
-   1.1
+++ regress/libexec/ld.so/constructor/prog2/Makefile26 Sep 2016 21:59:21 
-
@@ -22,7 +22,7 @@ AB_OBJDIR!=if [ -d $(AB_DIR)/${__obj
 
 
 
-CFLAGS=-I${.CURDIR}/../libab
+CPPFLAGS=-I${.CURDIR}/../libab
 LDADD=
 LDADD+=-laa
 LDADD+=-lab
Index: regress/libexec/ld.so/constructor/prog2/prog2.C
===
RCS file: /cvs/src/regress/libexec/ld.so/constructor/prog2/prog2.C,v
retrieving revision 1.1
diff -u -p -r1.1 prog2.C
--- regress/libexec/ld.so/constructor/prog2/prog2.C 1 Feb 2003 19:56:17 
-   1.1
+++ regress/libexec/ld.so/constructor/prog2/prog2.C 26 Sep 2016 21:59:21 
-
@@ -3,8 +3,11 @@
  *
  * $OpenBSD: prog2.C,v 1.1 2003/02/01 19:56:17 drahn Exp $
  */
-#include "iostream.h"
+#include 
 #include "ab.h"
+
+using namespace std;
+
 BB BBmain("main");
 
 int a;



Re: Fix kbd -l

2016-09-29 Thread Mark Kettenis
> Date: Thu, 29 Sep 2016 16:09:09 +0200
> From: Theo Buehler <t...@math.ethz.ch>
> 
> On Thu, Sep 29, 2016 at 02:19:43PM +0200, Mark Kettenis wrote:
> > This diff adds a WSKBDIO_GETENCODINGS ioctl and uses it to print a
> > list of supported encodings like the old kvm groveling code did.  The
> > ioctl will clamp the number of entries that are returns to the number
> > that was passed in.  This means that if the number returned is the
> > same as the number passed in, there might be more entries and you
> > probably want to retry with a larger buffer.  The new implementation
> > does this.
> > 
> > Waring; this did not go through a make release yet.  And that might be
> > relevant, since this code gets included in the ramdisks.
> > 
> > Thoughts?
> > 
> 
> amd64 release builds fine with this patch. I tested it on both a normal
> system and with bsd.rd, works fine.  I like the fact that extended
> keyboard encodings are now also listed in bsd.rd.
> 
> There is one change of behavior: previously, if a non-root user ran
> kbd -l, it would exit with status 1 and print the error message:
> 
> kbd: kvm_openfiles: /dev/mem: permission denied
> 
> which gave at least some indication that it must be run as root.
> 
> Now it fails silently with exit code 0 without printing anything since
> opening the /dev/wskbd?  devices fails, as they are owned by root:wheel
> with permissions 600.

If you log in on the console, it actually works for non-root users as
well, at least for the primary keyboard.  This is because login(1)
modifies the permissions according to /etc/fbtab.  Now if you have
both pckbd(4) and ukbd(4), it will probably only show the encodings
for pckbd(4), unless you change /etc/fbtab to also change the
permissions on /dev/wskbd1.  But at that point we're quickly entering
the realm where kbd(8) simply isn't the appropriate tools to manage
things.

Now if you log in through xdm, you will in all likelyhood get an empty
list.  But X has its own idea about keyboard mappings anyway.  It only
initializes its settings based on the wscons settings.  But it never
changes the wscons settings if you manipulate the X mappings.

Cheers,

Mark



Re: Fix kbd -l

2016-09-29 Thread Mark Kettenis
> Date: Thu, 29 Sep 2016 14:19:43 +0200 (CEST)
> From: Mark Kettenis <mark.kette...@xs4all.nl>
> 
> This diff adds a WSKBDIO_GETENCODINGS ioctl and uses it to print a
> list of supported encodings like the old kvm groveling code did.  The
> ioctl will clamp the number of entries that are returns to the number
> that was passed in.  This means that if the number returned is the
> same as the number passed in, there might be more entries and you
> probably want to retry with a larger buffer.  The new implementation
> does this.

Thanks to tb@ for testing this on a ramdisk.  Here is a slightly
better diff that frees the allocated memory.

ok?


Index: sys/dev/wscons/wsconsio.h
===
RCS file: /cvs/src/sys/dev/wscons/wsconsio.h,v
retrieving revision 1.75
diff -u -p -r1.75 wsconsio.h
--- sys/dev/wscons/wsconsio.h   14 Sep 2016 03:25:51 -  1.75
+++ sys/dev/wscons/wsconsio.h   29 Sep 2016 18:12:48 -
@@ -207,6 +207,12 @@ struct wskbd_backlight {
 #defineWSKBD_TRANSLATED0
 #defineWSKBD_RAW   1
 
+struct wskbd_encoding_data {
+   int nencodings;
+   kbd_t   *encodings;
+};
+#define WSKBDIO_GETENCODINGS   _IOWR('W', 21, struct wskbd_encoding_data)
+
 /*
  * Mouse ioctls (32 - 63)
  */
Index: sys/dev/wscons/wskbd.c
===
RCS file: /cvs/src/sys/dev/wscons/wskbd.c,v
retrieving revision 1.83
diff -u -p -r1.83 wskbd.c
--- sys/dev/wscons/wskbd.c  12 Dec 2015 12:30:18 -  1.83
+++ sys/dev/wscons/wskbd.c  29 Sep 2016 18:12:48 -
@@ -1001,9 +1001,11 @@ wskbd_displayioctl(struct device *dev, u
struct wskbd_bell_data *ubdp, *kbdp;
struct wskbd_keyrepeat_data *ukdp, *kkdp;
struct wskbd_map_data *umdp;
+   struct wskbd_encoding_data *uedp;
kbd_t enc;
void *buf;
int len, error;
+   int count, i;
 
switch (cmd) {
case WSKBDIO_BELL:
@@ -1159,6 +1161,20 @@ getkeyrepeat:
wsmux_set_layout(sc->sc_base.me_parent, enc);
 #endif
return (0);
+
+   case WSKBDIO_GETENCODINGS:
+   uedp = (struct wskbd_encoding_data *)data;
+   for (count = 0; sc->id->t_keymap.keydesc[count].name; count++)
+   ;
+   if (uedp->nencodings > count)
+   uedp->nencodings = count;
+   for (i = 0; i < uedp->nencodings; i++) {
+   error = copyout(>id->t_keymap.keydesc[i].name,
+   >encodings[i], sizeof(kbd_t));
+   if (error)
+   return (error);
+   }
+   return(0);
 
case WSKBDIO_GETBACKLIGHT:
if (wskbd_get_backlight != NULL)
Index: sbin/kbd/kbd_wscons.c
===
RCS file: /cvs/src/sbin/kbd/kbd_wscons.c,v
retrieving revision 1.30
diff -u -p -r1.30 kbd_wscons.c
--- sbin/kbd/kbd_wscons.c   27 Sep 2016 22:03:49 -  1.30
+++ sbin/kbd/kbd_wscons.c   29 Sep 2016 18:12:48 -
@@ -34,6 +34,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 
@@ -82,31 +83,83 @@ struct nameint kbdvar_tab[] = {
 
 extern char *__progname;
 
-void   kbd_show_enc(int idx);
+void   kbd_show_enc(struct wskbd_encoding_data *encs, int idx);
+void   kbd_get_encs(int fd, struct wskbd_encoding_data *encs);
 void   kbd_list(void);
 void   kbd_set(char *name, int verbose);
 
 void
-kbd_show_enc(int idx)
+kbd_show_enc(struct wskbd_encoding_data *encs, int idx)
 {
+   int found;
+   kbd_t encoding, variant;
+   struct nameint *n;
int i;
 
printf("tables available for %s keyboard:\nencoding\n\n",
kbtype_tab[idx]);
 
-   for (i = 0; kbdenc_tab[i].value; i++)
-   printf("%s\n", kbdenc_tab[i].name);
+   for (i = 0; i < encs->nencodings; i++) {
+   n = _tab[0];
+   found = 0;
+   encoding = encs->encodings[i];
+   while (n->value) {
+   if (n->value == KB_ENCODING(encoding)) {
+   printf("%s", n->name);
+   found++;
+   }
+   n++;
+   }
+   if (found == 0)
+   printf("", KB_ENCODING(encoding));
+   n = _tab[0];
+   found = 0;
+   variant = KB_VARIANT(encoding);
+   while (n->value) {
+   if ((n->value & KB_VARIANT(encoding)) == n->value) {
+   printf(".%s", n->name);
+   variant &= ~n->value;
+  

Re: 64-bit address for bus_space_map(9) on arm

2016-10-04 Thread Mark Kettenis
> Date: Tue, 4 Oct 2016 10:59:26 +0200
> From: Patrick Wildt 
> 
> Hi,
> 
> continuing where we left off before the hackathon I would like to add
> a diff to the 64-bit bus_addr_t discussion.  This diff does not
> increase the size of bus_addr_t.  Instead it changes the argument
> of the function pointer stored in the bus tag from bus_addr_t to
> uint64_t.  This is an arm only change and will not affect any other
> architecture.
> 
> This is needed to pass virtual addresses retrieved from the device tree
> between the different simple-busses in the tree topology.  In the end
> every single hardware that we want to speak to is in the 32-bit range,
> not outside.  This means the final bus_space_map(9) will work on a
> 32-bit value.
> 
> Opinions? ok?

I think this is an acceptable hack.

ok kettenis@

> diff --git sys/arch/arm/armv7/armv7_space.c sys/arch/arm/armv7/armv7_space.c
> index 4f6c1e0..fbd558a 100644
> --- sys/arch/arm/armv7/armv7_space.c
> +++ sys/arch/arm/armv7/armv7_space.c
> @@ -165,7 +165,7 @@ struct bus_space armv7_bs_tag = {
>  };
>  
>  int
> -armv7_bs_map(void *t, bus_addr_t bpa, bus_size_t size,
> +armv7_bs_map(void *t, uint64_t bpa, bus_size_t size,
> int flags, bus_space_handle_t *bshp)
>  {
>   u_long startpa, endpa, pa;
> diff --git sys/arch/arm/include/bus.h sys/arch/arm/include/bus.h
> index f00c897..c108359 100644
> --- sys/arch/arm/include/bus.h
> +++ sys/arch/arm/include/bus.h
> @@ -93,7 +93,7 @@ struct bus_space {
>   void*bs_cookie;
>  
>   /* mapping/unmapping */
> - int (*bs_map) (void *, bus_addr_t, bus_size_t,
> + int (*bs_map) (void *, uint64_t, bus_size_t,
>   int, bus_space_handle_t *);
>   void(*bs_unmap) (void *, bus_space_handle_t,
>   bus_size_t);
> @@ -373,7 +373,7 @@ struct bus_space {
>   */
>  
>  #define bs_map_proto(f)  
> \
> -int  __bs_c(f,_bs_map) (void *t, bus_addr_t addr,\
> +int  __bs_c(f,_bs_map) (void *t, uint64_t addr,  \
>   bus_size_t size, int flags, bus_space_handle_t *bshp);
>  
>  #define bs_unmap_proto(f)\
> diff --git sys/arch/arm/simplebus/simplebus.c 
> sys/arch/arm/simplebus/simplebus.c
> index d2f5bfe..325e149 100644
> --- sys/arch/arm/simplebus/simplebus.c
> +++ sys/arch/arm/simplebus/simplebus.c
> @@ -30,7 +30,7 @@ int simplebus_match(struct device *, void *, void *);
>  void simplebus_attach(struct device *, struct device *, void *);
>  
>  void simplebus_attach_node(struct device *, int);
> -int simplebus_bs_map(void *, bus_addr_t, bus_size_t, int, bus_space_handle_t 
> *);
> +int simplebus_bs_map(void *, uint64_t, bus_size_t, int, bus_space_handle_t 
> *);
>  
>  struct simplebus_softc {
>   struct devicesc_dev;
> @@ -205,7 +205,7 @@ simplebus_attach_node(struct device *self, int node)
>   * Translate memory address if needed.
>   */
>  int
> -simplebus_bs_map(void *t, bus_addr_t bpa, bus_size_t size,
> +simplebus_bs_map(void *t, uint64_t bpa, bus_size_t size,
>  int flag, bus_space_handle_t *bshp)
>  {
>   struct simplebus_softc *sc = (struct simplebus_softc *)t;
> diff --git sys/arch/armv7/armv7/armv7_machdep.c 
> sys/arch/armv7/armv7/armv7_machdep.c
> index e869c2c..839e45b 100644
> --- sys/arch/armv7/armv7/armv7_machdep.c
> +++ sys/arch/armv7/armv7/armv7_machdep.c
> @@ -199,7 +199,7 @@ int   safepri = 0;
>  /* Prototypes */
>  
>  char bootargs[MAX_BOOT_STRING];
> -int  bootstrap_bs_map(void *, bus_addr_t, bus_size_t, int,
> +int  bootstrap_bs_map(void *, uint64_t, bus_size_t, int,
>  bus_space_handle_t *);
>  void process_kernel_args(char *);
>  void consinit(void);
> @@ -318,7 +318,7 @@ read_ttb(void)
>  static vaddr_t section_free = 0xfd00; /* XXX - huh */
>  
>  int
> -bootstrap_bs_map(void *t, bus_addr_t bpa, bus_size_t size,
> +bootstrap_bs_map(void *t, uint64_t bpa, bus_size_t size,
>  int flags, bus_space_handle_t *bshp)
>  {
>   u_long startpa, pa, endpa;
> @@ -393,7 +393,7 @@ initarm(void *arg0, void *arg1, void *arg2, paddr_t 
> loadaddr)
>  
>   /* early bus_space_map support */
>   struct bus_space tmp_bs_tag;
> - int (*map_func_save)(void *, bus_addr_t, bus_size_t, int,
> + int (*map_func_save)(void *, uint64_t, bus_size_t, int,
>   bus_space_handle_t *);
>  
>   if (arg0)
> 
> 



Re: cdce(4): Remove zaurus specific code

2016-10-07 Thread Mark Kettenis
> Date: Fri, 7 Oct 2016 16:32:35 +0200
> From: Frederic Cambus 
> 
> Hi tech@,
> 
> It seems there are still some leftovers from the zaurus port removal.
> 
> Comments? OK?

Not ok.  This is support for the zaurus as a usb device attached to an
OpenBSD machine.  Perhaps the option should be renamed (to CDCE_CRC32
for example) to make this clear.

Cheers,

Mark

> Index: sys/dev/usb/if_cdce.c
> ===
> RCS file: /cvs/src/sys/dev/usb/if_cdce.c,v
> retrieving revision 1.71
> diff -u -p -r1.71 if_cdce.c
> --- sys/dev/usb/if_cdce.c 26 Sep 2016 07:09:32 -  1.71
> +++ sys/dev/usb/if_cdce.c 7 Oct 2016 13:38:43 -
> @@ -88,7 +88,6 @@ void cdce_init(void *);
>  void  cdce_watchdog(struct ifnet *);
>  void  cdce_stop(struct cdce_softc *);
>  void  cdce_intr(struct usbd_xfer *, void *, usbd_status);
> -static uint32_t   cdce_crc32(const void *, size_t);
>  
>  const struct cdce_type cdce_devs[] = {
>  {{ USB_VENDOR_ACERLABS, USB_PRODUCT_ACERLABS_M5632 }, 0 },
> @@ -404,23 +403,14 @@ cdce_encap(struct cdce_softc *sc, struct
>  {
>   struct cdce_chain   *c;
>   usbd_status  err;
> - int  extra = 0;
>  
>   c = >cdce_cdata.cdce_tx_chain[idx];
>  
>   m_copydata(m, 0, m->m_pkthdr.len, c->cdce_buf);
> - if (sc->cdce_flags & CDCE_ZAURUS) {
> - /* Zaurus wants a 32-bit CRC appended to every frame */
> - u_int32_t crc;
> -
> - crc = cdce_crc32(c->cdce_buf, m->m_pkthdr.len);
> - bcopy(, c->cdce_buf + m->m_pkthdr.len, 4);
> - extra = 4;
> - }
>   c->cdce_mbuf = m;
>  
>   usbd_setup_xfer(c->cdce_xfer, sc->cdce_bulkout_pipe, c, c->cdce_buf,
> - m->m_pkthdr.len + extra, USBD_FORCE_SHORT_XFER | USBD_NO_COPY,
> + m->m_pkthdr.len, USBD_FORCE_SHORT_XFER | USBD_NO_COPY,
>   1, cdce_txeof);
>   err = usbd_transfer(c->cdce_xfer);
>   if (err != USBD_IN_PROGRESS) {
> @@ -741,8 +731,6 @@ cdce_rxeof(struct usbd_xfer *xfer, void 
>   sc->cdce_rxeof_errors = 0;
>  
>   usbd_get_xfer_status(xfer, NULL, NULL, _len, NULL);
> - if (sc->cdce_flags & CDCE_ZAURUS)
> - total_len -= 4; /* Strip off CRC added by Zaurus */
>   if (total_len <= 1)
>   goto done;
>  
> @@ -869,68 +857,3 @@ cdce_intr(struct usbd_xfer *xfer, void *
>  #endif
>  }
>  
> -
> -/*  COPYRIGHT (C) 1986 Gary S. Brown.  You may use this program, or
> - *  code or tables extracted from it, as desired without restriction.
> - */
> -
> -static uint32_t cdce_crc32_tab[] = {
> - 0x, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f,
> - 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,
> - 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2,
> - 0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,
> - 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
> - 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172,
> - 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, 0x42b2986c,
> - 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59,
> - 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423,
> - 0xcfba9599, 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
> - 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, 0x01db7106,
> - 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433,
> - 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d,
> - 0x91646c97, 0xe6635c01, 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e,
> - 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
> - 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65,
> - 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7,
> - 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0,
> - 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa,
> - 0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
> - 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81,
> - 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a,
> - 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, 0xe3630b12, 0x94643b84,
> - 0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1,
> - 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
> - 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc,
> - 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8, 0xa1d1937e,
> - 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,
> - 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55,
> - 

Re: add MCS support to radiotap

2016-10-08 Thread Mark Kettenis
> Date: Sat, 8 Oct 2016 13:06:53 +0200 (CEST)
> From: Mark Kettenis <mark.kette...@xs4all.nl>
> 
> > Date: Fri, 7 Oct 2016 18:59:52 +0200
> > From: Stefan Sperling <s...@stsp.name>
> > 
> > On Fri, Oct 07, 2016 at 03:28:19PM +0200, Stefan Sperling wrote:
> > > Currently tcpdump shows "0 Mbit/s" for any frame sent with 11n HT MCS.
> > > To make progress easier, I'd like to see which MCS are used on the air,
> > > by any device.
> > > 
> > > The change below matches what FreeBSD did to pass an MCS index via 
> > > radiotap.
> > > This simply writes the MCS index into a previously unused range of rate 
> > > values.
> > > This format is already recognized by third party tools such as wireshark
> > > so let's just do it the same way.
> > > 
> > > The diff below updates the radiotap docs, makes iwn pass the MCS index,
> > > shows it in tcpdump. I can now see MCS with iwn in monitor mode.
> > > 
> > > ok?
> > 
> > Same diff, plus iwn now captures MIMO frames in monitor mode.
> 
> The addition might need to be tested on a 1TR1 and 2T3R setups.  I can
> test the latter, but I have no hardware to test the former.

FWIW, this seems to cause no regressions on:

iwn0 at pci2 dev 0 function 0 "Intel WiFi Link 5300" rev 0x00: msi, MIMO 3T3R, 
MoW, address 00:21:6a:13:67:82

Cheers,

Mark

> > Index: sys/net80211/ieee80211_radiotap.h
> > ===
> > RCS file: /cvs/src/sys/net80211/ieee80211_radiotap.h,v
> > retrieving revision 1.13
> > diff -u -p -r1.13 ieee80211_radiotap.h
> > --- sys/net80211/ieee80211_radiotap.h   12 Jan 2016 09:28:09 -  
> > 1.13
> > +++ sys/net80211/ieee80211_radiotap.h   7 Oct 2016 13:15:59 -
> > @@ -90,9 +90,10 @@ struct ieee80211_radiotap_header {
> >   *  For frequency-hopping radios, the hop set (first byte)
> >   *  and pattern (second byte).
> >   *
> > - * IEEE80211_RADIOTAP_RATE  u_int8_t500kb/s
> > + * IEEE80211_RADIOTAP_RATE  u_int8_t500kb/s or MCS 
> > index
> >   *
> > - *  Tx/Rx data rate
> > + *  Tx/Rx data rate in units of 500kb/s. If the high bit (0x80) is set
> > + *  the remaining bits contain an MCS index instead of a date rate.
> >   *
> >   * IEEE80211_RADIOTAP_DBM_ANTSIGNAL int8_t  decibels from
> >   *  one milliwatt (dBm)
> > Index: sys/dev/pci/if_iwn.c
> > ===
> > RCS file: /cvs/src/sys/dev/pci/if_iwn.c,v
> > retrieving revision 1.172
> > diff -u -p -r1.172 if_iwn.c
> > --- sys/dev/pci/if_iwn.c5 Sep 2016 08:18:18 -   1.172
> > +++ sys/dev/pci/if_iwn.c7 Oct 2016 16:33:39 -
> > @@ -2131,23 +2131,27 @@ iwn_rx_done(struct iwn_softc *sc, struct
> > tap->wr_dbm_antsignal = (int8_t)rssi;
> > tap->wr_dbm_antnoise = (int8_t)sc->noise;
> > tap->wr_tsft = stat->tstamp;
> > -   switch (stat->rate) {
> > -   /* CCK rates. */
> > -   case  10: tap->wr_rate =   2; break;
> > -   case  20: tap->wr_rate =   4; break;
> > -   case  55: tap->wr_rate =  11; break;
> > -   case 110: tap->wr_rate =  22; break;
> > -   /* OFDM rates. */
> > -   case 0xd: tap->wr_rate =  12; break;
> > -   case 0xf: tap->wr_rate =  18; break;
> > -   case 0x5: tap->wr_rate =  24; break;
> > -   case 0x7: tap->wr_rate =  36; break;
> > -   case 0x9: tap->wr_rate =  48; break;
> > -   case 0xb: tap->wr_rate =  72; break;
> > -   case 0x1: tap->wr_rate =  96; break;
> > -   case 0x3: tap->wr_rate = 108; break;
> > -   /* Unknown rate: should not happen. */
> > -   default:  tap->wr_rate =   0;
> > +   if (stat->rflags & IWN_RFLAG_MCS) {
> > +   tap->wr_rate = (0x80 | stat->rate); /* HT MCS index */
> > +   } else {
> > +   switch (stat->rate) {
> > +   /* CCK rates. */
> > +   case  10: tap->wr_rate =   2; break;
> > +   case  20: tap->wr_rate =   4; break;
> > +   case  55: tap->wr_rate =  11; break;
> > +   case 110: tap->wr_rat

Re: iwm ack rate mapping

2016-10-08 Thread Mark Kettenis
> Date: Fri, 7 Oct 2016 14:01:27 +0200
> From: Stefan Sperling 
> 
> Imre Vadasz pointed out that rate sets managed by net80211 are sorted
> by effective data rate speed, while the iwm_rates array sorts CCK rates
> (1 - 11 Mbit/s) before OFDM rates (6Mbit/s - 54Mbit/s).
> 
> rate set (11g): 1, 2, 5.5, 6, 9, 11, 12, 18, 24, 36, 54
> iwm_rates:  1, 2, 5.5, 11, 6, 9, 12, 18, 24, 36, 54
> 
> The rate set is sorted at runtime and its length differs between 11a/11b/11g.
> So let's add a mapping function and fill the ACK rate bitmap correctly
> without making assumptions about the rate set.

Looks good to me.

> Index: if_iwm.c
> ===
> RCS file: /cvs/src/sys/dev/pci/if_iwm.c,v
> retrieving revision 1.143
> diff -u -p -r1.143 if_iwm.c
> --- if_iwm.c  5 Oct 2016 18:13:25 -   1.143
> +++ if_iwm.c  7 Oct 2016 11:50:19 -
> @@ -398,6 +398,7 @@ int   iwm_fill_probe_req(struct iwm_softc 
>  int  iwm_lmac_scan(struct iwm_softc *);
>  int  iwm_config_umac_scan(struct iwm_softc *);
>  int  iwm_umac_scan(struct iwm_softc *);
> +uint8_t  iwm_ridx2rate(struct ieee80211_rateset *, int);
>  void iwm_ack_rates(struct iwm_softc *, struct iwm_node *, int *, int *);
>  void iwm_mac_ctxt_cmd_common(struct iwm_softc *, struct iwm_node *,
>   struct iwm_mac_ctx_cmd *, uint32_t, int);
> @@ -4881,6 +4882,21 @@ iwm_umac_scan(struct iwm_softc *sc)
>   return err;
>  }
>  
> +uint8_t
> +iwm_ridx2rate(struct ieee80211_rateset *rs, int ridx)
> +{
> + int i;
> + uint8_t rval;
> +
> + for (i = 0; i < rs->rs_nrates; i++) {
> + rval = (rs->rs_rates[i] & IEEE80211_RATE_VAL);
> + if (rval == iwm_rates[ridx].rate)
> + return rs->rs_rates[i];
> + }
> +
> + return 0;
> +}
> +
>  void
>  iwm_ack_rates(struct iwm_softc *sc, struct iwm_node *in, int *cck_rates,
>  int *ofdm_rates)
> @@ -4895,17 +4911,16 @@ iwm_ack_rates(struct iwm_softc *sc, stru
>  
>   if (ni->ni_chan == IEEE80211_CHAN_ANYC ||
>   IEEE80211_IS_CHAN_2GHZ(ni->ni_chan)) {
> - for (i = 0; i < MIN(IWM_FIRST_OFDM_RATE, rs->rs_nrates); i++) {
> - if ((rs->rs_rates[i] & IEEE80211_RATE_BASIC) == 0)
> + for (i = IWM_FIRST_CCK_RATE; i < IWM_FIRST_OFDM_RATE; i++) {
> + if ((iwm_ridx2rate(rs, i) & IEEE80211_RATE_BASIC) == 0)
>   continue;
>   cck |= (1 << i);
>   if (lowest_present_cck > i)
>   lowest_present_cck = i;
>   }
>   }
> - for (i = IWM_FIRST_OFDM_RATE;
> - i <= MIN(IWM_LAST_NON_HT_RATE, rs->rs_nrates - 1); i++) {
> - if ((rs->rs_rates[i] & IEEE80211_RATE_BASIC) == 0)
> + for (i = IWM_FIRST_OFDM_RATE; i <= IWM_LAST_NON_HT_RATE; i++) {
> + if ((iwm_ridx2rate(rs, i) & IEEE80211_RATE_BASIC) == 0)
>   continue;   
>   ofdm |= (1 << (i - IWM_FIRST_OFDM_RATE));
>   if (lowest_present_ofdm > i)
> 
> 



Re: hide iwn firmware error log

2016-10-08 Thread Mark Kettenis
> Date: Thu, 6 Oct 2016 12:46:21 +0200
> From: Stefan Sperling 
> 
> Disable the detailed fatal firmware error log in iwn(4) by default.

You're the best judge on how useful this information is.

ok kettenis@

> Index: if_iwn.c
> ===
> RCS file: /cvs/src/sys/dev/pci/if_iwn.c,v
> retrieving revision 1.172
> diff -u -p -r1.172 if_iwn.c
> --- if_iwn.c  5 Sep 2016 08:18:18 -   1.172
> +++ if_iwn.c  6 Oct 2016 10:42:41 -
> @@ -2595,6 +2595,7 @@ iwn_wakeup_intr(struct iwn_softc *sc)
>   }
>  }
>  
> +#ifdef IWN_DEBUG
>  /*
>   * Dump the error log of the firmware when a firmware panic occurs.  Although
>   * we can't debug the firmware because it is neither open source nor free, it
> @@ -2606,9 +2607,6 @@ iwn_fatal_intr(struct iwn_softc *sc)
>   struct iwn_fw_dump dump;
>   int i;
>  
> - /* Force a complete recalibration on next init. */
> - sc->sc_flags &= ~IWN_FLAG_CALIB_DONE;
> -
>   /* Check that the error log address is valid. */
>   if (sc->errptr < IWN_FW_DATA_BASE ||
>   sc->errptr + sizeof (dump) >
> @@ -2657,6 +2655,7 @@ iwn_fatal_intr(struct iwn_softc *sc)
>   printf("  rx ring: cur=%d\n", sc->rxq.cur);
>   printf("  802.11 state %d\n", sc->sc_ic.ic_state);
>  }
> +#endif
>  
>  int
>  iwn_intr(void *arg)
> @@ -2711,8 +2710,14 @@ iwn_intr(void *arg)
>   }
>   if (r1 & (IWN_INT_SW_ERR | IWN_INT_HW_ERR)) {
>   printf("%s: fatal firmware error\n", sc->sc_dev.dv_xname);
> +
> + /* Force a complete recalibration on next init. */
> + sc->sc_flags &= ~IWN_FLAG_CALIB_DONE;
> +
>   /* Dump firmware error log and stop. */
> +#ifdef IWN_DEBUG
>   iwn_fatal_intr(sc);
> +#endif
>   iwn_stop(ifp, 1);
>   task_add(systq, >init_task);
>   return 1;
> 
> 



Re: iwm(4): Improve iwm_rx_addbuf() error handling.

2016-10-08 Thread Mark Kettenis
> Date: Thu, 6 Oct 2016 12:56:37 +0200
> From: Stefan Sperling 
> 
> On Thu, Oct 06, 2016 at 10:49:21AM +0200, Imre Vadasz wrote:
> > Hi,
> > This patch improves the error handling iwm_rx_addbuf(), specifically in
> > out-of-memory and mbuf exhaustion cases.
> > 
> > Keep an additional/spare bus_dmamap_t object around to make error handling
> > for bus_dmamap_load_mbuf() failures easier in iwm_rx_addbuf().
> > This seems like an easy way to avoid having weird panic() cases in the code
> > (like in iwn, which then tries to bus_dmamap_load_mbuf() the old mbuf and
> > panics when that fails).
> > 
> > Move mbuf modifications that are needed before calling ieee80211_input()
> > in iwm_rx_rx_mpdu() to below the iwm_rx_addbuf call. Otherwise we can end
> > up with a broken mbuf in the rx ring when iwm_rx_rx_mpdu() aborts.
> 
> If memory is so tight that this panic triggers is it reasonable to
> even try to recover? I honestly don't know.
> 
> This problem exists in many drivers.
> Are we going to add a spare map to all of them?
> 
> $ egrep -i 'panic.*rx.*buf' pci/*c ic/*c
> pci/if_ipw.c: panic("%s: could not load old rx mbuf",
> pci/if_iwi.c: panic("%s: could not load old rx mbuf",
> pci/if_iwm.c: panic("iwm: could not load RX mbuf");
> pci/if_iwn.c: panic("%s: could not load old RX mbuf",
> pci/if_ix.c:  panic("%s: ixgbe_rxeof: NULL mbuf in slot %d "
> pci/if_nfe.c: panic("%s: could not load old rx mbuf",
> pci/if_pcn.c: panic("pcn_add_rxbuf");
> pci/if_rtwn.c:panic("%s: could not load old RX mbuf",
> pci/if_stge.c:panic("stge_add_rxbuf");/* XXX */
> pci/if_vio.c: panic("enqueue_prep for rx buffers: %d", r);
> pci/if_wpi.c: panic("%s: could not load old RX mbuf",
> ic/aic6915.c: panic("sf_add_rxbuf"); /* XXX */
> ic/atw.c: panic("atw_add_rxbuf"); /* XXX */
> ic/dwc_gmac.c:panic("%s: could not load old 
> rx mbuf",
> ic/gem.c: panic("gem_add_rxbuf"); /* XXX */
> ic/malo.c:panic("%s: could not load old rx mbuf",
> ic/rt2560.c:  panic("%s: could not load old rx mbuf",
> ic/rt2661.c:  panic("%s: could not load old rx mbuf",
> ic/rt2860.c:  panic("%s: could not load old rx mbuf",
> ic/smc83c170.c:   panic("epic_add_rxbuf");/* XXX */

I think we're at the point where bus_dmamap_load() should never fail
because of memory shortage.  As part of the effort to make interrupt
handlers mpsafe, we pre-allocate all the necessary resources.  I think
the sparc64 iommu code can still return ENOMEM, but only if you screw
up and bus_dmam_load() something that doesn't fit into the resources
created by bus_dmamap_create().  And that would almost certainly be a
driver bug.



Re: athn: allow lower tx retry rates with RTS

2016-10-08 Thread Mark Kettenis
> Date: Fri, 7 Oct 2016 08:33:06 +0200
> From: Stefan Sperling 
> 
> On Thu, Oct 06, 2016 at 06:51:04PM +0200, Stefan Sperling wrote:
> > athn(4) has a hack which disables lower Tx retry rates if RTS is used.
> > 
> > I don't understand why this was added. Perhaps the assumption was
> > that RTS will prevent transmission failures outright.
> 
> I believe I've found the reason for this after examining the frame
> exchanges more closely. OK to commit these comments instead?
> 
> The duration field mentioned below specifies the air time required
> to send the data frame + ack. And of course different data rates
> use up different amounts of air time.

Not to familliar with the specs, but you explanation Sounds plausible.
I wouldn't hesitate to commit this.

> Index: ar5008.c
> ===
> RCS file: /cvs/src/sys/dev/ic/ar5008.c,v
> retrieving revision 1.35
> diff -u -p -r1.35 ar5008.c
> --- ar5008.c  5 Jan 2016 18:41:15 -   1.35
> +++ ar5008.c  7 Oct 2016 06:26:03 -
> @@ -1467,8 +1467,12 @@ ar5008_tx(struct athn_softc *sc, struct 
>   ds->ds_ctl0 |= AR_TXC0_CTS_ENABLE;
>   }
>   }
> + /* 
> +  * Disable multi-rate retries when protection is used.
> +  * The RTS/CTS frame's duration field is fixed and won't be
> +  * updated by hardware when the data rate changes.
> +  */
>   if (ds->ds_ctl0 & (AR_TXC0_RTS_ENABLE | AR_TXC0_CTS_ENABLE)) {
> - /* Disable multi-rate retries when protection is used. */
>   ridx[1] = ridx[2] = ridx[3] = ridx[0];
>   }
>   /* Setup multi-rate retries. */
> Index: ar9003.c
> ===
> RCS file: /cvs/src/sys/dev/ic/ar9003.c,v
> retrieving revision 1.39
> diff -u -p -r1.39 ar9003.c
> --- ar9003.c  5 Jan 2016 18:41:15 -   1.39
> +++ ar9003.c  7 Oct 2016 06:26:18 -
> @@ -1613,8 +1613,12 @@ ar9003_tx(struct athn_softc *sc, struct 
>   ds->ds_ctl11 |= AR_TXC11_CTS_ENABLE;
>   }
>   }
> + /* 
> +  * Disable multi-rate retries when protection is used.
> +  * The RTS/CTS frame's duration field is fixed and won't be
> +  * updated by hardware when the data rate changes.
> +  */
>   if (ds->ds_ctl11 & (AR_TXC11_RTS_ENABLE | AR_TXC11_CTS_ENABLE)) {
> - /* Disable multi-rate retries when protection is used. */
>   ridx[1] = ridx[2] = ridx[3] = ridx[0];
>   }
>   /* Setup multi-rate retries. */
> 
> 
> 



Re: add MCS support to radiotap

2016-10-08 Thread Mark Kettenis
> Date: Fri, 7 Oct 2016 15:28:19 +0200
> From: Stefan Sperling 
> 
> Currently tcpdump shows "0 Mbit/s" for any frame sent with 11n HT MCS.
> To make progress easier, I'd like to see which MCS are used on the air,
> by any device.
> 
> The change below matches what FreeBSD did to pass an MCS index via radiotap.
> This simply writes the MCS index into a previously unused range of rate 
> values.
> This format is already recognized by third party tools such as wireshark
> so let's just do it the same way.
> 
> The diff below updates the radiotap docs, makes iwn pass the MCS index,
> shows it in tcpdump. I can now see MCS with iwn in monitor mode.
> 
> ok?

ok kettenis@

> Index: sys/net80211/ieee80211_radiotap.h
> ===
> RCS file: /cvs/src/sys/net80211/ieee80211_radiotap.h,v
> retrieving revision 1.13
> diff -u -p -r1.13 ieee80211_radiotap.h
> --- sys/net80211/ieee80211_radiotap.h 12 Jan 2016 09:28:09 -  1.13
> +++ sys/net80211/ieee80211_radiotap.h 7 Oct 2016 13:15:59 -
> @@ -90,9 +90,10 @@ struct ieee80211_radiotap_header {
>   *  For frequency-hopping radios, the hop set (first byte)
>   *  and pattern (second byte).
>   *
> - * IEEE80211_RADIOTAP_RATE  u_int8_t500kb/s
> + * IEEE80211_RADIOTAP_RATE  u_int8_t500kb/s or MCS index
>   *
> - *  Tx/Rx data rate
> + *  Tx/Rx data rate in units of 500kb/s. If the high bit (0x80) is set
> + *  the remaining bits contain an MCS index instead of a date rate.
>   *
>   * IEEE80211_RADIOTAP_DBM_ANTSIGNAL int8_t  decibels from
>   *  one milliwatt (dBm)
> Index: sys/dev/pci/if_iwn.c
> ===
> RCS file: /cvs/src/sys/dev/pci/if_iwn.c,v
> retrieving revision 1.172
> diff -u -p -r1.172 if_iwn.c
> --- sys/dev/pci/if_iwn.c  5 Sep 2016 08:18:18 -   1.172
> +++ sys/dev/pci/if_iwn.c  7 Oct 2016 13:10:42 -
> @@ -2131,23 +2131,27 @@ iwn_rx_done(struct iwn_softc *sc, struct
>   tap->wr_dbm_antsignal = (int8_t)rssi;
>   tap->wr_dbm_antnoise = (int8_t)sc->noise;
>   tap->wr_tsft = stat->tstamp;
> - switch (stat->rate) {
> - /* CCK rates. */
> - case  10: tap->wr_rate =   2; break;
> - case  20: tap->wr_rate =   4; break;
> - case  55: tap->wr_rate =  11; break;
> - case 110: tap->wr_rate =  22; break;
> - /* OFDM rates. */
> - case 0xd: tap->wr_rate =  12; break;
> - case 0xf: tap->wr_rate =  18; break;
> - case 0x5: tap->wr_rate =  24; break;
> - case 0x7: tap->wr_rate =  36; break;
> - case 0x9: tap->wr_rate =  48; break;
> - case 0xb: tap->wr_rate =  72; break;
> - case 0x1: tap->wr_rate =  96; break;
> - case 0x3: tap->wr_rate = 108; break;
> - /* Unknown rate: should not happen. */
> - default:  tap->wr_rate =   0;
> + if (stat->rflags & IWN_RFLAG_MCS) {
> + tap->wr_rate = (0x80 | stat->rate); /* HT MCS index */
> + } else {
> + switch (stat->rate) {
> + /* CCK rates. */
> + case  10: tap->wr_rate =   2; break;
> + case  20: tap->wr_rate =   4; break;
> + case  55: tap->wr_rate =  11; break;
> + case 110: tap->wr_rate =  22; break;
> + /* OFDM rates. */
> + case 0xd: tap->wr_rate =  12; break;
> + case 0xf: tap->wr_rate =  18; break;
> + case 0x5: tap->wr_rate =  24; break;
> + case 0x7: tap->wr_rate =  36; break;
> + case 0x9: tap->wr_rate =  48; break;
> + case 0xb: tap->wr_rate =  72; break;
> + case 0x1: tap->wr_rate =  96; break;
> + case 0x3: tap->wr_rate = 108; break;
> + /* Unknown rate: should not happen. */
> + default:  tap->wr_rate =  0;
> + }
>   }
>  
>   mb.m_data = (caddr_t)tap;
> @@ -2876,8 +2880,7 @@ iwn_tx(struct iwn_softc *sc, struct mbuf
>   if ((ni->ni_flags & IEEE80211_NODE_HT) &&
>   !IEEE80211_IS_MULTICAST(wh->i_addr1) &&
>   type == IEEE80211_FC0_TYPE_DATA) {
> - /* XXX need a way to pass current MCS in 11n mode */
> - tap->wt_rate = 0;
> + tap->wt_rate = (0x80 | ni->ni_txmcs);
>   } else
>   tap->wt_rate = rinfo->rate;
>   tap->wt_hwqueue = ac;
> Index: usr.sbin/tcpdump/print-802_11.c
> ===
> RCS 

Re: add MCS support to radiotap

2016-10-08 Thread Mark Kettenis
> Date: Fri, 7 Oct 2016 18:59:52 +0200
> From: Stefan Sperling 
> 
> On Fri, Oct 07, 2016 at 03:28:19PM +0200, Stefan Sperling wrote:
> > Currently tcpdump shows "0 Mbit/s" for any frame sent with 11n HT MCS.
> > To make progress easier, I'd like to see which MCS are used on the air,
> > by any device.
> > 
> > The change below matches what FreeBSD did to pass an MCS index via radiotap.
> > This simply writes the MCS index into a previously unused range of rate 
> > values.
> > This format is already recognized by third party tools such as wireshark
> > so let's just do it the same way.
> > 
> > The diff below updates the radiotap docs, makes iwn pass the MCS index,
> > shows it in tcpdump. I can now see MCS with iwn in monitor mode.
> > 
> > ok?
> 
> Same diff, plus iwn now captures MIMO frames in monitor mode.

The addition might need to be tested on a 1TR1 and 2T3R setups.  I can
test the latter, but I have no hardware to test the former.

> Index: sys/net80211/ieee80211_radiotap.h
> ===
> RCS file: /cvs/src/sys/net80211/ieee80211_radiotap.h,v
> retrieving revision 1.13
> diff -u -p -r1.13 ieee80211_radiotap.h
> --- sys/net80211/ieee80211_radiotap.h 12 Jan 2016 09:28:09 -  1.13
> +++ sys/net80211/ieee80211_radiotap.h 7 Oct 2016 13:15:59 -
> @@ -90,9 +90,10 @@ struct ieee80211_radiotap_header {
>   *  For frequency-hopping radios, the hop set (first byte)
>   *  and pattern (second byte).
>   *
> - * IEEE80211_RADIOTAP_RATE  u_int8_t500kb/s
> + * IEEE80211_RADIOTAP_RATE  u_int8_t500kb/s or MCS index
>   *
> - *  Tx/Rx data rate
> + *  Tx/Rx data rate in units of 500kb/s. If the high bit (0x80) is set
> + *  the remaining bits contain an MCS index instead of a date rate.
>   *
>   * IEEE80211_RADIOTAP_DBM_ANTSIGNAL int8_t  decibels from
>   *  one milliwatt (dBm)
> Index: sys/dev/pci/if_iwn.c
> ===
> RCS file: /cvs/src/sys/dev/pci/if_iwn.c,v
> retrieving revision 1.172
> diff -u -p -r1.172 if_iwn.c
> --- sys/dev/pci/if_iwn.c  5 Sep 2016 08:18:18 -   1.172
> +++ sys/dev/pci/if_iwn.c  7 Oct 2016 16:33:39 -
> @@ -2131,23 +2131,27 @@ iwn_rx_done(struct iwn_softc *sc, struct
>   tap->wr_dbm_antsignal = (int8_t)rssi;
>   tap->wr_dbm_antnoise = (int8_t)sc->noise;
>   tap->wr_tsft = stat->tstamp;
> - switch (stat->rate) {
> - /* CCK rates. */
> - case  10: tap->wr_rate =   2; break;
> - case  20: tap->wr_rate =   4; break;
> - case  55: tap->wr_rate =  11; break;
> - case 110: tap->wr_rate =  22; break;
> - /* OFDM rates. */
> - case 0xd: tap->wr_rate =  12; break;
> - case 0xf: tap->wr_rate =  18; break;
> - case 0x5: tap->wr_rate =  24; break;
> - case 0x7: tap->wr_rate =  36; break;
> - case 0x9: tap->wr_rate =  48; break;
> - case 0xb: tap->wr_rate =  72; break;
> - case 0x1: tap->wr_rate =  96; break;
> - case 0x3: tap->wr_rate = 108; break;
> - /* Unknown rate: should not happen. */
> - default:  tap->wr_rate =   0;
> + if (stat->rflags & IWN_RFLAG_MCS) {
> + tap->wr_rate = (0x80 | stat->rate); /* HT MCS index */
> + } else {
> + switch (stat->rate) {
> + /* CCK rates. */
> + case  10: tap->wr_rate =   2; break;
> + case  20: tap->wr_rate =   4; break;
> + case  55: tap->wr_rate =  11; break;
> + case 110: tap->wr_rate =  22; break;
> + /* OFDM rates. */
> + case 0xd: tap->wr_rate =  12; break;
> + case 0xf: tap->wr_rate =  18; break;
> + case 0x5: tap->wr_rate =  24; break;
> + case 0x7: tap->wr_rate =  36; break;
> + case 0x9: tap->wr_rate =  48; break;
> + case 0xb: tap->wr_rate =  72; break;
> + case 0x1: tap->wr_rate =  96; break;
> + case 0x3: tap->wr_rate = 108; break;
> + /* Unknown rate: should not happen. */
> + default:  tap->wr_rate =  0;
> + }
>   }
>  
>   mb.m_data = (caddr_t)tap;
> @@ -2876,8 +2880,7 @@ iwn_tx(struct iwn_softc *sc, struct mbuf
>   if ((ni->ni_flags & IEEE80211_NODE_HT) &&
>   !IEEE80211_IS_MULTICAST(wh->i_addr1) &&
>   type == IEEE80211_FC0_TYPE_DATA) {
> - /* XXX need a way to pass current MCS in 11n mode */
> - tap->wt_rate = 0;
> + 

sxitimer(4) fix

2016-10-09 Thread Mark Kettenis
On my Olimex A10s-Olinuxino Micro, time drifts quite fast (something
of the order of a second per minute).  The driver is written to use a
32kHz clock.  The device tree on both sun4i and sun5i only references
the 24MHz clock though.  And the A10s and A13 datasheets don't
document the settings for using the 32kHz clock.  The diff below
switches the driver over to the 24MHz clock.  This could use some
additional testing on other boards, especially those with the A10 SoC
such as the original Cubieboard.


Index: arch/armv7/sunxi/sunxireg.h
===
RCS file: /cvs/src/sys/arch/armv7/sunxi/sunxireg.h,v
retrieving revision 1.8
diff -u -p -r1.8 sunxireg.h
--- arch/armv7/sunxi/sunxireg.h 2 Feb 2016 21:40:47 -   1.8
+++ arch/armv7/sunxi/sunxireg.h 9 Oct 2016 16:03:38 -
@@ -37,9 +37,9 @@
 #defineSXICMS4(sc, reg, mask, bits)
\
SXIWRITE4((sc), (reg), (SXIREAD4((sc), (reg)) & ~(mask)) | (bits))
 
-#defineTIMER0_FREQUENCY(32768)
-#defineTIMER1_FREQUENCY(32768)
-#defineTIMER2_FREQUENCY(32768)
+#defineTIMER0_FREQUENCY(2400)
+#defineTIMER1_FREQUENCY(2400)
+#defineTIMER2_FREQUENCY(2400)
 #defineCOUNTER_FREQUENCY   (2400)
 
 /* SRAM Controller / System Control */
Index: arch/armv7/sunxi/sxitimer.c
===
RCS file: /cvs/src/sys/arch/armv7/sunxi/sxitimer.c,v
retrieving revision 1.6
diff -u -p -r1.6 sxitimer.c
--- arch/armv7/sunxi/sxitimer.c 18 Jul 2016 19:22:45 -  1.6
+++ arch/armv7/sunxi/sxitimer.c 9 Oct 2016 16:03:45 -
@@ -52,13 +52,9 @@
 #defineCNT64_CLR_EN(1 << 0) /* clear enable */
 #defineCNT64_RL_EN (1 << 1) /* read latch enable */
 
-#defineLOSC_CTRL   0x100
-#defineOSC32K_SRC_SEL  (1 << 0)
-
 #defineTIMER_ENABLE(1 << 0)
 #defineTIMER_RELOAD(1 << 1)
 #defineTIMER_CLK_SRC_MASK  (3 << 2)
-#defineTIMER_LSOSC (0 << 2)
 #defineTIMER_OSC24M(1 << 2)
 #defineTIMER_PLL6_6(2 << 2)
 #defineTIMER_PRESC_1   (0 << 4)
@@ -132,7 +128,7 @@ void
 sxitimer_attach(struct device *parent, struct device *self, void *args)
 {
struct armv7_attach_args *aa = args;
-   uint32_t freq, ival, now, cr;
+   uint32_t freq, ival, now;
int unit = self->dv_unit;
 
if (unit != 0)
@@ -151,11 +147,6 @@ sxitimer_attach(struct device *parent, s
& CNT64_CLR_EN)
continue;
 
-   /* setup timers */
-   cr = bus_space_read_4(sxitimer_iot, sxitimer_ioh, LOSC_CTRL);
-   cr |= OSC32K_SRC_SEL; /* ext 32.768KHz OSC src */
-   bus_space_write_4(sxitimer_iot, sxitimer_ioh, LOSC_CTRL, cr);
-
 skip_init:
/* timers are down-counters, from interval to 0 */
now = 0x; /* known big value */
@@ -163,8 +154,7 @@ skip_init:
 
/* stop timer, and set clk src */
bus_space_write_4(sxitimer_iot, sxitimer_ioh,
-   TIMER_CTRL(unit),
-   freq == 2400 ? TIMER_OSC24M : TIMER_LSOSC);
+   TIMER_CTRL(unit), TIMER_OSC24M);
 
switch (unit) { /* XXX more TIMER magic for less lines? */
case TICKTIMER:
@@ -217,7 +207,7 @@ skip_init:
 void
 sxitimer_cpu_initclocks(void)
 {
-   uint32_t isr, ier;
+   uint32_t isr, ier, ctrl;
 
/* establish interrupts */
arm_intr_establish(sxitimer_irq[TICKTIMER], IPL_CLOCK,
@@ -236,17 +226,23 @@ sxitimer_cpu_initclocks(void)
bus_space_write_4(sxitimer_iot, sxitimer_ioh, TIMER_IER, ier);
 
/* enable timers */
+   ctrl = bus_space_read_4(sxitimer_iot, sxitimer_ioh,
+   TIMER_CTRL(CNTRTIMER));
bus_space_write_4(sxitimer_iot, sxitimer_ioh,
TIMER_CTRL(CNTRTIMER),
-   TIMER_ENABLE | TIMER_RELOAD | TIMER_CONTINOUS);
+   ctrl | TIMER_ENABLE | TIMER_RELOAD | TIMER_CONTINOUS);
 
+   ctrl = bus_space_read_4(sxitimer_iot, sxitimer_ioh,
+   TIMER_CTRL(STATTIMER));
bus_space_write_4(sxitimer_iot, sxitimer_ioh,
TIMER_CTRL(STATTIMER),
-   TIMER_ENABLE | TIMER_RELOAD | TIMER_SINGLESHOT);
+   ctrl | TIMER_ENABLE | TIMER_RELOAD | TIMER_SINGLESHOT);
 
+   ctrl = bus_space_read_4(sxitimer_iot, sxitimer_ioh,
+   TIMER_CTRL(TICKTIMER));
bus_space_write_4(sxitimer_iot, sxitimer_ioh,
TIMER_CTRL(TICKTIMER),
-   TIMER_ENABLE | TIMER_RELOAD | TIMER_SINGLESHOT);
+   ctrl | TIMER_ENABLE | TIMER_RELOAD | TIMER_SINGLESHOT);
 }
 
 /* 



fec(4) mii_tick

2016-09-21 Thread Mark Kettenis
Here is the promised diff that makes fec(4) call mii_tick() like all
our other ethernet drivers that use mii do.

Does this fix your problem Philip?


Index: sys/arch/armv7/imx/if_fec.c
===
RCS file: /cvs/src/sys/arch/armv7/imx/if_fec.c,v
retrieving revision 1.17
diff -u -p -r1.17 if_fec.c
--- sys/arch/armv7/imx/if_fec.c 21 Sep 2016 10:28:47 -  1.17
+++ sys/arch/armv7/imx/if_fec.c 21 Sep 2016 11:19:21 -
@@ -231,6 +231,7 @@ struct fec_softc {
struct fec_buffer   *rx_buffer_base;
int cur_tx;
int cur_rx;
+   struct timeout  sc_tick;
 };
 
 struct fec_softc *fec_sc;
@@ -249,6 +250,7 @@ void fec_iff(struct fec_softc *);
 struct mbuf * fec_newbuf(void);
 int fec_intr(void *);
 void fec_recv(struct fec_softc *);
+void fec_tick(void *);
 int fec_miibus_readreg(struct device *, int, int);
 void fec_miibus_writereg(struct device *, int, int, int);
 void fec_miibus_statchg(struct device *);
@@ -430,6 +432,8 @@ fec_attach(struct device *parent, struct
ether_ifattach(ifp);
splx(s);
 
+   timeout_set(>sc_tick, fec_tick, sc);
+
fec_sc = sc;
return;
 
@@ -966,6 +970,19 @@ done:
HWRITE4(sc, ENET_RDAR, ENET_RDAR_RDAR);
 
if_input(ifp, );
+}
+
+void
+fec_tick(void *arg)
+{
+   struct fec_softc *sc = arg;
+   int s;
+
+   s = splnet();
+   mii_tick(>sc_mii);
+   splx(s);
+
+   timeout_add_sec(>sc_tick, 1);
 }
 
 /*



fec(4) cleanup

2016-09-21 Thread Mark Kettenis
Diff below removes nused code from the driver and makes sure we only
enable the tx and rx interrupts.  This seems to work fine for me.
Next step will be to add the missing PHY tick stuff.

ok?


Index: sys/arch/armv7/imx/if_fec.c
===
RCS file: /cvs/src/sys/arch/armv7/imx/if_fec.c,v
retrieving revision 1.16
diff -u -p -r1.16 if_fec.c
--- sys/arch/armv7/imx/if_fec.c 19 Aug 2016 18:25:53 -  1.16
+++ sys/arch/armv7/imx/if_fec.c 21 Sep 2016 08:11:53 -
@@ -221,7 +221,6 @@ struct fec_softc {
bus_space_handle_t  sc_ioh;
void*sc_ih; /* Interrupt handler */
bus_dma_tag_t   sc_dma_tag;
-   uint32_tintr_status;/* soft interrupt status */
struct fec_dma_alloctxdma;  /* bus_dma glue for tx desc */
struct fec_buf_desc *tx_desc_base;
struct fec_dma_allocrxdma;  /* bus_dma glue for rx desc */
@@ -250,7 +249,6 @@ void fec_iff(struct fec_softc *);
 struct mbuf * fec_newbuf(void);
 int fec_intr(void *);
 void fec_recv(struct fec_softc *);
-int fec_wait_intr(struct fec_softc *, int, int);
 int fec_miibus_readreg(struct device *, int, int);
 void fec_miibus_writereg(struct device *, int, int, int);
 void fec_miibus_statchg(struct device *);
@@ -680,7 +678,6 @@ fec_init(struct fec_softc *sc)
 
/* enable interrupts for tx/rx */
HWRITE4(sc, ENET_EIMR, ENET_EIR_TXF | ENET_EIR_RXF);
-   HWRITE4(sc, ENET_EIMR, 0x);
 
fec_start(ifp);
 }
@@ -900,15 +897,6 @@ fec_intr(void *arg)
HWRITE4(sc, ENET_EIR, status);
 
/*
-* Wake up the blocking process to service command
-* related interrupt(s).
-*/
-   if (ISSET(status, ENET_EIR_MII)) {
-   sc->intr_status |= status;
-   wakeup(>intr_status);
-   }
-
-   /*
 * Handle incoming packets.
 */
if (ISSET(status, ENET_EIR_RXF)) {
@@ -978,28 +966,6 @@ done:
HWRITE4(sc, ENET_RDAR, ENET_RDAR_RDAR);
 
if_input(ifp, );
-}
-
-int
-fec_wait_intr(struct fec_softc *sc, int mask, int timo)
-{
-   int status;
-   int s;
-
-   s = splnet();
-
-   status = sc->intr_status;
-   while (status == 0) {
-   if (tsleep(>intr_status, PWAIT, "hcintr", timo)
-   == EWOULDBLOCK) {
-   break;
-   }
-   status = sc->intr_status;
-   }
-   sc->intr_status &= ~status;
-
-   splx(s);
-   return status;
 }
 
 /*



Re: OMAP4/5 Wake-up generator driver

2016-09-15 Thread Mark Kettenis
> Date: Thu, 15 Sep 2016 14:53:14 +1000
> From: Jonathan Gray <j...@jsg.id.au>
> 
> It turns out on OMAP4/OMAP5 there is a "Wake-up generator"
> interrupt controller that routes interrupts to the GIC and does power
> management comparable to imx with the i.MX6 General Power Controller
> (GPC).
> 
> / {
> #address-cells = <0x0001>;
> #size-cells = <0x0001>;
> compatible = "ti,omap4-panda-es", "ti,omap4-panda", "ti,omap4460", 
> "ti,omap4430", "ti,omap4";
> interrupt-parent = <0x0001>;
> model = "TI OMAP4 PandaBoard-ES";
> ...
> 
> interrupt-controller@48241000 {
> compatible = "arm,cortex-a9-gic";
> interrupt-controller;
> #interrupt-cells = <0x0003>;
> reg = <0x48241000 0x1000 0x48240100 0x0100>;
> interrupt-parent = <0x0004>;
> linux,phandle = <0x0004>;
> phandle = <0x0004>;
> };
> 
> interrupt-controller@48281000 {
> compatible = "ti,omap4-wugen-mpu";
> interrupt-controller;
> #interrupt-cells = <0x0003>;
> reg = <0x48281000 0x1000>;
> interrupt-parent = <0x0004>;
> linux,phandle = <0x0001>;
> phandle = <0x0001>;
> };
> 
> Reusing the imxgpc code to handle this allows interrupts on ommc(4) with
> the pandaboard to work again and the board can now find it's root disk
> once again.

Go for it.

The wakeup issue is cited in the "Linus ARM rant" thread as a flaw of
the GIC, so we can expect this sort of wakeup interrupt controller to
appear om other "platforms" as well.  This is why we implement the
"parent" establish and disestablish functions.

> Index: omap/files.omap
> ===
> RCS file: /cvs/src/sys/arch/armv7/omap/files.omap,v
> retrieving revision 1.17
> diff -u -p -r1.17 files.omap
> --- omap/files.omap   15 Aug 2016 13:42:49 -  1.17
> +++ omap/files.omap   15 Sep 2016 04:33:56 -
> @@ -42,6 +42,10 @@ device intc
>  attach intc at fdt
>  file arch/armv7/omap/intc.c  intc
>  
> +device omwugen
> +attach omwugen at fdt
> +file arch/armv7/omap/omwugen.c   omwugen
> +
>  device gptimer
>  attach gptimer at omap
>  file arch/armv7/omap/gptimer.c   gptimer
> Index: conf/GENERIC
> ===
> RCS file: /cvs/src/sys/arch/armv7/conf/GENERIC,v
> retrieving revision 1.53
> diff -u -p -r1.53 GENERIC
> --- conf/GENERIC  12 Sep 2016 08:28:44 -  1.53
> +++ conf/GENERIC  15 Sep 2016 04:33:56 -
> @@ -63,6 +63,7 @@ omapid* at omap?
>  
>  # OMAP on-chip devices
>  intc*at fdt? # OMAP3 interrupt controller
> +omwugen* at fdt? # Wake-up generator
>  #edma*   at omap?# OMAP3 dma controller
>  prcm*at omap?# power/clock controller
>  sitaracm*at omap?# sitara control module
> Index: conf/RAMDISK
> ===
> RCS file: /cvs/src/sys/arch/armv7/conf/RAMDISK,v
> retrieving revision 1.48
> diff -u -p -r1.48 RAMDISK
> --- conf/RAMDISK  21 Aug 2016 06:36:23 -  1.48
> +++ conf/RAMDISK  15 Sep 2016 04:33:56 -
> @@ -61,6 +61,7 @@ omapid* at omap?
>  
>  # OMAP on-chip devices
>  intc*at fdt? # OMAP3 interrupt controller
> +omwugen* at fdt? # Wake-up generator
>  #edma*   at omap?# OMAP3 dma controller
>  prcm*at omap?# power/clock controller
>  sitaracm*at omap?# sitara control module
> --- /dev/null Thu Sep 15 14:35:46 2016
> +++ omap/omwugen.cThu Sep 15 14:22:00 2016
> @@ -0,0 +1,63 @@
> +/*   $OpenBSD$   */
> +/*
> + * Copyright (c) 2016 Mark Kettenis
> + *
> + * Permission to use, copy, modify, and distribute this software for any
> + * purpose with or without fee is hereby granted, provided that the above
> + * copyright notice and this permission notice appear in all copies.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
> + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
> + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
> + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL 

We don't need cross-unwinding support

2016-09-19 Thread Mark Kettenis
Saves a bit code and a bit of stack space, which might be important
important in some unwinding scenarios.

ok?


Index: Makefile
===
RCS file: /cvs/src/lib/libcxx/Makefile,v
retrieving revision 1.2
diff -u -p -r1.2 Makefile
--- Makefile19 Sep 2016 11:22:39 -  1.2
+++ Makefile19 Sep 2016 12:04:52 -
@@ -40,7 +40,8 @@ SRCS+=algorithm.cpp\
valarray.cpp
 
 CPPFLAGS+= -DLIBCXXABI -I${HDRDIR} \
-   -DLIBCXX_BUILDING_LIBCXXABI -I${AHDRDIR} -I${UHDRDIR}
+   -DLIBCXX_BUILDING_LIBCXXABI -I${AHDRDIR} -I${UHDRDIR} \
+   -D_LIBUNWIND_IS_NATIVE_ONLY
 CXXFLAGS+= -nostdlib -nostdinc++
 .if empty(CXXFLAGS:M-std=*)
 CXXFLAGS+= -std=c++11



Re: Modernize arm assembly in the kernel

2016-09-21 Thread Mark Kettenis
> Date: Wed, 21 Sep 2016 11:00:49 +0200
> From: Joerg Sonnenberger <jo...@bec.de>
> 
> On Wed, Sep 21, 2016 at 10:10:43AM +0200, Mark Kettenis wrote:
> > 1. In GNU as, .align 0 is equivalent to .align 2, but with clang's
> >internal assembler .align 0 means "no alignment".
> 
> It might be even better to use .balign or .p2align.

Perhaps.  It's annoying how .align is ambiguous and different between
systems.  Don't feel like polishing that turd at this moment though.

> > 2. Using "ldr" to load a constant into a register is strange.  It
> >works with GNU as, but not with clang.
> 
> It should? See llvm/test/MC/ARM/ldr-pseudo.s. For small constants that
> fit into an immediate, the mov version is certainly smaller than going
> via the constant island, but the syntax should be correct.

Heh, I think I know what's going on here.  GNU as defenitely optimizes
the ldr from the constant pool into a mov.  Clang doesn't do this, but
the code looks correct.  But the code in question lives in the sigcode
page, and some time ago Theo added code there to fill the non-code
bits of the sigcode page with an instruction that generates SIGILL.
The code that does this is overwriting the constant pool!  So in the
end, using mov is the right solution.



Re: fec(4) mii_tick

2016-09-21 Thread Mark Kettenis
> Date: Wed, 21 Sep 2016 21:42:36 +1000
> From: Jonathan Gray <j...@jsg.id.au>
> 
> On Wed, Sep 21, 2016 at 01:22:04PM +0200, Mark Kettenis wrote:
> > Here is the promised diff that makes fec(4) call mii_tick() like all
> > our other ethernet drivers that use mii do.
> > 
> > Does this fix your problem Philip?
> 
> Isn't this missing a call to timeout_add_sec() outside of
> fec_tick()?

Right.  Updated diff (for real now).

Index: sys/arch/armv7/imx/if_fec.c
===
RCS file: /cvs/src/sys/arch/armv7/imx/if_fec.c,v
retrieving revision 1.17
diff -u -p -r1.17 if_fec.c
--- sys/arch/armv7/imx/if_fec.c 21 Sep 2016 10:28:47 -  1.17
+++ sys/arch/armv7/imx/if_fec.c 21 Sep 2016 12:16:28 -
@@ -231,6 +231,7 @@ struct fec_softc {
struct fec_buffer   *rx_buffer_base;
int cur_tx;
int cur_rx;
+   struct timeout  sc_tick;
 };
 
 struct fec_softc *fec_sc;
@@ -249,6 +250,7 @@ void fec_iff(struct fec_softc *);
 struct mbuf * fec_newbuf(void);
 int fec_intr(void *);
 void fec_recv(struct fec_softc *);
+void fec_tick(void *);
 int fec_miibus_readreg(struct device *, int, int);
 void fec_miibus_writereg(struct device *, int, int, int);
 void fec_miibus_statchg(struct device *);
@@ -430,6 +432,8 @@ fec_attach(struct device *parent, struct
ether_ifattach(ifp);
splx(s);
 
+   timeout_set(>sc_tick, fec_tick, sc);
+
fec_sc = sc;
return;
 
@@ -672,6 +676,8 @@ fec_init(struct fec_softc *sc)
/* program promiscuous mode and multicast filters */
fec_iff(sc);
 
+   timeout_add_sec(>sc_tick, 1);
+
/* Indicate we are up and running. */
ifp->if_flags |= IFF_RUNNING;
ifq_clr_oactive(>if_snd);
@@ -694,6 +700,8 @@ fec_stop(struct fec_softc *sc)
ifp->if_timer = 0;
ifq_clr_oactive(>if_snd);
 
+   timeout_del(>sc_tick);
+
/* reset the controller */
HSET4(sc, ENET_ECR, ENET_ECR_RESET);
while(HREAD4(sc, ENET_ECR) & ENET_ECR_RESET);
@@ -966,6 +974,19 @@ done:
HWRITE4(sc, ENET_RDAR, ENET_RDAR_RDAR);
 
if_input(ifp, );
+}
+
+void
+fec_tick(void *arg)
+{
+   struct fec_softc *sc = arg;
+   int s;
+
+   s = splnet();
+   mii_tick(>sc_mii);
+   splx(s);
+
+   timeout_add_sec(>sc_tick, 1);
 }
 
 /*



arm assembly syntax

2016-09-18 Thread Mark Kettenis
Somewhere down the line the ARM people made some subtle changes to
their assembly syntax.  The new syntax is called Unified Assembler
Language (UAL), and tis is what clang supports.  But gas defaults to
the old pre-UAL dialect.  The easiest way to make code compile with
both clang and gcc is to tell gas to switch into UAL mode.  The
following diff does this for the one file in libc where it matters.
The resulting binary code is identical.

ok?


Index: lib/libc/arch/arm/string/ffs.S
===
RCS file: /cvs/src/lib/libc/arch/arm/string/ffs.S,v
retrieving revision 1.5
diff -u -p -r1.5 ffs.S
--- lib/libc/arch/arm/string/ffs.S  6 Aug 2016 19:16:09 -   1.5
+++ lib/libc/arch/arm/string/ffs.S  18 Sep 2016 09:53:30 -
@@ -44,6 +44,8 @@
  * 16 Feb 1994.
  */
 
+   .syntax unified
+
 ENTRY(ffs)
/* Standard trick to isolate bottom bit in r0 or 0 if r0 = 0 on entry */
rsb r1, r0, #0
@@ -58,7 +60,7 @@ ENTRY(ffs)
rsbne   r0, r0, r0, lsl #16 /* r0 = X * 0x0450fbaf */
   
/* now lookup in table indexed on top 6 bits of r0 */
-   ldrneb  r0, [ r2, r0, lsr #26 ]
+   ldrbne  r0, [ r2, r0, lsr #26 ]
 
 mov   pc, lr
 END_WEAK(ffs)



fix clang types on arm

2016-09-16 Thread Mark Kettenis
On OpenBSD we use a consistent set of typedefs across platforms for
the types specified by the C standard.  In some cases these deviate
from what the processor-specific ABI says.  The diff below fixes the
ones relevant for arm, pretty much by following NetBSD.

ok?

Oh, and how do we handle upstreaming these kind of diffs?


Index: gnu/llvm/tools/clang/lib/Basic/Targets.cpp
===
RCS file: /cvs/src/gnu/llvm/tools/clang/lib/Basic/Targets.cpp,v
retrieving revision 1.1.1.1
diff -u -p -r1.1.1.1 Targets.cpp
--- gnu/llvm/tools/clang/lib/Basic/Targets.cpp  3 Sep 2016 22:46:57 -   
1.1.1.1
+++ gnu/llvm/tools/clang/lib/Basic/Targets.cpp  16 Sep 2016 18:58:59 -
@@ -4275,8 +4275,10 @@ class ARMTargetInfo : public TargetInfo 
 DoubleAlign = LongLongAlign = LongDoubleAlign = SuitableAlign = 64;
 const llvm::Triple  = getTriple();
 
-// size_t is unsigned long on MachO-derived environments, NetBSD and 
Bitrig.
+// size_t is unsigned long on MachO-derived environments, NetBSD,
+// OpenBSD and Bitrig.
 if (T.isOSBinFormatMachO() || T.getOS() == llvm::Triple::NetBSD ||
+T.getOS() == llvm::Triple::OpenBSD ||
 T.getOS() == llvm::Triple::Bitrig)
   SizeType = UnsignedLong;
 else
@@ -4284,6 +4286,7 @@ class ARMTargetInfo : public TargetInfo 
 
 switch (T.getOS()) {
 case llvm::Triple::NetBSD:
+case llvm::Triple::OpenBSD:
   WCharType = SignedInt;
   break;
 case llvm::Triple::Win32:
@@ -4475,6 +4478,7 @@ public:
 
 switch (getTriple().getOS()) {
 case llvm::Triple::NetBSD:
+case llvm::Triple::OpenBSD:
   PtrDiffType = SignedLong;
   break;
 default:



Build libc++ and libc++abi with -nostdinc++

2016-09-17 Thread Mark Kettenis
Without this, they don't build with clang++ because it tries to use
the installed headers.  Doesn't hurt building with eg++.

ok?


Index: lib/libcxx/Makefile
===
RCS file: /cvs/src/lib/libcxx/Makefile,v
retrieving revision 1.1
diff -u -p -r1.1 Makefile
--- lib/libcxx/Makefile 4 Sep 2016 12:48:33 -   1.1
+++ lib/libcxx/Makefile 17 Sep 2016 22:09:30 -
@@ -41,7 +41,7 @@ SRCS+=algorithm.cpp\
 
 CPPFLAGS+= -DLIBCXXABI -I${HDRDIR} \
-DLIBCXX_BUILDING_LIBCXXABI -I${AHDRDIR} -I${UHDRDIR}
-CXXFLAGS+= -nostdlib
+CXXFLAGS+= -nostdlib -nostdinc++
 .if empty(CXXFLAGS:M-std=*)
 CXXFLAGS+= -std=c++11
 .endif
Index: lib/libcxxabi/Makefile
===
RCS file: /cvs/src/lib/libcxxabi/Makefile,v
retrieving revision 1.1
diff -u -p -r1.1 Makefile
--- lib/libcxxabi/Makefile  4 Sep 2016 12:48:34 -   1.1
+++ lib/libcxxabi/Makefile  17 Sep 2016 22:09:30 -
@@ -39,7 +39,7 @@ SRCS+=abort_message.cpp\
libunwind.cpp
 
 CPPFLAGS+= -I${SHDRDIR} -I${HDRDIR} -I${UHDRDIR}
-CXXFLAGS+= -nostdlib -funwind-tables
+CXXFLAGS+= -nostdlib -nostdinc++ -funwind-tables
 .if empty(CXXFLAGS:M-std=*)
 CXXFLAGS+= -std=c++11
 .endif



Re: We don't need cross-unwinding support

2016-09-19 Thread Mark Kettenis
> Date: Mon, 19 Sep 2016 14:08:49 +0200 (CEST)
> From: Mark Kettenis <mark.kette...@xs4all.nl>
> 
> Saves a bit code and a bit of stack space, which might be important
> important in some unwinding scenarios.
> 
> ok?

Transplanted the diff into the wrong file.  Here is the correct one.

Index: Makefile
===
RCS file: /cvs/src/lib/libcxx/Makefile,v
retrieving revision 1.2
diff -u -p -r1.2 Makefile
--- Makefile19 Sep 2016 11:22:39 -  1.2
+++ Makefile19 Sep 2016 12:04:52 -
@@ -40,7 +40,8 @@ SRCS+=algorithm.cpp\
valarray.cpp
 
 CPPFLAGS+= -DLIBCXXABI -I${HDRDIR} \
-   -DLIBCXX_BUILDING_LIBCXXABI -I${AHDRDIR} -I${UHDRDIR}
+   -DLIBCXX_BUILDING_LIBCXXABI -I${AHDRDIR} -I${UHDRDIR} \
+   -D_LIBUNWIND_IS_NATIVE_ONLY
 CXXFLAGS+= -nostdlib -nostdinc++
 .if empty(CXXFLAGS:M-std=*)
 CXXFLAGS+= -std=c++11



Re: We don't need cross-unwinding support

2016-09-19 Thread Mark Kettenis
> Date: Mon, 19 Sep 2016 16:08:33 +0200 (CEST)
> From: Mark Kettenis <mark.kette...@xs4all.nl>
> 
> > Date: Mon, 19 Sep 2016 14:08:49 +0200 (CEST)
> > From: Mark Kettenis <mark.kette...@xs4all.nl>
> > 
> > Saves a bit code and a bit of stack space, which might be important
> > important in some unwinding scenarios.
> > 
> > ok?
> 
> Transplanted the diff into the wrong file.  Here is the correct one.

Ugh, not my day.

Index: lib/libcxxabi/Makefile
===
RCS file: /cvs/src/lib/libcxxabi/Makefile,v
retrieving revision 1.2
diff -u -p -r1.2 Makefile
--- lib/libcxxabi/Makefile  19 Sep 2016 11:23:16 -  1.2
+++ lib/libcxxabi/Makefile  19 Sep 2016 14:07:28 -
@@ -39,6 +39,7 @@ SRCS+=abort_message.cpp\
libunwind.cpp
 
 CPPFLAGS+= -I${SHDRDIR} -I${HDRDIR} -I${UHDRDIR}
+CPPFLAGS+= -D_LIBUNWIND_IS_NATIVE_ONLY
 CXXFLAGS+= -nostdlib -nostdinc++ -funwind-tables
 .if empty(CXXFLAGS:M-std=*)
 CXXFLAGS+= -std=c++11



Re: timeout_set_proc(9)

2016-09-19 Thread Mark Kettenis
> Date: Mon, 19 Sep 2016 13:47:25 +1000
> From: David Gwynne <da...@gwynne.id.au>
> 
> On Fri, Sep 16, 2016 at 04:58:39PM +0200, Mark Kettenis wrote:
> > > Date: Thu, 15 Sep 2016 16:29:45 +0200
> > > From: Martin Pieuchot <m...@openbsd.org>
> > > 
> > > After discussing with a few people about a new "timed task" API I came
> > > to the conclusion that mixing timeouts and tasks will result in:
> > > 
> > >   - always including a 'struct timeout' in a 'struct task', or the other
> > > the way around
> > > or
> > >   
> > >   - introducing a new data structure, hence API.
> > > 
> > > Since I'd like to keep the change as small as possible when converting
> > > existing timeout_set(9), neither option seem a good fit.  So I decided
> > > to add a new kernel thread, curiously named "softclock", that will
> > > offer his stack to the poor timeout handlers that need one. 
> > > 
> > > With this approach, converting a timeout is just a matter of doing:
> > > 
> > >   s/timeout_set/timeout_set_proc/
> > > 
> > > 
> > > Diff below includes the conversions I need for the "netlock".  I'm
> > > waiting for feedbacks and a better name to document the new function.
> > > 
> > > Comments?
> > 
> > I like how minimal this is.  Would like to see a few more people that
> > are familliar with the timeout code chime in, but it looks mostly
> > correct to me as well.  One question though:
> 
> id rather not grow the timeout (or task for that matter) apis just
> yet. theyre nice and straightforward to read and understand so far.
> 
> for this specific problem can we do a specific fix for it? the diff
> below is equiv to the timeout_set_proc change, but implements it
> by using explicit tasks that are called by the timeouts from a
> common trampoline in the network stack.

But this is much more involved tha mpi@'s change.

So unless somebody shoots a hole into his approach, I'd prefer the
timeout_set_proc() approach.

> Index: net/if.c
> ===
> RCS file: /cvs/src/sys/net/if.c,v
> retrieving revision 1.448
> diff -u -p -r1.448 if.c
> --- net/if.c  13 Sep 2016 08:15:01 -  1.448
> +++ net/if.c  19 Sep 2016 01:51:37 -
> @@ -155,6 +155,8 @@ void  if_watchdog_task(void *);
>  void if_input_process(void *);
>  void if_netisr(void *);
>  
> +void if_nettmo_add(void *);
> +
>  #ifdef DDB
>  void ifa_print_all(void);
>  #endif
> @@ -875,6 +877,21 @@ if_netisr(void *unused)
>  
>   splx(s);
>   KERNEL_UNLOCK();
> +}
> +
> +void
> +if_nettmo_add(void *t)
> +{
> + /* the task is added to systq so it inherits the KERNEL_LOCK */
> + task_add(systq, t);
> +}
> +
> +void
> +if_nettmo_set(struct timeout *tmo, struct task *task,
> +void (*fn)(void *), void *arg)
> +{
> + task_set(task, fn, arg);
> + timeout_set(tmo, if_nettmo_add, task);
>  }
>  
>  void
> Index: net/if_pflow.c
> ===
> RCS file: /cvs/src/sys/net/if_pflow.c,v
> retrieving revision 1.61
> diff -u -p -r1.61 if_pflow.c
> --- net/if_pflow.c29 Apr 2016 08:55:03 -  1.61
> +++ net/if_pflow.c19 Sep 2016 01:51:37 -
> @@ -36,6 +36,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  #include 
>  #include 
>  #include 
> @@ -547,16 +548,24 @@ pflow_init_timeouts(struct pflow_softc *
>   timeout_del(>sc_tmo6);
>   if (timeout_initialized(>sc_tmo_tmpl))
>   timeout_del(>sc_tmo_tmpl);
> - if (!timeout_initialized(>sc_tmo))
> - timeout_set(>sc_tmo, pflow_timeout, sc);
> + if (!timeout_initialized(>sc_tmo)) {
> + if_nettmo_set(>sc_tmo, >sc_task,
> + pflow_timeout, sc);
> + }
>   break;
>   case PFLOW_PROTO_10:
> - if (!timeout_initialized(>sc_tmo_tmpl))
> - timeout_set(>sc_tmo_tmpl, pflow_timeout_tmpl, sc);
> - if (!timeout_initialized(>sc_tmo))
> - timeout_set(>sc_tmo, pflow_timeout, sc);
> - if (!timeout_initialized(>sc_tmo6))
> - timeout_set(>sc_tmo6, pflow_timeout6, sc);
> + if (!timeout_initialized(>sc_tmo_tmpl)) {
> + if_nettmo_set(>sc_tmo_tmpl, >sc_task_tmpl,
> + pflow_timeout_tmpl,

Add support for a few more arm relocations

2016-09-19 Thread Mark Kettenis
>From FreeBSD, still under GPLv2.  I've seen R_ARM_MOVW_ABS_NC in code
generated by clang.

ok?


Index: gnu/usr.bin/binutils-2.17/bfd/bfd-in2.h
===
RCS file: /cvs/src/gnu/usr.bin/binutils-2.17/bfd/bfd-in2.h,v
retrieving revision 1.6
diff -u -p -r1.6 bfd-in2.h
--- gnu/usr.bin/binutils-2.17/bfd/bfd-in2.h 31 May 2016 17:05:03 -  
1.6
+++ gnu/usr.bin/binutils-2.17/bfd/bfd-in2.h 19 Sep 2016 09:17:38 -
@@ -2907,6 +2907,12 @@ pc-relative or some form of GOT-indirect
 /* 31-bit PC relative address.  */
   BFD_RELOC_ARM_PREL31,
 
+/* Low and High halfword relocations for MOVW and MOVT instructions.  */
+  BFD_RELOC_ARM_MOVW,
+  BFD_RELOC_ARM_MOVT,
+  BFD_RELOC_ARM_MOVW_PCREL,
+  BFD_RELOC_ARM_MOVT_PCREL,
+
 /* Relocations for setting up GOTs and PLTs for shared libraries.  */
   BFD_RELOC_ARM_JUMP_SLOT,
   BFD_RELOC_ARM_GLOB_DAT,
Index: gnu/usr.bin/binutils-2.17/bfd/elf32-arm.c
===
RCS file: /cvs/src/gnu/usr.bin/binutils-2.17/bfd/elf32-arm.c,v
retrieving revision 1.2
diff -u -p -r1.2 elf32-arm.c
--- gnu/usr.bin/binutils-2.17/bfd/elf32-arm.c   26 Jun 2015 04:28:53 -  
1.2
+++ gnu/usr.bin/binutils-2.17/bfd/elf32-arm.c   19 Sep 2016 09:17:38 -
@@ -1366,6 +1366,10 @@ static const struct elf32_arm_reloc_map 
 {BFD_RELOC_ARM_TLS_LE32, R_ARM_TLS_LE32},
 {BFD_RELOC_VTABLE_INHERIT,  R_ARM_GNU_VTINHERIT},
 {BFD_RELOC_VTABLE_ENTRY,R_ARM_GNU_VTENTRY},
+{BFD_RELOC_ARM_MOVW,R_ARM_MOVW_ABS_NC},
+{BFD_RELOC_ARM_MOVT,R_ARM_MOVT_ABS},
+{BFD_RELOC_ARM_MOVW_PCREL,  R_ARM_MOVW_PREL_NC},
+{BFD_RELOC_ARM_MOVT_PCREL,  R_ARM_MOVT_PREL},
   };
 
 static reloc_howto_type *
@@ -4080,6 +4084,49 @@ elf32_arm_final_link_relocate (reloc_how
 }
   return bfd_reloc_ok;
 
+case R_ARM_MOVW_ABS_NC:
+case R_ARM_MOVT_ABS:
+case R_ARM_MOVW_PREL_NC:
+case R_ARM_MOVT_PREL:
+/* Until we properly support segment-base-relative addressing then
+   we assume the segment base to be zero, as for the group relocations.
+   Thus R_ARM_MOVW_BREL_NC has the same semantics as R_ARM_MOVW_ABS_NC
+   and R_ARM_MOVT_BREL has the same semantics as R_ARM_MOVT_ABS.  */
+case R_ARM_MOVW_BREL_NC:
+case R_ARM_MOVW_BREL:
+case R_ARM_MOVT_BREL:
+  {
+   bfd_vma insn = bfd_get_32 (input_bfd, hit_data);
+
+   if (globals->use_rel)
+ {
+   addend = ((insn >> 4) & 0xf000) | (insn & 0xfff);
+   signed_addend = (addend ^ 0x8000) - 0x8000;
+ }
+
+   value += signed_addend;
+
+   if (r_type == R_ARM_MOVW_PREL_NC || r_type == R_ARM_MOVT_PREL)
+ value -= (input_section->output_section->vma
+   + input_section->output_offset + rel->r_offset);
+
+   if (r_type == R_ARM_MOVW_BREL && value >= 0x1)
+  return bfd_reloc_overflow;
+
+   if (sym_flags == STT_ARM_TFUNC)
+ value |= 1;
+
+   if (r_type == R_ARM_MOVT_ABS || r_type == R_ARM_MOVT_PREL
+|| r_type == R_ARM_MOVT_BREL)
+ value >>= 16;
+
+   insn &= 0xfff0f000;
+   insn |= value & 0xfff;
+   insn |= (value & 0xf000) << 4;
+   bfd_put_32 (input_bfd, insn, hit_data);
+  }
+  return bfd_reloc_ok;
+
 default:
   return bfd_reloc_notsupported;
 }
@@ -5651,6 +5698,10 @@ elf32_arm_gc_sweep_hook (bfd *  
case R_ARM_JUMP24:
case R_ARM_PREL31:
case R_ARM_THM_CALL:
+   case R_ARM_MOVW_ABS_NC:
+   case R_ARM_MOVT_ABS:
+   case R_ARM_MOVW_PREL_NC:
+   case R_ARM_MOVT_PREL:
  /* Should the interworking branches be here also?  */
 
  if (h != NULL)
@@ -5861,6 +5912,10 @@ elf32_arm_check_relocs (bfd *abfd, struc
  case R_ARM_JUMP24:
  case R_ARM_PREL31:
  case R_ARM_THM_CALL:
+ case R_ARM_MOVW_ABS_NC:
+ case R_ARM_MOVT_ABS:
+ case R_ARM_MOVW_PREL_NC:
+ case R_ARM_MOVT_PREL:
/* Should the interworking branches be listed here?  */
if (h != NULL)
  {
Index: gnu/usr.bin/binutils-2.17/bfd/libbfd.h
===
RCS file: /cvs/src/gnu/usr.bin/binutils-2.17/bfd/libbfd.h,v
retrieving revision 1.5
diff -u -p -r1.5 libbfd.h
--- gnu/usr.bin/binutils-2.17/bfd/libbfd.h  31 May 2016 17:05:03 -  
1.5
+++ gnu/usr.bin/binutils-2.17/bfd/libbfd.h  19 Sep 2016 09:17:38 -
@@ -1209,6 +1209,10 @@ static const char *const bfd_reloc_code_
   "BFD_RELOC_ARM_SBREL32",
   "BFD_RELOC_ARM_TARGET2",
   "BFD_RELOC_ARM_PREL31",
+  "BFD_RELOC_ARM_MOVW",
+  "BFD_RELOC_ARM_MOVT",
+  "BFD_RELOC_ARM_MOVW_PCREL",
+  "BFD_RELOC_ARM_MOVT_PCREL",
   "BFD_RELOC_ARM_JUMP_SLOT",
   "BFD_RELOC_ARM_GLOB_DAT",
   "BFD_RELOC_ARM_GOT32",
Index: gnu/usr.bin/binutils-2.17/bfd/reloc.c

arm libcompiler_rt

2016-09-19 Thread Mark Kettenis
Diff below adds the relevant arm-specific code to the build.  It
leaves out the VFP bits.  Those don't compile with our current
toolchain (gcc/binutils) and I believe they're only necessary for the
hard-float ABI anyway.

ok?


Index: Makefile
===
RCS file: /cvs/src/lib/libcompiler_rt/Makefile,v
retrieving revision 1.1
diff -u -p -r1.1 Makefile
--- Makefile5 Sep 2016 11:38:16 -   1.1
+++ Makefile19 Sep 2016 08:28:57 -
@@ -164,6 +164,53 @@ SRCS+= ${file}.c
 .  endif
 .endfor
 
+.if ${RTARCH} == "arm"
+SRCS+= aeabi_cdcmp.S \
+   aeabi_cdcmpeq_check_nan.c \
+   aeabi_cfcmp.S \
+   aeabi_cfcmpeq_check_nan.c \
+   aeabi_dcmp.S \
+   aeabi_div0.c \
+   aeabi_drsub.c \
+   aeabi_fcmp.S \
+   aeabi_frsub.c \
+   aeabi_idivmod.S \
+   aeabi_ldivmod.S \
+   aeabi_memcmp.S \
+   aeabi_memcpy.S \
+   aeabi_memmove.S \
+   aeabi_memset.S \
+   aeabi_uidivmod.S \
+   aeabi_uldivmod.S \
+   bswapdi2.S \
+   bswapsi2.S \
+   switch16.S \
+   switch32.S \
+   switch8.S \
+   switchu8.S \
+   sync_fetch_and_add_4.S \
+   sync_fetch_and_add_8.S \
+   sync_fetch_and_and_4.S \
+   sync_fetch_and_and_8.S \
+   sync_fetch_and_max_4.S \
+   sync_fetch_and_max_8.S \
+   sync_fetch_and_min_4.S \
+   sync_fetch_and_min_8.S \
+   sync_fetch_and_nand_4.S \
+   sync_fetch_and_nand_8.S \
+   sync_fetch_and_or_4.S \
+   sync_fetch_and_or_8.S \
+   sync_fetch_and_sub_4.S \
+   sync_fetch_and_sub_8.S \
+   sync_fetch_and_umax_4.S \
+   sync_fetch_and_umax_8.S \
+   sync_fetch_and_umin_4.S \
+   sync_fetch_and_umin_8.S \
+   sync_fetch_and_xor_4.S \
+   sync_fetch_and_xor_8.S \
+   sync_synchronize.S
+.endif
+
 .if ${RTARCH} == "ppc"
 SRCS+= divtc3.c \
fixtfdi.c \



dwc2 cleanup diff

2016-09-23 Thread Mark Kettenis
Essentially fixes for clang warnings.  Clang doesn't like the

sc = sc;

statements in dwc2_shutdown(), dwc2_childdet() and dwc2_activate().
Those functions aren't actually used.  This diff moves them inside the
#if 0 that's already there for dwc2_suspend() and dwc2_resume().  But
perhaps I should just remove the code altogether?


Index: dev/usb/dwc2/dwc2.c
===
RCS file: /cvs/src/sys/dev/usb/dwc2/dwc2.c,v
retrieving revision 1.37
diff -u -p -r1.37 dwc2.c
--- dev/usb/dwc2/dwc2.c 15 Sep 2016 02:00:18 -  1.37
+++ dev/usb/dwc2/dwc2.c 23 Sep 2016 11:43:30 -
@@ -1493,6 +1493,7 @@ dwc2_detach(struct dwc2_softc *sc, int f
return rv;
 }
 
+#if 0
 bool
 dwc2_shutdown(struct device *self, int flags)
 {
@@ -1521,7 +1522,6 @@ dwc2_activate(struct device *self, int a
return 0;
 }
 
-#if 0
 bool
 dwc2_resume(struct device *dv, const pmf_qual_t *qual)
 {
Index: dev/usb/dwc2/dwc2var.h
===
RCS file: /cvs/src/sys/dev/usb/dwc2/dwc2var.h,v
retrieving revision 1.16
diff -u -p -r1.16 dwc2var.h
--- dev/usb/dwc2/dwc2var.h  3 Sep 2015 14:22:27 -   1.16
+++ dev/usb/dwc2/dwc2var.h  23 Sep 2016 11:43:30 -
@@ -120,10 +120,10 @@ int   dwc2_dma_config(struct dwc2_softc *
struct dwc2_core_dma_config *);
 intdwc2_intr(void *);
 intdwc2_detach(dwc2_softc_t *, int);
+#if 0
 bool   dwc2_shutdown(struct device *, int);
 void   dwc2_childdet(struct device *, struct device *);
 intdwc2_activate(struct device *, int);
-#if 0
 bool   dwc2_resume(struct device *, const pmf_qual_t *);
 bool   dwc2_suspend(struct device *, const pmf_qual_t *);
 #endif



Some arm cleanups suggested by clang

2016-09-23 Thread Mark Kettenis
Most of these are warnings about static symbols that aren't used.  The
pmap_get_pde_pte() bit fixes:

../../../../arch/arm/arm/pmap7.c:2220:10: warning: comparison of array
  'pm->pm_l2' equal to a null pointer is always false
  [-Wtautological-pointer-compare]
if (pm->pm_l2 == NULL)

ok?


Index: arch/arm/arm/cpu.c
===
RCS file: /cvs/src/sys/arch/arm/arm/cpu.c,v
retrieving revision 1.32
diff -u -p -r1.32 cpu.c
--- arch/arm/arm/cpu.c  14 Aug 2016 11:30:54 -  1.32
+++ arch/arm/arm/cpu.c  23 Sep 2016 11:32:51 -
@@ -103,16 +103,6 @@ static const char * const pxa2x0_steppin
"rev 12",   "rev 13",   "rev 14",   "rev 15"
 };
 
-/* Steppings for PXA255/26x.
- * rev 5: PXA26x B0, rev 6: PXA255 A0
- */
-static const char * const pxa255_steppings[16] = {
-   "rev 0","rev 1","rev 2","step A-0",
-   "rev 4","step B-0", "step A-0", "rev 7",
-   "rev 8","rev 9","rev 10",   "rev 11",
-   "rev 12",   "rev 13",   "rev 14",   "rev 15"
-};
-
 /* Steppings for PXA270 */
 static const char * const pxa27x_steppings[16] = {
"step A-0", "step A-1", "step B-0", "step B-1",
Index: arch/arm/arm/pmap7.c
===
RCS file: /cvs/src/sys/arch/arm/arm/pmap7.c,v
retrieving revision 1.52
diff -u -p -r1.52 pmap7.c
--- arch/arm/arm/pmap7.c15 Sep 2016 02:00:17 -  1.52
+++ arch/arm/arm/pmap7.c23 Sep 2016 11:32:51 -
@@ -446,26 +446,12 @@ pmap_tlb_flushID_SE(pmap_t pm, vaddr_t v
 }
 
 static __inline void
-pmap_tlb_flushD_SE(pmap_t pm, vaddr_t va)
-{
-   if (pmap_is_current(pm))
-   cpu_tlb_flushD_SE(va);
-}
-
-static __inline void
 pmap_tlb_flushID(pmap_t pm)
 {
if (pmap_is_current(pm))
cpu_tlb_flushID();
 }
 
-static __inline void
-pmap_tlb_flushD(pmap_t pm)
-{
-   if (pmap_is_current(pm))
-   cpu_tlb_flushD();
-}
-
 /*
  * Returns a pointer to the L2 bucket associated with the specified pmap
  * and VA, or NULL if no L2 bucket exists for the address.
@@ -2217,11 +2203,7 @@ pmap_get_pde_pte(pmap_t pm, vaddr_t va, 
return (TRUE);
}
 
-   if (pm->pm_l2 == NULL)
-   return (FALSE);
-
l2 = pm->pm_l2[L2_IDX(l1idx)];
-
if (l2 == NULL ||
(ptep = l2->l2_bucket[L2_BUCKET(l1idx)].l2b_kva) == NULL) {
return (FALSE);
Index: arch/arm/cortex/agtimer.c
===
RCS file: /cvs/src/sys/arch/arm/cortex/agtimer.c,v
retrieving revision 1.7
diff -u -p -r1.7 agtimer.c
--- arch/arm/cortex/agtimer.c   10 Aug 2016 06:51:57 -  1.7
+++ arch/arm/cortex/agtimer.c   23 Sep 2016 11:32:51 -
@@ -126,16 +126,6 @@ agtimer_set_ctrl(uint32_t val)
 }
 
 static inline int
-agtimer_get_tval(void)
-{
-   uint32_t val;
-
-   __asm volatile("mrc p15, 0, %0, c14, c2, 0" : "=r" (val));
-
-   return (val);
-}
-
-static inline int
 agtimer_set_tval(uint32_t val)
 {
__asm volatile("mcr p15, 0, %[val], c14, c2, 0" : :



Modernize arm assembly in the kernel

2016-09-21 Thread Mark Kettenis
This fixes two isses.

1. In GNU as, .align 0 is equivalent to .align 2, but with clang's
   internal assembler .align 0 means "no alignment".

2. Using "ldr" to load a constant into a register is strange.  It
   works with GNU as, but not with clang.

No binary change in a kernel compiled with gcc.

ok?


Index: arch/arm/arm/bcopyinout.S
===
RCS file: /cvs/src/sys/arch/arm/arm/bcopyinout.S,v
retrieving revision 1.5
diff -u -p -r1.5 bcopyinout.S
--- arch/arm/arm/bcopyinout.S   25 Apr 2016 04:46:56 -  1.5
+++ arch/arm/arm/bcopyinout.S   21 Sep 2016 08:06:23 -
@@ -46,7 +46,7 @@
 #else
 
.text
-   .align  0
+   .align  2
 
 #ifdef MULTIPROCESSOR
 .Lcpu_info:
Index: arch/arm/arm/bus_space_notimpl.S
===
RCS file: /cvs/src/sys/arch/arm/arm/bus_space_notimpl.S,v
retrieving revision 1.2
diff -u -p -r1.2 bus_space_notimpl.S
--- arch/arm/arm/bus_space_notimpl.S27 May 2007 16:10:39 -  1.2
+++ arch/arm/arm/bus_space_notimpl.S21 Sep 2016 08:06:23 -
@@ -65,7 +65,7 @@ LLABEL(__C(func,_text))   
;   \
.align  0   ;
 
 bs_notimpl_message:
-.asciz  __S(BUS_SPACE) "_%s: args at %p"
+.asciz  __S(BUS_SPACE), "_%s: args at %p"
 
.align  2
 bs_notimpl_panic:
Index: arch/arm/arm/copystr.S
===
RCS file: /cvs/src/sys/arch/arm/arm/copystr.S,v
retrieving revision 1.6
diff -u -p -r1.6 copystr.S
--- arch/arm/arm/copystr.S  25 Apr 2016 04:46:56 -  1.6
+++ arch/arm/arm/copystr.S  21 Sep 2016 08:06:23 -
@@ -45,7 +45,7 @@
 #include 
 
.text
-   .align  0
+   .align  2
 #ifdef MULTIPROCESSOR
 .Lcpu_info:
.word   _C_LABEL(cpu_info)
@@ -210,5 +210,5 @@ ENTRY(copyoutstr)
 
 Lcopystrpcbfaulttext:
.asciz  "No valid PCB during copyinoutstr() addr1=%08x addr2=%08x\n"
-   .align  0
+   .align  2
 #endif
Index: arch/arm/arm/cpufunc_asm.S
===
RCS file: /cvs/src/sys/arch/arm/arm/cpufunc_asm.S,v
retrieving revision 1.4
diff -u -p -r1.4 cpufunc_asm.S
--- arch/arm/arm/cpufunc_asm.S  25 Apr 2016 04:46:56 -  1.4
+++ arch/arm/arm/cpufunc_asm.S  21 Sep 2016 08:06:23 -
@@ -47,7 +47,7 @@
 #include 
 
.text
-   .align  0
+   .align  2
 
 ENTRY(cpufunc_nullop)
mov pc, lr
Index: arch/arm/arm/exception.S
===
RCS file: /cvs/src/sys/arch/arm/arm/exception.S,v
retrieving revision 1.5
diff -u -p -r1.5 exception.S
--- arch/arm/arm/exception.S18 Jan 2015 12:03:11 -  1.5
+++ arch/arm/arm/exception.S21 Sep 2016 08:06:23 -
@@ -52,7 +52,7 @@
 #include "assym.h"
 
.text   
-   .align  0
+   .align  2
 
 AST_LOCALS
 
@@ -120,7 +120,7 @@ abortprefetch:
 
 abortprefetchmsg:
 .asciz  "abortprefetch"
-.align  0
+.align  2
 
 /*
  * data_abort_entry:
@@ -157,7 +157,7 @@ abortdata:
 
 abortdatamsg:
 .asciz  "abortdata"
-.align  0
+.align  2
 
 /*
  * address_exception_entry:
@@ -231,7 +231,7 @@ ENTRY_NP(undefinedinstruction_bounce)
b   _C_LABEL(undefinedinstruction)
 
.data
-   .align  0
+   .align  2
 
 /*
  * Indirection data
Index: arch/arm/arm/irq_dispatch.S
===
RCS file: /cvs/src/sys/arch/arm/arm/irq_dispatch.S,v
retrieving revision 1.11
diff -u -p -r1.11 irq_dispatch.S
--- arch/arm/arm/irq_dispatch.S 25 Apr 2016 04:46:56 -  1.11
+++ arch/arm/arm/irq_dispatch.S 21 Sep 2016 08:06:23 -
@@ -86,7 +86,7 @@
  * which can be used by different platforms.
  */
.text
-   .align  0
+   .align  2
 .Lcpu_info_primary:
.word   _C_LABEL(cpu_info_primary)
 
@@ -129,7 +129,7 @@ ASENTRY_NP(irq_entry)
movspc, lr  /* Exit */
 
.bss
-   .align  0
+   .align  2
 
.global _C_LABEL(astpending)
 _C_LABEL(astpending):
Index: arch/arm/arm/locore.S
===
RCS file: /cvs/src/sys/arch/arm/arm/locore.S,v
retrieving revision 1.10
diff -u -p -r1.10 locore.S
--- arch/arm/arm/locore.S   25 Apr 2016 04:46:56 -  1.10
+++ arch/arm/arm/locore.S   21 Sep 2016 08:06:23 -
@@ -49,7 +49,7 @@
  */
 
.text
-   .align  0
+   .align  2
 
 ENTRY_NP(kernel_text)
 
@@ -98,14 +98,14 @@ ASENTRY_NP(start)
 
 .Lmainreturned:
.asciz  "main() returned"
-   .align  0
+   .align  2
 
.bss
 svcstk:
.space  INIT_ARM_STACK_SIZE
 
.text
-   .align  0
+   .align  2
 
 #ifndef OFW
/* OFW based systems will use OF_boot() */
Index: 

aeabi stuff in libkern

2016-09-22 Thread Mark Kettenis
clang generates these calls using the official aeabi names instead of
the gcc names.  Just add an alias for them.  FreeBSD does something
similar.

ok?


Index: lib/libkern/arch/arm/divsi3.S
===
RCS file: /cvs/src/sys/lib/libkern/arch/arm/divsi3.S,v
retrieving revision 1.3
diff -u -p -r1.3 divsi3.S
--- lib/libkern/arch/arm/divsi3.S   30 Dec 2014 08:12:52 -  1.3
+++ lib/libkern/arch/arm/divsi3.S   22 Sep 2016 15:07:07 -
@@ -385,3 +385,6 @@ L_udivide_l1:
addhs   r3, r3, r2
mov r0, r3
mov pc, lr
+
+STRONG_ALIAS(__aeabi_idiv, __divsi3)
+STRONG_ALIAS(__aeabi_uidiv, __udivsi3)



Two more arm aeabi functions for the kernel

2016-09-22 Thread Mark Kettenis
These functions are necessary to build our kernel with clang.  I
picked these from NetBSD as I didn't quite like the way FreeBSD
implemented them.  I stripped all the unecessary bits from the NetBSD
implementation (which is shared with userland).

Do the file names with the leading underscores bother people?  I could
rename the files ldivmod.S and uldivmod.S.

These seem to be the last two missing symbols.

ok?


Index: lib/libkern/arch/arm/__aeabi_ldivmod.S
===
RCS file: lib/libkern/arch/arm/__aeabi_ldivmod.S
diff -N lib/libkern/arch/arm/__aeabi_ldivmod.S
--- /dev/null   1 Jan 1970 00:00:00 -
+++ lib/libkern/arch/arm/__aeabi_ldivmod.S  22 Sep 2016 20:03:42 -
@@ -0,0 +1,133 @@
+/*-
+ * Copyright (c) 2012 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Matt Thomas of 3am Software Foundry.
+ *
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``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 FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include 
+
+#ifdef __ARMEB__
+#defineALO r1  /* incoming numerator, outgoing quotient */
+#defineAHI r0  /* incoming numerator, outgoing quotient */
+#defineBLO r3  /* incoming denominator, outgoing remainder */
+#defineBHI r2  /* incoming denominator, outgoing remainder */
+#else
+#defineALO r0  /* incoming numerator, outgoing quotient */
+#defineAHI r1  /* incoming numerator, outgoing quotient */
+#defineBLO r2  /* incoming denominator, outgoing remainder */
+#defineBHI r3  /* incoming denominator, outgoing remainder */
+#endif
+
+ENTRY(__aeabi_ldivmod)
+   push{r4-r6, lr}
+#defineNEG r5
+   movsNEG, #0
+
+   cmp BHI, #0
+   bge 2f
+   movsNEG, #1 /* flip quotient sign */
+   bl  .Lnegate_b
+   bcs .Lmaxdenom
+
+2:
+   cmp AHI, #0
+   eorlt   NEG, NEG, #3/* flip quotient sign, flip remainder sign */
+   bllt.Lnegate_a
+
+   /*
+* Arguments are setup, allocate some stack for the remainder
+* and call __qdivrem for the heavy lifting.
+*/
+   sub sp, sp, #16
+   addsr4, sp, #8
+   str r4, [sp]
+   bl  __qdivrem
+   add sp, sp, #8
+
+   /*
+* The quotient is already in the right place and neither value
+* needs its sign flipped.
+*/
+   cmp NEG, #0 /* any signs to flip? */
+   beq .Lnegate_neither
+
+   cmp NEG, #2 /* does remainder need to be negative? */
+   beq .Lnegate_b_only /* 2 means b only */
+   bgt .Lnegate_both   /* 3 means both */
+.Lnegate_a_only:
+   bl  .Lnegate_a  /* 1 means a only */
+.Lnegate_neither:
+   pop {r2-r6, pc} /* grab b from stack */
+.Lnegate_both:
+   bl  .Lnegate_a
+.Lnegate_b_only:
+   pop {r2-r3} /* get remainder */
+   bl  .Lnegate_b  /* negate it */
+   pop {r4-r6, pc}
+
+   .align  0
+.Lnegate_a:
+   negsALO, ALO
+   rsc AHI, AHI, #0
+   mov pc, lr
+
+   .align  0
+.Lnegate_b:
+   negsBLO, BLO
+   rsc BHI, BHI, #0
+   mov pc, lr
+
+   .align  0
+.Lmaxdenom:
+   /*
+* We had a carry so the denominator must have INT64_MIN
+* Also BLO and BHI never changed values so we can use
+* them to see if the numerator has the same value.  We
+* don't have to worry about sign.
+*/
+   cmp BHI, AHI
+   cmpeq   BLO, ALO
+   bne 1f
+
+   /*
+* They were 

dl_unwind_find_exidx prototype

2016-09-20 Thread Mark Kettenis
So my diff that switched libunwind to use dl_unwind_find_exidx() was
incomplete.  I forgot that I had put its prototype in  and
missed that file when generating the diff.  However,  isn't
really the right place to put the prototype.  We have
dl_iterate_phdr() in , and dl_unwind_find_exidx() is
closely realted to that function.  In addition to that FreeBSD has it
there as well.  Well actually, they have ..  So that's
why I include  to get the prototype, which include
 on OpenBSD and NetBSD and  on FreeBSD.

ok?


Index: include/link_elf.h
===
RCS file: /cvs/src/include/link_elf.h,v
retrieving revision 1.6
diff -u -p -r1.6 link_elf.h
--- include/link_elf.h  6 Feb 2006 16:51:50 -   1.6
+++ include/link_elf.h  20 Sep 2016 17:59:37 -
@@ -36,6 +36,7 @@ struct dl_phdr_info {
 __BEGIN_DECLS
 intdl_iterate_phdr (int (*)(struct dl_phdr_info *, size_t, void *),
   void *);
+void   *dl_unwind_find_exidx(const void *, int *);
 __END_DECLS
 
 #endif /* !_LINK_ELF_H */
Index: lib/libunwind/src/AddressSpace.hpp
===
RCS file: /cvs/src/lib/libunwind/src/AddressSpace.hpp,v
retrieving revision 1.4
diff -u -p -r1.4 AddressSpace.hpp
--- lib/libunwind/src/AddressSpace.hpp  18 Sep 2016 11:18:28 -  1.4
+++ lib/libunwind/src/AddressSpace.hpp  20 Sep 2016 17:59:37 -
@@ -37,6 +37,7 @@ namespace libunwind {
 #if _LIBUNWIND_ARM_EHABI
 #if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
 
+#include 
 typedef void *_Unwind_Ptr;
 
 #elif defined(__linux__)



Re: timeout_set_proc(9)

2016-09-16 Thread Mark Kettenis
> Date: Fri, 16 Sep 2016 16:03:50 +0200
> From: Vincent Gross 
> 
> On Thu, 15 Sep 2016 16:29:45 +0200
> Martin Pieuchot  wrote:
> 
> > After discussing with a few people about a new "timed task" API I came
> > to the conclusion that mixing timeouts and tasks will result in:
> > 
> >   - always including a 'struct timeout' in a 'struct task', or the
> > other the way around
> > or
> >   
> >   - introducing a new data structure, hence API.
> > 
> > Since I'd like to keep the change as small as possible when converting
> > existing timeout_set(9), neither option seem a good fit.  So I decided
> > to add a new kernel thread, curiously named "softclock", that will
> > offer his stack to the poor timeout handlers that need one. 
> > 
> > With this approach, converting a timeout is just a matter of doing:
> > 
> > s/timeout_set/timeout_set_proc/
> > 
> > 
> > Diff below includes the conversions I need for the "netlock".  I'm
> > waiting for feedbacks and a better name to document the new function.
> > 
> > Comments?
> 
> Reads OK; I like the simple renaming.
> 
> The "softclock" thread name will be confusing, the timeouts are indeed
> driven by the softclock interrupt, but the tasks have nothing to do
> with softclock. Maybe "timeothread" ?

Naming things is always hard.  The :"thread" in the name is a bit
redundant.  Probably just "timeout" would be fine.  The nice thing
about "sofclock" is that it is nicely symmetric with the "softnet"
thread.  Although that one is a taskq.



Re: timeout_set_proc(9)

2016-09-16 Thread Mark Kettenis
> Date: Thu, 15 Sep 2016 16:29:45 +0200
> From: Martin Pieuchot 
> 
> After discussing with a few people about a new "timed task" API I came
> to the conclusion that mixing timeouts and tasks will result in:
> 
>   - always including a 'struct timeout' in a 'struct task', or the other
> the way around
> or
>   
>   - introducing a new data structure, hence API.
> 
> Since I'd like to keep the change as small as possible when converting
> existing timeout_set(9), neither option seem a good fit.  So I decided
> to add a new kernel thread, curiously named "softclock", that will
> offer his stack to the poor timeout handlers that need one. 
> 
> With this approach, converting a timeout is just a matter of doing:
> 
>   s/timeout_set/timeout_set_proc/
> 
> 
> Diff below includes the conversions I need for the "netlock".  I'm
> waiting for feedbacks and a better name to document the new function.
> 
> Comments?

I like how minimal this is.  Would like to see a few more people that
are familliar with the timeout code chime in, but it looks mostly
correct to me as well.  One question though:

> Index: kern/kern_timeout.c
> ===
> RCS file: /cvs/src/sys/kern/kern_timeout.c,v
> retrieving revision 1.48
> diff -u -p -r1.48 kern_timeout.c
> --- kern/kern_timeout.c   6 Jul 2016 15:53:01 -   1.48
> +++ kern/kern_timeout.c   15 Sep 2016 14:19:10 -
> @@ -27,7 +27,7 @@
>  
>  #include 
>  #include 
> -#include 
> +#include 
>  #include 
>  #include 
>  #include 
> @@ -54,6 +54,7 @@
>  
>  struct circq timeout_wheel[BUCKETS]; /* Queues of timeouts */
>  struct circq timeout_todo;   /* Worklist */
> +struct circq timeout_proc;   /* Due timeouts needing proc. context */
>  
>  #define MASKWHEEL(wheel, time) (((time) >> ((wheel)*WHEELBITS)) & WHEELMASK)
>  
> @@ -127,6 +128,9 @@ struct mutex timeout_mutex = MUTEX_INITI
>  
>  #define CIRCQ_EMPTY(elem) (CIRCQ_FIRST(elem) == (elem))
>  
> +void softclock_thread(void *);
> +void softclock_create_thread(void *);
> +
>  /*
>   * Some of the "math" in here is a bit tricky.
>   *
> @@ -147,11 +151,18 @@ timeout_startup(void)
>   int b;
>  
>   CIRCQ_INIT(_todo);
> + CIRCQ_INIT(_proc);
>   for (b = 0; b < nitems(timeout_wheel); b++)
>   CIRCQ_INIT(_wheel[b]);
>  }
>  
>  void
> +timeout_proc_init(void)
> +{
> + kthread_create_deferred(softclock_create_thread, curcpu());
> +}
> +
> +void
>  timeout_set(struct timeout *new, void (*fn)(void *), void *arg)
>  {
>   new->to_func = fn;
> @@ -159,6 +170,12 @@ timeout_set(struct timeout *new, void (*
>   new->to_flags = TIMEOUT_INITIALIZED;
>  }
>  
> +void
> +timeout_set_proc(struct timeout *new, void (*fn)(void *), void *arg)
> +{
> + timeout_set(new, fn, arg);
> + new->to_flags |= TIMEOUT_NEEDPROCCTX;
> +}
>  
>  int
>  timeout_add(struct timeout *new, int to_ticks)
> @@ -334,38 +351,84 @@ timeout_hardclock_update(void)
>  }
>  
>  void
> +timeout_run(struct timeout *to)
> +{
> + void (*fn)(void *);
> + void *arg;
> +
> + MUTEX_ASSERT_LOCKED(_mutex);
> +
> + to->to_flags &= ~TIMEOUT_ONQUEUE;
> + to->to_flags |= TIMEOUT_TRIGGERED;
> +
> + fn = to->to_func;
> + arg = to->to_arg;
> +
> + mtx_leave(_mutex);
> + fn(arg);
> + mtx_enter(_mutex);
> +}
> +
> +void
>  softclock(void *arg)
>  {
>   int delta;
>   struct circq *bucket;
>   struct timeout *to;
> - void (*fn)(void *);
>  
>   mtx_enter(_mutex);
>   while (!CIRCQ_EMPTY(_todo)) {
>   to = timeout_from_circq(CIRCQ_FIRST(_todo));
>   CIRCQ_REMOVE(>to_list);
>  
> - /* If due run it, otherwise insert it into the right bucket. */
> + /*
> +  * If due run it or defer execution to the thread,
> +  * otherwise insert it into the right bucket.
> +  */
>   delta = to->to_time - ticks;
>   if (delta > 0) {
>   bucket = (delta, to->to_time);
>   CIRCQ_INSERT(>to_list, bucket);
> + } else if (to->to_flags & TIMEOUT_NEEDPROCCTX) {
> + CIRCQ_INSERT(>to_list, _proc);
> + wakeup(_proc);
>   } else {
>  #ifdef DEBUG
>   if (delta < 0)
>   printf("timeout delayed %d\n", delta);
>  #endif
> - to->to_flags &= ~TIMEOUT_ONQUEUE;
> - to->to_flags |= TIMEOUT_TRIGGERED;
> + timeout_run(to);
> + }
> + }
> + mtx_leave(_mutex);
> +}
>  
> - fn = to->to_func;
> - arg = to->to_arg;
> +void
> +softclock_create_thread(void *xci)
> +{
> + if (kthread_create(softclock_thread, xci, NULL, "softclock"))
> + panic("fork softclock");
> +}
>  
> - mtx_leave(_mutex);
> -  

Re: sys/systm.h: drop read_symtab_from_file() proto

2016-09-17 Thread Mark Kettenis
> Date: Sat, 17 Sep 2016 13:05:01 +0200
> From: Jasper Lievisse Adriaanse 
> 
> This seems to be a leftover from when the actual function itself was removed
> at some point?

ok kettenis@

> Index: systm.h
> ===
> RCS file: /cvs/src/sys/sys/systm.h,v
> retrieving revision 1.117
> diff -u -p -r1.117 systm.h
> --- systm.h   13 Sep 2016 08:32:44 -  1.117
> +++ systm.h   17 Sep 2016 11:04:10 -
> @@ -308,7 +308,6 @@ extern int (*mountroot)(void);
>  #if defined(DDB) || defined(KGDB)
>  /* debugger entry points */
>  void Debugger(void); /* in DDB only */
> -int  read_symtab_from_file(struct proc *,struct vnode *,const char *);
>  #endif
>  
>  #ifdef BOOT_CONFIG
> 
> -- 
> jasper
> 
> 



Re: arm exidx functions

2016-09-17 Thread Mark Kettenis
> Date: Sat, 17 Sep 2016 09:38:46 -0700
> From: Philip Guenther <guent...@gmail.com>
> 
> On Sat, 17 Sep 2016, Mark Kettenis wrote:
> > Note that libunwind uses __gnu_Unwind_Find_exidx on Linux, so we could
> > follow Linux here and drop the dl_unwind_find_exidx alias.  But my
> > personal preference is to follow the other BSDs here.
> 
> The downside of the name used by the other BSDs is that it's in the 
> application namespace, of course.  

Yup.  Hence the weak attribute.

> > --- dlfcn/Makefile.inc  7 May 2016 19:05:22 -   1.5
> > +++ dlfcn/Makefile.inc  17 Sep 2016 16:04:32 -
> > @@ -5,3 +5,7 @@
> >  .include 
> >  
> >  SRCS+= dlfcn_stubs.c init.c tib.c
> > +
> > +.if ${MACHINE_ARCH} == "arm"
> > +SRCS+= exidx.c
> > +.endif
> 
> Instead of a conditional in the Makefile, can't this all go under 
> arch/arm?

It could.  Not sure where exectly I should put it though.  In a new
dlfcn subdirectory under arch/arm?



clang makefiles for arm

2016-09-16 Thread Mark Kettenis
I'm working on arm support for the in-tree llvm.  I've got it working
well enough to build "Hello, World", but I still have some exception
handling issues.

As a first step, this adds the build infrastructure.

ok?


Index: include/llvm/ARM/Makefile
===
RCS file: include/llvm/ARM/Makefile
diff -N include/llvm/ARM/Makefile
--- /dev/null   1 Jan 1970 00:00:00 -
+++ include/llvm/ARM/Makefile   16 Sep 2016 18:18:50 -
@@ -0,0 +1,85 @@
+# $OpenBSD: Makefile,v 1.1 2016/09/05 10:56:48 pascal Exp $
+
+.include 
+
+LLVM_SRCS= ${.CURDIR}/../../../../../llvm
+
+HDRS=  ARMGenAsmMatcher.inc ARMGenAsmWriter.inc \
+   ARMGenCallingConv.inc ARMGenDAGISel.inc ARMGenDisassemblerTables.inc \
+   ARMGenFastISel.inc ARMGenInstrInfo.inc ARMGenRegisterInfo.inc \
+   ARMGenSubtargetInfo.inc \
+   ARMGenMCCodeEmitter.inc ARMGenMCPseudoLowering.inc \
+   ARMGenDisassemblerTables.inc
+
+all: ${HDRS}
+
+install:
+   # Nothing here so far ...
+
+depend:
+   # Nothing here so far ...
+
+clean:
+   rm -f ${HDRS}
+
+ARMGenRegisterInfo.inc: ${LLVM_SRCS}/lib/Target/ARM/ARM.td
+   ${.OBJDIR}/../../../llvm-tblgen/llvm-tblgen -gen-register-info \
+   -I${LLVM_SRCS}/include -I${LLVM_SRCS}/lib/Target/ARM \
+   -o ${.TARGET} ${.ALLSRC}
+
+ARMGenDisassemblerTables.inc: ${LLVM_SRCS}/lib/Target/ARM/ARM.td
+   ${.OBJDIR}/../../../llvm-tblgen/llvm-tblgen -gen-disassembler \
+   -I${LLVM_SRCS}/include -I${LLVM_SRCS}/lib/Target/ARM \
+   -o ${.TARGET} ${.ALLSRC}
+
+ARMGenInstrInfo.inc: ${LLVM_SRCS}/lib/Target/ARM/ARM.td
+   ${.OBJDIR}/../../../llvm-tblgen/llvm-tblgen -gen-instr-info \
+   -I${LLVM_SRCS}/include -I${LLVM_SRCS}/lib/Target/ARM \
+   -o ${.TARGET} ${.ALLSRC}
+
+ARMGenAsmWriter.inc: ${LLVM_SRCS}/lib/Target/ARM/ARM.td
+   ${.OBJDIR}/../../../llvm-tblgen/llvm-tblgen -gen-asm-writer \
+   -I${LLVM_SRCS}/include -I${LLVM_SRCS}/lib/Target/ARM \
+   -o ${.TARGET} ${.ALLSRC}
+
+ARMGenAsmMatcher.inc: ${LLVM_SRCS}/lib/Target/ARM/ARM.td
+   ${.OBJDIR}/../../../llvm-tblgen/llvm-tblgen -gen-asm-matcher \
+   -I${LLVM_SRCS}/include -I${LLVM_SRCS}/lib/Target/ARM \
+   -o ${.TARGET} ${.ALLSRC}
+
+ARMGenDAGISel.inc: ${LLVM_SRCS}/lib/Target/ARM/ARM.td
+   ${.OBJDIR}/../../../llvm-tblgen/llvm-tblgen -gen-dag-isel \
+   -I${LLVM_SRCS}/include -I${LLVM_SRCS}/lib/Target/ARM \
+   -o ${.TARGET} ${.ALLSRC}
+
+ARMGenFastISel.inc: ${LLVM_SRCS}/lib/Target/ARM/ARM.td
+   ${.OBJDIR}/../../../llvm-tblgen/llvm-tblgen -gen-fast-isel \
+   -I${LLVM_SRCS}/include -I${LLVM_SRCS}/lib/Target/ARM \
+   -o ${.TARGET} ${.ALLSRC}
+
+ARMGenCallingConv.inc: ${LLVM_SRCS}/lib/Target/ARM/ARM.td
+   ${.OBJDIR}/../../../llvm-tblgen/llvm-tblgen -gen-callingconv \
+   -I${LLVM_SRCS}/include -I${LLVM_SRCS}/lib/Target/ARM \
+   -o ${.TARGET} ${.ALLSRC}
+
+ARMGenSubtargetInfo.inc: ${LLVM_SRCS}/lib/Target/ARM/ARM.td
+   ${.OBJDIR}/../../../llvm-tblgen/llvm-tblgen -gen-subtarget \
+   -I${LLVM_SRCS}/include -I${LLVM_SRCS}/lib/Target/ARM \
+   -o ${.TARGET} ${.ALLSRC}
+
+ARMGenMCCodeEmitter.inc: ${LLVM_SRCS}/lib/Target/ARM/ARM.td
+   ${.OBJDIR}/../../../llvm-tblgen/llvm-tblgen -gen-emitter \
+   -I${LLVM_SRCS}/include -I${LLVM_SRCS}/lib/Target/ARM \
+   -o ${.TARGET} ${.ALLSRC}
+
+ARMGenMCPseudoLowering.inc: ${LLVM_SRCS}/lib/Target/ARM/ARM.td
+   ${.OBJDIR}/../../../llvm-tblgen/llvm-tblgen -gen-pseudo-lowering \
+   -I${LLVM_SRCS}/include -I${LLVM_SRCS}/lib/Target/ARM \
+   -o ${.TARGET} ${.ALLSRC}
+
+ARMGenDisassemblerTables.inc: ${LLVM_SRCS}/lib/Target/ARM/ARM.td
+   ${.OBJDIR}/../../../llvm-tblgen/llvm-tblgen -gen-disassembler \
+   -I${LLVM_SRCS}/include -I${LLVM_SRCS}/lib/Target/ARM \
+   -o ${.TARGET} ${.ALLSRC}
+
+.include 
Index: libLLVMARMAsmParser/Makefile
===
RCS file: libLLVMARMAsmParser/Makefile
diff -N libLLVMARMAsmParser/Makefile
--- /dev/null   1 Jan 1970 00:00:00 -
+++ libLLVMARMAsmParser/Makefile16 Sep 2016 18:18:50 -
@@ -0,0 +1,20 @@
+# $OpenBSD: Makefile,v 1.1 2016/09/05 10:56:50 pascal Exp $
+
+LIB=   LLVMARMAsmParser
+NOPIC=
+NOPROFILE=
+
+CPPFLAGS+= -I${.OBJDIR}/../include/llvm/ARM -I${LLVM_SRCS}/lib/Target/ARM
+
+.include 
+SRCS=  ARMAsmParser.cpp
+
+.PATH: ${.CURDIR}/../../../llvm/lib/Target/ARM/AsmParser
+
+depend:
+   # Nothing here so far ...
+
+install:
+   # Nothing here so far ...
+
+.include 
Index: libLLVMARMAsmPrinter/Makefile
===
RCS file: libLLVMARMAsmPrinter/Makefile
diff -N libLLVMARMAsmPrinter/Makefile
--- /dev/null   1 Jan 1970 00:00:00 -
+++ 

Re: ld.so initarray support

2016-08-18 Thread Mark Kettenis
> Date: Wed, 17 Aug 2016 12:50:54 -0700
> From: Philip Guenther <guent...@gmail.com>
> 
> On Wed, 17 Aug 2016, Mark Kettenis wrote:
> ...
> > Functions listed by DT_PREINIT_ARRAY get run immediately after ld.so has 
> > finished loading and relocating all shared objects. This happens only 
> > for the main executable.
> 
> The _dl_call_init() invocation in dlopen() needs to change too, or 
> dlopen() will call preinit functions in the requested object, no?

Hmm, yes.  Our linker doesn't actually allow you to create a
DT_PREINIT_ARRAY in something that isn't an executable, but the
standard is quite explicit:

  DT_PREINIT_ARRAY

This element holds the address of the array of pointers to
pre-initialization functions, discussed in ``Initialization and
Termination Functions'' below. The DT_PREINIT_ARRAY table is
processed only in an executable file; it is ignored if contained
in a shared object.

I'll fix that.

> > There is a functional change here.  Our current ld.so doesn't run 
> > DT_INIT and DT_FINI for the main executable.  The ELF standard is a bit 
> > ambiguous about this, but Linux does run tose for the main executable.  
> > And Solaris allegedly does as well.  So my diff changes that.
> 
> ld.so doesn't run them because __start() in csu does!  Note that csu needs 
> to run them for static executables, and we use the same crt0.o for both 
> static and dynamic executables.  I think you're double executing them with 
> this.

We're not double executing because we don't create a DT_INIT entry for
them.

> (There are _some_ regress tests for this, but we'll want to add more for 
> the {init,fini,preinit}array additions.)

Yeah, I need to convert my testing code into a proper regress test.



Re: Enable FIFO Synopsis DesignWare APB UART

2016-08-18 Thread Mark Kettenis
> Date: Thu, 18 Aug 2016 11:41:52 +0200
> From: Marcus Glocker <mar...@nazgul.ch>
> 
> On Wed, Aug 17, 2016 at 04:05:05PM +0200, Mark Kettenis wrote:
> 
> > > Date: Wed, 17 Aug 2016 15:36:21 +0200
> > > From: Marcus Glocker <mar...@nazgul.ch>
> > > 
> > > Enables FIFO for Synopsis DesignWare APB UART.
> > > 
> > > ok?
> > 
> > Apparently the FIFO is optional.  There is a register that tells you
> > whether it is enabled or not.  Not sure we'll ever encounter an
> > implementation that has that option turned off.  But we probably
> > should check to be sure.
> 
> Ok.  This updated diff tries to find out about FIFO support by reading
> the CPR registers FIFO_MODE field.  If it contains zero, no FIFO
> support, otherwise it conains the supported FIFO depth.
> 
> Unfortunately on my allwinner,sun5i-r8 it returns zero which suprises
> me a bit.  Therefore it would be interessting if it could be tested on
> other sunxi boards as well to see whether it returns non-zero there and
> hence you should find a com-line showing the FIFO size.

Same on allwinner,sun8i-a20.  The data sheet says there is a 64-byte
FIFO, but they have conveniently disabled the registers that tell you
that!  Not sure to what extent we should trust the data sheet though.
This is cheap Chinese hardware in the end.  Probably best to leave
things as they are right now.  Unless you move large volumes of data,
the FIFO isn't terribly important I'd say.

> Index: com_fdt.c
> ===
> RCS file: /cvs/src/sys/arch/armv7/dev/com_fdt.c,v
> retrieving revision 1.6
> diff -u -p -r1.6 com_fdt.c
> --- com_fdt.c 17 Aug 2016 13:44:48 -  1.6
> +++ com_fdt.c 18 Aug 2016 09:36:05 -
> @@ -38,6 +38,8 @@
>  #include 
>  
>  #define com_usr 31   /* Synopsys DesignWare UART */
> +#define com_cpr 61   /* Component Parameter Register */
> +#define CPR_MASK_FIFO(val) ((val >> 16) & 0x00ff)/* CPR FIFO_MODE */
>  
>  int  com_fdt_match(struct device *, void *, void *);
>  void com_fdt_attach(struct device *, struct device *, void *);
> @@ -98,6 +100,7 @@ com_fdt_attach(struct device *parent, st
>   struct fdt_attach_args *faa = aux;
>   int (*intr)(void *) = comintr;
>   int node;
> + uint32_t reg;
>  
>   if (faa->fa_nreg < 1)
>   return;
> @@ -115,11 +118,6 @@ com_fdt_attach(struct device *parent, st
>   sc->sc.sc_frequency = 4800;
>   sc->sc.sc_uarttype = COM_UART_TI16750;
>  
> - if (OF_is_compatible(faa->fa_node, "snps,dw-apb-uart")) {
> - sc->sc.sc_uarttype = COM_UART_16550;
> - intr = com_fdt_intr_designware;
> - }
> -
>   if ((node = OF_finddevice("/")) != 0 &&
>   (OF_is_compatible(node, "allwinner,sun4i-a10") ||
>   OF_is_compatible(node, "allwinner,sun5i-a10s") ||
> @@ -136,6 +134,15 @@ com_fdt_attach(struct device *parent, st
>   faa->fa_reg[0].size, 0, >sc.sc_ioh)) {
>   printf("%s: bus_space_map failed\n", __func__);
>   return;
> + }
> +
> + if (OF_is_compatible(faa->fa_node, "snps,dw-apb-uart")) {
> + reg = bus_space_read_4(sc->sc.sc_iot, sc->sc.sc_ioh, com_cpr);
> + if (CPR_MASK_FIFO(reg) > 0)
> + sc->sc.sc_uarttype = COM_UART_16550A;
> + else
> + sc->sc.sc_uarttype = COM_UART_16550;
> + intr = com_fdt_intr_designware;
>   }
>  
>   pinctrl_byname(faa->fa_node, "default");
> 



Use Access Flag to do page reference emulation on armv7

2016-08-18 Thread Mark Kettenis
Currently we mark page table entries as invalid to do reference
emulation.  This is a bit complicated as the XN bit for "small"
(normal 4K) pages has been stuffed into the two-bit type field.
That's why all those

/* XXX use of L2_V7_S_XN */

comments were in the code for.  But ARMv7 defines a proper Access Flag
bit.  The idea is that if you want to track page references, you clear
the bit.  At that point accessing the page will fault.  When that
happens, we update the referenced flag and set the Access Flag in the
page table to prevent further faults.

The diff below implements that.  It also rationalizes the use of the
page table entry type bits and recognizes that AP[2] is now a bit that
indicates whether a page is write-protected and that AP[1] is now a
bit that indicates that a page is accessible from userland.

Makes life simpler, and paves the way for supporting the XN bit, which
will be addressed in the next diff.

ok?


Index: arch/arm/arm/fault.c
===
RCS file: /cvs/src/sys/arch/arm/arm/fault.c,v
retrieving revision 1.20
diff -u -p -r1.20 fault.c
--- arch/arm/arm/fault.c27 Feb 2016 13:08:06 -  1.20
+++ arch/arm/arm/fault.c18 Aug 2016 19:25:28 -
@@ -154,10 +154,10 @@ static const struct data_abort data_abor
{dab_fatal, "V7 fault 0"},
{dab_align, "Alignment Fault 1"},
{dab_fatal, "Debug Event"},
-   {dab_fatal, "Access Flag Fault (S)"},
+   {NULL,  "Access Flag Fault (S)"},
{dab_buserr,"External Linefetch Abort (S)"},
{NULL,  "Translation Fault (S)"},
-   {dab_fatal, "Access Flag Fault (P)"},
+   {NULL,  "Access Flag Fault (P)"},
{NULL,  "Translation Fault (P)"},
{dab_buserr,"External Non-Linefetch Abort (S)"},
{NULL,  "Domain Fault (S)"},
Index: arch/arm/arm/pmap7.c
===
RCS file: /cvs/src/sys/arch/arm/arm/pmap7.c,v
retrieving revision 1.39
diff -u -p -r1.39 pmap7.c
--- arch/arm/arm/pmap7.c18 Aug 2016 09:28:22 -  1.39
+++ arch/arm/arm/pmap7.c18 Aug 2016 19:25:28 -
@@ -921,27 +921,24 @@ pmap_clearbit(struct vm_page *pg, u_int 
pv, pv->pv_pmap, pv->pv_va, oflags));
 
if (maskbits & (PVF_WRITE|PVF_MOD)) {
-   /* make the pte read only */
-   npte = (npte & ~L2_S_PROT_MASK) |
-   L2_S_PROT(pm == pmap_kernel() ? PTE_KERNEL : 
PTE_USER,
- npte & L2_V7_S_XN ? PROT_READ : PROT_READ | 
PROT_EXEC);
+   /* Disable write access. */
+   npte |= L2_V7_AP(0x4);
}
 
if (maskbits & PVF_REF) {
/*
-* Make the PTE invalid so that we will take a
-* page fault the next time the mapping is
-* referenced.
+* Clear the Access Flag such that we will
+* take a page fault the next time the mapping
+* is referenced.
 */
-   npte = (npte & ~L2_TYPE_MASK) | L2_TYPE_INV |
-   (npte & L2_V7_S_XN);
+   npte &= ~L2_V7_AF;
}
 
if (npte != opte) {
*ptep = npte;
PTE_SYNC(ptep);
/* Flush the TLB entry if a current pmap. */
-   if (l2pte_valid(opte))
+   if (opte & L2_V7_AF)
pmap_tlb_flushID_SE(pm, pv->pv_va);
}
 
@@ -997,7 +994,7 @@ pmap_page_remove(struct vm_page *pg)
struct l2_bucket *l2b;
struct pv_entry *pv, *npv;
pmap_t pm, curpm;
-   pt_entry_t *ptep;
+   pt_entry_t *ptep, opte;
boolean_t flush;
 
NPDEBUG(PDB_FOLLOW,
@@ -1020,9 +1017,10 @@ pmap_page_remove(struct vm_page *pg)
KDASSERT(l2b != NULL);
 
ptep = >l2b_kva[l2pte_index(pv->pv_va)];
-   if (*ptep != 0) {
+   opte = *ptep;
+   if (opte != L2_TYPE_INV) {
/* inline pmap_is_current(pm) */
-   if (l2pte_valid(*ptep) &&
+   if ((opte & L2_V7_AF) &&
(pm == curpm || pm == pmap_kernel())) {
if (PV_BEEN_EXECD(pv->pv_flags))
cpu_icache_sync_range(pv->pv_va, 
PAGE_SIZE);
@@ -1136,9 +1134,9 @@ pmap_enter(pmap_t pm, vaddr_t va, paddr_
}
ptep = >l2b_kva[l2pte_index(va)];
opte = *ptep;
-   npte = pa | L2_V7_AF;
+   npte = L2_S_PROTO | pa;
 
-   if (opte != 0) {/* not l2pte_valid!!! MIOD */
+   

Re: ld.so: remove unused syscall stubs

2016-08-28 Thread Mark Kettenis
> Date: Sat, 27 Aug 2016 21:14:20 -0700
> From: Philip Guenther 
> 
> _dl_gettimeofday() was used by the prebind code, which was recently 
> removed.
> 
> _dl_lstat() was only used by _dl_realpath(), which no longer needs it.
> 
> ok?

ok kettenis@

> Index: alpha/ldasm.S
> ===
> RCS file: /cvs/src/libexec/ld.so/alpha/ldasm.S,v
> retrieving revision 1.36
> diff -u -p -r1.36 ldasm.S
> --- alpha/ldasm.S 7 Aug 2016 03:05:23 -   1.36
> +++ alpha/ldasm.S 28 Aug 2016 04:12:17 -
> @@ -316,10 +316,8 @@ DL_SYSCALL(getdents)
>  DL_SYSCALL(getentropy)
>  DL_SYSCALL(sendsyslog)
>  DL_SYSCALL(pledge)
> -DL_SYSCALL(gettimeofday)
>  DL_SYSCALL_NOERR(issetugid)
>  DL_SYSCALL_NOERR(getthrid)
> -DL_SYSCALL(lstat)
>  DL_SYSCALL(mprotect)
>  DL_SYSCALL(munmap)
>  DL_SYSCALL(open)
> Index: alpha/syscall.h
> ===
> RCS file: /cvs/src/libexec/ld.so/alpha/syscall.h,v
> retrieving revision 1.34
> diff -u -p -r1.34 syscall.h
> --- alpha/syscall.h   4 Jul 2016 21:15:06 -   1.34
> +++ alpha/syscall.h   28 Aug 2016 04:12:17 -
> @@ -51,10 +51,8 @@ int_dl_fstat(int, struct stat *);
>  ssize_t  _dl_getdents(int, char *, size_t);
>  long _dl__syscall(quad_t, ...);
>  int  _dl_sysctl(const int *, u_int, void *, size_t *, void *, size_t);
> -int  _dl_gettimeofday(struct timeval *, struct timezone *);
>  ssize_t  _dl_readlink(const char *, char *, size_t);
>  int  _dl_pledge(const char *, const char **);
> -int  _dl_lstat(const char *, struct stat *);
>  int  _dl_getcwd(char *, size_t);
>  int  _dl_utrace(const char *, const void *, size_t);
>  int  _dl_getentropy(char *, size_t);
> Index: amd64/ldasm.S
> ===
> RCS file: /cvs/src/libexec/ld.so/amd64/ldasm.S,v
> retrieving revision 1.24
> diff -u -p -r1.24 ldasm.S
> --- amd64/ldasm.S 7 May 2016 19:05:23 -   1.24
> +++ amd64/ldasm.S 28 Aug 2016 04:12:17 -
> @@ -91,10 +91,8 @@ DL_SYSCALL(getthrid)
>  DL_SYSCALL(getdents)
>  DL_SYSCALL(mprotect)
>  DL_SYSCALL(munmap)
> -DL_SYSCALL(gettimeofday)
>  DL_SYSCALL(exit)
>  DL_SYSCALL(readlink)
> -DL_SYSCALL(lstat)
>  DL_SYSCALL(utrace)
>  DL_SYSCALL(getentropy)
>  DL_SYSCALL(sendsyslog)
> Index: amd64/syscall.h
> ===
> RCS file: /cvs/src/libexec/ld.so/amd64/syscall.h,v
> retrieving revision 1.22
> diff -u -p -r1.22 syscall.h
> --- amd64/syscall.h   4 Jul 2016 21:15:06 -   1.22
> +++ amd64/syscall.h   28 Aug 2016 04:12:18 -
> @@ -51,10 +51,8 @@ ssize_t_dl_read(int, const char *, size
>  int  _dl_fstat(int, struct stat *);
>  ssize_t  _dl_getdents(int, char *, size_t);
>  int  _dl_sysctl(const int *, u_int, void *, size_t *, void *, size_t);
> -int  _dl_gettimeofday(struct timeval *, struct timezone *);
>  ssize_t  _dl_readlink(const char *, char *, size_t);
>  int  _dl_pledge(const char *, const char **);
> -int  _dl_lstat(const char *, struct stat *);
>  int  _dl_getcwd(char *, size_t);
>  int  _dl_utrace(const char *, const void *, size_t);
>  int  _dl_getentropy(char *, size_t);
> Index: arm/ldasm.S
> ===
> RCS file: /cvs/src/libexec/ld.so/arm/ldasm.S,v
> retrieving revision 1.23
> diff -u -p -r1.23 ldasm.S
> --- arm/ldasm.S   9 Aug 2016 03:58:35 -   1.23
> +++ arm/ldasm.S   28 Aug 2016 04:12:18 -
> @@ -126,9 +126,7 @@ DL_SYSCALL(open)
>  DL_SYSCALL(read)
>  DL_SYSCALL(write)
>  DL_SYSCALL(fstat)
> -DL_SYSCALL(gettimeofday)
>  DL_SYSCALL(readlink)
> -DL_SYSCALL(lstat)
>  DL_SYSCALL(utrace)
>  DL_SYSCALL(getentropy)
>  DL_SYSCALL(sendsyslog)
> Index: arm/syscall.h
> ===
> RCS file: /cvs/src/libexec/ld.so/arm/syscall.h,v
> retrieving revision 1.22
> diff -u -p -r1.22 syscall.h
> --- arm/syscall.h 4 Jul 2016 21:15:06 -   1.22
> +++ arm/syscall.h 28 Aug 2016 04:12:18 -
> @@ -51,10 +51,8 @@ ssize_t_dl_read(int, const char *, size
>  int  _dl_fstat(int, struct stat *);
>  ssize_t  _dl_getdents(int, char *, size_t);
>  int  _dl_sysctl(const int *, u_int, void *, size_t *, void *, size_t);
> -int  _dl_gettimeofday(struct timeval *, struct timezone *);
>  ssize_t  _dl_readlink(const char *, char *, size_t);
>  int  _dl_pledge(const char *, const char **);
> -int  _dl_lstat(const char *, struct stat *);
>  int  _dl_getcwd(char *, size_t);
>  int  _dl_utrace(const char *, const void *, size_t);
>  int  _dl_getentropy(char *, size_t);
> Index: hppa/ldasm.S
> ===
> RCS file: /cvs/src/libexec/ld.so/hppa/ldasm.S,v
> retrieving revision 1.21
> diff -u -p -r1.21 ldasm.S
> --- hppa/ldasm.S  7 May 2016 19:05:23 -   1.21
> +++ hppa/ldasm.S  28 Aug 2016 

Add support for the PXN bit on armv7

2016-08-26 Thread Mark Kettenis
The PXN (Privileged eXecute Never) bit can be set on level 1 page
table entries to prevent execution of the pages covered by that page
table entry from PL1 and above.  So by setting this bit on the level 1
page table entries that cover the user space part of the address
space, we can prevent the kernel from executing those pages.  The
result is comparable to SMEP on x86.

This diff uses the fact that all level 1 entries for userland will be
created by pmap_enter(), whereas entries for the kernel are created by
pmap_growkernel().

ok?


Index: arch/arm/arm/pmap7.c
===
RCS file: /cvs/src/sys/arch/arm/arm/pmap7.c,v
retrieving revision 1.49
diff -u -p -r1.49 pmap7.c
--- arch/arm/arm/pmap7.c26 Aug 2016 16:02:33 -  1.49
+++ arch/arm/arm/pmap7.c26 Aug 2016 19:24:39 -
@@ -303,6 +303,11 @@ struct l1_ttable {
 #defineL1_IDX(va)  (((vaddr_t)(va)) >> L1_S_SHIFT)
 
 /*
+ * Set if the PXN bit is supported.
+ */
+pd_entry_t l1_c_pxn;
+
+/*
  * A list of all L1 tables
  */
 TAILQ_HEAD(, l1_ttable) l1_list;
@@ -1267,7 +1272,7 @@ pmap_enter(pmap_t pm, vaddr_t va, paddr_
pd_entry_t *pl1pd, l1pd;
 
pl1pd = >pm_l1->l1_kva[L1_IDX(va)];
-   l1pd = L1_C_PROTO | l2b->l2b_phys;
+   l1pd = L1_C_PROTO | l2b->l2b_phys | l1_c_pxn;
if (*pl1pd != l1pd) {
*pl1pd = l1pd;
PTE_SYNC(pl1pd);
@@ -2861,7 +2866,7 @@ void  (*pmap_zero_page_func)(struct vm_p
 void
 pmap_pte_init_armv7(void)
 {
-   uint32_t id_mmfr3;
+   uint32_t id_mmfr0, id_mmfr3;
 
/*
 * XXX We want to use proper TEX settings eventually.
@@ -2909,6 +2914,11 @@ pmap_pte_init_armv7(void)
 
pmap_copy_page_func = pmap_copy_page_generic;
pmap_zero_page_func = pmap_zero_page_generic;
+
+   /* Check if the PXN bit is supported. */
+   __asm volatile("mrc p15, 0, %0, c0, c1, 4" : "=r"(id_mmfr0));
+   if ((id_mmfr0 & ID_MMFR0_VMSA_MASK) >= VMSA_V7_PXN)
+   l1_c_pxn = L1_C_V7_PXN;
 
/* Check for coherent walk. */
__asm volatile("mrc p15, 0, %0, c0, c1, 7" : "=r"(id_mmfr3));
Index: arch/arm/include/pte.h
===
RCS file: /cvs/src/sys/arch/arm/include/pte.h,v
retrieving revision 1.7
diff -u -p -r1.7 pte.h
--- arch/arm/include/pte.h  18 Aug 2016 09:28:22 -  1.7
+++ arch/arm/include/pte.h  26 Aug 2016 19:24:39 -
@@ -159,6 +159,7 @@ typedef uint32_tpt_entry_t; /* L2 table
 #defineL1_S_V7_AF  0x0400  /* Access Flag */
 #defineL1_S_V7_IMP 0x0200  /* implementation defined */
 #defineL1_S_V7_XN  0x0010  /* eXecute Never */
+#defineL1_S_V7_PXN 0x0001  /* Privileged eXecute Never */
 
 /* L1 Coarse Descriptor */
 #defineL1_C_IMP0   0x0004  /* implementation defined */
@@ -170,8 +171,9 @@ typedef uint32_tpt_entry_t; /* L2 table
 
 #defineL1_C_XSCALE_P   0x0200  /* ECC enable for this section 
*/
 
-#defineL1_C_V7_NS  0x0008  /* Non-secure */
 #defineL1_C_V7_IMP 0x0200  /* implementation defined */
+#defineL1_C_V7_NS  0x0008  /* Non-secure */
+#defineL1_C_V7_PXN 0x0004  /* Privileged eXecute Never */
 
 /* L1 Fine Descriptor */
 #defineL1_F_IMP0   0x0004  /* implementation defined */



fdt_find_node() bug

2016-08-23 Thread Mark Kettenis
This function is supposed to return NULL if the node isn't found.  But
the current implementation will always return the node for the last
path component that matched.  Wchis will be the root node if nothing
else matches.  So this function will never return NULL if the path
starts with '/'.  Diff fixes this issue.

ok?


Index: fdt.c
===
RCS file: /cvs/src/sys/dev/ofw/fdt.c,v
retrieving revision 1.18
diff -u -p -r1.18 fdt.c
--- fdt.c   26 Jul 2016 22:10:10 -  1.18
+++ fdt.c   23 Aug 2016 17:36:00 -
@@ -410,6 +410,9 @@ fdt_find_node(char *name)
}
}
 
+   if (child == NULL)
+   return NULL; /* No match found. */
+
p = q;
}
 



Re: ld.so initarray support

2016-08-23 Thread Mark Kettenis
> Date: Mon, 22 Aug 2016 21:27:51 -0700
> From: Philip Guenther 
> 
> Right now, DT_NUM is defined in , but that's dumb: it 
> should be moved immediately to libexec/ld.so/resolv.h, right above this 
> struct, and its value increased to match the growth here.  I killed it's 
> use in lib/csu for this, so don't hesitate in pulling it over.

Currntly doing a make build on hppa with this diff.

ok (assuming it's happy)?


Index: sys/sys/exec_elf.h
===
RCS file: /cvs/src/sys/sys/exec_elf.h,v
retrieving revision 1.60
diff -u -p -r1.60 exec_elf.h
--- sys/sys/exec_elf.h  23 Aug 2016 06:46:17 -  1.60
+++ sys/sys/exec_elf.h  23 Aug 2016 13:56:37 -
@@ -525,9 +525,6 @@ typedef struct {
 #define DF_1_NODUMP0x1000
 #define DF_1_CONLFAT   0x2000
 
-/* ld.so: number of low tags that are used saved internally (0 .. DT_NUM-1) */
-#define DT_NUM (DT_PREINIT_ARRAYSZ+1)
-
 /* Standard ELF hashing function */
 unsigned int elf_hash(const unsigned char *name);
 
Index: libexec/ld.so/resolve.h
===
RCS file: /cvs/src/libexec/ld.so/resolve.h,v
retrieving revision 1.80
diff -u -p -r1.80 resolve.h
--- libexec/ld.so/resolve.h 23 Aug 2016 06:46:17 -  1.80
+++ libexec/ld.so/resolve.h 23 Aug 2016 13:56:37 -
@@ -33,6 +33,9 @@
 #include 
 #include 
 
+/* Number of low tags that are used saved internally (0 .. DT_NUM-1) */
+#define DT_NUM (DT_PREINIT_ARRAYSZ + 1)
+
 struct load_list {
struct load_list *next;
void*start;



Re: First usages of timeout_set_proc(9)

2016-10-03 Thread Mark Kettenis
> Date: Mon, 3 Oct 2016 14:57:34 +0200
> From: Martin Pieuchot 
> 
> Here are some timeouts that require a process context in order to call
> ip_output().
> 
> The reason is that rtalloc(9) might end up inserting a RTF_CLONING route
> and that requires holding a write lock.  This isn't going to change
> because we're also going to use write locks to protect pf(4) internals. 
> 
> So to not introduce new sleeping points in the socket layer we're going
> to serialize all code paths that might end up in ip_output().  For that
> we're going to use a write lock, for which we need a process context.
> 
> Now that dlg@ fixed the deadlocks pointed by Haesbaert and guenther@,
> let's convert the first timeouts.
> 
> ok?

Let's see if this sticks.

ok kettenis@

> Index: net/if_pflow.c
> ===
> RCS file: /cvs/src/sys/net/if_pflow.c,v
> retrieving revision 1.61
> diff -u -p -r1.61 if_pflow.c
> --- net/if_pflow.c29 Apr 2016 08:55:03 -  1.61
> +++ net/if_pflow.c3 Oct 2016 12:47:11 -
> @@ -548,15 +548,16 @@ pflow_init_timeouts(struct pflow_softc *
>   if (timeout_initialized(>sc_tmo_tmpl))
>   timeout_del(>sc_tmo_tmpl);
>   if (!timeout_initialized(>sc_tmo))
> - timeout_set(>sc_tmo, pflow_timeout, sc);
> + timeout_set_proc(>sc_tmo, pflow_timeout, sc);
>   break;
>   case PFLOW_PROTO_10:
>   if (!timeout_initialized(>sc_tmo_tmpl))
> - timeout_set(>sc_tmo_tmpl, pflow_timeout_tmpl, sc);
> + timeout_set_proc(>sc_tmo_tmpl, pflow_timeout_tmpl,
> + sc);
>   if (!timeout_initialized(>sc_tmo))
> - timeout_set(>sc_tmo, pflow_timeout, sc);
> + timeout_set_proc(>sc_tmo, pflow_timeout, sc);
>   if (!timeout_initialized(>sc_tmo6))
> - timeout_set(>sc_tmo6, pflow_timeout6, sc);
> + timeout_set_proc(>sc_tmo6, pflow_timeout6, sc);
>  
>   timeout_add_sec(>sc_tmo_tmpl, PFLOW_TMPL_TIMEOUT);
>   break;
> Index: net/if_pfsync.c
> ===
> RCS file: /cvs/src/sys/net/if_pfsync.c,v
> retrieving revision 1.234
> diff -u -p -r1.234 if_pfsync.c
> --- net/if_pfsync.c   27 Sep 2016 04:57:17 -  1.234
> +++ net/if_pfsync.c   3 Oct 2016 12:47:11 -
> @@ -328,9 +328,9 @@ pfsync_clone_create(struct if_clone *ifc
>   IFQ_SET_MAXLEN(>if_snd, IFQ_MAXLEN);
>   ifp->if_hdrlen = sizeof(struct pfsync_header);
>   ifp->if_mtu = ETHERMTU;
> - timeout_set(>sc_tmo, pfsync_timeout, sc);
> - timeout_set(>sc_bulk_tmo, pfsync_bulk_update, sc);
> - timeout_set(>sc_bulkfail_tmo, pfsync_bulk_fail, sc);
> + timeout_set_proc(>sc_tmo, pfsync_timeout, sc);
> + timeout_set_proc(>sc_bulk_tmo, pfsync_bulk_update, sc);
> + timeout_set_proc(>sc_bulkfail_tmo, pfsync_bulk_fail, sc);
>  
>   if_attach(ifp);
>   if_alloc_sadl(ifp);
> @@ -1720,7 +1720,7 @@ pfsync_defer(struct pf_state *st, struct
>   sc->sc_deferred++;
>   TAILQ_INSERT_TAIL(>sc_deferrals, pd, pd_entry);
>  
> - timeout_set(>pd_tmo, pfsync_defer_tmo, pd);
> + timeout_set_proc(>pd_tmo, pfsync_defer_tmo, pd);
>   timeout_add_msec(>pd_tmo, 20);
>  
>   schednetisr(NETISR_PFSYNC);
> Index: netinet/ip_carp.c
> ===
> RCS file: /cvs/src/sys/netinet/ip_carp.c,v
> retrieving revision 1.293
> diff -u -p -r1.293 ip_carp.c
> --- netinet/ip_carp.c 25 Jul 2016 16:44:04 -  1.293
> +++ netinet/ip_carp.c 3 Oct 2016 12:47:11 -
> @@ -831,9 +831,9 @@ carp_new_vhost(struct carp_softc *sc, in
>   vhe->vhid = vhid;
>   vhe->advskew = advskew;
>   vhe->state = INIT;
> - timeout_set(>ad_tmo, carp_send_ad, vhe);
> - timeout_set(>md_tmo, carp_master_down, vhe);
> - timeout_set(>md6_tmo, carp_master_down, vhe);
> + timeout_set_proc(>ad_tmo, carp_send_ad, vhe);
> + timeout_set_proc(>md_tmo, carp_master_down, vhe);
> + timeout_set_proc(>md6_tmo, carp_master_down, vhe);
>  
>   KERNEL_ASSERT_LOCKED(); /* touching carp_vhosts */
>  
> Index: netinet/tcp_timer.h
> ===
> RCS file: /cvs/src/sys/netinet/tcp_timer.h,v
> retrieving revision 1.13
> diff -u -p -r1.13 tcp_timer.h
> --- netinet/tcp_timer.h   6 Jul 2011 23:44:20 -   1.13
> +++ netinet/tcp_timer.h   3 Oct 2016 12:47:11 -
> @@ -116,7 +116,7 @@ const char *tcptimers[] =
>   * Init, arm, disarm, and test TCP timers.
>   */
>  #define  TCP_TIMER_INIT(tp, timer)   
> \
> - timeout_set(&(tp)->t_timer[(timer)], tcp_timer_funcs[(timer)], tp)
> + timeout_set_proc(&(tp)->t_timer[(timer)], tcp_timer_funcs[(timer)], tp)
>  
>  

Re: Fix kbd -l

2016-09-30 Thread Mark Kettenis
> From: Jeremie Courreges-Anglas <j...@wxcvbn.org>
> Date: Fri, 30 Sep 2016 17:00:45 +0200
> 
> Mark Kettenis <mark.kette...@xs4all.nl> writes:
> 
> [...]
> 
> >> > -for (i = 0; kbdenc_tab[i].value; i++)
> >> > -printf("%s\n", kbdenc_tab[i].name);
> >> > +for (i = 0; i < encs->nencodings; i++) {
> >> > +n = _tab[0];
> >> > +found = 0;
> >> > +encoding = encs->encodings[i];
> >> > +while (n->value) {
> >> > +if (n->value == KB_ENCODING(encoding)) {
> >> > +printf("%s", n->name);
> >> > +found++;
> >> > +}
> >> > +n++;
> >> > +}
> >> 
> >> This looks a lot like a for loop.
> >
> > Right.  But there are some similar loops that are already written this
> > way.  So I left it the way I wrote^H^H^H^H^Hcopied it.  Feel free to
> > submite a separate patch that fixes this.
> 
> Ah, I see.  Here's the diff.

Thanks!  ok kettenis@

> Index: kbd_wscons.c
> ===
> RCS file: /cvs/src/sbin/kbd/kbd_wscons.c,v
> retrieving revision 1.31
> diff -u -p -p -u -r1.31 kbd_wscons.c
> --- kbd_wscons.c  30 Sep 2016 12:07:23 -  1.31
> +++ kbd_wscons.c  30 Sep 2016 14:55:03 -
> @@ -100,27 +100,23 @@ kbd_show_enc(struct wskbd_encoding_data 
>   kbtype_tab[idx]);
>  
>   for (i = 0; i < encs->nencodings; i++) {
> - n = _tab[0];
>   found = 0;
>   encoding = encs->encodings[i];
> - while (n->value) {
> + for (n = _tab[0]; n->value; n++) {
>   if (n->value == KB_ENCODING(encoding)) {
>   printf("%s", n->name);
>   found++;
>   }
> - n++;
>   }
>   if (found == 0)
>   printf("", KB_ENCODING(encoding));
> - n = _tab[0];
>   found = 0;
>   variant = KB_VARIANT(encoding);
> - while (n->value) {
> + for (n = _tab[0]; n->value; n++) {
>   if ((n->value & KB_VARIANT(encoding)) == n->value) {
>   printf(".%s", n->name);
>   variant &= ~n->value;
>   }
> - n++;
>   }
>   if (variant != 0)
>   printf(".", variant);
> @@ -248,11 +244,9 @@ kbd_set(char *name, int verbose)
>   *b++ = *c++;
>   *b = '\0';
>   v = 0;
> - n = _tab[0];
> - while (n->value) {
> + for (n = _tab[0]; n->value; n++) {
>   if (strcmp(n->name, buf) == 0)
>   v = n->value;
> - n++;
>   }
>   if (v == 0)
>   errx(1, "unknown variant %s", buf);
> 
> -- 
> jca | PGP : 0x1524E7EE / 5135 92C1 AD36 5293 2BDF  DDCC 0DFA 74AE 1524 E7EE
> 



Re: clang, stack limit and inlining

2016-10-02 Thread Mark Kettenis
> From: "Theo de Raadt" 
> Date: Fri, 30 Sep 2016 09:38:30 -0600
> 
> > Diff below is a possible way to fix this.  But in a way we're cheating
> > here since we'll still consume more than 2047 bytes of stack space
> > when we descend into wskbd_initmute().  So perhaps we should rewrite
> > this code to dynamically allocate the mixer_devinfo structs?
> 
> yes, it should be dynamically allocated.

Here's a diff that does that.

As far as I can tell (playing "My favourite hacks") this causes bo
regressions on my x1 rev 3.

ok?


Index: dev/audio.c
===
RCS file: /cvs/src/sys/dev/audio.c,v
retrieving revision 1.153
diff -u -p -r1.153 audio.c
--- dev/audio.c 19 Sep 2016 06:46:43 -  1.153
+++ dev/audio.c 2 Oct 2016 17:33:56 -
@@ -1786,45 +1786,57 @@ audiopoll(dev_t dev, int events, struct 
 int
 wskbd_initmute(struct audio_softc *sc, struct mixer_devinfo *vol)
 {
-   struct mixer_devinfo mi;
+   struct mixer_devinfo *mi;
+   int index = -1;
 
-   mi.index = vol->next;
-   for (mi.index = vol->next; mi.index != -1; mi.index = mi.next) {
-   if (sc->ops->query_devinfo(sc->arg, ) != 0)
+   mi = malloc(sizeof(struct mixer_devinfo), M_TEMP, M_WAITOK);
+
+   for (mi->index = vol->next; mi->index != -1; mi->index = mi->next) {
+   if (sc->ops->query_devinfo(sc->arg, mi) != 0)
+   break;
+   if (strcmp(mi->label.name, AudioNmute) == 0) {
+   index = mi->index;
break;
-   if (strcmp(mi.label.name, AudioNmute) == 0)
-   return mi.index;
+   }
}
-   return -1;
+
+   free(mi, M_TEMP, sizeof(struct mixer_devinfo));
+   return index;
 }
 
 int
 wskbd_initvol(struct audio_softc *sc, struct wskbd_vol *vol, char *cn, char 
*dn)
 {
-   struct mixer_devinfo dev, cls;
+   struct mixer_devinfo *dev, *cls;
 
-   for (dev.index = 0; ; dev.index++) {
-   if (sc->ops->query_devinfo(sc->arg, ) != 0)
+   vol->val = vol->mute = -1;
+   dev = malloc(sizeof(struct mixer_devinfo), M_TEMP, M_WAITOK);
+   cls = malloc(sizeof(struct mixer_devinfo), M_TEMP, M_WAITOK);
+
+   for (dev->index = 0; ; dev->index++) {
+   if (sc->ops->query_devinfo(sc->arg, dev) != 0)
break;
-   if (dev.type != AUDIO_MIXER_VALUE)
+   if (dev->type != AUDIO_MIXER_VALUE)
continue;
-   cls.index = dev.mixer_class;
-   if (sc->ops->query_devinfo(sc->arg, ) != 0)
+   cls->index = dev->mixer_class;
+   if (sc->ops->query_devinfo(sc->arg, cls) != 0)
continue;
-   if (strcmp(cls.label.name, cn) == 0 &&
-   strcmp(dev.label.name, dn) == 0) {
-   vol->val = dev.index;
-   vol->nch = dev.un.v.num_channels;
-   vol->step = dev.un.v.delta > 8 ? dev.un.v.delta : 8;
-   vol->mute = wskbd_initmute(sc, );
+   if (strcmp(cls->label.name, cn) == 0 &&
+   strcmp(dev->label.name, dn) == 0) {
+   vol->val = dev->index;
+   vol->nch = dev->un.v.num_channels;
+   vol->step = dev->un.v.delta > 8 ? dev->un.v.delta : 8;
+   vol->mute = wskbd_initmute(sc, dev);
vol->val_pending = vol->mute_pending = 0;
-   DPRINTF("%s: wskbd using %s.%s%s\n",
-   DEVNAME(sc), cn, dn, vol->mute >= 0 ? ", mute 
control" : "");
-   return 1;
+   DPRINTF("%s: wskbd using %s.%s%s\n", DEVNAME(sc),
+   cn, dn, vol->mute >= 0 ? ", mute control" : "");
+   break;
}
}
-   vol->val = vol->mute = -1;
-   return 0;
+
+   free(cls, M_TEMP, sizeof(struct mixer_devinfo));
+   free(dev, M_TEMP, sizeof(struct mixer_devinfo));
+   return (vol->val != -1);
 }
 
 void



Re: Modernize regress/libexec/ld.so/constructor

2016-09-27 Thread Mark Kettenis
> Date: Tue, 27 Sep 2016 18:01:51 +0200
> From: Alexander Bluhm <alexander.bl...@gmx.net>
> 
> On Mon, Sep 26, 2016 at 11:39:29PM +0200, Mark Kettenis wrote:
> > Since the tests succeed on amd64, and should succeed on other
> > architectures, the diff re-enables this test.
> 
> When running with "make regress" the test fails as the regress
> target does not build the libraries.
> 
> Usually I add an addidtional rule in such a case.
> 
> ok?

Other regress tests that build library solve this by having a

regress: all

target in the library Makefile.  See lib/libc/cxa-exit for example.

Here is a diff that does that.  As a bonus it sets NOPROFILE=yes to
avoid building a profiled library and also adds $OpenBSD$ markers.

ok?


Index: regress/libexec/ld.so/constructor/libaa/Makefile
===
RCS file: /cvs/src/regress/libexec/ld.so/constructor/libaa/Makefile,v
retrieving revision 1.1
diff -u -p -r1.1 Makefile
--- regress/libexec/ld.so/constructor/libaa/Makefile1 Feb 2003 19:56:17 
-   1.1
+++ regress/libexec/ld.so/constructor/libaa/Makefile27 Sep 2016 17:39:56 
-
@@ -1,3 +1,9 @@
+# $OpenBSD$
+
 LIB=aa
 SRCS= aa.C
+NOPROFILE=yes
+
+regress: all
+
 .include 
Index: regress/libexec/ld.so/constructor/libab/Makefile
===
RCS file: /cvs/src/regress/libexec/ld.so/constructor/libab/Makefile,v
retrieving revision 1.2
diff -u -p -r1.2 Makefile
--- regress/libexec/ld.so/constructor/libab/Makefile27 Sep 2016 06:52:50 
-  1.2
+++ regress/libexec/ld.so/constructor/libab/Makefile27 Sep 2016 17:40:25 
-
@@ -1,6 +1,12 @@
+# $OpenBSD$
+
 LIB=ab
 SRCS= ab.C
+NOPROFILE=yes
 CPPFLAGS=-I${.CURDIR}/../libaa
 LDADD=-L../libaa
 LDADD+=-laa
+
+regress: all
+
 .include 



ehci(4)/imxehci(4) diff to switch port into host mode

2016-10-01 Thread Mark Kettenis
The USB controller on the Freescale i.MX application processors has a
dual role port that can act as device (OTG) or as host.  Since we
don't have any device mode support in our kernel, we try to switch the
port into host mode.  Unfortunately that never worked.  Here's why:

The USBMODE register that controls the mode, gets reset whenever we
reset the controller, i.e. when ehci_reset() gets called.  Since
ehci_init() calls ehci_reset() we lose the host mode setting almost
immediately, and nothing works.

The diff below adds code to save and restore the USBMODE register if
the EHCIF_USBMODE flag is set, and sets this flag in the imxehci(4)
driver.  I also moved the defines for this register to ehcireg.h.
While this isn't a standard EHCI register, it seems that it is present
on many dual-role USB 2.0 controller.  Allegedly it is part of a
design that ended up being licensed to many other companies.

Note that the register offset changed from 0xa8 to 0x68.  This is not
a bug.  Imade the offset relative to the offset given by the
EHCI_CAPLENGTH register.  It is now accessed using EOREAD4/EOWRITE4
instead of EREAD4/EWRITE4.

ok?


Index: arch/armv7/imx/imxehci.c
===
RCS file: /cvs/src/sys/arch/armv7/imx/imxehci.c,v
retrieving revision 1.17
diff -u -p -r1.17 imxehci.c
--- arch/armv7/imx/imxehci.c13 Aug 2016 11:08:58 -  1.17
+++ arch/armv7/imx/imxehci.c1 Oct 2016 13:26:02 -
@@ -58,9 +58,6 @@
 /* ehci */
 #define USB_EHCI_OFFSET0x100
 
-#define EHCI_USBMODE   0xa8
-
-#define EHCI_USBMODE_HOST  (3 << 0)
 #define EHCI_PS_PTS_UTMI_MASK  ((1 << 25) | (3 << 30))
 
 /* usb non-core */
@@ -144,6 +141,7 @@ imxehci_attach(struct device *parent, st
sc->sc.iot = faa->fa_iot;
sc->sc.sc_bus.dmatag = faa->fa_dmat;
sc->sc.sc_size = faa->fa_reg[0].size - USB_EHCI_OFFSET;
+   sc->sc.sc_flags = EHCIF_USBMODE;
 
/* Map I/O space */
if (bus_space_map(sc->sc.iot, faa->fa_reg[0].addr,
@@ -247,8 +245,8 @@ imxehci_attach(struct device *parent, st
USBPHY_CTRL_ENUTMILEVEL2 | USBPHY_CTRL_ENUTMILEVEL3);
 
/* set host mode */
-   EWRITE4(>sc, EHCI_USBMODE,
-   EREAD4(>sc, EHCI_USBMODE) | EHCI_USBMODE_HOST);
+   EOWRITE4(>sc, EHCI_USBMODE,
+   EOREAD4(>sc, EHCI_USBMODE) | EHCI_USBMODE_CM_HOST);
 
/* set to UTMI mode */
EOWRITE4(>sc, EHCI_PORTSC(1),
Index: dev/usb/ehci.c
===
RCS file: /cvs/src/sys/dev/usb/ehci.c,v
retrieving revision 1.193
diff -u -p -r1.193 ehci.c
--- dev/usb/ehci.c  15 Sep 2016 02:00:17 -  1.193
+++ dev/usb/ehci.c  1 Oct 2016 13:26:02 -
@@ -1114,7 +1114,7 @@ ehci_activate(struct device *self, int a
 usbd_status
 ehci_reset(struct ehci_softc *sc)
 {
-   u_int32_t hcr;
+   u_int32_t hcr, usbmode;
int i;
 
EOWRITE4(sc, EHCI_USBCMD, 0);   /* Halt controller */
@@ -1128,6 +1128,9 @@ ehci_reset(struct ehci_softc *sc)
if (!hcr)
printf("%s: halt timeout\n", sc->sc_bus.bdev.dv_xname);
 
+   if (sc->sc_flags & EHCIF_USBMODE)
+   usbmode = EOREAD4(sc, EHCI_USBMODE);
+
EOWRITE4(sc, EHCI_USBCMD, EHCI_CMD_HCRESET);
for (i = 0; i < 100; i++) {
usb_delay_ms(>sc_bus, 1);
@@ -1140,6 +1143,9 @@ ehci_reset(struct ehci_softc *sc)
printf("%s: reset timeout\n", sc->sc_bus.bdev.dv_xname);
return (USBD_IOERROR);
}
+
+   if (sc->sc_flags & EHCIF_USBMODE)
+   EOWRITE4(sc, EHCI_USBMODE, usbmode);
 
return (USBD_NORMAL_COMPLETION);
 }
Index: dev/usb/ehcireg.h
===
RCS file: /cvs/src/sys/dev/usb/ehcireg.h,v
retrieving revision 1.20
diff -u -p -r1.20 ehcireg.h
--- dev/usb/ehcireg.h   10 Apr 2015 13:56:42 -  1.20
+++ dev/usb/ehcireg.h   1 Oct 2016 13:26:02 -
@@ -162,6 +162,13 @@
 
 #define EHCI_PORT_RESET_COMPLETE 2 /* ms */
 
+/* Nonstandard register to set controller mode. */
+#define EHCI_USBMODE   0x68
+#define  EHCI_USBMODE_CM_M 0x0003
+#define  EHCI_USBMODE_CM_IDLE  0x
+#define  EHCI_USBMODE_CM_DEVICE0x0002
+#define  EHCI_USBMODE_CM_HOST  0x0003  
+
 #define EHCI_FLALIGN_ALIGN 0x1000
 
 /* No data structure may cross a page boundary. */
Index: dev/usb/ehcivar.h
===
RCS file: /cvs/src/sys/dev/usb/ehcivar.h,v
retrieving revision 1.36
diff -u -p -r1.36 ehcivar.h
--- dev/usb/ehcivar.h   2 Nov 2015 14:55:41 -   1.36
+++ dev/usb/ehcivar.h   1 Oct 2016 13:26:02 -
@@ -130,6 +130,7 @@ struct ehci_softc {
int sc_flags;   /* misc flags */
 #define EHCIF_DROPPED_INTR_WORKAROUND  0x01
 #define EHCIF_PCB_INTR 0x02
+#define EHCIF_USBMODE  

Fix kbd -l

2016-09-29 Thread Mark Kettenis
This diff adds a WSKBDIO_GETENCODINGS ioctl and uses it to print a
list of supported encodings like the old kvm groveling code did.  The
ioctl will clamp the number of entries that are returns to the number
that was passed in.  This means that if the number returned is the
same as the number passed in, there might be more entries and you
probably want to retry with a larger buffer.  The new implementation
does this.

Waring; this did not go through a make release yet.  And that might be
relevant, since this code gets included in the ramdisks.

Thoughts?


Index: sys/dev/wscons/wsconsio.h
===
RCS file: /cvs/src/sys/dev/wscons/wsconsio.h,v
retrieving revision 1.75
diff -u -p -r1.75 wsconsio.h
--- sys/dev/wscons/wsconsio.h   14 Sep 2016 03:25:51 -  1.75
+++ sys/dev/wscons/wsconsio.h   29 Sep 2016 12:10:57 -
@@ -207,6 +207,12 @@ struct wskbd_backlight {
 #defineWSKBD_TRANSLATED0
 #defineWSKBD_RAW   1
 
+struct wskbd_encoding_data {
+   int nencodings;
+   kbd_t   *encodings;
+};
+#define WSKBDIO_GETENCODINGS   _IOWR('W', 21, struct wskbd_encoding_data)
+
 /*
  * Mouse ioctls (32 - 63)
  */
Index: sys/dev/wscons/wskbd.c
===
RCS file: /cvs/src/sys/dev/wscons/wskbd.c,v
retrieving revision 1.83
diff -u -p -r1.83 wskbd.c
--- sys/dev/wscons/wskbd.c  12 Dec 2015 12:30:18 -  1.83
+++ sys/dev/wscons/wskbd.c  29 Sep 2016 12:10:57 -
@@ -1001,9 +1001,11 @@ wskbd_displayioctl(struct device *dev, u
struct wskbd_bell_data *ubdp, *kbdp;
struct wskbd_keyrepeat_data *ukdp, *kkdp;
struct wskbd_map_data *umdp;
+   struct wskbd_encoding_data *uedp;
kbd_t enc;
void *buf;
int len, error;
+   int count, i;
 
switch (cmd) {
case WSKBDIO_BELL:
@@ -1159,6 +1161,20 @@ getkeyrepeat:
wsmux_set_layout(sc->sc_base.me_parent, enc);
 #endif
return (0);
+
+   case WSKBDIO_GETENCODINGS:
+   uedp = (struct wskbd_encoding_data *)data;
+   for (count = 0; sc->id->t_keymap.keydesc[count].name; count++)
+   ;
+   if (uedp->nencodings > count)
+   uedp->nencodings = count;
+   for (i = 0; i < uedp->nencodings; i++) {
+   error = copyout(>id->t_keymap.keydesc[i].name,
+   >encodings[i], sizeof(kbd_t));
+   if (error)
+   return (error);
+   }
+   return(0);
 
case WSKBDIO_GETBACKLIGHT:
if (wskbd_get_backlight != NULL)
Index: sbin/kbd/kbd_wscons.c
===
RCS file: /cvs/src/sbin/kbd/kbd_wscons.c,v
retrieving revision 1.30
diff -u -p -r1.30 kbd_wscons.c
--- sbin/kbd/kbd_wscons.c   27 Sep 2016 22:03:49 -  1.30
+++ sbin/kbd/kbd_wscons.c   29 Sep 2016 12:10:57 -
@@ -34,6 +34,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 
@@ -82,31 +83,83 @@ struct nameint kbdvar_tab[] = {
 
 extern char *__progname;
 
-void   kbd_show_enc(int idx);
+void   kbd_show_enc(struct wskbd_encoding_data *encs, int idx);
+void   kbd_get_encs(int fd, struct wskbd_encoding_data *encs);
 void   kbd_list(void);
 void   kbd_set(char *name, int verbose);
 
 void
-kbd_show_enc(int idx)
+kbd_show_enc(struct wskbd_encoding_data *encs, int idx)
 {
+   int found;
+   kbd_t encoding, variant;
+   struct nameint *n;
int i;
 
printf("tables available for %s keyboard:\nencoding\n\n",
kbtype_tab[idx]);
 
-   for (i = 0; kbdenc_tab[i].value; i++)
-   printf("%s\n", kbdenc_tab[i].name);
+   for (i = 0; i < encs->nencodings; i++) {
+   n = _tab[0];
+   found = 0;
+   encoding = encs->encodings[i];
+   while (n->value) {
+   if (n->value == KB_ENCODING(encoding)) {
+   printf("%s", n->name);
+   found++;
+   }
+   n++;
+   }
+   if (found == 0)
+   printf("", KB_ENCODING(encoding));
+   n = _tab[0];
+   found = 0;
+   variant = KB_VARIANT(encoding);
+   while (n->value) {
+   if ((n->value & KB_VARIANT(encoding)) == n->value) {
+   printf(".%s", n->name);
+   variant &= ~n->value;
+   }
+   n++;
+   }
+   if (variant != 0)
+   printf(".", variant);
+   printf("\n");
+   }
printf("\n");
 }
 
 void
+kbd_get_encs(int fd, struct wskbd_encoding_data 

clang, stack limit and inlining

2016-09-30 Thread Mark Kettenis
We compile out kernel with -Wframe-larger-than=2047 to make sure we
don't write stupid code that blows the kernel stack.  Now clang thinks
it is clever and considers it a good idea to inline functions when the
function and the caller live in the same source file.  A particular
case where this happens is in audio.c, where wskbd_initmute() gets
inlined into wskbd_initvol().  And this inlining pushes things over
the stack limit, since struct mixer_devinfo is quite large and it now
needs three copies of that structure.

Diff below is a possible way to fix this.  But in a way we're cheating
here since we'll still consume more than 2047 bytes of stack space
when we descend into wskbd_initmute().  So perhaps we should rewrite
this code to dynamically allocate the mixer_devinfo structs?


Index: sys/cdefs.h
===
RCS file: /cvs/src/sys/sys/cdefs.h,v
retrieving revision 1.39
diff -u -p -r1.39 cdefs.h
--- sys/cdefs.h 18 Apr 2014 11:51:17 -  1.39
+++ sys/cdefs.h 30 Sep 2016 14:22:28 -
@@ -160,6 +160,12 @@
 #define __only_inline  static __inline
 #endif
 
+#if __GNUC_PREREQ__(3, 0)
+#define __noinline __attribute__((__noinline__))
+#else
+#define __noinline
+#endif
+
 /*
  * GNU C version 2.96 adds explicit branch prediction so that
  * the CPU back-end can hint the processor and also so that
Index: dev/audio.c
===
RCS file: /cvs/src/sys/dev/audio.c,v
retrieving revision 1.153
diff -u -p -r1.153 audio.c
--- dev/audio.c 19 Sep 2016 06:46:43 -  1.153
+++ dev/audio.c 30 Sep 2016 14:22:28 -
@@ -1783,7 +1783,7 @@ audiopoll(dev_t dev, int events, struct 
 }
 
 #if NWSKBD > 0
-int
+__noinline int
 wskbd_initmute(struct audio_softc *sc, struct mixer_devinfo *vol)
 {
struct mixer_devinfo mi;



Re: Fix kbd -l

2016-09-30 Thread Mark Kettenis
> From: Jeremie Courreges-Anglas <j...@wxcvbn.org>
> Date: Fri, 30 Sep 2016 13:32:57 +0200
> 
> Mark Kettenis <mark.kette...@xs4all.nl> writes:
> 
> >> Date: Thu, 29 Sep 2016 14:19:43 +0200 (CEST)
> >> From: Mark Kettenis <mark.kette...@xs4all.nl>
> >> 
> >> This diff adds a WSKBDIO_GETENCODINGS ioctl and uses it to print a
> >> list of supported encodings like the old kvm groveling code did.  The
> >> ioctl will clamp the number of entries that are returns to the number
> >> that was passed in.  This means that if the number returned is the
> >> same as the number passed in, there might be more entries and you
> >> probably want to retry with a larger buffer.  The new implementation
> >> does this.
> >
> > Thanks to tb@ for testing this on a ramdisk.  Here is a slightly
> > better diff that frees the allocated memory.
> >
> > ok?
> 
> Looks fine to me, ok jca@

Thanks,

> Nitpicking below,

I selectively applied those; see comments below.

> > Index: sbin/kbd/kbd_wscons.c
> > ===
> > RCS file: /cvs/src/sbin/kbd/kbd_wscons.c,v
> > retrieving revision 1.30
> > diff -u -p -r1.30 kbd_wscons.c
> > --- sbin/kbd/kbd_wscons.c   27 Sep 2016 22:03:49 -  1.30
> > +++ sbin/kbd/kbd_wscons.c   29 Sep 2016 18:12:48 -
> > @@ -34,6 +34,7 @@
> >  #include 
> >  #include 
> >  #include 
> > +#include 
> >  #include 
> >  #include 
> >  
> > @@ -82,31 +83,83 @@ struct nameint kbdvar_tab[] = {
> >  
> >  extern char *__progname;
> >  
> > -void   kbd_show_enc(int idx);
> > +void   kbd_show_enc(struct wskbd_encoding_data *encs, int idx);
> > +void   kbd_get_encs(int fd, struct wskbd_encoding_data *encs);
> >  void   kbd_list(void);
> >  void   kbd_set(char *name, int verbose);
> >  
> >  void
> > -kbd_show_enc(int idx)
> > +kbd_show_enc(struct wskbd_encoding_data *encs, int idx)
> >  {
> > +   int found;
> > +   kbd_t encoding, variant;
> > +   struct nameint *n;
> > int i;
> >  
> > printf("tables available for %s keyboard:\nencoding\n\n",
> > kbtype_tab[idx]);
> >  
> > -   for (i = 0; kbdenc_tab[i].value; i++)
> > -   printf("%s\n", kbdenc_tab[i].name);
> > +   for (i = 0; i < encs->nencodings; i++) {
> > +   n = _tab[0];
> > +   found = 0;
> > +   encoding = encs->encodings[i];
> > +   while (n->value) {
> > +   if (n->value == KB_ENCODING(encoding)) {
> > +   printf("%s", n->name);
> > +   found++;
> > +   }
> > +   n++;
> > +   }
> 
> This looks a lot like a for loop.

Right.  But there are some similar loops that are already written this
way.  So I left it the way I wrote^H^H^H^H^Hcopied it.  Feel free to
submite a separate patch that fixes this.



Re: aml_rdpciaddr is busted

2016-10-25 Thread Mark Kettenis
> Date: Wed, 19 Oct 2016 21:51:47 +0200 (CEST)
> From: Mark Kettenis <mark.kette...@xs4all.nl>
> 
> The bus number it reports will be totally bogus for devices behind PCI
> bridges.  As a consequence AML will peek and poke at registers of the
> wrong device.  This is what caused the suspend issues with Joris'
> Macbook.
> 
> The diff below attempts to fix this by using the mapping between AML
> nodes and PCI devices that we establish.  Because _INI methods may end
> up executing AML that ends up calling aml_rdpciaddr(), the mapping is
> now established before we execute _INI.  I'm not 100% sure this is
> correct as there is a possibility that _INI will poke some PCI bridges
> in a way that changes the mapping.  Only one way to find out...
> 
> The code also deals with devices that aren't there in a slightly
> different way.  They are now included in the node -> PCI mapping, but
> they're still not included in the list of PCI device nodes that we
> create.  Writing to config space for devices that aren't there is
> implemented as a no-op.  Reading will return an all-ones pattern.
> 
> So far I've only tested this on my x1.  More testing is needed.

This has been in snaps for a couple of days now.  Anybody bold enough
to ok this?

> Index: dev/acpi/acpi.c
> ===
> RCS file: /cvs/src/sys/dev/acpi/acpi.c,v
> retrieving revision 1.316
> diff -u -p -r1.316 acpi.c
> --- dev/acpi/acpi.c   18 Sep 2016 23:56:45 -  1.316
> +++ dev/acpi/acpi.c   19 Oct 2016 19:42:51 -
> @@ -614,6 +614,7 @@ acpi_getpci(struct aml_node *node, void 
>   pci->dev = ACPI_ADR_PCIDEV(val);
>   pci->fun = ACPI_ADR_PCIFUN(val);
>   pci->node = node;
> + node->pci = pci;
>   pci->sub = -1;
>  
>   dnprintf(10, "%.2x:%.2x.%x -> %s\n", 
> @@ -639,17 +640,12 @@ acpi_getpci(struct aml_node *node, void 
>   pci->_s4w = -1;
>  
>   /* Check if PCI device exists */
> - if (pci->dev > 0x1F || pci->fun > 7) {
> - free(pci, M_DEVBUF, sizeof(*pci));
> - return (1);
> - }
> + if (pci->dev > 31 || pci->fun > 7)
> + return 1;
>   tag = pci_make_tag(pc, pci->bus, pci->dev, pci->fun);
>   reg = pci_conf_read(pc, tag, PCI_ID_REG);
> - if (PCI_VENDOR(reg) == PCI_VENDOR_INVALID) {
> - free(pci, M_DEVBUF, sizeof(*pci));
> - return (1);
> - }
> - node->pci = pci;
> + if (PCI_VENDOR(reg) == PCI_VENDOR_INVALID)
> + return 1;
>  
>   TAILQ_INSERT_TAIL(_pcidevs, pci, next);
>  
> @@ -1066,11 +1062,11 @@ acpi_attach(struct device *parent, struc
>   config_found_sm(self, , acpi_print, acpi_submatch);
>   }
>  
> + /* get PCI mapping */
> + aml_walknodes(_root, AML_WALK_PRE, acpi_getpci, sc);
> +
>   /* initialize runtime environment */
>   aml_find_node(_root, "_INI", acpi_inidev, sc);
> -
> - /* Get PCI mapping */
> - aml_walknodes(_root, AML_WALK_PRE, acpi_getpci, sc);
>  
>   /* attach pci interrupt routing tables */
>   aml_find_node(_root, "_PRT", acpi_foundprt, sc);
> Index: dev/acpi/dsdt.c
> ===
> RCS file: /cvs/src/sys/dev/acpi/dsdt.c,v
> retrieving revision 1.225
> diff -u -p -r1.225 dsdt.c
> --- dev/acpi/dsdt.c   27 Sep 2016 10:04:19 -  1.225
> +++ dev/acpi/dsdt.c   19 Oct 2016 19:42:51 -
> @@ -2216,21 +2216,16 @@ aml_rdpciaddr(struct aml_node *pcidev, u
>  {
>   int64_t res;
>  
> - if (aml_evalinteger(acpi_softc, pcidev, "_ADR", 0, NULL, ) == 0) {
> - addr->fun = res & 0x;
> - addr->dev = res >> 16;
> - }
> - while (pcidev != NULL) {
> - /* HID device (PCI or PCIE root): eval _BBN */
> - if (__aml_search(pcidev, "_HID", 0)) {
> - if (aml_evalinteger(acpi_softc, pcidev, "_BBN", 0, 
> NULL, ) == 0) {
> - addr->bus = res;
> - break;
> - }
> - }
> - pcidev = pcidev->parent;
> - }
> - return (0);
> + if (pcidev->pci == NULL)
> + return -1;
> +
> + if (aml_evalinteger(acpi_softc, pcidev, "_ADR", 0, NULL, ))
> + return -1;
> +
> + addr->fun = res & 0x;
> + addr->dev = res >> 16;
> + addr->bus = pcidev->pci->bus;
> + return 0;
>  }
>  
>  /* Read/Write from opr

aml_rdpciaddr is busted

2016-10-19 Thread Mark Kettenis
The bus number it reports will be totally bogus for devices behind PCI
bridges.  As a consequence AML will peek and poke at registers of the
wrong device.  This is what caused the suspend issues with Joris'
Macbook.

The diff below attempts to fix this by using the mapping between AML
nodes and PCI devices that we establish.  Because _INI methods may end
up executing AML that ends up calling aml_rdpciaddr(), the mapping is
now established before we execute _INI.  I'm not 100% sure this is
correct as there is a possibility that _INI will poke some PCI bridges
in a way that changes the mapping.  Only one way to find out...

The code also deals with devices that aren't there in a slightly
different way.  They are now included in the node -> PCI mapping, but
they're still not included in the list of PCI device nodes that we
create.  Writing to config space for devices that aren't there is
implemented as a no-op.  Reading will return an all-ones pattern.

So far I've only tested this on my x1.  More testing is needed.


Index: dev/acpi/acpi.c
===
RCS file: /cvs/src/sys/dev/acpi/acpi.c,v
retrieving revision 1.316
diff -u -p -r1.316 acpi.c
--- dev/acpi/acpi.c 18 Sep 2016 23:56:45 -  1.316
+++ dev/acpi/acpi.c 19 Oct 2016 19:42:51 -
@@ -614,6 +614,7 @@ acpi_getpci(struct aml_node *node, void 
pci->dev = ACPI_ADR_PCIDEV(val);
pci->fun = ACPI_ADR_PCIFUN(val);
pci->node = node;
+   node->pci = pci;
pci->sub = -1;
 
dnprintf(10, "%.2x:%.2x.%x -> %s\n", 
@@ -639,17 +640,12 @@ acpi_getpci(struct aml_node *node, void 
pci->_s4w = -1;
 
/* Check if PCI device exists */
-   if (pci->dev > 0x1F || pci->fun > 7) {
-   free(pci, M_DEVBUF, sizeof(*pci));
-   return (1);
-   }
+   if (pci->dev > 31 || pci->fun > 7)
+   return 1;
tag = pci_make_tag(pc, pci->bus, pci->dev, pci->fun);
reg = pci_conf_read(pc, tag, PCI_ID_REG);
-   if (PCI_VENDOR(reg) == PCI_VENDOR_INVALID) {
-   free(pci, M_DEVBUF, sizeof(*pci));
-   return (1);
-   }
-   node->pci = pci;
+   if (PCI_VENDOR(reg) == PCI_VENDOR_INVALID)
+   return 1;
 
TAILQ_INSERT_TAIL(_pcidevs, pci, next);
 
@@ -1066,11 +1062,11 @@ acpi_attach(struct device *parent, struc
config_found_sm(self, , acpi_print, acpi_submatch);
}
 
+   /* get PCI mapping */
+   aml_walknodes(_root, AML_WALK_PRE, acpi_getpci, sc);
+
/* initialize runtime environment */
aml_find_node(_root, "_INI", acpi_inidev, sc);
-
-   /* Get PCI mapping */
-   aml_walknodes(_root, AML_WALK_PRE, acpi_getpci, sc);
 
/* attach pci interrupt routing tables */
aml_find_node(_root, "_PRT", acpi_foundprt, sc);
Index: dev/acpi/dsdt.c
===
RCS file: /cvs/src/sys/dev/acpi/dsdt.c,v
retrieving revision 1.225
diff -u -p -r1.225 dsdt.c
--- dev/acpi/dsdt.c 27 Sep 2016 10:04:19 -  1.225
+++ dev/acpi/dsdt.c 19 Oct 2016 19:42:51 -
@@ -2216,21 +2216,16 @@ aml_rdpciaddr(struct aml_node *pcidev, u
 {
int64_t res;
 
-   if (aml_evalinteger(acpi_softc, pcidev, "_ADR", 0, NULL, ) == 0) {
-   addr->fun = res & 0x;
-   addr->dev = res >> 16;
-   }
-   while (pcidev != NULL) {
-   /* HID device (PCI or PCIE root): eval _BBN */
-   if (__aml_search(pcidev, "_HID", 0)) {
-   if (aml_evalinteger(acpi_softc, pcidev, "_BBN", 0, 
NULL, ) == 0) {
-   addr->bus = res;
-   break;
-   }
-   }
-   pcidev = pcidev->parent;
-   }
-   return (0);
+   if (pcidev->pci == NULL)
+   return -1;
+
+   if (aml_evalinteger(acpi_softc, pcidev, "_ADR", 0, NULL, ))
+   return -1;
+
+   addr->fun = res & 0x;
+   addr->dev = res >> 16;
+   addr->bus = pcidev->pci->bus;
+   return 0;
 }
 
 /* Read/Write from opregion object */
@@ -2272,7 +2267,12 @@ aml_rwgas(struct aml_value *rgn, int bpo
 
if (rgn->v_opregion.iospace == GAS_PCI_CFG_SPACE) {
/* Get PCI Root Address for this opregion */
-   aml_rdpciaddr(rgn->node->parent, );
+   if (aml_rdpciaddr(rgn->node->parent, )) {
+   if (mode == ACPI_IOREAD)
+   pi.fun = 0x;
+   else
+   return;
+   }
}
 
tbit = _integer;



Re: use x2apic if it is enabled by BIOS

2016-10-14 Thread Mark Kettenis
> Date: Fri, 14 Oct 2016 16:49:31 +0900 (JST)
> From: YASUOKA Masahiko 
> 
> Hi,
> 
> I'm working on NEC Express5800/R110h-1 (dmesg is attached).  On this
> machine, our kernel panics with following message.
> 
>   cpu0 at mainbus0panic: cpu at apic id 0 already attached?
> 
> This seems to happen since x2APIC on the machine is enabled by BIOS
> and the kernel doesn't assume that.  The diff makes the kernel use
> x2APIC if it is enabled by BIOS.
> 
> ok?

is the APICBASE msr available on all amd64 machines?  If not, it will
need to be protected with a CPUID check.

> Index: sys/arch/amd64/amd64/lapic.c
> ===
> RCS file: /cvs/src/sys/arch/amd64/amd64/lapic.c,v
> retrieving revision 1.44
> diff -u -p -r1.44 lapic.c
> --- sys/arch/amd64/amd64/lapic.c  22 Jun 2016 01:12:38 -  1.44
> +++ sys/arch/amd64/amd64/lapic.c  14 Oct 2016 07:45:50 -
> @@ -170,60 +170,55 @@ lapic_map(paddr_t lapic_base)
>   int s;
>   pt_entry_t *pte;
>   vaddr_t va;
> + u_int64_t msr;
>  
> - /*
> -  * On real hardware, x2apic must only be enabled if interrupt remapping
> -  * is also enabled. See 10.12.7 of the SDM vol 3.
> -  * On hypervisors, this is not necessary. Hypervisors can implement
> -  * x2apic support even if the host CPU does not support it.
> -  * Until we support interrupt remapping, use x2apic only if the
> -  * hypervisor flag is also set.
> -  */
> - if ((cpu_ecxfeature_X2APIC) && (cpu_ecxfeature_HV)) {
> - u_int64_t msr;
> -
> - disable_intr();
> - s = lapic_tpr;
> -
> - msr = rdmsr(MSR_APICBASE);
> - msr |= APICBASE_ENABLE_X2APIC;
> - wrmsr(MSR_APICBASE, msr);
> + disable_intr();
> + s = lapic_tpr;
> +
> + msr = rdmsr(MSR_APICBASE);
>  
> + if (ISSET(msr, APICBASE_ENABLE_X2APIC) ||
> + (ISSET(cpu_ecxfeature, CPUIDECX_HV) &&
> + ISSET(cpu_ecxfeature, CPUIDECX_X2APIC))) {
> + /*
> +  * If x2APIC is enabled already, use it since it is enabled
> +  * by BIOS.  On hypervisor, use it if it exists.
> +  */
> + if (!ISSET(msr, APICBASE_ENABLE_X2APIC)) {
> + msr |= APICBASE_ENABLE_X2APIC;
> + wrmsr(MSR_APICBASE, msr);
> + }
>   lapic_readreg = x2apic_readreg;
>   lapic_writereg = x2apic_writereg;
>  #ifdef MULTIPROCESSOR
>   x86_ipi = x2apic_ipi;
>  #endif
>   x2apic_enabled = 1;
> -
>   codepatch_call(CPTAG_EOI, _eoi);
>  
>   lapic_writereg(LAPIC_TPRI, s);
> - enable_intr();
> + } else {
> + /*
> +  * Map local apic.  If we have a local apic, it's safe to
> +  * assume we're on a 486 or better and can use invlpg and
> +  * non-cacheable PTE's
> +  *
> +  * Whap the PTE "by hand" rather than calling pmap_kenter_pa
> +  * because the latter will attempt to invoke TLB shootdown
> +  * code just as we might have changed the value of
> +  * cpu_number()..
> +  */
> + va = (vaddr_t)_apic;
> + pte = kvtopte(va);
> + *pte = lapic_base | PG_RW | PG_V | PG_N | PG_G | pg_nx;
> + invlpg(va);
>  
> - return;
> + lapic_tpr = s;
>   }
>  
> - va = (vaddr_t)_apic;
> -
> - disable_intr();
> - s = lapic_tpr;
> -
> - /*
> -  * Map local apic.  If we have a local apic, it's safe to assume
> -  * we're on a 486 or better and can use invlpg and non-cacheable PTE's
> -  *
> -  * Whap the PTE "by hand" rather than calling pmap_kenter_pa because
> -  * the latter will attempt to invoke TLB shootdown code just as we
> -  * might have changed the value of cpu_number()..
> -  */
> -
> - pte = kvtopte(va);
> - *pte = lapic_base | PG_RW | PG_V | PG_N | PG_G | pg_nx;
> - invlpg(va);
> -
> - lapic_tpr = s;
>   enable_intr();
> +
> + return;
>  }
>  
>  /*
> 
> OpenBSD 6.0-current (GENERIC.MP) #44: Fri Oct 14 16:32:03 JST 2016
> 
> yasu...@yasuoka-ob1.tokyo.iiji.jp:/source/yasuoka/openbsd/head/git/src/sys/arch/amd64/compile/GENERIC.MP
> real mem = 8207699968 (7827MB)
> avail mem = 7954391040 (7585MB)
> mpath0 at root
> scsibus0 at mpath0: 256 targets
> mainbus0 at root
> bios0 at mainbus0: SMBIOS rev. 3.0 @ 0x7f92b000 (60 entries)
> bios0: vendor American Megatrends Inc. version "5.0.4012" date 06/15/2016
> bios0: NEC Express5800/R110h-1 [N8100-2316Y]
> acpi0 at bios0: rev 2
> acpi0: sleep states S0 S4 S5
> acpi0: tables DSDT FACP APIC FIDT MCFG HPET SSDT SSDT SSDT SSDT SPCR DMAR BERT
> acpi0: wakeup devices PEGP(S4) PEG0(S4) PEG1(S4) PEG2(S4) PXSX(S4) RP17(S4) 
> PXSX(S4) RP18(S4) PXSX(S4) RP19(S4) PXSX(S4) RP20(S4) PXSX(S4) RP01(S4) 
> 

pstat -d fix

2016-10-22 Thread Mark Kettenis
If there is no modifier, we should not go down the "longformat" path.
The amount of breakage is somewhat ABI-dependent, but on armv7

   pstat -d x ticks

would print stack garbage.

ok?


Index: pstat.c
===
RCS file: /cvs/src/usr.sbin/pstat/pstat.c,v
retrieving revision 1.110
diff -u -p -r1.110 pstat.c
--- pstat.c 19 Sep 2016 20:10:54 -  1.110
+++ pstat.c 22 Oct 2016 20:38:15 -
@@ -270,7 +270,7 @@ main(int argc, char *argv[])
mask = 0x;
else if (strcmp(mod, "hh") == 0)
mask = 0xff;
-   else
+   else if (strcmp(mod, "") != 0)
longformat = 1;
 
} else



Re: use x2apic if it is enabled by BIOS

2016-10-17 Thread Mark Kettenis
> Date: Sat, 15 Oct 2016 09:55:05 +0200 (CEST)
> From: s...@openbsd.org
> 
> On Fri, 14 Oct 2016, Mike Larkin wrote:
> 
> > On Fri, Oct 14, 2016 at 04:49:31PM +0900, YASUOKA Masahiko wrote:
> > > Hi,
> > > 
> > > I'm working on NEC Express5800/R110h-1 (dmesg is attached).  On this
> > > machine, our kernel panics with following message.
> > > 
> > >   cpu0 at mainbus0panic: cpu at apic id 0 already attached?
> > > 
> > > This seems to happen since x2APIC on the machine is enabled by BIOS
> > > and the kernel doesn't assume that.  The diff makes the kernel use
> > > x2APIC if it is enabled by BIOS.
> > > 
> > > ok?
> > > 
> > 
> > This should go in snaps, or wait for reports from tech@ with test results
> > before it should be committed, IMO. We don't have full support for x2apic,
> > and blindly enabling it like this hoping that the bios set everything up
> > right is bound to be a bad assumption on at least one machine out there.
> 
> As I understand the code, it should only change behavior on systems where 
> x2apic is enabled by the bios. And currently on such systems openbsd will 
> not work anyway, because we then try to use xapic mode without disabling 
> x2apic mode. Or am I missing something?

No, I think you're right and the risk of the diff is low.



Re: sparc64: delete old "traptrace" bits

2016-10-18 Thread Mark Kettenis
> Date: Sun, 16 Oct 2016 23:30:07 -0700
> From: Philip Guenther 
> 
> In 2003(!) a pile of code was deleted from sparc64's locore.s:
> 
> revision 1.35
> date: 2003/05/17 07:09:08;  author: art;  state: Exp;  lines: +1 -957;
> Get rid of lots of hairy ifdefs that we'll most likely never use.
> TRAPTRACE, TRAPSTATS, FLTTRACE and SCHED_DEBUG.
> 
> mdw@ henric@ ok.
> 
> 
> That was the code that actually put data into the trap_trace[] array, 
> rendering the remaining trap_trace* code useless.  How about we delete 
> those bits?
> 
> This built and the box booted with the resulting kernel.
> 
> ok?

ok kettenis@

> Index: sparc64/autoconf.c
> ===
> RCS file: /cvs/src/sys/arch/sparc64/sparc64/autoconf.c,v
> retrieving revision 1.126
> diff -u -p -r1.126 autoconf.c
> --- sparc64/autoconf.c8 Jun 2016 17:24:44 -   1.126
> +++ sparc64/autoconf.c17 Oct 2016 06:25:36 -
> @@ -586,11 +586,6 @@ bootpath_build(void)
>  #else
>   printf("kernel has no debugger\n");
>  #endif
> - } else if (*cp == 't') {
> - /* turn on traptrace w/o breaking into kdb */
> - extern int trap_trace_dis;
> -
> - trap_trace_dis = 0;
>   }
>   }
>  }
> Index: sparc64/db_interface.c
> ===
> RCS file: /cvs/src/sys/arch/sparc64/sparc64/db_interface.c,v
> retrieving revision 1.45
> diff -u -p -r1.45 db_interface.c
> --- sparc64/db_interface.c8 Oct 2016 05:49:09 -   1.45
> +++ sparc64/db_interface.c17 Oct 2016 06:25:37 -
> @@ -73,17 +73,6 @@ db_regs_t  ddb_regs;   /* register state */
>  
>  extern void OF_enter(void);
>  
> -extern struct traptrace {
> - unsigned short tl:3,/* Trap level */
> - ns:4,   /* PCB nsaved */
> - tt:9;   /* Trap type */
> - unsigned short pid; /* PID */
> - u_int tstate;   /* tstate */
> - u_int tsp;  /* sp */
> - u_int tpc;  /* pc */
> - u_int tfault;   /* MMU tag access */
> -} trap_trace[], trap_trace_end[];
> -
>  static long nil;
>  
>  static int
> @@ -231,14 +220,12 @@ void db_pmap_kernel(db_expr_t, int, db_e
>  void db_pload_cmd(db_expr_t, int, db_expr_t, char *);
>  void db_pmap_cmd(db_expr_t, int, db_expr_t, char *);
>  void db_lock(db_expr_t, int, db_expr_t, char *);
> -void db_traptrace(db_expr_t, int, db_expr_t, char *);
>  void db_dump_buf(db_expr_t, int, db_expr_t, char *);
>  void db_dump_espcmd(db_expr_t, int, db_expr_t, char *);
>  void db_watch(db_expr_t, int, db_expr_t, char *);
>  void db_xir(db_expr_t, int, db_expr_t, char *);
>  
>  static void db_dump_pmap(struct pmap*);
> -static void db_print_trace_entry(struct traptrace *, int);
>  
>  #ifdef MULTIPROCESSOR
>  void db_cpuinfo_cmd(db_expr_t, int, db_expr_t, char *);
> @@ -272,9 +259,6 @@ db_ktrap(type, tf)
>   struct trapstate *ts = _regs.ddb_ts[0];
>   extern int savetstate(struct trapstate *ts);
>   extern void restoretstate(int tl, struct trapstate *ts);
> - extern int trap_trace_dis;
> -
> - trap_trace_dis++;
>  
>  #if NTDA > 0
>   tda_full_blast();
> @@ -336,7 +320,6 @@ db_ktrap(type, tf)
>   *(struct frame *)tf->tf_out[6] = ddb_regs.ddb_fr;
>  #endif
>   *tf = ddb_regs.ddb_tf;
> - trap_trace_dis--;
>  
>  #ifdef MULTIPROCESSOR
>   if (!db_switch_cpu)
> @@ -1098,78 +1081,6 @@ db_setpcb(addr, have_addr, count, modif)
>   db_printf("PID %ld not found.\n", addr);
>  }
>  
> -static void
> -db_print_trace_entry(te, i)
> - struct traptrace *te;
> - int i;
> -{
> - db_printf("%d:%d p:%d tt:%d:%llx:%llx %llx:%llx ", i,
> -   (int)te->tl, (int)te->pid,
> -   (int)te->tt, (unsigned long long)te->tstate,
> -   (unsigned long long)te->tfault, (unsigned long long)te->tsp,
> -   (unsigned long long)te->tpc);
> - db_printsym((u_long)te->tpc, DB_STGY_PROC, db_printf);
> - db_printf(": ");
> - if ((te->tpc && !(te->tpc&0x3)) &&
> - curproc &&
> - (curproc->p_pid == te->pid)) {
> - db_disasm((u_long)te->tpc, 0);
> - } else db_printf("\n");
> -}
> -
> -void
> -db_traptrace(addr, have_addr, count, modif)
> - db_expr_t addr;
> - int have_addr;
> - db_expr_t count;
> - char *modif;
> -{
> - int i, start = 0, full = 0, reverse = 0;
> - struct traptrace *end;
> -
> - start = 0;
> - end = _trace_end[0];
> -
> - {
> - register char c, *cp = modif;
> - if (modif)
> - while ((c = *cp++) != 0) {
> - if (c == 'f')
> - full = 1;
> - if (c == 'r')
> -

Re: CVS: cvs.openbsd.org: src (fwd)

2016-10-18 Thread Mark Kettenis
> Date: Sun, 16 Oct 2016 13:58:17 -0700
> From: Philip Guenther 
> 
> Should have sent this to tech...

Yes please!  But by terminating the loop early, I you'll miss the case
where the symbol shadows both a function and a global variable.

> -- Forwarded message --
> Date: Sun, 16 Oct 2016 13:57:42 -0700
> From: Philip Guenther 
> To: Jeremie Courreges-Anglas 
> Cc: source-chan...@openbsd.org
> Subject: Re: CVS: cvs.openbsd.org: src
> 
> On Sun, 16 Oct 2016, Jeremie Courreges-Anglas wrote:
> > CVSROOT:/cvs
> > Module name:src
> > Changes by: j...@cvs.openbsd.org2016/10/16 04:40:59
> > 
> > Modified files:
> > usr.sbin/rpc.bootparamd: bootparamd.c 
> > 
> > Log message:
> > Rename local variable 'err' to 'error', to avoid -Wshadow conflicts with 
> > err.h
> 
> Ick.  I know that newer gcc's have stopped generating shadow warning for 
> local variables vs global functions, such as this case.  Making these 
> changes just because we have an old gcc is kinda annoying.
> 
> So let's fix that and make our gcc a bit more like new ones.  Written 
> without peeking at the new ones and tested against the .c file at bottom 
> to verify that it doesn't fail or crash on some weird combo of shadowing.
> 
> oks?
> 
> Philip Guenther
> 
> 
> Index: c-decl.c
> ===
> RCS file: /data/src/openbsd/src/gnu/gcc/gcc/c-decl.c,v
> retrieving revision 1.4
> diff -u -p -r1.4 c-decl.c
> --- c-decl.c  10 Sep 2015 10:56:35 -  1.4
> +++ c-decl.c  16 Oct 2016 20:50:10 -
> @@ -1946,8 +1946,19 @@ warn_if_shadowing (tree new_decl)
> warning (OPT_Wshadow, "declaration of %q+D shadows a parameter",
>  new_decl);
>   else if (DECL_FILE_SCOPE_P (old_decl))
> -   warning (OPT_Wshadow, "declaration of %q+D shadows a global "
> -"declaration", new_decl);
> +   {
> + /* Don't warn about shadowing a global function unless the local
> +variable is a pointer to a function */
> + if (TREE_CODE (old_decl) == FUNCTION_DECL
> + && TREE_CODE (new_decl) != FUNCTION_DECL
> + && (TREE_CODE (new_decl) != VAR_DECL
> + || !POINTER_TYPE_P (TREE_TYPE (new_decl))
> + || TREE_CODE (TREE_TYPE (TREE_TYPE (new_decl)))
> +!= FUNCTION_TYPE))
> +   break;
> + warning (OPT_Wshadow, "declaration of %q+D shadows a global "
> +  "declaration", new_decl);
> +   }
>   else if (TREE_CODE (old_decl) == FUNCTION_DECL
>&& DECL_BUILT_IN (old_decl))
> {
> 
> 
> 
> -- test-shadow.c ---
> int var;
> void func(void);
> void (*func_ptr)(void) = func;
> enum { ENUM };
> typedef int type;
> 
> void
> test_var(int var_arg, void (*func_ptr_arg)(void))
> {
>   int var;
>   int func;
>   int func_ptr;
>   int ENUM;
>   int type;
>   {
>   int var_arg;
>   int func_ptr_arg;
>   }
> }
> 
> void
> test_func_ptr(int var_arg, void (*func_ptr_arg)(void))
> {
>   void (*var)(void);
>   void (*func)(void);
>   void (*func_ptr)(void);
>   void (*ENUM)(void);
>   void (*type)(void);
>   {
>   void (*var_arg)(void);
>   void (*func_ptr_arg)(void);
>   }
> }
> 
> void
> test_int_ptr(int var_arg, void (*func_ptr_arg)(void))
> {
>   int *var;
>   int *func;
>   int *func_ptr;
>   int *ENUM;
>   int *type;
>   {
>   int *var_arg;
>   int *func_ptr_arg;
>   }
> }
> 
> void
> test_enum(int var_arg, void (*func_ptr_arg)(void))
> {
>   enum { var };
>   enum { func };
>   enum { func_ptr };
>   enum { ENUM };
>   enum { type };
>   {
>   enum { var_arg };
>   enum { func_ptr_arg };
>   }
> }
> 
> void
> test_type(int var_arg, void (*func_ptr_arg)(void))
> {
>   typedef int var;
>   typedef int func;
>   typedef int func_ptr;
>   typedef int ENUM;
>   typedef int type;
>   {
>   typedef int var_arg;
>   typedef int func_ptr_arg;
>   }
> }
> 
> void
> test_var_param(
>   int var,
>   int func,
>   int func_ptr,
>   int ENUM,
>   int type)
> {
> }
> 
> void
> test_func_ptr_param(
>   void (*var)(void),
>   void (*func)(void),
>   void (*func_ptr)(void),
>   void (*ENUM)(void),
>   void (*type)(void))
> {
> }
> 
> 



Re: suspend/resume on macbooks

2016-10-18 Thread Mark Kettenis
> Date: Tue, 18 Oct 2016 21:56:13 +0200
> From: Joris Vink 
> 
> Hi,
> 
> Sending this out so others with Macbooks can test this.
> 
> This diff may fix suspend/resume problems seen on certain Macbooks where
> your display goes black but nothing else happens.
> 
> Note that this is babysteps as after resume your system is missing its
> battery, the keyboard backlight needs a kick via wsconsctl and if you
> are in X you may have to switch VT's quickly to get something to
> display.
> 
> But at least you can suspend/resume, maybe.

I think this is a bad choice.  See:

  http://mjg59.dreamwidth.org/29954.html

Does Windows susped/resume successfully on that machine?

> Index: dsdt.c
> ===
> RCS file: /cvs/src/sys/dev/acpi/dsdt.c,v
> retrieving revision 1.225
> diff -u -p -u -p -r1.225 dsdt.c
> --- dsdt.c27 Sep 2016 10:04:19 -  1.225
> +++ dsdt.c18 Oct 2016 19:37:59 -
> @@ -1493,6 +1493,7 @@ char *aml_valid_osi[] = {
>   "Windows 2012",
>   "Windows 2013",
>   "Windows 2015",
> + "Darwin",
>   NULL
>  };
>  
> 
> 



Re: acpiec on acer aspire S7 with CURRENT

2016-10-24 Thread Mark Kettenis
> Date: Mon, 24 Oct 2016 23:01:22 +0300
> From: Paul Irofti <p...@irofti.net>
> 
> On Mon, Oct 24, 2016 at 10:50:00PM +0300, Paul Irofti wrote:
> > On Mon, Oct 24, 2016 at 07:46:33PM +0200, Mark Kettenis wrote:
> > > > From: Paul Irofti <p...@irofti.net>
> > > > Date: Mon, 24 Oct 2016 17:12:01 +0300
> > > > 
> > > > Any thoughts on this?
> > > 
> > > Sorry, yes.  Adding the crs "index" as the last argument of the
> > > callback function seems a bit non-intuitive to me.  I'd say the void *
> > > argument should remain the last argument, and the crs "number" should
> > > be the first, although I could live with it being the second.
> > > 
> > > I feel a bit bad though for not suggesting that earlier.
> > 
> > Sure, makes sense. I thought about doing that too, but I did not know
> > how much breakage I could do to the original function.
> > 
> > What about crsno, do you prefer it to be called crsidx? That might be
> > a better name...

I agree!

> Like this?

Yes, ok kettenis@


> Index: acpi.c
> ===
> RCS file: /cvs/src/sys/dev/acpi/acpi.c,v
> retrieving revision 1.316
> diff -u -p -u -p -r1.316 acpi.c
> --- acpi.c18 Sep 2016 23:56:45 -  1.316
> +++ acpi.c24 Oct 2016 20:00:30 -
> @@ -513,10 +513,10 @@ TAILQ_HEAD(, acpi_pci) acpi_pcirootdevs 
>  TAILQ_HEAD_INITIALIZER(acpi_pcirootdevs);
>  
>  int acpi_getpci(struct aml_node *node, void *arg);
> -int acpi_getminbus(union acpi_resource *crs, void *arg);
> +int acpi_getminbus(int crsidx, union acpi_resource *crs, void *arg);
>  
>  int
> -acpi_getminbus(union acpi_resource *crs, void *arg)
> +acpi_getminbus(int crsidx, union acpi_resource *crs, void *arg)
>  {
>   int *bbn = arg;
>   int typ = AML_CRSTYPE(crs);
> Index: acpiprt.c
> ===
> RCS file: /cvs/src/sys/dev/acpi/acpiprt.c,v
> retrieving revision 1.47
> diff -u -p -u -p -r1.47 acpiprt.c
> --- acpiprt.c 14 Mar 2015 03:38:46 -  1.47
> +++ acpiprt.c 24 Oct 2016 20:00:31 -
> @@ -60,8 +60,8 @@ SIMPLEQ_HEAD(, acpiprt_map) acpiprt_map_
>  
>  int  acpiprt_match(struct device *, void *, void *);
>  void acpiprt_attach(struct device *, struct device *, void *);
> -int  acpiprt_getirq(union acpi_resource *crs, void *arg);
> -int  acpiprt_chooseirq(union acpi_resource *, void *);
> +int  acpiprt_getirq(int, union acpi_resource *, void *);
> +int  acpiprt_chooseirq(int, union acpi_resource *, void *);
>  
>  struct acpiprt_softc {
>   struct device   sc_dev;
> @@ -137,7 +137,7 @@ acpiprt_attach(struct device *parent, st
>  }
>  
>  int
> -acpiprt_getirq(union acpi_resource *crs, void *arg)
> +acpiprt_getirq(int crsidx, union acpi_resource *crs, void *arg)
>  {
>   struct acpiprt_irq *irq = arg;
>   int typ, len;
> @@ -190,7 +190,7 @@ acpiprt_pri[16] = {
>  };
>  
>  int
> -acpiprt_chooseirq(union acpi_resource *crs, void *arg)
> +acpiprt_chooseirq(int crsidx, union acpi_resource *crs, void *arg)
>  {
>   struct acpiprt_irq *irq = arg;
>   int typ, len, i, pri = -1;
> Index: bytgpio.c
> ===
> RCS file: /cvs/src/sys/dev/acpi/bytgpio.c,v
> retrieving revision 1.11
> diff -u -p -u -p -r1.11 bytgpio.c
> --- bytgpio.c 8 May 2016 11:08:01 -   1.11
> +++ bytgpio.c 24 Oct 2016 20:00:31 -
> @@ -104,7 +104,7 @@ const int byt_sus_pins[] = {
>   56, 54, 49, 55, 48, 57, 50, 58, 52, 53, 59, 40
>  };
>  
> -int  bytgpio_parse_resources(union acpi_resource *, void *);
> +int  bytgpio_parse_resources(int, union acpi_resource *, void *);
>  int  bytgpio_read_pin(void *, int);
>  void bytgpio_write_pin(void *, int, int);
>  void bytgpio_intr_establish(void *, int, int, int (*)(), void *);
> @@ -238,7 +238,7 @@ free:
>  }
>  
>  int
> -bytgpio_parse_resources(union acpi_resource *crs, void *arg)
> +bytgpio_parse_resources(int crsidx, union acpi_resource *crs, void *arg)
>  {
>   struct bytgpio_softc *sc = arg;
>   int type = AML_CRSTYPE(crs);
> Index: chvgpio.c
> ===
> RCS file: /cvs/src/sys/dev/acpi/chvgpio.c,v
> retrieving revision 1.5
> diff -u -p -u -p -r1.5 chvgpio.c
> --- chvgpio.c 8 May 2016 18:18:42 -   1.5
> +++ chvgpio.c 24 Oct 2016 20:00:31 -
> @@ -143,7 +143,7 @@ const int chv_southeast_pins[] = {
>   8, 12, 6, 8, 10, 11, -1
>  };
>  
> -int  chvgpio_parse_resources(union acpi_resource *, voi

Re: log mutex

2016-10-20 Thread Mark Kettenis
> Date: Thu, 20 Oct 2016 15:42:32 +0200
> From: Alexander Bluhm 
> 
> Hi,
> 
> A while ago I made kernel logging interrupt safe by adding a
> splhigh().  When we are going MP this is not sufficient, so replace
> it with a mutex.  The idea is to hold the mutex every time msgbufp
> is dereferenced.  This allows to print to dmesg without kernel lock.
> 
> Note that we take the mutex for every character.  That should be
> not performance critical as when you log too much in kernel, you
> have other problems anyway.
> 
> There is still a race with logsoftc.sc_state |= LOG_RDWAIT, but I
> want to address that separately.
> 
> ok?

I don't think putting a lock in msgbuf_putchar us a good idea.  We
deliberately did not put a lock in kprintf() to make sure it can still
be used when we're in ddb without hitting a deadlock.  Instead we put
the lock (kprintf_mutex) in the higher-level functions.

> Index: kern/subr_log.c
> ===
> RCS file: /data/mirror/openbsd/cvs/src/sys/kern/subr_log.c,v
> retrieving revision 1.48
> diff -u -p -u -p -r1.48 subr_log.c
> --- kern/subr_log.c   23 Jun 2016 15:41:42 -  1.48
> +++ kern/subr_log.c   19 Oct 2016 19:07:27 -
> @@ -79,6 +79,7 @@ int msgbufmapped;   /* is the message bu
>  struct   msgbuf *msgbufp;/* the mapped buffer, itself. */
>  struct   msgbuf *consbufp;   /* console message buffer. */
>  struct   file *syslogf;
> +struct mutex log_mtx = MUTEX_INITIALIZER(IPL_HIGH);
>  
>  void filt_logrdetach(struct knote *kn);
>  int filt_logread(struct knote *kn, long hint);
> @@ -140,13 +141,11 @@ initconsbuf(void)
>  void
>  msgbuf_putchar(struct msgbuf *mbp, const char c)
>  {
> - int s;
> -
>   if (mbp->msg_magic != MSG_MAGIC)
>   /* Nothing we can do */
>   return;
>  
> - s = splhigh();
> + mtx_enter(_mtx);
>   mbp->msg_bufc[mbp->msg_bufx++] = c;
>   mbp->msg_bufl = lmin(mbp->msg_bufl+1, mbp->msg_bufs);
>   if (mbp->msg_bufx < 0 || mbp->msg_bufx >= mbp->msg_bufs)
> @@ -157,7 +156,7 @@ msgbuf_putchar(struct msgbuf *mbp, const
>   mbp->msg_bufr = 0;
>   mbp->msg_bufd++;
>   }
> - splx(s);
> + mtx_leave(_mtx);
>  }
>  
>  int
> @@ -186,19 +185,21 @@ logread(dev_t dev, struct uio *uio, int 
>  {
>   struct msgbuf *mbp = msgbufp;
>   size_t l;
> - int s, error = 0;
> + int error = 0;
>  
> - s = splhigh();
> + mtx_enter(_mtx);
>   while (mbp->msg_bufr == mbp->msg_bufx) {
>   if (flag & IO_NDELAY) {
> - error = EWOULDBLOCK;
> - goto out;
> + mtx_leave(_mtx);
> + return (EWOULDBLOCK);
>   }
>   logsoftc.sc_state |= LOG_RDWAIT;
> - error = tsleep(mbp, LOG_RDPRI | PCATCH,
> + error = msleep(mbp, _mtx, LOG_RDPRI | PCATCH,
>  "klog", 0);
> - if (error)
> - goto out;
> + if (error) {
> + mtx_leave(_mtx);
> + return (error);
> + }
>   }
>   logsoftc.sc_state &= ~LOG_RDWAIT;
>  
> @@ -209,13 +210,17 @@ logread(dev_t dev, struct uio *uio, int 
>   "<%d>klog: dropped %ld byte%s, message buffer full\n",
>   LOG_KERN|LOG_WARNING, mbp->msg_bufd,
>  mbp->msg_bufd == 1 ? "" : "s");
> + mtx_leave(_mtx);
>   error = uiomove(buf, ulmin(l, sizeof(buf) - 1), uio);
>   if (error)
> - goto out;
> + return (error);
> + mtx_enter(_mtx);
>   mbp->msg_bufd = 0;
>   }
>  
>   while (uio->uio_resid > 0) {
> + char *buf;
> +
>   if (mbp->msg_bufx >= mbp->msg_bufr)
>   l = mbp->msg_bufx - mbp->msg_bufr;
>   else
> @@ -223,31 +228,34 @@ logread(dev_t dev, struct uio *uio, int 
>   l = ulmin(l, uio->uio_resid);
>   if (l == 0)
>   break;
> - error = uiomove(>msg_bufc[mbp->msg_bufr], l, uio);
> + buf = >msg_bufc[mbp->msg_bufr];
> + mtx_leave(_mtx);
> + error = uiomove(buf, l, uio);
>   if (error)
> - break;
> + return (error);
> + mtx_enter(_mtx);
>   mbp->msg_bufr += l;
>   if (mbp->msg_bufr < 0 || mbp->msg_bufr >= mbp->msg_bufs)
>   mbp->msg_bufr = 0;
>   }
> - out:
> - splx(s);
> + mtx_leave(_mtx);
> +
>   return (error);
>  }
>  
>  int
>  logpoll(dev_t dev, int events, struct proc *p)
>  {
> - int s, revents = 0;
> + int revents = 0;
>  
> - s = splhigh();
> + mtx_enter(_mtx);
>   if (events & (POLLIN | POLLRDNORM)) {
>  

Re: acpiec on acer aspire S7 with CURRENT

2016-10-21 Thread Mark Kettenis
> Date: Fri, 21 Oct 2016 10:37:08 +0300
> From: Paul Irofti 
> 
> On Tue, Oct 18, 2016 at 09:01:59PM -0700, Ilya Kaliman wrote:
> > Thanks! Now everything seems to work. Minor tweak - maybe need extra
> > newline after "acpiec0 at acpi0"
> 
> New diff that fixes the printfs, removes dead code (suggested by
> guenther@) and takes care of some small style(9) nits. OK?

I'm not really happy about the use of the static variable in the
resource parsing function.  It feels like the aml_parse_resource API
should be changed to pass the resource number to the callback
function.

> Index: acpidev.h
> ===
> RCS file: /cvs/src/sys/dev/acpi/acpidev.h,v
> retrieving revision 1.38
> diff -u -p -u -p -r1.38 acpidev.h
> --- acpidev.h 12 Aug 2015 05:59:54 -  1.38
> +++ acpidev.h 21 Oct 2016 07:35:22 -
> @@ -323,10 +323,12 @@ struct acpiec_softc {
>   int sc_ecbusy;
>  
>   /* command/status register */
> + bus_size_t  sc_ec_sc;
>   bus_space_tag_t sc_cmd_bt;
>   bus_space_handle_t  sc_cmd_bh;
>  
>   /* data register */
> + bus_size_t  sc_ec_data;
>   bus_space_tag_t sc_data_bt;
>   bus_space_handle_t  sc_data_bh;
>  
> Index: acpiec.c
> ===
> RCS file: /cvs/src/sys/dev/acpi/acpiec.c,v
> retrieving revision 1.54
> diff -u -p -u -p -r1.54 acpiec.c
> --- acpiec.c  23 Aug 2016 18:26:21 -  1.54
> +++ acpiec.c  21 Oct 2016 07:35:22 -
> @@ -48,7 +48,7 @@ voidacpiec_write(struct acpiec_softc *
>  
>  int  acpiec_getcrs(struct acpiec_softc *,
>   struct acpi_attach_args *);
> -int  acpiec_getregister(const u_int8_t *, int, int *, bus_size_t *);
> +int  acpiec_parse_resources(union acpi_resource *, void *);
>  
>  void acpiec_wait(struct acpiec_softc *, u_int8_t, u_int8_t);
>  void acpiec_sci_event(struct acpiec_softc *);
> @@ -285,15 +285,16 @@ acpiec_attach(struct device *parent, str
>   return;
>   }
>  
> + printf("\n");
>   if (acpiec_getcrs(sc, aa)) {
> - printf(": Failed to read resource settings\n");
> + printf("%s: Failed to read resource settings\n", DEVNAME(sc));
>   return;
>   }
>  
>   sc->sc_acpi->sc_ec = sc;
>  
>   if (acpiec_reg(sc)) {
> - printf(": Failed to register address space\n");
> + printf("%s: Failed to register address space\n", DEVNAME(sc));
>   return;
>   }
>  
> @@ -305,15 +306,13 @@ acpiec_attach(struct device *parent, str
>   acpi_set_gpehandler(sc->sc_acpi, sc->sc_gpe, acpiec_gpehandler,
>   sc, 1);
>  #endif
> - 
> +
>   if (aml_evalname(sc->sc_acpi, sc->sc_devnode, "_GLK", 0, NULL, ))
>   sc->sc_glk = 0;
>   else if (res.type != AML_OBJTYPE_INTEGER)
>   sc->sc_glk = 0;
>   else
>   sc->sc_glk = res.v_integer ? 1 : 0;
> -
> - printf("\n");
>  }
>  
>  void
> @@ -366,68 +365,75 @@ acpiec_gpehandler(struct acpi_softc *acp
>   return (0);
>  }
>  
> -/* parse the resource buffer to get a 'register' value */
>  int
> -acpiec_getregister(const u_int8_t *buf, int size, int *type, bus_size_t 
> *addr)
> +acpiec_parse_resources(union acpi_resource *crs, void *arg)
>  {
> - int len, hlen;
> + struct acpiec_softc *sc = arg;
> + int type = AML_CRSTYPE(crs);
>  
> -#define RES_TYPE_MASK 0x80
> -#define RES_LENGTH_MASK 0x07
> -#define RES_TYPE_IOPORT  0x47
> -#define RES_TYPE_ENDTAG  0x79
> + static int argno = 0;
>  
> - if (size <= 0)
> - return (0);
> -
> - if (*buf & RES_TYPE_MASK) {
> - /* large resource */
> - if (size < 3)
> - return (1);
> - len = (int)buf[1] + 256 * (int)buf[2];
> - hlen = 3;
> - } else {
> - /* small resource */
> - len = buf[0] & RES_LENGTH_MASK;
> - hlen = 1;
> + switch (argno) {
> + case 0:
> + if (type != SR_IOPORT) {
> + printf("%s: Unexpected resource #%d type %d\n",
> + DEVNAME(sc), argno, type);
> + break;
> + }
> + sc->sc_data_bt = sc->sc_acpi->sc_iot;
> + sc->sc_ec_data = crs->sr_ioport._max;
> + break;
> + case 1:
> + if (type != SR_IOPORT) {
> + printf("%s: Unexpected resource #%d type %d\n",
> + DEVNAME(sc), argno, type);
> + break;
> + }
> + sc->sc_cmd_bt = sc->sc_acpi->sc_iot;
> + sc->sc_ec_sc = crs->sr_ioport._max;
> + break;
> + case 2:
> + if (!sc->sc_acpi->sc_hw_reduced) {
> + 

Re: acpiec on acer aspire S7 with CURRENT

2016-10-24 Thread Mark Kettenis
> From: Paul Irofti <p...@irofti.net>
> Date: Mon, 24 Oct 2016 17:12:01 +0300
> 
> Any thoughts on this?

Sorry, yes.  Adding the crs "index" as the last argument of the
callback function seems a bit non-intuitive to me.  I'd say the void *
argument should remain the last argument, and the crs "number" should
be the first, although I could live with it being the second.

I feel a bit bad though for not suggesting that earlier.

> -Mesaj original-
> De la: "Paul Irofti" <p...@irofti.net>
> Trimis: ‎22.‎10.‎2016 15:34
> Către: "Mark Kettenis" <mark.kette...@xs4all.nl>
> Cc: "guent...@gmail.com" <guent...@gmail.com>; "tech@openbsd.org" 
> <tech@openbsd.org>
> Subiect: Re: acpiec on acer aspire S7 with CURRENT
> 
> > I'm not really happy about the use of the static variable in the
> > resource parsing function.  It feels like the aml_parse_resource API
> > should be changed to pass the resource number to the callback
> > function.
> 
> I hated doing that as well, but I was afraid it wouldn't be justified to
> change the prototype and all the callers for this particular use case.
> Glad you suggested it. Here is a diff to add support for that in the
> current code.
> 
> 
> Index: acpi.c
> ===
> RCS file: /cvs/src/sys/dev/acpi/acpi.c,v
> retrieving revision 1.316
> diff -u -p -u -p -r1.316 acpi.c
> --- acpi.c18 Sep 2016 23:56:45 -  1.316
> +++ acpi.c22 Oct 2016 12:29:11 -
> @@ -513,10 +513,10 @@ TAILQ_HEAD(, acpi_pci) acpi_pcirootdevs 
>  TAILQ_HEAD_INITIALIZER(acpi_pcirootdevs);
>  
>  int acpi_getpci(struct aml_node *node, void *arg);
> -int acpi_getminbus(union acpi_resource *crs, void *arg);
> +int acpi_getminbus(union acpi_resource *crs, void *arg, int crsno);
>  
>  int
> -acpi_getminbus(union acpi_resource *crs, void *arg)
> +acpi_getminbus(union acpi_resource *crs, void *arg, int crsno)
>  {
>   int *bbn = arg;
>   int typ = AML_CRSTYPE(crs);
> Index: acpiprt.c
> ===
> RCS file: /cvs/src/sys/dev/acpi/acpiprt.c,v
> retrieving revision 1.47
> diff -u -p -u -p -r1.47 acpiprt.c
> --- acpiprt.c 14 Mar 2015 03:38:46 -  1.47
> +++ acpiprt.c 22 Oct 2016 12:29:11 -
> @@ -60,8 +60,8 @@ SIMPLEQ_HEAD(, acpiprt_map) acpiprt_map_
>  
>  int  acpiprt_match(struct device *, void *, void *);
>  void acpiprt_attach(struct device *, struct device *, void *);
> -int  acpiprt_getirq(union acpi_resource *crs, void *arg);
> -int  acpiprt_chooseirq(union acpi_resource *, void *);
> +int  acpiprt_getirq(union acpi_resource *crs, void *arg, int crsno);
> +int  acpiprt_chooseirq(union acpi_resource *, void *, int);
>  
>  struct acpiprt_softc {
>   struct device   sc_dev;
> @@ -137,7 +137,7 @@ acpiprt_attach(struct device *parent, st
>  }
>  
>  int
> -acpiprt_getirq(union acpi_resource *crs, void *arg)
> +acpiprt_getirq(union acpi_resource *crs, void *arg, int crsno)
>  {
>   struct acpiprt_irq *irq = arg;
>   int typ, len;
> @@ -190,7 +190,7 @@ acpiprt_pri[16] = {
>  };
>  
>  int
> -acpiprt_chooseirq(union acpi_resource *crs, void *arg)
> +acpiprt_chooseirq(union acpi_resource *crs, void *arg, int crsno)
>  {
>   struct acpiprt_irq *irq = arg;
>   int typ, len, i, pri = -1;
> Index: bytgpio.c
> ===
> RCS file: /cvs/src/sys/dev/acpi/bytgpio.c,v
> retrieving revision 1.11
> diff -u -p -u -p -r1.11 bytgpio.c
> --- bytgpio.c 8 May 2016 11:08:01 -   1.11
> +++ bytgpio.c 22 Oct 2016 12:29:11 -
> @@ -104,7 +104,7 @@ const int byt_sus_pins[] = {
>   56, 54, 49, 55, 48, 57, 50, 58, 52, 53, 59, 40
>  };
>  
> -int  bytgpio_parse_resources(union acpi_resource *, void *);
> +int  bytgpio_parse_resources(union acpi_resource *, void *, int crsno);
>  int  bytgpio_read_pin(void *, int);
>  void bytgpio_write_pin(void *, int, int);
>  void bytgpio_intr_establish(void *, int, int, int (*)(), void *);
> @@ -238,7 +238,7 @@ free:
>  }
>  
>  int
> -bytgpio_parse_resources(union acpi_resource *crs, void *arg)
> +bytgpio_parse_resources(union acpi_resource *crs, void *arg, int crsno)
>  {
>   struct bytgpio_softc *sc = arg;
>   int type = AML_CRSTYPE(crs);
> Index: chvgpio.c
> ===
> RCS file: /cvs/src/sys/dev/acpi/chvgpio.c,v
> retrieving revision 1.5
> diff -u -p -u -p -r1.5 chvgpio.c
> --- chvgpio.c 8 May 2016 18:18:42 -   1.5
> +++ chvgpio.c 22 Oct 2

Re: syslog_r() should use strerror_r()

2016-10-19 Thread Mark Kettenis
> From: "Todd C. Miller" 
> Date: Wed, 19 Oct 2016 09:11:36 -0600
> 
> Currently, syslog_r() avoids using strerror() since it is not
> reentrant.  We have a reentrant strerror_r() so let's use it.
> 
> OK?

Perhaps add a comment explicitly stating that OpenBSD's strerror_r()
*is* reentrant?

> Index: lib/libc/gen/syslog_r.c
> ===
> RCS file: /cvs/src/lib/libc/gen/syslog_r.c,v
> retrieving revision 1.15
> diff -u -p -u -r1.15 syslog_r.c
> --- lib/libc/gen/syslog_r.c   27 Mar 2016 16:28:56 -  1.15
> +++ lib/libc/gen/syslog_r.c   19 Oct 2016 15:06:48 -
> @@ -138,17 +138,16 @@ __vsyslog_r(int pri, struct syslog_data 
>   }
>   }
>  
> - /* strerror() is not reentrant */
> -
>   for (t = fmt_cpy, fmt_left = FMT_LEN; (ch = *fmt); ++fmt) {
>   if (ch == '%' && fmt[1] == 'm') {
> + char ebuf[NL_TEXTMAX];
> +
>   ++fmt;
> - if (reentrant) {
> + if (strerror_r(saved_errno, ebuf, sizeof(ebuf)) != 0) {
>   prlen = snprintf(t, fmt_left, "Error %d",
>   saved_errno); 
>   } else {
> - prlen = snprintf(t, fmt_left, "%s",
> - strerror(saved_errno)); 
> + prlen = snprintf(t, fmt_left, "%s", ebuf);
>   }
>   if (prlen < 0)
>   prlen = 0;
> 
> 



Re: Fix loadavg(3)

2016-11-14 Thread Mark Kettenis
> Date: Mon, 14 Nov 2016 13:11:58 +0100
> From: Martin Pieuchot 
> 
> On 12/11/16(Sat) 15:52, patrick keshishian wrote:
> > Ahh... seems the culprit is softclock_thread added 2016/09/22
> > (kern/kern_timeout.c mpi@).
> 
> I'd suggest we simply skip kernel thread when calculating the load.

Hmm, I'd say that counting runnable kernel threads towards the load is
the right thing to do.

> Since we're slowly moving code executed in software interrupt
> context to kernel threads this will keep the original behavior.

A different way of viewing is that this move now enables us to
properly take into account the work done by the network stack.


> Index: uvm/uvm_meter.c
> ===
> RCS file: /cvs/src/sys/uvm/uvm_meter.c,v
> retrieving revision 1.36
> diff -u -p -r1.36 uvm_meter.c
> --- uvm/uvm_meter.c   14 Mar 2015 03:38:53 -  1.36
> +++ uvm/uvm_meter.c   14 Nov 2016 12:08:11 -
> @@ -107,6 +107,9 @@ uvm_loadav(struct loadavg *avg)
>   memset(nrun_cpu, 0, sizeof(nrun_cpu));
>  
>   LIST_FOREACH(p, , p_list) {
> + if (p->p_flag & P_SYSTEM)
> + continue;
> +
>   switch (p->p_stat) {
>   case SSLEEP:
>   if (p->p_priority > PZERO || p->p_slptime > 1)
> @@ -114,8 +117,6 @@ uvm_loadav(struct loadavg *avg)
>   /* FALLTHROUGH */
>   case SRUN:
>   case SONPROC:
> - if (p == p->p_cpu->ci_schedstate.spc_idleproc)
> - continue;
>   case SIDL:
>   nrun++;
>   if (p->p_cpu)
> @@ -136,7 +137,7 @@ uvm_loadav(struct loadavg *avg)
>   spc->spc_ldavg = (cexp[0] * spc->spc_ldavg +
>   nrun_cpu[CPU_INFO_UNIT(ci)] * FSCALE *
>   (FSCALE - cexp[0])) >> FSHIFT;
> - }   
> + }
>  }
>  
>  /*
> 
> 



Re: umb: NCM datagram pointer entries

2016-11-14 Thread Mark Kettenis
> Date: Mon, 14 Nov 2016 10:51:03 +0100
> From: Gerhard Roth 
> 
> Hi,
> 
> according to the NCM spec, the list of datagram pointer entries has to
> be terminated with an entry where wDatagramIndex and wDatagramLen are
> zero. Not all implementations seem to follow that rule: otto@ had one
> that only sets the index to zero while using an arbitrary length value.
> 
> The patch below fixes the parsing to stop if any of those values is
> zero. It was successfully tested by otto@

Looks reasonable to me; ok kettenis@

> Index: if_umb.c
> ===
> RCS file: /cvs/src/sys/dev/usb/if_umb.c,v
> retrieving revision 1.5
> diff -u -p -u -p -r1.5 if_umb.c
> --- if_umb.c  10 Nov 2016 14:45:43 -  1.5
> +++ if_umb.c  14 Nov 2016 09:34:29 -
> @@ -1815,7 +1815,7 @@ umb_decap(struct umb_softc *sc, struct u
>   }
>  
>   /* Terminating zero entry */
> - if (dlen == 0 && doff == 0)
> + if (dlen == 0 || doff == 0)
>   break;
>   if (len < dlen + doff) {
>   /* Skip giant datagram but continue processing */
> 
> 



Re: use DRM_IOCTL_GET_PCIINFO in libdrm

2016-11-23 Thread Mark Kettenis
> Date: Wed, 23 Nov 2016 11:50:49 +1100
> From: Jonathan Gray <j...@jsg.id.au>
> 
> On Tue, Nov 22, 2016 at 09:29:03PM +0100, Mark Kettenis wrote:
> > > Date: Sat, 19 Nov 2016 19:31:18 +1100
> > > From: Jonathan Gray <j...@jsg.id.au>
> > > 
> > > Support libdrm functions required for Mesa versions >= 13.
> > > 
> > > On linux this information is pulled out of a psuedo filesystem, here the
> > > new DRM_IOCTL_GET_PCIINFO ioctl is used for the same.
> > > 
> > > Only primary drm nodes are handled, render and control nodes which we
> > > don't have aren't.  This also only handles devices with PCI ids.
> > > 
> > > drmGetMinorNameForFD() based on code the Mesa loader used to have.
> > 
> > See my reply to the kernel diff.  One nit...
> > 
> > > diff --git xf86drm.c xf86drm.c
> > > index 3c2c5d4..03fe257 100644
> > > --- xf86drm.c
> > > +++ xf86drm.c
> > > @@ -62,6 +62,10 @@
> > >  #endif
> > >  #include 
> > >  
> > > +#ifdef __OpenBSD__
> > > +#include 
> > > +#endif
> > > +
> > >  /* Not all systems have MAP_FAILED defined */
> > >  #ifndef MAP_FAILED
> > >  #define MAP_FAILED ((void *)-1)
> > > @@ -2851,7 +2855,25 @@ static char *drmGetMinorNameForFD(int fd, int type)
> > >  out_close_dir:
> > >  closedir(sysdir);
> > >  #else
> > > -#warning "Missing implementation of drmGetMinorNameForFD"
> > > +struct stat sbuf;
> > > +unsigned int maj, min;
> > > +char buf[0x40];
> > 
> > Any reason not to use PATH_MAX + 1 here?
> 
> This was carried over from the old Mesa loader code, updated diff to
> use PATH_MAX and inline ioctl definition:

ok kettenis@

> diff --git xf86drm.c xf86drm.c
> index 3c2c5d4..38f6440 100644
> --- xf86drm.c
> +++ xf86drm.c
> @@ -103,7 +103,23 @@
>  #endif
>  
>  #ifdef __OpenBSD__
> +
>  #define X_PRIVSEP
> +
> +struct drm_pciinfo {
> + uint16_tdomain;
> + uint8_t bus;
> + uint8_t dev;
> + uint8_t func;
> + uint16_tvendor_id;
> + uint16_tdevice_id;
> + uint16_tsubvendor_id;
> + uint16_tsubdevice_id;
> + uint8_t revision_id;
> +};
> +
> +#define DRM_IOCTL_GET_PCIINFODRM_IOR(0x15, struct drm_pciinfo)
> +
>  #endif
>  
>  #define DRM_MSG_VERBOSITY 3
> @@ -2851,7 +2867,25 @@ static char *drmGetMinorNameForFD(int fd, int type)
>  out_close_dir:
>  closedir(sysdir);
>  #else
> -#warning "Missing implementation of drmGetMinorNameForFD"
> +struct stat sbuf;
> +unsigned int maj, min;
> +char buf[PATH_MAX + 1];
> +int n;
> +
> +if (fstat(fd, ))
> +return NULL;
> +
> +maj = major(sbuf.st_rdev);
> +min = minor(sbuf.st_rdev);
> +
> +if (maj != DRM_MAJOR || !S_ISCHR(sbuf.st_mode))
> +return NULL;
> +
> +n = snprintf(buf, sizeof(buf), DRM_DEV_NAME, DRM_DIR_NAME, min);
> +if (n == -1 || n >= sizeof(buf))
> +return NULL;
> +
> +return strdup(buf);
>  #endif
>  return NULL;
>  }
> @@ -2887,6 +2921,8 @@ static int drmParseSubsystemType(int maj, int min)
>  return DRM_BUS_PCI;
>  
>  return -EINVAL;
> +#elif defined(__OpenBSD__)
> + return DRM_BUS_PCI;
>  #else
>  #warning "Missing implementation of drmParseSubsystemType"
>  return -EINVAL;
> @@ -2929,6 +2965,26 @@ static int drmParsePciBusInfo(int maj, int min, 
> drmPciBusInfoPtr info)
>  info->func = func;
>  
>  return 0;
> +#elif defined(__OpenBSD__)
> +struct drm_pciinfo pinfo;
> +int fd;
> +
> +fd = drmOpenMinor(min, 0, DRM_NODE_PRIMARY);
> +if (fd < 0)
> +return -errno;
> +
> +if (drmIoctl(fd, DRM_IOCTL_GET_PCIINFO, )) {
> +close(fd);
> +return -errno;
> +}
> +close(fd);
> +
> +info->domain = pinfo.domain;
> +info->bus = pinfo.bus;
> +info->dev = pinfo.dev;
> +info->func = pinfo.func;
> +
> +return 0;
>  #else
>  #warning "Missing implementation of drmParsePciBusInfo"
>  return -EINVAL;
> @@ -3004,6 +3060,37 @@ static int drmParsePciDeviceInfo(const char *d_name,
>  device->subdevice_id = config[46] | (config[47] << 8);
>  
>  return 0;
> +#elif defined(__OpenBSD__)
> +struct drm_pciinfo pinfo;
> +char buf[PATH_MAX + 1];
> +int fd, n;
> +
> +n = snprintf(buf, sizeof(buf), &

Re: add a new DRM_IOCTL_GET_PCIINFO ioctl

2016-11-23 Thread Mark Kettenis
> Date: Wed, 23 Nov 2016 11:46:41 +1100
> From: Jonathan Gray <j...@jsg.id.au>
> 
> On Tue, Nov 22, 2016 at 09:26:21PM +0100, Mark Kettenis wrote:
> > > Date: Sat, 19 Nov 2016 19:27:25 +1100
> > > From: Jonathan Gray <j...@jsg.id.au>
> > > 
> > > To pull pci information from the kernel for drm devices we need a common
> > > drm ioctl.  This is a requirement for implementing functions in libdrm
> > > which are used by Mesa >= 13.
> > > 
> > > To not clash with drm headers this is added via pciio.h at kettenis'
> > > suggestion.
> > > 
> > > The ioctl number reuses that of DRM_IOCTL_ADD_MAP, a DRI1 ioctl
> > > we dropped support for, to avoid using a number that might be later
> > > used in linux.
> > 
> > Sorry for dropping the ball on this.  My original thought was that we
> > would have a 'p' ioctl instead of a 'd' ioctl with a name that is more
> > in line with the existing ioctls in .  Having a #define
> > for DRM_IOCTL_GET_PCIINFO in  feels wrong.
> > 
> > Looking at your diffs, I wonder if we shouldn't just add the
> > DRM_IOCTL_GET_PCIINFO define to  for the kernel,
> > and put a copy (protectected by #ifdef __OpenBSD__) in
> > libdrm/xf86drm.c.
> 
> Sure, updated diff

ok kettenis@

> Index: drm.h
> ===
> RCS file: /cvs/src/sys/dev/pci/drm/drm.h,v
> retrieving revision 1.20
> diff -u -p -r1.20 drm.h
> --- drm.h 23 Sep 2015 23:12:11 -  1.20
> +++ drm.h 23 Nov 2016 00:30:50 -
> @@ -706,6 +706,20 @@ struct drm_event_vblank {
>   u_int32_treserved;
>  };
>  
> +#ifdef __OpenBSD__
> +struct drm_pciinfo {
> + uint16_tdomain;
> + uint8_t bus;
> + uint8_t dev;
> + uint8_t func;
> + uint16_tvendor_id;
> + uint16_tdevice_id;
> + uint16_tsubvendor_id;
> + uint16_tsubdevice_id;
> + uint8_t revision_id;
> +};
> +#endif
> +
>  #include "drm_mode.h"
>  
>  #define DRM_IOCTL_BASE   'd'
> @@ -734,7 +748,11 @@ struct drm_event_vblank {
>  #define DRM_IOCTL_BLOCK  DRM_IOWR(0x12, struct drm_block)
>  #define DRM_IOCTL_UNBLOCKDRM_IOWR(0x13, struct drm_block)
>  #define DRM_IOCTL_CONTROLDRM_IOW( 0x14, struct drm_control)
> +#ifdef __OpenBSD__
> +#define DRM_IOCTL_GET_PCIINFODRM_IOR( 0x15, struct 
> drm_pciinfo)
> +#else
>  #define DRM_IOCTL_ADD_MAPDRM_IOWR(0x15, struct drm_map)
> +#endif
>  #define DRM_IOCTL_ADD_BUFS   DRM_IOWR(0x16, struct drm_buf_desc)
>  #define DRM_IOCTL_MARK_BUFS  DRM_IOW( 0x17, struct drm_buf_desc)
>  #define DRM_IOCTL_INFO_BUFS  DRM_IOWR(0x18, struct drm_buf_info)
> Index: drm_drv.c
> ===
> RCS file: /cvs/src/sys/dev/pci/drm/drm_drv.c,v
> retrieving revision 1.149
> diff -u -p -r1.149 drm_drv.c
> --- drm_drv.c 15 Sep 2016 02:00:17 -  1.149
> +++ drm_drv.c 23 Nov 2016 00:30:51 -
> @@ -81,6 +81,7 @@ int  drm_version(struct drm_device *, vo
>  int   drm_setversion(struct drm_device *, void *, struct drm_file *);
>  int   drm_getmagic(struct drm_device *, void *, struct drm_file *);
>  int   drm_authmagic(struct drm_device *, void *, struct drm_file *);
> +int   drm_getpciinfo(struct drm_device *, void *, struct drm_file *);
>  int   drm_file_cmp(struct drm_file *, struct drm_file *);
>  SPLAY_PROTOTYPE(drm_file_tree, drm_file, link, drm_file_cmp);
>  
> @@ -120,6 +121,8 @@ static struct drm_ioctl_desc drm_ioctls[
>   DRM_IOCTL_DEF(DRM_IOCTL_SET_SAREA_CTX, drm_setsareactx, 
> DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
>   DRM_IOCTL_DEF(DRM_IOCTL_GET_SAREA_CTX, drm_getsareactx, DRM_AUTH),
>  #else
> + DRM_IOCTL_DEF(DRM_IOCTL_GET_PCIINFO, drm_getpciinfo, 
> DRM_UNLOCKED|DRM_RENDER_ALLOW),
> +
>   DRM_IOCTL_DEF(DRM_IOCTL_SET_SAREA_CTX, drm_noop, 
> DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
>   DRM_IOCTL_DEF(DRM_IOCTL_GET_SAREA_CTX, drm_noop, DRM_AUTH),
>  #endif
> @@ -1345,5 +1348,23 @@ int drm_pcie_get_speed_cap_mask(struct d
>  
>   DRM_INFO("probing gen 2 caps for device 0x%04x:0x%04x = %x/%x\n",
>   PCI_VENDOR(id), PCI_PRODUCT(id), lnkcap, lnkcap2);
> + return 0;
> +}
> +
> +int
> +drm_getpciinfo(struct drm_device *dev, void *data, struct drm_file 
> *file_priv)
> +{
> + struct drm_pciinfo *info = data;
> +
> + info->domain = 0;
> + info->bus = dev->pdev->bus->number;
> + info->dev = PCI_SLOT(dev->pdev->devfn);
> + info->func = PCI_FUNC(dev->pdev->devfn);
> + info->vendor_id = dev->pdev->vendor;
> + info->device_id = dev->pdev->device;
> + info->subvendor_id = dev->pdev->subsystem_vendor;
> + info->subdevice_id = dev->pdev->subsystem_device;
> + info->revision_id = 0;
> +
>   return 0;
>  }
> 



Re: UEFI install fails on Hetzner EX51

2016-11-23 Thread Mark Kettenis
> From: Leo Unglaub 
> Date: Wed, 23 Nov 2016 12:20:24 +0100
> 
> Hey friends,
> first of all i am sorry if this is not for tech@ and more for bugs@ but 
> to me it seams like a tech@ issue.
> 
> I am trying to install OpenBSD on a Hetzner EX51 server. The specs can 
> be found here: https://www.hetzner.de/us/hosting/produkte_rootserver/ex51
> 
> In order to use the entire 4 TB drives i wanted to use a
> 
> UEFI -> GPT -> softraid0 (RAID 1) -> 2 x 4 TB drives.
> 
> Booting the UEFI version of the install.fs works fine and also the 
> install works but i am unable to boot the server. According the the 
> datacenter this happens because OpenBSD does not write an entry in the 
> mainboards firmware UEFI bootlist and simply asumes a fallback to 
> /boot/bootx64.efi. But according to the datacenter this mainboard does 
> not have that fallback and simply does not know what to boot.

That sounds correct.

> So maybe it would be a good idea to write an entry in the UEFI bootmenu.
> I would love to provide a dmesg but sadly this is very dificult to get 
> from this crappy remote vnc console i have to use to install stuff on 
> the server. But i am working on getting a dmesg to you guys.

Unfortunately writing such an entry isn't trivial.  To do this from
within the installer, we'll need to write code to call the UEFI
runtime services from the OpenBSD kernel.

Cheers,

Mark



Re: UEFI install fails on Hetzner EX51

2016-11-23 Thread Mark Kettenis
> Date: Wed, 23 Nov 2016 08:50:25 -0500
> From: Jiri B <ji...@devio.us>
> 
> On Wed, Nov 23, 2016 at 01:55:59PM +0100, Leo Unglaub wrote:
> > Hey,
> > 
> > On 11/23/16 13:27, Mark Kettenis wrote:
> > >>> Booting the UEFI version of the install.fs works fine and also the
> > >>> install works but i am unable to boot the server. According the the
> > >>> datacenter this happens because OpenBSD does not write an entry in the
> > >>> mainboards firmware UEFI bootlist and simply asumes a fallback to
> > >>> /boot/bootx64.efi. But according to the datacenter this mainboard does
> > >>> not have that fallback and simply does not know what to boot.
> > >That sounds correct.
> 
> So probably something like this?
> 
> efibootmgr --create --disk /dev/$disk --part 1 --label "OpenBSD (${disk})" 
> --load "\\EFI\\openbsd\\BOOTX64.EFI"

Right, something like that would work if you copy the OpenBSD EFI
bootloader into /EFI/OpenBSD/BOOTX64.EFI on the EFI system partition
first.



Re: only free pool pages from the gc task

2016-11-22 Thread Mark Kettenis
> Date: Tue, 22 Nov 2016 12:45:44 +1000
> From: David Gwynne 
> 
> at the moment pages can be freed on a pool_put call and from the gc.
> 
> it is a bit unfair that pool_get may end up doing the heavy lifting
> of allocating a pool page and pool_put wont have to do an equivalent
> free, but we should try and minimise the amount of work done in
> these hot paths.
> 
> ok?

A potentially serious downside of this approach is that this makes us
rely on a thread to run in order to free up memory.  That may be ok
now that most of the network stack runs out of a thread.  But I'm not
confident (yet) that this is safe.

Best not to pile this immediately onto the other pool changes.

> Index: subr_pool.c
> ===
> RCS file: /cvs/src/sys/kern/subr_pool.c,v
> retrieving revision 1.204
> diff -u -p -r1.204 subr_pool.c
> --- subr_pool.c   21 Nov 2016 01:44:06 -  1.204
> +++ subr_pool.c   22 Nov 2016 02:43:23 -
> @@ -707,7 +707,7 @@ void
>  pool_put(struct pool *pp, void *v)
>  {
>   struct pool_item *pi = v;
> - struct pool_page_header *ph, *freeph = NULL;
> + struct pool_page_header *ph;
>  
>  #ifdef DIAGNOSTIC
>   if (v == NULL)
> @@ -770,17 +770,7 @@ pool_put(struct pool *pp, void *v)
>   pp->pr_nout--;
>   pp->pr_nput++;
>  
> - /* is it time to free a page? */
> - if (pp->pr_nidle > pp->pr_maxpages &&
> - (ph = TAILQ_FIRST(>pr_emptypages)) != NULL &&
> - (ticks - ph->ph_tick) > (hz * pool_wait_free)) {
> - freeph = ph;
> - pool_p_remove(pp, freeph);
> - }
>   mtx_leave(>pr_mtx);
> -
> - if (freeph != NULL)
> - pool_p_free(pp, freeph);
>  
>   if (!TAILQ_EMPTY(>pr_requests)) {
>   mtx_enter(>pr_requests_mtx);
> 
> 



Re: global mbuf memory limit

2016-11-22 Thread Mark Kettenis
> Date: Tue, 22 Nov 2016 12:42:39 +1000
> From: David Gwynne 
> 
> right now pools that make up mbufs are each limited individually.
> 
> the following diff instead has the mbuf layer have a global limit
> on the amount of memory that can be allocated to the pools. this
> is enforced by wrapping the multi page pool allocator with something
> that checks the mbuf memory limit first.
> 
> this means all mbufs will use a max of 2k * nmbclust bytes instead
> of each pool being able to use that amount each.
> 
> ok?

Mostly makes sense to me.  Not sure the complixty of copying the
supported page sizes from the multi-page pool allocator is worth the
additional complication.  I'd probably just initialize it the same way
using POOL_ALLOC_SIZES(PAGE_SIZE, 1UL<<31, POOL_ALLOC_ALIGNED).

Wouldn't it make sense to use atomic operations to keep track of the
amount of memory that was allocated?

Long run I suppose we want to drop nmbclust and let users tune the
total amount of memory available for clusters and set the initial
amount to a percentage of physical memory?


> Index: sys/pool.h
> ===
> RCS file: /cvs/src/sys/sys/pool.h,v
> retrieving revision 1.68
> diff -u -p -r1.68 pool.h
> --- sys/pool.h21 Nov 2016 01:44:06 -  1.68
> +++ sys/pool.h22 Nov 2016 02:31:47 -
> @@ -205,6 +205,7 @@ struct pool {
>  #ifdef _KERNEL
>  
>  extern struct pool_allocator pool_allocator_single;
> +extern struct pool_allocator pool_allocator_multi;
>  
>  struct pool_request {
>   TAILQ_ENTRY(pool_request) pr_entry;
> Index: sys/mbuf.h
> ===
> RCS file: /cvs/src/sys/sys/mbuf.h,v
> retrieving revision 1.222
> diff -u -p -r1.222 mbuf.h
> --- sys/mbuf.h24 Oct 2016 04:38:44 -  1.222
> +++ sys/mbuf.h22 Nov 2016 02:31:47 -
> @@ -416,6 +416,7 @@ struct mbuf_queue {
>  };
>  
>  #ifdef   _KERNEL
> +struct pool;
>  
>  extern   int nmbclust;   /* limit on the # of clusters */
>  extern   int mblowat;/* mbuf low water mark */
> @@ -444,6 +445,7 @@ int   m_leadingspace(struct mbuf *);
>  int  m_trailingspace(struct mbuf *);
>  struct mbuf *m_clget(struct mbuf *, int, u_int);
>  void m_extref(struct mbuf *, struct mbuf *);
> +void m_pool_init(struct pool *, u_int, u_int, const char *);
>  void m_extfree_pool(caddr_t, u_int, void *);
>  void m_adj(struct mbuf *, int);
>  int  m_copyback(struct mbuf *, int, int, const void *, int);
> Index: kern/uipc_mbuf.c
> ===
> RCS file: /cvs/src/sys/kern/uipc_mbuf.c,v
> retrieving revision 1.238
> diff -u -p -r1.238 uipc_mbuf.c
> --- kern/uipc_mbuf.c  9 Nov 2016 08:55:11 -   1.238
> +++ kern/uipc_mbuf.c  22 Nov 2016 02:31:47 -
> @@ -133,6 +133,19 @@ void m_extfree(struct mbuf *);
>  void nmbclust_update(void);
>  void m_zero(struct mbuf *);
>  
> +struct mutex m_pool_mtx = MUTEX_INITIALIZER(IPL_NET);
> +unsigned int mbuf_mem_limit; /* how much memory can we allocated */
> +unsigned int mbuf_mem_alloc; /* how much memory has been allocated */
> +
> +void *m_pool_alloc(struct pool *, int, int *);
> +void m_pool_free(struct pool *, void *);
> +
> +struct pool_allocator m_pool_allocator = {
> + m_pool_alloc,
> + m_pool_free,
> + 0 /* will be copied from pool_allocator_multi */
> +};
> +
>  static void (*mextfree_fns[4])(caddr_t, u_int, void *);
>  static u_int num_extfree_fns;
>  
> @@ -148,6 +161,11 @@ mbinit(void)
>   int i;
>   unsigned int lowbits;
>  
> + m_pool_allocator.pa_pagesz = pool_allocator_multi.pa_pagesz;
> +
> + nmbclust_update();
> + mbuf_mem_alloc = 0;
> +
>  #if DIAGNOSTIC
>   if (mclsizes[0] != MCLBYTES)
>   panic("mbinit: the smallest cluster size != MCLBYTES");
> @@ -155,9 +173,7 @@ mbinit(void)
>   panic("mbinit: the largest cluster size != MAXMCLBYTES");
>  #endif
>  
> - pool_init(, MSIZE, 0, IPL_NET, 0, "mbufpl", NULL);
> - pool_set_constraints(, _dma_contig);
> - pool_setlowat(, mblowat);
> + m_pool_init(, MSIZE, 64, "mbufpl");
>  
>   pool_init(, PACKET_TAG_MAXSIZE + sizeof(struct m_tag), 0,
>   IPL_NET, 0, "mtagpl", NULL);
> @@ -171,47 +187,32 @@ mbinit(void)
>   snprintf(mclnames[i], sizeof(mclnames[0]), "mcl%dk",
>   mclsizes[i] >> 10);
>   }
> - pool_init([i], mclsizes[i], 64, IPL_NET, 0,
> - mclnames[i], NULL);
> - pool_set_constraints([i], _dma_contig);
> - pool_setlowat([i], mcllowat);
> +
> + m_pool_init([i], mclsizes[i], 64, mclnames[i]);
>   }
>  
>   (void)mextfree_register(m_extfree_pool);
>   KASSERT(num_extfree_fns == 1);
> -
> - nmbclust_update();
>  }
>  
>  void
>  mbcpuinit()
>  {
> + int i;
> +
>   mbstat = 

Re: add a new DRM_IOCTL_GET_PCIINFO ioctl

2016-11-22 Thread Mark Kettenis
> Date: Sat, 19 Nov 2016 19:27:25 +1100
> From: Jonathan Gray 
> 
> To pull pci information from the kernel for drm devices we need a common
> drm ioctl.  This is a requirement for implementing functions in libdrm
> which are used by Mesa >= 13.
> 
> To not clash with drm headers this is added via pciio.h at kettenis'
> suggestion.
> 
> The ioctl number reuses that of DRM_IOCTL_ADD_MAP, a DRI1 ioctl
> we dropped support for, to avoid using a number that might be later
> used in linux.

Sorry for dropping the ball on this.  My original thought was that we
would have a 'p' ioctl instead of a 'd' ioctl with a name that is more
in line with the existing ioctls in .  Having a #define
for DRM_IOCTL_GET_PCIINFO in  feels wrong.

Looking at your diffs, I wonder if we shouldn't just add the
DRM_IOCTL_GET_PCIINFO define to  for the kernel,
and put a copy (protectected by #ifdef __OpenBSD__) in
libdrm/xf86drm.c.

The implementation looks good, but...

> Index: dev/pci/drm/drm_drv.c
> ===
> RCS file: /cvs/src/sys/dev/pci/drm/drm_drv.c,v
> retrieving revision 1.149
> diff -u -p -r1.149 drm_drv.c
> --- dev/pci/drm/drm_drv.c 15 Sep 2016 02:00:17 -  1.149
> +++ dev/pci/drm/drm_drv.c 19 Nov 2016 07:12:06 -
> @@ -50,6 +50,7 @@
>  #include 
>  #include  /* for TIOCSGRP */
>  #include 
> +#include  /* for DRM_IOCTL_GET_PCIINFO */
>  
>  #include 
>  #include 
> @@ -81,6 +82,7 @@ int  drm_version(struct drm_device *, vo
>  int   drm_setversion(struct drm_device *, void *, struct drm_file *);
>  int   drm_getmagic(struct drm_device *, void *, struct drm_file *);
>  int   drm_authmagic(struct drm_device *, void *, struct drm_file *);
> +int   drm_getpciinfo(struct drm_device *, void *, struct drm_file *);
>  int   drm_file_cmp(struct drm_file *, struct drm_file *);
>  SPLAY_PROTOTYPE(drm_file_tree, drm_file, link, drm_file_cmp);
>  
> @@ -120,6 +122,8 @@ static struct drm_ioctl_desc drm_ioctls[
>   DRM_IOCTL_DEF(DRM_IOCTL_SET_SAREA_CTX, drm_setsareactx, 
> DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
>   DRM_IOCTL_DEF(DRM_IOCTL_GET_SAREA_CTX, drm_getsareactx, DRM_AUTH),
>  #else
> + DRM_IOCTL_DEF(DRM_IOCTL_GET_PCIINFO, drm_getpciinfo, 0),
> +
>   DRM_IOCTL_DEF(DRM_IOCTL_SET_SAREA_CTX, drm_noop, 
> DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
>   DRM_IOCTL_DEF(DRM_IOCTL_GET_SAREA_CTX, drm_noop, DRM_AUTH),
>  #endif
> @@ -254,11 +258,12 @@ pledge_ioctl_drm(struct proc *p, long co
>   if (ioctl->flags & DRM_RENDER_ALLOW)
>   return 0;
>  
> + switch (com) {
> + case DRM_IOCTL_GET_PCIINFO:

...I think we should just mark DRM_IOCTL_GET_PCIINFO as DRM_RENDER_ALLOW.

>   /*
>* These are dangerous, but we have to allow them until we
>* have prime/dma-buf support.
>*/
> - switch (com) {
>   case DRM_IOCTL_GET_MAGIC:
>   case DRM_IOCTL_GEM_OPEN:
>   return 0;
> @@ -1345,5 +1350,23 @@ int drm_pcie_get_speed_cap_mask(struct d
>  
>   DRM_INFO("probing gen 2 caps for device 0x%04x:0x%04x = %x/%x\n",
>   PCI_VENDOR(id), PCI_PRODUCT(id), lnkcap, lnkcap2);
> + return 0;
> +}
> +
> +int
> +drm_getpciinfo(struct drm_device *dev, void *data, struct drm_file 
> *file_priv)
> +{
> + struct drm_pciinfo *info = data;
> +
> + info->domain = 0;
> + info->bus = dev->pdev->bus->number;
> + info->dev = PCI_SLOT(dev->pdev->devfn);
> + info->func = PCI_FUNC(dev->pdev->devfn);
> + info->vendor_id = dev->pdev->vendor;
> + info->device_id = dev->pdev->device;
> + info->subvendor_id = dev->pdev->subsystem_vendor;
> + info->subdevice_id = dev->pdev->subsystem_device;
> + info->revision_id = 0;
> +
>   return 0;
>  }
> Index: sys/pciio.h
> ===
> RCS file: /cvs/src/sys/sys/pciio.h,v
> retrieving revision 1.7
> diff -u -p -r1.7 pciio.h
> --- sys/pciio.h   5 Sep 2010 18:14:33 -   1.7
> +++ sys/pciio.h   19 Nov 2016 07:12:06 -
> @@ -60,6 +60,18 @@ struct pci_vga {
>   int pv_decode;
>  };
>  
> +struct drm_pciinfo {
> + uint16_tdomain;
> + uint8_t bus;
> + uint8_t dev;
> + uint8_t func;
> + uint16_tvendor_id;
> + uint16_tdevice_id;
> + uint16_tsubvendor_id;
> + uint16_tsubdevice_id;
> + uint8_t revision_id;
> +};
> +
>  #define  PCI_VGA_UNLOCK  0x00
>  #define  PCI_VGA_LOCK0x01
>  #define  PCI_VGA_TRYLOCK 0x02
> @@ -74,5 +86,7 @@ struct pci_vga {
>  #define  PCIOCGETVGA _IOWR('p', 6, struct pci_vga)
>  #define  PCIOCSETVGA _IOWR('p', 7, struct pci_vga)
>  #define  PCIOCREADMASK   _IOWR('p', 8, struct pci_io)
> +
> +#define  DRM_IOCTL_GET_PCIINFO   _IOR('d', 0x15, struct drm_pciinfo)
>  
>  #endif /* !_SYS_PCIIO_H_ */
> 
> 



Re: use DRM_IOCTL_GET_PCIINFO in libdrm

2016-11-22 Thread Mark Kettenis
> Date: Sat, 19 Nov 2016 19:31:18 +1100
> From: Jonathan Gray 
> 
> Support libdrm functions required for Mesa versions >= 13.
> 
> On linux this information is pulled out of a psuedo filesystem, here the
> new DRM_IOCTL_GET_PCIINFO ioctl is used for the same.
> 
> Only primary drm nodes are handled, render and control nodes which we
> don't have aren't.  This also only handles devices with PCI ids.
> 
> drmGetMinorNameForFD() based on code the Mesa loader used to have.

See my reply to the kernel diff.  One nit...

> diff --git xf86drm.c xf86drm.c
> index 3c2c5d4..03fe257 100644
> --- xf86drm.c
> +++ xf86drm.c
> @@ -62,6 +62,10 @@
>  #endif
>  #include 
>  
> +#ifdef __OpenBSD__
> +#include 
> +#endif
> +
>  /* Not all systems have MAP_FAILED defined */
>  #ifndef MAP_FAILED
>  #define MAP_FAILED ((void *)-1)
> @@ -2851,7 +2855,25 @@ static char *drmGetMinorNameForFD(int fd, int type)
>  out_close_dir:
>  closedir(sysdir);
>  #else
> -#warning "Missing implementation of drmGetMinorNameForFD"
> +struct stat sbuf;
> +unsigned int maj, min;
> +char buf[0x40];

Any reason not to use PATH_MAX + 1 here?

> +int n;
> +
> +if (fstat(fd, ))
> +return NULL;
> +
> +maj = major(sbuf.st_rdev);
> +min = minor(sbuf.st_rdev);
> +
> +if (maj != DRM_MAJOR || !S_ISCHR(sbuf.st_mode))
> +return NULL;
> +
> +n = snprintf(buf, sizeof(buf), DRM_DEV_NAME, DRM_DIR_NAME, min);
> +if (n == -1 || n >= sizeof(buf))
> +return NULL;
> +
> +return strdup(buf);
>  #endif
>  return NULL;
>  }
> @@ -2887,6 +2909,8 @@ static int drmParseSubsystemType(int maj, int min)
>  return DRM_BUS_PCI;
>  
>  return -EINVAL;
> +#elif defined(__OpenBSD__)
> + return DRM_BUS_PCI;
>  #else
>  #warning "Missing implementation of drmParseSubsystemType"
>  return -EINVAL;
> @@ -2929,6 +2953,26 @@ static int drmParsePciBusInfo(int maj, int min, 
> drmPciBusInfoPtr info)
>  info->func = func;
>  
>  return 0;
> +#elif defined(__OpenBSD__)
> +struct drm_pciinfo pinfo;
> +int fd;
> +
> +fd = drmOpenMinor(min, 0, DRM_NODE_PRIMARY);
> +if (fd < 0)
> +return -errno;
> +
> +if (drmIoctl(fd, DRM_IOCTL_GET_PCIINFO, )) {
> +close(fd);
> +return -errno;
> +}
> +close(fd);
> +
> +info->domain = pinfo.domain;
> +info->bus = pinfo.bus;
> +info->dev = pinfo.dev;
> +info->func = pinfo.func;
> +
> +return 0;
>  #else
>  #warning "Missing implementation of drmParsePciBusInfo"
>  return -EINVAL;
> @@ -3004,6 +3048,37 @@ static int drmParsePciDeviceInfo(const char *d_name,
>  device->subdevice_id = config[46] | (config[47] << 8);
>  
>  return 0;
> +#elif defined(__OpenBSD__)
> +struct drm_pciinfo pinfo;
> +char buf[0x40];

And here?

> +int fd, n;
> +
> +n = snprintf(buf, sizeof(buf), "%s/%s", DRM_DIR_NAME, d_name);
> +if (n == -1 || n >= sizeof(buf))
> +return -errno;
> +
> +#ifndef X_PRIVSEP
> +fd = open(buf, O_RDWR, 0);
> +#else
> +fd = priv_open_device(buf);
> +#endif
> +
> +if (fd < 0)
> +return -errno;
> +
> +if (drmIoctl(fd, DRM_IOCTL_GET_PCIINFO, )) {
> +close(fd);
> +return -errno;
> +}
> +close(fd);
> +
> +device->vendor_id = pinfo.vendor_id;
> +device->device_id = pinfo.device_id;
> +device->revision_id = pinfo.revision_id;
> +device->subvendor_id = pinfo.subvendor_id;
> +device->subdevice_id = pinfo.subdevice_id;
> +
> +return 0;
>  #else
>  #warning "Missing implementation of drmParsePciDeviceInfo"
>  return -EINVAL;
> @@ -3117,6 +3192,46 @@ static void drmFoldDuplicatedDevices(drmDevicePtr 
> local_devices[], int count)
>   */
>  int drmGetDevice(int fd, drmDevicePtr *device)
>  {
> +#ifdef __OpenBSD__
> +drmDevicePtr d;
> +struct stat sbuf;
> +char node[PATH_MAX + 1];
> +char d_name[PATH_MAX + 1];
> +int maj, min, n;
> +int ret;
> +int max_count = 1;
> +
> +if (fd == -1 || device == NULL)
> +return -EINVAL;
> +
> +if (fstat(fd, ))
> +return -errno;
> +
> +maj = major(sbuf.st_rdev);
> +min = minor(sbuf.st_rdev);
> +
> +if (maj != DRM_MAJOR || !S_ISCHR(sbuf.st_mode))
> +return -EINVAL;
> +
> +n = snprintf(d_name, PATH_MAX, "drm%d", min);
> +if (n == -1 || n >= PATH_MAX)
> +  return -errno;
> +
> +n = snprintf(node, PATH_MAX, DRM_DEV_NAME, DRM_DIR_NAME, min);
> +if (n == -1 || n >= PATH_MAX)
> +  return -errno;
> +if (stat(node, ))
> +return -EINVAL;
> +
> +ret = drmProcessPciDevice(, d_name, node, DRM_NODE_PRIMARY,
> +   maj, min, true);
> +if (ret)
> +return ret;
> +
> +*device = d;
> +
> +return 0;
> +#else
>  drmDevicePtr *local_devices;
>  drmDevicePtr d;
>  DIR *sysdir;
> @@ -3224,6 +3339,7 @@ free_devices:
>  free_locals:
>  free(local_devices);
>  return ret;
> +#endif
>  }
>  
>  

Re: pine64: working bootloader

2016-11-17 Thread Mark Kettenis
Plese stop sending large attachments.  The lists will drop them, and
they're overflowing my inbox.

Thanks,

Mark



Re: reduce iwm's RTS retry limit

2016-11-20 Thread Mark Kettenis
> Date: Sat, 19 Nov 2016 18:11:23 +0100
> From: Stefan Sperling 
> 
> The RTS retry limit we inherited from Linux seems insanely high.
> 
> It seems to be the cause for "bursty" pings and high latency for
> smaller packets while larger packets from TCP streams are stuck
> in the Tx queue:
> 
>  64 bytes from 192.168.1.12: icmp_seq=84 ttl=251 time=380.203 ms
>  64 bytes from 192.168.1.12: icmp_seq=85 ttl=251 time=710.714 ms
>  64 bytes from 192.168.1.12: icmp_seq=86 ttl=251 time=279.594 ms
>  64 bytes from 192.168.1.12: icmp_seq=87 ttl=251 time=893.879 ms
>  64 bytes from 192.168.1.12: icmp_seq=88 ttl=251 time=34800.236 ms
>  64 bytes from 192.168.1.12: icmp_seq=89 ttl=251 time=33815.364 ms
>  64 bytes from 192.168.1.12: icmp_seq=90 ttl=251 time=32824.247 ms
>  64 bytes from 192.168.1.12: icmp_seq=91 ttl=251 time=31822.355 ms
>  64 bytes from 192.168.1.12: icmp_seq=92 ttl=251 time=30817.395 ms
>  64 bytes from 192.168.1.12: icmp_seq=93 ttl=251 time=29822.478 ms
>  64 bytes from 192.168.1.12: icmp_seq=94 ttl=251 time=28817.508 ms
> 
> With this diff, while in bad channel conditions, instead of the above
> I am seeing 22% lost ping packets, and reasonable latency for those
> packets which make it through.
> 
> SSH into the machine is even possible (yet rather unusable), whereas
> before it didn't work at all.
> 
> ok?

Is it really a good idea to deviate from what Linux does here?
Perhaps for TCP this is slightly better, but how about other
protocols?  Anything that does broadcasts/multicasts will suffer from
higher packet loss.

In the end if you end up in a situation where the wireless connection
is so unreliable, you'll have to fix the wireless setup...


> Index: if_iwmreg.h
> ===
> RCS file: /cvs/src/sys/dev/pci/if_iwmreg.h,v
> retrieving revision 1.19
> diff -u -p -r1.19 if_iwmreg.h
> --- if_iwmreg.h   20 Sep 2016 11:46:09 -  1.19
> +++ if_iwmreg.h   19 Nov 2016 16:36:21 -
> @@ -4268,7 +4268,7 @@ struct iwm_lq_cmd {
>   */
>  #define IWM_DEFAULT_TX_RETRY 15
>  #define IWM_MGMT_DFAULT_RETRY_LIMIT  3
> -#define IWM_RTS_DFAULT_RETRY_LIMIT   60
> +#define IWM_RTS_DFAULT_RETRY_LIMIT   3
>  #define IWM_BAR_DFAULT_RETRY_LIMIT   60
>  #define IWM_LOW_RETRY_LIMIT  7
>  
> 
> 



Re: Add ioctl for disk cache flush

2016-10-30 Thread Mark Kettenis
> From: David Gwynne 
> Date: Mon, 31 Oct 2016 10:38:49 +1000
> 
> > On 31 Oct 2016, at 09:18, Stefan Fritsch  wrote:
> > 
> > On Sun, 30 Oct 2016, Stefan Fritsch wrote:
> >> I agree with all your comments (and should have reviewed the initial patch 
> >> better). Here is an updated diff.
> > 
> > The FWRITE check was missing in wdioctl(). Next try:
> 
> the diff looks fine to me.
> 
> whats the use of the ioctl though? why do we need extra sync cache things?

Right.  This smells like papering over real bugs.



Re: cdce(4): Remove zaurus specific code

2016-10-12 Thread Mark Kettenis
> Date: Tue, 11 Oct 2016 23:03:59 +0200
> From: Frederic Cambus <f...@statdns.com>
> 
> On Fri, Oct 07, 2016 at 06:02:35PM +0200, Mark Kettenis wrote:
> 
> > > It seems there are still some leftovers from the zaurus port removal.
> > > 
> > > Comments? OK?
> > 
> > Not ok.  This is support for the zaurus as a usb device attached to an
> 
> My mistake, thanks for the clarification.
> 
> > OpenBSD machine.  Perhaps the option should be renamed (to CDCE_CRC32
> > for example) to make this clear.
> 
> That would make sense, what about the following diff?

Makes sesne to me. ok kettenis@

> Index: sys/dev/usb/if_cdce.c
> ===
> RCS file: /cvs/src/sys/dev/usb/if_cdce.c,v
> retrieving revision 1.71
> diff -u -p -r1.71 if_cdce.c
> --- sys/dev/usb/if_cdce.c 26 Sep 2016 07:09:32 -  1.71
> +++ sys/dev/usb/if_cdce.c 11 Oct 2016 10:37:53 -
> @@ -93,13 +93,13 @@ static uint32_tcdce_crc32(const void *
>  const struct cdce_type cdce_devs[] = {
>  {{ USB_VENDOR_ACERLABS, USB_PRODUCT_ACERLABS_M5632 }, 0 },
>  {{ USB_VENDOR_PROLIFIC, USB_PRODUCT_PROLIFIC_PL2501 }, 0 },
> -{{ USB_VENDOR_SHARP, USB_PRODUCT_SHARP_SL5500 }, CDCE_ZAURUS },
> -{{ USB_VENDOR_SHARP, USB_PRODUCT_SHARP_A300 }, CDCE_ZAURUS },
> -{{ USB_VENDOR_SHARP, USB_PRODUCT_SHARP_SL5600 }, CDCE_ZAURUS },
> -{{ USB_VENDOR_SHARP, USB_PRODUCT_SHARP_C700 }, CDCE_ZAURUS },
> -{{ USB_VENDOR_SHARP, USB_PRODUCT_SHARP_C750 }, CDCE_ZAURUS },
> -{{ USB_VENDOR_MOTOROLA2, USB_PRODUCT_MOTOROLA2_USBLAN }, CDCE_ZAURUS },
> -{{ USB_VENDOR_MOTOROLA2, USB_PRODUCT_MOTOROLA2_USBLAN2 }, CDCE_ZAURUS },
> +{{ USB_VENDOR_SHARP, USB_PRODUCT_SHARP_SL5500 }, CDCE_CRC32 },
> +{{ USB_VENDOR_SHARP, USB_PRODUCT_SHARP_A300 }, CDCE_CRC32 },
> +{{ USB_VENDOR_SHARP, USB_PRODUCT_SHARP_SL5600 }, CDCE_CRC32 },
> +{{ USB_VENDOR_SHARP, USB_PRODUCT_SHARP_C700 }, CDCE_CRC32 },
> +{{ USB_VENDOR_SHARP, USB_PRODUCT_SHARP_C750 }, CDCE_CRC32 },
> +{{ USB_VENDOR_MOTOROLA2, USB_PRODUCT_MOTOROLA2_USBLAN }, CDCE_CRC32 },
> +{{ USB_VENDOR_MOTOROLA2, USB_PRODUCT_MOTOROLA2_USBLAN2 }, CDCE_CRC32 },
>  {{ USB_VENDOR_GMATE, USB_PRODUCT_GMATE_YP3X00 }, 0 },
>  {{ USB_VENDOR_NETCHIP, USB_PRODUCT_NETCHIP_ETHERNETGADGET }, 0 },
>  {{ USB_VENDOR_COMPAQ, USB_PRODUCT_COMPAQ_IPAQLINUX }, 0 },
> @@ -409,8 +409,8 @@ cdce_encap(struct cdce_softc *sc, struct
>   c = >cdce_cdata.cdce_tx_chain[idx];
>  
>   m_copydata(m, 0, m->m_pkthdr.len, c->cdce_buf);
> - if (sc->cdce_flags & CDCE_ZAURUS) {
> - /* Zaurus wants a 32-bit CRC appended to every frame */
> + if (sc->cdce_flags & CDCE_CRC32) {
> + /* Some devices want a 32-bit CRC appended to every frame */
>   u_int32_t crc;
>  
>   crc = cdce_crc32(c->cdce_buf, m->m_pkthdr.len);
> @@ -741,8 +741,8 @@ cdce_rxeof(struct usbd_xfer *xfer, void 
>   sc->cdce_rxeof_errors = 0;
>  
>   usbd_get_xfer_status(xfer, NULL, NULL, _len, NULL);
> - if (sc->cdce_flags & CDCE_ZAURUS)
> - total_len -= 4; /* Strip off CRC added by Zaurus */
> + if (sc->cdce_flags & CDCE_CRC32)
> + total_len -= 4; /* Strip off added CRC */
>   if (total_len <= 1)
>   goto done;
>  
> Index: sys/dev/usb/if_cdcereg.h
> ===
> RCS file: /cvs/src/sys/dev/usb/if_cdcereg.h,v
> retrieving revision 1.6
> diff -u -p -r1.6 if_cdcereg.h
> --- sys/dev/usb/if_cdcereg.h  4 Dec 2013 00:52:52 -   1.6
> +++ sys/dev/usb/if_cdcereg.h  11 Oct 2016 10:37:53 -
> @@ -41,7 +41,7 @@
>  struct cdce_type {
>   struct usb_devno cdce_dev;
>   u_int16_tcdce_flags;
> -#define CDCE_ZAURUS  1
> +#define CDCE_CRC32   1
>  #define CDCE_SWAPUNION   2
>  };
>  
> 



Re: M_PREPEND in vxlan encap on not strict-alignment archs

2016-10-10 Thread Mark Kettenis
> Date: Mon, 10 Oct 2016 13:48:18 +1000
> From: David Gwynne 
> 
> if the arch can cope with prepending on an unaligned address in
> vxlan, then let it do it.
> 
> this means less work if we can get away with it.
> 
> ok?

Let's face it.  The vxlan protocol is badly designed.  Should we
really create multiple code paths for strict-align and
non-strict-align architectures?  Is vxlan really used in
performance-critical setups?

> Index: if_vxlan.c
> ===
> RCS file: /cvs/src/sys/net/if_vxlan.c,v
> retrieving revision 1.49
> diff -u -p -r1.49 if_vxlan.c
> --- if_vxlan.c7 Oct 2016 06:16:03 -   1.49
> +++ if_vxlan.c10 Oct 2016 03:42:36 -
> @@ -766,20 +765,29 @@ vxlan_output(struct ifnet *ifp, struct m
>  #endif
>   int  error, af;
>   uint32_t tag;
> - struct mbuf *m0;
>  
>   /* VXLAN header */
> - MGETHDR(m0, M_DONTWAIT, m->m_type);
> - if (m0 == NULL) {
> - ifp->if_oerrors++;
> - return (ENOBUFS);
> + if (!ALIGNED_POINTER(mtod(m, caddr_t), uint32_t)) {
> + struct mbuf *m0;
> +
> + MGETHDR(m0, M_DONTWAIT, m->m_type);
> + if (m0 == NULL) {
> + ifp->if_oerrors++;
> + return (ENOBUFS);
> + }
> + M_MOVE_PKTHDR(m0, m);
> + m0->m_next = m;
> + m = m0;
> + MH_ALIGN(m, sizeof(*vu));
> + m->m_len = sizeof(*vu);
> + m->m_pkthdr.len += sizeof(*vu);
> + } else {
> + M_PREPEND(m, sizeof(*vu), M_DONTWAIT);
> + if (m == NULL) {
> + ifp->if_oerrors++;
> + return (ENOBUFS);
> + }
>   }
> - M_MOVE_PKTHDR(m0, m);
> - m0->m_next = m;
> - m = m0;
> - MH_ALIGN(m, sizeof(*vu));
> - m->m_len = sizeof(*vu);
> - m->m_pkthdr.len += sizeof(*vu);
>  
>   src = (struct sockaddr *)>sc_src;
>   dst = (struct sockaddr *)>sc_dst;
> 
> 



Re: King Jim Portabook

2016-12-10 Thread Mark Kettenis
> From: Reyk Floeter 
> Date: Sat, 10 Dec 2016 12:50:56 +0100
> 
> >> On Sat, Dec 10, 2016 at 08:17:10PM +0900, Ryan McBride wrote:
> >> So I've been eying this machine for a while:
> >> http://www.kingjim.co.jp/sp/portabook/xmc10/
> > 
> > Included below is the dmesg with the previous diff applied.
> > 
> > Besides all the devices that show "not configured", there are a bunch of
> > other things that don't work. I guess there's more broken that I haven't
> > run into yet.
> > 
> > - Built-in keyboard does not work in the bootloader (an external USB
> >  keyboard is fine)
> > 
> > - zzz fails with "acpi0: state S3 unavailable"
> > 
> > - Console does not use the whole screen, there is an empty border around
> >  the whole screen (~2 chars tall at top and bottom, ~3 wide on the
> >  sides)
> > 
> 
> efifb(4) does not fill the screen, it uses hardcoded values; I only
> get a tiny console on my 2560x screen.

There are hardcoded limits.  On smaller screens it will use the entire
screen.
> 
> I patched my kernel to fill the laptop screen but efifb should
> really just adjust to the actual resolution automatically.

The problem with filling the entire screen is that the console becomes
quite slow.  This makes doing things like running a full-screen editor
or scrolling through logs a bit of a pain.  Maybe it is a bit better
now that we map the framebuffer in write-combining mode.  Also
increasing the number of characters beyond what we have now is not
going to make it more usable.

What we really need is a bigger font for those high-resolution screens.



Re: ifconfig: print netmask in CIDR notation

2016-12-13 Thread Mark Kettenis
> Date: Tue, 13 Dec 2016 10:51:40 +0100
> From: Reyk Floeter 
> 
> Hi,
> 
> printing the netmask in hex seems to be a historical artifact in ifconfig;
> I always wondered about it and I never got used to it.
> 
> The following diff changes ifconfig output to print contiguous
> netmasks in CIDR notation.  Non-contiguous netmasks will still be
> printed in full, tunnels will print explicit "prefixlen" because it is
> not unambiguous where the mask belongs to in this case.
> 
> lo1: flags=8049 rdomain 1 mtu 32768
> index 7 priority 0 llprio 3
> groups: lo
> inet6 ::1/128
> inet6 fe80::1%lo1/64 scopeid 0x7
> inet 10.2.1.100 netmask 0x00ff
> inet 10.3.100.1/24
> 
> A similar change has been done in NetBSD and FreeBSD is doing the
> FreeBSD thing by providing an -f command-line button to select one of
> three output modes ...
> 
> Thoughts?

I'd say it is a bad idea to mix the two forms in ifconfig output.



Re: if() before m_free(9)

2017-01-09 Thread Mark Kettenis
> Date: Mon, 9 Jan 2017 20:12:32 +0100
> From: Martin Pieuchot 
> 
> m_free(9) handles NULL, no need to check for it beforehand.
> 
> Seems that we missed these because of the (void) cast!
> 
> ok?

ok kettenis@

> Index: netinet/ip_output.c
> ===
> RCS file: /cvs/src/sys/netinet/ip_output.c,v
> retrieving revision 1.333
> diff -u -p -r1.333 ip_output.c
> --- netinet/ip_output.c   19 Dec 2016 09:22:24 -  1.333
> +++ netinet/ip_output.c   9 Jan 2017 17:51:52 -
> @@ -1074,8 +1074,7 @@ ip_ctloutput(int op, struct socket *so, 
>   error = ENOPROTOOPT;
>   break;
>   }
> - if (m)
> - (void)m_free(m);
> + m_free(m);
>   break;
>  
>   case PRCO_GETOPT:
> @@ -1242,15 +1241,13 @@ ip_pcbopts(struct mbuf **pcbopt, struct 
>   u_char opt;
>  
>   /* turn off any old options */
> - if (*pcbopt)
> - (void)m_free(*pcbopt);
> + m_free(*pcbopt);
>   *pcbopt = 0;
>   if (m == NULL || m->m_len == 0) {
>   /*
>* Only turning off any previous options.
>*/
> - if (m)
> - (void)m_free(m);
> + m_free(m);
>   return (0);
>   }
>  
> Index: netinet/raw_ip.c
> ===
> RCS file: /cvs/src/sys/netinet/raw_ip.c,v
> retrieving revision 1.90
> diff -u -p -r1.90 raw_ip.c
> --- netinet/raw_ip.c  19 Dec 2016 09:22:24 -  1.90
> +++ netinet/raw_ip.c  9 Jan 2017 17:52:13 -
> @@ -325,8 +325,7 @@ rip_ctloutput(int op, struct socket *so,
>   inp->inp_flags |= INP_HDRINCL;
>   else
>   inp->inp_flags &= ~INP_HDRINCL;
> - if (*mp)
> - (void)m_free(*mp);
> + m_free(*mp);
>   } else {
>   *mp = m_get(M_WAIT, M_SOOPTS);
>   (*mp)->m_len = sizeof(int);
> Index: netinet/tcp_input.c
> ===
> RCS file: /cvs/src/sys/netinet/tcp_input.c,v
> retrieving revision 1.334
> diff -u -p -r1.334 tcp_input.c
> --- netinet/tcp_input.c   19 Dec 2016 08:36:49 -  1.334
> +++ netinet/tcp_input.c   9 Jan 2017 17:53:03 -
> @@ -3340,8 +3340,7 @@ syn_cache_rm(struct syn_cache *sc)
>  void
>  syn_cache_put(struct syn_cache *sc)
>  {
> - if (sc->sc_ipopts)
> - (void) m_free(sc->sc_ipopts);
> + m_free(sc->sc_ipopts);
>   if (sc->sc_route4.ro_rt != NULL) {
>   rtfree(sc->sc_route4.ro_rt);
>   sc->sc_route4.ro_rt = NULL;
> @@ -4035,8 +4034,7 @@ syn_cache_add(struct sockaddr *src, stru
>* If we were remembering a previous source route,
>* forget it and use the new one we've been given.
>*/
> - if (sc->sc_ipopts)
> - (void) m_free(sc->sc_ipopts);
> + m_free(sc->sc_ipopts);
>   sc->sc_ipopts = ipopts;
>   }
>   sc->sc_timestamp = tb.ts_recent;
> @@ -4049,8 +4047,7 @@ syn_cache_add(struct sockaddr *src, stru
>  
>   sc = pool_get(_cache_pool, PR_NOWAIT|PR_ZERO);
>   if (sc == NULL) {
> - if (ipopts)
> - (void) m_free(ipopts);
> + m_free(ipopts);
>   return (-1);
>   }
>  
> Index: netinet/tcp_subr.c
> ===
> RCS file: /cvs/src/sys/netinet/tcp_subr.c,v
> retrieving revision 1.157
> diff -u -p -r1.157 tcp_subr.c
> --- netinet/tcp_subr.c20 Dec 2016 09:57:10 -  1.157
> +++ netinet/tcp_subr.c9 Jan 2017 17:52:39 -
> @@ -534,8 +534,7 @@ tcp_close(struct tcpcb *tp)
>   p = q;
>   }
>  #endif
> - if (tp->t_template)
> - (void) m_free(tp->t_template);
> + m_free(tp->t_template);
>  
>   tp->t_flags |= TF_DEAD;
>   timeout_add(>t_reap_to, 0);
> Index: netinet/tcp_usrreq.c
> ===
> RCS file: /cvs/src/sys/netinet/tcp_usrreq.c,v
> retrieving revision 1.141
> diff -u -p -r1.141 tcp_usrreq.c
> --- netinet/tcp_usrreq.c  3 Jan 2017 10:52:21 -   1.141
> +++ netinet/tcp_usrreq.c  9 Jan 2017 17:52:28 -
> @@ -569,8 +569,7 @@ tcp_ctloutput(int op, struct socket *so,
>   error = ENOPROTOOPT;
>   break;
>   }
> - if (m)
> - (void) m_free(m);
> + m_free(m);
>   break;
>  
>   case PRCO_GETOPT:
> Index: netinet6/ip6_output.c
> ===
> RCS 

Re: Remove uvm hint address selector

2017-01-15 Thread Mark Kettenis
> Date: Sun, 15 Jan 2017 15:06:50 +0100
> From: Stefan Kempf 
> 
> When uvm pivots are enabled, allocations
> with an address hint provided by the user program are
> handled by the uaddr_hint selector.
> 
> I'd like to remove the uaddr_hint selector. The uaddr_rnd selector
> already deals with hinted allocations correctly, so why not use
> it for hinted allocations in the pivot selector?
> 
> This diff is a part of making pivots work.
> Getting rid of the hint selectors makes the code simpler.
> I'd to commit this part first, to make the actual pivot
> diffs smaller.
> 
> ok?

No objection from me.

> Some more details:
> 
> If you have multiple selectors per address space that manage
> overlapping address ranges, some selectors have priority
> over others. E.g. only the brk selector is allowed to make
> allocations within the brk area. The rnd selector
> gets all these checks right, but the hint selector does
> not, which causes panics when you use pivots and try to
> do a hinted allocation within the brk area.
> 
> So better use the code which is known to work for hinted
> allocations. Once pivots are enabled, maybe the parts of the
> rnd allocator that deal with hinted allocations can be factored
> out into a common function.
> 
> Index: uvm/uvm_addr.c
> ===
> RCS file: /cvs/src/sys/uvm/uvm_addr.c,v
> retrieving revision 1.22
> diff -u -p -r1.22 uvm_addr.c
> --- uvm/uvm_addr.c16 Sep 2016 02:50:54 -  1.22
> +++ uvm/uvm_addr.c14 Jan 2017 05:53:17 -
> @@ -46,17 +46,10 @@
>  
>  /* Pool with uvm_addr_state structures. */
>  struct pool uaddr_pool;
> -struct pool uaddr_hint_pool;
>  struct pool uaddr_bestfit_pool;
>  struct pool uaddr_pivot_pool;
>  struct pool uaddr_rnd_pool;
>  
> -/* uvm_addr state for hint based selector. */
> -struct uaddr_hint_state {
> - struct uvm_addr_stateuaddr;
> - vsize_t  max_dist;
> -};
> -
>  /* uvm_addr state for bestfit selector. */
>  struct uaddr_bestfit_state {
>   struct uvm_addr_stateubf_uaddr;
> @@ -118,7 +111,6 @@ void   uaddr_kremove(struct vm_map *,
>  void  uaddr_kbootstrapdestroy(struct uvm_addr_state *);
>  
>  void  uaddr_destroy(struct uvm_addr_state *);
> -void  uaddr_hint_destroy(struct uvm_addr_state *);
>  void  uaddr_kbootstrap_destroy(struct uvm_addr_state *);
>  void  uaddr_rnd_destroy(struct uvm_addr_state *);
>  void  uaddr_bestfit_destroy(struct uvm_addr_state *);
> @@ -138,10 +130,6 @@ int   uaddr_rnd_select(struct vm_map 
> *,
>   struct uvm_addr_state *, struct vm_map_entry **,
>   vaddr_t *, vsize_t, vaddr_t, vaddr_t, vm_prot_t,
>   vaddr_t);
> -int   uaddr_hint_select(struct vm_map *,
> - struct uvm_addr_state*, struct vm_map_entry **,
> - vaddr_t *, vsize_t, vaddr_t, vaddr_t, vm_prot_t,
> - vaddr_t);
>  int   uaddr_bestfit_select(struct vm_map *,
>   struct uvm_addr_state*, struct vm_map_entry **,
>   vaddr_t *, vsize_t, vaddr_t, vaddr_t, vm_prot_t,
> @@ -290,8 +278,6 @@ uvm_addr_init(void)
>  {
>   pool_init(_pool, sizeof(struct uvm_addr_state), 0,
>   IPL_VM, PR_WAITOK, "uaddr", NULL);
> - pool_init(_hint_pool, sizeof(struct uaddr_hint_state), 0,
> - IPL_VM, PR_WAITOK, "uaddrhint", NULL);
>   pool_init(_bestfit_pool, sizeof(struct uaddr_bestfit_state), 0,
>   IPL_VM, PR_WAITOK, "uaddrbest", NULL);
>   pool_init(_pivot_pool, sizeof(struct uaddr_pivot_state), 0,
> @@ -740,116 +726,6 @@ uaddr_rnd_print(struct uvm_addr_state *u
>  #endif
>  
>  /*
> - * An allocator that selects an address within distance of the hint.
> - *
> - * If no hint is given, the allocator refuses to allocate.
> - */
> -const struct uvm_addr_functions uaddr_hint_functions = {
> - .uaddr_select = _hint_select,
> - .uaddr_destroy = _hint_destroy,
> - .uaddr_name = "uaddr_hint"
> -};
> -
> -/*
> - * Create uaddr_hint state.
> - */
> -struct uvm_addr_state *
> -uaddr_hint_create(vaddr_t minaddr, vaddr_t maxaddr, vsize_t max_dist)
> -{
> - struct uaddr_hint_state *ua_hint;
> -
> - KASSERT(uaddr_hint_pool.pr_size == sizeof(*ua_hint));
> -
> - ua_hint = pool_get(_hint_pool, PR_WAITOK);
> - ua_hint->uaddr.uaddr_minaddr = minaddr;
> - ua_hint->uaddr.uaddr_maxaddr = maxaddr;
> - ua_hint->uaddr.uaddr_functions = _hint_functions;
> - ua_hint->max_dist = max_dist;
> - return _hint->uaddr;
> -}
> -
> -/*
> - * Destroy uaddr_hint state.
> - */
> -void
> -uaddr_hint_destroy(struct uvm_addr_state *uaddr)
> -{
> - pool_put(_hint_pool, uaddr);
> -}
> -
> -/*
> - * Hint selector.
> - *
> - * 

Re: arm64: userland pieces (libm)

2017-01-11 Thread Mark Kettenis
> Date: Wed, 11 Jan 2017 14:12:59 +0100
> From: Patrick Wildt 
> 
> Hi,
> 
> I'd like to start importing the userland pieces, piece by piece.  This
> diff implements support for aarch64 in libm.  It's based on the FreeBSD
> header, modified to look and feel more like our code.
> 
> ok?

If Theo and Philip agree, I think you should just move ahead and
import new bits and obvious makefile changes straightaway.  It is much
easier to have it in the tree such that we can produce diffs for any
mistakes that are made.

Cheers,

Mark

> diff --git a/lib/libm/Makefile b/lib/libm/Makefile
> index 3854bb395fe..3d063929d0a 100644
> --- a/lib/libm/Makefile
> +++ b/lib/libm/Makefile
> @@ -48,6 +48,8 @@ ARCH_SRCS = e_sqrt.c e_sqrtf.c e_remainder.c e_remainderf.c 
> \
>  .elif (${MACHINE_ARCH} == "sh")
>  .PATH:   ${.CURDIR}/arch/sh
>  ARCH_SRCS = e_sqrt.c e_sqrtf.c s_fabsf.c
> +.elif (${MACHINE_ARCH} == "aarch64")
> +.PATH:   ${.CURDIR}/arch/aarch64
>  .elif (${MACHINE_ARCH} == "arm")
>  .PATH:   ${.CURDIR}/arch/arm
>  .elif (${MACHINE_ARCH} == "m88k")
> @@ -134,7 +136,8 @@ SRCS= ${COMMON_SRCS} ${PURE_SRCS}
>  CPPFLAGS+=   -I${.CURDIR}/src -I${.CURDIR}/src/ld80
>  SRCS+=   ${LONG_SRCS}
>  .endif
> -.if (${MACHINE_CPU} == "mips64") || (${MACHINE_ARCH} == "sparc64")
> +.if (${MACHINE_CPU} == "mips64") || (${MACHINE_ARCH} == "sparc64") || \
> +(${MACHINE_ARCH} == "aarch64")
>  .PATH:   ${.CURDIR}/src/ld128
>  CPPFLAGS+=   -I${.CURDIR}/src -I${.CURDIR}/src/ld128
>  SRCS+=   ${LONG_SRCS}
> diff --git a/lib/libm/arch/aarch64/fenv.c b/lib/libm/arch/aarch64/fenv.c
> new file mode 100644
> index 000..f186b3d260c
> --- /dev/null
> +++ b/lib/libm/arch/aarch64/fenv.c
> @@ -0,0 +1,284 @@
> +/* $OpenBSD$ */
> +/*-
> + * Copyright (c) 2004-2005 David Schultz 
> + * 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.
> + *
> + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS BE LIABLE
> + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
> + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
> + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
> + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
> + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
> + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
> + * SUCH DAMAGE.
> + *
> + * $FreeBSD: head/lib/msun/aarch64/fenv.h 280857 2015-03-30 16:42:08Z emaste 
> $
> + */
> +
> +#include 
> +#include 
> +
> +/* We need to be able to map status flag positions to mask flag positions */
> +#define  _FPUSW_SHIFT8
> +#define  _ENABLE_MASK(FE_ALL_EXCEPT << _FPUSW_SHIFT)
> +
> +#define  __mrs_fpcr(r)   __asm __volatile("mrs %x0, fpcr" : "=r" (r))
> +#define  __msr_fpcr(r)   __asm __volatile("msr fpcr, %x0" : : "r" (r))
> +
> +#define  __mrs_fpsr(r)   __asm __volatile("mrs %x0, fpsr" : "=r" (r))
> +#define  __msr_fpsr(r)   __asm __volatile("msr fpsr, %x0" : : "r" (r))
> +
> +/*
> + * The following constant represents the default floating-point environment
> + * (that is, the one installed at program startup) and has type pointer to
> + * const-qualified fenv_t.
> + *
> + * It can be used as an argument to the functions within the  header
> + * that manage the floating-point environment, namely fesetenv() and
> + * feupdateenv().
> + */
> +fenv_t __fe_dfl_env = 0;
> +
> +/*
> + * The feclearexcept() function clears the supported floating-point 
> exceptions
> + * represented by `excepts'.
> + */
> +int
> +feclearexcept(int excepts)
> +{
> + fexcept_t r;
> +
> + __mrs_fpsr(r);
> + r &= ~excepts;
> + __msr_fpsr(r);
> + return (0);
> +}
> +DEF_STD(feclearexcept);
> +
> +/*
> + * The fegetexceptflag() function stores an implementation-defined
> + * representation of the states of the floating-point status flags indicated 
> by
> + * the argument excepts in the object pointed to by the argument flagp.
> + */
> +int
> +fegetexceptflag(fexcept_t *flagp, int excepts)
> +{
> + fexcept_t r;
> +
> + __mrs_fpsr(r);
> + *flagp = r & excepts;
> + return (0);

Re: C11 max_align_t

2017-01-06 Thread Mark Kettenis
> From: "Todd C. Miller" 
> Date: Thu, 05 Jan 2017 15:50:02 -0700
> 
> I think you need to also define __CLANG_MAX_ALIGN_T_DEFINED and
> perhaps _GCC_MAX_ALIGN_T to avoid libcxx from redefining max_align_t
> as a different type.  E.g. in src/lib/libcxx/include/stddef.h
> 
> // Re-use the compiler's  max_align_t where possible.
> #if !defined(__CLANG_MAX_ALIGN_T_DEFINED) && !defined(_GCC_MAX_ALIGN_T)
> typedef long double max_align_t;
> #endif
> 
> FreeBSD defines both __CLANG_MAX_ALIGN_T_DEFINED and _GCC_MAX_ALIGN_T
> when defining max_align_t in stddef.h, we probably need to as well.

Good point.  I don't really see a reason to define _GCC_MAX_ALIGN_T as
libstdc++ doesn't try to define its own max_align_t like libc++ does.
We do need to make sure that we define max_align_t for C++11 and up
though.

New diff below.

ok?


Index: include/stddef.h
===
RCS file: /cvs/src/include/stddef.h,v
retrieving revision 1.13
diff -u -p -r1.13 stddef.h
--- include/stddef.h9 Sep 2016 18:12:37 -   1.13
+++ include/stddef.h6 Jan 2017 11:19:39 -
@@ -71,4 +71,14 @@ typedef  __mbstate_t mbstate_t;
 #defineoffsetof(type, member)  ((size_t)(&((type *)0)->member))
 #endif
 
+#if __ISO_C_VISIBLE >= 2011 || __cplusplus >= 201103
+#ifndef __CLANG_MAX_ALIGN_T_DEFINED
+#define __CLANG_MAX_ALIGN_T_DEFINED
+typedef struct {
+   long long __max_align_ll __aligned(__alignof__(long long));
+   long double __max_align_ld __aligned(__alignof__(long double));
+} max_align_t;
+#endif
+#endif
+
 #endif /* _STDDEF_H_ */
Index: sys/sys/cdefs.h
===
RCS file: /cvs/src/sys/sys/cdefs.h,v
retrieving revision 1.39
diff -u -p -r1.39 cdefs.h
--- sys/sys/cdefs.h 18 Apr 2014 11:51:17 -  1.39
+++ sys/sys/cdefs.h 6 Jan 2017 11:19:39 -
@@ -375,14 +375,19 @@
 #endif
 
 /*
- * _ISOC99_SOURCE and __STDC_VERSION__ override any of the other macros since
- * they are non-exclusive.
+ * _ISOC99_SOURCE, _ISOC11_SOURCE and __STDC_VERSION__ override any of
+ * the other macros since they are non-exclusive.
  */
 #if defined(_ISOC99_SOURCE) || \
 (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901) || \
 (defined(__cplusplus) && __cplusplus >= 201103)
 # undef __ISO_C_VISIBLE
 # define __ISO_C_VISIBLE   1999
+#endif
+#if defined(_ISOC11_SOURCE) || \
+(defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112)
+# undef __ISO_C_VISIBLE
+# define __ISO_C_VISIBLE   2011
 #endif
 
 /*



ld.so diff that needs testing on landisk

2017-01-03 Thread Mark Kettenis
The diff below (partly by guenther@) removes ld.so's dependency on the
__got_{start,end} symbols by looking at PT_GNU_RELRO instead.  On some
platforms (hppa and perhaps a few others) this leads to even less
writable pages.  However, we're not sure if this will work correctly
on landisk.  So if somebody with a fairly up-to-date landisk could
give this a spin for us, it would be highly appreciated.


Index: libexec/ld.so/boot.c
===
RCS file: /cvs/src/libexec/ld.so/boot.c,v
retrieving revision 1.14
diff -u -p -r1.14 boot.c
--- libexec/ld.so/boot.c13 Aug 2016 20:57:04 -  1.14
+++ libexec/ld.so/boot.c2 Jan 2017 15:55:52 -
@@ -87,6 +87,8 @@ _dl_boot_bind(const long sp, long *dl_da
longloff;
Elf_Addri;
RELOC_TYPE  *rp;
+   Elf_Ehdr*ehdp;
+   Elf_Phdr*phdp;
 
/*
 * Scan argument and environment vectors. Find dynamic
@@ -189,4 +191,30 @@ _dl_boot_bind(const long sp, long *dl_da
 * we have been fully relocated here, so most things no longer
 * need the loff adjustment
 */
+
+   /*
+* No further changes to the PLT and/or GOT are needed so make
+* them read-only.
+*/
+
+   /* do any RWX -> RX fixups for executable PLTs and apply GNU_RELRO */
+   ehdp = (Elf_Ehdr *)loff;
+   phdp = (Elf_Phdr *)(loff + ehdp->e_phoff);
+   for (i = 0; i < dl_data[AUX_phnum]; i++, phdp++) {
+   switch (phdp->p_type) {
+#if defined(__alpha__) || defined(__hppa__) || defined(__powerpc__) || \
+defined(__sparc64__)
+   case PT_LOAD:
+   if ((phdp->p_flags & (PF_X | PF_W)) != (PF_X | PF_W))
+   break;
+   _dl_mprotect((void *)(phdp->p_vaddr + loff),
+   phdp->p_memsz, PROT_READ);
+   break;
+#endif
+   case PT_GNU_RELRO:
+   _dl_mprotect((void *)(phdp->p_vaddr + loff),
+   phdp->p_memsz, PROT_READ);
+   break;
+   }
+   }
 }
Index: libexec/ld.so/loader.c
===
RCS file: /cvs/src/libexec/ld.so/loader.c,v
retrieving revision 1.167
diff -u -p -r1.167 loader.c
--- libexec/ld.so/loader.c  28 Aug 2016 04:33:17 -  1.167
+++ libexec/ld.so/loader.c  2 Jan 2017 15:55:52 -
@@ -413,25 +413,6 @@ _dl_boot(const char **argv, char **envp,
 #define ROUND_PG(x) (((x) + align) & ~(align))
 #define TRUNC_PG(x) ((x) & ~(align))
 
-   /*
-* now that GOT and PLT have been relocated, and we know
-* page size, protect them from modification
-*/
-#ifndef  RTLD_NO_WXORX
-   {
-   extern char *__got_start;
-   extern char *__got_end;
-
-   if (&__got_start != &__got_end) {
-   _dl_mprotect((void *)ELF_TRUNC((long)&__got_start,
-   _dl_pagesz),
-   ELF_ROUND((long)&__got_end,_dl_pagesz) -
-   ELF_TRUNC((long)&__got_start, _dl_pagesz),
-   GOT_PERMS);
-   }
-   }
-#endif
-
_dl_setup_env(argv[0], envp);
 
DL_DEB(("rtld loading: '%s'\n", __progname));
Index: libexec/ld.so/alpha/archdep.h
===
RCS file: /cvs/src/libexec/ld.so/alpha/archdep.h,v
retrieving revision 1.17
diff -u -p -r1.17 archdep.h
--- libexec/ld.so/alpha/archdep.h   6 Dec 2015 23:36:12 -   1.17
+++ libexec/ld.so/alpha/archdep.h   2 Jan 2017 15:55:52 -
@@ -65,6 +65,4 @@ RELOC_DYN(Elf64_Rela *r, const Elf64_Sym
 
 #define RELOC_GOT(obj, offs)
 
-#define GOT_PERMS PROT_READ
-
 #endif /* _ALPHA_ARCHDEP_H_ */
Index: libexec/ld.so/amd64/archdep.h
===
RCS file: /cvs/src/libexec/ld.so/amd64/archdep.h,v
retrieving revision 1.8
diff -u -p -r1.8 archdep.h
--- libexec/ld.so/amd64/archdep.h   18 May 2016 20:40:20 -  1.8
+++ libexec/ld.so/amd64/archdep.h   2 Jan 2017 15:55:52 -
@@ -68,6 +68,4 @@ RELOC_DYN(Elf64_Rela *r, const Elf64_Sym
 
 #define RELOC_GOT(obj, offs)
 
-#define GOT_PERMS PROT_READ
-
 #endif /* _X86_64_ARCHDEP_H_ */
Index: libexec/ld.so/arm/archdep.h
===
RCS file: /cvs/src/libexec/ld.so/arm/archdep.h,v
retrieving revision 1.8
diff -u -p -r1.8 archdep.h
--- libexec/ld.so/arm/archdep.h 8 Sep 2016 18:56:58 -   1.8
+++ libexec/ld.so/arm/archdep.h 2 Jan 2017 15:55:52 -
@@ -73,6 +73,4 @@ RELOC_DYN(Elf_Rel *r, const Elf_Sym *s, 
 
 #define RELOC_GOT(obj, offs)
 
-#define GOT_PERMS (PROT_READ|PROT_EXEC)
-
 #endif /* _ARM_ARCHDEP_H_ */
Index: libexec/ld.so/hppa/archdep.h

C11 max_align_t

2017-01-05 Thread Mark Kettenis
Diff below adds C11 support to the feature test macros in
 and uses those to conditionally define the max_align_t
type in .  All systems/compilers seem to use the same
construct.  See

  https://reviews.llvm.org/rL201729

for a bit more background.

This will make it possible to remove clang's private 
without losing functionality.

Since our base compiler doesn't have C11 support, the type generally
won't be available.  But it can be made available by using

  gcc -D_ISOC11_SOURCE

With clang, C11 support is enabled by default, so max_align_t is
visible.  But it can be hidden by using

  clang -std=c99

I don't expect any major fall-out in ports from this.

ok?


Index: sys/sys/cdefs.h
===
RCS file: /cvs/src/sys/sys/cdefs.h,v
retrieving revision 1.39
diff -u -p -r1.39 cdefs.h
--- sys/sys/cdefs.h 18 Apr 2014 11:51:17 -  1.39
+++ sys/sys/cdefs.h 5 Jan 2017 20:07:02 -
@@ -375,14 +375,19 @@
 #endif
 
 /*
- * _ISOC99_SOURCE and __STDC_VERSION__ override any of the other macros since
- * they are non-exclusive.
+ * _ISOC99_SOURCE, _ISOC11_SOURCE and __STDC_VERSION__ override any of
+ * the other macros since they are non-exclusive.
  */
 #if defined(_ISOC99_SOURCE) || \
 (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901) || \
 (defined(__cplusplus) && __cplusplus >= 201103)
 # undef __ISO_C_VISIBLE
 # define __ISO_C_VISIBLE   1999
+#endif
+#if defined(_ISOC11_SOURCE) || \
+(defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112)
+# undef __ISO_C_VISIBLE
+# define __ISO_C_VISIBLE   2011
 #endif
 
 /*
Index: include/stddef.h
===
RCS file: /cvs/src/include/stddef.h,v
retrieving revision 1.13
diff -u -p -r1.13 stddef.h
--- include/stddef.h9 Sep 2016 18:12:37 -   1.13
+++ include/stddef.h5 Jan 2017 20:07:02 -
@@ -71,4 +71,11 @@ typedef  __mbstate_t mbstate_t;
 #defineoffsetof(type, member)  ((size_t)(&((type *)0)->member))
 #endif
 
+#if __ISO_C_VISIBLE >= 2011
+typedef struct {
+   long long __max_align_ll __aligned(__alignof__(long long));
+   long double __max_align_ld __aligned(__alignof__(long double));
+} max_align_t;
+#endif
+
 #endif /* _STDDEF_H_ */



Re: Only install relevant "intrinsics" header files

2017-01-06 Thread Mark Kettenis
> Date: Sat, 7 Jan 2017 08:10:02 +1100
> From: Jonathan Gray <j...@jsg.id.au>
> 
> On Fri, Jan 06, 2017 at 05:26:36PM +0100, Mark Kettenis wrote:
> > These are hardware-specific, so it makes sense to only install the
> > ones relevant for the (target) hardware.
> > 
> > ok?
> 
> Looking at the cmake files there is also a arm_neon.h
> generated by llvm's tablegen.

I suppose that needs some additional Makefile magic.  I'd say it's a
separate issue though.  So ok in this diff as a first step?

> > Index: gnu/usr.bin/clang/include/clang/intrin/Makefile
> > ===
> > RCS file: /cvs/src/gnu/usr.bin/clang/include/clang/intrin/Makefile,v
> > retrieving revision 1.3
> > diff -u -p -r1.3 Makefile
> > --- gnu/usr.bin/clang/include/clang/intrin/Makefile 6 Jan 2017 14:44:34 
> > -   1.3
> > +++ gnu/usr.bin/clang/include/clang/intrin/Makefile 6 Jan 2017 16:24:41 
> > -
> > @@ -7,70 +7,70 @@ CLANG_INTR_INCDIR=/usr/lib/clang/${LLVM
> >  
> >  .PATH: ${.CURDIR}/../../../../../llvm/tools/clang/lib/Headers
> >  
> > -HEADERS=adxintrin.h \
> > -   altivec.h \
> > -   ammintrin.h \
> > -   arm_acle.h \
> > -   avx2intrin.h \
> > -   avx512bwintrin.h \
> > -   avx512cdintrin.h \
> > -   avx512erintrin.h \
> > -   avx512fintrin.h \
> > -   avx512vlbwintrin.h \
> > -   avx512vlintrin.h \
> > -   avx512dqintrin.h \
> > -   avx512vldqintrin.h \
> > -   pkuintrin.h \
> > -   avxintrin.h \
> > -   bmi2intrin.h \
> > -   bmiintrin.h \
> > -   __clang_cuda_runtime_wrapper.h \
> > -   cpuid.h \
> > -   cuda_builtin_vars.h \
> > -   emmintrin.h \
> > -   f16cintrin.h \
> > -   fma4intrin.h \
> > -   fmaintrin.h \
> > -   fxsrintrin.h \
> > -   htmintrin.h \
> > -   htmxlintrin.h \
> > -   ia32intrin.h \
> > -   immintrin.h \
> > -   Intrin.h \
> > -   lzcntintrin.h \
> > -   mm3dnow.h \
> > -   mmintrin.h \
> > -   mm_malloc.h \
> > -   module.modulemap \
> > -   nmmintrin.h \
> > -   pmmintrin.h \
> > -   popcntintrin.h \
> > -   prfchwintrin.h \
> > -   rdseedintrin.h \
> > -   rtmintrin.h \
> > -   s390intrin.h \
> > -   shaintrin.h \
> > -   smmintrin.h \
> > -   stdalign.h \
> > -   stdatomic.h \
> > -   stdnoreturn.h \
> > -   tbmintrin.h \
> > -   tgmath.h \
> > -   tmmintrin.h \
> > -   unwind.h \
> > -   varargs.h \
> > -   vecintrin.h \
> > -   __wmmintrin_aes.h \
> > -   wmmintrin.h \
> > -   __wmmintrin_pclmul.h \
> > -   x86intrin.h \
> > -   xmmintrin.h \
> > -   xopintrin.h \
> > -   xsaveintrin.h \
> > -   xsaveoptintrin.h \
> > -   xsavecintrin.h \
> > -   xsavesintrin.h \
> > -   xtestintrin.h
> > +HEADERS=   stdalign.h \
> > +   stdatomic.h \
> > +   stdnoreturn.h \
> > +   tgmath.h \
> > +   unwind.h \
> > +   varargs.h \
> > +   module.modulemap \
> > +
> > +.if ${MACHINE_ARCH} == "aarch64" || ${MACHINE_ARCH} == "arm"
> > +HEADERS+=  arm_acle.h
> > +.elif ${MACHINE_ARCH} == "amd64" || ${MACHINE_ARCH} == "i386"
> > +HEADERS+=  adxintrin.h \
> > +   ammintrin.h \
> > +   avx2intrin.h \
> > +   avx512bwintrin.h \
> > +   avx512cdintrin.h \
> > +   avx512erintrin.h \
> > +   avx512fintrin.h \
> > +   avx512vlbwintrin.h \
> > +   avx512vlintrin.h \
> > +   avx512dqintrin.h \
> > +   avx512vldqintrin.h \
> > +   pkuintrin.h \
> > +   avxintrin.h \
> > +   bmi2intrin.h \
> > +   bmiintrin.h \
> > +   cpuid.h \
> > +   emmintrin.h \
> > +   f16cintrin.h \
> > +   fma4intrin.h \
> > +   fmaintrin.h \
> > +   fxsrintrin.h \
> > +   ia32intrin.h \
> > +   immintrin.h \
> > +   lzcntintrin.h \
> > +   mm3dnow.h \
> > +   mmintrin.h \
> > +   mm_malloc.h \
> > +   nmmintrin.h \
> > +   pmmintrin.h \
> > +   popcntintrin.h \
> > +   prfchwintrin.h \
> > +   rdseedintrin.h \
> > +   rtmintrin.h \
> > +   shaintrin.h \
> > +   smmintrin.h \
> > +   tbmintrin.h \
> > +   tmmintrin.h \
> > +   __wmmintrin_aes.h \
> > +   wmmintrin.h \
> > +   __wmmintrin_pclmul.h \
> > +   x86intrin.h \
> > +   xmmintrin.h \
> > +   xopintrin.h \
> > +   xsaveintrin.h \
> > +   xsaveoptintrin.h \
> > +   xsavecintrin.h \
> > +   xsavesintrin.h \
> > +   xtestintrin.h
> > +.elif ${MACHINE_ARCH} == "powerpc"
> > +HEADERS+=  altivec.h \
> > +   htmintrin.h \
> > +   htmxlintrin.h
> > +.endif
> >  
> >  all:   ${HEADERS}
> >  
> > 
> 



<    7   8   9   10   11   12   13   14   15   16   >