All of lore.kernel.org
 help / color / mirror / Atom feed
From: Marc Zyngier <maz@kernel.org>
To: eric.auger@redhat.com
Cc: qemu-devel@nongnu.org, kvmarm@lists.cs.columbia.edu,
	kvm@vger.kernel.org, kernel-team@android.com,
	Andrew Jones <drjones@redhat.com>,
	Peter Maydell <peter.maydell@linaro.org>
Subject: Re: [PATCH v4 4/6] hw/arm/virt: Use the PA range to compute the memory map
Date: Mon, 10 Jan 2022 15:58:33 +0000	[thread overview]
Message-ID: <87ilurtweu.wl-maz@kernel.org> (raw)
In-Reply-To: <d7f793ab-bf78-32fb-e793-54a034ffd5d8@redhat.com>

On Mon, 10 Jan 2022 15:38:56 +0000,
Eric Auger <eric.auger@redhat.com> wrote:
> 
> Hi Marc,
> 
> On 1/7/22 5:33 PM, Marc Zyngier wrote:
> > The highmem attribute is nothing but another way to express the
> > PA range of a VM. To support HW that has a smaller PA range then
> > what QEMU assumes, pass this PA range to the virt_set_memmap()
> > function, allowing it to correctly exclude highmem devices
> > if they are outside of the PA range.
> >
> > Signed-off-by: Marc Zyngier <maz@kernel.org>
> > ---
> >  hw/arm/virt.c | 53 ++++++++++++++++++++++++++++++++++++++++++++-------
> >  1 file changed, 46 insertions(+), 7 deletions(-)
> >
> > diff --git a/hw/arm/virt.c b/hw/arm/virt.c
> > index 57c55e8a37..db4b0636e1 100644
> > --- a/hw/arm/virt.c
> > +++ b/hw/arm/virt.c
> > @@ -1660,7 +1660,7 @@ static uint64_t virt_cpu_mp_affinity(VirtMachineState *vms, int idx)
> >      return arm_cpu_mp_affinity(idx, clustersz);
> >  }
> >  
> > -static void virt_set_memmap(VirtMachineState *vms)
> > +static void virt_set_memmap(VirtMachineState *vms, int pa_bits)
> >  {
> >      MachineState *ms = MACHINE(vms);
> >      hwaddr base, device_memory_base, device_memory_size, memtop;
> > @@ -1678,6 +1678,13 @@ static void virt_set_memmap(VirtMachineState *vms)
> >          exit(EXIT_FAILURE);
> >      }
> >  
> > +    /*
> > +     * !highmem is exactly the same as limiting the PA space to 32bit,
> > +     * irrespective of the underlying capabilities of the HW.
> > +     */
> > +    if (!vms->highmem)
> > +	    pa_bits = 32;
> you need {} according to the QEMU coding style. Welcome to a new shiny
> world :-)

Yeah. Between the reduced indentation and the avalanche of braces, my
brain fails to pattern-match blocks of code. Amusing how inflexible
you become after a couple of decades...

> > +
> >      /*
> >       * We compute the base of the high IO region depending on the
> >       * amount of initial and device memory. The device memory start/size
> > @@ -1691,8 +1698,9 @@ static void virt_set_memmap(VirtMachineState *vms)
> >  
> >      /* Base address of the high IO region */
> >      memtop = base = device_memory_base + ROUND_UP(device_memory_size, GiB);
> > -    if (!vms->highmem && memtop > 4 * GiB) {
> > -        error_report("highmem=off, but memory crosses the 4GiB limit\n");
> > +    if (memtop > BIT_ULL(pa_bits)) {
> > +	    error_report("Addressing limited to %d bits, but memory exceeds it by %llu bytes\n",
> > +			 pa_bits, memtop - BIT_ULL(pa_bits));
> >          exit(EXIT_FAILURE);
> >      }
> >      if (base < device_memory_base) {
> > @@ -1711,7 +1719,13 @@ static void virt_set_memmap(VirtMachineState *vms)
> >          vms->memmap[i].size = size;
> >          base += size;
> >      }
> > -    vms->highest_gpa = (vms->highmem ? base : memtop) - 1;
> > +
> > +    /*
> > +     * If base fits within pa_bits, all good. If it doesn't, limit it
> > +     * to the end of RAM, which is guaranteed to fit within pa_bits.
> > +     */
> > +    vms->highest_gpa = (base <= BIT_ULL(pa_bits) ? base : memtop) - 1;
> > +
> >      if (device_memory_size > 0) {
> >          ms->device_memory = g_malloc0(sizeof(*ms->device_memory));
> >          ms->device_memory->base = device_memory_base;
> > @@ -1902,12 +1916,38 @@ static void machvirt_init(MachineState *machine)
> >      unsigned int smp_cpus = machine->smp.cpus;
> >      unsigned int max_cpus = machine->smp.max_cpus;
> Move the cpu_type check before?
> 
>     if (!cpu_type_valid(machine->cpu_type)) {
>         error_report("mach-virt: CPU type %s not supported",
> machine->cpu_type);
>         exit(1);
>     }
> >

Yes, very good point. I wonder why this was tucked away past
computing the memory map and the GIC configuration... Anyway, I'll
move it up.

Thanks,

	M.

-- 
Without deviation from the norm, progress is not possible.

WARNING: multiple messages have this Message-ID (diff)
From: Marc Zyngier <maz@kernel.org>
To: eric.auger@redhat.com
Cc: kvm@vger.kernel.org, qemu-devel@nongnu.org,
	kernel-team@android.com, kvmarm@lists.cs.columbia.edu
Subject: Re: [PATCH v4 4/6] hw/arm/virt: Use the PA range to compute the memory map
Date: Mon, 10 Jan 2022 15:58:33 +0000	[thread overview]
Message-ID: <87ilurtweu.wl-maz@kernel.org> (raw)
In-Reply-To: <d7f793ab-bf78-32fb-e793-54a034ffd5d8@redhat.com>

On Mon, 10 Jan 2022 15:38:56 +0000,
Eric Auger <eric.auger@redhat.com> wrote:
> 
> Hi Marc,
> 
> On 1/7/22 5:33 PM, Marc Zyngier wrote:
> > The highmem attribute is nothing but another way to express the
> > PA range of a VM. To support HW that has a smaller PA range then
> > what QEMU assumes, pass this PA range to the virt_set_memmap()
> > function, allowing it to correctly exclude highmem devices
> > if they are outside of the PA range.
> >
> > Signed-off-by: Marc Zyngier <maz@kernel.org>
> > ---
> >  hw/arm/virt.c | 53 ++++++++++++++++++++++++++++++++++++++++++++-------
> >  1 file changed, 46 insertions(+), 7 deletions(-)
> >
> > diff --git a/hw/arm/virt.c b/hw/arm/virt.c
> > index 57c55e8a37..db4b0636e1 100644
> > --- a/hw/arm/virt.c
> > +++ b/hw/arm/virt.c
> > @@ -1660,7 +1660,7 @@ static uint64_t virt_cpu_mp_affinity(VirtMachineState *vms, int idx)
> >      return arm_cpu_mp_affinity(idx, clustersz);
> >  }
> >  
> > -static void virt_set_memmap(VirtMachineState *vms)
> > +static void virt_set_memmap(VirtMachineState *vms, int pa_bits)
> >  {
> >      MachineState *ms = MACHINE(vms);
> >      hwaddr base, device_memory_base, device_memory_size, memtop;
> > @@ -1678,6 +1678,13 @@ static void virt_set_memmap(VirtMachineState *vms)
> >          exit(EXIT_FAILURE);
> >      }
> >  
> > +    /*
> > +     * !highmem is exactly the same as limiting the PA space to 32bit,
> > +     * irrespective of the underlying capabilities of the HW.
> > +     */
> > +    if (!vms->highmem)
> > +	    pa_bits = 32;
> you need {} according to the QEMU coding style. Welcome to a new shiny
> world :-)

Yeah. Between the reduced indentation and the avalanche of braces, my
brain fails to pattern-match blocks of code. Amusing how inflexible
you become after a couple of decades...

> > +
> >      /*
> >       * We compute the base of the high IO region depending on the
> >       * amount of initial and device memory. The device memory start/size
> > @@ -1691,8 +1698,9 @@ static void virt_set_memmap(VirtMachineState *vms)
> >  
> >      /* Base address of the high IO region */
> >      memtop = base = device_memory_base + ROUND_UP(device_memory_size, GiB);
> > -    if (!vms->highmem && memtop > 4 * GiB) {
> > -        error_report("highmem=off, but memory crosses the 4GiB limit\n");
> > +    if (memtop > BIT_ULL(pa_bits)) {
> > +	    error_report("Addressing limited to %d bits, but memory exceeds it by %llu bytes\n",
> > +			 pa_bits, memtop - BIT_ULL(pa_bits));
> >          exit(EXIT_FAILURE);
> >      }
> >      if (base < device_memory_base) {
> > @@ -1711,7 +1719,13 @@ static void virt_set_memmap(VirtMachineState *vms)
> >          vms->memmap[i].size = size;
> >          base += size;
> >      }
> > -    vms->highest_gpa = (vms->highmem ? base : memtop) - 1;
> > +
> > +    /*
> > +     * If base fits within pa_bits, all good. If it doesn't, limit it
> > +     * to the end of RAM, which is guaranteed to fit within pa_bits.
> > +     */
> > +    vms->highest_gpa = (base <= BIT_ULL(pa_bits) ? base : memtop) - 1;
> > +
> >      if (device_memory_size > 0) {
> >          ms->device_memory = g_malloc0(sizeof(*ms->device_memory));
> >          ms->device_memory->base = device_memory_base;
> > @@ -1902,12 +1916,38 @@ static void machvirt_init(MachineState *machine)
> >      unsigned int smp_cpus = machine->smp.cpus;
> >      unsigned int max_cpus = machine->smp.max_cpus;
> Move the cpu_type check before?
> 
>     if (!cpu_type_valid(machine->cpu_type)) {
>         error_report("mach-virt: CPU type %s not supported",
> machine->cpu_type);
>         exit(1);
>     }
> >

Yes, very good point. I wonder why this was tucked away past
computing the memory map and the GIC configuration... Anyway, I'll
move it up.

Thanks,

	M.

-- 
Without deviation from the norm, progress is not possible.
_______________________________________________
kvmarm mailing list
kvmarm@lists.cs.columbia.edu
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm

WARNING: multiple messages have this Message-ID (diff)
From: Marc Zyngier <maz@kernel.org>
To: eric.auger@redhat.com
Cc: Peter Maydell <peter.maydell@linaro.org>,
	Andrew Jones <drjones@redhat.com>,
	kvm@vger.kernel.org, qemu-devel@nongnu.org,
	kernel-team@android.com, kvmarm@lists.cs.columbia.edu
Subject: Re: [PATCH v4 4/6] hw/arm/virt: Use the PA range to compute the memory map
Date: Mon, 10 Jan 2022 15:58:33 +0000	[thread overview]
Message-ID: <87ilurtweu.wl-maz@kernel.org> (raw)
In-Reply-To: <d7f793ab-bf78-32fb-e793-54a034ffd5d8@redhat.com>

On Mon, 10 Jan 2022 15:38:56 +0000,
Eric Auger <eric.auger@redhat.com> wrote:
> 
> Hi Marc,
> 
> On 1/7/22 5:33 PM, Marc Zyngier wrote:
> > The highmem attribute is nothing but another way to express the
> > PA range of a VM. To support HW that has a smaller PA range then
> > what QEMU assumes, pass this PA range to the virt_set_memmap()
> > function, allowing it to correctly exclude highmem devices
> > if they are outside of the PA range.
> >
> > Signed-off-by: Marc Zyngier <maz@kernel.org>
> > ---
> >  hw/arm/virt.c | 53 ++++++++++++++++++++++++++++++++++++++++++++-------
> >  1 file changed, 46 insertions(+), 7 deletions(-)
> >
> > diff --git a/hw/arm/virt.c b/hw/arm/virt.c
> > index 57c55e8a37..db4b0636e1 100644
> > --- a/hw/arm/virt.c
> > +++ b/hw/arm/virt.c
> > @@ -1660,7 +1660,7 @@ static uint64_t virt_cpu_mp_affinity(VirtMachineState *vms, int idx)
> >      return arm_cpu_mp_affinity(idx, clustersz);
> >  }
> >  
> > -static void virt_set_memmap(VirtMachineState *vms)
> > +static void virt_set_memmap(VirtMachineState *vms, int pa_bits)
> >  {
> >      MachineState *ms = MACHINE(vms);
> >      hwaddr base, device_memory_base, device_memory_size, memtop;
> > @@ -1678,6 +1678,13 @@ static void virt_set_memmap(VirtMachineState *vms)
> >          exit(EXIT_FAILURE);
> >      }
> >  
> > +    /*
> > +     * !highmem is exactly the same as limiting the PA space to 32bit,
> > +     * irrespective of the underlying capabilities of the HW.
> > +     */
> > +    if (!vms->highmem)
> > +	    pa_bits = 32;
> you need {} according to the QEMU coding style. Welcome to a new shiny
> world :-)

Yeah. Between the reduced indentation and the avalanche of braces, my
brain fails to pattern-match blocks of code. Amusing how inflexible
you become after a couple of decades...

> > +
> >      /*
> >       * We compute the base of the high IO region depending on the
> >       * amount of initial and device memory. The device memory start/size
> > @@ -1691,8 +1698,9 @@ static void virt_set_memmap(VirtMachineState *vms)
> >  
> >      /* Base address of the high IO region */
> >      memtop = base = device_memory_base + ROUND_UP(device_memory_size, GiB);
> > -    if (!vms->highmem && memtop > 4 * GiB) {
> > -        error_report("highmem=off, but memory crosses the 4GiB limit\n");
> > +    if (memtop > BIT_ULL(pa_bits)) {
> > +	    error_report("Addressing limited to %d bits, but memory exceeds it by %llu bytes\n",
> > +			 pa_bits, memtop - BIT_ULL(pa_bits));
> >          exit(EXIT_FAILURE);
> >      }
> >      if (base < device_memory_base) {
> > @@ -1711,7 +1719,13 @@ static void virt_set_memmap(VirtMachineState *vms)
> >          vms->memmap[i].size = size;
> >          base += size;
> >      }
> > -    vms->highest_gpa = (vms->highmem ? base : memtop) - 1;
> > +
> > +    /*
> > +     * If base fits within pa_bits, all good. If it doesn't, limit it
> > +     * to the end of RAM, which is guaranteed to fit within pa_bits.
> > +     */
> > +    vms->highest_gpa = (base <= BIT_ULL(pa_bits) ? base : memtop) - 1;
> > +
> >      if (device_memory_size > 0) {
> >          ms->device_memory = g_malloc0(sizeof(*ms->device_memory));
> >          ms->device_memory->base = device_memory_base;
> > @@ -1902,12 +1916,38 @@ static void machvirt_init(MachineState *machine)
> >      unsigned int smp_cpus = machine->smp.cpus;
> >      unsigned int max_cpus = machine->smp.max_cpus;
> Move the cpu_type check before?
> 
>     if (!cpu_type_valid(machine->cpu_type)) {
>         error_report("mach-virt: CPU type %s not supported",
> machine->cpu_type);
>         exit(1);
>     }
> >

Yes, very good point. I wonder why this was tucked away past
computing the memory map and the GIC configuration... Anyway, I'll
move it up.

Thanks,

	M.

-- 
Without deviation from the norm, progress is not possible.


  reply	other threads:[~2022-01-10 15:58 UTC|newest]

Thread overview: 54+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-07 16:33 [PATCH v4 0/6] target/arm: Reduced-IPA space and highmem fixes Marc Zyngier
2022-01-07 16:33 ` Marc Zyngier
2022-01-07 16:33 ` Marc Zyngier
2022-01-07 16:33 ` [PATCH v4 1/6] hw/arm/virt: Add a control for the the highmem PCIe MMIO Marc Zyngier
2022-01-07 16:33   ` Marc Zyngier
2022-01-07 16:33   ` Marc Zyngier
2022-01-07 16:33 ` [PATCH v4 2/6] hw/arm/virt: Add a control for the the highmem redistributors Marc Zyngier
2022-01-07 16:33   ` Marc Zyngier
2022-01-07 16:33   ` Marc Zyngier
2022-01-10 15:35   ` Eric Auger
2022-01-10 15:35     ` Eric Auger
2022-01-10 15:35     ` Eric Auger
2022-01-10 15:45     ` Marc Zyngier
2022-01-10 15:45       ` Marc Zyngier
2022-01-10 15:45       ` Marc Zyngier
2022-01-10 15:47       ` Peter Maydell
2022-01-10 15:47         ` Peter Maydell
2022-01-10 15:47         ` Peter Maydell
2022-01-10 16:02         ` Marc Zyngier
2022-01-10 16:02           ` Marc Zyngier
2022-01-10 16:02           ` Marc Zyngier
2022-01-10 15:48       ` Eric Auger
2022-01-10 15:48         ` Eric Auger
2022-01-10 15:48         ` Eric Auger
2022-01-07 16:33 ` [PATCH v4 3/6] hw/arm/virt: Honor highmem setting when computing the memory map Marc Zyngier
2022-01-07 16:33   ` Marc Zyngier
2022-01-07 16:33   ` Marc Zyngier
2022-01-10 15:30   ` Eric Auger
2022-01-10 15:30     ` Eric Auger
2022-01-10 15:30     ` Eric Auger
2022-01-07 16:33 ` [PATCH v4 4/6] hw/arm/virt: Use the PA range to compute " Marc Zyngier
2022-01-07 16:33   ` Marc Zyngier
2022-01-07 16:33   ` Marc Zyngier
2022-01-10 15:38   ` Eric Auger
2022-01-10 15:38     ` Eric Auger
2022-01-10 15:38     ` Eric Auger
2022-01-10 15:58     ` Marc Zyngier [this message]
2022-01-10 15:58       ` Marc Zyngier
2022-01-10 15:58       ` Marc Zyngier
2022-01-07 16:33 ` [PATCH v4 5/6] hw/arm/virt: Disable highmem devices that don't fit in the PA range Marc Zyngier
2022-01-07 16:33   ` Marc Zyngier
2022-01-07 16:33   ` Marc Zyngier
2022-01-10 17:12   ` Eric Auger
2022-01-10 17:12     ` Eric Auger
2022-01-10 17:12     ` Eric Auger
2022-01-10 18:51     ` Marc Zyngier
2022-01-10 18:51       ` Marc Zyngier
2022-01-10 18:51       ` Marc Zyngier
2022-01-07 16:33 ` [PATCH v4 6/6] hw/arm/virt: Drop superfluous checks against highmem Marc Zyngier
2022-01-07 16:33   ` Marc Zyngier
2022-01-07 16:33   ` Marc Zyngier
2022-01-10 17:14   ` Eric Auger
2022-01-10 17:14     ` Eric Auger
2022-01-10 17:14     ` Eric Auger

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87ilurtweu.wl-maz@kernel.org \
    --to=maz@kernel.org \
    --cc=drjones@redhat.com \
    --cc=eric.auger@redhat.com \
    --cc=kernel-team@android.com \
    --cc=kvm@vger.kernel.org \
    --cc=kvmarm@lists.cs.columbia.edu \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.