drm/amdkfd: Prevent user space using both svm and kfd api to register same user buffer
Subsystems (3)
PATCH v2 1/1 drm/amdkfd: Prevent user space using both svm and kfd api to register same user buffer
From: Xiaogang Chen <[email protected]>
When xnack is on user space can use svm page restore to set a vm range without setup it first, then use regular api to register. Currently kfd api and svm are not interoperable. We already have check on that, but for user buffer the mapping address is not same as buffer cpu virtual address. Add checking on that to avoid error propagate to hmm.
--- drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +15 -0
@@ -1065,6 +1065,21 @@ static int kfd_ioctl_alloc_memory_of_gpu(struct file *filep,mutex_unlock (&p->svms.lock); return -EADDRINUSE; } + +/* When register user buffer check if it has been registered by svm by +* buffer cpu virtual address. +*/ +if ((flags &KFD_IOC_ALLOC_MEM_FLAGS_USERPTR ) && +interval_tree_iter_first (&p->svms.objects, + args->mmap_offset >>PAGE_SHIFT , + (args->mmap_offset + args->size -1 ) >>PAGE_SHIFT )) { + +pr_err ("User Buffer Address: 0x%llx already allocated by SVM\n" , + args->mmap_offset); +mutex_unlock (&p->svms.lock); +return -EADDRINUSE ; + } +mutex_unlock (&p->svms.lock);#endif mutex_lock (&p->mutex);
Signature · 1 line
2.25.1
Felix Kuehling
maintainerAm 2023-02-08 um 14:57 schrieb Xiaogang.Chen:
Quoted 17 lines
From: Xiaogang Chen <[email protected]>
When xnack is on user space can use svm page restore to set a vm range without setup it first, then use regular api to register. Currently kfd api and svm are not interoperable. We already have check on that, but for user buffer the mapping address is not same as buffer cpu virtual address. Add checking on that to avoid error propagate to hmm.
--- drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +0
-0@@ -1065,6 +1065,21 @@ static int kfd_ioctl_alloc_memory_of_gpu(struct file *filep,mutex_unlock (&p->svms.lock);
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c static int kfd_ioctl_alloc_memory_of_gpu(struct file *filep, · line 1075
Quoted 10 lines
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +8
-0return -EADDRINUSE ; } + +/* When register user buffer check if it has been registered by svm by +* buffer cpu virtual address. +*/ +if ((flags &KFD_IOC_ALLOC_MEM_FLAGS_USERPTR ) && +interval_tree_iter_first (&p->svms.objects, + args->mmap_offset >>PAGE_SHIFT , + (args->mmap_offset + args->size -1 ) >>PAGE_SHIFT )) {
The indentation would be more readable if it was properly aligned with the opening (, both for the if statement and the interval_tree_iter_first call. Our coding style is not completely consistent in this, but the existing call of interval_tree_iter_first in this function uses that style for reference.
Regards,
Felix
Quoted 10 lines
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +7
-0+ +pr_err ("User Buffer Address: 0x%llx already allocated by SVM\n" , + args->mmap_offset); +mutex_unlock (&p->svms.lock); + return -EADDRINUSE; + } +mutex_unlock (&p->svms.lock);#endif mutex_lock (&p->mutex);