From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-106119.protonmail.ch (mail-106119.protonmail.ch [79.135.106.119]) (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 5D4BB30FC30 for ; Wed, 25 Feb 2026 08:17:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=79.135.106.119 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772007473; cv=none; b=EkN2jUkW3T/fyPzpimXsXrJBGnUvSNvSD9W2dsq9pDKHEN0NPVML/ac2iU5dMwPT//lCMeCUiLE/HeArQRpZUajMXag93dozx2PMOv2UcsFNb4raPNOeR4JzCOsm/dIe+Kj2IBhKuF5iGnWLvs/IwLkkWSWUdN/RGryKi97vg1Y= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772007473; c=relaxed/simple; bh=eIRJk8NaSx/igwAdYtfsWTg4/rnhKKuDE6rt+XC9Xoc=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=j6laTANhnwQf3H1xFjTtSqG11kGFhTzAz6fH8c/SFcbNOL+X/SBV6bnYzDdW6w/H1/3625D/SqlXBnLiRNXB51w+KvX6TiHSLnGhks4wz4KwiA+LgxnGpHvzcYrVDYhqqD+8cAZH0A4EGFhIoAi7baVvvlo/QG6nARiFzslsZLg= 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=afOzGAfl; arc=none smtp.client-ip=79.135.106.119 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="afOzGAfl" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pm.me; s=protonmail3; t=1772007469; x=1772266669; bh=+lg/bS/z5ambMFxeMVYisHJMCEx3NTx2voLcKtr72AQ=; 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=afOzGAfl4AQHCN2p+uMkXhYrNway3G1guDrP2Ml9w6Ki2svOAMvaGyMEaS8rBzOz7 2ZClLh913W1nHPNteFwNBoLHLb3PDpXWjH7IFH1lqcH+GCOsU0SJPhLuycvnXh4tha ENXN7QMK08BrYc+AJxZFSbk2bWmmeygxjQu0YbfJfcxSQ65KYOVVr91Fsc6q/wnGer u7twPq+3K/oDV7ebP36VLeFwKJyEIuBTMfEVAPN8psszzlLoXShkvDbBF+Z608zPAy psi4frzRctstUbk33p6SXbrAMyaFR/pdPMY06gXbcOfCyGUrsBSKShOODYemEI9gDN aRrS+79kzBCeg== Date: Wed, 25 Feb 2026 08:17:45 +0000 To: Dave Hansen From: Maciej Wieczor-Retman Cc: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Andy Lutomirski , Peter Zijlstra , Maciej Wieczor-Retman , Alexander Potapenko , linux-kernel@vger.kernel.org Subject: Re: [PATCH v9 05/13] x86/mm: Reset tag for virtual to physical address conversions Message-ID: In-Reply-To: References: <51598144b682a57f50ec8da65a52b005701f309e.1768845098.git.m.wieczorretman@pm.me> Feedback-ID: 164464600:user:proton X-Pm-Message-ID: 28e67d153d6100ed9b43d10fc2c31542a3662877 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=utf-8 Content-Transfer-Encoding: quoted-printable On 2026-02-23 at 12:33:01 -0800, Dave Hansen wrote: >> #ifdef CONFIG_X86_64 >> #include >> @@ -65,6 +66,13 @@ static inline void copy_user_page(void *to, void *fro= m, 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) ({=09=09=09=09=09=09=09\ >> +=09void *__addr =3D __va(page_to_pfn((struct page *)x) << PAGE_SHIFT);= =09\ >> +=09__tag_set(__addr, page_kasan_tag(x));=09=09=09=09=09\ >> +}) >> +#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? arm64's pretty similar so I suppose it should work. >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. Okay, I'll rewrite it. >> 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; >> =20 >> static __always_inline unsigned long __phys_addr_nodebug(unsigned long = x) >> { >> +=09x =3D __tag_reset(x); >> =09unsigned long y =3D x - __START_KERNEL_map; >> =20 >> =09/* 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) >> { >> +=09x =3D __tag_reset(x); >> =09unsigned long y =3D 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. > Okay, I'll add that in. > >> @@ -35,6 +36,7 @@ EXPORT_SYMBOL(__phys_addr); >> =20 >> bool __virt_addr_valid(unsigned long x) >> { >> +=09x =3D __tag_reset(x); >> =09unsigned long y =3D x - __START_KERNEL_map; >> =20 >> =09/* use the carry flag to determine if x was < __START_KERNEL_map */ > >It also occurs to me that having a helper that does: > >=09x - __START_KERNEL_map; > >it could do the tag reset, which might consolidate all of these sites. Thanks! It's a good idea, I'll do that. --=20 Kind regards Maciej Wiecz=C3=B3r-Retman