From: David Hildenbrand <david@redhat.com>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Alex Williamson <alex.williamson@redhat.com>,
"kvm@vger.kernel.org" <kvm@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"lizhe.67@bytedance.com" <lizhe.67@bytedance.com>,
Jason Gunthorpe <jgg@nvidia.com>
Subject: Re: [GIT PULL] VFIO updates for v6.17-rc1
Date: Tue, 5 Aug 2025 15:20:15 +0200 [thread overview]
Message-ID: <7f891077-39a2-4c0a-87ec-8ef1a244f7ad@redhat.com> (raw)
In-Reply-To: <CAHk-=wiCYfNp4AJLBORU-c7ZyRBUp66W2-Et6cdQ4REx-GyQ_A@mail.gmail.com>
On 05.08.25 15:00, Linus Torvalds wrote:
> On Tue, 5 Aug 2025 at 10:47, David Hildenbrand <david@redhat.com> wrote:
>>
>> The concern is rather false positives, meaning, you want consecutive
>> PFNs (just like within a folio), but -- because the stars aligned --
>> you get consecutive "struct page" that do not translate to consecutive PFNs.
>
> So I don't think that can happen with a valid 'struct page', because
> if the 'struct page's are in different sections, they will have been
> allocated separately too.
I think you can end up with two memory sections not being consecutive,
but the struct pages being consecutive.
I assume the easiest way to achieve that is having a large-enough memory
hole (PCI hole?) that spans more than section, and memblock just giving
you the next PFN range to use as "struct page".
It's one allocation per memory section, see
sparse_init_nid()->__populate_section_memmap(prn, PAGES_PER_SECTION) ->
memmap_alloc()->memblock_alloc().
With memory hotplug, there might be other weird ways to achieve it I
suspect.
>
> So you can't have two consecutive 'struct page' things without them
> being consecutive pages.
>
> But by all means, if you want to make sure, just compare the page
> sections. But converting them to a PFN and then converting back is
> just crazy.
> > IOW, the logic would literally be something like (this assumes there
> is always at least *one* page):
>
> struct page *page = *pages++;
> int section = page_to_section(page);
>
> for (size_t nr = 1; nr < nr_pages; nr++) {
> if (*pages++ != ++page)
> break;
> if (page_to_section(page) != section)
> break;
> }
> return nr;
I think that would work, and we could limit the section check to the
problematic case only (sparsemem without VMEMMAP).
>
> and yes, I think we only define page_to_section() for
> SECTION_IN_PAGE_FLAGS, but we should fix that and just have a
>
> #define page_to_section(pg) 0
Probably yes, have to think about that.
>
> for the other cases, and the compiler will happily optimize away the
> "oh, it's always zero" case.
>
> So something like that should actually generate reasonable code. It
> *really* shouldn't try to generate a pfn (or, like that horror that I
> didn't pull did, then go *back* from pfn to page)
> > That 'nth_page()' thing is just crazy garbage.
Yes, it's unfortunate garbage we have to use even in folio_page().
>
> And even when fixed to not be garbage, I'm not convinced this needs to
> be in <linux/mm.h>.
Yeah, let's move it to mm/util.c if you agree.
--
Cheers,
David / dhildenb
next prev parent reply other threads:[~2025-08-05 13:20 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-04 22:22 Alex Williamson
2025-08-04 23:55 ` Linus Torvalds
2025-08-05 0:53 ` Alex Williamson
2025-08-05 7:47 ` David Hildenbrand
2025-08-05 11:49 ` Jason Gunthorpe
2025-08-05 12:07 ` David Hildenbrand
2025-08-05 12:38 ` Jason Gunthorpe
2025-08-05 12:41 ` David Hildenbrand
2025-08-05 12:56 ` Jason Gunthorpe
2025-08-05 13:05 ` David Hildenbrand
2025-08-05 13:15 ` Linus Torvalds
2025-08-05 13:19 ` David Hildenbrand
2025-08-05 13:22 ` David Hildenbrand
2025-08-05 13:00 ` Linus Torvalds
2025-08-05 13:20 ` David Hildenbrand [this message]
2025-08-05 13:24 ` David Hildenbrand
2025-08-05 13:28 ` Linus Torvalds
2025-08-05 13:37 ` David Hildenbrand
2025-08-05 13:49 ` Linus Torvalds
2025-08-05 13:25 ` Jason Gunthorpe
2025-08-05 13:33 ` David Hildenbrand
2025-08-05 13:55 ` Jason Gunthorpe
2025-08-05 14:10 ` David Hildenbrand
2025-08-05 14:20 ` Jason Gunthorpe
2025-08-05 14:22 ` David Hildenbrand
2025-08-05 14:24 ` Jason Gunthorpe
2025-08-05 14:26 ` David Hildenbrand
2025-08-05 13:36 ` Linus Torvalds
2025-08-05 13:47 ` David Hildenbrand
2025-08-05 13:51 ` Linus Torvalds
2025-08-05 13:55 ` David Hildenbrand
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=7f891077-39a2-4c0a-87ec-8ef1a244f7ad@redhat.com \
--to=david@redhat.com \
--cc=alex.williamson@redhat.com \
--cc=jgg@nvidia.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lizhe.67@bytedance.com \
--cc=torvalds@linux-foundation.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®