summaryrefslogtreecommitdiff
path: root/xen/arch/arm/hvm.c
blob: 8951b3408651aabf77168b44d959f99d2222d125 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/*
 * arch/arm/hvm.c
 *
 * Arch-specific hardware virtual machine abstractions.
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms and conditions of the GNU General Public License,
 * version 2, as published by the Free Software Foundation.
 *
 * This program is distributed in the hope it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program; If not, see <http://www.gnu.org/licenses/>.
 */

#include <xen/init.h>
#include <xen/lib.h>
#include <xen/errno.h>
#include <xen/guest_access.h>
#include <xen/sched.h>
#include <xen/monitor.h>

#include <xsm/xsm.h>

#include <public/xen.h>
#include <public/hvm/params.h>
#include <public/hvm/hvm_op.h>

#include <asm/hypercall.h>

static int hvm_allow_set_param(const struct domain *d, unsigned int param)
{
    switch ( param )
    {
        /*
         * The following parameters are intended for toolstack usage only.
         * They may not be set by the domain.
         *
         * The {STORE,CONSOLE}_EVTCHN values will need to become read/write to
         * the guest (not just the toolstack) if a new ABI hasn't appeared by
         * the time migration support is added.
         */
    case HVM_PARAM_CALLBACK_IRQ:
    case HVM_PARAM_STORE_PFN:
    case HVM_PARAM_STORE_EVTCHN:
    case HVM_PARAM_CONSOLE_PFN:
    case HVM_PARAM_CONSOLE_EVTCHN:
    case HVM_PARAM_MONITOR_RING_PFN:
        return d == current->domain ? -EPERM : 0;

        /* Writeable only by Xen, hole, deprecated, or out-of-range. */
    default:
        return -EINVAL;
    }
}

static int hvm_allow_get_param(const struct domain *d, unsigned int param)
{
    switch ( param )
    {
        /* The following parameters can be read by the guest and toolstack. */
    case HVM_PARAM_CALLBACK_IRQ:
    case HVM_PARAM_STORE_PFN:
    case HVM_PARAM_STORE_EVTCHN:
    case HVM_PARAM_CONSOLE_PFN:
    case HVM_PARAM_CONSOLE_EVTCHN:
        return 0;

        /*
         * The following parameters are intended for toolstack usage only.
         * They may not be read by the domain.
         */
    case HVM_PARAM_MONITOR_RING_PFN:
        return d == current->domain ? -EPERM : 0;

        /* Hole, deprecated, or out-of-range. */
    default:
        return -EINVAL;
    }
}

long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg)
{
    long rc = 0;

    switch ( op )
    {
    case HVMOP_set_param:
    case HVMOP_get_param:
    {
        struct xen_hvm_param a;
        struct domain *d;

        if ( copy_from_guest(&a, arg, 1) )
            return -EFAULT;

        d = rcu_lock_domain_by_any_id(a.domid);
        if ( d == NULL )
            return -ESRCH;

        rc = xsm_hvm_param(XSM_TARGET, d, op);
        if ( rc )
            goto param_fail;

        if ( op == HVMOP_set_param )
        {
            rc = hvm_allow_set_param(d, a.index);
            if ( rc )
                goto param_fail;

            d->arch.hvm.params[a.index] = a.value;
        }
        else
        {
            rc = hvm_allow_get_param(d, a.index);
            if ( rc )
                goto param_fail;

            a.value = d->arch.hvm.params[a.index];
            rc = copy_to_guest(arg, &a, 1) ? -EFAULT : 0;
        }

    param_fail:
        rcu_unlock_domain(d);
        break;
    }

    case HVMOP_guest_request_vm_event:
        if ( guest_handle_is_null(arg) )
            monitor_guest_request();
        else
            rc = -EINVAL;
        break;

    default:
    {
        gdprintk(XENLOG_DEBUG, "HVMOP op=%lu: not implemented\n", op);
        rc = -ENOSYS;
        break;
    }
    }

    return rc;
}

/*
 * Local variables:
 * mode: C
 * c-file-style: "BSD"
 * c-basic-offset: 4
 * tab-width: 4
 * indent-tabs-mode: nil
 * End:
 */