Re: [PATCH v2 8/8] KVM: x86: Fold decache_cr3() into cache_reg()

From: Sean Christopherson
Date: Mon Sep 30 2019 - 11:04:38 EST


On Mon, Sep 30, 2019 at 12:58:53PM +0200, Vitaly Kuznetsov wrote:
> Sean Christopherson <sean.j.christopherson@xxxxxxxxx> writes:
>
> > Handle caching CR3 (from VMX's VMCS) into struct kvm_vcpu via the common
> > cache_reg() callback and drop the dedicated decache_cr3(). The name
> > decache_cr3() is somewhat confusing as the caching behavior of CR3
> > follows that of GPRs, RFLAGS and PDPTRs, (handled via cache_reg()), and
> > has nothing in common with the caching behavior of CR0/CR4 (whose
> > decache_cr{0,4}_guest_bits() likely provided the 'decache' verbiage).
> >
> > Note, this effectively adds a BUG() if KVM attempts to cache CR3 on SVM.
> > Opportunistically add a WARN_ON_ONCE() in VMX to provide an equivalent
> > check.
>
> Just to justify my idea of replacing such occasions with
> KVM_INTERNAL_ERROR by setting a special 'kill ASAP' bit somewhere:
>
> This WARN_ON_ONCE() falls in the same category (IMO).

Maybe something like KVM_BUG_ON? E.g.:

#define KVM_BUG_ON(kvm, cond) \
({ \
int r; \
\
if (r = WARN_ON_ONCE(cond)) \
kvm->vm_bugged = true; \
r; \
)}


> > Signed-off-by: Sean Christopherson <sean.j.christopherson@xxxxxxxxx>
> > ---

...

> Reviewed (and Tested-On-Amd-By:): Vitaly Kuznetsov <vkuznets@xxxxxxxxxx>

Thanks for the reviews and for testing on AMD!