hw/arm/virt: Improve address assignment for high memory regions
v3 cover hw/arm/virt: Improve address assignment for high memory regions
There are three high memory regions, which are VIRT_HIGH_REDIST2, VIRT_HIGH_PCIE_ECAM and VIRT_HIGH_PCIE_MMIO. Their base addresses are floating on highest RAM address. However, they can be disabled in several cases.
(1) One specific high memory region is disabled by developer by
toggling vms->highmem_{redists, ecam, mmio}.(2) VIRT_HIGH_PCIE_ECAM region is disabled on machine, which is
'virt-2.12' or ealier than it.
(3) VIRT_HIGH_PCIE_ECAM region is disabled when firmware is loaded on 32-bits system.
(4) One specific high memory region is disabled when it breaks the PA space limit.
The current implementation of virt_set_memmap() isn't comprehensive because the space for one specific high memory region is always reserved from the PA space for case (1), (2) and (3). In the code, 'base' and 'vms->highest_gpa' are always increased for those three cases. It's unnecessary since the assigned space of the disabled high memory region won't be used afterwards.
The series intends to improve the address assignment for these high memory regions.
PATCH[1-3] preparatory work for the improvment
PATCH[4] improve high memory region address assignment
PATCH[5] adds 'highmem-compact' to enable or disable the optimization
History
=======
v2: https://lore.kernel.org/all/[email protected]/T/
v1: https://lists.nongnu.org/archive/html/qemu-arm/2022-08/msg00013.html
Changelog
==========
v3:
* Reorder the patches (Gavin)
* Add 'highmem-compact' property for backwards compatibility (Eric)
v2:
* Split the patches for easier review (Gavin) * Improved changelog (Marc) * Use 'bool fits' in virt_set_high_memmap() (Eric)
Gavin Shan (5):
hw/arm/virt: Introduce virt_set_high_memmap() helper hw/arm/virt: Rename variable size to region_size in
virt_set_high_memmap()
hw/arm/virt: Introduce variable region_base in virt_set_high_memmap() hw/arm/virt: Improve high memory region address assignment hw/arm/virt: Add 'highmem-compact' property
docs/system/arm/virt.rst | 4 ++ hw/arm/virt.c | 116 ++++++++++++++++++++++++++++----------- include/hw/arm/virt.h | 2 + 3 files changed, 89 insertions(+), 33 deletions(-)
Signature · 1 line
2.23.0
PATCH v3 1/5 hw/arm/virt: Introduce virt_set_high_memmap() helper
This introduces virt_set_high_memmap() helper. The logic of high memory region address assignment is moved to the helper. The intention is to make the subsequent optimization for high memory region address assignment easier.
No functional change intended.
--- hw/arm/virt.c | 74 ++++++++++++++++++++++++++++----------------------- 1 file changed, 41 insertions(+), 33 deletions(-)
hw/arm/virt.c +41 -33
@@ -1689,6 +1689,46 @@ static uint64_t virt_cpu_mp_affinity(VirtMachineState *vms, int idx)return arm_cpu_mp_affinity (idx, clustersz); } +static void virt_set_high_memmap (VirtMachineState *vms, +hwaddr base,int pa_bits) +{ +int i; + +for (i =VIRT_LOWMEMMAP_LAST ; i <ARRAY_SIZE (extended_memmap); i++) { +hwaddr size = extended_memmap[i].size; +bool fits; + + base =ROUND_UP (base, size); + vms->memmap[i].base = base; + vms->memmap[i].size = size; + +/* +* Check each device to see if they fit in the PA space, +* moving highest_gpa as we go. +* +* For each device that doesn't fit, disable it. +*/ + fits = (base + size) <=BIT_ULL (pa_bits); +if (fits) { + vms->highest_gpa = base + size -1 ; + } + +switch (i) { +case VIRT_HIGH_GIC_REDIST2 : + vms->highmem_redists &= fits; +break ; +case VIRT_HIGH_PCIE_ECAM : + vms->highmem_ecam &= fits; +break ; +case VIRT_HIGH_PCIE_MMIO : + vms->highmem_mmio &= fits; +break ; + } + + base += size; + } +} +static void virt_set_memmap (VirtMachineState *vms,int pa_bits) {MachineState *ms =MACHINE (vms);
@@ -1744,39 +1784,7 @@ static void virt_set_memmap(VirtMachineState *vms, int pa_bits)/* We know for sure that at least the memory fits in the PA space */ vms->highest_gpa = memtop -1 ; -for (i =VIRT_LOWMEMMAP_LAST ; i <ARRAY_SIZE (extended_memmap); i++) { -hwaddr size = extended_memmap[i].size; -bool fits; - - base =ROUND_UP (base, size); - vms->memmap[i].base = base; - vms->memmap[i].size = size; - -/* -* Check each device to see if they fit in the PA space, -* moving highest_gpa as we go. -* -* For each device that doesn't fit, disable it. -*/ - fits = (base + size) <=BIT_ULL (pa_bits); -if (fits) { - vms->highest_gpa = base + size -1 ; - } - -switch (i) { -case VIRT_HIGH_GIC_REDIST2 : - vms->highmem_redists &= fits; -break ; -case VIRT_HIGH_PCIE_ECAM : - vms->highmem_ecam &= fits; -break ; -case VIRT_HIGH_PCIE_MMIO : - vms->highmem_mmio &= fits; -break ; - } - - base += size; - } +virt_set_high_memmap (vms, base, pa_bits);if (device_memory_size >0 ) { ms->device_memory =g_malloc0 (sizeof (*ms->device_memory));
Signature · 1 line
2.23.0
Re: [PATCH v3 1/5] hw/arm/virt: Introduce virt_set_high_memmap() helper
Hi Gavin,
Quoted 8 lines · Gavin Shan
This introduces
virt_set_high_memmap()helper. The logic of high memory region address assignment is moved to the helper. The intention is to make the subsequent optimization for high memory region address assignment easier.No functional change intended.
Signed-off-by Gavin Shan <[email protected]>
Thanks
Eric
Quoted 96 lines
--- hw/arm/virt.c | 74 ++++++++++++++++++++++++++++----------------------- 1 file changed, 41 insertions(+), 33 deletions(-)hw/arm/virt.c +41
-33@@ -1689,6 +1689,46 @@ static uint64_t virt_cpu_mp_affinity(VirtMachineState *vms, int idx)return arm_cpu_mp_affinity (idx, clustersz); } +static void virt_set_high_memmap (VirtMachineState *vms, +hwaddr base,int pa_bits) +{ +int i; + +for (i =VIRT_LOWMEMMAP_LAST ; i <ARRAY_SIZE (extended_memmap); i++) { +hwaddr size = extended_memmap[i].size; +bool fits; + + base =ROUND_UP (base, size); + vms->memmap[i].base = base; + vms->memmap[i].size = size; + +/* +* Check each device to see if they fit in the PA space, +* moving highest_gpa as we go. +* +* For each device that doesn't fit, disable it. +*/ + fits = (base + size) <=BIT_ULL (pa_bits); +if (fits) { + vms->highest_gpa = base + size -1 ; + } + +switch (i) { +case VIRT_HIGH_GIC_REDIST2 : + vms->highmem_redists &= fits; +break ; +case VIRT_HIGH_PCIE_ECAM : + vms->highmem_ecam &= fits; +break ; +case VIRT_HIGH_PCIE_MMIO : + vms->highmem_mmio &= fits; +break ; + } + + base += size; + } +} +static void virt_set_memmap (VirtMachineState *vms,int pa_bits) {MachineState *ms =MACHINE (vms);@@ -1744,39 +1784,7 @@ static void virt_set_memmap(VirtMachineState *vms, int pa_bits)/* We know for sure that at least the memory fits in the PA space */ vms->highest_gpa = memtop -1 ; -for (i =VIRT_LOWMEMMAP_LAST ; i <ARRAY_SIZE (extended_memmap); i++) { -hwaddr size = extended_memmap[i].size; -bool fits; - - base =ROUND_UP (base, size); - vms->memmap[i].base = base; - vms->memmap[i].size = size; - -/* -* Check each device to see if they fit in the PA space, -* moving highest_gpa as we go. -* -* For each device that doesn't fit, disable it. -*/ - fits = (base + size) <=BIT_ULL (pa_bits); -if (fits) { - vms->highest_gpa = base + size -1 ; - } - -switch (i) { -case VIRT_HIGH_GIC_REDIST2 : - vms->highmem_redists &= fits; -break ; -case VIRT_HIGH_PCIE_ECAM : - vms->highmem_ecam &= fits; -break ; -case VIRT_HIGH_PCIE_MMIO : - vms->highmem_mmio &= fits; -break ; - } - - base += size; - } +virt_set_high_memmap (vms, base, pa_bits);if (device_memory_size >0 ) { ms->device_memory =g_malloc0 (sizeof (*ms->device_memory));
Re: [PATCH v3 1/5] hw/arm/virt: Introduce virt_set_high_memmap() helper
In reply to Gavin ShanQuoted 11 lines · Gavin Shan
This introduces
virt_set_high_memmap()helper. The logic of high memory region address assignment is moved to the helper. The intention is to make the subsequent optimization for high memory region address assignment easier.No functional change intended.
Signed-off-by Gavin Shan <[email protected]>--- hw/arm/virt.c | 74 ++++++++++++++++++++++++++++----------------------- 1 file changed, 41 insertions(+), 33 deletions(-)
PATCH v3 2/5 hw/arm/virt: Rename variable size to region_size in virt_set_high_memmap()
In reply to Gavin ShanThis renames variable 'size' to 'region_size' in virt_set_high_memmap(). Its counterpart ('region_base') will be introduced in next patch.
No functional change intended.
--- hw/arm/virt.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-)
hw/arm/virt.c +8 -7
@@ -1692,15 +1692,16 @@ static uint64_t virt_cpu_mp_affinity(VirtMachineState *vms, int idx)static void virt_set_high_memmap (VirtMachineState *vms,hwaddr base,int pa_bits) { +hwaddr region_size; +bool fits;int i;for (i =VIRT_LOWMEMMAP_LAST ; i <ARRAY_SIZE (extended_memmap); i++) { -hwaddr size = extended_memmap[i].size; -bool fits; + region_size = extended_memmap[i].size; - base =ROUND_UP (base, size); + base =ROUND_UP (base, region_size); vms->memmap[i].base = base; - vms->memmap[i].size = size; + vms->memmap[i].size = region_size;/* * Check each device to see if they fit in the PA space,
@@ -1708,9 +1709,9 @@ static void virt_set_high_memmap(VirtMachineState *vms,* * For each device that doesn't fit, disable it. */ - fits = (base + size) <=BIT_ULL (pa_bits); + fits = (base + region_size) <=BIT_ULL (pa_bits);if (fits) { - vms->highest_gpa = base + size -1 ; + vms->highest_gpa = base + region_size -1 ; }switch (i) {
@@ -1725,7 +1726,7 @@ static void virt_set_high_memmap(VirtMachineState *vms,break ; } - base += size; + base += region_size; } }
Signature · 1 line
2.23.0
Re: [PATCH v3 2/5] hw/arm/virt: Rename variable size to region_size in virt_set_high_memmap()
Quoted 6 lines · Gavin Shan
This renames variable 'size' to '
region_size' invirt_set_high_memmap(). Its counterpart ('region_base') will be introduced in next patch.No functional change intended.
Signed-off-by Gavin Shan <[email protected]>
Eric
Quoted 50 lines
--- hw/arm/virt.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-)hw/arm/virt.c +8
-7@@ -1692,15 +1692,16 @@ static uint64_t virt_cpu_mp_affinity(VirtMachineState *vms, int idx)static void virt_set_high_memmap (VirtMachineState *vms,hwaddr base,int pa_bits) { +hwaddr region_size; +bool fits;int i;for (i =VIRT_LOWMEMMAP_LAST ; i <ARRAY_SIZE (extended_memmap); i++) { -hwaddr size = extended_memmap[i].size; -bool fits; + region_size = extended_memmap[i].size; - base =ROUND_UP (base, size); + base =ROUND_UP (base, region_size); vms->memmap[i].base = base; - vms->memmap[i].size = size; + vms->memmap[i].size = region_size;/* * Check each device to see if they fit in the PA space, @@ -1708,9 +1709,9 @@ static void virt_set_high_memmap(VirtMachineState *vms,* * For each device that doesn't fit, disable it. */ - fits = (base + size) <=BIT_ULL (pa_bits); + fits = (base + region_size) <=BIT_ULL (pa_bits);if (fits) { - vms->highest_gpa = base + size -1 ; + vms->highest_gpa = base + region_size -1 ; }switch (i) {@@ -1725,7 +1726,7 @@ static void virt_set_high_memmap(VirtMachineState *vms,break ; } - base += size; + base += region_size; } }
PATCH v3 3/5 hw/arm/virt: Introduce variable region_base in virt_set_high_memmap()
In reply to Gavin ShanThis introduces variable 'region_base' for the base address of the specific high memory region. It's the preparatory work to optimize high memory region address assignment.
No functional change intended.
--- hw/arm/virt.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
hw/arm/virt.c +6 -6
@@ -1692,15 +1692,15 @@ static uint64_t virt_cpu_mp_affinity(VirtMachineState *vms, int idx)static void virt_set_high_memmap (VirtMachineState *vms,hwaddr base,int pa_bits) { -hwaddr region_size; +hwaddr region_base, region_size;bool fits;int i;for (i =VIRT_LOWMEMMAP_LAST ; i <ARRAY_SIZE (extended_memmap); i++) { + region_base =ROUND_UP (base, extended_memmap[i].size); region_size = extended_memmap[i].size; - base =ROUND_UP (base, region_size); - vms->memmap[i].base = base; + vms->memmap[i].base = region_base; vms->memmap[i].size = region_size;/*
@@ -1709,9 +1709,9 @@ static void virt_set_high_memmap(VirtMachineState *vms,* * For each device that doesn't fit, disable it. */ - fits = (base + region_size) <=BIT_ULL (pa_bits); + fits = (region_base + region_size) <=BIT_ULL (pa_bits);if (fits) { - vms->highest_gpa = base + region_size -1 ; + vms->highest_gpa = region_base + region_size -1 ; }switch (i) {
@@ -1726,7 +1726,7 @@ static void virt_set_high_memmap(VirtMachineState *vms,break ; } - base += region_size; + base = region_base + region_size; } }
Signature · 1 line
2.23.0
Re: [PATCH v3 3/5] hw/arm/virt: Introduce variable region_base in virt_set_high_memmap()
Hi Gavin,
Quoted 3 lines · Gavin Shan
This introduces variable '
region_base' for the base address of the specific high memory region. It's the preparatory work to optimize high memory region address assignment.
Why is it a preparatory work (same comment for previous patch, ie [2/5] ). Are those changes really needed? why?
Eric
Quoted 52 lines
No functional change intended.
Signed-off-by Gavin Shan <[email protected]>--- hw/arm/virt.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)hw/arm/virt.c +6
-6@@ -1692,15 +1692,15 @@ static uint64_t virt_cpu_mp_affinity(VirtMachineState *vms, int idx)static void virt_set_high_memmap (VirtMachineState *vms,hwaddr base,int pa_bits) { -hwaddr region_size; +hwaddr region_base, region_size;bool fits;int i;for (i =VIRT_LOWMEMMAP_LAST ; i <ARRAY_SIZE (extended_memmap); i++) { + region_base =ROUND_UP (base, extended_memmap[i].size); region_size = extended_memmap[i].size; - base =ROUND_UP (base, region_size); - vms->memmap[i].base = base; + vms->memmap[i].base = region_base; vms->memmap[i].size = region_size;/* @@ -1709,9 +1709,9 @@ static void virt_set_high_memmap(VirtMachineState *vms,* * For each device that doesn't fit, disable it. */ - fits = (base + region_size) <=BIT_ULL (pa_bits); + fits = (region_base + region_size) <=BIT_ULL (pa_bits);if (fits) { - vms->highest_gpa = base + region_size -1 ; + vms->highest_gpa = region_base + region_size -1 ; }switch (i) {@@ -1726,7 +1726,7 @@ static void virt_set_high_memmap(VirtMachineState *vms,break ; } - base += region_size; + base = region_base + region_size; } }
Re: [PATCH v3 3/5] hw/arm/virt: Introduce variable region_base in virt_set_high_memmap()
Hi Eric,
Quoted 7 lines · Eric Auger
Quoted 3 lines · Gavin Shan
This introduces variable '
region_base' for the base address of the specific high memory region. It's the preparatory work to optimize high memory region address assignment.Why is it a preparatory work (same comment for previous patch, ie [2/5] ). Are those changes really needed? why?
In PATCH[4/5], @base argument is added to virt_set_high_memmap(), to represent current global base address. With the optimization applied in PATCH[4/5], @base isn't unconditionally updated to the top of the iterated high memory region. So we need @region_base here (PATCH[3/5]) to track the aligned base address for the iterated high memory region, which may or may be not updated to @base.
Since we have @region_base in PATCH[3/5], it'd better to have @region_size in PATCH[2/5].
Actually, PATCH[1-3/5] are all preparatory patches for PATCH[4/5]. My intention was to organize the patches in a way to keep the logical change part simple enough, for easier review.
Thanks,
Gavin
Quoted 53 lines
Quoted 52 lines
No functional change intended.
Signed-off-by Gavin Shan <[email protected]>--- hw/arm/virt.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)hw/arm/virt.c +6
-6@@ -1692,15 +1692,15 @@ static uint64_t virt_cpu_mp_affinity(VirtMachineState *vms, int idx)static void virt_set_high_memmap (VirtMachineState *vms,hwaddr base,int pa_bits) { -hwaddr region_size; +hwaddr region_base, region_size;bool fits;int i;for (i =VIRT_LOWMEMMAP_LAST ; i <ARRAY_SIZE (extended_memmap); i++) { + region_base =ROUND_UP (base, extended_memmap[i].size); region_size = extended_memmap[i].size; - base =ROUND_UP (base, region_size); - vms->memmap[i].base = base; + vms->memmap[i].base = region_base; vms->memmap[i].size = region_size;/* @@ -1709,9 +1709,9 @@ static void virt_set_high_memmap(VirtMachineState *vms,* * For each device that doesn't fit, disable it. */ - fits = (base + region_size) <=BIT_ULL (pa_bits); + fits = (region_base + region_size) <=BIT_ULL (pa_bits);if (fits) { - vms->highest_gpa = base + region_size -1 ; + vms->highest_gpa = region_base + region_size -1 ; }switch (i) {@@ -1726,7 +1726,7 @@ static void virt_set_high_memmap(VirtMachineState *vms,break ; } - base += region_size; + base = region_base + region_size; } }
Re: [PATCH v3 3/5] hw/arm/virt: Introduce variable region_base in virt_set_high_memmap()
Hi Gavin,
Quoted 18 lines · Gavin Shan
Hi Eric,
Quoted 7 lines · Eric Auger
Quoted 3 lines · Gavin Shan
This introduces variable '
region_base' for the base address of the specific high memory region. It's the preparatory work to optimize high memory region address assignment.Why is it a preparatory work (same comment for previous patch, ie [2/5] ). Are those changes really needed? why?
In PATCH[4/5], @base argument is added to
virt_set_high_memmap(), to represent current global base address. With the optimization applied in PATCH[4/5], @base isn't unconditionally updated to the top of the iterated high memory region. So we need @region_base here (PATCH[3/5]) to track the aligned base address for the iterated high memory region, which may or may be not updated to @base.
Quoted 7 lines
Since we have @region_base in PATCH[3/5], it'd better to have @region_size
in PATCH[2/5].Actually, PATCH[1-3/5] are all preparatory patches for PATCH[4/5]. My intention was to organize the patches in a way to keep the logical change part simple enough, for easier review.
OK fair enough
Eric
Quoted 57 lines
Thanks,
GavinQuoted 52 lines
Quoted 51 lines
No functional change intended.
Signed-off-by Gavin Shan <[email protected]>---
hw/arm/virt.c| 12 ++++++------1 file changed, 6 insertions(+), 6 deletions(-)hw/arm/virt.c +1
-1@@ -1692,15 +1692,15 @@ static uint64_t virt_cpu_mp_affinity(VirtMachineState *vms, int idx) static void virt_set_high_memmap(VirtMachineState *vms, hwaddr base, int pa_bits) { - hwaddr region_size; + hwaddr region_base, region_size; bool fits; int i;for (i =
VIRT_LOWMEMMAP_LAST; i <ARRAY_SIZE(extended_memmap); i++) {
+region_base=ROUND_UP(base, extended_memmap[i].size);region_size= extended_memmap[i].size;
- base =ROUND_UP(base, region_size);
- vms->memmap[i].base = base;
+ vms->memmap[i].base =region_base; vms->memmap[i].size =region_size;
/*hw/arm/virt.c +3
-2@@ -1709,9 +1709,9 @@ static voidvirt_set_high_memmap(VirtMachineState *vms, * * For each device that doesn't fit, disable it. */ - fits = (base + region_size) <= BIT_ULL(pa_bits); + fits = (region_base + region_size) <= BIT_ULL(pa_bits); if (fits) { - vms->highest_gpa = base + region_size - 1; + vms->highest_gpa = region_base + region_size - 1; } switch (i) {@@ -1726,7 +1726,7 @@ static void virt_set_high_memmap(VirtMachineState *vms, break; } - base += region_size; + base = region_base + region_size; } }
Re: [PATCH v3 3/5] hw/arm/virt: Introduce variable region_base in virt_set_high_memmap()
In reply to Gavin ShanQuoted 7 lines · Gavin Shan
This introduces variable '
region_base' for the base address of the specific high memory region. It's the preparatory work to optimize high memory region address assignment.No functional change intended.
Signed-off-by Gavin Shan <[email protected]>
Eric
Quoted 48 lines
--- hw/arm/virt.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)hw/arm/virt.c +6
-6@@ -1692,15 +1692,15 @@ static uint64_t virt_cpu_mp_affinity(VirtMachineState *vms, int idx)static void virt_set_high_memmap (VirtMachineState *vms,hwaddr base,int pa_bits) { -hwaddr region_size; +hwaddr region_base, region_size;bool fits;int i;for (i =VIRT_LOWMEMMAP_LAST ; i <ARRAY_SIZE (extended_memmap); i++) { + region_base =ROUND_UP (base, extended_memmap[i].size); region_size = extended_memmap[i].size; - base =ROUND_UP (base, region_size); - vms->memmap[i].base = base; + vms->memmap[i].base = region_base; vms->memmap[i].size = region_size;/* @@ -1709,9 +1709,9 @@ static void virt_set_high_memmap(VirtMachineState *vms,* * For each device that doesn't fit, disable it. */ - fits = (base + region_size) <=BIT_ULL (pa_bits); + fits = (region_base + region_size) <=BIT_ULL (pa_bits);if (fits) { - vms->highest_gpa = base + region_size -1 ; + vms->highest_gpa = region_base + region_size -1 ; }switch (i) {@@ -1726,7 +1726,7 @@ static void virt_set_high_memmap(VirtMachineState *vms,break ; } - base += region_size; + base = region_base + region_size; } }
PATCH v3 4/5 hw/arm/virt: Improve high memory region address assignment
In reply to Gavin ShanThere are three high memory regions, which are VIRT_HIGH_REDIST2, VIRT_HIGH_PCIE_ECAM and VIRT_HIGH_PCIE_MMIO. Their base addresses are floating on highest RAM address. However, they can be disabled in several cases.
(1) One specific high memory region is disabled by developer by
toggling vms->highmem_{redists, ecam, mmio}.(2) VIRT_HIGH_PCIE_ECAM region is disabled on machine, which is
'virt-2.12' or ealier than it.
(3) VIRT_HIGH_PCIE_ECAM region is disabled when firmware is loaded on 32-bits system.
(4) One specific high memory region is disabled when it breaks the PA space limit.
The current implementation of virt_set_memmap() isn't comprehensive because the space for one specific high memory region is always reserved from the PA space for case (1), (2) and (3). In the code, 'base' and 'vms->highest_gpa' are always increased for those three cases. It's unnecessary since the assigned space of the disabled high memory region won't be used afterwards.
This improves the address assignment for those three high memory region by skipping the address assignment for one specific high memory region if it has been disabled in case (1), (2) and (3).
--- hw/arm/virt.c | 44 ++++++++++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 18 deletions(-)
hw/arm/virt.c +26 -18
@@ -1693,15 +1693,31 @@ static void virt_set_high_memmap(VirtMachineState *vms, hwaddr base, int pa_bits) {hwaddr region_base, region_size; -bool fits; +bool *region_enabled, fits;int i;for (i =VIRT_LOWMEMMAP_LAST ; i <ARRAY_SIZE (extended_memmap); i++) { region_base =ROUND_UP (base, extended_memmap[i].size); region_size = extended_memmap[i].size; - vms->memmap[i].base = region_base; - vms->memmap[i].size = region_size; +switch (i) { +case VIRT_HIGH_GIC_REDIST2 : + region_enabled = &vms->highmem_redists; +break ; +case VIRT_HIGH_PCIE_ECAM : + region_enabled = &vms->highmem_ecam; +break ; +case VIRT_HIGH_PCIE_MMIO : + region_enabled = &vms->highmem_mmio; +break ; +default : + region_enabled =NULL ; + } + +/* Skip unknown region */ +if (!region_enabled) { +continue ; + }/* * Check each device to see if they fit in the PA space,
@@ -1710,23 +1726,15 @@ static void virt_set_high_memmap(VirtMachineState *vms,* For each device that doesn't fit, disable it. */ fits = (region_base + region_size) <=BIT_ULL (pa_bits); -if (fits) { - vms->highest_gpa = region_base + region_size -1 ; - } +if (*region_enabled && fits) { + vms->memmap[i].base = region_base; + vms->memmap[i].size = region_size; -switch (i) { -case VIRT_HIGH_GIC_REDIST2 : - vms->highmem_redists &= fits; -break ; -case VIRT_HIGH_PCIE_ECAM : - vms->highmem_ecam &= fits; -break ; -case VIRT_HIGH_PCIE_MMIO : - vms->highmem_mmio &= fits; -break ; + vms->highest_gpa = region_base + region_size -1 ; + base = region_base + region_size; + }else { + *region_enabled = false; } - - base = region_base + region_size; } }
Signature · 1 line
2.23.0
Re: [PATCH v3 4/5] hw/arm/virt: Improve high memory region address assignment
Hi Gavin,
Quoted 38 lines · Gavin Shan
There are three high memory regions, which are
VIRT_HIGH_REDIST2,VIRT_HIGH_PCIE_ECAMandVIRT_HIGH_PCIE_MMIO. Their base addresses are floating on highest RAM address. However, they can be disabled in several cases.(1) One specific high memory region is disabled by developer by
toggling vms->highmem_{redists, ecam, mmio}.(2)
VIRT_HIGH_PCIE_ECAMregion is disabled on machine, which is'virt-2.12' or ealier than it.(3)
VIRT_HIGH_PCIE_ECAMregion is disabled when firmware is loaded on 32-bits system.(4) One specific high memory region is disabled when it breaks the PA space limit.
The current implementation of
virt_set_memmap()isn't comprehensive because the space for one specific high memory region is always reserved from the PA space for case (1), (2) and (3). In the code, 'base' and 'vms->highest_gpa' are always increased for those three cases. It's unnecessary since the assigned space of the disabled high memory region won't be used afterwards.This improves the address assignment for those three high memory region by skipping the address assignment for one specific high memory region if it has been disabled in case (1), (2) and (3).
Signed-off-by Gavin Shan <[email protected]>--- hw/arm/virt.c | 44 ++++++++++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 18 deletions(-)hw/arm/virt.c +0
-0
hw/arm/virt.c static void virt_set_high_memmap(VirtMachineState *vms, · line 1696
Quoted 5 lines
hw/arm/virt.c +1
-1@@ -1693,15 +1693,31 @@ static void virt_set_high_memmap(VirtMachineState *vms, hwaddr base, int pa_bits) {hwaddr region_base, region_size; -bool fits; +bool *region_enabled, fits;
IDo you really need a pointer? If the region is unknown this is a bug in virt code.
Quoted 8 lines
hw/arm/virt.c +0
-2int i;for (i =VIRT_LOWMEMMAP_LAST ; i <ARRAY_SIZE (extended_memmap); i++) { region_base =ROUND_UP (base, extended_memmap[i].size); region_size = extended_memmap[i].size; - vms->memmap[i].base = region_base; - vms->memmap[i].size = region_size;
hw/arm/virt.c static void virt_set_high_memmap(VirtMachineState *vms, · line 1712
Quoted 10 lines
hw/arm/virt.c +10
-0+switch (i) { +case VIRT_HIGH_GIC_REDIST2 : + region_enabled = &vms->highmem_redists; +break ; +case VIRT_HIGH_PCIE_ECAM : + region_enabled = &vms->highmem_ecam; +break ; +case VIRT_HIGH_PCIE_MMIO : + region_enabled = &vms->highmem_mmio; +break ;
While we are at it I would change the vms fields dealing with those highmem regions and turn those fields into an array of bool indexed using i - VIRT_LOWMEMMAP_LAST (using a macro or something alike). We would not be obliged to have this switch, now duplicated.
Quoted 32 lines
hw/arm/virt.c +11
-13+default : + region_enabled =NULL ; + } + +/* Skip unknown region */ +if (!region_enabled) { +continue ; + }/* * Check each device to see if they fit in the PA space, @@ -1710,23 +1726,15 @@ static void virt_set_high_memmap(VirtMachineState *vms,* For each device that doesn't fit, disable it. */ fits = (region_base + region_size) <=BIT_ULL (pa_bits); -if (fits) { - vms->highest_gpa = region_base + region_size -1 ; - } +if (*region_enabled && fits) { + vms->memmap[i].base = region_base; + vms->memmap[i].size = region_size; -switch (i) { -case VIRT_HIGH_GIC_REDIST2 : - vms->highmem_redists &= fits; -break ; -case VIRT_HIGH_PCIE_ECAM : - vms->highmem_ecam &= fits; -break ; -case VIRT_HIGH_PCIE_MMIO : - vms->highmem_mmio &= fits; -break ;
hw/arm/virt.c static void virt_set_high_memmap(VirtMachineState *vms, · line 1740
Quoted 10 lines
hw/arm/virt.c +4
-2+ vms->highest_gpa = region_base + region_size -1 ; + base = region_base + region_size; + }else { + *region_enabled = false; } - - base = region_base + region_size; } }
Thanks
Eric
Re: [PATCH v3 4/5] hw/arm/virt: Improve high memory region address assignment
Hi Eric,
Quoted 34 lines · Eric Auger
Quoted 33 lines · Gavin Shan
There are three high memory regions, which are
VIRT_HIGH_REDIST2,VIRT_HIGH_PCIE_ECAMandVIRT_HIGH_PCIE_MMIO. Their base addresses are floating on highest RAM address. However, they can be disabled in several cases.(1) One specific high memory region is disabled by developer by
toggling vms->highmem_{redists, ecam, mmio}.(2)
VIRT_HIGH_PCIE_ECAMregion is disabled on machine, which is'virt-2.12' or ealier than it.(3)
VIRT_HIGH_PCIE_ECAMregion is disabled when firmware is loaded on 32-bits system.(4) One specific high memory region is disabled when it breaks the PA space limit.
The current implementation of
virt_set_memmap()isn't comprehensive because the space for one specific high memory region is always reserved from the PA space for case (1), (2) and (3). In the code, 'base' and 'vms->highest_gpa' are always increased for those three cases. It's unnecessary since the assigned space of the disabled high memory region won't be used afterwards.This improves the address assignment for those three high memory region by skipping the address assignment for one specific high memory region if it has been disabled in case (1), (2) and (3).
Signed-off-by Gavin Shan <[email protected]>--- hw/arm/virt.c | 44 ++++++++++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 18 deletions(-)
Quoted 12 lines
hw/arm/virt.c static void virt_set_high_memmap(VirtMachineState *vms, · line 1696
Quoted 10 lines
hw/arm/virt.c +1
-1@@ -1693,15 +1693,31 @@ static void virt_set_high_memmap(VirtMachineState *vms, hwaddr base, int pa_bits) {hwaddr region_base, region_size; -bool fits; +bool *region_enabled, fits;IDo you really need a pointer? If the region is unknown this is a bug in virt code.
The pointer is needed so that we can disable the region by setting 'false' to it at later point. Yeah, I think you're correct that 'unknown region' is a bug and we need to do assert(region_enabled), or something like below.
Quoted 18 lines
Quoted 8 lines
hw/arm/virt.c +0
-2int i;for (i =VIRT_LOWMEMMAP_LAST ; i <ARRAY_SIZE (extended_memmap); i++) { region_base =ROUND_UP (base, extended_memmap[i].size); region_size = extended_memmap[i].size; - vms->memmap[i].base = region_base; - vms->memmap[i].size = region_size;hw/arm/virt.c static void virt_set_high_memmap(VirtMachineState *vms, · line 1712
Quoted 10 lines
hw/arm/virt.c +10
-0+switch (i) { +case VIRT_HIGH_GIC_REDIST2 : + region_enabled = &vms->highmem_redists; +break ; +case VIRT_HIGH_PCIE_ECAM : + region_enabled = &vms->highmem_ecam; +break ; +case VIRT_HIGH_PCIE_MMIO : + region_enabled = &vms->highmem_mmio; +break ;
Quoted 4 lines
While we are at it I would change the vms fields dealing with those highmem regions and turn those fields into an array of bool indexed using i -
VIRT_LOWMEMMAP_LAST(using a macro or something alike). We would not be obliged to have this switch, now duplicated.
It makes sense to me. How about to have something like below in v4?
static inline bool *virt_get_high_memmap_enabled(VirtMachineState *vms, int index)
{
bool *enabled_array[] = {
&vms->highmem_redists,
&vms->highmem_ecam,
&vms->highmem_mmio,
};
assert(index - VIRT_LOWMEMMAP_LAST < ARRAY_SIZE(enabled_array));
return enabled_array[index - VIRT_LOWMEMMAP_LAST];
}Quoted 34 lines
Quoted 34 lines
hw/arm/virt.c +13
-13+default : + region_enabled =NULL ; + } + +/* Skip unknown region */ +if (!region_enabled) { +continue ; + }/* * Check each device to see if they fit in the PA space, @@ -1710,23 +1726,15 @@ static void virt_set_high_memmap(VirtMachineState *vms,* For each device that doesn't fit, disable it. */ fits = (region_base + region_size) <=BIT_ULL (pa_bits); -if (fits) { - vms->highest_gpa = region_base + region_size -1 ; - } +if (*region_enabled && fits) { + vms->memmap[i].base = region_base; + vms->memmap[i].size = region_size; -switch (i) { -case VIRT_HIGH_GIC_REDIST2 : - vms->highmem_redists &= fits; -break ; -case VIRT_HIGH_PCIE_ECAM : - vms->highmem_ecam &= fits; -break ; -case VIRT_HIGH_PCIE_MMIO : - vms->highmem_mmio &= fits; -break ; + vms->highest_gpa = region_base + region_size -1 ; + base = region_base + region_size;
Quoted 8 lines
hw/arm/virt.c static void virt_set_high_memmap(VirtMachineState *vms, · line 1740
Quoted 8 lines
hw/arm/virt.c +2
-2+ }else { + *region_enabled = false; } - - base = region_base + region_size; } }
Thanks,
Gavin
Re: [PATCH v3 4/5] hw/arm/virt: Improve high memory region address assignment
Hi Gavin,
Quoted 51 lines · Gavin Shan
Hi Eric,
Quoted 34 lines · Eric Auger
Quoted 33 lines · Gavin Shan
There are three high memory regions, which are
VIRT_HIGH_REDIST2,VIRT_HIGH_PCIE_ECAMandVIRT_HIGH_PCIE_MMIO. Their base addresses are floating on highest RAM address. However, they can be disabled in several cases.(1) One specific high memory region is disabled by developer by toggling vms->highmem_{redists, ecam, mmio}.
(2)
VIRT_HIGH_PCIE_ECAMregion is disabled on machine, which is 'virt-2.12' or ealier than it.(3)
VIRT_HIGH_PCIE_ECAMregion is disabled when firmware is loaded on 32-bits system.(4) One specific high memory region is disabled when it breaks the PA space limit.
The current implementation of
virt_set_memmap()isn't comprehensive because the space for one specific high memory region is always reserved from the PA space for case (1), (2) and (3). In the code, 'base' and 'vms->highest_gpa' are always increased for those three cases. It's unnecessary since the assigned space of the disabled high memory region won't be used afterwards.This improves the address assignment for those three high memory region by skipping the address assignment for one specific high memory region if it has been disabled in case (1), (2) and (3).
Signed-off-by Gavin Shan <[email protected]>---
hw/arm/virt.c| 44 ++++++++++++++++++++++++++------------------1 file changed, 26 insertions(+), 18 deletions(-)Quoted 13 lines
hw/arm/virt.c static void · line 1697
Quoted 11 lines
hw/arm/virt.c +1
-1@@ -1693,15 +1693,31 @@ static voidvirt_set_high_memmap (VirtMachineState *vms, hwaddr base, int pa_bits) { hwaddr region_base, region_size; - bool fits; + bool *region_enabled, fits;IDo you really need a pointer? If the region is unknown this is a bug in virt code.
Quoted 5 lines
The pointer is needed so that we can disable the region by setting 'false'
to it at later point. Yeah, I think you're correct that 'unknown region' is a bug and we need to doassert(region_enabled), or something like below.
Yeah I don't think using a pointer here is useful.
Quoted 34 lines
Quoted 18 lines
Quoted 10 lines
hw/arm/virt.c +0
-0int i;for (i =
VIRT_LOWMEMMAP_LAST; i <ARRAY_SIZE(extended_memmap); i++) {
region_base=ROUND_UP(base, extended_memmap[i].size);region_size= extended_memmap[i].size;
- vms->memmap[i].base =region_base;
- vms->memmap[i].size =region_size;
+ switch (i) {
+ caseVIRT_HIGH_GIC_REDIST2:Quoted 8 lines
+
region_enabled=&vms->highmem_redists; + break;
+ caseVIRT_HIGH_PCIE_ECAM:
+region_enabled=&vms->highmem_ecam; + break;
+ caseVIRT_HIGH_PCIE_MMIO:
+region_enabled=&vms->highmem_mmio; + break;Quoted 4 lines
While we are at it I would change the vms fields dealing with those highmem regions and turn those fields into an array of bool indexed using i -
VIRT_LOWMEMMAP_LAST(using a macro or something alike). We would not be obliged to have this switch, now duplicated.It makes sense to me. How about to have something like below in v4?
static inline bool *virt_get_high_memmap_enabled(VirtMachineState *vms, int index)
{
bool *enabled_array[] = {
&vms->highmem_redists,
&vms->highmem_ecam,
&vms->highmem_mmio,
};
Quoted 4 lines
assert(index - VIRT_LOWMEMMAP_LAST < ARRAY_SIZE(enabled_array));return enabled_array[index -
VIRT_LOWMEMMAP_LAST]; }
I was rather thinking as directly using a vms->highmem_flags[] but your proposal may work as well.
Quoted 28 lines
Quoted 28 lines
Quoted 28 lines
+ default:
+region_enabled= NULL;
+ }
+
+ /* Skip unknown region */
+ if (!region_enabled) {
+ continue;
+ }
/*
* Check each device to see if they fit in the PA space,hw/arm/virt.c +3
-8@@ -1710,23 +1726,15 @@ static voidvirt_set_high_memmap(VirtMachineState *vms, * For each device that doesn't fit, disable it. */ fits = (region_base + region_size) <= BIT_ULL(pa_bits); - if (fits) { - vms->highest_gpa = region_base + region_size - 1; - } + if (*region_enabled && fits) { + vms->memmap[i].base = region_base; + vms->memmap[i].size = region_size; - switch (i) { - case VIRT_HIGH_GIC_REDIST2: - vms->highmem_redists &= fits; - break; - case VIRT_HIGH_PCIE_ECAM: - vms->highmem_ecam &= fits;
Quoted 8 lines
Quoted 8 lines
hw/arm/virt.c static void virt_set_high_memmap(VirtMachineState *vms, · line 1736
Quoted 8 lines
hw/arm/virt.c +4
-4- break; - case VIRT_HIGH_PCIE_MMIO: - vms->highmem_mmio &= fits; - break; + vms->highest_gpa = region_base + region_size - 1; + base = region_base + region_size; + } else { + *region_enabled = false;
what's the purpose to update the region_enabled here? Is it used anywhere?
The fact you do not update vms->highmem_* flags may introduce regressions I think as the resulting flag may be used in some places such as:virt_gicv3_redist_region_count().
Quoted 9 lines
Quoted 5 lines
Quoted 5 lines
hw/arm/virt.c +0
-2- - base = region_base + region_size; } }Thanks,
Gavin
Thanks
Eric
Re: [PATCH v3 4/5] hw/arm/virt: Improve high memory region address assignment
Hi Eric,
Quoted 50 lines · Eric Auger
Quoted 49 lines · Gavin Shan
Quoted 47 lines · Eric Auger
Quoted 38 lines · Gavin Shan
There are three high memory regions, which are
VIRT_HIGH_REDIST2,VIRT_HIGH_PCIE_ECAMandVIRT_HIGH_PCIE_MMIO. Their base addresses are floating on highest RAM address. However, they can be disabled in several cases.(1) One specific high memory region is disabled by developer by toggling vms->highmem_{redists, ecam, mmio}.
(2)
VIRT_HIGH_PCIE_ECAMregion is disabled on machine, which is 'virt-2.12' or ealier than it.(3)
VIRT_HIGH_PCIE_ECAMregion is disabled when firmware is loaded on 32-bits system.(4) One specific high memory region is disabled when it breaks the PA space limit.
The current implementation of
virt_set_memmap()isn't comprehensive because the space for one specific high memory region is always reserved from the PA space for case (1), (2) and (3). In the code, 'base' and 'vms->highest_gpa' are always increased for those three cases. It's unnecessary since the assigned space of the disabled high memory region won't be used afterwards.This improves the address assignment for those three high memory region by skipping the address assignment for one specific high memory region if it has been disabled in case (1), (2) and (3).
Signed-off-by Gavin Shan <[email protected]>--- hw/arm/virt.c | 44 ++++++++++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 18 deletions(-)hw/arm/virt.c +0
-0hw/arm/virt.c static void · line 1697
Quoted 6 lines
hw/arm/virt.c +1
-1@@ -1693,15 +1693,31 @@ static voidvirt_set_high_memmap (VirtMachineState *vms, hwaddr base, int pa_bits) { hwaddr region_base, region_size; - bool fits; + bool *region_enabled, fits;IDo you really need a pointer? If the region is unknown this is a bug in virt code.
Quoted 6 lines
Quoted 5 lines
The pointer is needed so that we can disable the region by setting 'false'
to it at later point. Yeah, I think you're correct that 'unknown region' is a bug and we need to doassert(region_enabled), or something like below.Yeah I don't think using a pointer here is useful.
When the high memory region can't fit into the PA space, it is disabled by toggling the corresponding flag (vms->highmem_{redists, ecam, mmio}) to false. It's part of the original implementation, as below. We either need a 'switch ... case' or a pointer. A pointer is more convenient since we need check and possibly update to the value.
switch (i) {
case VIRT_HIGH_GIC_REDIST2:
vms->highmem_redists &= fits;
break;
case VIRT_HIGH_PCIE_ECAM:
vms->highmem_ecam &= fits;
break;
case VIRT_HIGH_PCIE_MMIO:
vms->highmem_mmio &= fits;
break;
}Quoted 34 lines
Quoted 34 lines
Quoted 18 lines
Quoted 8 lines
hw/arm/virt.c +0
-1int i; for (i = VIRT_LOWMEMMAP_LAST; i <ARRAY_SIZE (extended_memmap); i++) { region_base = ROUND_UP(base, extended_memmap[i].size); region_size = extended_memmap[i].size; - vms->memmap[i].base = region_base; - vms->memmap[i].size = region_size;hw/arm/virt.c static void virt_set_high_memmap(VirtMachineState *vms, · line 1712
Quoted 10 lines
hw/arm/virt.c +10
-0+ switch (i) { + case VIRT_HIGH_GIC_REDIST2: + region_enabled = &vms->highmem_redists; + break; + case VIRT_HIGH_PCIE_ECAM: + region_enabled = &vms->highmem_ecam; + break; + case VIRT_HIGH_PCIE_MMIO: + region_enabled = &vms->highmem_mmio; + break;Quoted 4 lines
While we are at it I would change the vms fields dealing with those highmem regions and turn those fields into an array of bool indexed using i -
VIRT_LOWMEMMAP_LAST(using a macro or something alike). We would not be obliged to have this switch, now duplicated.It makes sense to me. How about to have something like below in v4?
static inline bool *virt_get_high_memmap_enabled(VirtMachineState *vms, int index)
{
bool *enabled_array[] = {
&vms->highmem_redists,
&vms->highmem_ecam,
&vms->highmem_mmio,
};
Quoted 6 lines
Quoted 4 lines
assert(index - VIRT_LOWMEMMAP_LAST < ARRAY_SIZE(enabled_array));return enabled_array[index -
VIRT_LOWMEMMAP_LAST];
}I was rather thinking as directly using a vms->highmem_flags[] but your proposal may work as well.
Ok. I will use my proposed change in next revision.
Quoted 38 lines
Quoted 28 lines
Quoted 28 lines
Quoted 28 lines
hw/arm/virt.c +11
-8+ default: + region_enabled = NULL; + } + + /* Skip unknown region */ + if (!region_enabled) { + continue; + } /** Check each device to see if they fit in the PA space, @@ -1710,23 +1726,15 @@ static voidvirt_set_high_memmap(VirtMachineState *vms, * For each device that doesn't fit, disable it. */ fits = (region_base + region_size) <= BIT_ULL(pa_bits); - if (fits) { - vms->highest_gpa = region_base + region_size - 1; - } + if (*region_enabled && fits) { + vms->memmap[i].base = region_base; + vms->memmap[i].size = region_size; - switch (i) { - case VIRT_HIGH_GIC_REDIST2: - vms->highmem_redists &= fits; - break; - case VIRT_HIGH_PCIE_ECAM: - vms->highmem_ecam &= fits;Quoted 8 lines
Quoted 8 lines
hw/arm/virt.c static void virt_set_high_memmap(VirtMachineState *vms, · line 1736
Quoted 8 lines
hw/arm/virt.c +4
-4- break; - case VIRT_HIGH_PCIE_MMIO: - vms->highmem_mmio &= fits; - break; + vms->highest_gpa = region_base + region_size - 1; + base = region_base + region_size; + } else { + *region_enabled = false;what's the purpose to update the
region_enabledhere? Is it used anywhere?
Quoted 5 lines
The fact you do not update vms->highmem_* flags may introduce regressions I think as the resulting flag may be used in some places such as:
virt_gicv3_redist_region_count().
'region_enabled' points to 'vms->highmem_{redist2, ecam, mmio}'. They are same thing.
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
hw/arm/virt.c static void virt_set_high_memmap(VirtMachineState *vms, · line 1740
Quoted 5 lines
hw/arm/virt.c +0
-2- - base = region_base + region_size; } }
Thanks,
Gavin
Re: [PATCH v3 4/5] hw/arm/virt: Improve high memory region address assignment
Quoted 162 lines · Gavin Shan
Hi Eric,
Quoted 51 lines · Eric Auger
Quoted 50 lines · Gavin Shan
Quoted 48 lines · Eric Auger
Quoted 38 lines · Gavin Shan
There are three high memory regions, which are
VIRT_HIGH_REDIST2,VIRT_HIGH_PCIE_ECAMandVIRT_HIGH_PCIE_MMIO. Their base addresses are floating on highest RAM address. However, they can be disabled in several cases.(1) One specific high memory region is disabled by developer by toggling vms->highmem_{redists, ecam, mmio}.
(2)
VIRT_HIGH_PCIE_ECAMregion is disabled on machine, which is 'virt-2.12' or ealier than it.(3)
VIRT_HIGH_PCIE_ECAMregion is disabled when firmware is loaded on 32-bits system.(4) One specific high memory region is disabled when it breaks the PA space limit.
The current implementation of
virt_set_memmap()isn't comprehensive because the space for one specific high memory region is always reserved from the PA space for case (1), (2) and (3). In the code, 'base' and 'vms->highest_gpa' are always increased for those three cases. It's unnecessary since the assigned space of the disabled high memory region won't be used afterwards.This improves the address assignment for those three high memory region by skipping the address assignment for one specific high memory region if it has been disabled in case (1), (2) and (3).
Signed-off-by Gavin Shan <[email protected]>---
hw/arm/virt.c| 44 ++++++++++++++++++++++++++------------------1 file changed, 26 insertions(+), 18 deletions(-)hw/arm/virt.c +0
-0hw/arm/virt.c static void · line 1697
Quoted 6 lines
hw/arm/virt.c +1
-1@@ -1693,15 +1693,31 @@ static voidvirt_set_high_memmap (VirtMachineState *vms, hwaddr base, int pa_bits) { hwaddr region_base, region_size; - bool fits; + bool *region_enabled, fits;IDo you really need a pointer? If the region is unknown this is a bug in
virt code.Quoted 7 lines
Quoted 6 lines
The pointer is needed so that we can disable the region by setting 'false'
to it at later point. Yeah, I think you're correct that 'unknown region'
is a bug and we need to doassert(region_enabled), or something like below.Yeah I don't think using a pointer here is useful.
When the high memory region can't fit into the PA space, it is disabled by toggling the corresponding flag (vms->highmem_{redists, ecam, mmio}) to false. It's part of the original implementation, as below. We either need a 'switch ... case' or a pointer. A pointer is more convenient since we need check and possibly update to the value.
switch (i) {
caseVIRT_HIGH_GIC_REDIST2:
vms->highmem_redists&= fits;
break;
caseVIRT_HIGH_PCIE_ECAM:
vms->highmem_ecam&= fits;
break;
caseVIRT_HIGH_PCIE_MMIO:
vms->highmem_mmio&= fits;
break;
}Quoted 34 lines
Quoted 34 lines
Quoted 18 lines
Quoted 10 lines
hw/arm/virt.c +0
-0int i;for (i =
VIRT_LOWMEMMAP_LAST; i <ARRAY_SIZE(extended_memmap); i++) {
region_base=ROUND_UP(base, extended_memmap[i].size);region_size= extended_memmap[i].size;
- vms->memmap[i].base =region_base;
- vms->memmap[i].size =region_size;
+ switch (i) {
+ caseVIRT_HIGH_GIC_REDIST2:Quoted 8 lines
+
region_enabled=&vms->highmem_redists; + break;
+ caseVIRT_HIGH_PCIE_ECAM:
+region_enabled=&vms->highmem_ecam; + break;
+ caseVIRT_HIGH_PCIE_MMIO:
+region_enabled=&vms->highmem_mmio; + break;Quoted 4 lines
While we are at it I would change the vms fields dealing with those highmem regions and turn those fields into an array of bool indexed using i -
VIRT_LOWMEMMAP_LAST(using a macro or something alike). We would not be obliged to have this switch, now duplicated.It makes sense to me. How about to have something like below in v4?
static inline bool *virt_get_high_memmap_enabled(VirtMachineState *vms, int index)
{
bool *enabled_array[] = {
&vms->highmem_redists,
&vms->highmem_ecam,
&vms->highmem_mmio,
};Quoted 6 lines
Quoted 4 lines
assert(index - VIRT_LOWMEMMAP_LAST < ARRAY_SIZE(enabled_array));return enabled_array[index -
VIRT_LOWMEMMAP_LAST]; }I was rather thinking as directly using a vms->highmem_flags[] but your proposal may work as well.
Ok. I will use my proposed change in next revision.
Quoted 39 lines
Quoted 28 lines
Quoted 28 lines
Quoted 28 lines
+ default:
+region_enabled= NULL;
+ }
+
+ /* Skip unknown region */
+ if (!region_enabled) {
+ continue;
+ }
/*
* Check each device to see if they fit in the PA space,hw/arm/virt.c +3
-8@@ -1710,23 +1726,15 @@ static voidvirt_set_high_memmap(VirtMachineState *vms, * For each device that doesn't fit, disable it. */ fits = (region_base + region_size) <= BIT_ULL(pa_bits); - if (fits) { - vms->highest_gpa = region_base + region_size - 1; - } + if (*region_enabled && fits) { + vms->memmap[i].base = region_base; + vms->memmap[i].size = region_size; - switch (i) { - case VIRT_HIGH_GIC_REDIST2: - vms->highmem_redists &= fits; - break; - case VIRT_HIGH_PCIE_ECAM: - vms->highmem_ecam &= fits;Quoted 8 lines
Quoted 8 lines
hw/arm/virt.c static void virt_set_high_memmap(VirtMachineState *vms, · line 1736
Quoted 8 lines
hw/arm/virt.c +4
-4- break; - case VIRT_HIGH_PCIE_MMIO: - vms->highmem_mmio &= fits; - break; + vms->highest_gpa = region_base + region_size - 1; + base = region_base + region_size; + } else { + *region_enabled = false;what's the purpose to update the
region_enabledhere? Is it used anywhere?
Quoted 8 lines
Quoted 5 lines
The fact you do not update vms->highmem_* flags may introduce regressions I think as the resulting flag may be used in some places such as:
virt_gicv3_redist_region_count().'
region_enabled' points to 'vms->highmem_{redist2, ecam, mmio}'. They are same thing.
Oh OK. Sorry for the noise.
Eric
Quoted 10 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
hw/arm/virt.c +0
-2- - base = region_base + region_size; } }Thanks,
Gavin
PATCH v3 5/5 hw/arm/virt: Add 'highmem-compact' property
In reply to Gavin ShanAfter the improvement to high memory region address assignment is applied, the memory layout is changed. For example, VIRT_HIGH_PCIE_MMIO memory region is enabled when the improvement is applied, but it's disabled if the improvement isn't applied.
pa_bits = 40;
vms->highmem_redists = false;
vms->highmem_ecam = false;
vms->highmem_mmio = true;
# qemu-system-aarch64 -accel kvm -cpu host \
-machine virt-7.2 -m 4G,maxmem=511G \
-monitor stdioIn order to keep backwords compatibility, we need to disable the optimization on machines, which is virt-7.1 or ealier than it. It means the optimization is enabled by default from virt-7.2. Besides, 'highmem-compact' property is added so that the optimization can be explicitly enabled or disabled on all machine types by users.
--- docs/system/arm/virt.rst | 4 ++++ hw/arm/virt.c | 33 +++++++++++++++++++++++++++++++++ include/hw/arm/virt.h | 2 ++ 3 files changed, 39 insertions(+)
docs/system/arm/virt.rst +4 -0
@@ -94,6 +94,10 @@ highmem address space above 32 bits. The default is ``on`` for machine types later than ``virt-2.12``. +highmem-compact + Set ``on``/``off`` to enable/disable compact space for high memory regions. + The default is ``on`` for machine types later than ``virt-7.2`` + gic-version Specify the version of the Generic Interrupt Controller (GIC) to provide. Valid values are:
hw/arm/virt.c +33 -0
@@ -1734,6 +1734,13 @@ static void virt_set_high_memmap(VirtMachineState *vms, base = region_base + region_size; }else { *region_enabled = false; + +if (!vms->highmem_compact) { + base = region_base + region_size; +if (fits) { + vms->highest_gpa = region_base + region_size -1 ; + } + } } } }
@@ -2348,6 +2355,20 @@ static void virt_set_highmem(Object *obj, bool value, Error **errp) vms->highmem = value; } +static bool virt_get_highmem_compact (Object *obj,Error **errp) +{ +VirtMachineState *vms =VIRT_MACHINE (obj); + +return vms->highmem_compact; +} + +static void virt_set_highmem_compact (Object *obj,bool value,Error **errp) +{ +VirtMachineState *vms =VIRT_MACHINE (obj); + + vms->highmem_compact = value; +} +static bool virt_get_its (Object *obj,Error **errp) {VirtMachineState *vms =VIRT_MACHINE (obj);
@@ -2966,6 +2987,13 @@ static void virt_machine_class_init(ObjectClass *oc, void *data)"Set on/off to enable/disable using " "physical address space above 32 bits"); +object_class_property_add_bool (oc,"highmem-compact" , + virt_get_highmem_compact, + virt_set_highmem_compact); +object_class_property_set_description (oc,"highmem-compact" , +"Set on/off to enable/disable compact " +"space for high memory regions" ); +object_class_property_add_str (oc,"gic-version" , virt_get_gic_version, virt_set_gic_version); object_class_property_set_description(oc, "gic-version",
@@ -3050,6 +3078,7 @@ static void virt_instance_init(Object *obj)/* High memory is enabled by default */ vms->highmem = true; + vms->highmem_compact = !vmc->no_highmem_compact; vms->gic_version =VIRT_GIC_VERSION_NOSEL ; vms->highmem_ecam = !vmc->no_highmem_ecam;
@@ -3119,8 +3148,12 @@ DEFINE_VIRT_MACHINE_AS_LATEST(7, 2)static void virt_machine_7_1_options (MachineClass *mc) { +VirtMachineClass *vmc =VIRT_MACHINE_CLASS (OBJECT_CLASS (mc)); +virt_machine_7_2_options (mc);compat_props_add (mc->compat_props, hw_compat_7_1, hw_compat_7_1_len); +/* Compact space for high memory regions was introduced with 7.2 */ + vmc->no_highmem_compact = true; }DEFINE_VIRT_MACHINE (7 ,1 )
include/hw/arm/virt.h +2 -0
@@ -125,6 +125,7 @@ struct VirtMachineClass {bool no_pmu;bool claim_edge_triggered_timers;bool smbios_old_sys_ver; +bool no_highmem_compact;bool no_highmem_ecam;bool no_ged;/* Machines < 4.2 have no support for ACPI GED device */ bool kvm_no_adjvtime;
@@ -144,6 +145,7 @@ struct VirtMachineState {PFlashCFI01 *flash[2 ];bool secure;bool highmem; +bool highmem_compact;bool highmem_ecam;bool highmem_mmio;bool highmem_redists;
Signature · 1 line
2.23.0
Re: [PATCH v3 5/5] hw/arm/virt: Add 'highmem-compact' property
Hi Gavin,
Quoted 2 lines · Gavin Shan
After the improvement to high memory region address assignment is applied, the memory layout is changed. For example,
VIRT_HIGH_PCIE_MMIO
s/the memory layout is changed./the memory layout is changed, introducing possible migration breakage.
Quoted 12 lines
memory region is enabled when the improvement is applied, but it's disabled if the improvement isn't applied.
pa_bits = 40; vms->highmem_redists = false; vms->highmem_ecam = false; vms->highmem_mmio = true; # qemu-system-aarch64 -accel kvm -cpu host \ -machine virt-7.2 -m 4G,maxmem=511G \ -monitor stdio
Quoted 4 lines
In order to keep backwords compatibility, we need to disable the optimization on machines, which is virt-7.1 or ealier than it. It means the optimization is enabled by default from virt-7.2. Besides, 'highmem-compact' property is added so that the optimization can be
I would rather rename the property into compact-highmem even if the vms field is name highmem_compact to align with other highmem fields
Quoted 14 lines
explicitly enabled or disabled on all machine types by users.
Signed-off-by Gavin Shan <[email protected]>--- docs/system/arm/virt.rst | 4 ++++ hw/arm/virt.c | 33 +++++++++++++++++++++++++++++++++ include/hw/arm/virt.h | 2 ++ 3 files changed, 39 insertions(+)docs/system/arm/virt.rst +0
-0
docs/system/arm/virt.rst highmem · line 99
Quoted 6 lines
docs/system/arm/virt.rst +3
-0@@ -94,6 +94,10 @@ highmem address space above 32 bits. The default is ``on`` for machine types later than ``virt-2.12``. +highmem-compact + Set ``on``/``off`` to enable/disable compact space for high memory regions. + The default is ``on`` for machine types later than ``virt-7.2``
I think you should document what is compact layout versus legacy one, both in the commit msg and maybe as a comment in a code along with the comment in hw/arm/virt.c starting with 'Highmem IO Regions: '
Quoted 9 lines
docs/system/arm/virt.rst +1
-0+ gic-version Specify the version of the Generic Interrupt Controller (GIC) to provide. Valid values are:hw/arm/virt.c +0
-0
hw/arm/virt.c static void virt_set_high_memmap(VirtMachineState *vms, · line 1738
Quoted 5 lines
hw/arm/virt.c +2
-0@@ -1734,6 +1734,13 @@ static void virt_set_high_memmap(VirtMachineState *vms, base = region_base + region_size; }else { *region_enabled = false; + +if (!vms->highmem_compact) {
this snippet should be already present in previous patch otherwise this will break bisectability.
Quoted 77 lines
hw/arm/virt.c +31
-0+ base = region_base + region_size; +if (fits) { + vms->highest_gpa = region_base + region_size -1 ; + } + } } } }@@ -2348,6 +2355,20 @@ static void virt_set_highmem(Object *obj, bool value, Error **errp) vms->highmem = value; } +static bool virt_get_highmem_compact (Object *obj,Error **errp) +{ +VirtMachineState *vms =VIRT_MACHINE (obj); + +return vms->highmem_compact; +} + +static void virt_set_highmem_compact (Object *obj,bool value,Error **errp) +{ +VirtMachineState *vms =VIRT_MACHINE (obj); + + vms->highmem_compact = value; +} +static bool virt_get_its (Object *obj,Error **errp) {VirtMachineState *vms =VIRT_MACHINE (obj);@@ -2966,6 +2987,13 @@ static void virt_machine_class_init(ObjectClass *oc, void *data)"Set on/off to enable/disable using " "physical address space above 32 bits"); +object_class_property_add_bool (oc,"highmem-compact" , + virt_get_highmem_compact, + virt_set_highmem_compact); +object_class_property_set_description (oc,"highmem-compact" , +"Set on/off to enable/disable compact " +"space for high memory regions" ); +object_class_property_add_str (oc,"gic-version" , virt_get_gic_version, virt_set_gic_version); object_class_property_set_description(oc, "gic-version",@@ -3050,6 +3078,7 @@ static void virt_instance_init(Object *obj)/* High memory is enabled by default */ vms->highmem = true; + vms->highmem_compact = !vmc->no_highmem_compact; vms->gic_version =VIRT_GIC_VERSION_NOSEL ; vms->highmem_ecam = !vmc->no_highmem_ecam;@@ -3119,8 +3148,12 @@ DEFINE_VIRT_MACHINE_AS_LATEST(7, 2)static void virt_machine_7_1_options (MachineClass *mc) { +VirtMachineClass *vmc =VIRT_MACHINE_CLASS (OBJECT_CLASS (mc)); +virt_machine_7_2_options (mc);compat_props_add (mc->compat_props, hw_compat_7_1, hw_compat_7_1_len); +/* Compact space for high memory regions was introduced with 7.2 */ + vmc->no_highmem_compact = true; }DEFINE_VIRT_MACHINE (7 ,1 )include/hw/arm/virt.h +1
-0@@ -125,6 +125,7 @@ struct VirtMachineClass {bool no_pmu;bool claim_edge_triggered_timers;bool smbios_old_sys_ver; +bool no_highmem_compact;bool no_highmem_ecam;bool no_ged;/* Machines < 4.2 have no support for ACPI GED device */ bool kvm_no_adjvtime;
include/hw/arm/virt.h struct VirtMachineState { · line 151
Quoted 7 lines
include/hw/arm/virt.h +1
-0@@ -144,6 +145,7 @@ struct VirtMachineState {PFlashCFI01 *flash[2 ];bool secure;bool highmem; +bool highmem_compact;bool highmem_ecam;bool highmem_mmio;bool highmem_redists;
Thanks
Eric
Re: [PATCH v3 5/5] hw/arm/virt: Add 'highmem-compact' property
Hi Eric,
Quoted 5 lines · Eric Auger
Quoted 2 lines · Gavin Shan
After the improvement to high memory region address assignment is applied, the memory layout is changed. For example,
VIRT_HIGH_PCIE_MMIOs/the memory layout is changed./the memory layout is changed, introducing possible migration breakage.
Ok, much clearer.
Quoted 12 lines
Quoted 12 lines
memory region is enabled when the improvement is applied, but it's disabled if the improvement isn't applied.
pa_bits = 40; vms->highmem_redists = false; vms->highmem_ecam = false; vms->highmem_mmio = true; # qemu-system-aarch64 -accel kvm -cpu host \ -machine virt-7.2 -m 4G,maxmem=511G \ -monitor stdio
Quoted 6 lines
Quoted 4 lines
In order to keep backwords compatibility, we need to disable the optimization on machines, which is virt-7.1 or ealier than it. It means the optimization is enabled by default from virt-7.2. Besides, 'highmem-compact' property is added so that the optimization can be
I would rather rename the property into compact-highmem even if the vms field is name
highmem_compactto align with other highmem fields
Ok, but I would love to know why. Note that we already have 'highmem=on|off'. 'highmem_compact=on|off' seems consistent to me.
Quoted 17 lines
Quoted 17 lines
explicitly enabled or disabled on all machine types by users.
Signed-off-by Gavin Shan <[email protected]>--- docs/system/arm/virt.rst | 4 ++++ hw/arm/virt.c | 33 +++++++++++++++++++++++++++++++++ include/hw/arm/virt.h | 2 ++ 3 files changed, 39 insertions(+)docs/system/arm/virt.rst +0
-0@@ -94,6 +94,10 @@ highmem address space above 32 bits. The default is ``on`` for machine types later than ``virt-2.12``.
Quoted 6 lines
docs/system/arm/virt.rst highmem · line 99
Quoted 3 lines
docs/system/arm/virt.rst +3
-0+highmem-compact + Set ``on``/``off`` to enable/disable compact space for high memory regions. + The default is ``on`` for machine types later than ``virt-7.2``I think you should document what is compact layout versus legacy one, both in the commit msg and maybe as a comment in a code along with the comment in
hw/arm/virt.cstarting with 'Highmem IO Regions: '
Ok, I will add this into the commit log in v4. I don't think it's necessary to add duplicate comment in the code. People can check the commit log for details if needed.
Quoted 8 lines
Quoted 8 lines
docs/system/arm/virt.rst +1
-0+ gic-version Specify the version of the Generic Interrupt Controller (GIC) to provide. Valid values are:hw/arm/virt.c +0
-0
Quoted 9 lines
hw/arm/virt.c static void virt_set_high_memmap(VirtMachineState *vms, · line 1738
Quoted 6 lines
hw/arm/virt.c +2
-0@@ -1734,6 +1734,13 @@ static void virt_set_high_memmap(VirtMachineState *vms, base = region_base + region_size; }else { *region_enabled = false; + +if (!vms->highmem_compact) {this snippet should be already present in previous patch otherwise this will break bisectability.
Hmm, nice catch! I think I need to swap PATCH[4] and PATCH[5] in next revision. In that order, 'compact-highmem' is introduced in PATCH[4], but not used yet. PATCH[5] has the optimization and 'compact-highmem' is used.
Quoted 76 lines
Quoted 76 lines
hw/arm/virt.c +31
-0+ base = region_base + region_size; +if (fits) { + vms->highest_gpa = region_base + region_size -1 ; + } + } } } }@@ -2348,6 +2355,20 @@ static void virt_set_highmem(Object *obj, bool value, Error **errp) vms->highmem = value; } +static bool virt_get_highmem_compact (Object *obj,Error **errp) +{ +VirtMachineState *vms =VIRT_MACHINE (obj); + +return vms->highmem_compact; +} + +static void virt_set_highmem_compact (Object *obj,bool value,Error **errp) +{ +VirtMachineState *vms =VIRT_MACHINE (obj); + + vms->highmem_compact = value; +} +static bool virt_get_its (Object *obj,Error **errp) {VirtMachineState *vms =VIRT_MACHINE (obj);@@ -2966,6 +2987,13 @@ static void virt_machine_class_init(ObjectClass *oc, void *data)"Set on/off to enable/disable using " "physical address space above 32 bits"); +object_class_property_add_bool (oc,"highmem-compact" , + virt_get_highmem_compact, + virt_set_highmem_compact); +object_class_property_set_description (oc,"highmem-compact" , +"Set on/off to enable/disable compact " +"space for high memory regions" ); +object_class_property_add_str (oc,"gic-version" , virt_get_gic_version, virt_set_gic_version); object_class_property_set_description(oc, "gic-version",@@ -3050,6 +3078,7 @@ static void virt_instance_init(Object *obj)/* High memory is enabled by default */ vms->highmem = true; + vms->highmem_compact = !vmc->no_highmem_compact; vms->gic_version =VIRT_GIC_VERSION_NOSEL ; vms->highmem_ecam = !vmc->no_highmem_ecam;@@ -3119,8 +3148,12 @@ DEFINE_VIRT_MACHINE_AS_LATEST(7, 2)static void virt_machine_7_1_options (MachineClass *mc) { +VirtMachineClass *vmc =VIRT_MACHINE_CLASS (OBJECT_CLASS (mc)); +virt_machine_7_2_options (mc);compat_props_add (mc->compat_props, hw_compat_7_1, hw_compat_7_1_len); +/* Compact space for high memory regions was introduced with 7.2 */ + vmc->no_highmem_compact = true; }DEFINE_VIRT_MACHINE (7 ,1 )include/hw/arm/virt.h +1
-0@@ -125,6 +125,7 @@ struct VirtMachineClass {bool no_pmu;bool claim_edge_triggered_timers;bool smbios_old_sys_ver; +bool no_highmem_compact;bool no_highmem_ecam;bool no_ged;/* Machines < 4.2 have no support for ACPI GED device */ bool kvm_no_adjvtime;
Quoted 9 lines
include/hw/arm/virt.h struct VirtMachineState { · line 151
Quoted 8 lines
include/hw/arm/virt.h +1
-0@@ -144,6 +145,7 @@ struct VirtMachineState {PFlashCFI01 *flash[2 ];bool secure;bool highmem; +bool highmem_compact;bool highmem_ecam;bool highmem_mmio;bool highmem_redists;
Thanks,
Gavin
Re: [PATCH v3 5/5] hw/arm/virt: Add 'highmem-compact' property
Quoted 27 lines · Gavin Shan
Hi Eric,
Quoted 5 lines · Eric Auger
Quoted 2 lines · Gavin Shan
After the improvement to high memory region address assignment is applied, the memory layout is changed. For example,
VIRT_HIGH_PCIE_MMIOs/the memory layout is changed./the memory layout is changed, introducing possible migration breakage.
Ok, much clearer.
Quoted 16 lines
Quoted 16 lines
memory region is enabled when the improvement is applied, but it's disabled if the improvement isn't applied.
pa_bits = 40; vms->highmem_redists = false; vms->highmem_ecam = false; vms->highmem_mmio = true; # qemu-system-aarch64 -accel kvm -cpu host \ -machine virt-7.2 -m 4G,maxmem=511G \ -monitor stdioIn order to keep backwords compatibility, we need to disable the optimization on machines, which is virt-7.1 or ealier than it. It means the optimization is enabled by default from virt-7.2. Besides, 'highmem-compact' property is added so that the optimization can be
Quoted 6 lines
Quoted 2 lines
I would rather rename the property into compact-highmem even if the vms field is name
highmem_compactto align with other highmem fieldsOk, but I would love to know why. Note that we already have 'highmem=on|off'. 'highmem_compact=on|off' seems consistent to me.
FWIW, I initially misread 'highmem_compact' as 'highmem_compat' (and had to re-read because I got confused). At least to me, 'compact_highmem' has less chance of being parsed incorrectly :) (although that is probably a personal thing.)
Quoted 25 lines
Quoted 18 lines
Quoted 18 lines
explicitly enabled or disabled on all machine types by users.
Signed-off-by Gavin Shan <[email protected]>--- docs/system/arm/virt.rst | 4 ++++ hw/arm/virt.c | 33 +++++++++++++++++++++++++++++++++ include/hw/arm/virt.h | 2 ++ 3 files changed, 39 insertions(+)docs/system/arm/virt.rst +0
-0@@ -94,6 +94,10 @@ highmem address space above 32 bits. The default is ``on`` for machine types later than ``virt-2.12``.Quoted 6 lines
docs/system/arm/virt.rst highmem · line 99
Quoted 3 lines
docs/system/arm/virt.rst +3
-0+highmem-compact + Set ``on``/``off`` to enable/disable compact space for high memory regions. + The default is ``on`` for machine types later than ``virt-7.2``I think you should document what is compact layout versus legacy one, both in the commit msg and maybe as a comment in a code along with the comment in
hw/arm/virt.cstarting with 'Highmem IO Regions: '
Quoted 3 lines
Ok, I will add this into the commit log in v4. I don't think it's necessary to add duplicate comment in the code. People can check the commit log for details if needed.
Rather explain it in this file here, maybe? I'd prefer to be able to find out what 'compact' means without digging through the commit log.
Re: [PATCH v3 5/5] hw/arm/virt: Add 'highmem-compact' property
Hi Cornelia,
Quoted 29 lines · Cornelia Huck
Quoted 28 lines · Gavin Shan
Quoted 5 lines · Eric Auger
Quoted 2 lines · Gavin Shan
After the improvement to high memory region address assignment is applied, the memory layout is changed. For example,
VIRT_HIGH_PCIE_MMIOs/the memory layout is changed./the memory layout is changed, introducing possible migration breakage.
Ok, much clearer.
Quoted 18 lines
Quoted 12 lines
memory region is enabled when the improvement is applied, but it's disabled if the improvement isn't applied.
pa_bits = 40; vms->highmem_redists = false; vms->highmem_ecam = false; vms->highmem_mmio = true; # qemu-system-aarch64 -accel kvm -cpu host \ -machine virt-7.2 -m 4G,maxmem=511G \ -monitor stdioQuoted 4 lines
In order to keep backwords compatibility, we need to disable the optimization on machines, which is virt-7.1 or ealier than it. It means the optimization is enabled by default from virt-7.2. Besides, 'highmem-compact' property is added so that the optimization can be
I would rather rename the property into compact-highmem even if the vms field is name
highmem_compactto align with other highmem fields
Quoted 9 lines
Quoted 3 lines
Ok, but I would love to know why. Note that we already have 'highmem=on|off'. 'highmem_compact=on|off' seems consistent to me.
FWIW, I initially misread '
highmem_compact' as 'highmem_compat' (and had to re-read because I got confused). At least to me, 'compact_highmem' has less chance of being parsed incorrectly :) (although that is probably a personal thing.)
Ok. 'compact-highmem' is also fine to me. I'm really bad at naming :)
Quoted 25 lines
Quoted 25 lines
Quoted 24 lines
Quoted 15 lines
explicitly enabled or disabled on all machine types by users.
Signed-off-by Gavin Shan <[email protected]>--- docs/system/arm/virt.rst | 4 ++++ hw/arm/virt.c | 33 +++++++++++++++++++++++++++++++++ include/hw/arm/virt.h | 2 ++ 3 files changed, 39 insertions(+)docs/system/arm/virt.rst +0
-0docs/system/arm/virt.rst highmem · line 99
Quoted 6 lines
docs/system/arm/virt.rst +3
-0@@ -94,6 +94,10 @@ highmem address space above 32 bits. The default is ``on`` for machine types later than ``virt-2.12``. +highmem-compact + Set ``on``/``off`` to enable/disable compact space for high memory regions. + The default is ``on`` for machine types later than ``virt-7.2``I think you should document what is compact layout versus legacy one, both in the commit msg and maybe as a comment in a code along with the comment in
hw/arm/virt.cstarting with 'Highmem IO Regions: '
Quoted 7 lines
Quoted 3 lines
Ok, I will add this into the commit log in v4. I don't think it's necessary to add duplicate comment in the code. People can check the commit log for details if needed.
Rather explain it in this file here, maybe? I'd prefer to be able to find out what 'compact' means without digging through the commit log.
Ok, lets do as Eric suggested. There are existing comments about @extended_memmap[] in hw/arm/virt.c. We need to explain the legacy/modern laoyout and 'compact-highmem' property there.
Thanks,
Gavin
Re: [PATCH v3 5/5] hw/arm/virt: Add 'highmem-compact' property
In reply to Gavin ShanHi Gavin,
Quoted 27 lines · Gavin Shan
Hi Eric,
Quoted 5 lines · Eric Auger
Quoted 2 lines · Gavin Shan
After the improvement to high memory region address assignment is applied, the memory layout is changed. For example,
VIRT_HIGH_PCIE_MMIOs/the memory layout is changed./the memory layout is changed, introducing possible migration breakage.
Ok, much clearer.
Quoted 16 lines
Quoted 16 lines
memory region is enabled when the improvement is applied, but it's disabled if the improvement isn't applied.
pa_bits = 40;
vms->highmem_redists= false;
vms->highmem_ecam = false;
vms->highmem_mmio = true;# qemu-system-aarch64 -accel kvm -cpu host \ -machine virt-7.2 -m 4G,maxmem=511G \ -monitor stdioIn order to keep backwords compatibility, we need to disable the optimization on machines, which is virt-7.1 or ealier than it. It means the optimization is enabled by default from virt-7.2. Besides, 'highmem-compact' property is added so that the optimization can be
Quoted 6 lines
Quoted 2 lines
I would rather rename the property into compact-highmem even if the vms field is name
highmem_compactto align with other highmem fieldsOk, but I would love to know why. Note that we already have 'highmem=on|off'. 'highmem_compact=on|off' seems consistent to me.
To me the property name should rather sound 'english' with the adjective before the name 'high memory"' but I am not a native english speaker either.
Quoted 51 lines
Quoted 10 lines
Quoted 10 lines
explicitly enabled or disabled on all machine types by users.
Signed-off-by Gavin Shan <[email protected]>---
docs/system/arm/virt.rst| 4 ++++
hw/arm/virt.c | 33 +++++++++++++++++++++++++++++++++ include/hw/arm/virt.h | 2 ++3 files changed, 39 insertions(+)Quoted 15 lines
Quoted 5 lines
docs/system/arm/virt.rst +0
-0@@ -94,6 +94,10 @@ highmemQuoted 7 lines
address space above 32 bits. The default is ``on`` for machine types
later than ``virt-2.12``.
+highmem-compact
+ Set ``on``/``off`` to enable/disable compact space for high memory regions.
+ The default is ``on`` for machine types later than ``virt-7.2``I think you should document what is compact layout versus legacy one, both in the commit msg and maybe as a comment in a code along with the comment in
hw/arm/virt.cstarting with 'Highmem IO Regions: 'Ok, I will add this into the commit log in v4. I don't think it's necessary
to add duplicate comment in the code. People can check the commit log for details if needed.Quoted 10 lines
Quoted 10 lines
+
gic-version
Specify the version of the Generic Interrupt Controller (GIC) to provide.
Valid values are:hw/arm/virt.c +0
-0@@ -1734,6 +1734,13 @@ static voidQuoted 9 lines
hw/arm/virt.c static void virt_set_high_memmap(VirtMachineState *vms, · line 1738
Quoted 6 lines
hw/arm/virt.c +2
-0virt_set_high_memmap(VirtMachineState *vms, base = region_base + region_size; } else { *region_enabled = false; + + if (!vms->highmem_compact) {this snippet should be already present in previous patch otherwise this will break bisectability.
Quoted 4 lines
Hmm, nice catch! I think I need to swap PATCH[4] and PATCH[5] in next revision. In that order, 'compact-highmem' is introduced in PATCH[4], but not used yet. PATCH[5] has the optimization and 'compact-highmem' is used.
No in general you introduce the property at the very end with the code guarded with an unset vms->highmem_compact in the previous patch.
Thanks
Eric
Quoted 95 lines
Quoted 82 lines
Quoted 82 lines
hw/arm/virt.c +5
-0+ base = region_base + region_size; + if (fits) { + vms->highest_gpa = region_base + region_size - 1; + } + } } }}
hw/arm/virt.c +13
-0@@ -2348,6 +2355,20 @@ static void virt_set_highmem(Object *obj, bool value, Error **errp) vms->highmem = value; } +static bool virt_get_highmem_compact(Object *obj, Error **errp) +{ + VirtMachineState *vms = VIRT_MACHINE(obj); + + return vms->highmem_compact; +} + +static void virt_set_highmem_compact (Object *obj,bool value,Error **errp) +{ + VirtMachineState *vms = VIRT_MACHINE(obj); + + vms->highmem_compact = value; +} + static bool virt_get_its(Object *obj, Error **errp){
VirtMachineState *vms =VIRT_MACHINE(obj);hw/arm/virt.c +0
-0@@ -2966,6 +2987,13 @@ static voidvirt_machine_class_init (ObjectClass *oc, void *data)"Set on/off to enable/disable using "
"physical address space above 32 bits");
+ object_class_property_add_bool(oc, "highmem-compact", +virt_get_highmem_compact, +virt_set_highmem_compact); + object_class_property_set_description(oc, "highmem-compact", + "Set on/off to enable/disable compact "
+ "space for high memory regions");
+
object_class_property_add_str(oc, "gic-version",virt_get_gic_version,
virt_set_gic_version); object_class_property_set_description(oc, "gic-version",hw/arm/virt.c +4
-0@@ -3050,6 +3078,7 @@ static void virt_instance_init(Object *obj) /* High memory is enabled by default */ vms->highmem = true; + vms->highmem_compact = !vmc->no_highmem_compact; vms->gic_version = VIRT_GIC_VERSION_NOSEL; vms->highmem_ecam = !vmc->no_highmem_ecam;@@ -3119,8 +3148,12 @@ DEFINE_VIRT_MACHINE_AS_LATEST(7, 2) static void virt_machine_7_1_options(MachineClass *mc) { + VirtMachineClass *vmc = VIRT_MACHINE_CLASS(OBJECT_CLASS(mc)); + virt_machine_7_2_options(mc); compat_props_add(mc->compat_props, hw_compat_7_1, hw_compat_7_1_len); + /* Compact space for high memory regions was introduced with7.2 */
+vmc->no_highmem_compact= true;
}
DEFINE_VIRT_MACHINE(7, 1)
diff --gita/include/hw/arm/virt.hb/include/hw/arm/virt.hindex6ec479ca2b..c7dd59d7f1100644include/hw/arm/virt.h +1
-0@@ -125,6 +125,7 @@ struct VirtMachineClass { bool no_pmu; bool claim_edge_triggered_timers; bool smbios_old_sys_ver; + bool no_highmem_compact; bool no_highmem_ecam;bool no_ged; /* Machines < 4.2 have no support for ACPI GED device */
boolkvm_no_adjvtime;Quoted 9 lines
include/hw/arm/virt.h struct VirtMachineState { · line 151
Quoted 8 lines
include/hw/arm/virt.h +1
-0@@ -144,6 +145,7 @@ struct VirtMachineState { PFlashCFI01 *flash[2]; bool secure; bool highmem; + bool highmem_compact; bool highmem_ecam; bool highmem_mmio; bool highmem_redists;Thanks,
Gavin
Re: [PATCH v3 5/5] hw/arm/virt: Add 'highmem-compact' property
Hi Eric,
Quoted 29 lines · Eric Auger
Quoted 28 lines · Gavin Shan
Quoted 5 lines · Eric Auger
Quoted 2 lines · Gavin Shan
After the improvement to high memory region address assignment is applied, the memory layout is changed. For example,
VIRT_HIGH_PCIE_MMIOs/the memory layout is changed./the memory layout is changed, introducing possible migration breakage.
Ok, much clearer.
Quoted 18 lines
Quoted 8 lines
memory region is enabled when the improvement is applied, but it's disabled if the improvement isn't applied.
pa_bits = 40;
vms->highmem_redists= false;
vms->highmem_ecam = false;
vms->highmem_mmio = true;Quoted 8 lines
# qemu-system-aarch64 -accel kvm -cpu host \ -machine virt-7.2 -m 4G,maxmem=511G \ -monitor stdioIn order to keep backwords compatibility, we need to disable the optimization on machines, which is virt-7.1 or ealier than it. It means the optimization is enabled by default from virt-7.2. Besides, 'highmem-compact' property is added so that the optimization can be
I would rather rename the property into compact-highmem even if the vms field is name
highmem_compactto align with other highmem fields
Quoted 6 lines
Quoted 3 lines
Ok, but I would love to know why. Note that we already have 'highmem=on|off'. 'highmem_compact=on|off' seems consistent to me.
To me the property name should rather sound 'english' with the adjective before the name 'high memory"' but I am not a native english speaker either.
Ok. I agree 'compact-highmem' is better. The backup variable name will be still 'highmem_compact', which is consistent with the existing ones.
Quoted 51 lines
Quoted 51 lines
Quoted 10 lines
Quoted 10 lines
explicitly enabled or disabled on all machine types by users.
Signed-off-by Gavin Shan <[email protected]>--- docs/system/arm/virt.rst | 4 ++++ hw/arm/virt.c | 33 +++++++++++++++++++++++++++++++++ include/hw/arm/virt.h | 2 ++ 3 files changed, 39 insertions(+)Quoted 15 lines
Quoted 6 lines
docs/system/arm/virt.rst +0
-0@@ -94,6 +94,10 @@ highmem address space above 32 bits. The default is ``on`` for machineQuoted 6 lines
types
later than ``virt-2.12``.
+highmem-compact
+ Set ``on``/``off`` to enable/disable compact space for high memory regions.
+ The default is ``on`` for machine types later than ``virt-7.2``I think you should document what is compact layout versus legacy one, both in the commit msg and maybe as a comment in a code along with the comment in
hw/arm/virt.cstarting with 'Highmem IO Regions: 'Ok, I will add this into the commit log in v4. I don't think it's necessary
to add duplicate comment in the code. People can check the commit log for details if needed.Quoted 19 lines
Quoted 10 lines
+
gic-version
Specify the version of the Generic Interrupt Controller (GIC) to
provide.
Valid values are:hw/arm/virt.c +0
-0hw/arm/virt.c static void · line 1739
Quoted 6 lines
hw/arm/virt.c +2
-0@@ -1734,6 +1734,13 @@ static void virt_set_high_memmap(VirtMachineState *vms, base = region_base + region_size; } else { *region_enabled = false; + + if (!vms->highmem_compact) {this snippet should be already present in previous patch otherwise this will break bisectability.
Quoted 7 lines
Quoted 4 lines
Hmm, nice catch! I think I need to swap PATCH[4] and PATCH[5] in next revision. In that order, 'compact-highmem' is introduced in PATCH[4], but not used yet. PATCH[5] has the optimization and 'compact-highmem' is used.
No in general you introduce the property at the very end with the code guarded with an unset
vms->highmem_compactin the previous patch.
Yeah, what I need is define 'vms->highmem_compact' in PATCH[v3 4/5], whose value is false. I also need to update @base and @vms->highest_gpa on !vms->highmem_compact' in PATCH[v3 4/5].
Quoted 83 lines
Quoted 83 lines
Quoted 83 lines
Quoted 83 lines
hw/arm/virt.c +5
-0+ base = region_base + region_size; + if (fits) { + vms->highest_gpa = region_base + region_size - 1; + } + } } }}
hw/arm/virt.c +13
-0@@ -2348,6 +2355,20 @@ static void virt_set_highmem(Object *obj, bool value, Error **errp) vms->highmem = value; } +static bool virt_get_highmem_compact(Object *obj, Error **errp) +{ + VirtMachineState *vms = VIRT_MACHINE(obj); + + return vms->highmem_compact; +} + +static void virt_set_highmem_compact (Object *obj,bool value,Error **errp) +{ + VirtMachineState *vms = VIRT_MACHINE(obj); + + vms->highmem_compact = value; +} + static bool virt_get_its(Object *obj, Error **errp) { VirtMachineState *vms = VIRT_MACHINE(obj);@@ -2966,6 +2987,13 @@ static void virt_machine_class_init(ObjectClass *oc, void *data) "Set on/off toenable/disable using "
"physical address space
above 32 bits");
+ object_class_property_add_bool(oc, "highmem-compact",
+virt_get_highmem_compact, +virt_set_highmem_compact); + object_class_property_set_description(oc, "highmem-compact", + "Set on/off to enable/disable compact "
+ "space for high memory regions");
+
object_class_property_add_str(oc, "gic-version",virt_get_gic_version,
virt_set_gic_version); object_class_property_set_description(oc, "gic-version",hw/arm/virt.c +4
-0@@ -3050,6 +3078,7 @@ static void virt_instance_init(Object *obj) /* High memory is enabled by default */ vms->highmem = true; + vms->highmem_compact = !vmc->no_highmem_compact; vms->gic_version = VIRT_GIC_VERSION_NOSEL; vms->highmem_ecam = !vmc->no_highmem_ecam;@@ -3119,8 +3148,12 @@ DEFINE_VIRT_MACHINE_AS_LATEST(7, 2) static void virt_machine_7_1_options(MachineClass *mc) { + VirtMachineClass *vmc = VIRT_MACHINE_CLASS(OBJECT_CLASS(mc)); + virt_machine_7_2_options(mc); compat_props_add(mc->compat_props, hw_compat_7_1, hw_compat_7_1_len); + /* Compact space for high memory regions was introduced with7.2 */
+vmc->no_highmem_compact= true;
}
DEFINE_VIRT_MACHINE(7, 1)
diff --gita/include/hw/arm/virt.hb/include/hw/arm/virt.h
index6ec479ca2b..c7dd59d7f1100644include/hw/arm/virt.h +1
-0@@ -125,6 +125,7 @@ struct VirtMachineClass { bool no_pmu; bool claim_edge_triggered_timers; bool smbios_old_sys_ver; + bool no_highmem_compact; bool no_highmem_ecam; bool no_ged; /* Machines < 4.2 have no support for ACPI GEDdevice */
boolkvm_no_adjvtime;include/hw/arm/virt.h +0
-0@@ -144,6 +145,7 @@ struct VirtMachineState {
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
include/hw/arm/virt.h struct VirtMachineState { · line 151
Quoted 7 lines
include/hw/arm/virt.h +1
-0PFlashCFI01 *flash[2]; bool secure; bool highmem; + bool highmem_compact; bool highmem_ecam; bool highmem_mmio; bool highmem_redists;
Thanks,
Gavin
[PATCH v3 0/5] hw/arm/virt: Improve address assignment for high memory regions
Author: Gavin Shan <[email protected]> Date: Thu Sep 22 07:13:45 2022 +0800
PATCH[1-3] preparatory work for the improvment
PATCH[4] improve high memory region address assignment
PATCH[5] adds 'highmem-compact' to enable or disable the optimization
The patchs works well on "IPA Size Limit: 40" FUJITSU machine. I added some debug code to show high memory region address. The test results are as expected.
1. virt-7.2 default
# /home/qemu/build/qemu-system-aarch64 -accel kvm -cpu host -machine virt-7.2 -m 4G,maxmem=511G -monitor stdio =====> virt_set_high_memmap: pa_bits=40, base=0x8000000000 [HIGH_GIC_REDIST2]: disabled, highest_gpa=0x7fffffffff [no] [yes] [HIGH_PCIE_ECAM]: disabled, highest_gpa=0x7fffffffff [no] [yes] [HIGH_PCIE_MMIO] enabled, highest_gpa=0xffffffffff
2. When virt-7.2,highmem-compact=off
# /home/qemu/build/qemu-system-aarch64 -accel kvm -cpu host -machine virt-7.2,highmem-compact=off -m 4G,maxmem=511G -monitor stdio =====> virt_set_high_memmap: pa_bits=40, base=0x8000000000 [HIGH_GIC_REDIST2]: disabled, highest_gpa=0x8003ffffff [no] [yes] [HIGH_PCIE_ECAM]: disabled, highest_gpa=0x801fffffff [no] [yes] [HIGH_PCIE_MMIO]: disabled, highest_gpa=0x801fffffff [no] [no]
3. virt-7.1 default
# /home/qemu/build/qemu-system-aarch64 -accel kvm -cpu host -machine virt-7.1 -m 4G,maxmem=511G -monitor stdio =====> virt_set_high_memmap: pa_bits=40, base=0x8000000000 [HIGH_GIC_REDIST2]: disabled, highest_gpa=0x8003ffffff [no] [yes] [HIGH_PCIE_ECAM]: disabled, highest_gpa=0x801fffffff [no] [yes] [HIGH_PCIE_MMIO]: disabled, highest_gpa=0x801fffffff [no] [no]
2. When virt-7.1,highmem-compact=on
# /home/qemu/build/qemu-system-aarch64 -accel kvm -cpu host -machine virt-7.1,highmem-compact=on -m 4G,maxmem=511G -monitor stdio =====> virt_set_high_memmap: pa_bits=40, base=0x8000000000 [HIGH_GIC_REDIST2]: disabled, highest_gpa=0x7fffffffff [no] [yes] [HIGH_PCIE_ECAM]: disabled, highest_gpa=0x7fffffffff [no] [yes] [HIGH_PCIE_MMIO] enabled, highest_gpa=0xffffffffff
Quoted 63 lines · Gavin Shan
There are three high memory regions, which are
VIRT_HIGH_REDIST2,VIRT_HIGH_PCIE_ECAMandVIRT_HIGH_PCIE_MMIO. Their base addresses are floating on highest RAM address. However, they can be disabled in several cases.(1) One specific high memory region is disabled by developer by
toggling vms->highmem_{redists, ecam, mmio}.(2)
VIRT_HIGH_PCIE_ECAMregion is disabled on machine, which is'virt-2.12' or ealier than it.(3)
VIRT_HIGH_PCIE_ECAMregion is disabled when firmware is loaded on 32-bits system.(4) One specific high memory region is disabled when it breaks the PA space limit.
The current implementation of
virt_set_memmap()isn't comprehensive because the space for one specific high memory region is always reserved from the PA space for case (1), (2) and (3). In the code, 'base' and 'vms->highest_gpa' are always increased for those three cases. It's unnecessary since the assigned space of the disabled high memory region won't be used afterwards.The series intends to improve the address assignment for these high memory regions.
PATCH[1-3] preparatory work for the improvment
PATCH[4] improve high memory region address assignment
PATCH[5] adds 'highmem-compact' to enable or disable the optimizationHistory
=======
v2: https://lore.kernel.org/all/[email protected]/T/
v1: https://lists.nongnu.org/archive/html/qemu-arm/2022-08/msg00013.htmlChangelog
==========
v3:
* Reorder the patches (Gavin)
* Add 'highmem-compact' property for backwards compatibility (Eric)
v2:* Split the patches for easier review (Gavin) * Improved changelog (Marc) * Use 'bool fits' in virt_set_high_memmap() (Eric)Gavin Shan (5):
hw/arm/virt: Introducevirt_set_high_memmap()helper hw/arm/virt: Rename variable size toregion_sizein
virt_set_high_memmap()
hw/arm/virt: Introduce variableregion_baseinvirt_set_high_memmap()hw/arm/virt: Improve high memory region address assignment hw/arm/virt: Add 'highmem-compact' propertydocs/system/arm/virt.rst | 4 ++ hw/arm/virt.c | 116 ++++++++++++++++++++++++++++----------- include/hw/arm/virt.h | 2 + 3 files changed, 89 insertions(+), 33 deletions(-)--
2.23.0