From patchwork Wed Aug 14 08:55:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Holland X-Patchwork-Id: 13763218 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 3BD6CC5320D for ; Wed, 14 Aug 2024 10:00:57 +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=q+LcB4MC6Qgfr9kzwjEWl/9KLwOZpaXC6CA7cxVGJTI=; b=gbCw30DysIEV+S+7XCMMcZ19XR XoWA0p6phHL/l/ddq+GY05XOcd6PSOd3CaNNwn+SfO/VHaTXFMeIoMlYb1a059WVAgOftNvWH1PaN 5+Jk1AYlhbtcPighOkocHPQGn7Ekkz9+DkxnmhZMlgJ0BGJyA8YVCBNc9s3/jfaDkA+AQnDeozqSp C5wlDzPfc26yMS0OxT6a9YfZId8YmnBvF+5S/ASJRSngdw25Nt1g2vfVawi5sY3oPBHSZkZz3POq2 bZTCaCj8xKCyteFrywdKOdMBO32wJ4PXPJZSUPrTTjhJQbPgHpMC4bBpmsr4DDyzUQBNZy5Dq344Z +6W6XsnA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1seAoA-00000006U5P-23Q8; Wed, 14 Aug 2024 10:00:46 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1se9o3-00000006IDX-22p0 for linux-arm-kernel@bombadil.infradead.org; Wed, 14 Aug 2024 08:56:35 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Transfer-Encoding:MIME-Version :References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=q+LcB4MC6Qgfr9kzwjEWl/9KLwOZpaXC6CA7cxVGJTI=; b=KN5LzflrBaJ9GYiwhUZxej494k 2302nnNLkdTOPr5+lPaF278IFyyaH/y3/7EOdBpgts5Lxw03DQUZYzX9LfD1gGr/zzPwGsjm+pxte 4JgYz1XehqMhsRDD7qs/2UtRLyoifkpp3Plm1F5r23sPoq8xk9R26SaUULGUg/k3yGio8WY00tqUI QKO0x5BPJyWsKVF8h2Y5NywckB+hTILjXbZsJAy3HJ4IJmC+ET3hPw7LfgyWNFaJ190vBGdFnb+IC lvrBoYVsw6Jp/d2LefKwzR4u5/NU4aBeTSJo1yrcoxKykVLjWyqUCtA3oTOLtQ7RNgySsFAq/MgJb PszFHwuQ==; Received: from mail-pg1-x529.google.com ([2607:f8b0:4864:20::529]) by desiato.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1se9nz-00000007zDR-3Nv3 for linux-arm-kernel@lists.infradead.org; Wed, 14 Aug 2024 08:56:33 +0000 Received: by mail-pg1-x529.google.com with SMTP id 41be03b00d2f7-76cb5b6b3e4so4216008a12.1 for ; Wed, 14 Aug 2024 01:56:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1723625787; x=1724230587; 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=q+LcB4MC6Qgfr9kzwjEWl/9KLwOZpaXC6CA7cxVGJTI=; b=YhSDj7gRNo1/FoN5CSeSwviOQxYfDKhu40XOpvup/HlXAz2IO8+8jrYrDbIN7tKX6H rZy0pG9o2SgpxDugw/bUeoEK/N+eLHdX4LAmlbrm3HFMcMbztaeZnPk4tWbTBNBUzhCg Ewa06QrC3e1XpEtmX2O45DPpPuEvizmqkvAAfk3pM5UtdNNquObl8MpKFYfsFv2EGbKJ s3rdSri5A7jGW+1FO/9kqIO5xEIr8MfiRNttwZscPAtJdJiIAhqnj+c/JjbRcj6Jw/jZ vvl3tDEsXj/vJUebG8U/IB//rzxqQ6SAxNy2ZWaHJV7IDiP+2/rYVlV4K5MCYMXERwvo qh5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723625787; x=1724230587; 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=q+LcB4MC6Qgfr9kzwjEWl/9KLwOZpaXC6CA7cxVGJTI=; b=NbRdkI/4sXLpx14pP1jSnpWsLIWcHwHfUVHH6cPwdWL4ccGyd9hEAU7VfMk7jHhbvB tY8qojLL7VqFfKNvJtjTyxgyrRdqpvoRQg4ydIcNbHGsTdHgnOuMOJJOdK8MBWP5UHtf d9zpLlfkRNASGvS/edhN2FQEPNFF+83z3PbD+EaXlIkd1l3HZAuwpBNwnGgMPmrsF+qi cfF7KpNA7noL9JU6AvwZH0EVDnblsm97OAaZJ/Q4aoXtGwPo5mJKHjSsteEwtLH9UxnL XjFM8UAGqAWja153S/vNdX2eAislM1DmR2y3tU0Cp0T/qZp0GfzP4BmxVJwKcXHxwq1Z vraQ== X-Forwarded-Encrypted: i=1; AJvYcCVuzLd/8KQxUfI0sxwrZshlBrHmKU8sqCTMjmXAQ9Ww4GensBuQP5OjMWvHkPKGDwzsHUH8hncHjwiE4qYsY7d/55h5Cw8yX88yOpKIsIFp13BwhPw= X-Gm-Message-State: AOJu0Yx/jPGzov2F/hN9D5BZEXO/oKF/ysbNamu7icSjTDsgEHTFMoyo WYNlt3wcU84Qs/CgCJUxG6xB1/eMJrXaG4+2w2SkD1xZeOemiWOWPLOOKn5Z0c0= X-Google-Smtp-Source: AGHT+IHeop/4tDtqPSIvDLepGfrszpRVvQ8NysDbzpZjr3VmMUvS3QBFyPVJf7l/syUiJf9jHvayiw== X-Received: by 2002:a05:6a20:c88b:b0:1c4:c879:b770 with SMTP id adf61e73a8af0-1c8eae8dd79mr2680167637.23.1723625787615; Wed, 14 Aug 2024 01:56:27 -0700 (PDT) Received: from sw06.internal.sifive.com ([4.53.31.132]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-201cd14a7b8sm25439615ad.100.2024.08.14.01.56.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Aug 2024 01:56:27 -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, linux-kernel@vger.kernel.org, Alexandre Ghiti , Evgenii Stepanov , Andrew Morton , linux-arm-kernel@lists.infradead.org, Samuel Holland Subject: [RFC PATCH 4/7] riscv: Do not rely on KASAN to define the memory layout Date: Wed, 14 Aug 2024 01:55:32 -0700 Message-ID: <20240814085618.968833-5-samuel.holland@sifive.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240814085618.968833-1-samuel.holland@sifive.com> References: <20240814085618.968833-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-20240814_095632_038292_44486DCA X-CRM114-Status: GOOD ( 17.91 ) 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 --- 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 8b698d9609e7..1667f1b05f5a 100644 --- a/arch/riscv/mm/init.c +++ b/arch/riscv/mm/init.c @@ -1492,7 +1492,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) {