Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp947899pxk; Thu, 10 Sep 2020 03:01:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxRE6bydw5s0P7xp6DI6pn2V8lkXH0HdJSuEusSaXISPpDJ8exFqOZJXiBu0Xtyx8xOlmTi X-Received: by 2002:a17:906:33d8:: with SMTP id w24mr7796162eja.224.1599732070904; Thu, 10 Sep 2020 03:01:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599732070; cv=none; d=google.com; s=arc-20160816; b=R2fGMCh8rbw1PZ2G8mpwTAQpC2ngI9iicXAPF+OOnKWgvWsvoFjOd8IqtBL9R4sG7e FVtxiHiWKJ1R2i9IZNbWVNcP63OIuTwyRtCq/R33BzxpyvTsrBRWslIY2hVKfEzOOtIJ X4f6LLMQLrLZAmhDVcVfDr10mRYR7EKF8kBy8F3LbNSwFEnLg9X7l9Pbot04Wsv8/tcj 5xQ+j++t8J8GsD/JFqliCi4t/1k+ko8w66FOx5q3KKSPFdRCT1zUrtsgHKvNlzYiA4my shLJgHHWWacngspAr7uSjv2s9OaZje9E9qvLCbhW9caFuKt+LYdUWA+DJe2tjPtmaENY hUDQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=kBmlII5Vo//A9yPEJvnx3pKLF3xO4ua5qFTJHSq3g7w=; b=XZtXze+54vEoM4Tt/QGdOIVHkzzCwKgG76N2WKdO8UrtJiEn/t9Fwxm+jft/1+Neyq NizidPpDUN1s8E3+j/jn8CDzO3CvHWY5Eai9pXp9Ampl4wl9Og978L92HaTaIC17JKds nn2pFCBsAPZMMPylyAidRs0/R+LWTw9uHREKqkDZdlk5fmv0O7d+n+aXZ9TAuPQX1xIZ sSDmtDnp+0xVMVg7XYId+wCawJpQu8aRgGYNQSnhPmemD6qfbg7ClgrS+gqMctpIcYfQ 8eX5iqkYK8pbevZNjBuE2nlzb7YN2bKmbrkSjMo/6908E+vH1sQ+XceXS4efyEzBgaWV 9HuQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Mp48Y5o3; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l30si3042789ede.434.2020.09.10.03.00.47; Thu, 10 Sep 2020 03:01:10 -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=@google.com header.s=20161025 header.b=Mp48Y5o3; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730640AbgIJJ6I (ORCPT + 99 others); Thu, 10 Sep 2020 05:58:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41330 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730552AbgIJJzB (ORCPT ); Thu, 10 Sep 2020 05:55:01 -0400 Received: from mail-wm1-x344.google.com (mail-wm1-x344.google.com [IPv6:2a00:1450:4864:20::344]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EAC61C061798 for ; Thu, 10 Sep 2020 02:55:00 -0700 (PDT) Received: by mail-wm1-x344.google.com with SMTP id k18so5145054wmj.5 for ; Thu, 10 Sep 2020 02:55:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=kBmlII5Vo//A9yPEJvnx3pKLF3xO4ua5qFTJHSq3g7w=; b=Mp48Y5o3UTjqc7GRbcTi2cjvv51nFGNvyAA5DE1UfeTL1TMGbjAHc4RUbolyjBcq78 jLfYRxESN0S1R7j1vveSLWJeMYK+nJX28JhMyTmyicQtPHsq5swlYfpyW+55u5AoImfZ oBxeH5Lbwxs2v/dztAijetFrho1Wx6bVj+Oc/dkvUXrE5TyUZWh0epgiUpxiOto85MsG hTEOT+NcLacuqmR7JmXxY+IDVmr5voQ/ECTLxZvFSYbuWjRg4MsOVEUUgTnqbsR0HMQb V0et67mMhX/LXsQcKVGVYQwUkRusWYFa/RLbGrMSils0/fDIHW0nT7CA22W1u9F3htI4 NkqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=kBmlII5Vo//A9yPEJvnx3pKLF3xO4ua5qFTJHSq3g7w=; b=klT+HSWJLb6EGpLYR+lx+ZY4wJC+ovGzPEyoJYQkaNq/pNlITXyJ3jl4EivUfked7P R1XZBu4JC/0ZIaPHFfpTRt2uXPbfqLvu2T9E0h0Qk2LYO1c1+9pgq6DYw/yoGBbuLKQN rn404CO/ONfwS8YWB3SyFowDO/tkKTFi9qL4VYq+xl0S0TXJhNRVJqpJBvGzZYEihkWA 8cUVj3XWW2UVss87QHTmNWwCeH9pmrXoC5wWZxy8UrpV43M1oWETs9wFVOJS4q6gDW8+ +U13pcNvbEK/89EiNouy4N8KaSInMWIvdfkkBA0wPo0IKGookz8SlIzXxI75UV/gcCr0 qZIg== X-Gm-Message-State: AOAM5314CCjStuO4jggLN2/gXZ5fWFWVBdxkyX8G0u5XJYCvKjP1PwMs XwfDJYZ4Hac588tc6sS6H9/cPg== X-Received: by 2002:a7b:c14d:: with SMTP id z13mr7474778wmi.19.1599731699416; Thu, 10 Sep 2020 02:54:59 -0700 (PDT) Received: from google.com ([2a00:79e0:d:109:4a0f:cfff:fe4a:6363]) by smtp.gmail.com with ESMTPSA id b76sm2975511wme.45.2020.09.10.02.54.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Sep 2020 02:54:58 -0700 (PDT) Date: Thu, 10 Sep 2020 10:54:54 +0100 From: Andrew Scull To: David Brazdil Cc: Marc Zyngier , Catalin Marinas , Will Deacon , 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: <20200910095454.GB93664@google.com> 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> 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' via kernel-team 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. > > 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. This certaintly feels like a more robust and controlled approach to the sections now that we have an explicit list of those that are allowed. > 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. Very much a nit, but possibly .nvhe.o or .kvm_nvhe.o would make the intended distinction more obvious and line up with the prefix being applied to the symbols. > +$(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) > + > +# 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 > + */ Should this file have the standard copyright line? > + > +/* > + * Defines an ELF hyp section from input section @NAME and its subsections. > + */ > +#define HYP_SECTION(NAME) .hyp##NAME : { *(NAME NAME##.[0-9a-zA-Z_]*) } > + > +SECTIONS { > + HYP_SECTION(.text) > +} > -- > 2.28.0.402.g5ffc5be6b7-goog > > -- > To unsubscribe from this group and stop receiving emails from it, send an email to kernel-team+unsubscribe@android.com. >