2021-07-19 14:21:07 +03:00
|
|
|
/*
|
|
|
|
* SGX EPC device
|
|
|
|
*
|
|
|
|
* Copyright (C) 2019 Intel Corporation
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Sean Christopherson <sean.j.christopherson@intel.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 QEMU_SGX_EPC_H
|
|
|
|
#define QEMU_SGX_EPC_H
|
|
|
|
|
|
|
|
#include "hw/i386/hostmem-epc.h"
|
|
|
|
|
|
|
|
#define TYPE_SGX_EPC "sgx-epc"
|
|
|
|
#define SGX_EPC(obj) \
|
|
|
|
OBJECT_CHECK(SGXEPCDevice, (obj), TYPE_SGX_EPC)
|
|
|
|
#define SGX_EPC_CLASS(oc) \
|
|
|
|
OBJECT_CLASS_CHECK(SGXEPCDeviceClass, (oc), TYPE_SGX_EPC)
|
|
|
|
#define SGX_EPC_GET_CLASS(obj) \
|
|
|
|
OBJECT_GET_CLASS(SGXEPCDeviceClass, (obj), TYPE_SGX_EPC)
|
|
|
|
|
|
|
|
#define SGX_EPC_ADDR_PROP "addr"
|
|
|
|
#define SGX_EPC_SIZE_PROP "size"
|
|
|
|
#define SGX_EPC_MEMDEV_PROP "memdev"
|
numa: Enable numa for SGX EPC sections
The basic SGX did not enable numa for SGX EPC sections, which
result in all EPC sections located in numa node 0. This patch
enable SGX numa function in the guest and the EPC section can
work with RAM as one numa node.
The Guest kernel related log:
[ 0.009981] ACPI: SRAT: Node 0 PXM 0 [mem 0x180000000-0x183ffffff]
[ 0.009982] ACPI: SRAT: Node 1 PXM 1 [mem 0x184000000-0x185bfffff]
The SRAT table can normally show SGX EPC sections menory info in different
numa nodes.
The SGX EPC numa related command:
......
-m 4G,maxmem=20G \
-smp sockets=2,cores=2 \
-cpu host,+sgx-provisionkey \
-object memory-backend-ram,size=2G,host-nodes=0,policy=bind,id=node0 \
-object memory-backend-epc,id=mem0,size=64M,prealloc=on,host-nodes=0,policy=bind \
-numa node,nodeid=0,cpus=0-1,memdev=node0 \
-object memory-backend-ram,size=2G,host-nodes=1,policy=bind,id=node1 \
-object memory-backend-epc,id=mem1,size=28M,prealloc=on,host-nodes=1,policy=bind \
-numa node,nodeid=1,cpus=2-3,memdev=node1 \
-M sgx-epc.0.memdev=mem0,sgx-epc.0.node=0,sgx-epc.1.memdev=mem1,sgx-epc.1.node=1 \
......
Signed-off-by: Yang Zhong <yang.zhong@intel.com>
Message-Id: <20211101162009.62161-2-yang.zhong@intel.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2021-11-01 19:20:05 +03:00
|
|
|
#define SGX_EPC_NUMA_NODE_PROP "node"
|
2021-07-19 14:21:07 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* SGXEPCDevice:
|
|
|
|
* @addr: starting guest physical address, where @SGXEPCDevice is mapped.
|
|
|
|
* Default value: 0, means that address is auto-allocated.
|
|
|
|
* @hostmem: host memory backend providing memory for @SGXEPCDevice
|
|
|
|
*/
|
|
|
|
typedef struct SGXEPCDevice {
|
|
|
|
/* private */
|
|
|
|
DeviceState parent_obj;
|
|
|
|
|
|
|
|
/* public */
|
|
|
|
uint64_t addr;
|
numa: Enable numa for SGX EPC sections
The basic SGX did not enable numa for SGX EPC sections, which
result in all EPC sections located in numa node 0. This patch
enable SGX numa function in the guest and the EPC section can
work with RAM as one numa node.
The Guest kernel related log:
[ 0.009981] ACPI: SRAT: Node 0 PXM 0 [mem 0x180000000-0x183ffffff]
[ 0.009982] ACPI: SRAT: Node 1 PXM 1 [mem 0x184000000-0x185bfffff]
The SRAT table can normally show SGX EPC sections menory info in different
numa nodes.
The SGX EPC numa related command:
......
-m 4G,maxmem=20G \
-smp sockets=2,cores=2 \
-cpu host,+sgx-provisionkey \
-object memory-backend-ram,size=2G,host-nodes=0,policy=bind,id=node0 \
-object memory-backend-epc,id=mem0,size=64M,prealloc=on,host-nodes=0,policy=bind \
-numa node,nodeid=0,cpus=0-1,memdev=node0 \
-object memory-backend-ram,size=2G,host-nodes=1,policy=bind,id=node1 \
-object memory-backend-epc,id=mem1,size=28M,prealloc=on,host-nodes=1,policy=bind \
-numa node,nodeid=1,cpus=2-3,memdev=node1 \
-M sgx-epc.0.memdev=mem0,sgx-epc.0.node=0,sgx-epc.1.memdev=mem1,sgx-epc.1.node=1 \
......
Signed-off-by: Yang Zhong <yang.zhong@intel.com>
Message-Id: <20211101162009.62161-2-yang.zhong@intel.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2021-11-01 19:20:05 +03:00
|
|
|
uint32_t node;
|
2021-07-19 14:21:07 +03:00
|
|
|
HostMemoryBackendEpc *hostmem;
|
|
|
|
} SGXEPCDevice;
|
|
|
|
|
vl: Add sgx compound properties to expose SGX EPC sections to guest
Because SGX EPC is enumerated through CPUID, EPC "devices" need to be
realized prior to realizing the vCPUs themselves, i.e. long before
generic devices are parsed and realized. From a virtualization
perspective, the CPUID aspect also means that EPC sections cannot be
hotplugged without paravirtualizing the guest kernel (hardware does
not support hotplugging as EPC sections must be locked down during
pre-boot to provide EPC's security properties).
So even though EPC sections could be realized through the generic
-devices command, they need to be created much earlier for them to
actually be usable by the guest. Place all EPC sections in a
contiguous block, somewhat arbitrarily starting after RAM above 4g.
Ensuring EPC is in a contiguous region simplifies calculations, e.g.
device memory base, PCI hole, etc..., allows dynamic calculation of the
total EPC size, e.g. exposing EPC to guests does not require -maxmem,
and last but not least allows all of EPC to be enumerated in a single
ACPI entry, which is expected by some kernels, e.g. Windows 7 and 8.
The new compound properties command for sgx like below:
......
-object memory-backend-epc,id=mem1,size=28M,prealloc=on \
-object memory-backend-epc,id=mem2,size=10M \
-M sgx-epc.0.memdev=mem1,sgx-epc.1.memdev=mem2
Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
Signed-off-by: Yang Zhong <yang.zhong@intel.com>
Message-Id: <20210719112136.57018-6-yang.zhong@intel.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2021-09-28 11:40:58 +03:00
|
|
|
/*
|
|
|
|
* @base: address in guest physical address space where EPC regions start
|
|
|
|
* @mr: address space container for memory devices
|
|
|
|
*/
|
|
|
|
typedef struct SGXEPCState {
|
|
|
|
uint64_t base;
|
|
|
|
uint64_t size;
|
|
|
|
|
|
|
|
MemoryRegion mr;
|
|
|
|
|
|
|
|
struct SGXEPCDevice **sections;
|
|
|
|
int nr_sections;
|
|
|
|
} SGXEPCState;
|
|
|
|
|
2021-10-07 20:56:10 +03:00
|
|
|
bool sgx_epc_get_section(int section_nr, uint64_t *addr, uint64_t *size);
|
numa: Enable numa for SGX EPC sections
The basic SGX did not enable numa for SGX EPC sections, which
result in all EPC sections located in numa node 0. This patch
enable SGX numa function in the guest and the EPC section can
work with RAM as one numa node.
The Guest kernel related log:
[ 0.009981] ACPI: SRAT: Node 0 PXM 0 [mem 0x180000000-0x183ffffff]
[ 0.009982] ACPI: SRAT: Node 1 PXM 1 [mem 0x184000000-0x185bfffff]
The SRAT table can normally show SGX EPC sections menory info in different
numa nodes.
The SGX EPC numa related command:
......
-m 4G,maxmem=20G \
-smp sockets=2,cores=2 \
-cpu host,+sgx-provisionkey \
-object memory-backend-ram,size=2G,host-nodes=0,policy=bind,id=node0 \
-object memory-backend-epc,id=mem0,size=64M,prealloc=on,host-nodes=0,policy=bind \
-numa node,nodeid=0,cpus=0-1,memdev=node0 \
-object memory-backend-ram,size=2G,host-nodes=1,policy=bind,id=node1 \
-object memory-backend-epc,id=mem1,size=28M,prealloc=on,host-nodes=1,policy=bind \
-numa node,nodeid=1,cpus=2-3,memdev=node1 \
-M sgx-epc.0.memdev=mem0,sgx-epc.0.node=0,sgx-epc.1.memdev=mem1,sgx-epc.1.node=1 \
......
Signed-off-by: Yang Zhong <yang.zhong@intel.com>
Message-Id: <20211101162009.62161-2-yang.zhong@intel.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2021-11-01 19:20:05 +03:00
|
|
|
void sgx_epc_build_srat(GArray *table_data);
|
2021-07-19 14:21:15 +03:00
|
|
|
|
2021-07-19 14:21:20 +03:00
|
|
|
static inline uint64_t sgx_epc_above_4g_end(SGXEPCState *sgx_epc)
|
|
|
|
{
|
|
|
|
assert(sgx_epc != NULL && sgx_epc->base >= 0x100000000ULL);
|
|
|
|
|
|
|
|
return sgx_epc->base + sgx_epc->size;
|
|
|
|
}
|
|
|
|
|
2021-07-19 14:21:07 +03:00
|
|
|
#endif
|