[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <f6a0aed8-2cfe-0af3-dd6f-26e4f203be9e@redhat.com>
Date: Thu, 10 Jun 2021 17:06:04 +0200
From: Paolo Bonzini <pbonzini@...hat.com>
To: Maxim Levitsky <mlevitsk@...hat.com>, kvm@...r.kernel.org
Cc: open list <linux-kernel@...r.kernel.org>,
"open list:DOCUMENTATION" <linux-doc@...r.kernel.org>,
Wanpeng Li <wanpengli@...cent.com>,
Ingo Molnar <mingo@...hat.com>,
Vitaly Kuznetsov <vkuznets@...hat.com>,
Thomas Gleixner <tglx@...utronix.de>,
Sean Christopherson <seanjc@...gle.com>,
Borislav Petkov <bp@...en8.de>, Joerg Roedel <joro@...tes.org>,
"maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)" <x86@...nel.org>,
Jim Mattson <jmattson@...gle.com>,
Jonathan Corbet <corbet@....net>,
"H. Peter Anvin" <hpa@...or.com>
Subject: Re: [PATCH v3 7/8] KVM: x86: Introduce KVM_GET_SREGS2 /
KVM_SET_SREGS2
On 07/06/21 11:02, Maxim Levitsky wrote:
> +static int __set_sregs2(struct kvm_vcpu *vcpu, struct kvm_sregs2 *sregs2)
> +{
> + int mmu_reset_needed = 0;
> + bool valid_pdptrs = sregs2->flags & KVM_SREGS2_FLAGS_PDPTRS_VALID;
> + int i, ret;
>
> + if (sregs2->flags & ~KVM_SREGS2_FLAGS_PDPTRS_VALID)
> + return -EINVAL;
> +
> + ret = __set_sregs_common(vcpu, (struct kvm_sregs *)sregs2,
> + &mmu_reset_needed, !valid_pdptrs);
> + if (ret)
> + return ret;
> +
> + if (valid_pdptrs) {
> + if (!is_pae_paging(vcpu))
> + return -EINVAL;
> + if (vcpu->arch.guest_state_protected)
> + return -EINVAL;
> + for (i = 0 ; i < 4 ; i++)
> + kvm_pdptr_write(vcpu, i, sregs2->pdptrs[i]);
> +
> + kvm_register_mark_dirty(vcpu, VCPU_EXREG_PDPTR);
> + mmu_reset_needed = 1;
> + }
> + if (mmu_reset_needed)
> + kvm_mmu_reset_context(vcpu);
> + return 0;
> }
It's a bit nicer if the checks are done early:
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index f20c7c06bd4a..c6f8fec78c53 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -10248,22 +10248,23 @@ static int __set_sregs2(struct kvm_vcpu *vcpu, struct kvm_sregs2 *sregs2)
{
int mmu_reset_needed = 0;
bool valid_pdptrs = sregs2->flags & KVM_SREGS2_FLAGS_PDPTRS_VALID;
+ bool pae = (sregs2->cr0 & X86_CR0_PG) && (sregs2->cr4 & X86_CR4_PAE) &&
+ !(sregs2->efer & EFER_LMA);
int i, ret;
if (sregs2->flags & ~KVM_SREGS2_FLAGS_PDPTRS_VALID)
return -EINVAL;
+ if (valid_pdptrs && (!pae || vcpu->arch.guest_state_protected))
+ return -EINVAL;
+
ret = __set_sregs_common(vcpu, (struct kvm_sregs *)sregs2,
&mmu_reset_needed, !valid_pdptrs);
if (ret)
return ret;
if (valid_pdptrs) {
- if (!is_pae_paging(vcpu))
- return -EINVAL;
- if (vcpu->arch.guest_state_protected)
- return -EINVAL;
- for (i = 0 ; i < 4 ; i++)
+ for (i = 0; i < 4 ; i++)
kvm_pdptr_write(vcpu, i, sregs2->pdptrs[i]);
kvm_register_mark_dirty(vcpu, VCPU_EXREG_PDPTR);
Paolo
Powered by blists - more mailing lists