From patchwork Wed Jul 27 17:09:34 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 9250189 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 EDDFF60757 for ; Wed, 27 Jul 2016 17:12:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DECE8219AC for ; Wed, 27 Jul 2016 17:12:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D365926253; Wed, 27 Jul 2016 17:12:27 +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, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 56B59219AC for ; Wed, 27 Jul 2016 17:12:27 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bSSLB-0004Je-8u; Wed, 27 Jul 2016 17:09:53 +0000 Received: from mail6.bemta6.messagelabs.com ([85.158.143.247]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bSSLA-0004Ii-07 for xen-devel@lists.xen.org; Wed, 27 Jul 2016 17:09:52 +0000 Received: from [85.158.143.35] by server-1.bemta-6.messagelabs.com id 6D/D8-21406-FDAE8975; Wed, 27 Jul 2016 17:09:51 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrOLMWRWlGSWpSXmKPExsVysyfVTffOqxn hBrdXylos+biYxYHR4+ju30wBjFGsmXlJ+RUJrBltl36wFjyTrFjVf5KtgXEdfxcjF4eQwCZG id8zV7BBOKcZJb7s3sbaxcjJwSagKXHn8ycmEFtEQFri2ufLjCBFzALbGSWuzVsCViQsECzx9 PgisCIWAVWJs+umsYPYvALOEhdW/2cDsSUE5CROHpsMVs8p4CLRcb0NrF4IqGbO3n2sExi5Fz AyrGJUL04tKkst0jXVSyrKTM8oyU3MzNE1NDDTy00tLk5MT81JTCrWS87P3cQI9DADEOxgnH7 Z/xCjJAeTkigv17MZ4UJ8SfkplRmJxRnxRaU5qcWHGGU4OJQkeOteAuUEi1LTUyvSMnOAoQaT luDgURLh3QCS5i0uSMwtzkyHSJ1iVJQS55UDSQiAJDJK8+DaYOF9iVFWSpiXEegQIZ6C1KLcz BJU+VeM4hyMSsK880Gm8GTmlcBNfwW0mAlocXEs2OKSRISUVAOj7+JbvKGTfuUdyw4NPFcqEp T6duG3hXH3VvNlVMtcksy/ctJruYAER8P/my2Ff+J2OU4pr3A5tlLJcuairpWXeEKuHXo/u+2 zhGmmv/ynMve61Yy7r50IeLZFct+iR21WroXf9Ood33F4XzaZkpIm6f/Bjufgmhtu+5wy6jVS Z39deDJ3wlcZJZbijERDLeai4kQAVA26sWoCAAA= X-Env-Sender: julien.grall@arm.com X-Msg-Ref: server-4.tower-21.messagelabs.com!1469639387!19822774!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 51861 invoked from network); 27 Jul 2016 17:09:48 -0000 Received: from foss.arm.com (HELO foss.arm.com) (217.140.101.70) by server-4.tower-21.messagelabs.com with SMTP; 27 Jul 2016 17:09:48 -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 02837434; Wed, 27 Jul 2016 10:11:04 -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 5F23E3F213; Wed, 27 Jul 2016 10:09:46 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xen.org Date: Wed, 27 Jul 2016 18:09:34 +0100 Message-Id: <1469639378-9244-3-git-send-email-julien.grall@arm.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1469639378-9244-1-git-send-email-julien.grall@arm.com> References: <1469639378-9244-1-git-send-email-julien.grall@arm.com> Cc: sstabellini@kernel.org, steve.capper@arm.com, andre.przywara@arm.com, Julien Grall , wei.chen@linaro.org Subject: [Xen-devel] [PATCH v2 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" X-Virus-Scanned: ClamAV using ClamSMTP 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: