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 C13143CBE9D for ; Tue, 31 Mar 2026 20:06:43 +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=1774987603; cv=none; b=fXkv/AHZQH9HjEMvp8v3+Dkl5zDejKD9EBQrL4z4P0WoMi3KVZSAjVhmhnIJGWhfSno++oErQJJdpGeoZ24u8uGybR+lvgleWTc7b2pBaiYqQ+cW7C2e04SLx8s6HsneT6M0DNWnlMiDQ6s62FBytSIAzlyOJhYbku3KQMeDEP4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774987603; c=relaxed/simple; bh=KabC0Or5uXagKoB0Q8zePzNEvjLSg6+mr+qSUuEcW9M=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=as5vDOhtjD2khsk5inKBKip7SHV8zBDGxR1jZk8xE+75bFoH9amDilRT1hMm2SJ733nor20fjxQ53982mmyl258YByyORzZwCqGU1ZWFRVQFFjsjB761frANb7llxf88akpSwjF4qfHfwwoJ7tUGGw1AgTTUimX05WmuSmr7YqI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=GkDOVQGi; 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="GkDOVQGi" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 911C6C2BCB0; Tue, 31 Mar 2026 20:06:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1774987603; bh=KabC0Or5uXagKoB0Q8zePzNEvjLSg6+mr+qSUuEcW9M=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=GkDOVQGijiYAfBZ5fT2rU6iC7mMAnJF3Zg3lk1KrOMYnGUQTpiLp1pq6d3jHY9B7M ky/yN5Ky10qZVy68U98IDwjnlIClc8iwGBHIfrJ+b9XGUrE0bQDspTML5gdDm7Hs5T LOdelE40N+ln0/eh5sq3RfiUz6UGtfEp/kLV/8pP7HwXpWmVj54KXHzf+03HcfXHSa gV2YOIKV0S7/itS3irmnD32F8P4VNxgsug8YiS1R3NPov/aoLN7JCrU0AXfSgubkVZ D28OqAdbTskExpirD5MRyG3NZDC8cYvq5ARxMXYKkAU+mGJS7/l90ISH/zzZk5RU36 gYBUWcRi3aD5g== Date: Tue, 31 Mar 2026 21:06:30 +0100 From: "Lorenzo Stoakes (Oracle)" To: "David Hildenbrand (Arm)" Cc: Nico Pache , linux-kernel@vger.kernel.org, linux-mm@kvack.org, aarcange@redhat.com, akpm@linux-foundation.org, 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: <440d6b8a-d299-43eb-83b5-6625f9468e5e@lucifer.local> 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> 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-Disposition: inline In-Reply-To: <26fcec86-ee78-4f5c-8ca5-0e6230699cfd@kernel.org> On Tue, Mar 31, 2026 at 10:00:58PM +0200, David Hildenbrand (Arm) wrote: > On 3/31/26 16:15, Lorenzo Stoakes (Oracle) wrote: > > On Tue, Mar 31, 2026 at 04:13:29PM +0200, David Hildenbrand (Arm) wrote: > >>> > >>> So this is the bug. 'lock_dropped' needs to record if the lock was _ever_ > >>> dropped, not if it is _currently_ dropped. > >> > >> Ah, well spotted. I thought we discussed that at some point during > >> review ... > >> > >> Thanks for tackling this! > >> > >> [...] > >> > >>> > >>> ----8<---- > >>> From a4dfc7718a15035449f344a0bc7f58e449366405 Mon Sep 17 00:00:00 2001 > >>> 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) > >>> --- > >>> mm/khugepaged.c | 12 ++++++++---- > >>> 1 file changed, 8 insertions(+), 4 deletions(-) > >>> > >>> 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, > >> > >> (in hurry so I might be wrong) > >> > >> Do we have to handle when collapse_single_pmd() dropped the lock as well? > > > > That updates mmap_unlocked which will be handled in the loop or on exit: > > > > if (mmap_unlocked) { > > ... > > mmap_read_lock(mm); > > mmap_unlocked = false; > > *lock_dropped = true; > > ... > > } > > > > result = collapse_single_pmd(addr, vma, &mmap_unlocked, cc); > > > > ... > > > > 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? Well collapse_single_pmd() and all descendents would need to be updated to invert the boolean, not sure it's worth it. > > (this is not in stable, right?) > > -- > Cheers, > > David