From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.5 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_PASS,URIBL_BLOCKED,USER_AGENT_MUTT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AACBCC10F0E for ; Mon, 15 Apr 2019 17:06:36 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 7D7C22075B for ; Mon, 15 Apr 2019 17:06:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="miaBZCZW" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7D7C22075B Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=4mMSZ+VJ03zF0mJu1xicDjHDvA8kZIJz2cklRsz5yOE=; b=miaBZCZWEpV0Cy ApBXXiRUhaxgNUnQXTYxwqqV6VhA0Jqwdizz36e/7ZaToxgXXlPMxIjA80f6nitxuNnCNJs9RgGi4 /dmc5xO5PMfftCjfxOgqbAcdpkfi3gUImIuiSfl+jkXLRQ+RMhgXIyaOazDCb7vyIoWcbZJsZK7nT mUNpddiFQV4s+zEKCIvfsoIa/T3kLgamWN1GmVCz3A7TfpFCCQqSTjThcKMN775vnloCk1Yqe6R2p UuDfs6MpDY0GPXzdFn2bQPYgvRHjIBnTr+135GYJBnjXIdsYgQ1zVKW2MpHDn6+1y2Kxp/vXFs3iR YZFmAwSIqokRQz3FEkgg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hG53s-0002Bo-6N; Mon, 15 Apr 2019 17:06:28 +0000 Received: from foss.arm.com ([217.140.101.70]) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hG53o-0002BA-Sg for linux-arm-kernel@lists.infradead.org; Mon, 15 Apr 2019 17:06:26 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 2E55080D; Mon, 15 Apr 2019 10:06:23 -0700 (PDT) Received: from lakrids.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 3D7543F68F; Mon, 15 Apr 2019 10:06:21 -0700 (PDT) Date: Mon, 15 Apr 2019 18:06:08 +0100 From: Mark Rutland To: Kees Cook Subject: Re: [PATCH v3] arm64: sysreg: make mrs_s and msr_s macros work with Clang and LTO Message-ID: <20190415170604.GA44415@lakrids.cambridge.arm.com> References: <20190415143821.GA46880@beast> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20190415143821.GA46880@beast> User-Agent: Mutt/1.11.1+11 (2f07cb52) (2018-12-01) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190415_100624_935812_41A47937 X-CRM114-Status: GOOD ( 23.35 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ard Biesheuvel , Catalin Marinas , Nick Desaulniers , linux-kernel@vger.kernel.org, Will Deacon , Yury Norov , Sami Tolvanen , Alex Matveev , Matthias Kaehlcke , linux-arm-kernel@lists.infradead.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Mon, Apr 15, 2019 at 07:38:21AM -0700, Kees Cook wrote: > From: Alex Matveev > > Clang's integrated assembler does not allow assembly macros defined > in one inline asm block using the .macro directive to be used across > separate asm blocks. LLVM developers consider this a feature and not a > bug, recommending code refactoring: > > https://bugs.llvm.org/show_bug.cgi?id=19749 > > As binutils doesn't allow macros to be redefined, this change uses > UNDEFINE_MRS_S and UNDEFINE_MSR_S to define corresponding macros > in-place and workaround gcc and clang limitations on redefining macros > across different assembler blocks. > > Specifically, the current state after preprocessing looks like this: > > asm volatile(".macro mXX_s ... .endm"); > void f() > { > asm volatile("mXX_s a, b"); > } > > With GCC, it gives macro redefinition error because sysreg.h is included > in multiple source files, and assembler code for all of them is later > combined for LTO (I've seen an intermediate file with hundreds of > identical definitions). > > With clang, it gives macro undefined error because clang doesn't allow > sharing macros between inline asm statements. > > I also seem to remember catching another sort of undefined error with > GCC due to reordering of macro definition asm statement and generated > asm code for function that uses the macro. > > The solution with defining and undefining for each use, while certainly > not elegant, satisfies both GCC and clang, LTO and non-LTO. > > Signed-off-by: Alex Matveev > Signed-off-by: Yury Norov > Signed-off-by: Sami Tolvanen > Signed-off-by: Kees Cook > --- > v3: split out patch as stand-alone, added more uses in irqflags, > updated commit log, based on discussion in > https://lore.kernel.org/patchwork/patch/851580/ > --- > arch/arm64/include/asm/irqflags.h | 12 +++++-- > arch/arm64/include/asm/kvm_hyp.h | 8 +++-- > arch/arm64/include/asm/sysreg.h | 55 +++++++++++++++++++++---------- > 3 files changed, 53 insertions(+), 22 deletions(-) > > diff --git a/arch/arm64/include/asm/irqflags.h b/arch/arm64/include/asm/irqflags.h > index 43d8366c1e87..06d3987d1546 100644 > --- a/arch/arm64/include/asm/irqflags.h > +++ b/arch/arm64/include/asm/irqflags.h > @@ -43,7 +43,9 @@ static inline void arch_local_irq_enable(void) > asm volatile(ALTERNATIVE( > "msr daifclr, #2 // arch_local_irq_enable\n" > "nop", > + DEFINE_MSR_S > "msr_s " __stringify(SYS_ICC_PMR_EL1) ",%0\n" > + UNDEFINE_MSR_S If we do need this, can we wrap this in a larger CPP macro that does the whole sequence of defining, using, and undefining the asm macros? It would be nice if we could simply rely on a more recent binutils these days, which supports the generic S____ sysreg definition. That would mean we could get rid of the whole msr_s/mrs_s hack by turning that into a CPP macro which built that name. It looks like binutils has been able to do that since September 2014... Are folk using toolchains older than that to compile kernels? Thanks, Mark. _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel