Re: bgpd refactor rib dumping

2018-10-23 Thread Claudio Jeker
On Sun, Oct 21, 2018 at 01:51:52PM +0200, Claudio Jeker wrote:
> On Thu, Oct 18, 2018 at 02:29:17PM +0200, Claudio Jeker wrote:
> > Change the way ribs are porcessed. Currently all async dumpers have to
> > call rib_dump_r() whenever progress should be made. Also creating the
> > context for such a dump is all on the caller side. Change this to one
> > central place. Now all that is needed is to call rib_dump_new() with
> > the callbacks for upcall, done and throttled. done and throttled are
> > optional. This should solve the problem of not progressing rib_dump
> > once and for all, also it removes the sync rib_dump() function which
> > is no longer used.
> > 
> 
> Thanks to denis@ this uncovered a bigger problem in the RDE. The RIB heads
> are currently stored in an array indexed by their id. Now if new RIBs are
> added this array may be reallocated. The problem is that the a pointer to
> that struct is stored in a few places (peer, rib entries, dump contexts)
> which is bad once such are realloc happens.
> 
> I extended this diff now to solve this issue by storing the RIB ID instead
> of rib pointers in those structs. With this I no longer get the crashes by
> adding new ribs.

New version which also solves a use-after-free bug because of peer_up ->
peer_dump and hitting peer_down quickly afterwards. Found by benno@ with a
neighbor that had a to low max-prefix limit. On peer_down any possible
peer_up_dump_upcall runners need to terminated before the peer is freed.

This following diff also includes the 'show rib out nei $FOO' patch from
yesterday.
-- 
:wq Claudio

Index: mrt.c
===
RCS file: /cvs/src/usr.sbin/bgpd/mrt.c,v
retrieving revision 1.86
diff -u -p -r1.86 mrt.c
--- mrt.c   24 Jul 2018 10:10:58 -  1.86
+++ mrt.c   18 Oct 2018 11:03:36 -
@@ -673,10 +673,8 @@ mrt_dump_upcall(struct rib_entry *re, vo
 }
 
 void
-mrt_done(void *ptr)
+mrt_done(struct mrt *mrtbuf)
 {
-   struct mrt  *mrtbuf = ptr;
-
mrtbuf->state = MRT_STATE_REMOVE;
 }
 
Index: rde.c
===
RCS file: /cvs/src/usr.sbin/bgpd/rde.c,v
retrieving revision 1.438
diff -u -p -r1.438 rde.c
--- rde.c   22 Oct 2018 07:46:55 -  1.438
+++ rde.c   22 Oct 2018 21:23:24 -
@@ -69,34 +69,18 @@ void rde_update_log(const char *, u_in
 voidrde_as4byte_fixup(struct rde_peer *, struct rde_aspath *);
 voidrde_reflector(struct rde_peer *, struct rde_aspath *);
 
-voidrde_dump_rib_as(struct prefix *, struct rde_aspath *, pid_t,
-int);
-voidrde_dump_filter(struct prefix *,
-struct ctl_show_rib_request *);
-voidrde_dump_filterout(struct rde_peer *, struct prefix *,
-struct ctl_show_rib_request *);
-voidrde_dump_upcall(struct rib_entry *, void *);
-voidrde_dump_prefix_upcall(struct rib_entry *, void *);
 voidrde_dump_ctx_new(struct ctl_show_rib_request *, pid_t,
 enum imsg_type);
 voidrde_dump_ctx_throttle(pid_t pid, int throttle);
-voidrde_dump_runner(void);
-int rde_dump_pending(void);
-voidrde_dump_done(void *);
 voidrde_dump_mrt_new(struct mrt *, pid_t, int);
-voidrde_dump_rib_free(struct rib *);
-voidrde_dump_mrt_free(struct rib *);
-voidrde_rib_free(struct rib_desc *);
 
 int rde_rdomain_import(struct rde_aspath *, struct rdomain *);
 voidrde_reload_done(void);
-static void rde_reload_runner(void);
-static void rde_softreconfig_in_done(void *);
-static void rde_softreconfig_out_done(void *);
+static void rde_softreconfig_in_done(void *, u_int8_t);
+static void rde_softreconfig_out_done(void *, u_int8_t);
 static void rde_softreconfig_done(void);
 static void rde_softreconfig_out(struct rib_entry *, void *);
 static void rde_softreconfig_in(struct rib_entry *, void *);
-voidrde_up_dump_upcall(struct rib_entry *, void *);
 voidrde_update_queue_runner(void);
 voidrde_update6_queue_runner(u_int8_t);
 struct rde_prefixset *rde_find_prefixset(char *, struct rde_prefixset_head *);
@@ -146,7 +130,6 @@ int  softreconfig;
 
 struct rde_dump_ctx {
LIST_ENTRY(rde_dump_ctx)entry;
-   struct rib_context  ribctx;
struct ctl_show_rib_request req;
sa_family_t af;
u_int8_tthrottled;
@@ -156,7 +139,6 @@ LIST_HEAD(, rde_dump_ctx) rde_dump_h = L
 
 struct rde_mrt_ctx {
LIST_ENTRY(rde_mrt_ctx) entry;
-   struct rib_context  ribctx;
struct mrt  mrt;
 };
 
@@ -272,20 +254,13 @@ rde_main(int debug, int verbose)
set_pollfd([PFD_PIPE_SESSION], ibuf_se);

unveil spamd

2018-10-23 Thread Ricardo Mestre
Hi,

When spamd runs in greylist mode the parent process (which runs greywatcher())
we know that the only files that it will ever access are PATH_SPAMD_DB in rw,
alloweddomains_file in r and that it will need to exec PATH_PFCTL so we can
unveil them with those permissions.

All other necessary files, such as certificates if used and /dev/pf, were
already opened by this time so they don't need to be unveiled. /dev/fd/*
doesn't need to be unveiled since from spamd's perspective is only a parameter
for pfctl. Furthermore, the child process loop already runs without fs access.

Comments? OK?

Index: grey.c
===
RCS file: /cvs/src/libexec/spamd/grey.c,v
retrieving revision 1.65
diff -u -p -u -r1.65 grey.c
--- grey.c  18 Oct 2017 17:31:01 -  1.65
+++ grey.c  23 Oct 2018 08:39:38 -
@@ -1078,6 +1078,18 @@ greywatcher(void)
 
drop_privs();
 
+   if (unveil(PATH_SPAMD_DB, "rw") == -1) {
+   syslog_r(LOG_ERR, , "unveil failed (%m)");
+   exit(1);
+   }
+   if (unveil(alloweddomains_file, "r") == -1) {
+   syslog_r(LOG_ERR, , "unveil failed (%m)");
+   exit(1);
+   }
+   if (unveil(PATH_PFCTL, "x") == -1) {
+   syslog_r(LOG_ERR, , "unveil failed (%m)");
+   exit(1);
+   }
if (pledge("stdio rpath wpath inet flock proc exec", NULL) == -1) {
syslog_r(LOG_ERR, , "pledge failed (%m)");
exit(1);



Re: Add acpipci(4) on amd64

2018-10-23 Thread Peter Hessler
On 2018 Oct 22 (Mon) at 21:45:06 +0200 (+0200), Mark Kettenis wrote:
:Diff below adds an acpipci(4) driver on amd64.  For now the main
:purpose of this driver is to make the PCI-specific _OSC calls to
:advertise the functionality we support.  Most notably this advertises
:support for PCIE native hotplug as we have some indications that this
:will help Thunderbolt 3 support on some machines.
:
:I'd like to see this tested on a wide range of amd64 hardware, but
:especially on laptops.  Please reply with a diff of your dmesg before
:and after.  Make sure you run make config before building a new kernel.
:
:Thanks,
:
:Mark
:

Tested on Thinkpad X1 Carbon 5th Gen.  No explosions yet, but I don't
have any usb-c devices to try against it.

Diff is:

--- dmesg.boot  Tue Oct 23 12:57:31 2018
+++ dmesg.acpipci   Tue Oct 23 12:57:30 2018
@@ -1,7 +1,7 @@
-OpenBSD 6.4-current (GENERIC.MP) #0: Tue Oct 23 10:18:36 CEST 2018
+OpenBSD 6.4-current (GENERIC.MP) #1: Tue Oct 23 12:14:06 CEST 2018
 phess...@gwen.theapt.org:/usr/src/sys/arch/amd64/compile/GENERIC.MP
 real mem = 8446648320 (8055MB)
-avail mem = 8181391360 (7802MB)
+avail mem = 8181379072 (7802MB)
 mpath0 at root
 scsibus0 at mpath0: 256 targets
 mainbus0 at root
@@ -16,7 +16,7 @@ acpitimer0 at acpi0: 3579545 Hz, 24 bits
 acpihpet0 at acpi0: 2399 Hz
 acpimadt0 at acpi0 addr 0xfee0: PC-AT compat
 cpu0 at mainbus0: apid 0 (boot processor)
-cpu0: Intel(R) Core(TM) i5-6300U CPU @ 2.40GHz, 1197.70 MHz, 06-4e-03
+cpu0: Intel(R) Core(TM) i5-6300U CPU @ 2.40GHz, 1197.52 MHz, 06-4e-03
 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,SMX,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,SGX,BMI1,HLE,AVX2,SMEP,BMI2,ERMS,INVPCID,RTM,MPX,RDSEED,ADX,SMAP,CLFLUSHOPT,PT,IBRS,IBPB,STIBP,L1DF,SSBD,SENSOR,ARAT,XSAVEOPT,XSAVEC,XGETBV1,XSAVES,MELTDOWN
 cpu0: 256KB 64b/line 8-way L2 cache
 cpu0: smt 0, core 0, package 0
@@ -24,7 +24,7 @@ mtrr: Pentium Pro MTRR support, 10 var ranges, 88 fixe
 cpu0: apic clock running at 23MHz
 cpu0: mwait min=64, max=64, C-substates=0.2.1.2.4.1.1.1, IBE
 cpu1 at mainbus0: apid 2 (application processor)
-cpu1: Intel(R) Core(TM) i5-6300U CPU @ 2.40GHz, 963.35 MHz, 06-4e-03
+cpu1: Intel(R) Core(TM) i5-6300U CPU @ 2.40GHz, 971.76 MHz, 06-4e-03
 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,SMX,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,SGX,BMI1,HLE,AVX2,SMEP,BMI2,ERMS,INVPCID,RTM,MPX,RDSEED,ADX,SMAP,CLFLUSHOPT,PT,IBRS,IBPB,STIBP,L1DF,SSBD,SENSOR,ARAT,XSAVEOPT,XSAVEC,XGETBV1,XSAVES,MELTDOWN
 cpu1: 256KB 64b/line 8-way L2 cache
 cpu1: smt 0, core 1, package 0
@@ -75,8 +75,9 @@ acpipwrres0 at acpi0: PUBS, resource for XHC_
 acpipwrres1 at acpi0: WRST
 acpipwrres2 at acpi0: WRST
 acpitz0 at acpi0: critical temperature is 128 degC
+acpipci0 at acpi0 PCI0: 0x0010 0x0011 0x
 acpithinkpad0 at acpi0
-acpiac0 at acpi0: AC unit offline
+acpiac0 at acpi0: AC unit online
 acpibat0 at acpi0: BAT0 model "01AV430" serial  1267 type LiP oem "SMP"
 acpicmos0 at acpi0
 "ALPS" at acpi0 not configured


Full dmesg is:

OpenBSD 6.4-current (GENERIC.MP) #1: Tue Oct 23 12:14:06 CEST 2018
phess...@gwen.theapt.org:/usr/src/sys/arch/amd64/compile/GENERIC.MP
real mem = 8446648320 (8055MB)
avail mem = 8181379072 (7802MB)
mpath0 at root
scsibus0 at mpath0: 256 targets
mainbus0 at root
bios0 at mainbus0: SMBIOS rev. 3.0 @ 0xca6bb000 (62 entries)
bios0: vendor LENOVO version "N1MET49W (1.34 )" date 07/02/2018
bios0: LENOVO 20K4002VGE
acpi0 at bios0: rev 2
acpi0: sleep states S0 S3 S4 S5
acpi0: tables DSDT FACP SSDT TPM2 UEFI SSDT SSDT HPET APIC MCFG ECDT SSDT BOOT 
BATB SLIC SSDT SSDT SSDT WSMT SSDT SSDT DBGP DBG2 MSDM DMAR ASF! FPDT UEFI
acpi0: wakeup devices GLAN(S4) XHC_(S3) XDCI(S4) HDAS(S4) RP01(S4) RP02(S4) 
RP04(S4) RP05(S4) RP06(S4) RP07(S4) RP08(S4) RP09(S4) RP10(S4) RP11(S4) 
RP12(S4) RP13(S4) [...]
acpitimer0 at acpi0: 3579545 Hz, 24 bits
acpihpet0 at acpi0: 2399 Hz
acpimadt0 at acpi0 addr 0xfee0: PC-AT compat
cpu0 at mainbus0: apid 0 (boot processor)
cpu0: Intel(R) Core(TM) i5-6300U CPU @ 2.40GHz, 1197.52 MHz, 06-4e-03
cpu0: 

Re: Add acpipci(4) on amd64

2018-10-23 Thread Eric Augé
Hello

I just adapted the patch for 6.4 stable (for small failed hunks) and
recompiled/rebooted the kernel.
Thinkpad X1 Carbon 5th Gen, same changes in dmesg as phessler :
...
+acpipci0 at acpi0 PCI0: 0x0010 0x0011 0x
...
(let me know if you want both as they're the same as his laptop output)

tried usb-c yubikey and usb-c harddrive, nothing happens, no new
devices, no power to the device

HTH,
Eric.
On Tue, Oct 23, 2018 at 1:11 PM Peter Hessler  wrote:
>
> On 2018 Oct 22 (Mon) at 21:45:06 +0200 (+0200), Mark Kettenis wrote:
> :Diff below adds an acpipci(4) driver on amd64.  For now the main
> :purpose of this driver is to make the PCI-specific _OSC calls to
> :advertise the functionality we support.  Most notably this advertises
> :support for PCIE native hotplug as we have some indications that this
> :will help Thunderbolt 3 support on some machines.
> :
> :I'd like to see this tested on a wide range of amd64 hardware, but
> :especially on laptops.  Please reply with a diff of your dmesg before
> :and after.  Make sure you run make config before building a new kernel.
> :
> :Thanks,
> :
> :Mark
> :
>
> Tested on Thinkpad X1 Carbon 5th Gen.  No explosions yet, but I don't
> have any usb-c devices to try against it.
>
> Diff is:
>
> --- dmesg.boot  Tue Oct 23 12:57:31 2018
> +++ dmesg.acpipci   Tue Oct 23 12:57:30 2018
> @@ -1,7 +1,7 @@
> -OpenBSD 6.4-current (GENERIC.MP) #0: Tue Oct 23 10:18:36 CEST 2018
> +OpenBSD 6.4-current (GENERIC.MP) #1: Tue Oct 23 12:14:06 CEST 2018
>  phess...@gwen.theapt.org:/usr/src/sys/arch/amd64/compile/GENERIC.MP
>  real mem = 8446648320 (8055MB)
> -avail mem = 8181391360 (7802MB)
> +avail mem = 8181379072 (7802MB)
>  mpath0 at root
>  scsibus0 at mpath0: 256 targets
>  mainbus0 at root
> @@ -16,7 +16,7 @@ acpitimer0 at acpi0: 3579545 Hz, 24 bits
>  acpihpet0 at acpi0: 2399 Hz
>  acpimadt0 at acpi0 addr 0xfee0: PC-AT compat
>  cpu0 at mainbus0: apid 0 (boot processor)
> -cpu0: Intel(R) Core(TM) i5-6300U CPU @ 2.40GHz, 1197.70 MHz, 06-4e-03
> +cpu0: Intel(R) Core(TM) i5-6300U CPU @ 2.40GHz, 1197.52 MHz, 06-4e-03
>  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,SMX,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,SGX,BMI1,HLE,AVX2,SMEP,BMI2,ERMS,INVPCID,RTM,MPX,RDSEED,ADX,SMAP,CLFLUSHOPT,PT,IBRS,IBPB,STIBP,L1DF,SSBD,SENSOR,ARAT,XSAVEOPT,XSAVEC,XGETBV1,XSAVES,MELTDOWN
>  cpu0: 256KB 64b/line 8-way L2 cache
>  cpu0: smt 0, core 0, package 0
> @@ -24,7 +24,7 @@ mtrr: Pentium Pro MTRR support, 10 var ranges, 88 fixe
>  cpu0: apic clock running at 23MHz
>  cpu0: mwait min=64, max=64, C-substates=0.2.1.2.4.1.1.1, IBE
>  cpu1 at mainbus0: apid 2 (application processor)
> -cpu1: Intel(R) Core(TM) i5-6300U CPU @ 2.40GHz, 963.35 MHz, 06-4e-03
> +cpu1: Intel(R) Core(TM) i5-6300U CPU @ 2.40GHz, 971.76 MHz, 06-4e-03
>  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,SMX,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,SGX,BMI1,HLE,AVX2,SMEP,BMI2,ERMS,INVPCID,RTM,MPX,RDSEED,ADX,SMAP,CLFLUSHOPT,PT,IBRS,IBPB,STIBP,L1DF,SSBD,SENSOR,ARAT,XSAVEOPT,XSAVEC,XGETBV1,XSAVES,MELTDOWN
>  cpu1: 256KB 64b/line 8-way L2 cache
>  cpu1: smt 0, core 1, package 0
> @@ -75,8 +75,9 @@ acpipwrres0 at acpi0: PUBS, resource for XHC_
>  acpipwrres1 at acpi0: WRST
>  acpipwrres2 at acpi0: WRST
>  acpitz0 at acpi0: critical temperature is 128 degC
> +acpipci0 at acpi0 PCI0: 0x0010 0x0011 0x
>  acpithinkpad0 at acpi0
> -acpiac0 at acpi0: AC unit offline
> +acpiac0 at acpi0: AC unit online
>  acpibat0 at acpi0: BAT0 model "01AV430" serial  1267 type LiP oem "SMP"
>  acpicmos0 at acpi0
>  "ALPS" at acpi0 not configured
>
>
> Full dmesg is:
>
> OpenBSD 6.4-current (GENERIC.MP) #1: Tue Oct 23 12:14:06 CEST 2018
> phess...@gwen.theapt.org:/usr/src/sys/arch/amd64/compile/GENERIC.MP
> real mem = 8446648320 (8055MB)
> avail mem = 8181379072 (7802MB)
> mpath0 at root
> scsibus0 at mpath0: 256 targets
> mainbus0 at root
> bios0 at mainbus0: SMBIOS rev. 3.0 @ 0xca6bb000 (62 entries)
> bios0: vendor LENOVO version "N1MET49W (1.34 )" date 07/02/2018
> bios0: LENOVO 20K4002VGE
> acpi0 at bios0: rev 2
> acpi0: sleep states S0 S3 S4 S5
> acpi0: tables DSDT FACP SSDT TPM2 UEFI SSDT SSDT HPET APIC MCFG ECDT SSDT 
> BOOT BATB SLIC SSDT SSDT SSDT WSMT SSDT SSDT DBGP DBG2 MSDM DMAR ASF! FPDT 
> UEFI
> acpi0: wakeup devices GLAN(S4) XHC_(S3) XDCI(S4) HDAS(S4) RP01(S4) RP02(S4) 
> RP04(S4) RP05(S4) RP06(S4) RP07(S4) RP08(S4) RP09(S4) RP10(S4) RP11(S4) 
> RP12(S4) RP13(S4) [...]
> acpitimer0 at acpi0: 3579545 Hz, 

Re: Add acpipci(4) on amd64

2018-10-23 Thread Jan Klemkow
Hi Mark,

On Mon, Oct 22, 2018 at 09:45:06PM +0200, Mark Kettenis wrote:
> Diff below adds an acpipci(4) driver on amd64.  For now the main
> purpose of this driver is to make the PCI-specific _OSC calls to
> advertise the functionality we support.  Most notably this advertises
> support for PCIE native hotplug as we have some indications that this
> will help Thunderbolt 3 support on some machines.
> 
> I'd like to see this tested on a wide range of amd64 hardware, but
> especially on laptops.  Please reply with a diff of your dmesg before
> and after.  Make sure you run make config before building a new kernel.

Tested with ThinkPad X1 Carbon 6th Gen under OpenBSD/amd64-current.  It
is tested with Thunderbold 3 enabled in BIOS.

Bye,
Jan

--- dmesg.boot_before_nohackTue Oct 23 18:00:39 2018
+++ dmesg.boot_after_nohack Tue Oct 23 16:43:35 2018
@@ -1,7 +1,7 @@
-OpenBSD 6.4-current (GENERIC.MP) #22: Tue Oct 23 15:04:51 CEST 2018
+OpenBSD 6.4-current (GENERIC.MP) #23: Tue Oct 23 15:16:49 CEST 2018
 you...@fabien.klemkow.net:/sys/arch/amd64/compile/GENERIC.MP
 real mem = 8451149824 (8059MB)
-avail mem = 8185745408 (7806MB)
+avail mem = 8185741312 (7806MB)
 mpath0 at root
 scsibus0 at mpath0: 256 targets
 mainbus0 at root
@@ -16,7 +16,7 @@
 acpihpet0 at acpi0: 2399 Hz
 acpimadt0 at acpi0 addr 0xfee0: PC-AT compat
 cpu0 at mainbus0: apid 0 (boot processor)
-cpu0: Intel(R) Core(TM) i5-7300U CPU @ 2.60GHz, 1394.63 MHz, 06-8e-09
+cpu0: Intel(R) Core(TM) i5-7300U CPU @ 2.60GHz, 1397.33 MHz, 06-8e-09
 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,SMX,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,SGX,BMI1,HLE,AVX2,SMEP,BMI2,ERMS,INVPCID,RTM,MPX,RDSEED,ADX,SMAP,CLFLUSHOPT,PT,IBRS,IBPB,STIBP,L1DF,SSBD,SENSOR,ARAT,XSAVEOPT,XSAVEC,XGETBV1,XSAVES,MELTDOWN
 cpu0: 256KB 64b/line 8-way L2 cache
 cpu0: smt 0, core 0, package 0
@@ -24,7 +24,7 @@
 cpu0: apic clock running at 23MHz
 cpu0: mwait min=64, max=64, C-substates=0.2.1.2.4.1.1.1, IBE
 cpu1 at mainbus0: apid 2 (application processor)
-cpu1: Intel(R) Core(TM) i5-7300U CPU @ 2.60GHz, 1158.97 MHz, 06-8e-09
+cpu1: Intel(R) Core(TM) i5-7300U CPU @ 2.60GHz, 1144.60 MHz, 06-8e-09
 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,SMX,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,SGX,BMI1,HLE,AVX2,SMEP,BMI2,ERMS,INVPCID,RTM,MPX,RDSEED,ADX,SMAP,CLFLUSHOPT,PT,IBRS,IBPB,STIBP,L1DF,SSBD,SENSOR,ARAT,XSAVEOPT,XSAVEC,XGETBV1,XSAVES,MELTDOWN
 cpu1: 256KB 64b/line 8-way L2 cache
 cpu1: smt 0, core 1, package 0
@@ -74,6 +74,7 @@
 acpipwrres0 at acpi0: PUBS, resource for XHC_
 acpipwrres1 at acpi0: PXP_, resource for RP09
 acpitz0 at acpi0: critical temperature is 128 degC
+acpipci0 at acpi0 PCI0: 0x 0x0011 0x0001
 acpithinkpad0 at acpi0
 acpiac0 at acpi0: AC unit online
 acpibat0 at acpi0: BAT0 model "01AV430" serial   585 type LiP oem "SMP"
@@ -91,7 +92,7 @@
 "USBC000" at acpi0 not configured
 acpivideo0 at acpi0: GFX0
 acpivout at acpivideo0 not configured
-cpu0: Enhanced SpeedStep 1394 MHz: speeds: 2601, 2600, 2500, 2400, 2200, 2000, 
1900, 1700, 1500, 1400, 1200, 1100, 800, 700, 600, 400 MHz
+cpu0: Enhanced SpeedStep 1397 MHz: speeds: 2601, 2600, 2500, 2400, 2200, 2000, 
1900, 1700, 1500, 1400, 1200, 1100, 800, 700, 600, 400 MHz
 pci0 at mainbus0 bus 0
 pchb0 at pci0 dev 0 function 0 "Intel Core 7G Host" rev 0x02
 inteldrm0 at pci0 dev 2 function 0 "Intel HD Graphics 620" rev 0x02
@@ -122,6 +123,20 @@
 sd0: 244198MB, 512 bytes/sector, 500118192 sectors
 ppb2 at pci0 dev 29 function 0 "Intel 100 Series PCIE" rev 0xf1: msi
 pci3 at ppb2 bus 5
+ppb3 at pci3 dev 0 function 0 "Intel JHL6540 Thunderbolt" rev 0x02
+pci4 at ppb3 bus 6
+ppb4 at pci4 dev 0 function 0 "Intel JHL6540 Thunderbolt" rev 0x02: msi
+pci5 at ppb4 bus 7
+"Intel JHL6540 Thunderbolt" rev 0x02 at pci5 dev 0 function 0 not configured
+ppb5 at pci4 dev 1 function 0 "Intel JHL6540 Thunderbolt" rev 0x02: msi
+pci6 at ppb5 bus 8
+ppb6 at pci4 dev 2 function 0 "Intel JHL6540 Thunderbolt" rev 0x02: msi
+pci7 at ppb6 bus 59
+xhci1 at pci7 dev 0 function 0 "Intel JHL6540 Thunderbolt" rev 0x02: msi, xHCI 
1.16
+usb1 at xhci1: USB revision 3.0
+uhub1 at usb1 configuration 1 interface 0 "Intel xHCI root hub" rev 3.00/1.00 
addr 1
+ppb7 at pci4 dev 4 function 0 "Intel JHL6540 Thunderbolt" rev 0x02: msi
+pci8 at ppb7 bus 60
 pcib0 at pci0 dev 31 function 0 "Intel 200 Series LPC" rev 0x21
 "Intel 100 Series PMC" rev 0x21 at pci0 dev 31 function 2 not configured
 azalia0 at pci0 dev 31 function 3 "Intel 200 Series HD Audio" rev 

Re: Add acpipci(4) on amd64

2018-10-23 Thread Mike Larkin
On Mon, Oct 22, 2018 at 09:45:06PM +0200, Mark Kettenis wrote:
> Diff below adds an acpipci(4) driver on amd64.  For now the main
> purpose of this driver is to make the PCI-specific _OSC calls to
> advertise the functionality we support.  Most notably this advertises
> support for PCIE native hotplug as we have some indications that this
> will help Thunderbolt 3 support on some machines.
> 
> I'd like to see this tested on a wide range of amd64 hardware, but
> especially on laptops.  Please reply with a diff of your dmesg before
> and after.  Make sure you run make config before building a new kernel.
> 
> Thanks,
> 
> Mark

acpipci0 at acpi0 PCI0: 0x 0x0011 0x0001


... was added to dmesg on my x230. Everything appears to work.

-ml



Re: vmd losing VMs

2018-10-23 Thread Greg Steuck
Not that I expected anything to change considering the patches submitted,
but Oct 21 snapshot (minus "Add support to create and convert disk images
from existing images") is similarly afflicted. Any candidate fixes or
patches for added logging will be put to test in short order :)

ci-openbsd$ dmesg | head
OpenBSD 6.4-current (GENERIC.MP) #376: Sun Oct 21 22:46:20 MDT 2018
dera...@amd64.openbsd.org:/usr/src/sys/arch/amd64/compile/GENERIC.MP
real mem = 17163079680 (16367MB)
avail mem = 16633651200 (15863MB)
mpath0 at root
scsibus0 at mpath0: 256 targets
mainbus0 at root
bios0 at mainbus0: SMBIOS rev. 2.4 @ 0xbcf0 (20 entries)
bios0: vendor Google version "Google" date 01/01/2011
bios0: Google Google Compute Engine
ci-openbsd$ ps ax | grep vm
 75798 ??  Is  0:00.04 vmd: priv (vmd)
70138 ??  Isp 0:02.35 /usr/sbin/vmd
49408 ??  Isp 0:01.25 vmd: vmm (vmd)
87301 ??  Isp 0:04.63 vmd: control (vmd)
83798 ??  Rp/2  874:45.69 vmd: ci-openbsd-main-0 (vmd)
74819 ??  Rp/0  469:43.70 vmd: ci-openbsd-main-1 (vmd)
52785 ??  Rp/38:04.52 vmd: ci-openbsd-main-2 (vmd)
58963 ??  Ip  0:00.02 vmctl stop ci-openbsd-main-0 -f -w
25424 ??  Ip  0:00.02 vmctl stop ci-openbsd-main-1 -f -w
58043 p3  S+p 0:00.01 grep vm


Re: Add acpipci(4) on amd64

2018-10-23 Thread Mark Kettenis
> Date: Tue, 23 Oct 2018 18:40:42 +0200
> From: Jan Klemkow 
> 
> Hi Mark,
> 
> On Mon, Oct 22, 2018 at 09:45:06PM +0200, Mark Kettenis wrote:
> > Diff below adds an acpipci(4) driver on amd64.  For now the main
> > purpose of this driver is to make the PCI-specific _OSC calls to
> > advertise the functionality we support.  Most notably this advertises
> > support for PCIE native hotplug as we have some indications that this
> > will help Thunderbolt 3 support on some machines.
> > 
> > I'd like to see this tested on a wide range of amd64 hardware, but
> > especially on laptops.  Please reply with a diff of your dmesg before
> > and after.  Make sure you run make config before building a new kernel.
> 
> Tested with ThinkPad X1 Carbon 6th Gen under OpenBSD/amd64-current.  It
> is tested with Thunderbold 3 enabled in BIOS.

Bingo!

Just to be sure, both dmesg's were made with the same BIOS
configuration and no devices connected to Thunderbolt 3 at boot?

> --- dmesg.boot_before_nohack  Tue Oct 23 18:00:39 2018
> +++ dmesg.boot_after_nohack   Tue Oct 23 16:43:35 2018
> @@ -1,7 +1,7 @@
> -OpenBSD 6.4-current (GENERIC.MP) #22: Tue Oct 23 15:04:51 CEST 2018
> +OpenBSD 6.4-current (GENERIC.MP) #23: Tue Oct 23 15:16:49 CEST 2018
>  you...@fabien.klemkow.net:/sys/arch/amd64/compile/GENERIC.MP
>  real mem = 8451149824 (8059MB)
> -avail mem = 8185745408 (7806MB)
> +avail mem = 8185741312 (7806MB)
>  mpath0 at root
>  scsibus0 at mpath0: 256 targets
>  mainbus0 at root
> @@ -16,7 +16,7 @@
>  acpihpet0 at acpi0: 2399 Hz
>  acpimadt0 at acpi0 addr 0xfee0: PC-AT compat
>  cpu0 at mainbus0: apid 0 (boot processor)
> -cpu0: Intel(R) Core(TM) i5-7300U CPU @ 2.60GHz, 1394.63 MHz, 06-8e-09
> +cpu0: Intel(R) Core(TM) i5-7300U CPU @ 2.60GHz, 1397.33 MHz, 06-8e-09
>  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,SMX,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,SGX,BMI1,HLE,AVX2,SMEP,BMI2,ERMS,INVPCID,RTM,MPX,RDSEED,ADX,SMAP,CLFLUSHOPT,PT,IBRS,IBPB,STIBP,L1DF,SSBD,SENSOR,ARAT,XSAVEOPT,XSAVEC,XGETBV1,XSAVES,MELTDOWN
>  cpu0: 256KB 64b/line 8-way L2 cache
>  cpu0: smt 0, core 0, package 0
> @@ -24,7 +24,7 @@
>  cpu0: apic clock running at 23MHz
>  cpu0: mwait min=64, max=64, C-substates=0.2.1.2.4.1.1.1, IBE
>  cpu1 at mainbus0: apid 2 (application processor)
> -cpu1: Intel(R) Core(TM) i5-7300U CPU @ 2.60GHz, 1158.97 MHz, 06-8e-09
> +cpu1: Intel(R) Core(TM) i5-7300U CPU @ 2.60GHz, 1144.60 MHz, 06-8e-09
>  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,SMX,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,SGX,BMI1,HLE,AVX2,SMEP,BMI2,ERMS,INVPCID,RTM,MPX,RDSEED,ADX,SMAP,CLFLUSHOPT,PT,IBRS,IBPB,STIBP,L1DF,SSBD,SENSOR,ARAT,XSAVEOPT,XSAVEC,XGETBV1,XSAVES,MELTDOWN
>  cpu1: 256KB 64b/line 8-way L2 cache
>  cpu1: smt 0, core 1, package 0
> @@ -74,6 +74,7 @@
>  acpipwrres0 at acpi0: PUBS, resource for XHC_
>  acpipwrres1 at acpi0: PXP_, resource for RP09
>  acpitz0 at acpi0: critical temperature is 128 degC
> +acpipci0 at acpi0 PCI0: 0x 0x0011 0x0001
>  acpithinkpad0 at acpi0
>  acpiac0 at acpi0: AC unit online
>  acpibat0 at acpi0: BAT0 model "01AV430" serial   585 type LiP oem "SMP"
> @@ -91,7 +92,7 @@
>  "USBC000" at acpi0 not configured
>  acpivideo0 at acpi0: GFX0
>  acpivout at acpivideo0 not configured
> -cpu0: Enhanced SpeedStep 1394 MHz: speeds: 2601, 2600, 2500, 2400, 2200, 
> 2000, 1900, 1700, 1500, 1400, 1200, 1100, 800, 700, 600, 400 MHz
> +cpu0: Enhanced SpeedStep 1397 MHz: speeds: 2601, 2600, 2500, 2400, 2200, 
> 2000, 1900, 1700, 1500, 1400, 1200, 1100, 800, 700, 600, 400 MHz
>  pci0 at mainbus0 bus 0
>  pchb0 at pci0 dev 0 function 0 "Intel Core 7G Host" rev 0x02
>  inteldrm0 at pci0 dev 2 function 0 "Intel HD Graphics 620" rev 0x02
> @@ -122,6 +123,20 @@
>  sd0: 244198MB, 512 bytes/sector, 500118192 sectors
>  ppb2 at pci0 dev 29 function 0 "Intel 100 Series PCIE" rev 0xf1: msi
>  pci3 at ppb2 bus 5
> +ppb3 at pci3 dev 0 function 0 "Intel JHL6540 Thunderbolt" rev 0x02
> +pci4 at ppb3 bus 6
> +ppb4 at pci4 dev 0 function 0 "Intel JHL6540 Thunderbolt" rev 0x02: msi
> +pci5 at ppb4 bus 7
> +"Intel JHL6540 Thunderbolt" rev 0x02 at pci5 dev 0 function 0 not configured
> +ppb5 at pci4 dev 1 function 0 "Intel JHL6540 Thunderbolt" rev 0x02: msi
> +pci6 at ppb5 bus 8
> +ppb6 at pci4 dev 2 function 0 "Intel JHL6540 Thunderbolt" rev 0x02: msi
> +pci7 at ppb6 bus 59
> +xhci1 at pci7 dev 0 function 0 "Intel JHL6540 Thunderbolt" rev 0x02: msi, 
> xHCI 1.16
> +usb1 at xhci1: USB revision 3.0
> +uhub1 at usb1 configuration 1 interface 

Re: More km_alloc(9)

2018-10-23 Thread Amit Kulkarni
> > Had the diff below in my tree for a very long time.  Switch several
> > uvm_km_alloc()/uvm_km_valloc() calls over to km_alloc().
> >
> > ok?
> >
>
> ok but there is a knf spacing issue (end-pa). other than that nit, ok mlarkin
>

tested to work fine on amd64.
thanks



Re: Add acpipci(4) on amd64

2018-10-23 Thread Jan Klemkow
Hi Mark,

On Tue, Oct 23, 2018 at 07:32:16PM +0200, Mark Kettenis wrote:
> > Date: Tue, 23 Oct 2018 18:40:42 +0200
> > From: Jan Klemkow 
> > On Mon, Oct 22, 2018 at 09:45:06PM +0200, Mark Kettenis wrote:
> > > Diff below adds an acpipci(4) driver on amd64.  For now the main
> > > purpose of this driver is to make the PCI-specific _OSC calls to
> > > advertise the functionality we support.  Most notably this advertises
> > > support for PCIE native hotplug as we have some indications that this
> > > will help Thunderbolt 3 support on some machines.
> > > 
> > > I'd like to see this tested on a wide range of amd64 hardware, but
> > > especially on laptops.  Please reply with a diff of your dmesg before
> > > and after.  Make sure you run make config before building a new kernel.
> > 
> > Tested with ThinkPad X1 Carbon 6th Gen under OpenBSD/amd64-current.  It
> > is tested with Thunderbold 3 enabled in BIOS.
> 
> Bingo!
> 
> Just to be sure, both dmesg's were made with the same BIOS
> configuration and no devices connected to Thunderbolt 3 at boot?

Yes, same BIOS option and no devices attached for both dmesgs .  But, I
have changed the BIOS option them.  When "Thunderbolt 3" is enabled and
the machine resumes from suspend (S3), than the acpi0 kernel thread
takes 80-90% CPU usage till reboot.

Tomorrow, I will see if could get a thunderbolt device for testing.

FYI, with "Thunderbolt 3" disabled the dmesg looks like the ThinkPad X1
Carbon 5th Gen. dmesgs from the other testers.

See below for a full dmesg listing with your diff and "Thunderbolt 3"
enabled.

Thanks,
Jan

--- dmesg.boot_before_hack  Tue Oct 23 15:24:35 2018
+++ dmesg.boot_after_hack   Tue Oct 23 15:24:58 2018
@@ -1,4 +1,4 @@
-OpenBSD 6.4-current (GENERIC.MP) #22: Tue Oct 23 15:04:51 CEST 2018
+OpenBSD 6.4-current (GENERIC.MP) #23: Tue Oct 23 15:16:49 CEST 2018
 you...@fabien.klemkow.net:/sys/arch/amd64/compile/GENERIC.MP
 real mem = 8451149824 (8059MB)
 avail mem = 8185741312 (7806MB)
@@ -24,7 +24,7 @@
 cpu0: apic clock running at 24MHz
 cpu0: mwait min=64, max=64, C-substates=0.2.1.2.4.1.1.1, IBE
 cpu1 at mainbus0: apid 2 (application processor)
-cpu1: Intel(R) Core(TM) i5-7300U CPU @ 2.60GHz, 1155.00 MHz, 06-8e-09
+cpu1: Intel(R) Core(TM) i5-7300U CPU @ 2.60GHz, 1156.38 MHz, 06-8e-09
 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,SMX,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,SGX,BMI1,HLE,AVX2,SMEP,BMI2,ERMS,INVPCID,RTM,MPX,RDSEED,ADX,SMAP,CLFLUSHOPT,PT,IBRS,IBPB,STIBP,L1DF,SSBD,SENSOR,ARAT,XSAVEOPT,XSAVEC,XGETBV1,XSAVES,MELTDOWN
 cpu1: 256KB 64b/line 8-way L2 cache
 cpu1: smt 0, core 1, package 0
@@ -73,6 +73,7 @@
 acpicpu3 at acpi0: C3(200@1034 mwait.1@0x60), C2(200@151 mwait.1@0x33), 
C1(1000@1 mwait.1), PSS
 acpipwrres0 at acpi0: PUBS, resource for XHC_
 acpitz0 at acpi0: critical temperature is 128 degC
+acpipci0 at acpi0 PCI0: 0x 0x0011 0x0001
 acpithinkpad0 at acpi0
 acpiac0 at acpi0: AC unit online
 acpibat0 at acpi0: BAT0 model "01AV430" serial   585 type LiP oem "SMP"


Full dmegs listing:


OpenBSD 6.4-current (GENERIC.MP) #23: Tue Oct 23 15:16:49 CEST 2018
you...@fabien.klemkow.net:/sys/arch/amd64/compile/GENERIC.MP
real mem = 8451149824 (8059MB)
avail mem = 8185741312 (7806MB)
mpath0 at root
scsibus0 at mpath0: 256 targets
mainbus0 at root
bios0 at mainbus0: SMBIOS rev. 3.0 @ 0xca63b000 (63 entries)
bios0: vendor LENOVO version "N23ET55W (1.30 )" date 08/31/2018
bios0: LENOVO 20KHS08H00
acpi0 at bios0: rev 2
acpi0: sleep states S0 S3 S4 S5
acpi0: tables DSDT FACP SSDT SSDT TPM2 UEFI SSDT SSDT HPET APIC MCFG ECDT SSDT 
SSDT BOOT BATB SSDT SSDT SSDT LPIT WSMT SSDT SSDT SSDT DBGP DBG2 POAT DMAR NHLT 
ASF! FPDT UEFI
acpi0: wakeup devices GLAN(S4) XHC_(S3) XDCI(S4) HDAS(S4) RP01(S4) PXSX(S4) 
RP02(S4) PXSX(S4) PXSX(S4) RP04(S4) PXSX(S4) RP05(S4) PXSX(S4) RP06(S4) 
PXSX(S4) RP07(S4) [...]
acpitimer0 at acpi0: 3579545 Hz, 24 bits
acpihpet0 at acpi0: 2399 Hz
acpimadt0 at acpi0 addr 0xfee0: PC-AT compat
cpu0 at mainbus0: apid 0 (boot processor)
cpu0: Intel(R) Core(TM) i5-7300U CPU @ 2.60GHz, 1397.33 MHz, 06-8e-09
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,SMX,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,SGX,BMI1,HLE,AVX2,SMEP,BMI2,ERMS,INVPCID,RTM,MPX,RDSEED,ADX,SMAP,CLFLUSHOPT,PT,IBRS,IBPB,STIBP,L1DF,SSBD,SENSOR,ARAT,XSAVEOPT,XSAVEC,XGETBV1,XSAVES,MELTDOWN
cpu0: 256KB 64b/line 8-way L2 cache
cpu0: smt 0, core 0, package 0
mtrr: Pentium Pro MTRR support, 10 var ranges, 88 fixed ranges
cpu0: apic clock running at 

readelf: fix out-of-bounds error

2018-10-23 Thread Christian Weisgerber
I ran across this:

  $ readelf -h /usr/local/bin/w3m
  ...
  readelf(71968) in free(): bogus pointer (double free?) 0x1
  Abort trap (core dumped)

In readelf.c there's a static arrary:

  static bfd_vma dynamic_info[DT_JMPREL + 1];

Later this array is written to like this:

  switch (entry->d_tag)
{
  ...
  case DT_TEXTREL :
  case DT_JMPREL  :
  case DT_RUNPATH :
dynamic_info[entry->d_tag] = entry->d_un.d_val;
...

Alas, DT_RUNPATH > DT_JMPREL, so we have an out-of-bounds write
that splats somewhere into memory.  In my case it mangled an unrelated
pointer.

I checked that DT_RUNPATH is the numerically highest value used to
index dynamic_info[], so let's size the array appropriately.

OK?

Index: gnu/usr.bin/binutils/binutils/readelf.c
===
RCS file: /cvs/src/gnu/usr.bin/binutils/binutils/readelf.c,v
retrieving revision 1.11
diff -u -p -r1.11 readelf.c
--- gnu/usr.bin/binutils/binutils/readelf.c 31 Aug 2014 13:40:02 -  
1.11
+++ gnu/usr.bin/binutils/binutils/readelf.c 23 Oct 2018 21:30:49 -
@@ -129,7 +129,7 @@ Elf_Internal_Syminfo *dynamic_syminfo;
 unsigned long dynamic_syminfo_offset;
 unsigned int dynamic_syminfo_nent;
 char program_interpreter[64];
-bfd_vma dynamic_info[DT_JMPREL + 1];
+bfd_vma dynamic_info[DT_RUNPATH + 1];
 bfd_vma version_info[16];
 Elf_Internal_Ehdr elf_header;
 Elf_Internal_Shdr *section_headers;
Index: gnu/usr.bin/binutils-2.17/binutils/readelf.c
===
RCS file: /cvs/src/gnu/usr.bin/binutils-2.17/binutils/readelf.c,v
retrieving revision 1.15
diff -u -p -r1.15 readelf.c
--- gnu/usr.bin/binutils-2.17/binutils/readelf.c23 Oct 2017 05:26:58 
-  1.15
+++ gnu/usr.bin/binutils-2.17/binutils/readelf.c23 Oct 2018 21:25:53 
-
@@ -136,7 +136,7 @@ static Elf_Internal_Syminfo *dynamic_sym
 static unsigned long dynamic_syminfo_offset;
 static unsigned int dynamic_syminfo_nent;
 static char program_interpreter[64];
-static bfd_vma dynamic_info[DT_JMPREL + 1];
+static bfd_vma dynamic_info[DT_RUNPATH + 1];
 static bfd_vma version_info[16];
 static Elf_Internal_Ehdr elf_header;
 static Elf_Internal_Shdr *section_headers;
-- 
Christian "naddy" Weisgerber  na...@mips.inka.de



Allow vmd to specify which ports it can handle

2018-10-23 Thread Adam Steen
Hi tech

The following diff allows vmd to specify which ports it can handle
or fix "XXX something better than a hardcoded list here, maybe configure via
vmd via the device list in vm create params?"

There are currently two implementation of bsearch in the kernel and this patch
would add a third, I think these should be consolidated, but i didn't know
where to put the new function.
the implementations are in:
  - ieee80211_regdomain.c
  - sys/kern/kern_pledge.c

Cheers
Adam

Index: sys/arch/amd64/amd64/vmm.c
===
RCS file: /cvs/src/sys/arch/amd64/amd64/vmm.c,v
retrieving revision 1.221
diff -u -p -u -p -r1.221 vmm.c
--- sys/arch/amd64/amd64/vmm.c  7 Oct 2018 22:43:06 -   1.221
+++ sys/arch/amd64/amd64/vmm.c  23 Oct 2018 11:37:56 -
@@ -114,6 +114,7 @@ int vmmioctl(dev_t, u_long, caddr_t, int
 int vmmclose(dev_t, int, int, struct proc *);
 int vmm_start(void);
 int vmm_stop(void);
+int vmm_compare_vei_port(const void *a, const void *b);
 size_t vm_create_check_mem_ranges(struct vm_create_params *);
 int vm_create(struct vm_create_params *, struct proc *);
 int vm_run(struct vm_run_params *);
@@ -1116,6 +1117,10 @@ vm_create(struct vm_create_params *vcp,
return (ret);
}
rw_enter_write(>vm_vcpu_lock);
+
+   vcpu->vc_nportranges = vcp->vcp_nportranges;
+   memcpy(vcpu->vc_portranges, vcp->vcp_portranges,
+   vcpu->vc_nportranges * sizeof(vcp->vcp_portranges[0]));
vcpu->vc_id = vm->vm_vcpu_ct;
vm->vm_vcpu_ct++;
SLIST_INSERT_HEAD(>vm_vcpu_list, vcpu, vc_vcpu_link);
@@ -5059,6 +5064,38 @@ vmm_get_guest_cpu_mode(struct vcpu *vcpu
 }

 /*
+ * XXX this should be consolidated in the kernel
+ * see
+ *  - ieee80211_regdomain.c
+ *  - sys/kern/kern_pledge.c
+ */
+#ifndef bsearch
+const void *vmm_bsearch(const void *, const void *, size_t, size_t,
+int (*)(const void *, const void *));
+
+const void *
+vmm_bsearch(const void *key, const void *base0, size_t nmemb, size_t size,
+int (*compar)(const void *, const void *))
+{
+   const char *base = base0;
+   int lim, cmp;
+   const void *p;
+
+   for (lim = nmemb; lim != 0; lim >>= 1) {
+   p = base + (lim >> 1) * size;
+   cmp = (*compar)(key, p);
+   if (cmp == 0)
+   return ((const void *)p);
+   if (cmp > 0) {  /* key > p: move right */
+   base = (const char *)p + size;
+   lim--;
+   } /* else move left */
+   }
+   return (NULL);
+}
+#endif
+
+/*
  * svm_handle_inout
  *
  * Exit handler for IN/OUT instructions.
@@ -5113,28 +5150,15 @@ svm_handle_inout(struct vcpu *vcpu)
vcpu->vc_gueststate.vg_rip += insn_length;

/*
-* The following ports usually belong to devices owned by vmd.
+* The ports specified by vc_portranges belong to devices owned by vmd.
 * Return EAGAIN to signal help needed from userspace (vmd).
 * Return 0 to indicate we don't care about this port.
-*
-* XXX something better than a hardcoded list here, maybe
-* configure via vmd via the device list in vm create params?
 */
-   switch (vcpu->vc_exit.vei.vei_port) {
-   case IO_ICU1 ... IO_ICU1 + 1:
-   case 0x40 ... 0x43:
-   case PCKBC_AUX:
-   case IO_RTC ... IO_RTC + 1:
-   case IO_ICU2 ... IO_ICU2 + 1:
-   case 0x3f8 ... 0x3ff:
-   case ELCR0 ... ELCR1:
-   case 0x500 ... 0x50f:
-   case 0xcf8:
-   case 0xcfc ... 0xcff:
-   case VMM_PCI_IO_BAR_BASE ... VMM_PCI_IO_BAR_END:
+   if (vmm_bsearch(>vc_exit.vei.vei_port, vcpu->vc_portranges,
+   vcpu->vc_nportranges, sizeof(struct vm_port_range),
+   vmm_compare_vei_port)) {
ret = EAGAIN;
-   break;
-   default:
+   } else {
/* Read from unsupported ports returns FFs */
if (vcpu->vc_exit.vei.vei_dir == 1) {
switch(vcpu->vc_exit.vei.vei_size) {
@@ -5206,28 +5230,15 @@ vmx_handle_inout(struct vcpu *vcpu)
vcpu->vc_gueststate.vg_rip += insn_length;

/*
-* The following ports usually belong to devices owned by vmd.
+* The ports specified by vc_portranges belong to devices owned by vmd.
 * Return EAGAIN to signal help needed from userspace (vmd).
 * Return 0 to indicate we don't care about this port.
-*
-* XXX something better than a hardcoded list here, maybe
-* configure via vmd via the device list in vm create params?
 */
-   switch (vcpu->vc_exit.vei.vei_port) {
-   case IO_ICU1 ... IO_ICU1 + 1:
-   case 0x40 ... 0x43:
-   case PCKBC_AUX:
-   case IO_RTC ... IO_RTC + 1:
-   case IO_ICU2 ... IO_ICU2 + 1:
-   case 0x3f8 ... 0x3ff:
-   case ELCR0 ... 

Re: Reuse VM ids.

2018-10-23 Thread Ori Bernstein
On Mon, 8 Oct 2018 07:59:15 -0700, Bob Beck  wrote:

> works here and I like it.  but probably for after unlock
> 

It's after unlock -- pinging for OKs.

-- 
Ori Bernstein



Qcow2: Clean up logging/error handling

2018-10-23 Thread Ori Bernstein
This patch turns most warnings into errors, and uses the
appropriate fatal/fatalx so that we don't print bogus error
strings. It also adds checks for unsupported refcount sizes
and writes that clobber the header.

Ok?

diff --git usr.sbin/vmd/vioqcow2.c usr.sbin/vmd/vioqcow2.c
index 3a215599d49..e550f3b84b5 100644
--- usr.sbin/vmd/vioqcow2.c
+++ usr.sbin/vmd/vioqcow2.c
@@ -137,6 +137,12 @@ virtio_init_qcow2(struct virtio_backing *file, off_t *szp, 
int *fd, size_t nfd)
return 0;
 }
 
+/*
+ * Return the path to the base image given a disk image.
+ *
+ * This is used when resolving base images from vmd, so it should avoid
+ * fatalx'ing, or we will bring down multiple vms on a corrupt disk.
+ */
 ssize_t
 virtio_qcow2_get_base(int fd, char *path, size_t npath, const char *dpath)
 {
@@ -151,7 +157,7 @@ virtio_qcow2_get_base(int fd, char *path, size_t npath, 
const char *dpath)
return -1;
}
if (strncmp(header.magic, VM_MAGIC_QCOW, strlen(VM_MAGIC_QCOW)) != 0) {
-   log_warn("%s: invalid magic numbers", __func__);
+   log_warnx("%s: invalid magic numbers", __func__);
return -1;
}
backingoff = be64toh(header.backingoff);
@@ -160,7 +166,7 @@ virtio_qcow2_get_base(int fd, char *path, size_t npath, 
const char *dpath)
return 0;
 
if (backingsz >= npath - 1) {
-   log_warn("%s: snapshot path too long", __func__);
+   log_warnx("%s: snapshot path too long", __func__);
return -1;
}
if (pread(fd, path, backingsz, backingoff) != backingsz) {
@@ -178,20 +184,19 @@ virtio_qcow2_get_base(int fd, char *path, size_t npath, 
const char *dpath)
if (path[0] == '/') {
if (realpath(path, expanded) == NULL ||
strlcpy(path, expanded, npath) >= npath) {
-   log_warn("unable to resolve %s", path);
+   log_warnx("unable to resolve %s", path);
return -1;
}
} else {
s = dirname(dpath);
if (snprintf(expanded, sizeof(expanded),
"%s/%s", s, path) >= (int)sizeof(expanded)) {
-   log_warn("path too long: %s/%s",
-   s, path);
+   log_warnx("path too long: %s/%s", s, path);
return -1;
}
if (npath < PATH_MAX ||
realpath(expanded, path) == NULL) {
-   log_warn("unable to resolve %s", path);
+   log_warnx("unable to resolve %s", path);
return -1;
}
}
@@ -216,15 +221,10 @@ qc2_open(struct qcdisk *disk, int *fds, size_t nfd)
disk->base = NULL;
disk->l1 = NULL;
 
-   if (pread(fd, , sizeof(header), 0) != sizeof(header)) {
-   log_warn("%s: short read on header", __func__);
-   goto error;
-   }
-   if (strncmp(header.magic,
-   VM_MAGIC_QCOW, strlen(VM_MAGIC_QCOW)) != 0) {
-   log_warn("%s: invalid magic numbers", __func__);
-   goto error;
-   }
+   if (pread(fd, , sizeof(header), 0) != sizeof(header))
+   fatalx("%s: short read on header", __func__);
+   if (strncmp(header.magic, VM_MAGIC_QCOW, strlen(VM_MAGIC_QCOW)) != 0)
+   fatalx("%s: invalid magic numbers", __func__);
 
disk->clustersz = (1ull << be32toh(header.clustershift));
disk->disksz= be64toh(header.disksz);
@@ -249,79 +249,59 @@ qc2_open(struct qcdisk *disk, int *fds, size_t nfd)
/*
 * We only know about the dirty or corrupt bits here.
 */
-   if (disk->incompatfeatures & ~(QCOW2_DIRTY|QCOW2_CORRUPT)) {
-   log_warnx("%s: unsupported features %llx", __func__,
+   if (disk->incompatfeatures & ~(QCOW2_DIRTY|QCOW2_CORRUPT))
+   fatalx("%s: unsupported features %llx", __func__,
disk->incompatfeatures & ~(QCOW2_DIRTY|QCOW2_CORRUPT));
-   goto error;
-   }
+   if (be32toh(header.reforder) != 4)
+   fatalx("%s: unsupported refcount size\n", __func__);
 
disk->l1 = calloc(disk->l1sz, sizeof(*disk->l1));
if (!disk->l1)
-   goto error;
+   fatalx("%s: could not allocate l1 table", __func__);
if (pread(disk->fd, disk->l1, 8 * disk->l1sz, disk->l1off)
-   != 8 * disk->l1sz) {
-   log_warn("%s: unable to read qcow2 L1 table", __func__);
-   goto error;
-   }
+   != 8 * disk->l1sz)
+   fatalx("%s: unable to read qcow2 L1 table", __func__);
for (i = 0; i < disk->l1sz; i++)
disk->l1[i] = be64toh(disk->l1[i]);
version = be32toh(header.version);
-   if (version != 2 && version != 3) {
-   log_warn("%s: unknown qcow2