From: Alex Williamson <alex.williamson@redhat.com>
To: Mitchell Augustin <mitchell.augustin@canonical.com>
Cc: Peter Xu <peterx@redhat.com>,
kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
clg@redhat.com, jgg@nvidia.com, willy@infradead.org
Subject: Re: [PATCH v2 6/6] vfio/type1: Use mapping page mask for pfnmaps
Date: Wed, 26 Feb 2025 10:55:40 -0700 [thread overview]
Message-ID: <20250226105540.696a4b80.alex.williamson@redhat.com> (raw)
In-Reply-To: <CAHTA-ubiguHnrQQH7uML30LsVc+wk-b=zTCioVTs3368eWkmeg@mail.gmail.com>
On Wed, 19 Feb 2025 14:32:35 -0600
Mitchell Augustin <mitchell.augustin@canonical.com> wrote:
> > Thanks for the review and testing!
>
> Sure thing, thanks for the patch set!
>
> If you happen to have a few minutes, I'm struggling to understand the
> epfn computation and would appreciate some insight.
Sorry, this slipped off my todo list for a few days.
> My current understanding (very possibly incorrect):
> - epfn is intended to be the last page frame number that can be
> represented at the mapping level corresponding to addr_mask. (so, if
> addr_mask == PUD_MASK, epfn would be the highest pfn still in PUD
> level).
Actually epfn is the first pfn of the next addr_mask level page. The
value in the parens (*pfn | (~addr_mask >> PAGE_SHIFT)) is the last pfn
within the same level page. We could do it either way, it's just a
matter of where the +1 gets added.
> - ret should be == npages if all pfns in the requested vma are within
> the memory hierarchy level denoted by addr_mask. If npages is more
> than can be represented at that level, ret == the max number of page
> frames representable at addr_mask level.
Yes.
> - - (if the second case is true, that means we were not able to obtain
> all requested pages due to running out of PFNs at the current mapping
> level)
vaddr_get_pfns() is called again if we haven't reached npage.
Specifically, from vfio_pin_pages_remote() we hit the added continue
under the !batch->size branch. If the pfnmaps are fully PUD aligned,
we'll call vaddr_get_pfns() once per PUD_SIZE, vfio_pin_pages_remote()
will only return with the full requested npage value, and we'll only
call vfio_iommu_map() once. The latter has always been true, the
difference is the number of times we iterate calling vaddr_get_pfns().
> If the above is all correct, what is confusing me is where the "(*pfn)
> | " comes into this equation. If epfn is meant to be the last pfn
> representable at addr_mask level of the hierarchy, wouldn't that be
> represented by (~pgmask >> PAGE_SHIFT) alone?
(~addr_mask >> PAGE_SHIFT) gives us the last pfn relative to zero. We
want the last pfn relative to *pfn, therefore we OR in *pfn. The OR
handles any offset that *pfn might have within the addr_mask page, so
this operation always provides the last pfn of the addr_mask page
relative to *pfn. +1 because we want to calculate the number of pfns
until the next page. Thanks,
Alex
next prev parent reply other threads:[~2025-02-26 17:55 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-18 22:22 [PATCH v2 0/6] vfio: Improve DMA mapping performance for huge pfnmaps Alex Williamson
2025-02-18 22:22 ` [PATCH v2 1/6] vfio/type1: Catch zero from pin_user_pages_remote() Alex Williamson
2025-02-18 22:22 ` [PATCH v2 2/6] vfio/type1: Convert all vaddr_get_pfns() callers to use vfio_batch Alex Williamson
2025-02-18 22:22 ` [PATCH v2 3/6] vfio/type1: Use vfio_batch for vaddr_get_pfns() Alex Williamson
2025-02-18 22:22 ` [PATCH v2 4/6] vfio/type1: Use consistent types for page counts Alex Williamson
2025-02-18 22:46 ` Peter Xu
2025-02-19 0:55 ` Mitchell Augustin
2025-02-25 0:17 ` Jason Gunthorpe
2025-02-18 22:22 ` [PATCH v2 5/6] mm: Provide address mask in struct follow_pfnmap_args Alex Williamson
2025-02-19 8:31 ` David Hildenbrand
2025-02-26 19:54 ` Alex Williamson
2025-02-26 20:05 ` David Hildenbrand
2025-02-18 22:22 ` [PATCH v2 6/6] vfio/type1: Use mapping page mask for pfnmaps Alex Williamson
2025-02-18 22:47 ` Peter Xu
2025-02-18 23:14 ` Alex Williamson
2025-02-19 2:36 ` Mitchell Augustin
2025-02-19 15:08 ` Alex Williamson
2025-02-19 20:32 ` Mitchell Augustin
2025-02-26 17:55 ` Alex Williamson [this message]
2025-02-27 20:22 ` Mitchell Augustin
2025-02-25 0:17 ` Jason Gunthorpe
2025-02-19 2:37 ` [PATCH v2 0/6] vfio: Improve DMA mapping performance for huge pfnmaps Mitchell Augustin
2025-02-28 16:32 ` Alex Williamson
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=20250226105540.696a4b80.alex.williamson@redhat.com \
--to=alex.williamson@redhat.com \
--cc=clg@redhat.com \
--cc=jgg@nvidia.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mitchell.augustin@canonical.com \
--cc=peterx@redhat.com \
--cc=willy@infradead.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
all inboxes | Powered by JetHome®