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 5E8DCCD11BF for ; Sat, 23 Mar 2024 11:28:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A89D36B007B; Sat, 23 Mar 2024 07:28:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A120A6B0082; Sat, 23 Mar 2024 07:28:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 88C326B0083; Sat, 23 Mar 2024 07:28:21 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 70B636B007B for ; Sat, 23 Mar 2024 07:28:21 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 0E3F3A2296 for ; Sat, 23 Mar 2024 11:28:21 +0000 (UTC) X-FDA: 81928080402.01.3FD66EE Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf24.hostedemail.com (Postfix) with ESMTP id 6C97F18000D for ; Sat, 23 Mar 2024 11:28:18 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=lMx0lSVF; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf24.hostedemail.com: domain of chrisl@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=chrisl@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1711193299; a=rsa-sha256; cv=none; b=Guo1LzKYhQrYFR2f/hgoCGLXKCPKdhwl5NoswIj1ppO31vYa2jBPX0AzIMW83ghhwTe4qr IvUHu3Bq3pAcAghi5SAqO4EgZJVMAJ48i8uwI4egNzs9rsJdhCRXWQzpw/8aXJbbX84tp7 Mau9vCrw0jQLWPu/TxTklSOND/z3PJc= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=lMx0lSVF; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf24.hostedemail.com: domain of chrisl@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=chrisl@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1711193299; 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=pJVFGJ9zilm3aYUKM2UJY9VfDicbx9hFUA/z40zo0XE=; b=vbOocht0tj5+qROJ0ee0/leolWZARn4u+b+7G50KMADlcenYflXjhqsqTfu/j/i6bQnXwp jCjlZCupfPmmxqSgQGICrDWL64PPmzmEn7SbMEdaOjbATaTPAkHvbdjmxmw4J1veE4Ag+G Pdqh93jas0RwDmmA5RsX6lJXOYT+/Rg= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id CEC53CE09AE for ; Sat, 23 Mar 2024 11:28:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0B843C433F1 for ; Sat, 23 Mar 2024 11:28:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711193293; bh=As3QTtFQjPriP4xPog4WF/44GwMJq9eYqzBnelWaQvU=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=lMx0lSVFnDTWn8dYQPYLR5KIcwwretp5rbnwtX9z+FAUuoa5MUXTU6FaiW1BqD3fK BC3zP0EB8cWB1vELu4QFcD0fTocUffmE/dwZyj/LSmIlVtgaWlTeixVt1Mysj9g0ig QUAYMyAcHZEuJntwy7b3SjqsGNLAZcSEYMtAHAEluPGkM8sO2kuPUIzLKCvfD7gjQt /Loh2BjrDGfoWRwKSRVyVmro6/m/SkR5CSFtdv0NwVSC/9ChNTp/kiCiGjWsF8GscX nwCAhGrMU73in78r6cnfHv0zTmAaAGkcHGWNz4sJSDsLg9NnREkMVWulsx1zutbJ0y lpr68ewsN5vJQ== Received: by mail-il1-f177.google.com with SMTP id e9e14a558f8ab-36885693b5bso183675ab.1 for ; Sat, 23 Mar 2024 04:28:13 -0700 (PDT) X-Forwarded-Encrypted: i=1; AJvYcCULlcrWqVwFGygdFe8OFEUsHLF1MeZ8FrKscRhzFFdTJ8edaSc1UeWncADIozBFttaohfc9hUj2NvbGrY8CFGaSbAM= X-Gm-Message-State: AOJu0YxsNuYJVRC8sZVKkUk3DlcKGkNYjCEbgEfSgkCtcs1wAmBaan5w YVy6ZCxZZ1PQ5K/BzStOb0xLZrVDE3YsBUFO6kjS/WIxyb+NyGybfxK0epo8QrNL8NnDQttmYnN bGqtnj/LcxmyVhUoecWXBUbxusHpCI24kgrc/ X-Google-Smtp-Source: AGHT+IFSbHqGhnVbCPAPtU3zGZr2Ha3zthGBRjjSBMW9y6kkZV7nM3zIDanQVNciPtvQvymewZPQj/BD2Y1WBWz3XZg= X-Received: by 2002:a05:6602:1dc3:b0:7d0:489a:63fb with SMTP id hk3-20020a0566021dc300b007d0489a63fbmr14758iob.4.1711193292353; Sat, 23 Mar 2024 04:28:12 -0700 (PDT) MIME-Version: 1.0 References: <01b0b8e8-af1d-4fbe-951e-278e882283fd@linux.dev> In-Reply-To: From: Chris Li Date: Sat, 23 Mar 2024 04:27:59 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [External] Re: [bug report] mm/zswap :memory corruption after zswap_load(). To: Barry Song <21cnbao@gmail.com> Cc: Yosry Ahmed , Zhongkun He , Chengming Zhou , Johannes Weiner , Andrew Morton , linux-mm , wuyun.abel@bytedance.com, zhouchengming@bytedance.com, Nhat Pham , Kairui Song , Minchan Kim , David Hildenbrand , Ying Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 6C97F18000D X-Stat-Signature: 1ao3k86p8za4mpc5hzgo17esnwhts8nw X-HE-Tag: 1711193298-876024 X-HE-Meta: U2FsdGVkX18sn0wCwIN1tl4EHRFqvqJvHWGwN5InIbTbmbh6wnsup8tKgCUMoebIUaKlNCX7KaQuWu7prfVA0VHN4RFcj3xAZVSBmkZwuaUfzv6emDIpw9mioxBSKY8N8gwkrCJb5BLg54AkvNhVwplq0ssVO+mxlMibJ2c7ykr/QJsun5SrCKrMbM2iY2Ok99/9yy3xTljAfek9Ca2OsYTH898lCtHb42UwCiAXTxlzhBf2QgkDZKYkGUk2DuY7o73eBKvO5cAhJfYW/ncta2PxP/M/TDZZm/3dbQ67oDt0TAyR2lxTxzQcv0J+qEIjq24ErLr6NN8yEUaHau/FAI5DUuoGJj5Exyazhf29+XeHtdGzLJC2MuqmNoCgeGgPvXFfWrTR3A4Mi8lIO5lxY+mJ9yDZYijRUtpiK+DtU6rb+H5U2eaJYWkavaBpYkMu4K8hWD179fMRL47X0lYjEpI7voNAcpbFN02yxEuXmc67y7bzfsNHeSi5ihaT/975j3Nd8JhL5NZbGsB928ao0asELVaVmytr3Y9hPX/P7lytxNhit9QiAOpuRzmfphc7BF4ZR2skaA4v7qWyOQRMrSNqmktmmsdFKUOwfZoTFYsxehARpzBYor2Sn39OIoRuA5bzGjkBx0Fn3EXAx3kHjMpbUGfrJzZFycetpGjk1J+74MwvJ3Tanmw8abT1Ar4v+iygx9Eit049PHuNtgU4anBhMnIoFWqBYC/vAoaT/f0OVt9InSMYFbVKGgXJGbXGIIirwZCnEP9CVXyhQFoV30SnI+7q/hyz46VpXHWylw/40GQulvNn3YRkqSBpQCjK2tU1KzD9dKGUKPyF5z3Gj0J6wHj66FFLtSGfGuY4szzgYHB6x0vX2oUKF/o1iN3O2BpdnZRD/i4+hNtEfwzJnDlZCWRnoPqDanP5T5INbZg/hF9jJc7zs2XYpX78KpLM/QStw3lK1QcJQTOEQrS 50utGp2R M2LsX4edPCJC8G9cVB2tGOBQ+DFdgBtwHJT5jefuqeCwKJ7HBAPpuNdSP4J0UT5MqXNdKS3+IZwLEr4dm/EsP7LoL9+AQr8YTv6//IN3vp8ePk3RneNh0Uez8C+VxUWE+fvvZznZIkqWTyERzot0g7xtx8PtgOvJOdnJ/uiRex91i9O158/nQAtHIBj1MiJYBXBsZGOrNfxBnmzssIQGC0Mmcw+1k/2yPSzqRyNXahXjFYBSaVzfh3fAmZ+IT7uSiHp/BALkX+zxJh0plkFXtFajNTAUFomqgUF82ezra+zHl1BWWzbgGBZ5tI/eEAmAiRecm0zJppPsVYaIDuV4jrhevjFgsFYUjQ1dp0Yh04qkYTFYoYkdFZymmP5BtgiSLV7aY/fxDf4Z8ZF3sDudr5Jqw/FE5Nia8XMU1RUZ+CSescdM= 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 Sat, Mar 23, 2024 at 3:48=E2=80=AFAM Chris Li wrote: > > On Fri, Mar 22, 2024 at 5:35=E2=80=AFPM Barry Song <21cnbao@gmail.com> wr= ote: > > > > On Sat, Mar 23, 2024 at 12:42=E2=80=AFPM Yosry Ahmed wrote: > > > > > > On Fri, Mar 22, 2024 at 4:38=E2=80=AFPM Barry Song <21cnbao@gmail.com= > wrote: > > > > > > > > On Sat, Mar 23, 2024 at 12:35=E2=80=AFPM Yosry Ahmed wrote: > > > > > > > > > > On Fri, Mar 22, 2024 at 4:32=E2=80=AFPM Barry Song <21cnbao@gmail= .com> wrote: > > > > > > > > > > > > On Sat, Mar 23, 2024 at 12:23=E2=80=AFPM Yosry Ahmed wrote: > > > > > > > > > > > > > > On Fri, Mar 22, 2024 at 4:18=E2=80=AFPM Barry Song <21cnbao@g= mail.com> wrote: > > > > > > > > > > > > > > > > On Sat, Mar 23, 2024 at 12:09=E2=80=AFPM Yosry Ahmed wrote: > > > > > > > > > > > > > > > > > > On Fri, Mar 22, 2024 at 4:04=E2=80=AFPM Barry Song <21cnb= ao@gmail.com> wrote: > > > > > > > > > > > > > > > > > > > > On Sat, Mar 23, 2024 at 8:35=E2=80=AFAM Yosry Ahmed wrote: > > > > > > > > > > > > > > > > > > > > > > On Thu, Mar 21, 2024 at 8:04=E2=80=AFPM Zhongkun He > > > > > > > > > > > wrote: > > > > > > > > > > > > > > > > > > > > > > > > On Thu, Mar 21, 2024 at 5:29=E2=80=AFPM Chengming Z= hou wrote: > > > > > > > > > > > > > > > > > > > > > > > > > > On 2024/3/21 14:36, Zhongkun He wrote: > > > > > > > > > > > > > > On Thu, Mar 21, 2024 at 1:24=E2=80=AFPM Chengmi= ng Zhou wrote: > > > > > > > > > > > > > >> > > > > > > > > > > > > > >> On 2024/3/21 13:09, Zhongkun He wrote: > > > > > > > > > > > > > >>> On Thu, Mar 21, 2024 at 12:42=E2=80=AFPM Chen= gming Zhou > > > > > > > > > > > > > >>> wrote: > > > > > > > > > > > > > >>>> > > > > > > > > > > > > > >>>> On 2024/3/21 12:34, Zhongkun He wrote: > > > > > > > > > > > > > >>>>> Hey folks, > > > > > > > > > > > > > >>>>> > > > > > > > > > > > > > >>>>> Recently, I tested the zswap with memory re= claiming in the mainline > > > > > > > > > > > > > >>>>> (6.8) and found a memory corruption issue r= elated to exclusive loads. > > > > > > > > > > > > > >>>> > > > > > > > > > > > > > >>>> Is this fix included? 13ddaf26be32 ("mm/swap= : fix race when skipping swapcache") > > > > > > > > > > > > > >>>> This fix avoids concurrent swapin using the = same swap entry. > > > > > > > > > > > > > >>>> > > > > > > > > > > > > > >>> > > > > > > > > > > > > > >>> Yes, This fix avoids concurrent swapin from d= ifferent cpu, but the > > > > > > > > > > > > > >>> reported issue occurs > > > > > > > > > > > > > >>> on the same cpu. > > > > > > > > > > > > > >> > > > > > > > > > > > > > >> I think you may misunderstand the race descrip= tion in this fix changelog, > > > > > > > > > > > > > >> the CPU0 and CPU1 just mean two concurrent thr= eads, not real two CPUs. > > > > > > > > > > > > > >> > > > > > > > > > > > > > >> Could you verify if the problem still exists w= ith this fix? > > > > > > > > > > > > > > > > > > > > > > > > > > > > Yes=EF=BC=8CI'm sure the problem still exists w= ith this patch. > > > > > > > > > > > > > > There is some debug info, not mainline. > > > > > > > > > > > > > > > > > > > > > > > > > > > > bpftrace -e'k:swap_readpage {printf("%lld, %lld= ,%ld,%ld,%ld\n%s", > > > > > > > > > > > > > > ((struct page *)arg0)->private,nsecs,tid,pid,cp= u,kstack)}' --include > > > > > > > > > > > > > > linux/mm_types.h > > > > > > > > > > > > > > > > > > > > > > > > > > Ok, this problem seems only happen on SWP_SYNCHRO= NOUS_IO swap backends, > > > > > > > > > > > > > which now include zram, ramdisk, pmem, nvdimm. > > > > > > > > > > > > > > > > > > > > > > > > Yes. > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > It maybe not good to use zswap on these swap back= ends? > > > > > > > > > > > > > > > > > > > > > > > > > > The problem here is the page fault handler tries = to skip swapcache to > > > > > > > > > > > > > swapin the folio (swap entry count =3D=3D 1), but= then it can't install folio > > > > > > > > > > > > > to pte entry since some changes happened such as = concurrent fork of entry. > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > The first page fault returned VM_FAULT_RETRY becaus= e > > > > > > > > > > > > folio_lock_or_retry() failed. > > > > > > > > > > > > > > > > > > > > > > How so? The folio is newly allocated and not visible = to any other > > > > > > > > > > > threads or CPUs. swap_read_folio() unlocks it and the= n returns and we > > > > > > > > > > > immediately try to lock it again with folio_lock_or_r= etry(). How does > > > > > > > > > > > this fail? > > > > > > > > > > > > > > > > > > > > > > Let's go over what happens after swap_read_folio(): > > > > > > > > > > > - The 'if (!folio)' code block will be skipped. > > > > > > > > > > > - folio_lock_or_retry() should succeed as I mentioned= earlier. > > > > > > > > > > > - The 'if (swapcache)' code block will be skipped. > > > > > > > > > > > - The pte_same() check should succeed on first look b= ecause other > > > > > > > > > > > concurrent faulting threads should be held off by the= newly introduced > > > > > > > > > > > swapcache_prepare() logic. But looking deeper I think= this one may > > > > > > > > > > > fail due to a concurrent MADV_WILLNEED. > > > > > > > > > > > - The 'if (unlikely(!folio_test_uptodate(folio)))` pa= rt will be > > > > > > > > > > > skipped because swap_read_folio() marks the folio up-= to-date. > > > > > > > > > > > - After that point there is no possible failure until= we install the > > > > > > > > > > > pte, at which point concurrent faults will fail on !p= te_same() and > > > > > > > > > > > retry. > > > > > > > > > > > > > > > > > > > > > > So the only failure I think is possible is the pte_sa= me() check. I see > > > > > > > > > > > how a concurrent MADV_WILLNEED could cause that check= to fail. A > > > > > > > > > > > concurrent MADV_WILLNEED will block on swapcache_prep= are(), but once > > > > > > > > > > > the fault resolves it will go ahead and read the foli= o again into the > > > > > > > > > > > swapcache. It seems like we will end up with two copi= es of the same > > > > > > > > > > > > > > > > > > > > but zswap has freed the object when the do_swap_page fi= nishes swap_read_folio > > > > > > > > > > due to exclusive load feature of zswap? > > > > > > > > > > > > > > > > > > > > so WILLNEED will get corrupted data and put it into swa= pcache. > > > > > > > > > > some other concurrent new forked process might get the = new data > > > > > > > > > > from the swapcache WILLNEED puts when the new-forked pr= ocess > > > > > > > > > > goes into do_swap_page. > > > > > > > > > > > > > > > > > > Oh I was wondering how synchronization with WILLNEED happ= ens without > > > > > > > > > zswap. It seems like we could end up with two copies of t= he same folio > > > > > > > > > and one of them will be leaked unless I am missing someth= ing. > > > > > > > > > > > > > > > > > > > > > > > > > > > > > so very likely a new process is forked right after do_s= wap_page finishes > > > > > > > > > > swap_read_folio and before swapcache_clear. > > > > > > > > > > > > > > > > > > > > > folio? Maybe this is harmless because the folio in th= e swacache will > > > > > > > > > > > never be used, but it is essentially leaked at that p= oint, right? > > > > > > > > > > > > > > > > > > > > > > I feel like I am missing something. Adding other folk= s that were > > > > > > > > > > > involved in the recent swapcache_prepare() synchroniz= ation thread. > > > > > > > > > > > > > > > > > > > > > > Anyway, I agree that at least in theory the data corr= uption could > > > > > > > > > > > happen because of exclusive loads when skipping the s= wapcache, and we > > > > > > > > > > > should fix that. > > > > > > > > > > > > > > > > > > > > > > Perhaps the right thing to do may be to write the fol= io again to zswap > > > > > > > > > > > before unlocking it and before calling swapcache_clea= r(). The need for > > > > > > > > > > > the write can be detected by checking if the folio is= dirty, I think > > > > > > > > > > > this will only be true if the folio was loaded from z= swap. > > > > > > > > > > > > > > > > > > > > we only need to write when we know swap_read_folio() ge= ts data > > > > > > > > > > from zswap but not swapfile. is there a quick way to do= this? > > > > > > > > > > > > > > > > > > The folio will be dirty when loaded from zswap, so we can= check if the > > > > > > > > > folio is dirty and write the page if fail after swap_read= _folio(). > > > > > > > > > > > > > > > > Is it actually a bug of swapin_walk_pmd_entry? it only chec= k pte > > > > > > > > before read_swap_cache_async. but when read_swap_cache_asyn= c > > > > > > > > is blocked by swapcache_prepare, after it gets the swapcach= e_prepare > > > > > > > > successfully , someone else should have already set the pte= and freed > > > > > > > > the swap slot even if this is not zswap? > > > > > > > > > > > > > > If someone freed the swap slot then swapcache_prepare() shoul= d fail, > > > > > > > but the swap entry could have been recycled after we dropped = the pte > > > > > > > lock, right? > > > > > > > > > > > > > > Anyway, yeah, I think there might be a bug here irrelevant to= zswap. > > > > > > > > > > > > > > > > > > > > > > > static int swapin_walk_pmd_entry(pmd_t *pmd, unsigned long = start, > > > > > > > > unsigned long end, struct mm_walk *walk) > > > > > > > > { > > > > > > > > struct vm_area_struct *vma =3D walk->private; > > > > > > > > struct swap_iocb *splug =3D NULL; > > > > > > > > pte_t *ptep =3D NULL; > > > > > > > > spinlock_t *ptl; > > > > > > > > unsigned long addr; > > > > > > > > > > > > > > > > for (addr =3D start; addr < end; addr +=3D PAGE_SIZ= E) { > > > > > > > > pte_t pte; > > > > > > > > swp_entry_t entry; > > > > > > > > struct folio *folio; > > > > > > > > > > > > > > > > if (!ptep++) { > > > > > > > > ptep =3D pte_offset_map_lock(vma->v= m_mm, pmd, addr, &ptl); > > > > > > > > if (!ptep) > > > > > > > > break; > > > > > > > > } > > > > > > > > > > > > > > > > pte =3D ptep_get(ptep); > > > > > > > > if (!is_swap_pte(pte)) > > > > > > > > continue; > > > > > > > > entry =3D pte_to_swp_entry(pte); > > > > > > > > if (unlikely(non_swap_entry(entry))) > > > > > > > > continue; > > > > > > > > > > > > > > > > pte_unmap_unlock(ptep, ptl); > > > > > > > > ptep =3D NULL; > > > > > > > > > > > > > > > > folio =3D read_swap_cache_async(entry, GFP_= HIGHUSER_MOVABLE, > > > > > > > > vma, addr, &sp= lug); > > > > > > > > if (folio) > > > > > > > > folio_put(folio); > > > > > > > > } > > > > > > > > > > > > > > > > if (ptep)c > > > > > > > > pte_unmap_unlock(ptep, ptl); > > > > > > > > swap_read_unplug(splug); > > > > > > > > cond_resched(); > > > > > > > > > > > > > > > > return 0; > > > > > > > > } > > > > > > > > > > > > > > > > I mean pte can become non-swap within read_swap_cache_async= (), > > > > > > > > so no matter if it is zswap, we have the bug. > > > > > > > > > > > > checked again, probably still a zswap issue, as swapcache_prep= are can detect > > > > > > real swap slot free :-) > > > > > > > > > > > > /* > > > > > > * Swap entry may have been freed since our cal= ler observed it. > > > > > > */ > > > > > > err =3D swapcache_prepare(entry); > > > > > > if (!err) > > > > > > break; > > > > > > > > > > > > > > > > > > zswap exslusive load isn't a real swap free. > > > > > > > > > > > > But probably we have found the timing which causes the issue at= least :-) > > > > > > > > > > The problem I was referring to is with the swapin fault path that > > > > > skips the swapcache vs. MADV_WILLNEED. The fault path could swapi= n the > > > > > page and skip the swapcache, and MADV_WILLNEED could swap it in a= gain > > > > > into the swapcache. We would end up with two copies of the folio. > > > > > > > > right. i feel like we have to re-check pte is not changed within > > > > __read_swap_cache_async after swapcache_prepare succeed > > > > after being blocked for a while as the previous entry could have > > > > been freed and re-allocted by someone else - a completely > > > > different process. then we get read other processes' data. > > > > > > > > This is only a problem when we skip the swapcache during swapin. > > > Otherwise the swapcache synchronizes this. I wonder how much does > > > skipping the swapcache buy us on recent kernels? This optimization wa= s > > > introduced a long time ago. > > > > Still performs quite good. according to kairui's data: > > https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/comm= it/?id=3D13ddaf26be324a7f951891ecd9ccd04466d27458 > > > > Before: 10934698 us > > After: 11157121 us > > Cached: 13155355 us (Dropping SWP_SYNCHRONOUS_IO flag) > > > > BTW, zram+zswap seems pointless from the first beginning. it seems a wr= ong > > configuration for users. if this case is really happening, could we > > simply fix it > > by: > > > > diff --git a/mm/memory.c b/mm/memory.c > > index b7cab8be8632..6742d1428373 100644 > > --- a/mm/memory.c > > +++ b/mm/memory.c > > @@ -3999,7 +3999,7 @@ vm_fault_t do_swap_page(struct vm_fault *vmf) > > swapcache =3D folio; > > > > if (!folio) { > > - if (data_race(si->flags & SWP_SYNCHRONOUS_IO) && > > + if (!is_zswap_enabled() && data_race(si->flags & > > SWP_SYNCHRONOUS_IO) && > > Because zswap_enable can change at run time due to the delay setup of zsw= ap. > > This has the time-of-check to time-of-use issue. Never mind that, I just realized that even if zswap was enabled, the data race does not affect the current swap entry, which already swapped out before the change of zswap_enable. Chris > > Maybe moving to the zswap_store() is better. > > Something like this. > > Zhongkun, can you verify with this change the bug will go away? > > Chris > > > zswap: disable SWP_SYNCRNOUS_IO in zswap_store > > diff --git a/mm/zswap.c b/mm/zswap.c > index f04a75a36236..f40778adefa3 100644 > --- a/mm/zswap.c > +++ b/mm/zswap.c > @@ -1472,6 +1472,7 @@ bool zswap_store(struct folio *folio) > struct obj_cgroup *objcg =3D NULL; > struct mem_cgroup *memcg =3D NULL; > unsigned long max_pages, cur_pages; > + struct swap_info_struct *si =3D NULL; > > VM_WARN_ON_ONCE(!folio_test_locked(folio)); > VM_WARN_ON_ONCE(!folio_test_swapcache(folio)); > @@ -1483,6 +1484,18 @@ bool zswap_store(struct folio *folio) > if (!zswap_enabled) > goto check_old; > > + /* Prevent swapoff from happening to us. */ > + si =3D get_swap_device(swp); > + if (si) { > + /* > + * SWP_SYNCRONOUS_IO bypass swap cache, not compatible > + * with zswap exclusive load. > + */ > + if (data_race(si->flags & SWP_SYNCHRONOUS_IO)) > + si->flags &=3D ~ SWP_SYNCHRONOUS_IO; > + put_swap_device(si); > + } > + > /* Check cgroup limits */ > objcg =3D get_obj_cgroup_from_folio(folio); > if (objcg && !obj_cgroup_may_zswap(objcg)) {