From patchwork Tue Jul 11 13:07:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Ungerer X-Patchwork-Id: 13308715 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 A512BEB64DD for ; Tue, 11 Jul 2023 13:09:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 45D866B0071; Tue, 11 Jul 2023 09:09:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 40DE96B0075; Tue, 11 Jul 2023 09:09:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2AF3B6B0078; Tue, 11 Jul 2023 09:09:42 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 1CB336B0071 for ; Tue, 11 Jul 2023 09:09:42 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 8A48DAFF6F for ; Tue, 11 Jul 2023 13:09:41 +0000 (UTC) X-FDA: 80999362962.22.AFF0A76 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf08.hostedemail.com (Postfix) with ESMTP id 0C2D9160044 for ; Tue, 11 Jul 2023 13:08:30 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=gI8w4Ex9; spf=pass (imf08.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=1689080911; 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=ZOGwRkt935zwHk3NLHZiAz3LcyZ9BPat8+n6QL8Hdek=; b=J4bWyqJ0xUD+ox4vnZD1fI+fcdnbhFVANKuOYf11EBUd2l4ay/Q8KUewddadehwQ5Vjj9B GZEeASUktvUb5azcO77zCqxgb4QhrwYi9dW9emmDHLB9V1uTyIbxL0KRrNtQFGSHmAOR5o /+6qNg+Ro7LnsGmUv0j642sYGHSv9tY= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1689080911; a=rsa-sha256; cv=none; b=jhK7OVVv7uLRijLqlFwRHX1UBcXUD3nqhUjKwAELQKH0HvCjAFzUGmR/77Xxg4RgdkdJkE 4UqX13DbcMwHCvAU+j2WCxIQH7MAudop4wAxoe5Qy3ijaLQ8ChR9U1tEWNXR1RDbXFeWEg 6eifA7svcmQZ2Ms6miqY9Edcuxa/vmY= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=gI8w4Ex9; spf=pass (imf08.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 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id B969C614AC; Tue, 11 Jul 2023 13:08:29 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EF0ECC433C8; Tue, 11 Jul 2023 13:08:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1689080909; bh=LUcJB0cq3kg6328TLZnO/4L83pKi9KtIC1j5JsNOlE8=; h=From:To:Cc:Subject:Date:From; b=gI8w4Ex9LIcrKsCI1HWYPC+akmsCgpovuc87W7bVuf9+xEyO7s29XnpujGm9IHQ/F iXg0ykha7MCPbDzVdvvbV3nWbggu5BQN/3V4lfJShrQ3bdP/vCEXsEdP60ZkBAz2yA wQO6Eic4WPZgm/ZcZH4rQNehffXS8kEMPfEciRznJpcz2UM/Fxo2moBLNF7gRBAjkK NNQ7dRYhscaMbYNU/KC+//Ef2M0GPHj/xRMBHClMCFMrxLnjN7W4bTWu9bIO8Flg64 AZIqh6xIlgxowZWGKrnkyTNcXGXHyC65zCrrS0X+1PoSoGUDRaQmDXItO0JHdRqCyp +ML9YhD7XnYpw== From: Greg Ungerer To: linux-riscv@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: palmer@dabbelt.com, viro@zeniv.linux.org.uk, ebiederm@xmission.com, keescook@chromium.org, brauner@kernel.org, Greg Ungerer Subject: [PATCH v2 0/2] riscv: support ELF format binaries in nommu mode Date: Tue, 11 Jul 2023 23:07:52 +1000 Message-Id: <20230711130754.481209-1-gerg@kernel.org> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Rspamd-Queue-Id: 0C2D9160044 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: j7xpjn53j1g85fuzoc5d346hom6yf51p X-HE-Tag: 1689080910-815975 X-HE-Meta: U2FsdGVkX19ewJA/j1GARdN2bjZmybu45SajgkBMKvoiVl+s/D5MHhHkrgK2LJnuvDWYB/3lqcFlMBiaERMAfY5coXtrYQa8hntpTO+6qkfOYqh9j0Zkc8AH1uX/9WaSK0D+wyTjIJSnrN4snnLHacplwHhWNR7ESFDZK/X+b9dWzjB2gH1Laowi/A1mtvKXTbKS3o4hyOFdiyFqfetIF6bQeA8HupUEBzKvSZzC0B2Mv1/MLLKt6EvfQEjo4WvlNwmaZBrcJWmZmAHmBbShzIiGAPa+cVQzGeKfn76cutI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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 --- v1->v2: rebase onto 6.5-rc1 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(-)