From nobody Thu May 9 20:56:20 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=1664843429; cv=none; d=zohomail.com; s=zohoarc; b=V/gMYRdBaaiB/wKT6G3hvgOA2AO0Kce4v2GYbJtP2oBxwPuX4p8O8wC6c5KgDGfvNCO4yp9/FvF9YqMYAQFds5FTcd2frg6uuvjou9120PfLVm+zv8CxV9dat6w5YXhoHo0cyP5D+z0NxAOjiRHVHUVwgQ1Ia8Xcy4uuC5bwwpg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1664843429; 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=YZts7HP0P/o4y952/JJF9h4xHArVVKoewzDjO34Yvxg=; b=ee2Qgss4xNN/odf8KTwi2eMMntaSM1Rd8kvJChgqeTZmuZTIDQMDjHWjyF7aaqA5sI1GVaBUYVU1NVNUppgaLcX3lQGVj1yFTa72Ga/qQ/JfUHvSa2zWB5hi/CiWAHmiCmjf6dptpMcPGN/IJRKNV5ERwWllU0pelkHBLjXjqCI= 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 16648434298231011.2178513758998; Mon, 3 Oct 2022 17:30:29 -0700 (PDT) Received: from localhost ([::1]:37864 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ofVpL-00029N-Sw for importer@patchew.org; Mon, 03 Oct 2022 20:30:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50016) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ofVlj-0007or-Cy for qemu-devel@nongnu.org; Mon, 03 Oct 2022 20:26:43 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:58128) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ofVlg-0004sF-U1 for qemu-devel@nongnu.org; Mon, 03 Oct 2022 20:26:42 -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-216-sMFqkUyLM0W277CwS9yN0Q-1; Mon, 03 Oct 2022 20:26:38 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id F1C7D29ABA30; Tue, 4 Oct 2022 00:26:37 +0000 (UTC) Received: from gshan.redhat.com (vpn2-54-56.bne.redhat.com [10.64.54.56]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9133240C206B; Tue, 4 Oct 2022 00:26:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1664843199; 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=YZts7HP0P/o4y952/JJF9h4xHArVVKoewzDjO34Yvxg=; b=XXgN0QgDWgQHPrKBNaDqhD9hwcEC8VohsT0298zvmouxyxe1Wl/7l19Oy8fOss/oY5oobp CHWlEysS8lz2I14qJGyAytr3kAR4uQnob0bfdv4A1kawlm3aQcjl0tb3gmOOWKEVhBXeRL RwOLFtCtNYU6CtvBNJigQSIAsIfT2CA= X-MC-Unique: sMFqkUyLM0W277CwS9yN0Q-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 v4 1/6] hw/arm/virt: Introduce virt_set_high_memmap() helper Date: Tue, 4 Oct 2022 08:26:22 +0800 Message-Id: <20221004002627.59172-2-gshan@redhat.com> In-Reply-To: <20221004002627.59172-1-gshan@redhat.com> References: <20221004002627.59172-1-gshan@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 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, RCVD_IN_DNSWL_NONE=-0.0001, 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: 1664843431478100003 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: Eric Auger Reviewed-by: Cornelia Huck --- 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 Thu May 9 20:56:20 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=1664843431; cv=none; d=zohomail.com; s=zohoarc; b=acrD20zzSvnng+MM4jGT7VammkeeK+FetCDdWH2rQ51hNrZIIECbDxHZbt4cXXT6dUqeLGPcdhsnSCGx/LlQhFz7QjzUzKot7OfsPb+ktQwcZta04zu+BhghqQlDElX8BnognzQoulSDZlJC0/c9cSynem2WOciYPWRE8XgPU2g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1664843431; 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=0cpzWAzeOTzdJ2vfk5+Szof42wnxFA0Q8gQ7EsUznCI=; b=Ik+HUF7CvAwhJPhBFkuXzUdONxqV2CPAVJphw1KqVACOolNzc5ZnhQJL8ZJZjbHnMW0k+IiGEkO4e1Vv47UE74ErBatM6ulB/MSoVkWRozzDcgQoONkxI4lCvbIVB06HGlkF9PzyzvCMUvPyEYabh9UqfQYoOHHbGZHUdH/niR0= 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 1664843431140770.531708406997; Mon, 3 Oct 2022 17:30:31 -0700 (PDT) Received: from localhost ([::1]:49988 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ofVpN-0002E7-D1 for importer@patchew.org; Mon, 03 Oct 2022 20:30:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56612) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ofVlo-0007pi-Hq for qemu-devel@nongnu.org; Mon, 03 Oct 2022 20:26:48 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:37102) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ofVlm-0004u2-0Z for qemu-devel@nongnu.org; Mon, 03 Oct 2022 20:26:48 -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-609-6m1OstkkPH65UGsKwM3NgA-1; Mon, 03 Oct 2022 20:26:42 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id F07463C0F661; Tue, 4 Oct 2022 00:26:41 +0000 (UTC) Received: from gshan.redhat.com (vpn2-54-56.bne.redhat.com [10.64.54.56]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8FE2F40C206B; Tue, 4 Oct 2022 00:26:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1664843205; 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=0cpzWAzeOTzdJ2vfk5+Szof42wnxFA0Q8gQ7EsUznCI=; b=ganpKKmoewD5swULuN1GjEB+te19QQwX2Z8HthXPhrAcP8/H1+9/2otn1YLQDVgQs9fsoX aTpOjDBFSm/dLhvxgZB1dmLE6ENsrV0ipOVHpyALaAsBOMYmV4tq2wjjpJBOThXgyQRw90 fVIE3UAO0B4QgrZx3V1H+AXuRgffhGM= X-MC-Unique: 6m1OstkkPH65UGsKwM3NgA-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 v4 2/6] hw/arm/virt: Rename variable size to region_size in virt_set_high_memmap() Date: Tue, 4 Oct 2022 08:26:23 +0800 Message-Id: <20221004002627.59172-3-gshan@redhat.com> In-Reply-To: <20221004002627.59172-1-gshan@redhat.com> References: <20221004002627.59172-1-gshan@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 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.129.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: 1664843431473100002 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 Reviewed-by: Cornelia Huck --- 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 Thu May 9 20:56:20 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=1664843430; cv=none; d=zohomail.com; s=zohoarc; b=OBCkYF4SlUEiMgiDDH9R3Y+tRISZhf74XgZZ2MB2k5wjB4TgOA7uUJd7tTUCYh03EkIQesx9oqVExNc+BfjRa9EC+DMWBGtNcr8ti0QCFBgHq53mL8bTcrr0qBPOH0ssgs92kRL03a3kqU8iNFb53E78KE8Dv88mCpnCogs+Heg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1664843430; 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=ZiywPYaQZ9wLpbRIRk+IduR7ifaJejpEMgYyhAciTtM=; b=jgW9RfsBDGJhVxS6lFnPn97wmRMM0foD/xOZ0D8DGjH+ol7yHPGYaSGvOpfa9PkHeCvWLBxdtilGAyKbjYfBFjYIGOI0BRnkBP2KGLdg25tNokGyIqxO8AeRZXypP6TPhKmHo+1d05Urv8c/47Vglfn0bgABRvcHnDlyQ4v5ddw= 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 1664843430973376.8975231256693; Mon, 3 Oct 2022 17:30:30 -0700 (PDT) Received: from localhost ([::1]:49992 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ofVpN-0002Hu-PH for importer@patchew.org; Mon, 03 Oct 2022 20:30:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56614) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ofVlu-0007t1-2F for qemu-devel@nongnu.org; Mon, 03 Oct 2022 20:26:54 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:32739) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ofVls-0004uS-1f for qemu-devel@nongnu.org; Mon, 03 Oct 2022 20:26:53 -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-611-r3eI5_sPMDmBPEcC4rqxIA-1; Mon, 03 Oct 2022 20:26:46 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 138983C0F661; Tue, 4 Oct 2022 00:26:46 +0000 (UTC) Received: from gshan.redhat.com (vpn2-54-56.bne.redhat.com [10.64.54.56]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9046A40C206B; Tue, 4 Oct 2022 00:26:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1664843211; 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=ZiywPYaQZ9wLpbRIRk+IduR7ifaJejpEMgYyhAciTtM=; b=IpPKDmCogXsXuCEWLgahTSfpKXuKVFh2P5M7nBKs6Y0dkOwPsLCeaOUULNnu1QcsqUePod O1I7uyiLAOLexqO+1ZdGShCRm6VjFdo51yIZD53HMAEByb4RydT0hwIoskHVDj7AmLgH2l PWxCFw4LoExhRegYHvgCzq9boFLhipQ= X-MC-Unique: r3eI5_sPMDmBPEcC4rqxIA-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 v4 3/6] hw/arm/virt: Introduce variable region_base in virt_set_high_memmap() Date: Tue, 4 Oct 2022 08:26:24 +0800 Message-Id: <20221004002627.59172-4-gshan@redhat.com> In-Reply-To: <20221004002627.59172-1-gshan@redhat.com> References: <20221004002627.59172-1-gshan@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 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.129.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: 1664843431471100001 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 Reviewed-by: Cornelia Huck --- 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 Thu May 9 20:56:20 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=1664843905; cv=none; d=zohomail.com; s=zohoarc; b=OXjd6u2z0u/4W32IxSCH7q++mL1r154jqVkceSgx7xce5YslS9P1VcaJewSZQi41bOoQR6JAtOpM85wazAt7tridzJteDelILpHGp2ARU+kraxgksm8HbVxvX/qShxyfubbqGZ9GqzSABuv9w2/Nx0AN5SsHzxofx6u9TKZ++i0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1664843905; 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=g9OVHLht1sJiIpjMrBxyf/vibyZGmXv0kUqwcs4vbDo=; b=HcBBWSTK2WVRJhUq/7lD7XESufX6RG4+MH6pxlJjbV7i0hkHxBH/zxk+FLPAhOya/azT9QaiYgyqvFOwZJYLCZqDvbC/ipJGKzRC/3bXL+mgxwMnk1QfX/Gk6LUQEVQaFzZvA9H8DSMbMXD6gDBmT8yH43BoxQiLWb40zqNyvXk= 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 166484390561289.22025867767286; Mon, 3 Oct 2022 17:38:25 -0700 (PDT) Received: from localhost ([::1]:38500 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ofVx2-0000nu-3k for importer@patchew.org; Mon, 03 Oct 2022 20:38:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56616) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ofVlu-0007uQ-Hq for qemu-devel@nongnu.org; Mon, 03 Oct 2022 20:26:54 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:22910) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ofVls-0004uY-JL for qemu-devel@nongnu.org; Mon, 03 Oct 2022 20:26:54 -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-357-30PZtRZXNFeBV-MyObZVPw-1; Mon, 03 Oct 2022 20:26:50 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5FA3D29ABA2B; Tue, 4 Oct 2022 00:26:50 +0000 (UTC) Received: from gshan.redhat.com (vpn2-54-56.bne.redhat.com [10.64.54.56]) by smtp.corp.redhat.com (Postfix) with ESMTP id A5A8C40C206B; Tue, 4 Oct 2022 00:26:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1664843212; 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=g9OVHLht1sJiIpjMrBxyf/vibyZGmXv0kUqwcs4vbDo=; b=hPoZefuI+ioj6pLJxr4ix+HeNhns81k/Ctp8l5JdxsPFpgVPnW6AqzwQW3xGx8nkT6ju7e PmNIKRJ53Itw+JM++/pKg227dAn8qK1MvvGde1gn64ctcoCpiv0Tfq6kVB8H7rLTmsV2ie CLIWTCwIjv9uGaZ/Hg86Zva4gb1zy5U= X-MC-Unique: 30PZtRZXNFeBV-MyObZVPw-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 v4 4/6] hw/arm/virt: Introduce virt_get_high_memmap_enabled() helper Date: Tue, 4 Oct 2022 08:26:25 +0800 Message-Id: <20221004002627.59172-5-gshan@redhat.com> In-Reply-To: <20221004002627.59172-1-gshan@redhat.com> References: <20221004002627.59172-1-gshan@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 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.129.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: 1664843906843100001 Content-Type: text/plain; charset="utf-8" This introduces virt_get_high_memmap_enabled() helper, which returns the pointer to vms->highmem_{redists, ecam, mmio}. The pointer will be used in the subsequent patches. No functional change intended. Signed-off-by: Gavin Shan --- hw/arm/virt.c | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/hw/arm/virt.c b/hw/arm/virt.c index b0b679d1f4..59de7b78b5 100644 --- a/hw/arm/virt.c +++ b/hw/arm/virt.c @@ -1689,14 +1689,29 @@ static uint64_t virt_cpu_mp_affinity(VirtMachineSta= te *vms, int idx) return arm_cpu_mp_affinity(idx, clustersz); } =20 +static inline bool *virt_get_high_memmap_enabled(VirtMachineState *vms, + int index) +{ + bool *enabled_array[] =3D { + &vms->highmem_redists, + &vms->highmem_ecam, + &vms->highmem_mmio, + }; + + assert(index - VIRT_LOWMEMMAP_LAST < ARRAY_SIZE(enabled_array)); + + return enabled_array[index - VIRT_LOWMEMMAP_LAST]; +} + 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_enabled =3D virt_get_high_memmap_enabled(vms, i); region_base =3D ROUND_UP(base, extended_memmap[i].size); region_size =3D extended_memmap[i].size; =20 @@ -1714,18 +1729,7 @@ static void virt_set_high_memmap(VirtMachineState *v= ms, vms->highest_gpa =3D region_base + region_size - 1; } =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; - } - + *region_enabled &=3D fits; base =3D region_base + region_size; } } --=20 2.23.0 From nobody Thu May 9 20:56:20 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=1664844178; cv=none; d=zohomail.com; s=zohoarc; b=DSw82IlxUPvSh3hebxeVkB0KQQ6n8tZ08vJHaU+RMSESuY9OcLaeEKb8EeTa1JeJ83HtMNT8ARjtHqYp+7g4b/4TF78rvPOPtSp5w3ks/3Qb+J9A+VQEcniVx3MDvOj5iub6KhNSYdfvqeID4M3RILieDFL0smeRdFqw3El/VJA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1664844178; 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=9AsOGcv3LZhphPkFGMW7RDSQQeSlyfk9xRX48/WO+SE=; b=doUp8SfEVBhzlvsHlyXlXqC5dqnVoKQ6Kyvxn+4qO6Hu3uu8O1Slgmp83mz4ids0XeW4MuKRpmGE93iM3b0WySLFp0hWJjTttaH+hqF7D/pqSX6ebVIjin28X5eN152bQAwSi3hNvwpXIrdgR6dlAFxGTaKNRz/XFsCBa1hZBjE= 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 1664844178523598.3294189143281; Mon, 3 Oct 2022 17:42:58 -0700 (PDT) Received: from localhost ([::1]:47602 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ofW1Q-0006Un-9L for importer@patchew.org; Mon, 03 Oct 2022 20:42:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47514) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ofVm8-0008HE-LR for qemu-devel@nongnu.org; Mon, 03 Oct 2022 20:27:08 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:38943) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ofVm7-0004wq-1B for qemu-devel@nongnu.org; Mon, 03 Oct 2022 20:27:08 -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-306-4qmv38jMOb6kLY0wIZiYxw-1; Mon, 03 Oct 2022 20:26:56 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 96DE2811726; Tue, 4 Oct 2022 00:26:55 +0000 (UTC) Received: from gshan.redhat.com (vpn2-54-56.bne.redhat.com [10.64.54.56]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2F43240C206B; Tue, 4 Oct 2022 00:26:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1664843226; 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=9AsOGcv3LZhphPkFGMW7RDSQQeSlyfk9xRX48/WO+SE=; b=SH68dfTB3f9eTvE0CuZ7BHy9grfoiSk8+nupLbD0nUSYG7N08jccWb2XSVNBgOtXGEKFpv jw+kMKJnZMVdCJGF97Th8Xjesv5kGhvpXB/ST3JUHBQXdDBUeXxdSuaJToayLlrMSkGDDx 7D44fuPZvwrmPxR/7eiriJhZR5KkRF4= X-MC-Unique: 4qmv38jMOb6kLY0wIZiYxw-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 v4 5/6] hw/arm/virt: Improve high memory region address Date: Tue, 4 Oct 2022 08:26:26 +0800 Message-Id: <20221004002627.59172-6-gshan@redhat.com> In-Reply-To: <20221004002627.59172-1-gshan@redhat.com> References: <20221004002627.59172-1-gshan@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 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, RCVD_IN_DNSWL_NONE=-0.0001, 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: 1664844179647100001 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). 'vms->high_compact' is false for now, meaning that we don't have any behavior changes until it becomes configurable through property 'compact-highmem' in next patch. Signed-off-by: Gavin Shan --- hw/arm/virt.c | 19 ++++++++++++------- include/hw/arm/virt.h | 1 + 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/hw/arm/virt.c b/hw/arm/virt.c index 59de7b78b5..4164da49e9 100644 --- a/hw/arm/virt.c +++ b/hw/arm/virt.c @@ -1715,9 +1715,6 @@ static void virt_set_high_memmap(VirtMachineState *vm= s, 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; - /* * Check each device to see if they fit in the PA space, * moving highest_gpa as we go. @@ -1725,12 +1722,20 @@ 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) { + if (*region_enabled && fits) { + vms->memmap[i].base =3D region_base; + vms->memmap[i].size =3D region_size; vms->highest_gpa =3D region_base + region_size - 1; + 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; + } + } } - - *region_enabled &=3D fits; - base =3D region_base + region_size; } } =20 diff --git a/include/hw/arm/virt.h b/include/hw/arm/virt.h index 6ec479ca2b..709f623741 100644 --- a/include/hw/arm/virt.h +++ b/include/hw/arm/virt.h @@ -144,6 +144,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 From nobody Thu May 9 20:56:20 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=1664843914; cv=none; d=zohomail.com; s=zohoarc; b=TvYUCVZlG/7LEQOLZx5475hExsNwU/uhqj+bJikQKjuF/X2+ERCxzcF0s25Wvr2qX/vQsTbQSIkawK+ZwxV4ncrBHgCbG40LKdBG7n4fn5IckGtgNX3oQMwY7cNwIcKcSZuFN45d4UdduGltI5Pp7DH+Xx0GyXPU7NLukDqHPxs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1664843914; 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=rRi4Hk58Gd7gcvdQY51cHkNMV/C6OXjM1h5tLeypFjI=; b=WzLI2Zv4SMFQitESM1uFk3PFEeBe7fXFdr8q/aEGMJMRm2h2caLDhiozto/AI78bES+0q1slMNEzaUTrFyvGSTeYPfA6dfsVuNaHPgxUL56GzjyqycYHRayVbhNVUi7Q990BsUVwK5DCq0WInQGqqaO2y50SXX9wm/hLDnmMceY= 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 1664843914130406.6575917544923; Mon, 3 Oct 2022 17:38:34 -0700 (PDT) Received: from localhost ([::1]:51904 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ofVxA-0001AR-R4 for importer@patchew.org; Mon, 03 Oct 2022 20:38:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47510) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ofVm6-0008EG-AM for qemu-devel@nongnu.org; Mon, 03 Oct 2022 20:27:06 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:31971) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ofVm4-0004wH-JA for qemu-devel@nongnu.org; Mon, 03 Oct 2022 20:27:06 -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-394-UAVtZgmRPqSa0VE98nJlnA-1; Mon, 03 Oct 2022 20:26:59 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5F6BF3C0F661; Tue, 4 Oct 2022 00:26:59 +0000 (UTC) Received: from gshan.redhat.com (vpn2-54-56.bne.redhat.com [10.64.54.56]) by smtp.corp.redhat.com (Postfix) with ESMTP id 30F2C40C206B; Tue, 4 Oct 2022 00:26:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1664843224; 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=rRi4Hk58Gd7gcvdQY51cHkNMV/C6OXjM1h5tLeypFjI=; b=gZ+nnONt/s9Mlw0/6hglV5DFimoafxYgC8bvH3WZBjnjDeRf64Htqdbsmh1dued+C9owrq GDa/Cc3FzSzrT8tvNfvPtsudHPNcMIBLOe8liygY3BXoIJzV7rL7Md8I24wI/arAneyEx3 F4gvEr0UYUdwnPQnBNQF9LFUXerr5+g= X-MC-Unique: UAVtZgmRPqSa0VE98nJlnA-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 v4 6/6] hw/arm/virt: Add 'compact-highmem' property Date: Tue, 4 Oct 2022 08:26:27 +0800 Message-Id: <20221004002627.59172-7-gshan@redhat.com> In-Reply-To: <20221004002627.59172-1-gshan@redhat.com> References: <20221004002627.59172-1-gshan@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 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, RCVD_IN_DNSWL_NONE=-0.0001, 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: 1664843914554100001 Content-Type: text/plain; charset="utf-8" After the improvement to high memory region address assignment is applied, the memory layout can be changed, introducing possible migration breakage. For example, VIRT_HIGH_PCIE_MMIO memory region is disabled or enabled when the optimization is applied or not, with the following configuration. 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,compact-highmem=3D{on, off} \ -m 4G,maxmem=3D511G -monitor stdio Region compact-highmem=3Doff compact-highmem=3Don ---------------------------------------------------------------- RAM [1GB 512GB] [1GB 512GB] HIGH_GIC_REDISTS [512GB 512GB+64MB] [disabled] HIGH_PCIE_ECAM [512GB+256MB 512GB+512MB] [disabled] HIGH_PCIE_MMIO [disabled] [512GB 1TB] 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, 'compact-highmem' property is added so that the optimization can be explicitly enabled or disabled on all machine types by users. Signed-off-by: Gavin Shan --- docs/system/arm/virt.rst | 4 ++++ hw/arm/virt.c | 47 ++++++++++++++++++++++++++++++++++++++++ include/hw/arm/virt.h | 1 + 3 files changed, 52 insertions(+) diff --git a/docs/system/arm/virt.rst b/docs/system/arm/virt.rst index 20442ea2c1..75bf5a4994 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 +compact-highmem + 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 4164da49e9..9fe65a2ae1 100644 --- a/hw/arm/virt.c +++ b/hw/arm/virt.c @@ -174,6 +174,27 @@ static const MemMapEntry base_memmap[] =3D { * Note the extended_memmap is sized so that it eventually also includes t= he * base_memmap entries (VIRT_HIGH_GIC_REDIST2 index is greater than the la= st * index of base_memmap). + * + * The addresses assigned to these regions are affected by 'compact-highme= m' + * property, which is to enable or disable the compact space in the Highmem + * IO regions. For example, VIRT_HIGH_PCIE_MMIO can be disabled or enabled + * depending on the property in the following scenario. + * + * 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,compact-highmem=3D{on, off} \ + * -m 4G,maxmem=3D511G -monitor stdio + * + * Region compact-highmem=3Doff compact-highmem=3Don + * ---------------------------------------------------------------- + * RAM [1GB 512GB] [1GB 512GB] + * HIGH_GIC_REDISTS [512GB 512GB+64MB] [disabled] + * HIGH_PCIE_ECAM [512GB+256GB 512GB+512MB] [disabled] + * HIGH_PCIE_MMIO [disabled] [512GB 1TB] */ static MemMapEntry extended_memmap[] =3D { /* Additional 64 MB redist region (can contain up to 512 redistributor= s) */ @@ -2349,6 +2370,20 @@ static void virt_set_highmem(Object *obj, bool value= , Error **errp) vms->highmem =3D value; } =20 +static bool virt_get_compact_highmem(Object *obj, Error **errp) +{ + VirtMachineState *vms =3D VIRT_MACHINE(obj); + + return vms->highmem_compact; +} + +static void virt_set_compact_highmem(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); @@ -2967,6 +3002,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, "compact-highmem", + virt_get_compact_highmem, + virt_set_compact_highmem); + object_class_property_set_description(oc, "compact-highmem", + "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", @@ -3051,6 +3093,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; @@ -3120,8 +3163,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 709f623741..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; --=20 2.23.0