Received: by 2002:a05:7412:bbc7:b0:fc:a2b0:25d7 with SMTP id kh7csp3277665rdb; Tue, 6 Feb 2024 12:26:42 -0800 (PST) X-Google-Smtp-Source: AGHT+IF5VooSItq3vSf6v9WSwJNOp1bjeNZavRFiy8v4zQxlSrzMgMI+fWb6pfPeTcgrhIK2+w+i X-Received: by 2002:a05:6a21:920e:b0:19c:621d:7f73 with SMTP id tl14-20020a056a21920e00b0019c621d7f73mr4095887pzb.24.1707251201726; Tue, 06 Feb 2024 12:26:41 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707251201; cv=pass; d=google.com; s=arc-20160816; b=B557qfogQ64bHfiZwQ0gyHmwDpbYtq7ywwu0Jnm2r9H+tj4GqDcfVdt2u0urf3sRUx MYrkMDStr2nBqPAhvNyZt5SF+UTZTIX950PNZDHTbDgGR2RqAiDru00JxhnhZBaNT0tz eEUzdVX3V26KuWo1Q1CwvguAaI6lUUCBHmqvdFn5wNivHH6ACHbHufVSVbV75Fpqgap5 5SlLTiHnzJADUTS3YchhyzlwO7G+nUF+hJzH4Ie97kd84c+KuFvapSTRx+lxKYIVwWrS jMwwnRbUQ2pCgFFQg1pa2UkCzbkW9l7Uj6Se+hqkaa/B8exZl71nyjVBvKoIBD49QT8W /QTA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=v/0RXbqJk3p+Iy+ZevOvYx7kyIE4q+v2z/wExgGiYBE=; fh=mSLoknnnQkpU4JQmhLmEHBqsnNMlgmSf9IxyWrK+6aI=; b=h0hX/iY6TEj6GtwFcZ4YdWZnyX2/m7YH43TaATIyve1M6T40pzpqPMtbD9CfStMDHO jAxmqnMrRGE25PNNfAVQCU+EVkZO0RcfbjjDw+m14TynsOowompgI2CaoNemwkhtx9ow lW/MzeOo6lwI77uQCztO4c8hWRkal6B1Ixvi8oDVgyzZN9CJ5fRVQCXzrYvyU78HkOB0 HFsuHwjfdG/vbDtJ537PYJs7CtJhjj2OoDM8wLb0eK36f6PQmtA3uhzgx5B8TITxlZHu OtBk6/rOu7R/o6qH1LpgpUtItHLvio7NSq/vqlPjHmqDHjY7kAhNlxNSy/vQZOEhJ2WZ 7ktQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@cmpxchg-org.20230601.gappssmtp.com header.s=20230601 header.b=omSH9yjP; arc=pass (i=1 spf=pass spfdomain=cmpxchg.org dkim=pass dkdomain=cmpxchg-org.20230601.gappssmtp.com dmarc=pass fromdomain=cmpxchg.org); spf=pass (google.com: domain of linux-kernel+bounces-55597-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-55597-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=cmpxchg.org X-Forwarded-Encrypted: i=1; AJvYcCXQb0U0/6AF8VrY9sTE5nzf3RqKgfo/GXRFU3I+mIouy9QnNYz8c96f67Evm3FxLT8VKOZglddYi49puKlJJaV+cDco2q9QC1wONtne8Q== Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id 36-20020a631164000000b005cdd60a42f5si2051358pgr.838.2024.02.06.12.26.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 12:26:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-55597-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@cmpxchg-org.20230601.gappssmtp.com header.s=20230601 header.b=omSH9yjP; arc=pass (i=1 spf=pass spfdomain=cmpxchg.org dkim=pass dkdomain=cmpxchg-org.20230601.gappssmtp.com dmarc=pass fromdomain=cmpxchg.org); spf=pass (google.com: domain of linux-kernel+bounces-55597-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-55597-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=cmpxchg.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 5DA8D281F8C for ; Tue, 6 Feb 2024 20:26:41 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9BDE117BB3; Tue, 6 Feb 2024 20:26:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=cmpxchg-org.20230601.gappssmtp.com header.i=@cmpxchg-org.20230601.gappssmtp.com header.b="omSH9yjP" Received: from mail-ej1-f49.google.com (mail-ej1-f49.google.com [209.85.218.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4496D1798A for ; Tue, 6 Feb 2024 20:26:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.49 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707251190; cv=none; b=C4/4e6ZdINgKOxE1iN5gJTuLyUZAx5wqUP6QK3MUidXk4GJf3nu3efq1VwBC9ddjh3H8U3YqWxENJUMffhh4Lp4bftYUowhqWkMrhmyZunoHxiHQJO/DyaxgcNpm2hylg+v8B1HkWVNoccULgQph9DLTaUltl+4rqloUHkEhErM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707251190; c=relaxed/simple; bh=TeToKRLqHwGPheV9Y/TZxamway7IArC0Hy+zgck7zgc=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=czcBsrNpkrKVn+Wmq7OkRkol2xqhO/rOhn/5VHdzn6ZzkL67HCzhFCelcUqa1p7sWIKQP6EvccGpO3FPb8DwfM0+wBXbCA9m9gmkjQg+DKc2qQ+BwhzTJWujCEzftLlegxNA0Bp5MUqfKReYclspRi26tXzBNlzoJXRb7R1CF5Q= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=cmpxchg.org; spf=pass smtp.mailfrom=cmpxchg.org; dkim=pass (2048-bit key) header.d=cmpxchg-org.20230601.gappssmtp.com header.i=@cmpxchg-org.20230601.gappssmtp.com header.b=omSH9yjP; arc=none smtp.client-ip=209.85.218.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=cmpxchg.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=cmpxchg.org Received: by mail-ej1-f49.google.com with SMTP id a640c23a62f3a-a37721e42feso401171966b.2 for ; Tue, 06 Feb 2024 12:26:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20230601.gappssmtp.com; s=20230601; t=1707251186; x=1707855986; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=v/0RXbqJk3p+Iy+ZevOvYx7kyIE4q+v2z/wExgGiYBE=; b=omSH9yjPL2OzLvGaQdNQF1wQQxkCEk74albq+JphN+Fay1E/H/94nBshUN2PieWb3f 0W3InvrG2Tj8A9n0Vhh5PNZqN+ok/UfBTYBHhI2nX01ycCnD8GFac6EHRee4SvjAkQOM a3CaAqwU29CkmSh89bbE0c0YKrqmHQxXelLwHQYhzeTPFoDaEoTubkvvoAco32Vg5tIi YxsY7aP11CRG9Ttr+U1kWquGMdeCAHez5meWuY8h85IxC58K4qVwWQKPXyKMGfG8pvUR eeLLaznBK2JPIMUJwuJuuUZhUfwhqWQ4uQb9z4h4/ZZbuBMZYyEtHci3cPx312Grb5qc iVhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707251186; x=1707855986; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=v/0RXbqJk3p+Iy+ZevOvYx7kyIE4q+v2z/wExgGiYBE=; b=EGI9MJaE0AgWKjN7BwsKlkxwVnX3RNWt1GjWix+HaJl7MNsuQjogOyExTVP5vT06Ym oUcf8XtGkkPv6K7qZLauUnsrS4dlbcgqqmLKGxO9dpQtwx8EWie45EhQQs9qybcW5yLA Bd/njpSCFEeg8WUcYcksu4tBPCZwEoOeRrsOcwj/wJZHPQH3IsCJyFJYlskHxcC4vJh8 Mu6/8TxegO7f7T/gCYPs10rF56HylReTUXt2qlKkJSDAl0BhW/TqWl+XYVJDl6B5v/Gy uIvZt/VonCAMlxLWfNBB5k+2eridh996asLL2uftkyY3CYZVgJWhfX8jdX8GaGreiGuD SXeA== X-Gm-Message-State: AOJu0YxYmdoKUPcF75b37/js5VlE9JV2ncXh7J6qsbRE/f7f87PGg5zB PwQgKVwKAAwRpP/Yjevn/SxYLn2cuuS3UZCRxgd15Jttzkp0Mu3jFG0ldRe2w2UuJdMCadYDkO/ elOI= X-Received: by 2002:a17:906:f0cc:b0:a36:696f:3e20 with SMTP id dk12-20020a170906f0cc00b00a36696f3e20mr2839376ejb.66.1707251186226; Tue, 06 Feb 2024 12:26:26 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCU1bzhouKHDP+zXjwff86wa4JNDF8ywWc/udqyxFsOWza+5byAnBTqZ8wqNrJBmOpBRHDhuofCYj7q4xnG6dthHYLoS6CilTEQBMRtoTS3lkydMBqasqg8H33ARs3bb9QnoFy/VrCnHFpdnHahrWR7ndr9SY/71NABiNNKogGZp0CDBmkYzL/spU1MuRVe/7lE1SCr+XdiraFtlARnPdUKeB4U/KPQ0iQ== Received: from localhost ([2a02:8071:6401:180:f8f5:527f:9670:eba8]) by smtp.gmail.com with ESMTPSA id hu15-20020a170907a08f00b00a38103bfa29sm1373785ejc.174.2024.02.06.12.26.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 12:26:25 -0800 (PST) Date: Tue, 6 Feb 2024 21:26:24 +0100 From: Johannes Weiner To: Nhat Pham Cc: akpm@linux-foundation.org, chengming.zhou@linux.dev, yosryahmed@google.com, linux-mm@kvack.org, kernel-team@meta.com, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] mm/swap_state: update zswap LRU's protection range with the folio locked Message-ID: <20240206202624.GC97483@cmpxchg.org> References: <20240206180855.3987204-1-nphamcs@gmail.com> 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: <20240206180855.3987204-1-nphamcs@gmail.com> On Tue, Feb 06, 2024 at 10:08:55AM -0800, Nhat Pham wrote: > When a folio is swapped in, the protection size of the corresponding > zswap LRU is incremented, so that the zswap shrinker is more > conservative with its reclaiming action. This field is embedded within > the struct lruvec, so updating it requires looking up the folio's memcg > and lruvec. However, currently this lookup can happen after the folio is > unlocked, for instance if a new folio is allocated, and > swap_read_folio() unlocks the folio before returning. In this scenario, > there is no stability guarantee for the binding between a folio and its > memcg and lruvec: > > * A folio's memcg and lruvec can be freed between the lookup and the > update, leading to a UAF. > * Folio migration can clear the now-unlocked folio's memcg_data, which > directs the zswap LRU protection size update towards the root memcg > instead of the original memcg. This was recently picked up by the > syzbot thanks to a warning in the inlined folio_lruvec() call. > > Move the zswap LRU protection range update above the swap_read_folio() > call, and only when a new page is allocated, to prevent this. > > Reported-by: syzbot+17a611d10af7d18a7092@syzkaller.appspotmail.com > Closes: https://lore.kernel.org/all/000000000000ae47f90610803260@google.com/ > Fixes: b5ba474f3f51 ("zswap: shrink zswap pool based on memory pressure") > Signed-off-by: Nhat Pham With the fixlet applied, Acked-by: Johannes Weiner