Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp3632120rdb; Wed, 13 Sep 2023 19:32:14 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGkTa08y/vAmmwJ4D2FsaSMP6NMWABlK2RvP5t4ZC47wE6kfhv8gEvGWkVh1kteODdwHGne X-Received: by 2002:a05:6358:c1d:b0:139:b1c8:a28a with SMTP id f29-20020a0563580c1d00b00139b1c8a28amr4339391rwj.0.1694658733838; Wed, 13 Sep 2023 19:32:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694658733; cv=none; d=google.com; s=arc-20160816; b=nz4cbzz0y0vFVaz7b6hjE6EUVXnUWlowY7w3N0PkeUW79eyTDFJ7krmgzHUsulxWJt zr7ZTiT93ze1deoy+exXHTdUStvhMEMwxanB4MeSmu9EFot5jKhr/C94YtavEeMnVR20 gGv6uyzqNSuWtvm84wxstSYSdLF207mrgBv6w9hUMuQ85OP2JXTt4ZHhthlEFGn2zCmf GgLH3kj1vXRMTf4mNRQELxvQuoDpBMcsXx//yNKspGWEX2lbVTt8G+OJsErLsilczfIH 9iQv1RsqgpmbaFGLZMH2N2lrKm34DVl4mQGiLobXqDDHjhx90Rf4TR6hiuc0dStdVbxG FuSQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :organization:references:in-reply-to:message-id:subject:cc:to:from :date:dkim-signature; bh=ADwxYAA/t9O+gn48g4rkUPaDbnKqp4MOCKTC54uFQd4=; fh=iUS413dVenIF5zzUEj/JAYSspxKEUmfTSWp8twPe5Io=; b=FuAkLwGdtrXrM9U1WIu+J4Kbz2pdt8utgs3hSOvfSYQTFCyzY9FbalG/iRG29PDcfx iMCO5khndTTG44WfUdtdpcFHFuWd2iCRfG9nBjw54ug5gYsa8AcwFO2AllnvczGOM4Wo XCvld9bs2gkBGajU9LnjrqUT2A1ItjfyiO64GXvtREf8OmplTL5MM+R520n8z1WXY2uG kIXGc7lZIsll6fENkML9c/MkptZB2RVtusn8WUbhX2ufGvbHmh+traVPC2zHksZ/o5dF uizuYLgyxIHm//GuBjPGFN9zEqFR+xn+oZK2kDPjJWK0ICQfQynvegrv/JmBy4MFAzjZ plCg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=d1gHAJA7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Return-Path: Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id r20-20020a6560d4000000b00565dd3fbfdfsi469239pgv.214.2023.09.13.19.32.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Sep 2023 19:32:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=d1gHAJA7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 1AF158086516; Wed, 13 Sep 2023 07:02:01 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240816AbjIMOB5 (ORCPT + 99 others); Wed, 13 Sep 2023 10:01:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52316 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232734AbjIMOB4 (ORCPT ); Wed, 13 Sep 2023 10:01:56 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e5ab]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9C0C819B1 for ; Wed, 13 Sep 2023 07:01:52 -0700 (PDT) Received: from localhost (unknown [IPv6:2a01:e0a:2c:6930:5cf4:84a1:2763:fe0d]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: bbrezillon) by madras.collabora.co.uk (Postfix) with ESMTPSA id 1D09266072F4; Wed, 13 Sep 2023 15:01:51 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1694613711; bh=Mwd//y8kHHQGgFxOxx8+av5f6FESInoaEQ4FowrvBRI=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=d1gHAJA7me5QINpy/fe01qCDBjK6a3k8ZGjHTlZRJMsss8iNaPNzzed/8q67Ej39k tn2wBThiIyRHWTp5Ftq50mo5RRPWGF8n0ar4P4xfA1g2gnAsk2v0Z80SCc40D/7vWz hxNlHOIIX9OcORdPPDNy/TG5uv6tD2jXmYCI+fmAm9RYdYMY7Hw7UBKaIcpo3Ci5lX ZQcXG6wdt2rlfDPljmGaz43yMezvMLidAiwndcAlRE1l3N/IDJ3iCzMnhTjKF8QWwq QSzTdpjGaGcPw67BdXW4C3B3rdzxbW4v6tvlDgDBjWq/P54oCm1KzUiFlakMKgyB8O XYIOszqbo10gg== Date: Wed, 13 Sep 2023 16:01:48 +0200 From: Boris Brezillon To: Thomas =?UTF-8?B?SGVsbHN0csO2bQ==?= Cc: Dave Airlie , Danilo Krummrich , daniel@ffwll.ch, matthew.brost@intel.com, sarah.walker@imgtec.com, donald.robson@imgtec.com, christian.koenig@amd.com, faith.ekstrand@collabora.com, dri-devel@lists.freedesktop.org, nouveau@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH drm-misc-next v3 6/7] drm/gpuvm: generalize dma_resv/extobj handling and GEM validation Message-ID: <20230913160148.4d941975@collabora.com> In-Reply-To: <6f4c047d-0e6d-c45b-3092-cd0bc84849dc@linux.intel.com> References: <20230909153125.30032-1-dakr@redhat.com> <20230909153125.30032-7-dakr@redhat.com> <20230913090311.5eeb026a@collabora.com> <20230913091918.62c06a30@collabora.com> <20230913133318.15edec7c@collabora.com> <6f4c047d-0e6d-c45b-3092-cd0bc84849dc@linux.intel.com> Organization: Collabora X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; x86_64-redhat-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Wed, 13 Sep 2023 07:02:01 -0700 (PDT) X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email On Wed, 13 Sep 2023 15:22:56 +0200 Thomas Hellstr=C3=B6m wrote: > On 9/13/23 13:33, Boris Brezillon wrote: > > On Wed, 13 Sep 2023 12:39:01 +0200 > > Thomas Hellstr=C3=B6m wrote: > > =20 > >> Hi, > >> > >> On 9/13/23 09:19, Boris Brezillon wrote: =20 > >>> On Wed, 13 Sep 2023 17:05:42 +1000 > >>> Dave Airlie wrote: > >>> =20 > >>>> On Wed, 13 Sept 2023 at 17:03, Boris Brezillon > >>>> wrote: =20 > >>>>> On Tue, 12 Sep 2023 18:20:32 +0200 > >>>>> Thomas Hellstr=C3=B6m wrote: > >>>>> =20 > >>>>>>> +/** > >>>>>>> + * get_next_vm_bo_from_list() - get the next vm_bo element > >>>>>>> + * @__gpuvm: The GPU VM > >>>>>>> + * @__list_name: The name of the list we're iterating on > >>>>>>> + * @__local_list: A pointer to the local list used to store alre= ady iterated items > >>>>>>> + * @__prev_vm_bo: The previous element we got from drm_gpuvm_get= _next_cached_vm_bo() > >>>>>>> + * > >>>>>>> + * This helper is here to provide lockless list iteration. Lockl= ess as in, the > >>>>>>> + * iterator releases the lock immediately after picking the firs= t element from > >>>>>>> + * the list, so list insertion deletion can happen concurrently.= =20 > >>>>>> Are the list spinlocks needed for that async state update from wit= hin > >>>>>> the dma-fence critical section we've discussed previously? =20 > >>>>> Any driver calling _[un]link() from its drm_gpu_scheduler::run_job() > >>>>> hook will be in this situation (Panthor at the moment, PowerVR soon= ). I > >>>>> get that Xe and Nouveau don't need that because they update the VM > >>>>> state early (in the ioctl path), but I keep thinking this will hurt= us > >>>>> if we don't think it through from the beginning, because once you've > >>>>> set this logic to depend only on resv locks, it will be pretty hard= to > >>>>> get back to a solution which lets synchronous VM_BINDs take precede= nce > >>>>> on asynchronous request, and, with vkQueueBindSparse() passing exte= rnal > >>>>> deps (plus the fact the VM_BIND queue might be pretty deep), it can > >>>>> take a long time to get your synchronous VM_BIND executed... =20 > >> So this would boil down to either (possibly opt-in) keeping the spinlo= ck > >> approach or pushing the unlink out to a wq then? =20 > > Deferred _unlink() would not be an issue, since I already defer the > > drm_gpuva destruction to a wq, it would just a be a matter of moving the > > _unlink() call there as well. But _link() also takes the GEM gpuva list > > lock, and that one is bit tricky, in that sm_map() can trigger 2 more > > _link() calls for the prev/next mappings, which we can't guess until we > > get to execute the VM update. If we mandate the use of the GEM resv > > lock, that simply means async VM updates (AKA calling > > drm_gpuvm_sm_[un]map()) are not an option. And if this is what everyone > > agrees on, then I'd like the APIs that make this sort of async VM > > update possible (drm_gpuvm_sm_[un]map(), the drm_gpuvm_ops::sm_step* > > methods, and probably other things) to be dropped, so we don't make it > > look like it's something we support. > > =20 > >> BTW, as also asked in a reply to Danilo, how do you call unlink from > >> run_job() when it was requiring the obj->dma_resv lock, or was that a = WIP? =20 > > _unlink() makes sure the GEM gpuva list lock is taken, but this can be > > a custom lock (see drm_gem_gpuva_set_lock()). In panthor we have > > panthor_gem_object::gpuva_list_lock that's dedicated the gpuva list > > protection. We make sure we never take this lock while allocating > > memory to guarantee the dma-signalling path can't deadlock. > > =20 > >>>>> =20 > >>>> btw what is the use case for this? do we have actual vulkan > >>>> applications we know will have problems here? =20 > >>> I don't, but I think that's a concern Faith raised at some point (dat= es > >>> back from when I was reading threads describing how VM_BIND on i915 > >>> should work, and I was clearly discovering this whole VM_BIND thing at > >>> that time, so maybe I misunderstood). > >>> =20 > >>>> it feels like a bit of premature optimisation, but maybe we have use= cases. =20 > >>> Might be, but that's the sort of thing that would put us in a corner = if > >>> we don't have a plan for when the needs arise. Besides, if we don't > >>> want to support that case because it's too complicated, I'd recommend > >>> dropping all the drm_gpuvm APIs that let people think this mode is > >>> valid/supported (map/remap/unmap hooks in drm_gpuvm_ops, > >>> drm_gpuvm_sm_[un]map helpers, etc). Keeping them around just adds to = the > >>> confusion. =20 > >> Xe allows bypassing the bind-queue with another bind-queue, but to > >> completely avoid dependencies between queues the Operations may not > >> overlap. =20 > > So, you check the VM state with some VM lock held (would be the VM resv > > in my case), and if the mapping is new (no overlaps with pre-existing > > mappings), you queue it to the fast-track/sync-VM_BIND queue. What would > > be missing I guess is a way to know if the mapping is active (MMU has > > been updated) or pending (MMU update queued to the bind-queue), so I can > > fast-track mapping/unmapping of active mappings. This would leave > > overlapping sync/async VM updates, which can't happen in practice > > unless userspace is doing something wrong (sparse bindings always go > > through vkQueueBindSparse). =20 >=20 > User-space is allowed to create new bind queues at will, and they=20 > execute independently save for range overlaps. I've limited panthor to just one bind-queue that's automatically created when the VM is created. I guess letting userspace create more than one queue is doable, but we'd still be serializing VM operations anyway and that complicates the whole thing when concurrent operations to the same VM region happen from different bind queues, so I figured it'd be simpler to expose just one queue. >=20 > And the overlapping granularity depends very much on the detail of the=20 > range tracking. > We drafted this fenced range utility >=20 > https://gitlab.freedesktop.org/drm/xe/kernel/-/merge_requests/353 >=20 > That tracks active ranges that remove themselves when the attached fence= =20 > signals. Not sure if we ended up using it, though. A new binding would=20 > scan this utility for dma-fences it needs to depend upon. Sounds like implicit deps on VM ranges :D. I'll have a look, thanks for the pointer!=20 > Ranges in Xe=20 > are actually page-table modification ranges, so can exceed the actual VA= =20 > range in some situations, but if you can build page-table structures=20 > async the granularity indeed becomes better. The granularity in Mali is 4k, and we don't build the page table struct asynchronously, we just update the page table tree from the CPU, holding a VM lock to serialize such operations (that's done synchronously in the ::run_job() path, or from the ioctl in case of a sync-VM_BIND). >=20 > /Thomas >=20 >=20 >=20 > > > > I'll give it a try. > > =20 > >> (And the definition of overlap is currently page-table > >> structure updates may not overlap) but no guarantees are made about > >> priority. > >> > >> /Thomas > >> > >> > >> =20