Received: by 2002:a05:7412:251c:b0:e2:908c:2ebd with SMTP id w28csp1459009rda; Mon, 23 Oct 2023 13:18:36 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGOVWxGC+h7+Ud83F9ADZUoK8yR0u1S21Rf+48NbFVRSOrZ84ygpVgl30dI32U7F1Pag3e9 X-Received: by 2002:a17:902:f104:b0:1c9:dff1:6ded with SMTP id e4-20020a170902f10400b001c9dff16dedmr6727239plb.1.1698092316564; Mon, 23 Oct 2023 13:18:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698092316; cv=none; d=google.com; s=arc-20160816; b=Zr3CRYOnPbTIXoime5D+flexSAnaxxZu1lA73KrzQpIPknYHoR5S5GmgDvUGjvN+ms EHo6knfR5+deAf6K2zr+dlQGSXuyht4OCfGY15F7JcoVYbYImJfYYVtoPB6OTRZQi6qN A2NC85QFrrrfSIktdfAZ9MOKdMwAL9OqOnMu4Pke9FnmAf399S8TUVRgdLsHEwXQREjl 5QmOSv2v6OcDO2rBrCTEqaDX2jHhmhJOUeNuo3pE4R6rIhS3p/Ii4Ikb0GwveCi1Pl07 vDdEIQMjSrBl0OFaijit0SwSGcuHAG3ndQhMc6A+5z80e1RbdLZ3lXvyd4LmFbKy4LFH Xppw== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=pXbkmp90Ht3YmNZtihTIxAiHljHUVhjWIR13eg3J3rQ=; fh=8dtrvlz6eC1As92HJPwYWdp8qGhbMzdOhqcu6vG4iUM=; b=Aeh7RltHxtbw0mnfWgCBdb0lZtJOBBaKEbth7ZcD0/J1kr4TXzfp9Rj0m2qOU67DnK 62v8ERGdjuGUyM2VHnd4AM0Tr77gMbTRlvVh73rFjoXDwGrn1WY8biQj9Lrg9IWccSMl 2HAvWDqyJMx1f6UosxYPWuAC5xDqO/H+iac68O5zYsGX6p14mHVYviL3gDWvkYaeJqSa tW0mKPGGJI82AiQ3mV34pFVEEyyhHR45LfZhTkUzIptSur5ITCfRN5q8QxVGUt+N1aeo lm1dJckdX9SkWUWwl/efy6i0MMEs3/tR+2k/agPkmltDz7PBYQ6Cpqf9KIpUeQMb6HJb on2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=gyoOUbEQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 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 fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id x17-20020a170902ec9100b001c61a27f5b6si7168163plg.400.2023.10.23.13.18.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Oct 2023 13:18:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=gyoOUbEQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 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 fry.vger.email (Postfix) with ESMTP id 8434280557EB; Mon, 23 Oct 2023 13:18:27 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229662AbjJWUSJ (ORCPT + 99 others); Mon, 23 Oct 2023 16:18:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48756 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229482AbjJWUSI (ORCPT ); Mon, 23 Oct 2023 16:18:08 -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 E6E641A4 for ; Mon, 23 Oct 2023 13:17:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1698092241; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=pXbkmp90Ht3YmNZtihTIxAiHljHUVhjWIR13eg3J3rQ=; b=gyoOUbEQhrQowMmn3KCzMz+NOHvEsQoNJ51B8bRsaHx8PYrTSKxCjSuVlv1lWwrhnOa/lF WSiUON5iFNSgU3cTNTVLeMiStMwqoNqegWNjE4nvstRhsYYzDdXxSRHoYGndkymZzKo2e/ QRNDBtNm1zmonLrxWunwdUBcpM9cYzo= Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-57-uu8AWSyYNROhjAQ8P-_1PQ-1; Mon, 23 Oct 2023 16:17:04 -0400 X-MC-Unique: uu8AWSyYNROhjAQ8P-_1PQ-1 Received: by mail-ed1-f71.google.com with SMTP id 4fb4d7f45d1cf-53e3120ae44so2573597a12.2 for ; Mon, 23 Oct 2023 13:17:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698092223; x=1698697023; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=pXbkmp90Ht3YmNZtihTIxAiHljHUVhjWIR13eg3J3rQ=; b=FmAVleg1uf9U/zinoA57kjPYJws+I1eESpSLlKmv6G4ACivwokjRGCtpJf3sX9ZoED WmbDNZhWHoPE+CoYs7jqJhSiz9Zz5nc9gQhTvt/qsfoy7uJvqwaLeuZgnp6SB9H/zMFY 6MXHnunQIxHF7SGVATJpkDmpCEGTz0/zWXFkyClwxQWQYgFsV5cE4HkC5IdEKXcZy8Rh M5OtH4hIX3IcYKMfGCgrDWslA6fe1Oxx1aekan1gU1Sm9gl9uvuWX24XGy7eZyFsSXlA dODvLYz9ID8z9gXwB9mNhheinp3EAAWqVe8aPTznUv0jFY21Y1reWxf4H/Uuf548OyDU eiag== X-Gm-Message-State: AOJu0YyXpJ8J6ytO/thZV54MFircivlfJUpDnNeRYWxutn6oqPwfIOug t/A923R9x5RlUCf6oyDWdvxjWvkq/gtQWM893NCW416ww6GuFkPpCWfmiOq0gtvIF7dM/u0iLAc jjJ6jNGyVeTWc4Pv4rsQbgLOL X-Received: by 2002:a50:9fab:0:b0:53d:f4a2:5140 with SMTP id c40-20020a509fab000000b0053df4a25140mr6869147edf.33.1698092223711; Mon, 23 Oct 2023 13:17:03 -0700 (PDT) X-Received: by 2002:a50:9fab:0:b0:53d:f4a2:5140 with SMTP id c40-20020a509fab000000b0053df4a25140mr6869131edf.33.1698092223407; Mon, 23 Oct 2023 13:17:03 -0700 (PDT) Received: from cassiopeiae.. ([2a02:810d:4b3f:de9c:642:1aff:fe31:a19f]) by smtp.gmail.com with ESMTPSA id n4-20020a05640205c400b0053f9578ec97sm6745844edx.56.2023.10.23.13.17.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Oct 2023 13:17:02 -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 v7 0/7] [RFC] DRM GPUVM features Date: Mon, 23 Oct 2023 22:16:46 +0200 Message-ID: <20231023201659.25332-1-dakr@redhat.com> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,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 fry.vger.email 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 (fry.vger.email [0.0.0.0]); Mon, 23 Oct 2023 13:18:27 -0700 (PDT) Currently GPUVM offers common infrastructure to track GPU VA allocations and mappings, generically connect GPU VA mappings to their backing buffers and perform more complex mapping operations on the GPU VA space. However, there are more design patterns commonly used by drivers, which can potentially be generalized in order to make GPUVM represent the basis of a VM implementation. In this context, this patch series aims at generalizing the following elements. 1) Provide a common dma-resv for GEM objects not being used outside of this GPU-VM. 2) Provide tracking of external GEM objects (GEM objects which are shared with other GPU-VMs). 3) Provide functions to efficiently lock all GEM objects dma-resv the GPU-VM contains mappings of. 4) Provide tracking of evicted GEM objects the GPU-VM contains mappings of, such that validation of evicted GEM objects is accelerated. 5) Provide some convinience functions for common patterns. The implementation introduces struct drm_gpuvm_bo, which serves as abstraction combining a struct drm_gpuvm and struct drm_gem_object, similar to what amdgpu does with struct amdgpu_bo_vm. While this adds a bit of complexity it improves the efficiency of tracking external and evicted GEM objects. This patch series is also available at [3]. [1] https://gitlab.freedesktop.org/nouvelles/kernel/-/commits/gpuvm-next Changes in V2: ============== - rename 'drm_gpuva_manager' -> 'drm_gpuvm' which generally leads to more consistent naming - properly separate commits (introduce common dma-resv, drm_gpuvm_bo abstraction, etc.) - remove maple tree for tracking external objects, use a list drm_gpuvm_bos per drm_gpuvm instead - rework dma-resv locking helpers (Thomas) - add a locking helper for a given range of the VA space (Christian) - make the GPUVA manager buildable as module, rather than drm_exec builtin (Christian) Changes in V3: ============== - rename missing function and files (Boris) - warn if vm_obj->obj != obj in drm_gpuva_link() (Boris) - don't expose drm_gpuvm_bo_destroy() (Boris) - unlink VM_BO from GEM in drm_gpuvm_bo_destroy() rather than drm_gpuva_unlink() and link within drm_gpuvm_bo_obtain() to keep drm_gpuvm_bo instances unique - add internal locking to external and evicted object lists to support drivers updating the VA space from within the fence signalling critical path (Boris) - unlink external objects and evicted objects from the GPUVM's list in drm_gpuvm_bo_destroy() - add more documentation and fix some kernel doc issues Changes in V4: ============== - add a drm_gpuvm_resv() helper (Boris) - add a drm_gpuvm::::local_list field (Boris) - remove drm_gpuvm_bo_get_unless_zero() helper (Boris) - fix missing NULL assignment in get_next_vm_bo_from_list() (Boris) - keep a drm_gem_object reference on potential vm_bo destroy (alternatively we could free the vm_bo and drop the vm_bo's drm_gem_object reference through async work) - introduce DRM_GPUVM_RESV_PROTECTED flag to indicate external locking through the corresponding dma-resv locks to optimize for drivers already holding them when needed; add the corresponding lock_assert_held() calls (Thomas) - make drm_gpuvm_bo_evict() per vm_bo and add a drm_gpuvm_bo_gem_evict() helper (Thomas) - pass a drm_gpuvm_bo in drm_gpuvm_ops::vm_bo_validate() (Thomas) - documentation fixes Changes in V5: ============== - use a root drm_gem_object provided by the driver as a base for the VM's common dma-resv (Christian) - provide a helper to allocate a "dummy" root GEM object in case a driver specific root GEM object isn't available - add a dedicated patch for nouveau to make use of the GPUVM's shared dma-resv - improve documentation (Boris) - the following patches are removed from the series, since they already landed in drm-misc-next - f72c2db47080 ("drm/gpuvm: rename struct drm_gpuva_manager to struct drm_gpuvm") - fe7acaa727e1 ("drm/gpuvm: allow building as module") - 78f54469b871 ("drm/nouveau: uvmm: rename 'umgr' to 'base'") Changes in V6: ============== - add drm_gpuvm_bo::evicted field protected by the drm_gem_object's dma-resv lock (Thomas) - additionally to the original proposal, always use drm_gpuvm_bo::evicted regardless of the used locking scheme and always keep it up to date - remove unneccesary get->put dance in drm_gpuva_unlink() (Thomas) - fix commit message wording (Thomas) - fix kernel doc warnings (kernel test robot) Changes in V7: ============== - add a patch converting WARN() macros to drm_WARN() variants - allow drivers to pass the number of fences to reserve and the drm_exec flags through struct drm_gpuvm_exec - rename 'root' GEM object to 'resv' GEM object - fix order of private_usage and extobj_usage in drm_gpuvm_resv_add_fence() - always set drm_gpuvm_bo::evicted accordingly - explicitly clear drm_gpuvm_bo from evict list after successful validation - group reference get() calls with pointer assignments - call drm_gem_object_put() after vm_bo_free() callback - make lockdep checks explicit for drm_gpuvm_bo_* functions - improve documentation of struct drm_gpuvm_bo - fix a few documentation typos and style issues - use BIT() instead of shift ops for enum drm_gpuvm_flags Danilo Krummrich (7): drm/gpuvm: convert WARN() to drm_WARN() variants drm/gpuvm: add common dma-resv per struct drm_gpuvm drm/gpuvm: add drm_gpuvm_flags to drm_gpuvm drm/gpuvm: add an abstraction for a VM / BO combination drm/gpuvm: track/lock/validate external/evicted objects drm/nouveau: make use of the GPUVM's shared dma-resv drm/nouveau: use GPUVM common infrastructure drivers/gpu/drm/drm_gpuvm.c | 1054 +++++++++++++++++++++-- drivers/gpu/drm/nouveau/nouveau_bo.c | 15 +- drivers/gpu/drm/nouveau/nouveau_bo.h | 5 + drivers/gpu/drm/nouveau/nouveau_exec.c | 57 +- drivers/gpu/drm/nouveau/nouveau_exec.h | 4 - drivers/gpu/drm/nouveau/nouveau_gem.c | 10 +- drivers/gpu/drm/nouveau/nouveau_sched.c | 9 +- drivers/gpu/drm/nouveau/nouveau_sched.h | 7 +- drivers/gpu/drm/nouveau/nouveau_uvmm.c | 189 ++-- drivers/gpu/drm/nouveau/nouveau_uvmm.h | 1 - include/drm/drm_gem.h | 32 +- include/drm/drm_gpuvm.h | 492 ++++++++++- 12 files changed, 1673 insertions(+), 202 deletions(-) base-commit: f5b55f32ce4ba953c270b2e9c3f5d4cd6951b1a1 -- 2.41.0