stubdom/grub: avoid relying on start_info definition
PATCH 1/1 stubdom/grub: avoid relying on start_info definition
The kexec() function of grub-pv is relying on the exact definition of start_info from Mini-OS by having an "#undef start_info" and a few lines later a copy of the Mini-OS definition again.
This is bad practice by making all attempts of Mini-OS to change that definition impossible.
Avoid that dependency by moving the code fragment in question to the very end of the source file, allowing to drop the copy of the definition.
--- stubdom/grub/kexec.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)
stubdom/grub/kexec.c +10 -4
@@ -209,6 +209,8 @@ static void tpm_hash2pcr(struct xc_dom_image *dom, char *cmdline)shutdown_tpmfront (tpm); } +static void call_start_info_hook (struct xc_dom_image *dom); +void kexec (void *kernel,long kernel_size,void *module,long module_size,char *cmdline,unsigned long flags) {struct xc_dom_image *dom;
@@ -330,10 +332,7 @@ void kexec(void *kernel, long kernel_size, void *module, long module_size, char }/* start info page */ -#undef start_info -if ( dom->arch_hooks->start_info ) - dom->arch_hooks->start_info (dom); -#define start_info (start_info_union.start_info) +call_start_info_hook (dom);xc_dom_log_memory_footprint (dom);
@@ -432,3 +431,10 @@ out: allocated =0 ;xc_interface_close (xc_handle ); } + +static void call_start_info_hook (struct xc_dom_image *dom) +{ +#undef start_info +if ( dom->arch_hooks->start_info ) + dom->arch_hooks->start_info (dom); +}
Signature · 1 line
2.43.0
Quoted 4 lines · Juergen Gross
The
kexec()function of grub-pv is relying on the exact definition ofstart_infofrom Mini-OS by having an "#undefstart_info" and a few lines later a copy of the Mini-OS definition again.
Quoted 8 lines
This is bad practice by making all attempts of Mini-OS to change that definition impossible.
Avoid that dependency by moving the code fragment in question to the very end of the source file, allowing to drop the copy of the definition.
Signed-off-by Juergen Gross <[email protected]>
stubdom/grub/kexec.c out: · line 440
Quoted 11 lines · Juergen Gross
stubdom/grub/kexec.c +7
-0@@ -432,3 +431,10 @@ out: allocated =0 ;xc_interface_close (xc_handle ); } + +static void call_start_info_hook (struct xc_dom_image *dom) +{ +#undef start_info +if ( dom->arch_hooks->start_info ) + dom->arch_hooks->start_info (dom); +}
Maybe add a comment ahead of the function clarifying that it ought to remain last?
Jan
Quoted 15 lines · Jan Beulich
stubdom/grub/kexec.c out: · line 440
Quoted 11 lines · Juergen Gross
stubdom/grub/kexec.c +7
-0@@ -432,3 +431,10 @@ out: allocated =0 ;xc_interface_close (xc_handle ); } + +static void call_start_info_hook (struct xc_dom_image *dom) +{ +#undef start_info +if ( dom->arch_hooks->start_info ) + dom->arch_hooks->start_info (dom); +}Maybe add a comment ahead of the function clarifying that it ought to remain last?
Good idea.
I'll add:
/* No references to start_info of Mini-OS after this function. */
Juergen
Quoted 18 lines · Jürgen Groß
Quoted 16 lines · Jan Beulich
stubdom/grub/kexec.c out: · line 440
Quoted 11 lines · Juergen Gross
stubdom/grub/kexec.c +7
-0@@ -432,3 +431,10 @@ out: allocated = 0; xc_interface_close(xc_handle ); } + +static void call_start_info_hook (struct xc_dom_image *dom) +{ +#undef start_info + if ( dom->arch_hooks->start_info ) + dom->arch_hooks->start_info(dom); +}Maybe add a comment ahead of the function clarifying that it ought to remain
last?
Quoted 5 lines
Good idea.
I'll add:
/* No references to
start_infoof Mini-OS after this function. */
Given how few uses of start_info there actually are, can't you just drop that piece of extreme obfuscation and make this work like regular C?
~Andrew
Quoted 19 lines · Andrew Cooper
Quoted 18 lines · Jürgen Groß
Quoted 16 lines · Jan Beulich
stubdom/grub/kexec.c out: · line 440
Quoted 11 lines · Juergen Gross
stubdom/grub/kexec.c +7
-0@@ -432,3 +431,10 @@ out: allocated = 0; xc_interface_close(xc_handle ); } + +static void call_start_info_hook (struct xc_dom_image *dom) +{ +#undef start_info + if ( dom->arch_hooks->start_info ) + dom->arch_hooks->start_info(dom); +}Maybe add a comment ahead of the function clarifying that it ought to remain
last?
Quoted 8 lines
Quoted 5 lines
Good idea.
I'll add:
/* No references to
start_infoof Mini-OS after this function. */Given how few uses of
start_infothere actually are, can't you just drop that piece of extreme obfuscation and make this work like regular C?
Hmm, you mean by using start_info_ptr directly?
This would be possible, but it would introduce a two-way dependency between xen.git and minios.git.
Right now the build is basically fine, as Config.mk doesn't reference the variant of Mini-OS breaking today's grub-pv.
Applying my current patch to grub-pv will still work with the "old" Mini-OS, which then could be updated to a commit-id containing the related Mini-OS patch defining start_info differently.
This update strategy would not result in a situation where the build is broken, while modifying grub-pv to use start_info_ptr directly isn't possible without either breaking the build in between (we'd need a Mini-OS update for that to have "EXPORT_SYMBOL(start_info_ptr);" included), or by taking my current patch as an intermediate step and only then switch grub-pv to use start_info_ptr.
Thoughts?
Juergen