Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp1931715ybv; Fri, 14 Feb 2020 08:26:21 -0800 (PST) X-Google-Smtp-Source: APXvYqw2ZLtqAgiL51QgAAGO+e8P18SOC6LU0+37dNRvTxgJoSTSytk2gHNl8YJ0bXHyHfBvZj0M X-Received: by 2002:a54:4117:: with SMTP id l23mr2341644oic.140.1581697581476; Fri, 14 Feb 2020 08:26:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581697581; cv=none; d=google.com; s=arc-20160816; b=X6mV1MGxl3N5XyeRDHgSy8Y3iXsM41HRiMaPvwTacR3CY3NLk7CmNPPVjjDNR5vUAb BKcGKo8bI2ve7+bEv3uClTEe+TxOV/2F3KWPmJGx8hUdnTCRUdzRiSQmut7YH0z3oHUC MnJKGLydAOWtNj0q+evBwOrnr4XIE4OUPUQ8HfvfSZ3LspjDzO4mt4o5y7xJ9zqGyS5b RC+O240TFcfx4J51iDY59OC/HmEGqb1tBGBg+jV3rgtO8thAcZkgbnkyXewx3Ckiew/B /fXQE6AkxHXlICbq0aPcn5LH75G3vaFSFZvNoGfm/yfq2xIbi7uW+Zb5A5Y9++1rWTg4 fl/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=26e4Gl6HyuXH10D/TrxqxJTDnFM/q2djaEQI5bxneZY=; b=WQ0Sb6x9wwuwbUf3LGAVqZaZjsHe7ejxWUb2NmLcMcqpGxdyJ5N7mtK8JVbQUuvmff b34gLGM7sdbcqP6YKnqm43aAzdQfdHf64Q2dKog064jkBRAd8fVJ55Vmg9ovXvl9nHOt 3dpfQtiJSvns2/FA5WA7Mw9uoESjwG5ZhRKB3d2GO5vZa3ARXuTY6BICmTOhA0DDbhdV gxyMSop7bsY72I6gDx5MnaCI84EiGkJgYoHz3/u/kOMh6ZPXS2a+y7b6iWKp2CdhoTXR 06A7+5pQ1Q5c64JICc1H7Dfp/Mo5olXIJfyPOvewee4+uroMjfASXv8hqIpvsdLL+2bh fH8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=wwbJU1AK; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id f187si2959022oia.218.2020.02.14.08.26.09; Fri, 14 Feb 2020 08:26:21 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=wwbJU1AK; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S2405832AbgBNQZn (ORCPT + 99 others); Fri, 14 Feb 2020 11:25:43 -0500 Received: from mail.kernel.org ([198.145.29.99]:59906 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2405665AbgBNQXe (ORCPT ); Fri, 14 Feb 2020 11:23:34 -0500 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B408524780; Fri, 14 Feb 2020 16:23:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1581697413; bh=PDMbmD8Sqlz13ShwSV+5MvJr2JPo+gqZP1cUKJNWXDE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wwbJU1AKRJNvZ5/Kteb2jtyYu3wVZ6zU6ROrITc1/W+i17smJl2NTWB6S8b8osH3n D7Bjfv3zxF0aldymA6p4HpTatg8OzVIhNG5UwEkBy9yAGhoLISuFJpAjZkJU4CqZg/ nMvppaeIhb4QYPEXCmyhbCDu67SoX96hCvIJ8bzw= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Sami Tolvanen , Nick Desaulniers , Kees Cook , Will Deacon , Sasha Levin , linux-arm-kernel@lists.infradead.org, clang-built-linux@googlegroups.com Subject: [PATCH AUTOSEL 4.9 104/141] arm64: fix alternatives with LLVM's integrated assembler Date: Fri, 14 Feb 2020 11:20:44 -0500 Message-Id: <20200214162122.19794-104-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200214162122.19794-1-sashal@kernel.org> References: <20200214162122.19794-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sami Tolvanen [ Upstream commit c54f90c2627cc316d365e3073614731e17dbc631 ] LLVM's integrated assembler fails with the following error when building KVM: :12:6: error: expected absolute expression .if kvm_update_va_mask == 0 ^ :21:6: error: expected absolute expression .if kvm_update_va_mask == 0 ^ :24:2: error: unrecognized instruction mnemonic NOT_AN_INSTRUCTION ^ LLVM ERROR: Error parsing inline asm These errors come from ALTERNATIVE_CB and __ALTERNATIVE_CFG, which test for the existence of the callback parameter in inline assembly using the following expression: " .if " __stringify(cb) " == 0\n" This works with GNU as, but isn't supported by LLVM. This change splits __ALTERNATIVE_CFG and ALTINSTR_ENTRY into separate macros to fix the LLVM build. Link: https://github.com/ClangBuiltLinux/linux/issues/472 Signed-off-by: Sami Tolvanen Tested-by: Nick Desaulniers Reviewed-by: Kees Cook Signed-off-by: Will Deacon Signed-off-by: Sasha Levin --- arch/arm64/include/asm/alternative.h | 32 ++++++++++++++++++---------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/arch/arm64/include/asm/alternative.h b/arch/arm64/include/asm/alternative.h index 7e842dcae4509..3626655175a2e 100644 --- a/arch/arm64/include/asm/alternative.h +++ b/arch/arm64/include/asm/alternative.h @@ -29,13 +29,16 @@ typedef void (*alternative_cb_t)(struct alt_instr *alt, void __init apply_alternatives_all(void); void apply_alternatives(void *start, size_t length); -#define ALTINSTR_ENTRY(feature,cb) \ +#define ALTINSTR_ENTRY(feature) \ " .word 661b - .\n" /* label */ \ - " .if " __stringify(cb) " == 0\n" \ " .word 663f - .\n" /* new instruction */ \ - " .else\n" \ + " .hword " __stringify(feature) "\n" /* feature bit */ \ + " .byte 662b-661b\n" /* source len */ \ + " .byte 664f-663f\n" /* replacement len */ + +#define ALTINSTR_ENTRY_CB(feature, cb) \ + " .word 661b - .\n" /* label */ \ " .word " __stringify(cb) "- .\n" /* callback */ \ - " .endif\n" \ " .hword " __stringify(feature) "\n" /* feature bit */ \ " .byte 662b-661b\n" /* source len */ \ " .byte 664f-663f\n" /* replacement len */ @@ -56,15 +59,14 @@ void apply_alternatives(void *start, size_t length); * * Alternatives with callbacks do not generate replacement instructions. */ -#define __ALTERNATIVE_CFG(oldinstr, newinstr, feature, cfg_enabled, cb) \ +#define __ALTERNATIVE_CFG(oldinstr, newinstr, feature, cfg_enabled) \ ".if "__stringify(cfg_enabled)" == 1\n" \ "661:\n\t" \ oldinstr "\n" \ "662:\n" \ ".pushsection .altinstructions,\"a\"\n" \ - ALTINSTR_ENTRY(feature,cb) \ + ALTINSTR_ENTRY(feature) \ ".popsection\n" \ - " .if " __stringify(cb) " == 0\n" \ ".pushsection .altinstr_replacement, \"a\"\n" \ "663:\n\t" \ newinstr "\n" \ @@ -72,17 +74,25 @@ void apply_alternatives(void *start, size_t length); ".popsection\n\t" \ ".org . - (664b-663b) + (662b-661b)\n\t" \ ".org . - (662b-661b) + (664b-663b)\n" \ - ".else\n\t" \ + ".endif\n" + +#define __ALTERNATIVE_CFG_CB(oldinstr, feature, cfg_enabled, cb) \ + ".if "__stringify(cfg_enabled)" == 1\n" \ + "661:\n\t" \ + oldinstr "\n" \ + "662:\n" \ + ".pushsection .altinstructions,\"a\"\n" \ + ALTINSTR_ENTRY_CB(feature, cb) \ + ".popsection\n" \ "663:\n\t" \ "664:\n\t" \ - ".endif\n" \ ".endif\n" #define _ALTERNATIVE_CFG(oldinstr, newinstr, feature, cfg, ...) \ - __ALTERNATIVE_CFG(oldinstr, newinstr, feature, IS_ENABLED(cfg), 0) + __ALTERNATIVE_CFG(oldinstr, newinstr, feature, IS_ENABLED(cfg)) #define ALTERNATIVE_CB(oldinstr, cb) \ - __ALTERNATIVE_CFG(oldinstr, "NOT_AN_INSTRUCTION", ARM64_CB_PATCH, 1, cb) + __ALTERNATIVE_CFG_CB(oldinstr, ARM64_CB_PATCH, 1, cb) #else #include -- 2.20.1