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
|
/*
* x86-specific confidential guest methods.
*
* Copyright (c) 2024 Red Hat Inc.
*
* Authors:
* Paolo Bonzini <pbonzini@redhat.com>
*
* This work is licensed under the terms of the GNU GPL, version 2 or later.
* See the COPYING file in the top-level directory.
*/
#ifndef TARGET_I386_CG_H
#define TARGET_I386_CG_H
#include "qom/object.h"
#include "system/confidential-guest-support.h"
#define TYPE_X86_CONFIDENTIAL_GUEST "x86-confidential-guest"
OBJECT_DECLARE_TYPE(X86ConfidentialGuest,
X86ConfidentialGuestClass,
X86_CONFIDENTIAL_GUEST)
struct X86ConfidentialGuest {
/* <private> */
ConfidentialGuestSupport parent_obj;
};
/**
* X86ConfidentialGuestClass:
*
* Class to be implemented by confidential-guest-support concrete objects
* for the x86 target.
*/
struct X86ConfidentialGuestClass {
/* <private> */
ConfidentialGuestSupportClass parent;
/* <public> */
int (*kvm_type)(X86ConfidentialGuest *cg);
void (*cpu_instance_init)(X86ConfidentialGuest *cg, CPUState *cpu);
uint32_t (*adjust_cpuid_features)(X86ConfidentialGuest *cg, uint32_t feature,
uint32_t index, int reg, uint32_t value);
int (*check_features)(X86ConfidentialGuest *cg, CPUState *cs);
};
/**
* x86_confidential_guest_kvm_type:
*
* Calls #X86ConfidentialGuestClass.kvm_type() callback.
*/
static inline int x86_confidential_guest_kvm_type(X86ConfidentialGuest *cg)
{
X86ConfidentialGuestClass *klass = X86_CONFIDENTIAL_GUEST_GET_CLASS(cg);
if (klass->kvm_type) {
return klass->kvm_type(cg);
} else {
return 0;
}
}
static inline void x86_confidential_guest_cpu_instance_init(X86ConfidentialGuest *cg,
CPUState *cpu)
{
X86ConfidentialGuestClass *klass = X86_CONFIDENTIAL_GUEST_GET_CLASS(cg);
if (klass->cpu_instance_init) {
klass->cpu_instance_init(cg, cpu);
}
}
/**
* x86_confidential_guest_adjust_cpuid_features:
*
* Adjust the supported features from a confidential guest's CPUID values,
* returns the adjusted value. There are bits being removed that are not
* supported by the confidential computing firmware or bits being added that
* are forcibly exposed to guest by the confidential computing firmware.
*/
static inline int x86_confidential_guest_adjust_cpuid_features(X86ConfidentialGuest *cg,
uint32_t feature, uint32_t index,
int reg, uint32_t value)
{
X86ConfidentialGuestClass *klass = X86_CONFIDENTIAL_GUEST_GET_CLASS(cg);
if (klass->adjust_cpuid_features) {
return klass->adjust_cpuid_features(cg, feature, index, reg, value);
} else {
return value;
}
}
static inline int x86_confidential_guest_check_features(X86ConfidentialGuest *cg,
CPUState *cs)
{
X86ConfidentialGuestClass *klass = X86_CONFIDENTIAL_GUEST_GET_CLASS(cg);
if (klass->check_features) {
return klass->check_features(cg, cs);
}
return 0;
}
#endif
|