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: 13844992 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 609B5D17157 for ; Tue, 22 Oct 2024 02:08:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=jOWNg37CI6wBNjlK3WTwIizp4MumcxiO1pDVtn3VcZ8=; b=ZMu16mPCFbUv4vdmovQopoVf9F HjB93KNt+7CFxKuzwtGgaQlzKFayY12daUollJjyH8WCibv9R4L1x5i/qqz28xPTUki76jqYIzfi3 O599ARpRoZvBxCELPN7LCp4ldbOnZ/iaDd4Im5DsP4o11nHSLXN/eBSEDqFSKZd5TFCdJIhfbmsDB 5pCVkSbL2GHdVPySCrae9GEgyt2msAAkZg3PtK2WiFxmkkmyosQBNWd2YI/wMNTas/nFfktvQ8+z0 aR7pMrpO53xCWm2lJAwT2Y9X/FxCJ703OHk+AHG6kmHP4o5/i09lh9oFmYx2WYkG6b0SJgIxUEJOf XTFmQ8Ug==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t34JQ-00000009HzX-3hz4; Tue, 22 Oct 2024 02:07:56 +0000 Received: from mail-oa1-x35.google.com ([2001:4860:4864:20::35]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t34BE-00000009Fr1-0Oud for linux-arm-kernel@lists.infradead.org; Tue, 22 Oct 2024 01:59:31 +0000 Received: by mail-oa1-x35.google.com with SMTP id 586e51a60fabf-27b7a1480bdso2214456fac.2 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=lists.infradead.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=ekj/O/m+TegZFBB9wzrogI7SheMvGKivaDHcESFVBLmbPcbNJV91/6CQqYseETVWJq aU0PwRV8+ATkJSkhadXaY89uQEYqTYs+TT7sV8kDIF9wyu7w9hYOzTcMEeizbnGbuQh/ 5CGsMOcaAPo/NAC+AWKnyAwJQtmL9RFwpT+M05qd6ifVe8qcwURWCDoHyEVfKewBBSVo o5fF4wh7QnO2QQS7qKGdFawxR5W8xFUDp2HquE+sBUQ0k+gyzB5JhyM9Z4hwYs0fohAp RhpiHlZZ8T1B19X2Hd3Eo2Fp3h1xM5+V4/N4SlLNzAbpOhlI5iTn2eRwtPoZZoJeGBEE WA2A== 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=pdZ2yXSU0UzNrjSEXbPUexjvFI4DRMBpVrQcUu2aEDwo2IDoFY4a34TQxZ46FFy32t 2szIWlOr5dQR9oZ1SD5chVYwPpL7hIs6v5p/mq6beesZbDin/w9ZX0JBE5qqJnrYqYdZ xorUkymC/jFWaqrbLUxAeZ47iukPsbfompQGoHkXArO/mJ95xglG+Br2mki3v7Qf2rcH WVFmIDz6Xa2LtLxAk4DqONVcEZC5Qxj1UbEfEnSNOm/tJ02vttRbIDWjb/5TFiOw9ysZ vtb9XKvibb1KBNzrnSQj/m36veQJg23kRKJVStQILNW/xKSYVZ4AGDm0G6pfNI67uc9I Mawg== X-Forwarded-Encrypted: i=1; AJvYcCXMzlrLcyj8wGHiQwJVR66PVuiRlkwXGQDmEw8JKne5KfchHyEoxQvX3qDDoTwvjJ8sfAhrZ/ktDORfa5KtLMvu@lists.infradead.org X-Gm-Message-State: AOJu0YyFPcS3hOE/QkACfEpCs9VBhI5CJMqlPzXtA6rTp1fd+v/kTzZE vjeJjl/ee8wvnhIcGqfqtzdZoKkA5bRZ9g1P44ADz2RWGxRo8eo/vB1/HCWyHwg= 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-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241021_185928_432258_D9BC7C79 X-CRM114-Status: GOOD ( 17.84 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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) {