From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id B6A26C4828F for ; Thu, 8 Feb 2024 02:35:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 340F86B0075; Wed, 7 Feb 2024 21:35:05 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 2F0EE6B0078; Wed, 7 Feb 2024 21:35:05 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1B82A6B0080; Wed, 7 Feb 2024 21:35:05 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 0CE0F6B0075 for ; Wed, 7 Feb 2024 21:35:05 -0500 (EST) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id B48BBA05DC for ; Thu, 8 Feb 2024 02:35:04 +0000 (UTC) X-FDA: 81767069328.26.7F3E56D Received: from out-176.mta1.migadu.com (out-176.mta1.migadu.com [95.215.58.176]) by imf20.hostedemail.com (Postfix) with ESMTP id DA61A1C000C for ; Thu, 8 Feb 2024 02:35:02 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=cSqV5VGu; spf=pass (imf20.hostedemail.com: domain of chengming.zhou@linux.dev designates 95.215.58.176 as permitted sender) smtp.mailfrom=chengming.zhou@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707359703; h=from:from:sender: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:dkim-signature; bh=JcrtKKNrzp8Qp0fqpYyaI1RyGJgRqDnnLYhAFWHoxnw=; b=fW/LT3yjsfGxZM8c5cwpMKdc1rqjvSlz6uCqOCvSh45D9xJ5br0VF9kiS5DJPKQWFgpjI5 wGmVUs+b6Si5bNgZI6p5UaDKZynwn6HLbTBUK+ta0LjqFXcEA8hjhKRsXLW6G/bw9+ZAPP 6lmfI1HjambCK3Q1M7b8RN0ac01G5Qs= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707359703; a=rsa-sha256; cv=none; b=7Roa/7mNr7VNxncNjq7p/hhGpv2W5HEfoiq9V0tPnHnu0Mu+sLoy6XMdg79jkeRCAvUnDq B6qdXL6LVAQUP4+9taXUYLt8j0PmBv5jv5kB0Ec4Sw+ysPs5Xr4QJsqUp/mZzA+KqCSbjt 3Hd4j9cVrWE4K4NdbouEqNRDq0wYIkQ= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=cSqV5VGu; spf=pass (imf20.hostedemail.com: domain of chengming.zhou@linux.dev designates 95.215.58.176 as permitted sender) smtp.mailfrom=chengming.zhou@linux.dev; dmarc=pass (policy=none) header.from=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 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 X-Rspamd-Queue-Id: DA61A1C000C X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: hxzgbawj4cua94iuefzfdpt6nsxbkz76 X-HE-Tag: 1707359702-689273 X-HE-Meta: U2FsdGVkX1+fPrTYiIEK1o+0bjuS5Isny43UfaBI2Vc0tQlIu9ypVKNvIwfL3JAGSSW7dOXLkTTdYdtnEVIPGsm0Fw5z1Fh5OwD0tjk+UNVaN9SjcW/XjsevXeeSR7oPw1126PsCaFS69CVOo8wkk3XatJBZ1fXGo5Ejr2ZfO/6E9ySCJnps+H4QcOxEIEMS5/5fcVvcHpct4wPkV6Xa7Y6uAV70co4Q2m5+F+f1bFvrIjDzXKjrhmzHMVA6kqn+awAy+pUHOLm3Ql+6VlGkCKMDu7BaikJdzDVnMPC796SG5XTnaSWB1vCsTLwn/pbV7z9McoU9SPII8jiKb3n7NdrmBokJXCQOqh5vrX4o75RK4VM17tLCDBiOeKCWp9r/FW0SeVbb7FUa2Doh0nFRRhHKaCscSUTKtHhXtq5M5W75nNoSW+rFlTgvKc0ID54LW4BNzx8XfSomznoCwwI9+/9QlpF9tfiZmOZFxAqvODdHOhEdpC59RuXHKa3Xob48Yh/olfxM7BQrrPeABs+r9AQ57s2kTJzbSjqzd1cb6nXqO7hRvr3fWAJ2xAOea2VcWZCjag0Nlm2tohvpjegcRaFWVRFtLmKVrNm0BScvAtv9Hj6bcE8qd84IURsfGypqZsY381bQCeodbaH84secG3a2Zve98Tb/Sjeoky7rYq0xlQmVY7OHtZ+S4odNfC5rG0iy36eYdNsKimUduPKS1Khqd0vIYJjQxl8lYXi5tR77ZMJnEBTdU9kxOOzxoF4FVobMr+s7utJ8Y3g5ed9gx0vFWMb4jy6gr3Rh2PcW/Hg2E8BdN5ryLWN680h4EJ6ibj/GZc/mCFecJt/P/2UENy3mThiYS9pLkgg303p+mcmUU5+/Qmxwd9st74MuDpUmeCHR23V5OKxzsqj29RqC2+g6MXkpkwkFCQJEVxpEjnfaWcWeyewatoUJFHefEVuCywcrJHuGAoYJqJ0Qj2D d56SDWH3 nnrsRck65h+ZypPebcFtDj75WQ6R5p8ShlFyszsYM50GEvlSgDcp/ErwdMA9KvbHiNJJOTLlHdTyjRCJyeqbhS5XK/Gs8/9hV4CNQk8BampAqOUMTuGdYbqTnaTHKRXlKUj6PFMpgnZLZcRTxoM7V0uHWQJmYmAcDKWBFJkpTLXxigUk3PZgNdyeu/u/1JZmjJw2D7SXBhU1WfuKv7qKJE0sUjT9GRrPBW5zOmaqjAEV21TmV1B+AnaShCVGuFwaTocOlbTFS93+N/BFvlf38R+51iLayoWR7ox8c+YzpvkWDuCBK6qn4q1RzrCFp284MOjWNvO8QVdXYxju0ivZoi8Vpm1H2MfRQHnMRvSZ4zRbdo1PUbrw2PDhEPVXz0kXW9fHS7CKLGHy07wN7VKMlohESVmaZLsFuJHvyEojStfCD2xWOaI428XroxnbAdSBEnSAVXALsr8+RRVw= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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! :)