<feed xmlns='http://www.w3.org/2005/Atom'>
<title>linux.git/tools/testing/selftests/vfio/lib/include, branch master</title>
<subtitle>Linux kernel source tree</subtitle>
<link rel='alternate' type='text/html' href='https://git.tavy.me/linux.git/'/>
<entry>
<title>vfio: selftests: Retry on EAGAIN during device reset</title>
<updated>2026-08-10T19:24:40+00:00</updated>
<author>
<name>Josh Hilke</name>
<email>jrhilke@google.com</email>
</author>
<published>2026-08-05T00:21:00+00:00</published>
<link rel='alternate' type='text/html' href='https://git.tavy.me/linux.git/commit/?id=28ca5f67e1a79f62ed7988674fb07a8fc9eab8d2'/>
<id>28ca5f67e1a79f62ed7988674fb07a8fc9eab8d2</id>
<content type='text'>
Add retry logic to vfio_pci_device_reset() to handle the case where PCI
resets fail due to lock contention, in which case
pci_try_reset_function() returns -EAGAIN.

Suggested-by: David Matlack &lt;dmatlack@google.com&gt;
Signed-off-by: Josh Hilke &lt;jrhilke@google.com&gt;
Acked-by: David Matlack &lt;dmatlack@google.com&gt;
Link: https://lore.kernel.org/r/20260805-igb_v3_b4-v10-3-9c86dc849c0d@google.com
Signed-off-by: Alex Williamson &lt;alex@shazbot.org&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Add retry logic to vfio_pci_device_reset() to handle the case where PCI
resets fail due to lock contention, in which case
pci_try_reset_function() returns -EAGAIN.

Suggested-by: David Matlack &lt;dmatlack@google.com&gt;
Signed-off-by: Josh Hilke &lt;jrhilke@google.com&gt;
Acked-by: David Matlack &lt;dmatlack@google.com&gt;
Link: https://lore.kernel.org/r/20260805-igb_v3_b4-v10-3-9c86dc849c0d@google.com
Signed-off-by: Alex Williamson &lt;alex@shazbot.org&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>vfio: selftests: Add helpers to re-enable interrupts</title>
<updated>2026-08-10T19:24:40+00:00</updated>
<author>
<name>Alex Williamson</name>
<email>alex.williamson@nvidia.com</email>
</author>
<published>2026-08-05T00:20:58+00:00</published>
<link rel='alternate' type='text/html' href='https://git.tavy.me/linux.git/commit/?id=aabaf84560e0737eeba0927395d04a813cbec8c0'/>
<id>aabaf84560e0737eeba0927395d04a813cbec8c0</id>
<content type='text'>
Selftest drivers that recover from a fault by issuing VFIO_DEVICE_RESET
need to re-arm device interrupts afterwards.  VFIO_DEVICE_RESET tears
down the kernel-side IRQ trigger so a subsequent VFIO_DEVICE_SET_IRQS
is required, but the user-side eventfds (and any fd cached in a test
fixture) are still valid and must be preserved.

vfio_pci_irq_enable() refuses to be called for vectors that already
have an eventfd (VFIO_ASSERT_LT), and vfio_pci_irq_disable() closes
all eventfds before resetting the trigger, so neither is suitable.

Add vfio_pci_irq_reenable(device, index, vector, count) which asserts
that the requested range has existing eventfds and re-issues
VFIO_DEVICE_SET_IRQS using them.  Signature mirrors vfio_pci_irq_enable().

Add vfio_pci_msi{,x}_reenable() wrappers around vfio_pci_irq_reenable()
for additional ease of use and readability.

Assisted-by: Claude:claude-opus-4-7
Signed-off-by: Alex Williamson &lt;alex.williamson@nvidia.com&gt;
Reviewed-by: David Matlack &lt;dmatlack@google.com&gt;
Acked-by: David Matlack &lt;dmatlack@google.com&gt;
Link: https://lore.kernel.org/r/20260805-igb_v3_b4-v10-1-9c86dc849c0d@google.com
Signed-off-by: Alex Williamson &lt;alex@shazbot.org&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Selftest drivers that recover from a fault by issuing VFIO_DEVICE_RESET
need to re-arm device interrupts afterwards.  VFIO_DEVICE_RESET tears
down the kernel-side IRQ trigger so a subsequent VFIO_DEVICE_SET_IRQS
is required, but the user-side eventfds (and any fd cached in a test
fixture) are still valid and must be preserved.

vfio_pci_irq_enable() refuses to be called for vectors that already
have an eventfd (VFIO_ASSERT_LT), and vfio_pci_irq_disable() closes
all eventfds before resetting the trigger, so neither is suitable.

Add vfio_pci_irq_reenable(device, index, vector, count) which asserts
that the requested range has existing eventfds and re-issues
VFIO_DEVICE_SET_IRQS using them.  Signature mirrors vfio_pci_irq_enable().

Add vfio_pci_msi{,x}_reenable() wrappers around vfio_pci_irq_reenable()
for additional ease of use and readability.

Assisted-by: Claude:claude-opus-4-7
Signed-off-by: Alex Williamson &lt;alex.williamson@nvidia.com&gt;
Reviewed-by: David Matlack &lt;dmatlack@google.com&gt;
Acked-by: David Matlack &lt;dmatlack@google.com&gt;
Link: https://lore.kernel.org/r/20260805-igb_v3_b4-v10-1-9c86dc849c0d@google.com
Signed-off-by: Alex Williamson &lt;alex@shazbot.org&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>vfio: selftests: Add allocation assert helpers</title>
<updated>2026-07-17T14:39:35+00:00</updated>
<author>
<name>Alex Mastro</name>
<email>amastro@fb.com</email>
</author>
<published>2026-06-17T18:58:00+00:00</published>
<link rel='alternate' type='text/html' href='https://git.tavy.me/linux.git/commit/?id=bc4be8c6fd8bf9f4d7febccfbd6441c4d708135a'/>
<id>bc4be8c6fd8bf9f4d7febccfbd6441c4d708135a</id>
<content type='text'>
Add {malloc,calloc}_assert() helpers alongside the existing *_assert()
helpers.

Use them for VFIO selftest allocations that immediately assert a
non-NULL result.

Assisted-by: Codex:gpt-5.5-high
Signed-off-by: Alex Mastro &lt;amastro@fb.com&gt;
Reviewed-by: David Matlack &lt;dmatlack@google.com&gt;
Link: https://lore.kernel.org/r/20260617-scratch-amastro-vfio-selftests-avoid-vlas-v4-1-b9f52f1e2c5a@fb.com
Signed-off-by: Alex Williamson &lt;alex@shazbot.org&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Add {malloc,calloc}_assert() helpers alongside the existing *_assert()
helpers.

Use them for VFIO selftest allocations that immediately assert a
non-NULL result.

Assisted-by: Codex:gpt-5.5-high
Signed-off-by: Alex Mastro &lt;amastro@fb.com&gt;
Reviewed-by: David Matlack &lt;dmatlack@google.com&gt;
Link: https://lore.kernel.org/r/20260617-scratch-amastro-vfio-selftests-avoid-vlas-v4-1-b9f52f1e2c5a@fb.com
Signed-off-by: Alex Williamson &lt;alex@shazbot.org&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>vfio: selftests: Add generic PCI command register helpers</title>
<updated>2026-07-17T14:39:34+00:00</updated>
<author>
<name>Rubin Du</name>
<email>rubind@nvidia.com</email>
</author>
<published>2026-06-09T23:28:53+00:00</published>
<link rel='alternate' type='text/html' href='https://git.tavy.me/linux.git/commit/?id=984b43b203c43ff7ab11dd92c04a5b29eb80389b'/>
<id>984b43b203c43ff7ab11dd92c04a5b29eb80389b</id>
<content type='text'>
Add vfio_pci_cmd_set()/vfio_pci_cmd_clear() read-modify-write macros
for PCI_COMMAND in vfio_pci_device.h.

Reviewed-by: David Matlack &lt;dmatlack@google.com&gt;
Signed-off-by: Alex Williamson &lt;alex.williamson@nvidia.com&gt;
Signed-off-by: Rubin Du &lt;rubind@nvidia.com&gt;
Link: https://lore.kernel.org/r/20260609232855.3808971-3-rubind@nvidia.com
Signed-off-by: Alex Williamson &lt;alex@shazbot.org&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Add vfio_pci_cmd_set()/vfio_pci_cmd_clear() read-modify-write macros
for PCI_COMMAND in vfio_pci_device.h.

Reviewed-by: David Matlack &lt;dmatlack@google.com&gt;
Signed-off-by: Alex Williamson &lt;alex.williamson@nvidia.com&gt;
Signed-off-by: Rubin Du &lt;rubind@nvidia.com&gt;
Link: https://lore.kernel.org/r/20260609232855.3808971-3-rubind@nvidia.com
Signed-off-by: Alex Williamson &lt;alex@shazbot.org&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>vfio: selftests: Add helpers to alloc/free vfio_pci_device</title>
<updated>2026-05-20T17:54:10+00:00</updated>
<author>
<name>Raghavendra Rao Ananta</name>
<email>rananta@google.com</email>
</author>
<published>2026-05-05T21:28:37+00:00</published>
<link rel='alternate' type='text/html' href='https://git.tavy.me/linux.git/commit/?id=3152e7f457dece42b13423c45a371ee686074fac'/>
<id>3152e7f457dece42b13423c45a371ee686074fac</id>
<content type='text'>
Add a helper, vfio_pci_device_alloc(), to allocate 'struct
vfio_pci_device'. The subsequent test patch will utilize this
to get the struct with very minimal initialization done.
Internally, let vfio_pci_device_init() also make use of this
function and later do the full initialization.

Symmetrically, add a free variant, vfio_pci_device_free(),
to be used in a similar fashion.

No functional change intended.

Signed-off-by: Raghavendra Rao Ananta &lt;rananta@google.com&gt;
Reviewed-by: David Matlack &lt;dmatlack@google.com&gt;
Reviewed-by: Vipin Sharma &lt;vipinsh@google.com&gt;
Tested-by: David Matlack &lt;dmatlack@google.com&gt;
Link: https://lore.kernel.org/r/20260505212838.1698034-8-rananta@google.com
Signed-off-by: Alex Williamson &lt;alex@shazbot.org&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Add a helper, vfio_pci_device_alloc(), to allocate 'struct
vfio_pci_device'. The subsequent test patch will utilize this
to get the struct with very minimal initialization done.
Internally, let vfio_pci_device_init() also make use of this
function and later do the full initialization.

Symmetrically, add a free variant, vfio_pci_device_free(),
to be used in a similar fashion.

No functional change intended.

Signed-off-by: Raghavendra Rao Ananta &lt;rananta@google.com&gt;
Reviewed-by: David Matlack &lt;dmatlack@google.com&gt;
Reviewed-by: Vipin Sharma &lt;vipinsh@google.com&gt;
Tested-by: David Matlack &lt;dmatlack@google.com&gt;
Link: https://lore.kernel.org/r/20260505212838.1698034-8-rananta@google.com
Signed-off-by: Alex Williamson &lt;alex@shazbot.org&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>vfio: selftests: Add helper to set/override a vf_token</title>
<updated>2026-05-20T17:54:10+00:00</updated>
<author>
<name>Raghavendra Rao Ananta</name>
<email>rananta@google.com</email>
</author>
<published>2026-05-05T21:28:36+00:00</published>
<link rel='alternate' type='text/html' href='https://git.tavy.me/linux.git/commit/?id=20face8c75ffb3dd7e8d6743498b47403e57ebda'/>
<id>20face8c75ffb3dd7e8d6743498b47403e57ebda</id>
<content type='text'>
Add a helper function, vfio_device_set_vf_token(), to set or override a
vf_token. Not only at init, but a vf_token can also be set via the
VFIO_DEVICE_FEATURE ioctl, by setting the
VFIO_DEVICE_FEATURE_PCI_VF_TOKEN flag. Hence, add an API to utilize this
functionality from the test code. The subsequent commit will use this to
test the functionality of this method to set the vf_token.

Signed-off-by: Raghavendra Rao Ananta &lt;rananta@google.com&gt;
Reviewed-by: David Matlack &lt;dmatlack@google.com&gt;
Reviewed-by: Vipin Sharma &lt;vipinsh@google.com&gt;
Tested-by: David Matlack &lt;dmatlack@google.com&gt;
Link: https://lore.kernel.org/r/20260505212838.1698034-7-rananta@google.com
Signed-off-by: Alex Williamson &lt;alex@shazbot.org&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Add a helper function, vfio_device_set_vf_token(), to set or override a
vf_token. Not only at init, but a vf_token can also be set via the
VFIO_DEVICE_FEATURE ioctl, by setting the
VFIO_DEVICE_FEATURE_PCI_VF_TOKEN flag. Hence, add an API to utilize this
functionality from the test code. The subsequent commit will use this to
test the functionality of this method to set the vf_token.

Signed-off-by: Raghavendra Rao Ananta &lt;rananta@google.com&gt;
Reviewed-by: David Matlack &lt;dmatlack@google.com&gt;
Reviewed-by: Vipin Sharma &lt;vipinsh@google.com&gt;
Tested-by: David Matlack &lt;dmatlack@google.com&gt;
Link: https://lore.kernel.org/r/20260505212838.1698034-7-rananta@google.com
Signed-off-by: Alex Williamson &lt;alex@shazbot.org&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>vfio: selftests: Expose more vfio_pci_device functions</title>
<updated>2026-05-20T17:54:10+00:00</updated>
<author>
<name>Raghavendra Rao Ananta</name>
<email>rananta@google.com</email>
</author>
<published>2026-05-05T21:28:35+00:00</published>
<link rel='alternate' type='text/html' href='https://git.tavy.me/linux.git/commit/?id=60ab36e5d02a8e50e1edce24bff58507b514b94e'/>
<id>60ab36e5d02a8e50e1edce24bff58507b514b94e</id>
<content type='text'>
Refactor and make the functions called under device initialization
public. A later patch adds a test that calls these functions to validate
the UAPI of SR-IOV devices. Opportunistically, to test the success
and failure cases of the UAPI, split the functions dealing with
VFIO_GROUP_GET_DEVICE_FD and VFIO_DEVICE_BIND_IOMMUFD into a core
function and another one that asserts the ioctl. The former will be
used for testing the SR-IOV UAPI, hence only export these.

Signed-off-by: Raghavendra Rao Ananta &lt;rananta@google.com&gt;
Reviewed-by: David Matlack &lt;dmatlack@google.com&gt;
Reviewed-by: Vipin Sharma &lt;vipinsh@google.com&gt;
Tested-by: David Matlack &lt;dmatlack@google.com&gt;
Link: https://lore.kernel.org/r/20260505212838.1698034-6-rananta@google.com
Signed-off-by: Alex Williamson &lt;alex@shazbot.org&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Refactor and make the functions called under device initialization
public. A later patch adds a test that calls these functions to validate
the UAPI of SR-IOV devices. Opportunistically, to test the success
and failure cases of the UAPI, split the functions dealing with
VFIO_GROUP_GET_DEVICE_FD and VFIO_DEVICE_BIND_IOMMUFD into a core
function and another one that asserts the ioctl. The former will be
used for testing the SR-IOV UAPI, hence only export these.

Signed-off-by: Raghavendra Rao Ananta &lt;rananta@google.com&gt;
Reviewed-by: David Matlack &lt;dmatlack@google.com&gt;
Reviewed-by: Vipin Sharma &lt;vipinsh@google.com&gt;
Tested-by: David Matlack &lt;dmatlack@google.com&gt;
Link: https://lore.kernel.org/r/20260505212838.1698034-6-rananta@google.com
Signed-off-by: Alex Williamson &lt;alex@shazbot.org&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>vfio: selftests: Introduce a sysfs lib</title>
<updated>2026-05-20T17:54:10+00:00</updated>
<author>
<name>Raghavendra Rao Ananta</name>
<email>rananta@google.com</email>
</author>
<published>2026-05-05T21:28:33+00:00</published>
<link rel='alternate' type='text/html' href='https://git.tavy.me/linux.git/commit/?id=c5db77a035e1291e2c9b488073c28b441e5e44f3'/>
<id>c5db77a035e1291e2c9b488073c28b441e5e44f3</id>
<content type='text'>
Introduce a sysfs library to handle the common reads/writes to the
PCI sysfs files, for example, getting the total number of VFs supported
by the device via /sys/bus/pci/devices/$BDF/sriov_totalvfs. The library
will be used in the upcoming test patch to configure the VFs for a given
PF device.

Since readlink() is quite commonly used in the lib, introduce and use
readlink_safe() to take care of potential buffer overrun errors and to
safely terminate the buffer with '\0'.

Opportunistically, move vfio_pci_get_group_from_dev() to this library as
it falls under the same bucket. Rename it to sysfs_iommu_group_get() to
align with other function names.

Signed-off-by: Raghavendra Rao Ananta &lt;rananta@google.com&gt;
Reviewed-by: Vipin Sharma &lt;vipinsh@google.com&gt;
Reviewed-by: David Matlack &lt;dmatlack@google.com&gt;
Tested-by: David Matlack &lt;dmatlack@google.com&gt;
Link: https://lore.kernel.org/r/20260505212838.1698034-4-rananta@google.com
Signed-off-by: Alex Williamson &lt;alex@shazbot.org&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Introduce a sysfs library to handle the common reads/writes to the
PCI sysfs files, for example, getting the total number of VFs supported
by the device via /sys/bus/pci/devices/$BDF/sriov_totalvfs. The library
will be used in the upcoming test patch to configure the VFs for a given
PF device.

Since readlink() is quite commonly used in the lib, introduce and use
readlink_safe() to take care of potential buffer overrun errors and to
safely terminate the buffer with '\0'.

Opportunistically, move vfio_pci_get_group_from_dev() to this library as
it falls under the same bucket. Rename it to sysfs_iommu_group_get() to
align with other function names.

Signed-off-by: Raghavendra Rao Ananta &lt;rananta@google.com&gt;
Reviewed-by: Vipin Sharma &lt;vipinsh@google.com&gt;
Reviewed-by: David Matlack &lt;dmatlack@google.com&gt;
Tested-by: David Matlack &lt;dmatlack@google.com&gt;
Link: https://lore.kernel.org/r/20260505212838.1698034-4-rananta@google.com
Signed-off-by: Alex Williamson &lt;alex@shazbot.org&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>vfio: selftests: Introduce snprintf_assert()</title>
<updated>2026-05-20T17:54:10+00:00</updated>
<author>
<name>Raghavendra Rao Ananta</name>
<email>rananta@google.com</email>
</author>
<published>2026-05-05T21:28:32+00:00</published>
<link rel='alternate' type='text/html' href='https://git.tavy.me/linux.git/commit/?id=91ee1738a9d358d3e0120a783cc052c275dea5e5'/>
<id>91ee1738a9d358d3e0120a783cc052c275dea5e5</id>
<content type='text'>
Introduce snprintf_assert() to protect the users of snprintf() to fail
if the requested operation was truncated due to buffer limits. VFIO
tests and libraries, including a new sysfs library that will be introduced
by an upcoming patch, rely quite heavily on snprintf()s to build PCI
sysfs paths. Having a protection against this will be helpful to prevent
false test failures.

Signed-off-by: Raghavendra Rao Ananta &lt;rananta@google.com&gt;
Reviewed-by: David Matlack &lt;dmatlack@google.com&gt;
Reviewed-by: Vipin Sharma &lt;vipinsh@google.com&gt;
Tested-by: David Matlack &lt;dmatlack@google.com&gt;
Link: https://lore.kernel.org/r/20260505212838.1698034-3-rananta@google.com
Signed-off-by: Alex Williamson &lt;alex@shazbot.org&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Introduce snprintf_assert() to protect the users of snprintf() to fail
if the requested operation was truncated due to buffer limits. VFIO
tests and libraries, including a new sysfs library that will be introduced
by an upcoming patch, rely quite heavily on snprintf()s to build PCI
sysfs paths. Having a protection against this will be helpful to prevent
false test failures.

Signed-off-by: Raghavendra Rao Ananta &lt;rananta@google.com&gt;
Reviewed-by: David Matlack &lt;dmatlack@google.com&gt;
Reviewed-by: Vipin Sharma &lt;vipinsh@google.com&gt;
Tested-by: David Matlack &lt;dmatlack@google.com&gt;
Link: https://lore.kernel.org/r/20260505212838.1698034-3-rananta@google.com
Signed-off-by: Alex Williamson &lt;alex@shazbot.org&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>vfio: selftests: Align BAR mmaps for efficient IOMMU mapping</title>
<updated>2026-01-19T17:06:30+00:00</updated>
<author>
<name>Alex Mastro</name>
<email>amastro@fb.com</email>
</author>
<published>2026-01-14T18:57:17+00:00</published>
<link rel='alternate' type='text/html' href='https://git.tavy.me/linux.git/commit/?id=557dbdf6c4e9c2dc3d4a4476c67ef14dca32378d'/>
<id>557dbdf6c4e9c2dc3d4a4476c67ef14dca32378d</id>
<content type='text'>
Update vfio_pci_bar_map() to align BAR mmaps for efficient huge page
mappings. The manual mmap alignment can be removed once mmap(!MAP_FIXED)
on vfio device fds improves to automatically return well-aligned
addresses.

Also add MADV_HUGEPAGE, which encourages the kernel to use huge pages
(e.g. when /sys/kernel/mm/transparent_hugepage/enabled is set to "madvise").

Drop MAP_FILE from mmap(). It is an ignored compatibility flag.

Signed-off-by: Alex Mastro &lt;amastro@fb.com&gt;
Reviewed-by: David Matlack &lt;dmatlack@google.com&gt;
Tested-by: David Matlack &lt;dmatlack@google.com&gt;
Link: https://lore.kernel.org/r/20260114-map-mmio-test-v3-2-44e036d95e64@fb.com
Signed-off-by: Alex Williamson &lt;alex@shazbot.org&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Update vfio_pci_bar_map() to align BAR mmaps for efficient huge page
mappings. The manual mmap alignment can be removed once mmap(!MAP_FIXED)
on vfio device fds improves to automatically return well-aligned
addresses.

Also add MADV_HUGEPAGE, which encourages the kernel to use huge pages
(e.g. when /sys/kernel/mm/transparent_hugepage/enabled is set to "madvise").

Drop MAP_FILE from mmap(). It is an ignored compatibility flag.

Signed-off-by: Alex Mastro &lt;amastro@fb.com&gt;
Reviewed-by: David Matlack &lt;dmatlack@google.com&gt;
Tested-by: David Matlack &lt;dmatlack@google.com&gt;
Link: https://lore.kernel.org/r/20260114-map-mmio-test-v3-2-44e036d95e64@fb.com
Signed-off-by: Alex Williamson &lt;alex@shazbot.org&gt;
</pre>
</div>
</content>
</entry>
</feed>
