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 064F4431E66 for ; Thu, 2 Jul 2026 00:11:15 +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=1782951077; cv=none; b=dZjoEFb8VGX5Qpd45FLh31rqexFZ+tIvnqOmaLmZddLajY5aZ/wAN6xkCFwHJSQFzAzKFAOVwuPoOsqDlLngQ0baJPmcAmxspuDZ36qndTh5G2i8Yu4H99Uzca+JMoGwDYOMFTMrHklAutHgzg2H8kXdeEnE/pVXG6JjKuOp/Nc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782951077; c=relaxed/simple; bh=NHIc0iw11ZyXWsRThyNxFwDcBj4CJqL9v16XrQCjUho=; h=Date:From:To:Cc:Subject:Message-Id:In-Reply-To:References: Mime-Version:Content-Type; b=homQbG5NyDBD38YlxXYVWsIS835iW2DtBvgfg5B7DuFujsv/kV7IW2QdGHLEtMdE1/B1qbIqlumhX+Iwgk6noEwknYFm7s4iaogK7F3Z/KyuPoD/g8DGkd5xQUUuIeNgNGgVC/b4qqEvJWJ9NbVIP+76SFD+L1ROtRT8nSWXeOQ= 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=B1NTniAD; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b="B1NTniAD" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 696451F000E9; Thu, 2 Jul 2026 00:11:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=korg; t=1782951075; bh=OUQ/ncYtl6fMqy08Nx0w8y0TjW9zrOsupNjOF3/ZMmY=; h=Date:From:To:Cc:Subject:In-Reply-To:References; b=B1NTniADpXkKOwZBSXMHYoybCX13p9DBSoT4CqWqrIywB6aqahiTZn4zE2p2pIJvw vXJYAdRMCSotP1sgOw6LURcgJqNoC8yJu7MYLP5Qnii04g3pvrncqXlZXkz5fQd4M4 MRzn18njR2GDJBBzBNkQ7GqwVGNyMeDPcK+wPOPA= Date: Wed, 1 Jul 2026 17:11:15 -0700 From: Andrew Morton To: Ye Liu Cc: Zi Yan , Vlastimil Babka , Suren Baghdasaryan , Michal Hocko , Brendan Jackman , Johannes Weiner , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v5 0/9] mm/page_owner: misc cleanups Message-Id: <20260701171115.79148d1c7e4f07ebf419c185@linux-foundation.org> In-Reply-To: <20260701061101.344679-1-ye.liu@linux.dev> References: <20260701061101.344679-1-ye.liu@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 Wed, 1 Jul 2026 14:10:43 +0800 Ye Liu wrote: > This series collects a few cleanups for mm/page_owner.c that have been > accumulated while reading through the file. There is no functional > change -- the goal is to make the code easier to read and maintain. Thanks, updated. And... this series is wearing out my keyboard. Please leave it a week, gather up any additional feedback and only then send v6, if needed? btw, it's conventional to place the what-changed-since-last-time info below the ^---$ separator rather than at top-of-changelog. That's where we place info which isn't appropriate for the mainline tree. AI review flagged another possible pre-existing issue. A second occurrence of the race your "mm/page_owner: fix TOCTOU races in lockless page state reading" series addresses: https://sashiko.dev/#/patchset/20260701061101.344679-1-ye.liu@linux.dev > v5: > - Place the two patches corresponding to the Close connection, patch8 > and patch9, together in this part. > - Close: https://lore.kernel.org/all/20260625014708.87386-1-ye.liu@linux.dev/ > - Link: https://lore.kernel.org/all/20260701012239.315262-1-ye.liu@linux.dev/ Below is how v9 altered mm.git. This is the addition of your "mm/page_owner: fix TOCTOU races in lockless page state reading" series, mm/page_owner.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) --- a/mm/page_owner.c~b +++ a/mm/page_owner.c @@ -428,6 +428,12 @@ void __folio_copy_owner(struct folio *ne * to skip less than the full buddy block, but that is acceptable for page owner * iteration purposes. * + * The lockless read of buddy_order_unsafe() can also return a garbage order if + * the page is concurrently allocated and PageBuddy is cleared between the check + * and the read. Clamp the advance at the next MAX_ORDER_NR_PAGES boundary so + * that a bogus order cannot carry @pfn into an unvalidated memory section, + * which would break callers that rely on boundary-aligned pfn_valid() checks. + * * Return: true if the page was skipped (caller should continue its loop), * false if the page is not a buddy page and should be processed normally. */ @@ -439,8 +445,12 @@ static inline bool skip_buddy_pages(unsi return false; order = buddy_order_unsafe(page); - if (order <= MAX_PAGE_ORDER) - *pfn += (1UL << order) - 1; + if (order <= MAX_PAGE_ORDER) { + unsigned long new_pfn = *pfn + (1UL << order); + unsigned long boundary = ALIGN(*pfn + 1, MAX_ORDER_NR_PAGES); + + *pfn = min(new_pfn, boundary) - 1; + } return true; } @@ -551,7 +561,7 @@ static inline int print_page_owner_memcg cgroup_name(memcg->css.cgroup, name, sizeof(name)); ret += scnprintf(kbuf + ret, count - ret, "Charged %sto %smemcg %s\n", - PageMemcgKmem(page) ? "(via objcg) " : "", + (memcg_data & MEMCG_DATA_KMEM) ? "(via objcg) " : "", online ? "" : "offline ", name); out_unlock: _