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: 146811 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2a8e:b0:403:3b70:6f57 with SMTP id in14csp85683vqb; Fri, 29 Sep 2023 15:55:47 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH7g5qK9Du1THv6XA0+blboaS1v/YfXSjwgWeZIHR/watHZp3biuyCC9UeTBzvYflcXkIQU X-Received: by 2002:a05:6a20:430e:b0:141:d640:794a with SMTP id h14-20020a056a20430e00b00141d640794amr6674099pzk.39.1696028146988; Fri, 29 Sep 2023 15:55:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696028146; cv=none; d=google.com; s=arc-20160816; b=EGewNdEsdbw+wjhVvR62aqM7IczmNqj/b2QTlgpE3a3fif+5ZV5wvTMpE0QICtDu6H hsRqQNT945d8FcRLhvOMcrSiHe53+bB35HXYHd8MxkQRbE+LAEX8w1y+egf+6xBPzPTl piy7hcC3zljs+eu/E1eiekeoY/dd/X4vEW/2COSl95/2NWpC3QmiJePyePelWF3KcCFo FxVnZGcUbuVuD/o2fQsJmzJgvaLQ6vdcAh8Fob7sHe8ZFPt67+pPOlVwnkAPa1XbN6+R o3dICl2pSx/Y2dsMLl3ZvPFx4L4WlLv6n+l9dtoI2mLdZn7Q3wGTx6wxJI2w5v+ZVJ9u r6og== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=FR1ZKwT/o63KmLhMDo8tUZzc0vKzUsUCbtQdapDGJGA=; fh=lCEZWMPVG49nWgDluo69iKN/WzAgI8N9vRK+/JDFAA8=; b=mAQvCsX+XFhqH83Hr36H9jmNQSy+6wXmW79eHgEAN6rC7HedrEaBJntly32G9/iECY fdpgM7eR48xMfturHGxdecpt/41FM+pEzNG8Lh3jQPHd9KWhLmnDloB/C5QQ2bQ8Kknl 8Ux3TNAiObVChEZm41p96YWgfF5p8er4g8O4mXPMnB7O5scuUrsJbkrbFqDjF0ZFZwsi 1N5HnBND49moCRYsoHTrmulLdzXyV6MIU9skpwy2SiKB/HTct8nIhhyLbKGyjzWWhLSF ahS1KRn0yuNCB4kcBXrILlFSgVU+tgehw2fUZMjsVXWKoA9dePVwiCqfJARmVXTykWui M7wA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=bf1EOsOu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id z186-20020a6333c3000000b005852a35afeesi9097853pgz.186.2023.09.29.15.55.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Sep 2023 15:55:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=bf1EOsOu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 125D6827A0B6; Fri, 29 Sep 2023 14:12:19 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233753AbjI2VME (ORCPT + 19 others); Fri, 29 Sep 2023 17:12:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37572 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232985AbjI2VMC (ORCPT ); Fri, 29 Sep 2023 17:12:02 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 04B4C1A7 for ; Fri, 29 Sep 2023 14:12:00 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-d85fc6261ffso21294473276.1 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=vger.kernel.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=bf1EOsOuDJTQHfN+mIHHCC1FmaxjQbk+q6a+dHkaFwE7mFrm300htcxJdAnrxtZNGd WZ7+4BLcYv+U5MeLcWFhYD5wMwHMSyTPj2qL6tfB29U1Y7UtKmKKUOfhBROhY22K1uAp XinQzJrrlts0sSGRZL0HhqldQ2dXE4cps+upv5jq8qzpnB/v6sfI+4m6X/xrVlBCc808 8Ap+9jHGNfmZKtnxaNBMucN132MaX7kseHR0Gri2cvPMqTn885FgVP24lAsBSpWjq8Ea Ks2+jgzjvZBU+5QdLtw+q/+KP5aaTjz1oClDwgpu8gi9dIgsUYPZsToyU7t8iwC0ya9v 5FKQ== 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=baoJ17LVjX1zDZKp8FXOgwmMAFhy9ZogkfFXH7IGHZm7ZK++16JMI/W7DYE3vYYk0f ENbIQFwzMU0NZ577SYhEeDU3xlH6pu8XJVb8g3K8XGMSfvDUYhjl8OY3yKePynvL+W+z qn9UWFHKxAomapuuvg7FvHzf/qpUT5PJ+SaWTaXIpI/h87lgn2f5WvS2uQSXgtCIUUSp PVFHUcGPqnUwIpBUrmUs7UOXwzohAv148puTgqdsjFCBP2NkxcknVRWbCsV2yYMde+0c 68dktrecAp+ajP9jND2uekTsBXb6U3oG1F6x9u8z3qCsmh59IGNTXP9yTB0Sg7buco0l YN6A== X-Gm-Message-State: AOJu0Ywln8LRN80JYTx9d1k4mSDojarbnUJtUHuctoMcpjosBnxbq3hz k/jarm8QWufflEEx0Q838Swg0xQfcLHe70tFe5w= 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-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Fri, 29 Sep 2023 14:12:19 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778414410337033970 X-GMAIL-MSGID: 1778414410337033970 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: 146801 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2a8e:b0:403:3b70:6f57 with SMTP id in14csp73501vqb; Fri, 29 Sep 2023 15:24:47 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHbl+Dl+T9ICHFxX1eIEwGrcJ/McyponxGkMbX/FJbMPfz/ErnLa1aYyvtc2AsVW8RM+UV8 X-Received: by 2002:a17:90b:3905:b0:274:6ab0:67ba with SMTP id ob5-20020a17090b390500b002746ab067bamr4344186pjb.48.1696026287010; Fri, 29 Sep 2023 15:24:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696026286; cv=none; d=google.com; s=arc-20160816; b=W0xEQDwQk3jbIhDAmsFtYEh2uY2Ew1MHm6e+L2A9RK1M3g4VukPrykW/JFyKZelSc/ opEEWas55lp9K3TkX9YncUNW3YpKe5sESRhQ43P9/pyM9fdMj4Jp3BAOZH8PjC9IiIpa NDTwEgMv3KhhRywIh4QXSUK+6F3wtwII+cAJ8iJ7GTxm7cEBNpnWVJQMZAlszYQhSApd NkEWJRuju9EH7J2C71mdJZQXxyLi7ZLI2Jb9AMIQ7sgjmSUmCyLAjpuNf38XPPNAjSwm ge80d1/KaUAND5xsKBodJ2uIUFPfyrA1+J3t2GONVcjqPmtIq832rxxs5+gGbMcW1vA4 B5Pg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=19scQT+vZguMbMPGvwbswmmwWeMyYkP13y1R8IKgsdo=; fh=lCEZWMPVG49nWgDluo69iKN/WzAgI8N9vRK+/JDFAA8=; b=LFIFcW5RoS3dyBvgSdCMoQuk6qOCKOhYB7LrGU7wvv5GlgJEExRtGsoq0ABD8nwLCK GtXcIInDi0M5Sp1/ynMf/xVelL+sun10CdHmzfHPTF3zMiF8eZ9iKYGadF1T2E80d/c+ mQEG3b4+LThSjk2z/lFEpjEM5M8wx/rtLxO0TqFeLvKxJ7IFzOnVoVkGwJcEAzb7ZPxA iIA8beV03rgTf8faG1nzt9r+mZLPwJQyUXL0Bc6VhDPGEbqQ5P8sGuNx70b8yYtl8t9t VnHHCnNUZzoPDPaS+hM2QIT5iHwhDfMmdlK2pFuFyS88waYdK8RsPCWz/joocGZ8pKkt ycNg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=Zd6JRriO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id nm9-20020a17090b19c900b0027455c727f5si2321807pjb.84.2023.09.29.15.24.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Sep 2023 15:24:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=Zd6JRriO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 55650802691E; Fri, 29 Sep 2023 14:13:10 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233782AbjI2VMK (ORCPT + 19 others); Fri, 29 Sep 2023 17:12:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37586 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233516AbjI2VME (ORCPT ); Fri, 29 Sep 2023 17:12:04 -0400 Received: from mail-pl1-x649.google.com (mail-pl1-x649.google.com [IPv6:2607:f8b0:4864:20::649]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 647811A7 for ; Fri, 29 Sep 2023 14:12:02 -0700 (PDT) Received: by mail-pl1-x649.google.com with SMTP id d9443c01a7336-1c74e099ba9so6397305ad.1 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=vger.kernel.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=Zd6JRriOPOX1x6aTOLFBCqzeK/oCDIqgP2b+sbpHWzAsxc6caGkOCYDY2Ks5XGVIz7 uhGkdjS/ImUVT2Iga+RfyKLbtFAf2ZfkqNEjRzGZ+AdrLnnHk1sHvMZqkvdbYIvj5YQe PeWI+aF6G+Hs+ilT6qhP22WbvLXXWY6ZsCNsxF6M8PIiaEL1Db9GE1huzhtYt+8yeQRd tWJxFZFt7W0ouxNi7gEZ2vkRcyPEVcRiTBFGf6G7VfPNia8/tTxqUbSpf4Ud3ZO5k6Zu rHDlx40FWz6xFRs/FMim9TScpVDgB0XTNOgUnZOlLPNfq9Ne7dcqOptWDmvIyVlhQSUm /KVw== 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=IvsfoQz8j9hGriUzmYU8ObZRhjrS2rvJDX7eMX4v+jorHlStZYIQFVW6SaB494Yrla 73qKFW9+fBEHaGnrlKZ8jWNS5s7iWTPKOS0bjtUGWQVCiPD2VJE3xBuedM664G9YDJYz WVjYPEPa8c58m/wOfYjoxcd4WxzRWx7nwvz8ZuXBHT9ftF+RzZPl43iMUIBOyIti8Lbx bW/ajL/M2WG42Dp6ejDJLwsrJOOVEFcsKNof96e4TjRktV09WceosP97Rpu4lTY/ec0l Xa8sIWjVqCV+ErHSMkAfc2Mm7ugQce0rfvzwI87R1wLeECsyO36r/9E6sgkxjmbBmY2G /mNw== X-Gm-Message-State: AOJu0YwOr5ocU26oKV2oL9er3xa7kUlkpY5x8R5RAtN9KI0T5ZGB61L1 zSbj4hsTGbLe4Fk+Gol0axsnh5rDg7y8rWxa6j4= 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-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Fri, 29 Sep 2023 14:13:10 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778412459790566988 X-GMAIL-MSGID: 1778412459790566988 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 /*