From: David Hildenbrand <david@redhat.com>
To: lizhe.67@bytedance.com, jgg@ziepe.ca
Cc: akpm@linux-foundation.org, alex.williamson@redhat.com,
kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-mm@kvack.org, peterx@redhat.com
Subject: Re: [PATCH v4 2/3] gup: introduce unpin_user_folio_dirty_locked()
Date: Wed, 18 Jun 2025 10:20:46 +0200 [thread overview]
Message-ID: <c485543e-8450-448e-9db3-d459f2096496@redhat.com> (raw)
In-Reply-To: <20250618062820.8477-1-lizhe.67@bytedance.com>
On 18.06.25 08:28, lizhe.67@bytedance.com wrote:
> On Tue, 17 Jun 2025 12:22:10 -0300, jgg@ziepe.ca wrote:
>
>> Weird, but I would not expect this as a general rule, not sure we
>> should rely on it.
>>
>> I would say exported function should not get automatically
>> inlined. That throws all the kprobes into chaos :\
>>
>> BTW, why can't the other patches in this series just use
>> unpin_user_page_range_dirty_lock? The way this stuff is supposed to
>> work is to combine adjacent physical addresses and then invoke
>> unpin_user_page_range_dirty_lock() on the start page of the physical
>> range. This is why we have the gup_folio_range_next() which does the
>> segmentation in an efficient way.
>>
>> Combining adjacent physical is basically free math.
>>
>> Segmenting to folios in the vfio side doesn't make a lot of sense,
>> IMHO.
>>
>> drivers/vfio/vfio_iommu_type1.c | 35 +++++++++++++++++++++++++++++----
>> 1 file changed, 31 insertions(+), 4 deletions(-)
>>
>> diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c
>> index e952bf8bdfab..159ba80082a8 100644
>> --- a/drivers/vfio/vfio_iommu_type1.c
>> +++ b/drivers/vfio/vfio_iommu_type1.c
>> @@ -806,11 +806,38 @@ static long vfio_unpin_pages_remote(struct vfio_dma *dma, dma_addr_t iova,
>> bool do_accounting)
>> {
>> long unlocked = 0, locked = vpfn_pages(dma, iova, npage);
>> - long i;
>>
>> - for (i = 0; i < npage; i++)
>> - if (put_pfn(pfn++, dma->prot))
>> - unlocked++;
>> + while (npage) {
>> + long nr_pages = 1;
>> +
>> + if (!is_invalid_reserved_pfn(pfn)) {
>> + struct page *page = pfn_to_page(pfn);
>> + struct folio *folio = page_folio(page);
>> + long folio_pages_num = folio_nr_pages(folio);
>> +
>> + /*
>> + * For a folio, it represents a physically
>> + * contiguous set of bytes, and all of its pages
>> + * share the same invalid/reserved state.
>> + *
>> + * Here, our PFNs are contiguous. Therefore, if we
>> + * detect that the current PFN belongs to a large
>> + * folio, we can batch the operations for the next
>> + * nr_pages PFNs.
>> + */
>> + if (folio_pages_num > 1)
>> + nr_pages = min_t(long, npage,
>> + folio_pages_num -
>> + folio_page_idx(folio, page));
>> +
>> + unpin_user_folio_dirty_locked(folio, nr_pages,
>> + dma->prot & IOMMU_WRITE);
>
> Are you suggesting that we should directly call
> unpin_user_page_range_dirty_lock() here (patch 3/3) instead?
>
> BTW, it appears that implementing unpin_user_folio_dirty_locked()
> as an inline function may not be viable for vfio, given that
> gup_put_folio() is not exported.
The compiler seems to properly inline like before, so I think we can
keep that. @Jason correct me if I am wrong.
--
Cheers,
David / dhildenb
next prev parent reply other threads:[~2025-06-18 8:20 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-17 4:18 [PATCH v4 0/3] optimize vfio_unpin_pages_remote() for large folio lizhe.67
2025-06-17 4:18 ` [PATCH v4 1/3] vfio/type1: batch vfio_find_vpfn() in function vfio_unpin_pages_remote() lizhe.67
2025-06-17 4:18 ` [PATCH v4 2/3] gup: introduce unpin_user_folio_dirty_locked() lizhe.67
2025-06-17 7:35 ` David Hildenbrand
2025-06-17 13:42 ` Jason Gunthorpe
2025-06-17 13:45 ` David Hildenbrand
2025-06-17 13:58 ` David Hildenbrand
2025-06-17 14:04 ` David Hildenbrand
2025-06-17 15:22 ` Jason Gunthorpe
2025-06-18 6:28 ` lizhe.67
2025-06-18 8:20 ` David Hildenbrand [this message]
2025-06-18 11:36 ` Jason Gunthorpe
2025-06-18 11:40 ` David Hildenbrand
2025-06-18 11:42 ` David Hildenbrand
2025-06-18 11:46 ` Jason Gunthorpe
2025-06-18 11:52 ` David Hildenbrand
2025-06-18 11:56 ` Jason Gunthorpe
2025-06-18 12:19 ` lizhe.67
2025-06-18 13:23 ` Jason Gunthorpe
2025-06-19 9:05 ` lizhe.67
2025-06-19 12:35 ` Jason Gunthorpe
2025-06-19 12:49 ` lizhe.67
2025-06-17 4:18 ` [PATCH v4 3/3] vfio/type1: optimize vfio_unpin_pages_remote() for large folio lizhe.67
2025-06-17 7:43 ` David Hildenbrand
2025-06-17 9:21 ` [PATCH v4 2/3] gup: introduce unpin_user_folio_dirty_locked() lizhe.67
2025-06-17 9:27 ` David Hildenbrand
2025-06-17 9:47 ` [PATCH v4 3/3] vfio/type1: optimize vfio_unpin_pages_remote() for large folio lizhe.67
2025-06-17 9:49 ` David Hildenbrand
2025-06-17 12:42 ` lizhe.67
2025-06-17 13:47 ` David Hildenbrand
2025-06-18 6:11 ` lizhe.67
2025-06-18 7:22 ` lizhe.67
2025-06-18 8:54 ` David Hildenbrand
2025-06-18 9:39 ` lizhe.67
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=c485543e-8450-448e-9db3-d459f2096496@redhat.com \
--to=david@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=alex.williamson@redhat.com \
--cc=jgg@ziepe.ca \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=lizhe.67@bytedance.com \
--cc=peterx@redhat.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;
as well as URLs for NNTP newsgroup(s).