From patchwork Fri Nov 3 17:11:57 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sami Tolvanen X-Patchwork-Id: 10040841 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 0C5EA60384 for ; Fri, 3 Nov 2017 17:15:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E5D2C296FA for ; Fri, 3 Nov 2017 17:14:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D8E712970E; Fri, 3 Nov 2017 17:14:59 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, DKIM_VALID, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 4ED50296FA for ; Fri, 3 Nov 2017 17:14:59 +0000 (UTC) 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:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=wKaRdhprHIxHfSo9C+Gj9qn4f0O0ppLbklMMXnLsuHk=; b=RvQRzfeCwEtEYVPfyrM+zO8W8R sVl+SNO0oJ4TpBB1Tg9bEUCiR8jxXHLbYVCvGuyMJjgWUj/GRm+s8Nt8vIhjA4327J9GvNQZwO15c Cuap1kWYjvPiscRI+n1qHxzX7LENhBQHO23end9pFt96xXRrNbBxQmfp9DWCkR+ovfpN29lDSf2gK taXSfQNNMTdotuxKWkeSH4y98hccToyt77t9dT+y1OKwACnDD6+q7lpFBNa3poXCDW70JydQXP/Ad q7vp7unRYdk838xy/zc9Pci3GgoM+mW6euW5htlr2lfbioVn50xyMyX9WG2ClrNfCPPinc4TeOFYj Y58cI3hA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1eAfYY-0001sF-Jx; Fri, 03 Nov 2017 17:14:58 +0000 Received: from mail-io0-x241.google.com ([2607:f8b0:4001:c06::241]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1eAfWy-00005A-9E for linux-arm-kernel@lists.infradead.org; Fri, 03 Nov 2017 17:13:53 +0000 Received: by mail-io0-x241.google.com with SMTP id 189so7712399iow.10 for ; Fri, 03 Nov 2017 10:12:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=qSSGiIxpsfKrAO30RF0erGNPwh25M6eX6K+gQq2GDXk=; b=g7uaxAw76wJpqIHliTZINoFOVnZx/cCPxf5FYlGnddUvrnJEdcrcf7IDXjOBkt4LsM o2XlmV4IvMehksxzowKTVaZjit3E/4im7oQCa05vzbRuzesoVqKsbKRyEUau+dW6BRGb wdLGENiOcmwZmGzR+drbpDbiCl4+sldu0J/ttbMt8GB2EMhxSdsGidoZEr5DVtFD/SVK SRF2wSGghg5oxtkQ3AblNpviKsuUFrwN26fkFX1hEJFPXWYlgCICVD25M3Veth5T13VI 6QbYRqr9duFwa3HAMM/kFpDsBT/kt2gLEzxpS/BgvDQKoOt465wHVB71sQo19D8Lk6Pq Lb2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=qSSGiIxpsfKrAO30RF0erGNPwh25M6eX6K+gQq2GDXk=; b=mzHdDgdtRnlk4weaSPNFQ+xL47ZeYVay4wxVXGLMe90dbZJdeSmQdopXAU+7DyA0Vi /m94sp57HKaTjmNzvcq4IN+xw8z7S+r6EvJlCSdg1IFJVnXw1LHrfEjtKODJ+JqTLGwM 0SEDPWpgx3dPbfpMUr2v8ssLIAUDHEZq98LfknV9Ee6Ktb797sBYkukB60LLXkQa2UIT AAjwI2/oiozPXUrFEWAxSCwvErD43vElvDMJnHcPIenJyMOkBQa/tRL5gFg1/9ZyQW6K OABYwGWf10VW1AiDMQOTkqXeaPmDtAntqpMJl1VSMGgjPDNOx0t6CtIT7c2fBXZ7Hjuz acmg== X-Gm-Message-State: AJaThX42FxhQ758Cf1CpS6TOkLzjmh/SARAW729buLs6yy48U/qLGu4T 8/X/8pA254m9hAozQuL9skGPfg== X-Google-Smtp-Source: ABhQp+RMIow9+YUYWpC4Os3X7N7Se4KvUj0WMf5KSDD/PR9mRO7iT61dqjxc03AH5pZ/gKIpWzaWwQ== X-Received: by 10.36.107.132 with SMTP id v126mr705822itc.43.1509729179002; Fri, 03 Nov 2017 10:12:59 -0700 (PDT) Received: from samitolvanen.mtv.corp.google.com ([100.98.112.14]) by smtp.gmail.com with ESMTPSA id d186sm1370787itd.38.2017.11.03.10.12.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 03 Nov 2017 10:12:57 -0700 (PDT) From: Sami Tolvanen To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH 11/15] arm64: fix mrs_s/msr_s macros for clang LTO Date: Fri, 3 Nov 2017 10:11:57 -0700 Message-Id: <20171103171203.107569-14-samitolvanen@google.com> X-Mailer: git-send-email 2.15.0.403.gc27cc4dac6-goog In-Reply-To: <20171103171203.107569-1-samitolvanen@google.com> References: <20171103171203.107569-1-samitolvanen@google.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171103_101320_983840_06FC3212 X-CRM114-Status: GOOD ( 11.77 ) 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: Sami Tolvanen , Matthias Kaehlcke , Nick Desaulniers , Kees Cook , Greg Hackmann MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP 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 adds C preprocessor macros that define the assembly macros globally for binutils and locally for clang's integrated assembler. Suggested-by: Greg Hackmann Suggested-by: Nick Desaulniers Signed-off-by: Sami Tolvanen --- arch/arm64/include/asm/kvm_hyp.h | 2 ++ arch/arm64/include/asm/sysreg.h | 71 ++++++++++++++++++++++++++++++---------- 2 files changed, 56 insertions(+), 17 deletions(-) diff --git a/arch/arm64/include/asm/kvm_hyp.h b/arch/arm64/include/asm/kvm_hyp.h index 4572a9b560fa..6840704ea894 100644 --- a/arch/arm64/include/asm/kvm_hyp.h +++ b/arch/arm64/include/asm/kvm_hyp.h @@ -29,6 +29,7 @@ ({ \ u64 reg; \ asm volatile(ALTERNATIVE("mrs %0, " __stringify(r##nvh),\ + DEFINE_MRS_S \ "mrs_s %0, " __stringify(r##vh),\ ARM64_HAS_VIRT_HOST_EXTN) \ : "=r" (reg)); \ @@ -39,6 +40,7 @@ do { \ u64 __val = (u64)(v); \ asm volatile(ALTERNATIVE("msr " __stringify(r##nvh) ", %x0",\ + DEFINE_MSR_S \ "msr_s " __stringify(r##vh) ", %x0",\ ARM64_HAS_VIRT_HOST_EXTN) \ : : "rZ" (__val)); \ diff --git a/arch/arm64/include/asm/sysreg.h b/arch/arm64/include/asm/sysreg.h index f707fed5886f..1588ac3f3690 100644 --- a/arch/arm64/include/asm/sysreg.h +++ b/arch/arm64/include/asm/sysreg.h @@ -463,21 +463,58 @@ #include -asm( -" .irp num,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30\n" -" .equ .L__reg_num_x\\num, \\num\n" -" .endr\n" +#define ___MRS_MSR_S_REGNUM \ +" .irp num,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30\n" \ +" .equ .L__reg_num_x\\num, \\num\n" \ +" .endr\n" \ " .equ .L__reg_num_xzr, 31\n" -"\n" -" .macro mrs_s, rt, sreg\n" - __emit_inst(0xd5200000|(\\sreg)|(.L__reg_num_\\rt)) + +#define ___MRS_S \ +" .macro mrs_s, rt, sreg\n" \ + __emit_inst(0xd5200000|(\\sreg)|(.L__reg_num_\\rt)) \ " .endm\n" -"\n" -" .macro msr_s, sreg, rt\n" - __emit_inst(0xd5000000|(\\sreg)|(.L__reg_num_\\rt)) + +#define ___MSR_S \ +" .macro msr_s, sreg, rt\n" \ + __emit_inst(0xd5000000|(\\sreg)|(.L__reg_num_\\rt)) \ " .endm\n" + +/* + * llvm-as doesn't allow macros defined in an asm block to be used in other + * asm blocks, which means we cannot define them globally. + */ +#if !defined(CONFIG_CLANG_LTO) +asm( + ___MRS_MSR_S_REGNUM + ___MRS_S + ___MSR_S ); +#undef ___MRS_MSR_S_REGNUM +#define ___MRS_MSR_S_REGNUM +#undef ___MRS_S +#define ___MRS_S +#undef ___MSR_S +#define ___MSR_S +#endif + +#define DEFINE_MRS_S \ + ___MRS_MSR_S_REGNUM \ + ___MRS_S + +#define DEFINE_MSR_S \ + ___MRS_MSR_S_REGNUM \ + ___MSR_S + + +#define __mrs_s(r, v) \ + DEFINE_MRS_S \ +" mrs_s %0, " __stringify(r) : "=r" (v) + +#define __msr_s(r, v) \ + DEFINE_MSR_S \ +" msr_s " __stringify(r) ", %0" : : "r" (v) + /* * Unlike read_cpuid, calls to read_sysreg are never expected to be * optimized away or replaced with synthetic values. @@ -502,15 +539,15 @@ asm( * For registers without architectural names, or simply unsupported by * GAS. */ -#define read_sysreg_s(r) ({ \ - u64 __val; \ - asm volatile("mrs_s %0, " __stringify(r) : "=r" (__val)); \ - __val; \ +#define read_sysreg_s(r) ({ \ + u64 __val; \ + asm volatile(__mrs_s(r, __val)); \ + __val; \ }) -#define write_sysreg_s(v, r) do { \ - u64 __val = (u64)(v); \ - asm volatile("msr_s " __stringify(r) ", %x0" : : "rZ" (__val)); \ +#define write_sysreg_s(v, r) do { \ + u64 __val = (u64)(v); \ + asm volatile(__msr_s(r, __val)); \ } while (0) static inline void config_sctlr_el1(u32 clear, u32 set)