From: "Aneesh Kumar K.V" <aneesh.kumar@linux.ibm.com>
To: linuxppc-dev@lists.ozlabs.org, mpe@ellerman.id.au
Cc: "Aneesh Kumar K.V" <aneesh.kumar@linux.ibm.com>,
Kefeng Wang <wangkefeng.wang@huawei.com>
Subject: [PATCH v2] powerpc/mm: Use is_vmalloc_addr to validate addr
Date: Mon, 4 Jul 2022 12:09:09 +0530 [thread overview]
Message-ID: <20220704063909.295546-1-aneesh.kumar@linux.ibm.com> (raw)
Instead of high_memory use is_vmalloc_addr to validate that the address is
not in the vmalloc range.
Cc: Kefeng Wang <wangkefeng.wang@huawei.com>
Cc: Christophe Leroy <christophe.leroy@csgroup.eu>
Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com>
-
---
arch/powerpc/include/asm/page.h | 10 ++++------
arch/powerpc/mm/mem.c | 11 +++++++++++
2 files changed, 15 insertions(+), 6 deletions(-)
diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
index e5f75c70eda8..977835570db3 100644
--- a/arch/powerpc/include/asm/page.h
+++ b/arch/powerpc/include/asm/page.h
@@ -131,12 +131,10 @@ static inline bool pfn_valid(unsigned long pfn)
#define virt_to_pfn(kaddr) (__pa(kaddr) >> PAGE_SHIFT)
#define virt_to_page(kaddr) pfn_to_page(virt_to_pfn(kaddr))
#define pfn_to_kaddr(pfn) __va((pfn) << PAGE_SHIFT)
-
-#define virt_addr_valid(vaddr) ({ \
- unsigned long _addr = (unsigned long)vaddr; \
- _addr >= PAGE_OFFSET && _addr < (unsigned long)high_memory && \
- pfn_valid(virt_to_pfn(_addr)); \
-})
+#ifndef __ASSEMBLY__
+extern bool __virt_addr_valid(unsigned long kaddr);
+#endif
+#define virt_addr_valid(kaddr) __virt_addr_valid((unsigned long) (kaddr))
/*
* On Book-E parts we need __va to parse the device tree and we can't
diff --git a/arch/powerpc/mm/mem.c b/arch/powerpc/mm/mem.c
index 7b0d286bf9ba..622f8bac808b 100644
--- a/arch/powerpc/mm/mem.c
+++ b/arch/powerpc/mm/mem.c
@@ -406,3 +406,14 @@ int devmem_is_allowed(unsigned long pfn)
* the EHEA driver. Drop this when drivers/net/ethernet/ibm/ehea is removed.
*/
EXPORT_SYMBOL_GPL(walk_system_ram_range);
+
+bool __virt_addr_valid(unsigned long kaddr)
+{
+ if (kaddr < PAGE_OFFSET)
+ return false;
+ if (is_vmalloc_addr((void *) kaddr))
+ return false;
+ return pfn_valid(virt_to_pfn(kaddr));
+}
+EXPORT_SYMBOL(__virt_addr_valid);
+
--
2.36.1
next reply other threads:[~2022-07-04 6:40 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-04 6:39 Aneesh Kumar K.V [this message]
2022-07-04 7:13 ` [PATCH v2] powerpc/mm: Use is_vmalloc_addr to validate addr Christophe Leroy
2022-07-04 7:45 ` Aneesh Kumar K V
2022-07-04 7:55 ` Christophe Leroy
2022-07-06 12:50 ` Christophe Leroy
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=20220704063909.295546-1-aneesh.kumar@linux.ibm.com \
--to=aneesh.kumar@linux.ibm.com \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=mpe@ellerman.id.au \
--cc=wangkefeng.wang@huawei.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).