From: Tianyi Chen <hi@tychen.cc>
To: Mike Rapoport <rppt@kernel.org>
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: [PATCH v2 3/4] tools: use __pa() in virt_to_phys()
Date: Wed, 23 Sep 2026 11:31:25 +0900 [thread overview]
Message-ID: <20260923023126.1910311-4-hi@tychen.cc> (raw)
In-Reply-To: <20260923023126.1910311-1-hi@tychen.cc>
With 32-bit pointers and a 64-bit phys_addr_t, GCC warns about the
pointer-to-integer cast in virt_to_phys(). It can also sign-extend
pointers whose top bit is set, turning 0x80000000 into 0xffffffff80000000.
Use __pa() to convert through unsigned long before widening the result.
This preserves the unsigned pointer value and matches the other address
conversion helpers.
Reported-by: Mike Rapoport <rppt@kernel.org>
Link: https://lore.kernel.org/r/179007180279.508753.4595268983388589280.b4-review@b4
Assisted-by: LLM
Signed-off-by: Tianyi Chen <hi@tychen.cc>
---
tools/include/linux/mm.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/include/linux/mm.h b/tools/include/linux/mm.h
index 84b5954f66c3..480526de8d65 100644
--- a/tools/include/linux/mm.h
+++ b/tools/include/linux/mm.h
@@ -30,7 +30,7 @@ static inline void *phys_to_virt(unsigned long address)
#define virt_to_phys virt_to_phys
static inline phys_addr_t virt_to_phys(volatile void *address)
{
- return (phys_addr_t)address;
+ return __pa(address);
}
static inline void totalram_pages_inc(void)
--
2.55.0
next prev parent reply other threads:[~2026-09-23 2:32 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-23 2:31 [PATCH v2 0/4] memblock tests: fix BUILD=32 address conversions and warnings Tianyi Chen
2026-09-23 2:31 ` [PATCH v2 1/4] memblock tests: use physical addresses for region removal Tianyi Chen
2026-09-23 2:31 ` [PATCH v2 2/4] memblock tests: zero-extend simulated memory addresses Tianyi Chen
2026-09-23 2:31 ` Tianyi Chen [this message]
2026-09-23 2:31 ` [PATCH v2 4/4] memblock: initialize the region merge end index Tianyi Chen
2026-09-24 7:57 ` [PATCH v2 0/4] memblock tests: fix BUILD=32 address conversions and warnings Mike Rapoport
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=20260923023126.1910311-4-hi@tychen.cc \
--to=hi@tychen.cc \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=rppt@kernel.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