2 * PEF (Protected Execution Facility) for POWER support
6 * This work is licensed under the terms of the GNU GPL, version 2 or later.
7 * See the COPYING file in the top-level directory.
11 #include "qemu/osdep.h"
13 #include "qapi/error.h"
14 #include "qom/object_interfaces.h"
15 #include "sysemu/kvm.h"
16 #include "migration/blocker.h"
17 #include "exec/confidential-guest-support.h"
18 #include "hw/ppc/pef.h"
20 #define TYPE_PEF_GUEST "pef-guest"
21 OBJECT_DECLARE_SIMPLE_TYPE(PefGuest, PEF_GUEST)
23 typedef struct PefGuest PefGuest;
24 typedef struct PefGuestClass PefGuestClass;
26 struct PefGuestClass {
27 ConfidentialGuestSupportClass parent_class;
33 * The PefGuest object is used for creating and managing a PEF
37 * -object pef-guest,id=pef0 \
38 * -machine ...,confidential-guest-support=pef0
41 ConfidentialGuestSupport parent_obj;
44 static int kvmppc_svm_init(ConfidentialGuestSupport *cgs, Error **errp)
47 static Error *pef_mig_blocker;
49 if (!kvm_check_extension(kvm_state, KVM_CAP_PPC_SECURE_GUEST)) {
51 "KVM implementation does not support Secure VMs (is an ultravisor running?)");
54 int ret = kvm_vm_enable_cap(kvm_state, KVM_CAP_PPC_SECURE_GUEST, 0, 1);
58 "Error enabling PEF with KVM");
63 /* add migration blocker */
64 error_setg(&pef_mig_blocker, "PEF: Migration is not implemented");
65 /* NB: This can fail if --only-migratable is used */
66 migrate_add_blocker(pef_mig_blocker, &error_fatal);
72 g_assert_not_reached();
77 * Don't set error if KVM_PPC_SVM_OFF ioctl is invoked on kernels
78 * that don't support this ioctl.
80 static int kvmppc_svm_off(Error **errp)
85 rc = kvm_vm_ioctl(KVM_STATE(current_accel()), KVM_PPC_SVM_OFF);
86 if (rc && rc != -ENOTTY) {
87 error_setg_errno(errp, -rc, "KVM_PPC_SVM_OFF ioctl failed");
92 g_assert_not_reached();
96 int pef_kvm_init(ConfidentialGuestSupport *cgs, Error **errp)
98 if (!object_dynamic_cast(OBJECT(cgs), TYPE_PEF_GUEST)) {
102 if (!kvm_enabled()) {
103 error_setg(errp, "PEF requires KVM");
107 return kvmppc_svm_init(cgs, errp);
110 int pef_kvm_reset(ConfidentialGuestSupport *cgs, Error **errp)
112 if (!object_dynamic_cast(OBJECT(cgs), TYPE_PEF_GUEST)) {
117 * If we don't have KVM we should never have been able to
118 * initialize PEF, so we should never get this far
120 assert(kvm_enabled());
122 return kvmppc_svm_off(errp);
125 OBJECT_DEFINE_TYPE_WITH_INTERFACES(PefGuest,
128 CONFIDENTIAL_GUEST_SUPPORT,
129 { TYPE_USER_CREATABLE },
132 static void pef_guest_class_init(ObjectClass *oc, void *data)
136 static void pef_guest_init(Object *obj)
140 static void pef_guest_finalize(Object *obj)