Bug 216449 - vfio-pci calls pci_bus_reset whenever a pci_release is triggered and refcnt is zero
Summary: vfio-pci calls pci_bus_reset whenever a pci_release is triggered and refcnt i...
Status: NEW
Alias: None
Product: Drivers
Classification: Unclassified
Component: PCI (show other bugs)
Hardware: All Linux
: P1 normal
Assignee: drivers_pci@kernel-bugs.osdl.org
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-09-05 08:21 UTC by a-dibacco
Modified: 2022-09-05 19:43 UTC (History)
1 user (show)

See Also:
Kernel Version: 5.x
Subsystem:
Regression: No
Bisected commit-id:


Attachments

Description a-dibacco 2022-09-05 08:21:24 UTC
I'm using vfio-pci to map an FPGA. I have an utility program that gets a file descriptor for the device and does an mmap to read and write registers.

When I close the utility the FPGA is reset and all registers are gone. 
I wonder if this is the correct behaviour, I understand that the vfio_pci_try_bus_reset is performed only when refcnt reaches zero but, in case of other drivers, like UIO the behaviour is different. 

I expected to be able to close my utility and restart it and find the FPGA registers at the last configured value.

The vfio_pci_try_bus_reset is in vfio_pci_disable that is called by pci_release.

Probably even a module parameter to prevent calling vfio_pci_try_bus_reset could be useful.

Regards.
Comment 1 Alex Williamson 2022-09-05 13:17:19 UTC
This is the expected behavior, the kernel cannot know if you or some other user will get the device next and whether the state of the device contains sensitive information.  Imagine a GPU that might contain a frame buffer from the previous user or a crypto device still holding a keychain.  Therefore we always try to reset the device when it is released by the user.
Comment 2 a-dibacco 2022-09-05 19:43:22 UTC
I understand your point and I agree with the choice. Anyway, wouldn't be possible to add a new module parameter that disables reset on close?
I mean a parameter like disable_reset_on_close with a default value that mimic the current behaviour.

I'm not an expert but it could be that there are applications that don't need to reset the device when they have finished configuring it. Keeping the device open could be a risk because in case of a software crash the device would be closed potentially affecting the functionality of the hardware. 

Thank you for your answer.

Note You need to log in before you can comment on or make changes to this bug.