direct-io.hg

changeset 11336:c232365128cf

[IA64] Expand hvm_op hypercall for PV-on-HVM/IPF

Introduce HVMOP_setup_shared_info_page
- A page allocated on HVM-guest OS is swapped original shared_info
page with this hypercall.
- In x86 code, original shared_info page is used after pv-on-hvm
setup with remapping feature in arch depend HYPERVISOR_memory_op.
But, we can't implement same feature for IPF, thus we select to
implement with this method.
Introduce HVMOP_setup_gnttab_table
- Pages allocated on HVM-guest OS is swapped original grant_table
page frames with this hypercall.
- Same above.

Signed-off-by: Tsunehisa Doi <Doi.Tsunehisa@jp.fujitsu.com>
Signed-off-by: Tomonari Horikoshi <t.horikoshi@jp.fujitsu.com>
author awilliam@xenbuild.aw
date Fri Aug 25 15:06:18 2006 -0600 (2006-08-25)
parents 0ae5ba4585c9
children d188c51ea883
files xen/arch/ia64/vmx/vmx_hypercall.c xen/include/public/arch-ia64.h
line diff
     1.1 --- a/xen/arch/ia64/vmx/vmx_hypercall.c	Thu Aug 24 11:54:23 2006 -0600
     1.2 +++ b/xen/arch/ia64/vmx/vmx_hypercall.c	Fri Aug 25 15:06:18 2006 -0600
     1.3 @@ -2,6 +2,7 @@
     1.4  /*
     1.5   * vmx_hyparcall.c: handling hypercall from domain
     1.6   * Copyright (c) 2005, Intel Corporation.
     1.7 + * Copyright (c) 2006, Fujitsu Limited.
     1.8   *
     1.9   * This program is free software; you can redistribute it and/or modify it
    1.10   * under the terms and conditions of the GNU General Public License,
    1.11 @@ -17,6 +18,8 @@
    1.12   * Place - Suite 330, Boston, MA 02111-1307 USA.
    1.13   *
    1.14   *  Xuefei Xu (Anthony Xu) (Anthony.xu@intel.com)
    1.15 + *  Tsunehisa Doi (Doi.Tsunehisa@jp.fujitsu.com)
    1.16 + *  Tomonari Horikoshi (t.horikoshi@jp.fujitsu.com)
    1.17   */
    1.18  
    1.19  #include <xen/config.h>
    1.20 @@ -34,6 +37,89 @@
    1.21  #include <public/version.h>
    1.22  #include <asm/dom_fw.h>
    1.23  #include <xen/domain.h>
    1.24 +#include <xen/compile.h>
    1.25 +#include <xen/event.h>
    1.26 +
    1.27 +static void
    1.28 +vmx_free_pages(unsigned long pgaddr, int npg)
    1.29 +{
    1.30 +    for (; npg > 0; npg--, pgaddr += PAGE_SIZE) {
    1.31 +        /* If original page belongs to xen heap, then relinguish back
    1.32 +         * to xen heap. Or else, leave to domain itself to decide.
    1.33 +         */
    1.34 +        if (likely(IS_XEN_HEAP_FRAME(virt_to_page(pgaddr)))) {
    1.35 +            free_domheap_page(virt_to_page(pgaddr));
    1.36 +            free_xenheap_page((void *)pgaddr);
    1.37 +        }
    1.38 +        else {
    1.39 +            put_page(virt_to_page(pgaddr));
    1.40 +        }
    1.41 +    }
    1.42 +}
    1.43 +
    1.44 +static int
    1.45 +vmx_gnttab_setup_table(unsigned long frame_pa, unsigned long nr_frames)
    1.46 +{
    1.47 +    struct domain *d = current->domain;
    1.48 +    unsigned long o_grant_shared, pgaddr;
    1.49 +
    1.50 +    if ((nr_frames != NR_GRANT_FRAMES) || (frame_pa & (PAGE_SIZE - 1))) {
    1.51 +        return -EINVAL;
    1.52 +    }
    1.53 +
    1.54 +    pgaddr = domain_mpa_to_imva(d, frame_pa);
    1.55 +    if (pgaddr == NULL) {
    1.56 +        return -EFAULT;
    1.57 +    }
    1.58 +
    1.59 +    o_grant_shared = (unsigned long)d->grant_table->shared;
    1.60 +    d->grant_table->shared = (struct grant_entry *)pgaddr;
    1.61 +
    1.62 +    /* Copy existing grant table shared into new page */
    1.63 +    if (o_grant_shared) {
    1.64 +        memcpy((void *)d->grant_table->shared,
    1.65 +               (void *)o_grant_shared, PAGE_SIZE * nr_frames);
    1.66 +        vmx_free_pages(o_grant_shared, nr_frames);
    1.67 +    }
    1.68 +    else {
    1.69 +        memset((void *)d->grant_table->shared, 0, PAGE_SIZE * nr_frames);
    1.70 +    }
    1.71 +    return 0;
    1.72 +}
    1.73 +
    1.74 +static int
    1.75 +vmx_setup_shared_info_page(unsigned long gpa)
    1.76 +{
    1.77 +    VCPU *vcpu = current;
    1.78 +    struct domain *d = vcpu->domain;
    1.79 +    unsigned long o_info, pgaddr;
    1.80 +    struct vcpu *v;
    1.81 +
    1.82 +    if (gpa & (PAGE_SIZE - 1)) {
    1.83 +        return -EINVAL;
    1.84 +    }
    1.85 +
    1.86 +    pgaddr = domain_mpa_to_imva(d, gpa);
    1.87 +    if (pgaddr == NULL) {
    1.88 +        return -EFAULT;
    1.89 +    }
    1.90 +
    1.91 +    o_info = (u64)d->shared_info;
    1.92 +    d->shared_info = (shared_info_t *)pgaddr;
    1.93 +
    1.94 +    /* Copy existing shared info into new page */
    1.95 +    if (o_info) {
    1.96 +        memcpy((void*)d->shared_info, (void*)o_info, PAGE_SIZE);
    1.97 +        for_each_vcpu(d, v) {
    1.98 +            v->vcpu_info = &d->shared_info->vcpu_info[v->vcpu_id];
    1.99 +        }
   1.100 +        vmx_free_pages(o_info, 1);
   1.101 +    }
   1.102 +    else {
   1.103 +        memset((void *)d->shared_info, 0, PAGE_SIZE);
   1.104 +    }
   1.105 +    return 0;
   1.106 +}
   1.107  
   1.108  long
   1.109  do_hvm_op(unsigned long op, XEN_GUEST_HANDLE(void) arg)
   1.110 @@ -78,6 +164,25 @@ do_hvm_op(unsigned long op, XEN_GUEST_HA
   1.111          break;
   1.112      }
   1.113  
   1.114 +    case HVMOP_setup_gnttab_table:
   1.115 +    case HVMOP_setup_shared_info_page:
   1.116 +    {
   1.117 +        struct xen_hvm_setup a;
   1.118 +
   1.119 +        if (copy_from_guest(&a, arg, 1))
   1.120 +            return -EFAULT;
   1.121 +
   1.122 +        switch (op) {
   1.123 +        case HVMOP_setup_gnttab_table:
   1.124 +            printk("vmx_gnttab_setup_table: frame_pa=%#lx,"
   1.125 +                            "nr_frame=%ld\n", a.arg1, a.arg2);
   1.126 +            return vmx_gnttab_setup_table(a.arg1, a.arg2);
   1.127 +        case HVMOP_setup_shared_info_page:
   1.128 +            printk("vmx_setup_shared_info_page: gpa=0x%lx\n", a.arg1);
   1.129 +            return vmx_setup_shared_info_page(a.arg1);
   1.130 +        }
   1.131 +    }
   1.132 +
   1.133      default:
   1.134          DPRINTK("Bad HVM op %ld.\n", op);
   1.135          rc = -ENOSYS;
     2.1 --- a/xen/include/public/arch-ia64.h	Thu Aug 24 11:54:23 2006 -0600
     2.2 +++ b/xen/include/public/arch-ia64.h	Fri Aug 25 15:06:18 2006 -0600
     2.3 @@ -336,6 +336,17 @@ struct vcpu_guest_context {
     2.4  typedef struct vcpu_guest_context vcpu_guest_context_t;
     2.5  DEFINE_XEN_GUEST_HANDLE(vcpu_guest_context_t);
     2.6  
     2.7 +// hvm_op expansion
     2.8 +#define HVMOP_setup_gnttab_table        2
     2.9 +#define HVMOP_setup_shared_info_page    3
    2.10 +
    2.11 +struct xen_hvm_setup {
    2.12 +    unsigned long arg1;
    2.13 +    unsigned long arg2;
    2.14 +};
    2.15 +typedef struct xen_hvm_setup xen_hvm_setup_t;
    2.16 +DEFINE_XEN_GUEST_HANDLE(xen_hvm_setup_t);
    2.17 +
    2.18  // dom0 vp op
    2.19  #define __HYPERVISOR_ia64_dom0vp_op     __HYPERVISOR_arch_0
    2.20  #define IA64_DOM0VP_ioremap             0       // map io space in machine