--- amdgpu-19.20-812932.bak/amd/amdgpu/amdgpu_mn.c 2019-05-10 19:57:47.000000000 +0200 +++ amdgpu-19.20-812932.new/amd/amdgpu/amdgpu_mn.c 2019-07-17 08:48:23.966428076 +0200 @@ -257,7 +257,7 @@ } } -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 19, 0) +#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 0, 0) /** * amdgpu_mn_invalidate_range_start_gfx - callback to notify about mm change * @@ -365,10 +365,18 @@ * Block for operations on BOs to finish and mark pages as accessed and * potentially dirty. */ +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 19, 0) +static int amdgpu_mn_invalidate_range_start_gfx(struct mmu_notifier *mn, + struct mm_struct *mm, + unsigned long start, + unsigned long end, + bool blockable) +#else static void amdgpu_mn_invalidate_range_start_gfx(struct mmu_notifier *mn, struct mm_struct *mm, unsigned long start, unsigned long end) +#endif { struct amdgpu_mn *amn = container_of(mn, struct amdgpu_mn, mn); struct interval_tree_node *it; @@ -376,17 +384,35 @@ /* notification is exclusive, but interval is inclusive */ end -= 1; +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 19, 0) + /* TODO we should be able to split locking for interval tree and + * amdgpu_mn_invalidate_node + */ + if (amdgpu_mn_read_lock(amn, blockable)) + return -EAGAIN; +#else amdgpu_mn_read_lock(amn); +#endif it = interval_tree_iter_first(&amn->objects, start, end); while (it) { struct amdgpu_mn_node *node; +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 19, 0) + if (!blockable) { + amdgpu_mn_read_unlock(amn); + return -EAGAIN; + } + +#endif node = container_of(it, struct amdgpu_mn_node, it); it = interval_tree_iter_next(it, start, end); amdgpu_mn_invalidate_node(node, start, end); } +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 19, 0) + return 0; +#endif } @@ -402,10 +428,19 @@ * necessitates evicting all user-mode queues of the process. The BOs * are restorted in amdgpu_mn_invalidate_range_end_hsa. */ +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 19, 0) +static int amdgpu_mn_invalidate_range_start_hsa(struct mmu_notifier *mn, + struct mm_struct *mm, + unsigned long start, + unsigned long end, + bool blockable) +#else static void amdgpu_mn_invalidate_range_start_hsa(struct mmu_notifier *mn, struct mm_struct *mm, unsigned long start, unsigned long end) +#endif + { struct amdgpu_mn *amn = container_of(mn, struct amdgpu_mn, mn); struct interval_tree_node *it; @@ -413,13 +448,26 @@ /* notification is exclusive, but interval is inclusive */ end -= 1; +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 19, 0) + if (amdgpu_mn_read_lock(amn, blockable)) + return -EAGAIN; +#else amdgpu_mn_read_lock(amn); +#endif + it = interval_tree_iter_first(&amn->objects, start, end); while (it) { struct amdgpu_mn_node *node; struct amdgpu_bo *bo; +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 19, 0) + if (!blockable) { + amdgpu_mn_read_unlock(amn); + return -EAGAIN; + } + +#endif node = container_of(it, struct amdgpu_mn_node, it); it = interval_tree_iter_next(it, start, end); @@ -431,6 +479,9 @@ amdgpu_amdkfd_evict_userptr(mem, mm); } } +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 19, 0) + return 0; +#endif } #endif diff -Naur amdgpu-19.20-812932.bak/Makefile amdgpu-19.20-812932/Makefile --- amdgpu-19.20-812932.bak/Makefile 2019-05-10 19:57:47.000000000 +0200 +++ amdgpu-19.20-812932/Makefile 2019-07-11 07:51:58.646571741 +0200 @@ -33,6 +33,9 @@ DRM_VER=$(shell sed -n 's/^VERSION = \(.*\)/\1/p' $(kdir)/Makefile) DRM_PATCH=$(shell sed -n 's/^PATCHLEVEL = \(.*\)/\1/p' $(kdir)/Makefile) endif +else +DRM_VER=$(shell make kernelversion | sed -n 's/\(.*\)\.\(.*\)\.\(.*\)/\1/p') +DRM_PATCH=$(shell make kernelversion | sed -n 's/\(.*\)\.\(.*\)\.\(.*\)/\2/p') endif subdir-ccflags-y += \