Re: _exit(2), execve(2): cancel interval timers MP-safely

2020-10-14 Thread Scott Cheloha
On Wed, Oct 14, 2020 at 08:06:52PM -0500, Scott Cheloha wrote:
> _exit(2) and execve(2) need to obey the locking protocol described in
> proc.h when manipulating the per-process interval timer state.
> 
> While we're here we can also remove the now pointless splclock/splx
> dance from execve(2).
> 
> The easiest way to obey the locking protocol is to reuse the interface
> the syscalls are using: setitimer() in kern_time.c.
> 
> Given that we only want to cancel the timers I wrote a small helper
> function, cancelitimer().  I think it's tidier than putting the
> prototype for setitimer() into sys/time.h and requiring the caller to
> prepare an itimerval struct before calling.
> 
> Compare:
> 
>   struct itimerval itv;
>   timerclear(_value);
>   timerclear(_interval);
>   setitimer(ITIMER_REAL, , NULL);
> 
> with:
> 
>   cancelitimer(ITIMER_REAL);
> 
> ... should I shove the for-loop into the helper function too?  Maybe
> call it "cancel_all_itimers()"?  I have a vague feeling that showing
> the reader that there are multiple timers is a good thing here, but
> then again maybe I'm wrong and nobody cares.
> 
> Preferences?  ok?

Whoops, forgot the kern_time.c part of the diff.

Index: kern/kern_exit.c
===
RCS file: /cvs/src/sys/kern/kern_exit.c,v
retrieving revision 1.188
diff -u -p -r1.188 kern_exit.c
--- kern/kern_exit.c18 Mar 2020 15:48:21 -  1.188
+++ kern/kern_exit.c15 Oct 2020 01:12:50 -
@@ -194,7 +194,11 @@ exit1(struct proc *p, int xexit, int xsi
/* close open files and release open-file table */
fdfree(p);
 
-   timeout_del(>ps_realit_to);
+   /* cancel all interval timers */
+   int i;
+   for (i = 0; i < nitems(pr->ps_timer); i++)
+   cancelitimer(i);
+
timeout_del(>ps_rucheck_to);
 #ifdef SYSVSEM
semexit(pr);
Index: kern/kern_exec.c
===
RCS file: /cvs/src/sys/kern/kern_exec.c,v
retrieving revision 1.217
diff -u -p -r1.217 kern_exec.c
--- kern/kern_exec.c11 Jul 2020 22:59:05 -  1.217
+++ kern/kern_exec.c15 Oct 2020 01:12:50 -
@@ -656,14 +656,9 @@ sys_execve(struct proc *p, void *v, regi
}
 
if (pr->ps_flags & PS_SUGIDEXEC) {
-   int i, s = splclock();
-
-   timeout_del(>ps_realit_to);
-   for (i = 0; i < nitems(pr->ps_timer); i++) {
-   timespecclear(>ps_timer[i].it_interval);
-   timespecclear(>ps_timer[i].it_value);
-   }
-   splx(s);
+   int i;
+   for (i = 0; i < nitems(pr->ps_timer); i++)
+   cancelitimer(i);
}
 
/* reset CPU time usage for the thread, but not the process */
Index: kern/kern_time.c
===
RCS file: /cvs/src/sys/kern/kern_time.c,v
retrieving revision 1.146
diff -u -p -r1.146 kern_time.c
--- kern/kern_time.c13 Oct 2020 17:33:39 -  1.146
+++ kern/kern_time.c15 Oct 2020 01:12:50 -
@@ -572,6 +572,16 @@ setitimer(int which, const struct itimer
}
 }
 
+void
+cancelitimer(int which)
+{
+   struct itimerval itv;
+
+   timerclear(_value);
+   timerclear(_interval);
+   setitimer(which, , NULL);
+}
+
 int
 sys_getitimer(struct proc *p, void *v, register_t *retval)
 {
Index: sys/time.h
===
RCS file: /cvs/src/sys/sys/time.h,v
retrieving revision 1.55
diff -u -p -r1.55 time.h
--- sys/time.h  6 Jul 2020 13:33:09 -   1.55
+++ sys/time.h  15 Oct 2020 01:12:50 -
@@ -307,6 +307,7 @@ time_t  getuptime(void);
 struct proc;
 intclock_gettime(struct proc *, clockid_t, struct timespec *);
 
+void   cancelitimer(int);
 intitimerfix(struct timeval *);
 intitimerdecr(struct itimerspec *, long);
 intsettime(const struct timespec *);



_exit(2), execve(2): cancel interval timers MP-safely

2020-10-14 Thread Scott Cheloha
_exit(2) and execve(2) need to obey the locking protocol described in
proc.h when manipulating the per-process interval timer state.

While we're here we can also remove the now pointless splclock/splx
dance from execve(2).

The easiest way to obey the locking protocol is to reuse the interface
the syscalls are using: setitimer() in kern_time.c.

Given that we only want to cancel the timers I wrote a small helper
function, cancelitimer().  I think it's tidier than putting the
prototype for setitimer() into sys/time.h and requiring the caller to
prepare an itimerval struct before calling.

Compare:

struct itimerval itv;
timerclear(_value);
timerclear(_interval);
setitimer(ITIMER_REAL, , NULL);

with:

cancelitimer(ITIMER_REAL);

... should I shove the for-loop into the helper function too?  Maybe
call it "cancel_all_itimers()"?  I have a vague feeling that showing
the reader that there are multiple timers is a good thing here, but
then again maybe I'm wrong and nobody cares.

Preferences?  ok?

Index: kern/kern_exec.c
===
RCS file: /cvs/src/sys/kern/kern_exec.c,v
retrieving revision 1.217
diff -u -p -r1.217 kern_exec.c
--- kern/kern_exec.c11 Jul 2020 22:59:05 -  1.217
+++ kern/kern_exec.c15 Oct 2020 01:02:45 -
@@ -656,14 +656,9 @@ sys_execve(struct proc *p, void *v, regi
}
 
if (pr->ps_flags & PS_SUGIDEXEC) {
-   int i, s = splclock();
-
-   timeout_del(>ps_realit_to);
-   for (i = 0; i < nitems(pr->ps_timer); i++) {
-   timespecclear(>ps_timer[i].it_interval);
-   timespecclear(>ps_timer[i].it_value);
-   }
-   splx(s);
+   int i;
+   for (i = 0; i < nitems(pr->ps_timer); i++)
+   cancelitimer(i);
}
 
/* reset CPU time usage for the thread, but not the process */
Index: kern/kern_exit.c
===
RCS file: /cvs/src/sys/kern/kern_exit.c,v
retrieving revision 1.188
diff -u -p -r1.188 kern_exit.c
--- kern/kern_exit.c18 Mar 2020 15:48:21 -  1.188
+++ kern/kern_exit.c15 Oct 2020 01:02:45 -
@@ -194,7 +194,11 @@ exit1(struct proc *p, int xexit, int xsi
/* close open files and release open-file table */
fdfree(p);
 
-   timeout_del(>ps_realit_to);
+   /* cancel all interval timers */
+   int i;
+   for (i = 0; i < nitems(pr->ps_timer); i++)
+   cancelitimer(i);
+
timeout_del(>ps_rucheck_to);
 #ifdef SYSVSEM
semexit(pr);
Index: sys/time.h
===
RCS file: /cvs/src/sys/sys/time.h,v
retrieving revision 1.55
diff -u -p -r1.55 time.h
--- sys/time.h  6 Jul 2020 13:33:09 -   1.55
+++ sys/time.h  15 Oct 2020 01:02:45 -
@@ -307,6 +307,7 @@ time_t  getuptime(void);
 struct proc;
 intclock_gettime(struct proc *, clockid_t, struct timespec *);
 
+void   cancelitimer(int);
 intitimerfix(struct timeval *);
 intitimerdecr(struct itimerspec *, long);
 intsettime(const struct timespec *);



Re: Expose touchpad sensitivity in wsconsctl

2020-10-14 Thread Ulf Brosziewski
I'm not convinced that this makes sense.  While there are still a lot of
touchpads around that need deceleration, modern ones tend to be larger and
more precise, so maybe we want to drop it at some point in the future?
Given that up to now, nobody else reported a problem with it, I'd prefer
to leave it in the set of "inofficial" configuration options.

On 10/14/20 9:13 PM, Brennan Vincent wrote:
> Oops, the subject should be "Expose touchpad _decleration threshold_ in 
> wsconsctl". Not sure why I wrote "sensitivity".
> 
> On Wed, 14 Oct 2020, Brennan Vincent wrote:
> 
>>
>> diff --git sbin/wsconsctl/mouse.c sbin/wsconsctl/mouse.c
>> index e04642dacbc..0f1594e17e0 100644
>> --- sbin/wsconsctl/mouse.c
>> +++ sbin/wsconsctl/mouse.c
>> @@ -61,6 +61,7 @@ struct field mouse_field_tab[] = {
>>  { "tp.swapsides",   _swapsides, FMT_CFG,
>> FLG_NORDBACK },
>>  { "tp.disable", _disable,   FMT_CFG,FLG_NORDBACK },
>>  { "tp.edges",   _edges, FMT_CFG,FLG_NORDBACK },
>> +{ "tp.deceleration",_decel, FMT_CFG,FLG_NORDBACK },
>>  { "tp.param",   _param, FMT_CFG,FLG_WRONLY },
>>  /* Add an alias.  This field is valid for all wsmouse devices. */
>>  { "param",  _param, FMT_CFG,
>> FLG_WRONLY },
>> diff --git sbin/wsconsctl/mousecfg.c sbin/wsconsctl/mousecfg.c
>> index 6d52bcbfc9c..6162df5c229 100644
>> --- sbin/wsconsctl/mousecfg.c
>> +++ sbin/wsconsctl/mousecfg.c
>> @@ -109,6 +109,12 @@ struct wsmouse_parameters cfg_revscroll = {
>>  1
>>  };
>>  
>> +struct wsmouse_parameters cfg_decel = {
>> +(struct wsmouse_param[]) {
>> +{ WSMOUSECFG_DECELERATION, 0 }, },
>> +1
>> +};
>> +
>>  struct wsmouse_parameters cfg_param = {
>>  (struct wsmouse_param[]) {
>>  { -1, 0 },
>> diff --git sbin/wsconsctl/mousecfg.h sbin/wsconsctl/mousecfg.h
>> index 8e99139d280..97ef153fcb3 100644
>> --- sbin/wsconsctl/mousecfg.h
>> +++ sbin/wsconsctl/mousecfg.h
>> @@ -22,6 +22,7 @@ extern struct wsmouse_parameters cfg_edges;
>>  extern struct wsmouse_parameters cfg_swapsides;
>>  extern struct wsmouse_parameters cfg_disable;
>>  extern struct wsmouse_parameters cfg_revscroll;
>> +extern struct wsmouse_parameters cfg_decel;
>>  extern struct wsmouse_parameters cfg_param;
>>  extern int cfg_touchpad;
>>  
>>
> 



Re: Expose touchpad sensitivity in wsconsctl

2020-10-14 Thread Brennan Vincent
People who prefer flatter profiles are not as rare as one might think, 
cf similar discussions on Libinput:

https://bugs.freedesktop.org/show_bug.cgi?id=89485

I found setting it to 4 gives best results (it was 16 by default) so I 
wouldn't want to totally remove it either.


Feel free to not merge this patch if you don't want it; I will not be 
offended. As long as I have things working how I like on my own system :)


On 10/14/20 5:16 PM, Ulf Brosziewski wrote:

I'm not convinced that this makes sense.  While there are still a lot of
touchpads around that need deceleration, modern ones tend to be larger and
more precise, so maybe we want to drop it at some point in the future?
Given that up to now, nobody else reported a problem with it, I'd prefer
to leave it in the set of "inofficial" configuration options.

On 10/14/20 9:13 PM, Brennan Vincent wrote:

Oops, the subject should be "Expose touchpad _decleration threshold_ in wsconsctl". Not 
sure why I wrote "sensitivity".

On Wed, 14 Oct 2020, Brennan Vincent wrote:


diff --git sbin/wsconsctl/mouse.c sbin/wsconsctl/mouse.c
index e04642dacbc..0f1594e17e0 100644
--- sbin/wsconsctl/mouse.c
+++ sbin/wsconsctl/mouse.c
@@ -61,6 +61,7 @@ struct field mouse_field_tab[] = {
  { "tp.swapsides",   _swapsides, FMT_CFG,
FLG_NORDBACK },
  { "tp.disable", _disable,   FMT_CFG,FLG_NORDBACK 
},
  { "tp.edges",   _edges, FMT_CFG,FLG_NORDBACK },
+{ "tp.deceleration", _decel, FMT_CFG,FLG_NORDBACK },
  { "tp.param",   _param, FMT_CFG,FLG_WRONLY },
  /* Add an alias.  This field is valid for all wsmouse devices. */
  { "param",  _param, FMT_CFG,FLG_WRONLY },
diff --git sbin/wsconsctl/mousecfg.c sbin/wsconsctl/mousecfg.c
index 6d52bcbfc9c..6162df5c229 100644
--- sbin/wsconsctl/mousecfg.c
+++ sbin/wsconsctl/mousecfg.c
@@ -109,6 +109,12 @@ struct wsmouse_parameters cfg_revscroll = {
1
  };
  
+struct wsmouse_parameters cfg_decel = {

+   (struct wsmouse_param[]) {
+   { WSMOUSECFG_DECELERATION, 0 }, },
+   1
+};
+
  struct wsmouse_parameters cfg_param = {
(struct wsmouse_param[]) {
{ -1, 0 },
diff --git sbin/wsconsctl/mousecfg.h sbin/wsconsctl/mousecfg.h
index 8e99139d280..97ef153fcb3 100644
--- sbin/wsconsctl/mousecfg.h
+++ sbin/wsconsctl/mousecfg.h
@@ -22,6 +22,7 @@ extern struct wsmouse_parameters cfg_edges;
  extern struct wsmouse_parameters cfg_swapsides;
  extern struct wsmouse_parameters cfg_disable;
  extern struct wsmouse_parameters cfg_revscroll;
+extern struct wsmouse_parameters cfg_decel;
  extern struct wsmouse_parameters cfg_param;
  extern int cfg_touchpad;
  





Non-const basename: usr.sbin/vmd, usr.sbin/vmctl

2020-10-14 Thread Christian Weisgerber
Accommodate POSIX basename(3) that takes a non-const parameter and
may in fact modify the string buffer.

The file is built by vmd and vmctl.

I'm uncertain if we want a truncation check here.  Both in vmd and
vmctl, the path has been validated by a previous open(), but given
the code complexity, do we want to rely on this?


Index: usr.sbin/vmd/vioqcow2.c
===
RCS file: /cvs/src/usr.sbin/vmd/vioqcow2.c,v
retrieving revision 1.13
diff -u -p -r1.13 vioqcow2.c
--- usr.sbin/vmd/vioqcow2.c 10 Jan 2019 19:21:02 -  1.13
+++ usr.sbin/vmd/vioqcow2.c 14 Oct 2020 20:57:31 -
@@ -145,6 +145,7 @@ virtio_qcow2_init(struct virtio_backing 
 ssize_t
 virtio_qcow2_get_base(int fd, char *path, size_t npath, const char *dpath)
 {
+   char dpathbuf[PATH_MAX];
char expanded[PATH_MAX];
struct qcheader header;
uint64_t backingoff;
@@ -186,7 +187,8 @@ virtio_qcow2_get_base(int fd, char *path
return -1;
}
} else {
-   s = dirname(dpath);
+   strlcpy(dpathbuf, dpath, sizeof(dpathbuf));
+   s = dirname(dpathbuf);
if (snprintf(expanded, sizeof(expanded),
"%s/%s", s, path) >= (int)sizeof(expanded)) {
log_warnx("path too long: %s/%s", s, path);
-- 
Christian "naddy" Weisgerber  na...@mips.inka.de



Non-const basename: usr.bin/rcs

2020-10-14 Thread Christian Weisgerber
Accommodate POSIX basename(3) that takes a non-const parameter and
may in fact modify the string buffer.

ok?

Index: usr.bin/rcs/rlog.c
===
RCS file: /cvs/src/usr.bin/rcs/rlog.c,v
retrieving revision 1.74
diff -u -p -r1.74 rlog.c
--- usr.bin/rcs/rlog.c  16 Oct 2016 13:35:51 -  1.74
+++ usr.bin/rcs/rlog.c  14 Oct 2020 20:18:55 -
@@ -28,6 +28,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -348,7 +349,7 @@ rlog_select_daterev(RCSFILE *rcsfile, ch
 static void
 rlog_file(const char *fname, RCSFILE *file)
 {
-   char numb[RCS_REV_BUFSZ];
+   char fnamebuf[PATH_MAX], numb[RCS_REV_BUFSZ];
u_int nrev;
struct rcs_sym *sym;
struct rcs_access *acp;
@@ -364,7 +365,10 @@ rlog_file(const char *fname, RCSFILE *fi
} else
nrev = file->rf_ndelta;
 
-   if ((workfile = basename(fname)) == NULL)
+   if (strlcpy(fnamebuf, fname, sizeof(fnamebuf)) >= sizeof(fnamebuf))
+   errx(1, "rlog_file: truncation");
+
+   if ((workfile = basename(fnamebuf)) == NULL)
err(1, "basename");
 
/*
-- 
Christian "naddy" Weisgerber  na...@mips.inka.de



smtpd: simplify codepath

2020-10-14 Thread Eric Faurot
When creating a tls session on an incoming connection, a useless
roundtrip through the lka is made (see cert.c) to retreive a
certificate which is not used anyway: the necessary contexts have
already been set up for all pki names (in smtp.c:smtp_setup_events()).
This diff makes the codepath more straight-forward and should not
change the current behaviour.

Please test and report if you are using server-side tls.

Eric.

Index: smtp_session.c
===
RCS file: /cvs/src/usr.sbin/smtpd/smtp_session.c,v
retrieving revision 1.426
diff -u -p -r1.426 smtp_session.c
--- smtp_session.c  24 Apr 2020 11:34:07 -  1.426
+++ smtp_session.c  14 Oct 2020 17:12:05 -
@@ -134,7 +134,6 @@ struct smtp_session {
uint64_t id;
struct io   *io;
struct listener *listener;
-   void*ssl_ctx;
struct sockaddr_storage  ss;
char rdns[HOST_NAME_MAX+1];
char smtpname[HOST_NAME_MAX+1];
@@ -193,8 +192,7 @@ static void smtp_rfc4954_auth_plain(stru
 static void smtp_rfc4954_auth_login(struct smtp_session *, char *);
 static void smtp_free(struct smtp_session *, const char *);
 static const char *smtp_strstate(int);
-static void smtp_cert_init(struct smtp_session *);
-static void smtp_cert_init_cb(void *, int, const char *, const void *, size_t);
+static void smtp_tls_init(struct smtp_session *);
 static void smtp_cert_verify(struct smtp_session *);
 static void smtp_cert_verify_cb(void *, int);
 static void smtp_auth_failure_pause(struct smtp_session *);
@@ -306,7 +304,6 @@ static struct tree wait_parent_auth;
 static struct tree wait_queue_msg;
 static struct tree wait_queue_fd;
 static struct tree wait_queue_commit;
-static struct tree wait_ssl_init;
 static struct tree wait_ssl_verify;
 static struct tree wait_filters;
 static struct tree wait_filter_fd;
@@ -587,7 +584,6 @@ smtp_session_init(void)
tree_init(_queue_msg);
tree_init(_queue_fd);
tree_init(_queue_commit);
-   tree_init(_ssl_init);
tree_init(_ssl_verify);
tree_init(_filters);
tree_init(_filter_fd);
@@ -1193,7 +1189,7 @@ smtp_io(struct io *io, int evt, void *ar
 
/* Wait for the client to start tls */
if (s->state == STATE_TLS) {
-   smtp_cert_init(s);
+   smtp_tls_init(s);
break;
}
 
@@ -2071,7 +2067,7 @@ static void
 smtp_proceed_connected(struct smtp_session *s)
 {
if (s->listener->flags & F_SMTPS)
-   smtp_cert_init(s);
+   smtp_tls_init(s);
else
smtp_send_banner(s);
 }
@@ -2261,34 +2257,20 @@ smtp_mailaddr(struct mailaddr *maddr, ch
 }
 
 static void
-smtp_cert_init(struct smtp_session *s)
+smtp_tls_init(struct smtp_session *s)
 {
-   const char *name;
-   int fallback;
+   void *ssl_ctx;
+   void *ssl;
 
-   if (s->listener->pki_name[0]) {
-   name = s->listener->pki_name;
-   fallback = 0;
-   }
+   if (s->listener->pki_name[0])
+   ssl_ctx = dict_get(env->sc_ssl_dict, s->listener->pki_name);
else {
-   name = s->smtpname;
-   fallback = 1;
+   ssl_ctx = dict_get(env->sc_ssl_dict, s->smtpname);
+   if (ssl_ctx == NULL)
+   ssl_ctx = dict_get(env->sc_ssl_dict, "*");
}
 
-   if (cert_init(name, fallback, smtp_cert_init_cb, s))
-   tree_xset(_ssl_init, s->id, s);
-}
-
-static void
-smtp_cert_init_cb(void *arg, int status, const char *name, const void *cert,
-size_t cert_len)
-{
-   struct smtp_session *s = arg;
-   void *ssl, *ssl_ctx;
-
-   tree_pop(_ssl_init, s->id);
-
-   if (status == CA_FAIL) {
+   if (ssl_ctx == NULL) {
log_info("%016"PRIx64" smtp disconnected "
"reason=ca-failure",
s->id);
@@ -2296,7 +2278,6 @@ smtp_cert_init_cb(void *arg, int status,
return;
}
 
-   ssl_ctx = dict_get(env->sc_ssl_dict, name);
ssl = ssl_smtp_init(ssl_ctx, s->listener->flags & F_TLS_VERIFY);
io_set_read(s->io);
io_start_tls(s->io, ssl);



Re: match on more ure(4) devices

2020-10-14 Thread Stefan Hagen
Hi Jonathan,

Jonathan Gray wrote:
> match on additional device ids from lenovo windows driver
> https://download.lenovo.com/consumer/options/thinkpad_usb-c_dock_gen2_drivers_v1.0.3.03241.exe
> and linux driver
[...]
> +   { USB_VENDOR_LENOVO, USB_PRODUCT_LENOVO_RTL8153B_2 },
[...]

This is an audio device in the Lenovo Thunderbolt 3 Workstation Dock Gen 2.
I've sent a bug report with dmesg to bugs@ for it an hour ago.

This is the windows driver for this dock. If you want to cross check.
https://download.lenovo.com/consumer/options/thinkpad_tbt3_gen2_ws_dock_driver_10016.exe

Best Regards,
Stefan



Re: Expose touchpad sensitivity in wsconsctl

2020-10-14 Thread Brennan Vincent
Oops, the subject should be "Expose touchpad _decleration threshold_ in 
wsconsctl". Not sure why I wrote "sensitivity".

On Wed, 14 Oct 2020, Brennan Vincent wrote:

> 
> diff --git sbin/wsconsctl/mouse.c sbin/wsconsctl/mouse.c
> index e04642dacbc..0f1594e17e0 100644
> --- sbin/wsconsctl/mouse.c
> +++ sbin/wsconsctl/mouse.c
> @@ -61,6 +61,7 @@ struct field mouse_field_tab[] = {
>  { "tp.swapsides",_swapsides, FMT_CFG,
> FLG_NORDBACK },
>  { "tp.disable",  _disable,   FMT_CFG,FLG_NORDBACK },
>  { "tp.edges",_edges, FMT_CFG,FLG_NORDBACK },
> +{ "tp.deceleration", _decel, FMT_CFG,FLG_NORDBACK },
>  { "tp.param",_param, FMT_CFG,FLG_WRONLY },
>  /* Add an alias.  This field is valid for all wsmouse devices. */
>  { "param",   _param, FMT_CFG,
> FLG_WRONLY },
> diff --git sbin/wsconsctl/mousecfg.c sbin/wsconsctl/mousecfg.c
> index 6d52bcbfc9c..6162df5c229 100644
> --- sbin/wsconsctl/mousecfg.c
> +++ sbin/wsconsctl/mousecfg.c
> @@ -109,6 +109,12 @@ struct wsmouse_parameters cfg_revscroll = {
>   1
>  };
>  
> +struct wsmouse_parameters cfg_decel = {
> + (struct wsmouse_param[]) {
> + { WSMOUSECFG_DECELERATION, 0 }, },
> + 1
> +};
> +
>  struct wsmouse_parameters cfg_param = {
>   (struct wsmouse_param[]) {
>   { -1, 0 },
> diff --git sbin/wsconsctl/mousecfg.h sbin/wsconsctl/mousecfg.h
> index 8e99139d280..97ef153fcb3 100644
> --- sbin/wsconsctl/mousecfg.h
> +++ sbin/wsconsctl/mousecfg.h
> @@ -22,6 +22,7 @@ extern struct wsmouse_parameters cfg_edges;
>  extern struct wsmouse_parameters cfg_swapsides;
>  extern struct wsmouse_parameters cfg_disable;
>  extern struct wsmouse_parameters cfg_revscroll;
> +extern struct wsmouse_parameters cfg_decel;
>  extern struct wsmouse_parameters cfg_param;
>  extern int cfg_touchpad;
>  
> 



Re: Lenovo X1 gen 8 touchpad interrupt: pchgpio(4)

2020-10-14 Thread Mark Kettenis
> From: James Hastings 
> Date: Sun, 11 Oct 2020 03:49:11 -0400 (EDT)
> 
> On Thu, 08 Oct 2020 20:29:38 + Mark Kettenis wrote:
> > Diff below adds a driver for the GPIO controller found on the Intel
> > 400 Series PCH as found on (for example) the Lenovo X1 gen 8 laptop.
> > Since I don't have such hardware, I'd appreciate some tests on laptops
> > that current show:
> > 
> > "INT34BB" at acpi0 not configured
> > 
> 
> Thanks for the driver Mark! Compiles fine here but panics like this:
> ihidev0 at iic0 addr 0x2c gpio 291panic: kernel diagnostic assertion "pin >= 
> 0 && pin < sc->sc_npins" failed: file "/usr/src/sys/dev/acpi/pchgpio.c", line 
> 335
> 
> Let me know any way I can help.

Can you figure out what pin number it is trying to use?

Thanks,

Mark

P.S. Feel free to finish the driver yourself if you have time.  This
 sort of thing is way easier if you have the hardware.  The
 hardware itself should be very similar to aplgpio(4).  It's just
 that the registers moved around a bit and there is a single ACPI
 device for all the pin "communities" instead of the model of
 separate ACPI devices for each community that aplgpio(4) uses.



Re: drm: avoid possible deadlock in kthread_stop

2020-10-14 Thread Mark Kettenis
> Date: Thu, 1 Oct 2020 09:09:50 +0200
> From: Sebastien Marie 
> 
> Hi,
> 
> Currently, when a process is calling kthread_stop(), it sets a flag
> asking the thread to stop, and enters in sleep mode, but the code
> doing the stop doesn't wakeup the caller of kthread_stop().
> 
> The thread should also be unparked as else it will not seen the
> KTHREAD_SHOULDSTOP flag. it follows what Linux is doing.
> 
> While here, I added some comments in the locking logic for park/unpark
> and stop.
> 
> Comments or OK ?

I don't think adding all those comments makes a lot of sense.  This
uses a fairly standard tsleep/wakeup pattern and the some of the
comments really state the obvious.  Can you do a diff that just adds
the missing wakeup() and kthread_unpark() call?

> ---
> commit 70e71461c8598e28820f1743923cac40670f7c33
> from: Sébastien Marie 
> date: Thu Oct  1 07:02:46 2020 UTC
>  
>  properly support kthread_stop()
>  - wakeup pthread_stop() caller
>  - unpark the thread if parked
>  
>  while here, add comments for locking logic for park/unpark/stop
>  
> diff ec329a4429e2542bc24dd017b8001b22df43564c 
> ce2b5031503711bbdd7a3067c76c4f18b1d8da82
> blob - 2cbd0905406ccc9d89c86cee38673a4e9c3fcf42
> blob + f0e5a5a1b282c071c97505556510952ee7a6282a
> --- sys/dev/pci/drm/drm_linux.c
> +++ sys/dev/pci/drm/drm_linux.c
> @@ -206,6 +206,10 @@ kthread_func(void *arg)
>  
>   ret = thread->func(thread->data);
>   thread->flags |= KTHREAD_STOPPED;
> +
> + /* wakeup thread waiting in kthread_stop() */
> + wakeup(thread);
> +
>   kthread_exit(ret);
>  }
>  
> @@ -256,7 +260,14 @@ kthread_parkme(void)
>  
>   while (thread->flags & KTHREAD_SHOULDPARK) {
>   thread->flags |= KTHREAD_PARKED;
> +
> + /* 
> +  * wakeup kthread_park() caller
> +  * to signal I am parked as asked.
> +  */
>   wakeup(thread);
> +
> + /* wait for someone to kthread_unpark() me */
>   tsleep_nsec(thread, PPAUSE, "parkme", INFSLP);
>   thread->flags &= ~KTHREAD_PARKED;
>   }
> @@ -269,7 +280,13 @@ kthread_park(struct proc *p)
>  
>   while ((thread->flags & KTHREAD_PARKED) == 0) {
>   thread->flags |= KTHREAD_SHOULDPARK;
> +
>   wake_up_process(thread->proc);
> +
> + /*
> +  * wait for thread to be parked.
> +  * the asked thread should call kthread_parkme()
> +  */
>   tsleep_nsec(thread, PPAUSE, "park", INFSLP);
>   }
>  }
> @@ -280,6 +297,8 @@ kthread_unpark(struct proc *p)
>   struct kthread *thread = kthread_lookup(p);
>  
>   thread->flags &= ~KTHREAD_SHOULDPARK;
> +
> + /* wakeup kthread_parkme() caller */
>   wakeup(thread);
>  }
>  
> @@ -297,7 +316,13 @@ kthread_stop(struct proc *p)
>  
>   while ((thread->flags & KTHREAD_STOPPED) == 0) {
>   thread->flags |= KTHREAD_SHOULDSTOP;
> +
> + /* kthread_unpark() the thread if parked */
> + kthread_unpark(p);
> +
>   wake_up_process(thread->proc);
> + 
> + /* wait for thread to stop (func() should return) */
>   tsleep_nsec(thread, PPAUSE, "stop", INFSLP);
>   }
>   LIST_REMOVE(thread, next);
> 
> 
> 



Expose touchpad sensitivity in wsconsctl

2020-10-14 Thread Brennan Vincent


diff --git sbin/wsconsctl/mouse.c sbin/wsconsctl/mouse.c
index e04642dacbc..0f1594e17e0 100644
--- sbin/wsconsctl/mouse.c
+++ sbin/wsconsctl/mouse.c
@@ -61,6 +61,7 @@ struct field mouse_field_tab[] = {
 { "tp.swapsides",  _swapsides, FMT_CFG,FLG_NORDBACK },
 { "tp.disable",_disable,   FMT_CFG,FLG_NORDBACK },
 { "tp.edges",  _edges, FMT_CFG,FLG_NORDBACK },
+{ "tp.deceleration",   _decel, FMT_CFG,FLG_NORDBACK },
 { "tp.param",  _param, FMT_CFG,FLG_WRONLY },
 /* Add an alias.  This field is valid for all wsmouse devices. */
 { "param", _param, FMT_CFG,FLG_WRONLY },
diff --git sbin/wsconsctl/mousecfg.c sbin/wsconsctl/mousecfg.c
index 6d52bcbfc9c..6162df5c229 100644
--- sbin/wsconsctl/mousecfg.c
+++ sbin/wsconsctl/mousecfg.c
@@ -109,6 +109,12 @@ struct wsmouse_parameters cfg_revscroll = {
1
 };
 
+struct wsmouse_parameters cfg_decel = {
+   (struct wsmouse_param[]) {
+   { WSMOUSECFG_DECELERATION, 0 }, },
+   1
+};
+
 struct wsmouse_parameters cfg_param = {
(struct wsmouse_param[]) {
{ -1, 0 },
diff --git sbin/wsconsctl/mousecfg.h sbin/wsconsctl/mousecfg.h
index 8e99139d280..97ef153fcb3 100644
--- sbin/wsconsctl/mousecfg.h
+++ sbin/wsconsctl/mousecfg.h
@@ -22,6 +22,7 @@ extern struct wsmouse_parameters cfg_edges;
 extern struct wsmouse_parameters cfg_swapsides;
 extern struct wsmouse_parameters cfg_disable;
 extern struct wsmouse_parameters cfg_revscroll;
+extern struct wsmouse_parameters cfg_decel;
 extern struct wsmouse_parameters cfg_param;
 extern int cfg_touchpad;
 



[s...@spacehopper.org: Re: Remove useless line from daemon class in login.conf]

2020-10-14 Thread Stuart Henderson
Just found this in my local tree still, iirc danj liked it but there
wasn't much other enthusiasm. Any other comments? Should I just drop
the diff? Change 'a' to use 2^10 minimum? Change to fixed 2^10 with
no auto measurement?

- Forwarded message from Stuart Henderson  -

From: Stuart Henderson 
Date: Sat, 23 May 2020 22:08:11 +0100
Subject: Re: Remove useless line from daemon class in login.conf

On 2020/05/22 16:04, Theo de Raadt wrote:
> Stuart Henderson  wrote:
> 
> > On 2020/05/22 17:06, Daniel Jakots wrote:
> > > Hi,
> > > 
> > > We used to have different numbers of blowfish rounds between the
> > > default and daemon classes in login.conf. On Jun 26, 2016, tedu
> > > committed "upgrade selected login.conf to use auto rounds for bcrypt"
> > > for amd64, sparc64, i386, and maccpc [1].
> > > 
> > > Since the class daemon inherits from the default class, the 
> > > :localcipher=blowfish,a:\
> > > is a duplicate.
> > > 
> > > Here's a diff to remove them.
> > 
> > I'm OK with unifying these settings, but FWIW I never switched to auto
> > for these, it doesn't seem all that sensible for somebody with the ability
> > to generate enough load on the machine to be able to reduce the strength
> > of bcrypt down to the 64 (2^6) rounds minimum.
> 
> Yes, that is problematic.
> 
> The minimum should be probably be raised, we should consider if auto
> should even exist anymore.
> 

As long as it doesn't allow weakening things I think auto should still
exist so that machines can have a stronger bcrypt where it's cheap.

When this was introduced, login.conf for amd64/i386/macppc/sparc64
changed from 8 (normal users) and 9 (daemon class i.e. root) to auto.
Since other, mainly slower, arches stayed with hardcoded 8/9 I don't
think the current minimum reachable in the code makes sense at all.

I've gone to a few machines and done:

- 50 runs of "encrypt -b a" to see what setting was chosen by auto

for i in `jot 50`; do echo foo | encrypt -b a; sleep .1; done | cut -d'$' -f3 | 
sort | uniq -c

- 50 runs of "encrypt -b 9" or "encrypt -b 10" and averaged, to see
how long those two settings take

time for i in `jot 50`; do echo foo | encrypt -b 10; done
(divided by 50)

Chosen  -b 9-b 10
Cortex-A53 1.4GHz (pi3) all 8   0.220.40
GX-412TC 1GHz (APU2)all 8   0.160.31
Cortex-A72 1.5GHz (pi4) all 9   0.070.14
L5520 2.27GHz   all 9   0.080.16
E3-1225v3 3.2GHz12x8 3x9 35x10  0.050.10
E3-1240v5 3.5GHzall 10  0.040.08
E3-1270v6 3.8GHzall 11  0.030.05

I think bumping the minimum to 2^9 would be reasonable, there's a more
noticeable delay on some machines but I think that's fair enough (any
cracking is likely to be done on a fast machine, and the user can force
it lower themselves if they want to take the risk).

With a higher minimum than that the delay starts to get very noticeable
in some cases, so I'm not sure we're ready for that yet.

I think it also makes sense to use blowfish,a in login.conf on all
arches, replacing the old 8/9. Actually -b a is already used in the
installer for both root and the standard user on all archs, whatever
they have in login.conf. Resulting in the situation that on some
archs, the bcrypt created during install for root's password is
weaker than it would be if reset after boot.

So maybe this or something like it?

Index: lib/libc/crypt/bcrypt.c
===
RCS file: /cvs/src/lib/libc/crypt/bcrypt.c,v
retrieving revision 1.57
diff -u -p -r1.57 bcrypt.c
--- lib/libc/crypt/bcrypt.c 26 Aug 2016 08:25:02 -  1.57
+++ lib/libc/crypt/bcrypt.c 23 May 2020 20:16:46 -
@@ -237,14 +237,15 @@ bcrypt_checkpass(const char *pass, const
 DEF_WEAK(bcrypt_checkpass);
 
 /*
- * Measure this system's performance by measuring the time for 8 rounds.
- * We are aiming for something that takes around 0.1s, but not too much over.
+ * Measure this system's performance by measuring the time for 2^9 rounds.
+ * We are aiming for something that takes around 0.1s, not too much over,
+ * but without allowing it to be too weak.
  */
 int
 _bcrypt_autorounds(void)
 {
struct timespec before, after;
-   int r = 8;
+   int r = 9;
char buf[_PASSWORD_LEN];
int duration;
 
@@ -257,12 +258,12 @@ _bcrypt_autorounds(void)
duration += (after.tv_nsec - before.tv_nsec) / 1000;
 
/* too quick? slow it down. */
-   while (r < 16 && duration <= 6) {
+   while (r < 16 && duration <= 75000) {
r += 1;
duration *= 2;
}
/* too slow? speed it up. */
-   while (r > 6 && duration > 12) {
+   while (r > 10 && duration > 12) {
r -= 1;
duration /= 2;
}
Index: etc/etc.alpha/login.conf
===
RCS file: 

uvm_grow(): serialize updates

2020-10-14 Thread Martin Pieuchot
Getting uvm_fault() out of the KERNEL_LOCK() alone is not enough to
reduce the contention due to page faults.  A single part of the handler
spinning on the lock is enough to hide bugs and increase latency.  One
recent example is the uvm_map_inentry() check.

uvm_grow() is another small function called in trap that currently needs
the KERNEL_LOCK().  Diff below changes this requirement without removing
the KERNEL_LOCK() yet. 

It uses the underlying vm_space lock to serialize writes to the fields
of "truct vmspace". 

While here I also documented that the reference counting is currently
protected by the KERNEL_LOCK() and introduced a wrapper to help with
future changes and reduce the differences with NetBSD.

Once uvm_grow() is safe to be called without the KERNEL_LOCK() MD trap
functions can be adapted on a case-per-case basis.

Comments, Oks?

Index: kern/kern_sysctl.c
===
RCS file: /cvs/src/sys/kern/kern_sysctl.c,v
retrieving revision 1.379
diff -u -p -r1.379 kern_sysctl.c
--- kern/kern_sysctl.c  1 Sep 2020 01:53:50 -   1.379
+++ kern/kern_sysctl.c  14 Oct 2020 09:35:00 -
@@ -1783,7 +1783,7 @@ sysctl_proc_args(int *name, u_int namele
/* Execing - danger. */
if ((vpr->ps_flags & PS_INEXEC))
return (EBUSY);
-   
+
/* Only owner or root can get env */
if ((op == KERN_PROC_NENV || op == KERN_PROC_ENV) &&
(vpr->ps_ucred->cr_uid != cp->p_ucred->cr_uid &&
@@ -1792,7 +1792,7 @@ sysctl_proc_args(int *name, u_int namele
 
ps_strings = vpr->ps_strings;
vm = vpr->ps_vmspace;
-   vm->vm_refcnt++;
+   uvmspace_addref(vm);
vpr = NULL;
 
buf = malloc(PAGE_SIZE, M_TEMP, M_WAITOK);
Index: kern/sys_process.c
===
RCS file: /cvs/src/sys/kern/sys_process.c,v
retrieving revision 1.83
diff -u -p -r1.83 sys_process.c
--- kern/sys_process.c  16 Mar 2020 11:58:46 -  1.83
+++ kern/sys_process.c  14 Oct 2020 09:35:00 -
@@ -850,13 +850,12 @@ process_domem(struct proc *curp, struct 
if ((error = process_checkioperm(curp, tr)) != 0)
return error;
 
-   /* XXXCDC: how should locking work here? */
vm = tr->ps_vmspace;
if ((tr->ps_flags & PS_EXITING) || (vm->vm_refcnt < 1))
return EFAULT;
addr = uio->uio_offset;
 
-   vm->vm_refcnt++;
+   uvmspace_addref(vm);
 
error = uvm_io(>vm_map, uio,
(uio->uio_rw == UIO_WRITE) ? UVM_IO_FIXPROT : 0);
@@ -892,7 +891,7 @@ process_auxv_offset(struct proc *curp, s
if ((tr->ps_flags & PS_EXITING) || (vm->vm_refcnt < 1))
return EFAULT;
 
-   vm->vm_refcnt++;
+   uvmspace_addref(vm);
error = uvm_io(>vm_map, , 0);
uvmspace_free(vm);
 
Index: uvm/uvm_extern.h
===
RCS file: /cvs/src/sys/uvm/uvm_extern.h,v
retrieving revision 1.153
diff -u -p -r1.153 uvm_extern.h
--- uvm/uvm_extern.h13 Sep 2020 10:05:25 -  1.153
+++ uvm/uvm_extern.h14 Oct 2020 09:35:00 -
@@ -192,11 +192,13 @@ struct pmap;
  * Several fields are temporary (text, data stuff).
  *
  *  Locks used to protect struct members in this file:
+ * K   kernel lock
  * I   immutable after creation
+ * v   vm_map's lock
  */
 struct vmspace {
struct  vm_map vm_map;  /* VM address map */
-   int vm_refcnt;  /* number of references */
+   int vm_refcnt;  /* [K] number of references */
caddr_t vm_shm; /* SYS5 shared memory private data XXX */
 /* we copy from vm_startcopy to the end of the structure on fork */
 #define vm_startcopy vm_rssize
@@ -205,9 +207,9 @@ struct vmspace {
segsz_t vm_tsize;   /* text size (pages) XXX */
segsz_t vm_dsize;   /* data size (pages) XXX */
segsz_t vm_dused;   /* data segment length (pages) XXX */
-   segsz_t vm_ssize;   /* stack size (pages) */
-   caddr_t vm_taddr;   /* user virtual address of text XXX */
-   caddr_t vm_daddr;   /* user virtual address of data XXX */
+   segsz_t vm_ssize;   /* [v] stack size (pages) */
+   caddr_t vm_taddr;   /* [I] user virtual address of text */
+   caddr_t vm_daddr;   /* [I] user virtual address of data */
caddr_t vm_maxsaddr;/* [I] user VA at max stack growth */
caddr_t vm_minsaddr;/* [I] user VA at top of stack */
 };
@@ -413,6 +415,7 @@ voiduvmspace_init(struct vmspace *, 
s
vaddr_t, vaddr_t, boolean_t, boolean_t);
 void   uvmspace_exec(struct proc *, vaddr_t, vaddr_t);
 struct vmspace *uvmspace_fork(struct process *);
+void   uvmspace_addref(struct vmspace *);
 void   uvmspace_free(struct vmspace *);
 struct vmspace