i386/xen: Implement HYPERVISOR_grant_table_op and GNTTABOP_[gs]et_verson
Signed-off-by: David Woodhouse <dwmw@amazon.co.uk> Reviewed-by: Paul Durrant <paul@xen.org>
This commit is contained in:
parent
e33cb789af
commit
28b7ae94a2
|
@ -180,3 +180,34 @@ int xen_gnttab_map_page(uint64_t idx, uint64_t gfn)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int xen_gnttab_set_version_op(struct gnttab_set_version *set)
|
||||
{
|
||||
int ret;
|
||||
|
||||
switch (set->version) {
|
||||
case 1:
|
||||
ret = 0;
|
||||
break;
|
||||
|
||||
case 2:
|
||||
/* Behave as before set_version was introduced. */
|
||||
ret = -ENOSYS;
|
||||
break;
|
||||
|
||||
default:
|
||||
ret = -EINVAL;
|
||||
}
|
||||
|
||||
set->version = 1;
|
||||
return ret;
|
||||
}
|
||||
|
||||
int xen_gnttab_get_version_op(struct gnttab_get_version *get)
|
||||
{
|
||||
if (get->dom != DOMID_SELF && get->dom != xen_domid) {
|
||||
return -ESRCH;
|
||||
}
|
||||
|
||||
get->version = 1;
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -15,4 +15,9 @@
|
|||
void xen_gnttab_create(void);
|
||||
int xen_gnttab_map_page(uint64_t idx, uint64_t gfn);
|
||||
|
||||
struct gnttab_set_version;
|
||||
struct gnttab_get_version;
|
||||
int xen_gnttab_set_version_op(struct gnttab_set_version *set);
|
||||
int xen_gnttab_get_version_op(struct gnttab_get_version *get);
|
||||
|
||||
#endif /* QEMU_XEN_GNTTAB_H */
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
#include "hw/xen/interface/hvm/params.h"
|
||||
#include "hw/xen/interface/vcpu.h"
|
||||
#include "hw/xen/interface/event_channel.h"
|
||||
#include "hw/xen/interface/grant_table.h"
|
||||
|
||||
#include "xen-compat.h"
|
||||
|
||||
|
@ -1169,6 +1170,61 @@ static bool kvm_xen_hcall_sched_op(struct kvm_xen_exit *exit, X86CPU *cpu,
|
|||
return true;
|
||||
}
|
||||
|
||||
static bool kvm_xen_hcall_gnttab_op(struct kvm_xen_exit *exit, X86CPU *cpu,
|
||||
int cmd, uint64_t arg, int count)
|
||||
{
|
||||
CPUState *cs = CPU(cpu);
|
||||
int err;
|
||||
|
||||
switch (cmd) {
|
||||
case GNTTABOP_set_version: {
|
||||
struct gnttab_set_version set;
|
||||
|
||||
qemu_build_assert(sizeof(set) == 4);
|
||||
if (kvm_copy_from_gva(cs, arg, &set, sizeof(set))) {
|
||||
err = -EFAULT;
|
||||
break;
|
||||
}
|
||||
|
||||
err = xen_gnttab_set_version_op(&set);
|
||||
if (!err && kvm_copy_to_gva(cs, arg, &set, sizeof(set))) {
|
||||
err = -EFAULT;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case GNTTABOP_get_version: {
|
||||
struct gnttab_get_version get;
|
||||
|
||||
qemu_build_assert(sizeof(get) == 8);
|
||||
if (kvm_copy_from_gva(cs, arg, &get, sizeof(get))) {
|
||||
err = -EFAULT;
|
||||
break;
|
||||
}
|
||||
|
||||
err = xen_gnttab_get_version_op(&get);
|
||||
if (!err && kvm_copy_to_gva(cs, arg, &get, sizeof(get))) {
|
||||
err = -EFAULT;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case GNTTABOP_query_size:
|
||||
case GNTTABOP_setup_table:
|
||||
case GNTTABOP_copy:
|
||||
case GNTTABOP_map_grant_ref:
|
||||
case GNTTABOP_unmap_grant_ref:
|
||||
case GNTTABOP_swap_grant_ref:
|
||||
return false;
|
||||
|
||||
default:
|
||||
/* Xen explicitly returns -ENOSYS to HVM guests for all others */
|
||||
err = -ENOSYS;
|
||||
break;
|
||||
}
|
||||
|
||||
exit->u.hcall.result = err;
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool do_kvm_xen_handle_exit(X86CPU *cpu, struct kvm_xen_exit *exit)
|
||||
{
|
||||
uint16_t code = exit->u.hcall.input;
|
||||
|
@ -1179,6 +1235,10 @@ static bool do_kvm_xen_handle_exit(X86CPU *cpu, struct kvm_xen_exit *exit)
|
|||
}
|
||||
|
||||
switch (code) {
|
||||
case __HYPERVISOR_grant_table_op:
|
||||
return kvm_xen_hcall_gnttab_op(exit, cpu, exit->u.hcall.params[0],
|
||||
exit->u.hcall.params[1],
|
||||
exit->u.hcall.params[2]);
|
||||
case __HYPERVISOR_sched_op:
|
||||
return kvm_xen_hcall_sched_op(exit, cpu, exit->u.hcall.params[0],
|
||||
exit->u.hcall.params[1]);
|
||||
|
|
Loading…
Reference in New Issue