From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 29B93C433EF for ; Mon, 10 Jan 2022 16:03:57 +0000 (UTC) Received: from localhost ([::1]:40730 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1n6x9H-0000s1-4d for qemu-devel@archiver.kernel.org; Mon, 10 Jan 2022 11:03:55 -0500 Received: from eggs.gnu.org ([209.51.188.92]:49978) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n6x4D-0005hi-6y for qemu-devel@nongnu.org; Mon, 10 Jan 2022 10:58:41 -0500 Received: from [2604:1380:4641:c500::1] (port=43366 helo=dfw.source.kernel.org) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n6x4A-0004jS-5m for qemu-devel@nongnu.org; Mon, 10 Jan 2022 10:58:40 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 74C9460EF4; Mon, 10 Jan 2022 15:58:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DEA0DC36AE5; Mon, 10 Jan 2022 15:58:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1641830315; bh=yy2g18ZmN6V9ofHPGdck09RwOJDBvsPANaHpXOcQECQ=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=W/cQTf1/z21ABUgAszAEP2BgFPvE9YEgWKljQMwmJ6gJbLqQOSnwQXOV/Q4zNr6yB xHYeV9IlJfEdy4gL8XJtjTYBa2xhAV0k0CWshEwx/bHQkbMu7A3k8UPvBl7hyDUJXz Na6pPAr9QtAHptoMmPRtycpNq8vOnMonKvc8uqUDufPv7uuEz7Lbc9tbXEq1jKswje cjYa9mXir1C+W9JlBKmg2Ee8uSSbQgs+FPFjnjlpSXCEUEgwRegKZTnXT4bF/1tLJ9 sJNGM2S0p0im5T2v/C+RQ95xwa+RooWkSM6EXDRmlmw3hQCtvpooYgY0FdB4aQt5BF MGG8saYejYsKw== Received: from sofa.misterjones.org ([185.219.108.64] helo=why.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1n6x45-00HAi9-T9; Mon, 10 Jan 2022 15:58:34 +0000 Date: Mon, 10 Jan 2022 15:58:33 +0000 Message-ID: <87ilurtweu.wl-maz@kernel.org> From: Marc Zyngier To: eric.auger@redhat.com Subject: Re: [PATCH v4 4/6] hw/arm/virt: Use the PA range to compute the memory map In-Reply-To: References: <20220107163324.2491209-1-maz@kernel.org> <20220107163324.2491209-5-maz@kernel.org> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/27.1 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: eric.auger@redhat.com, qemu-devel@nongnu.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, kernel-team@android.com, drjones@redhat.com, peter.maydell@linaro.org X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false X-Host-Lookup-Failed: Reverse DNS lookup failed for 2604:1380:4641:c500::1 (failed) Received-SPF: pass client-ip=2604:1380:4641:c500::1; envelope-from=maz@kernel.org; helo=dfw.source.kernel.org X-Spam_score_int: -68 X-Spam_score: -6.9 X-Spam_bar: ------ X-Spam_report: (-6.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.597, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_HI=-5, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Andrew Jones , kvm@vger.kernel.org, qemu-devel@nongnu.org, kernel-team@android.com, kvmarm@lists.cs.columbia.edu Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" On Mon, 10 Jan 2022 15:38:56 +0000, Eric Auger wrote: >=20 > Hi Marc, >=20 > 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 > > --- > > 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(VirtMachineS= tate *vms, int idx) > > return arm_cpu_mp_affinity(idx, clustersz); > > } > > =20 > > -static void virt_set_memmap(VirtMachineState *vms) > > +static void virt_set_memmap(VirtMachineState *vms, int pa_bits) > > { > > MachineState *ms =3D MACHINE(vms); > > hwaddr base, device_memory_base, device_memory_size, memtop; > > @@ -1678,6 +1678,13 @@ static void virt_set_memmap(VirtMachineState *vm= s) > > exit(EXIT_FAILURE); > > } > > =20 > > + /* > > + * !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 =3D 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/si= ze > > @@ -1691,8 +1698,9 @@ static void virt_set_memmap(VirtMachineState *vms) > > =20 > > /* Base address of the high IO region */ > > memtop =3D base =3D device_memory_base + ROUND_UP(device_memory_si= ze, GiB); > > - if (!vms->highmem && memtop > 4 * GiB) { > > - error_report("highmem=3Doff, but memory crosses the 4GiB limit= \n"); > > + if (memtop > BIT_ULL(pa_bits)) { > > + error_report("Addressing limited to %d bits, but memory exceeds i= t 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 *vm= s) > > vms->memmap[i].size =3D size; > > base +=3D size; > > } > > - vms->highest_gpa =3D (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 =3D (base <=3D BIT_ULL(pa_bits) ? base : memtop) = - 1; > > + > > if (device_memory_size > 0) { > > ms->device_memory =3D g_malloc0(sizeof(*ms->device_memory)); > > ms->device_memory->base =3D device_memory_base; > > @@ -1902,12 +1916,38 @@ static void machvirt_init(MachineState *machine) > > unsigned int smp_cpus =3D machine->smp.cpus; > > unsigned int max_cpus =3D machine->smp.max_cpus; > Move the cpu_type check before? >=20 > =C2=A0=C2=A0=C2=A0 if (!cpu_type_valid(machine->cpu_type)) { > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 error_report("mach-virt: CPU t= ype %s not supported", > machine->cpu_type); > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 exit(1); > =C2=A0=C2=A0=C2=A0 } > > 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. --=20 Without deviation from the norm, progress is not possible.