vdpa: add driver_override support
PATCH 1/1 vdpa: add driver_override support
driver_override allows to control which of the vDPA bus drivers binds to a vDPA device.
If driver_override is not set, the previous behaviour is followed:
devices use the first vDPA bus driver loaded (unless auto binding is disabled).
Tested on Fedora 34 with driverctl(8):
$ modprobe virtio-vdpa $ modprobe vhost-vdpa $ modprobe vdpa-sim-net
$ vdpa dev add mgmtdev vdpasim_net name dev1
# dev1 is attached to the first vDPA bus driver loaded
$ driverctl -b vdpa list-devices
dev1 virtio_vdpa$ driverctl -b vdpa set-override dev1 vhost_vdpa
$ driverctl -b vdpa list-devices
dev1 vhost_vdpa [*]Note: driverctl(8) integrates with udev so the binding is preserved.
--- include/linux/vdpa.h | 2 ++ drivers/vdpa/vdpa.c | 74 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+)
include/linux/vdpa.h +2 -0
@@ -64,6 +64,7 @@ struct vdpa_mgmt_dev;* struct vdpa_device - representation of a vDPA device * @dev: underlying device * @dma_dev: the actual device that is performing DMA +* @driver_override: driver name to force a match * @config: the configuration ops for this device. * @cf_mutex: Protects get and set access to configuration layout. * @index: device index
@@ -76,6 +77,7 @@ struct vdpa_mgmt_dev;struct vdpa_device {struct device dev;struct device *dma_dev; +const char *driver_override;const struct vdpa_config_ops *config;struct mutex cf_mutex;/* Protects get/set config */ unsigned int index;
drivers/vdpa/vdpa.c +74 -0
88 lines not on this page · raw message
Signature · 1 line
2.31.1
Quoted 39 lines · Stefano Garzarella
driver_overrideallows to control which of the vDPA bus drivers binds to a vDPA device.If
driver_overrideis not set, the previous behaviour is followed:
devices use the first vDPA bus driver loaded (unless auto binding is disabled).Tested on Fedora 34 with driverctl(8):
$ modprobe virtio-vdpa $ modprobe vhost-vdpa $ modprobe vdpa-sim-net$ vdpa dev add mgmtdev vdpasim_net name dev1# dev1 is attached to the first vDPA bus driver loaded $ driverctl -b vdpa list-devices dev1 virtio_vdpa$ driverctl -b vdpa set-override dev1 vhost_vdpa$ driverctl -b vdpa list-devices dev1 vhost_vdpa [*]Note: driverctl(8) integrates with udev so the binding is preserved.
Suggested-by Jason Wang <[email protected]>Signed-off-by Stefano Garzarella <[email protected]>--- include/linux/vdpa.h | 2 ++ drivers/vdpa/vdpa.c | 74 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+)include/linux/vdpa.h +0
-0
include/linux/vdpa.h struct vdpa_mgmt_dev; · line 67
Quoted 4 lines
include/linux/vdpa.h +1
-0@@ -64,6 +64,7 @@ struct vdpa_mgmt_dev;* struct vdpa_device - representation of a vDPA device * @dev: underlying device * @dma_dev: the actual device that is performing DMA +* @driver_override: driver name to force a match
This seems useless?
Quoted 83 lines
include/linux/vdpa.h +1
-0* @config: the configuration ops for this device. * @cf_mutex: Protects get and set access to configuration layout. * @index: device index @@ -76,6 +77,7 @@ struct vdpa_mgmt_dev;struct vdpa_device {struct device dev;struct device *dma_dev; +const char *driver_override;const struct vdpa_config_ops *config;struct mutex cf_mutex;/* Protects get/set config */ unsigned int index;drivers/vdpa/vdpa.c +64
-0@@ -52,8 +52,81 @@ static void vdpa_dev_remove(struct device *d) drv->remove (vdev); } +static int vdpa_dev_match (struct device *dev,struct device_driver *drv) +{ +struct vdpa_device *vdev =dev_to_vdpa (dev); + +/* Check override first, and if set, only use the named driver */ +if (vdev->driver_override) +return strcmp (vdev->driver_override, drv->name) ==0 ; + +/* Currently devices must be supported by all vDPA bus drivers */ +return 1 ; +} + +static ssize_t driver_override_store (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t count) +{ +struct vdpa_device *vdev =dev_to_vdpa (dev); +const char *driver_override, *old; +char *cp; + +/* We need to keep extra room for a newline */ +if (count >= (PAGE_SIZE -1 )) +return -EINVAL ; + + driver_override =kstrndup (buf, count,GFP_KERNEL ); +if (!driver_override) +return -ENOMEM ; + + cp =strchr (driver_override,'\n' ); +if (cp) + *cp ='\0' ; + +device_lock (dev); + old = vdev->driver_override; +if (strlen (driver_override)) { + vdev->driver_override = driver_override; + }else { +kfree (driver_override); + vdev->driver_override =NULL ; + } +device_unlock (dev); + +kfree (old); + +return count; +} + +static ssize_t driver_override_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +struct vdpa_device *vdev =dev_to_vdpa (dev); +ssize_t len; + +device_lock (dev); + len =snprintf (buf,PAGE_SIZE ,"%s\n" , vdev->driver_override); +device_unlock (dev); + +return len; +} +static DEVICE_ATTR_RW (driver_override); + +static struct attribute *vdpa_dev_attrs[] = { + &dev_attr_driver_override.attr, +NULL ,
drivers/vdpa/vdpa.c static void vdpa_dev_remove(struct device *d) · line 128
Quoted 10 lines
drivers/vdpa/vdpa.c +8
-0+}; + +static const struct attribute_group vdpa_dev_group = { + .attrs = vdpa_dev_attrs, +}; +__ATTRIBUTE_GROUPS (vdpa_dev); +static struct bus_type vdpa_bus = { .name ="vdpa" , + .dev_groups = vdpa_dev_groups,
This reminds me that we probably need to document the sysfs interface in Documentation/ABI/testing/sysfs-bus-vdpa.
But it's not the fault of this patch which look good.
Thanks
Quoted 15 lines
drivers/vdpa/vdpa.c +2
-1+ .match = vdpa_dev_match, .probe = vdpa_dev_probe, .remove = vdpa_dev_remove, };@@ -68,6 +141,7 @@ static void vdpa_release_dev(struct device *d)ida_simple_remove (&vdpa_index_ida, vdev->index);mutex_destroy (&vdev->cf_mutex); +kfree (vdev->driver_override);kfree (vdev); } --2.31.1
Quoted 35 lines · Jason Wang
Quoted 34 lines · Stefano Garzarella
driver_overrideallows to control which of the vDPA bus drivers binds to a vDPA device.If
driver_overrideis not set, the previous behaviour is followed:
devices use the first vDPA bus driver loaded (unless auto binding is disabled).Tested on Fedora 34 with driverctl(8):
$ modprobe virtio-vdpa $ modprobe vhost-vdpa $ modprobe vdpa-sim-net$ vdpa dev add mgmtdev vdpasim_net name dev1# dev1 is attached to the first vDPA bus driver loaded $ driverctl -b vdpa list-devices dev1 virtio_vdpa$ driverctl -b vdpa set-override dev1 vhost_vdpa$ driverctl -b vdpa list-devices dev1 vhost_vdpa [*]Note: driverctl(8) integrates with udev so the binding is preserved.
Suggested-by Jason Wang <[email protected]>Signed-off-by Stefano Garzarella <[email protected]>--- include/linux/vdpa.h | 2 ++ drivers/vdpa/vdpa.c | 74 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+)
Quoted 11 lines
include/linux/vdpa.h struct vdpa_mgmt_dev; · line 67
Quoted 9 lines
include/linux/vdpa.h +1
-0@@ -64,6 +64,7 @@ struct vdpa_mgmt_dev;* struct vdpa_device - representation of a vDPA device * @dev: underlying device * @dma_dev: the actual device that is performing DMA +* @driver_override: driver name to force a match This seems useless?
I'm a bit lost, do you mean we should remove the documentation of driver_override?
Quoted 90 lines
Quoted 90 lines
include/linux/vdpa.h +1
-0* @config: the configuration ops for this device. * @cf_mutex: Protects get and set access to configuration layout. * @index: device index @@ -76,6 +77,7 @@ struct vdpa_mgmt_dev;struct vdpa_device {struct device dev;struct device *dma_dev; +const char *driver_override;const struct vdpa_config_ops *config;struct mutex cf_mutex;/* Protects get/set config */ unsigned int index;drivers/vdpa/vdpa.c +9
-0@@ -52,8 +52,81 @@ static void vdpa_dev_remove(struct device *d) drv->remove (vdev); } +static int vdpa_dev_match (struct device *dev,struct device_driver *drv) +{ +struct vdpa_device *vdev =dev_to_vdpa (dev); + +/* Check override first, and if set, only use the named driver */ +if (vdev->driver_override) +return strcmp (vdev->driver_override, drv->name) ==0 ; + +/* Currently devices must be supported by all vDPA bus drivers */
drivers/vdpa/vdpa.c +60
-0+return 1 ; +} + +static ssize_t driver_override_store (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t count) +{ +struct vdpa_device *vdev =dev_to_vdpa (dev); +const char *driver_override, *old; +char *cp; + +/* We need to keep extra room for a newline */ +if (count >= (PAGE_SIZE -1 )) +return -EINVAL ; + + driver_override =kstrndup (buf, count,GFP_KERNEL ); +if (!driver_override) +return -ENOMEM ; + + cp =strchr (driver_override,'\n' ); +if (cp) + *cp ='\0' ; + +device_lock (dev); + old = vdev->driver_override; +if (strlen (driver_override)) { + vdev->driver_override = driver_override; + }else { +kfree (driver_override); + vdev->driver_override =NULL ; + } +device_unlock (dev); + +kfree (old); + +return count; +} + +static ssize_t driver_override_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +struct vdpa_device *vdev =dev_to_vdpa (dev); +ssize_t len; + +device_lock (dev); + len =snprintf (buf,PAGE_SIZE ,"%s\n" , vdev->driver_override); +device_unlock (dev); + +return len; +} +static DEVICE_ATTR_RW (driver_override); + +static struct attribute *vdpa_dev_attrs[] = { + &dev_attr_driver_override.attr, +NULL , +}; + +static const struct attribute_group vdpa_dev_group = { + .attrs = vdpa_dev_attrs, +};
Quoted 9 lines
drivers/vdpa/vdpa.c static void vdpa_dev_remove(struct device *d) · line 128
Quoted 5 lines
drivers/vdpa/vdpa.c +3
-0+__ATTRIBUTE_GROUPS (vdpa_dev); +static struct bus_type vdpa_bus = { .name ="vdpa" , + .dev_groups = vdpa_dev_groups,This reminds me that we probably need to document the sysfs interface in
Documentation/ABI/testing/sysfs-bus-vdpa.
Yeah, I'd like to add more documentation. We should also document the device life cycle and management API.
It's on my to-do list, I'm prioritizing it!
Quoted 1 line
But it's not the fault of this patch which look good.
Thanks,
Stefano
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Jason Wang
Acked-byQuoted 49 lines · Stefano Garzarella
Quoted 35 lines · Jason Wang
Quoted 34 lines · Stefano Garzarella
driver_overrideallows to control which of the vDPA bus drivers binds to a vDPA device.If
driver_overrideis not set, the previous behaviour is followed:
devices use the first vDPA bus driver loaded (unless auto binding is disabled).Tested on Fedora 34 with driverctl(8):
$ modprobe virtio-vdpa $ modprobe vhost-vdpa $ modprobe vdpa-sim-net$ vdpa dev add mgmtdev vdpasim_net name dev1# dev1 is attached to the first vDPA bus driver loaded $ driverctl -b vdpa list-devices dev1 virtio_vdpa$ driverctl -b vdpa set-override dev1 vhost_vdpa$ driverctl -b vdpa list-devices dev1 vhost_vdpa [*]Note: driverctl(8) integrates with udev so the binding is preserved.
Suggested-by Jason Wang <[email protected]>Signed-off-by Stefano Garzarella <[email protected]>--- include/linux/vdpa.h | 2 ++ drivers/vdpa/vdpa.c | 74 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+)Quoted 11 lines
include/linux/vdpa.h struct vdpa_mgmt_dev; · line 67
Quoted 9 lines
include/linux/vdpa.h +1
-0@@ -64,6 +64,7 @@ struct vdpa_mgmt_dev;* struct vdpa_device - representation of a vDPA device * @dev: underlying device * @dma_dev: the actual device that is performing DMA +* @driver_override: driver name to force a match This seems useless?
Quoted 2 lines
I'm a bit lost, do you mean we should remove the documentation of
driver_override?
I misread the code which was misled by vdpa_mgmt_dev above:(
The code should be fine.
So:
Quoted 111 lines
Quoted 91 lines
Quoted 91 lines
include/linux/vdpa.h +1
-0* @config: the configuration ops for this device. * @cf_mutex: Protects get and set access to configuration layout. * @index: device index @@ -76,6 +77,7 @@ struct vdpa_mgmt_dev;struct vdpa_device {struct device dev;struct device *dma_dev; +const char *driver_override;const struct vdpa_config_ops *config;struct mutex cf_mutex;/* Protects get/set config */ unsigned int index;drivers/vdpa/vdpa.c +9
-0@@ -52,8 +52,81 @@ static void vdpa_dev_remove(struct device *d) drv->remove (vdev); } +static int vdpa_dev_match (struct device *dev,struct device_driver *drv) +{ +struct vdpa_device *vdev =dev_to_vdpa (dev); + +/* Check override first, and if set, only use the named driver */ +if (vdev->driver_override) +return strcmp (vdev->driver_override, drv->name) ==0 ; + +/* Currently devices must be supported by all vDPA bus drivers */
drivers/vdpa/vdpa.c +60
-0+return 1 ; +} + +static ssize_t driver_override_store (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t count) +{ +struct vdpa_device *vdev =dev_to_vdpa (dev); +const char *driver_override, *old; +char *cp; + +/* We need to keep extra room for a newline */ +if (count >= (PAGE_SIZE -1 )) +return -EINVAL ; + + driver_override =kstrndup (buf, count,GFP_KERNEL ); +if (!driver_override) +return -ENOMEM ; + + cp =strchr (driver_override,'\n' ); +if (cp) + *cp ='\0' ; + +device_lock (dev); + old = vdev->driver_override; +if (strlen (driver_override)) { + vdev->driver_override = driver_override; + }else { +kfree (driver_override); + vdev->driver_override =NULL ; + } +device_unlock (dev); + +kfree (old); + +return count; +} + +static ssize_t driver_override_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +struct vdpa_device *vdev =dev_to_vdpa (dev); +ssize_t len; + +device_lock (dev); + len =snprintf (buf,PAGE_SIZE ,"%s\n" , vdev->driver_override); +device_unlock (dev); + +return len; +} +static DEVICE_ATTR_RW (driver_override); + +static struct attribute *vdpa_dev_attrs[] = { + &dev_attr_driver_override.attr, +NULL , +}; + +static const struct attribute_group vdpa_dev_group = { + .attrs = vdpa_dev_attrs, +};Quoted 9 lines
drivers/vdpa/vdpa.c static void vdpa_dev_remove(struct device *d) · line 128
Quoted 5 lines
drivers/vdpa/vdpa.c +3
-0+__ATTRIBUTE_GROUPS (vdpa_dev); +static struct bus_type vdpa_bus = { .name ="vdpa" , + .dev_groups = vdpa_dev_groups,This reminds me that we probably need to document the sysfs interface in
Documentation/ABI/testing/sysfs-bus-vdpa.Yeah, I'd like to add more documentation. We should also document the device life cycle and management API.
It's on my to-do list, I'm prioritizing it!
Quoted 1 line
But it's not the fault of this patch which look good.
Thanks,
Stefano
Quoted 50 lines · Jason Wang
Quoted 49 lines · Stefano Garzarella
Quoted 46 lines · Jason Wang
Quoted 39 lines · Stefano Garzarella
driver_overrideallows to control which of the vDPA bus drivers binds to a vDPA device.If
driver_overrideis not set, the previous behaviour is followed:
devices use the first vDPA bus driver loaded (unless auto binding is disabled).Tested on Fedora 34 with driverctl(8):
$ modprobe virtio-vdpa $ modprobe vhost-vdpa $ modprobe vdpa-sim-net$ vdpa dev add mgmtdev vdpasim_net name dev1# dev1 is attached to the first vDPA bus driver loaded $ driverctl -b vdpa list-devices dev1 virtio_vdpa$ driverctl -b vdpa set-override dev1 vhost_vdpa$ driverctl -b vdpa list-devices dev1 vhost_vdpa [*]Note: driverctl(8) integrates with udev so the binding is preserved.
Suggested-by Jason Wang <[email protected]>Signed-off-by Stefano Garzarella <[email protected]>--- include/linux/vdpa.h | 2 ++ drivers/vdpa/vdpa.c | 74 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+)include/linux/vdpa.h +0
-0include/linux/vdpa.h struct vdpa_mgmt_dev; · line 67
Quoted 4 lines
include/linux/vdpa.h +1
-0@@ -64,6 +64,7 @@ struct vdpa_mgmt_dev;* struct vdpa_device - representation of a vDPA device * @dev: underlying device * @dma_dev: the actual device that is performing DMA +* @driver_override: driver name to force a match This seems useless?
Quoted 4 lines
Quoted 2 lines
I'm a bit lost, do you mean we should remove the documentation of
driver_override?I misread the code which was misled by
vdpa_mgmt_devabove:(
Yeah, the same thing happened to me now while double checking ;-)
Quoted 7 lines
The code should be fine.
So:
Acked-by Jason Wang <[email protected]>
Thanks,
Stefano
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Quoted 145 lines · Jason Wang
Quoted 39 lines · Stefano Garzarella
driver_overrideallows to control which of the vDPA bus drivers binds to a vDPA device.If
driver_overrideis not set, the previous behaviour is followed:
devices use the first vDPA bus driver loaded (unless auto binding is disabled).Tested on Fedora 34 with driverctl(8):
$ modprobe virtio-vdpa $ modprobe vhost-vdpa $ modprobe vdpa-sim-net$ vdpa dev add mgmtdev vdpasim_net name dev1# dev1 is attached to the first vDPA bus driver loaded $ driverctl -b vdpa list-devices dev1 virtio_vdpa$ driverctl -b vdpa set-override dev1 vhost_vdpa$ driverctl -b vdpa list-devices dev1 vhost_vdpa [*]Note: driverctl(8) integrates with udev so the binding is preserved.
Suggested-by Jason Wang <[email protected]>Signed-off-by Stefano Garzarella <[email protected]>--- include/linux/vdpa.h | 2 ++ drivers/vdpa/vdpa.c | 74 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+)include/linux/vdpa.h +0
-0include/linux/vdpa.h struct vdpa_mgmt_dev; · line 67
Quoted 4 lines
include/linux/vdpa.h +1
-0@@ -64,6 +64,7 @@ struct vdpa_mgmt_dev;* struct vdpa_device - representation of a vDPA device * @dev: underlying device * @dma_dev: the actual device that is performing DMA +* @driver_override: driver name to force a match This seems useless?
Quoted 83 lines
include/linux/vdpa.h +1
-0* @config: the configuration ops for this device. * @cf_mutex: Protects get and set access to configuration layout. * @index: device index @@ -76,6 +77,7 @@ struct vdpa_mgmt_dev;struct vdpa_device {struct device dev;struct device *dma_dev; +const char *driver_override;const struct vdpa_config_ops *config;struct mutex cf_mutex;/* Protects get/set config */ unsigned int index;drivers/vdpa/vdpa.c +64
-0@@ -52,8 +52,81 @@ static void vdpa_dev_remove(struct device *d) drv->remove (vdev); } +static int vdpa_dev_match (struct device *dev,struct device_driver *drv) +{ +struct vdpa_device *vdev =dev_to_vdpa (dev); + +/* Check override first, and if set, only use the named driver */ +if (vdev->driver_override) +return strcmp (vdev->driver_override, drv->name) ==0 ; + +/* Currently devices must be supported by all vDPA bus drivers */ +return 1 ; +} + +static ssize_t driver_override_store (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t count) +{ +struct vdpa_device *vdev =dev_to_vdpa (dev); +const char *driver_override, *old; +char *cp; + +/* We need to keep extra room for a newline */ +if (count >= (PAGE_SIZE -1 )) +return -EINVAL ; + + driver_override =kstrndup (buf, count,GFP_KERNEL ); +if (!driver_override) +return -ENOMEM ; + + cp =strchr (driver_override,'\n' ); +if (cp) + *cp ='\0' ; + +device_lock (dev); + old = vdev->driver_override; +if (strlen (driver_override)) { + vdev->driver_override = driver_override; + }else { +kfree (driver_override); + vdev->driver_override =NULL ; + } +device_unlock (dev); + +kfree (old); + +return count; +} + +static ssize_t driver_override_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +struct vdpa_device *vdev =dev_to_vdpa (dev); +ssize_t len; + +device_lock (dev); + len =snprintf (buf,PAGE_SIZE ,"%s\n" , vdev->driver_override); +device_unlock (dev); + +return len; +} +static DEVICE_ATTR_RW (driver_override); + +static struct attribute *vdpa_dev_attrs[] = { + &dev_attr_driver_override.attr, +NULL ,drivers/vdpa/vdpa.c static void vdpa_dev_remove(struct device *d) · line 128
Quoted 10 lines
drivers/vdpa/vdpa.c +8
-0+}; + +static const struct attribute_group vdpa_dev_group = { + .attrs = vdpa_dev_attrs, +}; +__ATTRIBUTE_GROUPS (vdpa_dev); +static struct bus_type vdpa_bus = { .name ="vdpa" , + .dev_groups = vdpa_dev_groups,This reminds me that we probably need to document the sysfs interface in
Documentation/ABI/testing/sysfs-bus-vdpa.
Quoted 1 line
But it's not the fault of this patch which look good.
Michael, Jason, about Documentation/ABI/testing/sysfs-bus-vdpa, do you think is better to send a follow up patch/series, maybe including also others entries (e.g. bind, unbind) or a v2 including the documentation of driver_ovveride?
Thanks,
Stefano
Michael S. Tsirkin
maintainerQuoted 148 lines · Stefano Garzarella
Quoted 145 lines · Jason Wang
Quoted 39 lines · Stefano Garzarella
driver_overrideallows to control which of the vDPA bus drivers binds to a vDPA device.If
driver_overrideis not set, the previous behaviour is followed:
devices use the first vDPA bus driver loaded (unless auto binding is disabled).Tested on Fedora 34 with driverctl(8):
$ modprobe virtio-vdpa $ modprobe vhost-vdpa $ modprobe vdpa-sim-net$ vdpa dev add mgmtdev vdpasim_net name dev1# dev1 is attached to the first vDPA bus driver loaded $ driverctl -b vdpa list-devices dev1 virtio_vdpa$ driverctl -b vdpa set-override dev1 vhost_vdpa$ driverctl -b vdpa list-devices dev1 vhost_vdpa [*]Note: driverctl(8) integrates with udev so the binding is preserved.
Suggested-by Jason Wang <[email protected]>Signed-off-by Stefano Garzarella <[email protected]>--- include/linux/vdpa.h | 2 ++ drivers/vdpa/vdpa.c | 74 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+)include/linux/vdpa.h +0
-0include/linux/vdpa.h struct vdpa_mgmt_dev; · line 67
Quoted 4 lines
include/linux/vdpa.h +1
-0@@ -64,6 +64,7 @@ struct vdpa_mgmt_dev;* struct vdpa_device - representation of a vDPA device * @dev: underlying device * @dma_dev: the actual device that is performing DMA +* @driver_override: driver name to force a match This seems useless?
Quoted 83 lines
include/linux/vdpa.h +1
-0* @config: the configuration ops for this device. * @cf_mutex: Protects get and set access to configuration layout. * @index: device index @@ -76,6 +77,7 @@ struct vdpa_mgmt_dev;struct vdpa_device {struct device dev;struct device *dma_dev; +const char *driver_override;const struct vdpa_config_ops *config;struct mutex cf_mutex;/* Protects get/set config */ unsigned int index;drivers/vdpa/vdpa.c +64
-0@@ -52,8 +52,81 @@ static void vdpa_dev_remove(struct device *d) drv->remove (vdev); } +static int vdpa_dev_match (struct device *dev,struct device_driver *drv) +{ +struct vdpa_device *vdev =dev_to_vdpa (dev); + +/* Check override first, and if set, only use the named driver */ +if (vdev->driver_override) +return strcmp (vdev->driver_override, drv->name) ==0 ; + +/* Currently devices must be supported by all vDPA bus drivers */ +return 1 ; +} + +static ssize_t driver_override_store (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t count) +{ +struct vdpa_device *vdev =dev_to_vdpa (dev); +const char *driver_override, *old; +char *cp; + +/* We need to keep extra room for a newline */ +if (count >= (PAGE_SIZE -1 )) +return -EINVAL ; + + driver_override =kstrndup (buf, count,GFP_KERNEL ); +if (!driver_override) +return -ENOMEM ; + + cp =strchr (driver_override,'\n' ); +if (cp) + *cp ='\0' ; + +device_lock (dev); + old = vdev->driver_override; +if (strlen (driver_override)) { + vdev->driver_override = driver_override; + }else { +kfree (driver_override); + vdev->driver_override =NULL ; + } +device_unlock (dev); + +kfree (old); + +return count; +} + +static ssize_t driver_override_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +struct vdpa_device *vdev =dev_to_vdpa (dev); +ssize_t len; + +device_lock (dev); + len =snprintf (buf,PAGE_SIZE ,"%s\n" , vdev->driver_override); +device_unlock (dev); + +return len; +} +static DEVICE_ATTR_RW (driver_override); + +static struct attribute *vdpa_dev_attrs[] = { + &dev_attr_driver_override.attr, +NULL ,drivers/vdpa/vdpa.c static void vdpa_dev_remove(struct device *d) · line 128
Quoted 10 lines
drivers/vdpa/vdpa.c +8
-0+}; + +static const struct attribute_group vdpa_dev_group = { + .attrs = vdpa_dev_attrs, +}; +__ATTRIBUTE_GROUPS (vdpa_dev); +static struct bus_type vdpa_bus = { .name ="vdpa" , + .dev_groups = vdpa_dev_groups,This reminds me that we probably need to document the sysfs interface in
Documentation/ABI/testing/sysfs-bus-vdpa.Quoted 1 line
But it's not the fault of this patch which look good.
Quoted 7 lines
Michael, Jason, about
Documentation/ABI/testing/sysfs-bus-vdpa, do you think is better to send a follow up patch/series, maybe including also others entries (e.g. bind, unbind) or a v2 including the documentation ofdriver_ovveride?Thanks,
Stefano
I'd include it as a patch in series.
Signature · 1 line
MST
Quoted 154 lines · Michael S. Tsirkin
Quoted 153 lines · Stefano Garzarella
Quoted 145 lines · Jason Wang
Quoted 39 lines · Stefano Garzarella
driver_overrideallows to control which of the vDPA bus drivers binds to a vDPA device.If
driver_overrideis not set, the previous behaviour is followed:
devices use the first vDPA bus driver loaded (unless auto binding is disabled).Tested on Fedora 34 with driverctl(8):
$ modprobe virtio-vdpa $ modprobe vhost-vdpa $ modprobe vdpa-sim-net$ vdpa dev add mgmtdev vdpasim_net name dev1# dev1 is attached to the first vDPA bus driver loaded $ driverctl -b vdpa list-devices dev1 virtio_vdpa$ driverctl -b vdpa set-override dev1 vhost_vdpa$ driverctl -b vdpa list-devices dev1 vhost_vdpa [*]Note: driverctl(8) integrates with udev so the binding is preserved.
Suggested-by Jason Wang <[email protected]>Signed-off-by Stefano Garzarella <[email protected]>--- include/linux/vdpa.h | 2 ++ drivers/vdpa/vdpa.c | 74 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+)include/linux/vdpa.h +0
-0include/linux/vdpa.h struct vdpa_mgmt_dev; · line 67
Quoted 4 lines
include/linux/vdpa.h +1
-0@@ -64,6 +64,7 @@ struct vdpa_mgmt_dev;* struct vdpa_device - representation of a vDPA device * @dev: underlying device * @dma_dev: the actual device that is performing DMA +* @driver_override: driver name to force a match This seems useless?
Quoted 83 lines
include/linux/vdpa.h +1
-0* @config: the configuration ops for this device. * @cf_mutex: Protects get and set access to configuration layout. * @index: device index @@ -76,6 +77,7 @@ struct vdpa_mgmt_dev;struct vdpa_device {struct device dev;struct device *dma_dev; +const char *driver_override;const struct vdpa_config_ops *config;struct mutex cf_mutex;/* Protects get/set config */ unsigned int index;drivers/vdpa/vdpa.c +64
-0@@ -52,8 +52,81 @@ static void vdpa_dev_remove(struct device *d) drv->remove (vdev); } +static int vdpa_dev_match (struct device *dev,struct device_driver *drv) +{ +struct vdpa_device *vdev =dev_to_vdpa (dev); + +/* Check override first, and if set, only use the named driver */ +if (vdev->driver_override) +return strcmp (vdev->driver_override, drv->name) ==0 ; + +/* Currently devices must be supported by all vDPA bus drivers */ +return 1 ; +} + +static ssize_t driver_override_store (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t count) +{ +struct vdpa_device *vdev =dev_to_vdpa (dev); +const char *driver_override, *old; +char *cp; + +/* We need to keep extra room for a newline */ +if (count >= (PAGE_SIZE -1 )) +return -EINVAL ; + + driver_override =kstrndup (buf, count,GFP_KERNEL ); +if (!driver_override) +return -ENOMEM ; + + cp =strchr (driver_override,'\n' ); +if (cp) + *cp ='\0' ; + +device_lock (dev); + old = vdev->driver_override; +if (strlen (driver_override)) { + vdev->driver_override = driver_override; + }else { +kfree (driver_override); + vdev->driver_override =NULL ; + } +device_unlock (dev); + +kfree (old); + +return count; +} + +static ssize_t driver_override_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +struct vdpa_device *vdev =dev_to_vdpa (dev); +ssize_t len; + +device_lock (dev); + len =snprintf (buf,PAGE_SIZE ,"%s\n" , vdev->driver_override); +device_unlock (dev); + +return len; +} +static DEVICE_ATTR_RW (driver_override); + +static struct attribute *vdpa_dev_attrs[] = { + &dev_attr_driver_override.attr, +NULL ,drivers/vdpa/vdpa.c static void vdpa_dev_remove(struct device *d) · line 128
Quoted 10 lines
drivers/vdpa/vdpa.c +8
-0+}; + +static const struct attribute_group vdpa_dev_group = { + .attrs = vdpa_dev_attrs, +}; +__ATTRIBUTE_GROUPS (vdpa_dev); +static struct bus_type vdpa_bus = { .name ="vdpa" , + .dev_groups = vdpa_dev_groups,This reminds me that we probably need to document the sysfs interface in
Documentation/ABI/testing/sysfs-bus-vdpa.Quoted 1 line
But it's not the fault of this patch which look good.
Michael, Jason, about
Documentation/ABI/testing/sysfs-bus-vdpa, do you think is better to send a follow up patch/series, maybe including also others entries (e.g. bind, unbind) or a v2 including the documentation ofdriver_ovveride?
Quoted 5 lines
Quoted 2 lines
Thanks,
StefanoI'd include it as a patch in series.
Okay, so I'll send the documentation in a followup series.
Thanks,
Stefano