[PATCH v12 06/15] kasan: arm64: x86: Make page_to_virt() KASAN aware
Maciej Wieczor-Retman
maciej.wieczor-retman at intel.com
Mon May 18 05:59:04 PDT 2026
On 2026-05-18 at 12:56:51 +0100, Will Deacon wrote:
>On Mon, Mar 30, 2026 at 02:33:43PM +0000, Maciej Wieczor-Retman wrote:
>> From: Maciej Wieczor-Retman <maciej.wieczor-retman at intel.com>
>> diff --git a/arch/arm64/include/asm/memory.h b/arch/arm64/include/asm/memory.h
>> index 875c0bd0d85a..39dd0071d3ec 100644
>> --- a/arch/arm64/include/asm/memory.h
>> +++ b/arch/arm64/include/asm/memory.h
>> @@ -411,11 +411,6 @@ static inline unsigned long virt_to_pfn(const void *kaddr)
>> */
>>
>> #if defined(CONFIG_DEBUG_VIRTUAL)
>> -#define page_to_virt(x) ({ \
>> - __typeof__(x) __page = x; \
>> - void *__addr = __va(page_to_phys(__page)); \
>> - (void *)__tag_set((const void *)__addr, page_kasan_tag(__page));\
>> -})
>
>So here we're using '__page' to avoid multiple evaluations of 'x'...
>
...
>> diff --git a/include/linux/mm.h b/include/linux/mm.h
>> index 09044934dda8..f234650a4edf 100644
>> --- a/include/linux/mm.h
>> +++ b/include/linux/mm.h
>> @@ -117,7 +117,10 @@ extern int mmap_rnd_compat_bits __read_mostly;
>> #endif
>>
>> #ifndef page_to_virt
>> -#define page_to_virt(x) __va(PFN_PHYS(page_to_pfn(x)))
>> +#define page_to_virt(x) ({ \
>> + void *__addr = __va(PFN_PHYS(page_to_pfn((struct page *)x))); \
>> + kasan_set_tag(__addr, page_kasan_tag(x)); \
>> +})
>
>... but in the new code you're proposing, you evaluate 'x' twice.
>
>Is there a reason not to take the arm64 code as-is?
>
>Will
I was going for less lines in this macro when I initially wrote it. But you're
right, the arm64 version is better, I'll switch to it.
Thanks!
--
Kind regards
Maciej Wieczór-Retman
More information about the linux-arm-kernel
mailing list