Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp36834566rwd; Tue, 11 Jul 2023 06:22:11 -0700 (PDT) X-Google-Smtp-Source: APBJJlHLohLRIEZhoSAFyQelq8OCathqva5bHK9XlBXgh/LfpTdwfeCssn5YO58fyZiJYF29okMy X-Received: by 2002:a05:6a20:9695:b0:10c:4c76:e909 with SMTP id hp21-20020a056a20969500b0010c4c76e909mr11429015pzc.8.1689081730742; Tue, 11 Jul 2023 06:22:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689081730; cv=none; d=google.com; s=arc-20160816; b=FmFh0cT7uUr/hvI/QOkNm93NozBeZkqkYnrikhNnqbak/28RHF408pJ9zntOvmt98b KnyVvmPbl4qNwMp/krs9kv6Y0gixMAPFGwv+jKq8IQt3EyoUF1NT8pJvUZ1I7uCDGta1 PAyb54LGcavFj8A71pUbLbDkSus1X5FCUqvqwPWk4IQF3mLeRsJbjpvVRR2Ysh8N5xbh oY0XzPPQtocbXozeB5Rk0TPSTpuLO3963LsEl5QGJk61+N7yilFo53TKen6w1eHLXe+c xZPQBAAmUJAnva9HIWWEr+aDkdB5ZGWQfmnJSBNdszE+syaY0xS3B1L2AwFxn/KwCnAA w9xw== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=ZOGwRkt935zwHk3NLHZiAz3LcyZ9BPat8+n6QL8Hdek=; fh=NxQDIo4JBLp57/JgJgcSQwgQkWLQsYyb4wjsMoILEcM=; b=TQmpJXwDPTiE+Z6tkOTLRWPPJfj3CeFGczQn0yQ9EfatzsMpXTpEGgEp4D5H2IJJEA 2qJ4OHMLjGqM357IselfTo18EiwwsmN+AeAfpWeuNUYhcPiNcqD/cmryv9FbyVX19q6Q G4qN1AIqcsPSN0boapg4OEhSRQrQtpSkxJ+YtAXa9u9h6F7u7C43WjaMmSl7domNG5DR vZzVZ/P9rEPgEVm05iqIQn63Nnk2OrloFQj4OA8TOgvv+T+7CeloW08N6Oz7ugIJ4srT LIzZHjdNxvgl5jr3nNN6qq2dzg1zFZq8mtHwO1AkFkg97t+x7QkxokBueydHdI6R/rD5 62Jw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=gI8w4Ex9; 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 c5-20020a6566c5000000b0055c0477e26dsi1383940pgw.475.2023.07.11.06.21.57; Tue, 11 Jul 2023 06:22:10 -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=gI8w4Ex9; 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 S232777AbjGKNIb (ORCPT + 99 others); Tue, 11 Jul 2023 09:08:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38212 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232752AbjGKNIb (ORCPT ); Tue, 11 Jul 2023 09:08:31 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3E69A93 for ; Tue, 11 Jul 2023 06:08:30 -0700 (PDT) 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 C61E1614BD for ; 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 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, 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 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(-)