From patchwork Tue Oct 22 01:57:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Holland X-Patchwork-Id: 13844968 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 189D6D17157 for ; Tue, 22 Oct 2024 01:59:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 644906B00A0; Mon, 21 Oct 2024 21:59:30 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5F2186B00A1; Mon, 21 Oct 2024 21:59:30 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 445A36B00A2; Mon, 21 Oct 2024 21:59:30 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 210C76B00A0 for ; Mon, 21 Oct 2024 21:59:30 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 21C8381BE5 for ; Tue, 22 Oct 2024 01:59:16 +0000 (UTC) X-FDA: 82699580586.08.4F8A7FB Received: from mail-oo1-f51.google.com (mail-oo1-f51.google.com [209.85.161.51]) by imf19.hostedemail.com (Postfix) with ESMTP id C21551A000B for ; Tue, 22 Oct 2024 01:59:08 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=sifive.com header.s=google header.b=gpWEb2yT; spf=pass (imf19.hostedemail.com: domain of samuel.holland@sifive.com designates 209.85.161.51 as permitted sender) smtp.mailfrom=samuel.holland@sifive.com; dmarc=pass (policy=reject) header.from=sifive.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1729562218; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=jOWNg37CI6wBNjlK3WTwIizp4MumcxiO1pDVtn3VcZ8=; b=IfDY1R7+yWEL+CZ0/wzPPywYX1ecYfkJgQenr3ikJ2DA2sh0Q16WoWghsYR5RGuuovKR0q /vHcvgWhonS4aQJpkKZE88N772dfMK/A8UIHLx70R5jisiOKXj+aWSC/YBKx8cKYOuDlWb TTDhtD6POU4f94PPxTfOQasAOBp003U= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1729562218; a=rsa-sha256; cv=none; b=tplIlEg3pPAibM1SyPgs7gB8DwMx3vgrOgWvST3Qf0KsOvfXEBXaQBUWKiNiKhSV/3zpdk ury25pLlZ6jziNDRrsI0KcGHMfGvqCDvRkazK9pQgF6NAu+jZxtCxW22yceOKnwMwKrDFe t6OtlOYMR2NfjZlA4k1FniRnrymO75A= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=sifive.com header.s=google header.b=gpWEb2yT; spf=pass (imf19.hostedemail.com: domain of samuel.holland@sifive.com designates 209.85.161.51 as permitted sender) smtp.mailfrom=samuel.holland@sifive.com; dmarc=pass (policy=reject) header.from=sifive.com Received: by mail-oo1-f51.google.com with SMTP id 006d021491bc7-5eb5be68c7dso2604800eaf.0 for ; Mon, 21 Oct 2024 18:59:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1729562367; x=1730167167; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=jOWNg37CI6wBNjlK3WTwIizp4MumcxiO1pDVtn3VcZ8=; b=gpWEb2yTlrTstE0WF/Y5R1VCqy2Na9TN3x/I2aJgrYBz8NgVUh2QGNcDZ9HiARq9zR /Sks9LUGVWZqeTEEPQRt7g5GNLTXGt1UtFj5280b5R5Zsav3ciBGE7IjfIK+67eUm7uI tIOg1GFkILUHftU3/ZsTJnm0rwnfLBa/M8u6kB7bYPHKiM4JNwUnI58IBF2WIYoLPysd ime7aQ4T2kQHfg21Nr7uk8fuaS+/HkHzgFS3LkT3r8oL2GAqlDR/Kga+Coq+kHgrcQBD lOdngUojXfbb4qhuIXa+pBDnnwYjONc/lwYJ203oi2W6rwlBrUT/japl6PdYEgIlYcxp QlpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729562367; x=1730167167; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jOWNg37CI6wBNjlK3WTwIizp4MumcxiO1pDVtn3VcZ8=; b=M2+yN5JnpblfD3O/VWHk4NDkHLK7ECx5XjDEeB21yH7dTBrECLEbNiK74Q0OIhvCZ3 xec4vzGJIsbqDPTswpYwZTNPkqzOnMWdEmp5oifl9zQDGypzB8LhA3XVu/Of/Nr8SmRI kPBCITsDgzkKIQxlvzqi1eDuNgstxsZmN0Taw6KvQJPpfjxrd4gjU0V8rSaAuJVbNkWp h6bn6FzzaeQpK9ItsSJXLQW0cKohAKYrdiRgs5RXvdqoyyYCYgu7WQAHa9whohrj2jqw z6s0JmdIOF4L9d0PYSp0U+kch4aN56p/34utTKtfnrXMWc7jkZI7M0jkwlC35CUslDUx p3rw== X-Forwarded-Encrypted: i=1; AJvYcCWuJ2Nti9l/hT5wMKvkZf/1fV8TScU5SpntpQ42Pcs2GZ9HBbgNH3wqTThVdHmZ72e1rd+EFY6HaA==@kvack.org X-Gm-Message-State: AOJu0Yx5ml6xykhuVUoXDDJKVD8K5jA84rhH6z5fm7DB1R3vY/f0LaXk yaBR4RO1fVYGsIspV8gOVZYpsnr85M3wEq2eZVur6nXmDqLq/TS8e22pTTyDCPw= X-Google-Smtp-Source: AGHT+IHErzREUGw6ROMLMvLXYHp4zadEF+Dwq950EYc2048lR/Pu3YsD3Bs92QVrt5aBEWQnl13Wpw== X-Received: by 2002:a05:6871:109:b0:288:b220:a57e with SMTP id 586e51a60fabf-28cb0184ff2mr946194fac.40.1729562366823; Mon, 21 Oct 2024 18:59:26 -0700 (PDT) Received: from sw06.internal.sifive.com ([4.53.31.132]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71ec132ffdcsm3600710b3a.46.2024.10.21.18.59.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Oct 2024 18:59:26 -0700 (PDT) From: Samuel Holland To: Palmer Dabbelt , linux-riscv@lists.infradead.org, Andrey Ryabinin , Alexander Potapenko , Andrey Konovalov , Dmitry Vyukov , Vincenzo Frascino , kasan-dev@googlegroups.com Cc: llvm@lists.linux.dev, Catalin Marinas , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Alexandre Ghiti , Will Deacon , Evgenii Stepanov , Andrew Morton , linux-arm-kernel@lists.infradead.org, Samuel Holland Subject: [PATCH v2 6/9] riscv: Do not rely on KASAN to define the memory layout Date: Mon, 21 Oct 2024 18:57:14 -0700 Message-ID: <20241022015913.3524425-7-samuel.holland@sifive.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20241022015913.3524425-1-samuel.holland@sifive.com> References: <20241022015913.3524425-1-samuel.holland@sifive.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: C21551A000B X-Stat-Signature: yg1gb3hariwg1n6itkoxkhjmiw5yxw3r X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1729562348-411810 X-HE-Meta: U2FsdGVkX18e2Z0lcYcJsLmfGz7H9P4dxTCZecSOt3xXCMutisX78sa64n6e5QFNw95mtHeahQHhTvBOIsu12FO3USxUydq9L/8ApwtbfHEW/zhQp5estJiIi4m4FVBfJU6KxhAydzIqXIGmPvn5X9I39iLb7MLv3YSAhj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jSlBDaYCHvSp6wnoVQW1lNvB3dWyRRQdeJB0BNX2SvgWZAE/dyfjrqdPRpSUP0Hgn8+vlR0xORTWmWfBpWzPRSf4mxs5kfrmuboCThZy/dW2IQzVEttlY+VhOTj6xrgcE8v3obdzAB0cvJjrkLzAQ4upyWxoIG5V9IzXhDudoHLoMpC9tO4Wg== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Commit 66673099f734 ("riscv: mm: Pre-allocate vmemmap/direct map/kasan PGD entries") used the start of the KASAN shadow memory region to represent the end of the linear map, since the two memory regions were immediately adjacent. This is no longer the case for Sv39; commit 5c8405d763dc ("riscv: Extend sv39 linear mapping max size to 128G") introduced a 4 GiB hole between the regions. Introducing KASAN_SW_TAGS will cut the size of the shadow memory region in half, creating an even larger hole. Avoid wasting PGD entries on this hole by using the size of the linear map (KERN_VIRT_SIZE) to compute PAGE_END. Since KASAN_SHADOW_START/KASAN_SHADOW_END are used inside an IS_ENABLED block, it's not possible to completely hide the constants when KASAN is disabled, so provide dummy definitions for that case. Signed-off-by: Samuel Holland Reviewed-by: Alexandre Ghiti --- (no changes since v1) arch/riscv/include/asm/kasan.h | 11 +++++++++-- arch/riscv/mm/init.c | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/arch/riscv/include/asm/kasan.h b/arch/riscv/include/asm/kasan.h index e6a0071bdb56..a4e92ce9fa31 100644 --- a/arch/riscv/include/asm/kasan.h +++ b/arch/riscv/include/asm/kasan.h @@ -6,6 +6,8 @@ #ifndef __ASSEMBLY__ +#ifdef CONFIG_KASAN + /* * The following comment was copied from arm64: * KASAN_SHADOW_START: beginning of the kernel virtual addresses. @@ -33,13 +35,18 @@ #define KASAN_SHADOW_START ((KASAN_SHADOW_END - KASAN_SHADOW_SIZE) & PGDIR_MASK) #define KASAN_SHADOW_END MODULES_LOWEST_VADDR -#ifdef CONFIG_KASAN #define KASAN_SHADOW_OFFSET _AC(CONFIG_KASAN_SHADOW_OFFSET, UL) void kasan_init(void); asmlinkage void kasan_early_init(void); void kasan_swapper_init(void); -#endif +#else /* CONFIG_KASAN */ + +#define KASAN_SHADOW_START MODULES_LOWEST_VADDR +#define KASAN_SHADOW_END MODULES_LOWEST_VADDR + +#endif /* CONFIG_KASAN */ + #endif #endif /* __ASM_KASAN_H */ diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c index 0e8c20adcd98..1f9bb95c2169 100644 --- a/arch/riscv/mm/init.c +++ b/arch/riscv/mm/init.c @@ -1494,7 +1494,7 @@ static void __init preallocate_pgd_pages_range(unsigned long start, unsigned lon panic("Failed to pre-allocate %s pages for %s area\n", lvl, area); } -#define PAGE_END KASAN_SHADOW_START +#define PAGE_END (PAGE_OFFSET + KERN_VIRT_SIZE) void __init pgtable_cache_init(void) {