Commit b9b33da2 authored by Paolo Bonzini's avatar Paolo Bonzini

KVM: try __get_user_pages_fast even if not in atomic context

We are currently cutting hva_to_pfn_fast short if we do not want an
immediate exit, which is represented by !async && !atomic.  However,
this is unnecessary, and __get_user_pages_fast is *much* faster
because the regular get_user_pages takes pmd_lock/pte_lock.
In fact, when many CPUs take a nested vmexit at the same time
the contention on those locks is visible, and this patch removes
about 25% (compared to 4.18) from vmexit.flat on a 16 vCPU
nested guest.
Suggested-by: default avatarAndrea Arcangeli <aarcange@redhat.com>
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent 877ad952
...@@ -1343,18 +1343,16 @@ static inline int check_user_page_hwpoison(unsigned long addr) ...@@ -1343,18 +1343,16 @@ static inline int check_user_page_hwpoison(unsigned long addr)
} }
/* /*
* The atomic path to get the writable pfn which will be stored in @pfn, * The fast path to get the writable pfn which will be stored in @pfn,
* true indicates success, otherwise false is returned. * true indicates success, otherwise false is returned. It's also the
* only part that runs if we can are in atomic context.
*/ */
static bool hva_to_pfn_fast(unsigned long addr, bool atomic, bool *async, static bool hva_to_pfn_fast(unsigned long addr, bool write_fault,
bool write_fault, bool *writable, kvm_pfn_t *pfn) bool *writable, kvm_pfn_t *pfn)
{ {
struct page *page[1]; struct page *page[1];
int npages; int npages;
if (!(async || atomic))
return false;
/* /*
* Fast pin a writable pfn only if it is a write fault request * Fast pin a writable pfn only if it is a write fault request
* or the caller allows to map a writable pfn for a read fault * or the caller allows to map a writable pfn for a read fault
...@@ -1498,7 +1496,7 @@ static kvm_pfn_t hva_to_pfn(unsigned long addr, bool atomic, bool *async, ...@@ -1498,7 +1496,7 @@ static kvm_pfn_t hva_to_pfn(unsigned long addr, bool atomic, bool *async,
/* we can do it either atomically or asynchronously, not both */ /* we can do it either atomically or asynchronously, not both */
BUG_ON(atomic && async); BUG_ON(atomic && async);
if (hva_to_pfn_fast(addr, atomic, async, write_fault, writable, &pfn)) if (hva_to_pfn_fast(addr, write_fault, writable, &pfn))
return pfn; return pfn;
if (atomic) if (atomic)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment