From nobody Wed May 8 17:06:48 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=1659415758; cv=none; d=zohomail.com; s=zohoarc; b=iEwCFp/2oP+HmP/9KQxxGCBN8MbUNPn8rx0HjG++LuAXOqRPYcjRGKABwIvgqatQc5sJpbPSpZwPE0ikYExXYENcsN+L9sCGoIzP9tvsVV9SvWvPGAbQehJQIsz3qG1/DS9XaZKxceAX8BHhQjwU9NvKIgKy1F9+RRVRAEO+YPM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1659415758; 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=Fyr89UPFJ2icMpRdGHU+/6Vbe4UOerIOwE1Jhy475s0=; b=HoSOec7slOqgjVAoJRaWSALuWDbScv5FOU7zHCGtVpQSE17wrBoyPqlo/EqUIODJ3hpaBYZYH9dPONY3E7ENXcSHZoLS7XNkOWSfjh2Qvzd8SQjORxAd8iy+qzr4AnDCdRLydMDZgVijwb1nwFu5mt9ZfmqDADfBNsOofE1ZaMw= 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 1659415758313119.43259311517897; Mon, 1 Aug 2022 21:49:18 -0700 (PDT) Received: from localhost ([::1]:59794 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oIjqG-0002Tw-Cx for importer@patchew.org; Tue, 02 Aug 2022 00:49:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50756) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oIjo8-0008C7-Nd for qemu-devel@nongnu.org; Tue, 02 Aug 2022 00:47:04 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:52855) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oIjo5-0004WI-Fq for qemu-devel@nongnu.org; Tue, 02 Aug 2022 00:47:04 -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-553-AC9dNuXeO-idZDuM0QqtuQ-1; Tue, 02 Aug 2022 00:45:42 -0400 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 338DA802D2C; Tue, 2 Aug 2022 04:45:42 +0000 (UTC) Received: from gshan.redhat.com (vpn2-54-18.bne.redhat.com [10.64.54.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id 125D7492C3B; Tue, 2 Aug 2022 04:45:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1659415621; 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=Fyr89UPFJ2icMpRdGHU+/6Vbe4UOerIOwE1Jhy475s0=; b=b6zIq90Z+Zm0x2DSRTOipHfy/WWrd5f46tBrtZbyl/wnR0rb8XHacnHa0upv++fSq3oGrP OthF+BzsPJPDM8ZtocnsyR93osdNcNGexevA79zuhInqO9JogBRNjG0ib4uqLJ+hV/3MBc J+88R0aUz9gjlwO0oPy0TBTe/w+ezy8= X-MC-Unique: AC9dNuXeO-idZDuM0QqtuQ-1 From: Gavin Shan To: qemu-arm@nongnu.org Cc: qemu-devel@nongnu.org, peter.maydell@linaro.org, richard.henderson@linaro.org, eric.auger@redhat.com, cohuck@redhat.com, zhenyzha@redhat.com, shan.gavin@gmail.com Subject: [PATCH 1/2] hw/arm/virt: Improve address assignment for highmem IO regions Date: Tue, 2 Aug 2022 14:45:28 +0800 Message-Id: <20220802064529.547361-2-gshan@redhat.com> In-Reply-To: <20220802064529.547361-1-gshan@redhat.com> References: <20220802064529.547361-1-gshan@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.85 on 10.11.54.10 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: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, 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, T_SCC_BODY_TEXT_LINE=-0.01 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: 1659415759911100003 Content-Type: text/plain; charset="utf-8" There are 3 highmem IO regions as below. They can be disabled in two situations: (a) The specific region is disabled by user. (b) The specific region doesn't fit in the PA space. However, the base address and highest_gpa are still updated no matter if the region is enabled or disabled. It's incorrectly incurring waste in the PA space. Improve address assignment for highmem IO regions to avoid the waste in the PA space by putting the logic into virt_memmap_fits(). Signed-off-by: Gavin Shan --- hw/arm/virt.c | 54 +++++++++++++++++++++++++++++---------------------- 1 file changed, 31 insertions(+), 23 deletions(-) diff --git a/hw/arm/virt.c b/hw/arm/virt.c index 9633f822f3..bc0cd218f9 100644 --- a/hw/arm/virt.c +++ b/hw/arm/virt.c @@ -1688,6 +1688,34 @@ static uint64_t virt_cpu_mp_affinity(VirtMachineStat= e *vms, int idx) return arm_cpu_mp_affinity(idx, clustersz); } =20 +static void virt_memmap_fits(VirtMachineState *vms, int index, + bool *enabled, hwaddr *base, int pa_bits) +{ + hwaddr size =3D extended_memmap[index].size; + + /* The region will be disabled if its size isn't given */ + if (!*enabled || !size) { + *enabled =3D false; + vms->memmap[index].base =3D 0; + vms->memmap[index].size =3D 0; + return; + } + + /* + * Check if the memory region fits in the PA space. The memory map + * and highest_gpa are updated if it fits. Otherwise, it's disabled. + */ + *enabled =3D (ROUND_UP(*base, size) + size <=3D BIT_ULL(pa_bits)); + if (*enabled) { + *base =3D ROUND_UP(*base, size); + vms->memmap[index].base =3D *base; + vms->memmap[index].size =3D size; + vms->highest_gpa =3D *base + size - 1; + + *base =3D *base + size; + } +} + static void virt_set_memmap(VirtMachineState *vms, int pa_bits) { MachineState *ms =3D MACHINE(vms); @@ -1744,37 +1772,17 @@ static void virt_set_memmap(VirtMachineState *vms, = int pa_bits) 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; + virt_memmap_fits(vms, i, &vms->highmem_redists, &base, pa_bits= ); break; case VIRT_HIGH_PCIE_ECAM: - vms->highmem_ecam &=3D fits; + virt_memmap_fits(vms, i, &vms->highmem_ecam, &base, pa_bits); break; case VIRT_HIGH_PCIE_MMIO: - vms->highmem_mmio &=3D fits; + virt_memmap_fits(vms, i, &vms->highmem_mmio, &base, pa_bits); break; } - - base +=3D size; } =20 if (device_memory_size > 0) { --=20 2.23.0 From nobody Wed May 8 17:06:48 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=1659415769; cv=none; d=zohomail.com; s=zohoarc; b=g3H2+nRiRdcoACaK181qWncy1P8TgyPssDloKrz2M9nAQA+3eZvdk25G3jjyoCa62J7Si5O21ATf89gZQLvqR/JGfcW1kX56vJ1421jIh3P8/JGHc7ZEdzmL7629JnbiKZB3x+IVfktXVWgI09Tpa8S4BXpWttLru+BPkxveEZA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1659415769; 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=OzSd66vMiAGfWp3SjT783MBf4FZiMzQ6hwrmJytEckg=; b=ERX2CT8SmOevw0XLqhucgQaldrg8xyNSn+Hj0staqNHxQUha8n0mm8NPoIdkPb1f7aDpzhu/n4gWu9Jm6J+5ouPjs2UoO0aMYEQoRZoU1wU76Ni+ewvPFkYGT6mKOUIhZUuFVWzaRQCiuHXrGGZdfKfurs8jdYZq9/L2ge7+D0E= 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 1659415769114920.1034390827446; Mon, 1 Aug 2022 21:49:29 -0700 (PDT) Received: from localhost ([::1]:60938 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oIjqR-0003IO-6Y for importer@patchew.org; Tue, 02 Aug 2022 00:49:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50750) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oIjo8-0008Bx-GQ for qemu-devel@nongnu.org; Tue, 02 Aug 2022 00:47:04 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:51791) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oIjo5-0004W7-EJ for qemu-devel@nongnu.org; Tue, 02 Aug 2022 00:47:04 -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-597-Dfl41vLYOuqBMYLlAUmkDg-1; Tue, 02 Aug 2022 00:45:46 -0400 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4D9833C01DF7; Tue, 2 Aug 2022 04:45:46 +0000 (UTC) Received: from gshan.redhat.com (vpn2-54-18.bne.redhat.com [10.64.54.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0570B492C3B; Tue, 2 Aug 2022 04:45:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1659415620; 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=OzSd66vMiAGfWp3SjT783MBf4FZiMzQ6hwrmJytEckg=; b=KMDRPsqS6IDbxPw+hL8nW/yAnKcRrpc8HRmlBoSK5qN6cLbdK8izEtyXdgWr8AXNv4WM0h lxR56Nf/5L5oWZa0/qD3zaGE1c9yZ3ElGtv//DGn9QjWTBNU5L2x7Qtg+P8hzWvncFVltg d8b2/oGGQAhI9uzWenkvS0yezhEvMQ4= X-MC-Unique: Dfl41vLYOuqBMYLlAUmkDg-1 From: Gavin Shan To: qemu-arm@nongnu.org Cc: qemu-devel@nongnu.org, peter.maydell@linaro.org, richard.henderson@linaro.org, eric.auger@redhat.com, cohuck@redhat.com, zhenyzha@redhat.com, shan.gavin@gmail.com Subject: [PATCH 2/2] hw/arm/virt: Warn when high memory region is disabled Date: Tue, 2 Aug 2022 14:45:29 +0800 Message-Id: <20220802064529.547361-3-gshan@redhat.com> In-Reply-To: <20220802064529.547361-1-gshan@redhat.com> References: <20220802064529.547361-1-gshan@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.85 on 10.11.54.10 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: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, 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, T_SCC_BODY_TEXT_LINE=-0.01 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: 1659415770035100005 Content-Type: text/plain; charset="utf-8" When one specific high memory region is disabled due to the PA limit, it'd better to warn user about that. The warning messages help to identify the cause in some cases. For example, PCIe device that has large MMIO bar, to be covered by PCIE_MMIO high memory region, won't work properly if PCIE_MMIO high memory region is disabled due to the PA limit. Signed-off-by: Gavin Shan --- hw/arm/virt.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/hw/arm/virt.c b/hw/arm/virt.c index bc0cd218f9..c91756e33d 100644 --- a/hw/arm/virt.c +++ b/hw/arm/virt.c @@ -1691,6 +1691,7 @@ static uint64_t virt_cpu_mp_affinity(VirtMachineState= *vms, int idx) static void virt_memmap_fits(VirtMachineState *vms, int index, bool *enabled, hwaddr *base, int pa_bits) { + const char *region_name; hwaddr size =3D extended_memmap[index].size; =20 /* The region will be disabled if its size isn't given */ @@ -1713,6 +1714,23 @@ static void virt_memmap_fits(VirtMachineState *vms, = int index, vms->highest_gpa =3D *base + size - 1; =20 *base =3D *base + size; + } else { + switch (index) { + case VIRT_HIGH_GIC_REDIST2: + region_name =3D "GIC_REDIST2"; + break; + case VIRT_HIGH_PCIE_ECAM: + region_name =3D "PCIE_ECAM"; + break; + case VIRT_HIGH_PCIE_MMIO: + region_name =3D "PCIE_MMIO"; + break; + default: + region_name =3D "unknown"; + } + + warn_report("Disabled %s high memory region due to PA limit", + region_name); } } =20 --=20 2.23.0