From nobody Sun Dec 14 12:17:56 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6C5B515886C; Fri, 28 Jun 2024 12:27:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719577668; cv=none; b=pFOfT5Pe4nzE59dWq3IIhProVomUT1ioDX9cBiX6WYkcdkGE1YV49g3NX4vVUsRAZZsTHm1BsmK30s9A09AJXUfdE/TNo45WWbaOrOLwDOSOb9Q0yL+SEGeQhaN98jByoIMhNoYMvyc88JcomgoXvNHlX1wA7XuZUhyWXNNH5cE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719577668; c=relaxed/simple; bh=qJ67/bAXQ32MZFRQ2Q6zPEG3W92JXa5lRpboUiFbg1M=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=su7+TSqlYpuEIAyAl4RSpOA4lCPZ9qxpaQCoPxPHpE9G7BID0HoKWHPy2g7nS+alhUxUAFQdyH9qHT6j3fvzYD9ZSUCuJnaPvLPEq2njvm6T1kR0JG0DlU6zZsG46lzq5kfaQKxDJFT9zUp2QqWaXqLxPoZB5lt296xgmOoyigc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Oj2QBIjH; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Oj2QBIjH" Received: by smtp.kernel.org (Postfix) with ESMTPS id 44E92C32781; Fri, 28 Jun 2024 12:27:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1719577668; bh=qJ67/bAXQ32MZFRQ2Q6zPEG3W92JXa5lRpboUiFbg1M=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=Oj2QBIjHVBM4ptzAjkQCkou5lYmv5XDUmGagXZJDnayai5hoaxoquslYcCMeHtcM6 rMS5yYAb6gZ9a2iAlh0qHxeZ1S/iCrNgZpfgxEH2G1Jj1/horA5prhqocU1Qo3wH0t p0GbB+q6cda7/lK8VteJS4nMzZNxlf26X+kSlibN9sks4blRvWi4yF+h6VeLalhO9I YMtLcgQkX8m7QDUEayvWaPooYoQ/1yNS6Dx2Z/iXgwM1d51MWygTmMsT1qNu+ISrXi j134XvX0p6SsQJOCER2JciJrxtKjPEAHt+b94fCkRHrbqZzPtWfbZqZ8rOBXrl9Zjt wVM2dbW6MqiLQ== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 32D22C30658; Fri, 28 Jun 2024 12:27:48 +0000 (UTC) From: Joel Granados via B4 Relay Date: Fri, 28 Jun 2024 14:27:39 +0200 Subject: [PATCH RFC 1/5] iommu/vt-d: introduce cache_tag_id to the struct cache_tag Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240628-jag-revisit_cache_tag_assign-v1-1-a0c19063c983@samsung.com> References: <20240628-jag-revisit_cache_tag_assign-v1-0-a0c19063c983@samsung.com> In-Reply-To: <20240628-jag-revisit_cache_tag_assign-v1-0-a0c19063c983@samsung.com> To: David Woodhouse , Lu Baolu , Joerg Roedel , Will Deacon , Robin Murphy Cc: iommu@lists.linux.dev, linux-kernel@vger.kernel.org, Joel Granados X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=7371; i=j.granados@samsung.com; h=from:subject:message-id; bh=CeIl/+AGdknk3OAv3towgvKASz6XQ7Rq3zYF0Ui/bu4=; b=owJ4nAHtARL+kA0DAAoBupfNUreWQU8ByyZiAGZ+rDznM+jfL/TdhJL5yghg71UR9YBVUiO6F 6f1QRESv0e3HokBswQAAQoAHRYhBK5HCVcl5jElzssnkLqXzVK3lkFPBQJmfqw8AAoJELqXzVK3 lkFPUFAMAIchaETns9jmFV4Hz8ihPEvob+O5EvOqoCRt3PXdavH5jyjxG+T448FeuZAaO8SHnnq kX+tHEv1wcs7cR9ZFA6WgZNErkmjEr4VCw3k9AgkUVlIsaBw6U/XPd9nV2IVmtjyPvYHTe2qSFI wiXz+00EAn/LAN3PjhNyZjxue5hrTneYYar6YXtf+N2VvDuQw8Xh8tEU3wBb3JFJapbDtUIS0vT QJdOf6qyh8HAgVTbAkLUJkbj4KqxkY4DvxKDowMPTfs5ybC8b7kmB+jQJ482p6N7hulCFUFzRq+ h0nACrNGVv1ecncwyh9w8iFyur55X3QcmULAkbVPLmNMc0nwrRdHcc1QrEhuIP+jWmQCP0ezZkT kio8bUwEATyomhXGuD512iElU8YA1idswEdL6tX9Xf7EOl8KvT6FOug/sgAdX6pzZMz52ekUGWu glIxF7ZTO24XW4t8QQmwsO3Fq3JHoHjoD76oLyuwjWN1a7SZ3eF6b7OwQe9iaheSrkNobVqkEO4 h4= X-Developer-Key: i=j.granados@samsung.com; a=openpgp; fpr=F1F8E46D30F0F6C4A45FF4465895FAAC338C6E77 X-Endpoint-Received: by B4 Relay for j.granados@samsung.com/default with auth_id=70 X-Original-From: Joel Granados Reply-To: j.granados@samsung.com From: Joel Granados Introduce a cache_tag_id so it can be used separately from list and user counters. Signed-off-by: Joel Granados --- drivers/iommu/intel/cache.c | 62 ++++++++++++++++++++++-------------------= ---- drivers/iommu/intel/iommu.h | 24 ++++++++++-------- 2 files changed, 44 insertions(+), 42 deletions(-) diff --git a/drivers/iommu/intel/cache.c b/drivers/iommu/intel/cache.c index e8418cdd8331..aa8a463b1251 100644 --- a/drivers/iommu/intel/cache.c +++ b/drivers/iommu/intel/cache.c @@ -24,17 +24,17 @@ 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) { - if (tag->type !=3D type) + if (tag->id.type !=3D type) return false; =20 - if (tag->domain_id !=3D domain_id || tag->pasid !=3D pasid) + if (tag->id.domain_id !=3D domain_id || tag->id.pasid !=3D pasid) return false; =20 if (type =3D=3D CACHE_TAG_IOTLB || type =3D=3D CACHE_TAG_NESTING_IOTLB) - return tag->iommu =3D=3D iommu; + return tag->id.iommu =3D=3D iommu; =20 if (type =3D=3D CACHE_TAG_DEVTLB || type =3D=3D CACHE_TAG_NESTING_DEVTLB) - return tag->dev =3D=3D dev; + return tag->id.dev =3D=3D dev; =20 return false; } @@ -53,16 +53,16 @@ static int cache_tag_assign(struct dmar_domain *domain,= u16 did, if (!tag) return -ENOMEM; =20 - tag->type =3D type; - tag->iommu =3D iommu; - tag->domain_id =3D did; - tag->pasid =3D pasid; + tag->id.type =3D type; + tag->id.iommu =3D iommu; + tag->id.domain_id =3D did; + tag->id.pasid =3D pasid; tag->users =3D 1; =20 if (type =3D=3D CACHE_TAG_DEVTLB || type =3D=3D CACHE_TAG_NESTING_DEVTLB) - tag->dev =3D dev; + tag->id.dev =3D dev; else - tag->dev =3D iommu->iommu.dev; + tag->id.dev =3D iommu->iommu.dev; =20 spin_lock_irqsave(&domain->cache_lock, flags); list_for_each_entry(temp, &domain->cache_tags, node) { @@ -269,16 +269,16 @@ void cache_tag_flush_range(struct dmar_domain *domain= , unsigned long start, =20 spin_lock_irqsave(&domain->cache_lock, flags); list_for_each_entry(tag, &domain->cache_tags, node) { - struct intel_iommu *iommu =3D tag->iommu; + struct intel_iommu *iommu =3D tag->id.iommu; struct device_domain_info *info; u16 sid; =20 - switch (tag->type) { + switch (tag->id.type) { case CACHE_TAG_IOTLB: case CACHE_TAG_NESTING_IOTLB: if (domain->use_first_level) { - qi_flush_piotlb(iommu, tag->domain_id, - tag->pasid, addr, pages, ih); + qi_flush_piotlb(iommu, tag->id.domain_id, + tag->id.pasid, addr, pages, ih); } else { /* * Fallback to domain selective flush if no @@ -286,10 +286,10 @@ void cache_tag_flush_range(struct dmar_domain *domain= , unsigned long start, */ if (!cap_pgsel_inv(iommu->cap) || mask > cap_max_amask_val(iommu->cap)) - iommu->flush.flush_iotlb(iommu, tag->domain_id, + iommu->flush.flush_iotlb(iommu, tag->id.domain_id, 0, 0, DMA_TLB_DSI_FLUSH); else - iommu->flush.flush_iotlb(iommu, tag->domain_id, + iommu->flush.flush_iotlb(iommu, tag->id.domain_id, addr | ih, mask, DMA_TLB_PSI_FLUSH); } @@ -306,18 +306,18 @@ void cache_tag_flush_range(struct dmar_domain *domain= , unsigned long start, mask =3D MAX_AGAW_PFN_WIDTH; fallthrough; case CACHE_TAG_DEVTLB: - info =3D dev_iommu_priv_get(tag->dev); + info =3D dev_iommu_priv_get(tag->id.dev); sid =3D PCI_DEVID(info->bus, info->devfn); =20 - if (tag->pasid =3D=3D IOMMU_NO_PASID) + if (tag->id.pasid =3D=3D IOMMU_NO_PASID) qi_flush_dev_iotlb(iommu, sid, info->pfsid, info->ats_qdep, addr, mask); else qi_flush_dev_iotlb_pasid(iommu, sid, info->pfsid, - tag->pasid, info->ats_qdep, + tag->id.pasid, info->ats_qdep, addr, mask); =20 - quirk_extra_dev_tlb_flush(info, addr, mask, tag->pasid, info->ats_qdep); + quirk_extra_dev_tlb_flush(info, addr, mask, tag->id.pasid, info->ats_qd= ep); break; } =20 @@ -337,23 +337,23 @@ void cache_tag_flush_all(struct dmar_domain *domain) =20 spin_lock_irqsave(&domain->cache_lock, flags); list_for_each_entry(tag, &domain->cache_tags, node) { - struct intel_iommu *iommu =3D tag->iommu; + struct intel_iommu *iommu =3D tag->id.iommu; struct device_domain_info *info; u16 sid; =20 - switch (tag->type) { + switch (tag->id.type) { case CACHE_TAG_IOTLB: case CACHE_TAG_NESTING_IOTLB: if (domain->use_first_level) - qi_flush_piotlb(iommu, tag->domain_id, - tag->pasid, 0, -1, 0); + qi_flush_piotlb(iommu, tag->id.domain_id, + tag->id.pasid, 0, -1, 0); else - iommu->flush.flush_iotlb(iommu, tag->domain_id, + iommu->flush.flush_iotlb(iommu, tag->id.domain_id, 0, 0, DMA_TLB_DSI_FLUSH); break; case CACHE_TAG_DEVTLB: case CACHE_TAG_NESTING_DEVTLB: - info =3D dev_iommu_priv_get(tag->dev); + info =3D dev_iommu_priv_get(tag->id.dev); sid =3D PCI_DEVID(info->bus, info->devfn); =20 qi_flush_dev_iotlb(iommu, sid, info->pfsid, info->ats_qdep, @@ -390,25 +390,25 @@ void cache_tag_flush_range_np(struct dmar_domain *dom= ain, unsigned long start, =20 spin_lock_irqsave(&domain->cache_lock, flags); list_for_each_entry(tag, &domain->cache_tags, node) { - struct intel_iommu *iommu =3D tag->iommu; + struct intel_iommu *iommu =3D tag->id.iommu; =20 if (!cap_caching_mode(iommu->cap) || domain->use_first_level) { iommu_flush_write_buffer(iommu); continue; } =20 - if (tag->type =3D=3D CACHE_TAG_IOTLB || - tag->type =3D=3D CACHE_TAG_NESTING_IOTLB) { + if (tag->id.type =3D=3D CACHE_TAG_IOTLB || + tag->id.type =3D=3D CACHE_TAG_NESTING_IOTLB) { /* * Fallback to domain selective flush if no * PSI support or the size is too big. */ if (!cap_pgsel_inv(iommu->cap) || mask > cap_max_amask_val(iommu->cap)) - iommu->flush.flush_iotlb(iommu, tag->domain_id, + iommu->flush.flush_iotlb(iommu, tag->id.domain_id, 0, 0, DMA_TLB_DSI_FLUSH); else - iommu->flush.flush_iotlb(iommu, tag->domain_id, + iommu->flush.flush_iotlb(iommu, tag->id.domain_id, addr, mask, DMA_TLB_PSI_FLUSH); } diff --git a/drivers/iommu/intel/iommu.h b/drivers/iommu/intel/iommu.h index eaf015b4353b..cc8c9130e177 100644 --- a/drivers/iommu/intel/iommu.h +++ b/drivers/iommu/intel/iommu.h @@ -1121,17 +1121,19 @@ enum cache_tag_type { =20 struct cache_tag { struct list_head node; - enum cache_tag_type type; - struct intel_iommu *iommu; - /* - * The @dev field represents the location of the cache. For IOTLB, it - * resides on the IOMMU hardware. @dev stores the device pointer to - * the IOMMU hardware. For DevTLB, it locates in the PCIe endpoint. - * @dev stores the device pointer to that endpoint. - */ - struct device *dev; - u16 domain_id; - ioasid_t pasid; + struct cache_tag_id { + enum cache_tag_type type; + ioasid_t pasid; + struct intel_iommu *iommu; + /* + * The @dev field represents the location of the cache. For IOTLB, it + * resides on the IOMMU hardware. @dev stores the device pointer to + * the IOMMU hardware. For DevTLB, it locates in the PCIe endpoint. + * @dev stores the device pointer to that endpoint. + */ + struct device *dev; + u16 domain_id; + } id; unsigned int users; }; =20 --=20 2.43.0 From nobody Sun Dec 14 12:17:56 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A15AF158879; Fri, 28 Jun 2024 12:27:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719577668; cv=none; b=bh/JW6vg9xhGeWxvIbLgHWYJujYR51pbLXpF4urj6hXmWKdKL+RZibUoLig7iL7tdUOCPQwC5hNyjUdqly/sgWE7g0ia/yWLutROYzdw40DFQgKmy/wg6Ybm6HpQ6YVPMqKNPYgBsf7d227D6L35PyfOouUjPw55KuQSN2sLoY0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719577668; c=relaxed/simple; bh=EowXbq+3GcSwnDqZA0ItT17PGnvphPglRVy1uSDu0A4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=aB1h5iavz5NPZ+uLLo9v6tLWZY0NTPEvQg/QqqX0Ukucc2UKJofcQ8bw7xN2NlxgYw0XyadWbmNrYJQJ1xZmvOQhi4Anfd0yHABfJICRgqk2+9KBTnsuVeImBBR+VfX/6srh8ld7/I8TTVP+KFTzELhkrZ3/Ot2nk2J0BGI9xpQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=tf6q4bGe; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="tf6q4bGe" Received: by smtp.kernel.org (Postfix) with ESMTPS id 538D7C2BBFC; Fri, 28 Jun 2024 12:27:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1719577668; bh=EowXbq+3GcSwnDqZA0ItT17PGnvphPglRVy1uSDu0A4=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=tf6q4bGeBsyqG0TS3Li3X2poALFPaAnEzXqht8SEKsDgyhNVVvvAVSJte/SybT6W2 /I9stlCzOnb6T++otg2t7xz2N+TlZbhy4UocvVB1JvO8h+v/5KIZioo2O+GC/ucK45 CjJkh74/6h0wrG077tuld7gDldNvVYwhYvKayj5XXGt2DQ/bRcQOlYiuJgrd6OhPM0 vVulvxpmTWB4EgQ6M3tQkwBYy9IjtteyJzOqMEQWeI0bMAAMaaXbg0iLPfgQxzK3PZ hTqeBCpdc6eP9oSOvxdrwklfuDo+RKHtUL9//f9iTPceG1Y3gHriF99aVZFCAkVGxV G6j32jOrKNN7g== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 42A97C3065B; Fri, 28 Jun 2024 12:27:48 +0000 (UTC) From: Joel Granados via B4 Relay Date: Fri, 28 Jun 2024 14:27:40 +0200 Subject: [PATCH RFC 2/5] iommu/vt-d: Replace cache_tag_match with a tag comparison function Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240628-jag-revisit_cache_tag_assign-v1-2-a0c19063c983@samsung.com> References: <20240628-jag-revisit_cache_tag_assign-v1-0-a0c19063c983@samsung.com> In-Reply-To: <20240628-jag-revisit_cache_tag_assign-v1-0-a0c19063c983@samsung.com> To: David Woodhouse , Lu Baolu , Joerg Roedel , Will Deacon , Robin Murphy Cc: iommu@lists.linux.dev, linux-kernel@vger.kernel.org, Joel Granados X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3271; i=j.granados@samsung.com; h=from:subject:message-id; bh=JWe71x3QOlu5j4Wh0iPnW/XbH7HpQb7ccgT4S59ce+c=; b=owJ4nAHtARL+kA0DAAoBupfNUreWQU8ByyZiAGZ+rD0hWBNGYZ1/T161VVajrGE3mBMB88ZcK UVJW+ZAJcusFIkBswQAAQoAHRYhBK5HCVcl5jElzssnkLqXzVK3lkFPBQJmfqw9AAoJELqXzVK3 lkFP3xYL/At0MpQQ3WxWHg2BaBN2WTbirowQaNWk+Rf2ua5BecgxmTIWu2UgzrvkwqYUin+JLxz BrgGngxceL0wP+bnLqW6aFGq0vWXBftXiWp9vYx7OdLQFI5fIA4NyyhtXJSkmXzLFW2CCXEHeom BivKJFt/UEhcC1uZ05/OJ50tMjgw26mPq2bvjy7a02DNcPiARx0oDS5Rrj0YGfrPbcSxswqLo4/ tYpvgMwfmqtxyu/VdMdWLVbiwSXctF6IHbl1rplpurwMigB5Ha8XNIhxrxI0zt9mUPsPpSgo46s vzPO/2fjiaBiTiro6Xt31Sb+23IRjdPCQK0Xy7TCTRGKBD/4anclveoSK4MqHkAN39EXvIoWB6S kciNq9Ubo95B9Fwc15bRv158kx6uA54ynxaR3LYeDMJB5Zt2QuP/FZX2JRw1qRddn+Vs/JpFyJI VrWdmOcfs4kyLSp0hTjzRhIWENCikefQd1x74LYKX3V5+Wn9F+ievwClzlgyhbFiZHYPkf+ygR5 yw= X-Developer-Key: i=j.granados@samsung.com; a=openpgp; fpr=F1F8E46D30F0F6C4A45FF4465895FAAC338C6E77 X-Endpoint-Received: by B4 Relay for j.granados@samsung.com/default with auth_id=70 X-Original-From: Joel Granados Reply-To: j.granados@samsung.com From: Joel Granados Refactor cache_tag_match into a comparison of cache_tag_id. This clarifies the usage of the function. Signed-off-by: Joel Granados --- 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" =20 -/* 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 !=3D type) + if (left->type !=3D right->type) return false; =20 - if (tag->id.domain_id !=3D domain_id || tag->id.pasid !=3D pasid) + if (left->domain_id !=3D right->domain_id || left->pasid !=3D right->pasi= d) return false; =20 - if (type =3D=3D CACHE_TAG_IOTLB || type =3D=3D CACHE_TAG_NESTING_IOTLB) - return tag->id.iommu =3D=3D iommu; + if (left->type =3D=3D CACHE_TAG_DEVTLB || left->type =3D=3D CACHE_TAG_NES= TING_DEVTLB) + return left->dev =3D=3D right->dev; =20 - if (type =3D=3D CACHE_TAG_DEVTLB || type =3D=3D CACHE_TAG_NESTING_DEVTLB) - return tag->id.dev =3D=3D dev; + if (left->type =3D=3D CACHE_TAG_IOTLB || left->type =3D=3D CACHE_TAG_NEST= ING_IOTLB) + return left->iommu =3D=3D right->iommu; =20 return false; } @@ -48,6 +46,13 @@ static int cache_tag_assign(struct dmar_domain *domain, = u16 did, struct intel_iommu *iommu =3D info->iommu; struct cache_tag *tag, *temp; unsigned long flags; + struct cache_tag_id cmp_tag =3D { + .type =3D type, + .pasid =3D pasid, + .iommu =3D info->iommu, + .dev =3D dev, + .domain_id =3D did + }; =20 tag =3D kzalloc(sizeof(*tag), GFP_KERNEL); if (!tag) @@ -66,7 +71,7 @@ static int cache_tag_assign(struct dmar_domain *domain, u= 16 did, =20 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 *doma= in, u16 did, struct device *dev, ioasid_t pasid, enum cache_tag_type type) { - struct device_domain_info *info =3D dev_iommu_priv_get(dev); - struct intel_iommu *iommu =3D info->iommu; struct cache_tag *tag; unsigned long flags; + struct device_domain_info *info =3D dev_iommu_priv_get(dev); + struct cache_tag_id cmp_tag =3D { + .type =3D type, + .pasid =3D pasid, + .iommu =3D info->iommu, + .dev =3D dev, + .domain_id =3D did + }; + =20 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 =3D=3D 0) { list_del(&tag->node); --=20 2.43.0 From nobody Sun Dec 14 12:17:56 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CABD7158A17; Fri, 28 Jun 2024 12:27:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719577668; cv=none; b=aw/9NlbWhjiCPY9rjf64fMnAbDZ+74ewutp+S30F4V0XH1pJ9WMQbj6Jo07RRKBeeR87KCvF4ixhRtXwMl9i4iJy3+Isr/vKk6pQDz9kgIggsFZcASdI092HXr7J2B6VlHwKw08tp8bJXBWaLBfb2OELM9cRW1CXFUNfI5ggwcQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719577668; c=relaxed/simple; bh=QIn2HKuwrv5y+SYpDlSeDz8OZdgqw8nG5nlJLtYUDwE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=GhiGe6/2fw32SH+hHVVMdLAwsg1vCqlC8IIJoxQXRydSJEyhRqWcyT4S/WhFZIkOK5oLdtm56UHUfSr3HaZ8RE0c9BsmT7DgYVrZmZm9rqxCOA1YX4S3p+BaBlfqlfRramI+Tz0bOB1ymrUDlpZu0J1D1EoCZQ++AuTsPApPC/0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=WXosp/u5; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="WXosp/u5" Received: by smtp.kernel.org (Postfix) with ESMTPS id 5CE0FC116B1; Fri, 28 Jun 2024 12:27:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1719577668; bh=QIn2HKuwrv5y+SYpDlSeDz8OZdgqw8nG5nlJLtYUDwE=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=WXosp/u5okANdJPoJ0xYyqHgWXUemqqec9BmVls8cKR+pUGm/i+tiLuSGy/Ty9cIB x3LHGsSSNxvL9+kg4EGSOsIRcwxopDjmdclJxOlcj2L3vXQS8S/+U4FeuI5rQHjq8L jTZGszzIOw6aJalNE668o+MjeEAdwkJncHGJz3fhh1H0A5ddXYF/jgj9jcd/2ZA4IY nYe/7AJPrbiugKGEK6e+nYBIDGMfat6O37fK2bgMfAbWAOlkNK5qVVoNx9PxNDEtqu VjrcgXBVAcq8sz+eTZl/+77d8z+btIgd03QXwor0CFx9tTIaOSL7NjBQ8dvjvhfRRc aRjGcpP7UQ7Cg== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 528A7C2BD09; Fri, 28 Jun 2024 12:27:48 +0000 (UTC) From: Joel Granados via B4 Relay Date: Fri, 28 Jun 2024 14:27:41 +0200 Subject: [PATCH RFC 3/5] iommu/vt-d: Pass cache_tag_id to {un}assignment functions Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240628-jag-revisit_cache_tag_assign-v1-3-a0c19063c983@samsung.com> References: <20240628-jag-revisit_cache_tag_assign-v1-0-a0c19063c983@samsung.com> In-Reply-To: <20240628-jag-revisit_cache_tag_assign-v1-0-a0c19063c983@samsung.com> To: David Woodhouse , Lu Baolu , Joerg Roedel , Will Deacon , Robin Murphy Cc: iommu@lists.linux.dev, linux-kernel@vger.kernel.org, Joel Granados X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=8380; i=j.granados@samsung.com; h=from:subject:message-id; bh=VJrhxLNxW8HI5m/DeBVEAQusP+0q9BVObAY0Jv2AWqs=; b=owJ4nAHtARL+kA0DAAoBupfNUreWQU8ByyZiAGZ+rD7VrAJE58mEa+stecuzCUGdKNn5YDEM8 U7bytv6gOZOuokBswQAAQoAHRYhBK5HCVcl5jElzssnkLqXzVK3lkFPBQJmfqw+AAoJELqXzVK3 lkFPYncL/RwMN0b47HICMaKw/hTVh2I0bncndNZYINCnvad/6U5ww2F1X+WeL7Fv20AQdxndBQt aBOhQE35GnlIkjkJr7dZ1Zx8S9OK2jzJC/pXSqZWR21g77tSGuiB1EAdzYd2oU3DwV2xf02fhgr 3gBCtfNqKwfNIDoakQ90NuJ6LH60UB0cTn68h9viUT2ejVu1AnbHc/efr0QGCvULkwuaXdNfU7W ItvBPf24Icx35IclbWkls2zpipmfe+qZWYnszuLbXXtnNI9oWd3DF6a2ivcJ9A5I7YZ/d/nfKUb lg99C8vZrvI2IBwgkD6Sg2454VywPgzCFaRbGzsJ3qrdeSirBkdTd9nH3Ws0LO3EsKzUvcCyMpv +aOD1HTbHjQSVr3hvLZWoVcqMK3NhNt/St9Qvxizn137scia6k3csdkyTqf4OgEy8TYlk1MjzUv j0hQ753XhABhst+IYrtm6ozG9phm5lcSbJ98VRXHHWil2jWtXW7S60FcTgvVG4aZaCAF5gFv5k8 Vs= X-Developer-Key: i=j.granados@samsung.com; a=openpgp; fpr=F1F8E46D30F0F6C4A45FF4465895FAAC338C6E77 X-Endpoint-Received: by B4 Relay for j.granados@samsung.com/default with auth_id=70 X-Original-From: Joel Granados Reply-To: j.granados@samsung.com From: Joel Granados Replace passing 4 arguments (domain id, pasid, cache type and device) with just one cache_tag_id. Signed-off-by: Joel Granados --- drivers/iommu/intel/cache.c | 120 ++++++++++++++++++++--------------------= ---- 1 file changed, 54 insertions(+), 66 deletions(-) diff --git a/drivers/iommu/intel/cache.c b/drivers/iommu/intel/cache.c index b50ec5520871..eb409a296e43 100644 --- a/drivers/iommu/intel/cache.c +++ b/drivers/iommu/intel/cache.c @@ -38,40 +38,26 @@ static bool cache_tag_cmp(const struct cache_tag_id *le= ft, } =20 /* Assign a cache tag with specified type to domain. */ -static int cache_tag_assign(struct dmar_domain *domain, u16 did, - struct device *dev, ioasid_t pasid, - enum cache_tag_type type) +static int cache_tag_assign_type(struct dmar_domain *domain, + struct cache_tag_id const *tag_id, + enum cache_tag_type tag_type) { - struct device_domain_info *info =3D dev_iommu_priv_get(dev); - struct intel_iommu *iommu =3D info->iommu; struct cache_tag *tag, *temp; unsigned long flags; - struct cache_tag_id cmp_tag =3D { - .type =3D type, - .pasid =3D pasid, - .iommu =3D info->iommu, - .dev =3D dev, - .domain_id =3D did - }; =20 tag =3D kzalloc(sizeof(*tag), GFP_KERNEL); if (!tag) return -ENOMEM; =20 - tag->id.type =3D type; - tag->id.iommu =3D iommu; - tag->id.domain_id =3D did; - tag->id.pasid =3D pasid; + tag->id =3D *tag_id; + tag->id.type =3D tag_type; + if (tag_id->type !=3D CACHE_TAG_DEVTLB && tag_id->type !=3D CACHE_TAG_NES= TING_DEVTLB) + tag->id.dev =3D tag_id->iommu->iommu.dev; tag->users =3D 1; =20 - if (type =3D=3D CACHE_TAG_DEVTLB || type =3D=3D CACHE_TAG_NESTING_DEVTLB) - tag->id.dev =3D dev; - else - tag->id.dev =3D iommu->iommu.dev; - spin_lock_irqsave(&domain->cache_lock, flags); list_for_each_entry(temp, &domain->cache_tags, node) { - if (cache_tag_cmp(&temp->id, &cmp_tag)) { + if (cache_tag_cmp(&temp->id, tag_id)) { temp->users++; spin_unlock_irqrestore(&domain->cache_lock, flags); kfree(tag); @@ -87,25 +73,17 @@ static int cache_tag_assign(struct dmar_domain *domain,= u16 did, } =20 /* Unassign a cache tag with specified type from domain. */ -static void cache_tag_unassign(struct dmar_domain *domain, u16 did, - struct device *dev, ioasid_t pasid, - enum cache_tag_type type) +static void cache_tag_unassign_type(struct dmar_domain *domain, + struct cache_tag_id *tag_id, + enum cache_tag_type tag_type) { struct cache_tag *tag; unsigned long flags; - struct device_domain_info *info =3D dev_iommu_priv_get(dev); - struct cache_tag_id cmp_tag =3D { - .type =3D type, - .pasid =3D pasid, - .iommu =3D info->iommu, - .dev =3D dev, - .domain_id =3D did - }; - =20 + tag_id->type =3D tag_type; spin_lock_irqsave(&domain->cache_lock, flags); list_for_each_entry(tag, &domain->cache_tags, node) { - if (cache_tag_cmp(&tag->id, &cmp_tag)) { + if (cache_tag_cmp(&tag->id, tag_id)) { trace_cache_tag_unassign(tag); if (--tag->users =3D=3D 0) { list_del(&tag->node); @@ -117,60 +95,58 @@ static void cache_tag_unassign(struct dmar_domain *dom= ain, u16 did, spin_unlock_irqrestore(&domain->cache_lock, flags); } =20 -static int __cache_tag_assign_domain(struct dmar_domain *domain, u16 did, - struct device *dev, ioasid_t pasid) +static int __cache_tag_assign_domain(struct dmar_domain *domain, + struct cache_tag_id *new_tag_id) { - struct device_domain_info *info =3D dev_iommu_priv_get(dev); + struct device_domain_info *info =3D dev_iommu_priv_get(new_tag_id->dev); int ret; =20 - ret =3D cache_tag_assign(domain, did, dev, pasid, CACHE_TAG_IOTLB); + ret =3D cache_tag_assign_type(domain, new_tag_id, CACHE_TAG_IOTLB); if (ret || !info->ats_enabled) return ret; =20 - ret =3D cache_tag_assign(domain, did, dev, pasid, CACHE_TAG_DEVTLB); + ret =3D cache_tag_assign_type(domain, new_tag_id, CACHE_TAG_DEVTLB); if (ret) - cache_tag_unassign(domain, did, dev, pasid, CACHE_TAG_IOTLB); + cache_tag_unassign_type(domain, new_tag_id, CACHE_TAG_IOTLB); =20 return ret; } =20 -static void __cache_tag_unassign_domain(struct dmar_domain *domain, u16 di= d, - struct device *dev, ioasid_t pasid) +static void __cache_tag_unassign_domain(struct dmar_domain *domain, + struct cache_tag_id *tag_id) { - struct device_domain_info *info =3D dev_iommu_priv_get(dev); - - cache_tag_unassign(domain, did, dev, pasid, CACHE_TAG_IOTLB); + struct device_domain_info *info =3D dev_iommu_priv_get(tag_id->dev); =20 + cache_tag_unassign_type(domain, tag_id, CACHE_TAG_IOTLB); if (info->ats_enabled) - cache_tag_unassign(domain, did, dev, pasid, CACHE_TAG_DEVTLB); + cache_tag_unassign_type(domain, tag_id, CACHE_TAG_DEVTLB); } =20 -static int __cache_tag_assign_parent_domain(struct dmar_domain *domain, u1= 6 did, - struct device *dev, ioasid_t pasid) +static int __cache_tag_assign_parent_domain(struct dmar_domain *domain, + struct cache_tag_id *new_tag_id) { - struct device_domain_info *info =3D dev_iommu_priv_get(dev); + struct device_domain_info *info =3D dev_iommu_priv_get(new_tag_id->dev); int ret; =20 - ret =3D cache_tag_assign(domain, did, dev, pasid, CACHE_TAG_NESTING_IOTLB= ); + ret =3D cache_tag_assign_type(domain, new_tag_id, CACHE_TAG_NESTING_IOTLB= ); if (ret || !info->ats_enabled) return ret; =20 - ret =3D cache_tag_assign(domain, did, dev, pasid, CACHE_TAG_NESTING_DEVTL= B); + ret =3D cache_tag_assign_type(domain, new_tag_id, CACHE_TAG_NESTING_DEVTL= B); if (ret) - cache_tag_unassign(domain, did, dev, pasid, CACHE_TAG_NESTING_IOTLB); + cache_tag_unassign_type(domain, new_tag_id, CACHE_TAG_NESTING_IOTLB); =20 return ret; } =20 -static void __cache_tag_unassign_parent_domain(struct dmar_domain *domain,= u16 did, - struct device *dev, ioasid_t pasid) +static void __cache_tag_unassign_parent_domain(struct dmar_domain *domain, + struct cache_tag_id *tag_id) { - struct device_domain_info *info =3D dev_iommu_priv_get(dev); - - cache_tag_unassign(domain, did, dev, pasid, CACHE_TAG_NESTING_IOTLB); + struct device_domain_info *info =3D dev_iommu_priv_get(tag_id->dev); =20 + cache_tag_unassign_type(domain, tag_id, CACHE_TAG_NESTING_IOTLB); if (info->ats_enabled) - cache_tag_unassign(domain, did, dev, pasid, CACHE_TAG_NESTING_DEVTLB); + cache_tag_unassign_type(domain, tag_id, CACHE_TAG_NESTING_DEVTLB); } =20 static u16 domain_get_id_for_dev(struct dmar_domain *domain, struct device= *dev) @@ -199,16 +175,22 @@ static u16 domain_get_id_for_dev(struct dmar_domain *= domain, struct device *dev) int cache_tag_assign_domain(struct dmar_domain *domain, struct device *dev, ioasid_t pasid) { - u16 did =3D domain_get_id_for_dev(domain, dev); + struct device_domain_info *info =3D dev_iommu_priv_get(dev); + struct cache_tag_id new_tag_id =3D { + .pasid =3D pasid, + .iommu =3D info->iommu, + .dev =3D dev, + .domain_id =3D domain_get_id_for_dev(domain, dev), + }; int ret; =20 - ret =3D __cache_tag_assign_domain(domain, did, dev, pasid); + ret =3D __cache_tag_assign_domain(domain, &new_tag_id); if (ret || domain->domain.type !=3D IOMMU_DOMAIN_NESTED) return ret; =20 - ret =3D __cache_tag_assign_parent_domain(domain->s2_domain, did, dev, pas= id); + ret =3D __cache_tag_assign_parent_domain(domain->s2_domain, &new_tag_id); if (ret) - __cache_tag_unassign_domain(domain, did, dev, pasid); + __cache_tag_unassign_domain(domain, &new_tag_id); =20 return ret; } @@ -223,11 +205,17 @@ int cache_tag_assign_domain(struct dmar_domain *domai= n, void cache_tag_unassign_domain(struct dmar_domain *domain, struct device *dev, ioasid_t pasid) { - u16 did =3D domain_get_id_for_dev(domain, dev); + struct device_domain_info *info =3D dev_iommu_priv_get(dev); + struct cache_tag_id tag_id =3D { + .pasid =3D pasid, + .iommu =3D info->iommu, + .dev =3D dev, + .domain_id =3D domain_get_id_for_dev(domain, dev) + }; =20 - __cache_tag_unassign_domain(domain, did, dev, pasid); + __cache_tag_unassign_domain(domain, &tag_id); if (domain->domain.type =3D=3D IOMMU_DOMAIN_NESTED) - __cache_tag_unassign_parent_domain(domain->s2_domain, did, dev, pasid); + __cache_tag_unassign_parent_domain(domain->s2_domain, &tag_id); } =20 static unsigned long calculate_psi_aligned_address(unsigned long start, --=20 2.43.0 From nobody Sun Dec 14 12:17:56 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CAC2A158A18; Fri, 28 Jun 2024 12:27:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719577668; cv=none; b=mFIPKi/V++Ku4h4HtCN/3OBsfP6oiZ4zrBdjvkcn+/5O8P2CaNzykbTUNxF5frQbk8UoA1kO8qxn0Ou7m67fBlEd3/4qpqo2LuqbbzEkqkIFGtjQ0/b8T3WEl3e5tEzqaPEX/ULJfWGsIgN2AbOVuCNjSoL4VaUJvXdzOAmluXE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719577668; c=relaxed/simple; bh=+2zu/Qzx4FIvpJHItIhBbZC2EpxeoFjZ719vb8lE4to=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=qb6baW1znH4D2MAlVRsfQaT/4hsEGYKKzN5HsfU1SKJ++oWla2u7UDUd/3jQeY9ec+dDkDpN8G58A/Gl0Fmz17WLBWnK+MOObJ9PGNDFMzILPJalAXg77IS1Bvn/ZrFUstVclVT/DgmXt5JXYKlo/GYrlCFAhOq4+rqXuNuU0Nw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=oTnUDTEi; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="oTnUDTEi" Received: by smtp.kernel.org (Postfix) with ESMTPS id 751D8C4AF0F; Fri, 28 Jun 2024 12:27:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1719577668; bh=+2zu/Qzx4FIvpJHItIhBbZC2EpxeoFjZ719vb8lE4to=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=oTnUDTEi/LGslSI4W3rCOUeF2NqyJxGxPnvNOcrx7vqqir/cp2wQ+7d0IWTdMizQw BGwh/j8TW/CwG5Oee0oghsqN17Mb9/HPYLmzbq3uFrGjlmnl5f79y8au338C4tSFG5 OU7Xsfoyst4cATdp/N2HkvLBxUGAvrU9bIzE9CAN9GVQlB/BAoMXPdKajXWlAneIkA wbt5djSgJpyOZoNZeoaD5q1A59IFNH5jNlMEjRCVBUW3DqtiFClEmoVi5nYr1s/yGx JzdoOTydKq+pDGlD3RkRY2HLHrU8ZCez2nV6K8jxcclaZBPYtlt/q0rX1ef5EB5gav w+dfXvrCpEf5Q== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 67786C3064D; Fri, 28 Jun 2024 12:27:48 +0000 (UTC) From: Joel Granados via B4 Relay Date: Fri, 28 Jun 2024 14:27:42 +0200 Subject: [PATCH RFC 4/5] iommu/vt-d: Use ats_enable as an argument Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240628-jag-revisit_cache_tag_assign-v1-4-a0c19063c983@samsung.com> References: <20240628-jag-revisit_cache_tag_assign-v1-0-a0c19063c983@samsung.com> In-Reply-To: <20240628-jag-revisit_cache_tag_assign-v1-0-a0c19063c983@samsung.com> To: David Woodhouse , Lu Baolu , Joerg Roedel , Will Deacon , Robin Murphy Cc: iommu@lists.linux.dev, linux-kernel@vger.kernel.org, Joel Granados X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3905; i=j.granados@samsung.com; h=from:subject:message-id; bh=hio8w1SDQJuW7Ys9C3jM+VXzxzsPd2lcrv4x7GWHRTI=; b=owJ4nAHtARL+kA0DAAoBupfNUreWQU8ByyZiAGZ+rEDkqOIvynV0g/qnndBqQ0i8IEKRJ5coo KT42/eia1n+CokBswQAAQoAHRYhBK5HCVcl5jElzssnkLqXzVK3lkFPBQJmfqxAAAoJELqXzVK3 lkFPcw0MAIFM16hWhkf04N2YmO5Lgfv9g8UJNnXRrhgj7dDkbQPxjpkNIPE++iu0cfVrcaLQ0Xu IuiSoZD7FUO1o5qLL/3u5K5MgzGIhhwce4bvvl+UzQ4z/2pABYCG0PvmCVb0/0JKFUUrMkQcVWf mVsWt+Mhgs3C+z3f0MuvvlIAhNrz7ujjo/QSKOMQA46V3IdRrfiwvdRGARJKCnmSBF5sh9XeUWy Qaz4ngg7u6TEPA4E96YyIVp0i0EKlVEHzDKTjeMwyK+or0ZdKaLlzUR1ttLoyg/E/6CW6CdqyYi IaG/L6RuF091B6JfJZFiuITB6qRwScCiB9q7LzGH6iEmKhgrYeSNXkt5dNdST8PoqTFgXCtwP+Q RYYeJMyHuoIQzOtDqbG6P/Z954YP+l+7+hUMazyUFwPKFVnDOpmJ4GolYCkRsNr9XIsAsIwuHAk 1Q7rW+QNm+V6FmaSt47SG95dd73v5Tp6YiTYPMguMabQ10DuJW9AeDTvPDTbsOnVVyxGg+5i1Z6 U4= X-Developer-Key: i=j.granados@samsung.com; a=openpgp; fpr=F1F8E46D30F0F6C4A45FF4465895FAAC338C6E77 X-Endpoint-Received: by B4 Relay for j.granados@samsung.com/default with auth_id=70 X-Original-From: Joel Granados Reply-To: j.granados@samsung.com From: Joel Granados Pass the ats_enabled flag as a function argument instead of calling dev_iommu_priv_get. Signed-off-by: Joel Granados --- drivers/iommu/intel/cache.c | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/drivers/iommu/intel/cache.c b/drivers/iommu/intel/cache.c index eb409a296e43..c630f4485a06 100644 --- a/drivers/iommu/intel/cache.c +++ b/drivers/iommu/intel/cache.c @@ -96,13 +96,13 @@ static void cache_tag_unassign_type(struct dmar_domain = *domain, } =20 static int __cache_tag_assign_domain(struct dmar_domain *domain, - struct cache_tag_id *new_tag_id) + struct cache_tag_id *new_tag_id, + const bool ats_enabled) { - struct device_domain_info *info =3D dev_iommu_priv_get(new_tag_id->dev); int ret; =20 ret =3D cache_tag_assign_type(domain, new_tag_id, CACHE_TAG_IOTLB); - if (ret || !info->ats_enabled) + if (ret || !ats_enabled) return ret; =20 ret =3D cache_tag_assign_type(domain, new_tag_id, CACHE_TAG_DEVTLB); @@ -113,23 +113,22 @@ static int __cache_tag_assign_domain(struct dmar_doma= in *domain, } =20 static void __cache_tag_unassign_domain(struct dmar_domain *domain, - struct cache_tag_id *tag_id) + struct cache_tag_id *tag_id, + const bool ats_enabled) { - struct device_domain_info *info =3D dev_iommu_priv_get(tag_id->dev); - cache_tag_unassign_type(domain, tag_id, CACHE_TAG_IOTLB); - if (info->ats_enabled) + if (ats_enabled) cache_tag_unassign_type(domain, tag_id, CACHE_TAG_DEVTLB); } =20 static int __cache_tag_assign_parent_domain(struct dmar_domain *domain, - struct cache_tag_id *new_tag_id) + struct cache_tag_id *new_tag_id, + const bool ats_enabled) { - struct device_domain_info *info =3D dev_iommu_priv_get(new_tag_id->dev); int ret; =20 ret =3D cache_tag_assign_type(domain, new_tag_id, CACHE_TAG_NESTING_IOTLB= ); - if (ret || !info->ats_enabled) + if (ret || !ats_enabled) return ret; =20 ret =3D cache_tag_assign_type(domain, new_tag_id, CACHE_TAG_NESTING_DEVTL= B); @@ -140,12 +139,11 @@ static int __cache_tag_assign_parent_domain(struct dm= ar_domain *domain, } =20 static void __cache_tag_unassign_parent_domain(struct dmar_domain *domain, - struct cache_tag_id *tag_id) + struct cache_tag_id *tag_id, + const bool ats_enabled) { - struct device_domain_info *info =3D dev_iommu_priv_get(tag_id->dev); - cache_tag_unassign_type(domain, tag_id, CACHE_TAG_NESTING_IOTLB); - if (info->ats_enabled) + if (ats_enabled) cache_tag_unassign_type(domain, tag_id, CACHE_TAG_NESTING_DEVTLB); } =20 @@ -184,13 +182,14 @@ int cache_tag_assign_domain(struct dmar_domain *domai= n, }; int ret; =20 - ret =3D __cache_tag_assign_domain(domain, &new_tag_id); + ret =3D __cache_tag_assign_domain(domain, &new_tag_id, info->ats_enabled); if (ret || domain->domain.type !=3D IOMMU_DOMAIN_NESTED) return ret; =20 - ret =3D __cache_tag_assign_parent_domain(domain->s2_domain, &new_tag_id); + ret =3D __cache_tag_assign_parent_domain(domain->s2_domain, &new_tag_id, + info->ats_enabled); if (ret) - __cache_tag_unassign_domain(domain, &new_tag_id); + __cache_tag_unassign_domain(domain, &new_tag_id, info->ats_enabled); =20 return ret; } @@ -213,9 +212,10 @@ void cache_tag_unassign_domain(struct dmar_domain *dom= ain, .domain_id =3D domain_get_id_for_dev(domain, dev) }; =20 - __cache_tag_unassign_domain(domain, &tag_id); + __cache_tag_unassign_domain(domain, &tag_id, info->ats_enabled); if (domain->domain.type =3D=3D IOMMU_DOMAIN_NESTED) - __cache_tag_unassign_parent_domain(domain->s2_domain, &tag_id); + __cache_tag_unassign_parent_domain(domain->s2_domain, &tag_id, + info->ats_enabled); } =20 static unsigned long calculate_psi_aligned_address(unsigned long start, --=20 2.43.0 From nobody Sun Dec 14 12:17:56 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CAC72158A1C; Fri, 28 Jun 2024 12:27:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719577668; cv=none; b=tECFXTrLuZTbWoiQpfwzwPcwFwT4C75VqTdqWTbAqlE+cr8x9ptshUE4p5MpCz49Qvply7IOV9qREBgQV+8xB5tfwJy67IHm7e0c4/pPJEw1D6DgavNUpbWHMGpffcxBfvp0PBOkQ4WDzTs3hasO0GX+hMGdk89b9n1r/Jck8Jw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719577668; c=relaxed/simple; bh=z6oyl79I8NC5of/6nM0UNbEIpkWqKcp2re1J+nHNR5k=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=dgiAZnuWP6Ht4uTTUD/ZS6aNRti89ehNAW4FOsAKGToSl1CP2FoHDE27LpDeqh0X9l6HQSh8fCvzDF6BfnSNYQ07oMt7aV9EWp5IczSJzXazT9JIVoi2o8xxqTAUGP7E/ra42naCCWFdy11KSp4QcCMCFWQDJ/EuqybhQsOyfHc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=bHnwe2Kx; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="bHnwe2Kx" Received: by smtp.kernel.org (Postfix) with ESMTPS id 840C2C4AF0D; Fri, 28 Jun 2024 12:27:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1719577668; bh=z6oyl79I8NC5of/6nM0UNbEIpkWqKcp2re1J+nHNR5k=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=bHnwe2KxwVlR1KJzzEwY7jK1EwbEG1JsXlU1GZNUG7GViU8EsKQs02lEBLZZpSlSl sPNN2P2oiH9LkqhIcBwH7Ehl8+9qSTEPm7yCr5j7MkNhzj4BWiIEZz2TohPS37cCSo I6k2ggwEVPBEifjk65NX5Ojw8bQfaxG+M1TZLJNw618yf10LzQCH94G/5Cd560bqoa kJMyrvV94lg/tDBjZ3+8R296Gl5SRsR4hi5Nwf4rHCoP1z7qEzkzWrMxWxFwCUHx3n C0ON8KombicJ28G+5al8lgwSwsDj46bFB07l89hwuPP5d8xN8icjJlnRduwTudLBZv HWbbe0ZBspGcg== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7610EC3065B; Fri, 28 Jun 2024 12:27:48 +0000 (UTC) From: Joel Granados via B4 Relay Date: Fri, 28 Jun 2024 14:27:43 +0200 Subject: [PATCH RFC 5/5] iommu/vt-d: Remove dev_iommu_priv_get call from domain_get_id_for_dev Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240628-jag-revisit_cache_tag_assign-v1-5-a0c19063c983@samsung.com> References: <20240628-jag-revisit_cache_tag_assign-v1-0-a0c19063c983@samsung.com> In-Reply-To: <20240628-jag-revisit_cache_tag_assign-v1-0-a0c19063c983@samsung.com> To: David Woodhouse , Lu Baolu , Joerg Roedel , Will Deacon , Robin Murphy Cc: iommu@lists.linux.dev, linux-kernel@vger.kernel.org, Joel Granados X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1737; i=j.granados@samsung.com; h=from:subject:message-id; bh=bSKT5KATPjuI2PxohgEgtnVEXQsN8h24B4pOY9NhzjU=; b=owJ4nAHtARL+kA0DAAoBupfNUreWQU8ByyZiAGZ+rEF2V7Oo9xvBBkRnBcyi7uYIJn2E2BmRL zd6A97flRB21YkBswQAAQoAHRYhBK5HCVcl5jElzssnkLqXzVK3lkFPBQJmfqxBAAoJELqXzVK3 lkFPc4sL/RP2u/N7pZpUkjwF9ibuOdDKPQq0mcziIN7z5zfCccwR8R5f28tiBqm36muQHDl3qVE b827WJyDMCL/DX2xxrJTBpjp5dK0mHykkG3RJ4RCV8FawkmJf7dZus7Knc80cToJNl+7baUGdFP 0iOflA4jFxAIOQRS03F4+gj6NLIwkskCHNi/WQFz+pbkia1uBdd3swWzbqIAygVmswB0blfRN6U rkOc0E3WRWU6dGBigInYECE2YF1z14kJwzScXiptlXUP/5jSi2f65k0iwlK1CV4pBVVNN/USNO5 vemGoTl1yPL8RCHMoLShNtc4Z1unj6CK7zCn6QsanxX49UT0Gp2/yOxZDb0ZrDHLNzB0K1G9TBO YhntrSay+2lqRYzp2s+QIAkhKLkLWGdvCrxpnvMN4cx+E05EKMo5oug1tfRQ4ISCwz9Yh0R+Kkr epg/Nod559pIr+Um5Yx6eWnjR6msc473VzqHPXAilzwSkwnxds3QegrN+CospmIlMhmle9VBof4 8I= X-Developer-Key: i=j.granados@samsung.com; a=openpgp; fpr=F1F8E46D30F0F6C4A45FF4465895FAAC338C6E77 X-Endpoint-Received: by B4 Relay for j.granados@samsung.com/default with auth_id=70 X-Original-From: Joel Granados Reply-To: j.granados@samsung.com From: Joel Granados We don't need to run dev_iommu_priv_get as we already have the struct intel_iommu. Pass the intel_iommu instead of the device and rename the function to domain_id_for_iommu to express what it is really doing. Signed-off-by: Joel Granados --- drivers/iommu/intel/cache.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/drivers/iommu/intel/cache.c b/drivers/iommu/intel/cache.c index c630f4485a06..e55d700fcd29 100644 --- a/drivers/iommu/intel/cache.c +++ b/drivers/iommu/intel/cache.c @@ -147,11 +147,9 @@ static void __cache_tag_unassign_parent_domain(struct = dmar_domain *domain, cache_tag_unassign_type(domain, tag_id, CACHE_TAG_NESTING_DEVTLB); } =20 -static u16 domain_get_id_for_dev(struct dmar_domain *domain, struct device= *dev) +static u16 domain_id_for_iommu(struct dmar_domain *domain, + struct intel_iommu *iommu) { - struct device_domain_info *info =3D dev_iommu_priv_get(dev); - struct intel_iommu *iommu =3D info->iommu; - /* * The driver assigns different domain IDs for all domains except * the SVA type. @@ -178,7 +176,7 @@ int cache_tag_assign_domain(struct dmar_domain *domain, .pasid =3D pasid, .iommu =3D info->iommu, .dev =3D dev, - .domain_id =3D domain_get_id_for_dev(domain, dev), + .domain_id =3D domain_id_for_iommu(domain, info->iommu), }; int ret; =20 @@ -209,7 +207,7 @@ void cache_tag_unassign_domain(struct dmar_domain *doma= in, .pasid =3D pasid, .iommu =3D info->iommu, .dev =3D dev, - .domain_id =3D domain_get_id_for_dev(domain, dev) + .domain_id =3D domain_id_for_iommu(domain, info->iommu) }; =20 __cache_tag_unassign_domain(domain, &tag_id, info->ats_enabled); --=20 2.43.0