* [Patch v2] uio_hv_generic: Set event for all channels on the device
@ 2025-02-28 22:14 longli
2025-03-01 0:19 ` Michael Kelley
2025-03-09 5:47 ` Saurabh Singh Sengar
0 siblings, 2 replies; 6+ messages in thread
From: longli @ 2025-02-28 22:14 UTC (permalink / raw)
To: K. Y. Srinivasan, Haiyang Zhang, Wei Liu, Dexuan Cui,
Greg Kroah-Hartman, linux-hyperv, linux-kernel
Cc: Long Li
From: Long Li <longli@microsoft.com>
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.
Signed-off-by: Long Li <longli@microsoft.com>
---
Change log
v2: Use vmbus_set_event() to avoid additional check on monitored bit
Lock vmbus_connection.channel_mutex when going through subchannels
drivers/uio/uio_hv_generic.c | 32 ++++++++++++++++++++++++++------
1 file changed, 26 insertions(+), 6 deletions(-)
diff --git a/drivers/uio/uio_hv_generic.c b/drivers/uio/uio_hv_generic.c
index 3976360d0096..45be2f8baade 100644
--- a/drivers/uio/uio_hv_generic.c
+++ b/drivers/uio/uio_hv_generic.c
@@ -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_set_event(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,15 @@ 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);
+ mutex_lock(&vmbus_connection.channel_mutex);
+ list_for_each_entry(sc, &primary->sc_list, sc_list)
+ set_event(sc, irq_state);
+ mutex_unlock(&vmbus_connection.channel_mutex);
return 0;
}
@@ -95,12 +108,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);
}
--
2.34.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* RE: [Patch v2] uio_hv_generic: Set event for all channels on the device
2025-02-28 22:14 [Patch v2] uio_hv_generic: Set event for all channels on the device longli
@ 2025-03-01 0:19 ` Michael Kelley
2025-03-09 5:47 ` Saurabh Singh Sengar
1 sibling, 0 replies; 6+ messages in thread
From: Michael Kelley @ 2025-03-01 0:19 UTC (permalink / raw)
To: longli@linuxonhyperv.com, K. Y. Srinivasan, Haiyang Zhang,
Wei Liu, Dexuan Cui, Greg Kroah-Hartman,
linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Long Li
From: longli@linuxonhyperv.com <longli@linuxonhyperv.com> Sent: Friday, February 28, 2025 2:14 PM
>
> 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.
>
> Signed-off-by: Long Li <longli@microsoft.com>
> ---
> Change log
> v2: Use vmbus_set_event() to avoid additional check on monitored bit
> Lock vmbus_connection.channel_mutex when going through subchannels
>
> drivers/uio/uio_hv_generic.c | 32 ++++++++++++++++++++++++++------
> 1 file changed, 26 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/uio/uio_hv_generic.c b/drivers/uio/uio_hv_generic.c
> index 3976360d0096..45be2f8baade 100644
> --- a/drivers/uio/uio_hv_generic.c
> +++ b/drivers/uio/uio_hv_generic.c
> @@ -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_set_event(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,15 @@ 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);
> + mutex_lock(&vmbus_connection.channel_mutex);
> + list_for_each_entry(sc, &primary->sc_list, sc_list)
> + set_event(sc, irq_state);
> + mutex_unlock(&vmbus_connection.channel_mutex);
>
> return 0;
> }
> @@ -95,12 +108,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);
> }
>
Reviewed-by: Michael Kelley <mhklinux@outlook.com>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Patch v2] uio_hv_generic: Set event for all channels on the device
2025-02-28 22:14 [Patch v2] uio_hv_generic: Set event for all channels on the device longli
2025-03-01 0:19 ` Michael Kelley
@ 2025-03-09 5:47 ` Saurabh Singh Sengar
2025-03-10 17:16 ` Long Li
1 sibling, 1 reply; 6+ messages in thread
From: Saurabh Singh Sengar @ 2025-03-09 5:47 UTC (permalink / raw)
To: longli
Cc: K. Y. Srinivasan, Haiyang Zhang, Wei Liu, Dexuan Cui,
Greg Kroah-Hartman, linux-hyperv, linux-kernel, Long Li
On Fri, Feb 28, 2025 at 02:14:14PM -0800, longli@linuxonhyperv.com wrote:
> From: Long Li <longli@microsoft.com>
>
> 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.
>
> Signed-off-by: Long Li <longli@microsoft.com>
> ---
> Change log
> v2: Use vmbus_set_event() to avoid additional check on monitored bit
> Lock vmbus_connection.channel_mutex when going through subchannels
>
> drivers/uio/uio_hv_generic.c | 32 ++++++++++++++++++++++++++------
> 1 file changed, 26 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/uio/uio_hv_generic.c b/drivers/uio/uio_hv_generic.c
> index 3976360d0096..45be2f8baade 100644
> --- a/drivers/uio/uio_hv_generic.c
> +++ b/drivers/uio/uio_hv_generic.c
> @@ -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();
Why is memory barrier not getting called for 'faster' channels ?
- Saurabh
^ permalink raw reply [flat|nested] 6+ messages in thread
* RE: [Patch v2] uio_hv_generic: Set event for all channels on the device
2025-03-09 5:47 ` Saurabh Singh Sengar
@ 2025-03-10 17:16 ` Long Li
2025-03-10 17:31 ` Saurabh Singh Sengar
0 siblings, 1 reply; 6+ messages in thread
From: Long Li @ 2025-03-10 17:16 UTC (permalink / raw)
To: Saurabh Singh Sengar, longli@linuxonhyperv.com
Cc: KY Srinivasan, Haiyang Zhang, Wei Liu, Dexuan Cui,
Greg Kroah-Hartman, linux-hyperv@vger.kernel.org,
linux-kernel@vger.kernel.org
> Subject: Re: [Patch v2] uio_hv_generic: Set event for all channels on the device
>
> On Fri, Feb 28, 2025 at 02:14:14PM -0800, longli@linuxonhyperv.com wrote:
> > From: Long Li <longli@microsoft.com>
> >
> > 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.
> >
> > Signed-off-by: Long Li <longli@microsoft.com>
> > ---
> > Change log
> > v2: Use vmbus_set_event() to avoid additional check on monitored bit
> > Lock vmbus_connection.channel_mutex when going through subchannels
> >
> > drivers/uio/uio_hv_generic.c | 32 ++++++++++++++++++++++++++------
> > 1 file changed, 26 insertions(+), 6 deletions(-)
> >
> > diff --git a/drivers/uio/uio_hv_generic.c
> > b/drivers/uio/uio_hv_generic.c index 3976360d0096..45be2f8baade 100644
> > --- a/drivers/uio/uio_hv_generic.c
> > +++ b/drivers/uio/uio_hv_generic.c
> > @@ -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();
>
> Why is memory barrier not getting called for 'faster' channels ?
>
> - Saurabh
No, the memory barrier is not needed. Even with a barrier, There is no guarantee that all pending IRQs are flushed when hv_uio_irqcontrol() returns. If user-mode depends on this guarantee, that user-mode has a bug. This barrier adds unnecessary costs when walking through subchannels.
Long
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Patch v2] uio_hv_generic: Set event for all channels on the device
2025-03-10 17:16 ` Long Li
@ 2025-03-10 17:31 ` Saurabh Singh Sengar
2025-03-10 18:57 ` Long Li
0 siblings, 1 reply; 6+ messages in thread
From: Saurabh Singh Sengar @ 2025-03-10 17:31 UTC (permalink / raw)
To: Long Li
Cc: longli@linuxonhyperv.com, KY Srinivasan, Haiyang Zhang, Wei Liu,
Dexuan Cui, Greg Kroah-Hartman, linux-hyperv@vger.kernel.org,
linux-kernel@vger.kernel.org
On Mon, Mar 10, 2025 at 05:16:15PM +0000, Long Li wrote:
> > Subject: Re: [Patch v2] uio_hv_generic: Set event for all channels on the device
> >
> > On Fri, Feb 28, 2025 at 02:14:14PM -0800, longli@linuxonhyperv.com wrote:
> > > From: Long Li <longli@microsoft.com>
> > >
> > > 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.
> > >
> > > Signed-off-by: Long Li <longli@microsoft.com>
> > > ---
> > > Change log
> > > v2: Use vmbus_set_event() to avoid additional check on monitored bit
> > > Lock vmbus_connection.channel_mutex when going through subchannels
> > >
> > > drivers/uio/uio_hv_generic.c | 32 ++++++++++++++++++++++++++------
> > > 1 file changed, 26 insertions(+), 6 deletions(-)
> > >
> > > diff --git a/drivers/uio/uio_hv_generic.c
> > > b/drivers/uio/uio_hv_generic.c index 3976360d0096..45be2f8baade 100644
> > > --- a/drivers/uio/uio_hv_generic.c
> > > +++ b/drivers/uio/uio_hv_generic.c
> > > @@ -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();
> >
> > Why is memory barrier not getting called for 'faster' channels ?
> >
> > - Saurabh
>
> No, the memory barrier is not needed. Even with a barrier, There is no guarantee that all pending IRQs are flushed when hv_uio_irqcontrol() returns. If user-mode depends on this guarantee, that user-mode has a bug. This barrier adds unnecessary costs when walking through subchannels.
>
Thanks for the details. However I didn't understand if memory barrier is not
required why have it only for 'slow' devices (ie !monitor_allocated) ?
This change also removes the MB for primary channel (if it supports moitor bits),
if this is intentional, we should call out this in commit message.
Regards,
Saurabh
^ permalink raw reply [flat|nested] 6+ messages in thread
* RE: [Patch v2] uio_hv_generic: Set event for all channels on the device
2025-03-10 17:31 ` Saurabh Singh Sengar
@ 2025-03-10 18:57 ` Long Li
0 siblings, 0 replies; 6+ messages in thread
From: Long Li @ 2025-03-10 18:57 UTC (permalink / raw)
To: Saurabh Singh Sengar
Cc: longli@linuxonhyperv.com, KY Srinivasan, Haiyang Zhang, Wei Liu,
Dexuan Cui, Greg Kroah-Hartman, linux-hyperv@vger.kernel.org,
linux-kernel@vger.kernel.org
> -----Original Message-----
> From: Saurabh Singh Sengar <ssengar@linux.microsoft.com>
> Sent: Monday, March 10, 2025 10:31 AM
> To: Long Li <longli@microsoft.com>
> Cc: longli@linuxonhyperv.com; KY Srinivasan <kys@microsoft.com>; Haiyang
> Zhang <haiyangz@microsoft.com>; Wei Liu <wei.liu@kernel.org>; Dexuan Cui
> <decui@microsoft.com>; Greg Kroah-Hartman <gregkh@linuxfoundation.org>;
> linux-hyperv@vger.kernel.org; linux-kernel@vger.kernel.org
> Subject: Re: [Patch v2] uio_hv_generic: Set event for all channels on the device
>
> On Mon, Mar 10, 2025 at 05:16:15PM +0000, Long Li wrote:
> > > Subject: Re: [Patch v2] uio_hv_generic: Set event for all channels
> > > on the device
> > >
> > > On Fri, Feb 28, 2025 at 02:14:14PM -0800, longli@linuxonhyperv.com wrote:
> > > > From: Long Li <longli@microsoft.com>
> > > >
> > > > 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.
> > > >
> > > > Signed-off-by: Long Li <longli@microsoft.com>
> > > > ---
> > > > Change log
> > > > v2: Use vmbus_set_event() to avoid additional check on monitored bit
> > > > Lock vmbus_connection.channel_mutex when going through
> > > > subchannels
> > > >
> > > > drivers/uio/uio_hv_generic.c | 32
> > > > ++++++++++++++++++++++++++------
> > > > 1 file changed, 26 insertions(+), 6 deletions(-)
> > > >
> > > > diff --git a/drivers/uio/uio_hv_generic.c
> > > > b/drivers/uio/uio_hv_generic.c index 3976360d0096..45be2f8baade
> > > > 100644
> > > > --- a/drivers/uio/uio_hv_generic.c
> > > > +++ b/drivers/uio/uio_hv_generic.c
> > > > @@ -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();
> > >
> > > Why is memory barrier not getting called for 'faster' channels ?
> > >
> > > - Saurabh
> >
> > No, the memory barrier is not needed. Even with a barrier, There is no
> guarantee that all pending IRQs are flushed when hv_uio_irqcontrol() returns. If
> user-mode depends on this guarantee, that user-mode has a bug. This barrier
> adds unnecessary costs when walking through subchannels.
> >
>
> Thanks for the details. However I didn't understand if memory barrier is not
> required why have it only for 'slow' devices (ie !monitor_allocated) ?
Because memory barrier is needed between setting interrupt mask and calling vmbus_set_event().
>
> This change also removes the MB for primary channel (if it supports moitor bits), if
> this is intentional, we should call out this in commit message.
Okay, I'm adding it to the commit message.
Long
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2025-03-10 18:57 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-28 22:14 [Patch v2] uio_hv_generic: Set event for all channels on the device longli
2025-03-01 0:19 ` Michael Kelley
2025-03-09 5:47 ` Saurabh Singh Sengar
2025-03-10 17:16 ` Long Li
2025-03-10 17:31 ` Saurabh Singh Sengar
2025-03-10 18:57 ` Long Li
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).