Skip to content

Commit 4402f26

Browse files
hegdevasantjoergroedel
authored andcommitted
iommu/amd: Implement global identity domain
Implement global identity domain. All device groups in identity domain will share this domain. In attach device path, based on device capability it will allocate per device domain ID and GCR3 table. So that it can support SVA. Signed-off-by: Vasant Hegde <vasant.hegde@amd.com> Reviewed-by: Jason Gunthorpe <jgg@nvidia.com> Reviewed-by: Kevin Tian <kevin.tian@intel.com> Link: https://lore.kernel.org/r/20241028093810.5901-11-vasant.hegde@amd.com Signed-off-by: Joerg Roedel <jroedel@suse.de>
1 parent ce2cd17 commit 4402f26

File tree

3 files changed

+36
-4
lines changed

3 files changed

+36
-4
lines changed

drivers/iommu/amd/amd_iommu.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ extern int amd_iommu_gpt_level;
4646
extern unsigned long amd_iommu_pgsize_bitmap;
4747

4848
/* Protection domain ops */
49+
void amd_iommu_init_identity_domain(void);
4950
struct protection_domain *protection_domain_alloc(unsigned int type, int nid);
5051
void protection_domain_free(struct protection_domain *domain);
5152
struct iommu_domain *amd_iommu_domain_alloc_sva(struct device *dev,

drivers/iommu/amd/init.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2164,6 +2164,9 @@ static int __init amd_iommu_init_pci(void)
21642164
struct amd_iommu_pci_seg *pci_seg;
21652165
int ret;
21662166

2167+
/* Init global identity domain before registering IOMMU */
2168+
amd_iommu_init_identity_domain();
2169+
21672170
for_each_iommu(iommu) {
21682171
ret = iommu_init_pci(iommu);
21692172
if (ret) {

drivers/iommu/amd/iommu.c

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ struct kmem_cache *amd_iommu_irq_cache;
7474

7575
static void detach_device(struct device *dev);
7676

77+
static int amd_iommu_attach_device(struct iommu_domain *dom,
78+
struct device *dev);
79+
7780
static void set_dte_entry(struct amd_iommu *iommu,
7881
struct iommu_dev_data *dev_data);
7982

@@ -2263,6 +2266,14 @@ void protection_domain_free(struct protection_domain *domain)
22632266
kfree(domain);
22642267
}
22652268

2269+
static void protection_domain_init(struct protection_domain *domain, int nid)
2270+
{
2271+
spin_lock_init(&domain->lock);
2272+
INIT_LIST_HEAD(&domain->dev_list);
2273+
INIT_LIST_HEAD(&domain->dev_data_list);
2274+
domain->iop.pgtbl.cfg.amd.nid = nid;
2275+
}
2276+
22662277
struct protection_domain *protection_domain_alloc(unsigned int type, int nid)
22672278
{
22682279
struct protection_domain *domain;
@@ -2277,10 +2288,7 @@ struct protection_domain *protection_domain_alloc(unsigned int type, int nid)
22772288
return NULL;
22782289
}
22792290

2280-
spin_lock_init(&domain->lock);
2281-
INIT_LIST_HEAD(&domain->dev_list);
2282-
INIT_LIST_HEAD(&domain->dev_data_list);
2283-
domain->iop.pgtbl.cfg.amd.nid = nid;
2291+
protection_domain_init(domain, nid);
22842292

22852293
return domain;
22862294
}
@@ -2471,6 +2479,25 @@ static struct iommu_domain blocked_domain = {
24712479
}
24722480
};
24732481

2482+
static struct protection_domain identity_domain;
2483+
2484+
static const struct iommu_domain_ops identity_domain_ops = {
2485+
.attach_dev = amd_iommu_attach_device,
2486+
};
2487+
2488+
void amd_iommu_init_identity_domain(void)
2489+
{
2490+
struct iommu_domain *domain = &identity_domain.domain;
2491+
2492+
domain->type = IOMMU_DOMAIN_IDENTITY;
2493+
domain->ops = &identity_domain_ops;
2494+
domain->owner = &amd_iommu_ops;
2495+
2496+
identity_domain.id = domain_id_alloc();
2497+
2498+
protection_domain_init(&identity_domain, NUMA_NO_NODE);
2499+
}
2500+
24742501
static int amd_iommu_attach_device(struct iommu_domain *dom,
24752502
struct device *dev)
24762503
{
@@ -2869,6 +2896,7 @@ static int amd_iommu_dev_disable_feature(struct device *dev,
28692896
const struct iommu_ops amd_iommu_ops = {
28702897
.capable = amd_iommu_capable,
28712898
.blocked_domain = &blocked_domain,
2899+
.identity_domain = &identity_domain.domain,
28722900
.domain_alloc = amd_iommu_domain_alloc,
28732901
.domain_alloc_user = amd_iommu_domain_alloc_user,
28742902
.domain_alloc_sva = amd_iommu_domain_alloc_sva,

0 commit comments

Comments
 (0)