All of lore.kernel.org
 help / color / mirror / Atom feed
From: Shuai Ruan <shuai.ruan@linux.intel.com>
To: xen-devel@lists.xen.org
Cc: andrew.cooper3@citrix.com, keir@xen.org, jbeulich@suse.com
Subject: [PATCH 1/2] x86: add alternavive_io_2/3 to support alternative with 2/3 features.
Date: Tue,  2 Feb 2016 15:11:03 +0800	[thread overview]
Message-ID: <1454397064-29268-2-git-send-email-shuai.ruan@linux.intel.com> (raw)
In-Reply-To: <1454397064-29268-1-git-send-email-shuai.ruan@linux.intel.com>

Most of the code is porting from linux with some changes.
alternative_io_2 replaces old instruction with new instructions
based on two features.
alternative_io_3 replaces old instruction with new instructions
based on three features.

Signed-off-by: Shuai Ruan <shuai.ruan@linux.intel.com>
---
 xen/include/asm-x86/alternative.h | 65 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 65 insertions(+)

diff --git a/xen/include/asm-x86/alternative.h b/xen/include/asm-x86/alternative.h
index 7d11354..b018613 100644
--- a/xen/include/asm-x86/alternative.h
+++ b/xen/include/asm-x86/alternative.h
@@ -59,6 +59,39 @@ extern void alternative_instructions(void);
         ALTINSTR_REPLACEMENT(newinstr, feature, 1)                      \
         ".popsection"
 
+#define ALTERNATIVE_2(oldinstr, newinstr1, feature1, newinstr2, feature2) \
+        OLDINSTR(oldinstr)                                                \
+        ".pushsection .altinstructions,\"a\"\n"                           \
+        ALTINSTR_ENTRY(feature1, 1)                                       \
+        ALTINSTR_ENTRY(feature2, 2)                                       \
+        ".popsection\n"                                                   \
+        ".pushsection .discard,\"aw\",@progbits\n"                        \
+        DISCARD_ENTRY(1)                                                  \
+        DISCARD_ENTRY(2)                                                  \
+        ".popsection\n"                                                   \
+        ".pushsection .altinstr_replacement, \"ax\"\n"                    \
+        ALTINSTR_REPLACEMENT(newinstr1, feature1, 1)                      \
+        ALTINSTR_REPLACEMENT(newinstr2, feature2, 2)                      \
+        ".popsection"
+
+#define ALTERNATIVE_3(oldinstr, newinstr1, feature1, newinstr2, feature2, \
+                      newinstr3, feature3)                                \
+        OLDINSTR(oldinstr)                                                \
+        ".pushsection .altinstructions,\"a\"\n"                           \
+        ALTINSTR_ENTRY(feature1, 1)                                       \
+        ALTINSTR_ENTRY(feature2, 2)                                       \
+        ALTINSTR_ENTRY(feature3, 3)                                       \
+        ".popsection\n"                                                   \
+        ".pushsection .discard,\"aw\",@progbits\n"                        \
+        DISCARD_ENTRY(1)                                                  \
+        DISCARD_ENTRY(2)                                                  \
+        DISCARD_ENTRY(3)                                                  \
+        ".popsection\n"                                                   \
+        ".pushsection .altinstr_replacement, \"ax\"\n"                    \
+        ALTINSTR_REPLACEMENT(newinstr1, feature1, 1)                      \
+        ALTINSTR_REPLACEMENT(newinstr2, feature2, 2)                      \
+        ALTINSTR_REPLACEMENT(newinstr3, feature3, 3)                      \
+        ".popsection"
 /*
  * Alternative instructions for different CPU types or capabilities.
  *
@@ -93,6 +126,38 @@ extern void alternative_instructions(void);
 	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.
+ *  if CPU has feature1, newinstr1 is used.
+ *  Otherwise, oldinstr is used.
+ */
+
+#define alternative_io_2(oldinstr, newinstr1, feature1, newinstr2,       \
+                         feature2, out_put, 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.
+ *  If CPU has feature2, newinstr2 is used.
+ *  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
 
-- 
1.9.1

  reply	other threads:[~2016-02-02  7:11 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-02  7:11 [PATCH 0/2] use alternative asm on xsave side Shuai Ruan
2016-02-02  7:11 ` Shuai Ruan [this message]
2016-02-02  7:11 ` [PATCH 2/2] x86/xsave: " Shuai Ruan
2016-02-03 11:40   ` Jan Beulich
2016-02-03 12:08     ` Jan Beulich

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1454397064-29268-2-git-send-email-shuai.ruan@linux.intel.com \
    --to=shuai.ruan@linux.intel.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=jbeulich@suse.com \
    --cc=keir@xen.org \
    --cc=xen-devel@lists.xen.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.