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 8417A1A9F8E for ; Mon, 11 Aug 2025 15:53:04 +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=1754927586; cv=none; b=G1CacjYIbMnQs2lFzhph9vrGG+zYVRh8mBlpKH9L3YxZ4cf9CggKjlHhNgOHa9muS4z+Vl3EBVWTl/xTrtHKWNZ9KIdo6go6k61GcNkx5SSsp26/pIAk6DkSLeiILfvvDGMUHCzLlBBZJKt0E2a5qx+5CDS9KBCKHbTiCh8+d6U= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754927586; c=relaxed/simple; bh=wH+YJJ78SpGXvS/sNiNLkme7MxFSovvNx4cxQr7gEow=; h=Message-ID:Date:MIME-Version:Subject:To:References:From: In-Reply-To:Content-Type; b=fDasxj/AzKS4lzWZ1zp4zqTOgp/U081kFecRx2Hkphk5DEJxxlgAr6jYj3S6TdfdE9t2gr+txmHoK5BGA/F8qoNH8AMOA11i6U+Cz7dvcMN//epNfSq8+7Ea9etvvn6pXH79SJORfqYZqrPztr0BwFUuJKvudmYDVVB/f+9nOSg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine 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=N1FI+u44; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine 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="N1FI+u44" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1754927583; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to: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=GyWr1QpZuxF9B4FyrzRej7noS4J8x1+3Oa8vyw2kJ7w=; b=N1FI+u44s7WKGOvfMDvYigIXqdCOGMdBf5mi2tFLoC12Uyjggv6nEqvDgxoypNxn/5ANsE pYneTzh1tWgOt3+3fTId4gKfNlaNlBkHIgDhSGDDyt/LCwqSxJRGPunLvxNlOM5xSeoOPt Q40YwklLrr9oQ1K2bDq5RZ1zNDBzWks= 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-194-ZNRyrtmLOP-1i8Bb4oAuWA-1; Mon, 11 Aug 2025 11:39:35 -0400 X-MC-Unique: ZNRyrtmLOP-1i8Bb4oAuWA-1 X-Mimecast-MFC-AGG-ID: ZNRyrtmLOP-1i8Bb4oAuWA_1754926774 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-459d6c83e2eso25675215e9.1 for ; Mon, 11 Aug 2025 08:39:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1754926774; x=1755531574; h=content-transfer-encoding:in-reply-to:organization:autocrypt :content-language:from:references:to:subject:user-agent:mime-version :date:message-id:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=GyWr1QpZuxF9B4FyrzRej7noS4J8x1+3Oa8vyw2kJ7w=; b=hNgVkOOX2J+NZCvqUCqCxOyix8V+YMVMKpLYSEu4nnDQIosJJoCTe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05:600c:c494:b0:459:db5a:b097 with SMTP id 5b1f17b1804b1-45a10c0126fmr1610705e9.16.1754926774348; Mon, 11 Aug 2025 08:39:34 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHlf+7BcvARxFRQk8Q5EGLD08HwQZfsUf/AwyhotSUn7XHRyNjGYRhhAvp4S2PkxpNDcQl2fQ== X-Received: by 2002:a05:600c:c494:b0:459:db5a:b097 with SMTP id 5b1f17b1804b1-45a10c0126fmr1610205e9.16.1754926773715; Mon, 11 Aug 2025 08:39:33 -0700 (PDT) Received: from ?IPV6:2003:d8:2f06:a600:a397:de1d:2f8b:b66f? (p200300d82f06a600a397de1d2f8bb66f.dip0.t-ipconnect.de. [2003:d8:2f06:a600:a397:de1d:2f8b:b66f]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-458b4f9e952sm399513135e9.9.2025.08.11.08.39.32 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 11 Aug 2025 08:39:33 -0700 (PDT) Message-ID: <2e8df53b-d953-43fb-9c69-7d7d60e95c9a@redhat.com> Date: Mon, 11 Aug 2025 17:39:32 +0200 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: swap: check for xa_zero_entry() on vma in swapoff path To: "Liam R. Howlett" , Lorenzo Stoakes , Charan Teja Kalla , akpm@linux-foundation.org, shikemeng@huaweicloud.com, kasong@tencent.com, nphamcs@gmail.com, bhe@redhat.com, baohua@kernel.org, chrisl@kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Matthew Wilcox References: <20250808092156.1918973-1-quic_charante@quicinc.com> <29e080fd-5f9a-4760-876a-a6ccef33129f@quicinc.com> <9178bf98-2ea7-4ad8-ad43-cdcc02ab863d@redhat.com> <904f85d0-acd6-4f47-ab45-fbf18b80f1c6@lucifer.local> <7e7bfd05-434c-40b7-98ec-8ce352a8147d@redhat.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+5qaSr0ID2sz5jtBLRb15RMre27E1ImpaIv2Jw8NJgW0k/D1RyKCwaTsgRdwuK Kx/Y91XuSBdz0uOyU/S8kM1+ag0wvsGlpBVxRR/xw/E8M7TEwuCZQArqqTCmkG6HGcXFT0V9 PXFNNgV5jXMQRwU0O/ztJIQqsE5LsUomE//bLwzj9IVsaQpKDqW6TAPjcdBDPLHvriq7kGjt WhVhdl0qEYB8lkBEU7V2Yb+SYhmhpDrti9Fq1EsmhiHSkxJcGREoMK/63r9WLZYI3+4W2rAc UucZa4OT27U5ZISjNg3Ev0rxU5UH2/pT4wJCfxwocmqaRr6UYmrtZmND89X0KigoFD/XSeVv jwBRNjPAubK9/k5NoRrYqztM9W6sJqrH8+UWZ1Idd/DdmogJh0gNC0+N42Za9yBRURfIdKSb B3JfpUqcWwE7vUaYrHG1nw54pLUoPG6sAA7Mehl3nd4pZUALHwARAQABzSREYXZpZCBIaWxk ZW5icmFuZCA8ZGF2aWRAcmVkaGF0LmNvbT7CwZgEEwEIAEICGwMGCwkIBwMCBhUIAgkKCwQW AgMBAh4BAheAAhkBFiEEG9nKrXNcTDpGDfzKTd4Q9wD/g1oFAmgsLPQFCRvGjuMACgkQTd4Q 9wD/g1o0bxAAqYC7gTyGj5rZwvy1VesF6YoQncH0yI79lvXUYOX+Nngko4v4dTlOQvrd/vhb 02e9FtpA1CxgwdgIPFKIuXvdSyXAp0xXuIuRPQYbgNriQFkaBlHe9mSf8O09J3SCVa/5ez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YjVoylWiBNknvQWBXS lQCWmavOT9sttGQXdPCC5ynI+1ymZC1ORZKANLnRAb0NH/UCzcsstw2TAkFnMEbo9Zu9w7Kv AxBQXWeXhJI9XQssfrf4Gusdqx8nPEpfOqCtbbwJMATbHyqLt7/oz/5deGuwxgb65pWIzufa N7eop7uh+6bezi+rugUI+w6DABEBAAHCwXwEGAEIACYCGwwWIQQb2cqtc1xMOkYN/MpN3hD3 AP+DWgUCaCwtJQUJG8aPFAAKCRBN3hD3AP+DWlDnD/4k2TW+HyOOOePVm23F5HOhNNd7nNv3 Vq2cLcW1DteHUdxMO0X+zqrKDHI5hgnE/E2QH9jyV8mB8l/ndElobciaJcbl1cM43vVzPIWn 01vW62oxUNtEvzLLxGLPTrnMxWdZgxr7ACCWKUnMGE2E8eca0cT2pnIJoQRz242xqe/nYxBB /BAK+dsxHIfcQzl88G83oaO7vb7s/cWMYRKOg+WIgp0MJ8DO2IU5JmUtyJB+V3YzzM4cMic3 bNn8nHjTWw/9+QQ5vg3TXHZ5XMu9mtfw2La3bHJ6AybL0DvEkdGxk6YHqJVEukciLMWDWqQQ RtbBhqcprgUxipNvdn9KwNpGciM+hNtM9kf9gt0fjv79l/FiSw6KbCPX9b636GzgNy0Ev2UV m00EtcpRXXMlEpbP4V947ufWVK2Mz7RFUfU4+ETDd1scMQDHzrXItryHLZWhopPI4Z+ps0rB CQHfSpl+wG4XbJJu1D8/Ww3FsO42TMFrNr2/cmqwuUZ0a0uxrpkNYrsGjkEu7a+9MheyTzcm vyU2knz5/stkTN2LKz5REqOe24oRnypjpAfaoxRYXs+F8wml519InWlwCra49IUSxD1hXPxO WBe5lqcozu9LpNDH/brVSzHCSb7vjNGvvSVESDuoiHK8gNlf0v+epy5WYd7CGAgODPvDShGN g3eXuA== Organization: Red Hat In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit >> >> I think it may actually be difficult to do on some level or there was some >> reason we couldn't, but I may be mistaken. > Thanks for the information! > Down the rabbit hole we go.. > > The cloning of the tree happens by copying the tree in DFS and > replacing the old nodes with new nodes. The tree leaves end up being > copied, which contains all the vmas (unless DONT_COPY is set, so > basically always all of them..). When the tree is copied, we have a > duplicate of the tree with pointers to all the vmas in the old process. > > The way the tree fails is that we've been unable to finish cloning it, > usually for out of memory reasons. So, this means we have a tree with > new and exciting vmas that have never been used and old but still active > vmas in oldmm. > > The failure point is then marked with an XA_ZERO_ENTRY, which will > succeed in storing as it's a direct replacement in the tree so no > allocations necessary. Thus this is safe even in -ENOMEM scenarios. > > Clearing out the stale data means we may actually need to allocate to > remove vmas from the new tree, because we use allocated memory in the > maple tree - we'll need to rebalance, new parents, etc, etc. > > So, to remove the stale data - we may actually have to allocate memory. Ah, that sucks. And I assume we cannot preallocate early, because we might actually require multiple alloc+free cycles. > > But we're most likely out of memory.. and we don't want to get the > shrinker involved in a broken task teardown, especially since it has > already been run and failed to help.. > > We could replace all the old vmas with XA_ZERO_ENTRY, but that doesn't > really fix this issue either. No. > > I could make a function that frees all new vmas and destroys the tree > specifically for this failure state? I think the problem is that some page tables were already copied, so we would have to zap them as well. Maybe just factoring stuff from the exit_mmap() function could be one way to do it. > > I'm almost certain this will lead to another whack-a-mole situation, but > those _should_ already be checked or written to work when there are zero > vmas in an mm (going by experience of what the scheduler does with an > empty tree). Syzbot finds these scenarios sometimes via signals or > other corner cases that can happen.. Yes, I rememebr fixing one instance of "0 VMAs". Most code paths just don't apply if a process was never actually ran I guess. > > Then again, I also thought the unstable mm should be checked where > necessary to avoid assumptions on the mm state..? > > This is funny because we already have a (probably) benign race with oom > here. This code may already visit the mm after __oom_reap_task_mm() and > the mm disappearing, but since the anon vmas should be removed, > unuse_mm() will skip them. > > Although, I'm not sure what happens when > mmu_notifier_invalidate_range_start_nonblock() fails AND unuse_mm() is > called on the mm after. Maybe checking the unstable mm is necessary > here anyways? Can we have MMU notifiers active while the process never even ran and we are only halfway through duplicating VMAs? -- Cheers, David / dhildenb