From: Dave Hansen <dave.hansen@intel.com>
To: Maciej Wieczor-Retman <m.wieczorretman@pm.me>
Cc: Thomas Gleixner <tglx@kernel.org>, Ingo Molnar <mingo@redhat.com>,
Borislav Petkov <bp@alien8.de>,
Dave Hansen <dave.hansen@linux.intel.com>,
x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
Andy Lutomirski <luto@kernel.org>,
Peter Zijlstra <peterz@infradead.org>,
Maciej Wieczor-Retman <maciej.wieczor-retman@intel.com>,
Alexander Potapenko <glider@google.com>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v9 05/13] x86/mm: Reset tag for virtual to physical address conversions
Date: Wed, 25 Feb 2026 06:48:09 -0800 [thread overview]
Message-ID: <37a4b02c-5860-4d02-893e-e624b758f042@intel.com> (raw)
In-Reply-To: <aZ6sZv3PdGiEdBC1@wieczorr-mobl1.localdomain>
On 2/25/26 00:17, Maciej Wieczor-Retman wrote:
> On 2026-02-23 at 12:33:01 -0800, Dave Hansen wrote:
>>> #ifdef CONFIG_X86_64
>>> #include <asm/page_64.h>
>>> @@ -65,6 +66,13 @@ static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
>>> * virt_to_page(kaddr) returns a valid pointer if and only if
>>> * virt_addr_valid(kaddr) returns true.
>>> */
>>> +
>>> +#ifdef CONFIG_KASAN_SW_TAGS
>>> +#define page_to_virt(x) ({ \
>>> + void *__addr = __va(page_to_pfn((struct page *)x) << PAGE_SHIFT); \
>>> + __tag_set(__addr, page_kasan_tag(x)); \
>>> +})
>>> +#endif
>>
>> Can we pretty please keep this in arch-independent code?
>>
>> The idea of tags is not x86-specific and I can almost guarantee that x86
>> won't be the last one needing this.
>
> Do you mean adding a KASAN oriented page_to_virt() that's arch independent? I'd
> guess next to the regular one, in include/linux/mm.h?
Close.
There should be one and one only arch-independent page_to_virt() that
uses __tag_set(). Then, since __tag_set() gets compiled out when KASAN
is off, you get to keep a single page_to_virt() implementation that
compiles down to the original implementation when KASAN is off.
BTW, you can get __tag_set() down to a single implementation too:
static inline void *__tag_set(const void *__addr, u8 tag)
{
u64 addr = (u64)__addr;
if (IS_ENABLED(CONFIG_KASAN_SW_TAGS)) {
addr &= ~__tag_shifted(KASAN_TAG_BITS_MASK);
addr |= __tag_shifted(tag & KASAN_TAG_BITS_MASK);
}
return (void *)addr;
}
That shifts the actual #ifdeffery all the way back to the constants. At
this level it doesn't really matter much though. Just do whatever is
easy to read.
next prev parent reply other threads:[~2026-02-25 14:48 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-20 14:40 [PATCH v9 00/13] kasan: x86: arm64: KASAN tag-based mode for x86 Maciej Wieczor-Retman
2026-01-20 14:40 ` Maciej Wieczor-Retman
2026-01-20 14:41 ` [PATCH v9 01/13] kasan: sw_tags: Use arithmetic shift for shadow computation Maciej Wieczor-Retman
2026-01-20 14:41 ` [PATCH v9 02/13] kasan: arm64: x86: Make special tags arch specific Maciej Wieczor-Retman
2026-01-20 14:41 ` [PATCH v9 03/13] kasan: Fix inline mode for x86 tag-based mode Maciej Wieczor-Retman
2026-01-20 14:41 ` [PATCH v9 04/13] x86/kasan: Add arch specific kasan functions Maciej Wieczor-Retman
2026-01-20 14:41 ` [PATCH v9 05/13] x86/mm: Reset tag for virtual to physical address conversions Maciej Wieczor-Retman
2026-02-23 20:33 ` Dave Hansen
2026-02-25 8:17 ` Maciej Wieczor-Retman
2026-02-25 14:48 ` Dave Hansen [this message]
2026-01-20 14:41 ` [PATCH v9 06/13] mm/execmem: Untag addresses in EXECMEM_ROX related pointer arithmetic Maciej Wieczor-Retman
2026-01-22 10:32 ` Mike Rapoport
2026-01-23 9:37 ` Maciej Wieczor-Retman
2026-01-20 14:41 ` [PATCH v9 07/13] x86/mm: Use physical address comparisons in fill_p*d/pte Maciej Wieczor-Retman
2026-01-20 14:41 ` [PATCH v9 08/13] x86/kasan: Initialize KASAN raw shadow memory Maciej Wieczor-Retman
2026-01-20 14:42 ` [PATCH v9 09/13] x86/mm: Reset tags in a canonical address helper call Maciej Wieczor-Retman
2026-01-20 14:42 ` [PATCH v9 10/13] x86/mm: Initialize LAM_SUP Maciej Wieczor-Retman
2026-01-20 14:42 ` [PATCH v9 11/13] x86: Increase minimal SLAB alignment for KASAN Maciej Wieczor-Retman
2026-01-20 14:42 ` [PATCH v9 12/13] x86/kasan: Use a logical bit shift for kasan_mem_to_shadow Maciej Wieczor-Retman
2026-01-20 14:42 ` [PATCH v9 13/13] x86/kasan: Make software tag-based kasan available Maciej Wieczor-Retman
2026-01-20 17:54 ` [PATCH v9 00/13] kasan: x86: arm64: KASAN tag-based mode for x86 Andrey Konovalov
2026-01-20 19:18 ` Maciej Wieczor-Retman
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=37a4b02c-5860-4d02-893e-e624b758f042@intel.com \
--to=dave.hansen@intel.com \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=glider@google.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@kernel.org \
--cc=m.wieczorretman@pm.me \
--cc=maciej.wieczor-retman@intel.com \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=tglx@kernel.org \
--cc=x86@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.