From nobody Mon Feb 9 17:59:21 2026 Received: from mail-244123.protonmail.ch (mail-244123.protonmail.ch [109.224.244.123]) (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 7085443C064 for ; Tue, 20 Jan 2026 14:42:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=109.224.244.123 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768920129; cv=none; b=ouYQPJ1fXyjxHUFEEDxM9FLtmrrrNNtuzSFldxH9cCA9DOpWKVfQosamRhfUDPAmjab2wvsIBAVgPD1SR48EyamkMLm9n65ANROpIFLJ+Gn5Q24aY/ApuwgcHeWqf5oiAPUMXt+s613c/r8ZzBo7FSUsDd5GGWrAwleMNR1+sDQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768920129; c=relaxed/simple; bh=yB8NregIQjCmAem+GsNDjfv3iJUn537VmEgjqJcRgvU=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=IJHc/DITA8Ghv51dv2aQb0iFtcy35fRylz3/DqldDTNrkFaDUkKyS9YpjrJ57R3e80cJpWA1vJo6aJDkYiWm5mYC+chZB2xy0pMM53Z+3qZDn0hsdt9Hz2IP+6WAvn+dN4CpEA/tTgmCnT5x+9lu9WLY2kP6HHmq/cb3HiqIiCg= 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=r8/QUqXH; arc=none smtp.client-ip=109.224.244.123 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="r8/QUqXH" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pm.me; s=protonmail3; t=1768920118; x=1769179318; bh=A25tv44ykjvi1Kbnb5x6U/k0DKYzcpc1BCKXyH8bncU=; 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=r8/QUqXH8gUeUmXQtsLpXDcI0g0lSMhzcDdN4wZ6Mcr2mq3DiHBIG/1T++QBDet5K gekQruSyvn4NhxqmLX3OSG/xzNyzM1IlRhKE1qotu+0FIWW0lSLqTNzJ8coA1ym1eE CxVfNVjOWeUpnBFV0T+Zfj+mbiT/oMhIcEqGWiArRkDN5jy0jM39F7dU4TthEfV9/y aWqoS6+DHGHSDFf9CYeMeYaVcjHjdKV1dZpxUPWxgQHSDq74QXLM4fI0jjWWLrotLX DsZ7i+D7eQcdrmwN9E9JIImIpKVM1+0Fg/THJcldn8aaYMfEdxIe5rtIhtknJ98dTs QBbhsYiSJ5PGw== Date: Tue, 20 Jan 2026 14:41:55 +0000 To: Andrey Ryabinin , Alexander Potapenko , Andrey Konovalov , Dmitry Vyukov , Vincenzo Frascino , Dave Hansen , Andy Lutomirski , Peter Zijlstra , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" From: Maciej Wieczor-Retman Cc: m.wieczorretman@pm.me, Maciej Wieczor-Retman , kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org Subject: [PATCH v9 08/13] x86/kasan: Initialize KASAN raw shadow memory Message-ID: <7dd4bcbbcb055dc9cbc1f5abb0825b6943d0fd7f.1768845098.git.m.wieczorretman@pm.me> In-Reply-To: References: Feedback-ID: 164464600:user:proton X-Pm-Message-ID: 1638d56cbb1a8d2a03dfa4123fb056d50bb4db2e 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 In KASAN's generic mode the default value in shadow memory is zero. During initialization of shadow memory pages they are allocated and zeroed. In KASAN's tag-based mode the default tag for the arm64 architecture is 0xFE which corresponds to any memory that should not be accessed. On x86 (where tags are 4-bit wide instead of 8-bit wide) that tag is 0xE so during the initializations all the bytes in shadow memory pages should be filled with it. Use memblock_alloc_try_nid_raw() instead of memblock_alloc_try_nid() to avoid zeroing out the memory so it can be set with the KASAN invalid tag. Signed-off-by: Maciej Wieczor-Retman Reviewed-by: Alexander Potapenko Reviewed-by: Andrey Ryabinin --- Changelog v9: - Rename patch title so it fits the tip standards. - Add Andrey Ryabinin's Reviewed-by tag. Changelog v7: - Fix flipped arguments in memset(). - Add Alexander's reviewed-by tag. Changelog v2: - Remove dense mode references, use memset() instead of kasan_poison(). arch/x86/mm/kasan_init_64.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/arch/x86/mm/kasan_init_64.c b/arch/x86/mm/kasan_init_64.c index 998b6010d6d3..7f5c11328ec1 100644 --- a/arch/x86/mm/kasan_init_64.c +++ b/arch/x86/mm/kasan_init_64.c @@ -34,6 +34,18 @@ static __init void *early_alloc(size_t size, int nid, bo= ol should_panic) return ptr; } =20 +static __init void *early_raw_alloc(size_t size, int nid, bool should_pani= c) +{ + void *ptr =3D memblock_alloc_try_nid_raw(size, size, + __pa(MAX_DMA_ADDRESS), MEMBLOCK_ALLOC_ACCESSIBLE, nid); + + if (!ptr && should_panic) + panic("%pS: Failed to allocate page, nid=3D%d from=3D%lx\n", + (void *)_RET_IP_, nid, __pa(MAX_DMA_ADDRESS)); + + return ptr; +} + static void __init kasan_populate_pmd(pmd_t *pmd, unsigned long addr, unsigned long end, int nid) { @@ -63,8 +75,9 @@ static void __init kasan_populate_pmd(pmd_t *pmd, unsigne= d long addr, if (!pte_none(*pte)) continue; =20 - p =3D early_alloc(PAGE_SIZE, nid, true); - entry =3D pfn_pte(PFN_DOWN(__pa(p)), PAGE_KERNEL); + p =3D early_raw_alloc(PAGE_SIZE, nid, true); + memset(p, KASAN_SHADOW_INIT, PAGE_SIZE); + entry =3D pfn_pte(PFN_DOWN(__pa_nodebug(p)), PAGE_KERNEL); set_pte_at(&init_mm, addr, pte, entry); } while (pte++, addr +=3D PAGE_SIZE, addr !=3D end); } @@ -436,7 +449,7 @@ void __init kasan_init(void) * it may contain some garbage. Now we can clear and write protect it, * since after the TLB flush no one should write to it. */ - memset(kasan_early_shadow_page, 0, PAGE_SIZE); + memset(kasan_early_shadow_page, KASAN_SHADOW_INIT, PAGE_SIZE); for (i =3D 0; i < PTRS_PER_PTE; i++) { pte_t pte; pgprot_t prot; --=20 2.52.0