Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp38501801rwd; Wed, 12 Jul 2023 08:29:27 -0700 (PDT) X-Google-Smtp-Source: APBJJlFCJSnIaC4j5KFolvb7Mn+XW0uvXey4sBxF1AfXUoYoc86f3AHbxVJi4xm+eXCMox33iYv0 X-Received: by 2002:a17:907:d23:b0:991:f383:d5c3 with SMTP id gn35-20020a1709070d2300b00991f383d5c3mr25363910ejc.74.1689175767144; Wed, 12 Jul 2023 08:29:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689175767; cv=none; d=google.com; s=arc-20160816; b=E5doTyRtp93pJVY9qJm/YRndubdr4Wd4fVTUNFGbQBE0BX9MhJfqDyxQabLZ6gViZ/ im2tnmlYhG69mRu290SUdtsQx70+8k+HvaC4KJNd+R17s0NX5d6qTsj23n1rMv7cttgf QW4RJazpPph2cbLHqsNDjy1STmAxDuqfW4CVPjqaB6Tyau3WdDEwY8SUvAI48iTG0a/F T1WhKt3CcLz1f9wwfp/4RCQyseQRMV4B2hhkfQ1p/qA16sYZa5oDz2pjLc2kYLJAbiHJ SFsikcty/Y7hxcDzpSdR4PX4NPMIOQpODqttIO6luMVwfc0ybL1YjS1VZFJpq+YH4p51 /oRA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:subject:cc:to:from:date:references:in-reply-to :message-id:mime-version:user-agent:feedback-id:dkim-signature :dkim-signature; bh=dSgpbN2qqN6BLnaVZrXrgZ301dLlfYvJq2QGVf6hj70=; fh=79y4+KlzxnujBmjtTChY6M1plj5s3hqh5Gn3xPwpdL8=; b=JnAR3UmSjV5mNu8XpNrL7T7b7jDtwT8lnFKUJvAfJH36yhaSa2zj51U+jzjqFMq43S Z6ythneSmAtWlg5HnzO2oarSCPeYD0patGYqTuU45zxlaWBTysQZ04KSygB/Pf9ES8gI ulb3tV4CN6gbLmhgqzTCYxjXU2kGjlDDDP98F2T4WVe9cy3HTKidkYNK+PkkwpV47/3C iJZRBSZ7Pz159CG9IQ5g30cNgcQvrpGi6Vd3aFEgpcghi8j2dz6eDrfEw8fnLk9w5vPL Dd9eRD5Wbi88MM54pxK/JPqjmlLtIUboNOp4JDPPi7FwISLD0yYYg3Eq1AMnjMHieW95 tpJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fastmail.com header.s=fm2 header.b=VRcANVnE; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=bVjH8KDB; 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=fastmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v14-20020a1709060b4e00b00992d0de8769si4803467ejg.907.2023.07.12.08.29.01; Wed, 12 Jul 2023 08:29:27 -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=@fastmail.com header.s=fm2 header.b=VRcANVnE; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=bVjH8KDB; 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=fastmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233476AbjGLPNS (ORCPT + 99 others); Wed, 12 Jul 2023 11:13:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34074 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233389AbjGLPNR (ORCPT ); Wed, 12 Jul 2023 11:13:17 -0400 Received: from out5-smtp.messagingengine.com (out5-smtp.messagingengine.com [66.111.4.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5F9431BCC for ; Wed, 12 Jul 2023 08:13:16 -0700 (PDT) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 0147A5C00E8; Wed, 12 Jul 2023 11:13:14 -0400 (EDT) Received: from imap50 ([10.202.2.100]) by compute1.internal (MEProxy); Wed, 12 Jul 2023 11:13:14 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fastmail.com; h= cc:cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:sender :subject:subject:to:to; s=fm2; t=1689174793; x=1689261193; bh=dS gpbN2qqN6BLnaVZrXrgZ301dLlfYvJq2QGVf6hj70=; b=VRcANVnEB2elnO8va5 7qDzlklh+Nx+prfh8PRfHEKkTXshU67ofceeigTZ9rT5UDSk8eEOJEa5v5vGynWY SKxEIc2xWdNcG5Fp7nxQiBenVluT7+pbKVS/PtmVaCYe2THBu+Y3i5LsoC/SsQus 5HDA5bbAM9575RbxSE8TMt7kkjvMXkacW4pPbkC7anwh/1oYeHvbqJYPYHQcD5ZX YfPHfhBsFeOLQO453EUuy/sX6DDHEuYHgE0mMc5qEUHEY4HopZjtdriX+JpjH32P AqQ0wzchbFzP7XzVi9Cjr8qs90QOfpWciNwobxhXsCPlzDOz7WY+a2K/NMerUaAG ygrw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm2; t=1689174793; x=1689261193; bh=dSgpbN2qqN6BL naVZrXrgZ301dLlfYvJq2QGVf6hj70=; b=bVjH8KDBs5z5dsZkuFwFImLh8Slui QqmG02Oy49twz7BISKEgnY/ZjFeZ+llsc1+VE2JrZ1L2jhxCL9WrSWeW1xa3/jex VrTNsK8otzYHHsCVMwWsxl0tx8NAiJHOerGZMcXSWS4V/wfvURG18KbYEgLVHKap JQ5NmZbnDRjHyJZ7cIwBK21dC7VzH2JPwMZn+0Scp4C53kYawRAtY7kg9GGUHUET 5PEUOurEHtKWOpZmN2cGfUu2rSnFMOGl2C6DecMTnXyu2Tnkkua2tYem8McGi7zS hwkVyyREt8oWnHwPwJHtQ3ieIOF0X6R77vGVOMB9q5aNaNwhZUZztYimg== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedviedrfedvgdekiecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefofgggkfgjfhffhffvvefutgesthdtredtreertdenucfhrhhomhepfdfuthgv fhgrnhcuqfdktfgvrghrfdcuoehsohhrvggrrhesfhgrshhtmhgrihhlrdgtohhmqeenuc ggtffrrghtthgvrhhnpeejueehgedtueetgefhheejjeeigffhieefjeehuddvueegtdfh heevgfeggfektdenucffohhmrghinhepihhnfhhrrgguvggrugdrohhrghenucevlhhush htvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehsohhrvggrrhesfhgr shhtmhgrihhlrdgtohhm X-ME-Proxy: Feedback-ID: i84414492:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id 0BDAD1700096; Wed, 12 Jul 2023 11:13:12 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.9.0-alpha0-531-gfdfa13a06d-fm-20230703.001-gfdfa13a0 Mime-Version: 1.0 Message-Id: <31c4024b-3553-4117-a22a-b39259c8fea4@app.fastmail.com> In-Reply-To: <20230711130754.481209-3-gerg@kernel.org> References: <20230711130754.481209-1-gerg@kernel.org> <20230711130754.481209-3-gerg@kernel.org> Date: Wed, 12 Jul 2023 11:12:45 -0400 From: "Stefan O'Rear" To: "Greg Ungerer" , linux-riscv@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: "Palmer Dabbelt" , viro@zeniv.linux.org.uk, ebiederm@xmission.com, keescook@chromium.org, brauner@kernel.org Subject: Re: [PATCH v2 2/2] riscv: support the elf-fdpic binfmt loader Content-Type: text/plain X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL, SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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 On Tue, Jul 11, 2023, at 9:07 AM, Greg Ungerer wrote: > Add support for enabling and using the binfmt_elf_fdpic program loader > on RISC-V platforms. The most important change is to setup registers > during program load to pass the mapping addresses to the new process. > > One of the interesting features of the elf-fdpic loader is that it > also allows appropriately compiled ELF format binaries to be loaded on > nommu systems. Appropriate being those compiled with -pie. > > Signed-off-by: Greg Ungerer > --- > v1->v2: rebase onto linux-6.5-rc1 > increment PTRACE_GETFDPIC value to keep it unique > > arch/riscv/include/asm/elf.h | 11 ++++++++++- > arch/riscv/include/asm/mmu.h | 4 ++++ > arch/riscv/include/uapi/asm/ptrace.h | 5 +++++ > fs/Kconfig.binfmt | 2 +- > 4 files changed, 20 insertions(+), 2 deletions(-) > > diff --git a/arch/riscv/include/asm/elf.h b/arch/riscv/include/asm/elf.h > index c24280774caf..c33fe923ef6d 100644 > --- a/arch/riscv/include/asm/elf.h > +++ b/arch/riscv/include/asm/elf.h > @@ -41,6 +41,7 @@ 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_FDPIC_CORE_EFLAGS 0 > #define ELF_EXEC_PAGESIZE (PAGE_SIZE) > > /* > @@ -69,6 +70,13 @@ extern bool compat_elf_check_arch(Elf32_Ehdr *hdr); > #define ELF_HWCAP riscv_get_elf_hwcap() > extern unsigned long elf_hwcap; > > +#define ELF_FDPIC_PLAT_INIT(_r, _exec_map_addr, _interp_map_addr, > dynamic_addr) \ > + do { \ > + (_r)->a1 = _exec_map_addr; \ > + (_r)->a2 = _interp_map_addr; \ > + (_r)->a3 = dynamic_addr; \ > + } while (0) > + This should probably be left empty for now; it will be defined by the ELF FDPIC ABI when that is done, and shouldn't be used by normal ELF binaries. I'd ask if there's a reason it starts at a1 instead of a0, but it seems idiosyncratic on all arches that have full FDPIC support. -s > /* > * This yields a string that ld.so will use to load implementation > * specific libraries for optimization. This is more specific in > @@ -78,7 +86,6 @@ extern unsigned long elf_hwcap; > > #define COMPAT_ELF_PLATFORM (NULL) > > -#ifdef CONFIG_MMU > #define ARCH_DLINFO \ > do { \ > /* \ > @@ -115,6 +122,8 @@ do { \ > else \ > NEW_AUX_ENT(AT_IGNORE, 0); \ > } while (0) > + > +#ifdef CONFIG_MMU > #define ARCH_HAS_SETUP_ADDITIONAL_PAGES > struct linux_binprm; > extern int arch_setup_additional_pages(struct linux_binprm *bprm, > diff --git a/arch/riscv/include/asm/mmu.h b/arch/riscv/include/asm/mmu.h > index 0099dc116168..355504b37f8e 100644 > --- a/arch/riscv/include/asm/mmu.h > +++ b/arch/riscv/include/asm/mmu.h > @@ -20,6 +20,10 @@ typedef struct { > /* A local icache flush is needed before user execution can resume. */ > cpumask_t icache_stale_mask; > #endif > +#ifdef CONFIG_BINFMT_ELF_FDPIC > + unsigned long exec_fdpic_loadmap; > + unsigned long interp_fdpic_loadmap; > +#endif > } mm_context_t; > > void __init create_pgd_mapping(pgd_t *pgdp, uintptr_t va, phys_addr_t > pa, > diff --git a/arch/riscv/include/uapi/asm/ptrace.h > b/arch/riscv/include/uapi/asm/ptrace.h > index e17c550986a6..30f6d6537adc 100644 > --- a/arch/riscv/include/uapi/asm/ptrace.h > +++ b/arch/riscv/include/uapi/asm/ptrace.h > @@ -10,6 +10,11 @@ > > #include > > +#define PTRACE_GETFDPIC 33 > + > +#define PTRACE_GETFDPIC_EXEC 0 > +#define PTRACE_GETFDPIC_INTERP 1 > + > /* > * User-mode register state for core dumps, ptrace, sigcontext > * > diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt > index 93539aac0e5b..f5693164ca9a 100644 > --- a/fs/Kconfig.binfmt > +++ b/fs/Kconfig.binfmt > @@ -58,7 +58,7 @@ config ARCH_USE_GNU_PROPERTY > config BINFMT_ELF_FDPIC > bool "Kernel support for FDPIC ELF binaries" > default y if !BINFMT_ELF > - depends on ARM || ((M68K || SUPERH || XTENSA) && !MMU) > + depends on ARM || ((M68K || RISCV || SUPERH || XTENSA) && !MMU) > select ELFCORE > help > ELF FDPIC binaries are based on ELF, but allow the individual load > -- > 2.25.1 > > > _______________________________________________ > linux-riscv mailing list > linux-riscv@lists.infradead.org > http://lists.infradead.org/mailman/listinfo/linux-riscv