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 51A2FD806DD for ; Thu, 25 Jan 2024 06:52:41 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=bBjfisUpMOTw7IylfJUWk1Kb//ssYsFw7MM6d0eHydU=; c=relaxed/simple; d=groups.io; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version:In-Reply-To:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Type:Content-Disposition; s=20140610; t=1706165559; v=1; b=vgqjhj3MK8cAhLg/qDJVW5aDsQCEcHdr4mDevcT46S74HQuxQX+6hXT0bsT2pzF6ms75QfLg miH9lku87YBCkhFjVlqi4TAeF0F1phYHRUtF5Yhs5fJehB89PJar257+RDi2IVAc/slBnA9w7zb K0Qoe61CP0bkNBtMUNnkV2YA= X-Received: by 127.0.0.2 with SMTP id txN8YY7687511xGxAmswWDS9; Wed, 24 Jan 2024 22:52:39 -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.web10.11325.1706165559214041210 for ; Wed, 24 Jan 2024 22:52:39 -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-518-yWRu-Gw1NpeMi_WpwI0ApA-1; Thu, 25 Jan 2024 01:52:33 -0500 X-MC-Unique: yWRu-Gw1NpeMi_WpwI0ApA-1 X-Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (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 36248884347; Thu, 25 Jan 2024 06:52:33 +0000 (UTC) X-Received: from sirius.home.kraxel.org (unknown [10.39.192.43]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E11A4492BC6; Thu, 25 Jan 2024 06:52:32 +0000 (UTC) X-Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id B837C1801A8A; Thu, 25 Jan 2024 07:52:31 +0100 (CET) Date: Thu, 25 Jan 2024 07:52:31 +0100 From: "Gerd Hoffmann" To: Laszlo Ersek Cc: devel@edk2.groups.io, Michael Roth , Tom Lendacky , Jiewen Yao , Ard Biesheuvel , Oliver Steffen , Min Xu , Erdem Aktas Subject: Re: [edk2-devel] [PATCH 1/1] OvmfPkg/Sec: Setup MTRR early in the boot process. Message-ID: <34qfpf44zr4e5fgxbajked3dbwuc2k6yl6bherm4zazziuyyef@33k4wclwrh44> References: <20240124151542.2091782-1-kraxel@redhat.com> <6d89f7aa-938c-2a96-3eb8-53169dcfd3db@redhat.com> MIME-Version: 1.0 In-Reply-To: <6d89f7aa-938c-2a96-3eb8-53169dcfd3db@redhat.com> X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.9 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: DnawhDZU7LPrv5yYmpRxFjDFx7686176AA= Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=vgqjhj3M; 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) On Wed, Jan 24, 2024 at 05:14:10PM +0100, Laszlo Ersek wrote: > On 1/24/24 16:15, Gerd Hoffmann wrote: > > 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. > > I suggest mentioning mdev and noncoherent DMA here (the linux code you > quoted elsewhere would be welcome too). Ok, I guess it makes sense to quote it completely in the commit message then ... static u8 vmx_get_mt_mask(struct kvm_vcpu *vcpu, gfn_t gfn, bool is_mmio) { /* We wanted to honor guest CD/MTRR/PAT, but doing so could result in * memory aliases with conflicting memory types and sometimes MCEs. * We have to be careful as to what are honored and when. * * For MMIO, guest CD/MTRR are ignored. The EPT memory type is set to * UC. The effective memory type is UC or WC depending on guest PAT. * This was historically the source of MCEs and we want to be * conservative. * * When there is no need to deal with noncoherent DMA (e.g., no VT-d * or VT-d has snoop control), guest CD/MTRR/PAT are all ignored. The * EPT memory type is set to WB. The effective memory type is forced * WB. * * Otherwise, we trust guest. Guest CD/MTRR/PAT are all honored. The * EPT memory type is used to emulate guest CD/MTRR. */ if (is_mmio) return MTRR_TYPE_UNCACHABLE << VMX_EPT_MT_EPTE_SHIFT; if (!kvm_arch_has_noncoherent_dma(vcpu->kvm)) return (MTRR_TYPE_WRBACK << VMX_EPT_MT_EPTE_SHIFT) | VMX_EPT_IPAT_BIT; if (kvm_read_cr0_bits(vcpu, X86_CR0_CD)) { if (kvm_check_has_quirk(vcpu->kvm, KVM_X86_QUIRK_CD_NW_CLEARED)) return MTRR_TYPE_WRBACK << VMX_EPT_MT_EPTE_SHIFT; else return (MTRR_TYPE_UNCACHABLE << VMX_EPT_MT_EPTE_SHIFT) | VMX_EPT_IPAT_BIT; } return kvm_mtrr_get_guest_memory_type(vcpu, gfn) << VMX_EPT_MT_EPTE_SHIFT; } > The original report > claims that commit e8aa4c6546ad ("UefiCpuPkg/ResetVector: Cache Disable > should not be set by default in CR0", 2023-08-30) triggered the symptom. > I don't understand how *clearing* CD in CR0, could make guest memory > *less* cacheable. I understand the point about MTRR, but exactly the > MTRR's currently upstream state should have masked any changes to CD. ... because it also explains that question: I think with CD set we take the KVM_X86_QUIRK_CD_NW_CLEARED code path and run with memory in write-back mode. > (2) We already assume (minimally since 2015) that MTRRs are supported by > the processor. No. The whole MTRR setup is gated by "if (IsMtrrSupported ())". Also note that qemu allows to turn off MTRRs (-cpu host,mtrr=off), which btw can be used as workaround for this bug. With MTRR support disabled kvm takes yet another code path ... > > InitializeApicTimer (0, MAX_UINT32, TRUE, 5); > > DisableApicTimerInterrupt (); > > > > + // > > + // Initialize MTRR > > + // > > + SecMtrrSetup (); > (7) If you have a particular reason for doing it here, please capture > that in the comment. Placing it near other hardware init (timers) looked somewhat logical to me. Any other place in that function should work equally well though. > (8) Just for symmetry -- I'm noticing there are two > SecCoreStartupWithStack() functions; the other being in > "OvmfPkg/IntelTdx/Sec/SecMain.c". > > Also, Min's original QEMU command line included TDVF references. > > Does that mean this patch should be reflected to the TDX platform's modules? Probably, I'll have a look. take care, Gerd -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#114367): https://edk2.groups.io/g/devel/message/114367 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] -=-=-=-=-=-=-=-=-=-=-=-