From patchwork Thu Aug 4 17:50:03 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 73303 Delivered-To: patch@linaro.org Received: by 10.140.29.52 with SMTP id a49csp1519396qga; Thu, 4 Aug 2016 10:52:44 -0700 (PDT) X-Received: by 10.36.242.1 with SMTP id j1mr73039495ith.8.1470333155304; Thu, 04 Aug 2016 10:52:35 -0700 (PDT) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id z201si4131613itb.24.2016.08.04.10.52.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 04 Aug 2016 10:52:35 -0700 (PDT) Received-SPF: neutral (google.com: 192.237.175.120 is neither permitted nor denied by best guess record for domain of xen-devel-bounces@lists.xen.org) client-ip=192.237.175.120; Authentication-Results: mx.google.com; spf=neutral (google.com: 192.237.175.120 is neither permitted nor denied by best guess record for domain of xen-devel-bounces@lists.xen.org) smtp.mailfrom=xen-devel-bounces@lists.xen.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bVMmh-0004bN-8L; Thu, 04 Aug 2016 17:50:19 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bVMmg-0004aU-CB for xen-devel@lists.xen.org; Thu, 04 Aug 2016 17:50:18 +0000 Received: from [85.158.137.68] by server-9.bemta-3.messagelabs.com id 8A/86-27233-95083A75; Thu, 04 Aug 2016 17:50:17 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrGLMWRWlGSWpSXmKPExsVysyfVTTeyYXG 4wZp1bBZLPi5mcWD0OLr7N1MAYxRrZl5SfkUCa0bbpR+sBc8kK1b1n2RrYFzH38XIxSEksIlR Yv6bP6wQzmlGiavv/rF1MXJysAloStz5/IkJxBYRkJa49vkyI4jNLFAo0dvYDWYLCwRLNO6/B FTDwcEioCpxuUsVJMwr4CLRdGQK2BgJATmJk8cms4LYnAKuEpNO/WAGsYWAatatu8wygZF7AS PDKkaN4tSistQiXUNDvaSizPSMktzEzBxdQwNjvdzU4uLE9NScxKRiveT83E2MQP8yAMEOxtW /nQ4xSnIwKYnyvqpeHC7El5SfUpmRWJwRX1Sak1p8iFGGg0NJgvdJHVBOsCg1PbUiLTMHGGgw aQkOHiUR3hUgad7igsTc4sx0iNQpRkUpcd5ykIQASCKjNA+uDRbclxhlpYR5GYEOEeIpSC3Kz SxBlX/FKM7BqCTMewhkCk9mXgnc9FdAi5mAFp8wWACyuCQRISXVwLiz8JedzNQU1qtuM/Nv3p E51s+aeN2OxSh7z4G/5oWPIx7e2C37LDDot/Km3wYNv03XPtiye42nj6ycb1nG0ejos09NzwV ya2y7HdN7YO+F43rN0i+FXt7dlpX8kTtnylHn3bfWaK13EtyoNUVhh5VwyPm2cJsClzx3hZ1v /01tmmeil6/QvVCJpTgj0VCLuag4EQDsuivAaQIAAA== X-Env-Sender: julien.grall@arm.com X-Msg-Ref: server-7.tower-31.messagelabs.com!1470333016!46512559!1 X-Originating-IP: [217.140.101.70] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 8.77; banners=-,-,- X-VirusChecked: Checked Received: (qmail 53134 invoked from network); 4 Aug 2016 17:50:16 -0000 Received: from foss.arm.com (HELO foss.arm.com) (217.140.101.70) by server-7.tower-31.messagelabs.com with SMTP; 4 Aug 2016 17:50:16 -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 EB2E03A1; Thu, 4 Aug 2016 10:51:38 -0700 (PDT) Received: from e108454-lin.cambridge.arm.com (e108454-lin.cambridge.arm.com [10.1.218.32]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 340583F575; Thu, 4 Aug 2016 10:50:15 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xen.org Date: Thu, 4 Aug 2016 18:50:03 +0100 Message-Id: <1470333007-25178-3-git-send-email-julien.grall@arm.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1470333007-25178-1-git-send-email-julien.grall@arm.com> References: <1470333007-25178-1-git-send-email-julien.grall@arm.com> Cc: Julien Grall , sstabellini@kernel.org Subject: [Xen-devel] [PATCH v3 2/6] xen/arm: Provide macros to help creating workaround helpers X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" Workarounds may require to execute a different path when the platform is affected by the associated erratum. Furthermore, this may need to be called in the common code. To avoid too much intrusion/overhead, the workaround helpers need to be a nop on architecture which will never have the workaround and have to be quick to check whether the platform requires it. The alternative framework is used to transform the check in a single instruction. When the framework is not available, the helper will have ~6 instructions including 1 instruction load. The macro will create a handler called check_workaround_xxxxx with xxxx the erratum number. For instance, the line bellow will create a workaround helper for erratum #424242 which is enabled when the capability ARM64_WORKAROUND_424242 is set and only available for ARM64: CHECK_WORKAROUND_HELPER(424242, ARM64_WORKAROUND_42424242, CONFIG_ARM64) Signed-off-by: Julien Grall Reviewed-by: Konrad Rzeszutek Wilk Acked-by: Stefano Stabellini --- Changes in v2: - Add Konrad's reviewed-by --- xen/include/asm-arm/cpuerrata.h | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/xen/include/asm-arm/cpuerrata.h b/xen/include/asm-arm/cpuerrata.h index c495ee5..2982a92 100644 --- a/xen/include/asm-arm/cpuerrata.h +++ b/xen/include/asm-arm/cpuerrata.h @@ -1,8 +1,47 @@ #ifndef __ARM_CPUERRATA_H__ #define __ARM_CPUERRATA_H__ +#include +#include +#include + void check_local_cpu_errata(void); +#ifdef CONFIG_ALTERNATIVE + +#define CHECK_WORKAROUND_HELPER(erratum, feature, arch) \ +static inline bool_t check_workaround_##erratum(void) \ +{ \ + if ( !IS_ENABLED(arch) ) \ + return 0; \ + else \ + { \ + bool_t ret; \ + \ + asm volatile (ALTERNATIVE("mov %0, #0", \ + "mov %0, #1", \ + feature) \ + : "=r" (ret)); \ + \ + return unlikely(ret); \ + } \ +} + +#else /* CONFIG_ALTERNATIVE */ + +#define CHECK_WORKAROUND_HELPER(erratum, feature, arch) \ +static inline bool_t check_workaround_##erratum(void) \ +{ \ + if ( !IS_ENABLED(arch) ) \ + return 0; \ + else \ + return unlikely(cpus_have_cap(feature)); \ +} + +#endif + +#undef CHECK_WORKAROUND_HELPER + #endif /* __ARM_CPUERRATA_H__ */ /* * Local variables: