• Andy Lutomirski's avatar
    x86,kvm,vmx: Preserve CR4 across VM entry · 4e2c6422
    Andy Lutomirski authored
    commit d974baa3 upstream.
    
    CR4 isn't constant; at least the TSD and PCE bits can vary.
    
    TBH, treating CR0 and CR3 as constant scares me a bit, too, but it looks
    like it's correct.
    
    This adds a branch and a read from cr4 to each vm entry.  Because it is
    extremely likely that consecutive entries into the same vcpu will have
    the same host cr4 value, this fixes up the vmcs instead of restoring cr4
    after the fact.  A subsequent patch will add a kernel-wide cr4 shadow,
    reducing the overhead in the common case to just two memory reads and a
    branch.
    Signed-off-by: default avatarAndy Lutomirski <luto@amacapital.net>
    Acked-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
    Cc: Petr Matousek <pmatouse@redhat.com>
    Cc: Gleb Natapov <gleb@kernel.org>
    Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
    [lizf: Backported to 3.4:
     - adjust context
     - add parameter struct vcpu_vmx *vmx to vmx_set_constant_host_state()]
    Signed-off-by: default avatarZefan Li <lizefan@huawei.com>
    4e2c6422
vmx.c 206 KB