[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20240628-jag-revisit_cache_tag_assign-v1-2-a0c19063c983@samsung.com>
Date: Fri, 28 Jun 2024 14:27:40 +0200
From: Joel Granados via B4 Relay <devnull+j.granados.samsung.com@...nel.org>
To: David Woodhouse <dwmw2@...radead.org>,
Lu Baolu <baolu.lu@...ux.intel.com>, Joerg Roedel <joro@...tes.org>,
Will Deacon <will@...nel.org>, Robin Murphy <robin.murphy@....com>
Cc: iommu@...ts.linux.dev, linux-kernel@...r.kernel.org,
Joel Granados <j.granados@...sung.com>
Subject: [PATCH RFC 2/5] iommu/vt-d: Replace cache_tag_match with a tag
comparison function
From: Joel Granados <j.granados@...sung.com>
Refactor cache_tag_match into a comparison of cache_tag_id. This
clarifies the usage of the function.
Signed-off-by: Joel Granados <j.granados@...sung.com>
---
drivers/iommu/intel/cache.c | 40 ++++++++++++++++++++++++++--------------
1 file changed, 26 insertions(+), 14 deletions(-)
diff --git a/drivers/iommu/intel/cache.c b/drivers/iommu/intel/cache.c
index aa8a463b1251..b50ec5520871 100644
--- a/drivers/iommu/intel/cache.c
+++ b/drivers/iommu/intel/cache.c
@@ -19,22 +19,20 @@
#include "pasid.h"
#include "trace.h"
-/* Check if an existing cache tag can be reused for a new association. */
-static bool cache_tage_match(struct cache_tag *tag, u16 domain_id,
- struct intel_iommu *iommu, struct device *dev,
- ioasid_t pasid, enum cache_tag_type type)
+static bool cache_tag_cmp(const struct cache_tag_id *left,
+ const struct cache_tag_id *right)
{
- if (tag->id.type != type)
+ if (left->type != right->type)
return false;
- if (tag->id.domain_id != domain_id || tag->id.pasid != pasid)
+ if (left->domain_id != right->domain_id || left->pasid != right->pasid)
return false;
- if (type == CACHE_TAG_IOTLB || type == CACHE_TAG_NESTING_IOTLB)
- return tag->id.iommu == iommu;
+ if (left->type == CACHE_TAG_DEVTLB || left->type == CACHE_TAG_NESTING_DEVTLB)
+ return left->dev == right->dev;
- if (type == CACHE_TAG_DEVTLB || type == CACHE_TAG_NESTING_DEVTLB)
- return tag->id.dev == dev;
+ if (left->type == CACHE_TAG_IOTLB || left->type == CACHE_TAG_NESTING_IOTLB)
+ return left->iommu == right->iommu;
return false;
}
@@ -48,6 +46,13 @@ static int cache_tag_assign(struct dmar_domain *domain, u16 did,
struct intel_iommu *iommu = info->iommu;
struct cache_tag *tag, *temp;
unsigned long flags;
+ struct cache_tag_id cmp_tag = {
+ .type = type,
+ .pasid = pasid,
+ .iommu = info->iommu,
+ .dev = dev,
+ .domain_id = did
+ };
tag = kzalloc(sizeof(*tag), GFP_KERNEL);
if (!tag)
@@ -66,7 +71,7 @@ static int cache_tag_assign(struct dmar_domain *domain, u16 did,
spin_lock_irqsave(&domain->cache_lock, flags);
list_for_each_entry(temp, &domain->cache_tags, node) {
- if (cache_tage_match(temp, did, iommu, dev, pasid, type)) {
+ if (cache_tag_cmp(&temp->id, &cmp_tag)) {
temp->users++;
spin_unlock_irqrestore(&domain->cache_lock, flags);
kfree(tag);
@@ -86,14 +91,21 @@ static void cache_tag_unassign(struct dmar_domain *domain, u16 did,
struct device *dev, ioasid_t pasid,
enum cache_tag_type type)
{
- struct device_domain_info *info = dev_iommu_priv_get(dev);
- struct intel_iommu *iommu = info->iommu;
struct cache_tag *tag;
unsigned long flags;
+ struct device_domain_info *info = dev_iommu_priv_get(dev);
+ struct cache_tag_id cmp_tag = {
+ .type = type,
+ .pasid = pasid,
+ .iommu = info->iommu,
+ .dev = dev,
+ .domain_id = did
+ };
+
spin_lock_irqsave(&domain->cache_lock, flags);
list_for_each_entry(tag, &domain->cache_tags, node) {
- if (cache_tage_match(tag, did, iommu, dev, pasid, type)) {
+ if (cache_tag_cmp(&tag->id, &cmp_tag)) {
trace_cache_tag_unassign(tag);
if (--tag->users == 0) {
list_del(&tag->node);
--
2.43.0
Powered by blists - more mailing lists