From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-186.mta1.migadu.com (out-186.mta1.migadu.com [95.215.58.186]) (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 2F5E21548C for ; Mon, 20 Jul 2026 06:58:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.186 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784530735; cv=none; b=MDsAdgyf9jqlk/No+c+WNEDMRbE1raFSFCS4Xhw0f82MedVRp7HpyOAnbRF+jmBACMKuXT9sl3l3wVtJOTZll+uHYMC37LeCLP60zKdHx6M1obKymLWjRNZmnx4Dn1D/me6ZYQE0nURfyaczV/jawT/DbrG31aXZdeSy+PqXy7A= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784530735; c=relaxed/simple; bh=uB1qITkYtx52Plk/to5Gg2VrAcpj3AWwb2Y5kCUxMBs=; h=Message-ID:Date:MIME-Version:From:Subject:To:Cc:References: In-Reply-To:Content-Type; b=BvTe80dCSEjWl0A2hsEP4Acy3MOb0wSRhLJOe28DtWwQsvNRPpK3VyqXEllEKMdPOuAzvXI+0765iT3O8pD/QHnTgiCbuAk1F4jhmACWwJAy6liOZ9v4SpTr+Catp1bMdR4KF8mDSKuCB+QW+X5uzCG2Q0PUYvBljm60EtIf0/U= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=jcy5LAak; arc=none smtp.client-ip=95.215.58.186 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="jcy5LAak" Message-ID: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1784530730; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jxcjZTfCxdOxrLMz+THGBCm+S/NYMN19qenWyxKwTqM=; b=jcy5LAakIaLoy8oknD7Y0v2vm4C3A1mefiHvg8tzak2qb0WXiuIrFWQ0eMqJ9mKF4hjUOe Zlk+gVEdVgha/pwINdIeLxXrrzJSKqDUiIZYljjy3mams7qqXSgljLf9oPG8/8iX8tjgml xkQ86I5SyPIA8zQr2gBJWsJHUoJWXeg= Date: Mon, 20 Jul 2026 14:58:10 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Ye Liu Subject: Re: [PATCH v6 9/9] mm/page_owner: use memcg_data snapshot to avoid TOCTOU in print_page_owner_memcg() To: Andrew Morton Cc: "Vlastimil Babka (SUSE)" , Suren Baghdasaryan , Michal Hocko , Brendan Jackman , Johannes Weiner , Zi Yan , linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <20260714015117.78351-1-ye.liu@linux.dev> <20260714015117.78351-10-ye.liu@linux.dev> <21007313-40dc-46fb-bbf2-453c8eedf3e8@kernel.org> <20260719224255.8e2bc60e8a42681fb541e6ad@linux-foundation.org> Content-Language: en-US In-Reply-To: <20260719224255.8e2bc60e8a42681fb541e6ad@linux-foundation.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT 在 2026/7/20 13:42, Andrew Morton 写道: > On Mon, 20 Jul 2026 10:45:56 +0800 Ye Liu wrote: > >>> These points have too much detail that's already in the code. Would just >>> mention that we opencode applicable parts of page_memcg_check() and >>> PageMemcgKmem() using the snapshot? >> Yes,It's a bit wordy. >>> >>>> This avoids both TOCTOU windows and the assertions entirely. >>>> >>>> Signed-off-by: Ye Liu >>> >>> Reviewed-by: Vlastimil Babka (SUSE) >>> >>> Was all of this reported by sashiko? At least the new-in-v6 was? >>> Then: >>> >>> Reported-by: Sashiko >>> >>> But it's no longer a cleanup but a fix, so probably this? >>> >>> Fixes: fcf8935832b8 ("mm/page_owner: print memcg information") >>> Cc: stable@vger.kernel.org >>> >>> It's not fixing a new regression so I think it's fine to keep it part of >>> this series for next release and not need to split out for mm-hotfixes. >>> >> Hi Andrew, >> >> Could you please help me revise the above? > > Sure, how does this look? > Looks great, thank you! > > From: Ye Liu > Subject: mm/page_owner: use memcg_data snapshot to avoid TOCTOU in print_page_owner_memcg() > Date: Tue, 14 Jul 2026 09:51:08 +0800 > > print_page_owner_memcg() reads page->memcg_data via READ_ONCE() at the > start to guard against tail pages and NULL data. However, it later > re-reads page->memcg_data locklessly in two places: > > 1: page_memcg_check(page) > > 2: PageMemcgKmem(page) (via folio_memcg_kmem(), which includes > VM_BUG_ON assertions for tail pages and MEMCG_DATA_OBJEXTS) > > If the page is concurrently freed and reallocated as a THP tail page or > slab page between these calls, the VM_BUG_ON assertions can trigger on > CONFIG_DEBUG_VM=y builds, crashing the kernel. > > Fix both TOCTOU issues by using the memcg_data snapshot throughout. > > Link: https://lore.kernel.org/20260714015117.78351-10-ye.liu@linux.dev > Fixes: fcf8935832b8 ("mm/page_owner: print memcg information") > Signed-off-by: Ye Liu > Reviewed-by: Zi Yan > Reviewed-by: Vlastimil Babka (SUSE) > Cc: Brendan Jackman > Cc: Johannes Weiner > Cc: Lorenzo Stoakes > Cc: Michal Hocko > Cc: Suren Baghdasaryan > Cc: David Hildenbrand (Arm) > Cc: -- Thanks, Ye Liu