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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 54BDAC0218A for ; Tue, 28 Jan 2025 20:24:42 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 9E71A10E0A7; Tue, 28 Jan 2025 20:24:41 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="enqCzAvK"; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by gabe.freedesktop.org (Postfix) with ESMTPS id 3E94E10E0A7 for ; Tue, 28 Jan 2025 20:24:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1738095879; 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=iNDpudIY0bPli5LGjMVKpmXgCO8o2Ymuyxua8dIBZCM=; b=enqCzAvKVhapaMr/92TmunAckzC9J/Ryg7Mps5AMsi/NYMN/5AZBmWTNw2bxqBBF6uPe66 2L7aVomFKmW0zLQtZ6r0QgsSSJe7yZS2R3KsBIT/kkDBpLJLpYQ3GO5DMyVmnosnv4paZT f5PDUnM25ELFPOyzSOz0L/pEMR8CGPk= 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-694-ju4zDOLiPz-dK6xYxJhQLw-1; Tue, 28 Jan 2025 15:24:37 -0500 X-MC-Unique: ju4zDOLiPz-dK6xYxJhQLw-1 X-Mimecast-MFC-AGG-ID: ju4zDOLiPz-dK6xYxJhQLw Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-4361fc2b2d6so34686365e9.3 for ; Tue, 28 Jan 2025 12:24:37 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738095876; x=1738700676; 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=iNDpudIY0bPli5LGjMVKpmXgCO8o2Ymuyxua8dIBZCM=; b=Zt8PBFbPAv1IuN1swu1fSSOWLDC3p/0MTcnTaKIQ9OKN/Zrn+R5gyYbqVS/kw/zuSs jSTDEgzG64FtH9kYC23DVip3mZ8WBFZITROv+Gr6iL40j+Okq11fRnnYMGXHAkSoIrYT rjUY3YoBOb98GGivUToaVVtC0pNcFFBAzNHBs+LRGeZLwzpebMIxjay5eXFw3Y1a88EF +uA48+wh5CTcyz+9/x9ndXG/FR9S75TkYMXyfLyuoYLV3POsSktdPZ0Jz68QRCZ9m/rv MyF2vYvdmgum1hXIkFW5DJJmeo33icHlc/qIMgEH9jZhDbVFbRNZtwv+sdf7WNVlwYwj Q24g== X-Forwarded-Encrypted: i=1; AJvYcCWLrG1oZLSRLybVH0fsY7q8PILEfFdm9YdVgHNgq2+ooPlECBMPCqIu2I/C1qP7War7QaKGvzSO@lists.freedesktop.org X-Gm-Message-State: AOJu0YyPjz8nBGQXvGpOznxAwGTtw1afyy6OOzQMV/VejCNd84FsB3Ed VlKr33U47nf2L9+pjmLeMTpXQcd0LcZqUBUEzs01AIJTlUlA+K1LIJsf4G0p5dK3/Q7maRoFoPa mQqJzFJMxHIvJnLhW1Z0DcNdVDKPOe3b5HAlskQSjIvdmPgRlLHaoprKLIKzYGOc= X-Gm-Gg: ASbGncuN8jHr8XZLmi3VOfzXzJxdsooqYxm4wp83X7vh7Z43hcNtsXm5Xc9iyyHhXh8 znTMY6va09XoRenh+4G0rGJNG2lWObOSx4rKXPXXg2JrtIa/KixUtPE7C8t44rk458SEwbXRVx3 7fGhi0qrShL3KGpmCgbbNl6441O0BslI9j+uQlFBMSO2Csc6MUyFillnB55fA8KYuk2VdokFUdr A37G8WE1S3rPOK/FocUMxA8yQKLMeBgxGw71EkYv22Uwjh1czGY1Xnpqea2Kj/+dYKEKBkugYNc x6dW/SaKLbVeZa63atDOV1kVHL6znkcf5wVKNrxyHgMjGODfsnkoS/giZYA1iOu91AmZcfGq0Pu ctXb8sciftQWjiM1rWcaoazxKJ6vACf/O X-Received: by 2002:a05:600c:4e14:b0:438:a214:52f4 with SMTP id 5b1f17b1804b1-438dc428c0amr1999805e9.25.1738095876557; Tue, 28 Jan 2025 12:24:36 -0800 (PST) X-Google-Smtp-Source: AGHT+IFG549CWXnWLeL/X/VL8ixFtav9qhAQqZxiT84vSQDru6hmKepAblMtW6jxTH/r0SRrryd1/A== X-Received: by 2002:a05:600c:4e14:b0:438:a214:52f4 with SMTP id 5b1f17b1804b1-438dc428c0amr1999615e9.25.1738095876187; Tue, 28 Jan 2025 12:24:36 -0800 (PST) Received: from ?IPV6:2003:cb:c73f:ce00:1be7:6d7f:3cc3:563d? (p200300cbc73fce001be76d7f3cc3563d.dip0.t-ipconnect.de. [2003:cb:c73f:ce00:1be7:6d7f:3cc3:563d]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-438bd4b9984sm179722225e9.28.2025.01.28.12.24.33 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 28 Jan 2025 12:24:34 -0800 (PST) Message-ID: Date: Tue, 28 Jan 2025 21:24:33 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [Question] Are "device exclusive non-swap entries" / "SVM atomics in Nouveau" still getting used in practice? To: Alistair Popple , "linux-mm@kvack.org" , John Hubbard , nouveau@lists.freedesktop.org, Jason Gunthorpe , DRI Development , Karol Herbst , Lyude Paul , Danilo Krummrich References: <346518a4-a090-4eaa-bc04-634388fd4ca3@redhat.com> <8c6f3838-f194-4a42-845d-10011192a234@redhat.com> From: David Hildenbrand 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/g1oFAl8Ox4kFCRKpKXgACgkQTd4Q 9wD/g1o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5b8Tovi8C0tmxiCHaQYqj7G2rgnT0kt WNyWQQ== Organization: Red Hat In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: c7UNTbXZSvX2TyCD1UNCD2cvMB3jtNiDQuPp0LhK8Mw_1738095877 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: nouveau@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Nouveau development list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: nouveau-bounces@lists.freedesktop.org Sender: "Nouveau" On 28.01.25 21:14, Simona Vetter wrote: > On Tue, Jan 28, 2025 at 11:09:24AM +1100, Alistair Popple wrote: >> On Fri, Jan 24, 2025 at 06:54:02PM +0100, David Hildenbrand wrote: >>>>>> On integrated the gpu is tied into the coherency >>>>>> fabric, so there it's not needed. >>>>>> >>>>>> I think the more fundamental question with both this function here and >>>>>> with forced migration to device memory is that there's no guarantee it >>>>>> will work out. >>>>> >>>>> Yes, in particular with device-exclusive, it doesn't really work with THP >>>>> and is only limited to anonymous memory. I have patches to at least make it >>>>> work reliably with THP. >>>> >>>> I should have crawled through the implementation first before replying. >>>> Since it only looks at folio_mapcount() make_device_exclusive() should at >>>> least in theory work reliably on anon memory, and not be impacted by >>>> elevated refcounts due to migration/ksm/thp/whatever. >>> >>> Yes, there is -- in theory -- nothing blocking the conversion except the >>> folio lock. That's different than page migration. >> >> Indeed - this was the entire motivation for make_device_exclusive() - that we >> needed a way to reliably exclude CPU access that couldn't be blocked in the same >> way page migration can (otherwise we could have just migrated to a device page, >> even if that may have added unwanted overhead). > > The folio_trylock worries me a bit. I guess this is to avoid deadlocks > when locking multiple folios, but I think at least on the first one we > need an unconditional folio_lock to guarantee forward progress. At least on the hmm path I was able to trigger the EBUSY a couple of times due to concurrent swapout. But the hmm-tests selftest fails immediately instead of retrying. > Since > atomics can't cross 4k boundaries (or the hw is just really broken) this > should be enough to avoid being stuck in a livelock. I'm also not seeing > any other reason why a folio_lock shouldn't work here, but then my > understanding of mm/ stuff is really just scratching the surface. > > I did crawl through all the other code and it looks like everything else > is unconditional locks. So looks all good and I didn't spot anything else > that seemed problematic. > > Somewhat aside, I do wonder whether we really want to require callers to > hold the mmap lock, or whether with all the work towards lockless fastpath > that shouldn't instead just be an implementation detail. We might be able to use the VMA lock in the future, but that will require GUP support and a bunch more. Until then, the mm_lock in read mode is required. I was not able to convince myself that we'll really need the folio lock, but that's also a separate discussion. > At least for the > gpu hmm code I've seen I've tried to push hard towards a world were the > gpu side does not rely on mmap_read_lock being held at all, to future > proof this all. And currently we only have one caller of > make_device_exclusive_range() so would be simple to do. We could likely move the mmap_lock into that function, but avoiding it is more effort. In any case, I'll send something out probably tomorrow to fix page migration/swapout of pages with device-exclusive entries and a bunch of other things (THP, interaction with hugetlb, ...). -- Cheers, David / dhildenb