From: Alexey Kardashevskiy <aik@amd.com>
To: <iommu@lists.linux.dev>
Cc: Jason Gunthorpe <jgg@ziepe.ca>, Kevin Tian <kevin.tian@intel.com>,
"Joerg Roedel" <joro@8bytes.org>, Will Deacon <will@kernel.org>,
Robin Murphy <robin.murphy@arm.com>,
Steve Sistare <steven.sistare@oracle.com>,
"Alexey Kardashevskiy" <aik@amd.com>
Subject: [PATCH] iommufd: Fix offset handling in folio subroutines
Date: Wed, 2 Apr 2025 12:44:08 +1100 [thread overview]
Message-ID: <20250402014408.2760300-1-aik@amd.com> (raw)
The @offset from memfd_pin_folios() is pgoff_t and is bytes, not
a number of pages as batch_from_folios() treats it.
Convert byte offset to pfn offset and use that.
Fixes: ed9178fbfd4e ("iommufd: Folio subroutines")
Signed-off-by: Alexey Kardashevskiy <aik@amd.com>
---
Found this when tried mapping a bunch of folios (>64) with an offset and
the first folio was used for all the mappings in the batch.
---
drivers/iommu/iommufd/pages.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/drivers/iommu/iommufd/pages.c b/drivers/iommu/iommufd/pages.c
index 3427749bc5ce..6075d11691a6 100644
--- a/drivers/iommu/iommufd/pages.c
+++ b/drivers/iommu/iommufd/pages.c
@@ -646,8 +646,9 @@ static int batch_from_folios(struct pfn_batch *batch, struct folio ***folios_p,
while (npages) {
struct folio *folio = *folios;
- unsigned long nr = folio_nr_pages(folio) - offset;
- unsigned long pfn = page_to_pfn(folio_page(folio, offset));
+ unsigned long offset_nr = offset >> PAGE_SHIFT;
+ unsigned long nr = folio_nr_pages(folio) - offset_nr;
+ unsigned long pfn = page_to_pfn(folio_page(folio, offset_nr));
nr = min(nr, npages);
npages -= nr;
--
2.47.1
next reply other threads:[~2025-04-02 1:44 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-02 1:44 Alexey Kardashevskiy [this message]
2025-04-07 5:12 ` [PATCH] iommufd: Fix offset handling in folio subroutines Tian, Kevin
2025-04-07 6:53 ` Alexey Kardashevskiy
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=20250402014408.2760300-1-aik@amd.com \
--to=aik@amd.com \
--cc=iommu@lists.linux.dev \
--cc=jgg@ziepe.ca \
--cc=joro@8bytes.org \
--cc=kevin.tian@intel.com \
--cc=robin.murphy@arm.com \
--cc=steven.sistare@oracle.com \
--cc=will@kernel.org \
/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;
as well as URLs for NNTP newsgroup(s).