Re: Completely disable 2D acceleration on Broadwell

2015-12-01 Thread Jonathan Gray
On Tue, Dec 01, 2015 at 04:44:39PM +0100, Mark Kettenis wrote:
> As tedu@ reported (and some pople on misc@ confirmed) partly disabling
> 2D acceleration on Broadwell made X unstable.  It really looks like
> the alternative BLT path isn't well tested and therefore buggy.  So
> here is a diff that disables 2D acceleration completely.  Those who
> don't care about suspend/resume can still enable it if they want.  3D
> acceleration should continue to work.
> 
> ok?

chrome and mplayer seem basically unuseable with this.  Perhaps it
should be those who want to suspend/resume can run the modesetting
driver or disable acceleration via xorg.conf.

> 
> 
> Index: sna_accel.c
> ===
> RCS file: /home/cvs/xenocara/driver/xf86-video-intel/src/sna/sna_accel.c,v
> retrieving revision 1.6
> diff -u -p -r1.6 sna_accel.c
> --- sna_accel.c   15 Nov 2015 15:33:57 -  1.6
> +++ sna_accel.c   1 Dec 2015 15:37:44 -
> @@ -17659,6 +17659,9 @@ static bool sna_option_accel_none(struct
>   return true;
>  
>   s = xf86GetOptValString(sna->Options, OPTION_ACCEL_METHOD);
> + /* XXX avoid render ring since it gets stuck after resume */
> + if (s == NULL && sna->info->gen >= 0100)
> + return true;
>   if (s == NULL)
>   return IS_DEFAULT_ACCEL_METHOD(NOACCEL);
>  
> @@ -17670,9 +17673,6 @@ static bool sna_option_accel_blt(struct 
>   const char *s;
>  
>   s = xf86GetOptValString(sna->Options, OPTION_ACCEL_METHOD);
> - /* XXX avoid render ring since it gets stuck after resume */
> - if (s == NULL && sna->info->gen >= 0100)
> - return true;
>   if (s == NULL)
>   return false;
>  
> 



unifdef(1) - in-place editing without backups

2015-12-01 Thread Michael McConville
unifdef's -M option is like sed's -i option, editing in-place and saving
a backup with the supplied extension.

Currently, if -M '' is passed:

 * the original file is copied to the backup filename (i.e. itself)

 * the temp file is copied to the original filename

It therefore has the same behavior as sed -i ''. However, this
is brittle and maybe even inadvertent. It's also undocumented.

The below diff:

 * adds a sentence from sed(1) to the man page

 * only creates a backup file when it's actually a backup file (no nop
   copying)

Am I understanding correctly? ok?


Index: unifdef.1
===
RCS file: /cvs/src/usr.bin/unifdef/unifdef.1,v
retrieving revision 1.24
diff -u -p -r1.24 unifdef.1
--- unifdef.1   12 Sep 2015 15:27:38 -  1.24
+++ unifdef.1   2 Dec 2015 04:44:15 -
@@ -312,6 +312,9 @@ Modify input files in place, and keep ba
 appending the
 .Ar backext
 to the input filenames.
+If a zero length
+.Ar extension
+is given, no backup will be saved.
 .Pp
 .It Fl m
 Modify one or more input files in place.
Index: unifdef.c
===
RCS file: /cvs/src/usr.bin/unifdef/unifdef.c,v
retrieving revision 1.24
diff -u -p -r1.24 unifdef.c
--- unifdef.c   9 Oct 2015 01:37:09 -   1.24
+++ unifdef.c   2 Dec 2015 04:44:15 -
@@ -425,7 +425,7 @@ processinout(const char *ifn, const char
 
process();
 
-   if (backext != NULL) {
+   if (backext != NULL && *backext != '\0') {
char *backname = astrcat(ofn, backext);
if (rename(ofn, backname) < 0)
err(2, "can't rename \"%s\" to \"%s\"", ofn, backname);



IPsec: remove unimplemented algorithms

2015-12-01 Thread Christian Weisgerber
pfkeyv2.h has defines for a number of obsolete algorithms we don't and
won't implement.  These have been mechanically added to ipsecctl and
iked.  I'd like to remove all traces of these zombies.
(SADB_X_AALG_DES designates DES-MAC authentication.)

ok?


Index: sys/net/pfkeyv2.h
===
RCS file: /cvs/src/sys/net/pfkeyv2.h,v
retrieving revision 1.70
diff -u -p -r1.70 pfkeyv2.h
--- sys/net/pfkeyv2.h   3 Nov 2015 01:50:36 -   1.70
+++ sys/net/pfkeyv2.h   1 Dec 2015 21:31:24 -
@@ -285,7 +285,6 @@ struct sadb_x_tap {
 #define SADB_AALG_NONE   0
 #define SADB_AALG_MD5HMAC2
 #define SADB_AALG_SHA1HMAC   3
-#define SADB_X_AALG_DES  4
 #define SADB_X_AALG_SHA2_256 5
 #define SADB_X_AALG_SHA2_384 6
 #define SADB_X_AALG_SHA2_512 7
@@ -297,16 +296,10 @@ struct sadb_x_tap {
 #define SADB_AALG_MAX12
 
 #define SADB_EALG_NONE0
-#define SADB_X_EALG_DES_IV64  1
 #define SADB_EALG_DESCBC  2
 #define SADB_EALG_3DESCBC 3
-#define SADB_X_EALG_RC5   4
-#define SADB_X_EALG_IDEA  5
 #define SADB_X_EALG_CAST  6
 #define SADB_X_EALG_BLF   7
-#define SADB_X_EALG_3IDEA 8
-#define SADB_X_EALG_DES_IV32  9
-#define SADB_X_EALG_RC4   10
 #define SADB_EALG_NULL11
 #define SADB_X_EALG_AES   12
 #define SADB_X_EALG_AESCTR13
Index: sbin/iked/pfkey.c
===
RCS file: /cvs/src/sbin/iked/pfkey.c,v
retrieving revision 1.47
diff -u -p -r1.47 pfkey.c
--- sbin/iked/pfkey.c   4 Nov 2015 12:40:49 -   1.47
+++ sbin/iked/pfkey.c   1 Dec 2015 21:32:29 -
@@ -69,16 +69,10 @@ struct pfkey_constmap {
 };
 
 static const struct pfkey_constmap pfkey_encr[] = {
-   { SADB_X_EALG_DES_IV64, IKEV2_XFORMENCR_DES_IV64 },
{ SADB_EALG_DESCBC, IKEV2_XFORMENCR_DES },
{ SADB_EALG_3DESCBC,IKEV2_XFORMENCR_3DES },
-   { SADB_X_EALG_RC5,  IKEV2_XFORMENCR_RC5 },
-   { SADB_X_EALG_IDEA, IKEV2_XFORMENCR_IDEA },
{ SADB_X_EALG_CAST, IKEV2_XFORMENCR_CAST },
{ SADB_X_EALG_BLF,  IKEV2_XFORMENCR_BLOWFISH },
-   { SADB_X_EALG_3IDEA,IKEV2_XFORMENCR_3IDEA },
-   { SADB_X_EALG_DES_IV32, IKEV2_XFORMENCR_DES_IV32 },
-   { SADB_X_EALG_RC4,  IKEV2_XFORMENCR_RC4 },
{ SADB_EALG_NULL,   IKEV2_XFORMENCR_NULL },
{ SADB_X_EALG_AES,  IKEV2_XFORMENCR_AES_CBC },
{ SADB_X_EALG_AESCTR,   IKEV2_XFORMENCR_AES_CTR },
@@ -91,7 +85,6 @@ static const struct pfkey_constmap pfkey
 static const struct pfkey_constmap pfkey_integr[] = {
{ SADB_AALG_MD5HMAC,IKEV2_XFORMAUTH_HMAC_MD5_96 },
{ SADB_AALG_SHA1HMAC,   IKEV2_XFORMAUTH_HMAC_SHA1_96 },
-   { SADB_X_AALG_DES,  IKEV2_XFORMAUTH_DES_MAC },
{ SADB_X_AALG_SHA2_256, IKEV2_XFORMAUTH_HMAC_SHA2_256_128 },
{ SADB_X_AALG_SHA2_384, IKEV2_XFORMAUTH_HMAC_SHA2_384_192 },
{ SADB_X_AALG_SHA2_512, IKEV2_XFORMAUTH_HMAC_SHA2_512_256 },
Index: sbin/ipsecctl/pfkdump.c
===
RCS file: /cvs/src/sbin/ipsecctl/pfkdump.c,v
retrieving revision 1.40
diff -u -p -r1.40 pfkdump.c
--- sbin/ipsecctl/pfkdump.c 4 Nov 2015 12:46:13 -   1.40
+++ sbin/ipsecctl/pfkdump.c 1 Dec 2015 21:32:04 -
@@ -141,7 +141,6 @@ struct idname sa_types[] = {
 
 struct idname auth_types[] = {
{ SADB_AALG_NONE,   "none", NULL },
-   { SADB_X_AALG_DES,  "des",  NULL },
{ SADB_AALG_MD5HMAC,"hmac-md5", NULL },
{ SADB_X_AALG_RIPEMD160HMAC,"hmac-ripemd160",   NULL },
{ SADB_AALG_SHA1HMAC,   "hmac-sha1",NULL },
@@ -159,19 +158,13 @@ struct idname enc_types[] = {
{ SADB_EALG_NONE,   "none", NULL },
{ SADB_EALG_3DESCBC,"3des-cbc", NULL },
{ SADB_EALG_DESCBC, "des-cbc",  NULL },
-   { SADB_X_EALG_3IDEA,"idea3",NULL },
{ SADB_X_EALG_AES,  "aes",  NULL },
{ SADB_X_EALG_AESCTR,   "aesctr",   NULL },
{ SADB_X_EALG_AESGCM16, "aes-gcm",  NULL },
{ SADB_X_EALG_AESGMAC,  "aes-gmac", NULL },
{ SADB_X_EALG_BLF,  "blowfish", NULL },
{ SADB_X_EALG_CAST, "cast128",  NULL },
-   { SADB_X_EALG_DES_IV32, "des-iv32", NULL },
-   { SADB_X_EALG_DES_IV64, "des-iv64", NULL },
-   { SADB_X_EALG_IDEA, "idea", NULL },
{ SADB_EALG_NULL,   "null", NULL },
-   { SADB_X_EALG_RC4,  "rc4",  NULL },
-   { SADB_X_EALG_RC5,

ssh-agent: flush stdout before main loop in foreground mode

2015-12-01 Thread Dustin Lundquist
When ssh-agent is run in foreground mode with -d and stdout is not a
terminal, the output including the path to the listening socket and
PID may not be written before the main loop begins. Since no further
output is written to stdout, this output may never be written.

$ ssh-agent -d < /dev/null 2> /dev/null | cat
^C
$

This behavior is important when wrapping ssh-agent in another daemon.

Thank you,


Dustin Lundquist


Index: usr.bin/ssh/ssh-agent.c
===
RCS file: /cvs/src/usr.bin/ssh/ssh-agent.c,v
retrieving revision 1.204
diff -u -r1.204 ssh-agent.c
--- usr.bin/ssh/ssh-agent.c 8 Jul 2015 20:24:02 - 1.204
+++ usr.bin/ssh/ssh-agent.c 1 Dec 2015 22:05:17 -
@@ -1301,6 +1301,7 @@
  printf(format, SSH_AUTHSOCKET_ENV_NAME, socket_name,
 SSH_AUTHSOCKET_ENV_NAME);
  printf("echo Agent pid %ld;\n", (long)parent_pid);
+ fflush(stdout);
  goto skip;
  }
  pid = fork();



Re: pledge dhcpd(8), 1st attempt

2015-12-01 Thread Stuart Henderson
On 2015/12/01 21:24, Ricardo Mestre wrote:
> Hi tech@
> 
> This is my first attempt at pledging dhcpd(8), right now I don't have time to
> go further, but this is a working diff I having seating at my tree I want to
> show you, although tomorrow I intend to get back at it.
> 
> Declare usage() as __dead since it never returns, hoist up sync_init() since 
> it
> calls a setsockopt(2) for multicast not allowed (yet?) by pledge(2) so I
> (someone else?) can apply pledge ealier on and then finally if dhcpd(8) was 
> NOT
> called with "-u" parameter (!udpsockmode) then request "inet" since this is a
> network daemon and therefore needs to perform network operations and "sendfd"
> to send a msg.
> 
> For this last annotation I changed sendto(2) to sendmsg(2) in icmp.c so we
> don't have to give permissions to the daemon it doesn't need and it just sends
> an ICMP echo request (hey here is a DHCPOFFER) to the host that is requesting
> an IP address.

Don't these (sendto, sendmsg) need the same permissions anyway?

> +++ icmp.c1 Dec 2015 20:59:31 -
..
>   icmp.icmp_cksum = wrapsum(checksum((unsigned char *)&icmp,
> - sizeof(icmp), 0));
> + sizeof(icmp), 0));
> + 

KNF here, the previous indentation was correct



pledge dhcpd(8), 1st attempt

2015-12-01 Thread Ricardo Mestre
Hi tech@

This is my first attempt at pledging dhcpd(8), right now I don't have time to
go further, but this is a working diff I having seating at my tree I want to
show you, although tomorrow I intend to get back at it.

Declare usage() as __dead since it never returns, hoist up sync_init() since it
calls a setsockopt(2) for multicast not allowed (yet?) by pledge(2) so I
(someone else?) can apply pledge ealier on and then finally if dhcpd(8) was NOT
called with "-u" parameter (!udpsockmode) then request "inet" since this is a
network daemon and therefore needs to perform network operations and "sendfd"
to send a msg.

For this last annotation I changed sendto(2) to sendmsg(2) in icmp.c so we
don't have to give permissions to the daemon it doesn't need and it just sends
an ICMP echo request (hey here is a DHCPOFFER) to the host that is requesting
an IP address.

Index: dhcpd.c
===
RCS file: /cvs/src/usr.sbin/dhcpd/dhcpd.c,v
retrieving revision 1.48
diff -u -p -u -r1.48 dhcpd.c
--- dhcpd.c 10 Feb 2015 23:06:13 -  1.48
+++ dhcpd.c 1 Dec 2015 20:59:27 -
@@ -45,7 +45,7 @@
 #include 
 #include 
 
-void usage(void);
+__dead void usage(void);
 
 time_t cur_time, last_scan;
 struct group root_group;
@@ -187,16 +187,16 @@ main(int argc, char *argv[])
if (setrtable(rdomain) == -1)
error("setrtable (%m)");
 
-   if (udpsockmode)
-   udpsock_startup(udpaddr);
-   icmp_startup(1, lease_pinged);
-
if (syncsend || syncrecv) {
syncfd = sync_init(sync_iface, sync_baddr, sync_port);
if (syncfd == -1)
err(1, "sync init");
}
 
+   if (udpsockmode)
+   udpsock_startup(udpaddr);
+   icmp_startup(1, lease_pinged);
+
if ((pw = getpwnam("_dhcp")) == NULL)
error("user \"_dhcp\" not found");
 
@@ -236,6 +236,10 @@ main(int argc, char *argv[])
setresuid(pw->pw_uid, pw->pw_uid, pw->pw_uid))
error("can't drop privileges: %m");
 
+   if (!udpsockmode)
+   if (pledge("stdio inet sendfd", NULL) == -1)
+   err(1, "pledge");
+
add_timeout(cur_time + 5, periodic_scan, NULL);
dispatch();
 
@@ -243,7 +247,7 @@ main(int argc, char *argv[])
exit(0);
 }
 
-void
+__dead void
 usage(void)
 {
extern char *__progname;
Index: icmp.c
===
RCS file: /cvs/src/usr.sbin/dhcpd/icmp.c,v
retrieving revision 1.13
diff -u -p -u -r1.13 icmp.c
--- icmp.c  25 Oct 2014 03:23:49 -  1.13
+++ icmp.c  1 Dec 2015 20:59:31 -
@@ -80,6 +80,8 @@ icmp_echorequest(struct iaddr *addr)
 {
struct sockaddr_in to;
struct icmp icmp;
+   struct msghdr msg;
+   struct iovec iov;
int status;
 
if (!icmp_protocol_initialized)
@@ -97,11 +99,22 @@ icmp_echorequest(struct iaddr *addr)
icmp.icmp_id = getpid() & 0x;
 
icmp.icmp_cksum = wrapsum(checksum((unsigned char *)&icmp,
-   sizeof(icmp), 0));
+   sizeof(icmp), 0));
+   
+   iov.iov_base = &icmp;
+   iov.iov_len = sizeof(struct icmp);
+
+   memset(&msg, 0, sizeof(msg));
+   msg.msg_name = &to;
+   msg.msg_namelen = sizeof(to);
+   msg.msg_iov = &iov;
+   msg.msg_iovlen = 1;
+   msg.msg_control = 0;
+   msg.msg_controllen = 0;
+   msg.msg_flags = 0;
 
/* Send the ICMP packet... */
-   status = sendto(icmp_protocol_fd, &icmp, sizeof(icmp), 0,
-   (struct sockaddr *)&to, sizeof(to));
+   status = sendmsg(icmp_protocol_fd, &msg, 0);
if (status == -1)
warning("icmp_echorequest %s: %m", inet_ntoa(to.sin_addr));
 



Re: use m_defrag in fxp

2015-12-01 Thread Mark Kettenis
> Date: Tue, 1 Dec 2015 19:30:44 +0100
> From: Claudio Jeker 
> 
> Use m_defrag in fxp to make it nicer and simpler.
> 
> works for me with
> fxp0 at pci6 dev 6 function 0 "Intel 8255x" rev 0x08, i82559: apic 6 int 21, 
> address 00:d0:b7:4c:36:c4
> inphy0 at fxp0 phy 1: i82555 10/100 PHY, rev. 4
> 
> It would be possible to drop the mbuf on error and then the ifq_deq_begin
> and ifq_deq_rollback dance could be even more simplified.

ok kettenis@

> Index: dev/ic/fxp.c
> ===
> RCS file: /cvs/src/sys/dev/ic/fxp.c,v
> retrieving revision 1.127
> diff -u -p -r1.127 fxp.c
> --- dev/ic/fxp.c  25 Nov 2015 03:09:58 -  1.127
> +++ dev/ic/fxp.c  1 Dec 2015 13:52:53 -
> @@ -673,8 +673,8 @@ fxp_start(struct ifnet *ifp)
>   struct fxp_softc *sc = ifp->if_softc;
>   struct fxp_txsw *txs = sc->sc_cbt_prod;
>   struct fxp_cb_tx *txc;
> - struct mbuf *m0, *m = NULL;
> - int cnt = sc->sc_cbt_cnt, seg;
> + struct mbuf *m0;
> + int cnt = sc->sc_cbt_cnt, seg, error;
>  
>   if (!(ifp->if_flags & IFF_RUNNING) || ifq_is_oactive(&ifp->if_snd))
>   return;
> @@ -691,38 +691,22 @@ fxp_start(struct ifnet *ifp)
>   if (m0 == NULL)
>   break;
>  
> - if (bus_dmamap_load_mbuf(sc->sc_dmat, txs->tx_map,
> - m0, BUS_DMA_NOWAIT) != 0) {
> - MGETHDR(m, M_DONTWAIT, MT_DATA);
> - if (m == NULL) {
> - ifq_deq_rollback(&ifp->if_snd, m0);
> - break;
> - }
> - if (m0->m_pkthdr.len > MHLEN) {
> - MCLGET(m, M_DONTWAIT);
> - if (!(m->m_flags & M_EXT)) {
> - m_freem(m);
> - ifq_deq_rollback(&ifp->if_snd, m0);
> - break;
> - }
> - }
> - m_copydata(m0, 0, m0->m_pkthdr.len, mtod(m, caddr_t));
> - m->m_pkthdr.len = m->m_len = m0->m_pkthdr.len;
> - if (bus_dmamap_load_mbuf(sc->sc_dmat, txs->tx_map,
> - m, BUS_DMA_NOWAIT) != 0) {
> - m_freem(m);
> + error = bus_dmamap_load_mbuf(sc->sc_dmat, txs->tx_map,
> + m0, BUS_DMA_NOWAIT);
> + if (error == EFBIG) {
> + if (m_defrag(m0, M_DONTWAIT)) {
>   ifq_deq_rollback(&ifp->if_snd, m0);
>   break;
>   }
> + error = bus_dmamap_load_mbuf(sc->sc_dmat, txs->tx_map,
> + m0, BUS_DMA_NOWAIT);
>   }
> -
> - ifq_deq_commit(&ifp->if_snd, m0);
> - if (m != NULL) {
> - m_freem(m0);
> - m0 = m;
> - m = NULL;
> + if (error != 0) {
> + ifq_deq_rollback(&ifp->if_snd, m0);
> + break;
>   }
>  
> + ifq_deq_commit(&ifp->if_snd, m0);
>   txs->tx_mbuf = m0;
>  
>  #if NBPFILTER > 0
> 
> 



Re: Slow wsmouse down in console

2015-12-01 Thread Thierry Deval
Hi Ulf,

I indeed guess there are not much console users these modern days.

Personally, my current laptop is so slow in X that I find it convenient to
switch back and forth between ttyC[014]. In that regard, I will probably
investigate the possibility of sharing the copy-buffer between screens. Who
knows ?

I unfortunately couldn't test my patch as much as you did.
(I'm still waiting for my new laptop to speed up my builds. Should arrive
soon hopefully)

Thanks for your involved feedback,

Thierry


On Sun, Nov 29, 2015 at 5:02 PM, Ulf Brosziewski <
ulf.brosziew...@t-online.de> wrote:

> This looks nice. Maybe someone else who is more familiar with wsdisplay
> could also have a look at it?
>
> I made a test with a USB mouse and an ALPS Glidepoint, which worked
> well.  Without the patch wsmoused is completely useless for that
> touchpad. Out of curiosity, I made another test with an Elantech-v4
> clickpad, and the cursor control also worked well (of course, wsmoused
> remains useless for clickpads because you cannot paste).
>
> Both tracking the remainders when scaling and taking the size of the
> cells into account looks reasonable. There might still be no g
> ā€‹uā€‹
> arantee
> that this works everywhere - pms, for example, applies somewhat
> arbitrary scale factors in compat mode, there is no stable correlation
> to the touchpad resolutions. But if this works in standard environments,
> it is certainly more useful than the current version.
>
> Because I saw no complaints up to now, I have been thinking that hardly
> anyone uses touchpads at the console. Am I wrong here?
>
>
>
> On 11/27/2015 12:35 AM, Thierry Deval wrote:
>
>> Hi,
>>
>> I hope I'm not the only one being annoyed by the fast movement of wsmouse
>> when
>> in text mode, and this one can be useful.
>>
>> Here is a patch that slows down the cursor by reducing the mouse
>> coordinates
>> proportionally to the console font size.
>> I confess I have only tried it on this laptop with its Synaptics touchpad
>> and
>> some other USB mouses.
>>
>> Anyone else interested ?
>>
>> Thierry
>>
>> Index: sys/dev/wscons/wsdisplay.c
>> ===
>> RCS file: /cvs/src/sys/dev/wscons/wsdisplay.c,v
>> retrieving revision 1.124
>> diff -u -p -r1.124 wsdisplay.c
>> --- dev/wscons/wsdisplay.c  8 Sep 2015 11:13:20 -   1.124
>> +++ dev/wscons/wsdisplay.c  26 Nov 2015 20:28:48 -
>> @@ -2463,27 +2463,39 @@ ctrl_event(struct wsdisplay_softc *sc, u
>>   void
>>   mouse_moverel(struct wsscreen *scr, int dx, int dy)
>>   {
>> +   static int acc_dx, acc_dy;
>> struct wsscreen_internal *dconf = scr->scr_dconf;
>> +   const struct wsscreen_descr *descr = dconf->scrdata;
>> u_int old_mouse = scr->mouse;
>> int mouse_col = scr->mouse % N_COLS(dconf);
>> int mouse_row = scr->mouse / N_COLS(dconf);
>> +   int norm_dx, norm_dy;
>> +
>> +   /* accumulate movement and calculate character equivalent */
>> +   acc_dx += dx;
>> +   if ((norm_dx = acc_dx / descr->fontwidth )) acc_dx -=
>> descr->fontwidth  * norm_dx;
>> +   acc_dy += dy;
>> +   if ((norm_dy = acc_dy / descr->fontheight)) acc_dy -=
>> descr->fontheight * norm_dy;
>> +
>> +   /* bail out if mouse hasn't virtually moved */
>> +   if (norm_dx == 0 && norm_dy == 0) return;
>>
>> /* update position */
>> -   if (mouse_col + dx >= MAXCOL(dconf))
>> +   if (mouse_col + norm_dx >= MAXCOL(dconf))
>> mouse_col = MAXCOL(dconf);
>> else {
>> -   if (mouse_col + dx <= 0)
>> +   if (mouse_col + norm_dx <= 0)
>> mouse_col = 0;
>> else
>> -   mouse_col += dx;
>> +   mouse_col += norm_dx;
>> }
>> -   if (mouse_row + dy >= MAXROW(dconf))
>> +   if (mouse_row + norm_dy >= MAXROW(dconf))
>> mouse_row = MAXROW(dconf);
>> else {
>> -   if (mouse_row + dy <= 0)
>> +   if (mouse_row + norm_dy <= 0)
>> mouse_row = 0;
>> else
>> -   mouse_row += dy;
>> +   mouse_row += norm_dy;
>> }
>> scr->mouse = mouse_row * N_COLS(dconf) + mouse_col;
>>
>>
>>
>>
>


Re: use m_defrag in fxp

2015-12-01 Thread David Hill
On Tue, Dec 01, 2015 at 07:30:44PM +0100, Claudio Jeker wrote:
> Use m_defrag in fxp to make it nicer and simpler.
> 
> works for me with
> fxp0 at pci6 dev 6 function 0 "Intel 8255x" rev 0x08, i82559: apic 6 int 21, 
> address 00:d0:b7:4c:36:c4
> inphy0 at fxp0 phy 1: i82555 10/100 PHY, rev. 4
> 
> It would be possible to drop the mbuf on error and then the ifq_deq_begin
> and ifq_deq_rollback dance could be even more simplified.
> -- 
> :wq Claudio
>

Verified works on same hardware..

fxp0 at pci5 dev 1 function 0 "Intel 8255x" rev 0x08, i82559: apic 2 int
19, address 00:0e:0c:35:70:48
inphy0 at fxp0 phy 1: i82555 10/100 PHY, rev. 4
 



Re: Simplify rtredirect

2015-12-01 Thread Alexander Bluhm
On Tue, Dec 01, 2015 at 05:53:47PM +0100, Martin Pieuchot wrote:
> The netmask argument is always NULL and the flags are always the same.
> RTF_GATEWAY|RTF_HOST routes *are* routes created by redirect.   
> 
> I need this simplification to move forward with my rt_mask() cleanup.
> 
> ok?

OK bluhm@

> 
> Index: net/route.c
> ===
> RCS file: /cvs/src/sys/net/route.c,v
> retrieving revision 1.277
> diff -u -p -r1.277 route.c
> --- net/route.c   27 Nov 2015 11:52:44 -  1.277
> +++ net/route.c   1 Dec 2015 16:52:10 -
> @@ -529,8 +529,7 @@ ifafree(struct ifaddr *ifa)
>   */
>  void
>  rtredirect(struct sockaddr *dst, struct sockaddr *gateway,
> -struct sockaddr *netmask, int flags, struct sockaddr *src,
> -struct rtentry **rtp, u_int rdomain)
> +struct sockaddr *src, struct rtentry **rtp, unsigned int rdomain)
>  {
>   struct rtentry  *rt;
>   int  error = 0;
> @@ -538,6 +537,7 @@ rtredirect(struct sockaddr *dst, struct 
>   struct rt_addrinfo   info;
>   struct ifaddr   *ifa;
>   unsigned int ifidx = 0;
> + int  flags = RTF_GATEWAY|RTF_HOST;
>  
>   splsoftassert(IPL_SOFTNET);
>  
> @@ -557,8 +557,7 @@ rtredirect(struct sockaddr *dst, struct 
>  #define  equal(a1, a2) \
>   ((a1)->sa_len == (a2)->sa_len && \
>bcmp((caddr_t)(a1), (caddr_t)(a2), (a1)->sa_len) == 0)
> - if (!(flags & RTF_DONE) && rt &&
> -  (!equal(src, rt->rt_gateway) || rt->rt_ifa != ifa))
> + if (rt != NULL && (!equal(src, rt->rt_gateway) || rt->rt_ifa != ifa))
>   error = EINVAL;
>   else if (ifa_ifwithaddr(gateway, rdomain) != NULL)
>   error = EHOSTUNREACH;
> @@ -574,21 +573,20 @@ rtredirect(struct sockaddr *dst, struct 
>   goto create;
>   /*
>* Don't listen to the redirect if it's
> -  * for a route to an interface. 
> +  * for a route to an interface.
>*/
> - if (rt->rt_flags & RTF_GATEWAY) {
> - if (((rt->rt_flags & RTF_HOST) == 0) && (flags & RTF_HOST)) {
> + if (ISSET(rt->rt_flags, RTF_GATEWAY)) {
> + if (!ISSET(rt->rt_flags, RTF_HOST)) {
>   /*
>* Changing from route to net => route to host.
>* Create new route, rather than smashing route to net.
>*/
>  create:
>   rtfree(rt);
> - flags |= RTF_GATEWAY | RTF_DYNAMIC;
> + flags |= RTF_DYNAMIC;
>   bzero(&info, sizeof(info));
>   info.rti_info[RTAX_DST] = dst;
>   info.rti_info[RTAX_GATEWAY] = gateway;
> - info.rti_info[RTAX_NETMASK] = netmask;
>   info.rti_ifa = ifa;
>   info.rti_flags = flags;
>   rt = NULL;
> @@ -624,7 +622,6 @@ out:
>   bzero((caddr_t)&info, sizeof(info));
>   info.rti_info[RTAX_DST] = dst;
>   info.rti_info[RTAX_GATEWAY] = gateway;
> - info.rti_info[RTAX_NETMASK] = netmask;
>   info.rti_info[RTAX_AUTHOR] = src;
>   rt_missmsg(RTM_REDIRECT, &info, flags, ifidx, error, rdomain);
>  }
> Index: net/route.h
> ===
> RCS file: /cvs/src/sys/net/route.h,v
> retrieving revision 1.122
> diff -u -p -r1.122 route.h
> --- net/route.h   29 Nov 2015 16:02:18 -  1.122
> +++ net/route.h   1 Dec 2015 16:49:26 -
> @@ -392,9 +392,7 @@ intrt_ifa_del(struct ifaddr *, int, st
>  int   rt_ifa_addlocal(struct ifaddr *);
>  int   rt_ifa_dellocal(struct ifaddr *);
>  int   rtioctl(u_long, caddr_t, struct proc *);
> -void  rtredirect(struct sockaddr *, struct sockaddr *,
> -  struct sockaddr *, int, struct sockaddr *,
> -  struct rtentry **, u_int);
> +void  rtredirect(struct sockaddr *, struct sockaddr *, struct sockaddr *, 
> struct rtentry **, unsigned int);
>  int   rtrequest(int, struct rt_addrinfo *, u_int8_t, struct rtentry **,
>u_int);
>  void  rt_if_remove(struct ifnet *);
> Index: netinet/ip_icmp.c
> ===
> RCS file: /cvs/src/sys/netinet/ip_icmp.c,v
> retrieving revision 1.146
> diff -u -p -r1.146 ip_icmp.c
> --- netinet/ip_icmp.c 21 Nov 2015 11:26:59 -  1.146
> +++ netinet/ip_icmp.c 1 Dec 2015 16:36:52 -
> @@ -652,9 +652,8 @@ reflect:
>   &ip->ip_dst.s_addr))
>   goto freeit;
>  #endif
> - rtredirect(sintosa(&sdst), sintosa(&sgw), NULL,
> - RTF_GATEWAY | RTF_HOST, sintosa(&ssrc),
> - &newrt, m->m_pkthdr.ph_rtableid);
> + rtredirect(sintosa(&sdst), sintosa(&sgw),
> + sintosa(&ssrc), &newrt, m->m_pkthdr.ph_rtableid);
> 

Re: ND and rt_ifa_add(9)

2015-12-01 Thread Alexander Bluhm
On Tue, Dec 01, 2015 at 01:34:15PM +0100, Martin Pieuchot wrote:
> Diff below converts two custom uses of rtrequest(9) to rt_ifa_add(9).
> These are used to automagically install and remove the RTF_CONNECTED
> route obtained from a router advertisement.
> 
> This changes the existing logic a bit to match the netinet behavior.
> The route will now be attached to the ``ifa'' matching the prefix
> announced:
> 
> -2001::/64  fe80::5054:ff:fe12:3456%vio0   UC 
> 02 - 4 vio0 
> +2001::/64  2001::5054:ff:fe12:3456UC 
> 00 - 4 vio0
> 
> This should be fine as the "gateway" field does not matter for
> RTF_CLONING routes.
> 
> ok?

OK bluhm@

> 
> Index: netinet6/nd6_rtr.c
> ===
> RCS file: /cvs/src/sys/netinet6/nd6_rtr.c,v
> retrieving revision 1.134
> diff -u -p -r1.134 nd6_rtr.c
> --- netinet6/nd6_rtr.c24 Nov 2015 13:37:16 -  1.134
> +++ netinet6/nd6_rtr.c1 Dec 2015 12:22:56 -
> @@ -1697,15 +1697,11 @@ pfxlist_onlink_check(void)
>  int
>  nd6_prefix_onlink(struct nd_prefix *pr)
>  {
> - struct rt_addrinfo info;
> - struct ifaddr *ifa;
>   struct ifnet *ifp = pr->ndpr_ifp;
> - struct sockaddr_in6 mask6;
> + struct ifaddr *ifa;
>   struct nd_prefix *opr;
> - struct rtentry *rt;
>   char addr[INET6_ADDRSTRLEN];
> - u_long rtflags = 0;
> - int error;
> + int error, rtflags = 0;
>  
>   /* sanity check */
>   if ((pr->ndpr_stateflags & NDPRF_ONLINK) != 0)
> @@ -1731,18 +1727,11 @@ nd6_prefix_onlink(struct nd_prefix *pr)
>   return (0);
>   }
>  
> - /*
> -  * We prefer link-local addresses as the associated interface address.
> -  */
> - /* search for a link-local addr */
> - ifa = &in6ifa_ifpforlinklocal(ifp,
> - IN6_IFF_NOTREADY | IN6_IFF_ANYCAST)->ia_ifa;
> - if (ifa == NULL) {
> - TAILQ_FOREACH(ifa, &ifp->if_addrlist, ifa_list) {
> - if (ifa->ifa_addr->sa_family == AF_INET6)
> - break;
> - }
> - /* should we care about ia6_flags? */
> + TAILQ_FOREACH(ifa, &ifp->if_addrlist, ifa_list) {
> + if (ifa->ifa_addr->sa_family != AF_INET6)
> + continue;
> + if (ifatoia6(ifa)->ia6_ndpr == pr)
> + break;
>   }
>   if (ifa == NULL) {
>   /*
> @@ -1760,25 +1749,12 @@ nd6_prefix_onlink(struct nd_prefix *pr)
>   return (0);
>   }
>  
> - bzero(&mask6, sizeof(mask6));
> - mask6.sin6_len = sizeof(mask6);
> - mask6.sin6_addr = pr->ndpr_mask;
> -
>   if (nd6_need_cache(ifp))
>   rtflags = RTF_CLONING | RTF_CONNECTED;
>  
> - bzero(&info, sizeof(info));
> - info.rti_flags = rtflags;
> - info.rti_info[RTAX_DST] = sin6tosa(&pr->ndpr_prefix);
> - info.rti_info[RTAX_GATEWAY] = ifa->ifa_addr;
> - info.rti_info[RTAX_NETMASK] = sin6tosa(&mask6);
> -
> - error = rtrequest(RTM_ADD, &info, RTP_CONNECTED, &rt, ifp->if_rdomain);
> - if (error == 0) {
> + error = rt_ifa_add(ifa, rtflags, sin6tosa(&pr->ndpr_prefix));
> + if (error == 0)
>   pr->ndpr_stateflags |= NDPRF_ONLINK;
> - rt_sendmsg(rt, RTM_ADD, ifp->if_rdomain);
> - rtfree(rt);
> - }
>  
>   return (error);
>  }
> @@ -1786,13 +1762,11 @@ nd6_prefix_onlink(struct nd_prefix *pr)
>  int
>  nd6_prefix_offlink(struct nd_prefix *pr)
>  {
> - struct rt_addrinfo info;
>   struct ifnet *ifp = pr->ndpr_ifp;
> + struct ifaddr *ifa;
>   struct nd_prefix *opr;
> - struct sockaddr_in6 sa6, mask6;
> - struct rtentry *rt;
>   char addr[INET6_ADDRSTRLEN];
> - int error;
> + int error, rtflags = 0;
>  
>   /* sanity check */
>   if ((pr->ndpr_stateflags & NDPRF_ONLINK) == 0) {
> @@ -1804,27 +1778,22 @@ nd6_prefix_offlink(struct nd_prefix *pr)
>   return (EEXIST);
>   }
>  
> - bzero(&sa6, sizeof(sa6));
> - sa6.sin6_family = AF_INET6;
> - sa6.sin6_len = sizeof(sa6);
> - bcopy(&pr->ndpr_prefix.sin6_addr, &sa6.sin6_addr,
> - sizeof(struct in6_addr));
> - bzero(&mask6, sizeof(mask6));
> - mask6.sin6_family = AF_INET6;
> - mask6.sin6_len = sizeof(sa6);
> - bcopy(&pr->ndpr_mask, &mask6.sin6_addr, sizeof(struct in6_addr));
> - bzero(&info, sizeof(info));
> - info.rti_info[RTAX_DST] = sin6tosa(&sa6);
> - info.rti_info[RTAX_NETMASK] = sin6tosa(&mask6);
> + TAILQ_FOREACH(ifa, &ifp->if_addrlist, ifa_list) {
> + if (ifa->ifa_addr->sa_family != AF_INET6)
> + continue;
> + if (ifatoia6(ifa)->ia6_ndpr == pr)
> + break;
> + }
> + if (ifa == NULL)
> + return (EINVAL);
>  
> - error = rtrequest(RTM_DELETE, &info, RTP_CONNECTED, &rt,

use m_defrag in fxp

2015-12-01 Thread Claudio Jeker
Use m_defrag in fxp to make it nicer and simpler.

works for me with
fxp0 at pci6 dev 6 function 0 "Intel 8255x" rev 0x08, i82559: apic 6 int 21, 
address 00:d0:b7:4c:36:c4
inphy0 at fxp0 phy 1: i82555 10/100 PHY, rev. 4

It would be possible to drop the mbuf on error and then the ifq_deq_begin
and ifq_deq_rollback dance could be even more simplified.
-- 
:wq Claudio

Index: dev/ic/fxp.c
===
RCS file: /cvs/src/sys/dev/ic/fxp.c,v
retrieving revision 1.127
diff -u -p -r1.127 fxp.c
--- dev/ic/fxp.c25 Nov 2015 03:09:58 -  1.127
+++ dev/ic/fxp.c1 Dec 2015 13:52:53 -
@@ -673,8 +673,8 @@ fxp_start(struct ifnet *ifp)
struct fxp_softc *sc = ifp->if_softc;
struct fxp_txsw *txs = sc->sc_cbt_prod;
struct fxp_cb_tx *txc;
-   struct mbuf *m0, *m = NULL;
-   int cnt = sc->sc_cbt_cnt, seg;
+   struct mbuf *m0;
+   int cnt = sc->sc_cbt_cnt, seg, error;
 
if (!(ifp->if_flags & IFF_RUNNING) || ifq_is_oactive(&ifp->if_snd))
return;
@@ -691,38 +691,22 @@ fxp_start(struct ifnet *ifp)
if (m0 == NULL)
break;
 
-   if (bus_dmamap_load_mbuf(sc->sc_dmat, txs->tx_map,
-   m0, BUS_DMA_NOWAIT) != 0) {
-   MGETHDR(m, M_DONTWAIT, MT_DATA);
-   if (m == NULL) {
-   ifq_deq_rollback(&ifp->if_snd, m0);
-   break;
-   }
-   if (m0->m_pkthdr.len > MHLEN) {
-   MCLGET(m, M_DONTWAIT);
-   if (!(m->m_flags & M_EXT)) {
-   m_freem(m);
-   ifq_deq_rollback(&ifp->if_snd, m0);
-   break;
-   }
-   }
-   m_copydata(m0, 0, m0->m_pkthdr.len, mtod(m, caddr_t));
-   m->m_pkthdr.len = m->m_len = m0->m_pkthdr.len;
-   if (bus_dmamap_load_mbuf(sc->sc_dmat, txs->tx_map,
-   m, BUS_DMA_NOWAIT) != 0) {
-   m_freem(m);
+   error = bus_dmamap_load_mbuf(sc->sc_dmat, txs->tx_map,
+   m0, BUS_DMA_NOWAIT);
+   if (error == EFBIG) {
+   if (m_defrag(m0, M_DONTWAIT)) {
ifq_deq_rollback(&ifp->if_snd, m0);
break;
}
+   error = bus_dmamap_load_mbuf(sc->sc_dmat, txs->tx_map,
+   m0, BUS_DMA_NOWAIT);
}
-
-   ifq_deq_commit(&ifp->if_snd, m0);
-   if (m != NULL) {
-   m_freem(m0);
-   m0 = m;
-   m = NULL;
+   if (error != 0) {
+   ifq_deq_rollback(&ifp->if_snd, m0);
+   break;
}
 
+   ifq_deq_commit(&ifp->if_snd, m0);
txs->tx_mbuf = m0;
 
 #if NBPFILTER > 0



Re: inteldrm: HBR2 support for DisplayPort 1.2

2015-12-01 Thread Scot Doyle
On Tue, 1 Dec 2015, Jonathan Gray wrote:
> On Tue, Dec 01, 2015 at 07:00:19AM +, Scot Doyle wrote:
> > Should we include "INTEL_INFO(dev)->gen >= 8"? There is at least one known
> > regression (booting with blank screen) described in commit  
> > 8749be86a8f0c8a956d20f7d3c768ed6d1e356a1.
> 
> I think we can safely skip that one as it concerns skylake and
> we don't have any code for skylake at the moment.
> 
> > 
> > > + intel_dp->dpcd[DP_DPCD_REV] >= 0x12)
> > > + max_link_bw = DP_LINK_BW_5_4;
> > 
> > No need to set max_link_bw to same value? Negate previous condition, 
> > assign DP_LINK_BW_2_7 and delete following else clause?
> 
> It's harmless though, I'd prefer to leave it as then it is potentially
> one less conflict to deal with later.

Sounds good. I've confirmed Ultra HD at 60Hz with the suggested patches.



Simplify rtredirect

2015-12-01 Thread Martin Pieuchot
The netmask argument is always NULL and the flags are always the same.
RTF_GATEWAY|RTF_HOST routes *are* routes created by redirect.   

I need this simplification to move forward with my rt_mask() cleanup.

ok?

Index: net/route.c
===
RCS file: /cvs/src/sys/net/route.c,v
retrieving revision 1.277
diff -u -p -r1.277 route.c
--- net/route.c 27 Nov 2015 11:52:44 -  1.277
+++ net/route.c 1 Dec 2015 16:52:10 -
@@ -529,8 +529,7 @@ ifafree(struct ifaddr *ifa)
  */
 void
 rtredirect(struct sockaddr *dst, struct sockaddr *gateway,
-struct sockaddr *netmask, int flags, struct sockaddr *src,
-struct rtentry **rtp, u_int rdomain)
+struct sockaddr *src, struct rtentry **rtp, unsigned int rdomain)
 {
struct rtentry  *rt;
int  error = 0;
@@ -538,6 +537,7 @@ rtredirect(struct sockaddr *dst, struct 
struct rt_addrinfo   info;
struct ifaddr   *ifa;
unsigned int ifidx = 0;
+   int  flags = RTF_GATEWAY|RTF_HOST;
 
splsoftassert(IPL_SOFTNET);
 
@@ -557,8 +557,7 @@ rtredirect(struct sockaddr *dst, struct 
 #defineequal(a1, a2) \
((a1)->sa_len == (a2)->sa_len && \
 bcmp((caddr_t)(a1), (caddr_t)(a2), (a1)->sa_len) == 0)
-   if (!(flags & RTF_DONE) && rt &&
-(!equal(src, rt->rt_gateway) || rt->rt_ifa != ifa))
+   if (rt != NULL && (!equal(src, rt->rt_gateway) || rt->rt_ifa != ifa))
error = EINVAL;
else if (ifa_ifwithaddr(gateway, rdomain) != NULL)
error = EHOSTUNREACH;
@@ -574,21 +573,20 @@ rtredirect(struct sockaddr *dst, struct 
goto create;
/*
 * Don't listen to the redirect if it's
-* for a route to an interface. 
+* for a route to an interface.
 */
-   if (rt->rt_flags & RTF_GATEWAY) {
-   if (((rt->rt_flags & RTF_HOST) == 0) && (flags & RTF_HOST)) {
+   if (ISSET(rt->rt_flags, RTF_GATEWAY)) {
+   if (!ISSET(rt->rt_flags, RTF_HOST)) {
/*
 * Changing from route to net => route to host.
 * Create new route, rather than smashing route to net.
 */
 create:
rtfree(rt);
-   flags |= RTF_GATEWAY | RTF_DYNAMIC;
+   flags |= RTF_DYNAMIC;
bzero(&info, sizeof(info));
info.rti_info[RTAX_DST] = dst;
info.rti_info[RTAX_GATEWAY] = gateway;
-   info.rti_info[RTAX_NETMASK] = netmask;
info.rti_ifa = ifa;
info.rti_flags = flags;
rt = NULL;
@@ -624,7 +622,6 @@ out:
bzero((caddr_t)&info, sizeof(info));
info.rti_info[RTAX_DST] = dst;
info.rti_info[RTAX_GATEWAY] = gateway;
-   info.rti_info[RTAX_NETMASK] = netmask;
info.rti_info[RTAX_AUTHOR] = src;
rt_missmsg(RTM_REDIRECT, &info, flags, ifidx, error, rdomain);
 }
Index: net/route.h
===
RCS file: /cvs/src/sys/net/route.h,v
retrieving revision 1.122
diff -u -p -r1.122 route.h
--- net/route.h 29 Nov 2015 16:02:18 -  1.122
+++ net/route.h 1 Dec 2015 16:49:26 -
@@ -392,9 +392,7 @@ int  rt_ifa_del(struct ifaddr *, int, st
 int rt_ifa_addlocal(struct ifaddr *);
 int rt_ifa_dellocal(struct ifaddr *);
 int rtioctl(u_long, caddr_t, struct proc *);
-voidrtredirect(struct sockaddr *, struct sockaddr *,
-struct sockaddr *, int, struct sockaddr *,
-struct rtentry **, u_int);
+voidrtredirect(struct sockaddr *, struct sockaddr *, struct sockaddr *, 
struct rtentry **, unsigned int);
 int rtrequest(int, struct rt_addrinfo *, u_int8_t, struct rtentry **,
 u_int);
 voidrt_if_remove(struct ifnet *);
Index: netinet/ip_icmp.c
===
RCS file: /cvs/src/sys/netinet/ip_icmp.c,v
retrieving revision 1.146
diff -u -p -r1.146 ip_icmp.c
--- netinet/ip_icmp.c   21 Nov 2015 11:26:59 -  1.146
+++ netinet/ip_icmp.c   1 Dec 2015 16:36:52 -
@@ -652,9 +652,8 @@ reflect:
&ip->ip_dst.s_addr))
goto freeit;
 #endif
-   rtredirect(sintosa(&sdst), sintosa(&sgw), NULL,
-   RTF_GATEWAY | RTF_HOST, sintosa(&ssrc),
-   &newrt, m->m_pkthdr.ph_rtableid);
+   rtredirect(sintosa(&sdst), sintosa(&sgw),
+   sintosa(&ssrc), &newrt, m->m_pkthdr.ph_rtableid);
if (newrt != NULL && icmp_redirtimeout != 0) {
(void)rt_timer_add(newrt, icmp_redirect_timeout,
icmp_redirect_timeout_q, m->m_pkthdr.ph_rtableid)

Completely disable 2D acceleration on Broadwell

2015-12-01 Thread Mark Kettenis
As tedu@ reported (and some pople on misc@ confirmed) partly disabling
2D acceleration on Broadwell made X unstable.  It really looks like
the alternative BLT path isn't well tested and therefore buggy.  So
here is a diff that disables 2D acceleration completely.  Those who
don't care about suspend/resume can still enable it if they want.  3D
acceleration should continue to work.

ok?


Index: sna_accel.c
===
RCS file: /home/cvs/xenocara/driver/xf86-video-intel/src/sna/sna_accel.c,v
retrieving revision 1.6
diff -u -p -r1.6 sna_accel.c
--- sna_accel.c 15 Nov 2015 15:33:57 -  1.6
+++ sna_accel.c 1 Dec 2015 15:37:44 -
@@ -17659,6 +17659,9 @@ static bool sna_option_accel_none(struct
return true;
 
s = xf86GetOptValString(sna->Options, OPTION_ACCEL_METHOD);
+   /* XXX avoid render ring since it gets stuck after resume */
+   if (s == NULL && sna->info->gen >= 0100)
+   return true;
if (s == NULL)
return IS_DEFAULT_ACCEL_METHOD(NOACCEL);
 
@@ -17670,9 +17673,6 @@ static bool sna_option_accel_blt(struct 
const char *s;
 
s = xf86GetOptValString(sna->Options, OPTION_ACCEL_METHOD);
-   /* XXX avoid render ring since it gets stuck after resume */
-   if (s == NULL && sna->info->gen >= 0100)
-   return true;
if (s == NULL)
return false;
 



ND and rt_ifa_add(9)

2015-12-01 Thread Martin Pieuchot
Diff below converts two custom uses of rtrequest(9) to rt_ifa_add(9).
These are used to automagically install and remove the RTF_CONNECTED
route obtained from a router advertisement.

This changes the existing logic a bit to match the netinet behavior.
The route will now be attached to the ``ifa'' matching the prefix
announced:

-2001::/64  fe80::5054:ff:fe12:3456%vio0   UC 0 
   2 - 4 vio0 
+2001::/64  2001::5054:ff:fe12:3456UC 0 
   0 - 4 vio0

This should be fine as the "gateway" field does not matter for
RTF_CLONING routes.

ok?

Index: netinet6/nd6_rtr.c
===
RCS file: /cvs/src/sys/netinet6/nd6_rtr.c,v
retrieving revision 1.134
diff -u -p -r1.134 nd6_rtr.c
--- netinet6/nd6_rtr.c  24 Nov 2015 13:37:16 -  1.134
+++ netinet6/nd6_rtr.c  1 Dec 2015 12:22:56 -
@@ -1697,15 +1697,11 @@ pfxlist_onlink_check(void)
 int
 nd6_prefix_onlink(struct nd_prefix *pr)
 {
-   struct rt_addrinfo info;
-   struct ifaddr *ifa;
struct ifnet *ifp = pr->ndpr_ifp;
-   struct sockaddr_in6 mask6;
+   struct ifaddr *ifa;
struct nd_prefix *opr;
-   struct rtentry *rt;
char addr[INET6_ADDRSTRLEN];
-   u_long rtflags = 0;
-   int error;
+   int error, rtflags = 0;
 
/* sanity check */
if ((pr->ndpr_stateflags & NDPRF_ONLINK) != 0)
@@ -1731,18 +1727,11 @@ nd6_prefix_onlink(struct nd_prefix *pr)
return (0);
}
 
-   /*
-* We prefer link-local addresses as the associated interface address.
-*/
-   /* search for a link-local addr */
-   ifa = &in6ifa_ifpforlinklocal(ifp,
-   IN6_IFF_NOTREADY | IN6_IFF_ANYCAST)->ia_ifa;
-   if (ifa == NULL) {
-   TAILQ_FOREACH(ifa, &ifp->if_addrlist, ifa_list) {
-   if (ifa->ifa_addr->sa_family == AF_INET6)
-   break;
-   }
-   /* should we care about ia6_flags? */
+   TAILQ_FOREACH(ifa, &ifp->if_addrlist, ifa_list) {
+   if (ifa->ifa_addr->sa_family != AF_INET6)
+   continue;
+   if (ifatoia6(ifa)->ia6_ndpr == pr)
+   break;
}
if (ifa == NULL) {
/*
@@ -1760,25 +1749,12 @@ nd6_prefix_onlink(struct nd_prefix *pr)
return (0);
}
 
-   bzero(&mask6, sizeof(mask6));
-   mask6.sin6_len = sizeof(mask6);
-   mask6.sin6_addr = pr->ndpr_mask;
-
if (nd6_need_cache(ifp))
rtflags = RTF_CLONING | RTF_CONNECTED;
 
-   bzero(&info, sizeof(info));
-   info.rti_flags = rtflags;
-   info.rti_info[RTAX_DST] = sin6tosa(&pr->ndpr_prefix);
-   info.rti_info[RTAX_GATEWAY] = ifa->ifa_addr;
-   info.rti_info[RTAX_NETMASK] = sin6tosa(&mask6);
-
-   error = rtrequest(RTM_ADD, &info, RTP_CONNECTED, &rt, ifp->if_rdomain);
-   if (error == 0) {
+   error = rt_ifa_add(ifa, rtflags, sin6tosa(&pr->ndpr_prefix));
+   if (error == 0)
pr->ndpr_stateflags |= NDPRF_ONLINK;
-   rt_sendmsg(rt, RTM_ADD, ifp->if_rdomain);
-   rtfree(rt);
-   }
 
return (error);
 }
@@ -1786,13 +1762,11 @@ nd6_prefix_onlink(struct nd_prefix *pr)
 int
 nd6_prefix_offlink(struct nd_prefix *pr)
 {
-   struct rt_addrinfo info;
struct ifnet *ifp = pr->ndpr_ifp;
+   struct ifaddr *ifa;
struct nd_prefix *opr;
-   struct sockaddr_in6 sa6, mask6;
-   struct rtentry *rt;
char addr[INET6_ADDRSTRLEN];
-   int error;
+   int error, rtflags = 0;
 
/* sanity check */
if ((pr->ndpr_stateflags & NDPRF_ONLINK) == 0) {
@@ -1804,27 +1778,22 @@ nd6_prefix_offlink(struct nd_prefix *pr)
return (EEXIST);
}
 
-   bzero(&sa6, sizeof(sa6));
-   sa6.sin6_family = AF_INET6;
-   sa6.sin6_len = sizeof(sa6);
-   bcopy(&pr->ndpr_prefix.sin6_addr, &sa6.sin6_addr,
-   sizeof(struct in6_addr));
-   bzero(&mask6, sizeof(mask6));
-   mask6.sin6_family = AF_INET6;
-   mask6.sin6_len = sizeof(sa6);
-   bcopy(&pr->ndpr_mask, &mask6.sin6_addr, sizeof(struct in6_addr));
-   bzero(&info, sizeof(info));
-   info.rti_info[RTAX_DST] = sin6tosa(&sa6);
-   info.rti_info[RTAX_NETMASK] = sin6tosa(&mask6);
+   TAILQ_FOREACH(ifa, &ifp->if_addrlist, ifa_list) {
+   if (ifa->ifa_addr->sa_family != AF_INET6)
+   continue;
+   if (ifatoia6(ifa)->ia6_ndpr == pr)
+   break;
+   }
+   if (ifa == NULL)
+   return (EINVAL);
 
-   error = rtrequest(RTM_DELETE, &info, RTP_CONNECTED, &rt,
-   ifp->if_rdomain);
+   if (nd6_need_cache(ifp))
+   rtflags = RTF_CLONING | RTF_CONNECTED;
+
+   error = rt_ifa_del(ifa, rtflags, sin6tosa(&pr->ndpr_pre

Re: serialise if_start calls

2015-12-01 Thread David Gwynne

> On 1 Dec 2015, at 5:40 AM, Hrvoje Popovski  wrote:
> 
> On 30.11.2015. 12:55, David Gwynne wrote:
>> this tweaks the guts of if_start so it guarantees that there's only
>> ever one call to ifp->if_start running in the system at a time.
>> previously this was implicit because it could only be called with
>> the KERNEL_LOCK held.
>> 
>> as we move forward it would be nice to run the queue without having
>> to take the biglock. however, because we also want to dequeue the
>> packets in order, it only makes sense to run a single instance of
>> the function in the whole system.
>> 
>> also, if a driver is recovering from an oactive situation (ie, it's
>> been able to free space on the tx ring) it should be able to start
>> tx again from an mpsafe interrupt context.
>> 
>> because most of our drivers assume that theyre run under the
>> KERNEL_LOCK, this diff uses a flag for the internals of the if_start
>> call to differentiate between them. it defaults for kernel locked,
>> but drivers can opt in to an mpsafe version that can call ifp->if_start
>> without the mplock held.
>> 
>> the kernel locked code takes KERNEL_LOCK and splnet before calling
>> ifp->if_start.
>> 
>> the mpsafe code uses the serialisation mechanism that the scsi
>> midlayer and pool runqueue use, but implemented with atomics instead
>> of operations under a mutex.
>> 
>> the semantic is that work will be queued onto a list protected by
>> a mutex (ie, the guts of struct ifqueue), and then a cpu will try
>> to enter a critical section that runs a function to service the
>> queued work. the cpu that enters the critical section has to dequeue
>> work in a loop, which is what all our drivers do.
>> 
>> if another cpu tries to enter the same critical section after
>> queueing more work, it will return immediately rather than spin on
>> the lock. the first cpu that is currently dequeueing work in the
>> critical section will be told to spin again to guarantee that it
>> will service the work the other cpu added.
>> 
>> so the network stack may be transmitting packets on cpu1, while an
>> interrupts on cpu0 occurs which frees up tx descriprots. if cpu0
>> calls if_start, it will return immediately because cpu1 will end
>> up doing the work it wanted to do anyway.
>> 
>> if the start routine can run on multiple cpus, then it becomes
>> necessary to know it is NOT running anymore when tearing a nic down.
>> to that end i have added an if_start_barrier function. an mpsafe
>> driver can call that when it's being brought down to guarantee that
>> another cpu isnt fiddling with the tx ring before freeing it.
>> 
>> a driver opts in to the mpsafe if_start call by doing the following:
>> 
>> 1. set ifp->if_xflags = IFXF_MPSAFE.
>> 2. calling if_start() instead of its own start routine (eg, myx_start).
>> 3. clearing IFF_RUNNING before calling if_start_barrier() on its way down.
>> 4. only using IFQ_DEQUEUE (not ifq_deq_begin/commit/rollback)
>> 
>> anyway, this is the diff i have come up with after playing with
>> several ideas. it removes the IFXF_TXREADY semantics, ie, tx
>> mitigation and reuses the flag bit for IFXF_MPSAFE.
>> 
>> the reason for that is juggling or deferring the start routine made
>> if_start_barrier annoyingly complicated, and all my attmepts at it
>> introduced a significant performance hit or were insanely complicated.
>> 
>> tx mitigation only ever gave me back 5 to 10% before it was badly
>> tweaked, and we've made a lot of other performance improvements
>> since then. while im sad to see it go, id rather move forward than
>> dwell on it.
>> 
>> in the future i would like to try delegating the work to mpsafe
>> taskqs, but in my attempts i lost something like 30% of my tx rate
>> by doing that. id like to investigate that further in the future,
>> just not right now.
>> 
>> finally, the last thing to consider is lock ordering problems.
>> because contention on the ifq_serializer causes the second context
>> to return imediately (that's true even if you call if_start from
>> within a critical section), i think all the problems are avoided.
>> i am more concerned with the ifq mutex than i am with the serialiser.
>> 
>> anyway, here's the diff to look at. happy to discuss further.
>> 
>> tests would be welcome too.
> 
> ...and i bought 10G-PCIE2-8B2L-2S although i'm 82599 fan and i will
> never give up on IX  :

but i dont want myx users. i can do pretty much what i like to that driver cos 
only two people use it.

ix is "quite" popular, so needs more care to touch.



pledge spamd(8) and spamd-setup(8)

2015-12-01 Thread Ricardo Mestre
Hello tech@!

As per Theo's request I'm sending both patches attached below for spamd(8) and
spamd-setup(8) in order to pledge them and for spamd(8) I will just transcribe
the same text I sent before, but with an addition spotted by himself after I
ran a patch on libc.

spamd(8):

Hoist the sync_init() part to the top since it calls a setsockopt(2) forbidden
by pledge(2). Then in the default mode (greylisting) spamd(8) needs
"rpath wpath" to at least open "/dev/pf", "flock" to lock the database
/var/db/spamd each time it needs to update it, "proc id" for chroot(2) and
the privdrop section. Finally it also needs "exec" since it will call pfctl(8)
to update the tables with the information it gets from the database. If not in
greylist mode (blacklist) then it only needs "rpath proc id" to chroot(2) and
privdrop. Both modes always needs "inet", and also "getpw" due to YP
environments.

After privdrop the child only needs "stdio inet" since it only accepts
connections and makes decisions on that, although doesn't seem to need more
than "inet" for that.

spamd-setup(8):

Now this one will really need someone to give an extra careful look at it since
I may, I'm almost 100% sure I did, have screw up somewhere big time. So please
review it and let me know where I got it wrong and why so I don't make the same
mistakes again (I'm still trying to revive my poor C skills from last century,
and learning new stuff as I go along, so be patient with me, although you can
still beat me with the clue stick).

First, currently the parsing of PATH_SPAMD_CONF file is done inside a while
loop and at the same time it proceeds with the loading of the black/whitelists
in the same step. In order to pledge it correctly I separated this logic by
first parsing the entire file and only afterwards getting the black/whitelists
and sending them to pfctl(8).

I created a new struct called conffile with members capability, name, message,
method and file (see spamd.conf(5)), then I basically took out all the code
referring to the parsing of the file that was within getlist() (emulating as
much as possible of code that was there) and put it in a new function called
parsefile() which parses PATH_SPAMD_CONF and adds the contents into an array
of struct conffile. I allocated memory for at most 255 objects of this type,
which I still think is overkill, so please comment this, and finally the
function returns a struct conffile*

I also had to change getlist() parameters to take a struct conffile* so I could
access its members, then the function behaves the same as before but without
all parsing that was already done in parsefile().

In main() then I call parsefile(), assign its result to "cf" object, run a loop
to check the number of members of the array, and if any of the methods are http
or ftp then assign flag=1.

If flag=1 then the program will need "rpath" to read PATH_SPAMD_CONF,
"inet dns" to download the lists, and "proc exec" for fork, running pfctl and
ftp. If flag=0 then it doesn't need "inet dns" since all methods parsed don't
need network access.

I'm truly sorry for the long email, I will try to be more succinct next time,
so without further ado:

Index: libexec/spamd/spamd.c
===
RCS file: /cvs/src/libexec/spamd/spamd.c,v
retrieving revision 1.130
diff -u -p -u -r1.130 spamd.c
--- libexec/spamd/spamd.c   10 Sep 2015 13:56:12 -  1.130
+++ libexec/spamd/spamd.c   1 Dec 2015 11:15:43 -
@@ -1335,9 +1335,22 @@ main(int argc, char *argv[])
greylist ? " (greylist)" : "",
(syncrecv || syncsend) ? " (sync)" : "");
 
-   if (!greylist)
+   if (syncsend || syncrecv) {
+   syncfd = sync_init(sync_iface, sync_baddr, sync_port);
+   if (syncfd == -1)
+   err(1, "sync init");
+   }
+
+   if (pledge("stdio rpath wpath flock inet getpw proc exec id", NULL) == 
-1)
+   err(1, "pledge");
+
+   if (!greylist) {
maxblack = maxcon;
-   else if (maxblack > maxcon)
+
+   if (pledge("stdio rpath inet getpw proc id", NULL) == -1)
+   err(1, "pledge");
+
+   } else if (maxblack > maxcon)
usage();
 
rlp.rlim_cur = rlp.rlim_max = maxcon + 15;
@@ -1403,12 +1416,6 @@ main(int argc, char *argv[])
if (bind(conflisten, (struct sockaddr *)&lin, sizeof lin) == -1)
err(1, "bind local");
 
-   if (syncsend || syncrecv) {
-   syncfd = sync_init(sync_iface, sync_baddr, sync_port);
-   if (syncfd == -1)
-   err(1, "sync init");
-   }
-
if ((pw = getpwnam("_spamd")) == NULL)
errx(1, "no such user _spamd");
 
@@ -1492,6 +1499,9 @@ jail:
setresuid(pw->pw_uid, pw->pw_uid, pw->pw_uid))
err(1, "failed to drop privs");
 
+   if (pledge("stdio inet", NULL) == -1)
+   

Re: Backward compat

2015-12-01 Thread Alexander Bluhm
On Mon, Nov 30, 2015 at 06:16:17PM +0100, Martin Pieuchot wrote:
> I'm about to kill rt_mask() and I believe it's not worth keeping this
> old backward compatibility.
> 
> Anybody disagree?  Ok?

OK bluhm@

> 
> Index: netinet/if_ether.c
> ===
> RCS file: /cvs/src/sys/netinet/if_ether.c,v
> retrieving revision 1.190
> diff -u -p -r1.190 if_ether.c
> --- netinet/if_ether.c20 Nov 2015 10:51:30 -  1.190
> +++ netinet/if_ether.c30 Nov 2015 17:13:40 -
> @@ -161,14 +161,6 @@ arp_rtrequest(struct ifnet *ifp, int req
>   switch (req) {
>  
>   case RTM_ADD:
> - /*
> -  * XXX: If this is a manually added route to interface
> -  * such as older version of routed or gated might provide,
> -  * restore cloning bit.
> -  */
> - if ((rt->rt_flags & RTF_HOST) == 0 && rt_mask(rt) &&
> - satosin(rt_mask(rt))->sin_addr.s_addr != 0x)
> - rt->rt_flags |= RTF_CLONING;
>   if (rt->rt_flags & RTF_CLONING ||
>   ((rt->rt_flags & (RTF_LLINFO | RTF_LOCAL)) && !la)) {
>   /*
> Index: netinet6/nd6.c
> ===
> RCS file: /cvs/src/sys/netinet6/nd6.c,v
> retrieving revision 1.172
> diff -u -p -r1.172 nd6.c
> --- netinet6/nd6.c6 Nov 2015 11:20:56 -   1.172
> +++ netinet6/nd6.c30 Nov 2015 17:13:40 -
> @@ -937,13 +937,6 @@ nd6_rtrequest(struct ifnet *ifp, int req
>  
>   switch (req) {
>   case RTM_ADD:
> - /*
> -  * There is no backward compatibility :)
> -  *
> -  * if ((rt->rt_flags & RTF_HOST) == 0 &&
> -  * SIN(rt_mask(rt))->sin_addr.s_addr != 0x)
> -  * rt->rt_flags |= RTF_CLONING;
> -  */
>   if ((rt->rt_flags & RTF_CLONING) ||
>   ((rt->rt_flags & (RTF_LLINFO | RTF_LOCAL)) && ln == NULL)) {
>   if (ln != NULL)



Re: lex(1) allocation cleanup

2015-12-01 Thread Ted Unangst
Michael McConville wrote:
> Theo de Raadt wrote:
> > > > If it is not our own fork -- then stay away from this.  It is
> > > > pointless putting increasing delta into code which does not run in
> > > > risk environments.
> > > 
> > > I thought we had already made that decision based on tedu's recent
> > > commits. Not sure though.
> > 
> > I am not so sure.  That fixed important bugs.
> 
> A lot of it was KNF and misc. style changes across almost every source
> file. That said, sounds like it I falsely thought that there was a
> consensus on forking.

I may have run ahead of the consensus by a bit. Let's pause.



Re: move scorefile + pledge for robots(6)

2015-12-01 Thread Theo Buehler
On Tue, Dec 01, 2015 at 03:08:39AM -0500, Ted Unangst wrote:
> Theo Buehler wrote:
> > Robots has a nicely implemented score file, so I decided not to touch
> > it, except for moving to $HOME by default.  Needs pledge("getpw")
> > because of that.
> 
> I think some combination of $LOGNAME, $USER, and getlogin() should suffice for
> that. I mean, getlogin() alone should be 99.9% reliable, but like I said
> before, maybe I want to override it with env (just because). I'd like for this
> to be consistent between games, and the current course is removing getpwuid
> calls.

I hear you.  Consistency is a good ultimate goal and I agree with the
suggestion.  I will provide a diff as soon as I will have had some
sufficiently connected chunks of free time.  I'd also like for the dust
to settle a little in /usr/games for the moment.



Re: what approach for TRNG?

2015-12-01 Thread Ted Unangst
Devin Reade wrote:
> A while ago a posted a dmesg for a TRNG USB device (the MoonBase Otago
> OneRNG) per
> .
> 
> I'm looking at adding support for this device but haven't splunked too
> much into the OpenBSD kernel before, and I'm looking for advice.
> 
> The OneRNG was manufactured to present itself as a modem and in the Linux
> sample source code the (user space) process to first initialize the device
> by echoing some commands to the device and then cat its output to rngd.
> 
> For the OpenBSD side, I found /usr/src/sys/dev/usb/ualea.c which is
> another USB-based TRNG.  The model there would be to usbd_transfer(9)
> from the device and then forward it via add_true_randomness(9).
> 
> However, because the OneRNG was manufactured to look like a modem,
> the other possibility is to have it recognised in
> /usr/src/sys/dev/usb/umodem.c.  If that's the case, though, it's
> unclear to me what the mechanism should be to pull the data from the
> OneRNG and give it to the kernel; presumably we don't want any
> userspace code here.
> 
> Am I correct in assuming that the ualea mechanism is probabably the
> right way to go?

There is some line discipline code in kern/tty_nmea.c which may also provide
some hints about interfacing with a serial device in the kernel.

That said, there's nothing particularly wrong with doing this in userland.



Re: move scorefile + pledge for robots(6)

2015-12-01 Thread Ted Unangst
Theo Buehler wrote:
> Robots has a nicely implemented score file, so I decided not to touch
> it, except for moving to $HOME by default.  Needs pledge("getpw")
> because of that.

I think some combination of $LOGNAME, $USER, and getlogin() should suffice for
that. I mean, getlogin() alone should be 99.9% reliable, but like I said
before, maybe I want to override it with env (just because). I'd like for this
to be consistent between games, and the current course is removing getpwuid
calls.