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 7E248C52D7C for ; Fri, 9 Aug 2024 13:26:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F26D26B0095; Fri, 9 Aug 2024 09:26:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id ED6B76B0098; Fri, 9 Aug 2024 09:26:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D4FD56B009A; Fri, 9 Aug 2024 09:26:25 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id B00516B0095 for ; Fri, 9 Aug 2024 09:26:25 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 2CD69161009 for ; Fri, 9 Aug 2024 13:26:25 +0000 (UTC) X-FDA: 82432781130.13.1E7D80E Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf02.hostedemail.com (Postfix) with ESMTP id DF34380024 for ; Fri, 9 Aug 2024 13:26:22 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=FccGSS0J; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf02.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1723209929; a=rsa-sha256; cv=none; b=2bdtcMQ9nXuDIsIkhthe3EFLGZTXV5E4FAKQU5AvvrY3RU7p2qxGNXo3tnMveQTxkxXAxE TdUlCg8CYSPbJTL+ScmOd9WrCh8zxXGJjF/TyiIIf8hBXnq+XmfpeF+DY4IMEUeax4HbiQ +q3GaU3RrJWOSz7IGYtjgNMVO9KJDHc= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=FccGSS0J; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf02.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1723209929; 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=lakPMiUqJ44ZyLo8Xx7/8fKlcWilAh1p1T11Ui6lAXM=; b=slI1dvo6RKezLBTG9FLxUg6NMMRJf9JeB1mPIWBwDgWiRdskKj4k6vL5KGcyndKfZ6T90A BpKK5yePQ3oSrz1cNTsiOgwja+DaTKeln6EDzwQmqumJOxis9E/oraKEWwOOaDH+5s9moV XEJhy8b18FIYtnioUKUYaR8xeN0mgQ4= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1723209982; 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:autocrypt:autocrypt; bh=lakPMiUqJ44ZyLo8Xx7/8fKlcWilAh1p1T11Ui6lAXM=; b=FccGSS0Jjab3afsZyUtN5xNYMssAaFruAjCIycItTmiN/VBVc/ELrnfvW6uKR3XyT6NdEM 1EYgD7CoscEVjKXb3FepUBNQr9p/bMCePauOhAuNFVzoev4l9P+MA62swBjG3tESZZ84Qu pcAlHoLXs2s1SuPZ1YnwZXC6j3R84zo= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-464-x8l-48gxOPafMrxRWT2pkw-1; Fri, 09 Aug 2024 09:26:21 -0400 X-MC-Unique: x8l-48gxOPafMrxRWT2pkw-1 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-36b356a73fcso1155104f8f.1 for ; Fri, 09 Aug 2024 06:26:20 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723209980; x=1723814780; h=content-transfer-encoding:in-reply-to:organization:autocrypt :content-language:references:cc:to:from:subject:user-agent :mime-version:date:message-id:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=lakPMiUqJ44ZyLo8Xx7/8fKlcWilAh1p1T11Ui6lAXM=; b=vtriFbNuodA0BOum8d5WM1z5hJI27ilOOzQrad0354obygfVU4eBYSCbvKZnKMuxsm crn4ouu6TxthCVUxQdjsXEqhjMSax22h7CxhwNIPiihmmXpUFoZdjfse918+0idLsdPt jOdpVWCByI8BB3hNmSjRPhNKNeceVPYf5rdfLGM39w25n26pJRvlShG0Ep+CqWvX3dxz cKbjMjlHJHML1Bofh4ujKVEKNihNs6294aN0Nh8XsDkFxcEsPys+BGZMyStmCoIi/w18 ctJjlv/BtgGFOcLgVC+f3isMjiQtUl8Y5hwOUQ6omXfCGpee+0GCCHMvYuViNiDC/gMC PtaQ== X-Forwarded-Encrypted: i=1; AJvYcCUQKQZc9kcmmF/nuDTaGPg8jO0zCMuL683sbesBG9TFNxK9ZexD6kjvWt/TeBAQKcOlY41LDcfW7jIXADFKOCg90yY= X-Gm-Message-State: AOJu0YwWxtl54mGFV6qqmUyn/fDdCfbUOxt4aFl3/QtMG0hWPIPun17A LN88Pid96eqYRA6i21K3KhAnJEUlk9rLZA6SKgY9eKVAzPpHvWq72yxAjC0TyH2wINhOobBotZE qpTayAaCZdJYahqlEb8wgCyPlzMcC8bDzEHeNlPKSQlOIeQXN X-Received: by 2002:adf:f412:0:b0:368:6598:131e with SMTP id ffacd0b85a97d-36d5fe778f3mr1586270f8f.38.1723209979501; Fri, 09 Aug 2024 06:26:19 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHrukAb/xfsR/RH8ebSErMNRv1EYUrmJO1ow2M5YNFmsw+EMmuUlt6zYCJnFe9Igb8vkKkI9A== X-Received: by 2002:adf:f412:0:b0:368:6598:131e with SMTP id ffacd0b85a97d-36d5fe778f3mr1586200f8f.38.1723209978914; Fri, 09 Aug 2024 06:26:18 -0700 (PDT) Received: from ?IPV6:2003:d8:2f09:3f00:d228:bd67:7baa:d604? (p200300d82f093f00d228bd677baad604.dip0.t-ipconnect.de. [2003:d8:2f09:3f00:d228:bd67:7baa:d604]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-36d27209196sm5348024f8f.77.2024.08.09.06.26.17 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 09 Aug 2024 06:26:18 -0700 (PDT) Message-ID: Date: Fri, 9 Aug 2024 15:26:16 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Race condition observed between page migration and page fault handling on arm64 machines From: David Hildenbrand To: Dev Jain , Will Deacon Cc: akpm@linux-foundation.org, willy@infradead.org, ryan.roberts@arm.com, anshuman.khandual@arm.com, catalin.marinas@arm.com, cl@gentwo.org, vbabka@suse.cz, mhocko@suse.com, apopple@nvidia.com, osalvador@suse.de, baolin.wang@linux.alibaba.com, dave.hansen@linux.intel.com, baohua@kernel.org, ioworker0@gmail.com, gshan@redhat.com, mark.rutland@arm.com, kirill.shutemov@linux.intel.com, hughd@google.com, aneesh.kumar@kernel.org, yang@os.amperecomputing.com, peterx@redhat.com, broonie@kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, mgorman@techsingularity.net References: <20240801081657.1386743-1-dev.jain@arm.com> <3b82e195-5871-4880-9ce5-d01bb751f471@redhat.com> <92df0ee1-d3c9-41e2-834c-284127ae2c4c@arm.com> <19902a48-c59b-4e3b-afc5-e792506c2fd6@redhat.com> <6486a2b1-45ef-44b6-bd84-d402fc121373@redhat.com> <20240801134358.GB4794@willie-the-truck> <9359caf7-81a8-45d9-9787-9009b3b2eed3@redhat.com> <418e818a-f385-459e-a84d-e3880ac08ad5@redhat.com> <8158c9d6-cbfe-4767-be8e-dc227b29200c@arm.com> <79924d5b-b807-440a-a6e8-8f0ae13aa04b@redhat.com> Autocrypt: addr=david@redhat.com; keydata= xsFNBFXLn5EBEAC+zYvAFJxCBY9Tr1xZgcESmxVNI/0ffzE/ZQOiHJl6mGkmA1R7/uUpiCjJ dBrn+lhhOYjjNefFQou6478faXE6o2AhmebqT4KiQoUQFV4R7y1KMEKoSyy8hQaK1umALTdL QZLQMzNE74ap+GDK0wnacPQFpcG1AE9RMq3aeErY5tujekBS32jfC/7AnH7I0v1v1TbbK3Gp XNeiN4QroO+5qaSr0ID2sz5jtBLRb15RMre27E1ImpaIv2Jw8NJgW0k/D1RyKCwaTsgRdwuK Kx/Y91XuSBdz0uOyU/S8kM1+ag0wvsGlpBVxRR/xw/E8M7TEwuCZQArqqTCmkG6HGcXFT0V9 PXFNNgV5jXMQRwU0O/ztJIQqsE5LsUomE//bLwzj9IVsaQpKDqW6TAPjcdBDPLHvriq7kGjt WhVhdl0qEYB8lkBEU7V2Yb+SYhmhpDrti9Fq1EsmhiHSkxJcGREoMK/63r9WLZYI3+4W2rAc UucZa4OT27U5ZISjNg3Ev0rxU5UH2/pT4wJCfxwocmqaRr6UYmrtZmND89X0KigoFD/XSeVv jwBRNjPAubK9/k5NoRrYqztM9W6sJqrH8+UWZ1Idd/DdmogJh0gNC0+N42Za9yBRURfIdKSb B3JfpUqcWwE7vUaYrHG1nw54pLUoPG6sAA7Mehl3nd4pZUALHwARAQABzSREYXZpZCBIaWxk ZW5icmFuZCA8Z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x7dZU1Xf8HFuE+UZ5UDHDTnwgv7E th6RC9+WrhDNspZ9fJjKWRbveQgUFCpe1sa77LAw+XFrKmBHXp9ZVIe90RMe2tRL06BGiRZr jPrnvUsUUsjRoRNJjKKA/REq+sAnhkNPPZ/NNMjaZ5b8Tovi8C0tmxiCHaQYqj7G2rgnT0kt WNyWQQ== Organization: Red Hat In-Reply-To: <79924d5b-b807-440a-a6e8-8f0ae13aa04b@redhat.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: DF34380024 X-Stat-Signature: p8q3dt7ceayfooapdpu3ffw8r6g1y1ms X-Rspam-User: X-HE-Tag: 1723209982-567864 X-HE-Meta: U2FsdGVkX1/f17aY/GSTrINKezYhkss8+vlc7uF9GdsUvHTBwoRllVjd91Cdt6YtgWTDM8cRHkCM9/Ud5kUI+mBwSXfrQIoPoP8SR7oGS93mifk4yFufm2EA5obZ2jKcTALhfN2i9Sr4eTV0Q6sFqVmQBwLjjNquCxxMskFlHHX3ZKl9YS4On+HNA/igs+/I97r+QpmrGcTyktUF2rnnN9XvyPFtw86iEcXihVWtxzz8bl7SIo2KGbVXUnInxQulLabIUPidXGMgytc3rEYEvGFCi+TTO3hu2bIOaGDOeBXBUN5FRPvab3JM7U4l2sEGHLeZtBEc5JqX1YjIBwg6xxnxuQXDB/ns334YeCeBn/b2ABKT+Z7CkG6fy4X674RnbZlvXOVGG6gUVGbCwCrZXsnL0VAcYmcaLXRtA0gBVbji5EoQjOMmCAFuOwXe0C73lY9CVYxOnOsKDLU+vZnlK1f3bhmZE20/LR6lyGu5TCpadWbhdq7habegMDQMKthvQ68qzQvxpGou3t/EZNRf/SvyqEim2h1H1bZa1OU4RsQgfZG+c9N/G85+ULvE4M4CsUtsyeiU8QQ/55C5GDCDOGuWYaC81kQcUmGILETdMy9MFiJ1RgrpRWI++Z/zvxUrPDsaUwuQyArsXYgCj8PJQ++RWQnXiQ+5j3Gzk3T6ZkNeekZHizHzWa/iThGmRQnnnCvT9yzpSm7gfcYDwrYkQFh9EK7KCgAAIhcemE4jU/R7A4vNgJ8A1mOA500793vtapOkg4VWW4nBd/3fb6X7pjk8xIeYNss29qFKonW9es6yuvWiheaH7nh7zKnoO6KIjGVtochRIRIt8B3vEE8vd2q9tEiCDi7Iq7ScbknMSsNXaLj+d8j8heD2rb1O7+E0vtSaV/PomFnNNC6fOaWfU/ZOW3+JMOKertNHKZ5WbKVWbyW/OG1Hzmx39CEb656Ijs5pYo8wwdxO4sTaaaz dFOthWOW cToMlXPV3pEF8lECTFIJ9Y8+lZB+3jkzQAP4H/8IS+rPsTxYt72pTqmDw7ipc5h7TcFAsr7+pJgHq+qi4Jh5a05CiBAVD1E6b66EhZVp2yJVlNwjd5pTeSLLvqqJ/6PYZj/KKZBpxf4il7o3Pu9qsEran38icq5syPkAN/oygDlcAe/ZinV1BvYkbckAL+qY5zewEDd/sWD8b3iXTMHPf8xEMc3n3oLPVfuJ5kytF402mSJg0sdXc/cXLCVuR5AoZ8JcB8+PCu93CE2v4HRsspNoML0u0ko6GVOe7Jog+fjAE2E1wMyPcS4tbF6k38JYAg4aw9D7qRNkAQrg8WDu2ZzKarwJqgCAg9dq9 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 09.08.24 15:23, David Hildenbrand wrote: > On 07.08.24 14:58, Dev Jain wrote: >> >> On 8/7/24 17:09, David Hildenbrand wrote: >>> On 05.08.24 16:14, Dev Jain wrote: >>>> >>>> On 8/5/24 16:16, David Hildenbrand wrote: >>>>> On 05.08.24 11:51, Dev Jain wrote: >>>>>> >>>>>> On 8/1/24 19:18, David Hildenbrand wrote: >>>>>>> On 01.08.24 15:43, Will Deacon wrote: >>>>>>>> On Thu, Aug 01, 2024 at 03:26:57PM +0200, David Hildenbrand wrote: >>>>>>>>> On 01.08.24 15:13, David Hildenbrand wrote: >>>>>>>>>>>>> To dampen the tradeoff, we could do this in shmem_fault() >>>>>>>>>>>>> instead? But >>>>>>>>>>>>> then, this would mean that we do this in all >>>>>>>>>>>>> >>>>>>>>>>>>> kinds of vma->vm_ops->fault, only when we discover another >>>>>>>>>>>>> reference >>>>>>>>>>>>> count race condition :) Doing this in do_fault() >>>>>>>>>>>>> >>>>>>>>>>>>> should solve this once and for all. In fact, do_pte_missing() >>>>>>>>>>>>> may call >>>>>>>>>>>>> do_anonymous_page() or do_fault(), and I just >>>>>>>>>>>>> >>>>>>>>>>>>> noticed that the former already checks this using >>>>>>>>>>>>> vmf_pte_changed(). >>>>>>>>>>>> >>>>>>>>>>>> What I am still missing is why this is (a) arm64 only; and >>>>>>>>>>>> (b) if >>>>>>>>>>>> this >>>>>>>>>>>> is something we should really worry about. There are other >>>>>>>>>>>> reasons >>>>>>>>>>>> (e.g., speculative references) why migration could temporarily >>>>>>>>>>>> fail, >>>>>>>>>>>> does it happen that often that it is really something we have to >>>>>>>>>>>> worry >>>>>>>>>>>> about? >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> (a) See discussion at [1]; I guess it passes on x86, which is >>>>>>>>>>> quite >>>>>>>>>>> strange since the race is clearly arch-independent. >>>>>>>>>> >>>>>>>>>> Yes, I think this is what we have to understand. Is the race >>>>>>>>>> simply >>>>>>>>>> less >>>>>>>>>> likely to trigger on x86? >>>>>>>>>> >>>>>>>>>> I would assume that it would trigger on any arch. >>>>>>>>>> >>>>>>>>>> I just ran it on a x86 VM with 2 NUMA nodes and it also seems to >>>>>>>>>> work here. >>>>>>>>>> >>>>>>>>>> Is this maybe related to deferred flushing? Such that the other >>>>>>>>>> CPU >>>>>>>>>> will >>>>>>>>>> by accident just observe the !pte_none a little less likely? >>>>>>>>>> >>>>>>>>>> But arm64 also usually defers flushes, right? At least unless >>>>>>>>>> ARM64_WORKAROUND_REPEAT_TLBI is around. With that we never do >>>>>>>>>> deferred >>>>>>>>>> flushes. >>>>>>>>> >>>>>>>>> Bingo! >>>>>>>>> >>>>>>>>> diff --git a/mm/rmap.c b/mm/rmap.c >>>>>>>>> index e51ed44f8b53..ce94b810586b 100644 >>>>>>>>> --- a/mm/rmap.c >>>>>>>>> +++ b/mm/rmap.c >>>>>>>>> @@ -718,10 +718,7 @@ static void set_tlb_ubc_flush_pending(struct >>>>>>>>> mm_struct >>>>>>>>> *mm, pte_t pteval, >>>>>>>>>      */ >>>>>>>>>     static bool should_defer_flush(struct mm_struct *mm, enum >>>>>>>>> ttu_flags flags) >>>>>>>>>     { >>>>>>>>> -       if (!(flags & TTU_BATCH_FLUSH)) >>>>>>>>> -               return false; >>>>>>>>> - >>>>>>>>> -       return arch_tlbbatch_should_defer(mm); >>>>>>>>> +       return false; >>>>>>>>>     } >>>>>>>>> >>>>>>>>> >>>>>>>>> On x86: >>>>>>>>> >>>>>>>>> # ./migration >>>>>>>>> TAP version 13 >>>>>>>>> 1..1 >>>>>>>>> # Starting 1 tests from 1 test cases. >>>>>>>>> #  RUN           migration.shared_anon ... >>>>>>>>> Didn't migrate 1 pages >>>>>>>>> # migration.c:170:shared_anon:Expected migrate(ptr, self->n1, >>>>>>>>> self->n2) (-2) >>>>>>>>> == 0 (0) >>>>>>>>> # shared_anon: Test terminated by assertion >>>>>>>>> #          FAIL  migration.shared_anon >>>>>>>>> not ok 1 migration.shared_anon >>>>>>>>> >>>>>>>>> >>>>>>>>> It fails all of the time! >>>>>>>> >>>>>>>> Nice work! I suppose that makes sense as, with the eager TLB >>>>>>>> invalidation, the window between the other CPU faulting and the >>>>>>>> migration entry being written is fairly wide. >>>>>>>> >>>>>>>> Not sure about a fix though :/ It feels a bit overkill to add a new >>>>>>>> invalid pte encoding just for this. >>>>>>> >>>>>>> Something like that might make the test happy in most cases: >>>>>>> >>>>>>> diff --git a/tools/testing/selftests/mm/migration.c >>>>>>> b/tools/testing/selftests/mm/migration.c >>>>>>> index 6908569ef406..4c18bfc13b94 100644 >>>>>>> --- a/tools/testing/selftests/mm/migration.c >>>>>>> +++ b/tools/testing/selftests/mm/migration.c >>>>>>> @@ -65,6 +65,7 @@ int migrate(uint64_t *ptr, int n1, int n2) >>>>>>>           int ret, tmp; >>>>>>>           int status = 0; >>>>>>>           struct timespec ts1, ts2; >>>>>>> +       int errors = 0; >>>>>>> >>>>>>>           if (clock_gettime(CLOCK_MONOTONIC, &ts1)) >>>>>>>                   return -1; >>>>>>> @@ -79,12 +80,17 @@ int migrate(uint64_t *ptr, int n1, int n2) >>>>>>>                   ret = move_pages(0, 1, (void **) &ptr, &n2, >>>>>>> &status, >>>>>>>                                   MPOL_MF_MOVE_ALL); >>>>>>>                   if (ret) { >>>>>>> -                       if (ret > 0) >>>>>>> +                       if (ret > 0) { >>>>>>> +                               if (++errors < 100) >>>>>>> +                                       continue; >>>>>>>                                   printf("Didn't migrate %d pages\n", >>>>>>> ret); >>>>>>> -                       else >>>>>>> +                       } else { >>>>>>>                                   perror("Couldn't migrate pages"); >>>>>>> +                       } >>>>>>>                           return -2; >>>>>>>                   } >>>>>>> +               /* Progress! */ >>>>>>> +               errors = 0; >>>>>>> >>>>>>>                   tmp = n2; >>>>>>>                   n2 = n1; >>>>>>> >>>>>>> >>>>>>> [root@localhost mm]# ./migration >>>>>>> TAP version 13 >>>>>>> 1..1 >>>>>>> # Starting 1 tests from 1 test cases. >>>>>>> #  RUN           migration.shared_anon ... >>>>>>> #            OK  migration.shared_anon >>>>>>> ok 1 migration.shared_anon >>>>>>> # PASSED: 1 / 1 tests passed. >>>>>>> # Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0 >>>>>> >>>>>> >>>>>> This does make the test pass, to my surprise, since what you are doing >>>>>> from userspace >>>>>> >>>>>> should have been done by the kernel, because it retries folio >>>>>> unmapping >>>>>> and moving >>>>>> >>>>>> NR_MAX_MIGRATE_(A)SYNC_RETRY times; I had already tested pumping up >>>>>> these >>>>>> >>>>>> macros and the original test was still failing. Now, I digged in more, >>>>>> and, if the >>>>>> >>>>>> following assertion is correct: >>>>>> >>>>>> >>>>>> Any thread having a reference on a folio will end up calling >>>>>> folio_lock() >>>>>> >>>>> >>>>> Good point. I suspect concurrent things like read/write would also be >>>>> able to trigger this (did not check, though). >>>>> >>>>>> >>>>>> then it seems to me that the retry for loop wrapped around >>>>>> migrate_folio_move(), inside >>>>>> >>>>>> migrate_pages_batch(), is useless; if migrate_folio_move() fails on >>>>>> the >>>>>> first iteration, it is >>>>>> >>>>>> going to fail for all iterations since, if I am reading the code path >>>>>> correctly, the only way it >>>>>> >>>>>> fails is when the actual refcount is not equal to expected refcount >>>>>> (in >>>>>> folio_migrate_mapping()), >>>>>> >>>>>> and there is no way that the extra refcount is going to get released >>>>>> since the migration path >>>>>> >>>>>> has the folio lock. >>>>>> >>>>>> And therefore, this begs the question: isn't it logical to assert the >>>>>> actual refcount against the >>>>>> >>>>>> expected refcount, just after we have changed the PTEs, so that if >>>>>> this >>>>>> assertion fails, we can >>>>>> >>>>>> go to the next iteration of the for loop for migrate_folio_unmap() >>>>>> inside migrate_pages_batch() >>>>>> >>>>>> by calling migrate_folio_undo_src()/dst() to restore the old state? >>>>>> I am >>>>>> trying to implement >>>>>> >>>>>> this but is not as straightforward as it seemed to me this morning. >>>>> >>>>> I agree with your assessment that migration code currently doesn't >>>>> handle the case well when some other thread does an unconditional >>>>> folio_lock(). folio_trylock() users would be handled, but that's not >>>>> what we want with FGP_LOCK I assume. >>>>> >>>>> So IIUC, your idea would be to unlock the folio in migration code and >>>>> try again their. Sounds reasonable, without looking into the details :) >>>> >>>> >>> >>> BTW, I was trying to find the spot that would do the folio_lock(), but >>> filemap_fault() does the lock_folio_maybe_drop_mmap() where we do a >>> folio_trylock(). >>> >>> Where exactly is the folio_lock() on the fault path that would >>> prohibit us from making progress? >> >> Not filemap_fault(); it enters shmem_fault() which eventually calls >> shmem_get_folio_gfp(), retrieving the folio from the pagecache, and >> calling folio_lock(). > > Ah, thanks! > > ... which raises the question if we should handle it similar to > filemap_fault(), essentially drop the reference and retry using > VM_FAULT_RETRY. Hmmmmm ... just had another look at lock_folio_maybe_drop_mmap(), and we also usually end up in __folio_lock() / __folio_lock_killable(), folio_trylock() is only used for the fast path. So no, that wouldn't change that much. -- Cheers, David / dhildenb