Add PCI configuration tests for SR-IOV VFs
Subsystems (2)
v3 cover Add PCI configuration tests for SR-IOV VFs
From: Piotr Piórkowski <[email protected]>
This series introduces PCI configuration space tests for SR-IOV Virtual Functions. It verifies the required values and read-only fields in the common PCI header, BARs, PCI Express capabilities, and optional Power Management, AER, and ATS capabilities. The series also adds the PCI helpers needed to read raw configuration space and find standard and extended capabilities.
v2 -> v3:
- Shared the standard capability list walk between find_pci_cap_offset() and igt_pci_config_raw_find_cap_offset().
- Masked the reserved low bits of capability pointers instead of rejecting them.
- Reported an inaccessible (0xff) capability pointer as -ENODEV.
- Stopped the extended capability walk on an all-ones header.
- Documented the remaining raw configuration space helpers.
- Used PCI_CFG_SPACE_EXP_SIZE from linux/pci_regs.h instead of a local definition.
- Moved the test state from globals to igt_main().
- Rejected a 64-bit memory BAR type in BAR5.
v1 -> v2:
- Dropped the unused find_pci_ext_cap_offset() helper.
- Registered sriov_pci_config in tests/meson.build.
- Enabled the VF and read its configuration space once in the fixture instead of repeating the setup for every subtest.
- Restored the driver autoprobe state and disabled the VF in the final fixture.
- Removed redundant informational messages.
- Simplified subtest descriptions while retaining detailed documentation.
- Corrected PCI register macro names for compatibility with pci_regs.h.
- Improved malformed conventional and extended capability chain handling.
- Added unit tests for valid, invalid, cyclic, and boundary capability chains.
- Added sriov_pci_config to the Xe CI blocklist as a separate patch, since it is intended for HW verification rather than recurring CI runs.
Piotr Piórkowski (4):
lib/igt_pci: Add raw configuration space helpers tests/sriov_pci_config: Add VF core config checks tests/sriov_pci_config: Add optional capability checks
intel-ci: Block igt@sriov_pci_config.*
lib/igt_pci.c | 191 +++++++++++++++++-- lib/igt_pci.h | 7 +- lib/tests/igt_pci.c | 76 ++++++++ lib/tests/meson.build | 1 + tests/intel-ci/xe.blocklist.txt | 1 + tests/meson.build | 1 + tests/sriov_pci_config.c | 323 ++++++++++++++++++++++++++++++++ 7 files changed, 580 insertions(+), 20 deletions(-) create mode 100644 lib/tests/igt_pci.c create mode 100644 tests/sriov_pci_config.c
Signature · 1 line
2.34.1
PATCH v3 1/4 lib/igt_pci: Add raw configuration space helpers
From: Piotr Piórkowski <[email protected]>
Add helpers to read raw PCI configuration space from sysfs and access its contents.
Provide little-endian u16/u32 readers and standard and extended capability lookup helpers for configuration-space buffers.
v2:
- Validate malformed and cyclic capability chains.
- Add unit tests for capability lookup and malformed chains.
v3:
- Share the capability list walk between the pciaccess and raw helpers.
- Mask reserved low bits of capability pointers instead of rejecting them.
- Stop the extended capability walk on an all-ones header.
- Rename the capability list start parameter to cap_ptr.
- Document the remaining raw configuration space helpers.
- Use PCI_CFG_SPACE_EXP_SIZE from linux/pci_regs.h.
--- lib/igt_pci.c | 191 +++++++++++++++++++++++++++++++++++++----- lib/igt_pci.h | 7 +- lib/tests/igt_pci.c | 76 +++++++++++++++++ lib/tests/meson.build | 1 + 4 files changed, 255 insertions(+), 20 deletions(-) create mode 100644 lib/tests/igt_pci.c
lib/igt_pci.c +172 -19
@@ -8,6 +8,7 @@#include <errno.h> #include <fcntl.h> #include <limits.h> +#include <linux/pci_regs.h> #include <string.h> #include <unistd.h> #include <pciaccess.h>
@@ -16,35 +17,71 @@#include "igt_pci.h" #include "igt_sysfs.h" -static int find_pci_cap_offset_at (struct pci_device *dev,enum pci_cap_id cap_id, -int start_offset) -{ -uint8_t offset =0xff ; -uint16_t cap_header =0xffff ; -int loop = (PCI_CFG_SPACE_SIZE -PCI_TYPE0_1_HEADER_SIZE ) - /sizeof (cap_header); +typedef int (*pci_cap_read_u16_fn )(void *ctx,unsigned int offset,uint16_t *val); -if (pci_device_cfg_read_u8 (dev, &offset, start_offset)) -return -1 ; +/* +* Walk the standard capability list starting at @cap_ptr, the value of the +* capability pointer (e.g. read from PCI_CAPS_START). Returns the offset of +* the capability with @cap_id (any capability if 0), 0 if not found, or a +* negative errno: -EIO on read failure, -ENODEV if config space is +* inaccessible (reads back as 0xff), -EINVAL if a pointer points into the +* header, -ELOOP if the list doesn't terminate. +*/ +static int pci_cap_walk (uint8_t cap_ptr,uint8_t cap_id, +pci_cap_read_u16_fn read_u16,void *ctx) +{ +int loop = (PCI_CFG_SPACE_SIZE -PCI_TYPE0_1_HEADER_SIZE ) /sizeof (uint16_t );while (loop--) { -igt_assert_f (offset !=0xff ,"pci config space inaccessible\n" ); +uint16_t cap_header; -if (offset <PCI_TYPE0_1_HEADER_SIZE ) -break ; +if (!cap_ptr) +return 0 ; -if (pci_device_cfg_read_u16 (dev, &cap_header, (offset &0xFC ))) -return -1 ; +if (cap_ptr ==0xff ) +return -ENODEV ; -if (!cap_id || cap_id == (cap_header &0xFF )) -return offset; +if (cap_ptr <PCI_TYPE0_1_HEADER_SIZE ) +return -EINVAL ; + +/* The two low bits of capability pointers are reserved */ + cap_ptr &=0xfc ; + +if (read_u16 (ctx, cap_ptr, &cap_header)) +return -EIO ; - offset = cap_header >>8 ; +if (!cap_id || cap_id == (cap_header &0xff )) +return cap_ptr; + + cap_ptr = cap_header >>8 ; } -igt_fail_on_f (loop <=0 && offset,"pci capability offset doesn't terminate\n" ); +return cap_ptr ? -ELOOP :0 ; +} -return 0 ; +static int pciaccess_read_u16 (void *ctx,unsigned int offset,uint16_t *val) +{ +return pci_device_cfg_read_u16 (ctx, val, offset); +} + +static int find_pci_cap_offset_at (struct pci_device *dev,enum pci_cap_id cap_id, +int start_offset) +{ +uint8_t cap_ptr; +int ret; + +if (pci_device_cfg_read_u8 (dev, &cap_ptr, start_offset)) +return -1 ; + + ret =pci_cap_walk (cap_ptr, cap_id, pciaccess_read_u16, dev); +igt_assert_f (ret != -ENODEV ,"pci config space inaccessible\n" ); +igt_fail_on_f (ret == -ELOOP ,"pci capability offset doesn't terminate\n" ); + +/* A pointer into the header has always terminated the list here */ +if (ret == -EINVAL ) +return 0 ; + +return ret == -EIO ?-1 : ret; }/**
@@ -61,6 +98,122 @@ int find_pci_cap_offset(struct pci_device *dev, enum pci_cap_id cap_id)return find_pci_cap_offset_at (dev, cap_id,PCI_CAPS_START ); } +/** +* igt_pci_config_raw_read: +* @pci_slot: PCI device BDF (e.g. "0000:01:00.0") +* @buffer: destination buffer +* @length: number of configuration-space bytes to read +* +* Read raw PCI configuration space through the device sysfs config attribute. +* +* Returns 0 on success, otherwise a negative errno-like value. +*/ +int igt_pci_config_raw_read (const char *pci_slot,void *buffer,size_t length) +{ +char path[PATH_MAX ]; +ssize_t ret; +int err; +int fd; + +if (!pci_slot || !buffer || !length) +return -EINVAL ; + +snprintf (path,sizeof (path),"/sys/bus/pci/devices/%s/config" , pci_slot); + fd =open (path,O_RDONLY |O_CLOEXEC ); +if (fd <0 ) +return -errno; + + ret =pread (fd, buffer, length,0 ); + err = errno; +close (fd); +if (ret <0 ) +return -err; + +return (size_t )ret == length ?0 : -EIO ; +} + +/** +* igt_pci_config_raw_read_u16: +* @config: raw configuration space buffer +* @offset: byte offset within @config +* +* Returns the little-endian 16-bit value at @offset. +*/ +uint16_t igt_pci_config_raw_read_u16 (const uint8_t *config,unsigned int offset) +{ +return config[offset] | (config[offset +1 ] <<8 ); +} + +/** +* igt_pci_config_raw_read_u32: +* @config: raw configuration space buffer +* @offset: byte offset within @config +* +* Returns the little-endian 32-bit value at @offset. +*/ +uint32_t igt_pci_config_raw_read_u32 (const uint8_t *config,unsigned int offset) +{ +return igt_pci_config_raw_read_u16 (config, offset) | + ((uint32_t )igt_pci_config_raw_read_u16 (config, offset +2 ) <<16 ); +} + +static int raw_read_u16 (void *ctx,unsigned int offset,uint16_t *val) +{ + *val =igt_pci_config_raw_read_u16 (ctx, offset); + +return 0 ; +} + +/** +* igt_pci_config_raw_find_cap_offset: +* @config: raw configuration space, at least PCI_CFG_SPACE_SIZE bytes +* @cap_id: searched standard capability id +* +* Returns the capability offset, 0 if not found, -ENODEV if config space +* is inaccessible, -EINVAL if the capability list points into the header or +* -ELOOP if the capability list doesn't terminate. +*/ +int igt_pci_config_raw_find_cap_offset (const uint8_t *config,uint8_t cap_id) +{ +return pci_cap_walk (config[PCI_CAPS_START ], cap_id, raw_read_u16, + (void *)config); +} + +/** +* igt_pci_config_raw_find_ext_cap_offset: +* @config: raw configuration space, at least PCI_CFG_SPACE_EXP_SIZE bytes +* @cap_id: searched extended capability id +* +* Returns the extended capability offset, 0 if not found or the extended +* configuration space is not accessible, -EINVAL if the list points outside +* the extended configuration space or -ELOOP if it doesn't terminate. +*/ +int igt_pci_config_raw_find_ext_cap_offset (const uint8_t *config,uint16_t cap_id) +{ +unsigned int offset =PCI_EXT_CAPS_START ; +unsigned int loop = (PCI_CFG_SPACE_EXP_SIZE - offset) /4 ; + +while (loop) { +uint32_t header =igt_pci_config_raw_read_u32 (config, offset); + + loop--; + +/* All ones: extended config space is not accessible */ +if (!header || header ==0xffffffff ) +return 0 ; +if ((header &0xffff ) == cap_id) +return offset; + + offset = (header >>20 ) &0xffc ; +if (!offset) +return 0 ; +if (offset <PCI_EXT_CAPS_START ) +return -EINVAL ; + } + +return -ELOOP ; +} +static int open_pci_driver_dir (const char *driver) {char path[PATH_MAX ];
lib/igt_pci.h +6 -1
@@ -15,7 +15,7 @@ struct pci_device;#define PCI_TYPE0_1_HEADER_SIZE 0x40#define PCI_CAPS_START 0x34 -#define PCI_CFG_SPACE_SIZE 0x100 +#define PCI_EXT_CAPS_START 0x100enum pci_cap_id {PCI_EXPRESS_CAP_ID =0x10
@@ -27,6 +27,11 @@ enum pci_cap_id {#define PCI_SLOT_PWR_CTRL_PRESENT (1 << 1)int find_pci_cap_offset (struct pci_device *dev,enum pci_cap_id cap_id); +int igt_pci_config_raw_read (const char *pci_slot,void *buffer,size_t length); +uint16_t igt_pci_config_raw_read_u16 (const uint8_t *config,unsigned int offset); +uint32_t igt_pci_config_raw_read_u32 (const uint8_t *config,unsigned int offset); +int igt_pci_config_raw_find_cap_offset (const uint8_t *config,uint8_t cap_id); +int igt_pci_config_raw_find_ext_cap_offset (const uint8_t *config,uint16_t cap_id);int igt_pci_device_unbind (const char *pci_slot);int igt_pci_driver_bind (const char *driver,const char *pci_slot);int igt_pci_driver_unbind (const char *driver,const char *pci_slot);
lib/tests/igt_pci.c new file +76 -0
76 lines not on this page · raw message
lib/tests/meson.build +1 -0
@@ -19,6 +19,7 @@ lib_tests = [ 'igt_invalid_subtest_name', 'igt_nesting', 'igt_no_exit', + 'igt_pci', 'igt_runnercomms_packets', 'igt_segfault', 'igt_simulation',
Signature · 1 line
2.34.1
PATCH v3 2/4 tests/sriov_pci_config: Add VF core config checks
In reply to Piórkowski, PiotrFrom: Piotr Piórkowski <[email protected]>
Add checks for PCI configuration fields required by SR-IOV VFs. Cover the common header, BARs, and PCI Express capability fields.
v2:
- Enable the VF and read its configuration once in the fixture.
- Restore driver autoprobe state and disable the VF during cleanup.
- Clarify test documentation and shorten runtime descriptions.
- Remove redundant informational messages.
v3:
- Move test state from globals to igt_main().
- Add missing blank lines in the test.
- Reject a 64-bit memory BAR type in BAR5.
--- tests/meson.build | 1 + tests/sriov_pci_config.c | 214 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 215 insertions(+) create mode 100644 tests/sriov_pci_config.c
tests/meson.build +1 -0
@@ -74,6 +74,7 @@ test_progs = [ 'meta_test', 'prime_vgem', 'sriov_basic', + 'sriov_pci_config', 'syncobj_basic', 'syncobj_eventfd', 'syncobj_wait',
tests/sriov_pci_config.c new file +214 -0
214 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH v3 3/4 tests/sriov_pci_config: Add optional capability checks
In reply to Piórkowski, PiotrFrom: Piotr Piórkowski <[email protected]>
Add subtests for the optional Power Management, Advanced Error Reporting, and Address Translation Service capabilities. Skip an optional-capability subtest when the capability is not exposed by the VF.
Validate the VF ROZ fields required by the SR-IOV specification, including Power Management Data Select/Data, AER status/mask/severity fields, and ATS Queue Depth/STU.
v2:
- Reuse the VF configuration captured by the common fixture.
- Use PCI register definitions available from linux/pci_regs.h.
- Simplify optional-capability skips and runtime descriptions.
- Remove redundant informational messages.
--- tests/sriov_pci_config.c | 109 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+)
tests/sriov_pci_config.c +109 -0
@@ -43,6 +43,21 @@* Description: Validate that the Current De-emphasis Level field in Link * Status 2 is RsvdZ and therefore reads as zero for PCIe Capability Version 2 * and later. +* +* SUBTEST: vf-power-management-capability +* Description: Validate that Data Select in Power Management Control and +* Power Management Data are ROZ and therefore read as zero when the optional +* Power Management capability is present. +* +* SUBTEST: vf-advanced-error-reporting +* Description: Validate that the specified ROZ bits in AER Uncorrectable +* Error Status, Mask, and Severity, and Correctable Error Status read as zero +* when the optional AER capability is present. +* +* SUBTEST: vf-ats-capability +* Description: Validate that ATS Queue Depth and the Smallest Translation Unit +* (STU) are ROZ and therefore read as zero when the optional ATS capability +* is present. */ IGT_TEST_DESCRIPTION("Validate PCI configuration fields required for SR-IOV, "
@@ -159,6 +174,85 @@ static void check_vf_pcie_capabilities_2(const uint8_t *config) lnksta2); } +static int get_optional_cap (const uint8_t *config,uint8_t cap_id,const char *name) +{ +int cap =igt_pci_config_raw_find_cap_offset (config, cap_id); + +igt_assert_f (cap >=0 ,"Invalid VF PCI capability list (%d)\n" , cap); +if (!cap) +igt_skip ("%s\n" , name); + +return cap; +} + +static int get_optional_ext_cap (const uint8_t *config,uint16_t cap_id,const char *name) +{ +int cap =igt_pci_config_raw_find_ext_cap_offset (config, cap_id); + +igt_assert_f (cap >=0 ,"Invalid VF extended capability list (%d)\n" , cap); +if (!cap) +igt_skip ("%s\n" , name); + +return cap; +} + +static void check_vf_power_management_capability (const uint8_t *config) +{ +int pm_cap =get_optional_cap (config,PCI_CAP_ID_PM , +"Power Management capability is not present" ); +uint16_t pm_ctrl =igt_pci_config_raw_read_u16 (config, pm_cap +PCI_PM_CTRL ); +uint8_t pm_data = config[pm_cap +PCI_PM_DATA_REGISTER ]; + +igt_assert_f (!(pm_ctrl &PCI_PM_CTRL_DATA_SEL_MASK ), +"Power Management Control: Data Select must be zero (0x%04x)\n" , pm_ctrl); +igt_assert_f (!pm_data,"Power Management Data: expected 0x00, got 0x%02x\n" , pm_data); +} + +static void check_vf_advanced_error_reporting (const uint8_t *config) +{ +const uint32_t uncor_roz =PCI_ERR_UNC_DLP |PCI_ERR_UNC_SURPDN | +PCI_ERR_UNC_FCP |PCI_ERR_UNC_RX_OVER | +PCI_ERR_UNC_MALF_TLP |PCI_ERR_UNC_ECRC ; +const uint32_t cor_roz =PCI_ERR_COR_RCVR |PCI_ERR_COR_BAD_TLP | +PCI_ERR_COR_REP_ROLL |PCI_ERR_COR_REP_TIMER ; +int aer_cap =get_optional_ext_cap (config,PCI_EXT_CAP_ID_ERR , +"Advanced Error Reporting capability is not present" ); +uint32_t uncor_status =igt_pci_config_raw_read_u32 (config, + aer_cap +PCI_ERR_UNCOR_STATUS ); +uint32_t uncor_mask =igt_pci_config_raw_read_u32 (config, + aer_cap +PCI_ERR_UNCOR_MASK ); +uint32_t uncor_severity =igt_pci_config_raw_read_u32 (config, + aer_cap +PCI_ERR_UNCOR_SEVER ); +uint32_t cor_status =igt_pci_config_raw_read_u32 (config, + aer_cap +PCI_ERR_COR_STATUS ); + +igt_assert_f (!(uncor_status & uncor_roz), +"AER Uncorrectable Error Status: VF ROZ bits are set (0x%08x)\n" , + uncor_status); +igt_assert_f (!(uncor_mask & uncor_roz), +"AER Uncorrectable Error Mask: VF ROZ bits are set (0x%08x)\n" , + uncor_mask); +igt_assert_f (!(uncor_severity & uncor_roz), +"AER Uncorrectable Error Severity: VF ROZ bits are set (0x%08x)\n" , + uncor_severity); +igt_assert_f (!(cor_status & cor_roz), +"AER Correctable Error Status: VF ROZ bits are set (0x%08x)\n" , + cor_status); +} + +static void check_vf_ats_capability (const uint8_t *config) +{ +int ats_cap =get_optional_ext_cap (config,PCI_EXT_CAP_ID_ATS , +"ATS capability is not present" ); +uint16_t ats_capability =igt_pci_config_raw_read_u16 (config, ats_cap +PCI_ATS_CAP ); +uint16_t ats_control =igt_pci_config_raw_read_u16 (config, ats_cap +PCI_ATS_CTRL ); + +igt_assert_f (!PCI_ATS_CAP_QDEP (ats_capability), +"ATS Capability: Queue Depth must be zero (0x%04x)\n" , ats_capability); +igt_assert_f (!PCI_ATS_CTRL_STU (ats_control), +"ATS Control: STU must be zero (0x%04x)\n" , ats_control); +} +int igt_main () {uint8_t vf_config[PCI_CFG_SPACE_EXP_SIZE ];
@@ -199,6 +293,21 @@ int igt_main()check_vf_pcie_capabilities_2 (vf_config); } +igt_describe ("Validate the optional VF Power Management capability" ); + igt_subtest("vf-power-management-capability") { +check_vf_power_management_capability (vf_config); + } + +igt_describe ("Validate the optional VF AER capability" ); + igt_subtest("vf-advanced-error-reporting") { +check_vf_advanced_error_reporting (vf_config); + } + +igt_describe ("Validate the optional VF ATS capability" ); + igt_subtest("vf-ats-capability") { +check_vf_ats_capability (vf_config); + } + igt_fixture() {igt_abort_on_f (pf_fd <0 ,"Device is not accessible\n" );igt_sriov_disable_vfs (pf_fd);
Signature · 1 line
2.34.1
PATCH v3 4/4 intel-ci: Block igt@sriov_pci_config.*
In reply to Piórkowski, PiotrFrom: Piotr Piórkowski <[email protected]>
This test is intended for HW verification and does not need to run in recurring CI runs.
--- tests/intel-ci/xe.blocklist.txt | 1 + 1 file changed, 1 insertion(+)
tests/intel-ci/xe.blocklist.txt +1 -0
@@ -116,6 +116,7 @@ igt@sriov_basic@bind-unbind-vf$ ################################################################## # SR-IOV tests for HW checkout, not suited for recurring CI runs ################################################################## +igt@sriov_pci_config.* igt@xe_sriov_ggtt.* ################################################################## # Chamelium V1 HDMI receiver supports a maximum resolution
Signature · 1 line
2.34.1