|
56 | 56 | #define SPTE_MMU_WRITEABLE (1ULL << (PT_FIRST_AVAIL_BITS_SHIFT + 1))
|
57 | 57 |
|
58 | 58 | /*
|
59 |
| - * Due to limited space in PTEs, the MMIO generation is a 19 bit subset of |
| 59 | + * Due to limited space in PTEs, the MMIO generation is a 18 bit subset of |
60 | 60 | * the memslots generation and is derived as follows:
|
61 | 61 | *
|
62 | 62 | * Bits 0-8 of the MMIO generation are propagated to spte bits 3-11
|
63 |
| - * Bits 9-18 of the MMIO generation are propagated to spte bits 52-61 |
| 63 | + * Bits 9-17 of the MMIO generation are propagated to spte bits 54-62 |
64 | 64 | *
|
65 | 65 | * The KVM_MEMSLOT_GEN_UPDATE_IN_PROGRESS flag is intentionally not included in
|
66 | 66 | * the MMIO generation number, as doing so would require stealing a bit from
|
|
69 | 69 | * requires a full MMU zap). The flag is instead explicitly queried when
|
70 | 70 | * checking for MMIO spte cache hits.
|
71 | 71 | */
|
72 |
| -#define MMIO_SPTE_GEN_MASK GENMASK_ULL(17, 0) |
73 | 72 |
|
74 | 73 | #define MMIO_SPTE_GEN_LOW_START 3
|
75 | 74 | #define MMIO_SPTE_GEN_LOW_END 11
|
76 |
| -#define MMIO_SPTE_GEN_LOW_MASK GENMASK_ULL(MMIO_SPTE_GEN_LOW_END, \ |
77 |
| - MMIO_SPTE_GEN_LOW_START) |
78 | 75 |
|
79 | 76 | #define MMIO_SPTE_GEN_HIGH_START PT64_SECOND_AVAIL_BITS_SHIFT
|
80 | 77 | #define MMIO_SPTE_GEN_HIGH_END 62
|
| 78 | + |
| 79 | +#define MMIO_SPTE_GEN_LOW_MASK GENMASK_ULL(MMIO_SPTE_GEN_LOW_END, \ |
| 80 | + MMIO_SPTE_GEN_LOW_START) |
81 | 81 | #define MMIO_SPTE_GEN_HIGH_MASK GENMASK_ULL(MMIO_SPTE_GEN_HIGH_END, \
|
82 | 82 | MMIO_SPTE_GEN_HIGH_START)
|
83 | 83 |
|
| 84 | +#define MMIO_SPTE_GEN_LOW_BITS (MMIO_SPTE_GEN_LOW_END - MMIO_SPTE_GEN_LOW_START + 1) |
| 85 | +#define MMIO_SPTE_GEN_HIGH_BITS (MMIO_SPTE_GEN_HIGH_END - MMIO_SPTE_GEN_HIGH_START + 1) |
| 86 | + |
| 87 | +/* remember to adjust the comment above as well if you change these */ |
| 88 | +static_assert(MMIO_SPTE_GEN_LOW_BITS == 9 && MMIO_SPTE_GEN_HIGH_BITS == 9); |
| 89 | + |
| 90 | +#define MMIO_SPTE_GEN_LOW_SHIFT (MMIO_SPTE_GEN_LOW_START - 0) |
| 91 | +#define MMIO_SPTE_GEN_HIGH_SHIFT (MMIO_SPTE_GEN_HIGH_START - MMIO_SPTE_GEN_LOW_BITS) |
| 92 | + |
| 93 | +#define MMIO_SPTE_GEN_MASK GENMASK_ULL(MMIO_SPTE_GEN_LOW_BITS + MMIO_SPTE_GEN_HIGH_BITS - 1, 0) |
| 94 | + |
84 | 95 | extern u64 __read_mostly shadow_nx_mask;
|
85 | 96 | extern u64 __read_mostly shadow_x_mask; /* mutual exclusive with nx_mask */
|
86 | 97 | extern u64 __read_mostly shadow_user_mask;
|
@@ -228,8 +239,8 @@ static inline u64 get_mmio_spte_generation(u64 spte)
|
228 | 239 | {
|
229 | 240 | u64 gen;
|
230 | 241 |
|
231 |
| - gen = (spte & MMIO_SPTE_GEN_LOW_MASK) >> MMIO_SPTE_GEN_LOW_START; |
232 |
| - gen |= (spte & MMIO_SPTE_GEN_HIGH_MASK) >> MMIO_SPTE_GEN_HIGH_START; |
| 242 | + gen = (spte & MMIO_SPTE_GEN_LOW_MASK) >> MMIO_SPTE_GEN_LOW_SHIFT; |
| 243 | + gen |= (spte & MMIO_SPTE_GEN_HIGH_MASK) >> MMIO_SPTE_GEN_HIGH_SHIFT; |
233 | 244 | return gen;
|
234 | 245 | }
|
235 | 246 |
|
|
0 commit comments