gpudev: fix deadlocks when registering callback

Message ID 20230103104900.616477-1-david.marchand@redhat.com (mailing list archive)
State Accepted, archived
Delegated to: David Marchand
Headers
Series gpudev: fix deadlocks when registering callback |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/loongarch-compilation success Compilation OK
ci/loongarch-unit-testing success Unit Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/github-robot: build success github build: passed
ci/iol-abi-testing success Testing PASS
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/iol-x86_64-compile-testing success Testing PASS
ci/iol-aarch64-compile-testing success Testing PASS
ci/iol-aarch64-unit-testing success Testing PASS
ci/iol-testing success Testing PASS
ci/iol-x86_64-unit-testing success Testing PASS

Commit Message

David Marchand Jan. 3, 2023, 10:49 a.m. UTC
  gpu_callback_lock was not released in some branches of the register
helper.
While at it, set rte_errno in one branch.

Fixes: 18cb07563165 ("gpudev: add event notification")
Cc: stable@dpdk.org

Signed-off-by: David Marchand <david.marchand@redhat.com>
---
 lib/gpudev/gpudev.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
  

Comments

Elena Agostini Jan. 29, 2023, 3:36 p.m. UTC | #1
Agree with the patch.
Thanks!
  
David Marchand Jan. 31, 2023, 10:14 a.m. UTC | #2
On Tue, Jan 3, 2023 at 11:49 AM David Marchand
<david.marchand@redhat.com> wrote:
>
> gpu_callback_lock was not released in some branches of the register
> helper.
> While at it, set rte_errno in one branch.
>
> Fixes: 18cb07563165 ("gpudev: add event notification")
> Cc: stable@dpdk.org
>
> Signed-off-by: David Marchand <david.marchand@redhat.com>
Acked-by: Elena Agostini <eagostini@nvidia.com>

Applied, thanks.
  

Patch

diff --git a/lib/gpudev/gpudev.c b/lib/gpudev/gpudev.c
index 805719d00c..8f12abef23 100644
--- a/lib/gpudev/gpudev.c
+++ b/lib/gpudev/gpudev.c
@@ -408,6 +408,7 @@  rte_gpu_callback_register(int16_t dev_id, enum rte_gpu_event event,
 					callback->function == function &&
 					callback->user_data == user_data) {
 				GPU_LOG(INFO, "callback already registered");
+				rte_rwlock_write_unlock(&gpu_callback_lock);
 				return 0;
 			}
 		}
@@ -415,7 +416,9 @@  rte_gpu_callback_register(int16_t dev_id, enum rte_gpu_event event,
 		callback = malloc(sizeof(*callback));
 		if (callback == NULL) {
 			GPU_LOG(ERR, "cannot allocate callback");
-			return -ENOMEM;
+			rte_rwlock_write_unlock(&gpu_callback_lock);
+			rte_errno = ENOMEM;
+			return -rte_errno;
 		}
 		callback->function = function;
 		callback->user_data = user_data;