Skip to content

Commit 25efbb0

Browse files
hegdevasantjoergroedel
authored andcommitted
iommu/amd: Enable PCI features based on attached domain capability
Commit eda8c28 ("iommu/amd: Enable device ATS/PASID/PRI capabilities independently") changed the way it enables device capability while attaching devices. I missed to account the attached domain capability. Meaning if domain is not capable of handling PASID/PRI (ex: paging domain with v1 page table) then enabling device feature is not required. This patch enables PASID/PRI only if domain is capable of handling SVA. Also move pci feature enablement to do_attach() function so that we make SVA capability in one place. Finally make PRI enable/disable functions as static functions. Signed-off-by: Vasant Hegde <[email protected]> Reviewed-by: Jason Gunthorpe <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Joerg Roedel <[email protected]>
1 parent c9e8701 commit 25efbb0

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

drivers/iommu/amd/amd_iommu.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,6 @@ extern int amd_iommu_gpt_level;
4646

4747
bool amd_iommu_pasid_supported(void);
4848

49-
/* Device capabilities */
50-
int amd_iommu_pdev_enable_cap_pri(struct pci_dev *pdev);
51-
void amd_iommu_pdev_disable_cap_pri(struct pci_dev *pdev);
52-
5349
/* GCR3 setup */
5450
int amd_iommu_set_gcr3(struct iommu_dev_data *dev_data,
5551
ioasid_t pasid, unsigned long gcr3);

drivers/iommu/amd/iommu.c

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -399,14 +399,17 @@ static inline void pdev_disable_cap_ats(struct pci_dev *pdev)
399399
}
400400
}
401401

402-
int amd_iommu_pdev_enable_cap_pri(struct pci_dev *pdev)
402+
static inline int pdev_enable_cap_pri(struct pci_dev *pdev)
403403
{
404404
struct iommu_dev_data *dev_data = dev_iommu_priv_get(&pdev->dev);
405405
int ret = -EINVAL;
406406

407407
if (dev_data->pri_enabled)
408408
return 0;
409409

410+
if (!dev_data->ats_enabled)
411+
return 0;
412+
410413
if (dev_data->flags & AMD_IOMMU_DEVICE_FLAG_PRI_SUP) {
411414
/*
412415
* First reset the PRI state of the device.
@@ -423,7 +426,7 @@ int amd_iommu_pdev_enable_cap_pri(struct pci_dev *pdev)
423426
return ret;
424427
}
425428

426-
void amd_iommu_pdev_disable_cap_pri(struct pci_dev *pdev)
429+
static inline void pdev_disable_cap_pri(struct pci_dev *pdev)
427430
{
428431
struct iommu_dev_data *dev_data = dev_iommu_priv_get(&pdev->dev);
429432

@@ -465,15 +468,14 @@ static void pdev_enable_caps(struct pci_dev *pdev)
465468
{
466469
pdev_enable_cap_ats(pdev);
467470
pdev_enable_cap_pasid(pdev);
468-
amd_iommu_pdev_enable_cap_pri(pdev);
469-
471+
pdev_enable_cap_pri(pdev);
470472
}
471473

472474
static void pdev_disable_caps(struct pci_dev *pdev)
473475
{
474476
pdev_disable_cap_ats(pdev);
475477
pdev_disable_cap_pasid(pdev);
476-
amd_iommu_pdev_disable_cap_pri(pdev);
478+
pdev_disable_cap_pri(pdev);
477479
}
478480

479481
/*
@@ -2035,6 +2037,7 @@ static int do_attach(struct iommu_dev_data *dev_data,
20352037
struct protection_domain *domain)
20362038
{
20372039
struct amd_iommu *iommu = get_amd_iommu_from_dev_data(dev_data);
2040+
struct pci_dev *pdev;
20382041
int ret = 0;
20392042

20402043
/* Update data structures */
@@ -2049,10 +2052,16 @@ static int do_attach(struct iommu_dev_data *dev_data,
20492052
domain->dev_iommu[iommu->index] += 1;
20502053
domain->dev_cnt += 1;
20512054

2055+
pdev = dev_is_pci(dev_data->dev) ? to_pci_dev(dev_data->dev) : NULL;
20522056
if (pdom_is_sva_capable(domain)) {
20532057
ret = init_gcr3_table(dev_data, domain);
20542058
if (ret)
20552059
return ret;
2060+
2061+
if (pdev)
2062+
pdev_enable_caps(pdev);
2063+
} else if (pdev) {
2064+
pdev_enable_cap_ats(pdev);
20562065
}
20572066

20582067
/* Update device table */
@@ -2107,9 +2116,6 @@ static int attach_device(struct device *dev,
21072116
goto out;
21082117
}
21092118

2110-
if (dev_is_pci(dev))
2111-
pdev_enable_caps(to_pci_dev(dev));
2112-
21132119
ret = do_attach(dev_data, domain);
21142120

21152121
out:

0 commit comments

Comments
 (0)