Add kexec_ops & function pointers
PATCH 1/1 Add kexec_ops & function pointers
--- linux-2.6-xen-sparse/arch/i386/kernel/machine_kexec.c | 2 linux-2.6-xen-sparse/arch/x86_64/kernel/machine_kexec.c | 2 linux-2.6-xen-sparse/drivers/xen/core/machine_kexec.c | 42 +++++++- linux-2.6-xen-sparse/include/asm-i386/kexec.h | 14 -- linux-2.6-xen-sparse/include/asm-x86_64/kexec.h | 13 -- linux-2.6-xen-sparse/include/linux/kexec.h | 24 ++-- linux-2.6-xen-sparse/kernel/kexec.c | 80 +++++++++++----- 7 files changed, 110 insertions(+), 67 deletions(-)
linux-2.6-xen-sparse/arch/i386/kernel/machine_kexec.c +0 -2
@@ -92,7 +92,6 @@ void machine_kexec_cleanup(struct kimage { } -#ifndef CONFIG_XEN /* * Do not allocate memory (or fail in any way) in machine_kexec(). * We are past the point of no return, committed to rebooting now.
@@ -126,4 +125,3 @@ NORET_TYPE void machine_kexec(struct kimrelocate_kernel ((unsigned long )image->head, (unsigned long )page_list, image->start, cpu_has_pae); } -#endif
linux-2.6-xen-sparse/arch/x86_64/kernel/machine_kexec.c +0 -2
@@ -237,7 +237,6 @@ void machine_kexec_cleanup(struct kimagereturn ; } -#ifndef CONFIG_XEN /* * Do not allocate memory (or fail in any way) in machine_kexec(). * We are past the point of no return, committed to rebooting now.
@@ -276,4 +275,3 @@ NORET_TYPE void machine_kexec(struct kimrelocate_kernel ((unsigned long )image->head, (unsigned long )page_list, image->start); } -#endif
linux-2.6-xen-sparse/drivers/xen/core/machine_kexec.c +39 -3
78 lines not on this page · raw message
linux-2.6-xen-sparse/include/asm-i386/kexec.h +0 -14
@@ -98,20 +98,6 @@ relocate_kernel(unsigned long indirectiounsigned long start_address, unsigned int has_pae) ATTRIB_NORET; - -/* Under Xen we need to work with machine addresses. These macros give the -* machine address of a certain page to the generic kexec code instead of -* the pseudo physical address which would be given by the default macros. -*/ - -#ifdef CONFIG_XEN -#define KEXEC_ARCH_HAS_PAGE_MACROS -#define kexec_page_to_pfn (page) pfn_to_mfn(page_to_pfn(page)) -#define kexec_pfn_to_page (pfn) pfn_to_page(mfn_to_pfn(pfn)) -#define kexec_virt_to_phys (addr) virt_to_machine(addr) -#define kexec_phys_to_virt (addr) phys_to_virt(machine_to_phys(addr)) -#endif -#endif /* __ASSEMBLY__ */ #endif /* _I386_KEXEC_H */
linux-2.6-xen-sparse/include/asm-x86_64/kexec.h +0 -13
@@ -91,19 +91,6 @@ relocate_kernel(unsigned long indirectiounsigned long page_list, unsigned long start_address) ATTRIB_NORET; -/* Under Xen we need to work with machine addresses. These macros give the -* machine address of a certain page to the generic kexec code instead of -* the pseudo physical address which would be given by the default macros. -*/ - -#ifdef CONFIG_XEN -#define KEXEC_ARCH_HAS_PAGE_MACROS -#define kexec_page_to_pfn (page) pfn_to_mfn(page_to_pfn(page)) -#define kexec_pfn_to_page (pfn) pfn_to_page(mfn_to_pfn(pfn)) -#define kexec_virt_to_phys (addr) virt_to_machine(addr) -#define kexec_phys_to_virt (addr) phys_to_virt(machine_to_phys(addr)) -#endif -#endif /* __ASSEMBLY__ */ #endif /* _X86_64_KEXEC_H */
linux-2.6-xen-sparse/include/linux/kexec.h +14 -10
@@ -31,13 +31,6 @@#error KEXEC_ARCH not defined#endif -#ifndef KEXEC_ARCH_HAS_PAGE_MACROS -#define kexec_page_to_pfn (page) page_to_pfn(page) -#define kexec_pfn_to_page (pfn) pfn_to_page(pfn) -#define kexec_virt_to_phys (addr) virt_to_phys(addr) -#define kexec_phys_to_virt (addr) phys_to_virt(addr) -#endif -/* * This structure is used to hold the arguments that are used when loading * kernel binaries.
@@ -92,15 +85,26 @@ struct kimage {#define KEXEC_TYPE_CRASH 1 }; +/* kexec interface functions */ +struct kexec_machine_ops { +unsigned long (*kpage_to_pfn)(struct page *page); +struct page * (*kpfn_to_page)(unsigned long pfn); +unsigned long (*kvirt_to_phys)(void *addr); +void * (*kphys_to_virt)(unsigned long addr); + NORET_TYPE void (*kexec)(struct kimage *image) ATTRIB_NORET; +int (*kexec_prepare)(struct kimage *image); +int (*kexec_load)(struct kimage *image); +void (*kexec_unload)(struct kimage *image); +void (*kexec_cleanup)(struct kimage *image); +}; +extern struct kexec_machine_ops kexec_ops; -/* kexec interface functions */ extern NORET_TYPE void machine_kexec(struct kimage *image) ATTRIB_NORET;extern int machine_kexec_prepare (struct kimage *image);extern void machine_kexec_cleanup (struct kimage *image); +#ifdef CONFIG_XEN -extern int xen_machine_kexec_load (struct kimage *image); -extern void xen_machine_kexec_unload (struct kimage *image);extern void xen_machine_kexec_setup_resources (void );extern void xen_machine_kexec_register_resources (struct resource *res);#endif
linux-2.6-xen-sparse/kernel/kexec.c +57 -23
173 lines not on this page · raw message
Hi Gerd,
Quoted 10 lines · Gerd Hoffmann
Signed-off-by Gerd Hoffmann <[email protected]>--- linux-2.6-xen-sparse/arch/i386/kernel/machine_kexec.c | 2 linux-2.6-xen-sparse/arch/x86_64/kernel/machine_kexec.c | 2 linux-2.6-xen-sparse/drivers/xen/core/machine_kexec.c | 42 +++++++- linux-2.6-xen-sparse/include/asm-i386/kexec.h | 14 -- linux-2.6-xen-sparse/include/asm-x86_64/kexec.h | 13 -- linux-2.6-xen-sparse/include/linux/kexec.h | 24 ++-- linux-2.6-xen-sparse/kernel/kexec.c | 80 +++++++++++----- 7 files changed, 110 insertions(+), 67 deletions(-)
This version looks much cleaner. I've tested the code on i386 using version 12898 and there was one small piece missing, see the attached patch.
Basically, machine_kexec() should be converted to kexec_ops.kexec() in two places. The second place is unfortunately located in linux/kernel/sys.c which does not exist in sparse yet. So that needs to be resolved somehow.
So apart from that I think the code looks very good. Thanks.
/ magnus
linux-2.6-xen-sparse/kernel/kexec.c +1 -1
@@ -1119,7 +1119,7 @@ void crash_kexec(struct pt_regs *regs)struct pt_regs fixed_regs;crash_setup_regs (&fixed_regs, regs);machine_crash_shutdown (&fixed_regs); -machine_kexec (image); + kexec_ops.kexec (image); }xchg (&kexec_lock,0 ); }
linux-2.6.16.33-xen/kernel/sys.c +1 -1
@@ -435,7 +435,7 @@ void kernel_kexec(void)kernel_restart_prepare (NULL );printk (KERN_EMERG "Starting new kernel\n" );machine_shutdown (); -machine_kexec (image); + kexec_ops.kexec (image);#endif }EXPORT_SYMBOL_GPL (kernel_kexec);
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Hi,
Quoted 4 lines
Basically,
machine_kexec()should be converted tokexec_ops.kexec()in two places. The second place is unfortunately located inlinux/kernel/sys.cwhich does not exist in sparse yet. So that needs to be resolved somehow.
Noticed that too meanwhile, while making domU kexec work again. Latest version has this fixed.
http://www.suse.de/~kraxel/patches/unstable-hg12895-20061211-quilt/
kexec-add-kernel-sys.diff
kexec-fixups.diff
cheers,
Gerd
Signature · 1 line
Gerd Hoffmann <[email protected]>
Quoted 4 lines · Magnus Damm
Basically,
machine_kexec()should be converted tokexec_ops.kexec()in two places. The second place is unfortunately located inlinux/kernel/sys.cwhich does not exist in sparse yet. So that needs to be resolved somehow.
Hiding the indirections through the function table in the header via defines or inline functions would make things a lot cleaner in my opinion and as a bonus avoid this addition to the sparse tree.
That is the approach taken by the paravirt_ops stuff so it would also make it easier to integrate with that in the future.
Ian.
Quoted 9 lines · Ian Campbell
Quoted 4 lines · Magnus Damm
Basically,
machine_kexec()should be converted tokexec_ops.kexec()in two places. The second place is unfortunately located inlinux/kernel/sys.cwhich does not exist in sparse yet. So that needs to be resolved somehow.Hiding the indirections through the function table in the header via defines or inline functions would make things a lot cleaner in my opinion and as a bonus avoid this addition to the sparse tree.
No. As machine_kexec() continues to exist (and is the default for kexec_ops.kexec) you can't just turn that into a macro. You have to either fix the two callers (as done by the patch) or rename the function to something different in arch/*/kernel/machine_kexec.c in order to be able to reuse the name for the macro.
cheers,
Gerd
Signature · 1 line
Gerd Hoffmann <[email protected]>
Quoted 11 lines · Gerd Hoffmann
Quoted 9 lines · Ian Campbell
Quoted 4 lines · Magnus Damm
Basically,
machine_kexec()should be converted tokexec_ops.kexec()in two places. The second place is unfortunately located inlinux/kernel/sys.cwhich does not exist in sparse yet. So that needs to be resolved somehow.Hiding the indirections through the function table in the header via defines or inline functions would make things a lot cleaner in my opinion and as a bonus avoid this addition to the sparse tree.
Quoted 5 lines
No. As
machine_kexec()continues to exist (and is the default for kexec_ops.kexec) you can't just turn that into a macro. You have to either fix the two callers (as done by the patch) or rename the function to something different inarch/*/kernel/machine_kexec.cin order to be able to reuse the name for the macro.
Yes you may need to rename some bits. I was thinking of a solution where you have foo_native, foo_xen0 and foo_xenU functions (or whatever) with an inline foo() which calls through the function table to the correct version.
Cheers,
Ian.
Quoted 9 lines · Ian Campbell
Quoted 8 lines
Quoted 3 lines
Hiding the indirections through the function table in the header via defines or inline functions would make things a lot cleaner in my opinion and as a bonus avoid this addition to the sparse tree.
No. As
machine_kexec()continues to exist (and is the default for kexec_ops.kexec) you can't just turn that into a macro. You have to either fix the two callers (as done by the patch) or rename the function to something different inarch/*/kernel/machine_kexec.cin order to be able to reuse the name for the macro.
Quoted 4 lines
Yes you may need to rename some bits. I was thinking of a solution where you have
foo_native,foo_xen0andfoo_xenUfunctions (or whatever) with an inlinefoo()which calls through the function table to the correct version.
Sure. But renaming machine_kexec() to machine_kexec_native() or simliar means touching a big bunch of files, namely arch/{lots-of-directories-here}/kernel/machine_kexec.c. I'd prefer to touch only one (kernel/sys.c) to keep the number of changes in the xen tree small.
We'll have to see how we solve that finally, most likely it isn't the final solution anyway. paravirt is still some way to go, we have to upgrade to 2.6.20-rc1 first, and even that gives us paravirt for x86_32 only, not yet x86_64 ...
cheers,
Gerd
Signature · 1 line
Gerd Hoffmann <[email protected]>
Quoted 15 lines · Gerd Hoffmann
Quoted 9 lines · Ian Campbell
Quoted 8 lines
Quoted 3 lines
Hiding the indirections through the function table in the header via defines or inline functions would make things a lot cleaner in my opinion and as a bonus avoid this addition to the sparse tree.
No. As
machine_kexec()continues to exist (and is the default for kexec_ops.kexec) you can't just turn that into a macro. You have to either fix the two callers (as done by the patch) or rename the function to something different inarch/*/kernel/machine_kexec.cin order to be able to reuse the name for the macro.Quoted 4 lines
Yes you may need to rename some bits. I was thinking of a solution where you have
foo_native,foo_xen0andfoo_xenUfunctions (or whatever) with an inlinefoo()which calls through the function table to the correct version.
Quoted 5 lines
Sure. But renaming
machine_kexec()tomachine_kexec_native()or simliar means touching a big bunch of files, namelyarch/{lots-of-directories-here}/kernel/machine_kexec.c. I'd prefer to touch only one (kernel/sys.c) to keep the number of changes in the xen tree small.
You mean the versions for arch's other than i386 and x86_64? arch/{x86_64,i386}/kernel/machine_kexec.c are both in the sparse tree already.
If you are adding the function table to all architectures then you are right, changing kernel/sys.c is much simpler. I thought the function table was an implementation detail on i386 and x86_64 only.
Ian.