Skip to content

Commit e5e5cc8

Browse files
hegdevasantjoergroedel
authored andcommitted
iommu/amd: Add blocked domain support
Create global blocked domain with attach device ops. It will clear the DTE so that all DMA from device will be aborted. Signed-off-by: Vasant Hegde <[email protected]> Reviewed-by: Suravee Suthikulpanit <[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 7c626ce commit e5e5cc8

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

drivers/iommu/amd/iommu.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2462,6 +2462,29 @@ void amd_iommu_domain_free(struct iommu_domain *dom)
24622462
protection_domain_free(domain);
24632463
}
24642464

2465+
static int blocked_domain_attach_device(struct iommu_domain *domain,
2466+
struct device *dev)
2467+
{
2468+
struct iommu_dev_data *dev_data = dev_iommu_priv_get(dev);
2469+
2470+
if (dev_data->domain)
2471+
detach_device(dev);
2472+
2473+
/* Clear DTE and flush the entry */
2474+
spin_lock(&dev_data->lock);
2475+
amd_iommu_dev_update_dte(dev_data, false);
2476+
spin_unlock(&dev_data->lock);
2477+
2478+
return 0;
2479+
}
2480+
2481+
static struct iommu_domain blocked_domain = {
2482+
.type = IOMMU_DOMAIN_BLOCKED,
2483+
.ops = &(const struct iommu_domain_ops) {
2484+
.attach_dev = blocked_domain_attach_device,
2485+
}
2486+
};
2487+
24652488
static int amd_iommu_attach_device(struct iommu_domain *dom,
24662489
struct device *dev)
24672490
{
@@ -2859,6 +2882,7 @@ static int amd_iommu_dev_disable_feature(struct device *dev,
28592882

28602883
const struct iommu_ops amd_iommu_ops = {
28612884
.capable = amd_iommu_capable,
2885+
.blocked_domain = &blocked_domain,
28622886
.domain_alloc = amd_iommu_domain_alloc,
28632887
.domain_alloc_user = amd_iommu_domain_alloc_user,
28642888
.domain_alloc_sva = amd_iommu_domain_alloc_sva,

0 commit comments

Comments
 (0)