[PATCH v3 0/5] hw/arm/virt: Improve address assignment for high memory regions

Gavin Shan posted 5 patches 1 week ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20220921231349.274049-1-gshan@redhat.com
Maintainers: Peter Maydell <peter.maydell@linaro.org>
docs/system/arm/virt.rst |   4 ++
hw/arm/virt.c            | 116 ++++++++++++++++++++++++++++-----------
include/hw/arm/virt.h    |   2 +
3 files changed, 89 insertions(+), 33 deletions(-)
[PATCH v3 0/5] hw/arm/virt: Improve address assignment for high memory regions
Posted by Gavin Shan 1 week ago
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/20220815062958.100366-1-gshan@redhat.com/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(-)

-- 
2.23.0
Re: [PATCH v3 0/5] hw/arm/virt: Improve address assignment for high memory regions
Posted by Zhenyu Zhang 1 week ago
[PATCH v3 0/5] hw/arm/virt: Improve address assignment for high memory regions
Author: Gavin Shan <gshan@redhat.com>
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

    Signed-off-by: Gavin Shan <gshan@redhat.com>

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


Tested-by: Zhenyu Zhang<zhenyzha@redhat.com>

On Thu, Sep 22, 2022 at 7:13 AM Gavin Shan <gshan@redhat.com> wrote:
>
> 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/20220815062958.100366-1-gshan@redhat.com/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(-)
>
> --
> 2.23.0
>