mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Dave Hansen <dave.hansen@intel.com>
To: Maciej Wieczor-Retman <m.wieczorretman@pm.me>,
	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>
Cc: 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: Mon, 23 Feb 2026 12:33:01 -0800	[thread overview]
Message-ID: <b3828f63-fa70-431b-bafa-c324861c9eb3@intel.com> (raw)
In-Reply-To: <51598144b682a57f50ec8da65a52b005701f309e.1768845098.git.m.wieczorretman@pm.me>

>  #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.

On to the rest...

> Reset the pointer's tag by sign extending the tag bits in macros that do
> pointer arithmetic in address conversions. There will be no change in
> compiled code with KASAN disabled since the compiler will optimize the
> __tag_reset() out.

Nit: there's no "macro" for the rest. They're functions. I also don't
_care_ how __tag_reset() works here. Don't explain implementation details.

> index 2f0e47be79a4..01f9e6233bba 100644
> --- a/arch/x86/include/asm/page_64.h
> +++ b/arch/x86/include/asm/page_64.h
> @@ -22,6 +22,7 @@ extern unsigned long direct_map_physmem_end;
>  
>  static __always_inline unsigned long __phys_addr_nodebug(unsigned long x)
>  {
> +	x = __tag_reset(x);
>  	unsigned long y = x - __START_KERNEL_map;
>  
>  	/* use the carry flag to determine if x was < __START_KERNEL_map */
> diff --git a/arch/x86/mm/physaddr.c b/arch/x86/mm/physaddr.c
> index 8d31c6b9e184..8f18273be0d2 100644
> --- a/arch/x86/mm/physaddr.c
> +++ b/arch/x86/mm/physaddr.c
> @@ -14,6 +14,7 @@
>  #ifdef CONFIG_DEBUG_VIRTUAL
>  unsigned long __phys_addr(unsigned long x)
>  {
> +	x = __tag_reset(x);
>  	unsigned long y = x - __START_KERNEL_map;

I know all the virt-to/from-phys functions are a mess. But could we
please take a wee peek here at refactoring them so this doesn't need to
be done *twice*?

I also think the changelog here needs to include something about the
idea that arbitrary kernel pointers are assumed to be tagged and that
these functions mostly accept those arbitrary pointers.


> @@ -35,6 +36,7 @@ EXPORT_SYMBOL(__phys_addr);
>  
>  bool __virt_addr_valid(unsigned long x)
>  {
> +	x = __tag_reset(x);
>  	unsigned long y = x - __START_KERNEL_map;
>  
>  	/* use the carry flag to determine if x was < __START_KERNEL_map */

It also occurs to me that having a helper that does:

	x - __START_KERNEL_map;

it could do the tag reset, which might consolidate all of these sites.

  reply	other threads:[~2026-02-23 20:33 UTC|newest]

Thread overview: 21+ 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: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 [this message]
2026-02-25  8:17     ` Maciej Wieczor-Retman
2026-02-25 14:48       ` Dave Hansen
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=b3828f63-fa70-431b-bafa-c324861c9eb3@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome