Hi Kai
On Tue, 14 Feb 2023 03:47:24 -0600, Huang, Kai <kai.huang@xxxxxxxxx> wrote:
On Fri, 2023-01-27 at 20:55 -0800, Haitao Huang wrote:
@@ -97,10 +99,81 @@ static int sgx_mmap(struct file *file, struct
vm_area_struct *vma)
vma->vm_ops = &sgx_vm_ops;
vma->vm_flags |= VM_PFNMAP | VM_DONTEXPAND | VM_DONTDUMP | VM_IO;
vma->vm_private_data = encl;
+ vma->vm_pgoff = PFN_DOWN(vma->vm_start - encl->base);
return 0;
}
Perhaps I am missing something, but above change looks weird.
Conceptually, it doesn't/shouldn't belong to this series, which
essentially
preallocates and does EAUG EPC pages for a (or part of) given enclave.
The EAUG
logic should already be working for the normal fault path, which means
the code
change above either: 1) has been done at other place; 2) isn't needed.
I have kinda forgotten the userspace sequence to create an enclave. If
I recall
correctly, you do below to create an enclave:
1) encl_fd = open("/dev/sgx_enclave");
2) encl_addr = mmap(encl_fd, encl_size, 0 /* pgoff */);
3) IOCTL(ECREATE, encl_addr, encl_size);
Would the above code change break the "mmap()" in above step 2?
No, vm_pgoff was not used previously for enclave VMAs. I had to add this
because the offset passed to sgx_fadvise is relative to file base and
calculated in mm/madvise.c like this:
offset = (loff_t)(start - vma->vm_start)
+ ((loff_t)vma->vm_pgoff << PAGE_SHIFT);
I had a comment in first version but removed it based on Jarkko's
suggestion here: https://lore.kernel.org/all/Y2B0jBsG6HE4KVk7@xxxxxxxxxx/
The original comments probably seemed redundant to the definitions of the
vm_pgoff field and the fadvise interface. But let me know if we need add a
more helpful version of comments or any suggestion on the comments.
Thanks
Haitao