From nobody Sun Apr 5 04:24:41 2026 Received: from mail-106120.protonmail.ch (mail-106120.protonmail.ch [79.135.106.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 84C9C31715E for ; Tue, 10 Mar 2026 17:54:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=79.135.106.120 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773165256; cv=none; b=b762bXdY3TaMOROupWbZsTSCOeacYbu8haK8ceqoqDA0ynme/PHvVMuLAcmX1zmpfgx9gdOFfYx7Ml7SSbamNrW4aVAjbKC/aY7keqxrDIoN06aXQnES8a4iid3y8WUnxGLPhnG1heh6+gaIWmxzlLvkCGUpv8LVcA5qP/X7WvE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773165256; c=relaxed/simple; bh=7AFthwAm+gatT35eXeU/LM3MuDQxV8VZ/+uxZ3AfbIU=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=tlff5jno4J9jmk7C1OW+5VhrqJ02id1YDLkhTjvM+jBjbb32xI/JfydwYidUjn8whzLNFe7HOU/QlsPSxbjzj1j+w8d22YmP2P247CWDiD3ouvbYD4gHBRGfetmg/N+YogWoPiYuqKtiFfslHlWD+zCNbcoBCUt+07vZYNXgRYc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=pm.me; spf=pass smtp.mailfrom=pm.me; dkim=pass (2048-bit key) header.d=pm.me header.i=@pm.me header.b=ekBW0fZ9; arc=none smtp.client-ip=79.135.106.120 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=pm.me Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pm.me Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pm.me header.i=@pm.me header.b="ekBW0fZ9" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pm.me; s=protonmail3; t=1773165247; x=1773424447; bh=P/sihZxhx1D4j95rOaUZIBK6YpmtfpmdHtZkQ0gkPEM=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector; b=ekBW0fZ9U0pFISQm13VX4gPINMRAG+aUrcMWRdpMtPRYjiU0o+vByxhUb1KF1Zi61 Wj473fxX6LRdP1689VmXcolWLtRbnuQMbnCSFTT0HnvSGZCJhAiYKD0D7nCcfKifzX HTY1ILTnG0Nyth8kynBh5MW/Pwhvgo11LIrvfIhbZzBxzSqTaCk5i/0cajygRZfq6t 6NvpEnFTccnFzqCGSRX8GyxjJI90FXOM/LW8dy6lv5IMqSYssjzRpELia5E7dIXmJM Ezo35ZY2MrgXFt7FrYeylzao0kUrtt89z6DpWmmigWEmVo3++MY62NHhmLVacFeYDz luP/kVPGs1tpQ== Date: Tue, 10 Mar 2026 17:54:02 +0000 To: akpm@linux-foundation.org, Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Andy Lutomirski , Peter Zijlstra From: Maciej Wieczor-Retman Cc: m.wieczorretman@pm.me, Maciej Wieczor-Retman , linux-kernel@vger.kernel.org Subject: [PATCH v11 05/15] x86/mm: Reset pointer tag in x - __START_KERNEL_map instances Message-ID: In-Reply-To: References: Feedback-ID: 164464600:user:proton X-Pm-Message-ID: 5d63b0e957ace989d8e72826c150df393d957212 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Maciej Wieczor-Retman With KASAN software tag-based mode arbitrary kernel pointers can be tagged, and any place where pointer arithmetic is used to convert a virtual address into a physical one can raise errors if the virtual address is tagged. To lower the amount of lines added it's beneficial to move the similar pointer arithmetic to a helper first. Reset the tag in the __phys_addr_kernel_start() which plugs into all the relevant virtual to physical address helpers. Signed-off-by: Maciej Wieczor-Retman --- Changelog v11: - Split off this patch from the tag reset patch. Move x - __START_KERNEL_map to a helper so less lines are added. arch/x86/include/asm/page_64.h | 11 +++++++++-- arch/x86/mm/physaddr.c | 4 ++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/arch/x86/include/asm/page_64.h b/arch/x86/include/asm/page_64.h index 1895c207f629..9260a0d693d6 100644 --- a/arch/x86/include/asm/page_64.h +++ b/arch/x86/include/asm/page_64.h @@ -7,6 +7,7 @@ #ifndef __ASSEMBLER__ #include #include +#include =20 #include #include @@ -20,9 +21,15 @@ extern unsigned long vmalloc_base; extern unsigned long vmemmap_base; extern unsigned long direct_map_physmem_end; =20 +static __always_inline unsigned long __phys_addr_kernel_start(unsigned lon= g x) +{ + x =3D __tag_reset(x); + return x - __START_KERNEL_map; +} + static __always_inline unsigned long __phys_addr_nodebug(unsigned long x) { - unsigned long y =3D x - __START_KERNEL_map; + unsigned long y =3D __phys_addr_kernel_start(x); =20 /* use the carry flag to determine if x was < __START_KERNEL_map */ x =3D y + ((x > y) ? phys_base : (__START_KERNEL_map - PAGE_OFFSET)); @@ -38,7 +45,7 @@ extern unsigned long __phys_addr(unsigned long); =20 static inline unsigned long __phys_addr_symbol(unsigned long x) { - unsigned long y =3D x - __START_KERNEL_map; + unsigned long y =3D __phys_addr_kernel_start(x); =20 /* only check upper bounds since lower bounds will trigger carry */ VIRTUAL_BUG_ON(y >=3D KERNEL_IMAGE_SIZE); diff --git a/arch/x86/mm/physaddr.c b/arch/x86/mm/physaddr.c index 8d31c6b9e184..682e23541228 100644 --- a/arch/x86/mm/physaddr.c +++ b/arch/x86/mm/physaddr.c @@ -14,7 +14,7 @@ #ifdef CONFIG_DEBUG_VIRTUAL unsigned long __phys_addr(unsigned long x) { - unsigned long y =3D x - __START_KERNEL_map; + unsigned long y =3D __phys_addr_kernel_start(x); =20 /* use the carry flag to determine if x was < __START_KERNEL_map */ if (unlikely(x > y)) { @@ -35,7 +35,7 @@ EXPORT_SYMBOL(__phys_addr); =20 bool __virt_addr_valid(unsigned long x) { - unsigned long y =3D x - __START_KERNEL_map; + unsigned long y =3D __phys_addr_kernel_start(x); =20 /* use the carry flag to determine if x was < __START_KERNEL_map */ if (unlikely(x > y)) { --=20 2.53.0