Skip to content

Commit 946de55

Browse files
committed
Merge remote-tracking branch 'remotes/bonzini/tags/for-upstream' into staging
* SEV and SGX cleanups (Philippe, Dov) * bugfixes for "check-block" * bugfix for static build * ObjectOptions cleanups (Thomas) * binutils fix for PVH (Cole) * HVF cleanup (Alex) # gpg: Signature made Wed 13 Oct 2021 01:47:56 AM PDT # gpg: using RSA key F13338574B662389866C7682BFFBD25F78C7AE83 # gpg: issuer "[email protected]" # gpg: Good signature from "Paolo Bonzini <[email protected]>" [full] # gpg: aka "Paolo Bonzini <[email protected]>" [full] * remotes/bonzini/tags/for-upstream: (40 commits) ebpf: really include it only in system emulators target/i386/sev: Use local variable for kvm_sev_launch_measure target/i386/sev: Use local variable for kvm_sev_launch_start monitor: Tidy up find_device_state() Revert "hw/misc: applesmc: use host osk as default on macs" hw/i386/sgx: Move qmp_query_sgx() and hmp_info_sgx() to hw/i386/sgx.c hw/i386/sgx: Move qmp_query_sgx_capabilities() to hw/i386/sgx.c hw/i386/sgx: Have sgx_epc_get_section() return a boolean MAINTAINERS: Cover SGX documentation file with X86/KVM section hvf: Determine slot count from struct layout tests: tcg: Fix PVH test with binutils 2.36+ qapi: Make some ObjectTypes depend on the build settings MAINTAINERS: Cover SEV-related files with X86/KVM section monitor: Reduce hmp_info_sev() declaration target/i386/sev: Move qmp_query_sev() & hmp_info_sev() to sev.c target/i386/sev: Move qmp_query_sev_launch_measure() to sev.c target/i386/sev: Move qmp_query_sev_capabilities() to sev.c target/i386/sev: Move qmp_sev_inject_launch_secret() to sev.c target/i386/sev: Move qmp_query_sev_attestation_report() to sev.c target/i386/sev: Remove stubs by using code elision ... Signed-off-by: Richard Henderson <[email protected]>
2 parents ee26ce6 + eeecc2e commit 946de55

File tree

31 files changed

+392
-619
lines changed

31 files changed

+392
-619
lines changed

MAINTAINERS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,10 @@ M: Paolo Bonzini <[email protected]>
417417
M: Marcelo Tosatti <[email protected]>
418418
419419
S: Supported
420+
F: docs/amd-memory-encryption.txt
421+
F: docs/system/i386/sgx.rst
420422
F: target/i386/kvm/
423+
F: target/i386/sev*
421424
F: scripts/kvm/vmxcap
422425

423426
Guest CPU Cores (other accelerators)
@@ -2502,6 +2505,7 @@ Memory API
25022505
M: Paolo Bonzini <[email protected]>
25032506
M: Peter Xu <[email protected]>
25042507
M: David Hildenbrand <[email protected]>
2508+
R: Philippe Mathieu-Daudé <[email protected]>
25052509
S: Supported
25062510
F: include/exec/ioport.h
25072511
F: include/exec/memop.h

accel/hvf/hvf-accel-ops.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ static int hvf_accel_init(MachineState *ms)
321321

322322
s = g_new0(HVFState, 1);
323323

324-
s->num_slots = 32;
324+
s->num_slots = ARRAY_SIZE(s->slots);
325325
for (x = 0; x < s->num_slots; ++x) {
326326
s->slots[x].size = 0;
327327
s->slots[x].slot_id = x;

accel/kvm/meson.build

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,5 @@ kvm_ss.add(files(
33
'kvm-all.c',
44
'kvm-accel-ops.c',
55
))
6-
kvm_ss.add(when: 'CONFIG_SEV', if_false: files('sev-stub.c'))
76

87
specific_ss.add_all(when: 'CONFIG_KVM', if_true: kvm_ss)

hw/i386/pc_sysfw.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
#include "hw/qdev-properties.h"
3838
#include "hw/block/flash.h"
3939
#include "sysemu/kvm.h"
40-
#include "sysemu/sev.h"
40+
#include "sev.h"
4141

4242
#define FLASH_SECTOR_SIZE 4096
4343

hw/i386/sgx-stub.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,34 @@
11
#include "qemu/osdep.h"
2+
#include "monitor/monitor.h"
3+
#include "monitor/hmp-target.h"
24
#include "hw/i386/pc.h"
35
#include "hw/i386/sgx-epc.h"
4-
#include "hw/i386/sgx.h"
6+
#include "qapi/error.h"
7+
#include "qapi/qapi-commands-misc-target.h"
58

6-
SGXInfo *sgx_get_info(Error **errp)
9+
SGXInfo *qmp_query_sgx(Error **errp)
710
{
811
error_setg(errp, "SGX support is not compiled in");
912
return NULL;
1013
}
1114

12-
SGXInfo *sgx_get_capabilities(Error **errp)
15+
SGXInfo *qmp_query_sgx_capabilities(Error **errp)
1316
{
1417
error_setg(errp, "SGX support is not compiled in");
1518
return NULL;
1619
}
1720

21+
void hmp_info_sgx(Monitor *mon, const QDict *qdict)
22+
{
23+
monitor_printf(mon, "SGX is not available in this QEMU\n");
24+
}
25+
1826
void pc_machine_init_sgx_epc(PCMachineState *pcms)
1927
{
2028
memset(&pcms->sgx_epc, 0, sizeof(SGXEPCState));
2129
}
2230

23-
int sgx_epc_get_section(int section_nr, uint64_t *addr, uint64_t *size)
31+
bool sgx_epc_get_section(int section_nr, uint64_t *addr, uint64_t *size)
2432
{
2533
g_assert_not_reached();
2634
}

hw/i386/sgx.c

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@
1515
#include "hw/i386/sgx-epc.h"
1616
#include "hw/mem/memory-device.h"
1717
#include "monitor/qdev.h"
18+
#include "monitor/monitor.h"
19+
#include "monitor/hmp-target.h"
1820
#include "qapi/error.h"
21+
#include "qapi/qapi-commands-misc-target.h"
1922
#include "exec/address-spaces.h"
20-
#include "hw/i386/sgx.h"
2123
#include "sysemu/hw_accel.h"
2224

2325
#define SGX_MAX_EPC_SECTIONS 8
@@ -57,7 +59,7 @@ static uint64_t sgx_calc_host_epc_section_size(void)
5759
return size;
5860
}
5961

60-
SGXInfo *sgx_get_capabilities(Error **errp)
62+
SGXInfo *qmp_query_sgx_capabilities(Error **errp)
6163
{
6264
SGXInfo *info = NULL;
6365
uint32_t eax, ebx, ecx, edx;
@@ -85,7 +87,7 @@ SGXInfo *sgx_get_capabilities(Error **errp)
8587
return info;
8688
}
8789

88-
SGXInfo *sgx_get_info(Error **errp)
90+
SGXInfo *qmp_query_sgx(Error **errp)
8991
{
9092
SGXInfo *info = NULL;
9193
X86MachineState *x86ms;
@@ -115,21 +117,42 @@ SGXInfo *sgx_get_info(Error **errp)
115117
return info;
116118
}
117119

118-
int sgx_epc_get_section(int section_nr, uint64_t *addr, uint64_t *size)
120+
void hmp_info_sgx(Monitor *mon, const QDict *qdict)
121+
{
122+
Error *err = NULL;
123+
g_autoptr(SGXInfo) info = qmp_query_sgx(&err);
124+
125+
if (err) {
126+
error_report_err(err);
127+
return;
128+
}
129+
monitor_printf(mon, "SGX support: %s\n",
130+
info->sgx ? "enabled" : "disabled");
131+
monitor_printf(mon, "SGX1 support: %s\n",
132+
info->sgx1 ? "enabled" : "disabled");
133+
monitor_printf(mon, "SGX2 support: %s\n",
134+
info->sgx2 ? "enabled" : "disabled");
135+
monitor_printf(mon, "FLC support: %s\n",
136+
info->flc ? "enabled" : "disabled");
137+
monitor_printf(mon, "size: %" PRIu64 "\n",
138+
info->section_size);
139+
}
140+
141+
bool sgx_epc_get_section(int section_nr, uint64_t *addr, uint64_t *size)
119142
{
120143
PCMachineState *pcms = PC_MACHINE(qdev_get_machine());
121144
SGXEPCDevice *epc;
122145

123146
if (pcms->sgx_epc.size == 0 || pcms->sgx_epc.nr_sections <= section_nr) {
124-
return 1;
147+
return true;
125148
}
126149

127150
epc = pcms->sgx_epc.sections[section_nr];
128151

129152
*addr = epc->addr;
130153
*size = memory_device_get_region_size(MEMORY_DEVICE(epc), &error_fatal);
131154

132-
return 0;
155+
return false;
133156
}
134157

135158
void pc_machine_init_sgx_epc(PCMachineState *pcms)

hw/i386/x86.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
#include "hw/i386/fw_cfg.h"
4848
#include "hw/intc/i8259.h"
4949
#include "hw/rtc/mc146818rtc.h"
50-
#include "target/i386/sev_i386.h"
50+
#include "target/i386/sev.h"
5151

5252
#include "hw/acpi/cpu_hotplug.h"
5353
#include "hw/irq.h"

hw/misc/applesmc.c

Lines changed: 1 addition & 191 deletions
Original file line numberDiff line numberDiff line change
@@ -38,171 +38,6 @@
3838
#include "qemu/timer.h"
3939
#include "qom/object.h"
4040

41-
#if defined(__APPLE__) && defined(__MACH__)
42-
#include <IOKit/IOKitLib.h>
43-
44-
enum {
45-
kSMCSuccess = 0x00,
46-
kSMCKeyNotFound = 0x84
47-
};
48-
49-
enum {
50-
kSMCUserClientOpen = 0x00,
51-
kSMCUserClientClose = 0x01,
52-
kSMCHandleYPCEvent = 0x02,
53-
kSMCReadKey = 0x05,
54-
kSMCGetKeyInfo = 0x09
55-
};
56-
57-
typedef struct SMCVersion {
58-
uint8_t major;
59-
uint8_t minor;
60-
uint8_t build;
61-
uint8_t reserved;
62-
uint16_t release;
63-
} SMCVersion;
64-
65-
typedef struct SMCPLimitData {
66-
uint16_t version;
67-
uint16_t length;
68-
uint32_t cpuPLimit;
69-
uint32_t gpuPLimit;
70-
uint32_t memPLimit;
71-
} SMCPLimitData;
72-
73-
typedef struct SMCKeyInfoData {
74-
IOByteCount dataSize;
75-
uint32_t dataType;
76-
uint8_t dataAttributes;
77-
} SMCKeyInfoData;
78-
79-
typedef struct {
80-
uint32_t key;
81-
SMCVersion vers;
82-
SMCPLimitData pLimitData;
83-
SMCKeyInfoData keyInfo;
84-
uint8_t result;
85-
uint8_t status;
86-
uint8_t data8;
87-
uint32_t data32;
88-
uint8_t bytes[32];
89-
} SMCParamStruct;
90-
91-
static IOReturn smc_call_struct_method(uint32_t selector,
92-
SMCParamStruct *inputStruct,
93-
SMCParamStruct *outputStruct)
94-
{
95-
IOReturn ret;
96-
97-
size_t inputStructCnt = sizeof(SMCParamStruct);
98-
size_t outputStructCnt = sizeof(SMCParamStruct);
99-
100-
io_service_t smcService = IO_OBJECT_NULL;
101-
io_connect_t smcConnect = IO_OBJECT_NULL;
102-
103-
smcService = IOServiceGetMatchingService(kIOMasterPortDefault,
104-
IOServiceMatching("AppleSMC"));
105-
if (smcService == IO_OBJECT_NULL) {
106-
ret = kIOReturnNotFound;
107-
goto exit;
108-
}
109-
110-
ret = IOServiceOpen(smcService, mach_task_self(), 1, &smcConnect);
111-
if (ret != kIOReturnSuccess) {
112-
smcConnect = IO_OBJECT_NULL;
113-
goto exit;
114-
}
115-
if (smcConnect == IO_OBJECT_NULL) {
116-
ret = kIOReturnError;
117-
goto exit;
118-
}
119-
120-
ret = IOConnectCallMethod(smcConnect, kSMCUserClientOpen,
121-
NULL, 0, NULL, 0,
122-
NULL, NULL, NULL, NULL);
123-
if (ret != kIOReturnSuccess) {
124-
goto exit;
125-
}
126-
127-
ret = IOConnectCallStructMethod(smcConnect, selector,
128-
inputStruct, inputStructCnt,
129-
outputStruct, &outputStructCnt);
130-
131-
exit:
132-
if (smcConnect != IO_OBJECT_NULL) {
133-
IOConnectCallMethod(smcConnect, kSMCUserClientClose,
134-
NULL, 0, NULL, 0, NULL,
135-
NULL, NULL, NULL);
136-
IOServiceClose(smcConnect);
137-
}
138-
139-
return ret;
140-
}
141-
142-
static IOReturn smc_read_key(uint32_t key,
143-
uint8_t *bytes,
144-
IOByteCount *dataSize)
145-
{
146-
IOReturn ret;
147-
148-
SMCParamStruct inputStruct;
149-
SMCParamStruct outputStruct;
150-
151-
if (key == 0 || bytes == NULL) {
152-
ret = kIOReturnCannotWire;
153-
goto exit;
154-
}
155-
156-
/* determine key's data size */
157-
memset(&inputStruct, 0, sizeof(SMCParamStruct));
158-
inputStruct.data8 = kSMCGetKeyInfo;
159-
inputStruct.key = key;
160-
161-
memset(&outputStruct, 0, sizeof(SMCParamStruct));
162-
ret = smc_call_struct_method(kSMCHandleYPCEvent, &inputStruct, &outputStruct);
163-
if (ret != kIOReturnSuccess) {
164-
goto exit;
165-
}
166-
if (outputStruct.result == kSMCKeyNotFound) {
167-
ret = kIOReturnNotFound;
168-
goto exit;
169-
}
170-
if (outputStruct.result != kSMCSuccess) {
171-
ret = kIOReturnInternalError;
172-
goto exit;
173-
}
174-
175-
/* get key value */
176-
memset(&inputStruct, 0, sizeof(SMCParamStruct));
177-
inputStruct.data8 = kSMCReadKey;
178-
inputStruct.key = key;
179-
inputStruct.keyInfo.dataSize = outputStruct.keyInfo.dataSize;
180-
181-
memset(&outputStruct, 0, sizeof(SMCParamStruct));
182-
ret = smc_call_struct_method(kSMCHandleYPCEvent, &inputStruct, &outputStruct);
183-
if (ret != kIOReturnSuccess) {
184-
goto exit;
185-
}
186-
if (outputStruct.result == kSMCKeyNotFound) {
187-
ret = kIOReturnNotFound;
188-
goto exit;
189-
}
190-
if (outputStruct.result != kSMCSuccess) {
191-
ret = kIOReturnInternalError;
192-
goto exit;
193-
}
194-
195-
memset(bytes, 0, *dataSize);
196-
if (*dataSize > inputStruct.keyInfo.dataSize) {
197-
*dataSize = inputStruct.keyInfo.dataSize;
198-
}
199-
memcpy(bytes, outputStruct.bytes, *dataSize);
200-
201-
exit:
202-
return ret;
203-
}
204-
#endif
205-
20641
/* #define DEBUG_SMC */
20742

20843
#define APPLESMC_DEFAULT_IOBASE 0x300
@@ -480,7 +315,6 @@ static const MemoryRegionOps applesmc_err_io_ops = {
480315
static void applesmc_isa_realize(DeviceState *dev, Error **errp)
481316
{
482317
AppleSMCState *s = APPLE_SMC(dev);
483-
bool valid_key = false;
484318

485319
memory_region_init_io(&s->io_data, OBJECT(s), &applesmc_data_io_ops, s,
486320
"applesmc-data", 1);
@@ -497,31 +331,7 @@ static void applesmc_isa_realize(DeviceState *dev, Error **errp)
497331
isa_register_ioport(&s->parent_obj, &s->io_err,
498332
s->iobase + APPLESMC_ERR_PORT);
499333

500-
if (s->osk) {
501-
valid_key = strlen(s->osk) == 64;
502-
} else {
503-
#if defined(__APPLE__) && defined(__MACH__)
504-
IOReturn ret;
505-
IOByteCount size = 32;
506-
507-
ret = smc_read_key('OSK0', (uint8_t *) default_osk, &size);
508-
if (ret != kIOReturnSuccess) {
509-
goto failure;
510-
}
511-
512-
ret = smc_read_key('OSK1', (uint8_t *) default_osk + size, &size);
513-
if (ret != kIOReturnSuccess) {
514-
goto failure;
515-
}
516-
517-
warn_report("Using AppleSMC with host key");
518-
valid_key = true;
519-
s->osk = default_osk;
520-
failure:;
521-
#endif
522-
}
523-
524-
if (!valid_key) {
334+
if (!s->osk || (strlen(s->osk) != 64)) {
525335
warn_report("Using AppleSMC with invalid key");
526336
s->osk = default_osk;
527337
}

include/hw/i386/sgx-epc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ typedef struct SGXEPCState {
5555
int nr_sections;
5656
} SGXEPCState;
5757

58-
int sgx_epc_get_section(int section_nr, uint64_t *addr, uint64_t *size);
58+
bool sgx_epc_get_section(int section_nr, uint64_t *addr, uint64_t *size);
5959

6060
static inline uint64_t sgx_epc_above_4g_end(SGXEPCState *sgx_epc)
6161
{

0 commit comments

Comments
 (0)