Skip to content

Commit 4e1b09d

Browse files
ssuthiku-amdjoergroedel
authored andcommitted
iommu/amd: Refactor persistent DTE bits programming into amd_iommu_make_clear_dte()
To help avoid duplicate logic when programing DTE for nested translation. Note that this commit changes behavior of when the IOMMU driver is switching domain during attach and the blocking domain, where DTE bit fields for interrupt pass-through (i.e. Lint0, Lint1, NMI, INIT, ExtInt) and System management message could be affected. These DTE bits are specified in the IVRS table for specific devices, and should be persistent. Suggested-by: Jason Gunthorpe <jgg@nvidia.com> Reviewed-by: Jason Gunthorpe <jgg@nvidia.com> Reviewed-by: Nicolin Chen <nicolinc@nvidia.com> Signed-off-by: Suravee Suthikulpanit <suravee.suthikulpanit@amd.com> Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
1 parent 757d2b1 commit 4e1b09d

2 files changed

Lines changed: 13 additions & 11 deletions

File tree

drivers/iommu/amd/amd_iommu.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,22 @@ void amd_iommu_update_dte(struct amd_iommu *iommu,
197197
static inline void
198198
amd_iommu_make_clear_dte(struct iommu_dev_data *dev_data, struct dev_table_entry *new)
199199
{
200+
struct dev_table_entry *initial_dte;
201+
struct amd_iommu *iommu = get_amd_iommu_from_dev(dev_data->dev);
202+
200203
/* All existing DTE must have V bit set */
201204
new->data128[0] = DTE_FLAG_V;
202205
new->data128[1] = 0;
206+
207+
/*
208+
* Restore cached persistent DTE bits, which can be set by information
209+
* in IVRS table. See set_dev_entry_from_acpi().
210+
*/
211+
initial_dte = amd_iommu_get_ivhd_dte_flags(iommu->pci_seg->id, dev_data->devid);
212+
if (initial_dte) {
213+
new->data128[0] |= initial_dte->data128[0];
214+
new->data128[1] |= initial_dte->data128[1];
215+
}
203216
}
204217

205218
/* NESTED */

drivers/iommu/amd/iommu.c

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2110,7 +2110,6 @@ static void set_dte_entry(struct amd_iommu *iommu,
21102110
{
21112111
u16 domid;
21122112
u32 old_domid;
2113-
struct dev_table_entry *initial_dte;
21142113
struct dev_table_entry new = {};
21152114
struct protection_domain *domain = dev_data->domain;
21162115
struct gcr3_tbl_info *gcr3_info = &dev_data->gcr3_info;
@@ -2168,16 +2167,6 @@ static void set_dte_entry(struct amd_iommu *iommu,
21682167
old_domid = READ_ONCE(dte->data[1]) & DTE_DOMID_MASK;
21692168
new.data[1] |= domid;
21702169

2171-
/*
2172-
* Restore cached persistent DTE bits, which can be set by information
2173-
* in IVRS table. See set_dev_entry_from_acpi().
2174-
*/
2175-
initial_dte = amd_iommu_get_ivhd_dte_flags(iommu->pci_seg->id, dev_data->devid);
2176-
if (initial_dte) {
2177-
new.data128[0] |= initial_dte->data128[0];
2178-
new.data128[1] |= initial_dte->data128[1];
2179-
}
2180-
21812170
set_dte_gcr3_table(iommu, dev_data, &new);
21822171

21832172
amd_iommu_update_dte(iommu, dev_data, &new);

0 commit comments

Comments
 (0)