libnvmm: Improve the page walker
* Implement A/D bit setting.
* Inject #PFs on non-present pages when emulating MMIOs. This is needed
for guests like Windows 2000 that aggressively page out memory that
they then use in MMIO operations.
* Fix the '64bit walk - present' test that failed in the previous
commit.
Obtained-from: NVMM Reference Implementation
libnvmm: Improve the correctness of page table walks
* Fix 32bit PAE: the top-level pdir doesn't have NX.
* Fix 32bit non-PAE: PTE_PS is ignored if CR4.PSE=0.
* Stop the walks early on if a required permission is not met.
* Take CR0.WP and EFER.NXE into account when evaluating permissions.
* Enforce SMEP/SMAP protections.
* Document the semantics of nvmm_gva_to_gpa() more clearly.
* Add unit-tests.
Note that the '64bit walk - present' test is failing, which will be
fixed in a later commit.
Obtained-from: NVMM Reference Implementation
testcases/libnvmm: Fully reset the VCPU after each test
Otherwise if a fault is pending it gets injected in the next test.
Obtained-from: NVMM Reference Implementation
libnvmm: Fix MOVZX emulation
The overridden operand_size was being used to select the register, and
this did not match the actual desired register size. This could result
in the wrong register being written to, for example EBP would be decoded
as CH.
Update the existing unit-test to exercise this case.
Obtained-from: NVMM Reference Implementation
nvmm: Improve OS independence
* Add os_copy_from_user() and os_copy_to_user() helpers.
* Split os_vmobj_map() into os_vmobj_map_{user,kern}(), which are the
same for DragonFly and NetBSD; this helps the Haiku port.
Obtained-from: NVMM Reference Implementation
nvmm: Make the ASM files more OS-independent
* Introduce OS-independent ASM_FUNCTION and ASM_END macros.
* Move the OS-dependant bits to nvmm_x86_internal.h.
* Fetch the hgdt pointer in C with os_curcpu_gdt(), so svm_vmrun()
becomes OS-independent.
* Use RIP-relative addressing in vmx_insn_fail{valid,invalid}.
Obtained-from: NVMM Reference Implementation
nvmm: Ignore MSR_LS_CFG (0xC0011020) on AMD CPUs
On older AMD CPUs that do not support SSBD mitigations, Linux falls
back to writing to MSR_LS_CFG on each context switch if this MSR
exists. This creates significant noise in the QEMU output.
We can't simply inject #GP for accesses to this MSR, as that may
break compatibility with older guests which assume that MSR_LS_CFG
is present based solely on the reported CPU family and model.
So just ignore this MSR completely. This fixes a QEMU output storm
on Arch Linux (tested with archlinux-2019.05.02-x86_64.iso).
Obtained-from: NVMM Reference Implementation
nvmm: Support cache and process topology CPUID info for SVM
Support CPUIDs 0x8000001D and 0x8000001E for SVM.
Obtained-from: NVMM Reference Implementation
nvmm: Fix SWINT reinjection in svm_exit_evt()
AMD CPUs have an issue where they may not set nrip if a VMEXIT
occurs during a SWINT event. Work around it by not reinjecting
SWINTs and just letting the guest re-execute the INT instruction.
Obtained-from: NVMM Reference Implementation
mount(8): Detect known filesystem types in raw GPT partitions
mount(8) previously only guessed the filesystem from the disklabel
fstype. DIOCGPART already puts the GPT partition type UUID in
partinfo.fstype_uuid, but mount(8) never looked at it. A raw GPT
partition has fstype 0, so mount(8) would warn and fall back to ufs.
Update checkdisklabel() to look the fstype_uuid up in a table of known
GPT partition types (EFI -> msdos, the DragonFly/FreeBSD native types ->
ufs/hammer/hammer2) if the disklabel fstype does not map. Unknown GPT
partition types keep the old warning and ufs fallback.
Bug: #3401
efi/loader: Improve the linker script and LDFLAGS
* Remove the stale comment of `.hash`, which is empty under the default
`--hash-style=gnu`. The image base is also pinned by
`. = 0; ImageBase = .`.
* Fold the remaining linker-generated PLT sections (`.plt.*` and `.iplt`)
into `.text` so the `objcopy -j .text` can never drop them.
* Add `-Wl,-z,defs` to fail the link if there are unresolved symbols,
instead of generating PLT entries for them.
* Add `-Wl,--no-eh-frame-hdr` to skip generating the `.eh_frame_hdr`
section because it's never copied into the final `loader.efi`
executable. What's worse, the generation sidesteps a bug in
bintuils/bfd that produced the misleading overlapping FDEs error, as
observed in the previous commit.
Assisted-by: DeepSeek-v4.1-flash (with Pi Coding Agent)
mount(8): Detect known filesystem types in raw GPT partitions
mount(8) previously only guessed the filesystem from the disklabel
fstype. DIOCGPART already puts the GPT partition type UUID in
partinfo.fstype_uuid, but mount(8) never looked at it. A raw GPT
partition has fstype 0, so mount(8) would warn and fall back to ufs.
Update checkdisklabel() to look the fstype_uuid up in a table of known
GPT partition types (EFI -> msdos, the DragonFly/FreeBSD native types ->
ufs/hammer/hammer2) if the disklabel fstype does not map. Unknown GPT
partition types keep the old warning and ufs fallback.
Bug: #3401
efi/loader: Improve the linker script and LDFLAGS
* Remove the stale comment of `.hash`, which is empty under the default
`--hash-style=gnu`. The image base is also pinned by
`. = 0; ImageBase = .`.
* Fold the remaining linker-generated PLT sections (`.plt.*` and `.iplt`)
into `.text` so the `objcopy -j .text` can never drop them.
* Add `-Wl,-z,defs` to fail the link if there are unresolved symbols,
instead of generating PLT entries for them.
* Add `-Wl,--no-eh-frame-hdr` to skip generating the `.eh_frame_hdr`
section because it's never copied into the final `loader.efi`
executable. What's worse, the generation sidesteps a bug in
bintuils/bfd that produced the misleading overlapping FDEs error, as
observed in the previous commit.
Assisted-by: DeepSeek-v4.1-flash (with Pi Coding Agent)
kern: Fix mmioctl() to return ENOTTY for unknown devices
The default case for unknown devices handles /dev/null and previously
returned ENODEV for tcsetattr/tcgetattr/tc* requests, which should be
ENOTTY as specified by POSIX (as well as documented in the man pages).
Fix the bug by correcting mmioctl() to return ENOTTY in the default
case.
Patch-by: jpikin, sigttou (David Bidner)
Bug: https://bugs.dragonflybsd.org/issues/3252
w(1) - Do not warn about non-existent tty lines
ttystat() called warn() when stat("/dev/<line>") failed, so X11 sessions
(ut_line like ":16") printed a spurious
"w: /dev/:16: No such file or directory".
Return NULL silently unless the line is an existing character device.
Matches FreeBSD (see commits 21632754d652d20a4618cac0b52ebe7d8e790865,
d0d0355e4dd9fa060443d3f1b1a223118ff68827).
Fixes #3298
loader: Clear CR0.WP during EFI kernel relocation
Firmware on an HP ProDesk 600 G4 leaves relocation destination pages
read-only. efi_copy_finish() faults at 0x1001000 with page-fault error
code 3 (supervisor write, protection violation) while CR0.WP is set.
Save CR0 and clear WP around the relocation copy after ExitBootServices,
with interrupts disabled. Restore CR0 before entering the kernel. Reject
active CET before leaving boot services, since it prevents clearing WP.
Bug: https://bugs.dragonflybsd.org/issues/3427