From nobody Thu Sep 11 15:18:05 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1128AC001DB for ; Fri, 4 Aug 2023 18:26:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230211AbjHDS0t (ORCPT ); Fri, 4 Aug 2023 14:26:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53186 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231196AbjHDSZh (ORCPT ); Fri, 4 Aug 2023 14:25:37 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 096C24EC1 for ; Fri, 4 Aug 2023 11:24:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1691173486; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=AdYXUTjXeD+srFScWAxgyp5PN7Frlivhk/MIfK7tk74=; b=A9HX3LnhJ0q6ksFaGyxUMfONHZNpUgATlP4JI20OcYWaqSDeZJfBCHVpT3y3tDUREJDNWb NV/7VXE/zh//7CLn3tv81k84uEM0RJA9sCSpm7oSTbslhkgFOJmnAh6/aFmA5DKq3duBBT 6BF24jCh2FBLFlWfFcsHT9GCIFfcnzM= Received: from mail-ej1-f70.google.com (mail-ej1-f70.google.com [209.85.218.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-295-m16O31OnPkGJDKcmrcqozg-1; Fri, 04 Aug 2023 14:24:44 -0400 X-MC-Unique: m16O31OnPkGJDKcmrcqozg-1 Received: by mail-ej1-f70.google.com with SMTP id a640c23a62f3a-94f7a2b21fdso164131666b.2 for ; Fri, 04 Aug 2023 11:24:44 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691173484; x=1691778284; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=AdYXUTjXeD+srFScWAxgyp5PN7Frlivhk/MIfK7tk74=; b=kVk4fJbqIpsJx8E/XfZ0q9sprtl5fQocqlmdBnEWV76fZ2kQLziGnVzBg/xP2mFdk2 GxzZSlAZsalgIVHOnQeHwH1JiZtHmcb7ymkW+17gRDOGJx1i/PmbdtT5uridA+7pRY8y b5W5iTGDgaRfW99wWtBU3EpQAEpii2XFZ8kYKCUixvf1bMIw4BK65UMGPOmjCAboHUeb rV5VpxqT0H2tuR1cPoaM7Gw3210CtxEW9mclH2U/zIX2b6tSUht6hNHjRNiAM4ppiUTb hRosEgJkNKEJmkHtYdMOsAKBjv5mbe4rEGXq+tf6M5mHvB2efVPG+hz6TS+KC8zZodJC Mxyw== X-Gm-Message-State: AOJu0YzoweZsRC+WSJS9NAIbRRBtXNlfDLlaVK4PAz1WbXx1QGtAzeuQ FTt+63MWYHICv8rhFE1YFFbRqb4Iw7j6/4iMYe+WZqfwW1YiccykUdq+642U7mffd+fFrXpUUq6 W6CJXZTVur3tiA1uo+4XW3LEw X-Received: by 2002:a17:906:10cb:b0:99b:574f:d201 with SMTP id v11-20020a17090610cb00b0099b574fd201mr2292910ejv.40.1691173483734; Fri, 04 Aug 2023 11:24:43 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFUyXGNtbE+Mp2LUBU0xa17SUC/SHJoKkj49VpSr5tsgT1IZzi5FzBBpls7vLZVxNQNIy4AfA== X-Received: by 2002:a17:906:10cb:b0:99b:574f:d201 with SMTP id v11-20020a17090610cb00b0099b574fd201mr2292900ejv.40.1691173483554; Fri, 04 Aug 2023 11:24:43 -0700 (PDT) Received: from cassiopeiae.. ([2a02:810d:4b3f:de9c:642:1aff:fe31:a19f]) by smtp.gmail.com with ESMTPSA id j11-20020a1709062a0b00b0099bd5d28dc4sm1623127eje.195.2023.08.04.11.24.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Aug 2023 11:24:42 -0700 (PDT) From: Danilo Krummrich To: airlied@gmail.com, daniel@ffwll.ch, tzimmermann@suse.de, mripard@kernel.org, corbet@lwn.net, christian.koenig@amd.com, bskeggs@redhat.com, Liam.Howlett@oracle.com, matthew.brost@intel.com, boris.brezillon@collabora.com, alexdeucher@gmail.com, ogabbay@kernel.org, bagasdotme@gmail.com, willy@infradead.org, jason@jlekstrand.net, donald.robson@imgtec.com Cc: dri-devel@lists.freedesktop.org, nouveau@lists.freedesktop.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, Danilo Krummrich , Dave Airlie Subject: [PATCH drm-misc-next v10 07/12] drm/nouveau: fence: separate fence alloc and emit Date: Fri, 4 Aug 2023 20:23:47 +0200 Message-ID: <20230804182406.5222-8-dakr@redhat.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230804182406.5222-1-dakr@redhat.com> References: <20230804182406.5222-1-dakr@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The new (VM_BIND) UAPI exports DMA fences through DRM syncobjs. Hence, in order to emit fences within DMA fence signalling critical sections (e.g. as typically done in the DRM GPU schedulers run_job() callback) we need to separate fence allocation and fence emitting. Reviewed-by: Dave Airlie Signed-off-by: Danilo Krummrich --- drivers/gpu/drm/nouveau/dispnv04/crtc.c | 9 ++++- drivers/gpu/drm/nouveau/nouveau_bo.c | 52 +++++++++++++++---------- drivers/gpu/drm/nouveau/nouveau_chan.c | 6 ++- drivers/gpu/drm/nouveau/nouveau_dmem.c | 9 +++-- drivers/gpu/drm/nouveau/nouveau_fence.c | 16 +++----- drivers/gpu/drm/nouveau/nouveau_fence.h | 3 +- drivers/gpu/drm/nouveau/nouveau_gem.c | 5 ++- 7 files changed, 59 insertions(+), 41 deletions(-) diff --git a/drivers/gpu/drm/nouveau/dispnv04/crtc.c b/drivers/gpu/drm/nouv= eau/dispnv04/crtc.c index a6f2e681bde9..a34924523133 100644 --- a/drivers/gpu/drm/nouveau/dispnv04/crtc.c +++ b/drivers/gpu/drm/nouveau/dispnv04/crtc.c @@ -1122,11 +1122,18 @@ nv04_page_flip_emit(struct nouveau_channel *chan, PUSH_NVSQ(push, NV_SW, NV_SW_PAGE_FLIP, 0x00000000); PUSH_KICK(push); =20 - ret =3D nouveau_fence_new(chan, false, pfence); + ret =3D nouveau_fence_new(pfence); if (ret) goto fail; =20 + ret =3D nouveau_fence_emit(*pfence, chan); + if (ret) + goto fail_fence_unref; + return 0; + +fail_fence_unref: + nouveau_fence_unref(pfence); fail: spin_lock_irqsave(&dev->event_lock, flags); list_del(&s->head); diff --git a/drivers/gpu/drm/nouveau/nouveau_bo.c b/drivers/gpu/drm/nouveau= /nouveau_bo.c index 6130c99b6b2c..e38e448d9632 100644 --- a/drivers/gpu/drm/nouveau/nouveau_bo.c +++ b/drivers/gpu/drm/nouveau/nouveau_bo.c @@ -823,29 +823,39 @@ nouveau_bo_move_m2mf(struct ttm_buffer_object *bo, in= t evict, mutex_lock(&cli->mutex); else mutex_lock_nested(&cli->mutex, SINGLE_DEPTH_NESTING); + ret =3D nouveau_fence_sync(nouveau_bo(bo), chan, true, ctx->interruptible= ); - if (ret =3D=3D 0) { - ret =3D drm->ttm.move(chan, bo, bo->resource, new_reg); - if (ret =3D=3D 0) { - ret =3D nouveau_fence_new(chan, false, &fence); - if (ret =3D=3D 0) { - /* TODO: figure out a better solution here - * - * wait on the fence here explicitly as going through - * ttm_bo_move_accel_cleanup somehow doesn't seem to do it. - * - * Without this the operation can timeout and we'll fallback to a - * software copy, which might take several minutes to finish. - */ - nouveau_fence_wait(fence, false, false); - ret =3D ttm_bo_move_accel_cleanup(bo, - &fence->base, - evict, false, - new_reg); - nouveau_fence_unref(&fence); - } - } + if (ret) + goto out_unlock; + + ret =3D drm->ttm.move(chan, bo, bo->resource, new_reg); + if (ret) + goto out_unlock; + + ret =3D nouveau_fence_new(&fence); + if (ret) + goto out_unlock; + + ret =3D nouveau_fence_emit(fence, chan); + if (ret) { + nouveau_fence_unref(&fence); + goto out_unlock; } + + /* TODO: figure out a better solution here + * + * wait on the fence here explicitly as going through + * ttm_bo_move_accel_cleanup somehow doesn't seem to do it. + * + * Without this the operation can timeout and we'll fallback to a + * software copy, which might take several minutes to finish. + */ + nouveau_fence_wait(fence, false, false); + ret =3D ttm_bo_move_accel_cleanup(bo, &fence->base, evict, false, + new_reg); + nouveau_fence_unref(&fence); + +out_unlock: mutex_unlock(&cli->mutex); return ret; } diff --git a/drivers/gpu/drm/nouveau/nouveau_chan.c b/drivers/gpu/drm/nouve= au/nouveau_chan.c index 6d639314250a..f69be4c8f9f2 100644 --- a/drivers/gpu/drm/nouveau/nouveau_chan.c +++ b/drivers/gpu/drm/nouveau/nouveau_chan.c @@ -62,9 +62,11 @@ nouveau_channel_idle(struct nouveau_channel *chan) struct nouveau_fence *fence =3D NULL; int ret; =20 - ret =3D nouveau_fence_new(chan, false, &fence); + ret =3D nouveau_fence_new(&fence); if (!ret) { - ret =3D nouveau_fence_wait(fence, false, false); + ret =3D nouveau_fence_emit(fence, chan); + if (!ret) + ret =3D nouveau_fence_wait(fence, false, false); nouveau_fence_unref(&fence); } =20 diff --git a/drivers/gpu/drm/nouveau/nouveau_dmem.c b/drivers/gpu/drm/nouve= au/nouveau_dmem.c index 789857faa048..4ad40e42cae1 100644 --- a/drivers/gpu/drm/nouveau/nouveau_dmem.c +++ b/drivers/gpu/drm/nouveau/nouveau_dmem.c @@ -209,7 +209,8 @@ static vm_fault_t nouveau_dmem_migrate_to_ram(struct vm= _fault *vmf) goto done; } =20 - nouveau_fence_new(dmem->migrate.chan, false, &fence); + if (!nouveau_fence_new(&fence)) + nouveau_fence_emit(fence, dmem->migrate.chan); migrate_vma_pages(&args); nouveau_dmem_fence_done(&fence); dma_unmap_page(drm->dev->dev, dma_addr, PAGE_SIZE, DMA_BIDIRECTIONAL); @@ -402,7 +403,8 @@ nouveau_dmem_evict_chunk(struct nouveau_dmem_chunk *chu= nk) } } =20 - nouveau_fence_new(chunk->drm->dmem->migrate.chan, false, &fence); + if (!nouveau_fence_new(&fence)) + nouveau_fence_emit(fence, chunk->drm->dmem->migrate.chan); migrate_device_pages(src_pfns, dst_pfns, npages); nouveau_dmem_fence_done(&fence); migrate_device_finalize(src_pfns, dst_pfns, npages); @@ -675,7 +677,8 @@ static void nouveau_dmem_migrate_chunk(struct nouveau_d= rm *drm, addr +=3D PAGE_SIZE; } =20 - nouveau_fence_new(drm->dmem->migrate.chan, false, &fence); + if (!nouveau_fence_new(&fence)) + nouveau_fence_emit(fence, chunk->drm->dmem->migrate.chan); migrate_vma_pages(args); nouveau_dmem_fence_done(&fence); nouveau_pfns_map(svmm, args->vma->vm_mm, args->start, pfns, i); diff --git a/drivers/gpu/drm/nouveau/nouveau_fence.c b/drivers/gpu/drm/nouv= eau/nouveau_fence.c index ee5e9d40c166..e946408f945b 100644 --- a/drivers/gpu/drm/nouveau/nouveau_fence.c +++ b/drivers/gpu/drm/nouveau/nouveau_fence.c @@ -210,6 +210,9 @@ nouveau_fence_emit(struct nouveau_fence *fence, struct = nouveau_channel *chan) struct nouveau_fence_priv *priv =3D (void*)chan->drm->fence; int ret; =20 + if (unlikely(!chan->fence)) + return -ENODEV; + fence->channel =3D chan; fence->timeout =3D jiffies + (15 * HZ); =20 @@ -396,25 +399,16 @@ nouveau_fence_unref(struct nouveau_fence **pfence) } =20 int -nouveau_fence_new(struct nouveau_channel *chan, bool sysmem, - struct nouveau_fence **pfence) +nouveau_fence_new(struct nouveau_fence **pfence) { struct nouveau_fence *fence; - int ret =3D 0; - - if (unlikely(!chan->fence)) - return -ENODEV; =20 fence =3D kzalloc(sizeof(*fence), GFP_KERNEL); if (!fence) return -ENOMEM; =20 - ret =3D nouveau_fence_emit(fence, chan); - if (ret) - nouveau_fence_unref(&fence); - *pfence =3D fence; - return ret; + return 0; } =20 static const char *nouveau_fence_get_get_driver_name(struct dma_fence *fen= ce) diff --git a/drivers/gpu/drm/nouveau/nouveau_fence.h b/drivers/gpu/drm/nouv= eau/nouveau_fence.h index 0ca2bc85adf6..7c73c7c9834a 100644 --- a/drivers/gpu/drm/nouveau/nouveau_fence.h +++ b/drivers/gpu/drm/nouveau/nouveau_fence.h @@ -17,8 +17,7 @@ struct nouveau_fence { unsigned long timeout; }; =20 -int nouveau_fence_new(struct nouveau_channel *, bool sysmem, - struct nouveau_fence **); +int nouveau_fence_new(struct nouveau_fence **); void nouveau_fence_unref(struct nouveau_fence **); =20 int nouveau_fence_emit(struct nouveau_fence *, struct nouveau_channel *); diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouvea= u/nouveau_gem.c index a48f42aaeab9..9c8d1b911a01 100644 --- a/drivers/gpu/drm/nouveau/nouveau_gem.c +++ b/drivers/gpu/drm/nouveau/nouveau_gem.c @@ -873,8 +873,11 @@ nouveau_gem_ioctl_pushbuf(struct drm_device *dev, void= *data, } } =20 - ret =3D nouveau_fence_new(chan, false, &fence); + ret =3D nouveau_fence_new(&fence); + if (!ret) + ret =3D nouveau_fence_emit(fence, chan); if (ret) { + nouveau_fence_unref(&fence); NV_PRINTK(err, cli, "error fencing pushbuf: %d\n", ret); WIND_RING(chan); goto out; --=20 2.41.0