Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp3582029pxp; Wed, 23 Mar 2022 01:21:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz7SP8RZXJ7RTRhYrixuExLxnpVr7QeeAQIk22SP95+W8f1x/oNLoyjFcdCIlfYKoN4v5YC X-Received: by 2002:a05:6a00:16cd:b0:4e1:366:7ee8 with SMTP id l13-20020a056a0016cd00b004e103667ee8mr33492871pfc.9.1648023668046; Wed, 23 Mar 2022 01:21:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648023668; cv=none; d=google.com; s=arc-20160816; b=e4e9q6mDGZ1VpfmKhJqmqRtUokz4mlv8jJWo1RKWEeovInzy201Bbgr2m4oKjctQAh 794+Z0gDzeSK+tSgML7PXrwOEDJUKBsE4tS/o0x1B5rFI5RbrUgu7lv2ew8KvX+bDQHa ml7tbaFihWfOtBeGiFCASinnWqVQYYjocn83eomjvpk/Colv7HTyN42jjOn/OwO+OsC3 EIHpcVic4swNjgGz8BZxlyFOl3G9RLwa8d5DOOOYr0j37kGJroxdebDTBnMe84kxgdqP yXJmGzr3u5cubpXyGDIBLWT05YBVIRpNLxCf/w1RWy4yPa6T5aYG7sVCUlivyXJSG69C 16kA== 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=pQEn+d4lTlX9J9QxdcWStlgeXjRpWFVfG0sfTMq2xMQ=; b=nqEuA+rS6nmr/L3I8tYeqDj5rwCEnnUWQJ1fg7yDIja0+kS79Z8USzxZ/PvLCLYf9o DDCVOfuncv5SYfkogB8GvYdCkt2VbUpE+0DKs3wYdHATuAFluiLz9wfwnFRlrDdP/lon E+0YtRfS8XdChe4oXJLcWk+kFc559FB5Hi+Gl26lnOeDLndGQoAaiL3mitCK6aShU0wd 2nQdKeIchywF2i16L5ZhljgZC3RWM7TLetj/zYbHBLzY0zYOTiBXgDI9GEZ1DcFxIhhb js3frWFl0E384KsJZ5CnAFLH6EVU48GfhLVCGyT5zDNEqJE95lWI/QOtaQTwpXSANJwz 5ppg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=CpikaUWu; 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 12-20020a63184c000000b003816043ef60si16610770pgy.341.2022.03.23.01.20.55; Wed, 23 Mar 2022 01:21:08 -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=CpikaUWu; 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 S238076AbiCVOoJ (ORCPT + 99 others); Tue, 22 Mar 2022 10:44:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44338 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238254AbiCVOnP (ORCPT ); Tue, 22 Mar 2022 10:43:15 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6282C6AA52; Tue, 22 Mar 2022 07:41:47 -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 ams.source.kernel.org (Postfix) with ESMTPS id 1369CB81D08; Tue, 22 Mar 2022 14:41:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DC2B2C340EC; Tue, 22 Mar 2022 14:41:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1647960104; bh=0gzQGGxdHWRt9A+64eem+dLQzBOPjB9Pfn9kxqzAZaI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CpikaUWuQt56x1sx9EXwKtcq6scEeta+u7wRO4aGANqT0USCNDCqzgJnWqma8zQjw DaeEWdV/uqRzKCRUqcq+/UScLNmBwObdYenLG0hwjuUu5ttah1dXGhFKt2hWfPNNBo KDe6xISHwnDIwgW8bz8Y3ZPqJ9cM+Xw+ygmkd+1E1Rgnw086H1yWIfs3+0mSCqIjeI o5/mcKdoW0rO8xKkD3IBVBFhNNRkNhWbDBsY6uynB6zKvLeUV/6992AZlzG5dRDHdh 9tABuHiGzLThbMFH45ixkzChZ3afonhVK7Bv/ZBhiixYpGsF0xR8Dq2/N64JpfqXgz p6D/p4pQTjmSA== 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 14/20] riscv: compat: Add elf.h implementation Date: Tue, 22 Mar 2022 22:39:57 +0800 Message-Id: <20220322144003.2357128-15-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-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 Implement necessary type and macro for compat elf. See the code comment for detail. Signed-off-by: Guo Ren Signed-off-by: Guo Ren Reviewed-by: Arnd Bergmann Tested-by: Heiko Stuebner --- arch/riscv/include/asm/elf.h | 41 +++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/arch/riscv/include/asm/elf.h b/arch/riscv/include/asm/elf.h index f53c40026c7a..a234656cfb5d 100644 --- a/arch/riscv/include/asm/elf.h +++ b/arch/riscv/include/asm/elf.h @@ -8,6 +8,8 @@ #ifndef _ASM_RISCV_ELF_H #define _ASM_RISCV_ELF_H +#include +#include #include #include #include @@ -18,11 +20,13 @@ */ #define ELF_ARCH EM_RISCV +#ifndef ELF_CLASS #ifdef CONFIG_64BIT #define ELF_CLASS ELFCLASS64 #else #define ELF_CLASS ELFCLASS32 #endif +#endif #define ELF_DATA ELFDATA2LSB @@ -31,6 +35,8 @@ */ #define elf_check_arch(x) ((x)->e_machine == EM_RISCV) +#define compat_elf_check_arch(x) ((x)->e_machine == EM_RISCV) + #define CORE_DUMP_USE_REGSET #define ELF_EXEC_PAGESIZE (PAGE_SIZE) @@ -43,8 +49,14 @@ #define ELF_ET_DYN_BASE ((TASK_SIZE / 3) * 2) #ifdef CONFIG_64BIT +#ifdef CONFIG_COMPAT +#define STACK_RND_MASK (test_thread_flag(TIF_32BIT) ? \ + 0x7ff >> (PAGE_SHIFT - 12) : \ + 0x3ffff >> (PAGE_SHIFT - 12)) +#else #define STACK_RND_MASK (0x3ffff >> (PAGE_SHIFT - 12)) #endif +#endif /* * This yields a mask that user programs can use to figure out what * instruction set this CPU supports. This could be done in user space, @@ -60,11 +72,19 @@ extern unsigned long elf_hwcap; */ #define ELF_PLATFORM (NULL) +#define COMPAT_ELF_PLATFORM (NULL) + #ifdef CONFIG_MMU #define ARCH_DLINFO \ do { \ + /* \ + * Note that we add ulong after elf_addr_t because \ + * casting current->mm->context.vdso triggers a cast \ + * warning of cast from pointer to integer for \ + * COMPAT ELFCLASS32. \ + */ \ NEW_AUX_ENT(AT_SYSINFO_EHDR, \ - (elf_addr_t)current->mm->context.vdso); \ + (elf_addr_t)(ulong)current->mm->context.vdso); \ NEW_AUX_ENT(AT_L1I_CACHESIZE, \ get_cache_size(1, CACHE_TYPE_INST)); \ NEW_AUX_ENT(AT_L1I_CACHEGEOMETRY, \ @@ -90,4 +110,23 @@ do { \ *(struct user_regs_struct *)regs; \ } while (0); +#ifdef CONFIG_COMPAT + +#define SET_PERSONALITY(ex) \ +do { if ((ex).e_ident[EI_CLASS] == ELFCLASS32) \ + set_thread_flag(TIF_32BIT); \ + else \ + clear_thread_flag(TIF_32BIT); \ + if (personality(current->personality) != PER_LINUX32) \ + set_personality(PER_LINUX | \ + (current->personality & (~PER_MASK))); \ +} while (0) + +#define COMPAT_ELF_ET_DYN_BASE ((TASK_SIZE_32 / 3) * 2) + +/* rv32 registers */ +typedef compat_ulong_t compat_elf_greg_t; +typedef compat_elf_greg_t compat_elf_gregset_t[ELF_NGREG]; + +#endif /* CONFIG_COMPAT */ #endif /* _ASM_RISCV_ELF_H */ -- 2.25.1