Re: [PATCH] hugetlbfs: remove call to huge_pte_alloc without i_mmap_rwsem
From: Mike Kravetz
Date: Mon Aug 03 2020 - 22:03:51 EST
On 8/3/20 4:00 PM, Mike Kravetz wrote:
> On 8/3/20 3:52 PM, Matthew Wilcox wrote:
>> On Mon, Aug 03, 2020 at 03:43:35PM -0700, Mike Kravetz wrote:
>>> Commit c0d0381ade79 ("hugetlbfs: use i_mmap_rwsem for more pmd sharing
>>> synchronization") requires callers of huge_pte_alloc to hold i_mmap_rwsem
>>> in at least read mode. This is because the explicit locking in
>>> huge_pmd_share (called by huge_pte_alloc) was removed. When restructuring
>>> the code, the call to huge_pte_alloc in the else block at the beginning
>>> of hugetlb_fault was missed.
>>
>> Should we have a call to mmap_assert_locked() in huge_pte_alloc(),
>> at least the generic one?
>
> That is the wrong semaphore.
>
> However, I was not aware of the checks for a semaphore being held as is
> done in rwsem_is_locked(). That would have caught this when the original
> code was changed. Thanks for pointing this out.
>
> Let me update the patch and add checks to huge_pmd_share().
Here is an updated version.
I added routines to assert that i_mmap_rwsem is held as required. This
requires changing the parameters passed to huge_pmd_unshare. Verified
that the problematic call to huge_pte_alloc (that this patch also removes)
will generate WARNINGs.
Not sure if the fix should be separated from the verification code for
sending to stable?