Message ID | 20230929211155.3910949-6-samitolvanen@google.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> 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 <rfc822;pwkd43@gmail.com> + 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 <rfc822;linux-kernel@vger.kernel.org>); 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 <linux-kernel@vger.kernel.org>; Fri, 29 Sep 2023 14:12:02 -0700 (PDT) Received: by mail-pl1-x649.google.com with SMTP id d9443c01a7336-1c74e099ba9so6397305ad.1 for <linux-kernel@vger.kernel.org>; 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 <samitolvanen@google.com> To: Paul Walmsley <paul.walmsley@sifive.com>, Palmer Dabbelt <palmer@dabbelt.com>, Albert Ou <aou@eecs.berkeley.edu>, Andrew Morton <akpm@linux-foundation.org>, Kees Cook <keescook@chromium.org> Cc: linux-mm@kvack.org, linux-riscv@lists.infradead.org, llvm@lists.linux.dev, linux-kernel@vger.kernel.org, Sami Tolvanen <samitolvanen@google.com> Content-Type: text/plain; charset="UTF-8" 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: <linux-kernel.vger.kernel.org> 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 |
Series |
riscv: Increase mmap_rnd_bits_max on Sv48/57
|
|
Commit Message
Sami Tolvanen
Sept. 29, 2023, 9:11 p.m. UTC
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 <samitolvanen@google.com>
---
arch/riscv/mm/init.c | 6 ++++++
1 file changed, 6 insertions(+)
Comments
On Fri, Sep 29, 2023 at 09:11:58PM +0000, Sami Tolvanen wrote: > 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 <samitolvanen@google.com> I like this. Is RISCV the only arch where the paging level can be chosen at boot time? Reviewed-by: Kees Cook <keescook@chromium.org>
On Fri, Sep 29, 2023 at 2:54 PM Kees Cook <keescook@chromium.org> wrote: > > On Fri, Sep 29, 2023 at 09:11:58PM +0000, Sami Tolvanen wrote: > > 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 <samitolvanen@google.com> > > I like this. Is RISCV the only arch where the paging level can be chosen > at boot time? I haven't seen this elsewhere, but I also haven't looked at all the other architectures that closely. arm64 does something interesting with ARM64_VA_BITS_52, but I think we can still handle that in Kconfig. Sami
On Fri, Sep 29, 2023 at 03:52:22PM -0700, Sami Tolvanen wrote: > On Fri, Sep 29, 2023 at 2:54 PM Kees Cook <keescook@chromium.org> wrote: > > > > On Fri, Sep 29, 2023 at 09:11:58PM +0000, Sami Tolvanen wrote: > > > 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 <samitolvanen@google.com> > > > > I like this. Is RISCV the only arch where the paging level can be chosen > > at boot time? > > I haven't seen this elsewhere, but I also haven't looked at all the > other architectures that closely. arm64 does something interesting > with ARM64_VA_BITS_52, but I think we can still handle that in > Kconfig. AFAIU, x86-64 can do this also: no4lvl [RISCV] Disable 4-level and 5-level paging modes. Forces kernel to use 3-level paging instead. no5lvl [X86-64,RISCV] Disable 5-level paging mode. Forces kernel to use 4-level paging instead.
On Sat, Sep 30, 2023 at 10:02:35AM +0100, Conor Dooley wrote: > On Fri, Sep 29, 2023 at 03:52:22PM -0700, Sami Tolvanen wrote: > > On Fri, Sep 29, 2023 at 2:54 PM Kees Cook <keescook@chromium.org> wrote: > > > > > > On Fri, Sep 29, 2023 at 09:11:58PM +0000, Sami Tolvanen wrote: > > > > 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 <samitolvanen@google.com> > > > > > > I like this. Is RISCV the only arch where the paging level can be chosen > > > at boot time? > > > > I haven't seen this elsewhere, but I also haven't looked at all the > > other architectures that closely. arm64 does something interesting > > with ARM64_VA_BITS_52, but I think we can still handle that in > > Kconfig. > > AFAIU, x86-64 can do this also: > > no4lvl [RISCV] Disable 4-level and 5-level paging modes. Forces > kernel to use 3-level paging instead. > > no5lvl [X86-64,RISCV] Disable 5-level paging mode. Forces > kernel to use 4-level paging instead. Ah-ha! Okay, well, then let's track this idea: https://github.com/KSPP/linux/issues/346
On Sun, Oct 1, 2023 at 2:51 AM Kees Cook <keescook@chromium.org> wrote: > > On Sat, Sep 30, 2023 at 10:02:35AM +0100, Conor Dooley wrote: > > On Fri, Sep 29, 2023 at 03:52:22PM -0700, Sami Tolvanen wrote: > > > On Fri, Sep 29, 2023 at 2:54 PM Kees Cook <keescook@chromium.org> wrote: > > > > > > > > On Fri, Sep 29, 2023 at 09:11:58PM +0000, Sami Tolvanen wrote: > > > > > 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 <samitolvanen@google.com> > > > > > > > > I like this. Is RISCV the only arch where the paging level can be chosen > > > > at boot time? > > > > > > I haven't seen this elsewhere, but I also haven't looked at all the > > > other architectures that closely. arm64 does something interesting > > > with ARM64_VA_BITS_52, but I think we can still handle that in > > > Kconfig. > > > > AFAIU, x86-64 can do this also: > > > > no4lvl [RISCV] Disable 4-level and 5-level paging modes. Forces > > kernel to use 3-level paging instead. > > > > no5lvl [X86-64,RISCV] Disable 5-level paging mode. Forces > > kernel to use 4-level paging instead. > > Ah-ha! Okay, well, then let's track this idea: > https://github.com/KSPP/linux/issues/346 (Replying here for visibility, tell me if you want to move this discussion to github) AIUI, x86 cannot do this for compat reasons. Even if you enable LA57, mmap only gives you < 48-bit addresses, for compatibility with things like JITs, etc that stash information in the upper 16 bits. You need to pass a > 48-bit mmap hint to get 57-bit addresses. I imagine riscv does not have this issue yet, due to little accumulated cruft, but it may be wise to check against popular JITters for these problems on riscv code.
On 01/10/2023 17:19, Pedro Falcato wrote: > On Sun, Oct 1, 2023 at 2:51 AM Kees Cook <keescook@chromium.org> wrote: >> On Sat, Sep 30, 2023 at 10:02:35AM +0100, Conor Dooley wrote: >>> On Fri, Sep 29, 2023 at 03:52:22PM -0700, Sami Tolvanen wrote: >>>> On Fri, Sep 29, 2023 at 2:54 PM Kees Cook <keescook@chromium.org> wrote: >>>>> On Fri, Sep 29, 2023 at 09:11:58PM +0000, Sami Tolvanen wrote: >>>>>> 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 <samitolvanen@google.com> >>>>> I like this. Is RISCV the only arch where the paging level can be chosen >>>>> at boot time? >>>> I haven't seen this elsewhere, but I also haven't looked at all the >>>> other architectures that closely. arm64 does something interesting >>>> with ARM64_VA_BITS_52, but I think we can still handle that in >>>> Kconfig. >>> AFAIU, x86-64 can do this also: >>> >>> no4lvl [RISCV] Disable 4-level and 5-level paging modes. Forces >>> kernel to use 3-level paging instead. >>> >>> no5lvl [X86-64,RISCV] Disable 5-level paging mode. Forces >>> kernel to use 4-level paging instead. >> Ah-ha! Okay, well, then let's track this idea: >> https://github.com/KSPP/linux/issues/346 > (Replying here for visibility, tell me if you want to move this > discussion to github) > > AIUI, x86 cannot do this for compat reasons. Even if you enable LA57, > mmap only gives you < 48-bit addresses, for compatibility with things > like JITs, etc that stash information in the upper 16 bits. You need > to pass a > 48-bit mmap hint to get 57-bit addresses. > > I imagine riscv does not have this issue yet, due to little > accumulated cruft, but it may be wise to check against popular JITters > for these problems on riscv code. > We already encountered those issues and the same solution was recently merged (restrict to sv48 unless otherwise specified): https://lore.kernel.org/all/20230809232218.849726-1-charlie@rivosinc.com/
On Mon, Oct 2, 2023 at 12:02 AM Alexandre Ghiti <alex@ghiti.fr> wrote: > > On 01/10/2023 17:19, Pedro Falcato wrote: > > On Sun, Oct 1, 2023 at 2:51 AM Kees Cook <keescook@chromium.org> wrote: > >> On Sat, Sep 30, 2023 at 10:02:35AM +0100, Conor Dooley wrote: > >>> On Fri, Sep 29, 2023 at 03:52:22PM -0700, Sami Tolvanen wrote: > >>>> On Fri, Sep 29, 2023 at 2:54 PM Kees Cook <keescook@chromium.org> wrote: > >>>>> On Fri, Sep 29, 2023 at 09:11:58PM +0000, Sami Tolvanen wrote: > >>>>>> 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 <samitolvanen@google.com> > >>>>> I like this. Is RISCV the only arch where the paging level can be chosen > >>>>> at boot time? > >>>> I haven't seen this elsewhere, but I also haven't looked at all the > >>>> other architectures that closely. arm64 does something interesting > >>>> with ARM64_VA_BITS_52, but I think we can still handle that in > >>>> Kconfig. > >>> AFAIU, x86-64 can do this also: > >>> > >>> no4lvl [RISCV] Disable 4-level and 5-level paging modes. Forces > >>> kernel to use 3-level paging instead. > >>> > >>> no5lvl [X86-64,RISCV] Disable 5-level paging mode. Forces > >>> kernel to use 4-level paging instead. > >> Ah-ha! Okay, well, then let's track this idea: > >> https://github.com/KSPP/linux/issues/346 > > (Replying here for visibility, tell me if you want to move this > > discussion to github) > > > > AIUI, x86 cannot do this for compat reasons. Even if you enable LA57, > > mmap only gives you < 48-bit addresses, for compatibility with things > > like JITs, etc that stash information in the upper 16 bits. You need > > to pass a > 48-bit mmap hint to get 57-bit addresses. > > > > I imagine riscv does not have this issue yet, due to little > > accumulated cruft, but it may be wise to check against popular JITters > > for these problems on riscv code. > > > > We already encountered those issues and the same solution was recently > merged (restrict to sv48 unless otherwise specified): > https://lore.kernel.org/all/20230809232218.849726-1-charlie@rivosinc.com/ We recently ran into this issue when bringing up Android as well because qemu defaults to Sv57 and some userspace bits weren't happy with >48-bit mmap addresses. Note that this patch uses MMAP_VA_BITS, which is 48 for both Sv48 and Sv57, which is why mmap_rnd_bits_max will be 33 even with Sv57. Sami
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 /*