On Mon, Sep 08, 2025 at 10:52:40AM -0300, Jason Gunthorpe wrote:
> On Mon, Sep 08, 2025 at 02:37:44PM +0100, Lorenzo Stoakes wrote:
> > On Mon, Sep 08, 2025 at 10:11:21AM -0300, Jason Gunthorpe wrote:
> > > On Mon, Sep 08, 2025 at 12:10:41PM +0100, Lorenzo Stoakes wrote:
> > > > @@ -151,20 +123,55 @@ static int hugetlbfs_file_mmap(struct file *file, 
> > > > struct vm_area_struct *vma)
> > > >                 vm_flags |= VM_NORESERVE;
> > > >
> > > >         if (hugetlb_reserve_pages(inode,
> > > > -                               vma->vm_pgoff >> huge_page_order(h),
> > > > -                               len >> huge_page_shift(h), vma,
> > > > -                               vm_flags) < 0)
> > > > +                       vma->vm_pgoff >> huge_page_order(h),
> > > > +                       len >> huge_page_shift(h), vma,
> > > > +                       vm_flags) < 0) {
> > >
> > > It was split like this because vma is passed here right?
> > >
> > > But hugetlb_reserve_pages() doesn't do much with the vma:
> > >
> > >   hugetlb_vma_lock_alloc(vma);
> > > [..]
> > >   vma->vm_private_data = vma_lock;
> > >
> > > Manipulates the private which should already exist in prepare:
> > >
> > > Check non-share a few times:
> > >
> > >   if (!vma || vma->vm_flags & VM_MAYSHARE) {
> > >   if (vma && !(vma->vm_flags & VM_MAYSHARE) && h_cg) {
> > >   if (!vma || vma->vm_flags & VM_MAYSHARE) {
> > >
> > > And does this resv_map stuff:
> > >
> > >           set_vma_resv_map(vma, resv_map);
> > >           set_vma_resv_flags(vma, HPAGE_RESV_OWNER);
> > > [..]
> > >   set_vma_private_data(vma, (unsigned long)map);
> > >
> > > Which is also just manipulating the private data.
> > >
> > > So it looks to me like it should be refactored so that
> > > hugetlb_reserve_pages() returns the priv pointer to set in the VMA
> > > instead of accepting vma as an argument. Maybe just pass in the desc
> > > instead?
> >
> > Well hugetlb_vma_lock_alloc() does:
> >
> >     vma_lock->vma = vma;
> >
> > Which we cannot do in prepare.
>
> Okay, just doing that in commit would be appropriate then
>
> > This is checked in hugetlb_dup_vma_private(), and obviously desc is not a 
> > stable
> > pointer to be used for comparing anything.
> >
> > I'm also trying to do the minimal changes I can here, I'd rather not majorly
> > refactor things to suit this change if possible.
>
> It doesn't look like a bit refactor, pass vma desc into
> hugetlb_reserve_pages(), lift the vma_lock set out

OK, I'll take a look at refactoring this.

>
> Jason

Cheers, Lorenzo

Reply via email to