From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-185.mta1.migadu.com (out-185.mta1.migadu.com [95.215.58.185]) (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 CBF2F3F9F3B for ; Tue, 11 Aug 2026 12:49:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.185 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786452582; cv=none; b=Mi//Bl3q4XNjelY9hLOXPqziAuNC+30oLMQqlQGk/ONrZYedSdCzuu/G/+4+RkKcvKWTbhEz2SaYHEK3gVtKZ4Cq45njfPrt5jd7p/yvvdYrx/KgIHzTcDq0aT1tfvhLtP/5rq3BojgHc/7SrZW1XF5EyjQtw8tYmBtTQcMar6I= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786452582; c=relaxed/simple; bh=eIQfMiB1l0ur7E1BRaspNgQ9yrlBZ8ATHM0KAcZEzDw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Agv4HDQQW5LhcX1l6a8hApKvdk1UNxMLKBVGHNEnxOZEZYeVtjvvu4zuWmyJKzTugUgXTX5MuwDSh+jaoEDYEmRZgQ6Z2VEqql0A6465v+AW6cHM8idNeb9jOCjywkQwKiKOvE3oCtk9a1x5BtZGEzB/7T73GiJtQZaQH4eOCms= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=lWAWFvri; arc=none smtp.client-ip=95.215.58.185 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="lWAWFvri" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1786452578; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XVQSZpjAJnAABJI67TTQSmMP8vAAvmycYzDtMVPpcHY=; b=lWAWFvriFfl0cp/ibyF02UZQtwwi8SZU78mlgDkb5+DPPrtWhX1LpqJOka7Ib1yAOuzW9c vWAxwBpWMF2uFziE+mhQS2TyRonP9r4qfGbpZjaHLIOgeK8UyrqjYcxktVSHxmWakzBggR dnvIh6NXuT5Lmo8vmyGzLtnZgMuTQys= From: "Nico Pache (Red Hat)" Date: Tue, 11 Aug 2026 06:48:38 -0600 Subject: [PATCH v4 6/7] mm/khugepaged: unmap pte before releasing vma write lock 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="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260811-khugepaged_pte_refactor-v4-6-ddac39d61c4a@linux.dev> References: <20260811-khugepaged_pte_refactor-v4-0-ddac39d61c4a@linux.dev> In-Reply-To: <20260811-khugepaged_pte_refactor-v4-0-ddac39d61c4a@linux.dev> To: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org Cc: Andrew Morton , David Hildenbrand , Lorenzo Stoakes , Zi Yan , Baolin Wang , "Liam R. Howlett" , Ryan Roberts , Dev Jain , Barry Song , Lance Yang , Usama Arif , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Jonathan Corbet , Shuah Khan , "Nico Pache (Red Hat)" X-Migadu-Flow: FLOW_OUT We are currently dropping the anon_vma write lock before unmapping the PTE. Although this is safe, due to us still holding the mmap_write_lock, its safer and less confusing to switch the order of these two operations. Suggested-by: David Hildenbrand Acked-by: David Hildenbrand (Arm) Signed-off-by: Nico Pache (Red Hat) --- mm/khugepaged.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mm/khugepaged.c b/mm/khugepaged.c index b7372aba4417..0ba637df9c48 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -1546,10 +1546,10 @@ static enum scan_result collapse_huge_page(struct mm_struct *mm, unsigned long s result = SCAN_SUCCEED; out_up_write: - if (anon_vma_locked) - anon_vma_unlock_write(vma->anon_vma); if (pte) pte_unmap(pte); + if (anon_vma_locked) + anon_vma_unlock_write(vma->anon_vma); mmap_write_unlock(mm); out_nolock: if (folio) -- 2.55.0