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 DC984C433EF for ; Mon, 27 Dec 2021 16:39:51 +0000 (UTC) Received: from localhost ([::1]:47982 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1n1t2M-0003A9-Lc for qemu-devel@archiver.kernel.org; Mon, 27 Dec 2021 11:39:50 -0500 Received: from eggs.gnu.org ([209.51.188.92]:59788) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n1t1g-0002V0-Nc for qemu-devel@nongnu.org; Mon, 27 Dec 2021 11:39:08 -0500 Received: from dfw.source.kernel.org ([139.178.84.217]:37882) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n1t1e-0006R1-QU for qemu-devel@nongnu.org; Mon, 27 Dec 2021 11:39:08 -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 3625861119; Mon, 27 Dec 2021 16:39:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9BFADC36AE7; Mon, 27 Dec 2021 16:39:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1640623143; bh=WEDbpEQhjoWaU0eAWyDEdcLhrsSzaMog2S29Lw9qtmk=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=NtLNIGGxRyIizvSbAaIfsLpFFs/rZX6VaeFRLPoqcQqoMazJzKHgAkEBmEfX4h491 jTvy1DxYyM2mmJt1LIo0dTQ7fsEXlEIcZ+cWs4XW8SCtKtUtN3KFWcX6XR6pw4dDUr Uwg95qbwCJXplo+VqWkimps3L39YkXhn4tbna1elGeNwuC42TGY8I+W1AneODx26w5 /e6ysrQ5PREY8d+RzpLtC8sVYw9oF4tAntYhPky5gYHFM2bpcxGtEg5/yRI57rIDv6 4P74lzUbWSUfq0VsOdLATkkHCF85UIGt5h6ALEtAnkYNLiWhNo0vM7/LqDlIrt25SK TW1iF35u2M6bQ== Received: from cfbb000407.r.cam.camfibre.uk ([185.219.108.64] helo=wait-a-minute.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 1n1t1Z-00Eawq-JP; Mon, 27 Dec 2021 16:39:01 +0000 Date: Mon, 27 Dec 2021 16:39:01 +0000 Message-ID: <87o852ypcq.wl-maz@kernel.org> From: Marc Zyngier To: eric.auger@redhat.com Subject: Re: [PATCH v2 3/5] hw/arm/virt: Honor highmem setting when computing the memory map In-Reply-To: References: <20211003164605.3116450-1-maz@kernel.org> <20211003164605.3116450-4-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, drjones@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 client-ip=139.178.84.217; envelope-from=maz@kernel.org; helo=dfw.source.kernel.org X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.575, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, 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, 04 Oct 2021 13:23:41 +0100, Eric Auger wrote: >=20 > Hi Marc, >=20 > On 10/3/21 6:46 PM, Marc Zyngier wrote: > > Even when the VM is configured with highmem=3Doff, the highest_gpa > > field includes devices that are above the 4GiB limit. > > Similarily, nothing seem to check that the memory is within > > the limit set by the highmem=3Doff option. > > > > This leads to failures in virt_kvm_type() on systems that have > > a crippled IPA range, as the reported IPA space is larger than > > what it should be. > > > > Instead, honor the user-specified limit to only use the devices > > at the lowest end of the spectrum, and fail if we have memory > > crossing the 4GiB limit. > > > > Signed-off-by: Marc Zyngier > > --- > > hw/arm/virt.c | 9 ++++++++- > > 1 file changed, 8 insertions(+), 1 deletion(-) > > > > diff --git a/hw/arm/virt.c b/hw/arm/virt.c > > index bcf58f677d..9d2abdbd5f 100644 > > --- a/hw/arm/virt.c > > +++ b/hw/arm/virt.c > > @@ -1628,6 +1628,11 @@ static void virt_set_memmap(VirtMachineState *vm= s) > > exit(EXIT_FAILURE); > > } > > =20 > > + if (!vms->highmem && > > + vms->memmap[VIRT_MEM].base + ms->maxram_size > 4 * GiB) { > > + error_report("highmem=3Doff, but memory crosses the 4GiB limit= \n"); > > + exit(EXIT_FAILURE); > > + } > > /* > > * We compute the base of the high IO region depending on the > > * amount of initial and device memory. The device memory start/si= ze > > @@ -1657,7 +1662,9 @@ static void virt_set_memmap(VirtMachineState *vms) > > vms->memmap[i].size =3D size; > > base +=3D size; > > } > > - vms->highest_gpa =3D base - 1; > > + vms->highest_gpa =3D (vms->highmem ? > > + base : > > + vms->memmap[VIRT_MEM].base + ms->maxram_size) = - 1; > I think I would have preferred to have >=20 > if (vms->highmem) { > =C2=A0=C2=A0 for (i =3D VIRT_LOWMEMMAP_LAST; i < ARRAY_SIZE(extended_memm= ap); i++) { > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 hwaddr size =3D extended_memma= p[i].size; >=20 > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 base =3D ROUND_UP(base, size); > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 vms->memmap[i].base =3D base; > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 vms->memmap[i].size =3D size; > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 base +=3D size; > =C2=A0=C2=A0=C2=A0 } > } > as it is useless to execute that code and create new memmap entries in > case of !highmem. I agree that it is a bit useless when we only have highmem. But we really want to deal with arbitrary IPA spaces (see how this changes in the follow-up patches), and we need to check that everything fits in the IPA space (and fix things up if they don't). >=20 > But nevertheless, this looks correct Thanks, M. --=20 Without deviation from the norm, progress is not possible.