On Fri 10-06-22 17:35:25, Kirill A. Shutemov wrote: [...] > diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c > index 1962008fe743..93c8eba1a66d 100644 > --- a/arch/x86/kernel/process_64.c > +++ b/arch/x86/kernel/process_64.c > @@ -742,6 +742,32 @@ static long prctl_map_vdso(const struct vdso_image *image, unsigned long addr) > } > #endif > > +static int prctl_enable_tagged_addr(unsigned long nr_bits) > +{ > + struct mm_struct *mm = current->mm; > + > + /* Already enabled? */ > + if (mm->context.lam_cr3_mask) > + return -EBUSY; > + > + /* LAM has to be enabled before spawning threads */ > + if (get_nr_threads(current) > 1) > + return -EBUSY; This will not be sufficient in general. You can have mm shared with a process without CLONE_THREAD. So you would also need to check also MMF_MULTIPROCESS. But I do remember that general get_nr_threads is quite tricky to use properly. Make sure to CC Oleg Nesterov for more details. Also how does this work when the mm is shared with a kernel thread? > + > + if (!nr_bits) { > + return -EINVAL; > + } else if (nr_bits <= 6) { > + mm->context.lam_cr3_mask = X86_CR3_LAM_U57; > + mm->context.untag_mask = ~GENMASK(62, 57); > + } else { > + return -EINVAL; > + } > + > + /* Update CR3 to get LAM active */ > + switch_mm(current->mm, current->mm, current); > + return 0; > +} -- Michal Hocko SUSE Labs