[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH 2/5] xen/alternatives: Plumb a 'live' parameter through apply_alternatives()



On x86, we would like to alter how we patch based on whether there is any
chance of the code being patched being concurrently executed.

prepare_payload() passes false (as the livepatch definitely isn't live at this
point), whereas the boot-time alternatives application passes true.

Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
---
CC: Jan Beulich <JBeulich@xxxxxxxx>
CC: Stefano Stabellini <sstabellini@xxxxxxxxxx>
CC: Julien Grall <julien.grall@xxxxxxx>
CC: Konrad Rzeszutek Wilk <konrad.wilk@xxxxxxxxxx>
CC: Ross Lagerwall <ross.lagerwall@xxxxxxxxxx>
---
 xen/arch/arm/alternative.c        | 10 ++++++----
 xen/arch/x86/alternative.c        |  5 +++--
 xen/common/livepatch.c            |  2 +-
 xen/include/asm-arm/alternative.h |  6 ++++--
 xen/include/asm-x86/alternative.h |  3 ++-
 5 files changed, 16 insertions(+), 10 deletions(-)

diff --git a/xen/arch/arm/alternative.c b/xen/arch/arm/alternative.c
index 99112e1..078b259 100644
--- a/xen/arch/arm/alternative.c
+++ b/xen/arch/arm/alternative.c
@@ -98,7 +98,8 @@ static u32 get_alt_insn(const struct alt_instr *alt,
  * The region patched should be read-write to allow __apply_alternatives
  * to replacing the instructions when necessary.
  */
-static void __apply_alternatives(const struct alt_region *region)
+static void __apply_alternatives(const struct alt_region *region,
+                                 bool live)
 {
     const struct alt_instr *alt;
     const u32 *replptr;
@@ -193,7 +194,7 @@ static int __init __apply_alternatives_multi_stop(void 
*unused)
         region.begin = (void *)__alt_instructions - (void *)_start + xenmap;
         region.end = (void *)__alt_instructions_end - (void *)_start + xenmap;
 
-        __apply_alternatives(&region);
+        __apply_alternatives(&region, true);
 
         unregister_virtual_region(&patch_region);
 
@@ -224,14 +225,15 @@ void __init apply_alternatives_all(void)
 }
 
 void apply_alternatives(const struct alt_instr *start,
-                        const struct alt_instr *end)
+                        const struct alt_instr *end,
+                        bool live)
 {
     const struct alt_region region = {
         .begin = start,
         .end = end,
     };
 
-    __apply_alternatives(&region);
+    __apply_alternatives(&region, live);
 }
 
 /*
diff --git a/xen/arch/x86/alternative.c b/xen/arch/x86/alternative.c
index ee18e6c..5b3fb80 100644
--- a/xen/arch/x86/alternative.c
+++ b/xen/arch/x86/alternative.c
@@ -163,7 +163,8 @@ text_poke(void *addr, const void *opcode, size_t len)
  * Tough. Make sure you disable such features by hand.
  */
 void init_or_livepatch apply_alternatives(const struct alt_instr *start,
-                                          const struct alt_instr *end)
+                                          const struct alt_instr *end,
+                                          bool live)
 {
     const struct alt_instr *a;
     u8 *instr, *replacement;
@@ -235,7 +236,7 @@ void __init alternative_instructions(void)
     /* Disable WP to allow application of alternatives to read-only pages. */
     write_cr0(cr0 & ~X86_CR0_WP);
 
-    apply_alternatives(__alt_instructions, __alt_instructions_end);
+    apply_alternatives(__alt_instructions, __alt_instructions_end, true);
 
     /* Reinstate WP. */
     write_cr0(cr0);
diff --git a/xen/common/livepatch.c b/xen/common/livepatch.c
index b9376c9..6f03e89 100644
--- a/xen/common/livepatch.c
+++ b/xen/common/livepatch.c
@@ -682,7 +682,7 @@ static int prepare_payload(struct payload *payload,
                 return -EINVAL;
             }
         }
-        apply_alternatives(start, end);
+        apply_alternatives(start, end, false);
 #else
         dprintk(XENLOG_ERR, LIVEPATCH "%s: We don't support alternative 
patching!\n",
                 elf->name);
diff --git a/xen/include/asm-arm/alternative.h 
b/xen/include/asm-arm/alternative.h
index 49a055e..77b0944 100644
--- a/xen/include/asm-arm/alternative.h
+++ b/xen/include/asm-arm/alternative.h
@@ -26,7 +26,8 @@ struct alt_instr {
 
 void __init apply_alternatives_all(void);
 void apply_alternatives(const struct alt_instr *start,
-                        const struct alt_instr *end);
+                        const struct alt_instr *end,
+                        bool live);
 
 #define ALTINSTR_ENTRY(feature)                                                
      \
        " .word 661b - .\n"                             /* label           */ \
@@ -160,7 +161,8 @@ static inline void apply_alternatives_all(void)
 }
 
 static inline void apply_alternatives(const struct alt_instr *start,
-                                      const struct alt_instr *end)
+                                      const struct alt_instr *end,
+                                      bool live)
 {
 }
 
diff --git a/xen/include/asm-x86/alternative.h 
b/xen/include/asm-x86/alternative.h
index ba537d6..07ff424 100644
--- a/xen/include/asm-x86/alternative.h
+++ b/xen/include/asm-x86/alternative.h
@@ -23,7 +23,8 @@ struct alt_instr {
 extern void add_nops(void *insns, unsigned int len);
 /* Similar to alternative_instructions except it can be run with IRQs enabled. 
*/
 extern void apply_alternatives(const struct alt_instr *start,
-                               const struct alt_instr *end);
+                               const struct alt_instr *end,
+                               bool live);
 extern void alternative_instructions(void);
 
 #define OLDINSTR(oldinstr)      "661:\n\t" oldinstr "\n662:\n"
-- 
2.1.4


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.