From patchwork Tue Feb 28 13:51:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Ungerer X-Patchwork-Id: 13154926 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 99CF7C64ED6 for ; Tue, 28 Feb 2023 13:52:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E752A6B0078; Tue, 28 Feb 2023 08:52:19 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E24DF6B007B; Tue, 28 Feb 2023 08:52:19 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CEE006B007D; Tue, 28 Feb 2023 08:52:19 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id BB83E6B0078 for ; Tue, 28 Feb 2023 08:52:19 -0500 (EST) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 84C0C80B45 for ; Tue, 28 Feb 2023 13:52:19 +0000 (UTC) X-FDA: 80516839998.17.334DCA3 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf27.hostedemail.com (Postfix) with ESMTP id DE0264001C for ; Tue, 28 Feb 2023 13:52:17 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=l0lI1LdQ; spf=pass (imf27.hostedemail.com: domain of gerg@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=gerg@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1677592338; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=/j8kqAfXxp79yoxUqbWrsIBlC7l7y0O8kL3A+F+e5Ag=; b=gRWrSwMayGVRdeWrHfG4Eb7PJVGk6St7WjlPOvSbPpxstaj4pHCV+qHWtF0LmRyZl032Ow DLh0FeGzjDx6STXLO+EYvTXwBdkV0AOCHTDI8UArpbMU7QOJcx5rjjF98dta3/BhiM7Xkn sT191+GzL0Yb6aOP3DYUrzaU0aefl6E= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=l0lI1LdQ; spf=pass (imf27.hostedemail.com: domain of gerg@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=gerg@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1677592338; a=rsa-sha256; cv=none; b=a8B52C+62uv6NKUErsllO4mBqQI6eBw3gRgNVotpAbUFGsxflutN7Ij7ZB2q3Y2hHnUYdZ rXIXyRlM7htZGJ4mlh05XiboEnStk0Qju434QHXhdXOWEf/lV9rbGI95ocy7mWaw/TGYdC Ylb9+nM5f0e0FBjGF7hZnLurrSlj5W8= 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 DD7886109E; Tue, 28 Feb 2023 13:52:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 19DDFC433EF; Tue, 28 Feb 2023 13:52:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1677592336; bh=NuoO5o1gNzybHzjaUYtQJpYqsA4sxJZdGNvF28deojY=; h=From:To:Cc:Subject:Date:From; b=l0lI1LdQ8gtTTq8qLsQ0PsPf6PqJCDkaxV9zreuOwD3zbiPhsoGRdj88ow6Yljai6 xKkerNJrlCHn6oPTd/Bunuu/dwStOEYKq9naSMwYxvEB092FF6cBVlu2nJWOc081KX RU5OT7SSrZ8UUzqPszx9Y18ZJYZU9xAiFgAahSv0l+tqTCwLlCOC5scTWN9Yb6h09Z PbVblg76VLZRKuPInEcuEj2mUNzMP3leYsWSuJw4r+/fSzmnACm2mMUICu+rKoRBsa Sio1vgDn1tRu7jAVSOsdPn/KfCMHgD3xTO6TMzOpLeFVt1EIAXxEHdlrjx3TJvzol/ 9HjOHwO4ysRLA== From: Greg Ungerer To: linux-riscv@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Greg Ungerer Subject: [PATCH 0/2] riscv: support ELF format binaries in nommu mode Date: Tue, 28 Feb 2023 23:51:24 +1000 Message-Id: <20230228135126.1686427-1-gerg@kernel.org> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Rspamd-Queue-Id: DE0264001C X-Stat-Signature: of4w6jibgex13j7mn3rrnggp8z5aqj6r X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1677592337-338409 X-HE-Meta: U2FsdGVkX181HCPgNvNClGnq6IWQeRjJNSux4prilexfUYFINmbQNZAbhbllympmQMLKpaeYhVIR4Xh2O62zouLOWRu+/S6tIPWqetJ5q0iqzKCMDXQphfh2Oir0lRnf5dRCIC6rLgj0NGQx1pPlDIKpbgmafpuAFzCN4kMrOEwZODbTdxt+8BWW66FAhEMYol3y+ncV5+HsQY7cqm4N1PQyoqxYvXQMoppdTjHxGZpWqVkgp2ADg+FkwycG/fDZmDJ4CGJJWzydUq7t5B0CEXBWS3t8V+Ymb7CkSAjVEhxMHEsY8/VKu4SP4Vf2TE1TgMnhaoUTF28vwLjYfh4yp4qf+kkeUHyi8TFr5n3e08F6/tzJlGs7CZJEwBu3YD4nm0g1YXvLeABbvfKWZxb5Mr714Djth49WxD6IBdynq/X219RrTdg5s+xQWxMuEeVtyH7c7pcTcYWUcMok3wmH/tGv2CoNukKTB/0a6DSGnTB7/fIxYxMecsxuqXZSAmlXCRTL0g4HaTRfp7Ue73yX7TMjsMQTOt9rct7MYib/hF47Z47FWX8v7eUFYIOESREZe7MVGTrxgWeZozgaTx8h9ICb4++7tDqhZR207nLqGeVuLpBEYDjHidZLZ8NkcA/lWcKOB9Fwho6HB7M2zUm9J+5xIvi5wm40lheIbPdEZPYy3V+r8F9FuNNG70aX3VHAGqHv7p4QQoTjNut+hja0KD6jq+M3nO+6X5uORf58kvtlnp9TYTNibPTyrFxdLdd2WMmd2NQG/XB+ikDWD305eRTICSpqcrSBzYOOPMBN3EUYYuybUbqy1bPT9KSkt4OVmBg+5orgPB+e6R3KwvT/zV/7YmjPYGQV7LIbzCLisvKg+Ar479IZm1qJj4M7WMrCLEnb+mLu3tq01unkeTEZF9yOp7qqoGIOB26L8NCsBb8U+hGbRumWEAwV0xsD6NF9xcecsmt5x7RSzT7g2HH o+qrpSLO Pzw2tUwJiXp07aDu8m8AGp5yZuYVdhysp0yrbj5CFTkfdxou4msNxIpbXx6YP1o7mtcvB71xceH/1IJ+ANETKiPtG8vBOMHWUV6/9hwyDRQkFuz7UvFm87AtwHqCpm8/YBu6aqE/TiCL7hzqyT6tLRjCYm8HDgr2JnPDMiAtoPSLS99vF3+wOZPI7ZBYc9xVhr95FvLER/6stD/McZC61jjL2c2p1fNMaUNkN178bW6zgPktO8cg+mP9u8+Fs4mTCCIS1SZewgLV1kF4YWEQcCCjLbgRqgWAQSeg6A8Xh9ziN/TJyGMpiVe+BOngWPb7q+VLNRpm/MD35DHwkAIEkWfOxbmwzVz1ombPYtPYU/6+AwDJzU0X3PU1KfA== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: The following changes add the ability to run ELF format binaries when running RISC-V in nommu mode. That support is actually part of the ELF-FDPIC loader, so these changes are all about making that work on RISC-V. The first issue to deal with is making the ELF-FDPIC loader capable of handling 64-bit ELF files. As coded right now it only supports 32-bit ELF files. Secondly some changes are required to enable and compile the ELF-FDPIC loader on RISC-V and to pass the ELF-FDPIC mapping addresses through to user space when execing the new program. These changes have not been used to run actual ELF-FDPIC binaries. It is used to load and run normal ELF - compiled -pie format. Though the underlying changes are expected to work with full ELF-FDPIC binaries if or when that is supported on RISC-V in gcc. To avoid needing changes to the C-library (tested with uClibc-ng currently) there is a simple runtime dynamic loader (interpreter) available to do the final relocations, https://github.com/gregungerer/uldso. The nice thing about doing it this way is that the same program binary can also be loaded with the usual ELF loader in MMU linux. The motivation here is to provide an easy to use alternative to the flat format binaries normally used for RISC-V nommu based systems. Signed-off-by: Greg Ungerer --- 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 - fs/binfmt_elf_fdpic.c | 38 +++++++++++++++++------------------ include/linux/elf-fdpic.h | 14 +++++++++++- include/uapi/linux/elf-fdpic.h | 15 +++++++++++++ 7 files changed, 67 insertions(+), 22 deletions(-)