Re: multi-pool malloc wip diff

2016-03-28 Thread Daniel Micay
> - Curently fixed at 4 pools with a fixed thread -> pool mapping.
> - All pools are always initialized, even for single threaded programs,
> where
>   only one pool is used.
> - Especially realloc gets quite a bit uglier.
> - I'm pondering storing the thread -> pool mapping in the thread
>   struct instead of computing it each time from the tcb address.

If you wanted to get rid of the static mapping of threads to pools, it
would make sense to replace the per-pool region tables with a global, 2-
tier table. The first tier would be a table of mutexes paired with the
current style region tables, and it would pick the right one using a
secondary hash. It could be much larger than the number of pools to
avoid it being a bottleneck. This would eliminate the free / realloc
loops.

I don't think it would make sense right now, since it would add an extra
pair of lock / unlock calls to each malloc / free call in the common
case where allocations are freed by the allocating thread. If the thread
-> pool assignment was dynamic, it would be faster due to not needing
those loops. So if you wanted to do something like picking a random pool
each time, this would make a lot of sense. It would be increasingly
better with a larger number of pools.



vlan(4) doesnt have to filter its own mac address

2016-03-28 Thread David Gwynne
because the network stack does it for it on the way in.

the following chunk in src/sys/net/if_ethersubr.c does the same job
later on:

int
ether_input(struct ifnet *ifp, struct mbuf *m, void *cookie)
{
...
/*
 * If packet is unicast, make sure it is for us.  Drop otherwise.
 * This check is required in promiscous mode, and for some hypervisors
 * where the MAC filter is 'best effort' only.
 */
if ((m->m_flags & (M_BCAST|M_MCAST)) == 0) {
if (memcmp(ac->ac_enaddr, eh->ether_dhost, ETHER_ADDR_LEN)) {
m_freem(m);
return (1);
}
}
...

ok?

Index: if_vlan.c
===
RCS file: /cvs/src/sys/net/if_vlan.c,v
retrieving revision 1.157
diff -u -p -r1.157 if_vlan.c
--- if_vlan.c   29 Mar 2016 04:33:16 -  1.157
+++ if_vlan.c   29 Mar 2016 04:35:28 -
@@ -375,18 +375,6 @@ vlan_input(struct ifnet *ifp0, struct mb
goto drop;
 
/*
-* Drop promiscuously received packets if we are not in
-* promiscuous mode.
-*/
-   if (!ETHER_IS_MULTICAST(eh->ether_dhost) &&
-   (ifp0->if_flags & IFF_PROMISC) &&
-   (ifv->ifv_if.if_flags & IFF_PROMISC) == 0) {
-   if (bcmp(>ifv_ac.ac_enaddr, eh->ether_dhost,
-   ETHER_ADDR_LEN))
-   goto drop;
-   }
-
-   /*
 * Having found a valid vlan interface corresponding to
 * the given source interface and vlan tag, remove the
 * encapsulation.



manpages for bpf_mtap(9) and co

2016-03-28 Thread David Gwynne
im sure these could be improved, but that can be done in tree right?

ok?

Index: Makefile
===
RCS file: /cvs/src/share/man/man9/Makefile,v
retrieving revision 1.272
diff -u -p -r1.272 Makefile
--- Makefile15 Mar 2016 04:19:26 -  1.272
+++ Makefile29 Mar 2016 04:12:15 -
@@ -7,8 +7,8 @@ MAN=aml_evalnode.9 atomic_add_int.9 ato
atomic_dec_int.9 atomic_inc_int.9 atomic_setbits_int.9 \
atomic_sub_int.9 atomic_swap_uint.9 \
audio.9 autoconf.9 \
-   bemtoh32.9 bio_register.9 boot.9 buffercache.9 bufq_init.9 bus_dma.9 \
-   bus_space.9 \
+   bemtoh32.9 bio_register.9 boot.9 bpf_mtap.9 buffercache.9 bufq_init.9 \
+   bus_dma.9 bus_space.9 \
copy.9 config_attach.9 config_defer.9 crypto.9 delay.9 \
disk.9 disklabel.9 dma_alloc.9 dohooks.9 \
dostartuphooks.9 \
@@ -66,6 +66,8 @@ MLINKS+=bemtoh32.9 bemtoh16.9 bemtoh32.9
bemtoh32.9 lemtoh16.9 bemtoh32.9 lemtoh32.9 bemtoh32.9 lemtoh64.9 \
bemtoh32.9 htolem16.9 bemtoh32.9 htolem32.9 bemtoh32.9 htolem64.9
 MLINKS+=bio_register.9 bio_unregister.9
+MLINKS+=bpf_mtap.9 bpf_tap.9 bpf_mtap.9 bpf_mtap_hdr.9 \
+   bpf_mtap.9 bpf_tap_af.9 bpf_mtap.9 bpf_mtap_ether.9
 MLINKS+=buffercache.9 bread.9 buffercache.9 breadn.9 \
buffercache.9 bwrite.9 buffercache.9 bawrite.9 \
buffercache.9 bdwrite.9 buffercache.9 getblk.9 \
Index: bpf_mtap.9
===
RCS file: bpf_mtap.9
diff -N bpf_mtap.9
--- /dev/null   1 Jan 1970 00:00:00 -
+++ bpf_mtap.9  29 Mar 2016 04:12:15 -
@@ -0,0 +1,124 @@
+.\"$OpenBSD$
+.\"
+.\" Copyright (c) 2016 David Gwynne 
+.\"
+.\" 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 DAMAGES OR ANY DAMAGES
+.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+.\"
+.Dd $Mdocdate: March 29 2016 $
+.Dt BPF_MTAP 9
+.Os
+.Sh NAME
+.Nm bpf_mtap ,
+.Nm bpf_mtap_hdr ,
+.Nm bpf_mtap_af ,
+.Nm bpf_mtap_ether
+.Nd BPF kernel API
+.Sh SYNOPSIS
+.In net/bpf.h
+.Ft int
+.Fn bpf_tap "caddr_t bpf" "u_char *pkt" "u_int pktlen" "u_int direction"
+.Ft void
+.Fn bpf_mtap "caddr_t bpf" "struct mbuf *m" "u_int direction"
+.Ft void
+.Fo bpf_hdr
+.Fa "caddr_t bpf"
+.Fa "caddr_t hdr"
+.Fa "u_int hdrlen" 
+.Fa "struct mbuf *m"
+.Fa "u_int direction"
+.Fa "void (*cpfn)(const void *, void *, size_t)"
+.Fc
+.Ft void
+.Fn bpf_mtap_af "caddr_t bpf" "u_int32_t af" "struct mbuf *m" "u_int direction"
+.Ft void
+.Fn bpf_mtap_ether "caddr_t bpf" "struct mbuf *m" "u_int direction"
+.Sh DESCRIPTION
+The BPF kernel API provides incoming linkage from device drivers.
+A packet is parsed by the filters associated with each interface,
+and if accepted, stashed into the corresponding buffer.
+.Pp
+.Fn bfp_tap
+runs the filters on the BPF interface referenced by
+.Fa bpf
+in the direction
+.Fa direction
+against the packet in the
+.Fa pkt
+buffer.
+.Pp
+.Fn bfp_mtap
+runs the filters on the BPF interface referenced by
+.Fa bpf
+in the direction
+.Fa direction
+against the packet in mbuf chain
+.Fa m .
+.Pp
+.Fn bfp_mtap_hdr
+runs the filters on the BPF interface referenced by
+.Fa bpf
+in the direction
+.Fa direction
+against the packet in mbuf chain
+.Fa m .
+The header referenced by
+.Fa hdr
+will be prefixed to the packet during filter evaluation.
+A custom packet copy function may be provided via
+.Fa cpfn .
+If
+.Fa cpfn
+is
+.Dv NULL
+an internal function for copying mbuf payloads will be used.
+.Pp
+.Fn bpf_mtap_af
+runs the filters on the BPF interface referenced by
+.Fa bpf
+in the direction
+.Fa direction
+against the packet in mbuf chain
+.Fa m .
+The address family specified by
+.Fa af
+will be prepended to the packet before matching occurs.
+.Pp
+.Fn bpf_mtap_ether
+runs the filters on the BPF interface referenced by
+.Fa bpf
+in the direction
+.Fa direction
+against an Ethernet packet in the mbuf
+.Fa m .
+If the mbuf is flagged with
+.Dv M_VLANTAG
+an Ethernet VLAN header is constructed using
+m->m_pkthdr.ether_vtag
+and
+m->m_pkthdr.pf.prio
+before matching occurs.
+.Sh CONTEXT
+.Fn bpf_tap ,
+.Fn bpf_mtap ,
+.Fn bpf_mtap_hdr ,
+.Fn bpf_mtap_af ,
+and
+.Fn bpf_mtap_ether
+can be called from process context, or from an interrupt context at or below
+.Dv IPL_HIGH .
+.Sh RETURN VALUES
+.Fn bpf_tap
+returns 1 if the packet matched 

make bpf_mtap return whether to drop the packet or not

2016-03-28 Thread David Gwynne
the end goal is to be able to pass the mbuf as a const.

at the moment we still mark the packet with M_FILDROP to keep the
changes minimal, but that will change in a later diff.

ok?

Index: bpf.h
===
RCS file: /cvs/src/sys/net/bpf.h,v
retrieving revision 1.50
diff -u -p -r1.50 bpf.h
--- bpf.h   9 Mar 2016 16:32:19 -   1.50
+++ bpf.h   29 Mar 2016 03:10:10 -
@@ -275,11 +275,11 @@ struct ifnet;
 
 int bpf_validate(struct bpf_insn *, int);
 int bpf_tap(caddr_t, u_char *, u_int, u_int);
-voidbpf_mtap(caddr_t, struct mbuf *, u_int);
-voidbpf_mtap_hdr(caddr_t, caddr_t, u_int, struct mbuf *, u_int,
+int bpf_mtap(caddr_t, struct mbuf *, u_int);
+int bpf_mtap_hdr(caddr_t, caddr_t, u_int, struct mbuf *, u_int,
void (*)(const void *, void *, size_t));
-voidbpf_mtap_af(caddr_t, u_int32_t, struct mbuf *, u_int);
-voidbpf_mtap_ether(caddr_t, struct mbuf *, u_int);
+int bpf_mtap_af(caddr_t, u_int32_t, struct mbuf *, u_int);
+int bpf_mtap_ether(caddr_t, struct mbuf *, u_int);
 voidbpfattach(caddr_t *, struct ifnet *, u_int, u_int);
 voidbpfdetach(struct ifnet *);
 voidbpfilterattach(int);
Index: bpf.c
===
RCS file: /cvs/src/sys/net/bpf.c,v
retrieving revision 1.135
diff -u -p -r1.135 bpf.c
--- bpf.c   12 Feb 2016 18:56:12 -  1.135
+++ bpf.c   29 Mar 2016 03:10:10 -
@@ -92,7 +92,7 @@ LIST_HEAD(, bpf_d) bpf_d_list;
 void   bpf_allocbufs(struct bpf_d *);
 void   bpf_freed(struct bpf_d *);
 void   bpf_ifname(struct ifnet *, struct ifreq *);
-void   _bpf_mtap(caddr_t, struct mbuf *, u_int,
+int_bpf_mtap(caddr_t, struct mbuf *, u_int,
void (*)(const void *, void *, size_t));
 void   bpf_mcopy(const void *, void *, size_t);
 intbpf_movein(struct uio *, u_int, struct mbuf **,
@@ -1178,7 +1178,7 @@ bpf_tap(caddr_t arg, u_char *pkt, u_int 
KERNEL_UNLOCK();
 
if (d->bd_fildrop)
-   drop++;
+   drop = 1;
}
}
SRPL_LEAVE(, d);
@@ -1213,7 +1213,7 @@ bpf_mcopy(const void *src_arg, void *dst
 /*
  * like bpf_mtap, but copy fn can be given. used by various bpf_mtap*
  */
-void
+int
 _bpf_mtap(caddr_t arg, struct mbuf *m, u_int direction,
 void (*cpfn)(const void *, void *, size_t))
 {
@@ -1224,16 +1224,17 @@ _bpf_mtap(caddr_t arg, struct mbuf *m, u
struct mbuf *m0;
struct timeval tv;
int gottime = 0;
+   int drop = 0;
int s;
 
if (m == NULL)
-   return;
+   return (0);
 
if (cpfn == NULL)
cpfn = bpf_mcopy;
 
if (bp == NULL)
-   return;
+   return (0);
 
pktlen = 0;
for (m0 = m; m0 != NULL; m0 = m0->m_next)
@@ -1271,19 +1272,24 @@ _bpf_mtap(caddr_t arg, struct mbuf *m, u
KERNEL_UNLOCK();
 
if (d->bd_fildrop)
-   m->m_flags |= M_FILDROP;
+   drop = 1;
}
}
SRPL_LEAVE(, d);
+
+   if (drop)
+   m->m_flags |= M_FILDROP;
+
+   return (drop);
 }
 
 /*
  * Incoming linkage from device drivers, when packet is in an mbuf chain.
  */
-void
+int
 bpf_mtap(caddr_t arg, struct mbuf *m, u_int direction)
 {
-   _bpf_mtap(arg, m, direction, NULL);
+   return _bpf_mtap(arg, m, direction, NULL);
 }
 
 /*
@@ -1295,12 +1301,13 @@ bpf_mtap(caddr_t arg, struct mbuf *m, u_
  * fields in this header that we initialize, and will not try to free
  * it or keep a pointer to it.
  */
-void
+int
 bpf_mtap_hdr(caddr_t arg, caddr_t data, u_int dlen, struct mbuf *m,
 u_int direction, void (*cpfn)(const void *, void *, size_t))
 {
struct m_hdr mh;
struct mbuf *m0;
+   int drop;
 
if (dlen > 0) {
mh.mh_flags = 0;
@@ -1311,9 +1318,12 @@ bpf_mtap_hdr(caddr_t arg, caddr_t data, 
} else 
m0 = m;
 
-   _bpf_mtap(arg, m0, direction, cpfn);
+   drop = _bpf_mtap(arg, m0, direction, cpfn);
+
if (m0 != m)
m->m_flags |= m0->m_flags & M_FILDROP;
+
+   return (drop);
 }
 
 /*
@@ -1325,13 +1335,15 @@ bpf_mtap_hdr(caddr_t arg, caddr_t data, 
  * fields in this header that we initialize, and will not try to free
  * it or keep a pointer to it.
  */
-void
+int
 bpf_mtap_af(caddr_t arg, u_int32_t af, struct mbuf *m, u_int direction)
 {
u_int32_tafh;
 
afh = htonl(af);
-   bpf_mtap_hdr(arg, (caddr_t), sizeof(afh), m, direction, NULL);
+
+   return bpf_mtap_hdr(arg, (caddr_t), sizeof(afh),
+   m, direction, NULL);
 }
 
 /*
@@ -1343,31 +1355,40 @@ bpf_mtap_af(caddr_t arg, u_int32_t af, s
  * fields in this header that we initialize, and will not try 

Re: tcp syn cache random reseed

2016-03-28 Thread Alexander Bluhm
On Mon, Mar 21, 2016 at 12:58:41PM +0100, Alexander Bluhm wrote:
> The attack I see is that you can measure the bucket distribution
> by timing the SYN+ACK response.  You can collect samples that end
> in the same bucket.  After you have collected enough, start your
> DoS attack.  I think that just collecting data is also possible
> with a strong hash function.  With a weak function you may collect
> less and can start guessing early on top of that.  But reseeding
> after a number of packets prevents to collect information over a
> long peroid.

The syn cache already detects when it has too many bucket collisions.
That seems a good moment to reseed the hash function.

ok?

bluhm

Index: netinet/tcp_input.c
===
RCS file: /data/mirror/openbsd/cvs/src/sys/netinet/tcp_input.c,v
retrieving revision 1.316
diff -u -p -r1.316 tcp_input.c
--- netinet/tcp_input.c 27 Mar 2016 19:19:01 -  1.316
+++ netinet/tcp_input.c 28 Mar 2016 21:51:20 -
@@ -3400,6 +3400,12 @@ syn_cache_insert(struct syn_cache *sc, s
if (scp->sch_length >= tcp_syn_bucket_limit) {
tcpstat.tcps_sc_bucketoverflow++;
/*
+* Someone might attack our bucket hash function.  Reseed
+* with random as soon as the passive syn cache gets empty.
+*/
+   if (set->scs_use > 0)
+   set->scs_use = 0;
+   /*
 * The bucket is full.  Toss the oldest element in the
 * bucket.  This will be the first entry in the bucket.
 */



Re: tcp syn cache random reseed

2016-03-28 Thread Alexander Bluhm
On Mon, Mar 21, 2016 at 11:05:25AM +0100, Martin Pieuchot wrote:
> I like it.  Do you think it could be useful to export the value of the
> current active cache set and/or the value of ``tcp_syn_use_limit''?

When the active cache set switches, the reseed counter increments.
It might be usefull to see the current fill and use counter, but
that does not fit well in the tcpstat netstat counters.

The tcp_syn_use_limit can be added as sysctl.  Although we don't
like knobs, this one is useful to test the feature and may be handy
to defend against syn-flood in a denial of service condition.  It
is consistent to the existing two syn cache sysctls.

net.inet.tcp.syncachelimit=10255
net.inet.tcp.synbucketlimit=105
net.inet.tcp.synuselimit=10

I moved some declarations to tcp_var.h to access syn_cache_set from
tcp_sysctl().  Note that TCPCTL_VARS had a missing NULL before.

ok?

bluhm

Index: netinet/tcp_input.c
===
RCS file: /data/mirror/openbsd/cvs/src/sys/netinet/tcp_input.c,v
retrieving revision 1.316
diff -u -p -r1.316 tcp_input.c
--- netinet/tcp_input.c 27 Mar 2016 19:19:01 -  1.316
+++ netinet/tcp_input.c 28 Mar 2016 21:26:14 -
@@ -3255,19 +3255,12 @@ tcp_mss_adv(struct mbuf *m, int af)
  */
 
 /* syn hash parameters */
-#defineTCP_SYN_HASH_SIZE   293
-#defineTCP_SYN_BUCKET_SIZE 35
 inttcp_syn_cache_size = TCP_SYN_HASH_SIZE;
 inttcp_syn_cache_limit = TCP_SYN_HASH_SIZE*TCP_SYN_BUCKET_SIZE;
 inttcp_syn_bucket_limit = 3*TCP_SYN_BUCKET_SIZE;
 inttcp_syn_use_limit = 10;
 
-struct syn_cache_set {
-struct syn_cache_head scs_buckethead[TCP_SYN_HASH_SIZE];
-intscs_count;
-intscs_use;
-u_int32_t  scs_random[5];
-} tcp_syn_cache[2];
+struct syn_cache_set tcp_syn_cache[2];
 int tcp_syn_cache_active;
 
 #define SYN_HASH(sa, sp, dp, rand) \
Index: netinet/tcp_usrreq.c
===
RCS file: /data/mirror/openbsd/cvs/src/sys/netinet/tcp_usrreq.c,v
retrieving revision 1.129
diff -u -p -r1.129 tcp_usrreq.c
--- netinet/tcp_usrreq.c23 Mar 2016 15:50:36 -  1.129
+++ netinet/tcp_usrreq.c28 Mar 2016 21:48:23 -
@@ -933,6 +933,23 @@ tcp_sysctl(name, namelen, oldp, oldlenp,
return (sysctl_struct(oldp, oldlenp, newp, newlen,
, sizeof(tcpstat)));
 
+   case TCPCTL_SYN_USE_LIMIT:
+   error = sysctl_int(oldp, oldlenp, newp, newlen,
+   _syn_use_limit);
+   if (error)
+   return (error);
+   if (newp != NULL) {
+   /*
+* Global tcp_syn_use_limit is used when reseeding a
+* new cache.  Also update the value in active cache.
+*/
+   if (tcp_syn_cache[0].scs_use > tcp_syn_use_limit)
+   tcp_syn_cache[0].scs_use = tcp_syn_use_limit;
+   if (tcp_syn_cache[1].scs_use > tcp_syn_use_limit)
+   tcp_syn_cache[1].scs_use = tcp_syn_use_limit;
+   }
+   return (0);
+
default:
if (name[0] < TCPCTL_MAXID)
return (sysctl_int_arr(tcpctl_vars, name, namelen,
Index: netinet/tcp_var.h
===
RCS file: /data/mirror/openbsd/cvs/src/sys/netinet/tcp_var.h,v
retrieving revision 1.111
diff -u -p -r1.111 tcp_var.h
--- netinet/tcp_var.h   27 Mar 2016 19:19:01 -  1.111
+++ netinet/tcp_var.h   28 Mar 2016 21:26:14 -
@@ -251,6 +251,10 @@ struct tcp_opt_info {
 /*
  * Data for the TCP compressed state engine.
  */
+
+#defineTCP_SYN_HASH_SIZE   293
+#defineTCP_SYN_BUCKET_SIZE 35
+
 union syn_cache_sa {
struct sockaddr sa;
struct sockaddr_in sin;
@@ -311,6 +315,13 @@ struct syn_cache_head {
u_short sch_length; /* # entries in bucket */
 };
 
+struct syn_cache_set {
+struct syn_cache_head scs_buckethead[TCP_SYN_HASH_SIZE];
+intscs_count;
+intscs_use;
+u_int32_t  scs_random[5];
+};
+
 #endif /* _KERNEL */
 
 /*
@@ -478,7 +489,8 @@ struct  tcpstat {
 #defineTCPCTL_SACKHOLE_LIMIT  20 /* max entries for tcp sack queues */
 #defineTCPCTL_STATS   21 /* TCP statistics */
 #defineTCPCTL_ALWAYS_KEEPALIVE 22 /* assume SO_KEEPALIVE is always set 
*/
-#defineTCPCTL_MAXID   23
+#defineTCPCTL_SYN_USE_LIMIT   23 /* number of uses before reseeding 
hash */
+#defineTCPCTL_MAXID   24
 
 #defineTCPCTL_NAMES { \
{ 0, 0 }, \
@@ -503,7 +515,8 @@ struct  tcpstat {
{ "drop",   CTLTYPE_STRUCT }, \
{ "sackholelimit",  CTLTYPE_INT }, \
  

Cleaner way to disable acpivout(4)

2016-03-28 Thread Mark Kettenis
Simply don'tmatch if the ws_get_param or ws_set_param callback has
been set.  That way we don't need the platform-specific acpi driver
"enabled" variables anymore.

ok?


Index: acpi.c
===
RCS file: /cvs/src/sys/dev/acpi/acpi.c,v
retrieving revision 1.306
diff -u -p -r1.306 acpi.c
--- acpi.c  28 Mar 2016 19:12:17 -  1.306
+++ acpi.c  28 Mar 2016 21:08:22 -
@@ -121,10 +121,6 @@ intacpi_add_device(struct aml_node *nod
 void   acpi_thread(void *);
 void   acpi_create_thread(void *);
 
-intacpi_thinkpad_enabled;
-intacpi_toshiba_enabled;
-intacpi_asus_enabled;
-
 #ifndef SMALL_KERNEL
 
 void   acpi_indicator(struct acpi_softc *, int);
@@ -1097,10 +1093,8 @@ acpi_attach(struct device *parent, struc
/* attach docks */
aml_find_node(_root, "_DCK", acpi_founddock, sc);
 
-   /* attach video only if this is not a thinkpad or toshiba */
-   if (!acpi_thinkpad_enabled && !acpi_toshiba_enabled &&
-   !acpi_asus_enabled)
-   aml_find_node(_root, "_DOS", acpi_foundvideo, sc);
+   /* attach video */
+   aml_find_node(_root, "_DOS", acpi_foundvideo, sc);
 
/* create list of devices we want to query when APM comes in */
SLIST_INIT(>sc_ac);
@@ -2779,18 +2773,6 @@ acpi_foundhid(struct aml_node *node, voi
aaa.aaa_memt = sc->sc_memt;
aaa.aaa_node = node->parent;
aaa.aaa_dev = dev;
-
-   if (!strcmp(dev, ACPI_DEV_ASUS) ||
-   !strcmp(dev, ACPI_DEV_ASUS1)) {
-   acpi_asus_enabled = 1;
-   } else if (!strcmp(dev, ACPI_DEV_IBM) ||
-   !strcmp(dev, ACPI_DEV_LENOVO)) {
-   acpi_thinkpad_enabled = 1;
-   } else if (!strcmp(dev, ACPI_DEV_TOSHIBA_LIBRETTO) ||
-   !strcmp(dev, ACPI_DEV_TOSHIBA_DYNABOOK) ||
-   !strcmp(dev, ACPI_DEV_TOSHIBA_SPA40)) {
-   acpi_toshiba_enabled = 1;
-   }
 
 #ifndef SMALL_KERNEL
if (!strcmp(cdev, ACPI_DEV_MOUSE)) {
Index: acpivout.c
===
RCS file: /cvs/src/sys/dev/acpi/acpivout.c,v
retrieving revision 1.11
diff -u -p -r1.11 acpivout.c
--- acpivout.c  14 Mar 2015 03:38:47 -  1.11
+++ acpivout.c  28 Mar 2016 21:08:22 -
@@ -94,6 +94,9 @@ acpivout_match(struct device *parent, vo
aaa->aaa_table != NULL)
return (0);
 
+   if (ws_get_param || ws_set_param)
+   return (0);
+
return (1);
 }
 



Re: let's get reference to state key back

2016-03-28 Thread Alexandr Nedvedicky
Hello,

> i can't see any problem with this patch. i'm sending 14Mpps ip4 and ip6
> over ix intefaces and creating around 3M to 5M states and all this more
> than 24 hours. box is unusable but it's alive :)

thank you very much for testing. let's wait day or two to give other folks
chance to trip panics/leaks.

the patch you've kindly tried is tiny step, which prepares PF for
gentle/gradual unlock.

regards
sashan



Re: Scheduler hack for multi-threaded processes

2016-03-28 Thread Henrik Friedrichsen
Hey,

On Mon, Mar 28, 2016 at 02:00:13PM +0200, Alexandre Ratchov wrote:
> do you mean that sound stuttes if the diff is applied but doesn't
> stutter without the diff?

Stuttering may have been an exaggeration. It's more of a short, bassy
click than a stutter, really.

Could be that it already did this before and I just hadn't noticed. I'll
observe it more closely and report back, should I have something more
accurate.



dwiic attach

2016-03-28 Thread Mark Kettenis
The diff below makes the dwiic(4) driver's match function behave like
the other acpi attach functions by matching on the _HID.  This way it
will continue to atach with the diff I sent out earlier today.

I deliberately did not use the #define's from acpireg.h here.  I
intend to remove those.  Just listing the strings in the driver makes
it easier to check to what IDs the driver attaches.

ok?


Index: dwiic.c
===
RCS file: /cvs/src/sys/dev/acpi/dwiic.c,v
retrieving revision 1.9
diff -u -p -r1.9 dwiic.c
--- dwiic.c 22 Jan 2016 22:57:23 -  1.9
+++ dwiic.c 28 Mar 2016 18:34:32 -
@@ -196,6 +196,15 @@ struct cfdriver dwiic_cd = {
NULL, "dwiic", DV_DULL
 };
 
+const char *dwiic_hids[] = {
+   "INT33C2",
+   "INT33C3",
+   "INT3432",
+   "INT3433",
+   "80860F41",
+   NULL
+};
+
 int
 dwiic_match(struct device *parent, void *match, void *aux)
 {
@@ -203,9 +212,7 @@ dwiic_match(struct device *parent, void 
struct cfdata *cf = match;
int64_t sta;
 
-   if (aaa->aaa_name == NULL ||
-   strcmp(aaa->aaa_name, cf->cf_driver->cd_name) != 0 ||
-   aaa->aaa_table != NULL)
+   if (!acpi_matchhids(aaa, dwiic_hids, cf->cf_driver->cd_name))
return 0;
 
if (aml_evalinteger((struct acpi_softc *)parent, aaa->aaa_node,



acpi device attachment

2016-03-28 Thread Mark Kettenis
Adding each and every new acpi device driver to acpi_foundhid() is
gettingabit of the burden.  And it really isn't how our autoconf
framework is supposed to work for busses that can be enumerated.  All
the drivers already check for a matching _HID in their attach
function.  So we can just drop the checks in acpi_foundhid() and let
the drivers sort themselves out.

The checks for acpithinkpad(4), acpitoshiba(4) and acpiasus(4) remain
for now as they set a variable that prevents acpivideo(3) from
attaching.  I have some ideas for a better mechanism there as well.

The diff also adds code that prints a "not configured" line for
devices for which we don't attach a driver.  That may be a bit much as
there are tons of devices for which we will not have a driver.  But
I'm somewhat curious to see the results.  So I'd like to commit it and
remove it in the future if it causes too much dmesg pollution.

ok?


Index: acpi.c
===
RCS file: /cvs/src/sys/dev/acpi/acpi.c,v
retrieving revision 1.305
diff -u -p -r1.305 acpi.c
--- acpi.c  17 Jan 2016 09:04:18 -  1.305
+++ acpi.c  28 Mar 2016 17:06:49 -
@@ -1155,6 +1155,8 @@ acpi_print(void *aux, const char *pnp)
if (pnp) {
if (aa->aaa_name)
printf("%s at %s", aa->aaa_name, pnp);
+   else if (aa->aaa_dev)
+   printf("\"%s\" at %s", aa->aaa_dev, pnp);
else
return (QUIET);
}
@@ -2778,37 +2780,16 @@ acpi_foundhid(struct aml_node *node, voi
aaa.aaa_node = node->parent;
aaa.aaa_dev = dev;
 
-   if (!strcmp(dev, ACPI_DEV_AC)) {
-   aaa.aaa_name = "acpiac";
-   } else if (!strcmp(dev, ACPI_DEV_CMB)) {
-   aaa.aaa_name = "acpibat";
-   } else if (!strcmp(dev, ACPI_DEV_LD) ||
-   !strcmp(dev, ACPI_DEV_PBD) ||
-   !strcmp(dev, ACPI_DEV_SBD)) {
-   aaa.aaa_name = "acpibtn";
-   } else if (!strcmp(dev, ACPI_DEV_ASUS) ||
+   if (!strcmp(dev, ACPI_DEV_ASUS) ||
!strcmp(dev, ACPI_DEV_ASUS1)) {
-   aaa.aaa_name = "acpiasus";
acpi_asus_enabled = 1;
} else if (!strcmp(dev, ACPI_DEV_IBM) ||
!strcmp(dev, ACPI_DEV_LENOVO)) {
-   aaa.aaa_name = "acpithinkpad";
acpi_thinkpad_enabled = 1;
-   } else if (!strcmp(dev, ACPI_DEV_ASUSAIBOOSTER)) {
-   aaa.aaa_name = "aibs";
} else if (!strcmp(dev, ACPI_DEV_TOSHIBA_LIBRETTO) ||
!strcmp(dev, ACPI_DEV_TOSHIBA_DYNABOOK) ||
!strcmp(dev, ACPI_DEV_TOSHIBA_SPA40)) {
-   aaa.aaa_name = "acpitoshiba";
acpi_toshiba_enabled = 1;
-   } else if (!strcmp(dev, "80860F14") || !strcmp(dev, "PNP0FFF")) {
-   aaa.aaa_name = "sdhc";
-   } else if (!strcmp(dev, ACPI_DEV_DWIIC1) ||
-   !strcmp(dev, ACPI_DEV_DWIIC2) ||
-   !strcmp(dev, ACPI_DEV_DWIIC3) ||
-   !strcmp(dev, ACPI_DEV_DWIIC4) ||
-   !strcmp(dev, ACPI_DEV_DWIIC5)) {
-   aaa.aaa_name = "dwiic";
}
 
 #ifndef SMALL_KERNEL
@@ -2822,8 +2803,7 @@ acpi_foundhid(struct aml_node *node, voi
}
 #endif
 
-   if (aaa.aaa_name)
-   config_found(self, , acpi_print);
+   config_found(self, , acpi_print);
 
return (0);
 }



Re: acpi gpio support

2016-03-28 Thread Mark Kettenis
> Date: Mon, 28 Mar 2016 21:49:39 +1100
> From: Jonathan Gray 
> 
> On Sun, Mar 27, 2016 at 09:28:25PM +0200, Mark Kettenis wrote:
> > The diff below is a first stab at adding support for GPIOs as defined
> > in ACPI 5.0.  The primary target for this new ACPI feature is hardware
> > reduced platforms like those based on Intel's Bay Trail SoC.  The diff
> > adds a bytgpio(4) driver for the hardware found on that SoC.  This
> > driver registers itself with the acpi framework by setting the struct
> > acpi_gpio pointer on the AML node for the device.  Then this gets used
> > by the acpi sdhc(4) frontend to use the appropriate gpio as the card
> > detect signal.  This makes it possible to detectwhether a card is
> > inserted when the kernel boots.  Support for GPIO-based interrupts is
> > still missing, so hotplugging SD cards doesn't work yet.
> > 
> > There are some debug printfs here that will disappear eventually.
> > 
> > ok?
> 
> Works on ideapad 100s:
> 
> bytgpio0 at acpi0: GPO0 uid 1 addr 0xfed0c000/0x1000 irq 49, 102 pins
> bytgpio1 at acpi0: GPO1 uid 2 addr 0xfed0d000/0x1000 irq 48, 28 pins
> bytgpio2 at acpi0: GPO2 uid 3 addr 0xfed0e000/0x1000 irq 50, 44 pins
> sdhc0 at acpi0: SDHA addr 0x9091d000/0x1000 irq 44
> sdmmc0 at sdhc0
> sdhc at acpi0 not configured
> sdhc1 at acpi0: SDHD GPO0 pin 38
>  tflags 0x1d
>  ppi 0x3
>  drs 0x0
>  dbt 0x2710
>  GPO0 pin 38
>  tflags 0x9
>  ppi 0x0
>  drs 0x0
>  dbt 0x0
>  addr 0x90903000/0x1000 irq 47
> sdmmc1 at sdhc1
> 
> ...
> 
> scsibus1 at sdmmc0: 2 targets, initiator 0
> sd0 at scsibus1 targ 1 lun 0:  SCSI2 0/direct fixed
> sd0: 29820MB, 512 bytes/sector, 61071360 sectors
> scsibus2 at sdmmc1: 2 targets, initiator 0
> sd1 at scsibus2 targ 1 lun 0:  SCSI2 0/direct fixed
> sd1: 15271MB, 512 bytes/sector, 31275008 sectors
> 
> sdmmc0 is emmc sdmmc1 is a usd card in the slot.
> 
> Though after some network traffic over usb the machine seems to hang.
> Opening new windows in tmux over ssh works but shells don't spawn.
> I can still type locally (with the polling diff) but can't login on tty.
> 
> Is it possible this somehow enables gpio interrupts that we then
> don't acknowledge?

I don't think so.  Given the symptoms I'd say it is more likely that
the sdmmc interrupt gets stuck.



Re: acpi gpio support

2016-03-28 Thread Mark Kettenis
> Date: Sun, 27 Mar 2016 20:29:29 -0700
> From: Philip Guenther 
> 
> On Sun, Mar 27, 2016 at 12:28 PM, Mark Kettenis  
> wrote:
> > The diff below is a first stab at adding support for GPIOs as defined
> > in ACPI 5.0.  The primary target for this new ACPI feature is hardware
> > reduced platforms like those based on Intel's Bay Trail SoC.  The diff
> > adds a bytgpio(4) driver for the hardware found on that SoC.  This
> > driver registers itself with the acpi framework by setting the struct
> > acpi_gpio pointer on the AML node for the device.  Then this gets used
> > by the acpi sdhc(4) frontend to use the appropriate gpio as the card
> > detect signal.  This makes it possible to detectwhether a card is
> > inserted when the kernel boots.  Support for GPIO-based interrupts is
> > still missing, so hotplugging SD cards doesn't work yet.
> >
> > There are some debug printfs here that will disappear eventually.
> >
> > ok?
> 
> Not really specific to this driver, but should we be using letoh16()
> and similar when accessing the fields like pin_off?  We do so in a few
> acpi drivers, but many do not and I'm not aware of any big-endian
> archs that are looking to use ACPI ("here, have another albatross!").

In theory there could be future big-endian ARM systems with ACPI
firmware.  Let's worry about those if we ever see one that we want to
support.

> > +/*
> > + * The pads for the pins are randomly ordered.
> > + */
> > +
> > +const int byt_score_pins[] = {
> 
> These values from some Intel doc?

I took them from the Linux driver.  It is possible to figure out the
mapping from the Intel docs.

> ...
> > +   switch (uid) {
> > +   case 1:
> > +   sc->sc_pins = byt_score_pins;
> > +   sc->sc_npins = nitems(byt_score_pins);
> 
> ok...
> 
> > +   break;
> > +   case 2:
> > +   sc->sc_pins = byt_score_pins;
> > +   sc->sc_npins = nitems(byt_ncore_pins);
> 
> Uh, mismatch here and on the next.  Shouldn't sc_pins be set to
> byt_ncore_pins and byt_sus_pins?

Yes.  Fixed.

> > +   break;
> > +   case 3:
> > +   sc->sc_pins = byt_score_pins;
> > +   sc->sc_npins = nitems(byt_sus_pins);

Thanks,

Mark



handle bogus sparc64 frame buffers

2016-03-28 Thread Miod Vallat
Some sparc64 pci frame buffers incorrectly have the `depth' property
spelled `depth ' with a trailing space.

This can be found in this E450 eeprom -p output:
  http://pastebin.com/P4ab4Xt4

Because of this, gfxp(4) attaches believing the display is only 8bpp,
and the display gets garbled.

The following diff will fix this issue. I don't think sparc needs a
similar fix as there are no Sun sparc systems with pci slots.

Index: fb.c
===
RCS file: /OpenBSD/src/sys/arch/sparc64/dev/fb.c,v
retrieving revision 1.25
diff -u -p -r1.25 fb.c
--- fb.c21 Oct 2013 10:36:19 -  1.25
+++ fb.c28 Mar 2016 12:54:32 -
@@ -131,7 +131,12 @@ fb_setsize(struct sunfb *sf, int def_dep
 {
int def_linebytes;
 
-   sf->sf_depth = getpropint(node, "depth", def_depth);
+   /*
+* Some PCI devices lack the `depth' property, but have a `depth '
+* property (with a trailing space) instead.
+*/
+   sf->sf_depth = getpropint(node, "depth",
+   getpropint(node, "depth ", def_depth));
sf->sf_width = getpropint(node, "width", def_width);
sf->sf_height = getpropint(node, "height", def_height);
 



lpd systrace policy update

2016-03-28 Thread Ray Lai
Probably going to be obsolete once lpd gets pledged, but as it stands, 
the lpd systrace policy is missing these system calls.


Index: usr_sbin_lpd
===
RCS file: /home/cvs/src/etc/systrace/usr_sbin_lpd,v
retrieving revision 1.9
diff -u -p -u -p -r1.9 usr_sbin_lpd
--- usr_sbin_lpd13 Sep 2015 17:08:04 -  1.9
+++ usr_sbin_lpd28 Mar 2016 14:11:40 -
@@ -12,7 +12,9 @@ Policy: /usr/sbin/lpd, Emulation: native
native-chdir: permit
native-chmod: filename eq "/var/run/printer" then permit
native-chown: filename eq "/var/run/printer" then permit
+   native-clock_gettime: permit
native-close: permit
+   native-connect: sockaddr eq "/var/run/printer" then permit
native-connect: sockaddr match "inet-*:53" then permit
native-connect: sockaddr sub ":515" then permit
native-dup2: permit
@@ -30,6 +32,7 @@ Policy: /usr/sbin/lpd, Emulation: native
native-fsread: filename eq "/etc/spwd.db" then deny[eperm]
native-fsread: filename eq "/usr/libexec/ld.so" then permit
native-fsread: filename eq "/var/run/ld.so.hints" then permit
+   native-fsread: filename eq "/var/run/ypbind.lock" then permit
native-fsread: filename eq "" then deny[enoent]
native-fsread: filename match "/usr/lib" then permit
native-fsread: filename match "/usr/share/nls" then permit



Re: make vlan(4) remember its parent by index, not by reference

2016-03-28 Thread David Gwynne

> On 23 Mar 2016, at 12:36 AM, Masao Uebayashi  wrote:
> 
> On Tue, Mar 22, 2016 at 09:36:18PM +1000, David Gwynne wrote:
>> this basically makes the code use if_get instead of carrying a
>> pointer around. this is as mechanical as i can make it.
>> 
>> ok?
>> 
>> Index: if_vlan_var.h
>> ===
>> RCS file: /cvs/src/sys/net/if_vlan_var.h,v
>> retrieving revision 1.33
>> diff -u -p -r1.33 if_vlan_var.h
>> --- if_vlan_var.h14 Mar 2016 03:48:47 -  1.33
>> +++ if_vlan_var.h22 Mar 2016 11:34:45 -
>> @@ -61,9 +61,8 @@ struct vlan_mc_entry {
>> 
>> struct   ifvlan {
>>  struct  arpcom ifv_ac;  /* make this an interface */
>> -struct  ifnet *ifv_p;   /* parent interface of this vlan */
>> +unsigned int ifv_p; /* parent interface of this vlan */
>>  struct  ifv_linkmib {
>> -int ifvm_parent;
>>  u_int16_t ifvm_proto; /* encapsulation ethertype */
>>  u_int16_t ifvm_tag; /* tag to apply on packets leaving if */
>>  u_int16_t ifvm_prio; /* prio to apply on packet leaving if */
>> Index: if_vlan.c
>> ===
>> RCS file: /cvs/src/sys/net/if_vlan.c,v
>> retrieving revision 1.155
>> diff -u -p -r1.155 if_vlan.c
>> --- if_vlan.c18 Mar 2016 02:40:04 -  1.155
>> +++ if_vlan.c22 Mar 2016 11:34:45 -
>> @@ -235,7 +235,12 @@ vlan_start(struct ifnet *ifp)
>>  uint8_t  prio;
>> 
>>  ifv = ifp->if_softc;
>> -ifp0 = ifv->ifv_p;
>> +ifp0 = if_get(ifv->ifv_p);
>> +if (ifp0 == NULL || (ifp0->if_flags & (IFF_UP|IFF_RUNNING)) !=
>> +(IFF_UP|IFF_RUNNING)) {
>> +ifq_purge(>if_snd);
> 
> You can't dereference ifp if (ifp0 == NULL)?

ifp is a pointer to the vlan interface, and ifp0 is supposed to be its parent. 
the vlan interface can exist after its parent is detached.

> 
>> +goto leave;
>> +}
>> 
>>  for (;;) {
>>  IFQ_DEQUEUE(>if_snd, m);
>> @@ -247,12 +252,6 @@ vlan_start(struct ifnet *ifp)
>>  bpf_mtap_ether(ifp->if_bpf, m, BPF_DIRECTION_OUT);
>> #endif /* NBPFILTER > 0 */
>> 
>> -if ((ifp0->if_flags & (IFF_UP|IFF_RUNNING)) !=
>> -(IFF_UP|IFF_RUNNING)) {
>> -ifp->if_oerrors++;
>> -m_freem(m);
>> -continue;
>> -}
>> 
>>  /* IEEE 802.1p has prio 0 and 1 swapped */
>>  prio = m->m_pkthdr.pf.prio;
>> @@ -290,6 +289,9 @@ vlan_start(struct ifnet *ifp)
>>  }
>>  ifp->if_opackets++;
>>  }
>> +
>> +leave:
>> +if_put(ifp0);
>> }
>> 
>> struct mbuf *
>> @@ -358,7 +360,7 @@ vlan_input(struct ifnet *ifp0, struct mb
>> 
>>  list = [TAG_HASH(tag)];
>>  SRPL_FOREACH(ifv, list, , ifv_list) {
>> -if (ifp0 == ifv->ifv_p && tag == ifv->ifv_tag &&
>> +if (ifp0->if_index == ifv->ifv_p && tag == ifv->ifv_tag &&
>>  etype == ifv->ifv_type)
>>  break;
>>  }
>> @@ -417,13 +419,13 @@ vlan_config(struct ifvlan *ifv, struct i
>> 
>>  if (ifp0->if_type != IFT_ETHER)
>>  return EPROTONOSUPPORT;
>> -if (ifv->ifv_p == ifp0 && ifv->ifv_tag == tag) /* noop */
>> +if (ifp0->if_index == ifv->ifv_p && ifv->ifv_tag == tag) /* noop */
>>  return (0);
>> 
>>  /* Remember existing interface flags and reset the interface */
>>  flags = ifv->ifv_flags;
>>  vlan_unconfig(>ifv_if, ifp0);
>> -ifv->ifv_p = ifp0;
>> +ifv->ifv_p = ifp0->if_index;
>>  ifv->ifv_if.if_baudrate = ifp0->if_baudrate;
>> 
>>  if (ifp0->if_capabilities & IFCAP_VLAN_MTU) {
>> @@ -509,8 +511,9 @@ vlan_unconfig(struct ifnet *ifp, struct 
>>  struct ifnet*ifp0;
>> 
>>  ifv = ifp->if_softc;
>> -if ((ifp0 = ifv->ifv_p) == NULL)
>> -return 0;
>> +ifp0 = if_get(ifv->ifv_p);
>> +if (ifp0 == NULL)
>> +goto disconnect;
>> 
>>  /* Unset promisc mode on the interface and its parent */
>>  if (ifv->ifv_flags & IFVF_PROMISC) {
>> @@ -544,8 +547,9 @@ vlan_unconfig(struct ifnet *ifp, struct 
>>   */
>>  vlan_multi_apply(ifv, ifp0, SIOCDELMULTI);
>> 
>> +disconnect:
>>  /* Disconnect from parent. */
>> -ifv->ifv_p = NULL;
>> +ifv->ifv_p = 0;
>>  ifv->ifv_if.if_mtu = ETHERMTU;
>>  ifv->ifv_if.if_hardmtu = ETHERMTU;
>>  ifv->ifv_flags = 0;
> 
> So you're changing error code path here?  I'm not sure this correctness
> but I'd change this separately.

its not really an error path, its cleanup. again, if the parent has detached 
then this is where we need to reset the vlan interface state.

> 
>> @@ -557,6 +561,8 @@ vlan_unconfig(struct ifnet *ifp, struct 
>>  bzero(LLADDR(sdl), ETHER_ADDR_LEN);
>>  bzero(ifv->ifv_ac.ac_enaddr, ETHER_ADDR_LEN);
>> 
>> +if_put(ifp0);
>> +
>>  

Re: Scheduler hack for multi-threaded processes

2016-03-28 Thread Alexandre Ratchov
On Mon, Mar 28, 2016 at 12:41:01PM +0200, Henrik Friedrichsen wrote:
> Can confirm all the reports regarding desktop apps becoming more
> responsive. I do, however, experience sound stutters, e.g. when playing
> music in the browser (Google Play Music) or movies with mpv.

do you mean that sound stuttes if the diff is applied but doesn't
stutter without the diff?



Re: multi-pool malloc wip diff

2016-03-28 Thread Henrik Friedrichsen
Just a subjective opinion (if that counts as feedback):

This in combination with the scheduler patch by mpi@ seems to greatly
improve the browsing experience with Chrome, esp. when opening/closing
tabs, which I suppose involves a lot of memory management calls?

Other than that I haven't noticed any regressions, yet.



Re: acpi gpio support

2016-03-28 Thread Jonathan Gray
On Sun, Mar 27, 2016 at 09:28:25PM +0200, Mark Kettenis wrote:
> The diff below is a first stab at adding support for GPIOs as defined
> in ACPI 5.0.  The primary target for this new ACPI feature is hardware
> reduced platforms like those based on Intel's Bay Trail SoC.  The diff
> adds a bytgpio(4) driver for the hardware found on that SoC.  This
> driver registers itself with the acpi framework by setting the struct
> acpi_gpio pointer on the AML node for the device.  Then this gets used
> by the acpi sdhc(4) frontend to use the appropriate gpio as the card
> detect signal.  This makes it possible to detectwhether a card is
> inserted when the kernel boots.  Support for GPIO-based interrupts is
> still missing, so hotplugging SD cards doesn't work yet.
> 
> There are some debug printfs here that will disappear eventually.
> 
> ok?

Works on ideapad 100s:

bytgpio0 at acpi0: GPO0 uid 1 addr 0xfed0c000/0x1000 irq 49, 102 pins
bytgpio1 at acpi0: GPO1 uid 2 addr 0xfed0d000/0x1000 irq 48, 28 pins
bytgpio2 at acpi0: GPO2 uid 3 addr 0xfed0e000/0x1000 irq 50, 44 pins
sdhc0 at acpi0: SDHA addr 0x9091d000/0x1000 irq 44
sdmmc0 at sdhc0
sdhc at acpi0 not configured
sdhc1 at acpi0: SDHD GPO0 pin 38
 tflags 0x1d
 ppi 0x3
 drs 0x0
 dbt 0x2710
 GPO0 pin 38
 tflags 0x9
 ppi 0x0
 drs 0x0
 dbt 0x0
 addr 0x90903000/0x1000 irq 47
sdmmc1 at sdhc1

...

scsibus1 at sdmmc0: 2 targets, initiator 0
sd0 at scsibus1 targ 1 lun 0:  SCSI2 0/direct fixed
sd0: 29820MB, 512 bytes/sector, 61071360 sectors
scsibus2 at sdmmc1: 2 targets, initiator 0
sd1 at scsibus2 targ 1 lun 0:  SCSI2 0/direct fixed
sd1: 15271MB, 512 bytes/sector, 31275008 sectors

sdmmc0 is emmc sdmmc1 is a usd card in the slot.

Though after some network traffic over usb the machine seems to hang.
Opening new windows in tmux over ssh works but shells don't spawn.
I can still type locally (with the polling diff) but can't login on tty.

Is it possible this somehow enables gpio interrupts that we then
don't acknowledge?

> 
> 
> Index: acpi.c
> ===
> RCS file: /cvs/src/sys/dev/acpi/acpi.c,v
> retrieving revision 1.305
> diff -u -p -r1.305 acpi.c
> --- acpi.c17 Jan 2016 09:04:18 -  1.305
> +++ acpi.c27 Mar 2016 19:18:31 -
> @@ -2801,6 +2801,8 @@ acpi_foundhid(struct aml_node *node, voi
>   !strcmp(dev, ACPI_DEV_TOSHIBA_SPA40)) {
>   aaa.aaa_name = "acpitoshiba";
>   acpi_toshiba_enabled = 1;
> + } else if (!strcmp(dev, "INT33FC")) {
> + aaa.aaa_name = "bytgpio";
>   } else if (!strcmp(dev, "80860F14") || !strcmp(dev, "PNP0FFF")) {
>   aaa.aaa_name = "sdhc";
>   } else if (!strcmp(dev, ACPI_DEV_DWIIC1) ||
> Index: amltypes.h
> ===
> RCS file: /cvs/src/sys/dev/acpi/amltypes.h,v
> retrieving revision 1.40
> diff -u -p -r1.40 amltypes.h
> --- amltypes.h7 Sep 2012 19:19:59 -   1.40
> +++ amltypes.h27 Mar 2016 19:18:31 -
> @@ -364,6 +364,11 @@ struct acpi_pci {
>   int _s4w;
>  };
>  
> +struct acpi_gpio {
> + void*cookie;
> + int (*read_pin)(void *, int);
> +};
> +
>  struct aml_node {
>   struct aml_node *parent;
>  
> @@ -377,6 +382,7 @@ struct aml_node {
>  
>   struct aml_value *value;
>   struct acpi_pci  *pci;
> + struct acpi_gpio *gpio;
>  };
>  
>  #define aml_bitmask(n)   (1L << ((n) & 0x7))
> Index: bytgpio.c
> ===
> RCS file: bytgpio.c
> diff -N bytgpio.c
> --- /dev/null 1 Jan 1970 00:00:00 -
> +++ bytgpio.c 27 Mar 2016 19:18:31 -
> @@ -0,0 +1,242 @@
> +/*   $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 DAMAGES OR ANY DAMAGES
> + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
> + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
> + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
> + */
> +
> +#include 
> +#include 
> +#include 
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#define BYTGPIO_PAD_VAL  0x0001
> +
> +struct bytgpio_softc {
> + struct device sc_dev;
> + struct acpi_softc *sc_acpi;
> + struct aml_node *sc_node;
> +
> + bus_space_tag_t sc_memt;
> + bus_space_handle_t sc_memh;
> + bus_addr_t sc_addr;
> + 

Re: Scheduler hack for multi-threaded processes

2016-03-28 Thread Henrik Friedrichsen
Can confirm all the reports regarding desktop apps becoming more
responsive. I do, however, experience sound stutters, e.g. when playing
music in the browser (Google Play Music) or movies with mpv.

Interestingly, this does not seem to happen when playing YouTube videos.



Re: multi-pool malloc wip diff

2016-03-28 Thread Otto Moerbeek
On Mon, Mar 28, 2016 at 11:43:22AM +0200, Otto Moerbeek wrote:

> No specifics, just watch out for malloc related bugs. It's
> both important that non-threaded programs and non-threaded programs
> show no new bugs.

And don't forget to test non-threaded programs ;-)



Re: multi-pool malloc wip diff

2016-03-28 Thread Otto Moerbeek
On Mon, Mar 28, 2016 at 03:40:21AM -0600, Abel Abraham Camarillo Ojeda wrote:

> On Mon, Mar 28, 2016 at 3:27 AM, Otto Moerbeek  wrote:
> > On Wed, Mar 23, 2016 at 08:00:19AM +0100, Otto Moerbeek wrote:
> >
> >> Hi,
> >>
> >> first diff that seems to work. Tested on amd64 and compile tested on
> >> sparc64.
> >>
> >> It is alo available at http://www.drijf.net/openbsd/malloc
> >>
> >> Form the README:
> >>
> >> The diff should be applied while in /usr/src/lib, it will patch
> >> both librthreads as as well as libc.
> >>
> >> THIS IS WORK IN PROGRESS. It contains multiple things that should
> >> be improved. To name a few things:
> >>
> >> - Curently fixed at 4 pools with a fixed thread -> pool mapping.
> >> - All pools are always initialized, even for single threaded programs, 
> >> where
> >>   only one pool is used.
> >> - Especially realloc gets quite a bit uglier.
> >> - I'm pondering storing the thread -> pool mapping in the thread
> >>   struct instead of computing it each time from the tcb address.
> >>
> >>   -Otto
> >>
> >
> > Second diff. Only one person (Stefan Kempf, thanks!) gave feedback...
> >
> > A race condition was fixed in the init code. But there remain race
> > problems in the init code. I will be working on that the coming time.
> >
> > Please be aware that to make this code ready for commit, I need
> > feedback/tests/reviews. There's no way this code will end up in the tree
> > without those.
> >
> 
> Hi Otto,
> 
> anything specific to test or general desktop-browser-use testing is enough?
> 
> thanks

No specifics, just watch out for malloc related bugs. It's
both important that non-threaded programs and non-threaded programs
show no new bugs.


-Otto

> 
> 
> > -Otto
> >
> >
> > Index: libc/include/thread_private.h
> > ===
> > RCS file: /cvs/src/lib/libc/include/thread_private.h,v
> > retrieving revision 1.26
> > diff -u -p -r1.26 thread_private.h
> > --- libc/include/thread_private.h   7 Apr 2015 01:27:07 -   1.26
> > +++ libc/include/thread_private.h   28 Mar 2016 08:22:31 -
> > @@ -17,6 +17,8 @@
> >   */
> >  extern int __isthreaded;
> >
> > +#define _MALLOC_MUTEXES 4
> > +
> >  /*
> >   * Weak symbols are used in libc so that the thread library can
> >   * efficiently wrap libc functions.
> > @@ -136,16 +138,16 @@ extern void *__THREAD_NAME(serv_mutex);
> >  /*
> >   * malloc lock/unlock prototypes and definitions
> >   */
> > -void   _thread_malloc_lock(void);
> > -void   _thread_malloc_unlock(void);
> > +void   _thread_malloc_lock(int);
> > +void   _thread_malloc_unlock(int);
> >
> > -#define _MALLOC_LOCK() do {\
> > +#define _MALLOC_LOCK(n)do {
> > \
> > if (__isthreaded)   \
> > -   _thread_malloc_lock();  \
> > +   _thread_malloc_lock(n); \
> > } while (0)
> > -#define _MALLOC_UNLOCK()   do {\
> > +#define _MALLOC_UNLOCK(n)  do {\
> > if (__isthreaded)   \
> > -   _thread_malloc_unlock();\
> > +   _thread_malloc_unlock(n);\
> > } while (0)
> >
> >  void   _thread_atexit_lock(void);
> > Index: libc/stdlib/malloc.c
> > ===
> > RCS file: /cvs/src/lib/libc/stdlib/malloc.c,v
> > retrieving revision 1.185
> > diff -u -p -r1.185 malloc.c
> > --- libc/stdlib/malloc.c17 Mar 2016 17:55:33 -  1.185
> > +++ libc/stdlib/malloc.c28 Mar 2016 08:22:31 -
> > @@ -1,6 +1,6 @@
> >  /* $OpenBSD: malloc.c,v 1.185 2016/03/17 17:55:33 mmcc Exp $   */
> >  /*
> > - * Copyright (c) 2008, 2010, 2011 Otto Moerbeek 
> > + * Copyright (c) 2008, 2010, 2011, 2016 Otto Moerbeek 
> >   * Copyright (c) 2012 Matthew Dempsky 
> >   * Copyright (c) 2008 Damien Miller 
> >   * Copyright (c) 2000 Poul-Henning Kamp 
> > @@ -43,6 +43,7 @@
> >  #endif
> >
> >  #include "thread_private.h"
> > +#include 
> >
> >  #if defined(__sparc__) && !defined(__sparcv9__)
> >  #define MALLOC_PAGESHIFT   (13U)
> > @@ -95,10 +96,10 @@
> >
> >  #define _MALLOC_LEAVE(d) do { if (__isthreaded) { \
> > (d)->active--; \
> > -   _MALLOC_UNLOCK(); } \
> > +   _MALLOC_UNLOCK(d->mutex); } \
> >  } while (0)
> >  #define _MALLOC_ENTER(d) do { if (__isthreaded) { \
> > -   _MALLOC_LOCK(); \
> > +   _MALLOC_LOCK(d->mutex); \
> > (d)->active++; } \
> >  } while (0)
> >
> > @@ -129,6 +130,7 @@ 

Re: multi-pool malloc wip diff

2016-03-28 Thread Abel Abraham Camarillo Ojeda
On Mon, Mar 28, 2016 at 3:27 AM, Otto Moerbeek  wrote:
> On Wed, Mar 23, 2016 at 08:00:19AM +0100, Otto Moerbeek wrote:
>
>> Hi,
>>
>> first diff that seems to work. Tested on amd64 and compile tested on
>> sparc64.
>>
>> It is alo available at http://www.drijf.net/openbsd/malloc
>>
>> Form the README:
>>
>> The diff should be applied while in /usr/src/lib, it will patch
>> both librthreads as as well as libc.
>>
>> THIS IS WORK IN PROGRESS. It contains multiple things that should
>> be improved. To name a few things:
>>
>> - Curently fixed at 4 pools with a fixed thread -> pool mapping.
>> - All pools are always initialized, even for single threaded programs, where
>>   only one pool is used.
>> - Especially realloc gets quite a bit uglier.
>> - I'm pondering storing the thread -> pool mapping in the thread
>>   struct instead of computing it each time from the tcb address.
>>
>>   -Otto
>>
>
> Second diff. Only one person (Stefan Kempf, thanks!) gave feedback...
>
> A race condition was fixed in the init code. But there remain race
> problems in the init code. I will be working on that the coming time.
>
> Please be aware that to make this code ready for commit, I need
> feedback/tests/reviews. There's no way this code will end up in the tree
> without those.
>

Hi Otto,

anything specific to test or general desktop-browser-use testing is enough?

thanks


> -Otto
>
>
> Index: libc/include/thread_private.h
> ===
> RCS file: /cvs/src/lib/libc/include/thread_private.h,v
> retrieving revision 1.26
> diff -u -p -r1.26 thread_private.h
> --- libc/include/thread_private.h   7 Apr 2015 01:27:07 -   1.26
> +++ libc/include/thread_private.h   28 Mar 2016 08:22:31 -
> @@ -17,6 +17,8 @@
>   */
>  extern int __isthreaded;
>
> +#define _MALLOC_MUTEXES 4
> +
>  /*
>   * Weak symbols are used in libc so that the thread library can
>   * efficiently wrap libc functions.
> @@ -136,16 +138,16 @@ extern void *__THREAD_NAME(serv_mutex);
>  /*
>   * malloc lock/unlock prototypes and definitions
>   */
> -void   _thread_malloc_lock(void);
> -void   _thread_malloc_unlock(void);
> +void   _thread_malloc_lock(int);
> +void   _thread_malloc_unlock(int);
>
> -#define _MALLOC_LOCK() do {\
> +#define _MALLOC_LOCK(n)do {  
>   \
> if (__isthreaded)   \
> -   _thread_malloc_lock();  \
> +   _thread_malloc_lock(n); \
> } while (0)
> -#define _MALLOC_UNLOCK()   do {\
> +#define _MALLOC_UNLOCK(n)  do {\
> if (__isthreaded)   \
> -   _thread_malloc_unlock();\
> +   _thread_malloc_unlock(n);\
> } while (0)
>
>  void   _thread_atexit_lock(void);
> Index: libc/stdlib/malloc.c
> ===
> RCS file: /cvs/src/lib/libc/stdlib/malloc.c,v
> retrieving revision 1.185
> diff -u -p -r1.185 malloc.c
> --- libc/stdlib/malloc.c17 Mar 2016 17:55:33 -  1.185
> +++ libc/stdlib/malloc.c28 Mar 2016 08:22:31 -
> @@ -1,6 +1,6 @@
>  /* $OpenBSD: malloc.c,v 1.185 2016/03/17 17:55:33 mmcc Exp $   */
>  /*
> - * Copyright (c) 2008, 2010, 2011 Otto Moerbeek 
> + * Copyright (c) 2008, 2010, 2011, 2016 Otto Moerbeek 
>   * Copyright (c) 2012 Matthew Dempsky 
>   * Copyright (c) 2008 Damien Miller 
>   * Copyright (c) 2000 Poul-Henning Kamp 
> @@ -43,6 +43,7 @@
>  #endif
>
>  #include "thread_private.h"
> +#include 
>
>  #if defined(__sparc__) && !defined(__sparcv9__)
>  #define MALLOC_PAGESHIFT   (13U)
> @@ -95,10 +96,10 @@
>
>  #define _MALLOC_LEAVE(d) do { if (__isthreaded) { \
> (d)->active--; \
> -   _MALLOC_UNLOCK(); } \
> +   _MALLOC_UNLOCK(d->mutex); } \
>  } while (0)
>  #define _MALLOC_ENTER(d) do { if (__isthreaded) { \
> -   _MALLOC_LOCK(); \
> +   _MALLOC_LOCK(d->mutex); \
> (d)->active++; } \
>  } while (0)
>
> @@ -129,6 +130,7 @@ struct dir_info {
> void *delayed_chunks[MALLOC_DELAYED_CHUNK_MASK + 1];
> size_t rbytesused;  /* random bytes used */
> char *func; /* current function */
> +   int mutex;
> u_char rbytes[32];  /* random bytes */
> u_short chunk_start;
>  #ifdef MALLOC_STATS
> @@ -178,7 +180,7 @@ struct chunk_info {
>  };
>
>  struct malloc_readonly {
> -   struct dir_info *malloc_pool;   /* Main bookkeeping information 

Re: uvm: enable amap per-page refcounting unconditionally

2016-03-28 Thread Stefan Kempf
Miod Vallat wrote:
> 
> > It seems per-page reference counting is used since forever. I think
> > there's no reason to ever turn it off (and track referenced pages
> > with less accuracy, causing leaks).
> 
> Actually, assuming the #undef code path works, it might work keeping
> this and only defining UVM_AMAP_PPREF iff defined(SMALL_KERNEL).

Doing this saves around 1.6K on bsd.rd/amd64.

Would that be preferred over removing the #ifdefs?

textdatabss dec hex
4736948 2409000 577536  7723484 75d9dc
4738636 2409000 577536  7725172 75e074
 
diff --git a/uvm/uvm_amap.h b/uvm/uvm_amap.h
index a98b440..a768e94 100644
--- a/uvm/uvm_amap.h
+++ b/uvm/uvm_amap.h
@@ -119,7 +119,9 @@ boolean_t   amap_swap_off(int, int);
  * ... this is enabled with the "UVM_AMAP_PPREF" define.
  */
 
-#define UVM_AMAP_PPREF /* track partial references */
+#ifndef SMALL_KERNEL
+# define UVM_AMAP_PPREF/* track partial references */
+#endif
 
 /*
  * here is the definition of the vm_amap structure for this implementation.



Re: multi-pool malloc wip diff

2016-03-28 Thread Otto Moerbeek
On Wed, Mar 23, 2016 at 08:00:19AM +0100, Otto Moerbeek wrote:

> Hi,
> 
> first diff that seems to work. Tested on amd64 and compile tested on
> sparc64. 
> 
> It is alo available at http://www.drijf.net/openbsd/malloc
> 
> Form the README:
> 
> The diff should be applied while in /usr/src/lib, it will patch
> both librthreads as as well as libc.
> 
> THIS IS WORK IN PROGRESS. It contains multiple things that should
> be improved. To name a few things:
> 
> - Curently fixed at 4 pools with a fixed thread -> pool mapping.
> - All pools are always initialized, even for single threaded programs, where
>   only one pool is used.
> - Especially realloc gets quite a bit uglier.
> - I'm pondering storing the thread -> pool mapping in the thread
>   struct instead of computing it each time from the tcb address.
> 
>   -Otto
> 

Second diff. Only one person (Stefan Kempf, thanks!) gave feedback...

A race condition was fixed in the init code. But there remain race
problems in the init code. I will be working on that the coming time.

Please be aware that to make this code ready for commit, I need
feedback/tests/reviews. There's no way this code will end up in the tree 
without those.

-Otto


Index: libc/include/thread_private.h
===
RCS file: /cvs/src/lib/libc/include/thread_private.h,v
retrieving revision 1.26
diff -u -p -r1.26 thread_private.h
--- libc/include/thread_private.h   7 Apr 2015 01:27:07 -   1.26
+++ libc/include/thread_private.h   28 Mar 2016 08:22:31 -
@@ -17,6 +17,8 @@
  */
 extern int __isthreaded;
 
+#define _MALLOC_MUTEXES 4
+
 /*
  * Weak symbols are used in libc so that the thread library can
  * efficiently wrap libc functions.
@@ -136,16 +138,16 @@ extern void *__THREAD_NAME(serv_mutex);
 /*
  * malloc lock/unlock prototypes and definitions
  */
-void   _thread_malloc_lock(void);
-void   _thread_malloc_unlock(void);
+void   _thread_malloc_lock(int);
+void   _thread_malloc_unlock(int);
 
-#define _MALLOC_LOCK() do {\
+#define _MALLOC_LOCK(n)do {
\
if (__isthreaded)   \
-   _thread_malloc_lock();  \
+   _thread_malloc_lock(n); \
} while (0)
-#define _MALLOC_UNLOCK()   do {\
+#define _MALLOC_UNLOCK(n)  do {\
if (__isthreaded)   \
-   _thread_malloc_unlock();\
+   _thread_malloc_unlock(n);\
} while (0)
 
 void   _thread_atexit_lock(void);
Index: libc/stdlib/malloc.c
===
RCS file: /cvs/src/lib/libc/stdlib/malloc.c,v
retrieving revision 1.185
diff -u -p -r1.185 malloc.c
--- libc/stdlib/malloc.c17 Mar 2016 17:55:33 -  1.185
+++ libc/stdlib/malloc.c28 Mar 2016 08:22:31 -
@@ -1,6 +1,6 @@
 /* $OpenBSD: malloc.c,v 1.185 2016/03/17 17:55:33 mmcc Exp $   */
 /*
- * Copyright (c) 2008, 2010, 2011 Otto Moerbeek 
+ * Copyright (c) 2008, 2010, 2011, 2016 Otto Moerbeek 
  * Copyright (c) 2012 Matthew Dempsky 
  * Copyright (c) 2008 Damien Miller 
  * Copyright (c) 2000 Poul-Henning Kamp 
@@ -43,6 +43,7 @@
 #endif
 
 #include "thread_private.h"
+#include 
 
 #if defined(__sparc__) && !defined(__sparcv9__)
 #define MALLOC_PAGESHIFT   (13U)
@@ -95,10 +96,10 @@
 
 #define _MALLOC_LEAVE(d) do { if (__isthreaded) { \
(d)->active--; \
-   _MALLOC_UNLOCK(); } \
+   _MALLOC_UNLOCK(d->mutex); } \
 } while (0)
 #define _MALLOC_ENTER(d) do { if (__isthreaded) { \
-   _MALLOC_LOCK(); \
+   _MALLOC_LOCK(d->mutex); \
(d)->active++; } \
 } while (0)
 
@@ -129,6 +130,7 @@ struct dir_info {
void *delayed_chunks[MALLOC_DELAYED_CHUNK_MASK + 1];
size_t rbytesused;  /* random bytes used */
char *func; /* current function */
+   int mutex;
u_char rbytes[32];  /* random bytes */
u_short chunk_start;
 #ifdef MALLOC_STATS
@@ -178,7 +180,7 @@ struct chunk_info {
 };
 
 struct malloc_readonly {
-   struct dir_info *malloc_pool;   /* Main bookkeeping information */
+   struct dir_info *malloc_pool[_MALLOC_MUTEXES];  /* Main bookkeeping 
information */
int malloc_freenow; /* Free quickly - disable chunk rnd */
int malloc_freeunmap;   /* mprotect free pages PROT_NONE? */
int malloc_hint;/* call madvice on free pages?  */
@@ -202,14 +204,13 @@ static union {

Re: www.openbsd.org/cgi-bin/man.cgi

2016-03-28 Thread bytevolcano
I was thinking more of having a Javascript implementation of OpenBSD so
that you could type the 'man' command to get the page you are after.

It will only increase the size of the page by about 400MB, and hard
disk and CPU space is cheap.

And everyone has infinite bandwidth internet.

On Fri, 25 Mar 2016 09:24:29 -0600
Bob Beck  wrote:

> Now now, we can be more hipster than that.. a docker image that runs
> the man command for you after downloading
> all the openbsd man pages as a dependency - you can just deploy it
> automatically with vagrant and run it in AWS.. etc.
> 
> After all, isn't there no simple command that can't be made better by
> installing an os image someone else built to run?
> 
> 
> 
> 
> On Fri, Mar 25, 2016 at 8:45 AM, Ingo Schwarze 
> wrote:
> > Hi Gilles,
> >
> > Gilles Chehade wrote on Fri, Mar 25, 2016 at 03:34:02PM +0100:
> >  
> >> maybe we could provide MaaS (man as a service, copyright eric@)
> >>
> >> if user issues `man` and the man page is not found locally, man
> >> would transparently ssh to gu...@man.openbsd.org ?  
> >
> > Hilarious on so many levels...  :-D
> >   Ingo
> >  
> 



Re: wsdisplay_compat_usl/KDENABIO: no need to specisal case i386

2016-03-28 Thread Jeremie Courreges-Anglas
Matthieu Herrb  writes:

> Hi,
>
> OpenBSD has stopped using the SVr4 KDENABIO/KDDISABIO ioctls for at
> least 10 years. No need for special treatement on i386.
>
> ok?

yup

-- 
jca | PGP : 0x1524E7EE / 5135 92C1 AD36 5293 2BDF  DDCC 0DFA 74AE 1524 E7EE