Skip to content

Commit e85bb99

Browse files
LuBaolujoergroedel
authored andcommitted
iommu/vt-d: Add get_domain_info() helper
Add a get_domain_info() helper to retrieve the valid per-device iommu private data. Signed-off-by: Lu Baolu <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Joerg Roedel <[email protected]>
1 parent 3375303 commit e85bb99

File tree

4 files changed

+35
-20
lines changed

4 files changed

+35
-20
lines changed

drivers/iommu/intel-iommu.c

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,21 @@ EXPORT_SYMBOL_GPL(intel_iommu_gfx_mapped);
365365

366366
#define DUMMY_DEVICE_DOMAIN_INFO ((struct device_domain_info *)(-1))
367367
#define DEFER_DEVICE_DOMAIN_INFO ((struct device_domain_info *)(-2))
368+
struct device_domain_info *get_domain_info(struct device *dev)
369+
{
370+
struct device_domain_info *info;
371+
372+
if (!dev)
373+
return NULL;
374+
375+
info = dev->archdata.iommu;
376+
if (unlikely(info == DUMMY_DEVICE_DOMAIN_INFO ||
377+
info == DEFER_DEVICE_DOMAIN_INFO))
378+
return NULL;
379+
380+
return info;
381+
}
382+
368383
DEFINE_SPINLOCK(device_domain_lock);
369384
static LIST_HEAD(device_domain_list);
370385

@@ -2429,7 +2444,7 @@ struct dmar_domain *find_domain(struct device *dev)
24292444
dev = &pci_real_dma_dev(to_pci_dev(dev))->dev;
24302445

24312446
/* No lock here, assumes no domain exit in normal case */
2432-
info = dev->archdata.iommu;
2447+
info = get_domain_info(dev);
24332448
if (likely(info))
24342449
return info->domain;
24352450

@@ -5012,9 +5027,8 @@ static void dmar_remove_one_dev_info(struct device *dev)
50125027
unsigned long flags;
50135028

50145029
spin_lock_irqsave(&device_domain_lock, flags);
5015-
info = dev->archdata.iommu;
5016-
if (info && info != DEFER_DEVICE_DOMAIN_INFO
5017-
&& info != DUMMY_DEVICE_DOMAIN_INFO)
5030+
info = get_domain_info(dev);
5031+
if (info)
50185032
__dmar_remove_one_dev_info(info);
50195033
spin_unlock_irqrestore(&device_domain_lock, flags);
50205034
}
@@ -5104,7 +5118,7 @@ static void intel_iommu_domain_free(struct iommu_domain *domain)
51045118
static inline bool
51055119
is_aux_domain(struct device *dev, struct iommu_domain *domain)
51065120
{
5107-
struct device_domain_info *info = dev->archdata.iommu;
5121+
struct device_domain_info *info = get_domain_info(dev);
51085122

51095123
return info && info->auxd_enabled &&
51105124
domain->type == IOMMU_DOMAIN_UNMANAGED;
@@ -5113,7 +5127,7 @@ is_aux_domain(struct device *dev, struct iommu_domain *domain)
51135127
static void auxiliary_link_device(struct dmar_domain *domain,
51145128
struct device *dev)
51155129
{
5116-
struct device_domain_info *info = dev->archdata.iommu;
5130+
struct device_domain_info *info = get_domain_info(dev);
51175131

51185132
assert_spin_locked(&device_domain_lock);
51195133
if (WARN_ON(!info))
@@ -5126,7 +5140,7 @@ static void auxiliary_link_device(struct dmar_domain *domain,
51265140
static void auxiliary_unlink_device(struct dmar_domain *domain,
51275141
struct device *dev)
51285142
{
5129-
struct device_domain_info *info = dev->archdata.iommu;
5143+
struct device_domain_info *info = get_domain_info(dev);
51305144

51315145
assert_spin_locked(&device_domain_lock);
51325146
if (WARN_ON(!info))
@@ -5214,7 +5228,7 @@ static void aux_domain_remove_dev(struct dmar_domain *domain,
52145228
return;
52155229

52165230
spin_lock_irqsave(&device_domain_lock, flags);
5217-
info = dev->archdata.iommu;
5231+
info = get_domain_info(dev);
52185232
iommu = info->iommu;
52195233

52205234
auxiliary_unlink_device(domain, dev);
@@ -5404,7 +5418,7 @@ intel_iommu_sva_invalidate(struct iommu_domain *domain, struct device *dev,
54045418

54055419
spin_lock_irqsave(&device_domain_lock, flags);
54065420
spin_lock(&iommu->lock);
5407-
info = dev->archdata.iommu;
5421+
info = get_domain_info(dev);
54085422
if (!info) {
54095423
ret = -EINVAL;
54105424
goto out_unlock;
@@ -5768,7 +5782,7 @@ int intel_iommu_enable_pasid(struct intel_iommu *iommu, struct device *dev)
57685782
spin_lock(&iommu->lock);
57695783

57705784
ret = -EINVAL;
5771-
info = dev->archdata.iommu;
5785+
info = get_domain_info(dev);
57725786
if (!info || !info->pasid_supported)
57735787
goto out;
57745788

@@ -5864,7 +5878,7 @@ static int intel_iommu_enable_auxd(struct device *dev)
58645878
return -ENODEV;
58655879

58665880
spin_lock_irqsave(&device_domain_lock, flags);
5867-
info = dev->archdata.iommu;
5881+
info = get_domain_info(dev);
58685882
info->auxd_enabled = 1;
58695883
spin_unlock_irqrestore(&device_domain_lock, flags);
58705884

@@ -5877,7 +5891,7 @@ static int intel_iommu_disable_auxd(struct device *dev)
58775891
unsigned long flags;
58785892

58795893
spin_lock_irqsave(&device_domain_lock, flags);
5880-
info = dev->archdata.iommu;
5894+
info = get_domain_info(dev);
58815895
if (!WARN_ON(!info))
58825896
info->auxd_enabled = 0;
58835897
spin_unlock_irqrestore(&device_domain_lock, flags);
@@ -5954,7 +5968,7 @@ intel_iommu_dev_disable_feat(struct device *dev, enum iommu_dev_features feat)
59545968
static bool
59555969
intel_iommu_dev_feat_enabled(struct device *dev, enum iommu_dev_features feat)
59565970
{
5957-
struct device_domain_info *info = dev->archdata.iommu;
5971+
struct device_domain_info *info = get_domain_info(dev);
59585972

59595973
if (feat == IOMMU_DEV_FEAT_AUX)
59605974
return scalable_mode_support() && info && info->auxd_enabled;

drivers/iommu/intel-pasid.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ int intel_pasid_alloc_table(struct device *dev)
151151
int size;
152152

153153
might_sleep();
154-
info = dev->archdata.iommu;
154+
info = get_domain_info(dev);
155155
if (WARN_ON(!info || !dev_is_pci(dev) || info->pasid_table))
156156
return -EINVAL;
157157

@@ -198,7 +198,7 @@ void intel_pasid_free_table(struct device *dev)
198198
struct pasid_entry *table;
199199
int i, max_pde;
200200

201-
info = dev->archdata.iommu;
201+
info = get_domain_info(dev);
202202
if (!info || !dev_is_pci(dev) || !info->pasid_table)
203203
return;
204204

@@ -224,7 +224,7 @@ struct pasid_table *intel_pasid_get_table(struct device *dev)
224224
{
225225
struct device_domain_info *info;
226226

227-
info = dev->archdata.iommu;
227+
info = get_domain_info(dev);
228228
if (!info)
229229
return NULL;
230230

@@ -235,7 +235,7 @@ int intel_pasid_get_dev_max_id(struct device *dev)
235235
{
236236
struct device_domain_info *info;
237237

238-
info = dev->archdata.iommu;
238+
info = get_domain_info(dev);
239239
if (!info || !info->pasid_table)
240240
return 0;
241241

@@ -256,7 +256,7 @@ struct pasid_entry *intel_pasid_get_entry(struct device *dev, int pasid)
256256
return NULL;
257257

258258
dir = pasid_table->table;
259-
info = dev->archdata.iommu;
259+
info = get_domain_info(dev);
260260
dir_index = pasid >> PASID_PDE_SHIFT;
261261
index = pasid & PASID_PTE_MASK;
262262

@@ -462,7 +462,7 @@ devtlb_invalidation_with_pasid(struct intel_iommu *iommu,
462462
struct device_domain_info *info;
463463
u16 sid, qdep, pfsid;
464464

465-
info = dev->archdata.iommu;
465+
info = get_domain_info(dev);
466466
if (!info || !info->ats_enabled)
467467
return;
468468

drivers/iommu/intel-svm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ int intel_svm_bind_mm(struct device *dev, int *pasid, int flags, struct svm_dev_
503503
goto out;
504504
}
505505

506-
info = dev->archdata.iommu;
506+
info = get_domain_info(dev);
507507
if (!info || !info->pasid_supported) {
508508
kfree(sdev);
509509
goto out;

include/linux/intel-iommu.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -714,6 +714,7 @@ int for_each_device_domain(int (*fn)(struct device_domain_info *info,
714714
void iommu_flush_write_buffer(struct intel_iommu *iommu);
715715
int intel_iommu_enable_pasid(struct intel_iommu *iommu, struct device *dev);
716716
struct dmar_domain *find_domain(struct device *dev);
717+
struct device_domain_info *get_domain_info(struct device *dev);
717718

718719
#ifdef CONFIG_INTEL_IOMMU_SVM
719720
extern void intel_svm_check(struct intel_iommu *iommu);

0 commit comments

Comments
 (0)