aboutsummaryrefslogtreecommitdiffstats
path: root/xen
diff options
context:
space:
mode:
authorTim Deegan <tim@xen.org>2012-03-08 16:40:05 +0000
committerTim Deegan <tim@xen.org>2012-03-08 16:40:05 +0000
commit7a3de767373545388a9fded238b3450c5b21066d (patch)
tree8f8d0a768593e3753e14bc57626f9829d07326f5 /xen
parent08d62198150bb50f4a0e19e5f96141c2394415f0 (diff)
downloadxen-7a3de767373545388a9fded238b3450c5b21066d.tar.gz
xen-7a3de767373545388a9fded238b3450c5b21066d.tar.bz2
xen-7a3de767373545388a9fded238b3450c5b21066d.zip
x86/hvm: refactor calls to prepare and tear down a helper ring
These are currently used for the rings connecting Xen with qemu. Refactor them so the same code can be later used for mem event rings. Signed-off-by: Andres Lagar-Cavilla <andres@lagarcavilla.org> Acked-by: Tim Deegan <tim@xen.org> Committed-by: Tim Deegan <tim@xen.org>
Diffstat (limited to 'xen')
-rw-r--r--xen/arch/x86/hvm/hvm.c48
-rw-r--r--xen/include/asm-x86/hvm/hvm.h7
2 files changed, 43 insertions, 12 deletions
diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c
index e926c581a9..df4326cce6 100644
--- a/xen/arch/x86/hvm/hvm.c
+++ b/xen/arch/x86/hvm/hvm.c
@@ -339,6 +339,19 @@ static void hvm_init_ioreq_page(
domain_pause(d);
}
+void destroy_ring_for_helper(
+ void **_va, struct page_info *page)
+{
+ void *va = *_va;
+
+ if ( va != NULL )
+ {
+ unmap_domain_page_global(va);
+ put_page_and_type(page);
+ *_va = NULL;
+ }
+}
+
static void hvm_destroy_ioreq_page(
struct domain *d, struct hvm_ioreq_page *iorp)
{
@@ -346,18 +359,14 @@ static void hvm_destroy_ioreq_page(
ASSERT(d->is_dying);
- if ( iorp->va != NULL )
- {
- unmap_domain_page_global(iorp->va);
- put_page_and_type(iorp->page);
- iorp->va = NULL;
- }
+ destroy_ring_for_helper(&iorp->va, iorp->page);
spin_unlock(&iorp->lock);
}
-static int hvm_set_ioreq_page(
- struct domain *d, struct hvm_ioreq_page *iorp, unsigned long gmfn)
+int prepare_ring_for_helper(
+ struct domain *d, unsigned long gmfn, struct page_info **_page,
+ void **_va)
{
struct page_info *page;
p2m_type_t p2mt;
@@ -398,14 +407,30 @@ static int hvm_set_ioreq_page(
return -ENOMEM;
}
+ *_va = va;
+ *_page = page;
+
+ put_gfn(d, gmfn);
+
+ return 0;
+}
+
+static int hvm_set_ioreq_page(
+ struct domain *d, struct hvm_ioreq_page *iorp, unsigned long gmfn)
+{
+ struct page_info *page;
+ void *va;
+ int rc;
+
+ if ( (rc = prepare_ring_for_helper(d, gmfn, &page, &va)) )
+ return rc;
+
spin_lock(&iorp->lock);
if ( (iorp->va != NULL) || d->is_dying )
{
+ destroy_ring_for_helper(&iorp->va, iorp->page);
spin_unlock(&iorp->lock);
- unmap_domain_page_global(va);
- put_page_and_type(mfn_to_page(mfn));
- put_gfn(d, gmfn);
return -EINVAL;
}
@@ -413,7 +438,6 @@ static int hvm_set_ioreq_page(
iorp->page = page;
spin_unlock(&iorp->lock);
- put_gfn(d, gmfn);
domain_unpause(d);
diff --git a/xen/include/asm-x86/hvm/hvm.h b/xen/include/asm-x86/hvm/hvm.h
index 1a113f2bf9..69f4477472 100644
--- a/xen/include/asm-x86/hvm/hvm.h
+++ b/xen/include/asm-x86/hvm/hvm.h
@@ -26,6 +26,7 @@
#include <asm/hvm/asid.h>
#include <public/domctl.h>
#include <public/hvm/save.h>
+#include <asm/mm.h>
/* Interrupt acknowledgement sources. */
enum hvm_intsrc {
@@ -191,6 +192,12 @@ int hvm_vcpu_cacheattr_init(struct vcpu *v);
void hvm_vcpu_cacheattr_destroy(struct vcpu *v);
void hvm_vcpu_reset_state(struct vcpu *v, uint16_t cs, uint16_t ip);
+/* Prepare/destroy a ring for a dom0 helper. Helper with talk
+ * with Xen on behalf of this hvm domain. */
+int prepare_ring_for_helper(struct domain *d, unsigned long gmfn,
+ struct page_info **_page, void **_va);
+void destroy_ring_for_helper(void **_va, struct page_info *page);
+
bool_t hvm_send_assist_req(struct vcpu *v);
void hvm_set_guest_tsc(struct vcpu *v, u64 guest_tsc);