From: Pratyush Yadav <pratyush@kernel.org>
To: Jason Gunthorpe <jgg@nvidia.com>
Cc: Pratyush Yadav <pratyush@kernel.org>,
Pratyush Yadav <me@yadavpratyush.com>,
Matthew Wilcox <willy@infradead.org>,
Alexander Graf <graf@amazon.com>,
Mike Rapoport <rppt@kernel.org>,
Changyuan Lyu <changyuanl@google.com>,
Andrew Morton <akpm@linux-foundation.org>,
Baoquan He <bhe@redhat.com>,
Pasha Tatashin <pasha.tatashin@soleen.com>,
Chris Li <chrisl@kernel.org>, Jason Miu <jasonmiu@google.com>,
linux-kernel@vger.kernel.org, kexec@lists.infradead.org,
linux-mm@kvack.org
Subject: Re: [PATCH] kho: make sure folio being restored is actually from KHO
Date: Tue, 16 Sep 2025 16:52:06 +0200 [thread overview]
Message-ID: <mafs0ldmeh2ll.fsf@kernel.org> (raw)
In-Reply-To: <20250916132759.GC1086830@nvidia.com>
On Tue, Sep 16 2025, Jason Gunthorpe wrote:
> On Tue, Sep 16, 2025 at 03:20:51PM +0200, Pratyush Yadav wrote:
>> >> >> @@ -210,16 +226,16 @@ static void kho_restore_page(struct page *page, unsigned int order)
>> >> >> struct folio *kho_restore_folio(phys_addr_t phys)
>> >> >> {
>> >> >> struct page *page = pfn_to_online_page(PHYS_PFN(phys));
>> >> >> - unsigned long order;
>> >> >> + union kho_page_info info;
>> >> >>
>> >> >> if (!page)
>> >> >> return NULL;
>> >> >>
>> >> >> - order = page->private;
>> >> >> - if (order > MAX_PAGE_ORDER)
>> >> >> + info.page_private = page->private;
>> >> >> + if (info.magic != KHO_PAGE_MAGIC || info.order > MAX_PAGE_ORDER)
>> >
>> > All the impossible checks shoudl be WARN_ON()
>>
>> The mental model I have is that the place that introduced the
>> "impossible" situation should get the WARN(). So for an incorrect phys
>> address (leading to magic mismatch) or incorrect order (say preserved
>> big range using kho_preserve_phys() and restoring it using
>> kho_restore_folio()), the caller is responsible so it should do the
>> WARN(). Does that make sense?
>
> Callers should not pass illegal phys here, WARN at this point is
> appropriate, and maybe under a debug #ifdef or something like that.
>
> This is to make it clear that "test and fail" is not an acceptable way
> to use this API.
Okay, makes sense. Will add.
>
>> Actually, on another look, this patch implicitly makes sure that
>> unaligned phys always fails. This is because deserialize_bitmap() only
>> sets the magic on the head page which is always aligned by the order.
>> For any unaligned phys, the magic will not match.
>
> Makes sense, maybe a comment?
Will do.
>
>> Makes sense. Do you suggest the magic and order checks to also be under
>> KHO_DEBUG, or should they always be done? I am of the opinion that it
>> makes sense to do them always, but I can also understand the argument
>> for disabling them in production for better performance.
>
> I'm ambivalent :)
>
> For now I'd do it always and leave some debug optimization to a future
> project.
Sounds good. Will add them as always for now.
--
Regards,
Pratyush Yadav
next prev parent reply other threads:[~2025-09-16 14:52 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-10 15:34 Pratyush Yadav
2025-09-10 15:44 ` Matthew Wilcox
2025-09-10 15:52 ` Pratyush Yadav
2025-09-10 15:55 ` Jason Gunthorpe
2025-09-16 13:20 ` Pratyush Yadav
2025-09-16 13:27 ` Jason Gunthorpe
2025-09-16 14:52 ` Pratyush Yadav [this message]
2025-09-16 14:37 ` Mike Rapoport
2025-09-16 14:55 ` Pratyush Yadav
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=mafs0ldmeh2ll.fsf@kernel.org \
--to=pratyush@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=bhe@redhat.com \
--cc=changyuanl@google.com \
--cc=chrisl@kernel.org \
--cc=graf@amazon.com \
--cc=jasonmiu@google.com \
--cc=jgg@nvidia.com \
--cc=kexec@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=me@yadavpratyush.com \
--cc=pasha.tatashin@soleen.com \
--cc=rppt@kernel.org \
--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