Skip to contentSkip to conversation

xen/arm: livepatch: Prevent CPUs to fetch stale instructions after livepatching

PATCH In review Julien Grall 3 participants 3 messages Sep 18, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xen/arm: livepatch: Prevent CPUs to fetch stale instructions after livepatching

During livepatch, a single CPU will take care of applying the patch and all the others will wait for the action to complete. They will then once execute arch_livepatch_post_action() to flush the pipeline.

Per B2.2.5 "Concurrent modification and execution of instructions" in DDI 0487E.a, flushing the instruction cache is not enough to ensure new instructions are seen. All the PEs should also do an isb() to synchronize the fetched instruction stream.

---
 xen/arch/arm/livepatch.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
xen/arch/arm/livepatch.c +2 -1
index 279d52cc6c..00c5e2bc45 100644
@@ -88,7 +88,8 @@ void arch_livepatch_revert(const struct livepatch_func *func)
 
 void arch_livepatch_post_action(void)
 {
-    /* arch_livepatch_revive has nuked the instruction cache. */
+    /* Discard any stale instructions that may have been fetched. */
+    isb();
 }
 
 void arch_livepatch_mask(void)
Signature · 7 lines
2.11.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Acked-by on v1 1/1
#1 lore raw
Quoted 20 lines · Julien Grall

During livepatch, a single CPU will take care of applying the patch and all the others will wait for the action to complete. They will then once execute arch_livepatch_post_action() to flush the pipeline.

Per B2.2.5 "Concurrent modification and execution of instructions" in DDI 0487E.a, flushing the instruction cache is not enough to ensure new instructions are seen. All the PEs should also do an isb() to synchronize the fetched instruction stream.

---
  xen/arch/arm/livepatch.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
xen/arch/arm/livepatch.c +0 -0
index 279d52cc6c..00c5e2bc45 100644

xen/arch/arm/livepatch.c void arch_livepatch_revert(const struct livepatch_func *func) · line 95

Quoted 9 lines
xen/arch/arm/livepatch.c +2 -1
@@ -88,7 +88,8 @@ void arch_livepatch_revert(const struct livepatch_func *func)
 
  void arch_livepatch_post_action(void)
  {
-    /* arch_livepatch_revive has nuked the instruction cache. */
+    /* Discard any stale instructions that may have been fetched. */
+    isb();
  }
 
  void arch_livepatch_mask(void)

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

Reviewed-by on v1 1/1
#2 lore raw
In reply to Julien Grall

Hi Julien,

Quoted 10 lines · Julien Grall

During livepatch, a single CPU will take care of applying the patch and all the others will wait for the action to complete. They will then once execute arch_livepatch_post_action() to flush the pipeline.

Per B2.2.5 "Concurrent modification and execution of instructions" in DDI 0487E.a, flushing the instruction cache is not enough to ensure new instructions are seen. All the PEs should also do an isb() to synchronize the fetched instruction stream.

Quoted 18 lines
---
 xen/arch/arm/livepatch.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
xen/arch/arm/livepatch.c +2 -1
index 279d52cc6c..00c5e2bc45 100644
@@ -88,7 +88,8 @@ void arch_livepatch_revert(const struct livepatch_func *func)
 
 void arch_livepatch_post_action(void)
 {
-    /* arch_livepatch_revive has nuked the instruction cache. */
+    /* Discard any stale instructions that may have been fetched. */
+    isb();
 }
 
 void arch_livepatch_mask(void)
Signature · 5 lines
Volodymyr Babchuk at EPAM
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel