Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp2158763pxk; Mon, 14 Sep 2020 06:20:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzGAdfXPMTngcpF3GrDqgYltl/Amg+zM2EACN6GKoSeVVlFS8jLvTxr6vRhPmUSPvbZcP0h X-Received: by 2002:a17:906:e103:: with SMTP id gj3mr14442338ejb.153.1600089629287; Mon, 14 Sep 2020 06:20:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600089629; cv=none; d=google.com; s=arc-20160816; b=Pv4y0yjUAyRV5s5wACrAtURozKm2jH5tIS/61jRSal41ErvuJpe05eyIuBtOJ2Ciyi zOoKAaFIU4E80dQrrn44D0V8BZqtUx75ABgTUJnvPlmqYu2gxbvAS6woFQ80PwZde7XE /ZPLPwdm4ajSSBEFXz+lolRWPhzzQ0kZ/lL5/83CizOSCcBtZidxjNIZXpkZvEIdbnDw PUcqFzvge6I42jZqGJw4Q+5R3ra4DcyZO/r6Ral1zFCL1Jblg1vLejEiEVF/1NS4SQHl sSKh4U6yqfJGXTy9LpPCDfv/6cr1sKNmDb6q4vWTEiag17mYrz1PfSvhZ0OOzmj0E4H7 AR8g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=30Zi6cWXPJ6PMFcTCzkcdf76n353HzVQGON0lmNFFZU=; b=payEmQOXJ3FSxphwu2lyse1AoSOdNZULRQB4mzUm5RqUsICpEwFNErnyzxNQp0I4NR uZN8BmIURXZAgp4Ibwo2eo2HQ5PUlfDo784M6OhQcyJiaIEYmTDqoYbFI3Rbulp8PUyx 9PNbXGnLiDLY2K101fRllFc6EtCedO2qGpLqa7WyVY1glii7ADB9OrO/xzTy7KSS/Qlv y5XSuHOsTvmBxJDc96mucAN8uOEPyZjrDs2KPjbrUUTZVJK+rJp7Pdw1Jqbdds/Loqn8 cPfyCTneuFSjWg09DpgHZPaXKXIPGqotr2D9y/bUePYQtc7iIHCzlr9YBOJ41o5atQ8l 8WTg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=HJEzeySp; 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=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a14si3314453edk.57.2020.09.14.06.20.06; Mon, 14 Sep 2020 06:20:29 -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=@kernel.org header.s=default header.b=HJEzeySp; 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=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726747AbgINNTZ (ORCPT + 99 others); Mon, 14 Sep 2020 09:19:25 -0400 Received: from mail.kernel.org ([198.145.29.99]:36748 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726407AbgINNJp (ORCPT ); Mon, 14 Sep 2020 09:09:45 -0400 Received: from willie-the-truck (236.31.169.217.in-addr.arpa [217.169.31.236]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 7AF03206B2; Mon, 14 Sep 2020 13:09:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600088984; bh=enr+iyTv6u2XzskZFJ5qT83Kq/MSJgsJ+u1/0SVC2DE=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=HJEzeySpEP9Li+pydqi15kb1u831aaAa+xIym6H9E2N3vCvslGr2iwd+P8M1q2/KV oSZObq1fkwLf0vFtUgCRsKaEc92nsIxzoi2BG5AQAEfuEj1PR858lINKG6gctQ6lsa BjSmPK+oikK1hmXW8zjoRAQ2wZdbtaPoD7suvK/g= Date: Mon, 14 Sep 2020 14:09:38 +0100 From: Will Deacon To: David Brazdil Cc: Marc Zyngier , Catalin Marinas , Dennis Zhou , Tejun Heo , Christoph Lameter , Arnd Bergmann , James Morse , Julien Thierry , Suzuki K Poulose , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kvmarm@lists.cs.columbia.edu, linux-arch@vger.kernel.org, kernel-team@android.com Subject: Re: [PATCH v2 02/10] kvm: arm64: Partially link nVHE hyp code, simplify HYPCOPY Message-ID: <20200914130937.GC24441@willie-the-truck> References: <20200903091712.46456-1-dbrazdil@google.com> <20200903091712.46456-3-dbrazdil@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200903091712.46456-3-dbrazdil@google.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Sep 03, 2020 at 11:17:04AM +0200, David Brazdil wrote: > Previous series introduced custom build rules for nVHE hyp code, using > objcopy to prefix ELF section and symbol names to separate nVHE code > into its own "namespace". This approach was limited by the expressiveness > of objcopy's command line interface, eg. missing support for wildcards. nit: "Previous series" isn't a lot of use here or in the git log. You can just say something like: "Relying on objcopy to prefix the ELF section names of the nVHE hyp code is brittle and prevents us from using wildcards to match specific section names." and then go on to explain what the change is doing (see Documentation/process/submitting-patches.rst for more help here) Also, given that this is independent of the other patches, please can you move it right to the start of the series? I'm a bit worried about the potential for regressions given the changes to the way in which we link, so the sooner we can get this patch some more exposure, the better. > Improve the build rules by partially linking all '.hyp.o' files and > prefixing their ELF section names using a linker script. Continue using > objcopy for prefixing ELF symbol names. > > One immediate advantage of this approach is that all subsections > matching a pattern can be merged into a single prefixed section, eg. > .text and .text.* can be linked into a single '.hyp.text'. This removes > the need for -fno-reorder-functions on GCC and will be useful in the > future too: LTO builds use .text subsections, compilers routinely > generate .rodata subsections, etc. > > Partially linking all hyp code into a single object file also makes it > easier to analyze. > > Signed-off-by: David Brazdil > --- > arch/arm64/kvm/hyp/nvhe/Makefile | 56 ++++++++++++++++--------------- > arch/arm64/kvm/hyp/nvhe/hyp.lds.S | 14 ++++++++ > 2 files changed, 43 insertions(+), 27 deletions(-) > create mode 100644 arch/arm64/kvm/hyp/nvhe/hyp.lds.S > > diff --git a/arch/arm64/kvm/hyp/nvhe/Makefile b/arch/arm64/kvm/hyp/nvhe/Makefile > index aef76487edc2..1b2fbb19f3e8 100644 > --- a/arch/arm64/kvm/hyp/nvhe/Makefile > +++ b/arch/arm64/kvm/hyp/nvhe/Makefile > @@ -10,40 +10,42 @@ obj-y := timer-sr.o sysreg-sr.o debug-sr.o switch.o tlb.o hyp-init.o > obj-y += ../vgic-v3-sr.o ../aarch32.o ../vgic-v2-cpuif-proxy.o ../entry.o \ > ../fpsimd.o ../hyp-entry.o > > -obj-y := $(patsubst %.o,%.hyp.o,$(obj-y)) > -extra-y := $(patsubst %.hyp.o,%.hyp.tmp.o,$(obj-y)) > +## > +## Build rules for compiling nVHE hyp code > +## Output of this folder is `hyp.o`, a partially linked object file containing > +## all nVHE hyp code and data. > +## > > -$(obj)/%.hyp.tmp.o: $(src)/%.c FORCE > +hyp-obj := $(patsubst %.o,%.hyp.o,$(obj-y)) > +obj-y := hyp.o > +extra-y := $(hyp-obj) hyp.tmp.o hyp.lds > + > +# 1) Compile all source files to `.hyp.o` object files. The file extension > +# avoids file name clashes for files shared with VHE. > +$(obj)/%.hyp.o: $(src)/%.c FORCE > $(call if_changed_rule,cc_o_c) > -$(obj)/%.hyp.tmp.o: $(src)/%.S FORCE > +$(obj)/%.hyp.o: $(src)/%.S FORCE > $(call if_changed_rule,as_o_S) > -$(obj)/%.hyp.o: $(obj)/%.hyp.tmp.o FORCE > - $(call if_changed,hypcopy) > > -# Disable reordering functions by GCC (enabled at -O2). > -# This pass puts functions into '.text.*' sections to aid the linker > -# in optimizing ELF layout. See HYPCOPY comment below for more info. > -ccflags-y += $(call cc-option,-fno-reorder-functions) > +# 2) Compile linker script. > +$(obj)/hyp.lds: $(src)/hyp.lds.S FORCE > + $(call if_changed_dep,cpp_lds_S) Why is it not sufficient just to list the linker script as a target, like we do for vmlinux.lds in extra-y? > +# 3) Partially link all '.hyp.o' files and apply the linker script. > +# Prefixes names of ELF sections with '.hyp', eg. '.hyp.text'. > +LDFLAGS_hyp.tmp.o := -r -T $(obj)/hyp.lds > +$(obj)/hyp.tmp.o: $(addprefix $(obj)/,$(hyp-obj)) $(obj)/hyp.lds FORCE > + $(call if_changed,ld) > + > +# 4) Produce the final 'hyp.o', ready to be linked into 'vmlinux'. > +# Prefixes names of ELF symbols with '__kvm_nvhe_'. > +$(obj)/hyp.o: $(obj)/hyp.tmp.o FORCE > + $(call if_changed,hypcopy) > > # The HYPCOPY command uses `objcopy` to prefix all ELF symbol names > -# and relevant ELF section names to avoid clashes with VHE code/data. > -# > -# Hyp code is assumed to be in the '.text' section of the input object > -# files (with the exception of specialized sections such as > -# '.hyp.idmap.text'). This assumption may be broken by a compiler that > -# divides code into sections like '.text.unlikely' so as to optimize > -# ELF layout. HYPCOPY checks that no such sections exist in the input > -# using `objdump`, otherwise they would be linked together with other > -# kernel code and not memory-mapped correctly at runtime. > +# to avoid clashes with VHE code/data. > quiet_cmd_hypcopy = HYPCOPY $@ > - cmd_hypcopy = \ > - if $(OBJDUMP) -h $< | grep -F '.text.'; then \ > - echo "$@: function reordering not supported in nVHE hyp code" >&2; \ > - /bin/false; \ > - fi; \ > - $(OBJCOPY) --prefix-symbols=__kvm_nvhe_ \ > - --rename-section=.text=.hyp.text \ > - $< $@ > + cmd_hypcopy = $(OBJCOPY) --prefix-symbols=__kvm_nvhe_ $< $@ > > # Remove ftrace and Shadow Call Stack CFLAGS. > # This is equivalent to the 'notrace' and '__noscs' annotations. > diff --git a/arch/arm64/kvm/hyp/nvhe/hyp.lds.S b/arch/arm64/kvm/hyp/nvhe/hyp.lds.S > new file mode 100644 > index 000000000000..aaa0ce133a32 > --- /dev/null > +++ b/arch/arm64/kvm/hyp/nvhe/hyp.lds.S > @@ -0,0 +1,14 @@ > +/* SPDX-License-Identifier: GPL-2.0 */ > +/* > + * Linker script used during partial linking of nVHE EL2 object files. > + * Written by David Brazdil > + */ > + > +/* > + * Defines an ELF hyp section from input section @NAME and its subsections. > + */ > +#define HYP_SECTION(NAME) .hyp##NAME : { *(NAME NAME##.[0-9a-zA-Z_]*) } Is 'NAME##.*' likely to cause a problem here? Will