AI Trajectory


Trajectory: (Expand/Collapse All)
Seq Timestamp Type Name Duration
0/0 2026/11/08 03:20 flow patch-triage
17m Args:
null

Results:
{
  "EnableConfigs": null,
  "FocusSymbols": [],
  "KMSANReasoning": "",
  "NeedsKMSAN": false,
  "Reasoning": "The patch series refactors PCI Access Control Services (ACS) peer-to-peer DMA (P2PDMA) routing logic in drivers/pci/p2pdma.c, adds read error checks in drivers/pci/pci.c and drivers/pci/quirks.c, and adds a KUnit test suite in drivers/pci/pci_acs_test.c. In standard virtualized fuzzing environments (QEMU/GCE), the modified P2PDMA code paths are structurally unreachable because no PCIe P2PDMA memory providers (such as NVMe controllers with CMB or accelerator ASICs) or PCIe switch fabrics with ACS redirect capabilities are emulated or available. Furthermore, pci_acs_flags_enabled is only called during device probing/IOMMU group initialization at boot time, and KUnit unit tests are not exercised by syzkaller syscall fuzzing.",
  "WorthFuzzing": false
}

1/1 2026/11/08 03:20 action read-patch-diff
0m Args:
null

Results:
{
  "PatchDiff": "commit adff3f91dd81741a0584e6c5f2b042c8d97d6d80\nAuthor: syz-cluster \u003ctriage@syzkaller.com\u003e\nDate:   Sun Nov 8 03:20:38 2026 +0000\n\n    syz-cluster: applied patch under review\n\ndiff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt\nindex 0b3c140babd944..f7e116703ffcd1 100644\n--- a/Documentation/admin-guide/kernel-parameters.txt\n+++ b/Documentation/admin-guide/kernel-parameters.txt\n@@ -5251,11 +5251,12 @@ Kernel parameters\n \t\t\t\tSpecify one or more PCI devices (in the format\n \t\t\t\tspecified above) separated by semicolons.\n \t\t\t\tEach device specified will have the PCI ACS\n-\t\t\t\tredirect capabilities forced off which will\n-\t\t\t\tallow P2P traffic between devices through\n-\t\t\t\tbridges without forcing it upstream. Note:\n-\t\t\t\tthis removes isolation between devices and\n-\t\t\t\tmay put more devices in an IOMMU group.\n+\t\t\t\tP2P Request Redirect, Completion Redirect, and\n+\t\t\t\tEgress Control features forced off. This may\n+\t\t\t\tallow P2P traffic through bridges that would\n+\t\t\t\totherwise be redirected upstream. Note: this\n+\t\t\t\tremoves isolation between devices and may\n+\t\t\t\tcause affected devices to share an IOMMU group.\n \t\tconfig_acs=\n \t\t\t\tFormat:\n \t\t\t\t\u003cACS flags\u003e@\u003cpci_dev\u003e[; ...]\ndiff --git a/Documentation/driver-api/pci/p2pdma.rst b/Documentation/driver-api/pci/p2pdma.rst\nindex 63cff9e4d2c9ac..7760ff64ed05b8 100644\n--- a/Documentation/driver-api/pci/p2pdma.rst\n+++ b/Documentation/driver-api/pci/p2pdma.rst\n@@ -15,6 +15,112 @@ then based on the ACS settings the transaction can route entirely within\n the PCIe hierarchy and never reach the root port. The kernel will evaluate\n the PCIe topology and always permit P2P in these well-defined cases.\n \n+The client is the PCIe Requester and the provider is the Completer, whether\n+the client reads or writes provider memory. For devices on separate links\n+below the same Root Port, their paths first meet in a Switch, where they\n+diverge.\n+A Request enters that Switch through the Downstream Port above the\n+Requester, the Requester-side port. If ACS P2P Request Redirect is enabled\n+there, the Request is routed upstream; otherwise it is routed back\n+downstream through the Downstream Port leading to the Completer, the\n+Completer-side port. The path of Completions from a read likewise depends on\n+ACS P2P Completion Redirect in the Completer-side port. An enabled Egress\n+Control is conservatively treated as a Request redirect.\n+\n+Below the divergence, the route toward the other branch is already upstream,\n+so those P2P redirect controls do not affect it. Redirect controls for the\n+reverse transaction directions do not affect the mapping. P2P DMA is routed\n+through the host bridge when either applicable port redirects. If an ACS\n+Control register needed for a route cannot be read, that route is rejected.\n+\n+Functions sharing one PCIe link can instead route internally within their\n+device. An ACS capability without Request or Completion Redirect support\n+means that the corresponding internal route does not exist. Device-specific\n+ACS quirks can report the same restriction for functions without ACS, and\n+SR-IOV functions without ACS cannot support internal peer traffic. These\n+restrictions apply only between functions sharing the link, including ARI\n+functions and VFs; they do not redirect traffic to a separate device.\n+\n+When traffic continues upstream beyond the divergence, ACS Upstream Forwarding\n+must be enabled, or provided by a device-specific quirk, at every shared\n+Downstream and Root Port on the way to the host bridge. This includes ports\n+above a shared Switch Upstream Port as well as ports shared by sibling\n+functions. Missing forwarding support or unreadable forwarding controls reject\n+the host route while leaving direct routes available. The host bridge must\n+also support P2P. Clearing redirect controls cannot create an internal route\n+that the device does not support.\n+\n+Three of those controls act on TLP attributes that the Requester chooses rather\n+than on the topology, so the same path routes differently for different\n+traffic. ACS Translation Blocking rejects any upstream Request whose Address\n+Type is not Untranslated, and takes precedence over every other P2P control.\n+ACS Direct Translated P2P routes a Translated Request to the peer regardless of\n+Request Redirect and Egress Control. ACS Completion Redirect leaves alone\n+Completions that carry the Relaxed Ordering attribute, which a Completion\n+copies from the Request it answers.\n+\n+P2PDMA therefore decides each class of traffic separately, and\n+``pci_p2pdma_map_type()`` answers for the one a DMA mapping is built for:\n+strictly ordered Requests carrying an Untranslated address.\n+\n+The PCIe ATS Enable bit covers the whole device, and most devices translate\n+any address they are handed once it is set. Unless a driver has declared with\n+``pcim_p2pdma_set_ats_per_mapping()`` that its device chooses ATS per mapping,\n+that bit decides which Address Type P2PDMA assumes, and a client with ATS\n+enabled is never handed a bus address, which it would translate as though it\n+were an IOVA. Its Translated Requests may still route directly, but anything\n+it issues untranslated reaches the host bridge, so that route has to work too.\n+\n+The two directions are decided independently. Translation Blocking (TB),\n+Direct Translated P2P (DT), Request Redirect (RR) and Egress Control (EC) on\n+the Requester-side port decide the Request:\n+\n+=====  =====  =======  ============  ==========\n+TB     DT     RR/EC    TLP class     Request\n+=====  =====  =======  ============  ==========\n+set    x      x        translated    blocked\n+clear  set    x        translated    direct\n+clear  clear  clear    translated    direct\n+clear  clear  set      translated    redirected\n+x      x      clear    untranslated  direct\n+x      x      set      untranslated  redirected\n+=====  =====  =======  ============  ==========\n+\n+Completion Redirect (CR) on the Completer-side port decides the Completions:\n+\n+=====  =========  ==========\n+CR     TLP class  Completion\n+=====  =========  ==========\n+x      relaxed    direct\n+clear  strict     direct\n+set    strict     redirected\n+=====  =========  ==========\n+\n+Combining the two tables gives the mapping type. A class is bus addressable\n+when its Request and its Completions both route directly, and anything else\n+goes through the host bridge. A blocked Request has neither route, because\n+Translation Blocking rejects the Address Type itself rather than the\n+destination. With no ACS control set anywhere, every class routes directly\n+provided that any required internal route between sibling functions exists.\n+Neither Direct Translated P2P nor Relaxed Ordering can create such a route.\n+\n+Some ports without an ACS capability, such as certain Zhaoxin Switch\n+Downstream Ports, redirect peer-to-peer traffic anyway, and a device-specific\n+ACS quirk tells the kernel so. P2PDMA treats such a port as having Request and\n+Completion Redirect set, but with no exception for Relaxed Ordering, so it\n+redirects every Completion.\n+\n+Note that DT only matters where RR or EC would otherwise redirect: it\n+overrides them for a Translated address rather than granting a direct route\n+that was not already there.\n+\n+Translation Blocking is not a routing control, so it is evaluated on every\n+port the Request passes on its way upstream rather than at the divergence\n+alone. A direct route turns around at the divergence and only passes the ports\n+below it, while the host bridge route keeps climbing and passes that port and\n+everything above it as well. Neither route falls back to the other, because\n+the Address Type is rejected wherever the Request is addressed.\n+\n However, if the P2P transaction reaches the host bridge then it might have to\n hairpin back out the same root port, be routed inside the CPU SOC to another\n PCIe root port, or routed internally to the SOC.\ndiff --git a/drivers/pci/Kconfig b/drivers/pci/Kconfig\nindex 0c7408509ba24b..7a3eb5beb3281b 100644\n--- a/drivers/pci/Kconfig\n+++ b/drivers/pci/Kconfig\n@@ -226,6 +226,21 @@ config PCI_P2PDMA\n \n \t  If unsure, say N.\n \n+config PCI_ACS_KUNIT_TEST\n+\ttristate \"KUnit tests for PCI ACS P2P routing\" if !KUNIT_ALL_TESTS\n+\tdepends on PCI_P2PDMA \u0026\u0026 KUNIT\n+\tdefault KUNIT_ALL_TESTS\n+\thelp\n+\t  Enable KUnit tests for the PCI ACS peer-to-peer routing decision\n+\t  logic, including direction-specific Request and Completion\n+\t  controls that cannot all be exercised on typical peer-to-peer\n+\t  hardware.\n+\n+\t  For more information on KUnit and unit tests in general, refer to\n+\t  the KUnit documentation in Documentation/dev-tools/kunit/.\n+\n+\t  If unsure, say N.\n+\n config PCI_LABEL\n \tdef_bool y if (DMI || ACPI)\n \tselect NLS\ndiff --git a/drivers/pci/Makefile b/drivers/pci/Makefile\nindex 41ebc3b9a51824..6305d128d3dff2 100644\n--- a/drivers/pci/Makefile\n+++ b/drivers/pci/Makefile\n@@ -31,6 +31,7 @@ obj-$(CONFIG_PCI_STUB)\t\t+= pci-stub.o\n obj-$(CONFIG_PCI_PF_STUB)\t+= pci-pf-stub.o\n obj-$(CONFIG_PCI_ECAM)\t\t+= ecam.o\n obj-$(CONFIG_PCI_P2PDMA)\t+= p2pdma.o\n+obj-$(CONFIG_PCI_ACS_KUNIT_TEST) += pci_acs_test.o\n obj-$(CONFIG_XEN_PCIDEV_FRONTEND) += xen-pcifront.o\n obj-$(CONFIG_VGA_ARB)\t\t+= vgaarb.o\n obj-$(CONFIG_PCI_DOE)\t\t+= doe.o\ndiff --git a/drivers/pci/p2pdma.c b/drivers/pci/p2pdma.c\nindex 45260423dfb092..a0f572e117d8dc 100644\n--- a/drivers/pci/p2pdma.c\n+++ b/drivers/pci/p2pdma.c\n@@ -21,9 +21,12 @@\n #include \u003clinux/seq_buf.h\u003e\n #include \u003clinux/xarray.h\u003e\n \n+#include \"pci.h\"\n+\n struct pci_p2pdma {\n \tstruct gen_pool *pool;\n \tbool p2pmem_published;\n+\tbool ats_per_mapping;\n \tstruct xarray map_types;\n \tstruct p2pdma_provider mem[PCI_STD_NUM_BARS];\n };\n@@ -491,25 +494,304 @@ static struct pci_dev *find_parent_pci_dev(struct device *dev)\n }\n \n /*\n- * Check if a PCI bridge has its ACS redirection bits set to redirect P2P\n- * TLPs upstream via ACS. Returns 1 if the packets will be redirected\n- * upstream, 0 otherwise.\n+ * Some ports send peer-to-peer traffic upstream without a standard ACS\n+ * capability, such as Zhaoxin Root and Switch Downstream Ports. Their\n+ * device-specific ACS quirks say so. Report whether @pdev's quirk says that\n+ * @flag is in effect.\n+ *\n+ * Only ask bridges. The quirks for multi-function endpoints only say that\n+ * their functions do not talk to each other directly, which says nothing\n+ * about their traffic to other devices. Skip bridges on a root bus too. They\n+ * never decide whether two peers connect directly, and for them the AMD\n+ * southbridge quirk calls acpi_get_table(), which may sleep. DMA mapping may\n+ * call this code where sleeping is not allowed.\n  */\n-static int pci_bridge_has_acs_redir(struct pci_dev *pdev)\n+static bool pci_acs_p2pdma_quirk(struct pci_dev *pdev, u16 flag)\n {\n-\tint pos;\n-\tu16 ctrl;\n+\tif (!pci_is_bridge(pdev) || pci_is_root_bus(pdev-\u003ebus))\n+\t\treturn false;\n+\n+\treturn pci_dev_specific_acs_enabled(pdev, flag) \u003e 0;\n+}\n+\n+/*\n+ * Add the Request and Completion Redirect that @pdev's quirk reports to its\n+ * ACS Control value. Only ever add them: a quirk that covers every device of\n+ * a vendor says \"no\" for the ones it does not know, and that must not hide\n+ * their own ACS controls. What a quirk says about other controls only means\n+ * that the control does not apply, so ignore it.\n+ */\n+static u16 pci_acs_p2pdma_quirk_redirect(struct pci_dev *pdev, u16 ctrl)\n+{\n+\tif (pci_acs_p2pdma_quirk(pdev, PCI_ACS_RR))\n+\t\tctrl |= PCI_ACS_RR;\n+\tif (pci_acs_p2pdma_quirk(pdev, PCI_ACS_CR))\n+\t\tctrl |= PCI_ACS_CR;\n+\n+\treturn ctrl;\n+}\n+\n+/*\n+ * Decide how a peer-to-peer Request at an ACS-capable ingress port routes,\n+ * from that port's ACS Control register and the Request's Address Type.\n+ *\n+ * Linux does not read the Egress Control Vector, so Egress Control is treated\n+ * conservatively as a redirect. Per PCIe r7.0 Table 6-11 the outcomes it\n+ * selects are a direct route and an ACS Violation, and neither one lets peer\n+ * bus addressing be assumed.\n+ */\n+VISIBLE_IF_KUNIT enum pci_acs_p2pdma_state\n+pci_acs_p2pdma_request(u16 ctrl, unsigned int tlp_flags)\n+{\n+\tif (tlp_flags \u0026 PCI_P2PDMA_TLP_TRANSLATED) {\n+\t\t/*\n+\t\t * PCIe r7.0 sec 6.12.1.1: Translation Blocking makes every\n+\t\t * Upstream Memory Request whose Address Type is not\n+\t\t * Untranslated an ACS Violation, taking precedence over the\n+\t\t * P2P controls. Sec 7.7.12.5: Direct Translated P2P \"is\n+\t\t * ignored if ACS Translation Blocking Enable is 1b\".\n+\t\t */\n+\t\tif (ctrl \u0026 PCI_ACS_TB)\n+\t\t\treturn PCI_ACS_P2PDMA_BLOCKED;\n+\n+\t\t/*\n+\t\t * PCIe r7.0 sec 6.12.3: ACS Direct Translated P2P routes a\n+\t\t * Request carrying a Translated address to the peer \"without\n+\t\t * redirection, regardless of ACS P2P Request Redirect and ACS\n+\t\t * P2P Egress Control settings\".\n+\t\t */\n+\t\tif (ctrl \u0026 PCI_ACS_DT)\n+\t\t\treturn PCI_ACS_P2PDMA_DIRECT;\n+\t}\n+\n+\treturn ctrl \u0026 (PCI_ACS_RR | PCI_ACS_EC) ?\n+\t\tPCI_ACS_P2PDMA_REDIRECT : PCI_ACS_P2PDMA_DIRECT;\n+}\n+EXPORT_SYMBOL_IF_KUNIT(pci_acs_p2pdma_request);\n+\n+/*\n+ * Decide how a peer-to-peer Completion at an ACS-capable ingress port routes.\n+ * PCIe r7.0 sec 6.12.1.1: no ACS control other than P2P Completion Redirect\n+ * affects a Completion, and that one leaves Completions carrying the Relaxed\n+ * Ordering attribute alone.\n+ */\n+VISIBLE_IF_KUNIT enum pci_acs_p2pdma_state\n+pci_acs_p2pdma_completion(u16 ctrl, unsigned int tlp_flags)\n+{\n+\tif (tlp_flags \u0026 PCI_P2PDMA_TLP_RELAXED_CPL)\n+\t\treturn PCI_ACS_P2PDMA_DIRECT;\n+\n+\treturn ctrl \u0026 PCI_ACS_CR ? PCI_ACS_P2PDMA_REDIRECT :\n+\t\t\t\t   PCI_ACS_P2PDMA_DIRECT;\n+}\n+EXPORT_SYMBOL_IF_KUNIT(pci_acs_p2pdma_completion);\n+\n+static const char *pci_acs_p2pdma_state_name(enum pci_acs_p2pdma_state state)\n+{\n+\tswitch (state) {\n+\tcase PCI_ACS_P2PDMA_DIRECT:\n+\t\treturn \"direct\";\n+\tcase PCI_ACS_P2PDMA_REDIRECT:\n+\t\treturn \"redirect\";\n+\tcase PCI_ACS_P2PDMA_BLOCKED:\n+\t\treturn \"blocked\";\n+\tcase PCI_ACS_P2PDMA_NOT_SUPPORTED:\n+\t\treturn \"not-supported\";\n+\t}\n+\n+\treturn \"invalid\";\n+}\n+\n+static const char *pci_p2pdma_map_type_name(enum pci_p2pdma_map_type type)\n+{\n+\tswitch (type) {\n+\tcase PCI_P2PDMA_MAP_UNKNOWN:\n+\t\treturn \"unknown\";\n+\tcase PCI_P2PDMA_MAP_NONE:\n+\t\treturn \"none\";\n+\tcase PCI_P2PDMA_MAP_NOT_SUPPORTED:\n+\t\treturn \"not-supported\";\n+\tcase PCI_P2PDMA_MAP_BUS_ADDR:\n+\t\treturn \"bus-address\";\n+\tcase PCI_P2PDMA_MAP_THRU_HOST_BRIDGE:\n+\t\treturn \"through-host-bridge\";\n+\t}\n+\n+\treturn \"invalid\";\n+}\n+\n+/*\n+ * Read @pdev's ACS Control register, with Request and Completion Redirect\n+ * taken from its ACS quirk if it has one. A device with neither has no\n+ * peer-to-peer controls at all. Whether functions can route internally is\n+ * checked separately. Returns false when the register cannot be read, or\n+ * reads as all ones, which is what a device that does not answer returns;\n+ * @ctrl is then meaningless.\n+ */\n+static bool pci_acs_p2pdma_ctrl(struct pci_dev *pdev, const char *what,\n+\t\t\t\tu16 *ctrl, bool verbose)\n+{\n+\tint pos, ret;\n \n \tpos = pdev-\u003eacs_cap;\n-\tif (!pos)\n-\t\treturn 0;\n+\tif (!pos) {\n+\t\tif (verbose)\n+\t\t\tpci_dbg(pdev,\n+\t\t\t\t\"P2PDMA ACS: %s has no ACS capability\\n\", what);\n+\t\t*ctrl = pci_acs_p2pdma_quirk_redirect(pdev, 0);\n+\t\treturn true;\n+\t}\n \n-\tpci_read_config_word(pdev, pos + PCI_ACS_CTRL, \u0026ctrl);\n+\tret = pci_dev_specific_read_acs_ctrl(pdev, ctrl);\n+\tif (ret == -ENOTTY)\n+\t\tret = pci_read_config_word(pdev, pos + PCI_ACS_CTRL, ctrl);\n+\tif (ret || PCI_POSSIBLE_ERROR(*ctrl)) {\n+\t\tif (verbose)\n+\t\t\tpci_dbg(pdev,\n+\t\t\t\t\"P2PDMA ACS: %s ACS Control read failed: cap=%#x status=%#x value=%#06x\\n\",\n+\t\t\t\t what, pos, ret, *ctrl);\n+\t\treturn false;\n+\t}\n \n-\tif (ctrl \u0026 (PCI_ACS_RR | PCI_ACS_CR | PCI_ACS_EC))\n-\t\treturn 1;\n+\t*ctrl = pci_acs_p2pdma_quirk_redirect(pdev, *ctrl);\n+\tif (verbose) {\n+\t\tpci_dbg(pdev,\n+\t\t\t \"P2PDMA ACS: %s cap=%#x caps=%#06x ctrl=%#06x\\n\",\n+\t\t\t what, pos, pdev-\u003eacs_capabilities, *ctrl);\n+\t\tpci_dbg(pdev,\n+\t\t\t \"P2PDMA ACS: control bits SV=%u TB=%u RR=%u CR=%u UF=%u EC=%u DT=%u\\n\",\n+\t\t\t !!(*ctrl \u0026 PCI_ACS_SV), !!(*ctrl \u0026 PCI_ACS_TB),\n+\t\t\t !!(*ctrl \u0026 PCI_ACS_RR), !!(*ctrl \u0026 PCI_ACS_CR),\n+\t\t\t !!(*ctrl \u0026 PCI_ACS_UF), !!(*ctrl \u0026 PCI_ACS_EC),\n+\t\t\t !!(*ctrl \u0026 PCI_ACS_DT));\n+\t}\n \n-\treturn 0;\n+\treturn true;\n+}\n+\n+static bool pci_acs_p2pdma_downstream_port(struct pci_dev *pdev)\n+{\n+\treturn pci_is_pcie(pdev) \u0026\u0026\n+\t\t(pci_pcie_type(pdev) == PCI_EXP_TYPE_ROOT_PORT ||\n+\t\t pci_pcie_type(pdev) == PCI_EXP_TYPE_DOWNSTREAM);\n+}\n+\n+/*\n+ * Only use this for functions sharing a PCIe link. An absent RR or CR\n+ * capability means that the corresponding internal peer route does not\n+ * exist, rather than that a programmable redirect is disabled. Likewise,\n+ * SR-IOV functions that support internal peer traffic must implement ACS.\n+ * Use each VF's own capability, not its PF's.\n+ */\n+static bool pci_acs_p2pdma_no_internal_route(struct pci_dev *pdev, u16 flag)\n+{\n+\tif (pci_dev_specific_acs_enabled(pdev, flag) \u003e 0)\n+\t\treturn true;\n+\n+\tif (pdev-\u003eacs_cap)\n+\t\treturn !(pdev-\u003eacs_capabilities \u0026 flag);\n+\n+\treturn pdev-\u003eis_physfn || pdev-\u003eis_virtfn;\n+}\n+\n+/*\n+ * Traffic redirected above the divergence has the same ingress and egress\n+ * at every shared Downstream Port. ACS Upstream Forwarding must carry it\n+ * toward the host instead of back down that link. Missing UF support does\n+ * not establish a forwarding route, even though it satisfies an isolation\n+ * query. Report unreadable controls separately from missing forwarding.\n+ */\n+static struct pci_dev *\n+pci_acs_p2pdma_no_upstream_forwarding(struct pci_dev *common,\n+\t\t\t\t    struct pci_dev **unreadable, bool verbose)\n+{\n+\tstruct pci_dev *pdev;\n+\tu16 ctrl;\n+\n+\tfor (pdev = common; pdev; pdev = pci_upstream_bridge(pdev)) {\n+\t\tif (!pci_acs_p2pdma_downstream_port(pdev))\n+\t\t\tcontinue;\n+\n+\t\tif (!pci_acs_p2pdma_ctrl(pdev, \"upstream forwarding\", \u0026ctrl,\n+\t\t\t\t\t verbose)) {\n+\t\t\t*unreadable = pdev;\n+\t\t\treturn NULL;\n+\t\t}\n+\n+\t\t/*\n+\t\t * Include Root Ports here. The PCIe port type check excludes\n+\t\t * the legacy AMD southbridge quirk, which may sleep.\n+\t\t */\n+\t\tif (pci_dev_specific_acs_enabled(pdev, PCI_ACS_UF) \u003e 0)\n+\t\t\tcontinue;\n+\n+\t\tif (!(pdev-\u003eacs_cap \u0026\u0026 pdev-\u003eacs_capabilities \u0026 ctrl \u0026 PCI_ACS_UF))\n+\t\t\treturn pdev;\n+\t}\n+\n+\treturn NULL;\n+}\n+\n+static void pci_p2pdma_log_path(const char *name, struct pci_dev *start,\n+\t\t\t\tstruct pci_dev *common)\n+{\n+\tstruct pci_dev *pdev, *upstream;\n+\tint hop = 0, type;\n+\n+\tfor (pdev = start; pdev; pdev = upstream, hop++) {\n+\t\tupstream = pci_upstream_bridge(pdev);\n+\t\ttype = pci_is_pcie(pdev) ? pci_pcie_type(pdev) : -1;\n+\t\tpci_dbg(pdev,\n+\t\t\t \"P2PDMA ACS: %s path hop=%d common=%u pcie=%u type=%d class=%#08x vendor=%04x device=%04x upstream=%s\\n\",\n+\t\t\t name, hop, pdev == common, pci_is_pcie(pdev), type,\n+\t\t\t pdev-\u003eclass, pdev-\u003evendor, pdev-\u003edevice,\n+\t\t\t upstream ? pci_name(upstream) : \"\u003cnone\u003e\");\n+\n+\t\t/* Cached state only: the routing logs the ACS Control it reads. */\n+\t\tif (pdev-\u003eacs_cap)\n+\t\t\tpci_dbg(pdev, \"P2PDMA ACS: ACS cap=%#x caps=%#06x\\n\",\n+\t\t\t\t pdev-\u003eacs_cap, pdev-\u003eacs_capabilities);\n+\t\telse\n+\t\t\tpci_dbg(pdev, \"P2PDMA ACS: ACS capability absent\\n\");\n+\t}\n+}\n+\n+/*\n+ * Report whether any port between @client and @common rejects Translated\n+ * addresses. If @common is NULL, every port up to the host bridge is walked.\n+ * A port whose ACS Control cannot be read counts as blocking, which withdraws\n+ * only the Translated classes because an Untranslated Request is routed by the\n+ * redirect controls instead.\n+ */\n+static bool pci_p2pdma_path_blocks_translation(struct pci_dev *client,\n+\t\t\t\t\t       struct pci_dev *common,\n+\t\t\t\t\t       bool verbose)\n+{\n+\tstruct pci_dev *pdev;\n+\tu16 ctrl;\n+\n+\t/*\n+\t * @common is @client itself when the provider is the client or sits\n+\t * below it. The Request never travels upstream then, so no port sees\n+\t * it and none can reject its Address Type.\n+\t */\n+\tif (client == common)\n+\t\treturn false;\n+\n+\tfor (pdev = pci_upstream_bridge(client); pdev \u0026\u0026 pdev != common;\n+\t     pdev = pci_upstream_bridge(pdev)) {\n+\t\tif (!pci_acs_p2pdma_ctrl(pdev, \"path hop\", \u0026ctrl, verbose))\n+\t\t\treturn true;\n+\n+\t\tif (ctrl \u0026 PCI_ACS_TB) {\n+\t\t\tif (verbose)\n+\t\t\t\tpci_dbg(pdev,\n+\t\t\t\t\t\"P2PDMA ACS: Translation Blocking rejects Translated Requests on this path\\n\");\n+\t\t\treturn true;\n+\t\t}\n+\t}\n+\n+\treturn false;\n }\n \n static void seq_buf_print_bus_devfn(struct seq_buf *buf, struct pci_dev *pdev)\n@@ -520,6 +802,220 @@ static void seq_buf_print_bus_devfn(struct seq_buf *buf, struct pci_dev *pdev)\n \tseq_buf_printf(buf, \"%s;\", pci_name(pdev));\n }\n \n+/*\n+ * Sort a port that redirects into @acs_list, the ports to suggest for\n+ * pci=disable_acs_redir=, or @quirk_list. That parameter only clears the ACS\n+ * Control register, so it cannot undo a redirect that a device quirk reports.\n+ */\n+static void pci_p2pdma_list_redir(struct seq_buf *acs_list,\n+\t\t\t\t  struct seq_buf *quirk_list,\n+\t\t\t\t  struct pci_dev *pdev)\n+{\n+\tif (pci_acs_p2pdma_quirk(pdev, PCI_ACS_RR) ||\n+\t    pci_acs_p2pdma_quirk(pdev, PCI_ACS_CR))\n+\t\tseq_buf_print_bus_devfn(quirk_list, pdev);\n+\telse\n+\t\tseq_buf_print_bus_devfn(acs_list, pdev);\n+}\n+\n+/* Drop the final semicolon. Returns false if no port was listed. */\n+static bool pci_p2pdma_end_list(struct seq_buf *list)\n+{\n+\tif (!seq_buf_used(list))\n+\t\treturn false;\n+\n+\tif (!seq_buf_has_overflowed(list))\n+\t\tlist-\u003ebuffer[list-\u003elen - 1] = '\\0';\n+\treturn true;\n+}\n+\n+static void pci_p2pdma_warn_redir(struct pci_dev *client,\n+\t\t\t\t  struct pci_dev *provider,\n+\t\t\t\t  struct seq_buf *acs_list,\n+\t\t\t\t  struct seq_buf *quirk_list)\n+{\n+\tpci_warn(client,\n+\t\t \"ACS redirect is set between the client and provider (%s)\\n\",\n+\t\t pci_name(provider));\n+\tif (pci_p2pdma_end_list(quirk_list))\n+\t\tpci_warn(client,\n+\t\t\t \"hardware redirects peer-to-peer traffic at %s, which no kernel parameter changes\\n\",\n+\t\t\t seq_buf_str(quirk_list));\n+\tif (pci_p2pdma_end_list(acs_list))\n+\t\tpci_warn(client,\n+\t\t\t \"to disable ACS controls for this path, add the kernel parameter: pci=disable_acs_redir=%s\\n\",\n+\t\t\t seq_buf_str(acs_list));\n+}\n+\n+/*\n+ * What the topology walk found out about one provider/client path. Producing\n+ * this costs a walk and config reads, none of which depends on the TLP being\n+ * routed.\n+ *\n+ * @req_ctrl:\tACS Control of the Requester-side divergence port. That is the\n+ *\t\tfirst port at which a Request can route toward the peer rather\n+ *\t\tthan upstream, so it is where the Request controls apply.\n+ * @cpl_ctrl:\tACS Control of the Completer-side divergence port, likewise for\n+ *\t\tthe Completions travelling back.\n+ * @cpl_quirk:\tA device quirk reports Completion Redirect at that port.\n+ * @req_upstream: The Requester has no internal route to its sibling.\n+ * @cpl_upstream: The Completer has no internal route to its sibling.\n+ * @tb_on_path:\tA port below the divergence blocks Translated addresses.\n+ *\t\tEvery route out of @client passes those, so none carries them.\n+ * @tb_above_divergence: A port at or above the divergence blocks Translated\n+ *\t\taddresses. Only a Request continuing to the host bridge passes\n+ *\t\tthose, so a direct route is still open to them.\n+ * @no_common_bridge: The two paths share no upstream bridge, so no direct\n+ *\t\troute exists for ACS to gate.\n+ * @unreadable:\tFirst port whose ACS Control could not be read, if any.\n+ * @uf_blocked:\tFirst shared port without usable Upstream Forwarding, if any.\n+ * @uf_unreadable: Shared port whose forwarding control could not be read.\n+ */\n+struct pci_p2pdma_acs_path {\n+\tu16 req_ctrl;\n+\tu16 cpl_ctrl;\n+\tbool cpl_quirk;\n+\tbool req_upstream;\n+\tbool cpl_upstream;\n+\tbool tb_on_path;\n+\tbool tb_above_divergence;\n+\tbool no_common_bridge;\n+\tstruct pci_dev *unreadable;\n+\tstruct pci_dev *uf_blocked;\n+\tstruct pci_dev *uf_unreadable;\n+};\n+\n+/*\n+ * ACS Translation Blocking is not a routing control, so unlike the redirect\n+ * controls it is not decided at the divergence alone. PCIe r7.0 sec 6.12.1.1\n+ * has every Downstream Port check the Address Type of each Upstream Memory\n+ * Request it receives, ahead of \"any applicable ACS P2P control mechanisms\".\n+ * A port below the divergence cannot redirect the Request anywhere it was not\n+ * already going, but it can still reject a Translated address.\n+ */\n+static enum pci_acs_p2pdma_state\n+pci_p2pdma_request_state(const struct pci_p2pdma_acs_path *path,\n+\t\t\t unsigned int tlp_flags)\n+{\n+\tif (tlp_flags \u0026 PCI_P2PDMA_TLP_TRANSLATED \u0026\u0026 path-\u003etb_on_path)\n+\t\treturn PCI_ACS_P2PDMA_BLOCKED;\n+\n+\tif (path-\u003ereq_upstream)\n+\t\treturn PCI_ACS_P2PDMA_REDIRECT;\n+\n+\treturn pci_acs_p2pdma_request(path-\u003ereq_ctrl, tlp_flags);\n+}\n+\n+/*\n+ * ACS P2P Completion Redirect leaves Relaxed Ordering Completions alone. A\n+ * device quirk that reports Completion Redirect does not promise that, so\n+ * treat every Completion through that port as redirected.\n+ */\n+static enum pci_acs_p2pdma_state\n+pci_p2pdma_completion_state(const struct pci_p2pdma_acs_path *path,\n+\t\t\t    unsigned int tlp_flags)\n+{\n+\tif (path-\u003ecpl_quirk || path-\u003ecpl_upstream)\n+\t\treturn PCI_ACS_P2PDMA_REDIRECT;\n+\n+\treturn pci_acs_p2pdma_completion(path-\u003ecpl_ctrl, tlp_flags);\n+}\n+\n+/*\n+ * Combine both directions into a mapping type. Only a path that routes the\n+ * Request and the Completions it generates directly can be programmed with\n+ * the peer's bus addresses.\n+ */\n+static enum pci_p2pdma_map_type\n+pci_p2pdma_route(const struct pci_p2pdma_acs_path *path,\n+\t\t unsigned int tlp_flags)\n+{\n+\tenum pci_acs_p2pdma_state req;\n+\n+\tif (path-\u003eunreadable)\n+\t\treturn PCI_P2PDMA_MAP_NOT_SUPPORTED;\n+\n+\treq = pci_p2pdma_request_state(path, tlp_flags);\n+\n+\t/*\n+\t * Translation Blocking rejects the Address Type rather than the\n+\t * target, so a blocked Request stays blocked however it is addressed.\n+\t * No host bridge fallback keeps a Translated address working; the\n+\t * caller has to issue a different kind of Request instead.\n+\t */\n+\tif (req == PCI_ACS_P2PDMA_BLOCKED)\n+\t\treturn PCI_P2PDMA_MAP_NOT_SUPPORTED;\n+\n+\tif (!path-\u003eno_common_bridge \u0026\u0026 req == PCI_ACS_P2PDMA_DIRECT \u0026\u0026\n+\t    pci_p2pdma_completion_state(path, tlp_flags) ==\n+\t\t    PCI_ACS_P2PDMA_DIRECT)\n+\t\treturn PCI_P2PDMA_MAP_BUS_ADDR;\n+\n+\tif (path-\u003euf_blocked || path-\u003euf_unreadable)\n+\t\treturn PCI_P2PDMA_MAP_NOT_SUPPORTED;\n+\n+\t/*\n+\t * A Request that turns around at the divergence never reaches the\n+\t * ports above it, but one that keeps climbing to the host bridge\n+\t * does, so that route has to clear their Translation Blocking too.\n+\t */\n+\tif (tlp_flags \u0026 PCI_P2PDMA_TLP_TRANSLATED \u0026\u0026 path-\u003etb_above_divergence)\n+\t\treturn PCI_P2PDMA_MAP_NOT_SUPPORTED;\n+\n+\treturn PCI_P2PDMA_MAP_THRU_HOST_BRIDGE;\n+}\n+\n+/*\n+ * Name the ports that keep this path off a direct route, so that the admin\n+ * can hand them to pci=disable_acs_redir=. That parameter clears the\n+ * redirect controls, which decide the default class, so that is the class\n+ * this reports on.\n+ */\n+static void pci_p2pdma_warn_path(struct pci_dev *client,\n+\t\t\t\t struct pci_dev *provider,\n+\t\t\t\t const struct pci_p2pdma_acs_path *path,\n+\t\t\t\t struct pci_dev *a_child,\n+\t\t\t\t struct pci_dev *b_child)\n+{\n+\tstruct seq_buf acs_list, quirk_list;\n+\tchar buf[128], quirk_buf[64];\n+\n+\tif (path-\u003eunreadable) {\n+\t\tpci_warn(client,\n+\t\t\t \"ACS Control is unreadable for provider %s at %s\\n\",\n+\t\t\t pci_name(provider), pci_name(path-\u003eunreadable));\n+\t\treturn;\n+\t}\n+\n+\tif (path-\u003euf_unreadable) {\n+\t\tpci_warn(client,\n+\t\t\t \"ACS Control is unreadable for provider %s at %s\\n\",\n+\t\t\t pci_name(provider), pci_name(path-\u003euf_unreadable));\n+\t} else if (path-\u003euf_blocked) {\n+\t\tpci_warn(client,\n+\t\t\t \"cannot forward peer-to-peer DMA for provider %s upstream at %s\\n\",\n+\t\t\t pci_name(provider), pci_name(path-\u003euf_blocked));\n+\t}\n+\n+\tif (path-\u003ereq_upstream || path-\u003ecpl_upstream) {\n+\t\tpci_warn(client,\n+\t\t\t \"peer-to-peer DMA with provider %s requires the host bridge; no internal route between functions\\n\",\n+\t\t\t pci_name(provider));\n+\t\treturn;\n+\t}\n+\n+\tseq_buf_init(\u0026acs_list, buf, sizeof(buf));\n+\tseq_buf_init(\u0026quirk_list, quirk_buf, sizeof(quirk_buf));\n+\tif (pci_acs_p2pdma_completion(path-\u003ecpl_ctrl, 0) !=\n+\t    PCI_ACS_P2PDMA_DIRECT)\n+\t\tpci_p2pdma_list_redir(\u0026acs_list, \u0026quirk_list, a_child);\n+\tif (pci_acs_p2pdma_request(path-\u003ereq_ctrl, 0) != PCI_ACS_P2PDMA_DIRECT)\n+\t\tpci_p2pdma_list_redir(\u0026acs_list, \u0026quirk_list, b_child);\n+\n+\tif (seq_buf_used(\u0026acs_list) || seq_buf_used(\u0026quirk_list))\n+\t\tpci_p2pdma_warn_redir(client, provider, \u0026acs_list, \u0026quirk_list);\n+}\n+\n static bool cpu_supports_p2pdma(void)\n {\n #ifdef CONFIG_X86\n@@ -679,15 +1175,43 @@ static unsigned long map_types_idx(struct pci_dev *client)\n \treturn (pci_domain_nr(client-\u003ebus) \u003c\u003c 16) | pci_dev_id(client);\n }\n \n+/*\n+ * One cache entry holds the routing of every TLP class, four bits each,\n+ * indexed by the \u0026enum pci_p2pdma_tlp_flags combination that selects it. An\n+ * absent entry reads back as PCI_P2PDMA_MAP_UNKNOWN in every class.\n+ */\n+static_assert(PCI_P2PDMA_MAP_THRU_HOST_BRIDGE \u003c 16);\n+\n+VISIBLE_IF_KUNIT unsigned long\n+pci_p2pdma_map_types_pack(const enum pci_p2pdma_map_type *type)\n+{\n+\tunsigned long val = 0;\n+\tunsigned int flags;\n+\n+\tfor (flags = 0; flags \u003c PCI_P2PDMA_TLP_CLASSES; flags++)\n+\t\tval |= (unsigned long)type[flags] \u003c\u003c (flags * 4);\n+\n+\treturn val;\n+}\n+EXPORT_SYMBOL_IF_KUNIT(pci_p2pdma_map_types_pack);\n+\n+VISIBLE_IF_KUNIT enum pci_p2pdma_map_type\n+pci_p2pdma_map_types_unpack(unsigned long val, unsigned int tlp_flags)\n+{\n+\treturn (val \u003e\u003e (tlp_flags * 4)) \u0026 0xf;\n+}\n+EXPORT_SYMBOL_IF_KUNIT(pci_p2pdma_map_types_unpack);\n+\n /*\n  * Calculate the P2PDMA mapping type and distance between two PCI devices.\n  *\n  * If the two devices are the same PCI function, return\n  * PCI_P2PDMA_MAP_BUS_ADDR and a distance of 0.\n  *\n- * If they are two functions of the same device, return\n- * PCI_P2PDMA_MAP_BUS_ADDR and a distance of 2 (one hop up to the bridge,\n- * then one hop back down to another function of the same device).\n+ * If they are two functions of the same device, return a distance of 2.\n+ * A bus address requires an internal route between the functions. Otherwise,\n+ * Upstream Forwarding must carry the traffic through their shared ports\n+ * toward a supported host bridge.\n  *\n  * In the case where two devices are connected to the same PCIe switch,\n  * return a distance of 4. This corresponds to the following PCI tree:\n@@ -704,10 +1228,21 @@ static unsigned long map_types_idx(struct pci_dev *client)\n  * then to Device B. The mapping type returned depends on the ACS\n  * redirection setting of the ports along the path.\n  *\n- * If ACS redirect is set on any port in the path, traffic between the\n- * devices will go through the host bridge, so return\n- * PCI_P2PDMA_MAP_THRU_HOST_BRIDGE; otherwise return\n- * PCI_P2PDMA_MAP_BUS_ADDR.\n+ * The client is the Requester and the provider the Completer. At the path\n+ * divergence, check Request Redirect, Egress Control and Direct Translated\n+ * P2P on the Requester-side port, and Completion Redirect for read\n+ * Completions on the Completer-side port. Translation Blocking is checked on\n+ * every port the Request passes instead, because it rejects a Request rather\n+ * than routing it.\n+ *\n+ * Those controls apply to different TLPs, so every class named by \u0026enum\n+ * pci_p2pdma_tlp_flags is decided from the one walk and cached together;\n+ * @tlp_flags selects which one is returned.\n+ *\n+ * If ACS redirects traffic at either divergence port, return\n+ * PCI_P2PDMA_MAP_THRU_HOST_BRIDGE. If the ACS Control register cannot be\n+ * read, or Translation Blocking rejects the class being asked about, return\n+ * PCI_P2PDMA_MAP_NOT_SUPPORTED. Otherwise, return PCI_P2PDMA_MAP_BUS_ADDR.\n  *\n  * Any two devices that have a data path that goes through the host bridge\n  * will consult a whitelist. If the host bridge is in the whitelist, return\n@@ -715,20 +1250,29 @@ static unsigned long map_types_idx(struct pci_dev *client)\n  * ports per above. If the device is not in the whitelist, return\n  * PCI_P2PDMA_MAP_NOT_SUPPORTED.\n  */\n-static enum pci_p2pdma_map_type\n+VISIBLE_IF_KUNIT enum pci_p2pdma_map_type\n calc_map_type_and_dist(struct pci_dev *provider, struct pci_dev *client,\n-\t\tint *dist, bool verbose)\n+\t\tint *dist, unsigned int tlp_flags, bool verbose)\n {\n-\tenum pci_p2pdma_map_type map_type = PCI_P2PDMA_MAP_THRU_HOST_BRIDGE;\n+\tenum pci_p2pdma_map_type map_type[PCI_P2PDMA_TLP_CLASSES];\n \tstruct pci_dev *a = provider, *b = client, *bb;\n+\tstruct pci_dev *a_child = NULL, *b_child = NULL;\n+\tstruct pci_host_bridge *provider_host, *client_host;\n+\tstruct pci_p2pdma_acs_path path = {};\n \tstruct pci_p2pdma *p2pdma;\n-\tstruct seq_buf acs_list;\n-\tint acs_cnt = 0;\n+\tbool cpu_p2pdma, host_whitelisted = false;\n+\tbool cache_store = false;\n+\tbool host_fallback = false;\n+\tunsigned int flags;\n \tint dist_a = 0;\n \tint dist_b = 0;\n-\tchar buf[128];\n+\tvoid *old;\n \n-\tseq_buf_init(\u0026acs_list, buf, sizeof(buf));\n+\tif (verbose)\n+\t\tpci_dbg(client,\n+\t\t\t\"P2PDMA ACS: begin provider=%s client=%s cache-index=%#lx\\n\",\n+\t\t\t pci_name(provider), pci_name(client),\n+\t\t\t map_types_idx(client));\n \n \t/*\n \t * Note, we don't need to take references to devices returned by\n@@ -737,77 +1281,245 @@ calc_map_type_and_dist(struct pci_dev *provider, struct pci_dev *client,\n \t */\n \twhile (a) {\n \t\tdist_b = 0;\n-\n-\t\tif (pci_bridge_has_acs_redir(a)) {\n-\t\t\tseq_buf_print_bus_devfn(\u0026acs_list, a);\n-\t\t\tacs_cnt++;\n-\t\t}\n-\n+\t\tb_child = NULL;\n \t\tbb = b;\n \n \t\twhile (bb) {\n \t\t\tif (a == bb)\n-\t\t\t\tgoto check_b_path_acs;\n+\t\t\t\tgoto check_paths_acs;\n \n+\t\t\tb_child = bb;\n \t\t\tbb = pci_upstream_bridge(bb);\n \t\t\tdist_b++;\n \t\t}\n \n+\t\ta_child = a;\n \t\ta = pci_upstream_bridge(a);\n \t\tdist_a++;\n \t}\n \n+\t/*\n+\t * The paths share no upstream bridge, so there is no direct path for\n+\t * ACS to gate: PCI_P2PDMA_MAP_BUS_ADDR is not reachable here and the\n+\t * request can only get to the peer through the host bridge.\n+\t */\n \t*dist = dist_a + dist_b;\n+\tif (verbose) {\n+\t\tpci_dbg(client,\n+\t\t\t\"P2PDMA ACS: no common upstream bridge provider-distance=%d client-distance=%d total=%d\\n\",\n+\t\t\t dist_a, dist_b, *dist);\n+\t\tpci_p2pdma_log_path(\"provider\", provider, NULL);\n+\t\tpci_p2pdma_log_path(\"client\", client, NULL);\n+\t}\n+\tpath.no_common_bridge = true;\n+\tpath.tb_on_path = pci_p2pdma_path_blocks_translation(client, NULL,\n+\t\t\t\t\t\t\t     verbose);\n+\tfor (flags = 0; flags \u003c PCI_P2PDMA_TLP_CLASSES; flags++)\n+\t\tmap_type[flags] = pci_p2pdma_route(\u0026path, flags);\n \tgoto map_through_host_bridge;\n \n-check_b_path_acs:\n-\tbb = b;\n-\n-\twhile (bb) {\n-\t\tif (a == bb)\n-\t\t\tbreak;\n+check_paths_acs:\n+\t*dist = dist_a + dist_b;\n+\tif (verbose) {\n+\t\tpci_dbg(client,\n+\t\t\t\"P2PDMA ACS: common=%s provider-divergence=%s client-divergence=%s provider-distance=%d client-distance=%d total=%d\\n\",\n+\t\t\t pci_name(a),\n+\t\t\t a_child ? pci_name(a_child) : \"\u003cnone\u003e\",\n+\t\t\t b_child ? pci_name(b_child) : \"\u003cnone\u003e\",\n+\t\t\t dist_a, dist_b, *dist);\n+\t\tpci_p2pdma_log_path(\"provider\", provider, a);\n+\t\tpci_p2pdma_log_path(\"client\", client, a);\n+\t}\n \n-\t\tif (pci_bridge_has_acs_redir(bb)) {\n-\t\t\tseq_buf_print_bus_devfn(\u0026acs_list, bb);\n-\t\t\tacs_cnt++;\n+\t/*\n+\t * ACS P2P routing controls apply where a TLP can route toward the peer\n+\t * or upstream. Below that divergence, its only route toward the other\n+\t * branch is upstream, so redirect controls do not affect the path.\n+\t */\n+\tif (a_child \u0026\u0026 b_child) {\n+\t\tif (!pci_acs_p2pdma_ctrl(a_child, \"completion\", \u0026path.cpl_ctrl,\n+\t\t\t\t\t verbose))\n+\t\t\tpath.unreadable = a_child;\n+\t\tpath.cpl_quirk = pci_acs_p2pdma_quirk(a_child, PCI_ACS_CR);\n+\t\tif (!pci_acs_p2pdma_ctrl(b_child, \"request\", \u0026path.req_ctrl,\n+\t\t\t\t\t verbose) \u0026\u0026 !path.unreadable)\n+\t\t\tpath.unreadable = b_child;\n+\t\t/*\n+\t\t * Two children of one Downstream or Root Port share a link.\n+\t\t * Use topology rather than slot numbers or the multifunction\n+\t\t * bit, since ARI functions and VFs need not share those.\n+\t\t */\n+\t\tif (pci_acs_p2pdma_downstream_port(a)) {\n+\t\t\tpath.req_upstream =\n+\t\t\t\tpci_acs_p2pdma_no_internal_route(b_child, PCI_ACS_RR);\n+\t\t\tpath.cpl_upstream =\n+\t\t\t\tpci_acs_p2pdma_no_internal_route(a_child, PCI_ACS_CR);\n \t\t}\n+\t\tif (verbose \u0026\u0026 !path.unreadable)\n+\t\t\tpci_dbg(client,\n+\t\t\t\t\"P2PDMA ACS: class=strict request=%s at %s completion=%s at %s\\n\",\n+\t\t\t\t pci_acs_p2pdma_state_name(\n+\t\t\t\t\t pci_p2pdma_request_state(\u0026path, 0)),\n+\t\t\t\t pci_name(b_child),\n+\t\t\t\t pci_acs_p2pdma_state_name(\n+\t\t\t\t\t pci_p2pdma_completion_state(\u0026path, 0)),\n+\t\t\t\t pci_name(a_child));\n+\t} else if (verbose) {\n+\t\tpci_dbg(client,\n+\t\t\t\"P2PDMA ACS: peer divergence is incomplete; no ACS peer-routing controls evaluated\\n\");\n+\t}\n \n-\t\tbb = pci_upstream_bridge(bb);\n+\tpath.tb_on_path = pci_p2pdma_path_blocks_translation(client, a,\n+\t\t\t\t\t\t\t     verbose);\n+\tif (b_child)\n+\t\tpath.tb_above_divergence =\n+\t\t\tpci_p2pdma_path_blocks_translation(b_child, NULL,\n+\t\t\t\t\t\t\t   verbose);\n+\n+\t/* Shared ports need forwarding only for classes using the host bridge. */\n+\tfor (flags = 0; flags \u003c PCI_P2PDMA_TLP_CLASSES; flags++) {\n+\t\tif (pci_p2pdma_route(\u0026path, flags) !=\n+\t\t    PCI_P2PDMA_MAP_THRU_HOST_BRIDGE)\n+\t\t\tcontinue;\n+\t\tpath.uf_blocked = pci_acs_p2pdma_no_upstream_forwarding(a,\n+\t\t\t\t\t\t\u0026path.uf_unreadable, verbose);\n+\t\tbreak;\n \t}\n \n-\t*dist = dist_a + dist_b;\n+\t/*\n+\t * The walk and the config reads above serve every class; only the\n+\t * decision below depends on the kind of TLP being routed.\n+\t */\n+\tfor (flags = 0; flags \u003c PCI_P2PDMA_TLP_CLASSES; flags++) {\n+\t\tmap_type[flags] = pci_p2pdma_route(\u0026path, flags);\n+\t\tif (map_type[flags] == PCI_P2PDMA_MAP_THRU_HOST_BRIDGE)\n+\t\t\thost_fallback = true;\n+\t}\n \n-\tif (!acs_cnt) {\n-\t\tmap_type = PCI_P2PDMA_MAP_BUS_ADDR;\n+\tif (verbose \u0026\u0026 map_type[0] != PCI_P2PDMA_MAP_BUS_ADDR)\n+\t\tpci_p2pdma_warn_path(client, provider, \u0026path, a_child,\n+\t\t\t\t     b_child);\n+\n+\t/*\n+\t * Nothing needs the host bridge: the classes that did not get a direct\n+\t * route have no fallback that would use it.\n+\t */\n+\tif (!host_fallback)\n \t\tgoto done;\n-\t}\n+\n+map_through_host_bridge:\n+\tcpu_p2pdma = cpu_supports_p2pdma();\n+\tif (!cpu_p2pdma)\n+\t\thost_whitelisted = host_bridge_whitelist(provider, client,\n+\t\t\t\t\t\t\t  verbose);\n \n \tif (verbose) {\n-\t\t/* Drop the final semicolon; the list is not empty here */\n-\t\tif (!seq_buf_has_overflowed(\u0026acs_list))\n-\t\t\tacs_list.buffer[acs_list.len - 1] = '\\0';\n-\t\tpci_warn(client, \"ACS redirect is set between the client and provider (%s)\\n\",\n-\t\t\t pci_name(provider));\n-\t\tpci_warn(client, \"to disable ACS redirect for this path, add the kernel parameter: pci=disable_acs_redir=%s\\n\",\n-\t\t\t seq_buf_str(\u0026acs_list));\n+\t\tprovider_host = pci_find_host_bridge(provider-\u003ebus);\n+\t\tclient_host = pci_find_host_bridge(client-\u003ebus);\n+\t\tpci_dbg(client,\n+\t\t\t\"P2PDMA ACS: host fallback cpu-support=%u whitelist=%s provider-host=%s client-host=%s same-host=%u\\n\",\n+\t\t\t cpu_p2pdma,\n+\t\t\t cpu_p2pdma ? \"not-consulted\" :\n+\t\t\t\t\t(host_whitelisted ? \"yes\" : \"no\"),\n+\t\t\t provider_host ? dev_name(\u0026provider_host-\u003edev) : \"\u003cnone\u003e\",\n+\t\t\t client_host ? dev_name(\u0026client_host-\u003edev) : \"\u003cnone\u003e\",\n+\t\t\t provider_host \u0026\u0026 provider_host == client_host);\n \t}\n \n-map_through_host_bridge:\n-\tif (!cpu_supports_p2pdma() \u0026\u0026\n-\t    !host_bridge_whitelist(provider, client, verbose)) {\n+\tif (!cpu_p2pdma \u0026\u0026 !host_whitelisted) {\n \t\tif (verbose)\n \t\t\tpci_warn(client, \"cannot be used for peer-to-peer DMA as the client and provider (%s) do not share an upstream bridge or whitelisted host bridge\\n\",\n \t\t\t\t pci_name(provider));\n-\t\tmap_type = PCI_P2PDMA_MAP_NOT_SUPPORTED;\n+\t\tfor (flags = 0; flags \u003c PCI_P2PDMA_TLP_CLASSES; flags++)\n+\t\t\tif (map_type[flags] == PCI_P2PDMA_MAP_THRU_HOST_BRIDGE)\n+\t\t\t\tmap_type[flags] = PCI_P2PDMA_MAP_NOT_SUPPORTED;\n \t}\n done:\n \trcu_read_lock();\n \tp2pdma = rcu_dereference(provider-\u003ep2pdma);\n-\tif (p2pdma)\n-\t\txa_store(\u0026p2pdma-\u003emap_types, map_types_idx(client),\n-\t\t\t xa_mk_value(map_type), GFP_ATOMIC);\n+\tif (p2pdma) {\n+\t\told = xa_store(\u0026p2pdma-\u003emap_types, map_types_idx(client),\n+\t\t\t       xa_mk_value(pci_p2pdma_map_types_pack(map_type)),\n+\t\t\t       GFP_ATOMIC);\n+\t\tcache_store = !xa_is_err(old);\n+\t}\n \trcu_read_unlock();\n-\treturn map_type;\n+\tif (verbose) {\n+\t\tpci_dbg(client,\n+\t\t\t\"P2PDMA ACS: final provider=%s result=%s(%d) tlp-flags=%#x distance=%d unreadable=%s cache-store=%u index=%#lx\\n\",\n+\t\t\t pci_name(provider),\n+\t\t\t pci_p2pdma_map_type_name(map_type[tlp_flags]),\n+\t\t\t map_type[tlp_flags], tlp_flags, *dist,\n+\t\t\t path.unreadable ? pci_name(path.unreadable) : \"\u003cnone\u003e\",\n+\t\t\t cache_store, map_types_idx(client));\n+\t\tpci_dbg(client,\n+\t\t\t\"P2PDMA ACS: classes strict=%s relaxed=%s translated=%s translated+relaxed=%s\\n\",\n+\t\t\t pci_p2pdma_map_type_name(map_type[0]),\n+\t\t\t pci_p2pdma_map_type_name(\n+\t\t\t\t map_type[PCI_P2PDMA_TLP_RELAXED_CPL]),\n+\t\t\t pci_p2pdma_map_type_name(\n+\t\t\t\t map_type[PCI_P2PDMA_TLP_TRANSLATED]),\n+\t\t\t pci_p2pdma_map_type_name(\n+\t\t\t\t map_type[PCI_P2PDMA_TLP_TRANSLATED |\n+\t\t\t\t\t  PCI_P2PDMA_TLP_RELAXED_CPL]));\n+\t}\n+\treturn map_type[tlp_flags];\n+}\n+EXPORT_SYMBOL_IF_KUNIT(calc_map_type_and_dist);\n+\n+VISIBLE_IF_KUNIT unsigned int\n+pci_p2pdma_client_tlp_flags(struct pci_dev *client, unsigned int tlp_flags)\n+{\n+\tif (client-\u003eats_enabled)\n+\t\treturn tlp_flags | PCI_P2PDMA_TLP_TRANSLATED;\n+\n+\treturn tlp_flags \u0026 ~PCI_P2PDMA_TLP_TRANSLATED;\n+}\n+EXPORT_SYMBOL_IF_KUNIT(pci_p2pdma_client_tlp_flags);\n+\n+/*\n+ * A client that translates every address it is handed cannot be handed a bus\n+ * address, which it would translate as though it were an IOVA. Its Translated\n+ * Requests may still route directly, but a Request it issues without a\n+ * translation carries the IOVA to the host bridge, so that route has to work\n+ * as well.\n+ *\n+ * Take the Address Type from @tlp_flags rather than reading the ATS Enable\n+ * bit again, so the policy and the class it applies to always agree.\n+ */\n+VISIBLE_IF_KUNIT enum pci_p2pdma_map_type\n+pci_p2pdma_client_map_type(struct pci_dev *provider, struct pci_dev *client,\n+\t\t\t   bool per_mapping, unsigned int tlp_flags,\n+\t\t\t   enum pci_p2pdma_map_type type)\n+{\n+\tif (per_mapping || !(tlp_flags \u0026 PCI_P2PDMA_TLP_TRANSLATED) ||\n+\t    type != PCI_P2PDMA_MAP_BUS_ADDR)\n+\t\treturn type;\n+\n+\tpci_dbg(client,\n+\t\t\"P2PDMA ACS: provider=%s bus address withheld; ATS is enabled for the whole client\\n\",\n+\t\t pci_name(provider));\n+\n+\tif (cpu_supports_p2pdma() ||\n+\t    host_bridge_whitelist(provider, client, false))\n+\t\treturn PCI_P2PDMA_MAP_THRU_HOST_BRIDGE;\n+\n+\treturn PCI_P2PDMA_MAP_NOT_SUPPORTED;\n+}\n+EXPORT_SYMBOL_IF_KUNIT(pci_p2pdma_client_map_type);\n+\n+/* Whether the driver of @client called pcim_p2pdma_set_ats_per_mapping(). */\n+static bool pci_p2pdma_client_per_mapping(struct pci_dev *client)\n+{\n+\tstruct pci_p2pdma *p2pdma;\n+\tbool per_mapping;\n+\n+\trcu_read_lock();\n+\tp2pdma = rcu_dereference(client-\u003ep2pdma);\n+\tper_mapping = p2pdma \u0026\u0026 p2pdma-\u003eats_per_mapping;\n+\trcu_read_unlock();\n+\n+\treturn per_mapping;\n }\n \n /**\n@@ -825,15 +1537,19 @@ calc_map_type_and_dist(struct pci_dev *provider, struct pci_dev *client,\n  *\n  * \"compatible\" means the provider and the clients are either all behind\n  * the same PCI root port or the host bridges connected to each of the devices\n- * are listed in the 'pci_p2pdma_whitelist'.\n+ * are listed in the 'pci_p2pdma_whitelist'. Each client is judged the way\n+ * pci_p2pdma_map_type() maps it, so one with ATS enabled for the whole device\n+ * also needs a host bridge that supports peer-to-peer DMA.\n  */\n int pci_p2pdma_distance_many(struct pci_dev *provider, struct device **clients,\n \t\t\t     int num_clients, bool verbose)\n {\n-\tenum pci_p2pdma_map_type map;\n+\tenum pci_p2pdma_map_type map, type;\n \tbool not_supported = false;\n \tstruct pci_dev *pci_client;\n+\tunsigned int tlp_flags;\n \tint total_dist = 0;\n+\tbool per_mapping;\n \tint i, distance;\n \n \tif (num_clients == 0)\n@@ -848,8 +1564,18 @@ int pci_p2pdma_distance_many(struct pci_dev *provider, struct device **clients,\n \t\t\treturn -1;\n \t\t}\n \n-\t\tmap = calc_map_type_and_dist(provider, pci_client, \u0026distance,\n-\t\t\t\t\t     verbose);\n+\t\tper_mapping = pci_p2pdma_client_per_mapping(pci_client);\n+\t\ttlp_flags = per_mapping ? 0 :\n+\t\t\t    pci_p2pdma_client_tlp_flags(pci_client, 0);\n+\t\ttype = calc_map_type_and_dist(provider, pci_client, \u0026distance,\n+\t\t\t\t\t      tlp_flags, verbose);\n+\t\tmap = pci_p2pdma_client_map_type(provider, pci_client,\n+\t\t\t\t\t\t per_mapping, tlp_flags, type);\n+\t\tif (verbose \u0026\u0026 map != type \u0026\u0026\n+\t\t    map == PCI_P2PDMA_MAP_NOT_SUPPORTED)\n+\t\t\tpci_warn(pci_client,\n+\t\t\t\t \"cannot be used for peer-to-peer DMA with %s: ATS is enabled for the whole device and the host bridge is not whitelisted\\n\",\n+\t\t\t\t pci_name(provider));\n \n \t\tpci_dev_put(pci_client);\n \n@@ -1114,44 +1840,121 @@ void pci_p2pmem_publish(struct pci_dev *pdev, bool publish)\n EXPORT_SYMBOL_GPL(pci_p2pmem_publish);\n \n /**\n- * pci_p2pdma_map_type - Determine the mapping type for P2PDMA transfers\n+ * pcim_p2pdma_set_ats_per_mapping - Declare per-mapping ATS for a client\n+ * @pdev: PCI device that initiates peer-to-peer DMA\n+ *\n+ * Declare that @pdev issues Translated Requests only for the DMA mappings its\n+ * driver sets up to use ATS, rather than for any address once ATS is enabled.\n+ * P2PDMA then routes this client's Requests with the Address Type each query\n+ * asks about, rather than the one its ATS Enable bit implies.\n+ *\n+ * Call it once pcim_p2pdma_init() has succeeded. Without P2PDMA state the\n+ * declaration is dropped and the ATS Enable bit keeps deciding.\n+ */\n+void pcim_p2pdma_set_ats_per_mapping(struct pci_dev *pdev)\n+{\n+\tstruct pci_p2pdma *p2p;\n+\n+\tp2p = rcu_dereference_protected(pdev-\u003ep2pdma, 1);\n+\tif (!p2p)\n+\t\t/*\n+\t\t * ats_per_mapping is a performance optimization,\n+\t\t * if pcim_p2pdma_init() didn't set pdev-\u003ep2pdma pointer\n+\t\t * for some reason, let's simply use ATS global settings.\n+\t\t */\n+\t\treturn;\n+\n+\tp2p-\u003eats_per_mapping = true;\n+}\n+EXPORT_SYMBOL_GPL(pcim_p2pdma_set_ats_per_mapping);\n+\n+/**\n+ * pci_p2pdma_map_type_tlp - Determine the mapping type for P2PDMA transfers\n  * @provider: P2PDMA provider structure\n- * @dev: Target device for the transfer\n+ * @dev: Client device that initiates the transfer\n+ * @tlp_flags: \u0026enum pci_p2pdma_tlp_flags describing the TLPs @dev will issue\n  *\n  * Determines how peer-to-peer DMA transfers should be mapped between\n- * the provider and the target device. The mapping type indicates whether\n+ * the provider and the client device. The mapping type indicates whether\n  * the transfer can be done directly through PCI switches or must go\n  * through the host bridge.\n+ *\n+ * ACS routes a peer-to-peer transaction by the attributes its TLPs carry, so\n+ * the answer depends on @tlp_flags. A caller that passes flags its traffic\n+ * does not match gets a mapping the fabric will not deliver.\n+ *\n+ * Only a client whose driver called pcim_p2pdma_set_ats_per_mapping() takes\n+ * the Address Type from @tlp_flags. For any other client its ATS Enable bit\n+ * decides, and a client that translates every address it is handed never gets\n+ * %PCI_P2PDMA_MAP_BUS_ADDR.\n  */\n-enum pci_p2pdma_map_type pci_p2pdma_map_type(struct p2pdma_provider *provider,\n-\t\t\t\t\t     struct device *dev)\n+static enum pci_p2pdma_map_type\n+pci_p2pdma_map_type_tlp(struct p2pdma_provider *provider, struct device *dev,\n+\t\t\tunsigned int tlp_flags)\n {\n-\tenum pci_p2pdma_map_type type = PCI_P2PDMA_MAP_NOT_SUPPORTED;\n \tstruct pci_dev *pdev = to_pci_dev(provider-\u003eowner);\n-\tstruct pci_dev *client;\n+\tunsigned long cache_index, cached = 0;\n+\tenum pci_p2pdma_map_type type;\n \tstruct pci_p2pdma *p2pdma;\n+\tstruct pci_dev *client;\n+\tbool provider_state;\n+\tbool per_mapping;\n \tint dist;\n \n-\tif (!pdev-\u003ep2pdma)\n+\tif (!pdev-\u003ep2pdma) {\n+\t\tpci_dbg(pdev,\n+\t\t\t\"P2PDMA ACS: map lookup rejected; provider state is absent\\n\");\n \t\treturn PCI_P2PDMA_MAP_NOT_SUPPORTED;\n+\t}\n \n-\tif (!dev_is_pci(dev))\n+\tif (!dev_is_pci(dev)) {\n+\t\tdev_dbg(dev,\n+\t\t\t\"P2PDMA ACS: provider=%s map lookup rejected; client is not PCI\\n\",\n+\t\t\t pci_name(pdev));\n \t\treturn PCI_P2PDMA_MAP_NOT_SUPPORTED;\n+\t}\n \n \tclient = to_pci_dev(dev);\n+\tcache_index = map_types_idx(client);\n+\tper_mapping = pci_p2pdma_client_per_mapping(client);\n+\tif (!per_mapping)\n+\t\ttlp_flags = pci_p2pdma_client_tlp_flags(client, tlp_flags);\n \n \trcu_read_lock();\n \tp2pdma = rcu_dereference(pdev-\u003ep2pdma);\n \n \tif (p2pdma)\n-\t\ttype = xa_to_value(xa_load(\u0026p2pdma-\u003emap_types,\n-\t\t\t\t\t   map_types_idx(client)));\n+\t\tcached = xa_to_value(xa_load(\u0026p2pdma-\u003emap_types,\n+\t\t\t\t\t     cache_index));\n+\tprovider_state = !!p2pdma;\n \trcu_read_unlock();\n+\ttype = pci_p2pdma_map_types_unpack(cached, tlp_flags);\n+\tpci_dbg(client,\n+\t\t \"P2PDMA ACS: map lookup provider=%s index=%#lx tlp-flags=%#x cached=%s(%d) provider-state=%u\\n\",\n+\t\t pci_name(pdev), cache_index, tlp_flags,\n+\t\t pci_p2pdma_map_type_name(type), type, provider_state);\n \n \tif (type == PCI_P2PDMA_MAP_UNKNOWN)\n-\t\treturn calc_map_type_and_dist(pdev, client, \u0026dist, true);\n+\t\ttype = calc_map_type_and_dist(pdev, client, \u0026dist, tlp_flags,\n+\t\t\t\t\t      true);\n+\n+\treturn pci_p2pdma_client_map_type(pdev, client, per_mapping, tlp_flags,\n+\t\t\t\t\t  type);\n+}\n \n-\treturn type;\n+/**\n+ * pci_p2pdma_map_type - Determine the mapping type for P2PDMA transfers\n+ * @provider: P2PDMA provider structure\n+ * @dev: Client device that initiates the transfer\n+ *\n+ * Same as pci_p2pdma_map_type_tlp() for a client issuing strictly ordered\n+ * Requests. Their Address Type is Untranslated unless the client enables ATS\n+ * for the whole device.\n+ */\n+enum pci_p2pdma_map_type pci_p2pdma_map_type(struct p2pdma_provider *provider,\n+\t\t\t\t\t     struct device *dev)\n+{\n+\treturn pci_p2pdma_map_type_tlp(provider, dev, 0);\n }\n \n void __pci_p2pdma_update_state(struct pci_p2pdma_map_state *state,\ndiff --git a/drivers/pci/pci.c b/drivers/pci/pci.c\nindex 7c6f2aba81443d..930c35fcca695b 100644\n--- a/drivers/pci/pci.c\n+++ b/drivers/pci/pci.c\n@@ -3611,7 +3611,8 @@ void pci_configure_ari(struct pci_dev *dev)\n \t}\n }\n \n-static bool pci_acs_flags_enabled(struct pci_dev *pdev, u16 acs_flags)\n+VISIBLE_IF_KUNIT\n+bool pci_acs_flags_enabled(struct pci_dev *pdev, u16 acs_flags)\n {\n \tint pos;\n \tu16 ctrl;\n@@ -3627,9 +3628,12 @@ static bool pci_acs_flags_enabled(struct pci_dev *pdev, u16 acs_flags)\n \t */\n \tacs_flags \u0026= (pdev-\u003eacs_capabilities | PCI_ACS_EC);\n \n-\tpci_read_config_word(pdev, pos + PCI_ACS_CTRL, \u0026ctrl);\n+\tif (pci_read_config_word(pdev, pos + PCI_ACS_CTRL, \u0026ctrl) ||\n+\t    PCI_POSSIBLE_ERROR(ctrl))\n+\t\treturn false;\n \treturn (ctrl \u0026 acs_flags) == acs_flags;\n }\n+EXPORT_SYMBOL_IF_KUNIT(pci_acs_flags_enabled);\n \n /**\n  * pci_acs_enabled - test ACS against required flags for a given device\ndiff --git a/drivers/pci/pci.h b/drivers/pci/pci.h\nindex 77efa4c5c960e7..70fc29c42c274e 100644\n--- a/drivers/pci/pci.h\n+++ b/drivers/pci/pci.h\n@@ -2,10 +2,12 @@\n #ifndef DRIVERS_PCI_H\n #define DRIVERS_PCI_H\n \n+#include \u003ckunit/visibility.h\u003e\n #include \u003clinux/bug.h\u003e\n #include \u003clinux/align.h\u003e\n #include \u003clinux/bitfield.h\u003e\n #include \u003clinux/pci.h\u003e\n+#include \u003clinux/pci-p2pdma.h\u003e\n #include \u003ctrace/events/pci.h\u003e\n \n struct pcie_tlp_log;\n@@ -1099,13 +1101,74 @@ resource_size_t pci_min_window_alignment(struct pci_bus *bus,\n \n void pci_acs_init(struct pci_dev *dev);\n void pci_enable_acs(struct pci_dev *dev);\n+\n+/**\n+ * enum pci_p2pdma_tlp_flags - Properties of the TLPs a client will issue\n+ *\n+ * These describe the traffic rather than the topology, and select which ACS\n+ * controls apply along the peer-to-peer path. A value of 0 means strictly\n+ * ordered Requests carrying an Untranslated address.\n+ *\n+ * @PCI_P2PDMA_TLP_TRANSLATED: Requests carry an ATS Translated address. PCIe\n+ *\tr7.0 sec 6.12.3 routes those to the peer regardless of ACS P2P Request\n+ *\tRedirect and ACS P2P Egress Control wherever ACS Direct Translated P2P\n+ *\tis enabled.\n+ * @PCI_P2PDMA_TLP_RELAXED_CPL: Non-Posted Requests carry the Relaxed\n+ *\tOrdering attribute, and PCIe r7.0 sec 2.2.9.1 requires the Completer to\n+ *\treturn it in their Completions. Sec 6.12.1.1 never redirects those, so\n+ *\tACS P2P Completion Redirect does not gate the path.\n+ */\n+enum pci_p2pdma_tlp_flags {\n+\tPCI_P2PDMA_TLP_TRANSLATED\t= 1 \u003c\u003c 0,\n+\tPCI_P2PDMA_TLP_RELAXED_CPL\t= 1 \u003c\u003c 1,\n+};\n+\n+/* Every combination of the flags above selects one routing class. */\n+#define PCI_P2PDMA_TLP_CLASSES \\\n+\t((PCI_P2PDMA_TLP_TRANSLATED | PCI_P2PDMA_TLP_RELAXED_CPL) + 1)\n+\n+enum pci_acs_p2pdma_state {\n+\tPCI_ACS_P2PDMA_NOT_SUPPORTED,\n+\tPCI_ACS_P2PDMA_DIRECT,\n+\tPCI_ACS_P2PDMA_REDIRECT,\n+\tPCI_ACS_P2PDMA_BLOCKED,\n+};\n+\n+#if IS_ENABLED(CONFIG_KUNIT)\n+bool pci_acs_flags_enabled(struct pci_dev *pdev, u16 acs_flags);\n+enum pci_acs_p2pdma_state pci_acs_p2pdma_request(u16 ctrl,\n+\t\t\t\t\t\tunsigned int tlp_flags);\n+enum pci_acs_p2pdma_state pci_acs_p2pdma_completion(u16 ctrl,\n+\t\t\t\t\t\t    unsigned int tlp_flags);\n+unsigned long pci_p2pdma_map_types_pack(const enum pci_p2pdma_map_type *type);\n+enum pci_p2pdma_map_type pci_p2pdma_map_types_unpack(unsigned long val,\n+\t\t\t\t\t\t     unsigned int tlp_flags);\n+enum pci_p2pdma_map_type calc_map_type_and_dist(struct pci_dev *provider,\n+\t\t\t\t\t\tstruct pci_dev *client,\n+\t\t\t\t\t\tint *dist,\n+\t\t\t\t\t\tunsigned int tlp_flags,\n+\t\t\t\t\t\tbool verbose);\n+unsigned int pci_p2pdma_client_tlp_flags(struct pci_dev *client,\n+\t\t\t\t\t unsigned int tlp_flags);\n+enum pci_p2pdma_map_type\n+pci_p2pdma_client_map_type(struct pci_dev *provider, struct pci_dev *client,\n+\t\t\t   bool per_mapping, unsigned int tlp_flags,\n+\t\t\t   enum pci_p2pdma_map_type type);\n+#endif\n+\n #ifdef CONFIG_PCI_QUIRKS\n+int pci_dev_specific_read_acs_ctrl(struct pci_dev *dev, u16 *ctrl);\n int pci_dev_specific_acs_enabled(struct pci_dev *dev, u16 acs_flags);\n int pci_dev_specific_enable_acs(struct pci_dev *dev);\n int pci_dev_specific_disable_acs_redir(struct pci_dev *dev);\n void pci_disable_broken_acs_cap(struct pci_dev *pdev);\n int pcie_failed_link_retrain(struct pci_dev *dev);\n #else\n+static inline int pci_dev_specific_read_acs_ctrl(struct pci_dev *dev, u16 *ctrl)\n+{\n+\treturn -ENOTTY;\n+}\n+\n static inline int pci_dev_specific_acs_enabled(struct pci_dev *dev,\n \t\t\t\t\t       u16 acs_flags)\n {\ndiff --git a/drivers/pci/pci_acs_test.c b/drivers/pci/pci_acs_test.c\nnew file mode 100644\nindex 00000000000000..b0e5e2eac97ccd\n--- /dev/null\n+++ b/drivers/pci/pci_acs_test.c\n@@ -0,0 +1,1409 @@\n+// SPDX-License-Identifier: GPL-2.0\n+/*\n+ * KUnit tests for PCI ACS peer-to-peer routing decisions.\n+ *\n+ * These exercise Request and Completion routing independently of the ACS\n+ * settings exposed by available PCIe hardware.\n+ */\n+#include \u003ckunit/test.h\u003e\n+\n+#include \u003clinux/pci.h\u003e\n+#include \u003clinux/pci-p2pdma.h\u003e\n+#include \u003clinux/pci_regs.h\u003e\n+\n+#include \"pci.h\"\n+\n+struct acs_decision_case {\n+\tconst char *desc;\n+\tu16 ctrl;\n+\tunsigned int tlp_flags;\n+\tenum pci_acs_p2pdma_state expect;\n+};\n+\n+/* Shorthands to keep the tables below readable. */\n+#define ACS_DIRECT\tPCI_ACS_P2PDMA_DIRECT\n+#define ACS_REDIR\tPCI_ACS_P2PDMA_REDIRECT\n+#define ACS_RO\t\tPCI_P2PDMA_TLP_RELAXED_CPL\n+#define ACS_AT\t\tPCI_P2PDMA_TLP_TRANSLATED\n+#define ACS_BLOCK\tPCI_ACS_P2PDMA_BLOCKED\n+\n+/* Request routing ignores Completion Redirect. */\n+static const struct acs_decision_case acs_request_cases[] = {\n+\t{ \"req/none\", 0, 0, ACS_DIRECT },\n+\t{ \"req/rr\", PCI_ACS_RR, 0, ACS_REDIR },\n+\t{ \"req/cr\", PCI_ACS_CR, 0, ACS_DIRECT },\n+\t{ \"req/rr_cr\", PCI_ACS_RR | PCI_ACS_CR, 0, ACS_REDIR },\n+\t{ \"req/ec\", PCI_ACS_EC, 0, ACS_REDIR },\n+\t{ \"req/ec_cr\", PCI_ACS_EC | PCI_ACS_CR, 0, ACS_REDIR },\n+\n+\t/*\n+\t * Direct Translated P2P overrides the redirect controls, but only for\n+\t * a Request that actually carries a Translated address.\n+\t */\n+\t{ \"req/dt\", PCI_ACS_DT, 0, ACS_DIRECT },\n+\t{ \"req/dt_rr\", PCI_ACS_DT | PCI_ACS_RR, 0, ACS_REDIR },\n+\t{ \"req/at\", 0, ACS_AT, ACS_DIRECT },\n+\t{ \"req/at_rr\", PCI_ACS_RR, ACS_AT, ACS_REDIR },\n+\t{ \"req/at_dt\", PCI_ACS_DT, ACS_AT, ACS_DIRECT },\n+\t{ \"req/at_dt_rr\", PCI_ACS_DT | PCI_ACS_RR, ACS_AT, ACS_DIRECT },\n+\t{ \"req/at_dt_ec\", PCI_ACS_DT | PCI_ACS_EC, ACS_AT, ACS_DIRECT },\n+\n+\t/*\n+\t * Translation Blocking rejects a Translated address outright, and\n+\t * makes the port ignore Direct Translated P2P.\n+\t */\n+\t{ \"req/tb\", PCI_ACS_TB, 0, ACS_DIRECT },\n+\t{ \"req/tb_rr\", PCI_ACS_TB | PCI_ACS_RR, 0, ACS_REDIR },\n+\t{ \"req/at_tb\", PCI_ACS_TB, ACS_AT, ACS_BLOCK },\n+\t{ \"req/at_tb_dt\", PCI_ACS_TB | PCI_ACS_DT, ACS_AT, ACS_BLOCK },\n+};\n+\n+/* Completion routing depends only on Completion Redirect. */\n+static const struct acs_decision_case acs_completion_cases[] = {\n+\t{ \"cpl/none\", 0, 0, ACS_DIRECT },\n+\t{ \"cpl/rr\", PCI_ACS_RR, 0, ACS_DIRECT },\n+\t{ \"cpl/cr\", PCI_ACS_CR, 0, ACS_REDIR },\n+\t{ \"cpl/rr_cr\", PCI_ACS_RR | PCI_ACS_CR, 0, ACS_REDIR },\n+\t{ \"cpl/ec\", PCI_ACS_EC, 0, ACS_DIRECT },\n+\t{ \"cpl/ec_cr\", PCI_ACS_EC | PCI_ACS_CR, 0, ACS_REDIR },\n+\n+\t/* Relaxed Ordering Completions are never redirected. */\n+\t{ \"cpl/ro\", 0, ACS_RO, ACS_DIRECT },\n+\t{ \"cpl/ro_cr\", PCI_ACS_CR, ACS_RO, ACS_DIRECT },\n+\t{ \"cpl/ro_rr_cr\", PCI_ACS_RR | PCI_ACS_CR, ACS_RO, ACS_DIRECT },\n+};\n+\n+#undef ACS_DIRECT\n+#undef ACS_REDIR\n+#undef ACS_RO\n+#undef ACS_AT\n+#undef ACS_BLOCK\n+\n+static void acs_decision_desc(const struct acs_decision_case *c, char *desc)\n+{\n+\tstrscpy(desc, c-\u003edesc, KUNIT_PARAM_DESC_SIZE);\n+}\n+\n+KUNIT_ARRAY_PARAM(acs_request, acs_request_cases, acs_decision_desc);\n+KUNIT_ARRAY_PARAM(acs_completion, acs_completion_cases, acs_decision_desc);\n+\n+static void pci_acs_p2pdma_request_test(struct kunit *test)\n+{\n+\tconst struct acs_decision_case *c = test-\u003eparam_value;\n+\n+\tKUNIT_EXPECT_EQ(test, pci_acs_p2pdma_request(c-\u003ectrl, c-\u003etlp_flags),\n+\t\t\tc-\u003eexpect);\n+}\n+\n+static void pci_acs_p2pdma_completion_test(struct kunit *test)\n+{\n+\tconst struct acs_decision_case *c = test-\u003eparam_value;\n+\n+\tKUNIT_EXPECT_EQ(test, pci_acs_p2pdma_completion(c-\u003ectrl, c-\u003etlp_flags),\n+\t\t\tc-\u003eexpect);\n+}\n+\n+/* Flags an IOMMU asks for; see REQ_ACS_FLAGS in drivers/iommu/iommu.c. */\n+#define ACS_REQ_FLAGS\t(PCI_ACS_SV | PCI_ACS_RR | PCI_ACS_CR | PCI_ACS_UF)\n+#define ACS_ALL_CAPS\t(PCI_ACS_SV | PCI_ACS_TB | PCI_ACS_RR | PCI_ACS_CR | \\\n+\t\t\t PCI_ACS_UF | PCI_ACS_DT)\n+#define ACS_TEST_CAP\t0x100\n+\n+struct acs_ctrl_cfg {\n+\tunsigned int devfn;\n+\tu16 cap;\t/* Offset where the ACS capability responds */\n+\tu16 ctrl;\n+\tbool fail_read;\n+};\n+\n+static int acs_ctrl_read(struct pci_bus *bus, unsigned int devfn,\n+\t\t\t int where, int size, u32 *val)\n+{\n+\tstruct acs_ctrl_cfg *cfg = bus-\u003esysdata;\n+\n+\t*val = 0;\n+\tif (cfg-\u003efail_read)\n+\t\treturn PCIBIOS_DEVICE_NOT_FOUND;\n+\n+\tif (devfn == cfg-\u003edevfn \u0026\u0026 size == 2 \u0026\u0026\n+\t    where == cfg-\u003ecap + PCI_ACS_CTRL)\n+\t\t*val = cfg-\u003ectrl;\n+\treturn PCIBIOS_SUCCESSFUL;\n+}\n+\n+static int acs_ctrl_write(struct pci_bus *bus, unsigned int devfn,\n+\t\t\t  int where, int size, u32 val)\n+{\n+\treturn PCIBIOS_SUCCESSFUL;\n+}\n+\n+static struct pci_ops acs_ctrl_ops = {\n+\t.read\t= acs_ctrl_read,\n+\t.write\t= acs_ctrl_write,\n+};\n+\n+struct acs_isolation_case {\n+\tconst char *desc;\n+\tu16 ctrl;\n+\tu16 req;\n+\tbool expect;\n+};\n+\n+static const struct acs_isolation_case acs_isolation_cases[] = {\n+\t{ \"all_enabled\", ACS_REQ_FLAGS, ACS_REQ_FLAGS, true },\n+\t/* Translated Requests remain isolated by their IOMMU translation. */\n+\t{ \"dt\", ACS_REQ_FLAGS | PCI_ACS_DT, ACS_REQ_FLAGS, true },\n+\t{ \"rr_not_enabled\", PCI_ACS_SV | PCI_ACS_CR | PCI_ACS_UF,\n+\t  ACS_REQ_FLAGS, false },\n+\t{ \"rr_not_required\", PCI_ACS_SV | PCI_ACS_CR | PCI_ACS_UF,\n+\t  PCI_ACS_SV | PCI_ACS_CR | PCI_ACS_UF, true },\n+};\n+\n+static void acs_isolation_desc(const struct acs_isolation_case *c, char *desc)\n+{\n+\tstrscpy(desc, c-\u003edesc, KUNIT_PARAM_DESC_SIZE);\n+}\n+\n+KUNIT_ARRAY_PARAM(acs_isolation, acs_isolation_cases, acs_isolation_desc);\n+\n+static bool acs_isolated(struct kunit *test, struct acs_ctrl_cfg *cfg,\n+\t\t\t u16 acs_flags)\n+{\n+\tstruct pci_bus *bus = kunit_kzalloc(test, sizeof(*bus), GFP_KERNEL);\n+\tstruct pci_dev *pdev = kunit_kzalloc(test, sizeof(*pdev), GFP_KERNEL);\n+\n+\tKUNIT_ASSERT_NOT_NULL(test, bus);\n+\tKUNIT_ASSERT_NOT_NULL(test, pdev);\n+\n+\tbus-\u003eops = \u0026acs_ctrl_ops;\n+\tbus-\u003esysdata = cfg;\n+\n+\tpdev-\u003ebus = bus;\n+\tpdev-\u003edevfn = cfg-\u003edevfn;\n+\tpdev-\u003eacs_cap = cfg-\u003ecap;\n+\tpdev-\u003eacs_capabilities = ACS_ALL_CAPS;\n+\n+\treturn pci_acs_flags_enabled(pdev, acs_flags);\n+}\n+\n+static void pci_acs_flags_enabled_test(struct kunit *test)\n+{\n+\tconst struct acs_isolation_case *c = test-\u003eparam_value;\n+\tstruct acs_ctrl_cfg cfg = {\n+\t\t.devfn = PCI_DEVFN(0, 0),\n+\t\t.cap = ACS_TEST_CAP,\n+\t\t.ctrl = c-\u003ectrl,\n+\t};\n+\n+\tKUNIT_EXPECT_EQ(test, acs_isolated(test, \u0026cfg, c-\u003ereq), c-\u003eexpect);\n+}\n+\n+static void pci_acs_flags_no_cap_test(struct kunit *test)\n+{\n+\tstruct acs_ctrl_cfg cfg = {\n+\t\t.devfn = PCI_DEVFN(0, 0),\n+\t\t.cap = 0,\n+\t\t.ctrl = ACS_REQ_FLAGS,\n+\t};\n+\n+\tKUNIT_EXPECT_FALSE(test, acs_isolated(test, \u0026cfg, ACS_REQ_FLAGS));\n+}\n+\n+static void pci_acs_flags_read_fails_test(struct kunit *test)\n+{\n+\tu16 no_rr = ACS_REQ_FLAGS \u0026 ~PCI_ACS_RR;\n+\tstruct acs_ctrl_cfg cfg = {\n+\t\t.devfn = PCI_DEVFN(0, 0),\n+\t\t.cap = ACS_TEST_CAP,\n+\t\t.ctrl = ACS_REQ_FLAGS,\n+\t};\n+\n+\tKUNIT_EXPECT_TRUE(test, acs_isolated(test, \u0026cfg, no_rr));\n+\n+\tcfg.fail_read = true;\n+\tKUNIT_EXPECT_FALSE(test, acs_isolated(test, \u0026cfg, no_rr));\n+\n+\t/* A device that does not answer reads as all ones, without an error */\n+\tcfg.fail_read = false;\n+\tcfg.ctrl = 0xffff;\n+\tKUNIT_EXPECT_FALSE(test, acs_isolated(test, \u0026cfg, no_rr));\n+}\n+\n+/*\n+ * Drive calc_map_type_and_dist() over a fabricated PCIe fabric matching the\n+ * canonical topology of two devices below one switch:\n+ *\n+ *   host bridge / root bus\n+ *     Root Port\n+ *       Switch Upstream Port\n+ *         Switch Downstream Port 0\n+ *           Nested Switch -- provider\n+ *         Switch Downstream Port 1\n+ *           Nested Switch -- client\n+ *\n+ * Fake config-space operations supply the ACS Control registers. This lets\n+ * the cases vary both divergence ports and controls below the divergence\n+ * without depending on real hardware.\n+ */\n+struct acs_port_cfg {\n+\tu32 ctrl;\n+\tbool fail_read;\n+\tbool dword_acs;\n+};\n+\n+struct acs_fabric {\n+\tstruct pci_dev *rootport;\n+\tstruct pci_dev *provider;\n+\tstruct pci_dev *client;\n+\tstruct pci_dev *dn0;\t/* Downstream Port 0 (provider side) */\n+\tstruct pci_dev *dn1;\t/* Downstream Port 1 (client side) */\n+\tstruct pci_dev *provider_leaf;\n+\tstruct pci_dev *client_leaf;\n+\tstruct acs_port_cfg dn0_cfg;\n+\tstruct acs_port_cfg dn1_cfg;\n+\tstruct acs_port_cfg provider_leaf_cfg;\n+\tstruct acs_port_cfg client_leaf_cfg;\n+\tstruct acs_port_cfg rootport_cfg;\n+\tstruct acs_port_cfg provider_cfg;\n+\tstruct acs_port_cfg client_cfg;\n+};\n+\n+static int acs_port_read(struct pci_dev *port, struct acs_port_cfg *cfg,\n+\t\t\t int where, int size, u32 *val)\n+{\n+\tint ctrl_offset = cfg-\u003edword_acs ? 8 : PCI_ACS_CTRL;\n+\tint reg_size = cfg-\u003edword_acs ? 4 : 2;\n+\n+\tif (!port-\u003eacs_cap || size != reg_size)\n+\t\treturn PCIBIOS_SUCCESSFUL;\n+\n+\tif (where == port-\u003eacs_cap + PCI_ACS_CAP)\n+\t\t*val = port-\u003eacs_capabilities;\n+\tif (where == port-\u003eacs_cap + ctrl_offset) {\n+\t\tif (cfg-\u003efail_read)\n+\t\t\treturn PCIBIOS_DEVICE_NOT_FOUND;\n+\t\t*val = cfg-\u003ectrl;\n+\t}\n+\n+\treturn PCIBIOS_SUCCESSFUL;\n+}\n+\n+static int acs_fabric_read(struct pci_bus *bus, unsigned int devfn,\n+\t\t\t   int where, int size, u32 *val)\n+{\n+\tstruct acs_fabric *f = bus-\u003esysdata;\n+\n+\t*val = 0;\n+\tif (bus == f-\u003eprovider-\u003ebus \u0026\u0026 devfn == f-\u003eprovider-\u003edevfn)\n+\t\treturn acs_port_read(f-\u003eprovider, \u0026f-\u003eprovider_cfg,\n+\t\t\t\t     where, size, val);\n+\tif (bus == f-\u003eclient-\u003ebus \u0026\u0026 devfn == f-\u003eclient-\u003edevfn)\n+\t\treturn acs_port_read(f-\u003eclient, \u0026f-\u003eclient_cfg,\n+\t\t\t\t     where, size, val);\n+\tif (bus == f-\u003erootport-\u003ebus \u0026\u0026 devfn == f-\u003erootport-\u003edevfn)\n+\t\treturn acs_port_read(f-\u003erootport, \u0026f-\u003erootport_cfg,\n+\t\t\t\t     where, size, val);\n+\tif (bus == f-\u003edn0-\u003ebus \u0026\u0026 devfn == f-\u003edn0-\u003edevfn)\n+\t\treturn acs_port_read(f-\u003edn0, \u0026f-\u003edn0_cfg, where, size, val);\n+\tif (bus == f-\u003edn1-\u003ebus \u0026\u0026 devfn == f-\u003edn1-\u003edevfn)\n+\t\treturn acs_port_read(f-\u003edn1, \u0026f-\u003edn1_cfg, where, size, val);\n+\tif (bus == f-\u003eprovider_leaf-\u003ebus \u0026\u0026\n+\t    devfn == f-\u003eprovider_leaf-\u003edevfn)\n+\t\treturn acs_port_read(f-\u003eprovider_leaf, \u0026f-\u003eprovider_leaf_cfg,\n+\t\t\t\t     where, size, val);\n+\tif (bus == f-\u003eclient_leaf-\u003ebus \u0026\u0026 devfn == f-\u003eclient_leaf-\u003edevfn)\n+\t\treturn acs_port_read(f-\u003eclient_leaf, \u0026f-\u003eclient_leaf_cfg,\n+\t\t\t\t     where, size, val);\n+\n+\treturn PCIBIOS_SUCCESSFUL;\n+}\n+\n+static int acs_fabric_write(struct pci_bus *bus, unsigned int devfn,\n+\t\t\t    int where, int size, u32 val)\n+{\n+\treturn PCIBIOS_SUCCESSFUL;\n+}\n+\n+static struct pci_ops acs_fabric_ops = {\n+\t.read\t= acs_fabric_read,\n+\t.write\t= acs_fabric_write,\n+};\n+\n+static struct pci_bus *acs_add_bus(struct kunit *test, struct pci_bus *parent,\n+\t\t\t\t   struct pci_dev *self, u8 nr, void *sysdata)\n+{\n+\tstruct pci_bus *bus = kunit_kzalloc(test, sizeof(*bus), GFP_KERNEL);\n+\n+\tKUNIT_ASSERT_NOT_NULL(test, bus);\n+\tbus-\u003eparent = parent;\n+\tbus-\u003eself = self;\n+\tbus-\u003enumber = nr;\n+\tbus-\u003eops = \u0026acs_fabric_ops;\n+\tbus-\u003esysdata = sysdata;\n+\tINIT_LIST_HEAD(\u0026bus-\u003edevices);\n+\treturn bus;\n+}\n+\n+static struct pci_dev *acs_add_dev(struct kunit *test, struct pci_bus *bus,\n+\t\t\t\t   unsigned int devfn, int pcie_type)\n+{\n+\tstruct pci_dev *dev = kunit_kzalloc(test, sizeof(*dev), GFP_KERNEL);\n+\n+\tKUNIT_ASSERT_NOT_NULL(test, dev);\n+\tdev-\u003ebus = bus;\n+\tdev-\u003edevfn = devfn;\n+\tdev-\u003epcie_cap = 0x40;\n+\tdev-\u003epcie_flags_reg = (pcie_type \u003c\u003c 4) | 0x2;\n+\tif (pcie_type != PCI_EXP_TYPE_ENDPOINT)\n+\t\tdev-\u003ehdr_type = PCI_HEADER_TYPE_BRIDGE;\n+\tlist_add_tail(\u0026dev-\u003ebus_list, \u0026bus-\u003edevices);\n+\treturn dev;\n+}\n+\n+static void acs_build_fabric(struct kunit *test, struct acs_fabric *f)\n+{\n+\tstruct pci_bus *bus0, *bus1, *bus2, *bus3, *bus4, *bus5, *bus6;\n+\tstruct pci_bus *bus7, *bus8;\n+\tstruct pci_dev *swup, *provider_swup, *client_swup;\n+\tstruct pci_dev *rootport;\n+\tstruct pci_host_bridge *host;\n+\n+\thost = kunit_kzalloc(test, sizeof(*host), GFP_KERNEL);\n+\tKUNIT_ASSERT_NOT_NULL(test, host);\n+\n+\tbus0 = acs_add_bus(test, NULL, NULL, 0, f);\n+\t/* The Root Port doubles as the whitelisted host-bridge device. */\n+\trootport = acs_add_dev(test, bus0, PCI_DEVFN(0, 0),\n+\t\t\t       PCI_EXP_TYPE_ROOT_PORT);\n+\tf-\u003erootport = rootport;\n+\trootport-\u003evendor = PCI_VENDOR_ID_GOOGLE;\n+\trootport-\u003edevice = 0x1234;\n+\trootport-\u003eacs_cap = ACS_TEST_CAP;\n+\trootport-\u003eacs_capabilities = PCI_ACS_UF;\n+\tf-\u003erootport_cfg.ctrl = PCI_ACS_UF;\n+\thost-\u003ebus = bus0;\n+\tbus0-\u003ebridge = \u0026host-\u003edev;\n+\n+\tbus1 = acs_add_bus(test, bus0, rootport, 1, f);\n+\tswup = acs_add_dev(test, bus1, PCI_DEVFN(0, 0),\n+\t\t\t   PCI_EXP_TYPE_UPSTREAM);\n+\n+\tbus2 = acs_add_bus(test, bus1, swup, 2, f);\n+\tf-\u003edn0 = acs_add_dev(test, bus2, PCI_DEVFN(0, 0),\n+\t\t\t     PCI_EXP_TYPE_DOWNSTREAM);\n+\tf-\u003edn1 = acs_add_dev(test, bus2, PCI_DEVFN(1, 0),\n+\t\t\t     PCI_EXP_TYPE_DOWNSTREAM);\n+\n+\tbus3 = acs_add_bus(test, bus2, f-\u003edn0, 3, f);\n+\tprovider_swup = acs_add_dev(test, bus3, PCI_DEVFN(0, 0),\n+\t\t\t\t    PCI_EXP_TYPE_UPSTREAM);\n+\tbus5 = acs_add_bus(test, bus3, provider_swup, 5, f);\n+\tf-\u003eprovider_leaf = acs_add_dev(test, bus5, PCI_DEVFN(0, 0),\n+\t\t\t\t       PCI_EXP_TYPE_DOWNSTREAM);\n+\tbus7 = acs_add_bus(test, bus5, f-\u003eprovider_leaf, 7, f);\n+\tf-\u003eprovider = acs_add_dev(test, bus7, PCI_DEVFN(0, 0),\n+\t\t\t\t  PCI_EXP_TYPE_ENDPOINT);\n+\n+\tbus4 = acs_add_bus(test, bus2, f-\u003edn1, 4, f);\n+\tclient_swup = acs_add_dev(test, bus4, PCI_DEVFN(0, 0),\n+\t\t\t\t  PCI_EXP_TYPE_UPSTREAM);\n+\tbus6 = acs_add_bus(test, bus4, client_swup, 6, f);\n+\tf-\u003eclient_leaf = acs_add_dev(test, bus6, PCI_DEVFN(0, 0),\n+\t\t\t\t     PCI_EXP_TYPE_DOWNSTREAM);\n+\tbus8 = acs_add_bus(test, bus6, f-\u003eclient_leaf, 8, f);\n+\tf-\u003eclient = acs_add_dev(test, bus8, PCI_DEVFN(0, 0),\n+\t\t\t\tPCI_EXP_TYPE_ENDPOINT);\n+}\n+\n+static enum pci_p2pdma_map_type acs_walk_map(struct acs_fabric *f,\n+\t\t\t\t\t     unsigned int tlp_flags)\n+{\n+\tint dist;\n+\n+\treturn calc_map_type_and_dist(f-\u003eprovider, f-\u003eclient, \u0026dist, tlp_flags,\n+\t\t\t\t      false);\n+}\n+\n+static void acs_walk_bus_addr_test(struct kunit *test)\n+{\n+\tstruct acs_fabric f = {};\n+\n+\tacs_build_fabric(test, \u0026f);\n+\tKUNIT_EXPECT_EQ(test, acs_walk_map(\u0026f, 0), PCI_P2PDMA_MAP_BUS_ADDR);\n+}\n+\n+static void acs_walk_request_redirect_test(struct kunit *test)\n+{\n+\tstruct acs_fabric f = {};\n+\n+\tacs_build_fabric(test, \u0026f);\n+\tf.dn1-\u003eacs_cap = 0x100;\n+\tf.dn1-\u003eacs_capabilities = PCI_ACS_RR;\n+\tf.dn1_cfg.ctrl = PCI_ACS_RR;\n+\n+\tKUNIT_EXPECT_EQ(test, acs_walk_map(\u0026f, 0),\n+\t\t\tPCI_P2PDMA_MAP_THRU_HOST_BRIDGE);\n+}\n+\n+static void acs_walk_completion_redirect_test(struct kunit *test)\n+{\n+\tstruct acs_fabric f = {};\n+\n+\tacs_build_fabric(test, \u0026f);\n+\tf.dn0-\u003eacs_cap = 0x100;\n+\tf.dn0-\u003eacs_capabilities = PCI_ACS_CR;\n+\tf.dn0_cfg.ctrl = PCI_ACS_CR;\n+\n+\tKUNIT_EXPECT_EQ(test, acs_walk_map(\u0026f, 0),\n+\t\t\tPCI_P2PDMA_MAP_THRU_HOST_BRIDGE);\n+}\n+\n+static void acs_walk_egress_control_test(struct kunit *test)\n+{\n+\tstruct acs_fabric f = {};\n+\n+\tacs_build_fabric(test, \u0026f);\n+\tf.dn1-\u003eacs_cap = 0x100;\n+\tf.dn1-\u003eacs_capabilities = PCI_ACS_EC;\n+\tf.dn1_cfg.ctrl = PCI_ACS_EC;\n+\n+\tKUNIT_EXPECT_EQ(test, acs_walk_map(\u0026f, 0),\n+\t\t\tPCI_P2PDMA_MAP_THRU_HOST_BRIDGE);\n+}\n+\n+/*\n+ * Zhaoxin Downstream Ports that lack an ACS capability redirect through a\n+ * quirk, which covers every class, Relaxed Ordering Completions included.\n+ * A Zhaoxin port the quirk does not know keeps its own ACS controls.\n+ */\n+static void acs_walk_quirk_redirect_test(struct kunit *test)\n+{\n+\tstruct acs_fabric f = {};\n+\n+\tif (!IS_ENABLED(CONFIG_PCI_QUIRKS))\n+\t\tkunit_skip(test, \"needs CONFIG_PCI_QUIRKS\");\n+\n+\tacs_build_fabric(test, \u0026f);\n+\tf.dn0-\u003evendor = PCI_VENDOR_ID_ZHAOXIN;\n+\tf.dn0-\u003edevice = 0x0710;\n+\n+\tKUNIT_EXPECT_EQ(test, acs_walk_map(\u0026f, 0),\n+\t\t\tPCI_P2PDMA_MAP_THRU_HOST_BRIDGE);\n+\tKUNIT_EXPECT_EQ(test, acs_walk_map(\u0026f, PCI_P2PDMA_TLP_RELAXED_CPL),\n+\t\t\tPCI_P2PDMA_MAP_THRU_HOST_BRIDGE);\n+\n+\tf.dn0-\u003edevice = 0x0700;\n+\tf.dn1-\u003evendor = PCI_VENDOR_ID_ZHAOXIN;\n+\tf.dn1-\u003edevice = 0x0700;\n+\tf.dn1-\u003eacs_cap = 0x100;\n+\tf.dn1-\u003eacs_capabilities = PCI_ACS_RR;\n+\tf.dn1_cfg.ctrl = PCI_ACS_RR;\n+\n+\tKUNIT_EXPECT_EQ(test, acs_walk_map(\u0026f, 0),\n+\t\t\tPCI_P2PDMA_MAP_THRU_HOST_BRIDGE);\n+}\n+\n+static void acs_walk_asymmetric_direct_test(struct kunit *test)\n+{\n+\tstruct acs_fabric f = {};\n+\n+\tacs_build_fabric(test, \u0026f);\n+\t/* These controls affect only the reverse transaction directions. */\n+\tf.dn0-\u003eacs_cap = 0x100;\n+\tf.dn0-\u003eacs_capabilities = PCI_ACS_RR | PCI_ACS_EC;\n+\tf.dn0_cfg.ctrl = PCI_ACS_RR | PCI_ACS_EC;\n+\tf.dn1-\u003eacs_cap = 0x100;\n+\tf.dn1-\u003eacs_capabilities = PCI_ACS_CR;\n+\tf.dn1_cfg.ctrl = PCI_ACS_CR;\n+\n+\tKUNIT_EXPECT_EQ(test, acs_walk_map(\u0026f, 0), PCI_P2PDMA_MAP_BUS_ADDR);\n+}\n+\n+static void acs_walk_nested_completion_redirect_test(struct kunit *test)\n+{\n+\tstruct acs_fabric f = {};\n+\n+\tacs_build_fabric(test, \u0026f);\n+\tf.provider_leaf-\u003eacs_cap = 0x100;\n+\tf.provider_leaf-\u003eacs_capabilities = PCI_ACS_CR;\n+\tf.provider_leaf_cfg.ctrl = PCI_ACS_CR;\n+\n+\tKUNIT_EXPECT_EQ(test, acs_walk_map(\u0026f, 0), PCI_P2PDMA_MAP_BUS_ADDR);\n+}\n+\n+static void acs_walk_nested_request_redirect_test(struct kunit *test)\n+{\n+\tstruct acs_fabric f = {};\n+\n+\tacs_build_fabric(test, \u0026f);\n+\tf.client_leaf-\u003eacs_cap = 0x100;\n+\tf.client_leaf-\u003eacs_capabilities = PCI_ACS_RR;\n+\tf.client_leaf_cfg.ctrl = PCI_ACS_RR;\n+\n+\tKUNIT_EXPECT_EQ(test, acs_walk_map(\u0026f, 0), PCI_P2PDMA_MAP_BUS_ADDR);\n+}\n+\n+static void acs_walk_translation_blocking_test(struct kunit *test)\n+{\n+\tstruct acs_fabric f = {};\n+\n+\tacs_build_fabric(test, \u0026f);\n+\tf.client_leaf-\u003eacs_cap = 0x100;\n+\tf.client_leaf-\u003eacs_capabilities = PCI_ACS_TB;\n+\tf.client_leaf_cfg.ctrl = PCI_ACS_TB;\n+\n+\t/* Untranslated Requests are unaffected by Translation Blocking. */\n+\tKUNIT_EXPECT_EQ(test, acs_walk_map(\u0026f, 0), PCI_P2PDMA_MAP_BUS_ADDR);\n+\tKUNIT_EXPECT_EQ(test, acs_walk_map(\u0026f, PCI_P2PDMA_TLP_TRANSLATED),\n+\t\t\tPCI_P2PDMA_MAP_NOT_SUPPORTED);\n+}\n+\n+static void acs_walk_relaxed_completion_test(struct kunit *test)\n+{\n+\tstruct acs_fabric f = {};\n+\n+\tacs_build_fabric(test, \u0026f);\n+\tf.dn0-\u003eacs_cap = 0x100;\n+\tf.dn0-\u003eacs_capabilities = PCI_ACS_CR;\n+\tf.dn0_cfg.ctrl = PCI_ACS_CR;\n+\n+\tKUNIT_EXPECT_EQ(test, acs_walk_map(\u0026f, 0),\n+\t\t\tPCI_P2PDMA_MAP_THRU_HOST_BRIDGE);\n+\tKUNIT_EXPECT_EQ(test, acs_walk_map(\u0026f, PCI_P2PDMA_TLP_RELAXED_CPL),\n+\t\t\tPCI_P2PDMA_MAP_BUS_ADDR);\n+}\n+\n+static void acs_walk_direct_translated_test(struct kunit *test)\n+{\n+\tstruct acs_fabric f = {};\n+\n+\tacs_build_fabric(test, \u0026f);\n+\tf.dn1-\u003eacs_cap = 0x100;\n+\tf.dn1-\u003eacs_capabilities = PCI_ACS_RR | PCI_ACS_DT;\n+\tf.dn1_cfg.ctrl = PCI_ACS_RR | PCI_ACS_DT;\n+\n+\tKUNIT_EXPECT_EQ(test, acs_walk_map(\u0026f, 0),\n+\t\t\tPCI_P2PDMA_MAP_THRU_HOST_BRIDGE);\n+\tKUNIT_EXPECT_EQ(test, acs_walk_map(\u0026f, PCI_P2PDMA_TLP_TRANSLATED),\n+\t\t\tPCI_P2PDMA_MAP_BUS_ADDR);\n+}\n+\n+static void acs_enable_forwarding(struct pci_dev *port,\n+\t\t\t\t  struct acs_port_cfg *cfg)\n+{\n+\tport-\u003eacs_cap = ACS_TEST_CAP;\n+\tport-\u003eacs_capabilities = PCI_ACS_UF;\n+\tcfg-\u003ectrl = PCI_ACS_UF;\n+}\n+\n+/*\n+ * Put both functions on one downstream link. Like the Intel E810, each\n+ * advertises ACS with neither Request nor Completion Redirect support,\n+ * indicating that there is no internal peer path. The shared Downstream\n+ * Port and its ancestors forward traffic upstream towards the host.\n+ */\n+static void acs_build_mf_fabric(struct kunit *test, struct acs_fabric *f)\n+{\n+\tacs_build_fabric(test, f);\n+\tf-\u003eclient-\u003ebus = f-\u003eprovider-\u003ebus;\n+\tf-\u003eclient-\u003edevfn = PCI_DEVFN(0, 1);\n+\tlist_move_tail(\u0026f-\u003eclient-\u003ebus_list, \u0026f-\u003eprovider-\u003ebus-\u003edevices);\n+\tf-\u003eprovider-\u003emultifunction = 1;\n+\tf-\u003eclient-\u003emultifunction = 1;\n+\tf-\u003eprovider-\u003eacs_cap = ACS_TEST_CAP;\n+\tf-\u003eclient-\u003eacs_cap = ACS_TEST_CAP;\n+\tacs_enable_forwarding(f-\u003eprovider_leaf, \u0026f-\u003eprovider_leaf_cfg);\n+\tacs_enable_forwarding(f-\u003edn0, \u0026f-\u003edn0_cfg);\n+\tacs_enable_forwarding(f-\u003erootport, \u0026f-\u003erootport_cfg);\n+}\n+\n+static void acs_expect_classes(struct kunit *test, struct acs_fabric *f,\n+\t\t\t       enum pci_p2pdma_map_type expect)\n+{\n+\tunsigned int flags;\n+\n+\tfor (flags = 0; flags \u003c PCI_P2PDMA_TLP_CLASSES; flags++)\n+\t\tKUNIT_EXPECT_EQ_MSG(test, acs_walk_map(f, flags), expect,\n+\t\t\t\t    \"TLP flags %#x\", flags);\n+}\n+\n+static void acs_walk_mf_isolation_test(struct kunit *test)\n+{\n+\tstruct acs_fabric f = {};\n+\n+\tacs_build_mf_fabric(test, \u0026f);\n+\tacs_expect_classes(test, \u0026f, PCI_P2PDMA_MAP_THRU_HOST_BRIDGE);\n+}\n+\n+static void acs_walk_mf_quirk_test(struct kunit *test)\n+{\n+\tstruct acs_fabric f = {};\n+\n+\tif (!IS_ENABLED(CONFIG_PCI_QUIRKS))\n+\t\tkunit_skip(test, \"needs CONFIG_PCI_QUIRKS\");\n+\n+\tacs_build_mf_fabric(test, \u0026f);\n+\tf.provider-\u003eacs_cap = 0;\n+\tf.client-\u003eacs_cap = 0;\n+\tf.provider-\u003evendor = PCI_VENDOR_ID_WANGXUN;\n+\tf.client-\u003evendor = PCI_VENDOR_ID_WANGXUN;\n+\tf.provider-\u003edevice = 0x0100;\n+\tf.client-\u003edevice = 0x0100;\n+\tacs_expect_classes(test, \u0026f, PCI_P2PDMA_MAP_THRU_HOST_BRIDGE);\n+\n+\t/* A port quirk can also establish hardwired Upstream Forwarding. */\n+\tf.provider_leaf-\u003eacs_cap = 0;\n+\tf.provider_leaf-\u003evendor = PCI_VENDOR_ID_ZHAOXIN;\n+\tf.provider_leaf-\u003edevice = 0x0710;\n+\tacs_expect_classes(test, \u0026f, PCI_P2PDMA_MAP_THRU_HOST_BRIDGE);\n+\n+\t/* An unknown device must keep its own programmable ACS controls. */\n+\tf.provider-\u003edevice = 0xffff;\n+\tf.client-\u003edevice = 0xffff;\n+\tf.provider-\u003eacs_cap = ACS_TEST_CAP;\n+\tf.client-\u003eacs_cap = ACS_TEST_CAP;\n+\tf.provider-\u003eacs_capabilities = ACS_ALL_CAPS;\n+\tf.client-\u003eacs_capabilities = ACS_ALL_CAPS;\n+\tacs_expect_classes(test, \u0026f, PCI_P2PDMA_MAP_BUS_ADDR);\n+}\n+\n+/* DT and Relaxed Ordering cannot create a missing internal peer path. */\n+static void acs_walk_mf_direction_test(struct kunit *test)\n+{\n+\tstruct acs_fabric f = {};\n+\n+\tacs_build_mf_fabric(test, \u0026f);\n+\tf.provider-\u003eacs_capabilities = ACS_ALL_CAPS;\n+\tf.client-\u003eacs_capabilities = ACS_ALL_CAPS \u0026 ~PCI_ACS_RR;\n+\tf.client_cfg.ctrl = PCI_ACS_DT;\n+\tacs_expect_classes(test, \u0026f, PCI_P2PDMA_MAP_THRU_HOST_BRIDGE);\n+\n+\tf.provider-\u003eacs_capabilities = ACS_ALL_CAPS \u0026 ~PCI_ACS_CR;\n+\tf.client-\u003eacs_capabilities = ACS_ALL_CAPS;\n+\tf.client_cfg.ctrl = 0;\n+\tacs_expect_classes(test, \u0026f, PCI_P2PDMA_MAP_THRU_HOST_BRIDGE);\n+}\n+\n+static void acs_walk_mf_programmable_test(struct kunit *test)\n+{\n+\tstruct acs_fabric f = {};\n+\n+\tacs_build_mf_fabric(test, \u0026f);\n+\tf.provider-\u003eacs_capabilities = ACS_ALL_CAPS;\n+\tf.client-\u003eacs_capabilities = ACS_ALL_CAPS;\n+\tacs_expect_classes(test, \u0026f, PCI_P2PDMA_MAP_BUS_ADDR);\n+\n+\tf.provider_cfg.ctrl = PCI_ACS_CR;\n+\tf.client_cfg.ctrl = PCI_ACS_RR | PCI_ACS_DT;\n+\tKUNIT_EXPECT_EQ(test, acs_walk_map(\u0026f, 0),\n+\t\t\tPCI_P2PDMA_MAP_THRU_HOST_BRIDGE);\n+\tKUNIT_EXPECT_EQ(test, acs_walk_map(\u0026f, PCI_P2PDMA_TLP_TRANSLATED),\n+\t\t\tPCI_P2PDMA_MAP_THRU_HOST_BRIDGE);\n+\tKUNIT_EXPECT_EQ(test, acs_walk_map(\u0026f, PCI_P2PDMA_TLP_RELAXED_CPL),\n+\t\t\tPCI_P2PDMA_MAP_THRU_HOST_BRIDGE);\n+\tKUNIT_EXPECT_EQ(test,\n+\t\t\tacs_walk_map(\u0026f, PCI_P2PDMA_TLP_TRANSLATED |\n+\t\t\t\t     PCI_P2PDMA_TLP_RELAXED_CPL),\n+\t\t\tPCI_P2PDMA_MAP_BUS_ADDR);\n+\n+\t/* A route that stays within the device does not need forwarding. */\n+\tf.provider_leaf_cfg.ctrl = 0;\n+\tKUNIT_EXPECT_EQ(test, acs_walk_map(\u0026f, 0),\n+\t\t\tPCI_P2PDMA_MAP_NOT_SUPPORTED);\n+\tKUNIT_EXPECT_EQ(test,\n+\t\t\tacs_walk_map(\u0026f, PCI_P2PDMA_TLP_TRANSLATED |\n+\t\t\t\t     PCI_P2PDMA_TLP_RELAXED_CPL),\n+\t\t\tPCI_P2PDMA_MAP_BUS_ADDR);\n+\n+\tf.provider_leaf_cfg.fail_read = true;\n+\tKUNIT_EXPECT_EQ(test, acs_walk_map(\u0026f, 0),\n+\t\t\tPCI_P2PDMA_MAP_NOT_SUPPORTED);\n+\tKUNIT_EXPECT_EQ(test,\n+\t\t\tacs_walk_map(\u0026f, PCI_P2PDMA_TLP_TRANSLATED |\n+\t\t\t\t     PCI_P2PDMA_TLP_RELAXED_CPL),\n+\t\t\tPCI_P2PDMA_MAP_BUS_ADDR);\n+}\n+\n+struct acs_forwarding_case {\n+\tconst char *desc;\n+\tu16 cap;\n+\tu16 capabilities;\n+\tu16 ctrl;\n+\tbool fail_read;\n+};\n+\n+static const struct acs_forwarding_case acs_forwarding_cases[] = {\n+\t{ \"disabled\", ACS_TEST_CAP, PCI_ACS_UF, 0, false },\n+\t{ \"unsupported\", ACS_TEST_CAP, 0, 0, false },\n+\t{ \"absent_acs\", 0, 0, 0, false },\n+\t{ \"read_error\", ACS_TEST_CAP, PCI_ACS_UF, PCI_ACS_UF, true },\n+\t{ \"all_ones\", ACS_TEST_CAP, PCI_ACS_UF, 0xffff, false },\n+};\n+\n+static void acs_forwarding_desc(const struct acs_forwarding_case *c,\n+\t\t\t\tchar *desc)\n+{\n+\tstrscpy(desc, c-\u003edesc, KUNIT_PARAM_DESC_SIZE);\n+}\n+\n+KUNIT_ARRAY_PARAM(acs_forwarding, acs_forwarding_cases, acs_forwarding_desc);\n+\n+static void acs_expect_redirect_forwarding(struct kunit *test,\n+\t\t\t\t\t  struct acs_fabric *f,\n+\t\t\t\t\t  struct pci_dev *provider_port,\n+\t\t\t\t\t  struct acs_port_cfg *provider_cfg,\n+\t\t\t\t\t  struct pci_dev *client_port,\n+\t\t\t\t\t  struct acs_port_cfg *client_cfg)\n+{\n+\tunsigned int flags;\n+\n+\tprovider_port-\u003eacs_cap = ACS_TEST_CAP;\n+\tprovider_port-\u003eacs_capabilities = ACS_ALL_CAPS;\n+\tclient_port-\u003eacs_cap = ACS_TEST_CAP;\n+\tclient_port-\u003eacs_capabilities = ACS_ALL_CAPS | PCI_ACS_EC;\n+\tacs_expect_classes(test, f, PCI_P2PDMA_MAP_BUS_ADDR);\n+\n+\tclient_cfg-\u003ectrl = PCI_ACS_RR;\n+\tacs_expect_classes(test, f, PCI_P2PDMA_MAP_NOT_SUPPORTED);\n+\tclient_cfg-\u003ectrl = PCI_ACS_EC;\n+\tacs_expect_classes(test, f, PCI_P2PDMA_MAP_NOT_SUPPORTED);\n+\tclient_cfg-\u003ectrl = 0;\n+\tprovider_cfg-\u003ectrl = PCI_ACS_CR;\n+\tfor (flags = 0; flags \u003c PCI_P2PDMA_TLP_CLASSES; flags++)\n+\t\tKUNIT_EXPECT_EQ_MSG(test, acs_walk_map(f, flags),\n+\t\t\t\t    flags \u0026 PCI_P2PDMA_TLP_RELAXED_CPL ?\n+\t\t\t\t    PCI_P2PDMA_MAP_BUS_ADDR :\n+\t\t\t\t    PCI_P2PDMA_MAP_NOT_SUPPORTED,\n+\t\t\t\t    \"TLP flags %#x\", flags);\n+\n+\tclient_cfg-\u003ectrl = PCI_ACS_RR | PCI_ACS_DT;\n+\tfor (flags = 0; flags \u003c PCI_P2PDMA_TLP_CLASSES; flags++)\n+\t\tKUNIT_EXPECT_EQ_MSG(test, acs_walk_map(f, flags),\n+\t\t\t\t    flags == (PCI_P2PDMA_TLP_TRANSLATED |\n+\t\t\t\t\t      PCI_P2PDMA_TLP_RELAXED_CPL) ?\n+\t\t\t\t    PCI_P2PDMA_MAP_BUS_ADDR :\n+\t\t\t\t    PCI_P2PDMA_MAP_NOT_SUPPORTED,\n+\t\t\t\t    \"TLP flags %#x\", flags);\n+}\n+\n+static void acs_walk_switch_forwarding_test(struct kunit *test)\n+{\n+\tconst struct acs_forwarding_case *c = test-\u003eparam_value;\n+\tstruct acs_fabric f = {};\n+\n+\tacs_build_fabric(test, \u0026f);\n+\tf.rootport-\u003eacs_cap = c-\u003ecap;\n+\tf.rootport-\u003eacs_capabilities = c-\u003ecapabilities;\n+\tf.rootport_cfg.ctrl = c-\u003ectrl;\n+\tf.rootport_cfg.fail_read = c-\u003efail_read;\n+\tacs_expect_redirect_forwarding(test, \u0026f, f.dn0, \u0026f.dn0_cfg,\n+\t\t\t\t       f.dn1, \u0026f.dn1_cfg);\n+}\n+\n+static void acs_walk_cascaded_forwarding_test(struct kunit *test)\n+{\n+\tconst struct acs_forwarding_case *c = test-\u003eparam_value;\n+\tstruct acs_fabric f = {};\n+\n+\tacs_build_fabric(test, \u0026f);\n+\tf.client_leaf-\u003ebus = f.provider_leaf-\u003ebus;\n+\tf.client_leaf-\u003edevfn = PCI_DEVFN(1, 0);\n+\tlist_move_tail(\u0026f.client_leaf-\u003ebus_list, \u0026f.client_leaf-\u003ebus-\u003edevices);\n+\tf.client-\u003ebus-\u003eparent = f.client_leaf-\u003ebus;\n+\tf.dn0-\u003eacs_cap = c-\u003ecap;\n+\tf.dn0-\u003eacs_capabilities = c-\u003ecapabilities;\n+\tf.dn0_cfg.ctrl = c-\u003ectrl;\n+\tf.dn0_cfg.fail_read = c-\u003efail_read;\n+\tacs_expect_redirect_forwarding(test, \u0026f,\n+\t\t\t\t       f.provider_leaf, \u0026f.provider_leaf_cfg,\n+\t\t\t\t       f.client_leaf, \u0026f.client_leaf_cfg);\n+\n+\tacs_enable_forwarding(f.dn0, \u0026f.dn0_cfg);\n+\tf.dn0_cfg.fail_read = false;\n+\tf.provider_leaf_cfg.ctrl = 0;\n+\tf.client_leaf_cfg.ctrl = PCI_ACS_RR;\n+\tacs_expect_classes(test, \u0026f, PCI_P2PDMA_MAP_THRU_HOST_BRIDGE);\n+\tf.rootport_cfg.ctrl = 0;\n+\tacs_expect_classes(test, \u0026f, PCI_P2PDMA_MAP_NOT_SUPPORTED);\n+}\n+\n+static void acs_walk_mf_forwarding_test(struct kunit *test)\n+{\n+\tconst struct acs_forwarding_case *c = test-\u003eparam_value;\n+\tstruct acs_fabric f = {};\n+\n+\tacs_build_mf_fabric(test, \u0026f);\n+\tf.provider_leaf-\u003eacs_cap = c-\u003ecap;\n+\tf.provider_leaf-\u003eacs_capabilities = c-\u003ecapabilities;\n+\tf.provider_leaf_cfg.ctrl = c-\u003ectrl;\n+\tf.provider_leaf_cfg.fail_read = c-\u003efail_read;\n+\tacs_expect_classes(test, \u0026f, PCI_P2PDMA_MAP_NOT_SUPPORTED);\n+}\n+\n+static void acs_walk_mf_upstream_forwarding_test(struct kunit *test)\n+{\n+\tstruct acs_fabric f = {};\n+\n+\tacs_build_mf_fabric(test, \u0026f);\n+\tf.dn0_cfg.ctrl = 0;\n+\tacs_expect_classes(test, \u0026f, PCI_P2PDMA_MAP_NOT_SUPPORTED);\n+\n+\tf.dn0_cfg.ctrl = PCI_ACS_UF;\n+\tf.rootport_cfg.ctrl = 0;\n+\tacs_expect_classes(test, \u0026f, PCI_P2PDMA_MAP_NOT_SUPPORTED);\n+}\n+\n+static void acs_walk_mf_translation_blocking_test(struct kunit *test)\n+{\n+\tstruct acs_fabric f = {};\n+\tunsigned int flags;\n+\n+\tacs_build_mf_fabric(test, \u0026f);\n+\tf.provider_leaf-\u003eacs_capabilities |= PCI_ACS_TB;\n+\tf.provider_leaf_cfg.ctrl |= PCI_ACS_TB;\n+\tfor (flags = 0; flags \u003c PCI_P2PDMA_TLP_CLASSES; flags++)\n+\t\tKUNIT_EXPECT_EQ_MSG(test, acs_walk_map(\u0026f, flags),\n+\t\t\t\t    flags \u0026 PCI_P2PDMA_TLP_TRANSLATED ?\n+\t\t\t\t    PCI_P2PDMA_MAP_NOT_SUPPORTED :\n+\t\t\t\t    PCI_P2PDMA_MAP_THRU_HOST_BRIDGE,\n+\t\t\t\t    \"TLP flags %#x\", flags);\n+}\n+\n+static void acs_walk_mf_unlisted_host_test(struct kunit *test)\n+{\n+\tstruct acs_fabric f = {}, g = {};\n+\tint dist;\n+\n+\tacs_build_mf_fabric(test, \u0026f);\n+\tacs_build_fabric(test, \u0026g);\n+\tf.rootport-\u003evendor = 0;\n+\tg.rootport-\u003evendor = 0;\n+\t/* Some CPUs permit host routing regardless of the host allowlist. */\n+\tif (calc_map_type_and_dist(f.provider, g.client, \u0026dist, 0, false) ==\n+\t    PCI_P2PDMA_MAP_THRU_HOST_BRIDGE)\n+\t\tkunit_skip(test, \"CPU supports P2PDMA on unlisted hosts\");\n+\n+\tacs_expect_classes(test, \u0026f, PCI_P2PDMA_MAP_NOT_SUPPORTED);\n+}\n+\n+static void acs_walk_mf_ari_test(struct kunit *test)\n+{\n+\tstruct acs_fabric f = {};\n+\n+\tacs_build_mf_fabric(test, \u0026f);\n+\tf.provider-\u003ebus-\u003eself-\u003eari_enabled = 1;\n+\tf.client-\u003edevfn = 8;\n+\tf.client-\u003emultifunction = 0;\n+\tacs_expect_classes(test, \u0026f, PCI_P2PDMA_MAP_THRU_HOST_BRIDGE);\n+\n+\t/* The same shared-link topology can be directly below a Root Port. */\n+\tf.provider-\u003ebus-\u003eparent = f.rootport-\u003ebus;\n+\tf.provider-\u003ebus-\u003eself = f.rootport;\n+\tf.rootport-\u003eari_enabled = 1;\n+\tacs_expect_classes(test, \u0026f, PCI_P2PDMA_MAP_THRU_HOST_BRIDGE);\n+}\n+\n+static void acs_walk_mf_vf_test(struct kunit *test)\n+{\n+#ifdef CONFIG_PCI_IOV\n+\tstruct acs_fabric f = {};\n+\tstruct pci_dev *physfn;\n+\n+\tacs_build_mf_fabric(test, \u0026f);\n+\tphysfn = acs_add_dev(test, f.provider-\u003ebus, PCI_DEVFN(0, 0),\n+\t\t\t     PCI_EXP_TYPE_ENDPOINT);\n+\tphysfn-\u003eis_physfn = 1;\n+\tphysfn-\u003eacs_cap = ACS_TEST_CAP;\n+\tphysfn-\u003eacs_capabilities = ACS_ALL_CAPS;\n+\tf.provider-\u003edevfn = 1;\n+\tf.client-\u003edevfn = 8;\n+\tf.provider-\u003ebus-\u003eself-\u003eari_enabled = 1;\n+\tf.provider-\u003emultifunction = 0;\n+\tf.client-\u003emultifunction = 0;\n+\tf.provider-\u003eis_virtfn = 1;\n+\tf.client-\u003eis_virtfn = 1;\n+\tf.provider-\u003ephysfn = physfn;\n+\tf.client-\u003ephysfn = physfn;\n+\tacs_expect_classes(test, \u0026f, PCI_P2PDMA_MAP_THRU_HOST_BRIDGE);\n+\n+\t/* SR-IOV functions without ACS cannot route internally either. */\n+\tf.provider-\u003eacs_cap = 0;\n+\tf.client-\u003eacs_cap = 0;\n+\tacs_expect_classes(test, \u0026f, PCI_P2PDMA_MAP_THRU_HOST_BRIDGE);\n+\n+\t/* Check the physical function as the peer of one of its VFs. */\n+\tf.provider-\u003eis_virtfn = 0;\n+\tf.provider-\u003ephysfn = NULL;\n+\tf.provider-\u003eis_physfn = 1;\n+\tf.client-\u003ephysfn = f.provider;\n+\tacs_expect_classes(test, \u0026f, PCI_P2PDMA_MAP_THRU_HOST_BRIDGE);\n+#else\n+\tkunit_skip(test, \"needs CONFIG_PCI_IOV\");\n+#endif\n+}\n+\n+static void acs_walk_mf_external_peer_test(struct kunit *test)\n+{\n+\tstruct acs_fabric f = {};\n+\n+\tacs_build_fabric(test, \u0026f);\n+\tf.provider-\u003emultifunction = 1;\n+\tf.client-\u003emultifunction = 1;\n+\tf.provider-\u003eacs_cap = ACS_TEST_CAP;\n+\tf.client-\u003eacs_cap = ACS_TEST_CAP;\n+\tacs_expect_classes(test, \u0026f, PCI_P2PDMA_MAP_BUS_ADDR);\n+}\n+\n+static void acs_walk_mf_self_dma_test(struct kunit *test)\n+{\n+\tstruct acs_fabric f = {};\n+\tunsigned int flags;\n+\tint dist;\n+\n+\tacs_build_mf_fabric(test, \u0026f);\n+\tf.provider_leaf-\u003eacs_capabilities = PCI_ACS_TB;\n+\tf.provider_leaf_cfg.ctrl = PCI_ACS_TB;\n+\tfor (flags = 0; flags \u003c PCI_P2PDMA_TLP_CLASSES; flags++) {\n+\t\tKUNIT_EXPECT_EQ(test,\n+\t\t\t\tcalc_map_type_and_dist(f.client, f.client, \u0026dist,\n+\t\t\t\t\t\t       flags, false),\n+\t\t\t\tPCI_P2PDMA_MAP_BUS_ADDR);\n+\t\tKUNIT_EXPECT_EQ(test, dist, 0);\n+\t}\n+}\n+\n+/*\n+ * The cache stores one packed value per client, so every class has to come\n+ * back out under the flags that selected it.\n+ */\n+static void acs_map_types_pack_test(struct kunit *test)\n+{\n+\tstatic const enum pci_p2pdma_map_type type[PCI_P2PDMA_TLP_CLASSES] = {\n+\t\t[0] = PCI_P2PDMA_MAP_THRU_HOST_BRIDGE,\n+\t\t[PCI_P2PDMA_TLP_TRANSLATED] = PCI_P2PDMA_MAP_NOT_SUPPORTED,\n+\t\t[PCI_P2PDMA_TLP_RELAXED_CPL] = PCI_P2PDMA_MAP_BUS_ADDR,\n+\t\t[PCI_P2PDMA_TLP_TRANSLATED | PCI_P2PDMA_TLP_RELAXED_CPL] =\n+\t\t\tPCI_P2PDMA_MAP_UNKNOWN,\n+\t};\n+\tunsigned long packed = pci_p2pdma_map_types_pack(type);\n+\tunsigned int flags;\n+\n+\tfor (flags = 0; flags \u003c PCI_P2PDMA_TLP_CLASSES; flags++)\n+\t\tKUNIT_EXPECT_EQ(test,\n+\t\t\t\tpci_p2pdma_map_types_unpack(packed, flags),\n+\t\t\t\ttype[flags]);\n+\n+\t/* An absent cache entry reads back as unknown in every class. */\n+\tfor (flags = 0; flags \u003c PCI_P2PDMA_TLP_CLASSES; flags++)\n+\t\tKUNIT_EXPECT_EQ(test, pci_p2pdma_map_types_unpack(0, flags),\n+\t\t\t\tPCI_P2PDMA_MAP_UNKNOWN);\n+}\n+\n+/*\n+ * The provider can be an ancestor of the client, which leaves no divergence\n+ * to evaluate. Translation Blocking still applies to every port the Request\n+ * passes on its way up.\n+ */\n+static void acs_walk_ancestor_provider_tb_test(struct kunit *test)\n+{\n+\tstruct acs_fabric f = {};\n+\tint dist;\n+\n+\tacs_build_fabric(test, \u0026f);\n+\tf.client_leaf-\u003eacs_cap = 0x100;\n+\tf.client_leaf-\u003eacs_capabilities = PCI_ACS_TB;\n+\tf.client_leaf_cfg.ctrl = PCI_ACS_TB;\n+\n+\tKUNIT_EXPECT_EQ(test,\n+\t\t\tcalc_map_type_and_dist(f.dn1, f.client, \u0026dist, 0,\n+\t\t\t\t\t       false),\n+\t\t\tPCI_P2PDMA_MAP_BUS_ADDR);\n+\tKUNIT_EXPECT_EQ(test,\n+\t\t\tcalc_map_type_and_dist(f.dn1, f.client, \u0026dist,\n+\t\t\t\t\t       PCI_P2PDMA_TLP_TRANSLATED,\n+\t\t\t\t\t       false),\n+\t\t\tPCI_P2PDMA_MAP_NOT_SUPPORTED);\n+}\n+\n+/*\n+ * Without a common upstream bridge the Request still climbs towards the host\n+ * bridge, so Translation Blocking on the way withdraws the Translated classes\n+ * there too.\n+ */\n+static void acs_walk_no_common_bridge_tb_test(struct kunit *test)\n+{\n+\tstruct acs_fabric f = {}, g = {};\n+\tint dist;\n+\n+\tacs_build_fabric(test, \u0026f);\n+\tacs_build_fabric(test, \u0026g);\n+\tf.client_leaf-\u003eacs_cap = 0x100;\n+\tf.client_leaf-\u003eacs_capabilities = PCI_ACS_TB;\n+\tf.client_leaf_cfg.ctrl = PCI_ACS_TB;\n+\n+\tKUNIT_EXPECT_EQ(test,\n+\t\t\tcalc_map_type_and_dist(g.provider, f.client, \u0026dist, 0,\n+\t\t\t\t\t       false),\n+\t\t\tPCI_P2PDMA_MAP_THRU_HOST_BRIDGE);\n+\tKUNIT_EXPECT_EQ(test,\n+\t\t\tcalc_map_type_and_dist(g.provider, f.client, \u0026dist,\n+\t\t\t\t\t       PCI_P2PDMA_TLP_TRANSLATED,\n+\t\t\t\t\t       false),\n+\t\t\tPCI_P2PDMA_MAP_NOT_SUPPORTED);\n+}\n+\n+/*\n+ * A Request between the client and itself never leaves the device, so no port\n+ * is in a position to inspect its Address Type. Translation Blocking directly\n+ * above the client must not withdraw the Translated classes.\n+ */\n+static void acs_walk_self_dma_tb_test(struct kunit *test)\n+{\n+\tstruct acs_fabric f = {};\n+\tint dist;\n+\n+\tacs_build_fabric(test, \u0026f);\n+\tf.client_leaf-\u003eacs_cap = 0x100;\n+\tf.client_leaf-\u003eacs_capabilities = PCI_ACS_TB;\n+\tf.client_leaf_cfg.ctrl = PCI_ACS_TB;\n+\n+\tKUNIT_EXPECT_EQ(test,\n+\t\t\tcalc_map_type_and_dist(f.client, f.client, \u0026dist, 0,\n+\t\t\t\t\t       false),\n+\t\t\tPCI_P2PDMA_MAP_BUS_ADDR);\n+\tKUNIT_EXPECT_EQ(test,\n+\t\t\tcalc_map_type_and_dist(f.client, f.client, \u0026dist,\n+\t\t\t\t\t       PCI_P2PDMA_TLP_TRANSLATED,\n+\t\t\t\t\t       false),\n+\t\t\tPCI_P2PDMA_MAP_BUS_ADDR);\n+}\n+\n+/*\n+ * A direct route turns around at the divergence, so Translation Blocking above\n+ * it does not touch one. The host bridge route keeps climbing past that port,\n+ * and the Translated classes have to go without it.\n+ */\n+static void acs_walk_tb_above_divergence_test(struct kunit *test)\n+{\n+\tstruct acs_fabric f = {};\n+\tint dist;\n+\n+\tacs_build_fabric(test, \u0026f);\n+\tf.rootport-\u003eacs_cap = 0x100;\n+\tf.rootport-\u003eacs_capabilities |= PCI_ACS_TB;\n+\tf.rootport_cfg.ctrl |= PCI_ACS_TB;\n+\n+\t/* Nothing redirects yet, so the Request never reaches the Root Port. */\n+\tKUNIT_EXPECT_EQ(test,\n+\t\t\tcalc_map_type_and_dist(f.provider, f.client, \u0026dist,\n+\t\t\t\t\t       PCI_P2PDMA_TLP_TRANSLATED,\n+\t\t\t\t\t       false),\n+\t\t\tPCI_P2PDMA_MAP_BUS_ADDR);\n+\n+\t/* Request Redirect sends it up past the Root Port instead. */\n+\tf.dn1-\u003eacs_cap = 0x100;\n+\tf.dn1-\u003eacs_capabilities = PCI_ACS_RR;\n+\tf.dn1_cfg.ctrl = PCI_ACS_RR;\n+\n+\tKUNIT_EXPECT_EQ(test,\n+\t\t\tcalc_map_type_and_dist(f.provider, f.client, \u0026dist, 0,\n+\t\t\t\t\t       false),\n+\t\t\tPCI_P2PDMA_MAP_THRU_HOST_BRIDGE);\n+\tKUNIT_EXPECT_EQ(test,\n+\t\t\tcalc_map_type_and_dist(f.provider, f.client, \u0026dist,\n+\t\t\t\t\t       PCI_P2PDMA_TLP_TRANSLATED,\n+\t\t\t\t\t       false),\n+\t\t\tPCI_P2PDMA_MAP_NOT_SUPPORTED);\n+}\n+\n+struct acs_intel_tb_case {\n+\tconst char *desc;\n+\tu32 ctrl;\n+\tbool fail_read;\n+\tenum pci_p2pdma_map_type translated;\n+\tenum pci_p2pdma_map_type redirected;\n+};\n+\n+static const struct acs_intel_tb_case acs_intel_tb_cases[] = {\n+\t{ \"tb_clear\", PCI_ACS_UF, false,\n+\t  PCI_P2PDMA_MAP_THRU_HOST_BRIDGE, PCI_P2PDMA_MAP_THRU_HOST_BRIDGE },\n+\t{ \"tb_set\", PCI_ACS_UF | PCI_ACS_TB, false,\n+\t  PCI_P2PDMA_MAP_NOT_SUPPORTED, PCI_P2PDMA_MAP_THRU_HOST_BRIDGE },\n+\t{ \"read_error\", PCI_ACS_UF, true,\n+\t  PCI_P2PDMA_MAP_NOT_SUPPORTED, PCI_P2PDMA_MAP_NOT_SUPPORTED },\n+\t{ \"all_ones\", ~0U, false,\n+\t  PCI_P2PDMA_MAP_NOT_SUPPORTED, PCI_P2PDMA_MAP_NOT_SUPPORTED },\n+};\n+\n+static void acs_intel_tb_desc(const struct acs_intel_tb_case *c, char *desc)\n+{\n+\tstrscpy(desc, c-\u003edesc, KUNIT_PARAM_DESC_SIZE);\n+}\n+\n+KUNIT_ARRAY_PARAM(acs_intel_tb, acs_intel_tb_cases, acs_intel_tb_desc);\n+\n+static void acs_build_intel_fabric(struct kunit *test, struct acs_fabric *f,\n+\t\t\t\t   const struct acs_intel_tb_case *c)\n+{\n+\tstruct pci_dev *host;\n+\n+\tacs_build_fabric(test, f);\n+\tf-\u003erootport-\u003edevfn = PCI_DEVFN(1, 0);\n+\tf-\u003erootport-\u003evendor = PCI_VENDOR_ID_INTEL;\n+\tf-\u003erootport-\u003edevice = 0xa290;\n+\tf-\u003erootport-\u003eacs_capabilities = PCI_ACS_UF | PCI_ACS_TB;\n+\tf-\u003erootport_cfg.ctrl = c-\u003ectrl;\n+\tf-\u003erootport_cfg.fail_read = c-\u003efail_read;\n+\tf-\u003erootport_cfg.dword_acs = true;\n+\n+\thost = acs_add_dev(test, f-\u003erootport-\u003ebus, PCI_DEVFN(0, 0),\n+\t\t\t   PCI_EXP_TYPE_ENDPOINT);\n+\thost-\u003evendor = PCI_VENDOR_ID_INTEL;\n+\thost-\u003edevice = 0x2020;\n+\thost-\u003epcie_cap = 0;\n+\thost-\u003eclass = PCI_CLASS_BRIDGE_HOST \u003c\u003c 8;\n+\tlist_move(\u0026host-\u003ebus_list, \u0026host-\u003ebus-\u003edevices);\n+}\n+\n+static void acs_walk_intel_tb_above_divergence_test(struct kunit *test)\n+{\n+\tconst struct acs_intel_tb_case *c = test-\u003eparam_value;\n+\tstruct acs_fabric f = {};\n+\tunsigned int flags;\n+\n+\tif (!IS_ENABLED(CONFIG_PCI_QUIRKS))\n+\t\tkunit_skip(test, \"needs CONFIG_PCI_QUIRKS\");\n+\n+\tacs_build_intel_fabric(test, \u0026f, c);\n+\tacs_expect_classes(test, \u0026f, PCI_P2PDMA_MAP_BUS_ADDR);\n+\n+\tf.dn1-\u003eacs_cap = ACS_TEST_CAP;\n+\tf.dn1-\u003eacs_capabilities = PCI_ACS_RR;\n+\tf.dn1_cfg.ctrl = PCI_ACS_RR;\n+\tfor (flags = 0; flags \u003c PCI_P2PDMA_TLP_CLASSES; flags++)\n+\t\tKUNIT_EXPECT_EQ_MSG(test, acs_walk_map(\u0026f, flags),\n+\t\t\t\t    flags \u0026 PCI_P2PDMA_TLP_TRANSLATED ?\n+\t\t\t\t    c-\u003etranslated : c-\u003eredirected,\n+\t\t\t\t    \"TLP flags %#x\", flags);\n+}\n+\n+static void acs_walk_intel_no_common_bridge_tb_test(struct kunit *test)\n+{\n+\tconst struct acs_intel_tb_case *c = test-\u003eparam_value;\n+\tstruct acs_fabric f = {}, g = {};\n+\tunsigned int flags;\n+\tint dist;\n+\n+\tif (!IS_ENABLED(CONFIG_PCI_QUIRKS))\n+\t\tkunit_skip(test, \"needs CONFIG_PCI_QUIRKS\");\n+\n+\tacs_build_intel_fabric(test, \u0026f, c);\n+\tacs_build_fabric(test, \u0026g);\n+\tfor (flags = 0; flags \u003c PCI_P2PDMA_TLP_CLASSES; flags++)\n+\t\tKUNIT_EXPECT_EQ_MSG(test,\n+\t\t\t\t    calc_map_type_and_dist(g.provider, f.client,\n+\t\t\t\t\t\t\t   \u0026dist, flags, false),\n+\t\t\t\t    flags \u0026 PCI_P2PDMA_TLP_TRANSLATED ?\n+\t\t\t\t    c-\u003etranslated :\n+\t\t\t\t    PCI_P2PDMA_MAP_THRU_HOST_BRIDGE,\n+\t\t\t\t    \"TLP flags %#x\", flags);\n+}\n+\n+static void acs_walk_unreadable_control_test(struct kunit *test)\n+{\n+\tstruct acs_fabric f = {};\n+\n+\tacs_build_fabric(test, \u0026f);\n+\tf.dn1-\u003eacs_cap = 0x100;\n+\tf.dn1_cfg.fail_read = true;\n+\n+\tKUNIT_EXPECT_EQ(test, acs_walk_map(\u0026f, 0),\n+\t\t\tPCI_P2PDMA_MAP_NOT_SUPPORTED);\n+\n+\t/* A port that does not answer reads as all ones, without an error */\n+\tf.dn1_cfg.fail_read = false;\n+\tf.dn1_cfg.ctrl = 0xffff;\n+\n+\tKUNIT_EXPECT_EQ(test, acs_walk_map(\u0026f, 0),\n+\t\t\tPCI_P2PDMA_MAP_NOT_SUPPORTED);\n+}\n+\n+/*\n+ * Route the way pci_p2pdma_map_type_tlp() does once it has a client: the\n+ * client decides which flags apply, and the answer is then checked against\n+ * what the client can be handed.\n+ */\n+static enum pci_p2pdma_map_type acs_client_map(struct acs_fabric *f,\n+\t\t\t\t\t       bool per_mapping,\n+\t\t\t\t\t       unsigned int tlp_flags)\n+{\n+\tenum pci_p2pdma_map_type type;\n+\tint dist;\n+\n+\tif (!per_mapping)\n+\t\ttlp_flags = pci_p2pdma_client_tlp_flags(f-\u003eclient, tlp_flags);\n+\ttype = calc_map_type_and_dist(f-\u003eprovider, f-\u003eclient, \u0026dist, tlp_flags,\n+\t\t\t\t      false);\n+\treturn pci_p2pdma_client_map_type(f-\u003eprovider, f-\u003eclient, per_mapping,\n+\t\t\t\t\t  tlp_flags, type);\n+}\n+\n+/*\n+ * A client with ATS enabled for the whole device translates whatever it is\n+ * handed, so it never gets bus addresses even on a direct route, and\n+ * Translation Blocking rejects it even when its caller asks for the default\n+ * class.\n+ */\n+static void acs_client_ats_test(struct kunit *test)\n+{\n+\tstruct acs_fabric f = {};\n+\n+\tacs_build_fabric(test, \u0026f);\n+\tf.client-\u003eats_enabled = 1;\n+\n+\tKUNIT_EXPECT_EQ(test, acs_client_map(\u0026f, false, 0),\n+\t\t\tPCI_P2PDMA_MAP_THRU_HOST_BRIDGE);\n+\n+\tf.client_leaf-\u003eacs_cap = 0x100;\n+\tf.client_leaf-\u003eacs_capabilities = PCI_ACS_TB;\n+\tf.client_leaf_cfg.ctrl = PCI_ACS_TB;\n+\n+\tKUNIT_EXPECT_EQ(test, acs_client_map(\u0026f, false, 0),\n+\t\t\tPCI_P2PDMA_MAP_NOT_SUPPORTED);\n+}\n+\n+/*\n+ * The cache holds what the topology allows, filled when the client first\n+ * asked. A client whose ATS was enabled after that must still be kept off the\n+ * bus addresses the cache recorded.\n+ */\n+static void acs_client_ats_cached_test(struct kunit *test)\n+{\n+\tenum pci_p2pdma_map_type type[PCI_P2PDMA_TLP_CLASSES], hit;\n+\tstruct acs_fabric f = {};\n+\tunsigned long cached;\n+\tunsigned int flags;\n+\tint dist;\n+\n+\tacs_build_fabric(test, \u0026f);\n+\tfor (flags = 0; flags \u003c PCI_P2PDMA_TLP_CLASSES; flags++)\n+\t\ttype[flags] = calc_map_type_and_dist(f.provider, f.client,\n+\t\t\t\t\t\t     \u0026dist, flags, false);\n+\tcached = pci_p2pdma_map_types_pack(type);\n+\n+\tf.client-\u003eats_enabled = 1;\n+\tflags = pci_p2pdma_client_tlp_flags(f.client, 0);\n+\thit = pci_p2pdma_map_types_unpack(cached, flags);\n+\n+\tKUNIT_EXPECT_EQ(test,\n+\t\t\tpci_p2pdma_client_map_type(f.provider, f.client, false,\n+\t\t\t\t\t\t   flags, hit),\n+\t\t\tPCI_P2PDMA_MAP_THRU_HOST_BRIDGE);\n+}\n+\n+/*\n+ * A client that declared per-mapping ATS picks the Address Type per mapping,\n+ * so it keeps the per-class answers even with ATS enabled.\n+ */\n+static void acs_client_ats_per_mapping_test(struct kunit *test)\n+{\n+\tstruct acs_fabric f = {};\n+\n+\tacs_build_fabric(test, \u0026f);\n+\tf.client-\u003eats_enabled = 1;\n+\n+\tKUNIT_EXPECT_EQ(test, acs_client_map(\u0026f, true, 0),\n+\t\t\tPCI_P2PDMA_MAP_BUS_ADDR);\n+\tKUNIT_EXPECT_EQ(test,\n+\t\t\tacs_client_map(\u0026f, true, PCI_P2PDMA_TLP_TRANSLATED),\n+\t\t\tPCI_P2PDMA_MAP_BUS_ADDR);\n+\n+\tf.client_leaf-\u003eacs_cap = 0x100;\n+\tf.client_leaf-\u003eacs_capabilities = PCI_ACS_TB;\n+\tf.client_leaf_cfg.ctrl = PCI_ACS_TB;\n+\n+\tKUNIT_EXPECT_EQ(test, acs_client_map(\u0026f, true, 0),\n+\t\t\tPCI_P2PDMA_MAP_BUS_ADDR);\n+\tKUNIT_EXPECT_EQ(test,\n+\t\t\tacs_client_map(\u0026f, true, PCI_P2PDMA_TLP_TRANSLATED),\n+\t\t\tPCI_P2PDMA_MAP_NOT_SUPPORTED);\n+}\n+\n+/*\n+ * A client with ATS disabled cannot issue Translated Requests, so a caller\n+ * asking about them gets the answer for the Untranslated ones it will issue.\n+ */\n+static void acs_client_no_ats_test(struct kunit *test)\n+{\n+\tstruct acs_fabric f = {};\n+\n+\tacs_build_fabric(test, \u0026f);\n+\tf.dn1-\u003eacs_cap = 0x100;\n+\tf.dn1-\u003eacs_capabilities = PCI_ACS_RR | PCI_ACS_DT;\n+\tf.dn1_cfg.ctrl = PCI_ACS_RR | PCI_ACS_DT;\n+\n+\tKUNIT_EXPECT_EQ(test,\n+\t\t\tacs_client_map(\u0026f, false, PCI_P2PDMA_TLP_TRANSLATED),\n+\t\t\tPCI_P2PDMA_MAP_THRU_HOST_BRIDGE);\n+}\n+\n+static struct kunit_case pci_acs_test_cases[] = {\n+\tKUNIT_CASE_PARAM(pci_acs_p2pdma_request_test,\n+\t\t\t acs_request_gen_params),\n+\tKUNIT_CASE_PARAM(pci_acs_p2pdma_completion_test,\n+\t\t\t acs_completion_gen_params),\n+\tKUNIT_CASE_PARAM(pci_acs_flags_enabled_test,\n+\t\t\t acs_isolation_gen_params),\n+\tKUNIT_CASE(pci_acs_flags_no_cap_test),\n+\tKUNIT_CASE(pci_acs_flags_read_fails_test),\n+\tKUNIT_CASE(acs_walk_bus_addr_test),\n+\tKUNIT_CASE(acs_walk_request_redirect_test),\n+\tKUNIT_CASE(acs_walk_completion_redirect_test),\n+\tKUNIT_CASE(acs_walk_egress_control_test),\n+\tKUNIT_CASE(acs_walk_quirk_redirect_test),\n+\tKUNIT_CASE(acs_walk_asymmetric_direct_test),\n+\tKUNIT_CASE(acs_walk_nested_completion_redirect_test),\n+\tKUNIT_CASE(acs_walk_nested_request_redirect_test),\n+\tKUNIT_CASE(acs_walk_translation_blocking_test),\n+\tKUNIT_CASE(acs_walk_ancestor_provider_tb_test),\n+\tKUNIT_CASE(acs_walk_no_common_bridge_tb_test),\n+\tKUNIT_CASE(acs_walk_self_dma_tb_test),\n+\tKUNIT_CASE(acs_walk_relaxed_completion_test),\n+\tKUNIT_CASE(acs_walk_direct_translated_test),\n+\tKUNIT_CASE(acs_walk_mf_isolation_test),\n+\tKUNIT_CASE(acs_walk_mf_quirk_test),\n+\tKUNIT_CASE(acs_walk_mf_direction_test),\n+\tKUNIT_CASE(acs_walk_mf_programmable_test),\n+\tKUNIT_CASE_PARAM(acs_walk_switch_forwarding_test, acs_forwarding_gen_params),\n+\tKUNIT_CASE_PARAM(acs_walk_cascaded_forwarding_test, acs_forwarding_gen_params),\n+\tKUNIT_CASE_PARAM(acs_walk_mf_forwarding_test, acs_forwarding_gen_params),\n+\tKUNIT_CASE(acs_walk_mf_upstream_forwarding_test),\n+\tKUNIT_CASE(acs_walk_mf_translation_blocking_test),\n+\tKUNIT_CASE(acs_walk_mf_unlisted_host_test),\n+\tKUNIT_CASE(acs_walk_mf_ari_test),\n+\tKUNIT_CASE(acs_walk_mf_vf_test),\n+\tKUNIT_CASE(acs_walk_mf_external_peer_test),\n+\tKUNIT_CASE(acs_walk_mf_self_dma_test),\n+\tKUNIT_CASE(acs_walk_tb_above_divergence_test),\n+\tKUNIT_CASE_PARAM(acs_walk_intel_tb_above_divergence_test,\n+\t\t\t acs_intel_tb_gen_params),\n+\tKUNIT_CASE_PARAM(acs_walk_intel_no_common_bridge_tb_test,\n+\t\t\t acs_intel_tb_gen_params),\n+\tKUNIT_CASE(acs_walk_unreadable_control_test),\n+\tKUNIT_CASE(acs_map_types_pack_test),\n+\tKUNIT_CASE(acs_client_ats_test),\n+\tKUNIT_CASE(acs_client_ats_cached_test),\n+\tKUNIT_CASE(acs_client_ats_per_mapping_test),\n+\tKUNIT_CASE(acs_client_no_ats_test),\n+\t{}\n+};\n+\n+static struct kunit_suite pci_acs_test_suite = {\n+\t.name = \"pci_acs\",\n+\t.test_cases = pci_acs_test_cases,\n+};\n+kunit_test_suite(pci_acs_test_suite);\n+\n+MODULE_IMPORT_NS(\"EXPORTED_FOR_KUNIT_TESTING\");\n+MODULE_LICENSE(\"GPL\");\n+MODULE_DESCRIPTION(\"KUnit tests for PCI ACS peer-to-peer routing decisions\");\ndiff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c\nindex 7f1f47ea2ee415..4b6e868722280a 100644\n--- a/drivers/pci/quirks.c\n+++ b/drivers/pci/quirks.c\n@@ -5132,6 +5132,21 @@ static bool pci_quirk_intel_spt_pch_acs_match(struct pci_dev *dev)\n \n #define INTEL_SPT_ACS_CTRL (PCI_ACS_CAP + 4)\n \n+int pci_dev_specific_read_acs_ctrl(struct pci_dev *dev, u16 *ctrl)\n+{\n+\tu32 val = ~0;\n+\tint ret;\n+\n+\tif (dev-\u003evendor != PCI_VENDOR_ID_INTEL || !dev-\u003eacs_cap ||\n+\t    !pci_quirk_intel_spt_pch_acs_match(dev))\n+\t\treturn -ENOTTY;\n+\n+\tret = pci_read_config_dword(dev, dev-\u003eacs_cap + INTEL_SPT_ACS_CTRL,\n+\t\t\t\t   \u0026val);\n+\t*ctrl = val;\n+\treturn ret;\n+}\n+\n static int pci_quirk_intel_spt_pch_acs(struct pci_dev *dev, u16 acs_flags)\n {\n \tint pos;\n@@ -5145,10 +5160,14 @@ static int pci_quirk_intel_spt_pch_acs(struct pci_dev *dev, u16 acs_flags)\n \t\treturn -ENOTTY;\n \n \t/* see pci_acs_flags_enabled() */\n-\tpci_read_config_dword(dev, pos + PCI_ACS_CAP, \u0026cap);\n+\tif (pci_read_config_dword(dev, pos + PCI_ACS_CAP, \u0026cap) ||\n+\t    PCI_POSSIBLE_ERROR(cap))\n+\t\treturn 0;\n \tacs_flags \u0026= (cap | PCI_ACS_EC);\n \n-\tpci_read_config_dword(dev, pos + INTEL_SPT_ACS_CTRL, \u0026ctrl);\n+\tif (pci_read_config_dword(dev, pos + INTEL_SPT_ACS_CTRL, \u0026ctrl) ||\n+\t    PCI_POSSIBLE_ERROR(ctrl))\n+\t\treturn 0;\n \n \treturn pci_acs_ctrl_enabled(acs_flags, ctrl);\n }\ndiff --git a/include/linux/pci-p2pdma.h b/include/linux/pci-p2pdma.h\nindex 873de20a224759..ce389e18d02396 100644\n--- a/include/linux/pci-p2pdma.h\n+++ b/include/linux/pci-p2pdma.h\n@@ -42,10 +42,10 @@ enum pci_p2pdma_map_type {\n \tPCI_P2PDMA_MAP_NONE,\n \n \t/*\n-\t * PCI_P2PDMA_MAP_NOT_SUPPORTED: Indicates the transaction will\n-\t * traverse the host bridge and the host bridge is not in the\n-\t * allowlist. DMA Mapping routines should return an error when\n-\t * this is returned.\n+\t * PCI_P2PDMA_MAP_NOT_SUPPORTED: Indicates no safe mapping is available,\n+\t * for example because ACS blocks the direct path or the required host\n+\t * bridge is not in the allowlist. DMA Mapping routines should return an\n+\t * error when this is returned.\n \t */\n \tPCI_P2PDMA_MAP_NOT_SUPPORTED,\n \n@@ -82,6 +82,7 @@ struct scatterlist *pci_p2pmem_alloc_sgl(struct pci_dev *pdev,\n \t\t\t\t\t unsigned int *nents, u32 length);\n void pci_p2pmem_free_sgl(struct pci_dev *pdev, struct scatterlist *sgl);\n void pci_p2pmem_publish(struct pci_dev *pdev, bool publish);\n+void pcim_p2pdma_set_ats_per_mapping(struct pci_dev *pdev);\n int pci_p2pdma_enable_store(const char *page, struct pci_dev **p2p_dev,\n \t\t\t    bool *use_p2pdma);\n ssize_t pci_p2pdma_enable_show(char *page, struct pci_dev *p2p_dev,\n@@ -138,6 +139,9 @@ static inline void pci_p2pmem_free_sgl(struct pci_dev *pdev,\n static inline void pci_p2pmem_publish(struct pci_dev *pdev, bool publish)\n {\n }\n+static inline void pcim_p2pdma_set_ats_per_mapping(struct pci_dev *pdev)\n+{\n+}\n static inline int pci_p2pdma_enable_store(const char *page,\n \t\tstruct pci_dev **p2p_dev, bool *use_p2pdma)\n {\n"
}

2/1 2026/11/08 03:20 agent patch-evaluator
17m Model:
core

Args:
null

Results:
{
  "EnableConfigs": null,
  "FocusSymbols": [],
  "Reasoning": "The patch series refactors PCI Access Control Services (ACS) peer-to-peer DMA (P2PDMA) routing logic in drivers/pci/p2pdma.c, adds read error checks in drivers/pci/pci.c and drivers/pci/quirks.c, and adds a KUnit test suite in drivers/pci/pci_acs_test.c. In standard virtualized fuzzing environments (QEMU/GCE), the modified P2PDMA code paths are structurally unreachable because no PCIe P2PDMA memory providers (such as NVMe controllers with CMB or accelerator ASICs) or PCIe switch fabrics with ACS redirect capabilities are emulated or available. Furthermore, pci_acs_flags_enabled is only called during device probing/IOMMU group initialization at boot time, and KUnit unit tests are not exercised by syzkaller syscall fuzzing.",
  "WorthFuzzing": false
}

Instruction:
You are an expert Linux kernel maintainer and security engineer.
Your job is to review a provided patch series and evaluate whether it warrants fuzzing with syzkaller.

IMPORTANT: The changes have ALREADY been applied and committed as the HEAD commit in
your workspace. Do NOT rely on internal assumptions. You must actively use your code access
tools to inspect the actual source code, callers, and surrounding context.

================================================================================
1. CORE TRIAGE PHILOSOPHY
================================================================================
The goal of patch fuzzing is to discover crashes, regressions, exposed latent bugs,
and newly triggered assertions introduced by the patch series.

- REACHABILITY IS THE PRIMARY GATE:
  Fuzzing can only discover bugs in code that can actually execute in standard virtualized
  environments (GCE or QEMU, utilizing software-emulated devices like USB gadgets, netdev, tun/tap).
  If the modified code is structurally unreachable (see Section 2), it MUST NOT be fuzzed,
  regardless of whether it adds assertions or complex logic.

- DO NOT BLINDLY TRUST "NO FUNCTIONAL CHANGE" (NFCI) OR "REFACTORING" CLAIMS:
  Patch authors routinely label changes as "cleanups", "refactorings", or state
  "No functional change intended". Do NOT take these claims at face value.
  Code refactorings that rearrange logic, introduce helper functions, or alter state management
  in core subsystems frequently introduce subtle semantic shifts or uncover latent kernel bugs.
  If reachable executable code is modified or refactored, it MUST be fuzzed.

- NEW OR MODIFIED ASSERTIONS IN REACHABLE CODE MUST BE FUZZED:
  When a patch introduces or modifies runtime checks or assertions (e.g., WARN_ON*, VM_WARN_ON*,
  BUG_ON*, lockdep_assert*) in reachable code paths, it enforces new or stricter invariants.
  Even if the author believes the invariant always holds, fuzzing is essential to verify whether
  an unusual sequence of operations can violate it.

================================================================================
2. WHEN TO RETURN WorthFuzzing=false (NEGATIVE CRITERIA)
================================================================================
Return WorthFuzzing=false ONLY IF all modified code falls strictly into one or more of these categories:

- Non-kernel and non-executable changes:
  * Modifications to Documentation/, comments, or spelling fixes.
  * User-space directories, self-tests, samples, or scripts (e.g., tools/, samples/, scripts/, usr/)
    that do not affect the compiled kernel image (vmlinux) or kernel modules.
  * Purely decorative logging (e.g., message strings in pr_err, printk, dev_info) or tracepoints
    that do not alter control flow or data structures.
  * Build system or Kconfig changes that do not alter compiled C logic.
- Structurally unreachable hardware:
  * Vendor-specific PCIe switches, SmartNICs, or GPU drivers (e.g., mlxsw, pds_core, qed,
    ionic, amdgpu) requiring physical ASIC/PCIe cards not emulated in standard QEMU.
- Unreachable execution paths:
  * Driver teardown callbacks (.remove, .shutdown, pci_unregister_driver) executed only during
    physical PCI hot-unplug or manual sysfs driver unbinding.
  * Code paths exclusive to architectures other than the target architecture.

================================================================================
3. WHEN TO RETURN WorthFuzzing=true (POSITIVE CRITERIA)
================================================================================
Return WorthFuzzing=true whenever the patch touches reachable executable code, including:
- Core Subsystems:
  * Any logic modifications in memory management (mm/), synchronization/locking (kernel/locking/),
    BPF, scheduler, core networking, VFS, or syscall handling.
- Refactorings and Code Cleanups:
  * Any restructuring of reachable data structures, helper abstractions, or algorithm flows.
- Runtime Assertions and Defensive Checks:
  * Any introduction or alteration of assertions (WARN_ON*, VM_WARN_ON*, BUG_ON*, etc.) in reachable paths.
- Reachable Drivers and Protocols:
  * Drivers accessible via virtual buses (virtio, USB gadget, loopback, netlink, binder, sockets, etc.).

================================================================================
4. EXTRACTING FocusSymbols (PREVENTING DILUTION)
================================================================================
When WorthFuzzing=true, you must extract specific kernel functions into FocusSymbols to guide the fuzzer:

- AVOID UBIQUITOUS LIFECYCLE HOT-PATHS:
  Do NOT list generic, ubiquitous functions called by almost every program in the corpus
  (including, but not limited to: general memory allocators and deallocators, page fault
  and trap handlers, or core synchronization primitives; this is not an exhaustive list).
  Listing ubiquitous functions causes the fuzzer to classify thousands of unrelated tests as "focused",
  which severely dilutes fuzzing effort away from the actual changes.

- TARGET SPECIFIC FEATURE LOGIC AND ENTRYPOINTS:
  List functions that specifically implement the logic being added or altered, or direct API entrypoints
  for the subsystem feature under review.

- HANDLING STATIC INLINE FUNCTIONS IN HEADERS (.h):
  Compiler-inlined static functions (such as static inlines in mm/*.h or include/linux/*.h) lack
  distinct symbol addresses in vmlinux and cannot be targeted directly by symbol coverage filters.
  If the changes are primarily in static inline helpers, identify non-static, feature-specific caller
  functions in .c files that exercise them (avoiding ubiquitous lifecycle wrappers).

================================================================================
5. IDENTIFYING EnableConfigs
================================================================================
Identify any specific CONFIG_ options required to properly compile and reach the modified code:
- Inspect Kconfig files and #ifdef guards; do not make assumptions.
- Check "depends on" lines in Kconfig to include any non-standard parent subsystem configs needed.
- Strip any 'CONFIG_' prefix (e.g., return "NET_IPV4" instead of "CONFIG_NET_IPV4").
Prefer calling several tools at the same time to save round-trips.


Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.

Prompt:
Target architecture: amd64

For your convenience, here is the diff of the changes:
commit adff3f91dd81741a0584e6c5f2b042c8d97d6d80
Author: syz-cluster <triage@syzkaller.com>
Date:   Sun Nov 8 03:20:38 2026 +0000

    syz-cluster: applied patch under review

diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
index 0b3c140babd944..f7e116703ffcd1 100644
--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@ -5251,11 +5251,12 @@ Kernel parameters
 				Specify one or more PCI devices (in the format
 				specified above) separated by semicolons.
 				Each device specified will have the PCI ACS
-				redirect capabilities forced off which will
-				allow P2P traffic between devices through
-				bridges without forcing it upstream. Note:
-				this removes isolation between devices and
-				may put more devices in an IOMMU group.
+				P2P Request Redirect, Completion Redirect, and
+				Egress Control features forced off. This may
+				allow P2P traffic through bridges that would
+				otherwise be redirected upstream. Note: this
+				removes isolation between devices and may
+				cause affected devices to share an IOMMU group.
 		config_acs=
 				Format:
 				<ACS flags>@<pci_dev>[; ...]
diff --git a/Documentation/driver-api/pci/p2pdma.rst b/Documentation/driver-api/pci/p2pdma.rst
index 63cff9e4d2c9ac..7760ff64ed05b8 100644
--- a/Documentation/driver-api/pci/p2pdma.rst
+++ b/Documentation/driver-api/pci/p2pdma.rst
@@ -15,6 +15,112 @@ then based on the ACS settings the transaction can route entirely within
 the PCIe hierarchy and never reach the root port. The kernel will evaluate
 the PCIe topology and always permit P2P in these well-defined cases.
 
+The client is the PCIe Requester and the provider is the Completer, whether
+the client reads or writes provider memory. For devices on separate links
+below the same Root Port, their paths first meet in a Switch, where they
+diverge.
+A Request enters that Switch through the Downstream Port above the
+Requester, the Requester-side port. If ACS P2P Request Redirect is enabled
+there, the Request is routed upstream; otherwise it is routed back
+downstream through the Downstream Port leading to the Completer, the
+Completer-side port. The path of Completions from a read likewise depends on
+ACS P2P Completion Redirect in the Completer-side port. An enabled Egress
+Control is conservatively treated as a Request redirect.
+
+Below the divergence, the route toward the other branch is already upstream,
+so those P2P redirect controls do not affect it. Redirect controls for the
+reverse transaction directions do not affect the mapping. P2P DMA is routed
+through the host bridge when either applicable port redirects. If an ACS
+Control register needed for a route cannot be read, that route is rejected.
+
+Functions sharing one PCIe link can instead route internally within their
+device. An ACS capability without Request or Completion Redirect support
+means that the corresponding internal route does not exist. Device-specific
+ACS quirks can report the same restriction for functions without ACS, and
+SR-IOV functions without ACS cannot support internal peer traffic. These
+restrictions apply only between functions sharing the link, including ARI
+functions and VFs; they do not redirect traffic to a separate device.
+
+When traffic continues upstream beyond the divergence, ACS Upstream Forwarding
+must be enabled, or provided by a device-specific quirk, at every shared
+Downstream and Root Port on the way to the host bridge. This includes ports
+above a shared Switch Upstream Port as well as ports shared by sibling
+functions. Missing forwarding support or unreadable forwarding controls reject
+the host route while leaving direct routes available. The host bridge must
+also support P2P. Clearing redirect controls cannot create an internal route
+that the device does not support.
+
+Three of those controls act on TLP attributes that the Requester chooses rather
+than on the topology, so the same path routes differently for different
+traffic. ACS Translation Blocking rejects any upstream Request whose Address
+Type is not Untranslated, and takes precedence over every other P2P control.
+ACS Direct Translated P2P routes a Translated Request to the peer regardless of
+Request Redirect and Egress Control. ACS Completion Redirect leaves alone
+Completions that carry the Relaxed Ordering attribute, which a Completion
+copies from the Request it answers.
+
+P2PDMA therefore decides each class of traffic separately, and
+``pci_p2pdma_map_type()`` answers for the one a DMA mapping is built for:
+strictly ordered Requests carrying an Untranslated address.
+
+The PCIe ATS Enable bit covers the whole device, and most devices translate
+any address they are handed once it is set. Unless a driver has declared with
+``pcim_p2pdma_set_ats_per_mapping()`` that its device chooses ATS per mapping,
+that bit decides which Address Type P2PDMA assumes, and a client with ATS
+enabled is never handed a bus address, which it would translate as though it
+were an IOVA. Its Translated Requests may still route directly, but anything
+it issues untranslated reaches the host bridge, so that route has to work too.
+
+The two directions are decided independently. Translation Blocking (TB),
+Direct Translated P2P (DT), Request Redirect (RR) and Egress Control (EC) on
+the Requester-side port decide the Request:
+
+=====  =====  =======  ============  ==========
+TB     DT     RR/EC    TLP class     Request
+=====  =====  =======  ============  ==========
+set    x      x        translated    blocked
+clear  set    x        translated    direct
+clear  clear  clear    translated    direct
+clear  clear  set      translated    redirected
+x      x      clear    untranslated  direct
+x      x      set      untranslated  redirected
+=====  =====  =======  ============  ==========
+
+Completion Redirect (CR) on the Completer-side port decides the Completions:
+
+=====  =========  ==========
+CR     TLP class  Completion
+=====  =========  ==========
+x      relaxed    direct
+clear  strict     direct
+set    strict     redirected
+=====  =========  ==========
+
+Combining the two tables gives the mapping type. A class is bus addressable
+when its Request and its Completions both route directly, and anything else
+goes through the host bridge. A blocked Request has neither route, because
+Translation Blocking rejects the Address Type itself rather than the
+destination. With no ACS control set anywhere, every class routes directly
+provided that any required internal route between sibling functions exists.
+Neither Direct Translated P2P nor Relaxed Ordering can create such a route.
+
+Some ports without an ACS capability, such as certain Zhaoxin Switch
+Downstream Ports, redirect peer-to-peer traffic anyway, and a device-specific
+ACS quirk tells the kernel so. P2PDMA treats such a port as having Request and
+Completion Redirect set, but with no exception for Relaxed Ordering, so it
+redirects every Completion.
+
+Note that DT only matters where RR or EC would otherwise redirect: it
+overrides them for a Translated address rather than granting a direct route
+that was not already there.
+
+Translation Blocking is not a routing control, so it is evaluated on every
+port the Request passes on its way upstream rather than at the divergence
+alone. A direct route turns around at the divergence and only passes the ports
+below it, while the host bridge route keeps climbing and passes that port and
+everything above it as well. Neither route falls back to the other, because
+the Address Type is rejected wherever the Request is addressed.
+
 However, if the P2P transaction reaches the host bridge then it might have to
 hairpin back out the same root port, be routed inside the CPU SOC to another
 PCIe root port, or routed internally to the SOC.
diff --git a/drivers/pci/Kconfig b/drivers/pci/Kconfig
index 0c7408509ba24b..7a3eb5beb3281b 100644
--- a/drivers/pci/Kconfig
+++ b/drivers/pci/Kconfig
@@ -226,6 +226,21 @@ config PCI_P2PDMA
 
 	  If unsure, say N.
 
+config PCI_ACS_KUNIT_TEST
+	tristate "KUnit tests for PCI ACS P2P routing" if !KUNIT_ALL_TESTS
+	depends on PCI_P2PDMA && KUNIT
+	default KUNIT_ALL_TESTS
+	help
+	  Enable KUnit tests for the PCI ACS peer-to-peer routing decision
+	  logic, including direction-specific Request and Completion
+	  controls that cannot all be exercised on typical peer-to-peer
+	  hardware.
+
+	  For more information on KUnit and unit tests in general, refer to
+	  the KUnit documentation in Documentation/dev-tools/kunit/.
+
+	  If unsure, say N.
+
 config PCI_LABEL
 	def_bool y if (DMI || ACPI)
 	select NLS
diff --git a/drivers/pci/Makefile b/drivers/pci/Makefile
index 41ebc3b9a51824..6305d128d3dff2 100644
--- a/drivers/pci/Makefile
+++ b/drivers/pci/Makefile
@@ -31,6 +31,7 @@ obj-$(CONFIG_PCI_STUB)		+= pci-stub.o
 obj-$(CONFIG_PCI_PF_STUB)	+= pci-pf-stub.o
 obj-$(CONFIG_PCI_ECAM)		+= ecam.o
 obj-$(CONFIG_PCI_P2PDMA)	+= p2pdma.o
+obj-$(CONFIG_PCI_ACS_KUNIT_TEST) += pci_acs_test.o
 obj-$(CONFIG_XEN_PCIDEV_FRONTEND) += xen-pcifront.o
 obj-$(CONFIG_VGA_ARB)		+= vgaarb.o
 obj-$(CONFIG_PCI_DOE)		+= doe.o
diff --git a/drivers/pci/p2pdma.c b/drivers/pci/p2pdma.c
index 45260423dfb092..a0f572e117d8dc 100644
--- a/drivers/pci/p2pdma.c
+++ b/drivers/pci/p2pdma.c
@@ -21,9 +21,12 @@
 #include <linux/seq_buf.h>
 #include <linux/xarray.h>
 
+#include "pci.h"
+
 struct pci_p2pdma {
 	struct gen_pool *pool;
 	bool p2pmem_published;
+	bool ats_per_mapping;
 	struct xarray map_types;
 	struct p2pdma_provider mem[PCI_STD_NUM_BARS];
 };
@@ -491,25 +494,304 @@ static struct pci_dev *find_parent_pci_dev(struct device *dev)
 }
 
 /*
- * Check if a PCI bridge has its ACS redirection bits set to redirect P2P
- * TLPs upstream via ACS. Returns 1 if the packets will be redirected
- * upstream, 0 otherwise.
+ * Some ports send peer-to-peer traffic upstream without a standard ACS
+ * capability, such as Zhaoxin Root and Switch Downstream Ports. Their
+ * device-specific ACS quirks say so. Report whether @pdev's quirk says that
+ * @flag is in effect.
+ *
+ * Only ask bridges. The quirks for multi-function endpoints only say that
+ * their functions do not talk to each other directly, which says nothing
+ * about their traffic to other devices. Skip bridges on a root bus too. They
+ * never decide whether two peers connect directly, and for them the AMD
+ * southbridge quirk calls acpi_get_table(), which may sleep. DMA mapping may
+ * call this code where sleeping is not allowed.
  */
-static int pci_bridge_has_acs_redir(struct pci_dev *pdev)
+static bool pci_acs_p2pdma_quirk(struct pci_dev *pdev, u16 flag)
 {
-	int pos;
-	u16 ctrl;
+	if (!pci_is_bridge(pdev) || pci_is_root_bus(pdev->bus))
+		return false;
+
+	return pci_dev_specific_acs_enabled(pdev, flag) > 0;
+}
+
+/*
+ * Add the Request and Completion Redirect that @pdev's quirk reports to its
+ * ACS Control value. Only ever add them: a quirk that covers every device of
+ * a vendor says "no" for the ones it does not know, and that must not hide
+ * their own ACS controls. What a quirk says about other controls only means
+ * that the control does not apply, so ignore it.
+ */
+static u16 pci_acs_p2pdma_quirk_redirect(struct pci_dev *pdev, u16 ctrl)
+{
+	if (pci_acs_p2pdma_quirk(pdev, PCI_ACS_RR))
+		ctrl |= PCI_ACS_RR;
+	if (pci_acs_p2pdma_quirk(pdev, PCI_ACS_CR))
+		ctrl |= PCI_ACS_CR;
+
+	return ctrl;
+}
+
+/*
+ * Decide how a peer-to-peer Request at an ACS-capable ingress port routes,
+ * from that port's ACS Control register and the Request's Address Type.
+ *
+ * Linux does not read the Egress Control Vector, so Egress Control is treated
+ * conservatively as a redirect. Per PCIe r7.0 Table 6-11 the outcomes it
+ * selects are a direct route and an ACS Violation, and neither one lets peer
+ * bus addressing be assumed.
+ */
+VISIBLE_IF_KUNIT enum pci_acs_p2pdma_state
+pci_acs_p2pdma_request(u16 ctrl, unsigned int tlp_flags)
+{
+	if (tlp_flags & PCI_P2PDMA_TLP_TRANSLATED) {
+		/*
+		 * PCIe r7.0 sec 6.12.1.1: Translation Blocking makes every
+		 * Upstream Memory Request whose Address Type is not
+		 * Untranslated an ACS Violation, taking precedence over the
+		 * P2P controls. Sec 7.7.12.5: Direct Translated P2P "is
+		 * ignored if ACS Translation Blocking Enable is 1b".
+		 */
+		if (ctrl & PCI_ACS_TB)
+			return PCI_ACS_P2PDMA_BLOCKED;
+
+		/*
+		 * PCIe r7.0 sec 6.12.3: ACS Direct Translated P2P routes a
+		 * Request carrying a Translated address to the peer "without
+		 * redirection, regardless of ACS P2P Request Redirect and ACS
+		 * P2P Egress Control settings".
+		 */
+		if (ctrl & PCI_ACS_DT)
+			return PCI_ACS_P2PDMA_DIRECT;
+	}
+
+	return ctrl & (PCI_ACS_RR | PCI_ACS_EC) ?
+		PCI_ACS_P2PDMA_REDIRECT : PCI_ACS_P2PDMA_DIRECT;
+}
+EXPORT_SYMBOL_IF_KUNIT(pci_acs_p2pdma_request);
+
+/*
+ * Decide how a peer-to-peer Completion at an ACS-capable ingress port routes.
+ * PCIe r7.0 sec 6.12.1.1: no ACS control other than P2P Completion Redirect
+ * affects a Completion, and that one leaves Completions carrying the Relaxed
+ * Ordering attribute alone.
+ */
+VISIBLE_IF_KUNIT enum pci_acs_p2pdma_state
+pci_acs_p2pdma_completion(u16 ctrl, unsigned int tlp_flags)
+{
+	if (tlp_flags & PCI_P2PDMA_TLP_RELAXED_CPL)
+		return PCI_ACS_P2PDMA_DIRECT;
+
+	return ctrl & PCI_ACS_CR ? PCI_ACS_P2PDMA_REDIRECT :
+				   PCI_ACS_P2PDMA_DIRECT;
+}
+EXPORT_SYMBOL_IF_KUNIT(pci_acs_p2pdma_completion);
+
+static const char *pci_acs_p2pdma_state_name(enum pci_acs_p2pdma_state state)
+{
+	switch (state) {
+	case PCI_ACS_P2PDMA_DIRECT:
+		return "direct";
+	case PCI_ACS_P2PDMA_REDIRECT:
+		return "redirect";
+	case PCI_ACS_P2PDMA_BLOCKED:
+		return "blocked";
+	case PCI_ACS_P2PDMA_NOT_SUPPORTED:
+		return "not-supported";
+	}
+
+	return "invalid";
+}
+
+static const char *pci_p2pdma_map_type_name(enum pci_p2pdma_map_type type)
+{
+	switch (type) {
+	case PCI_P2PDMA_MAP_UNKNOWN:
+		return "unknown";
+	case PCI_P2PDMA_MAP_NONE:
+		return "none";
+	case PCI_P2PDMA_MAP_NOT_SUPPORTED:
+		return "not-supported";
+	case PCI_P2PDMA_MAP_BUS_ADDR:
+		return "bus-address";
+	case PCI_P2PDMA_MAP_THRU_HOST_BRIDGE:
+		return "through-host-bridge";
+	}
+
+	return "invalid";
+}
+
+/*
+ * Read @pdev's ACS Control register, with Request and Completion Redirect
+ * taken from its ACS quirk if it has one. A device with neither has no
+ * peer-to-peer controls at all. Whether functions can route internally is
+ * checked separately. Returns false when the register cannot be read, or
+ * reads as all ones, which is what a device that does not answer returns;
+ * @ctrl is then meaningless.
+ */
+static bool pci_acs_p2pdma_ctrl(struct pci_dev *pdev, const char *what,
+				u16 *ctrl, bool verbose)
+{
+	int pos, ret;
 
 	pos = pdev->acs_cap;
-	if (!pos)
-		return 0;
+	if (!pos) {
+		if (verbose)
+			pci_dbg(pdev,
+				"P2PDMA ACS: %s has no ACS capability\n", what);
+		*ctrl = pci_acs_p2pdma_quirk_redirect(pdev, 0);
+		return true;
+	}
 
-	pci_read_config_word(pdev, pos + PCI_ACS_CTRL, &ctrl);
+	ret = pci_dev_specific_read_acs_ctrl(pdev, ctrl);
+	if (ret == -ENOTTY)
+		ret = pci_read_config_word(pdev, pos + PCI_ACS_CTRL, ctrl);
+	if (ret || PCI_POSSIBLE_ERROR(*ctrl)) {
+		if (verbose)
+			pci_dbg(pdev,
+				"P2PDMA ACS: %s ACS Control read failed: cap=%#x status=%#x value=%#06x\n",
+				 what, pos, ret, *ctrl);
+		return false;
+	}
 
-	if (ctrl & (PCI_ACS_RR | PCI_ACS_CR | PCI_ACS_EC))
-		return 1;
+	*ctrl = pci_acs_p2pdma_quirk_redirect(pdev, *ctrl);
+	if (verbose) {
+		pci_dbg(pdev,
+			 "P2PDMA ACS: %s cap=%#x caps=%#06x ctrl=%#06x\n",
+			 what, pos, pdev->acs_capabilities, *ctrl);
+		pci_dbg(pdev,
+			 "P2PDMA ACS: control bits SV=%u TB=%u RR=%u CR=%u UF=%u EC=%u DT=%u\n",
+			 !!(*ctrl & PCI_ACS_SV), !!(*ctrl & PCI_ACS_TB),
+			 !!(*ctrl & PCI_ACS_RR), !!(*ctrl & PCI_ACS_CR),
+			 !!(*ctrl & PCI_ACS_UF), !!(*ctrl & PCI_ACS_EC),
+			 !!(*ctrl & PCI_ACS_DT));
+	}
 
-	return 0;
+	return true;
+}
+
+static bool pci_acs_p2pdma_downstream_port(struct pci_dev *pdev)
+{
+	return pci_is_pcie(pdev) &&
+		(pci_pcie_type(pdev) == PCI_EXP_TYPE_ROOT_PORT ||
+		 pci_pcie_type(pdev) == PCI_EXP_TYPE_DOWNSTREAM);
+}
+
+/*
+ * Only use this for functions sharing a PCIe link. An absent RR or CR
+ * capability means that the corresponding internal peer route does not
+ * exist, rather than that a programmable redirect is disabled. Likewise,
+ * SR-IOV functions that support internal peer traffic must implement ACS.
+ * Use each VF's own capability, not its PF's.
+ */
+static bool pci_acs_p2pdma_no_internal_route(struct pci_dev *pdev, u16 flag)
+{
+	if (pci_dev_specific_acs_enabled(pdev, flag) > 0)
+		return true;
+
+	if (pdev->acs_cap)
+		return !(pdev->acs_capabilities & flag);
+
+	return pdev->is_physfn || pdev->is_virtfn;
+}
+
+/*
+ * Traffic redirected above the divergence has the same ingress and egress
+ * at every shared Downstream Port. ACS Upstream Forwarding must carry it
+ * toward the host instead of back down that link. Missing UF support does
+ * not establish a forwarding route, even though it satisfies an isolation
+ * query. Report unreadable controls separately from missing forwarding.
+ */
+static struct pci_dev *
+pci_acs_p2pdma_no_upstream_forwarding(struct pci_dev *common,
+				    struct pci_dev **unreadable, bool verbose)
+{
+	struct pci_dev *pdev;
+	u16 ctrl;
+
+	for (pdev = common; pdev; pdev = pci_upstream_bridge(pdev)) {
+		if (!pci_acs_p2pdma_downstream_port(pdev))
+			continue;
+
+		if (!pci_acs_p2pdma_ctrl(pdev, "upstream forwarding", &ctrl,
+					 verbose)) {
+			*unreadable = pdev;
+			return NULL;
+		}
+
+		/*
+		 * Include Root Ports here. The PCIe port type check excludes
+		 * the legacy AMD southbridge quirk, which may sleep.
+		 */
+		if (pci_dev_specific_acs_enabled(pdev, PCI_ACS_UF) > 0)
+			continue;
+
+		if (!(pdev->acs_cap && pdev->acs_capabilities & ctrl & PCI_ACS_UF))
+			return pdev;
+	}
+
+	return NULL;
+}
+
+static void pci_p2pdma_log_path(const char *name, struct pci_dev *start,
+				struct pci_dev *common)
+{
+	struct pci_dev *pdev, *upstream;
+	int hop = 0, type;
+
+	for (pdev = start; pdev; pdev = upstream, hop++) {
+		upstream = pci_upstream_bridge(pdev);
+		type = pci_is_pcie(pdev) ? pci_pcie_type(pdev) : -1;
+		pci_dbg(pdev,
+			 "P2PDMA ACS: %s path hop=%d common=%u pcie=%u type=%d class=%#08x vendor=%04x device=%04x upstream=%s\n",
+			 name, hop, pdev == common, pci_is_pcie(pdev), type,
+			 pdev->class, pdev->vendor, pdev->device,
+			 upstream ? pci_name(upstream) : "<none>");
+
+		/* Cached state only: the routing logs the ACS Control it reads. */
+		if (pdev->acs_cap)
+			pci_dbg(pdev, "P2PDMA ACS: ACS cap=%#x caps=%#06x\n",
+				 pdev->acs_cap, pdev->acs_capabilities);
+		else
+			pci_dbg(pdev, "P2PDMA ACS: ACS capability absent\n");
+	}
+}
+
+/*
+ * Report whether any port between @client and @common rejects Translated
+ * addresses. If @common is NULL, every port up to the host bridge is walked.
+ * A port whose ACS Control cannot be read counts as blocking, which withdraws
+ * only the Translated classes because an Untranslated Request is routed by the
+ * redirect controls instead.
+ */
+static bool pci_p2pdma_path_blocks_translation(struct pci_dev *client,
+					       struct pci_dev *common,
+					       bool verbose)
+{
+	struct pci_dev *pdev;
+	u16 ctrl;
+
+	/*
+	 * @common is @client itself when the provider is the client or sits
+	 * below it. The Request never travels upstream then, so no port sees
+	 * it and none can reject its Address Type.
+	 */
+	if (client == common)
+		return false;
+
+	for (pdev = pci_upstream_bridge(client); pdev && pdev != common;
+	     pdev = pci_upstream_bridge(pdev)) {
+		if (!pci_acs_p2pdma_ctrl(pdev, "path hop", &ctrl, verbose))
+			return true;
+
+		if (ctrl & PCI_ACS_TB) {
+			if (verbose)
+				pci_dbg(pdev,
+					"P2PDMA ACS: Translation Blocking rejects Translated Requests on this path\n");
+			return true;
+		}
+	}
+
+	return false;
 }
 
 static void seq_buf_print_bus_devfn(struct seq_buf *buf, struct pci_dev *pdev)
@@ -520,6 +802,220 @@ static void seq_buf_print_bus_devfn(struct seq_buf *buf, struct pci_dev *pdev)
 	seq_buf_printf(buf, "%s;", pci_name(pdev));
 }
 
+/*
+ * Sort a port that redirects into @acs_list, the ports to suggest for
+ * pci=disable_acs_redir=, or @quirk_list. That parameter only clears the ACS
+ * Control register, so it cannot undo a redirect that a device quirk reports.
+ */
+static void pci_p2pdma_list_redir(struct seq_buf *acs_list,
+				  struct seq_buf *quirk_list,
+				  struct pci_dev *pdev)
+{
+	if (pci_acs_p2pdma_quirk(pdev, PCI_ACS_RR) ||
+	    pci_acs_p2pdma_quirk(pdev, PCI_ACS_CR))
+		seq_buf_print_bus_devfn(quirk_list, pdev);
+	else
+		seq_buf_print_bus_devfn(acs_list, pdev);
+}
+
+/* Drop the final semicolon. Returns false if no port was listed. */
+static bool pci_p2pdma_end_list(struct seq_buf *list)
+{
+	if (!seq_buf_used(list))
+		return false;
+
+	if (!seq_buf_has_overflowed(list))
+		list->buffer[list->len - 1] = '\0';
+	return true;
+}
+
+static void pci_p2pdma_warn_redir(struct pci_dev *client,
+				  struct pci_dev *provider,
+				  struct seq_buf *acs_list,
+				  struct seq_buf *quirk_list)
+{
+	pci_warn(client,
+		 "ACS redirect is set between the client and provider (%s)\n",
+		 pci_name(provider));
+	if (pci_p2pdma_end_list(quirk_list))
+		pci_warn(client,
+			 "hardware redirects peer-to-peer traffic at %s, which no kernel parameter changes\n",
+			 seq_buf_str(quirk_list));
+	if (pci_p2pdma_end_list(acs_list))
+		pci_warn(client,
+			 "to disable ACS controls for this path, add the kernel parameter: pci=disable_acs_redir=%s\n",
+			 seq_buf_str(acs_list));
+}
+
+/*
+ * What the topology walk found out about one provider/client path. Producing
+ * this costs a walk and config reads, none of which depends on the TLP being
+ * routed.
+ *
+ * @req_ctrl:	ACS Control of the Requester-side divergence port. That is the
+ *		first port at which a Request can route toward the peer rather
+ *		than upstream, so it is where the Request controls apply.
+ * @cpl_ctrl:	ACS Control of the Completer-side divergence port, likewise for
+ *		the Completions travelling back.
+ * @cpl_quirk:	A device quirk reports Completion Redirect at that port.
+ * @req_upstream: The Requester has no internal route to its sibling.
+ * @cpl_upstream: The Completer has no internal route to its sibling.
+ * @tb_on_path:	A port below the divergence blocks Translated addresses.
+ *		Every route out of @client passes those, so none carries them.
+ * @tb_above_divergence: A port at or above the divergence blocks Translated
+ *		addresses. Only a Request continuing to the host bridge passes
+ *		those, so a direct route is still open to them.
+ * @no_common_bridge: The two paths share no upstream bridge, so no direct
+ *		route exists for ACS to gate.
+ * @unreadable:	First port whose ACS Control could not be read, if any.
+ * @uf_blocked:	First shared port without usable Upstream Forwarding, if any.
+ * @uf_unreadable: Shared port whose forwarding control could not be read.
+ */
+struct pci_p2pdma_acs_path {
+	u16 req_ctrl;
+	u16 cpl_ctrl;
+	bool cpl_quirk;
+	bool req_upstream;
+	bool cpl_upstream;
+	bool tb_on_path;
+	bool tb_above_divergence;
+	bool no_common_bridge;
+	struct pci_dev *unreadable;
+	struct pci_dev *uf_blocked;
+	struct pci_dev *uf_unreadable;
+};
+
+/*
+ * ACS Translation Blocking is not a routing control, so unlike the redirect
+ * controls it is not decided at the divergence alone. PCIe r7.0 sec 6.12.1.1
+ * has every Downstream Port check the Address Type of each Upstream Memory
+ * Request it receives, ahead of "any applicable ACS P2P control mechanisms".
+ * A port below the divergence cannot redirect the Request anywhere it was not
+ * already going, but it can still reject a Translated address.
+ */
+static enum pci_acs_p2pdma_state
+pci_p2pdma_request_state(const struct pci_p2pdma_acs_path *path,
+			 unsigned int tlp_flags)
+{
+	if (tlp_flags & PCI_P2PDMA_TLP_TRANSLATED && path->tb_on_path)
+		return PCI_ACS_P2PDMA_BLOCKED;
+
+	if (path->req_upstream)
+		return PCI_ACS_P2PDMA_REDIRECT;
+
+	return pci_acs_p2pdma_request(path->req_ctrl, tlp_flags);
+}
+
+/*
+ * ACS P2P Completion Redirect leaves Relaxed Ordering Completions alone. A
+ * device quirk that reports Completion Redirect does not promise that, so
+ * treat every Completion through that port as redirected.
+ */
+static enum pci_acs_p2pdma_state
+pci_p2pdma_completion_state(const struct pci_p2pdma_acs_path *path,
+			    unsigned int tlp_flags)
+{
+	if (path->cpl_quirk || path->cpl_upstream)
+		return PCI_ACS_P2PDMA_REDIRECT;
+
+	return pci_acs_p2pdma_completion(path->cpl_ctrl, tlp_flags);
+}
+
+/*
+ * Combine both directions into a mapping type. Only a path that routes the
+ * Request and the Completions it generates directly can be programmed with
+ * the peer's bus addresses.
+ */
+static enum pci_p2pdma_map_type
+pci_p2pdma_route(const struct pci_p2pdma_acs_path *path,
+		 unsigned int tlp_flags)
+{
+	enum pci_acs_p2pdma_state req;
+
+	if (path->unreadable)
+		return PCI_P2PDMA_MAP_NOT_SUPPORTED;
+
+	req = pci_p2pdma_request_state(path, tlp_flags);
+
+	/*
+	 * Translation Blocking rejects the Address Type rather than the
+	 * target, so a blocked Request stays blocked however it is addressed.
+	 * No host bridge fallback keeps a Translated address working; the
+	 * caller has to issue a different kind of Request instead.
+	 */
+	if (req == PCI_ACS_P2PDMA_BLOCKED)
+		return PCI_P2PDMA_MAP_NOT_SUPPORTED;
+
+	if (!path->no_common_bridge && req == PCI_ACS_P2PDMA_DIRECT &&
+	    pci_p2pdma_completion_state(path, tlp_flags) ==
+		    PCI_ACS_P2PDMA_DIRECT)
+		return PCI_P2PDMA_MAP_BUS_ADDR;
+
+	if (path->uf_blocked || path->uf_unreadable)
+		return PCI_P2PDMA_MAP_NOT_SUPPORTED;
+
+	/*
+	 * A Request that turns around at the divergence never reaches the
+	 * ports above it, but one that keeps climbing to the host bridge
+	 * does, so that route has to clear their Translation Blocking too.
+	 */
+	if (tlp_flags & PCI_P2PDMA_TLP_TRANSLATED && path->tb_above_divergence)
+		return PCI_P2PDMA_MAP_NOT_SUPPORTED;
+
+	return PCI_P2PDMA_MAP_THRU_HOST_BRIDGE;
+}
+
+/*
+ * Name the ports that keep this path off a direct route, so that the admin
+ * can hand them to pci=disable_acs_redir=. That parameter clears the
+ * redirect controls, which decide the default class, so that is the class
+ * this reports on.
+ */
+static void pci_p2pdma_warn_path(struct pci_dev *client,
+				 struct pci_dev *provider,
+				 const struct pci_p2pdma_acs_path *path,
+				 struct pci_dev *a_child,
+				 struct pci_dev *b_child)
+{
+	struct seq_buf acs_list, quirk_list;
+	char buf[128], quirk_buf[64];
+
+	if (path->unreadable) {
+		pci_warn(client,
+			 "ACS Control is unreadable for provider %s at %s\n",
+			 pci_name(provider), pci_name(path->unreadable));
+		return;
+	}
+
+	if (path->uf_unreadable) {
+		pci_warn(client,
+			 "ACS Control is unreadable for provider %s at %s\n",
+			 pci_name(provider), pci_name(path->uf_unreadable));
+	} else if (path->uf_blocked) {
+		pci_warn(client,
+			 "cannot forward peer-to-peer DMA for provider %s upstream at %s\n",
+			 pci_name(provider), pci_name(path->uf_blocked));
+	}
+
+	if (path->req_upstream || path->cpl_upstream) {
+		pci_warn(client,
+			 "peer-to-peer DMA with provider %s requires the host bridge; no internal route between functions\n",
+			 pci_name(provider));
+		return;
+	}
+
+	seq_buf_init(&acs_list, buf, sizeof(buf));
+	seq_buf_init(&quirk_list, quirk_buf, sizeof(quirk_buf));
+	if (pci_acs_p2pdma_completion(path->cpl_ctrl, 0) !=
+	    PCI_ACS_P2PDMA_DIRECT)
+		pci_p2pdma_list_redir(&acs_list, &quirk_list, a_child);
+	if (pci_acs_p2pdma_request(path->req_ctrl, 0) != PCI_ACS_P2PDMA_DIRECT)
+		pci_p2pdma_list_redir(&acs_list, &quirk_list, b_child);
+
+	if (seq_buf_used(&acs_list) || seq_buf_used(&quirk_list))
+		pci_p2pdma_warn_redir(client, provider, &acs_list, &quirk_list);
+}
+
 static bool cpu_supports_p2pdma(void)
 {
 #ifdef CONFIG_X86
@@ -679,15 +1175,43 @@ static unsigned long map_types_idx(struct pci_dev *client)
 	return (pci_domain_nr(client->bus) << 16) | pci_dev_id(client);
 }
 
+/*
+ * One cache entry holds the routing of every TLP class, four bits each,
+ * indexed by the &enum pci_p2pdma_tlp_flags combination that selects it. An
+ * absent entry reads back as PCI_P2PDMA_MAP_UNKNOWN in every class.
+ */
+static_assert(PCI_P2PDMA_MAP_THRU_HOST_BRIDGE < 16);
+
+VISIBLE_IF_KUNIT unsigned long
+pci_p2pdma_map_types_pack(const enum pci_p2pdma_map_type *type)
+{
+	unsigned long val = 0;
+	unsigned int flags;
+
+	for (flags = 0; flags < PCI_P2PDMA_TLP_CLASSES; flags++)
+		val |= (unsigned long)type[flags] << (flags * 4);
+
+	return val;
+}
+EXPORT_SYMBOL_IF_KUNIT(pci_p2pdma_map_types_pack);
+
+VISIBLE_IF_KUNIT enum pci_p2pdma_map_type
+pci_p2pdma_map_types_unpack(unsigned long val, unsigned int tlp_flags)
+{
+	return (val >> (tlp_flags * 4)) & 0xf;
+}
+EXPORT_SYMBOL_IF_KUNIT(pci_p2pdma_map_types_unpack);
+
 /*
  * Calculate the P2PDMA mapping type and distance between two PCI devices.
  *
  * If the two devices are the same PCI function, return
  * PCI_P2PDMA_MAP_BUS_ADDR and a distance of 0.
  *
- * If they are two functions of the same device, return
- * PCI_P2PDMA_MAP_BUS_ADDR and a distance of 2 (one hop up to the bridge,
- * then one hop back down to another function of the same device).
+ * If they are two functions of the same device, return a distance of 2.
+ * A bus address requires an internal route between the functions. Otherwise,
+ * Upstream Forwarding must carry the traffic through their shared ports
+ * toward a supported host bridge.
  *
  * In the case where two devices are connected to the same PCIe switch,
  * return a distance of 4. This corresponds to the following PCI tree:
@@ -704,10 +1228,21 @@ static unsigned long map_types_idx(struct pci_dev *client)
  * then to Device B. The mapping type returned depends on the ACS
  * redirection setting of the ports along the path.
  *
- * If ACS redirect is set on any port in the path, traffic between the
- * devices will go through the host bridge, so return
- * PCI_P2PDMA_MAP_THRU_HOST_BRIDGE; otherwise return
- * PCI_P2PDMA_MAP_BUS_ADDR.
+ * The client is the Requester and the provider the Completer. At the path
+ * divergence, check Request Redirect, Egress Control and Direct Translated
+ * P2P on the Requester-side port, and Completion Redirect for read
+ * Completions on the Completer-side port. Translation Blocking is checked on
+ * every port the Request passes instead, because it rejects a Request rather
+ * than routing it.
+ *
+ * Those controls apply to different TLPs, so every class named by &enum
+ * pci_p2pdma_tlp_flags is decided from the one walk and cached together;
+ * @tlp_flags selects which one is returned.
+ *
+ * If ACS redirects traffic at either divergence port, return
+ * PCI_P2PDMA_MAP_THRU_HOST_BRIDGE. If the ACS Control register cannot be
+ * read, or Translation Blocking rejects the class being asked about, return
+ * PCI_P2PDMA_MAP_NOT_SUPPORTED. Otherwise, return PCI_P2PDMA_MAP_BUS_ADDR.
  *
  * Any two devices that have a data path that goes through the host bridge
  * will consult a whitelist. If the host bridge is in the whitelist, return
@@ -715,20 +1250,29 @@ static unsigned long map_types_idx(struct pci_dev *client)
  * ports per above. If the device is not in the whitelist, return
  * PCI_P2PDMA_MAP_NOT_SUPPORTED.
  */
-static enum pci_p2pdma_map_type
+VISIBLE_IF_KUNIT enum pci_p2pdma_map_type
 calc_map_type_and_dist(struct pci_dev *provider, struct pci_dev *client,
-		int *dist, bool verbose)
+		int *dist, unsigned int tlp_flags, bool verbose)
 {
-	enum pci_p2pdma_map_type map_type = PCI_P2PDMA_MAP_THRU_HOST_BRIDGE;
+	enum pci_p2pdma_map_type map_type[PCI_P2PDMA_TLP_CLASSES];
 	struct pci_dev *a = provider, *b = client, *bb;
+	struct pci_dev *a_child = NULL, *b_child = NULL;
+	struct pci_host_bridge *provider_host, *client_host;
+	struct pci_p2pdma_acs_path path = {};
 	struct pci_p2pdma *p2pdma;
-	struct seq_buf acs_list;
-	int acs_cnt = 0;
+	bool cpu_p2pdma, host_whitelisted = false;
+	bool cache_store = false;
+	bool host_fallback = false;
+	unsigned int flags;
 	int dist_a = 0;
 	int dist_b = 0;
-	char buf[128];
+	void *old;
 
-	seq_buf_init(&acs_list, buf, sizeof(buf));
+	if (verbose)
+		pci_dbg(client,
+			"P2PDMA ACS: begin provider=%s client=%s cache-index=%#lx\n",
+			 pci_name(provider), pci_name(client),
+			 map_types_idx(client));
 
 	/*
 	 * Note, we don't need to take references to devices returned by
@@ -737,77 +1281,245 @@ calc_map_type_and_dist(struct pci_dev *provider, struct pci_dev *client,
 	 */
 	while (a) {
 		dist_b = 0;
-
-		if (pci_bridge_has_acs_redir(a)) {
-			seq_buf_print_bus_devfn(&acs_list, a);
-			acs_cnt++;
-		}
-
+		b_child = NULL;
 		bb = b;
 
 		while (bb) {
 			if (a == bb)
-				goto check_b_path_acs;
+				goto check_paths_acs;
 
+			b_child = bb;
 			bb = pci_upstream_bridge(bb);
 			dist_b++;
 		}
 
+		a_child = a;
 		a = pci_upstream_bridge(a);
 		dist_a++;
 	}
 
+	/*
+	 * The paths share no upstream bridge, so there is no direct path for
+	 * ACS to gate: PCI_P2PDMA_MAP_BUS_ADDR is not reachable here and the
+	 * request can only get to the peer through the host bridge.
+	 */
 	*dist = dist_a + dist_b;
+	if (verbose) {
+		pci_dbg(client,
+			"P2PDMA ACS: no common upstream bridge provider-distance=%d client-distance=%d total=%d\n",
+			 dist_a, dist_b, *dist);
+		pci_p2pdma_log_path("provider", provider, NULL);
+		pci_p2pdma_log_path("client", client, NULL);
+	}
+	path.no_common_bridge = true;
+	path.tb_on_path = pci_p2pdma_path_blocks_translation(client, NULL,
+							     verbose);
+	for (flags = 0; flags < PCI_P2PDMA_TLP_CLASSES; flags++)
+		map_type[flags] = pci_p2pdma_route(&path, flags);
 	goto map_through_host_bridge;
 
-check_b_path_acs:
-	bb = b;
-
-	while (bb) {
-		if (a == bb)
-			break;
+check_paths_acs:
+	*dist = dist_a + dist_b;
+	if (verbose) {
+		pci_dbg(client,
+			"P2PDMA ACS: common=%s provider-divergence=%s client-divergence=%s provider-distance=%d client-distance=%d total=%d\n",
+			 pci_name(a),
+			 a_child ? pci_name(a_child) : "<none>",
+			 b_child ? pci_name(b_child) : "<none>",
+			 dist_a, dist_b, *dist);
+		pci_p2pdma_log_path("provider", provider, a);
+		pci_p2pdma_log_path("client", client, a);
+	}
 
-		if (pci_bridge_has_acs_redir(bb)) {
-			seq_buf_print_bus_devfn(&acs_list, bb);
-			acs_cnt++;
+	/*
+	 * ACS P2P routing controls apply where a TLP can route toward the peer
+	 * or upstream. Below that divergence, its only route toward the other
+	 * branch is upstream, so redirect controls do not affect the path.
+	 */
+	if (a_child && b_child) {
+		if (!pci_acs_p2pdma_ctrl(a_child, "completion", &path.cpl_ctrl,
+					 verbose))
+			path.unreadable = a_child;
+		path.cpl_quirk = pci_acs_p2pdma_quirk(a_child, PCI_ACS_CR);
+		if (!pci_acs_p2pdma_ctrl(b_child, "request", &path.req_ctrl,
+					 verbose) && !path.unreadable)
+			path.unreadable = b_child;
+		/*
+		 * Two children of one Downstream or Root Port share a link.
+		 * Use topology rather than slot numbers or the multifunction
+		 * bit, since ARI functions and VFs need not share those.
+		 */
+		if (pci_acs_p2pdma_downstream_port(a)) {
+			path.req_upstream =
+				pci_acs_p2pdma_no_internal_route(b_child, PCI_ACS_RR);
+			path.cpl_upstream =
+				pci_acs_p2pdma_no_internal_route(a_child, PCI_ACS_CR);
 		}
+		if (verbose && !path.unreadable)
+			pci_dbg(client,
+				"P2PDMA ACS: class=strict request=%s at %s completion=%s at %s\n",
+				 pci_acs_p2pdma_state_name(
+					 pci_p2pdma_request_state(&path, 0)),
+				 pci_name(b_child),
+				 pci_acs_p2pdma_state_name(
+					 pci_p2pdma_completion_state(&path, 0)),
+				 pci_name(a_child));
+	} else if (verbose) {
+		pci_dbg(client,
+			"P2PDMA ACS: peer divergence is incomplete; no ACS peer-routing controls evaluated\n");
+	}
 
-		bb = pci_upstream_bridge(bb);
+	path.tb_on_path = pci_p2pdma_path_blocks_translation(client, a,
+							     verbose);
+	if (b_child)
+		path.tb_above_divergence =
+			pci_p2pdma_path_blocks_translation(b_child, NULL,
+							   verbose);
+
+	/* Shared ports need forwarding only for classes using the host bridge. */
+	for (flags = 0; flags < PCI_P2PDMA_TLP_CLASSES; flags++) {
+		if (pci_p2pdma_route(&path, flags) !=
+		    PCI_P2PDMA_MAP_THRU_HOST_BRIDGE)
+			continue;
+		path.uf_blocked = pci_acs_p2pdma_no_upstream_forwarding(a,
+						&path.uf_unreadable, verbose);
+		break;
 	}
 
-	*dist = dist_a + dist_b;
+	/*
+	 * The walk and the config reads above serve every class; only the
+	 * decision below depends on the kind of TLP being routed.
+	 */
+	for (flags = 0; flags < PCI_P2PDMA_TLP_CLASSES; flags++) {
+		map_type[flags] = pci_p2pdma_route(&path, flags);
+		if (map_type[flags] == PCI_P2PDMA_MAP_THRU_HOST_BRIDGE)
+			host_fallback = true;
+	}
 
-	if (!acs_cnt) {
-		map_type = PCI_P2PDMA_MAP_BUS_ADDR;
+	if (verbose && map_type[0] != PCI_P2PDMA_MAP_BUS_ADDR)
+		pci_p2pdma_warn_path(client, provider, &path, a_child,
+				     b_child);
+
+	/*
+	 * Nothing needs the host bridge: the classes that did not get a direct
+	 * route have no fallback that would use it.
+	 */
+	if (!host_fallback)
 		goto done;
-	}
+
+map_through_host_bridge:
+	cpu_p2pdma = cpu_supports_p2pdma();
+	if (!cpu_p2pdma)
+		host_whitelisted = host_bridge_whitelist(provider, client,
+							  verbose);
 
 	if (verbose) {
-		/* Drop the final semicolon; the list is not empty here */
-		if (!seq_buf_has_overflowed(&acs_list))
-			acs_list.buffer[acs_list.len - 1] = '\0';
-		pci_warn(client, "ACS redirect is set between the client and provider (%s)\n",
-			 pci_name(provider));
-		pci_warn(client, "to disable ACS redirect for this path, add the kernel parameter: pci=disable_acs_redir=%s\n",
-			 seq_buf_str(&acs_list));
+		provider_host = pci_find_host_bridge(provider->bus);
+		client_host = pci_find_host_bridge(client->bus);
+		pci_dbg(client,
+			"P2PDMA ACS: host fallback cpu-support=%u whitelist=%s provider-host=%s client-host=%s same-host=%u\n",
+			 cpu_p2pdma,
+			 cpu_p2pdma ? "not-consulted" :
+					(host_whitelisted ? "yes" : "no"),
+			 provider_host ? dev_name(&provider_host->dev) : "<none>",
+			 client_host ? dev_name(&client_host->dev) : "<none>",
+			 provider_host && provider_host == client_host);
 	}
 
-map_through_host_bridge:
-	if (!cpu_supports_p2pdma() &&
-	    !host_bridge_whitelist(provider, client, verbose)) {
+	if (!cpu_p2pdma && !host_whitelisted) {
 		if (verbose)
 			pci_warn(client, "cannot be used for peer-to-peer DMA as the client and provider (%s) do not share an upstream bridge or whitelisted host bridge\n",
 				 pci_name(provider));
-		map_type = PCI_P2PDMA_MAP_NOT_SUPPORTED;
+		for (flags = 0; flags < PCI_P2PDMA_TLP_CLASSES; flags++)
+			if (map_type[flags] == PCI_P2PDMA_MAP_THRU_HOST_BRIDGE)
+				map_type[flags] = PCI_P2PDMA_MAP_NOT_SUPPORTED;
 	}
 done:
 	rcu_read_lock();
 	p2pdma = rcu_dereference(provider->p2pdma);
-	if (p2pdma)
-		xa_store(&p2pdma->map_types, map_types_idx(client),
-			 xa_mk_value(map_type), GFP_ATOMIC);
+	if (p2pdma) {
+		old = xa_store(&p2pdma->map_types, map_types_idx(client),
+			       xa_mk_value(pci_p2pdma_map_types_pack(map_type)),
+			       GFP_ATOMIC);
+		cache_store = !xa_is_err(old);
+	}
 	rcu_read_unlock();
-	return map_type;
+	if (verbose) {
+		pci_dbg(client,
+			"P2PDMA ACS: final provider=%s result=%s(%d) tlp-flags=%#x distance=%d unreadable=%s cache-store=%u index=%#lx\n",
+			 pci_name(provider),
+			 pci_p2pdma_map_type_name(map_type[tlp_flags]),
+			 map_type[tlp_flags], tlp_flags, *dist,
+			 path.unreadable ? pci_name(path.unreadable) : "<none>",
+			 cache_store, map_types_idx(client));
+		pci_dbg(client,
+			"P2PDMA ACS: classes strict=%s relaxed=%s translated=%s translated+relaxed=%s\n",
+			 pci_p2pdma_map_type_name(map_type[0]),
+			 pci_p2pdma_map_type_name(
+				 map_type[PCI_P2PDMA_TLP_RELAXED_CPL]),
+			 pci_p2pdma_map_type_name(
+				 map_type[PCI_P2PDMA_TLP_TRANSLATED]),
+			 pci_p2pdma_map_type_name(
+				 map_type[PCI_P2PDMA_TLP_TRANSLATED |
+					  PCI_P2PDMA_TLP_RELAXED_CPL]));
+	}
+	return map_type[tlp_flags];
+}
+EXPORT_SYMBOL_IF_KUNIT(calc_map_type_and_dist);
+
+VISIBLE_IF_KUNIT unsigned int
+pci_p2pdma_client_tlp_flags(struct pci_dev *client, unsigned int tlp_flags)
+{
+	if (client->ats_enabled)
+		return tlp_flags | PCI_P2PDMA_TLP_TRANSLATED;
+
+	return tlp_flags & ~PCI_P2PDMA_TLP_TRANSLATED;
+}
+EXPORT_SYMBOL_IF_KUNIT(pci_p2pdma_client_tlp_flags);
+
+/*
+ * A client that translates every address it is handed cannot be handed a bus
+ * address, which it would translate as though it were an IOVA. Its Translated
+ * Requests may still route directly, but a Request it issues without a
+ * translation carries the IOVA to the host bridge, so that route has to work
+ * as well.
+ *
+ * Take the Address Type from @tlp_flags rather than reading the ATS Enable
+ * bit again, so the policy and the class it applies to always agree.
+ */
+VISIBLE_IF_KUNIT enum pci_p2pdma_map_type
+pci_p2pdma_client_map_type(struct pci_dev *provider, struct pci_dev *client,
+			   bool per_mapping, unsigned int tlp_flags,
+			   enum pci_p2pdma_map_type type)
+{
+	if (per_mapping || !(tlp_flags & PCI_P2PDMA_TLP_TRANSLATED) ||
+	    type != PCI_P2PDMA_MAP_BUS_ADDR)
+		return type;
+
+	pci_dbg(client,
+		"P2PDMA ACS: provider=%s bus address withheld; ATS is enabled for the whole client\n",
+		 pci_name(provider));
+
+	if (cpu_supports_p2pdma() ||
+	    host_bridge_whitelist(provider, client, false))
+		return PCI_P2PDMA_MAP_THRU_HOST_BRIDGE;
+
+	return PCI_P2PDMA_MAP_NOT_SUPPORTED;
+}
+EXPORT_SYMBOL_IF_KUNIT(pci_p2pdma_client_map_type);
+
+/* Whether the driver of @client called pcim_p2pdma_set_ats_per_mapping(). */
+static bool pci_p2pdma_client_per_mapping(struct pci_dev *client)
+{
+	struct pci_p2pdma *p2pdma;
+	bool per_mapping;
+
+	rcu_read_lock();
+	p2pdma = rcu_dereference(client->p2pdma);
+	per_mapping = p2pdma && p2pdma->ats_per_mapping;
+	rcu_read_unlock();
+
+	return per_mapping;
 }
 
 /**
@@ -825,15 +1537,19 @@ calc_map_type_and_dist(struct pci_dev *provider, struct pci_dev *client,
  *
  * "compatible" means the provider and the clients are either all behind
  * the same PCI root port or the host bridges connected to each of the devices
- * are listed in the 'pci_p2pdma_whitelist'.
+ * are listed in the 'pci_p2pdma_whitelist'. Each client is judged the way
+ * pci_p2pdma_map_type() maps it, so one with ATS enabled for the whole device
+ * also needs a host bridge that supports peer-to-peer DMA.
  */
 int pci_p2pdma_distance_many(struct pci_dev *provider, struct device **clients,
 			     int num_clients, bool verbose)
 {
-	enum pci_p2pdma_map_type map;
+	enum pci_p2pdma_map_type map, type;
 	bool not_supported = false;
 	struct pci_dev *pci_client;
+	unsigned int tlp_flags;
 	int total_dist = 0;
+	bool per_mapping;
 	int i, distance;
 
 	if (num_clients == 0)
@@ -848,8 +1564,18 @@ int pci_p2pdma_distance_many(struct pci_dev *provider, struct device **clients,
 			return -1;
 		}
 
-		map = calc_map_type_and_dist(provider, pci_client, &distance,
-					     verbose);
+		per_mapping = pci_p2pdma_client_per_mapping(pci_client);
+		tlp_flags = per_mapping ? 0 :
+			    pci_p2pdma_client_tlp_flags(pci_client, 0);
+		type = calc_map_type_and_dist(provider, pci_client, &distance,
+					      tlp_flags, verbose);
+		map = pci_p2pdma_client_map_type(provider, pci_client,
+						 per_mapping, tlp_flags, type);
+		if (verbose && map != type &&
+		    map == PCI_P2PDMA_MAP_NOT_SUPPORTED)
+			pci_warn(pci_client,
+				 "cannot be used for peer-to-peer DMA with %s: ATS is enabled for the whole device and the host bridge is not whitelisted\n",
+				 pci_name(provider));
 
 		pci_dev_put(pci_client);
 
@@ -1114,44 +1840,121 @@ void pci_p2pmem_publish(struct pci_dev *pdev, bool publish)
 EXPORT_SYMBOL_GPL(pci_p2pmem_publish);
 
 /**
- * pci_p2pdma_map_type - Determine the mapping type for P2PDMA transfers
+ * pcim_p2pdma_set_ats_per_mapping - Declare per-mapping ATS for a client
+ * @pdev: PCI device that initiates peer-to-peer DMA
+ *
+ * Declare that @pdev issues Translated Requests only for the DMA mappings its
+ * driver sets up to use ATS, rather than for any address once ATS is enabled.
+ * P2PDMA then routes this client's Requests with the Address Type each query
+ * asks about, rather than the one its ATS Enable bit implies.
+ *
+ * Call it once pcim_p2pdma_init() has succeeded. Without P2PDMA state the
+ * declaration is dropped and the ATS Enable bit keeps deciding.
+ */
+void pcim_p2pdma_set_ats_per_mapping(struct pci_dev *pdev)
+{
+	struct pci_p2pdma *p2p;
+
+	p2p = rcu_dereference_protected(pdev->p2pdma, 1);
+	if (!p2p)
+		/*
+		 * ats_per_mapping is a performance optimization,
+		 * if pcim_p2pdma_init() didn't set pdev->p2pdma pointer
+		 * for some reason, let's simply use ATS global settings.
+		 */
+		return;
+
+	p2p->ats_per_mapping = true;
+}
+EXPORT_SYMBOL_GPL(pcim_p2pdma_set_ats_per_mapping);
+
+/**
+ * pci_p2pdma_map_type_tlp - Determine the mapping type for P2PDMA transfers
  * @provider: P2PDMA provider structure
- * @dev: Target device for the transfer
+ * @dev: Client device that initiates the transfer
+ * @tlp_flags: &enum pci_p2pdma_tlp_flags describing the TLPs @dev will issue
  *
  * Determines how peer-to-peer DMA transfers should be mapped between
- * the provider and the target device. The mapping type indicates whether
+ * the provider and the client device. The mapping type indicates whether
  * the transfer can be done directly through PCI switches or must go
  * through the host bridge.
+ *
+ * ACS routes a peer-to-peer transaction by the attributes its TLPs carry, so
+ * the answer depends on @tlp_flags. A caller that passes flags its traffic
+ * does not match gets a mapping the fabric will not deliver.
+ *
+ * Only a client whose driver called pcim_p2pdma_set_ats_per_mapping() takes
+ * the Address Type from @tlp_flags. For any other client its ATS Enable bit
+ * decides, and a client that translates every address it is handed never gets
+ * %PCI_P2PDMA_MAP_BUS_ADDR.
  */
-enum pci_p2pdma_map_type pci_p2pdma_map_type(struct p2pdma_provider *provider,
-					     struct device *dev)
+static enum pci_p2pdma_map_type
+pci_p2pdma_map_type_tlp(struct p2pdma_provider *provider, struct device *dev,
+			unsigned int tlp_flags)
 {
-	enum pci_p2pdma_map_type type = PCI_P2PDMA_MAP_NOT_SUPPORTED;
 	struct pci_dev *pdev = to_pci_dev(provider->owner);
-	struct pci_dev *client;
+	unsigned long cache_index, cached = 0;
+	enum pci_p2pdma_map_type type;
 	struct pci_p2pdma *p2pdma;
+	struct pci_dev *client;
+	bool provider_state;
+	bool per_mapping;
 	int dist;
 
-	if (!pdev->p2pdma)
+	if (!pdev->p2pdma) {
+		pci_dbg(pdev,
+			"P2PDMA ACS: map lookup rejected; provider state is absent\n");
 		return PCI_P2PDMA_MAP_NOT_SUPPORTED;
+	}
 
-	if (!dev_is_pci(dev))
+	if (!dev_is_pci(dev)) {
+		dev_dbg(dev,
+			"P2PDMA ACS: provider=%s map lookup rejected; client is not PCI\n",
+			 pci_name(pdev));
 		return PCI_P2PDMA_MAP_NOT_SUPPORTED;
+	}
 
 	client = to_pci_dev(dev);
+	cache_index = map_types_idx(client);
+	per_mapping = pci_p2pdma_client_per_mapping(client);
+	if (!per_mapping)
+		tlp_flags = pci_p2pdma_client_tlp_flags(client, tlp_flags);
 
 	rcu_read_lock();
 	p2pdma = rcu_dereference(pdev->p2pdma);
 
 	if (p2pdma)
-		type = xa_to_value(xa_load(&p2pdma->map_types,
-					   map_types_idx(client)));
+		cached = xa_to_value(xa_load(&p2pdma->map_types,
+					     cache_index));
+	provider_state = !!p2pdma;
 	rcu_read_unlock();
+	type = pci_p2pdma_map_types_unpack(cached, tlp_flags);
+	pci_dbg(client,
+		 "P2PDMA ACS: map lookup provider=%s index=%#lx tlp-flags=%#x cached=%s(%d) provider-state=%u\n",
+		 pci_name(pdev), cache_index, tlp_flags,
+		 pci_p2pdma_map_type_name(type), type, provider_state);
 
 	if (type == PCI_P2PDMA_MAP_UNKNOWN)
-		return calc_map_type_and_dist(pdev, client, &dist, true);
+		type = calc_map_type_and_dist(pdev, client, &dist, tlp_flags,
+					      true);
+
+	return pci_p2pdma_client_map_type(pdev, client, per_mapping, tlp_flags,
+					  type);
+}
 
-	return type;
+/**
+ * pci_p2pdma_map_type - Determine the mapping type for P2PDMA transfers
+ * @provider: P2PDMA provider structure
+ * @dev: Client device that initiates the transfer
+ *
+ * Same as pci_p2pdma_map_type_tlp() for a client issuing strictly ordered
+ * Requests. Their Address Type is Untranslated unless the client enables ATS
+ * for the whole device.
+ */
+enum pci_p2pdma_map_type pci_p2pdma_map_type(struct p2pdma_provider *provider,
+					     struct device *dev)
+{
+	return pci_p2pdma_map_type_tlp(provider, dev, 0);
 }
 
 void __pci_p2pdma_update_state(struct pci_p2pdma_map_state *state,
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index 7c6f2aba81443d..930c35fcca695b 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -3611,7 +3611,8 @@ void pci_configure_ari(struct pci_dev *dev)
 	}
 }
 
-static bool pci_acs_flags_enabled(struct pci_dev *pdev, u16 acs_flags)
+VISIBLE_IF_KUNIT
+bool pci_acs_flags_enabled(struct pci_dev *pdev, u16 acs_flags)
 {
 	int pos;
 	u16 ctrl;
@@ -3627,9 +3628,12 @@ static bool pci_acs_flags_enabled(struct pci_dev *pdev, u16 acs_flags)
 	 */
 	acs_flags &= (pdev->acs_capabilities | PCI_ACS_EC);
 
-	pci_read_config_word(pdev, pos + PCI_ACS_CTRL, &ctrl);
+	if (pci_read_config_word(pdev, pos + PCI_ACS_CTRL, &ctrl) ||
+	    PCI_POSSIBLE_ERROR(ctrl))
+		return false;
 	return (ctrl & acs_flags) == acs_flags;
 }
+EXPORT_SYMBOL_IF_KUNIT(pci_acs_flags_enabled);
 
 /**
  * pci_acs_enabled - test ACS against required flags for a given device
diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
index 77efa4c5c960e7..70fc29c42c274e 100644
--- a/drivers/pci/pci.h
+++ b/drivers/pci/pci.h
@@ -2,10 +2,12 @@
 #ifndef DRIVERS_PCI_H
 #define DRIVERS_PCI_H
 
+#include <kunit/visibility.h>
 #include <linux/bug.h>
 #include <linux/align.h>
 #include <linux/bitfield.h>
 #include <linux/pci.h>
+#include <linux/pci-p2pdma.h>
 #include <trace/events/pci.h>
 
 struct pcie_tlp_log;
@@ -1099,13 +1101,74 @@ resource_size_t pci_min_window_alignment(struct pci_bus *bus,
 
 void pci_acs_init(struct pci_dev *dev);
 void pci_enable_acs(struct pci_dev *dev);
+
+/**
+ * enum pci_p2pdma_tlp_flags - Properties of the TLPs a client will issue
+ *
+ * These describe the traffic rather than the topology, and select which ACS
+ * controls apply along the peer-to-peer path. A value of 0 means strictly
+ * ordered Requests carrying an Untranslated address.
+ *
+ * @PCI_P2PDMA_TLP_TRANSLATED: Requests carry an ATS Translated address. PCIe
+ *	r7.0 sec 6.12.3 routes those to the peer regardless of ACS P2P Request
+ *	Redirect and ACS P2P Egress Control wherever ACS Direct Translated P2P
+ *	is enabled.
+ * @PCI_P2PDMA_TLP_RELAXED_CPL: Non-Posted Requests carry the Relaxed
+ *	Ordering attribute, and PCIe r7.0 sec 2.2.9.1 requires the Completer to
+ *	return it in their Completions. Sec 6.12.1.1 never redirects those, so
+ *	ACS P2P Completion Redirect does not gate the path.
+ */
+enum pci_p2pdma_tlp_flags {
+	PCI_P2PDMA_TLP_TRANSLATED	= 1 << 0,
+	PCI_P2PDMA_TLP_RELAXED_CPL	= 1 << 1,
+};
+
+/* Every combination of the flags above selects one routing class. */
+#define PCI_P2PDMA_TLP_CLASSES \
+	((PCI_P2PDMA_TLP_TRANSLATED | PCI_P2PDMA_TLP_RELAXED_CPL) + 1)
+
+enum pci_acs_p2pdma_state {
+	PCI_ACS_P2PDMA_NOT_SUPPORTED,
+	PCI_ACS_P2PDMA_DIRECT,
+	PCI_ACS_P2PDMA_REDIRECT,
+	PCI_ACS_P2PDMA_BLOCKED,
+};
+
+#if IS_ENABLED(CONFIG_KUNIT)
+bool pci_acs_flags_enabled(struct pci_dev *pdev, u16 acs_flags);
+enum pci_acs_p2pdma_state pci_acs_p2pdma_request(u16 ctrl,
+						unsigned int tlp_flags);
+enum pci_acs_p2pdma_state pci_acs_p2pdma_completion(u16 ctrl,
+						    unsigned int tlp_flags);
+unsigned long pci_p2pdma_map_types_pack(const enum pci_p2pdma_map_type *type);
+enum pci_p2pdma_map_type pci_p2pdma_map_types_unpack(unsigned long val,
+						     unsigned int tlp_flags);
+enum pci_p2pdma_map_type calc_map_type_and_dist(struct pci_dev *provider,
+						struct pci_dev *client,
+						int *dist,
+						unsigned int tlp_flags,
+						bool verbose);
+unsigned int pci_p2pdma_client_tlp_flags(struct pci_dev *client,
+					 unsigned int tlp_flags);
+enum pci_p2pdma_map_type
+pci_p2pdma_client_map_type(struct pci_dev *provider, struct pci_dev *client,
+			   bool per_mapping, unsigned int tlp_flags,
+			   enum pci_p2pdma_map_type type);
+#endif
+
 #ifdef CONFIG_PCI_QUIRKS
+int pci_dev_specific_read_acs_ctrl(struct pci_dev *dev, u16 *ctrl);
 int pci_dev_specific_acs_enabled(struct pci_dev *dev, u16 acs_flags);
 int pci_dev_specific_enable_acs(struct pci_dev *dev);
 int pci_dev_specific_disable_acs_redir(struct pci_dev *dev);
 void pci_disable_broken_acs_cap(struct pci_dev *pdev);
 int pcie_failed_link_retrain(struct pci_dev *dev);
 #else
+static inline int pci_dev_specific_read_acs_ctrl(struct pci_dev *dev, u16 *ctrl)
+{
+	return -ENOTTY;
+}
+
 static inline int pci_dev_specific_acs_enabled(struct pci_dev *dev,
 					       u16 acs_flags)
 {
diff --git a/drivers/pci/pci_acs_test.c b/drivers/pci/pci_acs_test.c
new file mode 100644
index 00000000000000..b0e5e2eac97ccd
--- /dev/null
+++ b/drivers/pci/pci_acs_test.c
@@ -0,0 +1,1409 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * KUnit tests for PCI ACS peer-to-peer routing decisions.
+ *
+ * These exercise Request and Completion routing independently of the ACS
+ * settings exposed by available PCIe hardware.
+ */
+#include <kunit/test.h>
+
+#include <linux/pci.h>
+#include <linux/pci-p2pdma.h>
+#include <linux/pci_regs.h>
+
+#include "pci.h"
+
+struct acs_decision_case {
+	const char *desc;
+	u16 ctrl;
+	unsigned int tlp_flags;
+	enum pci_acs_p2pdma_state expect;
+};
+
+/* Shorthands to keep the tables below readable. */
+#define ACS_DIRECT	PCI_ACS_P2PDMA_DIRECT
+#define ACS_REDIR	PCI_ACS_P2PDMA_REDIRECT
+#define ACS_RO		PCI_P2PDMA_TLP_RELAXED_CPL
+#define ACS_AT		PCI_P2PDMA_TLP_TRANSLATED
+#define ACS_BLOCK	PCI_ACS_P2PDMA_BLOCKED
+
+/* Request routing ignores Completion Redirect. */
+static const struct acs_decision_case acs_request_cases[] = {
+	{ "req/none", 0, 0, ACS_DIRECT },
+	{ "req/rr", PCI_ACS_RR, 0, ACS_REDIR },
+	{ "req/cr", PCI_ACS_CR, 0, ACS_DIRECT },
+	{ "req/rr_cr", PCI_ACS_RR | PCI_ACS_CR, 0, ACS_REDIR },
+	{ "req/ec", PCI_ACS_EC, 0, ACS_REDIR },
+	{ "req/ec_cr", PCI_ACS_EC | PCI_ACS_CR, 0, ACS_REDIR },
+
+	/*
+	 * Direct Translated P2P overrides the redirect controls, but only for
+	 * a Request that actually carries a Translated address.
+	 */
+	{ "req/dt", PCI_ACS_DT, 0, ACS_DIRECT },
+	{ "req/dt_rr", PCI_ACS_DT | PCI_ACS_RR, 0, ACS_REDIR },
+	{ "req/at", 0, ACS_AT, ACS_DIRECT },
+	{ "req/at_rr", PCI_ACS_RR, ACS_AT, ACS_REDIR },
+	{ "req/at_dt", PCI_ACS_DT, ACS_AT, ACS_DIRECT },
+	{ "req/at_dt_rr", PCI_ACS_DT | PCI_ACS_RR, ACS_AT, ACS_DIRECT },
+	{ "req/at_dt_ec", PCI_ACS_DT | PCI_ACS_EC, ACS_AT, ACS_DIRECT },
+
+	/*
+	 * Translation Blocking rejects a Translated address outright, and
+	 * makes the port ignore Direct Translated P2P.
+	 */
+	{ "req/tb", PCI_ACS_TB, 0, ACS_DIRECT },
+	{ "req/tb_rr", PCI_ACS_TB | PCI_ACS_RR, 0, ACS_REDIR },
+	{ "req/at_tb", PCI_ACS_TB, ACS_AT, ACS_BLOCK },
+	{ "req/at_tb_dt", PCI_ACS_TB | PCI_ACS_DT, ACS_AT, ACS_BLOCK },
+};
+
+/* Completion routing depends only on Completion Redirect. */
+static const struct acs_decision_case acs_completion_cases[] = {
+	{ "cpl/none", 0, 0, ACS_DIRECT },
+	{ "cpl/rr", PCI_ACS_RR, 0, ACS_DIRECT },
+	{ "cpl/cr", PCI_ACS_CR, 0, ACS_REDIR },
+	{ "cpl/rr_cr", PCI_ACS_RR | PCI_ACS_CR, 0, ACS_REDIR },
+	{ "cpl/ec", PCI_ACS_EC, 0, ACS_DIRECT },
+	{ "cpl/ec_cr", PCI_ACS_EC | PCI_ACS_CR, 0, ACS_REDIR },
+
+	/* Relaxed Ordering Completions are never redirected. */
+	{ "cpl/ro", 0, ACS_RO, ACS_DIRECT },
+	{ "cpl/ro_cr", PCI_ACS_CR, ACS_RO, ACS_DIRECT },
+	{ "cpl/ro_rr_cr", PCI_ACS_RR | PCI_ACS_CR, ACS_RO, ACS_DIRECT },
+};
+
+#undef ACS_DIRECT
+#undef ACS_REDIR
+#undef ACS_RO
+#undef ACS_AT
+#undef ACS_BLOCK
+
+static void acs_decision_desc(const struct acs_decision_case *c, char *desc)
+{
+	strscpy(desc, c->desc, KUNIT_PARAM_DESC_SIZE);
+}
+
+KUNIT_ARRAY_PARAM(acs_request, acs_request_cases, acs_decision_desc);
+KUNIT_ARRAY_PARAM(acs_completion, acs_completion_cases, acs_decision_desc);
+
+static void pci_acs_p2pdma_request_test(struct kunit *test)
+{
+	const struct acs_decision_case *c = test->param_value;
+
+	KUNIT_EXPECT_EQ(test, pci_acs_p2pdma_request(c->ctrl, c->tlp_flags),
+			c->expect);
+}
+
+static void pci_acs_p2pdma_completion_test(struct kunit *test)
+{
+	const struct acs_decision_case *c = test->param_value;
+
+	KUNIT_EXPECT_EQ(test, pci_acs_p2pdma_completion(c->ctrl, c->tlp_flags),
+			c->expect);
+}
+
+/* Flags an IOMMU asks for; see REQ_ACS_FLAGS in drivers/iommu/iommu.c. */
+#define ACS_REQ_FLAGS	(PCI_ACS_SV | PCI_ACS_RR | PCI_ACS_CR | PCI_ACS_UF)
+#define ACS_ALL_CAPS	(PCI_ACS_SV | PCI_ACS_TB | PCI_ACS_RR | PCI_ACS_CR | \
+			 PCI_ACS_UF | PCI_ACS_DT)
+#define ACS_TEST_CAP	0x100
+
+struct acs_ctrl_cfg {
+	unsigned int devfn;
+	u16 cap;	/* Offset where the ACS capability responds */
+	u16 ctrl;
+	bool fail_read;
+};
+
+static int acs_ctrl_read(struct pci_bus *bus, unsigned int devfn,
+			 int where, int size, u32 *val)
+{
+	struct acs_ctrl_cfg *cfg = bus->sysdata;
+
+	*val = 0;
+	if (cfg->fail_read)
+		return PCIBIOS_DEVICE_NOT_FOUND;
+
+	if (devfn == cfg->devfn && size == 2 &&
+	    where == cfg->cap + PCI_ACS_CTRL)
+		*val = cfg->ctrl;
+	return PCIBIOS_SUCCESSFUL;
+}
+
+static int acs_ctrl_write(struct pci_bus *bus, unsigned int devfn,
+			  int where, int size, u32 val)
+{
+	return PCIBIOS_SUCCESSFUL;
+}
+
+static struct pci_ops acs_ctrl_ops = {
+	.read	= acs_ctrl_read,
+	.write	= acs_ctrl_write,
+};
+
+struct acs_isolation_case {
+	const char *desc;
+	u16 ctrl;
+	u16 req;
+	bool expect;
+};
+
+static const struct acs_isolation_case acs_isolation_cases[] = {
+	{ "all_enabled", ACS_REQ_FLAGS, ACS_REQ_FLAGS, true },
+	/* Translated Requests remain isolated by their IOMMU translation. */
+	{ "dt", ACS_REQ_FLAGS | PCI_ACS_DT, ACS_REQ_FLAGS, true },
+	{ "rr_not_enabled", PCI_ACS_SV | PCI_ACS_CR | PCI_ACS_UF,
+	  ACS_REQ_FLAGS, false },
+	{ "rr_not_required", PCI_ACS_SV | PCI_ACS_CR | PCI_ACS_UF,
+	  PCI_ACS_SV | PCI_ACS_CR | PCI_ACS_UF, true },
+};
+
+static void acs_isolation_desc(const struct acs_isolation_case *c, char *desc)
+{
+	strscpy(desc, c->desc, KUNIT_PARAM_DESC_SIZE);
+}
+
+KUNIT_ARRAY_PARAM(acs_isolation, acs_isolation_cases, acs_isolation_desc);
+
+static bool acs_isolated(struct kunit *test, struct acs_ctrl_cfg *cfg,
+			 u16 acs_flags)
+{
+	struct pci_bus *bus = kunit_kzalloc(test, sizeof(*bus), GFP_KERNEL);
+	struct pci_dev *pdev = kunit_kzalloc(test, sizeof(*pdev), GFP_KERNEL);
+
+	KUNIT_ASSERT_NOT_NULL(test, bus);
+	KUNIT_ASSERT_NOT_NULL(test, pdev);
+
+	bus->ops = &acs_ctrl_ops;
+	bus->sysdata = cfg;
+
+	pdev->bus = bus;
+	pdev->devfn = cfg->devfn;
+	pdev->acs_cap = cfg->cap;
+	pdev->acs_capabilities = ACS_ALL_CAPS;
+
+	return pci_acs_flags_enabled(pdev, acs_flags);
+}
+
+static void pci_acs_flags_enabled_test(struct kunit *test)
+{
+	const struct acs_isolation_case *c = test->param_value;
+	struct acs_ctrl_cfg cfg = {
+		.devfn = PCI_DEVFN(0, 0),
+		.cap = ACS_TEST_CAP,
+		.ctrl = c->ctrl,
+	};
+
+	KUNIT_EXPECT_EQ(test, acs_isolated(test, &cfg, c->req), c->expect);
+}
+
+static void pci_acs_flags_no_cap_test(struct kunit *test)
+{
+	struct acs_ctrl_cfg cfg = {
+		.devfn = PCI_DEVFN(0, 0),
+		.cap = 0,
+		.ctrl = ACS_REQ_FLAGS,
+	};
+
+	KUNIT_EXPECT_FALSE(test, acs_isolated(test, &cfg, ACS_REQ_FLAGS));
+}
+
+static void pci_acs_flags_read_fails_test(struct kunit *test)
+{
+	u16 no_rr = ACS_REQ_FLAGS & ~PCI_ACS_RR;
+	struct acs_ctrl_cfg cfg = {
+		.devfn = PCI_DEVFN(0, 0),
+		.cap = ACS_TEST_CAP,
+		.ctrl = ACS_REQ_FLAGS,
+	};
+
+	KUNIT_EXPECT_TRUE(test, acs_isolated(test, &cfg, no_rr));
+
+	cfg.fail_read = true;
+	KUNIT_EXPECT_FALSE(test, acs_isolated(test, &cfg, no_rr));
+
+	/* A device that does not answer reads as all ones, without an error */
+	cfg.fail_read = false;
+	cfg.ctrl = 0xffff;
+	KUNIT_EXPECT_FALSE(test, acs_isolated(test, &cfg, no_rr));
+}
+
+/*
+ * Drive calc_map_type_and_dist() over a fabricated PCIe fabric matching the
+ * canonical topology of two devices below one switch:
+ *
+ *   host bridge / root bus
+ *     Root Port
+ *       Switch Upstream Port
+ *         Switch Downstream Port 0
+ *           Nested Switch -- provider
+ *         Switch Downstream Port 1
+ *           Nested Switch -- client
+ *
+ * Fake config-space operations supply the ACS Control registers. This lets
+ * the cases vary both divergence ports and controls below the divergence
+ * without depending on real hardware.
+ */
+struct acs_port_cfg {
+	u32 ctrl;
+	bool fail_read;
+	bool dword_acs;
+};
+
+struct acs_fabric {
+	struct pci_dev *rootport;
+	struct pci_dev *provider;
+	struct pci_dev *client;
+	struct pci_dev *dn0;	/* Downstream Port 0 (provider side) */
+	struct pci_dev *dn1;	/* Downstream Port 1 (client side) */
+	struct pci_dev *provider_leaf;
+	struct pci_dev *client_leaf;
+	struct acs_port_cfg dn0_cfg;
+	struct acs_port_cfg dn1_cfg;
+	struct acs_port_cfg provider_leaf_cfg;
+	struct acs_port_cfg client_leaf_cfg;
+	struct acs_port_cfg rootport_cfg;
+	struct acs_port_cfg provider_cfg;
+	struct acs_port_cfg client_cfg;
+};
+
+static int acs_port_read(struct pci_dev *port, struct acs_port_cfg *cfg,
+			 int where, int size, u32 *val)
+{
+	int ctrl_offset = cfg->dword_acs ? 8 : PCI_ACS_CTRL;
+	int reg_size = cfg->dword_acs ? 4 : 2;
+
+	if (!port->acs_cap || size != reg_size)
+		return PCIBIOS_SUCCESSFUL;
+
+	if (where == port->acs_cap + PCI_ACS_CAP)
+		*val = port->acs_capabilities;
+	if (where == port->acs_cap + ctrl_offset) {
+		if (cfg->fail_read)
+			return PCIBIOS_DEVICE_NOT_FOUND;
+		*val = cfg->ctrl;
+	}
+
+	return PCIBIOS_SUCCESSFUL;
+}
+
+static int acs_fabric_read(struct pci_bus *bus, unsigned int devfn,
+			   int where, int size, u32 *val)
+{
+	struct acs_fabric *f = bus->sysdata;
+
+	*val = 0;
+	if (bus == f->provider->bus && devfn == f->provider->devfn)
+		return acs_port_read(f->provider, &f->provider_cfg,
+				     where, size, val);
+	if (bus == f->client->bus && devfn == f->client->devfn)
+		return acs_port_read(f->client, &f->client_cfg,
+				     where, size, val);
+	if (bus == f->rootport->bus && devfn == f->rootport->devfn)
+		return acs_port_read(f->rootport, &f->rootport_cfg,
+				     where, size, val);
+	if (bus == f->dn0->bus && devfn == f->dn0->devfn)
+		return acs_port_read(f->dn0, &f->dn0_cfg, where, size, val);
+	if (bus == f->dn1->bus && devfn == f->dn1->devfn)
+		return acs_port_read(f->dn1, &f->dn1_cfg, where, size, val);
+	if (bus == f->provider_leaf->bus &&
+	    devfn == f->provider_leaf->devfn)
+		return acs_port_read(f->provider_leaf, &f->provider_leaf_cfg,
+				     where, size, val);
+	if (bus == f->client_leaf->bus && devfn == f->client_leaf->devfn)
+		return acs_port_read(f->client_leaf, &f->client_leaf_cfg,
+				     where, size, val);
+
+	return PCIBIOS_SUCCESSFUL;
+}
+
+static int acs_fabric_write(struct pci_bus *bus, unsigned int devfn,
+			    int where, int size, u32 val)
+{
+	return PCIBIOS_SUCCESSFUL;
+}
+
+static struct pci_ops acs_fabric_ops = {
+	.read	= acs_fabric_read,
+	.write	= acs_fabric_write,
+};
+
+static struct pci_bus *acs_add_bus(struct kunit *test, struct pci_bus *parent,
+				   struct pci_dev *self, u8 nr, void *sysdata)
+{
+	struct pci_bus *bus = kunit_kzalloc(test, sizeof(*bus), GFP_KERNEL);
+
+	KUNIT_ASSERT_NOT_NULL(test, bus);
+	bus->parent = parent;
+	bus->self = self;
+	bus->number = nr;
+	bus->ops = &acs_fabric_ops;
+	bus->sysdata = sysdata;
+	INIT_LIST_HEAD(&bus->devices);
+	return bus;
+}
+
+static struct pci_dev *acs_add_dev(struct kunit *test, struct pci_bus *bus,
+				   unsigned int devfn, int pcie_type)
+{
+	struct pci_dev *dev = kunit_kzalloc(test, sizeof(*dev), GFP_KERNEL);
+
+	KUNIT_ASSERT_NOT_NULL(test, dev);
+	dev->bus = bus;
+	dev->devfn = devfn;
+	dev->pcie_cap = 0x40;
+	dev->pcie_flags_reg = (pcie_type << 4) | 0x2;
+	if (pcie_type != PCI_EXP_TYPE_ENDPOINT)
+		dev->hdr_type = PCI_HEADER_TYPE_BRIDGE;
+	list_add_tail(&dev->bus_list, &bus->devices);
+	return dev;
+}
+
+static void acs_build_fabric(struct kunit *test, struct acs_fabric *f)
+{
+	struct pci_bus *bus0, *bus1, *bus2, *bus3, *bus4, *bus5, *bus6;
+	struct pci_bus *bus7, *bus8;
+	struct pci_dev *swup, *provider_swup, *client_swup;
+	struct pci_dev *rootport;
+	struct pci_host_bridge *host;
+
+	host = kunit_kzalloc(test, sizeof(*host), GFP_KERNEL);
+	KUNIT_ASSERT_NOT_NULL(test, host);
+
+	bus0 = acs_add_bus(test, NULL, NULL, 0, f);
+	/* The Root Port doubles as the whitelisted host-bridge device. */
+	rootport = acs_add_dev(test, bus0, PCI_DEVFN(0, 0),
+			       PCI_EXP_TYPE_ROOT_PORT);
+	f->rootport = rootport;
+	rootport->vendor = PCI_VENDOR_ID_GOOGLE;
+	rootport->device = 0x1234;
+	rootport->acs_cap = ACS_TEST_CAP;
+	rootport->acs_capabilities = PCI_ACS_UF;
+	f->rootport_cfg.ctrl = PCI_ACS_UF;
+	host->bus = bus0;
+	bus0->bridge = &host->dev;
+
+	bus1 = acs_add_bus(test, bus0, rootport, 1, f);
+	swup = acs_add_dev(test, bus1, PCI_DEVFN(0, 0),
+			   PCI_EXP_TYPE_UPSTREAM);
+
+	bus2 = acs_add_bus(test, bus1, swup, 2, f);
+	f->dn0 = acs_add_dev(test, bus2, PCI_DEVFN(0, 0),
+			     PCI_EXP_TYPE_DOWNSTREAM);
+	f->dn1 = acs_add_dev(test, bus2, PCI_DEVFN(1, 0),
+			     PCI_EXP_TYPE_DOWNSTREAM);
+
+	bus3 = acs_add_bus(test, bus2, f->dn0, 3, f);
+	provider_swup = acs_add_dev(test, bus3, PCI_DEVFN(0, 0),
+				    PCI_EXP_TYPE_UPSTREAM);
+	bus5 = acs_add_bus(test, bus3, provider_swup, 5, f);
+	f->provider_leaf = acs_add_dev(test, bus5, PCI_DEVFN(0, 0),
+				       PCI_EXP_TYPE_DOWNSTREAM);
+	bus7 = acs_add_bus(test, bus5, f->provider_leaf, 7, f);
+	f->provider = acs_add_dev(test, bus7, PCI_DEVFN(0, 0),
+				  PCI_EXP_TYPE_ENDPOINT);
+
+	bus4 = acs_add_bus(test, bus2, f->dn1, 4, f);
+	client_swup = acs_add_dev(test, bus4, PCI_DEVFN(0, 0),
+				  PCI_EXP_TYPE_UPSTREAM);
+	bus6 = acs_add_bus(test, bus4, client_swup, 6, f);
+	f->client_leaf = acs_add_dev(test, bus6, PCI_DEVFN(0, 0),
+				     PCI_EXP_TYPE_DOWNSTREAM);
+	bus8 = acs_add_bus(test, bus6, f->client_leaf, 8, f);
+	f->client = acs_add_dev(test, bus8, PCI_DEVFN(0, 0),
+				PCI_EXP_TYPE_ENDPOINT);
+}
+
+static enum pci_p2pdma_map_type acs_walk_map(struct acs_fabric *f,
+					     unsigned int tlp_flags)
+{
+	int dist;
+
+	return calc_map_type_and_dist(f->provider, f->client, &dist, tlp_flags,
+				      false);
+}
+
+static void acs_walk_bus_addr_test(struct kunit *test)
+{
+	struct acs_fabric f = {};
+
+	acs_build_fabric(test, &f);
+	KUNIT_EXPECT_EQ(test, acs_walk_map(&f, 0), PCI_P2PDMA_MAP_BUS_ADDR);
+}
+
+static void acs_walk_request_redirect_test(struct kunit *test)
+{
+	struct acs_fabric f = {};
+
+	acs_build_fabric(test, &f);
+	f.dn1->acs_cap = 0x100;
+	f.dn1->acs_capabilities = PCI_ACS_RR;
+	f.dn1_cfg.ctrl = PCI_ACS_RR;
+
+	KUNIT_EXPECT_EQ(test, acs_walk_map(&f, 0),
+			PCI_P2PDMA_MAP_THRU_HOST_BRIDGE);
+}
+
+static void acs_walk_completion_redirect_test(struct kunit *test)
+{
+	struct acs_fabric f = {};
+
+	acs_build_fabric(test, &f);
+	f.dn0->acs_cap = 0x100;
+	f.dn0->acs_capabilities = PCI_ACS_CR;
+	f.dn0_cfg.ctrl = PCI_ACS_CR;
+
+	KUNIT_EXPECT_EQ(test, acs_walk_map(&f, 0),
+			PCI_P2PDMA_MAP_THRU_HOST_BRIDGE);
+}
+
+static void acs_walk_egress_control_test(struct kunit *test)
+{
+	struct acs_fabric f = {};
+
+	acs_build_fabric(test, &f);
+	f.dn1->acs_cap = 0x100;
+	f.dn1->acs_capabilities = PCI_ACS_EC;
+	f.dn1_cfg.ctrl = PCI_ACS_EC;
+
+	KUNIT_EXPECT_EQ(test, acs_walk_map(&f, 0),
+			PCI_P2PDMA_MAP_THRU_HOST_BRIDGE);
+}
+
+/*
+ * Zhaoxin Downstream Ports that lack an ACS capability redirect through a
+ * quirk, which covers every class, Relaxed Ordering Completions included.
+ * A Zhaoxin port the quirk does not know keeps its own ACS controls.
+ */
+static void acs_walk_quirk_redirect_test(struct kunit *test)
+{
+	struct acs_fabric f = {};
+
+	if (!IS_ENABLED(CONFIG_PCI_QUIRKS))
+		kunit_skip(test, "needs CONFIG_PCI_QUIRKS");
+
+	acs_build_fabric(test, &f);
+	f.dn0->vendor = PCI_VENDOR_ID_ZHAOXIN;
+	f.dn0->device = 0x0710;
+
+	KUNIT_EXPECT_EQ(test, acs_walk_map(&f, 0),
+			PCI_P2PDMA_MAP_THRU_HOST_BRIDGE);
+	KUNIT_EXPECT_EQ(test, acs_walk_map(&f, PCI_P2PDMA_TLP_RELAXED_CPL),
+			PCI_P2PDMA_MAP_THRU_HOST_BRIDGE);
+
+	f.dn0->device = 0x0700;
+	f.dn1->vendor = PCI_VENDOR_ID_ZHAOXIN;
+	f.dn1->device = 0x0700;
+	f.dn1->acs_cap = 0x100;
+	f.dn1->acs_capabilities = PCI_ACS_RR;
+	f.dn1_cfg.ctrl = PCI_ACS_RR;
+
+	KUNIT_EXPECT_EQ(test, acs_walk_map(&f, 0),
+			PCI_P2PDMA_MAP_THRU_HOST_BRIDGE);
+}
+
+static void acs_walk_asymmetric_direct_test(struct kunit *test)
+{
+	struct acs_fabric f = {};
+
+	acs_build_fabric(test, &f);
+	/* These controls affect only the reverse transaction directions. */
+	f.dn0->acs_cap = 0x100;
+	f.dn0->acs_capabilities = PCI_ACS_RR | PCI_ACS_EC;
+	f.dn0_cfg.ctrl = PCI_ACS_RR | PCI_ACS_EC;
+	f.dn1->acs_cap = 0x100;
+	f.dn1->acs_capabilities = PCI_ACS_CR;
+	f.dn1_cfg.ctrl = PCI_ACS_CR;
+
+	KUNIT_EXPECT_EQ(test, acs_walk_map(&f, 0), PCI_P2PDMA_MAP_BUS_ADDR);
+}
+
+static void acs_walk_nested_completion_redirect_test(struct kunit *test)
+{
+	struct acs_fabric f = {};
+
+	acs_build_fabric(test, &f);
+	f.provider_leaf->acs_cap = 0x100;
+	f.provider_leaf->acs_capabilities = PCI_ACS_CR;
+	f.provider_leaf_cfg.ctrl = PCI_ACS_CR;
+
+	KUNIT_EXPECT_EQ(test, acs_walk_map(&f, 0), PCI_P2PDMA_MAP_BUS_ADDR);
+}
+
+static void acs_walk_nested_request_redirect_test(struct kunit *test)
+{
+	struct acs_fabric f = {};
+
+	acs_build_fabric(test, &f);
+	f.client_leaf->acs_cap = 0x100;
+	f.client_leaf->acs_capabilities = PCI_ACS_RR;
+	f.client_leaf_cfg.ctrl = PCI_ACS_RR;
+
+	KUNIT_EXPECT_EQ(test, acs_walk_map(&f, 0), PCI_P2PDMA_MAP_BUS_ADDR);
+}
+
+static void acs_walk_translation_blocking_test(struct kunit *test)
+{
+	struct acs_fabric f = {};
+
+	acs_build_fabric(test, &f);
+	f.client_leaf->acs_cap = 0x100;
+	f.client_leaf->acs_capabilities = PCI_ACS_TB;
+	f.client_leaf_cfg.ctrl = PCI_ACS_TB;
+
+	/* Untranslated Requests are unaffected by Translation Blocking. */
+	KUNIT_EXPECT_EQ(test, acs_walk_map(&f, 0), PCI_P2PDMA_MAP_BUS_ADDR);
+	KUNIT_EXPECT_EQ(test, acs_walk_map(&f, PCI_P2PDMA_TLP_TRANSLATED),
+			PCI_P2PDMA_MAP_NOT_SUPPORTED);
+}
+
+static void acs_walk_relaxed_completion_test(struct kunit *test)
+{
+	struct acs_fabric f = {};
+
+	acs_build_fabric(test, &f);
+	f.dn0->acs_cap = 0x100;
+	f.dn0->acs_capabilities = PCI_ACS_CR;
+	f.dn0_cfg.ctrl = PCI_ACS_CR;
+
+	KUNIT_EXPECT_EQ(test, acs_walk_map(&f, 0),
+			PCI_P2PDMA_MAP_THRU_HOST_BRIDGE);
+	KUNIT_EXPECT_EQ(test, acs_walk_map(&f, PCI_P2PDMA_TLP_RELAXED_CPL),
+			PCI_P2PDMA_MAP_BUS_ADDR);
+}
+
+static void acs_walk_direct_translated_test(struct kunit *test)
+{
+	struct acs_fabric f = {};
+
+	acs_build_fabric(test, &f);
+	f.dn1->acs_cap = 0x100;
+	f.dn1->acs_capabilities = PCI_ACS_RR | PCI_ACS_DT;
+	f.dn1_cfg.ctrl = PCI_ACS_RR | PCI_ACS_DT;
+
+	KUNIT_EXPECT_EQ(test, acs_walk_map(&f, 0),
+			PCI_P2PDMA_MAP_THRU_HOST_BRIDGE);
+	KUNIT_EXPECT_EQ(test, acs_walk_map(&f, PCI_P2PDMA_TLP_TRANSLATED),
+			PCI_P2PDMA_MAP_BUS_ADDR);
+}
+
+static void acs_enable_forwarding(struct pci_dev *port,
+				  struct acs_port_cfg *cfg)
+{
+	port->acs_cap = ACS_TEST_CAP;
+	port->acs_capabilities = PCI_ACS_UF;
+	cfg->ctrl = PCI_ACS_UF;
+}
+
+/*
+ * Put both functions on one downstream link. Like the Intel E810, each
+ * advertises ACS with neither Request nor Completion Redirect support,
+ * indicating that there is no internal peer path. The shared Downstream
+ * Port and its ancestors forward traffic upstream towards the host.
+ */
+static void acs_build_mf_fabric(struct kunit *test, struct acs_fabric *f)
+{
+	acs_build_fabric(test, f);
+	f->client->bus = f->provider->bus;
+	f->client->devfn = PCI_DEVFN(0, 1);
+	list_move_tail(&f->client->bus_list, &f->provider->bus->devices);
+	f->provider->multifunction = 1;
+	f->client->multifunction = 1;
+	f->provider->acs_cap = ACS_TEST_CAP;
+	f->client->acs_cap = ACS_TEST_CAP;
+	acs_enable_forwarding(f->provider_leaf, &f->provider_leaf_cfg);
+	acs_enable_forwarding(f->dn0, &f->dn0_cfg);
+	acs_enable_forwarding(f->rootport, &f->rootport_cfg);
+}
+
+static void acs_expect_classes(struct kunit *test, struct acs_fabric *f,
+			       enum pci_p2pdma_map_type expect)
+{
+	unsigned int flags;
+
+	for (flags = 0; flags < PCI_P2PDMA_TLP_CLASSES; flags++)
+		KUNIT_EXPECT_EQ_MSG(test, acs_walk_map(f, flags), expect,
+				    "TLP flags %#x", flags);
+}
+
+static void acs_walk_mf_isolation_test(struct kunit *test)
+{
+	struct acs_fabric f = {};
+
+	acs_build_mf_fabric(test, &f);
+	acs_expect_classes(test, &f, PCI_P2PDMA_MAP_THRU_HOST_BRIDGE);
+}
+
+static void acs_walk_mf_quirk_test(struct kunit *test)
+{
+	struct acs_fabric f = {};
+
+	if (!IS_ENABLED(CONFIG_PCI_QUIRKS))
+		kunit_skip(test, "needs CONFIG_PCI_QUIRKS");
+
+	acs_build_mf_fabric(test, &f);
+	f.provider->acs_cap = 0;
+	f.client->acs_cap = 0;
+	f.provider->vendor = PCI_VENDOR_ID_WANGXUN;
+	f.client->vendor = PCI_VENDOR_ID_WANGXUN;
+	f.provider->device = 0x0100;
+	f.client->device = 0x0100;
+	acs_expect_classes(test, &f, PCI_P2PDMA_MAP_THRU_HOST_BRIDGE);
+
+	/* A port quirk can also establish hardwired Upstream Forwarding. */
+	f.provider_leaf->acs_cap = 0;
+	f.provider_leaf->vendor = PCI_VENDOR_ID_ZHAOXIN;
+	f.provider_leaf->device = 0x0710;
+	acs_expect_classes(test, &f, PCI_P2PDMA_MAP_THRU_HOST_BRIDGE);
+
+	/* An unknown device must keep its own programmable ACS controls. */
+	f.provider->device = 0xffff;
+	f.client->device = 0xffff;
+	f.provider->acs_cap = ACS_TEST_CAP;
+	f.client->acs_cap = ACS_TEST_CAP;
+	f.provider->acs_capabilities = ACS_ALL_CAPS;
+	f.client->acs_capabilities = ACS_ALL_CAPS;
+	acs_expect_classes(test, &f, PCI_P2PDMA_MAP_BUS_ADDR);
+}
+
+/* DT and Relaxed Ordering cannot create a missing internal peer path. */
+static void acs_walk_mf_direction_test(struct kunit *test)
+{
+	struct acs_fabric f = {};
+
+	acs_build_mf_fabric(test, &f);
+	f.provider->acs_capabilities = ACS_ALL_CAPS;
+	f.client->acs_capabilities = ACS_ALL_CAPS & ~PCI_ACS_RR;
+	f.client_cfg.ctrl = PCI_ACS_DT;
+	acs_expect_classes(test, &f, PCI_P2PDMA_MAP_THRU_HOST_BRIDGE);
+
+	f.provider->acs_capabilities = ACS_ALL_CAPS & ~PCI_ACS_CR;
+	f.client->acs_capabilities = ACS_ALL_CAPS;
+	f.client_cfg.ctrl = 0;
+	acs_expect_classes(test, &f, PCI_P2PDMA_MAP_THRU_HOST_BRIDGE);
+}
+
+static void acs_walk_mf_programmable_test(struct kunit *test)
+{
+	struct acs_fabric f = {};
+
+	acs_build_mf_fabric(test, &f);
+	f.provider->acs_capabilities = ACS_ALL_CAPS;
+	f.client->acs_capabilities = ACS_ALL_CAPS;
+	acs_expect_classes(test, &f, PCI_P2PDMA_MAP_BUS_ADDR);
+
+	f.provider_cfg.ctrl = PCI_ACS_CR;
+	f.client_cfg.ctrl = PCI_ACS_RR | PCI_ACS_DT;
+	KUNIT_EXPECT_EQ(test, acs_walk_map(&f, 0),
+			PCI_P2PDMA_MAP_THRU_HOST_BRIDGE);
+	KUNIT_EXPECT_EQ(test, acs_walk_map(&f, PCI_P2PDMA_TLP_TRANSLATED),
+			PCI_P2PDMA_MAP_THRU_HOST_BRIDGE);
+	KUNIT_EXPECT_EQ(test, acs_walk_map(&f, PCI_P2PDMA_TLP_RELAXED_CPL),
+			PCI_P2PDMA_MAP_THRU_HOST_BRIDGE);
+	KUNIT_EXPECT_EQ(test,
+			acs_walk_map(&f, PCI_P2PDMA_TLP_TRANSLATED |
+				     PCI_P2PDMA_TLP_RELAXED_CPL),
+			PCI_P2PDMA_MAP_BUS_ADDR);
+
+	/* A route that stays within the device does not need forwarding. */
+	f.provider_leaf_cfg.ctrl = 0;
+	KUNIT_EXPECT_EQ(test, acs_walk_map(&f, 0),
+			PCI_P2PDMA_MAP_NOT_SUPPORTED);
+	KUNIT_EXPECT_EQ(test,
+			acs_walk_map(&f, PCI_P2PDMA_TLP_TRANSLATED |
+				     PCI_P2PDMA_TLP_RELAXED_CPL),
+			PCI_P2PDMA_MAP_BUS_ADDR);
+
+	f.provider_leaf_cfg.fail_read = true;
+	KUNIT_EXPECT_EQ(test, acs_walk_map(&f, 0),
+			PCI_P2PDMA_MAP_NOT_SUPPORTED);
+	KUNIT_EXPECT_EQ(test,
+			acs_walk_map(&f, PCI_P2PDMA_TLP_TRANSLATED |
+				     PCI_P2PDMA_TLP_RELAXED_CPL),
+			PCI_P2PDMA_MAP_BUS_ADDR);
+}
+
+struct acs_forwarding_case {
+	const char *desc;
+	u16 cap;
+	u16 capabilities;
+	u16 ctrl;
+	bool fail_read;
+};
+
+static const struct acs_forwarding_case acs_forwarding_cases[] = {
+	{ "disabled", ACS_TEST_CAP, PCI_ACS_UF, 0, false },
+	{ "unsupported", ACS_TEST_CAP, 0, 0, false },
+	{ "absent_acs", 0, 0, 0, false },
+	{ "read_error", ACS_TEST_CAP, PCI_ACS_UF, PCI_ACS_UF, true },
+	{ "all_ones", ACS_TEST_CAP, PCI_ACS_UF, 0xffff, false },
+};
+
+static void acs_forwarding_desc(const struct acs_forwarding_case *c,
+				char *desc)
+{
+	strscpy(desc, c->desc, KUNIT_PARAM_DESC_SIZE);
+}
+
+KUNIT_ARRAY_PARAM(acs_forwarding, acs_forwarding_cases, acs_forwarding_desc);
+
+static void acs_expect_redirect_forwarding(struct kunit *test,
+					  struct acs_fabric *f,
+					  struct pci_dev *provider_port,
+					  struct acs_port_cfg *provider_cfg,
+					  struct pci_dev *client_port,
+					  struct acs_port_cfg *client_cfg)
+{
+	unsigned int flags;
+
+	provider_port->acs_cap = ACS_TEST_CAP;
+	provider_port->acs_capabilities = ACS_ALL_CAPS;
+	client_port->acs_cap = ACS_TEST_CAP;
+	client_port->acs_capabilities = ACS_ALL_CAPS | PCI_ACS_EC;
+	acs_expect_classes(test, f, PCI_P2PDMA_MAP_BUS_ADDR);
+
+	client_cfg->ctrl = PCI_ACS_RR;
+	acs_expect_classes(test, f, PCI_P2PDMA_MAP_NOT_SUPPORTED);
+	client_cfg->ctrl = PCI_ACS_EC;
+	acs_expect_classes(test, f, PCI_P2PDMA_MAP_NOT_SUPPORTED);
+	client_cfg->ctrl = 0;
+	provider_cfg->ctrl = PCI_ACS_CR;
+	for (flags = 0; flags < PCI_P2PDMA_TLP_CLASSES; flags++)
+		KUNIT_EXPECT_EQ_MSG(test, acs_walk_map(f, flags),
+				    flags & PCI_P2PDMA_TLP_RELAXED_CPL ?
+				    PCI_P2PDMA_MAP_BUS_ADDR :
+				    PCI_P2PDMA_MAP_NOT_SUPPORTED,
+				    "TLP flags %#x", flags);
+
+	client_cfg->ctrl = PCI_ACS_RR | PCI_ACS_DT;
+	for (flags = 0; flags < PCI_P2PDMA_TLP_CLASSES; flags++)
+		KUNIT_EXPECT_EQ_MSG(test, acs_walk_map(f, flags),
+				    flags == (PCI_P2PDMA_TLP_TRANSLATED |
+					      PCI_P2PDMA_TLP_RELAXED_CPL) ?
+				    PCI_P2PDMA_MAP_BUS_ADDR :
+				    PCI_P2PDMA_MAP_NOT_SUPPORTED,
+				    "TLP flags %#x", flags);
+}
+
+static void acs_walk_switch_forwarding_test(struct kunit *test)
+{
+	const struct acs_forwarding_case *c = test->param_value;
+	struct acs_fabric f = {};
+
+	acs_build_fabric(test, &f);
+	f.rootport->acs_cap = c->cap;
+	f.rootport->acs_capabilities = c->capabilities;
+	f.rootport_cfg.ctrl = c->ctrl;
+	f.rootport_cfg.fail_read = c->fail_read;
+	acs_expect_redirect_forwarding(test, &f, f.dn0, &f.dn0_cfg,
+				       f.dn1, &f.dn1_cfg);
+}
+
+static void acs_walk_cascaded_forwarding_test(struct kunit *test)
+{
+	const struct acs_forwarding_case *c = test->param_value;
+	struct acs_fabric f = {};
+
+	acs_build_fabric(test, &f);
+	f.client_leaf->bus = f.provider_leaf->bus;
+	f.client_leaf->devfn = PCI_DEVFN(1, 0);
+	list_move_tail(&f.client_leaf->bus_list, &f.client_leaf->bus->devices);
+	f.client->bus->parent = f.client_leaf->bus;
+	f.dn0->acs_cap = c->cap;
+	f.dn0->acs_capabilities = c->capabilities;
+	f.dn0_cfg.ctrl = c->ctrl;
+	f.dn0_cfg.fail_read = c->fail_read;
+	acs_expect_redirect_forwarding(test, &f,
+				       f.provider_leaf, &f.provider_leaf_cfg,
+				       f.client_leaf, &f.client_leaf_cfg);
+
+	acs_enable_forwarding(f.dn0, &f.dn0_cfg);
+	f.dn0_cfg.fail_read = false;
+	f.provider_leaf_cfg.ctrl = 0;
+	f.client_leaf_cfg.ctrl = PCI_ACS_RR;
+	acs_expect_classes(test, &f, PCI_P2PDMA_MAP_THRU_HOST_BRIDGE);
+	f.rootport_cfg.ctrl = 0;
+	acs_expect_classes(test, &f, PCI_P2PDMA_MAP_NOT_SUPPORTED);
+}
+
+static void acs_walk_mf_forwarding_test(struct kunit *test)
+{
+	const struct acs_forwarding_case *c = test->param_value;
+	struct acs_fabric f = {};
+
+	acs_build_mf_fabric(test, &f);
+	f.provider_leaf->acs_cap = c->cap;
+	f.provider_leaf->acs_capabilities = c->capabilities;
+	f.provider_leaf_cfg.ctrl = c->ctrl;
+	f.provider_leaf_cfg.fail_read = c->fail_read;
+	acs_expect_classes(test, &f, PCI_P2PDMA_MAP_NOT_SUPPORTED);
+}
+
+static void acs_walk_mf_upstream_forwarding_test(struct kunit *test)
+{
+	struct acs_fabric f = {};
+
+	acs_build_mf_fabric(test, &f);
+	f.dn0_cfg.ctrl = 0;
+	acs_expect_classes(test, &f, PCI_P2PDMA_MAP_NOT_SUPPORTED);
+
+	f.dn0_cfg.ctrl = PCI_ACS_UF;
+	f.rootport_cfg.ctrl = 0;
+	acs_expect_classes(test, &f, PCI_P2PDMA_MAP_NOT_SUPPORTED);
+}
+
+static void acs_walk_mf_translation_blocking_test(struct kunit *test)
+{
+	struct acs_fabric f = {};
+	unsigned int flags;
+
+	acs_build_mf_fabric(test, &f);
+	f.provider_leaf->acs_capabilities |= PCI_ACS_TB;
+	f.provider_leaf_cfg.ctrl |= PCI_ACS_TB;
+	for (flags = 0; flags < PCI_P2PDMA_TLP_CLASSES; flags++)
+		KUNIT_EXPECT_EQ_MSG(test, acs_walk_map(&f, flags),
+				    flags & PCI_P2PDMA_TLP_TRANSLATED ?
+				    PCI_P2PDMA_MAP_NOT_SUPPORTED :
+				    PCI_P2PDMA_MAP_THRU_HOST_BRIDGE,
+				    "TLP flags %#x", flags);
+}
+
+static void acs_walk_mf_unlisted_host_test(struct kunit *test)
+{
+	struct acs_fabric f = {}, g = {};
+	int dist;
+
+	acs_build_mf_fabric(test, &f);
+	acs_build_fabric(test, &g);
+	f.rootport->vendor = 0;
+	g.rootport->vendor = 0;
+	/* Some CPUs permit host routing regardless of the host allowlist. */
+	if (calc_map_type_and_dist(f.provider, g.client, &dist, 0, false) ==
+	    PCI_P2PDMA_MAP_THRU_HOST_BRIDGE)
+		kunit_skip(test, "CPU supports P2PDMA on unlisted hosts");
+
+	acs_expect_classes(test, &f, PCI_P2PDMA_MAP_NOT_SUPPORTED);
+}
+
+static void acs_walk_mf_ari_test(struct kunit *test)
+{
+	struct acs_fabric f = {};
+
+	acs_build_mf_fabric(test, &f);
+	f.provider->bus->self->ari_enabled = 1;
+	f.client->devfn = 8;
+	f.client->multifunction = 0;
+	acs_expect_classes(test, &f, PCI_P2PDMA_MAP_THRU_HOST_BRIDGE);
+
+	/* The same shared-link topology can be directly below a Root Port. */
+	f.provider->bus->parent = f.rootport->bus;
+	f.provider->bus->self = f.rootport;
+	f.rootport->ari_enabled = 1;
+	acs_expect_classes(test, &f, PCI_P2PDMA_MAP_THRU_HOST_BRIDGE);
+}
+
+static void acs_walk_mf_vf_test(struct kunit *test)
+{
+#ifdef CONFIG_PCI_IOV
+	struct acs_fabric f = {};
+	struct pci_dev *physfn;
+
+	acs_build_mf_fabric(test, &f);
+	physfn = acs_add_dev(test, f.provider->bus, PCI_DEVFN(0, 0),
+			     PCI_EXP_TYPE_ENDPOINT);
+	physfn->is_physfn = 1;
+	physfn->acs_cap = ACS_TEST_CAP;
+	physfn->acs_capabilities = ACS_ALL_CAPS;
+	f.provider->devfn = 1;
+	f.client->devfn = 8;
+	f.provider->bus->self->ari_enabled = 1;
+	f.provider->multifunction = 0;
+	f.client->multifunction = 0;
+	f.provider->is_virtfn = 1;
+	f.client->is_virtfn = 1;
+	f.provider->physfn = physfn;
+	f.client->physfn = physfn;
+	acs_expect_classes(test, &f, PCI_P2PDMA_MAP_THRU_HOST_BRIDGE);
+
+	/* SR-IOV functions without ACS cannot route internally either. */
+	f.provider->acs_cap = 0;
+	f.client->acs_cap = 0;
+	acs_expect_classes(test, &f, PCI_P2PDMA_MAP_THRU_HOST_BRIDGE);
+
+	/* Check the physical function as the peer of one of its VFs. */
+	f.provider->is_virtfn = 0;
+	f.provider->physfn = NULL;
+	f.provider->is_physfn = 1;
+	f.client->physfn = f.provider;
+	acs_expect_classes(test, &f, PCI_P2PDMA_MAP_THRU_HOST_BRIDGE);
+#else
+	kunit_skip(test, "needs CONFIG_PCI_IOV");
+#endif
+}
+
+static void acs_walk_mf_external_peer_test(struct kunit *test)
+{
+	struct acs_fabric f = {};
+
+	acs_build_fabric(test, &f);
+	f.provider->multifunction = 1;
+	f.client->multifunction = 1;
+	f.provider->acs_cap = ACS_TEST_CAP;
+	f.client->acs_cap = ACS_TEST_CAP;
+	acs_expect_classes(test, &f, PCI_P2PDMA_MAP_BUS_ADDR);
+}
+
+static void acs_walk_mf_self_dma_test(struct kunit *test)
+{
+	struct acs_fabric f = {};
+	unsigned int flags;
+	int dist;
+
+	acs_build_mf_fabric(test, &f);
+	f.provider_leaf->acs_capabilities = PCI_ACS_TB;
+	f.provider_leaf_cfg.ctrl = PCI_ACS_TB;
+	for (flags = 0; flags < PCI_P2PDMA_TLP_CLASSES; flags++) {
+		KUNIT_EXPECT_EQ(test,
+				calc_map_type_and_dist(f.client, f.client, &dist,
+						       flags, false),
+				PCI_P2PDMA_MAP_BUS_ADDR);
+		KUNIT_EXPECT_EQ(test, dist, 0);
+	}
+}
+
+/*
+ * The cache stores one packed value per client, so every class has to come
+ * back out under the flags that selected it.
+ */
+static void acs_map_types_pack_test(struct kunit *test)
+{
+	static const enum pci_p2pdma_map_type type[PCI_P2PDMA_TLP_CLASSES] = {
+		[0] = PCI_P2PDMA_MAP_THRU_HOST_BRIDGE,
+		[PCI_P2PDMA_TLP_TRANSLATED] = PCI_P2PDMA_MAP_NOT_SUPPORTED,
+		[PCI_P2PDMA_TLP_RELAXED_CPL] = PCI_P2PDMA_MAP_BUS_ADDR,
+		[PCI_P2PDMA_TLP_TRANSLATED | PCI_P2PDMA_TLP_RELAXED_CPL] =
+			PCI_P2PDMA_MAP_UNKNOWN,
+	};
+	unsigned long packed = pci_p2pdma_map_types_pack(type);
+	unsigned int flags;
+
+	for (flags = 0; flags < PCI_P2PDMA_TLP_CLASSES; flags++)
+		KUNIT_EXPECT_EQ(test,
+				pci_p2pdma_map_types_unpack(packed, flags),
+				type[flags]);
+
+	/* An absent cache entry reads back as unknown in every class. */
+	for (flags = 0; flags < PCI_P2PDMA_TLP_CLASSES; flags++)
+		KUNIT_EXPECT_EQ(test, pci_p2pdma_map_types_unpack(0, flags),
+				PCI_P2PDMA_MAP_UNKNOWN);
+}
+
+/*
+ * The provider can be an ancestor of the client, which leaves no divergence
+ * to evaluate. Translation Blocking still applies to every port the Request
+ * passes on its way up.
+ */
+static void acs_walk_ancestor_provider_tb_test(struct kunit *test)
+{
+	struct acs_fabric f = {};
+	int dist;
+
+	acs_build_fabric(test, &f);
+	f.client_leaf->acs_cap = 0x100;
+	f.client_leaf->acs_capabilities = PCI_ACS_TB;
+	f.client_leaf_cfg.ctrl = PCI_ACS_TB;
+
+	KUNIT_EXPECT_EQ(test,
+			calc_map_type_and_dist(f.dn1, f.client, &dist, 0,
+					       false),
+			PCI_P2PDMA_MAP_BUS_ADDR);
+	KUNIT_EXPECT_EQ(test,
+			calc_map_type_and_dist(f.dn1, f.client, &dist,
+					       PCI_P2PDMA_TLP_TRANSLATED,
+					       false),
+			PCI_P2PDMA_MAP_NOT_SUPPORTED);
+}
+
+/*
+ * Without a common upstream bridge the Request still climbs towards the host
+ * bridge, so Translation Blocking on the way withdraws the Translated classes
+ * there too.
+ */
+static void acs_walk_no_common_bridge_tb_test(struct kunit *test)
+{
+	struct acs_fabric f = {}, g = {};
+	int dist;
+
+	acs_build_fabric(test, &f);
+	acs_build_fabric(test, &g);
+	f.client_leaf->acs_cap = 0x100;
+	f.client_leaf->acs_capabilities = PCI_ACS_TB;
+	f.client_leaf_cfg.ctrl = PCI_ACS_TB;
+
+	KUNIT_EXPECT_EQ(test,
+			calc_map_type_and_dist(g.provider, f.client, &dist, 0,
+					       false),
+			PCI_P2PDMA_MAP_THRU_HOST_BRIDGE);
+	KUNIT_EXPECT_EQ(test,
+			calc_map_type_and_dist(g.provider, f.client, &dist,
+					       PCI_P2PDMA_TLP_TRANSLATED,
+					       false),
+			PCI_P2PDMA_MAP_NOT_SUPPORTED);
+}
+
+/*
+ * A Request between the client and itself never leaves the device, so no port
+ * is in a position to inspect its Address Type. Translation Blocking directly
+ * above the client must not withdraw the Translated classes.
+ */
+static void acs_walk_self_dma_tb_test(struct kunit *test)
+{
+	struct acs_fabric f = {};
+	int dist;
+
+	acs_build_fabric(test, &f);
+	f.client_leaf->acs_cap = 0x100;
+	f.client_leaf->acs_capabilities = PCI_ACS_TB;
+	f.client_leaf_cfg.ctrl = PCI_ACS_TB;
+
+	KUNIT_EXPECT_EQ(test,
+			calc_map_type_and_dist(f.client, f.client, &dist, 0,
+					       false),
+			PCI_P2PDMA_MAP_BUS_ADDR);
+	KUNIT_EXPECT_EQ(test,
+			calc_map_type_and_dist(f.client, f.client, &dist,
+					       PCI_P2PDMA_TLP_TRANSLATED,
+					       false),
+			PCI_P2PDMA_MAP_BUS_ADDR);
+}
+
+/*
+ * A direct route turns around at the divergence, so Translation Blocking above
+ * it does not touch one. The host bridge route keeps climbing past that port,
+ * and the Translated classes have to go without it.
+ */
+static void acs_walk_tb_above_divergence_test(struct kunit *test)
+{
+	struct acs_fabric f = {};
+	int dist;
+
+	acs_build_fabric(test, &f);
+	f.rootport->acs_cap = 0x100;
+	f.rootport->acs_capabilities |= PCI_ACS_TB;
+	f.rootport_cfg.ctrl |= PCI_ACS_TB;
+
+	/* Nothing redirects yet, so the Request never reaches the Root Port. */
+	KUNIT_EXPECT_EQ(test,
+			calc_map_type_and_dist(f.provider, f.client, &dist,
+					       PCI_P2PDMA_TLP_TRANSLATED,
+					       false),
+			PCI_P2PDMA_MAP_BUS_ADDR);
+
+	/* Request Redirect sends it up past the Root Port instead. */
+	f.dn1->acs_cap = 0x100;
+	f.dn1->acs_capabilities = PCI_ACS_RR;
+	f.dn1_cfg.ctrl = PCI_ACS_RR;
+
+	KUNIT_EXPECT_EQ(test,
+			calc_map_type_and_dist(f.provider, f.client, &dist, 0,
+					       false),
+			PCI_P2PDMA_MAP_THRU_HOST_BRIDGE);
+	KUNIT_EXPECT_EQ(test,
+			calc_map_type_and_dist(f.provider, f.client, &dist,
+					       PCI_P2PDMA_TLP_TRANSLATED,
+					       false),
+			PCI_P2PDMA_MAP_NOT_SUPPORTED);
+}
+
+struct acs_intel_tb_case {
+	const char *desc;
+	u32 ctrl;
+	bool fail_read;
+	enum pci_p2pdma_map_type translated;
+	enum pci_p2pdma_map_type redirected;
+};
+
+static const struct acs_intel_tb_case acs_intel_tb_cases[] = {
+	{ "tb_clear", PCI_ACS_UF, false,
+	  PCI_P2PDMA_MAP_THRU_HOST_BRIDGE, PCI_P2PDMA_MAP_THRU_HOST_BRIDGE },
+	{ "tb_set", PCI_ACS_UF | PCI_ACS_TB, false,
+	  PCI_P2PDMA_MAP_NOT_SUPPORTED, PCI_P2PDMA_MAP_THRU_HOST_BRIDGE },
+	{ "read_error", PCI_ACS_UF, true,
+	  PCI_P2PDMA_MAP_NOT_SUPPORTED, PCI_P2PDMA_MAP_NOT_SUPPORTED },
+	{ "all_ones", ~0U, false,
+	  PCI_P2PDMA_MAP_NOT_SUPPORTED, PCI_P2PDMA_MAP_NOT_SUPPORTED },
+};
+
+static void acs_intel_tb_desc(const struct acs_intel_tb_case *c, char *desc)
+{
+	strscpy(desc, c->desc, KUNIT_PARAM_DESC_SIZE);
+}
+
+KUNIT_ARRAY_PARAM(acs_intel_tb, acs_intel_tb_cases, acs_intel_tb_desc);
+
+static void acs_build_intel_fabric(struct kunit *test, struct acs_fabric *f,
+				   const struct acs_intel_tb_case *c)
+{
+	struct pci_dev *host;
+
+	acs_build_fabric(test, f);
+	f->rootport->devfn = PCI_DEVFN(1, 0);
+	f->rootport->vendor = PCI_VENDOR_ID_INTEL;
+	f->rootport->device = 0xa290;
+	f->rootport->acs_capabilities = PCI_ACS_UF | PCI_ACS_TB;
+	f->rootport_cfg.ctrl = c->ctrl;
+	f->rootport_cfg.fail_read = c->fail_read;
+	f->rootport_cfg.dword_acs = true;
+
+	host = acs_add_dev(test, f->rootport->bus, PCI_DEVFN(0, 0),
+			   PCI_EXP_TYPE_ENDPOINT);
+	host->vendor = PCI_VENDOR_ID_INTEL;
+	host->device = 0x2020;
+	host->pcie_cap = 0;
+	host->class = PCI_CLASS_BRIDGE_HOST << 8;
+	list_move(&host->bus_list, &host->bus->devices);
+}
+
+static void acs_walk_intel_tb_above_divergence_test(struct kunit *test)
+{
+	const struct acs_intel_tb_case *c = test->param_value;
+	struct acs_fabric f = {};
+	unsigned int flags;
+
+	if (!IS_ENABLED(CONFIG_PCI_QUIRKS))
+		kunit_skip(test, "needs CONFIG_PCI_QUIRKS");
+
+	acs_build_intel_fabric(test, &f, c);
+	acs_expect_classes(test, &f, PCI_P2PDMA_MAP_BUS_ADDR);
+
+	f.dn1->acs_cap = ACS_TEST_CAP;
+	f.dn1->acs_capabilities = PCI_ACS_RR;
+	f.dn1_cfg.ctrl = PCI_ACS_RR;
+	for (flags = 0; flags < PCI_P2PDMA_TLP_CLASSES; flags++)
+		KUNIT_EXPECT_EQ_MSG(test, acs_walk_map(&f, flags),
+				    flags & PCI_P2PDMA_TLP_TRANSLATED ?
+				    c->translated : c->redirected,
+				    "TLP flags %#x", flags);
+}
+
+static void acs_walk_intel_no_common_bridge_tb_test(struct kunit *test)
+{
+	const struct acs_intel_tb_case *c = test->param_value;
+	struct acs_fabric f = {}, g = {};
+	unsigned int flags;
+	int dist;
+
+	if (!IS_ENABLED(CONFIG_PCI_QUIRKS))
+		kunit_skip(test, "needs CONFIG_PCI_QUIRKS");
+
+	acs_build_intel_fabric(test, &f, c);
+	acs_build_fabric(test, &g);
+	for (flags = 0; flags < PCI_P2PDMA_TLP_CLASSES; flags++)
+		KUNIT_EXPECT_EQ_MSG(test,
+				    calc_map_type_and_dist(g.provider, f.client,
+							   &dist, flags, false),
+				    flags & PCI_P2PDMA_TLP_TRANSLATED ?
+				    c->translated :
+				    PCI_P2PDMA_MAP_THRU_HOST_BRIDGE,
+				    "TLP flags %#x", flags);
+}
+
+static void acs_walk_unreadable_control_test(struct kunit *test)
+{
+	struct acs_fabric f = {};
+
+	acs_build_fabric(test, &f);
+	f.dn1->acs_cap = 0x100;
+	f.dn1_cfg.fail_read = true;
+
+	KUNIT_EXPECT_EQ(test, acs_walk_map(&f, 0),
+			PCI_P2PDMA_MAP_NOT_SUPPORTED);
+
+	/* A port that does not answer reads as all ones, without an error */
+	f.dn1_cfg.fail_read = false;
+	f.dn1_cfg.ctrl = 0xffff;
+
+	KUNIT_EXPECT_EQ(test, acs_walk_map(&f, 0),
+			PCI_P2PDMA_MAP_NOT_SUPPORTED);
+}
+
+/*
+ * Route the way pci_p2pdma_map_type_tlp() does once it has a client: the
+ * client decides which flags apply, and the answer is then checked against
+ * what the client can be handed.
+ */
+static enum pci_p2pdma_map_type acs_client_map(struct acs_fabric *f,
+					       bool per_mapping,
+					       unsigned int tlp_flags)
+{
+	enum pci_p2pdma_map_type type;
+	int dist;
+
+	if (!per_mapping)
+		tlp_flags = pci_p2pdma_client_tlp_flags(f->client, tlp_flags);
+	type = calc_map_type_and_dist(f->provider, f->client, &dist, tlp_flags,
+				      false);
+	return pci_p2pdma_client_map_type(f->provider, f->client, per_mapping,
+					  tlp_flags, type);
+}
+
+/*
+ * A client with ATS enabled for the whole device translates whatever it is
+ * handed, so it never gets bus addresses even on a direct route, and
+ * Translation Blocking rejects it even when its caller asks for the default
+ * class.
+ */
+static void acs_client_ats_test(struct kunit *test)
+{
+	struct acs_fabric f = {};
+
+	acs_build_fabric(test, &f);
+	f.client->ats_enabled = 1;
+
+	KUNIT_EXPECT_EQ(test, acs_client_map(&f, false, 0),
+			PCI_P2PDMA_MAP_THRU_HOST_BRIDGE);
+
+	f.client_leaf->acs_cap = 0x100;
+	f.client_leaf->acs_capabilities = PCI_ACS_TB;
+	f.client_leaf_cfg.ctrl = PCI_ACS_TB;
+
+	KUNIT_EXPECT_EQ(test, acs_client_map(&f, false, 0),
+			PCI_P2PDMA_MAP_NOT_SUPPORTED);
+}
+
+/*
+ * The cache holds what the topology allows, filled when the client first
+ * asked. A client whose ATS was enabled after that must still be kept off the
+ * bus addresses the cache recorded.
+ */
+static void acs_client_ats_cached_test(struct kunit *test)
+{
+	enum pci_p2pdma_map_type type[PCI_P2PDMA_TLP_CLASSES], hit;
+	struct acs_fabric f = {};
+	unsigned long cached;
+	unsigned int flags;
+	int dist;
+
+	acs_build_fabric(test, &f);
+	for (flags = 0; flags < PCI_P2PDMA_TLP_CLASSES; flags++)
+		type[flags] = calc_map_type_and_dist(f.provider, f.client,
+						     &dist, flags, false);
+	cached = pci_p2pdma_map_types_pack(type);
+
+	f.client->ats_enabled = 1;
+	flags = pci_p2pdma_client_tlp_flags(f.client, 0);
+	hit = pci_p2pdma_map_types_unpack(cached, flags);
+
+	KUNIT_EXPECT_EQ(test,
+			pci_p2pdma_client_map_type(f.provider, f.client, false,
+						   flags, hit),
+			PCI_P2PDMA_MAP_THRU_HOST_BRIDGE);
+}
+
+/*
+ * A client that declared per-mapping ATS picks the Address Type per mapping,
+ * so it keeps the per-class answers even with ATS enabled.
+ */
+static void acs_client_ats_per_mapping_test(struct kunit *test)
+{
+	struct acs_fabric f = {};
+
+	acs_build_fabric(test, &f);
+	f.client->ats_enabled = 1;
+
+	KUNIT_EXPECT_EQ(test, acs_client_map(&f, true, 0),
+			PCI_P2PDMA_MAP_BUS_ADDR);
+	KUNIT_EXPECT_EQ(test,
+			acs_client_map(&f, true, PCI_P2PDMA_TLP_TRANSLATED),
+			PCI_P2PDMA_MAP_BUS_ADDR);
+
+	f.client_leaf->acs_cap = 0x100;
+	f.client_leaf->acs_capabilities = PCI_ACS_TB;
+	f.client_leaf_cfg.ctrl = PCI_ACS_TB;
+
+	KUNIT_EXPECT_EQ(test, acs_client_map(&f, true, 0),
+			PCI_P2PDMA_MAP_BUS_ADDR);
+	KUNIT_EXPECT_EQ(test,
+			acs_client_map(&f, true, PCI_P2PDMA_TLP_TRANSLATED),
+			PCI_P2PDMA_MAP_NOT_SUPPORTED);
+}
+
+/*
+ * A client with ATS disabled cannot issue Translated Requests, so a caller
+ * asking about them gets the answer for the Untranslated ones it will issue.
+ */
+static void acs_client_no_ats_test(struct kunit *test)
+{
+	struct acs_fabric f = {};
+
+	acs_build_fabric(test, &f);
+	f.dn1->acs_cap = 0x100;
+	f.dn1->acs_capabilities = PCI_ACS_RR | PCI_ACS_DT;
+	f.dn1_cfg.ctrl = PCI_ACS_RR | PCI_ACS_DT;
+
+	KUNIT_EXPECT_EQ(test,
+			acs_client_map(&f, false, PCI_P2PDMA_TLP_TRANSLATED),
+			PCI_P2PDMA_MAP_THRU_HOST_BRIDGE);
+}
+
+static struct kunit_case pci_acs_test_cases[] = {
+	KUNIT_CASE_PARAM(pci_acs_p2pdma_request_test,
+			 acs_request_gen_params),
+	KUNIT_CASE_PARAM(pci_acs_p2pdma_completion_test,
+			 acs_completion_gen_params),
+	KUNIT_CASE_PARAM(pci_acs_flags_enabled_test,
+			 acs_isolation_gen_params),
+	KUNIT_CASE(pci_acs_flags_no_cap_test),
+	KUNIT_CASE(pci_acs_flags_read_fails_test),
+	KUNIT_CASE(acs_walk_bus_addr_test),
+	KUNIT_CASE(acs_walk_request_redirect_test),
+	KUNIT_CASE(acs_walk_completion_redirect_test),
+	KUNIT_CASE(acs_walk_egress_control_test),
+	KUNIT_CASE(acs_walk_quirk_redirect_test),
+	KUNIT_CASE(acs_walk_asymmetric_direct_test),
+	KUNIT_CASE(acs_walk_nested_completion_redirect_test),
+	KUNIT_CASE(acs_walk_nested_request_redirect_test),
+	KUNIT_CASE(acs_walk_translation_blocking_test),
+	KUNIT_CASE(acs_walk_ancestor_provider_tb_test),
+	KUNIT_CASE(acs_walk_no_common_bridge_tb_test),
+	KUNIT_CASE(acs_walk_self_dma_tb_test),
+	KUNIT_CASE(acs_walk_relaxed_completion_test),
+	KUNIT_CASE(acs_walk_direct_translated_test),
+	KUNIT_CASE(acs_walk_mf_isolation_test),
+	KUNIT_CASE(acs_walk_mf_quirk_test),
+	KUNIT_CASE(acs_walk_mf_direction_test),
+	KUNIT_CASE(acs_walk_mf_programmable_test),
+	KUNIT_CASE_PARAM(acs_walk_switch_forwarding_test, acs_forwarding_gen_params),
+	KUNIT_CASE_PARAM(acs_walk_cascaded_forwarding_test, acs_forwarding_gen_params),
+	KUNIT_CASE_PARAM(acs_walk_mf_forwarding_test, acs_forwarding_gen_params),
+	KUNIT_CASE(acs_walk_mf_upstream_forwarding_test),
+	KUNIT_CASE(acs_walk_mf_translation_blocking_test),
+	KUNIT_CASE(acs_walk_mf_unlisted_host_test),
+	KUNIT_CASE(acs_walk_mf_ari_test),
+	KUNIT_CASE(acs_walk_mf_vf_test),
+	KUNIT_CASE(acs_walk_mf_external_peer_test),
+	KUNIT_CASE(acs_walk_mf_self_dma_test),
+	KUNIT_CASE(acs_walk_tb_above_divergence_test),
+	KUNIT_CASE_PARAM(acs_walk_intel_tb_above_divergence_test,
+			 acs_intel_tb_gen_params),
+	KUNIT_CASE_PARAM(acs_walk_intel_no_common_bridge_tb_test,
+			 acs_intel_tb_gen_params),
+	KUNIT_CASE(acs_walk_unreadable_control_test),
+	KUNIT_CASE(acs_map_types_pack_test),
+	KUNIT_CASE(acs_client_ats_test),
+	KUNIT_CASE(acs_client_ats_cached_test),
+	KUNIT_CASE(acs_client_ats_per_mapping_test),
+	KUNIT_CASE(acs_client_no_ats_test),
+	{}
+};
+
+static struct kunit_suite pci_acs_test_suite = {
+	.name = "pci_acs",
+	.test_cases = pci_acs_test_cases,
+};
+kunit_test_suite(pci_acs_test_suite);
+
+MODULE_IMPORT_NS("EXPORTED_FOR_KUNIT_TESTING");
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("KUnit tests for PCI ACS peer-to-peer routing decisions");
diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c
index 7f1f47ea2ee415..4b6e868722280a 100644
--- a/drivers/pci/quirks.c
+++ b/drivers/pci/quirks.c
@@ -5132,6 +5132,21 @@ static bool pci_quirk_intel_spt_pch_acs_match(struct pci_dev *dev)
 
 #define INTEL_SPT_ACS_CTRL (PCI_ACS_CAP + 4)
 
+int pci_dev_specific_read_acs_ctrl(struct pci_dev *dev, u16 *ctrl)
+{
+	u32 val = ~0;
+	int ret;
+
+	if (dev->vendor != PCI_VENDOR_ID_INTEL || !dev->acs_cap ||
+	    !pci_quirk_intel_spt_pch_acs_match(dev))
+		return -ENOTTY;
+
+	ret = pci_read_config_dword(dev, dev->acs_cap + INTEL_SPT_ACS_CTRL,
+				   &val);
+	*ctrl = val;
+	return ret;
+}
+
 static int pci_quirk_intel_spt_pch_acs(struct pci_dev *dev, u16 acs_flags)
 {
 	int pos;
@@ -5145,10 +5160,14 @@ static int pci_quirk_intel_spt_pch_acs(struct pci_dev *dev, u16 acs_flags)
 		return -ENOTTY;
 
 	/* see pci_acs_flags_enabled() */
-	pci_read_config_dword(dev, pos + PCI_ACS_CAP, &cap);
+	if (pci_read_config_dword(dev, pos + PCI_ACS_CAP, &cap) ||
+	    PCI_POSSIBLE_ERROR(cap))
+		return 0;
 	acs_flags &= (cap | PCI_ACS_EC);
 
-	pci_read_config_dword(dev, pos + INTEL_SPT_ACS_CTRL, &ctrl);
+	if (pci_read_config_dword(dev, pos + INTEL_SPT_ACS_CTRL, &ctrl) ||
+	    PCI_POSSIBLE_ERROR(ctrl))
+		return 0;
 
 	return pci_acs_ctrl_enabled(acs_flags, ctrl);
 }
diff --git a/include/linux/pci-p2pdma.h b/include/linux/pci-p2pdma.h
index 873de20a224759..ce389e18d02396 100644
--- a/include/linux/pci-p2pdma.h
+++ b/include/linux/pci-p2pdma.h
@@ -42,10 +42,10 @@ enum pci_p2pdma_map_type {
 	PCI_P2PDMA_MAP_NONE,
 
 	/*
-	 * PCI_P2PDMA_MAP_NOT_SUPPORTED: Indicates the transaction will
-	 * traverse the host bridge and the host bridge is not in the
-	 * allowlist. DMA Mapping routines should return an error when
-	 * this is returned.
+	 * PCI_P2PDMA_MAP_NOT_SUPPORTED: Indicates no safe mapping is available,
+	 * for example because ACS blocks the direct path or the required host
+	 * bridge is not in the allowlist. DMA Mapping routines should return an
+	 * error when this is returned.
 	 */
 	PCI_P2PDMA_MAP_NOT_SUPPORTED,
 
@@ -82,6 +82,7 @@ struct scatterlist *pci_p2pmem_alloc_sgl(struct pci_dev *pdev,
 					 unsigned int *nents, u32 length);
 void pci_p2pmem_free_sgl(struct pci_dev *pdev, struct scatterlist *sgl);
 void pci_p2pmem_publish(struct pci_dev *pdev, bool publish);
+void pcim_p2pdma_set_ats_per_mapping(struct pci_dev *pdev);
 int pci_p2pdma_enable_store(const char *page, struct pci_dev **p2p_dev,
 			    bool *use_p2pdma);
 ssize_t pci_p2pdma_enable_show(char *page, struct pci_dev *p2p_dev,
@@ -138,6 +139,9 @@ static inline void pci_p2pmem_free_sgl(struct pci_dev *pdev,
 static inline void pci_p2pmem_publish(struct pci_dev *pdev, bool publish)
 {
 }
+static inline void pcim_p2pdma_set_ats_per_mapping(struct pci_dev *pdev)
+{
+}
 static inline int pci_p2pdma_enable_store(const char *page,
 		struct pci_dev **p2p_dev, bool *use_p2pdma)
 {

3/2 2026/11/08 03:20 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 42993
							output: 22
							thoughts: 514
						

Thoughts:
**Fuzzing Feasibility Evaluation: PCI P2PDMA Patch Series**

Okay, let's break this down. My initial assessment is that we need to determine if this patch series warrants a full syzkaller fuzzing campaign. First, I need to get a solid understanding of the changes.

Looking at the diff, it's pretty clear that this is a significant rework. It's not just a minor bug fix. We have documentation updates, Kconfig and Makefile changes that look to be enabling a KUnit test, and then the core of the work is in the `drivers/pci/p2pdma.c` file. This looks like the big ticket item. I see a *major* rework and enhancements, dealing with ACS evaluation for peer-to-peer DMA – lots of new functions with `pci_acs_p2pdma_*` as well as changes to existing functions like `calc_map_type_and_dist` and `pci_p2pdma_map_type`. We've got `pcim_p2pdma_set_ats_per_mapping` being added too, which seems significant.

There are also related changes in `pci.c`, `pci.h`, `pci_acs_test.c`, and `quirks.c`, mostly definitions, and test suites, and quirk related changes. And of course the addition of a header file.

Now, the crucial question: can we reach this code and fuzz it effectively? Reachability and fuzzability are the key considerations. What triggers PCI P2PDMA? How is this functionality exposed? Can it be triggered from userspace? Can syzkaller reach it? We need to figure out the entry points. I should probably start by grepping the kernel source for calls to the `pci_p2pdma_*` functions, and tracing back from there. That will give me a good picture of where it's used and what the potential attack surfaces are. From there I'll have a much better handle on whether or not this warrants the fuzzing effort.



4/2 2026/11/08 03:20 tool grepper
0m Args:
{
  "Expression": "pci_p2pdma_"
}

Results:
{
  "Output": "\nFull output is too long, showing 200 out of 881 lines.\nUse more precise expression or PathPrefixes if possible.\n\nNumber of matching lines per file (31 files in total):\nDocumentation/driver-api/pci/p2pdma.rst:3\nblock/bio-integrity.c:1\nblock/bio.c:2\nblock/blk-mq-dma.c:2\nblock/blk.h:1\ndrivers/accel/habanalabs/common/hldio.c:2\ndrivers/accel/habanalabs/common/memory.c:1\ndrivers/dma-buf/dma-buf-mapping.c:3\ndrivers/gpu/drm/amd/amdgpu/amdgpu_device.c:1\ndrivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c:1\ndrivers/gpu/drm/xe/xe_dma_buf.c:1\ndrivers/gpu/drm/xe/xe_svm.c:1\ndrivers/infiniband/hw/mlx5/odp.c:1\ndrivers/iommu/dma-iommu.c:3\ndrivers/nvme/host/pci.c:6\ndrivers/nvme/target/configfs.c:2\ndrivers/nvme/target/core.c:2\ndrivers/nvme/target/io-cmd-bdev.c:1\ndrivers/pci/p2pdma.c:114\ndrivers/pci/pci.h:9\ndrivers/pci/pci_acs_test.c:18\ninclude/linux/blk-mq-dma.h:2\ninclude/linux/dma-mapping.h:2\ninclude/linux/hmm-dma.h:2\ninclude/linux/memremap.h:1\ninclude/linux/pci-p2pdma.h:25\ninclude/rdma/ib_verbs.h:1\nkernel/dma/direct.c:3\nkernel/dma/mapping.c:2\nmm/gup.c:1\nmm/hmm.c:3\n\nDocumentation/driver-api/pci/p2pdma.rst=62=P2PDMA therefore decides each class of traffic separately, and\nDocumentation/driver-api/pci/p2pdma.rst:63:``pci_p2pdma_map_type()`` answers for the one a DMA mapping is built for:\nDocumentation/driver-api/pci/p2pdma.rst-64-strictly ordered Requests carrying an Untranslated address.\n--\nDocumentation/driver-api/pci/p2pdma.rst=201=A provider simply needs to register a BAR (or a portion of a BAR)\nDocumentation/driver-api/pci/p2pdma.rst:202:as a P2P DMA resource using :c:func:`pci_p2pdma_add_resource()`.\nDocumentation/driver-api/pci/p2pdma.rst-203-This will register struct pages for all the specified memory.\n--\nDocumentation/driver-api/pci/p2pdma.rst=230=a specific P2P provider to use it may check compatibility using\nDocumentation/driver-api/pci/p2pdma.rst:231::c:func:`pci_p2pdma_distance()` otherwise it may find a memory provider\nDocumentation/driver-api/pci/p2pdma.rst-232-that's compatible with all clients using  :c:func:`pci_p2pmem_find()`.\n--\nblock/bio-integrity.c=334=static unsigned int bvec_from_pages(struct bio_vec *bvec, struct page **pages,\n--\nblock/bio-integrity.c-356-\nblock/bio-integrity.c:357:\t\tif (is_pci_p2pdma_page(pages[i]))\nblock/bio-integrity.c-358-\t\t\t*is_p2p = true;\n--\nblock/bio.c=1030=void __bio_add_page(struct bio *bio, struct page *page,\n--\nblock/bio.c-1035-\nblock/bio.c:1036:\tif (is_pci_p2pdma_page(page))\nblock/bio.c-1037-\t\tbio-\u003ebi_opf |= REQ_NOMERGE;\n--\nblock/bio.c=1343=int bio_iov_iter_get_pages(struct bio *bio, struct iov_iter *iter,\n--\nblock/bio.c-1388-\nblock/bio.c:1389:\tif (is_pci_p2pdma_page(bio-\u003ebi_io_vec-\u003ebv_page))\nblock/bio.c-1390-\t\tbio-\u003ebi_opf |= REQ_NOMERGE;\n--\nblock/blk-mq-dma.c=80=static bool blk_dma_map_bus(struct blk_dma_iter *iter, struct phys_vec *vec)\nblock/blk-mq-dma.c-81-{\nblock/blk-mq-dma.c:82:\titer-\u003eaddr = pci_p2pdma_bus_addr_map(iter-\u003ep2pdma.mem, vec-\u003epaddr);\nblock/blk-mq-dma.c-83-\titer-\u003elen = vec-\u003elen;\n--\nblock/blk-mq-dma.c=164=static bool blk_dma_map_iter_start(struct request *req, struct device *dma_dev,\n--\nblock/blk-mq-dma.c-180-\nblock/blk-mq-dma.c:181:\tswitch (pci_p2pdma_state(\u0026iter-\u003ep2pdma, dma_dev,\nblock/blk-mq-dma.c-182-\t\t\t\t phys_to_page(vec.paddr))) {\n--\nblock/blk.h=156=static inline bool zone_device_pages_compatible(const struct page *a,\n--\nblock/blk.h-158-{\nblock/blk.h:159:\tif (is_pci_p2pdma_page(a) || is_pci_p2pdma_page(b))\nblock/blk.h-160-\t\treturn zone_device_pages_have_same_pgmap(a, b);\n--\ndrivers/accel/habanalabs/common/hldio.c=67=static int hl_dio_fd_register(struct hl_ctx *ctx, int fd, struct hl_dio_fd *f)\n--\ndrivers/accel/habanalabs/common/hldio.c-112-\tdisk_dev = disk_to_dev(gd);\ndrivers/accel/habanalabs/common/hldio.c:113:\tif (!dma_pci_p2pdma_supported(disk_dev)) {\ndrivers/accel/habanalabs/common/hldio.c-114-\t\tdev_err(hdev-\u003edev, \"device does not support PCI P2P DMA\\n\");\n--\ndrivers/accel/habanalabs/common/hldio.c=369=int hl_p2p_region_init(struct hl_device *hdev, struct hl_p2p_region *p2pr)\n--\ndrivers/accel/habanalabs/common/hldio.c-374-\t/* Start by publishing our p2p memory */\ndrivers/accel/habanalabs/common/hldio.c:375:\trc = pci_p2pdma_add_resource(hdev-\u003epdev, p2pr-\u003ebar, p2pr-\u003esize, p2pr-\u003ebar_offset);\ndrivers/accel/habanalabs/common/hldio.c-376-\tif (rc) {\n--\ndrivers/accel/habanalabs/common/memory.c=1707=static int hl_dmabuf_attach(struct dma_buf *dmabuf,\n--\ndrivers/accel/habanalabs/common/memory.c-1716-\ndrivers/accel/habanalabs/common/memory.c:1717:\trc = pci_p2pdma_distance(hdev-\u003epdev, attachment-\u003edev, true);\ndrivers/accel/habanalabs/common/memory.c-1718-\n--\ndrivers/dma-buf/dma-buf-mapping.c=71=struct dma_buf_dma {\n--\ndrivers/dma-buf/dma-buf-mapping.c-96- * NOTE: This function is intended for exporters. If direct traffic routing is\ndrivers/dma-buf/dma-buf-mapping.c:97: * mandatory exporter should call routing pci_p2pdma_map_type() before calling\ndrivers/dma-buf/dma-buf-mapping.c-98- * this function.\n--\ndrivers/dma-buf/dma-buf-mapping.c=100=struct sg_table *dma_buf_phys_vec_to_sgt(struct dma_buf_attachment *attach,\n--\ndrivers/dma-buf/dma-buf-mapping.c-123-\ndrivers/dma-buf/dma-buf-mapping.c:124:\tswitch (pci_p2pdma_map_type(provider, attach-\u003edev)) {\ndrivers/dma-buf/dma-buf-mapping.c-125-\tcase PCI_P2PDMA_MAP_BUS_ADDR:\n--\ndrivers/dma-buf/dma-buf-mapping.c-154-\t\tif (!dma-\u003estate) {\ndrivers/dma-buf/dma-buf-mapping.c:155:\t\t\taddr = pci_p2pdma_bus_addr_map(provider,\ndrivers/dma-buf/dma-buf-mapping.c-156-\t\t\t\t\t\t       phys_vec[i].paddr);\n--\ndrivers/gpu/drm/amd/amdgpu/amdgpu_device.c=6179=bool amdgpu_device_is_peer_accessible(struct amdgpu_device *adev,\n--\ndrivers/gpu/drm/amd/amdgpu/amdgpu_device.c-6184-\t\t!adev-\u003egmc.xgmi.connected_to_cpu \u0026\u0026\ndrivers/gpu/drm/amd/amdgpu/amdgpu_device.c:6185:\t\t!(pci_p2pdma_distance(adev-\u003epdev, peer_adev-\u003edev, false) \u003c 0);\ndrivers/gpu/drm/amd/amdgpu/amdgpu_device.c-6186-\tif (!p2p_access)\n--\ndrivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c=79=static int amdgpu_dma_buf_attach(struct dma_buf *dmabuf,\n--\ndrivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c-100-\tif (!amdgpu_dmabuf_is_xgmi_accessible(attach_adev, bo) \u0026\u0026\ndrivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c:101:\t    pci_p2pdma_distance(adev-\u003epdev, attach-\u003edev, false) \u003c 0)\ndrivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c-102-\t\tattach-\u003epeer2peer = false;\n--\ndrivers/gpu/drm/xe/xe_dma_buf.c=39=static int xe_dma_buf_attach(struct dma_buf *dmabuf,\n--\ndrivers/gpu/drm/xe/xe_dma_buf.c-47-\tif (attach-\u003epeer2peer \u0026\u0026\ndrivers/gpu/drm/xe/xe_dma_buf.c:48:\t    pci_p2pdma_distance(to_pci_dev(obj-\u003edev-\u003edev), attach-\u003edev, verbose_p2p_dist) \u003c 0)\ndrivers/gpu/drm/xe/xe_dma_buf.c-49-\t\tattach-\u003epeer2peer = false;\n--\ndrivers/gpu/drm/xe/xe_svm.c=888=static bool xe_has_interconnect(struct drm_pagemap_peer *peer1,\n--\ndrivers/gpu/drm/xe/xe_svm.c-896-\ndrivers/gpu/drm/xe/xe_svm.c:897:\treturn pci_p2pdma_distance(to_pci_dev(dev1), dev2, true) \u003e= 0;\ndrivers/gpu/drm/xe/xe_svm.c-898-}\n--\ndrivers/infiniband/hw/mlx5/odp.c=159=static int populate_mtt(__be64 *pas, size_t start, size_t nentries,\n--\ndrivers/infiniband/hw/mlx5/odp.c-163-\tbool downgrade = flags \u0026 MLX5_IB_UPD_XLT_DOWNGRADE;\ndrivers/infiniband/hw/mlx5/odp.c:164:\tstruct pci_p2pdma_map_state p2pdma_state = {};\ndrivers/infiniband/hw/mlx5/odp.c-165-\tstruct ib_device *dev = odp-\u003eumem.ibdev;\n--\ndrivers/iommu/dma-iommu.c=1413=int iommu_dma_map_sg(struct device *dev, struct scatterlist *sg, int nents,\n--\ndrivers/iommu/dma-iommu.c-1420-\tint prot = dma_info_to_prot(dir, dev_is_dma_coherent(dev), attrs);\ndrivers/iommu/dma-iommu.c:1421:\tstruct pci_p2pdma_map_state p2pdma_state = {};\ndrivers/iommu/dma-iommu.c-1422-\tdma_addr_t iova;\n--\ndrivers/iommu/dma-iommu.c-1450-\ndrivers/iommu/dma-iommu.c:1451:\t\tswitch (pci_p2pdma_state(\u0026p2pdma_state, dev, sg_page(s))) {\ndrivers/iommu/dma-iommu.c-1452-\t\tcase PCI_P2PDMA_MAP_THRU_HOST_BRIDGE:\n--\ndrivers/iommu/dma-iommu.c-1466-\t\t\t */\ndrivers/iommu/dma-iommu.c:1467:\t\t\ts-\u003edma_address = pci_p2pdma_bus_addr_map(\ndrivers/iommu/dma-iommu.c-1468-\t\t\t\tp2pdma_state.mem, sg_phys(s));\n--\ndrivers/nvme/host/pci.c=972=static void nvme_unmap_metadata(struct request *req)\n--\ndrivers/nvme/host/pci.c-974-\tstruct nvme_queue *nvmeq = req-\u003emq_hctx-\u003edriver_data;\ndrivers/nvme/host/pci.c:975:\tenum pci_p2pdma_map_type map = PCI_P2PDMA_MAP_NONE;\ndrivers/nvme/host/pci.c-976-\tenum dma_data_direction dir = rq_dma_dir(req);\n--\ndrivers/nvme/host/pci.c=1010=static void nvme_unmap_data(struct request *req)\ndrivers/nvme/host/pci.c-1011-{\ndrivers/nvme/host/pci.c:1012:\tenum pci_p2pdma_map_type map = PCI_P2PDMA_MAP_NONE;\ndrivers/nvme/host/pci.c-1013-\tstruct nvme_iod *iod = blk_mq_rq_to_pdu(req);\n--\ndrivers/nvme/host/pci.c=1430=static blk_status_t nvme_pci_setup_data_simple(struct request *req,\n--\ndrivers/nvme/host/pci.c-1441-\t\treturn BLK_STS_AGAIN;\ndrivers/nvme/host/pci.c:1442:\tif (is_pci_p2pdma_page(bv.bv_page))\ndrivers/nvme/host/pci.c-1443-\t\treturn BLK_STS_AGAIN;\n--\ndrivers/nvme/host/pci.c=1599=static blk_status_t nvme_pci_setup_meta_mptr(struct request *req)\n--\ndrivers/nvme/host/pci.c-1604-\ndrivers/nvme/host/pci.c:1605:\tif (is_pci_p2pdma_page(bv.bv_page))\ndrivers/nvme/host/pci.c-1606-\t\treturn nvme_pci_setup_meta_iter(req);\n--\ndrivers/nvme/host/pci.c=2696=static void nvme_map_cmb(struct nvme_dev *dev)\n--\ndrivers/nvme/host/pci.c-2743-\ndrivers/nvme/host/pci.c:2744:\tif (pci_p2pdma_add_resource(pdev, bar, size, offset)) {\ndrivers/nvme/host/pci.c-2745-\t\tdev_warn(dev-\u003ectrl.device,\n--\ndrivers/nvme/host/pci.c=3773=static bool nvme_pci_supports_pci_p2pdma(struct nvme_ctrl *ctrl)\n--\ndrivers/nvme/host/pci.c-3776-\ndrivers/nvme/host/pci.c:3777:\treturn dma_pci_p2pdma_supported(dev-\u003edev);\ndrivers/nvme/host/pci.c-3778-}\n--\ndrivers/nvme/target/configfs.c=576=static ssize_t nvmet_ns_p2pmem_show(struct config_item *item, char *page)\n--\ndrivers/nvme/target/configfs.c-579-\ndrivers/nvme/target/configfs.c:580:\treturn pci_p2pdma_enable_show(page, ns-\u003ep2p_dev, ns-\u003euse_p2pmem);\ndrivers/nvme/target/configfs.c-581-}\n--\ndrivers/nvme/target/configfs.c=583=static ssize_t nvmet_ns_p2pmem_store(struct config_item *item,\n--\ndrivers/nvme/target/configfs.c-597-\ndrivers/nvme/target/configfs.c:598:\terror = pci_p2pdma_enable_store(page, \u0026p2p_dev, \u0026use_p2pmem);\ndrivers/nvme/target/configfs.c-599-\tif (error) {\n--\ndrivers/nvme/target/core.c=492=static int nvmet_p2pmem_ns_enable(struct nvmet_ns *ns)\n--\ndrivers/nvme/target/core.c-511-\tif (ns-\u003ep2p_dev) {\ndrivers/nvme/target/core.c:512:\t\tret = pci_p2pdma_distance(ns-\u003ep2p_dev, nvmet_ns_dev(ns), true);\ndrivers/nvme/target/core.c-513-\t\tif (ret \u003c 0)\n--\ndrivers/nvme/target/core.c=536=static void nvmet_p2pmem_ns_add_p2p(struct nvmet_ctrl *ctrl,\n--\ndrivers/nvme/target/core.c-548-\tif (ns-\u003ep2p_dev) {\ndrivers/nvme/target/core.c:549:\t\tret = pci_p2pdma_distance(ns-\u003ep2p_dev, ctrl-\u003ep2p_client, true);\ndrivers/nvme/target/core.c-550-\t\tif (ret \u003c 0)\n--\ndrivers/nvme/target/io-cmd-bdev.c=253=static void nvmet_bdev_execute_rw(struct nvmet_req *req)\n--\ndrivers/nvme/target/io-cmd-bdev.c-286-\ndrivers/nvme/target/io-cmd-bdev.c:287:\tif (is_pci_p2pdma_page(sg_page(req-\u003esg)))\ndrivers/nvme/target/io-cmd-bdev.c-288-\t\topf |= REQ_NOMERGE;\n--\ndrivers/pci/p2pdma.c=26=struct pci_p2pdma {\n--\ndrivers/pci/p2pdma.c-33-\ndrivers/pci/p2pdma.c:34:struct pci_p2pdma_pagemap {\ndrivers/pci/p2pdma.c-35-\tstruct dev_pagemap pgmap;\n--\ndrivers/pci/p2pdma.c-38-\ndrivers/pci/p2pdma.c:39:static struct pci_p2pdma_pagemap *to_p2p_pgmap(struct dev_pagemap *pgmap)\ndrivers/pci/p2pdma.c-40-{\ndrivers/pci/p2pdma.c:41:\treturn container_of(pgmap, struct pci_p2pdma_pagemap, pgmap);\n\n"
}

5/2 2026/11/08 03:20 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 49408
							output: 35
							thoughts: 55
						

Thoughts:
Okay, here's my summary, tailored as if I'm thinking it:

**Investigating `pci_p2pdma_map_type` Calls**

Alright, I need to get a clear understanding of how the `pci_p2pdma_map_type` function is actually *used* within the kernel. I can't just rely on the documentation; I need to see it in context. So, the first logical step is a quick search. I'll fire up `grep` (or whatever search tool I prefer, probably ripgrep for speed) and look for instances of *both* `pci_p2pdma_map_type` and its potential related function, `pci_p2pdma_distance`. This should give me a good overview of the call sites and how the function is intended to be used. I expect to find some patterns emerge and by extension, where the function is most critical. This is standard operating procedure - understand usage to understand the function's purpose!



6/2 2026/11/08 03:21 tool grepper
0m Args:
{
  "Expression": "pci_p2pdma_map_type|pci_p2pdma_distance"
}

Results:
{
  "Output": "\nFull output is too long, showing 200 out of 332 lines.\nUse more precise expression or PathPrefixes if possible.\n\nNumber of matching lines per file (14 files in total):\nDocumentation/driver-api/pci/p2pdma.rst:2\ndrivers/accel/habanalabs/common/memory.c:1\ndrivers/dma-buf/dma-buf-mapping.c:2\ndrivers/gpu/drm/amd/amdgpu/amdgpu_device.c:1\ndrivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c:1\ndrivers/gpu/drm/xe/xe_dma_buf.c:1\ndrivers/gpu/drm/xe/xe_svm.c:1\ndrivers/nvme/host/pci.c:2\ndrivers/nvme/target/core.c:2\ndrivers/pci/p2pdma.c:34\ndrivers/pci/pci.h:5\ndrivers/pci/pci_acs_test.c:14\ninclude/linux/blk-mq-dma.h:1\ninclude/linux/pci-p2pdma.h:10\n\nDocumentation/driver-api/pci/p2pdma.rst=62=P2PDMA therefore decides each class of traffic separately, and\nDocumentation/driver-api/pci/p2pdma.rst:63:``pci_p2pdma_map_type()`` answers for the one a DMA mapping is built for:\nDocumentation/driver-api/pci/p2pdma.rst-64-strictly ordered Requests carrying an Untranslated address.\n--\nDocumentation/driver-api/pci/p2pdma.rst=230=a specific P2P provider to use it may check compatibility using\nDocumentation/driver-api/pci/p2pdma.rst:231::c:func:`pci_p2pdma_distance()` otherwise it may find a memory provider\nDocumentation/driver-api/pci/p2pdma.rst-232-that's compatible with all clients using  :c:func:`pci_p2pmem_find()`.\n--\ndrivers/accel/habanalabs/common/memory.c=1707=static int hl_dmabuf_attach(struct dma_buf *dmabuf,\n--\ndrivers/accel/habanalabs/common/memory.c-1716-\ndrivers/accel/habanalabs/common/memory.c:1717:\trc = pci_p2pdma_distance(hdev-\u003epdev, attachment-\u003edev, true);\ndrivers/accel/habanalabs/common/memory.c-1718-\n--\ndrivers/dma-buf/dma-buf-mapping.c=71=struct dma_buf_dma {\n--\ndrivers/dma-buf/dma-buf-mapping.c-96- * NOTE: This function is intended for exporters. If direct traffic routing is\ndrivers/dma-buf/dma-buf-mapping.c:97: * mandatory exporter should call routing pci_p2pdma_map_type() before calling\ndrivers/dma-buf/dma-buf-mapping.c-98- * this function.\n--\ndrivers/dma-buf/dma-buf-mapping.c=100=struct sg_table *dma_buf_phys_vec_to_sgt(struct dma_buf_attachment *attach,\n--\ndrivers/dma-buf/dma-buf-mapping.c-123-\ndrivers/dma-buf/dma-buf-mapping.c:124:\tswitch (pci_p2pdma_map_type(provider, attach-\u003edev)) {\ndrivers/dma-buf/dma-buf-mapping.c-125-\tcase PCI_P2PDMA_MAP_BUS_ADDR:\n--\ndrivers/gpu/drm/amd/amdgpu/amdgpu_device.c=6179=bool amdgpu_device_is_peer_accessible(struct amdgpu_device *adev,\n--\ndrivers/gpu/drm/amd/amdgpu/amdgpu_device.c-6184-\t\t!adev-\u003egmc.xgmi.connected_to_cpu \u0026\u0026\ndrivers/gpu/drm/amd/amdgpu/amdgpu_device.c:6185:\t\t!(pci_p2pdma_distance(adev-\u003epdev, peer_adev-\u003edev, false) \u003c 0);\ndrivers/gpu/drm/amd/amdgpu/amdgpu_device.c-6186-\tif (!p2p_access)\n--\ndrivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c=79=static int amdgpu_dma_buf_attach(struct dma_buf *dmabuf,\n--\ndrivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c-100-\tif (!amdgpu_dmabuf_is_xgmi_accessible(attach_adev, bo) \u0026\u0026\ndrivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c:101:\t    pci_p2pdma_distance(adev-\u003epdev, attach-\u003edev, false) \u003c 0)\ndrivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c-102-\t\tattach-\u003epeer2peer = false;\n--\ndrivers/gpu/drm/xe/xe_dma_buf.c=39=static int xe_dma_buf_attach(struct dma_buf *dmabuf,\n--\ndrivers/gpu/drm/xe/xe_dma_buf.c-47-\tif (attach-\u003epeer2peer \u0026\u0026\ndrivers/gpu/drm/xe/xe_dma_buf.c:48:\t    pci_p2pdma_distance(to_pci_dev(obj-\u003edev-\u003edev), attach-\u003edev, verbose_p2p_dist) \u003c 0)\ndrivers/gpu/drm/xe/xe_dma_buf.c-49-\t\tattach-\u003epeer2peer = false;\n--\ndrivers/gpu/drm/xe/xe_svm.c=888=static bool xe_has_interconnect(struct drm_pagemap_peer *peer1,\n--\ndrivers/gpu/drm/xe/xe_svm.c-896-\ndrivers/gpu/drm/xe/xe_svm.c:897:\treturn pci_p2pdma_distance(to_pci_dev(dev1), dev2, true) \u003e= 0;\ndrivers/gpu/drm/xe/xe_svm.c-898-}\n--\ndrivers/nvme/host/pci.c=972=static void nvme_unmap_metadata(struct request *req)\n--\ndrivers/nvme/host/pci.c-974-\tstruct nvme_queue *nvmeq = req-\u003emq_hctx-\u003edriver_data;\ndrivers/nvme/host/pci.c:975:\tenum pci_p2pdma_map_type map = PCI_P2PDMA_MAP_NONE;\ndrivers/nvme/host/pci.c-976-\tenum dma_data_direction dir = rq_dma_dir(req);\n--\ndrivers/nvme/host/pci.c=1010=static void nvme_unmap_data(struct request *req)\ndrivers/nvme/host/pci.c-1011-{\ndrivers/nvme/host/pci.c:1012:\tenum pci_p2pdma_map_type map = PCI_P2PDMA_MAP_NONE;\ndrivers/nvme/host/pci.c-1013-\tstruct nvme_iod *iod = blk_mq_rq_to_pdu(req);\n--\ndrivers/nvme/target/core.c=492=static int nvmet_p2pmem_ns_enable(struct nvmet_ns *ns)\n--\ndrivers/nvme/target/core.c-511-\tif (ns-\u003ep2p_dev) {\ndrivers/nvme/target/core.c:512:\t\tret = pci_p2pdma_distance(ns-\u003ep2p_dev, nvmet_ns_dev(ns), true);\ndrivers/nvme/target/core.c-513-\t\tif (ret \u003c 0)\n--\ndrivers/nvme/target/core.c=536=static void nvmet_p2pmem_ns_add_p2p(struct nvmet_ctrl *ctrl,\n--\ndrivers/nvme/target/core.c-548-\tif (ns-\u003ep2p_dev) {\ndrivers/nvme/target/core.c:549:\t\tret = pci_p2pdma_distance(ns-\u003ep2p_dev, ctrl-\u003ep2p_client, true);\ndrivers/nvme/target/core.c-550-\t\tif (ret \u003c 0)\n--\ndrivers/pci/p2pdma.c=589=static const char *pci_acs_p2pdma_state_name(enum pci_acs_p2pdma_state state)\n--\ndrivers/pci/p2pdma.c-604-\ndrivers/pci/p2pdma.c:605:static const char *pci_p2pdma_map_type_name(enum pci_p2pdma_map_type type)\ndrivers/pci/p2pdma.c-606-{\n--\ndrivers/pci/p2pdma.c=915=pci_p2pdma_completion_state(const struct pci_p2pdma_acs_path *path,\n--\ndrivers/pci/p2pdma.c-928- */\ndrivers/pci/p2pdma.c:929:static enum pci_p2pdma_map_type\ndrivers/pci/p2pdma.c-930-pci_p2pdma_route(const struct pci_p2pdma_acs_path *path,\n--\ndrivers/pci/p2pdma.c=1185=VISIBLE_IF_KUNIT unsigned long\ndrivers/pci/p2pdma.c:1186:pci_p2pdma_map_types_pack(const enum pci_p2pdma_map_type *type)\ndrivers/pci/p2pdma.c-1187-{\n--\ndrivers/pci/p2pdma.c-1195-}\ndrivers/pci/p2pdma.c:1196:EXPORT_SYMBOL_IF_KUNIT(pci_p2pdma_map_types_pack);\ndrivers/pci/p2pdma.c-1197-\ndrivers/pci/p2pdma.c:1198:VISIBLE_IF_KUNIT enum pci_p2pdma_map_type\ndrivers/pci/p2pdma.c:1199:pci_p2pdma_map_types_unpack(unsigned long val, unsigned int tlp_flags)\ndrivers/pci/p2pdma.c-1200-{\n--\ndrivers/pci/p2pdma.c-1202-}\ndrivers/pci/p2pdma.c:1203:EXPORT_SYMBOL_IF_KUNIT(pci_p2pdma_map_types_unpack);\ndrivers/pci/p2pdma.c-1204-\n--\ndrivers/pci/p2pdma.c-1252- */\ndrivers/pci/p2pdma.c:1253:VISIBLE_IF_KUNIT enum pci_p2pdma_map_type\ndrivers/pci/p2pdma.c-1254-calc_map_type_and_dist(struct pci_dev *provider, struct pci_dev *client,\n--\ndrivers/pci/p2pdma.c-1256-{\ndrivers/pci/p2pdma.c:1257:\tenum pci_p2pdma_map_type map_type[PCI_P2PDMA_TLP_CLASSES];\ndrivers/pci/p2pdma.c-1258-\tstruct pci_dev *a = provider, *b = client, *bb;\n--\ndrivers/pci/p2pdma.c-1441-\t\told = xa_store(\u0026p2pdma-\u003emap_types, map_types_idx(client),\ndrivers/pci/p2pdma.c:1442:\t\t\t       xa_mk_value(pci_p2pdma_map_types_pack(map_type)),\ndrivers/pci/p2pdma.c-1443-\t\t\t       GFP_ATOMIC);\n--\ndrivers/pci/p2pdma.c-1450-\t\t\t pci_name(provider),\ndrivers/pci/p2pdma.c:1451:\t\t\t pci_p2pdma_map_type_name(map_type[tlp_flags]),\ndrivers/pci/p2pdma.c-1452-\t\t\t map_type[tlp_flags], tlp_flags, *dist,\n--\ndrivers/pci/p2pdma.c-1456-\t\t\t\"P2PDMA ACS: classes strict=%s relaxed=%s translated=%s translated+relaxed=%s\\n\",\ndrivers/pci/p2pdma.c:1457:\t\t\t pci_p2pdma_map_type_name(map_type[0]),\ndrivers/pci/p2pdma.c:1458:\t\t\t pci_p2pdma_map_type_name(\ndrivers/pci/p2pdma.c-1459-\t\t\t\t map_type[PCI_P2PDMA_TLP_RELAXED_CPL]),\ndrivers/pci/p2pdma.c:1460:\t\t\t pci_p2pdma_map_type_name(\ndrivers/pci/p2pdma.c-1461-\t\t\t\t map_type[PCI_P2PDMA_TLP_TRANSLATED]),\ndrivers/pci/p2pdma.c:1462:\t\t\t pci_p2pdma_map_type_name(\ndrivers/pci/p2pdma.c-1463-\t\t\t\t map_type[PCI_P2PDMA_TLP_TRANSLATED |\n--\ndrivers/pci/p2pdma.c=1478=EXPORT_SYMBOL_IF_KUNIT(pci_p2pdma_client_tlp_flags);\n--\ndrivers/pci/p2pdma.c-1489- */\ndrivers/pci/p2pdma.c:1490:VISIBLE_IF_KUNIT enum pci_p2pdma_map_type\ndrivers/pci/p2pdma.c-1491-pci_p2pdma_client_map_type(struct pci_dev *provider, struct pci_dev *client,\ndrivers/pci/p2pdma.c-1492-\t\t\t   bool per_mapping, unsigned int tlp_flags,\ndrivers/pci/p2pdma.c:1493:\t\t\t   enum pci_p2pdma_map_type type)\ndrivers/pci/p2pdma.c-1494-{\n--\ndrivers/pci/p2pdma.c=1512=static bool pci_p2pdma_client_per_mapping(struct pci_dev *client)\n--\ndrivers/pci/p2pdma.c-1525-/**\ndrivers/pci/p2pdma.c:1526: * pci_p2pdma_distance_many - Determine the cumulative distance between\ndrivers/pci/p2pdma.c-1527- *\ta p2pdma provider and the clients in use.\n--\ndrivers/pci/p2pdma.c-1540- * are listed in the 'pci_p2pdma_whitelist'. Each client is judged the way\ndrivers/pci/p2pdma.c:1541: * pci_p2pdma_map_type() maps it, so one with ATS enabled for the whole device\ndrivers/pci/p2pdma.c-1542- * also needs a host bridge that supports peer-to-peer DMA.\ndrivers/pci/p2pdma.c-1543- */\ndrivers/pci/p2pdma.c:1544:int pci_p2pdma_distance_many(struct pci_dev *provider, struct device **clients,\ndrivers/pci/p2pdma.c-1545-\t\t\t     int num_clients, bool verbose)\ndrivers/pci/p2pdma.c-1546-{\ndrivers/pci/p2pdma.c:1547:\tenum pci_p2pdma_map_type map, type;\ndrivers/pci/p2pdma.c-1548-\tbool not_supported = false;\n--\ndrivers/pci/p2pdma.c-1595-}\ndrivers/pci/p2pdma.c:1596:EXPORT_SYMBOL_GPL(pci_p2pdma_distance_many);\ndrivers/pci/p2pdma.c-1597-\n--\ndrivers/pci/p2pdma.c=1637=struct pci_dev *pci_p2pmem_find_many(struct device **clients, int num_clients)\n--\ndrivers/pci/p2pdma.c-1654-\ndrivers/pci/p2pdma.c:1655:\t\tdistance = pci_p2pdma_distance_many(pdev, clients,\ndrivers/pci/p2pdma.c-1656-\t\t\t\t\t\t    num_clients, false);\n--\ndrivers/pci/p2pdma.c=1869=EXPORT_SYMBOL_GPL(pcim_p2pdma_set_ats_per_mapping);\n--\ndrivers/pci/p2pdma.c-1871-/**\ndrivers/pci/p2pdma.c:1872: * pci_p2pdma_map_type_tlp - Determine the mapping type for P2PDMA transfers\ndrivers/pci/p2pdma.c-1873- * @provider: P2PDMA provider structure\n--\ndrivers/pci/p2pdma.c-1890- */\ndrivers/pci/p2pdma.c:1891:static enum pci_p2pdma_map_type\ndrivers/pci/p2pdma.c:1892:pci_p2pdma_map_type_tlp(struct p2pdma_provider *provider, struct device *dev,\ndrivers/pci/p2pdma.c-1893-\t\t\tunsigned int tlp_flags)\n--\ndrivers/pci/p2pdma.c-1896-\tunsigned long cache_index, cached = 0;\ndrivers/pci/p2pdma.c:1897:\tenum pci_p2pdma_map_type type;\ndrivers/pci/p2pdma.c-1898-\tstruct pci_p2pdma *p2pdma;\n--\ndrivers/pci/p2pdma.c-1930-\trcu_read_unlock();\ndrivers/pci/p2pdma.c:1931:\ttype = pci_p2pdma_map_types_unpack(cached, tlp_flags);\ndrivers/pci/p2pdma.c-1932-\tpci_dbg(client,\n--\ndrivers/pci/p2pdma.c-1934-\t\t pci_name(pdev), cache_index, tlp_flags,\ndrivers/pci/p2pdma.c:1935:\t\t pci_p2pdma_map_type_name(type), type, provider_state);\ndrivers/pci/p2pdma.c-1936-\n--\ndrivers/pci/p2pdma.c-1945-/**\ndrivers/pci/p2pdma.c:1946: * pci_p2pdma_map_type - Determine the mapping type for P2PDMA transfers\ndrivers/pci/p2pdma.c-1947- * @provider: P2PDMA provider structure\n--\ndrivers/pci/p2pdma.c-1949- *\ndrivers/pci/p2pdma.c:1950: * Same as pci_p2pdma_map_type_tlp() for a client issuing strictly ordered\ndrivers/pci/p2pdma.c-1951- * Requests. Their Address Type is Untranslated unless the client enables ATS\n--\ndrivers/pci/p2pdma.c-1953- */\ndrivers/pci/p2pdma.c:1954:enum pci_p2pdma_map_type pci_p2pdma_map_type(struct p2pdma_provider *provider,\ndrivers/pci/p2pdma.c-1955-\t\t\t\t\t     struct device *dev)\ndrivers/pci/p2pdma.c-1956-{\ndrivers/pci/p2pdma.c:1957:\treturn pci_p2pdma_map_type_tlp(provider, dev, 0);\ndrivers/pci/p2pdma.c-1958-}\n--\ndrivers/pci/p2pdma.c=1960=void __pci_p2pdma_update_state(struct pci_p2pdma_map_state *state,\n--\n\n"
}

7/2 2026/11/08 03:21 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 55098
							output: 43
							thoughts: 97
						

Thoughts:
Okay, let's dive into this. Here's how I see this playing out:

**Examining PCI Peer-to-Peer DMA and User Space Interaction**

Alright, my first instinct is to trace the connections between `pci_p2pdma_map_type`, `pci_p2pdma_distance`, and how user space applications are able to utilize them. My attention is immediately drawn to the NVMe target, specifically the configfs implementation – that's often a key entry point for user-space configuration, I'll bet.

Aha! `nvmet_ns_p2pmem_store` looks interesting. It seems to call `pci_p2pdma_enable_store`. Now we're getting somewhere. `pci_p2pdma_enable_store` is the immediate next function to examine - what does it *do* exactly? That's where the real magic likely happens, the bridge between the NVMe setup and the PCI DMA enablement or configuration, I'm guessing. Let's see what that function reveals!



8/2 2026/11/08 03:21 tool grepper
0m Args:
{
  "Expression": "pci_p2pdma_enable_store",
  "PathPrefixes": [
    "drivers/pci/p2pdma.c"
  ]
}

Results:
{
  "Output": "drivers/pci/p2pdma.c=1960=void __pci_p2pdma_update_state(struct pci_p2pdma_map_state *state,\n--\ndrivers/pci/p2pdma.c-1972-/**\ndrivers/pci/p2pdma.c:1973: * pci_p2pdma_enable_store - parse a configfs/sysfs attribute store\ndrivers/pci/p2pdma.c-1974- *\t\tto enable p2pdma\n--\ndrivers/pci/p2pdma.c-1991- */\ndrivers/pci/p2pdma.c:1992:int pci_p2pdma_enable_store(const char *page, struct pci_dev **p2p_dev,\ndrivers/pci/p2pdma.c-1993-\t\t\t    bool *use_p2pdma)\n--\ndrivers/pci/p2pdma.c-2024-}\ndrivers/pci/p2pdma.c:2025:EXPORT_SYMBOL_GPL(pci_p2pdma_enable_store);\ndrivers/pci/p2pdma.c-2026-\n--\ndrivers/pci/p2pdma.c-2033- *\ndrivers/pci/p2pdma.c:2034: * Attributes that use pci_p2pdma_enable_store() should use this function\ndrivers/pci/p2pdma.c-2035- * to show the value of the attribute.\n"
}

9/2 2026/11/08 03:21 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 55874
							output: 40
							thoughts: 50
						

Thoughts:
Okay, here's my take on those thoughts, tailored for an expert audience:

**Diving into the PCI P2PDMA Implementation**

Alright, let's get down to it. I'm focusing on the `drivers/pci/p2pdma.c` file, specifically zeroing in on the `pci_p2pdma_enable_store` function and the surrounding sysfs and configfs attributes within the `p2pdma.c` module. I need to understand how these control the P2P DMA enablement. I'm assuming there's some sort of user-space interface – probably exposed via sysfs or possibly configfs – that allows configuration of P2P DMA features for PCI devices.

I'm interested in how the enabling/disabling is handled. What are the constraints, if any? What kind of checks are performed before the operation can be performed? What are the implications of enabling or disabling P2P DMA at run time, and are any resources locked or reserved? Are there any potential race conditions I need to be aware of? I'll probably be interested in knowing whether the implementation supports hot-plug and the configuration of DMA parameters per device. I'm curious about the specific sysfs/configfs attributes: the names, data types, and access methods. It's likely that a key concern will be security and potential DMA-related vulnerabilities. I need to get a clear picture of how those are addressed. Specifically, are there any address range checks, access control lists, or other mechanisms in place to prevent malicious DMA activity? I should also investigate how these attributes interface with the PCI subsystem, the DMA engine, and the interrupt controller. I have a hunch it's not a trivial implementation. I'm particularly keen to see how the implementation handles resource allocation and potential conflicts with other drivers or hardware features. I need to see how the code interfaces with the hardware and if it handles DMA remapping, if supported.



10/2 2026/11/08 03:21 tool read-file
0m Args:
{
  "File": "drivers/pci/p2pdma.c",
  "FirstLine": 1970,
  "LineCount": 80
}

Results:
{
  "Contents": "1970:\t}\n1971:\t\n1972:\t/**\n1973:\t * pci_p2pdma_enable_store - parse a configfs/sysfs attribute store\n1974:\t *\t\tto enable p2pdma\n1975:\t * @page: contents of the value to be stored\n1976:\t * @p2p_dev: returns the PCI device that was selected to be used\n1977:\t *\t\t(if one was specified in the stored value)\n1978:\t * @use_p2pdma: returns whether to enable p2pdma or not\n1979:\t *\n1980:\t * Parses an attribute value to decide whether to enable p2pdma.\n1981:\t * The value can select a PCI device (using its full BDF device\n1982:\t * name) or a boolean (in any format kstrtobool() accepts). A false\n1983:\t * value disables p2pdma, a true value expects the caller\n1984:\t * to automatically find a compatible device and specifying a PCI device\n1985:\t * expects the caller to use the specific provider.\n1986:\t *\n1987:\t * pci_p2pdma_enable_show() should be used as the show operation for\n1988:\t * the attribute.\n1989:\t *\n1990:\t * Returns 0 on success\n1991:\t */\n1992:\tint pci_p2pdma_enable_store(const char *page, struct pci_dev **p2p_dev,\n1993:\t\t\t\t    bool *use_p2pdma)\n1994:\t{\n1995:\t\tstruct device *dev;\n1996:\t\n1997:\t\tdev = bus_find_device_by_name(\u0026pci_bus_type, NULL, page);\n1998:\t\tif (dev) {\n1999:\t\t\t*use_p2pdma = true;\n2000:\t\t\t*p2p_dev = to_pci_dev(dev);\n2001:\t\n2002:\t\t\tif (!pci_has_p2pmem(*p2p_dev)) {\n2003:\t\t\t\tpci_err(*p2p_dev,\n2004:\t\t\t\t\t\"PCI device has no peer-to-peer memory: %s\\n\",\n2005:\t\t\t\t\tpage);\n2006:\t\t\t\tpci_dev_put(*p2p_dev);\n2007:\t\t\t\treturn -ENODEV;\n2008:\t\t\t}\n2009:\t\n2010:\t\t\treturn 0;\n2011:\t\t} else if ((page[0] == '0' || page[0] == '1') \u0026\u0026 !iscntrl(page[1])) {\n2012:\t\t\t/*\n2013:\t\t\t * If the user enters a PCI device that  doesn't exist\n2014:\t\t\t * like \"0000:01:00.1\", we don't want kstrtobool to think\n2015:\t\t\t * it's a '0' when it's clearly not what the user wanted.\n2016:\t\t\t * So we require 0's and 1's to be exactly one character.\n2017:\t\t\t */\n2018:\t\t} else if (!kstrtobool(page, use_p2pdma)) {\n2019:\t\t\treturn 0;\n2020:\t\t}\n2021:\t\n2022:\t\tpr_err(\"No such PCI device: %.*s\\n\", (int)strcspn(page, \"\\n\"), page);\n2023:\t\treturn -ENODEV;\n2024:\t}\n2025:\tEXPORT_SYMBOL_GPL(pci_p2pdma_enable_store);\n2026:\t\n2027:\t/**\n2028:\t * pci_p2pdma_enable_show - show a configfs/sysfs attribute indicating\n2029:\t *\t\twhether p2pdma is enabled\n2030:\t * @page: contents of the stored value\n2031:\t * @p2p_dev: the selected p2p device (NULL if no device is selected)\n2032:\t * @use_p2pdma: whether p2pdma has been enabled\n2033:\t *\n2034:\t * Attributes that use pci_p2pdma_enable_store() should use this function\n2035:\t * to show the value of the attribute.\n2036:\t *\n2037:\t * Returns 0 on success\n2038:\t */\n2039:\tssize_t pci_p2pdma_enable_show(char *page, struct pci_dev *p2p_dev,\n2040:\t\t\t\t       bool use_p2pdma)\n2041:\t{\n2042:\t\tif (!use_p2pdma)\n2043:\t\t\treturn sprintf(page, \"0\\n\");\n2044:\t\n2045:\t\tif (!p2p_dev)\n2046:\t\t\treturn sprintf(page, \"1\\n\");\n2047:\t\n2048:\t\treturn sprintf(page, \"%s\\n\", pci_name(p2p_dev));\n2049:\t}\n"
}

11/2 2026/11/08 03:21 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 57744
							output: 35
							thoughts: 51
						

Thoughts:
Okay, let's dive into this. Here's how I'd approach this task, thinking through it step-by-step:

**Finding P2PDMA and P2PMEM Devices**

Right, my goal here is to identify which devices are advertising themselves as P2PDMA providers or, alternatively, publishing p2pmem. I need to figure out what's advertising this capability. The easiest way to start is by looking for those specific function calls.

I'm thinking, "Okay, how do I actually *find* this information within the source code?" The system I'm working with must provide hooks for the device. I'll need to use `grep`. Specifically, I know those devices need to register to use these features.

My thinking is `grep` for the function calls that register those resources, the key functions like `pci_p2pdma_add_resource` and `pci_p2pmem_publish`. Those are the usual suspects for this kind of functionality and the best place to start. That should give me a good list to work with. I'll see where those functions are called and I'll see what the callers are doing. It's the standard procedure for getting a list of resources. From there, I can determine which devices are providing those services.



12/2 2026/11/08 03:21 tool grepper
0m Args:
{
  "Expression": "pci_p2pdma_add_resource|pci_p2pmem_publish"
}

Results:
{
  "Output": "Documentation/driver-api/pci/p2pdma.rst=201=A provider simply needs to register a BAR (or a portion of a BAR)\nDocumentation/driver-api/pci/p2pdma.rst:202:as a P2P DMA resource using :c:func:`pci_p2pdma_add_resource()`.\nDocumentation/driver-api/pci/p2pdma.rst-203-This will register struct pages for all the specified memory.\n--\nDocumentation/driver-api/pci/p2pdma.rst=205=After that it may optionally publish all of its resources as\nDocumentation/driver-api/pci/p2pdma.rst:206:P2P memory using :c:func:`pci_p2pmem_publish()`. This will allow\nDocumentation/driver-api/pci/p2pdma.rst-207-any orchestrator drivers to find and use the memory. When marked in\n--\ndrivers/accel/habanalabs/common/hldio.c=369=int hl_p2p_region_init(struct hl_device *hdev, struct hl_p2p_region *p2pr)\n--\ndrivers/accel/habanalabs/common/hldio.c-374-\t/* Start by publishing our p2p memory */\ndrivers/accel/habanalabs/common/hldio.c:375:\trc = pci_p2pdma_add_resource(hdev-\u003epdev, p2pr-\u003ebar, p2pr-\u003esize, p2pr-\u003ebar_offset);\ndrivers/accel/habanalabs/common/hldio.c-376-\tif (rc) {\n--\ndrivers/nvme/host/pci.c=2696=static void nvme_map_cmb(struct nvme_dev *dev)\n--\ndrivers/nvme/host/pci.c-2743-\ndrivers/nvme/host/pci.c:2744:\tif (pci_p2pdma_add_resource(pdev, bar, size, offset)) {\ndrivers/nvme/host/pci.c-2745-\t\tdev_warn(dev-\u003ectrl.device,\n--\ndrivers/nvme/host/pci.c-2755-\t\t\t(NVME_CMBSZ_WDS | NVME_CMBSZ_RDS))\ndrivers/nvme/host/pci.c:2756:\t\tpci_p2pmem_publish(pdev, true);\ndrivers/nvme/host/pci.c-2757-}\n--\ndrivers/pci/p2pdma.c=365=static void pci_p2pdma_unmap_mappings(void *data)\n--\ndrivers/pci/p2pdma.c-379-/**\ndrivers/pci/p2pdma.c:380: * pci_p2pdma_add_resource - add memory for use as p2p memory\ndrivers/pci/p2pdma.c-381- * @pdev: the device to add the memory to\n--\ndrivers/pci/p2pdma.c-388- */\ndrivers/pci/p2pdma.c:389:int pci_p2pdma_add_resource(struct pci_dev *pdev, int bar, size_t size,\ndrivers/pci/p2pdma.c-390-\t\t\t    u64 offset)\n--\ndrivers/pci/p2pdma.c-470-}\ndrivers/pci/p2pdma.c:471:EXPORT_SYMBOL_GPL(pci_p2pdma_add_resource);\ndrivers/pci/p2pdma.c-472-\n--\ndrivers/pci/p2pdma.c=1817=EXPORT_SYMBOL_GPL(pci_p2pmem_free_sgl);\n--\ndrivers/pci/p2pdma.c-1819-/**\ndrivers/pci/p2pdma.c:1820: * pci_p2pmem_publish - publish the peer-to-peer DMA memory for use by\ndrivers/pci/p2pdma.c-1821- *\tother devices with pci_p2pmem_find()\n--\ndrivers/pci/p2pdma.c-1829- */\ndrivers/pci/p2pdma.c:1830:void pci_p2pmem_publish(struct pci_dev *pdev, bool publish)\ndrivers/pci/p2pdma.c-1831-{\n--\ndrivers/pci/p2pdma.c-1839-}\ndrivers/pci/p2pdma.c:1840:EXPORT_SYMBOL_GPL(pci_p2pmem_publish);\ndrivers/pci/p2pdma.c-1841-\n--\ninclude/linux/pci-p2pdma.h=72=struct p2pdma_provider *pcim_p2pdma_provider(struct pci_dev *pdev, int bar);\ninclude/linux/pci-p2pdma.h:73:int pci_p2pdma_add_resource(struct pci_dev *pdev, int bar, size_t size,\ninclude/linux/pci-p2pdma.h-74-\t\tu64 offset);\n--\ninclude/linux/pci-p2pdma.h=83=void pci_p2pmem_free_sgl(struct pci_dev *pdev, struct scatterlist *sgl);\ninclude/linux/pci-p2pdma.h:84:void pci_p2pmem_publish(struct pci_dev *pdev, bool publish);\ninclude/linux/pci-p2pdma.h-85-void pcim_p2pdma_set_ats_per_mapping(struct pci_dev *pdev);\n--\ninclude/linux/pci-p2pdma.h=97=static inline struct p2pdma_provider *pcim_p2pdma_provider(struct pci_dev *pdev,\n--\ninclude/linux/pci-p2pdma.h-101-}\ninclude/linux/pci-p2pdma.h:102:static inline int pci_p2pdma_add_resource(struct pci_dev *pdev, int bar,\ninclude/linux/pci-p2pdma.h-103-\t\tsize_t size, u64 offset)\n--\ninclude/linux/pci-p2pdma.h=135=static inline void pci_p2pmem_free_sgl(struct pci_dev *pdev,\n--\ninclude/linux/pci-p2pdma.h-138-}\ninclude/linux/pci-p2pdma.h:139:static inline void pci_p2pmem_publish(struct pci_dev *pdev, bool publish)\ninclude/linux/pci-p2pdma.h-140-{\n"
}

13/2 2026/11/08 03:21 llm patch-evaluator
2m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 59865
							output: 27
							thoughts: 212
						

Thoughts:
**Investigating Direct PCI DMA Usage**

Okay, so I'm trying to wrap my head around the calls to `pci_p2pdma_add_resource` and `pci_p2pmem_publish`. My immediate thought is that these are *only* used by habanalabs accelerators and NVMe hosts – specifically, the NVMe ones that support CMB, right? But... hold on. What about NVMe with CMB in QEMU? That's a possibility I hadn't fully considered.

Now I remember that QEMU's NVMe device *does* have support for CMB! It's right there: `cmb_size_mb`. This introduces a new question: does syzkaller actually run with NVMe CMB enabled? And if not, *can* syzkaller be configured to use NVMe CMB? That's the critical question here.

My train of thought continues... Right, I need to understand the relationship of virtual environments and QEMU when running syzkaller. I should check how syzkaller invokes QEMU. What's the command-line setup? Does QEMU itself have NVMe CMB enabled in this configuration? That's the key.

This line of thought quickly leads to this question: can userspace somehow trigger these `pci_p2pdma_*` functions?

Alright, let's take a step back and think about the other possible callers of these functions. Okay, wait! Looking beyond those two known examples, I need to check `drivers/dma-buf/dma-buf-mapping.c` and potentially other callers. Let's see if that file sheds any light on this.



14/2 2026/11/08 03:23 tool grepper
0m Args:
{
  "Expression": "dma_buf_phys_vec_to_sgt"
}

Results:
{
  "Output": "drivers/dma-buf/dma-buf-mapping.c=71=struct dma_buf_dma {\n--\ndrivers/dma-buf/dma-buf-mapping.c-77-/**\ndrivers/dma-buf/dma-buf-mapping.c:78: * dma_buf_phys_vec_to_sgt - Returns the scatterlist table of the attachment\ndrivers/dma-buf/dma-buf-mapping.c-79- * from arrays of physical vectors. This funciton is intended for MMIO memory\n--\ndrivers/dma-buf/dma-buf-mapping.c-99- */\ndrivers/dma-buf/dma-buf-mapping.c:100:struct sg_table *dma_buf_phys_vec_to_sgt(struct dma_buf_attachment *attach,\ndrivers/dma-buf/dma-buf-mapping.c-101-\t\t\t\t\t struct p2pdma_provider *provider,\n--\ndrivers/dma-buf/dma-buf-mapping.c-221-}\ndrivers/dma-buf/dma-buf-mapping.c:222:EXPORT_SYMBOL_NS_GPL(dma_buf_phys_vec_to_sgt, \"DMA_BUF\");\ndrivers/dma-buf/dma-buf-mapping.c-223-\n--\ndrivers/dma-buf/dma-buf-mapping.c-230- * This unmaps a DMA mapping for @attached obtained\ndrivers/dma-buf/dma-buf-mapping.c:231: * by dma_buf_phys_vec_to_sgt().\ndrivers/dma-buf/dma-buf-mapping.c-232- */\n--\ndrivers/infiniband/core/uverbs_std_types_dmabuf.c=25=uverbs_dmabuf_map(struct dma_buf_attachment *attachment,\n--\ndrivers/infiniband/core/uverbs_std_types_dmabuf.c-35-\ndrivers/infiniband/core/uverbs_std_types_dmabuf.c:36:\tret = dma_buf_phys_vec_to_sgt(attachment, priv-\u003eprovider,\ndrivers/infiniband/core/uverbs_std_types_dmabuf.c-37-\t\t\t\t      \u0026priv-\u003ephys_vec, 1, priv-\u003ephys_vec.len,\n--\ndrivers/vfio/pci/vfio_pci_dmabuf.c=51=vfio_pci_dma_buf_map(struct dma_buf_attachment *attachment,\n--\ndrivers/vfio/pci/vfio_pci_dmabuf.c-61-\ndrivers/vfio/pci/vfio_pci_dmabuf.c:62:\tret = dma_buf_phys_vec_to_sgt(attachment, priv-\u003eprovider,\ndrivers/vfio/pci/vfio_pci_dmabuf.c-63-\t\t\t\t      priv-\u003ephys_vec, priv-\u003enr_ranges,\n--\ninclude/linux/dma-buf-mapping.h-9-\ninclude/linux/dma-buf-mapping.h:10:struct sg_table *dma_buf_phys_vec_to_sgt(struct dma_buf_attachment *attach,\ninclude/linux/dma-buf-mapping.h-11-\t\t\t\t\t struct p2pdma_provider *provider,\n"
}

15/2 2026/11/08 03:23 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 61318
							output: 29
							thoughts: 74
						

Thoughts:
Okay, let's dive into this. Here's my thought process on this:

**Digging into DMA-BUF and VFIO Interactions**

Right, so I need to understand how DMA-BUF and VFIO are playing together. My immediate instinct is to check out `vfio/pci/vfio_pci_dmabuf.c`. That's the obvious place to start. I'll also glance over at `drivers/infiniband/core/uverbs_std_types_dmabuf.c` – Infiniband uses DMA-BUF too, and it might offer some useful perspectives on how these sorts of interfaces are being used.

But hold on a second… I'm curious *specifically* about `pcim_p2pdma_set_ats_per_mapping`. Who's calling that function? I need to trace the usage to understand the control flow, so I'm going to track down every caller of that function to see the context within which it's being used. That's the key to understanding how these pieces connect.



16/2 2026/11/08 03:23 tool grepper
0m Args:
{
  "Expression": "pcim_p2pdma_set_ats_per_mapping"
}

Results:
{
  "Output": "Documentation/driver-api/pci/p2pdma.rst=67=any address they are handed once it is set. Unless a driver has declared with\nDocumentation/driver-api/pci/p2pdma.rst:68:``pcim_p2pdma_set_ats_per_mapping()`` that its device chooses ATS per mapping,\nDocumentation/driver-api/pci/p2pdma.rst-69-that bit decides which Address Type P2PDMA assumes, and a client with ATS\n--\ndrivers/pci/p2pdma.c=1509=EXPORT_SYMBOL_IF_KUNIT(pci_p2pdma_client_map_type);\ndrivers/pci/p2pdma.c-1510-\ndrivers/pci/p2pdma.c:1511:/* Whether the driver of @client called pcim_p2pdma_set_ats_per_mapping(). */\ndrivers/pci/p2pdma.c-1512-static bool pci_p2pdma_client_per_mapping(struct pci_dev *client)\n--\ndrivers/pci/p2pdma.c=1840=EXPORT_SYMBOL_GPL(pci_p2pmem_publish);\n--\ndrivers/pci/p2pdma.c-1842-/**\ndrivers/pci/p2pdma.c:1843: * pcim_p2pdma_set_ats_per_mapping - Declare per-mapping ATS for a client\ndrivers/pci/p2pdma.c-1844- * @pdev: PCI device that initiates peer-to-peer DMA\n--\ndrivers/pci/p2pdma.c-1853- */\ndrivers/pci/p2pdma.c:1854:void pcim_p2pdma_set_ats_per_mapping(struct pci_dev *pdev)\ndrivers/pci/p2pdma.c-1855-{\n--\ndrivers/pci/p2pdma.c-1868-}\ndrivers/pci/p2pdma.c:1869:EXPORT_SYMBOL_GPL(pcim_p2pdma_set_ats_per_mapping);\ndrivers/pci/p2pdma.c-1870-\n--\ndrivers/pci/p2pdma.c-1885- *\ndrivers/pci/p2pdma.c:1886: * Only a client whose driver called pcim_p2pdma_set_ats_per_mapping() takes\ndrivers/pci/p2pdma.c-1887- * the Address Type from @tlp_flags. For any other client its ATS Enable bit\n--\ninclude/linux/pci-p2pdma.h=84=void pci_p2pmem_publish(struct pci_dev *pdev, bool publish);\ninclude/linux/pci-p2pdma.h:85:void pcim_p2pdma_set_ats_per_mapping(struct pci_dev *pdev);\ninclude/linux/pci-p2pdma.h-86-int pci_p2pdma_enable_store(const char *page, struct pci_dev **p2p_dev,\n--\ninclude/linux/pci-p2pdma.h=139=static inline void pci_p2pmem_publish(struct pci_dev *pdev, bool publish)\n--\ninclude/linux/pci-p2pdma.h-141-}\ninclude/linux/pci-p2pdma.h:142:static inline void pcim_p2pdma_set_ats_per_mapping(struct pci_dev *pdev)\ninclude/linux/pci-p2pdma.h-143-{\n"
}

17/2 2026/11/08 03:23 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 62593
							output: 22
							thoughts: 57
						

Thoughts:
Okay, here's my take on those thoughts, tailored for an expert audience:

**Investigating `pcim_p2pdma_set_ats_per_mapping` Usage**

Alright, no immediate leads on callers for `pcim_p2pdma_set_ats_per_mapping` so far, which isn't entirely surprising given the nature of ATS configuration. This suggests a potentially more niche usage scenario. However, a related question jumps out: what's enabling the underlying ACS capabilities? I need to understand the control path upstream. It's time to dig into the callers of `pci_acs_flags_enabled`. That function is the linchpin; it's the gatekeeper for these crucial ACS flags that directly influence DMA behavior. Finding its uses will give me crucial context. This should shed light on the conditions under which these DMA security and performance features are activated. Let's see what the kernel has to say.



18/2 2026/11/08 03:24 tool grepper
0m Args:
{
  "Expression": "pci_acs_flags_enabled"
}

Results:
{
  "Output": "drivers/pci/pci.c=3614=VISIBLE_IF_KUNIT\ndrivers/pci/pci.c:3615:bool pci_acs_flags_enabled(struct pci_dev *pdev, u16 acs_flags)\ndrivers/pci/pci.c-3616-{\n--\ndrivers/pci/pci.c-3635-}\ndrivers/pci/pci.c:3636:EXPORT_SYMBOL_IF_KUNIT(pci_acs_flags_enabled);\ndrivers/pci/pci.c-3637-\n--\ndrivers/pci/pci.c=3654=bool pci_acs_enabled(struct pci_dev *pdev, u16 acs_flags)\n--\ndrivers/pci/pci.c-3692-\tcase PCI_EXP_TYPE_ROOT_PORT:\ndrivers/pci/pci.c:3693:\t\treturn pci_acs_flags_enabled(pdev, acs_flags);\ndrivers/pci/pci.c-3694-\t/*\n--\ndrivers/pci/pci.c-3707-\ndrivers/pci/pci.c:3708:\t\treturn pci_acs_flags_enabled(pdev, acs_flags);\ndrivers/pci/pci.c-3709-\t}\n--\ndrivers/pci/pci.h=1130=enum pci_acs_p2pdma_state {\n--\ndrivers/pci/pci.h-1137-#if IS_ENABLED(CONFIG_KUNIT)\ndrivers/pci/pci.h:1138:bool pci_acs_flags_enabled(struct pci_dev *pdev, u16 acs_flags);\ndrivers/pci/pci.h-1139-enum pci_acs_p2pdma_state pci_acs_p2pdma_request(u16 ctrl,\n--\ndrivers/pci/pci_acs_test.c=169=static bool acs_isolated(struct kunit *test, struct acs_ctrl_cfg *cfg,\n--\ndrivers/pci/pci_acs_test.c-185-\ndrivers/pci/pci_acs_test.c:186:\treturn pci_acs_flags_enabled(pdev, acs_flags);\ndrivers/pci/pci_acs_test.c-187-}\ndrivers/pci/pci_acs_test.c-188-\ndrivers/pci/pci_acs_test.c:189:static void pci_acs_flags_enabled_test(struct kunit *test)\ndrivers/pci/pci_acs_test.c-190-{\n--\ndrivers/pci/pci_acs_test.c=1350=static struct kunit_case pci_acs_test_cases[] = {\n--\ndrivers/pci/pci_acs_test.c-1354-\t\t\t acs_completion_gen_params),\ndrivers/pci/pci_acs_test.c:1355:\tKUNIT_CASE_PARAM(pci_acs_flags_enabled_test,\ndrivers/pci/pci_acs_test.c-1356-\t\t\t acs_isolation_gen_params),\n--\ndrivers/pci/quirks.c=5150=static int pci_quirk_intel_spt_pch_acs(struct pci_dev *dev, u16 acs_flags)\n--\ndrivers/pci/quirks.c-5161-\ndrivers/pci/quirks.c:5162:\t/* see pci_acs_flags_enabled() */\ndrivers/pci/quirks.c-5163-\tif (pci_read_config_dword(dev, pos + PCI_ACS_CAP, \u0026cap) ||\n"
}

19/2 2026/11/08 03:24 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 63856
							output: 20
							thoughts: 62
						

Thoughts:
Here's my thought process, as if I were reviewing this code:

**Diving into PCI ACS Flag Enablement**

Okay, so I'm digging into how the Access Control Services (ACS) flags are enabled in the PCI subsystem. My first point of entry is `pci_acs_flags_enabled` in `drivers/pci/pci.c`. The comments probably explain the overall function and usage. I can see that `pci_acs_enabled` calls that function, so I'll want to check that it isn't used too frequently. But first, the function itself. Then I'll check to see where `pci_acs_enabled` is actually being called. Understanding the call chain will illuminate the control flow. It should give me a solid picture of when and why ACS is being enabled. From there, I can get a better grip on any possible issues or enhancements. Let's get to it!



20/2 2026/11/08 03:24 tool grepper
0m Args:
{
  "Expression": "pci_acs_enabled"
}

Results:
{
  "Output": "drivers/iommu/iommu.c=1499=static struct iommu_group *get_pci_function_alias_group(struct pci_dev *pdev,\n--\ndrivers/iommu/iommu.c-1504-\ndrivers/iommu/iommu.c:1505:\tif (!pdev-\u003emultifunction || pci_acs_enabled(pdev, REQ_ACS_FLAGS))\ndrivers/iommu/iommu.c-1506-\t\treturn NULL;\n--\ndrivers/iommu/iommu.c-1510-\t\t    PCI_SLOT(tmp-\u003edevfn) != PCI_SLOT(pdev-\u003edevfn) ||\ndrivers/iommu/iommu.c:1511:\t\t    pci_acs_enabled(tmp, REQ_ACS_FLAGS))\ndrivers/iommu/iommu.c-1512-\t\t\tcontinue;\n--\ndrivers/pci/pci.c=3636=EXPORT_SYMBOL_IF_KUNIT(pci_acs_flags_enabled);\n--\ndrivers/pci/pci.c-3638-/**\ndrivers/pci/pci.c:3639: * pci_acs_enabled - test ACS against required flags for a given device\ndrivers/pci/pci.c-3640- * @pdev: device to test\n--\ndrivers/pci/pci.c-3653- */\ndrivers/pci/pci.c:3654:bool pci_acs_enabled(struct pci_dev *pdev, u16 acs_flags)\ndrivers/pci/pci.c-3655-{\n--\ndrivers/pci/pci.c=3727=bool pci_acs_path_enabled(struct pci_dev *start,\n--\ndrivers/pci/pci.c-3734-\ndrivers/pci/pci.c:3735:\t\tif (!pci_acs_enabled(pdev, acs_flags))\ndrivers/pci/pci.c-3736-\t\t\treturn false;\n--\ninclude/linux/pci.h=2251=static inline struct pci_dev *pci_dev_get(struct pci_dev *dev) { return NULL; }\n--\ninclude/linux/pci.h-2254-#define dev_is_pf(d) (false)\ninclude/linux/pci.h:2255:static inline bool pci_acs_enabled(struct pci_dev *pdev, u16 acs_flags)\ninclude/linux/pci.h-2256-{ return false; }\n--\ninclude/linux/pci.h=2756=void pci_request_acs(void);\ninclude/linux/pci.h:2757:bool pci_acs_enabled(struct pci_dev *pdev, u16 acs_flags);\ninclude/linux/pci.h-2758-bool pci_acs_path_enabled(struct pci_dev *start,\n"
}

21/2 2026/11/08 03:24 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 64914
							output: 25
							thoughts: 928
						

Thoughts:
**Analyzing PCI ACS Flag and DMA Changes**

Okay, let's break down these changes. First, I see a modification to `pci_acs_flags_enabled`. Previously, the code read the ACS control register without checking for errors from `pci_read_config_word` or considering potential errors using `PCI_POSSIBLE_ERROR`. That's not ideal; a failed read could lead to incorrect flag determination. Now, the code explicitly checks the return value and handles potential errors. This is a good, defensive programming practice to ensure robustness. The function is also now `VISIBLE_IF_KUNIT` and `EXPORT_SYMBOL_IF_KUNIT`, which suggests this function is intended for kernel unit testing, so it's good to see these additions which help testability.

Next, I'm checking `pci_dev_specific_read_acs_ctrl` in `drivers/pci/quirks.c`. This function reads the ACS control register for specific Intel devices. It looks like it doesn't have an error check. I need to make sure this is correct.

Then, there's `pci_quirk_intel_spt_pch_acs`, which I see has also been updated with the same error handling around `pci_read_config_dword` calls. Again, good to see consistency in error checking. This is also reading from the ACS CAP and ACS CTRL registers, filtering based on `acs_flags`.

Finally, my attention is drawn to `p2pdma.c`. Specifically, I'm interested in how `pci_p2pdma_distance_many` is used. I see it's called by `pci_p2pmem_find_many` and `pci_p2pdma_distance`. I should probably check the definition of `pci_p2pdma_distance`, given it looks like a macro or inline. This will help understand the complete call graph.



22/2 2026/11/08 03:25 tool grepper
0m Args:
{
  "Expression": "#define pci_p2pdma_distance"
}

Results:
{
  "Output": "no matches"
}

23/2 2026/11/08 03:25 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 66299
							output: 44
							thoughts: 30
						

Thoughts:
Okay, here's my attempt at summarizing the thought process, as requested, targeting an expert user and using the first person perspective:

**Locating the `pci_p2pdma_distance` Definition**

Alright, I need to get to the source. Time to find the declaration for `pci_p2pdma_distance`. I know that deals with PCI peer-to-peer DMA functionality, so my first instinct is to look within the kernel's include files. Specifically, since it's a PCI-related function and specifically deals with DMA, I'm pretty confident it'll be in `include/linux/pci-p2pdma.h`. That seems like the logical place to start. Let's head there and see what's defined.



24/2 2026/11/08 03:25 tool grepper
0m Args:
{
  "Expression": "pci_p2pdma_distance\\(",
  "PathPrefixes": [
    "include/linux/pci-p2pdma.h"
  ]
}

Results:
{
  "Output": "include/linux/pci-p2pdma.h=157=pci_p2pdma_map_type(struct p2pdma_provider *provider, struct device *dev)\n--\ninclude/linux/pci-p2pdma.h-163-\ninclude/linux/pci-p2pdma.h:164:static inline int pci_p2pdma_distance(struct pci_dev *provider,\ninclude/linux/pci-p2pdma.h-165-\tstruct device *client, bool verbose)\n"
}

25/2 2026/11/08 03:25 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 66686
							output: 23
							thoughts: 31
						

Thoughts:
Okay, here's my summary, taking on the persona you requested:

**Investigating PCI Peer-to-Peer Memory Mapping Functions**

Alright, let's dive in. My immediate goal is to understand the calling contexts of `pci_p2pmem_find_many` and `pci_p2pmem_find`. I want to see *how* these functions are being used within the system. Are they called frequently? In what scenarios? What are the typical parameters being passed? The broader context will reveal the design decisions and potential performance bottlenecks. I need to trace the call paths to get a handle on the intention behind the developers' implementation. Let's see what the code has to say.



26/2 2026/11/08 03:25 tool grepper
0m Args:
{
  "Expression": "pci_p2pmem_find"
}

Results:
{
  "Output": "Documentation/driver-api/pci/p2pdma.rst=230=a specific P2P provider to use it may check compatibility using\nDocumentation/driver-api/pci/p2pdma.rst-231-:c:func:`pci_p2pdma_distance()` otherwise it may find a memory provider\nDocumentation/driver-api/pci/p2pdma.rst:232:that's compatible with all clients using  :c:func:`pci_p2pmem_find()`.\nDocumentation/driver-api/pci/p2pdma.rst-233-If more than one provider is supported, the one nearest to all the clients will\n--\ndrivers/nvme/target/core.c=492=static int nvmet_p2pmem_ns_enable(struct nvmet_ns *ns)\n--\ndrivers/nvme/target/core.c-522-\ndrivers/nvme/target/core.c:523:\t\tp2p_dev = pci_p2pmem_find(nvmet_ns_dev(ns));\ndrivers/nvme/target/core.c-524-\t\tif (!p2p_dev) {\n--\ndrivers/nvme/target/core.c=536=static void nvmet_p2pmem_ns_add_p2p(struct nvmet_ctrl *ctrl,\n--\ndrivers/nvme/target/core.c-557-\ndrivers/nvme/target/core.c:558:\t\tp2p_dev = pci_p2pmem_find_many(clients, ARRAY_SIZE(clients));\ndrivers/nvme/target/core.c-559-\t\tif (!p2p_dev) {\n--\ndrivers/pci/p2pdma.c=1602=static bool pci_has_p2pmem(struct pci_dev *pdev)\n--\ndrivers/pci/p2pdma.c-1621-/**\ndrivers/pci/p2pdma.c:1622: * pci_p2pmem_find_many - find a peer-to-peer DMA memory device compatible with\ndrivers/pci/p2pdma.c-1623- *\tthe specified list of clients and shortest distance\n--\ndrivers/pci/p2pdma.c-1636- */\ndrivers/pci/p2pdma.c:1637:struct pci_dev *pci_p2pmem_find_many(struct device **clients, int num_clients)\ndrivers/pci/p2pdma.c-1638-{\n--\ndrivers/pci/p2pdma.c-1682-}\ndrivers/pci/p2pdma.c:1683:EXPORT_SYMBOL_GPL(pci_p2pmem_find_many);\ndrivers/pci/p2pdma.c-1684-\n--\ndrivers/pci/p2pdma.c=1817=EXPORT_SYMBOL_GPL(pci_p2pmem_free_sgl);\n--\ndrivers/pci/p2pdma.c-1820- * pci_p2pmem_publish - publish the peer-to-peer DMA memory for use by\ndrivers/pci/p2pdma.c:1821: *\tother devices with pci_p2pmem_find()\ndrivers/pci/p2pdma.c-1822- * @pdev: the device with peer-to-peer DMA memory to publish\n--\ninclude/linux/pci-p2pdma.h=75=int pci_p2pdma_distance_many(struct pci_dev *provider, struct device **clients,\ninclude/linux/pci-p2pdma.h-76-\t\t\t     int num_clients, bool verbose);\ninclude/linux/pci-p2pdma.h:77:struct pci_dev *pci_p2pmem_find_many(struct device **clients, int num_clients);\ninclude/linux/pci-p2pdma.h-78-void *pci_alloc_p2pmem(struct pci_dev *pdev, size_t size);\n--\ninclude/linux/pci-p2pdma.h=107=static inline int pci_p2pdma_distance_many(struct pci_dev *provider,\n--\ninclude/linux/pci-p2pdma.h-111-}\ninclude/linux/pci-p2pdma.h:112:static inline struct pci_dev *pci_p2pmem_find_many(struct device **clients,\ninclude/linux/pci-p2pdma.h-113-\t\t\t\t\t\t   int num_clients)\n--\ninclude/linux/pci-p2pdma.h=164=static inline int pci_p2pdma_distance(struct pci_dev *provider,\n--\ninclude/linux/pci-p2pdma.h-169-\ninclude/linux/pci-p2pdma.h:170:static inline struct pci_dev *pci_p2pmem_find(struct device *client)\ninclude/linux/pci-p2pdma.h-171-{\ninclude/linux/pci-p2pdma.h:172:\treturn pci_p2pmem_find_many(\u0026client, 1);\ninclude/linux/pci-p2pdma.h-173-}\n"
}

27/2 2026/11/08 03:25 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 68243
							output: 29
							thoughts: 62
						

Thoughts:
**NVMe Target Configuration and Fuzzing Potential**

Okay, so I'm looking at `nvmet_p2pmem_ns_enable`. Immediately, my mind jumps to the configuration possibilities for an NVMe target. Can we manipulate the target through configfs? The answer is likely yes, and that's incredibly interesting. If `nvmet` is exposed through configfs, it becomes highly fuzzable via syzkaller, which opens up a whole new attack surface. Time to check if syzkaller already has the relevant descriptions for `nvmet`. This could be a significant find if we can leverage this.



28/2 2026/11/08 03:25 tool grepper
0m Args:
{
  "Expression": "nvmet",
  "PathPrefixes": [
    "drivers/nvme/target"
  ]
}

Results:
{
  "Output": "\nFull output is too long, showing 200 out of 12194 lines.\nUse more precise expression or PathPrefixes if possible.\n\nNumber of matching lines per file (25 files in total):\ndrivers/nvme/target/Kconfig:2\ndrivers/nvme/target/Makefile:15\ndrivers/nvme/target/admin-cmd.c:289\ndrivers/nvme/target/auth.c:28\ndrivers/nvme/target/configfs.c:631\ndrivers/nvme/target/core.c:409\ndrivers/nvme/target/debugfs.c:66\ndrivers/nvme/target/debugfs.h:16\ndrivers/nvme/target/discovery.c:102\ndrivers/nvme/target/fabrics-cmd-auth.c:54\ndrivers/nvme/target/fabrics-cmd.c:54\ndrivers/nvme/target/fc.c:508\ndrivers/nvme/target/fcloop.c:29\ndrivers/nvme/target/io-cmd-bdev.c:54\ndrivers/nvme/target/io-cmd-file.c:59\ndrivers/nvme/target/loop.c:35\ndrivers/nvme/target/nvmet.h:306\ndrivers/nvme/target/passthru.c:76\ndrivers/nvme/target/pci-epf.c:416\ndrivers/nvme/target/pr.c:229\ndrivers/nvme/target/rdma.c:390\ndrivers/nvme/target/tcp.c:370\ndrivers/nvme/target/trace.c:44\ndrivers/nvme/target/trace.h:25\ndrivers/nvme/target/zns.c:75\n\ndrivers/nvme/target/Kconfig=3=config NVME_TARGET\n--\ndrivers/nvme/target/Kconfig-16-\ndrivers/nvme/target/Kconfig:17:\t  To configure the NVMe target you probably want to use the nvmetcli\ndrivers/nvme/target/Kconfig:18:\t  tool from http://git.infradead.org/users/hch/nvmetcli.git.\ndrivers/nvme/target/Kconfig-19-\n--\ndrivers/nvme/target/Makefile=3=ccflags-y\t\t\t\t+= -I$(src)\ndrivers/nvme/target/Makefile-4-\ndrivers/nvme/target/Makefile:5:obj-$(CONFIG_NVME_TARGET)\t\t+= nvmet.o\ndrivers/nvme/target/Makefile-6-obj-$(CONFIG_NVME_TARGET_LOOP)\t\t+= nvme-loop.o\ndrivers/nvme/target/Makefile:7:obj-$(CONFIG_NVME_TARGET_RDMA)\t\t+= nvmet-rdma.o\ndrivers/nvme/target/Makefile:8:obj-$(CONFIG_NVME_TARGET_FC)\t\t+= nvmet-fc.o\ndrivers/nvme/target/Makefile-9-obj-$(CONFIG_NVME_TARGET_FCLOOP)\t+= nvme-fcloop.o\ndrivers/nvme/target/Makefile:10:obj-$(CONFIG_NVME_TARGET_TCP)\t\t+= nvmet-tcp.o\ndrivers/nvme/target/Makefile:11:obj-$(CONFIG_NVME_TARGET_PCI_EPF)\t+= nvmet-pci-epf.o\ndrivers/nvme/target/Makefile-12-\ndrivers/nvme/target/Makefile:13:nvmet-y\t\t+= core.o configfs.o admin-cmd.o fabrics-cmd.o \\\ndrivers/nvme/target/Makefile-14-\t\t\tdiscovery.o io-cmd-file.o io-cmd-bdev.o pr.o\ndrivers/nvme/target/Makefile:15:nvmet-$(CONFIG_NVME_TARGET_DEBUGFS)\t+= debugfs.o\ndrivers/nvme/target/Makefile:16:nvmet-$(CONFIG_NVME_TARGET_PASSTHRU)\t+= passthru.o\ndrivers/nvme/target/Makefile:17:nvmet-$(CONFIG_BLK_DEV_ZONED)\t\t+= zns.o\ndrivers/nvme/target/Makefile:18:nvmet-$(CONFIG_NVME_TARGET_AUTH)\t+= fabrics-cmd-auth.o auth.o\ndrivers/nvme/target/Makefile-19-nvme-loop-y\t+= loop.o\ndrivers/nvme/target/Makefile:20:nvmet-rdma-y\t+= rdma.o\ndrivers/nvme/target/Makefile:21:nvmet-fc-y\t+= fc.o\ndrivers/nvme/target/Makefile-22-nvme-fcloop-y\t+= fcloop.o\ndrivers/nvme/target/Makefile:23:nvmet-tcp-y\t+= tcp.o\ndrivers/nvme/target/Makefile:24:nvmet-pci-epf-y\t+= pci-epf.o\ndrivers/nvme/target/Makefile:25:nvmet-$(CONFIG_TRACING)\t+= trace.o\n--\ndrivers/nvme/target/admin-cmd.c-12-#include \u003clinux/unaligned.h\u003e\ndrivers/nvme/target/admin-cmd.c:13:#include \"nvmet.h\"\ndrivers/nvme/target/admin-cmd.c-14-\ndrivers/nvme/target/admin-cmd.c:15:static void nvmet_execute_delete_sq(struct nvmet_req *req)\ndrivers/nvme/target/admin-cmd.c-16-{\ndrivers/nvme/target/admin-cmd.c:17:\tstruct nvmet_ctrl *ctrl = req-\u003esq-\u003ectrl;\ndrivers/nvme/target/admin-cmd.c-18-\tu16 sqid = le16_to_cpu(req-\u003ecmd-\u003edelete_queue.qid);\n--\ndrivers/nvme/target/admin-cmd.c-20-\ndrivers/nvme/target/admin-cmd.c:21:\tif (!nvmet_is_pci_ctrl(ctrl)) {\ndrivers/nvme/target/admin-cmd.c:22:\t\tstatus = nvmet_report_invalid_opcode(req);\ndrivers/nvme/target/admin-cmd.c-23-\t\tgoto complete;\n--\ndrivers/nvme/target/admin-cmd.c-30-\ndrivers/nvme/target/admin-cmd.c:31:\tstatus = nvmet_check_sqid(ctrl, sqid, false);\ndrivers/nvme/target/admin-cmd.c-32-\tif (status != NVME_SC_SUCCESS)\n--\ndrivers/nvme/target/admin-cmd.c-37-complete:\ndrivers/nvme/target/admin-cmd.c:38:\tnvmet_req_complete(req, status);\ndrivers/nvme/target/admin-cmd.c-39-}\ndrivers/nvme/target/admin-cmd.c-40-\ndrivers/nvme/target/admin-cmd.c:41:static void nvmet_execute_create_sq(struct nvmet_req *req)\ndrivers/nvme/target/admin-cmd.c-42-{\ndrivers/nvme/target/admin-cmd.c:43:\tstruct nvmet_ctrl *ctrl = req-\u003esq-\u003ectrl;\ndrivers/nvme/target/admin-cmd.c-44-\tstruct nvme_command *cmd = req-\u003ecmd;\n--\ndrivers/nvme/target/admin-cmd.c-51-\ndrivers/nvme/target/admin-cmd.c:52:\tif (!nvmet_is_pci_ctrl(ctrl)) {\ndrivers/nvme/target/admin-cmd.c:53:\t\tstatus = nvmet_report_invalid_opcode(req);\ndrivers/nvme/target/admin-cmd.c-54-\t\tgoto complete;\n--\ndrivers/nvme/target/admin-cmd.c-61-\ndrivers/nvme/target/admin-cmd.c:62:\tstatus = nvmet_check_sqid(ctrl, sqid, true);\ndrivers/nvme/target/admin-cmd.c-63-\tif (status != NVME_SC_SUCCESS)\n--\ndrivers/nvme/target/admin-cmd.c-65-\ndrivers/nvme/target/admin-cmd.c:66:\tstatus = nvmet_check_io_cqid(ctrl, cqid, false);\ndrivers/nvme/target/admin-cmd.c-67-\tif (status != NVME_SC_SUCCESS) {\n--\ndrivers/nvme/target/admin-cmd.c-79-complete:\ndrivers/nvme/target/admin-cmd.c:80:\tnvmet_req_complete(req, status);\ndrivers/nvme/target/admin-cmd.c-81-}\ndrivers/nvme/target/admin-cmd.c-82-\ndrivers/nvme/target/admin-cmd.c:83:static void nvmet_execute_delete_cq(struct nvmet_req *req)\ndrivers/nvme/target/admin-cmd.c-84-{\ndrivers/nvme/target/admin-cmd.c:85:\tstruct nvmet_ctrl *ctrl = req-\u003esq-\u003ectrl;\ndrivers/nvme/target/admin-cmd.c-86-\tu16 cqid = le16_to_cpu(req-\u003ecmd-\u003edelete_queue.qid);\n--\ndrivers/nvme/target/admin-cmd.c-88-\ndrivers/nvme/target/admin-cmd.c:89:\tif (!nvmet_is_pci_ctrl(ctrl)) {\ndrivers/nvme/target/admin-cmd.c:90:\t\tstatus = nvmet_report_invalid_opcode(req);\ndrivers/nvme/target/admin-cmd.c-91-\t\tgoto complete;\n--\ndrivers/nvme/target/admin-cmd.c-93-\ndrivers/nvme/target/admin-cmd.c:94:\tstatus = nvmet_check_io_cqid(ctrl, cqid, false);\ndrivers/nvme/target/admin-cmd.c-95-\tif (status != NVME_SC_SUCCESS)\n--\ndrivers/nvme/target/admin-cmd.c-97-\ndrivers/nvme/target/admin-cmd.c:98:\tif (!ctrl-\u003ecqs[cqid] || nvmet_cq_in_use(ctrl-\u003ecqs[cqid])) {\ndrivers/nvme/target/admin-cmd.c-99-\t\t/* Some SQs are still using this CQ */\n--\ndrivers/nvme/target/admin-cmd.c-106-complete:\ndrivers/nvme/target/admin-cmd.c:107:\tnvmet_req_complete(req, status);\ndrivers/nvme/target/admin-cmd.c-108-}\ndrivers/nvme/target/admin-cmd.c-109-\ndrivers/nvme/target/admin-cmd.c:110:static void nvmet_execute_create_cq(struct nvmet_req *req)\ndrivers/nvme/target/admin-cmd.c-111-{\ndrivers/nvme/target/admin-cmd.c:112:\tstruct nvmet_ctrl *ctrl = req-\u003esq-\u003ectrl;\ndrivers/nvme/target/admin-cmd.c-113-\tstruct nvme_command *cmd = req-\u003ecmd;\n--\ndrivers/nvme/target/admin-cmd.c-120-\ndrivers/nvme/target/admin-cmd.c:121:\tif (!nvmet_is_pci_ctrl(ctrl)) {\ndrivers/nvme/target/admin-cmd.c:122:\t\tstatus = nvmet_report_invalid_opcode(req);\ndrivers/nvme/target/admin-cmd.c-123-\t\tgoto complete;\n--\ndrivers/nvme/target/admin-cmd.c-125-\ndrivers/nvme/target/admin-cmd.c:126:\tstatus = nvmet_check_io_cqid(ctrl, cqid, true);\ndrivers/nvme/target/admin-cmd.c-127-\tif (status != NVME_SC_SUCCESS)\n--\ndrivers/nvme/target/admin-cmd.c-138-complete:\ndrivers/nvme/target/admin-cmd.c:139:\tnvmet_req_complete(req, status);\ndrivers/nvme/target/admin-cmd.c-140-}\ndrivers/nvme/target/admin-cmd.c-141-\ndrivers/nvme/target/admin-cmd.c:142:u32 nvmet_get_log_page_len(struct nvme_command *cmd)\ndrivers/nvme/target/admin-cmd.c-143-{\n--\ndrivers/nvme/target/admin-cmd.c-154-\ndrivers/nvme/target/admin-cmd.c:155:static u32 nvmet_feat_data_len(struct nvmet_req *req, u32 cdw10)\ndrivers/nvme/target/admin-cmd.c-156-{\n--\ndrivers/nvme/target/admin-cmd.c-164-\ndrivers/nvme/target/admin-cmd.c:165:u64 nvmet_get_log_page_offset(struct nvme_command *cmd)\ndrivers/nvme/target/admin-cmd.c-166-{\n--\ndrivers/nvme/target/admin-cmd.c-169-\ndrivers/nvme/target/admin-cmd.c:170:static void nvmet_execute_get_log_page_noop(struct nvmet_req *req)\ndrivers/nvme/target/admin-cmd.c-171-{\ndrivers/nvme/target/admin-cmd.c:172:\tnvmet_req_complete(req, nvmet_zero_sgl(req, 0, req-\u003etransfer_len));\ndrivers/nvme/target/admin-cmd.c-173-}\ndrivers/nvme/target/admin-cmd.c-174-\ndrivers/nvme/target/admin-cmd.c:175:static void nvmet_execute_get_log_page_error(struct nvmet_req *req)\ndrivers/nvme/target/admin-cmd.c-176-{\ndrivers/nvme/target/admin-cmd.c:177:\tstruct nvmet_ctrl *ctrl = req-\u003esq-\u003ectrl;\ndrivers/nvme/target/admin-cmd.c-178-\tunsigned long flags;\n--\ndrivers/nvme/target/admin-cmd.c-186-\tfor (i = 0; i \u003c NVMET_ERROR_LOG_SLOTS; i++) {\ndrivers/nvme/target/admin-cmd.c:187:\t\tif (nvmet_copy_to_sgl(req, offset, \u0026ctrl-\u003eslots[slot],\ndrivers/nvme/target/admin-cmd.c-188-\t\t\t\tsizeof(struct nvme_error_slot)))\n--\ndrivers/nvme/target/admin-cmd.c-197-\tspin_unlock_irqrestore(\u0026ctrl-\u003eerror_lock, flags);\ndrivers/nvme/target/admin-cmd.c:198:\tnvmet_req_complete(req, 0);\ndrivers/nvme/target/admin-cmd.c-199-}\ndrivers/nvme/target/admin-cmd.c-200-\ndrivers/nvme/target/admin-cmd.c:201:static void nvmet_execute_get_supported_log_pages(struct nvmet_req *req)\ndrivers/nvme/target/admin-cmd.c-202-{\n--\ndrivers/nvme/target/admin-cmd.c-223-\ndrivers/nvme/target/admin-cmd.c:224:\tstatus = nvmet_copy_to_sgl(req, 0, logs, sizeof(*logs));\ndrivers/nvme/target/admin-cmd.c-225-\tkfree(logs);\ndrivers/nvme/target/admin-cmd.c-226-out:\ndrivers/nvme/target/admin-cmd.c:227:\tnvmet_req_complete(req, status);\ndrivers/nvme/target/admin-cmd.c-228-}\ndrivers/nvme/target/admin-cmd.c-229-\ndrivers/nvme/target/admin-cmd.c:230:static u16 nvmet_get_smart_log_nsid(struct nvmet_req *req,\ndrivers/nvme/target/admin-cmd.c-231-\t\tstruct nvme_smart_log *slog)\n--\ndrivers/nvme/target/admin-cmd.c-235-\ndrivers/nvme/target/admin-cmd.c:236:\tstatus = nvmet_req_find_ns(req);\ndrivers/nvme/target/admin-cmd.c-237-\tif (status)\n--\ndrivers/nvme/target/admin-cmd.c-258-\ndrivers/nvme/target/admin-cmd.c:259:static u16 nvmet_get_smart_log_all(struct nvmet_req *req,\ndrivers/nvme/target/admin-cmd.c-260-\t\tstruct nvme_smart_log *slog)\n--\ndrivers/nvme/target/admin-cmd.c-263-\tu64 data_units_read = 0, data_units_written = 0;\ndrivers/nvme/target/admin-cmd.c:264:\tstruct nvmet_ns *ns;\ndrivers/nvme/target/admin-cmd.c:265:\tstruct nvmet_ctrl *ctrl;\ndrivers/nvme/target/admin-cmd.c-266-\tunsigned long idx;\n--\ndrivers/nvme/target/admin-cmd.c-268-\tctrl = req-\u003esq-\u003ectrl;\ndrivers/nvme/target/admin-cmd.c:269:\tnvmet_for_each_enabled_ns(\u0026ctrl-\u003esubsys-\u003enamespaces, idx, ns) {\ndrivers/nvme/target/admin-cmd.c-270-\t\t/* we don't have the right data for file backed ns */\n--\ndrivers/nvme/target/admin-cmd.c-288-\ndrivers/nvme/target/admin-cmd.c:289:static void nvmet_execute_get_log_page_rmi(struct nvmet_req *req)\ndrivers/nvme/target/admin-cmd.c-290-{\n--\ndrivers/nvme/target/admin-cmd.c-296-\t\t\t\t\t    req-\u003ecmd-\u003eget_log_page.lsi));\ndrivers/nvme/target/admin-cmd.c:297:\tstatus = nvmet_req_find_ns(req);\ndrivers/nvme/target/admin-cmd.c-298-\tif (status)\n--\ndrivers/nvme/target/admin-cmd.c-323-\ndrivers/nvme/target/admin-cmd.c:324:\tstatus = nvmet_copy_to_sgl(req, 0, log, sizeof(*log));\ndrivers/nvme/target/admin-cmd.c-325-\tkfree(log);\ndrivers/nvme/target/admin-cmd.c-326-out:\ndrivers/nvme/target/admin-cmd.c:327:\tnvmet_req_complete(req, status);\ndrivers/nvme/target/admin-cmd.c-328-}\ndrivers/nvme/target/admin-cmd.c-329-\ndrivers/nvme/target/admin-cmd.c:330:static void nvmet_execute_get_log_page_smart(struct nvmet_req *req)\ndrivers/nvme/target/admin-cmd.c-331-{\n--\ndrivers/nvme/target/admin-cmd.c-343-\tif (req-\u003ecmd-\u003eget_log_page.nsid == cpu_to_le32(NVME_NSID_ALL))\ndrivers/nvme/target/admin-cmd.c:344:\t\tstatus = nvmet_get_smart_log_all(req, log);\ndrivers/nvme/target/admin-cmd.c-345-\telse\ndrivers/nvme/target/admin-cmd.c:346:\t\tstatus = nvmet_get_smart_log_nsid(req, log);\ndrivers/nvme/target/admin-cmd.c-347-\tif (status)\n--\ndrivers/nvme/target/admin-cmd.c-354-\ndrivers/nvme/target/admin-cmd.c:355:\tstatus = nvmet_copy_to_sgl(req, 0, log, sizeof(*log));\n\n"
}

29/2 2026/11/08 03:25 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 73593
							output: 39
							thoughts: 62
						

Thoughts:
Here's my analysis of the provided information, as if these were my internal thoughts:

**Dissecting `nvmet_ns_p2pmem_store` in the NVMe Target ConfigFS**

Okay, so we're looking at `nvmet_ns_p2pmem_store`. Right, that's the function involved in handling the storage of p2pmem settings for NVMe namespaces, specifically within the ConfigFS framework. The file path confirms that it's in `drivers/nvme/target/configfs.c`.

My immediate next step is to drill down into the code. Let's zero in on the lines around 570-620 within that file. That should give me the core logic of `nvmet_ns_p2pmem_store`. This is likely where the ConfigFS attributes for p2pmem are being handled – where the data validation, storage, and possibly the triggering of related NVMe target actions are taking place. This should tell me what’s happening in detail. I need to understand how the p2pmem configurations interface with the overall NVMe target architecture and how the relevant data is stored.



30/2 2026/11/08 03:25 tool read-file
0m Args:
{
  "File": "drivers/nvme/target/configfs.c",
  "FirstLine": 570,
  "LineCount": 55
}

Results:
{
  "Contents": " 570:\t\treturn ret;\n 571:\t}\n 572:\t\n 573:\tCONFIGFS_ATTR(nvmet_ns_, device_path);\n 574:\t\n 575:\t#ifdef CONFIG_PCI_P2PDMA\n 576:\tstatic ssize_t nvmet_ns_p2pmem_show(struct config_item *item, char *page)\n 577:\t{\n 578:\t\tstruct nvmet_ns *ns = to_nvmet_ns(item);\n 579:\t\n 580:\t\treturn pci_p2pdma_enable_show(page, ns-\u003ep2p_dev, ns-\u003euse_p2pmem);\n 581:\t}\n 582:\t\n 583:\tstatic ssize_t nvmet_ns_p2pmem_store(struct config_item *item,\n 584:\t\t\tconst char *page, size_t count)\n 585:\t{\n 586:\t\tstruct nvmet_ns *ns = to_nvmet_ns(item);\n 587:\t\tstruct pci_dev *p2p_dev = NULL;\n 588:\t\tbool use_p2pmem;\n 589:\t\tint ret = count;\n 590:\t\tint error;\n 591:\t\n 592:\t\tmutex_lock(\u0026ns-\u003esubsys-\u003elock);\n 593:\t\tif (ns-\u003eenabled) {\n 594:\t\t\tret = -EBUSY;\n 595:\t\t\tgoto out_unlock;\n 596:\t\t}\n 597:\t\n 598:\t\terror = pci_p2pdma_enable_store(page, \u0026p2p_dev, \u0026use_p2pmem);\n 599:\t\tif (error) {\n 600:\t\t\tret = error;\n 601:\t\t\tgoto out_unlock;\n 602:\t\t}\n 603:\t\n 604:\t\tns-\u003euse_p2pmem = use_p2pmem;\n 605:\t\tpci_dev_put(ns-\u003ep2p_dev);\n 606:\t\tns-\u003ep2p_dev = p2p_dev;\n 607:\t\n 608:\tout_unlock:\n 609:\t\tmutex_unlock(\u0026ns-\u003esubsys-\u003elock);\n 610:\t\n 611:\t\treturn ret;\n 612:\t}\n 613:\t\n 614:\tCONFIGFS_ATTR(nvmet_ns_, p2pmem);\n 615:\t#endif /* CONFIG_PCI_P2PDMA */\n 616:\t\n 617:\tstatic ssize_t nvmet_ns_device_uuid_show(struct config_item *item, char *page)\n 618:\t{\n 619:\t\treturn sprintf(page, \"%pUb\\n\", \u0026to_nvmet_ns(item)-\u003euuid);\n 620:\t}\n 621:\t\n 622:\tstatic ssize_t nvmet_ns_device_uuid_store(struct config_item *item,\n 623:\t\t\t\t\t\t  const char *page, size_t count)\n 624:\t{\n"
}

31/2 2026/11/08 03:25 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 74782
							output: 38
							thoughts: 109
						

Thoughts:
Okay, let me break this down.

**Diving into NVMe P2P Memory Configuration**

Alright, I'm digging into how the `nvmet_ns_p2pmem_store` function handles Peer-to-Peer (P2P) memory configuration. It looks like when the `p2pmem` attribute is updated—be it with "1," "true," or a PCI device identifier—the `pci_p2pdma_enable_store` function gets the job of parsing the input. That parsed information then goes on to set `ns->use_p2pmem` to `true`. Essentially, flipping the switch to indicate that this namespace *should* be using P2P memory.

So, the critical question then becomes: *Where* does this P2P memory get enabled, and how does the target interact with it? I need to check out what happens when the namespace itself is enabled. My next target is `nvmet_p2pmem_ns_enable` located in `drivers/nvme/target/core.c`. Time to dig in!



32/2 2026/11/08 03:25 tool read-file
0m Args:
{
  "File": "drivers/nvme/target/core.c",
  "FirstLine": 490,
  "LineCount": 65
}

Results:
{
  "Contents": " 490:\t}\n 491:\t\n 492:\tstatic int nvmet_p2pmem_ns_enable(struct nvmet_ns *ns)\n 493:\t{\n 494:\t\tint ret;\n 495:\t\tstruct pci_dev *p2p_dev;\n 496:\t\n 497:\t\tif (!ns-\u003euse_p2pmem)\n 498:\t\t\treturn 0;\n 499:\t\n 500:\t\tif (!ns-\u003ebdev) {\n 501:\t\t\tpr_err(\"peer-to-peer DMA is not supported by non-block device namespaces\\n\");\n 502:\t\t\treturn -EINVAL;\n 503:\t\t}\n 504:\t\n 505:\t\tif (!blk_queue_pci_p2pdma(ns-\u003ebdev-\u003ebd_disk-\u003equeue)) {\n 506:\t\t\tpr_err(\"peer-to-peer DMA is not supported by the driver of %s\\n\",\n 507:\t\t\t       ns-\u003edevice_path);\n 508:\t\t\treturn -EINVAL;\n 509:\t\t}\n 510:\t\n 511:\t\tif (ns-\u003ep2p_dev) {\n 512:\t\t\tret = pci_p2pdma_distance(ns-\u003ep2p_dev, nvmet_ns_dev(ns), true);\n 513:\t\t\tif (ret \u003c 0)\n 514:\t\t\t\treturn -EINVAL;\n 515:\t\t} else {\n 516:\t\t\t/*\n 517:\t\t\t * Right now we just check that there is p2pmem available so\n 518:\t\t\t * we can report an error to the user right away if there\n 519:\t\t\t * is not. We'll find the actual device to use once we\n 520:\t\t\t * setup the controller when the port's device is available.\n 521:\t\t\t */\n 522:\t\n 523:\t\t\tp2p_dev = pci_p2pmem_find(nvmet_ns_dev(ns));\n 524:\t\t\tif (!p2p_dev) {\n 525:\t\t\t\tpr_err(\"no peer-to-peer memory is available for %s\\n\",\n 526:\t\t\t\t       ns-\u003edevice_path);\n 527:\t\t\t\treturn -EINVAL;\n 528:\t\t\t}\n 529:\t\n 530:\t\t\tpci_dev_put(p2p_dev);\n 531:\t\t}\n 532:\t\n 533:\t\treturn 0;\n 534:\t}\n 535:\t\n 536:\tstatic void nvmet_p2pmem_ns_add_p2p(struct nvmet_ctrl *ctrl,\n 537:\t\t\t\t\t    struct nvmet_ns *ns)\n 538:\t{\n 539:\t\tstruct device *clients[2];\n 540:\t\tstruct pci_dev *p2p_dev;\n 541:\t\tint ret;\n 542:\t\n 543:\t\tlockdep_assert_held(\u0026ctrl-\u003esubsys-\u003elock);\n 544:\t\n 545:\t\tif (!ctrl-\u003ep2p_client || !ns-\u003euse_p2pmem)\n 546:\t\t\treturn;\n 547:\t\n 548:\t\tif (ns-\u003ep2p_dev) {\n 549:\t\t\tret = pci_p2pdma_distance(ns-\u003ep2p_dev, ctrl-\u003ep2p_client, true);\n 550:\t\t\tif (ret \u003c 0)\n 551:\t\t\t\treturn;\n 552:\t\n 553:\t\t\tp2p_dev = pci_dev_get(ns-\u003ep2p_dev);\n 554:\t\t} else {\n"
}

33/2 2026/11/08 03:25 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 76151
							output: 40
							thoughts: 102
						

Thoughts:
Okay, here's my interpretation of that thought process, tailored for an expert audience:

**Diving into the NVMe P2P Memory Enablement Path**

Alright, so `nvmet_p2pmem_ns_enable` is triggering some P2P memory interactions. My first thought is to understand the control flow. It's calling `pci_p2pmem_find`. Right, that's the key function. Let me see... what's *that* doing? The immediate next thing to trace is where that leads. Ah, `pci_p2pmem_find` branches to `pci_p2pmem_find_many`. Okay, that's where the real work happens, presumably. Time to dig into the implementation itself, so let's check out `drivers/pci/p2pdma.c` to understand the details of `pci_p2pmem_find_many`. I want to see the criteria used to find the right peer device.



34/2 2026/11/08 03:25 tool read-file
0m Args:
{
  "File": "drivers/pci/p2pdma.c",
  "FirstLine": 1620,
  "LineCount": 65
}

Results:
{
  "Contents": "1620:\t\n1621:\t/**\n1622:\t * pci_p2pmem_find_many - find a peer-to-peer DMA memory device compatible with\n1623:\t *\tthe specified list of clients and shortest distance\n1624:\t * @clients: array of devices to check (NULL-terminated)\n1625:\t * @num_clients: number of client devices in the list\n1626:\t *\n1627:\t * If multiple devices are behind the same switch, the one \"closest\" to the\n1628:\t * client devices in use will be chosen first. (So if one of the providers is\n1629:\t * the same as one of the clients, that provider will be used ahead of any\n1630:\t * other providers that are unrelated). If multiple providers are an equal\n1631:\t * distance away, one will be chosen at random.\n1632:\t *\n1633:\t * Returns a pointer to the PCI device with a reference taken (use pci_dev_put\n1634:\t * to return the reference) or NULL if no compatible device is found. The\n1635:\t * found provider will also be assigned to the client list.\n1636:\t */\n1637:\tstruct pci_dev *pci_p2pmem_find_many(struct device **clients, int num_clients)\n1638:\t{\n1639:\t\tstruct pci_dev *pdev = NULL;\n1640:\t\tint distance;\n1641:\t\tint closest_distance = INT_MAX;\n1642:\t\tstruct pci_dev **closest_pdevs;\n1643:\t\tint dev_cnt = 0;\n1644:\t\tconst int max_devs = PAGE_SIZE / sizeof(*closest_pdevs);\n1645:\t\tint i;\n1646:\t\n1647:\t\tclosest_pdevs = kmalloc(PAGE_SIZE, GFP_KERNEL);\n1648:\t\tif (!closest_pdevs)\n1649:\t\t\treturn NULL;\n1650:\t\n1651:\t\tfor_each_pci_dev(pdev) {\n1652:\t\t\tif (!pci_has_p2pmem(pdev))\n1653:\t\t\t\tcontinue;\n1654:\t\n1655:\t\t\tdistance = pci_p2pdma_distance_many(pdev, clients,\n1656:\t\t\t\t\t\t\t    num_clients, false);\n1657:\t\t\tif (distance \u003c 0 || distance \u003e closest_distance)\n1658:\t\t\t\tcontinue;\n1659:\t\n1660:\t\t\tif (distance == closest_distance \u0026\u0026 dev_cnt \u003e= max_devs)\n1661:\t\t\t\tcontinue;\n1662:\t\n1663:\t\t\tif (distance \u003c closest_distance) {\n1664:\t\t\t\tfor (i = 0; i \u003c dev_cnt; i++)\n1665:\t\t\t\t\tpci_dev_put(closest_pdevs[i]);\n1666:\t\n1667:\t\t\t\tdev_cnt = 0;\n1668:\t\t\t\tclosest_distance = distance;\n1669:\t\t\t}\n1670:\t\n1671:\t\t\tclosest_pdevs[dev_cnt++] = pci_dev_get(pdev);\n1672:\t\t}\n1673:\t\n1674:\t\tif (dev_cnt)\n1675:\t\t\tpdev = pci_dev_get(closest_pdevs[get_random_u32_below(dev_cnt)]);\n1676:\t\n1677:\t\tfor (i = 0; i \u003c dev_cnt; i++)\n1678:\t\t\tpci_dev_put(closest_pdevs[i]);\n1679:\t\n1680:\t\tkfree(closest_pdevs);\n1681:\t\treturn pdev;\n1682:\t}\n1683:\tEXPORT_SYMBOL_GPL(pci_p2pmem_find_many);\n1684:\t\n"
}

35/2 2026/11/08 03:25 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 77555
							output: 40
							thoughts: 86
						

Thoughts:
Here's my analysis of the provided code snippet:

**Diving into PCI Device Iteration and P2P Memory**

Okay, so I'm looking at this PCI device iteration, specifically the `for_each_pci_dev(pdev)` loop. The key part I'm focusing on is the conditional check: `if (!pci_has_p2pmem(pdev)) continue;`. It immediately jumps out at me. Clearly, the code is only interested in PCI devices that have some form of P2P memory capability. The loop is being optimized to skip over those that don't.

Now, I need to understand *when* `pci_has_p2pmem(pdev)` actually returns true. That function is the gatekeeper. I immediately know the next step: lines 1600-1620 of `p2pdma.c` - that's where the magic, or the logic at least, is going to be implemented. I'm going to jump straight there. Time to dig in and determine the criteria for a PCI device to be considered a P2P memory device in the context of this code.



36/2 2026/11/08 03:26 tool read-file
0m Args:
{
  "File": "drivers/pci/p2pdma.c",
  "FirstLine": 1600,
  "LineCount": 25
}

Results:
{
  "Contents": "1600:\t * @pdev: PCI device to check\n1601:\t */\n1602:\tstatic bool pci_has_p2pmem(struct pci_dev *pdev)\n1603:\t{\n1604:\t\tstruct pci_p2pdma *p2pdma;\n1605:\t\tbool res;\n1606:\t\n1607:\t\trcu_read_lock();\n1608:\t\tp2pdma = rcu_dereference(pdev-\u003ep2pdma);\n1609:\t\n1610:\t\t/*\n1611:\t\t * The callers hand the result to pci_alloc_p2pmem(), so only a\n1612:\t\t * provider backed by a pool is of any use here. pcim_p2pdma_init()\n1613:\t\t * creates providers without one.\n1614:\t\t */\n1615:\t\tres = p2pdma \u0026\u0026 p2pdma-\u003epool \u0026\u0026 p2pdma-\u003ep2pmem_published;\n1616:\t\trcu_read_unlock();\n1617:\t\n1618:\t\treturn res;\n1619:\t}\n1620:\t\n1621:\t/**\n1622:\t * pci_p2pmem_find_many - find a peer-to-peer DMA memory device compatible with\n1623:\t *\tthe specified list of clients and shortest distance\n1624:\t * @clients: array of devices to check (NULL-terminated)\n"
}

37/2 2026/11/08 03:26 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 78332
							output: 40
							thoughts: 407
						

Thoughts:
**Investigating the `ns->p2p_dev` Logic**

Okay, hold on a second. Something just clicked. I was deep in this NVMe code, and this `ns->p2p_dev` variable popped up. My mind immediately went to `nvmet_ns_p2pmem_store`, and I saw that potential for direct peer-to-peer memory access. The code snippet flagged how `pci_p2pdma_enable_store` is called within the larger function. Specifically, it looked at the sequence involving `pci_p2pdma_enable_store(page, &p2p_dev, &use_p2pmem)`, followed by setting `ns->use_p2pmem` and handling the `ns->p2p_dev`.

And if I follow through, `pci_p2pdma_enable_store` has this interesting bit where it tries to find a device by name (`bus_find_device_by_name`). It checks if such a device exists and that `pci_has_p2pmem` is true for that device. If so, it sets `*p2p_dev` to that device and `*use_p2pdma` to true. But then there's this critical check: `pci_has_p2pmem(*p2p_dev)`. This must be true *before* `p2p_dev` is actually assigned.

So, the key here is `pci_has_p2pmem`. How does a PCI device actually *get* `pci_has_p2pmem` set to true? That's the question I need to answer. I need to figure out where that flag is set in the kernel. Let's see...I'm going to have to do a bit of grepping to trace the function's calls. Earlier, I did find a couple of entries, notably the Habanalabs ASIC accelerator driver. But it also looks like `drivers/nvme/host/pci.c` is involved here, so I will inspect that location! I am going to focus in and look around `nvme_map_cmb`. That looks like a good place to start. Let's see what's going on around there.



38/2 2026/11/08 03:26 tool read-file
0m Args:
{
  "File": "drivers/nvme/host/pci.c",
  "FirstLine": 2735,
  "LineCount": 35
}

Results:
{
  "Contents": "2735:\t\t * Tell the controller about the host side address mapping the CMB,\n2736:\t\t * and enable CMB decoding for the NVMe 1.4+ scheme:\n2737:\t\t */\n2738:\t\tif (NVME_CAP_CMBS(dev-\u003ectrl.cap)) {\n2739:\t\t\thi_lo_writeq(NVME_CMBMSC_CRE | NVME_CMBMSC_CMSE |\n2740:\t\t\t\t     (pci_bus_address(pdev, bar) + offset),\n2741:\t\t\t\t     dev-\u003ebar + NVME_REG_CMBMSC);\n2742:\t\t}\n2743:\t\n2744:\t\tif (pci_p2pdma_add_resource(pdev, bar, size, offset)) {\n2745:\t\t\tdev_warn(dev-\u003ectrl.device,\n2746:\t\t\t\t \"failed to register the CMB\\n\");\n2747:\t\t\thi_lo_writeq(0, dev-\u003ebar + NVME_REG_CMBMSC);\n2748:\t\t\treturn;\n2749:\t\t}\n2750:\t\n2751:\t\tdev-\u003ecmb_size = size;\n2752:\t\tdev-\u003ecmb_use_sqes = use_cmb_sqes \u0026\u0026 (dev-\u003ecmbsz \u0026 NVME_CMBSZ_SQS);\n2753:\t\n2754:\t\tif ((dev-\u003ecmbsz \u0026 (NVME_CMBSZ_WDS | NVME_CMBSZ_RDS)) ==\n2755:\t\t\t\t(NVME_CMBSZ_WDS | NVME_CMBSZ_RDS))\n2756:\t\t\tpci_p2pmem_publish(pdev, true);\n2757:\t}\n2758:\t\n2759:\tstatic int nvme_set_host_mem(struct nvme_dev *dev, u32 bits)\n2760:\t{\n2761:\t\tu32 host_mem_size = dev-\u003ehost_mem_size \u003e\u003e NVME_CTRL_PAGE_SHIFT;\n2762:\t\tu64 dma_addr = dev-\u003ehost_mem_descs_dma;\n2763:\t\tstruct nvme_command c = { };\n2764:\t\tint ret;\n2765:\t\n2766:\t\tc.features.opcode\t= nvme_admin_set_features;\n2767:\t\tc.features.fid\t\t= cpu_to_le32(NVME_FEAT_HOST_MEM_BUF);\n2768:\t\tc.features.dword11\t= cpu_to_le32(bits);\n2769:\t\tc.features.dword12\t= cpu_to_le32(host_mem_size);\n"
}

39/2 2026/11/08 03:26 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 79979
							output: 23
							thoughts: 121
						

Thoughts:
**NVMe CMB Implementation Thoughts**

Alright, so I'm looking at this and thinking, "NVMe CMB, now that's interesting!" Within the QEMU environment, I wonder if an NVMe device has the capability to provide a Controller Memory Buffer, or CMB? A quick check confirms that, yes, the `-device nvme,...,cmb_size_mb=...` option allows for the CMB functionality, complete with Write Data Shadowing (WDS) and Read Data Shadowing (RDS)!

But, a new question arises: what about configurations *without* a CMB? Could we leverage `pci_p2pdma` or even the slightly different `pcim_p2pdma_init` function in this situation? The idea has merit and warrants investigation. Ah, I should remind myself where `pcim_p2pdma_init` is actually called. Best to do a quick `grep` for `pcim_p2pdma_init` in the source! Let's see what that uncovers...



40/2 2026/11/08 03:26 tool grepper
0m Args:
{
  "Expression": "pcim_p2pdma_init"
}

Results:
{
  "Output": "drivers/infiniband/hw/mlx5/main.c=4433=static int mlx5_ib_stage_init_init(struct mlx5_ib_dev *dev)\n--\ndrivers/infiniband/hw/mlx5/main.c-4490-\ndrivers/infiniband/hw/mlx5/main.c:4491:\terr = pcim_p2pdma_init(mdev-\u003epdev);\ndrivers/infiniband/hw/mlx5/main.c-4492-\tif (err \u0026\u0026 err != -EOPNOTSUPP)\n--\ndrivers/pci/p2pdma.c=232=static void pci_p2pdma_release(void *data)\n--\ndrivers/pci/p2pdma.c-253-/**\ndrivers/pci/p2pdma.c:254: * pcim_p2pdma_init - Initialise peer-to-peer DMA providers\ndrivers/pci/p2pdma.c-255- * @pdev: The PCI device to enable P2PDMA for\n--\ndrivers/pci/p2pdma.c-261- */\ndrivers/pci/p2pdma.c:262:int pcim_p2pdma_init(struct pci_dev *pdev)\ndrivers/pci/p2pdma.c-263-{\n--\ndrivers/pci/p2pdma.c-304-}\ndrivers/pci/p2pdma.c:305:EXPORT_SYMBOL_GPL(pcim_p2pdma_init);\ndrivers/pci/p2pdma.c-306-\n--\ndrivers/pci/p2pdma.c=322=struct p2pdma_provider *pcim_p2pdma_provider(struct pci_dev *pdev, int bar)\n--\ndrivers/pci/p2pdma.c-331-\tif (WARN_ON(!p2p))\ndrivers/pci/p2pdma.c:332:\t\t/* Someone forgot to call to pcim_p2pdma_init() before */\ndrivers/pci/p2pdma.c-333-\t\treturn NULL;\n--\ndrivers/pci/p2pdma.c=389=int pci_p2pdma_add_resource(struct pci_dev *pdev, int bar, size_t size,\n--\ndrivers/pci/p2pdma.c-410-\ndrivers/pci/p2pdma.c:411:\terror = pcim_p2pdma_init(pdev);\ndrivers/pci/p2pdma.c-412-\tif (error)\n--\ndrivers/pci/p2pdma.c=1602=static bool pci_has_p2pmem(struct pci_dev *pdev)\n--\ndrivers/pci/p2pdma.c-1611-\t * The callers hand the result to pci_alloc_p2pmem(), so only a\ndrivers/pci/p2pdma.c:1612:\t * provider backed by a pool is of any use here. pcim_p2pdma_init()\ndrivers/pci/p2pdma.c-1613-\t * creates providers without one.\n--\ndrivers/pci/p2pdma.c=1840=EXPORT_SYMBOL_GPL(pci_p2pmem_publish);\n--\ndrivers/pci/p2pdma.c-1850- *\ndrivers/pci/p2pdma.c:1851: * Call it once pcim_p2pdma_init() has succeeded. Without P2PDMA state the\ndrivers/pci/p2pdma.c-1852- * declaration is dropped and the ATS Enable bit keeps deciding.\n--\ndrivers/pci/p2pdma.c=1854=void pcim_p2pdma_set_ats_per_mapping(struct pci_dev *pdev)\n--\ndrivers/pci/p2pdma.c-1861-\t\t * ats_per_mapping is a performance optimization,\ndrivers/pci/p2pdma.c:1862:\t\t * if pcim_p2pdma_init() didn't set pdev-\u003ep2pdma pointer\ndrivers/pci/p2pdma.c-1863-\t\t * for some reason, let's simply use ATS global settings.\n--\ndrivers/vfio/pci/vfio_pci_core.c=2168=int vfio_pci_core_init_dev(struct vfio_device *core_vdev)\n--\ndrivers/vfio/pci/vfio_pci_core.c-2181-\tINIT_LIST_HEAD(\u0026vdev-\u003esriov_pfs_item);\ndrivers/vfio/pci/vfio_pci_core.c:2182:\tret = pcim_p2pdma_init(vdev-\u003epdev);\ndrivers/vfio/pci/vfio_pci_core.c-2183-\tif (ret \u0026\u0026 ret != -EOPNOTSUPP)\n--\ninclude/linux/pci-p2pdma.h=31=enum pci_p2pdma_map_type {\n--\ninclude/linux/pci-p2pdma.h-70-#ifdef CONFIG_PCI_P2PDMA\ninclude/linux/pci-p2pdma.h:71:int pcim_p2pdma_init(struct pci_dev *pdev);\ninclude/linux/pci-p2pdma.h-72-struct p2pdma_provider *pcim_p2pdma_provider(struct pci_dev *pdev, int bar);\n--\ninclude/linux/pci-p2pdma.h=90=enum pci_p2pdma_map_type pci_p2pdma_map_type(struct p2pdma_provider *provider,\n--\ninclude/linux/pci-p2pdma.h-92-#else /* CONFIG_PCI_P2PDMA */\ninclude/linux/pci-p2pdma.h:93:static inline int pcim_p2pdma_init(struct pci_dev *pdev)\ninclude/linux/pci-p2pdma.h-94-{\n"
}

41/2 2026/11/08 03:26 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 81928
							output: 23
							thoughts: 81
						

Thoughts:
Here's my summary, as though I were thinking through the problem:

**Delving into the VFIO PCI Core Initialization**

Okay, so I'm digging into the VFIO PCI initialization sequence. Specifically, I'm at `drivers/vfio/pci/vfio_pci_core.c`. Right, `vfio_pci_core_init_dev` is the crucial function here. And aha! It calls `pcim_p2pdma_init(vdev->pdev);`. That’s interesting, because that's what I was looking for. Now the next question. What actually *provides* `pcim_p2pdma_provider`? I know I need to track down the call chain, so let's go back and examine the code.



42/2 2026/11/08 03:26 tool grepper
0m Args:
{
  "Expression": "pcim_p2pdma_provider"
}

Results:
{
  "Output": "drivers/infiniband/hw/mlx5/main.c=2501=static int mlx5_ib_mmap_get_pfns(struct rdma_user_mmap_entry *entry,\n--\ndrivers/infiniband/hw/mlx5/main.c-2515-\ndrivers/infiniband/hw/mlx5/main.c:2516:\t*provider = pcim_p2pdma_provider(pdev, bar);\ndrivers/infiniband/hw/mlx5/main.c-2517-\t/* If the kernel was not compiled with CONFIG_PCI_P2PDMA the\n--\ndrivers/pci/p2pdma.c=305=EXPORT_SYMBOL_GPL(pcim_p2pdma_init);\n--\ndrivers/pci/p2pdma.c-307-/**\ndrivers/pci/p2pdma.c:308: * pcim_p2pdma_provider - Get peer-to-peer DMA provider\ndrivers/pci/p2pdma.c-309- * @pdev: The PCI device to enable P2PDMA for\n--\ndrivers/pci/p2pdma.c-321- */\ndrivers/pci/p2pdma.c:322:struct p2pdma_provider *pcim_p2pdma_provider(struct pci_dev *pdev, int bar)\ndrivers/pci/p2pdma.c-323-{\n--\ndrivers/pci/p2pdma.c-336-}\ndrivers/pci/p2pdma.c:337:EXPORT_SYMBOL_GPL(pcim_p2pdma_provider);\ndrivers/pci/p2pdma.c-338-\n--\ndrivers/pci/p2pdma.c=389=int pci_p2pdma_add_resource(struct pci_dev *pdev, int bar, size_t size,\n--\ndrivers/pci/p2pdma.c-418-\ndrivers/pci/p2pdma.c:419:\tmem = pcim_p2pdma_provider(pdev, bar);\ndrivers/pci/p2pdma.c-420-\t/*\ndrivers/pci/p2pdma.c-421-\t * We checked validity of BAR prior to call\ndrivers/pci/p2pdma.c:422:\t * to pcim_p2pdma_provider. It should never return NULL.\ndrivers/pci/p2pdma.c-423-\t */\n--\ndrivers/vfio/pci/nvgrace-gpu/main.c=1022=static int nvgrace_get_dmabuf_phys(struct vfio_pci_core_device *core_vdev,\n--\ndrivers/vfio/pci/nvgrace-gpu/main.c-1048-\tif (mem_region) {\ndrivers/vfio/pci/nvgrace-gpu/main.c:1049:\t\t*provider = pcim_p2pdma_provider(pdev, 0);\ndrivers/vfio/pci/nvgrace-gpu/main.c-1050-\t\tif (!*provider)\n--\ndrivers/vfio/pci/vfio_pci_dmabuf.c=172=int vfio_pci_core_get_dmabuf_phys(struct vfio_pci_core_device *vdev,\n--\ndrivers/vfio/pci/vfio_pci_dmabuf.c-180-\ndrivers/vfio/pci/vfio_pci_dmabuf.c:181:\t*provider = pcim_p2pdma_provider(pdev, region_index);\ndrivers/vfio/pci/vfio_pci_dmabuf.c-182-\tif (!*provider)\n--\ninclude/linux/pci-p2pdma.h=71=int pcim_p2pdma_init(struct pci_dev *pdev);\ninclude/linux/pci-p2pdma.h:72:struct p2pdma_provider *pcim_p2pdma_provider(struct pci_dev *pdev, int bar);\ninclude/linux/pci-p2pdma.h-73-int pci_p2pdma_add_resource(struct pci_dev *pdev, int bar, size_t size,\n--\ninclude/linux/pci-p2pdma.h=93=static inline int pcim_p2pdma_init(struct pci_dev *pdev)\n--\ninclude/linux/pci-p2pdma.h-96-}\ninclude/linux/pci-p2pdma.h:97:static inline struct p2pdma_provider *pcim_p2pdma_provider(struct pci_dev *pdev,\ninclude/linux/pci-p2pdma.h-98-\t\t\t\t\t\t\t   int bar)\n"
}

43/2 2026/11/08 03:26 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 83443
							output: 46
							thoughts: 53
						

Thoughts:
Here's my take on the thought process, tailored for an expert audience:

**Diving into DMA Buffer Handling in VFIO-PCI**

Alright, let's get down to brass tacks. I need to understand how DMA buffers are managed within the VFIO-PCI framework, specifically how they handle physical addresses and mapping. My focus is immediately drawn to `vfio_pci_dmabuf.c`. This is where the magic (or potential headache, depending on the implementation) likely happens.

I'm particularly interested in tracing the control flow that maps DMA buffers into userspace. First, I need to know how the physical address associated with a DMA buffer is retrieved, so I'm going to carefully inspect `vfio_pci_core_get_dmabuf_phys`. I want to understand what the logic is behind the method to get the physical address of the buffer.

Following that path, I need to get a clear picture of the mapping process itself. Therefore, I will turn my attention to `vfio_pci_dma_buf_map`. Understanding this function is crucial. How is the physical address obtained by `vfio_pci_core_get_dmabuf_phys` utilized? What kind of memory management routines are used internally? Does this code interact with the IOMMU? I'm anticipating that understanding the relationship between the physical address, the DMA buffer, and the userspace mapping within these two functions will give me the insights I need to understand the DMA buffer handling.



44/2 2026/11/08 03:26 tool read-file
0m Args:
{
  "File": "drivers/vfio/pci/vfio_pci_dmabuf.c",
  "FirstLine": 40,
  "LineCount": 50
}

Results:
{
  "Contents": "  40:\t}\n  41:\t\n  42:\tstatic void vfio_pci_dma_buf_done(struct kref *kref)\n  43:\t{\n  44:\t\tstruct vfio_pci_dma_buf *priv =\n  45:\t\t\tcontainer_of(kref, struct vfio_pci_dma_buf, kref);\n  46:\t\n  47:\t\tcomplete(\u0026priv-\u003ecomp);\n  48:\t}\n  49:\t\n  50:\tstatic struct sg_table *\n  51:\tvfio_pci_dma_buf_map(struct dma_buf_attachment *attachment,\n  52:\t\t\t     enum dma_data_direction dir)\n  53:\t{\n  54:\t\tstruct vfio_pci_dma_buf *priv = attachment-\u003edmabuf-\u003epriv;\n  55:\t\tstruct sg_table *ret;\n  56:\t\n  57:\t\tdma_resv_assert_held(priv-\u003edmabuf-\u003eresv);\n  58:\t\n  59:\t\tif (priv-\u003erevoked)\n  60:\t\t\treturn ERR_PTR(-ENODEV);\n  61:\t\n  62:\t\tret = dma_buf_phys_vec_to_sgt(attachment, priv-\u003eprovider,\n  63:\t\t\t\t\t      priv-\u003ephys_vec, priv-\u003enr_ranges,\n  64:\t\t\t\t\t      priv-\u003esize, dir);\n  65:\t\tif (IS_ERR(ret))\n  66:\t\t\treturn ret;\n  67:\t\n  68:\t\tkref_get(\u0026priv-\u003ekref);\n  69:\t\treturn ret;\n  70:\t}\n  71:\t\n  72:\tstatic void vfio_pci_dma_buf_unmap(struct dma_buf_attachment *attachment,\n  73:\t\t\t\t\t   struct sg_table *sgt,\n  74:\t\t\t\t\t   enum dma_data_direction dir)\n  75:\t{\n  76:\t\tstruct vfio_pci_dma_buf *priv = attachment-\u003edmabuf-\u003epriv;\n  77:\t\n  78:\t\tdma_resv_assert_held(priv-\u003edmabuf-\u003eresv);\n  79:\t\n  80:\t\tdma_buf_free_sgt(attachment, sgt, dir);\n  81:\t\tkref_put(\u0026priv-\u003ekref, vfio_pci_dma_buf_done);\n  82:\t}\n  83:\t\n  84:\tstatic void vfio_pci_dma_buf_release(struct dma_buf *dmabuf)\n  85:\t{\n  86:\t\tstruct vfio_pci_dma_buf *priv = dmabuf-\u003epriv;\n  87:\t\n  88:\t\t/*\n  89:\t\t * Either this or vfio_pci_dma_buf_cleanup() will remove from the list.\n"
}

45/2 2026/11/08 03:26 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 84611
							output: 37
							thoughts: 85
						

Thoughts:
Okay, let me think this through.

**Investigating vfio-pci and DMA Buffer Mapping**

Alright, so I'm trying to trace the invocation of `vfio_pci_dma_buf_map`. The key is to remember that this has to be triggered through the DMA buffer operations, specifically the `map_dma_buf` method. Which means another driver must be attaching to the dmabuf and requesting a mapping. That's the entry point I need to focus on.

But how is the dmabuf itself exposed by vfio-pci? I'll need to figure out which ioctl call does that. The logical place to start digging is `vfio_pci_dmabuf.c`. Let's see what's in there.



46/2 2026/11/08 03:26 tool grepper
0m Args:
{
  "Expression": "ioctl|dma_buf_export",
  "PathPrefixes": [
    "drivers/vfio/pci/"
  ]
}

Results:
{
  "Output": "\nFull output is too long, showing 200 out of 365 lines.\nUse more precise expression or PathPrefixes if possible.\n\nNumber of matching lines per file (18 files in total):\ndrivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c:13\ndrivers/vfio/pci/ism/main.c:4\ndrivers/vfio/pci/mlx5/main.c:7\ndrivers/vfio/pci/nvgrace-gpu/main.c:10\ndrivers/vfio/pci/pds/pci_drv.c:1\ndrivers/vfio/pci/pds/vfio_dev.c:3\ndrivers/vfio/pci/qat/main.c:6\ndrivers/vfio/pci/vfio_pci.c:3\ndrivers/vfio/pci/vfio_pci_config.c:1\ndrivers/vfio/pci/vfio_pci_core.c:26\ndrivers/vfio/pci/vfio_pci_dmabuf.c:1\ndrivers/vfio/pci/vfio_pci_intrs.c:3\ndrivers/vfio/pci/vfio_pci_priv.h:1\ndrivers/vfio/pci/virtio/common.h:1\ndrivers/vfio/pci/virtio/legacy_io.c:2\ndrivers/vfio/pci/virtio/main.c:9\ndrivers/vfio/pci/virtio/migrate.c:4\ndrivers/vfio/pci/xe/main.c:3\n\ndrivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c=797=hisi_acc_vf_pci_resume(struct hisi_acc_vf_core_device *hisi_acc_vdev)\n--\ndrivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c-819-\ndrivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c:820:static long hisi_acc_vf_precopy_ioctl(struct file *filp,\ndrivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c-821-\t\t\t\t      unsigned int cmd, unsigned long arg)\n--\ndrivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c-828-\ndrivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c:829:\tret = vfio_check_precopy_ioctl(\u0026hisi_acc_vdev-\u003ecore_device.vdev, cmd,\ndrivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c-830-\t\t\t\t       arg, \u0026info);\n--\ndrivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c=904=static const struct file_operations hisi_acc_vf_save_fops = {\n--\ndrivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c-906-\t.read = hisi_acc_vf_save_read,\ndrivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c:907:\t.unlocked_ioctl = hisi_acc_vf_precopy_ioctl,\ndrivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c:908:\t.compat_ioctl = compat_ptr_ioctl,\ndrivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c-909-\t.release = hisi_acc_vf_release_file,\n--\ndrivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c=1192=static int hisi_acc_vf_qm_init(struct hisi_acc_vf_core_device *hisi_acc_vdev)\n--\ndrivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c-1214-\t\t * we restrict access to the migration control space from\ndrivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c:1215:\t\t * Guest(Please see mmap/ioctl/read/write override functions).\ndrivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c-1216-\t\t *\n--\ndrivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c=1355=static ssize_t hisi_acc_vfio_pci_read(struct vfio_device *core_vdev,\n--\ndrivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c-1368-\ndrivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c:1369:static int hisi_acc_vfio_ioctl_get_region(struct vfio_device *core_vdev,\ndrivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c-1370-\t\t\t\t\t  struct vfio_region_info *info,\n--\ndrivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c-1376-\tif (info-\u003eindex != VFIO_PCI_BAR2_REGION_INDEX)\ndrivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c:1377:\t\treturn vfio_pci_ioctl_get_region_info(core_vdev, info, caps);\ndrivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c-1378-\n--\ndrivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c=1574=static const struct vfio_device_ops hisi_acc_vfio_pci_migrn_ops = {\n--\ndrivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c-1579-\t.close_device = hisi_acc_vfio_pci_close_device,\ndrivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c:1580:\t.ioctl = vfio_pci_core_ioctl,\ndrivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c:1581:\t.get_region_info_caps = hisi_acc_vfio_ioctl_get_region,\ndrivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c:1582:\t.device_feature = vfio_pci_core_ioctl_feature,\ndrivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c-1583-\t.read = hisi_acc_vfio_pci_read,\n--\ndrivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c=1595=static const struct vfio_device_ops hisi_acc_vfio_pci_ops = {\n--\ndrivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c-1600-\t.close_device = vfio_pci_core_close_device,\ndrivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c:1601:\t.ioctl = vfio_pci_core_ioctl,\ndrivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c:1602:\t.get_region_info_caps = vfio_pci_ioctl_get_region_info,\ndrivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c:1603:\t.device_feature = vfio_pci_core_ioctl_feature,\ndrivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c-1604-\t.read = vfio_pci_core_read,\n--\ndrivers/vfio/pci/ism/main.c=257=static ssize_t ism_vfio_pci_write(struct vfio_device *core_vdev,\n--\ndrivers/vfio/pci/ism/main.c-264-\ndrivers/vfio/pci/ism/main.c:265:static int ism_vfio_pci_ioctl_get_region_info(struct vfio_device *core_vdev,\ndrivers/vfio/pci/ism/main.c-266-\t\t\t\t\t      struct vfio_region_info *info,\n--\ndrivers/vfio/pci/ism/main.c=338=static const struct vfio_device_ops ism_pci_ops = {\n--\ndrivers/vfio/pci/ism/main.c-343-\t.close_device = vfio_pci_core_close_device,\ndrivers/vfio/pci/ism/main.c:344:\t.ioctl = vfio_pci_core_ioctl,\ndrivers/vfio/pci/ism/main.c:345:\t.get_region_info_caps = ism_vfio_pci_ioctl_get_region_info,\ndrivers/vfio/pci/ism/main.c:346:\t.device_feature = vfio_pci_core_ioctl_feature,\ndrivers/vfio/pci/ism/main.c-347-\t.read = ism_vfio_pci_read,\n--\ndrivers/vfio/pci/mlx5/main.c=379=static int mlx5vf_prep_stop_copy(struct mlx5vf_pci_core_device *mvdev,\n--\ndrivers/vfio/pci/mlx5/main.c-458-\ndrivers/vfio/pci/mlx5/main.c:459:static long mlx5vf_precopy_ioctl(struct file *filp, unsigned int cmd,\ndrivers/vfio/pci/mlx5/main.c-460-\t\t\t\t unsigned long arg)\n--\ndrivers/vfio/pci/mlx5/main.c-472-\ndrivers/vfio/pci/mlx5/main.c:473:\tret = vfio_check_precopy_ioctl(\u0026mvdev-\u003ecore_device.vdev, cmd, arg,\ndrivers/vfio/pci/mlx5/main.c-474-\t\t\t\t       \u0026info);\n--\ndrivers/vfio/pci/mlx5/main.c=583=static const struct file_operations mlx5vf_save_fops = {\n--\ndrivers/vfio/pci/mlx5/main.c-586-\t.poll = mlx5vf_save_poll,\ndrivers/vfio/pci/mlx5/main.c:587:\t.unlocked_ioctl = mlx5vf_precopy_ioctl,\ndrivers/vfio/pci/mlx5/main.c:588:\t.compat_ioctl = compat_ptr_ioctl,\ndrivers/vfio/pci/mlx5/main.c-589-\t.release = mlx5vf_release_file,\n--\ndrivers/vfio/pci/mlx5/main.c=1386=static const struct vfio_device_ops mlx5vf_pci_ops = {\n--\ndrivers/vfio/pci/mlx5/main.c-1391-\t.close_device = mlx5vf_pci_close_device,\ndrivers/vfio/pci/mlx5/main.c:1392:\t.ioctl = vfio_pci_core_ioctl,\ndrivers/vfio/pci/mlx5/main.c:1393:\t.get_region_info_caps = vfio_pci_ioctl_get_region_info,\ndrivers/vfio/pci/mlx5/main.c:1394:\t.device_feature = vfio_pci_core_ioctl_feature,\ndrivers/vfio/pci/mlx5/main.c-1395-\t.read = vfio_pci_core_read,\n--\ndrivers/vfio/pci/nvgrace-gpu/main.c=476=static int nvgrace_gpu_mmap(struct vfio_device *core_vdev,\n--\ndrivers/vfio/pci/nvgrace-gpu/main.c-534-\ndrivers/vfio/pci/nvgrace-gpu/main.c:535:static int nvgrace_gpu_ioctl_get_region_info(struct vfio_device *core_vdev,\ndrivers/vfio/pci/nvgrace-gpu/main.c-536-\t\t\t\t\t     struct vfio_region_info *info,\n--\ndrivers/vfio/pci/nvgrace-gpu/main.c-552-\tif (!memregion)\ndrivers/vfio/pci/nvgrace-gpu/main.c:553:\t\treturn vfio_pci_ioctl_get_region_info(core_vdev, info, caps);\ndrivers/vfio/pci/nvgrace-gpu/main.c-554-\n--\ndrivers/vfio/pci/nvgrace-gpu/main.c-589-\ndrivers/vfio/pci/nvgrace-gpu/main.c:590:static long nvgrace_gpu_ioctl(struct vfio_device *core_vdev,\ndrivers/vfio/pci/nvgrace-gpu/main.c-591-\t\t\t      unsigned int cmd, unsigned long arg)\n--\ndrivers/vfio/pci/nvgrace-gpu/main.c-599-\tdefault:\ndrivers/vfio/pci/nvgrace-gpu/main.c:600:\t\treturn vfio_pci_core_ioctl(core_vdev, cmd, arg);\ndrivers/vfio/pci/nvgrace-gpu/main.c-601-\t}\n--\ndrivers/vfio/pci/nvgrace-gpu/main.c=1066=static const struct vfio_device_ops nvgrace_gpu_pci_ops = {\n--\ndrivers/vfio/pci/nvgrace-gpu/main.c-1071-\t.close_device\t= nvgrace_gpu_close_device,\ndrivers/vfio/pci/nvgrace-gpu/main.c:1072:\t.ioctl\t\t= nvgrace_gpu_ioctl,\ndrivers/vfio/pci/nvgrace-gpu/main.c:1073:\t.get_region_info_caps = nvgrace_gpu_ioctl_get_region_info,\ndrivers/vfio/pci/nvgrace-gpu/main.c:1074:\t.device_feature\t= vfio_pci_core_ioctl_feature,\ndrivers/vfio/pci/nvgrace-gpu/main.c-1075-\t.read\t\t= nvgrace_gpu_read,\n--\ndrivers/vfio/pci/nvgrace-gpu/main.c=1106=static const struct vfio_device_ops nvgrace_gpu_pci_core_ops = {\n--\ndrivers/vfio/pci/nvgrace-gpu/main.c-1111-\t.close_device\t= vfio_pci_core_close_device,\ndrivers/vfio/pci/nvgrace-gpu/main.c:1112:\t.ioctl\t\t= vfio_pci_core_ioctl,\ndrivers/vfio/pci/nvgrace-gpu/main.c:1113:\t.get_region_info_caps = vfio_pci_ioctl_get_region_info,\ndrivers/vfio/pci/nvgrace-gpu/main.c:1114:\t.device_feature\t= vfio_pci_core_ioctl_feature,\ndrivers/vfio/pci/nvgrace-gpu/main.c-1115-\t.read\t\t= vfio_pci_core_read,\n--\ndrivers/vfio/pci/pds/pci_drv.c=25=static void pds_vfio_recovery(struct pds_vfio_pci_device *pds_vfio)\n--\ndrivers/vfio/pci/pds/pci_drv.c-29-\t * generate asynchronous device state transitions outside of\ndrivers/vfio/pci/pds/pci_drv.c:30:\t * manipulation by the user or the VFIO_DEVICE_RESET ioctl.\ndrivers/vfio/pci/pds/pci_drv.c-31-\t *\n--\ndrivers/vfio/pci/pds/vfio_dev.c=188=static const struct vfio_device_ops pds_vfio_ops = {\n--\ndrivers/vfio/pci/pds/vfio_dev.c-193-\t.close_device = pds_vfio_close_device,\ndrivers/vfio/pci/pds/vfio_dev.c:194:\t.ioctl = vfio_pci_core_ioctl,\ndrivers/vfio/pci/pds/vfio_dev.c:195:\t.get_region_info_caps = vfio_pci_ioctl_get_region_info,\ndrivers/vfio/pci/pds/vfio_dev.c:196:\t.device_feature = vfio_pci_core_ioctl_feature,\ndrivers/vfio/pci/pds/vfio_dev.c-197-\t.read = vfio_pci_core_read,\n--\ndrivers/vfio/pci/qat/main.c=109=static void qat_vf_pci_close_device(struct vfio_device *core_vdev)\n--\ndrivers/vfio/pci/qat/main.c-118-\ndrivers/vfio/pci/qat/main.c:119:static long qat_vf_precopy_ioctl(struct file *filp, unsigned int cmd,\ndrivers/vfio/pci/qat/main.c-120-\t\t\t\t unsigned long arg)\n--\ndrivers/vfio/pci/qat/main.c-128-\ndrivers/vfio/pci/qat/main.c:129:\tret = vfio_check_precopy_ioctl(\u0026qat_vdev-\u003ecore_device.vdev, cmd, arg,\ndrivers/vfio/pci/qat/main.c-130-\t\t\t\t       \u0026info);\n--\ndrivers/vfio/pci/qat/main.c=215=static const struct file_operations qat_vf_save_fops = {\n--\ndrivers/vfio/pci/qat/main.c-217-\t.read = qat_vf_save_read,\ndrivers/vfio/pci/qat/main.c:218:\t.unlocked_ioctl = qat_vf_precopy_ioctl,\ndrivers/vfio/pci/qat/main.c:219:\t.compat_ioctl = compat_ptr_ioctl,\ndrivers/vfio/pci/qat/main.c-220-\t.release = qat_vf_release_file,\n--\ndrivers/vfio/pci/qat/main.c=607=static const struct vfio_device_ops qat_vf_pci_ops = {\n--\ndrivers/vfio/pci/qat/main.c-612-\t.close_device = qat_vf_pci_close_device,\ndrivers/vfio/pci/qat/main.c:613:\t.ioctl = vfio_pci_core_ioctl,\ndrivers/vfio/pci/qat/main.c:614:\t.get_region_info_caps = vfio_pci_ioctl_get_region_info,\ndrivers/vfio/pci/qat/main.c-615-\t.read = vfio_pci_core_read,\n--\ndrivers/vfio/pci/vfio_pci.c=149=static const struct vfio_device_ops vfio_pci_ops = {\n--\ndrivers/vfio/pci/vfio_pci.c-154-\t.close_device\t= vfio_pci_core_close_device,\ndrivers/vfio/pci/vfio_pci.c:155:\t.ioctl\t\t= vfio_pci_core_ioctl,\ndrivers/vfio/pci/vfio_pci.c:156:\t.get_region_info_caps = vfio_pci_ioctl_get_region_info,\ndrivers/vfio/pci/vfio_pci.c:157:\t.device_feature = vfio_pci_core_ioctl_feature,\ndrivers/vfio/pci/vfio_pci.c-158-\t.read\t\t= vfio_pci_core_read,\n--\ndrivers/vfio/pci/vfio_pci_config.c=1169=static int vfio_msi_config_write(struct vfio_pci_core_device *vdev, int pos,\n--\ndrivers/vfio/pci/vfio_pci_config.c-1188-\ndrivers/vfio/pci/vfio_pci_config.c:1189:\t\t/* MSI is enabled via ioctl */\ndrivers/vfio/pci/vfio_pci_config.c-1190-\t\tif  (vdev-\u003eirq_type != VFIO_PCI_MSI_IRQ_INDEX)\n--\ndrivers/vfio/pci/vfio_pci_core.c=396=static int vfio_pci_core_pm_entry(struct vfio_pci_core_device *vdev, u32 flags,\n--\ndrivers/vfio/pci/vfio_pci_core.c-407-\t * will be decremented. The pm_runtime_put() will be invoked again\ndrivers/vfio/pci/vfio_pci_core.c:408:\t * while returning from the ioctl and then the device can go into\ndrivers/vfio/pci/vfio_pci_core.c-409-\t * runtime suspended state.\n--\ndrivers/vfio/pci/vfio_pci_core.c=471=static int vfio_pci_core_pm_exit(struct vfio_pci_core_device *vdev, u32 flags,\n--\ndrivers/vfio/pci/vfio_pci_core.c-481-\t * The device is always in the active state here due to pm wrappers\ndrivers/vfio/pci/vfio_pci_core.c:482:\t * around ioctls. If the device had entered a low power state and\ndrivers/vfio/pci/vfio_pci_core.c-483-\t * pm_wake_eventfd_ctx is valid, vfio_pci_core_runtime_resume() has\n--\ndrivers/vfio/pci/vfio_pci_core.c=670=void vfio_pci_core_disable(struct vfio_pci_core_device *vdev)\n--\ndrivers/vfio/pci/vfio_pci_core.c-706-\ndrivers/vfio/pci/vfio_pci_core.c:707:\tvfio_pci_set_irqs_ioctl(vdev, VFIO_IRQ_SET_DATA_NONE |\ndrivers/vfio/pci/vfio_pci_core.c-708-\t\t\t\tVFIO_IRQ_SET_ACTION_TRIGGER,\n--\ndrivers/vfio/pci/vfio_pci_core.c=1029=static int vfio_pci_info_atomic_cap(struct vfio_pci_core_device *vdev,\n--\ndrivers/vfio/pci/vfio_pci_core.c-1059-\ndrivers/vfio/pci/vfio_pci_core.c:1060:static int vfio_pci_ioctl_get_info(struct vfio_pci_core_device *vdev,\ndrivers/vfio/pci/vfio_pci_core.c-1061-\t\t\t\t   struct vfio_device_info __user *arg)\n--\ndrivers/vfio/pci/vfio_pci_core.c-1116-\ndrivers/vfio/pci/vfio_pci_core.c:1117:int vfio_pci_ioctl_get_region_info(struct vfio_device *core_vdev,\n\n"
}

47/2 2026/11/08 03:26 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 91097
							output: 44
							thoughts: 54
						

Thoughts:
Okay, let's dive into this.

**VFIO PCI IOCTL Feature Exploration**

Alright, I need to get a clear picture of how Direct Memory Buffers (dmabufs) are handled within the VFIO PCI context. My immediate focus is on the `drivers/vfio/pci/vfio_pci_core.c` file. I'm going to pinpoint the specific location where `vfio_pci_core_ioctl_feature` (if it exists) handles dmabuf-related operations, or, if not directly within that function, then at least see how dmabufs are handled by `vfio_pci_core_ioctl`. Essentially, I want to understand the flow and logic surrounding this integration. I need to understand how the feature is implemented, or where to find the handling of these buffers, which is crucial for my understanding of the VFIO PCI design.



48/2 2026/11/08 03:26 tool grepper
0m Args:
{
  "Expression": "vfio_pci_core_get_dmabuf_phys",
  "PathPrefixes": [
    "drivers/vfio/pci/"
  ]
}

Results:
{
  "Output": "drivers/vfio/pci/nvgrace-gpu/main.c=1022=static int nvgrace_get_dmabuf_phys(struct vfio_pci_core_device *core_vdev,\n--\ndrivers/vfio/pci/nvgrace-gpu/main.c-1057-\ndrivers/vfio/pci/nvgrace-gpu/main.c:1058:\treturn vfio_pci_core_get_dmabuf_phys(core_vdev, provider, region_index,\ndrivers/vfio/pci/nvgrace-gpu/main.c-1059-\t\t\t\t\t     phys_vec, dma_ranges, nr_ranges);\n--\ndrivers/vfio/pci/nvgrace-gpu/main.c=1102=static const struct vfio_pci_device_ops nvgrace_gpu_pci_dev_core_ops = {\ndrivers/vfio/pci/nvgrace-gpu/main.c:1103:\t.get_dmabuf_phys = vfio_pci_core_get_dmabuf_phys,\ndrivers/vfio/pci/nvgrace-gpu/main.c-1104-};\n--\ndrivers/vfio/pci/vfio_pci.c=172=static const struct vfio_pci_device_ops vfio_pci_dev_ops = {\ndrivers/vfio/pci/vfio_pci.c:173:\t.get_dmabuf_phys = vfio_pci_core_get_dmabuf_phys,\ndrivers/vfio/pci/vfio_pci.c-174-};\n--\ndrivers/vfio/pci/vfio_pci_dmabuf.c=170=EXPORT_SYMBOL_GPL(vfio_pci_core_fill_phys_vec);\ndrivers/vfio/pci/vfio_pci_dmabuf.c-171-\ndrivers/vfio/pci/vfio_pci_dmabuf.c:172:int vfio_pci_core_get_dmabuf_phys(struct vfio_pci_core_device *vdev,\ndrivers/vfio/pci/vfio_pci_dmabuf.c-173-\t\t\t\t  struct p2pdma_provider **provider,\n--\ndrivers/vfio/pci/vfio_pci_dmabuf.c-189-}\ndrivers/vfio/pci/vfio_pci_dmabuf.c:190:EXPORT_SYMBOL_GPL(vfio_pci_core_get_dmabuf_phys);\ndrivers/vfio/pci/vfio_pci_dmabuf.c-191-\n"
}

49/2 2026/11/08 03:26 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 92071
							output: 36
							thoughts: 41
						

Thoughts:
Okay, here's my take on those thoughts, tailored for an expert audience and presented in the first person:

**Investigating vfio_pci and DMA Buffer Physical Address Retrieval**

Right, so `vfio_pci_core_get_dmabuf_phys`... that's a *vfio_pci* function, specifically. My initial thought is to immediately zoom in on its call sites. Anytime I see a function like this, especially one dealing with DMA buffers and physical addresses within the vfio_pci context, my first port of call is to understand where it's being used. The devil is always in the details with these hardware virtualization interactions, and understanding the surrounding code is key to any deeper understanding. I need to trace the data flow and the assumptions it makes. I want to see what triggers it, what it's trying to achieve, and what other components are relying on the value it returns. In short, who's calling `get_dmabuf_phys` and under what conditions? That's where the real story lies.



50/2 2026/11/08 03:26 tool grepper
0m Args:
{
  "Expression": "get_dmabuf_phys",
  "PathPrefixes": [
    "drivers/vfio/pci/"
  ]
}

Results:
{
  "Output": "drivers/vfio/pci/nvgrace-gpu/main.c=998=nvgrace_gpu_write(struct vfio_device *core_vdev,\n--\ndrivers/vfio/pci/nvgrace-gpu/main.c-1021-\ndrivers/vfio/pci/nvgrace-gpu/main.c:1022:static int nvgrace_get_dmabuf_phys(struct vfio_pci_core_device *core_vdev,\ndrivers/vfio/pci/nvgrace-gpu/main.c-1023-\t\t\t\t   struct p2pdma_provider **provider,\n--\ndrivers/vfio/pci/nvgrace-gpu/main.c-1057-\ndrivers/vfio/pci/nvgrace-gpu/main.c:1058:\treturn vfio_pci_core_get_dmabuf_phys(core_vdev, provider, region_index,\ndrivers/vfio/pci/nvgrace-gpu/main.c-1059-\t\t\t\t\t     phys_vec, dma_ranges, nr_ranges);\n--\ndrivers/vfio/pci/nvgrace-gpu/main.c=1062=static const struct vfio_pci_device_ops nvgrace_gpu_pci_dev_ops = {\ndrivers/vfio/pci/nvgrace-gpu/main.c:1063:\t.get_dmabuf_phys = nvgrace_get_dmabuf_phys,\ndrivers/vfio/pci/nvgrace-gpu/main.c-1064-};\n--\ndrivers/vfio/pci/nvgrace-gpu/main.c=1102=static const struct vfio_pci_device_ops nvgrace_gpu_pci_dev_core_ops = {\ndrivers/vfio/pci/nvgrace-gpu/main.c:1103:\t.get_dmabuf_phys = vfio_pci_core_get_dmabuf_phys,\ndrivers/vfio/pci/nvgrace-gpu/main.c-1104-};\n--\ndrivers/vfio/pci/vfio_pci.c=172=static const struct vfio_pci_device_ops vfio_pci_dev_ops = {\ndrivers/vfio/pci/vfio_pci.c:173:\t.get_dmabuf_phys = vfio_pci_core_get_dmabuf_phys,\ndrivers/vfio/pci/vfio_pci.c-174-};\n--\ndrivers/vfio/pci/vfio_pci_dmabuf.c=170=EXPORT_SYMBOL_GPL(vfio_pci_core_fill_phys_vec);\ndrivers/vfio/pci/vfio_pci_dmabuf.c-171-\ndrivers/vfio/pci/vfio_pci_dmabuf.c:172:int vfio_pci_core_get_dmabuf_phys(struct vfio_pci_core_device *vdev,\ndrivers/vfio/pci/vfio_pci_dmabuf.c-173-\t\t\t\t  struct p2pdma_provider **provider,\n--\ndrivers/vfio/pci/vfio_pci_dmabuf.c-189-}\ndrivers/vfio/pci/vfio_pci_dmabuf.c:190:EXPORT_SYMBOL_GPL(vfio_pci_core_get_dmabuf_phys);\ndrivers/vfio/pci/vfio_pci_dmabuf.c-191-\n--\ndrivers/vfio/pci/vfio_pci_dmabuf.c=221=int vfio_pci_core_feature_dma_buf(struct vfio_pci_core_device *vdev, u32 flags,\n--\ndrivers/vfio/pci/vfio_pci_dmabuf.c-231-\ndrivers/vfio/pci/vfio_pci_dmabuf.c:232:\tif (!vdev-\u003epci_ops || !vdev-\u003epci_ops-\u003eget_dmabuf_phys)\ndrivers/vfio/pci/vfio_pci_dmabuf.c-233-\t\treturn -EOPNOTSUPP;\n--\ndrivers/vfio/pci/vfio_pci_dmabuf.c-276-\tpriv-\u003esize = length;\ndrivers/vfio/pci/vfio_pci_dmabuf.c:277:\tret = vdev-\u003epci_ops-\u003eget_dmabuf_phys(vdev, \u0026priv-\u003eprovider,\ndrivers/vfio/pci/vfio_pci_dmabuf.c-278-\t\t\t\t\t     get_dma_buf.region_index,\n"
}

51/2 2026/11/08 03:26 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 93578
							output: 22
							thoughts: 988
						

Thoughts:
**Deep Dive into VFIO DMA-BUF and PCI P2PDMA Interactions**

Okay, so I'm focusing on `vfio_pci_core_feature_dma_buf` here. This is a standard VFIO feature, `VFIO_DEVICE_FEATURE_DMA_BUF`. When userspace calls that `VFIO_DEVICE_FEATURE` ioctl with `VFIO_DEVICE_FEATURE_DMA_BUF`, it gets a dmabuf file descriptor. That's the setup.

The interesting part is *what happens next*. Another device maps or imports this dmabuf and calls `dma_buf_map_attachment`. That kicks off `dma_buf_phys_vec_to_sgt`, which then hits `pci_p2pdma_map_type(provider, attach->dev)`. Bingo! This is where the PCI peer-to-peer DMA comes into play. And from `pci_p2pdma_map_type`, we're getting into `pci_p2pdma_map_type_tlp`, which eventually calls `calc_map_type_and_dist`. This is the core logic.

Now, let's zoom out and consider the bigger picture.

First, is PCI P2PDMA core code actually in the kernel? The answer is yes. It's in `drivers/pci/p2pdma.c`, and it's part of the core PCI subsystem, confirmed by `CONFIG_PCI_P2PDMA`.

Second, does this patch modify executable code that is reachable? Yes, indeed, `drivers/pci/p2pdma.c`, `drivers/pci/pci.c`, and `drivers/pci/quirks.c` are affected. Time for a close look at the code changes.

Let's dissect what's happened in the `drivers/pci/p2pdma.c` file: `pci_bridge_has_acs_redir` is *gone*. That's been replaced with a significant number of new functions dealing with ACS (Access Control Services) redirection! We're talking about everything from quirks (`pci_acs_p2pdma_quirk`, `pci_acs_p2pdma_quirk_redirect`), request and completion handling, state management, path logging, and the core mapping functions (`calc_map_type_and_dist`, `pci_p2pdma_map_type_tlp`, `pci_p2pdma_map_type`) and a lot more! This is a major structural change in ACS handling.

Now, shifting gears to `drivers/pci/pci.c`, it looks like `pci_acs_flags_enabled` has been modified, including a check for `pci_read_config_word` failure, `PCI_POSSIBLE_ERROR(ctrl)` and it's been made non-static which means it can be referenced outside of this .c file. This means the scope of how this functionality is used is increased. This is a crucial function, as it's called by `pci_acs_enabled`, which in turn is called during IOMMU group setup and also during the normal PCI device configuration (`pci_acs_path_enabled`) for *every* PCI device in the system! That means any device that has ACS support.

Hang on. I'm going to check the callers of `pci_acs_path_enabled` again. That is a critical code path. This could have a lot of ramifications for the whole system.



52/2 2026/11/08 03:26 tool grepper
0m Args:
{
  "Expression": "pci_acs_path_enabled"
}

Results:
{
  "Output": "drivers/iommu/iommu.c=1623=struct iommu_group *pci_device_group(struct device *dev)\n--\ndrivers/iommu/iommu.c-1654-\ndrivers/iommu/iommu.c:1655:\t\tif (pci_acs_path_enabled(bus-\u003eself, NULL, REQ_ACS_FLAGS))\ndrivers/iommu/iommu.c-1656-\t\t\tbreak;\n--\ndrivers/pci/ats.c=449=int pci_enable_pasid(struct pci_dev *pdev, int features)\n--\ndrivers/pci/ats.c-472-\ndrivers/pci/ats.c:473:\tif (!pci_acs_path_enabled(pdev, NULL, PCI_ACS_RR | PCI_ACS_UF))\ndrivers/pci/ats.c-474-\t\treturn -EINVAL;\n--\ndrivers/pci/pci.c=3654=bool pci_acs_enabled(struct pci_dev *pdev, u16 acs_flags)\n--\ndrivers/pci/pci.c-3718-/**\ndrivers/pci/pci.c:3719: * pci_acs_path_enabled - test ACS flags from start to end in a hierarchy\ndrivers/pci/pci.c-3720- * @start: starting downstream device\n--\ndrivers/pci/pci.c-3726- */\ndrivers/pci/pci.c:3727:bool pci_acs_path_enabled(struct pci_dev *start,\ndrivers/pci/pci.c-3728-\t\t\t  struct pci_dev *end, u16 acs_flags)\n--\ninclude/linux/pci.h=2757=bool pci_acs_enabled(struct pci_dev *pdev, u16 acs_flags);\ninclude/linux/pci.h:2758:bool pci_acs_path_enabled(struct pci_dev *start,\ninclude/linux/pci.h-2759-\t\t\t  struct pci_dev *end, u16 acs_flags);\n"
}

53/2 2026/11/08 03:26 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 95927
							output: 33
							thoughts: 1903
						

Thoughts:
**Analysis of Code Reachability for Fuzzing**

Okay, so the initial call stack shows `pci_device_group` calling `pci_acs_path_enabled`, which then calls `pci_acs_enabled`, and that in turn calls `pci_acs_flags_enabled`.  `pci_enable_pasid` also calls `pci_acs_path_enabled`. There's also a modification to `pci_quirk_intel_spt_pch_acs`.  There's a KUnit test in `drivers/pci/pci_acs_test.c` under `CONFIG_PCI_ACS_KUNIT_TEST`, but the core changes seem to be in `drivers/pci/p2pdma.c`, `drivers/pci/pci.c`, and `drivers/pci/quirks.c`. This needs a methodical check.

Given the criteria: I need to determine if this modified code is reachable in a standard virtualized environment (QEMU). No blind trust in "no functional change" claims, and any new or modified assertions in reachable code *must* be fuzzed. Conversely, I need to identify if the code falls under the "negative criteria" - non-kernel changes, unreachable hardware, or unreachable execution paths.

Let's break it down by file, starting with `drivers/pci/pci.c`. The function `pci_acs_flags_enabled` immediately grabs my attention. Examining the code, it's clear this function resides within core PCI code which is executed during PCI bus probing and device grouping, specifically for IOMMU and any PCIe device with an ACS capability or root ports.  The key here is whether QEMU emulates those features. And, yes, QEMU, particularly the `q35` machine type, *does* model PCIe root ports (like `pcie-root-port` or `ioh3420`) that have ACS capabilities.  This means that during device enumeration/IOMMU grouping, `pci_acs_flags_enabled` is indeed executed. That's a strong signal for fuzzing.

Now, on to `drivers/pci/p2pdma.c` and its functions such as `calc_map_type_and_dist` and `pci_p2pdma_map_type`.  The question is: can these functions be called within QEMU? Specifically, can P2P DMA occur?

Here's the critical piece. Could a virtual device or a common device be using P2PDMA? NVMe CMB support is interesting - the QEMU `nvme` device *does* have CMB support via the `-device nvme,cmb_size_mb=64` option.  Syzkaller is typically running on QEMU. If syzkaller is running on QEMU, it would typically attach a drive as a virtual block device and then configure `nvme`. However, syzkaller probably isn't using `cmb_size_mb`.

However, `nvmet` (NVMe target) is a software target! This is where things get interesting.  Can `nvmet` be configured over loopback? The answer is YES! `nvme-loop` connects `nvme` host to an `nvmet` (NVMe target) entirely in software, *without* the need for any hardware! The `nvmet` target can be created via configfs (`/sys/kernel/config/nvmet/...`).

Userspace creates a port with the "loop" transport and configures namespaces.  In `drivers/nvme/target/configfs.c`, `nvmet_ns_p2pmem_store` is an attribute in configfs (`/sys/kernel/config/nvmet/subsystems/<subsys>/namespaces/<ns>/p2pmem`). Writing to this attribute calls `pci_p2pdma_enable_store(page, &p2p_dev, &use_p2pmem)`.  Enabling the namespace calls `nvmet_p2pmem_ns_enable(ns)`.

Aha! Does `nvmet_p2pmem_ns_enable` then call `pci_p2pmem_find`? Looking at line 523 in `drivers/nvme/target/core.c`, I see a crucial line:  `if (ns->p2p_dev) { ret = pci_p2pdma_distance(ns->p2p_dev, nvmet_ns_dev(ns), true);`. And the target dev is `nvmet_ns_dev(ns)`. So, `pci_p2pdma_distance


54/2 2026/11/08 03:27 tool grepper
0m Args:
{
  "Expression": "nvmet_ns_dev",
  "PathPrefixes": [
    "drivers/nvme/target"
  ]
}

Results:
{
  "Output": "drivers/nvme/target/configfs.c=528=CONFIGFS_ATTR(nvmet_, addr_tsas);\n--\ndrivers/nvme/target/configfs.c-532- */\ndrivers/nvme/target/configfs.c:533:static ssize_t nvmet_ns_device_path_show(struct config_item *item, char *page)\ndrivers/nvme/target/configfs.c-534-{\n--\ndrivers/nvme/target/configfs.c-537-\ndrivers/nvme/target/configfs.c:538:static ssize_t nvmet_ns_device_path_store(struct config_item *item,\ndrivers/nvme/target/configfs.c-539-\t\tconst char *page, size_t count)\n--\ndrivers/nvme/target/configfs.c=614=CONFIGFS_ATTR(nvmet_ns_, p2pmem);\n--\ndrivers/nvme/target/configfs.c-616-\ndrivers/nvme/target/configfs.c:617:static ssize_t nvmet_ns_device_uuid_show(struct config_item *item, char *page)\ndrivers/nvme/target/configfs.c-618-{\n--\ndrivers/nvme/target/configfs.c-621-\ndrivers/nvme/target/configfs.c:622:static ssize_t nvmet_ns_device_uuid_store(struct config_item *item,\ndrivers/nvme/target/configfs.c-623-\t\t\t\t\t  const char *page, size_t count)\n--\ndrivers/nvme/target/configfs.c=643=CONFIGFS_ATTR(nvmet_ns_, device_uuid);\ndrivers/nvme/target/configfs.c-644-\ndrivers/nvme/target/configfs.c:645:static ssize_t nvmet_ns_device_nguid_show(struct config_item *item, char *page)\ndrivers/nvme/target/configfs.c-646-{\n--\ndrivers/nvme/target/configfs.c-649-\ndrivers/nvme/target/configfs.c:650:static ssize_t nvmet_ns_device_nguid_store(struct config_item *item,\ndrivers/nvme/target/configfs.c-651-\t\tconst char *page, size_t count)\n--\ndrivers/nvme/target/core.c=481=void nvmet_put_namespace(struct nvmet_ns *ns)\n--\ndrivers/nvme/target/core.c-485-\ndrivers/nvme/target/core.c:486:static void nvmet_ns_dev_disable(struct nvmet_ns *ns)\ndrivers/nvme/target/core.c-487-{\n--\ndrivers/nvme/target/core.c=492=static int nvmet_p2pmem_ns_enable(struct nvmet_ns *ns)\n--\ndrivers/nvme/target/core.c-511-\tif (ns-\u003ep2p_dev) {\ndrivers/nvme/target/core.c:512:\t\tret = pci_p2pdma_distance(ns-\u003ep2p_dev, nvmet_ns_dev(ns), true);\ndrivers/nvme/target/core.c-513-\t\tif (ret \u003c 0)\n--\ndrivers/nvme/target/core.c-522-\ndrivers/nvme/target/core.c:523:\t\tp2p_dev = pci_p2pmem_find(nvmet_ns_dev(ns));\ndrivers/nvme/target/core.c-524-\t\tif (!p2p_dev) {\n--\ndrivers/nvme/target/core.c=536=static void nvmet_p2pmem_ns_add_p2p(struct nvmet_ctrl *ctrl,\n--\ndrivers/nvme/target/core.c-555-\t\tclients[0] = ctrl-\u003ep2p_client;\ndrivers/nvme/target/core.c:556:\t\tclients[1] = nvmet_ns_dev(ns);\ndrivers/nvme/target/core.c-557-\n--\ndrivers/nvme/target/core.c=586=int nvmet_ns_enable(struct nvmet_ns *ns)\n--\ndrivers/nvme/target/core.c-646-out_dev_disable:\ndrivers/nvme/target/core.c:647:\tnvmet_ns_dev_disable(ns);\ndrivers/nvme/target/core.c-648-\tgoto out_unlock;\n--\ndrivers/nvme/target/core.c=651=void nvmet_ns_disable(struct nvmet_ns *ns)\n--\ndrivers/nvme/target/core.c-686-\tnvmet_ns_changed(subsys, ns-\u003ensid);\ndrivers/nvme/target/core.c:687:\tnvmet_ns_dev_disable(ns);\ndrivers/nvme/target/core.c-688-\tns-\u003eenabled = false;\n--\ndrivers/nvme/target/nvmet.h=138=static inline struct nvmet_ns *to_nvmet_ns(struct config_item *item)\n--\ndrivers/nvme/target/nvmet.h-142-\ndrivers/nvme/target/nvmet.h:143:static inline struct device *nvmet_ns_dev(struct nvmet_ns *ns)\ndrivers/nvme/target/nvmet.h-144-{\n"
}

55/2 2026/11/08 03:27 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 100289
							output: 39
							thoughts: 41
						

Thoughts:
Okay, let's dive into this. Here's how I'd approach this task, as if these were my internal thoughts:

**Dissecting the NVMe Namespace Device Retrieval**

Alright, I need to understand what `nvmet_ns_dev(ns)` actually does. Given my experience, I'm going to quickly look at the likely code definition of this function within the kernel. The goal is to see what the returned data structure is, because the context implies that this is critical. I'm going to navigate to `drivers/nvme/target/nvmet.h` and target around line 143. That's a reasonable place to start, as function definitions are often close to the data structures they return, or at least to related structs. I expect to be able to gather what I need from this area of the code.



56/2 2026/11/08 03:27 tool read-file
0m Args:
{
  "File": "drivers/nvme/target/nvmet.h",
  "FirstLine": 140,
  "LineCount": 20
}

Results:
{
  "Contents": " 140:\t\treturn container_of(to_config_group(item), struct nvmet_ns, group);\n 141:\t}\n 142:\t\n 143:\tstatic inline struct device *nvmet_ns_dev(struct nvmet_ns *ns)\n 144:\t{\n 145:\t\treturn ns-\u003ebdev ? disk_to_dev(ns-\u003ebdev-\u003ebd_disk) : NULL;\n 146:\t}\n 147:\t\n 148:\tstruct nvmet_cq {\n 149:\t\tstruct nvmet_ctrl\t*ctrl;\n 150:\t\tu16\t\t\tqid;\n 151:\t\tu16\t\t\tsize;\n 152:\t\trefcount_t\t\tref;\n 153:\t};\n 154:\t\n 155:\tstruct nvmet_sq {\n 156:\t\tstruct nvmet_ctrl\t*ctrl;\n 157:\t\tstruct percpu_ref\tref;\n 158:\t\tstruct nvmet_cq\t\t*cq;\n 159:\t\tu16\t\t\tqid;\n"
}

57/2 2026/11/08 03:27 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 100844
							output: 25
							thoughts: 165
						

Thoughts:
**Investigating NVMe Peer-to-Peer DMA Support**

Okay, so `nvmet_ns_dev(ns)` just hands me the block device through `disk_to_dev(ns->bdev->bd_disk)`. Nothing unexpected there. But in `nvmet_p2pmem_ns_enable`, there's this check: `blk_queue_pci_p2pdma(ns->bdev->bd_disk->queue)`. If that returns false, we get an error about P2P DMA not being supported.

Hold on a second... which drivers *actually* have that capability enabled? I need to figure out what sets `blk_queue_pci_p2pdma` in the first place, or, if nothing sets it, where it is tested to decide on the path forward. Let me find where that function is used and more importantly, set, or the logic surrounding the function's determination. Time to dig into the code and see what I can find.



58/2 2026/11/08 03:27 tool grepper
0m Args:
{
  "Expression": "blk_queue_pci_p2pdma"
}

Results:
{
  "Output": "block/bio-integrity.c=368=int bio_integrity_map_user(struct bio *bio, struct iov_iter *iter)\n--\nblock/bio-integrity.c-396-\nblock/bio-integrity.c:397:\tif (blk_queue_pci_p2pdma(q))\nblock/bio-integrity.c-398-\t\textraction_flags |= ITER_ALLOW_P2PDMA;\n--\nblock/bio.c=1343=int bio_iov_iter_get_pages(struct bio *bio, struct iov_iter *iter,\n--\nblock/bio.c-1366-\t\tbio_set_flag(bio, BIO_PAGE_PINNED);\nblock/bio.c:1367:\tif (bio-\u003ebi_bdev \u0026\u0026 blk_queue_pci_p2pdma(bio-\u003ebi_bdev-\u003ebd_disk-\u003equeue))\nblock/bio.c-1368-\t\tflags |= ITER_ALLOW_P2PDMA;\n--\ndrivers/nvme/target/core.c=492=static int nvmet_p2pmem_ns_enable(struct nvmet_ns *ns)\n--\ndrivers/nvme/target/core.c-504-\ndrivers/nvme/target/core.c:505:\tif (!blk_queue_pci_p2pdma(ns-\u003ebdev-\u003ebd_disk-\u003equeue)) {\ndrivers/nvme/target/core.c-506-\t\tpr_err(\"peer-to-peer DMA is not supported by the driver of %s\\n\",\n--\ninclude/linux/blkdev.h=691=void blk_queue_flag_clear(unsigned int flag, struct request_queue *q);\n--\ninclude/linux/blkdev.h-702-#define blk_queue_dax(q)\t((q)-\u003elimits.features \u0026 BLK_FEAT_DAX)\ninclude/linux/blkdev.h:703:#define blk_queue_pci_p2pdma(q)\t((q)-\u003elimits.features \u0026 BLK_FEAT_PCI_P2PDMA)\ninclude/linux/blkdev.h-704-#ifdef CONFIG_BLK_RQ_ALLOC_TIME\n"
}

59/2 2026/11/08 03:28 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 101805
							output: 25
							thoughts: 20
						

Thoughts:
Okay, here's my interpretation of that thought process, tailored for an expert audience, and written in the first person:

**Investigating the `BLK_FEAT_PCI_P2PDMA` Configuration**

Right, let's dive into this. My initial thought is to figure out what's setting that `BLK_FEAT_PCI_P2PDMA` flag. This screams a potential point-to-point DMA capability within the PCI subsystem, and naturally, I want to trace the dependencies. I need to understand which driver or subsystem is enabling it, and more importantly, why. Is it a specific device type? A particular BIOS setting? Perhaps a kernel configuration option I hadn't noticed before? Knowing the origin is crucial for understanding the overall data path and performance implications. I'll need to start by grepping the kernel sources, configuration files, and maybe even the device tree. I'm looking for the defining moment, the code path that ultimately sets that bit. The goal is to ascertain the conditions and rationale for its activation, as this has a huge impact on system optimization.



60/2 2026/11/08 03:28 tool grepper
0m Args:
{
  "Expression": "BLK_FEAT_PCI_P2PDMA"
}

Results:
{
  "Output": "block/blk-settings.c=788=int blk_stack_limits(struct queue_limits *t, struct queue_limits *b,\n--\nblock/blk-settings.c-805-\t\tt-\u003efeatures \u0026= ~BLK_FEAT_POLL;\nblock/blk-settings.c:806:\tif (!(b-\u003efeatures \u0026 BLK_FEAT_PCI_P2PDMA))\nblock/blk-settings.c:807:\t\tt-\u003efeatures \u0026= ~BLK_FEAT_PCI_P2PDMA;\nblock/blk-settings.c-808-\n--\ndrivers/md/raid0.c=388=static int raid0_set_limits(struct mddev *mddev)\n--\ndrivers/md/raid0.c-402-\tlim.features |= BLK_FEAT_ATOMIC_WRITES;\ndrivers/md/raid0.c:403:\tlim.features |= BLK_FEAT_PCI_P2PDMA;\ndrivers/md/raid0.c-404-\terr = mddev_stack_rdev_limits(mddev, \u0026lim, MDDEV_STACK_INTEGRITY);\n--\ndrivers/md/raid1.c=3137=static int raid1_set_limits(struct mddev *mddev)\n--\ndrivers/md/raid1.c-3147-\tlim.features |= BLK_FEAT_ATOMIC_WRITES;\ndrivers/md/raid1.c:3148:\tlim.features |= BLK_FEAT_PCI_P2PDMA;\ndrivers/md/raid1.c-3149-\terr = mddev_stack_rdev_limits(mddev, \u0026lim, MDDEV_STACK_INTEGRITY);\n--\ndrivers/md/raid10.c=3887=static int raid10_set_queue_limits(struct mddev *mddev)\n--\ndrivers/md/raid10.c-3900-\tlim.features |= BLK_FEAT_ATOMIC_WRITES;\ndrivers/md/raid10.c:3901:\tlim.features |= BLK_FEAT_PCI_P2PDMA;\ndrivers/md/raid10.c-3902-\terr = mddev_stack_rdev_limits(mddev, \u0026lim, MDDEV_STACK_INTEGRITY);\n--\ndrivers/nvme/host/core.c=4273=static void nvme_alloc_ns(struct nvme_ctrl *ctrl, struct nvme_ns_info *info)\n--\ndrivers/nvme/host/core.c-4288-\t    ctrl-\u003eops-\u003esupports_pci_p2pdma(ctrl))\ndrivers/nvme/host/core.c:4289:\t\tlim.features |= BLK_FEAT_PCI_P2PDMA;\ndrivers/nvme/host/core.c-4290-\n--\ndrivers/nvme/host/multipath.c=765=int nvme_mpath_alloc_disk(struct nvme_ctrl *ctrl, struct nvme_ns_head *head)\n--\ndrivers/nvme/host/multipath.c-795-\tlim.features |= BLK_FEAT_IO_STAT | BLK_FEAT_NOWAIT |\ndrivers/nvme/host/multipath.c:796:\t\tBLK_FEAT_POLL | BLK_FEAT_ATOMIC_WRITES | BLK_FEAT_PCI_P2PDMA;\ndrivers/nvme/host/multipath.c-797-\n--\ninclude/linux/blkdev.h=315=typedef unsigned int __bitwise blk_features_t;\n--\ninclude/linux/blkdev.h-350-/* supports PCI(e) p2p requests */\ninclude/linux/blkdev.h:351:#define BLK_FEAT_PCI_P2PDMA\t\t((__force blk_features_t)(1u \u003c\u003c 12))\ninclude/linux/blkdev.h-352-\n--\ninclude/linux/blkdev.h=691=void blk_queue_flag_clear(unsigned int flag, struct request_queue *q);\n--\ninclude/linux/blkdev.h-702-#define blk_queue_dax(q)\t((q)-\u003elimits.features \u0026 BLK_FEAT_DAX)\ninclude/linux/blkdev.h:703:#define blk_queue_pci_p2pdma(q)\t((q)-\u003elimits.features \u0026 BLK_FEAT_PCI_P2PDMA)\ninclude/linux/blkdev.h-704-#ifdef CONFIG_BLK_RQ_ALLOC_TIME\n"
}

61/2 2026/11/08 03:28 llm patch-evaluator
2m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 103230
							output: 26
							thoughts: 114
						

Thoughts:
**Investigating NVMe and PCI Peer-to-Peer DMA Support**

Okay, so `nvme_alloc_ns` is where this whole peer-to-peer DMA situation begins for NVMe devices. It looks like it's setting `BLK_FEAT_PCI_P2PDMA` if the controller supports it. That makes sense, a feature flag to indicate this capability. And since we are dealing with NVMe over PCI, I would expect some PCI specific support to come into play.

Specifically, `nvme_pci_supports_pci_p2pdma` looks like the PCI-specific function to determine this support. This function then calls `dma_pci_p2pdma_supported` which is the ultimate test. It's time to dig into what exactly `dma_pci_p2pdma_supported` does, as that's the core of whether this feature is enabled. I need to understand the underlying logic there, because, depending on the implementation details within `dma_pci_p2pdma_supported` this could be either very specific to the hardware, or just checking generic PCI configuration. That's what I will need to get a handle on!



62/2 2026/11/08 03:30 tool grepper
0m Args:
{
  "Expression": "dma_pci_p2pdma_supported"
}

Results:
{
  "Output": "drivers/accel/habanalabs/common/hldio.c=67=static int hl_dio_fd_register(struct hl_ctx *ctx, int fd, struct hl_dio_fd *f)\n--\ndrivers/accel/habanalabs/common/hldio.c-112-\tdisk_dev = disk_to_dev(gd);\ndrivers/accel/habanalabs/common/hldio.c:113:\tif (!dma_pci_p2pdma_supported(disk_dev)) {\ndrivers/accel/habanalabs/common/hldio.c-114-\t\tdev_err(hdev-\u003edev, \"device does not support PCI P2P DMA\\n\");\n--\ndrivers/nvme/host/pci.c=3773=static bool nvme_pci_supports_pci_p2pdma(struct nvme_ctrl *ctrl)\n--\ndrivers/nvme/host/pci.c-3776-\ndrivers/nvme/host/pci.c:3777:\treturn dma_pci_p2pdma_supported(dev-\u003edev);\ndrivers/nvme/host/pci.c-3778-}\n--\ninclude/linux/dma-mapping.h=203=bool dma_can_mmap(struct device *dev);\ninclude/linux/dma-mapping.h:204:bool dma_pci_p2pdma_supported(struct device *dev);\ninclude/linux/dma-mapping.h-205-int dma_set_mask(struct device *dev, u64 mask);\n--\ninclude/linux/dma-mapping.h=301=static inline bool dma_can_mmap(struct device *dev)\n--\ninclude/linux/dma-mapping.h-304-}\ninclude/linux/dma-mapping.h:305:static inline bool dma_pci_p2pdma_supported(struct device *dev)\ninclude/linux/dma-mapping.h-306-{\n--\ninclude/rdma/ib_verbs.h=4318=static inline bool ib_dma_pci_p2p_dma_supported(struct ib_device *dev)\n--\ninclude/rdma/ib_verbs.h-4322-\ninclude/rdma/ib_verbs.h:4323:\treturn dma_pci_p2pdma_supported(dev-\u003edma_device);\ninclude/rdma/ib_verbs.h-4324-}\n--\nkernel/dma/mapping.c=892=static int dma_supported(struct device *dev, u64 mask)\n--\nkernel/dma/mapping.c-914-\nkernel/dma/mapping.c:915:bool dma_pci_p2pdma_supported(struct device *dev)\nkernel/dma/mapping.c-916-{\n--\nkernel/dma/mapping.c-927-}\nkernel/dma/mapping.c:928:EXPORT_SYMBOL_GPL(dma_pci_p2pdma_supported);\nkernel/dma/mapping.c-929-\n"
}

63/2 2026/11/08 03:30 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 104426
							output: 36
							thoughts: 31
						

Thoughts:
Okay, let's dive into this. Here's my take on understanding `dma_pci_p2pdma_supported` in `kernel/dma/mapping.c`:

**Dissecting `dma_pci_p2pdma_supported`**

Alright, so I'm curious about how the kernel handles PCI peer-to-peer DMA. Time to check out the definition of `dma_pci_p2pdma_supported` in `kernel/dma/mapping.c`. From a quick mental scan, I'm expecting this function, or macro, to determine if the hardware and the current configuration support the crucial ability for Direct Memory Access to occur directly between PCI devices, without unnecessarily bouncing through system memory. This can be a huge performance boost, and it's essential for a lot of high-bandwidth I/O. I bet I can quickly determine what's checked here.



64/2 2026/11/08 03:31 tool read-file
0m Args:
{
  "File": "kernel/dma/mapping.c",
  "FirstLine": 914,
  "LineCount": 20
}

Results:
{
  "Contents": " 914:\t\n 915:\tbool dma_pci_p2pdma_supported(struct device *dev)\n 916:\t{\n 917:\t\tconst struct dma_map_ops *ops = get_dma_ops(dev);\n 918:\t\n 919:\t\t/*\n 920:\t\t * Note: dma_ops_bypass is not checked here because P2PDMA should\n 921:\t\t * not be used with dma mapping ops that do not have support even\n 922:\t\t * if the specific device is bypassing them.\n 923:\t\t */\n 924:\t\n 925:\t\t/* if ops is not set, dma direct and default IOMMU support P2PDMA */\n 926:\t\treturn !ops;\n 927:\t}\n 928:\tEXPORT_SYMBOL_GPL(dma_pci_p2pdma_supported);\n 929:\t\n 930:\tint dma_set_mask(struct device *dev, u64 mask)\n 931:\t{\n 932:\t\t/*\n 933:\t\t * Truncate the mask to the actually supported dma_addr_t width to\n"
}

65/2 2026/11/08 03:31 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 105013
							output: 37
							thoughts: 2836
						

Thoughts:
**Analysis of Potential Fuzzing Impact**

Okay, here's the breakdown of my thought process regarding this patch and its potential for fuzzing:

First, I see a connection: `dma_pci_p2pdma_supported(dev)` returning something, indicating potential P2PDMA support for NVMe controllers under certain conditions (like dma-direct and default iommu). But, I need to know if the NVMe controller has CMB and if QEMU enables it by default. If CMB isn't present or enabled, then `pci_p2pdma_add_resource` won't be called and `pci_has_p2pmem` will be false.

Then, there's the question of whether KUnit tests, which are involved with PCI ACS P2P routing and related logic, can be run by syzkaller. The answer is a clear "no." Syzkaller is for fuzzing, KUnit is for unit tests.

Now, I'm at the core of the matter: Does this patch fall under "reachable executable code" or "structurally unreachable hardware"? I have to carefully analyze.

*   `drivers/pci/p2pdma.c` is not vendor specific, it's core subsystem, so not "structurally unreachable hardware."

Section 3 of the fuzzing guidance is my guide. My initial assessment is that this patch touches "reachable executable code," particularly within core subsystems related to PCI. Key functions such as `pci_acs_enabled`, are used during boot and device setup. I also identify calls from `iommu.c` and `pci_device_group`, and `pci_acs_path_enabled`. That means these modifications are related to IOMMU groups, potentially altering how PCI devices are managed.

The change in `pci.c`, involves ACS register error handling and making `pci_acs_flags_enabled` `VISIBLE_IF_KUNIT`. The change in `quirks.c`, handles error handling in `pci_quirk_intel_spt_pch_acs`.

The biggest diff is in `p2pdma.c`. I have to figure out what triggers `calc_map_type_and_dist`. I've traced the calls to `calc_map_type_and_dist`, identifying various drivers like NVMe, GPU drivers (AMD/Intel), and DMA-BUF. It's connected to `kernel/dma/direct.c`. I need to figure out how `pci_p2pdma_state` is called in `kernel/dma/direct.c`.

**Conclusion:** This patch seems highly relevant for fuzzing, given the changes in core PCI code, its interaction with IOMMU groups, and its connection to drivers involved in DMA operations. It's likely to impact reachable execution paths in QEMU.



66/2 2026/11/08 03:31 tool grepper
0m Args:
{
  "Expression": "pci_p2pdma_",
  "PathPrefixes": [
    "kernel/dma/direct.c"
  ]
}

Results:
{
  "Output": "kernel/dma/direct.c=591=int dma_direct_map_sg(struct device *dev, struct scatterlist *sgl, int nents,\n--\nkernel/dma/direct.c-593-{\nkernel/dma/direct.c:594:\tstruct pci_p2pdma_map_state p2pdma_state = {};\nkernel/dma/direct.c-595-\tstruct scatterlist *sg;\n--\nkernel/dma/direct.c-599-\tfor_each_sg(sgl, sg, nents, i) {\nkernel/dma/direct.c:600:\t\tswitch (pci_p2pdma_state(\u0026p2pdma_state, dev, sg_page(sg))) {\nkernel/dma/direct.c-601-\t\tcase PCI_P2PDMA_MAP_THRU_HOST_BRIDGE:\n--\nkernel/dma/direct.c-617-\t\tcase PCI_P2PDMA_MAP_BUS_ADDR:\nkernel/dma/direct.c:618:\t\t\tsg-\u003edma_address = pci_p2pdma_bus_addr_map(\nkernel/dma/direct.c-619-\t\t\t\tp2pdma_state.mem, sg_phys(sg));\n"
}

67/2 2026/11/08 03:31 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 108835
							output: 41
							thoughts: 32
						

Thoughts:
Okay, let's dive into this. Here's my take on understanding `pci_p2pdma_state` in `drivers/pci/p2pdma.c`:

**Dissecting the `pci_p2pdma_state` in `drivers/pci/p2pdma.c`**

Alright, time to get my hands dirty and understand this `pci_p2pdma_state`. I need to figure out what it actually *does* in the grand scheme of the `p2pdma` subsystem. I'm going to start by reading the code within `drivers/pci/p2pdma.c` to see how it's defined and, more importantly, how it's used. I suspect this is where the core logic of point-to-point DMA within the PCI domain is defined. I'm going to pay close attention to the data structures involved, the functions that manipulate this state, and any locking mechanisms used to ensure concurrency safety. My experience tells me there's probably a lot of device context management here, likely handling the establishment and teardown of DMA connections between PCI devices. I will be looking out for how this state is used to handle DMA requests, manage resources, and perhaps implement some kind of error handling or fallback mechanisms. From my experience with PCI device drivers, I expect to see interactions with other kernel subsystems. I will also be keeping an eye out for how this is implemented in relation to the PCI Express protocol.



68/2 2026/11/08 03:31 tool grepper
0m Args:
{
  "Expression": "pci_p2pdma_state",
  "PathPrefixes": [
    "drivers/pci/p2pdma.c"
  ]
}

Results:
{
  "Output": "no matches"
}

69/2 2026/11/08 03:31 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 109239
							output: 24
							thoughts: 31
						

Thoughts:
Here's a summary of my immediate thought process:

**Hunting Down a Kernel Structure**

Okay, so I need to figure out where the `pci_p2pdma_state` structure is actually defined within the kernel. My first instinct, given my experience with kernel debugging, is to use `grep`. I'll run `grep` and see if I can find the definition. That should be the fastest way to get a solid answer.



70/2 2026/11/08 03:31 tool grepper
0m Args:
{
  "Expression": "pci_p2pdma_state\\("
}

Results:
{
  "Output": "block/blk-mq-dma.c=164=static bool blk_dma_map_iter_start(struct request *req, struct device *dma_dev,\n--\nblock/blk-mq-dma.c-180-\nblock/blk-mq-dma.c:181:\tswitch (pci_p2pdma_state(\u0026iter-\u003ep2pdma, dma_dev,\nblock/blk-mq-dma.c-182-\t\t\t\t phys_to_page(vec.paddr))) {\n--\ndrivers/iommu/dma-iommu.c=1413=int iommu_dma_map_sg(struct device *dev, struct scatterlist *sg, int nents,\n--\ndrivers/iommu/dma-iommu.c-1450-\ndrivers/iommu/dma-iommu.c:1451:\t\tswitch (pci_p2pdma_state(\u0026p2pdma_state, dev, sg_page(s))) {\ndrivers/iommu/dma-iommu.c-1452-\t\tcase PCI_P2PDMA_MAP_THRU_HOST_BRIDGE:\n--\ninclude/linux/pci-p2pdma.h=175=struct pci_p2pdma_map_state {\n--\ninclude/linux/pci-p2pdma.h-180-\ninclude/linux/pci-p2pdma.h:181:/* helper for pci_p2pdma_state(), do not use directly */\ninclude/linux/pci-p2pdma.h-182-void __pci_p2pdma_update_state(struct pci_p2pdma_map_state *state,\n--\ninclude/linux/pci-p2pdma.h=194=static inline enum pci_p2pdma_map_type\ninclude/linux/pci-p2pdma.h:195:pci_p2pdma_state(struct pci_p2pdma_map_state *state, struct device *dev,\ninclude/linux/pci-p2pdma.h-196-\t\tstruct page *page)\n--\nkernel/dma/direct.c=591=int dma_direct_map_sg(struct device *dev, struct scatterlist *sgl, int nents,\n--\nkernel/dma/direct.c-599-\tfor_each_sg(sgl, sg, nents, i) {\nkernel/dma/direct.c:600:\t\tswitch (pci_p2pdma_state(\u0026p2pdma_state, dev, sg_page(sg))) {\nkernel/dma/direct.c-601-\t\tcase PCI_P2PDMA_MAP_THRU_HOST_BRIDGE:\n--\nmm/hmm.c=916=dma_addr_t hmm_dma_map_pfn(struct device *dev, struct hmm_dma_map *map,\n--\nmm/hmm.c-954-\nmm/hmm.c:955:\tswitch (pci_p2pdma_state(p2pdma_state, dev, page)) {\nmm/hmm.c-956-\tcase PCI_P2PDMA_MAP_NONE:\n"
}

71/2 2026/11/08 03:31 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 110211
							output: 41
							thoughts: 37
						

Thoughts:
Here's a summary of my thought process:

**Diving into the PCI-P2PDMA Header**

Okay, let's take a look at the code. I need to understand how the PCI peer-to-peer DMA functionality is handled, so I'll start with the include file. Specifically, I need to understand the data structures and functions defined around the core mechanisms. I'm focusing on line 194 of `include/linux/pci-p2pdma.h`. To get the context, I'll read a block of lines surrounding that point. Let's examine lines 175 through 215. This should give me a good overview of the relevant definitions and perhaps some critical inline function declarations or macro definitions that are key to understanding the overall architecture. I'll be looking for things like structures used to manage DMA transactions, function prototypes for setting up and tearing down the P2P links, and any synchronization primitives employed to ensure data integrity and avoid race conditions. I'm particularly interested in how the driver interacts with the hardware, so I'll be paying close attention to any register definitions or access macros.



72/2 2026/11/08 03:31 tool read-file
0m Args:
{
  "File": "include/linux/pci-p2pdma.h",
  "FirstLine": 175,
  "LineCount": 40
}

Results:
{
  "Contents": " 175:\tstruct pci_p2pdma_map_state {\n 176:\t\tstruct p2pdma_provider *mem;\n 177:\t\tenum pci_p2pdma_map_type map;\n 178:\t};\n 179:\t\n 180:\t\n 181:\t/* helper for pci_p2pdma_state(), do not use directly */\n 182:\tvoid __pci_p2pdma_update_state(struct pci_p2pdma_map_state *state,\n 183:\t\t\tstruct device *dev, struct page *page);\n 184:\t\n 185:\t/**\n 186:\t * pci_p2pdma_state - check the P2P transfer state of a page\n 187:\t * @state:\tP2P state structure\n 188:\t * @dev:\tdevice to transfer to/from\n 189:\t * @page:\tpage to map\n 190:\t *\n 191:\t * Check if @page is a PCI P2PDMA page, and if yes of what kind.  Returns the\n 192:\t * map type, and updates @state with all information needed for a P2P transfer.\n 193:\t */\n 194:\tstatic inline enum pci_p2pdma_map_type\n 195:\tpci_p2pdma_state(struct pci_p2pdma_map_state *state, struct device *dev,\n 196:\t\t\tstruct page *page)\n 197:\t{\n 198:\t\tif (IS_ENABLED(CONFIG_PCI_P2PDMA) \u0026\u0026 is_pci_p2pdma_page(page)) {\n 199:\t\t\t__pci_p2pdma_update_state(state, dev, page);\n 200:\t\t\treturn state-\u003emap;\n 201:\t\t}\n 202:\t\treturn PCI_P2PDMA_MAP_NONE;\n 203:\t}\n 204:\t\n 205:\t/**\n 206:\t * pci_p2pdma_bus_addr_map - Translate a physical address to a bus address\n 207:\t *\t\t\t     for a PCI_P2PDMA_MAP_BUS_ADDR transfer.\n 208:\t * @provider:\tP2P provider structure\n 209:\t * @paddr:\tphysical address to map\n 210:\t *\n 211:\t * Map a physically contiguous PCI_P2PDMA_MAP_BUS_ADDR transfer.\n 212:\t */\n 213:\tstatic inline dma_addr_t\n 214:\tpci_p2pdma_bus_addr_map(struct p2pdma_provider *provider, phys_addr_t paddr)\n"
}

73/2 2026/11/08 03:31 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 111259
							output: 47
							thoughts: 242
						

Thoughts:
**My Analysis of PCI P2P DMA Page Detection**

Okay, so I'm digging into how the system determines if a page is eligible for PCI Peer-to-Peer DMA. The core function here seems to be `pci_p2pdma_state`, and it's calling `is_pci_p2pdma_page(page)`. Straightforward. Now, when does `is_pci_p2pdma_page` return true? Let's see... it checks two things: `is_zone_device_page(page)` *and* `page->pgmap->type == MEMORY_DEVICE_PCI_P2PDMA`. Right, that makes sense. So, we're looking for a page associated with a device zone, and it has to be specifically flagged as PCI P2P DMA capable.

Now, the crucial question is, how does a page *get* that `MEMORY_DEVICE_PCI_P2PDMA` flag? That's where `pci_p2pdma_add_resource` comes in. It's the mechanism for tagging a page as PCI P2P DMA capable. And who calls *that*? I see two primary callers: `nvme_map_cmb` and `hl_p2p_region_init`. That's important. NVMe controllers, High-Level Peer-to-Peer region initialization... those are obvious use cases.

Hold on a second, am I missing something? Are there any other potential paths where `pci_p2pdma_add_resource` might get called? We have to be thorough here. Aha! What about VFIO dmabuf? My Spidey-sense is tingling. Let's dig into that... VFIO dmabuf has its own mechanism. It looks like it's in `vfio_pci_core_feature_dma_buf`. Okay, time to crack open `drivers/vfio/pci/vfio_pci_dmabuf.c` and confirm my hunch. Need to see how that interacts with the `pci_p2pdma_add_resource` flow. We'll get to the bottom of this.



74/2 2026/11/08 03:32 tool read-file
0m Args:
{
  "File": "drivers/vfio/pci/vfio_pci_dmabuf.c",
  "FirstLine": 220,
  "LineCount": 70
}

Results:
{
  "Contents": " 220:\t\n 221:\tint vfio_pci_core_feature_dma_buf(struct vfio_pci_core_device *vdev, u32 flags,\n 222:\t\t\t\t\t  struct vfio_device_feature_dma_buf __user *arg,\n 223:\t\t\t\t\t  size_t argsz)\n 224:\t{\n 225:\t\tstruct vfio_device_feature_dma_buf get_dma_buf = {};\n 226:\t\tstruct vfio_region_dma_range *dma_ranges;\n 227:\t\tDEFINE_DMA_BUF_EXPORT_INFO(exp_info);\n 228:\t\tstruct vfio_pci_dma_buf *priv;\n 229:\t\tsize_t length;\n 230:\t\tint ret;\n 231:\t\n 232:\t\tif (!vdev-\u003epci_ops || !vdev-\u003epci_ops-\u003eget_dmabuf_phys)\n 233:\t\t\treturn -EOPNOTSUPP;\n 234:\t\n 235:\t\tret = vfio_check_feature(flags, argsz, VFIO_DEVICE_FEATURE_GET,\n 236:\t\t\t\t\t sizeof(get_dma_buf));\n 237:\t\tif (ret != 1)\n 238:\t\t\treturn ret;\n 239:\t\n 240:\t\tif (copy_from_user(\u0026get_dma_buf, arg, sizeof(get_dma_buf)))\n 241:\t\t\treturn -EFAULT;\n 242:\t\n 243:\t\tif (!get_dma_buf.nr_ranges || get_dma_buf.flags)\n 244:\t\t\treturn -EINVAL;\n 245:\t\n 246:\t\t/*\n 247:\t\t * For PCI the region_index is the BAR number like everything\n 248:\t\t * else.  Check that PCI resources have been claimed for it.\n 249:\t\t */\n 250:\t\tif (get_dma_buf.region_index \u003e= VFIO_PCI_ROM_REGION_INDEX ||\n 251:\t\t    IS_ERR(vfio_pci_core_get_iomap(vdev, get_dma_buf.region_index)))\n 252:\t\t\treturn -ENODEV;\n 253:\t\n 254:\t\tdma_ranges = memdup_array_user(\u0026arg-\u003edma_ranges, get_dma_buf.nr_ranges,\n 255:\t\t\t\t\t       sizeof(*dma_ranges));\n 256:\t\tif (IS_ERR(dma_ranges))\n 257:\t\t\treturn PTR_ERR(dma_ranges);\n 258:\t\n 259:\t\tret = validate_dmabuf_input(\u0026get_dma_buf, dma_ranges, \u0026length);\n 260:\t\tif (ret)\n 261:\t\t\tgoto err_free_ranges;\n 262:\t\n 263:\t\tpriv = kzalloc_obj(*priv);\n 264:\t\tif (!priv) {\n 265:\t\t\tret = -ENOMEM;\n 266:\t\t\tgoto err_free_ranges;\n 267:\t\t}\n 268:\t\tpriv-\u003ephys_vec = kzalloc_objs(*priv-\u003ephys_vec, get_dma_buf.nr_ranges);\n 269:\t\tif (!priv-\u003ephys_vec) {\n 270:\t\t\tret = -ENOMEM;\n 271:\t\t\tgoto err_free_priv;\n 272:\t\t}\n 273:\t\n 274:\t\tpriv-\u003evdev = vdev;\n 275:\t\tpriv-\u003enr_ranges = get_dma_buf.nr_ranges;\n 276:\t\tpriv-\u003esize = length;\n 277:\t\tret = vdev-\u003epci_ops-\u003eget_dmabuf_phys(vdev, \u0026priv-\u003eprovider,\n 278:\t\t\t\t\t\t     get_dma_buf.region_index,\n 279:\t\t\t\t\t\t     priv-\u003ephys_vec, dma_ranges,\n 280:\t\t\t\t\t\t     priv-\u003enr_ranges);\n 281:\t\tif (ret)\n 282:\t\t\tgoto err_free_phys;\n 283:\t\n 284:\t\tkfree(dma_ranges);\n 285:\t\tdma_ranges = NULL;\n 286:\t\n 287:\t\tif (!vfio_device_try_get_registration(\u0026vdev-\u003evdev)) {\n 288:\t\t\tret = -ENODEV;\n 289:\t\t\tgoto err_free_phys;\n"
}

75/2 2026/11/08 03:32 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 113208
							output: 40
							thoughts: 607
						

Thoughts:
**My Analysis of vfio-pci DMA-BUF Export and Mapping**

Okay, here's what's running through my head as I dissect this. It's fascinating – this `vfio_pci_core_feature_dma_buf` function allows any PCI BAR on a vfio-pci bound device to be exposed as a dmabuf. Clever.

My train of thought is as follows:

1.  **Exporting the DMA-BUF:** I see that the `vdev->pci_ops->get_dmabuf_phys` callback is called, and this in turn triggers `vfio_pci_core_get_dmabuf_phys`. This is the core of the functionality.

2.  **The Provider:**  `vfio_pci_core_get_dmabuf_phys` then calls `pcim_p2pdma_provider(pdev, region_index)`. Wait a minute, I remember now, that `pcim_p2pdma_init(vdev->pdev)` was initialized during `vfio_pci_core_init_dev`.  So, that provider structure is already ready. That's a good way to structure it.

3.  **Mapping the DMA-BUF:** Now, when this dmabuf is actually *used* (mapped by another device or driver), `dma_buf_phys_vec_to_sgt` gets involved. This then calls `pci_p2pdma_map_type`, which ultimately leads to `pci_p2pdma_map_type_tlp`, which *finally* calls `calc_map_type_and_dist`. This is where the magic happens and where I need to focus my attention.

4.  **`calc_map_type_and_dist` Question:** I need to figure out how `calc_map_type_and_dist` works. My gut tells me that's the key to understanding how the DMA transfer is configured. What's the impact of `pci_p2pdma_distance_many` and `pci_p2pdma_distance`? Let's check them.

5.  **Finding Callers:** I need to understand where this is used within the kernel. My research into call locations has uncovered the following.

    *   In the NVMe target driver: `nvmet_p2pmem_ns_enable` and `nvmet_p2pmem_ns_add_p2p`.
    *   In the DMA-BUF mapping layer: `dma_buf_phys_vec_to_sgt`.
    *   In the NVMe host PCI driver: `nvme_map_data` which calls `pci_p2pdma_state`, and that calls `__pci_p2pdma_update_state`.

6.  **`__pci_p2pdma_update_state` Deep Dive:** So, I need to look closely at `__pci_p2pdma_update_state` in `drivers/pci/p2pdma.c` to fully understand the context. This will give me the clearest picture of how these calculations are made, and what it all *means* in practice. I need to see how these calculations are performed and how they affect the mapping, distance calculation and DMA transfer.



76/2 2026/11/08 03:32 tool read-file
0m Args:
{
  "File": "drivers/pci/p2pdma.c",
  "FirstLine": 1955,
  "LineCount": 25
}

Results:
{
  "Contents": "1955:\t\t\t\t\t\t     struct device *dev)\n1956:\t{\n1957:\t\treturn pci_p2pdma_map_type_tlp(provider, dev, 0);\n1958:\t}\n1959:\t\n1960:\tvoid __pci_p2pdma_update_state(struct pci_p2pdma_map_state *state,\n1961:\t\t\tstruct device *dev, struct page *page)\n1962:\t{\n1963:\t\tstruct pci_p2pdma_pagemap *p2p_pgmap = to_p2p_pgmap(page_pgmap(page));\n1964:\t\n1965:\t\tif (state-\u003emem == p2p_pgmap-\u003emem)\n1966:\t\t\treturn;\n1967:\t\n1968:\t\tstate-\u003emem = p2p_pgmap-\u003emem;\n1969:\t\tstate-\u003emap = pci_p2pdma_map_type(p2p_pgmap-\u003emem, dev);\n1970:\t}\n1971:\t\n1972:\t/**\n1973:\t * pci_p2pdma_enable_store - parse a configfs/sysfs attribute store\n1974:\t *\t\tto enable p2pdma\n1975:\t * @page: contents of the value to be stored\n1976:\t * @p2p_dev: returns the PCI device that was selected to be used\n1977:\t *\t\t(if one was specified in the stored value)\n1978:\t * @use_p2pdma: returns whether to enable p2pdma or not\n1979:\t *\n"
}

77/2 2026/11/08 03:32 llm patch-evaluator
1m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 115036
							output: 24
							thoughts: 9706
						

Thoughts:
**Triage Time: Peer-to-Peer DMA and ACS Routing in the Crosshairs**

Okay, here's the deal. I'm looking at this patch and my initial thought is, "Can syzkaller, our beloved fuzzer, actually reach the modified code?" The patch touches PCI peer-to-peer DMA and, specifically, ACS (Access Control Services) routing. My gut feeling is that this might be tricky to reach. Here's my thought process.

First, I see the calls to `__pci_p2pdma_update_state` which in turn calls `pci_p2pdma_map_type`. Then, I note `pci_p2pdma_enable_store` is exported and called by `nvmet_ns_p2pmem_store` in `configfs.c`. Syzkaller can mess around with configfs, so I immediately think, can syzkaller write to that `/p2pmem` attribute to trigger this?

If syzkaller writes "1" to that p2pmem attribute, `pci_p2pdma_enable_store` sets `ns->use_p2pmem = true`. Then, when the user enables the namespace, `nvmet_p2pmem_ns_enable` runs. This is where it gets interesting. I see calls to `pci_p2pdma_distance` and, more importantly, `pci_p2pmem_find`. 

`pci_p2pmem_find` calls `pci_p2pmem_find_many` which, in turn, iterates through PCI devices using `for_each_pci_dev` and checks `pci_has_p2pmem`.  If there are no such devices, it returns NULL and that's it!  

Now I'm asking myself, are there any PCI devices with the proper flags set to even reach `pci_p2pdma_distance_many` in a standard QEMU environment? I go back to section 1 and 2, of the triage document. Section 2 says "Structurally unreachable hardware" does *not* need fuzzing. And specifically, "Vendor-specific PCIe switches, SmartNICs, or GPU drivers... requiring physical ASIC/PCIe cards not emulated in standard QEMU".  This made me think of P2PDMA, a generic Linux kernel subsystem, not a vendor specific. So I moved on.

I re-read what was modified, specifically in `drivers/pci/pci.c`, I see a function, `pci_acs_flags_enabled`, was touched by the patch. I check if this is reachable. I check what calls `pci_acs_flags_enabled`. It is called by `pci_acs_enabled`, which is called by `pci_device_group` and `iommu.c`. Can QEMU boot with PCIe root ports? The answer is YES, PCIe Root ports in QEMU implement ACS. So far, so good, this is probably reachable.

I think back to P2PDMA again. Is `drivers/pci/p2pdma.c` reachable? What is in p2pdma.c?  I check if I can trigger `calc_map_type_and_dist` or `pci_p2pdma_map_type`. 

I think of `vfio-pci` again. Syzkaller doesn't unbind drivers. I recall `nvmet_ns_p2pmem_store`, which calls `pci_p2pdma_enable_store`. Can I set `ns->p2p_dev` via configfs to a valid P2P DMA device? I recall that, no, because `pci_p2pdma_enable_store` can only set `ns->p2p_dev` if `pci_has_p2pmem` returns `true`.

And, finally, I have to figure out how `pci_has_p2pmem` is true! It must be true for `pdev->p2pdma->pool && pdev->p2pdma->p2pmem_published` to work. I search for how this is set, I can only find this being done by `drivers/accel/habanalabs/common/hldio.c` which needs a Habanalabs Gaudi/Goya AI accelerator. Syzkaller doesn't emulate this. Also `drivers/nvme/host/pci.c` when we have `nvme_map_cmb`.

I think about standard QEMU installs. I recall that by default, it does not enable CMB.


78/2 2026/11/08 03:33 tool grepper
0m Args:
{
  "Expression": "get_pci_function_alias_group"
}

Results:
{
  "Output": "drivers/iommu/iommu.c=1480=static struct iommu_group *get_pci_alias_group(struct pci_dev *pdev,\n--\ndrivers/iommu/iommu.c-1498- */\ndrivers/iommu/iommu.c:1499:static struct iommu_group *get_pci_function_alias_group(struct pci_dev *pdev,\ndrivers/iommu/iommu.c-1500-\t\t\t\t\t\t\tunsigned long *devfns)\n--\ndrivers/iommu/iommu.c=1533=static struct iommu_group *get_pci_alias_group(struct pci_dev *pdev,\n--\ndrivers/iommu/iommu.c-1557-\ndrivers/iommu/iommu.c:1558:\t\t\tgroup = get_pci_function_alias_group(tmp, devfns);\ndrivers/iommu/iommu.c-1559-\t\t\tif (group) {\n--\ndrivers/iommu/iommu.c=1623=struct iommu_group *pci_device_group(struct device *dev)\n--\ndrivers/iommu/iommu.c-1677-\t */\ndrivers/iommu/iommu.c:1678:\tgroup = get_pci_function_alias_group(pdev, (unsigned long *)devfns);\ndrivers/iommu/iommu.c-1679-\tif (group)\n"
}

79/2 2026/11/08 03:33 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 126192
							output: 21
							thoughts: 2716
						

Thoughts:
**Analyzing PCI Device Grouping and Reachability in the Fuzzing Context**

Okay, so I'm diving into this `pci_device_group` function in `drivers/iommu/iommu.c`. It's pretty clear that it gets called for every PCI device during IOMMU group initialization. The code's logic digs into the PCI hierarchy to figure out the isolation limits, checking for ACS support along the way via `pci_acs_path_enabled` and ultimately `pci_acs_flags_enabled`.

The main question is, when does `pci_device_group` actually run? Looks like it's happening during boot, specifically during device probe. Now, a key question arises: can this code path be triggered during runtime, which is crucial for fuzzing with tools like syzkaller?

Syzkaller typically doesn't hotplug PCI devices unless some explicit setup is done in QEMU (e.g. dynamic hotplug via sysfs or QEMU monitor interaction, which syzkaller doesn't directly use). I also need to make a distinction - what about software devices? Devices like tun, loopback, and virtio over mmio aren't PCI, even though virtio-pci devices are present from boot.

A new question arises - what about `pci_p2pdma.c`? Can syzkaller execute `pci_p2pdma_map_type` or `calc_map_type_and_dist`? My primary concern is reachability. Section 1 of the documentation highlights that fuzzing should only target code that executes in standard virtualized environments (GCE or QEMU, using software-emulated devices). Code that is structurally unreachable shouldn't be fuzzed, no matter how complex the logic is.

Now, does P2P DMA even execute in standard virtualized environments? In GCE, P2P DMA is a non-starter because they don't have the hardware. GCE runs on KVM/BHyve with virtio devices or Google virtual NIC (gVNIC) or nvme. None of these support P2P DMA. And, in QEMU - standard QEMU also doesn't provide these capabilities.

For P2P DMA, you need a device publishing P2P memory via `pci_p2pmem_publish()`, like NVMe devices with CMB (Controller Memory Buffer) or Habanalabs ASIC cards. Or, you could use `dma_buf_phys_vec_to_sgt` via `vfio_pci_dma_buf_map` (which requires VFIO-PCI and syzkaller does not have VFIO setup) or `mlx5` (which requires physical hardware like Mellanox ConnectX NIC). Or, DRM GPU peer-to-peer like `amdgpu` or `xe`. But GCE and standard QEMU don't have these.

Checking for calls to `pci_p2pdma_distance`, `pci_p2pmem_find_many`, and `pci_p2pdma_map_type`, all those are specific to NVMe or hardware (Habanalabs, AMD GPU, Intel GPU, Mellanox ConnectX NIC, VFIO-PCI).

What about `pci_acs_flags_enabled` in `pci.c`? The latest changes to `pci.c` include changes in `pci_acs_flags_enabled` function and an export to KUNIT. Can syzkaller fuzz this function? `pci_acs_flags_enabled` runs during boot (device discovery and IOMMU grouping). Syzkaller can't fuzz boot-time PCI device enumeration. Could it be triggered at runtime? Let me check for runtime callers of `pci_acs_flags_enabled`, `pci_acs_enabled`, or `pci_acs_path_enabled`. It looks like `pci_enable_pasid` calls these.



80/2 2026/11/08 03:33 tool grepper
0m Args:
{
  "Expression": "pci_enable_pasid"
}

Results:
{
  "Output": "drivers/iommu/amd/iommu.c=637=static inline int pdev_enable_cap_pasid(struct pci_dev *pdev)\n--\ndrivers/iommu/amd/iommu.c-646-\t\t/* Only allow access to user-accessible pages */\ndrivers/iommu/amd/iommu.c:647:\t\tret = pci_enable_pasid(pdev, 0);\ndrivers/iommu/amd/iommu.c-648-\t\tif (!ret)\n--\ndrivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c=3211=static int arm_smmu_enable_pasid(struct arm_smmu_master *master)\n--\ndrivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c-3230-\ndrivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c:3231:\tret = pci_enable_pasid(pdev, features);\ndrivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c-3232-\tif (ret) {\n--\ndrivers/iommu/intel/iommu.c=3468=static void intel_iommu_probe_finalize(struct device *dev)\n--\ndrivers/iommu/intel/iommu.c-3479-\tif (info-\u003epasid_supported \u0026\u0026\ndrivers/iommu/intel/iommu.c:3480:\t    !pci_enable_pasid(to_pci_dev(dev), info-\u003epasid_supported \u0026 ~1))\ndrivers/iommu/intel/iommu.c-3481-\t\tinfo-\u003epasid_enabled = 1;\n--\ndrivers/pci/ats.c=435=void pci_pasid_init(struct pci_dev *pdev)\n--\ndrivers/pci/ats.c-440-/**\ndrivers/pci/ats.c:441: * pci_enable_pasid - Enable the PASID capability\ndrivers/pci/ats.c-442- * @pdev: PCI device structure\n--\ndrivers/pci/ats.c-448- */\ndrivers/pci/ats.c:449:int pci_enable_pasid(struct pci_dev *pdev, int features)\ndrivers/pci/ats.c-450-{\n--\ndrivers/pci/ats.c-491-}\ndrivers/pci/ats.c:492:EXPORT_SYMBOL_GPL(pci_enable_pasid);\ndrivers/pci/ats.c-493-\n--\ninclude/linux/pci-ats.h=39=static inline bool pci_pri_supported(struct pci_dev *pdev)\n--\ninclude/linux/pci-ats.h-43-#ifdef CONFIG_PCI_PASID\ninclude/linux/pci-ats.h:44:int pci_enable_pasid(struct pci_dev *pdev, int features);\ninclude/linux/pci-ats.h-45-void pci_disable_pasid(struct pci_dev *pdev);\n--\ninclude/linux/pci-ats.h=48=int pci_pasid_status(struct pci_dev *pdev);\ninclude/linux/pci-ats.h-49-#else /* CONFIG_PCI_PASID */\ninclude/linux/pci-ats.h:50:static inline int pci_enable_pasid(struct pci_dev *pdev, int features)\ninclude/linux/pci-ats.h-51-{ return -EINVAL; }\n"
}

81/2 2026/11/08 03:33 llm patch-evaluator
3m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 130736
							output: 25
							thoughts: 4498
						

Thoughts:
**PCI P2PDMA Reachability Analysis for Fuzzing**

Alright, let's break this down. My primary concern here is determining if the modifications in this patch are *reachable* for fuzzing, specifically in the standard QEMU/GCE environments that syzkaller utilizes.  My approach hinges on the principle that if code is structurally unreachable within those environments, it shouldn't be fuzzed, regardless of added assertions or complex logic.

First, I identified that functions like `pci_enable_pasid` are called at device probe time, which alone doesn't scream reachability at runtime via syzkaller, but I must evaluate all touched functions. I then scrutinized the key functions, specifically those related to PCI P2PDMA (`drivers/pci/p2pdma.c`).

A critical point emerged: Is this "structurally unreachable hardware"? The text mentions "Vendor-specific PCIe switches, SmartNICs, or GPU drivers... requiring physical ASIC/PCIe cards not emulated in standard QEMU."  I immediately challenged this by considering whether PCIe P2P DMA *can* work across switches without physical hardware.  The presence of KUnit tests with mock PCIe topologies suggests that exercising P2PDMA routing controls is, in fact, not easily achievable even in real hardware without those tests. This means that, in a standard QEMU environment, P2PDMA features and device-specific quirks might not be present.

The question then becomes: can syzkaller *execute* any of the modified code paths? The text tells me to assume all code paths are unreachable, unless I can confirm that they are reachable.

I started examining specific functions. First, `pci_acs_flags_enabled` appears to be called only during PCI bus probing / IOMMU grouping at boot time. Second, `pci_dev_specific_read_acs_ctrl`, only called from within `p2pdma.c`, and so it is tightly coupled with P2PDMA's reachability. Third, and the most critical, I investigated reachability of the core DMA functions in `p2pdma.c`, particularly `calc_map_type_and_dist` and `pci_p2pdma_map_type`. Syzkaller tests can never call this code path.

To reach `calc_map_type_and_dist`, the device must have `pci_has_p2pmem(pdev) == true`, which is only true for Habanalabs AI accelerators (physical ASIC) or an NVMe device with CMB (which isn't usually present in standard virtual QEMU / GCE). I need to check whether the standard syzkaller setup runs with an NVMe device with CMB. The standard setup does not.

Furthermore, to reach `pci_p2pdma_map_type`, you must go through `dma_buf_phys_vec_to_sgt`, which requires mlx5 InfiniBand or vfio-pci dmabuf, or `pci_p2pdma_state`, which requires a  `MEMORY_DEVICE_PCI_P2PDMA` page. The former again is absent in standard QEMU/GCE, and the latter requires P2P memory from the nonexistent providers. The only drivers that call `pci_p2pdma_state` are in the block layer, iommu, and direct dma implementations.

So, the issue now is to determine whether standard QEMU is sufficient for reaching that code.  I checked whether QEMU could emulate PCIe switches. It can. But, does the syzkaller setup actually run a QEMU with those features? No, it does not.

The patch's mention of "Vendor-specific PCIe switches" is key. Are the switches involved vendor-specific? It mentions specific devices which do have that vendor-specific logic, but the code touched includes generic infrastructure for the PCI subsystem.

So, the next question is if the *PCI subsystem*'s implementation for P2PDMA is reachable via standard syzkaller.

And that's the crux of it. The key is in understanding the criteria:  Is the modified code (specifically within the context of `p2pdma.c`) truly *unreachable* in the syzkaller's standard environment, and what criteria makes it unreachable? The tests themselves seem to demonstrate that those features aren't present in standard QEMU, so that code is structurally unreachable. Therefore, WorthFuzzing is false.



82/2 2026/11/08 03:37 tool grepper
0m Args:
{
  "Expression": "is_pci_p2pdma_page"
}

Results:
{
  "Output": "block/bio-integrity.c=334=static unsigned int bvec_from_pages(struct bio_vec *bvec, struct page **pages,\n--\nblock/bio-integrity.c-356-\nblock/bio-integrity.c:357:\t\tif (is_pci_p2pdma_page(pages[i]))\nblock/bio-integrity.c-358-\t\t\t*is_p2p = true;\n--\nblock/bio.c=1030=void __bio_add_page(struct bio *bio, struct page *page,\n--\nblock/bio.c-1035-\nblock/bio.c:1036:\tif (is_pci_p2pdma_page(page))\nblock/bio.c-1037-\t\tbio-\u003ebi_opf |= REQ_NOMERGE;\n--\nblock/bio.c=1343=int bio_iov_iter_get_pages(struct bio *bio, struct iov_iter *iter,\n--\nblock/bio.c-1388-\nblock/bio.c:1389:\tif (is_pci_p2pdma_page(bio-\u003ebi_io_vec-\u003ebv_page))\nblock/bio.c-1390-\t\tbio-\u003ebi_opf |= REQ_NOMERGE;\n--\nblock/blk.h=156=static inline bool zone_device_pages_compatible(const struct page *a,\n--\nblock/blk.h-158-{\nblock/blk.h:159:\tif (is_pci_p2pdma_page(a) || is_pci_p2pdma_page(b))\nblock/blk.h-160-\t\treturn zone_device_pages_have_same_pgmap(a, b);\n--\ndrivers/nvme/host/pci.c=1430=static blk_status_t nvme_pci_setup_data_simple(struct request *req,\n--\ndrivers/nvme/host/pci.c-1441-\t\treturn BLK_STS_AGAIN;\ndrivers/nvme/host/pci.c:1442:\tif (is_pci_p2pdma_page(bv.bv_page))\ndrivers/nvme/host/pci.c-1443-\t\treturn BLK_STS_AGAIN;\n--\ndrivers/nvme/host/pci.c=1599=static blk_status_t nvme_pci_setup_meta_mptr(struct request *req)\n--\ndrivers/nvme/host/pci.c-1604-\ndrivers/nvme/host/pci.c:1605:\tif (is_pci_p2pdma_page(bv.bv_page))\ndrivers/nvme/host/pci.c-1606-\t\treturn nvme_pci_setup_meta_iter(req);\n--\ndrivers/nvme/target/io-cmd-bdev.c=253=static void nvmet_bdev_execute_rw(struct nvmet_req *req)\n--\ndrivers/nvme/target/io-cmd-bdev.c-286-\ndrivers/nvme/target/io-cmd-bdev.c:287:\tif (is_pci_p2pdma_page(sg_page(req-\u003esg)))\ndrivers/nvme/target/io-cmd-bdev.c-288-\t\topf |= REQ_NOMERGE;\n--\ninclude/linux/memremap.h=192=static inline void folio_set_zone_device_data(struct folio *folio, void *data)\n--\ninclude/linux/memremap.h-197-\ninclude/linux/memremap.h:198:static inline bool is_pci_p2pdma_page(const struct page *page)\ninclude/linux/memremap.h-199-{\n--\ninclude/linux/pci-p2pdma.h=195=pci_p2pdma_state(struct pci_p2pdma_map_state *state, struct device *dev,\n--\ninclude/linux/pci-p2pdma.h-197-{\ninclude/linux/pci-p2pdma.h:198:\tif (IS_ENABLED(CONFIG_PCI_P2PDMA) \u0026\u0026 is_pci_p2pdma_page(page)) {\ninclude/linux/pci-p2pdma.h-199-\t\t__pci_p2pdma_update_state(state, dev, page);\n--\nmm/gup.c=517=static struct folio *try_grab_folio_fast(struct page *page, int refs,\n--\nmm/gup.c-527-\nmm/gup.c:528:\tif (unlikely(!(flags \u0026 FOLL_PCI_P2PDMA) \u0026\u0026 is_pci_p2pdma_page(page)))\nmm/gup.c-529-\t\treturn NULL;\n"
}

83/2 2026/11/08 03:37 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 137474
							output: 24
							thoughts: 137
						

Thoughts:
**Investigating PCI P2PDMA Page Detection**

Okay, let's dive into this `is_pci_p2pdma_page` function. I need to understand what this does, specifically within `include/linux/memremap.h`. Looking at the definition, it's pretty straightforward, really. It appears to check if a given page is a PCI P2PDMA page by combining two conditions:  `is_zone_device_page(page)` must return true AND the `type` field of the page's page map must be `MEMORY_DEVICE_PCI_P2PDMA`.

The key piece now is to track down where `MEMORY_DEVICE_PCI_P2PDMA` is defined. I'll reach for `grep` and see where this enum value is coming from. Time to dig!



84/2 2026/11/08 03:37 tool grepper
0m Args:
{
  "Expression": "MEMORY_DEVICE_PCI_P2PDMA"
}

Results:
{
  "Output": "Documentation/driver-api/pci/p2pdma.rst=152=Building on this, the subsystem offers a layer to wrap the MMIO in a ZONE_DEVICE\nDocumentation/driver-api/pci/p2pdma.rst:153:pgmap of MEMORY_DEVICE_PCI_P2PDMA to create struct pages. The lifecycle of\nDocumentation/driver-api/pci/p2pdma.rst-154-pgmap ensures that when the pgmap is destroyed all other drivers have stopped\nDocumentation/driver-api/pci/p2pdma.rst=155=using the MMIO. This option works with O_DIRECT flows, in some cases, if the\nDocumentation/driver-api/pci/p2pdma.rst:156:underlying subsystem supports handling MEMORY_DEVICE_PCI_P2PDMA through\nDocumentation/driver-api/pci/p2pdma.rst-157-FOLL_PCI_P2PDMA. The use of FOLL_LONGTERM is prevented. As this relies on pgmap\n--\nDocumentation/driver-api/pci/p2pdma.rst=246=Struct Page Caveats\n--\nDocumentation/driver-api/pci/p2pdma.rst-248-\nDocumentation/driver-api/pci/p2pdma.rst:249:While the MEMORY_DEVICE_PCI_P2PDMA pages can be installed in VMAs,\nDocumentation/driver-api/pci/p2pdma.rst-250-pin_user_pages() and related will not return them unless FOLL_PCI_P2PDMA is set.\nDocumentation/driver-api/pci/p2pdma.rst-251-\nDocumentation/driver-api/pci/p2pdma.rst:252:The MEMORY_DEVICE_PCI_P2PDMA pages require care to support in the kernel. The\nDocumentation/driver-api/pci/p2pdma.rst-253-KVA is still MMIO and must still be accessed through the normal\n--\ndrivers/pci/p2pdma.c=389=int pci_p2pdma_add_resource(struct pci_dev *pdev, int bar, size_t size,\n--\ndrivers/pci/p2pdma.c-434-\tpgmap-\u003enr_range = 1;\ndrivers/pci/p2pdma.c:435:\tpgmap-\u003etype = MEMORY_DEVICE_PCI_P2PDMA;\ndrivers/pci/p2pdma.c-436-\tpgmap-\u003eops = \u0026p2pdma_pgmap_ops;\n--\ninclude/linux/memremap.h=21=struct vmem_altmap {\n--\ninclude/linux/memremap.h-63- *\ninclude/linux/memremap.h:64: * MEMORY_DEVICE_PCI_P2PDMA:\ninclude/linux/memremap.h-65- * Device memory residing in a PCI BAR intended for use with Peer-to-Peer\n--\ninclude/linux/memremap.h=68=enum memory_type {\n--\ninclude/linux/memremap.h-73-\tMEMORY_DEVICE_GENERIC,\ninclude/linux/memremap.h:74:\tMEMORY_DEVICE_PCI_P2PDMA,\ninclude/linux/memremap.h-75-};\n--\ninclude/linux/memremap.h=179=static inline bool folio_is_pci_p2pdma(const struct folio *folio)\n--\ninclude/linux/memremap.h-182-\t\tfolio_is_zone_device(folio) \u0026\u0026\ninclude/linux/memremap.h:183:\t\tfolio-\u003epgmap-\u003etype == MEMORY_DEVICE_PCI_P2PDMA;\ninclude/linux/memremap.h-184-}\n--\nmm/memremap.c=266=void *memremap_pages(struct dev_pagemap *pgmap, int nid)\n--\nmm/memremap.c-315-\t\tbreak;\nmm/memremap.c:316:\tcase MEMORY_DEVICE_PCI_P2PDMA:\nmm/memremap.c-317-\t\tparams.pgprot = pgprot_noncached(params.pgprot);\n--\nmm/memremap.c=416=void free_zone_device_folio(struct folio *folio)\n--\nmm/memremap.c-472-\nmm/memremap.c:473:\tcase MEMORY_DEVICE_PCI_P2PDMA:\nmm/memremap.c-474-\t\tif (WARN_ON_ONCE(!pgmap-\u003eops || !pgmap-\u003eops-\u003efolio_free))\n--\nmm/mm_init.c=1034=static void __ref __init_zone_device_page(struct page *page, unsigned long pfn,\n--\nmm/mm_init.c-1066-\tcase MEMORY_DEVICE_COHERENT:\nmm/mm_init.c:1067:\tcase MEMORY_DEVICE_PCI_P2PDMA:\nmm/mm_init.c-1068-\t\tset_page_count(page, 0);\n"
}

85/2 2026/11/08 03:37 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 139099
							output: 221
							thoughts: 3765
						

Thoughts:
**Analysis of PCIe ACS P2PDMA Patch for Fuzzing Suitability**

Okay, here's my assessment. This patch, at its core, delves into the intricacies of PCI Access Control Services (ACS) and Peer-to-Peer DMA (P2PDMA) routing, specifically addressing how traffic is managed across PCIe switches and bridges between devices. The core logic resides in `drivers/pci/p2pdma.c`, and it touches upon related aspects in `drivers/pci/pci.c` and `drivers/pci/quirks.c`.  A significant component is the introduction of a KUnit test suite, `drivers/pci/pci_acs_test.c`, designed to exercise this complex logic.

Here's the problem I see:  This code, at least the modified parts crucial for P2PDMA routing, isn't reachable in a standard fuzzing environment like QEMU or GCE.  The functions like `calc_map_type_and_dist`, `pci_acs_p2pdma_*`, and `pci_p2pdma_map_type*` require specific hardware configurations. These include things like NVMe controllers with Controller Memory Buffer (CMB), Habanalabs ASICs, or other PCIe devices equipped with ACS capabilities and PCIe switches supporting ACS redirect. These aren't emulated or commonly present in the virtual environments used for fuzzing. Accessing `pci_acs_flags_enabled` during fuzzing is not possible; these are only called during the initial bus probing at boot.

The documentation updates and the KUnit tests themselves do *not* impact the compiled kernel image. They're non-executable changes from a syzkaller perspective. The tests within `pci_acs_test.c` are specifically designed to circumvent hardware limitations by using a mock fabric – it's explicitly designed to test *unreachable* scenarios.

Even if we *could* trigger some of the involved calls like `pci_p2pdma_map_type_tlp`, it's not going to lead to code execution in the modified files. Those calls require the system to have a device with the `pci_has_p2pmem` capability, and those devices are not standard in QEMU/GCE. Therefore, any attempt to fuzz this area with the listed functions won't yield meaningful results.

The key is that the code is *structurally unreachable* in the target fuzzing environments. The patch deals with hardware configurations (specifically PCIe switches and P2PDMA providers) that are not emulated in standard QEMU or GCE. This is precisely why the author wrote the KUnit test file. It's the only way to test that logic.

Therefore, after thoroughly evaluating the reachability of the code within standard fuzzing environments, I conclude that this patch is **not worth fuzzing**. The modified code falls into the category of "structurally unreachable hardware," and the unit tests are not executed as a part of fuzzing.



86/2 2026/11/08 03:38 tool set-results
0m Args:
{
  "EnableConfigs": [],
  "FocusSymbols": [],
  "Reasoning": "The patch series refactors PCI Access Control Services (ACS) peer-to-peer DMA (P2PDMA) routing logic in drivers/pci/p2pdma.c, adds read error checks in drivers/pci/pci.c and drivers/pci/quirks.c, and adds a KUnit test suite in drivers/pci/pci_acs_test.c. In standard virtualized fuzzing environments (QEMU/GCE), the modified P2PDMA code paths are structurally unreachable because no PCIe P2PDMA memory providers (such as NVMe controllers with CMB or accelerator ASICs) or PCIe switch fabrics with ACS redirect capabilities are emulated or available. Furthermore, pci_acs_flags_enabled is only called during device probing/IOMMU group initialization at boot time, and KUnit unit tests are not exercised by syzkaller syscall fuzzing.",
  "WorthFuzzing": false
}

Results:
{
  "EnableConfigs": null,
  "FocusSymbols": [],
  "Reasoning": "The patch series refactors PCI Access Control Services (ACS) peer-to-peer DMA (P2PDMA) routing logic in drivers/pci/p2pdma.c, adds read error checks in drivers/pci/pci.c and drivers/pci/quirks.c, and adds a KUnit test suite in drivers/pci/pci_acs_test.c. In standard virtualized fuzzing environments (QEMU/GCE), the modified P2PDMA code paths are structurally unreachable because no PCIe P2PDMA memory providers (such as NVMe controllers with CMB or accelerator ASICs) or PCIe switch fabrics with ACS redirect capabilities are emulated or available. Furthermore, pci_acs_flags_enabled is only called during device probing/IOMMU group initialization at boot time, and KUnit unit tests are not exercised by syzkaller syscall fuzzing.",
  "WorthFuzzing": false
}

87/1 2026/11/08 03:38 action If
0m Args:
{
  "WorthFuzzing": false
}

Results:
null

LLM Calls Summary:
Total Calls Total Tokens Avg Tokens Total Duration (Seconds) Avg Duration (Seconds)
Tool Calls Summary:
Total Calls Total Duration (Seconds) Avg Duration (Seconds)