Received: by 2002:a05:7412:3b8b:b0:fc:a2b0:25d7 with SMTP id nd11csp2517rdb; Wed, 7 Feb 2024 18:35:13 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVMzPFd6l4XChjfYE/+QfHguEI2xmzCQvjDcmHw5kmk9k8ocfdaeaTf3FjptPoC3UFALCu5n6Jz86ybBc7U0DPf/iSaoO8zXwDl54F2Yg== X-Google-Smtp-Source: AGHT+IGhUkv+qJTwhklBoxPYJKzdeL6s0JSeTUV065guP91LN7aUbtbJyxkuKw/N6J28u8oofhzg X-Received: by 2002:a05:6a00:80ed:b0:6de:3833:425a with SMTP id ei45-20020a056a0080ed00b006de3833425amr4254546pfb.5.1707359712796; Wed, 07 Feb 2024 18:35:12 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707359712; cv=pass; d=google.com; s=arc-20160816; b=SXapG8X8a9mYicvby0Q51mFkTwyGuY920giIY1EKlbYrZek09gNNxSbJxBvnIJ/04i /QOABbbb71mbMzyTL7C22t2bICFmKa1yHT4R/e+aQoZfWDxC1w/GJowztC7TPUrtdzd8 w2fo70E+AosqVRawBYaLjiJtXuGeDyNlOkh4c4ACiPS7i1+gXTPQSVipbzdfnN99AtNm crMHx/zEwipnOanC5OaQgk8rsiygoqrvoc1WGN6Xxfoqg0UGbPEQh3zBihS29+eSr4N4 guzlgoBGaqjeabDaKIJ34lzrsLOFqLc6S6lC3emMNSdLt8NQdQoftDOCsTVlHmCB+LBz zEfg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:dkim-signature:message-id; bh=JcrtKKNrzp8Qp0fqpYyaI1RyGJgRqDnnLYhAFWHoxnw=; fh=3F0hu02dkuEbK6Nrm+qWO3uUXpbfs5PLBCqZCjaLSoE=; b=POqhOC+rrlVyYLtejuWdZD1Nv3u2yGca+o6MPJfiss8FEh77pafTGkA1aYmevrV9IE gne7Nh5Vyoz7z8Jq0T5MiCxzbdZV7enesq05SbNBcRfGfc+aQg/R7Q7utZDKU0GVXDLU huLWjKlzFjrVmbnU5vHI4xdYIjkIIFJZHMhblnG4T8YyytXe5C+/5ykuMm9SUxFdkE8c GV7NfzNPsS7jc+JtYvH+JC6q4+AONlw2sl86PYSUjykN7hSBBWlVQGSx9q5jMnOObbsR zpB7Ky8Uy7b1v09NG0JlEbvHgj0DIkpWG5EIIovlbCWoe8jjWbOnoeu0p5j94HZzmZ86 Zd/A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=cSqV5VGu; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-57390-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-57390-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev X-Forwarded-Encrypted: i=2; AJvYcCUyudpOF5pyf+Pw85F6YFRQG0cnj4BadEV9vODeo5A7DOhUz3r8P5R7usEmjSXryVR2gUgRq/lT2BL+T7fHG1WFAHOj545XQMB/V/fnCw== Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id cw25-20020a056a00451900b006dfbb278dd5si3001697pfb.236.2024.02.07.18.35.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 18:35:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-57390-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=@linux.dev header.s=key1 header.b=cSqV5VGu; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-57390-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-57390-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev 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 739C828710D for ; Thu, 8 Feb 2024 02:35:12 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AADA818EA1; Thu, 8 Feb 2024 02:35:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="cSqV5VGu" Received: from out-176.mta1.migadu.com (out-176.mta1.migadu.com [95.215.58.176]) (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 087271D527 for ; Thu, 8 Feb 2024 02:35:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.176 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707359703; cv=none; b=i3h6WEgG85qchkygE6jHuaJMzI3KjsBC/ISN7NUhGTFwYOpxP19tGjWTmh33TH+E4a4medqpi4/zOvfP32M+4CmTtpysasiGYHXbeGHDEOMj8UguRPgtEHuzLuutYXG/Pfk8ufFyMuE064LDTavebuNcuikL20yCbuHpTZ8QAdU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707359703; c=relaxed/simple; bh=EkOqfampjeSKQg5Cr8kvbOMjAirzAY3ivCor7kCy+9I=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=AE6nQlH4f5Y5bZEqXC8dB8mg7lexL/SPJxiI/wF09TPfAp5QFXb+WNiP12AvfEC4/M4UFbkVAFtcKyxDI78wDrtMpaJUIsptzvIFXaxokE7ViGPO4NBfVJjWvAtR8zre6rZhKPUb8RoiLP7XCbEoePtj7P+22xERMCh85oHZhpY= 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=cSqV5VGu; arc=none smtp.client-ip=95.215.58.176 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 Message-ID: <9dec8d00-c01b-44fe-983a-ec2b83d71e2a@linux.dev> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1707359700; 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=JcrtKKNrzp8Qp0fqpYyaI1RyGJgRqDnnLYhAFWHoxnw=; b=cSqV5VGuSF0ia9JzWNev68oQ36rGLC/zt3lp6piRGnu4bMViCrk5P9y+85jZ0slalDg6Mv O+vWNGeAQ9r4clnhO7Q+RkdRsUrYlwCzKtU3n+A4Qho7Gqs8hFRALgr+dPdDlEeL41xNbQ 0kWe69ej4IETPXXtQwDoSWX+n78X/C8= Date: Thu, 8 Feb 2024 10:34:54 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Subject: Re: [PATCH v4] mm/zswap: invalidate old entry when store fail or !zswap_enabled Content-Language: en-US To: Nhat Pham Cc: hannes@cmpxchg.org, yosryahmed@google.com, akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Chengming Zhou , stable@vger.kernel.org, Chris Li References: <20240207115406.3865746-1-chengming.zhou@linux.dev> X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Chengming Zhou In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT On 2024/2/8 07:06, Nhat Pham wrote: > On Wed, Feb 7, 2024 at 3:54 AM wrote: >> >> From: Chengming Zhou >> >> We may encounter duplicate entry in the zswap_store(): >> >> 1. swap slot that freed to per-cpu swap cache, doesn't invalidate >> the zswap entry, then got reused. This has been fixed. >> >> 2. !exclusive load mode, swapin folio will leave its zswap entry >> on the tree, then swapout again. This has been removed. >> >> 3. one folio can be dirtied again after zswap_store(), so need to >> zswap_store() again. This should be handled correctly. >> >> So we must invalidate the old duplicate entry before insert the >> new one, which actually doesn't have to be done at the beginning >> of zswap_store(). And this is a normal situation, we shouldn't >> WARN_ON(1) in this case, so delete it. (The WARN_ON(1) seems want >> to detect swap entry UAF problem? But not very necessary here.) >> >> The good point is that we don't need to lock tree twice in the >> store success path. >> >> Note we still need to invalidate the old duplicate entry in the >> store failure path, otherwise the new data in swapfile could be >> overwrite by the old data in zswap pool when lru writeback. >> >> We have to do this even when !zswap_enabled since zswap can be >> disabled anytime. If the folio store success before, then got >> dirtied again but zswap disabled, we won't invalidate the old >> duplicate entry in the zswap_store(). So later lru writeback >> may overwrite the new data in swapfile. >> >> Fixes: 42c06a0e8ebe ("mm: kill frontswap") >> Cc: >> Acked-by: Johannes Weiner >> Acked-by: Yosry Ahmed >> Acked-by: Chris Li >> Signed-off-by: Chengming Zhou > > Acked-by: Nhat Pham > > Sorry for being late to the party, and thanks for fixing this, Chengming! Thanks for your review! :)