From patchwork Wed Nov 15 21:34:21 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sami Tolvanen X-Patchwork-Id: 10060411 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 1F146604D4 for ; Wed, 15 Nov 2017 21:48:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1091C2A31E for ; Wed, 15 Nov 2017 21:48:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 057292A323; Wed, 15 Nov 2017 21:48:34 +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=unavailable 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 6F4DA2A31E for ; Wed, 15 Nov 2017 21:48:33 +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=Okf/AsD1EL6OaOP73aARGfQx66BgkansAHmpPF+rkuk=; b=nGGb0ze5ffRvspSpVROQxSpbDP kHhtfuqsxCYuJwBsKLO556o3N+JEF6Lvw1VxQCVtEEFQDr1tYJXLq58x1TpcFxFmLGLNbQDWHm2y7 Wl2zaizNim4/ri1/WykxCNzl82mXnHNFmq2+5EoqJLResqHQdJV00mVwLLcqR6QsDKNT0lTPEqFB1 zW1jlIt4vnSstRYf/sT9RDDKWWM9ZSj/iXlikPBQyea6jNm2ohbbRNXPpoxS51wOgJdrAYJs1UvOE eHb95Qrh4SxS2z3zmr4sZ5WIGaiATpCmJgE/nlG1n6AtQ9726vDLaWEbG9bthjFnXsjngMgvJnf58 kHe8VoDg==; 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 1eF5Xo-0003OL-P3; Wed, 15 Nov 2017 21:48:28 +0000 Received: from mail-io0-x243.google.com ([2607:f8b0:4001:c06::243]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1eF5L7-0008Ag-1u for linux-arm-kernel@lists.infradead.org; Wed, 15 Nov 2017 21:35:26 +0000 Received: by mail-io0-x243.google.com with SMTP id t11so3076081iof.13 for ; Wed, 15 Nov 2017 13:35:01 -0800 (PST) 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=8OQge4NWva0BQzF+rr/7099Ua+Bae7+EsFK3S5i/CKo=; b=JIQuTN9PkWYR1JfrbzQWr02/OJKAywy4TJ7zJYvOoulRcmwBrY2BWKS85MU+2Cjos+ Piw57HVN8pYFQfkE0u+hOBHTcNs0ijYSMcfvhDa/l5Yu8TbnRpzMkfYsMtLaE365BFfg jIddeg0XdmC5aeE2FfPSkeSrtsMw1DFjQCnVRqVuRBTTc2ULwojZJEYURu/ltag8NiTy KTiq7Kfy/5uRQjgcZIeSrxE1qDZGzaRRdibooJeRv1oFUPB3E/wvdmhuZSFwvriNqu7V teMJWF4UtRSZGfMQPczzl8d0qS2ouJWnDh4Zjc3uNyx/74bw2vbOWUEdwDr5jHkkmcAZ y8Ng== 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=8OQge4NWva0BQzF+rr/7099Ua+Bae7+EsFK3S5i/CKo=; b=qPDj7BX7tHpu0ny2x5Sj3pNClfNLINSnqM2E1b3QCTIABD+JZjlALcfXhOKTLR5pmn ypWiGF8QMYIMzEaLT167JgJQ3YDJ+nTN/CDnauOZeL1dTaNnK6BBxSIible1mVpLQjiu K4IudUYVYBSj01kKK13pUy6R9pkJKr76AiF976ybP1GXiOvLo9bdEywS8m8zIPM3GF9P SvCgcnLMgW3vHtOPzveGszpwO17j3OisjzReWLPRcVG937hLK6mMzz4WwANTGmpwlZ+S 5Yox9Fp+/tx8tpS7MFuP9H22I4NLmL2WOOhDESGKJp1fidkEGkCgRZ3yeFbVmmdJTyBr GXZw== X-Gm-Message-State: AJaThX6uhaeK12UlAqr0QSRo1SGbpqkuLQoEmmuSw15ItstSZ+YOWFU7 A4R52BUeyv/zcsvq3s9mjyTAcg== X-Google-Smtp-Source: AGs4zMbH8ALzAqLjQfqUsFfrvm7DVHqvreVc+uyExZBnyg2FuD07dq0YOehjyHXAQqtLEkd4DVNpvw== X-Received: by 10.107.8.152 with SMTP id h24mr5235528ioi.155.1510781700933; Wed, 15 Nov 2017 13:35:00 -0800 (PST) Received: from samitolvanen.mtv.corp.google.com ([100.98.112.14]) by smtp.gmail.com with ESMTPSA id 68sm9735197iov.2.2017.11.15.13.34.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 15 Nov 2017 13:35:00 -0800 (PST) From: Sami Tolvanen To: Alex Matveev , Andi Kleen , Ard Biesheuvel , Greg Hackmann , Kees Cook , linux-arm-kernel@lists.infradead.org, linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, Mark Rutland , Masahiro Yamada , Maxim Kuvyrkov , Michal Marek , Nick Desaulniers , Yury Norov , Matthias Kaehlcke Subject: [PATCH v2 11/18] arm64: make mrs_s and msr_s macros work with LTO Date: Wed, 15 Nov 2017 13:34:21 -0800 Message-Id: <20171115213428.22559-12-samitolvanen@google.com> X-Mailer: git-send-email 2.15.0.448.gf294e3d99a-goog In-Reply-To: <20171115213428.22559-1-samitolvanen@google.com> References: <20171115213428.22559-1-samitolvanen@google.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171115_133521_263619_62800460 X-CRM114-Status: UNSURE ( 9.61 ) X-CRM114-Notice: Please train this message. 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 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 From: Alex Matveev Use 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. Signed-off-by: Alex Matveev Signed-off-by: Yury Norov Signed-off-by: Sami Tolvanen --- arch/arm64/include/asm/kvm_hyp.h | 8 ++++-- arch/arm64/include/asm/sysreg.h | 55 +++++++++++++++++++++++++++------------- 2 files changed, 43 insertions(+), 20 deletions(-) diff --git a/arch/arm64/include/asm/kvm_hyp.h b/arch/arm64/include/asm/kvm_hyp.h index 4572a9b560fa..20bfb8e676e0 100644 --- a/arch/arm64/include/asm/kvm_hyp.h +++ b/arch/arm64/include/asm/kvm_hyp.h @@ -29,7 +29,9 @@ ({ \ u64 reg; \ asm volatile(ALTERNATIVE("mrs %0, " __stringify(r##nvh),\ - "mrs_s %0, " __stringify(r##vh),\ + DEFINE_MRS_S \ + "mrs_s %0, " __stringify(r##vh) "\n"\ + UNDEFINE_MRS_S, \ ARM64_HAS_VIRT_HOST_EXTN) \ : "=r" (reg)); \ reg; \ @@ -39,7 +41,9 @@ do { \ u64 __val = (u64)(v); \ asm volatile(ALTERNATIVE("msr " __stringify(r##nvh) ", %x0",\ - "msr_s " __stringify(r##vh) ", %x0",\ + DEFINE_MSR_S \ + "msr_s " __stringify(r##vh) ", %x0\n"\ + UNDEFINE_MSR_S, \ ARM64_HAS_VIRT_HOST_EXTN) \ : : "rZ" (__val)); \ } while (0) diff --git a/arch/arm64/include/asm/sysreg.h b/arch/arm64/include/asm/sysreg.h index 08cc88574659..3ae147c7e160 100644 --- a/arch/arm64/include/asm/sysreg.h +++ b/arch/arm64/include/asm/sysreg.h @@ -584,20 +584,39 @@ #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 __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 DEFINE_MRS_S \ + __DEFINE_MRS_MSR_S_REGNUM \ +" .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 DEFINE_MSR_S \ + __DEFINE_MRS_MSR_S_REGNUM \ +" .macro msr_s, sreg, rt\n" \ + __emit_inst(0xd5000000|(\\sreg)|(.L__reg_num_\\rt)) \ " .endm\n" -); + +#define UNDEFINE_MRS_S \ +" .purgem mrs_s\n" + +#define UNDEFINE_MSR_S \ +" .purgem msr_s\n" + +#define __mrs_s(r, v) \ + DEFINE_MRS_S \ +" mrs_s %0, " __stringify(r) "\n" \ + UNDEFINE_MRS_S : "=r" (v) + +#define __msr_s(r, v) \ + DEFINE_MSR_S \ +" msr_s " __stringify(r) ", %x0\n" \ + UNDEFINE_MSR_S : : "rZ" (v) /* * Unlike read_cpuid, calls to read_sysreg are never expected to be @@ -623,15 +642,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)