Re: workaround for buggy bios_memmap?

2018-03-05 Thread Mike Larkin
On Tue, Mar 06, 2018 at 01:46:58PM +0900, Naoki Fukaumi wrote:
> Hi tech@,
> 
> I'm using FreeBSD bhyve to run OpenBSD/amd64 VM for testing biosboot.
> (well, I know efiboot works fine on bhyve, but I want to try biosboot)
> 
> it seems bhyve's BIOS has buggy(?) entry in bios_memmap(E820 table).
> 
> 
> >> OpenBSD/amd64 BOOT 3.34
> boot> m m
> Region 0: type 1 at 0x0 for 639KB
> Region 1: type 2 at 0x9fc00 for 1KB
> Region 2: type 2 at 0xe for 128KB
> Region 3: type 1 at 0x10 for 3078904KB
> Region 4: type 3 at 0xbbfbe000 for 128KB
> Region 5: type 1 at 0xbbfde000 for 38836KB
> Region 6: type 3 at 0xbe5cb000 for 4984KB
> Region 7: type 1 at 0xbeaa9000 for 3556KB
> Region 8: type 3 at 0xbee22000 for 11804KB
> Region 9: type 1 at 0xbf9a9000 for 8KB
> Region 10: type 3 at 0xbf9ab000 for 1864KB
> Region 11: type 2 at 0xbfb7d000 for 16KB
> Region 12: type 3 at 0xbfb81000 for 32KB
> Region 13: type 4 at 0xbfb89000 for 16KB
> Region 14: type 3 at 0xbfb8d000 for 4492KB
> Region 15: type 1 at 0xbfff for 64KB
> Region 16: type 2 at 0xc000 for 983040KB
> Region 17: type 2 at 0xfec0 for 4KB
> Region 18: type 2 at 0xfed0 for 1KB
> Region 19: type 2 at 0xfee0 for 1024KB
> Region 20: type 1 at 0x1 for 5242880KB
> Low ram: 639KB  High ram: 3078904KB
> Total free memory: 8364887KB
> 
> 
> in this case, "Region 16" covers PCI memory-mapped I/O space. (why?)
> 
> in kernel, pci_init_extents() reserves there. then, PCI devices cannot
> use there, it cannot be attached or it cannot work properly.
> 
> 
> boot> boot
> cannot open hd0a:/etc/random.seed: No such file or directory
> booting hd0a:/6.3/amd64/bsd.rd: 3418091+1467392+3899896+0+593920 
> [363308+90+433368+287961]=0x9fd048
> entry point at 0x1000158
> Copyright (c) 1982, 1986, 1989, 1991, 1993
> The Regents of the University of California.  All rights reserved.
> Copyright (c) 1995-2018 OpenBSD. All rights reserved.  https://www.OpenBSD.org
> 
> OpenBSD 6.3-beta (RAMDISK_CD) #26: Sun Mar  4 11:42:12 MST 2018
> dera...@amd64.openbsd.org:/usr/src/sys/arch/amd64/compile/RAMDISK_CD
> real mem = 8549187584 (8153MB)
> avail mem = 8286302208 (7902MB)
> mainbus0 at root
> bios0 at mainbus0: SMBIOS rev. 3.0 @ 0xbfb7f000 (14 entries)
> bios0: vendor BHYVE version "1.00" date 03/14/2014
> bios0: bhyve BHYVE
> acpi0 at bios0: rev 2
> acpi0: tables DSDT FACP HPET APIC MCFG SPCR
> acpimadt0 at acpi0 addr 0xfee0: PC-AT compat
> cpu0 at mainbus0: apid 0 (boot processor)
> cpu0: AMD Ryzen 7 1700 Eight-Core Processor, 2994.31 MHz
> cpu0: 
> FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,MMX,FXSR,SSE,SSE2,HTT,SSE3,PCLMUL,SSSE3,FMA3,CX16,SSE4.1,SSE4.2,MOVBE,POPCNT,AES,XSAVE,AVX,F16C,RDRAND,HV,NXE,MMXX,FFXSR,PAGE1GB,LONG,LAHF,CMPLEG,EAPICSP,AMCR8,ABM,SSE4A,MASSE,3DNOWP,SKINIT,TCE,DBKP,ITSC,FSGSBASE,BMI1,AVX2,BMI2
> cpu0: 64KB 64b/line 4-way I-cache, 32KB 64b/line 8-way D-cache, 512KB 
> 64b/line 8-way L2 cache, 16MB 64b/line 16-way L3 cache
> cpu0: ITLB 64 4KB entries fully associative, 64 4MB entries fully associative
> cpu0: DTLB 64 4KB entries fully associative, 64 4MB entries fully associative
> cpu0: apic clock running at 134MHz
> cpu at mainbus0: not configured
> cpu at mainbus0: not configured
> cpu at mainbus0: not configured
> ioapic0 at mainbus0: apid 4 pa 0xfec0, version 11, 32 pins
> , remapped to apid 4
> acpiprt0 at acpi0: bus 0 (PC00)
> pvbus0 at mainbus0: bhyve
> pci0 at mainbus0 bus 0
> 0:4:0: mem address conflict 0xc000/0x400
> 0:10:0: mem address conflict 0xc0002000/0x2000
> (bhyve crashes here by calling pci_conf_write(pc, tag, reg, 0) twice ;)
> 
> 
> I can see similar problem on HPE ProLiant DL20 Gen9 with BIOS boot mode.
> (well, I'm sure it works well with UEFI boot mode, but I want to try...)
> 
> I made a dirty patch for boot(8). it adds function to force-delete
> reserved memory region.
> 
> 
> boot> m m ~983040K@0xc000
> Region 0: type 1 at 0x0 for 639KB
> Region 1: type 2 at 0x9fc00 for 1KB
> Region 2: type 2 at 0xe for 128KB
> Region 3: type 1 at 0x10 for 3078904KB
> Region 4: type 3 at 0xbbfbe000 for 128KB
> Region 5: type 1 at 0xbbfde000 for 38836KB
> Region 6: type 3 at 0xbe5cb000 for 4984KB
> Region 7: type 1 at 0xbeaa9000 for 3556KB
> Region 8: type 3 at 0xbee22000 for 11804KB
> Region 9: type 1 at 0xbf9a9000 for 8KB
> Region 10: type 3 at 0xbf9ab000 for 1864KB
> Region 11: type 2 at 0xbfb7d000 for 16KB
> Region 12: type 3 at 0xbfb81000 for 32KB
> Region 13: type 4 at 0xbfb89000 for 16KB
> Region 14: type 3 at 0xbfb8d000 for 4492KB
> Region 15: type 1 at 0xbfff for 64KB
> Region 16: type 2 at 0xfec0 for 4KB
> Region 17: type 2 at 0xfed0 for 1KB
> Region 18: type 2 at 0xfee0 for 1024KB
> Region 19: type 1 at 0x1 for 5242880KB
> Low ram: 639KB  High ram: 3078904KB
> Total free memory: 8364887KB
> boot> boot
> cannot open hd0a:/etc/random.seed: No such file or directory
> booting hd0a:/6.3/amd64/bsd.rd: 3418091+14

vmt: implement disk quiesce protocol with vfs_stall

2018-03-05 Thread Jonathan Matthew
A few days ago we ran into a situation where we wanted to clone a VM running
on VMWare to investigate some filesystem problems, but couldn't because vmt(4)
doesn't implement the protocol VMWare uses to quiesce disks to allow for
clean snapshots.

As it happens, we recently got vfs_stall(), which fits into the protocol nicely.
When the host tells us to quiesce, we just call vfs_stall(curproc, 1) and when
it says it's taken its snapshot, we call vfs_stall(curproc, 0).

I've tested this on esxi 5.5, where it lets me take disk-only snapshots of a VM
with 10gb of disk in around a second.  As expected, when there are deleted
files that are still open, the filesystem is marked dirty, so when you revert
to the snapshot and boot the VM, fsck runs and cleans up the deleted files.
Otherwise, the filesystem is clean.

ok?

Index: vmt.c
===
RCS file: /cvs/src/sys/dev/pv/vmt.c,v
retrieving revision 1.13
diff -u -p -u -p -r1.13 vmt.c
--- vmt.c   4 Jun 2017 05:04:24 -   1.13
+++ vmt.c   6 Mar 2018 04:29:25 -
@@ -36,6 +36,8 @@
 #include 
 #include 
 #include 
+#include 
+#include 
 
 #include 
 #include 
@@ -125,6 +127,13 @@
 #define VM_RPC_REPLY_ERROR "ERROR Unknown command"
 #define VM_RPC_REPLY_ERROR_IP_ADDR "ERROR Unable to find guest IP address"
 
+/* VM backup error codes */
+#define VM_BACKUP_SUCCESS  0
+#define VM_BACKUP_SYNC_ERROR   3
+#define VM_BACKUP_REMOTE_ABORT 4
+
+#define VM_BACKUP_TIMEOUT  30 /* seconds */
+
 /* A register. */
 union vm_reg {
struct {
@@ -167,6 +176,8 @@ struct vmt_softc {
int sc_rpc_error;
int sc_tclo_ping;
int sc_set_guest_os;
+   int sc_quiesce;
+   struct task sc_quiesce_task;
 #define VMT_RPC_BUFLEN 4096
 
struct timeout  sc_tick;
@@ -231,6 +242,14 @@ voidvmt_tclo_resume(struct vmt_softc *
 voidvmt_tclo_capreg(struct vmt_softc *);
 voidvmt_tclo_broadcastip(struct vmt_softc *);
 
+voidvmt_set_backup_status(struct vmt_softc *, const char *, int,
+   const char *);
+voidvmt_quiesce_task(void *);
+voidvmt_quiesce_done_task(void *);
+voidvmt_tclo_abortbackup(struct vmt_softc *);
+voidvmt_tclo_startbackup(struct vmt_softc *);
+voidvmt_tclo_backupdone(struct vmt_softc *);
+
 int vmt_probe(void);
 
 struct vmt_tclo_rpc {
@@ -247,7 +266,10 @@ struct vmt_tclo_rpc {
 { "Set_Option broadcastIP 1",   vmt_tclo_broadcastip },
 { "ping",   vmt_tclo_ping },
 { "reset",  vmt_tclo_reset },
-   { NULL },
+{ "vmbackup.abort",vmt_tclo_abortbackup },
+{ "vmbackup.snapshotDone", vmt_tclo_backupdone },
+{ "vmbackup.start 1",  vmt_tclo_startbackup },
+{ NULL },
 #if 0
/* Various unsupported commands */
{ "Set_Option autohide 0" },
@@ -809,6 +831,123 @@ vmt_tclo_broadcastip(struct vmt_softc *s
}
 }
 
+void
+vmt_set_backup_status(struct vmt_softc *sc, const char *state, int code,
+const char *desc)
+{
+   if (vm_rpc_send_rpci_tx(sc, "vmbackup.eventSet %s %d %s",
+   state, code, desc) != 0) {
+   DPRINTF("%s: setting backup status failed\n", DEVNAME(sc));
+   }
+}
+
+void
+vmt_quiesce_task(void *data)
+{
+   struct vmt_softc *sc = data;
+   int err;
+
+   DPRINTF("%s: quiescing filesystems for backup\n", DEVNAME(sc));
+   err = vfs_stall(curproc, 1);
+   if (err != 0) {
+   printf("%s: unable to quiesce filesystems\n", DEVNAME(sc));
+   vfs_stall(curproc, 0);
+
+   vmt_set_backup_status(sc, "req.aborted", VM_BACKUP_SYNC_ERROR,
+   "vfs_stall failed");
+   vmt_set_backup_status(sc, "req.done", VM_BACKUP_SUCCESS, "");
+   sc->sc_quiesce = 0;
+   return;
+   }
+
+   DPRINTF("%s: filesystems quiesced\n", DEVNAME(sc));
+   vmt_set_backup_status(sc, "prov.snapshotCommit", VM_BACKUP_SUCCESS, "");
+}
+
+void
+vmt_quiesce_done_task(void *data)
+{
+   struct vmt_softc *sc = data;
+
+   vfs_stall(curproc, 0);
+
+   if (sc->sc_quiesce == -1)
+   vmt_set_backup_status(sc, "req.aborted", VM_BACKUP_REMOTE_ABORT,
+   "");
+
+   vmt_set_backup_status(sc, "req.done", VM_BACKUP_SUCCESS, "");
+   sc->sc_quiesce = 0;
+}
+
+void
+vmt_tclo_abortbackup(struct vmt_softc *sc)
+{
+   const char *reply = VM_RPC_REPLY_OK;
+
+   if (sc->sc_quiesce > 0) {
+   DPRINTF("%s: aborting backup\n", DEVNAME(sc));
+   sc->sc_quiesce = -1;
+   task_set(&sc->sc_quiesce_task, vmt_quiesce_done_task, sc);
+   task_add(systq, &sc->sc_quiesce_task);
+   } else {
+   DPRINTF("%s: can't abort, no backup in 

workaround for buggy bios_memmap?

2018-03-05 Thread Naoki Fukaumi
Hi tech@,

I'm using FreeBSD bhyve to run OpenBSD/amd64 VM for testing biosboot.
(well, I know efiboot works fine on bhyve, but I want to try biosboot)

it seems bhyve's BIOS has buggy(?) entry in bios_memmap(E820 table).


>> OpenBSD/amd64 BOOT 3.34
boot> m m
Region 0: type 1 at 0x0 for 639KB
Region 1: type 2 at 0x9fc00 for 1KB
Region 2: type 2 at 0xe for 128KB
Region 3: type 1 at 0x10 for 3078904KB
Region 4: type 3 at 0xbbfbe000 for 128KB
Region 5: type 1 at 0xbbfde000 for 38836KB
Region 6: type 3 at 0xbe5cb000 for 4984KB
Region 7: type 1 at 0xbeaa9000 for 3556KB
Region 8: type 3 at 0xbee22000 for 11804KB
Region 9: type 1 at 0xbf9a9000 for 8KB
Region 10: type 3 at 0xbf9ab000 for 1864KB
Region 11: type 2 at 0xbfb7d000 for 16KB
Region 12: type 3 at 0xbfb81000 for 32KB
Region 13: type 4 at 0xbfb89000 for 16KB
Region 14: type 3 at 0xbfb8d000 for 4492KB
Region 15: type 1 at 0xbfff for 64KB
Region 16: type 2 at 0xc000 for 983040KB
Region 17: type 2 at 0xfec0 for 4KB
Region 18: type 2 at 0xfed0 for 1KB
Region 19: type 2 at 0xfee0 for 1024KB
Region 20: type 1 at 0x1 for 5242880KB
Low ram: 639KB  High ram: 3078904KB
Total free memory: 8364887KB


in this case, "Region 16" covers PCI memory-mapped I/O space. (why?)

in kernel, pci_init_extents() reserves there. then, PCI devices cannot
use there, it cannot be attached or it cannot work properly.


boot> boot
cannot open hd0a:/etc/random.seed: No such file or directory
booting hd0a:/6.3/amd64/bsd.rd: 3418091+1467392+3899896+0+593920 
[363308+90+433368+287961]=0x9fd048
entry point at 0x1000158
Copyright (c) 1982, 1986, 1989, 1991, 1993
  The Regents of the University of California.  All rights reserved.
Copyright (c) 1995-2018 OpenBSD. All rights reserved.  https://www.OpenBSD.org

OpenBSD 6.3-beta (RAMDISK_CD) #26: Sun Mar  4 11:42:12 MST 2018
dera...@amd64.openbsd.org:/usr/src/sys/arch/amd64/compile/RAMDISK_CD
real mem = 8549187584 (8153MB)
avail mem = 8286302208 (7902MB)
mainbus0 at root
bios0 at mainbus0: SMBIOS rev. 3.0 @ 0xbfb7f000 (14 entries)
bios0: vendor BHYVE version "1.00" date 03/14/2014
bios0: bhyve BHYVE
acpi0 at bios0: rev 2
acpi0: tables DSDT FACP HPET APIC MCFG SPCR
acpimadt0 at acpi0 addr 0xfee0: PC-AT compat
cpu0 at mainbus0: apid 0 (boot processor)
cpu0: AMD Ryzen 7 1700 Eight-Core Processor, 2994.31 MHz
cpu0: 
FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,MMX,FXSR,SSE,SSE2,HTT,SSE3,PCLMUL,SSSE3,FMA3,CX16,SSE4.1,SSE4.2,MOVBE,POPCNT,AES,XSAVE,AVX,F16C,RDRAND,HV,NXE,MMXX,FFXSR,PAGE1GB,LONG,LAHF,CMPLEG,EAPICSP,AMCR8,ABM,SSE4A,MASSE,3DNOWP,SKINIT,TCE,DBKP,ITSC,FSGSBASE,BMI1,AVX2,BMI2
cpu0: 64KB 64b/line 4-way I-cache, 32KB 64b/line 8-way D-cache, 512KB 64b/line 
8-way L2 cache, 16MB 64b/line 16-way L3 cache
cpu0: ITLB 64 4KB entries fully associative, 64 4MB entries fully associative
cpu0: DTLB 64 4KB entries fully associative, 64 4MB entries fully associative
cpu0: apic clock running at 134MHz
cpu at mainbus0: not configured
cpu at mainbus0: not configured
cpu at mainbus0: not configured
ioapic0 at mainbus0: apid 4 pa 0xfec0, version 11, 32 pins
, remapped to apid 4
acpiprt0 at acpi0: bus 0 (PC00)
pvbus0 at mainbus0: bhyve
pci0 at mainbus0 bus 0
0:4:0: mem address conflict 0xc000/0x400
0:10:0: mem address conflict 0xc0002000/0x2000
(bhyve crashes here by calling pci_conf_write(pc, tag, reg, 0) twice ;)


I can see similar problem on HPE ProLiant DL20 Gen9 with BIOS boot mode.
(well, I'm sure it works well with UEFI boot mode, but I want to try...)

I made a dirty patch for boot(8). it adds function to force-delete
reserved memory region.


boot> m m ~983040K@0xc000
Region 0: type 1 at 0x0 for 639KB
Region 1: type 2 at 0x9fc00 for 1KB
Region 2: type 2 at 0xe for 128KB
Region 3: type 1 at 0x10 for 3078904KB
Region 4: type 3 at 0xbbfbe000 for 128KB
Region 5: type 1 at 0xbbfde000 for 38836KB
Region 6: type 3 at 0xbe5cb000 for 4984KB
Region 7: type 1 at 0xbeaa9000 for 3556KB
Region 8: type 3 at 0xbee22000 for 11804KB
Region 9: type 1 at 0xbf9a9000 for 8KB
Region 10: type 3 at 0xbf9ab000 for 1864KB
Region 11: type 2 at 0xbfb7d000 for 16KB
Region 12: type 3 at 0xbfb81000 for 32KB
Region 13: type 4 at 0xbfb89000 for 16KB
Region 14: type 3 at 0xbfb8d000 for 4492KB
Region 15: type 1 at 0xbfff for 64KB
Region 16: type 2 at 0xfec0 for 4KB
Region 17: type 2 at 0xfed0 for 1KB
Region 18: type 2 at 0xfee0 for 1024KB
Region 19: type 1 at 0x1 for 5242880KB
Low ram: 639KB  High ram: 3078904KB
Total free memory: 8364887KB
boot> boot
cannot open hd0a:/etc/random.seed: No such file or directory
booting hd0a:/6.3/amd64/bsd.rd: 3418091+1467392+3899896+0+593920 
[363308+90+433368+287961]=0x9fd048
entry point at 0x1000158
Copyright (c) 1982, 1986, 1989, 1991, 1993
  The Regents of the University of California.  All rights reserved.
Copyright (c) 1995-2018 OpenBSD. All rights reserved.  https://www.OpenBSD.org

OpenBSD 6

ipmi(4): don't panic if ipmi_sendcmd() fails

2018-03-05 Thread Naoki Fukaumi
Hi tech@,

sending IPMI command can fail for some reason (e.g. during BMC reset,
and possibly BMC is just busy?), then it should be better to return
error than panic().

--- sys/dev/ipmi.c
+++ sys/dev/ipmi.c
@@ -1039,10 +1039,10 @@ ipmi_cmd_poll(struct ipmi_cmd *c)
 {
mtx_enter(&c->c_sc->sc_cmd_mtx);
 
-   if (ipmi_sendcmd(c)) {
-   panic("%s: sendcmd fails", DEVNAME(c->c_sc));
-   }
-   c->c_ccode = ipmi_recvcmd(c);
+   if ((c->c_ccode = ipmi_sendcmd(c)))
+   printf("%s: sendcmd fails\n", DEVNAME(c->c_sc));
+   else
+   c->c_ccode = ipmi_recvcmd(c);
 
mtx_leave(&c->c_sc->sc_cmd_mtx);
 }
@@ -1819,8 +1819,6 @@ ipmiioctl(dev_t dev, u_long cmd, caddr_t data, int flag, 
struct proc *proc)
c->c_txlen = req->msg.data_len;
c->c_rxlen = 0;
ipmi_cmd(c);
-
-   KASSERT(c->c_ccode != -1);
break;
case IPMICTL_RECEIVE_MSG_TRUNC:
case IPMICTL_RECEIVE_MSG:

--
FUKAUMI Naoki



Re: Patch to add 2 words to share/dict/web2

2018-03-05 Thread Theo de Raadt
> On 2018/03/05 17:14, Kurt Mosiejczuk wrote:
> > It was annoying me that "aspirational" wasn't in common spellcheck
> > dictionaries and afresh@ suggested I submit a patch to at least get
> > the situation corrected for OpenBSD.
> > 
> > Before getting around to this, I noticed "supremacist" wasn't there
> > either so added that.
> 
> hmm, according to README, this file is supposed to be "Webster's Second
> International Dictionary, all 234,936 words worth. The 1934 copyright
> has lapsed" ... should additions go in some other file or should the
> description be changed? It seems to have grown a bit already,
> 
> $ wc -l web2  
>   235971 web2

If we added the complete english language, /usr would be full.

(Already a few people having trouble with multiple upgrades + the
new kernel/library link kits)



Re: mfii(4): add bio(4) support

2018-03-05 Thread Naoki Fukaumi
Hi,

From: YASUOKA Masahiko 
Subject: Re: mfii(4): add bio(4) support
Date: Tue, 06 Mar 2018 08:14:44 +0900 (JST)

>> most parts are taken from mfi(4), plus fix for rebuilding (bioctl -R).
> 
> Do I understand the rebuilding problem correctly?
> 
> - mfii_makegood() and mfii_makespare() are added before sending the
>   rebuild command to fix the problem
> - The problem doesn't happen with mfi(4)

well, sorry for insufficient explanation.

mfi(4) has the problem. original fix for mfi(4) is here,

 https://marc.info/?t=14987241292&r=1&w=2

to support rebuilding in current bio(4) framework, swapped(new) disk
should be exposed to userland as "unused" disk, but mfi(4) exposes
removed disk as "failed" disk which cannot be controlled any way. first
fix, in mfi(i)_ioctl_disk(), is "find an unused(new) disk and expose it
to userland".

and, disk state of unused disk need to be "unconfigured good" and not to
be "foreign". second fix, mfi(i)_makegood(), try to change disk state if
needed/possible.

then, mfi(i)_makespare() starts rebuilding.

Best regards,

--
FUKAUMI Naoki



Re: Patch to add 2 words to share/dict/web2

2018-03-05 Thread STeve Andre'



On 03/05/18 19:16, Stuart Henderson wrote:

On 2018/03/05 17:14, Kurt Mosiejczuk wrote:

It was annoying me that "aspirational" wasn't in common spellcheck
dictionaries and afresh@ suggested I submit a patch to at least get
the situation corrected for OpenBSD.

Before getting around to this, I noticed "supremacist" wasn't there
either so added that.


hmm, according to README, this file is supposed to be "Webster's Second
International Dictionary, all 234,936 words worth. The 1934 copyright
has lapsed" ... should additions go in some other file or should the
description be changed? It seems to have grown a bit already,

$ wc -l web2
   235971 web2




Definitely it should just grow.  Having multiple files doesn't make 
sense, to me.  English is a growing language.


--STeve Andre'



Re: Patch to add 2 words to share/dict/web2

2018-03-05 Thread Stuart Henderson
On 2018/03/05 17:14, Kurt Mosiejczuk wrote:
> It was annoying me that "aspirational" wasn't in common spellcheck
> dictionaries and afresh@ suggested I submit a patch to at least get
> the situation corrected for OpenBSD.
> 
> Before getting around to this, I noticed "supremacist" wasn't there
> either so added that.

hmm, according to README, this file is supposed to be "Webster's Second
International Dictionary, all 234,936 words worth. The 1934 copyright
has lapsed" ... should additions go in some other file or should the
description be changed? It seems to have grown a bit already,

$ wc -l web2  
  235971 web2



Patch to add 2 words to share/dict/web2

2018-03-05 Thread Kurt Mosiejczuk
It was annoying me that "aspirational" wasn't in common spellcheck
dictionaries and afresh@ suggested I submit a patch to at least get
the situation corrected for OpenBSD.

Before getting around to this, I noticed "supremacist" wasn't there
either so added that.

Index: share/dict/web2
===
RCS file: /cvs/src/share/dict/web2,v
retrieving revision 1.8
diff -u -p -r1.8 web2
--- share/dict/web2 16 Dec 2017 13:01:22 -  1.8
+++ share/dict/web2 5 Mar 2018 22:02:55 -
@@ -14387,6 +14387,7 @@ aspirant
 aspirata
 aspirate
 aspiration
+aspirational
 aspirator
 aspiratory
 aspire
@@ -195461,6 +195462,7 @@ supraventricular
 supraversion
 supravital
 supraworld
+supremacist
 supremacy
 suprematism
 supreme



Re: mfii(4): add bio(4) support

2018-03-05 Thread YASUOKA Masahiko
Hi,

> most parts are taken from mfi(4), plus fix for rebuilding (bioctl -R).

Do I understand the rebuilding problem correctly?

- mfii_makegood() and mfii_makespare() are added before sending the
  rebuild command to fix the problem
- The problem doesn't happen with mfi(4)


On Mon, 05 Mar 2018 21:49:16 +0900 (JST)
Naoki Fukaumi  wrote:
> Hi tech@,
> 
> This patch adds bio(4) support for mfii(4).
> # with "mfii(4): use MFII_FUNCTION_PASSTHRU_IO for MFI commands"
> 
> most parts are taken from mfi(4), plus fix for rebuilding (bioctl -R).
> 
> --- sys/dev/ic/mfireg.h
> +++ sys/dev/ic/mfireg.h
> @@ -139,6 +139,9 @@
>  #define MR_DCMD_CONF_GET 0x0401
>  #define MR_DCMD_CFG_ADD  0x0402
>  #define MR_DCMD_CFG_CLEAR0x0403
> +#define MR_DCMD_CFG_MAKE_SPARE   0x0404
> +#define MR_DCMD_CFG_FOREIGN_SCAN 0x04060100
> +#define MR_DCMD_CFG_FOREIGN_CLEAR0x04060500
>  #define MR_DCMD_BBU_GET_STATUS   0x0501
>  #define MR_DCMD_BBU_GET_CAPACITY_INFO0x0502
>  #define MR_DCMD_BBU_GET_DESIGN_INFO  0x0503
> @@ -1228,3 +1231,13 @@ struct mfi_pr_properties {
>   uint32_texec_freq;
>   uint32_tclear_freq;
>  } __packed;
> +
> +/* We currently don't know the full details of the following struct */
> +struct mfii_foreign_scan_cfg {
> + char data[24];
> +};
> +
> +struct mfii_foreign_scan_info {
> + uint32_t count; /* Number of foreign configs found */
> + struct mfii_foreign_scan_cfg cfgs[8];
> +};
> --- sys/dev/pci/mfii.c
> +++ sys/dev/pci/mfii.c
> @@ -22,10 +22,14 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  #include 
>  #include 
>  #include 
> +#include 
> +#include 
>  
> +#include 
>  #include 
>  #include 
>  
> @@ -307,7 +311,35 @@ struct mfii_softc {
>   struct mfii_pd_softc*sc_pd;
>   struct scsi_iopool  sc_iopool;
>  
> + /* save some useful information for logical drives that is missing
> +  * in sc_ld_list
> +  */
> + struct {
> + uint32_tld_present;
> + charld_dev[16]; /* device name sd? */
> + }   sc_ld[MFI_MAX_LD];
> +
> + /* scsi ioctl from sd device */
> + int (*sc_ioctl)(struct device *, u_long, caddr_t);
> +
> + uint32_tsc_ld_cnt;
> +
> + /* bio */
> + struct mfi_conf *sc_cfg;
>   struct mfi_ctrl_infosc_info;
> + struct mfi_ld_list  sc_ld_list;
> + struct mfi_ld_details   *sc_ld_details; /* array to all logical disks */
> + int sc_no_pd; /* used physical disks */
> + int sc_ld_sz; /* sizeof sc_ld_details */
> +
> + /* mgmt lock */
> + struct rwlock   sc_lock;
> +
> + /* sensors */
> + struct ksensordev   sc_sensordev;
> + struct ksensor  *sc_bbu;
> + struct ksensor  *sc_bbu_status;
> + struct ksensor  *sc_sensors;
>  };
>  
>  #ifdef MFII_DEBUG
> @@ -355,13 +387,15 @@ struct cfdriver mfii_cd = {
>  
>  void mfii_scsi_cmd(struct scsi_xfer *);
>  void mfii_scsi_cmd_done(struct mfii_softc *, struct mfii_ccb *);
> +int  mfii_scsi_ioctl(struct scsi_link *, u_long, caddr_t, int);
> +int  mfii_ioctl_cache(struct scsi_link *, u_long, struct dk_cache *);
>  
>  struct scsi_adapter mfii_switch = {
>   mfii_scsi_cmd,
>   scsi_minphys,
>   NULL, /* probe */
>   NULL, /* unprobe */
> - NULL  /* ioctl */
> + mfii_scsi_ioctl
>  };
>  
>  void mfii_pd_scsi_cmd(struct scsi_xfer *);
> @@ -409,9 +443,11 @@ int  mfii_load_mfa(struct mfii_softc 
> *, struct mfii_ccb *,
>  
>  int  mfii_mfa_poll(struct mfii_softc *, struct mfii_ccb *);
>  
> -int  mfii_mgmt(struct mfii_softc *, struct mfii_ccb *,
> - u_int32_t, const union mfi_mbox *,
> - void *, size_t, int);
> +int  mfii_mgmt(struct mfii_softc *, uint32_t, uint32_t,
> + size_t, void *, const union mfi_mbox *);
> +int  mfii_do_mgmt(struct mfii_softc *, struct mfii_ccb *,
> + uint32_t, uint32_t, size_t, void *,
> + const union mfi_mbox *);
>  void mfii_empty_done(struct mfii_softc *, struct mfii_ccb *);
>  
>  int  mfii_scsi_cmd_io(struct mfii_softc *,
> @@ -445,6 +481,42 @@ void mfii_aen_pd_remove(struct 
> mfii_softc *,
>  void mfii_aen_pd_state_change(struct mfii_softc *,
>   const struct mfi_evtarg_pd_state *);
>  
> +#if NBIO > 0
> +int  mfii_ioctl(struct device *, u_long, caddr_t);
> +int  mfii_bio_getitall(struct mfii_softc *);
> +int  mfii_ioctl_inq(struct mfi

Re: handle updates via Adj-RIB-Out

2018-03-05 Thread Job Snijders
Claudio,

How best to test this change proposal? Should this maybe be tested on
one of the yycix route servers?

I'll let it run on my home router, if that doesn't cause issues in a
week or so; we can consider rs2.yycix.ca

Kind regards,

Job

On Fri, Mar 02, 2018 at 04:55:23PM +0100, Claudio Jeker wrote:
> On Wed, Feb 07, 2018 at 05:52:09AM +0100, Claudio Jeker wrote:
> > This diff changes the way bgpd does updates. Instead of having its own
> > special update queue/tree it uses a regular RIB (Adj-RIB-Out) to store all
> > updates to be sent. Stuff that has been sent is linked to the prefixes
> > queue. On the peer there are also queues for updates and withdraws.
> > The whole update code becomes a lot simpler but also results in the bulk
> > of the diff. Other changes include the bgpctl show rib handling (we can
> > just walk the Adj-RIB-Out now). Last but not least the EOR records are
> > also now a magic rde_aspath (flag F_ATTR_EOR) which is added to the update
> > queue.
> > 
> > This diff is still very large and the changes are intrusive so reviews and
> > testing is very welcome.
> 
> No news on this? Anyone?
> 
> -- 
> :wq Claudio
> 
> Index: rde.c
> ===
> RCS file: /cvs/src/usr.sbin/bgpd/rde.c,v
> retrieving revision 1.377
> diff -u -p -r1.377 rde.c
> --- rde.c 7 Feb 2018 00:02:02 -   1.377
> +++ rde.c 7 Feb 2018 00:02:18 -
> @@ -80,8 +80,6 @@ void rde_dump_rib_as(struct prefix *, 
>int);
>  void  rde_dump_filter(struct prefix *,
>struct ctl_show_rib_request *);
> -void  rde_dump_filterout(struct rde_peer *, struct prefix *,
> -  struct ctl_show_rib_request *);
>  void  rde_dump_upcall(struct rib_entry *, void *);
>  void  rde_dump_prefix_upcall(struct rib_entry *, void *);
>  void  rde_dump_ctx_new(struct ctl_show_rib_request *, pid_t,
> @@ -2262,71 +2260,33 @@ rde_dump_rib_as(struct prefix *p, struct
>  }
>  
>  void
> -rde_dump_filterout(struct rde_peer *peer, struct prefix *p,
> -struct ctl_show_rib_request *req)
> +rde_dump_filter(struct prefix *p, struct ctl_show_rib_request *req)
>  {
> - struct bgpd_addr addr;
> - struct rde_aspath   *asp, *fasp;
> - enum filter_actions  a;
> + struct rde_aspath   *asp;
>  
> - if (up_test_update(peer, p) != 1)
> + if (req->peerid && req->peerid != prefix_peer(p)->conf.id)
>   return;
> + if (p->flags & F_PREFIX_USE_PEER)
> + return; /* pending withdraw, skip */
>  
> - pt_getaddr(p->re->prefix, &addr);
>   asp = prefix_aspath(p);
> - a = rde_filter(out_rules, &fasp, peer, asp, &addr,
> - p->re->prefix->prefixlen, asp->peer);
> - if (fasp)
> - fasp->peer = asp->peer;
> - else
> - fasp = asp;
> -
> - if (a == ACTION_ALLOW)
> - rde_dump_rib_as(p, fasp, req->pid, req->flags);
> -
> - if (fasp != asp)
> - path_put(fasp);
> -}
> -
> -void
> -rde_dump_filter(struct prefix *p, struct ctl_show_rib_request *req)
> -{
> - struct rde_peer *peer;
> - struct rde_aspath   *asp;
> -
> - if (req->flags & F_CTL_ADJ_IN ||
> - !(req->flags & (F_CTL_ADJ_IN|F_CTL_ADJ_OUT))) {
> - asp = prefix_aspath(p);
> - if (req->peerid && req->peerid != asp->peer->conf.id)
> - return;
> - if (req->type == IMSG_CTL_SHOW_RIB_AS &&
> - !aspath_match(asp->aspath->data, asp->aspath->len,
> - &req->as, req->as.as))
> - return;
> - if (req->type == IMSG_CTL_SHOW_RIB_COMMUNITY &&
> - !community_match(asp, req->community.as,
> - req->community.type))
> - return;
> - if (req->type == IMSG_CTL_SHOW_RIB_EXTCOMMUNITY &&
> - !community_ext_match(asp, &req->extcommunity, 0))
> - return;
> - if (req->type == IMSG_CTL_SHOW_RIB_LARGECOMMUNITY &&
> - !community_large_match(asp, req->large_community.as,
> - req->large_community.ld1, req->large_community.ld2))
> - return;
> - if ((req->flags & F_CTL_ACTIVE) && p->re->active != p)
> - return;
> - rde_dump_rib_as(p, asp, req->pid, req->flags);
> - } else if (req->flags & F_CTL_ADJ_OUT) {
> - if (p->re->active != p)
> - /* only consider active prefix */
> - return;
> - if (req->peerid) {
> - if ((peer = peer_get(req->peerid)) != NULL)
> - rde_dump_filterout(peer, p, req);
> - return;
> - }
> - }
> + if (req->type == IMSG_CTL_SHOW_RIB_AS &&
> + !aspath_match(asp->aspath->data, asp->aspath->len

Re: A patch that fixes /usr/games/hack

2018-03-05 Thread tonypony76
The following patch is a slight improvement of the patch that I posted
on Thursday.  In particular, this patch places saved games exactly where
the man page says they should be placed.

This patch, together with the patch that prevents segmentation faults
(http://marc.info/?l=openbsd-tech&m=152020888711960), should be all that
is needed to make /usr/games/hack playable on OpenBSD 6.2 without
setting the setgid bit.

Remember to create the /usr/share/games/hack directory before trying to
install this patched version of hack.


--- games/hack/config.h.origFri Oct 16 07:37:46 2015
+++ games/hack/config.h Mon Mar  5 02:31:18 2018
@@ -77,10 +77,10 @@
 #define WIZARD  "bruno"/* the person allowed to use the -D option */
 #define RECORD "record"/* the file containing the list of topscorers */
 #defineNEWS"news"  /* the file containing the latest hack news */
-#defineHELP"help"  /* the file containing a description of the 
commands */
-#defineSHELP   "hh"/* abbreviated form of the same */
-#defineRUMORFILE   "rumors"/* a file with fortune cookies 
*/
-#defineDATAFILE"data"  /* a file giving the meaning of symbols 
used */
+#defineHELP"/usr/share/games/hack/help"/* the file containing 
a description of the commands */
+#defineSHELP   "/usr/share/games/hack/hh"  /* abbreviated form of 
the same */
+#defineRUMORFILE   "/usr/share/games/hack/rumors"  /* a file with 
fortune cookies */
+#defineDATAFILE"/usr/share/games/hack/data"/* a file 
giving the meaning of symbols used */
 #defineFMASK   0660/* file creation mask */
 #defineHLOCK   "perm"  /* an empty file used for locking purposes */
 #define LLOCK  "safelock"  /* link to previous */
@@ -93,7 +93,7 @@
  * (This might be preferable for security reasons.)
  * #define DEF_PAGER   ".../mydir/mypager"
  */
-#defineDEF_PAGER   _PATH_PAGER
+/* #define DEF_PAGER   _PATH_PAGER */
 
 /*
  * If you define MAIL, then the player will be notified of new mail
@@ -120,7 +120,7 @@
 #ifdef QUEST
 #define HACKDIR _PATH_QUEST
 #else /* QUEST */
-#define HACKDIR_PATH_HACK
+/* #define HACKDIR _PATH_HACK */
 #endif /* QUEST */
 
 /*
@@ -130,7 +130,7 @@
  * since the user might create files in a directory of his choice.
  * Of course SECURE is meaningful only if HACKDIR is defined.
  */
-#define SECURE /* do setuid(getuid()) after chdir() */
+/* #define SECURE */   /* do setuid(getuid()) after chdir() */
 
 /*
  * If it is desirable to limit the number of people that can play Hack
--- games/hack/hack.main.c.orig Sat Jan  9 21:54:11 2016
+++ games/hack/hack.main.c  Mon Mar  5 16:17:31 2018
@@ -62,6 +62,7 @@
  */
 
 #include 
+#include 
 
 #include 
 #include 
@@ -538,6 +539,8 @@
}
 
/* warn the player if he cannot write the record file */
+   /* warn the player if he cannot read the permanent lock file */
+   /* warn the player if he cannot create the save directory */
/* perhaps we should also test whether . is writable */
/* unfortunately the access systemcall is worthless */
if(wr) {
@@ -545,11 +548,20 @@
 
if(dir == NULL)
dir = ".";
-   if((fd = open(RECORD, O_RDWR)) < 0) {
+   if((fd = open(RECORD, O_RDWR | O_CREAT, FMASK)) < 0) {
printf("Warning: cannot write %s/%s", dir, RECORD);
getret();
} else
(void) close(fd);
+   if((fd = open(HLOCK, O_RDONLY | O_CREAT, FMASK)) < 0) {
+   printf("Warning: cannot read %s/%s", dir, HLOCK);
+   getret();
+   } else
+   (void) close(fd);
+   if(mkdir("save", 0770) && errno != EEXIST) {
+   printf("Warning: cannot create %s/save", dir);
+   getret();
+   }
}
 }
 #endif
--- games/hack/Makefile.origMon Jul 10 21:30:37 2017
+++ games/hack/Makefile Mon Mar  5 02:31:18 2018
@@ -27,12 +27,7 @@
${HOSTCC} ${CFLAGS} ${LDFLAGS} ${LDSTATIC} -o ${.TARGET} 
${.CURDIR}/${.PREFIX}.c ${LDADD}
 
 beforeinstall: 
-   ${INSTALL} ${INSTALL_COPY} -o root -g games -m 660 /dev/null \
-   ${DESTDIR}/var/games/hackdir/perm
-   ${INSTALL} ${INSTALL_COPY} -o root -g games -m 660 /dev/null \
-   ${DESTDIR}/var/games/hackdir/record
${INSTALL} ${INSTALL_COPY} -o ${BINOWN} -g ${BINGRP} -m 444 
${.CURDIR}/help \
-   ${.CURDIR}/hh ${.CURDIR}/data ${DESTDIR}/var/games/hackdir
-   rm -f ${DESTDIR}/var/games/hackdir/bones*
+   ${.CURDIR}/hh ${.CURDIR}/data ${.CURDIR}/rumors 
${DESTDIR}/usr/share/games/hack
 
 .include 
--- games/hack/hack.6.orig  Fri Sep  9 15:32:28 2016
+++ games/hack/hack.6   Mon Mar  5 15:41:06 2018
@@ -75,13 +75,6 @@
 .Op Fl d Ar directory
 .Op Ar playername ...
 .Sh DESCRIPTION
-.Bf -symbolic
-.Nm
-is currently unus

Re: SA_RESETHAND race (or the mpv(1) hanging story)

2018-03-05 Thread Hiltjo Posthuma
On Fri, Mar 02, 2018 at 02:18:46PM +0100, Hiltjo Posthuma wrote:
> On Wed, Feb 21, 2018 at 02:15:07PM +0100, Martin Pieuchot wrote:
> > Diff below fixes a race in signal handling that can be triggered when
> > a multi-threaded process installs a signal handler with SA_RESETHAND.
> > 
> > I described a case of this problem on bugs@ a month ago:
> >   https://marc.info/?l=openbsd-bugs&m=151672599508049&w=2
> > 
> > The race occurs when one of the threads is doing a NOLOCK syscall, like
> > futex(2):
> > 
> > CPU0:
> >   Before returning to userland this thread will call CURSIG() without
> >   KERNEL_LOCK(), issignal() will look at `ps_sigact', see that there's
> >   a handler and return the signal number.  After that the thread will
> >   call postsig() and spin on the KERNEL_LOCK().
> > 
> > CPU1:
> >   In the meantime another thread, with the KERNEL_LOCK(), also looked at
> >   `ps_sigact' and is already processing the signal.  Since the handler
> >   has been installed with SA_RESETHAND it will reset the action to
> >   SIG_DFL then release the KERNEL_LOCK().
> > 
> > CPU0:
> >   After grabbing the KERNEL_LOCK() inside postsig(), the thread tries
> >   to process an already processed signal, see that the actions is
> >   SIG_DFL and call sigexit() while all other threads are SSTOP'ed.
> > 
> > 
> > Diff below fixes that by serializing changes to `ps_sigact' via the
> > KERNEL_LOCK().  I also introduce postsig_done(), gypped from FreeBSD,
> > to assert that the lock is held and to prepare for finer grained
> > locking.
> > 
> > Tests, oks?
> > 
> > Index: kern/kern_sig.c
> > ===
> > RCS file: /cvs/src/sys/kern/kern_sig.c,v
> > retrieving revision 1.215
> > diff -u -p -r1.215 kern_sig.c
> > --- kern/kern_sig.c 19 Feb 2018 08:59:52 -  1.215
> > +++ kern/kern_sig.c 21 Feb 2018 13:09:54 -
> > @@ -82,6 +82,7 @@ void proc_stop(struct proc *p, int);
> >  void proc_stop_sweep(void *);
> >  struct timeout proc_stop_to;
> >  
> > +void postsig(struct proc *, int);
> >  int cansignal(struct proc *, struct process *, int);
> >  
> >  struct pool sigacts_pool;  /* memory pool for sigacts structures */
> > @@ -747,6 +748,27 @@ pgsignal(struct pgrp *pgrp, int signum, 
> >  }
> >  
> >  /*
> > + * Recalculate the signal mask and reset the signal disposition after
> > + * usermode frame for delivery is formed.
> > + */
> > +void
> > +postsig_done(struct proc *p, int signum, struct sigacts *ps)
> > +{
> > +   int mask = sigmask(signum);
> > +
> > +   KERNEL_ASSERT_LOCKED();
> > +
> > +   p->p_ru.ru_nsignals++;
> > +   atomic_setbits_int(&p->p_sigmask, ps->ps_catchmask[signum]);
> > +   if ((ps->ps_sigreset & mask) != 0) {
> > +   ps->ps_sigcatch &= ~mask;
> > +   if (signum != SIGCONT && sigprop[signum] & SA_IGNORE)
> > +   ps->ps_sigignore |= mask;
> > +   ps->ps_sigact[signum] = SIG_DFL;
> > +   }
> > +}
> > +
> > +/*
> >   * Send a signal caused by a trap to the current thread
> >   * If it will be caught immediately, deliver it with correct code.
> >   * Otherwise, post it normally.
> > @@ -780,16 +802,9 @@ trapsignal(struct proc *p, int signum, u
> > p->p_sigmask, code, &si);
> > }
> >  #endif
> > -   p->p_ru.ru_nsignals++;
> > (*pr->ps_emul->e_sendsig)(ps->ps_sigact[signum], signum,
> > p->p_sigmask, trapno, code, sigval);
> > -   atomic_setbits_int(&p->p_sigmask, ps->ps_catchmask[signum]);
> > -   if ((ps->ps_sigreset & mask) != 0) {
> > -   ps->ps_sigcatch &= ~mask;
> > -   if (signum != SIGCONT && sigprop[signum] & SA_IGNORE)
> > -   ps->ps_sigignore |= mask;
> > -   ps->ps_sigact[signum] = SIG_DFL;
> > -   }
> > +   postsig_done(p, signum, ps);
> > } else {
> > p->p_sisig = signum;
> > p->p_sitrapno = trapno; /* XXX for core dump/debugger */
> > @@ -1330,9 +1345,8 @@ proc_stop_sweep(void *v)
> >   * from the current set of pending signals.
> >   */
> >  void
> > -postsig(int signum)
> > +postsig(struct proc *p, int signum)
> >  {
> > -   struct proc *p = curproc;
> > struct process *pr = p->p_p;
> > struct sigacts *ps = pr->ps_sigacts;
> > sig_t action;
> > @@ -1341,12 +1355,8 @@ postsig(int signum)
> > union sigval sigval;
> > int s, code;
> >  
> > -#ifdef DIAGNOSTIC
> > -   if (signum == 0)
> > -   panic("postsig");
> > -#endif
> > -
> > -   KERNEL_LOCK();
> > +   KASSERT(signum != 0);
> > +   KERNEL_ASSERT_LOCKED();
> >  
> > mask = sigmask(signum);
> > atomic_clearbits_int(&p->p_siglist, mask);
> > @@ -1366,7 +1376,7 @@ postsig(int signum)
> >  #ifdef KTRACE
> > if (KTRPOINT(p, KTR_PSIG)) {
> > siginfo_t si;
> > -   
> > +
> > initsiginfo(&si, signum, trapno, code, sigval);
> > ktrpsig(p, signum, action, p->p_fla

Re: update ifstated parser

2018-03-05 Thread Rob Pierce
On Mon, Feb 26, 2018 at 05:10:43PM -0600, Michael Graves wrote:
> Hello
> 
> I use ifstated(8) to track the state of the the external interface that is
> configured via dhcp and based upon the state, (re)configure a VXLAN
> interface.
> The ifstated.conf currently looks like
> 
> ===
> exif="em0"
> vxif="vxlan0"
> 
> init-state state_down
> 
> state state_up {
>   init {
> run "ifconfig vlxna0 up"
>   }
>   if ( "ifconfig em0 | grep -q inet" every 60 )
> run "sleep 30 && ifconfig vxlan0 tunnel `ifconfig em0 | \
>  sed -nre 's/.*inet ([^ ]+).*/\1/p'` \
> `dig +short name-of-remote-device`"
>   if $exif.link.down
> set-state state_down
> }
> 
> state state_down {
>   init {
> run "ifconfig vxlan0 down"
>   }
>   if $exif.link.up
> set-state state_up
> }
> ===
> 
> The problem I ran into is that when I tried to substitute the vxlan0 and em0
> entries with exif and vxif in the 'run' statements no macro expansion
> occurred.
> This patch allows macro expansion within the 'run' and 'if' statements.
> 
> I appreciate any feedback.
> Regards

> Index: parse.y
> ===
> RCS file: /cvs/src/usr.sbin/ifstated/parse.y,v
> retrieving revision 1.47
> diff -u -p -r1.47 parse.y
> --- parse.y   21 Aug 2017 17:38:55 -  1.47
> +++ parse.y   26 Feb 2018 22:47:11 -
> @@ -509,9 +509,10 @@ int
>  yylex(void)
>  {
>   u_char   buf[8096];
> - u_char  *p, *val;
> + u_char  *p, *p1, *val;
>   int  quotec, next, c;
>   int  token;
> + size_t  x;
>  
>  top:
>   p = buf;
> @@ -575,6 +576,35 @@ top:
>   } else if (c == '\0') {
>   yyerror("syntax error");
>   return (findeol());
> + } else if (c == '$') {
> + p1 = p;
> + while (1) {
> + if ((c = lgetc(0)) == EOF)
> + return (0);
> + if (p1 + 1 >= buf + sizeof(buf) - 1) {
> + yyerror("string too long");
> + return (findeol());
> + }
> + if (isalnum(c) || c == '_') {
> + *p1++ = c;
> + continue;
> + }
> + *p1 = '\0';
> + lungetc(c);
> + break;
> + }
> + val = symget(p);
> + if (val == NULL) {
> + yyerror("macro '%s' not defined", buf);
> + return (findeol());
> + }
> + x = strlcpy(p,val,(buf-p));
> + if (x >= (buf-p)) {
> + yyerror("string too long");
> + return (findeol());
> + }
> + p += x;
> + continue;
>   }
>   if (p + 1 >= buf + sizeof(buf) - 1) {
>   yyerror("string too long");

Hey Michael,

Thank you for your email. I have been playing with your diff and will send you
some comments shortly. This might be worth future consideration.

For now, I think we should update the man page to clearly state that macro
expansion does not take place inside quotes as is currently done in the other
man pages.

Ok?

Index: ifstated.conf.5
===
RCS file: /cvs/src/usr.sbin/ifstated/ifstated.conf.5,v
retrieving revision 1.11
diff -u -p -r1.11 ifstated.conf.5
--- ifstated.conf.5 3 Mar 2018 02:57:17 -   1.11
+++ ifstated.conf.5 5 Mar 2018 18:39:06 -
@@ -55,6 +55,8 @@ instead of using the first state defined
 Macros can be defined that will later be expanded in context.
 Macro names must start with a letter, digit, or underscore,
 and may contain any of those characters.
+Macros are not expanded inside quotes.
+.Pp
 Macro names may not be reserved words like, for example,
 .Ar state
 or



mfii(4): add bio(4) support

2018-03-05 Thread Naoki Fukaumi
Hi tech@,

This patch adds bio(4) support for mfii(4).
# with "mfii(4): use MFII_FUNCTION_PASSTHRU_IO for MFI commands"

most parts are taken from mfi(4), plus fix for rebuilding (bioctl -R).

--- sys/dev/ic/mfireg.h
+++ sys/dev/ic/mfireg.h
@@ -139,6 +139,9 @@
 #define MR_DCMD_CONF_GET   0x0401
 #define MR_DCMD_CFG_ADD0x0402
 #define MR_DCMD_CFG_CLEAR  0x0403
+#define MR_DCMD_CFG_MAKE_SPARE 0x0404
+#define MR_DCMD_CFG_FOREIGN_SCAN   0x04060100
+#define MR_DCMD_CFG_FOREIGN_CLEAR  0x04060500
 #define MR_DCMD_BBU_GET_STATUS 0x0501
 #define MR_DCMD_BBU_GET_CAPACITY_INFO  0x0502
 #define MR_DCMD_BBU_GET_DESIGN_INFO0x0503
@@ -1228,3 +1231,13 @@ struct mfi_pr_properties {
uint32_texec_freq;
uint32_tclear_freq;
 } __packed;
+
+/* We currently don't know the full details of the following struct */
+struct mfii_foreign_scan_cfg {
+   char data[24];
+};
+
+struct mfii_foreign_scan_info {
+   uint32_t count; /* Number of foreign configs found */
+   struct mfii_foreign_scan_cfg cfgs[8];
+};
--- sys/dev/pci/mfii.c
+++ sys/dev/pci/mfii.c
@@ -22,10 +22,14 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
+#include 
+#include 
 
+#include 
 #include 
 #include 
 
@@ -307,7 +311,35 @@ struct mfii_softc {
struct mfii_pd_softc*sc_pd;
struct scsi_iopool  sc_iopool;
 
+   /* save some useful information for logical drives that is missing
+* in sc_ld_list
+*/
+   struct {
+   uint32_tld_present;
+   charld_dev[16]; /* device name sd? */
+   }   sc_ld[MFI_MAX_LD];
+
+   /* scsi ioctl from sd device */
+   int (*sc_ioctl)(struct device *, u_long, caddr_t);
+
+   uint32_tsc_ld_cnt;
+
+   /* bio */
+   struct mfi_conf *sc_cfg;
struct mfi_ctrl_infosc_info;
+   struct mfi_ld_list  sc_ld_list;
+   struct mfi_ld_details   *sc_ld_details; /* array to all logical disks */
+   int sc_no_pd; /* used physical disks */
+   int sc_ld_sz; /* sizeof sc_ld_details */
+
+   /* mgmt lock */
+   struct rwlock   sc_lock;
+
+   /* sensors */
+   struct ksensordev   sc_sensordev;
+   struct ksensor  *sc_bbu;
+   struct ksensor  *sc_bbu_status;
+   struct ksensor  *sc_sensors;
 };
 
 #ifdef MFII_DEBUG
@@ -355,13 +387,15 @@ struct cfdriver mfii_cd = {
 
 void   mfii_scsi_cmd(struct scsi_xfer *);
 void   mfii_scsi_cmd_done(struct mfii_softc *, struct mfii_ccb *);
+intmfii_scsi_ioctl(struct scsi_link *, u_long, caddr_t, int);
+intmfii_ioctl_cache(struct scsi_link *, u_long, struct dk_cache *);
 
 struct scsi_adapter mfii_switch = {
mfii_scsi_cmd,
scsi_minphys,
NULL, /* probe */
NULL, /* unprobe */
-   NULL  /* ioctl */
+   mfii_scsi_ioctl
 };
 
 void   mfii_pd_scsi_cmd(struct scsi_xfer *);
@@ -409,9 +443,11 @@ intmfii_load_mfa(struct mfii_softc 
*, struct mfii_ccb *,
 
 intmfii_mfa_poll(struct mfii_softc *, struct mfii_ccb *);
 
-intmfii_mgmt(struct mfii_softc *, struct mfii_ccb *,
-   u_int32_t, const union mfi_mbox *,
-   void *, size_t, int);
+intmfii_mgmt(struct mfii_softc *, uint32_t, uint32_t,
+   size_t, void *, const union mfi_mbox *);
+intmfii_do_mgmt(struct mfii_softc *, struct mfii_ccb *,
+   uint32_t, uint32_t, size_t, void *,
+   const union mfi_mbox *);
 void   mfii_empty_done(struct mfii_softc *, struct mfii_ccb *);
 
 intmfii_scsi_cmd_io(struct mfii_softc *,
@@ -445,6 +481,42 @@ void   mfii_aen_pd_remove(struct 
mfii_softc *,
 void   mfii_aen_pd_state_change(struct mfii_softc *,
const struct mfi_evtarg_pd_state *);
 
+#if NBIO > 0
+intmfii_ioctl(struct device *, u_long, caddr_t);
+intmfii_bio_getitall(struct mfii_softc *);
+intmfii_ioctl_inq(struct mfii_softc *, struct bioc_inq *);
+intmfii_ioctl_vol(struct mfii_softc *, struct bioc_vol *);
+intmfii_ioctl_disk(struct mfii_softc *, struct bioc_disk *);
+intmfii_ioctl_alarm(struct mfii_softc *, struct bioc_alarm *);
+intmfii_ioctl_blink(struct mfii_softc *sc, struct bioc_blink *);
+intmfii_ioctl_setstate(struct mfii_softc *,
+   struct bioc_setstate *);
+intmfii_ioctl_patrol(struct mfii_soft

mfii(4): use MFII_FUNCTION_PASSTHRU_IO for MFI commands

2018-03-05 Thread Naoki Fukaumi
Hi tech@,

while trying to add bio(4) support to mfii(4), we noticed that SAS2208
based card with cache memory hangs on boot.
 https://marc.info/?t=14773842861&r=1&w=2

after investigation, we made conclusion that MPII SCSI PASSTHRU feature
need to be used for sending MFI commands (such as DCMD_*) instead of
using MFA request.

this patch shouldn't change any functionality/behavior, but this is
required for upcoming bio(4) support.

tested on: SAS2208, SAS3008, and SAS3108

--- sys/dev/pci/mfii.c
+++ sys/dev/pci/mfii.c
@@ -44,6 +44,8 @@
 
 #define MFII_OSTS_INTR_VALID   0x0009
 #define MFII_RPI   0x6c /* reply post host index */
+#define MFII_OSP2  0xb4 /* outbound scratch pad 2 */
+#define MFII_OSP3  0xb8 /* outbound scratch pad 3 */
 
 #define MFII_REQ_TYPE_SCSI MPII_REQ_DESCR_SCSI_IO
 #define MFII_REQ_TYPE_LDIO (0x7 << 1)
@@ -51,20 +53,42 @@
 #define MFII_REQ_TYPE_NO_LOCK  (0x2 << 1)
 #define MFII_REQ_TYPE_HI_PRI   (0x6 << 1)
 
-#define MFII_REQ_MFA(_a)   htole64((_a) | MFII_REQ_TYPE_MFA)
-
 #define MFII_FUNCTION_PASSTHRU_IO  (0xf0)
 #define MFII_FUNCTION_LDIO_REQUEST (0xf1)
 
-struct mfii_request_descr {
+#define MFII_MAX_CHAIN_UNIT0x0040
+#define MFII_MAX_CHAIN_MASK0x03E0
+#define MFII_MAX_CHAIN_SHIFT   5
+
+#define MFII_256K_IO   128
+#define MFII_1MB_IO(MFII_256K_IO * 4)
+
+#define MFII_CHAIN_FRAME_MIN   1024
+
+struct mfii_scsi_io_request_descr {
u_int8_tflags;
u_int8_tmsix_index;
u_int16_t   smid;
-
u_int16_t   lmid;
u_int16_t   dev_handle;
 } __packed;
 
+struct mfii_mfa_io_request_descr {
+   u_int32_t   flags:8;
+   u_int32_t   addr1:24;
+   u_int32_t   addr2;
+} __packed;
+
+union mfii_request_descr {
+   struct mfii_scsi_io_request_descr   scsi;
+   struct mfii_mfa_io_request_descrmfa;
+   struct {
+   u_int32_t   lo;
+   u_int32_t   hi;
+   } __packed u;
+   u_int64_t   word;
+};
+
 #define MFII_RAID_CTX_IO_TYPE_SYSPD(0x1 << 4)
 #define MFII_RAID_CTX_TYPE_CUDA(0x2 << 4)
 
@@ -180,6 +204,10 @@ struct mfii_ccb {
u_int64_t   ccb_request_dva;
bus_addr_t  ccb_request_offset;
 
+   void*ccb_mfi;
+   u_int64_t   ccb_mfi_dva;
+   bus_addr_t  ccb_mfi_offset;
+
struct mfi_sense*ccb_sense;
u_int64_t   ccb_sense_dva;
bus_addr_t  ccb_sense_offset;
@@ -189,7 +217,7 @@ struct mfii_ccb {
bus_addr_t  ccb_sgl_offset;
u_int   ccb_sgl_len;
 
-   struct mfii_request_descr ccb_req;
+   union mfii_request_descr ccb_req;
 
bus_dmamap_tccb_dmamap;
 
@@ -250,6 +278,7 @@ struct mfii_softc {
struct mutexsc_ccb_mtx;
struct mutexsc_post_mtx;
 
+   u_int   sc_max_fw_cmds;
u_int   sc_max_cmds;
u_int   sc_max_sgl;
 
@@ -259,6 +288,7 @@ struct mfii_softc {
struct mfii_dmamem  *sc_reply_postq;
 
struct mfii_dmamem  *sc_requests;
+   struct mfii_dmamem  *sc_mfi;
struct mfii_dmamem  *sc_sense;
struct mfii_dmamem  *sc_sgl;
 
@@ -280,6 +310,32 @@ struct mfii_softc {
struct mfi_ctrl_infosc_info;
 };
 
+#ifdef MFII_DEBUG
+#define DPRINTF(x...)  do { if (mfii_debug) printf(x); } while(0)
+#define DNPRINTF(n,x...)   do { if (mfii_debug & n) printf(x); } while(0)
+#defineMFII_D_CMD  0x0001
+#defineMFII_D_INTR 0x0002
+#defineMFII_D_MISC 0x0004
+#defineMFII_D_DMA  0x0008
+#defineMFII_D_IOCTL0x0010
+#defineMFII_D_RW   0x0020
+#defineMFII_D_MEM  0x0040
+#defineMFII_D_CCB  0x0080
+uint32_t   mfii_debug = 0
+/* | MFII_D_CMD */
+/* | MFII_D_INTR */
+/* | MFII_D_MISC */
+/* | MFII_D_DMA */
+/* | MFII_D_IOCTL */
+/* | MFII_D_RW */
+/* | MFII_D_MEM */
+/* | MFII_D_CCB */
+   ;
+#else
+#define DPRINTF(x...)
+#define DNPRINTF(n,x...)
+#endif
+
 intmfii_match(struct device *, void *, void *);
 void   mfii_attach(struct device *, struct device *, void *);
 intmfii_detach(struct device *, int);
@@ -356,6 +412,7 @@ int mfii_mfa_poll(struct mfii_softc *, 
struct mfii_ccb *);
 intmfii_mgmt(struct mfii_softc *, struct mfii_ccb *,
u_int32_t, const union mfi_mbox *,
void