Skip to content

Commit f5f9ad8

Browse files
nicolincnirmoy
authored andcommitted
NVIDIA: VR: SAUCE: PCI: Allow ATS to be always on for CXL.cache capable devices
Controlled by the IOMMU driver, ATS is usually enabled "on demand", when a device requests a translation service from its associated IOMMU HW running on the channel of a given PASID. This is working even when a device has no translation on its RID, i.e. RID is IOMMU bypassed. On the other hand, certain PCIe device requires non-PASID ATS, when its RID stream is IOMMU bypassed. Call this "always on". For instance, the CXL spec notes in "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 word, the CXL.cache capability relies on ATS. Otherwise, it won't have access to the host physical memory. Introduce a new pci_ats_always_on() for IOMMU driver to scan a PCI device, to shift ATS policies between "on demand" and "always on". Add the support for CXL.cache devices first. Non-CXL devices will be added in quirks.c file. Suggested-by: Vikram Sethi <vsethi@nvidia.com> Suggested-by: Jason Gunthorpe <jgg@nvidia.com> Signed-off-by: Nicolin Chen <nicolinc@nvidia.com> (backported from https://lore.kernel.org/linux-iommu/cover.1768624180.git.nicolinc@nvidia.com) Signed-off-by: Nirmoy Das <nirmoyd@nvidia.com>
1 parent 51acc19 commit f5f9ad8

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed

drivers/pci/ats.c

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,50 @@ 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 world, CXL.cache devices cannot access physical memory without ATS.
214+
*/
215+
static bool pci_cxl_ats_always_on(struct pci_dev *pdev)
216+
{
217+
int offset;
218+
u16 cap;
219+
220+
offset = pci_find_dvsec_capability(pdev, PCI_VENDOR_ID_CXL,
221+
CXL_DVSEC_PCIE_DEVICE);
222+
if (!offset)
223+
return false;
224+
225+
pci_read_config_word(pdev, offset + CXL_DVSEC_CAP_OFFSET, &cap);
226+
if (cap & CXL_DVSEC_CACHE_CAPABLE)
227+
return true;
228+
229+
return false;
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 non-PASID ATS function on an IOMMU
237+
* bypassed configuration.
238+
*/
239+
bool pci_ats_always_on(struct pci_dev *pdev)
240+
{
241+
if (pci_ats_disabled() || !pci_ats_supported(pdev))
242+
return false;
243+
244+
/* A VF inherits its PF's requirement for ATS function */
245+
if (pdev->is_virtfn)
246+
pdev = pci_physfn(pdev);
247+
248+
return pci_cxl_ats_always_on(pdev);
249+
}
250+
EXPORT_SYMBOL_GPL(pci_ats_always_on);
251+
208252
#ifdef CONFIG_PCI_PRI
209253
void pci_pri_init(struct pci_dev *pdev)
210254
{

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

include/uapi/linux/pci_regs.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1239,4 +1239,9 @@
12391239
#define PCI_DVSEC_CXL_PORT_CTL 0x0c
12401240
#define PCI_DVSEC_CXL_PORT_CTL_UNMASK_SBR 0x00000001
12411241

1242+
/* CXL 2.0 8.1.3: PCIe DVSEC for CXL Device */
1243+
#define CXL_DVSEC_PCIE_DEVICE 0
1244+
#define CXL_DVSEC_CAP_OFFSET 0xA
1245+
#define CXL_DVSEC_CACHE_CAPABLE BIT(0)
1246+
12421247
#endif /* LINUX_PCI_REGS_H */

0 commit comments

Comments
 (0)