[patch 03/13] KVM: MMU: gfn_to_page_atomic

Marcelo Tosatti
2008-09-06T19:27:04Z

[-- Attachment #1: kvm-gfn-to-page-atomic --]
[-- Type: text/plain, Size: 1451 bytes --]

KVM wrapper around get_user_pages_fast_atomic.

Index: kvm/include/linux/kvm_host.h
===================================================================
--- kvm.orig/include/linux/kvm_host.h
+++ kvm/include/linux/kvm_host.h
@@ -177,6 +177,7 @@ int kvm_arch_set_memory_region(struct kv
void kvm_arch_flush_shadow(struct kvm *kvm);
gfn_t unalias_gfn(struct kvm *kvm, gfn_t gfn);
struct page *gfn_to_page(struct kvm *kvm, gfn_t gfn);
+struct page *gfn_to_page_atomic(struct kvm *kvm, gfn_t gfn);
unsigned long gfn_to_hva(struct kvm *kvm, gfn_t gfn);
void kvm_release_page_clean(struct page *page);
void kvm_release_page_dirty(struct page *page);
Index: kvm/virt/kvm/kvm_main.c
===================================================================
--- kvm.orig/virt/kvm/kvm_main.c
+++ kvm/virt/kvm/kvm_main.c
@@ -773,6 +773,30 @@ struct page *gfn_to_page(struct kvm *kvm

EXPORT_SYMBOL_GPL(gfn_to_page);

+struct page *gfn_to_page_atomic(struct kvm *kvm, gfn_t gfn)
+{
+ struct page *page[1];
+ unsigned long addr;
+ int npages;
+
+ addr = gfn_to_hva(kvm, gfn);
+ if (kvm_is_error_hva(addr)) {
+ get_page(bad_page);
+ return bad_page;
+ }
+
+ npages = get_user_pages_fast_atomic(addr, 1, 1, page);
+
+ if (unlikely(npages != 1)) {
+ get_page(bad_page);
+ return bad_page;
+ }
+
+ return page[0];
+}
+
+EXPORT_SYMBOL_GPL(gfn_to_page_atomic);
+
void kvm_release_page_clean(struct page *page)
{
kvm_release_pfn_clean(page_to_pfn(page));

--