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 BEAAFC76196 for ; Thu, 6 Apr 2023 12:20:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2FB146B007B; Thu, 6 Apr 2023 08:20:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2AB1F6B007D; Thu, 6 Apr 2023 08:20:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 19A7F6B007E; Thu, 6 Apr 2023 08:20:29 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 08BF16B007B for ; Thu, 6 Apr 2023 08:20:29 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id CAB1714061B for ; Thu, 6 Apr 2023 12:20:28 +0000 (UTC) X-FDA: 80650874136.07.005C3AE Received: from out30-99.freemail.mail.aliyun.com (out30-99.freemail.mail.aliyun.com [115.124.30.99]) by imf16.hostedemail.com (Postfix) with ESMTP id 2A7D3180004 for ; Thu, 6 Apr 2023 12:20:25 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=alibaba.com; spf=pass (imf16.hostedemail.com: domain of rongwei.wang@linux.alibaba.com designates 115.124.30.99 as permitted sender) smtp.mailfrom=rongwei.wang@linux.alibaba.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1680783627; 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; bh=IxDubS0b3WS3vujItEGK5TLb0LAOCHc2DCL4aFGE7hQ=; b=cv6AQShi2zXLgGyvFFpQXRtaQATfcyOTvFP74QcQZ6O4PwXd6LbMTcbv1diStqf0dBipSe T39t71nR/OVy8E7PPTr29HQvRlGQkI3SwBWW77B646LZ31s58eu5YO7GD+Tf6WTH/wvEqg /1LOa9lCnBC1r2m/pxc5sLoIViwZJzs= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=alibaba.com; spf=pass (imf16.hostedemail.com: domain of rongwei.wang@linux.alibaba.com designates 115.124.30.99 as permitted sender) smtp.mailfrom=rongwei.wang@linux.alibaba.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1680783627; a=rsa-sha256; cv=none; b=n5MGwvYX9+JqDOM7DiNIX4VdoL4dVUzROa4s5Ox0y5gsoz3ucwFID2n23wjSnDeBk4xdJG ilxoVjyoL+nKu4AXiEvGecioyngSwbcHtILsx2fz11iA471iU0GQm/bwLSWeHvxnX+wKN0 /1IL4rw08gmSD5LPCOZ1/KXB/WzzZCc= X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R111e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018045176;MF=rongwei.wang@linux.alibaba.com;NM=1;PH=DS;RN=7;SR=0;TI=SMTPD_---0VfT7z72_1680783614; Received: from 30.221.129.255(mailfrom:rongwei.wang@linux.alibaba.com fp:SMTPD_---0VfT7z72_1680783614) by smtp.aliyun-inc.com; Thu, 06 Apr 2023 20:20:19 +0800 Message-ID: <5963a915-00bd-bedc-14f4-abcd0997ae36@linux.alibaba.com> Date: Thu, 6 Apr 2023 20:20:14 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.9.1 From: Rongwei Wang Subject: Re: [PATCH v2] mm/swap: fix swap_info_struct race between swapoff and get_swap_pages() To: Aaron Lu , Andrew Morton Cc: bagasdotme@gmail.com, willy@infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org References: <20230401221920.57986-1-rongwei.wang@linux.alibaba.com> <20230404154716.23058-1-rongwei.wang@linux.alibaba.com> <20230404122600.88257a623c7f72e078dcf705@linux-foundation.org> <20230406065809.GB64960@ziqianlu-desk2> Content-Language: en-US In-Reply-To: <20230406065809.GB64960@ziqianlu-desk2> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 2A7D3180004 X-Stat-Signature: cq59iu6o1cu4jjtkam4q1heeandpo38c X-HE-Tag: 1680783625-104183 X-HE-Meta: U2FsdGVkX19HbOjhlhRguZcWtOMmIuV+0amsa4U8mbZhRjut58rbwQplbrZavQ3IsnOjnUonQKVjVHskuHRIoNUNc3wjJDyMzPI1BeOI0fEL4kMD4bMj62S4y9h77uuLdx+jVfZzsWzHFPHnUZr5/lss5muyIdi2Dj995hTOYOWdAwKw/swByMgqHAfYHa11vBcUkoOkySvnTjHij0CLTK3qTiFP8ZzW2nyLW2949p16xqm89IVpNwbbdOl89chrB2fk0EdmEaDGIz+iDoxH5Q8M2n/O/8YewgxO3iLbgvPoVbDgm15WVJVeWZAx3divlAsPQbjlfHlG4PMKuJP7mRJTv48sgXekUp9dhi82zP2zNmP0jT7PWd793nTZFjSNj9wSEUIIK2oANGxkLzWGISQbHK4g+SZH9Ro4QXSWL+NKBuqS4r00Jyi4RDz2sYosniAwdSDu0drihaJI8RYRKYxFql6ApSed8rajec9XEVRN9SwJF3ZrfLaoywfM5aznQ5ULpME77ajfBaVAJoDQWZYzwYHWFp8nlzbWfvgPwHCaBtX8QKC0KocrHTeINb3jyfm+Hbk1I53vzuG+WmdAk4CPOoMA9TJiOm1TUPOkEwnWus5E2qXF6LS0S5RsRlhZXhHyF4v1xZ9rpBWSIbQS8q2NIK16Y6SRXWfQD+l6O16s6Tatwel8hvZVTrO5nl9pThkMXM6+CdHP5ONxsElmSMNNTXrv4JtZaQ83IUgGTs8ycdiVsUq0dUQICPdazf6WsB8BfMQPDG+hcpSJlUP61Jlgk8L1TwO9AmzWqNriwZ094AYsw0MBT7ciARp47Zzt344L0avonaN9OPrpFbHLSF2Dt6J3l3ZaSHfj98UrCz4kw7xsZPwvx+t9VgNtNzbDyCYxjzDZ/EV+F7m0ZZzwxNHT5eg/XqrHxzxaK1FmBHsqk8B+oq2JhK75IWNBStlWQfrttEtLf1jDhcI2hIf LSxVGueN oezZPBjO+nWseWqpaJ1wiPJzgNxefrnpMdbZi+C7lzSDYbpNuvvGkrlonaYDiH6OPeoqA3WBK2y3lz2BxHT13q1ytes4wbrQvUWTrIThF5kyLZWErhROUdJ9n+hwQX1wiCU69xjK9EkiuM2R+8WGSqP7A1w== 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: > It doesn't appear to be the case. For one thing, the problematic code > that removes the swap device from the avail list without acquiring > si->lock was there before my commit and my commit didn't change that > behaviour. For another, I wanted to see if the problem is still there > without my commit(just to make sure). > > I followed Rongwei's description and used stress-ng/swap test together > with some test progs that does memory allocation then MADVISE(pageout) > in a loop to reproduce this problem and I can also see the warning like > below using Linus' master branch as of today, I believe this is the > problem Rongwei described: Hi, Aaron, I can sure this is that bug, and the panic will happen when CONFIG_PLIST_DEBUG enabled (I'm not sure whether you have enabled it). > > [ 1914.518786] ------------[ cut here ]------------ > [ 1914.519049] swap_info 9 in list but !SWP_WRITEOK > [ 1914.519274] WARNING: CPU: 14 PID: 14307 at mm/swapfile.c:1085 get_swap_pages+0x3b3/0x440 > [ 1914.519660] Modules linked in: > [ 1914.519811] CPU: 14 PID: 14307 Comm: swap Tainted: G W 6.3.0-rc5-00032-g99ddf2254feb #5 > [ 1914.520238] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.16.1-2.fc36 04/01/2014 > [ 1914.520641] RIP: 0010:get_swap_pages+0x3b3/0x440 > [ 1914.520860] Code: 48 8b 4c 24 30 48 c1 e0 3a 4c 09 e0 48 89 01 e8 43 79 96 00 e9 b2 fd ff ff 41 0f be 77 48 48 c7 c78 > [ 1914.521709] RSP: 0018:ffffc9000ba0f838 EFLAGS: 00010282 > [ 1914.521950] RAX: 0000000000000000 RBX: ffff888154411400 RCX: 0000000000000000 > [ 1914.522273] RDX: 0000000000000004 RSI: ffffffff824035cb RDI: 0000000000000001 > [ 1914.522601] RBP: ffff888100d95f68 R08: 0000000000000001 R09: 0000000000000003 > [ 1914.522926] R10: ffffffff82a7a420 R11: ffffffff82a7a420 R12: 0000000000000350 > [ 1914.523249] R13: ffff888100d95da8 R14: ffff888100d95f50 R15: ffff888100d95c00 > [ 1914.523576] FS: 00007f23abea2600(0000) GS:ffff88823b600000(0000) knlGS:0000000000000000 > [ 1914.523942] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 > [ 1914.524206] CR2: 00007f23abbff000 CR3: 0000000104b86004 CR4: 0000000000770ee0 > [ 1914.524534] PKRU: 55555554 > [ 1914.524661] Call Trace: > [ 1914.524782] > [ 1914.524889] folio_alloc_swap+0xde/0x230 > [ 1914.525076] add_to_swap+0x36/0xb0 > [ 1914.525242] shrink_folio_list+0x9ab/0xef0 > [ 1914.525445] reclaim_folio_list+0x70/0x130 > [ 1914.525644] reclaim_pages+0x9c/0x1c0 > [ 1914.525819] madvise_cold_or_pageout_pte_range+0x79f/0xc80 > [ 1914.526073] walk_pgd_range+0x4d8/0x940 > [ 1914.526255] ? mt_find+0x15b/0x490 > [ 1914.526426] __walk_page_range+0x211/0x230 > [ 1914.526619] walk_page_range+0x17a/0x1e0 > [ 1914.526807] madvise_pageout+0xef/0x250 > > And when I reverted my commit on the same branch(needs some manual edits), > the problem is still there. > > Another thing is, I noticed Rongwei mentioned "This problem exists in > versions after stable 5.10.y." in the changelog while my commit entered > mainline in v4.14. > > So either this problem is always there, i.e. earlier than my commit; or > this problem is indeed only there after v5.10, then it should be something > else that triggered it. My qemu refuses to boot v4.14 kernel so I can > not verify the former yet. Me too. The oldest kernel that my qemu can run is 4.19. BTW, I try to replace 'p' with 'si' today, and find there are many areas need to be modified, especially inside swapoff() and swapon(). So many modifications maybe affect future tracking of code modifications and will cost some time to test. So I wanna to ensure whether need I to do this. If need, I can continue to do this. Thanks.