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.133.124]) by mx.groups.io with SMTP id smtpd.web10.198702.1673968178302422290 for ; Tue, 17 Jan 2023 07:09:38 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=SHU17n16; spf=pass (domain: redhat.com, ip: 170.10.133.124, mailfrom: lersek@redhat.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1673968177; 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=oJrt/z3zIwyo86zlDak+g8iMe1sNGvmceWdmFLDyeFU=; b=SHU17n16FsfI8kAq8D/qxoDAdc23ipXrZI3IPLBO7vgQDEFbFz+hc6fvwl1oMPLLq4VFFD leppEPShKTezr8gbVfS75UyZyELY9ju1yjsf/0B5Ql1e/0SCtQkM6LBe2TzcLqr9UunYk9 B9c7cydLksTEYRtnkyoNBSJoUBK4MmM= 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-222-ujdwvqBSNAaUFSXXwt2GHA-1; Tue, 17 Jan 2023 10:08:43 -0500 X-MC-Unique: ujdwvqBSNAaUFSXXwt2GHA-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3691888F46B; Tue, 17 Jan 2023 15:05:43 +0000 (UTC) Received: from [10.39.194.135] (unknown [10.39.194.135]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E31D7C15BA0; Tue, 17 Jan 2023 15:05:41 +0000 (UTC) Message-ID: <9cea31ea-eeb2-cdee-8df1-807b7592d196@redhat.com> Date: Tue, 17 Jan 2023 16:05:40 +0100 MIME-Version: 1.0 Subject: Re: [PATCH v4 4/5] OvmfPkg/PlatformInitLib: Add PlatformReservationConflictCB To: Gerd Hoffmann , devel@edk2.groups.io Cc: Jiewen Yao , Oliver Steffen , Ard Biesheuvel , Pawel Polawski , Jordan Justen References: <20230117121629.2149112-1-kraxel@redhat.com> <20230117121629.2149112-5-kraxel@redhat.com> From: "Laszlo Ersek" In-Reply-To: <20230117121629.2149112-5-kraxel@redhat.com> X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 1/17/23 13:16, Gerd Hoffmann wrote: > Add PlatformReservationConflictCB() callback function for use with > PlatformScanE820(). It checks whenever the 64bit PCI MMIO window > overlaps with a reservation from qemu. If so move down the MMIO window > to resolve the conflict. > > Write any actions done (moving mmio window) to the firmware log with > INFO loglevel. > > This happens on (virtual) AMD machines with 1TB address space, > because the AMD IOMMU uses an address window just below 1TB. > > Bugzilla: https://bugzilla.tianocore.org/show_bug.cgi?id=4251 > Signed-off-by: Gerd Hoffmann > --- > OvmfPkg/Library/PlatformInitLib/MemDetect.c | 45 +++++++++++++++++++++ > 1 file changed, 45 insertions(+) > > diff --git a/OvmfPkg/Library/PlatformInitLib/MemDetect.c b/OvmfPkg/Library/PlatformInitLib/MemDetect.c > index c626fc49cf6c..1ce692e77ecb 100644 > --- a/OvmfPkg/Library/PlatformInitLib/MemDetect.c > +++ b/OvmfPkg/Library/PlatformInitLib/MemDetect.c > @@ -213,6 +213,50 @@ PlatformAddHobCB ( > } > } > > +/** > + Check whenever the 64bit PCI MMIO window overlaps with a reservation > + from qemu. If so move down the MMIO window to resolve the conflict. > + > + This happens on (virtual) AMD machines with 1TB address space, > + because the AMD IOMMU uses an address window just below 1TB. > +**/ > +STATIC VOID > +PlatformReservationConflictCB ( > + IN EFI_E820_ENTRY64 *E820Entry, > + IN OUT EFI_HOB_PLATFORM_INFO *PlatformInfoHob > + ) > +{ > + UINT64 IntersectionBase; > + UINT64 IntersectionEnd; > + UINT64 NewBase; > + > + IntersectionBase = MAX ( > + E820Entry->BaseAddr, > + PlatformInfoHob->PcdPciMmio64Base > + ); > + IntersectionEnd = MIN ( > + E820Entry->BaseAddr + E820Entry->Length, > + PlatformInfoHob->PcdPciMmio64Base + > + PlatformInfoHob->PcdPciMmio64Size > + ); > + > + if (IntersectionBase >= IntersectionEnd) { > + return; // no overlap > + } > + > + NewBase = E820Entry->BaseAddr - PlatformInfoHob->PcdPciMmio64Size; > + NewBase = NewBase & ~(PlatformInfoHob->PcdPciMmio64Size - 1); > + > + DEBUG (( > + DEBUG_INFO, > + "%a: move mmio: 0x%Lx => %Lx\n", > + __FUNCTION__, > + PlatformInfoHob->PcdPciMmio64Base, > + NewBase > + )); > + PlatformInfoHob->PcdPciMmio64Base = NewBase; > +} > + > /** > Iterate over the entries in QEMU's fw_cfg E820 RAM map, call the > passed callback for each entry. > @@ -650,6 +694,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; > + PlatformScanE820 (PlatformReservationConflictCB, PlatformInfoHob); > } else { > DEBUG ((DEBUG_INFO, "%a: using classic mmio window\n", __func__)); > } Reviewed-by: Laszlo Ersek