From patchwork Fri Sep 29 21:11:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sami Tolvanen X-Patchwork-Id: 13404846 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 57EE4E71D56 for ; Fri, 29 Sep 2023 21:12:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:Message-ID: References:Mime-Version:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=656QEbZ92obS5aiXoRtC0Z6P6G7stujo5M40zWtNPbI=; b=tHphmBlhzJZPqp7z4S9HKDDmvm O8sV5Y3W2/Agn0w+EsTQuxip5JE9XyGaXcyet18IUbF9HrlnYf/pAU9QAiM/HhkWrz5ewpK9QnvU9 1ZQ9a30L6WYyTndU8HKHMxYd3YAbIXDMx+DNAsTln07bbhd0BIamjGUGKggOcqvm51Ewy0QQCIto2 WDGIy4UPgCk5q+hg2LnHmyxNuRqsywXTn5II30sS2/4UKA9fmtmD2C2Jn1kBCUMGJ9e2dJnJwxMjV wYD161MkaNAwpHpdKmvOfHKQTQRk4S0WOv0+z8n2DkflP59WmcGPFOdpB6+SWidbpbb4UK9Q6ifNk ls11Ozkg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qmKmT-008aV1-1W; Fri, 29 Sep 2023 21:12:13 +0000 Received: from mail-yb1-xb4a.google.com ([2607:f8b0:4864:20::b4a]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qmKmM-008aQv-2X for linux-riscv@lists.infradead.org; Fri, 29 Sep 2023 21:12:09 +0000 Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-d81ff714678so22151287276.2 for ; Fri, 29 Sep 2023 14:12:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1696021920; x=1696626720; darn=lists.infradead.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=FR1ZKwT/o63KmLhMDo8tUZzc0vKzUsUCbtQdapDGJGA=; b=vc66vw4pG7d+yh61OWz5Cp1mGKem+UlCjIFv7lqimcZi7L+/8NHET5zn6+wiysioxV UBFQrWEgaw+leKoISHa1k9BTBg4Z2gay+95SruVHw4G3pGUoepl1z98pj6qzHRhMprwb Bq9k4JuwXPJY+ZpdLh6axbqwItbq9W4mNCgHS00vRXPPyEQBT/CsKqZxjxxmLuaCNrat 9D1FxDC4hmjwu1WTvLL20ud2pLSdFTCWWP0HGSIUk+1xu/yzP2knbJaFNgT8vdd3dxc4 x3hhgRAaKzV/JdGuqx9aqy8X0ph6Hjy8TomQoAmWX69CRquw2+MC9iHbficwQoTt/DgV QCzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696021920; x=1696626720; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=FR1ZKwT/o63KmLhMDo8tUZzc0vKzUsUCbtQdapDGJGA=; b=QxeSMW4WrS4sox6//zC8u0HLS8lTlWz0PYw68m4RG7mLxBqX8OkDT7XxzjzMqYd28H A3wyGDVmQoN0y2GQW/VXOyxQ3L3OR2AXzGMfuw1b8tC8Qp1TUchXEv4HgzpIshs5lUAD y6Z0V5hrY1SWcn5BQrKANgySfSQyB2QtRR7bm9Qrm1c1CvAoNvlmXYrnQtq5Eo2pL5DO W0eEySqfbvY2mR9Hfj47CgWvGTnFf7TLrvBrnwF7YKCT7KyP3yCrPxmkIk3H29wIWpiw jcqBtUAs6gTBO6nNf/VgWP2Y2S7HeTnE093JqcFE3gsIqlT1Pq6NBoSjSdzUT1iPBUY2 N0ag== X-Gm-Message-State: AOJu0Yw6pfkRZZSzfe5JPs9Rtb2VZNpd2QJWLX7JH27ZuRyYbvTAmGn/ u9udKjPgGPa93fGV6sfCzZdHYkCScYU1GPyWZm4= X-Google-Smtp-Source: AGHT+IHnDIypgcCWBxPESiB/yrBCpKXqORME3PWFhWMxCeyFk9cmGmraRzLwQcSrcYatS2Uvi9kN6m0eWCmXEF8Vfz0= X-Received: from samitolvanen.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:4f92]) (user=samitolvanen job=sendgmr) by 2002:a25:6812:0:b0:d13:856b:c10a with SMTP id d18-20020a256812000000b00d13856bc10amr77200ybc.3.1696021920090; Fri, 29 Sep 2023 14:12:00 -0700 (PDT) Date: Fri, 29 Sep 2023 21:11:57 +0000 In-Reply-To: <20230929211155.3910949-4-samitolvanen@google.com> Mime-Version: 1.0 References: <20230929211155.3910949-4-samitolvanen@google.com> X-Developer-Key: i=samitolvanen@google.com; a=openpgp; fpr=35CCFB63B283D6D3AEB783944CB5F6848BBC56EE X-Developer-Signature: v=1; a=openpgp-sha256; l=1359; i=samitolvanen@google.com; h=from:subject; bh=ARqQmg1Q7FqF1vgF9dpD7yhcKdtd1MfRgn2maiynoVQ=; b=owEB7QES/pANAwAKAUy19oSLvFbuAcsmYgBlFz2bINQRa9JuNqXpxYBQVzDJb/c0+7N1HB+sp 2/Sm1UUS7iJAbMEAAEKAB0WIQQ1zPtjsoPW0663g5RMtfaEi7xW7gUCZRc9mwAKCRBMtfaEi7xW 7vOOC/9tO/6MqlDPfjsiexFNXOEfW7Ar2H9OEVyVIE92EgZgm/mYuBlQqBRKkWvnSCUPZ+ktWxw /8gD9WFejtTnKMje8tf/4wwgxbVQuClXmgi7zZQJvbJ2+SG6cp6B7JcXsMhPsJsbuh3NhTEQj/o pgpvv9Uyv2mK/vRlud+N82dGqhUfLNAWNPfHmZmQ/tMcij5bpFL8VvhWPFF6Akufb6mjaM9D8vG +cR914ZzFo93wp2YlrOemHXK7uUcqH8HHjkYtoFn7o8xhU+VQ7oy1yajipTLM7ewaa0tOrdIWqa 08cpT5V8GX3uAGGuFOzPlMxeF7o/GIDLXMxDfovUqIRoGLzciTjGMCqRmRapZU6oY3GqWEqPSnx GnCaN0xzRvU31sMOUQQkusxUC/3qLR05lv7v/sDAlG5Yah5czQB5w1+2ClKsbQ3sCX6HmpcfWsx r/VvM19V0Dekn+5QLhuwnCOlt6Hs+HBdn3kG1truvPJvtRa+QxsCoiBcfxXnVWnQrVOuI= X-Mailer: git-send-email 2.42.0.582.g8ccd20d70d-goog Message-ID: <20230929211155.3910949-5-samitolvanen@google.com> Subject: [PATCH 1/2] mm: Change mmap_rnd_bits_max to __ro_after_init From: Sami Tolvanen To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Andrew Morton , Kees Cook Cc: linux-mm@kvack.org, linux-riscv@lists.infradead.org, llvm@lists.linux.dev, linux-kernel@vger.kernel.org, Sami Tolvanen X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230929_141206_822747_65C13579 X-CRM114-Status: GOOD ( 11.44 ) X-BeenThere: linux-riscv@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-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Allow mmap_rnd_bits_max to be updated on architectures that determine virtual address space size at runtime instead of relying on Kconfig options by changing it from const to __ro_after_init. Signed-off-by: Sami Tolvanen Reviewed-by: Kees Cook --- include/linux/mm.h | 2 +- mm/mmap.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index bf5d0b1b16f4..72a98b2afaf9 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -86,7 +86,7 @@ extern int sysctl_legacy_va_layout; #ifdef CONFIG_HAVE_ARCH_MMAP_RND_BITS extern const int mmap_rnd_bits_min; -extern const int mmap_rnd_bits_max; +extern int mmap_rnd_bits_max __ro_after_init; extern int mmap_rnd_bits __read_mostly; #endif #ifdef CONFIG_HAVE_ARCH_MMAP_RND_COMPAT_BITS diff --git a/mm/mmap.c b/mm/mmap.c index b56a7f0c9f85..ed1b178b223a 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -64,7 +64,7 @@ #ifdef CONFIG_HAVE_ARCH_MMAP_RND_BITS const int mmap_rnd_bits_min = CONFIG_ARCH_MMAP_RND_BITS_MIN; -const int mmap_rnd_bits_max = CONFIG_ARCH_MMAP_RND_BITS_MAX; +int mmap_rnd_bits_max __ro_after_init = CONFIG_ARCH_MMAP_RND_BITS_MAX; int mmap_rnd_bits __read_mostly = CONFIG_ARCH_MMAP_RND_BITS; #endif #ifdef CONFIG_HAVE_ARCH_MMAP_RND_COMPAT_BITS From patchwork Fri Sep 29 21:11:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sami Tolvanen X-Patchwork-Id: 13404844 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 A94DAE71D5C for ; Fri, 29 Sep 2023 21:12:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:Message-ID: References:Mime-Version:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=UazUX5vsJ737qSsU3mqMapAsB8xFm6oDOx72zz6frU4=; b=rJkQ3609fkA5Z6MRFusC53CZKr 6xwNYhheZBJznSLTWjVkdQSAjnEe5PjM2L2z4C+JEi4/eJ62GHe9GXFO0M1p2RniBrN0+NAH/WBk3 Xue1FP4fIwumJCwVh8qo6O/5r1+Wj+uWthqIDqZjLj9SMyBoZC4XVNzIynEpLWXIUIGSuvj2nSHAB YRvwxCpzR6FSn2okNnLprJY+pkezuwoHmSbECXDnd9pJIGnTTaX39OwFBTh7JvGIripuKgz1qbVmO UXUt8wbn2lkWh8zXYaPaacAXZzOAqrxNsg0qBp7GgyvpQ/HwQSJrQkuDMPj/zTdm5HGETIKzoQavS m+jKQZUA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qmKmP-008aUH-2c; Fri, 29 Sep 2023 21:12:09 +0000 Received: from mail-pl1-x64a.google.com ([2607:f8b0:4864:20::64a]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qmKmM-008aQz-0F for linux-riscv@lists.infradead.org; Fri, 29 Sep 2023 21:12:07 +0000 Received: by mail-pl1-x64a.google.com with SMTP id d9443c01a7336-1c60cf79e3eso116693635ad.3 for ; Fri, 29 Sep 2023 14:12:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1696021922; x=1696626722; darn=lists.infradead.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=19scQT+vZguMbMPGvwbswmmwWeMyYkP13y1R8IKgsdo=; b=CuRz8kPuvrycuiLFcbGWlyXKkuDZ/IbOe6ZS89vJnpun3yDfvjGe2i0jOxFrqm2TGr +zhZVuVwIZD17IC6AYqNShTPcExYS1uhWOUhJ7LlhUMKduar80nAq97XsUJS4I8SN3dq A7gSj9GphWi+H5R5rfTdnZVqEnPk1qaEBfyPg6k7UcawUUrDmJ5jRXVyuuK4VTUe+nMp vvFAxC6aU94x5JDRGP3DkP82C55vIIr+d7JKDjKTJ1rzzM8rOUYS2YqWunuD8uAYYUzq Wwfi1rW9MgEbogi5EKjb65cR9zC71k0zr0htvyOFDldwvm5FReFtnKF10slLWri/3hcV QbbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696021922; x=1696626722; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=19scQT+vZguMbMPGvwbswmmwWeMyYkP13y1R8IKgsdo=; b=vhBmTY5wWc8gg4CSRS/kKBb8UzQ1Xm67rHors+G6hzbIeNHVjTREURIn7Ni7zu9y/u rM4YcBrwjBCDEh7xCgY89E4+rmfLFbdfp+e85ANgtZez6Hv9+rIUQYPSL2jhJlNB2D2l 4gHvdq8cRlfiNefxYqd3MMZYaBdUG/vto0vRen2OWU0jE7CpZTPNZddHuFJvwVLrcKSp eYl+hT3qE4fYIqAaIk4cZCopf3kaysjG45GX/tvr/xXt+5B2T2Hutgvdqst6YOQKTGBk g3EmQ3oBPcyQT/K3Jow79o7mnSaUjQM5PkRCOEaNZ2cAvHl+ooLu3soFxiQ6nOcjuOY/ iFaw== X-Gm-Message-State: AOJu0YwiAW6KGv+rl6+YZg5mXxrxMqJ+9rTheU+WHY2RuBjgPU3/uC13 APUQBXm3/eMJSdxxvkcI3jTqCtBJrmKUHclrsf8= X-Google-Smtp-Source: AGHT+IEu8pWqkhn949EN2w2MEEmF4sIQU2CD0ztiPLeuQl+OuKcbvmbHD9LpYfISQSvkmvSO3SxPVHDUipdN2Hi1oC8= X-Received: from samitolvanen.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:4f92]) (user=samitolvanen job=sendgmr) by 2002:a17:903:1c8:b0:1c6:d25:8730 with SMTP id e8-20020a17090301c800b001c60d258730mr75155plh.0.1696021921796; Fri, 29 Sep 2023 14:12:01 -0700 (PDT) Date: Fri, 29 Sep 2023 21:11:58 +0000 In-Reply-To: <20230929211155.3910949-4-samitolvanen@google.com> Mime-Version: 1.0 References: <20230929211155.3910949-4-samitolvanen@google.com> X-Developer-Key: i=samitolvanen@google.com; a=openpgp; fpr=35CCFB63B283D6D3AEB783944CB5F6848BBC56EE X-Developer-Signature: v=1; a=openpgp-sha256; l=1191; i=samitolvanen@google.com; h=from:subject; bh=MSLQAq+u1Gq1vqQPv1L24OvfGxs9lQjVrKINsuZaDko=; b=owEB7QES/pANAwAKAUy19oSLvFbuAcsmYgBlFz2bXFheIUWsMCgpXroYNEMEHJSzh7lHXZPhb Ah07CUmBI2JAbMEAAEKAB0WIQQ1zPtjsoPW0663g5RMtfaEi7xW7gUCZRc9mwAKCRBMtfaEi7xW 7oPqC/9r2/xEbO/XFpLcUfW8kI4zwGyW+1Bc7PLy9I1XUD02QER16SuVa1TjN8rJQPDmOMsvTB5 T5jEE8zHkuv5iPAUTq/yfdsqgq7Z9o7WUqulun2nOY9Z455ZDOwLvbCIfEXhOthriqRBjm08Kd8 068lN/FADXcZatUB50UlQahfJo08fLC7oUQ5xDGv0aXR6pnqONVNs/F1FhlysA15ZmM0HVhJePX 6NcJ3HNNPyvbDbeafLIysEsEirdqqDLbxHXo6W0v7OFcevxKffQom+ZUD8w0SlBJsnrgLSQYfrL 4SDgYPIT3RgVrVY58SpSU/IrpswNMkcW1oGV+VpuE8vh5HfISvX0Y/jFIK76jIL1xM9gdG/5oKD xSBdaJPOnpK9Gcze/0uC08IM5oubP3raIy1qzWvrbWFce1KlRfKgkHLVVNp7KcJmqHe0lhZqoI4 gKx2VGQd8AOM+C9TUeca+0u6bNkxxIvvO6e8Zupt2MkaleKzO1xxv6N14XGwr2/VkIpsg= X-Mailer: git-send-email 2.42.0.582.g8ccd20d70d-goog Message-ID: <20230929211155.3910949-6-samitolvanen@google.com> Subject: [PATCH 2/2] riscv: mm: Update mmap_rnd_bits_max From: Sami Tolvanen To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Andrew Morton , Kees Cook Cc: linux-mm@kvack.org, linux-riscv@lists.infradead.org, llvm@lists.linux.dev, linux-kernel@vger.kernel.org, Sami Tolvanen X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230929_141206_120359_41B36847 X-CRM114-Status: GOOD ( 11.43 ) X-BeenThere: linux-riscv@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-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org ARCH_MMAP_RND_BITS_MAX is based on Sv39, which leaves a few potential bits of mmap randomness on the table if we end up enabling 4/5-level paging. Update mmap_rnd_bits_max to take the final address space size into account. This increases mmap_rnd_bits_max from 24 to 33 with Sv48/57. Signed-off-by: Sami Tolvanen Reviewed-by: Kees Cook --- arch/riscv/mm/init.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c index 0798bd861dcb..ff8d21a6cb2d 100644 --- a/arch/riscv/mm/init.c +++ b/arch/riscv/mm/init.c @@ -762,6 +762,11 @@ static int __init print_no5lvl(char *p) } early_param("no5lvl", print_no5lvl); +static void __init set_mmap_rnd_bits_max(void) +{ + mmap_rnd_bits_max = MMAP_VA_BITS - PAGE_SHIFT - 3; +} + /* * There is a simple way to determine if 4-level is supported by the * underlying hardware: establish 1:1 mapping in 4-level page table mode @@ -1071,6 +1076,7 @@ asmlinkage void __init setup_vm(uintptr_t dtb_pa) #if defined(CONFIG_64BIT) && !defined(CONFIG_XIP_KERNEL) set_satp_mode(dtb_pa); + set_mmap_rnd_bits_max(); #endif /*