Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp2804489rdb; Tue, 12 Sep 2023 12:34:20 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFLrQCjZ45ec+u4axfEtN0vfNmnAA73qRsGQ/aSpu9ldRh1Yj/efEkLFhavczUl8EcR2zHR X-Received: by 2002:a17:902:f80a:b0:1be:ff74:ec21 with SMTP id ix10-20020a170902f80a00b001beff74ec21mr733593plb.27.1694547260166; Tue, 12 Sep 2023 12:34:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694547260; cv=none; d=google.com; s=arc-20160816; b=Aj4CfIGxwgHXR7N7SyNjcmUEozmnPiufri3lSkAcyOwfnisl4NcsaTWZvjOKbnilB1 A9MMze8Zazgar6VkoEgLSuRCejys3wAv1wQ/FuWXRAGW/sY8ZjJknfO17JWF8CKVZAII i+xljnBVdLEsd+lCdlJPQ1BUmoF8W7mLZ3lfHIDfUbI/cxRAl6JtPKsFoq+uxY6++WfY UgchhQIyJq0Urub1c9IcQLykPuSCjz6Jizhm2rMx0KOBVlD101absDD0IpApkrifoxcB sV5xjSbs6GU0l8kM6K6MwHgGUFIK8lqik7Hc+LbD+IwqtGJoEjXXTFwy3rrA9y9c6tn+ nfGA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=ajMRGEYrbBv/i5mL3qJAhrVnaIQ2YcBHMEZHgckMCIE=; fh=yWmRpKIWIw5F4+VlUYq1cqlV7y6vh1Q4ItRc70Hs08g=; b=whdz7kvI24oxo4uXesni/+7Gb9ePRhPit/sl490TSWDyPVM/UmaITLt5YLpGOOiBsW efTXC1J8ihf2/TqC0ri7M6fC/F9FP0NkgjgVr255xAMTUf7CBO9KvoKARr83a65R6Tkf OAtv5L1pxdl1mlgxs+BV0tB68I/mCgnl+puRsxxWHD22A2YAL6we6YPluSTtODmY8P+g BHbZtqq1DJKLi3cPJDLSjPr54+xoIJxPThMSBf1wM9mlU6eczYOECR4c2zPBwvyvInKb 8dwOOheQfd4dyykrcOJjFRcLYTkHhOeQ4zYfXUrWQC4I2O/ROQ/uczf68oYWNSb0bPUj 8AiQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=abaI0fwB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id z1-20020a1709027e8100b001bf2931ccd1si8454090pla.579.2023.09.12.12.34.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Sep 2023 12:34:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=abaI0fwB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 275CD810FBDD; Tue, 12 Sep 2023 03:35:57 -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 S231560AbjILKf2 (ORCPT + 99 others); Tue, 12 Sep 2023 06:35:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49626 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234276AbjILKd0 (ORCPT ); Tue, 12 Sep 2023 06:33:26 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CE67419AC for ; Tue, 12 Sep 2023 03:33:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1694514800; x=1726050800; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=8t3tN4z2KMBNN5zbS0gpM5Z4a/MQjnGZId8LnAbZIZQ=; b=abaI0fwBIxDkkrrxTJ0HuBvz/HG7CI8MnGnNSaezVHlvSVmIlRCHs0lE I2Ms+AECuJ68LfDBF7r5KBE4ribr0x69R7r4fJ8Ot4e8Uw0KPeVzSZH+1 mC9i35Qub5vh0L4J65tS9kyzfI2Sti3qAr9pIpt/klzcEnXLwKKwkVQvk sB4xNbcwUBpQ60u452MTiBe8SBz+wLzaBHmABYhZArljiUBPyenrHY2Yb B+zlMS9XGJm1iS2jgKu+K8RnDSngt325BSE0jao7pOQsg6FTcvPXHg5Me /YAot0MxHcRfyUBEVKvoicacdXuj+SGSEuRL1LKOScshdVNp1kOF9Ps1E A==; X-IronPort-AV: E=McAfee;i="6600,9927,10830"; a="381037032" X-IronPort-AV: E=Sophos;i="6.02,139,1688454000"; d="scan'208";a="381037032" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Sep 2023 03:33:20 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10830"; a="990458988" X-IronPort-AV: E=Sophos;i="6.02,139,1688454000"; d="scan'208";a="990458988" Received: from dhermamx-mobl1.amr.corp.intel.com (HELO [10.249.254.193]) ([10.249.254.193]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Sep 2023 03:33:17 -0700 Message-ID: <72461288-4248-9dd9-4417-aaa72b864805@linux.intel.com> Date: Tue, 12 Sep 2023 12:33:14 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 Subject: Re: [PATCH drm-misc-next v3 5/7] drm/gpuvm: add an abstraction for a VM / BO combination Content-Language: en-US To: Danilo Krummrich Cc: airlied@gmail.com, daniel@ffwll.ch, matthew.brost@intel.com, sarah.walker@imgtec.com, donald.robson@imgtec.com, boris.brezillon@collabora.com, christian.koenig@amd.com, faith.ekstrand@collabora.com, dri-devel@lists.freedesktop.org, nouveau@lists.freedesktop.org, linux-kernel@vger.kernel.org References: <20230909153125.30032-1-dakr@redhat.com> <20230909153125.30032-6-dakr@redhat.com> <0a8799c3-1d4c-8d87-ebca-013f6541fbc4@linux.intel.com> <06bbb49d-974f-e3bb-f844-1509313066cc@redhat.com> <05b06e5d-03aa-14f4-46b1-6057c4437043@linux.intel.com> From: =?UTF-8?Q?Thomas_Hellstr=c3=b6m?= In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit 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]); Tue, 12 Sep 2023 03:35:57 -0700 (PDT) X-Spam-Status: No, score=-2.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, NICE_REPLY_A,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 On 9/12/23 12:06, Danilo Krummrich wrote: > On Tue, Sep 12, 2023 at 09:42:44AM +0200, Thomas Hellström wrote: >> Hi, Danilo >> >> On 9/11/23 19:49, Danilo Krummrich wrote: >>> Hi Thomas, >>> >>> On 9/11/23 19:19, Thomas Hellström wrote: >>>> Hi, Danilo >>>> >>>> On 9/9/23 17:31, Danilo Krummrich wrote: >>>>> This patch adds an abstraction layer between the drm_gpuva mappings of >>>>> a particular drm_gem_object and this GEM object itself. The abstraction >>>>> represents a combination of a drm_gem_object and drm_gpuvm. The >>>>> drm_gem_object holds a list of drm_gpuvm_bo structures (the structure >>>>> representing this abstraction), while each drm_gpuvm_bo contains >>>>> list of >>>>> mappings of this GEM object. >>>>> >>>>> This has multiple advantages: >>>>> >>>>> 1) We can use the drm_gpuvm_bo structure to attach it to various lists >>>>>     of the drm_gpuvm. This is useful for tracking external and evicted >>>>>     objects per VM, which is introduced in subsequent patches. >>>>> >>>>> 2) Finding mappings of a certain drm_gem_object mapped in a certain >>>>>     drm_gpuvm becomes much cheaper. >>>>> >>>>> 3) Drivers can derive and extend the structure to easily represent >>>>>     driver specific states of a BO for a certain GPUVM. >>>>> >>>>> The idea of this abstraction was taken from amdgpu, hence the >>>>> credit for >>>>> this idea goes to the developers of amdgpu. >>>>> >>>>> Cc: Christian König >>>>> Signed-off-by: Danilo Krummrich >>>> Did you consider having the drivers embed the struct drm_gpuvm_bo in >>>> their own bo definition? I figure that would mean using the gem bo's >>>> refcounting and providing a helper to call from the driver's bo >>>> release. Looks like that could potentially save a lot of code? Or is >>>> there something that won't work with that approach? >>> There are drm_gpuvm_ops::vm_bo_alloc and drm_gpuvm_ops::vm_bo_free >>> callback for drivers to register for that purpose. >>> >>> - Danilo >> Now after looking a bit deeper, I think actually the question could be >> rephrased as, why don't we just use the >> struct drm_gem_object::gpuva struct as the drm_gpuvm_bo in the spirit of >> keeping things simple? Drivers would then just embed it in their bo subclass >> and we'd avoid unnecessary fields in the struct drm_gem_object for drivers >> that don't do VM_BIND yet. > struct drm_gem_object::gpuva is just a container containing a list in order to > (currently) attach drm_gpuva structs to it and with this patch attach > drm_gpuvm_bo structs (combination of BO + VM) to it. Doing the above basically > means "leave everything as it is, but move the list_head of drm_gpuvs per GEM to > the driver specific BO structure". Having a common connection between GEM > objects and drm_gpuva structs was one of the goals of the initial GPUVA manager > patch series however. > >> Sure, this won't be per bo and per vm, but it'd really only make a slight >> difference where we have multiple VMAs per bo, where per-vm per-bo state >> either needs to be duplicated or attached to a single vma (as in the case of >> the external bo list). > > Correct, one implication is that we don't get a per VM and BO abstraction, and > hence are left with a list of all drm_gpuva structs having the same backing BO, > regardless of the VM. > > For amdgpu this was always a concern. Now that we want to keep track of external > and evicted objects it's going to be a concern for most drivers I guess. Because > the only structure we could use for tracking external and evicted objects we are > left with (without having a VM_BO abstraction) is struct drm_gpuva. But this > structure isn't unique and we need to consider cases where userspace just > allocates rather huge BOs and creates tons of mappings from it. Running the full > list of drm_gpuva structs (with even the ones from other VMs included) for > adding an external or evicted object isn't very efficient. Not to mention that > the maintenance when the mapping we've (randomly) picked as an entry for the > external/evicted object list is unmapped, but there are still mappings left in > the VM with the same backing BO. For the evicted object it's not much of an issue; we maintain a list of vmas needing rebinding for each VM rather than objects evicted, so there is no or very little additional overhead there. The extobj list is indeed a problem if many VMAs are bound to the same bo. Not that the code snippets are complicated, but the list traversals would be excessive. > > Now, a way to get rid of the VM_BO abstraction would be to use maple trees > instead, since then we can store drm_gem_object structs directly for each VM. > However, Xe had concerns about using maple trees and preferred lists, plus > having maple trees wouldn't get rid of the concerns of amdgpu not having a VM_BO > abstraction for cases with tons of VMs and tons of mappings per BO. Hence, > having a VM_BO abstraction enabling us to track external/evicted objects with > lists seems to satisfy everyone's needs. Indeed this is a tradeoff between a simple implementation that is OK for situations with not many VMs nor VMAs per bo vs a more complex implementation that optimizes for the opposite case. So if this latter is a case we need to optimize for at this point then I guess it's the way to go. (I'm in the process of adapting the xe driver to this, so I just wanted to bring up areas where the implementations differ quite a lot and make sure options are discussed). Thanks, Thomas > > - Danilo > >> To me that looks like a substantial amount of less code / complexity? >> >> /Thomas >> >> >>>> Thanks, >>>> >>>> Thomas >>>> >>>>