61491cf441
This just initializes the basic Xen support in KVM for now. Only permitted on TYPE_PC_MACHINE because that's where the sysbus devices for Xen heap overlay, event channel, grant tables and other stuff will exist. There's no point having the basic hypercall support if nothing else works. Provide sysemu/kvm_xen.h and a kvm_xen_get_caps() which will be used later by support devices. Signed-off-by: David Woodhouse <dwmw@amazon.co.uk> Reviewed-by: Paul Durrant <paul@xen.org>
59 lines
1.6 KiB
C
59 lines
1.6 KiB
C
/*
|
|
* Xen HVM emulation support in KVM
|
|
*
|
|
* Copyright © 2019 Oracle and/or its affiliates. All rights reserved.
|
|
* Copyright © 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
*
|
|
* This work is licensed under the terms of the GNU GPL, version 2 or later.
|
|
* See the COPYING file in the top-level directory.
|
|
*
|
|
*/
|
|
|
|
#include "qemu/osdep.h"
|
|
#include "sysemu/kvm_int.h"
|
|
#include "sysemu/kvm_xen.h"
|
|
#include "kvm/kvm_i386.h"
|
|
#include "xen-emu.h"
|
|
|
|
int kvm_xen_init(KVMState *s)
|
|
{
|
|
const int required_caps = KVM_XEN_HVM_CONFIG_HYPERCALL_MSR |
|
|
KVM_XEN_HVM_CONFIG_INTERCEPT_HCALL | KVM_XEN_HVM_CONFIG_SHARED_INFO;
|
|
struct kvm_xen_hvm_config cfg = {
|
|
.msr = XEN_HYPERCALL_MSR,
|
|
.flags = KVM_XEN_HVM_CONFIG_INTERCEPT_HCALL,
|
|
};
|
|
int xen_caps, ret;
|
|
|
|
xen_caps = kvm_check_extension(s, KVM_CAP_XEN_HVM);
|
|
if (required_caps & ~xen_caps) {
|
|
error_report("kvm: Xen HVM guest support not present or insufficient");
|
|
return -ENOSYS;
|
|
}
|
|
|
|
if (xen_caps & KVM_XEN_HVM_CONFIG_EVTCHN_SEND) {
|
|
struct kvm_xen_hvm_attr ha = {
|
|
.type = KVM_XEN_ATTR_TYPE_XEN_VERSION,
|
|
.u.xen_version = s->xen_version,
|
|
};
|
|
(void)kvm_vm_ioctl(s, KVM_XEN_HVM_SET_ATTR, &ha);
|
|
|
|
cfg.flags |= KVM_XEN_HVM_CONFIG_EVTCHN_SEND;
|
|
}
|
|
|
|
ret = kvm_vm_ioctl(s, KVM_XEN_HVM_CONFIG, &cfg);
|
|
if (ret < 0) {
|
|
error_report("kvm: Failed to enable Xen HVM support: %s",
|
|
strerror(-ret));
|
|
return ret;
|
|
}
|
|
|
|
s->xen_caps = xen_caps;
|
|
return 0;
|
|
}
|
|
|
|
uint32_t kvm_xen_get_caps(void)
|
|
{
|
|
return kvm_state->xen_caps;
|
|
}
|