From patchwork Wed Feb 3 12:39:05 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 8202041 Return-Path: X-Original-To: patchwork-xen-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 6151EBEEE5 for ; Wed, 3 Feb 2016 12:42:00 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 521B320148 for ; Wed, 3 Feb 2016 12:41:59 +0000 (UTC) Received: from lists.xen.org (lists.xenproject.org [50.57.142.19]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8A9A820266 for ; Wed, 3 Feb 2016 12:41:55 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xen.org) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aQwiH-0000EM-Lh; Wed, 03 Feb 2016 12:39:13 +0000 Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aQwiG-0000EB-QP for xen-devel@lists.xenproject.org; Wed, 03 Feb 2016 12:39:12 +0000 Received: from [193.109.254.147] by server-14.bemta-14.messagelabs.com id 1A/8C-07165-0F4F1B65; Wed, 03 Feb 2016 12:39:12 +0000 X-Env-Sender: JBeulich@suse.com X-Msg-Ref: server-14.tower-27.messagelabs.com!1454503148!21139839!1 X-Originating-IP: [137.65.248.74] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 7.35.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 60002 invoked from network); 3 Feb 2016 12:39:10 -0000 Received: from prv-mh.provo.novell.com (HELO prv-mh.provo.novell.com) (137.65.248.74) by server-14.tower-27.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 3 Feb 2016 12:39:10 -0000 Received: from INET-PRV-MTA by prv-mh.provo.novell.com with Novell_GroupWise; Wed, 03 Feb 2016 05:39:07 -0700 Message-Id: <56B202F902000078000CE038@prv-mh.provo.novell.com> X-Mailer: Novell GroupWise Internet Agent 14.2.0 Date: Wed, 03 Feb 2016 05:39:05 -0700 From: "Jan Beulich" To: "xen-devel" References: <56B2016102000078000CE005@prv-mh.provo.novell.com> In-Reply-To: <56B2016102000078000CE005@prv-mh.provo.novell.com> Mime-Version: 1.0 Cc: Andrew Cooper , Keir Fraser , Shuai Ruan Subject: [Xen-devel] [PATCH v2 1/2] x86: support 2- and 3-way alternatives X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Parts taken from Linux, but implementing the ALTERNATIVE*() macros recursively to avoid needless redundancy. Also make the .discard section non-writable (we might even consider dropping its alloc flag too) and limit the pushing and popping of sections. Signed-off-by: Jan Beulich x86: support 2- and 3-way alternatives Parts taken from Linux, but implementing the ALTERNATIVE*() macros recursively to avoid needless redundancy. Also make the .discard section non-writable (we might even consider dropping its alloc flag too) and limit the pushing and popping of sections. Signed-off-by: Jan Beulich --- a/xen/include/asm-x86/alternative.h +++ b/xen/include/asm-x86/alternative.h @@ -46,18 +46,28 @@ extern void alternative_instructions(voi #define ALTINSTR_REPLACEMENT(newinstr, feature, number) /* replacement */ \ b_replacement(number)":\n\t" newinstr "\n" e_replacement(number) ":\n\t" +#define ALTERNATIVE_N(newinstr, feature, number) \ + ".pushsection .altinstructions,\"a\"\n" \ + ALTINSTR_ENTRY(feature, number) \ + ".section .discard,\"a\",@progbits\n" \ + DISCARD_ENTRY(number) \ + ".section .altinstr_replacement, \"ax\"\n" \ + ALTINSTR_REPLACEMENT(newinstr, feature, number) \ + ".popsection\n" + /* alternative assembly primitive: */ -#define ALTERNATIVE(oldinstr, newinstr, feature) \ - OLDINSTR(oldinstr) \ - ".pushsection .altinstructions,\"a\"\n" \ - ALTINSTR_ENTRY(feature, 1) \ - ".popsection\n" \ - ".pushsection .discard,\"aw\",@progbits\n" \ - DISCARD_ENTRY(1) \ - ".popsection\n" \ - ".pushsection .altinstr_replacement, \"ax\"\n" \ - ALTINSTR_REPLACEMENT(newinstr, feature, 1) \ - ".popsection" +#define ALTERNATIVE(oldinstr, newinstr, feature) \ + OLDINSTR(oldinstr) \ + ALTERNATIVE_N(newinstr, feature, 1) + +#define ALTERNATIVE_2(oldinstr, newinstr1, feature1, newinstr2, feature2) \ + ALTERNATIVE(oldinstr, newinstr1, feature1) \ + ALTERNATIVE_N(newinstr2, feature2, 2) + +#define ALTERNATIVE_3(oldinstr, newinstr1, feature1, newinstr2, feature2, \ + newinstr3, feature3) \ + ALTERNATIVE_2(oldinstr, newinstr1, feature1, newinstr2, feature2) \ + ALTERNATIVE_N(newinstr3, feature3, 3) /* * Alternative instructions for different CPU types or capabilities. @@ -93,6 +103,37 @@ extern void alternative_instructions(voi asm volatile (ALTERNATIVE(oldinstr, newinstr, feature) \ : output : input) +/* + * This is similar to alternative_io. But it has two features and + * respective instructions. + * + * If CPU has feature2, newinstr2 is used. + * Otherwise, if CPU has feature1, newinstr1 is used. + * Otherwise, oldinstr is used. + */ +#define alternative_io_2(oldinstr, newinstr1, feature1, newinstr2, \ + feature2, output, input...) \ + asm volatile(ALTERNATIVE_2(oldinstr, newinstr1, feature1, \ + newinstr2, feature2) \ + : output : input) + +/* + * This is similar to alternative_io. But it has three features and + * respective instructions. + * + * If CPU has feature3, newinstr3 is used. + * Otherwise, if CPU has feature2, newinstr2 is used. + * Otherwise, if CPU has feature1, newinstr1 is used. + * Otherwise, oldinstr is used. + */ +#define alternative_io_3(oldinstr, newinstr1, feature1, newinstr2, \ + feature2, newinstr3, feature3, output, \ + input...) \ + asm volatile(ALTERNATIVE_3(oldinstr, newinstr1, feature1, \ + newinstr2, feature2, newinstr3, \ + feature3) \ + : output : input) + /* Use this macro(s) if you need more than one output parameter. */ #define ASM_OUTPUT2(a...) a Reviewed-by: Andrew Cooper --- a/xen/include/asm-x86/alternative.h +++ b/xen/include/asm-x86/alternative.h @@ -46,18 +46,28 @@ extern void alternative_instructions(voi #define ALTINSTR_REPLACEMENT(newinstr, feature, number) /* replacement */ \ b_replacement(number)":\n\t" newinstr "\n" e_replacement(number) ":\n\t" +#define ALTERNATIVE_N(newinstr, feature, number) \ + ".pushsection .altinstructions,\"a\"\n" \ + ALTINSTR_ENTRY(feature, number) \ + ".section .discard,\"a\",@progbits\n" \ + DISCARD_ENTRY(number) \ + ".section .altinstr_replacement, \"ax\"\n" \ + ALTINSTR_REPLACEMENT(newinstr, feature, number) \ + ".popsection\n" + /* alternative assembly primitive: */ -#define ALTERNATIVE(oldinstr, newinstr, feature) \ - OLDINSTR(oldinstr) \ - ".pushsection .altinstructions,\"a\"\n" \ - ALTINSTR_ENTRY(feature, 1) \ - ".popsection\n" \ - ".pushsection .discard,\"aw\",@progbits\n" \ - DISCARD_ENTRY(1) \ - ".popsection\n" \ - ".pushsection .altinstr_replacement, \"ax\"\n" \ - ALTINSTR_REPLACEMENT(newinstr, feature, 1) \ - ".popsection" +#define ALTERNATIVE(oldinstr, newinstr, feature) \ + OLDINSTR(oldinstr) \ + ALTERNATIVE_N(newinstr, feature, 1) + +#define ALTERNATIVE_2(oldinstr, newinstr1, feature1, newinstr2, feature2) \ + ALTERNATIVE(oldinstr, newinstr1, feature1) \ + ALTERNATIVE_N(newinstr2, feature2, 2) + +#define ALTERNATIVE_3(oldinstr, newinstr1, feature1, newinstr2, feature2, \ + newinstr3, feature3) \ + ALTERNATIVE_2(oldinstr, newinstr1, feature1, newinstr2, feature2) \ + ALTERNATIVE_N(newinstr3, feature3, 3) /* * Alternative instructions for different CPU types or capabilities. @@ -93,6 +103,37 @@ extern void alternative_instructions(voi asm volatile (ALTERNATIVE(oldinstr, newinstr, feature) \ : output : input) +/* + * This is similar to alternative_io. But it has two features and + * respective instructions. + * + * If CPU has feature2, newinstr2 is used. + * Otherwise, if CPU has feature1, newinstr1 is used. + * Otherwise, oldinstr is used. + */ +#define alternative_io_2(oldinstr, newinstr1, feature1, newinstr2, \ + feature2, output, input...) \ + asm volatile(ALTERNATIVE_2(oldinstr, newinstr1, feature1, \ + newinstr2, feature2) \ + : output : input) + +/* + * This is similar to alternative_io. But it has three features and + * respective instructions. + * + * If CPU has feature3, newinstr3 is used. + * Otherwise, if CPU has feature2, newinstr2 is used. + * Otherwise, if CPU has feature1, newinstr1 is used. + * Otherwise, oldinstr is used. + */ +#define alternative_io_3(oldinstr, newinstr1, feature1, newinstr2, \ + feature2, newinstr3, feature3, output, \ + input...) \ + asm volatile(ALTERNATIVE_3(oldinstr, newinstr1, feature1, \ + newinstr2, feature2, newinstr3, \ + feature3) \ + : output : input) + /* Use this macro(s) if you need more than one output parameter. */ #define ASM_OUTPUT2(a...) a