Re: Document "machine video" command in the boot(8) man page (offered in 6.2 EFI BOOTX64)

2018-02-17 Thread Jason McIntyre
On Sat, Feb 10, 2018 at 02:23:35AM -0500, Tinker wrote:
> Hi,
> 
> The "OpenBSD/amd64 BOOTX64 3.35" EFI boot console bundled with OpenBSD 6.2 
> offers the "video" subcommand to the "machine" command.
> 
> Please add it to boot(8).
> 
> (The command is not offered by 6.2's MBR boot console.)
> 
> Interaction:
> 
>  boot> help
>  commands: # boot echo env help ls machine reboot set stty time
>  machine: diskinfo memory video exit poweroff
>  boot> machine video
>  Mode 0: 80 x 25
>  Mode 1: 80 x 50
>  Mode 2: 100 x 31
>  Mode 3: 80 x 26
>  
>  Current mode = 2
> 
> And running machine video with an integer argument changes the resolution to 
> the respective setting.
> 
> Thanks,
> Tinker
> 

documented, for some value of documented. next time, a diff would be
nice ;)

jmc



Re: vmd: vm extremely slow; # time ls /var*; takes 14 seconds

2018-02-17 Thread Pratik Vyas

* Abel Abraham Camarillo Ojeda  [2018-02-17 23:11:52 -0600]:


To: bugs@openbsd.org
Subject: vmd: vm extremely slow; time ls /var*; takes 14 seconds
From: root
Cc: root
Reply-To: root


Synopsis:  vmd: vm extremely slow
Category:  amd64
Environment:

   System  : OpenBSD 6.2
   Details : OpenBSD 6.2-current (GENERIC.MP) #5: Mon Feb 12
21:05:57 MST 2018

dera...@amd64.openbsd.org:/usr/src/sys/arch/amd64/compile/GENERIC.MP

   Architecture: OpenBSD.amd64
   Machine : amd64

Description:

   just running # time ls /var*; after booting bsd.rd
   takes like 14 seconds, according to my phone clock

   don't know if it happened before because i'm just starting to
   try vmm

   i ran out of patience when trying to install OpenBSD
   because it takes ages...

   how to diagnose further?

   thanks


How-To-Repeat:


   Welcome to the OpenBSD/amd64 6.2 installation program.

(I)nstall, (U)pgrade, (A)utoinstall or (S)hell? (I)nstall, (U)pgrade,
(A)utoinstall or (S)hell? S
# time ls /var*
db empty  runtmptzlist
   0m00.02s real 0m00.00s user 0m00.00s system
# # time incorrectly reports 0s but on reality there happened like 14secs


Fix:

   unknown

SENDBUG: dmesg, pcidump, acpidump and usbdevs are attached.
SENDBUG: Feel free to delete or use the -D flag if they contain
sensitive information.

$ doas vmd -dv
startup
failed to open /etc/vm.conf: No such file or directory
test: started vm 1 successfully, tty /dev/ttypj

vm dmesg:

$ doas vmctl start test -b /bsd.rd -L -c
vmctl: starting without disks
Connected to /dev/ttypj (speed 115200)
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.2-current (RAMDISK_CD) #4: Mon Feb 12 21:10:26 MST 2018
   dera...@amd64.openbsd.org:/usr/src/sys/arch/amd64/compile/RAMDISK_CD
real mem = 520093696 (496MB)
avail mem = 500633600 (477MB)
enter_shared_special_pages: entered idt page va 0x8001 pa 0x1a24000
enter_shared_special_pages: entered kutext page va 0x81341000
pa 0x1341000
enter_shared_special_pages: entered kutext page va 0x81342000
pa 0x1342000
enter_shared_special_pages: entered kutext page va 0x81343000
pa 0x1343000
cpu_enter_pages: entered tss+gdt page at va 0x81856000 pa 0x1856000
cpu_enter_pages: entered t.stack page at va 0x81857000 pa 0x1857000
cpu_enter_pages: cif_tss.tss_rsp0 = 0x818573e0
mainbus0 at root
bios0 at mainbus0
acpi at bios0 not configured
cpu0 at mainbus0: (uniprocessor)
cpu0: AMD FX(tm)-6300 Six-Core Processor, 3512.49 MHz
cpu0: 
FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,SEP,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,MMX,FXSR,SSE,SSE2,SSE3,PCLMUL,SSSE3,FMA3,CX16,SSE4.1,SSE4.2,POPCNT,AES,XSAVE,AVX,F16C,HV,NXE,MMXX,FFXSR,PAGE1GB,RDTSCP,LONG,LAHF,CMPLEG,SVM,EAPICSP,AMCR8,ABM,SSE4A,MASSE,3DNOWP,OSVW,IBS,XOP,SKINIT,WDT,FMA4,TCE,NODEID,TBM,TOPEXT,CPCTR,ITSC,BMI1
cpu0: 64KB 64b/line 2-way I-cache, 16KB 64b/line 4-way D-cache, 2MB
64b/line 16-way L2 cache, 8MB 64b/line 64-way L3 cache
cpu0: ITLB 48 4KB entries fully associative, 24 4MB entries fully associative
cpu0: DTLB 64 4KB entries fully associative, 64 4MB entries fully associative
pvbus0 at mainbus0: OpenBSD
pci0 at mainbus0 bus 0
pchb0 at pci0 dev 0 function 0 "OpenBSD VMM Host" rev 0x00
virtio0 at pci0 dev 1 function 0 "Qumranet Virtio RNG" rev 0x00
viornd0 at virtio0
virtio0: irq 3
virtio1 at pci0 dev 2 function 0 "Qumranet Virtio Network" rev 0x00
vio0 at virtio1: address fe:e1:bb:d1:64:13
virtio1: irq 5
virtio2 at pci0 dev 3 function 0 "OpenBSD VMM Control" rev 0x00
virtio2: no matching child driver; not configured
isa0 at mainbus0
com0 at isa0 port 0x3f8/8 irq 4: ns16450, no fifo
com0: console
softraid0 at root
scsibus0 at softraid0: 256 targets
root on rd0a swap on rd0b dump on rd0b
erase ^?, werase ^W, kill ^U, intr ^C, status ^T

Welcome to the OpenBSD/amd64 6.2 installation program.

(I)nstall, (U)pgrade, (A)utoinstall or (S)hell? (I)nstall, (U)pgrade,
(A)utoinstall or (S)hell? S
# time ls /var*
db empty  runtmptzlist
   0m00.02s real 0m00.00s user 0m00.00s system
#

dmesg:
OpenBSD 6.2-current (GENERIC.MP) #5: Mon Feb 12 21:05:57 MST 2018
   dera...@amd64.openbsd.org:/usr/src/sys/arch/amd64/compile/GENERIC.MP
real mem = 8517390336 (8122MB)
avail mem = 8252248064 (7869MB)
enter_shared_special_pages: entered idt page va 0x8001 pa 0x1d5a000
enter_shared_special_pages: entered kutext page va 0x81832000
pa 0x1832000
enter_shared_special_pages: entered kutext page va 0x81833000
pa 0x1833000
enter_shared_special_pages: entered kutext page va 0x81834000
pa 0x1834000
enter_shared_special_pages: entered kudata page va 0x81ac9000
pa 0x1ac9000
cpu_enter_pages: entered tss+gdt page at va 0x81ab4000 pa 0x1ab4000
cpu_enter_pages: entered t.stack page a

Re: vmctl(8) pause never returns

2018-02-17 Thread Abel Abraham Camarillo Ojeda
On Fri, Feb 16, 2018 at 11:15 AM, Pratik Vyas  wrote:
> * Abel Abraham Camarillo Ojeda  [2018-02-15 06:06:50
> -0600]:
>
>>> Synopsis:  vmctl(8) pause never returns
>
>
> This should fix it. It checks if vm id is valid before sending to vmm
> for pausing. The 'lock' is caused by vmm sending back ENOENT for a non
> existent vm but vmd drops the message because it doesn't recogize the
> vmid vmm is talking about. This is an artifact of the 'policy' don't
> trust any imsg from a sibling priv sep processes and do your own
> checking.
>
>
> Index: usr.sbin/vmd/vmd.c
> ===
> RCS file: /home/pdvyas/cvs/src/usr.sbin/vmd/vmd.c,v
> retrieving revision 1.79
> diff -u -p -a -u -r1.79 vmd.c
> --- usr.sbin/vmd/vmd.c  10 Jan 2018 14:59:59 -  1.79
> +++ usr.sbin/vmd/vmd.c  16 Feb 2018 17:06:20 -
> @@ -186,6 +186,10 @@ vmd_dispatch_control(int fd, struct priv
> } else {
> vid.vid_id = vm->vm_vmid;
> }
> +   } else if (vm_getbyid(vid.vid_id) == NULL) {
> +   res = ENOENT;
> +   cmd = IMSG_VMDOP_PAUSE_VM_RESPONSE;
> +   break;
> }
> proc_compose_imsg(ps, PROC_VMM, -1, imsg->hdr.type,
> imsg->hdr.peerid, -1, &vid, sizeof(vid));

I confirm this fixes the issue

thanks



Re: LSI Logic MegaRAID SAS 9240-8i Panic

2018-02-17 Thread Shane Harbour

On 2018-01-07 20:24, Mike Larkin wrote:

On Sun, Jan 07, 2018 at 04:57:22PM -0700, Shane Harbour wrote:

Hello,
I'm running into the following panic when trying to boot the OpenBSD 6.2
release install disc (as well as the latest snapshot) with an LSI Logic
MegaRAID SAS 9240-8i (mfi driver) card installed in the machine.  I take the
card out and it boots just fine from the disc, but the following panic
happens with the RAID card in:

---
boot>
cannot open cd0a:/etc/random.see: No such file or directory
booting cd0a:/6.2/amd64/bsd.rd: 3371132+1459200+3873512+0+598016
[373741+82+427200+282103]=0x9e99c0
entry point at 0x1000158
panic: init_x86_64: can't find end of memory

The operating system has halted.
Please press any key to reboot.
---

The system is in an Intel Core 2 Quad system with 8GB of RAM. The RAID is
setup in two logical drives, one in RAID5 and the other in RAID1.

If you need any other information, just let me know.

Thanks,
Shane



sendbug from the working boot please

also please send output of "machine memory" from the boot> prompt, while
the card is plugged in.

-ml



Sorry about taking so long to get this.  Work has been eating my time.

Here is the output of "machine memory" with the card plugged in as well 
as the sendbug requested from the working boot.


Thanks,
Shane


boot> machine memory
Region 0: type 2 at 0x0 for 0KB
Low ram: 0KB  High ram: 0KB
Total free memory: 0KB
boot>

sendbug
---
>Synopsis:   Working boot without LSI Logic MegaRAID SAS 9240-8i
>Category:   kernel amd64
>Environment:
System  : OpenBSD 6.2
	Details : OpenBSD 6.2-current (GENERIC.MP) #8: Fri Feb 16 22:00:50 
MST 2018

 
dera...@amd64.openbsd.org:/usr/src/sys/arch/amd64/compile/GENERIC.MP

Architecture: OpenBSD.amd64
Machine : amd64
>Description:
Kernel panics when booting with LSI Logic MegaRAID SAS 9240-8i
installed.  This is the sendbug for the good boot without the
card installed.
>How-To-Repeat:
Install the LSI Logic MegaRAID SAS 9240-8i card in a PCI-e 16x
slot.  This is a PCI-e 8x card.
>Fix:
Unknown

dmesg:
OpenBSD 6.2-current (GENERIC.MP) #8: Fri Feb 16 22:00:50 MST 2018
dera...@amd64.openbsd.org:/usr/src/sys/arch/amd64/compile/GENERIC.MP
real mem = 8536326144 (8140MB)
avail mem = 8270610432 (7887MB)
enter_shared_special_pages: entered idt page va 0x8001 pa 
0x1d5a000
enter_shared_special_pages: entered kutext page va 0x81831000 pa 
0x1831000
enter_shared_special_pages: entered kutext page va 0x81832000 pa 
0x1832000
enter_shared_special_pages: entered kutext page va 0x81833000 pa 
0x1833000
enter_shared_special_pages: entered kudata page va 0x81ac9000 pa 
0x1ac9000

cpu_enter_pages: entered tss+gdt page at va 0x81a9e000 pa 0x1a9e000
cpu_enter_pages: entered t.stack page at va 0x81a9f000 pa 0x1a9f000
cpu_enter_pages: cif_tss.tss_rsp0 = 0x81a9f3e0
mpath0 at root
scsibus0 at mpath0: 256 targets
mainbus0 at root
bios0 at mainbus0: SMBIOS rev. 2.4 @ 0xf0100 (36 entries)
bios0: vendor Award Software International, Inc. version "F1" date 
12/31/2010

bios0: Gigabyte Technology Co., Ltd. G41MT-S2P
acpi0 at bios0: rev 0
acpi0: sleep states S0 S3 S4 S5
acpi0: tables DSDT FACP HPET MCFG TAMG APIC SSDT
acpi0: wakeup devices PEX0(S5) PEX1(S5) PEX2(S5) PEX3(S5) PEX4(S5) 
PEX5(S5) HUB0(S5) UAR1(S3) USB0(S3) USB1(S3) USB2(S3) USB3(S3) USBE(S3) 
AZAL(S5) PCI0(S5)

acpitimer0 at acpi0: 3579545 Hz, 24 bits
acpihpet0 at acpi0: 14318179 Hz
acpimcfg0 at acpi0 addr 0xe000, bus 0-255
acpimadt0 at acpi0 addr 0xfee0: PC-AT compat
lapic_map: entered lapic page va 0x81ab8000 pa 0xfee0
cpu0 at mainbus0: apid 0 (boot processor)
cpu0: Intel(R) Core(TM)2 Quad CPU Q8200 @ 2.33GHz, 2333.62 MHz
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,DTES64,MWAIT,DS-CPL,EST,TM2,SSSE3,CX16,xTPR,PDCM,SSE4.1,NXE,LONG,LAHF,PERF,SENSOR,MELTDOWN

cpu0: 2MB 64b/line 8-way L2 cache
cpu0: smt 0, core 0, package 0
mtrr: Pentium Pro MTRR support, 8 var ranges, 88 fixed ranges
cpu0: apic clock running at 333MHz
cpu0: mwait min=64, max=64, C-substates=0.2, IBE
cpu1 at mainbus0cpu_enter_pages: entered tss+gdt page at va 
0x80002200 pa 0x10f6db000
cpu_enter_pages: entered t.stack page at va 0x800022001000 pa 
0x10f6dc000

cpu_enter_pages: cif_tss.tss_rsp0 = 0x8000220013e0
: apid 3 (application processor)
cpu1: Intel(R) Core(TM)2 Quad CPU Q8200 @ 2.33GHz, 2333.29 MHz
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,DTES64,MWAIT,DS-CPL,EST,TM2,SSSE3,CX16,xTPR,PDCM,SSE4.1,NXE,LONG,LAHF,PERF,SENSOR,MELTDOWN

cpu1: 2MB 64b/line 8-way L2 cache
cpu1: smt 0, core 3, package 0
cpu2 at mainbus0cpu_enter_pages: entered tss+gdt page at 

Re: T470s power-cycles itself/hangs with/when plugged to ThinkPad Ultra Dock

2018-02-17 Thread Jiri B
On Fri, Feb 16, 2018 at 02:14:41PM +0200, Paul Irofti wrote:
> I bet this will fix it.
> 
>   https://marc.info/?l=openbsd-tech&m=151695604403648&w=2
> 
> On Wed, Feb 14, 2018 at 12:37:45PM -0500, Jiri B wrote:
> > Hello,
> > 
> > Lenovo T470s hangs when being plugged into docking station - ThinkPad
> > Ultra Dock (40A20)[1][2] - just hangs, no output, nothing.
> > 
> > When it does boot inside docking station it boots and it power cycle
> > itself after following lines (transcripted from video):
> > 
> > FYA, I can get couple of these docking stations and send them for free to
> > interested developers for hacking. I could probably get also other
> > ones (for T420s...). Let me know, I can ask for them at work.

Hi,

thank you, I can confirm your diff made my T470s working with
Lenovo ThinkPad Ultra Dock.

I tested plugging it in while running, I booted OpenBSD
while plugged in, I tested also if zzz and ZZZ and resume works.

Although there are some warnings and errors in dmesg outputs
below.

Thank you again!

- dmesg before plugging it in

OpenBSD 6.2-current (GENERIC.MP) #6: Tue Feb 13 20:16:11 MST 2018
dera...@amd64.openbsd.org:/usr/src/sys/arch/amd64/compile/GENERIC.MP
real mem = 17032802304 (16243MB)
avail mem = 16509575168 (15744MB)
enter_shared_special_pages: entered idt page va 0x8001 pa 0x1d65000
enter_shared_special_pages: entered kutext page va 0x81833000 pa 
0x1833000
enter_shared_special_pages: entered kutext page va 0x81834000 pa 
0x1834000
enter_shared_special_pages: entered kutext page va 0x81835000 pa 
0x1835000
enter_shared_special_pages: entered kudata page va 0x81aca000 pa 
0x1aca000
cpu_enter_pages: entered tss+gdt page at va 0x81a8e000 pa 0x1a8e000
cpu_enter_pages: entered t.stack page at va 0x81a8f000 pa 0x1a8f000
cpu_enter_pages: cif_tss.tss_rsp0 = 0x81a8f3e0
mpath0 at root
scsibus0 at mpath0: 256 targets
mainbus0 at root
bios0 at mainbus0: SMBIOS rev. 3.0 @ 0x9a2bb000 (62 entries)
bios0: vendor LENOVO version "N1WET41W (1.20 )" date 10/17/2017
bios0: LENOVO 20HGS22D0W
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 SSDT SSDT SSDT WSMT SSDT SSDT DBGP DBG2 POAT 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
lapic_map: entered lapic page va 0x81ac1000 pa 0xfee0
cpu0 at mainbus0: apid 0 (boot processor)
cpu0: Intel(R) Core(TM) i7-7600U CPU @ 2.80GHz, 2694.92 MHz
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,SENSOR,ARAT,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 24MHz
cpu0: mwait min=64, max=64, C-substates=0.2.1.2.4.1.1.1, IBE
cpu1 at mainbus0cpu_enter_pages: entered tss+gdt page at va 0x80002200 
pa 0x11ec65000
cpu_enter_pages: entered t.stack page at va 0x800022001000 pa 0x11ec66000
cpu_enter_pages: cif_tss.tss_rsp0 = 0x8000220013e0
: apid 2 (application processor)
cpu1: Intel(R) Core(TM) i7-7600U CPU @ 2.80GHz, 2693.75 MHz
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,SENSOR,ARAT,MELTDOWN
cpu1: 256KB 64b/line 8-way L2 cache
cpu1: smt 0, core 1, package 0
cpu2 at mainbus0cpu_enter_pages: entered tss+gdt page at va 0x800022011000 
pa 0x11ec7
cpu_enter_pages: entered t.stack page at va 0x800022012000 pa 0x11ec71000
cpu_enter_pages: cif_tss.tss_rsp0 = 0x8000220123e0
: apid 1 (application processor)
cpu2: Intel(R) Core(TM) i7-7600U CPU @ 2.80GHz, 2693.75 MHz
cpu2: 
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,SE

amd64 EFI - kernel boots with obsolete memory map

2018-02-17 Thread Ryan Lennox
Hi,

On amd64 EFI machines, the kernel is potentially booted with an 
obsolete memory map.

The file is "src/sys/arch/amd64/stand/libsa/exec_i386.c"

The memory map is passed to the kernel:

/* Pass memory map to the kernel */
mem_pass();

and then later, efi_cleanup() is called:

/*
 * Move the loaded kernel image to the usual place after calling
 * ExitBootServices().
 */
delta = DEFAULT_KERNEL_ADDRESS - efi_loadaddr;
efi_cleanup();


For reference, here is efi_cleanup() from 
"src/sys/arch/amd64/stand/efiboot/efiboot.c":

void
efi_cleanup(void)
{
int  retry;
EFI_STATUS   status;

/* retry once in case of failure */
for (retry = 1; retry >= 0; retry--) {
efi_memprobe_internal();/* sync the current map */
status = EFI_CALL(BS->ExitBootServices, IH, mmap_key);
if (status == EFI_SUCCESS)
break;
if (retry == 0)
panic("ExitBootServices failed (%d)", status);
}
}


When ExitBootServices is invoked, it has the potential to change 
the memory map. If this happens, it must be invoked a 2nd time.
This is normal behaviour according to the EFI specification, so 
there is nothing wrong with efi_cleanup() itself.

The bug is that the potentially updated memory map is never 
passed to the kernel in "exec_i386.c".

My understanding is that if the kernel boots with an obsolete 
memory map, it would then have the potential to corrupt EFI 
data in memory, with unpredictable and possibly catastrophic 
results.

The solution would be to ensure that the memory map is passed 
to the kernel *after* efi_cleanup() in "exec_i386.c".

This diff is my attempt to resolve the problem (and clean up 
some redundancy in the ifdef branching). I'd like to submit it here 
for review. I'm running 6.2 -stable, but this diff is against the most 
current version of the file at the time of writing.


diff -ur a/sys/arch/amd64/stand/libsa/exec_i386.c 
b/sys/arch/amd64/stand/libsa/exec_i386.c
--- a/sys/arch/amd64/stand/libsa/exec_i386.cSun Feb 11 22:37:16 2018
+++ b/sys/arch/amd64/stand/libsa/exec_i386.cSun Feb 11 22:40:23 2018
@@ -78,7 +78,7 @@
bios_bootsr_t bootsr;
struct sr_boot_volume *bv;
 #endif
-#if defined(EFIBOOT)
+#ifdef EFIBOOT
int i;
u_long delta;
extern u_long efi_loadaddr;
@@ -86,6 +86,7 @@
if ((av = alloc(ac)) == NULL)
panic("alloc for bootarg");
efi_makebootargs();
+   delta = DEFAULT_KERNEL_ADDRESS - efi_loadaddr;
 #endif
if (sa_cleanup != NULL)
(*sa_cleanup)();
@@ -124,6 +125,17 @@
sr_clear_keys();
 #endif
 
+   entry = marks[MARK_ENTRY] & 0x0fff;
+#ifdef EFIBOOT
+   entry += delta;
+#endif
+
+   printf("entry point at 0x%lx\n", entry);
+
+#ifdef EFIBOOT
+   /* Sync the memory map and call ExitBootServices() */
+   efi_cleanup();
+#endif
/* Pass memory map to the kernel */
mem_pass();
 
@@ -137,33 +149,24 @@
makebootargs(av, &ac);
 #endif
 
-   entry = marks[MARK_ENTRY] & 0x0fff;
-
-   printf("entry point at 0x%lx\n", entry);
-
-#ifndef EFIBOOT
-   /* stack and the gung is ok at this point, so, no need for asm setup */
-   (*(startfuncp)entry)(howto, bootdev, BOOTARG_APIVER, marks[MARK_END],
-   extmem, cnvmem, ac, (int)av);
-#else
+#ifdef EFIBOOT
/*
 * Move the loaded kernel image to the usual place after calling
 * ExitBootServices().
 */
-   delta = DEFAULT_KERNEL_ADDRESS - efi_loadaddr;
-   efi_cleanup();
memcpy((void *)marks[MARK_START] + delta, (void *)marks[MARK_START],
marks[MARK_END] - marks[MARK_START]);
for (i = 0; i < MARK_MAX; i++)
marks[i] += delta;
-   entry += delta;
+#endif
+
 #ifdef __amd64__
(*run_i386)((u_long)run_i386, entry, howto, bootdev, BOOTARG_APIVER,
marks[MARK_END], extmem, cnvmem, ac, (intptr_t)av);
 #else
+   /* stack and the gung is ok at this point, so, no need for asm setup */
(*(startfuncp)entry)(howto, bootdev, BOOTARG_APIVER, marks[MARK_END],
extmem, cnvmem, ac, (int)av);
-#endif
 #endif
/* not reached */
 }