From nobody Mon Feb 9 12:26:19 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+98125+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+98125+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1673013852; cv=none; d=zohomail.com; s=zohoarc; b=iWhTxGmWZytX1GVod3xWypvsEvhY4qp4H90Mk+V7RKVYWxCx9VXifImTF3ntfL0J7TxVy28cbyZoToh4i5PNicQkSUjwKklOp1CoX3g8QH3UZL8Auq+oWqw2nhfYuVJuVJ1HLWldVT1zPlX+QFaetAJkG1vKzUZn2CErUo33534= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1673013852; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=Oa/VsSOCNIJIZ+iTemC3ehdIMv0ojXsG0L5dkXAzd8o=; b=TAVVaVYi1MHGYS4OJtxhkPj4LWsg5obIgmxwiob54irQ7SH6g7emoXRZH1DArnxcJRZnCA2hIdWm1wUZujfBTwuPTmeWJrTOHKv3+mdtMSvC/UddMQivUv3PVbSG96gk7aKxCvBhB9Fk/O7Q6dsTEK3K8tgsjogJg8ILppVwGPE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+98125+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1673013852223385.9864515589994; Fri, 6 Jan 2023 06:04:12 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id SGFTYY1788612xSeUp3qEGWl; Fri, 06 Jan 2023 06:04:11 -0800 X-Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.groups.io with SMTP id smtpd.web10.14053.1673013851337072182 for ; Fri, 06 Jan 2023 06:04:11 -0800 X-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-31-oCCWcG9mPc-dlQae3bi7cg-1; Fri, 06 Jan 2023 09:04:07 -0500 X-MC-Unique: oCCWcG9mPc-dlQae3bi7cg-1 X-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 BFCA53C025D1; Fri, 6 Jan 2023 14:04:06 +0000 (UTC) X-Received: from sirius.home.kraxel.org (unknown [10.39.192.238]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5178840C2064; Fri, 6 Jan 2023 14:04:06 +0000 (UTC) X-Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 346D518009AB; Fri, 6 Jan 2023 15:04:03 +0100 (CET) From: "Gerd Hoffmann" To: devel@edk2.groups.io Cc: Ard Biesheuvel , =?UTF-8?q?L=C3=A1szl=C3=B3=20=C3=89rsek?= , Jordan Justen , Pawel Polawski , Oliver Steffen , Jiewen Yao , Gerd Hoffmann Subject: [edk2-devel] [PATCH 2/2] OvmfPkg/PlatformInitLib: check 64bit mmio window for resource conflicts Date: Fri, 6 Jan 2023 15:04:03 +0100 Message-Id: <20230106140403.2889131-3-kraxel@redhat.com> In-Reply-To: <20230106140403.2889131-1-kraxel@redhat.com> References: <20230106140403.2889131-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,kraxel@redhat.com X-Gm-Message-State: 7sA7rhWWZeYWNx3MQEfYlWvxx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1673013851; bh=AzYhHPAUYi77xgCpSY0/eLXBFpDPTVfZOFH5os/uTPk=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=dcpsNkNbsmI2Aya0gEaO2NnuNxDDqoIv3qGxM7YoMEq1+MshbyT/qaJ+Pl1PCn8wTaF l1OT3vS8XfSGU4JBdoSVCpgg6YMP8wto0OQ852SOeBx5rBbo4r+LNcKFxA+QdAxNxzLFu yfM9NWvn5FRCEuFWJPYdFMj/0lAne7VkIdM= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1673013852882100004 Content-Type: text/plain; charset="utf-8"; x-default="true" Add new operation mode to PlatformScanOrAdd64BitE820Ram() which checks whenever any reservations from the qemu e820 table overlap with the mmio window. Should that be the case move it to avoid the conflict. Signed-off-by: Gerd Hoffmann --- OvmfPkg/Library/PlatformInitLib/MemDetect.c | 47 ++++++++++++++++++--- 1 file changed, 41 insertions(+), 6 deletions(-) diff --git a/OvmfPkg/Library/PlatformInitLib/MemDetect.c b/OvmfPkg/Library/= PlatformInitLib/MemDetect.c index 1255d6300fdd..4f5a04832a4e 100644 --- a/OvmfPkg/Library/PlatformInitLib/MemDetect.c +++ b/OvmfPkg/Library/PlatformInitLib/MemDetect.c @@ -126,6 +126,12 @@ PlatformQemuUc32BaseInitialization ( entries that start at or above 4GB. It also produces HOBs for reserved entries. =20 + @param[in out] PlatformInfoHob If Lowmemory PlatformInfoHob is not NULL, + then PlatformScanOrAdd64BitE820Ram() che= cks + the 64bit PCI MMIO window against confli= cts + with e820 reservations from qemu. If ne= eded + the MMIO window will be moved down. + @param[out] LowMemory If Lowmemory is not NULL, then Lowmemory MaxAddre= ss holds the amout of emory below 4G on output. =20 @@ -147,9 +153,10 @@ PlatformQemuUc32BaseInitialization ( STATIC EFI_STATUS PlatformScanOrAdd64BitE820Ram ( - IN BOOLEAN AddHighHob, - OUT UINT64 *LowMemory OPTIONAL, - OUT UINT64 *MaxAddress OPTIONAL + IN BOOLEAN AddHighHob, + IN OUT EFI_HOB_PLATFORM_INFO *PlatformInfoHob OPTIONAL, + OUT UINT64 *LowMemory OPTIONAL, + OUT UINT64 *MaxAddress OPTIONAL ) { EFI_STATUS Status; @@ -249,6 +256,33 @@ PlatformScanOrAdd64BitE820Ram ( E820Entry.Length ); } + + if (PlatformInfoHob) { + UINT64 IntersectionBase =3D MAX ( + E820Entry.BaseAddr, + PlatformInfoHob->PcdPciMmio64Base + ); + UINT64 IntersectionEnd =3D MIN ( + E820Entry.BaseAddr + E820Entry.Length, + PlatformInfoHob->PcdPciMmio64Base + + PlatformInfoHob->PcdPciMmio64Size + ); + + if (IntersectionBase < IntersectionEnd) { + // have overlap, so move mmio window down from end of address sp= ace + UINT64 NewBase =3D (PlatformInfoHob->PcdPciMmio64Base - + PlatformInfoHob->PcdPciMmio64Size); + + DEBUG (( + DEBUG_INFO, + "%a: move mmio: 0x%Lx =3D> %Lx\n", + __FUNCTION__, + PlatformInfoHob->PcdPciMmio64Base, + NewBase + )); + PlatformInfoHob->PcdPciMmio64Base =3D NewBase; + } + } } } =20 @@ -340,7 +374,7 @@ PlatformGetSystemMemorySizeBelow4gb ( return (UINT32)GetHighestSystemMemoryAddressFromPvhMemmap (TRUE); } =20 - Status =3D PlatformScanOrAdd64BitE820Ram (FALSE, &LowerMemorySize, NULL); + Status =3D PlatformScanOrAdd64BitE820Ram (FALSE, NULL, &LowerMemorySize,= NULL); if ((Status =3D=3D EFI_SUCCESS) && (LowerMemorySize > 0)) { return (UINT32)LowerMemorySize; } @@ -412,7 +446,7 @@ PlatformGetFirstNonAddress ( // Otherwise, get the flat size of the memory above 4GB from the CMOS (w= hich // can only express a size smaller than 1TB), and add it to 4GB. // - Status =3D PlatformScanOrAdd64BitE820Ram (FALSE, NULL, &FirstNonAddress); + Status =3D PlatformScanOrAdd64BitE820Ram (FALSE, NULL, NULL, &FirstNonAd= dress); if (EFI_ERROR (Status)) { FirstNonAddress =3D BASE_4GB + PlatformGetSystemMemorySizeAbove4gb (); } @@ -648,6 +682,7 @@ PlatformDynamicMmioWindow ( DEBUG ((DEBUG_INFO, "%a: MMIO Space 0x%Lx (%Ld GB)\n", __func__, Mmi= oSpace, RShiftU64 (MmioSpace, 30))); PlatformInfoHob->PcdPciMmio64Size =3D MmioSpace; PlatformInfoHob->PcdPciMmio64Base =3D AddrSpace - MmioSpace; + PlatformScanOrAdd64BitE820Ram (FALSE, PlatformInfoHob, NULL, NULL); } else { DEBUG ((DEBUG_INFO, "%a: using classic mmio window\n", __func__)); } @@ -960,7 +995,7 @@ PlatformQemuInitializeRam ( // entries. Otherwise, create a single memory HOB with the flat >=3D4GB // memory size read from the CMOS. // - Status =3D PlatformScanOrAdd64BitE820Ram (TRUE, NULL, NULL); + Status =3D PlatformScanOrAdd64BitE820Ram (TRUE, NULL, NULL, NULL); if (EFI_ERROR (Status)) { UpperMemorySize =3D PlatformGetSystemMemorySizeAbove4gb (); if (UpperMemorySize !=3D 0) { --=20 2.39.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#98125): https://edk2.groups.io/g/devel/message/98125 Mute This Topic: https://groups.io/mt/96093486/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-