From nobody Tue Oct 7 03:46:14 2025 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BBA481B87E9; Mon, 14 Jul 2025 22:15:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=13.77.154.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752531349; cv=none; b=txnCbT9lHNaznNogue5k1RkqK2Re0K35W4tjXm7z0BSehxnJD/trRG5zFVdGxaHtoGhHoT3Or2VdnBkQXGUB9kzkqVWAbwXv9riQOOR8rjg3wyl+Iw2o8KWXCjn0N/sKqXQqmvXtg2wXXDMDY3pmP5z5FCe/4B0Fin839ot7DQg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752531349; c=relaxed/simple; bh=OyGH4spMrhcywIaQjsDzr0V2fG7hh6BSdDn/2ukWmsQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MayNQHNCCTpInvDow+1gqXoUUkvuffGo6qp9eN1VOmPwcgLNzyzhX/B5jIzyvCgN3TXJVIXsYCfG93KYFfqx12qEj2qxOLYAGi5JlZgpMRf0yZebUAQpOufr92WNdUl/B/GzPiz2eHjC0h+aTtemejNpWMerTLaOJdNouNukiko= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com; spf=pass smtp.mailfrom=linux.microsoft.com; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b=QYl2kgST; arc=none smtp.client-ip=13.77.154.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b="QYl2kgST" Received: from romank-3650.corp.microsoft.com (unknown [131.107.160.188]) by linux.microsoft.com (Postfix) with ESMTPSA id 3A8E22016578; Mon, 14 Jul 2025 15:15:47 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 3A8E22016578 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1752531347; bh=tF4KjrMlXUSFdjACqUuSOArtP8vWogRQxSVvgwAGV6E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QYl2kgSTQwafee9SG6N50zHSHIWK7KyWQexAVJDjT/Ug8JspfrHPxvxIxvor3WYmb 7Y46PM4nVYwQ1D8/d0IOedp8hnIALmqli0rnZSyOsJxrjaPfxe/eoHQHKvLIoVU4+V ZRz4FXuvu67wfKh/HrohS7LO4ln71dM9ov2ZTOsg= From: Roman Kisel To: alok.a.tiwari@oracle.com, arnd@arndb.de, bp@alien8.de, corbet@lwn.net, dave.hansen@linux.intel.com, decui@microsoft.com, haiyangz@microsoft.com, hpa@zytor.com, kys@microsoft.com, mhklinux@outlook.com, mingo@redhat.com, rdunlap@infradead.org, tglx@linutronix.de, Tianyu.Lan@microsoft.com, wei.liu@kernel.org, linux-arch@vger.kernel.org, linux-coco@lists.linux.dev, linux-doc@vger.kernel.org, linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org, x86@kernel.org Cc: apais@microsoft.com, benhill@microsoft.com, bperkins@microsoft.com, sunilmut@microsoft.com Subject: [PATCH hyperv-next v4 01/16] Documentation: hyperv: Confidential VMBus Date: Mon, 14 Jul 2025 15:15:30 -0700 Message-ID: <20250714221545.5615-2-romank@linux.microsoft.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250714221545.5615-1-romank@linux.microsoft.com> References: <20250714221545.5615-1-romank@linux.microsoft.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Define what the confidential VMBus is and describe what advantages it offers on the capable hardware. Signed-off-by: Roman Kisel Reviewed-by: Alok Tiwari --- Documentation/virt/hyperv/coco.rst | 140 ++++++++++++++++++++++++++++- 1 file changed, 139 insertions(+), 1 deletion(-) diff --git a/Documentation/virt/hyperv/coco.rst b/Documentation/virt/hyperv= /coco.rst index c15d6fe34b4e..e8515acfe306 100644 --- a/Documentation/virt/hyperv/coco.rst +++ b/Documentation/virt/hyperv/coco.rst @@ -178,7 +178,7 @@ These Hyper-V and VMBus memory pages are marked as decr= ypted: =20 * VMBus monitor pages =20 -* Synthetic interrupt controller (synic) related pages (unless supplied by +* Synthetic interrupt controller (SynIC) related pages (unless supplied by the paravisor) =20 * Per-cpu hypercall input and output pages (unless running with a paraviso= r) @@ -232,6 +232,144 @@ 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. =20 +Confidential VMBus +------------------ +The confidential VMBus enables the confidential guest not to interact with +the untrusted host partition and the untrusted hypervisor. Instead, the gu= est +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 secu= rity +processor to ensure trusted and confidential computing. + +Confidential VMBus provides a secure communication channel between the gue= st +and the paravisor, ensuring that sensitive data is protected from hypervis= or- +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 won't ever leave the VM when a device is attached to VTL2, and the +device supports encrypted memory. Therefore, neither the host partition no= r the +hypervisor can access the data being processed at all. 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 sup= port +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 bac= king +pages aren't mapped into the host partition through SLAT. While not imposs= ible, +it becomes much more difficult for the host partition to exfiltrate the da= ta +than it would be with a conventional VMBus connection where the host parti= tion +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 -----+ + | | | | | | + | | | | | | + | | | =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= | + | | | | | | + | | | | | | + | | | | | | + +----- C -------+ +-----------------+ +------- S ------+ + || || + || || + +------||------------------ VMBus --------------------------||------+ + | Interrupts, MMIO | + +-------------------------------------------------------------------+ + +and the Confidential VMBus connection:: + + +---- GUEST --------------- VTL0 ------+ +-- DEVICE --+ + | | | | + | +- PARAVISOR --------- VTL2 -----+ | | | + | | +-- VMBus Relay ------+ =3D=3D=3D=3D+=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D | + | | | 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. It does so by +first trying to establish a Confidential VMBus connection with the paravis= or +usingstandard mechanisms where the memory remains encrypted. If this succe= eds, +then the guest can proceed to use Confidential VMBus. If it fails, then the +guest must fallback to establishing a non-Confidential VMBus connection wi= th +the Hyper-V host. + +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-pa= ssing +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 o= ffer +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 setti= ngs +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 ch= annel +is offered by the paravisor with confidential VMBus, the ring buffer can a= lways +be encrypted since it's strictly for communication between the VTL2 paravi= sor +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, ther= e 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 bu= ffers +and DMA transfers, the guest must interact with two SynICs -- the one prov= ided +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 SynI= C, +but the guest must check for messages and for channel interrupts on both S= ynICs. + +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 spe= cial +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 hyperv= isor +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 --=20 2.43.0 From nobody Tue Oct 7 03:46:14 2025 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0C5D823B612; Mon, 14 Jul 2025 22:15:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=13.77.154.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752531349; cv=none; b=UQ1NemTNyCTuPLkaYngPeVD4fVrutDKHtsLdOdzFSoJ6PZBY0Jy8ullz1vZ7tIbPcdFyVVbT2xZCoumf0rWNsBFWjP13BVkx00PZ/0Ssja5cWwJEhQcXkemvg+ngvAkK+rF2FNkHs4j7uX+gRXZ8SU/aLtldBlyXVr11jOBaPXU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752531349; c=relaxed/simple; bh=GTK18SURi9MA5ksujzeL6uPXXJfV//F86xAT4KJw1w0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sUPwRVgjyvqCAmvkwMXEtdjUit/snv4mOjsuRRbyn1x9Dwt2ULWp5qH43F832qTX/CRPqX1PF/itCw+ehskylFiXm87tBE0lZ6Fo0xyU7AcKPmcdCnCKIJ8xw8r1l8MRc8GUEvPvkQzxYYfNxNZRzfknMJZCnwag53H5+ISaAD0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com; spf=pass smtp.mailfrom=linux.microsoft.com; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b=AsyujSpT; arc=none smtp.client-ip=13.77.154.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b="AsyujSpT" Received: from romank-3650.corp.microsoft.com (unknown [131.107.160.188]) by linux.microsoft.com (Postfix) with ESMTPSA id 7BBD2201657B; Mon, 14 Jul 2025 15:15:47 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 7BBD2201657B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1752531347; bh=VgkiizYMYF32uIO8lHFpO+dEsSl9O3ZuABsDjADOcUg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AsyujSpT3otIpHQWCWxTkSJrcOjjmtrRM6gLCswK4LoeaZxTryv7wwmW9jDUJhZP4 P4BsB3c63tmyxaRv2id2SjkR6JU0o+vSB0qroU2zE3l4HtxsCB55aN6V7vlNDboZ2y EYlYgdkzaZfhDTivIxgl53vTOjO6bZj55e9tn5uA= From: Roman Kisel To: alok.a.tiwari@oracle.com, arnd@arndb.de, bp@alien8.de, corbet@lwn.net, dave.hansen@linux.intel.com, decui@microsoft.com, haiyangz@microsoft.com, hpa@zytor.com, kys@microsoft.com, mhklinux@outlook.com, mingo@redhat.com, rdunlap@infradead.org, tglx@linutronix.de, Tianyu.Lan@microsoft.com, wei.liu@kernel.org, linux-arch@vger.kernel.org, linux-coco@lists.linux.dev, linux-doc@vger.kernel.org, linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org, x86@kernel.org Cc: apais@microsoft.com, benhill@microsoft.com, bperkins@microsoft.com, sunilmut@microsoft.com Subject: [PATCH hyperv-next v4 02/16] drivers: hv: VMBus protocol version 6.0 Date: Mon, 14 Jul 2025 15:15:31 -0700 Message-ID: <20250714221545.5615-3-romank@linux.microsoft.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250714221545.5615-1-romank@linux.microsoft.com> References: <20250714221545.5615-1-romank@linux.microsoft.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The confidential VMBus is supported starting from the protocol version 6.0 onwards. Update the relevant definitions, and provide a function that returns whether VMBus is confidential or not. No functional changes. Signed-off-by: Roman Kisel Reviewed-by: Alok Tiwari --- drivers/hv/vmbus_drv.c | 12 ++++++ include/asm-generic/mshyperv.h | 1 + include/linux/hyperv.h | 69 ++++++++++++++++++++++++---------- 3 files changed, 63 insertions(+), 19 deletions(-) diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c index 33b524b4eb5e..698c86c4ef03 100644 --- a/drivers/hv/vmbus_drv.c +++ b/drivers/hv/vmbus_drv.c @@ -56,6 +56,18 @@ static long __percpu *vmbus_evt; int vmbus_irq; int vmbus_interrupt; =20 +/* + * 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. diff --git a/include/asm-generic/mshyperv.h b/include/asm-generic/mshyperv.h index a729b77983fa..9722934a8332 100644 --- a/include/asm-generic/mshyperv.h +++ b/include/asm-generic/mshyperv.h @@ -373,6 +373,7 @@ static inline int hv_call_create_vp(int node, u64 parti= tion_id, u32 vp_index, u3 return -EOPNOTSUPP; } #endif /* CONFIG_MSHV_ROOT */ +bool vmbus_is_confidential(void); =20 #if IS_ENABLED(CONFIG_HYPERV_VTL_MODE) u8 __init get_vtl(void); diff --git a/include/linux/hyperv.h b/include/linux/hyperv.h index a59c5c3e95fb..a1820fabbfc0 100644 --- a/include/linux/hyperv.h +++ b/include/linux/hyperv.h @@ -265,16 +265,18 @@ static inline u32 hv_get_avail_to_write_percent( * Linux kernel. */ =20 -#define VERSION_WS2008 ((0 << 16) | (13)) -#define VERSION_WIN7 ((1 << 16) | (1)) -#define VERSION_WIN8 ((2 << 16) | (4)) -#define VERSION_WIN8_1 ((3 << 16) | (0)) -#define VERSION_WIN10 ((4 << 16) | (0)) -#define VERSION_WIN10_V4_1 ((4 << 16) | (1)) -#define VERSION_WIN10_V5 ((5 << 16) | (0)) -#define VERSION_WIN10_V5_1 ((5 << 16) | (1)) -#define VERSION_WIN10_V5_2 ((5 << 16) | (2)) -#define VERSION_WIN10_V5_3 ((5 << 16) | (3)) +#define VMBUS_MAKE_VERSION(MAJ, MIN) ((((u32)MAJ) << 16) | (MIN)) +#define VERSION_WS2008 VMBUS_MAKE_VERSION(0, 13) +#define VERSION_WIN7 VMBUS_MAKE_VERSION(1, 1) +#define VERSION_WIN8 VMBUS_MAKE_VERSION(2, 4) +#define VERSION_WIN8_1 VMBUS_MAKE_VERSION(3, 0) +#define VERSION_WIN10 VMBUS_MAKE_VERSION(4, 0) +#define VERSION_WIN10_V4_1 VMBUS_MAKE_VERSION(4, 1) +#define VERSION_WIN10_V5 VMBUS_MAKE_VERSION(5, 0) +#define VERSION_WIN10_V5_1 VMBUS_MAKE_VERSION(5, 1) +#define VERSION_WIN10_V5_2 VMBUS_MAKE_VERSION(5, 2) +#define VERSION_WIN10_V5_3 VMBUS_MAKE_VERSION(5, 3) +#define VERSION_WIN10_V6_0 VMBUS_MAKE_VERSION(6, 0) =20 /* Make maximum size of pipe payload of 16K */ #define MAX_PIPE_DATA_PAYLOAD (sizeof(u8) * 16384) @@ -335,14 +337,22 @@ struct vmbus_channel_offer { } __packed; =20 /* Server Flags */ -#define VMBUS_CHANNEL_ENUMERATE_DEVICE_INTERFACE 1 -#define VMBUS_CHANNEL_SERVER_SUPPORTS_TRANSFER_PAGES 2 -#define VMBUS_CHANNEL_SERVER_SUPPORTS_GPADLS 4 -#define VMBUS_CHANNEL_NAMED_PIPE_MODE 0x10 -#define VMBUS_CHANNEL_LOOPBACK_OFFER 0x100 -#define VMBUS_CHANNEL_PARENT_OFFER 0x200 -#define VMBUS_CHANNEL_REQUEST_MONITORED_NOTIFICATION 0x400 -#define VMBUS_CHANNEL_TLNPI_PROVIDER_OFFER 0x2000 +#define VMBUS_CHANNEL_ENUMERATE_DEVICE_INTERFACE 0x0001 +/* + * This flag indicates that the channel is offered by the paravisor, and m= ust + * use encrypted memory for the channel ring buffer. + */ +#define VMBUS_CHANNEL_CONFIDENTIAL_RING_BUFFER 0x0002 +/* + * This flag indicates that the channel is offered by the paravisor, and m= ust + * use encrypted memory for GPA direct packets and additional GPADLs. + */ +#define VMBUS_CHANNEL_CONFIDENTIAL_EXTERNAL_MEMORY 0x0004 +#define VMBUS_CHANNEL_NAMED_PIPE_MODE 0x0010 +#define VMBUS_CHANNEL_LOOPBACK_OFFER 0x0100 +#define VMBUS_CHANNEL_PARENT_OFFER 0x0200 +#define VMBUS_CHANNEL_REQUEST_MONITORED_NOTIFICATION 0x0400 +#define VMBUS_CHANNEL_TLNPI_PROVIDER_OFFER 0x2000 =20 struct vmpacket_descriptor { u16 type; @@ -621,6 +631,12 @@ struct vmbus_channel_relid_released { u32 child_relid; } __packed; =20 +/* + * Used by the paravisor only, means that the encrypted ring buffers and + * the encrypted external memory are supported + */ +#define VMBUS_FEATURE_FLAG_CONFIDENTIAL_CHANNELS 0x10 + struct vmbus_channel_initiate_contact { struct vmbus_channel_message_header header; u32 vmbus_version_requested; @@ -630,7 +646,8 @@ struct vmbus_channel_initiate_contact { struct { u8 msg_sint; u8 msg_vtl; - u8 reserved[6]; + u8 reserved[2]; + u32 feature_flags; /* VMBus version 6.0 */ }; }; u64 monitor_page1; @@ -1008,6 +1025,10 @@ struct vmbus_channel { =20 /* boolean to control visibility of sysfs for ring buffer */ bool ring_sysfs_visible; + /* The ring buffer is encrypted */ + bool co_ring_buffer; + /* The external memory is encrypted */ + bool co_external_memory; }; =20 #define lock_requestor(channel, flags) \ @@ -1032,6 +1053,16 @@ u64 vmbus_request_addr_match(struct vmbus_channel *c= hannel, u64 trans_id, u64 rqst_addr); u64 vmbus_request_addr(struct vmbus_channel *channel, u64 trans_id); =20 +static inline bool is_co_ring_buffer(const struct vmbus_channel_offer_chan= nel *o) +{ + return !!(o->offer.chn_flags & VMBUS_CHANNEL_CONFIDENTIAL_RING_BUFFER); +} + +static inline bool is_co_external_memory(const struct vmbus_channel_offer_= channel *o) +{ + return !!(o->offer.chn_flags & VMBUS_CHANNEL_CONFIDENTIAL_EXTERNAL_MEMORY= ); +} + static inline bool is_hvsock_offer(const struct vmbus_channel_offer_channe= l *o) { return !!(o->offer.chn_flags & VMBUS_CHANNEL_TLNPI_PROVIDER_OFFER); --=20 2.43.0 From nobody Tue Oct 7 03:46:14 2025 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6073D2417F2; Mon, 14 Jul 2025 22:15:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=13.77.154.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752531350; cv=none; b=gGmcumruUSVYT0hDca1rrbM6+q/DPW/QhcXF0do7B/CPk1hcM7aRnJoesyIklN5iVRrdXeX2QUVMpMIUX0GK/HF35DKZIJv9Hh9VmfIqQZLaA37GlWs0nKE/CyYNeMc7yJbnGAQ5mLaX+UBmScE4zx4/6Us9Y/qiYYPkE9OzfiE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752531350; c=relaxed/simple; bh=iaLzwCzp0IBa5pLtIbdZA0HxXWmyfYsrxH1UgdPLj6c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FBnAleYi+Lrzk1vmXPH2AGU/kwKkMYlBu1Cfw5lEtGqdl6FGxTdmbOKltV/jPGILdEMRCIZUFHw7XBmFGHoweGqxZ2pnxjDyUgME6uhV+/iSXbZAMmpyBS6tIAuXq+cb4glDMaYJj1gpwJ34z2CdK4rAX6nmMam/6vzOsTAyOjQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com; spf=pass smtp.mailfrom=linux.microsoft.com; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b=MQMLQOas; arc=none smtp.client-ip=13.77.154.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b="MQMLQOas" Received: from romank-3650.corp.microsoft.com (unknown [131.107.160.188]) by linux.microsoft.com (Postfix) with ESMTPSA id BD5FA201657D; Mon, 14 Jul 2025 15:15:47 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com BD5FA201657D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1752531347; bh=GZ9q8PABxSs18Zr3hF+BwFDwqPPPErZZn+AsTkCq4VM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MQMLQOasilfc5p+57UYvb/o65rCe8PyftaAglpZ5vEVxW+RpLBF/MrhzxvaN7DiAf 9pkEnIAdc1NgSLEKTHzGtN29K4tW8WeaDgd0EAPUfRPZDQFzY7rWjZqfP5jcKwmEUn NkWf1qo9U1UPIajpUyW1IScdabpMJM8YEdsPSFwA= From: Roman Kisel To: alok.a.tiwari@oracle.com, arnd@arndb.de, bp@alien8.de, corbet@lwn.net, dave.hansen@linux.intel.com, decui@microsoft.com, haiyangz@microsoft.com, hpa@zytor.com, kys@microsoft.com, mhklinux@outlook.com, mingo@redhat.com, rdunlap@infradead.org, tglx@linutronix.de, Tianyu.Lan@microsoft.com, wei.liu@kernel.org, linux-arch@vger.kernel.org, linux-coco@lists.linux.dev, linux-doc@vger.kernel.org, linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org, x86@kernel.org Cc: apais@microsoft.com, benhill@microsoft.com, bperkins@microsoft.com, sunilmut@microsoft.com Subject: [PATCH hyperv-next v4 03/16] arch: hyperv: Get/set SynIC synth.registers via paravisor Date: Mon, 14 Jul 2025 15:15:32 -0700 Message-ID: <20250714221545.5615-4-romank@linux.microsoft.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250714221545.5615-1-romank@linux.microsoft.com> References: <20250714221545.5615-1-romank@linux.microsoft.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The 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. But in some Confidential VMBus cases, the guest wants to talk only with the paravisor. To accomplish this, provide new functions for accessing SynICs that always do direct accesses (i.e., not via TDX or SNP GHCB), which will go to the paravisor. The mirroring of the existing "set" function is also not needed. These functions should be used only in the specific Confidential VMBus cases that require them. Provide functions that allow manipulating the SynIC registers through the paravisor. Signed-off-by: Roman Kisel Reviewed-by: Alok Tiwari --- arch/x86/kernel/cpu/mshyperv.c | 39 ++++++++++++++++++ drivers/hv/hv_common.c | 13 ++++++ include/asm-generic/mshyperv.h | 75 ++++++++++++++++++---------------- 3 files changed, 92 insertions(+), 35 deletions(-) diff --git a/arch/x86/kernel/cpu/mshyperv.c b/arch/x86/kernel/cpu/mshyperv.c index c78f860419d6..07c60231d0d8 100644 --- a/arch/x86/kernel/cpu/mshyperv.c +++ b/arch/x86/kernel/cpu/mshyperv.c @@ -90,6 +90,45 @@ void hv_set_non_nested_msr(unsigned int reg, u64 value) } EXPORT_SYMBOL_GPL(hv_set_non_nested_msr); =20 +/* + * Attempt to get the SynIC register value from the paravisor. + * + * Not all paravisors support reading SynIC registers, so this function + * may fail. The register for the SynIC of the running CPU is accessed. + * + * Writes the SynIC register value into the memory pointed by val, + * and ~0ULL is on failure. + * + * Returns -ENODEV if the MSR is not a SynIC register, or another error + * code if getting the MSR fails (meaning the paravisor doesn't support + * relaying VMBus communucations). + */ +int hv_para_get_synic_register(unsigned int reg, u64 *val) +{ + if (!hv_is_synic_msr(reg)) + return -ENODEV; + return native_read_msr_safe(reg, val); +} + +/* + * Attempt to set the SynIC register value with the paravisor. + * + * Not all paravisors support setting SynIC registers, so this function + * may fail. The register for the SynIC of the running CPU is accessed. + * + * Sets the register to the value supplied. + * + * Returns: -ENODEV if the MSR is not a SynIC register, or another error + * code if writing to the MSR fails (meaning the paravisor doesn't support + * relaying VMBus communucations). + */ +int hv_para_set_synic_register(unsigned int reg, u64 val) +{ + if (!hv_is_synic_msr(reg)) + return -ENODEV; + return native_write_msr_safe(reg, val); +} + u64 hv_get_msr(unsigned int reg) { if (hv_nested) diff --git a/drivers/hv/hv_common.c b/drivers/hv/hv_common.c index 49898d10faff..a179ea482cb1 100644 --- a/drivers/hv/hv_common.c +++ b/drivers/hv/hv_common.c @@ -716,6 +716,19 @@ u64 __weak hv_tdx_hypercall(u64 control, u64 param1, u= 64 param2) } EXPORT_SYMBOL_GPL(hv_tdx_hypercall); =20 +int __weak hv_para_get_synic_register(unsigned int reg, u64 *val) +{ + *val =3D ~0ULL; + return -ENODEV; +} +EXPORT_SYMBOL_GPL(hv_para_get_synic_register); + +int __weak hv_para_set_synic_register(unsigned int reg, u64 val) +{ + return -ENODEV; +} +EXPORT_SYMBOL_GPL(hv_para_set_synic_register); + void hv_identify_partition_type(void) { /* Assume guest role */ diff --git a/include/asm-generic/mshyperv.h b/include/asm-generic/mshyperv.h index 9722934a8332..9447558f425b 100644 --- a/include/asm-generic/mshyperv.h +++ b/include/asm-generic/mshyperv.h @@ -162,41 +162,6 @@ static inline u64 hv_generate_guest_id(u64 kernel_vers= ion) return guest_id; } =20 -/* Free the message slot and signal end-of-message if required */ -static inline void vmbus_signal_eom(struct hv_message *msg, u32 old_msg_ty= pe) -{ - /* - * On crash we're reading some other CPU's message page and we need - * to be careful: this other CPU may already had cleared the header - * and the host may already had delivered some other message there. - * In case we blindly write msg->header.message_type we're going - * to lose it. We can still lose a message of the same type but - * we count on the fact that there can only be one - * CHANNELMSG_UNLOAD_RESPONSE and we don't care about other messages - * on crash. - */ - if (cmpxchg(&msg->header.message_type, old_msg_type, - HVMSG_NONE) !=3D old_msg_type) - return; - - /* - * The cmxchg() above does an implicit memory barrier to - * ensure the write to MessageType (ie set to - * HVMSG_NONE) happens before we read the - * MessagePending and EOMing. Otherwise, the EOMing - * will not deliver any more messages since there is - * no empty slot - */ - if (msg->header.message_flags.msg_pending) { - /* - * This will cause message queue rescan to - * possibly deliver another msg from the - * hypervisor - */ - hv_set_msr(HV_MSR_EOM, 0); - } -} - int hv_get_hypervisor_version(union hv_hypervisor_version_info *info); =20 void hv_setup_vmbus_handler(void (*handler)(void)); @@ -333,6 +298,8 @@ bool hv_is_isolation_supported(void); bool hv_isolation_type_snp(void); u64 hv_ghcb_hypercall(u64 control, void *input, void *output, u32 input_si= ze); u64 hv_tdx_hypercall(u64 control, u64 param1, u64 param2); +int hv_para_get_synic_register(unsigned int reg, u64 *val); +int hv_para_set_synic_register(unsigned int reg, u64 val); void hyperv_cleanup(void); bool hv_query_ext_cap(u64 cap_query); void hv_setup_dma_ops(struct device *dev, bool coherent); @@ -375,6 +342,44 @@ static inline int hv_call_create_vp(int node, u64 part= ition_id, u32 vp_index, u3 #endif /* CONFIG_MSHV_ROOT */ bool vmbus_is_confidential(void); =20 +/* Free the message slot and signal end-of-message if required */ +static inline void vmbus_signal_eom(struct hv_message *msg, u32 old_msg_ty= pe) +{ + /* + * On crash we're reading some other CPU's message page and we need + * to be careful: this other CPU may already had cleared the header + * and the host may already had delivered some other message there. + * In case we blindly write msg->header.message_type we're going + * to lose it. We can still lose a message of the same type but + * we count on the fact that there can only be one + * CHANNELMSG_UNLOAD_RESPONSE and we don't care about other messages + * on crash. + */ + if (cmpxchg(&msg->header.message_type, old_msg_type, + HVMSG_NONE) !=3D old_msg_type) + return; + + /* + * The cmxchg() above does an implicit memory barrier to + * ensure the write to MessageType (ie set to + * HVMSG_NONE) happens before we read the + * MessagePending and EOMing. Otherwise, the EOMing + * will not deliver any more messages since there is + * no empty slot + */ + if (msg->header.message_flags.msg_pending) { + /* + * This will cause message queue rescan to + * possibly deliver another msg from the + * hypervisor + */ + if (vmbus_is_confidential()) + hv_para_set_synic_register(HV_MSR_EOM, 0); + else + hv_set_msr(HV_MSR_EOM, 0); + } +} + #if IS_ENABLED(CONFIG_HYPERV_VTL_MODE) u8 __init get_vtl(void); #else --=20 2.43.0 From nobody Tue Oct 7 03:46:14 2025 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 92757269CE8; Mon, 14 Jul 2025 22:15:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=13.77.154.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752531350; cv=none; b=D/iXQtFlIf+jScUHsmxv1K+G48c4E8XEm2KBSbnBDUhkz++OcYAvulXiFBj79KfZuC0pcWYBxZJm85Ix5kVuUzwq6esteYVuREIhjcCCiYdgA102PuVhiISAAwkmxPnpEmIBGuhF7QdRQuegYP8/W6bXcCGwoEKbxJYACJE2gAs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752531350; c=relaxed/simple; bh=vpFbeaUJfpR1IiORx7GUhHCnaglF4Old7yjW4KUTkcc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rm6TtJQesvIb22mmijBTLJWhtMzPwhj+yhdDjtM5VuBM0pemQ7e2QtjLqt5624BRmqcGFeF0Ke+tvYexfSwr8ThiGTI7crz45ofzDm8fNnOaYCP6TOznoybHEq6fmn/oS7Ug0kx0RgunNuIC0F9iM+sQn10IDJ3GVo4QSszQ6A4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com; spf=pass smtp.mailfrom=linux.microsoft.com; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b=g03Sv0/3; arc=none smtp.client-ip=13.77.154.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b="g03Sv0/3" Received: from romank-3650.corp.microsoft.com (unknown [131.107.160.188]) by linux.microsoft.com (Postfix) with ESMTPSA id 0BF332016580; Mon, 14 Jul 2025 15:15:48 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 0BF332016580 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1752531348; bh=Dd110x/i0AygnNthp2uprww/BsLAD70bjtAflO6nwyg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=g03Sv0/3uqPRINoVW/B+4iS9ql7YAbhiAfO8+BHedN3Z2EovnWsc9kkoonlwZn/V7 6IClbgjd8NVhU+lXngdUbVovF+VuHu8oBW7gb0yVvCcgJk8GqL9NeQeZox59lrqCFa eXTlzeCxOYPQtwqGnMJjtYqMsWqO0PnsSsSiMT4k= From: Roman Kisel To: alok.a.tiwari@oracle.com, arnd@arndb.de, bp@alien8.de, corbet@lwn.net, dave.hansen@linux.intel.com, decui@microsoft.com, haiyangz@microsoft.com, hpa@zytor.com, kys@microsoft.com, mhklinux@outlook.com, mingo@redhat.com, rdunlap@infradead.org, tglx@linutronix.de, Tianyu.Lan@microsoft.com, wei.liu@kernel.org, linux-arch@vger.kernel.org, linux-coco@lists.linux.dev, linux-doc@vger.kernel.org, linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org, x86@kernel.org Cc: apais@microsoft.com, benhill@microsoft.com, bperkins@microsoft.com, sunilmut@microsoft.com Subject: [PATCH hyperv-next v4 04/16] arch/x86: mshyperv: Trap on access for some synthetic MSRs Date: Mon, 14 Jul 2025 15:15:33 -0700 Message-ID: <20250714221545.5615-5-romank@linux.microsoft.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250714221545.5615-1-romank@linux.microsoft.com> References: <20250714221545.5615-1-romank@linux.microsoft.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" hv_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. Update the hv_set_non_nested_msr() function as well as vmbus_signal_eom() to trap on access for some synthetic MSRs. Signed-off-by: Roman Kisel Reviewed-by: Alok Tiwari Reviewed-by: Tianyu Lan --- arch/x86/kernel/cpu/mshyperv.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/arch/x86/kernel/cpu/mshyperv.c b/arch/x86/kernel/cpu/mshyperv.c index 07c60231d0d8..6c5a0a779c02 100644 --- a/arch/x86/kernel/cpu/mshyperv.c +++ b/arch/x86/kernel/cpu/mshyperv.c @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -79,13 +80,21 @@ 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); =20 - /* Write proxy bit via wrmsl instruction */ - if (hv_is_sint_msr(reg)) - wrmsrq(reg, value | 1 << 20); + if (hv_is_sint_msr(reg)) { + /* + * Write proxy bit in the case of non-confidential VMBus. + * Using wrmsrq instruction so the following goes to the paravisor. + */ + u32 proxy =3D vmbus_is_confidential() ? 0 : 1; + + value |=3D (proxy << 20); + native_wrmsrq(reg, value); + } } else { - wrmsrq(reg, value); + native_wrmsrq(reg, value); } } EXPORT_SYMBOL_GPL(hv_set_non_nested_msr); --=20 2.43.0 From nobody Tue Oct 7 03:46:14 2025 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 929CD277029; Mon, 14 Jul 2025 22:15:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=13.77.154.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752531353; cv=none; b=Czm5ymxGZjENBfs7ar3TRO+L4gg2VC6XtLp8D6wTe//zfBMRc0X+n6DsWTDyr4gx2AqZ9MLfCCcaRLaAQOEiYaEvNvGCvFJ59iaHDEoI/Nk84kLHUtPww+vXEm6vUnDBDhhuUg682pgYS5aomPW4PisgUu5gHmA0cmfzX903EB8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752531353; c=relaxed/simple; bh=KJTQgZwpPvYZEx8JPD3q+E5lRuv+nDDWTmoST71GIV4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MrNJk9sTnLspl7JuMSMRyXg7CPfSvon10hEy8bPzBundRcK93DRkEJlairrzFRrbnMKdvQEtz/5PxOo/mXSRw+h9nYUw+ZpqrgTO6y8z85MwXtUbTejiyOa6UoUvU5tlYCgxcu2CLIuCCKEttKwa9C7LQQl1z7swEEiNP9a9Vqc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com; spf=pass smtp.mailfrom=linux.microsoft.com; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b=NLuwLZMp; arc=none smtp.client-ip=13.77.154.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b="NLuwLZMp" Received: from romank-3650.corp.microsoft.com (unknown [131.107.160.188]) by linux.microsoft.com (Postfix) with ESMTPSA id 4E558201658A; Mon, 14 Jul 2025 15:15:48 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 4E558201658A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1752531348; bh=cI2dclVKrvjlHK4ae+5jKjlW35KoLlV51NoVD9CTTKE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NLuwLZMpbIppKb/J/znHqcrAYua5eZKnoqeXzCP74XoeCjFIDCDX+1jxTRYn/X81a /cI5v0k/gWEtwAB5HXujsNxKPHIBDt5IhvpBiXg/SiRsrdc0Q6AB9SCl/5ZFfhdGLw COeizMaIi2fiPZrHnumqW4Q3l8Q/RaK488AvEhCc= From: Roman Kisel To: alok.a.tiwari@oracle.com, arnd@arndb.de, bp@alien8.de, corbet@lwn.net, dave.hansen@linux.intel.com, decui@microsoft.com, haiyangz@microsoft.com, hpa@zytor.com, kys@microsoft.com, mhklinux@outlook.com, mingo@redhat.com, rdunlap@infradead.org, tglx@linutronix.de, Tianyu.Lan@microsoft.com, wei.liu@kernel.org, linux-arch@vger.kernel.org, linux-coco@lists.linux.dev, linux-doc@vger.kernel.org, linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org, x86@kernel.org Cc: apais@microsoft.com, benhill@microsoft.com, bperkins@microsoft.com, sunilmut@microsoft.com Subject: [PATCH hyperv-next v4 05/16] Drivers: hv: Rename fields for SynIC message and event pages Date: Mon, 14 Jul 2025 15:15:34 -0700 Message-ID: <20250714221545.5615-6-romank@linux.microsoft.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250714221545.5615-1-romank@linux.microsoft.com> References: <20250714221545.5615-1-romank@linux.microsoft.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Confidential 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. Signed-off-by: Roman Kisel Reviewed-by: Tianyu Lan --- 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(-) diff --git a/drivers/hv/channel_mgmt.c b/drivers/hv/channel_mgmt.c index 6e084c207414..6f87220e2ca3 100644 --- a/drivers/hv/channel_mgmt.c +++ b/drivers/hv/channel_mgmt.c @@ -843,14 +843,14 @@ static void vmbus_wait_for_unload(void) =3D per_cpu_ptr(hv_context.cpu_context, cpu); =20 /* - * 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 =3D hv_cpu->synic_message_page; + page_addr =3D hv_cpu->hyp_synic_message_page; if (!page_addr) continue; =20 @@ -891,7 +891,7 @@ static void vmbus_wait_for_unload(void) struct hv_per_cpu_context *hv_cpu =3D per_cpu_ptr(hv_context.cpu_context, cpu); =20 - page_addr =3D hv_cpu->synic_message_page; + page_addr =3D hv_cpu->hyp_synic_message_page; if (!page_addr) continue; =20 diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c index 308c8f279df8..964b9102477d 100644 --- a/drivers/hv/hv.c +++ b/drivers/hv/hv.c @@ -145,20 +145,20 @@ int hv_synic_alloc(void) * Skip these pages allocation here. */ if (!ms_hyperv.paravisor_present && !hv_root_partition()) { - hv_cpu->synic_message_page =3D + hv_cpu->hyp_synic_message_page =3D (void *)get_zeroed_page(GFP_ATOMIC); - if (!hv_cpu->synic_message_page) { + if (!hv_cpu->hyp_synic_message_page) { pr_err("Unable to allocate SYNIC message page\n"); goto err; } =20 - hv_cpu->synic_event_page =3D + hv_cpu->hyp_synic_event_page =3D (void *)get_zeroed_page(GFP_ATOMIC); - if (!hv_cpu->synic_event_page) { + if (!hv_cpu->hyp_synic_event_page) { pr_err("Unable to allocate SYNIC event page\n"); =20 - free_page((unsigned long)hv_cpu->synic_message_page); - hv_cpu->synic_message_page =3D NULL; + free_page((unsigned long)hv_cpu->hyp_synic_message_page); + hv_cpu->hyp_synic_message_page =3D NULL; goto err; } } @@ -166,30 +166,30 @@ int hv_synic_alloc(void) if (!ms_hyperv.paravisor_present && (hv_isolation_type_snp() || hv_isolation_type_tdx())) { ret =3D set_memory_decrypted((unsigned long) - hv_cpu->synic_message_page, 1); + hv_cpu->hyp_synic_message_page, 1); if (ret) { pr_err("Failed to decrypt SYNIC msg page: %d\n", ret); - hv_cpu->synic_message_page =3D NULL; + hv_cpu->hyp_synic_message_page =3D NULL; =20 /* * Free the event page here so that hv_synic_free() * won't later try to re-encrypt it. */ - free_page((unsigned long)hv_cpu->synic_event_page); - hv_cpu->synic_event_page =3D NULL; + free_page((unsigned long)hv_cpu->hyp_synic_event_page); + hv_cpu->hyp_synic_event_page =3D NULL; goto err; } =20 ret =3D set_memory_decrypted((unsigned long) - hv_cpu->synic_event_page, 1); + hv_cpu->hyp_synic_event_page, 1); if (ret) { pr_err("Failed to decrypt SYNIC event page: %d\n", ret); - hv_cpu->synic_event_page =3D NULL; + hv_cpu->hyp_synic_event_page =3D NULL; goto err; } =20 - memset(hv_cpu->synic_message_page, 0, PAGE_SIZE); - memset(hv_cpu->synic_event_page, 0, PAGE_SIZE); + memset(hv_cpu->hyp_synic_message_page, 0, PAGE_SIZE); + memset(hv_cpu->hyp_synic_event_page, 0, PAGE_SIZE); } } =20 @@ -225,28 +225,28 @@ void hv_synic_free(void) =20 if (!ms_hyperv.paravisor_present && (hv_isolation_type_snp() || hv_isolation_type_tdx())) { - if (hv_cpu->synic_message_page) { + if (hv_cpu->hyp_synic_message_page) { ret =3D set_memory_encrypted((unsigned long) - hv_cpu->synic_message_page, 1); + hv_cpu->hyp_synic_message_page, 1); if (ret) { pr_err("Failed to encrypt SYNIC msg page: %d\n", ret); - hv_cpu->synic_message_page =3D NULL; + hv_cpu->hyp_synic_message_page =3D NULL; } } =20 - if (hv_cpu->synic_event_page) { + if (hv_cpu->hyp_synic_event_page) { ret =3D set_memory_encrypted((unsigned long) - hv_cpu->synic_event_page, 1); + hv_cpu->hyp_synic_event_page, 1); if (ret) { pr_err("Failed to encrypt SYNIC event page: %d\n", ret); - hv_cpu->synic_event_page =3D NULL; + hv_cpu->hyp_synic_event_page =3D NULL; } } } =20 free_page((unsigned long)hv_cpu->post_msg_page); - free_page((unsigned long)hv_cpu->synic_event_page); - free_page((unsigned long)hv_cpu->synic_message_page); + free_page((unsigned long)hv_cpu->hyp_synic_event_page); + free_page((unsigned long)hv_cpu->hyp_synic_message_page); } =20 kfree(hv_context.hv_numa_map); @@ -276,12 +276,12 @@ void hv_synic_enable_regs(unsigned int cpu) /* Mask out vTOM bit. ioremap_cache() maps decrypted */ u64 base =3D (simp.base_simp_gpa << HV_HYP_PAGE_SHIFT) & ~ms_hyperv.shared_gpa_boundary; - hv_cpu->synic_message_page =3D + hv_cpu->hyp_synic_message_page =3D (void *)ioremap_cache(base, HV_HYP_PAGE_SIZE); - if (!hv_cpu->synic_message_page) + if (!hv_cpu->hyp_synic_message_page) pr_err("Fail to map synic message page.\n"); } else { - simp.base_simp_gpa =3D virt_to_phys(hv_cpu->synic_message_page) + simp.base_simp_gpa =3D virt_to_phys(hv_cpu->hyp_synic_message_page) >> HV_HYP_PAGE_SHIFT; } =20 @@ -295,12 +295,12 @@ void hv_synic_enable_regs(unsigned int cpu) /* Mask out vTOM bit. ioremap_cache() maps decrypted */ u64 base =3D (siefp.base_siefp_gpa << HV_HYP_PAGE_SHIFT) & ~ms_hyperv.shared_gpa_boundary; - hv_cpu->synic_event_page =3D + hv_cpu->hyp_synic_event_page =3D (void *)ioremap_cache(base, HV_HYP_PAGE_SIZE); - if (!hv_cpu->synic_event_page) + if (!hv_cpu->hyp_synic_event_page) pr_err("Fail to map synic event page.\n"); } else { - siefp.base_siefp_gpa =3D virt_to_phys(hv_cpu->synic_event_page) + siefp.base_siefp_gpa =3D virt_to_phys(hv_cpu->hyp_synic_event_page) >> HV_HYP_PAGE_SHIFT; } =20 @@ -358,8 +358,8 @@ void hv_synic_disable_regs(unsigned int cpu) */ simp.simp_enabled =3D 0; if (ms_hyperv.paravisor_present || hv_root_partition()) { - iounmap(hv_cpu->synic_message_page); - hv_cpu->synic_message_page =3D NULL; + iounmap(hv_cpu->hyp_synic_message_page); + hv_cpu->hyp_synic_message_page =3D NULL; } else { simp.base_simp_gpa =3D 0; } @@ -370,8 +370,8 @@ void hv_synic_disable_regs(unsigned int cpu) siefp.siefp_enabled =3D 0; =20 if (ms_hyperv.paravisor_present || hv_root_partition()) { - iounmap(hv_cpu->synic_event_page); - hv_cpu->synic_event_page =3D NULL; + iounmap(hv_cpu->hyp_synic_event_page); + hv_cpu->hyp_synic_event_page =3D NULL; } else { siefp.base_siefp_gpa =3D 0; } @@ -401,7 +401,7 @@ static bool hv_synic_event_pending(void) { struct hv_per_cpu_context *hv_cpu =3D this_cpu_ptr(hv_context.cpu_context= ); union hv_synic_event_flags *event =3D - (union hv_synic_event_flags *)hv_cpu->synic_event_page + VMBUS_MESSAGE_S= INT; + (union hv_synic_event_flags *)hv_cpu->hyp_synic_event_page + VMBUS_MESSA= GE_SINT; unsigned long *recv_int_page =3D event->flags; /* assumes VMBus version >= =3D VERSION_WIN8 */ bool pending; u32 relid; diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h index 0b450e53161e..fc3cdb26ff1a 100644 --- a/drivers/hv/hyperv_vmbus.h +++ b/drivers/hv/hyperv_vmbus.h @@ -120,8 +120,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; =20 /* * The page is only used in hv_post_message() for a TDX VM (with the diff --git a/drivers/hv/mshv_root.h b/drivers/hv/mshv_root.h index e3931b0f1269..db6b42db2fdc 100644 --- a/drivers/hv/mshv_root.h +++ b/drivers/hv/mshv_root.h @@ -169,7 +169,7 @@ struct mshv_girq_routing_table { }; =20 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; }; diff --git a/drivers/hv/mshv_synic.c b/drivers/hv/mshv_synic.c index e6b6381b7c36..f8b0337cdc82 100644 --- a/drivers/hv/mshv_synic.c +++ b/drivers/hv/mshv_synic.c @@ -394,7 +394,7 @@ mshv_intercept_isr(struct hv_message *msg) void mshv_isr(void) { struct hv_synic_pages *spages =3D this_cpu_ptr(mshv_root.synic_pages); - struct hv_message_page **msg_page =3D &spages->synic_message_page; + struct hv_message_page **msg_page =3D &spages->hyp_synic_message_page; struct hv_message *msg; bool handled; =20 @@ -456,7 +456,7 @@ int mshv_synic_init(unsigned int cpu) #endif union hv_synic_scontrol sctrl; struct hv_synic_pages *spages =3D this_cpu_ptr(mshv_root.synic_pages); - struct hv_message_page **msg_page =3D &spages->synic_message_page; + struct hv_message_page **msg_page =3D &spages->hyp_synic_message_page; struct hv_synic_event_flags_page **event_flags_page =3D &spages->synic_event_flags_page; struct hv_synic_event_ring_page **event_ring_page =3D @@ -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 =3D this_cpu_ptr(mshv_root.synic_pages); - struct hv_message_page **msg_page =3D &spages->synic_message_page; + struct hv_message_page **msg_page =3D &spages->hyp_synic_message_page; struct hv_synic_event_flags_page **event_flags_page =3D &spages->synic_event_flags_page; struct hv_synic_event_ring_page **event_ring_page =3D diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c index 698c86c4ef03..72940a64b0b6 100644 --- a/drivers/hv/vmbus_drv.c +++ b/drivers/hv/vmbus_drv.c @@ -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 =3D (void *)data; - void *page_addr =3D hv_cpu->synic_message_page; + void *page_addr =3D hv_cpu->hyp_synic_message_page; struct hv_message msg_copy, *msg =3D (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_contex= t *hv_cpu) * The event page can be directly checked to get the id of * the channel that has the interrupt pending. */ - void *page_addr =3D hv_cpu->synic_event_page; + void *page_addr =3D hv_cpu->hyp_synic_event_page; union hv_synic_event_flags *event =3D (union hv_synic_event_flags *)page_addr + VMBUS_MESSAGE_SINT; @@ -1327,7 +1327,7 @@ static void vmbus_isr(void) =20 vmbus_chan_sched(hv_cpu); =20 - page_addr =3D hv_cpu->synic_message_page; + page_addr =3D hv_cpu->hyp_synic_message_page; msg =3D (struct hv_message *)page_addr + VMBUS_MESSAGE_SINT; =20 /* Check if there are actual msgs to be processed */ --=20 2.43.0 From nobody Tue Oct 7 03:46:14 2025 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C39D3277C90; Mon, 14 Jul 2025 22:15:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=13.77.154.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752531354; cv=none; b=pr0RbN2HBsBEXYWXGYEcbibSQ+pgtK796Wb/cXJCcpl0eVuryqaloUkANeQyQrFKtx6KQjRboj+9fxCJDMLM3xrOWuIV9HhDJH/cfWd30klGLHtSHah4Qb8vh7YGZh7RvkDbN5zxQDxpIS2F9QYjDTB0NIbkzppsH4WwUwVGhGc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752531354; c=relaxed/simple; bh=jXzX23+vk/ISiT6f/XAQrhNaKxCl3/BgNh+25XnmdTw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uO0g4K0mjXbjemfCWeeao7tROvH2ckf4je9I/wlNHVdJT+EJ8qzuHZHLtJZViEgrgRr7JVmPzexExLB6RSCCBZdLAaE61Ee7ty7gtz+hvOEzpm9yT0daW7m5WMpcN1idz+4JYe+C/C/rYMb1aBRKhiGm31suC/sXHSBHm1HlPQU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com; spf=pass smtp.mailfrom=linux.microsoft.com; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b=VRLrxnv7; arc=none smtp.client-ip=13.77.154.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b="VRLrxnv7" Received: from romank-3650.corp.microsoft.com (unknown [131.107.160.188]) by linux.microsoft.com (Postfix) with ESMTPSA id 8FCDD201658C; Mon, 14 Jul 2025 15:15:48 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 8FCDD201658C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1752531348; bh=9vC0Ol2Be4TB/mOkPQt+zK1NX2371emadjhTsHwAdXY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VRLrxnv7H3+Qp/cT6RNYjjV04mZmQ+0JJ3z9yy/f3UfcPDBZ+kanx1tlm5LtxcUCR yaQpxhIj8kXoIzzOh0T8UGf8YHYx+2OwA3i3+5I+2c6PVLKbTx1Otxnz3k+uQX5FRu h4Pv24JqGVGnCUnQ8aQoIGJ6P9QyO/oVT75BfYiU= From: Roman Kisel To: alok.a.tiwari@oracle.com, arnd@arndb.de, bp@alien8.de, corbet@lwn.net, dave.hansen@linux.intel.com, decui@microsoft.com, haiyangz@microsoft.com, hpa@zytor.com, kys@microsoft.com, mhklinux@outlook.com, mingo@redhat.com, rdunlap@infradead.org, tglx@linutronix.de, Tianyu.Lan@microsoft.com, wei.liu@kernel.org, linux-arch@vger.kernel.org, linux-coco@lists.linux.dev, linux-doc@vger.kernel.org, linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org, x86@kernel.org Cc: apais@microsoft.com, benhill@microsoft.com, bperkins@microsoft.com, sunilmut@microsoft.com Subject: [PATCH hyperv-next v4 06/16] Drivers: hv: Allocate the paravisor SynIC pages when required Date: Mon, 14 Jul 2025 15:15:35 -0700 Message-ID: <20250714221545.5615-7-romank@linux.microsoft.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250714221545.5615-1-romank@linux.microsoft.com> References: <20250714221545.5615-1-romank@linux.microsoft.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Confidential 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. Signed-off-by: Roman Kisel Reviewed-by: Tianyu Lan --- drivers/hv/hv.c | 184 +++++++++++++++++++------------------- drivers/hv/hyperv_vmbus.h | 18 ++++ 2 files changed, 112 insertions(+), 90 deletions(-) diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c index 964b9102477d..e9ee0177d765 100644 --- a/drivers/hv/hv.c +++ b/drivers/hv/hv.c @@ -94,10 +94,70 @@ int hv_post_message(union hv_connection_id connection_i= d, return hv_result(status); } =20 +static int hv_alloc_page(void **page, bool decrypt, const char *note) +{ + int ret =3D 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 =3D (void *)__get_free_page(GFP_KERNEL); + if (!*page) + return -ENOMEM; + + if (decrypt) + ret =3D 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 =3D NULL; + return ret; +} + +static int hv_free_page(void **page, bool encrypt, const char *note) +{ + int ret =3D 0; + + if (!*page) + return 0; + + if (encrypt) + ret =3D 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 af= loat. + */ + if (ret) { + pr_err("deallocation failed for %s page, error %d, encrypt %d\n", + note, ret, encrypt); + } else + free_page((unsigned long)*page); + + *page =3D NULL; + + return ret; +} + int hv_synic_alloc(void) { int cpu, ret =3D -ENOMEM; struct hv_per_cpu_context *hv_cpu; + const bool decrypt =3D !vmbus_is_confidential(); =20 /* * First, zero all per-cpu memory areas so hv_synic_free() can @@ -123,73 +183,37 @@ int hv_synic_alloc(void) vmbus_on_msg_dpc, (unsigned long)hv_cpu); =20 if (ms_hyperv.paravisor_present && hv_isolation_type_tdx()) { - hv_cpu->post_msg_page =3D (void *)get_zeroed_page(GFP_ATOMIC); - if (!hv_cpu->post_msg_page) { - pr_err("Unable to allocate post msg page\n"); + ret =3D hv_alloc_page(&hv_cpu->post_msg_page, + decrypt, "post msg"); + if (ret) goto err; - } - - ret =3D 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 =3D NULL; - goto err; - } - - memset(hv_cpu->post_msg_page, 0, PAGE_SIZE); } =20 /* - * 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 =3D - (void *)get_zeroed_page(GFP_ATOMIC); - if (!hv_cpu->hyp_synic_message_page) { - pr_err("Unable to allocate SYNIC message page\n"); + ret =3D hv_alloc_page(&hv_cpu->hyp_synic_message_page, + decrypt, "hypervisor SynIC msg"); + if (ret) goto err; - } - - hv_cpu->hyp_synic_event_page =3D - (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 =3D NULL; + ret =3D hv_alloc_page(&hv_cpu->hyp_synic_event_page, + decrypt, "hypervisor SynIC event"); + if (ret) goto err; - } } =20 - if (!ms_hyperv.paravisor_present && - (hv_isolation_type_snp() || hv_isolation_type_tdx())) { - ret =3D 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 =3D 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 =3D NULL; + if (vmbus_is_confidential()) { + ret =3D hv_alloc_page(&hv_cpu->para_synic_message_page, + false, "paravisor SynIC msg"); + if (ret) goto err; - } - - ret =3D 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 =3D NULL; + ret =3D 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); } } =20 @@ -205,48 +229,28 @@ int hv_synic_alloc(void) =20 void hv_synic_free(void) { - int cpu, ret; + int cpu; + const bool encrypt =3D !vmbus_is_confidential(); =20 for_each_present_cpu(cpu) { struct hv_per_cpu_context *hv_cpu =3D per_cpu_ptr(hv_context.cpu_context, cpu); =20 - /* 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 =3D 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 =3D 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 =3D 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 =3D NULL; - } - } - - if (hv_cpu->hyp_synic_event_page) { - ret =3D 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 =3D 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); } =20 kfree(hv_context.hv_numa_map); diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h index fc3cdb26ff1a..16b5cf1bca19 100644 --- a/drivers/hv/hyperv_vmbus.h +++ b/drivers/hv/hyperv_vmbus.h @@ -120,8 +120,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; =20 /* * The page is only used in hv_post_message() for a TDX VM (with the --=20 2.43.0 From nobody Tue Oct 7 03:46:14 2025 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2DBFA278E75; Mon, 14 Jul 2025 22:15:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=13.77.154.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752531353; cv=none; b=DOAiDMnF6B3DKVGST1c2RSEL4+rtZBjL16+vK0/sGrmiSFdl57/NpZ1YiYUlp6UIlQ160FQh9xcoziCvnLIy66hppj9I3W+B5YVxGZfD9KiO8G1p/oK/IInqOpAnzOaQ2uZ54bYgXs7w/8NrAo6NdoaPTdn3WKg5tfyzF+R0VbM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752531353; c=relaxed/simple; bh=PDoW0cTwMd+zaYHHMOCKb9goqInwTZCebB8VI+uMRE0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WyLcrRd4ebVNeGN6C2n6P/51ErzK0HVh2h11Y45Dv19SoWmNgJGMqO1mQBqTnRTj96HWgrtn1U1/MDMqQGGtp71Tw6iNX8bqXfa9ljZOvx0Zidd3oA4TD7C2M8BmuexRX7He74P0e0e/oj7DhvpyvrpoOjTz9gx2J70nOOLgA60= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com; spf=pass smtp.mailfrom=linux.microsoft.com; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b=D/4xcalO; arc=none smtp.client-ip=13.77.154.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b="D/4xcalO" Received: from romank-3650.corp.microsoft.com (unknown [131.107.160.188]) by linux.microsoft.com (Postfix) with ESMTPSA id D37A52016592; Mon, 14 Jul 2025 15:15:48 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com D37A52016592 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1752531349; bh=2Uj5+MWRT6Nrb2e5uPnnI56BMuCGOG4Pghr4svS0DvM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=D/4xcalOyAiEZbazwtk4xGsxXLYvYZuuLwvfe/OzzaZpYr0LDrg9/j0DBkx5JZpPk xkrIRZbDUy1z46KfVEcAS8sV3qlJvlP/L52HatvDPz0o1uGiN/eq297peiCS6Q+INy hSRPS8RCx4tGFYbtI1OyI8+t7PRmtTVl3UUmCC10= From: Roman Kisel To: alok.a.tiwari@oracle.com, arnd@arndb.de, bp@alien8.de, corbet@lwn.net, dave.hansen@linux.intel.com, decui@microsoft.com, haiyangz@microsoft.com, hpa@zytor.com, kys@microsoft.com, mhklinux@outlook.com, mingo@redhat.com, rdunlap@infradead.org, tglx@linutronix.de, Tianyu.Lan@microsoft.com, wei.liu@kernel.org, linux-arch@vger.kernel.org, linux-coco@lists.linux.dev, linux-doc@vger.kernel.org, linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org, x86@kernel.org Cc: apais@microsoft.com, benhill@microsoft.com, bperkins@microsoft.com, sunilmut@microsoft.com Subject: [PATCH hyperv-next v4 07/16] Drivers: hv: Post messages through the confidential VMBus if available Date: Mon, 14 Jul 2025 15:15:36 -0700 Message-ID: <20250714221545.5615-8-romank@linux.microsoft.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250714221545.5615-1-romank@linux.microsoft.com> References: <20250714221545.5615-1-romank@linux.microsoft.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" When 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. Signed-off-by: Roman Kisel Reviewed-by: Tianyu Lan --- drivers/hv/hv.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c index e9ee0177d765..816f8a14ff63 100644 --- a/drivers/hv/hv.c +++ b/drivers/hv/hv.c @@ -74,7 +74,11 @@ int hv_post_message(union hv_connection_id connection_id, aligned_msg->payload_size =3D payload_size; memcpy((void *)aligned_msg->payload, payload, payload_size); =20 - 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 =3D hv_tdx_hypercall(HVCALL_POST_MESSAGE, virt_to_phys(aligned_msg), 0); @@ -85,6 +89,11 @@ int hv_post_message(union hv_connection_id connection_id, else status =3D HV_STATUS_INVALID_PARAMETER; } else { + /* + * 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 =3D hv_do_hypercall(HVCALL_POST_MESSAGE, aligned_msg, NULL); } --=20 2.43.0 From nobody Tue Oct 7 03:46:14 2025 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DF9AF278143; Mon, 14 Jul 2025 22:15:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=13.77.154.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752531352; cv=none; b=q7zd2VSNeHtzSIwEi1g+LC03zy0Rm1igfUFaipSMADg9ykcZozjMhcA5yjLReH/mmqC+37Lx/o0PqxSIZOhaADs+M2CP8FYZ4xnPAJlvV4KPZrrDZLQ4ppx1EzjAzVJaW0cfucuDMi2Jw96w/DfsfT/T74cP8niaN+34S8eKWSQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752531352; c=relaxed/simple; bh=hN0bzn33b7/bcvBUrIoUS+YL0Fauw5ocCHmmJJZGNOo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JKWlkt7GiZbrXwZ/BezwGZZzrmLHluwG3i2GSIl8DlQCRz+IHfX0AAjuqey3sz0QMcRFIrq+XI6Znw4XEbi1LpreJAY1k5bPAS+YlNL4BdbgMYgSzjAsooSdi6tszlAZktvZGCfBjuKxViRjMsI8CByaUERxrmaG0oQCCHUglIU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com; spf=pass smtp.mailfrom=linux.microsoft.com; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b=Gc0UX85E; arc=none smtp.client-ip=13.77.154.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b="Gc0UX85E" Received: from romank-3650.corp.microsoft.com (unknown [131.107.160.188]) by linux.microsoft.com (Postfix) with ESMTPSA id 20B8A2016594; Mon, 14 Jul 2025 15:15:49 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 20B8A2016594 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1752531349; bh=G1piMKMIQwdOuzoLPvU+WPXOuTN4hKPH7hsZm96BaHU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Gc0UX85ErGQszX3lQ+KML5u23xXLREkBCdgWmk1SpZilJVAdj7SDtcWFRes+ralIf EZzDgm3fCETCop3FP5+QaE0xoi1AQGjjVWu3rGiwxDEGzlcBxLhP2/fKMAvHl6UnDb AKlTnpIcvSkV75CW8pQdx3Rr8xXp/mitaivNOoM0= From: Roman Kisel To: alok.a.tiwari@oracle.com, arnd@arndb.de, bp@alien8.de, corbet@lwn.net, dave.hansen@linux.intel.com, decui@microsoft.com, haiyangz@microsoft.com, hpa@zytor.com, kys@microsoft.com, mhklinux@outlook.com, mingo@redhat.com, rdunlap@infradead.org, tglx@linutronix.de, Tianyu.Lan@microsoft.com, wei.liu@kernel.org, linux-arch@vger.kernel.org, linux-coco@lists.linux.dev, linux-doc@vger.kernel.org, linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org, x86@kernel.org Cc: apais@microsoft.com, benhill@microsoft.com, bperkins@microsoft.com, sunilmut@microsoft.com Subject: [PATCH hyperv-next v4 08/16] Drivers: hv: remove stale comment Date: Mon, 14 Jul 2025 15:15:37 -0700 Message-ID: <20250714221545.5615-9-romank@linux.microsoft.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250714221545.5615-1-romank@linux.microsoft.com> References: <20250714221545.5615-1-romank@linux.microsoft.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The comment about the x2v shim is ancient and long since incorrect. Remove the incorrect comment. Signed-off-by: Roman Kisel Reviewed-by: Tianyu Lan --- drivers/hv/hv.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c index 816f8a14ff63..820711e954d1 100644 --- a/drivers/hv/hv.c +++ b/drivers/hv/hv.c @@ -266,11 +266,7 @@ void hv_synic_free(void) } =20 /* - * 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) { --=20 2.43.0 From nobody Tue Oct 7 03:46:14 2025 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2C705278753; Mon, 14 Jul 2025 22:15:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=13.77.154.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752531352; cv=none; b=P8yLkTPKy3jKIfnhPoigziTP1dnwKxdZJEdRjcRAfNk/CjF2lVxiqyc0oKntojhjMgS1XgFSzHiy9uthz57bTUpM63RlasZW1sxpNoVzka1SpNjaKDw5VdEpgl7C4lr2/B+vA88H/RQ8YYbZqCNf2SDbnVCE7pIWR91NFioAELs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752531352; c=relaxed/simple; bh=u/KPsb1h5AglUAwekqho240DEYtuoNvGBF+U/5Ha9bE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=I7vlCZ+q+39UyTaLAQ36b240ZNb25LoMnI7PuDCy9C1M6XXwOQ6jHR/qFws1EUfCQGHTLc4UmWTijvL4z1BrdHHZGn+kS8cPN4vGqAi7XExHB2v5cI4mzkuWWiQHjNovXvfU0rQS3bqKd9SVC5JFv8MICuQeF1wJFr14mPmRwSs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com; spf=pass smtp.mailfrom=linux.microsoft.com; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b=Ht0M3ss7; arc=none smtp.client-ip=13.77.154.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b="Ht0M3ss7" Received: from romank-3650.corp.microsoft.com (unknown [131.107.160.188]) by linux.microsoft.com (Postfix) with ESMTPSA id 620B22016596; Mon, 14 Jul 2025 15:15:49 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 620B22016596 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1752531349; bh=ANaSeCLcuOpQTrlS/gomE+iBc3WLPtbEx8zr3r2sN/c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ht0M3ss7YtAqN2f0e54wCb9XuZKJB5oYA780tB1InvLZ+ROTELDad1U6UroSEFbCW s8b619rf8GbIQtE13F8E1mRCqcB3no5FK/5xrw7u/BIWSqQRihq4ZnUY1rfOkeC90C LobQVx2g5Qyr1I2c+HhWYLm8edvAG3/F5Re163vA= From: Roman Kisel To: alok.a.tiwari@oracle.com, arnd@arndb.de, bp@alien8.de, corbet@lwn.net, dave.hansen@linux.intel.com, decui@microsoft.com, haiyangz@microsoft.com, hpa@zytor.com, kys@microsoft.com, mhklinux@outlook.com, mingo@redhat.com, rdunlap@infradead.org, tglx@linutronix.de, Tianyu.Lan@microsoft.com, wei.liu@kernel.org, linux-arch@vger.kernel.org, linux-coco@lists.linux.dev, linux-doc@vger.kernel.org, linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org, x86@kernel.org Cc: apais@microsoft.com, benhill@microsoft.com, bperkins@microsoft.com, sunilmut@microsoft.com Subject: [PATCH hyperv-next v4 09/16] Drivers: hv: Check message and event pages for non-NULL before iounmap() Date: Mon, 14 Jul 2025 15:15:38 -0700 Message-ID: <20250714221545.5615-10-romank@linux.microsoft.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250714221545.5615-1-romank@linux.microsoft.com> References: <20250714221545.5615-1-romank@linux.microsoft.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" It might happen that some hyp SynIC pages aren't allocated. Check for that and only then call iounmap(). Signed-off-by: Roman Kisel Reviewed-by: Tianyu Lan --- drivers/hv/hv.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c index 820711e954d1..a8669843c56e 100644 --- a/drivers/hv/hv.c +++ b/drivers/hv/hv.c @@ -367,8 +367,10 @@ void hv_synic_disable_regs(unsigned int cpu) */ simp.simp_enabled =3D 0; if (ms_hyperv.paravisor_present || hv_root_partition()) { - iounmap(hv_cpu->hyp_synic_message_page); - hv_cpu->hyp_synic_message_page =3D NULL; + if (hv_cpu->hyp_synic_message_page) { + iounmap(hv_cpu->hyp_synic_message_page); + hv_cpu->hyp_synic_message_page =3D NULL; + } } else { simp.base_simp_gpa =3D 0; } @@ -379,8 +381,10 @@ void hv_synic_disable_regs(unsigned int cpu) siefp.siefp_enabled =3D 0; =20 if (ms_hyperv.paravisor_present || hv_root_partition()) { - iounmap(hv_cpu->hyp_synic_event_page); - hv_cpu->hyp_synic_event_page =3D NULL; + if (hv_cpu->hyp_synic_event_page) { + iounmap(hv_cpu->hyp_synic_event_page); + hv_cpu->hyp_synic_event_page =3D NULL; + } } else { siefp.base_siefp_gpa =3D 0; } --=20 2.43.0 From nobody Tue Oct 7 03:46:14 2025 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7FA94279327; Mon, 14 Jul 2025 22:15:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=13.77.154.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752531354; cv=none; b=kLvfXZ1dtcFo6cVWz6kah6nb4Qx5+iCf2A57ImTnxaMOsrEoVPU4K05NObyUlw9YSd+Q6hk2/O8nGEF9kwKCOBExFiYoJhHOHH5nYeoGr2oW7JaDLa52gLHl5UvyNdu2VUQE6827p6Ypn2Lyiiiiyqu2c8a0BXCOLObckpFZNj0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752531354; c=relaxed/simple; bh=NwWtU4pQqupYr0rrxiC/LfZQoDejFRAujTn7n0rRKVI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PSyzHsFRla4ISMFCcnXEbXlu9KVyfQTHnRlAFPYoJhDh0ivdCm4fWPFkU8wD1m9hdp7p3ySTK1DGDMOR5AeR5LjUlnke7zCwrC9b4XJT7hQy2xJ1CKvye2PXTjOhH7PnBKIzD1/veciqTJOAjc2vLoPWzsr+oZrKgI+riNpzlPA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com; spf=pass smtp.mailfrom=linux.microsoft.com; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b=LdNp/KDn; arc=none smtp.client-ip=13.77.154.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b="LdNp/KDn" Received: from romank-3650.corp.microsoft.com (unknown [131.107.160.188]) by linux.microsoft.com (Postfix) with ESMTPSA id A6F84201A4A1; Mon, 14 Jul 2025 15:15:49 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com A6F84201A4A1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1752531349; bh=8xRSjjAXOHXCVTJfOWaC61Gx4ioYySGsoSFmStFww+M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LdNp/KDn3G92CXUx4Z28jlwRu6Z7unV4x9a7ziuTrswy3mjk8BmxeLHU8InX7aAn1 l6AzMS9smN+pK3z5ORqp+H1p/uMghs/JfQxpJZdBJf6Mj6/XJ1VTu389YUJuax3ZSs E7+2OyFr159nV9m0oWsRDFXXcyTzizDMIQOnR3gk= From: Roman Kisel To: alok.a.tiwari@oracle.com, arnd@arndb.de, bp@alien8.de, corbet@lwn.net, dave.hansen@linux.intel.com, decui@microsoft.com, haiyangz@microsoft.com, hpa@zytor.com, kys@microsoft.com, mhklinux@outlook.com, mingo@redhat.com, rdunlap@infradead.org, tglx@linutronix.de, Tianyu.Lan@microsoft.com, wei.liu@kernel.org, linux-arch@vger.kernel.org, linux-coco@lists.linux.dev, linux-doc@vger.kernel.org, linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org, x86@kernel.org Cc: apais@microsoft.com, benhill@microsoft.com, bperkins@microsoft.com, sunilmut@microsoft.com Subject: [PATCH hyperv-next v4 10/16] Drivers: hv: Rename the SynIC enable and disable routines Date: Mon, 14 Jul 2025 15:15:39 -0700 Message-ID: <20250714221545.5615-11-romank@linux.microsoft.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250714221545.5615-1-romank@linux.microsoft.com> References: <20250714221545.5615-1-romank@linux.microsoft.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The 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. Signed-off-by: Roman Kisel Reviewed-by: Tianyu Lan --- 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(-) diff --git a/drivers/hv/channel_mgmt.c b/drivers/hv/channel_mgmt.c index 6f87220e2ca3..ca2fe10c110a 100644 --- a/drivers/hv/channel_mgmt.c +++ b/drivers/hv/channel_mgmt.c @@ -845,7 +845,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. diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c index a8669843c56e..94a81bb3c8c7 100644 --- a/drivers/hv/hv.c +++ b/drivers/hv/hv.c @@ -266,9 +266,10 @@ void hv_synic_free(void) } =20 /* - * 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 =3D per_cpu_ptr(hv_context.cpu_context, cpu); @@ -334,14 +335,14 @@ void hv_synic_enable_regs(unsigned int cpu) =20 int hv_synic_init(unsigned int cpu) { - hv_synic_enable_regs(cpu); + hv_hyp_synic_enable_regs(cpu); =20 hv_stimer_legacy_init(cpu, VMBUS_MESSAGE_SINT); =20 return 0; } =20 -void hv_synic_disable_regs(unsigned int cpu) +void hv_hyp_synic_disable_regs(unsigned int cpu) { struct hv_per_cpu_context *hv_cpu =3D per_cpu_ptr(hv_context.cpu_context, cpu); @@ -528,7 +529,7 @@ int hv_synic_cleanup(unsigned int cpu) always_cleanup: hv_stimer_legacy_cleanup(cpu); =20 - hv_synic_disable_regs(cpu); + hv_hyp_synic_disable_regs(cpu); =20 return ret; } diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h index 16b5cf1bca19..2873703d08a9 100644 --- a/drivers/hv/hyperv_vmbus.h +++ b/drivers/hv/hyperv_vmbus.h @@ -189,10 +189,10 @@ extern int hv_synic_alloc(void); =20 extern void hv_synic_free(void); =20 -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); =20 -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); =20 /* Interface */ diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c index 72940a64b0b6..13aca5abc7d8 100644 --- a/drivers/hv/vmbus_drv.c +++ b/drivers/hv/vmbus_drv.c @@ -2809,7 +2809,7 @@ static void hv_crash_handler(struct pt_regs *regs) */ cpu =3D smp_processor_id(); hv_stimer_cleanup(cpu); - hv_synic_disable_regs(cpu); + hv_hyp_synic_disable_regs(cpu); }; =20 static int hv_synic_suspend(void) @@ -2834,14 +2834,14 @@ static int hv_synic_suspend(void) * interrupts-disabled context. */ =20 - hv_synic_disable_regs(0); + hv_hyp_synic_disable_regs(0); =20 return 0; } =20 static void hv_synic_resume(void) { - hv_synic_enable_regs(0); + hv_hyp_synic_enable_regs(0); =20 /* * Note: we don't need to call hv_stimer_init(0), because the timer --=20 2.43.0 From nobody Tue Oct 7 03:46:14 2025 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E2883279795; Mon, 14 Jul 2025 22:15:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=13.77.154.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752531354; cv=none; b=UBTVaVsJzc4eMTYccuIsAq1RUFVmBlD5WwrgGbrWvhpc1XCdsQa3LS+1MreW+7v+zHVZM3+ldBQ5BufA8oPEIgbb5+GMdS6olmG3cH1ZUGe7pEl5Ix+syuCRKu4YLuVwmP7Io46C6Xmf9s4mUor3kNUq9h+RlTJHitfUT0YURMQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752531354; c=relaxed/simple; bh=/dJZ3cRvOzNN54jl9dU2yCgjMi/kqJvgcAhMV+mc4DU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=d/7KA4k7lvOWcVFJ8fm82L5ZBz9naHkrT3/O7l4edoy5Q5h8wbaNGLoRbR2faZx2H77WaQdqiCvAScUMkvJaTltGpK08wRyNgSHZ/mxDbNG7eXepO4TpVvWV6P+PsrGPCUVP5ZYyLPs3+igsDLtovkOm/wJomdqVMoBtcC4teLE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com; spf=pass smtp.mailfrom=linux.microsoft.com; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b=B69YWid3; arc=none smtp.client-ip=13.77.154.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b="B69YWid3" Received: from romank-3650.corp.microsoft.com (unknown [131.107.160.188]) by linux.microsoft.com (Postfix) with ESMTPSA id E98CB201A4A0; Mon, 14 Jul 2025 15:15:49 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com E98CB201A4A0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1752531350; bh=j00XbzilASNTkMHd9m2L0mBdWZrnYkzsjHSAldQBM9k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=B69YWid3xVys3P3BR0vAlLZVzI0tdaW4nUP1RbmsJPLJTOVfRLW8U0mgwI8msGb7W pWQDCK8Wkc6ABbSwTLrkroFeqxROp6GbDlJrZGdtB6O1wDNSj+lzhor4apfkmorXGN yrhGr8UDCfLdtMXbKRTvkkMiRlNZp3rAlRiBav3Q= From: Roman Kisel To: alok.a.tiwari@oracle.com, arnd@arndb.de, bp@alien8.de, corbet@lwn.net, dave.hansen@linux.intel.com, decui@microsoft.com, haiyangz@microsoft.com, hpa@zytor.com, kys@microsoft.com, mhklinux@outlook.com, mingo@redhat.com, rdunlap@infradead.org, tglx@linutronix.de, Tianyu.Lan@microsoft.com, wei.liu@kernel.org, linux-arch@vger.kernel.org, linux-coco@lists.linux.dev, linux-doc@vger.kernel.org, linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org, x86@kernel.org Cc: apais@microsoft.com, benhill@microsoft.com, bperkins@microsoft.com, sunilmut@microsoft.com Subject: [PATCH hyperv-next v4 11/16] Drivers: hv: Functions for setting up and tearing down the paravisor SynIC Date: Mon, 14 Jul 2025 15:15:40 -0700 Message-ID: <20250714221545.5615-12-romank@linux.microsoft.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250714221545.5615-1-romank@linux.microsoft.com> References: <20250714221545.5615-1-romank@linux.microsoft.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The 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. Signed-off-by: Roman Kisel --- drivers/hv/hv.c | 197 +++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 185 insertions(+), 12 deletions(-) diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c index 94a81bb3c8c7..9d85d5e62968 100644 --- a/drivers/hv/hv.c +++ b/drivers/hv/hv.c @@ -276,9 +276,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; =20 - /* Setup the Synic's message page */ + /* Setup the Synic's message page with the hypervisor. */ simp.as_uint64 =3D hv_get_msr(HV_MSR_SIMP); simp.simp_enabled =3D 1; =20 @@ -297,7 +296,7 @@ void hv_hyp_synic_enable_regs(unsigned int cpu) =20 hv_set_msr(HV_MSR_SIMP, simp.as_uint64); =20 - /* Setup the Synic's event page */ + /* Setup the Synic's event page with the hypervisor. */ siefp.as_uint64 =3D hv_get_msr(HV_MSR_SIEFP); siefp.siefp_enabled =3D 1; =20 @@ -325,6 +324,11 @@ void hv_hyp_synic_enable_regs(unsigned int cpu) shared_sint.masked =3D false; shared_sint.auto_eoi =3D 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; =20 /* Enable the global synic bit */ sctrl.as_uint64 =3D hv_get_msr(HV_MSR_SCONTROL); @@ -333,13 +337,100 @@ void hv_hyp_synic_enable_regs(unsigned int cpu) hv_set_msr(HV_MSR_SCONTROL, sctrl.as_uint64); } =20 +/* + * The paravisor might not support proxying SynIC, and this + * function may fail. + */ +static int hv_para_synic_enable_regs(unsigned int cpu) +{ + int err; + union hv_synic_simp simp; + union hv_synic_siefp siefp; + struct hv_per_cpu_context *hv_cpu + =3D per_cpu_ptr(hv_context.cpu_context, cpu); + + /* Setup the Synic's message page with the paravisor. */ + err =3D hv_para_get_synic_register(HV_MSR_SIMP, &simp.as_uint64); + if (err) + return err; + simp.simp_enabled =3D 1; + simp.base_simp_gpa =3D virt_to_phys(hv_cpu->para_synic_message_page) + >> HV_HYP_PAGE_SHIFT; + err =3D hv_para_set_synic_register(HV_MSR_SIMP, simp.as_uint64); + if (err) + return err; + + /* Setup the Synic's event page with the paravisor. */ + err =3D hv_para_get_synic_register(HV_MSR_SIEFP, &siefp.as_uint64); + if (err) + return err; + siefp.siefp_enabled =3D 1; + siefp.base_siefp_gpa =3D virt_to_phys(hv_cpu->para_synic_event_page) + >> HV_HYP_PAGE_SHIFT; + return hv_para_set_synic_register(HV_MSR_SIEFP, siefp.as_uint64); +} + +static int hv_para_synic_enable_interrupts(void) +{ + union hv_synic_scontrol sctrl; + int err; + + /* Enable the global synic bit */ + err =3D hv_para_get_synic_register(HV_MSR_SCONTROL, &sctrl.as_uint64); + if (err) + return err; + sctrl.enable =3D 1; + + return hv_para_set_synic_register(HV_MSR_SCONTROL, sctrl.as_uint64); +} + int hv_synic_init(unsigned int cpu) { + int err; + + /* + * The paravisor may not support the confidential VMBus, + * check on that first. + */ + if (vmbus_is_confidential()) { + err =3D hv_para_synic_enable_regs(cpu); + if (err) + goto fail; + } + + /* + * The SINT is set in hv_hyperv_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 the code above enables interrupts + * via the paravisor if VMBus is confidential, and otherwise via the + * hypervisor. + */ + hv_hyp_synic_enable_regs(cpu); + if (vmbus_is_confidential()) { + err =3D hv_para_synic_enable_interrupts(); + if (err) + goto fail; + } else + hv_hyp_synic_enable_interrupts(); =20 hv_stimer_legacy_init(cpu, VMBUS_MESSAGE_SINT); =20 return 0; + +fail: + /* + * The failure may only come from enabling the paravisor SynIC. + * That in turn means that the confidential VMBus cannot be used + * which is not an error: the setup will be re-tried with the + * non-confidential VMBus. + * + * We also don't bother attempting to reset the paravisor registers + * as something isn't working there anyway. + */ + return err; } =20 void hv_hyp_synic_disable_regs(unsigned int cpu) @@ -349,7 +440,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; =20 shared_sint.as_uint64 =3D hv_get_msr(HV_MSR_SINT0 + VMBUS_MESSAGE_SINT); =20 @@ -361,7 +451,7 @@ void hv_hyp_synic_disable_regs(unsigned int cpu) =20 simp.as_uint64 =3D 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. @@ -391,14 +481,64 @@ void hv_hyp_synic_disable_regs(unsigned int cpu) } =20 hv_set_msr(HV_MSR_SIEFP, siefp.as_uint64); +} + +static void hv_hyp_synic_disable_interrupts(void) +{ + union hv_synic_scontrol sctrl; =20 /* Disable the global synic bit */ sctrl.as_uint64 =3D hv_get_msr(HV_MSR_SCONTROL); sctrl.enable =3D 0; hv_set_msr(HV_MSR_SCONTROL, sctrl.as_uint64); +} =20 - if (vmbus_irq !=3D -1) - disable_percpu_irq(vmbus_irq); +static void hv_para_synic_disable_regs(unsigned int cpu) +{ + /* + * When a get/set register error is encountered, the function + * returns as the paravisor may not support these registers. + */ + int err; + union hv_synic_simp simp; + union hv_synic_siefp siefp; + + /* + * Don't deallocate memory here as the function is called on + * CPU online and offline operations. The guest will find + * itself without means of communication when resumed. + */ + + /* Disable SynIC's message page in the paravisor. */ + err =3D hv_para_get_synic_register(HV_MSR_SIMP, &simp.as_uint64); + if (err) + return; + simp.simp_enabled =3D 0; + + err =3D hv_para_set_synic_register(HV_MSR_SIMP, simp.as_uint64); + if (err) + return; + + /* Disable SynIC's event page in the paravisor. */ + err =3D hv_para_get_synic_register(HV_MSR_SIEFP, &siefp.as_uint64); + if (err) + return; + siefp.siefp_enabled =3D 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; + int err; + + /* Disable the global synic bit */ + err =3D hv_para_get_synic_register(HV_MSR_SCONTROL, &sctrl.as_uint64); + if (err) + return; + sctrl.enable =3D 0; + hv_para_set_synic_register(HV_MSR_SCONTROL, sctrl.as_uint64); } =20 #define HV_MAX_TRIES 3 @@ -411,16 +551,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, in= t sint) { - struct hv_per_cpu_context *hv_cpu =3D this_cpu_ptr(hv_context.cpu_context= ); - union hv_synic_event_flags *event =3D - (union hv_synic_event_flags *)hv_cpu->hyp_synic_event_page + VMBUS_MESSA= GE_SINT; - unsigned long *recv_int_page =3D event->flags; /* assumes VMBus version >= =3D VERSION_WIN8 */ + unsigned long *recv_int_page; bool pending; u32 relid; int tries =3D 0; =20 + if (!event) + return false; + + event +=3D sint; + recv_int_page =3D event->flags; /* assumes VMBus version >=3D VERSION_WIN= 8 */ retry: pending =3D false; for_each_set_bit(relid, recv_int_page, HV_EVENT_FLAGS_COUNT) { @@ -437,6 +579,17 @@ static bool hv_synic_event_pending(void) return pending; } =20 +static bool hv_synic_event_pending(void) +{ + struct hv_per_cpu_context *hv_cpu =3D this_cpu_ptr(hv_context.cpu_context= ); + union hv_synic_event_flags *hyp_synic_event_page =3D hv_cpu->hyp_synic_ev= ent_page; + union hv_synic_event_flags *para_synic_event_page =3D 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 =3D -EBUSY; @@ -529,7 +682,27 @@ int hv_synic_cleanup(unsigned int cpu) always_cleanup: hv_stimer_legacy_cleanup(cpu); =20 + /* + * 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 gurantee 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 !=3D -1) + disable_percpu_irq(vmbus_irq); =20 return ret; } --=20 2.43.0 From nobody Tue Oct 7 03:46:14 2025 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2B30E279904; Mon, 14 Jul 2025 22:15:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=13.77.154.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752531354; cv=none; b=HBtilVLdXU04om/85cxWugFnMHhthK8PKR3j8CmKz2Dr+vSknmM83arFUvNfnAy0OVCoATZ7KLjral0nhT3l3xW9QRxicl+pRXoK9GjGmwn987eMSEq/BuZcvMmBr23UwrT5GyeDRx5BG7CdiYeXPZSPDyxzCPWP4U45YsGWYig= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752531354; c=relaxed/simple; bh=dumwlVQAuaRbcn1p/IF4QNNVcpVnsy76a7SVLjV8Q3o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HkVDGH4qSwo313a1SgI+NZB9ETBsChtZh7ZvfFoLUtsDmodHiiV5CXz/G2j5yZ7FIWxMPZdKb0bQodO6bjc2KU0w47ue9hqCuwrqKv48uBSuSWlQP3nummFW7Ctg1ueSCp0IOytgzDtwXefaFi4g7wLMR578FObSxoeTmp54ZWo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com; spf=pass smtp.mailfrom=linux.microsoft.com; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b=qc//hMsk; arc=none smtp.client-ip=13.77.154.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b="qc//hMsk" Received: from romank-3650.corp.microsoft.com (unknown [131.107.160.188]) by linux.microsoft.com (Postfix) with ESMTPSA id 3727B201A4CD; Mon, 14 Jul 2025 15:15:50 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 3727B201A4CD DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1752531350; bh=42IHhrO4islY3PvMR+vhbbQVAyXFdhkMLiuZuOP40Cg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qc//hMskvHvj8KLR89RpfUaEbmkkZGUIf8gaOC7XYOXh5/9hyBBP3jbi8m285N1jz mwzXPdYcyzVN65THd0VRgoxt8y0bCyVUoIBb9wqzM8JrZx8dQubWVO1IKu+4/a33UQ raUdHqkePqBkkxL5NvpfH9N0W3IN45QbFr8P3e1s= From: Roman Kisel To: alok.a.tiwari@oracle.com, arnd@arndb.de, bp@alien8.de, corbet@lwn.net, dave.hansen@linux.intel.com, decui@microsoft.com, haiyangz@microsoft.com, hpa@zytor.com, kys@microsoft.com, mhklinux@outlook.com, mingo@redhat.com, rdunlap@infradead.org, tglx@linutronix.de, Tianyu.Lan@microsoft.com, wei.liu@kernel.org, linux-arch@vger.kernel.org, linux-coco@lists.linux.dev, linux-doc@vger.kernel.org, linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org, x86@kernel.org Cc: apais@microsoft.com, benhill@microsoft.com, bperkins@microsoft.com, sunilmut@microsoft.com Subject: [PATCH hyperv-next v4 12/16] Drivers: hv: Allocate encrypted buffers when requested Date: Mon, 14 Jul 2025 15:15:41 -0700 Message-ID: <20250714221545.5615-13-romank@linux.microsoft.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250714221545.5615-1-romank@linux.microsoft.com> References: <20250714221545.5615-1-romank@linux.microsoft.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Confidential VMBus is built around using buffers not shared with the host. Support allocating encrypted buffers when requested. Signed-off-by: Roman Kisel Reviewed-by: Tianyu Lan --- drivers/hv/channel.c | 49 +++++++++++++++++++++++---------------- drivers/hv/hyperv_vmbus.h | 3 ++- drivers/hv/ring_buffer.c | 5 ++-- 3 files changed, 34 insertions(+), 23 deletions(-) diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c index 35f26fa1ffe7..051eeba800f2 100644 --- a/drivers/hv/channel.c +++ b/drivers/hv/channel.c @@ -443,20 +443,23 @@ static int __vmbus_establish_gpadl(struct vmbus_chann= el *channel, return ret; } =20 - /* - * 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 =3D true; - ret =3D 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 =3D !((channel->co_external_memory && type =3D=3D HV_GPA= DL_BUFFER) || + (channel->co_ring_buffer && type =3D=3D HV_GPADL_RING)); + if (gpadl->decrypted) { + /* + * The "decrypted" flag being true assumes that set_memory_decrypted() s= ucceeds. + * But if it fails, the encryption state of the memory is unknown. In th= at case, + * leave "decrypted" as true to ensure the memory is leaked instead of g= oing back + * on the free list. + */ + ret =3D 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; + } } =20 init_completion(&msginfo->waitevent); @@ -544,8 +547,10 @@ static int __vmbus_establish_gpadl(struct vmbus_channe= l *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 =3D false; + if (gpadl->decrypted) { + if (!set_memory_encrypted((unsigned long)kbuffer, PFN_UP(size))) + gpadl->decrypted =3D false; + } } =20 return ret; @@ -676,12 +681,13 @@ static int __vmbus_open(struct vmbus_channel *newchan= nel, goto error_clean_ring; =20 err =3D hv_ringbuffer_init(&newchannel->outbound, - page, send_pages, 0); + page, send_pages, 0, newchannel->co_ring_buffer); if (err) goto error_free_gpadl; =20 err =3D 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; =20 @@ -862,8 +868,11 @@ int vmbus_teardown_gpadl(struct vmbus_channel *channel= , struct vmbus_gpadl *gpad =20 kfree(info); =20 - ret =3D set_memory_encrypted((unsigned long)gpadl->buffer, - PFN_UP(gpadl->size)); + if (gpadl->decrypted) + ret =3D set_memory_encrypted((unsigned long)gpadl->buffer, + PFN_UP(gpadl->size)); + else + ret =3D 0; if (ret) pr_warn("Fail to set mem host visibility in GPADL teardown %d.\n", ret); =20 diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h index 2873703d08a9..beae68a70939 100644 --- a/drivers/hv/hyperv_vmbus.h +++ b/drivers/hv/hyperv_vmbus.h @@ -200,7 +200,8 @@ extern int hv_synic_cleanup(unsigned int cpu); void hv_ringbuffer_pre_init(struct vmbus_channel *channel); =20 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); =20 void hv_ringbuffer_cleanup(struct hv_ring_buffer_info *ring_info); =20 diff --git a/drivers/hv/ring_buffer.c b/drivers/hv/ring_buffer.c index 3c9b02471760..05c2cd42fc75 100644 --- a/drivers/hv/ring_buffer.c +++ b/drivers/hv/ring_buffer.c @@ -183,7 +183,8 @@ void hv_ringbuffer_pre_init(struct vmbus_channel *chann= el) =20 /* 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; @@ -207,7 +208,7 @@ int hv_ringbuffer_init(struct hv_ring_buffer_info *ring= _info, =20 ring_info->ring_buffer =3D (struct hv_ring_buffer *) vmap(pages_wraparound, page_cnt * 2 - 1, VM_MAP, - pgprot_decrypted(PAGE_KERNEL)); + confidential ? PAGE_KERNEL : pgprot_decrypted(PAGE_KERNEL)); =20 kfree(pages_wraparound); if (!ring_info->ring_buffer) --=20 2.43.0 From nobody Tue Oct 7 03:46:14 2025 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2FBD0279910; Mon, 14 Jul 2025 22:15:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=13.77.154.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752531355; cv=none; b=cMQ93vwodensz2lvDH7p95UUuLG3mzvuBKXkkGO0vzBFD7B/rWrZlb262afiOR+AjPvYnKdC/9Yn4q7uQ4CSydKBTMHpfR4fYhwgCQy/mehxnDN24wUxON/XXn6+DUu6wPO8Rd452UdFQFUSXVZYQIwSNxR6H9cpeOrKHf0MiBw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752531355; c=relaxed/simple; bh=nY7Uk25eXZ9CPEhq+dyPOCFpcECMFILdyIxZJrORP78=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kmxhw7d81fs/PLqBOk/iZwK80UD8xmDiSigi+0P5OTDwBgRZxrxHt2yQCxFbartMW7EE3YOysuLlISpba4mxry62UTLpx8keEENrvOOIO01tmEzgtm3yVY5HGzqBVrUCGQmzG3oCjrmEa/mJYCVcyC+N+7uAkWBHXWVKce+2tF4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com; spf=pass smtp.mailfrom=linux.microsoft.com; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b=jNBpM4Dr; arc=none smtp.client-ip=13.77.154.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b="jNBpM4Dr" Received: from romank-3650.corp.microsoft.com (unknown [131.107.160.188]) by linux.microsoft.com (Postfix) with ESMTPSA id 793BB201A4B1; Mon, 14 Jul 2025 15:15:50 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 793BB201A4B1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1752531350; bh=pT4iPwLX5Hd9PCSn3JAM0vAmXvwVMyakn8rD4WQrInY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jNBpM4DrcoEA9sgu9QlkBKL7tQixnDlRM+9ZWYVLN8uj2NB8NP02cFs9sBREnZSq1 k33hzO/oAfNtIZjkgbC+aeiEzS9A2C+RbPIJkl2SAzSyO6SSwMIRvNp+T0QJNx4Pa0 gzw+EFOsOoxR8s9xD/uLg7iGI340LV6VdL2sTsEI= From: Roman Kisel To: alok.a.tiwari@oracle.com, arnd@arndb.de, bp@alien8.de, corbet@lwn.net, dave.hansen@linux.intel.com, decui@microsoft.com, haiyangz@microsoft.com, hpa@zytor.com, kys@microsoft.com, mhklinux@outlook.com, mingo@redhat.com, rdunlap@infradead.org, tglx@linutronix.de, Tianyu.Lan@microsoft.com, wei.liu@kernel.org, linux-arch@vger.kernel.org, linux-coco@lists.linux.dev, linux-doc@vger.kernel.org, linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org, x86@kernel.org Cc: apais@microsoft.com, benhill@microsoft.com, bperkins@microsoft.com, sunilmut@microsoft.com Subject: [PATCH hyperv-next v4 13/16] Drivers: hv: Free msginfo when the buffer fails to decrypt Date: Mon, 14 Jul 2025 15:15:42 -0700 Message-ID: <20250714221545.5615-14-romank@linux.microsoft.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250714221545.5615-1-romank@linux.microsoft.com> References: <20250714221545.5615-1-romank@linux.microsoft.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The 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. Fixes: d4dccf353db80 ("Drivers: hv: vmbus: Mark vmbus ring buffer visible t= o host in Isolation VM") Reported-by: Michael Kelly Closes: https://lore.kernel.org/linux-hyperv/SN6PR02MB41573796F9787F67E0E97= 049D472A@SN6PR02MB4157.namprd02.prod.outlook.com Signed-off-by: Roman Kisel --- drivers/hv/channel.c | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c index 051eeba800f2..0eb300b940db 100644 --- a/drivers/hv/channel.c +++ b/drivers/hv/channel.c @@ -409,6 +409,25 @@ static int create_gpadl_header(enum hv_gpadl_type type= , void *kbuffer, return 0; } =20 +static void vmbus_free_channel_msginfo(struct vmbus_channel_msginfo *msgin= fo) +{ + unsigned long flags; + struct vmbus_channel_msginfo *submsginfo, *tmp; + + if (!msginfo) + return; + + 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_establish_gpadl - Establish a GPADL for a buffer or ringbuffer * @@ -428,7 +447,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 =3D NULL; - struct vmbus_channel_msginfo *submsginfo, *tmp; + struct vmbus_channel_msginfo *submsginfo; struct list_head *curr; u32 next_gpadl_handle; unsigned long flags; @@ -458,6 +477,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; } } @@ -531,15 +551,7 @@ static int __vmbus_establish_gpadl(struct vmbus_channe= l *channel, =20 =20 cleanup: - 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); =20 if (ret) { /* --=20 2.43.0 From nobody Tue Oct 7 03:46:14 2025 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 73AEC27A130; Mon, 14 Jul 2025 22:15:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=13.77.154.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752531355; cv=none; b=LlPHjKh08TcJ9zXsifsfkPMMS26eTNmHR6odyn89MddM7hWH0J0vHqL8nEu7w2s1jALevIngsZAYTb1MZy/7NrGnVoWNq8ofub/XoopSI/QStyrFlIM00VeMiDO2WWzgJxFDjhYM9S5hOhOXnsF+oHPajUgKzlr+c3F0yW3xJ5Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752531355; c=relaxed/simple; bh=KGEfFIT/ZT1Y8Q45i70mOCPYMVR5EaPhFKqVImq0+nY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=h4JRVMqb6ajQUVpPwLWKCy594fE3F0Pv/BOlnYkl2YkYa9pgXeBCV23ai9eSMyncVYHMj90GDcs2yD7cvENcZdKt8lvQe7Ed5BMBw1SPFwAyWnSBPFUf65n0ZYoXOHT2LZbAZNVyrn28CrtJfcAgM+w2j8F7e6yFQWhbnJJZHRI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com; spf=pass smtp.mailfrom=linux.microsoft.com; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b=TwaYS/qJ; arc=none smtp.client-ip=13.77.154.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b="TwaYS/qJ" Received: from romank-3650.corp.microsoft.com (unknown [131.107.160.188]) by linux.microsoft.com (Postfix) with ESMTPSA id BBB2E201A4DE; Mon, 14 Jul 2025 15:15:50 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com BBB2E201A4DE DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1752531350; bh=G4pTvTDF4giNUjjIl5YiEHQWjO7GRzLcFy/iGyAB/qE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TwaYS/qJ3A6+zBQJlUkshr+Mph+Ede9M52tuVRyyoNBAuLVSwaMirdx+5DA3UfQ4/ JRaKczOXB/6+uqrIJILOisHsOlQJVGA8uWu6cZva1Hg9jpMM76iYRulMbIROK3mn5U ly4m1zzhnLvV2tAoE851ZLr7fkcQhQIQ8J9yAJOA= From: Roman Kisel To: alok.a.tiwari@oracle.com, arnd@arndb.de, bp@alien8.de, corbet@lwn.net, dave.hansen@linux.intel.com, decui@microsoft.com, haiyangz@microsoft.com, hpa@zytor.com, kys@microsoft.com, mhklinux@outlook.com, mingo@redhat.com, rdunlap@infradead.org, tglx@linutronix.de, Tianyu.Lan@microsoft.com, wei.liu@kernel.org, linux-arch@vger.kernel.org, linux-coco@lists.linux.dev, linux-doc@vger.kernel.org, linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org, x86@kernel.org Cc: apais@microsoft.com, benhill@microsoft.com, bperkins@microsoft.com, sunilmut@microsoft.com Subject: [PATCH hyperv-next v4 14/16] Drivers: hv: Support confidential VMBus channels Date: Mon, 14 Jul 2025 15:15:43 -0700 Message-ID: <20250714221545.5615-15-romank@linux.microsoft.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250714221545.5615-1-romank@linux.microsoft.com> References: <20250714221545.5615-1-romank@linux.microsoft.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" To 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. Signed-off-by: Roman Kisel --- drivers/hv/channel_mgmt.c | 19 +++++++++++++++++++ drivers/hv/connection.c | 3 +++ 2 files changed, 22 insertions(+) diff --git a/drivers/hv/channel_mgmt.c b/drivers/hv/channel_mgmt.c index ca2fe10c110a..6ae44eab1626 100644 --- a/drivers/hv/channel_mgmt.c +++ b/drivers/hv/channel_mgmt.c @@ -1021,6 +1021,7 @@ static void vmbus_onoffer(struct vmbus_channel_messag= e_header *hdr) struct vmbus_channel_offer_channel *offer; struct vmbus_channel *oldchannel, *newchannel; size_t offer_sz; + bool co_ring_buffer, co_external_memory; =20 offer =3D (struct vmbus_channel_offer_channel *)hdr; =20 @@ -1033,6 +1034,22 @@ static void vmbus_onoffer(struct vmbus_channel_messa= ge_header *hdr) return; } =20 + co_ring_buffer =3D is_co_ring_buffer(offer); + co_external_memory =3D is_co_external_memory(offer); + if (!co_ring_buffer && co_external_memory) { + pr_err("Invalid offer relid=3D%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=3D%d: no support for confidential VMBus\n", + offer->child_relid); + atomic_dec(&vmbus_connection.offer_in_progress); + return; + } + } + oldchannel =3D find_primary_channel_by_offer(offer); =20 if (oldchannel !=3D NULL) { @@ -1111,6 +1128,8 @@ static void vmbus_onoffer(struct vmbus_channel_messag= e_header *hdr) pr_err("Unable to allocate channel object\n"); return; } + newchannel->co_ring_buffer =3D co_ring_buffer; + newchannel->co_external_memory =3D co_external_memory; =20 vmbus_setup_channel_state(newchannel, offer); =20 diff --git a/drivers/hv/connection.c b/drivers/hv/connection.c index be490c598785..eeb472019d69 100644 --- a/drivers/hv/connection.c +++ b/drivers/hv/connection.c @@ -105,6 +105,9 @@ int vmbus_negotiate_version(struct vmbus_channel_msginf= o *msginfo, u32 version) vmbus_connection.msg_conn_id =3D VMBUS_MESSAGE_CONNECTION_ID; } =20 + if (vmbus_is_confidential() && version >=3D VERSION_WIN10_V6_0) + msg->feature_flags =3D VMBUS_FEATURE_FLAG_CONFIDENTIAL_CHANNELS; + /* * shared_gpa_boundary is zero in non-SNP VMs, so it's safe to always * bitwise OR it --=20 2.43.0 From nobody Tue Oct 7 03:46:14 2025 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9712E279DB3; Mon, 14 Jul 2025 22:15:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=13.77.154.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752531355; cv=none; b=ZW4UiQUp5deKHXZY7foRRhOhkUPZZj2FO6OuXOpwOpYA3rnxiPqLCnyemJGD39CiGFI1D92gZKn4r05VwsvTGMa2F7apyDUMgB/4cIw01uuv53lTWJ9TWiXPq90s9A8g5zC/rJgneO/C3mfCbR6vI2dEPuQEgHkSaqmvZrAMCHw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752531355; c=relaxed/simple; bh=L0cEdguqIHIbUbQ6E6fS4wlEd7bciMBnSjOWK4P7KKk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JBem2szFVMOJfGu/aW8b5U4uzD7wWQU/nH7ka9X2FssWe40eAnFrEZRg2ZbRDt6evgUGGt98BwG6dnG3/02Y2wz0ovxtzoRzpMAehLkXA2SqHrbO4Kw3bIvaabY50ExKQ+jHay4jgL2LeCYt77mcEzdZAD8gct5e5IIaA5iC58s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com; spf=pass smtp.mailfrom=linux.microsoft.com; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b=p1J/Gi1I; arc=none smtp.client-ip=13.77.154.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b="p1J/Gi1I" Received: from romank-3650.corp.microsoft.com (unknown [131.107.160.188]) by linux.microsoft.com (Postfix) with ESMTPSA id 0A502201B1CD; Mon, 14 Jul 2025 15:15:51 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 0A502201B1CD DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1752531351; bh=W8J2zGpFifnp+H2iTJGi0AjmiMmoEjxacsnTVf87d8w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=p1J/Gi1IiywwemzamVJgSiFSarmYRsnA0lhfkUz2tcQ6qCnBETzKplaL9gRtwB5Z1 V6m+bU89LbA6d7fnsGpvzi9u6tJiwvg6gs9ecnIyZ2AR39dxCtB6qJU0nqo/7AT5+F Q9M/9MGY7HovikLqcYri45wal+BMfOfvgmJZgAwQ= From: Roman Kisel To: alok.a.tiwari@oracle.com, arnd@arndb.de, bp@alien8.de, corbet@lwn.net, dave.hansen@linux.intel.com, decui@microsoft.com, haiyangz@microsoft.com, hpa@zytor.com, kys@microsoft.com, mhklinux@outlook.com, mingo@redhat.com, rdunlap@infradead.org, tglx@linutronix.de, Tianyu.Lan@microsoft.com, wei.liu@kernel.org, linux-arch@vger.kernel.org, linux-coco@lists.linux.dev, linux-doc@vger.kernel.org, linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org, x86@kernel.org Cc: apais@microsoft.com, benhill@microsoft.com, bperkins@microsoft.com, sunilmut@microsoft.com Subject: [PATCH hyperv-next v4 15/16] Drivers: hv: Support establishing the confidential VMBus connection Date: Mon, 14 Jul 2025 15:15:44 -0700 Message-ID: <20250714221545.5615-16-romank@linux.microsoft.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250714221545.5615-1-romank@linux.microsoft.com> References: <20250714221545.5615-1-romank@linux.microsoft.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" To establish the confidential VMBus connection the CoCo VM guest first attempts to connect to the VMBus server run by the paravisor. If that fails, the guest falls back to the non-confidential VMBus. Implement that in the VMBus driver initialization. Signed-off-by: Roman Kisel --- drivers/hv/vmbus_drv.c | 189 ++++++++++++++++++++++++++++------------- 1 file changed, 130 insertions(+), 59 deletions(-) diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c index 13aca5abc7d8..53be3157e22c 100644 --- a/drivers/hv/vmbus_drv.c +++ b/drivers/hv/vmbus_drv.c @@ -1057,12 +1057,9 @@ static void vmbus_onmessage_work(struct work_struct = *work) kfree(ctx); } =20 -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 =3D (void *)data; - void *page_addr =3D hv_cpu->hyp_synic_message_page; - struct hv_message msg_copy, *msg =3D (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; =20 + if (!message_page_addr) + return; + msg =3D (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); } =20 +void vmbus_on_msg_dpc(unsigned long data) +{ + struct hv_per_cpu_context *hv_cpu =3D (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 vm= bus_channel *channel) #endif /* CONFIG_PM_SLEEP */ =20 /* - * 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; =20 - /* - * The event page can be directly checked to get the id of - * the channel that has the interrupt pending. - */ - void *page_addr =3D hv_cpu->hyp_synic_event_page; - union hv_synic_event_flags *event - =3D (union hv_synic_event_flags *)page_addr + - VMBUS_MESSAGE_SINT; + if (!event_page_addr) + return; + event =3D (union hv_synic_event_flags *)event_page_addr + VMBUS_MESSAGE_S= INT; =20 maxbits =3D HV_EVENT_FLAGS_COUNT; recv_int_page =3D event->flags; @@ -1255,6 +1262,11 @@ static void vmbus_chan_sched(struct hv_per_cpu_conte= xt *hv_cpu) if (unlikely(!recv_int_page)) return; =20 + /* + * Suggested-by: Michael Kelley + * 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_cont= ext *hv_cpu) } } =20 -static void vmbus_isr(void) +static void vmbus_message_sched(struct hv_per_cpu_context *hv_cpu, void *m= essage_page_addr) { - struct hv_per_cpu_context *hv_cpu - =3D this_cpu_ptr(hv_context.cpu_context); - void *page_addr; struct hv_message *msg; =20 - vmbus_chan_sched(hv_cpu); - - page_addr =3D hv_cpu->hyp_synic_message_page; - msg =3D (struct hv_message *)page_addr + VMBUS_MESSAGE_SINT; + if (!message_page_addr) + return; + msg =3D (struct hv_message *)message_page_addr + VMBUS_MESSAGE_SINT; =20 /* Check if there are actual msgs to be processed */ if (msg->header.message_type !=3D HVMSG_NONE) { if (msg->header.message_type =3D=3D 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 + =3D 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); =20 add_interrupt_randomness(vmbus_interrupt); } @@ -1355,6 +1376,59 @@ static void vmbus_percpu_work(struct work_struct *wo= rk) hv_synic_init(cpu); } =20 +static int vmbus_alloc_synic_and_connect(void) +{ + int ret, cpu; + struct work_struct __percpu *works; + int hyperv_cpuhp_online; + + ret =3D hv_synic_alloc(); + if (ret < 0) + goto err_alloc; + + works =3D alloc_percpu(struct work_struct); + if (!works) { + ret =3D -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 =3D 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 =3D 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 =3D ret; + + ret =3D 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 *wor= k) */ static int vmbus_bus_init(void) { - int ret, cpu; - struct work_struct __percpu *works; + int ret; =20 ret =3D hv_init(); if (ret !=3D 0) { @@ -1401,41 +1474,42 @@ static int vmbus_bus_init(void) } } =20 - ret =3D hv_synic_alloc(); - if (ret) - goto err_alloc; - - works =3D alloc_percpu(struct work_struct); - if (!works) { - ret =3D -ENOMEM; - goto err_alloc; - } - /* - * Initialize the per-cpu interrupt state and stimer state. - * Then connect to the host. + * Attempt to establish the confidential VMBus connection first if this V= M is + * a hardware confidential VM, and the paravisor is present. + * + * All scenarios here are: + * 1. No paravisor, + * 2. Paravisor without VMBus relay, no hardware isolation, + * 3. Paravisor without VMBus relay, with hardware isolation, + * 4. Paravisor with VMBus relay, no hardware isolation, + * 5. Paravisor with VMBus relay, with hardware isolation. + * + * In the cloud, scenarios 1, 4, 5 are most common, and outside the cloud, + * scenario 1 should be the most common at the moment. Detecting of the C= onfidential + * VMBus support below takes that into account running `vmbus_alloc_synic= _and_connect()` + * only once (barring any faults not related to VMBus) in these cases. Th= at is true + * for the scenario 2, too, albeit it might be not as feature-rich as 1, = 4, 5. + * + * However, the code will be doing much more work in scenario 3 where it = will have to + * first initialize lots of structures for every CPU only to likely tear = them down later + * and start again, now without attempting to use Confidential VMBus, thu= s taking a + * performance hit. Such systems are rather uncomoon today, don't support= more than + * ~300 CPUs, and are rarely used with many dozens of CPUs. As the time g= oes on, that + * will be even less common. Hence, the preference is to not specialize t= he code for + * that scenario. */ - cpus_read_lock(); - for_each_online_cpu(cpu) { - struct work_struct *work =3D per_cpu_ptr(works, cpu); + ret =3D -ENODEV; + if (ms_hyperv.paravisor_present && (hv_isolation_type_tdx() || hv_isolati= on_type_snp())) { + is_confidential =3D true; + ret =3D vmbus_alloc_synic_and_connect(); + is_confidential =3D !ret; =20 - INIT_WORK(work, vmbus_percpu_work); - schedule_work_on(cpu, work); + pr_info("VMBus is confidential: %d\n", is_confidential); } =20 - for_each_online_cpu(cpu) - flush_work(per_cpu_ptr(works, cpu)); - - /* Register the callbacks for possible CPU online/offline'ing */ - ret =3D 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 =3D ret; - - ret =3D vmbus_connect(); + if (!is_confidential) + ret =3D vmbus_alloc_synic_and_connect(); if (ret) goto err_connect; =20 @@ -1451,9 +1525,6 @@ static int vmbus_bus_init(void) return 0; =20 err_connect: - cpuhp_remove_state(hyperv_cpuhp_online); -err_alloc: - hv_synic_free(); if (vmbus_irq =3D=3D -1) { hv_remove_vmbus_handler(); } else { --=20 2.43.0 From nobody Tue Oct 7 03:46:14 2025 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9A39427AC2A; Mon, 14 Jul 2025 22:15:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=13.77.154.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752531355; cv=none; b=tsF7qMJlthFbeYZjnAJHr8nBbvxVWcuUvO1ZEzHHGH+iywRPE7qOplds8Hk1e+XvEKgmK4PO5fVqbk8bASuG+rX3ttbV9EXZrw38Ora1y9FnmTl2NeuysVef4QGjZuHYSiLw/tLnzFUQp2tmvUIy58x3QwQ1fz++h5lMFbBcmhY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752531355; c=relaxed/simple; bh=qu5wrCRGckFddgOVao5M+PQvlTFUez7DHz4TBUqUopY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=M0k41xp8jP/MLTFtxRPtN/OGPyf5eqGuYsmX5WQQ7TMAHR4CEuWQLy0rFDK9e5qnRGCEhbjmaWFNrGMUyT2On/hz8qKcbJf0WSFUHzBeN7jmHe62CsVImc65RaUnXTmuuPVIUVneaucwNMN2BVhqmzbVUvi+2cwBgTHZXT3rPRs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com; spf=pass smtp.mailfrom=linux.microsoft.com; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b=e3/IvBo+; arc=none smtp.client-ip=13.77.154.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b="e3/IvBo+" Received: from romank-3650.corp.microsoft.com (unknown [131.107.160.188]) by linux.microsoft.com (Postfix) with ESMTPSA id 4BB0E201B1DA; Mon, 14 Jul 2025 15:15:51 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 4BB0E201B1DA DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1752531351; bh=5NILQvH5aX9tvrOJMwj2GLYW/SEBrWgpZjSjwN/upug=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=e3/IvBo+FS2asdg6lPj8x9+n0F7es6nrk0eOJEmD4n/TOXw9A/m2CG03AS7J4XWoD zZW7fqoRLaENo+goNyOOJuf6yus3qNHqg0cPvCN24VYiKXmEWY9EDx6jEGbNaPHZEm JpPdjGniblXqEnyQCjGTsLH7TlUtQcgpIbpNYEAA= From: Roman Kisel To: alok.a.tiwari@oracle.com, arnd@arndb.de, bp@alien8.de, corbet@lwn.net, dave.hansen@linux.intel.com, decui@microsoft.com, haiyangz@microsoft.com, hpa@zytor.com, kys@microsoft.com, mhklinux@outlook.com, mingo@redhat.com, rdunlap@infradead.org, tglx@linutronix.de, Tianyu.Lan@microsoft.com, wei.liu@kernel.org, linux-arch@vger.kernel.org, linux-coco@lists.linux.dev, linux-doc@vger.kernel.org, linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org, x86@kernel.org Cc: apais@microsoft.com, benhill@microsoft.com, bperkins@microsoft.com, sunilmut@microsoft.com Subject: [PATCH hyperv-next v4 16/16] Drivers: hv: Set the default VMBus version to 6.0 Date: Mon, 14 Jul 2025 15:15:45 -0700 Message-ID: <20250714221545.5615-17-romank@linux.microsoft.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250714221545.5615-1-romank@linux.microsoft.com> References: <20250714221545.5615-1-romank@linux.microsoft.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The 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. Signed-off-by: Roman Kisel --- drivers/hv/connection.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/hv/connection.c b/drivers/hv/connection.c index eeb472019d69..7cd43463f969 100644 --- a/drivers/hv/connection.c +++ b/drivers/hv/connection.c @@ -51,6 +51,7 @@ EXPORT_SYMBOL_GPL(vmbus_proto_version); * Linux guests and are not listed. */ static __u32 vmbus_versions[] =3D { + VERSION_WIN10_V6_0, VERSION_WIN10_V5_3, VERSION_WIN10_V5_2, VERSION_WIN10_V5_1, @@ -65,7 +66,7 @@ static __u32 vmbus_versions[] =3D { * Maximal VMBus protocol version guests can negotiate. Useful to cap the * VMBus version for testing and debugging purpose. */ -static uint max_version =3D VERSION_WIN10_V5_3; +static uint max_version =3D VERSION_WIN10_V6_0; =20 module_param(max_version, uint, S_IRUGO); MODULE_PARM_DESC(max_version, --=20 2.43.0