diff mbox

kvm: allow RO page when atomic && !write_fault

Message ID 4D61E058.9080201@cn.fujitsu.com (mailing list archive)
State New, archived
Headers show

Commit Message

Lai Jiangshan Feb. 21, 2011, 3:47 a.m. UTC
None
diff mbox

Patch

diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 1fa0d29..f49cfc0 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -1060,31 +1060,27 @@  static pfn_t hva_to_pfn(struct kvm *kvm, unsigned long addr, bool atomic,
 	BUG_ON(!write_fault && !writable);
 
 	if (writable)
-		*writable = true;
+		*writable = write_fault;
 
 	if (atomic || async)
-		npages = __get_user_pages_fast(addr, 1, 1, page);
+		npages = __get_user_pages_fast(addr, 1, write_fault, page);
 
 	if (unlikely(npages != 1) && !atomic) {
 		might_sleep();
-
-		if (writable)
-			*writable = write_fault;
-
 		npages = get_user_pages_fast(addr, 1, write_fault, page);
+	}
 
-		/* map read fault as writable if possible */
-		if (unlikely(!write_fault) && npages == 1) {
-			struct page *wpage[1];
+	/* map read fault as writable if possible */
+	if (unlikely(!write_fault) && npages == 1) {
+		struct page *wpage[1];
 
-			npages = __get_user_pages_fast(addr, 1, 1, wpage);
-			if (npages == 1) {
-				*writable = true;
-				put_page(page[0]);
-				page[0] = wpage[0];
-			}
-			npages = 1;
+		npages = __get_user_pages_fast(addr, 1, 1, wpage);
+		if (npages == 1) {
+			*writable = true;
+			put_page(page[0]);
+			page[0] = wpage[0];
 		}
+		npages = 1;
 	}
 
 	if (unlikely(npages != 1)) {