From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=115.124.30.131 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793603663; b=DOVNIAUq5T2r1yjtk3C+lMyjeFeKyOFJiy961oMIDt6DvO7SUtWXDKCt1A+Hxrjrn6cP /qJutttgxp3o5e1edYC2PSk0uJJDwu6YGGY5kBgrHL7xson8C5/CgI5D/zyGXFigrHRWF 3PWArv7YJ11jdu9hKZZWfk/eJ8Rzk06nzuzeGlqzi2NggVpFhtGQGMgR5msFHLQ2bPH9i 9IVzGyYaPYPGXhXx1qRnlnJPtTBz5CfRyrYmRab9lhMSzk4h8r14kmlux6OSSITIu5uhi ka7Abelj7vZI4OCuU2psEb84duzEv4VwIuF42KwLSRZ54mpLDyj7GBCQGICDIeVfVPA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793603663; h=DMARC-Filter:DKIM-Signature:X-Alimail-AntiSpam:Received:Message-ID: Date:MIME-Version:User-Agent:Subject:To:Cc:References:From: In-Reply-To:Content-Type:Content-Transfer-Encoding; bh=Qm2rnyse/ykhHOoe09sGuMes6K54FQWZVf+H4ljHjfM=; b=fWIVBwqaYMytQ7U2CtG1rjw17GeRXTV/o1GlTsHIRb1BRIOHWTSily2oUMVDk17OhEza D7a7mOnYJ0dO75uPz00k3/SASnW69ERwBiztsGJrQATGciKe2zxUfBcbSvRpTw+HXfBCm C8bclzmNxRPkRg/6t13Dvk0Y/RgzVBhe3boE5n2tyK8PalzZ3pBUpyeO3SFF+qyAqzqEN WGu9VAVCTZDeCp5a43hfLVaCBDXKCm+s1vKP/lVXLKDiqaXrWqSiPi8z2QEE3qkRVyuwZ MzrEZiA96LGr72tsAJGzNVFaqzqI/5DZEcfuwxupiBucar8FSuUiiYVvauUsg/uNJ3w== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass header.d=linux.alibaba.com header.i=@linux.alibaba.com header.a=rsa-sha256 header.s=default header.b=pZZwpvVO; arc=none smtp.remote-ip=115.124.30.131 Received: from out30-131.freemail.mail.aliyun.com (out30-131.freemail.mail.aliyun.com [115.124.30.131]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 907D7606A326; Mon, 2 Nov 2026 07:14:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 907D7606A326 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.a=rsa-sha256 header.s=default header.b=pZZwpvVO DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1793603653; h=Message-ID:Date:MIME-Version:Subject:To:From:Content-Type; bh=Qm2rnyse/ykhHOoe09sGuMes6K54FQWZVf+H4ljHjfM=; b=pZZwpvVOA+uj8Hey3gxKpg914FcxtBCprAFnla7zr3dyAQUuxzoqHrpe26MhbQDCNPM8yoFXpIDWMoyD7pMs/tnTGW5+AV+MRJF7a5OSZwLpbbcuoyBfN66Z17SkJJv5tFYMy0aVFPpkwNEqiU3RWweXPl9HVpCG0EckPfQji5U= X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R101e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033037009110;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=66;SR=0;TI=SMTPD_---0XDv-BWP_1793603647; Received: from 30.74.144.167(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0XDv-BWP_1793603647 cluster:ay36) by smtp.aliyun-inc.com; Mon, 02 Nov 2026 15:14:09 +0800 Message-ID: <72c3964c-1355-4272-b61c-5767f5591f43@linux.alibaba.com> Date: Mon, 2 Nov 2026 15:14:06 +0800 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v3 16/47] mm/khugepaged: fix PMD table lock leak in try_collapse_pte_mapped_thp() To: "David Hildenbrand (Arm)" , Andrew Morton , Johannes Weiner , Michal Hocko , Qi Zheng , Shakeel Butt , Lorenzo Stoakes , Kairui Song , Barry Song , Axel Rasmussen , Yuanchu Xie , Wei Xu , Baoquan He , "Liam R. Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Kees Cook , Peter Zijlstra , Jann Horn , Pedro Falcato , Hugh Dickins , Pasha Tatashin , Pratyush Yadav , "Matthew Wilcox (Oracle)" , Jan Kara , Zi Yan , Lance Yang , Rik van Riel , Harry Yoo , Alistair Popple , Nico Pache , Ryan Roberts , Dev Jain , Usama Arif , Kiryl Shutsemau , Matthew Brost , John Hubbard , Peter Xu , Will Deacon , "Aneesh Kumar K.V" , Nick Piggin , Oscar Salvador , Minchan Kim , Muchun Song , Xu Xin , Chengming Zhou , Chris Li , Kemeng Shi , Nhat Pham , Youngjun Park , Gregory Price , Joshua Hahn , Rakie Kim , Ying Huang , Jason Gunthorpe Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, kexec@lists.infradead.org, linux-fsdevel@vger.kernel.org, linux-arch@vger.kernel.org, linux-cxl@vger.kernel.org, Josef Bacik , stable@vger.kernel.org, Muhammad Usama Anjum References: <20261031-fixes_core-v3-0-d6437171ecc3@kernel.org> <20261031-fixes_core-v3-16-d6437171ecc3@kernel.org> From: Baolin Wang In-Reply-To: <20261031-fixes_core-v3-16-d6437171ecc3@kernel.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 10/31/26 5:39 PM, David Hildenbrand (Arm) wrote: > From: Josef Bacik > > For a private mapping with userfaultfd, try_collapse_pte_mapped_thp() > takes the PMD table lock before it maps the page table for the second time. > If that (pte_offset_map_rw_nolock) fails, because the page table vanished > in the meantime due to concurrent page table reclaim, it leaves through > the abort label, where the PMD table lock is unlocked if it differs from > PTE table lock. > > In case the PMD table lock and the PTE table lock match, which is the > case without CONFIG_SPLIT_PTE_PTLOCKS after pte_offset_map_rw_nolock() > failed, we miss to unlock the PMD table. > > To fix it, forget the PTE table lock when we unmap+unlock the PTE table. > > Fix generated by an LLM and sent by Josef Bacik in private. > > Fixes: 6375e95f381e ("mm: pgtable: reclaim empty PTE page in madvise(MADV_DONTNEED)") > Cc: stable@vger.kernel.org > Signed-off-by: Josef Bacik > [ david: move the ptl = NULL handling; rewrite description, drop wrong comments ] > Reviewed-by: Gregory Price (Meta) > Tested-by: Gregory Price (Meta) > Tested-by: Muhammad Usama Anjum > Signed-off-by: David Hildenbrand (Arm) > --- LGTM. Reviewed-by: Baolin Wang