From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=115.124.30.118 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793606272; b=Hgj0Owdh8UmxL7H2S9Oem2zUQ5n802hVCIoF6wqEYPDdwZxpQm5reIdG3yKFYZb6Sb2j 9ce8B4QAQBnQ7KPdepi5hriTCpQMg8OTF8uppfzAmg3ELSLhw95+9/tbfsnRYtIjT/O7K wjuMnvT7LQi7gARKAeUe2gAnhAMxiWF1rmExRrwS6Z4gzSV/iMvlMTs5rGy480KtKyuTA j1Gb2WnzNvSrPR6TfK+CSSlMtOkHmPq+S6/svQCnoVPMiWNCnR5oTwmpeIJnS3ggRwpXj 7A6cuVzkI/48hK9QL+g36JEI1LzcnpIi3sbQiBpVSKgdEANUWm87f7LqBdy8EoIioYw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793606272; 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=urqOGiWM43pGOIAX+SQ1xyGmHp8O9dptxy/AFX4SmjE=; b=flA+8bOhMPic+HDQ0sxyYkRj99aa7eaQ9KdP0EelVoiQnW9/kLJQBMZ0SvZygjOhT+Rj jpO4gL2FBybnj1DNio6VESlppaa50frdl/6IMep3noaRJRBv6mQclmW/wh3uJhORHfRzs CKE23ckUrlwVrdbCGmPYB4tnl3ME1bko47kY76DQ630pE3/fMU9RStH+fxSZ9B042ve7C loaPPFgt8Y04W5YMNqcSBsbyuUeqER+kYuJ5xJ0BzU2LugpXOeNZUNqLdO3JlYogKFrso a1MBxpbrobOTUYTWJFDsC9tynSqt4hTH5senx+aGVdOFqOlFnMeLA288sjs+uX2/UpA== 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=QNmcN+WB; arc=none smtp.remote-ip=115.124.30.118 Received: from out30-118.freemail.mail.aliyun.com (out30-118.freemail.mail.aliyun.com [115.124.30.118]) (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 5AD12606A324; Mon, 2 Nov 2026 07:57:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 5AD12606A324 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=QNmcN+WB DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1793606258; h=Message-ID:Date:MIME-Version:Subject:To:From:Content-Type; bh=urqOGiWM43pGOIAX+SQ1xyGmHp8O9dptxy/AFX4SmjE=; b=QNmcN+WBRZO7d5z8MvNlnvhmVN7NqAxSk2D2D4Y3jNYOq+EIfCvmBjT4kgXikK7Vxs1nNmtg07oso4sGjzg3+NUtjwQ9I60DPgA+15+lJ/I52Uw+UuLrxvzMs+wdVMJlcgpyUjVA+26G5CnsmCeN1cBpZHlMtIzVubs60o14UOI= X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R291e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033045133197;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=66;SR=0;TI=SMTPD_---0XDwJ4wk_1793606252; Received: from 30.74.144.167(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0XDwJ4wk_1793606252 cluster:ay36) by smtp.aliyun-inc.com; Mon, 02 Nov 2026 15:57:34 +0800 Message-ID: <902b1dd5-f002-4ba8-b6d7-6bf59d07f1d7@linux.alibaba.com> Date: Mon, 2 Nov 2026 15:57:32 +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 13/47] mm/huge_memory: fix truncate racing with PMD zapping 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, Chris Mason , stable@vger.kernel.org, Muhammad Usama Anjum References: <20261031-fixes_core-v3-0-d6437171ecc3@kernel.org> <20261031-fixes_core-v3-13-d6437171ecc3@kernel.org> From: Baolin Wang In-Reply-To: <20261031-fixes_core-v3-13-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: Chris Mason > > zap_huge_pmd_folio() removes the rmap before calling folio_mark_dirty(). > If this was the last mapping, truncation can skip unmapping the folio > and proceed without waiting for the PMD lock, racing with dirtying. > > ifs_set_range_dirty() can oops if MADV_DONTNEED races with > ftruncate() on XFS, when we get the folio set dirty after it was found > to not be mapped anymore. > > Move folio_mark_dirty() and folio_mark_accessed() before rmap removal, > matching the PTE zap path. This keeps the folio mapped while updating > its state, so truncation must wait for the page table lock. > > Fix generated by an LLM and sent by Chris Mason in private. > > Fixes: fe6cf984939d ("mm/huge_memory: transfer the pmd dirty bit to the folio on zap") > Cc: stable@vger.kernel.org > Signed-off-by: Chris Mason > [ david: simplify comment and description ] > Reviewed-by: Gregory Price (Meta) > Tested-by: Muhammad Usama Anjum > Signed-off-by: David Hildenbrand (Arm) > --- I checked the memory ordering issues, and it looks like the implicit barriers provided by the fully ordered atomic operations already ensure the required ordering. So LGTM. Reviewed-by: Baolin Wang