From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-170.mta0.migadu.com (out-170.mta0.migadu.com [91.218.175.170]) (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 E6D8E45C70C for ; Tue, 4 Aug 2026 19:25:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.170 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785871546; cv=none; b=OUNNbTYY+wOhJt3Z8caxc2c9A6rOrPTFxhwX/9iEmTM7ahYlaGJo8GIZ8NMVgKBAvObT04Y7Vx+rpPSCR1UrrwJFfSVTplX6VnzaJqIoTdfDhf0r6W0i6sNOLTl/X1sy47Lix5T85IrvaPIcmlE0qFSV4sd+dXaO2MGkH0fIRbw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785871546; c=relaxed/simple; bh=u/GLEjdWkEpmtKnFdrJLD51j/pHZIglCzxJaDFCTPY4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=R8dEIs3kZsp+XXpdXBCfJ3EnaV6gsaNw/DBAo4uTV9a++VR+kDpr2cY+I4rJ1AH/Clhnyw+gefGV1LfvINvmCLFqhLvCgU/uKf86FJEjYdV2yEZbhqtJ5Gp0q0xgD9HBg8bPirOs/mgPCJnYoL273l/bSuHI5lWyQLWIHkh2h14= 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=X69nTRUF; arc=none smtp.client-ip=91.218.175.170 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="X69nTRUF" 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=1785871541; 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=Bk+Ag5nJI+yRxdGaF5AGAZX80rlbQeLkx2hO1upBMEY=; b=X69nTRUFN7jj6tU0Ubf403CSxDuMzgXz+l03s90oUMDMZmK+V24Et9J5ogOrK20R5yccC8 u+ShBM4blOyVVsBjOjP3bWKlOHIG510Z2kTlDYajcNRMEd6SQNKkz6w5y9T4/lzrbuPRnl 66SVtfVx+s6seG8eNX2YK4PYPSQEhdo= From: "Nico Pache (Red Hat)" Date: Tue, 04 Aug 2026 13:25:04 -0600 Subject: [PATCH v3 6/7] mm/khugepaged: unmap pte before releasing vma write lock Precedence: bulk X-Mailing-List: linux-doc@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: <20260804-khugepaged_pte_refactor-v3-6-0364cad642a0@linux.dev> References: <20260804-khugepaged_pte_refactor-v3-0-0364cad642a0@linux.dev> In-Reply-To: <20260804-khugepaged_pte_refactor-v3-0-0364cad642a0@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 068368d27c2f..3338e9dc11dd 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