mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Robert Hoo <robert.hoo.linux@gmail.com>
To: Yan Zhao <yan.y.zhao@intel.com>
Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
	pbonzini@redhat.com, seanjc@google.com
Subject: Re: [PATCH v2 5/6] KVM: x86: Keep a per-VM MTRR state
Date: Thu, 25 May 2023 15:21:28 +0800	[thread overview]
Message-ID: <393b16f7-8359-5d77-7d5d-8942de987331@gmail.com> (raw)
In-Reply-To: <ZGxbat2mM6AfOOVv@yzhao56-desk.sh.intel.com>

On 5/23/2023 2:21 PM, Yan Zhao wrote:
[...]
> Yes, leaving each vCPU's MTRR to mimic HW.
> 
> As also suggested in SDM, the guest OS manipulates MTRRs in this way:
> 
> for each online CPUs {
> 	disable MTRR
> 	update fixed/var MTRR ranges
> 	enable MTRR
> }
> Guest OS needs to access memory only after this full pattern.
> 
Thanks for confirmation and clarification.

> So, I think there should not have "hazard of inconsistency among per-VPU MTRR
> states".
> 
> I want to have per-VM MTRR state is because I want to reduce unnessary EPT
> zap, which costs quite a lot cpu cycles even when the EPT is empty.
> 
> In this patch, per-VM MTRR pointer is used to point to vCPU 0's MTRR state,
> so that it can save some memory to keep the MTRR state.
> But I found out that it would only work when vCPU 0 (boot processor) is
> always online (which is not true for x86 under some configration).
> 
> I'll try to find out lowest online vCPU and keep a per-VM copy of MTRR state
> in next version.
> 
> Thanks!
> 

IIUC, your saving comes from skips the intermediate state during boot, when 
APs goes through setting MTRR, which would cause SPTE zap before your this 
patch set.

MHO was, now that your ignores other vCPU's MTRR settings (unless it is 
different from BP's MTRR?), why not let each vCPU's MTRR set/update 
directly set to the per-VM MTRR states (if differs from current value). 
It's guest OS/BIOS's responsibility to keep the consistency anyway. And 
even if the malfunction caused by the inconsistency might differ from that 
of native, SDM doesn't clearly state how the malfunction should be, does it?
that's to say, anyone knows, when inconsistency happens, does it cause that 
logical processor malfunction or in fact it impacts the global MTRR 
settings? If the latter, I think leaving only the per-VM MTRR state aligns 
with native.

BTW, with regard to KVM_X86_QUIRK_CD_NW_CLEARED, I see svm honors it while 
vmx doesn't before it clear CR0.CD/NW.

svm_set_cr0():

	if (kvm_check_has_quirk(vcpu->kvm, KVM_X86_QUIRK_CD_NW_CLEARED))
		hcr0 &= ~(X86_CR0_CD | X86_CR0_NW);


vmx_set_cr0():

	hw_cr0 = (cr0 & ~KVM_VM_CR0_ALWAYS_OFF);

Perhaps vmx side can be fixed passingly?

  parent reply	other threads:[~2023-05-25  7:21 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-09 13:48 [PATCH v2 0/6] KVM: x86/mmu: refine memtype related mmu zap Yan Zhao
2023-05-09 13:50 ` [PATCH v2 1/6] KVM: x86/mmu: add a new mmu zap helper to indicate memtype changes Yan Zhao
2023-05-10  5:30   ` Chao Gao
2023-05-10  8:06     ` Yan Zhao
2023-05-23 22:51       ` Sean Christopherson
2023-05-24  2:22         ` Yan Zhao
2023-05-24 14:50           ` Sean Christopherson
2023-05-25 10:14             ` Yan Zhao
2023-05-25 15:54               ` Sean Christopherson
2023-05-30  1:32                 ` Yan Zhao
2023-05-30  9:48                 ` Yan Zhao
2023-05-30 23:51                   ` Sean Christopherson
2023-05-31  0:18                     ` Yan Zhao
2023-05-09 13:51 ` [PATCH v2 2/6] KVM: x86/mmu: only zap EPT when guest CR0_CD changes Yan Zhao
2023-05-09 13:51 ` [PATCH v2 3/6] KVM: x86/mmu: only zap EPT when guest MTRR changes Yan Zhao
2023-05-10  5:39   ` Chao Gao
2023-05-10  8:00     ` Yan Zhao
2023-05-10 10:54       ` Huang, Kai
2023-05-11  0:15         ` Yan Zhao
2023-05-11  2:42           ` Huang, Kai
2023-05-11  2:31             ` Yan Zhao
2023-05-11  3:05               ` Huang, Kai
2023-05-09 13:52 ` [PATCH v2 4/6] KVM: x86/mmu: Zap all EPT leaf entries according noncoherent DMA count Yan Zhao
2023-05-09 13:53 ` [PATCH v2 5/6] KVM: x86: Keep a per-VM MTRR state Yan Zhao
2023-05-10 17:23   ` David Matlack
2023-05-21  3:44   ` Robert Hoo
2023-05-23  6:21     ` Yan Zhao
2023-05-24  0:13       ` Sean Christopherson
2023-05-24 11:03         ` Yan Zhao
2023-05-24 18:21           ` Sean Christopherson
2023-05-25 10:09             ` Yan Zhao
2023-05-25 14:53               ` Sean Christopherson
2023-05-26  7:54                 ` Yan Zhao
2023-05-26 16:09                   ` Sean Christopherson
2023-05-30  1:19                     ` Yan Zhao
2023-05-25  7:21       ` Robert Hoo [this message]
2023-05-25 15:00         ` Sean Christopherson
2023-05-26  1:49           ` Robert Hoo
2023-05-09 13:53 ` [PATCH v2 6/6] KVM: x86/mmu: use per-VM based MTRR for EPT Yan Zhao
2023-05-24  0:15 ` [PATCH v2 0/6] KVM: x86/mmu: refine memtype related mmu zap Sean Christopherson
2023-05-24 11:04   ` Yan Zhao

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=393b16f7-8359-5d77-7d5d-8942de987331@gmail.com \
    --to=robert.hoo.linux@gmail.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=seanjc@google.com \
    --cc=yan.y.zhao@intel.com \
    /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

Powered by JetHome