Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp581896rdb; Thu, 21 Dec 2023 20:51:08 -0800 (PST) X-Google-Smtp-Source: AGHT+IFpNRXEHky/re1MNt4oxrtC0IXf4Wv4enszy/WzYrg2Qsun5L6AkXyvhKExy8qJCQc/ZctH X-Received: by 2002:a17:906:a3d3:b0:a26:6e9b:a06e with SMTP id ca19-20020a170906a3d300b00a266e9ba06emr373362ejb.73.1703220668079; Thu, 21 Dec 2023 20:51:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703220668; cv=none; d=google.com; s=arc-20160816; b=y/GZSCVLDg6GlDvP0GB2UKvfBU6knfJvQghPnScSUe1ULxFcndqD329vhf4d6pJaoK 7VlhFm+Z46/f0Awh5YSaU3Pzr2QZWUGRwMINlihq6ty8+Gyerfvpj3pcsrgvSbWZ5sBu 64jN7Mo528sT4RSRGyNgPXe0FO0Nxibg37ew7rp+9ApgNkmE0F3HAvhbjQidhp0Rg4lB 922Hgr/Is4K0H/BtI4elzBSVgmWXJvavYsWRLkIfZkH89jweho7SDz7jxIKcyPVKMx0k y8gbzn/dRn+qUgsPyb4yIQtZR1uPwAtVRXobJwrBbq7fQq7tksjgjbelTEIgbVFDO9ke EdNA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=zReHV725eDRfSwC6VU7eKnGDSvNabo343kVboUA4r8s=; fh=jcohg6QvSkCye0Q+0TQCXinJ/lNxyw8rYKXS0Kgr+8g=; b=cglDaeb2evnKPqPBXbJr9bazIqL4GjafV6WdMzcx35joaAsVHQaJQABXUGNPbwIkKs F/MwJ/mTTVdxrzB1f2MYhlBRLNPUdcJt1bZYWFLTU4IyYLYIVRmK2dKbMeODHP9HRQkJ OuwvVuSI9nOCU/r0tdPe9kZR0rXTi2f+vor9Xc66/TsgCwOJJ7PW5M6kMOgJ7B5lx6hY S4c8sIBu2+Ao6jHPp5xhhLyjGEJMMVnnvryTwiTDdaOkaFeolHvPr/eiRRTII/gis3i3 9aVx260u/hIzCOwMazCbiKHkMMFXB6GHd3xqcwhLccyoWaD2rSqLe2QrJmb/3VkVfbx+ Wp2w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=buDEjzPz; spf=pass (google.com: domain of linux-kernel+bounces-9341-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-9341-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id wl6-20020a170907310600b00a269a62ff20si1363041ejb.147.2023.12.21.20.51.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Dec 2023 20:51:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-9341-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=buDEjzPz; spf=pass (google.com: domain of linux-kernel+bounces-9341-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-9341-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 939871F24DED for ; Fri, 22 Dec 2023 04:51:07 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 24B8A524F; Fri, 22 Dec 2023 04:50:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="buDEjzPz" X-Original-To: linux-kernel@vger.kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 56D9B5390; Fri, 22 Dec 2023 04:50:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D9BE5C433CD; Fri, 22 Dec 2023 04:50:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1703220657; bh=0LsfsZZzBusgIAD3qQmmUaG27xjYEQSKO7z6xMBhlSE=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=buDEjzPzJl2oOTCG4mR5hrq0Y5hBjbDkESelrGra7PVruT0KoN7WXmZfLmgG/pGo6 gO01+22n2/ktkp/IFnlDdlCkSqaFbtWbXPPkYBiu6eeE80rL5QVYNcNvA9jfU2KGq6 EU7Q6oo27Zm3n338viOKmNTfUKyULO6C1WpEXCJwVOh24KCDhrM5IW7jF1xar2CgWR AbehwW4SSzEr21ppi49PQ4t+hWsGc/rMH2zD8RqastjxFe6+CkDHwq0AnSVqXwlF+j 2JCgvEMZEhw0zBZg70qUZBSHbsAMBCd9qZ5mj6rXCwZ/UKrgtxGC2lw9DsMTJVACX5 BxdmWvEWsu/Nw== Received: by mail-ed1-f45.google.com with SMTP id 4fb4d7f45d1cf-54c79968ffbso1562202a12.3; Thu, 21 Dec 2023 20:50:57 -0800 (PST) X-Gm-Message-State: AOJu0YwxUWYog0366hfUij633lwBBYOzFw0p3hO8JHM1XmSMrE2KxYME 0w1uZ2J5bm6sI/Sr7yivTqPNdYQrzCMKwTy+FIc= X-Received: by 2002:a17:906:82:b0:a23:6fe5:affe with SMTP id 2-20020a170906008200b00a236fe5affemr414814ejc.62.1703220656295; Thu, 21 Dec 2023 20:50:56 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20231221154702.2267684-1-guoren@kernel.org> <20231221154702.2267684-3-guoren@kernel.org> In-Reply-To: From: Guo Ren Date: Fri, 22 Dec 2023 12:50:44 +0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH V2 2/4] riscv: mm: Fixup compat arch_get_mmap_end To: Leonardo Bras Cc: linux-kernel@vger.kernel.org, paul.walmsley@sifive.com, palmer@dabbelt.com, alexghiti@rivosinc.com, charlie@rivosinc.com, xiao.w.wang@intel.com, david@redhat.com, panqinglin2020@iscas.ac.cn, rick.p.edgecombe@intel.com, willy@infradead.org, bjorn@rivosinc.com, conor.dooley@microchip.com, cleger@rivosinc.com, linux-riscv@lists.infradead.org, Guo Ren , stable@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, Dec 22, 2023 at 12:43=E2=80=AFPM Leonardo Bras = wrote: > > On Fri, Dec 22, 2023 at 12:26:19PM +0800, Guo Ren wrote: > > On Fri, Dec 22, 2023 at 11:35=E2=80=AFAM Leonardo Bras wrote: > > > > > > On Thu, Dec 21, 2023 at 10:46:59AM -0500, guoren@kernel.org wrote: > > > > From: Guo Ren > > > > > > > > When the task is in COMPAT mode, the arch_get_mmap_end should be 2G= B, > > > > not TASK_SIZE_64. The TASK_SIZE has contained is_compat_mode() > > > > detection, so change the definition of STACK_TOP_MAX to TASK_SIZE > > > > directly. > > > > > > ok > > > > > > > > > > > Cc: stable@vger.kernel.org > > > > Fixes: add2cc6b6515 ("RISC-V: mm: Restrict address space for sv39,s= v48,sv57") > > > > Signed-off-by: Guo Ren > > > > Signed-off-by: Guo Ren > > > > --- > > > > arch/riscv/include/asm/processor.h | 6 ++---- > > > > 1 file changed, 2 insertions(+), 4 deletions(-) > > > > > > > > diff --git a/arch/riscv/include/asm/processor.h b/arch/riscv/includ= e/asm/processor.h > > > > index f19f861cda54..1f538fc4448d 100644 > > > > --- a/arch/riscv/include/asm/processor.h > > > > +++ b/arch/riscv/include/asm/processor.h > > > > @@ -16,15 +16,13 @@ > > > > > > > > #ifdef CONFIG_64BIT > > > > #define DEFAULT_MAP_WINDOW (UL(1) << (MMAP_VA_BITS - 1)) > > > > -#define STACK_TOP_MAX TASK_SIZE_64 > > > > +#define STACK_TOP_MAX TASK_SIZE > > > > > > It means STACK_TOP_MAX will be in 64BIT: > > > - TASK_SIZE_32 if compat_mode=3Dy > > > - TASK_SIZE_64 if compat_mode=3Dn > > > > > > Makes sense for me. > > > > > > > > > > > #define arch_get_mmap_end(addr, len, flags) \ > > > > ({ \ > > > > unsigned long mmap_end; \ > > > > typeof(addr) _addr =3D (addr); \ > > > > - if ((_addr) =3D=3D 0 || (IS_ENABLED(CONFIG_COMPAT) && is_comp= at_task())) \ > > > > - mmap_end =3D STACK_TOP_MAX; \ > > > > - else if ((_addr) >=3D VA_USER_SV57) \ > > > > + if ((_addr) =3D=3D 0 || (_addr) >=3D VA_USER_SV57) = \ > > > > mmap_end =3D STACK_TOP_MAX; \ > > > > else if ((((_addr) >=3D VA_USER_SV48)) && (VA_BITS >=3D VA_BI= TS_SV48)) \ > > > > mmap_end =3D VA_USER_SV48; \ > > > > > > > > > I don't think I got this change, or how it's connected to the commit = msg. > > The above is just code simplification; if STACK_TOP_MAX is TASK_SIZE, t= hen > > > > if ((_addr) =3D=3D 0 || (IS_ENABLED(CONFIG_COMPAT) && is_compat_ta= sk())) \ > > mmap_end =3D STACK_TOP_MAX; \ > > else if ((_addr) >=3D VA_USER_SV57) \ > > > > is equal to: > > > > if ((_addr) =3D=3D 0 || (_addr) >=3D VA_USER_SV57) \ > > I am failing to understand exactly how are they equal. > I mean, what in your STACK_TOP_MAX change made them equal? #define STACK_TOP_MAX TASK_SIZE #define TASK_SIZE (is_compat_task() ? TASK_SIZE_32 : TASK_SIZE_64) > > See below, the behavior changed: > > > > > > > > Before: > > > - addr =3D=3D 0, or addr > 2^57, or compat: mmap_end =3D STACK_TOP_MA= X > > > - 2^48 < addr < 2^57: mmap_end =3D 2^48 > > > - 0 < addr < 2^48 : mmap_end =3D 2^39 > > > > > > Now: > > > - addr =3D=3D 0, or addr > 2^57: mmap_end =3D STACK_TOP_MAX > > > - 2^48 < addr < 2^57: mmap_end =3D 2^48 > > > - 0 < addr < 2^48 : mmap_end =3D 2^39 > > > > > > IIUC compat mode addr will be < 2^32, so will always have mmap_end = =3D 2^39 > > > if addr !=3D 0. Is that desireable? > > > (if not, above change is unneeded) > > > > > ^ > > With your change on STACK_TOP_MAX only (not changing arch_get_mmap_end), > you would have: > > - compat_mode & (0 < addr < 2^32) -> mmap_end =3D 2^32 compat_mode -> mmap_end =3D 2^32 > - non-compat, addr =3D=3D 0, or addr > 2^57 -> mmap_end =3D TASK_SIZE_64 > - non-compat, (2^48 < addr < 2^57) -> mmap_end =3D 2^48 > - non-compat, (0 < addr < 2^48) -> mmap_end =3D 2^39 > > Which seems more likely, based on Charlie comments. > > Thanks, > Leo > > > > Also, unrelated to the change: > > > - 2^48 < addr < 2^57: mmap_end =3D 2^48 > > > Is the above correct? > > > It looks like it should be 2^57 instead, and a new if clause for > > > 2^32 < addr < 2^48 should have mmap_end =3D 2^48. > > > > > > Do I get it wrong? > > Maybe I should move this into the optimization part. > > > > > > > > (I will send an RFC 'fixing' the code the way I am whinking it should= look > > > like) > > > > > > Thanks, > > > Leo > > > > > > > > > > > > > > > > > > > -- > > > > 2.40.1 > > > > > > > > > > > > > -- > > Best Regards > > Guo Ren > > > --=20 Best Regards Guo Ren