kexec: Remove xen/common/compat/kexec.c
cover 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.
Signature · 1 line
Horms
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.
---
xen/common/kexec.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
xen/common/kexec.c +3 -2
@@ -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_HANreturn ret; } -#else /* COMPAT */ -#ifdef CONFIG_COMPAT static int kexec_get_range_compat (XEN_GUEST_HANDLE (void ) uarg) {
Signature · 2 lines
-- Horms
PATCH 2/5 kexec: Add XLAT_kexec_range
In reply to Simon HormanAdd 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().
---
xen/common/kexec.c | 11 ++--------- xen/include/xlat.lst | 1 + 2 files changed, 3 insertions(+), 9 deletions(-)
xen/common/kexec.c +2 -9
@@ -260,19 +260,12 @@ static int kexec_get_range_compat(XEN_GUif (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 ; }
xen/include/xlat.lst +1 -0
@@ -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
Signature · 2 lines
-- Horms
PATCH 3/5 kexec: Add explicit kexec_load_unload_compat()
In reply to Simon HormanAdd an explicit kexec_load_unload_compat() using the same method that was used to create kexec_range_compat()
---
xen/common/compat/kexec.c | 4 -- xen/common/kexec.c | 63 ++++++++++++++++++++++++++++++--------------- 2 files changed, 42 insertions(+), 25 deletions(-)
xen/common/kexec.c +42 -21
@@ -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 loBUG_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 loif (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 ;
xen/common/compat/kexec.c +0 -4
@@ -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"
Signature · 2 lines
-- Horms
PATCH 4/5 kexec: Add explicit compat_kexec_op()
In reply to Simon HormanAdd an explicit compat_kexec_op() using a method similar to that was used to create kexec_range_compat() and kexec_load_unload_compat()
---
xen/common/compat/kexec.c | 3 -- xen/common/kexec.c | 47 ++++++++++++++++++++++++++------------------- 2 files changed, 28 insertions(+), 22 deletions(-)
xen/common/kexec.c +28 -19
@@ -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_HANreturn 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 loreturn 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(unsiXLAT_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(vreturn -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
xen/common/compat/kexec.c +0 -3
@@ -5,9 +5,6 @@#include <compat/kexec.h> #define COMPAT -#define ret_t int - -#define do_kexec_op compat_kexec_op CHECK_kexec_exec;
Signature · 2 lines
-- Horms
PATCH 5/5 kexec: Remove xen/common/compat/kexec.c
In reply to Simon Hormanxen/common/compat/kexec.c and and the resulting two-pass build of xen/common/kexec.c is no longer needed.
---
xen/common/Makefile | 1 - xen/common/compat/kexec.c | 21 --------------------- xen/common/kexec.c | 8 -------- 3 files changed, 30 deletions(-)
xen/common/Makefile +0 -1
@@ -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
xen/common/compat/kexec.c deleted +0 -21
@@ -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: -*/
xen/common/kexec.c +0 -8
@@ -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
Signature · 2 lines
-- Horms
Quoted 7 lines · Simon Horman
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 ofxen/common/compat/kexec.c.This series of patches systematically removes any need for
xen/common/compat/kexec.cand then removesxen/common/compat/kexec.citself.
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
Quoted 6 lines · Keir Fraser
Quoted 4 lines · Simon Horman
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 ofxen/common/compat/kexec.c.
Quoted 6 lines
Quoted 3 lines
This series of patches systematically removes any need for
xen/common/compat/kexec.cand then removesxen/common/compat/kexec.citself.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.
Signature · 1 line
Horms