Pre-requisite fixes for supporting 32 bit physical address
v6 cover Pre-requisite fixes for supporting 32 bit physical address
Hi All,
These series include some patches and fixes identified during the review of "[XEN v2 00/11] Add support for 32 bit physical address" and "[XEN v3 0/9] Add support for 32 bit physical address".
Patch 1/2 : This has been reviewed and ack-ed. It needs to be committed before any of the "[XEN v3 0/9]" patches are applied.
Patch 2/2 : This addresses an issue identified during the review of
"[XEN v3 4/9] xen/arm: Introduce a wrapper for dt_device_get_address() to handle paddr_t".
Ayan Kumar Halder (2):
xen/arm: Use the correct format specifier xen/arm: domain_build: Use pfn start and end address for
rangeset_{xxx}_range()xen/arch/arm/domain_build.c | 86 +++++++++++++++++++++++-------------- xen/arch/arm/gic-v2.c | 6 +-- xen/arch/arm/mm.c | 2 +- 3 files changed, 57 insertions(+), 37 deletions(-)
Signature · 1 line
2.17.1
PATCH v6 1/2 xen/arm: Use the correct format specifier
1. One should use 'PRIpaddr' to display 'paddr_t' variables. However, while creating nodes in fdt, the address (if present in the node name) should be represented using 'PRIx64'. This is to be in conformance with the following rule present in https://elinux.org/Device_Tree_Linux
. node names
"unit-address does not have leading zeros"
As 'PRIpaddr' introduces leading zeros, we cannot use it.
So, we have introduced a wrapper ie domain_fdt_begin_node() which will represent physical address using 'PRIx64'.
2. One should use 'PRIx64' to display 'u64' in hex format. The current use of 'PRIpaddr' for printing PTE is buggy as this is not a physical address.
---
Changes from -
v1 - 1. Moved the patch earlier.
2. Moved a part of change from "[XEN v1 8/9] xen/arm: Other adaptations required to support 32bit paddr" into this patch.
v2 - 1. Use PRIx64 for appending addresses to fdt node names. This fixes the CI failure.
v3 - 1. Added a comment on top of domain_fdt_begin_node().
2. Check for the return of snprintf() in domain_fdt_begin_node().
v4 - 1. Grammatical error fixes.
v5 - 1. Added R-b and A-b.
xen/arch/arm/domain_build.c | 64 +++++++++++++++++++++++-------------- xen/arch/arm/gic-v2.c | 6 ++-- xen/arch/arm/mm.c | 2 +- 3 files changed, 44 insertions(+), 28 deletions(-)
xen/arch/arm/domain_build.c +40 -24
@@ -1288,6 +1288,39 @@ static int __init fdt_property_interrupts(const struct kernel_info *kinfo,return res; } +/* +* Wrapper to convert physical address from paddr_t to uint64_t and +* invoke fdt_begin_node(). This is required as the physical address +* provided as part of node name should not contain any leading +* zeroes. Thus, one should use PRIx64 (instead of PRIpaddr) to append +* unit (which contains the physical address) with name to generate a +* node name. +*/ +static int __init domain_fdt_begin_node (void *fdt,const char *name, +uint64_t unit) +{ +/* +* The size of the buffer to hold the longest possible string (i.e. +* interrupt-controller@ + a 64-bit number + \0). +*/ +char buf[38 ]; +int ret; + +/* ePAPR 3.4 */ + ret =snprintf (buf,sizeof (buf),"%s@%" PRIx64, name, unit); + +if ( ret >=sizeof (buf) ) + { +printk (XENLOG_ERR +"Insufficient buffer. Minimum size required is %d\n" , + (ret +1 )); + +return -FDT_ERR_TRUNCATED ; + } + +return fdt_begin_node (fdt, buf); +} + static int __init make_memory_node(const struct domain *d, void *fdt, int addrcells, int sizecells,
@@ -1296,8 +1329,6 @@ static int __init make_memory_node(const struct domain *d,unsigned int i;int res, reg_size = addrcells + sizecells;int nr_cells =0 ; -/* Placeholder for memory@ + a 64-bit number + \0 */ -char buf[24 ];__be32 reg[NR_MEM_BANKS *4 /* Worst case addrcells + sizecells */ ];__be32 *cells;
@@ -1314,9 +1345,7 @@ static int __init make_memory_node(const struct domain *d,dt_dprintk ("Create memory node\n" ); -/* ePAPR 3.4 */ -snprintf (buf,sizeof (buf),"memory@%" PRIx64, mem->bank[i].start); - res =fdt_begin_node (fdt, buf); + res =domain_fdt_begin_node (fdt,"memory" , mem->bank[i].start);if ( res )return res;
@@ -1375,16 +1404,13 @@ static int __init make_shm_memory_node(const struct domain *d, {uint64_t start = mem->bank[i].start;uint64_t size = mem->bank[i].size; -/* Placeholder for xen-shmem@ + a 64-bit number + \0 */ -char buf[27 ];const char compat[] ="xen,shared-memory-v1" ;/* Worst case addrcells + sizecells */ __be32 reg[GUEST_ROOT_ADDRESS_CELLS +GUEST_ROOT_SIZE_CELLS ];__be32 *cells;unsigned int len = (addrcells + sizecells) *sizeof (__be32); -snprintf (buf,sizeof (buf),"xen-shmem@%" PRIx64, mem->bank[i].start); - res =fdt_begin_node (fdt, buf); + res =domain_fdt_begin_node (fdt,"xen-shmem" , mem->bank[i].start);if ( res )return res;
@@ -2716,12 +2742,9 @@ static int __init make_gicv2_domU_node(struct kernel_info *kinfo)__be32 reg[(GUEST_ROOT_ADDRESS_CELLS +GUEST_ROOT_SIZE_CELLS ) *2 ];__be32 *cells;const struct domain *d = kinfo->d; -/* Placeholder for interrupt-controller@ + a 64-bit number + \0 */ -char buf[38 ]; -snprintf (buf,sizeof (buf),"interrupt-controller@%" PRIx64, -vgic_dist_base (&d->arch.vgic)); - res =fdt_begin_node (fdt, buf); + res =domain_fdt_begin_node (fdt,"interrupt-controller" , +vgic_dist_base (&d->arch.vgic));if ( res )return res;
@@ -2771,14 +2794,10 @@ static int __init make_gicv3_domU_node(struct kernel_info *kinfo)int res =0 ;__be32 *reg, *cells;const struct domain *d = kinfo->d; -/* Placeholder for interrupt-controller@ + a 64-bit number + \0 */ -char buf[38 ];unsigned int i, len =0 ; -snprintf (buf,sizeof (buf),"interrupt-controller@%" PRIx64, -vgic_dist_base (&d->arch.vgic)); - - res =fdt_begin_node (fdt, buf); + res =domain_fdt_begin_node (fdt,"interrupt-controller" , +vgic_dist_base (&d->arch.vgic));if ( res )return res;
@@ -2858,11 +2877,8 @@ static int __init make_vpl011_uart_node(struct kernel_info *kinfo)__be32 reg[GUEST_ROOT_ADDRESS_CELLS +GUEST_ROOT_SIZE_CELLS ];__be32 *cells;struct domain *d = kinfo->d; -/* Placeholder for sbsa-uart@ + a 64-bit number + \0 */ -char buf[27 ]; -snprintf (buf,sizeof (buf),"sbsa-uart@%" PRIx64, d->arch.vpl011.base_addr); - res =fdt_begin_node (fdt, buf); + res =domain_fdt_begin_node (fdt,"sbsa-uart" , d->arch.vpl011.base_addr);if ( res )return res;
xen/arch/arm/gic-v2.c +3 -3
@@ -1049,7 +1049,7 @@ static void __init gicv2_dt_init(void)if ( csize <SZ_8K ) {printk (XENLOG_WARNING "GICv2: WARNING: " -"The GICC size is too small: %#" PRIx64" expected %#x\n" , +"The GICC size is too small: %#" PRIpaddr" expected %#x\n" , csize,SZ_8K );if (platform_has_quirk (PLATFORM_QUIRK_GIC_64K_STRIDE ) ) {
@@ -1280,11 +1280,11 @@ static int __init gicv2_init(void) gicv2.map_cbase += aliased_offset;printk (XENLOG_WARNING -"GICv2: Adjusting CPU interface base to %#" PRIx64"\n" , +"GICv2: Adjusting CPU interface base to %#" PRIpaddr"\n" , cbase + aliased_offset); }else if ( csize ==SZ_128K )printk (XENLOG_WARNING -"GICv2: GICC size=%#" PRIx64" but not aliased\n" , +"GICv2: GICC size=%#" PRIpaddr" but not aliased\n" , csize); gicv2.map_hbase =ioremap_nocache (hbase,PAGE_SIZE );
xen/arch/arm/mm.c +1 -1
@@ -263,7 +263,7 @@ void dump_pt_walk(paddr_t ttbr, paddr_t addr, pte = mapping[offsets[level]]; -printk ("%s[0x%03x] = 0x%" PRIpaddr"\n" , +printk ("%s[0x%03x] = 0x%" PRIx64"\n" , level_strs[level], offsets[level], pte.bits);if ( level ==3 || !pte.walk.valid || !pte.walk.table )
Signature · 1 line
2.17.1
PATCH v6 2/2 xen/arm: domain_build: Use pfn start and end address for rangeset_{xxx}_range()
In reply to Ayan Kumar Halderrangeset_{xxx}_range() functions are invoked with 'start' and 'size' as arguments which are either 'uint64_t' or 'paddr_t'. However, the function accepts 'unsigned long' for 'start' and 'size'. 'unsigned long' is 32 bits for ARM_32. Thus, there is an implicit downcasting from 'uint64_t'/'paddr_t' to 'unsigned long' when invoking rangeset_{xxx}_range().
However, it may seem there is a possibility of lose of data due to truncation.
In reality, 'start' and 'size' are always page aligned. And ARM_32 currently supports 40 bits as the width of physical address.
So if the addresses are page aligned, the last 12 bits contain zeroes. Thus, we could instead pass page frame number which will contain 28 bits (40-12 on Arm_32) and this can be represented using 'unsigned long'.
On Arm_64, this change will not induce any adverse side effect as the width of physical address is 48 bits. Thus, the width of 'pfn' (ie 48 - 12 = 36) can be represented using 'unsigned long' (which is 64 bits wide).
---
Changes from -
v1 - v5 - NA (New patch introduced in v6).
xen/arch/arm/domain_build.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-)
xen/arch/arm/domain_build.c +13 -9
@@ -1566,7 +1566,8 @@ static int __init find_unallocated_memory(const struct kernel_info *kinfo, { start = bootinfo.mem.bank[i].start; end = bootinfo.mem.bank[i].start + bootinfo.mem.bank[i].size; - res =rangeset_add_range (unalloc_mem, start, end -1 ); + res =rangeset_add_range (unalloc_mem,PFN_DOWN (start), +PFN_DOWN (end -1 ));if ( res ) { printk(XENLOG_ERR "Failed to add: %#"PRIpaddr"->%#"PRIpaddr"\n",
@@ -1580,7 +1581,8 @@ static int __init find_unallocated_memory(const struct kernel_info *kinfo, { start = assign_mem->bank[i].start; end = assign_mem->bank[i].start + assign_mem->bank[i].size; - res =rangeset_remove_range (unalloc_mem, start, end -1 ); + res =rangeset_remove_range (unalloc_mem,PFN_DOWN (start), +PFN_DOWN (end -1 ));if ( res ) { printk(XENLOG_ERR "Failed to remove: %#"PRIpaddr"->%#"PRIpaddr"\n",
@@ -1595,7 +1597,8 @@ static int __init find_unallocated_memory(const struct kernel_info *kinfo, start = bootinfo.reserved_mem.bank[i].start; end = bootinfo.reserved_mem.bank[i].start + bootinfo.reserved_mem.bank[i].size; - res =rangeset_remove_range (unalloc_mem, start, end -1 ); + res =rangeset_remove_range (unalloc_mem,PFN_DOWN (start), +PFN_DOWN (end -1 ));if ( res ) { printk(XENLOG_ERR "Failed to remove: %#"PRIpaddr"->%#"PRIpaddr"\n",
@@ -1607,7 +1610,7 @@ static int __init find_unallocated_memory(const struct kernel_info *kinfo,/* Remove grant table region */ start = kinfo->gnttab_start; end = kinfo->gnttab_start + kinfo->gnttab_size; - res =rangeset_remove_range (unalloc_mem, start, end -1 ); + res =rangeset_remove_range (unalloc_mem,PFN_DOWN (start),PFN_DOWN (end -1 ));if ( res ) { printk(XENLOG_ERR "Failed to remove: %#"PRIpaddr"->%#"PRIpaddr"\n",
@@ -1617,7 +1620,7 @@ static int __init find_unallocated_memory(const struct kernel_info *kinfo, start =0 ; end = (1ULL << p2m_ipa_bits) -1 ; - res =rangeset_report_ranges (unalloc_mem, start, end, + res =rangeset_report_ranges (unalloc_mem,PFN_DOWN (start),PFN_DOWN (end), add_ext_regions, ext_regions);if ( res ) ext_regions->nr_banks =0 ;
@@ -1639,7 +1642,7 @@ static int __init handle_pci_range(const struct dt_device_node *dev, start = addr &PAGE_MASK ; end =PAGE_ALIGN (addr + len); - res =rangeset_remove_range (mem_holes, start, end -1 ); + res =rangeset_remove_range (mem_holes,PFN_DOWN (start),PFN_DOWN (end -1 ));if ( res ) { printk(XENLOG_ERR "Failed to remove: %#"PRIpaddr"->%#"PRIpaddr"\n",
@@ -1677,7 +1680,7 @@ static int __init find_memory_holes(const struct kernel_info *kinfo,/* Start with maximum possible addressable physical memory range */ start =0 ; end = (1ULL << p2m_ipa_bits) -1 ; - res =rangeset_add_range (mem_holes, start, end); + res =rangeset_add_range (mem_holes,PFN_DOWN (start),PFN_DOWN (end));if ( res ) { printk(XENLOG_ERR "Failed to add: %#"PRIpaddr"->%#"PRIpaddr"\n",
@@ -1708,7 +1711,8 @@ static int __init find_memory_holes(const struct kernel_info *kinfo, start = addr &PAGE_MASK ; end =PAGE_ALIGN (addr + size); - res =rangeset_remove_range (mem_holes, start, end -1 ); + res =rangeset_remove_range (mem_holes,PFN_DOWN (start), +PFN_DOWN (end -1 ));if ( res ) { printk(XENLOG_ERR "Failed to remove: %#"PRIpaddr"->%#"PRIpaddr"\n",
@@ -1735,7 +1739,7 @@ static int __init find_memory_holes(const struct kernel_info *kinfo, start =0 ; end = (1ULL << p2m_ipa_bits) -1 ; - res =rangeset_report_ranges (mem_holes, start, end, + res =rangeset_report_ranges (mem_holes,PFN_DOWN (start),PFN_DOWN (end), add_ext_regions, ext_regions);if ( res ) ext_regions->nr_banks =0 ;
Signature · 1 line
2.17.1
Re: [XEN v6 2/2] xen/arm: domain_build: Use pfn start and end address for rangeset_{xxx}_range()
Hi Ayan,
The title is a bit strange to read as a 'pfn' is not an address. So how about:
xen/arm: domain_build: Track unallocated pages using the frame number
Quoted 8 lines · Ayan Kumar Halder
rangeset_{xxx}_range() functions are invoked with 'start' and 'size' as arguments which are either '
uint64_t' or 'paddr_t'. However, the function accepts 'unsigned long' for 'start' and 'size'. 'unsigned long' is 32 bits forARM_32. Thus, there is an implicit downcasting from 'uint64_t'/'paddr_t' to 'unsigned long' when invoking rangeset_{xxx}_range().However, it may seem there is a possibility of lose of data due to truncation.
Quoted 8 lines
In reality, 'start' and 'size' are always page aligned. And
ARM_32currently supports 40 bits as the width of physical address.
So if the addresses are page aligned, the last 12 bits contain zeroes. Thus, we could instead pass page frame number which will contain 28 bits (40-12 onArm_32) and this can be represented using 'unsigned long'.On
Arm_64, this change will not induce any adverse side effect as the width of physical address is 48 bits. Thus, the width of 'pfn' (ie 48 - 12 = 36) can be
Technically, this will an MFN rather than PFN (Yes, I now the macro is called PFN_DOWN() but this is a generic name).
Quoted 56 lines
represented using 'unsigned long' (which is 64 bits wide).
Signed-off-by Ayan Kumar Halder <[email protected]>---
Changes from -
v1 - v5 - NA (New patch introduced in v6).
xen/arch/arm/domain_build.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-)xen/arch/arm/domain_build.c +7
-4@@ -1566,7 +1566,8 @@ static int __init find_unallocated_memory(const struct kernel_info *kinfo, { start = bootinfo.mem.bank[i].start; end = bootinfo.mem.bank[i].start + bootinfo.mem.bank[i].size; - res =rangeset_add_range (unalloc_mem, start, end -1 ); + res =rangeset_add_range (unalloc_mem,PFN_DOWN (start), +PFN_DOWN (end -1 ));if ( res ) { printk(XENLOG_ERR "Failed to add: %#"PRIpaddr"->%#"PRIpaddr"\n",@@ -1580,7 +1581,8 @@ static int __init find_unallocated_memory(const struct kernel_info *kinfo, { start = assign_mem->bank[i].start; end = assign_mem->bank[i].start + assign_mem->bank[i].size; - res =rangeset_remove_range (unalloc_mem, start, end -1 ); + res =rangeset_remove_range (unalloc_mem,PFN_DOWN (start), +PFN_DOWN (end -1 ));if ( res ) { printk(XENLOG_ERR "Failed to remove: %#"PRIpaddr"->%#"PRIpaddr"\n",@@ -1595,7 +1597,8 @@ static int __init find_unallocated_memory(const struct kernel_info *kinfo, start = bootinfo.reserved_mem.bank[i].start; end = bootinfo.reserved_mem.bank[i].start + bootinfo.reserved_mem.bank[i].size; - res =rangeset_remove_range (unalloc_mem, start, end -1 ); + res =rangeset_remove_range (unalloc_mem,PFN_DOWN (start), +PFN_DOWN (end -1 ));if ( res ) { printk(XENLOG_ERR "Failed to remove: %#"PRIpaddr"->%#"PRIpaddr"\n",@@ -1607,7 +1610,7 @@ static int __init find_unallocated_memory(const struct kernel_info *kinfo,/* Remove grant table region */ start = kinfo->gnttab_start; end = kinfo->gnttab_start + kinfo->gnttab_size; - res =rangeset_remove_range (unalloc_mem, start, end -1 ); + res =rangeset_remove_range (unalloc_mem,PFN_DOWN (start),PFN_DOWN (end -1 ));if ( res ) { printk(XENLOG_ERR "Failed to remove: %#"PRIpaddr"->%#"PRIpaddr"\n",
xen/arch/arm/domain_build.c static int __init find_unallocated_memory(const struct kernel_info *kinfo, · line 1624
Quoted 6 lines
xen/arch/arm/domain_build.c +1
-1@@ -1617,7 +1620,7 @@ static int __init find_unallocated_memory(const struct kernel_info *kinfo, start =0 ; end = (1ULL << p2m_ipa_bits) -1 ; - res =rangeset_report_ranges (unalloc_mem, start, end, + res =rangeset_report_ranges (unalloc_mem,PFN_DOWN (start),PFN_DOWN (end), add_ext_regions, ext_regions);
I believe you also need to modify add_ext_regions() because the existing code expect an address and we will now provide a frame number.
xen/arch/arm/domain_build.c static int __init handle_pci_range(const struct dt_device_node *dev, · line 1645
Quoted 8 lines
xen/arch/arm/domain_build.c +1
-1if ( res ) ext_regions->nr_banks =0 ;@@ -1639,7 +1642,7 @@ static int __init handle_pci_range(const struct dt_device_node *dev, start = addr &PAGE_MASK ; end =PAGE_ALIGN (addr + len); - res =rangeset_remove_range (mem_holes, start, end -1 ); + res =rangeset_remove_range (mem_holes,PFN_DOWN (start),PFN_DOWN (end -1 ));
Coding style: missing space after ","
Quoted 23 lines
xen/arch/arm/domain_build.c +3
-2if ( res ) { printk(XENLOG_ERR "Failed to remove: %#"PRIpaddr"->%#"PRIpaddr"\n",@@ -1677,7 +1680,7 @@ static int __init find_memory_holes(const struct kernel_info *kinfo,/* Start with maximum possible addressable physical memory range */ start =0 ; end = (1ULL << p2m_ipa_bits) -1 ; - res =rangeset_add_range (mem_holes, start, end); + res =rangeset_add_range (mem_holes,PFN_DOWN (start),PFN_DOWN (end));if ( res ) { printk(XENLOG_ERR "Failed to add: %#"PRIpaddr"->%#"PRIpaddr"\n",@@ -1708,7 +1711,8 @@ static int __init find_memory_holes(const struct kernel_info *kinfo, start = addr &PAGE_MASK ; end =PAGE_ALIGN (addr + size); - res =rangeset_remove_range (mem_holes, start, end -1 ); + res =rangeset_remove_range (mem_holes,PFN_DOWN (start), +PFN_DOWN (end -1 ));if ( res ) { printk(XENLOG_ERR "Failed to remove: %#"PRIpaddr"->%#"PRIpaddr"\n",
xen/arch/arm/domain_build.c static int __init find_memory_holes(const struct kernel_info *kinfo, · line 1744
Quoted 7 lines
xen/arch/arm/domain_build.c +1
-1@@ -1735,7 +1739,7 @@ static int __init find_memory_holes(const struct kernel_info *kinfo, start =0 ; end = (1ULL << p2m_ipa_bits) -1 ; - res =rangeset_report_ranges (mem_holes, start, end, + res =rangeset_report_ranges (mem_holes,PFN_DOWN (start),PFN_DOWN (end), add_ext_regions, ext_regions); > if ( res ) ext_regions->nr_banks =0 ;
Cheers,
Signature · 1 line
Julien Grall