Remove unused fields from struct in6_ifextra

2022-11-11 Thread Klemens Nanni
This is all under _KERNEL:
- rs_lhcookie was added in 2014 110585f259f4974284e531f0a1e121b001a580dc
  "Move sending of router solicitations to the kernel; [...]"
  but never used
- nprefixes and ndefrouters became obsolete with 2017
  4a2f474d14c160dc7829cce0149ead09d473ece9
  "Remove sending of router solicitations and processing of router
   advertisements from the kernel. [...]"

OK?

Index: netinet6/in6_var.h
===
RCS file: /cvs/src/sys/netinet6/in6_var.h,v
retrieving revision 1.74
diff -u -p -r1.74 in6_var.h
--- netinet6/in6_var.h  2 Jan 2022 22:36:04 -   1.74
+++ netinet6/in6_var.h  12 Nov 2022 03:00:53 -
@@ -90,9 +90,6 @@ struct in6_addrlifetime {
 struct nd_ifinfo;
 struct in6_ifextra {
struct nd_ifinfo *nd_ifinfo;
-   void *rs_lhcookie;
-   int nprefixes;
-   int ndefrouters;
 };
 
 struct in6_ifaddr {
Index: netinet6/in6.c
===
RCS file: /cvs/src/sys/netinet6/in6.c,v
retrieving revision 1.249
diff -u -p -r1.249 in6.c
--- netinet6/in6.c  8 Sep 2022 10:22:06 -   1.249
+++ netinet6/in6.c  12 Nov 2022 03:00:37 -
@@ -1602,8 +1602,6 @@ in6_domifattach(struct ifnet *ifp)
ext = malloc(sizeof(*ext), M_IFADDR, M_WAITOK | M_ZERO);
 
ext->nd_ifinfo = nd6_ifattach(ifp);
-   ext->nprefixes = 0;
-   ext->ndefrouters = 0;
return ext;
 }
 



Re: netstart: wait for autoconf on RUNNING interfaces only

2022-11-11 Thread Florian Obser
On 2022-11-11 20:15 UTC, Klemens Nanni  wrote:
> On Fri, Nov 11, 2022 at 07:00:27PM +, Florian Obser wrote:
>> On 2022-11-11 16:55 UTC, Klemens Nanni  wrote:
>> > Only /etc/hostname.athn0 contains autoconf on my X230.
>> >
>> > When the hardware switch turned off, netstart still waits 10 seconds:
>> >
>> >$ ifconfig athn0
>> >athn0: 
>> > flags=a48803
>> >  mtu 1500
>> >lladdr 04:f0:21:30:37:de
>> >index 2 priority 4 llprio 3
>> >groups: wlan
>> >media: IEEE802.11 autoselect
>> >status: no network
>> >ieee80211: nwid ""
>> >
>> ># time sh /etc/netstart
>> >0m11.48s real 0m00.93s user 0m00.55s system
>> >
>> > For DHCP/SLAAC to kick in, the interface must be UP and RUNNING, so this
>> > won't exit ealier unless I turn the switch on *and* athn0 gets an IP and
>> > default route within those ten seconds, which is quite unlikely, imho.
>> >
>> > Make netstart wait for RUNNING interfaces only so booting in guaranteed
>> > offline mode won't stall for nothing:
>> >
>> ># time sh ./netstart
>> >0m00.73s real 0m00.57s user 0m00.20s system
>> >
>> > Feedback? Objection? OK?
>> 
>> I have a suspicion that netstart(8) could win the race against the
>> kernel and see an interface as not yet running while it currently comes
>> up, defeating the purpose.
>
> When 'ifconfig athn0 inet autoconf' returns, UP and RUNNING should be
> set immediately.
>
> SIOCSIFXFLAGS directly sets those flags without any asynchronous logic
> that would make ifconfig return early and set flags later in the
> kernel.

I see 155 instances of

if_flags |= IFF_RUNNING

I don't find it obvious that IFF_RUNNING is set when ifconfig $IF inet
autoconf returns. Maybe it is true, but I don't see it.

>
> Am I missing something here?
>
>> 
>> On my laptop I'm setting a blackhole default route in one of my
>> hostname.if(5) files to get past the sleeping in netstart(8).
>
> That just sounds like a different "fix" for this naive sleep logic.
>
>> 
>> >
>> > Index: netstart
>> > ===
>> > RCS file: /cvs/src/etc/netstart,v
>> > retrieving revision 1.229
>> > diff -u -p -r1.229 netstart
>> > --- netstart   5 Nov 2022 12:06:05 -   1.229
>> > +++ netstart   11 Nov 2022 16:44:44 -
>> > @@ -292,7 +292,7 @@ ip6routes() {
>> >  wait_autoconf_default() {
>> >local _count=0
>> >  
>> > -  if ifconfig | grep -q ': flags=.*<.*AUTOCONF.*>'; then
>> > +  if ifconfig | grep -q ': flags=.*<.*RUNNING.*AUTOCONF.*>'; then
>> >while ((_count++ < 20)); do
>> >route -n show | grep -q ^default && break
>> >sleep .5
>> >
>> 
>> -- 
>> I'm not entirely sure you are real.
>> 
>

-- 
I'm not entirely sure you are real.



Re: size: improve column alignment

2022-11-11 Thread Klemens Nanni
On Sun, Oct 30, 2022 at 09:30:50PM +, Klemens Nanni wrote:
> size(1) output is not padded and uses a single tab between each column
> which often looks ugly:
> 
>   $ size bsd /usr/lib/libc.so.96.4 `which echo cc`
>   textdatabss dec hex
>   896234  31208   54664   982106  efc5a   /usr/lib/libc.so.96.4
>   106152  11200   12640   129992  1fbc8   /bin/echo
>   8439822141416   343049  8478268650dae5e /usr/bin/cc
> 
> 
> The GNU implementation looks less off:
> 
>   # pkg_add binutils
>   binutils-2.39: ok
> 
>   $ gsize bsd /usr/lib/libc.so.96.4 `which echo cc`
>  textdata bss dec hex filename
>896234   31208   54664  982106   efc5a /usr/lib/libc.so.96.4
>106152   11200   12640  129992   1fbc8 /bin/echo
>   84398221  41416  343049 8478268650dae5e /usr/bin/cc
> 
> I haven't checked their code, but padding fields to seven chars and
> delimiting with a tab yields their format (modulo "filename" printing):
> 
>   $ obj/size bsd /usr/lib/libc.so.96.4 `which echo cc`
>  textdata bss dec hex
>896234   31208   54664  982106   efc5a /usr/lib/libc.so.96.4
>106152   11200   12640  129992   1fbc8 /bin/echo
>   84398221  41416  343049 8478268650dae5e /usr/bin/cc
> 
> Big files are still off, but at least fields are now aligned.
> 
> Another alternative could be to pad fields to eight chars and delimit
> with a space, causing both small and big files to align nicely whilst
> staying under 80 chars total width with reasonable file names
> (which I left delimited with a tab... coulde be space for consistency):
> 
>   $ grep %8 nm.c
>   printf("%8s %8s %8s %8s %8s\n",
>   printf("%8lu %8lu %8lu %8lu %8lx",
>   $ obj/size bsd /usr/lib/libc.so.96.4 `which echo cc`
>   text data  bss  dec  hex
> 8962343120854664   982106efc5a/usr/lib/libc.so.96.4
> 1061521120012640   1299921fbc8/bin/echo
>   8439822141416   343049 84782686  50dae5e/usr/bin/cc
> 
> What do others think?
> Diff below switches to the GNU format, keeping tabs in outputs.
> 
> One possible concern is scripts parsing size(1) output with anything but
> awk(1), but at least base does not seem to contain Makefiles that depend
> on the exact current format.

Anyone?

More Conservative GNU-format diff reattached below, although I'd be
happy to switch to the better looking 8-spaces padding as seen above...

Index: nm.c
===
RCS file: /cvs/src/usr.bin/nm/nm.c,v
retrieving revision 1.54
diff -u -p -r1.54 nm.c
--- nm.c3 Mar 2019 16:07:39 -   1.54
+++ nm.c30 Oct 2022 21:21:17 -
@@ -682,11 +682,12 @@ show_file(int count, int warn_fmt, const
 
if (first) {
first = 0;
-   printf("text\tdata\tbss\tdec\thex\n");
+   printf("%8s %8s %8s %8s %8s\n",
+   "text", "data", "bss", "dec", "hex");
}
 
total = text + data + bss;
-   printf("%lu\t%lu\t%lu\t%lu\t%lx",
+   printf("%8lu %8lu %8lu %8lu %8lx",
text, data, bss, total, total);
if (count > 1)
(void)printf("\t%s", name);



Re: netstart: wait for autoconf on RUNNING interfaces only

2022-11-11 Thread Klemens Nanni
On Fri, Nov 11, 2022 at 07:00:27PM +, Florian Obser wrote:
> On 2022-11-11 16:55 UTC, Klemens Nanni  wrote:
> > Only /etc/hostname.athn0 contains autoconf on my X230.
> >
> > When the hardware switch turned off, netstart still waits 10 seconds:
> >
> > $ ifconfig athn0
> > athn0: 
> > flags=a48803
> >  mtu 1500
> > lladdr 04:f0:21:30:37:de
> > index 2 priority 4 llprio 3
> > groups: wlan
> > media: IEEE802.11 autoselect
> > status: no network
> > ieee80211: nwid ""
> >
> > # time sh /etc/netstart
> > 0m11.48s real 0m00.93s user 0m00.55s system
> >
> > For DHCP/SLAAC to kick in, the interface must be UP and RUNNING, so this
> > won't exit ealier unless I turn the switch on *and* athn0 gets an IP and
> > default route within those ten seconds, which is quite unlikely, imho.
> >
> > Make netstart wait for RUNNING interfaces only so booting in guaranteed
> > offline mode won't stall for nothing:
> >
> > # time sh ./netstart
> > 0m00.73s real 0m00.57s user 0m00.20s system
> >
> > Feedback? Objection? OK?
> 
> I have a suspicion that netstart(8) could win the race against the
> kernel and see an interface as not yet running while it currently comes
> up, defeating the purpose.

When 'ifconfig athn0 inet autoconf' returns, UP and RUNNING should be
set immediately.

SIOCSIFXFLAGS directly sets those flags without any asynchronous logic
that would make ifconfig return early and set flags later in the kernel.

Am I missing something here?

> 
> On my laptop I'm setting a blackhole default route in one of my
> hostname.if(5) files to get past the sleeping in netstart(8).

That just sounds like a different "fix" for this naive sleep logic.

> 
> >
> > Index: netstart
> > ===
> > RCS file: /cvs/src/etc/netstart,v
> > retrieving revision 1.229
> > diff -u -p -r1.229 netstart
> > --- netstart5 Nov 2022 12:06:05 -   1.229
> > +++ netstart11 Nov 2022 16:44:44 -
> > @@ -292,7 +292,7 @@ ip6routes() {
> >  wait_autoconf_default() {
> > local _count=0
> >  
> > -   if ifconfig | grep -q ': flags=.*<.*AUTOCONF.*>'; then
> > +   if ifconfig | grep -q ': flags=.*<.*RUNNING.*AUTOCONF.*>'; then
> > while ((_count++ < 20)); do
> > route -n show | grep -q ^default && break
> > sleep .5
> >
> 
> -- 
> I'm not entirely sure you are real.
> 



Re: netstart: wait for autoconf on RUNNING interfaces only

2022-11-11 Thread Florian Obser
On 2022-11-11 16:55 UTC, Klemens Nanni  wrote:
> Only /etc/hostname.athn0 contains autoconf on my X230.
>
> When the hardware switch turned off, netstart still waits 10 seconds:
>
>   $ ifconfig athn0
>   athn0: 
> flags=a48803
>  mtu 1500
>   lladdr 04:f0:21:30:37:de
>   index 2 priority 4 llprio 3
>   groups: wlan
>   media: IEEE802.11 autoselect
>   status: no network
>   ieee80211: nwid ""
>
>   # time sh /etc/netstart
>   0m11.48s real 0m00.93s user 0m00.55s system
>
> For DHCP/SLAAC to kick in, the interface must be UP and RUNNING, so this
> won't exit ealier unless I turn the switch on *and* athn0 gets an IP and
> default route within those ten seconds, which is quite unlikely, imho.
>
> Make netstart wait for RUNNING interfaces only so booting in guaranteed
> offline mode won't stall for nothing:
>
>   # time sh ./netstart
>   0m00.73s real 0m00.57s user 0m00.20s system
>
> Feedback? Objection? OK?

I have a suspicion that netstart(8) could win the race against the
kernel and see an interface as not yet running while it currently comes
up, defeating the purpose.

On my laptop I'm setting a blackhole default route in one of my
hostname.if(5) files to get past the sleeping in netstart(8).

>
> Index: netstart
> ===
> RCS file: /cvs/src/etc/netstart,v
> retrieving revision 1.229
> diff -u -p -r1.229 netstart
> --- netstart  5 Nov 2022 12:06:05 -   1.229
> +++ netstart  11 Nov 2022 16:44:44 -
> @@ -292,7 +292,7 @@ ip6routes() {
>  wait_autoconf_default() {
>   local _count=0
>  
> - if ifconfig | grep -q ': flags=.*<.*AUTOCONF.*>'; then
> + if ifconfig | grep -q ': flags=.*<.*RUNNING.*AUTOCONF.*>'; then
>   while ((_count++ < 20)); do
>   route -n show | grep -q ^default && break
>   sleep .5
>

-- 
I'm not entirely sure you are real.



Re: Push kernel lock into nd6_ioctl()

2022-11-11 Thread Klemens Nanni
This was in fact in_ioctl_get().

---
Push kernel lock into nd6_ioctl()

Purely mechanical.

Feedback? OK?
---
 sys/netinet6/in6.c | 2 --
 sys/netinet6/nd6.c | 5 +
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/sys/netinet6/in6.c b/sys/netinet6/in6.c
index 65f4b44e700..3c5b47bc1ed 100644
--- a/sys/netinet6/in6.c
+++ b/sys/netinet6/in6.c
@@ -231,9 +231,7 @@ in6_ioctl(u_long cmd, caddr_t data, struct ifnet *ifp, int 
privileged)
switch (cmd) {
case SIOCGIFINFO_IN6:
case SIOCGNBRINFO_IN6:
-   KERNEL_LOCK();
error = nd6_ioctl(cmd, data, ifp);
-   KERNEL_UNLOCK();
return (error);
case SIOCGIFDSTADDR_IN6:
case SIOCGIFNETMASK_IN6:
diff --git a/sys/netinet6/nd6.c b/sys/netinet6/nd6.c
index d88969be617..716946ab831 100644
--- a/sys/netinet6/nd6.c
+++ b/sys/netinet6/nd6.c
@@ -1018,9 +1018,11 @@ nd6_ioctl(u_long cmd, caddr_t data, struct ifnet *ifp)
 
switch (cmd) {
case SIOCGIFINFO_IN6:
+   KERNEL_LOCK();
NET_LOCK_SHARED();
ndi->ndi = *ND_IFINFO(ifp);
NET_UNLOCK_SHARED();
+   KERNEL_UNLOCK();
return (0);
case SIOCGNBRINFO_IN6:
{
@@ -1028,6 +1030,7 @@ nd6_ioctl(u_long cmd, caddr_t data, struct ifnet *ifp)
struct in6_addr nb_addr = nbi->addr; /* make local for safety */
time_t expire;
 
+   KERNEL_LOCK();
NET_LOCK_SHARED();
/*
 * XXX: KAME specific hack for scoped addresses
@@ -1046,6 +1049,7 @@ nd6_ioctl(u_long cmd, caddr_t data, struct ifnet *ifp)
(ln = (struct llinfo_nd6 *)rt->rt_llinfo) == NULL) {
rtfree(rt);
NET_UNLOCK_SHARED();
+   KERNEL_UNLOCK();
return (EINVAL);
}
expire = ln->ln_rt->rt_expire;
@@ -1061,6 +1065,7 @@ nd6_ioctl(u_long cmd, caddr_t data, struct ifnet *ifp)
 
rtfree(rt);
NET_UNLOCK_SHARED();
+   KERNEL_UNLOCK();
return (0);
}
}
-- 
2.38.1



netstart: wait for autoconf on RUNNING interfaces only

2022-11-11 Thread Klemens Nanni
Only /etc/hostname.athn0 contains autoconf on my X230.

When the hardware switch turned off, netstart still waits 10 seconds:

$ ifconfig athn0
athn0: 
flags=a48803 
mtu 1500
lladdr 04:f0:21:30:37:de
index 2 priority 4 llprio 3
groups: wlan
media: IEEE802.11 autoselect
status: no network
ieee80211: nwid ""

# time sh /etc/netstart
0m11.48s real 0m00.93s user 0m00.55s system

For DHCP/SLAAC to kick in, the interface must be UP and RUNNING, so this
won't exit ealier unless I turn the switch on *and* athn0 gets an IP and
default route within those ten seconds, which is quite unlikely, imho.

Make netstart wait for RUNNING interfaces only so booting in guaranteed
offline mode won't stall for nothing:

# time sh ./netstart
0m00.73s real 0m00.57s user 0m00.20s system

Feedback? Objection? OK?


Index: netstart
===
RCS file: /cvs/src/etc/netstart,v
retrieving revision 1.229
diff -u -p -r1.229 netstart
--- netstart5 Nov 2022 12:06:05 -   1.229
+++ netstart11 Nov 2022 16:44:44 -
@@ -292,7 +292,7 @@ ip6routes() {
 wait_autoconf_default() {
local _count=0
 
-   if ifconfig | grep -q ': flags=.*<.*AUTOCONF.*>'; then
+   if ifconfig | grep -q ': flags=.*<.*RUNNING.*AUTOCONF.*>'; then
while ((_count++ < 20)); do
route -n show | grep -q ^default && break
sleep .5



tmux: Sort the rest of the options

2022-11-11 Thread Josiah Frentsos
Also adds a few missing Op's.

Index: cmd-bind-key.c
===
RCS file: /cvs/src/usr.bin/tmux/cmd-bind-key.c,v
retrieving revision 1.46
diff -u -p -r1.46 cmd-bind-key.c
--- cmd-bind-key.c  27 Aug 2021 17:25:55 -  1.46
+++ cmd-bind-key.c  11 Nov 2022 17:31:28 -
@@ -36,9 +36,8 @@ const struct cmd_entry cmd_bind_key_entr
.name = "bind-key",
.alias = "bind",
 
-   .args = { "nrN:T:", 1, -1, cmd_bind_key_args_parse },
-   .usage = "[-nr] [-T key-table] [-N note] key "
-"[command [arguments]]",
+   .args = { "N:nrT:", 1, -1, cmd_bind_key_args_parse },
+   .usage = "[-nr] [-N note] [-T key-table] key [command [arguments]]",
 
.flags = CMD_AFTERHOOK,
.exec = cmd_bind_key_exec
Index: cmd-break-pane.c
===
RCS file: /cvs/src/usr.bin/tmux/cmd-break-pane.c,v
retrieving revision 1.60
diff -u -p -r1.60 cmd-break-pane.c
--- cmd-break-pane.c21 Aug 2021 10:22:38 -  1.60
+++ cmd-break-pane.c11 Nov 2022 17:31:28 -
@@ -34,7 +34,7 @@ const struct cmd_entry cmd_break_pane_en
.name = "break-pane",
.alias = "breakp",
 
-   .args = { "abdPF:n:s:t:", 0, 0, NULL },
+   .args = { "abdF:n:Ps:t:", 0, 0, NULL },
.usage = "[-abdP] [-F format] [-n window-name] [-s src-pane] "
 "[-t dst-window]",
 
Index: cmd-capture-pane.c
===
RCS file: /cvs/src/usr.bin/tmux/cmd-capture-pane.c,v
retrieving revision 1.59
diff -u -p -r1.59 cmd-capture-pane.c
--- cmd-capture-pane.c  28 Sep 2022 07:55:29 -  1.59
+++ cmd-capture-pane.c  11 Nov 2022 17:31:28 -
@@ -39,8 +39,8 @@ const struct cmd_entry cmd_capture_pane_
.name = "capture-pane",
.alias = "capturep",
 
-   .args = { "ab:CeE:JNpPqS:t:", 0, 0, NULL },
-   .usage = "[-aCeJNpPqT] " CMD_BUFFER_USAGE " [-E end-line] "
+   .args = { "ab:CE:eJNPpqS:t:", 0, 0, NULL },
+   .usage = "[-aCeJNPpqT] " CMD_BUFFER_USAGE " [-E end-line] "
 "[-S start-line] " CMD_TARGET_PANE_USAGE,
 
.target = { 't', CMD_FIND_PANE, 0 },
Index: cmd-command-prompt.c
===
RCS file: /cvs/src/usr.bin/tmux/cmd-command-prompt.c,v
retrieving revision 1.65
diff -u -p -r1.65 cmd-command-prompt.c
--- cmd-command-prompt.c30 May 2022 12:55:25 -  1.65
+++ cmd-command-prompt.c11 Nov 2022 17:31:28 -
@@ -42,9 +42,9 @@ const struct cmd_entry cmd_command_promp
.name = "command-prompt",
.alias = NULL,
 
-   .args = { "1bFkiI:Np:t:T:", 0, 1, cmd_command_prompt_args_parse },
-   .usage = "[-1bFkiN] [-I inputs] [-p prompts] " CMD_TARGET_CLIENT_USAGE
-" [-T type] [template]",
+   .args = { "1bFI:ikNp:T:t:", 0, 1, cmd_command_prompt_args_parse },
+   .usage = "[-1bFikN] [-I inputs] [-p prompts] [-T type] "
+CMD_TARGET_CLIENT_USAGE " [template]",
 
.flags = CMD_CLIENT_TFLAG,
.exec = cmd_command_prompt_exec
Index: cmd-copy-mode.c
===
RCS file: /cvs/src/usr.bin/tmux/cmd-copy-mode.c,v
retrieving revision 1.47
diff -u -p -r1.47 cmd-copy-mode.c
--- cmd-copy-mode.c 21 Aug 2021 10:22:38 -  1.47
+++ cmd-copy-mode.c 11 Nov 2022 17:31:28 -
@@ -30,8 +30,8 @@ const struct cmd_entry cmd_copy_mode_ent
.name = "copy-mode",
.alias = NULL,
 
-   .args = { "eHMs:t:uq", 0, 0, NULL },
-   .usage = "[-eHMuq] [-s src-pane] " CMD_TARGET_PANE_USAGE,
+   .args = { "eHMqs:t:u", 0, 0, NULL },
+   .usage = "[-eHMqu] [-s src-pane] " CMD_TARGET_PANE_USAGE,
 
.source =  { 's', CMD_FIND_PANE, 0 },
.target = { 't', CMD_FIND_PANE, 0 },
Index: cmd-detach-client.c
===
RCS file: /cvs/src/usr.bin/tmux/cmd-detach-client.c,v
retrieving revision 1.36
diff -u -p -r1.36 cmd-detach-client.c
--- cmd-detach-client.c 21 Aug 2021 10:22:38 -  1.36
+++ cmd-detach-client.c 11 Nov 2022 17:31:28 -
@@ -33,9 +33,9 @@ const struct cmd_entry cmd_detach_client
.name = "detach-client",
.alias = "detach",
 
-   .args = { "aE:s:t:P", 0, 0, NULL },
-   .usage = "[-aP] [-E shell-command] "
-"[-s target-session] " CMD_TARGET_CLIENT_USAGE,
+   .args = { "aE:Ps:t:", 0, 0, NULL },
+   .usage = "[-aP] [-E shell-command] [-s target-session] "
+CMD_TARGET_CLIENT_USAGE,
 
.source = { 's', CMD_FIND_SESSION, CMD_FIND_CANFAIL },
 
Index: cmd-display-menu.c
===
RCS file: /cvs/src/usr.bin/tmux/cmd-display-menu.c,v
retrieving revision 1.37
diff -u -p -r1.37 cmd-display-menu.c
--- cmd-display-menu.c  25 Oct 2021 09:38:36 -  

Re: libX11 patch for X*IfEvent() API issues, take #2

2022-11-11 Thread Walter Alejandro Iglesias
On Nov 11 2022, Matthieu Herrb wrote:
> On Fri, Nov 11, 2022 at 03:17:21PM +0100, Walter Alejandro Iglesias wrote:
> > On Nov 11 2022, Matthieu Herrb wrote:
> > > Hi,
> > > 
> > > So the patch provided by Adam Jackson upstreams is completely buggy.
> > > 
> > > - the logic to setup the new locking function was busted
> > > - I've observed  cases where even the XGetIfEvent() function gets
> > >   re-rentered. So the flags does in fact need to be a counter.
> > > 
> > > New patch which works for me with fvwm2...
> > > 
> > > Testing is welcome...
> > 
> > Unfortunately I still can reproduce the bug.
> > 
> > This patch also makes firefox crash, (I'm not sure if it's because of
> > firefox or cwm).  After reinstalling xenocara from the snapshots
> > packages I could run firefox again.  
> > 
> > fvwm is giving a lot of problems lately, there's also this drm bug I
> > reported: 
> > 
> >   https://marc.info/?l=openbsd-bugs&m=166332904632232&w=2
> > 
> > Now FvwmIcons is crashing on fvwm3...  I'm giving up with fvwm, I'm more
> > comfortable with cwm.
> 
> Ok, I've figured out the cwm + firefox issue. There's also a
> XInternalLock that needs to be neutered in the X*IfEvent() callbacks.
> 
> New diff, on which I've left my debug printfs. If you get other
> crashes it may be interesting to look in .xsession-errors...

This patch solved the firefox cwm issue.  Firefox shows this when
it starts: 

  ~$ firefox
  XXX _XLockDisplay 1
  XXX _XIfEventInternalLockDisplay 1
  XXX _XIfEventUnlockDisplay 0

fvwm2/3 still crashing.



> 
> Index: Makefile.bsd-wrapper
> ===
> RCS file: /cvs/OpenBSD/xenocara/lib/libX11/Makefile.bsd-wrapper,v
> retrieving revision 1.29
> diff -u -p -u -r1.29 Makefile.bsd-wrapper
> --- Makefile.bsd-wrapper  3 Sep 2022 06:55:25 -   1.29
> +++ Makefile.bsd-wrapper  11 Nov 2022 15:13:59 -
> @@ -14,7 +14,6 @@ SHARED_LIBS=X11 18.0 X11_xcb 2.0
>  
>  CONFIGURE_ARGS= --enable-tcp-transport --enable-unix-transport --enable-ipv6 
> \
>   --disable-composecache \
> - --disable-thread-safety-constructor \
>   --without-xmlto --without-fop --without-xsltproc
>  
>  .include 
> Index: include/X11/Xlibint.h
> ===
> RCS file: /cvs/OpenBSD/xenocara/lib/libX11/include/X11/Xlibint.h,v
> retrieving revision 1.15
> diff -u -p -u -r1.15 Xlibint.h
> --- include/X11/Xlibint.h 21 Feb 2022 08:01:24 -  1.15
> +++ include/X11/Xlibint.h 11 Nov 2022 15:14:00 -
> @@ -207,6 +207,7 @@ struct _XDisplay
>  
>   XIOErrorExitHandler exit_handler;
>   void *exit_handler_data;
> +CARD32 in_ifevent;
>  };
>  
>  #define XAllocIDs(dpy,ids,n) (*(dpy)->idlist_alloc)(dpy,ids,n)
> Index: src/ChkIfEv.c
> ===
> RCS file: /cvs/OpenBSD/xenocara/lib/libX11/src/ChkIfEv.c,v
> retrieving revision 1.4
> diff -u -p -u -r1.4 ChkIfEv.c
> --- src/ChkIfEv.c 30 May 2011 19:19:38 -  1.4
> +++ src/ChkIfEv.c 11 Nov 2022 15:14:00 -
> @@ -49,6 +49,7 @@ Bool XCheckIfEvent (
>   unsigned long qe_serial = 0;
>   int n;  /* time through count */
>  
> +dpy->in_ifevent++;
>  LockDisplay(dpy);
>   prev = NULL;
>   for (n = 3; --n >= 0;) {
> @@ -60,6 +61,7 @@ Bool XCheckIfEvent (
>   *event = qelt->event;
>   _XDeq(dpy, prev, qelt);
>   _XStoreEventCookie(dpy, event);
> +dpy->in_ifevent = False;
>   UnlockDisplay(dpy);
>   return True;
>   }
> @@ -78,6 +80,7 @@ Bool XCheckIfEvent (
>   /* another thread has snatched this event */
>   prev = NULL;
>   }
> +dpy->in_ifevent--;
>   UnlockDisplay(dpy);
>   return False;
>  }
> Index: src/IfEvent.c
> ===
> RCS file: /cvs/OpenBSD/xenocara/lib/libX11/src/IfEvent.c,v
> retrieving revision 1.4
> diff -u -p -u -r1.4 IfEvent.c
> --- src/IfEvent.c 30 May 2011 19:19:38 -  1.4
> +++ src/IfEvent.c 11 Nov 2022 15:14:00 -
> @@ -48,6 +48,7 @@ XIfEvent (
>   register _XQEvent *qelt, *prev;
>   unsigned long qe_serial = 0;
>  
> +dpy->in_ifevent++;
>  LockDisplay(dpy);
>   prev = NULL;
>   while (1) {
> @@ -59,6 +60,7 @@ XIfEvent (
>   *event = qelt->event;
>   _XDeq(dpy, prev, qelt);
>   _XStoreEventCookie(dpy, event);
> +dpy->in_ifevent--;
>   UnlockDisplay(dpy);
>   return 0;
>   }
> Index: src/OpenDis.c
> ===
> RCS file: /cvs/OpenBSD/xenocara/lib/libX11/src/OpenDis.c,v
> retrieving revision 1.12
> diff -u -p -u -r1.12 OpenDis.c
> --- src/OpenDis.c 28 Nov 20

move vmd vioblk handling to another thread

2022-11-11 Thread David Gwynne
this updates a diff i had from a few years ago to move the vioblk
handling in vmd into a separate thread.

basically disk io in your virtual machine should not block the vcpu from
running now.

just throwing this out so people can give it a go and kick it around.

Index: Makefile
===
RCS file: /cvs/src/usr.sbin/vmd/Makefile,v
retrieving revision 1.28
diff -u -p -r1.28 Makefile
--- Makefile10 Nov 2022 11:46:39 -  1.28
+++ Makefile11 Nov 2022 15:51:50 -
@@ -5,7 +5,7 @@
 PROG=  vmd
 SRCS=  vmd.c control.c log.c priv.c proc.c config.c vmm.c
 SRCS+= vm.c loadfile_elf.c pci.c virtio.c i8259.c mc146818.c
-SRCS+= ns8250.c i8253.c dhcp.c packet.c mmio.c
+SRCS+= ns8250.c i8253.c dhcp.c packet.c mmio.c task.c
 SRCS+= parse.y atomicio.c vioscsi.c vioraw.c vioqcow2.c fw_cfg.c
 SRCS+= vm_agentx.c
 
Index: task.c
===
RCS file: task.c
diff -N task.c
--- /dev/null   1 Jan 1970 00:00:00 -
+++ task.c  11 Nov 2022 15:51:50 -
@@ -0,0 +1,158 @@
+/* $OpenBSD: task.c,v 1.2 2018/06/19 17:12:34 reyk Exp $ */
+
+/*
+ * Copyright (c) 2017 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.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "task.h"
+
+#define ISSET(_v, _m)  ((_v) & (_m))
+#define SET(_v, _m)((_v) |= (_m))
+#define CLR(_v, _m)((_v) &= ~(_m))
+
+struct taskq {
+   pthread_t thread;
+   struct task_list  list;
+   pthread_mutex_t   mtx;
+   pthread_cond_tcv;
+};
+
+#define TASK_ONQUEUE   (1 << 0)
+
+static void *taskq_run(void *);
+
+struct taskq *
+taskq_create(const char *name)
+{
+   struct taskq *tq;
+   int error;
+
+   tq = malloc(sizeof(*tq));
+   if (tq == NULL)
+   return (NULL);
+
+   TAILQ_INIT(&tq->list);
+
+   error = pthread_mutex_init(&tq->mtx, NULL);
+   if (error != 0)
+   goto free;
+
+   error = pthread_cond_init(&tq->cv, NULL);
+   if (error != 0)
+   goto mtx;
+
+   error = pthread_create(&tq->thread, NULL, taskq_run, tq);
+   if (error != 0)
+   goto cv;
+
+   pthread_set_name_np(tq->thread, name);
+
+   return (tq);
+
+cv:
+   pthread_cond_destroy(&tq->cv);
+mtx:
+   pthread_mutex_destroy(&tq->mtx); /* can this really fail? */
+free:
+   free(tq);
+
+   errno = error;
+   return (NULL);
+}
+
+static void *
+taskq_run(void *tqarg)
+{
+   struct taskq *tq = tqarg;
+   struct task *t;
+
+   void (*t_func)(void *);
+   void *t_arg;
+
+   for (;;) {
+   pthread_mutex_lock(&tq->mtx);
+   while ((t = TAILQ_FIRST(&tq->list)) == NULL)
+   pthread_cond_wait(&tq->cv, &tq->mtx);
+
+   TAILQ_REMOVE(&tq->list, t, t_entry);
+   CLR(t->t_flags, TASK_ONQUEUE);
+
+   t_func = t->t_func;
+   t_arg = t->t_arg;
+
+   pthread_mutex_unlock(&tq->mtx);
+
+   (*t_func)(t_arg);
+   }
+
+   return (NULL);
+}
+
+void
+task_set(struct task *t, void (*fn)(void *), void *arg)
+{
+   t->t_func = fn;
+   t->t_arg = arg;
+   t->t_flags = 0;
+}
+
+int
+task_add(struct taskq *tq, struct task *t)
+{
+   int rv = 1;
+
+   if (ISSET(t->t_flags, TASK_ONQUEUE))
+   return (0);
+
+   pthread_mutex_lock(&tq->mtx);
+   if (ISSET(t->t_flags, TASK_ONQUEUE))
+   rv = 0;
+   else {
+   SET(t->t_flags, TASK_ONQUEUE);
+   TAILQ_INSERT_TAIL(&tq->list, t, t_entry);
+   pthread_cond_signal(&tq->cv);
+   }
+   pthread_mutex_unlock(&tq->mtx);
+
+   return (rv);
+}
+
+int
+task_del(struct taskq *tq, struct task *t)
+{
+   int rv = 1;
+
+   if (!ISSET(t->t_flags, TASK_ONQUEUE))
+   return (0);
+
+   pthread_mutex_lock(&tq->mtx);
+   if (!ISSET(t->t_flags, TASK_ONQUEUE))
+   rv = 0;
+   else {
+   TAILQ_REMOVE(&tq->list, t, t_entry);
+   CLR(t->t_flags, TASK_ONQUEUE);
+   }
+   pthread_mutex_unlo

Re: libX11 patch for X*IfEvent() API issues, take #2

2022-11-11 Thread Matthieu Herrb
On Fri, Nov 11, 2022 at 03:17:21PM +0100, Walter Alejandro Iglesias wrote:
> On Nov 11 2022, Matthieu Herrb wrote:
> > Hi,
> > 
> > So the patch provided by Adam Jackson upstreams is completely buggy.
> > 
> > - the logic to setup the new locking function was busted
> > - I've observed  cases where even the XGetIfEvent() function gets
> >   re-rentered. So the flags does in fact need to be a counter.
> > 
> > New patch which works for me with fvwm2...
> > 
> > Testing is welcome...
> 
> Unfortunately I still can reproduce the bug.
> 
> This patch also makes firefox crash, (I'm not sure if it's because of
> firefox or cwm).  After reinstalling xenocara from the snapshots
> packages I could run firefox again.  
> 
> fvwm is giving a lot of problems lately, there's also this drm bug I
> reported: 
> 
>   https://marc.info/?l=openbsd-bugs&m=166332904632232&w=2
> 
> Now FvwmIcons is crashing on fvwm3...  I'm giving up with fvwm, I'm more
> comfortable with cwm.

Ok, I've figured out the cwm + firefox issue. There's also a
XInternalLock that needs to be neutered in the X*IfEvent() callbacks.

New diff, on which I've left my debug printfs. If you get other
crashes it may be interesting to look in .xsession-errors...

Index: Makefile.bsd-wrapper
===
RCS file: /cvs/OpenBSD/xenocara/lib/libX11/Makefile.bsd-wrapper,v
retrieving revision 1.29
diff -u -p -u -r1.29 Makefile.bsd-wrapper
--- Makefile.bsd-wrapper3 Sep 2022 06:55:25 -   1.29
+++ Makefile.bsd-wrapper11 Nov 2022 15:13:59 -
@@ -14,7 +14,6 @@ SHARED_LIBS=  X11 18.0 X11_xcb 2.0
 
 CONFIGURE_ARGS= --enable-tcp-transport --enable-unix-transport --enable-ipv6 \
--disable-composecache \
-   --disable-thread-safety-constructor \
--without-xmlto --without-fop --without-xsltproc
 
 .include 
Index: include/X11/Xlibint.h
===
RCS file: /cvs/OpenBSD/xenocara/lib/libX11/include/X11/Xlibint.h,v
retrieving revision 1.15
diff -u -p -u -r1.15 Xlibint.h
--- include/X11/Xlibint.h   21 Feb 2022 08:01:24 -  1.15
+++ include/X11/Xlibint.h   11 Nov 2022 15:14:00 -
@@ -207,6 +207,7 @@ struct _XDisplay
 
XIOErrorExitHandler exit_handler;
void *exit_handler_data;
+CARD32 in_ifevent;
 };
 
 #define XAllocIDs(dpy,ids,n) (*(dpy)->idlist_alloc)(dpy,ids,n)
Index: src/ChkIfEv.c
===
RCS file: /cvs/OpenBSD/xenocara/lib/libX11/src/ChkIfEv.c,v
retrieving revision 1.4
diff -u -p -u -r1.4 ChkIfEv.c
--- src/ChkIfEv.c   30 May 2011 19:19:38 -  1.4
+++ src/ChkIfEv.c   11 Nov 2022 15:14:00 -
@@ -49,6 +49,7 @@ Bool XCheckIfEvent (
unsigned long qe_serial = 0;
int n;  /* time through count */
 
+dpy->in_ifevent++;
 LockDisplay(dpy);
prev = NULL;
for (n = 3; --n >= 0;) {
@@ -60,6 +61,7 @@ Bool XCheckIfEvent (
*event = qelt->event;
_XDeq(dpy, prev, qelt);
_XStoreEventCookie(dpy, event);
+dpy->in_ifevent = False;
UnlockDisplay(dpy);
return True;
}
@@ -78,6 +80,7 @@ Bool XCheckIfEvent (
/* another thread has snatched this event */
prev = NULL;
}
+dpy->in_ifevent--;
UnlockDisplay(dpy);
return False;
 }
Index: src/IfEvent.c
===
RCS file: /cvs/OpenBSD/xenocara/lib/libX11/src/IfEvent.c,v
retrieving revision 1.4
diff -u -p -u -r1.4 IfEvent.c
--- src/IfEvent.c   30 May 2011 19:19:38 -  1.4
+++ src/IfEvent.c   11 Nov 2022 15:14:00 -
@@ -48,6 +48,7 @@ XIfEvent (
register _XQEvent *qelt, *prev;
unsigned long qe_serial = 0;
 
+dpy->in_ifevent++;
 LockDisplay(dpy);
prev = NULL;
while (1) {
@@ -59,6 +60,7 @@ XIfEvent (
*event = qelt->event;
_XDeq(dpy, prev, qelt);
_XStoreEventCookie(dpy, event);
+dpy->in_ifevent--;
UnlockDisplay(dpy);
return 0;
}
Index: src/OpenDis.c
===
RCS file: /cvs/OpenBSD/xenocara/lib/libX11/src/OpenDis.c,v
retrieving revision 1.12
diff -u -p -u -r1.12 OpenDis.c
--- src/OpenDis.c   28 Nov 2020 14:39:48 -  1.12
+++ src/OpenDis.c   11 Nov 2022 15:14:00 -
@@ -189,6 +189,7 @@ XOpenDisplay (
dpy->xcmisc_opcode  = 0;
dpy->xkb_info   = NULL;
dpy->exit_handler_data  = NULL;
+dpy->in_ifevent = 0;
 
 /*
  * Setup other information in this display structure.
Index: src/PeekIfEv.c
===
RCS file

btrace: string comparison in filters

2022-11-11 Thread Martin Pieuchot
Diff below adds support for the common following idiom:

syscall:open:entry
/comm == "ksh"/
{
...
}

String comparison is tricky as it can be combined with any other
expression in filters, like:

syscall:mmap:entry
/comm == "cc" && pid != 4589/
{
...
}

I don't have the energy to change the parser so I went for the easy
solution to treat any "stupid" string comparisons as 'true' albeit
printing a warning.  I'd love if somebody with some yacc knowledge
could come up with a better solution.

ok?

Index: usr.sbin/btrace/bt_parse.y
===
RCS file: /cvs/src/usr.sbin/btrace/bt_parse.y,v
retrieving revision 1.46
diff -u -p -r1.46 bt_parse.y
--- usr.sbin/btrace/bt_parse.y  28 Apr 2022 21:04:24 -  1.46
+++ usr.sbin/btrace/bt_parse.y  11 Nov 2022 14:34:37 -
@@ -218,6 +218,7 @@ variable: lvar  { $$ = bl_find($1); }
 factor : '(' expr ')'  { $$ = $2; }
| NUMBER{ $$ = ba_new($1, B_AT_LONG); }
| BUILTIN   { $$ = ba_new(NULL, $1); }
+   | CSTRING   { $$ = ba_new($1, B_AT_STR); }
| staticv
| variable
| mentry
Index: usr.sbin/btrace/btrace.c
===
RCS file: /cvs/src/usr.sbin/btrace/btrace.c,v
retrieving revision 1.64
diff -u -p -r1.64 btrace.c
--- usr.sbin/btrace/btrace.c11 Nov 2022 10:51:39 -  1.64
+++ usr.sbin/btrace/btrace.c11 Nov 2022 14:44:15 -
@@ -434,14 +434,23 @@ rules_setup(int fd)
struct bt_rule *r, *rbegin = NULL;
struct bt_probe *bp;
struct bt_stmt *bs;
+   struct bt_arg *ba;
int dokstack = 0, on = 1;
uint64_t evtflags;
 
TAILQ_FOREACH(r, &g_rules, br_next) {
evtflags = 0;
-   SLIST_FOREACH(bs, &r->br_action, bs_next) {
-   struct bt_arg *ba;
 
+   if (r->br_filter != NULL &&
+   r->br_filter->bf_condition != NULL)  {
+
+   bs = r->br_filter->bf_condition;
+   ba = SLIST_FIRST(&bs->bs_args);
+
+   evtflags |= ba2dtflags(ba);
+   }
+
+   SLIST_FOREACH(bs, &r->br_action, bs_next) {
SLIST_FOREACH(ba, &bs->bs_args, ba_next)
evtflags |= ba2dtflags(ba);
 
@@ -1175,6 +1184,36 @@ baexpr2long(struct bt_arg *ba, struct dt
lhs = ba->ba_value;
rhs = SLIST_NEXT(lhs, ba_next);
 
+   /*
+* String comparison also use '==' and '!='.
+*/
+   if (lhs->ba_type == B_AT_STR ||
+   (rhs != NULL && rhs->ba_type == B_AT_STR)) {
+   char lstr[STRLEN], rstr[STRLEN];
+
+   strlcpy(lstr, ba2str(lhs, dtev), sizeof(lstr));
+   strlcpy(rstr, ba2str(rhs, dtev), sizeof(rstr));
+
+   result = strncmp(lstr, rstr, STRLEN) == 0;
+
+   switch (ba->ba_type) {
+   case B_AT_OP_EQ:
+   break;
+   case B_AT_OP_NE:
+   result = !result;
+   break;
+   default:
+   warnx("operation '%d' unsupported on strings",
+   ba->ba_type);
+   result = 1;
+   }
+
+   debug("ba=%p eval '(%s %s %s) = %d'\n", ba, lstr, ba_name(ba),
+  rstr, result);
+
+   goto out;
+   }
+
lval = ba2long(lhs, dtev);
if (rhs == NULL) {
rval = 0;
@@ -1233,9 +1272,10 @@ baexpr2long(struct bt_arg *ba, struct dt
xabort("unsupported operation %d", ba->ba_type);
}
 
-   debug("ba=%p eval '%ld %s %ld = %d'\n", ba, lval, ba_name(ba),
+   debug("ba=%p eval '(%ld %s %ld) = %d'\n", ba, lval, ba_name(ba),
   rval, result);
 
+out:
--recursions;
 
return result;
@@ -1245,10 +1285,15 @@ const char *
 ba_name(struct bt_arg *ba)
 {
switch (ba->ba_type) {
+   case B_AT_STR:
+   return (const char *)ba->ba_value;
+   case B_AT_LONG:
+   return ba2str(ba, NULL);
case B_AT_NIL:
return "0";
case B_AT_VAR:
case B_AT_MAP:
+   case B_AT_HIST:
break;
case B_AT_BI_PID:
return "pid";
@@ -1326,7 +1371,8 @@ ba_name(struct bt_arg *ba)
xabort("unsupported type %d", ba->ba_type);
}
 
-   assert(ba->ba_type == B_AT_VAR || ba->ba_type == B_AT_MAP);
+   assert(ba->ba_type == B_AT_VAR || ba->ba_type == B_AT_MAP ||
+   ba->ba_type == B_AT_HIST);
 
static char buf[64];
size_t sz;
@@ -1516,9 +1562,13 @@ ba2str(struct bt_arg *ba, struct dt_evt 
 int
 ba2dtflags(struct bt_arg *ba)
 {
+   static long recursions;
struct bt_arg *bval;
int flags = 0;
 
+   if (++recursions >= __MAXOPER

Re: libX11 patch for X*IfEvent() API issues, take #2

2022-11-11 Thread Matthieu Herrb
On Fri, Nov 11, 2022 at 03:17:21PM +0100, Walter Alejandro Iglesias wrote:
> On Nov 11 2022, Matthieu Herrb wrote:
> > Hi,
> > 
> > So the patch provided by Adam Jackson upstreams is completely buggy.
> > 
> > - the logic to setup the new locking function was busted
> > - I've observed  cases where even the XGetIfEvent() function gets
> >   re-rentered. So the flags does in fact need to be a counter.
> > 
> > New patch which works for me with fvwm2...
> > 
> > Testing is welcome...
> 
> Unfortunately I still can reproduce the bug.
> 
> This patch also makes firefox crash, (I'm not sure if it's because of
> firefox or cwm).  After reinstalling xenocara from the snapshots
> packages I could run firefox again.  
>

I'll try harder to reproduce then.  It was firefox under cwm ?

> fvwm is giving a lot of problems lately, there's also this drm bug I
> reported: 
> 
>   https://marc.info/?l=openbsd-bugs&m=166332904632232&w=2
> 
> Now FvwmIcons is crashing on fvwm3...  I'm giving up with fvwm, I'm more
> comfortable with cwm.

I can't really help with this one, sorry. drm is too complex.
-- 
Matthieu Herrb



Re: libX11 patch for X*IfEvent() API issues, take #2

2022-11-11 Thread Walter Alejandro Iglesias
On Nov 11 2022, Matthieu Herrb wrote:
> Hi,
> 
> So the patch provided by Adam Jackson upstreams is completely buggy.
> 
> - the logic to setup the new locking function was busted
> - I've observed  cases where even the XGetIfEvent() function gets
>   re-rentered. So the flags does in fact need to be a counter.
> 
> New patch which works for me with fvwm2...
> 
> Testing is welcome...

Unfortunately I still can reproduce the bug.

This patch also makes firefox crash, (I'm not sure if it's because of
firefox or cwm).  After reinstalling xenocara from the snapshots
packages I could run firefox again.  

fvwm is giving a lot of problems lately, there's also this drm bug I
reported: 

  https://marc.info/?l=openbsd-bugs&m=166332904632232&w=2

Now FvwmIcons is crashing on fvwm3...  I'm giving up with fvwm, I'm more
comfortable with cwm.


> 
> Index: Makefile.bsd-wrapper
> ===
> RCS file: /cvs/OpenBSD/xenocara/lib/libX11/Makefile.bsd-wrapper,v
> retrieving revision 1.29
> diff -u -p -u -r1.29 Makefile.bsd-wrapper
> --- Makefile.bsd-wrapper  3 Sep 2022 06:55:25 -   1.29
> +++ Makefile.bsd-wrapper  11 Nov 2022 12:10:16 -
> @@ -14,7 +14,6 @@ SHARED_LIBS=X11 18.0 X11_xcb 2.0
>  
>  CONFIGURE_ARGS= --enable-tcp-transport --enable-unix-transport --enable-ipv6 
> \
>   --disable-composecache \
> - --disable-thread-safety-constructor \
>   --without-xmlto --without-fop --without-xsltproc
>  
>  .include 
> Index: include/X11/Xlibint.h
> ===
> RCS file: /cvs/OpenBSD/xenocara/lib/libX11/include/X11/Xlibint.h,v
> retrieving revision 1.15
> diff -u -p -u -r1.15 Xlibint.h
> --- include/X11/Xlibint.h 21 Feb 2022 08:01:24 -  1.15
> +++ include/X11/Xlibint.h 11 Nov 2022 12:10:17 -
> @@ -207,6 +207,7 @@ struct _XDisplay
>  
>   XIOErrorExitHandler exit_handler;
>   void *exit_handler_data;
> +CARD32 in_ifevent;
>  };
>  
>  #define XAllocIDs(dpy,ids,n) (*(dpy)->idlist_alloc)(dpy,ids,n)
> Index: src/ChkIfEv.c
> ===
> RCS file: /cvs/OpenBSD/xenocara/lib/libX11/src/ChkIfEv.c,v
> retrieving revision 1.4
> diff -u -p -u -r1.4 ChkIfEv.c
> --- src/ChkIfEv.c 30 May 2011 19:19:38 -  1.4
> +++ src/ChkIfEv.c 11 Nov 2022 12:10:17 -
> @@ -49,6 +49,7 @@ Bool XCheckIfEvent (
>   unsigned long qe_serial = 0;
>   int n;  /* time through count */
>  
> +dpy->in_ifevent++;
>  LockDisplay(dpy);
>   prev = NULL;
>   for (n = 3; --n >= 0;) {
> @@ -60,6 +61,7 @@ Bool XCheckIfEvent (
>   *event = qelt->event;
>   _XDeq(dpy, prev, qelt);
>   _XStoreEventCookie(dpy, event);
> +dpy->in_ifevent = False;
>   UnlockDisplay(dpy);
>   return True;
>   }
> @@ -78,6 +80,7 @@ Bool XCheckIfEvent (
>   /* another thread has snatched this event */
>   prev = NULL;
>   }
> +dpy->in_ifevent--;
>   UnlockDisplay(dpy);
>   return False;
>  }
> Index: src/IfEvent.c
> ===
> RCS file: /cvs/OpenBSD/xenocara/lib/libX11/src/IfEvent.c,v
> retrieving revision 1.4
> diff -u -p -u -r1.4 IfEvent.c
> --- src/IfEvent.c 30 May 2011 19:19:38 -  1.4
> +++ src/IfEvent.c 11 Nov 2022 12:10:17 -
> @@ -48,6 +48,7 @@ XIfEvent (
>   register _XQEvent *qelt, *prev;
>   unsigned long qe_serial = 0;
>  
> +dpy->in_ifevent++;
>  LockDisplay(dpy);
>   prev = NULL;
>   while (1) {
> @@ -59,6 +60,7 @@ XIfEvent (
>   *event = qelt->event;
>   _XDeq(dpy, prev, qelt);
>   _XStoreEventCookie(dpy, event);
> +dpy->in_ifevent--;
>   UnlockDisplay(dpy);
>   return 0;
>   }
> Index: src/OpenDis.c
> ===
> RCS file: /cvs/OpenBSD/xenocara/lib/libX11/src/OpenDis.c,v
> retrieving revision 1.12
> diff -u -p -u -r1.12 OpenDis.c
> --- src/OpenDis.c 28 Nov 2020 14:39:48 -  1.12
> +++ src/OpenDis.c 11 Nov 2022 12:10:17 -
> @@ -189,6 +189,7 @@ XOpenDisplay (
>   dpy->xcmisc_opcode  = 0;
>   dpy->xkb_info   = NULL;
>   dpy->exit_handler_data  = NULL;
> +dpy->in_ifevent = 0;
>  
>  /*
>   * Setup other information in this display structure.
> Index: src/PeekIfEv.c
> ===
> RCS file: /cvs/OpenBSD/xenocara/lib/libX11/src/PeekIfEv.c,v
> retrieving revision 1.3
> diff -u -p -u -r1.3 PeekIfEv.c
> --- src/PeekIfEv.c30 May 2011 19:19:38 -  1.3
> +++ src/PeekIfEv.c11 Nov 2022 12:10:17 -
> @@ -49,6 +49,7 @@ XPeekIfEvent

MAP_CONCEAL bypass due to stack overflow

2022-11-11 Thread Moritz Buhl
Dear tech,

currently the MAP_CONCEAL flag for mmap(2) can be bypassed with a
stack overflow. FreeBSD introduced a similar flag called MAP_NOCORE.
They also save the auxinfo pointer in some struct that is attached
to the proc struct, similar to the diff below.

Here is an example CTF challenge:

/*
 * Setup:
 * make mmap
 * echo 'this is a well kept secret' > flag.txt
 * printf 'flag.txt\0' | ./mmap
 * strings mmap.core | grep secret
 */

#include 

#include 
#include 
#include 
#include 

char *
load_file(char *path)
{
char *addr;
int fd;

fd = open(path, O_RDONLY);
if ((addr = mmap((char *)0x4, 0x100, PROT_READ, MAP_FIXED
| MAP_CONCEAL, fd, 0)) == MAP_FAILED)
err(1, NULL);
close(fd);

return (addr);
}

int
main(void)
{
char file[0x100];
char *buf;

puts("Content-type: text/html\n");
puts("simple mmapPOST filename to /cgi-bin/mmap");
read(0, file, 0x1000);
buf = load_file(file);
printf("load: %p\n", buf);
fflush(stdout);

return (0);
}


With the following python program (on amd64) I can generate an input
string that writes the MAP_CONCEALED content of flag.txt to the
core file:

import struct
p64 = lambda x: struct.pack("p_p;
@@ -1282,23 +1279,7 @@ coredump_notes_elf(struct proc *p, void 
/* Second, write an NT_OPENBSD_AUXV note. */
notesize = sizeof(nhdr) + elfround(sizeof("OpenBSD")) +
elfround(ELF_AUX_WORDS * sizeof(char *));
-   if (iocookie) {
-   iov.iov_base = &pss;
-   iov.iov_len = sizeof(pss);
-   uio.uio_iov = &iov;
-   uio.uio_iovcnt = 1;
-   uio.uio_offset = (off_t)pr->ps_strings;
-   uio.uio_resid = sizeof(pss);
-   uio.uio_segflg = UIO_SYSSPACE;
-   uio.uio_rw = UIO_READ;
-   uio.uio_procp = NULL;
-
-   error = uvm_io(&p->p_vmspace->vm_map, &uio, 0);
-   if (error)
-   return (error);
-
-   if (pss.ps_envstr == NULL)
-   return (EIO);
+   if (iocookie && pr->ps_auxinfo) {
 
nhdr.namesz = sizeof("OpenBSD");
nhdr.descsz = ELF_AUX_WORDS * sizeof(char *);
@@ -1315,7 +1296,7 @@ coredump_notes_elf(struct proc *p, void 
return (error);
 
error = coredump_write(iocookie, UIO_USERSPACE,
-   pss.ps_envstr + pss.ps_nenvstr + 1, nhdr.descsz);
+   (caddr_t)pr->ps_auxinfo, nhdr.descsz);
if (error)
return (error);
}
Index: kern/kern_exec.c
===
RCS file: /mount/openbsd/cvs/src/sys/kern/kern_exec.c,v
retrieving revision 1.238
diff -u -p -r1.238 kern_exec.c
--- kern/kern_exec.c30 Oct 2022 17:43:40 -  1.238
+++ kern/kern_exec.c6 Nov 2022 10:37:19 -
@@ -492,6 +492,8 @@ sys_execve(struct proc *p, void *v, regi
if (!copyargs(&pack, &arginfo, stack, argp))
goto exec_abort;
 
+   pr->ps_auxinfo = (vaddr_t)pack.ep_auxinfo;
+
/* copy out the process's ps_strings structure */
if (copyout(&arginfo, (char *)pr->ps_strings, sizeof(arginfo)))
goto exec_abort;
Index: sys/proc.h
===
RCS file: /mount/openbsd/cvs/src/sys/sys/proc.h,v
retrieving revision 1.334
diff -u -p -r1.334 proc.h
--- sys/proc.h  23 Jul 2022 22:10:59 -  1.334
+++ sys/proc.h  6 Nov 2022 10:37:19 -
@@ -215,6 +215,7 @@ struct process {
charps_comm[_MAXCOMLEN];/* command name, incl NUL */
 
vaddr_t ps_strings; /* User pointers to argv/env */
+   vaddr_t ps_auxinfo; /* User pointer to auxinfo */
vaddr_t ps_timekeep;/* User pointer to timekeep */
vaddr_t ps_sigcode; /* [I] User pointer to signal code */
vaddr_t ps_sigcoderet;  /* [I] User ptr to sigreturn retPC */



Re: arm64 pwmbl(4): simplify ramp case

2022-11-11 Thread Patrick Wildt
On Fri, Nov 11, 2022 at 06:48:21AM +, Miod Vallat wrote:
> > This actually breaks my machine.  malloc() is saying allocation too
> > large.  OF_getproplen will return -1 on that.  Is it possible that
> > len is treated as uint64_t as it is an int and sizeof is effectively
> > uint64_t?
> 
> Ah, yes; size_t is unsigned and wider than int on 64-bit platforms,
> therefore int is converted to unsigned for the comparison. Casting
> sizeof to int will do.
> 
> > Might be easier to have a check like:
> > 
> > if (sc->sc_channels == NULL)
> > return level < sc->sc_nlevels ? level : sc->sc_nlevels - 1;
> > 
> > Then you don't need to indent the whole block.  Makes the diff smaller
> > and a bit easier to understand?
> 
> Sure; what about this new version, then?

Works for me, thanks!  ok patrick@

> 
> Index: pwmbl.c
> ===
> RCS file: /OpenBSD/src/sys/dev/fdt/pwmbl.c,v
> retrieving revision 1.6
> diff -u -p -r1.6 pwmbl.c
> --- pwmbl.c   24 Oct 2021 17:52:26 -  1.6
> +++ pwmbl.c   11 Nov 2022 06:46:41 -
> @@ -35,7 +35,7 @@ struct pwmbl_softc {
>   struct device   sc_dev;
>   uint32_t*sc_pwm;
>   int sc_pwm_len;
> - uint32_t*sc_levels;
> + uint32_t*sc_levels; /* NULL if simple ramp */
>   int sc_nlevels;
>   uint32_tsc_max_level;
>   uint32_tsc_def_level;
> @@ -73,7 +73,7 @@ pwmbl_attach(struct device *parent, stru
>   struct pwmbl_softc *sc = (struct pwmbl_softc *)self;
>   struct fdt_attach_args *faa = aux;
>   uint32_t *gpios;
> - int i, len;
> + int len;
>  
>   len = OF_getproplen(faa->fa_node, "pwms");
>   if (len < 0) {
> @@ -95,7 +95,7 @@ pwmbl_attach(struct device *parent, stru
>   }
>  
>   len = OF_getproplen(faa->fa_node, "brightness-levels");
> - if (len > 0) {
> + if (len >= (int)sizeof(uint32_t)) {
>   sc->sc_levels = malloc(len, M_DEVBUF, M_WAITOK);
>   OF_getpropintarray(faa->fa_node, "brightness-levels",
>   sc->sc_levels, len);
> @@ -107,13 +107,9 @@ pwmbl_attach(struct device *parent, stru
>   sc->sc_def_level = sc->sc_nlevels - 1;
>   sc->sc_def_level = sc->sc_levels[sc->sc_def_level];
>   } else {
> + /* No levels, assume a simple 0..255 ramp. */
>   sc->sc_nlevels = 256;
> - sc->sc_levels = mallocarray(sc->sc_nlevels,
> - sizeof(uint32_t), M_DEVBUF, M_WAITOK);
> - for (i = 0; i < sc->sc_nlevels; i++)
> - sc->sc_levels[i] = i;
> - sc->sc_max_level = sc->sc_levels[sc->sc_nlevels - 1];
> - sc->sc_def_level = sc->sc_levels[sc->sc_nlevels - 1];
> + sc->sc_max_level = sc->sc_def_level = sc->sc_nlevels - 1;
>   }
>  
>   printf("\n");
> @@ -143,6 +139,9 @@ pwmbl_find_brightness(struct pwmbl_softc
>  {
>   uint32_t mid;
>   int i;
> +
> + if (sc->sc_levels == NULL)
> + return level < sc->sc_nlevels ? level : sc->sc_nlevels - 1;
>  
>   for (i = 0; i < sc->sc_nlevels - 1; i++) {
>   mid = (sc->sc_levels[i] + sc->sc_levels[i + 1]) / 2;
> 



libX11 patch for X*IfEvent() API issues, take #2

2022-11-11 Thread Matthieu Herrb
Hi,

So the patch provided by Adam Jackson upstreams is completely buggy.

- the logic to setup the new locking function was busted
- I've observed  cases where even the XGetIfEvent() function gets
  re-rentered. So the flags does in fact need to be a counter.

New patch which works for me with fvwm2...

Testing is welcome...

Index: Makefile.bsd-wrapper
===
RCS file: /cvs/OpenBSD/xenocara/lib/libX11/Makefile.bsd-wrapper,v
retrieving revision 1.29
diff -u -p -u -r1.29 Makefile.bsd-wrapper
--- Makefile.bsd-wrapper3 Sep 2022 06:55:25 -   1.29
+++ Makefile.bsd-wrapper11 Nov 2022 12:10:16 -
@@ -14,7 +14,6 @@ SHARED_LIBS=  X11 18.0 X11_xcb 2.0
 
 CONFIGURE_ARGS= --enable-tcp-transport --enable-unix-transport --enable-ipv6 \
--disable-composecache \
-   --disable-thread-safety-constructor \
--without-xmlto --without-fop --without-xsltproc
 
 .include 
Index: include/X11/Xlibint.h
===
RCS file: /cvs/OpenBSD/xenocara/lib/libX11/include/X11/Xlibint.h,v
retrieving revision 1.15
diff -u -p -u -r1.15 Xlibint.h
--- include/X11/Xlibint.h   21 Feb 2022 08:01:24 -  1.15
+++ include/X11/Xlibint.h   11 Nov 2022 12:10:17 -
@@ -207,6 +207,7 @@ struct _XDisplay
 
XIOErrorExitHandler exit_handler;
void *exit_handler_data;
+CARD32 in_ifevent;
 };
 
 #define XAllocIDs(dpy,ids,n) (*(dpy)->idlist_alloc)(dpy,ids,n)
Index: src/ChkIfEv.c
===
RCS file: /cvs/OpenBSD/xenocara/lib/libX11/src/ChkIfEv.c,v
retrieving revision 1.4
diff -u -p -u -r1.4 ChkIfEv.c
--- src/ChkIfEv.c   30 May 2011 19:19:38 -  1.4
+++ src/ChkIfEv.c   11 Nov 2022 12:10:17 -
@@ -49,6 +49,7 @@ Bool XCheckIfEvent (
unsigned long qe_serial = 0;
int n;  /* time through count */
 
+dpy->in_ifevent++;
 LockDisplay(dpy);
prev = NULL;
for (n = 3; --n >= 0;) {
@@ -60,6 +61,7 @@ Bool XCheckIfEvent (
*event = qelt->event;
_XDeq(dpy, prev, qelt);
_XStoreEventCookie(dpy, event);
+dpy->in_ifevent = False;
UnlockDisplay(dpy);
return True;
}
@@ -78,6 +80,7 @@ Bool XCheckIfEvent (
/* another thread has snatched this event */
prev = NULL;
}
+dpy->in_ifevent--;
UnlockDisplay(dpy);
return False;
 }
Index: src/IfEvent.c
===
RCS file: /cvs/OpenBSD/xenocara/lib/libX11/src/IfEvent.c,v
retrieving revision 1.4
diff -u -p -u -r1.4 IfEvent.c
--- src/IfEvent.c   30 May 2011 19:19:38 -  1.4
+++ src/IfEvent.c   11 Nov 2022 12:10:17 -
@@ -48,6 +48,7 @@ XIfEvent (
register _XQEvent *qelt, *prev;
unsigned long qe_serial = 0;
 
+dpy->in_ifevent++;
 LockDisplay(dpy);
prev = NULL;
while (1) {
@@ -59,6 +60,7 @@ XIfEvent (
*event = qelt->event;
_XDeq(dpy, prev, qelt);
_XStoreEventCookie(dpy, event);
+dpy->in_ifevent--;
UnlockDisplay(dpy);
return 0;
}
Index: src/OpenDis.c
===
RCS file: /cvs/OpenBSD/xenocara/lib/libX11/src/OpenDis.c,v
retrieving revision 1.12
diff -u -p -u -r1.12 OpenDis.c
--- src/OpenDis.c   28 Nov 2020 14:39:48 -  1.12
+++ src/OpenDis.c   11 Nov 2022 12:10:17 -
@@ -189,6 +189,7 @@ XOpenDisplay (
dpy->xcmisc_opcode  = 0;
dpy->xkb_info   = NULL;
dpy->exit_handler_data  = NULL;
+dpy->in_ifevent = 0;
 
 /*
  * Setup other information in this display structure.
Index: src/PeekIfEv.c
===
RCS file: /cvs/OpenBSD/xenocara/lib/libX11/src/PeekIfEv.c,v
retrieving revision 1.3
diff -u -p -u -r1.3 PeekIfEv.c
--- src/PeekIfEv.c  30 May 2011 19:19:38 -  1.3
+++ src/PeekIfEv.c  11 Nov 2022 12:10:17 -
@@ -49,6 +49,7 @@ XPeekIfEvent (
register _XQEvent *prev, *qelt;
unsigned long qe_serial = 0;
 
+dpy->in_ifevent++;
LockDisplay(dpy);
prev = NULL;
while (1) {
@@ -63,6 +64,7 @@ XPeekIfEvent (
_XStoreEventCookie(dpy, ©);
*event = copy;
}
+dpy->in_ifevent--;
UnlockDisplay(dpy);
return 0;
}
Index: src/locking.c
===
RCS file: /cvs/OpenBSD/xenocara/lib/libX11/src/locking.c,v
retrieving revision 1.8
diff -u -p -u -r1.8 locking.c

Re: m88k, luna88k: switch to clockintr(9)

2022-11-11 Thread Kenji Aoyama
Hello,

On Mon, 07 Nov 2022 04:47:14 +0900,
Scott Cheloha wrote:
> 
> This patch switches luna88k to clockintr(9).
> 
> We have no control over the interrupt clock on luna88k so the patch
> is pretty simple.
> 
> aoyama@ has built a release and upgraded from the resulting bsd.rd on
> his LUNA-88K2.
> 
> A test on a different machine might help.  Not sure how many there
> are.

This diff might the same as previous one that you sent, but it seems
to work fine with -current tree on my LUNA-88K2 and LUNA-88K capable
emulator 'nono'.

ok aoyama@, if you need.

-- aoyama



Re: relax KASSET() to if () in pfsync_grab_snapshot()

2022-11-11 Thread David Gwynne
ok

> On 11 Nov 2022, at 7:31 pm, Alexandr Nedvedicky  wrote:
> 
> Hello,
> 
> Diff below changes KASSERT() to if (). We have to prevent
> packets to insert state to snapshot queue multiple times.
> Hrvoje@ can trigger situation where state updates to pfsync
> peer are more frequent than we are able to send out.
> 
> OK to go for this simple fix/workaround ?
> 
> thanks and
> regards
> sashan
> 
> 8<---8<---8<--8<
> diff --git a/sys/net/if_pfsync.c b/sys/net/if_pfsync.c
> index d279ede9cd6..fdff3d7a509 100644
> --- a/sys/net/if_pfsync.c
> +++ b/sys/net/if_pfsync.c
> @@ -1362,10 +1362,17 @@ pfsync_grab_snapshot(struct pfsync_snapshot *sn, 
> struct pfsync_softc *sc)
> TAILQ_INIT(&sn->sn_qs[q]);
> 
> while ((st = TAILQ_FIRST(&sc->sc_qs[q])) != NULL) {
> - KASSERT(st->snapped == 0);
> TAILQ_REMOVE(&sc->sc_qs[q], st, sync_list);
> - TAILQ_INSERT_TAIL(&sn->sn_qs[q], st, sync_snap);
> - st->snapped = 1;
> + if (st->snapped == 0) {
> + TAILQ_INSERT_TAIL(&sn->sn_qs[q], st, sync_snap);
> + st->snapped = 1;
> + } else {
> + /*
> + * item is on snapshot list already, just give
> + * up this attempt to update it.
> + */
> + pf_state_unref(st);
> + }
> }
> }
> 
> 



relax KASSET() to if () in pfsync_grab_snapshot()

2022-11-11 Thread Alexandr Nedvedicky
Hello,

Diff below changes KASSERT() to if (). We have to prevent
packets to insert state to snapshot queue multiple times.
Hrvoje@ can trigger situation where state updates to pfsync
peer are more frequent than we are able to send out.

OK to go for this simple fix/workaround ?

thanks and
regards
sashan

8<---8<---8<--8<
diff --git a/sys/net/if_pfsync.c b/sys/net/if_pfsync.c
index d279ede9cd6..fdff3d7a509 100644
--- a/sys/net/if_pfsync.c
+++ b/sys/net/if_pfsync.c
@@ -1362,10 +1362,17 @@ pfsync_grab_snapshot(struct pfsync_snapshot *sn, struct 
pfsync_softc *sc)
TAILQ_INIT(&sn->sn_qs[q]);
 
while ((st = TAILQ_FIRST(&sc->sc_qs[q])) != NULL) {
-   KASSERT(st->snapped == 0);
TAILQ_REMOVE(&sc->sc_qs[q], st, sync_list);
-   TAILQ_INSERT_TAIL(&sn->sn_qs[q], st, sync_snap);
-   st->snapped = 1;
+   if (st->snapped == 0) {
+   TAILQ_INSERT_TAIL(&sn->sn_qs[q], st, sync_snap);
+   st->snapped = 1;
+   } else {
+   /*
+* item is on snapshot list already, just give
+* up this attempt to update it.
+*/
+   pf_state_unref(st);
+   }
}
}