From 34461bafd834645fb981a5a11d6a6edbfff8c385 Mon Sep 17 00:00:00 2001 From: Xiao Guangrong Date: Tue, 21 Aug 2012 11:00:49 +0800 Subject: [PATCH] --- yaml --- r: 329867 b: refs/heads/master c: 12ce13fea925ab629f2281be2b9b01cf647a86cd h: refs/heads/master i: 329865: 0ae681060a9cd16141bf8de99ec7dc7c60d5e109 329863: 3c9827591184f857037b6a83d13b7779f76b1bd4 v: v3 --- [refs] | 2 +- trunk/virt/kvm/kvm_main.c | 24 +++++++++++++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/[refs] b/[refs] index 18cdcc608a42..8b5fd10bb045 100644 --- a/[refs] +++ b/[refs] @@ -1,2 +1,2 @@ --- -refs/heads/master: 2fc843117d64b31c20d36c6b625c0626c9a41a41 +refs/heads/master: 12ce13fea925ab629f2281be2b9b01cf647a86cd diff --git a/trunk/virt/kvm/kvm_main.c b/trunk/virt/kvm/kvm_main.c index aa4a38ad9d9a..c89d1b5129e4 100644 --- a/trunk/virt/kvm/kvm_main.c +++ b/trunk/virt/kvm/kvm_main.c @@ -1054,6 +1054,14 @@ static bool hva_to_pfn_fast(unsigned long addr, bool atomic, bool *async, if (!(async || atomic)) return false; + /* + * 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 + * request. + */ + if (!(write_fault || writable)) + return false; + npages = __get_user_pages_fast(addr, 1, 1, page); if (npages == 1) { *pfn = page_to_pfn(page[0]); @@ -1093,7 +1101,7 @@ static int hva_to_pfn_slow(unsigned long addr, bool *async, bool write_fault, return npages; /* map read fault as writable if possible */ - if (unlikely(!write_fault)) { + if (unlikely(!write_fault) && writable) { struct page *wpage[1]; npages = __get_user_pages_fast(addr, 1, 1, wpage); @@ -1109,6 +1117,20 @@ static int hva_to_pfn_slow(unsigned long addr, bool *async, bool write_fault, return npages; } +/* + * Pin guest page in memory and return its pfn. + * @addr: host virtual address which maps memory to the guest + * @atomic: whether this function can sleep + * @async: whether this function need to wait IO complete if the + * host page is not in the memory + * @write_fault: whether we should get a writable host page + * @writable: whether it allows to map a writable host page for !@write_fault + * + * The function will map a writable host page for these two cases: + * 1): @write_fault = true + * 2): @write_fault = false && @writable, @writable will tell the caller + * whether the mapping is writable. + */ static pfn_t hva_to_pfn(unsigned long addr, bool atomic, bool *async, bool write_fault, bool *writable) {