mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Rik van Riel <riel@surriel.com>
To: Mike Kravetz <mike.kravetz@oracle.com>
Cc: linux-kernel@vger.kernel.org, kernel-team@meta.com,
	linux-mm@kvack.org, akpm@linux-foundation.org,
	muchun.song@linux.dev, leit@meta.com, willy@infradead.org,
	stable@kernel.org
Subject: Re: [PATCH 2/3] hugetlbfs: close race between MADV_DONTNEED and page fault
Date: Thu, 05 Oct 2023 09:23:05 -0400	[thread overview]
Message-ID: <99b67e2408c260f53958e98226449fd2bb6a58d8.camel@surriel.com> (raw)
In-Reply-To: <20231005031959.GA13437@monkey>

On Wed, 2023-10-04 at 20:19 -0700, Mike Kravetz wrote:
> On 10/03/23 23:25, riel@surriel.com wrote:
> > 
> > @@ -5457,11 +5460,12 @@ void __unmap_hugepage_range_final(struct
> > mmu_gather *tlb,
> >                  * someone else.
> >                  */
> >                 __hugetlb_vma_unlock_write_free(vma);
> > -               i_mmap_unlock_write(vma->vm_file->f_mapping);
> >         } else {
> > -               i_mmap_unlock_write(vma->vm_file->f_mapping);
> >                 hugetlb_vma_unlock_write(vma);
> >         }
> > +
> > +       if (vma->vm_file)
> > +               i_mmap_unlock_write(vma->vm_file->f_mapping);
> >  }
> 
> In the case of a mmap(hugetlbfs_file_mmap) error, the per-vma hugetlb
> lock will not be setup.  The hugetlb_vma_lock/unlock routines do not
> check for this as they were previously always called after the lock
> was
> set up.  So, we can now get:

Wait, the hugetlb_vma_(un)lock_{read,write} functions do
have checks for the presence of the lock:

void hugetlb_vma_lock_read(struct vm_area_struct *vma)
{
        if (__vma_shareable_lock(vma)) {
                struct hugetlb_vma_lock *vma_lock = vma-
>vm_private_data;

                down_read(&vma_lock->rw_sema);
        } else if (__vma_private_lock(vma)) {
                struct resv_map *resv_map = vma_resv_map(vma);

                down_read(&resv_map->rw_sema);
        }
}

Both __vma_shareable_lock and __vma_private_lock check that
vma->vm_private_data points at something.

Exactly what corner case am I missing here?

What leaves vma->vm_private_data pointing at something
invalid?

> 
> +++ b/mm/hugetlb.c
> @@ -5503,10 +5503,12 @@ void __unmap_hugepage_range(struct mmu_gather
> *tlb, struct vm_area_struct *vma,
>  void __hugetlb_zap_begin(struct vm_area_struct *vma,
>                          unsigned long *start, unsigned long *end)
>  {
> +       if (!vma->vm_file)      /* hugetlbfs_file_mmap error */
> +               return;
> +

This does not seem quite correct, because the locking is needed to
avoid the race between MADV_DONTNEED and the page fault path.


> Another way to resolve would be to fix up the hugetlb_vma_lock/unlock
> routines
> to check for and handle a null lock.

I thought I had that already. 

Does __vma_shareable_lock need to check for !vma->vm_file ?

-- 
All Rights Reversed.

  reply	other threads:[~2023-10-05 14:43 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-04  3:25 [PATCH v6 0/3] " riel
2023-10-04  3:25 ` [PATCH 1/3] hugetlbfs: extend hugetlb_vma_lock to private VMAs riel
2023-10-04  3:25 ` [PATCH 2/3] hugetlbfs: close race between MADV_DONTNEED and page fault riel
2023-10-05  3:19   ` Mike Kravetz
2023-10-05 13:23     ` Rik van Riel [this message]
2023-10-05 22:59       ` Mike Kravetz
2023-10-04  3:25 ` [PATCH 3/3] hugetlbfs: replace hugetlb_vma_lock with invalidate_lock riel
2023-10-06  0:19   ` Mike Kravetz
2023-10-06  3:28     ` Rik van Riel
  -- strict thread matches above, loose matches on Subject: below --
2023-10-01  0:55 [PATCH v5 0/3] hugetlbfs: close race between MADV_DONTNEED and page fault riel
2023-10-01  0:55 ` [PATCH 2/3] " riel
2023-10-02  4:39   ` Mike Kravetz
2023-10-02 13:13     ` Rik van Riel
2023-10-03 19:35     ` Rik van Riel
2023-10-03 20:19       ` Mike Kravetz
2023-10-04  0:20         ` Rik van Riel
2023-09-26  3:10 [PATCH v4 0/3] " riel
2023-09-26  3:10 ` [PATCH 2/3] " riel
2023-09-26 21:15   ` Andrew Morton
2023-09-26 23:57     ` Rik van Riel
2023-09-25 20:28 [PATCH v3 0/3] " riel
2023-09-25 20:28 ` [PATCH 2/3] " riel
2023-09-25 22:25   ` Mike Kravetz
2023-09-26  0:46     ` Rik van Riel
2023-09-22 19:02 [PATCH v2 0/3] " riel
2023-09-22 19:02 ` [PATCH 2/3] " riel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=99b67e2408c260f53958e98226449fd2bb6a58d8.camel@surriel.com \
    --to=riel@surriel.com \
    --cc=akpm@linux-foundation.org \
    --cc=kernel-team@meta.com \
    --cc=leit@meta.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mike.kravetz@oracle.com \
    --cc=muchun.song@linux.dev \
    --cc=stable@kernel.org \
    --cc=willy@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®