driver core: Add new device_driver flag to allow binding via sysfs only
Subsystems (2)
PATCH 1/2 driver core: Add new device_driver flag to allow binding via sysfs only
VFIO supports pass-through of devices to user space - for sake of illustration, say a PCI e1000 device:
- the e1000 is first unbound from the PCI e1000 driver via sysfs
- the vfio-pci driver is told via new_id that it now handles e1000 devices
- the e1000 is explicitly bound to vfio-pci through sysfs
However, now we have two drivers in the system that both handle e1000 devices. A hotplug event could then occur and it is ambiguous as to which driver will claim the device. The desired semantics is that vfio-pci is only bound to devices by explicit request in sysfs. This patch makes this possible by introducing a sysfs_bind_only flag in struct device_driver.
---
rebased onto 3.13-rc2, and reposted from first submission which recieved no comments:
https://lkml.org/lkml/2013/10/11/53
drivers/base/dd.c | 5 ++++- include/linux/device.h | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-)
drivers/base/dd.c +4 -1
@@ -389,7 +389,7 @@ static int __device_attach(struct device_driver *drv, void *data) {struct device *dev = data; -if (!driver_match_device (drv, dev)) +if (drv->sysfs_bind_only || !driver_match_device (drv, dev))return 0 ;return driver_probe_device (drv, dev);
@@ -476,6 +476,9 @@ static int __driver_attach(struct device *dev, void *data)*/ int driver_attach (struct device_driver *drv) { +if (drv->sysfs_bind_only) +return 0 ; +return bus_for_each_dev (drv->bus,NULL , drv, __driver_attach); }EXPORT_SYMBOL_GPL (driver_attach);
include/linux/device.h +2 -0
@@ -200,6 +200,7 @@ extern struct klist *bus_get_device_klist(struct bus_type *bus);* @owner: The module owner. * @mod_name: Used for built-in modules. * @suppress_bind_attrs: Disables bind/unbind via sysfs. +* @sysfs_bind_only: Only allow bind/unbind via sysfs. * @of_match_table: The open firmware table. * @acpi_match_table: The ACPI match table. * @probe: Called to query the existence of a specific device,
@@ -233,6 +234,7 @@ struct device_driver {const char *mod_name;/* used for built-in modules */ bool suppress_bind_attrs;/* disables bind/unbind via sysfs */ +bool sysfs_bind_only;/* only allow bind/unbind via sysfs */ const struct of_device_id *of_match_table;const struct acpi_device_id *acpi_match_table;
Signature · 1 line
1.8.5
Quoted 62 lines · Kim Phillips
VFIO supports pass-through of devices to user space - for sake of illustration, say a PCI e1000 device:
- the e1000 is first unbound from the PCI e1000 driver via sysfs
- the vfio-pci driver is told vianew_idthat it now handles e1000 devices
- the e1000 is explicitly bound to vfio-pci through sysfsHowever, now we have two drivers in the system that both handle e1000 devices. A hotplug event could then occur and it is ambiguous as to which driver will claim the device. The desired semantics is that vfio-pci is only bound to devices by explicit request in sysfs. This patch makes this possible by introducing a
sysfs_bind_onlyflag in structdevice_driver.Signed-off-by Stuart Yoder <[email protected]>Signed-off-by Kim Phillips <[email protected]>---
rebased onto 3.13-rc2, and reposted from first submission which recieved no comments:https://lkml.org/lkml/2013/10/11/53
drivers/base/dd.c | 5 ++++- include/linux/device.h | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-)drivers/base/dd.c +4
-1@@ -389,7 +389,7 @@ static int __device_attach(struct device_driver *drv, void *data) {struct device *dev = data; -if (!driver_match_device (drv, dev)) +if (drv->sysfs_bind_only || !driver_match_device (drv, dev))return 0 ;return driver_probe_device (drv, dev);@@ -476,6 +476,9 @@ static int __driver_attach(struct device *dev, void *data)*/ int driver_attach (struct device_driver *drv) { +if (drv->sysfs_bind_only) +return 0 ; +return bus_for_each_dev (drv->bus,NULL , drv, __driver_attach); }EXPORT_SYMBOL_GPL (driver_attach);include/linux/device.h +1
-0@@ -200,6 +200,7 @@ extern struct klist *bus_get_device_klist(struct bus_type *bus);* @owner: The module owner. * @mod_name: Used for built-in modules. * @suppress_bind_attrs: Disables bind/unbind via sysfs. +* @sysfs_bind_only: Only allow bind/unbind via sysfs. * @of_match_table: The open firmware table. * @acpi_match_table: The ACPI match table. * @probe: Called to query the existence of a specific device,
include/linux/device.h struct device_driver { · line 240
Quoted 7 lines
include/linux/device.h +1
-0@@ -233,6 +234,7 @@ struct device_driver {const char *mod_name;/* used for built-in modules */ bool suppress_bind_attrs;/* disables bind/unbind via sysfs */ +bool sysfs_bind_only;/* only allow bind/unbind via sysfs */ const struct of_device_id *of_match_table;const struct acpi_device_id *acpi_match_table;
I think I only discussed this with Stuart in person at the KVM Forum:
Why not deriving the property "sysfs bind only" from the fact that a device does wild-card binding? Are there use cases that benefit from decoupling both features?
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT RTC ITP SES-DE Corporate Competence Center Embedded Linux
Quoted 67 lines · On Tue, 03 Dec 2013 16:34:33 +0100 Jan Kiszka <[email protected]> wrote:
Quoted 66 lines · Kim Phillips
VFIO supports pass-through of devices to user space - for sake of illustration, say a PCI e1000 device:
- the e1000 is first unbound from the PCI e1000 driver via sysfs
- the vfio-pci driver is told vianew_idthat it now handles e1000 devices
- the e1000 is explicitly bound to vfio-pci through sysfsHowever, now we have two drivers in the system that both handle e1000 devices. A hotplug event could then occur and it is ambiguous as to which driver will claim the device. The desired semantics is that vfio-pci is only bound to devices by explicit request in sysfs. This patch makes this possible by introducing a
sysfs_bind_onlyflag in structdevice_driver.Signed-off-by Stuart Yoder <[email protected]>Signed-off-by Kim Phillips <[email protected]>---
rebased onto 3.13-rc2, and reposted from first submission which recieved no comments:https://lkml.org/lkml/2013/10/11/53
drivers/base/dd.c | 5 ++++- include/linux/device.h | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-)drivers/base/dd.c +4
-1@@ -389,7 +389,7 @@ static int __device_attach(struct device_driver *drv, void *data) {struct device *dev = data; -if (!driver_match_device (drv, dev)) +if (drv->sysfs_bind_only || !driver_match_device (drv, dev))return 0 ;return driver_probe_device (drv, dev);@@ -476,6 +476,9 @@ static int __driver_attach(struct device *dev, void *data)*/ int driver_attach (struct device_driver *drv) { +if (drv->sysfs_bind_only) +return 0 ; +return bus_for_each_dev (drv->bus,NULL , drv, __driver_attach); }EXPORT_SYMBOL_GPL (driver_attach);include/linux/device.h +2
-0@@ -200,6 +200,7 @@ extern struct klist *bus_get_device_klist(struct bus_type *bus);* @owner: The module owner. * @mod_name: Used for built-in modules. * @suppress_bind_attrs: Disables bind/unbind via sysfs. +* @sysfs_bind_only: Only allow bind/unbind via sysfs. * @of_match_table: The open firmware table. * @acpi_match_table: The ACPI match table. * @probe: Called to query the existence of a specific device, @@ -233,6 +234,7 @@ struct device_driver {const char *mod_name;/* used for built-in modules */ bool suppress_bind_attrs;/* disables bind/unbind via sysfs */ +bool sysfs_bind_only;/* only allow bind/unbind via sysfs */
Quoted 7 lines
include/linux/device.h struct device_driver { · line 240
Quoted 2 lines
include/linux/device.h +0
-0const struct of_device_id *of_match_table;const struct acpi_device_id *acpi_match_table;I think I only discussed this with Stuart in person at the KVM Forum:
Why not deriving the property "sysfs bind only" from the fact that a device does wild-card binding? Are there use cases that benefit from decoupling both features?
you mean merge the two new flags sysfs_bind_only and platform driver's match_any_dev into one new single driver flag, right? good question.
I can't think of any, given none of the built-in PCI drivers set ANY_ID across the {sub}vendor/{sub}device/class{_mask} board for boot-time (or hotplug) binding. Technically it's possible with the pci_stub driver by setting its 'ids' module parameter in the kernel command line, but looking at the commit that adds 'ids', it was only meant to be used to "prevent built-in drivers from attaching to specific devices," so it's unlikely anyone would have it set to ANY_ID.
I'll look at what changes are necessary, barring anyone else coming up with a valid use-case.
Kim
Quoted 78 lines · Kim Phillips
Quoted 67 lines · On Tue, 03 Dec 2013 16:34:33 +0100 Jan Kiszka <[email protected]> wrote:
Quoted 66 lines · Kim Phillips
VFIO supports pass-through of devices to user space - for sake of illustration, say a PCI e1000 device:
- the e1000 is first unbound from the PCI e1000 driver via sysfs
- the vfio-pci driver is told vianew_idthat it now handles e1000 devices
- the e1000 is explicitly bound to vfio-pci through sysfsHowever, now we have two drivers in the system that both handle e1000 devices. A hotplug event could then occur and it is ambiguous as to which driver will claim the device. The desired semantics is that vfio-pci is only bound to devices by explicit request in sysfs. This patch makes this possible by introducing a
sysfs_bind_onlyflag in structdevice_driver.Signed-off-by Stuart Yoder <[email protected]>Signed-off-by Kim Phillips <[email protected]>---
rebased onto 3.13-rc2, and reposted from first submission which recieved no comments:https://lkml.org/lkml/2013/10/11/53
drivers/base/dd.c | 5 ++++- include/linux/device.h | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-)drivers/base/dd.c +4
-1@@ -389,7 +389,7 @@ static int __device_attach(struct device_driver *drv, void *data) {struct device *dev = data; -if (!driver_match_device (drv, dev)) +if (drv->sysfs_bind_only || !driver_match_device (drv, dev))return 0 ;return driver_probe_device (drv, dev);@@ -476,6 +476,9 @@ static int __driver_attach(struct device *dev, void *data)*/ int driver_attach (struct device_driver *drv) { +if (drv->sysfs_bind_only) +return 0 ; +return bus_for_each_dev (drv->bus,NULL , drv, __driver_attach); }EXPORT_SYMBOL_GPL (driver_attach);include/linux/device.h +2
-0@@ -200,6 +200,7 @@ extern struct klist *bus_get_device_klist(struct bus_type *bus);* @owner: The module owner. * @mod_name: Used for built-in modules. * @suppress_bind_attrs: Disables bind/unbind via sysfs. +* @sysfs_bind_only: Only allow bind/unbind via sysfs. * @of_match_table: The open firmware table. * @acpi_match_table: The ACPI match table. * @probe: Called to query the existence of a specific device, @@ -233,6 +234,7 @@ struct device_driver {const char *mod_name;/* used for built-in modules */ bool suppress_bind_attrs;/* disables bind/unbind via sysfs */ +bool sysfs_bind_only;/* only allow bind/unbind via sysfs */ Quoted 7 lines
include/linux/device.h struct device_driver { · line 240
Quoted 2 lines
include/linux/device.h +0
-0const struct of_device_id *of_match_table;const struct acpi_device_id *acpi_match_table;I think I only discussed this with Stuart in person at the KVM Forum:
Why not deriving the property "sysfs bind only" from the fact that a device does wild-card binding? Are there use cases that benefit from decoupling both features?
Quoted 2 lines
you mean merge the two new flags
sysfs_bind_onlyand platform driver'smatch_any_devinto one new single driver flag, right? good question.
What would combining them solve, other than making it more likely that Greg complains about the wildcard because it would no longer be handled at the bus level where all the other matching goes on?
They are logically separate things. That doesn't change just because we currently plan to use them together.
-Scott
Quoted 82 lines · On Thu, 5 Dec 2013 16:38:15 -0600 Scott Wood <[email protected]> wrote:
Quoted 78 lines · Kim Phillips
Quoted 67 lines · On Tue, 03 Dec 2013 16:34:33 +0100 Jan Kiszka <[email protected]> wrote:
Quoted 66 lines · Kim Phillips
VFIO supports pass-through of devices to user space - for sake of illustration, say a PCI e1000 device:
- the e1000 is first unbound from the PCI e1000 driver via sysfs
- the vfio-pci driver is told vianew_idthat it now handles e1000 devices
- the e1000 is explicitly bound to vfio-pci through sysfsHowever, now we have two drivers in the system that both handle e1000 devices. A hotplug event could then occur and it is ambiguous as to which driver will claim the device. The desired semantics is that vfio-pci is only bound to devices by explicit request in sysfs. This patch makes this possible by introducing a
sysfs_bind_onlyflag in structdevice_driver.Signed-off-by Stuart Yoder <[email protected]>Signed-off-by Kim Phillips <[email protected]>---
rebased onto 3.13-rc2, and reposted from first submission which recieved no comments:https://lkml.org/lkml/2013/10/11/53
drivers/base/dd.c | 5 ++++- include/linux/device.h | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-)drivers/base/dd.c +4
-1@@ -389,7 +389,7 @@ static int __device_attach(struct device_driver *drv, void *data) {struct device *dev = data; -if (!driver_match_device (drv, dev)) +if (drv->sysfs_bind_only || !driver_match_device (drv, dev))return 0 ;return driver_probe_device (drv, dev);@@ -476,6 +476,9 @@ static int __driver_attach(struct device *dev, void *data)*/ int driver_attach (struct device_driver *drv) { +if (drv->sysfs_bind_only) +return 0 ; +return bus_for_each_dev (drv->bus,NULL , drv, __driver_attach); }EXPORT_SYMBOL_GPL (driver_attach);include/linux/device.h +2
-0@@ -200,6 +200,7 @@ extern struct klist *bus_get_device_klist(struct bus_type *bus);* @owner: The module owner. * @mod_name: Used for built-in modules. * @suppress_bind_attrs: Disables bind/unbind via sysfs. +* @sysfs_bind_only: Only allow bind/unbind via sysfs. * @of_match_table: The open firmware table. * @acpi_match_table: The ACPI match table. * @probe: Called to query the existence of a specific device, @@ -233,6 +234,7 @@ struct device_driver {const char *mod_name;/* used for built-in modules */ bool suppress_bind_attrs;/* disables bind/unbind via sysfs */ +bool sysfs_bind_only;/* only allow bind/unbind via sysfs */ Quoted 7 lines
include/linux/device.h struct device_driver { · line 240
Quoted 2 lines
include/linux/device.h +0
-0const struct of_device_id *of_match_table;const struct acpi_device_id *acpi_match_table;I think I only discussed this with Stuart in person at the KVM Forum:
Why not deriving the property "sysfs bind only" from the fact that a device does wild-card binding? Are there use cases that benefit from decoupling both features?Quoted 2 lines
you mean merge the two new flags
sysfs_bind_onlyand platform driver'smatch_any_devinto one new single driver flag, right? good question.
Quoted 6 lines
What would combining them solve, other than making it more likely that Greg complains about the wildcard because it would no longer be handled at the bus level where all the other matching goes on?
They are logically separate things. That doesn't change just because we currently plan to use them together.
Jan? Given the above, what would be the advantage of merging sysfs_bind_only and (PCI drivers' PCI_ANY_ID and platform drivers' match_any_dev)?
Kim
Quoted 89 lines · Kim Phillips
Quoted 86 lines · On Thu, 5 Dec 2013 16:38:15 -0600 Scott Wood <[email protected]> wrote:
Quoted 78 lines · Kim Phillips
Quoted 67 lines · On Tue, 03 Dec 2013 16:34:33 +0100 Jan Kiszka <[email protected]> wrote:
Quoted 66 lines · Kim Phillips
VFIO supports pass-through of devices to user space - for sake of illustration, say a PCI e1000 device:
- the e1000 is first unbound from the PCI e1000 driver via sysfs
- the vfio-pci driver is told vianew_idthat it now handles e1000 devices
- the e1000 is explicitly bound to vfio-pci through sysfsHowever, now we have two drivers in the system that both handle e1000 devices. A hotplug event could then occur and it is ambiguous as to which driver will claim the device. The desired semantics is that vfio-pci is only bound to devices by explicit request in sysfs. This patch makes this possible by introducing a
sysfs_bind_onlyflag in structdevice_driver.Signed-off-by Stuart Yoder <[email protected]>Signed-off-by Kim Phillips <[email protected]>---
rebased onto 3.13-rc2, and reposted from first submission which recieved no comments:https://lkml.org/lkml/2013/10/11/53
drivers/base/dd.c | 5 ++++- include/linux/device.h | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-)drivers/base/dd.c +4
-1@@ -389,7 +389,7 @@ static int __device_attach(struct device_driver *drv, void *data) {struct device *dev = data; -if (!driver_match_device (drv, dev)) +if (drv->sysfs_bind_only || !driver_match_device (drv, dev))return 0 ;return driver_probe_device (drv, dev);@@ -476,6 +476,9 @@ static int __driver_attach(struct device *dev, void *data)*/ int driver_attach (struct device_driver *drv) { +if (drv->sysfs_bind_only) +return 0 ; +return bus_for_each_dev (drv->bus,NULL , drv, __driver_attach); }EXPORT_SYMBOL_GPL (driver_attach);include/linux/device.h +2
-0@@ -200,6 +200,7 @@ extern struct klist *bus_get_device_klist(struct bus_type *bus);* @owner: The module owner. * @mod_name: Used for built-in modules. * @suppress_bind_attrs: Disables bind/unbind via sysfs. +* @sysfs_bind_only: Only allow bind/unbind via sysfs. * @of_match_table: The open firmware table. * @acpi_match_table: The ACPI match table. * @probe: Called to query the existence of a specific device, @@ -233,6 +234,7 @@ struct device_driver {const char *mod_name;/* used for built-in modules */ bool suppress_bind_attrs;/* disables bind/unbind via sysfs */ +bool sysfs_bind_only;/* only allow bind/unbind via sysfs */ Quoted 7 lines
include/linux/device.h struct device_driver { · line 240
Quoted 2 lines
include/linux/device.h +0
-0const struct of_device_id *of_match_table;const struct acpi_device_id *acpi_match_table;I think I only discussed this with Stuart in person at the KVM Forum:
Why not deriving the property "sysfs bind only" from the fact that a device does wild-card binding? Are there use cases that benefit from decoupling both features?Quoted 2 lines
you mean merge the two new flags
sysfs_bind_onlyand platform driver'smatch_any_devinto one new single driver flag, right? good question.What would combining them solve, other than making it more likely that Greg complains about the wildcard because it would no longer be handled at the bus level where all the other matching goes on?
Quoted 6 lines
Quoted 2 lines
They are logically separate things. That doesn't change just because we currently plan to use them together.
Jan? Given the above, what would be the advantage of merging
sysfs_bind_onlyand (PCI drivers'PCI_ANY_IDand platform drivers'match_any_dev)?
That you cannot configure (likely) meaningless or even harmful (bind-any
+ auto-bind) configurations.
I didn't follow if Greg expressed his opinion on this or a similar scenario before. If he prefers separate knobs for a certain reason, he likely wins.
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT RTC ITP SES-DE Corporate Competence Center Embedded Linux
Quoted 11 lines · Jan Kiszka
Quoted 10 lines · Kim Phillips
Quoted 6 lines · On Thu, 5 Dec 2013 16:38:15 -0600 Scott Wood <[email protected]> wrote:
What would combining them solve, other than making it more likely that Greg complains about the wildcard because it would no longer be handled at the bus level where all the other matching goes on?
They are logically separate things. That doesn't change just because we currently plan to use them together.
Quoted 6 lines
Quoted 3 lines
Jan? Given the above, what would be the advantage of merging
sysfs_bind_onlyand (PCI drivers'PCI_ANY_IDand platform drivers'match_any_dev)?That you cannot configure (likely) meaningless or even harmful (bind-any
+ auto-bind) configurations.
If you want to put in a check that warns on bind-any plus auto-bind, fine -- but that doesn't mean they should share a mechanism. It's valid to have no-auto-bind without a wildcard match. And FWIW, PCI already has wildcard matches without any no-auto-bind mechanism (it's presumably not intended to specify PCI_ANY_ID for all fields, but it is allowed AFAICT).
-Scott
Greg Kroah-Hartman
maintainerQuoted 67 lines · Jan Kiszka
Quoted 66 lines · Kim Phillips
VFIO supports pass-through of devices to user space - for sake of illustration, say a PCI e1000 device:
- the e1000 is first unbound from the PCI e1000 driver via sysfs
- the vfio-pci driver is told vianew_idthat it now handles e1000 devices
- the e1000 is explicitly bound to vfio-pci through sysfsHowever, now we have two drivers in the system that both handle e1000 devices. A hotplug event could then occur and it is ambiguous as to which driver will claim the device. The desired semantics is that vfio-pci is only bound to devices by explicit request in sysfs. This patch makes this possible by introducing a
sysfs_bind_onlyflag in structdevice_driver.Signed-off-by Stuart Yoder <[email protected]>Signed-off-by Kim Phillips <[email protected]>---
rebased onto 3.13-rc2, and reposted from first submission which recieved no comments:https://lkml.org/lkml/2013/10/11/53
drivers/base/dd.c | 5 ++++- include/linux/device.h | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-)drivers/base/dd.c +4
-1@@ -389,7 +389,7 @@ static int __device_attach(struct device_driver *drv, void *data) {struct device *dev = data; -if (!driver_match_device (drv, dev)) +if (drv->sysfs_bind_only || !driver_match_device (drv, dev))return 0 ;return driver_probe_device (drv, dev);@@ -476,6 +476,9 @@ static int __driver_attach(struct device *dev, void *data)*/ int driver_attach (struct device_driver *drv) { +if (drv->sysfs_bind_only) +return 0 ; +return bus_for_each_dev (drv->bus,NULL , drv, __driver_attach); }EXPORT_SYMBOL_GPL (driver_attach);include/linux/device.h +2
-0@@ -200,6 +200,7 @@ extern struct klist *bus_get_device_klist(struct bus_type *bus);* @owner: The module owner. * @mod_name: Used for built-in modules. * @suppress_bind_attrs: Disables bind/unbind via sysfs. +* @sysfs_bind_only: Only allow bind/unbind via sysfs. * @of_match_table: The open firmware table. * @acpi_match_table: The ACPI match table. * @probe: Called to query the existence of a specific device, @@ -233,6 +234,7 @@ struct device_driver {const char *mod_name;/* used for built-in modules */ bool suppress_bind_attrs;/* disables bind/unbind via sysfs */ +bool sysfs_bind_only;/* only allow bind/unbind via sysfs */
Quoted 8 lines
include/linux/device.h struct device_driver { · line 240
Quoted 3 lines
include/linux/device.h +0
-0const struct of_device_id *of_match_table;const struct acpi_device_id *acpi_match_table;I think I only discussed this with Stuart in person at the KVM Forum:
Why not deriving the property "sysfs bind only" from the fact that a device does wild-card binding? Are there use cases that benefit from decoupling both features?
The driver core does not know if a bus, or a device, handles "wild card" binding, so you can't do it at this level, sorry.
greg k-h
Greg Kroah-Hartman
maintainerQuoted 7 lines · Kim Phillips
VFIO supports pass-through of devices to user space - for sake of illustration, say a PCI e1000 device:
- the e1000 is first unbound from the PCI e1000 driver via sysfs
- the vfio-pci driver is told vianew_idthat it now handles e1000 devices
- the e1000 is explicitly bound to vfio-pci through sysfs
Quoted 5 lines
However, now we have two drivers in the system that both handle e1000 devices. A hotplug event could then occur and it is ambiguous as to which driver will claim the device. The desired semantics is that vfio-pci is only bound to devices by explicit request in sysfs. This patch makes this possible by introducing a
sysfs_bind_onlyflag in structdevice_driver.
Why deal with this at all and not just deal with the "bind" sysfs file instead? That way no driver core logic needs to be changed at all, and your userspace tools know _exactly_ which device is being bound to the new device.
Don't mess with the "new_id" file for stuff like this, as you point out, it's "tricky"...
thanks,
greg k-h
Quoted 14 lines · Greg Kroah-Hartman
Quoted 7 lines · Kim Phillips
VFIO supports pass-through of devices to user space - for sake of illustration, say a PCI e1000 device:
- the e1000 is first unbound from the PCI e1000 driver via sysfs
- the vfio-pci driver is told vianew_idthat it now handles e1000 devices
- the e1000 is explicitly bound to vfio-pci through sysfsQuoted 5 lines
However, now we have two drivers in the system that both handle e1000 devices. A hotplug event could then occur and it is ambiguous as to which driver will claim the device. The desired semantics is that vfio-pci is only bound to devices by explicit request in sysfs. This patch makes this possible by introducing a
sysfs_bind_onlyflag in structdevice_driver.
Quoted 7 lines
Why deal with this at all and not just deal with the "bind" sysfs file instead? That way no driver core logic needs to be changed at all, and your userspace tools know _exactly_ which device is being bound to the new device.
Don't mess with the "
new_id" file for stuff like this, as you point out, it's "tricky"...
As discussed before, "bind" does not bypass the ID checks, and thus it does not work without either "new_id" or a wildcard match.
Or are you proposing changing "bind" so that it does bypass the ID checks? Or perhaps a new "force_bind" file that does?
-Scott
Greg Kroah-Hartman
maintainerQuoted 20 lines · Scott Wood
Quoted 19 lines · Greg Kroah-Hartman
Quoted 7 lines · Kim Phillips
VFIO supports pass-through of devices to user space - for sake of illustration, say a PCI e1000 device:
- the e1000 is first unbound from the PCI e1000 driver via sysfs
- the vfio-pci driver is told vianew_idthat it now handles e1000 devices
- the e1000 is explicitly bound to vfio-pci through sysfsQuoted 5 lines
However, now we have two drivers in the system that both handle e1000 devices. A hotplug event could then occur and it is ambiguous as to which driver will claim the device. The desired semantics is that vfio-pci is only bound to devices by explicit request in sysfs. This patch makes this possible by introducing a
sysfs_bind_onlyflag in structdevice_driver.Why deal with this at all and not just deal with the "bind" sysfs file instead? That way no driver core logic needs to be changed at all, and your userspace tools know _exactly_ which device is being bound to the new device.
Quoted 5 lines
Quoted 2 lines
Don't mess with the "
new_id" file for stuff like this, as you point out, it's "tricky"...As discussed before, "bind" does not bypass the ID checks, and thus it does not work without either "
new_id" or a wildcard match.
Ah, forgot about that.
Quoted 2 lines
Or are you proposing changing "bind" so that it does bypass the ID checks? Or perhaps a new "
force_bind" file that does?
No. But you can use bind/unbind along with the existing new_id file to get what you want today. If you just happen to bind a device to a wrong driver for a while, that's not really a problem, right?
I don't like this patch as we are adding lots of special and odd logic to the core, for use by almost no one, which ensures that it will never get tested, and will probably get broken in some subtle way in the future.
Heck, I can't even ensure that you got it right now, with this tiny patch, how do you know it works given that there are no users of this flag anywhere (hint, you never showed me any...)
greg k-h
Quoted 50 lines
-----Original Message-----
From: Greg Kroah-Hartman [mailto:[email protected]]
Sent: Thursday, December 19, 2013 2:34 PM
To: Wood Scott-B07421
Cc: Kim Phillips; [email protected]; [email protected]; Bhushan Bharat-R65777; Yoder Stuart-B08248; [email protected]; [email protected]; [email protected]; [email protected]; Sethi Varun-B16395
Subject: Re: [REPOST][PATCH 1/2] driver core: Add newdevice_driverflag to allow binding via sysfs onlyQuoted 7 lines · Scott Wood
Quoted 6 lines · Greg Kroah-Hartman
Quoted 5 lines · Kim Phillips
VFIO supports pass-through of devices to user space - for sake of illustration, say a PCI e1000 device:
- the e1000 is first unbound from the PCI e1000 driver via sysfs
- the vfio-pci driver is told vianew_idthat it now handles e1000devices
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
- the e1000 is explicitly bound to vfio-pci through sysfs
However, now we have two drivers in the system that both handle
e1000
Quoted 1 line
Quoted 1 line
Quoted 1 line
devices. A hotplug event could then occur and it is ambiguous as
to which
Quoted 1 line
Quoted 1 line
Quoted 1 line
driver will claim the device. The desired semantics is that vfio-
pci is
Quoted 1 line
Quoted 1 line
Quoted 1 line
only bound to devices by explicit request in sysfs. This patch
makes this
Quoted 1 line
Quoted 1 line
Quoted 1 line
possible by introducing a
sysfs_bind_onlyflag in struct
device_driver.Quoted 2 lines
Quoted 2 lines
Why deal with this at all and not just deal with the "bind" sysfs
file
Quoted 1 line
Quoted 1 line
instead? That way no driver core logic needs to be changed at all,
and
Quoted 1 line
Quoted 1 line
your userspace tools know _exactly_ which device is being bound to
the
Quoted 3 lines
Quoted 3 lines
new device.
Don't mess with the "
new_id" file for stuff like this, as you pointout,
Quoted 4 lines
Quoted 1 line
it's "tricky"...
As discussed before, "bind" does not bypass the ID checks, and thus it does not work without either "
new_id" or a wildcard match.
Quoted 7 lines
Ah, forgot about that.
Quoted 2 lines
Or are you proposing changing "bind" so that it does bypass the ID checks? Or perhaps a new "
force_bind" file that does?No. But you can use bind/unbind along with the existing
new_idfile to get what you want today.
Yes, but that only works for PCI. There is no such concept for platform drivers.
Quoted 2 lines
If you just happen to bind a device to a wrong driver for a while, that's not really a problem, right?
It's annoying but not the end of the world.
Quoted 4 lines
I don't like this patch as we are adding lots of special and odd logic to the core, for use by almost no one, which ensures that it will never get tested, and will probably get broken in some subtle way in the future.
It certainly will be used by users of vfio-platform.
Here is the problem-- the new platform device "match_any_dev" mechanism in patch 2 of this series is not going to work without "sysfs_bind_only". A platform driver that just sets "match_any_dev" will grab any or all platform devices during normal bus probing.
Quoted 3 lines
Heck, I can't even ensure that you got it right now, with this tiny patch, how do you know it works given that there are no users of this flag anywhere (hint, you never showed me any...)
It has been tested on both vfio-pci and vfio-platform in some limited experiments as far as I know, but that code is not ready for upstream yet.
Thanks,
Stuart
Greg Kroah-Hartman
maintainerQuoted 52 lines · Stuart Yoder
Quoted 52 lines
-----Original Message-----
From: Greg Kroah-Hartman [mailto:[email protected]]
Sent: Thursday, December 19, 2013 2:34 PM
To: Wood Scott-B07421
Cc: Kim Phillips; [email protected]; [email protected]; Bhushan Bharat-R65777; Yoder Stuart-B08248; [email protected]; [email protected]; [email protected]; [email protected]; Sethi Varun-B16395
Subject: Re: [REPOST][PATCH 1/2] driver core: Add newdevice_driverflag to allow binding via sysfs onlyQuoted 7 lines · Scott Wood
Quoted 6 lines · Greg Kroah-Hartman
Quoted 5 lines · Kim Phillips
VFIO supports pass-through of devices to user space - for sake of illustration, say a PCI e1000 device:
- the e1000 is first unbound from the PCI e1000 driver via sysfs
- the vfio-pci driver is told vianew_idthat it now handles e1000devices
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
- the e1000 is explicitly bound to vfio-pci through sysfs
However, now we have two drivers in the system that both handle
e1000
Quoted 1 line
Quoted 1 line
Quoted 1 line
devices. A hotplug event could then occur and it is ambiguous as
to which
Quoted 1 line
Quoted 1 line
Quoted 1 line
driver will claim the device. The desired semantics is that vfio-
pci is
Quoted 1 line
Quoted 1 line
Quoted 1 line
only bound to devices by explicit request in sysfs. This patch
makes this
Quoted 1 line
Quoted 1 line
Quoted 1 line
possible by introducing a
sysfs_bind_onlyflag in struct
device_driver.Quoted 2 lines
Quoted 2 lines
Why deal with this at all and not just deal with the "bind" sysfs
file
Quoted 1 line
Quoted 1 line
instead? That way no driver core logic needs to be changed at all,
and
Quoted 1 line
Quoted 1 line
your userspace tools know _exactly_ which device is being bound to
the
Quoted 3 lines
Quoted 3 lines
new device.
Don't mess with the "
new_id" file for stuff like this, as you pointout,
Quoted 4 lines
Quoted 1 line
it's "tricky"...
As discussed before, "bind" does not bypass the ID checks, and thus it does not work without either "
new_id" or a wildcard match.Ah, forgot about that.
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
Or are you proposing changing "bind" so that it does bypass the ID checks? Or perhaps a new "
force_bind" file that does?No. But you can use bind/unbind along with the existing
new_idfile to get what you want today.Yes, but that only works for PCI.
No, not only PCI.
Quoted 1 line
There is no such concept for platform drivers.
Then fix that.
Or make your device not be a platform device, odds are that's the better solution in the end, right?
Quoted 10 lines
Quoted 2 lines
If you just happen to bind a device to a wrong driver for a while, that's not really a problem, right?
It's annoying but not the end of the world.
Quoted 4 lines
I don't like this patch as we are adding lots of special and odd logic to the core, for use by almost no one, which ensures that it will never get tested, and will probably get broken in some subtle way in the future.
Quoted 6 lines
It certainly will be used by users of vfio-platform.
Here is the problem-- the new platform device "
match_any_dev" mechanism in patch 2 of this series is not going to work without "sysfs_bind_only". A platform driver that just sets "match_any_dev" will grab any or all platform devices during normal bus probing.
No it will not, it will fail in the probe function as it knows to not grab the device, just like any driver for other busses that say it can "handle all Intel PCI devices" and the like.
Quoted 7 lines
Quoted 3 lines
Heck, I can't even ensure that you got it right now, with this tiny patch, how do you know it works given that there are no users of this flag anywhere (hint, you never showed me any...)
It has been tested on both vfio-pci and vfio-platform in some limited experiments as far as I know, but that code is not ready for upstream yet.
Then I'll wait until you get something that actually is worth upstreaming before worrying about this again.
greg k-h
Quoted 17 lines · Greg Kroah-Hartman
Quoted 16 lines · Stuart Yoder
Quoted 15 lines
-----Original Message-----
From: Greg Kroah-Hartman [mailto:[email protected]]
Sent: Thursday, December 19, 2013 2:34 PM
To: Wood Scott-B07421
Cc: Kim Phillips; [email protected]; [email protected]; Bhushan Bharat-R65777; Yoder Stuart-B08248; [email protected]; [email protected]; [email protected]; [email protected]; Sethi Varun-B16395
Subject: Re: [REPOST][PATCH 1/2] driver core: Add newdevice_driverflag to allow binding via sysfs onlyNo. But you can use bind/unbind along with the existing
new_idfile to get what you want today.
Quoted 7 lines
Quoted 1 line
Yes, but that only works for PCI.
No, not only PCI.
Quoted 1 line
There is no such concept for platform drivers.
Then fix that.
We've already explained why that would be bad.
Quoted 2 lines
Or make your device not be a platform device, odds are that's the better solution in the end, right?
How would that solve anything? We'd just be talking about there not being such a mechanism for the device tree "bus" instead.
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines
If you just happen to bind a device to a wrong driver for a while, that's not really a problem, right?
It's annoying but not the end of the world.
Lots of bugs are "not the end of the world" but that doesn't mean we don't fix them. It certainly doesn't mean we duplicate the source of the bug in new subsystems.
Quoted 7 lines
Quoted 7 lines
Quoted 4 lines
I don't like this patch as we are adding lots of special and odd logic to the core, for use by almost no one, which ensures that it will never get tested, and will probably get broken in some subtle way in the future.
It certainly will be used by users of vfio-platform.
Quoted 8 lines
Quoted 4 lines
Here is the problem-- the new platform device "
match_any_dev" mechanism in patch 2 of this series is not going to work without "sysfs_bind_only". A platform driver that just sets "match_any_dev" will grab any or all platform devices during normal bus probing.No it will not, it will fail in the probe function as it knows to not grab the device, just like any driver for other busses that say it can "handle all Intel PCI devices" and the like.
How will it "know not to grab the device"? The knowledge of whether the binding was explicitly requested or not does not get passed through to the probe function.
It would be a shame to have to implement code in VFIO, and a userspace interface to go along with it, to keep track of which devices have been authorized to be bound when we already have sysfs bind -- we just need a way to differentiate that from automatic binding.
-Scott
Greg Kroah-Hartman
maintainerQuoted 20 lines · Scott Wood
Quoted 19 lines · Greg Kroah-Hartman
Quoted 17 lines · Stuart Yoder
Quoted 13 lines
-----Original Message-----
From: Greg Kroah-Hartman [mailto:[email protected]]
Sent: Thursday, December 19, 2013 2:34 PM
To: Wood Scott-B07421
Cc: Kim Phillips; [email protected]; [email protected]; Bhushan Bharat-R65777; Yoder Stuart-B08248; [email protected]; [email protected]; [email protected]; [email protected]; Sethi Varun-B16395
Subject: Re: [REPOST][PATCH 1/2] driver core: Add newdevice_driverflag to allow binding via sysfs onlyQuoted 2 lines
No. But you can use bind/unbind along with the existing
new_idfile to get what you want today.Yes, but that only works for PCI.
Quoted 7 lines
Quoted 5 lines
No, not only PCI.
Quoted 1 line
There is no such concept for platform drivers.
Then fix that.
We've already explained why that would be bad.
No you haven't, or if you have, my squirrel-brain doesn't remember it...
Quoted 5 lines
Quoted 2 lines
Or make your device not be a platform device, odds are that's the better solution in the end, right?
How would that solve anything? We'd just be talking about there not being such a mechanism for the device tree "bus" instead.
Nope, you could add it there, like PCI and other busses have.
Quoted 12 lines
Quoted 12 lines
Quoted 11 lines
Quoted 4 lines
I don't like this patch as we are adding lots of special and odd logic to the core, for use by almost no one, which ensures that it will never get tested, and will probably get broken in some subtle way in the future.
It certainly will be used by users of vfio-platform.
Here is the problem-- the new platform device "
match_any_dev" mechanism in patch 2 of this series is not going to work without "sysfs_bind_only". A platform driver that just sets "match_any_dev" will grab any or all platform devices during normal bus probing.
Quoted 7 lines
Quoted 3 lines
No it will not, it will fail in the probe function as it knows to not grab the device, just like any driver for other busses that say it can "handle all Intel PCI devices" and the like.
How will it "know not to grab the device"? The knowledge of whether the binding was explicitly requested or not does not get passed through to the probe function.
Nor should it, as a driver should not know, nor care about this.
It's up to the BUS to handle this if it really wants to, and I'm afraid that I really am not convinced that the driver core needs to handle it either.
But again, as you don't have anything that could actually use this code that is mergable, it's a totally moot point, sorry.
greg k-h
Quoted 85 lines
-----Original Message-----
From: Greg Kroah-Hartman [mailto:[email protected]]
Sent: Thursday, December 19, 2013 4:32 PM
To: Wood Scott-B07421
Cc: Yoder Stuart-B08248; Kim Phillips; [email protected]; [email protected]; Bhushan Bharat-R65777; [email protected]; [email protected]; [email protected]; [email protected]; Sethi Varun-B16395
Subject: Re: [REPOST][PATCH 1/2] driver core: Add newdevice_driverflag to allow binding via sysfs onlyQuoted 9 lines · Scott Wood
Quoted 8 lines · Greg Kroah-Hartman
Quoted 7 lines · Stuart Yoder
Quoted 7 lines
-----Original Message-----
From: Greg Kroah-Hartman [mailto:[email protected]]
Sent: Thursday, December 19, 2013 2:34 PM
To: Wood Scott-B07421
Cc: Kim Phillips; [email protected];Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Bhushan Bharat-R65777; Yoder Stuart-B08248;
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
[email protected]; [email protected]; [email protected]; Sethi Varun-B16395
Subject: Re: [REPOST][PATCH 1/2] driver core: Add new
device_driverflagQuoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
to allow binding via sysfs only
No. But you can use bind/unbind along with the existing
new_idfile to
Quoted 11 lines
Quoted 9 lines
Quoted 3 lines
Quoted 1 line
get what you want today.
Yes, but that only works for PCI.
No, not only PCI.
Quoted 1 line
There is no such concept for platform drivers.
Then fix that.
We've already explained why that would be bad.
No you haven't, or if you have, my squirrel-brain doesn't remember it...
Quoted 1 line
Quoted 1 line
Or make your device not be a platform device, odds are that's the
better
Quoted 4 lines
Quoted 1 line
solution in the end, right?
How would that solve anything? We'd just be talking about there not being such a mechanism for the device tree "bus" instead.
Nope, you could add it there, like PCI and other busses have.
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
I don't like this patch as we are adding lots of special and odd
logic
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
to the core, for use by almost no one, which ensures that it will
never
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
get tested, and will probably get broken in some subtle way in
the
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 1 line
future.
It certainly will be used by users of vfio-platform.
Here is the problem-- the new platform device "
match_any_dev"mechanism
Quoted 1 line
Quoted 1 line
Quoted 1 line
in patch 2 of this series is not going to work without
"
sysfs_bind_only".Quoted 1 line
Quoted 1 line
Quoted 1 line
A platform driver that just sets "
match_any_dev" will grab any orall
Quoted 4 lines
Quoted 4 lines
Quoted 1 line
platform devices during normal bus probing.
No it will not, it will fail in the probe function as it knows to not grab the device, just like any driver for other busses that say it
can
Quoted 3 lines
Quoted 1 line
"handle all Intel PCI devices" and the like.
How will it "know not to grab the device"? The knowledge of whether
the
Quoted 2 lines
binding was explicitly requested or not does not get passed through to the probe function.
Quoted 8 lines
Nor should it, as a driver should not know, nor care about this.
It's up to the BUS to handle this if it really wants to, and I'm afraid that I really am not convinced that the driver core needs to handle it either.
But again, as you don't have anything that could actually use this code that is mergable, it's a totally moot point, sorry.
Understand, but what assumption do we develop vfio-plaform with? That a driver core 'sysfs_bind_only' flag is not an option, period? If that is the case we need to go back to square one and invent some new mechanism to bind devices to the vfio-platform driver.
I guess it would need to be the platform bus equivalent of new_id.
But, then we're left with the potential racy situation where multiple drivers can potentially grab a device and it's ambiguous and non-deterministic at to which driver binds to it.
Stuart
Greg Kroah-Hartman
maintainerQuoted 11 lines · Stuart Yoder
Quoted 11 lines
Quoted 1 line
How will it "know not to grab the device"? The knowledge of whether
the
Quoted 2 lines
binding was explicitly requested or not does not get passed through to the probe function.
Nor should it, as a driver should not know, nor care about this.
It's up to the BUS to handle this if it really wants to, and I'm afraid that I really am not convinced that the driver core needs to handle it either.
Quoted 7 lines
Quoted 2 lines
But again, as you don't have anything that could actually use this code that is mergable, it's a totally moot point, sorry.
Understand, but what assumption do we develop vfio-plaform with? That a driver core '
sysfs_bind_only' flag is not an option, period? If that is the case we need to go back to square one and invent some new mechanism to bind devices to the vfio-platform driver.
Ok, why the total confusion between PCI and platform devices here? Why keep mentioning both of them in a semi-interchangeable way?
Quoted 1 line
I guess it would need to be the platform bus equivalent of
new_id.
Then add it, there's nothing stopping the platform bus from supporting this.
Quoted 3 lines
But, then we're left with the potential racy situation where multiple drivers can potentially grab a device and it's ambiguous and non-deterministic at to which driver binds to it.
Welcome to life in hotpluggable systems, this is nothing new :)
Seriously, userspace has the ability to sort this all out after devices show up, use it. Don't try to create convoluted schemes in the driver core that are confusing and don't really seem to work.
People have asked for a "priority" of drivers binding to devices for over a decade now, as "other" operating systems have it. Turns out, no one has ever needed it badly enough to actually implement it...
good luck,
greg k-h