Bug 202991

Summary: On change of sriov_numvfs, netlink message is sent before the new value is available in /sys
Product: Drivers Reporter: pierre.cregut
Component: PCIAssignee: drivers_pci (drivers_pci)
Status: NEW ---    
Severity: normal CC: bjorn
Priority: P1    
Hardware: All   
OS: Linux   
Kernel Version: 5.0.3 (all) Subsystem:
Regression: No Bisected commit-id:
Attachments: Shell script to monitor netlink and read sriov_numvfs
Proposed patch that sets num_VFs earlier.

Description pierre.cregut 2019-03-21 16:35:12 UTC
Created attachment 281953 [details]
Shell script to monitor netlink and read sriov_numvfs

I would like to monitor the number of VFs for an sr-iov card.
When sriov_numvfs is changed, a netlink message is sent. Unfortunately reading the value on sriov_numvfs just after receiving the message always give the value 0. As a result the netlink message is almost useless for monitoring.

The shell script in attachment can be used to monitor an interface (DEVICE). Changing alternatively sriov_numvfs will make a 0 be written down whatever the value used.

One solution may be to set iov->num_VFs just before each call to pci_iov_set_numvfs in sriov_enable (iov.c), on the normal path to nr_virtfn and to 0 on the error path.
Comment 1 pierre.cregut 2019-03-21 17:09:06 UTC
Created attachment 281955 [details]
Proposed patch that sets num_VFs earlier.
Comment 2 Bjorn Helgaas 2019-03-21 18:30:43 UTC
Thanks for the report and for the patch!  Can you please fix the whitespace issue (add spaces around "="), add a changelog (include the URL of this bug report), and post it to linux-pci@vger.kernel.com.

https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst has the basics of the process.  You can also run "git log drivers/pci/iov.c" to see the usual style.

Thanks again!
Comment 3 pierre.cregut 2019-03-26 10:11:03 UTC
patch has been posted to the list.