From mboxrd@z Thu Jan 1 00:00:00 1970 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 Authentication-Results: mx.groups.io; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=UzJsDMIM; spf=pass (domain: redhat.com, ip: 170.10.129.124, mailfrom: kraxel@redhat.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1673013850; 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=G6VlaX/0umtvCvQ0xsAu2Xdz1kd45Wv4v+sbN12PD3g=; b=UzJsDMIM9SRZPUn8AjEwQX5qiStKKcNcj86f7F0jirGd+XIJ7ziFTux/74QFjHeokfSI5G PZaph/JtPSOt3PXt+Os2wseN40muRVXL1YzGqq5FkfWj1xaYgA1XShWZOBxJ0RLpxfxHzP t/1sPUdGWoaEOK3yq4W16cSVnHa5Ibw= 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 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) 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) 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: [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 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; 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. + @param[in out] PlatformInfoHob If Lowmemory PlatformInfoHob is not NULL, + then PlatformScanOrAdd64BitE820Ram() checks + the 64bit PCI MMIO window against conflicts + with e820 reservations from qemu. If needed + the MMIO window will be moved down. + @param[out] LowMemory If Lowmemory is not NULL, then Lowmemory MaxAddress holds the amout of emory below 4G on output. @@ -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 = MAX ( + E820Entry.BaseAddr, + PlatformInfoHob->PcdPciMmio64Base + ); + UINT64 IntersectionEnd = MIN ( + E820Entry.BaseAddr + E820Entry.Length, + PlatformInfoHob->PcdPciMmio64Base + + PlatformInfoHob->PcdPciMmio64Size + ); + + if (IntersectionBase < IntersectionEnd) { + // have overlap, so move mmio window down from end of address space + UINT64 NewBase = (PlatformInfoHob->PcdPciMmio64Base - + PlatformInfoHob->PcdPciMmio64Size); + + DEBUG (( + DEBUG_INFO, + "%a: move mmio: 0x%Lx => %Lx\n", + __FUNCTION__, + PlatformInfoHob->PcdPciMmio64Base, + NewBase + )); + PlatformInfoHob->PcdPciMmio64Base = NewBase; + } + } } } @@ -340,7 +374,7 @@ PlatformGetSystemMemorySizeBelow4gb ( return (UINT32)GetHighestSystemMemoryAddressFromPvhMemmap (TRUE); } - Status = PlatformScanOrAdd64BitE820Ram (FALSE, &LowerMemorySize, NULL); + Status = PlatformScanOrAdd64BitE820Ram (FALSE, NULL, &LowerMemorySize, NULL); if ((Status == 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 (which // can only express a size smaller than 1TB), and add it to 4GB. // - Status = PlatformScanOrAdd64BitE820Ram (FALSE, NULL, &FirstNonAddress); + Status = PlatformScanOrAdd64BitE820Ram (FALSE, NULL, NULL, &FirstNonAddress); if (EFI_ERROR (Status)) { FirstNonAddress = BASE_4GB + PlatformGetSystemMemorySizeAbove4gb (); } @@ -648,6 +682,7 @@ PlatformDynamicMmioWindow ( DEBUG ((DEBUG_INFO, "%a: MMIO Space 0x%Lx (%Ld GB)\n", __func__, MmioSpace, RShiftU64 (MmioSpace, 30))); PlatformInfoHob->PcdPciMmio64Size = MmioSpace; PlatformInfoHob->PcdPciMmio64Base = 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 >=4GB // memory size read from the CMOS. // - Status = PlatformScanOrAdd64BitE820Ram (TRUE, NULL, NULL); + Status = PlatformScanOrAdd64BitE820Ram (TRUE, NULL, NULL, NULL); if (EFI_ERROR (Status)) { UpperMemorySize = PlatformGetSystemMemorySizeAbove4gb (); if (UpperMemorySize != 0) { -- 2.39.0