Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp2030847ybh; Tue, 14 Jul 2020 13:46:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx7bW1dBW8iaonSEjdABNqQPKKALRb+O8hqGCnMrVjwhXwVUAeQQY4Y0bqpzwX5PNkK90j4 X-Received: by 2002:a05:6402:1346:: with SMTP id y6mr6515709edw.192.1594759601562; Tue, 14 Jul 2020 13:46:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594759601; cv=none; d=google.com; s=arc-20160816; b=I5g7kXa+MCc2BMkaGJv0PFSpiixgvtFrrRVplAqcV9UJagTJUSf66V6kxr9z014M6z 8/aOqrxxW2lIOFC71JuICYAcDRGCEL2K8Poj4A3Q2o75VfnA0Co0zi+lnnR9G2VSx/XN JDUgwv/wNghPiIThGro5U73bkMu/7hiAZAlY3YJAxi4rIshOmO1h4okmZkwDpVBA5PUg tIj1sq1PPROt080+vK4GGDYTW3QayAnutKAhcWXbTuz5DW42Ir0qpgh8y3osyd1Tkk/A /gr9S6t+B3BTgyQ/OS+aTU1EZ4u7pvCtfoE77y3hRu8kdTS6p2k0s/yg2+Migrg/mJIC j5CQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :reply-to:in-reply-to:references:mime-version:dkim-signature; bh=659l3loeZVWVHQe88TmNq0IOrVNRvE12czGtYHK/OHE=; b=nwSplpxDawCwSdAF0GV9u6l0FJ1km+QJT9hYpTCp7UnrJwRRRUwQ6raT43MaHnt3PO r8lZYLUsMdSu3w2kLDQGtJNdWS2HJtPyJdKrsfemMhDJlGjHxPEBW3tx9X8n8RxuNdci bkK2xplEuXi37T2Ev4D8QXAA/noMYo/OuQp41S0ysr95YlgMrkWaNBBQ0zHNCAtoH32a jT57Pp3qkdAKIiPjhiU/lXf1AwCsMCP6Ids3zvgoR9zCq4CKpS8dR8c/M/LTQw5m5O6v wQoHRHcJA+hLBkFwuNljbjcTVS/BbD0Xi2vrYT/3pS7Xf2WNuDaVAxHT5Eh1NbG7KafC qobA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=unoUiIVB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m16si10875175eji.77.2020.07.14.13.46.17; Tue, 14 Jul 2020 13:46:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=unoUiIVB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726694AbgGNUnY (ORCPT + 99 others); Tue, 14 Jul 2020 16:43:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56708 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725945AbgGNUnX (ORCPT ); Tue, 14 Jul 2020 16:43:23 -0400 Received: from mail-io1-xd43.google.com (mail-io1-xd43.google.com [IPv6:2607:f8b0:4864:20::d43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CE9A8C061755 for ; Tue, 14 Jul 2020 13:43:23 -0700 (PDT) Received: by mail-io1-xd43.google.com with SMTP id d18so18795295ion.0 for ; Tue, 14 Jul 2020 13:43:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:reply-to:from:date:message-id :subject:to:cc; bh=659l3loeZVWVHQe88TmNq0IOrVNRvE12czGtYHK/OHE=; b=unoUiIVBsAzV6xaO9AwGRaVHJ6FFju2MiesoVKPzEXictkod4LyHQKxT/Q3gK03GyR QEZYeB9OvwcCwZq2pksu9VHP0OJ4Vx7AgQIUFMWuHyJUGRXiedi3PL5qWT/VSMvhY21U ahB1VCmdzi6+cCqJl67J6yztKzVBNl3tpYYqyj50GF9OG7UJs9fVGOxuAhCmtzvQxafi ZHgaMZS2nylS4xM/KV5jLclh+Llsa5PQ2pXtETLb9E1eZ0s7ba9ynU5yDT57pHcsPHKf bYr+mwjR2SzSmEH0ch/SJ9AdFPJ3lRVU2iI1+8S3QS7QMbAON4ila3cEuUQasHdo3FTK +ikQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:reply-to :from:date:message-id:subject:to:cc; bh=659l3loeZVWVHQe88TmNq0IOrVNRvE12czGtYHK/OHE=; b=oOSXAFq12g3dishYQVx5qcHrRnBgc01K/xu5hK3Q1HyFloAK4QYaJld6X7McX4H4OY RxSl1Ag0g37HhNGAE8a/0wh7B+omKh58H/svcnr3MZnlKn2BdIhYpZtYSlsIdyOJFiaA Os6msNOdQ3hfs/CGHbPDMiFAEq0oFsbD/yrT5OiwHT2jSSGw2DSvO2uN4eAkLs15hYVs 2AgjgC7gCtSqEDr7VBjcvnyPwh4q/YXOiIzX/yS4NEVI/cAo+l6XIu2jgUL2PYKWw6tj LISExZL642d/ory6kGwI+y8S6JqubgX4z4tggjmBUdugSFRm4Asj+z4aWbsh1WlefqYp SMFg== X-Gm-Message-State: AOAM532cbqkZl18iASEwU5LcxOYHYiF5gUYFmYJLEum972wdmnfyYSaS nmeJdvGwLQzcaBgeVLlFyC4P67WnnIOwPtO+05U= X-Received: by 2002:a05:6638:2591:: with SMTP id s17mr8067905jat.23.1594759403170; Tue, 14 Jul 2020 13:43:23 -0700 (PDT) MIME-Version: 1.0 References: <20200714141550.GA329060@rani.riverdale.lan> <20200714192956.GA689174@rani.riverdale.lan> <20200714202100.GB902932@rani.riverdale.lan> <20200714203537.GD902932@rani.riverdale.lan> In-Reply-To: <20200714203537.GD902932@rani.riverdale.lan> Reply-To: sedat.dilek@gmail.com From: Sedat Dilek Date: Tue, 14 Jul 2020 22:43:11 +0200 Message-ID: Subject: Re: [PATCH v4 0/7] x86/boot: Remove runtime relocations from compressed kernel To: Arvind Sankar Cc: Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , x86@kernel.org, Nick Desaulniers , Fangrui Song , Dmitry Golovin , Clang-Built-Linux ML , Ard Biesheuvel , Masahiro Yamada , Daniel Kiper , Kees Cook , Nathan Chancellor , Arnd Bergmann , "H . J . Lu" , linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jul 14, 2020 at 10:35 PM Arvind Sankar wrote: > > On Tue, Jul 14, 2020 at 10:27:25PM +0200, Sedat Dilek wrote: > > On Tue, Jul 14, 2020 at 10:24 PM Sedat Dilek wrote: > > > > > > On Tue, Jul 14, 2020 at 10:21 PM Arvind Sankar wrote: > > > > > > > > On Tue, Jul 14, 2020 at 10:08:04PM +0200, Sedat Dilek wrote: > > > > > > > > > > > > > > In any case, I think the right fix here would be to add -pie and > > > > > > > --no-dynamic-linker to LDFLAGS_vmlinux instead of KBUILD_LDFLAGS. > > > > > > > > > > > > Hmm, you might be right with moving to LDFLAGS_vmlinux. > > > > > > > > > > > > > > > > We will need the "ifndef CONFIG_LD_IS_LLD" as -r and -pie cannot be > > > > > used together. > > > > > Is that the or not the fact when moving to LDFLAGS_vmlinux? > > > > > > > > LDFLAGS_vmlinux will only be used to link boot/compressed/vmlinux, > > > > whereas KBUILD_LDFLAGS is used for all linker invocations, and in > > > > particular the little link to do the modversions stuff ends up using it. > > > > > > > > So once we move -pie --no-dynamic-linker to the more correct > > > > LDFLAGS_vmlinux and/or stop modversions running, we'll be fine. Being > > > > able to use -pie with lld is one of the goals of this series. > > > > > > > > > > OK, I am doing a new full kernel build with: > > > > > > $ git diff arch/x86/boot/compressed/Makefile > > > diff --git a/arch/x86/boot/compressed/Makefile > > > b/arch/x86/boot/compressed/Makefile > > > index 789d5d14d8b0..056a738e47c6 100644 > > > --- a/arch/x86/boot/compressed/Makefile > > > +++ b/arch/x86/boot/compressed/Makefile > > > @@ -51,7 +51,7 @@ UBSAN_SANITIZE :=n > > > KBUILD_LDFLAGS := -m elf_$(UTS_MACHINE) > > > # Compressed kernel should be built as PIE since it may be loaded at any > > > # address by the bootloader. > > > -KBUILD_LDFLAGS += -pie $(call ld-option, --no-dynamic-linker) > > > +LDFLAGS_vmlinux += -pie $(call ld-option, --no-dynamic-linker) > > > LDFLAGS_vmlinux := -T > > > > > > hostprogs := mkpiggy > > > > > > - Sedat - > > > > Not my day - today. > > > > $ git diff arch/x86/boot/compressed/Makefile > > diff --git a/arch/x86/boot/compressed/Makefile > > b/arch/x86/boot/compressed/Makefile > > index 789d5d14d8b0..9784ed37a5d7 100644 > > --- a/arch/x86/boot/compressed/Makefile > > +++ b/arch/x86/boot/compressed/Makefile > > @@ -51,8 +51,8 @@ UBSAN_SANITIZE :=n > > KBUILD_LDFLAGS := -m elf_$(UTS_MACHINE) > > # Compressed kernel should be built as PIE since it may be loaded at any > > # address by the bootloader. > > -KBUILD_LDFLAGS += -pie $(call ld-option, --no-dynamic-linker) > > LDFLAGS_vmlinux := -T > > +LDFLAGS_vmlinux += -pie $(call ld-option, --no-dynamic-linker) > > > > hostprogs := mkpiggy > > HOST_EXTRACFLAGS += -I$(srctree)/tools/include > > > > - Sedat - > > Nope -- -T needs to be last, since it's (trickily) put together with the > first prerequisite $(obj)/vmlinux.lds. Good I read this. Checked the previous build-log: ld.lld-11 -m elf_x86_64 -T arch/x86/boot/compressed/vmlinux.lds arch/x86/boot/compressed/kernel_info.o arch/x86/boot/compressed/head_64.o arch/x86/boot/compressed/misc.o arch/x86/boot/compressed/string.o arch/x86/boot/compressed/cmdline.o arch/x86/boot/compressed/error.o arch/x86/boot/compressed/piggy.o arch/x86/boot/compressed/cpuflags.o arch/x86/boot/compressed/early_serial_console.o arch/x86/boot/compressed/kaslr.o arch/x86/boot/compressed/kaslr_64.o arch/x86/boot/compressed/mem_encrypt.o arch/x86/boot/compressed/pgtable_64.o arch/x86/boot/compressed/acpi.o drivers/firmware/efi/libstub/lib.a arch/x86/boot/compressed/efi_thunk_64.o -o arch/x86/boot/compressed/vmlinux So there is no -r option in this line. If we move to LDFLAGS_vmlinux we can drop the "call ld-option" as both linker GNU/ld.bfd and LLVM/lld.ld support this? Do we need to adjust the comments? # Compressed kernel should be built as PIE since it may be loaded at any # address by the bootloader That's the minimal change needed: $ git diff arch/x86/boot/compressed/Makefile diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile index 789d5d14d8b0..d0aafcd8cf6c 100644 --- a/arch/x86/boot/compressed/Makefile +++ b/arch/x86/boot/compressed/Makefile @@ -51,8 +51,8 @@ UBSAN_SANITIZE :=n KBUILD_LDFLAGS := -m elf_$(UTS_MACHINE) # Compressed kernel should be built as PIE since it may be loaded at any # address by the bootloader. -KBUILD_LDFLAGS += -pie $(call ld-option, --no-dynamic-linker) -LDFLAGS_vmlinux := -T +LDFLAGS_vmlinux := -pie $(call ld-option, --no-dynamic-linker) +LDFLAGS_vmlinux += -T hostprogs := mkpiggy HOST_EXTRACFLAGS += -I$(srctree)/tools/include - Sedat -