Skip to content

Commit 0aec1c2

Browse files
author
Myron Stowe
committed
PCI/ACS: Fix 'pci=config_acs=' parameter
JIRA: https://issues.redhat.com/browse/RHEL-72898 Upstream Status: 9cf8a95 commit 9cf8a95 Author: Tushar Dave <tdave@nvidia.com> Date: Thu Feb 6 19:03:38 2025 -0800 PCI/ACS: Fix 'pci=config_acs=' parameter Commit 47c8846 ("PCI: Extend ACS configurability") introduced bugs that fail to configure ACS ctrl to the value specified by the kernel parameter. Essentially there are two bugs: 1) When ACS is configured for multiple PCI devices using 'config_acs' kernel parameter, it results into error "PCI: Can't parse ACS command line parameter". This is due to a bug that doesn't preserve the ACS mask, but instead overwrites the mask with value 0. For example, using 'config_acs' to configure ACS ctrl for multiple BDFs fails: Kernel command line: pci=config_acs=1111011@0020:02:00.0;101xxxx@0039:00:00.0 "dyndbg=file drivers/pci/pci.c +p" PCI: Can't parse ACS command line parameter pci 0020:02:00.0: ACS mask = 0x007f pci 0020:02:00.0: ACS flags = 0x007b pci 0020:02:00.0: Configured ACS to 0x007b After this fix: Kernel command line: pci=config_acs=1111011@0020:02:00.0;101xxxx@0039:00:00.0 "dyndbg=file drivers/pci/pci.c +p" pci 0020:02:00.0: ACS mask = 0x007f pci 0020:02:00.0: ACS flags = 0x007b pci 0020:02:00.0: ACS control = 0x005f pci 0020:02:00.0: ACS fw_ctrl = 0x0053 pci 0020:02:00.0: Configured ACS to 0x007b pci 0039:00:00.0: ACS mask = 0x0070 pci 0039:00:00.0: ACS flags = 0x0050 pci 0039:00:00.0: ACS control = 0x001d pci 0039:00:00.0: ACS fw_ctrl = 0x0000 pci 0039:00:00.0: Configured ACS to 0x0050 2) In the bit manipulation logic, we copy the bit from the firmware settings when mask bit 0. For example, 'disable_acs_redir' fails to clear all three ACS P2P redir bits due to the wrong bit fiddling: Kernel command line: pci=disable_acs_redir=0020:02:00.0;0030:02:00.0;0039:00:00.0 "dyndbg=file drivers/pci/pci.c +p" pci 0020:02:00.0: ACS mask = 0x002c pci 0020:02:00.0: ACS flags = 0xffd3 pci 0020:02:00.0: Configured ACS to 0xfffb pci 0030:02:00.0: ACS mask = 0x002c pci 0030:02:00.0: ACS flags = 0xffd3 pci 0030:02:00.0: Configured ACS to 0xffdf pci 0039:00:00.0: ACS mask = 0x002c pci 0039:00:00.0: ACS flags = 0xffd3 pci 0039:00:00.0: Configured ACS to 0xffd3 After this fix: Kernel command line: pci=disable_acs_redir=0020:02:00.0;0030:02:00.0;0039:00:00.0 "dyndbg=file drivers/pci/pci.c +p" pci 0020:02:00.0: ACS mask = 0x002c pci 0020:02:00.0: ACS flags = 0xffd3 pci 0020:02:00.0: ACS control = 0x007f pci 0020:02:00.0: ACS fw_ctrl = 0x007b pci 0020:02:00.0: Configured ACS to 0x0053 pci 0030:02:00.0: ACS mask = 0x002c pci 0030:02:00.0: ACS flags = 0xffd3 pci 0030:02:00.0: ACS control = 0x005f pci 0030:02:00.0: ACS fw_ctrl = 0x005f pci 0030:02:00.0: Configured ACS to 0x0053 pci 0039:00:00.0: ACS mask = 0x002c pci 0039:00:00.0: ACS flags = 0xffd3 pci 0039:00:00.0: ACS control = 0x001d pci 0039:00:00.0: ACS fw_ctrl = 0x0000 pci 0039:00:00.0: Configured ACS to 0x0000 Link: https://lore.kernel.org/r/20250207030338.456887-1-tdave@nvidia.com Fixes: 47c8846 ("PCI: Extend ACS configurability") Signed-off-by: Tushar Dave <tdave@nvidia.com> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com> Reviewed-by: Jason Gunthorpe <jgg@nvidia.com> Reviewed-by: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com> Signed-off-by: Myron Stowe <mstowe@redhat.com>
1 parent 37c258c commit 0aec1c2

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

drivers/pci/pci.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -955,23 +955,27 @@ struct pci_acs {
955955
};
956956

957957
static void __pci_config_acs(struct pci_dev *dev, struct pci_acs *caps,
958-
const char *p, u16 mask, u16 flags)
958+
const char *p, const u16 acs_mask, const u16 acs_flags)
959959
{
960+
u16 flags = acs_flags;
961+
u16 mask = acs_mask;
960962
char *delimit;
961963
int ret = 0;
962964

963965
if (!p)
964966
return;
965967

966968
while (*p) {
967-
if (!mask) {
969+
if (!acs_mask) {
968970
/* Check for ACS flags */
969971
delimit = strstr(p, "@");
970972
if (delimit) {
971973
int end;
972974
u32 shift = 0;
973975

974976
end = delimit - p - 1;
977+
mask = 0;
978+
flags = 0;
975979

976980
while (end > -1) {
977981
if (*(p + end) == '0') {
@@ -1028,10 +1032,14 @@ static void __pci_config_acs(struct pci_dev *dev, struct pci_acs *caps,
10281032

10291033
pci_dbg(dev, "ACS mask = %#06x\n", mask);
10301034
pci_dbg(dev, "ACS flags = %#06x\n", flags);
1035+
pci_dbg(dev, "ACS control = %#06x\n", caps->ctrl);
1036+
pci_dbg(dev, "ACS fw_ctrl = %#06x\n", caps->fw_ctrl);
10311037

1032-
/* If mask is 0 then we copy the bit from the firmware setting. */
1033-
caps->ctrl = (caps->ctrl & ~mask) | (caps->fw_ctrl & mask);
1034-
caps->ctrl |= flags;
1038+
/*
1039+
* For mask bits that are 0, copy them from the firmware setting
1040+
* and apply flags for all the mask bits that are 1.
1041+
*/
1042+
caps->ctrl = (caps->fw_ctrl & ~mask) | (flags & mask);
10351043

10361044
pci_info(dev, "Configured ACS to %#06x\n", caps->ctrl);
10371045
}

0 commit comments

Comments
 (0)