Static shared memory followup v2 - pt1
cover Static shared memory followup v2 - pt1
This serie is a partial rework of this other serie:
https://patchwork.kernel.org/project/xen-devel/cover/[email protected]/
The original serie is addressing an issue of the static shared memory feature that impacts the memory footprint of other component when the feature is enabled, another issue impacts the device tree generation for the guests when the feature is enabled and used and the last one is a missing feature that is the option to have a static shared memory region that is not from the host address space.
This serie is handling some comment on the original serie and it is splitting the rework in two part, this first part is addressing the memory footprint issue and the device tree generation, there will be a following serie addressing the last missing feature soon.
Luca Fancellu (7):
xen/arm: Introduce a generic way to access memory bank structures xen/arm: Conditional compilation of kernel_info.shm_mem member xen/arm: Introduce helper for static memory pages xen/arm: Avoid code duplication in find_unallocated_memory xen/arm: Avoid code duplication in check_reserved_regions_overlap xen/arm: Reduce struct membank size on static shared memory xen/arm: List static shared memory regions as /memory nodes
Penny Zheng (4):
xen/arm: remove stale addr_cells/size_cells in assign_shared_memory xen/arm: avoid repetitive checking in process_shm_node xen/arm: remove shm holes for extended regions
xen/arm: fix duplicate /reserved-memory node in Dom0
xen/arch/arm/acpi/domain_build.c | 6 +- xen/arch/arm/arm32/mmu/mm.c | 68 ++++-- xen/arch/arm/arm64/mmu/mm.c | 4 +- xen/arch/arm/bootfdt.c | 28 +-- xen/arch/arm/dom0less-build.c | 24 +- xen/arch/arm/domain_build.c | 187 +++++++++------- xen/arch/arm/efi/efi-boot.h | 8 +- xen/arch/arm/efi/efi-dom0.c | 13 +- xen/arch/arm/include/asm/domain_build.h | 4 +- xen/arch/arm/include/asm/kernel.h | 19 +- xen/arch/arm/include/asm/setup.h | 81 ++++++- xen/arch/arm/include/asm/static-memory.h | 12 + xen/arch/arm/include/asm/static-shmem.h | 49 +++- xen/arch/arm/kernel.c | 12 +- xen/arch/arm/setup.c | 97 +++++--- xen/arch/arm/static-memory.c | 35 ++- xen/arch/arm/static-shmem.c | 270 +++++++++++++++++------ 17 files changed, 634 insertions(+), 283 deletions(-)
Signature · 1 line
2.34.1
PATCH 1/11 xen/arm: remove stale addr_cells/size_cells in assign_shared_memory
From: Penny Zheng <[email protected]>
Function parameters {addr_cells,size_cells} are stale parameters in assign_shared_memory, so we shall remove them.
---
v1:
- This is this patch: https://patchwork.kernel.org/project/xen-devel/patch/[email protected]/
--- xen/arch/arm/static-shmem.c | 2 -- 1 file changed, 2 deletions(-)
xen/arch/arm/static-shmem.c +0 -2
@@ -90,7 +90,6 @@ static mfn_t __init acquire_shared_memory_bank(struct domain *d, }static int __init assign_shared_memory (struct domain *d, -uint32_t addr_cells,uint32_t size_cells,paddr_t pbase,paddr_t psize,paddr_t gbase) {
@@ -252,7 +251,6 @@ int __init process_shm(struct domain *d, struct kernel_info *kinfo,* specified, so they should be assigned to dom_io. */ ret =assign_shared_memory (owner_dom_io ? dom_io : d, - addr_cells, size_cells, pbase, psize, gbase);if ( ret )return ret;
Signature · 1 line
2.34.1
PATCH 2/11 xen/arm: avoid repetitive checking in process_shm_node
In reply to Luca FancelluFrom: Penny Zheng <[email protected]>
Putting overlap and overflow checking in the loop is causing repetitive operation, so this commit extracts both checking outside the loop.
---
v1:
- Rework of https://patchwork.kernel.org/project/xen-devel/patch/[email protected]/
- use strncmp to match the branch above
- drop Michal R-by given the change
--- xen/arch/arm/static-shmem.c | 39 +++++++++++++++---------------------- 1 file changed, 16 insertions(+), 23 deletions(-)
xen/arch/arm/static-shmem.c +16 -23
@@ -349,7 +349,7 @@ int __init process_shm_node(const void *fdt, int node, uint32_t address_cells, {const struct fdt_property *prop, *prop_id, *prop_role;const __be32 *cell; -paddr_t paddr, gaddr, size; +paddr_t paddr, gaddr, size, end;struct meminfo *mem = &bootinfo.reserved_mem;unsigned int i;int len;
@@ -422,6 +422,13 @@ int __init process_shm_node(const void *fdt, int node, uint32_t address_cells,return -EINVAL ; } + end = paddr + size; +if ( end <= paddr ) + { +printk ("fdt: static shared memory region %s overflow\n" , shm_id); +return -EINVAL ; + } +for ( i =0 ; i < mem->nr_banks; i++ ) {/*
@@ -441,30 +448,13 @@ int __init process_shm_node(const void *fdt, int node, uint32_t address_cells,return -EINVAL ; } } +else if (strncmp (shm_id, mem->bank[i].shm_id,MAX_SHM_ID_LENGTH ) !=0 ) +continue ;else { -paddr_t end = paddr + size; -paddr_t bank_end = mem->bank[i].start + mem->bank[i].size; - -if ( (end <= paddr) || (bank_end <= mem->bank[i].start) ) - { -printk ("fdt: static shared memory region %s overflow\n" , shm_id); -return -EINVAL ; - } - -if (check_reserved_regions_overlap (paddr, size) ) -return -EINVAL ; -else - { -if (strcmp (shm_id, mem->bank[i].shm_id) !=0 ) -continue ; -else - { -printk ("fdt: different shared memory region could not share the same shm ID %s\n" , - shm_id); -return -EINVAL ; - } - } +printk ("fdt: different shared memory region could not share the same shm ID %s\n" , + shm_id); +return -EINVAL ; } }
@@ -472,6 +462,9 @@ int __init process_shm_node(const void *fdt, int node, uint32_t address_cells, {if ( i <NR_MEM_BANKS ) { +if (check_reserved_regions_overlap (paddr, size) ) +return -EINVAL ; +/* Static shared memory shall be reserved from any other use. */ safe_strcpy (mem->bank[mem->nr_banks].shm_id, shm_id); mem->bank[mem->nr_banks].start = paddr;
Signature · 1 line
2.34.1
Re: [PATCH 02/11] xen/arm: avoid repetitive checking in process_shm_node
Hi Luca,
Quoted 7 lines · Luca Fancellu
From: Penny Zheng <[email protected]>
Putting overlap and overflow checking in the loop is causing repetitive operation, so this commit extracts both checking outside the loop.
Quoted 6 lines
Signed-off-by Penny Zheng <[email protected]>Signed-off-by Luca Fancellu <[email protected]>---
v1:
- Rework of https://patchwork.kernel.org/project/xen-devel/patch/[email protected]/
- use strncmp to match the branch above
I don't understand why we need strncmp if we already validated that shm_id is NULL terminated within MAX_SHM_ID_LENGTH at the beginning of the function with strnlen.
Other than that:
~Michal
PATCH 3/11 xen/arm: Introduce a generic way to access memory bank structures
In reply to Luca FancelluCurrently the 'stuct meminfo' is defining a static defined array of 'struct membank' of NR_MEM_BANKS elements, some feature like shared memory don't require such amount of memory allocation but might want to reuse existing code to manipulate this kind of structure that is just as 'struct meminfo' but less bulky.
For this reason introduce a generic way to access this kind of structure using a new stucture 'struct membanks', which implements all the fields needed by a structure related to memory banks without the need to specify at build time the size of the 'struct membank' array.
Modify 'struct meminfo' to implement the field related to the new introduced structure, given the change all usage of this structure are updated in this way:
- code accessing bootinfo.{mem,reserved_mem,acpi} field now uses 3 new introduced static inline helpers to access the new field of 'struct meminfo' named 'common'.
- code accessing 'struct kernel_info *' member 'mem' now use the new introduced macro 'kernel_info_get_mem(...)' to access the new field of 'struct meminfo' named 'common'.
Constify pointers where needed.
--- xen/arch/arm/acpi/domain_build.c | 6 +- xen/arch/arm/arm32/mmu/mm.c | 44 +++++----- xen/arch/arm/arm64/mmu/mm.c | 2 +- xen/arch/arm/bootfdt.c | 27 +++--- xen/arch/arm/dom0less-build.c | 18 ++-- xen/arch/arm/domain_build.c | 106 +++++++++++++----------- xen/arch/arm/efi/efi-boot.h | 8 +- xen/arch/arm/efi/efi-dom0.c | 13 +-- xen/arch/arm/include/asm/domain_build.h | 2 +- xen/arch/arm/include/asm/kernel.h | 9 ++ xen/arch/arm/include/asm/setup.h | 40 ++++++++- xen/arch/arm/include/asm/static-shmem.h | 4 +- xen/arch/arm/kernel.c | 12 +-- xen/arch/arm/setup.c | 58 +++++++------ xen/arch/arm/static-memory.c | 27 +++--- xen/arch/arm/static-shmem.c | 34 ++++---- 16 files changed, 243 insertions(+), 167 deletions(-)
xen/arch/arm/acpi/domain_build.c +3 -3
@@ -444,14 +444,14 @@ static int __init acpi_create_fadt(struct domain *d, struct membank tbl_add[]) }static int __init estimate_acpi_efi_size (struct domain *d, -struct kernel_info *kinfo) +const struct kernel_info *kinfo) {size_t efi_size, acpi_size, madt_size;u64 addr;struct acpi_table_rsdp *rsdp_tbl;struct acpi_table_header *table; - efi_size =estimate_efi_size (kinfo->mem.nr_banks); + efi_size =estimate_efi_size (kernel_info_get_mem (kinfo)->nr_banks); acpi_size =ROUNDUP (sizeof (struct acpi_table_fadt ),8 ); acpi_size +=ROUNDUP (sizeof (struct acpi_table_stao ),8 );
@@ -546,7 +546,7 @@ int __init prepare_acpi(struct domain *d, struct kernel_info *kinfo)acpi_map_other_tables (d);acpi_create_efi_system_table (d, tbl_add); -acpi_create_efi_mmap_table (d, &kinfo->mem, tbl_add); +acpi_create_efi_mmap_table (d,kernel_info_get_mem (kinfo), tbl_add);/* Map the EFI and ACPI tables to Dom0 */ rc = map_regions_p2mt(d,
xen/arch/arm/arm32/mmu/mm.c +24 -20
102 lines not on this page · raw message
xen/arch/arm/arm64/mmu/mm.c +1 -1
@@ -194,7 +194,7 @@ static void __init setup_directmap_mappings(unsigned long base_mfn,void __init setup_mm (void ) { -const struct meminfo *banks = &bootinfo.mem; +const struct membanks *banks =bootinfo_get_mem ();paddr_t ram_start =INVALID_PADDR ;paddr_t ram_end =0 ;paddr_t ram_size =0 ;
xen/arch/arm/bootfdt.c +14 -13
@@ -107,14 +107,14 @@ void __init device_tree_get_reg(const __be32 **cell, uint32_t address_cells,static int __init device_tree_get_meminfo (const void *fdt,int node,const char *prop_name,u32 address_cells,u32 size_cells, -void *data,enum membank_type type) +struct membanks *mem, +enum membank_type type) {const struct fdt_property *prop;unsigned int i, banks;const __be32 *cell;u32 reg_cells = address_cells + size_cells;paddr_t start, size; -struct meminfo *mem = data;if ( !device_tree_node_is_available (fdt, node) )return 0 ;
@@ -133,10 +133,10 @@ static int __init device_tree_get_meminfo(const void *fdt, int node, cell = (const __be32 *)prop->data; banks =fdt32_to_cpu (prop->len) / (reg_cells *sizeof (u32)); -for ( i =0 ; i < banks && mem->nr_banks <NR_MEM_BANKS ; i++ ) +for ( i =0 ; i < banks && mem->nr_banks < mem->max_banks; i++ ) {device_tree_get_reg (&cell, address_cells, size_cells, &start, &size); -if ( mem == &bootinfo.reserved_mem && +if ( mem ==bootinfo_get_reserved_mem () &&check_reserved_regions_overlap (start, size) )return -EINVAL ;/* Some DT may describe empty bank, ignore them */
@@ -231,10 +231,10 @@ int __init device_tree_for_each_node(const void *fdt, int node,static int __init process_memory_node (const void *fdt,int node,const char *name,int depth,u32 address_cells,u32 size_cells, -void *data) +struct membanks *mem) {return device_tree_get_meminfo (fdt, node,"reg" , address_cells, size_cells, - data,MEMBANK_DEFAULT ); + mem,MEMBANK_DEFAULT ); } static int __init process_reserved_memory_node(const void *fdt, int node,
@@ -259,7 +259,7 @@ static int __init process_reserved_memory(const void *fdt, int node, {return device_tree_for_each_node (fdt, node, process_reserved_memory_node, - &bootinfo.reserved_mem); +bootinfo_get_reserved_mem ()); } static void __init process_multiboot_node(const void *fdt, int node,
@@ -358,7 +358,7 @@ static int __init process_chosen_node(const void *fdt, int node, rc =device_tree_get_meminfo (fdt, node,"xen,static-heap" , address_cells, size_cells, - &bootinfo.reserved_mem, +bootinfo_get_reserved_mem (),MEMBANK_STATIC_HEAP );if ( rc )return rc;
@@ -420,7 +420,7 @@ static int __init process_domain_node(const void *fdt, int node,return 0 ;return device_tree_get_meminfo (fdt, node,"xen,static-mem" , address_cells, - size_cells, &bootinfo.reserved_mem, + size_cells,bootinfo_get_reserved_mem (),MEMBANK_STATIC_DOMAIN ); }
@@ -438,7 +438,7 @@ static int __init early_scan_node(const void *fdt,if ( !efi_enabled (EFI_BOOT ) &&device_tree_node_matches (fdt, node,"memory" ) ) rc =process_memory_node (fdt, node, name, depth, - address_cells, size_cells, &bootinfo.mem); + address_cells, size_cells,bootinfo_get_mem ());else if ( depth ==1 && !dt_node_cmp (name,"reserved-memory" ) ) rc =process_reserved_memory (fdt, node, name, depth, address_cells, size_cells);
@@ -459,8 +459,8 @@ static int __init early_scan_node(const void *fdt,static void __init early_print_info (void ) { -struct meminfo *mi = &bootinfo.mem; -struct meminfo *mem_resv = &bootinfo.reserved_mem; +const struct membanks *mi =bootinfo_get_mem (); +const struct membanks *mem_resv =bootinfo_get_reserved_mem ();struct bootmodules *mods = &bootinfo.modules;struct bootcmdlines *cmds = &bootinfo.cmdlines;unsigned int i, j;
@@ -537,6 +537,7 @@ static void __init swap_memory_node(void *_a, void *_b, size_t size)*/ size_t __init boot_fdt_info (const void *fdt,paddr_t paddr) { +struct membanks *mem =bootinfo_get_mem ();int ret; ret =fdt_check_header (fdt);
@@ -554,7 +555,7 @@ size_t __init boot_fdt_info(const void *fdt, paddr_t paddr)* bank in memory first. There is no requirement that the DT will provide * the banks sorted in ascending order. So sort them through. */ -sort (bootinfo.mem.bank, bootinfo.mem.nr_banks,sizeof (struct membank ), +sort (mem->bank, mem->nr_banks,sizeof (struct membank ), cmp_memory_node, swap_memory_node);early_print_info ();
xen/arch/arm/dom0less-build.c +10 -8
@@ -50,6 +50,7 @@ bool __init is_dom0less_mode(void)static void __init allocate_memory (struct domain *d,struct kernel_info *kinfo) { +struct membanks *mem =kernel_info_get_mem (kinfo);unsigned int i;paddr_t bank_size;
@@ -57,7 +58,7 @@ static void __init allocate_memory(struct domain *d, struct kernel_info *kinfo)/* Don't want format this as PRIpaddr (16 digit hex) */ (unsigned long)(kinfo->unassigned_mem >> 20), d); - kinfo->mem.nr_banks =0 ; + mem->nr_banks =0 ; bank_size =MIN (GUEST_RAM0_SIZE , kinfo->unassigned_mem);if ( !allocate_bank_memory (d, kinfo,gaddr_to_gfn (GUEST_RAM0_BASE ), bank_size) )
@@ -71,15 +72,15 @@ static void __init allocate_memory(struct domain *d, struct kernel_info *kinfo)if ( kinfo->unassigned_mem ) goto fail; -for ( i =0 ; i < kinfo->mem.nr_banks; i++ ) +for ( i =0 ; i < mem->nr_banks; i++ ) {printk (XENLOG_INFO "%pd BANK[%d] %#" PRIpaddr"-%#" PRIpaddr" (%ldMB)\n" , d, i, - kinfo->mem.bank[i].start, - kinfo->mem.bank[i].start + kinfo->mem.bank[i].size, + mem->bank[i].start, + mem->bank[i].start + mem->bank[i].size,/* Don't want format this as PRIpaddr (16 digit hex) */ - (unsigned long )(kinfo->mem.bank[i].size >>20 )); + (unsigned long )(mem->bank[i].size >>20 )); }return ;
@@ -641,12 +642,13 @@ static int __init prepare_dtb_domU(struct domain *d, struct kernel_info *kinfo)if ( ret ) goto err; - ret =make_memory_node (d, kinfo->fdt, addrcells, sizecells, &kinfo->mem); + ret =make_memory_node (d, kinfo->fdt, addrcells, sizecells, +kernel_info_get_mem (kinfo));if ( ret ) goto err; ret =make_resv_memory_node (d, kinfo->fdt, addrcells, sizecells, - &kinfo->shm_mem); + &kinfo->shm_mem.common);if ( ret ) goto err;
@@ -741,7 +743,7 @@ static int __init alloc_xenstore_evtchn(struct domain *d)static int __init construct_domU (struct domain *d,const struct dt_device_node *node) { -struct kernel_info kinfo = {}; +struct kernel_info kinfo =KERNEL_INFO_INIT ;const char *dom0less_enhanced;int rc;u64 mem;
xen/arch/arm/domain_build.c +58 -48
308 lines not on this page · raw message
xen/arch/arm/efi/efi-boot.h +4 -4
@@ -157,14 +157,14 @@ static void __init *lookup_fdt_config_table(EFI_SYSTEM_TABLE *sys_table)return fdt; } -static bool __init meminfo_add_bank (struct meminfo *mem, +static bool __init meminfo_add_bank (struct membanks *mem,EFI_MEMORY_DESCRIPTOR *desc) {struct membank *bank;paddr_t start = desc->PhysicalStart;paddr_t size = desc->NumberOfPages *EFI_PAGE_SIZE ; -if ( mem->nr_banks >=NR_MEM_BANKS ) +if ( mem->nr_banks >= mem->max_banks )return false;#ifdef CONFIG_ACPI if (check_reserved_regions_overlap (start, size) )
@@ -198,7 +198,7 @@ static EFI_STATUS __init efi_process_memory_map_bootinfo(EFI_MEMORY_DESCRIPTOR * (desc_ptr->Type == EfiBootServicesCode || desc_ptr->Type == EfiBootServicesData))) ) { -if ( !meminfo_add_bank (&bootinfo.mem, desc_ptr) ) +if ( !meminfo_add_bank (bootinfo_get_mem (), desc_ptr) ) { PrintStr(L"Warning: All " __stringify(NR_MEM_BANKS)" bootinfo mem banks exhausted.\r\n" );
@@ -208,7 +208,7 @@ static EFI_STATUS __init efi_process_memory_map_bootinfo(EFI_MEMORY_DESCRIPTOR *#ifdef CONFIG_ACPI else if ( desc_ptr->Type == EfiACPIReclaimMemory ) { -if ( !meminfo_add_bank (&bootinfo.acpi, desc_ptr) ) +if ( !meminfo_add_bank (bootinfo_get_acpi (), desc_ptr) ) { PrintStr(L"Error: All " __stringify(NR_MEM_BANKS)" acpi meminfo mem banks exhausted.\r\n" );
xen/arch/arm/efi/efi-dom0.c +7 -6
@@ -44,7 +44,7 @@ size_t __init estimate_efi_size(unsigned int mem_nr_banks)unsigned int acpi_mem_nr_banks =0 ;if ( !acpi_disabled ) - acpi_mem_nr_banks = bootinfo.acpi.nr_banks; + acpi_mem_nr_banks =bootinfo_get_acpi ()->nr_banks; size =ROUNDUP (est_size + ect_size + fw_vendor_size,8 );/* plus 1 for new created tables */
@@ -107,9 +107,10 @@ static void __init fill_efi_memory_descriptor(EFI_MEMORY_DESCRIPTOR *desc, }void __init acpi_create_efi_mmap_table (struct domain *d, -const struct meminfo *mem, +const struct membanks *mem,struct membank tbl_add[]) { +const struct membanks *acpi =bootinfo_get_acpi ();EFI_MEMORY_DESCRIPTOR *desc;unsigned int i;u8 *base_ptr;
@@ -122,10 +123,10 @@ void __init acpi_create_efi_mmap_table(struct domain *d,fill_efi_memory_descriptor (desc, EfiConventionalMemory, mem->bank[i].start, mem->bank[i].size); -for ( i =0 ; i < bootinfo.acpi.nr_banks; i++, desc++ ) +for ( i =0 ; i < acpi->nr_banks; i++, desc++ )fill_efi_memory_descriptor (desc, EfiACPIReclaimMemory, - bootinfo.acpi.bank[i].start, - bootinfo.acpi.bank[i].size); + acpi->bank[i].start, + acpi->bank[i].size);fill_efi_memory_descriptor (desc, EfiACPIReclaimMemory, d->arch.efi_acpi_gpa, d->arch.efi_acpi_len);
@@ -133,7 +134,7 @@ void __init acpi_create_efi_mmap_table(struct domain *d, tbl_add[TBL_MMAP ].start = d->arch.efi_acpi_gpa +acpi_get_table_offset (tbl_add,TBL_MMAP ); tbl_add[TBL_MMAP ].size =sizeof (EFI_MEMORY_DESCRIPTOR ) - * (mem->nr_banks + bootinfo.acpi.nr_banks +1 ); + * (mem->nr_banks + acpi->nr_banks +1 ); }/* Create /hypervisor/uefi node for efi properties. */
xen/arch/arm/include/asm/domain_build.h +1 -1
@@ -15,7 +15,7 @@ int make_cpus_node(const struct domain *d, void *fdt);int make_hypervisor_node (struct domain *d,const struct kernel_info *kinfo,int addrcells,int sizecells);int make_memory_node (const struct domain *d,void *fdt,int addrcells, -int sizecells,struct meminfo *mem); +int sizecells,const struct membanks *mem);int make_psci_node (void *fdt);int make_timer_node (const struct kernel_info *kinfo);void evtchn_allocate (struct domain *d);
xen/arch/arm/include/asm/kernel.h +9 -0
@@ -78,6 +78,15 @@ struct kernel_info { }; }; +#define kernel_info_get_mem (kinfo) \ + (&(kinfo)->mem.common) + +#define KERNEL_INFO_INIT \ +{ \ + .mem.common.max_banks = NR_MEM_BANKS, \ + .shm_mem.common.max_banks = NR_MEM_BANKS, \ +} +/* * Probe the kernel to detemine its type and select a loader. *
xen/arch/arm/include/asm/setup.h +38 -2
@@ -56,8 +56,14 @@ struct membank {#endif }; -struct meminfo { +struct membanks {unsigned int nr_banks; +unsigned int max_banks; +struct membank bank[]; +}; + +struct meminfo { +struct membanks common;struct membank bank[NR_MEM_BANKS ]; };
@@ -107,6 +113,19 @@ struct bootinfo {bool static_heap; }; +#ifdef CONFIG_ACPI +#define BOOTINFO_ACPI_INIT .acpi.common.max_banks = NR_MEM_BANKS, +#else +#define BOOTINFO_ACPI_INIT +#endif + +#define BOOTINFO_INIT \ +{ \ + .mem.common.max_banks = NR_MEM_BANKS, \ + .reserved_mem.common.max_banks = NR_MEM_BANKS, \ + BOOTINFO_ACPI_INIT \ +} +struct map_range_data {struct domain *d;
@@ -122,6 +141,23 @@ extern struct bootinfo bootinfo;extern domid_t max_init_domid; +static inline struct membanks *bootinfo_get_mem (void ) +{ +return &bootinfo.mem.common; +} + +static inline struct membanks *bootinfo_get_reserved_mem (void ) +{ +return &bootinfo.reserved_mem.common; +} + +#ifdef CONFIG_ACPI +static inline struct membanks *bootinfo_get_acpi (void ) +{ +return &bootinfo.acpi.common; +} +#endif +void copy_from_paddr (void *dst,paddr_t paddr,unsigned long len);size_t estimate_efi_size (unsigned int mem_nr_banks);
@@ -130,7 +166,7 @@ void acpi_create_efi_system_table(struct domain *d, struct membank tbl_add[]);void acpi_create_efi_mmap_table (struct domain *d, -const struct meminfo *mem, +const struct membanks *mem,struct membank tbl_add[]);int acpi_make_efi_nodes (void *fdt,struct membank tbl_add[]);
xen/arch/arm/include/asm/static-shmem.h +2 -2
@@ -8,7 +8,7 @@#ifdef CONFIG_STATIC_SHM int make_resv_memory_node (const struct domain *d,void *fdt,int addrcells, -int sizecells,const struct meminfo *mem); +int sizecells,const struct membanks *mem);int process_shm (struct domain *d,struct kernel_info *kinfo,const struct dt_device_node *node);
@@ -28,7 +28,7 @@ int process_shm_node(const void *fdt, int node, uint32_t address_cells,static inline int make_resv_memory_node (const struct domain *d,void *fdt,int addrcells,int sizecells, -const struct meminfo *mem) +const struct membanks *mem) {return 0 ; }
xen/arch/arm/kernel.c +7 -5
@@ -45,13 +45,14 @@ static void __init place_modules(struct kernel_info *info, {/* Align DTB and initrd size to 2Mb. Linux only requires 4 byte alignment */ const struct bootmodule *mod = info->initrd_bootmodule; +const struct membanks *mem =kernel_info_get_mem (info);const paddr_t initrd_len =ROUNDUP (mod ? mod->size :0 ,MB (2 ));const paddr_t dtb_len =ROUNDUP (fdt_totalsize (info->fdt),MB (2 ));const paddr_t modsize = initrd_len + dtb_len;/* Convenient */ -const paddr_t rambase = info->mem.bank[0 ].start; -const paddr_t ramsize = info->mem.bank[0 ].size; +const paddr_t rambase = mem->bank[0 ].start; +const paddr_t ramsize = mem->bank[0 ].size;const paddr_t ramend = rambase + ramsize;const paddr_t kernsize =ROUNDUP (kernend,MB (2 )) - kernbase;const paddr_t ram128mb = rambase +MB (128 );
@@ -96,11 +97,12 @@ static void __init place_modules(struct kernel_info *info,static paddr_t __init kernel_zimage_place (struct kernel_info *info) { +const struct membanks *mem =kernel_info_get_mem (info);paddr_t load_addr;#ifdef CONFIG_ARM_64 if ( (info->type ==DOMAIN_64BIT ) && (info->zimage.start ==0 ) ) -return info->mem.bank[0 ].start + info->zimage.text_offset; +return mem->bank[0 ].start + info->zimage.text_offset;#endif /*
@@ -113,8 +115,8 @@ static paddr_t __init kernel_zimage_place(struct kernel_info *info) {paddr_t load_end; - load_end = info->mem.bank[0 ].start + info->mem.bank[0 ].size; - load_end =MIN (info->mem.bank[0 ].start +MB (128 ), load_end); + load_end = mem->bank[0 ].start + mem->bank[0 ].size; + load_end =MIN (mem->bank[0 ].start +MB (128 ), load_end); load_addr = load_end - info->zimage.len;/* Align to 2MB */
xen/arch/arm/setup.c +32 -26
144 lines not on this page · raw message
xen/arch/arm/static-memory.c +15 -12
@@ -85,6 +85,7 @@ static int __init parse_static_mem_prop(const struct dt_device_node *node,void __init allocate_static_memory (struct domain *d,struct kernel_info *kinfo,const struct dt_device_node *node) { +struct membanks *mem =kernel_info_get_mem (kinfo);u32 addr_cells, size_cells, reg_cells;unsigned int nr_banks, gbank, bank =0 ;const uint64_t rambase[] =GUEST_RAM_BANK_BASES ;
@@ -106,7 +107,7 @@ void __init allocate_static_memory(struct domain *d, struct kernel_info *kinfo,*/ gbank =0 ; gsize = ramsize[gbank]; - kinfo->mem.bank[gbank].start = rambase[gbank]; + mem->bank[gbank].start = rambase[gbank]; nr_banks = length / (reg_cells *sizeof (u32));for ( ; bank < nr_banks; bank++ )
@@ -122,7 +123,7 @@ void __init allocate_static_memory(struct domain *d, struct kernel_info *kinfo,while (1 ) {/* Map as much as possible the static range to the guest bank */ -if ( !append_static_memory_to_bank (d, &kinfo->mem.bank[gbank], smfn, +if ( !append_static_memory_to_bank (d, &mem->bank[gbank], smfn,min (psize, gsize)) ) goto fail;
@@ -153,14 +154,14 @@ void __init allocate_static_memory(struct domain *d, struct kernel_info *kinfo,/* Update to the next guest bank. */ gbank++; gsize = ramsize[gbank]; - kinfo->mem.bank[gbank].start = rambase[gbank]; + mem->bank[gbank].start = rambase[gbank]; } } tot_size += psize; } - kinfo->mem.nr_banks = ++gbank; + mem->nr_banks = ++gbank; kinfo->unassigned_mem -= tot_size;/*
@@ -190,6 +191,7 @@ void __init allocate_static_memory(struct domain *d, struct kernel_info *kinfo,void __init assign_static_memory_11 (struct domain *d,struct kernel_info *kinfo,const struct dt_device_node *node) { +struct membanks *mem =kernel_info_get_mem (kinfo);u32 addr_cells, size_cells, reg_cells;unsigned int nr_banks, bank =0 ;const __be32 *cell;
@@ -206,7 +208,7 @@ void __init assign_static_memory_11(struct domain *d, struct kernel_info *kinfo, reg_cells = addr_cells + size_cells; nr_banks = length / (reg_cells *sizeof (u32)); -if ( nr_banks >NR_MEM_BANKS ) +if ( nr_banks > mem->max_banks ) {printk (XENLOG_ERR "%pd: exceed max number of supported guest memory banks.\n" , d);
@@ -224,15 +226,15 @@ void __init assign_static_memory_11(struct domain *d, struct kernel_info *kinfo, d, bank, pbase, pbase + psize);/* One guest memory bank is matched with one physical memory bank. */ - kinfo->mem.bank[bank].start = pbase; -if ( !append_static_memory_to_bank (d, &kinfo->mem.bank[bank], + mem->bank[bank].start = pbase; +if ( !append_static_memory_to_bank (d, &mem->bank[bank], smfn, psize) ) goto fail; kinfo->unassigned_mem -= psize; } - kinfo->mem.nr_banks = nr_banks; + mem->nr_banks = nr_banks;/* * The property 'memory' should match the amount of memory given to
@@ -257,14 +259,15 @@ void __init assign_static_memory_11(struct domain *d, struct kernel_info *kinfo,/* Static memory initialization */ void __init init_staticmem_pages (void ) { +const struct membanks *reserved_mem =bootinfo_get_reserved_mem ();unsigned int bank; -for ( bank =0 ; bank < bootinfo.reserved_mem.nr_banks; bank++ ) +for ( bank =0 ; bank < reserved_mem->nr_banks; bank++ ) { -if ( bootinfo.reserved_mem.bank[bank].type ==MEMBANK_STATIC_DOMAIN ) +if ( reserved_mem->bank[bank].type ==MEMBANK_STATIC_DOMAIN ) { -mfn_t bank_start =_mfn (PFN_UP (bootinfo.reserved_mem.bank[bank].start)); -unsigned long bank_pages =PFN_DOWN (bootinfo.reserved_mem.bank[bank].size); +mfn_t bank_start =_mfn (PFN_UP (reserved_mem->bank[bank].start)); +unsigned long bank_pages =PFN_DOWN (reserved_mem->bank[bank].size);mfn_t bank_end =mfn_add (bank_start, bank_pages);if (mfn_x (bank_end) <=mfn_x (bank_start) )
xen/arch/arm/static-shmem.c +18 -16
@@ -10,22 +10,23 @@ static int __init acquire_nr_borrower_domain(struct domain *d, paddr_t pbase, paddr_t psize, unsigned long *nr_borrowers) { + const struct membanks *reserved_mem = bootinfo_get_reserved_mem();unsigned int bank;/* Iterate reserved memory to find requested shm bank. */ -for ( bank =0 ; bank < bootinfo.reserved_mem.nr_banks; bank++ ) +for ( bank =0 ; bank < reserved_mem->nr_banks; bank++ ) { -paddr_t bank_start = bootinfo.reserved_mem.bank[bank].start; -paddr_t bank_size = bootinfo.reserved_mem.bank[bank].size; +paddr_t bank_start = reserved_mem->bank[bank].start; +paddr_t bank_size = reserved_mem->bank[bank].size;if ( (pbase == bank_start) && (psize == bank_size) )break ; } -if ( bank == bootinfo.reserved_mem.nr_banks ) +if ( bank == reserved_mem->nr_banks )return -ENOENT ; - *nr_borrowers = bootinfo.reserved_mem.bank[bank].nr_shm_borrowers; + *nr_borrowers = reserved_mem->bank[bank].nr_shm_borrowers;return 0 ; }
@@ -157,17 +158,17 @@ static int __init assign_shared_memory(struct domain *d,return ret; } -static int __init append_shm_bank_to_domain (struct kernel_info *kinfo, +static int __init append_shm_bank_to_domain (struct membanks *shm_mem,paddr_t start,paddr_t size,const char *shm_id) { -if ( kinfo->shm_mem.nr_banks >=NR_MEM_BANKS ) +if ( shm_mem->nr_banks >= shm_mem->max_banks )return -ENOMEM ; - kinfo->shm_mem.bank[kinfo->shm_mem.nr_banks].start = start; - kinfo->shm_mem.bank[kinfo->shm_mem.nr_banks].size = size; -safe_strcpy (kinfo->shm_mem.bank[kinfo->shm_mem.nr_banks].shm_id, shm_id); - kinfo->shm_mem.nr_banks++; + shm_mem->bank[shm_mem->nr_banks].start = start; + shm_mem->bank[shm_mem->nr_banks].size = size; +safe_strcpy (shm_mem->bank[shm_mem->nr_banks].shm_id, shm_id); + shm_mem->nr_banks++;return 0 ; }
@@ -269,7 +270,8 @@ int __init process_shm(struct domain *d, struct kernel_info *kinfo,* Record static shared memory region info for later setting * up shm-node in guest device tree. */ - ret =append_shm_bank_to_domain (kinfo, gbase, psize, shm_id); + ret =append_shm_bank_to_domain (&kinfo->shm_mem.common, gbase, psize, + shm_id);if ( ret )return ret; }
@@ -279,7 +281,7 @@ int __init process_shm(struct domain *d, struct kernel_info *kinfo,static int __init make_shm_memory_node (const struct domain *d,void *fdt,int addrcells,int sizecells, -const struct meminfo *mem) +const struct membanks *mem) {unsigned int i =0 ;int res =0 ;
@@ -350,7 +352,7 @@ int __init process_shm_node(const void *fdt, int node, uint32_t address_cells,const struct fdt_property *prop, *prop_id, *prop_role;const __be32 *cell;paddr_t paddr, gaddr, size, end; -struct meminfo *mem = &bootinfo.reserved_mem; +struct membanks *mem =bootinfo_get_reserved_mem ();unsigned int i;int len;bool owner = false;
@@ -460,7 +462,7 @@ int __init process_shm_node(const void *fdt, int node, uint32_t address_cells,if ( i == mem->nr_banks ) { -if ( i <NR_MEM_BANKS ) +if (i < mem->max_banks) {if (check_reserved_regions_overlap (paddr, size) )return -EINVAL ;
@@ -490,7 +492,7 @@ int __init process_shm_node(const void *fdt, int node, uint32_t address_cells,int __init make_resv_memory_node (const struct domain *d,void *fdt,int addrcells,int sizecells, -const struct meminfo *mem) +const struct membanks *mem) {int res =0 ;/* Placeholder for reserved-memory\0 */
Signature · 1 line
2.34.1
Re: [PATCH 03/11] xen/arm: Introduce a generic way to access memory bank structures
Hi Luca,
Quoted 10 lines · Luca Fancellu
Currently the 'stuct meminfo' is defining a static defined array of 'struct membank' of
NR_MEM_BANKSelements, some feature like shared memory don't require such amount of memory allocation but might want to reuse existing code to manipulate this kind of structure that is just as 'struct meminfo' but less bulky.For this reason introduce a generic way to access this kind of structure using a new stucture 'struct membanks', which implements
s/stucture/structure
Quoted 3 lines
all the fields needed by a structure related to memory banks without the need to specify at build time the size of the 'struct membank' array.
Might be beneficial here to mention the use of FAM.
Quoted 25 lines
Modify 'struct meminfo' to implement the field related to the new introduced structure, given the change all usage of this structure are updated in this way:
- code accessing bootinfo.{mem,reserved_mem,acpi} field now uses 3 new introduced static inline helpers to access the new field of 'struct meminfo' named 'common'.
- code accessing 'structkernel_info*' member 'mem' now use the new introduced macro 'kernel_info_get_mem(...)' to access the new field of 'struct meminfo' named 'common'.Constify pointers where needed.
Suggested-by Julien Grall <[email protected]>Signed-off-by Luca Fancellu <[email protected]>--- xen/arch/arm/acpi/domain_build.c | 6 +- xen/arch/arm/arm32/mmu/mm.c | 44 +++++----- xen/arch/arm/arm64/mmu/mm.c | 2 +- xen/arch/arm/bootfdt.c | 27 +++--- xen/arch/arm/dom0less-build.c | 18 ++-- xen/arch/arm/domain_build.c | 106 +++++++++++++----------- xen/arch/arm/efi/efi-boot.h | 8 +- xen/arch/arm/efi/efi-dom0.c | 13 +-- xen/arch/arm/include/asm/domain_build.h | 2 +-
Quoted 8 lines
xen/arch/arm/include/asm/kernel.h | 9 ++ xen/arch/arm/include/asm/setup.h | 40 ++++++++- xen/arch/arm/include/asm/static-shmem.h | 4 +- xen/arch/arm/kernel.c | 12 +-- xen/arch/arm/setup.c | 58 +++++++------ xen/arch/arm/static-memory.c | 27 +++--- xen/arch/arm/static-shmem.c | 34 ++++---- 16 files changed, 243 insertions(+), 167 deletions(-)
Lots of mechanical changes but in general I like this approach. I'd like other maintainers to share their opinion.
[...]
xen/arch/arm/domain_build.c int __init make_hypervisor_node(struct domain *d, · line 1166
Quoted 6 lines
xen/arch/arm/domain_build.c +1
-1@@ -1157,10 +1163,12 @@ int __init make_hypervisor_node(struct domain *d, }else { - ext_regions = xzalloc(struct meminfo); + ext_regions = (struct membanks *)xzalloc(struct meminfo);
You're making assumption that struct membanks is the first member of meminfo but there's no sanity check. Why not xzalloc_flex_struct()?
Quoted 2 lines
xen/arch/arm/domain_build.c +0
-0if ( !ext_regions )return -ENOMEM ;
[...]
xen/arch/arm/include/asm/kernel.h struct kernel_info { · line 82
Quoted 10 lines
xen/arch/arm/include/asm/kernel.h +2
-0@@ -78,6 +78,15 @@ struct kernel_info { }; }; +#define kernel_info_get_mem (kinfo) \ + (&(kinfo)->mem.common)
Why this is a macro but for bootinfo you use static inline helpers?
xen/arch/arm/include/asm/kernel.h struct kernel_info { · line 84
Quoted 2 lines
xen/arch/arm/include/asm/kernel.h +2
-0+ +#define KERNEL_INFO_INIT \
NIT: in most places we prefer \ to be aligned (the same apply to other places)
Quoted 15 lines
xen/arch/arm/include/asm/kernel.h +5
-0+{ \ + .mem.common.max_banks = NR_MEM_BANKS, \ + .shm_mem.common.max_banks = NR_MEM_BANKS, \ +} +/* * Probe the kernel to detemine its type and select a loader. * xen/arch/arm/include/asm/setup.h +0
-0@@ -56,8 +56,14 @@ struct membank {#endif };
xen/arch/arm/include/asm/setup.h struct membank { · line 66
Quoted 10 lines
xen/arch/arm/include/asm/setup.h +7
-1-struct meminfo { +struct membanks {unsigned int nr_banks; +unsigned int max_banks; +struct membank bank[]; +}; + +struct meminfo { +struct membanks common;
You were supposed to make sure there is no extra padding here. I don't see any check in this patch. I'd at least do sth like:BUILD_BUG_ON((offsetof(struct membanks, bank)) != (offsetof(struct meminfo, bank)));
~Michal
Re: [PATCH 03/11] xen/arm: Introduce a generic way to access memory bank structures
Quoted 5 lines · Michal Orzel
Hi Luca,
Hi Michal,
Thanks for having a look
Quoted 57 lines · Luca Fancellu
Quoted 10 lines
Currently the 'stuct meminfo' is defining a static defined array of 'struct membank' of
NR_MEM_BANKSelements, some feature like shared memory don't require such amount of memory allocation but might want to reuse existing code to manipulate this kind of structure that is just as 'struct meminfo' but less bulky.For this reason introduce a generic way to access this kind of structure using a new stucture 'struct membanks', which implements
s/stucture/structure
Quoted 3 lines
all the fields needed by a structure related to memory banks without the need to specify at build time the size of the 'struct membank' array.
Might be beneficial here to mention the use of FAM.
Quoted 25 lines
Modify 'struct meminfo' to implement the field related to the new introduced structure, given the change all usage of this structure are updated in this way:
- code accessing bootinfo.{mem,reserved_mem,acpi} field now uses 3 new introduced static inline helpers to access the new field of 'struct meminfo' named 'common'.
- code accessing 'structkernel_info*' member 'mem' now use the new introduced macro 'kernel_info_get_mem(...)' to access the new field of 'struct meminfo' named 'common'.Constify pointers where needed.
Suggested-by Julien Grall <[email protected]>Signed-off-by Luca Fancellu <[email protected]>---
xen/arch/arm/acpi/domain_build.c | 6 +- xen/arch/arm/arm32/mmu/mm.c | 44 +++++----- xen/arch/arm/arm64/mmu/mm.c | 2 +- xen/arch/arm/bootfdt.c | 27 +++--- xen/arch/arm/dom0less-build.c | 18 ++-- xen/arch/arm/domain_build.c | 106 +++++++++++++----------- xen/arch/arm/efi/efi-boot.h | 8 +- xen/arch/arm/efi/efi-dom0.c | 13 +-- xen/arch/arm/include/asm/domain_build.h | 2 +-Quoted 8 lines
xen/arch/arm/include/asm/kernel.h | 9 ++ xen/arch/arm/include/asm/setup.h | 40 ++++++++- xen/arch/arm/include/asm/static-shmem.h | 4 +- xen/arch/arm/kernel.c | 12 +-- xen/arch/arm/setup.c | 58 +++++++------ xen/arch/arm/static-memory.c | 27 +++--- xen/arch/arm/static-shmem.c | 34 ++++---- 16 files changed, 243 insertions(+), 167 deletions(-)Lots of mechanical changes but in general I like this approach. I'd like other maintainers to share their opinion.
[...]
Quoted 8 lines
xen/arch/arm/domain_build.c int __init make_hypervisor_node(struct domain *d, · line 1166
Quoted 6 lines
xen/arch/arm/domain_build.c +1
-1@@ -1157,10 +1163,12 @@ int __init make_hypervisor_node(struct domain *d, }else { - ext_regions = xzalloc(struct meminfo); + ext_regions = (struct membanks *)xzalloc(struct meminfo);You're making assumption that struct membanks is the first member of meminfo but there's no sanity check. Why not
xzalloc_flex_struct()?
I’ll use that, as well as the check you suggested below
Quoted 13 lines
Quoted 3 lines
xen/arch/arm/domain_build.c +0
-0if ( !ext_regions )return -ENOMEM ;[...]
Quoted 8 lines
xen/arch/arm/include/asm/kernel.h +0
-0@@ -78,6 +78,15 @@ struct kernel_info { }; };
Quoted 3 lines
xen/arch/arm/include/asm/kernel.h struct kernel_info { · line 82
Quoted 2 lines
xen/arch/arm/include/asm/kernel.h +2
-0+#define kernel_info_get_mem (kinfo) \ + (&(kinfo)->mem.common)Why this is a macro but for bootinfo you use static inline helpers?
So I think I started using static inline helpers but I had to have one that didn’t remove the const qualifier, and it was used only once. Anyway if it is acceptable I will go for static inline also here.
Quoted 4 lines
xen/arch/arm/include/asm/kernel.h struct kernel_info { · line 84
Quoted 3 lines
xen/arch/arm/include/asm/kernel.h +2
-0+ +#define KERNEL_INFO_INIT \NIT: in most places we prefer \ to be aligned (the same apply to other places)
kk
Quoted 17 lines
Quoted 17 lines
xen/arch/arm/include/asm/kernel.h +5
-0+{ \ + .mem.common.max_banks = NR_MEM_BANKS, \ + .shm_mem.common.max_banks = NR_MEM_BANKS, \ +} +/* * Probe the kernel to detemine its type and select a loader. * xen/arch/arm/include/asm/setup.h +0
-0@@ -56,8 +56,14 @@ struct membank {#endif };
Quoted 12 lines
xen/arch/arm/include/asm/setup.h struct membank { · line 66
Quoted 9 lines
xen/arch/arm/include/asm/setup.h +7
-1-struct meminfo { +struct membanks {unsigned int nr_banks; +unsigned int max_banks; +struct membank bank[]; +}; + +struct meminfo { +struct membanks common;You were supposed to make sure there is no extra padding here. I don't see any check in this patch. I'd at least do sth like:
BUILD_BUG_ON((offsetof(struct membanks, bank)) != (offsetof(struct meminfo, bank)));
I’ll add this check, thanks!
Quoted 2 lines
~Michal
Re: [PATCH 03/11] xen/arm: Introduce a generic way to access memory bank structures
In reply to Michal OrzelQuoted 11 lines · Michal Orzel
Hi Luca,
Quoted 8 lines · Luca Fancellu
Currently the 'stuct meminfo' is defining a static defined array of 'struct membank' of
NR_MEM_BANKSelements, some feature like shared memory don't require such amount of memory allocation but might want to reuse existing code to manipulate this kind of structure that is just as 'struct meminfo' but less bulky.
Quoted 8 lines
Quoted 2 lines
For this reason introduce a generic way to access this kind of structure using a new stucture 'struct membanks', which implements
s/stucture/structure
Quoted 3 lines
all the fields needed by a structure related to memory banks without the need to specify at build time the size of the 'struct membank' array.
Might be beneficial here to mention the use of FAM.
I had to look it up online and there was no hit on Google. I guess you mean "Flexible Array Member".
Quoted 32 lines
Quoted 24 lines
Modify 'struct meminfo' to implement the field related to the new introduced structure, given the change all usage of this structure are updated in this way:
- code accessing bootinfo.{mem,reserved_mem,acpi} field now uses 3 new introduced static inline helpers to access the new field of 'struct meminfo' named 'common'.
- code accessing 'structkernel_info*' member 'mem' now use the new introduced macro 'kernel_info_get_mem(...)' to access the new field of 'struct meminfo' named 'common'.Constify pointers where needed.
Suggested-by Julien Grall <[email protected]>Signed-off-by Luca Fancellu <[email protected]>--- xen/arch/arm/acpi/domain_build.c | 6 +- xen/arch/arm/arm32/mmu/mm.c | 44 +++++----- xen/arch/arm/arm64/mmu/mm.c | 2 +- xen/arch/arm/bootfdt.c | 27 +++--- xen/arch/arm/dom0less-build.c | 18 ++-- xen/arch/arm/domain_build.c | 106 +++++++++++++----------- xen/arch/arm/efi/efi-boot.h | 8 +- xen/arch/arm/efi/efi-dom0.c | 13 +-- xen/arch/arm/include/asm/domain_build.h | 2 +-Quoted 8 lines
xen/arch/arm/include/asm/kernel.h | 9 ++ xen/arch/arm/include/asm/setup.h | 40 ++++++++- xen/arch/arm/include/asm/static-shmem.h | 4 +- xen/arch/arm/kernel.c | 12 +-- xen/arch/arm/setup.c | 58 +++++++------ xen/arch/arm/static-memory.c | 27 +++--- xen/arch/arm/static-shmem.c | 34 ++++---- 16 files changed, 243 insertions(+), 167 deletions(-)
Quoted 2 lines
Lots of mechanical changes but in general I like this approach. I'd like other maintainers to share their opinion.
I don't mind the churn so long we get a correct interface at the end. The current interface looks alright (I know I suggested it ;)).
Quoted 48 lines
[...]
xen/arch/arm/domain_build.c int __init make_hypervisor_node(struct domain *d, · line 1166
Quoted 6 lines
xen/arch/arm/domain_build.c +1
-1@@ -1157,10 +1163,12 @@ int __init make_hypervisor_node(struct domain *d, }else { - ext_regions = xzalloc(struct meminfo); + ext_regions = (struct membanks *)xzalloc(struct meminfo);You're making assumption that struct membanks is the first member of meminfo but there's no sanity check. Why not
xzalloc_flex_struct()?Quoted 2 lines
xen/arch/arm/domain_build.c +0
-0if ( !ext_regions )return -ENOMEM ;[...]
xen/arch/arm/include/asm/kernel.h struct kernel_info { · line 82
Quoted 10 lines
xen/arch/arm/include/asm/kernel.h +2
-0@@ -78,6 +78,15 @@ struct kernel_info { }; }; +#define kernel_info_get_mem (kinfo) \ + (&(kinfo)->mem.common)Why this is a macro but for bootinfo you use static inline helpers?
xen/arch/arm/include/asm/kernel.h struct kernel_info { · line 84
Quoted 2 lines
xen/arch/arm/include/asm/kernel.h +2
-0+ +#define KERNEL_INFO_INIT \NIT: in most places we prefer \ to be aligned (the same apply to other places)
Quoted 16 lines
xen/arch/arm/include/asm/kernel.h +5
-0+{ \ + .mem.common.max_banks = NR_MEM_BANKS, \ + .shm_mem.common.max_banks = NR_MEM_BANKS, \ +} +/* * Probe the kernel to detemine its type and select a loader. * xen/arch/arm/include/asm/setup.h +0
-0@@ -56,8 +56,14 @@ struct membank {#endif };
Quoted 12 lines
xen/arch/arm/include/asm/setup.h struct membank { · line 66
Quoted 9 lines
xen/arch/arm/include/asm/setup.h +7
-1-struct meminfo { +struct membanks {unsigned int nr_banks; +unsigned int max_banks; +struct membank bank[]; +}; + +struct meminfo { +struct membanks common;You were supposed to make sure there is no extra padding here. I don't see any check in this patch. I'd at least do sth like:
BUILD_BUG_ON((offsetof(struct membanks, bank)) != (offsetof(struct meminfo, bank)));
+1. You could also check that "struct membanks" is 8-byte aligned.
Cheers,
Signature · 1 line
Julien Grall
PATCH 4/11 xen/arm: Conditional compilation of kernel_info.shm_mem member
In reply to Luca FancelluThe user of shm_mem member of the 'struct kernel_info' is only the code managing the static shared memory feature, which can be compiled out using CONFIG_STATIC_SHM, so in case the feature is not requested, that member won't be used and will waste memory space.
To address this issue, protect the member with the Kconfig parameter and modify the signature of the only function using it to remove any reference to the member from outside the static-shmem module.
--- xen/arch/arm/dom0less-build.c | 3 +-- xen/arch/arm/domain_build.c | 3 +-- xen/arch/arm/include/asm/kernel.h | 10 +++++++++- xen/arch/arm/include/asm/static-shmem.h | 11 ++++++----- xen/arch/arm/static-shmem.c | 8 +++++--- 5 files changed, 22 insertions(+), 13 deletions(-)
xen/arch/arm/dom0less-build.c +1 -2
@@ -647,8 +647,7 @@ static int __init prepare_dtb_domU(struct domain *d, struct kernel_info *kinfo)if ( ret ) goto err; - ret =make_resv_memory_node (d, kinfo->fdt, addrcells, sizecells, - &kinfo->shm_mem.common); + ret =make_resv_memory_node (d, kinfo, addrcells, sizecells);if ( ret ) goto err;
xen/arch/arm/domain_build.c +1 -2
@@ -1780,8 +1780,7 @@ static int __init handle_node(struct domain *d, struct kernel_info *kinfo,return res; } - res =make_resv_memory_node (d, kinfo->fdt, addrcells, sizecells, - &kinfo->shm_mem.common); + res =make_resv_memory_node (d, kinfo, addrcells, sizecells);if ( res )return res; }
xen/arch/arm/include/asm/kernel.h +9 -1
@@ -39,7 +39,9 @@ struct kernel_info {void *fdt;/* flat device tree */ paddr_t unassigned_mem;/* RAM not (yet) assigned to a bank */ struct meminfo mem; +#ifdef CONFIG_STATIC_SHM struct meminfo shm_mem; +#endif /* kernel entry point */ paddr_t entry;
@@ -81,10 +83,16 @@ struct kernel_info {#define kernel_info_get_mem (kinfo) \ (&(kinfo)->mem.common) +#ifdef CONFIG_STATIC_SHM +#define KERNEL_INFO_SHM_MEM_INIT .shm_mem.common.max_banks = NR_MEM_BANKS, +#else +#define KERNEL_INFO_SHM_MEM_INIT +#endif +#define KERNEL_INFO_INIT \ { \ .mem.common.max_banks = NR_MEM_BANKS, \ - .shm_mem.common.max_banks = NR_MEM_BANKS, \ + KERNEL_INFO_SHM_MEM_INIT \ }/*
xen/arch/arm/include/asm/static-shmem.h +6 -5
@@ -7,8 +7,9 @@#ifdef CONFIG_STATIC_SHM -int make_resv_memory_node (const struct domain *d,void *fdt,int addrcells, -int sizecells,const struct membanks *mem); +int make_resv_memory_node (const struct domain *d, +const struct kernel_info *kinfo,int addrcells, +int sizecells);int process_shm (struct domain *d,struct kernel_info *kinfo,const struct dt_device_node *node);
@@ -26,9 +27,9 @@ int process_shm_node(const void *fdt, int node, uint32_t address_cells,#else /* !CONFIG_STATIC_SHM */ -static inline int make_resv_memory_node (const struct domain *d,void *fdt, -int addrcells,int sizecells, -const struct membanks *mem) +static inline int make_resv_memory_node (const struct domain *d, +const struct kernel_info *kinfo, +int addrcells,int sizecells) {return 0 ; }
xen/arch/arm/static-shmem.c +5 -3
@@ -490,13 +490,15 @@ int __init process_shm_node(const void *fdt, int node, uint32_t address_cells,return 0 ; } -int __init make_resv_memory_node (const struct domain *d,void *fdt, -int addrcells,int sizecells, -const struct membanks *mem) +int __init make_resv_memory_node (const struct domain *d, +const struct kernel_info *kinfo, +int addrcells,int sizecells) {int res =0 ;/* Placeholder for reserved-memory\0 */ const char resvbuf[16 ] ="reserved-memory" ; +const struct membanks *mem = &kinfo->shm_mem.common; +void *fdt = kinfo->fdt;if ( mem->nr_banks ==0 )/* No shared memory provided. */
Signature · 1 line
2.34.1
Re: [PATCH 04/11] xen/arm: Conditional compilation of kernel_info.shm_mem member
Hi Luca,
Quoted 8 lines · Luca Fancellu
The user of
shm_memmember of the 'structkernel_info' is only the code managing the static shared memory feature, which can be compiled out usingCONFIG_STATIC_SHM, so in case the feature is not requested, that member won't be used and will waste memory space.
Quoted 5 lines
To address this issue, protect the member with the
Kconfigparameter and modify the signature of the only function using it to remove any reference to the member from outside the static-shmem module.Signed-off-by Luca Fancellu <[email protected]>
NIT: I always wonder why we have hundreds of functions taking both struct domain and struct kernel_info as arguments if the latter has the former as its member. As you are revisiting the function and modifying parameter list, you could take the opportunity to change it. But you don't have to.
~Michal
Re: [PATCH 04/11] xen/arm: Conditional compilation of kernel_info.shm_mem member
Quoted 19 lines · Michal Orzel
Hi Luca,
Quoted 12 lines · Luca Fancellu
The user of
shm_memmember of the 'structkernel_info' is only the code managing the static shared memory feature, which can be compiled out usingCONFIG_STATIC_SHM, so in case the feature is not requested, that member won't be used and will waste memory space.To address this issue, protect the member with the
Kconfigparameter and modify the signature of the only function using it to remove any reference to the member from outside the static-shmem module.
Quoted 7 lines
Quoted 1 line
Signed-off-by Luca Fancellu <[email protected]>Reviewed-by Michal Orzel <[email protected]>NIT: I always wonder why we have hundreds of functions taking both struct domain and struct
kernel_infoas arguments if the latter has the former as its member. As you are revisiting the function and modifying parameter list, you could take the opportunity to change it. But you don't have to.
You are right, can I do this modification as part of patch 3 and this one? Also, can I keep your R-by here when doing this change?
Quoted 3 lines
~Michal
Re: [PATCH 04/11] xen/arm: Conditional compilation of kernel_info.shm_mem member
Hi Luca,
Quoted 22 lines · Luca Fancellu
Quoted 22 lines · Michal Orzel
Hi Luca,
Quoted 8 lines · Luca Fancellu
The user of
shm_memmember of the 'structkernel_info' is only the code managing the static shared memory feature, which can be compiled out usingCONFIG_STATIC_SHM, so in case the feature is not requested, that member won't be used and will waste memory space.Quoted 5 lines
To address this issue, protect the member with the
Kconfigparameter and modify the signature of the only function using it to remove any reference to the member from outside the static-shmem module.Signed-off-by Luca Fancellu <[email protected]>Reviewed-by Michal Orzel <[email protected]>
Quoted 7 lines
Quoted 4 lines
NIT: I always wonder why we have hundreds of functions taking both struct domain and struct
kernel_infoas arguments if the latter has the former as its member. As you are revisiting the function and modifying parameter list, you could take the opportunity to change it. But you don't have to.You are right, can I do this modification as part of patch 3 and this one? Also, can I keep your R-by here when doing this change?
You can do this as part of patch 3 (afaict there will be no need to modify the argument list in patch 4) and you can keep my Rb.
~Michal
PATCH 5/11 xen/arm: Introduce helper for static memory pages
In reply to Luca FancelluIntroduce a new helper function in the static-memory module that can be called to manage static memory banks, this is done to reuse the code when other modules would like to manage static memory banks that are not part of the reserved_mem structure.
--- xen/arch/arm/include/asm/static-memory.h | 12 ++++++++++++ xen/arch/arm/static-memory.c | 12 +----------- 2 files changed, 13 insertions(+), 11 deletions(-)
xen/arch/arm/include/asm/static-memory.h +12 -0
@@ -7,6 +7,18 @@#ifdef CONFIG_STATIC_MEMORY +static inline void init_staticmem_bank (const struct membank *bank) +{ +mfn_t bank_start =_mfn (PFN_UP (bank->start)); +unsigned long bank_pages =PFN_DOWN (bank->size); +mfn_t bank_end =mfn_add (bank_start, bank_pages); + +if (mfn_x (bank_end) <=mfn_x (bank_start) ) +return ; + +unprepare_staticmem_pages (mfn_to_page (bank_start), bank_pages, false); +} +void allocate_static_memory (struct domain *d,struct kernel_info *kinfo,const struct dt_device_node *node); void assign_static_memory_11(struct domain *d, struct kernel_info *kinfo,
xen/arch/arm/static-memory.c +1 -11
@@ -265,17 +265,7 @@ void __init init_staticmem_pages(void)for ( bank =0 ; bank < reserved_mem->nr_banks; bank++ ) {if ( reserved_mem->bank[bank].type ==MEMBANK_STATIC_DOMAIN ) - { -mfn_t bank_start =_mfn (PFN_UP (reserved_mem->bank[bank].start)); -unsigned long bank_pages =PFN_DOWN (reserved_mem->bank[bank].size); -mfn_t bank_end =mfn_add (bank_start, bank_pages); - -if (mfn_x (bank_end) <=mfn_x (bank_start) ) -return ; - -unprepare_staticmem_pages (mfn_to_page (bank_start), - bank_pages, false); - } +init_staticmem_bank (&reserved_mem->bank[bank]); } }
Signature · 1 line
2.34.1
Re: [PATCH 05/11] xen/arm: Introduce helper for static memory pages
Hi Luca,
Quoted 7 lines · Luca Fancellu
Introduce a new helper function in the static-memory module that can be called to manage static memory banks, this is done to reuse the code when other modules would like to manage static memory banks that are not part of the
reserved_memstructure.
The placement of this patch in a series is a bit strange given no use of init_staticmem_bank() in the subsequent patch. I would move it right before patch #8.
Also, you could mention that this is because the information about shared memory regions will no longer be stored in reserved_mem.
Quoted 12 lines
Signed-off-by Luca Fancellu <[email protected]>--- xen/arch/arm/include/asm/static-memory.h | 12 ++++++++++++ xen/arch/arm/static-memory.c | 12 +----------- 2 files changed, 13 insertions(+), 11 deletions(-)xen/arch/arm/include/asm/static-memory.h +0
-0
xen/arch/arm/include/asm/static-memory.h line 12
Quoted 6 lines
xen/arch/arm/include/asm/static-memory.h +3
-0@@ -7,6 +7,18 @@#ifdef CONFIG_STATIC_MEMORY +static inline void init_staticmem_bank (const struct membank *bank) +{ +mfn_t bank_start =_mfn (PFN_UP (bank->start));
The header should be self-contained so you should add <xen/pfn.h> that is not included in asm/kernel.h path.
Other than that:
~Michal
PATCH 6/11 xen/arm: Avoid code duplication in find_unallocated_memory
In reply to Luca FancelluThe function find_unallocated_memory is using the same code to loop through 3 structure of the same type, in order to avoid code duplication, rework the code to have only one loop that goes through all the structures.
--- xen/arch/arm/domain_build.c | 62 ++++++++++--------------------------- 1 file changed, 17 insertions(+), 45 deletions(-)
xen/arch/arm/domain_build.c +17 -45
@@ -869,12 +869,14 @@ static int __init add_ext_regions(unsigned long s_gfn, unsigned long e_gfn,static int __init find_unallocated_memory (const struct kernel_info *kinfo,struct membanks *ext_regions) { -const struct membanks *kinfo_mem =kernel_info_get_mem (kinfo); -const struct membanks *mem =bootinfo_get_mem (); -const struct membanks *reserved_mem =bootinfo_get_reserved_mem (); +const struct membanks *mem_banks[] = { +bootinfo_get_mem (), +kernel_info_get_mem (kinfo), +bootinfo_get_reserved_mem (), + };struct rangeset *unalloc_mem;paddr_t start, end; -unsigned int i; +unsigned int i, j;int res;dt_dprintk ("Find unallocated memory for extended regions\n" );
@@ -883,50 +885,20 @@ static int __init find_unallocated_memory(const struct kernel_info *kinfo,if ( !unalloc_mem )return -ENOMEM ; -/* Start with all available RAM */ -for ( i =0 ; i < mem->nr_banks; i++ ) - { - start = mem->bank[i].start; - end = mem->bank[i].start + mem->bank[i].size; - res =rangeset_add_range (unalloc_mem,PFN_DOWN (start), -PFN_DOWN (end -1 )); -if ( res ) - { -printk (XENLOG_ERR "Failed to add: %#" PRIpaddr"->%#" PRIpaddr"\n" , - start, end); - goto out; - } - } - -/* Remove RAM assigned to Dom0 */ -for ( i =0 ; i < kinfo_mem->nr_banks; i++ ) - { - start = kinfo_mem->bank[i].start; - end = kinfo_mem->bank[i].start + kinfo_mem->bank[i].size; - res =rangeset_remove_range (unalloc_mem,PFN_DOWN (start), -PFN_DOWN (end -1 )); -if ( res ) +for ( i =0 ; i <ARRAY_SIZE (mem_banks); i++ ) +for ( j =0 ; j < mem_banks[i]->nr_banks; j++ ) { -printk (XENLOG_ERR "Failed to remove: %#" PRIpaddr"->%#" PRIpaddr"\n" , - start, end); - goto out; - } - } - -/* Remove reserved-memory regions */ -for ( i =0 ; i < reserved_mem->nr_banks; i++ ) - { - start = reserved_mem->bank[i].start; - end = reserved_mem->bank[i].start + reserved_mem->bank[i].size; - res =rangeset_remove_range (unalloc_mem,PFN_DOWN (start), + start = mem_banks[i]->bank[j].start; + end = mem_banks[i]->bank[j].start + mem_banks[i]->bank[j].size; + res =rangeset_add_range (unalloc_mem,PFN_DOWN (start),PFN_DOWN (end -1 )); -if ( res ) - { -printk (XENLOG_ERR "Failed to remove: %#" PRIpaddr"->%#" PRIpaddr"\n" , - start, end); - goto out; +if ( res ) + { +printk (XENLOG_ERR "Failed to add: %#" PRIpaddr"->%#" PRIpaddr"\n" , + start, end); + goto out; + } } - }/* Remove grant table region */ if ( kinfo->gnttab_size )
Signature · 1 line
2.34.1
Re: [PATCH 06/11] xen/arm: Avoid code duplication in find_unallocated_memory
Hi Luca,
Quoted 54 lines · Luca Fancellu
The function
find_unallocated_memoryis using the same code to loop through 3 structure of the same type, in order to avoid code duplication, rework the code to have only one loop that goes through all the structures.Signed-off-by Luca Fancellu <[email protected]>--- xen/arch/arm/domain_build.c | 62 ++++++++++--------------------------- 1 file changed, 17 insertions(+), 45 deletions(-)xen/arch/arm/domain_build.c +6
-19@@ -869,12 +869,14 @@ static int __init add_ext_regions(unsigned long s_gfn, unsigned long e_gfn,static int __init find_unallocated_memory (const struct kernel_info *kinfo,struct membanks *ext_regions) { -const struct membanks *kinfo_mem =kernel_info_get_mem (kinfo); -const struct membanks *mem =bootinfo_get_mem (); -const struct membanks *reserved_mem =bootinfo_get_reserved_mem (); +const struct membanks *mem_banks[] = { +bootinfo_get_mem (), +kernel_info_get_mem (kinfo), +bootinfo_get_reserved_mem (), + };struct rangeset *unalloc_mem;paddr_t start, end; -unsigned int i; +unsigned int i, j;int res;dt_dprintk ("Find unallocated memory for extended regions\n" );@@ -883,50 +885,20 @@ static int __init find_unallocated_memory(const struct kernel_info *kinfo,if ( !unalloc_mem )return -ENOMEM ; -/* Start with all available RAM */ -for ( i =0 ; i < mem->nr_banks; i++ ) - { - start = mem->bank[i].start; - end = mem->bank[i].start + mem->bank[i].size; - res =rangeset_add_range (unalloc_mem,PFN_DOWN (start), -PFN_DOWN (end -1 )); -if ( res ) - { -printk (XENLOG_ERR "Failed to add: %#" PRIpaddr"->%#" PRIpaddr"\n" , - start, end); - goto out; - } - } -
xen/arch/arm/domain_build.c static int __init find_unallocated_memory(const struct kernel_info *kinfo, · line 889
Quoted 10 lines
xen/arch/arm/domain_build.c +2
-8-/* Remove RAM assigned to Dom0 */ -for ( i =0 ; i < kinfo_mem->nr_banks; i++ ) - { - start = kinfo_mem->bank[i].start; - end = kinfo_mem->bank[i].start + kinfo_mem->bank[i].size; - res =rangeset_remove_range (unalloc_mem,PFN_DOWN (start), -PFN_DOWN (end -1 )); -if ( res ) +for ( i =0 ; i <ARRAY_SIZE (mem_banks); i++ ) +for ( j =0 ; j < mem_banks[i]->nr_banks; j++ )
It might be a matter of personal opinion, but I would actually prefer the current code that looks simpler/neater (the steps are clear) to me. I'd like to know other maintainers opinion.
~Michal
Re: [PATCH 06/11] xen/arm: Avoid code duplication in find_unallocated_memory
Quoted 65 lines · Michal Orzel
Hi Luca,
Quoted 58 lines · Luca Fancellu
The function
find_unallocated_memoryis using the same code to loop through 3 structure of the same type, in order to avoid code duplication, rework the code to have only one loop that goes through all the structures.Signed-off-by Luca Fancellu <[email protected]>---
xen/arch/arm/domain_build.c| 62 ++++++++++---------------------------1 file changed, 17 insertions(+), 45 deletions(-)xen/arch/arm/domain_build.c +6
-23@@ -869,12 +869,14 @@ static int __init add_ext_regions(unsigned long s_gfn, unsigned long e_gfn,static int __init find_unallocated_memory (const struct kernel_info *kinfo,struct membanks *ext_regions) { -const struct membanks *kinfo_mem =kernel_info_get_mem (kinfo); -const struct membanks *mem =bootinfo_get_mem (); -const struct membanks *reserved_mem =bootinfo_get_reserved_mem (); +const struct membanks *mem_banks[] = { +bootinfo_get_mem (), +kernel_info_get_mem (kinfo), +bootinfo_get_reserved_mem (), + };struct rangeset *unalloc_mem;paddr_t start, end; -unsigned int i; +unsigned int i, j;int res;dt_dprintk ("Find unallocated memory for extended regions\n" );@@ -883,50 +885,20 @@ static int __init find_unallocated_memory(const struct kernel_info *kinfo,if ( !unalloc_mem )return -ENOMEM ; -/* Start with all available RAM */ -for ( i =0 ; i < mem->nr_banks; i++ ) - { - start = mem->bank[i].start; - end = mem->bank[i].start + mem->bank[i].size; - res =rangeset_add_range (unalloc_mem,PFN_DOWN (start), -PFN_DOWN (end -1 )); -if ( res ) - { -printk (XENLOG_ERR "Failed to add: %#" PRIpaddr"->%#" PRIpaddr"\n" , - start, end); - goto out; - } - } - -/* Remove RAM assigned to Dom0 */ -for ( i =0 ; i < kinfo_mem->nr_banks; i++ ) - { - start = kinfo_mem->bank[i].start;
Quoted 8 lines
xen/arch/arm/domain_build.c static int __init find_unallocated_memory(const struct kernel_info *kinfo, · line 889
Quoted 6 lines
xen/arch/arm/domain_build.c +2
-4- end = kinfo_mem->bank[i].start + kinfo_mem->bank[i].size; - res =rangeset_remove_range (unalloc_mem,PFN_DOWN (start), -PFN_DOWN (end -1 )); -if ( res ) +for ( i =0 ; i <ARRAY_SIZE (mem_banks); i++ ) +for ( j =0 ; j < mem_banks[i]->nr_banks; j++ )It might be a matter of personal opinion, but I would actually prefer the current code that looks simpler/neater (the steps are clear) to me. I'd like to know other maintainers opinion.
Ok, I’ll wait the other maintainers then, I’m going to use this construct in other part of the code to simplify and remove duplication so it would be important to know if It’s desirable or not.
Maybe your opinion could change with a proper comment on top of the structure and the loop, listing the operation performed in order?
1) Start with all available RAM
2) Remove RAM assigned to Dom0
3) Remove reserved mem
<later>
4) Remove static shared memory regions
Cheers,
Luca
Quoted 2 lines
~Michal
Re: [PATCH 06/11] xen/arm: Avoid code duplication in find_unallocated_memory
Hi Luca,
Quoted 78 lines · Luca Fancellu
Quoted 65 lines · Michal Orzel
Hi Luca,
Quoted 58 lines · Luca Fancellu
The function
find_unallocated_memoryis using the same code to loop through 3 structure of the same type, in order to avoid code duplication, rework the code to have only one loop that goes through all the structures.Signed-off-by Luca Fancellu <[email protected]>---
xen/arch/arm/domain_build.c| 62 ++++++++++---------------------------1 file changed, 17 insertions(+), 45 deletions(-)xen/arch/arm/domain_build.c +6
-23@@ -869,12 +869,14 @@ static int __init add_ext_regions(unsigned long s_gfn, unsigned long e_gfn,static int __init find_unallocated_memory (const struct kernel_info *kinfo,struct membanks *ext_regions) { -const struct membanks *kinfo_mem =kernel_info_get_mem (kinfo); -const struct membanks *mem =bootinfo_get_mem (); -const struct membanks *reserved_mem =bootinfo_get_reserved_mem (); +const struct membanks *mem_banks[] = { +bootinfo_get_mem (), +kernel_info_get_mem (kinfo), +bootinfo_get_reserved_mem (), + };struct rangeset *unalloc_mem;paddr_t start, end; -unsigned int i; +unsigned int i, j;int res;dt_dprintk ("Find unallocated memory for extended regions\n" );@@ -883,50 +885,20 @@ static int __init find_unallocated_memory(const struct kernel_info *kinfo,if ( !unalloc_mem )return -ENOMEM ; -/* Start with all available RAM */ -for ( i =0 ; i < mem->nr_banks; i++ ) - { - start = mem->bank[i].start; - end = mem->bank[i].start + mem->bank[i].size; - res =rangeset_add_range (unalloc_mem,PFN_DOWN (start), -PFN_DOWN (end -1 )); -if ( res ) - { -printk (XENLOG_ERR "Failed to add: %#" PRIpaddr"->%#" PRIpaddr"\n" , - start, end); - goto out; - } - } - -/* Remove RAM assigned to Dom0 */ -for ( i =0 ; i < kinfo_mem->nr_banks; i++ ) - { - start = kinfo_mem->bank[i].start;Quoted 8 lines
xen/arch/arm/domain_build.c static int __init find_unallocated_memory(const struct kernel_info *kinfo, · line 889
Quoted 6 lines
xen/arch/arm/domain_build.c +2
-4- end = kinfo_mem->bank[i].start + kinfo_mem->bank[i].size; - res =rangeset_remove_range (unalloc_mem,PFN_DOWN (start), -PFN_DOWN (end -1 )); -if ( res ) +for ( i =0 ; i <ARRAY_SIZE (mem_banks); i++ ) +for ( j =0 ; j < mem_banks[i]->nr_banks; j++ )It might be a matter of personal opinion, but I would actually prefer the current code that looks simpler/neater (the steps are clear) to me. I'd like to know other maintainers opinion.
Ok, I’ll wait the other maintainers then, I’m going to use this construct in other part of the code to simplify and remove duplication so it would be important to know if It’s desirable or not.
Quoted 8 lines
Maybe your opinion could change with a proper comment on top of the structure and the loop, listing the operation performed in order?
1) Start with all available RAM
2) Remove RAM assigned to Dom0
3) Remove reserved mem
<later>
4) Remove static shared memory regions
Yes, that would help with the overall readability.
~Michal
PATCH 7/11 xen/arm: Avoid code duplication in check_reserved_regions_overlap
In reply to Luca FancelluThe function check_reserved_regions_overlap is calling 'meminfo_overlap_check' on the same type of structure, this code can be written in a way to avoid code duplication, so rework the function to do that.
--- xen/arch/arm/setup.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-)
xen/arch/arm/setup.c +13 -11
@@ -340,25 +340,27 @@ void __init fw_unreserved_regions(paddr_t s, paddr_t e,bool __init check_reserved_regions_overlap (paddr_t region_start,paddr_t region_size) { +const struct membanks *mem_banks[] = { +bootinfo_get_reserved_mem (), +#ifdef CONFIG_ACPI +bootinfo_get_acpi (), +#endif + }; +unsigned int i; +/* -* Check if input region is overlapping with bootinfo_get_reserved_mem() -* banks +* Check if input region is overlapping with reserved memory banks or +* ACPI EfiACPIReclaimMemory (when ACPI feature is enabled) */ -if (meminfo_overlap_check (bootinfo_get_reserved_mem (), - region_start, region_size) ) -return true; +for ( i =0 ; i <ARRAY_SIZE (mem_banks); i++ ) +if (meminfo_overlap_check (mem_banks[i], region_start, region_size) ) +return true;/* Check if input region is overlapping with bootmodules */ if (bootmodules_overlap_check (&bootinfo.modules, region_start, region_size) )return true; -#ifdef CONFIG_ACPI -/* Check if input region is overlapping with ACPI EfiACPIReclaimMemory */ -if (meminfo_overlap_check (bootinfo_get_acpi (), region_start, region_size) ) -return true; -#endif -return false; }
Signature · 1 line
2.34.1
PATCH 8/11 xen/arm: Reduce struct membank size on static shared memory
In reply to Luca FancelluCurrently the memory footprint of the static shared memory feature is impacting all the struct meminfo instances with memory space that is not going to be used.
To solve this issue, rework the static shared memory extra information linked to the memory bank to another structure, struct shmem_membank_extra, and exploit the struct membank padding to host a pointer to that structure in a union with the enum membank_type, with this trick the 'struct membank' has the same size with or without the static shared memory, given that the 'type' and 'shmem_extra' are never used at the same time.
Afterwards, create a new structure 'struct shared_meminfo' which has the same interface of 'struct meminfo', but requires less banks and hosts the extra information for the static shared memory. The fields 'bank' and 'extra' of this structure are meant to be linked by the index (e.g. extra[idx] will have the information for the bank[idx], for i=0..NR_SHMEM_BANKS), the convinient pointer 'shmem_extra' of 'struct membank' is then linked to the related 'extra' bank to ease the fruition when a function has access only to the 'struct membanks common' of 'struct shared_meminfo'.
The last part of this work is to move the allocation of the static shared memory banks from the 'reserved_mem' to a new 'shmem' member of the 'struct bootinfo'.
Change also the 'shm_mem' member type to be 'struct shared_meminfo' in order to match the above changes and allow a memory space reduction also in 'struct kernel_info'.
--- xen/arch/arm/arm32/mmu/mm.c | 24 +++++++++ xen/arch/arm/arm64/mmu/mm.c | 2 + xen/arch/arm/bootfdt.c | 1 + xen/arch/arm/domain_build.c | 4 ++ xen/arch/arm/include/asm/kernel.h | 4 +- xen/arch/arm/include/asm/setup.h | 41 +++++++++++++-- xen/arch/arm/include/asm/static-shmem.h | 8 +++ xen/arch/arm/setup.c | 25 ++++++++- xen/arch/arm/static-shmem.c | 69 ++++++++++++++++++------- 9 files changed, 154 insertions(+), 24 deletions(-)
xen/arch/arm/arm32/mmu/mm.c +24 -0
@@ -7,6 +7,7 @@#include <xen/pfn.h> #include <asm/fixmap.h> #include <asm/static-memory.h> +#include <asm/static-shmem.h> static unsigned long opt_xenheap_megabytes__initdata ;integer_param ("xenheap_megabytes" , opt_xenheap_megabytes);
@@ -42,6 +43,9 @@ static paddr_t __init consider_modules(paddr_t s, paddr_t e, int first_mod) {const struct membanks *reserved_mem =bootinfo_get_reserved_mem (); +#ifdef CONFIG_STATIC_SHM +const struct membanks *shmem =bootinfo_get_shmem (); +#endif const struct bootmodules *mi = &bootinfo.modules;int i;int nr;
@@ -118,6 +122,25 @@ static paddr_t __init consider_modules(paddr_t s, paddr_t e,return consider_modules (s, r_s, size, align, i +1 ); } } + +#ifdef CONFIG_STATIC_SHM + nr += reserved_mem->nr_banks; +for ( ; i - nr < shmem->nr_banks; i++ ) + { +paddr_t r_s = shmem->bank[i - nr].start; +paddr_t r_e = r_s + shmem->bank[i - nr].size; + +if ( s < r_e && r_s < e ) + { + r_e =consider_modules (r_e, e, size, align, i +1 ); +if ( r_e ) +return r_e; + +return consider_modules (s, r_s, size, align, i +1 ); + } + } +#endif +return e; }
@@ -294,6 +317,7 @@ void __init setup_mm(void) mfn_to_maddr(directmap_mfn_end));init_staticmem_pages (); +init_sharedmem_pages (); }/*
xen/arch/arm/arm64/mmu/mm.c +2 -0
@@ -6,6 +6,7 @@#include <asm/setup.h> #include <asm/static-memory.h> +#include <asm/static-shmem.h> /* Override macros from asm/page.h to make them work with mfn_t */ #undef virt_to_mfn
@@ -236,6 +237,7 @@ void __init setup_mm(void) max_page =PFN_DOWN (ram_end);init_staticmem_pages (); +init_sharedmem_pages (); }/*
xen/arch/arm/bootfdt.c +1 -0
@@ -499,6 +499,7 @@ static void __init early_print_info(void) mem_resv->bank[j].start, mem_resv->bank[j].start + mem_resv->bank[j].size - 1); } +early_print_info_shmem ();printk ("\n" );for ( i =0 ; i < cmds->nr_mods; i++ ) printk("CMDLINE[%"PRIpaddr"]:%s %s\n", cmds->cmdline[i].start,
xen/arch/arm/domain_build.c +4 -0
@@ -864,6 +864,7 @@ static int __init add_ext_regions(unsigned long s_gfn, unsigned long e_gfn,* regions we exclude every region assigned to Dom0 from the Host RAM: * - domain RAM * - reserved-memory +* - static shared memory * - grant table space */ static int __init find_unallocated_memory(const struct kernel_info *kinfo,
@@ -873,6 +874,9 @@ static int __init find_unallocated_memory(const struct kernel_info *kinfo,bootinfo_get_mem (),kernel_info_get_mem (kinfo),bootinfo_get_reserved_mem (), +#ifdef CONFIG_STATIC_SHM + bootinfo_get_shmem(), +#endif };struct rangeset *unalloc_mem;paddr_t start, end;
xen/arch/arm/include/asm/kernel.h +2 -2
@@ -40,7 +40,7 @@ struct kernel_info {paddr_t unassigned_mem;/* RAM not (yet) assigned to a bank */ struct meminfo mem;#ifdef CONFIG_STATIC_SHM -struct meminfo shm_mem; +struct shared_meminfo shm_mem;#endif /* kernel entry point */
@@ -84,7 +84,7 @@ struct kernel_info { (&(kinfo)->mem.common)#ifdef CONFIG_STATIC_SHM -#define KERNEL_INFO_SHM_MEM_INIT .shm_mem.common.max_banks = NR_MEM_BANKS, +#define KERNEL_INFO_SHM_MEM_INIT .shm_mem.common.max_banks = NR_SHMEM_BANKS,#else #define KERNEL_INFO_SHM_MEM_INIT #endif
xen/arch/arm/include/asm/setup.h +38 -3
87 lines not on this page · raw message
xen/arch/arm/include/asm/static-shmem.h +8 -0
@@ -25,6 +25,10 @@ static inline int process_shm_chosen(struct domain *d,int process_shm_node (const void *fdt,int node,uint32_t address_cells,uint32_t size_cells); +void early_print_info_shmem (void ); + +void init_sharedmem_pages (void ); +#else /* !CONFIG_STATIC_SHM */ static inline int make_resv_memory_node(const struct domain *d,
@@ -53,6 +57,10 @@ static inline int process_shm_node(const void *fdt, int node,return -EINVAL ; } +static inline void early_print_info_shmem (void ) {}; + +static inline void init_sharedmem_pages (void ) {}; +#endif /* CONFIG_STATIC_SHM */ #endif /* __ASM_STATIC_SHMEM_H_ */
xen/arch/arm/setup.c +24 -1
@@ -208,6 +208,9 @@ static void __init dt_unreserved_regions(paddr_t s, paddr_t e, unsigned int first) {const struct membanks *reserved_mem =bootinfo_get_reserved_mem (); +#ifdef CONFIG_STATIC_SHM +const struct membanks *shmem =bootinfo_get_shmem (); +#endif unsigned int i, nr;int rc;
@@ -258,6 +261,22 @@ static void __init dt_unreserved_regions(paddr_t s, paddr_t e, } } +#ifdef CONFIG_STATIC_SHM + nr += reserved_mem->nr_banks; +for ( ; i - nr < shmem->nr_banks; i++ ) + { +paddr_t r_s = shmem->bank[i - nr].start; +paddr_t r_e = r_s + shmem->bank[i - nr].size; + +if ( s < r_e && r_s < e ) + { +dt_unreserved_regions (r_e, e, cb, i +1 ); +dt_unreserved_regions (s, r_s, cb, i +1 ); +return ; + } + } +#endif +cb (s, e); }
@@ -344,13 +363,17 @@ bool __init check_reserved_regions_overlap(paddr_t region_start, bootinfo_get_reserved_mem(),#ifdef CONFIG_ACPI bootinfo_get_acpi(), +#endif +#ifdef CONFIG_STATIC_SHM + bootinfo_get_shmem(),#endif };unsigned int i;/* * Check if input region is overlapping with reserved memory banks or -* ACPI EfiACPIReclaimMemory (when ACPI feature is enabled) +* ACPI EfiACPIReclaimMemory (when ACPI feature is enabled) or static +* shared memory banks (when static shared memory feature is enabled) */ for ( i =0 ; i <ARRAY_SIZE (mem_banks); i++ )if (meminfo_overlap_check (mem_banks[i], region_start, region_size) )
xen/arch/arm/static-shmem.c +51 -18
154 lines not on this page · raw message
Signature · 1 line
2.34.1
Re: [PATCH 08/11] xen/arm: Reduce struct membank size on static shared memory
Hi Luca,
Quoted 10 lines · Luca Fancellu
Currently the memory footprint of the static shared memory feature is impacting all the struct meminfo instances with memory space that is not going to be used.
To solve this issue, rework the static shared memory extra information linked to the memory bank to another structure, struct
shmem_membank_extra, and exploit the struct membank padding to host a pointer to that structure in a union with the
NIT: AFAICT the padding will be reused on Arm64 but on Arm32 there will still be 4B padding.
Quoted 14 lines
enum
membank_type, with this trick the 'struct membank' has the same size with or without the static shared memory, given that the 'type' and 'shmem_extra' are never used at the same time.Afterwards, create a new structure 'struct
shared_meminfo' which has the same interface of 'struct meminfo', but requires less banks and hosts the extra information for the static shared memory. The fields 'bank' and 'extra' of this structure are meant to be linked by the index (e.g. extra[idx] will have the information for the bank[idx], for i=0..NR_SHMEM_BANKS), the convinient pointer 'shmem_extra' of 'struct membank' is then linked to the related 'extra' bank to ease the fruition when a function has access only to the 'struct membanks common' of 'structshared_meminfo'.
Quoted 6 lines
The last part of this work is to move the allocation of the static shared memory banks from the '
reserved_mem' to a new 'shmem' member of the 'struct bootinfo'.
Change also the 'shm_mem' member type to be 'structshared_meminfo' in order to match the above changes and allow a memory space reduction also in 'structkernel_info'.
Ok, so from this point onwards, when dealing with "reserved" memory, one needs to account for shmem as well, as it will no longer be part of bootinfo.reserved_mem (unlike static-mem or static-heap). This is really the only disadvantage. The changes LGTM, just a few comments below.
Quoted 183 lines
Signed-off-by Luca Fancellu <[email protected]>--- xen/arch/arm/arm32/mmu/mm.c | 24 +++++++++ xen/arch/arm/arm64/mmu/mm.c | 2 + xen/arch/arm/bootfdt.c | 1 + xen/arch/arm/domain_build.c | 4 ++ xen/arch/arm/include/asm/kernel.h | 4 +- xen/arch/arm/include/asm/setup.h | 41 +++++++++++++-- xen/arch/arm/include/asm/static-shmem.h | 8 +++ xen/arch/arm/setup.c | 25 ++++++++- xen/arch/arm/static-shmem.c | 69 ++++++++++++++++++------- 9 files changed, 154 insertions(+), 24 deletions(-)xen/arch/arm/arm32/mmu/mm.c +24
-0@@ -7,6 +7,7 @@#include <xen/pfn.h> #include <asm/fixmap.h> #include <asm/static-memory.h> +#include <asm/static-shmem.h> static unsigned long opt_xenheap_megabytes__initdata ;integer_param ("xenheap_megabytes" , opt_xenheap_megabytes);@@ -42,6 +43,9 @@ static paddr_t __init consider_modules(paddr_t s, paddr_t e, int first_mod) {const struct membanks *reserved_mem =bootinfo_get_reserved_mem (); +#ifdef CONFIG_STATIC_SHM +const struct membanks *shmem =bootinfo_get_shmem (); +#endif const struct bootmodules *mi = &bootinfo.modules;int i;int nr;@@ -118,6 +122,25 @@ static paddr_t __init consider_modules(paddr_t s, paddr_t e,return consider_modules (s, r_s, size, align, i +1 ); } } + +#ifdef CONFIG_STATIC_SHM + nr += reserved_mem->nr_banks; +for ( ; i - nr < shmem->nr_banks; i++ ) + { +paddr_t r_s = shmem->bank[i - nr].start; +paddr_t r_e = r_s + shmem->bank[i - nr].size; + +if ( s < r_e && r_s < e ) + { + r_e =consider_modules (r_e, e, size, align, i +1 ); +if ( r_e ) +return r_e; + +return consider_modules (s, r_s, size, align, i +1 ); + } + } +#endif +return e; }@@ -294,6 +317,7 @@ void __init setup_mm(void) mfn_to_maddr(directmap_mfn_end));init_staticmem_pages (); +init_sharedmem_pages (); }/* xen/arch/arm/arm64/mmu/mm.c +2
-0@@ -6,6 +6,7 @@#include <asm/setup.h> #include <asm/static-memory.h> +#include <asm/static-shmem.h> /* Override macros from asm/page.h to make them work with mfn_t */ #undef virt_to_mfn@@ -236,6 +237,7 @@ void __init setup_mm(void) max_page =PFN_DOWN (ram_end);init_staticmem_pages (); +init_sharedmem_pages (); }/* xen/arch/arm/bootfdt.c +1
-0@@ -499,6 +499,7 @@ static void __init early_print_info(void) mem_resv->bank[j].start, mem_resv->bank[j].start + mem_resv->bank[j].size - 1); } +early_print_info_shmem ();printk ("\n" );for ( i =0 ; i < cmds->nr_mods; i++ ) printk("CMDLINE[%"PRIpaddr"]:%s %s\n", cmds->cmdline[i].start,xen/arch/arm/domain_build.c +4
-0@@ -864,6 +864,7 @@ static int __init add_ext_regions(unsigned long s_gfn, unsigned long e_gfn,* regions we exclude every region assigned to Dom0 from the Host RAM: * - domain RAM * - reserved-memory +* - static shared memory * - grant table space */ static int __init find_unallocated_memory(const struct kernel_info *kinfo,@@ -873,6 +874,9 @@ static int __init find_unallocated_memory(const struct kernel_info *kinfo,bootinfo_get_mem (),kernel_info_get_mem (kinfo),bootinfo_get_reserved_mem (), +#ifdef CONFIG_STATIC_SHM + bootinfo_get_shmem(), +#endif };struct rangeset *unalloc_mem;paddr_t start, end;xen/arch/arm/include/asm/kernel.h +2
-2@@ -40,7 +40,7 @@ struct kernel_info {paddr_t unassigned_mem;/* RAM not (yet) assigned to a bank */ struct meminfo mem;#ifdef CONFIG_STATIC_SHM -struct meminfo shm_mem; +struct shared_meminfo shm_mem;#endif /* kernel entry point */ @@ -84,7 +84,7 @@ struct kernel_info { (&(kinfo)->mem.common)#ifdef CONFIG_STATIC_SHM -#define KERNEL_INFO_SHM_MEM_INIT .shm_mem.common.max_banks = NR_MEM_BANKS, +#define KERNEL_INFO_SHM_MEM_INIT .shm_mem.common.max_banks = NR_SHMEM_BANKS,#else #define KERNEL_INFO_SHM_MEM_INIT #endif xen/arch/arm/include/asm/setup.h +10
-3@@ -9,6 +9,7 @@#define MAX_FDT_SIZE SZ_2M#define NR_MEM_BANKS 256 +#define NR_SHMEM_BANKS 32#define MAX_MODULES 32/* Current maximum useful modules */ @@ -46,14 +47,20 @@ enum membank_type {/* Indicates the maximum number of characters(\0 included) for shm_id */ #define MAX_SHM_ID_LENGTH 16 +struct shmem_membank_extra { +char shm_id[MAX_SHM_ID_LENGTH ]; +unsigned int nr_shm_borrowers; +}; +struct membank {paddr_t start;paddr_t size; -enum membank_type type; +union { +enum membank_type type;#ifdef CONFIG_STATIC_SHM -char shm_id[MAX_SHM_ID_LENGTH ]; -unsigned int nr_shm_borrowers; +struct shmem_membank_extra *shmem_extra;#endif + }; };struct membanks {
xen/arch/arm/include/asm/setup.h struct meminfo { · line 81
Quoted 8 lines
xen/arch/arm/include/asm/setup.h +5
-0@@ -67,6 +74,12 @@ struct meminfo {struct membank bank[NR_MEM_BANKS ]; }; +struct shared_meminfo { +struct membanks common; +struct membank bank[NR_SHMEM_BANKS ]; +struct shmem_membank_extra extra[NR_SHMEM_BANKS ]; +};
Same as with meminfo, please add a BUILD_BUG_ON for padding between common and bank.
Quoted 176 lines
xen/arch/arm/include/asm/setup.h +23
-0+/* * The domU flag is set for kernels and ramdisks of "xen,domain" nodes. * The purpose of the domU flag is to avoid getting confused in @@ -109,6 +122,9 @@ struct bootinfo {struct bootcmdlines cmdlines;#ifdef CONFIG_ACPI struct meminfo acpi; +#endif +#ifdef CONFIG_STATIC_SHM +struct shared_meminfo shmem;#endif bool static_heap; };@@ -119,11 +135,18 @@ struct bootinfo {#define BOOTINFO_ACPI_INIT #endif +#ifdef CONFIG_STATIC_SHM +#define BOOTINFO_SHMEM_INIT .shmem.common.max_banks = NR_SHMEM_BANKS, +#else +#define BOOTINFO_SHMEM_INIT +#endif +#define BOOTINFO_INIT \ { \ .mem.common.max_banks = NR_MEM_BANKS, \ .reserved_mem.common.max_banks = NR_MEM_BANKS, \ BOOTINFO_ACPI_INIT \ + BOOTINFO_SHMEM_INIT \ }struct map_range_data @@ -158,6 +181,18 @@ static inline struct membanks *bootinfo_get_acpi(void) }#endif +#ifdef CONFIG_STATIC_SHM +static inline struct membanks *bootinfo_get_shmem (void ) +{ +return &bootinfo.shmem.common; +} + +static inline struct shmem_membank_extra *bootinfo_get_shmem_extra (void ) +{ +return bootinfo.shmem.extra; +} +#endif +void copy_from_paddr (void *dst,paddr_t paddr,unsigned long len);size_t estimate_efi_size (unsigned int mem_nr_banks);xen/arch/arm/include/asm/static-shmem.h +8
-0@@ -25,6 +25,10 @@ static inline int process_shm_chosen(struct domain *d,int process_shm_node (const void *fdt,int node,uint32_t address_cells,uint32_t size_cells); +void early_print_info_shmem (void ); + +void init_sharedmem_pages (void ); +#else /* !CONFIG_STATIC_SHM */ static inline int make_resv_memory_node(const struct domain *d,@@ -53,6 +57,10 @@ static inline int process_shm_node(const void *fdt, int node,return -EINVAL ; } +static inline void early_print_info_shmem (void ) {}; + +static inline void init_sharedmem_pages (void ) {}; +#endif /* CONFIG_STATIC_SHM */ #endif /* __ASM_STATIC_SHMEM_H_ */ xen/arch/arm/setup.c +24
-1@@ -208,6 +208,9 @@ static void __init dt_unreserved_regions(paddr_t s, paddr_t e, unsigned int first) {const struct membanks *reserved_mem =bootinfo_get_reserved_mem (); +#ifdef CONFIG_STATIC_SHM +const struct membanks *shmem =bootinfo_get_shmem (); +#endif unsigned int i, nr;int rc;@@ -258,6 +261,22 @@ static void __init dt_unreserved_regions(paddr_t s, paddr_t e, } } +#ifdef CONFIG_STATIC_SHM + nr += reserved_mem->nr_banks; +for ( ; i - nr < shmem->nr_banks; i++ ) + { +paddr_t r_s = shmem->bank[i - nr].start; +paddr_t r_e = r_s + shmem->bank[i - nr].size; + +if ( s < r_e && r_s < e ) + { +dt_unreserved_regions (r_e, e, cb, i +1 ); +dt_unreserved_regions (s, r_s, cb, i +1 ); +return ; + } + } +#endif +cb (s, e); }@@ -344,13 +363,17 @@ bool __init check_reserved_regions_overlap(paddr_t region_start, bootinfo_get_reserved_mem(),#ifdef CONFIG_ACPI bootinfo_get_acpi(), +#endif +#ifdef CONFIG_STATIC_SHM + bootinfo_get_shmem(),#endif };unsigned int i;/* * Check if input region is overlapping with reserved memory banks or -* ACPI EfiACPIReclaimMemory (when ACPI feature is enabled) +* ACPI EfiACPIReclaimMemory (when ACPI feature is enabled) or static +* shared memory banks (when static shared memory feature is enabled) */ for ( i =0 ; i <ARRAY_SIZE (mem_banks); i++ )if (meminfo_overlap_check (mem_banks[i], region_start, region_size) )xen/arch/arm/static-shmem.c +7
-6@@ -4,29 +4,30 @@#include <xen/sched.h> #include <asm/domain_build.h> +#include <asm/static-memory.h> #include <asm/static-shmem.h> static int __init acquire_nr_borrower_domain (struct domain *d,paddr_t pbase,paddr_t psize,unsigned long *nr_borrowers) { -const struct membanks *reserved_mem =bootinfo_get_reserved_mem (); +const struct membanks *shmem =bootinfo_get_shmem ();unsigned int bank;/* Iterate reserved memory to find requested shm bank. */ -for ( bank =0 ; bank < reserved_mem->nr_banks; bank++ ) +for ( bank =0 ; bank < shmem->nr_banks; bank++ ) { -paddr_t bank_start = reserved_mem->bank[bank].start; -paddr_t bank_size = reserved_mem->bank[bank].size; +paddr_t bank_start = shmem->bank[bank].start; +paddr_t bank_size = shmem->bank[bank].size;if ( (pbase == bank_start) && (psize == bank_size) )break ; } -if ( bank == reserved_mem->nr_banks ) +if ( bank == shmem->nr_banks )return -ENOENT ; - *nr_borrowers = reserved_mem->bank[bank].nr_shm_borrowers; + *nr_borrowers = shmem->bank[bank].shmem_extra->nr_shm_borrowers;return 0 ; }
xen/arch/arm/static-shmem.c static int __init assign_shared_memory(struct domain *d, · line 163
Quoted 8 lines
xen/arch/arm/static-shmem.c +2
-3@@ -158,16 +159,22 @@ static int __init assign_shared_memory(struct domain *d,return ret; } -static int __init append_shm_bank_to_domain (struct membanks *shm_mem, -paddr_t start,paddr_t size, -const char *shm_id) +static int __init +append_shm_bank_to_domain(struct shared_meminfo *kinfo_shm_mem, paddr_t start,
Is there any particular reason to prepend the shm_mem name with kinfo?
~Michal
Re: [PATCH 08/11] xen/arm: Reduce struct membank size on static shared memory
Quoted 13 lines · Michal Orzel
Hi Luca,
Quoted 6 lines · Luca Fancellu
Currently the memory footprint of the static shared memory feature is impacting all the struct meminfo instances with memory space that is not going to be used.
Quoted 5 lines
Quoted 4 lines
To solve this issue, rework the static shared memory extra information linked to the memory bank to another structure, struct
shmem_membank_extra, and exploit the struct membank padding to host a pointer to that structure in a union with theNIT: AFAICT the padding will be reused on Arm64 but on Arm32 there will still be 4B padding.
Yes, my purpose was to make clear that no additional space was needed for that pointer, should I rephrase it or it’s ok?
Quoted 8 lines
xen/arch/arm/include/asm/setup.h struct meminfo { · line 81
Quoted 7 lines
xen/arch/arm/include/asm/setup.h +5
-0+struct shared_meminfo { +struct membanks common; +struct membank bank[NR_SHMEM_BANKS ]; +struct shmem_membank_extra extra[NR_SHMEM_BANKS ]; +};Same as with meminfo, please add a
BUILD_BUG_ONfor padding between common and bank.
Sure
Quoted 8 lines
xen/arch/arm/static-shmem.c static int __init assign_shared_memory(struct domain *d, · line 163
Quoted 7 lines
xen/arch/arm/static-shmem.c +2
-3-static int __init append_shm_bank_to_domain (struct membanks *shm_mem, -paddr_t start,paddr_t size, -const char *shm_id) +static int __init +append_shm_bank_to_domain(struct shared_meminfo *kinfo_shm_mem, paddr_t start,Is there any particular reason to prepend the
shm_memname with kinfo?
I think because usually kinfo is used to point to ’struct kernel_info’, instead here we point to 'struct shared_meminfo'
Quoted 2 lines
~Michal
Re: [PATCH 08/11] xen/arm: Reduce struct membank size on static shared memory
Hi Luca,
Quoted 13 lines · Luca Fancellu
Quoted 13 lines · Michal Orzel
Hi Luca,
Quoted 6 lines · Luca Fancellu
Currently the memory footprint of the static shared memory feature is impacting all the struct meminfo instances with memory space that is not going to be used.
Quoted 8 lines
Quoted 5 lines
Quoted 4 lines
To solve this issue, rework the static shared memory extra information linked to the memory bank to another structure, struct
shmem_membank_extra, and exploit the struct membank padding to host a pointer to that structure in a union with theNIT: AFAICT the padding will be reused on Arm64 but on Arm32 there will still be 4B padding.
Yes, my purpose was to make clear that no additional space was needed for that pointer, should I rephrase it or it’s ok?
Since you are modifying this patch anyway, you can take the opportunity to rephrase it.
Quoted 22 lines
Quoted 10 lines
xen/arch/arm/include/asm/setup.h struct meminfo { · line 81
Quoted 9 lines
xen/arch/arm/include/asm/setup.h +5
-0+struct shared_meminfo { +struct membanks common; +struct membank bank[NR_SHMEM_BANKS ]; +struct shmem_membank_extra extra[NR_SHMEM_BANKS ]; +};Same as with meminfo, please add a
BUILD_BUG_ONfor padding between common and bank.Sure
Quoted 8 lines
xen/arch/arm/static-shmem.c static int __init assign_shared_memory(struct domain *d, · line 163
Quoted 7 lines
xen/arch/arm/static-shmem.c +2
-3-static int __init append_shm_bank_to_domain (struct membanks *shm_mem, -paddr_t start,paddr_t size, -const char *shm_id) +static int __init +append_shm_bank_to_domain(struct shared_meminfo *kinfo_shm_mem, paddr_t start,Is there any particular reason to prepend the
shm_memname with kinfo?
Quoted 6 lines
I think because usually kinfo is used to point to ’struct kernel_info’, instead here we point to 'struct
shared_meminfo'Quoted 2 lines
~Michal
~Michal
PATCH 9/11 xen/arm: remove shm holes for extended regions
In reply to Luca FancelluFrom: Penny Zheng <[email protected]>
Static shared memory acts as reserved memory in guest, so it shall be excluded from extended regions.
Extended regions are taken care of under three different scenarios:
normal DomU, direct-map domain with iommu on, and direct-map domain with iommu off.
For normal DomU, we create a new function "remove_shm_holes_for_domU", to firstly transfer original outputs into the format of "struct rangeset", then use "remove_shm_from_rangeset" to remove static shm from them.
For direct-map domain with iommu on, after we get guest shm info from "kinfo", we use "remove_shm_from_rangeset" to remove static shm.
For direct-map domain with iommu off, as static shm has already been taken care of through reserved memory banks, we do nothing.
---
v1:
- Rework of https://patchwork.kernel.org/project/xen-devel/patch/[email protected]/
--- xen/arch/arm/domain_build.c | 16 ++++- xen/arch/arm/include/asm/domain_build.h | 2 + xen/arch/arm/include/asm/static-shmem.h | 18 ++++++ xen/arch/arm/static-shmem.c | 86 +++++++++++++++++++++++++ 4 files changed, 119 insertions(+), 3 deletions(-)
xen/arch/arm/domain_build.c +13 -3
@@ -817,8 +817,8 @@ int __init make_memory_node(const struct domain *d,return res; } -static int __init add_ext_regions (unsigned long s_gfn,unsigned long e_gfn, -void *data) +int __init add_ext_regions (unsigned long s_gfn,unsigned long e_gfn, +void *data) {struct membanks *ext_regions = data;paddr_t start, size;
@@ -969,6 +969,8 @@ static int __init handle_pci_range(const struct dt_device_node *dev,* - MMIO * - Host RAM * - PCI aperture +* - Static shared memory regions, which are described by special property +* "xen,domain-shared-memory-v1" */ static int __init find_memory_holes (const struct kernel_info *kinfo,struct membanks *ext_regions)
@@ -985,6 +987,11 @@ static int __init find_memory_holes(const struct kernel_info *kinfo,if ( !mem_holes )return -ENOMEM ; +/* Remove static shared memory regions */ + res =remove_shm_from_rangeset (kinfo, mem_holes); +if ( res ) + goto out; +/* Start with maximum possible addressable physical memory range */ start =0 ; end = (1ULL << p2m_ipa_bits) -1 ;
@@ -1089,7 +1096,10 @@ static int __init find_domU_holes(const struct kernel_info *kinfo, res =0 ; } -return res; +if ( res ) +return res; + +return remove_shm_holes_for_domU (kinfo, ext_regions); } int __init make_hypervisor_node(struct domain *d,
xen/arch/arm/include/asm/domain_build.h +2 -0
@@ -51,6 +51,8 @@ static inline int prepare_acpi(struct domain *d, struct kernel_info *kinfo)int prepare_acpi (struct domain *d,struct kernel_info *kinfo);#endif +int add_ext_regions (unsigned long s_gfn,unsigned long e_gfn,void *data); +#endif /*
xen/arch/arm/include/asm/static-shmem.h +18 -0
@@ -29,6 +29,12 @@ void early_print_info_shmem(void);void init_sharedmem_pages (void ); +int remove_shm_from_rangeset (const struct kernel_info *kinfo, +struct rangeset *rangeset); + +int remove_shm_holes_for_domU (const struct kernel_info *kinfo, +struct membanks *ext_regions); +#else /* !CONFIG_STATIC_SHM */ static inline int make_resv_memory_node(const struct domain *d,
@@ -61,6 +67,18 @@ static inline void early_print_info_shmem(void) {};static inline void init_sharedmem_pages (void ) {}; +static inline int remove_shm_from_rangeset (const struct kernel_info *kinfo, +struct rangeset *rangeset) +{ +return 0 ; +} + +static inline int remove_shm_holes_for_domU (const struct kernel_info *kinfo, +struct membanks *ext_regions) +{ +return 0 ; +} +#endif /* CONFIG_STATIC_SHM */ #endif /* __ASM_STATIC_SHMEM_H_ */
xen/arch/arm/static-shmem.c +86 -0
98 lines not on this page · raw message
Signature · 1 line
2.34.1
Re: [PATCH 09/11] xen/arm: remove shm holes for extended regions
Hi Luca,
NIT: title s/for/from?
Quoted 50 lines · Luca Fancellu
From: Penny Zheng <[email protected]>
Static shared memory acts as reserved memory in guest, so it shall be excluded from extended regions.
Extended regions are taken care of under three different scenarios:
normal DomU, direct-map domain with iommu on, and direct-map domain with iommu off.For normal DomU, we create a new function "
remove_shm_holes_for_domU", to firstly transfer original outputs into the format of "struct rangeset", then use "remove_shm_from_rangeset" to remove static shm from them.For direct-map domain with iommu on, after we get guest shm info from "kinfo", we use "
remove_shm_from_rangeset" to remove static shm.For direct-map domain with iommu off, as static shm has already been taken care of through reserved memory banks, we do nothing.
Signed-off-by Penny Zheng <[email protected]>Signed-off-by Luca Fancellu <[email protected]>---
v1:
- Rework of https://patchwork.kernel.org/project/xen-devel/patch/[email protected]/--- xen/arch/arm/domain_build.c | 16 ++++- xen/arch/arm/include/asm/domain_build.h | 2 + xen/arch/arm/include/asm/static-shmem.h | 18 ++++++ xen/arch/arm/static-shmem.c | 86 +++++++++++++++++++++++++ 4 files changed, 119 insertions(+), 3 deletions(-)xen/arch/arm/domain_build.c +2
-2@@ -817,8 +817,8 @@ int __init make_memory_node(const struct domain *d,return res; } -static int __init add_ext_regions (unsigned long s_gfn,unsigned long e_gfn, -void *data) +int __init add_ext_regions (unsigned long s_gfn,unsigned long e_gfn, +void *data) {struct membanks *ext_regions = data;paddr_t start, size;
xen/arch/arm/domain_build.c static int __init handle_pci_range(const struct dt_device_node *dev, · line 973
Quoted 5 lines
xen/arch/arm/domain_build.c +2
-0@@ -969,6 +969,8 @@ static int __init handle_pci_range(const struct dt_device_node *dev,* - MMIO * - Host RAM * - PCI aperture +* - Static shared memory regions, which are described by special property +* "xen,domain-shared-memory-v1"
I'm not sure if providing a compatible here makes sense. If at all, I would put "xen,shared-mem" which holds the addresses.
xen/arch/arm/domain_build.c static int __init find_memory_holes(const struct kernel_info *kinfo, · line 993
Quoted 11 lines
xen/arch/arm/domain_build.c +4
-0*/ static int __init find_memory_holes (const struct kernel_info *kinfo,struct membanks *ext_regions)@@ -985,6 +987,11 @@ static int __init find_memory_holes(const struct kernel_info *kinfo,if ( !mem_holes )return -ENOMEM ; +/* Remove static shared memory regions */ + res =remove_shm_from_rangeset (kinfo, mem_holes); +if ( res ) + goto out;
How can you remove from a rangeset without first adding to it? This should be moved after rangeset_add_range().
Also, usually (and this is the case in this function) we pass frames to rangeset and not addresses (argument is of type ul). However...
Quoted 81 lines
xen/arch/arm/domain_build.c +5
-1+/* Start with maximum possible addressable physical memory range */ start =0 ; end = (1ULL << p2m_ipa_bits) -1 ;@@ -1089,7 +1096,10 @@ static int __init find_domU_holes(const struct kernel_info *kinfo, res =0 ; } -return res; +if ( res ) +return res; + +return remove_shm_holes_for_domU (kinfo, ext_regions); } int __init make_hypervisor_node(struct domain *d,xen/arch/arm/include/asm/domain_build.h +2
-0@@ -51,6 +51,8 @@ static inline int prepare_acpi(struct domain *d, struct kernel_info *kinfo)int prepare_acpi (struct domain *d,struct kernel_info *kinfo);#endif +int add_ext_regions (unsigned long s_gfn,unsigned long e_gfn,void *data); +#endif /* xen/arch/arm/include/asm/static-shmem.h +18
-0@@ -29,6 +29,12 @@ void early_print_info_shmem(void);void init_sharedmem_pages (void ); +int remove_shm_from_rangeset (const struct kernel_info *kinfo, +struct rangeset *rangeset); + +int remove_shm_holes_for_domU (const struct kernel_info *kinfo, +struct membanks *ext_regions); +#else /* !CONFIG_STATIC_SHM */ static inline int make_resv_memory_node(const struct domain *d,@@ -61,6 +67,18 @@ static inline void early_print_info_shmem(void) {};static inline void init_sharedmem_pages (void ) {}; +static inline int remove_shm_from_rangeset (const struct kernel_info *kinfo, +struct rangeset *rangeset) +{ +return 0 ; +} + +static inline int remove_shm_holes_for_domU (const struct kernel_info *kinfo, +struct membanks *ext_regions) +{ +return 0 ; +} +#endif /* CONFIG_STATIC_SHM */ #endif /* __ASM_STATIC_SHMEM_H_ */ xen/arch/arm/static-shmem.c +1
-0@@ -1,6 +1,7 @@/* SPDX-License-Identifier: GPL-2.0-only */ #include <xen/libfdt/libfdt.h> +#include <xen/rangeset.h> #include <xen/sched.h> #include <asm/domain_build.h> @@ -564,6 +565,91 @@ void __init init_sharedmem_pages(void)init_staticmem_bank (&shmem->bank[bank]); }
xen/arch/arm/static-shmem.c void __init init_sharedmem_pages(void) · line 577
Quoted 10 lines
xen/arch/arm/static-shmem.c +10
-0+int __init remove_shm_from_rangeset (const struct kernel_info *kinfo, +struct rangeset *rangeset) +{ +const struct membanks *shm_mem = &kinfo->shm_mem.common; +unsigned int i; + +/* Remove static shared memory regions */ +for ( i =0 ; i < shm_mem->nr_banks; i++ ) + { +paddr_t start, end;
... here, these hold physical addresses and...
xen/arch/arm/static-shmem.c void __init init_sharedmem_pages(void) · line 582
Quoted 5 lines
xen/arch/arm/static-shmem.c +5
-0+int res; + + start = shm_mem->bank[i].start; + end = shm_mem->bank[i].start + shm_mem->bank[i].size -1 ; + res =rangeset_remove_range (rangeset, start, end);
you will end up in a mix which won't work. Switch to PFN_DOWN()
xen/arch/arm/static-shmem.c void __init init_sharedmem_pages(void) · line 583
Quoted 1 line
xen/arch/arm/static-shmem.c +1
-0+if ( res )
What's the point of res variable if it is not printed below?
Quoted 27 lines
xen/arch/arm/static-shmem.c +27
-0+ { +printk (XENLOG_ERR "Failed to remove: %#" PRIpaddr"->%#" PRIpaddr"\n" , + start, end); +return -EINVAL ; + } + } + +return 0 ; +} + +int __init remove_shm_holes_for_domU (const struct kernel_info *kinfo, +struct membanks *ext_regions) +{ +const struct membanks *shm_mem = &kinfo->shm_mem.common; +struct rangeset *guest_holes; +unsigned int i; +paddr_t start; +paddr_t end; +int res; + +/* No static shared memory region. */ +if ( shm_mem->nr_banks ==0 ) +return 0 ; + +dt_dprintk ("Remove static shared memory holes for extended regions of DomU\n" ); + + guest_holes =rangeset_new (NULL ,NULL ,0 );
xen/arch/arm/static-shmem.c void __init init_sharedmem_pages(void) · line 620
Quoted 10 lines
xen/arch/arm/static-shmem.c +10
-0+if ( !guest_holes ) +return -ENOMEM ; + +/* Copy extended regions sets into the rangeset */ +for ( i =0 ; i < ext_regions->nr_banks; i++ ) + { + start = ext_regions->bank[i].start; + end = start + ext_regions->bank[i].size -1 ; + + res =rangeset_add_range (guest_holes, start, end);
Ditto, PFN_DOWN().
~Michal
Re: [PATCH 09/11] xen/arm: remove shm holes for extended regions
Quoted 73 lines · Michal Orzel
Hi Luca,
NIT: title s/for/from?
Quoted 50 lines · Luca Fancellu
From: Penny Zheng <[email protected]>
Static shared memory acts as reserved memory in guest, so it shall be excluded from extended regions.
Extended regions are taken care of under three different scenarios:
normal DomU, direct-map domain with iommu on, and direct-map domain with iommu off.For normal DomU, we create a new function "
remove_shm_holes_for_domU", to firstly transfer original outputs into the format of "struct rangeset", then use "remove_shm_from_rangeset" to remove static shm from them.For direct-map domain with iommu on, after we get guest shm info from "kinfo", we use "
remove_shm_from_rangeset" to remove static shm.For direct-map domain with iommu off, as static shm has already been taken care of through reserved memory banks, we do nothing.
Signed-off-by Penny Zheng <[email protected]>Signed-off-by Luca Fancellu <[email protected]>---
v1:
- Rework of https://patchwork.kernel.org/project/xen-devel/patch/[email protected]/
---xen/arch/arm/domain_build.c | 16 ++++- xen/arch/arm/include/asm/domain_build.h | 2 + xen/arch/arm/include/asm/static-shmem.h | 18 ++++++ xen/arch/arm/static-shmem.c | 86 +++++++++++++++++++++++++ 4 files changed, 119 insertions(+), 3 deletions(-)xen/arch/arm/domain_build.c +2
-2@@ -817,8 +817,8 @@ int __init make_memory_node(const struct domain *d,return res; } -static int __init add_ext_regions (unsigned long s_gfn,unsigned long e_gfn, -void *data) +int __init add_ext_regions (unsigned long s_gfn,unsigned long e_gfn, +void *data) {struct membanks *ext_regions = data;paddr_t start, size;xen/arch/arm/domain_build.c static int __init handle_pci_range(const struct dt_device_node *dev, · line 973
Quoted 5 lines
xen/arch/arm/domain_build.c +2
-0@@ -969,6 +969,8 @@ static int __init handle_pci_range(const struct dt_device_node *dev,* - MMIO * - Host RAM * - PCI aperture +* - Static shared memory regions, which are described by special property +* "xen,domain-shared-memory-v1" I'm not sure if providing a compatible here makes sense. If at all, I would put "xen,shared-mem" which holds the addresses.
Quoted 7 lines
xen/arch/arm/domain_build.c +0
-0*/ static int __init find_memory_holes (const struct kernel_info *kinfo,struct membanks *ext_regions)@@ -985,6 +987,11 @@ static int __init find_memory_holes(const struct kernel_info *kinfo,if ( !mem_holes )return -ENOMEM ;
Quoted 6 lines
xen/arch/arm/domain_build.c static int __init find_memory_holes(const struct kernel_info *kinfo, · line 993
Quoted 4 lines
xen/arch/arm/domain_build.c +4
-0+/* Remove static shared memory regions */ + res =remove_shm_from_rangeset (kinfo, mem_holes); +if ( res ) + goto out;How can you remove from a rangeset without first adding to it? This should be moved after
rangeset_add_range().
You are very right
Quoted 96 lines
Also, usually (and this is the case in this function) we pass frames to rangeset and not addresses (argument is of type ul). However...
Quoted 81 lines
xen/arch/arm/domain_build.c +5
-1+/* Start with maximum possible addressable physical memory range */ start =0 ; end = (1ULL << p2m_ipa_bits) -1 ;@@ -1089,7 +1096,10 @@ static int __init find_domU_holes(const struct kernel_info *kinfo, res =0 ; } -return res; +if ( res ) +return res; + +return remove_shm_holes_for_domU (kinfo, ext_regions); } int __init make_hypervisor_node(struct domain *d,xen/arch/arm/include/asm/domain_build.h +2
-0@@ -51,6 +51,8 @@ static inline int prepare_acpi(struct domain *d, struct kernel_info *kinfo)int prepare_acpi (struct domain *d,struct kernel_info *kinfo);#endif +int add_ext_regions (unsigned long s_gfn,unsigned long e_gfn,void *data); +#endif /* xen/arch/arm/include/asm/static-shmem.h +18
-0@@ -29,6 +29,12 @@ void early_print_info_shmem(void);void init_sharedmem_pages (void ); +int remove_shm_from_rangeset (const struct kernel_info *kinfo, +struct rangeset *rangeset); + +int remove_shm_holes_for_domU (const struct kernel_info *kinfo, +struct membanks *ext_regions); +#else /* !CONFIG_STATIC_SHM */ static inline int make_resv_memory_node(const struct domain *d,@@ -61,6 +67,18 @@ static inline void early_print_info_shmem(void) {};static inline void init_sharedmem_pages (void ) {}; +static inline int remove_shm_from_rangeset (const struct kernel_info *kinfo, +struct rangeset *rangeset) +{ +return 0 ; +} + +static inline int remove_shm_holes_for_domU (const struct kernel_info *kinfo, +struct membanks *ext_regions) +{ +return 0 ; +} +#endif /* CONFIG_STATIC_SHM */ #endif /* __ASM_STATIC_SHMEM_H_ */ xen/arch/arm/static-shmem.c +1
-0@@ -1,6 +1,7 @@/* SPDX-License-Identifier: GPL-2.0-only */ #include <xen/libfdt/libfdt.h> +#include <xen/rangeset.h> #include <xen/sched.h> #include <asm/domain_build.h> @@ -564,6 +565,91 @@ void __init init_sharedmem_pages(void)init_staticmem_bank (&shmem->bank[bank]); }xen/arch/arm/static-shmem.c void __init init_sharedmem_pages(void) · line 577
Quoted 10 lines
xen/arch/arm/static-shmem.c +10
-0+int __init remove_shm_from_rangeset (const struct kernel_info *kinfo, +struct rangeset *rangeset) +{ +const struct membanks *shm_mem = &kinfo->shm_mem.common; +unsigned int i; + +/* Remove static shared memory regions */ +for ( i =0 ; i < shm_mem->nr_banks; i++ ) + { +paddr_t start, end;... here, these hold physical addresses and...
Quoted 6 lines
xen/arch/arm/static-shmem.c void __init init_sharedmem_pages(void) · line 582
Quoted 5 lines
xen/arch/arm/static-shmem.c +5
-0+int res; + + start = shm_mem->bank[i].start; + end = shm_mem->bank[i].start + shm_mem->bank[i].size -1 ; + res =rangeset_remove_range (rangeset, start, end);you will end up in a mix which won't work. Switch to
PFN_DOWN()
Will fix
Quoted 3 lines
xen/arch/arm/static-shmem.c void __init init_sharedmem_pages(void) · line 583
Quoted 2 lines
xen/arch/arm/static-shmem.c +1
-0+if ( res )What's the point of res variable if it is not printed below?
I guess this part was copied from find_memory_holes which doesn’t print out res, anyway you are right, we should print it.
Quoted 31 lines
Quoted 31 lines
xen/arch/arm/static-shmem.c +30
-0+ { +printk (XENLOG_ERR "Failed to remove: %#" PRIpaddr"->%#" PRIpaddr"\n" , + start, end); +return -EINVAL ; + } + } + +return 0 ; +} + +int __init remove_shm_holes_for_domU (const struct kernel_info *kinfo, +struct membanks *ext_regions) +{ +const struct membanks *shm_mem = &kinfo->shm_mem.common; +struct rangeset *guest_holes; +unsigned int i; +paddr_t start; +paddr_t end; +int res; + +/* No static shared memory region. */ +if ( shm_mem->nr_banks ==0 ) +return 0 ; + +dt_dprintk ("Remove static shared memory holes for extended regions of DomU\n" ); + + guest_holes =rangeset_new (NULL ,NULL ,0 ); +if ( !guest_holes ) +return -ENOMEM ; +
Quoted 8 lines
xen/arch/arm/static-shmem.c void __init init_sharedmem_pages(void) · line 620
Quoted 7 lines
xen/arch/arm/static-shmem.c +7
-0+/* Copy extended regions sets into the rangeset */ +for ( i =0 ; i < ext_regions->nr_banks; i++ ) + { + start = ext_regions->bank[i].start; + end = start + ext_regions->bank[i].size -1 ; + + res =rangeset_add_range (guest_holes, start, end);Ditto,
PFN_DOWN().
Thanks for the review, I will fix the issues in the next push, I’ll just wait for the serie to be fully reviewed, or if you don’t want to check the remaining two patches before I fix the previous comments, just let me know.
Quoted 2 lines
~Michal
PATCH 10/11 xen/arm: fix duplicate /reserved-memory node in Dom0
In reply to Luca FancelluFrom: Penny Zheng <[email protected]>
In case there is a /reserved-memory node already present in the host dtb, current Xen codes would create yet another /reserved-memory node when the static shared memory feature is enabled and static shared memory region are present, this would result in an incorrect device tree generation and guest would not be able to detect the static shared memory region.
Avoid this issue checking the presence of the /reserved-memory node and appending the nodes instead of generating a duplicate /reserved-memory.
---
v1:
- Rework of https://patchwork.kernel.org/project/xen-devel/patch/[email protected]/
--- xen/arch/arm/domain_build.c | 23 ++++++++++++++++++++--- xen/arch/arm/include/asm/static-shmem.h | 11 +++++++++++ xen/arch/arm/static-shmem.c | 12 +++++++----- 3 files changed, 38 insertions(+), 8 deletions(-)
xen/arch/arm/domain_build.c +20 -3
@@ -1620,6 +1620,7 @@ static int __init handle_node(struct domain *d, struct kernel_info *kinfo, DT_MATCH_PATH("/hypervisor"), { /* sentinel */ }, }; +static __initdata bool res_mem_node_found = false;struct dt_device_node *child;int res, i, nirq, irq_id;const char *name;
@@ -1714,6 +1715,19 @@ static int __init handle_node(struct domain *d, struct kernel_info *kinfo,if ( res )return res; +if (dt_node_path_is_equal (node,"/reserved-memory" ) ) + { + res_mem_node_found = true; +/* +* Avoid duplicate /reserved-memory nodes in Device Tree, so list the +* static shared memory nodes there. +*/ + res =make_shm_memory_node (d, kinfo,dt_n_addr_cells (node), +dt_n_size_cells (node)); +if ( res ) +return res; + } +for ( child = node->child; child !=NULL ; child = child->sibling ) { res =handle_node (d, kinfo, child, p2mt);
@@ -1766,9 +1780,12 @@ static int __init handle_node(struct domain *d, struct kernel_info *kinfo,return res; } - res =make_resv_memory_node (d, kinfo, addrcells, sizecells); -if ( res ) -return res; +if ( !res_mem_node_found ) + { + res =make_resv_memory_node (d, kinfo, addrcells, sizecells); +if ( res ) +return res; + } } res =fdt_end_node (kinfo->fdt);
xen/arch/arm/include/asm/static-shmem.h +11 -0
@@ -35,6 +35,10 @@ int remove_shm_from_rangeset(const struct kernel_info *kinfo,int remove_shm_holes_for_domU (const struct kernel_info *kinfo,struct membanks *ext_regions); +int make_shm_memory_node (const struct domain *d, +const struct kernel_info *kinfo,int addrcells, +int sizecells); +#else /* !CONFIG_STATIC_SHM */ static inline int make_resv_memory_node(const struct domain *d,
@@ -79,6 +83,13 @@ static inline int remove_shm_holes_for_domU(const struct kernel_info *kinfo,return 0 ; } +static inline int make_shm_memory_node (const struct domain *d, +const struct kernel_info *kinfo, +int addrcells,int sizecells) +{ +return 0 ; +} +#endif /* CONFIG_STATIC_SHM */ #endif /* __ASM_STATIC_SHMEM_H_ */
xen/arch/arm/static-shmem.c +7 -5
@@ -287,15 +287,17 @@ int __init process_shm(struct domain *d, struct kernel_info *kinfo,return 0 ; } -static int __init make_shm_memory_node (const struct domain *d,void *fdt, -int addrcells,int sizecells, -const struct membanks *mem) +int __init make_shm_memory_node (const struct domain *d, +const struct kernel_info *kinfo,int addrcells, +int sizecells) { +const struct membanks *mem = &kinfo->shm_mem.common; +void *fdt = kinfo->fdt;unsigned int i =0 ;int res =0 ;if ( mem->nr_banks ==0 ) -return -ENOENT ; +return 0 ;/* * For each shared memory region, a range is exposed under
@@ -534,7 +536,7 @@ int __init make_resv_memory_node(const struct domain *d,if ( res )return res; - res =make_shm_memory_node (d, fdt, addrcells, sizecells, mem); + res =make_shm_memory_node (d, kinfo, addrcells, sizecells);if ( res )return res;
Signature · 1 line
2.34.1
Re: [PATCH 10/11] xen/arm: fix duplicate /reserved-memory node in Dom0
Hi Luca,
Quoted 8 lines · Luca Fancellu
From: Penny Zheng <[email protected]>
In case there is a /reserved-memory node already present in the host dtb, current Xen codes would create yet another /reserved-memory node when the static shared memory feature is enabled and static shared memory region are present, this would result in an incorrect device tree
s/region/regions, please add full stop after present.
Quoted 1 line
generation and guest would not be able to detect the static shared memory
s/guest/hwdom to make it clear when the issue can be observed
Quoted 3 lines
region.
Avoid this issue checking the presence of the /reserved-memory node and
by checking
Quoted 26 lines
appending the nodes instead of generating a duplicate /reserved-memory.
Signed-off-by Penny Zheng <[email protected]>Signed-off-by Luca Fancellu <[email protected]>---
v1:
- Rework of https://patchwork.kernel.org/project/xen-devel/patch/[email protected]/--- xen/arch/arm/domain_build.c | 23 ++++++++++++++++++++--- xen/arch/arm/include/asm/static-shmem.h | 11 +++++++++++ xen/arch/arm/static-shmem.c | 12 +++++++----- 3 files changed, 38 insertions(+), 8 deletions(-)xen/arch/arm/domain_build.c +1
-0@@ -1620,6 +1620,7 @@ static int __init handle_node(struct domain *d, struct kernel_info *kinfo, DT_MATCH_PATH("/hypervisor"), { /* sentinel */ }, }; +static __initdata bool res_mem_node_found = false;struct dt_device_node *child;int res, i, nirq, irq_id;const char *name;
xen/arch/arm/domain_build.c static int __init handle_node(struct domain *d, struct kernel_info *kinfo, · line 1722
Quoted 8 lines
xen/arch/arm/domain_build.c +5
-0@@ -1714,6 +1715,19 @@ static int __init handle_node(struct domain *d, struct kernel_info *kinfo,if ( res )return res; +if (dt_node_path_is_equal (node,"/reserved-memory" ) ) + { + res_mem_node_found = true; +/* +* Avoid duplicate /reserved-memory nodes in Device Tree, so list the
s/list/add
Quoted 61 lines
xen/arch/arm/domain_build.c +14
-3+* static shared memory nodes there. +*/ + res =make_shm_memory_node (d, kinfo,dt_n_addr_cells (node), +dt_n_size_cells (node)); +if ( res ) +return res; + } +for ( child = node->child; child !=NULL ; child = child->sibling ) { res =handle_node (d, kinfo, child, p2mt);@@ -1766,9 +1780,12 @@ static int __init handle_node(struct domain *d, struct kernel_info *kinfo,return res; } - res =make_resv_memory_node (d, kinfo, addrcells, sizecells); -if ( res ) -return res; +if ( !res_mem_node_found ) + { + res =make_resv_memory_node (d, kinfo, addrcells, sizecells); +if ( res ) +return res; + } } res =fdt_end_node (kinfo->fdt);xen/arch/arm/include/asm/static-shmem.h +11
-0@@ -35,6 +35,10 @@ int remove_shm_from_rangeset(const struct kernel_info *kinfo,int remove_shm_holes_for_domU (const struct kernel_info *kinfo,struct membanks *ext_regions); +int make_shm_memory_node (const struct domain *d, +const struct kernel_info *kinfo,int addrcells, +int sizecells); +#else /* !CONFIG_STATIC_SHM */ static inline int make_resv_memory_node(const struct domain *d,@@ -79,6 +83,13 @@ static inline int remove_shm_holes_for_domU(const struct kernel_info *kinfo,return 0 ; } +static inline int make_shm_memory_node (const struct domain *d, +const struct kernel_info *kinfo, +int addrcells,int sizecells) +{ +return 0 ; +} +#endif /* CONFIG_STATIC_SHM */ #endif /* __ASM_STATIC_SHMEM_H_ */ xen/arch/arm/static-shmem.c +0
-0
xen/arch/arm/static-shmem.c int __init process_shm(struct domain *d, struct kernel_info *kinfo, · line 292
Quoted 9 lines
xen/arch/arm/static-shmem.c +3
-3@@ -287,15 +287,17 @@ int __init process_shm(struct domain *d, struct kernel_info *kinfo,return 0 ; } -static int __init make_shm_memory_node (const struct domain *d,void *fdt, -int addrcells,int sizecells, -const struct membanks *mem) +int __init make_shm_memory_node (const struct domain *d, +const struct kernel_info *kinfo,int addrcells, +int sizecells)
Strictly speaking, changing the function signature is not mandatory for this change, so I would at least mention it in the commit msg.
Other than that:
~Michal
PATCH 11/11 xen/arm: List static shared memory regions as /memory nodes
In reply to Luca FancelluCurrently Xen is not exporting the static shared memory regions to the device tree as /memory node, this commit is fixing this issue.
--- xen/arch/arm/dom0less-build.c | 5 +++ xen/arch/arm/domain_build.c | 7 +++- xen/arch/arm/include/asm/static-shmem.h | 5 ++- xen/arch/arm/static-shmem.c | 54 +++++++++++++++---------- 4 files changed, 47 insertions(+), 24 deletions(-)
xen/arch/arm/dom0less-build.c +5 -0
@@ -647,6 +647,11 @@ static int __init prepare_dtb_domU(struct domain *d, struct kernel_info *kinfo)if ( ret ) goto err; +/* List static shared memory regions as /memory@<address> nodes */ + ret =make_shm_memory_node (d, kinfo, addrcells, sizecells, false); +if ( ret ) +return ret; + ret =make_resv_memory_node (d, kinfo, addrcells, sizecells);if ( ret ) goto err;
xen/arch/arm/domain_build.c +6 -1
@@ -1723,7 +1723,7 @@ static int __init handle_node(struct domain *d, struct kernel_info *kinfo,* static shared memory nodes there. */ res =make_shm_memory_node (d, kinfo,dt_n_addr_cells (node), -dt_n_size_cells (node)); +dt_n_size_cells (node), true);if ( res )return res; }
@@ -1780,6 +1780,11 @@ static int __init handle_node(struct domain *d, struct kernel_info *kinfo,return res; } +/* List static shared memory regions as /memory@<address> nodes */ + res =make_shm_memory_node (d, kinfo, addrcells, sizecells, false); +if ( res ) +return res; +if ( !res_mem_node_found ) { res =make_resv_memory_node (d, kinfo, addrcells, sizecells);
xen/arch/arm/include/asm/static-shmem.h +3 -2
@@ -37,7 +37,7 @@ int remove_shm_holes_for_domU(const struct kernel_info *kinfo,int make_shm_memory_node (const struct domain *d,const struct kernel_info *kinfo,int addrcells, -int sizecells); +int sizecells,bool is_resv_mem_node);#else /* !CONFIG_STATIC_SHM */
@@ -85,7 +85,8 @@ static inline int remove_shm_holes_for_domU(const struct kernel_info *kinfo,static inline int make_shm_memory_node (const struct domain *d,const struct kernel_info *kinfo, -int addrcells,int sizecells) +int addrcells,int sizecells, +bool is_resv_mem_node) {return 0 ; }
xen/arch/arm/static-shmem.c +33 -21
89 lines not on this page · raw message
Signature · 1 line
2.34.1
Re: [PATCH 11/11] xen/arm: List static shared memory regions as /memory nodes
Hi Luca,
Quoted 5 lines · Luca Fancellu
Currently Xen is not exporting the static shared memory regions to the device tree as /memory node, this commit is fixing this issue.
Looking at the implementation, you will always call make_shm_memory_node() twice. For the first time, to create /memory node and for the second time to create entry under /reserved-memory. Also, you will create a separate /memory node for every single shmem region instead of combining them in a single /memory region like make_memory_node() would do. Can't we reuse this function for simplicity?
Also, afaict it is not forbidden to specify shmem range (correct me if I'm wrong), where guest address will be within with RAM allocated by Xen (e.g. GPA RAM range 0x40000000 - 0x60000000 and shmem is at 0x50000000). In this case, you would create yet another /memory node that would result in overlap (i.e. more than one /memory node specifying the same range).
~Michal
Re: [PATCH 11/11] xen/arm: List static shared memory regions as /memory nodes
Quoted 6 lines · Michal Orzel
Hi Luca,
Hi Michal,
Quoted 10 lines · Luca Fancellu
Quoted 5 lines
Currently Xen is not exporting the static shared memory regions to the device tree as /memory node, this commit is fixing this issue.
Looking at the implementation, you will always call
make_shm_memory_node()twice. For the first time, to create /memory node and for the second time to create entry under /reserved-memory. Also, you will create a separate /memory node for every single shmem region instead of combining them in a single /memory region likemake_memory_node()would do. Can't we reuse this function for simplicity?
You mean using make_memory_node() to populate /reserved-memory and /memory? I feel they are very different In terms of properties to be created, so I don’t think we should create a make_memory_node() that does both.
Otherwise if you were suggesting to modify make_memory_node() only for what concerns the /memory nodes, it might be feasible, however there are some parts that need to be skipped with some flags (all the code accessing .type member), if I understand correctly you like this function because it doesn’t create one node for every bank, but it creates reg addresses instead, in that case I could modify the current make_shm_memory_node() to do the same.
Quoted 4 lines
Also, afaict it is not forbidden to specify shmem range (correct me if I'm wrong), where guest address will be within with RAM allocated by Xen (e.g. GPA RAM range
0x40000000-0x60000000and shmem is at0x50000000). In this case, you would create yet another /memory node that would result in overlap (i.e. more than one /memory node specifying the same range).
This is a good point I didn’t think about, yes currently the code is creating overlapping nodes in that case, wow so it means I need to compute the non overlapping regions and emit a /memory node then! :) ouch
Please let me know if I understood correctly your comments.
Cheers,
Luca
Quoted 2 lines
~Michal
Re: [PATCH 11/11] xen/arm: List static shared memory regions as /memory nodes
Hi Luca,
Quoted 20 lines · Luca Fancellu
Quoted 6 lines · Michal Orzel
Hi Luca,
Hi Michal,
Quoted 10 lines · Luca Fancellu
Quoted 5 lines
Currently Xen is not exporting the static shared memory regions to the device tree as /memory node, this commit is fixing this issue.
Looking at the implementation, you will always call
make_shm_memory_node()twice. For the first time, to create /memory node and for the second time to create entry under /reserved-memory. Also, you will create a separate /memory node for every single shmem region instead of combining them in a single /memory region likemake_memory_node()would do. Can't we reuse this function for simplicity?
Quoted 4 lines
You mean using
make_memory_node()to populate /reserved-memory and /memory? I feel they are very different In terms of properties to be created, so I don’t think we should create amake_memory_node()that does both.Otherwise if you were suggesting to modify
make_memory_node()only for what concerns the /memory nodes,
yes, this is what I meant
Quoted 3 lines
it might be feasible, however there are some parts that need to be skipped with some flags (all the code accessing .type member), if I understand correctly you like this function because it doesn’t create one node for every bank, but it creates reg addresses instead, in that case I could modify the current
make_shm_memory_node()to do the same.
My concern is that we will have 2 functions to create memory nodes instead of one that can be reused. I know the issue is with .type member. If skipping results in a worse code, then I'm ok with make_shm_memory_node() used for 2 purposes (would it be possible to create /memory and entry under /reserved in the same call to a function?).
Quoted 6 lines
Quoted 5 lines
Also, afaict it is not forbidden to specify shmem range (correct me if I'm wrong), where guest address will be within with RAM allocated by Xen (e.g. GPA RAM range
0x40000000-0x60000000and shmem is at0x50000000). In this case, you would create yet another /memory node that would result in overlap (i.e. more than one /memory node specifying the same range).
Quoted 11 lines
This is a good point I didn’t think about, yes currently the code is creating overlapping nodes in that case, wow so it means I need to compute the non overlapping regions and emit a /memory node then! :) ouch
Please let me know if I understood correctly your comments.
Cheers,
LucaQuoted 2 lines
~Michal
~Michal