Re: rpki-client: ASN1_IMP_OPT vs ASN1_EXP_OPT

2022-10-12 Thread Theo Buehler
On Thu, Oct 13, 2022 at 04:25:49AM +, Job Snijders wrote:
> Hi all,
> 
> All of ROA, MFT, ASPA, and RSC define their respective 'version' field
> in ASN.1 as following:
> 
> version [0] INTEGER DEFAULT 0,
> 
> Each object profile preamble "DEFINITIONS EXPLICIT TAGS ::="
> 
> We haven't bumped into an issue yet, because all Signed Objects are at
> version 0, which means the field is entirely omitted (including the tag,
> be it implicit or explicit). (From X.690 section 11.5: "The encoding of
> a set value or a sequence value shall not include an encoding for any
> component value which is equal to its default value.")
> 
> Then again, lib/libcrypto/asn1/asn1t.h is a mysterious place, so perhaps
> I'm holding it wrong.
> 
> OK?

Yes, I think that's right.

ok tb

> 
> Kind regards,
> 
> Job
> 
> Index: aspa.c
> ===
> RCS file: /cvs/src/usr.sbin/rpki-client/aspa.c,v
> retrieving revision 1.4
> diff -u -p -r1.4 aspa.c
> --- aspa.c5 Sep 2022 18:07:04 -   1.4
> +++ aspa.c13 Oct 2022 04:06:55 -
> @@ -71,7 +71,7 @@ typedef struct {
>  } ASProviderAttestation;
>  
>  ASN1_SEQUENCE(ASProviderAttestation) = {
> - ASN1_IMP_OPT(ASProviderAttestation, version, ASN1_INTEGER, 0),
> + ASN1_EXP_OPT(ASProviderAttestation, version, ASN1_INTEGER, 0),
>   ASN1_SIMPLE(ASProviderAttestation, customerASID, ASN1_INTEGER),
>   ASN1_SEQUENCE_OF(ASProviderAttestation, providers, ProviderAS),
>  } ASN1_SEQUENCE_END(ASProviderAttestation);
> Index: mft.c
> ===
> RCS file: /cvs/src/usr.sbin/rpki-client/mft.c,v
> retrieving revision 1.74
> diff -u -p -r1.74 mft.c
> --- mft.c 30 Aug 2022 18:56:49 -  1.74
> +++ mft.c 13 Oct 2022 04:06:55 -
> @@ -78,7 +78,7 @@ ASN1_SEQUENCE(FileAndHash) = {
>  } ASN1_SEQUENCE_END(FileAndHash);
>  
>  ASN1_SEQUENCE(Manifest) = {
> - ASN1_IMP_OPT(Manifest, version, ASN1_INTEGER, 0),
> + ASN1_EXP_OPT(Manifest, version, ASN1_INTEGER, 0),
>   ASN1_SIMPLE(Manifest, manifestNumber, ASN1_INTEGER),
>   ASN1_SIMPLE(Manifest, thisUpdate, ASN1_GENERALIZEDTIME),
>   ASN1_SIMPLE(Manifest, nextUpdate, ASN1_GENERALIZEDTIME),
> Index: roa.c
> ===
> RCS file: /cvs/src/usr.sbin/rpki-client/roa.c,v
> retrieving revision 1.52
> diff -u -p -r1.52 roa.c
> --- roa.c 3 Sep 2022 14:40:09 -   1.52
> +++ roa.c 13 Oct 2022 04:06:55 -
> @@ -86,7 +86,7 @@ ASN1_SEQUENCE(ROAIPAddressFamily) = {
>  } ASN1_SEQUENCE_END(ROAIPAddressFamily);
>  
>  ASN1_SEQUENCE(RouteOriginAttestation) = {
> - ASN1_IMP_OPT(RouteOriginAttestation, version, ASN1_INTEGER, 0),
> + ASN1_EXP_OPT(RouteOriginAttestation, version, ASN1_INTEGER, 0),
>   ASN1_SIMPLE(RouteOriginAttestation, asid, ASN1_INTEGER),
>   ASN1_SEQUENCE_OF(RouteOriginAttestation, ipAddrBlocks,
>   ROAIPAddressFamily),
> Index: rsc.c
> ===
> RCS file: /cvs/src/usr.sbin/rpki-client/rsc.c,v
> retrieving revision 1.15
> diff -u -p -r1.15 rsc.c
> --- rsc.c 3 Sep 2022 14:40:09 -   1.15
> +++ rsc.c 13 Oct 2022 04:06:55 -
> @@ -114,7 +114,7 @@ typedef struct {
>  } RpkiSignedChecklist;
>  
>  ASN1_SEQUENCE(RpkiSignedChecklist) = {
> - ASN1_IMP_OPT(RpkiSignedChecklist, version, ASN1_INTEGER, 0),
> + ASN1_EXP_OPT(RpkiSignedChecklist, version, ASN1_INTEGER, 0),
>   ASN1_SIMPLE(RpkiSignedChecklist, resources, ResourceBlock),
>   ASN1_SIMPLE(RpkiSignedChecklist, digestAlgorithm, X509_ALGOR),
>   ASN1_SEQUENCE_OF(RpkiSignedChecklist, checkList, FileNameAndHash),
> 



rpki-client: ASN1_IMP_OPT vs ASN1_EXP_OPT

2022-10-12 Thread Job Snijders
Hi all,

All of ROA, MFT, ASPA, and RSC define their respective 'version' field
in ASN.1 as following:

version [0] INTEGER DEFAULT 0,

Each object profile preamble "DEFINITIONS EXPLICIT TAGS ::="

We haven't bumped into an issue yet, because all Signed Objects are at
version 0, which means the field is entirely omitted (including the tag,
be it implicit or explicit). (From X.690 section 11.5: "The encoding of
a set value or a sequence value shall not include an encoding for any
component value which is equal to its default value.")

Then again, lib/libcrypto/asn1/asn1t.h is a mysterious place, so perhaps
I'm holding it wrong.

OK?

Kind regards,

Job

Index: aspa.c
===
RCS file: /cvs/src/usr.sbin/rpki-client/aspa.c,v
retrieving revision 1.4
diff -u -p -r1.4 aspa.c
--- aspa.c  5 Sep 2022 18:07:04 -   1.4
+++ aspa.c  13 Oct 2022 04:06:55 -
@@ -71,7 +71,7 @@ typedef struct {
 } ASProviderAttestation;
 
 ASN1_SEQUENCE(ASProviderAttestation) = {
-   ASN1_IMP_OPT(ASProviderAttestation, version, ASN1_INTEGER, 0),
+   ASN1_EXP_OPT(ASProviderAttestation, version, ASN1_INTEGER, 0),
ASN1_SIMPLE(ASProviderAttestation, customerASID, ASN1_INTEGER),
ASN1_SEQUENCE_OF(ASProviderAttestation, providers, ProviderAS),
 } ASN1_SEQUENCE_END(ASProviderAttestation);
Index: mft.c
===
RCS file: /cvs/src/usr.sbin/rpki-client/mft.c,v
retrieving revision 1.74
diff -u -p -r1.74 mft.c
--- mft.c   30 Aug 2022 18:56:49 -  1.74
+++ mft.c   13 Oct 2022 04:06:55 -
@@ -78,7 +78,7 @@ ASN1_SEQUENCE(FileAndHash) = {
 } ASN1_SEQUENCE_END(FileAndHash);
 
 ASN1_SEQUENCE(Manifest) = {
-   ASN1_IMP_OPT(Manifest, version, ASN1_INTEGER, 0),
+   ASN1_EXP_OPT(Manifest, version, ASN1_INTEGER, 0),
ASN1_SIMPLE(Manifest, manifestNumber, ASN1_INTEGER),
ASN1_SIMPLE(Manifest, thisUpdate, ASN1_GENERALIZEDTIME),
ASN1_SIMPLE(Manifest, nextUpdate, ASN1_GENERALIZEDTIME),
Index: roa.c
===
RCS file: /cvs/src/usr.sbin/rpki-client/roa.c,v
retrieving revision 1.52
diff -u -p -r1.52 roa.c
--- roa.c   3 Sep 2022 14:40:09 -   1.52
+++ roa.c   13 Oct 2022 04:06:55 -
@@ -86,7 +86,7 @@ ASN1_SEQUENCE(ROAIPAddressFamily) = {
 } ASN1_SEQUENCE_END(ROAIPAddressFamily);
 
 ASN1_SEQUENCE(RouteOriginAttestation) = {
-   ASN1_IMP_OPT(RouteOriginAttestation, version, ASN1_INTEGER, 0),
+   ASN1_EXP_OPT(RouteOriginAttestation, version, ASN1_INTEGER, 0),
ASN1_SIMPLE(RouteOriginAttestation, asid, ASN1_INTEGER),
ASN1_SEQUENCE_OF(RouteOriginAttestation, ipAddrBlocks,
ROAIPAddressFamily),
Index: rsc.c
===
RCS file: /cvs/src/usr.sbin/rpki-client/rsc.c,v
retrieving revision 1.15
diff -u -p -r1.15 rsc.c
--- rsc.c   3 Sep 2022 14:40:09 -   1.15
+++ rsc.c   13 Oct 2022 04:06:55 -
@@ -114,7 +114,7 @@ typedef struct {
 } RpkiSignedChecklist;
 
 ASN1_SEQUENCE(RpkiSignedChecklist) = {
-   ASN1_IMP_OPT(RpkiSignedChecklist, version, ASN1_INTEGER, 0),
+   ASN1_EXP_OPT(RpkiSignedChecklist, version, ASN1_INTEGER, 0),
ASN1_SIMPLE(RpkiSignedChecklist, resources, ResourceBlock),
ASN1_SIMPLE(RpkiSignedChecklist, digestAlgorithm, X509_ALGOR),
ASN1_SEQUENCE_OF(RpkiSignedChecklist, checkList, FileNameAndHash),



aucat.1: Improve description

2022-10-12 Thread Josiah Frentsos
Index: aucat.1
===
RCS file: /cvs/src/usr.bin/aucat/aucat.1,v
retrieving revision 1.117
diff -u -p -r1.117 aucat.1
--- aucat.1 7 Mar 2022 09:04:45 -   1.117
+++ aucat.1 13 Oct 2022 00:49:47 -
@@ -19,7 +19,7 @@
 .Os
 .Sh NAME
 .Nm aucat
-.Nd audio files manipulation tool
+.Nd manipulate audio files
 .Sh SYNOPSIS
 .Nm aucat
 .Op Fl dn



Re: Fix level-triggered ACPI GPIO interrupts on amd64

2022-10-12 Thread Mark Kettenis
> Date: Thu, 13 Oct 2022 00:17:37 +0200
> From: Mark Kettenis 
> 
> > Date: Mon, 10 Oct 2022 17:02:41 +0200
> > From: Matthias Schmidt 
> > 
> > * Matthias Schmidt wrote:
> > > Hi Mark,
> > > 
> > > Addendum after 24h of testing.  Your patch fixes the frequent touchpad
> > > freezes I see on this model and which I reported back then in
> > > https://marc.info/?l=openbsd-bugs=165328803822857=2
> > 
> > Any chance that this patch gets committed or wider testing in snaps?
> > It really improved the touchpad situation here.
> 
> Right, I should probably just commit the diff instead of waiting for
> more tests.
> 
> ok?

For reference, here is the diff again.


Index: dev/acpi/amdgpio.c
===
RCS file: /cvs/src/sys/dev/acpi/amdgpio.c,v
retrieving revision 1.9
diff -u -p -r1.9 amdgpio.c
--- dev/acpi/amdgpio.c  27 Jun 2022 08:00:31 -  1.9
+++ dev/acpi/amdgpio.c  3 Oct 2022 19:10:03 -
@@ -92,6 +92,8 @@ const char *amdgpio_hids[] = {
 intamdgpio_read_pin(void *, int);
 void   amdgpio_write_pin(void *, int, int);
 void   amdgpio_intr_establish(void *, int, int, int (*)(void *), void *);
+void   amdgpio_intr_enable(void *, int);
+void   amdgpio_intr_disable(void *, int);
 intamdgpio_pin_intr(struct amdgpio_softc *, int);
 intamdgpio_intr(void *);
 void   amdgpio_save_pin(struct amdgpio_softc *, int pin);
@@ -163,6 +165,8 @@ amdgpio_attach(struct device *parent, st
sc->sc_gpio.read_pin = amdgpio_read_pin;
sc->sc_gpio.write_pin = amdgpio_write_pin;
sc->sc_gpio.intr_establish = amdgpio_intr_establish;
+   sc->sc_gpio.intr_enable = amdgpio_intr_enable;
+   sc->sc_gpio.intr_disable = amdgpio_intr_disable;
sc->sc_node->gpio = >sc_gpio;
 
printf(", %d pins\n", sc->sc_npins);
@@ -275,6 +279,32 @@ amdgpio_intr_establish(void *cookie, int
if ((flags & LR_GPIO_POLARITY) == LR_GPIO_ACTBOTH)
reg |= AMDGPIO_CONF_ACTBOTH;
reg |= (AMDGPIO_CONF_INT_MASK | AMDGPIO_CONF_INT_EN);
+   bus_space_write_4(sc->sc_memt, sc->sc_memh, pin * 4, reg);
+}
+
+void
+amdgpio_intr_enable(void *cookie, int pin)
+{
+   struct amdgpio_softc *sc = cookie;
+   uint32_t reg;
+
+   KASSERT(pin >= 0 && pin != 63 && pin < sc->sc_npins);
+
+   reg = bus_space_read_4(sc->sc_memt, sc->sc_memh, pin * 4);
+   reg |= (AMDGPIO_CONF_INT_MASK | AMDGPIO_CONF_INT_EN);
+   bus_space_write_4(sc->sc_memt, sc->sc_memh, pin * 4, reg);
+}
+
+void
+amdgpio_intr_disable(void *cookie, int pin)
+{
+   struct amdgpio_softc *sc = cookie;
+   uint32_t reg;
+
+   KASSERT(pin >= 0 && pin != 63 && pin < sc->sc_npins);
+
+   reg = bus_space_read_4(sc->sc_memt, sc->sc_memh, pin * 4);
+   reg &= ~(AMDGPIO_CONF_INT_MASK | AMDGPIO_CONF_INT_EN);
bus_space_write_4(sc->sc_memt, sc->sc_memh, pin * 4, reg);
 }
 
Index: dev/acpi/aplgpio.c
===
RCS file: /cvs/src/sys/dev/acpi/aplgpio.c,v
retrieving revision 1.5
diff -u -p -r1.5 aplgpio.c
--- dev/acpi/aplgpio.c  6 Apr 2022 18:59:27 -   1.5
+++ dev/acpi/aplgpio.c  3 Oct 2022 19:10:03 -
@@ -76,6 +76,8 @@ const char *aplgpio_hids[] = {
 intaplgpio_read_pin(void *, int);
 void   aplgpio_write_pin(void *, int, int);
 void   aplgpio_intr_establish(void *, int, int, int (*)(void *), void *);
+void   aplgpio_intr_enable(void *, int);
+void   aplgpio_intr_disable(void *, int);
 intaplgpio_intr(void *);
 
 int
@@ -150,6 +152,8 @@ aplgpio_attach(struct device *parent, st
sc->sc_gpio.read_pin = aplgpio_read_pin;
sc->sc_gpio.write_pin = aplgpio_write_pin;
sc->sc_gpio.intr_establish = aplgpio_intr_establish;
+   sc->sc_gpio.intr_enable = aplgpio_intr_enable;
+   sc->sc_gpio.intr_disable = aplgpio_intr_disable;
sc->sc_node->gpio = >sc_gpio;
 
/* Mask and clear all interrupts. */
@@ -227,6 +231,36 @@ aplgpio_intr_establish(void *cookie, int
reg = bus_space_read_4(sc->sc_memt, sc->sc_memh,
APLGPIO_IRQ_EN + (pin / 32) * 4);
reg |= (1 << (pin % 32));
+   bus_space_write_4(sc->sc_memt, sc->sc_memh,
+   APLGPIO_IRQ_EN + (pin / 32) * 4, reg);
+}
+
+void
+aplgpio_intr_enable(void *cookie, int pin)
+{
+   struct aplgpio_softc *sc = cookie;
+   uint32_t reg;
+
+   KASSERT(pin >= 0 && pin < sc->sc_npins);
+
+   reg = bus_space_read_4(sc->sc_memt, sc->sc_memh,
+   APLGPIO_IRQ_EN + (pin / 32) * 4);
+   reg |= (1 << (pin % 32));
+   bus_space_write_4(sc->sc_memt, sc->sc_memh,
+   APLGPIO_IRQ_EN + (pin / 32) * 4, reg);
+}
+
+void
+aplgpio_intr_disable(void *cookie, int pin)
+{
+   struct aplgpio_softc *sc = cookie;
+   uint32_t reg;
+
+   KASSERT(pin >= 0 && pin < sc->sc_npins);
+
+   reg = bus_space_read_4(sc->sc_memt, sc->sc_memh,
+   APLGPIO_IRQ_EN + (pin / 32) * 4);
+   reg &= ~(1 << (pin % 32));

Re: EFI runtime services support on amd64

2022-10-12 Thread Mark Kettenis
So krw@ found an issue with the diff on an x230.  The diff
inadvertedly made us always use the EFI runtime services to access the
RTC.  And that is busted on the x230.  Fortunately I committed the
diff that allows us to have a quality indicater for RTCs.  So I
synched up the amd64 code with the arm64 such that we only use the EFI
interface as a last resort.

Ken, does this fix the issues you were seeing?

ok?


Index: arch/amd64/amd64/bios.c
===
RCS file: /cvs/src/sys/arch/amd64/amd64/bios.c,v
retrieving revision 1.45
diff -u -p -r1.45 bios.c
--- arch/amd64/amd64/bios.c 21 Feb 2022 11:03:39 -  1.45
+++ arch/amd64/amd64/bios.c 12 Oct 2022 23:11:19 -
@@ -30,6 +30,7 @@
 #include 
 
 #include "acpi.h"
+#include "efi.h"
 #include "mpbios.h"
 #include "pci.h"
 
@@ -189,6 +190,18 @@ out:
break;
}
}
+
+#if NEFI > 0
+   if (bios_efiinfo != NULL) {
+   struct bios_attach_args ba;
+
+   memset(, 0, sizeof(ba));
+   ba.ba_name = "efi";
+   ba.ba_memt = X86_BUS_SPACE_MEM;
+
+   config_found(self, , bios_print);
+   }
+#endif
 
 #if NACPI > 0
{
Index: arch/amd64/amd64/efi_machdep.c
===
RCS file: arch/amd64/amd64/efi_machdep.c
diff -N arch/amd64/amd64/efi_machdep.c
--- /dev/null   1 Jan 1970 00:00:00 -
+++ arch/amd64/amd64/efi_machdep.c  12 Oct 2022 23:11:19 -
@@ -0,0 +1,301 @@
+/* $OpenBSD$   */
+
+/*
+ * Copyright (c) 2022 Mark Kettenis 
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+#include 
+extern paddr_t cr3_reuse_pcid;
+
+#include 
+
+#include 
+
+extern EFI_MEMORY_DESCRIPTOR *mmap;
+
+struct efi_softc {
+   struct device   sc_dev;
+   struct pmap *sc_pm;
+   EFI_RUNTIME_SERVICES *sc_rs;
+   u_long  sc_psw;
+   uint64_tsc_cr3;
+
+   struct todr_chip_handle sc_todr;
+};
+
+intefi_match(struct device *, void *, void *);
+void   efi_attach(struct device *, struct device *, void *);
+
+const struct cfattach efi_ca = {
+   sizeof(struct efi_softc), efi_match, efi_attach
+};
+
+struct cfdriver efi_cd = {
+   NULL, "efi", DV_DULL
+};
+
+void   efi_map_runtime(struct efi_softc *);
+void   efi_enter(struct efi_softc *);
+void   efi_leave(struct efi_softc *);
+intefi_gettime(struct todr_chip_handle *, struct timeval *);
+intefi_settime(struct todr_chip_handle *, struct timeval *);
+
+int
+efi_match(struct device *parent, void *match, void *aux)
+{
+   struct bios_attach_args *ba = aux;
+   struct cfdata *cf = match;
+
+   if (strcmp(ba->ba_name, cf->cf_driver->cd_name) == 0 &&
+   bios_efiinfo->system_table != 0)
+   return 1;
+
+   return 0;
+}
+
+void
+efi_attach(struct device *parent, struct device *self, void *aux)
+{
+   struct efi_softc *sc = (struct efi_softc *)self;
+   struct bios_attach_args *ba = aux;
+   uint32_t mmap_desc_ver = bios_efiinfo->mmap_desc_ver;
+   uint64_t system_table;
+   bus_space_handle_t memh;
+   EFI_SYSTEM_TABLE *st;
+   EFI_TIME time;
+   EFI_STATUS status;
+   uint16_t major, minor;
+   int i;
+
+   if (mmap_desc_ver != EFI_MEMORY_DESCRIPTOR_VERSION) {
+   printf(": unsupported memory descriptor version %d\n",
+   mmap_desc_ver);
+   return;
+   }
+
+   system_table = bios_efiinfo->system_table;
+   KASSERT(system_table);
+
+   if (bus_space_map(ba->ba_memt, system_table, sizeof(EFI_SYSTEM_TABLE),
+   BUS_SPACE_MAP_LINEAR | BUS_SPACE_MAP_CACHEABLE, )) {
+   printf(": can't map system table\n");
+   return;
+   }
+
+   st = bus_space_vaddr(ba->ba_memt, memh);
+   sc->sc_rs = st->RuntimeServices;
+
+   major = st->Hdr.Revision >> 16;
+   minor = st->Hdr.Revision & 0x;
+   printf(": UEFI %d.%d", major, minor / 10);
+   if (minor % 10)
+   printf(".%d", minor % 10);
+   printf("\n");
+
+   if ((bios_efiinfo->flags & BEI_64BIT) == 0)
+   

Re: Fix level-triggered ACPI GPIO interrupts on amd64

2022-10-12 Thread Mark Kettenis
> Date: Mon, 10 Oct 2022 17:02:41 +0200
> From: Matthias Schmidt 
> 
> * Matthias Schmidt wrote:
> > Hi Mark,
> > 
> > Addendum after 24h of testing.  Your patch fixes the frequent touchpad
> > freezes I see on this model and which I reported back then in
> > https://marc.info/?l=openbsd-bugs=165328803822857=2
> 
> Any chance that this patch gets committed or wider testing in snaps?
> It really improved the touchpad situation here.

Right, I should probably just commit the diff instead of waiting for
more tests.

ok?



cwm: do not overlap menu entries

2022-10-12 Thread Klemens Nanni
This has annoyed me for a long time...

1. have at least two windows
2. open the window menu with M-slash (alt+/)
3. show all windows with C-A (ctrl+a)
4. move cursor over list from top to bottom,
   observe no glitch
5. move cursor over list from bottom to top,
   observe "[" and "]" chars in entries being drawn over at the top,
   i.e. upper entries overlap lower ones

It's easy to miss but hard to unsee.

Today I looked and came up with the following fix, drawing menu entries
without overlap.

All these `height + 1' spread across seem off, but they seem consistent.

Okan, is there a better way to fix this?


This is trivial to reproduce wihout messing with your running X:

$ Xephyr :1 &
$ xterm -display 1 &
$ xterm -display 1 &
$ DISPLAY=:1 ./obj/cwm

Then click on the background/root window to navigate the window menu.


Index: app/cwm/menu.c
===
RCS file: /cvs/xenocara/app/cwm/menu.c,v
retrieving revision 1.109
diff -u -p -r1.109 menu.c
--- app/cwm/menu.c  27 Feb 2020 14:56:39 -  1.109
+++ app/cwm/menu.c  12 Oct 2022 21:24:17 -
@@ -436,7 +436,7 @@ menu_draw_entry(struct menu_ctx *mc, str
color = (active) ? CWM_COLOR_MENU_FG : CWM_COLOR_MENU_BG;
XftDrawRect(mc->xftdraw, >xftcolor[color], 0,
(sc->xftfont->height + 1) * entry, mc->geom.w,
-   (sc->xftfont->height + 1) + sc->xftfont->descent);
+   (sc->xftfont->height + 1) + sc->xftfont->descent - 1);
color = (active) ? CWM_COLOR_MENU_FONT_SEL : CWM_COLOR_MENU_FONT;
XftDrawStringUtf8(mc->xftdraw,
>xftcolor[color], sc->xftfont,



Re: sparc64: bootblk: broken fake target still useful?

2022-10-12 Thread Klemens Nanni
Then there's also bootblk.text:  not required by bootblk, not installed
and only used with Sun's fakeboot in a target that cannot work:

$ make -n fake
([ -h machine ] || ln -s 
/home/kn/src/sys/arch/sparc64/stand/bootblk/../../include machine)
../fakeboot/fakeboot -elf32 /bootblk
../fakeboot/fakeboot -elf32 /bootblk.text

ksh(1) explains and a quick demo confirms this:

   Input/output redirection
 [...]

 > file  [...] Note that this means the command cmd < foo > foo will
 open foo for reading and then truncate it when it opens it for
 writing, before cmd gets a chance to actually read foo.

$ cat foo
foo
$ cat < foo > foo
$ du foo
0  

NetBSD still has the same Makefile bits;  I never had access to fakeboot
and thus can't judge its usefulness (today), but I'm pretty sure the
current target can't work.

Is anyone still using this or can it go?
Diff on top of the previous.

diff --git a/sys/arch/sparc64/stand/bootblk/Makefile 
b/sys/arch/sparc64/stand/bootblk/Makefile
index f544c6508ed..851b0484df3 100644
--- a/sys/arch/sparc64/stand/bootblk/Makefile
+++ b/sys/arch/sparc64/stand/bootblk/Makefile
@@ -8,8 +8,7 @@ S=  ${CURDIR}/../../../..
 # Override normal settings
 #
 
-CLEANFILES=machine ffs.fth.h \
-   bootblk.text bootblk.text.tmp -.d
+CLEANFILES=machine ffs.fth.h -.d
 
 PROG=  bootblk
 SRCS=
@@ -26,27 +25,12 @@ CPPFLAGS=   ${INCLUDES} ${IDENT} ${PARAM}
@([ -h machine ] || ln -s ${.CURDIR}/../../include machine)
 .endif
 
-all: bootblk.text
-
 ffs.fth.h: ${.CURDIR}/genassym.sh genfth.cf
sh ${.CURDIR}/genassym.sh -f ${CC} ${CFLAGS} ${CPPFLAGS} ${PROF} \
< ${.CURDIR}/genfth.cf >ffs.fth.h.tmp && \
mv -f ffs.fth.h.tmp ffs.fth.h
 
-bootblk.text: bootblk.fth ffs.fth.h
-   awk '/fload/ { print "#include \"" $$2 "\"" }; !/fload/' \
-   ${.CURDIR}/bootblk.fth | /usr/bin/cpp -P > bootblk.text.tmp && \
-   mv -f bootblk.text.tmp bootblk.text
-
 bootblk: bootblk.fth ffs.fth.h
fgen -o bootblk ${.CURDIR}/bootblk.fth
 
-#
-# The following are if you grab the fakeboot program from the Sun website
-#
-
-fake: bootblk bootblk.text
-   ../fakeboot/fakeboot -elf32 /bootblk
-   ../fakeboot/fakeboot -elf32 /bootblk.text
-
 .include 



sparc64: bootblk: let bsd.prog.mk do the work

2022-10-12 Thread Klemens Nanni
 sets up CLEANFILES, build/install targets and more, so no
need to roll them ourselves if we just set PROG and SRCS.

STRIPFLAG is defined but not used and in  INSTALL_STRIP is
the magic word, so fix that.

Don't replace "bootblk" wth "${PROG}" to avoid churn.


No object change, `make' does exactly the same, `make install' got more
explicit:
-install -c -o root -g bin -m 644  bootblk /usr/mdec
+install -c   -o root -g bin  -m 644 bootblk /usr/mdec/bootblk

Feedback? OK?

diff --git a/sys/arch/sparc64/stand/bootblk/Makefile 
b/sys/arch/sparc64/stand/bootblk/Makefile
index 2c4d2589ce6..f544c6508ed 100644
--- a/sys/arch/sparc64/stand/bootblk/Makefile
+++ b/sys/arch/sparc64/stand/bootblk/Makefile
@@ -9,10 +9,12 @@ S=${CURDIR}/../../../..
 #
 
 CLEANFILES=machine ffs.fth.h \
-   bootblk bootblk.text bootblk.text.tmp -.d
+   bootblk.text bootblk.text.tmp -.d
 
+PROG=  bootblk
+SRCS=
 NOMAN=
-STRIPFLAG=
+INSTALL_STRIP=
 BINMODE=644
 
 INCLUDES=  -I. -I$S/arch -I$S -nostdinc
@@ -24,7 +26,7 @@ CPPFLAGS= ${INCLUDES} ${IDENT} ${PARAM}
@([ -h machine ] || ln -s ${.CURDIR}/../../include machine)
 .endif
 
-all: bootblk.text bootblk
+all: bootblk.text
 
 ffs.fth.h: ${.CURDIR}/genassym.sh genfth.cf
sh ${.CURDIR}/genassym.sh -f ${CC} ${CFLAGS} ${CPPFLAGS} ${PROF} \
@@ -39,10 +41,6 @@ bootblk.text: bootblk.fth ffs.fth.h
 bootblk: bootblk.fth ffs.fth.h
fgen -o bootblk ${.CURDIR}/bootblk.fth
 
-beforeinstall:
-   ${INSTALL} ${INSTALL_COPY} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
-   bootblk ${DESTDIR}/usr/mdec
-
 #
 # The following are if you grab the fakeboot program from the Sun website
 #



Re: make.1: sync variable substitution bits with NetBSD

2022-10-12 Thread Omar Polo
On 2022/10/12 10:45:49 +, Klemens Nanni  wrote:
> Anyone willing to OK either the previous NetBSD/FreeBSD sync diff or the
> following minimal one which just mentions missing types?
> 
> We can always improve from there, but being stuck at an incomplete and
> thus misleading manual sucks.

agreed, and fwiw i think it's important to document when variable
substitution occurs.  ok for me, but please fix the typo:

> Index: make.1
> ===
> RCS file: /cvs/src/usr.bin/make/make.1,v
> retrieving revision 1.131
> diff -u -p -r1.131 make.1
> --- make.126 Jan 2020 12:40:50 -  1.131
> +++ make.130 Dec 2020 17:36:54 -
> @@ -600,9 +600,9 @@ If the variable name contains only a sin
>  braces or parentheses are not required.
>  This shorter form is not recommended.
>  .Pp
> -Variable substitution occurs at two distinct times, depending on where
> -the variable is being used.
> -Variables in dependency lines are expanded as the line is read.
> +Variable substitution occurs at distinct times, depending on the type of 
> line.
> +Variables in dependency lines, conditinal directives and include statements 
> are
  ^^

> +expanded as the line is read.
>  Variables in shell commands are expanded when the shell command is
>  executed.
>  .Pp




Re: EFI runtime services support on amd64

2022-10-12 Thread Mark Kettenis
> From: Dave Voutila 
> Date: Mon, 10 Oct 2022 14:08:57 -0400
> 
> Mark Kettenis  writes:
> 
> > Here is a diff that implements EFI runtime services support on amd64
> > in much the same way as we already do on arm64.  This will be used in
> > the future to implement support for EFI variables.
> >
> > Some initial testing among OpenBSD developers did not uncover any
> > issues.  So I'd like to move ahead with this.  If this ends up
> > breaking machines we can always disable the
> >
> > ok?
> 
> Tests fine on my Go3 and X13gen1. Code looks ok to me but 2 little nits
> below:
> 
> >
> >
> > Index: arch/amd64/amd64/bios.c
> > ===
> > RCS file: /cvs/src/sys/arch/amd64/amd64/bios.c,v
> > retrieving revision 1.45
> > diff -u -p -r1.45 bios.c
> > --- arch/amd64/amd64/bios.c 21 Feb 2022 11:03:39 -  1.45
> > +++ arch/amd64/amd64/bios.c 8 Oct 2022 16:07:02 -
> > @@ -30,6 +30,7 @@
> >  #include 
> >
> >  #include "acpi.h"
> > +#include "efi.h"
> >  #include "mpbios.h"
> >  #include "pci.h"
> >
> > @@ -189,6 +190,18 @@ out:
> > break;
> > }
> > }
> > +
> > +#if NEFI > 0
> > +   if (bios_efiinfo != NULL) {
> > +   struct bios_attach_args ba;
> > +
> > +   memset(, 0, sizeof(ba));
> > +   ba.ba_name = "efi";
> > +   ba.ba_memt = X86_BUS_SPACE_MEM;
> > +
> > +   config_found(self, , bios_print);
> > +   }
> > +#endif
> >
> >  #if NACPI > 0
> > {
> > Index: arch/amd64/amd64/efi_machdep.c
> > ===
> > RCS file: arch/amd64/amd64/efi_machdep.c
> > diff -N arch/amd64/amd64/efi_machdep.c
> > --- /dev/null   1 Jan 1970 00:00:00 -
> > +++ arch/amd64/amd64/efi_machdep.c  8 Oct 2022 16:07:02 -
> > @@ -0,0 +1,296 @@
> > +/* $OpenBSD$   */
> > +
> > +/*
> > + * Copyright (c) 2022 Mark Kettenis 
> > + *
> > + * Permission to use, copy, modify, and distribute this software for any
> > + * purpose with or without fee is hereby granted, provided that the above
> > + * copyright notice and this permission notice appear in all copies.
> > + *
> > + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
> > + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
> > + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
> > + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
> > + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
> > + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
> > + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
> > + */
> > +
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +
> > +#include 
> > +
> > +#include 
> > +extern paddr_t cr3_reuse_pcid;
> > +
> > +#include 
> > +
> > +#include 
> > +
> > +extern todr_chip_handle_t todr_handle;
> > +
> > +extern EFI_MEMORY_DESCRIPTOR *mmap;
> > +
> > +struct efi_softc {
> > +   struct device   sc_dev;
> > +   struct pmap *sc_pm;
> > +   EFI_RUNTIME_SERVICES *sc_rs;
> > +   u_long  sc_psw;
> > +   uint64_tsc_cr3;
> > +
> > +   struct todr_chip_handle sc_todr;
> > +};
> > +
> > +intefi_match(struct device *, void *, void *);
> > +void   efi_attach(struct device *, struct device *, void *);
> > +
> > +const struct cfattach efi_ca = {
> > +   sizeof(struct efi_softc), efi_match, efi_attach
> > +};
> > +
> > +struct cfdriver efi_cd = {
> > +   NULL, "efi", DV_DULL
> > +};
> > +
> > +void   efi_map_runtime(struct efi_softc *);
> > +void   efi_enter(struct efi_softc *);
> > +void   efi_leave(struct efi_softc *);
> > +intefi_gettime(struct todr_chip_handle *, struct timeval *);
> > +intefi_settime(struct todr_chip_handle *, struct timeval *);
> > +
> > +int
> > +efi_match(struct device *parent, void *match, void *aux)
> > +{
> > +   struct bios_attach_args *ba = aux;
> > +   struct cfdata *cf = match;
> > +
> > +   if (strcmp(ba->ba_name, cf->cf_driver->cd_name) == 0 &&
> > +   bios_efiinfo->system_table != 0)
> > +   return 1;
> > +
> > +   return 0;
> > +}
> > +
> > +void
> > +efi_attach(struct device *parent, struct device *self, void *aux)
> > +{
> > +   struct efi_softc *sc = (struct efi_softc *)self;
> > +   struct bios_attach_args *ba = aux;
> > +   uint32_t mmap_desc_ver = bios_efiinfo->mmap_desc_ver;
> > +   uint64_t system_table;
> > +   bus_space_handle_t memh;
> > +   EFI_SYSTEM_TABLE *st;
> > +   EFI_TIME time;
> > +   EFI_STATUS status;
> > +   uint16_t major, minor;
> > +   int i;
> > +
> > +   if (mmap_desc_ver != EFI_MEMORY_DESCRIPTOR_VERSION) {
> > +   printf(": unsupported memory descriptor version %d\n",
> > +   mmap_desc_ver);
> > +   return;
> > +   }
> > +
> > +   system_table = bios_efiinfo->system_table;
> > +   KASSERT(system_table);
> > +

Re: vmd: remove the user quota tracking

2022-10-12 Thread Dave Voutila


1 week bump for the below. If you use this feature or currently hacking
on it, speak up by end of week. I'm sharpening my axes.

Dave Voutila  writes:

> Matthew Martin recently presented a patch on tech@ [1] fixing some missed
> scaling from when I converted vmd(8) to use bytes instead of megabytes
> everywhere. I finally found time to wade through the code it touches and
> am proposing we simply "tedu" the incomplete feature.
>
> Does anyone use this? (And if so, how?)
>
> I don't see much value in this framework and it only adds additional
> state to track. Users can be confined by limits associated in
> login.conf(5) for the most part. There are more interesting things to
> work on, so unless anyone speaks up I'll look for an OK to remove it.
>
> -dv
>
> [1] https://marc.info/?l=openbsd-tech=166346196317673=2
>
>
> diff refs/heads/master refs/heads/vmd-user
> commit - bfe2092d87b190d9f89c4a6f2728a539b7f88233
> commit + e84ff2c7628a811e00044a447ad906d6e24beac0
> blob - 374d7de6629e072065b5c0232536c23c1e5bbbe0
> blob + a192223cf118e2a8764b24f965a15acbf8ae506f
> --- usr.sbin/vmd/config.c
> +++ usr.sbin/vmd/config.c
> @@ -98,12 +98,6 @@ config_init(struct vmd *env)
>   return (-1);
>   TAILQ_INIT(env->vmd_switches);
>   }
> - if (what & CONFIG_USERS) {
> - if ((env->vmd_users = calloc(1,
> - sizeof(*env->vmd_users))) == NULL)
> - return (-1);
> - TAILQ_INIT(env->vmd_users);
> - }
>
>   return (0);
>  }
> @@ -238,13 +232,6 @@ config_setvm(struct privsep *ps, struct vmd_vm *vm, ui
>   return (EALREADY);
>   }
>
> - /* increase the user reference counter and check user limits */
> - if (vm->vm_user != NULL && user_get(vm->vm_user->usr_id.uid) != NULL) {
> - user_inc(vcp, vm->vm_user, 1);
> - if (user_checklimit(vm->vm_user, vcp) == -1)
> - return (EPERM);
> - }
> -
>   /*
>* Rate-limit the VM so that it cannot restart in a loop:
>* if the VM restarts after less than VM_START_RATE_SEC seconds,
> blob - 2f3ac1a76f2c3e458919eca85c238a668c10422a
> blob + 755cbedb6a18502a87724502ec86e9e426961701
> --- usr.sbin/vmd/vmd.c
> +++ usr.sbin/vmd/vmd.c
> @@ -1188,9 +1188,6 @@ vm_stop(struct vmd_vm *vm, int keeptty, const char *ca
>   vm->vm_state &= ~(VM_STATE_RECEIVED | VM_STATE_RUNNING
>   | VM_STATE_SHUTDOWN);
>
> - user_inc(>vm_params.vmc_params, vm->vm_user, 0);
> - user_put(vm->vm_user);
> -
>   if (vm->vm_iev.ibuf.fd != -1) {
>   event_del(>vm_iev.ev);
>   close(vm->vm_iev.ibuf.fd);
> @@ -1243,7 +1240,6 @@ vm_remove(struct vmd_vm *vm, const char *caller)
>
>   TAILQ_REMOVE(env->vmd_vms, vm, vm_entry);
>
> - user_put(vm->vm_user);
>   vm_stop(vm, 0, caller);
>   free(vm);
>  }
> @@ -1286,7 +1282,6 @@ vm_register(struct privsep *ps, struct vmop_create_par
>   struct vmd_vm   *vm = NULL, *vm_parent = NULL;
>   struct vm_create_params *vcp = >vmc_params;
>   struct vmop_owner   *vmo = NULL;
> - struct vmd_user *usr = NULL;
>   uint32_t nid, rng;
>   unsigned int i, j;
>   struct vmd_switch   *sw;
> @@ -1362,13 +1357,6 @@ vm_register(struct privsep *ps, struct vmop_create_par
>   }
>   }
>
> - /* track active users */
> - if (uid != 0 && env->vmd_users != NULL &&
> - (usr = user_get(uid)) == NULL) {
> - log_warnx("could not add user");
> - goto fail;
> - }
> -
>   if ((vm = calloc(1, sizeof(*vm))) == NULL)
>   goto fail;
>
> @@ -1379,7 +1367,6 @@ vm_register(struct privsep *ps, struct vmop_create_par
>   vm->vm_tty = -1;
>   vm->vm_receive_fd = -1;
>   vm->vm_state &= ~VM_STATE_PAUSED;
> - vm->vm_user = usr;
>
>   for (i = 0; i < VMM_MAX_DISKS_PER_VM; i++)
>   for (j = 0; j < VM_MAX_BASE_PER_DISK; j++)
> @@ -1903,104 +1890,6 @@ struct vmd_user *
>   return (NULL);
>  }
>
> -struct vmd_user *
> -user_get(uid_t uid)
> -{
> - struct vmd_user *usr;
> -
> - if (uid == 0)
> - return (NULL);
> -
> - /* first try to find an existing user */
> - TAILQ_FOREACH(usr, env->vmd_users, usr_entry) {
> - if (usr->usr_id.uid == uid)
> - goto done;
> - }
> -
> - if ((usr = calloc(1, sizeof(*usr))) == NULL) {
> - log_warn("could not allocate user");
> - return (NULL);
> - }
> -
> - usr->usr_id.uid = uid;
> - usr->usr_id.gid = -1;
> - TAILQ_INSERT_TAIL(env->vmd_users, usr, usr_entry);
> -
> - done:
> - DPRINTF("%s: uid %d #%d +",
> - __func__, usr->usr_id.uid, usr->usr_refcnt + 1);
> - usr->usr_refcnt++;
> -
> - return (usr);
> -}
> -
> -void
> -user_put(struct vmd_user *usr)
> -{
> - if (usr == NULL)
> - return;
> -
> - DPRINTF("%s: uid 

Re: em(4) IPv4, TCP, UDP checksum offloading

2022-10-12 Thread Moritz Buhl
Another mistake

On Wed, Oct 12, 2022 at 01:45:30PM +0200, Moritz Buhl wrote:
> On Tue, Oct 11, 2022 at 04:16:15PM +0100, Stuart Henderson wrote:
> > On 2022/10/11 15:03, Moritz Buhl wrote:
> > > Here is a new diff for checksum offloading (ipv4, udp, tcp) for em(4).
> > > 
> > > The previous diff didn't implement hardware vlan tagging for >em82578
> > > which should result in variable ethernet header lengths and thus
> > > wrong checksums inserted at wrong places.
> > > 
> > > The diff below addresses this.
> > > I would appreciate further testing reports with different controllers.
> > > 
> > > mbuhl
> > 
> > I tried this on my laptop which has I219-V em (I run it in a trunk
> > with iwm). It breaks tx (packets don't show up on the other side).
> > rx seems ok.
> 
> The following diff will restrict the usage of the advanced 
> descriptors to 82575, 82576, i350 and i210, and fix what the
> last diff broke for i219.
> 
> Index: dev/pci/if_em.c
> ===
> RCS file: /cvs/src/sys/dev/pci/if_em.c,v
> retrieving revision 1.362
> diff -u -p -r1.362 if_em.c
> --- dev/pci/if_em.c   23 Jun 2022 09:38:28 -  1.362
> +++ dev/pci/if_em.c   11 Oct 2022 16:05:43 -
> @@ -37,6 +37,8 @@ POSSIBILITY OF SUCH DAMAGE.
>  #include 
>  #include 
>  
> +#include 
> +
>  /*
>   *  Driver version
>   */
> @@ -278,6 +280,8 @@ void em_receive_checksum(struct em_softc
>struct mbuf *);
>  u_intem_transmit_checksum_setup(struct em_queue *, struct mbuf *, 
> u_int,
>   u_int32_t *, u_int32_t *);
> +u_intem_tx_ctx_setup(struct em_queue *, struct mbuf *, u_int, 
> u_int32_t *,
> + u_int32_t *);
>  void em_iff(struct em_softc *);
>  void em_update_link_status(struct em_softc *);
>  int  em_get_buf(struct em_queue *, int);
> @@ -1220,10 +1224,9 @@ em_encap(struct em_queue *que, struct mb
>   BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE);
>   }
>  
> - if (sc->hw.mac_type >= em_82543 && sc->hw.mac_type != em_82575 &&
> - sc->hw.mac_type != em_82576 &&
> - sc->hw.mac_type != em_82580 && sc->hw.mac_type != em_i210 &&
> - sc->hw.mac_type != em_i350) {
> + if (sc->hw.mac_type >= em_82575 && sc->hw.mac_type <= em_i210) {
> + used += em_tx_ctx_setup(que, m, head, _upper, _lower);
> + } else if (sc->hw.mac_type >= em_82543) {
>   used += em_transmit_checksum_setup(que, m, head,
>   _upper, _lower);
>   } else {
> @@ -1278,7 +1281,7 @@ em_encap(struct em_queue *que, struct mb
>  
>  #if NVLAN > 0
>   /* Find out if we are in VLAN mode */
> - if (m->m_flags & M_VLANTAG) {
> + if (m->m_flags & M_VLANTAG && sc->hw.mac_type < em_82575) {

I missed this spot, it should be
if (m->m_flags & M_VLANTAG && (sc->hw.mac_type < em_82575 ||
sc->hw.mac_type > em_i210)) {




Re: em(4) IPv4, TCP, UDP checksum offloading

2022-10-12 Thread Moritz Buhl
On Tue, Oct 11, 2022 at 04:16:15PM +0100, Stuart Henderson wrote:
> On 2022/10/11 15:03, Moritz Buhl wrote:
> > Here is a new diff for checksum offloading (ipv4, udp, tcp) for em(4).
> > 
> > The previous diff didn't implement hardware vlan tagging for >em82578
> > which should result in variable ethernet header lengths and thus
> > wrong checksums inserted at wrong places.
> > 
> > The diff below addresses this.
> > I would appreciate further testing reports with different controllers.
> > 
> > mbuhl
> 
> I tried this on my laptop which has I219-V em (I run it in a trunk
> with iwm). It breaks tx (packets don't show up on the other side).
> rx seems ok.

The following diff will restrict the usage of the advanced 
descriptors to 82575, 82576, i350 and i210, and fix what the
last diff broke for i219.

Index: dev/pci/if_em.c
===
RCS file: /cvs/src/sys/dev/pci/if_em.c,v
retrieving revision 1.362
diff -u -p -r1.362 if_em.c
--- dev/pci/if_em.c 23 Jun 2022 09:38:28 -  1.362
+++ dev/pci/if_em.c 11 Oct 2022 16:05:43 -
@@ -37,6 +37,8 @@ POSSIBILITY OF SUCH DAMAGE.
 #include 
 #include 
 
+#include 
+
 /*
  *  Driver version
  */
@@ -278,6 +280,8 @@ void em_receive_checksum(struct em_softc
 struct mbuf *);
 u_int  em_transmit_checksum_setup(struct em_queue *, struct mbuf *, u_int,
u_int32_t *, u_int32_t *);
+u_int  em_tx_ctx_setup(struct em_queue *, struct mbuf *, u_int, u_int32_t *,
+   u_int32_t *);
 void em_iff(struct em_softc *);
 void em_update_link_status(struct em_softc *);
 int  em_get_buf(struct em_queue *, int);
@@ -1220,10 +1224,9 @@ em_encap(struct em_queue *que, struct mb
BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE);
}
 
-   if (sc->hw.mac_type >= em_82543 && sc->hw.mac_type != em_82575 &&
-   sc->hw.mac_type != em_82576 &&
-   sc->hw.mac_type != em_82580 && sc->hw.mac_type != em_i210 &&
-   sc->hw.mac_type != em_i350) {
+   if (sc->hw.mac_type >= em_82575 && sc->hw.mac_type <= em_i210) {
+   used += em_tx_ctx_setup(que, m, head, _upper, _lower);
+   } else if (sc->hw.mac_type >= em_82543) {
used += em_transmit_checksum_setup(que, m, head,
_upper, _lower);
} else {
@@ -1278,7 +1281,7 @@ em_encap(struct em_queue *que, struct mb
 
 #if NVLAN > 0
/* Find out if we are in VLAN mode */
-   if (m->m_flags & M_VLANTAG) {
+   if (m->m_flags & M_VLANTAG && sc->hw.mac_type < em_82575) {
/* Set the VLAN id */
desc->upper.fields.special = htole16(m->m_pkthdr.ether_vtag);
 
@@ -1964,17 +1967,14 @@ em_setup_interface(struct em_softc *sc)
ifp->if_capabilities = IFCAP_VLAN_MTU;
 
 #if NVLAN > 0
-   if (sc->hw.mac_type != em_82575 && sc->hw.mac_type != em_82580 &&
-   sc->hw.mac_type != em_82576 &&
-   sc->hw.mac_type != em_i210 && sc->hw.mac_type != em_i350)
-   ifp->if_capabilities |= IFCAP_VLAN_HWTAGGING;
+   ifp->if_capabilities |= IFCAP_VLAN_HWTAGGING;
 #endif
 
-   if (sc->hw.mac_type >= em_82543 && sc->hw.mac_type != em_82575 &&
-   sc->hw.mac_type != em_82576 &&
-   sc->hw.mac_type != em_82580 && sc->hw.mac_type != em_i210 &&
-   sc->hw.mac_type != em_i350)
+   if (sc->hw.mac_type >= em_82543) {
+   ifp->if_capabilities |= IFCAP_CSUM_IPv4;
ifp->if_capabilities |= IFCAP_CSUM_TCPv4 | IFCAP_CSUM_UDPv4;
+   ifp->if_capabilities |= IFCAP_CSUM_TCPv6 | IFCAP_CSUM_UDPv6;
+   }
 
/* 
 * Specify the media types supported by this adapter and register
@@ -2391,6 +2391,108 @@ em_free_transmit_structures(struct em_so
}
 }
 
+u_int
+em_tx_ctx_setup(struct em_queue *que, struct mbuf *mp, u_int head,
+u_int32_t *olinfo_status, u_int32_t *cmd_type_len)
+{
+   struct e1000_adv_tx_context_desc *TD;
+   struct ether_header *eh = mtod(mp, struct ether_header *);
+   struct mbuf *m;
+   uint32_t vlan_macip_lens = 0, type_tucmd_mlhl = 0, mss_l4len_idx = 0;
+   int off = 0, hoff;
+   uint8_t ipproto, iphlen;
+
+   *olinfo_status = 0;
+   *cmd_type_len = 0;
+   TD = (struct e1000_adv_tx_context_desc *)>tx.sc_tx_desc_ring[head];
+   
+#if NVLAN > 0
+   if (ISSET(mp->m_flags, M_VLANTAG)) {
+   uint16_t vtag = htole16(mp->m_pkthdr.ether_vtag);
+   vlan_macip_lens |= vtag << E1000_ADVTXD_VLAN_SHIFT;
+   *cmd_type_len |= E1000_ADVTXD_DCMD_VLE;
+   off = 1;
+   }
+#endif
+
+   vlan_macip_lens |= (sizeof(*eh) << E1000_ADVTXD_MACLEN_SHIFT);
+   
+   switch (ntohs(eh->ether_type)) {
+   case ETHERTYPE_IP: {
+   struct ip *ip;
+
+   m = 

Re: make.1: sync variable substitution bits with NetBSD

2022-10-12 Thread Klemens Nanni
On Sat, Nov 13, 2021 at 10:09:27AM +, Klemens Nanni wrote:
> On Sat, Dec 26, 2020 at 05:19:55PM +0100, Klemens Nanni wrote:
> > Our make(1) is behind NetBSD's and FreeBSD's make(1) on at least the
> > rules of variable substitution.
> > 
> > Our DESCRIPION says
> > 
> >  There are seven different types of lines in a makefile: dependency 
> > lines,
> >  shell commands, variable assignments, include statements, conditional
> >  directives, for loops, and comments.  Of these, include statements,
> >  conditional directives and for loops are extensions.
> > 
> > but our VARIABLES merely explains
> > 
> >  Variable substitution occurs at two distinct times, depending on where
> >  the variable is being used.  Variables in dependency lines are expanded
> >  as the line is read.  Variables in shell commands are expanded when the
> >  shell command is executed.
> > 
> > and therefore fails to explain behaviour for the other five line types.
> > 
> > 
> > http://man.netbsd.org/make.1#VARIABLE%20ASSIGNMENTS (same as FreeBSD in
> > this regard) does go into more detail here:
> > 
> > Variable substitution occurs at three distinct times, depending on where
> >  the variable is being used.
> > 
> >  1.   Variables in dependency lines are expanded as the line is 
> > read.
> > 
> >  2.   Variables in shell commands are expanded when the shell 
> > command is
> >   executed.
> > 
> >  3.   ``.for'' loop index variables are expanded on each loop 
> > iteration.
> >   Note that other variables are not expanded inside loops so 
> > the fol-
> >   lowing example code:
> > 
> >   [...]
> > 
> > 
> > Diff below sync this list in VARIABLES as is.
> > 
> > After that I'd like to expand it and explain behaviour for other types;
> > I've scratched my head on make's behaviour for too long and the manual
> > failed to cover this completely.
> > 
> > Feedback? OK?
> 
> I came across this again, so I would really like to fix our manual.

The sparc64 ofwboot libz dependency bug reminded me of our make(1) still
missing different cases of variable expansion.

> In https://marc.info/?l=openbsd-tech=160935207004852=2
> on 2020-12-30 espie said:
> > I do think we want to write something specific for .for loop variables
> > which are actually very special compared to the rest.
> > 
> > I'm not incredibly happy with the way netbsd explains it, not surprisingly.
> 
> which didn't result in any update to our manual.
> 
> I'm still in favour of syncing with NetBSD (first), they're wording and
> example explains the missing pieces.
> 
> We can gladly polish things afterwards if someone comes up with
> something better.
> 
> OK?

No feedback whatsoever.

Anyone willing to OK either the previous NetBSD/FreeBSD sync diff or the
following minimal one which just mentions missing types?

We can always improve from there, but being stuck at an incomplete and
thus misleading manual sucks.


Index: make.1
===
RCS file: /cvs/src/usr.bin/make/make.1,v
retrieving revision 1.131
diff -u -p -r1.131 make.1
--- make.1  26 Jan 2020 12:40:50 -  1.131
+++ make.1  30 Dec 2020 17:36:54 -
@@ -600,9 +600,9 @@ If the variable name contains only a sin
 braces or parentheses are not required.
 This shorter form is not recommended.
 .Pp
-Variable substitution occurs at two distinct times, depending on where
-the variable is being used.
-Variables in dependency lines are expanded as the line is read.
+Variable substitution occurs at distinct times, depending on the type of line.
+Variables in dependency lines, conditinal directives and include statements are
+expanded as the line is read.
 Variables in shell commands are expanded when the shell command is
 executed.
 .Pp



macppc: stand: remove powerpc left-overs

2022-10-12 Thread Klemens Nanni
There since the powerpc -> macppc move/rename.

KERN_AS   usage disappeared in
commit 5b7db11d478192c5908038bb1345e7d51cc35c8e
Author: rahnds 
Date:   Mon May 5 16:47:15 1997 +

only build one version of the libraries.

REAL_VIRT usage disappeared in
commit 08e027d6bb9ca863bfc44a1aa6957ff3a242e2f4
Author: rahnds 
Date:   Thu Apr 27 12:36:29 2000 +

Fixes to xcoff bootloader to allow it to execute and load kernels for 
OpenBSD.

Make agrees that these are defined but not used:

$ make -p| grep -e KERN_AS -e REAL_VIRT
KERN_AS  = library
REAL_VIRT= -v
$ make -C ofwboot -p | grep -e KERN_AS -e REAL_VIRT
KERN_AS  = library
REAL_VIRT= -v

No object change.
OK?


Index: sys/arch/macppc/stand/Makefile.inc
===
RCS file: /cvs/src/sys/arch/macppc/stand/Makefile.inc,v
retrieving revision 1.13
diff -u -p -r1.13 Makefile.inc
--- sys/arch/macppc/stand/Makefile.inc  6 Nov 2016 16:04:20 -   1.13
+++ sys/arch/macppc/stand/Makefile.inc  12 Oct 2022 10:08:14 -
@@ -4,8 +4,6 @@
 .if !defined(__stand_makefile_inc)
 __stand_makefile_inc=1
 
-KERN_AS=   library
-
 S=$(.CURDIR)/../../../$(R)
 
 .if !make(clean) && !make(cleandir) && !make(includes) && !make(libdep) && \
@@ -16,7 +14,6 @@ S=$(.CURDIR)/../../../$(R)
 
 #
 EXTRACFLAGS=   -msoft-float
-REAL_VIRT?=-v
 ENTRY?=_start
 
 INCLUDES+= -I. -I$(.OBJDIR) -I$(.CURDIR)/.. -I$(S)/arch -I$(S)



Re: bgpctl openmetric/prometheus output

2022-10-12 Thread Theo Buehler
On Fri, Oct 07, 2022 at 12:37:10PM +0200, Claudio Jeker wrote:
> This diff adds `bgpctl show metric` which is a command that dumps some
> stats out in openmetric format. This format can be ingested by e.g.
> prometheus and used for monitoring.
> 
> The openmetric handling is in ometric.[ch]. It is fairly basic and not
> intended for long running processes. There is a struct ometric (which is
> one individual metric point). This metric point can have many different
> values with each value including an optional set of labels. Since the
> labels are used over and over again, I used a refcount on them.
> Also since most strings used in these functions are string literals I also
> don't copy them. Only the values of labels are copied since those are
> for example per peer.
> 
> Using a small extra diff in bgplgd I can export the metrics into
> prometheus and visualize them with grafana.
> 
> Consider this an MVP that can be extended with all the infos we want.

This looks pretty good to me. I like the approach and I couldn't spot
anything really wrong with it.

Some very minor comments inline for your consideration.

> -- 
> :wq Claudio
> 
> Index: Makefile
> ===
> RCS file: /cvs/src/usr.sbin/bgpctl/Makefile,v
> retrieving revision 1.17
> diff -u -p -r1.17 Makefile
> --- Makefile  2 May 2020 14:33:33 -   1.17
> +++ Makefile  27 Sep 2022 15:50:40 -
> @@ -3,7 +3,8 @@
>  .PATH:   ${.CURDIR}/../bgpd
>  
>  PROG=bgpctl
> -SRCS=bgpctl.c output.c output_json.c parser.c mrtparser.c util.c 
> json.c
> +SRCS=bgpctl.c output.c output_json.c output_ometric.c parser.c \
> + mrtparser.c util.c json.c ometric.c
>  CFLAGS+= -Wall
>  CFLAGS+= -Wstrict-prototypes -Wmissing-prototypes
>  CFLAGS+= -Wmissing-declarations
> Index: bgpctl.c
> ===
> RCS file: /cvs/src/usr.sbin/bgpctl/bgpctl.c,v
> retrieving revision 1.283
> diff -u -p -r1.283 bgpctl.c
> --- bgpctl.c  31 Aug 2022 15:00:53 -  1.283
> +++ bgpctl.c  25 Sep 2022 08:35:43 -
> @@ -79,7 +79,7 @@ int
>  main(int argc, char *argv[])
>  {
>   struct sockaddr_un   sa_un;
> - int  fd, n, done, ch, verbose = 0;
> + int  fd, n, done, numdone, ch, verbose = 0;
>   struct imsg  imsg;
>   struct network_confignet;
>   struct parse_result *res;
> @@ -256,6 +256,12 @@ main(int argc, char *argv[])
>   case SHOW_RIB_MEM:
>   imsg_compose(ibuf, IMSG_CTL_SHOW_RIB_MEM, 0, 0, -1, NULL, 0);
>   break;
> + case SHOW_METRIC:
> + output = _output;
> + numdone = 2;
> + imsg_compose(ibuf, IMSG_CTL_SHOW_NEIGHBOR, 0, 0, -1, NULL, 0);
> + imsg_compose(ibuf, IMSG_CTL_SHOW_RIB_MEM, 0, 0, -1, NULL, 0);
> + break;
>   case RELOAD:
>   imsg_compose(ibuf, IMSG_CTL_RELOAD, 0, 0, -1,
>   res->reason, sizeof(res->reason));
> @@ -366,18 +372,14 @@ main(int argc, char *argv[])
>   break;
>   }
>  
> + output->head(res);
> +
> + again:
>   while (ibuf->w.queued)
> - if (msgbuf_write(>w) <= 0 && errno != EAGAIN)
> + if (msgbuf_write(>w) <= 0)
>   err(1, "write error");
>  
> - output->head(res);
> -
>   while (!done) {
> - if ((n = imsg_read(ibuf)) == -1 && errno != EAGAIN)
> - err(1, "imsg_read error");
> - if (n == 0)
> - errx(1, "pipe closed");
> -
>   while (!done) {
>   if ((n = imsg_get(ibuf, )) == -1)
>   err(1, "imsg_get error");
> @@ -387,6 +389,20 @@ main(int argc, char *argv[])
>   done = show(, res);
>   imsg_free();
>   }
> +
> + if (done)
> + break;
> +
> + if ((n = imsg_read(ibuf)) == -1)
> + err(1, "imsg_read error");
> + if (n == 0)
> + errx(1, "pipe closed");
> +
> + }
> +
> + if (res->action == SHOW_METRIC && --numdone > 0) {
> + done = 0;
> + goto again;
>   }
>  
>   output->tail();
> @@ -416,21 +432,29 @@ show(struct imsg *imsg, struct parse_res
>  
>   switch (imsg->hdr.type) {
>   case IMSG_CTL_SHOW_NEIGHBOR:
> + if (output->neighbor == NULL)
> + break;
>   p = imsg->data;
>   output->neighbor(p, res);
>   break;
>   case IMSG_CTL_SHOW_TIMER:
>   if (imsg->hdr.len < IMSG_HEADER_SIZE + sizeof(t))
>   errx(1, "wrong imsg len");
> + if (output->timer == NULL)
> + break;
>   memcpy(, imsg->data, sizeof(t));
>   if (t.type > 0 && t.type < Timer_Max)
>   

macppc: ofwboot: fix -Wreturn-type

2022-10-12 Thread Klemens Nanni
.../ofdev.c:130:1: warning: non-void function does not return a value 
[-Wreturn-type]

OK?

Index: sys/arch/macppc/stand/ofdev.c
===
RCS file: /cvs/src/sys/arch/macppc/stand/ofdev.c,v
retrieving revision 1.27
diff -u -p -r1.27 ofdev.c
--- sys/arch/macppc/stand/ofdev.c   5 Sep 2022 10:03:50 -   1.27
+++ sys/arch/macppc/stand/ofdev.c   12 Oct 2022 09:11:58 -
@@ -127,6 +127,7 @@ devclose(struct open_file *of)
 
OF_close(op->handle);
free(op, sizeof *op);
+   return 0;
 }
 
 struct devsw devsw[1] = {



Re: [acpi] patch for embedded controller detection

2022-10-12 Thread Mikhail
On Sat, Oct 08, 2022 at 03:10:18PM +0300, Mikhail wrote:
> I'm troubleshooting battery status for my Lenovo IdeaPad 3 14ITL05, on
> latest -current it shows that battery is absent and AC not connected:
> 
> Battery state: absent, 0% remaining, unknown life estimate
> AC adapter state: not connected
> Performance adjustment mode: manual (2900 MHz)

I'm still digging for this. 

Currently I don't understand why there have to be two acpiec devices
(see dmesg in previous mail - one acpiec0 and second "acpiec not
configured", or acpiec1 in patched version), while ASL has only one -
EC0, and having two ECs simply makes no sense. It brought me to match
logic of auto configuration for EC, with inlined patch I'm also able to
see battery status:

Battery state: high, 95% remaining, 178 minutes life estimate
AC adapter state: not connected
Performance adjustment mode: manual (2900 MHz)

This attempt is mostly for archive purpose and in hope, if anyone more
skilled may have immediate thought about the problem.

diff /usr/src
commit - 49f1cedec1baee518af868485e6367f5118073da
path + /usr/src
blob - 5ef24d5179de52d5321e578b3b73dd9524e7c1de
file + sys/dev/acpi/acpiec.c
--- sys/dev/acpi/acpiec.c
+++ sys/dev/acpi/acpiec.c
@@ -255,13 +255,8 @@ acpiec_match(struct device *parent, void *match, void 
 {
struct acpi_attach_args *aa = aux;
struct cfdata   *cf = match;
-   struct acpi_ecdt*ecdt = aa->aaa_table;
struct acpi_softc   *acpisc = (struct acpi_softc *)parent;
 
-   /* Check for early ECDT table attach */
-   if (ecdt && 
-   !memcmp(ecdt->hdr.signature, ECDT_SIG, sizeof(ECDT_SIG) - 1))
-   return (1);
if (acpisc->sc_ec)
return (0);
 
dmesg with the patch (now only one acpiec device):

OpenBSD 7.2-current (GENERIC.MP) #21: Wed Oct 12 09:06:10 MSK 2022
mi...@idea.lab.local:/sys/arch/amd64/compile/GENERIC.MP
real mem = 8363110400 (7975MB)
avail mem = 8092250112 (7717MB)
random: good seed from bootblocks
mpath0 at root
scsibus0 at mpath0: 256 targets
mainbus0 at root
bios0 at mainbus0: SMBIOS rev. 3.3 @ 0x439df000 (70 entries)
bios0: vendor LENOVO version "GCCN26WW" date 03/11/2022
bios0: LENOVO 81X7
acpi0 at bios0: ACPI 6.1Undefined scope: \\_SB_.PCI0

acpi0: sleep states S0 S4 S5
acpi0: tables DSDT FACP UEFI SSDT SSDT SSDT SSDT SSDT SSDT TPM2 MSDM NHLT SSDT 
LPIT WSMT SSDT SSDT DBGP DBG2 ECDT HPET APIC MCFG SSDT DMAR SSDT SSDT FPDT PTDT 
BGRT
acpi0: wakeup devices PEG0(S4) PEGP(S4) PEGP(S4) PEGP(S4) XHCI(S4) XDCI(S4) 
HDAS(S4) RP01(S4) PXSX(S4) RP02(S4) PXSX(S4) RP03(S4) PXSX(S4) RP04(S4) 
PXSX(S4) RP05(S4) [...]
acpitimer0 at acpi0: 3579545 Hz, 24 bits
acpihpet0 at acpi0: 1920 Hz
acpimadt0 at acpi0 addr 0xfee0: PC-AT compat
cpu0 at mainbus0: apid 0 (boot processor)
cpu0: 11th Gen Intel(R) Core(TM) i3-1115G4 @ 3.00GHz, 4090.57 MHz, 06-8c-01
cpu0: 
FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,DS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE,SSE3,PCLMUL,DTES64,MWAIT,DS-CPL,VMX,EST,TM2,SSSE3,SDBG,FMA3,CX16,xTPR,PDCM,PCID,SSE4.1,SSE4.2,x2APIC,MOVBE,POPCNT,DEADLINE,AES,XSAVE,AVX,F16C,RDRAND,NXE,PAGE1GB,RDTSCP,LONG,LAHF,ABM,3DNOWP,PERF,ITSC,FSGSBASE,TSC_ADJUST,BMI1,AVX2,SMEP,BMI2,ERMS,INVPCID,AVX512F,AVX512DQ,RDSEED,ADX,SMAP,AVX512IFMA,CLFLUSHOPT,CLWB,PT,AVX512CD,SHA,AVX512BW,AVX512VL,AVX512VBMI,UMIP,PKU,SRBDS_CTRL,MD_CLEAR,IBRS,IBPB,STIBP,L1DF,SSBD,SENSOR,ARAT,XSAVEOPT,XSAVEC,XGETBV1,XSAVES
cpu0: 48KB 64b/line 12-way D-cache, 32KB 64b/line 8-way I-cache, 1MB 64b/line 
20-way L2 cache, 6MB 64b/line 12-way L3 cache
cpu0: smt 0, core 0, package 0
mtrr: Pentium Pro MTRR support, 10 var ranges, 88 fixed ranges
cpu0: apic clock running at 38MHz
cpu0: mwait min=64, max=64, C-substates=0.2.0.1.2.1.1.1, IBE
cpu1 at mainbus0: apid 2 (application processor)
cpu1: 11th Gen Intel(R) Core(TM) i3-1115G4 @ 3.00GHz, 4090.58 MHz, 06-8c-01
cpu1: 
FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,DS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE,SSE3,PCLMUL,DTES64,MWAIT,DS-CPL,VMX,EST,TM2,SSSE3,SDBG,FMA3,CX16,xTPR,PDCM,PCID,SSE4.1,SSE4.2,x2APIC,MOVBE,POPCNT,DEADLINE,AES,XSAVE,AVX,F16C,RDRAND,NXE,PAGE1GB,RDTSCP,LONG,LAHF,ABM,3DNOWP,PERF,ITSC,FSGSBASE,TSC_ADJUST,BMI1,AVX2,SMEP,BMI2,ERMS,INVPCID,AVX512F,AVX512DQ,RDSEED,ADX,SMAP,AVX512IFMA,CLFLUSHOPT,CLWB,PT,AVX512CD,SHA,AVX512BW,AVX512VL,AVX512VBMI,UMIP,PKU,SRBDS_CTRL,MD_CLEAR,IBRS,IBPB,STIBP,L1DF,SSBD,SENSOR,ARAT,XSAVEOPT,XSAVEC,XGETBV1,XSAVES
cpu1: 48KB 64b/line 12-way D-cache, 32KB 64b/line 8-way I-cache, 1MB 64b/line 
20-way L2 cache, 6MB 64b/line 12-way L3 cache
cpu1: smt 0, core 1, package 0
cpu2 at mainbus0: apid 1 (application processor)
cpu2: 11th Gen Intel(R) Core(TM) i3-1115G4 @ 3.00GHz, 4090.57 MHz, 06-8c-01
cpu2: