From: Xianting Tian <xianting.tian@linux.alibaba.com>
To: akpm@linux-foundation.org, david@redhat.com, ziy@nvidia.com
Cc: guoren@kernel.org, linux-mm@kvack.org,
linux-kernel@vger.kernel.org,
Xianting Tian <xianting.tian@linux.alibaba.com>
Subject: [PATCH] mm: fixup validation of buddy pfn
Date: Tue, 21 Jun 2022 11:11:18 +0800 [thread overview]
Message-ID: <20220621031118.3650529-1-xianting.tian@linux.alibaba.com> (raw)
For RISC-V arch the first 2MB RAM could be reserved for opensbi,
and the arch code may don't create pages for the first 2MB RAM,
so it would have pfn_base=512 and mem_map began with 512th PFN when
CONFIG_FLATMEM=y.
But __find_buddy_pfn algorithm thinks the start PFN 0, it could get
0 PFN or less than the pfn_base value, so page_is_buddy() can't
verify the page whose PFN is 0 ~ 511, actually we don't have valid
pages for PFN 0 ~ 511.
Actually, buddy system should not assume Arch cretaed pages for
reserved memory, Arch may don't know the implied limitation.
With this patch, we can gurantee a valid buddy no matter what we
have pages for reserved memory or not.
Fixes: 8170ac4700d26f65 ("mm: wrap __find_buddy_pfn() with a necessary buddy page validation")
Signed-off-by: Xianting Tian <xianting.tian@linux.alibaba.com>
---
mm/internal.h | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/mm/internal.h b/mm/internal.h
index c0f8fbe0445b..0ec446caeb2e 100644
--- a/mm/internal.h
+++ b/mm/internal.h
@@ -322,7 +322,8 @@ __find_buddy_pfn(unsigned long page_pfn, unsigned int order)
* The found buddy can be a non PageBuddy, out of @page's zone, or its order is
* not the same as @page. The validation is necessary before use it.
*
- * Return: the found buddy page or NULL if not found.
+ * Return: the found buddy page or NULL if not found or NULL if buddy pfn is
+ * not valid.
*/
static inline struct page *find_buddy_page_pfn(struct page *page,
unsigned long pfn, unsigned int order, unsigned long *buddy_pfn)
@@ -330,6 +331,9 @@ static inline struct page *find_buddy_page_pfn(struct page *page,
unsigned long __buddy_pfn = __find_buddy_pfn(pfn, order);
struct page *buddy;
+ if (!pfn_valid(__buddy_pfn))
+ return NULL;
+
buddy = page + (__buddy_pfn - pfn);
if (buddy_pfn)
*buddy_pfn = __buddy_pfn;
--
2.17.1
next reply other threads:[~2022-06-21 3:11 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-21 3:11 Xianting Tian [this message]
2022-06-21 8:01 ` [PATCH] mm: fixup validation of buddy pfn David Hildenbrand
2022-06-21 8:49 ` Xianting Tian
2022-06-21 22:33 ` Zi Yan
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=20220621031118.3650529-1-xianting.tian@linux.alibaba.com \
--to=xianting.tian@linux.alibaba.com \
--cc=akpm@linux-foundation.org \
--cc=david@redhat.com \
--cc=guoren@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=ziy@nvidia.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