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 78CBB37DAA4 for ; Wed, 3 Jun 2026 05:35:48 +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=1780464955; cv=none; b=YwNzc4Lf+a41mUyxjvNnb+XVeeqiloqDK5YU/HBpTucoSTgGaCM1rEdWJ1qY/0q4TtTJWZ9qiOihQfUPvCEPwa1PhJ8jfNohETNmNLd2T6ZtoamNg63QB9VsE7tCQY8I5AUC7ALUf+zqfF56gul4XXLTw1PiS5gGAsHpxCV7QBE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780464955; c=relaxed/simple; bh=9eNQHsujvGL/v2JYhevSl0RRpKokuPkglQLZJwC3hug=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=KzaRuJgFqzwAEyiQADGRXZAndHPtF1RiE5IVqOztsP0k78rcGhwcl0vQq75zEj+faQIJKEf/Jen6D6ZMBUd9zj3hJhepXwyMjujstH9Qs45X/BP88UFXsbMfV+ZupORQTTMYUhHpVyLDXQOBX7WQQtKyA/k18pLg4a3VMnPQob0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=afKyfzPw; 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="afKyfzPw" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0C2491F00893; Wed, 3 Jun 2026 05:35:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1780464948; bh=sk+fixDbabhLM2/BdXdj31qYla4LMHhKSpCBuaGwgRU=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=afKyfzPwMZnX8RIkQ62Ya83mT2tiXh6A2Y4ngnA3DTORF80aPWcCsA9Ow9tWFaL8P Q3SeijIk5i44X5Pb5k1chgqbdmQBVYOP3/HhrbGvZIK87zpNHToS09FwTEQEOm0L4d nEs0ObzT+Pwcm7Rms4afNdAt62/YdphsvEugwPWGcRZ7hd9WuzURbZ446f88NHkACq KE0n9i1u+Hem+mJsgbcGvS0vJ1Q2wdwpgNUHCP4ztTBnHsukGxjgKCYYzx9RI7Dn/a n4HtV2VhwPI7pkIPFGuV+xJkLZblh3NOxl5FA5LRYtRH68rxb65adzMMRE1aiklf0P dwN5Hw0jqlhDg== Date: Wed, 3 Jun 2026 07:35:42 +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 Acked-by: Oscar Salvador (SUSE) -- Oscar Salvador SUSE Labs