Thank you for your contribution! Sashiko AI review found 1 potential issue(s) 
to consider:
- [High] pci: pci_p2pdma_distance_many() evaluates compatibility without 
applying client ATS constraints
--

commit 254b102fe424913edc3d5f94f8d41bc5d0de2b20
Author: Leon Romanovsky <[email protected]>

PCI/P2PDMA: Evaluate the ATS path for clients with ATS enabled

P2PDMA assumes every client issues Untranslated Requests. A device with
ATS enabled may translate any address it is handed, including a bus
address, and Translation Blocking can reject its Translated Requests on
a route the Untranslated answer called usable.

> diff --git a/drivers/pci/p2pdma.c b/drivers/pci/p2pdma.c
> index e38081f797611..a5fc622e3114f 100644
> --- a/drivers/pci/p2pdma.c
> +++ b/drivers/pci/p2pdma.c

[ ... ]

> @@ -1660,10 +1706,10 @@ pci_p2pdma_map_type_tlp(struct p2pdma_provider 
> *provider, struct device *dev,
>                pci_p2pdma_map_type_name(type), type, provider_state);
>  
>       if (type == PCI_P2PDMA_MAP_UNKNOWN)
> -             return calc_map_type_and_dist(pdev, client, &dist, tlp_flags,
> +             type = calc_map_type_and_dist(pdev, client, &dist, tlp_flags,
>                                             true);
>  
> -     return type;
> +     return pci_p2pdma_client_map_type(pdev, client, per_mapping, type);
>  }

[Severity: High]
Does pci_p2pdma_distance_many() also need to apply these new ATS constraints?

While this patch successfully updates pci_p2pdma_map_type_tlp() to evaluate ATS
routing constraints for P2PDMA clients, pci_p2pdma_distance_many() continues
to evaluate mapping compatibility without them:

drivers/pci/p2pdma.c:pci_p2pdma_distance_many() {
    ...
                pci_client = find_parent_pci_dev(clients[i]);
                if (!pci_client) {
    ...
                map = calc_map_type_and_dist(provider, pci_client, &distance, 0,
                                             verbose);
    ...
}

If a client has ATS enabled and its Untranslated route is usable but its
Translated route is blocked by Translation Blocking (or lacks a whitelisted
host bridge), pci_p2pdma_distance_many() evaluates the Untranslated mapping
with tlp_flags=0, and incorrectly returns success. 

When the driver subsequently attempts to map memory, the ATS-aware mapping
logic will return PCI_P2PDMA_MAP_NOT_SUPPORTED and fail unexpectedly at
runtime, breaking the API contract of the distance validation.

-- 
Sashiko AI review ยท 
https://sashiko.dev/#/patchset/[email protected]?part=17

Reply via email to