Skip to contentSkip to conversation

livepatch: apply_alternatives() is only used for livepatch

PATCH In review Roger Pau Monne 3 participants 7 messages Jun 7, 2023

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 livepatch: apply_alternatives() is only used for livepatch

Guard it with CONFIG_LIVEPATCH. Note alternatives are applied at boot using _apply_alternatives().

---
Changes since v1:
- Do not guard function prototypes.
---
Andrew raised a valid point of moving the prototype to a common header, but since I'm not longer touching the prototypes I'm not introducing such header here.

---
 xen/arch/arm/alternative.c | 2 ++
 xen/arch/x86/alternative.c | 5 +++--
 2 files changed, 5 insertions(+), 2 deletions(-)
xen/arch/arm/alternative.c +2 -0
index 7366af4ea646..016e66978b6d 100644
@@ -223,6 +223,7 @@ void __init apply_alternatives_all(void)
     vunmap(xenmap);
 }
 
+#ifdef CONFIG_LIVEPATCH
 int apply_alternatives(const struct alt_instr *start, const struct alt_instr *end)
 {
     const struct alt_region region = {
@@ -232,6 +233,7 @@ int apply_alternatives(const struct alt_instr *start, const struct alt_instr *en
 
     return __apply_alternatives(&region, 0);
 }
+#endif
 
 /*
  * Local variables:
xen/arch/x86/alternative.c +3 -2
index 99482766b51f..21af0e825822 100644
@@ -358,11 +358,12 @@ static void init_or_livepatch _apply_alternatives(struct alt_instr *start,
     }
 }
 
-void init_or_livepatch apply_alternatives(struct alt_instr *start,
-                                          struct alt_instr *end)
+#ifdef CONFIG_LIVEPATCH
+void apply_alternatives(struct alt_instr *start, struct alt_instr *end)
 {
     _apply_alternatives(start, end, true);
 }
+#endif
 
 static unsigned int __initdata alt_todo;
 static unsigned int __initdata alt_done;
Signature · 1 line
2.40.0
Reviewed-by on v2 1/1
#1 lore raw
Quoted 5 lines · Roger Pau Monne

Guard it with CONFIG_LIVEPATCH. Note alternatives are applied at boot using _apply_alternatives().

albeit the implicit ack therein is only on the assumption that (apart from me) it is generally deemed better ...

xen/arch/x86/alternative.c static void init_or_livepatch _apply_alternatives(struct alt_instr *start, · line 361

Quoted 9 lines
xen/arch/x86/alternative.c +1 -2
@@ -358,11 +358,12 @@ static void init_or_livepatch _apply_alternatives(struct alt_instr *start,
     }
 }
 
-void init_or_livepatch apply_alternatives(struct alt_instr *start,
-                                          struct alt_instr *end)
+#ifdef CONFIG_LIVEPATCH

... to have the #ifdef than the init_or_livepatch attribute.

Jan

Quoted 8 lines
xen/arch/x86/alternative.c +2 -0
+void apply_alternatives(struct alt_instr *start, struct alt_instr *end)
 {
     _apply_alternatives(start, end, true);
 }
+#endif
 
 static unsigned int __initdata alt_todo;
 static unsigned int __initdata alt_done;
#2 lore raw
Quoted 17 lines · Jan Beulich
Quoted 5 lines · Roger Pau Monne

Guard it with CONFIG_LIVEPATCH. Note alternatives are applied at boot using _apply_alternatives().

albeit the implicit ack therein is only on the assumption that (apart from me) it is generally deemed better ...

Quoted 6 lines
xen/arch/x86/alternative.c +0 -0
@@ -358,11 +358,12 @@ static void init_or_livepatch _apply_alternatives(struct alt_instr *start,
     }
 }
 
Quoted 5 lines

xen/arch/x86/alternative.c static void init_or_livepatch _apply_alternatives(struct alt_instr *start, · line 361

Quoted 3 lines
xen/arch/x86/alternative.c +1 -2
-void init_or_livepatch apply_alternatives(struct alt_instr *start,
-                                          struct alt_instr *end)
+#ifdef CONFIG_LIVEPATCH

... to have the #ifdef than the init_or_livepatch attribute.

But the init_or_livepatch attribute doesn't remove the function when !CONFIG_LIVEPATCH, so it's not a replacement for the ifdef.

IOW: it's my understanding that the purpose of init_or_livepatch is to add the __init attribute if livepatch is not enabled, but apply_alternatives() should never have the __init attribute because it's solely used by livepatch, it's not used at boot.

Thanks, Roger.

#3 lore raw
Quoted 21 lines · Roger Pau Monné
Quoted 16 lines · Jan Beulich
Quoted 5 lines · Roger Pau Monne

Guard it with CONFIG_LIVEPATCH. Note alternatives are applied at boot using _apply_alternatives().

albeit the implicit ack therein is only on the assumption that (apart from me) it is generally deemed better ...

Quoted 6 lines
xen/arch/x86/alternative.c +0 -0
@@ -358,11 +358,12 @@ static void init_or_livepatch _apply_alternatives(struct alt_instr *start,
     }
 }
 
Quoted 4 lines

xen/arch/x86/alternative.c static void init_or_livepatch _apply_alternatives(struct alt_instr *start, · line 361

Quoted 3 lines
xen/arch/x86/alternative.c +1 -2
-void init_or_livepatch apply_alternatives(struct alt_instr *start,
-                                          struct alt_instr *end)
+#ifdef CONFIG_LIVEPATCH

... to have the #ifdef than the init_or_livepatch attribute.

Quoted 7 lines

But the init_or_livepatch attribute doesn't remove the function when !CONFIG_LIVEPATCH, so it's not a replacement for the ifdef.

IOW: it's my understanding that the purpose of init_or_livepatch is to add the __init attribute if livepatch is not enabled, but apply_alternatives() should never have the __init attribute because it's solely used by livepatch, it's not used at boot.

For context, Jan you missed the MISRA call yesterday where this was identified as an emitted-but-undeferenced function.

~Andrew

#4 lore raw
Quoted 25 lines · Andrew Cooper
Quoted 24 lines · Roger Pau Monné
Quoted 16 lines · Jan Beulich
Quoted 5 lines · Roger Pau Monne

Guard it with CONFIG_LIVEPATCH. Note alternatives are applied at boot using _apply_alternatives().

albeit the implicit ack therein is only on the assumption that (apart from me) it is generally deemed better ...

Quoted 6 lines
xen/arch/x86/alternative.c +0 -0
@@ -358,11 +358,12 @@ static void init_or_livepatch _apply_alternatives(struct alt_instr *start,
     }
 }
 
Quoted 4 lines

xen/arch/x86/alternative.c static void init_or_livepatch _apply_alternatives(struct alt_instr *start, · line 361

Quoted 3 lines
xen/arch/x86/alternative.c +1 -2
-void init_or_livepatch apply_alternatives(struct alt_instr *start,
-                                          struct alt_instr *end)
+#ifdef CONFIG_LIVEPATCH

... to have the #ifdef than the init_or_livepatch attribute.

But the init_or_livepatch attribute doesn't remove the function when !CONFIG_LIVEPATCH, so it's not a replacement for the ifdef.

Quoted 7 lines
Quoted 4 lines

IOW: it's my understanding that the purpose of init_or_livepatch is to add the __init attribute if livepatch is not enabled, but apply_alternatives() should never have the __init attribute because it's solely used by livepatch, it's not used at boot.

For context, Jan you missed the MISRA call yesterday where this was identified as an emitted-but-undeferenced function.

Ah, this helps.

Thanks, Jan

#5 lore raw
In reply to Roger Pau Monné
Quoted 18 lines · Roger Pau Monné
Quoted 17 lines · Jan Beulich
Quoted 5 lines · Roger Pau Monne

Guard it with CONFIG_LIVEPATCH. Note alternatives are applied at boot using _apply_alternatives().

albeit the implicit ack therein is only on the assumption that (apart from me) it is generally deemed better ...

Quoted 6 lines
xen/arch/x86/alternative.c +0 -0
@@ -358,11 +358,12 @@ static void init_or_livepatch _apply_alternatives(struct alt_instr *start,
     }
 }
 
Quoted 8 lines
Quoted 5 lines

xen/arch/x86/alternative.c static void init_or_livepatch _apply_alternatives(struct alt_instr *start, · line 361

Quoted 3 lines
xen/arch/x86/alternative.c +1 -2
-void init_or_livepatch apply_alternatives(struct alt_instr *start,
-                                          struct alt_instr *end)
+#ifdef CONFIG_LIVEPATCH

... to have the #ifdef than the init_or_livepatch attribute.

But the init_or_livepatch attribute doesn't remove the function when !CONFIG_LIVEPATCH,

Yes up to here.

Quoted 1 line

so it's not a replacement for the ifdef.

That depends how you look at it. We don't meaningfully care about a few extra bytes in .init.text, I think. So it really is the Misra requirement of not having unreferenced symbols which makes the difference here.

Jan

#6 lore raw
Quoted 24 lines · Jan Beulich
Quoted 17 lines · Roger Pau Monné
Quoted 16 lines · Jan Beulich
Quoted 5 lines · Roger Pau Monne

Guard it with CONFIG_LIVEPATCH. Note alternatives are applied at boot using _apply_alternatives().

albeit the implicit ack therein is only on the assumption that (apart from me) it is generally deemed better ...

Quoted 6 lines
xen/arch/x86/alternative.c +0 -0
@@ -358,11 +358,12 @@ static void init_or_livepatch _apply_alternatives(struct alt_instr *start,
     }
 }
 
Quoted 6 lines
Quoted 4 lines

xen/arch/x86/alternative.c static void init_or_livepatch _apply_alternatives(struct alt_instr *start, · line 361

Quoted 3 lines
xen/arch/x86/alternative.c +1 -2
-void init_or_livepatch apply_alternatives(struct alt_instr *start,
-                                          struct alt_instr *end)
+#ifdef CONFIG_LIVEPATCH

... to have the #ifdef than the init_or_livepatch attribute.

But the init_or_livepatch attribute doesn't remove the function when !CONFIG_LIVEPATCH,

Quoted 7 lines

Yes up to here.

Quoted 1 line

so it's not a replacement for the ifdef.

That depends how you look at it. We don't meaningfully care about a few extra bytes in .init.text, I think. So it really is the Misra requirement of not having unreferenced symbols which makes the difference here.

A different option, which I've recommended before for other reasons, is to build with function/data sections (already supported for livepatch), and use --gc-sections at link time.

That would remove examples like this from the final binary, and there's probably wiggle-room at the MISRA level to say "we comply with this because the linker deletes it".

~Andrew