From: Shivank Garg <shivankg@amd.com>
To: "Matthew Wilcox (Oracle)" <willy@infradead.org>, linux-mm@kvack.org
Cc: David Hildenbrand <david@redhat.com>
Subject: Re: [RFC PATCH 2/3] mm: Create snapshot_page()
Date: Wed, 12 Feb 2025 14:24:35 +0530 [thread overview]
Message-ID: <5c04577e-6869-479b-bd22-c8868a1fc50f@amd.com> (raw)
In-Reply-To: <20250210212142.4002210-3-willy@infradead.org>
Hi Willy,
On 2/11/2025 2:51 AM, Matthew Wilcox (Oracle) wrote:
< snip >
...
> +const struct folio *snapshot_page(struct folio *foliop, struct page *precise,
> + unsigned long *idxp, const struct page *unstable)
> +{
> + struct folio *folio;
> + unsigned long head;
> + unsigned long idx, nr_pages = 1;
> + int loops = 5;
> +
> +again:
> + memcpy(precise, unstable, sizeof(struct page));
> + head = precise->compound_head;
> + /* Open-coded !PageTail because page_is_fake_head() doesn't work here */
> + if ((head & 1) == 0) {
> + folio = (struct folio *)precise;
> + *idxp = 0;
> + /* Not a tail, not a head, we have a single page */
> + if (!folio_test_large(folio))
> + goto out;
> + folio = (struct folio *)unstable;
> + } else {
> + folio = (struct folio *)(head - 1);
> + *idxp = folio_page_idx(folio, unstable);
> + }
> +
> + if (idx < MAX_FOLIO_NR_PAGES || folio_test_hugetlb(folio)) {
idx is not initialized before use. I think you meant *idxp here.
> + memcpy(foliop, folio, sizeof(struct folio));
> + nr_pages = folio_nr_pages(foliop);
> + folio = foliop;
> + }
> +
> + if (idx > nr_pages) {
> + if (loops-- > 0)
> + goto again;
> + pr_warn("page does not match folio\n");
> + precise->compound_head &= ~1UL;
> + folio = (struct folio *)precise;
> + *idxp = 0;
> + }
> +out:
> + return folio;
> +}
Please consider adding my
Reviewed-by: Shivank Garg <shivankg@amd.com>
with this fix:
diff --git a/mm/util.c b/mm/util.c
index 9f9cf3933eb1..155493b71d28 100644
--- a/mm/util.c
+++ b/mm/util.c
@@ -1253,7 +1253,7 @@ const struct folio *snapshot_page(struct folio *foliop, struct page *precise,
{
struct folio *folio;
unsigned long head;
- unsigned long idx, nr_pages = 1;
+ unsigned long nr_pages = 1;
int loops = 5;
again:
@@ -1272,13 +1272,13 @@ const struct folio *snapshot_page(struct folio *foliop, struct page *precise,
*idxp = folio_page_idx(folio, unstable);
}
- if (idx < MAX_FOLIO_NR_PAGES || folio_test_hugetlb(folio)) {
+ if (*idxp < MAX_FOLIO_NR_PAGES || folio_test_hugetlb(folio)) {
memcpy(foliop, folio, sizeof(struct folio));
nr_pages = folio_nr_pages(foliop);
folio = foliop;
}
- if (idx > nr_pages) {
+ if (*idxp > nr_pages) {
if (loops-- > 0)
goto again;
pr_warn("page does not match folio\n");
next prev parent reply other threads:[~2025-02-12 8:54 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-10 21:21 [RFC PATCH 0/3] snapshot_page() Matthew Wilcox (Oracle)
2025-02-10 21:21 ` [RFC PATCH 1/3] mm: Constify folio_mapping() and swapcache_mapping() Matthew Wilcox (Oracle)
2025-02-11 20:04 ` David Hildenbrand
2025-02-12 8:56 ` Shivank Garg
2025-02-10 21:21 ` [RFC PATCH 2/3] mm: Create snapshot_page() Matthew Wilcox (Oracle)
2025-02-12 8:54 ` Shivank Garg [this message]
2025-02-14 21:18 ` David Hildenbrand
2025-04-17 13:52 ` David Hildenbrand
2025-02-10 21:21 ` [RFC PATCH 3/3] proc: Use snapshot_page() in kpageflags Matthew Wilcox (Oracle)
2025-02-11 21:17 ` Zi Yan
2025-02-12 8:57 ` Shivank Garg
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=5c04577e-6869-479b-bd22-c8868a1fc50f@amd.com \
--to=shivankg@amd.com \
--cc=david@redhat.com \
--cc=linux-mm@kvack.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