diff mbox series

[RFC,01/12] Drivers: hv: vmbus: Drop unsupported VMBus devices earlier

Message ID 20240604050940.859909-2-mhklinux@outlook.com (mailing list archive)
State Not Applicable
Headers show
Series Hyper-V guests use Linux IRQs for channel interrupts | expand

Commit Message

Michael Kelley June 4, 2024, 5:09 a.m. UTC
From: Michael Kelley <mhklinux@outlook.com>

Because Hyper-V doesn't know ahead-of-time what operating system will be
running in a guest VM, it may offer to Linux guests VMBus devices that are
intended for use only in Windows guests. Currently in Linux, VMBus
channels are created for these devices, and they are processed by
vmbus_device_register(). While nothing further happens because no matching
driver is found, the channel continues to exist.

To avoid having the spurious channel, drop such devices immediately in
vmbus_onoffer(), based on identifying the device in the
vmbus_unsupported_devs table. If Hyper-V should issue a rescind request
for the device, no matching channel will be found and the rescind will
also be ignored.

Since unsupported devices are dropped early, the check for unsupported
devices in hv_get_dev_type() is redundant. Remove it.

Signed-off-by: Michael Kelley <mhklinux@outlook.com>
---
 drivers/hv/channel_mgmt.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

Comments

Wei Liu June 24, 2024, 7:11 a.m. UTC | #1
On Mon, Jun 03, 2024 at 10:09:29PM -0700, mhkelley58@gmail.com wrote:
> From: Michael Kelley <mhklinux@outlook.com>
> 
> Because Hyper-V doesn't know ahead-of-time what operating system will be
> running in a guest VM, it may offer to Linux guests VMBus devices that are
> intended for use only in Windows guests. Currently in Linux, VMBus
> channels are created for these devices, and they are processed by
> vmbus_device_register(). While nothing further happens because no matching
> driver is found, the channel continues to exist.
> 
> To avoid having the spurious channel, drop such devices immediately in
> vmbus_onoffer(), based on identifying the device in the
> vmbus_unsupported_devs table. If Hyper-V should issue a rescind request
> for the device, no matching channel will be found and the rescind will
> also be ignored.
> 
> Since unsupported devices are dropped early, the check for unsupported
> devices in hv_get_dev_type() is redundant. Remove it.
> 
> Signed-off-by: Michael Kelley <mhklinux@outlook.com>

Acked-by: Wei Liu <wei.liu@kernel.org>
diff mbox series

Patch

diff --git a/drivers/hv/channel_mgmt.c b/drivers/hv/channel_mgmt.c
index 3c6011a48dab..a216a0aede73 100644
--- a/drivers/hv/channel_mgmt.c
+++ b/drivers/hv/channel_mgmt.c
@@ -203,7 +203,7 @@  static u16 hv_get_dev_type(const struct vmbus_channel *channel)
 	const guid_t *guid = &channel->offermsg.offer.if_type;
 	u16 i;
 
-	if (is_hvsock_channel(channel) || is_unsupported_vmbus_devs(guid))
+	if (is_hvsock_channel(channel))
 		return HV_UNKNOWN;
 
 	for (i = HV_IDE; i < HV_UNKNOWN; i++) {
@@ -1036,6 +1036,16 @@  static void vmbus_onoffer(struct vmbus_channel_message_header *hdr)
 
 	trace_vmbus_onoffer(offer);
 
+	/*
+	 * Hyper-V may offer pseudo-devices with functionality intended for
+	 * Windows guests. Silently ignore them. There's no value in
+	 * cluttering dmesg with error messages.
+	 */
+	if (is_unsupported_vmbus_devs(&offer->offer.if_type)) {
+		atomic_dec(&vmbus_connection.offer_in_progress);
+		return;
+	}
+
 	if (!vmbus_is_valid_offer(offer)) {
 		pr_err_ratelimited("Invalid offer %d from the host supporting isolation\n",
 				   offer->child_relid);