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 33EAEC54E58 for ; Mon, 25 Mar 2024 16:30:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 81EF16B0087; Mon, 25 Mar 2024 12:30:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7CF296B0088; Mon, 25 Mar 2024 12:30:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6974B6B0089; Mon, 25 Mar 2024 12:30:12 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 5722F6B0087 for ; Mon, 25 Mar 2024 12:30:12 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 0F402140799 for ; Mon, 25 Mar 2024 16:30:12 +0000 (UTC) X-FDA: 81936098664.11.03FB5F6 Received: from mail-qk1-f181.google.com (mail-qk1-f181.google.com [209.85.222.181]) by imf04.hostedemail.com (Postfix) with ESMTP id E34B940018 for ; Mon, 25 Mar 2024 16:30:09 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=cmpxchg-org.20230601.gappssmtp.com header.s=20230601 header.b=FcxXv2yF; spf=pass (imf04.hostedemail.com: domain of hannes@cmpxchg.org designates 209.85.222.181 as permitted sender) smtp.mailfrom=hannes@cmpxchg.org; dmarc=pass (policy=none) header.from=cmpxchg.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1711384210; a=rsa-sha256; cv=none; b=y3KH1y+zPQ3NYjtJ1Qg38nfz3Y9WaHeszZH1imYu70Ih2JKGVzCQWLVMxqY2Vu9QS2zKHB dKFYLI6/YDBzP0cQEw6/nkUnU3O/QIbpn4ZmO37vf2ld+4XaI4Nma1tOVbcQMGkBhFRMfN xAn8rvcUWH+KUhuA6ERH4Zh4QfBJcbQ= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=cmpxchg-org.20230601.gappssmtp.com header.s=20230601 header.b=FcxXv2yF; spf=pass (imf04.hostedemail.com: domain of hannes@cmpxchg.org designates 209.85.222.181 as permitted sender) smtp.mailfrom=hannes@cmpxchg.org; dmarc=pass (policy=none) header.from=cmpxchg.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1711384210; 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=iWU1iomNitCz7xhvZ+axr2VvsxukZq2xkRMym6uJF3U=; b=A5PY82yefAaBsntYocpoEHZX6IwKflwGtWKluTGA0bmqn1RRa875JIBGmWIaBZSn18h73S 50RA4WMmhIi0r8bfRfnHFfsJswTX7owxnCZKtkGOAFHwQUm+mK3KhInLNh+qy6tdnDaeDF EjWQQo6joX5YYuWdxiQk+7TPdbYR4mI= Received: by mail-qk1-f181.google.com with SMTP id af79cd13be357-78a5580324eso65695285a.3 for ; Mon, 25 Mar 2024 09:30:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20230601.gappssmtp.com; s=20230601; t=1711384209; x=1711989009; darn=kvack.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=iWU1iomNitCz7xhvZ+axr2VvsxukZq2xkRMym6uJF3U=; b=FcxXv2yFIrzdKTbFlcvTeNSfUuMAzd8aMsg8zrQPlJSSw9V0wTFQnzbE62nRLr13nP AFcUjU4XYWgSH+Mvh0cv4eIevRQFdj1R/88I18vG72ixTQI/dRJQxuN5O4H+pIa8jqVR kjL2vWxN0vpwjuBmzK3zQ16KjvM8lL4vYrIGX4TmgUJw+iTu1Blan8RgH2Nfw8Cgb/rl XX11xdWo55lcGKaaN0IlhlX80v3QRm/lifb69UaL/wBCnW7usXzg4C5Zfhk+ums00yoW nPse/7S/pMjwfWudvfI2Fiu+Mt8wN6twBk2uoX/LUuUrKoAS19xTYyZ2PKDYMuMPAdxt QofA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711384209; x=1711989009; h=in-reply-to:content-transfer-encoding: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=iWU1iomNitCz7xhvZ+axr2VvsxukZq2xkRMym6uJF3U=; b=qBqM2fltuo3Hs/bDAvfgtMTRTq7jsJ4GsUxCU4y8Xh2k+VVGgWZcZA7RLn/03Aq1bM RIDrLlCJOIZbTRfTWO69MwqC9nwxwRBfrk2SNEgWLqkAKqHgiDATzcNTHcmZBc4KwH7k 7Kxhdt9hoIMlfFNemtlXlEH4ND5J3WHmklkqTk+Pq6lOveXCtyr1iHbwUd7AWSUyHEMy hivjpVou38NGNHjs/jwJqS6BP7cpmACiGGayNrp/wBawHZmwmzjpGA3wrBaFYnEb15Ts n0pqELDCAx9RzAqJ1aYdh7Ld1OMkmfDkyx7VnVJ32y1OslijJGGDdmjtPi6DqUThirSm frww== X-Forwarded-Encrypted: i=1; AJvYcCWtKpN6grtprlkzcvapfhucjTBMbvwtt6dTr2/RP2MhABru5EkPJndJeAX5CeHJBo4sYWHDVVWPYAmlLZUJs1rhL54= X-Gm-Message-State: AOJu0Yyb32fNMd5dVvOGbzVdKuIPFswpr0FZQ6ZlLRcyM+4OCw73KgLG y8DtYVuOELYl7sjPYrPk5hjJo2I2b2N2H+1HVNWdVWZx/y83R5uGyI5Urxkhw8I= X-Google-Smtp-Source: AGHT+IGfXdktUARTW/DIGirjPlGgHS1vx0o8seoKe5LBSCoLW8vOBkpB6lCZU2LWre+0twxZLn25MA== X-Received: by 2002:a05:620a:564f:b0:78a:29e1:6255 with SMTP id vw15-20020a05620a564f00b0078a29e16255mr397584qkn.20.1711384208711; Mon, 25 Mar 2024 09:30:08 -0700 (PDT) Received: from localhost (2603-7000-0c01-2716-da5e-d3ff-fee7-26e7.res6.spectrum.com. [2603:7000:c01:2716:da5e:d3ff:fee7:26e7]) by smtp.gmail.com with ESMTPSA id t1-20020a05620a0b0100b00788402160besm2232411qkg.128.2024.03.25.09.30.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 09:30:08 -0700 (PDT) Date: Mon, 25 Mar 2024 12:30:03 -0400 From: Johannes Weiner To: Yosry Ahmed Cc: Andrew Morton , Zhongkun He , Chengming Zhou , Barry Song <21cnbao@gmail.com>, Chris Li , Nhat Pham , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] mm: zswap: fix data loss on SWP_SYNCHRONOUS_IO devices Message-ID: <20240325163003.GA42450@cmpxchg.org> References: <20240324210447.956973-1-hannes@cmpxchg.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: E34B940018 X-Stat-Signature: eisty9au5t8dfqc5qric7aiw9eztshpd X-Rspam-User: X-HE-Tag: 1711384209-663953 X-HE-Meta: U2FsdGVkX1/Ywh2RzQVEGiJTyH1WuUY6uePIN28kNnAM0HXuout5hdw4MMO0EOJaNMTxG3eJpRrwDCDpaAgma+VN9HX6M8Xk8/J5MCiOFVcTquDXPbvwVvuDcVTY/hDSUq4c44k/K4ZojejjtdAm+2fTygEsBRSrnfZDsOPvMKR+6PtuDtZyWFl0v72WAjd9CH9ha3IZpdhoiqCoiQJ4KmqFsPPJu53VypAmNA9VqTIxIwTHN16FDUWbW5NxzVSyNcC2BUCSTrx04GhFZxuWpa2Nct/88Pkgoo+GgBwL2C3vsZKrFg6sS2MuuldNsmWOt/5SgfPw6GEmYHu/2pbUZ8KXFbByXcOtkuXULv5u2dKHFgOIs8oBtUI9B8qDf/0eOeNW4jeYbOR3HjQ18YLkMRnV+G0RV6HXtRnjqXeKS01lVYeba/nJ7HSgTsTv6vQrzomY2hUVugXQu9I44UhjXMx5n11EYwpokFaUDlQLMpo3LAd2ZkmJoAWo4pA1RlguM0nhzyHoCmuIoPQKQNGAmhG5pfaSqEQG88cAmDZCRKnNKsPvhQs16lop/k3fRwXZ7lj8zFOB3aJkU3/qkYRk+TIrWQ6tHQNygX5TANlLzxVMluTBUl4LTAQFWLyP0v5UAvx29UNB5q+U2IqSf5HSwhxuUE3n7wfzEOAsj98H5NTbYJE20BAgUNlRtDZsvLaX4/7n6bxDaBXSfLwhNLz0LI8X2RfLMWrhHnOhtpNfeh6qj0QTytLkrcEaDQ+7ym1d0pxMi9h0cb3rKR8RxJEvF0CAi/hhpmnUyG9UHKonfy2vCMWQRTIDmKS6xcyLKom7Xc9bjpDTtAjBLHkHJsf1zb4WRQp9a35eCwCTwQZt0F3WkwM4mPG83b01OOIgq7BVjIFj5S2kai7ZVmsLThO5YeQj/1FtD0/uL8b3praPuPMBLKtN7MBZQuq1eUOl8s1kLLZvMo7LttdrerNfxm1 a1wG6MKw 0lqkfxTyG7AfbyCD36krGFstLRrjGvn9ERMCugjxnBveeVmW9tmIGAXzQNYJEnmaRK8vHAsO12NhLrW5fbCv9q+rx+W89y2cBDoscD8vfEkGzn5jeqpDGLIe87uDzwjSJjCV6kL44MafEEBv0kCb0d3GWftgKSBKoNxn8nI5yUNTL3gfOssI//LQtiA== 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 Sun, Mar 24, 2024 at 02:22:46PM -0700, Yosry Ahmed wrote: > On Sun, Mar 24, 2024 at 2:04 PM Johannes Weiner wrote: > > > > Zhongkun He reports data corruption when combining zswap with zram. > > > > The issue is the exclusive loads we're doing in zswap. They assume > > that all reads are going into the swapcache, which can assume > > authoritative ownership of the data and so the zswap copy can go. > > > > However, zram files are marked SWP_SYNCHRONOUS_IO, and faults will try > > to bypass the swapcache. This results in an optimistic read of the > > swap data into a page that will be dismissed if the fault fails due to > > races. In this case, zswap mustn't drop its authoritative copy. > > > > Link: https://lore.kernel.org/all/CACSyD1N+dUvsu8=zV9P691B9bVq33erwOXNTmEaUbi9DrDeJzw@mail.gmail.com/ > > Reported-by: Zhongkun He > > Fixes: b9c91c43412f ("mm: zswap: support exclusive loads") > > Cc: stable@vger.kernel.org [6.5+] > > Signed-off-by: Johannes Weiner > > Tested-by: Zhongkun He > > Do we also want to mention somewhere (commit log or comment) that > keeping the entry in the tree is fine because we are still protected > from concurrent loads/invalidations/writeback by swapcache_prepare() > setting SWAP_HAS_CACHE or so? I don't think it's necessary, as zswap isn't doing anything special here. It's up to the caller to follow the generic swap exclusion protocol that zswap also adheres to. So IMO the relevant comment should be, and is, above that swapcache_prepare() in do_swap_page(). > Anyway, this LGTM. > > Acked-by: Yosry Ahmed Thanks!