Message ID | 20231222115703.2404036-2-guoren@kernel.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-9679-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2483:b0:fb:cd0c:d3e with SMTP id q3csp1006781dyi; Fri, 22 Dec 2023 03:58:10 -0800 (PST) X-Google-Smtp-Source: AGHT+IHzRvv4qh/h4sXGxmZhpEoftlSz+M2Un1p5F0gCaI+KgX6uK8WFSKXOb7ev4tFrGCpG/nBr X-Received: by 2002:a05:622a:1ba0:b0:427:9b36:d8f with SMTP id bp32-20020a05622a1ba000b004279b360d8fmr1235192qtb.93.1703246289823; Fri, 22 Dec 2023 03:58:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703246289; cv=none; d=google.com; s=arc-20160816; b=egjogcVjiVJf1sNIqEksND0XfqxnCbnMWbKtSoOggTJ53JRcS0wuYKJ0AFhceKHh5J vpEJSo0LNBft2hqTwGQ/821D08cRiWEoeIXXtuUOsxT7tXXIrC55MgVFprRwoYQz//1n G9fSkbeltLgO0NrYz+7Pj6IFEzmCdN7wfwbQDzXD7eFOQ+XeOD85paesBUreJ+eg/UM6 ypCtwQY9yItAEDb2LolbgU1HallIg9rzr8ZPEZC2MQOwQHo66r5S3sXr3KGlMqon774z W0+3vKFWzPoUttoFe/9sIcpbJ31T9ioaE4w4s8fHnb72kc00DtvmPZ73nLS2k8dSU3E5 AwBg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=cA4wksJKldGt+LCgiLDGw2cF2dfjvj8srBypxzsUtSk=; fh=3YQLS1cPsLhMKuGGotL7Ux7rpkwBoh7ZT2nN27VXc5c=; b=fmc2r1vEh7qH2gPdDC1By4ntgdb1IN74yXIICFI0+SVSoCagMJs4AyHeYYqqEGB0Gr M5b9Q5nlqE/7SiNpB05DgWn2oPiPY7AzF2bSXATJG7zOCFEpsphkK8GE+34GHMeNCG5z W9Y+qnHainywHw63HTbYdM9hyZZVB8mbVPlExp/VbRPvGWQyqKZ6KEjZgXgg6wq3PzkK ScGV1MhICroj0lku286lZ2zyZCvO4bExWrxQ+ELLS3W5Tbk9S5uPBrtdmW9YWM7ciiM6 kEqbWnhaugz8dgMhHAVVhqtxJ6+3IpkI3UICI0Oj9Vp8Ig7S1N/C8d0qpuwkuQAshcx/ nwUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=b9qp0VEO; spf=pass (google.com: domain of linux-kernel+bounces-9679-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-9679-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id u21-20020ac858d5000000b004259d9fde02si4164892qta.438.2023.12.22.03.58.09 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Dec 2023 03:58:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-9679-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=b9qp0VEO; spf=pass (google.com: domain of linux-kernel+bounces-9679-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-9679-ouuuleilei=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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 98D251C24A06 for <ouuuleilei@gmail.com>; Fri, 22 Dec 2023 11:58:09 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 176FA1A726; Fri, 22 Dec 2023 11:57:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="b9qp0VEO" 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 6451F17985; Fri, 22 Dec 2023 11:57:26 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7A7F8C433C8; Fri, 22 Dec 2023 11:57:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1703246245; bh=OMHoJ47sH8QL4h4TQhZ+b4gxch9yOK4WdYt6lzVlcv4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=b9qp0VEOGkrFAhxqIe4d6Y9gIs4x6sOfZwhGePIfwsqsVInwDYDn9xyPy0D6jHDf8 l80dp1DCIjiaIdq+5PnC7VMWBk1I1MVo2Kvz3lRX0lS+aStpiAEZpUTJ8a+nK6Cisq NPYiyqFkNnPd8iWk2opA3z9L0YWxKnMqBqifWtQZIoRcJt3hQZ5/8BdK20/JycOtV9 Vbu+Nf5bLXqImKx4F3uGjyRTiWakhBpnEd8OBDrR5Ky3U9rAjZcwI9w4n3wFEDlAUO JZQPQG3kpw5ZQVC2kAlMqOCLgqXJ97JXpA6tIzhx/yl2RMQQcSH9BYkEJx/5wHioZL HHbRAb8qWlz/w== From: guoren@kernel.org To: linux-kernel@vger.kernel.org, paul.walmsley@sifive.com, palmer@dabbelt.com, alexghiti@rivosinc.com, charlie@rivosinc.com, xiao.w.wang@intel.com, guoren@kernel.org, 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, leobras@redhat.com Cc: linux-riscv@lists.infradead.org, Guo Ren <guoren@linux.alibaba.com>, stable@vger.kernel.org Subject: [PATCH V3 1/4] riscv: mm: Fixup compat mode boot failure Date: Fri, 22 Dec 2023 06:57:00 -0500 Message-Id: <20231222115703.2404036-2-guoren@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231222115703.2404036-1-guoren@kernel.org> References: <20231222115703.2404036-1-guoren@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785983181296459584 X-GMAIL-MSGID: 1785983181296459584 |
Series |
riscv: mm: Fixup & Optimize COMPAT code
|
|
Commit Message
Guo Ren
Dec. 22, 2023, 11:57 a.m. UTC
From: Guo Ren <guoren@linux.alibaba.com> In COMPAT mode, the STACK_TOP is DEFAULT_MAP_WINDOW (0x80000000), but the TASK_SIZE is 0x7fff000. When the user stack is upon 0x7fff000, it will cause a user segment fault. Sometimes, it would cause boot failure when the whole rootfs is rv32. Freeing unused kernel image (initmem) memory: 2236K Run /sbin/init as init process Starting init: /sbin/init exists but couldn't execute it (error -14) Run /etc/init as init process ... Increase the TASK_SIZE to cover STACK_TOP. Cc: stable@vger.kernel.org Fixes: add2cc6b6515 ("RISC-V: mm: Restrict address space for sv39,sv48,sv57") Signed-off-by: Guo Ren <guoren@linux.alibaba.com> Signed-off-by: Guo Ren <guoren@kernel.org> --- arch/riscv/include/asm/pgtable.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Comments
On Fri, Dec 22, 2023 at 06:57:00AM -0500, guoren@kernel.org wrote: > From: Guo Ren <guoren@linux.alibaba.com> > > In COMPAT mode, the STACK_TOP is DEFAULT_MAP_WINDOW (0x80000000), but > the TASK_SIZE is 0x7fff000. When the user stack is upon 0x7fff000, it > will cause a user segment fault. Sometimes, it would cause boot > failure when the whole rootfs is rv32. > > Freeing unused kernel image (initmem) memory: 2236K > Run /sbin/init as init process > Starting init: /sbin/init exists but couldn't execute it (error -14) > Run /etc/init as init process > ... > > Increase the TASK_SIZE to cover STACK_TOP. > > Cc: stable@vger.kernel.org > Fixes: add2cc6b6515 ("RISC-V: mm: Restrict address space for sv39,sv48,sv57") > Signed-off-by: Guo Ren <guoren@linux.alibaba.com> > Signed-off-by: Guo Ren <guoren@kernel.org> > --- > arch/riscv/include/asm/pgtable.h | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/asm/pgtable.h > index ab00235b018f..74ffb2178f54 100644 > --- a/arch/riscv/include/asm/pgtable.h > +++ b/arch/riscv/include/asm/pgtable.h > @@ -881,7 +881,7 @@ static inline pte_t pte_swp_clear_exclusive(pte_t pte) > #define TASK_SIZE_MIN (PGDIR_SIZE_L3 * PTRS_PER_PGD / 2) > > #ifdef CONFIG_COMPAT > -#define TASK_SIZE_32 (_AC(0x80000000, UL) - PAGE_SIZE) > +#define TASK_SIZE_32 (_AC(0x80000000, UL)) > #define TASK_SIZE (test_thread_flag(TIF_32BIT) ? \ > TASK_SIZE_32 : TASK_SIZE_64) > #else > -- > 2.40.1 > I am not really involved in the issue this is solving, so I have no technical opinion on the solution. IIUC there should always be (TASK_SIZE >= STACK_TOP), so by itself this is fixing an issue. I have reviewed the code and it does exactly as stated into the commit message, so FWIW: Reviewed-by: Leonardo Bras <leobras@redhat.com>
On Sat, Dec 23, 2023 at 10:58 AM Leonardo Bras <leobras@redhat.com> wrote: > > On Fri, Dec 22, 2023 at 06:57:00AM -0500, guoren@kernel.org wrote: > > From: Guo Ren <guoren@linux.alibaba.com> > > > > In COMPAT mode, the STACK_TOP is DEFAULT_MAP_WINDOW (0x80000000), but > > the TASK_SIZE is 0x7fff000. When the user stack is upon 0x7fff000, it > > will cause a user segment fault. Sometimes, it would cause boot > > failure when the whole rootfs is rv32. > > > > Freeing unused kernel image (initmem) memory: 2236K > > Run /sbin/init as init process > > Starting init: /sbin/init exists but couldn't execute it (error -14) > > Run /etc/init as init process > > ... > > > > Increase the TASK_SIZE to cover STACK_TOP. > > > > Cc: stable@vger.kernel.org > > Fixes: add2cc6b6515 ("RISC-V: mm: Restrict address space for sv39,sv48,sv57") > > Signed-off-by: Guo Ren <guoren@linux.alibaba.com> > > Signed-off-by: Guo Ren <guoren@kernel.org> > > --- > > arch/riscv/include/asm/pgtable.h | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/asm/pgtable.h > > index ab00235b018f..74ffb2178f54 100644 > > --- a/arch/riscv/include/asm/pgtable.h > > +++ b/arch/riscv/include/asm/pgtable.h > > @@ -881,7 +881,7 @@ static inline pte_t pte_swp_clear_exclusive(pte_t pte) > > #define TASK_SIZE_MIN (PGDIR_SIZE_L3 * PTRS_PER_PGD / 2) > > > > #ifdef CONFIG_COMPAT > > -#define TASK_SIZE_32 (_AC(0x80000000, UL) - PAGE_SIZE) > > +#define TASK_SIZE_32 (_AC(0x80000000, UL)) > > #define TASK_SIZE (test_thread_flag(TIF_32BIT) ? \ > > TASK_SIZE_32 : TASK_SIZE_64) > > #else > > -- > > 2.40.1 > > > > I am not really involved in the issue this is solving, so I have no > technical opinion on the solution. > > IIUC there should always be (TASK_SIZE >= STACK_TOP), so by itself this > is fixing an issue. > > I have reviewed the code and it does exactly as stated into the commit > message, so FWIW: > Reviewed-by: Leonardo Bras <leobras@redhat.com> Thx, I found this problem because it can't boot my rv32 buildroot-rootfs in v6.6. But it's okay in v6.5. So I used git bisect and found commit: add2cc6b6515 ("RISC-V: mm: Restrict address space for sv39,sv48,sv57"), which caused that. Ping Charlie, I hope it can be fixed in the v6.6 long-term version. > -- Best Regards Guo Ren
On Sat, Dec 23, 2023 at 11:07:29AM +0800, Guo Ren wrote: > On Sat, Dec 23, 2023 at 10:58 AM Leonardo Bras <leobras@redhat.com> wrote: > > > > On Fri, Dec 22, 2023 at 06:57:00AM -0500, guoren@kernel.org wrote: > > > From: Guo Ren <guoren@linux.alibaba.com> > > > > > > In COMPAT mode, the STACK_TOP is DEFAULT_MAP_WINDOW (0x80000000), but > > > the TASK_SIZE is 0x7fff000. When the user stack is upon 0x7fff000, it > > > will cause a user segment fault. Sometimes, it would cause boot > > > failure when the whole rootfs is rv32. > > > > > > Freeing unused kernel image (initmem) memory: 2236K > > > Run /sbin/init as init process > > > Starting init: /sbin/init exists but couldn't execute it (error -14) > > > Run /etc/init as init process > > > ... > > > > > > Increase the TASK_SIZE to cover STACK_TOP. > > > > > > Cc: stable@vger.kernel.org > > > Fixes: add2cc6b6515 ("RISC-V: mm: Restrict address space for sv39,sv48,sv57") > > > Signed-off-by: Guo Ren <guoren@linux.alibaba.com> > > > Signed-off-by: Guo Ren <guoren@kernel.org> > > > --- > > > arch/riscv/include/asm/pgtable.h | 2 +- > > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > > > diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/asm/pgtable.h > > > index ab00235b018f..74ffb2178f54 100644 > > > --- a/arch/riscv/include/asm/pgtable.h > > > +++ b/arch/riscv/include/asm/pgtable.h > > > @@ -881,7 +881,7 @@ static inline pte_t pte_swp_clear_exclusive(pte_t pte) > > > #define TASK_SIZE_MIN (PGDIR_SIZE_L3 * PTRS_PER_PGD / 2) > > > > > > #ifdef CONFIG_COMPAT > > > -#define TASK_SIZE_32 (_AC(0x80000000, UL) - PAGE_SIZE) > > > +#define TASK_SIZE_32 (_AC(0x80000000, UL)) > > > #define TASK_SIZE (test_thread_flag(TIF_32BIT) ? \ > > > TASK_SIZE_32 : TASK_SIZE_64) > > > #else > > > -- > > > 2.40.1 > > > > > > > I am not really involved in the issue this is solving, so I have no > > technical opinion on the solution. > > > > IIUC there should always be (TASK_SIZE >= STACK_TOP), so by itself this > > is fixing an issue. > > > > I have reviewed the code and it does exactly as stated into the commit > > message, so FWIW: > > Reviewed-by: Leonardo Bras <leobras@redhat.com> > Thx, > > I found this problem because it can't boot my rv32 buildroot-rootfs in > v6.6. But it's okay in v6.5. So I used git bisect and found commit: > add2cc6b6515 ("RISC-V: mm: Restrict address space for > sv39,sv48,sv57"), which caused that. > > Ping Charlie, I hope it can be fixed in the v6.6 long-term version. I have looked at this more I do agree that this change makes sense. I was thinking that it was valid to have STACK_TOP that was greater than TASK_SIZE but I am no longer convinced that is true. Thank you for looking into this. Reviewed-by: Charlie Jenkins <charlie@rivosinc.com> > > > > > > > -- > Best Regards > Guo Ren
diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/asm/pgtable.h index ab00235b018f..74ffb2178f54 100644 --- a/arch/riscv/include/asm/pgtable.h +++ b/arch/riscv/include/asm/pgtable.h @@ -881,7 +881,7 @@ static inline pte_t pte_swp_clear_exclusive(pte_t pte) #define TASK_SIZE_MIN (PGDIR_SIZE_L3 * PTRS_PER_PGD / 2) #ifdef CONFIG_COMPAT -#define TASK_SIZE_32 (_AC(0x80000000, UL) - PAGE_SIZE) +#define TASK_SIZE_32 (_AC(0x80000000, UL)) #define TASK_SIZE (test_thread_flag(TIF_32BIT) ? \ TASK_SIZE_32 : TASK_SIZE_64) #else