From nobody Sat Feb 7 11:05:05 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=kernel.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1642170693773532.3246695144283; Fri, 14 Jan 2022 06:31:33 -0800 (PST) Received: from localhost ([::1]:34004 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1n8Nc4-0005bc-P6 for importer@patchew.org; Fri, 14 Jan 2022 09:31:32 -0500 Received: from eggs.gnu.org ([209.51.188.92]:48028) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n8NFZ-0006mq-Dd for qemu-devel@nongnu.org; Fri, 14 Jan 2022 09:08:17 -0500 Received: from ams.source.kernel.org ([145.40.68.75]:48434) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n8NFX-0002q0-75 for qemu-devel@nongnu.org; Fri, 14 Jan 2022 09:08:16 -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 ams.source.kernel.org (Postfix) with ESMTPS id A1701B825F8; Fri, 14 Jan 2022 14:08:06 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 429ADC36AF2; Fri, 14 Jan 2022 14:08:05 +0000 (UTC) Received: from sofa.misterjones.org ([185.219.108.64] helo=hot-poop.lan) 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 1n8NFL-000V8K-F7; Fri, 14 Jan 2022 14:08:03 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1642169285; bh=o+84v8AARuSDTfw6kHuIEO2OrH3GI/MMeSuFgurdj1A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Qc6SmWkoKVcx8o0bOy9uAYWeEjW8ievv8uYEERxjKrKR0HGm7XGubAp1wxqE33I6u yc9kXHN8mylAu+G42Y6ux3Hgk47kpmFzgXawWbB5TsYlN6rtdPNwI8NCNGWla1fy1m vMObs3vivLwAegCR9BCgu4LmOE6cLh3zxQa57bfn2bxUOYBETZaKszWJQeydw/pPR0 AwDpBCRv1WyJhEIhaawvcdp5qW2fh4lT2qdCFUJvRutjxH2nvgV36pLkCZ5WjQp+Zb LQKwCxKEfZmMbnHISS/W1swH4IyEsqsZ/IpOh8qrDyfLkvmJmdtM4bImUR+ajP7Q0k 5NEkuQMNWLHew== From: Marc Zyngier To: qemu-devel@nongnu.org Subject: [PATCH v5 4/6] hw/arm/virt: Use the PA range to compute the memory map Date: Fri, 14 Jan 2022 14:07:39 +0000 Message-Id: <20220114140741.1358263-5-maz@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220114140741.1358263-1-maz@kernel.org> References: <20220114140741.1358263-1-maz@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: qemu-devel@nongnu.org, drjones@redhat.com, eric.auger@redhat.com, peter.maydell@linaro.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, kernel-team@android.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=145.40.68.75; envelope-from=maz@kernel.org; helo=ams.source.kernel.org X-Spam_score_int: -76 X-Spam_score: -7.7 X-Spam_bar: ------- X-Spam_report: (-7.7 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.595, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_HI=-5, 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, Eric Auger , kernel-team@android.com, kvmarm@lists.cs.columbia.edu Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1642170696141100001 Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Eric Auger --- hw/arm/virt.c | 64 +++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 52 insertions(+), 12 deletions(-) diff --git a/hw/arm/virt.c b/hw/arm/virt.c index ecc3e3e5b0..a427676b50 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); } =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,14 @@ static void virt_set_memmap(VirtMachineState *vms) 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; + } + /* * 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 +1699,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_size, = 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 it by= %llu bytes\n", + pa_bits, memtop - BIT_ULL(pa_bits)); exit(EXIT_FAILURE); } if (base < device_memory_base) { @@ -1711,7 +1720,13 @@ static void virt_set_memmap(VirtMachineState *vms) 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 +1917,43 @@ static void machvirt_init(MachineState *machine) unsigned int smp_cpus =3D machine->smp.cpus; unsigned int max_cpus =3D machine->smp.max_cpus; =20 + if (!cpu_type_valid(machine->cpu_type)) { + error_report("mach-virt: CPU type %s not supported", machine->cpu_= type); + exit(1); + } + + possible_cpus =3D mc->possible_cpu_arch_ids(machine); + /* * In accelerated mode, the memory map is computed earlier in kvm_type= () * to create a VM with the right number of IPA bits. */ if (!vms->memmap) { - virt_set_memmap(vms); + Object *cpuobj; + ARMCPU *armcpu; + int pa_bits; + + /* + * Instanciate a temporary CPU object to find out about what + * we are about to deal with. Once this is done, get rid of + * the object. + */ + cpuobj =3D object_new(possible_cpus->cpus[0].type); + armcpu =3D ARM_CPU(cpuobj); + + if (object_property_get_bool(cpuobj, "aarch64", NULL)) { + pa_bits =3D arm_pamax(armcpu); + } else if (arm_feature(&armcpu->env, ARM_FEATURE_LPAE)) { + /* v7 with LPAE */ + pa_bits =3D 40; + } else { + /* Anything else */ + pa_bits =3D 32; + } + + object_unref(cpuobj); + + virt_set_memmap(vms, pa_bits); } =20 /* We can probe only here because during property set @@ -1915,11 +1961,6 @@ static void machvirt_init(MachineState *machine) */ finalize_gic_version(vms); =20 - if (!cpu_type_valid(machine->cpu_type)) { - error_report("mach-virt: CPU type %s not supported", machine->cpu_= type); - exit(1); - } - if (vms->secure) { /* * The Secure view of the world is the same as the NonSecure, @@ -1989,7 +2030,6 @@ static void machvirt_init(MachineState *machine) =20 create_fdt(vms); =20 - possible_cpus =3D mc->possible_cpu_arch_ids(machine); assert(possible_cpus->len =3D=3D max_cpus); for (n =3D 0; n < possible_cpus->len; n++) { Object *cpuobj; @@ -2646,7 +2686,7 @@ static int virt_kvm_type(MachineState *ms, const char= *type_str) max_vm_pa_size =3D kvm_arm_get_max_vm_ipa_size(ms, &fixed_ipa); =20 /* we freeze the memory map to compute the highest gpa */ - virt_set_memmap(vms); + virt_set_memmap(vms, max_vm_pa_size); =20 requested_pa_size =3D 64 - clz64(vms->highest_gpa); =20 --=20 2.30.2