lkml.org 
[lkml]   [2022]   [Sep]   [8]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [RFC PATCH 07/26] hugetlb: add hugetlb_pte to track HugeTLB page table entries
James,

On Fri, Jun 24, 2022 at 05:36:37PM +0000, James Houghton wrote:
> +static inline
> +spinlock_t *hugetlb_pte_lockptr(struct mm_struct *mm, struct hugetlb_pte *hpte)
> +{
> +
> + BUG_ON(!hpte->ptep);
> + // Only use huge_pte_lockptr if we are at leaf-level. Otherwise use
> + // the regular page table lock.
> + if (hugetlb_pte_none(hpte) || hugetlb_pte_present_leaf(hpte))
> + return huge_pte_lockptr(hugetlb_pte_shift(hpte),
> + mm, hpte->ptep);
> + return &mm->page_table_lock;
> +}

Today when I re-read part of this thread, I found that I'm not sure whether
this is safe. IIUC taking different locks depending on the state of pte
may lead to issues.

For example, could below race happen where two threads can be taking
different locks even if stumbled over the same pmd entry?

thread 1 thread 2
-------- --------

hugetlb_pte_lockptr (for pmd level)
pte_none()==true,
take pmd lock
pmd_alloc()
hugetlb_pte_lockptr (for pmd level)
pte is pgtable entry (so !none, !present_leaf)
take page_table_lock
(can run concurrently with thread 1...)
pte_alloc()
...

--
Peter Xu

\
 
 \ /
  Last update: 2022-09-08 19:40    [W:0.537 / U:0.168 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site