aboutsummaryrefslogtreecommitdiff
path: root/sys/amd64/vmm/intel
Commit message (Collapse)AuthorAgeFilesLines
* kernel: address executable stack warnings in amd64 gcc buildRyan Libby4 days1-0/+2
| | | | | | | Mark assembly files as not requiring executable stacks. Reviewed by: kib Differential Revision: https://reviews.freebsd.org/D56946
* PHYS_TO_DMAP: Return a void * instead of a vm_offset_tJohn Baldwin2026-04-232-6/+5
| | | | | | | | | | Add a new PHYS_TO_DMAP_ADDR that still returns an address for use in places that only need an address and not a pointer. Effort: CHERI upstreaming Reviewed by: kib Sponsored by: AFRL, DARPA Pull Request: https://github.com/freebsd/freebsd-src/pull/2068
* vmm: Consolidate vm and vcpu definitionsMark Johnston2026-01-081-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | There is quite a lot of duplication of code between amd64, arm64 and riscv with respect to VM and vCPU state management. This is a bit tricky to resolve since struct vm and struct vcpu are private to vmm.c and both structures contain a mix of machine-dependent and machine-independent fields. To allow deduplication without also introducing a lot of churn, follow the approach of struct pcpu and 1) lift the definitions of those structures into a new header, sys/dev/vmm/vmm_vm.h, and 2) define machine-dependent macros, VMM_VM_MD_FIELDS and VMM_VCPU_MD_FIELDS which lay out the machine-dependent fields. One disadvantage of this approach is that the two structures are no longer private to vmm.c, but I think this is acceptable. No functional change intended. A follow-up change will move a good deal of machine/vmm/vmm.c into sys/dev/vmm/vmm_vm.c. MFC after: 2 months Sponsored by: The FreeBSD Foundation Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D53584
* vmm: Move vm_maxcpu handling into MI codeMark Johnston2025-11-041-1/+1
| | | | | | | | | | No functional change intended. Reviewed by: corvink MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D53477
* amd64 vmx: micro-optimize vmlaunch failure pathKonstantin Belousov2025-08-241-5/+3
| | | | | | | | | | | Eliminate two unneeded jumps. One is the jmp to the next instruction, where there is no requrement that vmlaunch is followed by jmp. Another one conditionally sets %r11d value, and can be replaced by cmovcc. Reviewed by: markj Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D52136
* vmm: Support INOUT manual decode.ShengYi Hung2025-07-241-0/+2
| | | | | | | | | | | The inout instruction in AMD SVM requires DecodeAssist feature to decode the segment override prefix. However, without that feature, we are still able to decode by fetching the instruction directly. Approved by: markj (mentor) MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D51256
* amd64: Remove some unused SMP-only definesMark Johnston2025-07-171-6/+0
| | | | | | | No functional change intended. Reviewed by: kib Differential Revision: https://reviews.freebsd.org/D51350
* bhyve: make most of the iommu_ops interfaces return errorKonstantin Belousov2025-04-061-11/+17
| | | | | | | | | and change create_mapping()/remove_mapping() to allow shorten results. Reviewed by: markj Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D49629
* vmm: Consolidate code which manages guest memory regionsMark Johnston2025-02-181-1/+3
| | | | | | | | | | | | | | | | | | | | | | | On all three platforms supported by vmm, we have mostly duplicated code to manage guest physical memory regions. Deduplicate much of this code and move it into sys/dev/vmm/vmm_mem.c. To avoid exporting struct vm outside of machdep vmm.c, add a new struct vm_mem to contain the memory segment descriptors, and add a vm_mem() accessor, akin to vm_vmspace(). This way vmm_mem.c can implement its routines without needing to see the layout of struct vm. The handling of the per-VM vmspace is also duplicated but will be moved to vmm_mem.c in a follow-up patch. On amd64, move the ppt_is_mmio() check out of vm_mem_allocated() to keep the code MI, as PPT is only implemented on amd64. There are only a couple of callers, so this is not unreasonable. No functional change intended. Reviewed by: jhb Differential Revision: https://reviews.freebsd.org/D48270
* vmm: Correctly suspend and resume the vmm driver.Joshua Rogers2024-11-291-1/+10
| | | | | | | | | | | | | | | Previously, VMXON would be executed on a resume, contrary to proper initalization. The contents of MSR_IA32_FEATURE_CONTROL may be lost on suspension, therefore must be restored. Likewise, the VMX Enable bit may be cleared upon suspend, requiring it to be re-set. Concretely disable VMX on suspend, and re-enable it on resume. Note: any IOMMU context will remain lost for any enabled vmm devices. Signed-off-by: Joshua Rogers <Joshua@Joshua.Hu> Reviewed by: jhb,imp Pull Request: https://github.com/freebsd/freebsd-src/pull/1419
* Remove stray whitespaces from sys/amd64/Joshua Rogers2024-09-212-2/+2
| | | | | | Signed-off-by: Joshua Rogers <Joshua@Joshua.Hu> Reviewed by: imp Pull Request: https://github.com/freebsd/freebsd-src/pull/1418
* vmm: Move vmm_ktr.h to a common directoryMark Johnston2024-08-261-1/+2
| | | | | | | No functional change intended. Reviewed by: corvink, jhb, emaste Differential Revision: https://reviews.freebsd.org/D46429
* vmm: Expose more registers to VM_GET_REGISTERMark Johnston2024-02-072-2/+13
| | | | | | | | | | | In a follow-up revision the gdb stub will support sending an XML target description to gdb, which lets us send additional registers, including the ones added in this patch. Reviewed by: jhb MFC after: 1 month Sponsored by: Innovate UK Differential Revision: https://reviews.freebsd.org/D43665
* vmm: MTRR should be saved/restoredVitaliy Gusev2023-12-291-0/+3
| | | | | | | | | | | This fixes restoring a Linux VM if it was suspended while in the GRUB menu. Adding MTTR increases the kernel dump size by 256 bytes per vCPU. Sponsored by: vStack Reviewed by: markj, rew Differential Revision: https://reviews.freebsd.org/D43226
* sys: Automated cleanup of cdefs and other formattingWarner Losh2023-11-275-5/+0
| | | | | | | | | | | | | | | | Apply the following automated changes to try to eliminate no-longer-needed sys/cdefs.h includes as well as now-empty blank lines in a row. Remove /^#if.*\n#endif.*\n#include\s+<sys/cdefs.h>.*\n/ Remove /\n+#include\s+<sys/cdefs.h>.*\n+#if.*\n#endif.*\n+/ Remove /\n+#if.*\n#endif.*\n+/ Remove /^#if.*\n#endif.*\n/ Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/types.h>/ Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/param.h>/ Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/capsicum.h>/ Sponsored by: Netflix
* vmx: Prefer consistent naming for loader tunablesZhenlei Huang2023-10-191-5/+27
| | | | | | | | | | | | | | | | | | | | | | The following loader tunables do have corresponding sysctl MIBs but with different names. That may be historical reason. Let's prefer consistent naming for them so that it will be easier to read and maintain. 1. hw.vmm.l1d_flush -> hw.vmm.vmx.l1d_flush 2. hw.vmm.l1d_flush_sw -> hw.vmm.vmx.l1d_flush_sw 3. hw.vmm.vmx.use_apic_pir -> hw.vmm.vmx.cap.posted_interrupts 4. hw.vmm.vmx.use_apic_vid -> hw.vmm.vmx.cap.virtual_interrupt_delivery 5. hw.vmm.vmx.use_tpr_shadowing -> hw.vmm.vmx.cap.tpr_shadowing Old names are kept for compatibility. Meanwhile, add sysctl flag CTLFLAG_TUN to them so that `sysctl -T` will report them correctly. Reviewed by: corvink, jhb, kib, #bhyve MFC after: 5 days Differential Revision: https://reviews.freebsd.org/D42251
* sys: Remove $FreeBSD$: one-line .c patternWarner Losh2023-08-166-12/+0
| | | | Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/
* sys: Remove $FreeBSD$: two-line .h patternWarner Losh2023-08-1613-26/+0
| | | | Remove /^\s*\*\n \*\s+\$FreeBSD\$$\n/
* spdx: The BSD-2-Clause-FreeBSD identifier is obsolete, drop -FreeBSDWarner Losh2023-05-1213-13/+13
| | | | | | | | | The SPDX folks have obsoleted the BSD-2-Clause-FreeBSD identifier. Catch up to that fact and revert to their recommended match of BSD-2-Clause. Discussed with: pfg MFC After: 3 days Sponsored by: Netflix
* bhyve: save/restore pir_descVitaliy Gusev2023-05-091-0/+3
| | | | | | | | | | Failing to preserve pir_desc can result in pending interrupts being lost on resume leading to a hung VM. Reviewed by: corvink, jhb MFC after: 1 week Sponsored by: vStack Differential Revision: https://reviews.freebsd.org/D35447
* bhyve: fix vCPU single-stepping on VMXBojan Novković2023-05-091-0/+7
| | | | | | | | | | | | | | | | | | | | | This patch fixes virtual machine single stepping on VMX hosts. Currently, when using bhyve's gdb stub, each attempt at single-stepping a vCPU lands in a timer interrupt. The current single-stepping mechanism uses the Monitor Trap Flag feature to cause VMEXIT after a single instruction is executed. Unfortunately, the SDM states that MTF causes VMEXITs for the next instruction that gets executed, which is often not what the person using the debugger expects. [1] This patch adds a new VM capability that masks interrupts on a vCPU by blocking interrupt injection and modifies the gdb stub to use the newly added capability while single-stepping a vCPU. [1] Intel SDM 26.5.2 Vol. 3C Reviewed by: corvink, jbh MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D39949
* vmm: don't free unallocated memoryCorvin Köhne2023-05-051-1/+3
| | | | | | | | | | | | | | If vmx or svm is disabled in BIOS or the device isn't supported by vmm, modinit won't allocate these state save areas. As kmem_free panics when passing a NULL pointer to it, loading the vmm kernel module causes a panic too. PR: 271251 Reviewed by: markj Fixes: 74ac712f72cfd6d7b3db3c9d3b72ccf2824aa183 ("vmm: Dynamically allocate a couple of per-CPU state save areas") MFC after: 1 week Sponsored by: Beckhoff Automation GmbH & Co. KG Differential Revision: https://reviews.freebsd.org/D39974
* vmm: Dynamically allocate a couple of per-CPU state save areasMark Johnston2023-04-261-4/+8
| | | | | | | | | | | | | This avoids bloating the BSS when MAXCPU is large. No functional change intended. PR: 269572 Reviewed by: corvink, rew Tested by: rew MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D39805
* vmm: fix HLT loop while vcpu has requested virtual interruptsVitaliy Gusev2023-04-261-25/+19
| | | | | | | | | | | | | | This fixes the detection of pending interrupts when pirval is 0 and the pending bit is set More information how this situation occurs, can be found here: https://github.com/freebsd/freebsd-src/blob/c5b5f2d8086f540fefe4826da013dd31d4e45fe8/sys/amd64/vmm/intel/vmx.c#L4016-L4031 Reviewed by: corvink, markj Fixes: 02cc877968bbcd57695035c67114a67427f54549 ("Recognize a pending virtual interrupt while emulating the halt instruction.") MFC after: 1 week Sponsored by: vStack Differential Revision: https://reviews.freebsd.org/D39620
* bhyve: fix restore of kernel structsVitaliy Gusev2023-02-281-7/+0
| | | | | | | | | | | | | | | vmx_snapshot() and svm_snapshot() do not save any data and error occurs at resume: Restoring kernel structs... vm_restore_kern_struct: Kernel struct size was 0 for: vmx Failed to restore kernel structs. Reviewed by: corvink, markj Fixes: 39ec056e6dbd89e26ee21d2928dbd37335de0ebc ("vmm: Rework snapshotting of CPU-specific per-vCPU data.") MFC after: 2 weeks Sponsored by: vStack Differential Revision: https://reviews.freebsd.org/D38476
* vmm: avoid spurious rendezvousCorvin Köhne2023-02-011-1/+1
| | | | | | | | | | | | | | | | | | | | | | A vcpu only checks if a rendezvous is in progress or not to decide if it should handle a rendezvous. This could lead to spurios rendezvous where a vcpu tries a handle a rendezvous it isn't part of. This situation is properly handled by vm_handle_rendezvous but it could potentially degrade the performance. Avoid that by an early check if the vcpu is part of the rendezvous or not. At the moment, rendezvous are only used to spin up application processors and to send ioapic interrupts. Spinning up application processors is done in the guest boot phase by sending INIT SIPI sequences to single vcpus. This is known to cause spurious rendezvous and only occurs in the boot phase. Sending ioapic interrupts is rare because modern guest will use msi and the rendezvous is always send to all vcpus. Reviewed by: jhb MFC after: 1 week Sponsored by: Beckhoff Automation GmbH & Co. KG Differential Revision: https://reviews.freebsd.org/D37390
* vtd: Increase DRHD_MAX_UNITSEric Joyner2023-01-311-1/+1
| | | | | | | | | | | | | | | | | | | | Observed on a couple Ice Lake-SP platforms (Intel Coyote Pass, Dell R750), there are more than 8 DRHD sections enumerated in the DMAR ACPI section. Since the previous limit was 8, this resulted in some of these not being parsed by vtd when the iommu is initialized; in this case when PCI devices are being passthru'd to a bhyve VM. This omission later causes a kernel panic later in initialization when devices could not be found in a valid DRHD scope because the DHRD containing the device's scope was not added to vtd. Signed-off-by: Eric Joyner <erj@FreeBSD.org> PR: 268486 Sponsored by: Intel Corporation Reviewed by: rew@, corvink@ MFC after: 1 day Differential Revision: https://reviews.freebsd.org/D38285
* vmm: fix use after free in ppt_detach()Robert Wing2023-01-201-0/+2
| | | | | | | | The vmm module destroys the host_domain before unloading the ppt module causing a use after free. This can happen when kldunload'ing vmm. Reviewed by: markj, jhb Differential Revision: https://reviews.freebsd.org/D38072
* vmm: Fix build w/o KDTRACE_HOOKS.Dmitry Chagin2022-11-201-0/+4
| | | | | Reviewed by: imp Differential revision: https://reviews.freebsd.org/D37446
* vmm: Fix non-INVARIANTS buildCy Schubert2022-11-181-1/+1
| | | | | | | Reported by: O. Hartmann <freebsd@walstatt-de.de> Reviewed by: jhb Fixes: 58eefc67a1cf Differential Revision: https://reviews.freebsd.org/D37444
* vmm: Trim some pointless #ifdef KTR.John Baldwin2022-11-181-6/+0
| | | | | | Reported by: markj Reviewed by: corvink, markj Differential Revision: https://reviews.freebsd.org/D37272
* vmm: Convert VM_MAXCPU into a loader tunable hw.vmm.maxcpu.John Baldwin2022-11-181-5/+5
| | | | | | | | The default is now the number of physical CPUs in the system rather than 16. Reviewed by: corvink, markj Differential Revision: https://reviews.freebsd.org/D37175
* vmm vmx: Allocate vpids on demand as each vCPU is initialized.John Baldwin2022-11-182-31/+17
| | | | | | | | | | Compared to the previous version this does mean that if the system as a whole runs out of dedicated vPIDs you might end up with some vCPUs within a single VM using dedicated vPIDs and others using shared vPIDs, but this should not break anything. Reviewed by: corvink, markj Differential Revision: https://reviews.freebsd.org/D37169
* vmm: Pass vcpu instead of vm and vcpuid to APIs used from CPU backends.John Baldwin2022-11-184-71/+62
| | | | | Reviewed by: corvink, markj Differential Revision: https://reviews.freebsd.org/D37162
* vmm: Use struct vcpu in the instruction emulation code.John Baldwin2022-11-182-17/+17
| | | | | | | | | | | | | | | This passes struct vcpu down in place of struct vm and and integer vcpu index through the in-kernel instruction emulation code. To minimize userland disruption, helper macros are used for the vCPU arguments passed into and through the shared instruction emulation code. A few other APIs used by the instruction emulation code have also been updated to accept struct vcpu in the kernel including vm_get/set_register and vm_inject_fault. Reviewed by: corvink, markj Differential Revision: https://reviews.freebsd.org/D37161
* vmm: Use struct vcpu with the vmm_stat API.John Baldwin2022-11-181-19/+19
| | | | | | | The function callbacks still use struct vm and and vCPU index. Reviewed by: corvink, markj Differential Revision: https://reviews.freebsd.org/D37157
* vmm: Expose struct vcpu as an opaque type.John Baldwin2022-11-182-1/+4
| | | | | | | | | | | Pass a pointer to the current struct vcpu to the vcpu_init callback and save this pointer in the CPU-specific vcpu structures. Add routines to fetch a struct vcpu by index from a VM and to query the VM and vcpuid from a struct vcpu. Reviewed by: corvink, markj Differential Revision: https://reviews.freebsd.org/D37156
* vmm: Use VLAPIC_CTR* in more places.John Baldwin2022-11-181-13/+12
| | | | | Reviewed by: corvink, markj Differential Revision: https://reviews.freebsd.org/D37155
* vmm vmx: Add VMX_CTR* wrapper macros.John Baldwin2022-11-182-43/+50
| | | | | | | | These macros are similar to VCPU_CTR* but accept a single vmx_vcpu pointer as the first argument instead of separate vm and vcpuid. Reviewed by: corvink, markj Differential Revision: https://reviews.freebsd.org/D37154
* vmm: Remove the per-vm cookie argument from vmmops taking a vcpu.John Baldwin2022-11-182-91/+90
| | | | | | | | | | | This requires storing a reference to the per-vm cookie in the CPU-specific vCPU structure. Take advantage of this new field to remove no-longer-needed function arguments in the CPU-specific backends. In particular, stop passing the per-vm cookie to functions that either don't use it or only use it for KTR traces. Reviewed by: corvink, markj Differential Revision: https://reviews.freebsd.org/D37152
* vmm: Refactor storage of CPU-dependent per-vCPU data.John Baldwin2022-11-184-441/+464
| | | | | | | | | | | | | | | Rather than storing static arrays of per-vCPU data in the CPU-specific per-VM structure, adopt a more dynamic model similar to that used to manage CPU-specific per-VM data. That is, add new vmmops methods to init and cleanup a single vCPU. The init method returns a pointer that is stored in 'struct vcpu' as a cookie pointer. This cookie pointer is now passed to other vmmops callbacks in place of the integer index. The index is now only used in KTR traces and when calling back into the CPU-independent layer. Reviewed by: corvink, markj Differential Revision: https://reviews.freebsd.org/D37151
* vmm vmx: Add a global bool to indicate if the host has the TSC_AUX MSR.John Baldwin2022-11-183-18/+10
| | | | | | | | | A future commit will remove direct access to vCPU structures from struct vmx, so add a dedicated boolean for this rather than checking the capabilities for vCPU 0. Reviewed by: corvink, markj Differential Revision: https://reviews.freebsd.org/D37269
* vmm: Rework snapshotting of CPU-specific per-vCPU data.John Baldwin2022-11-181-48/+39
| | | | | | | | | | | Previously some per-vCPU state was saved in vmmops_snapshot and other state was saved in vmmops_vcmx_snapshot. Consolidate all per-vCPU state into the latter routine and rename the hook to the more generic 'vcpu_snapshot'. Note that the CPU-independent per-vCPU data is still stored in a separate blob as well as the per-vCPU local APIC data. Reviewed by: corvink, markj Differential Revision: https://reviews.freebsd.org/D37150
* vmm vmx: Refactor per-vCPU data.John Baldwin2022-11-183-132/+165
| | | | | | | | | | | | Add a struct vmx_vcpu to hold per-vCPU data specific to VT-x and move parallel arrays out of struct vmx into a single array of this structure. While here, dynamically allocate the VMCS, APIC page and PIR descriptors for each vCPU rather than embedding them. Reviewed by: corvink, markj Differential Revision: https://reviews.freebsd.org/D37149
* vmm: Use vm_get_maxcpus() instead of VM_MAXCPU in various places.John Baldwin2022-11-181-6/+6
| | | | | | | | Mostly these are loops that iterate over all possible vCPU IDs for a specific virtual machine. Reviewed by: corvink, markj Differential Revision: https://reviews.freebsd.org/D37147
* vmm: permit some IPIs to be handled by userspaceCorvin Köhne2022-10-141-0/+8
| | | | | | | | | | | Add VM_EXITCODE_IPI to permit returning unhandled IPIs to userland. INIT and STARTUP IPIs are now returned to userland. Due to backward compatibility reasons, a new capability is added for enabling VM_EXITCODE_IPI. Reviewed by: jhb Differential Revision: https://reviews.freebsd.org/D35623 Sponsored by: Beckhoff Automation GmbH & Co. KG
* Revert "vmm: permit some IPIs to be handled by userspace"Emmanuel Vadot2022-09-091-8/+0
| | | | | | | | This reverts commit a5a918b7a906eaa88e0833eac70a15989d535b02. This cause some problem with vm using bhyveload. Reported by: pho, kp
* vmm: permit some IPIs to be handled by userspaceCorvin Köhne2022-09-071-0/+8
| | | | | | | | | | | Add VM_EXITCODE_IPI to permit returning unhandled IPIs to userland. INIT and Startup IPIs are now returned to userland. Due to backward compatibility reasons, a new capability is added for enabling VM_EXITCODE_IPI. MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D35623 Sponsored by: Beckhoff Automation GmbH & Co. KG
* vmm: emulate INVD by ignoring itCorvin Köhne2022-07-271-1/+2
| | | | | | | | | | | | | On physical systems the ram isn't initialized on boot. So, coreboot uses the cache as ram in this boot phase. When exiting cache as ram, coreboot calls INVD for making the cache consistent. In a virtual environment ram is always initialized and the cache is always consistent. So, we can safely ignore this call. Reviewed by: jhb, imp Differential Revision: https://reviews.freebsd.org/D35620 Sponsored by: Beckhoff Automation GmbH & Co. KG
* vmm: move bumping VMEXIT_USERSPACE stat to the right placeVitaliy Gusev2022-06-091-3/+0
| | | | | | | | | | | | Statistic for "number of vm exits handled in userspace" should be increased in vm_run() instead of vmx_run() because in some cases vm_run() doesn't exit to userspace and keeps entering the guest. Also svm_run's implementation even wrongly misses that stat. Reviewed by: markj MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D35350