From patchwork Tue Dec 28 14:39:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guo Ren X-Patchwork-Id: 12700415 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 93060C433EF for ; Tue, 28 Dec 2021 14:41:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234471AbhL1OlE (ORCPT ); Tue, 28 Dec 2021 09:41:04 -0500 Received: from dfw.source.kernel.org ([139.178.84.217]:33780 "EHLO dfw.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234433AbhL1OlD (ORCPT ); Tue, 28 Dec 2021 09:41:03 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 5D0676123F; Tue, 28 Dec 2021 14:41:03 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B173FC36AEB; Tue, 28 Dec 2021 14:40:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1640702462; bh=pdrDlH8jqoqjZ8l99cKqnGDf4VeK939Cf4653l9SI3Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ERrwd3rBdCA1978j3In0lNzqO4ywGa9b4wqUrfKcAq5mhSVnQsPYTlTMhfTXOhP4o ruxxIh5OwNXGrpzmCZg3J4cTvvoFu6cnI3TYlWq31S7GuI38Bv4ihDNkOfr/NbZBqC 8rJve9kuVgxT9UINKP0yCtMvtQkuEpUv4Up49ysuVyLr+8FzXobOYUI4atatCI/EJC KPwDe+6zceYKD8ACNrOfUz3umNeDdkPtish3rSh/TsLjUdRYG5sT+POazrejLGyBhg dC1hKrmKqV/ZQTyzbhJaf80AOf08GFTDnsGYreJxzW0YjmsCu5HNeOifB9Aso1Yccs G+iwTANNiR/NQ== From: guoren@kernel.org To: guoren@kernel.org, palmer@dabbelt.com, arnd@arndb.de, anup.patel@wdc.com, gregkh@linuxfoundation.org, liush@allwinnertech.com, wefu@redhat.com, drew@beagleboard.org, wangjunqiang@iscas.ac.cn, hch@infradead.org Cc: linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, linux-csky@vger.kernel.org, linux-s390@vger.kernel.org, sparclinux@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, inux-parisc@vger.kernel.org, linux-mips@vger.kernel.org, linux-arm-kernel@lists.infradead.org, x86@kernel.org, Guo Ren Subject: [PATCH V2 08/17] riscv: compat: Re-implement TASK_SIZE for COMPAT_32BIT Date: Tue, 28 Dec 2021 22:39:49 +0800 Message-Id: <20211228143958.3409187-9-guoren@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211228143958.3409187-1-guoren@kernel.org> References: <20211228143958.3409187-1-guoren@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org From: Guo Ren Make TASK_SIZE from const to dynamic detect TIF_32BIT flag function. Refer to arm64 to implement DEFAULT_MAP_WINDOW_64 for efi-stub. Limit 32-bit compatible process in 0-2GB virtual address range (which is enough for real scenarios), because it could avoid address sign extend problem when 32-bit enter 64-bit and ease software design. The standard 32-bit TASK_SIZE is 0x9dc00000:FIXADDR_START, and compared to a compatible 32-bit, it increases 476MB for the application's virtual address. Signed-off-by: Guo Ren Signed-off-by: Guo Ren Cc: Arnd Bergmann --- arch/riscv/include/asm/pgtable.h | 11 ++++++++++- arch/riscv/include/asm/processor.h | 6 ++++++ drivers/firmware/efi/libstub/efi-stub.c | 2 +- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/asm/pgtable.h index bf204e7c1f74..2dd5b8674380 100644 --- a/arch/riscv/include/asm/pgtable.h +++ b/arch/riscv/include/asm/pgtable.h @@ -663,7 +663,16 @@ static inline pmd_t pmdp_establish(struct vm_area_struct *vma, * Note that PGDIR_SIZE must evenly divide TASK_SIZE. */ #ifdef CONFIG_64BIT -#define TASK_SIZE (PGDIR_SIZE * PTRS_PER_PGD / 2) +#define TASK_SIZE_64 (PGDIR_SIZE * PTRS_PER_PGD / 2) + +#ifdef CONFIG_COMPAT +#define TASK_SIZE_32 (_AC(0x80000000, UL) - PAGE_SIZE) +#define TASK_SIZE (test_thread_flag(TIF_32BIT) ? \ + TASK_SIZE_32 : TASK_SIZE_64) +#else +#define TASK_SIZE TASK_SIZE_64 +#endif + #else #define TASK_SIZE FIXADDR_START #endif diff --git a/arch/riscv/include/asm/processor.h b/arch/riscv/include/asm/processor.h index 0749924d9e55..8649436b8fcf 100644 --- a/arch/riscv/include/asm/processor.h +++ b/arch/riscv/include/asm/processor.h @@ -61,6 +61,12 @@ static inline void arch_thread_struct_whitelist(unsigned long *offset, extern void start_thread(struct pt_regs *regs, unsigned long pc, unsigned long sp); +#ifdef CONFIG_COMPAT +#define DEFAULT_MAP_WINDOW_64 TASK_SIZE_64 +#else +#define DEFAULT_MAP_WINDOW_64 TASK_SIZE +#endif + /* Free all resources held by a thread. */ static inline void release_thread(struct task_struct *dead_task) { diff --git a/drivers/firmware/efi/libstub/efi-stub.c b/drivers/firmware/efi/libstub/efi-stub.c index 26e69788f27a..4075fd19d219 100644 --- a/drivers/firmware/efi/libstub/efi-stub.c +++ b/drivers/firmware/efi/libstub/efi-stub.c @@ -38,7 +38,7 @@ #define EFI_RT_VIRTUAL_BASE SZ_512M #define EFI_RT_VIRTUAL_SIZE SZ_512M -#ifdef CONFIG_ARM64 +#if defined(CONFIG_ARM64) || defined(CONFIG_RISCV) # define EFI_RT_VIRTUAL_LIMIT DEFAULT_MAP_WINDOW_64 #else # define EFI_RT_VIRTUAL_LIMIT TASK_SIZE