Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp405025rwb; Thu, 27 Jul 2023 14:53:00 -0700 (PDT) X-Google-Smtp-Source: APBJJlHRyVwcF11xW5p8IEw1LV5WMRkwE3Xi+rYYCdWcMBdJ4SzrxxL6PxhF2faX88i5xr/NRH1T X-Received: by 2002:a17:902:d505:b0:1bb:d70b:e00a with SMTP id b5-20020a170902d50500b001bbd70be00amr636697plg.67.1690494779721; Thu, 27 Jul 2023 14:52:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690494779; cv=none; d=google.com; s=arc-20160816; b=tfFO30LsNO+saNA5hCl/a60jt0hFkT3wFgBQhtCI8NXGqDpoJ1AyAu1HXylasqFl9U j6BvIUvQafv/1AfYyqKhaCzK1A/bV5UMI65BGKFRl5w70lubDuNPFwL/RCKZagqpiEze IjoP5ugOb05pMJCr7+P0qqLlEYlw511LjIGMvFhG8Rt6xpWUGfwJVQOuJdA2bYBI01l9 5OFegO1Z2xDCmFnT2U8on3FPGpq+0PpqPydrN3recynOBy1JImAcz2mEBLx/hN0V4ZqX +Wk+A8NTWCaEThTCdrE0K4daA2IJD1PPxcN+62c9wEVAgsB769MyV6q5D5de1vlIHzg7 zeZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=ypAMONzQ9lM309vcGdh+Fb16cWv7RYOttEkuLSf+C9Q=; fh=7i4TRJ7DA21prUbxj6rESjNwgheLo/LBvmDJ64jGKyw=; b=BV6BVJBuRHL5/xYRyUfqoZf6EGDI59hEiVkJcfMhC3psYdZ/nuB8l6Fu26Qsf0cZ0Q SSJO0UyG+vBi3TW+H2Iet4IzvPaMlDXpr+jgmHiHglS+6C3HpB+q00px/rM+mixntGbh gifwQpkC8ZYhdajcC5bo5UkYUGBvdweZZSR13c7TBwkJbMzFFH6Dn9JFM+2B+RyuS8CI tC8qNcmxeZB4zZpub2lG+DY3xJc7W7+QQFyYnUn7SbU6pJ3dy/92aGEYETsuJAhZxdqY fLoQ7vaTUScrJDOyDv/6hY//uToxoFiUljfEWMMjYXQDDd4/2969tEyxFw5TNpJWnD89 pzUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rivosinc-com.20221208.gappssmtp.com header.s=20221208 header.b=Bwo2x8zf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n2-20020a170902d0c200b001b9c205a860si1773514pln.377.2023.07.27.14.52.47; Thu, 27 Jul 2023 14:52:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20221208.gappssmtp.com header.s=20221208 header.b=Bwo2x8zf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231856AbjG0V3w (ORCPT + 99 others); Thu, 27 Jul 2023 17:29:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52964 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232107AbjG0V3s (ORCPT ); Thu, 27 Jul 2023 17:29:48 -0400 Received: from mail-pf1-x430.google.com (mail-pf1-x430.google.com [IPv6:2607:f8b0:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BFAD630FC for ; Thu, 27 Jul 2023 14:29:20 -0700 (PDT) Received: by mail-pf1-x430.google.com with SMTP id d2e1a72fcca58-686c06b806cso1132874b3a.2 for ; Thu, 27 Jul 2023 14:29:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20221208.gappssmtp.com; s=20221208; t=1690493360; x=1691098160; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=ypAMONzQ9lM309vcGdh+Fb16cWv7RYOttEkuLSf+C9Q=; b=Bwo2x8zf58r3/17nU/dEA+lgi98417VBN10q9GpXZ2yX5bWgvClfFlRZrYgWh6vxOe r0mqw4aODhaJ2EjfLMEWChHMJo67QiYL7UuI76V0B5V0sBJqx633/8IdKvZ62MQ2+DUl J6GIo9C/bwVjsIs63nkDd9w15op+eE3bPam4/TK3NShywE+8Xx/75LaHkeodFIhEIwPp is5HGGIxHwP3BUX1Gg8ys2pqCCyqagzNp8TAZ2n3ah5xe/s8AuEUZyERBtbzxBBvh8e7 XW1EoV/f/B6VtHMfKKSgdzL/ZzdtxWPLIZShgMFFsPR1z034QbJg23p3Jo+apDeFjXi3 3MAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690493360; x=1691098160; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=ypAMONzQ9lM309vcGdh+Fb16cWv7RYOttEkuLSf+C9Q=; b=V93MA9mAlL+qdyaikbCecECEDSrJnkAPi/kls1WERX4+5TRWNohrtv61SdX/YPznsm mx6dOwOuLRW1qY/DlzKH9SLR80LvNxdMdIfRt37G18JGn1uw22+BuUnAiO2V34xWAekD H0mg6o+3DjWoN9TTSBTeCdPRMMhvufOuYX1hY4TR/ElG2NUwKt/1nUHgOytu5sQHkpGL rVXDVUl5wrmEFvd0AEjmSK2OVaJUA0ZrMDtcALgcDunPs4djGgZoCxT6kxQf4wvHduES xIFhpTmq98LcrfIKYxLUdlvLeKG5HntcyriQ0vVLAo9UK00njatImm8mRU1wice5W2+c vBVg== X-Gm-Message-State: ABy/qLZQAJKoiNJgG3q+U0CXxmejdaHaas4vvrLKinM2o6Fvbwc7FEPi 7tYMbQqJPx2sQOywaizJ/S9lAA== X-Received: by 2002:a05:6a20:7351:b0:133:656e:fe1e with SMTP id v17-20020a056a20735100b00133656efe1emr268970pzc.47.1690493360245; Thu, 27 Jul 2023 14:29:20 -0700 (PDT) Received: from ghost ([2601:c0:ca7f:e7c0:e300:c3dd:e089:386]) by smtp.gmail.com with ESMTPSA id b14-20020aa7870e000000b00686c77a2905sm1906083pfo.20.2023.07.27.14.29.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jul 2023 14:29:20 -0700 (PDT) Date: Thu, 27 Jul 2023 17:29:16 -0400 From: Charlie Jenkins To: Conor Dooley Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, paul.walmsley@sifive.com, palmer@rivosinc.com, aou@eecs.berkeley.edu, anup@brainfault.org, konstantin@linuxfoundation.org, linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org, mick@ics.forth.gr, jrtc27@jrtc27.com, rdunlap@infradead.org, alexghiti@rivosinc.com Subject: Re: [PATCH v7 1/4] RISC-V: mm: Restrict address space for sv39,sv48,sv57 Message-ID: References: <20230726164620.717288-1-charlie@rivosinc.com> <20230726164620.717288-2-charlie@rivosinc.com> <20230727-unruffled-joyride-410fc348ce7b@spud> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230727-unruffled-joyride-410fc348ce7b@spud> X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE 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 On Thu, Jul 27, 2023 at 01:33:41PM +0100, Conor Dooley wrote: > Hey Charlie, > > On Wed, Jul 26, 2023 at 09:45:55AM -0700, Charlie Jenkins wrote: > > Make sv48 the default address space for mmap as some applications > > currently depend on this assumption. A hint address passed to mmap will > > cause the largest address space that fits entirely into the hint to be > > used. If the hint is less than or equal to 1<<38, an sv39 address will > > be used. An exception is that if the hint address is 0, then a sv48 > > address will be used. After an address space is completely full, the next > > smallest address space will be used. > > > > Signed-off-by: Charlie Jenkins > > --- > > arch/riscv/include/asm/elf.h | 2 +- > > arch/riscv/include/asm/pgtable.h | 13 ++++++++- > > arch/riscv/include/asm/processor.h | 47 +++++++++++++++++++++++++----- > > 3 files changed, 53 insertions(+), 9 deletions(-) > > > > diff --git a/arch/riscv/include/asm/elf.h b/arch/riscv/include/asm/elf.h > > index c24280774caf..5d3368d5585c 100644 > > --- a/arch/riscv/include/asm/elf.h > > +++ b/arch/riscv/include/asm/elf.h > > @@ -49,7 +49,7 @@ extern bool compat_elf_check_arch(Elf32_Ehdr *hdr); > > * the loader. We need to make sure that it is out of the way of the program > > * that it will "exec", and that there is sufficient room for the brk. > > */ > > -#define ELF_ET_DYN_BASE ((TASK_SIZE / 3) * 2) > > +#define ELF_ET_DYN_BASE ((DEFAULT_MAP_WINDOW / 3) * 2) > > > > #ifdef CONFIG_64BIT > > #ifdef CONFIG_COMPAT > > diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/asm/pgtable.h > > index 75970ee2bda2..530f6a171a2b 100644 > > --- a/arch/riscv/include/asm/pgtable.h > > +++ b/arch/riscv/include/asm/pgtable.h > > @@ -63,12 +63,23 @@ > > * position vmemmap directly below the VMALLOC region. > > */ > > #ifdef CONFIG_64BIT > > +#define VA_BITS_SV39 39 > > +#define VA_BITS_SV48 48 > > +#define VA_BITS_SV57 57 > > + > > +#define VA_USER_SV39 (UL(1) << (VA_BITS_SV39 - 1)) > > +#define VA_USER_SV48 (UL(1) << (VA_BITS_SV48 - 1)) > > +#define VA_USER_SV57 (UL(1) << (VA_BITS_SV57 - 1)) > > + > > #define VA_BITS (pgtable_l5_enabled ? \ > > - 57 : (pgtable_l4_enabled ? 48 : 39)) > > + VA_BITS_SV57 : (pgtable_l4_enabled ? VA_BITS_SV48 : VA_BITS_SV39)) > > #else > > #define VA_BITS 32 > > #endif > > Please, at the very least, build test things for rv32 if you are going > to change things in mm: > io_uring/io_uring.c:3457:20: error: use of undeclared identifier 'VA_BITS_SV39' > io_uring/io_uring.c:3457:20: error: use of undeclared identifier 'VA_BITS_SV39' > io_uring/io_uring.c:3457:20: error: use of undeclared identifier 'VA_BITS_SV39' > io_uring/io_uring.c:3457:20: error: use of undeclared identifier 'VA_BITS_SV39' > io_uring/io_uring.c:3457:20: error: use of undeclared identifier 'VA_BITS_SV39' > io_uring/io_uring.c:3457:20: error: use of undeclared identifier 'VA_BITS_SV39' > mm/util.c:441:19: error: use of undeclared identifier 'VA_BITS_SV39' > mm/util.c:441:19: error: use of undeclared identifier 'VA_BITS_SV39' > mm/util.c:441:19: error: use of undeclared identifier 'VA_BITS_SV39' > mm/util.c:441:19: error: use of undeclared identifier 'VA_BITS_SV39' > mm/util.c:441:19: error: use of undeclared identifier 'VA_BITS_SV39' > mm/util.c:441:19: error: use of undeclared identifier 'VA_BITS_SV39' > mm/mmap.c:1770:20: error: use of undeclared identifier 'VA_BITS_SV39' > mm/mmap.c:1770:20: error: use of undeclared identifier 'VA_BITS_SV39' > mm/mmap.c:1770:20: error: use of undeclared identifier 'VA_BITS_SV39' > mm/mmap.c:1770:20: error: use of undeclared identifier 'VA_BITS_SV39' > mm/mmap.c:1770:20: error: use of undeclared identifier 'VA_BITS_SV39' > mm/mmap.c:1770:20: error: use of undeclared identifier 'VA_BITS_SV39' > > Thanks, > Conor. Thanks for that catch, I sent out a new patch to fix that up. There were also some problems with 32-bit compat support that I resolved.