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 8E9E4C54E64 for ; Mon, 25 Mar 2024 07:33:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DD7056B0082; Mon, 25 Mar 2024 03:33:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D877C6B0083; Mon, 25 Mar 2024 03:33:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C4EE26B0085; Mon, 25 Mar 2024 03:33:36 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id B596C6B0082 for ; Mon, 25 Mar 2024 03:33:36 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 471FD80983 for ; Mon, 25 Mar 2024 07:33:36 +0000 (UTC) X-FDA: 81934746432.25.BF081F0 Received: from out-185.mta0.migadu.com (out-185.mta0.migadu.com [91.218.175.185]) by imf28.hostedemail.com (Postfix) with ESMTP id 340D3C0011 for ; Mon, 25 Mar 2024 07:33:33 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=nYOZ5tgY; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf28.hostedemail.com: domain of chengming.zhou@linux.dev designates 91.218.175.185 as permitted sender) smtp.mailfrom=chengming.zhou@linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1711352014; 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=ctgFRMUCJ0CDMrWzPuN/mME5EPeVQIp5wNjYO6KRDeE=; b=qW1snQCnI8QyVNIBuX7ysgleZmtm6Jt73NLtSodEsnydhNq37H1MTABdi9ngzJUhKNOsnM C/jn/SdYLbAokngkgN56HZhNJbzZoRiimzQlUzR/YwvXR4wrPE3PLt+ILq3gWrUQEzuZiP DMLA9WTnZkIgywa6MXGsRx7SNzfbdw0= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=nYOZ5tgY; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf28.hostedemail.com: domain of chengming.zhou@linux.dev designates 91.218.175.185 as permitted sender) smtp.mailfrom=chengming.zhou@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1711352014; a=rsa-sha256; cv=none; b=Lw4ssZsMcnwTcQakVoA/2PAS9jq99ouCYtUadOP2vzG6y3mswFsZEbyb4K9Rt9XI5vLrhe 0ukmgYCjh3sN+aVButLwN3uudBAsBm5jTOvDIB8a2jHaA+JzLGzV+C+EW8WGoiATZnWNeV FNnBcoXh3t0pGEkeSoIxXtTDIfJyVZg= 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 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 X-Rspamd-Queue-Id: 340D3C0011 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: 89tshmgucpfii133t9dpqtgskrknqxz6 X-HE-Tag: 1711352013-886401 X-HE-Meta: U2FsdGVkX1+O0gEbulkpiKmvUsZUig6gYKMLKWnPQKB8p2i0G0lZCWMw5se1aHTyVARPaj/aywxH4z0J5toR4NTDeC356REDtL5cem2DxZdZObCb6uTE/RYA3c3Uy1KompU8feD3sQC9fVduW6SFOEEAeBVveoJWhvjtIDTiiJn1dQX5uSh+qlBXo7IioSYUb1ZO/jcsUG7I64JWx0uZ+L/bG27V2w0yJkQ9x/SKol0yj5ezHJu2maiTQAecx/nzdEKW1VCyjAFeMXDPGSiPHW2spdhzyf0CXzynYUsZf83oprgZjhWqmLlm1BnYye0b/C8O5iNav2ki7ooJKRRFBtQqx83GJCnyhGTD/4isKpf52Qg/aHORIWTYWWQjWqyl4xWsytbEOx7fkVC2pFRkR8ZSCIPQiCG0ivNN/fEGbzTi4wrP1XwzMn8PhH9cqA8bD1qREJfb/Ysn49AiIOvQuI9A7208VUFOgIxez7cgycCTFZWeNstUrHZKI5udh0FqHIKMKdmcaJfl0EinO3J06KOuSpkR5XL+MEXE8Wbdj+lAcMNdSLvwmR9uLBWXD005JaKN4n7IM9sZaIH8BwfCpLe3nVd6i9O1B9f0FWQG+SKO0430hoRqZXoxtWZSdg4VPEG5ljC27PaSkOAsvMtAxgswFDEGXx9Gk9BW94tZg00UZykbMYd5fkXIJXBHPHPSZRKZkoXen/7Hr8ljib2c4SxPKuRGaE2WFoSZ5FzN3s45M9o4Za968Ck07XBpTzp2/lRSswy3LaEu588pRrA76J9M3wPlxqE8juBKYKUeVTFCsGopBDO18c07IV9j7yIj69jxB3pMn5lcltfsiMFoPaNnHeB7Ery/XUF2v6MGdgrNZ/UhJ44OCOtLZeZbjNi0M9K48Z1MdekSMmQKpvKOoA57e4OfjESONLMdOm9MVugmPn/H69IvgBYjP9nY9I7goXXR4h6vvhs6uUUo8qi nB+xxFH4 +p0unhSb0hZcqK9MmZ8QAzjsbVbXJvD4BNfQySPhOgrJzH1uu4RFkCLpqOvQjrx0rqMatGfoQZ3pAj+3BtMkj0owRa0n3XToS+bLtenHNVG051i+2iHSRK7bAJEusCIWuiNLRU9o1UD8r5W8kHqOHtEjJJ7gaOrN7VMAx/aPJ9ofS9KeroPFdEILW9Qb7kL8PyJZo2BclHM967PKrgezxZUsoJrKbjI0zo11OjR8zjnZAEAT9O8jaJFMclixOTxtJIzVeVh6xwN0xn97yiHn2vYOwdwXnYyTwu+Q3XlgTaUY280K1anU5Sj4IOA++9oFh5zeORomilISEGo2r/pvTgQnHPmk83V/0ec+3cugM9V4TrB0IXfJSUA2bLwn5izUbhyNaf13GWMgQSNM= 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/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()?