Simon Horman
2008-Feb-29 06:28 UTC
[Xen-devel] [patch 0/5] kexec: Remove xen/common/compat/kexec.c
Hi, as discussed briefly on xen-devel, the method of defining compat functions for kexec involves a two-phase build of xen/common/kexec.c, hinging around the inclusion of xen/common/compat/kexec.c. This series of patches systematically removes any need for xen/common/compat/kexec.c and then removes xen/common/compat/kexec.c itself. -- Horms _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Simon Horman
2008-Feb-29 06:28 UTC
[Xen-devel] [patch 1/5] kexec: Include compat/kexec.h early
Include compat/kexec.h at the top of xen/common/kexec.c to allow kexec_get_range_compat() to be compiled outside of #ifndef COMPAT. This will slightly simplify the explicit creation of other _compat() functions and is needed for the eventual removal of xen/common/compat/kexec.c Note that the inclusion of compat/kexec.h needs to be protected by #ifdef CONFIG_COMPAT, as the file doesn''t exist otherwise. Signed-off-by: Simon Horman <horms@verge.net.au> --- xen/common/kexec.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) Index: xen-unstable.hg/xen/common/kexec.c ==================================================================--- xen-unstable.hg.orig/xen/common/kexec.c 2008-02-29 15:08:02.000000000 +0900 +++ xen-unstable.hg/xen/common/kexec.c 2008-02-29 15:10:21.000000000 +0900 @@ -23,6 +23,9 @@ #include <xen/kexec.h> #include <public/elfnote.h> #include <xsm/xsm.h> +#ifdef CONFIG_COMPAT +#include <compat/kexec.h> +#endif #ifndef COMPAT @@ -245,8 +248,6 @@ static int kexec_get_range(XEN_GUEST_HAN return ret; } -#else /* COMPAT */ - #ifdef CONFIG_COMPAT static int kexec_get_range_compat(XEN_GUEST_HANDLE(void) uarg) { -- -- Horms _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Add XLAT_kexec_range and use it to translate between xen_kexec_range_t and compat_kexec_range_t. I missed this in my previous patche which created the explicit definition of kexec_get_range_compat(). Signed-off-by: Simon Horman <horms@verge.net.au> --- xen/common/kexec.c | 11 ++--------- xen/include/xlat.lst | 1 + 2 files changed, 3 insertions(+), 9 deletions(-) Index: xen-unstable.hg/xen/common/kexec.c ==================================================================--- xen-unstable.hg.orig/xen/common/kexec.c 2008-02-29 14:50:20.000000000 +0900 +++ xen-unstable.hg/xen/common/kexec.c 2008-02-29 14:50:28.000000000 +0900 @@ -260,19 +260,12 @@ static int kexec_get_range_compat(XEN_GU if ( unlikely(copy_from_guest(&compat_range, uarg, 1)) ) return -EFAULT; - range.range = compat_range.range; - range.nr = compat_range.nr; - range.size = compat_range.size; - range.start = compat_range.start; + XLAT_kexec_range(&range, &compat_range); ret = kexec_get_range_internal(&range); if ( ret == 0 ) { - range.range = compat_range.range; - range.nr = compat_range.nr; - range.size = compat_range.size; - range.start = compat_range.start; - + XLAT_kexec_range(&compat_range, &range); if ( unlikely(copy_to_guest(uarg, &compat_range, 1)) ) return -EFAULT; } Index: xen-unstable.hg/xen/include/xlat.lst ==================================================================--- xen-unstable.hg.orig/xen/include/xlat.lst 2008-02-29 14:48:22.000000000 +0900 +++ xen-unstable.hg/xen/include/xlat.lst 2008-02-29 14:50:28.000000000 +0900 @@ -30,6 +30,7 @@ ? grant_entry grant_table.h ? kexec_exec kexec.h ! kexec_image kexec.h +! kexec_range kexec.h ! add_to_physmap memory.h ! foreign_memory_map memory.h ! memory_exchange memory.h -- -- Horms _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Simon Horman
2008-Feb-29 06:28 UTC
[Xen-devel] [patch 3/5] kexec: Add explicit kexec_load_unload_compat()
Add an explicit kexec_load_unload_compat() using the same method that was used to create kexec_range_compat() Signed-off-by: Simon Horman <horms@verge.net.au> --- xen/common/compat/kexec.c | 4 -- xen/common/kexec.c | 63 ++++++++++++++++++++++++++++++--------------- 2 files changed, 42 insertions(+), 25 deletions(-) Index: xen-unstable.hg/xen/common/kexec.c ==================================================================--- xen-unstable.hg.orig/xen/common/kexec.c 2008-02-29 15:13:43.000000000 +0900 +++ xen-unstable.hg/xen/common/kexec.c 2008-02-29 15:19:16.000000000 +0900 @@ -272,11 +272,6 @@ static int kexec_get_range_compat(XEN_GU } #endif /* CONFIG_COMPAT */ -#endif /* COMPAT */ - - -#ifndef COMPAT - static int kexec_load_get_bits(int type, int *base, int *bit) { switch ( type ) @@ -295,19 +290,13 @@ static int kexec_load_get_bits(int type, return 0; } -#endif - -static int kexec_load_unload(unsigned long op, XEN_GUEST_HANDLE(void) uarg) +static int kexec_load_unload_internal(unsigned long op, xen_kexec_load_t *load) { - xen_kexec_load_t load; xen_kexec_image_t *image; int base, bit, pos; int ret = 0; - if ( unlikely(copy_from_guest(&load, uarg, 1)) ) - return -EFAULT; - - if ( kexec_load_get_bits(load.type, &base, &bit) ) + if ( kexec_load_get_bits(load->type, &base, &bit) ) return -EINVAL; pos = (test_bit(bit, &kexec_flags) != 0); @@ -319,13 +308,9 @@ static int kexec_load_unload(unsigned lo BUG_ON(test_bit((base + !pos), &kexec_flags)); /* must be free */ -#ifndef COMPAT - memcpy(image, &load.image, sizeof(*image)); -#else - XLAT_kexec_image(image, &load.image); -#endif + memcpy(image, &load->image, sizeof(*image)); - if ( !(ret = machine_kexec_load(load.type, base + !pos, image)) ) + if ( !(ret = machine_kexec_load(load->type, base + !pos, image)) ) { /* Set image present bit */ set_bit((base + !pos), &kexec_flags); @@ -341,14 +326,46 @@ static int kexec_load_unload(unsigned lo if ( test_and_clear_bit((base + pos), &kexec_flags) ) { image = &kexec_image[base + pos]; - machine_kexec_unload(load.type, base + pos, image); + machine_kexec_unload(load->type, base + pos, image); } } return ret; } -#ifndef COMPAT +static int kexec_load_unload(unsigned long op, XEN_GUEST_HANDLE(void) uarg) +{ + xen_kexec_load_t load; + + if ( unlikely(copy_from_guest(&load, uarg, 1)) ) + return -EFAULT; + + return kexec_load_unload_internal(op, &load); +} + +#ifdef CONFIG_COMPAT +static int kexec_load_unload_compat(unsigned long op, + XEN_GUEST_HANDLE(void) uarg) +{ + compat_kexec_load_t compat_load; + xen_kexec_load_t load; + + if ( unlikely(copy_from_guest(&compat_load, uarg, 1)) ) + return -EFAULT; + + /* This is a bit dodgy, load.image is inside load, + * but XLAT_kexec_load (which is automatically generated) + * doesn''t translate load.image (correctly) + * Just copy load->type, the only other member, manually instead. + * + * XLAT_kexec_load(&load, &compat_load); + */ + load.type = compat_load.type; + XLAT_kexec_image(&load.image, &compat_load.image); + + return kexec_load_unload_internal(op, &load); +} +#endif static int kexec_exec(XEN_GUEST_HANDLE(void) uarg) { @@ -411,7 +428,11 @@ ret_t do_kexec_op(unsigned long op, XEN_ spin_lock_irqsave(&kexec_lock, flags); if (!test_bit(KEXEC_FLAG_IN_PROGRESS, &kexec_flags)) { +#ifndef COMPAT ret = kexec_load_unload(op, uarg); +#else + ret = kexec_load_unload_compat(op, uarg); +#endif } spin_unlock_irqrestore(&kexec_lock, flags); break; Index: xen-unstable.hg/xen/common/compat/kexec.c ==================================================================--- xen-unstable.hg.orig/xen/common/compat/kexec.c 2008-02-29 15:08:01.000000000 +0900 +++ xen-unstable.hg/xen/common/compat/kexec.c 2008-02-29 15:19:16.000000000 +0900 @@ -9,10 +9,6 @@ #define do_kexec_op compat_kexec_op -#define kexec_load_unload compat_kexec_load_unload -#define xen_kexec_load compat_kexec_load -#define xen_kexec_load_t compat_kexec_load_t - CHECK_kexec_exec; #include "../kexec.c" -- -- Horms _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Simon Horman
2008-Feb-29 06:28 UTC
[Xen-devel] [patch 4/5] kexec: Add explicit compat_kexec_op()
Add an explicit compat_kexec_op() using a method similar to that was used to create kexec_range_compat() and kexec_load_unload_compat() Signed-off-by: Simon Horman <horms@verge.net.au> --- xen/common/compat/kexec.c | 3 -- xen/common/kexec.c | 47 ++++++++++++++++++++++++++------------------- 2 files changed, 28 insertions(+), 22 deletions(-) Index: xen-unstable.hg/xen/common/kexec.c ==================================================================--- xen-unstable.hg.orig/xen/common/kexec.c 2008-02-29 14:56:46.000000000 +0900 +++ xen-unstable.hg/xen/common/kexec.c 2008-02-29 15:07:57.000000000 +0900 @@ -29,8 +29,6 @@ #ifndef COMPAT -typedef long ret_t; - static DEFINE_PER_CPU(void *, crash_notes); static Elf_Note *xen_crash_note; @@ -248,9 +246,9 @@ static int kexec_get_range(XEN_GUEST_HAN return ret; } -#ifdef CONFIG_COMPAT static int kexec_get_range_compat(XEN_GUEST_HANDLE(void) uarg) { +#ifdef CONFIG_COMPAT xen_kexec_range_t range; compat_kexec_range_t compat_range; int ret = -EINVAL; @@ -269,8 +267,8 @@ static int kexec_get_range_compat(XEN_GU } return ret; -} #endif /* CONFIG_COMPAT */ +} static int kexec_load_get_bits(int type, int *base, int *bit) { @@ -343,10 +341,10 @@ static int kexec_load_unload(unsigned lo return kexec_load_unload_internal(op, &load); } -#ifdef CONFIG_COMPAT static int kexec_load_unload_compat(unsigned long op, XEN_GUEST_HANDLE(void) uarg) { +#ifdef CONFIG_COMPAT compat_kexec_load_t compat_load; xen_kexec_load_t load; @@ -364,8 +362,8 @@ static int kexec_load_unload_compat(unsi XLAT_kexec_image(&load.image, &compat_load.image); return kexec_load_unload_internal(op, &load); -} #endif +} static int kexec_exec(XEN_GUEST_HANDLE(void) uarg) { @@ -400,9 +398,8 @@ static int kexec_exec(XEN_GUEST_HANDLE(v return -EINVAL; /* never reached */ } -#endif - -ret_t do_kexec_op(unsigned long op, XEN_GUEST_HANDLE(void) uarg) +int do_kexec_op_internal(unsigned long op, XEN_GUEST_HANDLE(void) uarg, + int compat) { unsigned long flags; int ret = -EINVAL; @@ -417,22 +414,20 @@ ret_t do_kexec_op(unsigned long op, XEN_ switch ( op ) { case KEXEC_CMD_kexec_get_range: -#ifndef COMPAT - ret = kexec_get_range(uarg); -#else - ret = kexec_get_range_compat(uarg); -#endif + if (compat) + ret = kexec_get_range_compat(uarg); + else + ret = kexec_get_range(uarg); break; case KEXEC_CMD_kexec_load: case KEXEC_CMD_kexec_unload: spin_lock_irqsave(&kexec_lock, flags); if (!test_bit(KEXEC_FLAG_IN_PROGRESS, &kexec_flags)) { -#ifndef COMPAT - ret = kexec_load_unload(op, uarg); -#else - ret = kexec_load_unload_compat(op, uarg); -#endif + if (compat) + ret = kexec_load_unload_compat(op, uarg); + else + ret = kexec_load_unload(op, uarg); } spin_unlock_irqrestore(&kexec_lock, flags); break; @@ -444,6 +439,20 @@ ret_t do_kexec_op(unsigned long op, XEN_ return ret; } +long do_kexec_op(unsigned long op, XEN_GUEST_HANDLE(void) uarg) +{ + return do_kexec_op_internal(op, uarg, 0); +} + +#ifdef CONFIG_COMPAT +int compat_kexec_op(unsigned long op, XEN_GUEST_HANDLE(void) uarg) +{ + return do_kexec_op_internal(op, uarg, 1); +} +#endif + +#endif /* COMPAT */ + #if defined(CONFIG_COMPAT) && !defined(COMPAT) #include "compat/kexec.c" #endif Index: xen-unstable.hg/xen/common/compat/kexec.c ==================================================================--- xen-unstable.hg.orig/xen/common/compat/kexec.c 2008-02-29 15:00:53.000000000 +0900 +++ xen-unstable.hg/xen/common/compat/kexec.c 2008-02-29 15:07:57.000000000 +0900 @@ -5,9 +5,6 @@ #include <compat/kexec.h> #define COMPAT -#define ret_t int - -#define do_kexec_op compat_kexec_op CHECK_kexec_exec; -- -- Horms _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Simon Horman
2008-Feb-29 06:28 UTC
[Xen-devel] [patch 5/5] kexec: Remove xen/common/compat/kexec.c
xen/common/compat/kexec.c and and the resulting two-pass build of xen/common/kexec.c is no longer needed. Signed-off-by: Simon Horman <horms@verge.net.au> --- xen/common/Makefile | 1 - xen/common/compat/kexec.c | 21 --------------------- xen/common/kexec.c | 8 -------- 3 files changed, 30 deletions(-) Index: xen-unstable.hg/xen/common/Makefile ==================================================================--- xen-unstable.hg.orig/xen/common/Makefile 2008-02-29 15:22:35.000000000 +0900 +++ xen-unstable.hg/xen/common/Makefile 2008-02-29 15:22:45.000000000 +0900 @@ -48,7 +48,6 @@ version.o: $(BASEDIR)/include/xen/compil ifeq ($(CONFIG_COMPAT),y) # extra dependencies grant_table.o: compat/grant_table.c -kexec.o: compat/kexec.c schedule.o: compat/schedule.c xenoprof.o: compat/xenoprof.c endif Index: xen-unstable.hg/xen/common/compat/kexec.c ==================================================================--- xen-unstable.hg.orig/xen/common/compat/kexec.c 2008-02-29 15:22:35.000000000 +0900 +++ /dev/null 1970-01-01 00:00:00.000000000 +0000 @@ -1,21 +0,0 @@ -/* - * compat/kexec.c - */ - -#include <compat/kexec.h> - -#define COMPAT - -CHECK_kexec_exec; - -#include "../kexec.c" - -/* - * Local variables: - * mode: C - * c-set-style: "BSD" - * c-basic-offset: 4 - * tab-width: 4 - * indent-tabs-mode: nil - * End: - */ Index: xen-unstable.hg/xen/common/kexec.c ==================================================================--- xen-unstable.hg.orig/xen/common/kexec.c 2008-02-29 15:22:35.000000000 +0900 +++ xen-unstable.hg/xen/common/kexec.c 2008-02-29 15:22:45.000000000 +0900 @@ -27,8 +27,6 @@ #include <compat/kexec.h> #endif -#ifndef COMPAT - static DEFINE_PER_CPU(void *, crash_notes); static Elf_Note *xen_crash_note; @@ -451,12 +449,6 @@ int compat_kexec_op(unsigned long op, XE } #endif -#endif /* COMPAT */ - -#if defined(CONFIG_COMPAT) && !defined(COMPAT) -#include "compat/kexec.c" -#endif - /* * Local variables: * mode: C -- -- Horms _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Keir Fraser
2008-Feb-29 07:34 UTC
[Xen-devel] Re: [patch 0/5] kexec: Remove xen/common/compat/kexec.c
On 29/2/08 06:28, "Simon Horman" <horms@verge.net.au> wrote:> as discussed briefly on xen-devel, the method of defining compat > functions for kexec involves a two-phase build of xen/common/kexec.c, > hinging around the inclusion of xen/common/compat/kexec.c. > > This series of patches systematically removes any need for > xen/common/compat/kexec.c and then removes xen/common/compat/kexec.c > itself.Thanks, I''ll take a look. It looks like it''s not really a reduction in code size, but is rather less likely to make the readers brain bleed! -- Keir _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Simon Horman
2008-Feb-29 08:41 UTC
[Xen-devel] Re: [patch 0/5] kexec: Remove xen/common/compat/kexec.c
On Fri, Feb 29, 2008 at 07:34:41AM +0000, Keir Fraser wrote:> On 29/2/08 06:28, "Simon Horman" <horms@verge.net.au> wrote: > > > as discussed briefly on xen-devel, the method of defining compat > > functions for kexec involves a two-phase build of xen/common/kexec.c, > > hinging around the inclusion of xen/common/compat/kexec.c. > > > > This series of patches systematically removes any need for > > xen/common/compat/kexec.c and then removes xen/common/compat/kexec.c > > itself. > > Thanks, I''ll take a look. It looks like it''s not really a reduction in code > size, but is rather less likely to make the readers brain bleed!More thought would be needed if lines of code reduction is desired, though I think that the size of the output of the compile might be slightly smaller. It does however seem to make things less bleed prone :-) I noticed a slight problem with compiling without CONFIG_COMPAT after lunch. I have posted my update to the relevant patch. -- Horms _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel