kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sean Christopherson <seanjc@google.com>
To: Binbin Wu <binbin.wu@linux.intel.com>
Cc: Vishal Annapurve <vannapurve@google.com>,
	Nikolay Borisov <nik.borisov@suse.com>,
	 Jianxiong Gao <jxgao@google.com>,
	"Borislav Petkov (AMD)" <bp@alien8.de>,
	 Dave Hansen <dave.hansen@linux.intel.com>,
	Dionna Glaze <dionnaglaze@google.com>,
	 "H. Peter Anvin" <hpa@zytor.com>,
	jgross@suse.com,
	 "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>,
	kvm@vger.kernel.org,  linux-kernel@vger.kernel.org,
	Ingo Molnar <mingo@redhat.com>,
	pbonzini@redhat.com,  Peter Gonda <pgonda@google.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	 Tom Lendacky <thomas.lendacky@amd.com>,
	Vitaly Kuznetsov <vkuznets@redhat.com>,
	x86@kernel.org,  Rick Edgecombe <rick.p.edgecombe@intel.com>,
	jiewen.yao@intel.com
Subject: Re: [PATCH 0/2] x86/kvm: Force legacy PCI hole as WB under SNP/TDX
Date: Wed, 27 Aug 2025 17:07:11 -0700	[thread overview]
Message-ID: <aK-dr2W7UoA65jM2@google.com> (raw)
In-Reply-To: <aKc61y0_tvGLmieC@google.com>

On Thu, Aug 21, 2025, Sean Christopherson wrote:
> On Thu, Aug 21, 2025, Binbin Wu wrote:
> > On 8/21/2025 11:30 AM, Binbin Wu wrote:
> > > Variable MTRR has requirement for range size and alignment:
> > > For ranges greater than 4 KBytes, each range must be of length 2^n and its base
> > > address must be aligned on a 2^n boundary, where n is a value equal to or
> > > greater than 12. The base-address alignment value cannot be less than its length.
> > 
> > Wait, Linux kernel converts MTRR register values to MTRR state (base and size) and
> > cache it for later lookups (refer to map_add_var()). I.e., in Linux kernel,
> > only the cached state will be used.
> > 
> > These MTRR register values are never programmed when using
> > guest_force_mtrr_state() , so even the values doesn't meet the requirement
> > from hardware perspective, Linux kernel can still get the right base and
> > size.
> 
> Yeah.  I forget what happens if the ranges don't meet the power-of-2 requirements,
> but the mask+match logic should work jus tfine.
> 
> > No bothering to force the base and size alignment.
> > But a comment would be helpful.
> > Also, BIT(11) could be replaced by MTRR_PHYSMASK_V.
> 
> Ha!  I spent a good 5 minutes looking for a #define couldn't find one.  What a
> bizarre name...
> 
> > How about:
> > diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c
> > index 90097df4eafd..a9582ffc3088 100644
> > --- a/arch/x86/kernel/kvm.c
> > +++ b/arch/x86/kernel/kvm.c
> > @@ -934,9 +934,15 @@ static void kvm_sev_hc_page_enc_status(unsigned long pfn, int npages, bool enc)
> >  static void __init kvm_init_platform(void)
> >  {
> >         u64 tolud = e820__end_of_low_ram_pfn() << PAGE_SHIFT;
> > +       /*
> > +        * The range's base address and size may not meet the alignment
> > +        * requirement for variable MTRR. However, Linux guest never
> > +        * programs MTRRs when forcing guest MTRR state, no bothering to
> > +        * enforce the base and range size alignment.
> > +        */
> >         struct mtrr_var_range pci_hole = {
> >                 .base_lo = tolud | X86_MEMTYPE_UC,
> > -               .mask_lo = (u32)(~(SZ_4G - tolud - 1)) | BIT(11),
> > +               .mask_lo = (u32)(~(SZ_4G - tolud - 1)) | MTRR_PHYSMASK_V,
> >                 .mask_hi = (BIT_ULL(boot_cpu_data.x86_phys_bits) - 1) >> 32,
> >         };
> > 
> > 
> > I tested it in my setup, it can fix the issue of TPM driver failure with the
> > modified ACPI table for TPM in QEMU.
> > 
> > 
> > Hi Vishal,
> > Could you test it with google's VMM?
> 
> Vishal is OOO for a few days.  I pinged our internal bug tracker, I'll find
> someone to test.

Got confirmation this fixes the vTPM woes with Google's VMM.  v2 incoming...

  reply	other threads:[~2025-08-28  0:07 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-09 16:54 [PATCH 0/2] x86/kvm: Force legacy PCI hole as WB under SNP/TDX Jianxiong Gao
2025-07-14  9:06 ` Binbin Wu
2025-07-14 11:24   ` Nikolay Borisov
2025-07-15  2:53     ` Binbin Wu
2025-07-16  9:51       ` Binbin Wu
2025-07-23 14:34     ` Sean Christopherson
2025-07-24  3:16       ` Binbin Wu
2025-07-28 15:33         ` Sean Christopherson
2025-07-30  7:34           ` Binbin Wu
2025-08-15 23:55             ` Korakit Seemakhupt
2025-08-18 11:07               ` Binbin Wu
2025-08-20  3:07             ` Vishal Annapurve
2025-08-20 10:03               ` Binbin Wu
2025-08-20 11:13                 ` Binbin Wu
2025-08-20 17:56                   ` Sean Christopherson
2025-08-21  3:30                     ` Binbin Wu
2025-08-21  5:23                       ` Binbin Wu
2025-08-21  6:02                         ` Jürgen Groß
2025-08-21 15:27                         ` Sean Christopherson
2025-08-28  0:07                           ` Sean Christopherson [this message]
  -- strict thread matches above, loose matches on Subject: below --
2025-02-01  0:50 Sean Christopherson
2025-02-01 14:25 ` Dionna Amalie Glaze
2025-02-03 18:14 ` Edgecombe, Rick P
2025-02-03 20:33   ` Sean Christopherson
2025-02-03 23:01     ` Edgecombe, Rick P
2025-02-04  0:27       ` Sean Christopherson
2025-02-05  3:51         ` Edgecombe, Rick P
2025-02-05  7:49           ` Xu, Min M
2025-02-10 15:29         ` Binbin Wu
2025-07-08 14:24 ` Nikolay Borisov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aK-dr2W7UoA65jM2@google.com \
    --to=seanjc@google.com \
    --cc=binbin.wu@linux.intel.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=dionnaglaze@google.com \
    --cc=hpa@zytor.com \
    --cc=jgross@suse.com \
    --cc=jiewen.yao@intel.com \
    --cc=jxgao@google.com \
    --cc=kirill.shutemov@linux.intel.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=nik.borisov@suse.com \
    --cc=pbonzini@redhat.com \
    --cc=pgonda@google.com \
    --cc=rick.p.edgecombe@intel.com \
    --cc=tglx@linutronix.de \
    --cc=thomas.lendacky@amd.com \
    --cc=vannapurve@google.com \
    --cc=vkuznets@redhat.com \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).