libnvmm(3): Fix sign-extension on immediates
It's the immediate size that should be used for sign-extension, not the
operand size. Fix this, and add a unit-test for it.
Credit: Maxime Villard (m00nbsd)
libnvmm(3): Fix the emulation of REP/REPN prefixes
- REP applies only to string instructions, so restrict the emulation
accordingly, and add a unit-test to ensure correctness.
- REPN applies only to SCAS and CMPS, neither of which we support;
nevertheless, allow REPN to be used with MOVS/LODS/STOS.
Credit: Maxime Villard (m00nbsd)
libnvmm(3): Do not confuse long-mode and 64bit-mode
32bit compatibility mode has EFER.LMA=1 and CS.L=0. Use CS.L rather than
EFER.LMA to determine whether to apply segmentation.
Credit: Maxime Villard (m00nbsd)
libnvmm(3): Remove erroneous PS check on L1 PTEs
On L1 PTEs, the PS bit is actually PAT, and it is legal for it to be set.
Credit: Maxime Villard (m00nbsd)
Revert "libnvmm(3): Simplify x86_emul.func prototype"
This reverts commit b4ca47aaefeba38c6205a34b0e24495f29d61463.
Directly passing 'uint64_t *gprs' saves a few fetch instructions.
In addition, we're not going to implement the instruction emulation that
requires further extend the 'func' prototype, so this reverted
simplification is of little use.
Discussed-with: Maxime Villard
testcases/libnvmm: Improve error handling of IO/memory callbacks
Don't simply abort the program in case of nvmm_assist_{io,mem}() errors.
Instead, propagate the error to the test runner so that the total
failures are counted and reported in the end.
This is a follow-up fix to my previous commit
dad22e44dc57d9ba999b6826494043a616e16b43.
testcases/libnvmm: Print more info and report total failures
* Print a few more details in the output logs.
* Run all tests to completeion and report the total number of failures
at the end.
nvmm(4): Undefine all specialreg macros to avoid potential conflicts
The 'nvmm_x86.h' is a public header that's included via 'nvmm.h', so
it's possible for the custom defined CR0/CR4/XCR0/MSR bits to conflict
with OS's version; for example, including one header that pulls in
<machine/specialreg.h>. This is actually the case happened in NetBSD
11.0.
In order to resolve the conflict in NetBSD 11.0 and be future-proof,
move the specialreg macros to the internal header 'nvmm_x86_internal.h',
and generate the `#undef` block to undefine all the macros to avoid any
redefinition warnings.
Discussed-with: Maxime Villard (m00nbsd)
nvmm(4): Sync misc changes from m00nbsd
* Fix extern global 'nmachines' to 'nvmm_nmachines'.
* Minor cleanup to NetBSD's pmap_ept_has_ad handling and EPT/NPT pmap
setup.
* Some code style tweaks.
No functional changes.
Add <sys/cdefs.h> inclusion to a number of headers.
These are the last non-contrib headers that were using macros from
<sys/cdefs.h> but were not including it.
nvmm(4): Improve guest TSC handling
Don't skip updating TSC if the emulator set a zero value, which can
happen if the emulator resets the VM. In this case, we really want this
to be applied.
Meanwhile, rename 'gtsc_match' to 'gtsc_last'.
Credit: Maxime Villard (m00nbsd)
nvmm(4): Make use of kernel_fpu_begin() and kernel_fpu_end()
The kernel_fpu_*() API was added to help drm/amdgpu in commit
1be00ff1850ebb705db236c08160ee8fea99b32a, shortly after I ported NVMM.
Use this API to reduce difference with the NVMM upstream.
Credit: Maxime Villard (m00nbsd)
nvmm(4): Fix CPUID bits
- FMA/F16C/VAES/VPCLMULQDQ are part of AVX and should not be exposed.
- PSE36 is not supported and should not be exposed.
- EferLmsleUnsupp should be unconditionally exposed on AMD.
- SHA is part of XMM, which is supported, so it can be exposed.
Credit: Maxime Villard (m00nbsd)
nvmm(4): Add TPR support for SVM
If DecodeAssist is supported, intercept writes to CR8, and deliver
TPR_CHANGED VMEXITs to the emulator. This should improve the accuracy of
interrupt delivery on guests like Windows that make heavy use of CR8.
Credit: Maxime Villard (m00nbsd)
nvmm(4): Remove NVMM_IOC_VCPU_INJECT and associated artifacts
Events are injected in vcpu_run, so this ioctl is not used anymore.
Credit: Maxime Villard (m00nbsd)
nvmm(4): Fix the XSAVE area size
- Fix nvmm_x86_xsave_size(): x87/SSE are in the legacy region, and the
size of that region is constant regardless of whether SSE is enabled.
- When XSAVEC is supported, CPUID leaf 0x0000000D:ECX=1[EBX] is supposed
to return the current XSAVE area size, but NVMM mistakenly returns
zero. Given that NVMM supports only x87/SSE, XSAVEC is useless, so
rather than fixing the EBX return value, just don't advertise XSAVEC.
Credit: Maxime Villard (m00nbsd)
nvmm(4): Advertise new CPUID and ARCH_CAP bits
Advertise SsbdNotRequired and BTC_NO bits in CPUID and mitigation bits
in ARCH_CAP, for the guest to know not to turn on costly mitigations if
the CPU doesn't require them.
Credit: Maxime Villard (m00nbsd)