Message ID | 20230329045329.64565-1-alexghiti@rivosinc.com |
---|---|
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp165202vqo; Tue, 28 Mar 2023 21:59:44 -0700 (PDT) X-Google-Smtp-Source: AKy350ate04VLYb26em6n2kSRy93u/RXuJsN4wmH0eJlylFHXvPlb/VVR1Ite3N7bQW9PE8qoacy X-Received: by 2002:a17:906:7090:b0:885:a62c:5a5c with SMTP id b16-20020a170906709000b00885a62c5a5cmr17626639ejk.46.1680065984470; Tue, 28 Mar 2023 21:59:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680065984; cv=none; d=google.com; s=arc-20160816; b=EMklbXDfQq+oiEa8+V4QBS/ySkLc//va2CMAeC08QZt6ce6R435Ywp685eUSAa5QeF fVErofxDB3fXAJu2FM8+HgP5R02PH8dGPOf7JtXuF9br+2IxoqqNQ0tmeFOrFnx8SbM9 yRaHIeWTwfLD4rnpz6V2ofNu9xM8p/9AoU4gLYdP8qxvFu1jY28T2gJK0XAmOpo4Vnca OXCGN2ALNLcdUYwPUltNL3DdsYElGtKqJwz+r2U1Egd+y6+HJL0IhzP65iC6gPlwsaJL vfe6GkFsCnzH+c1eeN/CdgoS/8zTPxGEoU11+0fIqCay8ff+skW6VVUAug9ugF8YVv77 dB4g== 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=Mo0pBz6wf3kyiWYQ9fjYRy+Wu64GhON7Bmz6ajIouOI=; b=quBvKhVTbwu53tr26o0qY6FsxXf7ZYq1OibzHuDiOX3BwBA7waBx8uHKebJQ96ETFe FLzcL32GQu0tfBDspfQUt8KUwpil9nfO9quemioYGsA8nRQCsMAwYtLKmWjhchdofZGF pGFlTJ9GWcsgoW8+eeKiXIp7chvexbR6lWRpY1MC+ZGnVnpiH1KrdMGbiIg01zqriovN IzCEKtX6o/S6+/a5wCEkERkYqcALL87nP6rKf3QXcav4aPz1lk/kd7IRzMNL5GpcOMpn d9MPT3GAQZu+EIOi9JDE3OJ8pbpcmTVwarK0AuVx3vGVD//akkygwxTt5yvVp2QI0+jE tPaQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rivosinc-com.20210112.gappssmtp.com header.s=20210112 header.b=dT3vR+5B; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ju17-20020a17090798b100b0092feaa573ffsi31776769ejc.632.2023.03.28.21.59.21; Tue, 28 Mar 2023 21:59:44 -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=@rivosinc-com.20210112.gappssmtp.com header.s=20210112 header.b=dT3vR+5B; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229735AbjC2Exi (ORCPT <rfc822;rua109.linux@gmail.com> + 99 others); Wed, 29 Mar 2023 00:53:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37326 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229549AbjC2Exg (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 29 Mar 2023 00:53:36 -0400 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 881E02D46 for <linux-kernel@vger.kernel.org>; Tue, 28 Mar 2023 21:53:34 -0700 (PDT) Received: by mail-wm1-x32f.google.com with SMTP id j18-20020a05600c1c1200b003ee5157346cso10646114wms.1 for <linux-kernel@vger.kernel.org>; Tue, 28 Mar 2023 21:53:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20210112.gappssmtp.com; s=20210112; t=1680065613; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=Mo0pBz6wf3kyiWYQ9fjYRy+Wu64GhON7Bmz6ajIouOI=; b=dT3vR+5BCE0d2cD8qefotDYbxWqPr15i/uHQCi1YF886RpaVStPW6F27dSe9spSiBr nSo/S/VtEpndi0j2dD/H1lMx8HaUY3qjH1EQ0q68rn++tg5lbeV9YItR3H0UmqtidEr4 GKRKJRhc5o+iNCRWeEZHO5kblPX5hYBdEfCMio2bAlbhW/sSelRb5v3N5WHsZkyfM5Gj becrsvXvlUJx1Mi33oacQC/hIR35TWFoCcR6S6AhtBxCZ8C9wt3Pf9FlTe+EOUXVxDTu KpQUXUSJ49y/XaC9UKkb06EVDpFkbGgNuj1x5g1oHnS0J3RO9jlYM2uhXRKwop3WEa/o XeAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680065613; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Mo0pBz6wf3kyiWYQ9fjYRy+Wu64GhON7Bmz6ajIouOI=; b=HBFjJMAdcLvprPpHpOcZg/3vwwYaX2tqyTsbAYP9eWh/8Zae1zRHNURGx4bjIQPnVu ny8whNy029LGjPsYcGfWG99A7vc94RyrNzG16gpxMk1ox+c3arp5fxkEug8GxaffrfuU epDzP0fy1misjzzYljbBXFbdy/UGAJidAtAtS51xrnJqgQHVeqAZqJnOlTVBgHAp7Z8A P6XEK2FeuNfdGRUPMObLO6FU5zLSbNN/WXgufiytz7466iEKMHGzAXb5PUNHoj5ogK8K IIbJiFpKQMestJ8T9FJKWe6UqDY6Fpg8gh7y96TzdlJZhdhHVy1pjUDBQzKmUImmZq4M 8MYQ== X-Gm-Message-State: AO0yUKXI/UksTV8TFYrkGSTsNDCV7tp96KOvlZ5ieN/uvGfxQUI3hh5N Gq9E+UaC3OyCWpUkp63iRaXhZQ== X-Received: by 2002:a7b:c850:0:b0:3ed:29db:cb80 with SMTP id c16-20020a7bc850000000b003ed29dbcb80mr13580773wml.18.1680065613023; Tue, 28 Mar 2023 21:53:33 -0700 (PDT) Received: from alex-rivos.home (amontpellier-656-1-456-62.w92-145.abo.wanadoo.fr. [92.145.124.62]) by smtp.gmail.com with ESMTPSA id o6-20020a1c7506000000b003ee63fe5203sm757591wmc.36.2023.03.28.21.53.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Mar 2023 21:53:32 -0700 (PDT) From: Alexandre Ghiti <alexghiti@rivosinc.com> To: Nick Desaulniers <ndesaulniers@google.com>, =?utf-8?b?QmrDtnJuIFTDtnBl?= =?utf-8?b?bA==?= <bjorn@kernel.org>, Michael Ellerman <mpe@ellerman.id.au>, Nicholas Piggin <npiggin@gmail.com>, Christophe Leroy <christophe.leroy@csgroup.eu>, Paul Walmsley <paul.walmsley@sifive.com>, Palmer Dabbelt <palmer@dabbelt.com>, Albert Ou <aou@eecs.berkeley.edu>, linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, linux-kbuild@vger.kernel.org Cc: Alexandre Ghiti <alexghiti@rivosinc.com> Subject: [PATCH v9 0/6] Introduce 64b relocatable kernel Date: Wed, 29 Mar 2023 06:53:23 +0200 Message-Id: <20230329045329.64565-1-alexghiti@rivosinc.com> X-Mailer: git-send-email 2.37.2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=0.0 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1761676869270003311?= X-GMAIL-MSGID: =?utf-8?q?1761676869270003311?= |
Series |
Introduce 64b relocatable kernel
|
|
Message
Alexandre Ghiti
March 29, 2023, 4:53 a.m. UTC
After multiple attempts, this patchset is now based on the fact that the 64b kernel mapping was moved outside the linear mapping. The first patch allows to build relocatable kernels but is not selected by default. That patch is a requirement for KASLR. The second and third patches take advantage of an already existing powerpc script that checks relocations at compile-time, and uses it for riscv. This patchset is rebased on top of: riscv: Use PUD/P4D/PGD pages for the linear mapping (https://patchwork.kernel.org/project/linux-riscv/list/?series=733603) base-commit-tag: v6.3-rc1 Changes in v9: * Fix gcc/llvm compilation errors by adding patch 1, thanks to Bjorn * Move a patch to move rela.dyn outside of init (patch 2): it is a separate patch to clearly explain why * To effectively move rela.dyn to init, we need to add patch 6: separate patch since we may be able at some point to revert (along with patch 2). * Add a lot of orphan sections to the linker script Changes in v8: * Fix UEFI boot by moving rela.dyn section into the data so that PE/COFF loader actually copies the relocations too * Fix check that used PGDIR instead of PUD which was not correct for sv48 and sv57 * Fix PE/COFF header data size definition as it led to size of 0 Changes in v7: * Rebase on top of v5.15 * Fix LDFLAGS_vmlinux which was overriden when CONFIG_DYNAMIC_FTRACE was set * Make relocate_kernel static * Add Ack from Michael Changes in v6: * Remove the kernel move to vmalloc zone * Rebased on top of for-next * Remove relocatable property from 32b kernel as the kernel is mapped in the linear mapping and would then need to be copied physically too * CONFIG_RELOCATABLE depends on !XIP_KERNEL * Remove Reviewed-by from first patch as it changed a bit Changes in v5: * Add "static __init" to create_kernel_page_table function as reported by Kbuild test robot * Add reviewed-by from Zong * Rebase onto v5.7 Changes in v4: * Fix BPF region that overlapped with kernel's as suggested by Zong * Fix end of module region that could be larger than 2GB as suggested by Zong * Fix the size of the vm area reserved for the kernel as we could lose PMD_SIZE if the size was already aligned on PMD_SIZE * Split compile time relocations check patch into 2 patches as suggested by Anup * Applied Reviewed-by from Zong and Anup Changes in v3: * Move kernel mapping to vmalloc Changes in v2: * Make RELOCATABLE depend on MMU as suggested by Anup * Rename kernel_load_addr into kernel_virt_addr as suggested by Anup * Use __pa_symbol instead of __pa, as suggested by Zong * Rebased on top of v5.6-rc3 * Tested with sv48 patchset * Add Reviewed/Tested-by from Zong and Anup Alexandre Ghiti (6): riscv: Prepare EFI header for relocatable kernels riscv: Move .rela.dyn outside of init to avoid empty relocations riscv: Introduce CONFIG_RELOCATABLE powerpc: Move script to check relocations at compile time in scripts/ riscv: Check relocations at compile time riscv: Use --emit-relocs in order to move .rela.dyn in init arch/powerpc/tools/relocs_check.sh | 18 ++-------- arch/riscv/Kconfig | 14 ++++++++ arch/riscv/Makefile | 7 ++-- arch/riscv/Makefile.postlink | 49 ++++++++++++++++++++++++++ arch/riscv/boot/Makefile | 7 ++++ arch/riscv/include/asm/set_memory.h | 3 ++ arch/riscv/kernel/efi-header.S | 19 ++++++++-- arch/riscv/kernel/vmlinux.lds.S | 26 ++++++++++---- arch/riscv/mm/Makefile | 4 +++ arch/riscv/mm/init.c | 54 ++++++++++++++++++++++++++++- arch/riscv/tools/relocs_check.sh | 26 ++++++++++++++ scripts/relocs_check.sh | 20 +++++++++++ 12 files changed, 218 insertions(+), 29 deletions(-) create mode 100644 arch/riscv/Makefile.postlink create mode 100755 arch/riscv/tools/relocs_check.sh create mode 100755 scripts/relocs_check.sh
Comments
On Wed, 29 Mar 2023 06:53:23 +0200, Alexandre Ghiti wrote: > After multiple attempts, this patchset is now based on the fact that the > 64b kernel mapping was moved outside the linear mapping. > > The first patch allows to build relocatable kernels but is not selected > by default. That patch is a requirement for KASLR. > The second and third patches take advantage of an already existing powerpc > script that checks relocations at compile-time, and uses it for riscv. > > [...] Applied, thanks! [1/6] riscv: Prepare EFI header for relocatable kernels https://git.kernel.org/palmer/c/55de1e4ad43b [2/6] riscv: Move .rela.dyn outside of init to avoid empty relocations https://git.kernel.org/palmer/c/69a90d2fe107 [3/6] riscv: Introduce CONFIG_RELOCATABLE https://git.kernel.org/palmer/c/39b33072941f [4/6] powerpc: Move script to check relocations at compile time in scripts/ https://git.kernel.org/palmer/c/47981b5cc687 [5/6] riscv: Check relocations at compile time https://git.kernel.org/palmer/c/c2dea0bc5339 [6/6] riscv: Use --emit-relocs in order to move .rela.dyn in init https://git.kernel.org/palmer/c/559d1e45a16d Best regards,
Hello: This series was applied to riscv/linux.git (for-next) by Palmer Dabbelt <palmer@rivosinc.com>: On Wed, 29 Mar 2023 06:53:23 +0200 you wrote: > After multiple attempts, this patchset is now based on the fact that the > 64b kernel mapping was moved outside the linear mapping. > > The first patch allows to build relocatable kernels but is not selected > by default. That patch is a requirement for KASLR. > The second and third patches take advantage of an already existing powerpc > script that checks relocations at compile-time, and uses it for riscv. > > [...] Here is the summary with links: - [v9,1/6] riscv: Prepare EFI header for relocatable kernels https://git.kernel.org/riscv/c/55de1e4ad43b - [v9,2/6] riscv: Move .rela.dyn outside of init to avoid empty relocations https://git.kernel.org/riscv/c/69a90d2fe107 - [v9,3/6] riscv: Introduce CONFIG_RELOCATABLE https://git.kernel.org/riscv/c/39b33072941f - [v9,4/6] powerpc: Move script to check relocations at compile time in scripts/ https://git.kernel.org/riscv/c/47981b5cc687 - [v9,5/6] riscv: Check relocations at compile time https://git.kernel.org/riscv/c/c2dea0bc5339 - [v9,6/6] riscv: Use --emit-relocs in order to move .rela.dyn in init https://git.kernel.org/riscv/c/559d1e45a16d You are awesome, thank you!
On Tue, 28 Mar 2023 21:53:23 PDT (-0700), alexghiti@rivosinc.com wrote: > After multiple attempts, this patchset is now based on the fact that the > 64b kernel mapping was moved outside the linear mapping. > > The first patch allows to build relocatable kernels but is not selected > by default. That patch is a requirement for KASLR. > The second and third patches take advantage of an already existing powerpc > script that checks relocations at compile-time, and uses it for riscv. > > This patchset is rebased on top of: > > riscv: Use PUD/P4D/PGD pages for the linear mapping > (https://patchwork.kernel.org/project/linux-riscv/list/?series=733603) > base-commit-tag: v6.3-rc1 The QEMU CI has some way to say "this depends on an un-merged patch set sent as $MESSAGE_ID", not sure if that's a b4-ism but it's a bit less confusing. I merged this on top of the pre-merge hugepage linear mapping changes, it's on for-next. > Changes in v9: > * Fix gcc/llvm compilation errors by adding patch 1, thanks to Bjorn > * Move a patch to move rela.dyn outside of init (patch 2): it is a > separate patch to clearly explain why > * To effectively move rela.dyn to init, we need to add patch 6: separate patch since we may be > able at some point to revert (along with patch 2). > * Add a lot of orphan sections to the linker script > > Changes in v8: > * Fix UEFI boot by moving rela.dyn section into the data so that PE/COFF > loader actually copies the relocations too > * Fix check that used PGDIR instead of PUD which was not correct > for sv48 and sv57 > * Fix PE/COFF header data size definition as it led to size of 0 > > Changes in v7: > * Rebase on top of v5.15 > * Fix LDFLAGS_vmlinux which was overriden when CONFIG_DYNAMIC_FTRACE was > set > * Make relocate_kernel static > * Add Ack from Michael > > Changes in v6: > * Remove the kernel move to vmalloc zone > * Rebased on top of for-next > * Remove relocatable property from 32b kernel as the kernel is mapped in > the linear mapping and would then need to be copied physically too > * CONFIG_RELOCATABLE depends on !XIP_KERNEL > * Remove Reviewed-by from first patch as it changed a bit > > Changes in v5: > * Add "static __init" to create_kernel_page_table function as reported by > Kbuild test robot > * Add reviewed-by from Zong > * Rebase onto v5.7 > > Changes in v4: > * Fix BPF region that overlapped with kernel's as suggested by Zong > * Fix end of module region that could be larger than 2GB as suggested by Zong > * Fix the size of the vm area reserved for the kernel as we could lose > PMD_SIZE if the size was already aligned on PMD_SIZE > * Split compile time relocations check patch into 2 patches as suggested by Anup > * Applied Reviewed-by from Zong and Anup > > Changes in v3: > * Move kernel mapping to vmalloc > > Changes in v2: > * Make RELOCATABLE depend on MMU as suggested by Anup > * Rename kernel_load_addr into kernel_virt_addr as suggested by Anup > * Use __pa_symbol instead of __pa, as suggested by Zong > * Rebased on top of v5.6-rc3 > * Tested with sv48 patchset > * Add Reviewed/Tested-by from Zong and Anup > > Alexandre Ghiti (6): > riscv: Prepare EFI header for relocatable kernels > riscv: Move .rela.dyn outside of init to avoid empty relocations > riscv: Introduce CONFIG_RELOCATABLE > powerpc: Move script to check relocations at compile time in scripts/ > riscv: Check relocations at compile time > riscv: Use --emit-relocs in order to move .rela.dyn in init > > arch/powerpc/tools/relocs_check.sh | 18 ++-------- > arch/riscv/Kconfig | 14 ++++++++ > arch/riscv/Makefile | 7 ++-- > arch/riscv/Makefile.postlink | 49 ++++++++++++++++++++++++++ > arch/riscv/boot/Makefile | 7 ++++ > arch/riscv/include/asm/set_memory.h | 3 ++ > arch/riscv/kernel/efi-header.S | 19 ++++++++-- > arch/riscv/kernel/vmlinux.lds.S | 26 ++++++++++---- > arch/riscv/mm/Makefile | 4 +++ > arch/riscv/mm/init.c | 54 ++++++++++++++++++++++++++++- > arch/riscv/tools/relocs_check.sh | 26 ++++++++++++++ > scripts/relocs_check.sh | 20 +++++++++++ > 12 files changed, 218 insertions(+), 29 deletions(-) > create mode 100644 arch/riscv/Makefile.postlink > create mode 100755 arch/riscv/tools/relocs_check.sh > create mode 100755 scripts/relocs_check.sh
April 21, 2023 2:59 PM, "Palmer Dabbelt" <palmer@dabbelt.com> wrote: >> riscv: Use PUD/P4D/PGD pages for the linear mapping >> (https://patchwork.kernel.org/project/linux-riscv/list/?series=733603) >> base-commit-tag: v6.3-rc1 > > The QEMU CI has some way to say "this depends on an un-merged patch set sent as $MESSAGE_ID", not > sure if that's a b4-ism but it's a bit less confusing. I think it's patchwork-ism, actually. B4 will eventually learn to be able to include dependent series info and automatically retrieve/apply them in the proper order on "shazam", but it can't do that yet. -K
On Fri, Apr 21, 2023 at 07:10:14PM +0000, Konstantin Ryabitsev wrote: > April 21, 2023 2:59 PM, "Palmer Dabbelt" <palmer@dabbelt.com> wrote: > >> riscv: Use PUD/P4D/PGD pages for the linear mapping > >> (https://patchwork.kernel.org/project/linux-riscv/list/?series=733603) > >> base-commit-tag: v6.3-rc1 > > > > The QEMU CI has some way to say "this depends on an un-merged patch set sent as $MESSAGE_ID", not > > sure if that's a b4-ism but it's a bit less confusing. > > I think it's patchwork-ism, actually. B4 will eventually learn to be > able to include dependent series info and automatically retrieve/apply > them in the proper order on "shazam", but it can't do that yet. A patchwork-ism or a patchew-ism? Drew Jones was my source for this, but he had said the thing to do in QEMU-land was put a: Based-on: $message-id in your cover letter for each thing that you depend on. I'm not entirely sure if that meant each series or each patch. I think patchew picks that up and dumps in it on a patchew github account that the CI might pick up on. From the QEMU docs: <quote> It is also okay to base patches on top of other on-going work that is not yet part of the git master branch. To aid continuous integration tools, such as `patchew <http://patchew.org/QEMU/>`__, you should `add a tag <https://lists.gnu.org/archive/html/qemu-devel/2017-08/msg01288.html>`__ line ``Based-on: $MESSAGE_ID`` to your cover letter to make the series dependency obvious. <\quote> FWIW, my vote is for something with a message-id, rather than those patchwork series links that you can't dump into b4!