DragonFlyBSD/src 9bace06lib/libnvmm libnvmm_x86.c

libnvmm(3): Sync misc changes from m00nbsd

* Fix inverted comments.
* Read guest PTEs atomically.
DeltaFile
+16-14lib/libnvmm/libnvmm_x86.c
+16-141 files

DragonFlyBSD/src ad801e3lib/libnvmm libnvmm_x86.c, test/testcases/libnvmm h_mem_assist.c h_mem_assist_asm.S

libnvmm(3): Add support for "BT r/m, imm8"

Used by Windows Vista 64bit.

Credit: Maxime Villard (m00nbsd)
DeltaFile
+101-0lib/libnvmm/libnvmm_x86.c
+89-0test/testcases/libnvmm/h_mem_assist_asm.S
+5-0test/testcases/libnvmm/h_mem_assist.c
+195-03 files

DragonFlyBSD/src b604ef8lib/libnvmm libnvmm_x86.c, test/testcases/libnvmm h_mem_assist.c h_mem_assist_asm.S

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)
DeltaFile
+21-0test/testcases/libnvmm/h_mem_assist_asm.S
+2-7lib/libnvmm/libnvmm_x86.c
+2-0test/testcases/libnvmm/h_mem_assist.c
+25-73 files

DragonFlyBSD/src 1391cc4lib/libnvmm libnvmm_x86.c, test/testcases/libnvmm h_mem_assist.c h_mem_assist_asm.S

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)
DeltaFile
+18-6lib/libnvmm/libnvmm_x86.c
+16-1test/testcases/libnvmm/h_mem_assist_asm.S
+2-0test/testcases/libnvmm/h_mem_assist.c
+36-73 files

DragonFlyBSD/src 453793elib/libnvmm libnvmm_x86.c

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)
DeltaFile
+4-10lib/libnvmm/libnvmm_x86.c
+4-101 files

DragonFlyBSD/src ed75211lib/libnvmm libnvmm_x86.c

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)
DeltaFile
+0-6lib/libnvmm/libnvmm_x86.c
+0-61 files

DragonFlyBSD/src d4608dclib/libnvmm libnvmm_x86.c

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
DeltaFile
+22-32lib/libnvmm/libnvmm_x86.c
+22-321 files

DragonFlyBSD/src 18e8b20test/testcases/libnvmm h_mem_assist.c h_io_assist.c

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.
DeltaFile
+18-13test/testcases/libnvmm/h_mem_assist.c
+18-13test/testcases/libnvmm/h_io_assist.c
+36-262 files

DragonFlyBSD/src cea9f57test/testcases/libnvmm h_mem_assist.c h_mem_assist_asm.S

testcases/libnvmm: Rename our extra tests to avoid conflicts
DeltaFile
+8-8test/testcases/libnvmm/h_mem_assist_asm.S
+7-8test/testcases/libnvmm/h_mem_assist.c
+15-162 files

DragonFlyBSD/src c620eectest/testcases/libnvmm h_mem_assist.c h_io_assist.c

testcases/libnvmm: Extract OS-specific bits into h_os.h
DeltaFile
+91-0test/testcases/libnvmm/h_os.h
+3-46test/testcases/libnvmm/h_io_assist.c
+3-45test/testcases/libnvmm/h_mem_assist.c
+97-913 files

DragonFlyBSD/src dad22e4test/testcases/libnvmm h_io_assist.c h_mem_assist.c

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.
DeltaFile
+36-13test/testcases/libnvmm/h_mem_assist.c
+20-8test/testcases/libnvmm/h_io_assist.c
+56-212 files

DragonFlyBSD/src da9c391test/testcases/libnvmm h_mem_assist.c h_io_assist.c

testcases/libnvmm: Add CFLAGS+=-g and enable WARNS=6
DeltaFile
+1-1test/testcases/libnvmm/h_mem_assist.c
+1-1test/testcases/libnvmm/h_io_assist.c
+2-0test/testcases/libnvmm/Makefile.inc
+4-23 files

DragonFlyBSD/src 691a36eusr.sbin/nvmmctl nvmmctl.8

nvmmctl.8: Improve command enumeration style
DeltaFile
+3-3usr.sbin/nvmmctl/nvmmctl.8
+3-31 files

DragonFlyBSD/src 0d5a90bsys/dev/virtual/nvmm nvmm_ioctl.h nvmm_os.h

nvmm(4): Add a few comments and clean up a bit
DeltaFile
+2-4sys/dev/virtual/nvmm/nvmm_internal.h
+4-1sys/dev/virtual/nvmm/nvmm_os.h
+0-2sys/dev/virtual/nvmm/nvmm_ioctl.h
+6-73 files

DragonFlyBSD/src ea254afsys/dev/virtual/nvmm/x86 nvmm_x86_vmxfunc.S nvmm_x86_svmfunc.S

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)
DeltaFile
+256-1sys/dev/virtual/nvmm/x86/nvmm_x86_internal.h
+0-70sys/dev/virtual/nvmm/x86/nvmm_x86.h
+2-2sys/dev/virtual/nvmm/x86/nvmm_x86_vmxfunc.S
+2-2sys/dev/virtual/nvmm/x86/nvmm_x86_svmfunc.S
+260-754 files

DragonFlyBSD/src 7c512aasys/dev/virtual/nvmm nvmm_dragonfly.c nvmm.c, sys/dev/virtual/nvmm/x86 nvmm_x86_vmx.c nvmm_x86_svm.c

nvmm(4): Dedup inclusion of system headers
DeltaFile
+1-13sys/dev/virtual/nvmm/x86/nvmm_x86_internal.h
+6-4sys/dev/virtual/nvmm/nvmm_os.h
+0-6sys/dev/virtual/nvmm/x86/nvmm_x86_vmx.c
+0-6sys/dev/virtual/nvmm/x86/nvmm_x86_svm.c
+0-6sys/dev/virtual/nvmm/nvmm.c
+0-5sys/dev/virtual/nvmm/nvmm_dragonfly.c
+7-402 files not shown
+7-468 files

DragonFlyBSD/src dc2d842sys/dev/virtual/nvmm nvmm.c nvmm_internal.h, sys/dev/virtual/nvmm/x86 nvmm_x86_vmx.c nvmm_x86_svm.c

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.
DeltaFile
+15-17sys/dev/virtual/nvmm/x86/nvmm_x86_svm.c
+15-13sys/dev/virtual/nvmm/x86/nvmm_x86_vmx.c
+3-8sys/dev/virtual/nvmm/nvmm_os.h
+5-5sys/dev/virtual/nvmm/nvmm_internal.h
+6-4sys/dev/virtual/nvmm/nvmm.h
+4-5sys/dev/virtual/nvmm/nvmm.c
+48-523 files not shown
+52-619 files

DragonFlyBSD/src 719a5b4lib/libnvmm libnvmm_x86.c

libnvmm(3): Fix build after nvmm_x86.h adjustment
DeltaFile
+8-0lib/libnvmm/libnvmm_x86.c
+8-01 files

DragonFlyBSD/src 9987ec0test/testcases/libnvmm h_mem_assist.c h_io_assist.c

testcases/libnvmm: Fix build after nvmm_x86.h adjustment
DeltaFile
+13-0test/testcases/libnvmm/h_mem_assist.c
+13-0test/testcases/libnvmm/h_io_assist.c
+26-02 files

DragonFlyBSD/src 1a32130lib/libutil pty.3, share/man/man4 mtw.4 corecstat.4

Sort SEE ALSO in a few manual pages.
DeltaFile
+3-3share/man/man4/pty.4
+2-2usr.bin/setcaps/setcaps.1
+1-1share/man/man4/mtw.4
+1-1share/man/man4/corecstat.4
+1-1lib/libutil/pty.3
+8-85 files

DragonFlyBSD/src ac8b1c8share/man/man9 unr.9

unr.9: Fix typo.
DeltaFile
+1-1share/man/man9/unr.9
+1-11 files

DragonFlyBSD/src 003c13finclude stdint.h ndbm.h, include/xlocale _monetary.h

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.
DeltaFile
+2-0sys/sys/_clock_id.h
+2-0include/xlocale/_monetary.h
+2-0include/ndbm.h
+1-0sys/sys/_ucontext.h
+1-0sys/netinet/in.h
+1-0include/stdint.h
+9-02 files not shown
+11-08 files

DragonFlyBSD/src 9e1703dsys/dev/virtual/nvmm/x86 nvmm_x86_vmx.c nvmm_x86_svm.c

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)
DeltaFile
+8-10sys/dev/virtual/nvmm/x86/nvmm_x86_vmx.c
+8-10sys/dev/virtual/nvmm/x86/nvmm_x86_svm.c
+16-202 files

DragonFlyBSD/src 51e47edsys/dev/virtual/nvmm/x86 nvmm_x86_internal.h nvmm_x86_vmx.c

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)
DeltaFile
+1-14sys/dev/virtual/nvmm/x86/nvmm_x86_vmx.c
+1-14sys/dev/virtual/nvmm/x86/nvmm_x86_svm.c
+2-2sys/dev/virtual/nvmm/x86/nvmm_x86_internal.h
+4-303 files

DragonFlyBSD/src 2321945sys/dev/virtual/nvmm/x86 nvmm_x86_svm.c nvmm_x86.c

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)
DeltaFile
+10-10sys/dev/virtual/nvmm/x86/nvmm_x86.c
+1-0sys/dev/virtual/nvmm/x86/nvmm_x86_svm.c
+11-102 files

DragonFlyBSD/src 5a1c409sys/dev/virtual/nvmm/x86 nvmm_x86.c nvmm_x86_vmx.c

nvmm(4): Add support for PCID on SVM

Credit: Maxime Villard (m00nbsd)
DeltaFile
+6-5sys/dev/virtual/nvmm/x86/nvmm_x86_svm.c
+5-5sys/dev/virtual/nvmm/x86/nvmm_x86_vmx.c
+2-2sys/dev/virtual/nvmm/x86/nvmm_x86.c
+13-123 files

DragonFlyBSD/src 7af02f8doc TODO.nvmm, sys/dev/virtual/nvmm/x86 nvmm_x86_svm.c

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)
DeltaFile
+64-4sys/dev/virtual/nvmm/x86/nvmm_x86_svm.c
+0-2doc/TODO.nvmm
+64-62 files

DragonFlyBSD/src 6776d55sys/dev/virtual/nvmm nvmm_internal.h nvmm_ioctl.h, sys/dev/virtual/nvmm/x86 nvmm_x86_vmx.c nvmm_x86_svm.c

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)
DeltaFile
+0-25sys/dev/virtual/nvmm/nvmm.c
+1-6sys/dev/virtual/nvmm/nvmm_ioctl.h
+1-2sys/dev/virtual/nvmm/nvmm_internal.h
+0-1sys/dev/virtual/nvmm/x86/nvmm_x86_vmx.c
+0-1sys/dev/virtual/nvmm/x86/nvmm_x86_svm.c
+2-355 files

DragonFlyBSD/src 0d1bb89sys/dev/virtual/nvmm/x86 nvmm_x86_vmx.c nvmm_x86_svm.c

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)
DeltaFile
+7-6sys/dev/virtual/nvmm/x86/nvmm_x86.c
+0-1sys/dev/virtual/nvmm/x86/nvmm_x86_vmx.c
+0-1sys/dev/virtual/nvmm/x86/nvmm_x86_svm.c
+7-83 files

DragonFlyBSD/src 0d06047sys/dev/virtual/nvmm/x86 nvmm_x86.h nvmm_x86.c

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)
DeltaFile
+31-1sys/dev/virtual/nvmm/x86/nvmm_x86_vmx.c
+7-2sys/dev/virtual/nvmm/x86/nvmm_x86.h
+7-2sys/dev/virtual/nvmm/x86/nvmm_x86.c
+45-53 files