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 09090C54E58 for ; Thu, 21 Mar 2024 09:29:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 717AD6B0083; Thu, 21 Mar 2024 05:29:06 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6C7106B0085; Thu, 21 Mar 2024 05:29:06 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 58E5B6B0087; Thu, 21 Mar 2024 05:29:06 -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 45F9A6B0083 for ; Thu, 21 Mar 2024 05:29:06 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 0F25CA1BED for ; Thu, 21 Mar 2024 09:29:06 +0000 (UTC) X-FDA: 81920522292.28.28A07F9 Received: from out-185.mta0.migadu.com (out-185.mta0.migadu.com [91.218.175.185]) by imf04.hostedemail.com (Postfix) with ESMTP id ED3FA4001D for ; Thu, 21 Mar 2024 09:29:03 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=KGbkZY+N; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf04.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=1711013344; 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=KUi4iHJTHYCLffoLFZu8wjOJUTFFhrTHbYOPA5OzGwA=; b=7vpWodKW/T7jVCVSQPllhzpPdbKiinEzLbprUSRU2KsI9TGtqzCOuAkSCCIJklBvjLNpB2 IBXKug66TE3XNEENDfUshCyD6IgLUmJsSAhMZ6Zp99kml2DGABF6moUD5NW31jNM/BaGde vFcDUwG42GTqxxC52hvoIJnFAhx4c+8= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=KGbkZY+N; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf04.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=1711013344; a=rsa-sha256; cv=none; b=zN89BSVwOhfwmzpX2d7fuJLx5Aq5f2MOmU29A12M/KCzbX3VkfeQFNzBkmN3ALDp6fDGCX 8ALHgU6qvVr7HotTjQANppRZL6E/ht6PQNSTkbcBt0W7z8p1wYRpaFSvq+zvtq11H91FZc tOrbofEq6ClWvPCK0NLGfvkLvRphvn4= Message-ID: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1711013338; 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=KUi4iHJTHYCLffoLFZu8wjOJUTFFhrTHbYOPA5OzGwA=; b=KGbkZY+NuhGpxFJgjpthKf6PZHRh1kDbIW+y1BkPNpfPLqCcL6jlOgMsIiW8GhmWOLTaqc ZU8yP1GQtvkB4HCeIbY8TOXwJEQ3IBiVFzSYQ0FlX7LITN3cIb3nwYbU19P50LJrZaQPPa Lisj3xB/mLlJyby3mznpf4o0y3EKxeY= Date: Thu, 21 Mar 2024 17:28:42 +0800 MIME-Version: 1.0 Subject: Re: [External] Re: [bug report] mm/zswap :memory corruption after zswap_load(). Content-Language: en-US To: Zhongkun He Cc: Johannes Weiner , Yosry Ahmed , Andrew Morton , linux-mm , wuyun.abel@bytedance.com, zhouchengming@bytedance.com, Nhat Pham References: <01b0b8e8-af1d-4fbe-951e-278e882283fd@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-Server: rspam09 X-Rspamd-Queue-Id: ED3FA4001D X-Stat-Signature: r3hqn1c1mrwiuxg7uxs3nhihyqkj7nuh X-Rspam-User: X-HE-Tag: 1711013343-658148 X-HE-Meta: U2FsdGVkX19Ert2qMmsm/dcUjOC/MLZ1Y3N8/tK/9oEaOqz9SqHCpvIHttFqJPSBS5xEV0z+sRLrhjfWu1x2WU9ntToavmUKqrm9p5crJG7HKl2RgrBeelbwDzOYACNDejxXlOMbyyIc4RJY7bxMAo2bdvzVDKydUJrGvHwvoGL1elLwF+oJulb7nik08/w3iGZEPEPSuRMKDgmmR5qEwopwPfgVLTClniTWw6et1Kg3+Us877cKYhxt2cc6GB1sygDiw5GvUBsa8bIsaeVYGtCXcA7tFKETaP9cM8h3R6c4c2jC4gKokQGKl4DsOlbj/Yb2sPRRtrOuhhEI1rquor62xhire7x0u8seyCnawRCsKpDn9Hzh0KmXm1Ug6Zm475V8mdamurSH1ACuc0qiticX+gLO/oQODm1DstnSvjM1rtBDSQHZIOwjAHNtaAZ+pdnHFO4/D+WqNOPbeCmAGFxtqA4r61e3j6qYEAi4k6woW+dsGggA0L9r4uGiJ78//LBOUI0suvepgObTCkXIhBuOVGoZnTcXuso52y6+8hbOsHMuJIpOPdI8PiPQomjvyCsOAT6I0QCqzCy1aOMY8VniuWpkdD1w5winzQNP2RLGkcbGeui1fgVU2+Fj0AoNG6b67BXaeLoxXJyU6KK4Xm/wmBpu717NOnRwFW6QdMHMkF/Ywmux721S4L/5lFr+TfZiMh+ggcXGy2Ho0wvaeT3hxJXUcB3grSIOUno95zx88tkEKO+c7FW689E1q5lKSVsAlAKK6Vggmch7t5fb/TgewRh8IqiUW3MBNCKpNDfzZhGzVd0P02cw0/uneLQR69eoJDADh5Hw9Na8UQ31aSd9WLBZiIQ7+LUdvqoPwxBt1LqQPyzX+3d+JWju3TkA+EeAMpw4ijeUw/7uCp++Bj76Ke8yrmaeWyfM6r3Kb2iDzFp7UQJmyVBzpl4w8FAZYIstKkeR/06XUqCtvpC WLqdGIcZ +Ji27ca3sUrlsBIfYl54ziXAl3QYvSeytmZie/yDqC8OB3YXdk4hTD8tGKjDxkoiSpTYS6eRLl5aGnm4dduAkyfAaSyFy49Bsrfu2YUVvkLiZ1KaxKVi3FhcgQygZ+jvkAnPSxShZ9epLiemuYB4JTov7Eun8slbfpdav 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/21 14:36, Zhongkun He wrote: > On Thu, Mar 21, 2024 at 1:24 PM Chengming Zhou wrote: >> >> On 2024/3/21 13:09, Zhongkun He wrote: >>> On Thu, Mar 21, 2024 at 12:42 PM Chengming Zhou >>> wrote: >>>> >>>> On 2024/3/21 12:34, Zhongkun He wrote: >>>>> Hey folks, >>>>> >>>>> Recently, I tested the zswap with memory reclaiming in the mainline >>>>> (6.8) and found a memory corruption issue related 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 different cpu, but the >>> reported issue occurs >>> on the same cpu. >> >> I think you may misunderstand the race description in this fix changelog, >> the CPU0 and CPU1 just mean two concurrent threads, not real two CPUs. >> >> Could you verify if the problem still exists with this fix? > > Yes,I'm sure the problem still exists with 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,cpu,kstack)}' --include > linux/mm_types.h Ok, this problem seems only happen on SWP_SYNCHRONOUS_IO swap backends, which now include zram, ramdisk, pmem, nvdimm. It maybe not good to use zswap on these swap backends? The problem here is the page fault handler tries to skip swapcache to swapin the folio (swap entry count == 1), but then it can't install folio to pte entry since some changes happened such as concurrent fork of entry. Maybe we should writeback that folio in this special case. > > offset nsecs tid pid cpu > 2140659, 595771411052,15045,15045,6 > swap_readpage+1 > do_swap_page+2135 > handle_mm_fault+2426 > do_user_addr_fault+462 > do_page_fault+48 > async_page_fault+62 > > offset nsecs tid pid cpu > 2140659, 595771424445,15045,15045,6 > swap_readpage+1 > do_swap_page+2135 > handle_mm_fault+2426 > do_user_addr_fault+462 > do_page_fault+48 > async_page_fault+62 > > ------------------------------- > There are two page faults with the same tid and offset in 13393 nsecs. > >> >>> >>> Thanks. >>> >>>> Thanks. >>>> >>>>> >>>>> >>>>> root@**:/sys/fs/cgroup/zz# stress --vm 5 --vm-bytes 1g --vm-hang 3 --vm-keep >>>>> stress: info: [31753] dispatching hogs: 0 cpu, 0 io, 5 vm, 0 hdd >>>>> stress: FAIL: [31758] (522) memory corruption at: 0x7f347ed1a010 >>>>> stress: FAIL: [31753] (394) <-- worker 31758 returned error 1 >>>>> stress: WARN: [31753] (396) now reaping child worker processes >>>>> stress: FAIL: [31753] (451) failed run completed in 14s >>>>> >>>>> >>>>> 1. Test step(the frequency of memory reclaiming has been accelerated): >>>>> ------------------------- >>>>> a. set up the zswap, zram and cgroup V2 >>>>> b. echo 0 > /sys/kernel/mm/lru_gen/enabled >>>>> (Increase the probability of problems occurring) >>>>> c. mkdir /sys/fs/cgroup/zz >>>>> echo $$ > /sys/fs/cgroup/zz/cgroup.procs >>>>> cd /sys/fs/cgroup/zz/ >>>>> stress --vm 5 --vm-bytes 1g --vm-hang 3 --vm-keep >>>>> >>>>> e. in other shell: >>>>> while :;do for i in {1..5};do echo 20g > >>>>> /sys/fs/cgroup/zz/memory.reclaim & done;sleep 1;done >>>>> >>>>> 2. Root cause: >>>>> -------------------------- >>>>> With a small probability, the page fault will occur twice with the >>>>> original pte, even if a new pte has been successfully set. >>>>> Unfortunately, zswap_entry has been released during the first page fault >>>>> with exclusive loads, so zswap_load will fail, and there is no corresponding >>>>> data in swap space, memory corruption occurs. >>>>> >>>>> bpftrace -e'k:zswap_load {printf("%lld, %lld\n", ((struct page >>>>> *)arg0)->private,nsecs)}' >>>>> --include linux/mm_types.h > a.txt >>>>> >>>>> look up the same index: >>>>> >>>>> index nsecs >>>>> 1318876, 8976040736819 >>>>> 1318876, 8976040746078 >>>>> >>>>> 4123110, 8976234682970 >>>>> 4123110, 8976234689736 >>>>> >>>>> 2268896, 8976660124792 >>>>> 2268896, 8976660130607 >>>>> >>>>> 4634105, 8976662117938 >>>>> 4634105, 8976662127596 >>>>> >>>>> 3. Solution >>>>> >>>>> Should we free zswap_entry in batches so that zswap_entry will be >>>>> valid when the next page fault occurs with the >>>>> original pte? It would be great if there are other better solutions. >>>>> >>>>