X-Received: by 2002:a17:90a:fb84:b0:1bc:4d16:51fb with SMTP id cp4-20020a17090afb8400b001bc4d1651fbmr13860381pjb.22.1645695529545; Thu, 24 Feb 2022 01:38:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645695529; cv=none; d=google.com; s=arc-20160816; b=DDh3PQppZ7rC7A3+2IOi7hcFu4wU50uZrw6rA5TBa0JxNvNsseyFfSGdA6lfRQj3fh wR0oEXL1jf+XXleoXHC2vsWHtIf7H3065n/wvGfNwA7KV1XGnV/2q6snQTrpHlS5P7ZM izWz9DG91AADeTRRilOaLODODQtpfk/zi+CJdCVeFc1ZZ7YcrRs0UlW6Pr9joyM8btb0 jD6mfqhwgQ4HcXDvzF92Yb80Jw16INBRIyRUzpEZeK5/pPCnuye2LD3yUOPsnVfodw8r uYCfKVwYpFtzdEUwIVuXgg6EgKe6FCLeXJ0KpjQuxRg+Npo4cEOcM0fMOdXKoWLqrCnT fgfw== 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=x3bfWukcWtGSGj89vQyUQr93+G5l3Dw1oX5HuBeh9O4=; b=U1bDGPUfUnFFCSqojZ4UbnkoRI+HnJ0kasZ7zBXdBVlYrZLcZ7FcKJBTfmAnv1KXQZ A8EW19G2fBPejxze+JsTHU/8xiuoXqmByMXYGXtlSDuzWIb2m9OFGEcP7H9qkClxP9yD o8PUgatVfJ3W1hNQIx1xY22d+Cu594vUSIj8eGqldAuxwUW+66pN8GDif0IgAXKruAQP twkPOEHc+x3EPO6hQRDGIUfKi3J3jSGDtfbyRxEdWANBSSOUBqWrVAbqLXwwmHeRzFmv obUCvGoXbXrB9EJiwYy30aceIisdCI0Q/fNp/6zGjH+R4PcZQ+RhtJeK7Xi6z7x3fO40 Ot0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="Y3Y/NRqV"; 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 b17-20020a17090a489100b001b8c6dcca5dsi4215653pjh.2.2022.02.24.01.38.34; Thu, 24 Feb 2022 01:38:49 -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="Y3Y/NRqV"; 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 S232077AbiBXI6I (ORCPT + 99 others); Thu, 24 Feb 2022 03:58:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44368 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232478AbiBXI5a (ORCPT ); Thu, 24 Feb 2022 03:57:30 -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 8DB3136328; Thu, 24 Feb 2022 00:56:47 -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 8690261B0F; Thu, 24 Feb 2022 08:56:47 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F0920C340E9; Thu, 24 Feb 2022 08:56:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1645693007; bh=YHBMf6oiN7AKyDQcRFQG6drB0b2sg1GEQLG12pVdvWw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Y3Y/NRqVQxVUTtAB3/fzxTf4Hl9aCJrxHdt0wXwEeIMlkVHaKweQZn8JFLnXvIqxa SX6XbreT2NV6+b1WcqW4Zu5wIM0bBkRlIi10wOkKWjFsfdXOuh6za3cotaPYabiA/G aG2gasqAZs8weiOTr7UF60qeqNe91bptGEzLhpzJZQldkwmD6/bzyGLJvF76WCPDBm 3mDt2h02smrKjcxOVntP+ejdWnThEu8gaNIB3mqkEZts8qizc91DHM1ZF5oGfizWs3 x+VkJzLazXZ869aixl7r/HQDAIDzqINeM2hNIMZMowYzrzsVIs3koMf1ksadaLD+DX EmfJ/sg5kGW3w== 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 Subject: [PATCH V6 15/20] riscv: compat: Add hw capability check for elf Date: Thu, 24 Feb 2022 16:54:05 +0800 Message-Id: <20220224085410.399351-16-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 Detect hardware COMPAT (32bit U-mode) capability in rv64. If not support COMPAT mode in hw, compat_elf_check_arch would return false by compat_binfmt_elf.c Signed-off-by: Guo Ren Signed-off-by: Guo Ren Cc: Arnd Bergmann Cc: Christoph Hellwig --- arch/riscv/include/asm/elf.h | 3 ++- arch/riscv/kernel/process.c | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/arch/riscv/include/asm/elf.h b/arch/riscv/include/asm/elf.h index aee40040917b..3a4293dc7229 100644 --- a/arch/riscv/include/asm/elf.h +++ b/arch/riscv/include/asm/elf.h @@ -40,7 +40,8 @@ * elf64_hdr e_machine's offset are different. The checker is * a little bit simple compare to other architectures. */ -#define compat_elf_check_arch(x) ((x)->e_machine == EM_RISCV) +extern bool compat_elf_check_arch(Elf32_Ehdr *hdr); +#define compat_elf_check_arch compat_elf_check_arch #define CORE_DUMP_USE_REGSET #define ELF_EXEC_PAGESIZE (PAGE_SIZE) diff --git a/arch/riscv/kernel/process.c b/arch/riscv/kernel/process.c index 54787ca9806a..7bbe4dd95e85 100644 --- a/arch/riscv/kernel/process.c +++ b/arch/riscv/kernel/process.c @@ -83,6 +83,32 @@ void show_regs(struct pt_regs *regs) dump_backtrace(regs, NULL, KERN_DEFAULT); } +#ifdef CONFIG_COMPAT +static bool compat_mode_supported __read_mostly; + +bool compat_elf_check_arch(Elf32_Ehdr *hdr) +{ + return compat_mode_supported && hdr->e_machine == EM_RISCV; +} + +static int __init compat_mode_detect(void) +{ + unsigned long tmp = csr_read(CSR_STATUS); + + csr_write(CSR_STATUS, (tmp & ~SR_UXL) | SR_UXL_32); + compat_mode_supported = + (csr_read(CSR_STATUS) & SR_UXL) == SR_UXL_32; + + csr_write(CSR_STATUS, tmp); + + pr_info("riscv: ELF compat mode %s", + compat_mode_supported ? "supported" : "failed"); + + return 0; +} +early_initcall(compat_mode_detect); +#endif + void start_thread(struct pt_regs *regs, unsigned long pc, unsigned long sp) { -- 2.25.1