From: Chao Gao <chao.gao@intel.com>
To: Robert Hoo <robert.hu@linux.intel.com>
Cc: <seanjc@google.com>, <pbonzini@redhat.com>,
<yu.c.zhang@linux.intel.com>, <yuan.yao@linux.intel.com>,
<jingqi.liu@intel.com>, <weijiang.yang@intel.com>,
<isaku.yamahata@intel.com>, <kirill.shutemov@linux.intel.com>,
<kvm@vger.kernel.org>
Subject: Re: [PATCH v4 7/9] KVM: x86: When guest set CR3, handle LAM bits semantics
Date: Mon, 13 Feb 2023 11:31:39 +0800 [thread overview]
Message-ID: <Y+mvG8S3W5lXoZNJ@gao-cwp> (raw)
In-Reply-To: <20230209024022.3371768-8-robert.hu@linux.intel.com>
On Thu, Feb 09, 2023 at 10:40:20AM +0800, Robert Hoo wrote:
>When only changes LAM bits, ask next vcpu run to load mmu pgd, so that it
>will build new CR3 with LAM bits updates.
>When changes on CR3's effective address bits, no matter LAM bits changes or not,
>go through normal pgd update process.
Please squash this into patch 2.
>
>Reviewed-by: Jingqi Liu <jingqi.liu@intel.com>
>Signed-off-by: Robert Hoo <robert.hu@linux.intel.com>
>---
> arch/x86/kvm/x86.c | 24 ++++++++++++++++++++----
> 1 file changed, 20 insertions(+), 4 deletions(-)
>
>diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
>index 3218f465ae71..7df6c9dd12a5 100644
>--- a/arch/x86/kvm/x86.c
>+++ b/arch/x86/kvm/x86.c
>@@ -1242,9 +1242,9 @@ static bool kvm_is_valid_cr3(struct kvm_vcpu *vcpu, unsigned long cr3)
> int kvm_set_cr3(struct kvm_vcpu *vcpu, unsigned long cr3)
> {
> bool skip_tlb_flush = false;
>- unsigned long pcid = 0;
>+ unsigned long pcid = 0, old_cr3;
> #ifdef CONFIG_X86_64
>- bool pcid_enabled = kvm_read_cr4_bits(vcpu, X86_CR4_PCIDE);
>+ bool pcid_enabled = !!kvm_read_cr4_bits(vcpu, X86_CR4_PCIDE);
This change isn't related. Please drop it or post it separately.
>
> if (pcid_enabled) {
> skip_tlb_flush = cr3 & X86_CR3_PCID_NOFLUSH;
>@@ -1257,6 +1257,10 @@ int kvm_set_cr3(struct kvm_vcpu *vcpu, unsigned long cr3)
> if (cr3 == kvm_read_cr3(vcpu) && !is_pae_paging(vcpu))
> goto handle_tlb_flush;
>
>+ if (!guest_cpuid_has(vcpu, X86_FEATURE_LAM) &&
>+ (cr3 & (X86_CR3_LAM_U48 | X86_CR3_LAM_U57)))
>+ return 1;
can you move this check to kvm_vcpu_is_valid_cr3(), i.e., return false in
that function if any LAM bit is toggled while LAM isn't exposed to the guest?
>+
> /*
> * Do not condition the GPA check on long mode, this helper is used to
> * stuff CR3, e.g. for RSM emulation, and there is no guarantee that
>@@ -1268,8 +1272,20 @@ int kvm_set_cr3(struct kvm_vcpu *vcpu, unsigned long cr3)
> if (is_pae_paging(vcpu) && !load_pdptrs(vcpu, cr3))
> return 1;
>
>- if (cr3 != kvm_read_cr3(vcpu))
>- kvm_mmu_new_pgd(vcpu, cr3);
>+ old_cr3 = kvm_read_cr3(vcpu);
>+ if (cr3 != old_cr3) {
>+ if ((cr3 ^ old_cr3) & CR3_ADDR_MASK) {
Does this check against CR3_ADDR_MASK necessarily mean LAM bits are
toggled, i.e., CR3_ADDR_MASK == ~(X86_CR3_LAM_U48 | X86_CR3_LAM_U57)?
Why not check if LAM bits are changed? This way the patch only changes
cases related to LAM, keeping other cases intact.
>+ kvm_mmu_new_pgd(vcpu, cr3 & ~(X86_CR3_LAM_U48 |
>+ X86_CR3_LAM_U57));
Do you need to touch kvm_mmu_new_pgd() in nested_vmx_load_cr3()?
>+ } else {
>+ /*
>+ * Though effective addr no change, mark the
>+ * request so that LAM bits will take effect
>+ * when enter guest.
>+ */
>+ kvm_make_request(KVM_REQ_LOAD_MMU_PGD, vcpu);
>+ }
>+ }
>
> vcpu->arch.cr3 = cr3;
> kvm_register_mark_dirty(vcpu, VCPU_EXREG_CR3);
>--
>2.31.1
>
next prev parent reply other threads:[~2023-02-13 3:31 UTC|newest]
Thread overview: 64+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-09 2:40 [PATCH v4 0/9] Linear Address Masking (LAM) KVM Enabling Robert Hoo
2023-02-09 2:40 ` [PATCH v4 1/9] KVM: x86: Intercept CR4.LAM_SUP when LAM feature is enabled in guest Robert Hoo
2023-02-09 9:21 ` Chao Gao
2023-02-09 12:48 ` Robert Hoo
2023-02-10 3:29 ` Yang, Weijiang
2023-02-10 5:02 ` Robert Hoo
2023-02-10 16:30 ` Sean Christopherson
2023-02-14 1:27 ` Binbin Wu
2023-02-14 6:11 ` Robert Hoo
2023-02-14 9:00 ` Binbin Wu
2023-02-14 12:24 ` Robert Hoo
2023-02-14 12:36 ` Robert Hoo
2023-02-16 5:31 ` Binbin Wu
2023-02-16 5:54 ` Robert Hoo
2023-02-09 2:40 ` [PATCH v4 2/9] KVM: x86: MMU: Clear CR3 LAM bits when allocate shadow root Robert Hoo
2023-02-09 9:55 ` Chao Gao
2023-02-09 13:02 ` Robert Hoo
2023-02-14 2:55 ` Binbin Wu
2023-02-15 1:17 ` Robert Hoo
2023-02-16 2:14 ` Robert Hoo
2023-02-10 3:38 ` Yang, Weijiang
2023-02-11 3:12 ` Robert Hoo
2023-02-09 2:40 ` [PATCH v4 3/9] KVM: x86: MMU: Commets update Robert Hoo
2023-02-10 6:59 ` Chao Gao
2023-02-10 7:55 ` Robert Hoo
2023-02-10 16:54 ` Sean Christopherson
2023-02-09 2:40 ` [PATCH v4 4/9] KVM: x86: MMU: Integrate LAM bits when build guest CR3 Robert Hoo
2023-02-10 14:04 ` Chao Gao
2023-02-11 6:24 ` Robert Hoo
2023-02-11 6:29 ` Robert Hoo
2023-02-09 2:40 ` [PATCH v4 5/9] KVM: x86: Untag LAM bits when applicable Robert Hoo
2023-02-10 15:04 ` Chao Gao
2023-02-11 5:57 ` Robert Hoo
2023-02-16 6:37 ` Binbin Wu
2023-02-09 2:40 ` [PATCH v4 6/9] KVM: x86: When KVM judges CR3 valid or not, consider LAM bits Robert Hoo
2023-02-13 2:01 ` Chao Gao
2023-02-13 13:25 ` Robert Hoo
2023-02-14 6:18 ` Chao Gao
2023-02-14 7:00 ` Chao Gao
2023-02-18 5:44 ` Robert Hoo
2023-02-09 2:40 ` [PATCH v4 7/9] KVM: x86: When guest set CR3, handle LAM bits semantics Robert Hoo
2023-02-13 3:31 ` Chao Gao [this message]
2023-02-14 5:28 ` Robert Hoo
2023-02-14 6:48 ` Chao Gao
2023-02-09 2:40 ` [PATCH v4 8/9] KVM: x86: emulation: Apply LAM when emulating data access Robert Hoo
2023-02-13 3:53 ` Chao Gao
2023-02-14 5:38 ` Robert Hoo
2023-02-09 2:40 ` [PATCH v4 9/9] KVM: x86: LAM: Expose LAM CPUID to user space VMM Robert Hoo
2023-02-21 5:47 ` Binbin Wu
2023-02-21 7:26 ` Robert Hoo
2023-02-21 8:26 ` Binbin Wu
2023-02-21 11:13 ` Yu Zhang
2023-02-21 13:18 ` Binbin Wu
2023-02-21 14:36 ` Robert Hoo
2023-02-09 6:15 ` [PATCH v4 0/9] Linear Address Masking (LAM) KVM Enabling Chao Gao
2023-02-09 12:25 ` Robert Hoo
2023-02-09 17:27 ` Sean Christopherson
2023-02-10 2:07 ` Robert Hoo
2023-02-10 3:17 ` Chao Gao
2023-02-10 8:41 ` Robert Hoo
2023-02-10 8:39 ` Robert Hoo
2023-02-10 9:22 ` Chao Gao
2023-02-13 9:02 ` Binbin Wu
2023-02-13 13:16 ` Robert Hoo
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=Y+mvG8S3W5lXoZNJ@gao-cwp \
--to=chao.gao@intel.com \
--cc=isaku.yamahata@intel.com \
--cc=jingqi.liu@intel.com \
--cc=kirill.shutemov@linux.intel.com \
--cc=kvm@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=robert.hu@linux.intel.com \
--cc=seanjc@google.com \
--cc=weijiang.yang@intel.com \
--cc=yu.c.zhang@linux.intel.com \
--cc=yuan.yao@linux.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