From: Tina Zhang <tina.zhang@intel.com>
To: Jean-Philippe Brucker <jean-philippe@linaro.org>,
Kevin Tian <kevin.tian@intel.com>,
Lu Baolu <baolu.lu@linux.intel.com>,
joro@8bytes.org, will@kernel.org, Yi Liu <yi.l.liu@intel.com>
Cc: virtualization@lists.linux-foundation.org, iommu@lists.linux.dev,
linux-kernel@vger.kernel.org, Tina Zhang <tina.zhang@intel.com>
Subject: [RFC PATCH 1/5] iommu/virtio-iommu: Correct the values of granule and nr_pages
Date: Mon, 6 Nov 2023 02:12:22 -0500 [thread overview]
Message-ID: <20231106071226.9656-2-tina.zhang@intel.com> (raw)
In-Reply-To: <20231106071226.9656-1-tina.zhang@intel.com>
The value of granule is ilog2(pgsize). When the value of pgsize isn't
a power of two, granule would make pgsize less than the actual size of
pgsize. E.g., if pgsize = 0x6000 and granule = ilog2(gather->pgsize), then
granule = 0xe. 2^0xe = 0x4000 makes the pgsize (0x4000) smaller than the
actual pgsize (0x6000). Invalidating IOTLB with smaller range would lead
to cache incoherence. So, roundup pgsize value to the nearest power of 2
to make sure the granule won't make pgsize less than the actual size. The
value of "gather->end - gather->start + 1" also needs similar adjustment.
Signed-off-by: Tina Zhang <tina.zhang@intel.com>
---
drivers/iommu/virtio-iommu.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/iommu/virtio-iommu.c b/drivers/iommu/virtio-iommu.c
index 08e310672e57..b1ceaac974e2 100644
--- a/drivers/iommu/virtio-iommu.c
+++ b/drivers/iommu/virtio-iommu.c
@@ -1289,8 +1289,8 @@ static void viommu_iotlb_sync(struct iommu_domain *domain,
if (!gather->pgsize)
return;
- granule = ilog2(gather->pgsize);
- nr_pages = (gather->end - gather->start + 1) >> granule;
+ granule = ilog2(__roundup_pow_of_two(gather->pgsize));
+ nr_pages = __roundup_pow_of_two(gather->end - gather->start + 1) >> granule;
req = (struct virtio_iommu_req_invalidate) {
.head.type = VIRTIO_IOMMU_T_INVALIDATE,
.inv_gran = cpu_to_le16(VIRTIO_IOMMU_INVAL_G_VA),
--
2.39.3
next prev parent reply other threads:[~2023-11-06 7:14 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-06 7:12 [RFC PATCH 0/5] virtio-iommu: Add VT-d IO page table Tina Zhang
2023-11-06 7:12 ` Tina Zhang [this message]
2023-11-06 7:12 ` [RFC PATCH 2/5] iommu/vt-d: Add generic IO page table support Tina Zhang
2023-11-06 19:32 ` Jason Gunthorpe
2023-11-09 0:10 ` Zhang, Tina
2023-11-09 0:33 ` Jason Gunthorpe
2023-11-06 7:12 ` [RFC PATCH 3/5] iommu/io-pgtable: Introduce struct vtd_cfg Tina Zhang
2023-11-06 7:12 ` [RFC PATCH 4/5] iommu/vt-d: Adapt alloc_pgtable interface to be used by others Tina Zhang
2023-11-06 7:12 ` [RFC PATCH 5/5] iommu/virtio-iommu: Support attaching VT-d IO pgtable Tina Zhang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231106071226.9656-2-tina.zhang@intel.com \
--to=tina.zhang@intel.com \
--cc=baolu.lu@linux.intel.com \
--cc=iommu@lists.linux.dev \
--cc=jean-philippe@linaro.org \
--cc=joro@8bytes.org \
--cc=kevin.tian@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=virtualization@lists.linux-foundation.org \
--cc=will@kernel.org \
--cc=yi.l.liu@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox