]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - queue-4.19/kvm-x86-mmu-detect-mmio-generation-wrap-in-any-address-space.patch
Linux 4.14.108
[thirdparty/kernel/stable-queue.git] / queue-4.19 / kvm-x86-mmu-detect-mmio-generation-wrap-in-any-address-space.patch
1 From e1359e2beb8b0a1188abc997273acbaedc8ee791 Mon Sep 17 00:00:00 2001
2 From: Sean Christopherson <sean.j.christopherson@intel.com>
3 Date: Tue, 5 Feb 2019 13:01:12 -0800
4 Subject: KVM: x86/mmu: Detect MMIO generation wrap in any address space
5
6 From: Sean Christopherson <sean.j.christopherson@intel.com>
7
8 commit e1359e2beb8b0a1188abc997273acbaedc8ee791 upstream.
9
10 The check to detect a wrap of the MMIO generation explicitly looks for a
11 generation number of zero. Now that unique memslots generation numbers
12 are assigned to each address space, only address space 0 will get a
13 generation number of exactly zero when wrapping. E.g. when address
14 space 1 goes from 0x7fffe to 0x80002, the MMIO generation number will
15 wrap to 0x2. Adjust the MMIO generation to strip the address space
16 modifier prior to checking for a wrap.
17
18 Fixes: 4bd518f1598d ("KVM: use separate generations for each address space")
19 Cc: <stable@vger.kernel.org>
20 Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
21 Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
22 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
23
24 ---
25 arch/x86/kvm/mmu.c | 21 +++++++++++++++++++--
26 1 file changed, 19 insertions(+), 2 deletions(-)
27
28 --- a/arch/x86/kvm/mmu.c
29 +++ b/arch/x86/kvm/mmu.c
30 @@ -5776,11 +5776,28 @@ static bool kvm_has_zapped_obsolete_page
31
32 void kvm_mmu_invalidate_mmio_sptes(struct kvm *kvm, u64 gen)
33 {
34 + gen &= MMIO_GEN_MASK;
35 +
36 + /*
37 + * Shift to eliminate the "update in-progress" flag, which isn't
38 + * included in the spte's generation number.
39 + */
40 + gen >>= 1;
41 +
42 + /*
43 + * Generation numbers are incremented in multiples of the number of
44 + * address spaces in order to provide unique generations across all
45 + * address spaces. Strip what is effectively the address space
46 + * modifier prior to checking for a wrap of the MMIO generation so
47 + * that a wrap in any address space is detected.
48 + */
49 + gen &= ~((u64)KVM_ADDRESS_SPACE_NUM - 1);
50 +
51 /*
52 - * The very rare case: if the generation-number is round,
53 + * The very rare case: if the MMIO generation number has wrapped,
54 * zap all shadow pages.
55 */
56 - if (unlikely((gen & MMIO_GEN_MASK) == 0)) {
57 + if (unlikely(gen == 0)) {
58 kvm_debug_ratelimited("kvm: zapping shadow pages for mmio generation wraparound\n");
59 kvm_mmu_invalidate_zap_all_pages(kvm);
60 }