Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2799112lqp; Mon, 25 Mar 2024 09:29:12 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWOiKFY3LAovxqnHw5w3EEyIz5qfnC2JGWfUhBdzkv0pP+DUN1+1kLXhjRiwhXOpXbLVfG2GyxfpXBfnNCxJGKeGxNsvyttoxNqGyUSCQ== X-Google-Smtp-Source: AGHT+IEENC991Wl6xY3IAVtFQN1IEni3vBRxqjhL2OYs7WFOJB0Zv4edC67TRBy992HbE/dFLcWr X-Received: by 2002:a05:6a00:398f:b0:6e6:767f:f807 with SMTP id fi15-20020a056a00398f00b006e6767ff807mr7889506pfb.10.1711384151965; Mon, 25 Mar 2024 09:29:11 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711384151; cv=pass; d=google.com; s=arc-20160816; b=HuxhjQm0IzfUvq0HG35+E6VrFY6Cf5grZIrgzPsjUaLl/cx/96Mg8FPfqQ2+t0+MBA 2cD6bWcSsXSK7V/zXEEUJ3bk2jsDA+hIaoYaF8xrxapADCtYhIJOAz60+mq90HJTfFEY cCXqgbujXMxJbsa6Ax4RJHzpJAOr7PjHkow2T0Ljdnkqil22jEs4lKgp4Glfa3pmrXcY uD5xmTu2J8gVB9lYklv5ZEpWtmrEd+QG3nBknwN+StoZzTwojcpgqpmfTB/jQCyHosZ1 ZfZkRj9Qou/OKX1gKEu5cLUYaNC1saDyeyY1I5RdJa+18gfQOp0qHzNG8jWuSw6ijmqC ScCA== 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=ctgFRMUCJ0CDMrWzPuN/mME5EPeVQIp5wNjYO6KRDeE=; fh=H08zOZeRe9lSRv5jEq+jNppGIj5JZi7vlc6rubvMhTA=; b=I9/TEICmwmFSaWWkptvVnZaEqSUZ/KIEojNoNo88RF0R+V+XOyIedviWl9Kw715JuY BTMnDviYXi3UbmYlQamLWrCHpkUiM3tJTzf8tqnddsVzTaYx6GdNEP6w1pKSNt0HEjrn 3AnPX8hoAmtyKqazLIc4rAavHCTiXyKb1VdqiajnKr0HC5l/O151BH0IVCZYhQXvoy8I gbL6662VD0QGQQZRVqnZqX/D0S3MOn4UmvWYJGgHKuCyBFkSYpOkCpqlFNTLxWLB3jZm 1Hj89fbHEJV04Dh9ACgcicPooHUhV5BWGy/UsZA9ZzHykbMN73Dl2FUrDHVU9Gukn1mU wgdA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=nYOZ5tgY; 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-116651-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-116651-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id l2-20020a656802000000b005d9b919b94asi1335441pgt.311.2024.03.25.09.29.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 09:29:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-116651-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=nYOZ5tgY; 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-116651-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-116651-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id A1949B28ADB for ; Mon, 25 Mar 2024 13:29:55 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D6657127B4D; Mon, 25 Mar 2024 10:20:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="nYOZ5tgY" Received: from out-188.mta0.migadu.com (out-188.mta0.migadu.com [91.218.175.188]) (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 E60747F7DC for ; Mon, 25 Mar 2024 07:33:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.188 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711352017; cv=none; b=XQ5VU2Co32+J/ai3BlNZBc7TAVqgn33/7lkEmrziBtcF2QO7yYfeWHWy5bx/mKe2AtcsX/wkZ0Qp8VN2cG6NZ05opBwRxkVizUQcFzd4cEKJruJ77ZkzoPtUOcR91Rj+g7BTO/4jzbqxIDhg1l0qO0JxwsxCLnjlfijKC+1Qng8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711352017; c=relaxed/simple; bh=3xEpE8MPeOQczZWC9N9uOK22QwblH0Uvs1dXkOkKnks=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=EGOqCRWN39i/BA6BXEAlKzPr+9z1N/pouq4CjfkTzwS7ap68ktf8CF9nF316HgXbdNPKgAXJyqbdFlkb80FN41tQ0ttdf3DGi9Bas795x3qI/KowAscNGxiRpX1ux+kdxAdQEy6TwBSJno1wykS8LyhJTrkjbIOu7pIIe9edfZM= 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=nYOZ5tgY; arc=none smtp.client-ip=91.218.175.188 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: <1e7ce417-b9dd-4d62-9f54-0adf1ccdae35@linux.dev> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1711352010; 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=ctgFRMUCJ0CDMrWzPuN/mME5EPeVQIp5wNjYO6KRDeE=; b=nYOZ5tgY1AgWEnnHbQVvCpy/Q56YwMgJljrZf4BVb9/vSI51TuLIp6kJUckO2S4IeTtqzW 0KIZqjXqZxZ4tX4M4k3cENv0IlY6jsymonu/px0/Gfx63utX6LmoxTKZ/HzpSOlC4ilThN YPGJOr2LXaZJQCfDWI6kNSeJFRSbe8s= Date: Mon, 25 Mar 2024 15:33:20 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Subject: Re: [PATCH] mm: zswap: fix data loss on SWP_SYNCHRONOUS_IO devices Content-Language: en-US To: Yosry Ahmed , Barry Song <21cnbao@gmail.com> Cc: Johannes Weiner , Andrew Morton , Zhongkun He , Chengming Zhou , Chris Li , Nhat Pham , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Kairui Song References: <20240324210447.956973-1-hannes@cmpxchg.org> 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/3/25 15:06, Yosry Ahmed wrote: > On Sun, Mar 24, 2024 at 9:54 PM Barry Song <21cnbao@gmail.com> wrote: >> >> On Mon, Mar 25, 2024 at 10:23 AM 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 >> >> Acked-by: Barry Song >> >>> >>> 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? >> >> It seems that Kairui's patch comprehensively addresses the issue at hand. >> Johannes's solution, on the other hand, appears to align zswap behavior >> more closely with that of a traditional swap device, only releasing an entry >> when the corresponding swap slot is freed, particularly in the sync-io case. > > It actually worked out quite well that Kairui's fix landed shortly > before this bug was reported, as this fix wouldn't have been possible > without it as far as I can tell. > >> >> Johannes' patch has inspired me to consider whether zRAM could achieve >> a comparable outcome by immediately releasing objects in swap cache >> scenarios. When I have the opportunity, I plan to experiment with zRAM. > > That would be interesting. I am curious if it would be as > straightforward in zram to just mark the folio as dirty in this case > like zswap does, given its implementation as a block device. > This makes me wonder who is responsible for marking folio dirty in this swapcache bypass case? Should we call folio_mark_dirty() after the swap_read_folio()?