Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp1376162pxm; Thu, 24 Feb 2022 01:44:42 -0800 (PST) X-Google-Smtp-Source: ABdhPJzfZm4F0Q+lbEwCb1Q/Xf5RNCdLuB+5naKBcdKb5Qhe0Yvrifo2W69kRYMSqpdO6WhcJGGm X-Received: by 2002:a17:907:2be6:b0:6ce:70da:12c2 with SMTP id gv38-20020a1709072be600b006ce70da12c2mr1600096ejc.649.1645695882643; Thu, 24 Feb 2022 01:44:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645695882; cv=none; d=google.com; s=arc-20160816; b=lgIDCluQnBsw/FYxW75WA5d9yGPxcqVcRlYQNMf+ifbqeo7G3yvJofNgkgZKvNqTQs bTJu3o7oj5DvZsVdnHH0wdkd5RSvGveT9ugydrGXjnIMfc2sUKpFBRerTYIyT5gujdGA aMLcbzzs+BxOyX99drvKgyqGeakIT1Dko3a8UR6jAu0FZNdCtQ8t4ToBbjwTDnsaONLf 09Wfel2Wo+0ofDFg/YD2w7pzZ6yTW2U1pyO5BAYaJikP7K6eE+OVvulNbXHv4Q/KMr6a ZNvf0O3KJ93z4JxJQMFP1QYgQKx/gQ4K21nORgcnMHDxaf0Vn63KaXh2Uh3AaT5B9KIS a9xw== 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=YkTSen6umozKzKK4qCwWbe0nVxsldkNeD3eq/FkJSTk=; b=Loqto2vvxTgXM2XIF2u0eklyQP2+R6a0tW90ZBAhMMsfRfQIdoCUZfaUM5gPw/PtqW jdHgygVF9rpnC2bic+OcWxgA/g/2kSEPUynU6xt1ZJ/n08ZMw+5uULpHRABTzG8TSGDs NJikRhXDqduCONdQkRaohB0xP4bwh0hdAQIEqgrqli7iqB8AHb5OVhcZOGZdq3WkEo0n 4koPrVzPW11aMMTsi/PwvTCMh3WCmVgW0lcLrTRvXk0r879bLFf+Ps8/mG3GlfSbRm8e lGtH+vAh9KB6CVMnauITu0uqnbQkppZs5t3v+Bmdsk9w+EoXrmOPOD3BxRxStpCh4wLn T/YA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=t8FT9MZV; 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 ed7si1085864edb.624.2022.02.24.01.44.19; Thu, 24 Feb 2022 01:44:42 -0800 (PST) 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=t8FT9MZV; 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 S232292AbiBXI5n (ORCPT + 99 others); Thu, 24 Feb 2022 03:57:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43864 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232434AbiBXI45 (ORCPT ); Thu, 24 Feb 2022 03:56:57 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8FD5726A3B9; Thu, 24 Feb 2022 00:56:24 -0800 (PST) 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 2EBDB61ADD; Thu, 24 Feb 2022 08:56:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DC589C340F0; Thu, 24 Feb 2022 08:56:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1645692983; bh=/ObW5rSeT34E/++iCg5HmXqlNd1ZKyvZrmWfUZvVcVY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=t8FT9MZVp9YrfWa2ZH1G7QiElejAuWDOG7GCCTU0k/3nuk4btL3yPe380cT3SvNhM IyqvNRd12m0qCOTp9E8/WtjueQM0d3tXnPfPtzREMNofJitB8bZWscPR5+sGEx7/Ee jNf74Rd0B5F/+UXFT9diyd/soZxMDXPN3sboE1Nhioh4MEMu5MgwWlckgzeBE1qdFq 0OJASKXcaD41RSFIvbyKSeZ3qX6LgRiehjegzn3jLsOP9ULxxiQf1PA6yksmXQ6RW8 v5OKtBKdH3ED19mklgdRqu9y1xeqagKdVe4AlWzFZiPeWwoTJyAsXyrZomN6ZACn4O ET3TqkaL71ePA== From: guoren@kernel.org To: guoren@kernel.org, palmer@dabbelt.com, arnd@arndb.de, anup@brainfault.org, gregkh@linuxfoundation.org, liush@allwinnertech.com, wefu@redhat.com, drew@beagleboard.org, wangjunqiang@iscas.ac.cn, 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, Guo Ren , Palmer Dabbelt Subject: [PATCH V6 12/20] riscv: compat: syscall: Add entry.S implementation Date: Thu, 24 Feb 2022 16:54:02 +0800 Message-Id: <20220224085410.399351-13-guoren@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220224085410.399351-1-guoren@kernel.org> References: <20220224085410.399351-1-guoren@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 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 Implement the entry of compat_sys_call_table[] in asm. Ref to riscv-privileged spec 4.1.1 Supervisor Status Register (sstatus): BIT[32:33] = UXL[1:0]: - 1:32 - 2:64 - 3:128 Signed-off-by: Guo Ren Signed-off-by: Guo Ren Reviewed-by: Palmer Dabbelt Cc: Arnd Bergmann --- arch/riscv/include/asm/csr.h | 7 +++++++ arch/riscv/kernel/entry.S | 18 ++++++++++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/arch/riscv/include/asm/csr.h b/arch/riscv/include/asm/csr.h index ae711692eec9..eed96fa62d66 100644 --- a/arch/riscv/include/asm/csr.h +++ b/arch/riscv/include/asm/csr.h @@ -36,6 +36,13 @@ #define SR_SD _AC(0x8000000000000000, UL) /* FS/XS dirty */ #endif +#ifdef CONFIG_COMPAT +#define SR_UXL _AC(0x300000000, UL) /* XLEN mask for U-mode */ +#define SR_UXL_32 _AC(0x100000000, UL) /* XLEN = 32 for U-mode */ +#define SR_UXL_64 _AC(0x200000000, UL) /* XLEN = 64 for U-mode */ +#define SR_UXL_SHIFT 32 +#endif + /* SATP flags */ #ifndef CONFIG_64BIT #define SATP_PPN _AC(0x003FFFFF, UL) diff --git a/arch/riscv/kernel/entry.S b/arch/riscv/kernel/entry.S index ed29e9c8f660..1951743f09b3 100644 --- a/arch/riscv/kernel/entry.S +++ b/arch/riscv/kernel/entry.S @@ -207,13 +207,27 @@ check_syscall_nr: * Syscall number held in a7. * If syscall number is above allowed value, redirect to ni_syscall. */ - bgeu a7, t0, 1f + bgeu a7, t0, 3f +#ifdef CONFIG_COMPAT + REG_L s0, PT_STATUS(sp) + srli s0, s0, SR_UXL_SHIFT + andi s0, s0, (SR_UXL >> SR_UXL_SHIFT) + li t0, (SR_UXL_32 >> SR_UXL_SHIFT) + sub t0, s0, t0 + bnez t0, 1f + + /* Call compat_syscall */ + la s0, compat_sys_call_table + j 2f +1: +#endif /* Call syscall */ la s0, sys_call_table +2: slli t0, a7, RISCV_LGPTR add s0, s0, t0 REG_L s0, 0(s0) -1: +3: jalr s0 ret_from_syscall: -- 2.25.1