Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1033264pxk; Fri, 18 Sep 2020 01:55:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxUPKZDB/hh+3eS0qmzjPt8MBUecVGm1w9y5BY8vxKJLlU7k+IMj6Ekw63EIfT4xhFGfPrO X-Received: by 2002:a17:907:2506:: with SMTP id y6mr33170638ejl.265.1600419300048; Fri, 18 Sep 2020 01:55:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600419300; cv=none; d=google.com; s=arc-20160816; b=RMHKr6o8DlU/v+emn1FNVOoZzPuK27+6bmIsVzOz+HiOEL5bmdq//DI5ZAHVKpz+mB itfnTMHC/2kjYYqC4SrIIVXzK/Z17eYAJsEOQ7UHbKH96ieH0oyNQSuSPhsZgFXiMFZw NdkN1x5UhKb/45a4Yp9o5zgeEwc3OCQ/f0pDKx1goTIqWNxXPAAhkch97pHNVoViPgK2 +UCjQypJbO+abpYIRikc7RgtAHmgR8mFGw5l7P3gwKio3gkAIzkfppG2FNv7Ti3etwfa Fo2pPUCSZ6jQNmm71FgdC8cjvRTvtW9yD5agx0g52XOWqC1C1sSYkkr6+RjQRhmzZTnX O81g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=iYHaF/oW3V9u3sPoV3yTdY4CmH6PFlhQHX/jcI2ho9s=; b=Y9IB32EkcJvIvMNz4Mv3+2Sy/ni0NF3cF0+lxHuDvTg2nGiRETQMvLWzh/jLz2zXer WxDg+czeOdVdF8EIpIo0Qz39gCK3uxqlcO9dZ5el08ogk8BYXaYzu7gbm8p0GmgcrFh9 LfrMEH7e1tMQAl9t4EjpUCF2rx8ttkYilOumxlgFxcwlqC8PtxBrTIT+cDgYt1JxFXn+ jAgCltfI19myHxKu/XkccMBRlFmKWOa59/5R3iZg1T0aNKc7FRt8GnGJA2GxT7SeDP6x XbYiPFYE1fgxq2LTu1n5NbxBO+Hm/DdEZjNgoQ8M6JsVJ4jOeT1sfoU/Rwvo113rhyKf Ij+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="RNh/kppb"; 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 n13si1737861edq.92.2020.09.18.01.54.37; Fri, 18 Sep 2020 01:55:00 -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="RNh/kppb"; 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 S1726612AbgIRIvY (ORCPT + 99 others); Fri, 18 Sep 2020 04:51:24 -0400 Received: from mail.kernel.org ([198.145.29.99]:60544 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726009AbgIRIvY (ORCPT ); Fri, 18 Sep 2020 04:51:24 -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 97F6D208B8; Fri, 18 Sep 2020 08:51:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600419083; bh=xSuljIaVzLXu/fP2mE0aGU32cBoHqrhtfIi4pwf6ku0=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=RNh/kppbBRNafdG5SxQjmgKu6lqLfCQO68yvGZ2XZ0suKr94KuMwIOD6RSsQFvnKI U+4FYyhlZN9nx3UowWA8v4x4ZWdHVqoC6dPHOwb405yYU93zomqj0i4XFen2uxOpKC fkimNUzViQv7Z0sKBHoDStVpoTLvWQ417k2DNin0= Date: Fri, 18 Sep 2020 09:51:17 +0100 From: Will Deacon To: David Brazdil Cc: kvmarm@lists.cs.columbia.edu, Catalin Marinas , Marc Zyngier , James Morse , Julien Thierry , Suzuki K Poulose , Dennis Zhou , Tejun Heo , Christoph Lameter , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kernel-team@android.com Subject: Re: [PATCH v3 01/11] kvm: arm64: Partially link nVHE hyp code, simplify HYPCOPY Message-ID: <20200918085116.GA30834@willie-the-truck> References: <20200916173439.32265-1-dbrazdil@google.com> <20200916173439.32265-2-dbrazdil@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200916173439.32265-2-dbrazdil@google.com> User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Sep 16, 2020 at 06:34:29PM +0100, David Brazdil wrote: > 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. > > Improve the build rules by partially linking all '.nvhe.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/include/asm/hyp_image.h | 24 ++++++++++++ > arch/arm64/kvm/hyp/nvhe/Makefile | 60 ++++++++++++++++-------------- > arch/arm64/kvm/hyp/nvhe/hyp.lds.S | 13 +++++++ > 3 files changed, 70 insertions(+), 27 deletions(-) > create mode 100644 arch/arm64/include/asm/hyp_image.h > create mode 100644 arch/arm64/kvm/hyp/nvhe/hyp.lds.S > > diff --git a/arch/arm64/include/asm/hyp_image.h b/arch/arm64/include/asm/hyp_image.h > new file mode 100644 > index 000000000000..5b1e3b9ef376 > --- /dev/null > +++ b/arch/arm64/include/asm/hyp_image.h > @@ -0,0 +1,24 @@ > +/* SPDX-License-Identifier: GPL-2.0 */ > +/* > + * Copyright (C) 2020 Google LLC. > + * Written by David Brazdil > + */ > + > +#ifndef __ARM64_HYP_IMAGE_H__ > +#define __ARM64_HYP_IMAGE_H__ > + > +#ifdef LINKER_SCRIPT > + > +/* > + * KVM nVHE ELF section names are prefixed with .hyp, to separate them > + * from the kernel proper. > + */ > +#define HYP_SECTION_NAME(NAME) .hyp##NAME > + > +/* Defines an ELF hyp section from input section @NAME and its subsections. */ > +#define HYP_SECTION(NAME) \ > + HYP_SECTION_NAME(NAME) : { *(NAME NAME##.[0-9a-zA-Z_]*) } I still don't get why we can't just use NAME ## .* for the regex here. That matches what we do elsewhere for linker script wildcarding, e.g. .rodata.*, .init.text.* ... in asm-generic/vmlinux.lds.h. Why is it different for these sections? > + > +#endif /* LINKER_SCRIPT */ > + > +#endif /* __ARM64_HYP_IMAGE_H__ */ > diff --git a/arch/arm64/kvm/hyp/nvhe/Makefile b/arch/arm64/kvm/hyp/nvhe/Makefile > index aef76487edc2..2b27b60182f9 100644 > --- a/arch/arm64/kvm/hyp/nvhe/Makefile > +++ b/arch/arm64/kvm/hyp/nvhe/Makefile > @@ -10,40 +10,46 @@ 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 `kvm_nvhe.o`, a partially linked object > +## file containing all nVHE hyp code and data. > +## > > -$(obj)/%.hyp.tmp.o: $(src)/%.c FORCE > +hyp-obj := $(patsubst %.o,%.nvhe.o,$(obj-y)) > +obj-y := kvm_nvhe.o > +extra-y := $(hyp-obj) kvm_nvhe.tmp.o hyp.lds > + > +# 1) Compile all source files to `.nvhe.o` object files. The file extension > +# avoids file name clashes for files shared with VHE. > +$(obj)/%.nvhe.o: $(src)/%.c FORCE > $(call if_changed_rule,cc_o_c) > -$(obj)/%.hyp.tmp.o: $(src)/%.S FORCE > +$(obj)/%.nvhe.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) You need a .gitignore file listing hyp.lds, otherwise some idiot will end up committing it. I definitely didn't do that when playing around with this series. Nope. Not at all. With that, and the regex resolved: Acked-by: Will Deacon Will