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

[Xen-devel] [PATCH 3/5] x86/livepatch: Use text_poke() and plumb a live parameter through



Update text_poke() to return void (rather than void *), take a live parameter,
and export it for arch_livepatch_apply() to use.

arch_livepatch_apply() can therefore lose its noinline for i-cache safey, as
text_poke() is doing the heavy lifting.

Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
---
CC: Jan Beulich <JBeulich@xxxxxxxx>
CC: Konrad Rzeszutek Wilk <konrad.wilk@xxxxxxxxxx>
CC: Ross Lagerwall <ross.lagerwall@xxxxxxxxxx>
---
 xen/arch/x86/alternative.c        | 9 +++++----
 xen/arch/x86/livepatch.c          | 8 ++------
 xen/include/asm-x86/alternative.h | 2 ++
 3 files changed, 9 insertions(+), 10 deletions(-)

diff --git a/xen/arch/x86/alternative.c b/xen/arch/x86/alternative.c
index 5b3fb80..0b309c3 100644
--- a/xen/arch/x86/alternative.c
+++ b/xen/arch/x86/alternative.c
@@ -136,6 +136,7 @@ void init_or_livepatch add_nops(void *insns, unsigned int 
len)
  * @addr: address to modify
  * @opcode: source of the copy
  * @len: length to copy
+ * @live: whether @addr is liable to be executed during patching
  *
  * When you use this code to patch more than one byte of an instruction
  * you need to make sure that other CPUs cannot execute this code in parallel.
@@ -149,10 +150,10 @@ void init_or_livepatch add_nops(void *insns, unsigned int 
len)
  * "noinline" to cause control flow change and thus invalidate I$ and
  * cause refetch after modification.
  */
-static void *init_or_livepatch noinline
-text_poke(void *addr, const void *opcode, size_t len)
+void init_or_livepatch noinline
+text_poke(void *addr, const void *opcode, size_t len, bool live)
 {
-    return memcpy(addr, opcode, len);
+    memcpy(addr, opcode, len);
 }
 
 /*
@@ -199,7 +200,7 @@ void init_or_livepatch apply_alternatives(const struct 
alt_instr *start,
 
         add_nops(insnbuf + a->replacementlen,
                  a->instrlen - a->replacementlen);
-        text_poke(instr, insnbuf, a->instrlen);
+        text_poke(instr, insnbuf, a->instrlen, live);
     }
 }
 
diff --git a/xen/arch/x86/livepatch.c b/xen/arch/x86/livepatch.c
index 406eb91..e624474 100644
--- a/xen/arch/x86/livepatch.c
+++ b/xen/arch/x86/livepatch.c
@@ -46,11 +46,7 @@ int arch_livepatch_verify_func(const struct livepatch_func 
*func)
     return 0;
 }
 
-/*
- * "noinline" to cause control flow change and thus invalidate I$ and
- * cause refetch after modification.
- */
-void noinline arch_livepatch_apply(struct livepatch_func *func)
+void arch_livepatch_apply(struct livepatch_func *func)
 {
     uint8_t *old_ptr;
     uint8_t insn[sizeof(func->opaque)];
@@ -76,7 +72,7 @@ void noinline arch_livepatch_apply(struct livepatch_func 
*func)
     else
         add_nops(insn, len);
 
-    memcpy(old_ptr, insn, len);
+    text_poke(old_ptr, insn, len, true);
 }
 
 /*
diff --git a/xen/include/asm-x86/alternative.h 
b/xen/include/asm-x86/alternative.h
index 07ff424..2d7cca5 100644
--- a/xen/include/asm-x86/alternative.h
+++ b/xen/include/asm-x86/alternative.h
@@ -20,6 +20,8 @@ struct alt_instr {
 #define ALT_ORIG_PTR(a)     __ALT_PTR(a, instr_offset)
 #define ALT_REPL_PTR(a)     __ALT_PTR(a, repl_offset)
 
+extern void text_poke(void *addr, const void *opcode, size_t len, bool live);
+
 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,
-- 
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®.