From nobody Sat Apr 27 00:24:31 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1663802314; cv=none; d=zohomail.com; s=zohoarc; b=QnD1uSqAcjYES9YFpQXQuGjiPU/eam6zu9D/Y2xnrszGfOqDNYDNwSVzJ5dtbnKORLmMiAYd6kPwYSYgVDbI7r8+jc3VTd/8ZSwgYJh2A97T/zhZdiL1+XW+Q5/GA2u+Dhl0JRj85JBCLdTfggDECXqEXhjZ75xN4IxLhoxH2kU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1663802314; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Pvn+Cli8mJFxs6YFz0HeEDFEOPc8W6c2cloU0829xpg=; b=mR0n6HsUCbi+n1vFZ0Tm9mm5fRBa3Rpv5s8KB8Dg9ynDzVeW+ZMkQx/91s7qObSmLy83e+JFkSHYCw5Z+AC8rlLTt2n1RSt8x9/SZWK55PfFRlG3JPH3DGXglrcLusANalWz2xOFMg6712PxXq5nvgQwwE+zl/D//CGcwYpTmwE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1663802314420579.6373752684088; Wed, 21 Sep 2022 16:18:34 -0700 (PDT) Received: from localhost ([::1]:36244 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ob8z9-0002qi-Ij for importer@patchew.org; Wed, 21 Sep 2022 19:18:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40874) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ob8us-0008Kc-9i for qemu-devel@nongnu.org; Wed, 21 Sep 2022 19:14:06 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:20447) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ob8uq-0001qu-AT for qemu-devel@nongnu.org; Wed, 21 Sep 2022 19:14:05 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-404-MQ7MXKm4OMGSgZIiV4mT5w-1; Wed, 21 Sep 2022 19:14:00 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 014A03C0D194; Wed, 21 Sep 2022 23:14:00 +0000 (UTC) Received: from gshan.redhat.com (vpn2-54-126.bne.redhat.com [10.64.54.126]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9D02C2166B26; Wed, 21 Sep 2022 23:13:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1663802043; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Pvn+Cli8mJFxs6YFz0HeEDFEOPc8W6c2cloU0829xpg=; b=Dmi1bCww8z6YrYCLZqiSX1F560TI73NC8gETND0ZoQ7SNyfWMlQaItPkDLQ25cZfaCmOMq IHlpzP5M199jWHFPzXmgSHANB7yZ6yMea1B/6TVYBeP5vG0e4jpdFmy2TWmVc8V+kgnDx6 2F5KkvqOU01NZPaWHIqbk0ju4+VqWwQ= X-MC-Unique: MQ7MXKm4OMGSgZIiV4mT5w-1 From: Gavin Shan To: qemu-arm@nongnu.org Cc: qemu-devel@nongnu.org, maz@kernel.org, eric.auger@redhat.com, cohuck@redhat.com, zhenyzha@redhat.com, richard.henderson@linaro.org, peter.maydell@linaro.org, shan.gavin@gmail.com Subject: [PATCH v3 1/5] hw/arm/virt: Introduce virt_set_high_memmap() helper Date: Thu, 22 Sep 2022 07:13:45 +0800 Message-Id: <20220921231349.274049-2-gshan@redhat.com> In-Reply-To: <20220921231349.274049-1-gshan@redhat.com> References: <20220921231349.274049-1-gshan@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 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=170.10.133.124; envelope-from=gshan@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1663802316219100001 Content-Type: text/plain; charset="utf-8" This introduces virt_set_high_memmap() helper. The logic of high memory region address assignment is moved to the helper. The intention is to make the subsequent optimization for high memory region address assignment easier. No functional change intended. Signed-off-by: Gavin Shan Reviewed-by: Cornelia Huck Reviewed-by: Eric Auger Tested-by: Zhenyu Zhang --- hw/arm/virt.c | 74 ++++++++++++++++++++++++++++----------------------- 1 file changed, 41 insertions(+), 33 deletions(-) diff --git a/hw/arm/virt.c b/hw/arm/virt.c index 0961e053e5..4dab528b82 100644 --- a/hw/arm/virt.c +++ b/hw/arm/virt.c @@ -1689,6 +1689,46 @@ static uint64_t virt_cpu_mp_affinity(VirtMachineStat= e *vms, int idx) return arm_cpu_mp_affinity(idx, clustersz); } =20 +static void virt_set_high_memmap(VirtMachineState *vms, + hwaddr base, int pa_bits) +{ + int i; + + for (i =3D VIRT_LOWMEMMAP_LAST; i < ARRAY_SIZE(extended_memmap); i++) { + hwaddr size =3D extended_memmap[i].size; + bool fits; + + base =3D ROUND_UP(base, size); + vms->memmap[i].base =3D base; + vms->memmap[i].size =3D size; + + /* + * Check each device to see if they fit in the PA space, + * moving highest_gpa as we go. + * + * For each device that doesn't fit, disable it. + */ + fits =3D (base + size) <=3D BIT_ULL(pa_bits); + if (fits) { + vms->highest_gpa =3D base + size - 1; + } + + switch (i) { + case VIRT_HIGH_GIC_REDIST2: + vms->highmem_redists &=3D fits; + break; + case VIRT_HIGH_PCIE_ECAM: + vms->highmem_ecam &=3D fits; + break; + case VIRT_HIGH_PCIE_MMIO: + vms->highmem_mmio &=3D fits; + break; + } + + base +=3D size; + } +} + static void virt_set_memmap(VirtMachineState *vms, int pa_bits) { MachineState *ms =3D MACHINE(vms); @@ -1744,39 +1784,7 @@ static void virt_set_memmap(VirtMachineState *vms, i= nt pa_bits) /* We know for sure that at least the memory fits in the PA space */ vms->highest_gpa =3D memtop - 1; =20 - for (i =3D VIRT_LOWMEMMAP_LAST; i < ARRAY_SIZE(extended_memmap); i++) { - hwaddr size =3D extended_memmap[i].size; - bool fits; - - base =3D ROUND_UP(base, size); - vms->memmap[i].base =3D base; - vms->memmap[i].size =3D size; - - /* - * Check each device to see if they fit in the PA space, - * moving highest_gpa as we go. - * - * For each device that doesn't fit, disable it. - */ - fits =3D (base + size) <=3D BIT_ULL(pa_bits); - if (fits) { - vms->highest_gpa =3D base + size - 1; - } - - switch (i) { - case VIRT_HIGH_GIC_REDIST2: - vms->highmem_redists &=3D fits; - break; - case VIRT_HIGH_PCIE_ECAM: - vms->highmem_ecam &=3D fits; - break; - case VIRT_HIGH_PCIE_MMIO: - vms->highmem_mmio &=3D fits; - break; - } - - base +=3D size; - } + virt_set_high_memmap(vms, base, pa_bits); =20 if (device_memory_size > 0) { ms->device_memory =3D g_malloc0(sizeof(*ms->device_memory)); --=20 2.23.0 From nobody Sat Apr 27 00:24:31 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1663802330; cv=none; d=zohomail.com; s=zohoarc; b=L0UgJWfkNiMrKJyouz98TJuvn9OEHAFBv5pwwh935PK4WrjjfAZVhTh8Ul8IQjV8C4u1zbO1EvU1axWsDnyjwfuyWJ3XEB8C/ytNIQK/se5sPYv/Wd2kbLxLDTq4J8pQWtkaS0mpUQRpR/Pp94bZoUQMKLwe/vohYQFxUnUcU0c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1663802330; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=hirCa3HlIueBb970knAeJhyoOGSf8eDwAi/bmUCUvNo=; b=VQJvUyH5B1bcf2dRiwrz3KvzUqYcifKGCaaeQONe6cN/kg1yO0JfNcsvsX0NHRPMZNUA4ZXBECsVdDjEbPeecof7i26yjTnTB9hRBvEV1St/Agq018eF4qtiUsItt39vYTqqkDxtWAReRhvj5BG5JQYfx0DSClYe67KM2WnL9KY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1663802330862503.88421378430667; Wed, 21 Sep 2022 16:18:50 -0700 (PDT) Received: from localhost ([::1]:38328 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ob8zR-0003fd-OE for importer@patchew.org; Wed, 21 Sep 2022 19:18:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40878) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ob8uw-0008Qu-VT for qemu-devel@nongnu.org; Wed, 21 Sep 2022 19:14:11 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:21870) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ob8uu-0001rd-EV for qemu-devel@nongnu.org; Wed, 21 Sep 2022 19:14:10 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-148-YAvDvmRPNIuTf2eV6lQOJA-1; Wed, 21 Sep 2022 19:14:04 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0628C862FDC; Wed, 21 Sep 2022 23:14:04 +0000 (UTC) Received: from gshan.redhat.com (vpn2-54-126.bne.redhat.com [10.64.54.126]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9A7EB2166B26; Wed, 21 Sep 2022 23:14:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1663802047; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hirCa3HlIueBb970knAeJhyoOGSf8eDwAi/bmUCUvNo=; b=MUXDeqbnEiAa5dFg3M8sr+nDWYToPaBDcda0gy42WalJ5Rbs71sQo3Jgfm/1GXlTTSPTP+ ycv3+fmBs2/67jg+AX4LrtnLjUIL/tTucwgiriuWRQdGHR6o03r8W6jzpthCYQGWARQDK1 uLuX/FzO4BoddzLiN+W5Z5GY7aCCVVU= X-MC-Unique: YAvDvmRPNIuTf2eV6lQOJA-1 From: Gavin Shan To: qemu-arm@nongnu.org Cc: qemu-devel@nongnu.org, maz@kernel.org, eric.auger@redhat.com, cohuck@redhat.com, zhenyzha@redhat.com, richard.henderson@linaro.org, peter.maydell@linaro.org, shan.gavin@gmail.com Subject: [PATCH v3 2/5] hw/arm/virt: Rename variable size to region_size in virt_set_high_memmap() Date: Thu, 22 Sep 2022 07:13:46 +0800 Message-Id: <20220921231349.274049-3-gshan@redhat.com> In-Reply-To: <20220921231349.274049-1-gshan@redhat.com> References: <20220921231349.274049-1-gshan@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 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=170.10.133.124; envelope-from=gshan@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1663802331939100005 Content-Type: text/plain; charset="utf-8" This renames variable 'size' to 'region_size' in virt_set_high_memmap(). Its counterpart ('region_base') will be introduced in next patch. No functional change intended. Signed-off-by: Gavin Shan Reviewed-by: Eric Auger Tested-by: Zhenyu Zhang --- hw/arm/virt.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/hw/arm/virt.c b/hw/arm/virt.c index 4dab528b82..187b3ee0e2 100644 --- a/hw/arm/virt.c +++ b/hw/arm/virt.c @@ -1692,15 +1692,16 @@ static uint64_t virt_cpu_mp_affinity(VirtMachineSta= te *vms, int idx) static void virt_set_high_memmap(VirtMachineState *vms, hwaddr base, int pa_bits) { + hwaddr region_size; + bool fits; int i; =20 for (i =3D VIRT_LOWMEMMAP_LAST; i < ARRAY_SIZE(extended_memmap); i++) { - hwaddr size =3D extended_memmap[i].size; - bool fits; + region_size =3D extended_memmap[i].size; =20 - base =3D ROUND_UP(base, size); + base =3D ROUND_UP(base, region_size); vms->memmap[i].base =3D base; - vms->memmap[i].size =3D size; + vms->memmap[i].size =3D region_size; =20 /* * Check each device to see if they fit in the PA space, @@ -1708,9 +1709,9 @@ static void virt_set_high_memmap(VirtMachineState *vm= s, * * For each device that doesn't fit, disable it. */ - fits =3D (base + size) <=3D BIT_ULL(pa_bits); + fits =3D (base + region_size) <=3D BIT_ULL(pa_bits); if (fits) { - vms->highest_gpa =3D base + size - 1; + vms->highest_gpa =3D base + region_size - 1; } =20 switch (i) { @@ -1725,7 +1726,7 @@ static void virt_set_high_memmap(VirtMachineState *vm= s, break; } =20 - base +=3D size; + base +=3D region_size; } } =20 --=20 2.23.0 From nobody Sat Apr 27 00:24:31 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1663802594; cv=none; d=zohomail.com; s=zohoarc; b=iPqlUm9/Z3nu2JzWRS20JGZueOHpvHTUO5uGDoKffMw9IoSVM1FAVYMfLYGweKv1Jucj7J/yZipKWGxdzwRSgh5MEXiP11tSyFNfNcxeCvsv+di5+2nELKJQ/Ctyn2TMPkumee8sEd+rluWYt6QJNsrNRjIJYpQFvSvlHnFaJjk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1663802594; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=INGyMUpdKLNzLwyHhM65ggS6sfucai9ZgAxo7nEnfY8=; b=ReeKWObE6xTdWdV0Zv25dtpMCTBhMr71P2pPRrlBa54BluGiEOTVpEMQa2EVFMHbsWNV92WKn+gCI3Hoad0ccB8f7/qUvDW6nlneRTIronhJGjQ9SV/pI7cErJyL42cAAXZocGj6pQndJV5jbMk/cdhMdoJiumcN+eYBdgQBe0Q= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1663802594229267.18111476398747; Wed, 21 Sep 2022 16:23:14 -0700 (PDT) Received: from localhost ([::1]:44206 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ob93h-0001QO-8C for importer@patchew.org; Wed, 21 Sep 2022 19:23:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43846) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ob8vE-0000Ln-7M for qemu-devel@nongnu.org; Wed, 21 Sep 2022 19:14:28 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:38808) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ob8uy-0001sN-Rz for qemu-devel@nongnu.org; Wed, 21 Sep 2022 19:14:27 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-380-QzSwp7BYOh6Jvl0RUz2O9g-1; Wed, 21 Sep 2022 19:14:09 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9B6EC101A528; Wed, 21 Sep 2022 23:14:08 +0000 (UTC) Received: from gshan.redhat.com (vpn2-54-126.bne.redhat.com [10.64.54.126]) by smtp.corp.redhat.com (Postfix) with ESMTP id 98B6F2166B29; Wed, 21 Sep 2022 23:14:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1663802052; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=INGyMUpdKLNzLwyHhM65ggS6sfucai9ZgAxo7nEnfY8=; b=IQxMxraF4S3LDB4OmdmvkBJjaNyc9xCVXaz/RQ1r2PBhdXgwZf/l2H9UgvhTKZGopERlxy Unnwlt5zwxvky1HlmhX6uzA6eZEl66CW7Nk7H+t+ER9smrTQjGEfL1VJimzgWWNbo2gHVu mdVNnsr4VDyJLcNfMyn3d+ay9VBDVF4= X-MC-Unique: QzSwp7BYOh6Jvl0RUz2O9g-1 From: Gavin Shan To: qemu-arm@nongnu.org Cc: qemu-devel@nongnu.org, maz@kernel.org, eric.auger@redhat.com, cohuck@redhat.com, zhenyzha@redhat.com, richard.henderson@linaro.org, peter.maydell@linaro.org, shan.gavin@gmail.com Subject: [PATCH v3 3/5] hw/arm/virt: Introduce variable region_base in virt_set_high_memmap() Date: Thu, 22 Sep 2022 07:13:47 +0800 Message-Id: <20220921231349.274049-4-gshan@redhat.com> In-Reply-To: <20220921231349.274049-1-gshan@redhat.com> References: <20220921231349.274049-1-gshan@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 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=170.10.133.124; envelope-from=gshan@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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=unavailable 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1663802594728100001 Content-Type: text/plain; charset="utf-8" This introduces variable 'region_base' for the base address of the specific high memory region. It's the preparatory work to optimize high memory region address assignment. No functional change intended. Signed-off-by: Gavin Shan Reviewed-by: Eric Auger Tested-by: Zhenyu Zhang --- hw/arm/virt.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/hw/arm/virt.c b/hw/arm/virt.c index 187b3ee0e2..b0b679d1f4 100644 --- a/hw/arm/virt.c +++ b/hw/arm/virt.c @@ -1692,15 +1692,15 @@ static uint64_t virt_cpu_mp_affinity(VirtMachineSta= te *vms, int idx) static void virt_set_high_memmap(VirtMachineState *vms, hwaddr base, int pa_bits) { - hwaddr region_size; + hwaddr region_base, region_size; bool fits; int i; =20 for (i =3D VIRT_LOWMEMMAP_LAST; i < ARRAY_SIZE(extended_memmap); i++) { + region_base =3D ROUND_UP(base, extended_memmap[i].size); region_size =3D extended_memmap[i].size; =20 - base =3D ROUND_UP(base, region_size); - vms->memmap[i].base =3D base; + vms->memmap[i].base =3D region_base; vms->memmap[i].size =3D region_size; =20 /* @@ -1709,9 +1709,9 @@ static void virt_set_high_memmap(VirtMachineState *vm= s, * * For each device that doesn't fit, disable it. */ - fits =3D (base + region_size) <=3D BIT_ULL(pa_bits); + fits =3D (region_base + region_size) <=3D BIT_ULL(pa_bits); if (fits) { - vms->highest_gpa =3D base + region_size - 1; + vms->highest_gpa =3D region_base + region_size - 1; } =20 switch (i) { @@ -1726,7 +1726,7 @@ static void virt_set_high_memmap(VirtMachineState *vm= s, break; } =20 - base +=3D region_size; + base =3D region_base + region_size; } } =20 --=20 2.23.0 From nobody Sat Apr 27 00:24:31 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1663802328; cv=none; d=zohomail.com; s=zohoarc; b=QwTWObrsfLD+r48Y3v7fjqSRKmvo3zPMNX8C9JYdsKa1nF2XSMRfo0HvvNDzsC3YngHdu7mfev+fIp6zQhippfvUe0vKzq0fWnONpZT9P2x6y5iZr5UbQwMrjSIukF5TtCy98d042lAuCcEaGX2xNCsaBnyDW7vTLiUVwpwd8Eo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1663802328; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Sv6gjcFNmp354tzRnNVqsmaz0Eb5IUn+dcydFYKMH/o=; b=TZ86ogXEVFSxeaSPuc+gH5kiry4oyNNQpeN1I/V/j0fGv7JmIOQrDKK1aTYeRqkqp+M4NibBk5uBGFh6CqAiWc2/49okPOpoML9xMPd1BJC33EEsPJ6TyykseyxFh5698MaxaY1Da5+xlxyxYdBowP3Obltf3Z06HUeaJhKSyuk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1663802328573600.3001355425166; Wed, 21 Sep 2022 16:18:48 -0700 (PDT) Received: from localhost ([::1]:48466 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ob8zO-0003X6-IT for importer@patchew.org; Wed, 21 Sep 2022 19:18:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54490) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ob8v4-000065-KX for qemu-devel@nongnu.org; Wed, 21 Sep 2022 19:14:18 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:23758) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ob8v3-0001sr-25 for qemu-devel@nongnu.org; Wed, 21 Sep 2022 19:14:18 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-580-t76h502BNOOuknaDTC2yZg-1; Wed, 21 Sep 2022 19:14:13 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id CD9DE3C0D197; Wed, 21 Sep 2022 23:14:12 +0000 (UTC) Received: from gshan.redhat.com (vpn2-54-126.bne.redhat.com [10.64.54.126]) by smtp.corp.redhat.com (Postfix) with ESMTP id 392982166B26; Wed, 21 Sep 2022 23:14:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1663802056; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Sv6gjcFNmp354tzRnNVqsmaz0Eb5IUn+dcydFYKMH/o=; b=OiUR7kNIdlOMOoKtkfmbL/YW3lhP10/qUz4x8BkYjZjklLjtDd6ajTBYjNn143dTkYKW1B nVcY6k84s9WY2ubD+4gOIGwzj5YnH9zq24SHgKl5rUFow+cM/wD7PrToLc+rNcAAgmWxS1 t9Kg6XFQk4ug23Yaw3BGSCChCm+XFo4= X-MC-Unique: t76h502BNOOuknaDTC2yZg-1 From: Gavin Shan To: qemu-arm@nongnu.org Cc: qemu-devel@nongnu.org, maz@kernel.org, eric.auger@redhat.com, cohuck@redhat.com, zhenyzha@redhat.com, richard.henderson@linaro.org, peter.maydell@linaro.org, shan.gavin@gmail.com Subject: [PATCH v3 4/5] hw/arm/virt: Improve high memory region address assignment Date: Thu, 22 Sep 2022 07:13:48 +0800 Message-Id: <20220921231349.274049-5-gshan@redhat.com> In-Reply-To: <20220921231349.274049-1-gshan@redhat.com> References: <20220921231349.274049-1-gshan@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 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=170.10.133.124; envelope-from=gshan@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1663802329946100001 Content-Type: text/plain; charset="utf-8" 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. This improves the address assignment for those three high memory region by skipping the address assignment for one specific high memory region if it has been disabled in case (1), (2) and (3). Signed-off-by: Gavin Shan Tested-by: Zhenyu Zhang --- hw/arm/virt.c | 44 ++++++++++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/hw/arm/virt.c b/hw/arm/virt.c index b0b679d1f4..b702f8f2b5 100644 --- a/hw/arm/virt.c +++ b/hw/arm/virt.c @@ -1693,15 +1693,31 @@ static void virt_set_high_memmap(VirtMachineState *= vms, hwaddr base, int pa_bits) { hwaddr region_base, region_size; - bool fits; + bool *region_enabled, fits; int i; =20 for (i =3D VIRT_LOWMEMMAP_LAST; i < ARRAY_SIZE(extended_memmap); i++) { region_base =3D ROUND_UP(base, extended_memmap[i].size); region_size =3D extended_memmap[i].size; =20 - vms->memmap[i].base =3D region_base; - vms->memmap[i].size =3D region_size; + switch (i) { + case VIRT_HIGH_GIC_REDIST2: + region_enabled =3D &vms->highmem_redists; + break; + case VIRT_HIGH_PCIE_ECAM: + region_enabled =3D &vms->highmem_ecam; + break; + case VIRT_HIGH_PCIE_MMIO: + region_enabled =3D &vms->highmem_mmio; + break; + default: + region_enabled =3D NULL; + } + + /* Skip unknown region */ + if (!region_enabled) { + continue; + } =20 /* * Check each device to see if they fit in the PA space, @@ -1710,23 +1726,15 @@ static void virt_set_high_memmap(VirtMachineState *= vms, * For each device that doesn't fit, disable it. */ fits =3D (region_base + region_size) <=3D BIT_ULL(pa_bits); - if (fits) { - vms->highest_gpa =3D region_base + region_size - 1; - } + if (*region_enabled && fits) { + vms->memmap[i].base =3D region_base; + vms->memmap[i].size =3D region_size; =20 - switch (i) { - case VIRT_HIGH_GIC_REDIST2: - vms->highmem_redists &=3D fits; - break; - case VIRT_HIGH_PCIE_ECAM: - vms->highmem_ecam &=3D fits; - break; - case VIRT_HIGH_PCIE_MMIO: - vms->highmem_mmio &=3D fits; - break; + vms->highest_gpa =3D region_base + region_size - 1; + base =3D region_base + region_size; + } else { + *region_enabled =3D false; } - - base =3D region_base + region_size; } } =20 --=20 2.23.0 From nobody Sat Apr 27 00:24:31 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1663802576; cv=none; d=zohomail.com; s=zohoarc; b=I3MVbfT41tieRoOEEcInKDhHYzCX7upH46LReu2WvkgGKYxbdW9Gd0u/V20jKazi1Hg6J7tm+saSzci2Hxd+8oOL8WmZ1x0fHL8y9RH7zHPbXnDl4QuE7iDRfKgJw3XH1Xu3cd656fUnLMQXOIiw4UShc2oj+GLBOf4c3Fqv3As= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1663802576; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Me8ulcsbNjHsaAKjtva3HKYWvRtkDuDwNDWtdQMzMFY=; b=oG67Kq4i7x1+Qs8YUJgtmyhHiQxSOViL6O4MV1gwbfcmF/Fe+N4FB/q1fNUCTzwNxDIXAXHjGsoqGuWFSUbZ7QH1NAYFBpUMbcc8AfoheLV6r9hSsDE8Uq5myA0YrDl723/wtAxUiLbrJ5Oi8wZ9suoHHukg8m9ebSaQcl88N14= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1663802576394679.7723900752885; Wed, 21 Sep 2022 16:22:56 -0700 (PDT) Received: from localhost ([::1]:57030 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ob93P-0000jL-CO for importer@patchew.org; Wed, 21 Sep 2022 19:22:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54496) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ob8vB-0000E9-5C for qemu-devel@nongnu.org; Wed, 21 Sep 2022 19:14:25 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:40719) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ob8v9-0001u7-CX for qemu-devel@nongnu.org; Wed, 21 Sep 2022 19:14:24 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-648-p9X1P-2FMFWP5c2lVdybgA-1; Wed, 21 Sep 2022 19:14:17 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 315DC862FDF; Wed, 21 Sep 2022 23:14:17 +0000 (UTC) Received: from gshan.redhat.com (vpn2-54-126.bne.redhat.com [10.64.54.126]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9DEBA2166B26; Wed, 21 Sep 2022 23:14:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1663802062; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Me8ulcsbNjHsaAKjtva3HKYWvRtkDuDwNDWtdQMzMFY=; b=HMtHV78d2h922ecFxPqetDFnfLVAoSoV60MDc0W/n7lkoPYdSaksxjUEL0eZGmJ8ZeLaTR Ez6PrBBZzkMObnBNYh6ragwkaItf4q0Co/iYOJaPDZZdtn7CP5qQKBsrv40BDsSjQVai1c 23em5suhcMuIh5JjmAQ9sC5u1bLeyXg= X-MC-Unique: p9X1P-2FMFWP5c2lVdybgA-1 From: Gavin Shan To: qemu-arm@nongnu.org Cc: qemu-devel@nongnu.org, maz@kernel.org, eric.auger@redhat.com, cohuck@redhat.com, zhenyzha@redhat.com, richard.henderson@linaro.org, peter.maydell@linaro.org, shan.gavin@gmail.com Subject: [PATCH v3 5/5] hw/arm/virt: Add 'highmem-compact' property Date: Thu, 22 Sep 2022 07:13:49 +0800 Message-Id: <20220921231349.274049-6-gshan@redhat.com> In-Reply-To: <20220921231349.274049-1-gshan@redhat.com> References: <20220921231349.274049-1-gshan@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 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=170.10.133.124; envelope-from=gshan@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1663802579932100001 Content-Type: text/plain; charset="utf-8" After the improvement to high memory region address assignment is applied, the memory layout is changed. For example, VIRT_HIGH_PCIE_MMIO memory region is enabled when the improvement is applied, but it's disabled if the improvement isn't applied. pa_bits =3D 40; vms->highmem_redists =3D false; vms->highmem_ecam =3D false; vms->highmem_mmio =3D true; # qemu-system-aarch64 -accel kvm -cpu host \ -machine virt-7.2 -m 4G,maxmem=3D511G \ -monitor stdio In order to keep backwords compatibility, we need to disable the optimization on machines, which is virt-7.1 or ealier than it. It means the optimization is enabled by default from virt-7.2. Besides, 'highmem-compact' property is added so that the optimization can be explicitly enabled or disabled on all machine types by users. Signed-off-by: Gavin Shan Tested-by: Zhenyu Zhang --- docs/system/arm/virt.rst | 4 ++++ hw/arm/virt.c | 33 +++++++++++++++++++++++++++++++++ include/hw/arm/virt.h | 2 ++ 3 files changed, 39 insertions(+) diff --git a/docs/system/arm/virt.rst b/docs/system/arm/virt.rst index 20442ea2c1..f05ec2253b 100644 --- a/docs/system/arm/virt.rst +++ b/docs/system/arm/virt.rst @@ -94,6 +94,10 @@ highmem address space above 32 bits. The default is ``on`` for machine types later than ``virt-2.12``. =20 +highmem-compact + Set ``on``/``off`` to enable/disable compact space for high memory regio= ns. + The default is ``on`` for machine types later than ``virt-7.2`` + gic-version Specify the version of the Generic Interrupt Controller (GIC) to provide. Valid values are: diff --git a/hw/arm/virt.c b/hw/arm/virt.c index b702f8f2b5..a4fbdaef91 100644 --- a/hw/arm/virt.c +++ b/hw/arm/virt.c @@ -1734,6 +1734,13 @@ static void virt_set_high_memmap(VirtMachineState *v= ms, base =3D region_base + region_size; } else { *region_enabled =3D false; + + if (!vms->highmem_compact) { + base =3D region_base + region_size; + if (fits) { + vms->highest_gpa =3D region_base + region_size - 1; + } + } } } } @@ -2348,6 +2355,20 @@ static void virt_set_highmem(Object *obj, bool value= , Error **errp) vms->highmem =3D value; } =20 +static bool virt_get_highmem_compact(Object *obj, Error **errp) +{ + VirtMachineState *vms =3D VIRT_MACHINE(obj); + + return vms->highmem_compact; +} + +static void virt_set_highmem_compact(Object *obj, bool value, Error **errp) +{ + VirtMachineState *vms =3D VIRT_MACHINE(obj); + + vms->highmem_compact =3D value; +} + static bool virt_get_its(Object *obj, Error **errp) { VirtMachineState *vms =3D VIRT_MACHINE(obj); @@ -2966,6 +2987,13 @@ static void virt_machine_class_init(ObjectClass *oc,= void *data) "Set on/off to enable/disable us= ing " "physical address space above 32= bits"); =20 + object_class_property_add_bool(oc, "highmem-compact", + virt_get_highmem_compact, + virt_set_highmem_compact); + object_class_property_set_description(oc, "highmem-compact", + "Set on/off to enable/disable co= mpact " + "space for high memory regions"); + object_class_property_add_str(oc, "gic-version", virt_get_gic_version, virt_set_gic_version); object_class_property_set_description(oc, "gic-version", @@ -3050,6 +3078,7 @@ static void virt_instance_init(Object *obj) =20 /* High memory is enabled by default */ vms->highmem =3D true; + vms->highmem_compact =3D !vmc->no_highmem_compact; vms->gic_version =3D VIRT_GIC_VERSION_NOSEL; =20 vms->highmem_ecam =3D !vmc->no_highmem_ecam; @@ -3119,8 +3148,12 @@ DEFINE_VIRT_MACHINE_AS_LATEST(7, 2) =20 static void virt_machine_7_1_options(MachineClass *mc) { + VirtMachineClass *vmc =3D VIRT_MACHINE_CLASS(OBJECT_CLASS(mc)); + virt_machine_7_2_options(mc); compat_props_add(mc->compat_props, hw_compat_7_1, hw_compat_7_1_len); + /* Compact space for high memory regions was introduced with 7.2 */ + vmc->no_highmem_compact =3D true; } DEFINE_VIRT_MACHINE(7, 1) =20 diff --git a/include/hw/arm/virt.h b/include/hw/arm/virt.h index 6ec479ca2b..c7dd59d7f1 100644 --- a/include/hw/arm/virt.h +++ b/include/hw/arm/virt.h @@ -125,6 +125,7 @@ struct VirtMachineClass { bool no_pmu; bool claim_edge_triggered_timers; bool smbios_old_sys_ver; + bool no_highmem_compact; bool no_highmem_ecam; bool no_ged; /* Machines < 4.2 have no support for ACPI GED device */ bool kvm_no_adjvtime; @@ -144,6 +145,7 @@ struct VirtMachineState { PFlashCFI01 *flash[2]; bool secure; bool highmem; + bool highmem_compact; bool highmem_ecam; bool highmem_mmio; bool highmem_redists; --=20 2.23.0