int mpx_enable_management(void) { void __user *bd_base = MPX_INVALID_BOUNDS_DIR; struct mm_struct *mm = current->mm; int ret = 0; /* * runtime in the userspace will be responsible for allocation of * the bounds directory. Then, it will save the base of the bounds * directory into XSAVE/XRSTOR Save Area and enable MPX through * XRSTOR instruction. * * The copy_xregs_to_kernel() beneath get_xsave_field_ptr() is * expected to be relatively expensive. Storing the bounds * directory here means that we do not have to do xsave in the * unmap path; we can just use mm->bd_addr instead. */ bd_base = mpx_get_bounds_dir(); down_write(&mm->mmap_sem); mm->bd_addr = bd_base; if (mm->bd_addr == MPX_INVALID_BOUNDS_DIR) ret = -ENXIO; up_write(&mm->mmap_sem); return ret; }
int mpx_enable_management(void) { void __user *bd_base = MPX_INVALID_BOUNDS_DIR; struct mm_struct *mm = current->mm; int ret = 0; /* * runtime in the userspace will be responsible for allocation of * the bounds directory. Then, it will save the base of the bounds * directory into XSAVE/XRSTOR Save Area and enable MPX through * XRSTOR instruction. * * The copy_xregs_to_kernel() beneath get_xsave_field_ptr() is * expected to be relatively expensive. Storing the bounds * directory here means that we do not have to do xsave in the * unmap path; we can just use mm->context.bd_addr instead. */ bd_base = mpx_get_bounds_dir(); down_write(&mm->mmap_sem); /* MPX doesn't support addresses above 47 bits yet. */ if (find_vma(mm, DEFAULT_MAP_WINDOW)) { pr_warn_once("%s (%d): MPX cannot handle addresses " "above 47-bits. Disabling.", current->comm, current->pid); ret = -ENXIO; goto out; } mm->context.bd_addr = bd_base; if (mm->context.bd_addr == MPX_INVALID_BOUNDS_DIR) ret = -ENXIO; out: up_write(&mm->mmap_sem); return ret; }