Skip to content

Commit 049df40

Browse files
nicolincnvidia-bfigg
authored andcommitted
NVIDIA: VR: SAUCE: PCI: Allow ATS to be always on for CXL.cache capable devices
BugLink: https://bugs.launchpad.net/bugs/2150727 Controlled by the IOMMU driver, ATS is usually enabled "on demand" when a given PASID on a device is attached to an I/O page table. This is working even when a device has no translation on its RID (i.e., the RID is IOMMU bypassed). However, certain PCIe devices require non-PASID ATS on their RID even when the RID is IOMMU bypassed. Call this "always on". For example, CXL spec r4.0 notes in sec 3.2.5.13 Memory Type on CXL.cache: "To source requests on CXL.cache, devices need to get the Host Physical Address (HPA) from the Host by means of an ATS request on CXL.io." In other words, the CXL.cache capability requires ATS; otherwise, it can't access host physical memory. Introduce a new pci_ats_always_on() helper for the IOMMU driver to scan a PCI device and shift ATS policies between "on demand" and "always on". Add the support for CXL.cache devices first. Pre-CXL devices will be added in quirks.c file. Note that pci_ats_always_on() validates against pci_ats_supported(), so we ensure that untrusted devices (e.g. external ports) will not be always on. This maintains the existing ATS security policy regarding potential side- channel attacks via ATS. Cc: linux-cxl@vger.kernel.org Suggested-by: Vikram Sethi <vsethi@nvidia.com> Suggested-by: Jason Gunthorpe <jgg@nvidia.com> Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com> Reviewed-by: Jason Gunthorpe <jgg@nvidia.com> Reviewed-by: Kevin Tian <kevin.tian@intel.com> Tested-by: Nirmoy Das <nirmoyd@nvidia.com> Acked-by: Nirmoy Das <nirmoyd@nvidia.com> Signed-off-by: Nicolin Chen <nicolinc@nvidia.com> Reviewed-by: Dave Jiang <dave.jiang@intel.com> (backported from https://lore.kernel.org/r/f6734b9dad0050138676f11ecd14e9db1cf6b697.1777269009.git.nicolinc@nvidia.com) [Nirmoy: Adapt to already existing PCI_DVSEC_CXL_CACHE_CAPABLE.] Signed-off-by: Nirmoy Das <nirmoyd@nvidia.com> Acked-by: Jamie Nguyen <jamien@nvidia.com> Acked-by: Carol L Soto <csoto@nvidia.com> Acked-by: Matthew R. Ochs <mochs@nvidia.com> Signed-off-by: Brad Figg <bfigg@nvidia.com>
1 parent 8b2f927 commit 049df40

2 files changed

Lines changed: 46 additions & 0 deletions

File tree

drivers/pci/ats.c

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,49 @@ int pci_ats_page_aligned(struct pci_dev *pdev)
205205
return 0;
206206
}
207207

208+
/*
209+
* CXL r4.0, sec 3.2.5.13 Memory Type on CXL.cache notes: to source requests on
210+
* CXL.cache, devices need to get the Host Physical Address (HPA) from the Host
211+
* by means of an ATS request on CXL.io.
212+
*
213+
* In other words, CXL.cache devices cannot access host physical memory without
214+
* ATS.
215+
*/
216+
static bool pci_cxl_ats_always_on(struct pci_dev *pdev)
217+
{
218+
int offset;
219+
u16 cap;
220+
221+
offset = pci_find_dvsec_capability(pdev, PCI_VENDOR_ID_CXL,
222+
PCI_DVSEC_CXL_DEVICE);
223+
if (!offset)
224+
return false;
225+
226+
if (pci_read_config_word(pdev, offset + PCI_DVSEC_CXL_CAP, &cap))
227+
return false;
228+
229+
return cap & PCI_DVSEC_CXL_CACHE_CAPABLE;
230+
}
231+
232+
/**
233+
* pci_ats_always_on - Whether the PCI device requires ATS to be always enabled
234+
* @pdev: the PCI device
235+
*
236+
* Returns true, if the PCI device requires ATS for basic functional operation.
237+
*/
238+
bool pci_ats_always_on(struct pci_dev *pdev)
239+
{
240+
if (pci_ats_disabled() || !pci_ats_supported(pdev))
241+
return false;
242+
243+
/* A VF inherits its PF's requirement for ATS function */
244+
if (pdev->is_virtfn)
245+
pdev = pci_physfn(pdev);
246+
247+
return pci_cxl_ats_always_on(pdev);
248+
}
249+
EXPORT_SYMBOL_GPL(pci_ats_always_on);
250+
208251
#ifdef CONFIG_PCI_PRI
209252
void pci_pri_init(struct pci_dev *pdev)
210253
{

include/linux/pci-ats.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ int pci_prepare_ats(struct pci_dev *dev, int ps);
1212
void pci_disable_ats(struct pci_dev *dev);
1313
int pci_ats_queue_depth(struct pci_dev *dev);
1414
int pci_ats_page_aligned(struct pci_dev *dev);
15+
bool pci_ats_always_on(struct pci_dev *dev);
1516
#else /* CONFIG_PCI_ATS */
1617
static inline bool pci_ats_supported(struct pci_dev *d)
1718
{ return false; }
@@ -24,6 +25,8 @@ static inline int pci_ats_queue_depth(struct pci_dev *d)
2425
{ return -ENODEV; }
2526
static inline int pci_ats_page_aligned(struct pci_dev *dev)
2627
{ return 0; }
28+
static inline bool pci_ats_always_on(struct pci_dev *dev)
29+
{ return false; }
2730
#endif /* CONFIG_PCI_ATS */
2831

2932
#ifdef CONFIG_PCI_PRI

0 commit comments

Comments
 (0)