xen/arm: Shrink down Xen on Arm
v2 cover xen/arm: Shrink down Xen on Arm
Hi all,
This series removes unused code from Xen and also move some part under __init if only used during boot.
The major change of this series is removing support for libelf in Xen (see patch #4 and #5).
Cheers,
Julien Grall (7):
xen/arm: Remove the variable dom0_11_mapping and open-code the value xen/arm: domain_build: Move in init all code/data of domain_build.c xen/arm: kernel: Move in init all the code/data of kernel.c xen/arm: Drop support for loading ELF Dom0 kernel
xen: Don't build libelf for Arm
xen/libfdt: Put all libfdt in init
xen/arm: setup: Move in init code only used at boot in setup.c
xen/arch/arm/Makefile | 4 +- xen/arch/arm/domain_build.c | 137 ++++++++++++++++++++++--------------------- xen/arch/arm/kernel.c | 103 ++++---------------------------- xen/arch/arm/kernel.h | 10 +--- xen/arch/arm/setup.c | 10 ++-- xen/arch/x86/Kconfig | 1 + xen/common/Kconfig | 3 + xen/common/Makefile | 2 +- xen/common/libfdt/Makefile | 10 +++- xen/include/asm-arm/domain.h | 4 +- 10 files changed, 107 insertions(+), 177 deletions(-)
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 1/7 xen/arm: Remove the variable dom0_11_mapping and open-code the value
Dom0 (aka hardware domain on Arm) is always direct mapped. Rather than using a global variable to store a const, directly open-code it or replace the use with is_domain_direct_mapped(...) macros.
This will also help a follow-up patch to move all domain_build.c in init.
---
Changes in v2:
- Add Stefano's reviewed-by
--- xen/arch/arm/domain_build.c | 4 +--- xen/include/asm-arm/domain.h | 4 ++-- 2 files changed, 3 insertions(+), 5 deletions(-)
xen/arch/arm/domain_build.c +1 -3
@@ -28,8 +28,6 @@static unsigned int __initdata opt_dom0_max_vcpus;integer_param ("dom0_max_vcpus" , opt_dom0_max_vcpus); -int dom0_11_mapping =1 ; -static u64 __initdata dom0_mem;static int __init parse_dom0_mem (const char *s)
@@ -261,7 +259,7 @@ static void allocate_memory(struct domain *d, struct kernel_info *kinfo)* TODO: Implement memory bank allocation when DOM0 is not direct * mapped */ -BUG_ON (!dom0_11_mapping); +BUG_ON (!is_domain_direct_mapped (d)); printk("Allocating 1:1 mappings totalling %ldMB for dom0:\n",/* Don't want format this as PRIpaddr (16 digit hex) */
xen/include/asm-arm/domain.h +2 -2
@@ -31,8 +31,8 @@ enum domain_type {#define is_64bit_domain (d) (0)#endif -extern int dom0_11_mapping; -#define is_domain_direct_mapped (d) ((d) == hardware_domain && dom0_11_mapping) +/* The hardware domain has always its memory direct mapped. */ +#define is_domain_direct_mapped (d) ((d) == hardware_domain)struct vtimer {struct vcpu *v;
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 2/7 xen/arm: domain_build: Move in init all code/data of domain_build.c
In reply to Julien GrallThe file domain_build.c only contains code/data used during the initialization. So move everything to init and mark the file as such.
---
Changes in v2:
- Add Stefano's reviewed-by
--- xen/arch/arm/Makefile | 2 +- xen/arch/arm/domain_build.c | 133 +++++++++++++++++++++++--------------------- 2 files changed, 70 insertions(+), 65 deletions(-)
xen/arch/arm/Makefile +1 -1
@@ -12,7 +12,7 @@ obj-y += cpufeature.o obj-y += decode.o obj-y += device.o obj-y += domain.o -obj-y += domain_build.o +obj-y += domain_build.init.o obj-y += domctl.o obj-$(EARLY_PRINTK) += early_printk.o obj-y += gic.o
xen/arch/arm/domain_build.c +69 -64
355 lines not on this page · raw message
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 3/7 xen/arm: kernel: Move in init all the code/data of kernel.c
In reply to Julien GrallThe file kernel.c only contains code/data used during the initialization. So move everything to init and mark the file as such.
---
Changes in v2:
- Add Stefano's reviewed-by
--- xen/arch/arm/Makefile | 2 +- xen/arch/arm/kernel.c | 32 ++++++++++++++++---------------- 2 files changed, 17 insertions(+), 17 deletions(-)
xen/arch/arm/Makefile +1 -1
@@ -25,7 +25,7 @@ obj-y += guest_walk.o obj-y += hvm.o obj-y += io.o obj-y += irq.o -obj-y += kernel.o +obj-y += kernel.init.o obj-$(CONFIG_LIVEPATCH) += livepatch.o obj-y += mem_access.o obj-y += mm.o
xen/arch/arm/kernel.c +16 -16
@@ -46,7 +46,7 @@ struct minimal_dtb_header {* @paddr: source physical address * @len: length to copy */ -void copy_from_paddr (void *dst,paddr_t paddr,unsigned long len) +void __init copy_from_paddr (void *dst,paddr_t paddr,unsigned long len) {void *src = (void *)FIXMAP_ADDR (FIXMAP_MISC );
@@ -68,8 +68,8 @@ void copy_from_paddr(void *dst, paddr_t paddr, unsigned long len)clear_fixmap (FIXMAP_MISC ); } -static void place_modules (struct kernel_info *info, -paddr_t kernbase,paddr_t kernend) +static void __init place_modules (struct kernel_info *info, +paddr_t kernbase,paddr_t kernend) {/* Align DTB and initrd size to 2Mb. Linux only requires 4 byte alignment */ const struct bootmodule *mod = info->initrd_bootmodule;
@@ -122,7 +122,7 @@ static void place_modules(struct kernel_info *info, info->initrd_paddr = info->dtb_paddr + dtb_len; } -static paddr_t kernel_zimage_place (struct kernel_info *info) +static paddr_t __init kernel_zimage_place (struct kernel_info *info) {paddr_t load_addr;
@@ -154,7 +154,7 @@ static paddr_t kernel_zimage_place(struct kernel_info *info)return load_addr; } -static void kernel_zimage_load (struct kernel_info *info) +static void __init kernel_zimage_load (struct kernel_info *info) {paddr_t load_addr =kernel_zimage_place (info);paddr_t paddr = info->zimage.kernel_addr;
@@ -190,8 +190,8 @@ static void kernel_zimage_load(struct kernel_info *info)/* * Check if the image is a uImage and setup kernel_info */ -static int kernel_uimage_probe (struct kernel_info *info, -paddr_t addr,paddr_t size) +static int __init kernel_uimage_probe (struct kernel_info *info, +paddr_t addr,paddr_t size) {struct {__be32 magic;/* Image Header Magic Number */
@@ -318,8 +318,8 @@ static __init int kernel_decompress(struct bootmodule *mod)/* * Check if the image is a 64-bit Image. */ -static int kernel_zimage64_probe (struct kernel_info *info, -paddr_t addr,paddr_t size) +static int __init kernel_zimage64_probe (struct kernel_info *info, +paddr_t addr,paddr_t size) {/* linux/Documentation/arm64/booting.txt */ struct {
@@ -372,8 +372,8 @@ static int kernel_zimage64_probe(struct kernel_info *info,/* * Check if the image is a 32-bit zImage and setup kernel_info */ -static int kernel_zimage32_probe (struct kernel_info *info, -paddr_t addr,paddr_t size) +static int __init kernel_zimage32_probe (struct kernel_info *info, +paddr_t addr,paddr_t size) {uint32_t zimage[ZIMAGE32_HEADER_LEN /4 ];uint32_t start, end;
@@ -421,7 +421,7 @@ static int kernel_zimage32_probe(struct kernel_info *info,return 0 ; } -static void kernel_elf_load (struct kernel_info *info) +static void __init kernel_elf_load (struct kernel_info *info) {/* * TODO: can the ELF header be used to find the physical address
@@ -444,8 +444,8 @@ static void kernel_elf_load(struct kernel_info *info)free_xenheap_pages (info->elf.kernel_img, info->elf.kernel_order); } -static int kernel_elf_probe (struct kernel_info *info, -paddr_t addr,paddr_t size) +static int __init kernel_elf_probe (struct kernel_info *info, +paddr_t addr,paddr_t size) {int rc;
@@ -496,7 +496,7 @@ err:return rc; } -int kernel_probe (struct kernel_info *info) +int __init kernel_probe (struct kernel_info *info) {struct bootmodule *mod =boot_module_find_by_kind (BOOTMOD_KERNEL );int rc;
@@ -534,7 +534,7 @@ int kernel_probe(struct kernel_info *info)return rc; } -void kernel_load (struct kernel_info *info) +void __init kernel_load (struct kernel_info *info) { info->load (info); }
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 4/7 xen/arm: Drop support for loading ELF Dom0 kernel
In reply to Julien GrallThe code has been around since the beginning of Xen Arm. However, I am not aware of any user and the code is pretty bogus:
1) It is assuming virtual address == physical address.
2) The cache is not cleaned after the Image is loaded but the Image is started with Cache disabled.
3) There are not clear ABI with the guest.
Xen is currently supporting 3 other formats (zImage, Image, U-boot Image) as well as gzip compressed version of each formats. All of them are well documented and widely use.
---
Given the state, I doubt anyone is using the ELF format with Xen on Arm. By dropping this code, it also allows us to remove the built-in libelf (~1.2K lines) from Xen.
Changes in v2:
- Add Stefano's reviewed-by
--- xen/arch/arm/kernel.c | 77 --------------------------------------------------- xen/arch/arm/kernel.h | 10 +------ 2 files changed, 1 insertion(+), 86 deletions(-)
xen/arch/arm/kernel.c +0 -77
@@ -421,81 +421,6 @@ static int __init kernel_zimage32_probe(struct kernel_info *info,return 0 ; } -static void __init kernel_elf_load (struct kernel_info *info) -{ -/* -* TODO: can the ELF header be used to find the physical address -* to load the image to? Instead of assuming virt == phys. -*/ - info->entry = info->elf.parms.virt_entry; - -place_modules (info, - info->elf.parms.virt_kstart, - info->elf.parms.virt_kend); - -printk ("Loading ELF image into guest memory\n" ); - info->elf.elf.dest_base = (void *)(unsigned long )info->elf.parms.virt_kstart; - info->elf.elf.dest_size = - info->elf.parms.virt_kend - info->elf.parms.virt_kstart; - -elf_load_binary (&info->elf.elf); - -printk ("Free temporary kernel buffer\n" ); -free_xenheap_pages (info->elf.kernel_img, info->elf.kernel_order); -} - -static int __init kernel_elf_probe (struct kernel_info *info, -paddr_t addr,paddr_t size) -{ -int rc; - -memset (&info->elf.elf,0 ,sizeof (info->elf.elf)); - - info->elf.kernel_order =get_order_from_bytes (size); - info->elf.kernel_img =alloc_xenheap_pages (info->elf.kernel_order,0 ); -if ( info->elf.kernel_img ==NULL ) -panic ("Cannot allocate temporary buffer for kernel" ); - -copy_from_paddr (info->elf.kernel_img, addr, size); - -if ( (rc =elf_init (&info->elf.elf, info->elf.kernel_img, size )) !=0 ) - goto err; -#ifdef CONFIG_VERBOSE_DEBUG -elf_set_verbose (&info->elf.elf); -#endif -elf_parse_binary (&info->elf.elf); -if ( (rc =elf_xen_parse (&info->elf.elf, &info->elf.parms)) !=0 ) - goto err; - -#ifdef CONFIG_ARM_64 -if (elf_32bit (&info->elf.elf) ) - info->type =DOMAIN_32BIT ; -else if (elf_64bit (&info->elf.elf) ) - info->type =DOMAIN_64BIT ; -else - { -printk ("Unknown ELF class\n" ); - rc = -EINVAL ; - goto err; - } -#endif - - info->load = kernel_elf_load; - -if (elf_check_broken (&info->elf.elf) ) -printk ("Xen: warning: ELF kernel broken: %s\n" , -elf_check_broken (&info->elf.elf)); - -return 0 ; -err: -if (elf_check_broken (&info->elf.elf) ) -printk ("Xen: ELF kernel broken: %s\n" , -elf_check_broken (&info->elf.elf)); - -free_xenheap_pages (info->elf.kernel_img, info->elf.kernel_order); -return rc; -} -int __init kernel_probe (struct kernel_info *info) {struct bootmodule *mod =boot_module_find_by_kind (BOOTMOD_KERNEL );
@@ -528,8 +453,6 @@ int __init kernel_probe(struct kernel_info *info) rc =kernel_uimage_probe (info, mod->start, mod->size);if (rc <0 ) rc =kernel_zimage32_probe (info, mod->start, mod->size); -if (rc <0 ) - rc =kernel_elf_probe (info, mod->start, mod->size);return rc; }
xen/arch/arm/kernel.h +1 -9
@@ -6,7 +6,6 @@#ifndef __ARCH_ARM_KERNEL_H__#define __ARCH_ARM_KERNEL_H__ -#include <xen/libelf.h> #include <xen/device_tree.h> #include <asm/setup.h>
@@ -45,13 +44,6 @@ struct kernel_info {#endif paddr_t start;/* 32-bit zImage only */ } zimage; - -struct { -struct elf_binary elf; -struct elf_dom_parms parms; -unsigned kernel_order; -void *kernel_img; - } elf; }; };
@@ -60,7 +52,7 @@ struct kernel_info {* * Sets in info: * ->type -* ->load hook, and sets loader specific variables ->{zimage,elf} +* ->load hook, and sets loader specific variables ->zimage */ int kernel_probe (struct kernel_info *info);
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 5/7 xen: Don't build libelf for Arm
In reply to Julien GrallNow that ELF support has been dropped to boot Dom0, no-one is using libelf within the hypervisor.
Introduce a config option to select libelf on x86 and keep unselected for Arm.
---
Changes in v2:
- Rename HAS_ELF to NEEDS_LIBELF
--- xen/arch/x86/Kconfig | 1 + xen/common/Kconfig | 3 +++ xen/common/Makefile | 2 +- 3 files changed, 5 insertions(+), 1 deletion(-)
xen/arch/x86/Kconfig +1 -0
@@ -24,6 +24,7 @@ config X86 select HAS_PDX select HAS_UBSAN select HAS_VPCI if !PV_SHIM_EXCLUSIVE + select NEEDS_LIBELF select NUMA config ARCH_DEFCONFIG
xen/common/Kconfig +3 -0
@@ -44,6 +44,9 @@ config HAS_GDBSX config HAS_IOPORTS bool +config NEEDS_LIBELF + bool + config NEEDS_LIST_SORT bool
xen/common/Makefile +1 -1
@@ -78,5 +78,5 @@ obj-$(CONFIG_TMEM) += $(tmem-y) subdir-$(CONFIG_COVERAGE) += coverage subdir-$(CONFIG_UBSAN) += ubsan -subdir-y += libelf +subdir-$(CONFIG_NEEDS_LIBELF) += libelf subdir-$(CONFIG_HAS_DEVICE_TREE) += libfdt
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v2 5/7] xen: Don't build libelf for Arm
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 02.07.18 at 18:19, <[email protected]> wrote:
Now that ELF support has been dropped to boot Dom0, no-one is using libelf within the hypervisor.
Introduce a config option to select libelf on x86 and keep unselected for Arm.
Signed-off-by Julien Grall <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v2 5/7] xen: Don't build libelf for Arm
In reply to Julien GrallQuoted 7 lines · Julien Grall
Now that ELF support has been dropped to boot Dom0, no-one is using libelf within the hypervisor.
Introduce a config option to select libelf on x86 and keep unselected for Arm.
Signed-off-by Julien Grall <[email protected]>
Quoted 49 lines
---
Changes in v2:
- RenameHAS_ELFtoNEEDS_LIBELF--- xen/arch/x86/Kconfig | 1 + xen/common/Kconfig | 3 +++ xen/common/Makefile | 2 +- 3 files changed, 5 insertions(+), 1 deletion(-)xen/arch/x86/Kconfig +1
-0@@ -24,6 +24,7 @@ config X86 select HAS_PDX select HAS_UBSAN select HAS_VPCI if !PV_SHIM_EXCLUSIVE + select NEEDS_LIBELF select NUMA config ARCH_DEFCONFIGxen/common/Kconfig +3
-0@@ -44,6 +44,9 @@ config HAS_GDBSX config HAS_IOPORTS bool +config NEEDS_LIBELF + bool + config NEEDS_LIST_SORT boolxen/common/Makefile +1
-1@@ -78,5 +78,5 @@ obj-$(CONFIG_TMEM) += $(tmem-y) subdir-$(CONFIG_COVERAGE) += coverage subdir-$(CONFIG_UBSAN) += ubsan -subdir-y += libelf +subdir-$(CONFIG_NEEDS_LIBELF) += libelf subdir-$(CONFIG_HAS_DEVICE_TREE) += libfdtSignature · 1 line
2.11.0
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 6/7 xen/libfdt: Put all libfdt in init
In reply to Julien GrallLibfdt is used for:
- Unflatten the Flatten Device-Tree (FDT) blob
- Create Device-Tree for the Hardware-Domain
Both use are done during the initialization of Xen. So move all the libfdt to init.
Note that the runes was borrowed from libelf Makefile.
---
Changes in v2:
- Add Stefano's reviewed-by
--- xen/common/libfdt/Makefile | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
xen/common/libfdt/Makefile +9 -1
@@ -1,5 +1,13 @@ include Makefile.libfdt -obj-y += $(LIBFDT_OBJS) +SECTIONS := text data $(SPECIAL_DATA_SECTIONS) + +obj-y += libfdt.o CFLAGS += -I$(BASEDIR)/include/xen/libfdt/ + +libfdt.o: libfdt-temp.o Makefile + $(OBJCOPY) $(foreach s,$(SECTIONS),--rename-section .$(s)=.init.$(s)) $< $@ + +libfdt-temp.o: $(LIBFDT_OBJS) + $(LD) $(LDFLAGS) -r -o $@ $^
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v2 7/7 xen/arm: setup: Move in init code only used at boot in setup.c
In reply to Julien GrallSome of the functions implemented in setup.c are only used at boot but not yet marked as such.
---
Changes in v2:
- Add Stefano's reviewed-by
--- xen/arch/arm/setup.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
xen/arch/arm/setup.c +5 -5
@@ -175,7 +175,7 @@ static void __init processor_id(void)check_local_cpu_errata (); } -void dt_unreserved_regions (paddr_t s,paddr_t e, +void __init dt_unreserved_regions (paddr_t s,paddr_t e,void (*cb)(paddr_t ,paddr_t ),int first) {int i, nr =fdt_num_mem_rsv (device_tree_flattened);
@@ -201,9 +201,9 @@ void dt_unreserved_regions(paddr_t s, paddr_t e,cb (s, e); } -struct bootmodule *add_boot_module (bootmodule_kind kind, -paddr_t start,paddr_t size, -const char *cmdline) +struct bootmodule __init *add_boot_module (bootmodule_kind kind, +paddr_t start,paddr_t size, +const char *cmdline) {struct bootmodules *mods = &bootinfo.modules;struct bootmodule *mod;
@@ -434,7 +434,7 @@ static paddr_t __init get_xen_paddr(void)return paddr; } -static void init_pdx (void ) +static void __init init_pdx (void ) {paddr_t bank_start, bank_size, bank_end;
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v2 7/7] xen/arm: setup: Move in init code only used at boot in setup.c
Quoted 27 lines · Julien Grall
Some of the functions implemented in
setup.care only used at boot but not yet marked as such.Signed-off-by Julien Grall <[email protected]>Reviewed-by Stefano Stabellini <[email protected]>---
Changes in v2:
- Add Stefano's reviewed-by--- xen/arch/arm/setup.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)xen/arch/arm/setup.c +1
-1@@ -175,7 +175,7 @@ static void __init processor_id(void)check_local_cpu_errata (); } -void dt_unreserved_regions (paddr_t s,paddr_t e, +void __init dt_unreserved_regions (paddr_t s,paddr_t e,void (*cb)(paddr_t ,paddr_t ),int first) {int i, nr =fdt_num_mem_rsv (device_tree_flattened);
xen/arch/arm/setup.c void dt_unreserved_regions(paddr_t s, paddr_t e, · line 206
Quoted 9 lines
xen/arch/arm/setup.c +3
-3@@ -201,9 +201,9 @@ void dt_unreserved_regions(paddr_t s, paddr_t e,cb (s, e); } -struct bootmodule *add_boot_module (bootmodule_kind kind, -paddr_t start,paddr_t size, -const char *cmdline) +struct bootmodule __init *add_boot_module (bootmodule_kind kind, +paddr_t start,paddr_t size, +const char *cmdline)
I have just spotted this minor alignment issue. I fixed on commit.
Quoted 15 lines
xen/arch/arm/setup.c +1
-1{struct bootmodules *mods = &bootinfo.modules;struct bootmodule *mod;@@ -434,7 +434,7 @@ static paddr_t __init get_xen_paddr(void)return paddr; } -static void init_pdx (void ) +static void __init init_pdx (void ) {paddr_t bank_start, bank_size, bank_end;Signature · 1 line
2.11.0
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel