Skip to content

Commit 0318f20

Browse files
mmhaldwmw2
authored andcommitted
KVM: Use gfn_to_pfn_cache's immutable "kvm" in kvm_gpc_refresh()
Make kvm_gpc_refresh() use kvm instance cached in gfn_to_pfn_cache. No functional change intended. Suggested-by: Sean Christopherson <[email protected]> Signed-off-by: Michal Luczaj <[email protected]> [sean: leave kvm_gpc_unmap() as-is] Signed-off-by: Sean Christopherson <[email protected]> Signed-off-by: David Woodhouse <[email protected]>
1 parent 2a0b128 commit 0318f20

File tree

4 files changed

+12
-17
lines changed

4 files changed

+12
-17
lines changed

arch/x86/kvm/x86.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3039,7 +3039,7 @@ static void kvm_setup_guest_pvclock(struct kvm_vcpu *v,
30393039
offset + sizeof(*guest_hv_clock))) {
30403040
read_unlock_irqrestore(&gpc->lock, flags);
30413041

3042-
if (kvm_gpc_refresh(v->kvm, gpc, gpc->gpa,
3042+
if (kvm_gpc_refresh(gpc, gpc->gpa,
30433043
offset + sizeof(*guest_hv_clock)))
30443044
return;
30453045

arch/x86/kvm/xen.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ static void kvm_xen_update_runstate_guest(struct kvm_vcpu *v, bool atomic)
279279
if (atomic)
280280
return;
281281

282-
if (kvm_gpc_refresh(v->kvm, gpc1, gpc1->gpa, user_len1))
282+
if (kvm_gpc_refresh(gpc1, gpc1->gpa, user_len1))
283283
return;
284284

285285
read_lock_irqsave(&gpc1->lock, flags);
@@ -491,8 +491,7 @@ void kvm_xen_inject_pending_events(struct kvm_vcpu *v)
491491
while (!kvm_gpc_check(gpc, gpc->gpa, sizeof(struct vcpu_info))) {
492492
read_unlock_irqrestore(&gpc->lock, flags);
493493

494-
if (kvm_gpc_refresh(v->kvm, gpc, gpc->gpa,
495-
sizeof(struct vcpu_info)))
494+
if (kvm_gpc_refresh(gpc, gpc->gpa, sizeof(struct vcpu_info)))
496495
return;
497496

498497
read_lock_irqsave(&gpc->lock, flags);
@@ -566,8 +565,7 @@ int __kvm_xen_has_interrupt(struct kvm_vcpu *v)
566565
if (in_atomic() || !task_is_running(current))
567566
return 1;
568567

569-
if (kvm_gpc_refresh(v->kvm, gpc, gpc->gpa,
570-
sizeof(struct vcpu_info))) {
568+
if (kvm_gpc_refresh(gpc, gpc->gpa, sizeof(struct vcpu_info))) {
571569
/*
572570
* If this failed, userspace has screwed up the
573571
* vcpu_info mapping. No interrupts for you.
@@ -1710,7 +1708,7 @@ static int kvm_xen_set_evtchn(struct kvm_xen_evtchn *xe, struct kvm *kvm)
17101708
break;
17111709

17121710
idx = srcu_read_lock(&kvm->srcu);
1713-
rc = kvm_gpc_refresh(kvm, gpc, gpc->gpa, PAGE_SIZE);
1711+
rc = kvm_gpc_refresh(gpc, gpc->gpa, PAGE_SIZE);
17141712
srcu_read_unlock(&kvm->srcu, idx);
17151713
} while(!rc);
17161714

include/linux/kvm_host.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1317,23 +1317,21 @@ bool kvm_gpc_check(struct gfn_to_pfn_cache *gpc, gpa_t gpa, unsigned long len);
13171317
/**
13181318
* kvm_gpc_refresh - update a previously initialized cache.
13191319
*
1320-
* @kvm: pointer to kvm instance.
13211320
* @gpc: struct gfn_to_pfn_cache object.
13221321
* @gpa: updated guest physical address to map.
13231322
* @len: sanity check; the range being access must fit a single page.
1324-
*
1323+
13251324
* @return: 0 for success.
13261325
* -EINVAL for a mapping which would cross a page boundary.
1327-
* -EFAULT for an untranslatable guest physical address.
1326+
* -EFAULT for an untranslatable guest physical address.
13281327
*
13291328
* This will attempt to refresh a gfn_to_pfn_cache. Note that a successful
1330-
* returm from this function does not mean the page can be immediately
1329+
* return from this function does not mean the page can be immediately
13311330
* accessed because it may have raced with an invalidation. Callers must
13321331
* still lock and check the cache status, as this function does not return
13331332
* with the lock still held to permit access.
13341333
*/
1335-
int kvm_gpc_refresh(struct kvm *kvm, struct gfn_to_pfn_cache *gpc, gpa_t gpa,
1336-
unsigned long len);
1334+
int kvm_gpc_refresh(struct gfn_to_pfn_cache *gpc, gpa_t gpa, unsigned long len);
13371335

13381336
/**
13391337
* kvm_gpc_unmap - temporarily unmap a gfn_to_pfn_cache.

virt/kvm/pfncache.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -237,10 +237,9 @@ static kvm_pfn_t hva_to_pfn_retry(struct gfn_to_pfn_cache *gpc)
237237
return -EFAULT;
238238
}
239239

240-
int kvm_gpc_refresh(struct kvm *kvm, struct gfn_to_pfn_cache *gpc, gpa_t gpa,
241-
unsigned long len)
240+
int kvm_gpc_refresh(struct gfn_to_pfn_cache *gpc, gpa_t gpa, unsigned long len)
242241
{
243-
struct kvm_memslots *slots = kvm_memslots(kvm);
242+
struct kvm_memslots *slots = kvm_memslots(gpc->kvm);
244243
unsigned long page_offset = gpa & ~PAGE_MASK;
245244
bool unmap_old = false;
246245
unsigned long old_uhva;
@@ -399,7 +398,7 @@ int kvm_gpc_activate(struct gfn_to_pfn_cache *gpc, gpa_t gpa, unsigned long len)
399398
gpc->active = true;
400399
write_unlock_irq(&gpc->lock);
401400
}
402-
return kvm_gpc_refresh(kvm, gpc, gpa, len);
401+
return kvm_gpc_refresh(gpc, gpa, len);
403402
}
404403
EXPORT_SYMBOL_GPL(kvm_gpc_activate);
405404

0 commit comments

Comments
 (0)