From patchwork Wed Mar 16 07:03:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guo Ren X-Patchwork-Id: 12782391 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5E02DC433EF for ; Wed, 16 Mar 2022 07:12:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=GQgcw4U8lumLP/7uiUh9tiqyZHLCrg6L2kCA/ZhU32U=; b=TQchTJQVWkDxlb P40r8kAVp1UA9+BGzlzhoSpVn0k89ni0I7QYrNJ/etXrTU2wgGAbMPDlRiSlzEcF3JqHjLD4JBuw4 Wg9xnvb8YozBHF8mxoPHgxy/kqoFaJR8wFttc3R1Qnhcf/sL4VOkMsgm2IXHM15dJtWuAqy6jaME5 aVqrSUubWMzj22j5Mv09t2d6D5e9mAYWGPUmuctl0lI7q89eVVMVfeUvVJHVJD9lxnMjjgtrbNlxZ AB6jvveSHraoPIe3dz92prD72ooEIIM6QJhqCZ30mp0/dEPxHghmKzPuSkaTmNG5f+3eCKGnH8Vdx Wspx3pBsGXvImOr3zlBw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nUNph-00BqBD-0s; Wed, 16 Mar 2022 07:12:33 +0000 Received: from sin.source.kernel.org ([2604:1380:40e1:4800::1]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nUNiB-00BlhF-Mu; Wed, 16 Mar 2022 07:04:49 +0000 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 sin.source.kernel.org (Postfix) with ESMTPS id D7768CE1D38; Wed, 16 Mar 2022 07:04:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 69B09C340EE; Wed, 16 Mar 2022 07:04:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1647414284; bh=kPBdsSZwAFo7vna7h4jVnZjxy4XlzYkfwZ49VTpvuBU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=M8JH4Hd81WgzJSOA+aSnC97fJRkcULfV+8Y4phqGf4ZB3aCbnH/wNS2XwFw3utQHe Krk7/jFrHLN69m1BKNPEppXgDXs/TH0baTLV0o9wQUKN8qZTldx92rLwoDeAN7VY3F 2JltJuwd6hcv6Eu3JMHzPVvp6OUy86dW4cKRuNi59v66ETBq2TSYPezvAd+Mh0eeGC e4JpKLRQtzRY94DdDdVK4HCx+b2cLsD6QZCGKqEDtwDwjJ16Oyux7V02X91In/gjJW m17b2EjySSuROOTzv1xDHVBehA4SD3/SQdG/eoAeamPrbTDNDHF+jihKAFn/cq4R+F YyiRCh8DitdPw== From: guoren@kernel.org To: guoren@kernel.org, palmer@dabbelt.com, arnd@arndb.de, anup@brainfault.org, 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 , Palmer Dabbelt Subject: [PATCH V8 12/20] riscv: compat: syscall: Add entry.S implementation Date: Wed, 16 Mar 2022 15:03:09 +0800 Message-Id: <20220316070317.1864279-13-guoren@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220316070317.1864279-1-guoren@kernel.org> References: <20220316070317.1864279-1-guoren@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220316_000447_981231_3196BB71 X-CRM114-Status: GOOD ( 11.05 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.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 Tested-by: Heiko Stuebner 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..7f05c65654c8 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_64BIT +#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 d6a46ed0bf05..d4a1ad4edbc6 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: