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 42B95C0218A for ; Tue, 28 Jan 2025 20:15:05 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id BB47A10E02A; Tue, 28 Jan 2025 20:15:04 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (1024-bit key; secure) header.d=ffwll.ch header.i=@ffwll.ch header.b="MFygSdqp"; dkim-atps=neutral Received: from mail-wm1-f51.google.com (mail-wm1-f51.google.com [209.85.128.51]) by gabe.freedesktop.org (Postfix) with ESMTPS id 4161710E02A for ; Tue, 28 Jan 2025 20:15:04 +0000 (UTC) Received: by mail-wm1-f51.google.com with SMTP id 5b1f17b1804b1-4361c705434so43613175e9.3 for ; Tue, 28 Jan 2025 12:15:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; t=1738095303; x=1738700103; darn=lists.freedesktop.org; h=in-reply-to:content-disposition:mime-version:references :mail-followup-to:message-id:subject:cc:to:from:date:from:to:cc :subject:date:message-id:reply-to; bh=Jfne+1E0DxYE+tkkNd2LaEnYSrvpDi+VKE9gDmVZgHA=; b=MFygSdqpIijHPGp8JAYr+hxuDLZbB71vrNijwnE7Lb9H/z8HIjzw4So2gnt4+7QB3o JWZXlvJnhe+jXy5c+9xWrzMvWj2kWIMRXOYfkqTSi7CGVmDg4OH2NnQdu/fajcZ3L/6b Vw5d/b62P9JbfTFfh+bcqYHS48Wlis3csC9Is= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738095303; x=1738700103; h=in-reply-to:content-disposition:mime-version:references :mail-followup-to:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Jfne+1E0DxYE+tkkNd2LaEnYSrvpDi+VKE9gDmVZgHA=; b=qqa/Lkx9lVi7aHiAE/T4G60017U4YwdNCh/exGsgTNwbHVrlF9L2C7gkU/kSCS6ceE AAeZ5moVExoRRZJHNCPFdNcz1y2vG1I9wZrmMIaa3W+B0i4wY0ZpJ1WJfbGxWSFMCzfA 40pgIwzbHmbnmc809IsOboSUDrnGoauC44BWbdihG4om3ZduLRZEXDYrmZOsBOhIosmY 8rm7VfK7nty/vzKr4Sr8T4u5zWVczB2sKaQKvC60xHHsJ1viWmOogyogohBTiVfOUznS s11V/nmHw58JI1WUblH7BJLDfYjherqbOmhEGBiR5/3BOHzu5jWRrXkpaid/1733aALP g7PA== X-Forwarded-Encrypted: i=1; AJvYcCXoUfP3OzGVgvida3GZAswc9sL4hTZ2RRAabDOUv/XYQ9bRWT+kaGFKiUOYok4EjfDz25dIzbp7UY0=@lists.freedesktop.org X-Gm-Message-State: AOJu0YwgbAdhrWJPvLP0Z9v7jNFJCtRorF6zjDm2ItcKRYuivvuDAf1a D8TWBK3thrAW5sCjGe+hbacXPO1GmJMuu4Cyzco8scWQp0JikaR+YGwdhX4u5PA= X-Gm-Gg: ASbGncvrBRKO79gNknjYFX1g0Te3+YZZANgu9uUEhq3V8bBkfBHKjmfqAGhQVmMgyVW sca1U3MyQqByRyffgyNeAK6dAx1FBoKCnumWqVORpZV2BCWlZXHGL8K5z3Yj6fM3LpIGJZnpmnk T7PXjLfY/QdOoAx9oE5JmEJyQgkOCk4iT8PkRQh89yVC9s4dvdFaGepJBWI5XO0Mccjl/HNodpv K9grHqkPV/2O7fJPBR8lE5oCErlO4QAZQQkhnifoF9rhqhy/WVaFI6hpnH+XqkCJWS08/AYuqHy yggNVjZRRplBaDoU1h6AfSygsZA= X-Google-Smtp-Source: AGHT+IFCpJVPpO9rfXvd1jMOU5Y8GXvqZMpsBrMYN7aXsmHR2MRFFuNi1zjP08VspD+cMw3VvnJFqQ== X-Received: by 2002:a05:600c:1f18:b0:436:1b08:4c78 with SMTP id 5b1f17b1804b1-438dc43093cmr2810575e9.31.1738095302513; Tue, 28 Jan 2025 12:15:02 -0800 (PST) Received: from phenom.ffwll.local ([2a02:168:57f4:0:5485:d4b2:c087:b497]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38c2a176490sm14733002f8f.1.2025.01.28.12.15.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Jan 2025 12:15:01 -0800 (PST) Date: Tue, 28 Jan 2025 21:14:59 +0100 From: Simona Vetter To: Alistair Popple Cc: David Hildenbrand , "linux-mm@kvack.org" , John Hubbard , nouveau@lists.freedesktop.org, Jason Gunthorpe , DRI Development , Karol Herbst , Lyude Paul , Danilo Krummrich Subject: Re: [Question] Are "device exclusive non-swap entries" / "SVM atomics in Nouveau" still getting used in practice? Message-ID: Mail-Followup-To: Alistair Popple , David Hildenbrand , "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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Operating-System: Linux phenom 6.12.11-amd64 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" 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. 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. 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. -Sima -- Simona Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch