* [PATCH 1/1] virtio: add driver_override support
@ 2025-12-08 14:39 Max Gurtovoy
2025-12-08 15:54 ` Stefan Hajnoczi
2025-12-08 21:12 ` Michael S. Tsirkin
0 siblings, 2 replies; 6+ messages in thread
From: Max Gurtovoy @ 2025-12-08 14:39 UTC (permalink / raw)
To: mst, stefanha, sgarzare, virtualization
Cc: oren, aevdaev, aaptel, Max Gurtovoy
Add support for the 'driver_override' attribute to Virtio devices. This
allows users to control which Virtio bus driver binds to a given Virtio
device.
If 'driver_override' is not set, the existing behavior is preserved and
devices will continue to auto-bind to the first matching Virtio bus
driver.
Signed-off-by: Avraham Evdaev <aevdaev@nvidia.com>
Signed-off-by: Max Gurtovoy <mgurtovoy@nvidia.com>
---
drivers/virtio/virtio.c | 34 ++++++++++++++++++++++++++++++++++
include/linux/virtio.h | 4 ++++
2 files changed, 38 insertions(+)
diff --git a/drivers/virtio/virtio.c b/drivers/virtio/virtio.c
index a09eb4d62f82..f3ce12ee1fb5 100644
--- a/drivers/virtio/virtio.c
+++ b/drivers/virtio/virtio.c
@@ -61,12 +61,41 @@ static ssize_t features_show(struct device *_d,
}
static DEVICE_ATTR_RO(features);
+static ssize_t driver_override_store(struct device *_d,
+ struct device_attribute *attr,
+ const char *buf, size_t count)
+{
+ struct virtio_device *dev = dev_to_virtio(_d);
+ int ret;
+
+ ret = driver_set_override(_d, &dev->driver_override, buf, count);
+ if (ret)
+ return ret;
+
+ return count;
+}
+
+static ssize_t driver_override_show(struct device *_d,
+ struct device_attribute *attr, char *buf)
+{
+ struct virtio_device *dev = dev_to_virtio(_d);
+ ssize_t len;
+
+ device_lock(_d);
+ len = sysfs_emit(buf, "%s\n", dev->driver_override);
+ device_unlock(_d);
+
+ return len;
+}
+static DEVICE_ATTR_RW(driver_override);
+
static struct attribute *virtio_dev_attrs[] = {
&dev_attr_device.attr,
&dev_attr_vendor.attr,
&dev_attr_status.attr,
&dev_attr_modalias.attr,
&dev_attr_features.attr,
+ &dev_attr_driver_override.attr,
NULL,
};
ATTRIBUTE_GROUPS(virtio_dev);
@@ -88,6 +117,10 @@ static int virtio_dev_match(struct device *_dv, const struct device_driver *_dr)
struct virtio_device *dev = dev_to_virtio(_dv);
const struct virtio_device_id *ids;
+ /* Check override first, and if set, only use the named driver */
+ if (dev->driver_override)
+ return strcmp(dev->driver_override, _dr->name) == 0;
+
ids = drv_to_virtio(_dr)->id_table;
for (i = 0; ids[i].device; i++)
if (virtio_id_match(dev, &ids[i]))
@@ -582,6 +615,7 @@ void unregister_virtio_device(struct virtio_device *dev)
{
int index = dev->index; /* save for after device release */
+ kfree(dev->driver_override);
device_unregister(&dev->dev);
virtio_debug_device_exit(dev);
ida_free(&virtio_index_ida, index);
diff --git a/include/linux/virtio.h b/include/linux/virtio.h
index db31fc6f4f1f..418bb490bdc6 100644
--- a/include/linux/virtio.h
+++ b/include/linux/virtio.h
@@ -138,6 +138,9 @@ struct virtio_admin_cmd {
* @config_lock: protects configuration change reporting
* @vqs_list_lock: protects @vqs.
* @dev: underlying device.
+ * @driver_override: driver name to force a match; do not set directly,
+ * because core frees it; use driver_set_override() to
+ * set or clear it.
* @id: the device type identification (used to match it with a driver).
* @config: the configuration ops for this device.
* @vringh_config: configuration ops for host vrings.
@@ -158,6 +161,7 @@ struct virtio_device {
spinlock_t config_lock;
spinlock_t vqs_list_lock;
struct device dev;
+ const char *driver_override;
struct virtio_device_id id;
const struct virtio_config_ops *config;
const struct vringh_config_ops *vringh_config;
--
2.18.1
^ permalink raw reply related [flat|nested] 6+ messages in thread* Re: [PATCH 1/1] virtio: add driver_override support
2025-12-08 14:39 [PATCH 1/1] virtio: add driver_override support Max Gurtovoy
@ 2025-12-08 15:54 ` Stefan Hajnoczi
2025-12-08 16:18 ` Max Gurtovoy
2025-12-08 21:12 ` Michael S. Tsirkin
1 sibling, 1 reply; 6+ messages in thread
From: Stefan Hajnoczi @ 2025-12-08 15:54 UTC (permalink / raw)
To: Max Gurtovoy; +Cc: mst, sgarzare, virtualization, oren, aevdaev, aaptel
[-- Attachment #1: Type: text/plain, Size: 783 bytes --]
On Mon, Dec 08, 2025 at 04:39:25PM +0200, Max Gurtovoy wrote:
> Add support for the 'driver_override' attribute to Virtio devices. This
> allows users to control which Virtio bus driver binds to a given Virtio
> device.
>
> If 'driver_override' is not set, the existing behavior is preserved and
> devices will continue to auto-bind to the first matching Virtio bus
> driver.
>
> Signed-off-by: Avraham Evdaev <aevdaev@nvidia.com>
> Signed-off-by: Max Gurtovoy <mgurtovoy@nvidia.com>
> ---
> drivers/virtio/virtio.c | 34 ++++++++++++++++++++++++++++++++++
> include/linux/virtio.h | 4 ++++
> 2 files changed, 38 insertions(+)
What is the use case? Is there something missing in existing drivers
that cannot be added to them by extending the code?
Stefan
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/1] virtio: add driver_override support
2025-12-08 15:54 ` Stefan Hajnoczi
@ 2025-12-08 16:18 ` Max Gurtovoy
2025-12-09 13:59 ` Stefan Hajnoczi
0 siblings, 1 reply; 6+ messages in thread
From: Max Gurtovoy @ 2025-12-08 16:18 UTC (permalink / raw)
To: Stefan Hajnoczi; +Cc: mst, sgarzare, virtualization, oren, aevdaev, aaptel
On 08/12/2025 17:54, Stefan Hajnoczi wrote:
> On Mon, Dec 08, 2025 at 04:39:25PM +0200, Max Gurtovoy wrote:
>> Add support for the 'driver_override' attribute to Virtio devices. This
>> allows users to control which Virtio bus driver binds to a given Virtio
>> device.
>>
>> If 'driver_override' is not set, the existing behavior is preserved and
>> devices will continue to auto-bind to the first matching Virtio bus
>> driver.
>>
>> Signed-off-by: Avraham Evdaev <aevdaev@nvidia.com>
>> Signed-off-by: Max Gurtovoy <mgurtovoy@nvidia.com>
>> ---
>> drivers/virtio/virtio.c | 34 ++++++++++++++++++++++++++++++++++
>> include/linux/virtio.h | 4 ++++
>> 2 files changed, 38 insertions(+)
> What is the use case? Is there something missing in existing drivers
> that cannot be added to them by extending the code?
>
> Stefan
The main goal is to align the virtio bus with the flexibility that already exists for other buses in the Linux device model.
On buses such as PCI and vDPA, it is possible to override or replace the default driver for a given device and bind it to an alternative driver.
Allowing the selection of which driver is bound to a device can be useful in both development and production environments.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/1] virtio: add driver_override support
2025-12-08 16:18 ` Max Gurtovoy
@ 2025-12-09 13:59 ` Stefan Hajnoczi
2025-12-09 15:12 ` Max Gurtovoy
0 siblings, 1 reply; 6+ messages in thread
From: Stefan Hajnoczi @ 2025-12-09 13:59 UTC (permalink / raw)
To: Max Gurtovoy; +Cc: mst, sgarzare, virtualization, oren, aevdaev, aaptel
[-- Attachment #1: Type: text/plain, Size: 1746 bytes --]
On Mon, Dec 08, 2025 at 06:18:14PM +0200, Max Gurtovoy wrote:
>
> On 08/12/2025 17:54, Stefan Hajnoczi wrote:
> > On Mon, Dec 08, 2025 at 04:39:25PM +0200, Max Gurtovoy wrote:
> > > Add support for the 'driver_override' attribute to Virtio devices. This
> > > allows users to control which Virtio bus driver binds to a given Virtio
> > > device.
> > >
> > > If 'driver_override' is not set, the existing behavior is preserved and
> > > devices will continue to auto-bind to the first matching Virtio bus
> > > driver.
> > >
> > > Signed-off-by: Avraham Evdaev <aevdaev@nvidia.com>
> > > Signed-off-by: Max Gurtovoy <mgurtovoy@nvidia.com>
> > > ---
> > > drivers/virtio/virtio.c | 34 ++++++++++++++++++++++++++++++++++
> > > include/linux/virtio.h | 4 ++++
> > > 2 files changed, 38 insertions(+)
> > What is the use case? Is there something missing in existing drivers
> > that cannot be added to them by extending the code?
> >
> > Stefan
>
> The main goal is to align the virtio bus with the flexibility that already exists for other buses in the Linux device model.
> On buses such as PCI and vDPA, it is possible to override or replace the default driver for a given device and bind it to an alternative driver.
> Allowing the selection of which driver is bound to a device can be useful in both development and production environments.
There are use cases for PCI and vDPA, like binding vfio_pci to a device
that would normally use its device-specific driver.
For VIRTIO, I'm not sure what the use case would be. Is there another
driver that could bind to virtio-net devices, for example?
Giving a concrete example would be useful to help people understand why
this is necessary.
Stefan
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/1] virtio: add driver_override support
2025-12-09 13:59 ` Stefan Hajnoczi
@ 2025-12-09 15:12 ` Max Gurtovoy
0 siblings, 0 replies; 6+ messages in thread
From: Max Gurtovoy @ 2025-12-09 15:12 UTC (permalink / raw)
To: Stefan Hajnoczi; +Cc: mst, sgarzare, virtualization, oren, aevdaev, aaptel
On 09/12/2025 15:59, Stefan Hajnoczi wrote:
> On Mon, Dec 08, 2025 at 06:18:14PM +0200, Max Gurtovoy wrote:
>> On 08/12/2025 17:54, Stefan Hajnoczi wrote:
>>> On Mon, Dec 08, 2025 at 04:39:25PM +0200, Max Gurtovoy wrote:
>>>> Add support for the 'driver_override' attribute to Virtio devices. This
>>>> allows users to control which Virtio bus driver binds to a given Virtio
>>>> device.
>>>>
>>>> If 'driver_override' is not set, the existing behavior is preserved and
>>>> devices will continue to auto-bind to the first matching Virtio bus
>>>> driver.
>>>>
>>>> Signed-off-by: Avraham Evdaev <aevdaev@nvidia.com>
>>>> Signed-off-by: Max Gurtovoy <mgurtovoy@nvidia.com>
>>>> ---
>>>> drivers/virtio/virtio.c | 34 ++++++++++++++++++++++++++++++++++
>>>> include/linux/virtio.h | 4 ++++
>>>> 2 files changed, 38 insertions(+)
>>> What is the use case? Is there something missing in existing drivers
>>> that cannot be added to them by extending the code?
>>>
>>> Stefan
>> The main goal is to align the virtio bus with the flexibility that already exists for other buses in the Linux device model.
>> On buses such as PCI and vDPA, it is possible to override or replace the default driver for a given device and bind it to an alternative driver.
>> Allowing the selection of which driver is bound to a device can be useful in both development and production environments.
> There are use cases for PCI and vDPA, like binding vfio_pci to a device
> that would normally use its device-specific driver.
>
> For VIRTIO, I'm not sure what the use case would be. Is there another
> driver that could bind to virtio-net devices, for example?
Yes.
>
> Giving a concrete example would be useful to help people understand why
> this is necessary.
See example in my v2.
-Max
>
> Stefan
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/1] virtio: add driver_override support
2025-12-08 14:39 [PATCH 1/1] virtio: add driver_override support Max Gurtovoy
2025-12-08 15:54 ` Stefan Hajnoczi
@ 2025-12-08 21:12 ` Michael S. Tsirkin
1 sibling, 0 replies; 6+ messages in thread
From: Michael S. Tsirkin @ 2025-12-08 21:12 UTC (permalink / raw)
To: Max Gurtovoy; +Cc: stefanha, sgarzare, virtualization, oren, aevdaev, aaptel
On Mon, Dec 08, 2025 at 04:39:25PM +0200, Max Gurtovoy wrote:
> Add support for the 'driver_override' attribute to Virtio devices. This
> allows users to control which Virtio bus driver binds to a given Virtio
> device.
>
> If 'driver_override' is not set, the existing behavior is preserved and
> devices will continue to auto-bind to the first matching Virtio bus
> driver.
>
> Signed-off-by: Avraham Evdaev <aevdaev@nvidia.com>
> Signed-off-by: Max Gurtovoy <mgurtovoy@nvidia.com>
Please include, in the commit log, some examples on how this is intended
to be used.
> ---
> drivers/virtio/virtio.c | 34 ++++++++++++++++++++++++++++++++++
> include/linux/virtio.h | 4 ++++
> 2 files changed, 38 insertions(+)
>
> diff --git a/drivers/virtio/virtio.c b/drivers/virtio/virtio.c
> index a09eb4d62f82..f3ce12ee1fb5 100644
> --- a/drivers/virtio/virtio.c
> +++ b/drivers/virtio/virtio.c
> @@ -61,12 +61,41 @@ static ssize_t features_show(struct device *_d,
> }
> static DEVICE_ATTR_RO(features);
>
> +static ssize_t driver_override_store(struct device *_d,
> + struct device_attribute *attr,
> + const char *buf, size_t count)
> +{
> + struct virtio_device *dev = dev_to_virtio(_d);
> + int ret;
> +
> + ret = driver_set_override(_d, &dev->driver_override, buf, count);
> + if (ret)
> + return ret;
> +
> + return count;
> +}
> +
> +static ssize_t driver_override_show(struct device *_d,
> + struct device_attribute *attr, char *buf)
> +{
> + struct virtio_device *dev = dev_to_virtio(_d);
> + ssize_t len;
> +
> + device_lock(_d);
> + len = sysfs_emit(buf, "%s\n", dev->driver_override);
> + device_unlock(_d);
> +
> + return len;
> +}
> +static DEVICE_ATTR_RW(driver_override);
> +
> static struct attribute *virtio_dev_attrs[] = {
> &dev_attr_device.attr,
> &dev_attr_vendor.attr,
> &dev_attr_status.attr,
> &dev_attr_modalias.attr,
> &dev_attr_features.attr,
> + &dev_attr_driver_override.attr,
> NULL,
> };
> ATTRIBUTE_GROUPS(virtio_dev);
> @@ -88,6 +117,10 @@ static int virtio_dev_match(struct device *_dv, const struct device_driver *_dr)
> struct virtio_device *dev = dev_to_virtio(_dv);
> const struct virtio_device_id *ids;
>
> + /* Check override first, and if set, only use the named driver */
> + if (dev->driver_override)
> + return strcmp(dev->driver_override, _dr->name) == 0;
> +
!strcmp is more concise and so is preferred
> ids = drv_to_virtio(_dr)->id_table;
> for (i = 0; ids[i].device; i++)
> if (virtio_id_match(dev, &ids[i]))
> @@ -582,6 +615,7 @@ void unregister_virtio_device(struct virtio_device *dev)
> {
> int index = dev->index; /* save for after device release */
>
> + kfree(dev->driver_override);
> device_unregister(&dev->dev);
> virtio_debug_device_exit(dev);
> ida_free(&virtio_index_ida, index);
> diff --git a/include/linux/virtio.h b/include/linux/virtio.h
> index db31fc6f4f1f..418bb490bdc6 100644
> --- a/include/linux/virtio.h
> +++ b/include/linux/virtio.h
> @@ -138,6 +138,9 @@ struct virtio_admin_cmd {
> * @config_lock: protects configuration change reporting
> * @vqs_list_lock: protects @vqs.
> * @dev: underlying device.
> + * @driver_override: driver name to force a match; do not set directly,
> + * because core frees it; use driver_set_override() to
> + * set or clear it.
> * @id: the device type identification (used to match it with a driver).
> * @config: the configuration ops for this device.
> * @vringh_config: configuration ops for host vrings.
> @@ -158,6 +161,7 @@ struct virtio_device {
> spinlock_t config_lock;
> spinlock_t vqs_list_lock;
> struct device dev;
> + const char *driver_override;
> struct virtio_device_id id;
> const struct virtio_config_ops *config;
> const struct vringh_config_ops *vringh_config;
> --
> 2.18.1
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2025-12-09 15:13 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-08 14:39 [PATCH 1/1] virtio: add driver_override support Max Gurtovoy
2025-12-08 15:54 ` Stefan Hajnoczi
2025-12-08 16:18 ` Max Gurtovoy
2025-12-09 13:59 ` Stefan Hajnoczi
2025-12-09 15:12 ` Max Gurtovoy
2025-12-08 21:12 ` Michael S. Tsirkin
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).