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 9B39BE7718B for ; Mon, 23 Dec 2024 12:03:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2C5226B0095; Mon, 23 Dec 2024 07:03:02 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 2743F6B0098; Mon, 23 Dec 2024 07:03:02 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0EE8D6B009C; Mon, 23 Dec 2024 07:03:02 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id E09746B0095 for ; Mon, 23 Dec 2024 07:03:01 -0500 (EST) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 72FD9A178A for ; Mon, 23 Dec 2024 12:03:01 +0000 (UTC) X-FDA: 82926086922.05.DC421C3 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by imf25.hostedemail.com (Postfix) with ESMTP id B6908A0019 for ; Mon, 23 Dec 2024 12:02:31 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b=Q2MOZ2Ry; spf=pass (imf25.hostedemail.com: domain of donettom@linux.ibm.com designates 148.163.156.1 as permitted sender) smtp.mailfrom=donettom@linux.ibm.com; dmarc=pass (policy=none) header.from=ibm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1734955339; 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=MLRA0p30L+Wd+5ALFuQw+pXVfJEh6SLA95cewsEpSVM=; b=vqAR11K+YXemfxjQLERNZoZ3TIfSoBEj/Qh92ipCpLteW8P34SMjurA232N1LRUVTISp/q 4Cdnkppp2jk997cThsreIsEPHQyIU6kYgqpE4RqLTa179X9EOnR2NHQ+p/5pc7VwKjN34c A3AX0RrMEzFOR2HUfjeU9BDQnuxAKbc= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b=Q2MOZ2Ry; spf=pass (imf25.hostedemail.com: domain of donettom@linux.ibm.com designates 148.163.156.1 as permitted sender) smtp.mailfrom=donettom@linux.ibm.com; dmarc=pass (policy=none) header.from=ibm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1734955339; a=rsa-sha256; cv=none; b=y1J6n7ZPIoEWtwCIUaHUZuLX0FD0S6zY6B1gjk4gjByqR6FZqhSC5kJizABZO7HXLd69M9 jeoHXQmAsC+JLI5OnURzgdSY6l+o4slWr89ZO//8IHLYEuhuCWLHKCUDjovqMRS2veN5uN EF5Xk4cR2k7XHTLL3AWeYvuh2gX8GBI= Received: from pps.filterd (m0356517.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 4BN3r2NU020113; Mon, 23 Dec 2024 12:02:47 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=pp1; bh=MLRA0p 30L+Wd+5ALFuQw+pXVfJEh6SLA95cewsEpSVM=; b=Q2MOZ2Ry4KKQ/2puvZgBfb SORcGLHqqjqeLqzw6tKCi7NjuPISADhDbrro3M7sQ/7y+IxPPKLGwiSnO04M6Zmk 8ji8z6SX6KI5PNPUt1vdv+fQTOKdpAs8bEX3z9HDBvmPPlWKFB5RSkAWsqq+JsGz Hio2CHmtAilB4c6EUOIbJCHcMEXirfqJnuaiFeV+zQTMHX7B357G2HjNOx8Ve0sn LsLG3oJ6Tt4vFJ49nYxzs81X3hmcPMvN/2cejGZgvlV8rrbuywTq19N7sC2qEob5 mdOT3fFaLFf37ybsQZgnI3l8qAfEBzIKFKFW0wCxJ39Cy0eyr22HC9b+imwDPW6g == Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 43q0bh1x7k-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 23 Dec 2024 12:02:46 +0000 (GMT) Received: from m0356517.ppops.net (m0356517.ppops.net [127.0.0.1]) by pps.reinject (8.18.0.8/8.18.0.8) with ESMTP id 4BNC2kkx021244; Mon, 23 Dec 2024 12:02:46 GMT Received: from ppma22.wdc07v.mail.ibm.com (5c.69.3da9.ip4.static.sl-reverse.com [169.61.105.92]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 43q0bh1x7e-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 23 Dec 2024 12:02:46 +0000 (GMT) Received: from pps.filterd (ppma22.wdc07v.mail.ibm.com [127.0.0.1]) by ppma22.wdc07v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 4BNA4hFT020548; Mon, 23 Dec 2024 12:02:44 GMT Received: from smtprelay03.dal12v.mail.ibm.com ([172.16.1.5]) by ppma22.wdc07v.mail.ibm.com (PPS) with ESMTPS id 43p8cy5mm9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 23 Dec 2024 12:02:44 +0000 Received: from smtpav04.wdc07v.mail.ibm.com (smtpav04.wdc07v.mail.ibm.com [10.39.53.231]) by smtprelay03.dal12v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 4BNC2hf130933558 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 23 Dec 2024 12:02:43 GMT Received: from smtpav04.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 812B858050; Mon, 23 Dec 2024 12:02:43 +0000 (GMT) Received: from smtpav04.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5075F58045; Mon, 23 Dec 2024 12:02:39 +0000 (GMT) Received: from [9.179.4.44] (unknown [9.179.4.44]) by smtpav04.wdc07v.mail.ibm.com (Postfix) with ESMTP; Mon, 23 Dec 2024 12:02:38 +0000 (GMT) Message-ID: <95b7d92f-a12d-47be-9099-f5efebb56ff2@linux.ibm.com> Date: Mon, 23 Dec 2024 17:32:37 +0530 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] mm: migration :shared anonymous migration test is failing To: Dev Jain , Baolin Wang , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Ritesh Harjani , "Aneesh Kumar K . V" , Zi Yan , David Hildenbrand , shuah Khan References: <20241219124717.4907-1-donettom@linux.ibm.com> <36f9ab13-e057-40a0-8d0b-9939df056fc6@linux.ibm.com> <4d76321e-7905-46e6-8105-f09afde516ff@linux.alibaba.com> Content-Language: en-US From: Donet Tom In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: z7Rq4IdVcds5D16uzkZKbr7-Qb8nGneH X-Proofpoint-GUID: zJz-FekdXfrxyDHLiG7HtaUnAmPevJ8k X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-10-15_01,2024-10-11_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 lowpriorityscore=0 bulkscore=0 priorityscore=1501 spamscore=0 impostorscore=0 malwarescore=0 adultscore=0 mlxscore=0 clxscore=1015 mlxlogscore=768 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2411120000 definitions=main-2412230108 X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: B6908A0019 X-Rspam-User: X-Stat-Signature: op7gqnh3yty61j78wtdjjg5bdhxe6dep X-HE-Tag: 1734955351-762344 X-HE-Meta: U2FsdGVkX18ZvpoXMpR5z9O6JkRq7hR8FOewkSicco+7SzaSsd8asyrwABotLgmG+yYMldSnxT9OVN+PWI9KevqttALAKQucoH8frHqAEqSevLnvihkCCbi4bvsCvPqmpcMLNg+qxoKo5CkIt2W8SS31heTic2EhLPmvRJj/W1qsoxyclaU6IAjksR0WZXvyarZPmEkdBQkUhAm/EnaHSJxoKFzF3fq4QutyNL9WJPTQPtdEA4Xwx4fX6CidMB6XoeZjXoIy5CXHSI4JDv9woUNyW/hb/JuV3U+uA/akTzfEc3gDosGGMApxrHgm+CWqj8FOyQhIqzdSHrmaNSDwRozhX7WgjBhyxoDgpMNp2fiIqUQJy4H/RYB1JoR2Dm5sN55XTL1hPyWVWZSf9EjdMw2s2K2WsJ+lEiaf9hVcplvhwB2qHCOtIHvYY9Uo1GyMYYtPf5tw/96b1w8mHVyR1jkejIEzioE/vIEPL1WXLCG1HMFdkwQreVy9XoA19E9Co5CVnaLCc8tnLqfOix2GFNHNBE9uF86cSgJHynOKwm/PNvg/jdsywjkLxwArhN1yuJp0eHC7R8YcXNqH7h3x6/wo1M7GfbDhwZ6b7rc71iUe0Clf4PBUearBXPkkOGBZyZeVLuHB4GxHX89hB28ZJbFDNnXvJ3HLxhsGnud+JumuV9PSllvYRVs+nn0Kswbm3FJA+Ts2sdIW9XJjQCImC6n2dI/QARy1pflHiHJQ03txCkb06jgYRuVSENuk0jI6UpXr40r/yzNl82HTKA2dyIWjEbO/JBH8oVGQIsSj1wohGmdsiSYgp9+3hs2iyAvyE3AxygfFR+PtSlzc67touXueLFCwc5jSOuV/nJWuYbB/OaejZI1Go1CkHGaPi1D8/Ns1AZkIutzTWxZu6WjiWb30wzOhyyzDigTbItdM13xUZTq5bzDksJDrsL30dDlw3a7MKbPB1CO6UuZ5clj OWHDZ6aU VAWDJHqfswrXDILvyodZyu0TUIsTg9tD7hOmpsIXpbXVwTDraK7cmrmLzH6n2fq27rp4DkkL72ifhVkzIYyiTBbZ3EOkHRCQShm/2lYVHJt5GbZGk+gf7wf+Ydb8KqQRNiR7agY4uStSV1pVGfMcGtvmA5st9Xxyba2pP/TTmogP6lJd7M5kY3WCxxaKDzJ9RuM3axt8XGX/5SezRu3PoPs7beGcP+VPZOOd3GlGHM+IRGrLv5ZBqvc72F25LTMSdgdqK3wf4dWYrQ/gTcU0xbCNqvhpSviLq99Qfqiq1QES/wjw= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000006, 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 12/20/24 10:07, Dev Jain wrote: > > On 20/12/24 9:02 am, Baolin Wang wrote: >> >> >> On 2024/12/20 11:12, Donet Tom wrote: >>> >>> On 12/20/24 08:01, Baolin Wang wrote: >>>> >>>> >>>> On 2024/12/19 20:47, Donet Tom wrote: >>>>> The migration selftest is currently failing for shared anonymous >>>>> mappings due to a race condition. >>>>> >>>>> During migration, the source folio's PTE is unmapped by nuking the >>>>> PTE, flushing the TLB,and then marking the page for migration >>>>> (by creating the swap entries). The issue arises when, immediately >>>>> after the PTE is nuked and the TLB is flushed, but before the page >>>>> is marked for migration, another thread accesses the page. This >>>>> triggers a page fault, and the page fault handler invokes >>>>> do_pte_missing() instead of do_swap_page(), as the page is not yet >>>>> marked for migration. >>>>> >>>>> In the fault handling path, do_pte_missing() calls __do_fault() >>>>> ->shmem_fault() -> shmem_get_folio_gfp() -> filemap_get_entry(). >>>>> This eventually calls folio_try_get(), incrementing the reference >>>>> count of the folio undergoing migration. The thread then blocks >>>>> on folio_lock(), as the migration path holds the lock. This >>>>> results in the migration failing in __migrate_folio(), which expects >>>>> the folio's reference count to be 2. However, the reference count is >>>>> incremented by the fault handler, leading to the failure. >>>>> >>>>> The issue arises because, after nuking the PTE and before marking the >>>>> page for migration, the page is accessed. To address this, we have >>>>> updated the logic to first nuke the PTE, then mark the page for >>>>> migration, and only then flush the TLB. With this patch, If the >>>>> page is >>>>> accessed immediately after nuking the PTE, the TLB entry is still >>>>> valid, so no fault occurs. After marking the page for migration, >>>> >>>> IMO, I don't think this assumption is correct. At this point, the >>>> TLB entry might also be evicted, so a page fault could still occur. >>>> It's just a matter of probability. >>> In this patch, we mark the page for migration before flushing the TLB. >>> This ensures that if someone accesses the page after the TLB flush, >>> the page fault will occur and in the page fault handler will wait >>> for the >>> migration to complete. So migration will not fail >>> >>> Without this patch, if someone accesses the page after the TLB flush >>> but before it is marked for migration, the migration will fail. >> >> Actually my concern is the same as David's (I did not see David's >> reply before sending my comments), which is that your patch does not >> "rules out all cases". > > > I like this solution but really the proper solution for this one was > to atomically set the migration entry IMHO. > Thank you Dev. I will check and come back on this. > >> >>>> Additionally, IIUC, if another thread is accessing the shmem folio >>>> causing the migration to fail, I think this is expected, and >>>> migration failure is not a vital issue? >>>> >>> In my case, the shmem migration test is always failing, >>> even after retries. Would it be correct to consider this >>> as expected behavior? >> >> IMHO I think your test case is too aggressive and unlikely to occur >> in real-world scenarios. Additionally, as I mentioned, migration >> failure is not a vital issue in the system, and some temporary refcnt >> can also lead to migration failure if you want to create such test >> cases. So personally, I don't think it is worthy doing. > > Agreed, AFAIR the test case starts faulting exactly on those pages > which we want to migrate, making this a very artificial scenario. >