Skip to content

Commit e308c24

Browse files
mmhaldwmw2
authored andcommitted
KVM: Use gfn_to_pfn_cache's immutable "kvm" in kvm_gpc_check()
Make kvm_gpc_check() use kvm instance cached in gfn_to_pfn_cache. Suggested-by: Sean Christopherson <[email protected]> Signed-off-by: Michal Luczaj <[email protected]> Signed-off-by: Sean Christopherson <[email protected]> Signed-off-by: David Woodhouse <[email protected]>
1 parent 8c82a0b commit e308c24

File tree

4 files changed

+11
-16
lines changed

4 files changed

+11
-16
lines changed

arch/x86/kvm/x86.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3035,7 +3035,7 @@ static void kvm_setup_guest_pvclock(struct kvm_vcpu *v,
30353035
unsigned long flags;
30363036

30373037
read_lock_irqsave(&gpc->lock, flags);
3038-
while (!kvm_gpc_check(v->kvm, gpc, gpc->gpa,
3038+
while (!kvm_gpc_check(gpc, gpc->gpa,
30393039
offset + sizeof(*guest_hv_clock))) {
30403040
read_unlock_irqrestore(&gpc->lock, flags);
30413041

arch/x86/kvm/xen.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ static void kvm_xen_update_runstate_guest(struct kvm_vcpu *v, bool atomic)
272272
* gfn_to_pfn caches that cover the region.
273273
*/
274274
read_lock_irqsave(&gpc1->lock, flags);
275-
while (!kvm_gpc_check(v->kvm, gpc1, gpc1->gpa, user_len1)) {
275+
while (!kvm_gpc_check(gpc1, gpc1->gpa, user_len1)) {
276276
read_unlock_irqrestore(&gpc1->lock, flags);
277277

278278
/* When invoked from kvm_sched_out() we cannot sleep */
@@ -308,7 +308,7 @@ static void kvm_xen_update_runstate_guest(struct kvm_vcpu *v, bool atomic)
308308
*/
309309
read_lock(&gpc2->lock);
310310

311-
if (!kvm_gpc_check(v->kvm, gpc2, gpc2->gpa, user_len2)) {
311+
if (!kvm_gpc_check(gpc2, gpc2->gpa, user_len2)) {
312312
read_unlock(&gpc2->lock);
313313
read_unlock_irqrestore(&gpc1->lock, flags);
314314

@@ -488,8 +488,7 @@ void kvm_xen_inject_pending_events(struct kvm_vcpu *v)
488488
* little more honest about it.
489489
*/
490490
read_lock_irqsave(&gpc->lock, flags);
491-
while (!kvm_gpc_check(v->kvm, gpc, gpc->gpa,
492-
sizeof(struct vcpu_info))) {
491+
while (!kvm_gpc_check(gpc, gpc->gpa, sizeof(struct vcpu_info))) {
493492
read_unlock_irqrestore(&gpc->lock, flags);
494493

495494
if (kvm_gpc_refresh(v->kvm, gpc, gpc->gpa,
@@ -553,8 +552,7 @@ int __kvm_xen_has_interrupt(struct kvm_vcpu *v)
553552
sizeof_field(struct compat_vcpu_info, evtchn_upcall_pending));
554553

555554
read_lock_irqsave(&gpc->lock, flags);
556-
while (!kvm_gpc_check(v->kvm, gpc, gpc->gpa,
557-
sizeof(struct vcpu_info))) {
555+
while (!kvm_gpc_check(gpc, gpc->gpa, sizeof(struct vcpu_info))) {
558556
read_unlock_irqrestore(&gpc->lock, flags);
559557

560558
/*
@@ -1158,7 +1156,7 @@ static bool wait_pending_event(struct kvm_vcpu *vcpu, int nr_ports,
11581156

11591157
read_lock_irqsave(&gpc->lock, flags);
11601158
idx = srcu_read_lock(&kvm->srcu);
1161-
if (!kvm_gpc_check(kvm, gpc, gpc->gpa, PAGE_SIZE))
1159+
if (!kvm_gpc_check(gpc, gpc->gpa, PAGE_SIZE))
11621160
goto out_rcu;
11631161

11641162
ret = false;
@@ -1580,7 +1578,7 @@ int kvm_xen_set_evtchn_fast(struct kvm_xen_evtchn *xe, struct kvm *kvm)
15801578
idx = srcu_read_lock(&kvm->srcu);
15811579

15821580
read_lock_irqsave(&gpc->lock, flags);
1583-
if (!kvm_gpc_check(kvm, gpc, gpc->gpa, PAGE_SIZE))
1581+
if (!kvm_gpc_check(gpc, gpc->gpa, PAGE_SIZE))
15841582
goto out_rcu;
15851583

15861584
if (IS_ENABLED(CONFIG_64BIT) && kvm->arch.xen.long_mode) {
@@ -1614,7 +1612,7 @@ int kvm_xen_set_evtchn_fast(struct kvm_xen_evtchn *xe, struct kvm *kvm)
16141612
gpc = &vcpu->arch.xen.vcpu_info_cache;
16151613

16161614
read_lock_irqsave(&gpc->lock, flags);
1617-
if (!kvm_gpc_check(kvm, gpc, gpc->gpa, sizeof(struct vcpu_info))) {
1615+
if (!kvm_gpc_check(gpc, gpc->gpa, sizeof(struct vcpu_info))) {
16181616
/*
16191617
* Could not access the vcpu_info. Set the bit in-kernel
16201618
* and prod the vCPU to deliver it for itself.

include/linux/kvm_host.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1298,7 +1298,6 @@ int kvm_gpc_activate(struct gfn_to_pfn_cache *gpc, gpa_t gpa, unsigned long len)
12981298
/**
12991299
* kvm_gpc_check - check validity of a gfn_to_pfn_cache.
13001300
*
1301-
* @kvm: pointer to kvm instance.
13021301
* @gpc: struct gfn_to_pfn_cache object.
13031302
* @gpa: current guest physical address to map.
13041303
* @len: sanity check; the range being access must fit a single page.
@@ -1313,8 +1312,7 @@ int kvm_gpc_activate(struct gfn_to_pfn_cache *gpc, gpa_t gpa, unsigned long len)
13131312
* Callers in IN_GUEST_MODE may do so without locking, although they should
13141313
* still hold a read lock on kvm->scru for the memslot checks.
13151314
*/
1316-
bool kvm_gpc_check(struct kvm *kvm, struct gfn_to_pfn_cache *gpc, gpa_t gpa,
1317-
unsigned long len);
1315+
bool kvm_gpc_check(struct gfn_to_pfn_cache *gpc, gpa_t gpa, unsigned long len);
13181316

13191317
/**
13201318
* kvm_gpc_refresh - update a previously initialized cache.

virt/kvm/pfncache.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,9 @@ void gfn_to_pfn_cache_invalidate_start(struct kvm *kvm, unsigned long start,
7676
}
7777
}
7878

79-
bool kvm_gpc_check(struct kvm *kvm, struct gfn_to_pfn_cache *gpc, gpa_t gpa,
80-
unsigned long len)
79+
bool kvm_gpc_check(struct gfn_to_pfn_cache *gpc, gpa_t gpa, unsigned long len)
8180
{
82-
struct kvm_memslots *slots = kvm_memslots(kvm);
81+
struct kvm_memslots *slots = kvm_memslots(gpc->kvm);
8382

8483
if (!gpc->active)
8584
return false;

0 commit comments

Comments
 (0)