From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 A3AD62DCBEB for ; Thu, 8 Jan 2026 17:56:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767895007; cv=none; b=DqrI/IO7XEelOJC5RqYy9iipQdmTBkyh/L6KoRSUbjGaxvGutMByh/spQvV8Bwje5CIRclS7ozsuwb9+a6HfQKRo09S+UmyZXNR6cCAY717G1mSPH97VXD+szl12jy09yqlcSv6gOBtXhcxhYHQu6AsRRsVcHdzkAibbKMNOoBs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767895007; c=relaxed/simple; bh=w/QLun24lbtHii2xsaLuuKpk/iaodRrWwMtJGRI8v2Q=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=BpJjpSlI6RR6sy7TUvOAZBmp8avaFLRShy+Zy0N/CWQOCySIvsK1Np61E5aLY8bjI9qpY4T8Nv0OzQMPix/Qc/4UZ4ALdbTc5Zi8XAfKN7zWV7dghFsg6NqpBORpFV+BiTIliTs7GcGPrpUXhKMwBVBLgOpTA2xQX06JeoSSJZg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=a+78jq3R; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="a+78jq3R" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5BEA0C116C6; Thu, 8 Jan 2026 17:56:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1767895007; bh=w/QLun24lbtHii2xsaLuuKpk/iaodRrWwMtJGRI8v2Q=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=a+78jq3RqBJgK4cIrQuLNVR/+PIoAzqHbdf1iJY5WrJNo1abFBr86lp4LW7IGujGf 7NqmWKUeZDNHD5CG29NJ8TnXtEDD/YyH6zzywPW+6zBaBftYsQuaXGDGXtkKEk7sWO 9o4sWunISQpCrz9w2ezuPrfH2AePhh/IrwnTiO9mcmYROnjVcOiGQI7YOyAvL7ajlt YLw5m6RuGa388VqebBzQgZYooFD7zqe7IlVWUTG5oCyQVlrF+HhJGN4xunCJpJfXgT EYED+MQWHyIxG79yg9HHk7Xg/Nlv3hD2u+6bmmAqHVmdKA07TfrmlQkHUOW0HbWio4 IK2OvPsjiBVmA== Date: Thu, 8 Jan 2026 17:56:39 +0000 From: Will Deacon To: Maciej Wieczor-Retman Cc: Andrey Ryabinin , Alexander Potapenko , Andrey Konovalov , Dmitry Vyukov , Vincenzo Frascino , Catalin Marinas , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Andrew Morton , David Hildenbrand , Lorenzo Stoakes , "Liam R. Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Samuel Holland , Maciej Wieczor-Retman , linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com, linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org Subject: Re: [PATCH v7 02/15] kasan: arm64: x86: Make special tags arch specific Message-ID: References: <0db7ec3b1a813b4d9e3aa8648b3c212166a248b7.1765386422.git.m.wieczorretman@pm.me> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <0db7ec3b1a813b4d9e3aa8648b3c212166a248b7.1765386422.git.m.wieczorretman@pm.me> On Wed, Dec 10, 2025 at 05:28:43PM +0000, Maciej Wieczor-Retman wrote: > From: Samuel Holland > > KASAN's tag-based mode defines multiple special tag values. They're > reserved for: > - Native kernel value. On arm64 it's 0xFF and it causes an early return > in the tag checking function. > - Invalid value. 0xFE marks an area as freed / unallocated. It's also > the value that is used to initialize regions of shadow memory. > - Min and max values. 0xFD is the highest value that can be randomly > generated for a new tag. 0 is the minimal value with the exception of > arm64's hardware mode where it is equal to 0xF0. > > Metadata macro is also defined: > - Tag width equal to 8. > > Tag-based mode on x86 is going to use 4 bit wide tags so all the above > values need to be changed accordingly. > > Make tag width and native kernel tag arch specific for x86 and arm64. > > Base the invalid tag value and the max value on the native kernel tag > since they follow the same pattern on both mentioned architectures. > > Also generalize KASAN_SHADOW_INIT and 0xff used in various > page_kasan_tag* helpers. > > Give KASAN_TAG_MIN the default value of zero, and move the special value > for hw_tags arm64 to its arch specific kasan-tags.h. > > Signed-off-by: Samuel Holland > Co-developed-by: Maciej Wieczor-Retman > Signed-off-by: Maciej Wieczor-Retman > --- > Changelog v7: > - Reorder defines of arm64 tag width to prevent redefinition warnings. > - Remove KASAN_TAG_MASK so it's only defined in mmzone.h (Andrey > Konovalov) > - Merge the 'support tag widths less than 8 bits' with this patch since > they do similar things and overwrite each other. (Alexander) > > Changelog v6: > - Add hardware tags KASAN_TAG_WIDTH value to the arm64 arch file. > - Keep KASAN_TAG_MASK in the mmzone.h. > - Remove ifndef from KASAN_SHADOW_INIT. > > Changelog v5: > - Move KASAN_TAG_MIN to the arm64 kasan-tags.h for the hardware KASAN > mode case. > > Changelog v4: > - Move KASAN_TAG_MASK to kasan-tags.h. > > Changelog v2: > - Remove risc-v from the patch. > > MAINTAINERS | 2 +- > arch/arm64/include/asm/kasan-tags.h | 14 ++++++++++++++ > arch/arm64/include/asm/kasan.h | 2 -- > arch/arm64/include/asm/uaccess.h | 1 + > arch/x86/include/asm/kasan-tags.h | 9 +++++++++ > include/linux/kasan-tags.h | 19 ++++++++++++++----- > include/linux/kasan.h | 3 +-- > include/linux/mm.h | 6 +++--- > include/linux/page-flags-layout.h | 9 +-------- > 9 files changed, 44 insertions(+), 21 deletions(-) > create mode 100644 arch/arm64/include/asm/kasan-tags.h > create mode 100644 arch/x86/include/asm/kasan-tags.h > > diff --git a/MAINTAINERS b/MAINTAINERS > index 7bf6385efe04..a591598cc4b5 100644 > --- a/MAINTAINERS > +++ b/MAINTAINERS > @@ -13420,7 +13420,7 @@ L: kasan-dev@googlegroups.com > S: Maintained > B: https://bugzilla.kernel.org/buglist.cgi?component=Sanitizers&product=Memory%20Management > F: Documentation/dev-tools/kasan.rst > -F: arch/*/include/asm/*kasan.h > +F: arch/*/include/asm/*kasan*.h > F: arch/*/mm/kasan_init* > F: include/linux/kasan*.h > F: lib/Kconfig.kasan > diff --git a/arch/arm64/include/asm/kasan-tags.h b/arch/arm64/include/asm/kasan-tags.h > new file mode 100644 > index 000000000000..259952677443 > --- /dev/null > +++ b/arch/arm64/include/asm/kasan-tags.h > @@ -0,0 +1,14 @@ > +/* SPDX-License-Identifier: GPL-2.0 */ > +#ifndef __ASM_KASAN_TAGS_H > +#define __ASM_KASAN_TAGS_H > + > +#define KASAN_TAG_KERNEL 0xFF /* native kernel pointers tag */ > + > +#ifdef CONFIG_KASAN_HW_TAGS > +#define KASAN_TAG_MIN 0xF0 /* minimum value for random tags */ > +#define KASAN_TAG_WIDTH 4 > +#else > +#define KASAN_TAG_WIDTH 8 > +#endif Shouldn't this be 0 when KASAN is not in use at all? Will