From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 759122C0F6D for ; Thu, 11 Jun 2026 07:52:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781164344; cv=none; b=ho9OKpvmrKfC7KesoARMtveulvsXX5kutjiJyf9Yrf5ihLR9P4DZvJs801roByjWMzhms53yPa/TGq0eXCbFIZVUKPcQ5q5pwFmPPhqn845anen940NxOJ0ComNPVPvC6fpTchNzC2TQ/SLhugPAHx9dp3e2qnDspJyNZTR80ZU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781164344; c=relaxed/simple; bh=l6dablLA2nFJPmqUIFH/25myl3oxiXhYLno3e74FR1s=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=mL2zDLADQEezy2TbdwHWT5IY2JKcSBm7x68sSCAiRY7K7nT3aRhCT5P4kdi5bIlfLtPs+WqE2ub1dWMLzhstsslKDBX7jcSxJzpDWkyDyvesRMj1CvZjI8qWvCzB1JiWos+oEGleEGBpRYsbH2l4tsEBjf6lGFKCieVVoQN4QcE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Pw7BVdtV; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Pw7BVdtV" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1B0901F00893; Thu, 11 Jun 2026 07:52:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1781164343; bh=Gy0fOwvIMH4EuNtEbs497c1jGFk+9kN0Zl6QDcA1oSs=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=Pw7BVdtV9nJb2vVo/Ix5ymbdE6e+nicMi2ufCJNiA6K1Lue934jVv9/5L8lXkcO0m 2UBvFQES+wq6L24tK2B59XMB8NPE9Fpx92KlDOqnfP6eUzBgFMOjwhNJCfYg+ejkMY LGBCMRYQhGSjGjFGfGtR2O5QCR5vFGisu7Vr71TDIG/m8Bnokjel7ReskvLrSndeOw B3MFG3DYMPrp+AoIyEt1yCYUIOlR/A2AH20Z8s/Y52h+lqPnZVzDuce3w4Tb/QbS7j 29GwXAaBqo/L542gTyeNxfXiqdQKZTpr6+GGPCbYrxbdC6w+buZi3wsWl8sYUg6U1W NDPm3lVE1z5IQ== Date: Thu, 11 Jun 2026 09:52:14 +0200 From: "Oscar Salvador (SUSE)" To: Kaitao Cheng Cc: Andrew Morton , Vlastimil Babka , Suren Baghdasaryan , Michal Hocko , Brendan Jackman , Johannes Weiner , Zi Yan , Liu Shixin , David Hildenbrand , Oscar Salvador , muchun.song@linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Kaitao Cheng Subject: Re: [PATCH v2] mm: page_isolation: avoid unsafe folio reads while scanning compound pages Message-ID: References: <20260602130755.38794-1-kaitao.cheng@linux.dev> 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: <20260602130755.38794-1-kaitao.cheng@linux.dev> On Tue, Jun 02, 2026 at 09:07:55PM +0800, Kaitao Cheng wrote: > From: Kaitao Cheng > > page_is_unmovable() can inspect compound pages without holding a folio > reference or any lock. The folio can therefore be freed, split or reused > while the scanner is still looking at it. > > The existing HugeTLB handling already avoids folio_hstate() for this > reason, but it still derives the hstate from folio_size() and later > derives the scan step from folio_nr_pages() and folio_page_idx(). > These helpers rely on the folio still being a valid folio head. If > the folio changed concurrently, the scanner can read inconsistent folio > metadata and compute a wrong step. In the worst case, folio_nr_pages() > can return 1 for what used to be a tail page and the subtraction from > folio_page_idx() can underflow. > > There is a similar issue for non-Hugetlb compound pages: folio_test_lru() > expects a valid folio. If the previously observed head page has been > reused as a tail page of another compound page, the folio flag checks > can trigger VM_BUG_ON_PGFLAGS(). > > Read the compound order once with compound_order(), reject obviously > bogus orders, and derive the hstate and scan step from that order > instead of querying folio size information again. Also use PageLRU(page), > which is safe for the page being scanned, instead of folio_test_lru() > on a potentially stale folio pointer. > > Treat an unknown HugeTLB hstate as unmovable so the scanner does not try > to skip over an unstable HugeTLB folio. > > Fixes: a0a9f2180b90 ("mm: page_isolation: avoid calling folio_hstate() without hugetlb_lock") > Signed-off-by: Kaitao Cheng > --- > Changes in v2: > - Avoid unsafe folio metadata reads in the unlocked scanner by deriving > the hstate and scan step from compound_order(). (David Hildenbrand, > Andrew Morton) > - Treat invalid compound orders or unknown HugeTLB hstates as unmovable. > - Use PageLRU(page) instead of folio_test_lru(folio) to avoid folio flag > checks on a stale folio pointer. () > - Update the commit log (David Hildenbrand) > > Link to v1: > https://lore.kernel.org/all/20260519121646.40833-1-kaitao.cheng@linux.dev/ Acked-by: Oscar Salvador (SUSE) -- Oscar Salvador SUSE Labs