On Fri, Aug 09, 2019 at 05:30:51PM -0700, Sean Christopherson wrote: > Manually align ELRANGE now that the kernel doesn't automatically do so > for SGX mappings. To guarantee mmap() returns a region that can be > naturally aligned, temporarily map 2x the enclave size and do fancy > arithmetic to naturally align the base. > > Signed-off-by: Sean Christopherson <sean.j.christopherson@xxxxxxxxx> Thank you. I fine-tuned the calculations a bit: area = mmap(NULL, secs->size * 2, PROT_NONE, MAP_SHARED, dev_fd, 0); if (area == MAP_FAILED) { perror("mmap"); return false; } secs->base = ((uint64_t)area + secs->size - 1) & ~(secs->size - 1); munmap(area, secs->base - (uint64_t)area); munmap((void *)(secs->base + secs->size), (uint64_t)area + secs->size - secs->base); /Jarkko