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 59D0F3FFAD0 for ; Tue, 31 Mar 2026 21:35:41 +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=1774992941; cv=none; b=pBphaSmAiGRlGqSi04ZZu/Jt9ZfX0hZd0fszJPKTzHJEsoXtDD46HsECk6qhmYD9QvaY1mGNywTNIC7XcVqDDnh0gAGnNB5X+TNH5FGn7luI8PhfMj7suxzpqueNRTr9SD6g+l18EN84t8fH777LEVGaJm3Fhm1xQDk4qjkm4Fg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774992941; c=relaxed/simple; bh=ItF2C7vWxavYeti16KEiOx27zwXUGG1kSH+fSMaNpzQ=; h=Date:From:To:Cc:Subject:Message-Id:In-Reply-To:References: Mime-Version:Content-Type; b=FTOTZVWJkP+CsoudH4AzoaXqR6AALdomt9ZW69qUJO8JZjnlAmZqI7YJdkvUvIZh7RYR6NyM4dFY3yYixzqlAoF9KfArYC0gBEkQ7DyF0/QlfT0CWHR32sJr2Q6jDvvMrriOMrwmDmfuaQnhf1Q6LDGN37nHKehBPpO7ZCmnLXk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b=sJaBUwGi; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b="sJaBUwGi" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4C7C2C19423; Tue, 31 Mar 2026 21:35:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1774992941; bh=ItF2C7vWxavYeti16KEiOx27zwXUGG1kSH+fSMaNpzQ=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=sJaBUwGikN9Norhx8A5uvQMDFYl0Mwp8HvEEwLjLgR0wuVFvcc7ERqkxy5ZlLYsDg 0LCAEdD0oTQbmCPM/6MJpOZ1EnAVOzkvmzSr34CThvn+U01XlYliRQ//lSoiqgZDlT Zofky4ajLoqO68zDBfo8dclRZkoicrnAxBT6bOdE= Date: Tue, 31 Mar 2026 14:35:38 -0700 From: Andrew Morton To: "David Hildenbrand (Arm)" Cc: "Lorenzo Stoakes (Oracle)" , Nico Pache , 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: <20260331143538.f41a5fef4201a7384388f31c@linux-foundation.org> In-Reply-To: <26fcec86-ee78-4f5c-8ca5-0e6230699cfd@kernel.org> References: <20260325114022.444081-1-npache@redhat.com> <20260325114022.444081-6-npache@redhat.com> <7760c811-e100-4d40-9217-0813c28314be@lucifer.local> <0223d45b-e8b4-49a7-882b-477250d0c14d@kernel.org> <26fcec86-ee78-4f5c-8ca5-0e6230699cfd@kernel.org> X-Mailer: Sylpheed 3.8.0beta1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) 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=US-ASCII Content-Transfer-Encoding: 7bit On Tue, 31 Mar 2026 22:00:58 +0200 "David Hildenbrand (Arm)" wrote: > > out_maybelock: > > /* Caller expects us to hold mmap_lock on return */ > > if (mmap_unlocked) { > > *lock_dropped = true; > > mmap_read_lock(mm); > > } > > > > Right. > > The original code used > > bool mmap_locked = true; > > If the fix get squashed, maybe we should revert to that handling to > minimize the churn? > > (this is not in stable, right?) "mm/khugepaged: unify khugepaged and madv_collapse with collapse_single_pmd(): is presently in mm-stable. Doing a big rebase&rework isn't the done thing, I believe. So queue it afterwards, add the Fixes: and tolerate the minor runtime bisection hole. It ends up looking like a later hotfix. Below is what I added to mm-unstable. I added a note-to-self to check in on Nico's question at https://lore.kernel.org/all/CAA1CXcCYLGQBy9nT-MSTPVK=XgWWtD6Af-QiA_6pXtM_2pybPg@mail.gmail.com/T/#u From: "Lorenzo Stoakes (Oracle)" Subject: mm/khugepaged: fix issue with tracking lock Date: Tue, 31 Mar 2026 13:11:18 +0100 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 ... Signed-off-by: Andrew Morton --- mm/khugepaged.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) --- a/mm/khugepaged.c~mm-khugepaged-fix-issue-with-tracking-lock +++ a/mm/khugepaged.c @@ -2828,6 +2828,7 @@ int madvise_collapse(struct vm_area_stru 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_stru 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_stru 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_stru 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); _