Add support for Intel Software Guard Extensions (Intel SGX).

Intel SGX allows to manage isolated compartments "Enclaves" in user VA
space. Enclaves memory is part of processor reserved memory (PRM) and
always encrypted. This allows to protect user application code and data
from upper privilege levels including OS kernel.

This includes SGX driver and optional linux ioctl compatibility layer.
Intel SGX SDK for FreeBSD is also available.

Note this requires support from hardware (available since late Intel
Skylake CPUs).

Many thanks to Robert Watson for support and Konstantin Belousov
for code review.

Project wiki: https://wiki.freebsd.org/Intel_SGX.

Reviewed by:	kib
Relnotes:	yes
Sponsored by:	DARPA, AFRL
Differential Revision:	https://reviews.freebsd.org/D11113
This commit is contained in:
Ruslan Bukin 2017-08-16 10:38:06 +00:00
parent 7bbdb843b6
commit 2164af29a0
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=322574
10 changed files with 1813 additions and 0 deletions

View file

@ -834,6 +834,85 @@ intr_restore(register_t rflags)
write_rflags(rflags);
}
enum {
SGX_ECREATE = 0x0,
SGX_EADD = 0x1,
SGX_EINIT = 0x2,
SGX_EREMOVE = 0x3,
SGX_EDGBRD = 0x4,
SGX_EDGBWR = 0x5,
SGX_EEXTEND = 0x6,
SGX_ELDU = 0x8,
SGX_EBLOCK = 0x9,
SGX_EPA = 0xA,
SGX_EWB = 0xB,
SGX_ETRACK = 0xC,
};
enum {
SGX_PT_SECS = 0x00,
SGX_PT_TCS = 0x01,
SGX_PT_REG = 0x02,
SGX_PT_VA = 0x03,
SGX_PT_TRIM = 0x04,
};
int sgx_encls(uint32_t eax, uint64_t rbx, uint64_t rcx, uint64_t rdx);
static __inline int
sgx_ecreate(void *pginfo, void *secs)
{
return (sgx_encls(SGX_ECREATE, (uint64_t)pginfo,
(uint64_t)secs, 0));
}
static __inline int
sgx_eadd(void *pginfo, void *epc)
{
return (sgx_encls(SGX_EADD, (uint64_t)pginfo,
(uint64_t)epc, 0));
}
static __inline int
sgx_einit(void *sigstruct, void *secs, void *einittoken)
{
return (sgx_encls(SGX_EINIT, (uint64_t)sigstruct,
(uint64_t)secs, (uint64_t)einittoken));
}
static __inline int
sgx_eextend(void *secs, void *epc)
{
return (sgx_encls(SGX_EEXTEND, (uint64_t)secs,
(uint64_t)epc, 0));
}
static __inline int
sgx_epa(void *epc)
{
return (sgx_encls(SGX_EPA, SGX_PT_VA, (uint64_t)epc, 0));
}
static __inline int
sgx_eldu(uint64_t rbx, uint64_t rcx,
uint64_t rdx)
{
return (sgx_encls(SGX_ELDU, rbx, rcx, rdx));
}
static __inline int
sgx_eremove(void *epc)
{
return (sgx_encls(SGX_EREMOVE, 0, (uint64_t)epc, 0));
}
#else /* !(__GNUCLIKE_ASM && __CC_SUPPORTS___INLINE) */
int breakpoint(void);

64
sys/amd64/include/sgx.h Normal file
View file

@ -0,0 +1,64 @@
/*-
* Copyright (c) 2017 Ruslan Bukin <br@bsdpad.com>
* All rights reserved.
*
* This software was developed by BAE Systems, the University of Cambridge
* Computer Laboratory, and Memorial University under DARPA/AFRL contract
* FA8650-15-C-7558 ("CADETS"), as part of the DARPA Transparent Computing
* (TC) research program.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD$
*/
/* User-visible header. */
#ifndef _MACHINE_SGX_H_
#define _MACHINE_SGX_H_
#define SGX_MAGIC 0xA4
#define SGX_IOC_ENCLAVE_CREATE \
_IOW(SGX_MAGIC, 0x00, struct sgx_enclave_create)
#define SGX_IOC_ENCLAVE_ADD_PAGE \
_IOW(SGX_MAGIC, 0x01, struct sgx_enclave_add_page)
#define SGX_IOC_ENCLAVE_INIT \
_IOW(SGX_MAGIC, 0x02, struct sgx_enclave_init)
struct sgx_enclave_create {
uint64_t src;
} __packed;
struct sgx_enclave_add_page {
uint64_t addr;
uint64_t src;
uint64_t secinfo;
uint16_t mrmask;
} __packed;
struct sgx_enclave_init {
uint64_t addr;
uint64_t sigstruct;
uint64_t einittoken;
} __packed;
#endif /* !_MACHINE_SGX_H_ */

155
sys/amd64/include/sgxreg.h Normal file
View file

@ -0,0 +1,155 @@
/*-
* Copyright (c) 2017 Ruslan Bukin <br@bsdpad.com>
* All rights reserved.
*
* This software was developed by BAE Systems, the University of Cambridge
* Computer Laboratory, and Memorial University under DARPA/AFRL contract
* FA8650-15-C-7558 ("CADETS"), as part of the DARPA Transparent Computing
* (TC) research program.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD$
*/
/* Machine-defined variables. */
#ifndef _MACHINE_SGXREG_H_
#define _MACHINE_SGXREG_H_
/* Error codes. */
#define SGX_SUCCESS 0
#define SGX_INVALID_SIG_STRUCT 1 /* EINIT */
#define SGX_INVALID_ATTRIBUTE 2 /* EINIT, EGETKEY */
#define SGX_BLSTATE 3 /* EBLOCK */
#define SGX_INVALID_MEASUREMENT 4 /* EINIT */
#define SGX_NOTBLOCKABLE 5 /* EBLOCK */
#define SGX_PG_INVLD 6 /* EBLOCK */
#define SGX_LOCKFAIL 7 /* EBLOCK, EMODPR, EMODT */
#define SGX_INVALID_SIGNATURE 8 /* EINIT */
#define SGX_MAC_COMPARE_FAIL 9 /* ELDB, ELDU */
#define SGX_PAGE_NOT_BLOCKED 10 /* EWB */
#define SGX_NOT_TRACKED 11 /* EWB, EACCEPT */
#define SGX_VA_SLOT_OCCUPIED 12 /* EWB */
#define SGX_CHILD_PRESENT 13 /* EWB, EREMOVE */
#define SGX_ENCLAVE_ACT 14 /* EREMOVE */
#define SGX_ENTRYEPOCH_LOCKED 15 /* EBLOCK */
#define SGX_INVALID_EINIT_TOKEN 16 /* EINIT */
#define SGX_PREV_TRK_INCMPL 17 /* ETRACK */
#define SGX_PG_IS_SECS 18 /* EBLOCK */
#define SGX_PAGE_ATTRIBUTES_MISMATCH 19 /* EACCEPT, EACCEPTCOPY */
#define SGX_PAGE_NOT_MODIFIABLE 20 /* EMODPR, EMODT */
#define SGX_INVALID_CPUSVN 32 /* EINIT, EGETKEY */
#define SGX_INVALID_ISVSVN 64 /* EGETKEY */
#define SGX_UNMASKED_EVENT 128 /* EINIT */
#define SGX_INVALID_KEYNAME 256 /* EGETKEY */
/*
* 2.10 Page Information (PAGEINFO)
* PAGEINFO is an architectural data structure that is used as a parameter
* to the EPC-management instructions. It requires 32-Byte alignment.
*/
struct page_info {
uint64_t linaddr;
uint64_t srcpge;
union {
struct secinfo *secinfo;
uint64_t pcmd;
};
uint64_t secs;
} __aligned(32);
/*
* 2.11 Security Information (SECINFO)
* The SECINFO data structure holds meta-data about an enclave page.
*/
struct secinfo {
uint64_t flags;
#define SECINFO_FLAGS_PT_S 8 /* Page type shift */
#define SECINFO_FLAGS_PT_M (0xff << SECINFO_FLAGS_PT_S)
uint64_t reserved[7];
} __aligned(64);
/*
* 2.7.1 ATTRIBUTES
* The ATTRIBUTES data structure is comprised of bit-granular fields that
* are used in the SECS, CPUID enumeration, the REPORT and the KEYREQUEST
* structures.
*/
struct secs_attr {
uint8_t reserved1: 1;
uint8_t debug: 1;
uint8_t mode64bit: 1;
uint8_t reserved2: 1;
uint8_t provisionkey: 1;
uint8_t einittokenkey: 1;
uint8_t reserved3: 2;
#define SECS_ATTR_RSV4_SIZE 7
uint8_t reserved4[SECS_ATTR_RSV4_SIZE];
uint64_t xfrm; /* X-Feature Request Mask */
};
/*
* 2.7 SGX Enclave Control Structure (SECS)
* The SECS data structure requires 4K-Bytes alignment.
*/
struct secs {
uint64_t size;
uint64_t base;
uint32_t ssa_frame_size;
uint32_t misc_select;
#define SECS_RSV1_SIZE 24
uint8_t reserved1[SECS_RSV1_SIZE];
struct secs_attr attributes;
uint8_t mr_enclave[32];
#define SECS_RSV2_SIZE 32
uint8_t reserved2[SECS_RSV2_SIZE];
uint8_t mr_signer[32];
#define SECS_RSV3_SIZE 96
uint8_t reserved3[SECS_RSV3_SIZE];
uint16_t isv_prod_id;
uint16_t isv_svn;
#define SECS_RSV4_SIZE 3836
uint8_t reserved4[SECS_RSV4_SIZE];
};
/*
* 2.8 Thread Control Structure (TCS)
* Each executing thread in the enclave is associated with a
* Thread Control Structure. It requires 4K-Bytes alignment.
*/
struct tcs {
uint64_t reserved1;
uint64_t flags;
uint64_t ossa;
uint32_t cssa;
uint32_t nssa;
uint64_t oentry;
uint64_t reserved2;
uint64_t ofsbasgx;
uint64_t ogsbasgx;
uint32_t fslimit;
uint32_t gslimit;
uint64_t reserved3[503];
};
#endif /* !_MACHINE_SGXREG_H_ */

1211
sys/amd64/sgx/sgx.c Normal file

File diff suppressed because it is too large Load diff

119
sys/amd64/sgx/sgx_linux.c Normal file
View file

@ -0,0 +1,119 @@
/*-
* Copyright (c) 2017 Ruslan Bukin <br@bsdpad.com>
* All rights reserved.
*
* This software was developed by BAE Systems, the University of Cambridge
* Computer Laboratory, and Memorial University under DARPA/AFRL contract
* FA8650-15-C-7558 ("CADETS"), as part of the DARPA Transparent Computing
* (TC) research program.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/capsicum.h>
#include <sys/conf.h>
#include <sys/kernel.h>
#include <sys/module.h>
#include <sys/file.h>
#include <sys/proc.h>
#include <machine/sgx.h>
#include <machine/../linux/linux.h>
#include <machine/../linux/linux_proto.h>
#include <compat/linux/linux_ioctl.h>
#include <amd64/sgx/sgxvar.h>
#include <sys/ioccom.h>
#define SGX_LINUX_IOCTL_MIN (SGX_IOC_ENCLAVE_CREATE & 0xffff)
#define SGX_LINUX_IOCTL_MAX (SGX_IOC_ENCLAVE_INIT & 0xffff)
static int
sgx_linux_ioctl(struct thread *td, struct linux_ioctl_args *args)
{
uint8_t data[SGX_IOCTL_MAX_DATA_LEN];
cap_rights_t rights;
struct file *fp;
u_long cmd;
int error;
int len;
error = fget(td, args->fd, cap_rights_init(&rights, CAP_IOCTL), &fp);
if (error != 0)
return (error);
cmd = args->cmd;
args->cmd &= ~(LINUX_IOC_IN | LINUX_IOC_OUT);
if (cmd & LINUX_IOC_IN)
args->cmd |= IOC_IN;
if (cmd & LINUX_IOC_OUT)
args->cmd |= IOC_OUT;
len = IOCPARM_LEN(cmd);
if (len > SGX_IOCTL_MAX_DATA_LEN) {
printf("%s: Can't copy data: cmd len is too big %d\n",
__func__, len);
return (EINVAL);
}
if (cmd & LINUX_IOC_IN) {
error = copyin((void *)args->arg, data, len);
if (error) {
printf("%s: Can't copy data, error %d\n",
__func__, error);
return (EINVAL);
}
}
error = (fo_ioctl(fp, args->cmd, (caddr_t)data, td->td_ucred, td));
fdrop(fp, td);
return (error);
}
static struct linux_ioctl_handler sgx_linux_handler = {
sgx_linux_ioctl,
SGX_LINUX_IOCTL_MIN,
SGX_LINUX_IOCTL_MAX,
};
SYSINIT(sgx_linux_register, SI_SUB_KLD, SI_ORDER_MIDDLE,
linux_ioctl_register_handler, &sgx_linux_handler);
SYSUNINIT(sgx_linux_unregister, SI_SUB_KLD, SI_ORDER_MIDDLE,
linux_ioctl_unregister_handler, &sgx_linux_handler);
static int
sgx_linux_modevent(module_t mod, int type, void *data)
{
return (0);
}
DEV_MODULE(sgx_linux, sgx_linux_modevent, NULL);
MODULE_DEPEND(sgx_linux, linux64, 1, 1, 1);

View file

@ -0,0 +1,70 @@
/*-
* Copyright (c) 2017 Ruslan Bukin <br@bsdpad.com>
* All rights reserved.
*
* This software was developed by BAE Systems, the University of Cambridge
* Computer Laboratory, and Memorial University under DARPA/AFRL contract
* FA8650-15-C-7558 ("CADETS"), as part of the DARPA Transparent Computing
* (TC) research program.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD$
*/
#include <machine/asmacros.h>
#include <amd64/sgx/sgxvar.h>
#include "assym.s"
.text
/*
* int
* sgx_encls(uint32_t eax, uint64_t rbx, uint64_t rcx, uint64_t rdx);
* %edi, %rsi, %rdx, %rcx
*/
ENTRY(sgx_encls)
PUSH_FRAME_POINTER
pushq %rbx
movq PCPU(CURPCB),%r8
movl %edi,%eax
movq %rsi,%rbx
xchgq %rdx,%rcx
movq $sgx_onfault,PCB_ONFAULT(%r8)
.byte 0x0f, 0x01, 0xcf
movq $0,PCB_ONFAULT(%r8)
popq %rbx
POP_FRAME_POINTER
ret
END(sgx_encls)
/*
* SGX operations fault handler
*/
ALIGN_TEXT
sgx_onfault:
movq $0,PCB_ONFAULT(%r8)
movl $SGX_EFAULT,%eax
popq %rbx
POP_FRAME_POINTER
ret

91
sys/amd64/sgx/sgxvar.h Normal file
View file

@ -0,0 +1,91 @@
/*-
* Copyright (c) 2017 Ruslan Bukin <br@bsdpad.com>
* All rights reserved.
*
* This software was developed by BAE Systems, the University of Cambridge
* Computer Laboratory, and Memorial University under DARPA/AFRL contract
* FA8650-15-C-7558 ("CADETS"), as part of the DARPA Transparent Computing
* (TC) research program.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD$
*/
#ifndef _AMD64_SGX_SGXVAR_H_
#define _AMD64_SGX_SGXVAR_H_
#define SGX_CPUID 0x12
#define SGX_PAGE_SIZE 4096
#define SGX_VA_PAGE_SLOTS 512
#define SGX_VA_PAGES_OFFS 512
#define SGX_SECS_VM_OBJECT_INDEX -1
#define SGX_SIGSTRUCT_SIZE 1808
#define SGX_EINITTOKEN_SIZE 304
#define SGX_IOCTL_MAX_DATA_LEN 26
#define SGX_ENCL_SIZE_MAX_DEF 0x1000000000ULL
#define SGX_EFAULT 99
#ifndef LOCORE
static MALLOC_DEFINE(M_SGX, "sgx", "SGX driver");
struct sgx_vm_handle {
struct sgx_softc *sc;
vm_object_t mem;
uint64_t base;
vm_size_t size;
struct sgx_enclave *enclave;
};
/* EPC (Enclave Page Cache) page. */
struct epc_page {
uint64_t base;
uint64_t phys;
int index;
};
struct sgx_enclave {
uint64_t base;
uint64_t size;
struct sgx_vm_handle *vmh;
TAILQ_ENTRY(sgx_enclave) next;
vm_object_t object;
struct epc_page *secs_epc_page;
};
struct sgx_softc {
struct cdev *sgx_cdev;
struct mtx mtx_encls;
struct mtx mtx;
uint64_t epc_base;
uint64_t epc_size;
struct epc_page *epc_pages;
struct vmem *vmem_epc;
uint32_t npages;
TAILQ_HEAD(, sgx_enclave) enclaves;
uint64_t enclave_size_max;
uint8_t state;
#define SGX_STATE_RUNNING (1 << 0)
};
#endif /* !LOCORE */
#endif /* !_AMD64_SGX_SGXVAR_H_ */

View file

@ -346,6 +346,8 @@ SUBDIR= \
${_sf} \
${_sfxge} \
sge \
${_sgx} \
${_sgx_linux} \
siba_bwn \
siftr \
siis \
@ -709,6 +711,8 @@ _qlxgb= qlxgb
_qlxgbe= qlxgbe
_qlnx= qlnx
_sfxge= sfxge
_sgx= sgx
_sgx_linux= sgx_linux
.if ${MK_BHYVE} != "no" || defined(ALL_MODULES)
_vmm= vmm

12
sys/modules/sgx/Makefile Normal file
View file

@ -0,0 +1,12 @@
# $FreeBSD$
.PATH: ${SRCTOP}/sys/amd64/sgx
KMOD= sgx
SRCS= sgx.c sgxvar.h assym.s sgx_support.S
sgx_support.o: assym.s
${CC} -c -x assembler-with-cpp -DLOCORE ${CFLAGS} \
${.IMPSRC} -o ${.TARGET}
.include <bsd.kmod.mk>

View file

@ -0,0 +1,8 @@
# $FreeBSD$
.PATH: ${SRCTOP}/sys/amd64/sgx
KMOD= sgx_linux
SRCS= sgx_linux.c
.include <bsd.kmod.mk>