Re: ukbd(4): support apple brightness keys

2020-10-27 Thread Tobias Heider
> What about KS_Cmd_BrightnessUp and KS_Cmd_BrightnessDown?

Right, here's a new diff using those wskbd commands.
I couldn't find any standardized UHID key codes for brightness keys
so I chose 232 and 233 which are currently unused and in the RESERVED range.

I also included the regenerated ukbdmap.c in the diff below for convenience.

Feedback, ok?

Index: hid/hidkbd.c
===
RCS file: /cvs/src/sys/dev/hid/hidkbd.c,v
retrieving revision 1.5
diff -u -p -r1.5 hidkbd.c
--- hid/hidkbd.c30 May 2017 07:40:24 -  1.5
+++ hid/hidkbd.c27 Oct 2020 22:37:05 -
@@ -397,7 +407,7 @@ hidkbd_decode(struct hidkbd *kbd, struct
wskbd_rawinput(kbd->sc_wskbddev, cbuf, j);
 
/*
-* Pass audio keys to wskbd_input anyway.
+* Pass audio and brightness keys to wskbd_input anyway.
 */
for (i = 0; i < nkeys; i++) {
key = ibuf[i];
@@ -405,6 +415,8 @@ hidkbd_decode(struct hidkbd *kbd, struct
case 127:
case 128:
case 129:
+   case 232:
+   case 233:
wskbd_input(kbd->sc_wskbddev,
key & RELEASE ?  WSCONS_EVENT_KEY_UP :
  WSCONS_EVENT_KEY_DOWN, key & CODEMASK);
Index: usb/makemap.awk
===
RCS file: /cvs/src/sys/dev/usb/makemap.awk,v
retrieving revision 1.14
diff -u -p -r1.14 makemap.awk
--- usb/makemap.awk 20 Nov 2013 17:27:32 -  1.14
+++ usb/makemap.awk 27 Oct 2020 22:37:05 -
@@ -341,6 +341,8 @@ $1 == "#define" || $1 == "#undef" {
lines[124] = "KC(124),\tKS_Copy,"
lines[125] = "KC(125),\tKS_Paste,"
lines[126] = "KC(126),\tKS_Find,"
+   lines[232] = "KC(232),\tKS_Cmd_BrightnessUp,"
+   lines[233] = "KC(233),\tKS_Cmd_BrightnessDown,"
}
 
for (i = 0; i < 256; i++)
Index: usb/ukbd.c
===
RCS file: /cvs/src/sys/dev/usb/ukbd.c,v
retrieving revision 1.79
diff -u -p -r1.79 ukbd.c
--- usb/ukbd.c  23 Aug 2020 11:08:02 -  1.79
+++ usb/ukbd.c  27 Oct 2020 22:37:05 -
@@ -559,6 +559,8 @@ ukbd_apple_munge(void *vsc, uint8_t *ibu
{ 66, 0 },  /* F9 -> audio next */
 #endif
 #ifdef __macppc__
+   { 58, 233 },/* F1 -> screen brightness down */
+   { 59, 232 },/* F2 -> screen brightness up */
{ 60, 127 },/* F3 -> audio mute */
{ 61, 129 },/* F4 -> audio lower */
{ 62, 128 },/* F5 -> audio raise */
Index: usb/ukbdmap.c
===
RCS file: /cvs/src/sys/dev/usb/ukbdmap.c,v
retrieving revision 1.44
diff -u -p -r1.44 ukbdmap.c
--- usb/ukbdmap.c   11 May 2019 14:20:17 -  1.44
+++ usb/ukbdmap.c   27 Oct 2020 22:37:05 -
@@ -1,4 +1,4 @@
-/* $OpenBSD: ukbdmap.c,v 1.44 2019/05/11 14:20:17 abieber Exp $*/
+/* $OpenBSD$   */
 
 /*
  * THIS FILE IS AUTOMAGICALLY GENERATED.  DO NOT EDIT.
@@ -185,6 +185,8 @@ static const keysym_t ukbd_keydesc_us[] 
 KC(229),   KS_Shift_R,
 KC(230),   KS_Cmd2,KS_Alt_R,   KS_Multi_key,
 KC(231),   KS_Meta_R,
+KC(232),   KS_Cmd_BrightnessUp,
+KC(233),   KS_Cmd_BrightnessDown,
 };
 
 #if !defined(WSKBD_NO_INTL_LAYOUTS)
Index: wscons/wskbd.c
===
RCS file: /cvs/src/sys/dev/wscons/wskbd.c,v
retrieving revision 1.106
diff -u -p -r1.106 wskbd.c
--- wscons/wskbd.c  29 Jul 2020 05:53:52 -  1.106
+++ wscons/wskbd.c  27 Oct 2020 22:37:06 -
@@ -1492,6 +1492,20 @@ internal_command(struct wskbd_softc *sc,
 #endif
 #endif
 
+#if NWSDISPLAY > 0
+   switch(ksym) {
+   case KS_Cmd_BrightnessUp:
+   wsdisplay_brightness_step(sc->sc_displaydv, 1);
+   return (1);
+   case KS_Cmd_BrightnessDown:
+   wsdisplay_brightness_step(sc->sc_displaydv, -1);
+   return (1);
+   case KS_Cmd_BrightnessRotate:
+   wsdisplay_brightness_cycle(sc->sc_displaydv);
+   return (1);
+   }
+#endif
+
if (!MOD_ONESET(sc->id, MOD_COMMAND) &&
!MOD_ALLSET(sc->id, MOD_COMMAND1 | MOD_COMMAND2))
return (0);
@@ -1555,15 +1569,6 @@ internal_command(struct wskbd_softc *sc,
change_displayparam(sc, WSDISPLAYIO_PARAM_BACKLIGHT,
ksym == KS_Cmd_BacklightOff ? -1 : 1,
ksym == KS_Cmd_BacklightToggle ? 1 : 0);
-   return (1);
-   case KS_Cmd_BrightnessUp:
- 

setitimer(2): protect per-process ITIMER_REAL state with ps_mtx

2020-10-27 Thread Scott Cheloha
Hi,

The last step before unlocking setitimer(2) and getitimer(2) is
protecting the per-process ITIMER_REAL state with something other
than the kernel lock.

Because the ITIMER_REAL timeout runs at IPL_SOFTCLOCK I think the
per-process mutex ps_mtx is appropriate.

Changing the setitimer() routine itself is trivial.  We just
enter/leave ps_mtx instead of the global itimer_mtx if the timer
in question is ITIMER_REAL.

The realitexpire() routine is trickier.  When setitimer(2) is unlocked
there will be a small race between the point where we leave
timeout_mutex in timeout_run() and where we enter ps_mtx in
realitexpire().  Between these two points a different thread in
setitimer(2) running without the kernel lock will be able to enter
ps_mtx and cancel or reschedule the timeout.  So the moment we enter
ps_mtx during realitexpire() we first need to check if the timer was
cancelled or rescheduled to run in the future.  In either case we
don't want to send SIGALRM to the process, we just want to leave the
mutex and return.

Sending the SIGALRM before/after we decide whether to reschedule the
timeout is inconsequential, so I've moved the prsignal() call to the
end of realitexpire().  I've added a KERNEL_ASSERT_LOCKED() there,
too, as prsignal() still needs the kernel lock.  This is trivial for
now, as all timeouts run with the kernel lock.

I have updated the locking notes in sys/proc.h to reflect these
changes.

ok?

Index: kern/kern_time.c
===
RCS file: /cvs/src/sys/kern/kern_time.c,v
retrieving revision 1.149
diff -u -p -r1.149 kern_time.c
--- kern/kern_time.c25 Oct 2020 01:55:18 -  1.149
+++ kern/kern_time.c27 Oct 2020 15:23:16 -
@@ -535,10 +535,11 @@ setitimer(int which, const struct itimer
TIMEVAL_TO_TIMESPEC(>it_interval, _interval);
}
 
-   if (which != ITIMER_REAL)
-   mtx_enter(_mtx);
-   else
+   if (which == ITIMER_REAL) {
+   mtx_enter(>ps_mtx);
nanouptime();
+   } else
+   mtx_enter(_mtx);
 
if (olditv != NULL)
oldits = *itimer;
@@ -553,7 +554,9 @@ setitimer(int which, const struct itimer
*itimer = its;
}
 
-   if (which != ITIMER_REAL)
+   if (which == ITIMER_REAL)
+   mtx_leave(>ps_mtx);
+   else
mtx_leave(_mtx);
 
if (olditv != NULL) {
@@ -660,21 +663,43 @@ realitexpire(void *arg)
struct timespec cts;
struct process *pr = arg;
struct itimerspec *tp = >ps_timer[ITIMER_REAL];
+   int need_signal = 0;
+
+   mtx_enter(>ps_mtx);
 
-   prsignal(pr, SIGALRM);
+   /*
+* Do nothing if the timer was cancelled or rescheduled while we
+* were entering the mutex.
+*/
+   if (!timespecisset(>it_value) || timeout_pending(>ps_realit_to))
+   goto out;
 
-   /* If it was a one-shot timer we're done. */
+   /* The timer expired.  We need to send the signal. */
+   need_signal = 1;
+
+   /* One-shot timers are not reloaded. */
if (!timespecisset(>it_interval)) {
timespecclear(>it_value);
-   return;
+   goto out;
}
 
-   /* Find the nearest future expiration point and restart the timeout. */
+   /*
+* Find the nearest future expiration point and restart the
+* timer before sending the signal.
+*/
nanouptime();
while (timespeccmp(>it_value, , <=))
timespecadd(>it_value, >it_interval, >it_value);
if ((pr->ps_flags & PS_EXITING) == 0)
timeout_at_ts(>ps_realit_to, >it_value);
+
+out:
+   mtx_leave(>ps_mtx);
+
+   if (need_signal) {
+   KERNEL_ASSERT_LOCKED();
+   prsignal(pr, SIGALRM);
+   }
 }
 
 /*
Index: sys/proc.h
===
RCS file: /cvs/src/sys/sys/proc.h,v
retrieving revision 1.300
diff -u -p -r1.300 proc.h
--- sys/proc.h  16 Sep 2020 08:01:15 -  1.300
+++ sys/proc.h  27 Oct 2020 15:23:16 -
@@ -219,7 +219,7 @@ struct process {
struct  rusage *ps_ru;  /* sum of stats for dead threads. */
struct  tusage ps_tu;   /* accumulated times. */
struct  rusage ps_cru;  /* sum of stats for reaped children */
-   struct  itimerspec ps_timer[3]; /* [K] ITIMER_REAL timer */
+   struct  itimerspec ps_timer[3]; /* [m] ITIMER_REAL timer */
/* [T] ITIMER_{VIRTUAL,PROF} timers */
struct  timeout ps_rucheck_to;  /* [] resource limit check timer */
time_t  ps_nextxcpu;/* when to send next SIGXCPU, */
@@ -273,7 +273,7 @@ struct process {
int ps_refcnt;  /* Number of references. */
 
struct  timespec ps_start;  /* starting uptime. */
-   struct  timeout ps_realit_to; 

Re: snapshot boot fails with error "entry point at 0x1001000"

2020-10-27 Thread Sven Wolf

Hi Mark,

on my Lenovo V130 the patch works. Now I'm able to boot the current 
kernel again, without the need to remove the radeon and amdgpu driver 
(https://marc.info/?l=openbsd-misc=159276382718317=2)


Thanks and best regards,
Sven

On 10/27/20 1:40 PM, Mark Kettenis wrote:

Hi Kastus,

Please don't have technical discussions on misc@; some developers,
like me, only read it sporadically.  The tech@ list is a much better
place.

The problem with your approach is that you allocate memory at a fixed
address, and we can't be sure that memory is available.  We may have
to extend the amount of memory we allocate such that larger kernels
fit.  The diff below bumps it from 32MB to 64MB.  Does this work for
you?


Index: arch/amd64/stand/efiboot/efiboot.c
===
RCS file: /cvs/src/sys/arch/amd64/stand/efiboot/efiboot.c,v
retrieving revision 1.35
diff -u -p -r1.35 efiboot.c
--- arch/amd64/stand/efiboot/efiboot.c  22 Mar 2020 14:59:11 -  1.35
+++ arch/amd64/stand/efiboot/efiboot.c  27 Oct 2020 12:36:45 -
@@ -39,7 +39,7 @@
  #include "eficall.h"
  #include "run_i386.h"
  
-#define	KERN_LOADSPACE_SIZE	(32 * 1024 * 1024)

+#defineKERN_LOADSPACE_SIZE (64 * 1024 * 1024)
  
  EFI_SYSTEM_TABLE	*ST;

  EFI_BOOT_SERVICES *BS;





[PATCH] tcpdump: special case dumping of layer 3 packets

2020-10-27 Thread Jason A. Donenfeld
Different link types get different printers. But until now, different
link types would get the same pcap dumper. This is mostly fine, except
for on LOOP-type interfaces, which have raw layer 3 packets. On these,
the first four bytes of the packet represent the AF family, which the
pcap data format doesn't care for. So, trying to open the result in
Wireshark is gibberish. This patch makes packet dumping act like packet
printing, which certain link types special cased. In this case,
LOOP-type packets get the first four bytes shaved off.
---
 usr.sbin/tcpdump/interface.h  |  1 +
 usr.sbin/tcpdump/print-null.c |  9 +
 usr.sbin/tcpdump/tcpdump.c| 19 ++-
 3 files changed, 28 insertions(+), 1 deletion(-)

diff --git usr.sbin/tcpdump/interface.h usr.sbin/tcpdump/interface.h
index 602be405723..147036f7d1e 100644
--- usr.sbin/tcpdump/interface.h
+++ usr.sbin/tcpdump/interface.h
@@ -249,6 +249,7 @@ extern void nfsreply_print(const u_char *, u_int, const 
u_char *);
 extern void nfsreq_print(const u_char *, u_int, const u_char *);
 extern void ns_print(const u_char *, u_int, int);
 extern void ntp_print(const u_char *, u_int);
+extern void loop_if_dump(u_char *, const struct pcap_pkthdr *, const u_char *);
 extern void loop_if_print(u_char *, const struct pcap_pkthdr *, const u_char 
*);
 extern void null_if_print(u_char *, const struct pcap_pkthdr *, const u_char 
*);
 extern void ospf_print(const u_char *, u_int, const u_char *);
diff --git usr.sbin/tcpdump/print-null.c usr.sbin/tcpdump/print-null.c
index f90f5e9030c..94457532c90 100644
--- usr.sbin/tcpdump/print-null.c
+++ usr.sbin/tcpdump/print-null.c
@@ -96,6 +96,15 @@ null_print(const u_char *p, const struct ip *ip, u_int 
length)
}
 }
 
+void
+loop_if_dump(u_char *user, const struct pcap_pkthdr *h, const u_char *p)
+{
+   struct pcap_pkthdr h_mod = *h;
+   h_mod.caplen -= sizeof(u_int);
+   h_mod.len -= sizeof(u_int);
+   pcap_dump(user, _mod, p + sizeof(u_int));
+}
+
 void
 loop_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p)
 {
diff --git usr.sbin/tcpdump/tcpdump.c usr.sbin/tcpdump/tcpdump.c
index bbdba4d4c48..40323870ed9 100644
--- usr.sbin/tcpdump/tcpdump.c
+++ usr.sbin/tcpdump/tcpdump.c
@@ -110,6 +110,23 @@ struct printer {
 #define DLT_ATM_RFC1483 11
 #endif
 
+static struct printer dumpers[] = {
+   { loop_if_dump, DLT_LOOP },
+   { NULL, 0 },
+};
+
+static pcap_handler
+lookup_dumper(int type)
+{
+   struct printer *p;
+
+   for (p = dumpers; p->f; ++p) {
+   if (type == p->type)
+   return p->f;
+   }
+   return pcap_dump;
+}
+
 static struct printer printers[] = {
{ ether_if_print,   DLT_EN10MB },
{ ether_if_print,   DLT_IEEE802 },
@@ -507,7 +524,7 @@ main(int argc, char **argv)
fflush(fp);
setvbuf(fp, NULL, _IONBF, 0);
}
-   printer = pcap_dump;
+   printer = lookup_dumper(pcap_datalink(pd));
pcap_userdata = (u_char *)p;
} else {
printer = lookup_printer(pcap_datalink(pd));
-- 
2.29.1



Re: [PATCH] ifconfig: keep track of allowed ips pointer correctly

2020-10-27 Thread Philip Guenther
On Tue, Oct 27, 2020 at 9:18 AM Jason A. Donenfeld  wrote:
...

> @@ -5721,16 +5720,18 @@ growwgdata(size_t by)
> if (wg_aip != NULL)
> wg_aip = (void *)wg_interface + aip_offset;
>
> -   ret = (void *)wg_interface + wgdata.wgd_size - by;
> -   bzero(ret, by);
> -
> -   return ret;
> +   bzero((void *)wg_interface + wgdata.wgd_size - by, by);
>  }
>

Total side note, but this caught my eye as relying on the gcc extension to
do pointer arithmetic on "void *" pointers.  At least historically we've
avoided relying on that, which is easy in this case by just casting to
"char *" instead.

Philip Guenther


Re: libagentx add agentx_varbind_unsigned32

2020-10-27 Thread Theo Buehler
On Tue, Oct 27, 2020 at 07:09:40PM +0100, Martijn van Duren wrote:
> To prevent any future confusion around unsigned ints I'd like to add
> agentx_varbind_unsigned32 as an alias to agentx_varbind_gauge32.
> 
> According to RFC 2578 section 2:
> -- an unsigned 32-bit quantity
> -- indistinguishable from Gauge32
> 
> OK?

ok (for this including manpage)

> Still OK to ride yesterdays bump?

I think so



[PATCH] ifconfig: keep track of allowed ips pointer correctly

2020-10-27 Thread Jason A. Donenfeld
Somebody on IRC mentioned that using ifconfig to set wgallowedips wasn't
working on macppc. I don't have a macppc to test this on, but it seems
like the code is assuming that the two values printed out by this test
program must always be the same:

  struct s {
  int i;
  };

  struct p {
  long l;
  char c;
  struct s a[];
  };

  int main(int argc, char *argv[])
  {
  printf("%zu %zu\n", sizeof(struct p), (size_t)&((struct p *)0)->a[0]);
  return 0;
  }

But actually, on my amd64 system, that little test prints out "16 12".
This patch fixes up ifconfig.c to do the right thing, so that it
corresponds with how the kernel handles iteration.

I don't have a macppc in order to test this, but it works on amd64.
---
 sbin/ifconfig/ifconfig.c | 19 +++
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git sbin/ifconfig/ifconfig.c sbin/ifconfig/ifconfig.c
index 2ccbac6f4ce..ade6e4943b7 100644
--- sbin/ifconfig/ifconfig.c
+++ sbin/ifconfig/ifconfig.c
@@ -5696,11 +5696,10 @@ ensurewginterface(void)
err(1, "calloc");
 }
 
-void *
+void
 growwgdata(size_t by)
 {
ptrdiff_t peer_offset, aip_offset;
-   void *ret;
 
if (wg_interface == NULL)
wgdata.wgd_size = sizeof(*wg_interface);
@@ -5721,16 +5720,18 @@ growwgdata(size_t by)
if (wg_aip != NULL)
wg_aip = (void *)wg_interface + aip_offset;
 
-   ret = (void *)wg_interface + wgdata.wgd_size - by;
-   bzero(ret, by);
-
-   return ret;
+   bzero((void *)wg_interface + wgdata.wgd_size - by, by);
 }
 
 void
 setwgpeer(const char *peerkey_b64, int param)
 {
-   wg_peer = growwgdata(sizeof(*wg_peer));
+   growwgdata(sizeof(*wg_peer));
+   if (wg_aip)
+   wg_peer = (struct wg_peer_io *)wg_aip;
+   else
+   wg_peer = _interface->i_peers[0];
+   wg_aip = _peer->p_aips[0];
wg_peer->p_flags |= WG_PEER_HAS_PUBLIC;
WG_LOAD_KEY(wg_peer->p_public, peerkey_b64, "wgpeer");
wg_interface->i_peers_count++;
@@ -5743,7 +5744,7 @@ setwgpeeraip(const char *aip, int param)
if (wg_peer == NULL)
errx(1, "wgaip: wgpeer not set");
 
-   wg_aip = growwgdata(sizeof(*wg_aip));
+   growwgdata(sizeof(*wg_aip));
 
if ((res = inet_net_pton(AF_INET, aip, _aip->a_ipv4,
sizeof(wg_aip->a_ipv4))) != -1) {
@@ -5759,6 +5760,8 @@ setwgpeeraip(const char *aip, int param)
 
wg_peer->p_flags |= WG_PEER_REPLACE_AIPS;
wg_peer->p_aips_count++;
+
+   wg_aip++;
 }
 
 void
-- 
2.29.1



Re: libagentx add agentx_varbind_unsigned32

2020-10-27 Thread Martijn van Duren
On Tue, 2020-10-27 at 19:09 +0100, Martijn van Duren wrote:
> To prevent any future confusion around unsigned ints I'd like to add
> agentx_varbind_unsigned32 as an alias to agentx_varbind_gauge32.
> 
> According to RFC 2578 section 2:
> -- an unsigned 32-bit quantity
> -- indistinguishable from Gauge32
> 
> OK?
> Still OK to ride yesterdays bump?
> 
> martijn@
> 
And of course the manpage bits:

Index: agentx.3
===
RCS file: /cvs/src/lib/libagentx/agentx.3,v
retrieving revision 1.3
diff -u -p -r1.3 agentx.3
--- agentx.327 Oct 2020 17:33:05 -  1.3
+++ agentx.327 Oct 2020 18:15:39 -
@@ -62,6 +62,7 @@
 .Nm agentx_varbind_ipaddress ,
 .Nm agentx_varbind_counter32 ,
 .Nm agentx_varbind_gauge32 ,
+.Nm agentx_varbind_unsigned32 ,
 .Nm agentx_varbind_timeticks ,
 .Nm agentx_varbind_opaque ,
 .Nm agentx_varbind_counter64 ,
@@ -222,6 +223,8 @@
 .Ft void
 .Fn agentx_varbind_gauge32 "struct agentx_varbind *sav" "uint32_t value"
 .Ft void
+.Fn agentx_varbind_unsigned32 "struct agentx_varbind *sav" "uint32_t value"
+.Ft void
 .Fo agentx_varbind_timeticks
 .Fa "struct agentx_varbind *sav"  "uint32_t value"
 .Fc
@@ -517,6 +520,8 @@ Set the return value to ipaddress.
 Set the return value to an uint32_t of type counter32.
 .It Fn agentx_varbind_gauge32
 Set the return value to an uint32_t of type gauge32.
+.It Fn agentx_varbind_unsigned32
+A wrapper around agentx_varbind_gauge32.
 .It Fn agentx_varbind_timeticks
 Set the return value to an uint32_t of type timeticks.
 .It Fn agentx_varbind_opaque



libagentx add agentx_varbind_unsigned32

2020-10-27 Thread Martijn van Duren
To prevent any future confusion around unsigned ints I'd like to add
agentx_varbind_unsigned32 as an alias to agentx_varbind_gauge32.

According to RFC 2578 section 2:
-- an unsigned 32-bit quantity
-- indistinguishable from Gauge32

OK?
Still OK to ride yesterdays bump?

martijn@

Index: Symbols.list
===
RCS file: /cvs/src/lib/libagentx/Symbols.list,v
retrieving revision 1.2
diff -u -p -r1.2 Symbols.list
--- Symbols.list26 Oct 2020 15:45:56 -  1.2
+++ Symbols.list27 Oct 2020 18:08:51 -
@@ -42,6 +42,7 @@ agentx_varbind_index
 agentx_varbind_ipaddress
 agentx_varbind_counter32
 agentx_varbind_gauge32
+agentx_varbind_unsigned32
 agentx_varbind_timeticks
 agentx_varbind_opaque
 agentx_varbind_counter64
Index: agentx.c
===
RCS file: /cvs/src/lib/libagentx/agentx.c,v
retrieving revision 1.7
diff -u -p -r1.7 agentx.c
--- agentx.c27 Oct 2020 17:19:44 -  1.7
+++ agentx.c27 Oct 2020 18:08:51 -
@@ -3152,6 +3152,12 @@ agentx_varbind_gauge32(struct agentx_var
 }
 
 void
+agentx_varbind_unsigned32(struct agentx_varbind *axv, uint32_t value)
+{
+   agentx_varbind_gauge32(axv, value);
+}
+
+void
 agentx_varbind_timeticks(struct agentx_varbind *axv, uint32_t value)
 {
axv->axv_vb.avb_type = AX_DATA_TYPE_TIMETICKS;
Index: agentx.h
===
RCS file: /cvs/src/lib/libagentx/agentx.h,v
retrieving revision 1.4
diff -u -p -r1.4 agentx.h
--- agentx.h27 Oct 2020 17:19:44 -  1.4
+++ agentx.h27 Oct 2020 18:08:51 -
@@ -116,6 +116,7 @@ void agentx_varbind_ipaddress(struct age
 const struct in_addr *);
 void agentx_varbind_counter32(struct agentx_varbind *, uint32_t);
 void agentx_varbind_gauge32(struct agentx_varbind *, uint32_t);
+void agentx_varbind_unsigned32(struct agentx_varbind *, uint32_t);
 void agentx_varbind_timeticks(struct agentx_varbind *, uint32_t);
 void agentx_varbind_opaque(struct agentx_varbind *, const char *, size_t);
 void agentx_varbind_counter64(struct agentx_varbind *, uint64_t);



Re: macppc: fix wsconsctl for non-vgafb

2020-10-27 Thread Klemens Nanni
On Mon, Oct 26, 2020 at 06:20:25PM +0100, Tobias Heider wrote:
> The diff below wires the ofw backlight commands to ws_get_param/ws_set_param
> and makes wsconsctl backlight/brightness work on my machine using radeondrm. 
This commit fixed brightness on my PowerBook5,8 but broke
display.contract in that wsconsctl(8) not fails for this knob:

# wsconsctl display.contrast
wsconsctl: WSDISPLAYIO_GETPARAM: Operation not permitted
display.contrast=0.00%
# wsconsctl display.contrast
wsconsctl: WSDISPLAYIO_GETPARAM: Operation not permitted
display.contrast=4294967293.4294967293%



Re: ukbd(4): support apple brightness keys

2020-10-27 Thread Klemens Nanni
On Tue, Oct 27, 2020 at 02:58:55PM +0100, Tobias Heider wrote:
> I think you're missing the previous diff, see
> https://marc.info/?l=openbsd-tech=160373302219962=2
Right, my bad.  -CURRENT with your diff works as expected in all regards.



Re: ukbd(4): support apple brightness keys

2020-10-27 Thread Mark Kettenis
> Date: Tue, 27 Oct 2020 00:16:16 +0100
> From: Tobias Heider 
> 
> Hi,
> 
> the diff below makes the brightness keys work on apple powerbooks > 5,6
> where the keyboard attaches via ukbd(4).
> I'm wondering if it would be better to go through wskbd as is done with
> audio, but we don't have keycodes allocated for brightness up/down.

What about KS_Cmd_BrightnessUp and KS_Cmd_BrightnessDown?

> Thoughts? ok?
> 
> Index: ukbd.c
> ===
> RCS file: /cvs/src/sys/dev/usb/ukbd.c,v
> retrieving revision 1.79
> diff -u -p -r1.79 ukbd.c
> --- ukbd.c23 Aug 2020 11:08:02 -  1.79
> +++ ukbd.c26 Oct 2020 23:10:05 -
> @@ -71,6 +71,7 @@
>  #include 
>  
>  #include 
> +#include 
>  #include 
>  #include 
>  #include 
> @@ -86,6 +87,10 @@ intukbddebug = 0;
>  #define DPRINTFN(n,x)
>  #endif
>  
> +#define UKBD_PARAM   (1 << 15)
> +#define UKBD_BRIGHTNESS_UP   0x1
> +#define UKBD_BRIGHTNESS_DOWN 0x2
> +
>  const kbd_t ukbd_countrylayout[1 + HCC_MAX] = {
>   (kbd_t)-1,
>   (kbd_t)-1,  /* arabic */
> @@ -159,6 +164,7 @@ void  ukbd_db_enter(void *);
>  int  ukbd_enable(void *, int);
>  void ukbd_set_leds(void *, int);
>  int  ukbd_ioctl(void *, u_long, caddr_t, int, struct proc *);
> +void ukbd_set_display_param(int);
>  
>  const struct wskbd_accessops ukbd_accessops = {
>   ukbd_enable,
> @@ -180,7 +186,7 @@ const struct cfattach ukbd_ca = {
>  
>  struct ukbd_translation {
>   uint8_t original;
> - uint8_t translation;
> + uint16_t translation;
>  };
>  
>  #ifdef __loongson__
> @@ -192,7 +198,7 @@ void  ukbd_apple_iso_munge(void *, uint8_
>  void ukbd_apple_iso_mba_munge(void *, uint8_t *, u_int);
>  void ukbd_apple_translate(void *, uint8_t *, u_int,
>   const struct ukbd_translation *, u_int);
> -uint8_t  ukbd_translate(const struct ukbd_translation *, size_t, 
> uint8_t);
> +uint16_t ukbd_translate(const struct ukbd_translation *, size_t, 
> uint8_t);
>  
>  int
>  ukbd_match(struct device *parent, void *match, void *aux)
> @@ -511,7 +517,7 @@ ukbd_cnattach(void)
>   return (0);
>  }
>  
> -uint8_t
> +uint16_t
>  ukbd_translate(const struct ukbd_translation *table, size_t tsize,
>  uint8_t keycode)
>  {
> @@ -527,13 +533,19 @@ ukbd_apple_translate(void *vsc, uint8_t 
>  {
>   struct ukbd_softc *sc = vsc;
>   struct hidkbd *kbd = >sc_kbd;
> - uint8_t *pos, *spos, *epos, xlat;
> + uint8_t *pos, *spos, *epos;
> + uint16_t xlat;
>  
>   spos = ibuf + kbd->sc_keycodeloc.pos / 8;
>   epos = spos + kbd->sc_nkeycode;
>  
>   for (pos = spos; pos != epos; pos++) {
>   xlat = ukbd_translate(trans, tlen, *pos);
> + if (xlat & UKBD_PARAM) {
> + ukbd_set_display_param(xlat & ~UKBD_PARAM);
> + *pos = 0;
> + return;
> + }
>   if (xlat != 0)
>   *pos = xlat;
>   }
> @@ -548,8 +560,6 @@ ukbd_apple_munge(void *vsc, uint8_t *ibu
>   { 40, 73 }, /* return -> insert */
>   { 42, 76 }, /* backspace -> delete */
>  #ifdef notyet
> - { 58, 0 },  /* F1 -> screen brightness down */
> - { 59, 0 },  /* F2 -> screen brightness up */
>   { 60, 0 },  /* F3 */
>   { 61, 0 },  /* F4 */
>   { 62, 0 },  /* F5 -> keyboard backlight down */
> @@ -559,6 +569,8 @@ ukbd_apple_munge(void *vsc, uint8_t *ibu
>   { 66, 0 },  /* F9 -> audio next */
>  #endif
>  #ifdef __macppc__
> + { 58, UKBD_PARAM | UKBD_BRIGHTNESS_DOWN },  /* F1 -> screen 
> brightness down */
> + { 59, UKBD_PARAM | UKBD_BRIGHTNESS_UP  },   /* F2 -> screen 
> brightness up */
>   { 60, 127 },/* F3 -> audio mute */
>   { 61, 129 },/* F4 -> audio lower */
>   { 62, 128 },/* F5 -> audio raise */
> @@ -641,6 +653,21 @@ ukbd_apple_iso_mba_munge(void *vsc, uint
>   ukbd_apple_translate(vsc, ibuf, ilen, apple_iso_trans,
>   nitems(apple_iso_trans));
>   ukbd_apple_mba_munge(vsc, ibuf, ilen);
> +}
> +
> +void
> +ukbd_set_display_param(int num)
> +{
> + switch(num) {
> + case UKBD_BRIGHTNESS_UP:
> + wsdisplay_brightness_step(NULL, 1);
> + break;
> + case UKBD_BRIGHTNESS_DOWN:
> + wsdisplay_brightness_step(NULL, -1);
> + break;
> + default:
> + break;
> + }
>  }
>  
>  #ifdef __loongson__
> 
> 



Re: ukbd(4): support apple brightness keys

2020-10-27 Thread Tobias Heider
On Tue, Oct 27, 2020 at 02:22:24PM +0100, Klemens Nanni wrote:
> On Tue, Oct 27, 2020 at 12:16:16AM +0100, Tobias Heider wrote:
> > the diff below makes the brightness keys work on apple powerbooks > 5,6
> > where the keyboard attaches via ukbd(4).
> > I'm wondering if it would be better to go through wskbd as is done with
> > audio, but we don't have keycodes allocated for brightness up/down.
> Running the latest snapshot on my PowerBook5,8 the keys do not work,
> neither does `wsconsctl display.brightness=50' or so.
> 
> Testing this before your diff, I noticed that the sensor values change
> each time I print them (random stack garbage?), same thing when setting
> values, i.e. setting brightness to 50 as above shows something like this
> 
>   display.brightness -> 0.23948792%
> 
> Applying your diff changes nothing for me.
> 

I think you're missing the previous diff, see
https://marc.info/?l=openbsd-tech=160373302219962=2



Re: ukbd(4): support apple brightness keys

2020-10-27 Thread Klemens Nanni
On Tue, Oct 27, 2020 at 12:16:16AM +0100, Tobias Heider wrote:
> the diff below makes the brightness keys work on apple powerbooks > 5,6
> where the keyboard attaches via ukbd(4).
> I'm wondering if it would be better to go through wskbd as is done with
> audio, but we don't have keycodes allocated for brightness up/down.
Running the latest snapshot on my PowerBook5,8 the keys do not work,
neither does `wsconsctl display.brightness=50' or so.

Testing this before your diff, I noticed that the sensor values change
each time I print them (random stack garbage?), same thing when setting
values, i.e. setting brightness to 50 as above shows something like this

display.brightness -> 0.23948792%

Applying your diff changes nothing for me.



Re: snapshot boot fails with error "entry point at 0x1001000"

2020-10-27 Thread Mark Kettenis
Hi Kastus,

Please don't have technical discussions on misc@; some developers,
like me, only read it sporadically.  The tech@ list is a much better
place.

The problem with your approach is that you allocate memory at a fixed
address, and we can't be sure that memory is available.  We may have
to extend the amount of memory we allocate such that larger kernels
fit.  The diff below bumps it from 32MB to 64MB.  Does this work for
you?


Index: arch/amd64/stand/efiboot/efiboot.c
===
RCS file: /cvs/src/sys/arch/amd64/stand/efiboot/efiboot.c,v
retrieving revision 1.35
diff -u -p -r1.35 efiboot.c
--- arch/amd64/stand/efiboot/efiboot.c  22 Mar 2020 14:59:11 -  1.35
+++ arch/amd64/stand/efiboot/efiboot.c  27 Oct 2020 12:36:45 -
@@ -39,7 +39,7 @@
 #include "eficall.h"
 #include "run_i386.h"
 
-#defineKERN_LOADSPACE_SIZE (32 * 1024 * 1024)
+#defineKERN_LOADSPACE_SIZE (64 * 1024 * 1024)
 
 EFI_SYSTEM_TABLE   *ST;
 EFI_BOOT_SERVICES  *BS;



Re: radeondrm(4) unaligned access fix

2020-10-27 Thread David Higgs
On Mon, Oct 26, 2020 at 3:18 PM Mark Kettenis 
wrote:

> > Date: Sun, 25 Oct 2020 10:42:38 +0100 (CET)
> > From: Mark Kettenis 
> >
> > While making radeondrm(4) work on powerpc64 I'm running into an
> > interesting unaligned access issue.
> >
> > Modern POWER CPUs generally support unaligned access.  Normal load and
> > store unstructions work fine with addresses that aren't naturally
> > aligned when operating on cached memory.  As a result, clang will
> > optimize code by replacing two 32-bit store instructions with a single
> > 64-bit store instruction even if there is only 32-bit alignment.
> >
> > However, this doesn't work for memory that is mapped uncachable.  And
> > there is some code in radeondrm(4) (and also in amdgpu(4)) that
> > generates alignment exceptions because it is writing to bits of video
> > memory that are mapped through the graphics aperture.
> >
> > There are two ways to fix this.  The compiler won't apply this
> > optimization if memory is accessed through pointers that are marked
> > volatile.  Hence the fix below.  In my opinion that is the right fix
> > as rdev->uvd.cpu_addr is a volatile pointer and that aspect shouldn't
> > be dropped.  The downside of this approach is that we may need to
> > maintain some additional local fixes.
> >
> > The alternative is to emulate the access in the kernel.  I fear that
> > is what Linux does, which is why they don't notice this issue.  As
> > such, this issue may crop up in more places and the emulation would
> > catch them all.  But I'm a bit reluctant to add this emulation since
> > it may hide bugs in other parts of our kernel.
> >
> > Thoughts?  ok?
>
> There is more code in radeondrm(4) and amdgpu(4) that is affected by
> this issues and some of it isn't easy to "volatilize".
>
> There is an llvm option to enforce strict alignment, but it isn't
> exposed as a proper option by clang.  I'm still investigating the use
> of that option, but meanwhile I think I'll commit the attached diff
> such that the kernel side of things works and I can look at what needs
> to happen on the userland side.
>

Disclaimer: I'm not an expert in this area.

Seems odd that this problem doesn't affect loads too...

Would it be difficult to also validate that the destination address is
mapped uncached, so that normal userland alignment bugs will still get
caught?

--david


Re: httpd(8): add location access tests

2020-10-27 Thread Denis Fondras
On Tue, Oct 27, 2020 at 12:02:18PM +0100, Matthias Pressfreund wrote:
> True. Updated patch below.
> 

Thanks, I have been using the diff (from your GH account) since a few weeks.

OK denis@

I will commit tonight if nobody stands against.


> 
> 
> Index: usr.sbin/httpd/httpd.conf.5
> ===
> RCS file: /cvs/src/usr.sbin/httpd/httpd.conf.5,v
> retrieving revision 1.113
> diff -u -p -u -p -r1.113 httpd.conf.5
> --- usr.sbin/httpd/httpd.conf.5   5 Sep 2020 11:49:38 -   1.113
> +++ usr.sbin/httpd/httpd.conf.5   27 Oct 2020 10:59:35 -
> @@ -1,5 +1,6 @@
>  .\"  $OpenBSD: httpd.conf.5,v 1.113 2020/09/05 11:49:38 tb Exp $
>  .\"
> +.\" Copyright (c) 2020 Matthias Pressfreund 
>  .\" Copyright (c) 2014, 2015 Reyk Floeter 
>  .\"
>  .\" Permission to use, copy, modify, and distribute this software for any
> @@ -14,7 +15,7 @@
>  .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
>  .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
>  .\"
> -.Dd $Mdocdate: September 5 2020 $
> +.Dd $Mdocdate: October 27 2020 $
>  .Dt HTTPD.CONF 5
>  .Os
>  .Sh NAME
> @@ -399,11 +400,16 @@ of the host's domain should be considere
>  .It Ic listen on Ar address Oo Ic tls Oc Ic port Ar number
>  Set the listen address and port.
>  This statement can be specified multiple times.
> -.It Ic location Ar path Brq ...
> +.It Ic location Oo Oo Ic not Oc Ic found Oc Ar path Brq ...
>  Specify server configuration rules for a specific location.
>  The
>  .Ar path
>  argument will be matched against the request path with shell globbing rules.
> +Optionally, it is also possible to match for
> +.Ic found
> +(i.e. accessible) or
> +.Ic not found
> +request paths only.
>  In case of multiple location statements in the same context, the
>  first matching location statement will be put into effect, while all
>  later ones will be ignored.
> @@ -419,7 +425,7 @@ except
>  .Ic tcp
>  and
>  .Ic tls .
> -.It Ic location match Ar path Brq ...
> +.It Ic location Oo Oo Ic not Oc Ic found Oc Ic match Ar path Brq ...
>  Like the
>  .Ic location
>  option,
> Index: usr.sbin/httpd/httpd.h
> ===
> RCS file: /cvs/src/usr.sbin/httpd/httpd.h,v
> retrieving revision 1.152
> diff -u -p -u -p -r1.152 httpd.h
> --- usr.sbin/httpd/httpd.h29 Aug 2020 07:53:48 -  1.152
> +++ usr.sbin/httpd/httpd.h27 Oct 2020 05:59:05 -
> @@ -1,6 +1,7 @@
>  /*   $OpenBSD: httpd.h,v 1.152 2020/08/29 07:53:48 florian Exp $ */
>  
>  /*
> + * Copyright (c) 2020 Matthias Pressfreund 
>   * Copyright (c) 2006 - 2015 Reyk Floeter 
>   * Copyright (c) 2006, 2007 Pierre-Yves Ritschard 
>   * Copyright (c) 2003, 2004 Henning Brauer 
> @@ -391,13 +392,16 @@ SPLAY_HEAD(client_tree, client);
>  #define SRVFLAG_DEFAULT_TYPE 0x0080
>  #define SRVFLAG_PATH_REWRITE 0x0100
>  #define SRVFLAG_NO_PATH_REWRITE  0x0200
> +#define SRVFLAG_LOCATION_FOUND   0x4000
> +#define SRVFLAG_LOCATION_NOT_FOUND 0x8000
>  
>  #define SRVFLAG_BITS \
>   "\10\01INDEX\02NO_INDEX\03AUTO_INDEX\04NO_AUTO_INDEX"   \
>   "\05ROOT\06LOCATION\07FCGI\10NO_FCGI\11LOG\12NO_LOG"\
>   "\14SYSLOG\15NO_SYSLOG\16TLS\17ACCESS_LOG\20ERROR_LOG"  \
>   "\21AUTH\22NO_AUTH\23BLOCK\24NO_BLOCK\25LOCATION_MATCH" \
> - "\26SERVER_MATCH\27SERVER_HSTS\30DEFAULT_TYPE\31PATH\32NO_PATH"
> + "\26SERVER_MATCH\27SERVER_HSTS\30DEFAULT_TYPE\31PATH\32NO_PATH" \
> + "\37LOCATION_FOUND\40LOCATION_NOT_FOUND"
>  
>  #define TCPFLAG_NODELAY  0x01
>  #define TCPFLAG_NNODELAY 0x02
> @@ -690,6 +694,7 @@ const char *
>server_root_strip(const char *, int);
>  struct server_config *
>server_getlocation(struct client *, const char *);
> +int   server_locationaccesstest(struct server_config *, const char *);
>  const char *
>server_http_host(struct sockaddr_storage *, char *, size_t);
>  char *server_http_parsehost(char *, char *, size_t, int *);
> Index: usr.sbin/httpd/parse.y
> ===
> RCS file: /cvs/src/usr.sbin/httpd/parse.y,v
> retrieving revision 1.119
> diff -u -p -u -p -r1.119 parse.y
> --- usr.sbin/httpd/parse.y26 Oct 2020 19:31:22 -  1.119
> +++ usr.sbin/httpd/parse.y27 Oct 2020 05:59:05 -
> @@ -143,12 +143,12 @@ typedef struct {
>  %token   PROTOCOLS REQUESTS ROOT SACK SERVER SOCKET STRIP STYLE SYSLOG 
> TCP TICKET
>  %token   TIMEOUT TLS TYPE TYPES HSTS MAXAGE SUBDOMAINS DEFAULT PRELOAD 
> REQUEST
>  %token   ERROR INCLUDE AUTHENTICATE WITH BLOCK DROP RETURN PASS REWRITE
> -%token   CA CLIENT CRL OPTIONAL PARAM FORWARDED
> +%token   CA CLIENT CRL OPTIONAL PARAM FORWARDED FOUND NOT
>  %token STRING
>  %token NUMBER
>  %typeport
>  %type  

Re: httpd(8): add location access tests

2020-10-27 Thread Matthias Pressfreund
True. Updated patch below.


On 2020-10-27 11:29, Denis Fondras wrote:
> Thanks Matthias,
> 
> comment below.
> 
> On Tue, Oct 27, 2020 at 08:37:39AM +0100, Matthias Pressfreund wrote:
>> Index: usr.sbin/httpd/httpd.conf.5
>> ===
>> RCS file: /cvs/src/usr.sbin/httpd/httpd.conf.5,v
>> retrieving revision 1.113
>> diff -u -p -u -p -r1.113 httpd.conf.5
>> --- usr.sbin/httpd/httpd.conf.5  5 Sep 2020 11:49:38 -   1.113
>> +++ usr.sbin/httpd/httpd.conf.5  27 Oct 2020 05:59:05 -
>> @@ -1,5 +1,6 @@
>>  .\" $OpenBSD: httpd.conf.5,v 1.113 2020/09/05 11:49:38 tb Exp $
>>  .\"
>> +.\" Copyright (c) 2020 Matthias Pressfreund 
>>  .\" Copyright (c) 2014, 2015 Reyk Floeter 
>>  .\"
>>  .\" Permission to use, copy, modify, and distribute this software for any
>> @@ -14,7 +15,7 @@
>>  .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
>>  .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
>>  .\"
>> -.Dd $Mdocdate: September 5 2020 $
>> +.Dd $Mdocdate: October 27 2020 $
>>  .Dt HTTPD.CONF 5
>>  .Os
>>  .Sh NAME
>> @@ -399,11 +400,16 @@ of the host's domain should be considere
>>  .It Ic listen on Ar address Oo Ic tls Oc Ic port Ar number
>>  Set the listen address and port.
>>  This statement can be specified multiple times.
>> -.It Ic location Ar path Brq ...
>> +.It Ic location Oo Oo Ic not Oc Ic found Oc Ar path Brq ...
>>  Specify server configuration rules for a specific location.
>>  The
>>  .Ar path
>>  argument will be matched against the request path with shell globbing rules.
>> +Optionally, it is also possible to match for
>> +.Ar found
>> +(i.e. accessible) or
>> +.Ar not found
> 
> .Ic seems best suited here.
> 


Index: usr.sbin/httpd/httpd.conf.5
===
RCS file: /cvs/src/usr.sbin/httpd/httpd.conf.5,v
retrieving revision 1.113
diff -u -p -u -p -r1.113 httpd.conf.5
--- usr.sbin/httpd/httpd.conf.5 5 Sep 2020 11:49:38 -   1.113
+++ usr.sbin/httpd/httpd.conf.5 27 Oct 2020 10:59:35 -
@@ -1,5 +1,6 @@
 .\"$OpenBSD: httpd.conf.5,v 1.113 2020/09/05 11:49:38 tb Exp $
 .\"
+.\" Copyright (c) 2020 Matthias Pressfreund 
 .\" Copyright (c) 2014, 2015 Reyk Floeter 
 .\"
 .\" Permission to use, copy, modify, and distribute this software for any
@@ -14,7 +15,7 @@
 .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 .\"
-.Dd $Mdocdate: September 5 2020 $
+.Dd $Mdocdate: October 27 2020 $
 .Dt HTTPD.CONF 5
 .Os
 .Sh NAME
@@ -399,11 +400,16 @@ of the host's domain should be considere
 .It Ic listen on Ar address Oo Ic tls Oc Ic port Ar number
 Set the listen address and port.
 This statement can be specified multiple times.
-.It Ic location Ar path Brq ...
+.It Ic location Oo Oo Ic not Oc Ic found Oc Ar path Brq ...
 Specify server configuration rules for a specific location.
 The
 .Ar path
 argument will be matched against the request path with shell globbing rules.
+Optionally, it is also possible to match for
+.Ic found
+(i.e. accessible) or
+.Ic not found
+request paths only.
 In case of multiple location statements in the same context, the
 first matching location statement will be put into effect, while all
 later ones will be ignored.
@@ -419,7 +425,7 @@ except
 .Ic tcp
 and
 .Ic tls .
-.It Ic location match Ar path Brq ...
+.It Ic location Oo Oo Ic not Oc Ic found Oc Ic match Ar path Brq ...
 Like the
 .Ic location
 option,
Index: usr.sbin/httpd/httpd.h
===
RCS file: /cvs/src/usr.sbin/httpd/httpd.h,v
retrieving revision 1.152
diff -u -p -u -p -r1.152 httpd.h
--- usr.sbin/httpd/httpd.h  29 Aug 2020 07:53:48 -  1.152
+++ usr.sbin/httpd/httpd.h  27 Oct 2020 05:59:05 -
@@ -1,6 +1,7 @@
 /* $OpenBSD: httpd.h,v 1.152 2020/08/29 07:53:48 florian Exp $ */
 
 /*
+ * Copyright (c) 2020 Matthias Pressfreund 
  * Copyright (c) 2006 - 2015 Reyk Floeter 
  * Copyright (c) 2006, 2007 Pierre-Yves Ritschard 
  * Copyright (c) 2003, 2004 Henning Brauer 
@@ -391,13 +392,16 @@ SPLAY_HEAD(client_tree, client);
 #define SRVFLAG_DEFAULT_TYPE   0x0080
 #define SRVFLAG_PATH_REWRITE   0x0100
 #define SRVFLAG_NO_PATH_REWRITE0x0200
+#define SRVFLAG_LOCATION_FOUND 0x4000
+#define SRVFLAG_LOCATION_NOT_FOUND 0x8000
 
 #define SRVFLAG_BITS   \
"\10\01INDEX\02NO_INDEX\03AUTO_INDEX\04NO_AUTO_INDEX"   \
"\05ROOT\06LOCATION\07FCGI\10NO_FCGI\11LOG\12NO_LOG"\
"\14SYSLOG\15NO_SYSLOG\16TLS\17ACCESS_LOG\20ERROR_LOG"  \
"\21AUTH\22NO_AUTH\23BLOCK\24NO_BLOCK\25LOCATION_MATCH" \
-   "\26SERVER_MATCH\27SERVER_HSTS\30DEFAULT_TYPE\31PATH\32NO_PATH"
+   "\26SERVER_MATCH\27SERVER_HSTS\30DEFAULT_TYPE\31PATH\32NO_PATH" \
+   

Re: httpd(8): add location access tests

2020-10-27 Thread Denis Fondras
Thanks Matthias,

comment below.

On Tue, Oct 27, 2020 at 08:37:39AM +0100, Matthias Pressfreund wrote:
> Index: usr.sbin/httpd/httpd.conf.5
> ===
> RCS file: /cvs/src/usr.sbin/httpd/httpd.conf.5,v
> retrieving revision 1.113
> diff -u -p -u -p -r1.113 httpd.conf.5
> --- usr.sbin/httpd/httpd.conf.5   5 Sep 2020 11:49:38 -   1.113
> +++ usr.sbin/httpd/httpd.conf.5   27 Oct 2020 05:59:05 -
> @@ -1,5 +1,6 @@
>  .\"  $OpenBSD: httpd.conf.5,v 1.113 2020/09/05 11:49:38 tb Exp $
>  .\"
> +.\" Copyright (c) 2020 Matthias Pressfreund 
>  .\" Copyright (c) 2014, 2015 Reyk Floeter 
>  .\"
>  .\" Permission to use, copy, modify, and distribute this software for any
> @@ -14,7 +15,7 @@
>  .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
>  .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
>  .\"
> -.Dd $Mdocdate: September 5 2020 $
> +.Dd $Mdocdate: October 27 2020 $
>  .Dt HTTPD.CONF 5
>  .Os
>  .Sh NAME
> @@ -399,11 +400,16 @@ of the host's domain should be considere
>  .It Ic listen on Ar address Oo Ic tls Oc Ic port Ar number
>  Set the listen address and port.
>  This statement can be specified multiple times.
> -.It Ic location Ar path Brq ...
> +.It Ic location Oo Oo Ic not Oc Ic found Oc Ar path Brq ...
>  Specify server configuration rules for a specific location.
>  The
>  .Ar path
>  argument will be matched against the request path with shell globbing rules.
> +Optionally, it is also possible to match for
> +.Ar found
> +(i.e. accessible) or
> +.Ar not found

.Ic seems best suited here.



Re: amap: introduce amap_adjref_anons()

2020-10-27 Thread Mark Kettenis
> Date: Fri, 23 Oct 2020 10:31:21 +0200
> From: Martin Pieuchot 
> 
> More refactoring.  This time let's introduce a helper to manipulate
> references.  The goal is to reduce the upcoming diff adding locking.
> 
> This is extracted from a bigger diff from guenther@ as well as some
> bits from NetBSD.
> 
> ok?

Hmm, this doesn't even compile...

> Index: uvm/uvm_amap.c
> ===
> RCS file: /cvs/src/sys/uvm/uvm_amap.c,v
> retrieving revision 1.85
> diff -u -p -r1.85 uvm_amap.c
> --- uvm/uvm_amap.c12 Oct 2020 08:44:45 -  1.85
> +++ uvm/uvm_amap.c23 Oct 2020 08:21:38 -
> @@ -68,7 +68,23 @@ static inline void amap_list_remove(stru
>  
>  struct vm_amap_chunk *amap_chunk_get(struct vm_amap *, int, int, int);
>  void amap_chunk_free(struct vm_amap *, struct vm_amap_chunk *);
> -void amap_wiperange_chunk(struct vm_amap *, struct vm_amap_chunk *, int, 
> int);
> +
> +/*
> + * if we enable PPREF, then we have a couple of extra functions that
> + * we need to prototype here...
> + */
> +
> +#ifdef UVM_AMAP_PPREF
> +
> +#define PPREF_NONE ((int *) -1)  /* not using ppref */
> +
> +void amap_pp_adjref(struct vm_amap *, int, vsize_t, int, struct vm_anon **);
> +void amap_pp_establish(struct vm_amap *);
> +void amap_wiperange_chunk(struct vm_amap *, struct vm_amap_chunk *, int,
> + int, struct vm_anon **);
> +void amap_wiperange(struct vm_amap *, int, int, struct vm_anon **);
> +
> +#endif   /* UVM_AMAP_PPREF */
>  
>  static inline void
>  amap_list_insert(struct vm_amap *amap)
> @@ -1153,6 +1169,32 @@ amap_unadd(struct vm_aref *aref, vaddr_t
>  }
>  
>  /*
> + * amap_adjref_anons: adjust the reference count(s) on amap and its anons.
> + */
> +static void
> +amap_adjref_anons(struct vm_amap *amap, vaddr_t offset, vsize_t len,
> +int refv, boolean_t all)
> +{
> +#ifdef UVM_AMAP_PPREF
> + if (amap->am_ppref == NULL && !all && len != amap->am_nslot) {
> + amap_pp_establish(amap);
> + }
> +#endif
> +
> + amap->am_ref += refv;
> +
> +#ifdef UVM_AMAP_PPREF
> + if (amap->am_ppref && amap->am_ppref != PPREF_NONE) {
> + if (all) {
> + amap_pp_adjref(amap, 0, amap->am_nslot, refv);
> + } else {
> + amap_pp_adjref(amap, offset, len, refv);
> + }
> + }
> +#endif
> +}
> +
> +/*
>   * amap_ref: gain a reference to an amap
>   *
>   * => "offset" and "len" are in units of pages
> @@ -1162,51 +1204,36 @@ void
>  amap_ref(struct vm_amap *amap, vaddr_t offset, vsize_t len, int flags)
>  {
>  
> - amap->am_ref++;
>   if (flags & AMAP_SHARED)
>   amap->am_flags |= AMAP_SHARED;
> -#ifdef UVM_AMAP_PPREF
> - if (amap->am_ppref == NULL && (flags & AMAP_REFALL) == 0 &&
> - len != amap->am_nslot)
> - amap_pp_establish(amap);
> - if (amap->am_ppref && amap->am_ppref != PPREF_NONE) {
> - if (flags & AMAP_REFALL)
> - amap_pp_adjref(amap, 0, amap->am_nslot, 1);
> - else
> - amap_pp_adjref(amap, offset, len, 1);
> - }
> -#endif
> + amap_adjref_anons(amap, offset, len, 1, (flags & AMAP_REFALL) != 0);
>  }
>  
>  /*
>   * amap_unref: remove a reference to an amap
>   *
> - * => caller must remove all pmap-level references to this amap before
> - *   dropping the reference
> - * => called from uvm_unmap_detach [only]  ... note that entry is no
> - *   longer part of a map
> + * => All pmap-level references to this amap must be already removed.
> + * => Called from uvm_unmap_detach(); entry is already removed from the map.
>   */
>  void
>  amap_unref(struct vm_amap *amap, vaddr_t offset, vsize_t len, boolean_t all)
>  {
> + KASSERT(amap->am_ref > 0);
>  
> - /* if we are the last reference, free the amap and return. */
> - if (amap->am_ref-- == 1) {
> - amap_wipeout(amap); /* drops final ref and frees */
> + if (amap->am_ref == 1) {
> + /*
> +  * If the last reference - wipeout and destroy the amap.
> +  */
> + amap->am_ref--;
> + amap_wipeout(amap);
>   return;
>   }
>  
> - /* otherwise just drop the reference count(s) */
> - if (amap->am_ref == 1 && (amap->am_flags & AMAP_SHARED) != 0)
> - amap->am_flags &= ~AMAP_SHARED; /* clear shared flag */
> -#ifdef UVM_AMAP_PPREF
> - if (amap->am_ppref == NULL && all == 0 && len != amap->am_nslot)
> - amap_pp_establish(amap);
> - if (amap->am_ppref && amap->am_ppref != PPREF_NONE) {
> - if (all)
> - amap_pp_adjref(amap, 0, amap->am_nslot, -1);
> - else
> - amap_pp_adjref(amap, offset, len, -1);
> + /*
> +  * Otherwise, drop the reference count(s) on anons.
> +  */
> + if (amap->am_ref == 2 && (amap->am_flags & AMAP_SHARED) != 0) {
> + amap->am_flags &= 

httpd(8): add location access tests

2020-10-27 Thread Matthias Pressfreund
The patch below adds access tests ('found' or 'not found') for
'location' resource paths via httpd.conf(5).  This enables WordPress
Pretty Permalinks (https://wordpress.org/support/article/using-permalinks/)
just like on an Apache web server with 'mod_rewrite' installed:

server "www.example.com" {
listen on * port www
directory index "index.php"

location not found "/*" {
request rewrite "/index.php"
}
location "/*.php" {
fastcgi socket "/run/php-fpm.sock"
}
}

NOTE: Even with this patch, WordPress is unable to discover that
the OpenBSD web server is now capable to perform required URL
rewrites.  This will make the Permalink Settings Screen
(https://wordpress.org/support/article/settings-permalinks-screen/)
not behave as expected.  Luckily, and for this case exactly, the
'got_url_rewrite' hook
(https://developer.wordpress.org/reference/hooks/got_url_rewrite/)
exists.  Adding the following line of code into the current theme's
'functions.php' file will straighten things out:

add_filter('got_url_rewrite', '__return_true');


(from https://github.com/mpfr/httpd-plus)



Index: usr.sbin/httpd/httpd.conf.5
===
RCS file: /cvs/src/usr.sbin/httpd/httpd.conf.5,v
retrieving revision 1.113
diff -u -p -u -p -r1.113 httpd.conf.5
--- usr.sbin/httpd/httpd.conf.5 5 Sep 2020 11:49:38 -   1.113
+++ usr.sbin/httpd/httpd.conf.5 27 Oct 2020 05:59:05 -
@@ -1,5 +1,6 @@
 .\"$OpenBSD: httpd.conf.5,v 1.113 2020/09/05 11:49:38 tb Exp $
 .\"
+.\" Copyright (c) 2020 Matthias Pressfreund 
 .\" Copyright (c) 2014, 2015 Reyk Floeter 
 .\"
 .\" Permission to use, copy, modify, and distribute this software for any
@@ -14,7 +15,7 @@
 .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 .\"
-.Dd $Mdocdate: September 5 2020 $
+.Dd $Mdocdate: October 27 2020 $
 .Dt HTTPD.CONF 5
 .Os
 .Sh NAME
@@ -399,11 +400,16 @@ of the host's domain should be considere
 .It Ic listen on Ar address Oo Ic tls Oc Ic port Ar number
 Set the listen address and port.
 This statement can be specified multiple times.
-.It Ic location Ar path Brq ...
+.It Ic location Oo Oo Ic not Oc Ic found Oc Ar path Brq ...
 Specify server configuration rules for a specific location.
 The
 .Ar path
 argument will be matched against the request path with shell globbing rules.
+Optionally, it is also possible to match for
+.Ar found
+(i.e. accessible) or
+.Ar not found
+request paths only.
 In case of multiple location statements in the same context, the
 first matching location statement will be put into effect, while all
 later ones will be ignored.
@@ -419,7 +425,7 @@ except
 .Ic tcp
 and
 .Ic tls .
-.It Ic location match Ar path Brq ...
+.It Ic location Oo Oo Ic not Oc Ic found Oc Ic match Ar path Brq ...
 Like the
 .Ic location
 option,
Index: usr.sbin/httpd/httpd.h
===
RCS file: /cvs/src/usr.sbin/httpd/httpd.h,v
retrieving revision 1.152
diff -u -p -u -p -r1.152 httpd.h
--- usr.sbin/httpd/httpd.h  29 Aug 2020 07:53:48 -  1.152
+++ usr.sbin/httpd/httpd.h  27 Oct 2020 05:59:05 -
@@ -1,6 +1,7 @@
 /* $OpenBSD: httpd.h,v 1.152 2020/08/29 07:53:48 florian Exp $ */
 
 /*
+ * Copyright (c) 2020 Matthias Pressfreund 
  * Copyright (c) 2006 - 2015 Reyk Floeter 
  * Copyright (c) 2006, 2007 Pierre-Yves Ritschard 
  * Copyright (c) 2003, 2004 Henning Brauer 
@@ -391,13 +392,16 @@ SPLAY_HEAD(client_tree, client);
 #define SRVFLAG_DEFAULT_TYPE   0x0080
 #define SRVFLAG_PATH_REWRITE   0x0100
 #define SRVFLAG_NO_PATH_REWRITE0x0200
+#define SRVFLAG_LOCATION_FOUND 0x4000
+#define SRVFLAG_LOCATION_NOT_FOUND 0x8000
 
 #define SRVFLAG_BITS   \
"\10\01INDEX\02NO_INDEX\03AUTO_INDEX\04NO_AUTO_INDEX"   \
"\05ROOT\06LOCATION\07FCGI\10NO_FCGI\11LOG\12NO_LOG"\
"\14SYSLOG\15NO_SYSLOG\16TLS\17ACCESS_LOG\20ERROR_LOG"  \
"\21AUTH\22NO_AUTH\23BLOCK\24NO_BLOCK\25LOCATION_MATCH" \
-   "\26SERVER_MATCH\27SERVER_HSTS\30DEFAULT_TYPE\31PATH\32NO_PATH"
+   "\26SERVER_MATCH\27SERVER_HSTS\30DEFAULT_TYPE\31PATH\32NO_PATH" \
+   "\37LOCATION_FOUND\40LOCATION_NOT_FOUND"
 
 #define TCPFLAG_NODELAY0x01
 #define TCPFLAG_NNODELAY   0x02
@@ -690,6 +694,7 @@ const char *
 server_root_strip(const char *, int);
 struct server_config *
 server_getlocation(struct client *, const char *);
+int server_locationaccesstest(struct server_config *, const char *);
 const char *
 server_http_host(struct sockaddr_storage *, char *, size_t);
 char   *server_http_parsehost(char *, char *, size_t, int *);
Index: usr.sbin/httpd/parse.y
===