From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 CA8D032B115 for ; Tue, 19 May 2026 17:54:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779213265; cv=none; b=OC5H1dVPBgFv1SzcYVRxWhgsaGDWuGxbjfEVrZ35ETCewnwwjHrjeTxYNRebbmBF/KCrxc6hpmQO8PYPC81fJuqeFvGf4vzWohupyaoPY6juHY28VtkoRBRypW07GKGrsSy4q5CtqmSkrhME/65vBBPyZ2nBPP/UJxu1stljqrE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779213265; c=relaxed/simple; bh=ZCOEIIWzp1vuHm3T+v8hOOHOOiwrxqzK4hHsnCJoRII=; h=Date:From:To:Cc:Subject:Message-Id:In-Reply-To:References: Mime-Version:Content-Type; b=AWYMKUDkeWpuNlm70xc2j/qPf1Bt0GKdnsmuJYAoFXorutkTCMnJ+XXB5iqcTrph5p61TNkDVLqoNGUDhMdH9kBAIIpkRh/15kXuHr633Pta95hKsTNOg2ZeqJDPJ4zpplyHJQes9WcgMOZ37AlZWBYbpMOIjmx4VXDZbbk37No= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b=A+jtP/uZ; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b="A+jtP/uZ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CBFAAC2BCB3; Tue, 19 May 2026 17:54:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1779213265; bh=ZCOEIIWzp1vuHm3T+v8hOOHOOiwrxqzK4hHsnCJoRII=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=A+jtP/uZ7+GWXcdqXPmeQfkeY65k9jdEg4qw6fiESoUf+Z7ufAVIAx83tATETBZLj zqfh4BHdNwFpZOJ1GGTQmoUYZ9zcvmYHU+XZiPvRkpnU7cAFu00gxJZ+218WB2PoY0 WKZWMt4TKVoSYXYbd1ZhUINtohfK1jQy0oCb+gtk= Date: Tue, 19 May 2026 10:54:24 -0700 From: Andrew Morton To: Kaitao Cheng Cc: vbabka@kernel.org, surenb@google.com, mhocko@suse.com, jackmanb@google.com, hannes@cmpxchg.org, ziy@nvidia.com, liushixin2@huawei.com, david@kernel.org, osalvador@suse.de, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Kaitao Cheng Subject: Re: [PATCH] mm: page_isolation: Avoid hugepage scan step underflow Message-Id: <20260519105424.e422131a0ffb49e19ed1aebe@linux-foundation.org> In-Reply-To: <20260519121646.40833-1-kaitao.cheng@linux.dev> References: <20260519121646.40833-1-kaitao.cheng@linux.dev> X-Mailer: Sylpheed 3.8.0beta1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) 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-Transfer-Encoding: 7bit On Tue, 19 May 2026 20:16:46 +0800 Kaitao Cheng wrote: > page_is_unmovable() checks HugeTLB pages without holding hugetlb_lock and > without pinning the folio. This is intentional for the pageblock scanning > paths, but it means the HugeTLB folio can be freed concurrently after > PageHuge() or folio_test_hugetlb() succeeds. Thanks. What are the userspace-visible runtime effects of this? > The existing code avoids folio_hstate() and uses size_to_hstate() because > the HugeTLB flag may already have been cleared. However, if > size_to_hstate() returns NULL, the code still falls through and computes > the scan step from folio_nr_pages(). If the folio has been freed and the > head/large state has been cleared, folio_nr_pages() can return 1. When the > current page is a tail page, subtracting folio_page_idx() from 1 can > underflow and make the scanner skip too far. > > Treat a NULL hstate as unmovable so the scanner does not try to skip over > an unstable HugeTLB folio. Once a valid hstate is found, derive the number > of pages from the hstate instead of reading the folio size again. Also > validate the page index before computing the step to avoid underflow if the > page/folio relationship changed concurrently. This code sounds rather sketchy, and it sounds like it will remain sketchy after the patch. And AI review says "hey, this code is sketchy": https://sashiko.dev/#/patchset/20260519121646.40833-1-kaitao.cheng@linux.dev > Fixes: a0a9f2180b90 ("mm: page_isolation: avoid calling folio_hstate() without hugetlb_lock") We might want to cc:stable on this, depends on the answer to my above question.