hw/i386/sgx: Housekeeping around SGX
PATCH 2/4 hw/i386/sgx: Have sgx_epc_get_section() return a boolean
In reply to Philippe Mathieu-Daudé--- include/hw/i386/sgx-epc.h | 2 +- hw/i386/sgx-stub.c | 2 +- hw/i386/sgx.c | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-)
include/hw/i386/sgx-epc.h +1 -1
@@ -55,7 +55,7 @@ typedef struct SGXEPCState {int nr_sections; } SGXEPCState; -int sgx_epc_get_section (int section_nr,uint64_t *addr,uint64_t *size); +bool sgx_epc_get_section (int section_nr,uint64_t *addr,uint64_t *size);static inline uint64_t sgx_epc_above_4g_end (SGXEPCState *sgx_epc) {
hw/i386/sgx-stub.c +1 -1
@@ -20,7 +20,7 @@ void pc_machine_init_sgx_epc(PCMachineState *pcms)memset (&pcms->sgx_epc,0 ,sizeof (SGXEPCState)); } -int sgx_epc_get_section (int section_nr,uint64_t *addr,uint64_t *size) +bool sgx_epc_get_section (int section_nr,uint64_t *addr,uint64_t *size) {g_assert_not_reached (); }
hw/i386/sgx.c +3 -3
@@ -115,13 +115,13 @@ SGXInfo *sgx_get_info(Error **errp)return info; } -int sgx_epc_get_section (int section_nr,uint64_t *addr,uint64_t *size) +bool sgx_epc_get_section (int section_nr,uint64_t *addr,uint64_t *size) {PCMachineState *pcms =PC_MACHINE (qdev_get_machine ());SGXEPCDevice *epc;if (pcms->sgx_epc.size ==0 || pcms->sgx_epc.nr_sections <= section_nr) { -return 1 ; +return true; } epc = pcms->sgx_epc.sections[section_nr];
@@ -129,7 +129,7 @@ int sgx_epc_get_section(int section_nr, uint64_t *addr, uint64_t *size) *addr = epc->addr; *size =memory_device_get_region_size (MEMORY_DEVICE (epc), &error_fatal); -return 0 ; +return false; }void pc_machine_init_sgx_epc (PCMachineState *pcms)
Signature · 1 line
2.31.1
cover hw/i386/sgx: Housekeeping around SGX
- Update MAINTAINERS
- Have sgx_epc_get_section() return a boolean
- Move QMP commands from target/i386 to hw/i386 (suggested by Paolo)
Based-on: <[email protected]>
Philippe Mathieu-Daudé (4):
MAINTAINERS: Cover SGX documentation file with X86/KVM section hw/i386/sgx: Have sgx_epc_get_section() return a boolean hw/i386/sgx: Move qmp_query_sgx_capabilities() to hw/i386/sgx.c hw/i386/sgx: Move qmp_query_sgx() and hmp_info_sgx() to hw/i386/sgx.c
include/hw/i386/sgx-epc.h | 2 +- include/hw/i386/sgx.h | 12 ------------ hw/i386/sgx-stub.c | 16 ++++++++++++---- hw/i386/sgx.c | 35 +++++++++++++++++++++++++++++------ target/i386/monitor.c | 32 -------------------------------- MAINTAINERS | 1 + 6 files changed, 43 insertions(+), 55 deletions(-) delete mode 100644 include/hw/i386/sgx.h
Signature · 1 line
2.31.1
PATCH 3/4 hw/i386/sgx: Move qmp_query_sgx_capabilities() to hw/i386/sgx.c
Move qmp_query_sgx_capabilities() from target/i386/monitor.c to hw/i386/sgx.c, removing the sgx_get_capabilities() indirection.
--- include/hw/i386/sgx.h | 1 - hw/i386/sgx-stub.c | 4 +++- hw/i386/sgx.c | 3 ++- target/i386/monitor.c | 5 ----- 4 files changed, 5 insertions(+), 8 deletions(-)
include/hw/i386/sgx.h +0 -1
@@ -7,6 +7,5 @@#include "qapi/qapi-types-misc-target.h" SGXInfo *sgx_get_info (Error **errp); -SGXInfo *sgx_get_capabilities (Error **errp);#endif
hw/i386/sgx-stub.c +3 -1
@@ -2,6 +2,8 @@#include "hw/i386/pc.h" #include "hw/i386/sgx-epc.h" #include "hw/i386/sgx.h" +#include "qapi/error.h" +#include "qapi/qapi-commands-misc-target.h" SGXInfo *sgx_get_info (Error **errp) {
@@ -9,7 +11,7 @@ SGXInfo *sgx_get_info(Error **errp)return NULL ; } -SGXInfo *sgx_get_capabilities (Error **errp) +SGXInfo *qmp_query_sgx_capabilities (Error **errp) {error_setg (errp,"SGX support is not compiled in" );return NULL ;
hw/i386/sgx.c +2 -1
@@ -16,6 +16,7 @@#include "hw/mem/memory-device.h" #include "monitor/qdev.h" #include "qapi/error.h" +#include "qapi/qapi-commands-misc-target.h" #include "exec/address-spaces.h" #include "hw/i386/sgx.h" #include "sysemu/hw_accel.h"
@@ -57,7 +58,7 @@ static uint64_t sgx_calc_host_epc_section_size(void)return size; } -SGXInfo *sgx_get_capabilities (Error **errp) +SGXInfo *qmp_query_sgx_capabilities (Error **errp) {SGXInfo *info =NULL ;uint32_t eax, ebx, ecx, edx;
target/i386/monitor.c +0 -5
@@ -700,8 +700,3 @@ void hmp_info_sgx(Monitor *mon, const QDict *qdict)monitor_printf (mon,"size: %" PRIu64"\n" , info->section_size); } - -SGXInfo *qmp_query_sgx_capabilities (Error **errp) -{ -return sgx_get_capabilities (errp); -}
Signature · 1 line
2.31.1
PATCH 4/4 hw/i386/sgx: Move qmp_query_sgx() and hmp_info_sgx() to hw/i386/sgx.c
In reply to Philippe Mathieu-DaudéMove qmp_query_sgx() and hmp_info_sgx() from target/i386/monitor.c to hw/i386/sgx.c, removing the sgx_get_info() indirection and the "hw/i386/sgx.h" header.
--- include/hw/i386/sgx.h | 11 ----------- hw/i386/sgx-stub.c | 10 ++++++++-- hw/i386/sgx.c | 26 ++++++++++++++++++++++++-- target/i386/monitor.c | 27 --------------------------- 4 files changed, 32 insertions(+), 42 deletions(-) delete mode 100644 include/hw/i386/sgx.h
include/hw/i386/sgx.h deleted +0 -11
@@ -1,11 +0,0 @@ -#ifndef QEMU_SGX_H -#define QEMU_SGX_H - -#include "qom/object.h" -#include "qapi/error.h" -#include "qemu/error-report.h" -#include "qapi/qapi-types-misc-target.h" - -SGXInfo *sgx_get_info (Error **errp); - -#endif
hw/i386/sgx-stub.c +8 -2
@@ -1,11 +1,12 @@#include "qemu/osdep.h" +#include "monitor/monitor.h" +#include "monitor/hmp-target.h" #include "hw/i386/pc.h" #include "hw/i386/sgx-epc.h" -#include "hw/i386/sgx.h" #include "qapi/error.h" #include "qapi/qapi-commands-misc-target.h" -SGXInfo *sgx_get_info (Error **errp) +SGXInfo *qmp_query_sgx (Error **errp) {error_setg (errp,"SGX support is not compiled in" );return NULL ;
@@ -17,6 +18,11 @@ SGXInfo *qmp_query_sgx_capabilities(Error **errp)return NULL ; } +void hmp_info_sgx (Monitor *mon,const QDict *qdict) +{ +monitor_printf (mon,"SGX is not available in this QEMU\n" ); +} +void pc_machine_init_sgx_epc (PCMachineState *pcms) {memset (&pcms->sgx_epc,0 ,sizeof (SGXEPCState));
hw/i386/sgx.c +24 -2
@@ -15,10 +15,11 @@#include "hw/i386/sgx-epc.h" #include "hw/mem/memory-device.h" #include "monitor/qdev.h" +#include "monitor/monitor.h" +#include "monitor/hmp-target.h" #include "qapi/error.h" #include "qapi/qapi-commands-misc-target.h" #include "exec/address-spaces.h" -#include "hw/i386/sgx.h" #include "sysemu/hw_accel.h" #define SGX_MAX_EPC_SECTIONS 8
@@ -86,7 +87,7 @@ SGXInfo *qmp_query_sgx_capabilities(Error **errp)return info; } -SGXInfo *sgx_get_info (Error **errp) +SGXInfo *qmp_query_sgx (Error **errp) {SGXInfo *info =NULL ;X86MachineState *x86ms;
@@ -116,6 +117,27 @@ SGXInfo *sgx_get_info(Error **errp)return info; } +void hmp_info_sgx (Monitor *mon,const QDict *qdict) +{ +Error *err =NULL ; +g_autoptr (SGXInfo) info =qmp_query_sgx (&err); + +if (err) { +error_report_err (err); +return ; + } +monitor_printf (mon,"SGX support: %s\n" , + info->sgx ?"enabled" :"disabled" ); +monitor_printf (mon,"SGX1 support: %s\n" , + info->sgx1 ?"enabled" :"disabled" ); +monitor_printf (mon,"SGX2 support: %s\n" , + info->sgx2 ?"enabled" :"disabled" ); +monitor_printf (mon,"FLC support: %s\n" , + info->flc ?"enabled" :"disabled" ); +monitor_printf (mon,"size: %" PRIu64"\n" , + info->section_size); +} +bool sgx_epc_get_section (int section_nr,uint64_t *addr,uint64_t *size) {PCMachineState *pcms =PC_MACHINE (qdev_get_machine ());
target/i386/monitor.c +0 -27
@@ -34,7 +34,6 @@#include "qapi/qapi-commands-misc-target.h" #include "qapi/qapi-commands-misc.h" #include "hw/i386/pc.h" -#include "hw/i386/sgx.h" /* Perform linear address sign extension */ static hwaddr addr_canonical (CPUArchState *env,hwaddr addr)
@@ -674,29 +673,3 @@ void hmp_info_io_apic(Monitor *mon, const QDict *qdict)monitor_printf (mon,"This command is obsolete and will be " "removed soon. Please use 'info pic' instead.\n" ); } - -SGXInfo *qmp_query_sgx (Error **errp) -{ -return sgx_get_info (errp); -} - -void hmp_info_sgx (Monitor *mon,const QDict *qdict) -{ -Error *err =NULL ; -g_autoptr (SGXInfo) info =qmp_query_sgx (&err); - -if (err) { -error_report_err (err); -return ; - } -monitor_printf (mon,"SGX support: %s\n" , - info->sgx ?"enabled" :"disabled" ); -monitor_printf (mon,"SGX1 support: %s\n" , - info->sgx1 ?"enabled" :"disabled" ); -monitor_printf (mon,"SGX2 support: %s\n" , - info->sgx2 ?"enabled" :"disabled" ); -monitor_printf (mon,"FLC support: %s\n" , - info->flc ?"enabled" :"disabled" ); -monitor_printf (mon,"size: %" PRIu64"\n" , - info->section_size); -}
Signature · 1 line
2.31.1
PATCH 1/4 MAINTAINERS: Cover SGX documentation file with X86/KVM section
In reply to Philippe Mathieu-Daudé--- MAINTAINERS | 1 + 1 file changed, 1 insertion(+)
MAINTAINERS +1 -0
@@ -418,6 +418,7 @@ M: Marcelo Tosatti <[email protected]> L: [email protected] S: Supported F: docs/amd-memory-encryption.txt +F: docs/system/i386/sgx.rst F: target/i386/kvm/ F: target/i386/sev* F: scripts/kvm/vmxcap
Signature · 1 line
2.31.1
Re: [PATCH 2/4] hw/i386/sgx: Have sgx_epc_get_section() return a boolean
In reply to Philippe Mathieu-DaudéQuoted 40 lines · Philippe Mathieu-Daudé
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- include/hw/i386/sgx-epc.h | 2 +- hw/i386/sgx-stub.c | 2 +- hw/i386/sgx.c | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-)include/hw/i386/sgx-epc.h +1
-1@@ -55,7 +55,7 @@ typedef struct SGXEPCState {int nr_sections; } SGXEPCState; -int sgx_epc_get_section (int section_nr,uint64_t *addr,uint64_t *size); +bool sgx_epc_get_section (int section_nr,uint64_t *addr,uint64_t *size);static inline uint64_t sgx_epc_above_4g_end (SGXEPCState *sgx_epc) {hw/i386/sgx-stub.c +1
-1@@ -20,7 +20,7 @@ void pc_machine_init_sgx_epc(PCMachineState *pcms)memset (&pcms->sgx_epc,0 ,sizeof (SGXEPCState)); } -int sgx_epc_get_section (int section_nr,uint64_t *addr,uint64_t *size) +bool sgx_epc_get_section (int section_nr,uint64_t *addr,uint64_t *size) {g_assert_not_reached (); }hw/i386/sgx.c +0
-0@@ -115,13 +115,13 @@ SGXInfo *sgx_get_info(Error **errp)return info; }
hw/i386/sgx.c SGXInfo *sgx_get_info(Error **errp) · line 124
Quoted 10 lines
hw/i386/sgx.c +2
-2-int sgx_epc_get_section (int section_nr,uint64_t *addr,uint64_t *size) +bool sgx_epc_get_section (int section_nr,uint64_t *addr,uint64_t *size) {PCMachineState *pcms =PC_MACHINE (qdev_get_machine ());SGXEPCDevice *epc;if (pcms->sgx_epc.size ==0 || pcms->sgx_epc.nr_sections <= section_nr) { -return 1 ; +return true;
If return boolean, here should be return false, Sean wrote this(return 0 or 1) like Linux kernel did.
hw/i386/sgx.c int sgx_epc_get_section(int section_nr, uint64_t *addr, uint64_t *size) · line 132
Quoted 9 lines
hw/i386/sgx.c +1
-1} epc = pcms->sgx_epc.sections[section_nr];@@ -129,7 +129,7 @@ int sgx_epc_get_section(int section_nr, uint64_t *addr, uint64_t *size) *addr = epc->addr; *size =memory_device_get_region_size (MEMORY_DEVICE (epc), &error_fatal); -return 0 ; +return false;
Here should be return true.
Then in the ./target/i386/cpu.c file,
if (sgx_epc_get_section(count - 2, &epc_addr, &epc_size))
should be
if (!sgx_epc_get_section(count - 2, &epc_addr, &epc_size))
Yang
Quoted 5 lines
hw/i386/sgx.c +0
-0}void pc_machine_init_sgx_epc (PCMachineState *pcms)Signature · 1 line
2.31.1