drm/amdkfd: Check cgroup when returning DMABuf info
Subsystems (3)
PATCH 1/1 drm/amdkfd: Check cgroup when returning DMABuf info
Check cgroup permissions when returning DMA-buf info and based on cgroup check return the id of the GPU that has access to the BO.
--- drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +2 -2
@@ -1523,7 +1523,7 @@ static int kfd_ioctl_get_dmabuf_info(struct file *filep,/* Find a KFD GPU device that supports the get_dmabuf_info query */ for (i =0 ;kfd_topology_enum_kfd_devices (i, &dev) ==0 ; i++) -if (dev) +if (dev && !kfd_devcgroup_check_permission (dev))break ;if (!dev)return -EINVAL ;
@@ -1545,7 +1545,7 @@ static int kfd_ioctl_get_dmabuf_info(struct file *filep,if (xcp_id >=0 ) args->gpu_id = dmabuf_adev->kfd.dev->nodes[xcp_id]->id;else - args->gpu_id = dmabuf_adev->kfd.dev->nodes[0 ]->id; + args->gpu_id = dev->id; args->flags = flags;/* Copy metadata buffer to user mode */
Signature · 1 line
2.35.1
Felix Kuehling
maintainerQuoted 23 lines · Mukul Joshi
Check cgroup permissions when returning DMA-buf info and based on cgroup check return the id of the GPU that has access to the BO.
Signed-off-by Mukul Joshi <[email protected]>--- drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +1
-1@@ -1523,7 +1523,7 @@ static int kfd_ioctl_get_dmabuf_info(struct file *filep,/* Find a KFD GPU device that supports the get_dmabuf_info query */ for (i =0 ;kfd_topology_enum_kfd_devices (i, &dev) ==0 ; i++) -if (dev) +if (dev && !kfd_devcgroup_check_permission (dev))break ;if (!dev)return -EINVAL ;
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c static int kfd_ioctl_get_dmabuf_info(struct file *filep, · line 1548
Quoted 5 lines
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +1
-1@@ -1545,7 +1545,7 @@ static int kfd_ioctl_get_dmabuf_info(struct file *filep,if (xcp_id >=0 ) args->gpu_id = dmabuf_adev->kfd.dev->nodes[xcp_id]->id;else - args->gpu_id = dmabuf_adev->kfd.dev->nodes[0 ]->id; + args->gpu_id = dev->id;
If I remember correctly, this was meant as a fallback in case for GTT BOs where the exporting partition wasn't known and the application didn't have access to the first partition. I think the way you wrote this, it could also change the behaviour (report the wrong GPU ID) on single-partition GPUs, which is probably not intended. Maybe this would preserve the behaviour for that case:
...
- else
+ else if (!kfd_devcgroup_check_permission(dmabuf_adev->kfd.dev->nodes[0]))
args->gpu_id = dmabuf_adev->kfd.dev->nodes[0]->id;
+ else
+ args->gpu_id = dev->id;
Or maybe a more general solution would make DMABuf import work when the exporter is really unknown or not even a GPU. This came up not so long ago in the context of interop with 3rd-party devices. This may require user mode changes as well.
Regards,
Felix
Quoted 3 lines
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +0
-0args->flags = flags;/* Copy metadata buffer to user mode */
[AMD Official Use Only - General]
Quoted 39 lines
-----Original Message-----
From: Kuehling, Felix <[email protected]>
Sent: Monday, March 18, 2024 4:13 PM
To: Joshi, Mukul <[email protected]>; [email protected]
Subject: Re: [PATCH] drm/amdkfd: Check cgroup when returning DMABuf infodrivers/gpu/drm/amd/amdkfd/kfd_chardev.c static int kfd_ioctl_get_dmabuf_info(struct file
Quoted 24 lines · Mukul Joshi
Check cgroup permissions when returning DMA-buf info and based on cgroup check return the id of the GPU that has access to the BO.
Signed-off-by Mukul Joshi <[email protected]>--- drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +1
-1@@ -1523,7 +1523,7 @@ static int kfd_ioctl_get_dmabuf_info(struct file *filep,/* Find a KFD GPU device that supports the get_dmabuf_info query */ for (i = 0; kfd_topology_enum_kfd_devices(i, &dev) == 0; i++) -if (dev) +if (dev && !kfd_devcgroup_check_permission (dev))break ;if (!dev)return -EINVAL;drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +0
-0@@ -1545,7 +1545,7 @@ static int kfd_ioctl_get_dmabuf_info(struct file*filep,
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c static int kfd_ioctl_get_dmabuf_info(struct file *filep, · line 1548
Quoted 5 lines
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +1
-1if (xcp_id >=0 ) args->gpu_id = dmabuf_adev->kfd.dev->nodes[xcp_id]->id;else - args->gpu_id = dmabuf_adev->kfd.dev->nodes[0 ]->id; + args->gpu_id = dev->id;
Quoted 7 lines
If I remember correctly, this was meant as a fallback in case for GTT BOs where the exporting partition wasn't known and the application didn't have access to the first partition. I think the way you wrote this, it could also change the behaviour (report the wrong GPU ID) on single-partition GPUs, which is probably not intended. Maybe this would preserve the behaviour for that case:
Can you please explain why this could be a issue on a single partition GPU?
Regards,
Mukul
Quoted 21 lines
...(quoted diff) +1
-1- else + else if (!kfd_devcgroup_check_permission(dmabuf_adev->kfd.dev-drivers/gpu/drm/amd/amdkfd/kfd_chardev.c static int kfd_ioctl_get_dmabuf_info(struct file · line 1549
Quoted 1 line
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +0
-0nodes[0]))args->gpu_id = dmabuf_adev->kfd.dev->nodes[0]->id;(quoted diff) +2
-0+ else + args->gpu_id = dev->id;Or maybe a more general solution would make DMABuf import work when the
exporter is really unknown or not even a GPU. This came up not so long ago in the context of interop with 3rd-party devices. This may require user mode changes as well.Regards,
FelixQuoted 3 lines
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +0
-0args->flags = flags;/* Copy metadata buffer to user mode */
Felix Kuehling
maintainerQuoted 40 lines · Mukul
[AMD Official Use Only - General]
Quoted 38 lines
-----Original Message-----
From: Kuehling, Felix <[email protected]>
Sent: Monday, March 18, 2024 4:13 PM
To: Joshi, Mukul <[email protected]>; [email protected]
Subject: Re: [PATCH] drm/amdkfd: Check cgroup when returning DMABuf infodrivers/gpu/drm/amd/amdkfd/kfd_chardev.c static int kfd_ioctl_get_dmabuf_info(struct file
Quoted 24 lines · Mukul Joshi
Check cgroup permissions when returning DMA-buf info and based on cgroup check return the id of the GPU that has access to the BO.
Signed-off-by Mukul Joshi <[email protected]>--- drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +1
-1@@ -1523,7 +1523,7 @@ static int kfd_ioctl_get_dmabuf_info(struct file *filep,/* Find a KFD GPU device that supports the get_dmabuf_info query */ for (i = 0; kfd_topology_enum_kfd_devices(i, &dev) == 0; i++) -if (dev) +if (dev && !kfd_devcgroup_check_permission (dev))break ;if (!dev)return -EINVAL;drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +0
-0@@ -1545,7 +1545,7 @@ static int kfd_ioctl_get_dmabuf_info(struct file*filep,
Quoted 5 lines
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +1
-1if (xcp_id >=0 ) args->gpu_id = dmabuf_adev->kfd.dev->nodes[xcp_id]->id;else - args->gpu_id = dmabuf_adev->kfd.dev->nodes[0 ]->id; + args->gpu_id = dev->id;
Quoted 8 lines
Quoted 7 lines
If I remember correctly, this was meant as a fallback in case for GTT BOs where the exporting partition wasn't known and the application didn't have access to the first partition. I think the way you wrote this, it could also change the behaviour (report the wrong GPU ID) on single-partition GPUs, which is probably not intended. Maybe this would preserve the behaviour for that case:
Can you please explain why this could be a issue on a single partition GPU?
What would xcp_id be on a single-partition GPU? If it's < 0, then your patch changes the behaviour. Instead or returning the GPU ID from the GPU where the memory was allocated, it returns some arbitrary GPU that the application has access to.
Regards,
Felix
Quoted 25 lines
Regards,
MukulQuoted 21 lines
...(quoted diff) +1
-1- else + else if (!kfd_devcgroup_check_permission(dmabuf_adev->kfd.dev-drivers/gpu/drm/amd/amdkfd/kfd_chardev.c static int kfd_ioctl_get_dmabuf_info(struct file · line 1549
Quoted 1 line
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +0
-0nodes[0]))args->gpu_id = dmabuf_adev->kfd.dev->nodes[0]->id;(quoted diff) +2
-0+ else + args->gpu_id = dev->id;Or maybe a more general solution would make DMABuf import work when the
exporter is really unknown or not even a GPU. This came up not so long ago in the context of interop with 3rd-party devices. This may require user mode changes as well.Regards,
FelixQuoted 3 lines
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +0
-0args->flags = flags;/* Copy metadata buffer to user mode */
Quoted 25 lines · Felix Kuehling
Quoted 23 lines · Mukul Joshi
Check cgroup permissions when returning DMA-buf info and based on cgroup check return the id of the GPU that has access to the BO.
Signed-off-by Mukul Joshi <[email protected]>---
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c| 4 ++--1 file changed, 2 insertions(+), 2 deletions(-)drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +1
-1@@ -1523,7 +1523,7 @@ static int kfd_ioctl_get_dmabuf_info(structfile *filep, /* Find a KFD GPU device that supports the get_dmabuf_info query */ for (i = 0; kfd_topology_enum_kfd_devices(i, &dev) == 0; i++) - if (dev) + if (dev && !kfd_devcgroup_check_permission(dev)) break; if (!dev) return -EINVAL;@@ -1545,7 +1545,7 @@ static int kfd_ioctl_get_dmabuf_info(struct
Quoted 8 lines
Quoted 6 lines
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +0
-0file *filep, if (xcp_id >= 0) args->gpu_id = dmabuf_adev->kfd.dev->nodes[xcp_id]->id;else
-args->gpu_id= dmabuf_adev->kfd.dev->nodes[0]->id; +args->gpu_id=dev->id;If I remember correctly, this was meant as a fallback in case for GTT BOs where the exporting partition wasn't known and the application didn't have access to the first partition. I think the way you wrote this, it could also change the behaviour (report the wrong GPU ID) on single-partition GPUs, which is probably not intended.
Never mind. I double checked: On single-partition GPUs, bo->xcp_id always seems to be 0. So your code won't change the behaviour here. The patch is
Quoted 18 lines
Maybe this would preserve the behaviour for that case:
...
- else
+ else if (!kfd_devcgroup_check_permission(dmabuf_adev->kfd.dev->nodes[0]))args->gpu_id= dmabuf_adev->kfd.dev->nodes[0]->id; + else
+args->gpu_id=dev->id;Or maybe a more general solution would make DMABuf import work when the exporter is really unknown or not even a GPU. This came up not so long ago in the context of interop with 3rd-party devices. This may require user mode changes as well.
Regards,
FelixQuoted 2 lines
args->flags= flags;
/* Copy metadata buffer to user mode */
Quoted 35 lines · Felix Kuehling
Quoted 25 lines · Felix Kuehling
Quoted 23 lines · Mukul Joshi
Check cgroup permissions when returning DMA-buf info and based on cgroup check return the id of the GPU that has access to the BO.
Signed-off-by Mukul Joshi <[email protected]>---
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c| 4 ++--1 file changed, 2 insertions(+), 2 deletions(-)drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +1
-1@@ -1523,7 +1523,7 @@ static int kfd_ioctl_get_dmabuf_info(structfile *filep, /* Find a KFD GPU device that supports the get_dmabuf_info query */ for (i = 0; kfd_topology_enum_kfd_devices(i, &dev) == 0; i++) - if (dev) + if (dev && !kfd_devcgroup_check_permission(dev)) break; if (!dev) return -EINVAL;@@ -1545,7 +1545,7 @@ static int kfd_ioctl_get_dmabuf_info(structQuoted 8 lines
Quoted 6 lines
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +0
-0file *filep, if (xcp_id >= 0) args->gpu_id = dmabuf_adev->kfd.dev->nodes[xcp_id]->id;else
-args->gpu_id= dmabuf_adev->kfd.dev->nodes[0]->id; +args->gpu_id=dev->id;If I remember correctly, this was meant as a fallback in case for GTT BOs where the exporting partition wasn't known and the application didn't have access to the first partition. I think the way you wrote this, it could also change the behaviour (report the wrong GPU ID) on single-partition GPUs, which is probably not intended.
Quoted 1 line
Never mind. I double checked: On single-partition GPUs,
bo->xcp_idalways seems to be 0. So your code won't change the behaviour here. The patch is
should bo->xcp_id be >= 0 for all cases? if yes then I think all tests can be moved. (like below) args->gpu_id = dmabuf_adev->kfd.dev->nodes[xcp_id]->id;
David
Quoted 23 lines
Reviewed-by Felix Kuehling <[email protected]>Quoted 18 lines
Maybe this would preserve the behaviour for that case:
...
- else
+ else if (!kfd_devcgroup_check_permission(dmabuf_adev->kfd.dev->nodes[0]))args->gpu_id= dmabuf_adev->kfd.dev->nodes[0]->id; + else
+args->gpu_id=dev->id;Or maybe a more general solution would make DMABuf import work when the exporter is really unknown or not even a GPU. This came up not so long ago in the context of interop with 3rd-party devices. This may require user mode changes as well.
Regards,
FelixQuoted 2 lines
args->flags= flags;
/* Copy metadata buffer to user mode */
[AMD Official Use Only - General]
Quoted 52 lines
-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Wu, David
Sent: Wednesday, March 20, 2024 8:02 PM
To: [email protected]
Subject: Re: [PATCH] drm/amdkfd: Check cgroup when returning DMABuf infoCaution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.
Quoted 40 lines · Felix Kuehling
Quoted 38 lines · Felix Kuehling
Quoted 24 lines · Mukul Joshi
Check cgroup permissions when returning DMA-buf info and based on cgroup check return the id of the GPU that has access to the BO.
Signed-off-by Mukul Joshi <[email protected]>--- drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +0
-0@@ -1523,7 +1523,7 @@ static int kfd_ioctl_get_dmabuf_info(struct file *filep,/* Find a KFD GPU device that supports the get_dmabuf_info query */
for (i = 0; kfd_topology_enum_kfd_devices(i, &dev) == 0; i++)drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +1
-1-if (dev) +if (dev && !kfd_devcgroup_check_permission (dev))break ;if (!dev)return -EINVAL ;drivers/gpu/drm/amd/amdkfd/kfd_chardev.c static int kfd_ioctl_get_dmabuf_info(struct · line 1549
Quoted 6 lines
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +1
-1@@ -1545,7 +1545,7 @@ static int kfd_ioctl_get_dmabuf_info(struct file *filep, if (xcp_id >= 0) args->gpu_id = dmabuf_adev->kfd.dev->nodes[xcp_id]->id; else - args->gpu_id = dmabuf_adev->kfd.dev->nodes[0]->id; + args->gpu_id = dev->id;If I remember correctly, this was meant as a fallback in case for GTT BOs where the exporting partition wasn't known and the application didn't have access to the first partition. I think the way you wrote this, it could also change the behaviour (report the wrong GPU ID) on single-partition GPUs, which is probably not intended.
Quoted 7 lines
Quoted 3 lines
Never mind. I double checked: On single-partition GPUs,
bo->xcp_idalways seems to be 0. So your code won't change the behaviour here. The patch isshould
bo->xcp_idbe >= 0 for all cases? if yes then I think all tests can be moved. (like below)args->gpu_id= dmabuf_adev->kfd.dev->nodes[xcp_id]->id;
No it can be -1 on GPUs that support spatial partitioning, especially for GTT BOs.
Regards,
Mukul
Quoted 27 lines
David
Quoted 26 lines
Reviewed-by Felix Kuehling <[email protected]>Quoted 21 lines
Maybe this would preserve the behaviour for that case:
...(quoted diff) +1
-1- else + else if(!kfd_devcgroup_check_permission(dmabuf_adev->kfd.dev->nodes[0]))
args->gpu_id = dmabuf_adev->kfd.dev->nodes[0]->id;(quoted diff) +2
-0+ else + args->gpu_id = dev->id;Or maybe a more general solution would make DMABuf import work when the exporter is really unknown or not even a GPU. This came up not so long ago in the context of interop with 3rd-party devices. This may require user mode changes as well.
Regards,
FelixQuoted 2 lines
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +0
-0args->flags = flags;/* Copy metadata buffer to user mode */