History

KVM: x86/mmu: Avoid an extra memslot lookup in try_async_pf() for L2

Create a new function kvm_is_visible_memslot() and use it from kvm_is_visible_gfn(); use the new function in try_async_pf() too, to avoid an extra memslot lookup. Opportunistically squish a multi-line comment into a single-line comment. Note, the end result, KVM_PFN_NOSLOT, is unchanged.

Paolo Bonzini committed 6 years ago

Commit c36b7151 parent c583eed3 files · +10 −11Browse files

Unified · Split

3 files
  1. arch/x86/kvm/mmu/mmu.c +3 −6
  2. include/linux/kvm_host.h +6 −0
  3. virt/kvm/kvm_main.c +1 −5
arch/x86/kvm/mmu/mmu.c+3−6
@@ -4082,19 +4082,16 @@ static bool try_async_pf(struct kvm_vcpu *vcpu, bool prefault, gfn_t gfn, · 4081 unmodified lines
40824082 gpa_t cr2_or_gpa, kvm_pfn_t *pfn, bool write,
40834083 bool *writable)
40844084 {
4085− struct kvm_memory_slot *slot;
4085+ struct kvm_memory_slot *slot = kvm_vcpu_gfn_to_memslot(vcpu, gfn);
40864086 bool async;
40874087
4088− /*
4089− * Don't expose private memslots to L2.
4090− */
4091− if (is_guest_mode(vcpu) && !kvm_is_visible_gfn(vcpu->kvm, gfn)) {
4088+ /* Don't expose private memslots to L2. */
4089+ if (is_guest_mode(vcpu) && !kvm_is_visible_memslot(slot)) {
40924090 *pfn = KVM_PFN_NOSLOT;
40934091 *writable = false;
40944092 return false;
40954093 }
40964094
4097− slot = kvm_vcpu_gfn_to_memslot(vcpu, gfn);
40984095 async = false;
40994096 *pfn = __gfn_to_pfn_memslot(slot, gfn, false, &async, write, writable);
41004097 if (!async)
include/linux/kvm_host.h+6−0
@@ -1357,6 +1357,12 @@ static inline void kvm_vcpu_set_dy_eligible(struct kvm_vcpu *vcpu, bool val) · 1356 unmodified lines
13571357 }
13581358 #endif /* CONFIG_HAVE_KVM_CPU_RELAX_INTERCEPT */
13591359
1360+static inline bool kvm_is_visible_memslot(struct kvm_memory_slot *memslot)
1361+{
1362+ return (memslot && memslot->id < KVM_USER_MEM_SLOTS &&
1363+ !(memslot->flags & KVM_MEMSLOT_INVALID));
1364+}
1365+
13601366 struct kvm_vcpu *kvm_get_running_vcpu(void);
13611367 struct kvm_vcpu * __percpu *kvm_get_running_vcpus(void);
13621368
virt/kvm/kvm_main.c+1−5
@@ -1607,11 +1607,7 @@ bool kvm_is_visible_gfn(struct kvm *kvm, gfn_t gfn) · 1606 unmodified lines
16071607 {
16081608 struct kvm_memory_slot *memslot = gfn_to_memslot(kvm, gfn);
16091609
1610− if (!memslot || memslot->id >= KVM_USER_MEM_SLOTS ||
1611− memslot->flags & KVM_MEMSLOT_INVALID)
1612− return false;
1613−
1614− return true;
1610+ return kvm_is_visible_memslot(memslot);
16151611 }
16161612 EXPORT_SYMBOL_GPL(kvm_is_visible_gfn);
16171613

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t