From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DCE2D223E73 for ; Thu, 19 Dec 2024 12:55:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734612920; cv=none; b=A3ZUMy6X9F6ib5ZacsKjvyt/pHSAd3gg9Jkl2SBm4NM56knCDREWAJQmQAnKOGKugw6/WMtDKCUg+v7mfT5iq6sKjQwYjsOM//Z3SqdbcUmrfeRdzsvIG73exQChpVujidn9DDV7RVAKTRuYR9ndcsleouz9Q2X1tsn1WjY3Xfs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734612920; c=relaxed/simple; bh=m1BTQFefhXuAGyfssZG0CJGT6oKbpEDr03os9eopP6g=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=R2TvddwZlxaD7ZnODVp+e88570Ex7gs8aGVXElY7+jUTTg46vjeX+vjKz31WgBNDgKCB/Oaw26hIWFfDsX9wPHHGfe9ZDRK3rUFjOzLIjqtdZn1C1hNlIjxR3LKEVAMlmnh/MylIsKXVa8YWp8rTaXkdoNu5TUm2hOpAoPgKOGc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=arJ7U8zw; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="arJ7U8zw" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1734612917; 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=KUWplam2GqLW+XMrVsOy+lbqiGXnQi3BpM93U5bh9MQ=; b=arJ7U8zw/WrBTGsDELBId4lOG/pZsXoz5l3+TsnUNAjvxT796ndGbY6EHwOVeLERfcQako 0Ze5PvQRodc14guNhHh4n3J3GPTa8X0zmIPIUtrE3umA3tZHXSDOwYUA1VKgw1GFF256VN w/lE2M/fVabqBaLHSGnwthLNMsC/rB0= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-486-E9Y5EG5VPyKLbdm_NYnYdw-1; Thu, 19 Dec 2024 07:55:16 -0500 X-MC-Unique: E9Y5EG5VPyKLbdm_NYnYdw-1 X-Mimecast-MFC-AGG-ID: E9Y5EG5VPyKLbdm_NYnYdw Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-43646b453bcso4623405e9.3 for ; Thu, 19 Dec 2024 04:55:15 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734612915; x=1735217715; h=content-transfer-encoding:in-reply-to:organization:autocrypt :content-language:from:references:cc:to:subject:user-agent :mime-version:date:message-id:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=KUWplam2GqLW+XMrVsOy+lbqiGXnQi3BpM93U5bh9MQ=; b=VqyOyJidbAk62Rs87vaD3N9ahHynDO1OxR5rS/xtnBoyABI83bsM+VHwVjqiDf+y9b opQf3YtuecZzLq3mI8/F/CjxVTV5Q1lkqqlxS2Vi6SiXrFw5xyTOvrfG8Nwj6yVM5mn2 +qjCtohLyEJEcuHXuy/JHu6oeNJHE+KYqIihGKrm9I93SOavspOP4ojNLISzdtndDHjA ST+wF9pf4AmsghyrLtVK/ScwBbkpge4HIHKsjBJV/DiSd3rDF8xvF3qBWHr8Uee6qfRq aUdo3E71MUlXaXCHfjPC25n8DgzmaKdzlSc7ei7WPAXhJy3BHK4HawO5vPuVBrkzJvjY uvww== X-Forwarded-Encrypted: i=1; AJvYcCUCZDdhjzxe6nTvmdSnbfmfweRxvLBl1eH0qgijJXBoUiBaN3JRu0cGhSxOadDSqO6QE1qMtb57qWbuqkg=@vger.kernel.org X-Gm-Message-State: AOJu0Ywxyk9BNBpu1ApiaMV88ymdAhAcOi3bX6IdtsFeLhkI/f/Za+zO QBiEBv0KjrQVhwi9NTt6wgcDdKjg0tA0tkyU+152i7abMohXD7LSKJE+XAHV3CKmngwh9HGSD5W 3ZTfGWpHTSPfcngzvf/9PGh0nNSFFZniWODJdoMU+XukVuEpCIDAelz19GvFyVA== X-Gm-Gg: ASbGncs/P9FeJaJbWeHPQ+lC299p2BRY1ApPOxcccmzldEEcdRKCIs6Pb5S7EsKLedx vLhk9L888qFVDFOiHsSuvlpEFdRLo+o83tHOcyOx7WsZb0qEgCheAkCyf8VQ3G+QF82KvCB97U0 CJKX2FOzzzr+jq/p4oEANMa8NapC9xCgGvocLhxIlYHLQYCU2fv1iNbRm9jdAMKgO+JK3dlB2tP WM13mLk4bFzlYGWgRNd/iG5Lagpm6taRCL9HT/U3p4DaY9yzQD8J28TyaB6pSwWJY+FqSgqHDkl FCaWD3Nx+dy/S2ZVWjEc64TGAH/7h1IV5GNapxaNgZ2IluwRhv3VRhpZp3vhbA0J7UT0Ry3+WK0 7Votl5g== X-Received: by 2002:a05:600c:5104:b0:434:e9ee:c1e with SMTP id 5b1f17b1804b1-4365c9cb4e1mr30993025e9.31.1734612914792; Thu, 19 Dec 2024 04:55:14 -0800 (PST) X-Google-Smtp-Source: AGHT+IEIEDvtNRNqHe7y1eh+SvWGr0nH0O/dH+N4+zqmgznR9MCcmlSZzOu4YH8lG1oJZZIXZJZyEg== X-Received: by 2002:a05:600c:5104:b0:434:e9ee:c1e with SMTP id 5b1f17b1804b1-4365c9cb4e1mr30992555e9.31.1734612914251; Thu, 19 Dec 2024 04:55:14 -0800 (PST) Received: from ?IPV6:2003:cb:c749:6600:b73a:466c:e610:686? (p200300cbc7496600b73a466ce6100686.dip0.t-ipconnect.de. [2003:cb:c749:6600:b73a:466c:e610:686]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-436612899f0sm17354405e9.38.2024.12.19.04.55.12 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 19 Dec 2024 04:55:13 -0800 (PST) Message-ID: <3c1665df-9367-4d43-8aa1-6726fbb59640@redhat.com> Date: Thu, 19 Dec 2024 13:55:12 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] mm: migration :shared anonymous migration test is failing To: Donet Tom , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Ritesh Harjani , Baolin Wang , "Aneesh Kumar K . V" , Zi Yan , shuah Khan , Dev Jain References: <20241219124717.4907-1-donettom@linux.ibm.com> From: David Hildenbrand Content-Language: en-US Autocrypt: addr=david@redhat.com; keydata= xsFNBFXLn5EBEAC+zYvAFJxCBY9Tr1xZgcESmxVNI/0ffzE/ZQOiHJl6mGkmA1R7/uUpiCjJ dBrn+lhhOYjjNefFQou6478faXE6o2AhmebqT4KiQoUQFV4R7y1KMEKoSyy8hQaK1umALTdL QZLQMzNE74ap+GDK0wnacPQFpcG1AE9RMq3aeErY5tujekBS32jfC/7AnH7I0v1v1TbbK3Gp XNeiN4QroO+5qaSr0ID2sz5jtBLRb15RMre27E1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aBTPHSy/Nksu0eY7x6HfQJ3xajVH32Ms6t1trDQmPx2iP5+7iDsb7OKAb5eOS8h+BEBDeq 3ecsQDv0fFJOA9ag5O3LLNk+3x3q7e0uo06XMaY7UHS341ozXUUI7wC7iKfoUTv03iO9El5f XpNMx/YrIMduZ2+nd9Di7o5+KIwlb2mAB9sTNHdMrXesX8eBL6T9b+MZJk+mZuPxKNVfEQMQ a5SxUEADIPQTPNvBewdeI80yeOCrN+Zzwy/Mrx9EPeu59Y5vSJOx/z6OUImD/GhX7Xvkt3kq Er5KTrJz3++B6SH9pum9PuoE/k+nntJkNMmQpR4MCBaV/J9gIOPGodDKnjdng+mXliF3Ptu6 3oxc2RCyGzTlxyMwuc2U5Q7KtUNTdDe8T0uE+9b8BLMVQDDfJjqY0VVqSUwImzTDLX9S4g/8 kC4HRcclk8hpyhY2jKGluZO0awwTIMgVEzmTyBphDg/Gx7dZU1Xf8HFuE+UZ5UDHDTnwgv7E th6RC9+WrhDNspZ9fJjKWRbveQgUFCpe1sa77LAw+XFrKmBHXp9ZVIe90RMe2tRL06BGiRZr jPrnvUsUUsjRoRNJjKKA/REq+sAnhkNPPZ/NNMjaZ5b8Tovi8C0tmxiCHaQYqj7G2rgnT0kt WNyWQQ== Organization: Red Hat In-Reply-To: <20241219124717.4907-1-donettom@linux.ibm.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 19.12.24 13: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, > flushing the TLB ensures that the next page fault correctly triggers > do_swap_page() and waits for the migration to complete. > Does this reproduce with commit 536ab838a5b37b6ae3f8d53552560b7c51daeb41 Author: Dev Jain Date: Fri Aug 30 10:46:09 2024 +0530 selftests/mm: relax test to fail after 100 migration failures It was recently observed at [1] that during the folio unmapping stage of migration, when the PTEs are cleared, a racing thread faulting on that folio may increase the refcount of the folio, sleep on the folio lock (the migration path has the lock), and migration ultimately fails when asserting the actual refcount against the expected. Thereby, the migration selftest fails on shared-anon mappings. The above enforces the fact that migration is a best-effort service, therefore, it is wrong to fail the test for just a single failure; hence, fail the test after 100 consecutive failures (where 100 is still a subjective choice). Note that, this has no effect on the execution time of the test since that is controlled by a timeout. [1] https://lore.kernel.org/all/20240801081657.1386743-1-dev.jain@arm.com/ part of 6.12? As part of that discussion, we discussed alternatives, such as retrying migration more often internally. -- Cheers, David / dhildenb