Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp3618151rdh; Thu, 28 Sep 2023 18:26:30 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF3/qgPkNRDW85yVb58iE4vH6+naKqcOWmzXqBI2RhdqW49gHprICTAale/ZI+1/W38wYVo X-Received: by 2002:a17:902:8649:b0:1c3:1f0c:fb82 with SMTP id y9-20020a170902864900b001c31f0cfb82mr2370814plt.41.1695950790303; Thu, 28 Sep 2023 18:26:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695950790; cv=none; d=google.com; s=arc-20160816; b=w7etKG4BmmQ9C5RtvQSiKmd+hT6MIk/pLGyvnGwmluqqb+hB2JtIs3z7Hyd/0QcMYw 5A+GHQ+rWeaMNDmZvY30peOaKG97cifl5xtSmIg9tEohn7hsDRs4yEjrYM4kvVxdrl7+ 5zhaO8YZzSPGc3BbKHyOgoDlBLbSTjGHo13jupAb7py/nZDIqW8+uE+86AXGK2JwSVo8 CF5ytv1q1dPAmuq6NuQvQc2tKUH4nTaFiG3Ezs1vHokkp38RIBLs0ND5E1QYLl+vosrr wk0V7leEEPdnHTPdPHrsNU9ZxbxsM73OEkaPxUmJRZK/0U/B6a0O88i5ojS2LbZvuJ90 G7zA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=AhD6ZC3iGBzPWvT8PElG1SxOfr5EHAC4vZ+6Lwjv84w=; fh=8dtrvlz6eC1As92HJPwYWdp8qGhbMzdOhqcu6vG4iUM=; b=n2IOY31F42ut6Qtgh1eGEQHLdC5TM7SCAuM+eEnekPi0NPhD9sDUSaeWQ6iXBrSCC8 /Im96V+gq5peKW9gZcMdF7ZTfj/GkiC5lRMziEfJ/X6z1Q+K/WrRVhTIQjCzyrBMH2uF TLX8zMV6ldFBVaO+6s1dWsuj+MC4jjOi8sUwP7RASaTexmQ72nCpGgUVJJLGRSNNCdUv TMAM1ffCq2neX/fBGbniM6ZGYOcknQ45kRkoo8lx0RHgzE4iT/pjOffD6mZ+T1tmtfVR qSvZsiUtxKQK3pxRjPjnI5nMeSXFRv96XvrRwvTPS0mc0iPgl894vWZPxbrHnXqLiXOu oM1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=S6jiwcIO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id z14-20020a170903018e00b001c7245a1e73si7440138plg.32.2023.09.28.18.26.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Sep 2023 18:26:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=S6jiwcIO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 3DDE1825CD1C; Thu, 28 Sep 2023 12:18:02 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232303AbjI1TRn (ORCPT + 99 others); Thu, 28 Sep 2023 15:17:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41314 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232190AbjI1TRi (ORCPT ); Thu, 28 Sep 2023 15:17:38 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5B0A5195 for ; Thu, 28 Sep 2023 12:16:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695928610; 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=AhD6ZC3iGBzPWvT8PElG1SxOfr5EHAC4vZ+6Lwjv84w=; b=S6jiwcIOxNU5W6mlygCK2ccvIm3PEOcEW+W8lXFbo4ix/l7+DMtvgO3gojFvlpY0fL9O7X 1Wnj1qsTNus5CZPKdzeRNZJVZ7lqgT9/DpzF7VuNAiBk1TXrZ6SxDP/pykMQeE8X2V8z9q zYr2M3H+ys2rvYFSASJ2G2QdEhf1PwE= Received: from mail-ej1-f72.google.com (mail-ej1-f72.google.com [209.85.218.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-520-DFf5V15VNkqAU-uBubtatA-1; Thu, 28 Sep 2023 15:16:49 -0400 X-MC-Unique: DFf5V15VNkqAU-uBubtatA-1 Received: by mail-ej1-f72.google.com with SMTP id a640c23a62f3a-9ae52fbac1dso2531945266b.1 for ; Thu, 28 Sep 2023 12:16:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695928607; x=1696533407; 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=AhD6ZC3iGBzPWvT8PElG1SxOfr5EHAC4vZ+6Lwjv84w=; b=swhcL6QWfFFX4HzPmKM1QwlrpYnddjO+40Br5bYo2oaqDXc73m2mgA0G0VezZLThx7 HfUl7BwztWAhKuRkxAKZvd24/8cf0+/mVOLcTDNdKthkM+MrzgydTT2bpBnHNVE3/+Ri cM0kNfcZ8AZJ0Z73KfJO7UBdKW+Cj3M+2l7uLs6/ZAqyGmZ6VwMYnmx3UuZlnnv7NYhW Z0DiVLDvrjBhIwFl1Ii/HYmwR5NjOJ+TtJEHZiSIJNIf3e5UFv9d4Jny4FtuO8pv+UDg 2tKqdXAIHdXv0oizWRt8B9AaCiyFSN9T3MP+wdF2oFhfm3zf4uzqrWtdB4Q8XjRohUH3 JJqQ== X-Gm-Message-State: AOJu0YyTtj+hR3wgHnZyjt6M4al1QC9xcjBXFyIq/4BCH4pl80iCJ8d9 o0ifPRlwVidZ1ot5IjzDLElK2ov9M+2EZSRqbeY1j1QDnFBkWR90CYKl9EnF4FIJbT8kmInkcCI SxMQ2ZJY3yf3ZtMwz2gpO+0rS6xEV7e6r X-Received: by 2002:a17:907:1c09:b0:9a9:405b:26d1 with SMTP id nc9-20020a1709071c0900b009a9405b26d1mr2108801ejc.5.1695928607741; Thu, 28 Sep 2023 12:16:47 -0700 (PDT) X-Received: by 2002:a17:907:1c09:b0:9a9:405b:26d1 with SMTP id nc9-20020a1709071c0900b009a9405b26d1mr2108787ejc.5.1695928607515; Thu, 28 Sep 2023 12:16:47 -0700 (PDT) Received: from cassiopeiae.. ([2a02:810d:4b3f:de9c:642:1aff:fe31:a19f]) by smtp.gmail.com with ESMTPSA id e8-20020a170906374800b009920e9a3a73sm11286154ejc.115.2023.09.28.12.16.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Sep 2023 12:16:47 -0700 (PDT) From: Danilo Krummrich To: airlied@gmail.com, daniel@ffwll.ch, matthew.brost@intel.com, thomas.hellstrom@linux.intel.com, sarah.walker@imgtec.com, donald.robson@imgtec.com, boris.brezillon@collabora.com, christian.koenig@amd.com, faith@gfxstrand.net Cc: dri-devel@lists.freedesktop.org, nouveau@lists.freedesktop.org, linux-kernel@vger.kernel.org, Danilo Krummrich Subject: [PATCH drm-misc-next v5 5/6] drm/nouveau: make use of the GPUVM's shared dma-resv Date: Thu, 28 Sep 2023 21:16:19 +0200 Message-ID: <20230928191624.13703-6-dakr@redhat.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230928191624.13703-1-dakr@redhat.com> References: <20230928191624.13703-1-dakr@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 (howler.vger.email [0.0.0.0]); Thu, 28 Sep 2023 12:18:03 -0700 (PDT) DRM GEM objects private to a single GPUVM can use a shared dma-resv. Make use of the shared dma-resv of GPUVM rather than a driver specific one. The shared dma-resv originates from a "root" GEM object serving as container for the dma-resv to make it compatible with drm_exec. In order to make sure the object proving the shared dma-resv can't be freed up before the objects making use of it, let every such GEM object take a reference on it. Signed-off-by: Danilo Krummrich --- drivers/gpu/drm/nouveau/nouveau_bo.c | 11 +++++++++-- drivers/gpu/drm/nouveau/nouveau_bo.h | 5 +++++ drivers/gpu/drm/nouveau/nouveau_gem.c | 10 ++++++++-- drivers/gpu/drm/nouveau/nouveau_uvmm.c | 7 ++----- drivers/gpu/drm/nouveau/nouveau_uvmm.h | 1 - 5 files changed, 24 insertions(+), 10 deletions(-) diff --git a/drivers/gpu/drm/nouveau/nouveau_bo.c b/drivers/gpu/drm/nouveau/nouveau_bo.c index 19cab37ac69c..dbb3facfd23d 100644 --- a/drivers/gpu/drm/nouveau/nouveau_bo.c +++ b/drivers/gpu/drm/nouveau/nouveau_bo.c @@ -148,10 +148,17 @@ nouveau_bo_del_ttm(struct ttm_buffer_object *bo) * If nouveau_bo_new() allocated this buffer, the GEM object was never * initialized, so don't attempt to release it. */ - if (bo->base.dev) + if (bo->base.dev) { + /* Gem objects not being shared with other VMs get their + * dma_resv from a root GEM object. + */ + if (nvbo->no_share) + drm_gem_object_put(nvbo->r_obj); + drm_gem_object_release(&bo->base); - else + } else { dma_resv_fini(&bo->base._resv); + } kfree(nvbo); } diff --git a/drivers/gpu/drm/nouveau/nouveau_bo.h b/drivers/gpu/drm/nouveau/nouveau_bo.h index 07f671cf895e..70c551921a9e 100644 --- a/drivers/gpu/drm/nouveau/nouveau_bo.h +++ b/drivers/gpu/drm/nouveau/nouveau_bo.h @@ -26,6 +26,11 @@ struct nouveau_bo { struct list_head entry; int pbbo_index; bool validate_mapped; + + /* Root GEM object we derive the dma_resv of in case this BO is not + * shared between VMs. + */ + struct drm_gem_object *r_obj; bool no_share; /* GPU address space is independent of CPU word size */ diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c index c0b10d8d3d03..7715baf85c7e 100644 --- a/drivers/gpu/drm/nouveau/nouveau_gem.c +++ b/drivers/gpu/drm/nouveau/nouveau_gem.c @@ -111,7 +111,8 @@ nouveau_gem_object_open(struct drm_gem_object *gem, struct drm_file *file_priv) if (vmm->vmm.object.oclass < NVIF_CLASS_VMM_NV50) return 0; - if (nvbo->no_share && uvmm && &uvmm->resv != nvbo->bo.base.resv) + if (nvbo->no_share && uvmm && + drm_gpuvm_resv(&uvmm->base) != nvbo->bo.base.resv) return -EPERM; ret = ttm_bo_reserve(&nvbo->bo, false, false, NULL); @@ -245,7 +246,7 @@ nouveau_gem_new(struct nouveau_cli *cli, u64 size, int align, uint32_t domain, if (unlikely(!uvmm)) return -EINVAL; - resv = &uvmm->resv; + resv = drm_gpuvm_resv(&uvmm->base); } if (!(domain & (NOUVEAU_GEM_DOMAIN_VRAM | NOUVEAU_GEM_DOMAIN_GART))) @@ -288,6 +289,11 @@ nouveau_gem_new(struct nouveau_cli *cli, u64 size, int align, uint32_t domain, if (drm->client.device.info.family >= NV_DEVICE_INFO_V0_TESLA) nvbo->valid_domains &= domain; + if (nvbo->no_share) { + nvbo->r_obj = drm_gpuvm_resv_obj(&uvmm->base); + drm_gem_object_get(nvbo->r_obj); + } + *pnvbo = nvbo; return 0; } diff --git a/drivers/gpu/drm/nouveau/nouveau_uvmm.c b/drivers/gpu/drm/nouveau/nouveau_uvmm.c index 4e46f850e65f..436b0ac74ffe 100644 --- a/drivers/gpu/drm/nouveau/nouveau_uvmm.c +++ b/drivers/gpu/drm/nouveau/nouveau_uvmm.c @@ -1841,7 +1841,6 @@ nouveau_uvmm_init(struct nouveau_uvmm *uvmm, struct nouveau_cli *cli, int ret; mutex_init(&uvmm->mutex); - dma_resv_init(&uvmm->resv); mt_init_flags(&uvmm->region_mt, MT_FLAGS_LOCK_EXTERN); mt_set_external_lock(&uvmm->region_mt, &uvmm->mutex); @@ -1884,14 +1883,14 @@ nouveau_uvmm_init(struct nouveau_uvmm *uvmm, struct nouveau_cli *cli, kernel_managed_addr, kernel_managed_size, NULL, 0, &cli->uvmm.vmm.vmm); if (ret) - goto out_free_gpuva_mgr; + goto out_gpuvm_fini; cli->uvmm.vmm.cli = cli; mutex_unlock(&cli->mutex); return 0; -out_free_gpuva_mgr: +out_gpuvm_fini: drm_gpuvm_destroy(&uvmm->base); out_unlock: mutex_unlock(&cli->mutex); @@ -1949,6 +1948,4 @@ nouveau_uvmm_fini(struct nouveau_uvmm *uvmm) nouveau_vmm_fini(&uvmm->vmm); drm_gpuvm_destroy(&uvmm->base); mutex_unlock(&cli->mutex); - - dma_resv_fini(&uvmm->resv); } diff --git a/drivers/gpu/drm/nouveau/nouveau_uvmm.h b/drivers/gpu/drm/nouveau/nouveau_uvmm.h index a308c59760a5..878cc7958483 100644 --- a/drivers/gpu/drm/nouveau/nouveau_uvmm.h +++ b/drivers/gpu/drm/nouveau/nouveau_uvmm.h @@ -12,7 +12,6 @@ struct nouveau_uvmm { struct nouveau_vmm vmm; struct maple_tree region_mt; struct mutex mutex; - struct dma_resv resv; u64 kernel_managed_addr; u64 kernel_managed_size; -- 2.41.0