Skip to contentSkip to conversation

x86/asm: ELF metadata for simple cases

PATCH In review Andrew Cooper 3 participants 5 messages Feb 20, 2023 – Feb 24, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/asm: ELF metadata for simple cases

This is generally good practice, and necessary for livepatch binary diffing to work.

With this, livepatching of the SVM entry path works. The only complication is with svm_stgi_label which is only used by oprofile to guestimate (not completely correctly) when an NMI hit guest context.

Livepatching of VMX is still an open question, because the logic doesn't form anything remotely resembling functions. Both code fragments jump into each other so need to be updated in tandem. Also, both code fragment entries need trampolines in the case that patching actually occurs. For now, just treat it as a single function.

---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Wei Liu <[email protected]>
CC: Konrad Rzeszutek Wilk <[email protected]>
CC: Ross Lagerwall <[email protected]>

---
 xen/arch/x86/clear_page.S    | 3 +++
 xen/arch/x86/copy_page.S     | 3 +++
 xen/arch/x86/hvm/svm/entry.S | 3 +++
 xen/arch/x86/hvm/vmx/entry.S | 3 +++
 4 files changed, 12 insertions(+)
xen/arch/x86/clear_page.S +3 -0
index d9d524c79ecd..5b5622cc526f 100644
@@ -16,3 +16,6 @@ ENTRY(clear_page_sse2)
 
         sfence
         ret
+
+        .type clear_page_sse2, @function
+        .size clear_page_sse2, . - clear_page_sse2
xen/arch/x86/copy_page.S +3 -0
index 2da81126c5fa..ddb6e0ebbb6e 100644
@@ -41,3 +41,6 @@ ENTRY(copy_page_sse2)
 
         sfence
         ret
+
+        .type copy_page_sse2, @function
+        .size copy_page_sse2, . - copy_page_sse2
xen/arch/x86/hvm/svm/entry.S +3 -0
index 981cd82e7c0b..9e3dab768027 100644
@@ -142,3 +142,6 @@ GLOBAL(svm_stgi_label)
         sti
         call do_softirq
         jmp  .Lsvm_do_resume
+
+        .type svm_asm_do_resume, @function
+        .size svm_asm_do_resume, . - svm_asm_do_resume
xen/arch/x86/hvm/vmx/entry.S +3 -0
index 5f5de45a1309..e3f60d5a82f7 100644
@@ -150,3 +150,6 @@ ENTRY(vmx_asm_do_vmentry)
         sti
         call do_softirq
         jmp  .Lvmx_do_vmentry
+
+        .type vmx_asm_vmexit_handler, @function
+        .size vmx_asm_vmexit_handler, . - vmx_asm_vmexit_handler
Signature · 1 line
2.30.2
#1 lore raw
Quoted 13 lines

From: Andrew Cooper <[email protected]>
Sent: Monday, February 20, 2023 11:04 AM
To: Xen-devel <[email protected]>
Cc: Andrew Cooper <[email protected]>; Jan Beulich <[email protected]>; Roger Pau Monne <[email protected]>; Wei Liu <[email protected]>; Konrad Rzeszutek Wilk <[email protected]>; Ross Lagerwall <[email protected]>
Subject: [PATCH] x86/asm: ELF metadata for simple cases

This is generally good practice, and necessary for livepatch binary diffing to
work.

With this, livepatching of the SVM entry path works.  The only complication is with svm_stgi_label which is only used by oprofile to guestimate (not completely correctly) when an NMI hit guest context.

Quoted 5 lines

Livepatching of VMX is still an open question, because the logic doesn't form anything remotely resembling functions.  Both code fragments jump into each other so need to be updated in tandem.  Also, both code fragment entries need trampolines in the case that patching actually occurs.  For now, just treat it as a single function.

If it is treated as two functions and both functions are always included in the live patch, would that work?

Quoted 20 lines

---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Wei Liu <[email protected]>
CC: Konrad Rzeszutek Wilk <[email protected]>
CC: Ross Lagerwall <[email protected]>
---
 xen/arch/x86/clear_page.S    | 3 +++ xen/arch/x86/copy_page.S     | 3 +++ xen/arch/x86/hvm/svm/entry.S | 3 +++ xen/arch/x86/hvm/vmx/entry.S | 3 +++

 4 files changed, 12 insertions(+)
xen/arch/x86/clear_page.S +0 -0
index d9d524c79ecd..5b5622cc526f 100644
@@ -16,3 +16,6 @@ ENTRY(clear_page_sse2)
Quoted 6 lines


         sfence
         ret
+
+        .type clear_page_sse2, @function
+        .size clear_page_sse2, . - clear_page_sse2

Would it be worth wrapping this pattern in a macro?

Ross

#2 lore raw
Quoted 11 lines · Ross Lagerwall
Quoted 9 lines
xen/arch/x86/clear_page.S +0 -0
@@ -16,3 +16,6 @@ ENTRY(clear_page_sse2)


         sfence
         ret
+
+        .type clear_page_sse2, @function
+        .size clear_page_sse2, . - clear_page_sse2

Would it be worth wrapping this pattern in a macro?

Funny you should ask this: Yes, certainly, but we can't quite agree what shape that macro (or really set of macros) is to take. Hence we did agree on this minimalistic approach as an intermediate solution.

Jan

#3 lore raw
In reply to Ross Lagerwall
Quoted 13 lines · Ross Lagerwall
Quoted 13 lines

From: Andrew Cooper <[email protected]>
Sent: Monday, February 20, 2023 11:04 AM
To: Xen-devel <[email protected]>
Cc: Andrew Cooper <[email protected]>; Jan Beulich <[email protected]>; Roger Pau Monne <[email protected]>; Wei Liu <[email protected]>; Konrad Rzeszutek Wilk <[email protected]>; Ross Lagerwall <[email protected]>
Subject: [PATCH] x86/asm: ELF metadata for simple cases

This is generally good practice, and necessary for livepatch binary diffing to
work.

With this, livepatching of the SVM entry path works.  The only complication is with svm_stgi_label which is only used by oprofile to guestimate (not completely correctly) when an NMI hit guest context.

Quoted 7 lines
Quoted 5 lines

Livepatching of VMX is still an open question, because the logic doesn't form anything remotely resembling functions.  Both code fragments jump into each other so need to be updated in tandem.  Also, both code fragment entries need trampolines in the case that patching actually occurs.  For now, just treat it as a single function.

If it is treated as two functions and both functions are always included in the live patch, would that work?

I think so, but only because the first jumped-to label in vmx_asm_do_vmentry is beyond the trampoline.

But I guess the question is how to tie the two symbols together.  We don't want to be hardcoding this in livepatch-build-tools IMO.

Perhaps we want a CONFIG_LIVEPATCH build of Xen to include a section/note/something identifying "grouped symbols", meaning "if there's a delta in one, include all even if they haven't changed" ?

I'm getting the distinct impression that we're going to need it it for the PV entry/exit paths too.

~Andrew

Acked-by on v1 1/1
#4 lore raw
In reply to Andrew Cooper
Quoted 7 lines · Andrew Cooper

This is generally good practice, and necessary for livepatch binary diffing to work.

With this, livepatching of the SVM entry path works. The only complication is with svm_stgi_label which is only used by oprofile to guestimate (not completely correctly) when an NMI hit guest context.

Quoted 5 lines

Livepatching of VMX is still an open question, because the logic doesn't form anything remotely resembling functions. Both code fragments jump into each other so need to be updated in tandem. Also, both code fragment entries need trampolines in the case that patching actually occurs. For now, just treat it as a single function.

I agree.

Quoted 1 line