From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by spool.mail.gandi.net (Postfix) with ESMTPS id 5FAE1D80CAA for ; Wed, 24 Jan 2024 15:15:50 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=xFQUB2V8SR4zMJpVHe35slo4KaQqi0OWvEBRWSaoSBo=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding:Content-Type; s=20140610; t=1706109348; v=1; b=ezsqvyenxkOPnm1ZVMA9nrAJ9PDpX9lwr8mpjDY9bS2d6OEVZqmCYgoAex+bkR05SXW7y7CG jAz9WGd58CIMyXeR7JWTP5GWVxKPL9DBmDh4VuzbBdZVmq6vjKnUatkrc2TNUYq0Wmz6IaLRL2d b31xALKB5Py+ZGcw7matT/Tc= X-Received: by 127.0.0.2 with SMTP id FTquYY7687511xLqbCqezHPb; Wed, 24 Jan 2024 07:15:48 -0800 X-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.web11.25127.1706109348139600513 for ; Wed, 24 Jan 2024 07:15:48 -0800 X-Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-296-DsuvT1iSNQO9JodumeVM9w-1; Wed, 24 Jan 2024 10:15:44 -0500 X-MC-Unique: DsuvT1iSNQO9JodumeVM9w-1 X-Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8A6F2827E5C; Wed, 24 Jan 2024 15:15:43 +0000 (UTC) X-Received: from sirius.home.kraxel.org (unknown [10.39.193.66]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 491882028CD2; Wed, 24 Jan 2024 15:15:43 +0000 (UTC) X-Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 182F0180038B; Wed, 24 Jan 2024 16:15:42 +0100 (CET) From: "Gerd Hoffmann" To: devel@edk2.groups.io Cc: Michael Roth , Tom Lendacky , Jiewen Yao , Ard Biesheuvel , Oliver Steffen , Laszlo Ersek , Min Xu , Gerd Hoffmann , Erdem Aktas Subject: [edk2-devel] [PATCH 1/1] OvmfPkg/Sec: Setup MTRR early in the boot process. Date: Wed, 24 Jan 2024 16:15:42 +0100 Message-ID: <20240124151542.2091782-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Precedence: Bulk 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 List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: VIUJmCshbDQ0LeOifpVpt4jKx7686176AA= Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=ezsqvyen; spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=redhat.com (policy=none) Specifically before running lzma uncompress of the main firmware volume. This is needed to make sure caching is enabled, otherwise the uncompress can be extremely slow. Adapt the ASSERTs in PlatformInitLib to the changes. Background: In some virtual machine configurations with assigned devices kvm uses EPT memory types to apply guest MTRR settings. In case MTRRs are disabled kvm will use the uncachable memory type for all mappings. Signed-off-by: Gerd Hoffmann --- OvmfPkg/Library/PlatformInitLib/MemDetect.c | 8 ++++-- OvmfPkg/Sec/SecMain.c | 32 +++++++++++++++++++++ 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/OvmfPkg/Library/PlatformInitLib/MemDetect.c b/OvmfPkg/Library/PlatformInitLib/MemDetect.c index f042517bb64a..cb2ae0f3d79d 100644 --- a/OvmfPkg/Library/PlatformInitLib/MemDetect.c +++ b/OvmfPkg/Library/PlatformInitLib/MemDetect.c @@ -1082,11 +1082,13 @@ PlatformQemuInitializeRam ( MtrrGetAllMtrrs (&MtrrSettings); // - // MTRRs disabled, fixed MTRRs disabled, default type is uncached + // Fixed MTRRs disabled, default type is uncached or write back (see SecMtrrSetup()) // - ASSERT ((MtrrSettings.MtrrDefType & BIT11) == 0); ASSERT ((MtrrSettings.MtrrDefType & BIT10) == 0); - ASSERT ((MtrrSettings.MtrrDefType & 0xFF) == 0); + ASSERT ( + (MtrrSettings.MtrrDefType & 0xFF) == 0x0 || + (MtrrSettings.MtrrDefType & 0xFF) == 0x6 + ); // // flip default type to writeback diff --git a/OvmfPkg/Sec/SecMain.c b/OvmfPkg/Sec/SecMain.c index 31da5d0ace51..a672751b046a 100644 --- a/OvmfPkg/Sec/SecMain.c +++ b/OvmfPkg/Sec/SecMain.c @@ -30,6 +30,8 @@ #include #include #include +#include +#include #include "AmdSev.h" #define SEC_IDT_ENTRY_COUNT 34 @@ -744,6 +746,31 @@ FindAndReportEntryPoints ( return; } +// +// Enable MTRR early, set default type to write back. +// Needed to make sure caching is enabled, +// without this lzma decompress can be very slow. +// +STATIC +VOID +SecMtrrSetup ( + VOID + ) +{ + CPUID_VERSION_INFO_EDX Edx; + MSR_IA32_MTRR_DEF_TYPE_REGISTER DefType; + + AsmCpuid (CPUID_VERSION_INFO, NULL, NULL, NULL, &Edx.Uint32); + if (!Edx.Bits.MTRR) { + return; + } + + DefType.Uint64 = 0; + DefType.Bits.Type = 6; /* write back */ + DefType.Bits.E = 1; /* enable */ + AsmWriteMsr64 (MSR_IA32_MTRR_DEF_TYPE, DefType.Uint64); +} + VOID EFIAPI SecCoreStartupWithStack ( @@ -942,6 +969,11 @@ SecCoreStartupWithStack ( InitializeApicTimer (0, MAX_UINT32, TRUE, 5); DisableApicTimerInterrupt (); + // + // Initialize MTRR + // + SecMtrrSetup (); + // // Initialize Debug Agent to support source level debug in SEC/PEI phases before memory ready. // -- 2.43.0 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#114309): https://edk2.groups.io/g/devel/message/114309 Mute This Topic: https://groups.io/mt/103933443/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-