Skip to contentSkip to conversation

uio_hv_generic: Set event for all channels on the device

PATCH Superseded [email protected] 3 participants 3 messages Feb 27, 2025 – Feb 28, 2025

Subsystems (3)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 uio_hv_generic: Set event for all channels on the device

From: Long Li <[email protected]>

Hyper-V may offer a non latency sensitive device with subchannels without monitor bit enabled. The decision is entirely on the Hyper-V host not configurable within guest.

When a device has subchannels, also signal events for the subchannel if its monitor bit is disabled.

---
 drivers/uio/uio_hv_generic.c | 30 ++++++++++++++++++++++++------
 1 file changed, 24 insertions(+), 6 deletions(-)
drivers/uio/uio_hv_generic.c +24 -6
index 3976360d0096..8b6df598a728 100644
@@ -65,6 +65,16 @@ struct hv_uio_private_data {
 	char	send_name[32];
 };
 
+static void set_event(struct vmbus_channel *channel, s32 irq_state)
+{
+	channel->inbound.ring_buffer->interrupt_mask = !irq_state;
+	if (!channel->offermsg.monitor_allocated && irq_state) {
+		/* MB is needed for host to see the interrupt mask first */
+		virt_mb();
+		vmbus_setevent(channel);
+	}
+}
+
 /*
  * This is the irqcontrol callback to be registered to uio_info.
  * It can be used to disable/enable interrupt from user space processes.
@@ -79,12 +89,13 @@ hv_uio_irqcontrol(struct uio_info *info, s32 irq_state)
 {
 	struct hv_uio_private_data *pdata = info->priv;
 	struct hv_device *dev = pdata->device;
+	struct vmbus_channel *primary, *sc;
 
-	dev->channel->inbound.ring_buffer->interrupt_mask = !irq_state;
-	virt_mb();
+	primary = dev->channel;
+	set_event(primary, irq_state);
 
-	if (!dev->channel->offermsg.monitor_allocated && irq_state)
-		vmbus_setevent(dev->channel);
+	list_for_each_entry(sc, &primary->sc_list, sc_list)
+		set_event(sc, irq_state);
 
 	return 0;
 }
@@ -95,12 +106,19 @@ hv_uio_irqcontrol(struct uio_info *info, s32 irq_state)
 static void hv_uio_channel_cb(void *context)
 {
 	struct vmbus_channel *chan = context;
-	struct hv_device *hv_dev = chan->device_obj;
-	struct hv_uio_private_data *pdata = hv_get_drvdata(hv_dev);
+	struct hv_device *hv_dev;
+	struct hv_uio_private_data *pdata;
 
 	chan->inbound.ring_buffer->interrupt_mask = 1;
 	virt_mb();
 
+	/*
+	 * The callback may come from a subchannel, in which case look
+	 * for the hv device in the primary channel
+	 */
+	hv_dev = chan->primary_channel ?
+		 chan->primary_channel->device_obj : chan->device_obj;
+	pdata = hv_get_drvdata(hv_dev);
 	uio_event_notify(&pdata->info);
 }
 
Signature · 1 line
2.34.1
#1 lore raw

From: [email protected] <[email protected]> Sent: Wednesday, February 26, 2025 4:46 PM

Quoted 18 lines

Hyper-V may offer a non latency sensitive device with subchannels without monitor bit enabled. The decision is entirely on the Hyper-V host not configurable within guest.

When a device has subchannels, also signal events for the subchannel if its monitor bit is disabled.

---
 drivers/uio/uio_hv_generic.c | 30 ++++++++++++++++++++++++------
 1 file changed, 24 insertions(+), 6 deletions(-)
drivers/uio/uio_hv_generic.c +0 -0
index 3976360d0096..8b6df598a728 100644

drivers/uio/uio_hv_generic.c struct hv_uio_private_data { · line 74

Quoted 10 lines
drivers/uio/uio_hv_generic.c +7 -0
@@ -65,6 +65,16 @@ struct hv_uio_private_data {
 	char	send_name[32];
 };
 
+static void set_event(struct vmbus_channel *channel, s32 irq_state)
+{
+	channel->inbound.ring_buffer->interrupt_mask = !irq_state;
+	if (!channel->offermsg.monitor_allocated && irq_state) {
+		/* MB is needed for host to see the interrupt mask first */
+		virt_mb();
+		vmbus_setevent(channel);

A minor point, but vmbus_setevent() checks the "monitor_allocated" flag, and if not set, then calls vmbus_set_event(). Since monitor_allocated() is already checked here, couldn't vmbus_set_event() be called directly? The existing code calls vmbus_setevent() so keeping vmbus_setevent() is less of a change, but it is still doing a redundant check.

Quoted 11 lines
drivers/uio/uio_hv_generic.c +4 -0
+	}
+}
+
 /*
  * This is the irqcontrol callback to be registered to uio_info.
  * It can be used to disable/enable interrupt from user space processes.
@@ -79,12 +89,13 @@ hv_uio_irqcontrol(struct uio_info *info, s32 irq_state)
 {
 	struct hv_uio_private_data *pdata = info->priv;
 	struct hv_device *dev = pdata->device;
+	struct vmbus_channel *primary, *sc;

drivers/uio/uio_hv_generic.c hv_uio_irqcontrol(struct uio_info *info, s32 irq_state) · line 98

Quoted 10 lines
drivers/uio/uio_hv_generic.c +4 -4
 
-	dev->channel->inbound.ring_buffer->interrupt_mask = !irq_state;
-	virt_mb();
+	primary = dev->channel;
+	set_event(primary, irq_state);
 
-	if (!dev->channel->offermsg.monitor_allocated && irq_state)
-		vmbus_setevent(dev->channel);
+	list_for_each_entry(sc, &primary->sc_list, sc_list)
+		set_event(sc, irq_state);

Walking the sc_list usually requires holding vmbus_connection.channel_mutex. Is there a reason it's safe to walk the list here without the mutex?

Quoted 11 lines
drivers/uio/uio_hv_generic.c +2 -2
 	return 0;
 }
@@ -95,12 +106,19 @@ hv_uio_irqcontrol(struct uio_info *info, s32 irq_state)
 static void hv_uio_channel_cb(void *context)
 {
 	struct vmbus_channel *chan = context;
-	struct hv_device *hv_dev = chan->device_obj;
-	struct hv_uio_private_data *pdata = hv_get_drvdata(hv_dev);
+	struct hv_device *hv_dev;
+	struct hv_uio_private_data *pdata;

drivers/uio/uio_hv_generic.c hv_uio_irqcontrol(struct uio_info *info, s32 irq_state) · line 120

Quoted 10 lines
drivers/uio/uio_hv_generic.c +6 -0
 
 	chan->inbound.ring_buffer->interrupt_mask = 1;
 	virt_mb();
 
+	/*
+	 * The callback may come from a subchannel, in which case look
+	 * for the hv device in the primary channel
+	 */
+	hv_dev = chan->primary_channel ?
+		 chan->primary_channel->device_obj : chan->device_obj;

This certainly looks correct and necessary. But how did this work in the past? Wouldn't DPDK running on a synthetic NIC have gotten callbacks on a subchannel? I'm just trying to understand whether this a bug fix, or if not, what new scenario requires this change. I'm not understanding how this change is related to the commit message.

Michael

Quoted 7 lines
drivers/uio/uio_hv_generic.c +1 -1
+	pdata = hv_get_drvdata(hv_dev);
 	uio_event_notify(&pdata->info);
 }
 
--

2.34.1

#2 lore raw
Quoted 24 lines

From: [email protected] <[email protected]> Sent:
Wednesday, February 26, 2025 4:46 PM

Quoted 8 lines

Hyper-V may offer a non latency sensitive device with subchannels without monitor bit enabled. The decision is entirely on the Hyper-V host not configurable within guest.

When a device has subchannels, also signal events for the subchannel if its monitor bit is disabled.

Quoted 7 lines
---
 drivers/uio/uio_hv_generic.c | 30 ++++++++++++++++++++++++------
 1 file changed, 24 insertions(+), 6 deletions(-)
(quoted diff) +0 -0

b/drivers/uio/uio_hv_generic.c index 3976360d0096..8b6df598a728

100644

Quoted 6 lines
drivers/uio/uio_hv_generic.c +0 -0
@@ -65,6 +65,16 @@ struct hv_uio_private_data {
 	char	send_name[32];
 };
 
Quoted 12 lines

drivers/uio/uio_hv_generic.c struct hv_uio_private_data { · line 74

Quoted 6 lines
drivers/uio/uio_hv_generic.c +6 -0
+static void set_event(struct vmbus_channel *channel, s32 irq_state) {
+	channel->inbound.ring_buffer->interrupt_mask = !irq_state;
+	if (!channel->offermsg.monitor_allocated && irq_state) {
+		/* MB is needed for host to see the interrupt mask first */
+		virt_mb();
+		vmbus_setevent(channel);

A minor point, but vmbus_setevent() checks the "monitor_allocated" flag, and if not set, then calls vmbus_set_event(). Since monitor_allocated() is already checked here, couldn't vmbus_set_event() be called directly? The existing code calls vmbus_setevent() so keeping vmbus_setevent() is less of a change, but it is still doing a redundant check.

Will change it to vmbus_set_event().

Quoted 18 lines
Quoted 18 lines
drivers/uio/uio_hv_generic.c +6 -2
+	}
+}
+
 /*
  * This is the irqcontrol callback to be registered to uio_info.
  * It can be used to disable/enable interrupt from user space processes.
@@ -79,12 +89,13 @@ hv_uio_irqcontrol(struct uio_info *info, s32
 irq_state)  {
 	struct hv_uio_private_data *pdata = info->priv;
 	struct hv_device *dev = pdata->device;
+	struct vmbus_channel *primary, *sc;
 
-	dev->channel->inbound.ring_buffer->interrupt_mask = !irq_state;
-	virt_mb();
+	primary = dev->channel;
+	set_event(primary, irq_state);
 
Quoted 8 lines

drivers/uio/uio_hv_generic.c hv_uio_irqcontrol(struct uio_info *info, s32 irq_state) · line 98

Quoted 4 lines
drivers/uio/uio_hv_generic.c +2 -2
-	if (!dev->channel->offermsg.monitor_allocated && irq_state)
-		vmbus_setevent(dev->channel);
+	list_for_each_entry(sc, &primary->sc_list, sc_list)
+		set_event(sc, irq_state);

Walking the sc_list usually requires holding vmbus_connection.channel_mutex.
Is there a reason it's safe to walk the list here without the mutex?

You are right, we need a lock here. Will be adding it.

Quoted 28 lines
Quoted 11 lines
drivers/uio/uio_hv_generic.c +2 -2
 	return 0;
 }
@@ -95,12 +106,19 @@ hv_uio_irqcontrol(struct uio_info *info, s32
 irq_state)  static void hv_uio_channel_cb(void *context)  {
 	struct vmbus_channel *chan = context;
-	struct hv_device *hv_dev = chan->device_obj;
-	struct hv_uio_private_data *pdata = hv_get_drvdata(hv_dev);
+	struct hv_device *hv_dev;
+	struct hv_uio_private_data *pdata;

drivers/uio/uio_hv_generic.c hv_uio_irqcontrol(struct uio_info *info, s32 · line 119

Quoted 10 lines
drivers/uio/uio_hv_generic.c +6 -0
 
 	chan->inbound.ring_buffer->interrupt_mask = 1;
 	virt_mb();
 
+	/*
+	 * The callback may come from a subchannel, in which case look
+	 * for the hv device in the primary channel
+	 */
+	hv_dev = chan->primary_channel ?
+		 chan->primary_channel->device_obj : chan->device_obj;

This certainly looks correct and necessary. But how did this work in the past? Wouldn't DPDK running on a synthetic NIC have gotten callbacks on a subchannel? I'm just trying to understand whether this a bug fix, or if not, what new scenario requires this change. I'm not understanding how this change is related to the commit message.

Quoted 1 line

Michael

In the past, host always offers sub channels with monitor bit enabled, and the interrupt mask on the channel is always set so we never got callbacks.

This has changed in that the host may offer channels without monitoring. This change also requires patches at DPDK netvsc driver to work on unmonitored channels. I think it's a new scenario that requires changes at both ends.

Long

Quoted 8 lines
Quoted 8 lines
drivers/uio/uio_hv_generic.c +1 -1
+	pdata = hv_get_drvdata(hv_dev);
 	uio_event_notify(&pdata->info);
 }
 
--

2.34.1