From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 5752036495E for ; Wed, 8 Apr 2026 06:42:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775630545; cv=none; b=HWqYz4kymnv6ezhxGph6zj4JKM7jezFHQt1KnUwTbGY0wCJZExHHK/wUzqNA5fbx5vVNhEIPh5bYQBeyCE6qT2/RL781iyaA+YwO5O+ccEaW9ziKszEGFOugjgoN9lEh7fmOREE4leIcBKz/NZW5aHfal7dNIfc0wtafLzcOL+c= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775630545; c=relaxed/simple; bh=hew+yMuJllj/CILG+kipSamfxQNTS+u4BKAsnh0Jvxc=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=hCUFq4YD+u5HUTxTPE9qx/8OIQ2mGMcaDi816r2Psf6Lp5gB9xVMOolrvrwnZx7D2LTc18BzpVlBFN7goRCeqfGh3qftsiRpWRnxPNPTLJKGD1rNUdf2UWxMki5G83oiTxLJ2STZ8kD7CFPuTbhTp5WcMNRdCCLuRtIEfepYwvw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=U/KAz5r7; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="U/KAz5r7" Received: by smtp.kernel.org (Postfix) with ESMTPSA id F2242C19424; Wed, 8 Apr 2026 06:42:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1775630544; bh=hew+yMuJllj/CILG+kipSamfxQNTS+u4BKAsnh0Jvxc=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=U/KAz5r784TYMJ5nXnUBiSQNvcv7W83SI2KXHmTgp/Gs7ftNs/tzH0V4nvKfeutOb R51tBfkNTTSjrqaF3xTtyIfveOPMkl9kz0hVus573UjOZ1dYd/ZYeW5EWMwA/jL0nK 91ebpbl6GDCBmjUNLHUtU0LA6IihOr+Xl1NZ5DGJ0jsZUTUhfINNyIFdWv8U/8cBzZ kkZNE0vwrCg/sN67ymN3pAfCux7NVAoKkvnaflxIb+zDsX1Te+Nam2oxE151EBFrCt dDTHQjv6JLWK/78L4wJD80J8aHaa0OXky53/ur5lIYdB+b3Lduwd8Vglq7dKSzEuAH pIP4IbOFvaeEw== Date: Wed, 8 Apr 2026 07:42:10 +0100 From: Lorenzo Stoakes To: Andrew Morton Cc: Nico Pache , "David Hildenbrand (Arm)" , linux-kernel@vger.kernel.org, linux-mm@kvack.org, aarcange@redhat.com, anshuman.khandual@arm.com, apopple@nvidia.com, baohua@kernel.org, baolin.wang@linux.alibaba.com, byungchul@sk.com, catalin.marinas@arm.com, cl@gentwo.org, corbet@lwn.net, dave.hansen@linux.intel.com, dev.jain@arm.com, gourry@gourry.net, hannes@cmpxchg.org, hughd@google.com, jackmanb@google.com, jack@suse.cz, jannh@google.com, jglisse@google.com, joshua.hahnjy@gmail.com, kas@kernel.org, lance.yang@linux.dev, Liam.Howlett@oracle.com, lorenzo.stoakes@oracle.com, mathieu.desnoyers@efficios.com, matthew.brost@intel.com, mhiramat@kernel.org, mhocko@suse.com, peterx@redhat.com, pfalcato@suse.de, rakie.kim@sk.com, raquini@redhat.com, rdunlap@infradead.org, richard.weiyang@gmail.com, rientjes@google.com, rostedt@goodmis.org, rppt@kernel.org, ryan.roberts@arm.com, shivankg@amd.com, sunnanyong@huawei.com, surenb@google.com, thomas.hellstrom@linux.intel.com, tiwai@suse.de, usamaarif642@gmail.com, vbabka@suse.cz, vishal.moola@gmail.com, wangkefeng.wang@huawei.com, will@kernel.org, willy@infradead.org, yang@os.amperecomputing.com, ying.huang@linux.alibaba.com, ziy@nvidia.com, zokeefe@google.com Subject: Re: [PATCH mm-unstable v4 5/5] mm/khugepaged: unify khugepaged and madv_collapse with collapse_single_pmd() Message-ID: References: <26fcec86-ee78-4f5c-8ca5-0e6230699cfd@kernel.org> <440d6b8a-d299-43eb-83b5-6625f9468e5e@lucifer.local> <37132e09-9c03-4afc-bc73-4bca416c5343@kernel.org> <9d5a4703-a15e-4be6-926b-af2d98db40c0@kernel.org> <87b83f7b-f0b1-4184-93a0-3b4b574c813b@lucifer.local> <20260401133145.90b094a7b87bdceb0013b5af@linux-foundation.org> <20260407144259.011a26666eff9c96d74e39a2@linux-foundation.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20260407144259.011a26666eff9c96d74e39a2@linux-foundation.org> On Tue, Apr 07, 2026 at 02:42:59PM -0700, Andrew Morton wrote: > On Tue, 7 Apr 2026 09:38:19 +0100 "Lorenzo Stoakes (Oracle)" wrote: > > > On Wed, Apr 01, 2026 at 01:31:45PM -0700, Andrew Morton wrote: > > > On Wed, 1 Apr 2026 09:14:35 +0100 "Lorenzo Stoakes (Oracle)" wrote: > > > > > > > From: "Lorenzo Stoakes (Oracle)" > > > > Date: Tue, 31 Mar 2026 13:11:18 +0100 > > > > Subject: [PATCH] mm/khugepaged: fix issue with tracking lock > > > > > > > > We are incorrectly treating lock_dropped to track both whether the lock is > > > > currently held and whether or not the lock was ever dropped. > > > > > > > > Update this change to account for this. > > > > > > > > Signed-off-by: Lorenzo Stoakes (Oracle) > > > > > > Not sure if I should add this? > > > > > > Should it have > > > > > > Fixes: 330f3758a3bc ("mm/khugepaged: unify khugepaged and madv_collapse > > > with collapse_single_pmd()")? > > > > (Sorry only just noticed this) > > > > I mean we do need this patch, if you plan to do this as a fix follow up then > > should have a fixed tag, but I do worry about bisection hazard by leaving this > > as-is. > > > > We definitely either need this patch folded in or as a fix that gets sent > > alongside the change. > > I added this to mm-stable a couple of days ago as 5a62019807da > ("mm/khugepaged: fix issue with tracking lock"), below. It does have > the Fixes: so I think we're good. Ack LGTM thanks! Sorry was going through old mail after I realised I didn't know how to use neomutt properly and missed a bunch :) Cheers, Lorenzo > > > commit 5a62019807da4a7add0717c962ac83b23dd12b2c > Author: Lorenzo Stoakes (Oracle) > Date: Tue Mar 31 13:11:18 2026 +0100 > > mm/khugepaged: fix issue with tracking lock > > We are incorrectly treating lock_dropped to track both whether the lock is > currently held and whether or not the lock was ever dropped. > > Update this change to account for this. > > Link: https://lkml.kernel.org/r/7760c811-e100-4d40-9217-0813c28314be@lucifer.local > Fixes: 330f3758a3bc ("mm/khugepaged: unify khugepaged and madv_collapse with collapse_single_pmd()") > Signed-off-by: Lorenzo Stoakes (Oracle) > Reviewed-by: Lance Yang > Reviewed-by: Nico Pache > Cc: Alistair Popple > Cc: Andrea Arcangeli > Cc: Anshuman Khandual > Cc: Baolin Wang > Cc: Barry Song > Cc: Brendan Jackman > Cc: Byungchul Park > Cc: Catalin Marinas > Cc: David Hildenbrand > Cc: David Rientjes > Cc: Dev Jain > Cc: Gregory Price > Cc: "Huang, Ying" > Cc: Hugh Dickins > Cc: Jan Kara > Cc: Jann Horn > Cc: Johannes Weiner > Cc: Jonathan Corbet > Cc: Joshua Hahn > Cc: Kefeng Wang > Cc: Liam Howlett > Cc: "Masami Hiramatsu (Google)" > Cc: Mathieu Desnoyers > Cc: Matthew Brost > Cc: Matthew Wilcox (Oracle) > Cc: Michal Hocko > Cc: Mike Rapoport > Cc: Nanyong Sun > Cc: Pedro Falcato > Cc: Peter Xu > Cc: Rafael Aquini > Cc: Rakie Kim > Cc: Randy Dunlap > Cc: Ryan Roberts > Cc: Shivank Garg > Cc: Steven Rostedt > Cc: Suren Baghdasaryan > Cc: Takashi Iwai (SUSE) > Cc: Thomas Hellström > Cc: Usama Arif > Cc: Vishal Moola (Oracle) > Cc: Vlastimil Babka > Cc: Wei Yang > Cc: Will Deacon > Cc: Yang Shi > Cc: Zach O'Keefe > Cc: Zi Yan > Signed-off-by: Andrew Morton > > diff --git a/mm/khugepaged.c b/mm/khugepaged.c > index d21348b85a59..b8452dbdb043 100644 > --- a/mm/khugepaged.c > +++ b/mm/khugepaged.c > @@ -2828,6 +2828,7 @@ int madvise_collapse(struct vm_area_struct *vma, unsigned long start, > unsigned long hstart, hend, addr; > enum scan_result last_fail = SCAN_FAIL; > int thps = 0; > + bool mmap_unlocked = false; > > BUG_ON(vma->vm_start > start); > BUG_ON(vma->vm_end < end); > @@ -2850,10 +2851,11 @@ int madvise_collapse(struct vm_area_struct *vma, unsigned long start, > for (addr = hstart; addr < hend; addr += HPAGE_PMD_SIZE) { > enum scan_result result = SCAN_FAIL; > > - if (*lock_dropped) { > + if (mmap_unlocked) { > cond_resched(); > mmap_read_lock(mm); > - *lock_dropped = false; > + mmap_unlocked = false; > + *lock_dropped = true; > result = hugepage_vma_revalidate(mm, addr, false, &vma, > cc); > if (result != SCAN_SUCCEED) { > @@ -2864,7 +2866,7 @@ int madvise_collapse(struct vm_area_struct *vma, unsigned long start, > hend = min(hend, vma->vm_end & HPAGE_PMD_MASK); > } > > - result = collapse_single_pmd(addr, vma, lock_dropped, cc); > + result = collapse_single_pmd(addr, vma, &mmap_unlocked, cc); > > switch (result) { > case SCAN_SUCCEED: > @@ -2893,8 +2895,10 @@ int madvise_collapse(struct vm_area_struct *vma, unsigned long start, > > out_maybelock: > /* Caller expects us to hold mmap_lock on return */ > - if (*lock_dropped) > + if (mmap_unlocked) { > + *lock_dropped = true; > mmap_read_lock(mm); > + } > out_nolock: > mmap_assert_locked(mm); > mmdrop(mm); >