From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out30-112.freemail.mail.aliyun.com (out30-112.freemail.mail.aliyun.com [115.124.30.112]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2F034233149 for ; Fri, 16 Jan 2026 01:03:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.112 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768525421; cv=none; b=bjNXjZRcAo3mJtMv2atRbHxKRTLenJ/Yije0vW+iyQQT5mDL5izXCs0F1y6jF7wl9GA+XM5qoV45ySUKEU7NY6Tjlh+Lwbej9FTWn2EjfqkbIfyI5H08VbD2N0bMEhMamzeJXNJ58dJGzQt9yOAl4vBGly/wUtFRG1opplqUluc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768525421; c=relaxed/simple; bh=OUiZWYr/1fnMkJNiTAu3jVXow6dV7Hle824NcaADiCg=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=ZV+sHFiNsC8rsekAHyHBFwJpXSftxYuP/MHQ0NUn6hWTg0kHJlgPzRsk8z89T+K/fBfONtu21dZcscBM1LeuZa9KJp4pWZjchNoc9juW5mA+oBmOheVlXsctFACV1N4E9WDV6nuMVlR1FKe5eEBIKA3PEsO6y93/IuW4262gU0I= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=I5YiJ+zC; arc=none smtp.client-ip=115.124.30.112 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="I5YiJ+zC" DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1768525417; h=Message-ID:Date:MIME-Version:Subject:To:From:Content-Type; bh=0bKL4mnAg97J1S0u6/QixAAbKrjY7AjKN002xrKUlnM=; b=I5YiJ+zC7VpMK4ZyINknVlt53bftjCOKDxp0h/7UWu7/K6j8eWQWOoUU8ph2Csv+aSKo0QX3rWQsZI7Qerf0CaIw3l2TYNpV2jhHh0/zE1eI3Ge6LgDQ7vcrXbi1E+GuQXiRr6ODXJWkMpgEoGXtkoCDwWNnqKvPC3OGzx0mbmQ= Received: from 30.251.17.19(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0Wx8.qXO_1768525413 cluster:ay36) by smtp.aliyun-inc.com; Fri, 16 Jan 2026 09:03:35 +0800 Message-ID: <26cb8bfa-67a7-43d8-b431-a3307df3e559@linux.alibaba.com> Date: Fri, 16 Jan 2026 09:03:33 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v1 1/1] mm/khugepaged: move tlb_remove_table_sync_one out from under PTL To: Lance Yang Cc: ioworker0@gmail.com, lorenzo.stoakes@oracle.com, david@kernel.org, akpm@linux-foundation.org, Liam.Howlett@oracle.com, vbabka@suse.cz, rppt@kernel.org, surenb@google.com, mhocko@suse.com, ziy@nvidia.com, npache@redhat.com, ryan.roberts@arm.com, dev.jain@arm.com, baohua@kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, "hughd@google.com" References: <20260115071651.42626-1-lance.yang@linux.dev> <0bc3807e-2c1b-43af-9aab-665ce30d49d4@linux.alibaba.com> <8754b56d-b9a8-4b94-b5bc-982384234527@linux.dev> From: Baolin Wang In-Reply-To: <8754b56d-b9a8-4b94-b5bc-982384234527@linux.dev> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 1/15/26 8:28 PM, Lance Yang wrote: > > > On 2026/1/15 18:00, Baolin Wang wrote: >> Hi Lance, >> >> On 1/15/26 3:16 PM, Lance Yang wrote: >>> From: Lance Yang >>> >>> tlb_remove_table_sync_one() sends IPIs to all CPUs and waits for them, >>> which we really don't want to do while holding PTL. >> >> Could you add more comments to explain why this is safe for the PAE case? > > Yep, IIUC, it is safe because we've already done pmdp_collapse_flush() > which ensures the PMD change is visible. > > pmdp_get_lockless_sync() (which calls tlb_remove_table_sync_one() on PAE) > is just to ensure any ongoing lockless pmd readers (e.g., GUP-fast) > complete > before we proceed. It sends IPIs to all CPUs and waits for responses - a > CPU > can only respond when it's not between local_irq_save() and > local_irq_restore(). > > Moving it out from under PTL doesn't change the synchronization semantics, > since lockless readers don't depend on PTL anyway. Cc Hugh who introduced the pmdp_get_lockless_sync(), to double check. Sounds reasonable to me, please add these comments into the commit message. Thanks. >> For the non-PAE case, you added a new tlb_remove_table_sync_one(), why >> we need this (to solve what problem)? Please also add more comments to >> explain. > > Oops, you're right, the original macro was a no-op for non-PAE. > > I should just move the macro call out from under PTL, rather than > replacing it with direct tlb_remove_table_sync_one() calls. OK. >>> Just move the call to after we release PTL, and drop the macro wrapper >>> while we're at it. >>> >>> Signed-off-by: Lance Yang >>> --- >>>   include/linux/pgtable.h | 4 ---- >>>   mm/khugepaged.c         | 5 +++-- >>>   2 files changed, 3 insertions(+), 6 deletions(-) >>> >>> diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h >>> index eb8aacba3698..fb04ed22052c 100644 >>> --- a/include/linux/pgtable.h >>> +++ b/include/linux/pgtable.h >>> @@ -755,7 +755,6 @@ static inline pmd_t pmdp_get_lockless(pmd_t *pmdp) >>>       return pmd; >>>   } >>>   #define pmdp_get_lockless pmdp_get_lockless >>> -#define pmdp_get_lockless_sync() tlb_remove_table_sync_one() >>>   #endif /* CONFIG_PGTABLE_LEVELS > 2 */ >>>   #endif /* CONFIG_GUP_GET_PXX_LOW_HIGH */ >>> @@ -774,9 +773,6 @@ static inline pmd_t pmdp_get_lockless(pmd_t *pmdp) >>>   { >>>       return pmdp_get(pmdp); >>>   } >>> -static inline void pmdp_get_lockless_sync(void) >>> -{ >>> -} >>>   #endif >>>   #ifdef CONFIG_TRANSPARENT_HUGEPAGE >>> diff --git a/mm/khugepaged.c b/mm/khugepaged.c >>> index 9f790ec34400..0a6cebf880e0 100644 >>> --- a/mm/khugepaged.c >>> +++ b/mm/khugepaged.c >>> @@ -1664,10 +1664,10 @@ static enum scan_result >>> try_collapse_pte_mapped_thp(struct mm_struct *mm, unsign >>>           } >>>       } >>>       pgt_pmd = pmdp_collapse_flush(vma, haddr, pmd); >>> -    pmdp_get_lockless_sync(); >>>       pte_unmap_unlock(start_pte, ptl); >>>       if (ptl != pml) >>>           spin_unlock(pml); >>> +    tlb_remove_table_sync_one(); >>>       mmu_notifier_invalidate_range_end(&range); >>> @@ -1818,7 +1818,6 @@ static void retract_page_tables(struct >>> address_space *mapping, pgoff_t pgoff) >>>            */ >>>           if (likely(file_backed_vma_is_retractable(vma))) { >>>               pgt_pmd = pmdp_collapse_flush(vma, addr, pmd); >>> -            pmdp_get_lockless_sync(); >>>               success = true; >>>           } >>> @@ -1826,6 +1825,8 @@ static void retract_page_tables(struct >>> address_space *mapping, pgoff_t pgoff) >>>               spin_unlock(ptl); >>>   drop_pml: >>>           spin_unlock(pml); >>> +        if (success) >>> +            tlb_remove_table_sync_one(); >>>           mmu_notifier_invalidate_range_end(&range); >>