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 905D0C30653 for ; Thu, 4 Jul 2024 06:12:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E4A216B009B; Thu, 4 Jul 2024 02:12:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DF8156B009E; Thu, 4 Jul 2024 02:12:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C99806B00A0; Thu, 4 Jul 2024 02:12:12 -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 AB5876B009B for ; Thu, 4 Jul 2024 02:12:12 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 4AD93C1059 for ; Thu, 4 Jul 2024 06:12:12 +0000 (UTC) X-FDA: 82301050104.26.3A8BA1F Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf05.hostedemail.com (Postfix) with ESMTP id AF48810000E for ; Thu, 4 Jul 2024 06:12:08 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=none; spf=pass (imf05.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1720073506; 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=3PJKMJWE74n+d0UtT4Mw0xN19Y/VNJFGXG0Li9a48ec=; b=wZqmY17E/q0m2FAVzwiDMZ2LA0fEQRqbv63tz4csnSSPWrkpDLsuShY+mvGiFOsWVr0ZEz e1GX49GK+CRec+qavIXJFMN2ls+udTLUrFLy8FJ+pD/EhPSDzOM1xh/GWXvUQd1Tdgg31W UEF+moOkXxWljVSdk5qrFQWeVsyeR1k= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1720073506; a=rsa-sha256; cv=none; b=nVzodvzvYjZO4BDZt5NRUyz+3g19szcMrRdIPge6fjzFtRzlIoUgFUj6Dj1HxFob6+1axL DUFFTjgJb46TyJmAuQ80imfdfcvsAzaOAu5gzEm4YOnZBhQx3g5pldp4afRkTl2VxTCgj7 2MoAoiNtX5izzLnxl01ErQdMuLArJBY= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=none; spf=pass (imf05.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com Received: from mail.maildlp.com (unknown [172.19.163.174]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4WF5q42SdSzdg8G; Thu, 4 Jul 2024 14:10:24 +0800 (CST) Received: from dggpemf100008.china.huawei.com (unknown [7.185.36.138]) by mail.maildlp.com (Postfix) with ESMTPS id DA67D140157; Thu, 4 Jul 2024 14:12:01 +0800 (CST) Received: from [10.174.177.243] (10.174.177.243) by dggpemf100008.china.huawei.com (7.185.36.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Thu, 4 Jul 2024 14:12:01 +0800 Message-ID: <7b7f2eb7-953a-4aa0-acb0-1ab32c7cc1bf@huawei.com> Date: Thu, 4 Jul 2024 14:12:00 +0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH hotfix] mm: fix crashes from deferred split racing folio migration Content-Language: en-US To: Hugh Dickins , Andrew Morton CC: Baolin Wang , Nhat Pham , Yang Shi , Zi Yan , Barry Song , David Hildenbrand , Matthew Wilcox , , References: <29c83d1a-11ca-b6c9-f92e-6ccb322af510@google.com> <20240703193536.78bce768a9330da3a361ca8a@linux-foundation.org> <825653a7-a4d4-89f2-278f-4b18f8f8da5d@google.com> From: Kefeng Wang In-Reply-To: <825653a7-a4d4-89f2-278f-4b18f8f8da5d@google.com> Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 7bit X-Originating-IP: [10.174.177.243] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To dggpemf100008.china.huawei.com (7.185.36.138) X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: AF48810000E X-Stat-Signature: i9jqety4u3wrumyuyhg8pa1gsakicrgh X-HE-Tag: 1720073528-75237 X-HE-Meta: U2FsdGVkX1++EPuBvDBj4SJDRETSijCCwSdou+iRGfWFZw9WAIMz372MFyYlaUCb0+EMx9EG1mmjxShBuIcmcM8yZMS1sKAi33Ur96kdbPMitCF6pSIidkxjN8AkgO09ap2UdKuKf3N+s3efB9JIUwpCbXW7Lwd/snPYr/Ui0/BQ0IvOTdLOIjMDbDzDGHNa2DNp6jaswjcYUDxDZj5CaTPoatwfN3MEJVVy8LNcKLIh4kPJ/dvfKe4NggDr+9pfHzh+RGCO1sOiOQol9Y+maZHgIxRkRbMxVXGPdzr0cXwPYFFk0v/Z10PCYhE2nFC5uE81jRolRm7rgFpjXxWWhoMb3opSyaYjOS3zv8LWqJOebEsunoLMU2p9J544zCoKkc8kGLDU8LexjXuJbymxghisDc4eyW07J8eHE1UiDxQjgA+1C9rp++3Ld/Iw01p+3c9cV/qP62+ieooqmZExTMvihUr0vLOkqWPZwbSdOmXd36fA+wx8BgNmDNh2MsKdMwFpdUXPtYnZQuC/EsdD7rGw0JcC+2Yf/ErwPeiPhaeQ9QrN8KVsBrebM8d8wBTMwx2RlmvSpkxjwYsMlxqQbhnOqmZv83n+w7uyo85DDfAWaYWlFJ+g35oIRh7T4CqxUs3Epb3oM62krlTFuwaTEnXAVCrSBcf3wv6H5ojr8T71Kgpx7A+tgwVdXsSjbaneUOJt/7RZmoLMHd5h55jFAoRppPmA1B1lcoTi5Axp5RwZtQiKMcfBPZ/DH0pdLJx4y2ttHohZwoFBl+1ZZdsXFrgWUOYnSp6K3QosYPBcgllnxSCu/ppAn4wV00EG5DnUEK8lJMDBJGnnx1JvDyG1TDu0MkZWsP56/lC9ayg8PsihXzC7Sl+AySmgIfpz/4pa3t7EOKci39anJL7ugSc6Z2UHVYj0wV85Hg55kCL2+iXKH64KlrsLg0aoEUQwXUSbUKOiIKNhZRuyj1eQrTD MPh2CJoK RVriqW0A2cgnaXRXx+6ufWOKnNnKCtVEUc7X0bRU21lwLyfgn8vC3Ca0F/h1aaVAab7BN60h+DCo0bKKaqNlPD6IO0ZYceJc2fYjDp6I5csa3M+Oj6TOysH01rDmGIWRJ6B6TcPANVJAD0onxwFNQLzmnR6ViYUh63y2pQGd4Wyxw9MNjkyueQNqWBltbG6zrNLyL 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/7/4 11:21, Hugh Dickins wrote: > On Wed, 3 Jul 2024, Andrew Morton wrote: >> On Tue, 2 Jul 2024 00:40:55 -0700 (PDT) Hugh Dickins wrote: >> ... > > And perhaps a conflict with another one of Kefeng's, which deletes a hunk > in mm/migrate.c just above where I add a hunk: and that's indeed how it > should end up, hunk deleted by Kefeng, hunk added by me. > >> >> --- mm/memcontrol.c~mm-refactor-folio_undo_large_rmappable >> +++ mm/memcontrol.c >> @@ -7832,8 +7832,7 @@ void mem_cgroup_migrate(struct folio *ol >> * In addition, the old folio is about to be freed after migration, so >> * removing from the split queue a bit earlier seems reasonable. >> */ >> - if (folio_test_large(old) && folio_test_large_rmappable(old)) >> - folio_undo_large_rmappable(old); >> + folio_undo_large_rmappable(old); >> old->memcg_data = 0; >> } >> >> I'm resolving this by simply dropping the above hunk. So Kefeng's >> patch is now as below. Please check. > > Checked, and that is correct, thank you Andrew. Correct, but not quite > complete: because I'm sure that if Kefeng had written his patch after > mine, he would have made the equivalent change in mm/migrate.c: > Yes, > --- a/mm/migrate.c > +++ b/mm/migrate.c > @@ -443,8 +443,7 @@ int folio_migrate_mapping(struct address_space *mapping, > } > > /* Take off deferred split queue while frozen and memcg set */ > - if (folio_test_large(folio) && folio_test_large_rmappable(folio)) > - folio_undo_large_rmappable(folio); > + folio_undo_large_rmappable(folio); > > /* > * Now we know that no one else is looking at the folio: > > But there's no harm done if you push out a tree without that additional > mod: we can add it as a fixup afterwards, it's no more than a cleanup. > Maybe we could convert to __folio_undo_large_rmappable() for !maping part, which will avoid unnecessary freeze/unfreeze for empty deferred list. diff --git a/mm/migrate.c b/mm/migrate.c index ca65f03acb31..e6af9c25c25b 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -412,10 +412,11 @@ static int __folio_migrate_mapping(struct address_space *mapping, if (!mapping) { /* Take off deferred split queue while frozen and memcg set */ if (folio_test_large(folio) && - folio_test_large_rmappable(folio)) { + folio_test_large_rmappable(folio) && + !data_race(list_empty(&folio->_deferred_list))) { if (!folio_ref_freeze(folio, expected_count)) return -EAGAIN; - folio_undo_large_rmappable(folio); + __folio_undo_large_rmappable(folio); folio_ref_unfreeze(folio, expected_count); } > (I'm on the lookout for an mm.git update, hope to give it a try when it > appears.) > > Thanks, > Hugh >