Skip to content

Commit 35a99c5

Browse files
LuBaolujoergroedel
authored andcommitted
iommu/vt-d: Add blocking domain support
The Intel IOMMU hardwares support blocking DMA transactions by clearing the translation table entries. This implements a real blocking domain to avoid using an empty UNMANAGED domain. The detach_dev callback of the domain ops is not used in any path. Remove it to avoid dead code as well. Signed-off-by: Lu Baolu <[email protected]> Reviewed-by: Kevin Tian <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Joerg Roedel <[email protected]>
1 parent c7be17c commit 35a99c5

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

drivers/iommu/intel/iommu.c

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ static LIST_HEAD(dmar_satc_units);
278278
list_for_each_entry(rmrr, &dmar_rmrr_units, list)
279279

280280
static void device_block_translation(struct device *dev);
281+
static void intel_iommu_domain_free(struct iommu_domain *domain);
281282

282283
int dmar_disabled = !IS_ENABLED(CONFIG_INTEL_IOMMU_DEFAULT_ON);
283284
int intel_iommu_sm = IS_ENABLED(CONFIG_INTEL_IOMMU_SCALABLE_MODE_DEFAULT_ON);
@@ -4162,12 +4163,28 @@ static int md_domain_init(struct dmar_domain *domain, int guest_width)
41624163
return 0;
41634164
}
41644165

4166+
static int blocking_domain_attach_dev(struct iommu_domain *domain,
4167+
struct device *dev)
4168+
{
4169+
device_block_translation(dev);
4170+
return 0;
4171+
}
4172+
4173+
static struct iommu_domain blocking_domain = {
4174+
.ops = &(const struct iommu_domain_ops) {
4175+
.attach_dev = blocking_domain_attach_dev,
4176+
.free = intel_iommu_domain_free
4177+
}
4178+
};
4179+
41654180
static struct iommu_domain *intel_iommu_domain_alloc(unsigned type)
41664181
{
41674182
struct dmar_domain *dmar_domain;
41684183
struct iommu_domain *domain;
41694184

41704185
switch (type) {
4186+
case IOMMU_DOMAIN_BLOCKED:
4187+
return &blocking_domain;
41714188
case IOMMU_DOMAIN_DMA:
41724189
case IOMMU_DOMAIN_DMA_FQ:
41734190
case IOMMU_DOMAIN_UNMANAGED:
@@ -4200,7 +4217,7 @@ static struct iommu_domain *intel_iommu_domain_alloc(unsigned type)
42004217

42014218
static void intel_iommu_domain_free(struct iommu_domain *domain)
42024219
{
4203-
if (domain != &si_domain->domain)
4220+
if (domain != &si_domain->domain && domain != &blocking_domain)
42044221
domain_exit(to_dmar_domain(domain));
42054222
}
42064223

@@ -4274,12 +4291,6 @@ static int intel_iommu_attach_device(struct iommu_domain *domain,
42744291
return domain_add_dev_info(to_dmar_domain(domain), dev);
42754292
}
42764293

4277-
static void intel_iommu_detach_device(struct iommu_domain *domain,
4278-
struct device *dev)
4279-
{
4280-
dmar_remove_one_dev_info(dev);
4281-
}
4282-
42834294
static int intel_iommu_map(struct iommu_domain *domain,
42844295
unsigned long iova, phys_addr_t hpa,
42854296
size_t size, int iommu_prot, gfp_t gfp)
@@ -4767,7 +4778,6 @@ const struct iommu_ops intel_iommu_ops = {
47674778
#endif
47684779
.default_domain_ops = &(const struct iommu_domain_ops) {
47694780
.attach_dev = intel_iommu_attach_device,
4770-
.detach_dev = intel_iommu_detach_device,
47714781
.map_pages = intel_iommu_map_pages,
47724782
.unmap_pages = intel_iommu_unmap_pages,
47734783
.iotlb_sync_map = intel_iommu_iotlb_sync_map,

0 commit comments

Comments
 (0)