#include <linux/mempolicy.h>
#include <linux/ioctl.h>
#include <linux/security.h>
+#include <linux/hugetlb.h>
static struct kmem_cache *userfaultfd_ctx_cachep __read_mostly;
struct uffdio_register __user *user_uffdio_register;
unsigned long vm_flags, new_flags;
bool found;
+ bool huge_pages;
unsigned long start, end, vma_end;
user_uffdio_register = (struct uffdio_register __user *) arg;
if (vma->vm_start >= end)
goto out_unlock;
+ /*
+ * If the first vma contains huge pages, make sure start address
+ * is aligned to huge page size.
+ */
+ if (is_vm_hugetlb_page(vma)) {
+ unsigned long vma_hpagesize = vma_kernel_pagesize(vma);
+
+ if (start & (vma_hpagesize - 1))
+ goto out_unlock;
+ }
+
/*
* Search for not compatible vmas.
*
* on anonymous vmas).
*/
found = false;
+ huge_pages = false;
for (cur = vma; cur && cur->vm_start < end; cur = cur->vm_next) {
cond_resched();
/* check not compatible vmas */
ret = -EINVAL;
- if (!vma_is_anonymous(cur))
+ if (!vma_is_anonymous(cur) && !is_vm_hugetlb_page(cur))
goto out_unlock;
+ /*
+ * If this vma contains ending address, and huge pages
+ * check alignment.
+ */
+ if (is_vm_hugetlb_page(cur) && end <= cur->vm_end &&
+ end > cur->vm_start) {
+ unsigned long vma_hpagesize = vma_kernel_pagesize(cur);
+
+ ret = -EINVAL;
+
+ if (end & (vma_hpagesize - 1))
+ goto out_unlock;
+ }
/*
* Check that this vma isn't already owned by a
cur->vm_userfaultfd_ctx.ctx != ctx)
goto out_unlock;
+ /*
+ * Note vmas containing huge pages
+ */
+ if (is_vm_hugetlb_page(cur))
+ huge_pages = true;
+
found = true;
}
BUG_ON(!found);
do {
cond_resched();
- BUG_ON(!vma_is_anonymous(vma));
+ BUG_ON(!vma_is_anonymous(vma) && !is_vm_hugetlb_page(vma));
BUG_ON(vma->vm_userfaultfd_ctx.ctx &&
vma->vm_userfaultfd_ctx.ctx != ctx);
* userland which ioctls methods are guaranteed to
* succeed on this range.
*/
- if (put_user(UFFD_API_RANGE_IOCTLS,
+ if (put_user(huge_pages ? UFFD_API_RANGE_IOCTLS_HPAGE :
+ UFFD_API_RANGE_IOCTLS,
&user_uffdio_register->ioctls))
ret = -EFAULT;
}
if (vma->vm_start >= end)
goto out_unlock;
+ /*
+ * If the first vma contains huge pages, make sure start address
+ * is aligned to huge page size.
+ */
+ if (is_vm_hugetlb_page(vma)) {
+ unsigned long vma_hpagesize = vma_kernel_pagesize(vma);
+
+ if (start & (vma_hpagesize - 1))
+ goto out_unlock;
+ }
+
/*
* Search for not compatible vmas.
*
* provides for more strict behavior to notice
* unregistration errors.
*/
- if (!vma_is_anonymous(cur))
+ if (!vma_is_anonymous(cur) && !is_vm_hugetlb_page(cur))
goto out_unlock;
found = true;
do {
cond_resched();
- BUG_ON(!vma_is_anonymous(vma));
+ BUG_ON(!vma_is_anonymous(vma) && !is_vm_hugetlb_page(vma));
/*
* Nothing to do: this vma is already registered into this