Confidential VMBus
Subsystems (5)
v7 cover Confidential VMBus
Hello all,
Enclosed is the 7th version of the patch series with all patches approved, and the delta against the 6th version is few non-functional changes suggested by Michael. Bagas also provided some feedback on how to use a simpler cross-reference mechanism in the Documentation based on some additional processing happening during "make htmldocs", and unfortunately that wouldn't work for "make pdfdocs" so I kept the original approach which is the standard :doc: role of Sphinx. I'll dig in into that anomaly separately.
Since v5, the fallback mechanism for establishing the VMBus connection is no longer used as the availability of the Confidential VMBus is now indicated by a bit in the Virtualization Stack (VS) CPUID leaf. The v6 patch series breaks that out into a separate patch seizing the opportunity to refactor the code that uses the same leaf. That is obviously an x86_64 specific technique. On ARM64, the Confidential VMBus is expected to be required once support for ARM CCA is implemented.
TLDR; is that these patches are for the Hyper-V guests, and the patches allow to keep data flowing from physical devices into the guests encrypted at the CPU level so that neither the root/host partition nor the hypervisor can access the data being processed (they only "see" the encrypted/garbled data) unless the guest decides to share it. The changes are backward compatible with older systems, and their full potential is realized on hardware that supports memory encryption.
These features also require running a paravisor, such as OpenHCL (https://github.com/microsoft/openvmm) used in Azure. Another implementation of the functionality available in this patch set is available in the Hyper-V UEFI: https://github.com/microsoft/mu_msvm.
A more detailed description of the patches follows.
The guests running on Hyper-V can be confidential where the memory and the register content are encrypted, provided that the hardware supports that (currently support for AMD SEV-SNP and Intel TDX is implemented) and the guest is capable of using these features. The confidential guests cannot be introspected by the host nor the hypervisor without the guest sharing the memory contents upon doing which the memory is decrypted.
In the confidential guests, neither the host nor the hypervisor need to be trusted, and the guests processing sensitive data can take advantage of that.
Not trusting the host and the hypervisor (removing them from the Trusted Computing Base aka TCB) necessitates that the method of communication between the host and the guest be changed. Here is the data flow for a conventional and the confidential VMBus connections (C stands for the client or VSC, S for the server or VSP, the DEVICE is a physical one, might be with multiple virtual functions):
1. Without the paravisor the devices are connected to the host, and the host provides the device emulation or translation to the guest:
+---- GUEST ----+ +----- DEVICE ----+ +----- HOST -----+
| | | | | |
| | | | | |
| | | ========== |
| | | | | |
| | | | | |
| | | | | |
+----- C -------+ +-----------------+ +------- S ------+
|| ||
|| ||
+------||------------------ VMBus --------------------------||------+
| Interrupts, MMIO |
+-------------------------------------------------------------------+2. With the paravisor, the devices are connected to the paravisor, and the paravisor provides the device emulation or translation to the guest. The guest doesn't communicate with the host directly, and the guest communicates with the paravisor via the VMBus. The host is not trusted in this model, and the paravisor is trusted:
+---- GUEST --------------- VTL0 ------+ +-- DEVICE --+
| | | |
| +- PARAVISOR --------- VTL2 -----+ | | |
| | +-- VMBus Relay ------+ ====+================ |
| | | Interrupts, MMIO | | | | |
| | +-------- S ----------+ | | +------------+
| | || | |
| +---------+ || | |
| | Linux | || OpenHCL | |
| | kernel | || | |
| +---- C --+-----||---------------+ |
| || || |
+-------++------- C -------------------+ +------------+
|| | HOST |
|| +---- S -----+
+-------||----------------- VMBus ---------------------------||-----+
| Interrupts, MMIO |
+-------------------------------------------------------------------+Note that in the second case the guest doesn't need to share the memory with the host as it communicates only with the paravisor within their partition boundary. That is precisely the raison d'etre and the value proposition of this patch series: equip the confidential guest to use private (encrypted) memory and rely on the paravisor when this is available to be more secure.
An implementation of the VMBus relay that offers the Confidential VMBus channels is available in the OpenVMM project as a part of the OpenHCL paravisor. Please refer to
* https://openvmm.dev/, and
* https://github.com/microsoft/openvmm
for more information about the OpenHCL paravisor. A VMBus client that can work with the Confidential VMBus is available in the open-source Hyper-V UEFI: https://github.com/microsoft/mu_msvm.
I'd like to thank the following people for their help with this patch series:
* Dexuan for help with validation and the fruitful discussions,
* Easwar for reviewing the refactoring of the page allocating and freeing in hv.c,
* John and Sven for the design,
* Mike for helping to avoid pitfalls when dealing with the GFP flags,
* Sven for blazing the trail and implementing the design in few codebases.
I made sure to validate the patch series on
{TrustedLaunch(x86_64), OpenHCL} x
{SNP(x86_64), TDX(x86_64), No hardware isolation, No paravisor} x
{VMBus 5.0, VMBus 6.0} x
{arm64, x86_64}.[V7]
- Removed the sentence about the fallible functions for setting/getting registers of the paravisor SynIC. That was no longer valid in v6.
- Fixed grammar and whitespace in the patch for Documentation. **Thank you, Michael!**
- Fixed the warning produced when building for i386 w/o Hyper-V. **Thank you, kernel robot!**
**Thank you, Michael!**
[V6] https://lore.kernel.org/linux-hyperv/[email protected]/
- Rebased onto the latest hyperv-next tree.
- Gave another thought to the fallible routines for getting and setting SynIC registers via paravisor introduced in the patch series, and after Michael's feedback decided to make them infallible as now we have the CPUID bit to indicate the availability of the Confidential VMBus. That simplifies the code and makes it clearer and more robust - a reflection of the improvements in the design throught the patch series iterations.
- Removed the sentence discussing the fallback mechanism in the Documentation as it is no longer relevant.
**Thank you, Michael!**
- Avoided using the macro'es for (un)masking the proxy bit thanks to union hv_synic_sint.
**Thank you, Wei!**
[V5] https://lore.kernel.org/linux-hyperv/[email protected]/
- Rebased onto the latest hyperv-next tree.
- Fixed build issues with the configs provided by the kernel robot. **Thank you, kernel robot!**
- Fixed the potential NULL deref in a failure path. **Thank you, Michael!**
- Removed the added blurb from the vmbus_drv.c with taxonomy of Hyper-V VMs that was providing reasons for the trade-offs in the fallback code. That code is no longer needed.
[V4] https://lore.kernel.org/linux-hyperv/[email protected]/
- Rebased the patch series on top of the latest hyperv-next branch, applying changes as needed.
- Fixed typos and clarifications all around the patch series.
- Added clarifications in the patch 7 for ms_hyperv.paravisor_present && !vmbus_is_confidential() and using hypercalls vs SNP or TDX specific protocols.
**Thank you, Alok!**
- Trim the Documentation changes to 80 columns. **Thank you, Randy!**
- Make sure adhere to the RST format, actually built the PDF docs and made sure the layout was correct.
**Thank you, Jon!**
- Better section order in Documentation.
- Fixed the commit descriptions where suggested.
- Moved EOI/EOM signaling for the confidential VMBus to the specialized function.
- Removed the unused cpu parameters.
- Clarified comments in the hv_per_cpu_context struct
- Explicitly test for NULL and only call iounmap() if non-NULL instead of using munmap().
- Don't deallocate SynIC pages in the CPU online and offline paths.
- Made sure the post page needs to be allocated for the future.
- Added comments to describe trade-offs.
**Thank you, Michael!**
[V3] https://lore.kernel.org/linux-hyperv/[email protected]/
- The patch series is rebased on top of the latest hyperv-next branch.
- Reworked the "wiring" diagram in the cover letter, added links to the OpenVMM project and the OpenHCL paravisor.
- More precise wording in the comments and clearer code. **Thank you, Alok!**
- Reworked the documentation patch.
- Split the patchset into much more granular patches.
- Various fixes and improvements throughout the patch series. **Thank you, Michael!**
[V2] https://lore.kernel.org/linux-hyperv/[email protected]/
- The patch series is rebased on top of the latest hyperv-next branch.
- Better wording in the commit messages and the Documentation. **Thank you, Alok and Wei!**
- Removed the patches 5 and 6 concerning turning bounce buffering off from the previous version of the patch series as they were found to be architecturally unsound. The value proposition of the patch series is not diminished by this removal: these patches were an optimization and only for the storage (for the simplicity sake) but not for the network. These changes might be proposed in the future again after revolving the issues.
** Thanks you, Christoph, Dexuan, Dan, Michael, James, Robin! **
[V1] https://lore.kernel.org/linux-hyperv/[email protected]/
Roman Kisel (17):
Documentation: hyperv: Confidential VMBus
Drivers: hv: VMBus protocol version 6.0
arch/x86: mshyperv: Discover Confidential VMBus availability
arch: hyperv: Get/set SynIC synth.registers via paravisor arch/x86: mshyperv: Trap on access for some synthetic MSRs
Drivers: hv: Rename fields for SynIC message and event pages
Drivers: hv: Allocate the paravisor SynIC pages when required
Drivers: hv: Post messages through the confidential VMBus if available
Drivers: hv: remove stale comment
Drivers: hv: Check message and event pages for non-NULL before
iounmap()
Drivers: hv: Rename the SynIC enable and disable routines
Drivers: hv: Functions for setting up and tearing down the paravisor
SynIC
Drivers: hv: Allocate encrypted buffers when requested
Drivers: hv: Free msginfo when the buffer fails to decrypt
Drivers: hv: Support confidential VMBus channels
Drivers: hv: Set the default VMBus version to 6.0
Drivers: hv: Support establishing the confidential VMBus connection
Documentation/virt/hyperv/coco.rst | 139 ++++++++++- arch/x86/kernel/cpu/mshyperv.c | 77 ++++-- drivers/hv/channel.c | 73 ++++-- drivers/hv/channel_mgmt.c | 27 ++- drivers/hv/connection.c | 6 +- drivers/hv/hv.c | 372 +++++++++++++++++++---------- drivers/hv/hv_common.c | 16 ++ drivers/hv/hyperv_vmbus.h | 75 +++++- drivers/hv/mshv_root.h | 2 +- drivers/hv/mshv_synic.c | 6 +- drivers/hv/ring_buffer.c | 5 +- drivers/hv/vmbus_drv.c | 186 ++++++++++----- include/asm-generic/mshyperv.h | 45 +--- include/hyperv/hvgdk_mini.h | 1 + include/linux/hyperv.h | 69 ++++-- 15 files changed, 793 insertions(+), 306 deletions(-)
base-commit: b595edcb24727e7f93e7962c3f6f971cc16dd29e
Signature · 1 line
2.43.0
PATCH v7 1/17 Documentation: hyperv: Confidential VMBus
Define what the confidential VMBus is and describe what advantages it offers on the capable hardware.
--- Documentation/virt/hyperv/coco.rst | 139 ++++++++++++++++++++++++++++- 1 file changed, 138 insertions(+), 1 deletion(-)
Documentation/virt/hyperv/coco.rst +138 -1
@@ -178,7 +178,7 @@ These Hyper-V and VMBus memory pages are marked as decrypted: * VMBus monitor pages -* Synthetic interrupt controller (synic) related pages (unless supplied by +* Synthetic interrupt controller (SynIC) related pages (unless supplied by the paravisor) * Per-cpu hypercall input and output pages (unless running with a paravisor)
@@ -232,6 +232,143 @@ with arguments explicitly describing the access. See _hv_pcifront_read_config() and _hv_pcifront_write_config() and the "use_calls" flag indicating to use hypercalls. +Confidential VMBus +------------------ +The confidential VMBus enables the confidential guest not to interact with +the untrusted host partition and the untrusted hypervisor. Instead, the guest +relies on the trusted paravisor to communicate with the devices processing +sensitive data. The hardware (SNP or TDX) encrypts the guest memory and the +register state while measuring the paravisor image using the platform security +processor to ensure trusted and confidential computing. + +Confidential VMBus provides a secure communication channel between the guest +and the paravisor, ensuring that sensitive data is protected from hypervisor- +level access through memory encryption and register state isolation. + +Confidential VMBus is an extension of Confidential Computing (CoCo) VMs +(a.k.a. "Isolated" VMs in Hyper-V terminology). Without Confidential VMBus, +guest VMBus device drivers (the "VSC"s in VMBus terminology) communicate +with VMBus servers (the VSPs) running on the Hyper-V host. The +communication must be through memory that has been decrypted so the +host can access it. With Confidential VMBus, one or more of the VSPs reside +in the trusted paravisor layer in the guest VM. Since the paravisor layer also +operates in encrypted memory, the memory used for communication with +such VSPs does not need to be decrypted and thereby exposed to the +Hyper-V host. The paravisor is responsible for communicating securely +with the Hyper-V host as necessary. + +The data is transferred directly between the VM and a vPCI device (a.k.a. +a PCI pass-thru device, see :doc:`vpci`) that is directly assigned to VTL2 +and that supports encrypted memory. In such a case, neither the host partition +nor the hypervisor has any access to the data. The guest needs to establish +a VMBus connection only with the paravisor for the channels that process +sensitive data, and the paravisor abstracts the details of communicating +with the specific devices away providing the guest with the well-established +VSP (Virtual Service Provider) interface that has had support in the Hyper-V +drivers for a decade. + +In the case the device does not support encrypted memory, the paravisor +provides bounce-buffering, and although the data is not encrypted, the backing +pages aren't mapped into the host partition through SLAT. While not impossible, +it becomes much more difficult for the host partition to exfiltrate the data +than it would be with a conventional VMBus connection where the host partition +has direct access to the memory used for communication. + +Here is the data flow for a conventional VMBus connection (`C` stands for the +client or VSC, `S` for the server or VSP, the `DEVICE` is a physical one, might +be with multiple virtual functions):: + + +---- GUEST ----+ +----- DEVICE ----+ +----- HOST -----+ + | | | | | | + | | | | | | + | | | ========== | + | | | | | | + | | | | | | + | | | | | | + +----- C -------+ +-----------------+ +------- S ------+ + || || + || || + +------||------------------ VMBus --------------------------||------+ + | Interrupts, MMIO | + +-------------------------------------------------------------------+ + +and the Confidential VMBus connection:: + + +---- GUEST --------------- VTL0 ------+ +-- DEVICE --+ + | | | | + | +- PARAVISOR --------- VTL2 -----+ | | | + | | +-- VMBus Relay ------+ ====+================ | + | | | Interrupts, MMIO | | | | | + | | +-------- S ----------+ | | +------------+ + | | || | | + | +---------+ || | | + | | Linux | || OpenHCL | | + | | kernel | || | | + | +---- C --+-----||---------------+ | + | || || | + +-------++------- C -------------------+ +------------+ + || | HOST | + || +---- S -----+ + +-------||----------------- VMBus ---------------------------||-----+ + | Interrupts, MMIO | + +-------------------------------------------------------------------+ + +An implementation of the VMBus relay that offers the Confidential VMBus +channels is available in the OpenVMM project as a part of the OpenHCL +paravisor. Please refer to + + * https://openvmm.dev/, and + * https://github.com/microsoft/openvmm + +for more information about the OpenHCL paravisor. + +A guest that is running with a paravisor must determine at runtime if +Confidential VMBus is supported by the current paravisor. The x86_64-specific +approach relies on the CPUID Virtualization Stack leaf; the ARM64 implementation +is expected to support the Confidential VMBus unconditionally when running +ARM CCA guests. + +Confidential VMBus is a characteristic of the VMBus connection as a whole, +and of each VMBus channel that is created. When a Confidential VMBus +connection is established, the paravisor provides the guest the message-passing +path that is used for VMBus device creation and deletion, and it provides a +per-CPU synthetic interrupt controller (SynIC) just like the SynIC that is +offered by the Hyper-V host. Each VMBus device that is offered to the guest +indicates the degree to which it participates in Confidential VMBus. The offer +indicates if the device uses encrypted ring buffers, and if the device uses +encrypted memory for DMA that is done outside the ring buffer. These settings +may be different for different devices using the same Confidential VMBus +connection. + +Although these settings are separate, in practice it'll always be encrypted +ring buffer only, or both encrypted ring buffer and external data. If a channel +is offered by the paravisor with confidential VMBus, the ring buffer can always +be encrypted since it's strictly for communication between the VTL2 paravisor +and the VTL0 guest. However, other memory regions are often used for e.g. DMA, +so they need to be accessible by the underlying hardware, and must be +unencrypted (unless the device supports encrypted memory). Currently, there are +not any VSPs in OpenHCL that support encrypted external memory, but future +versions are expected to enable this capability. + +Because some devices on a Confidential VMBus may require decrypted ring buffers +and DMA transfers, the guest must interact with two SynICs -- the one provided +by the paravisor and the one provided by the Hyper-V host when Confidential +VMBus is not offered. Interrupts are always signaled by the paravisor SynIC, +but the guest must check for messages and for channel interrupts on both SynICs. + +In the case of a confidential VMBus, regular SynIC access by the guest is +intercepted by the paravisor (this includes various MSRs such as the SIMP and +SIEFP, as well as hypercalls like HvPostMessage and HvSignalEvent). If the +guest actually wants to communicate with the hypervisor, it has to use special +mechanisms (GHCB page on SNP, or tdcall on TDX). Messages can be of either +kind: with confidential VMBus, messages use the paravisor SynIC, and if the +guest chose to communicate directly to the hypervisor, they use the hypervisor +SynIC. For interrupt signaling, some channels may be running on the host +(non-confidential, using the VMBus relay) and use the hypervisor SynIC, and +some on the paravisor and use its SynIC. The RelIDs are coordinated by the +OpenHCL VMBus server and are guaranteed to be unique regardless of whether +the channel originated on the host or the paravisor. + load_unaligned_zeropad() ------------------------ When transitioning memory between encrypted and decrypted, the caller of
Signature · 1 line
2.43.0
PATCH v7 2/17 Drivers: hv: VMBus protocol version 6.0
In reply to Roman KiselThe confidential VMBus is supported starting from the protocol version 6.0 onwards.
Provide the required definitions. No functional changes.
--- drivers/hv/hyperv_vmbus.h | 2 ++ drivers/hv/vmbus_drv.c | 12 +++++++ include/hyperv/hvgdk_mini.h | 1 + include/linux/hyperv.h | 69 +++++++++++++++++++++++++++---------- 4 files changed, 65 insertions(+), 19 deletions(-)
drivers/hv/hyperv_vmbus.h +2 -0
@@ -333,6 +333,8 @@ extern const struct vmbus_channel_message_table_entry/* General vmbus interface */ +bool vmbus_is_confidential (void ); +struct hv_device *vmbus_device_create (const guid_t *type,const guid_t *instance,struct vmbus_channel *channel);
drivers/hv/vmbus_drv.c +12 -0
@@ -56,6 +56,18 @@ static long __percpu *vmbus_evt;int vmbus_irq;int vmbus_interrupt; +/* +* If the Confidential VMBus is used, the data on the "wire" is not +* visible to either the host or the hypervisor. +*/ +static bool is_confidential; + +bool vmbus_is_confidential (void ) +{ +return is_confidential; +} +EXPORT_SYMBOL_GPL (vmbus_is_confidential); +/* * The panic notifier below is responsible solely for unloading the * vmbus connection, which is necessary in a panic event.
include/hyperv/hvgdk_mini.h +1 -0
@@ -260,6 +260,7 @@ union hv_hypervisor_version_info {#define HYPERV_CPUID_VIRT_STACK_PROPERTIES 0x40000082/* Support for the extended IOAPIC RTE format */ #define HYPERV_VS_PROPERTIES_EAX_EXTENDED_IOAPIC_RTE BIT(2) +#define HYPERV_VS_PROPERTIES_EAX_CONFIDENTIAL_VMBUS_AVAILABLE BIT(3)#define HYPERV_HYPERVISOR_PRESENT_BIT 0x80000000#define HYPERV_CPUID_MIN 0x40000005
include/linux/hyperv.h +50 -19
105 lines not on this page · raw message
Signature · 1 line
2.43.0
PATCH v7 3/17 arch/x86: mshyperv: Discover Confidential VMBus availability
In reply to Roman KiselConfidential VMBus requires enabling paravisor SynIC, and the x86_64 guest has to inspect the Virtualization Stack (VS) CPUID leaf to see if Confidential VMBus is available. If it is, the guest shall enable the paravisor SynIC.
Read the relevant data from the VS CPUID leaf. Refactor the code to avoid repeating CPUID and add flags to the struct ms_hyperv_info. For ARM64, the flag for Confidential VMBus is not set which provides the desired behaviour for now as it is not available on ARM64 just yet. Once ARM64 CCA guests are supported, this flag will be set unconditionally when running such a guest.
--- arch/x86/kernel/cpu/mshyperv.c | 28 +++++++++++++++------------- include/asm-generic/mshyperv.h | 2 ++ 2 files changed, 17 insertions(+), 13 deletions(-)
arch/x86/kernel/cpu/mshyperv.c +15 -13
@@ -434,7 +434,7 @@ EXPORT_SYMBOL_GPL(hv_get_hypervisor_version);static void __init ms_hyperv_init_platform (void ) { -int hv_max_functions_eax; +int hv_max_functions_eax, eax;#ifdef CONFIG_PARAVIRT pv_info.name ="Hyper-V" ;
@@ -469,6 +469,19 @@ static void __init ms_hyperv_init_platform(void)pr_info ("Hyper-V: running on a nested hypervisor\n" ); } +/* +* There is no check against the max function for HYPERV_CPUID_VIRT_STACK_* CPUID +* leaves as the hypervisor doesn't handle them. Even a nested root partition (L2 +* root) will not get them because the nested (L1) hypervisor filters them out. +* These are handled through intercept processing by the Windows Hyper-V stack +* or the paravisor. +*/ + eax =cpuid_eax (HYPERV_CPUID_VIRT_STACK_PROPERTIES ); + ms_hyperv.confidential_vmbus_available = + eax &HYPERV_VS_PROPERTIES_EAX_CONFIDENTIAL_VMBUS_AVAILABLE ; + ms_hyperv.msi_ext_dest_id = + eax &HYPERV_VS_PROPERTIES_EAX_EXTENDED_IOAPIC_RTE ; +if (ms_hyperv.features &HV_ACCESS_FREQUENCY_MSRS && ms_hyperv.misc_features &HV_FEATURE_FREQUENCY_MSRS_AVAILABLE ) { x86_platform.calibrate_tsc = hv_get_tsc_khz;
@@ -668,21 +681,10 @@ static bool __init ms_hyperv_x2apic_available(void)* pci-hyperv host bridge. * * Note: for a Hyper-V root partition, this will always return false. -* The hypervisor doesn't expose these HYPERV_CPUID_VIRT_STACK_* cpuids by -* default, they are implemented as intercepts by the Windows Hyper-V stack. -* Even a nested root partition (L2 root) will not get them because the -* nested (L1) hypervisor filters them out. */ static bool __init ms_hyperv_msi_ext_dest_id (void ) { -u32 eax; - - eax =cpuid_eax (HYPERV_CPUID_VIRT_STACK_INTERFACE ); -if (eax !=HYPERV_VS_INTERFACE_EAX_SIGNATURE ) -return false; - - eax =cpuid_eax (HYPERV_CPUID_VIRT_STACK_PROPERTIES ); -return eax &HYPERV_VS_PROPERTIES_EAX_EXTENDED_IOAPIC_RTE ; +return ms_hyperv.msi_ext_dest_id; }#ifdef CONFIG_AMD_MEM_ENCRYPT
include/asm-generic/mshyperv.h +2 -0
@@ -62,6 +62,8 @@ struct ms_hyperv_info { }; };u64 shared_gpa_boundary; +bool msi_ext_dest_id; +bool confidential_vmbus_available; };extern struct ms_hyperv_info ms_hyperv;extern bool hv_nested;
Signature · 1 line
2.43.0
PATCH v7 4/17 arch: hyperv: Get/set SynIC synth.registers via paravisor
In reply to Roman KiselThe existing Hyper-V wrappers for getting and setting MSRs are hv_get/set_msr(). Via hv_get/set_non_nested_msr(), they detect when running in a CoCo VM with a paravisor, and use the TDX or SNP guest-host communication protocol to bypass the paravisor and go directly to the host hypervisor for SynIC MSRs. The "set" function also implements the required special handling for the SINT MSRs.
Provide functions that allow manipulating the SynIC registers through the paravisor. Move vmbus_signal_eom() to a more appropriate location (which also avoids breaking KVM).
--- arch/x86/kernel/cpu/mshyperv.c | 20 ++++++++++++++++ drivers/hv/hv_common.c | 11 +++++++++ drivers/hv/hyperv_vmbus.h | 44 ++++++++++++++++++++++++++++++++++ include/asm-generic/mshyperv.h | 42 ++------------------------------ 4 files changed, 77 insertions(+), 40 deletions(-)
arch/x86/kernel/cpu/mshyperv.c +20 -0
@@ -90,6 +90,26 @@ void hv_set_non_nested_msr(unsigned int reg, u64 value) }EXPORT_SYMBOL_GPL (hv_set_non_nested_msr); +/* +* Get the SynIC register value from the paravisor. +*/ +u64 hv_para_get_synic_register (unsigned int reg) +{ +if (WARN_ON (!ms_hyperv.paravisor_present || !hv_is_synic_msr (reg))) +return ~0ULL ; +return native_read_msr (reg); +} + +/* +* Set the SynIC register value with the paravisor. +*/ +void hv_para_set_synic_register (unsigned int reg,u64 val) +{ +if (WARN_ON (!ms_hyperv.paravisor_present || !hv_is_synic_msr (reg))) +return ; +native_write_msr (reg, val); +} +u64 hv_get_msr (unsigned int reg) {if (hv_nested)
drivers/hv/hv_common.c +11 -0
@@ -716,6 +716,17 @@ u64 __weak hv_tdx_hypercall(u64 control, u64 param1, u64 param2) }EXPORT_SYMBOL_GPL (hv_tdx_hypercall); +u64 __weak hv_para_get_synic_register (unsigned int reg) +{ +return ~0ULL ; +} +EXPORT_SYMBOL_GPL (hv_para_get_synic_register); + +void __weak hv_para_set_synic_register (unsigned int reg,u64 val) +{ +} +EXPORT_SYMBOL_GPL (hv_para_set_synic_register); +void hv_identify_partition_type (void ) {/* Assume guest role */
drivers/hv/hyperv_vmbus.h +44 -0
56 lines not on this page · raw message
include/asm-generic/mshyperv.h +2 -40
54 lines not on this page · raw message
Signature · 1 line
2.43.0
PATCH v7 5/17 arch/x86: mshyperv: Trap on access for some synthetic MSRs
In reply to Roman Kiselhv_set_non_nested_msr() has special handling for SINT MSRs when a paravisor is present. In addition to updating the MSR on the host, the mirror MSR in the paravisor is updated, including with the proxy bit. But with Confidential VMBus, the proxy bit must not be used, so add a special case to skip it.
--- arch/x86/kernel/cpu/mshyperv.c | 29 +++++++++++++++++++++++++---- drivers/hv/hv_common.c | 5 +++++ include/asm-generic/mshyperv.h | 1 + 3 files changed, 31 insertions(+), 4 deletions(-)
arch/x86/kernel/cpu/mshyperv.c +25 -4
@@ -28,6 +28,7 @@#include <asm/apic.h> #include <asm/timer.h> #include <asm/reboot.h> +#include <asm/msr.h> #include <asm/nmi.h> #include <clocksource/hyperv_timer.h> #include <asm/msr.h>
@@ -43,6 +44,12 @@ bool hyperv_paravisor_present __ro_after_init;EXPORT_SYMBOL_GPL (hyperv_paravisor_present);#if IS_ENABLED (CONFIG_HYPERV ) +/* +* When running with the paravisor, controls proxying the synthetic interrupts +* from the host +*/ +static bool hv_para_sint_proxy; +static inline unsigned int hv_get_nested_msr (unsigned int reg) {if (hv_is_sint_msr (reg))
@@ -79,17 +86,31 @@ EXPORT_SYMBOL_GPL(hv_get_non_nested_msr);void hv_set_non_nested_msr (unsigned int reg,u64 value) {if (hv_is_synic_msr (reg) && ms_hyperv.paravisor_present) { +/* The hypervisor will get the intercept. */ hv_ivm_msr_write (reg, value); -/* Write proxy bit via wrmsl instruction */ -if (hv_is_sint_msr (reg)) -wrmsrq (reg, value |1 <<20 ); +/* Using wrmsrq so the following goes to the paravisor. */ +if (hv_is_sint_msr (reg)) { +union hv_synic_sint sint = { .as_uint64 = value }; + + sint.proxy = hv_para_sint_proxy; +native_wrmsrq (reg, sint.as_uint64); + } }else { -wrmsrq (reg, value); +native_wrmsrq (reg, value); } }EXPORT_SYMBOL_GPL (hv_set_non_nested_msr); +/* +* Enable or disable proxying synthetic interrupts +* to the paravisor. +*/ +void hv_para_set_sint_proxy (bool enable) +{ + hv_para_sint_proxy = enable; +} +/* * Get the SynIC register value from the paravisor. */
drivers/hv/hv_common.c +5 -0
@@ -716,6 +716,11 @@ u64 __weak hv_tdx_hypercall(u64 control, u64 param1, u64 param2) }EXPORT_SYMBOL_GPL (hv_tdx_hypercall); +void __weak hv_para_set_sint_proxy (bool enable) +{ +} +EXPORT_SYMBOL_GPL (hv_para_set_sint_proxy); +u64 __weak hv_para_get_synic_register (unsigned int reg) {return ~0ULL ;
include/asm-generic/mshyperv.h +1 -0
@@ -298,6 +298,7 @@ bool hv_is_isolation_supported(void);bool hv_isolation_type_snp (void );u64 hv_ghcb_hypercall (u64 control,void *input,void *output,u32 input_size);u64 hv_tdx_hypercall (u64 control,u64 param1,u64 param2); +void hv_para_set_sint_proxy (bool enable);u64 hv_para_get_synic_register (unsigned int reg);void hv_para_set_synic_register (unsigned int reg,u64 val);void hyperv_cleanup (void );
Signature · 1 line
2.43.0
PATCH v7 6/17 Drivers: hv: Rename fields for SynIC message and event pages
In reply to Roman KiselConfidential VMBus requires interacting with two SynICs -- one provided by the host hypervisor, and one provided by the paravisor. Each SynIC requires its own message and event pages.
Rename the existing host-accessible SynIC message and event pages with the "hyp_" prefix to clearly distinguish them from the paravisor ones. The field name is also changed in mshv_root.* for consistency.
No functional changes.
--- drivers/hv/channel_mgmt.c | 6 ++-- drivers/hv/hv.c | 66 +++++++++++++++++++-------------------- drivers/hv/hyperv_vmbus.h | 4 +-- drivers/hv/mshv_root.h | 2 +- drivers/hv/mshv_synic.c | 6 ++-- drivers/hv/vmbus_drv.c | 6 ++-- 6 files changed, 45 insertions(+), 45 deletions(-)
drivers/hv/channel_mgmt.c +3 -3
@@ -844,14 +844,14 @@ static void vmbus_wait_for_unload(void) = per_cpu_ptr(hv_context.cpu_context, cpu);/* -* In a CoCo VM the synic_message_page is not allocated +* In a CoCo VM the hyp_synic_message_page is not allocated * in hv_synic_alloc(). Instead it is set/cleared in * hv_synic_enable_regs() and hv_synic_disable_regs() * such that it is set only when the CPU is online. If * not all present CPUs are online, the message page * might be NULL, so skip such CPUs. */ - page_addr = hv_cpu->synic_message_page; + page_addr = hv_cpu->hyp_synic_message_page;if (!page_addr)continue ;
@@ -892,7 +892,7 @@ static void vmbus_wait_for_unload(void)struct hv_per_cpu_context *hv_cpu =per_cpu_ptr (hv_context.cpu_context, cpu); - page_addr = hv_cpu->synic_message_page; + page_addr = hv_cpu->hyp_synic_message_page;if (!page_addr)continue ;
drivers/hv/hv.c +33 -33
158 lines not on this page · raw message
drivers/hv/hyperv_vmbus.h +2 -2
@@ -121,8 +121,8 @@ enum {* Per cpu state for channel handling */ struct hv_per_cpu_context { -void *synic_message_page; -void *synic_event_page; +void *hyp_synic_message_page; +void *hyp_synic_event_page;/* * The page is only used in hv_post_message() for a TDX VM (with the
drivers/hv/mshv_root.h +1 -1
@@ -169,7 +169,7 @@ struct mshv_girq_routing_table { };struct hv_synic_pages { -struct hv_message_page *synic_message_page; +struct hv_message_page *hyp_synic_message_page;struct hv_synic_event_flags_page *synic_event_flags_page;struct hv_synic_event_ring_page *synic_event_ring_page; };
drivers/hv/mshv_synic.c +3 -3
@@ -394,7 +394,7 @@ mshv_intercept_isr(struct hv_message *msg)void mshv_isr (void ) {struct hv_synic_pages *spages =this_cpu_ptr (mshv_root.synic_pages); -struct hv_message_page **msg_page = &spages->synic_message_page; +struct hv_message_page **msg_page = &spages->hyp_synic_message_page;struct hv_message *msg;bool handled;
@@ -456,7 +456,7 @@ int mshv_synic_init(unsigned int cpu)#endif union hv_synic_scontrol sctrl;struct hv_synic_pages *spages =this_cpu_ptr (mshv_root.synic_pages); -struct hv_message_page **msg_page = &spages->synic_message_page; +struct hv_message_page **msg_page = &spages->hyp_synic_message_page;struct hv_synic_event_flags_page **event_flags_page = &spages->synic_event_flags_page; struct hv_synic_event_ring_page **event_ring_page =
@@ -550,7 +550,7 @@ int mshv_synic_cleanup(unsigned int cpu)union hv_synic_sirbp sirbp;union hv_synic_scontrol sctrl;struct hv_synic_pages *spages =this_cpu_ptr (mshv_root.synic_pages); -struct hv_message_page **msg_page = &spages->synic_message_page; +struct hv_message_page **msg_page = &spages->hyp_synic_message_page;struct hv_synic_event_flags_page **event_flags_page = &spages->synic_event_flags_page; struct hv_synic_event_ring_page **event_ring_page =
drivers/hv/vmbus_drv.c +3 -3
@@ -1060,7 +1060,7 @@ static void vmbus_onmessage_work(struct work_struct *work)void vmbus_on_msg_dpc (unsigned long data) {struct hv_per_cpu_context *hv_cpu = (void *)data; -void *page_addr = hv_cpu->synic_message_page; +void *page_addr = hv_cpu->hyp_synic_message_page;struct hv_message msg_copy, *msg = (struct hv_message *)page_addr +VMBUS_MESSAGE_SINT ;struct vmbus_channel_message_header *hdr;
@@ -1244,7 +1244,7 @@ static void vmbus_chan_sched(struct hv_per_cpu_context *hv_cpu)* The event page can be directly checked to get the id of * the channel that has the interrupt pending. */ -void *page_addr = hv_cpu->synic_event_page; +void *page_addr = hv_cpu->hyp_synic_event_page;union hv_synic_event_flags *event = (union hv_synic_event_flags *)page_addr +VMBUS_MESSAGE_SINT ;
@@ -1327,7 +1327,7 @@ static void vmbus_isr(void)vmbus_chan_sched (hv_cpu); - page_addr = hv_cpu->synic_message_page; + page_addr = hv_cpu->hyp_synic_message_page; msg = (struct hv_message *)page_addr +VMBUS_MESSAGE_SINT ;/* Check if there are actual msgs to be processed */
Signature · 1 line
2.43.0
PATCH v7 7/17 Drivers: hv: Allocate the paravisor SynIC pages when required
In reply to Roman KiselConfidential VMBus requires interacting with two SynICs -- one provided by the host hypervisor, and one provided by the paravisor. Each SynIC requires its own message and event pages.
Refactor and extend the existing code to add allocating and freeing the message and event pages for the paravisor SynIC when it is present.
--- drivers/hv/hv.c | 184 +++++++++++++++++++------------------- drivers/hv/hyperv_vmbus.h | 18 ++++ 2 files changed, 112 insertions(+), 90 deletions(-)
drivers/hv/hv.c +94 -90
@@ -96,10 +96,70 @@ int hv_post_message(union hv_connection_id connection_id,return hv_result (status); } +static int hv_alloc_page (void **page,bool decrypt,const char *note) +{ +int ret =0 ; + +/* +* After the page changes its encryption status, its contents might +* appear scrambled on some hardware. Thus `get_zeroed_page` would +* zero the page out in vain, so do that explicitly exactly once. +* +* By default, the page is allocated encrypted in a CoCo VM. +*/ + *page = (void *)__get_free_page (GFP_KERNEL ); +if (!*page) +return -ENOMEM ; + +if (decrypt) + ret =set_memory_decrypted ((unsigned long )*page,1 ); +if (ret) + goto failed; + +memset (*page,0 ,PAGE_SIZE ); +return 0 ; + +failed: +/* +* Report the failure but don't put the page back on the free list as +* its encryption status is unknown. +*/ +pr_err ("allocation failed for %s page, error %d, decrypted %d\n" , + note, ret, decrypt); + *page =NULL ; +return ret; +} + +static int hv_free_page (void **page,bool encrypt,const char *note) +{ +int ret =0 ; + +if (!*page) +return 0 ; + +if (encrypt) + ret =set_memory_encrypted ((unsigned long )*page,1 ); + +/* +* In the case of the failure, the page is leaked. Something is wrong, +* prefer to lose the page with the unknown encryption status and stay afloat. +*/ +if (ret) +pr_err ("deallocation failed for %s page, error %d, encrypt %d\n" , + note, ret, encrypt); +else +free_page ((unsigned long )*page); + + *page =NULL ; + +return ret; +} +int hv_synic_alloc (void ) {int cpu, ret = -ENOMEM ;struct hv_per_cpu_context *hv_cpu; +const bool decrypt = !vmbus_is_confidential ();/* * First, zero all per-cpu memory areas so hv_synic_free() can
@@ -125,73 +185,37 @@ int hv_synic_alloc(void) vmbus_on_msg_dpc, (unsigned long)hv_cpu);if (ms_hyperv.paravisor_present &&hv_isolation_type_tdx ()) { - hv_cpu->post_msg_page = (void *)get_zeroed_page (GFP_ATOMIC ); -if (!hv_cpu->post_msg_page) { -pr_err ("Unable to allocate post msg page\n" ); + ret =hv_alloc_page (&hv_cpu->post_msg_page, + decrypt,"post msg" ); +if (ret) goto err; - } - - ret =set_memory_decrypted ((unsigned long )hv_cpu->post_msg_page,1 ); -if (ret) { -pr_err ("Failed to decrypt post msg page: %d\n" , ret); -/* Just leak the page, as it's unsafe to free the page. */ - hv_cpu->post_msg_page =NULL ; - goto err; - } - -memset (hv_cpu->post_msg_page,0 ,PAGE_SIZE ); }/* -* Synic message and event pages are allocated by paravisor. -* Skip these pages allocation here. +* If these SynIC pages are not allocated, SIEF and SIM pages +* are configured using what the root partition or the paravisor +* provides upon reading the SIEFP and SIMP registers. */ if (!ms_hyperv.paravisor_present && !hv_root_partition ()) { - hv_cpu->hyp_synic_message_page = - (void *)get_zeroed_page (GFP_ATOMIC ); -if (!hv_cpu->hyp_synic_message_page) { -pr_err ("Unable to allocate SYNIC message page\n" ); + ret =hv_alloc_page (&hv_cpu->hyp_synic_message_page, + decrypt,"hypervisor SynIC msg" ); +if (ret) goto err; - } - - hv_cpu->hyp_synic_event_page = - (void *)get_zeroed_page (GFP_ATOMIC ); -if (!hv_cpu->hyp_synic_event_page) { -pr_err ("Unable to allocate SYNIC event page\n" ); - -free_page ((unsigned long )hv_cpu->hyp_synic_message_page); - hv_cpu->hyp_synic_message_page =NULL ; + ret =hv_alloc_page (&hv_cpu->hyp_synic_event_page, + decrypt,"hypervisor SynIC event" ); +if (ret) goto err; - } } -if (!ms_hyperv.paravisor_present && - (hv_isolation_type_snp () ||hv_isolation_type_tdx ())) { - ret =set_memory_decrypted ((unsigned long ) - hv_cpu->hyp_synic_message_page,1 ); -if (ret) { -pr_err ("Failed to decrypt SYNIC msg page: %d\n" , ret); - hv_cpu->hyp_synic_message_page =NULL ; - -/* -* Free the event page here so that hv_synic_free() -* won't later try to re-encrypt it. -*/ -free_page ((unsigned long )hv_cpu->hyp_synic_event_page); - hv_cpu->hyp_synic_event_page =NULL ; +if (vmbus_is_confidential ()) { + ret =hv_alloc_page (&hv_cpu->para_synic_message_page, + false,"paravisor SynIC msg" ); +if (ret) goto err; - } - - ret =set_memory_decrypted ((unsigned long ) - hv_cpu->hyp_synic_event_page,1 ); -if (ret) { -pr_err ("Failed to decrypt SYNIC event page: %d\n" , ret); - hv_cpu->hyp_synic_event_page =NULL ; + ret =hv_alloc_page (&hv_cpu->para_synic_event_page, + false,"paravisor SynIC event" ); +if (ret) goto err; - } - -memset (hv_cpu->hyp_synic_message_page,0 ,PAGE_SIZE ); -memset (hv_cpu->hyp_synic_event_page,0 ,PAGE_SIZE ); } }
@@ -207,48 +231,28 @@ int hv_synic_alloc(void)void hv_synic_free (void ) { -int cpu, ret; +int cpu; +const bool encrypt = !vmbus_is_confidential ();for_each_present_cpu (cpu) {struct hv_per_cpu_context *hv_cpu =per_cpu_ptr (hv_context.cpu_context, cpu); -/* It's better to leak the page if the encryption fails. */ -if (ms_hyperv.paravisor_present &&hv_isolation_type_tdx ()) { -if (hv_cpu->post_msg_page) { - ret =set_memory_encrypted ((unsigned long ) - hv_cpu->post_msg_page,1 ); -if (ret) { -pr_err ("Failed to encrypt post msg page: %d\n" , ret); - hv_cpu->post_msg_page =NULL ; - } - } +if (ms_hyperv.paravisor_present &&hv_isolation_type_tdx ()) +hv_free_page (&hv_cpu->post_msg_page, + encrypt,"post msg" ); +if (!ms_hyperv.paravisor_present && !hv_root_partition ()) { +hv_free_page (&hv_cpu->hyp_synic_event_page, + encrypt,"hypervisor SynIC event" ); +hv_free_page (&hv_cpu->hyp_synic_message_page, + encrypt,"hypervisor SynIC msg" ); } - -if (!ms_hyperv.paravisor_present && - (hv_isolation_type_snp () ||hv_isolation_type_tdx ())) { -if (hv_cpu->hyp_synic_message_page) { - ret =set_memory_encrypted ((unsigned long ) - hv_cpu->hyp_synic_message_page,1 ); -if (ret) { -pr_err ("Failed to encrypt SYNIC msg page: %d\n" , ret); - hv_cpu->hyp_synic_message_page =NULL ; - } - } - -if (hv_cpu->hyp_synic_event_page) { - ret =set_memory_encrypted ((unsigned long ) - hv_cpu->hyp_synic_event_page,1 ); -if (ret) { -pr_err ("Failed to encrypt SYNIC event page: %d\n" , ret); - hv_cpu->hyp_synic_event_page =NULL ; - } - } +if (vmbus_is_confidential ()) { +hv_free_page (&hv_cpu->para_synic_event_page, + false,"paravisor SynIC event" ); +hv_free_page (&hv_cpu->para_synic_message_page, + false,"paravisor SynIC msg" ); } - -free_page ((unsigned long )hv_cpu->post_msg_page); -free_page ((unsigned long )hv_cpu->hyp_synic_event_page); -free_page ((unsigned long )hv_cpu->hyp_synic_message_page); }kfree (hv_context.hv_numa_map);
drivers/hv/hyperv_vmbus.h +18 -0
@@ -121,8 +121,26 @@ enum {* Per cpu state for channel handling */ struct hv_per_cpu_context { +/* +* SynIC pages for communicating with the host. +* +* These pages are accessible to the host partition and the hypervisor. +* They may be used for exchanging data with the host partition and the +* hypervisor even when they aren't trusted yet the guest partition +* must be prepared to handle the malicious behavior. +*/ void *hyp_synic_message_page;void *hyp_synic_event_page; +/* +* SynIC pages for communicating with the paravisor. +* +* These pages may be accessed from within the guest partition only in +* CoCo VMs. Neither the host partition nor the hypervisor can access +* these pages in that case; they are used for exchanging data with the +* paravisor. +*/ +void *para_synic_message_page; +void *para_synic_event_page;/* * The page is only used in hv_post_message() for a TDX VM (with the
Signature · 1 line
2.43.0
PATCH v7 8/17 Drivers: hv: Post messages through the confidential VMBus if available
In reply to Roman KiselWhen the confidential VMBus is available, the guest should post messages to the paravisor.
Update hv_post_message() to post messages to the paravisor rather than through GHCB or TD calls.
--- drivers/hv/hv.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
drivers/hv/hv.c +10 -1
@@ -74,7 +74,11 @@ int hv_post_message(union hv_connection_id connection_id, aligned_msg->payload_size = payload_size;memcpy ((void *)aligned_msg->payload, payload, payload_size); -if (ms_hyperv.paravisor_present) { +if (ms_hyperv.paravisor_present && !vmbus_is_confidential ()) { +/* +* If the VMBus isn't confidential, use the CoCo-specific +* mechanism to communicate with the hypervisor. +*/ if (hv_isolation_type_tdx ()) status =hv_tdx_hypercall (HVCALL_POST_MESSAGE ,virt_to_phys (aligned_msg),0 );
@@ -88,6 +92,11 @@ int hv_post_message(union hv_connection_id connection_id,u64 control =HVCALL_POST_MESSAGE ; control |= hv_nested ?HV_HYPERCALL_NESTED :0 ; +/* +* If there is no paravisor, this will go to the hypervisor. +* In the Confidential VMBus case, there is the paravisor +* to which this will trap. +*/ status =hv_do_hypercall (control, aligned_msg,NULL ); }
Signature · 1 line
2.43.0
PATCH v7 9/17 Drivers: hv: remove stale comment
In reply to Roman KiselThe comment about the x2v shim is ancient and long since incorrect.
Remove the incorrect comment.
--- drivers/hv/hv.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
drivers/hv/hv.c +1 -5
@@ -268,11 +268,7 @@ void hv_synic_free(void) }/* -* hv_synic_init - Initialize the Synthetic Interrupt Controller. -* -* If it is already initialized by another entity (ie x2v shim), we need to -* retrieve the initialized message and event pages. Otherwise, we create and -* initialize the message and event pages. +* hv_synic_enable_regs - Initialize the Synthetic Interrupt Controller. */ void hv_synic_enable_regs (unsigned int cpu) {
Signature · 1 line
2.43.0
PATCH v7 10/17 Drivers: hv: Check message and event pages for non-NULL before iounmap()
In reply to Roman KiselIt might happen that some hyp SynIC pages aren't allocated.
Check for that and only then call iounmap().
--- drivers/hv/hv.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
drivers/hv/hv.c +8 -4
@@ -369,8 +369,10 @@ void hv_synic_disable_regs(unsigned int cpu)*/ simp.simp_enabled =0 ;if (ms_hyperv.paravisor_present ||hv_root_partition ()) { -iounmap (hv_cpu->hyp_synic_message_page); - hv_cpu->hyp_synic_message_page =NULL ; +if (hv_cpu->hyp_synic_message_page) { +iounmap (hv_cpu->hyp_synic_message_page); + hv_cpu->hyp_synic_message_page =NULL ; + } }else { simp.base_simp_gpa =0 ; }
@@ -381,8 +383,10 @@ void hv_synic_disable_regs(unsigned int cpu) siefp.siefp_enabled =0 ;if (ms_hyperv.paravisor_present ||hv_root_partition ()) { -iounmap (hv_cpu->hyp_synic_event_page); - hv_cpu->hyp_synic_event_page =NULL ; +if (hv_cpu->hyp_synic_event_page) { +iounmap (hv_cpu->hyp_synic_event_page); + hv_cpu->hyp_synic_event_page =NULL ; + } }else { siefp.base_siefp_gpa =0 ; }
Signature · 1 line
2.43.0
PATCH v7 11/17 Drivers: hv: Rename the SynIC enable and disable routines
In reply to Roman KiselThe confidential VMBus requires support for the both hypervisor facing SynIC and the paravisor one.
Rename the functions that enable and disable SynIC with the hypervisor. No functional changes.
--- drivers/hv/channel_mgmt.c | 2 +- drivers/hv/hv.c | 11 ++++++----- drivers/hv/hyperv_vmbus.h | 4 ++-- drivers/hv/vmbus_drv.c | 6 +++--- 4 files changed, 12 insertions(+), 11 deletions(-)
drivers/hv/channel_mgmt.c +1 -1
@@ -846,7 +846,7 @@ static void vmbus_wait_for_unload(void)/* * In a CoCo VM the hyp_synic_message_page is not allocated * in hv_synic_alloc(). Instead it is set/cleared in -* hv_synic_enable_regs() and hv_synic_disable_regs() +* hv_hyp_synic_enable_regs() and hv_hyp_synic_disable_regs() * such that it is set only when the CPU is online. If * not all present CPUs are online, the message page * might be NULL, so skip such CPUs.
drivers/hv/hv.c +6 -5
@@ -268,9 +268,10 @@ void hv_synic_free(void) }/* -* hv_synic_enable_regs - Initialize the Synthetic Interrupt Controller. +* hv_hyp_synic_enable_regs - Initialize the Synthetic Interrupt Controller +* with the hypervisor. */ -void hv_synic_enable_regs (unsigned int cpu) +void hv_hyp_synic_enable_regs (unsigned int cpu) {struct hv_per_cpu_context *hv_cpu =per_cpu_ptr (hv_context.cpu_context, cpu);
@@ -336,14 +337,14 @@ void hv_synic_enable_regs(unsigned int cpu)int hv_synic_init (unsigned int cpu) { -hv_synic_enable_regs (cpu); +hv_hyp_synic_enable_regs (cpu);hv_stimer_legacy_init (cpu,VMBUS_MESSAGE_SINT );return 0 ; } -void hv_synic_disable_regs (unsigned int cpu) +void hv_hyp_synic_disable_regs (unsigned int cpu) {struct hv_per_cpu_context *hv_cpu =per_cpu_ptr (hv_context.cpu_context, cpu);
@@ -530,7 +531,7 @@ int hv_synic_cleanup(unsigned int cpu) always_cleanup:hv_stimer_legacy_cleanup (cpu); -hv_synic_disable_regs (cpu); +hv_hyp_synic_disable_regs (cpu);return ret; }
drivers/hv/hyperv_vmbus.h +2 -2
@@ -190,10 +190,10 @@ extern int hv_synic_alloc(void);extern void hv_synic_free (void ); -extern void hv_synic_enable_regs (unsigned int cpu); +extern void hv_hyp_synic_enable_regs (unsigned int cpu);extern int hv_synic_init (unsigned int cpu); -extern void hv_synic_disable_regs (unsigned int cpu); +extern void hv_hyp_synic_disable_regs (unsigned int cpu);extern int hv_synic_cleanup (unsigned int cpu);/* Interface */
drivers/hv/vmbus_drv.c +3 -3
@@ -2810,7 +2810,7 @@ static void hv_crash_handler(struct pt_regs *regs)*/ cpu =smp_processor_id ();hv_stimer_cleanup (cpu); -hv_synic_disable_regs (cpu); +hv_hyp_synic_disable_regs (cpu); };static int hv_synic_suspend (void )
@@ -2835,14 +2835,14 @@ static int hv_synic_suspend(void)* interrupts-disabled context. */ -hv_synic_disable_regs (0 ); +hv_hyp_synic_disable_regs (0 );return 0 ; }static void hv_synic_resume (void ) { -hv_synic_enable_regs (0 ); +hv_hyp_synic_enable_regs (0 );/* * Note: we don't need to call hv_stimer_init(0), because the timer
Signature · 1 line
2.43.0
PATCH v7 12/17 Drivers: hv: Functions for setting up and tearing down the paravisor SynIC
In reply to Roman KiselThe confidential VMBus runs with the paravisor SynIC and requires configuring it with the paravisor.
Add the functions for configuring the paravisor SynIC. Update overall SynIC initialization logic to initialize the SynIC if it is present. Finally, break out SynIC interrupt enable/disable code into separate functions so that SynIC interrupts can be enabled or disabled via the paravisor instead of the hypervisor if the paravisor SynIC is present.
--- drivers/hv/hv.c | 138 +++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 126 insertions(+), 12 deletions(-)
drivers/hv/hv.c +126 -12
@@ -278,9 +278,8 @@ void hv_hyp_synic_enable_regs(unsigned int cpu)union hv_synic_simp simp;union hv_synic_siefp siefp;union hv_synic_sint shared_sint; -union hv_synic_scontrol sctrl; -/* Setup the Synic's message page */ +/* Setup the Synic's message page with the hypervisor. */ simp.as_uint64 =hv_get_msr (HV_MSR_SIMP ); simp.simp_enabled =1 ;
@@ -299,7 +298,7 @@ void hv_hyp_synic_enable_regs(unsigned int cpu)hv_set_msr (HV_MSR_SIMP , simp.as_uint64); -/* Setup the Synic's event page */ +/* Setup the Synic's event page with the hypervisor. */ siefp.as_uint64 =hv_get_msr (HV_MSR_SIEFP ); siefp.siefp_enabled =1 ;
@@ -327,6 +326,11 @@ void hv_hyp_synic_enable_regs(unsigned int cpu) shared_sint.masked = false; shared_sint.auto_eoi =hv_recommend_using_aeoi ();hv_set_msr (HV_MSR_SINT0 +VMBUS_MESSAGE_SINT , shared_sint.as_uint64); +} + +static void hv_hyp_synic_enable_interrupts (void ) +{ +union hv_synic_scontrol sctrl;/* Enable the global synic bit */ sctrl.as_uint64 =hv_get_msr (HV_MSR_SCONTROL );
@@ -335,9 +339,59 @@ void hv_hyp_synic_enable_regs(unsigned int cpu)hv_set_msr (HV_MSR_SCONTROL , sctrl.as_uint64); } +static void hv_para_synic_enable_regs (unsigned int cpu) +{ +union hv_synic_simp simp; +union hv_synic_siefp siefp; +struct hv_per_cpu_context *hv_cpu + =per_cpu_ptr (hv_context.cpu_context, cpu); + +/* Setup the Synic's message page with the paravisor. */ + simp.as_uint64 =hv_para_get_synic_register (HV_MSR_SIMP ); + simp.simp_enabled =1 ; + simp.base_simp_gpa =virt_to_phys (hv_cpu->para_synic_message_page) + >>HV_HYP_PAGE_SHIFT ; +hv_para_set_synic_register (HV_MSR_SIMP , simp.as_uint64); + +/* Setup the Synic's event page with the paravisor. */ + siefp.as_uint64 =hv_para_get_synic_register (HV_MSR_SIEFP ); + siefp.siefp_enabled =1 ; + siefp.base_siefp_gpa =virt_to_phys (hv_cpu->para_synic_event_page) + >>HV_HYP_PAGE_SHIFT ; +hv_para_set_synic_register (HV_MSR_SIEFP , siefp.as_uint64); +} + +static void hv_para_synic_enable_interrupts (void ) +{ +union hv_synic_scontrol sctrl; + +/* Enable the global synic bit */ + sctrl.as_uint64 =hv_para_get_synic_register (HV_MSR_SCONTROL ); + sctrl.enable =1 ; +hv_para_set_synic_register (HV_MSR_SCONTROL , sctrl.as_uint64); +} +int hv_synic_init (unsigned int cpu) { +if (vmbus_is_confidential ()) +hv_para_synic_enable_regs (cpu); + +/* +* The SINT is set in hv_hyp_synic_enable_regs() by calling +* hv_set_msr(). hv_set_msr() in turn has special case code for the +* SINT MSRs that write to the hypervisor version of the MSR *and* +* the paravisor version of the MSR (but *without* the proxy bit when +* VMBus is confidential). +* +* Then enable interrupts via the paravisor if VMBus is confidential, +* and otherwise via the hypervisor. +*/ +hv_hyp_synic_enable_regs (cpu); +if (vmbus_is_confidential ()) +hv_para_synic_enable_interrupts (); +else +hv_hyp_synic_enable_interrupts ();hv_stimer_legacy_init (cpu,VMBUS_MESSAGE_SINT );
@@ -351,7 +405,6 @@ void hv_hyp_synic_disable_regs(unsigned int cpu)union hv_synic_sint shared_sint;union hv_synic_simp simp;union hv_synic_siefp siefp; -union hv_synic_scontrol sctrl; shared_sint.as_uint64 =hv_get_msr (HV_MSR_SINT0 +VMBUS_MESSAGE_SINT );
@@ -363,7 +416,7 @@ void hv_hyp_synic_disable_regs(unsigned int cpu) simp.as_uint64 =hv_get_msr (HV_MSR_SIMP );/* -* In Isolation VM, sim and sief pages are allocated by +* In Isolation VM, simp and sief pages are allocated by * paravisor. These pages also will be used by kdump * kernel. So just reset enable bit here and keep page * addresses.
@@ -393,14 +446,42 @@ void hv_hyp_synic_disable_regs(unsigned int cpu) }hv_set_msr (HV_MSR_SIEFP , siefp.as_uint64); +} + +static void hv_hyp_synic_disable_interrupts (void ) +{ +union hv_synic_scontrol sctrl;/* Disable the global synic bit */ sctrl.as_uint64 =hv_get_msr (HV_MSR_SCONTROL ); sctrl.enable =0 ;hv_set_msr (HV_MSR_SCONTROL , sctrl.as_uint64); +} -if (vmbus_irq !=-1 ) -disable_percpu_irq (vmbus_irq); +static void hv_para_synic_disable_regs (unsigned int cpu) +{ +union hv_synic_simp simp; +union hv_synic_siefp siefp; + +/* Disable SynIC's message page in the paravisor. */ + simp.as_uint64 =hv_para_get_synic_register (HV_MSR_SIMP ); + simp.simp_enabled =0 ; +hv_para_set_synic_register (HV_MSR_SIMP , simp.as_uint64); + +/* Disable SynIC's event page in the paravisor. */ + siefp.as_uint64 =hv_para_get_synic_register (HV_MSR_SIEFP ); + siefp.siefp_enabled =0 ; +hv_para_set_synic_register (HV_MSR_SIEFP , siefp.as_uint64); +} + +static void hv_para_synic_disable_interrupts (void ) +{ +union hv_synic_scontrol sctrl; + +/* Disable the global synic bit */ + sctrl.as_uint64 =hv_para_get_synic_register (HV_MSR_SCONTROL ); + sctrl.enable =0 ; +hv_para_set_synic_register (HV_MSR_SCONTROL , sctrl.as_uint64); }#define HV_MAX_TRIES 3
@@ -413,16 +494,18 @@ void hv_hyp_synic_disable_regs(unsigned int cpu)* that the normal interrupt handling mechanism will find and process the channel interrupt * "very soon", and in the process clear the bit. */ -static bool hv_synic_event_pending (void ) +static bool __hv_synic_event_pending (union hv_synic_event_flags *event,int sint) { -struct hv_per_cpu_context *hv_cpu =this_cpu_ptr (hv_context.cpu_context); -union hv_synic_event_flags *event = - (union hv_synic_event_flags *)hv_cpu->hyp_synic_event_page +VMBUS_MESSAGE_SINT ; -unsigned long *recv_int_page = event->flags;/* assumes VMBus version >= VERSION_WIN8 */ +unsigned long *recv_int_page;bool pending;u32 relid;int tries =0 ; +if (!event) +return false; + + event += sint; + recv_int_page = event->flags;/* assumes VMBus version >= VERSION_WIN8 */ retry: pending = false;for_each_set_bit (relid, recv_int_page,HV_EVENT_FLAGS_COUNT ) {
@@ -439,6 +522,17 @@ static bool hv_synic_event_pending(void)return pending; } +static bool hv_synic_event_pending (void ) +{ +struct hv_per_cpu_context *hv_cpu =this_cpu_ptr (hv_context.cpu_context); +union hv_synic_event_flags *hyp_synic_event_page = hv_cpu->hyp_synic_event_page; +union hv_synic_event_flags *para_synic_event_page = hv_cpu->para_synic_event_page; + +return +__hv_synic_event_pending (hyp_synic_event_page,VMBUS_MESSAGE_SINT ) || +__hv_synic_event_pending (para_synic_event_page,VMBUS_MESSAGE_SINT ); +} +static int hv_pick_new_cpu (struct vmbus_channel *channel) {int ret = -EBUSY ;
@@ -531,7 +625,27 @@ int hv_synic_cleanup(unsigned int cpu) always_cleanup:hv_stimer_legacy_cleanup (cpu); +/* +* First, disable the event and message pages +* used for communicating with the host, and then +* disable the host interrupts if VMBus is not +* confidential. +*/ hv_hyp_synic_disable_regs (cpu); +if (!vmbus_is_confidential ()) +hv_hyp_synic_disable_interrupts (); + +/* +* Perform the same steps for the Confidential VMBus. +* The sequencing provides the guarantee that no data +* may be posted for processing before disabling interrupts. +*/ +if (vmbus_is_confidential ()) { +hv_para_synic_disable_regs (cpu); +hv_para_synic_disable_interrupts (); + } +if (vmbus_irq !=-1 ) +disable_percpu_irq (vmbus_irq);return ret; }
Signature · 1 line
2.43.0
PATCH v7 13/17 Drivers: hv: Allocate encrypted buffers when requested
In reply to Roman KiselConfidential VMBus is built around using buffers not shared with the host.
Support allocating encrypted buffers when requested.
--- drivers/hv/channel.c | 49 +++++++++++++++++++++++---------------- drivers/hv/hyperv_vmbus.h | 3 ++- drivers/hv/ring_buffer.c | 5 ++-- 3 files changed, 34 insertions(+), 23 deletions(-)
drivers/hv/channel.c +29 -20
@@ -444,20 +444,23 @@ static int __vmbus_establish_gpadl(struct vmbus_channel *channel,return ret; } -/* -* Set the "decrypted" flag to true for the set_memory_decrypted() -* success case. In the failure case, the encryption state of the -* memory is unknown. Leave "decrypted" as true to ensure the -* memory will be leaked instead of going back on the free list. -*/ - gpadl->decrypted = true; - ret =set_memory_decrypted ((unsigned long )kbuffer, -PFN_UP (size)); -if (ret) { -dev_warn (&channel->device_obj->device, -"Failed to set host visibility for new GPADL %d.\n" , - ret); -return ret; + gpadl->decrypted = !((channel->co_external_memory && type ==HV_GPADL_BUFFER ) || + (channel->co_ring_buffer && type ==HV_GPADL_RING )); +if (gpadl->decrypted) { +/* +* The "decrypted" flag being true assumes that set_memory_decrypted() succeeds. +* But if it fails, the encryption state of the memory is unknown. In that case, +* leave "decrypted" as true to ensure the memory is leaked instead of going back +* on the free list. +*/ + ret =set_memory_decrypted ((unsigned long )kbuffer, +PFN_UP (size)); +if (ret) { +dev_warn (&channel->device_obj->device, +"Failed to set host visibility for new GPADL %d.\n" , + ret); +return ret; + } }init_completion (&msginfo->waitevent);
@@ -545,8 +548,10 @@ static int __vmbus_establish_gpadl(struct vmbus_channel *channel,* left as true so the memory is leaked instead of being * put back on the free list. */ -if (!set_memory_encrypted ((unsigned long )kbuffer,PFN_UP (size))) - gpadl->decrypted = false; +if (gpadl->decrypted) { +if (!set_memory_encrypted ((unsigned long )kbuffer,PFN_UP (size))) + gpadl->decrypted = false; + } }return ret;
@@ -677,12 +682,13 @@ static int __vmbus_open(struct vmbus_channel *newchannel, goto error_clean_ring; err =hv_ringbuffer_init (&newchannel->outbound, - page, send_pages,0 ); + page, send_pages,0 , newchannel->co_ring_buffer);if (err) goto error_free_gpadl; err =hv_ringbuffer_init (&newchannel->inbound, &page[send_pages], - recv_pages, newchannel->max_pkt_size); + recv_pages, newchannel->max_pkt_size, + newchannel->co_ring_buffer);if (err) goto error_free_gpadl;
@@ -863,8 +869,11 @@ int vmbus_teardown_gpadl(struct vmbus_channel *channel, struct vmbus_gpadl *gpadkfree (info); - ret =set_memory_encrypted ((unsigned long )gpadl->buffer, -PFN_UP (gpadl->size)); +if (gpadl->decrypted) + ret =set_memory_encrypted ((unsigned long )gpadl->buffer, +PFN_UP (gpadl->size)); +else + ret =0 ;if (ret)pr_warn ("Fail to set mem host visibility in GPADL teardown %d.\n" , ret);
drivers/hv/hyperv_vmbus.h +2 -1
@@ -201,7 +201,8 @@ extern int hv_synic_cleanup(unsigned int cpu);void hv_ringbuffer_pre_init (struct vmbus_channel *channel);int hv_ringbuffer_init (struct hv_ring_buffer_info *ring_info, -struct page *pages,u32 pagecnt,u32 max_pkt_size); +struct page *pages,u32 pagecnt,u32 max_pkt_size, +bool confidential);void hv_ringbuffer_cleanup (struct hv_ring_buffer_info *ring_info);
drivers/hv/ring_buffer.c +3 -2
@@ -184,7 +184,8 @@ void hv_ringbuffer_pre_init(struct vmbus_channel *channel)/* Initialize the ring buffer. */ int hv_ringbuffer_init (struct hv_ring_buffer_info *ring_info, -struct page *pages,u32 page_cnt,u32 max_pkt_size) +struct page *pages,u32 page_cnt,u32 max_pkt_size, +bool confidential) {struct page **pages_wraparound;int i;
@@ -208,7 +209,7 @@ int hv_ringbuffer_init(struct hv_ring_buffer_info *ring_info, ring_info->ring_buffer = (struct hv_ring_buffer *)vmap (pages_wraparound, page_cnt *2 -1 ,VM_MAP , -pgprot_decrypted (PAGE_KERNEL )); + confidential ?PAGE_KERNEL :pgprot_decrypted (PAGE_KERNEL ));kfree (pages_wraparound);if (!ring_info->ring_buffer)
Signature · 1 line
2.43.0
PATCH v7 14/17 Drivers: hv: Free msginfo when the buffer fails to decrypt
In reply to Roman KiselThe early failure path in __vmbus_establish_gpadl() doesn't deallocate msginfo if the buffer fails to decrypt.
Fix the leak by breaking out the cleanup code into a separate function and calling it where required.
--- drivers/hv/channel.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-)
drivers/hv/channel.c +18 -6
@@ -410,6 +410,21 @@ static int create_gpadl_header(enum hv_gpadl_type type, void *kbuffer,return 0 ; } +static void vmbus_free_channel_msginfo (struct vmbus_channel_msginfo *msginfo) +{ +struct vmbus_channel_msginfo *submsginfo, *tmp; + +if (!msginfo) +return ; + +list_for_each_entry_safe (submsginfo, tmp, &msginfo->submsglist, + msglistentry) { +kfree (submsginfo); + } + +kfree (msginfo); +} +/* * __vmbus_establish_gpadl - Establish a GPADL for a buffer or ringbuffer *
@@ -429,7 +444,7 @@ static int __vmbus_establish_gpadl(struct vmbus_channel *channel,struct vmbus_channel_gpadl_header *gpadlmsg;struct vmbus_channel_gpadl_body *gpadl_body;struct vmbus_channel_msginfo *msginfo =NULL ; -struct vmbus_channel_msginfo *submsginfo, *tmp; +struct vmbus_channel_msginfo *submsginfo;struct list_head *curr;u32 next_gpadl_handle;unsigned long flags;
@@ -459,6 +474,7 @@ static int __vmbus_establish_gpadl(struct vmbus_channel *channel,dev_warn (&channel->device_obj->device,"Failed to set host visibility for new GPADL %d.\n" , ret); +vmbus_free_channel_msginfo (msginfo);return ret; } }
@@ -535,12 +551,8 @@ static int __vmbus_establish_gpadl(struct vmbus_channel *channel,spin_lock_irqsave (&vmbus_connection.channelmsg_lock, flags);list_del (&msginfo->msglistentry);spin_unlock_irqrestore (&vmbus_connection.channelmsg_lock, flags); -list_for_each_entry_safe (submsginfo, tmp, &msginfo->submsglist, - msglistentry) { -kfree (submsginfo); - } -kfree (msginfo); +vmbus_free_channel_msginfo (msginfo);if (ret) {/*
Signature · 1 line
2.43.0
PATCH v7 15/17 Drivers: hv: Support confidential VMBus channels
In reply to Roman KiselTo make use of Confidential VMBus channels, initialize the co_ring_buffers and co_external_memory fields of the channel structure.
Advertise support upon negotiating the version and compute values for those fields and initialize them.
--- drivers/hv/channel_mgmt.c | 19 +++++++++++++++++++ drivers/hv/connection.c | 3 +++ 2 files changed, 22 insertions(+)
drivers/hv/channel_mgmt.c +19 -0
@@ -1022,6 +1022,7 @@ static void vmbus_onoffer(struct vmbus_channel_message_header *hdr)struct vmbus_channel_offer_channel *offer;struct vmbus_channel *oldchannel, *newchannel;size_t offer_sz; +bool co_ring_buffer, co_external_memory; offer = (struct vmbus_channel_offer_channel *)hdr;
@@ -1034,6 +1035,22 @@ static void vmbus_onoffer(struct vmbus_channel_message_header *hdr)return ; } + co_ring_buffer =is_co_ring_buffer (offer); + co_external_memory =is_co_external_memory (offer); +if (!co_ring_buffer && co_external_memory) { +pr_err ("Invalid offer relid=%d: the ring buffer isn't encrypted\n" , + offer->child_relid); +return ; + } +if (co_ring_buffer || co_external_memory) { +if (vmbus_proto_version <VERSION_WIN10_V6_0 || !vmbus_is_confidential ()) { +pr_err ("Invalid offer relid=%d: no support for confidential VMBus\n" , + offer->child_relid); +atomic_dec (&vmbus_connection.offer_in_progress); +return ; + } + } + oldchannel =find_primary_channel_by_offer (offer);if (oldchannel !=NULL ) {
@@ -1112,6 +1129,8 @@ static void vmbus_onoffer(struct vmbus_channel_message_header *hdr)pr_err ("Unable to allocate channel object\n" );return ; } + newchannel->co_ring_buffer = co_ring_buffer; + newchannel->co_external_memory = co_external_memory;vmbus_setup_channel_state (newchannel, offer);
drivers/hv/connection.c +3 -0
@@ -105,6 +105,9 @@ int vmbus_negotiate_version(struct vmbus_channel_msginfo *msginfo, u32 version) vmbus_connection.msg_conn_id =VMBUS_MESSAGE_CONNECTION_ID ; } +if (vmbus_is_confidential () && version >=VERSION_WIN10_V6_0 ) + msg->feature_flags =VMBUS_FEATURE_FLAG_CONFIDENTIAL_CHANNELS ; +/* * shared_gpa_boundary is zero in non-SNP VMs, so it's safe to always * bitwise OR it
Signature · 1 line
2.43.0
PATCH v7 16/17 Drivers: hv: Set the default VMBus version to 6.0
In reply to Roman KiselThe confidential VMBus is supported by the protocol version 6.0 onwards.
Attempt to establish the VMBus 6.0 connection thus enabling the confidential VMBus features when available.
--- drivers/hv/connection.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/hv/connection.c +2 -1
@@ -51,6 +51,7 @@ EXPORT_SYMBOL_GPL(vmbus_proto_version);* Linux guests and are not listed. */ static __u32 vmbus_versions[] = { +VERSION_WIN10_V6_0 ,VERSION_WIN10_V5_3 ,VERSION_WIN10_V5_2 ,VERSION_WIN10_V5_1 ,
@@ -65,7 +66,7 @@ static __u32 vmbus_versions[] = {* Maximal VMBus protocol version guests can negotiate. Useful to cap the * VMBus version for testing and debugging purpose. */ -static uint max_version =VERSION_WIN10_V5_3 ; +static uint max_version =VERSION_WIN10_V6_0 ;module_param (max_version, uint,S_IRUGO ); MODULE_PARM_DESC(max_version,
Signature · 1 line
2.43.0
PATCH v7 17/17 Drivers: hv: Support establishing the confidential VMBus connection
In reply to Roman KiselTo establish the confidential VMBus connection the CoCo VM, the guest first checks on the confidential VMBus availability, and then proceeds to initializing the communication stack.
Implement that in the VMBus driver initialization.
--- drivers/hv/vmbus_drv.c | 168 ++++++++++++++++++++++++++--------------- 1 file changed, 106 insertions(+), 62 deletions(-)
drivers/hv/vmbus_drv.c +106 -62
@@ -1057,12 +1057,9 @@ static void vmbus_onmessage_work(struct work_struct *work)kfree (ctx); } -void vmbus_on_msg_dpc (unsigned long data) +static void __vmbus_on_msg_dpc (void *message_page_addr) { -struct hv_per_cpu_context *hv_cpu = (void *)data; -void *page_addr = hv_cpu->hyp_synic_message_page; -struct hv_message msg_copy, *msg = (struct hv_message *)page_addr + -VMBUS_MESSAGE_SINT ; +struct hv_message msg_copy, *msg;struct vmbus_channel_message_header *hdr;enum vmbus_channel_message_type msgtype;const struct vmbus_channel_message_table_entry *entry;
@@ -1070,6 +1067,10 @@ void vmbus_on_msg_dpc(unsigned long data)__u8 payload_size;u32 message_type; +if (!message_page_addr) +return ; + msg = (struct hv_message *)message_page_addr +VMBUS_MESSAGE_SINT ; +/* * 'enum vmbus_channel_message_type' is supposed to always be 'u32' as * it is being used in 'struct vmbus_channel_message_header' definition
@@ -1195,6 +1196,14 @@ void vmbus_on_msg_dpc(unsigned long data)vmbus_signal_eom (msg, message_type); } +void vmbus_on_msg_dpc (unsigned long data) +{ +struct hv_per_cpu_context *hv_cpu = (void *)data; + +__vmbus_on_msg_dpc (hv_cpu->hyp_synic_message_page); +__vmbus_on_msg_dpc (hv_cpu->para_synic_message_page); +} +#ifdef CONFIG_PM_SLEEP /* * Fake RESCIND_CHANNEL messages to clean up hv_sock channels by force for
@@ -1233,21 +1242,19 @@ static void vmbus_force_channel_rescinded(struct vmbus_channel *channel)#endif /* CONFIG_PM_SLEEP */ /* -* Schedule all channels with events pending +* Schedule all channels with events pending. +* The event page can be directly checked to get the id of +* the channel that has the interrupt pending. */ -static void vmbus_chan_sched (struct hv_per_cpu_context *hv_cpu) +static void vmbus_chan_sched (void *event_page_addr) {unsigned long *recv_int_page;u32 maxbits, relid; +union hv_synic_event_flags *event; -/* -* The event page can be directly checked to get the id of -* the channel that has the interrupt pending. -*/ -void *page_addr = hv_cpu->hyp_synic_event_page; -union hv_synic_event_flags *event - = (union hv_synic_event_flags *)page_addr + -VMBUS_MESSAGE_SINT ; +if (!event_page_addr) +return ; + event = (union hv_synic_event_flags *)event_page_addr +VMBUS_MESSAGE_SINT ; maxbits =HV_EVENT_FLAGS_COUNT ; recv_int_page = event->flags;
@@ -1255,6 +1262,11 @@ static void vmbus_chan_sched(struct hv_per_cpu_context *hv_cpu)if (unlikely (!recv_int_page))return ; +/* +* Suggested-by: Michael Kelley <[email protected]> +* One possible optimization would be to keep track of the largest relID that's in use, +* and only scan up to that relID. +*/ for_each_set_bit (relid, recv_int_page, maxbits) {void (*callback_fn)(void *context);struct vmbus_channel *channel;
@@ -1318,26 +1330,35 @@ static void vmbus_chan_sched(struct hv_per_cpu_context *hv_cpu) } } -static void vmbus_isr (void ) +static void vmbus_message_sched (struct hv_per_cpu_context *hv_cpu,void *message_page_addr) { -struct hv_per_cpu_context *hv_cpu - =this_cpu_ptr (hv_context.cpu_context); -void *page_addr;struct hv_message *msg; -vmbus_chan_sched (hv_cpu); - - page_addr = hv_cpu->hyp_synic_message_page; - msg = (struct hv_message *)page_addr +VMBUS_MESSAGE_SINT ; +if (!message_page_addr) +return ; + msg = (struct hv_message *)message_page_addr +VMBUS_MESSAGE_SINT ;/* Check if there are actual msgs to be processed */ if (msg->header.message_type !=HVMSG_NONE ) {if (msg->header.message_type ==HVMSG_TIMER_EXPIRED ) {hv_stimer0_isr ();vmbus_signal_eom (msg,HVMSG_TIMER_EXPIRED ); - }else + }else {tasklet_schedule (&hv_cpu->msg_dpc); + } } +} + +static void vmbus_isr (void ) +{ +struct hv_per_cpu_context *hv_cpu + =this_cpu_ptr (hv_context.cpu_context); + +vmbus_chan_sched (hv_cpu->hyp_synic_event_page); +vmbus_chan_sched (hv_cpu->para_synic_event_page); + +vmbus_message_sched (hv_cpu, hv_cpu->hyp_synic_message_page); +vmbus_message_sched (hv_cpu, hv_cpu->para_synic_message_page);add_interrupt_randomness (vmbus_interrupt); }
@@ -1355,6 +1376,59 @@ static void vmbus_percpu_work(struct work_struct *work)hv_synic_init (cpu); } +static int vmbus_alloc_synic_and_connect (void ) +{ +int ret, cpu; +struct work_struct __percpu *works; +int hyperv_cpuhp_online; + + ret =hv_synic_alloc (); +if (ret <0 ) + goto err_alloc; + + works = alloc_percpu(struct work_struct); +if (!works) { + ret = -ENOMEM ; + goto err_alloc; + } + +/* +* Initialize the per-cpu interrupt state and stimer state. +* Then connect to the host. +*/ +cpus_read_lock (); +for_each_online_cpu (cpu) { +struct work_struct *work =per_cpu_ptr (works, cpu); + +INIT_WORK (work, vmbus_percpu_work); +schedule_work_on (cpu, work); + } + +for_each_online_cpu (cpu) +flush_work (per_cpu_ptr (works, cpu)); + +/* Register the callbacks for possible CPU online/offline'ing */ + ret =cpuhp_setup_state_nocalls_cpuslocked (CPUHP_AP_ONLINE_DYN ,"hyperv/vmbus:online" , + hv_synic_init, hv_synic_cleanup); +cpus_read_unlock (); +free_percpu (works); +if (ret <0 ) + goto err_alloc; + hyperv_cpuhp_online = ret; + + ret =vmbus_connect (); +if (ret) + goto err_connect; +return 0 ; + +err_connect: +cpuhp_remove_state (hyperv_cpuhp_online); +return -ENODEV ; +err_alloc: +hv_synic_free (); +return -ENOMEM ; +} +/* * vmbus_bus_init -Main vmbus driver initialization routine. *
@@ -1365,8 +1439,7 @@ static void vmbus_percpu_work(struct work_struct *work)*/ static int vmbus_bus_init (void ) { -int ret, cpu; -struct work_struct __percpu *works; +int ret; ret =hv_init ();if (ret !=0 ) {
@@ -1401,41 +1474,15 @@ static int vmbus_bus_init(void) } } - ret =hv_synic_alloc (); -if (ret) - goto err_alloc; - - works = alloc_percpu(struct work_struct); -if (!works) { - ret = -ENOMEM ; - goto err_alloc; - } -/* -* Initialize the per-cpu interrupt state and stimer state. -* Then connect to the host. +* Cache the value as getting it involves a VM exit on x86(_64), and +* doing that on each VP while initializing SynIC's wastes time. */ -cpus_read_lock (); -for_each_online_cpu (cpu) { -struct work_struct *work =per_cpu_ptr (works, cpu); - -INIT_WORK (work, vmbus_percpu_work); -schedule_work_on (cpu, work); - } - -for_each_online_cpu (cpu) -flush_work (per_cpu_ptr (works, cpu)); - -/* Register the callbacks for possible CPU online/offline'ing */ - ret =cpuhp_setup_state_nocalls_cpuslocked (CPUHP_AP_ONLINE_DYN ,"hyperv/vmbus:online" , - hv_synic_init, hv_synic_cleanup); -cpus_read_unlock (); -free_percpu (works); -if (ret <0 ) - goto err_alloc; - hyperv_cpuhp_online = ret; - - ret =vmbus_connect (); + is_confidential = ms_hyperv.confidential_vmbus_available; +if (is_confidential) +pr_info ("Establishing connection to the confidential VMBus\n" ); +hv_para_set_sint_proxy (!is_confidential); + ret =vmbus_alloc_synic_and_connect ();if (ret) goto err_connect;
@@ -1451,9 +1498,6 @@ static int vmbus_bus_init(void)return 0 ; err_connect: -cpuhp_remove_state (hyperv_cpuhp_online); -err_alloc: -hv_synic_free ();if (vmbus_irq ==-1 ) {hv_remove_vmbus_handler (); }else {
Signature · 1 line
2.43.0
On Wed, Oct 08, 2025 at 04:34:02PM -0700, Roman Kisel wrote:
[...]
Quoted 13 lines
Roman Kisel (17):
Documentation: hyperv: Confidential VMBus
Drivers: hv: VMBus protocol version 6.0
arch/x86: mshyperv: Discover Confidential VMBus availability
arch: hyperv: Get/set SynIC synth.registers via paravisorarch/x86: mshyperv: Trap on access for some synthetic MSRs
Drivers: hv: Rename fields for SynIC message and event pages
Drivers: hv: Allocate the paravisor SynIC pages when required
Drivers: hv: Post messages through the confidential VMBus if available
Drivers: hv: remove stale comment
Drivers: hv: Check message and event pages for non-NULL before
iounmap()
Quoted 8 lines
Drivers: hv: Rename the SynIC enable and disable routines
Drivers: hv: Functions for setting up and tearing down the paravisor
SynIC
Drivers: hv: Allocate encrypted buffers when requested
Drivers: hv: Free msginfo when the buffer fails to decrypt
Drivers: hv: Support confidential VMBus channels
Drivers: hv: Set the default VMBus version to 6.0
Drivers: hv: Support establishing the confidential VMBus connection
Applied to hyperv-next. Thanks.
I needed to fix up a few minor things due to changes made by Tianyu's patches. Dexuan, please verify that everything is still OK.
Wei