Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp3376636pxp; Tue, 22 Mar 2022 18:59:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxtVfJn3+sxM+eUAC9kzZmGNsK7666B+eKqSYSFnUvqzhPIGWVUQI8up2FlNExPP91X3Ca1 X-Received: by 2002:a17:906:b052:b0:6ce:88a5:e42a with SMTP id bj18-20020a170906b05200b006ce88a5e42amr29797328ejb.237.1648000792982; Tue, 22 Mar 2022 18:59:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648000792; cv=none; d=google.com; s=arc-20160816; b=tThTyiaLTBDgSmBG612ZDz16sSkhpnl3zKvAdTjUrT1s4NBJUDEizmhhUB8g4URTwP Vz5WXeSDAid4pkVKz5npm7wAUSgyKsrqFK8hKvUerZmHnHackIEl7KDa+e815pXz/0hS sekqYYWi9E7UxGFRfSK1rEBy6qVJogN0aGZ6lA4/bmgujrpKVjXRblNaunHrrNF4zj+j XT5Skaj8NlG1xbuc0ONPtmQZFlTImLT0gYWPzfkIa0rPg99CyZ4CvSRrY5UE4EsJY5Du aaIyiXI0jWqoqkDXkyxn5TH0IZ1aSjODTMBIle8PESVCfqQ1Ja7hIt9vnmYLj1eDiJha VVoQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=N+xwEEw1O1OiU35RVBQmjEM82IuOvS5Twr4ELiaS78g=; b=gt7RZ/yv73qExYwHJrnkIrKuD0Cx8Wv0GgcJRwApxx8r+SVFuPP/ZCBZztBVLJKYAz jvcka8/c+YKocKKzMbRVG8IYQo7t2V5alLWkco+zBICrQ39uCMJqdmO1UkJ5mJ68rcJS 0A/QhMzcPEWAsMr9sr0L4hE6aBk+MIwBPA+9usS/Psqr1exhQAfrU2R1PNxdZgF8d2Wl UVAYlj9fj3FPc0QRGInxdOM6JETF6cBiW61ydab9vjM83ZyeWlOp3pAA//cbf/Y2ZmY1 rK3jtS9e+d2BPy/tSBuzI+tRxO7Q3Na7JoK42qrT8EAXIidOUBecFpxJst1pTLdQMAfm 0LJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=DnbADolR; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x15-20020a50f18f000000b00418c2b5be2csi15575995edl.270.2022.03.22.18.59.25; Tue, 22 Mar 2022 18:59:52 -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=@kernel.org header.s=k20201202 header.b=DnbADolR; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238327AbiCVOns (ORCPT + 99 others); Tue, 22 Mar 2022 10:43:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42774 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238145AbiCVOmu (ORCPT ); Tue, 22 Mar 2022 10:42:50 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 906EC80201; Tue, 22 Mar 2022 07:41:21 -0700 (PDT) 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 02A30616D1; Tue, 22 Mar 2022 14:41:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 66078C36AE3; Tue, 22 Mar 2022 14:41:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1647960080; bh=mPzTkgatSK8CCYcJZRjjnRIhaMHdvygHIPXND8TxesM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DnbADolRrfUtWkDl90gcqnLxy3xAD1rPGlH5QqgjzrFLT6SarLUzagtLpLrZpx+OS NVSk+uhBI8tXdq5jFQ/+5fDbTN5D9TGkTtMMpQjwt+R99v9lo53qkeJZMiwU5dWUtJ BD6VC3X0hBiDRO953HUEm4C12nXaKPMTHwFywwEcvuYMGrLAgc8PoLz7m++dLGLUUK itmRmru+mc4U6y33xFzsOER7PYY6LN+ux6oGq5BIbGrzXVRzCCjyK9uMxPi8oi5ulb 1h24Jr0HAU+J5fVtew8nOAidnSVq0qbQIpKW4E+0NMHRF1p9Qm8pehD6ASFCD5zAQO jsPl5XcwLP4zg== From: guoren@kernel.org To: guoren@kernel.org, palmer@dabbelt.com, arnd@arndb.de, gregkh@linuxfoundation.org, hch@lst.de Cc: linux-arch@vger.kernel.org, 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, linux-parisc@vger.kernel.org, linux-mips@vger.kernel.org, linux-arm-kernel@lists.infradead.org, x86@kernel.org, heiko@sntech.de, Guo Ren Subject: [PATCH V9 10/20] riscv: compat: Re-implement TASK_SIZE for COMPAT_32BIT Date: Tue, 22 Mar 2022 22:39:53 +0800 Message-Id: <20220322144003.2357128-11-guoren@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220322144003.2357128-1-guoren@kernel.org> References: <20220322144003.2357128-1-guoren@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.9 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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 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 Reviewed-by: Arnd Bergmann Tested-by: Heiko Stuebner --- arch/riscv/include/asm/pgtable.h | 13 +++++++++++-- arch/riscv/include/asm/processor.h | 6 +++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/asm/pgtable.h index e3549e50de95..afdc9ece2ba4 100644 --- a/arch/riscv/include/asm/pgtable.h +++ b/arch/riscv/include/asm/pgtable.h @@ -705,8 +705,17 @@ static inline pmd_t pmdp_establish(struct vm_area_struct *vma, * 63–48 all equal to bit 47, or else a page-fault exception will occur." */ #ifdef CONFIG_64BIT -#define TASK_SIZE (PGDIR_SIZE * PTRS_PER_PGD / 2) -#define TASK_SIZE_MIN (PGDIR_SIZE_L3 * PTRS_PER_PGD / 2) +#define TASK_SIZE_64 (PGDIR_SIZE * PTRS_PER_PGD / 2) +#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 (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 #define TASK_SIZE_MIN TASK_SIZE diff --git a/arch/riscv/include/asm/processor.h b/arch/riscv/include/asm/processor.h index 0749924d9e55..21c8072dce17 100644 --- a/arch/riscv/include/asm/processor.h +++ b/arch/riscv/include/asm/processor.h @@ -19,7 +19,11 @@ #define TASK_UNMAPPED_BASE PAGE_ALIGN(TASK_SIZE / 3) #define STACK_TOP TASK_SIZE -#define STACK_TOP_MAX STACK_TOP +#ifdef CONFIG_64BIT +#define STACK_TOP_MAX TASK_SIZE_64 +#else +#define STACK_TOP_MAX TASK_SIZE +#endif #define STACK_ALIGN 16 #ifndef __ASSEMBLY__ -- 2.25.1