VFIO: platform: AMD xgbe reset module
Subsystems (4)
PATCH 1/1 VFIO: platform: AMD xgbe reset module
This patch introduces a module that registers and implements a low-level reset function for the AMD XGBE device.
it performs the following actions:
- reset the PHY
- disable auto-negotiation
- disable & clear auto-negotiation IRQ
- soft-reset the MAC
Those tiny pieces of code are inherited from the native xgbe driver.
--- drivers/vfio/platform/reset/Kconfig | 7 ++ drivers/vfio/platform/reset/Makefile | 2 + .../vfio/platform/reset/vfio_platform_amdxgbe.c | 130 +++++++++++++++++++++ drivers/vfio/platform/vfio_platform_common.c | 5 + 4 files changed, 144 insertions(+) create mode 100644 drivers/vfio/platform/reset/vfio_platform_amdxgbe.c
drivers/vfio/platform/reset/Kconfig +7 -0
@@ -5,3 +5,10 @@ config VFIO_PLATFORM_CALXEDAXGMAC_RESET Enables the VFIO platform driver to handle reset for Calxeda xgmac If you don't know what to do here, say N. +config VFIO_PLATFORM_AMDXGBE_RESET + tristate "VFIO support for AMD XGBE reset" + depends on VFIO_PLATFORM + help + Enables the VFIO platform driver to handle reset for AMD XGBE + + If you don't know what to do here, say N.
drivers/vfio/platform/reset/Makefile +2 -0
@@ -1,5 +1,7 @@ vfio-platform-calxedaxgmac-y := vfio_platform_calxedaxgmac.o +vfio-platform-amdxgbe-y := vfio_platform_amdxgbe.o ccflags-y += -Idrivers/vfio/platform obj-$(CONFIG_VFIO_PLATFORM_CALXEDAXGMAC_RESET) += vfio-platform-calxedaxgmac.o +obj-$(CONFIG_VFIO_PLATFORM_AMDXGBE_RESET) += vfio-platform-amdxgbe.o
drivers/vfio/platform/reset/vfio_platform_amdxgbe.c new file +130 -0
130 lines not on this page · raw message
drivers/vfio/platform/vfio_platform_common.c +5 -0
@@ -31,6 +31,11 @@ static const struct vfio_platform_reset_combo reset_lookup_table[] = { .reset_function_name = "vfio_platform_calxedaxgmac_reset", .module_name = "vfio-platform-calxedaxgmac", }, + { + .compat = "amd,xgbe-seattle-v1a", + .reset_function_name = "vfio_platform_amdxgbe_reset", + .module_name = "vfio-platform-amdxgbe", + }, }; static void vfio_platform_get_reset(struct vfio_platform_device *vdev,
Signature · 1 line
1.9.1
Quoted 5 lines · On Wednesday 14 October 2015 15:33:12 Eric Auger wrote:
drivers/vfio/platform/vfio_platform_common.c +0
-0@@ -31,6 +31,11 @@ static const struct vfio_platform_reset_combo reset_lookup_table[] = { .reset_function_name = "vfio_platform_calxedaxgmac_reset",
drivers/vfio/platform/vfio_platform_common.c static const struct vfio_platform_reset_combo reset_lookup_table[] = { · line 41
Quoted 10 lines
drivers/vfio/platform/vfio_platform_common.c +5
-0.module_name = "vfio-platform-calxedaxgmac", }, + { + .compat = "amd,xgbe-seattle-v1a", + .reset_function_name = "vfio_platform_amdxgbe_reset", + .module_name = "vfio-platform-amdxgbe", + }, }; static void vfio_platform_get_reset(struct vfio_platform_device *vdev,
This is causing build errors for me when CONFIG_MODULES is disabled.
Could this please be restructured so vfio_platform_get_reset does not attempt to call __symbol_get() but instead has the drivers register themselves properly to a subsystem?
I don't see any way this could be fixed otherwise. The problem of course showed up with calxedaxgmac already, but I'd prefer not to see anything added there until the common code has been improved.
Arnd
Hi Arnd,
Quoted 14 lines · Arnd Bergmann
Quoted 13 lines · On Wednesday 14 October 2015 15:33:12 Eric Auger wrote:
drivers/vfio/platform/vfio_platform_common.c +5
-0@@ -31,6 +31,11 @@ static const struct vfio_platform_reset_combo reset_lookup_table[] = { .reset_function_name = "vfio_platform_calxedaxgmac_reset", .module_name = "vfio-platform-calxedaxgmac", }, + { + .compat = "amd,xgbe-seattle-v1a", + .reset_function_name = "vfio_platform_amdxgbe_reset", + .module_name = "vfio-platform-amdxgbe", + }, };
Quoted 4 lines
drivers/vfio/platform/vfio_platform_common.c static const struct vfio_platform_reset_combo reset_lookup_table[] = { · line 41
Quoted 2 lines
drivers/vfio/platform/vfio_platform_common.c +0
-0static void vfio_platform_get_reset(struct vfio_platform_device *vdev,This is causing build errors for me when
CONFIG_MODULESis disabled.
Sorry about that and thanks for reporting the issue
Quoted 4 lines
Could this please be restructured so
vfio_platform_get_resetdoes not attempt to call__symbol_get()but instead has the drivers register themselves properly to a subsystem?
OK
Could you elaborate about "has the drivers register themselves properly to a subsystem".
My first proposal when coping with this problematic of being able to add reset plugins to the vfio-platform driver was to create new drivers per device requiring reset. but this was considered painful for end-users, who needed to be aware of the right driver to bind - and I think that makes sense - (https://lkml.org/lkml/2015/4/17/568) .
A naive question I dare to ask, wouldn't it be acceptable to make vfio_platform depend on CONFIG_MODULES? Don't we disable modules for security purpose? In that context would we use VFIO?
Best Regards
Eric
Quoted 7 lines
I don't see any way this could be fixed otherwise. The problem of course showed up with calxedaxgmac already, but I'd prefer not to see anything added there until the common code has been improved.
Arnd
Quoted 27 lines · On Thursday 15 October 2015 10:08:02 Eric Auger wrote:
Hi Arnd,
Quoted 14 lines · Arnd Bergmann
Quoted 13 lines · On Wednesday 14 October 2015 15:33:12 Eric Auger wrote:
drivers/vfio/platform/vfio_platform_common.c +5
-0@@ -31,6 +31,11 @@ static const struct vfio_platform_reset_combo reset_lookup_table[] = { .reset_function_name = "vfio_platform_calxedaxgmac_reset", .module_name = "vfio-platform-calxedaxgmac", }, + { + .compat = "amd,xgbe-seattle-v1a", + .reset_function_name = "vfio_platform_amdxgbe_reset", + .module_name = "vfio-platform-amdxgbe", + }, };Quoted 4 lines
drivers/vfio/platform/vfio_platform_common.c static const struct vfio_platform_reset_combo reset_lookup_table[] = { · line 41
Quoted 2 lines
drivers/vfio/platform/vfio_platform_common.c +0
-0static void vfio_platform_get_reset(struct vfio_platform_device *vdev,This is causing build errors for me when
CONFIG_MODULESis disabled.Sorry about that and thanks for reporting the issue
Quoted 4 lines
Could this please be restructured so
vfio_platform_get_resetdoes not attempt to call__symbol_get()but instead has the drivers register themselves properly to a subsystem?OK
Quoted 8 lines
Could you elaborate about "has the drivers register themselves properly to a subsystem".
My first proposal when coping with this problematic of being able to add reset plugins to the vfio-platform driver was to create new drivers per device requiring reset. but this was considered painful for end-users, who needed to be aware of the right driver to bind - and I think that makes sense - (https://lkml.org/lkml/2015/4/17/568) .
Having multiple drivers indeed sucks, but your current approach isn't that much better, as you still have two modules that are used to driver the same hardware.
I would expect that the same driver that is used for the normal operation and that it calls a function to register itself to vfio by passing a structure with the device and reset function pointer.
Quoted 3 lines
A naive question I dare to ask, wouldn't it be acceptable to make
vfio_platformdepend onCONFIG_MODULES? Don't we disable modules for security purpose? In that context would we use VFIO?
I think a lot of embedded systems turn off modules to save a little memory, speed up boot time and simplify their user space.
Aside from that, the current method is highly unusual and looks a bit fragile to me, as you are relying on internals of the module loader code. It's also a layering violation as the generic code needs to be patched for each device specific module that is added, and we try to avoid that.
A possible solution could be something inside the xgbe driver like
static void xgbe_init_module(void)
{
int ret = 0;
if (IS_ENABLED(CONFIG_AMD_XGBE_ETHERNET)
ret = platform_driver_register(&xgbe_driver);
if (ret)
return ret;
if (IS_ENABLED(CONFIG_VFIO_PLATFORM))
ret = vfio_platform_register_reset(&xgbe_of_match, xgbe_platform_reset);
return ret;
}This way you have exactly one driver module that gets loaded for the device and you can use it either with the platform_driver or through vfio.
A nicer way that would be a little more work would be to integrate the reset infrastructure into 'struct platform_driver' framework, by adding another callback to the it for doing the interaction with vfio, something like
enum vfio_platform_op {
VFIO_PLATFORM_BIND,
VFIO_PLATFORM_UNBIND,
VFIO_PLATFORM_RESET,
};
struct platform_driver {
int (*probe)(struct platform_device *);
int (*remove)(struct platform_device *);
...
int (*vfio_manage)(struct platform_device *, enum vfio_platform_op);
struct device_driver driver;
};This would integrate much more closely into the platform driver framework, just like the regular vfio driver integrates into the PCI framework. Unlike PCI however, you can't just use the generic driver framework to unbind the driver, because you still need device specific code.
Arnd
Quoted 99 lines · Arnd Bergmann
Quoted 27 lines · On Thursday 15 October 2015 10:08:02 Eric Auger wrote:
Hi Arnd,
Quoted 14 lines · Arnd Bergmann
Quoted 13 lines · On Wednesday 14 October 2015 15:33:12 Eric Auger wrote:
drivers/vfio/platform/vfio_platform_common.c +5
-0@@ -31,6 +31,11 @@ static const struct vfio_platform_reset_combo reset_lookup_table[] = { .reset_function_name = "vfio_platform_calxedaxgmac_reset", .module_name = "vfio-platform-calxedaxgmac", }, + { + .compat = "amd,xgbe-seattle-v1a", + .reset_function_name = "vfio_platform_amdxgbe_reset", + .module_name = "vfio-platform-amdxgbe", + }, };Quoted 4 lines
drivers/vfio/platform/vfio_platform_common.c static const struct vfio_platform_reset_combo reset_lookup_table[] = { · line 41
Quoted 2 lines
drivers/vfio/platform/vfio_platform_common.c +0
-0static void vfio_platform_get_reset(struct vfio_platform_device *vdev,This is causing build errors for me when
CONFIG_MODULESis disabled.Sorry about that and thanks for reporting the issue
Quoted 4 lines
Could this please be restructured so
vfio_platform_get_resetdoes not attempt to call__symbol_get()but instead has the drivers register themselves properly to a subsystem?OK
Quoted 8 lines
Could you elaborate about "has the drivers register themselves properly to a subsystem".
My first proposal when coping with this problematic of being able to add reset plugins to the vfio-platform driver was to create new drivers per device requiring reset. but this was considered painful for end-users, who needed to be aware of the right driver to bind - and I think that makes sense - (https://lkml.org/lkml/2015/4/17/568) .
Having multiple drivers indeed sucks, but your current approach isn't that much better, as you still have two modules that are used to driver the same hardware.
I would expect that the same driver that is used for the normal operation and that it calls a function to register itself to vfio by passing a structure with the device and reset function pointer.
Quoted 3 lines
A naive question I dare to ask, wouldn't it be acceptable to make
vfio_platformdepend onCONFIG_MODULES? Don't we disable modules for security purpose? In that context would we use VFIO?I think a lot of embedded systems turn off modules to save a little memory, speed up boot time and simplify their user space.
Aside from that, the current method is highly unusual and looks a bit fragile to me, as you are relying on internals of the module loader code. It's also a layering violation as the generic code needs to be patched for each device specific module that is added, and we try to avoid that.
A possible solution could be something inside the xgbe driver like
static void
xgbe_init_module(void){ int ret = 0; if (IS_ENABLED(CONFIG_AMD_XGBE_ETHERNET) ret = platform_driver_register(&xgbe_driver); if (ret) return ret; if (IS_ENABLED(CONFIG_VFIO_PLATFORM)) ret = vfio_platform_register_reset(&xgbe_of_match, xgbe_platform_reset); return ret; }This way you have exactly one driver module that gets loaded for the device and you can use it either with the
platform_driveror through vfio.A nicer way that would be a little more work would be to integrate the reset infrastructure into 'struct
platform_driver' framework, by adding another callback to the it for doing the interaction with vfio, something likeenum
vfio_platform_op{
VFIO_PLATFORM_BIND,
VFIO_PLATFORM_UNBIND,
VFIO_PLATFORM_RESET,
};struct platform_driver { int (*probe)(struct platform_device *); int (*remove)(struct platform_device *); ... int (*vfio_manage)(struct platform_device *, enum vfio_platform_op); struct device_driver driver; };
Quoted 5 lines
This would integrate much more closely into the platform driver framework, just like the regular vfio driver integrates into the PCI framework. Unlike PCI however, you can't just use the generic driver framework to unbind the driver, because you still need device specific code.
Thanks for these suggestions, really helpful.
What I don't understand in the latter example is how VFIO knows which struct platform_driver to interact with?
Also, just so I'm sure I understand correctly, VFIO_PLATFORM_UNBIND is then called by VFIO before the VFIO driver unbinds from the device (unbinding the platform driver from the device being a completely separate thing)?
Thanks,
-Christoffer
Quoted 20 lines · On Thursday 15 October 2015 14:12:28 Christoffer Dall wrote:
Quoted 15 lines
enum
vfio_platform_op{
VFIO_PLATFORM_BIND,
VFIO_PLATFORM_UNBIND,
VFIO_PLATFORM_RESET,
};struct platform_driver { int (*probe)(struct platform_device *); int (*remove)(struct platform_device *); ... int (*vfio_manage)(struct platform_device *, enum vfio_platform_op); struct device_driver driver; };Quoted 5 lines
This would integrate much more closely into the platform driver framework, just like the regular vfio driver integrates into the PCI framework. Unlike PCI however, you can't just use the generic driver framework to unbind the driver, because you still need device specific code.
Quoted 4 lines
Thanks for these suggestions, really helpful.
What I don't understand in the latter example is how VFIO knows which struct
platform_driverto interact with?
This would assume that the driver remains bound to the device, so VFIO gets a pointer to the device from somewhere (as it does today) and then follows the dev->driver pointer to get to the platform_driver.
Quoted 4 lines
Also, just so I'm sure I understand correctly,
VFIO_PLATFORM_UNBINDis then called by VFIO before the VFIO driver unbinds from the device (unbinding the platform driver from the device being a completely separate thing)?
This is where we'd need a little more changes for this approach. Instead of unbinding the device from its driver, the idea would be that the driver remains bound as far as the driver model is concerned, but it would be in a quiescent state where no other subsystem interacts with it (i.e. it gets unregistered from networking core or whichever it uses).
Arnd
Hi Arnd,
Quoted 36 lines · Arnd Bergmann
Quoted 20 lines · On Thursday 15 October 2015 14:12:28 Christoffer Dall wrote:
Quoted 15 lines
enum
vfio_platform_op{
VFIO_PLATFORM_BIND,
VFIO_PLATFORM_UNBIND,
VFIO_PLATFORM_RESET,
};struct platform_driver { int (*probe)(struct platform_device *); int (*remove)(struct platform_device *); ... int (*vfio_manage)(struct platform_device *, enum vfio_platform_op); struct device_driver driver; };Quoted 5 lines
This would integrate much more closely into the platform driver framework, just like the regular vfio driver integrates into the PCI framework. Unlike PCI however, you can't just use the generic driver framework to unbind the driver, because you still need device specific code.
Quoted 4 lines
Thanks for these suggestions, really helpful.
What I don't understand in the latter example is how VFIO knows which struct
platform_driverto interact with?This would assume that the driver remains bound to the device, so VFIO gets a pointer to the device from somewhere (as it does today) and then follows the
dev->driverpointer to get to theplatform_driver.Quoted 4 lines
Also, just so I'm sure I understand correctly,
VFIO_PLATFORM_UNBINDis then called by VFIO before the VFIO driver unbinds from the device (unbinding the platform driver from the device being a completely separate thing)?
Quoted 5 lines
This is where we'd need a little more changes for this approach. Instead of unbinding the device from its driver, the idea would be that the driver remains bound as far as the driver model is concerned, but it would be in a quiescent state where no other subsystem interacts with it (i.e. it gets unregistered from networking core or whichever it uses).
Currently we use the same mechanism as for PCI, ie. unbind the native driver and then bind VFIO platform driver in its place. Don't you think changing this may be a pain for user-space tools that are designed to work that way for PCI?
My personal preference would be to start with your first proposal since it looks (to me) less complex and "unknown" that the 2d approach.
Let's wait for Alex opinion too...
Thanks again
Eric
Quoted 3 lines
Arnd
Quoted 7 lines · On Thursday 15 October 2015 16:46:09 Eric Auger wrote:
Quoted 6 lines
This is where we'd need a little more changes for this approach. Instead of unbinding the device from its driver, the idea would be that the driver remains bound as far as the driver model is concerned, but it would be in a quiescent state where no other subsystem interacts with it (i.e. it gets unregistered from networking core or whichever it uses).
Quoted 7 lines
Currently we use the same mechanism as for PCI, ie. unbind the native driver and then bind VFIO platform driver in its place. Don't you think changing this may be a pain for user-space tools that are designed to work that way for PCI?
My personal preference would be to start with your first proposal since it looks (to me) less complex and "unknown" that the 2d approach.
We certainly can't easily change from one approach to the other without breaking user expectations, so the decision needs to be made carefully.
The main observation here is that platform devices are unlike PCI in this regard because they need extra per-device code. I have argued in the past that we should not reuse the "VFIO" name here because it's actually something else. On the other hand, there are a lot of commonalities, we just have to make sure we don't try to force the code into one model that doesn't really work just to make it look more like PCI VFIO.
Arnd
Quoted 16 lines · Arnd Bergmann
Quoted 7 lines · On Thursday 15 October 2015 16:46:09 Eric Auger wrote:
Quoted 6 lines
This is where we'd need a little more changes for this approach. Instead of unbinding the device from its driver, the idea would be that the driver remains bound as far as the driver model is concerned, but it would be in a quiescent state where no other subsystem interacts with it (i.e. it gets unregistered from networking core or whichever it uses).
Quoted 7 lines
Currently we use the same mechanism as for PCI, ie. unbind the native driver and then bind VFIO platform driver in its place. Don't you think changing this may be a pain for user-space tools that are designed to work that way for PCI?
My personal preference would be to start with your first proposal since it looks (to me) less complex and "unknown" that the 2d approach.
Quoted 7 lines
We certainly can't easily change from one approach to the other without breaking user expectations, so the decision needs to be made carefully.
The main observation here is that platform devices are unlike PCI in this regard because they need extra per-device code. I have argued in the past that we should not reuse the "VFIO" name here because it's actually something else.
I've adjusted to consider VFIO a general purpose framework for mapping device resources into userspace/VMs, and there are certainly a lot of commonality with both PCI, platform, and potentially other devices for that to make sense.
Quoted 4 lines
On the other hand, there are a lot of commonalities,
we just have to make sure we don't try to force the code into one model that doesn't really work just to make it look more like PCI VFIO.
But given that we now have code for platform device passthrough that works in both QEMU and the kernel side and is actually useful for people, is there a clear technical advantage to go back and rework thaat at this point?
Don't get me wrong, I like the idea of having a single driver bound to a platform device, and then that's it, but it just feels like that discussion doesn't necessarily belong in the context of a patch that 'just' seeks to add reset functionality for a specific device for VFIO?
-Christoffer
Quoted 41 lines · On Thursday 15 October 2015 17:03:21 Christoffer Dall wrote:
Quoted 16 lines · Arnd Bergmann
Quoted 7 lines · On Thursday 15 October 2015 16:46:09 Eric Auger wrote:
Quoted 6 lines
This is where we'd need a little more changes for this approach. Instead of unbinding the device from its driver, the idea would be that the driver remains bound as far as the driver model is concerned, but it would be in a quiescent state where no other subsystem interacts with it (i.e. it gets unregistered from networking core or whichever it uses).
Quoted 7 lines
Currently we use the same mechanism as for PCI, ie. unbind the native driver and then bind VFIO platform driver in its place. Don't you think changing this may be a pain for user-space tools that are designed to work that way for PCI?
My personal preference would be to start with your first proposal since it looks (to me) less complex and "unknown" that the 2d approach.
Quoted 7 lines
We certainly can't easily change from one approach to the other without breaking user expectations, so the decision needs to be made carefully.
The main observation here is that platform devices are unlike PCI in this regard because they need extra per-device code. I have argued in the past that we should not reuse the "VFIO" name here because it's actually something else.
I've adjusted to consider VFIO a general purpose framework for mapping device resources into userspace/VMs, and there are certainly a lot of commonality with both PCI, platform, and potentially other devices for that to make sense.
Quoted 4 lines
On the other hand, there are a lot of commonalities,
we just have to make sure we don't try to force the code into one model that doesn't really work just to make it look more like PCI VFIO.But given that we now have code for platform device passthrough that works in both QEMU and the kernel side and is actually useful for people, is there a clear technical advantage to go back and rework thaat at this point?
Quoted 4 lines
Don't get me wrong, I like the idea of having a single driver bound to a platform device, and then that's it, but it just feels like that discussion doesn't necessarily belong in the context of a patch that 'just' seeks to add reset functionality for a specific device for VFIO?
Ah, this is for qemu/kvm? If there is already upstream qemu code that finds it easier to use this approach, it's certainly more logical to deal with it in my first approach than the second.
I was thinking of ODP as the primary user, and that wouldn't need the interface to be consistent with PCI as much, because the code is inherently device specific there anyway.
Arnd
Quoted 42 lines · Arnd Bergmann
Quoted 41 lines · On Thursday 15 October 2015 17:03:21 Christoffer Dall wrote:
Quoted 16 lines · Arnd Bergmann
Quoted 7 lines · On Thursday 15 October 2015 16:46:09 Eric Auger wrote:
Quoted 6 lines
This is where we'd need a little more changes for this approach. Instead of unbinding the device from its driver, the idea would be that the driver remains bound as far as the driver model is concerned, but it would be in a quiescent state where no other subsystem interacts with it (i.e. it gets unregistered from networking core or whichever it uses).
Quoted 7 lines
Currently we use the same mechanism as for PCI, ie. unbind the native driver and then bind VFIO platform driver in its place. Don't you think changing this may be a pain for user-space tools that are designed to work that way for PCI?
My personal preference would be to start with your first proposal since it looks (to me) less complex and "unknown" that the 2d approach.
Quoted 7 lines
We certainly can't easily change from one approach to the other without breaking user expectations, so the decision needs to be made carefully.
The main observation here is that platform devices are unlike PCI in this regard because they need extra per-device code. I have argued in the past that we should not reuse the "VFIO" name here because it's actually something else.
I've adjusted to consider VFIO a general purpose framework for mapping device resources into userspace/VMs, and there are certainly a lot of commonality with both PCI, platform, and potentially other devices for that to make sense.
Quoted 4 lines
On the other hand, there are a lot of commonalities,
we just have to make sure we don't try to force the code into one model that doesn't really work just to make it look more like PCI VFIO.But given that we now have code for platform device passthrough that works in both QEMU and the kernel side and is actually useful for people, is there a clear technical advantage to go back and rework thaat at this point?
Quoted 8 lines
Quoted 4 lines
Don't get me wrong, I like the idea of having a single driver bound to a platform device, and then that's it, but it just feels like that discussion doesn't necessarily belong in the context of a patch that 'just' seeks to add reset functionality for a specific device for VFIO?
Ah, this is for qemu/kvm? If there is already upstream qemu code that finds it easier to use this approach, it's certainly more logical to deal with it in my first approach than the second.
yes, indeed.
Quoted 5 lines
I was thinking of ODP as the primary user, and that wouldn't need the interface to be consistent with PCI as much, because the code is inherently device specific there anyway.
I didn't think about how this applies to ODP (haven't had time to look at ODP in any technical detail TBH), but it sounds like ODP could be adapted to use either approach.
In any case we can always transition towards your 2nd approach in a userspace compatible way later, if we find good reasons to.
Thanks,
-Christoffer
Quoted 31 lines · Eric Auger
Hi Arnd,
Quoted 29 lines · Arnd Bergmann
Quoted 20 lines · On Thursday 15 October 2015 14:12:28 Christoffer Dall wrote:
Quoted 15 lines
enum
vfio_platform_op{
VFIO_PLATFORM_BIND,
VFIO_PLATFORM_UNBIND,
VFIO_PLATFORM_RESET,
};struct platform_driver { int (*probe)(struct platform_device *); int (*remove)(struct platform_device *); ... int (*vfio_manage)(struct platform_device *, enum vfio_platform_op); struct device_driver driver; };Quoted 5 lines
This would integrate much more closely into the platform driver framework, just like the regular vfio driver integrates into the PCI framework. Unlike PCI however, you can't just use the generic driver framework to unbind the driver, because you still need device specific code.
Quoted 4 lines
Thanks for these suggestions, really helpful.
What I don't understand in the latter example is how VFIO knows which struct
platform_driverto interact with?This would assume that the driver remains bound to the device, so VFIO gets a pointer to the device from somewhere (as it does today) and then follows the
dev->driverpointer to get to theplatform_driver.
The complexity of managing a bi-modal driver seems like far more than a little bit of code duplication in a device specific reset module and extends into how userspace makes devices available through vfio, so I think it's too late for that discussion.
Quoted 16 lines
Quoted 10 lines
Quoted 4 lines
Also, just so I'm sure I understand correctly,
VFIO_PLATFORM_UNBINDis then called by VFIO before the VFIO driver unbinds from the device (unbinding the platform driver from the device being a completely separate thing)?This is where we'd need a little more changes for this approach. Instead of unbinding the device from its driver, the idea would be that the driver remains bound as far as the driver model is concerned, but it would be in a quiescent state where no other subsystem interacts with it (i.e. it gets unregistered from networking core or whichever it uses).
Currently we use the same mechanism as for PCI, ie. unbind the native driver and then bind VFIO platform driver in its place. Don't you think changing this may be a pain for user-space tools that are designed to work that way for PCI?
Quoted 4 lines
My personal preference would be to start with your first proposal since it looks (to me) less complex and "unknown" that the 2d approach.
Let's wait for Alex opinion too...
I thought the reason we took the approach we have now is so that we don't have reset code loaded into the kernel unless we have a device that needs it. Therefore we don't really want to preemptively load all the reset drivers and have them do a registration. The unfortunate side-effect of that is the platform code needs to go looking for the driver. We do that via the __symbol_get() trick, which only fails without modules because the underscore variant isn't defined in that case. I remember asking Eric previously why we're using that rather than symbol_get(), I've since forgotten his answer, but the fact that __symbol_get() is only defined for modules makes it moot, we either need to make symbol_get() work or define __symbol_get() for non-module builds.
Otherwise, we should probably abandon the idea of these reset functions being modules and build them into the vfio platform driver (which would still be less loaded, dead code than a bi-modal host driver). Thanks,
Alex
Quoted 29 lines · Alex Williamson
Quoted 28 lines · Eric Auger
Hi Arnd,
Quoted 26 lines · Arnd Bergmann
Quoted 24 lines · On Thursday 15 October 2015 14:12:28 Christoffer Dall wrote:
Quoted 15 lines
enum
vfio_platform_op{
VFIO_PLATFORM_BIND,
VFIO_PLATFORM_UNBIND,
VFIO_PLATFORM_RESET,
};struct platform_driver { int (*probe)(struct platform_device *); int (*remove)(struct platform_device *); ... int (*vfio_manage)(struct platform_device *, enum vfio_platform_op); struct device_driver driver; };Quoted 5 lines
This would integrate much more closely into the platform driver framework, just like the regular vfio driver integrates into the PCI framework. Unlike PCI however, you can't just use the generic driver framework to unbind the driver, because you still need device specific code.
Thanks for these suggestions, really helpful.
What I don't understand in the latter example is how VFIO knows which struct
platform_driverto interact with?
Quoted 9 lines
Quoted 3 lines
Quoted 3 lines
This would assume that the driver remains bound to the device, so VFIO gets a pointer to the device from somewhere (as it does today) and then follows the
dev->driverpointer to get to theplatform_driver.The complexity of managing a bi-modal driver seems like far more than a little bit of code duplication in a device specific reset module and extends into how userspace makes devices available through vfio, so I think it's too late for that discussion.
I have had extremely limited exposure to the implementation details of the drivers for devices relevant for VFIO platform, so apologies for asking stupid questions.
I'm sure that your point is valid, I just fully understand how the complexities of a bi-modal driver arise?
Is it simply that the reset function in a particular device driver may not be self-contained so therefore the whole driver would need to be refactored to be able to do a reset for the purpose of VFIO?
Quoted 19 lines
Quoted 19 lines
Quoted 10 lines
Quoted 4 lines
Also, just so I'm sure I understand correctly,
VFIO_PLATFORM_UNBINDis then called by VFIO before the VFIO driver unbinds from the device (unbinding the platform driver from the device being a completely separate thing)?This is where we'd need a little more changes for this approach. Instead of unbinding the device from its driver, the idea would be that the driver remains bound as far as the driver model is concerned, but it would be in a quiescent state where no other subsystem interacts with it (i.e. it gets unregistered from networking core or whichever it uses).
Currently we use the same mechanism as for PCI, ie. unbind the native driver and then bind VFIO platform driver in its place. Don't you think changing this may be a pain for user-space tools that are designed to work that way for PCI?
My personal preference would be to start with your first proposal since it looks (to me) less complex and "unknown" that the 2d approach.
Quoted 8 lines
Quoted 1 line
Let's wait for Alex opinion too...
I thought the reason we took the approach we have now is so that we don't have reset code loaded into the kernel unless we have a device that needs it. Therefore we don't really want to preemptively load all the reset drivers and have them do a registration. The unfortunate side-effect of that is the platform code needs to go looking for the driver.
Does the current approach have a separate driver for doing VFIO reset or does it reuse the existing device driver?
Why does the driver registering itself instead of using symbol_get imply that we must load reset drivers that we don't need?
Thanks,
-Christoffer
Quoted 14 lines
We do that via the
__symbol_get()trick, which only fails without modules because the underscore variant isn't defined in that case. I remember asking Eric previously why we're using that rather thansymbol_get(), I've since forgotten his answer, but the fact that__symbol_get()is only defined for modules makes it moot, we either need to makesymbol_get()work or define__symbol_get()for non-module builds.Otherwise, we should probably abandon the idea of these reset functions being modules and build them into the vfio platform driver (which would still be less loaded, dead code than a bi-modal host driver). Thanks,
Alex
Quoted 44 lines · Christoffer Dall
Quoted 29 lines · Alex Williamson
Quoted 28 lines · Eric Auger
Hi Arnd,
Quoted 26 lines · Arnd Bergmann
Quoted 24 lines · On Thursday 15 October 2015 14:12:28 Christoffer Dall wrote:
Quoted 15 lines
enum
vfio_platform_op{
VFIO_PLATFORM_BIND,
VFIO_PLATFORM_UNBIND,
VFIO_PLATFORM_RESET,
};struct platform_driver { int (*probe)(struct platform_device *); int (*remove)(struct platform_device *); ... int (*vfio_manage)(struct platform_device *, enum vfio_platform_op); struct device_driver driver; };Quoted 5 lines
This would integrate much more closely into the platform driver framework, just like the regular vfio driver integrates into the PCI framework. Unlike PCI however, you can't just use the generic driver framework to unbind the driver, because you still need device specific code.
Thanks for these suggestions, really helpful.
What I don't understand in the latter example is how VFIO knows which struct
platform_driverto interact with?Quoted 9 lines
Quoted 3 lines
Quoted 3 lines
This would assume that the driver remains bound to the device, so VFIO gets a pointer to the device from somewhere (as it does today) and then follows the
dev->driverpointer to get to theplatform_driver.The complexity of managing a bi-modal driver seems like far more than a little bit of code duplication in a device specific reset module and extends into how userspace makes devices available through vfio, so I think it's too late for that discussion.
I have had extremely limited exposure to the implementation details of the drivers for devices relevant for VFIO platform, so apologies for asking stupid questions.
Quoted 6 lines
I'm sure that your point is valid, I just fully understand how the complexities of a bi-modal driver arise?
Is it simply that the reset function in a particular device driver may not be self-contained so therefore the whole driver would need to be refactored to be able to do a reset for the purpose of VFIO?
Yes, I would expect that reset function in a driver is not typically self contained, probably referencing driver specific data structures for register offsets, relying on various mappings that are expected to be created from the driver probe() function, etc. It also creates a strange dependency on the host driver, how is the user to know they need the native host driver loaded for full functionality in a device assignment scenario? Are we going to need to do a module_request() of the host driver in vfio platform anyway? What if there are multiple devices and the host driver claims the others when loaded? In the case of PCI and SR-IOV virtual functions, I often blacklist the host VF driver because I shouldn't need it when I only intend to use the device in guests. Not to mention that we'd have to drop a little bit of vfio knowledge into each host driver that we intend to enlighten like this, and how do we resolve whether the host driver, potentially compiled from a separate source tree has this support.
I really don't see the layering violation in having a set of reset functions and some lookup mechanism to pick the correct one. The vfio platform driver is a meta driver and sometimes we need to enlighten it a little bit more about the device it's operating on. For PCI we have all sorts of special functionality for reset, but we have a standard to work with there, so we may need to choose between a bus reset, PM reset, AF FLR, PCIe FLR, or device specific reset, but it's all buried in the PCI core code; where device specific resets are the exception on PCI, they are the norm on platform.
Quoted 28 lines
Quoted 19 lines
Quoted 19 lines
Quoted 10 lines
Quoted 4 lines
Also, just so I'm sure I understand correctly,
VFIO_PLATFORM_UNBINDis then called by VFIO before the VFIO driver unbinds from the device (unbinding the platform driver from the device being a completely separate thing)?This is where we'd need a little more changes for this approach. Instead of unbinding the device from its driver, the idea would be that the driver remains bound as far as the driver model is concerned, but it would be in a quiescent state where no other subsystem interacts with it (i.e. it gets unregistered from networking core or whichever it uses).
Currently we use the same mechanism as for PCI, ie. unbind the native driver and then bind VFIO platform driver in its place. Don't you think changing this may be a pain for user-space tools that are designed to work that way for PCI?
My personal preference would be to start with your first proposal since it looks (to me) less complex and "unknown" that the 2d approach.
Quoted 8 lines
Quoted 1 line
Let's wait for Alex opinion too...
I thought the reason we took the approach we have now is so that we don't have reset code loaded into the kernel unless we have a device that needs it. Therefore we don't really want to preemptively load all the reset drivers and have them do a registration. The unfortunate side-effect of that is the platform code needs to go looking for the driver.
Quoted 2 lines
Does the current approach have a separate driver for doing VFIO reset or does it reuse the existing device driver?
They're separate modules, not drivers. They simply export a reset function, no module init or exit function. A table lookup via the device compatibility string identifies the module to load and name of reset function. At one point I suggested that we simply use standard naming based on the compatibility string to name the module and reset function to avoid the table, but that was thought to be too hackish or perhaps dangerous to have vfio requesting modules like that.
Quoted 2 lines
Why does the driver registering itself instead of using
symbol_getimply that we must load reset drivers that we don't need?
Who would register the reset driver if not the reset "driver" itself? Either we have a table/list of registered reset drivers and we can pick the one we want and the code is already loaded, or we have a table/list of who provides which reset driver and we load and get a pointer when we determine that we need it. Are there other options? Thanks,
Alex
Dear all,
Quoted 59 lines · Alex Williamson
Quoted 31 lines · Eric Auger
Hi Arnd,
Quoted 29 lines · Arnd Bergmann
Quoted 20 lines · On Thursday 15 October 2015 14:12:28 Christoffer Dall wrote:
Quoted 15 lines
enum
vfio_platform_op{
VFIO_PLATFORM_BIND,
VFIO_PLATFORM_UNBIND,
VFIO_PLATFORM_RESET,
};struct platform_driver { int (*probe)(struct platform_device *); int (*remove)(struct platform_device *); ... int (*vfio_manage)(struct platform_device *, enum vfio_platform_op); struct device_driver driver; };Quoted 5 lines
This would integrate much more closely into the platform driver framework, just like the regular vfio driver integrates into the PCI framework. Unlike PCI however, you can't just use the generic driver framework to unbind the driver, because you still need device specific code.
Quoted 4 lines
Thanks for these suggestions, really helpful.
What I don't understand in the latter example is how VFIO knows which struct
platform_driverto interact with?This would assume that the driver remains bound to the device, so VFIO gets a pointer to the device from somewhere (as it does today) and then follows the
dev->driverpointer to get to theplatform_driver.The complexity of managing a bi-modal driver seems like far more than a little bit of code duplication in a device specific reset module and extends into how userspace makes devices available through vfio, so I think it's too late for that discussion.
Quoted 16 lines
Quoted 10 lines
Quoted 4 lines
Also, just so I'm sure I understand correctly,
VFIO_PLATFORM_UNBINDis then called by VFIO before the VFIO driver unbinds from the device (unbinding the platform driver from the device being a completely separate thing)?This is where we'd need a little more changes for this approach. Instead of unbinding the device from its driver, the idea would be that the driver remains bound as far as the driver model is concerned, but it would be in a quiescent state where no other subsystem interacts with it (i.e. it gets unregistered from networking core or whichever it uses).
Currently we use the same mechanism as for PCI, ie. unbind the native driver and then bind VFIO platform driver in its place. Don't you think changing this may be a pain for user-space tools that are designed to work that way for PCI?
Quoted 4 lines
My personal preference would be to start with your first proposal since it looks (to me) less complex and "unknown" that the 2d approach.
Let's wait for Alex opinion too...
Quoted 9 lines
I thought the reason we took the approach we have now is so that we don't have reset code loaded into the kernel unless we have a device that needs it. Therefore we don't really want to preemptively load all the reset drivers and have them do a registration. The unfortunate side-effect of that is the platform code needs to go looking for the driver. We do that via the
__symbol_get()trick, which only fails without modules because the underscore variant isn't defined in that case. I remember asking Eric previously why we're using that rather thansymbol_get(),
the rationale behind using __get_symbol is that the function takes a char * as argument while the get_symbol macro takes the very symbol. I needed to provide a string since this is what is stored in the lookup table. Unfortunately I did not see the #if CONFIG_MODULES. I Should have been warned about "__" and Alex doubts, sin of naïvety.
I've since forgotten his answer, but the fact that
Quoted 3 lines
__symbol_get()is only defined for modules makes it moot, we either need to makesymbol_get()work or define__symbol_get()for non-module builds.
I currently don't see any solution for any of those. The only solution I can see is someone registers the reset function pointer to vfio.
I think we could keep the existing reset modules, do the request_module from VFIO, using their module name registered in the lookup table. But instead of having the reset function in the look-up table we would have the reset modules register their reset function pointer to VFIO. I think this could work around the symbol_get issue.
This still leaves the layer violation argument though.
Assuming this works, would that be an acceptable solution, although I acknowledge this does not perfectly fit into the driver model?
Best Regards
Eric
Quoted 8 lines
Otherwise, we should probably abandon the idea of these reset functions being modules and build them into the vfio platform driver (which would still be less loaded, dead code than a bi-modal host driver). Thanks,
Alex
_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
Quoted 13 lines · On Friday 16 October 2015 15:06:45 Eric Auger wrote:
I've since forgotten his answer, but the fact that
Quoted 3 lines
__symbol_get()is only defined for modules makes it moot, we either need to makesymbol_get()work or define__symbol_get()for non-module builds.I currently don't see any solution for any of those. The only solution I can see is someone registers the reset function pointer to vfio.
I think we could keep the existing reset modules, do the
request_modulefrom VFIO, using their module name registered in the lookup table. But instead of having the reset function in the look-up table we would have the reset modules register their reset function pointer to VFIO. I think this could work around thesymbol_getissue.
Quoted 4 lines
This still leaves the layer violation argument though.
Assuming this works, would that be an acceptable solution, although I acknowledge this does not perfectly fit into the driver model?
I think it's possible to avoid the layering violation that way too, by loading the module based on the compatible string, with a module_alias.
static void vfio_platform_get_reset(struct vfio_platform_device *vdev,
struct device *dev)
{
const char *compat;
int (*reset)(struct vfio_platform_device *);
int ret, i;
char modname[256];
ret = device_property_read_string(dev, "compatible", &compat);
if (ret)
return;
reset = vfio_platform_lookup_reset(compat);
if (!reset) {
snprintf(modname, "vfio-reset:%s", compat);
request_module(modname);
reset = vfio_platform_lookup_reset(compat);
}
vdev->reset = reset;
}---
#define module_vfio_reset_handler(compat, reset) \MODULE_ALIAS("vfio_reset" compat); \
static int reset ## _module_init(void) \
{ \
return vfio_reset_register(THIS_MODULE, compat, &reset); \
}I think that solution is good enough, as it avoids most of the problems with the current implementation but is a simple enough change.
Arnd
Hi Arnd,
Quoted 50 lines · Arnd Bergmann
Quoted 13 lines · On Friday 16 October 2015 15:06:45 Eric Auger wrote:
I've since forgotten his answer, but the fact that
Quoted 3 lines
__symbol_get()is only defined for modules makes it moot, we either need to makesymbol_get()work or define__symbol_get()for non-module builds.I currently don't see any solution for any of those. The only solution I can see is someone registers the reset function pointer to vfio.
I think we could keep the existing reset modules, do the
request_modulefrom VFIO, using their module name registered in the lookup table. But instead of having the reset function in the look-up table we would have the reset modules register their reset function pointer to VFIO. I think this could work around thesymbol_getissue.Quoted 4 lines
This still leaves the layer violation argument though.
Assuming this works, would that be an acceptable solution, although I acknowledge this does not perfectly fit into the driver model?
I think it's possible to avoid the layering violation that way too, by loading the module based on the compatible string, with a
module_alias.static void vfio_platform_get_reset(struct
vfio_platform_device*vdev,
struct device *dev){ const char *compat; int (*reset)(struct vfio_platform_device *); int ret, i; char modname[256]; ret = device_property_read_string(dev, "compatible", &compat); if (ret) return; reset = vfio_platform_lookup_reset(compat); if (!reset) { snprintf(modname, "vfio-reset:%s", compat); request_module(modname); reset = vfio_platform_lookup_reset(compat); } vdev->reset = reset; }---
#define
module_vfio_reset_handler(compat, reset)\MODULE_ALIAS("vfio_reset" compat); \
static int reset ##_module_init(void)\
Quoted 6 lines
{ \ return vfio_reset_register(THIS_MODULE, compat, &reset); \ }I think that solution is good enough, as it avoids most of the problems with the current implementation but is a simple enough change.
That looks a good perspective. Thanks for the hint! Let's code now ;-)
Best Regards
Eric
Quoted 3 lines
Arnd
Hi Arnd,
Quoted 50 lines · Christoffer Dall
Quoted 49 lines · Arnd Bergmann
Quoted 27 lines · On Thursday 15 October 2015 10:08:02 Eric Auger wrote:
Hi Arnd,
Quoted 14 lines · Arnd Bergmann
Quoted 13 lines · On Wednesday 14 October 2015 15:33:12 Eric Auger wrote:
drivers/vfio/platform/vfio_platform_common.c +5
-0@@ -31,6 +31,11 @@ static const struct vfio_platform_reset_combo reset_lookup_table[] = { .reset_function_name = "vfio_platform_calxedaxgmac_reset", .module_name = "vfio-platform-calxedaxgmac", }, + { + .compat = "amd,xgbe-seattle-v1a", + .reset_function_name = "vfio_platform_amdxgbe_reset", + .module_name = "vfio-platform-amdxgbe", + }, };Quoted 4 lines
drivers/vfio/platform/vfio_platform_common.c static const struct vfio_platform_reset_combo reset_lookup_table[] = { · line 41
Quoted 2 lines
drivers/vfio/platform/vfio_platform_common.c +0
-0static void vfio_platform_get_reset(struct vfio_platform_device *vdev,This is causing build errors for me when
CONFIG_MODULESis disabled.Sorry about that and thanks for reporting the issue
Quoted 4 lines
Could this please be restructured so
vfio_platform_get_resetdoes not attempt to call__symbol_get()but instead has the drivers register themselves properly to a subsystem?OK
Quoted 8 lines
Could you elaborate about "has the drivers register themselves properly to a subsystem".
My first proposal when coping with this problematic of being able to add reset plugins to the vfio-platform driver was to create new drivers per device requiring reset. but this was considered painful for end-users, who needed to be aware of the right driver to bind - and I think that makes sense - (https://lkml.org/lkml/2015/4/17/568) .
Having multiple drivers indeed sucks, but your current approach isn't that much better, as you still have two modules that are used to driver the same hardware.
I would expect that the same driver that is used for the normal operation and that it calls a function to register itself to vfio by passing a structure with the device and reset function pointer.
Quoted 3 lines
A naive question I dare to ask, wouldn't it be acceptable to make
vfio_platformdepend onCONFIG_MODULES? Don't we disable modules for security purpose? In that context would we use VFIO?
Quoted 8 lines
Quoted 8 lines
I think a lot of embedded systems turn off modules to save a little memory, speed up boot time and simplify their user space.
Aside from that, the current method is highly unusual and looks a bit fragile to me, as you are relying on internals of the module loader code. It's also a layering violation as the generic code needs to be patched for each device specific module that is added, and we try to avoid that.
Many thanks for taking the time to write this down
Quoted 16 lines
Quoted 16 lines
A possible solution could be something inside the xgbe driver like
static void
xgbe_init_module(void){ int ret = 0; if (IS_ENABLED(CONFIG_AMD_XGBE_ETHERNET) ret = platform_driver_register(&xgbe_driver); if (ret) return ret; if (IS_ENABLED(CONFIG_VFIO_PLATFORM)) ret = vfio_platform_register_reset(&xgbe_of_match, xgbe_platform_reset);
Quoted 6 lines
Quoted 6 lines
return ret; }This way you have exactly one driver module that gets loaded for the device and you can use it either with the
platform_driveror through vfio.
If I understand it correctly you still need 2 loaded modules (VFIO driver & XGBE driver which implements the reset function) or am I missing something?
I had a similar mechanism of registration in my PATCH v1 but I did the registration from the reset module itself instead of in the native driver, as you suggest here.
Best Regards
Eric
Quoted 38 lines
Quoted 20 lines
A nicer way that would be a little more work would be to integrate the reset infrastructure into 'struct
platform_driver' framework, by adding another callback to the it for doing the interaction with vfio, something likeenum
vfio_platform_op{
VFIO_PLATFORM_BIND,
VFIO_PLATFORM_UNBIND,
VFIO_PLATFORM_RESET,
};struct platform_driver { int (*probe)(struct platform_device *); int (*remove)(struct platform_device *); ... int (*vfio_manage)(struct platform_device *, enum vfio_platform_op); struct device_driver driver; };Quoted 5 lines
This would integrate much more closely into the platform driver framework, just like the regular vfio driver integrates into the PCI framework. Unlike PCI however, you can't just use the generic driver framework to unbind the driver, because you still need device specific code.
Thanks for these suggestions, really helpful.
What I don't understand in the latter example is how VFIO knows which struct
platform_driverto interact with?Also, just so I'm sure I understand correctly,
VFIO_PLATFORM_UNBINDis then called by VFIO before the VFIO driver unbinds from the device (unbinding the platform driver from the device being a completely separate thing)?Thanks,
-Christoffer
Quoted 23 lines · On Thursday 15 October 2015 16:20:46 Eric Auger wrote:
Quoted 22 lines · Christoffer Dall
Quoted 21 lines · Arnd Bergmann
Quoted 2 lines · On Thursday 15 October 2015 10:08:02 Eric Auger wrote:
Quoted 1 line · Arnd Bergmann
On Wednesday 14 October 2015 15:33:12 Eric Auger wrote:
A possible solution could be something inside the xgbe driver like
static void
xgbe_init_module(void){ int ret = 0; if (IS_ENABLED(CONFIG_AMD_XGBE_ETHERNET) ret = platform_driver_register(&xgbe_driver); if (ret) return ret; if (IS_ENABLED(CONFIG_VFIO_PLATFORM)) ret = vfio_platform_register_reset(&xgbe_of_match, xgbe_platform_reset); return ret; }
Quoted 6 lines
Quoted 3 lines
Quoted 3 lines
This way you have exactly one driver module that gets loaded for the device and you can use it either with the
platform_driveror through vfio.If I understand it correctly you still need 2 loaded modules (VFIO driver & XGBE driver which implements the reset function) or am I missing something?
That is correct, yes.
Quoted 3 lines
I had a similar mechanism of registration in my PATCH v1 but I did the registration from the reset module itself instead of in the native driver, as you suggest here.
Right. The main difference is that you don't have two modules fighting over the same device with the approach here.
Arnd