Skip to contentSkip to conversation

x86/kexec: Annotate more noreturns

PATCH In review Andrew Cooper 3 participants 5 messages Oct 6 – Oct 27

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/kexec: Annotate more noreturns

kexec_reloc() does not return. Plumbing this property upwards lets us mark machine_kexec() and machine_reboot_kexec() noreturn too.

---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Teddy Astie <[email protected]>

Rebase forward many years.

---
 xen/arch/x86/include/asm/machine_kexec.h | 7 ++++---
 xen/arch/x86/machine_kexec.c             | 5 ++---
 xen/common/kexec.c                       | 2 --
 xen/include/xen/kexec.h                  | 2 +-
 4 files changed, 7 insertions(+), 9 deletions(-)
xen/arch/x86/include/asm/machine_kexec.h +4 -3
index 3e189acf2464..f0bdc2f44109 100644
@@ -4,10 +4,11 @@
 #define KEXEC_RELOC_FLAG_COMPAT 0x1 /* 32-bit image */
 
 #ifndef __ASSEMBLER__
+#include <xen/compiler.h>
 
-extern void kexec_reloc(unsigned long reloc_code, unsigned long reloc_pt,
-                        unsigned long ind_maddr, unsigned long entry_maddr,
-                        unsigned long flags);
+extern void noreturn kexec_reloc(
+    unsigned long reloc_code, unsigned long reloc_pt, unsigned long ind_maddr,
+    unsigned long entry_maddr, unsigned long flags);
 
 extern const char kexec_reloc_end[];
 
xen/arch/x86/machine_kexec.c +2 -3
index 038670922d47..0fb9ed50e780 100644
@@ -142,15 +142,14 @@ void machine_kexec_unload(struct kexec_image *image)
     /* no-op. kimage_free() frees all control pages. */
 }
 
-void machine_reboot_kexec(struct kexec_image *image)
+void noreturn machine_reboot_kexec(struct kexec_image *image)
 {
     BUG_ON(smp_processor_id() != 0);
     smp_send_stop();
     machine_kexec(image);
-    BUG();
 }
 
-void machine_kexec(struct kexec_image *image)
+void noreturn machine_kexec(struct kexec_image *image)
 {
     int i;
     unsigned long reloc_flags = 0;
xen/common/kexec.c +0 -2
index 8ccaef1e0258..da3bb95d0852 100644
@@ -397,8 +397,6 @@ void kexec_crash(enum crash_reason reason)
     kexec_crash_save_cpu();
     machine_crash_shutdown();
     machine_kexec(kexec_image[KEXEC_IMAGE_CRASH_BASE + pos]);
-
-    BUG();
 }
 
 static long noreturn cf_check kexec_reboot(void *_image)
xen/include/xen/kexec.h +1 -1
index e0d793b04316..6bb3fde629a6 100644
@@ -49,7 +49,7 @@ int machine_kexec_load(struct kexec_image *image);
 void machine_kexec_unload(struct kexec_image *image);
 void machine_kexec_reserved(xen_kexec_reserve_t *reservation);
 void noreturn machine_reboot_kexec(struct kexec_image *image);
-void machine_kexec(struct kexec_image *image);
+void noreturn machine_kexec(struct kexec_image *image);
 void kexec_crash(enum crash_reason reason);
 void kexec_crash_save_cpu(void);
 struct crash_xen_info *kexec_crash_save_info(void);
Signature · 1 line
2.39.5
Reviewed-by on v1 1/1
#1 lore raw
Quoted 2 lines · Andrew Cooper

kexec_reloc() does not return. Plumbing this property upwards lets us mark machine_kexec() and machine_reboot_kexec() noreturn too.

The latter already is annotated such (see also next remark) as of 4d2ed2f88a0c.

Quoted 10 lines
xen/arch/x86/machine_kexec.c +1 -1
@@ -142,15 +142,14 @@ void machine_kexec_unload(struct kexec_image *image)
     /* no-op. kimage_free() frees all control pages. */
 }
 
-void machine_reboot_kexec(struct kexec_image *image)
+void noreturn machine_reboot_kexec(struct kexec_image *image)
 {
     BUG_ON(smp_processor_id() != 0);

xen/arch/x86/machine_kexec.c void machine_kexec_unload(struct kexec_image *image) · line 155

Quoted 10 lines
xen/arch/x86/machine_kexec.c +1 -2
     smp_send_stop();
     machine_kexec(image);
-    BUG();
 }
 
-void machine_kexec(struct kexec_image *image)
+void noreturn machine_kexec(struct kexec_image *image)
 {
     int i;
     unsigned long reloc_flags = 0;

The annotations here aren't needed, are they? I.e. this hunk can shrink to just the removal of the BUG() invocation.

xen/include/xen/kexec.h int machine_kexec_load(struct kexec_image *image); · line 52

Quoted 8 lines
xen/include/xen/kexec.h +1 -1
@@ -49,7 +49,7 @@ int machine_kexec_load(struct kexec_image *image);
 void machine_kexec_unload(struct kexec_image *image);
 void machine_kexec_reserved(xen_kexec_reserve_t *reservation);
 void noreturn machine_reboot_kexec(struct kexec_image *image);
-void machine_kexec(struct kexec_image *image);
+void noreturn machine_kexec(struct kexec_image *image);

The annotations on the declarations are sufficient, with another Misra rule making sure we don't omit the inclusion of the header in the CU having the definitions.

Preferably with the redundant annotations omitted, and with the description slightly adjusted:

Jan

#2 lore raw
Quoted 4 lines · Jan Beulich
Quoted 2 lines · Andrew Cooper

kexec_reloc() does not return. Plumbing this property upwards lets us mark machine_kexec() and machine_reboot_kexec() noreturn too.

The latter already is annotated such (see also next remark) as of 4d2ed2f88a0c.

You missed half of it.  I'm surprised that it didn't create a MISRA violation.

Quoted 16 lines
Quoted 16 lines
xen/arch/x86/machine_kexec.c +1 -2
@@ -142,15 +142,14 @@ void machine_kexec_unload(struct kexec_image *image)
     /* no-op. kimage_free() frees all control pages. */
 }
 
-void machine_reboot_kexec(struct kexec_image *image)
+void noreturn machine_reboot_kexec(struct kexec_image *image)
 {
     BUG_ON(smp_processor_id() != 0);
     smp_send_stop();
     machine_kexec(image);
-    BUG();
 }
 
Quoted 7 lines

xen/arch/x86/machine_kexec.c void machine_kexec_unload(struct kexec_image *image) · line 155

Quoted 5 lines
xen/arch/x86/machine_kexec.c +1 -1
-void machine_kexec(struct kexec_image *image)
+void noreturn machine_kexec(struct kexec_image *image)
 {
     int i;
     unsigned long reloc_flags = 0;

The annotations here aren't needed, are they? I.e. this hunk can shrink to just the removal of the BUG() invocation.

Readers of this code are not psychic.  They shouldn't need to be in order to follow what's going on.

Quoted 13 lines

xen/include/xen/kexec.h int machine_kexec_load(struct kexec_image *image); · line 52

Quoted 9 lines
xen/include/xen/kexec.h +1 -1
@@ -49,7 +49,7 @@ int machine_kexec_load(struct kexec_image *image);
 void machine_kexec_unload(struct kexec_image *image);
 void machine_kexec_reserved(xen_kexec_reserve_t *reservation);
 void noreturn machine_reboot_kexec(struct kexec_image *image);
-void machine_kexec(struct kexec_image *image);
+void noreturn machine_kexec(struct kexec_image *image);

The annotations on the declarations are sufficient, with another Misra rule making sure we don't omit the inclusion of the header in the CU having the definitions.

Quoted 3 lines

Preferably with the redundant annotations omitted, and with the description slightly adjusted:

I am not inclined to make changes.

~Andrew

#3 lore raw
Quoted 8 lines · Andrew Cooper
Quoted 4 lines · Jan Beulich
Quoted 2 lines · Andrew Cooper

kexec_reloc() does not return. Plumbing this property upwards lets us mark machine_kexec() and machine_reboot_kexec() noreturn too.

The latter already is annotated such (see also next remark) as of 4d2ed2f88a0c.

You missed half of it.  I'm surprised that it didn't create a MISRA violation.

Please clarify what it is that I missed.

Quoted 23 lines
Quoted 15 lines
Quoted 15 lines
xen/arch/x86/machine_kexec.c +1 -2
@@ -142,15 +142,14 @@ void machine_kexec_unload(struct kexec_image *image)
     /* no-op. kimage_free() frees all control pages. */
 }
 
-void machine_reboot_kexec(struct kexec_image *image)
+void noreturn machine_reboot_kexec(struct kexec_image *image)
 {
     BUG_ON(smp_processor_id() != 0);
     smp_send_stop();
     machine_kexec(image);
-    BUG();
 }
 
Quoted 7 lines

xen/arch/x86/machine_kexec.c void machine_kexec_unload(struct kexec_image *image) · line 155

Quoted 5 lines
xen/arch/x86/machine_kexec.c +1 -1
-void machine_kexec(struct kexec_image *image)
+void noreturn machine_kexec(struct kexec_image *image)
 {
     int i;
     unsigned long reloc_flags = 0;

The annotations here aren't needed, are they? I.e. this hunk can shrink to just the removal of the BUG() invocation.

Quoted 2 lines

Readers of this code are not psychic.  They shouldn't need to be in order to follow what's going on.

"Psychic"? What are you trying to tell me? There's nothing wrong with repeating this kind of annotation on the definition, but there also is no need for doing so. Hence as far as I can judge, the change I made was self-consistent. If you feel like repeating the annotation is wanted, then that's different from you (half implicitly, half explicitly) claiming it's _needed_.

Quoted 12 lines
Quoted 12 lines

xen/include/xen/kexec.h int machine_kexec_load(struct kexec_image *image); · line 52

Quoted 8 lines
xen/include/xen/kexec.h +1 -1
@@ -49,7 +49,7 @@ int machine_kexec_load(struct kexec_image *image);
 void machine_kexec_unload(struct kexec_image *image);
 void machine_kexec_reserved(xen_kexec_reserve_t *reservation);
 void noreturn machine_reboot_kexec(struct kexec_image *image);
-void machine_kexec(struct kexec_image *image);
+void noreturn machine_kexec(struct kexec_image *image);

The annotations on the declarations are sufficient, with another Misra rule making sure we don't omit the inclusion of the header in the CU having the definitions.

Quoted 5 lines
Quoted 3 lines

Preferably with the redundant annotations omitted, and with the description slightly adjusted:

I am not inclined to make changes.

Well, so be it then. Yet it again indicates that in certain situations you're simply not willing to accept that there may be (valid) viewpoints other than yours. Or, if you think those aren't valid, make clear what's objectively wrong.

Jan