Add a flag to allow userspace to replicate a single source page to multiple target pages in the enclave, e.g. to zero the .bss, initialize the heap, etc... Signed-off-by: Sean Christopherson <sean.j.christopherson@xxxxxxxxx> --- arch/x86/include/uapi/asm/sgx.h | 7 ++++++- arch/x86/kernel/cpu/sgx/ioctl.c | 3 ++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/arch/x86/include/uapi/asm/sgx.h b/arch/x86/include/uapi/asm/sgx.h index 84734229d8dd..42634e99945e 100644 --- a/arch/x86/include/uapi/asm/sgx.h +++ b/arch/x86/include/uapi/asm/sgx.h @@ -28,6 +28,9 @@ struct sgx_enclave_create { __u64 src; }; +/* Replicate a single source data page to all target pages. */ +#define SGX_ADD_PAGES_REPLICATE_SRC BIT(0) + /** * struct sgx_enclave_add_pages - parameter structure for the * %SGX_IOC_ENCLAVE_ADD_PAGE ioctl @@ -35,6 +38,7 @@ struct sgx_enclave_create { * @src: start address for the page data * @nr_pages: number of pages to add to enclave * @secinfo: address for the SECINFO data + * @flags: misc control flags * @mrmask: bitmask for the measured 256 byte chunks * @reserved: reserved for future use */ @@ -43,8 +47,9 @@ struct sgx_enclave_add_pages { __u64 src; __u64 nr_pages; __u64 secinfo; + __u32 flags; __u16 mrmask; - __u8 reserved[6]; + __u8 reserved[2]; }; /** diff --git a/arch/x86/kernel/cpu/sgx/ioctl.c b/arch/x86/kernel/cpu/sgx/ioctl.c index 4597dd8f5c91..9c6d582612cb 100644 --- a/arch/x86/kernel/cpu/sgx/ioctl.c +++ b/arch/x86/kernel/cpu/sgx/ioctl.c @@ -529,7 +529,8 @@ static long sgx_ioc_enclave_add_pages(struct sgx_encl *encl, void __user *arg) break; addp.offset += PAGE_SIZE; - addp.src += PAGE_SIZE; + if (!(addp.flags & SGX_ADD_PAGES_REPLICATE_SRC)) + addp.src += PAGE_SIZE; } if (copy_to_user(arg, &addp, sizeof(addp))) -- 2.22.0