Skip to content

Commit 5192f9b

Browse files
Sean Christophersonbonzini
Sean Christopherson
authored andcommitted
KVM: x86: Use a u64 when passing the MMIO gen around
KVM currently uses an 'unsigned int' for the MMIO generation number despite it being derived from the 64-bit memslots generation and being propagated to (potentially) 64-bit sptes. There is no hidden agenda behind using an 'unsigned int', it's done simply because the MMIO generation will never set bits above bit 19. Passing a u64 will allow the "update in-progress" flag to be relocated from bit 0 to bit 63 and removes the need to cast the generation back to a u64 when propagating it to a spte. Signed-off-by: Sean Christopherson <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 361209e commit 5192f9b

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

arch/x86/kvm/mmu.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -348,20 +348,20 @@ static inline bool is_access_track_spte(u64 spte)
348348
#define MMIO_GEN_LOW_MASK ((1 << MMIO_GEN_LOW_SHIFT) - 2)
349349
#define MMIO_GEN_MASK ((1 << MMIO_GEN_SHIFT) - 1)
350350

351-
static u64 generation_mmio_spte_mask(unsigned int gen)
351+
static u64 generation_mmio_spte_mask(u64 gen)
352352
{
353353
u64 mask;
354354

355355
WARN_ON(gen & ~MMIO_GEN_MASK);
356356

357357
mask = (gen & MMIO_GEN_LOW_MASK) << MMIO_SPTE_GEN_LOW_SHIFT;
358-
mask |= ((u64)gen >> MMIO_GEN_LOW_SHIFT) << MMIO_SPTE_GEN_HIGH_SHIFT;
358+
mask |= (gen >> MMIO_GEN_LOW_SHIFT) << MMIO_SPTE_GEN_HIGH_SHIFT;
359359
return mask;
360360
}
361361

362-
static unsigned int get_mmio_spte_generation(u64 spte)
362+
static u64 get_mmio_spte_generation(u64 spte)
363363
{
364-
unsigned int gen;
364+
u64 gen;
365365

366366
spte &= ~shadow_mmio_mask;
367367

@@ -370,15 +370,15 @@ static unsigned int get_mmio_spte_generation(u64 spte)
370370
return gen;
371371
}
372372

373-
static unsigned int kvm_current_mmio_generation(struct kvm_vcpu *vcpu)
373+
static u64 kvm_current_mmio_generation(struct kvm_vcpu *vcpu)
374374
{
375375
return kvm_vcpu_memslots(vcpu)->generation & MMIO_GEN_MASK;
376376
}
377377

378378
static void mark_mmio_spte(struct kvm_vcpu *vcpu, u64 *sptep, u64 gfn,
379379
unsigned access)
380380
{
381-
unsigned int gen = kvm_current_mmio_generation(vcpu);
381+
u64 gen = kvm_current_mmio_generation(vcpu);
382382
u64 mask = generation_mmio_spte_mask(gen);
383383
u64 gpa = gfn << PAGE_SHIFT;
384384

@@ -426,7 +426,7 @@ static bool set_mmio_spte(struct kvm_vcpu *vcpu, u64 *sptep, gfn_t gfn,
426426

427427
static bool check_mmio_spte(struct kvm_vcpu *vcpu, u64 spte)
428428
{
429-
unsigned int kvm_gen, spte_gen;
429+
u64 kvm_gen, spte_gen;
430430

431431
kvm_gen = kvm_current_mmio_generation(vcpu);
432432
spte_gen = get_mmio_spte_generation(spte);

0 commit comments

Comments
 (0)