Re: [Nouveau] [PATCH drm-next v4 03/14] drm: manager to keep track of GPUs VA mappings
On Tue, Jun 13, 2023 at 08:29:35PM -0400, Liam R. Howlett wrote: > * Danilo Krummrich [230606 18:32]: > > Add infrastructure to keep track of GPU virtual address (VA) mappings > > with a decicated VA space manager implementation. > > > > New UAPIs, motivated by Vulkan sparse memory bindings graphics drivers > > start implementing, allow userspace applications to request multiple and > > arbitrary GPU VA mappings of buffer objects. The DRM GPU VA manager is > > intended to serve the following purposes in this context. > > > > 1) Provide infrastructure to track GPU VA allocations and mappings, > >making use of the maple_tree. > > > > 2) Generically connect GPU VA mappings to their backing buffers, in > >particular DRM GEM objects. > > > > 3) Provide a common implementation to perform more complex mapping > >operations on the GPU VA space. In particular splitting and merging > >of GPU VA mappings, e.g. for intersecting mapping requests or partial > >unmap requests. > > > > Suggested-by: Dave Airlie > > Signed-off-by: Danilo Krummrich > > --- > > Documentation/gpu/drm-mm.rst| 31 + > > drivers/gpu/drm/Makefile|1 + > > drivers/gpu/drm/drm_gem.c |3 + > > drivers/gpu/drm/drm_gpuva_mgr.c | 1687 +++ > > include/drm/drm_drv.h |6 + > > include/drm/drm_gem.h | 75 ++ > > include/drm/drm_gpuva_mgr.h | 681 + > > 7 files changed, 2484 insertions(+) > > create mode 100644 drivers/gpu/drm/drm_gpuva_mgr.c > > create mode 100644 include/drm/drm_gpuva_mgr.h > > > > diff --git a/Documentation/gpu/drm-mm.rst b/Documentation/gpu/drm-mm.rst > > index a52e6f4117d6..c9f120cfe730 100644 > > --- a/Documentation/gpu/drm-mm.rst > > +++ b/Documentation/gpu/drm-mm.rst > > @@ -466,6 +466,37 @@ DRM MM Range Allocator Function References > > .. kernel-doc:: drivers/gpu/drm/drm_mm.c > > :export: > > > > +DRM GPU VA Manager > > +== > > + > > +Overview > > + > > + > > +.. kernel-doc:: drivers/gpu/drm/drm_gpuva_mgr.c > > + :doc: Overview > > + > > +Split and Merge > > +--- > > + > > +.. kernel-doc:: drivers/gpu/drm/drm_gpuva_mgr.c > > + :doc: Split and Merge > > + > > +Locking > > +--- > > + > > +.. kernel-doc:: drivers/gpu/drm/drm_gpuva_mgr.c > > + :doc: Locking > > + > > + > > +DRM GPU VA Manager Function References > > +-- > > + > > +.. kernel-doc:: include/drm/drm_gpuva_mgr.h > > + :internal: > > + > > +.. kernel-doc:: drivers/gpu/drm/drm_gpuva_mgr.c > > + :export: > > + > > DRM Buddy Allocator > > === > > > > diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile > > index 9c6446eb3c83..8eeed446a078 100644 > > --- a/drivers/gpu/drm/Makefile > > +++ b/drivers/gpu/drm/Makefile > > @@ -45,6 +45,7 @@ drm-y := \ > > drm_vblank.o \ > > drm_vblank_work.o \ > > drm_vma_manager.o \ > > + drm_gpuva_mgr.o \ > > drm_writeback.o > > drm-$(CONFIG_DRM_LEGACY) += \ > > drm_agpsupport.o \ > > diff --git a/drivers/gpu/drm/drm_gem.c b/drivers/gpu/drm/drm_gem.c > > index 1a5a2cd0d4ec..cd878ebddbd0 100644 > > --- a/drivers/gpu/drm/drm_gem.c > > +++ b/drivers/gpu/drm/drm_gem.c > > @@ -164,6 +164,9 @@ void drm_gem_private_object_init(struct drm_device *dev, > > if (!obj->resv) > > obj->resv = >_resv; > > > > + if (drm_core_check_feature(dev, DRIVER_GEM_GPUVA)) > > + drm_gem_gpuva_init(obj); > > + > > drm_vma_node_reset(>vma_node); > > INIT_LIST_HEAD(>lru_node); > > } > > diff --git a/drivers/gpu/drm/drm_gpuva_mgr.c > > b/drivers/gpu/drm/drm_gpuva_mgr.c > > new file mode 100644 > > index ..dd8dd7fef14b > > --- /dev/null > > +++ b/drivers/gpu/drm/drm_gpuva_mgr.c > > @@ -0,0 +1,1687 @@ > > +// SPDX-License-Identifier: GPL-2.0 > > +/* > > + * Copyright (c) 2022 Red Hat. > > + * > > + * Permission is hereby granted, free of charge, to any person obtaining a > > + * copy of this software and associated documentation files (the > > "Software"), > > + * to deal in the Software without restriction, including without > > limitation > > + * the rights to use, copy, modify, merge, publish, distribute, sublicense, > > + * and/or sell copies of the Software, and to permit persons to whom the > > + * Software is furnished to do so, subject to the following conditions: > > + * > > + * The above copyright notice and this permission notice shall be included > > in > > + * all copies or substantial portions of the Software. > > + * > > + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS > > OR > > + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, > > + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL > > + * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR > > + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, > > + * ARISING
Re: [Nouveau] [PATCH drm-next v4 03/14] drm: manager to keep track of GPUs VA mappings
* Danilo Krummrich [230606 18:32]: > Add infrastructure to keep track of GPU virtual address (VA) mappings > with a decicated VA space manager implementation. > > New UAPIs, motivated by Vulkan sparse memory bindings graphics drivers > start implementing, allow userspace applications to request multiple and > arbitrary GPU VA mappings of buffer objects. The DRM GPU VA manager is > intended to serve the following purposes in this context. > > 1) Provide infrastructure to track GPU VA allocations and mappings, >making use of the maple_tree. > > 2) Generically connect GPU VA mappings to their backing buffers, in >particular DRM GEM objects. > > 3) Provide a common implementation to perform more complex mapping >operations on the GPU VA space. In particular splitting and merging >of GPU VA mappings, e.g. for intersecting mapping requests or partial >unmap requests. > > Suggested-by: Dave Airlie > Signed-off-by: Danilo Krummrich > --- > Documentation/gpu/drm-mm.rst| 31 + > drivers/gpu/drm/Makefile|1 + > drivers/gpu/drm/drm_gem.c |3 + > drivers/gpu/drm/drm_gpuva_mgr.c | 1687 +++ > include/drm/drm_drv.h |6 + > include/drm/drm_gem.h | 75 ++ > include/drm/drm_gpuva_mgr.h | 681 + > 7 files changed, 2484 insertions(+) > create mode 100644 drivers/gpu/drm/drm_gpuva_mgr.c > create mode 100644 include/drm/drm_gpuva_mgr.h > > diff --git a/Documentation/gpu/drm-mm.rst b/Documentation/gpu/drm-mm.rst > index a52e6f4117d6..c9f120cfe730 100644 > --- a/Documentation/gpu/drm-mm.rst > +++ b/Documentation/gpu/drm-mm.rst > @@ -466,6 +466,37 @@ DRM MM Range Allocator Function References > .. kernel-doc:: drivers/gpu/drm/drm_mm.c > :export: > > +DRM GPU VA Manager > +== > + > +Overview > + > + > +.. kernel-doc:: drivers/gpu/drm/drm_gpuva_mgr.c > + :doc: Overview > + > +Split and Merge > +--- > + > +.. kernel-doc:: drivers/gpu/drm/drm_gpuva_mgr.c > + :doc: Split and Merge > + > +Locking > +--- > + > +.. kernel-doc:: drivers/gpu/drm/drm_gpuva_mgr.c > + :doc: Locking > + > + > +DRM GPU VA Manager Function References > +-- > + > +.. kernel-doc:: include/drm/drm_gpuva_mgr.h > + :internal: > + > +.. kernel-doc:: drivers/gpu/drm/drm_gpuva_mgr.c > + :export: > + > DRM Buddy Allocator > === > > diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile > index 9c6446eb3c83..8eeed446a078 100644 > --- a/drivers/gpu/drm/Makefile > +++ b/drivers/gpu/drm/Makefile > @@ -45,6 +45,7 @@ drm-y := \ > drm_vblank.o \ > drm_vblank_work.o \ > drm_vma_manager.o \ > + drm_gpuva_mgr.o \ > drm_writeback.o > drm-$(CONFIG_DRM_LEGACY) += \ > drm_agpsupport.o \ > diff --git a/drivers/gpu/drm/drm_gem.c b/drivers/gpu/drm/drm_gem.c > index 1a5a2cd0d4ec..cd878ebddbd0 100644 > --- a/drivers/gpu/drm/drm_gem.c > +++ b/drivers/gpu/drm/drm_gem.c > @@ -164,6 +164,9 @@ void drm_gem_private_object_init(struct drm_device *dev, > if (!obj->resv) > obj->resv = >_resv; > > + if (drm_core_check_feature(dev, DRIVER_GEM_GPUVA)) > + drm_gem_gpuva_init(obj); > + > drm_vma_node_reset(>vma_node); > INIT_LIST_HEAD(>lru_node); > } > diff --git a/drivers/gpu/drm/drm_gpuva_mgr.c b/drivers/gpu/drm/drm_gpuva_mgr.c > new file mode 100644 > index ..dd8dd7fef14b > --- /dev/null > +++ b/drivers/gpu/drm/drm_gpuva_mgr.c > @@ -0,0 +1,1687 @@ > +// SPDX-License-Identifier: GPL-2.0 > +/* > + * Copyright (c) 2022 Red Hat. > + * > + * Permission is hereby granted, free of charge, to any person obtaining a > + * copy of this software and associated documentation files (the "Software"), > + * to deal in the Software without restriction, including without limitation > + * the rights to use, copy, modify, merge, publish, distribute, sublicense, > + * and/or sell copies of the Software, and to permit persons to whom the > + * Software is furnished to do so, subject to the following conditions: > + * > + * The above copyright notice and this permission notice shall be included in > + * all copies or substantial portions of the Software. > + * > + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR > + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, > + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL > + * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR > + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, > + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR > + * OTHER DEALINGS IN THE SOFTWARE. > + * > + * Authors: > + * Danilo Krummrich > + * > + */ > + > +#include > +#include > + > +/** > + * DOC: Overview > + * > + * The DRM GPU VA Manager, represented by struct drm_gpuva_manager keeps > track > + * of
Re: [Nouveau] [PATCH drm-next v4 03/14] drm: manager to keep track of GPUs VA mappings
Hi Danilo, kernel test robot noticed the following build warnings: [auto build test WARNING on 33a86170888b7e4aa0cea94ebb9c67180139cea9] url: https://github.com/intel-lab-lkp/linux/commits/Danilo-Krummrich/drm-execution-context-for-GEM-buffers-v4/20230607-063442 base: 33a86170888b7e4aa0cea94ebb9c67180139cea9 patch link:https://lore.kernel.org/r/20230606223130.6132-4-dakr%40redhat.com patch subject: [PATCH drm-next v4 03/14] drm: manager to keep track of GPUs VA mappings config: alpha-allyesconfig (https://download.01.org/0day-ci/archive/20230607/202306071203.gn8jrmlz-...@intel.com/config) compiler: alpha-linux-gcc (GCC) 12.3.0 reproduce (this is a W=1 build): mkdir -p ~/bin wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross git checkout 33a86170888b7e4aa0cea94ebb9c67180139cea9 b4 shazam https://lore.kernel.org/r/20230606223130.6132-4-d...@redhat.com # save the config file mkdir build_dir && cp config build_dir/.config COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.3.0 ~/bin/make.cross W=1 O=build_dir ARCH=alpha olddefconfig COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.3.0 ~/bin/make.cross W=1 O=build_dir ARCH=alpha SHELL=/bin/bash drivers/gpu/drm/ If you fix the issue, kindly add following tag where applicable | Reported-by: kernel test robot | Closes: https://lore.kernel.org/oe-kbuild-all/202306071203.gn8jrmlz-...@intel.com/ All warnings (new ones prefixed by >>): drivers/gpu/drm/drm_gpuva_mgr.c: In function '__drm_gpuva_sm_map': >> drivers/gpu/drm/drm_gpuva_mgr.c:1032:32: warning: variable 'prev' set but >> not used [-Wunused-but-set-variable] 1032 | struct drm_gpuva *va, *prev = NULL; |^~~~ vim +/prev +1032 drivers/gpu/drm/drm_gpuva_mgr.c 1024 1025 static int 1026 __drm_gpuva_sm_map(struct drm_gpuva_manager *mgr, 1027 const struct drm_gpuva_fn_ops *ops, void *priv, 1028 u64 req_addr, u64 req_range, 1029 struct drm_gem_object *req_obj, u64 req_offset) 1030 { 1031 DRM_GPUVA_ITER(it, mgr, req_addr); > 1032 struct drm_gpuva *va, *prev = NULL; 1033 u64 req_end = req_addr + req_range; 1034 int ret; 1035 1036 if (unlikely(!drm_gpuva_in_mm_range(mgr, req_addr, req_range))) 1037 return -EINVAL; 1038 1039 if (unlikely(drm_gpuva_in_kernel_node(mgr, req_addr, req_range))) 1040 return -EINVAL; 1041 1042 drm_gpuva_iter_for_each_range(va, it, req_end) { 1043 struct drm_gem_object *obj = va->gem.obj; 1044 u64 offset = va->gem.offset; 1045 u64 addr = va->va.addr; 1046 u64 range = va->va.range; 1047 u64 end = addr + range; 1048 bool merge = !!va->gem.obj; 1049 1050 if (addr == req_addr) { 1051 merge &= obj == req_obj && 1052 offset == req_offset; 1053 1054 if (end == req_end) { 1055 ret = op_unmap_cb(ops, , priv, va, merge); 1056 if (ret) 1057 return ret; 1058 break; 1059 } 1060 1061 if (end < req_end) { 1062 ret = op_unmap_cb(ops, , priv, va, merge); 1063 if (ret) 1064 return ret; 1065 goto next; 1066 } 1067 1068 if (end > req_end) { 1069 struct drm_gpuva_op_map n = { 1070 .va.addr = req_end, 1071 .va.range = range - req_range, 1072 .gem.obj = obj, 1073 .gem.offset = offset + req_range, 1074 }; 1075 struct drm_gpuva_op_unmap u = { 1076 .va = va, 1077 .keep = merge, 1078 }; 1079 1080 ret = op_remap_cb(ops, , priv, NULL, , ); 1081 if (ret) 1082 return ret; 1083 break; 1084 } 1085 } else if (addr < req_addr) { 1086 u64 ls_range = req_addr -
[Nouveau] [PATCH drm-next v4 03/14] drm: manager to keep track of GPUs VA mappings
Add infrastructure to keep track of GPU virtual address (VA) mappings with a decicated VA space manager implementation. New UAPIs, motivated by Vulkan sparse memory bindings graphics drivers start implementing, allow userspace applications to request multiple and arbitrary GPU VA mappings of buffer objects. The DRM GPU VA manager is intended to serve the following purposes in this context. 1) Provide infrastructure to track GPU VA allocations and mappings, making use of the maple_tree. 2) Generically connect GPU VA mappings to their backing buffers, in particular DRM GEM objects. 3) Provide a common implementation to perform more complex mapping operations on the GPU VA space. In particular splitting and merging of GPU VA mappings, e.g. for intersecting mapping requests or partial unmap requests. Suggested-by: Dave Airlie Signed-off-by: Danilo Krummrich --- Documentation/gpu/drm-mm.rst| 31 + drivers/gpu/drm/Makefile|1 + drivers/gpu/drm/drm_gem.c |3 + drivers/gpu/drm/drm_gpuva_mgr.c | 1687 +++ include/drm/drm_drv.h |6 + include/drm/drm_gem.h | 75 ++ include/drm/drm_gpuva_mgr.h | 681 + 7 files changed, 2484 insertions(+) create mode 100644 drivers/gpu/drm/drm_gpuva_mgr.c create mode 100644 include/drm/drm_gpuva_mgr.h diff --git a/Documentation/gpu/drm-mm.rst b/Documentation/gpu/drm-mm.rst index a52e6f4117d6..c9f120cfe730 100644 --- a/Documentation/gpu/drm-mm.rst +++ b/Documentation/gpu/drm-mm.rst @@ -466,6 +466,37 @@ DRM MM Range Allocator Function References .. kernel-doc:: drivers/gpu/drm/drm_mm.c :export: +DRM GPU VA Manager +== + +Overview + + +.. kernel-doc:: drivers/gpu/drm/drm_gpuva_mgr.c + :doc: Overview + +Split and Merge +--- + +.. kernel-doc:: drivers/gpu/drm/drm_gpuva_mgr.c + :doc: Split and Merge + +Locking +--- + +.. kernel-doc:: drivers/gpu/drm/drm_gpuva_mgr.c + :doc: Locking + + +DRM GPU VA Manager Function References +-- + +.. kernel-doc:: include/drm/drm_gpuva_mgr.h + :internal: + +.. kernel-doc:: drivers/gpu/drm/drm_gpuva_mgr.c + :export: + DRM Buddy Allocator === diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile index 9c6446eb3c83..8eeed446a078 100644 --- a/drivers/gpu/drm/Makefile +++ b/drivers/gpu/drm/Makefile @@ -45,6 +45,7 @@ drm-y := \ drm_vblank.o \ drm_vblank_work.o \ drm_vma_manager.o \ + drm_gpuva_mgr.o \ drm_writeback.o drm-$(CONFIG_DRM_LEGACY) += \ drm_agpsupport.o \ diff --git a/drivers/gpu/drm/drm_gem.c b/drivers/gpu/drm/drm_gem.c index 1a5a2cd0d4ec..cd878ebddbd0 100644 --- a/drivers/gpu/drm/drm_gem.c +++ b/drivers/gpu/drm/drm_gem.c @@ -164,6 +164,9 @@ void drm_gem_private_object_init(struct drm_device *dev, if (!obj->resv) obj->resv = >_resv; + if (drm_core_check_feature(dev, DRIVER_GEM_GPUVA)) + drm_gem_gpuva_init(obj); + drm_vma_node_reset(>vma_node); INIT_LIST_HEAD(>lru_node); } diff --git a/drivers/gpu/drm/drm_gpuva_mgr.c b/drivers/gpu/drm/drm_gpuva_mgr.c new file mode 100644 index ..dd8dd7fef14b --- /dev/null +++ b/drivers/gpu/drm/drm_gpuva_mgr.c @@ -0,0 +1,1687 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2022 Red Hat. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Authors: + * Danilo Krummrich + * + */ + +#include +#include + +/** + * DOC: Overview + * + * The DRM GPU VA Manager, represented by struct drm_gpuva_manager keeps track + * of a GPU's virtual address (VA) space and manages the corresponding virtual + * mappings represented by _gpuva objects. It also keeps track of the + * mapping's backing _gem_object buffers. + * + * _gem_object buffers maintain a list (and a corresponding list lock) of + * _gpuva objects representing