From patchwork Wed Jun 22 13:21:05 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 9192763 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 517026075A for ; Wed, 22 Jun 2016 13:23:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4287C283F7 for ; Wed, 22 Jun 2016 13:23:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 36DEC28406; Wed, 22 Jun 2016 13:23:29 +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 D78AB283F7 for ; Wed, 22 Jun 2016 13:23:28 +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 1bFi5v-000197-Bq; Wed, 22 Jun 2016 13:21:27 +0000 Received: from mail6.bemta6.messagelabs.com ([85.158.143.247]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bFi5u-00016i-4B for xen-devel@lists.xen.org; Wed, 22 Jun 2016 13:21:26 +0000 Received: from [85.158.143.35] by server-2.bemta-6.messagelabs.com id C7/B2-11548-5D09A675; Wed, 22 Jun 2016 13:21:25 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrMLMWRWlGSWpSXmKPExsVysyfVTffqhKx wg3WrpSyWfFzM4sDocXT3b6YAxijWzLyk/IoE1ozNh/wKXkpU3DvXydzAeJqvi5GLQ0hgE6PE 8R/drF2MnEDOaUaJV3/zQGw2AU2JO58/MYHYIgLSEtc+X2YEaWAWaGOUWDt7KiNIQlggQOLTh k3sXYwcHCwCqhILz8WCmLwCLhKbt6uDVEgIyEmcPDYZbDyngKvE//NNUKtcJNZ9Ps86gZF7AS PDKkb14tSistQiXWO9pKLM9IyS3MTMHF1DAzO93NTi4sT01JzEpGK95PzcTYxAzzIAwQ7Gjn9 OhxglOZiURHnllbPChfiS8lMqMxKLM+KLSnNSiw8xynBwKEnwuvYD5QSLUtNTK9Iyc4AhBpOW 4OBREuGNBEnzFhck5hZnpkOkTjEqSonz1oAkBEASGaV5cG2wsL7EKCslzMsIdIgQT0FqUW5mC ar8K0ZxDkYlYV4FkCk8mXklcNNfAS1mAlq8rD8dZHFJIkJKqoFx8Y1rz97FzsvWCkv/lTfz2M 5ZOsX5des4N3Se5xe1WOH7n+Fu7xetAsXWZHsNsxsKJ31my4T1Tv2VsGRiw1TVPaGph/6wrGO c2npYefeuTav2XIl/1/XkdicfY0DK2pNRjNJq/yqF175UniFqqr5Mc5XAHjfh7juuOp3JmxnD /a9NOMy5PElHiaU4I9FQi7moOBEAVBU2EGYCAAA= X-Env-Sender: julien.grall@arm.com X-Msg-Ref: server-2.tower-21.messagelabs.com!1466601683!6353330!2 X-Originating-IP: [217.140.101.70] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 8.46; banners=-,-,- X-VirusChecked: Checked Received: (qmail 51587 invoked from network); 22 Jun 2016 13:21:25 -0000 Received: from foss.arm.com (HELO foss.arm.com) (217.140.101.70) by server-2.tower-21.messagelabs.com with SMTP; 22 Jun 2016 13:21:25 -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 E1E2F440; Wed, 22 Jun 2016 06:22:11 -0700 (PDT) Received: from e108454-lin.cambridge.arm.com (e108454-lin.cambridge.arm.com [10.1.215.28]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id CA1303F21A; Wed, 22 Jun 2016 06:21:23 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xen.org Date: Wed, 22 Jun 2016 14:21:05 +0100 Message-Id: <1466601669-25398-6-git-send-email-julien.grall@arm.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1466601669-25398-1-git-send-email-julien.grall@arm.com> References: <1466601669-25398-1-git-send-email-julien.grall@arm.com> Cc: andre.przywara@arm.com, Julien Grall , sstabellini@kernel.org, steve.capper@arm.com, wei.chen@linaro.org Subject: [Xen-devel] [PATCH 5/9] 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 --- 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 fe93beb..b9d8dfc 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: