48 lines
1.5 KiB
Diff
48 lines
1.5 KiB
Diff
From 29ee35cd6e2fd592730ce4374acce84f9c4b5c3f Mon Sep 17 00:00:00 2001
|
|
From: Yang Shen <shenyang39@huawei.com>
|
|
Date: Mon, 20 Nov 2023 15:21:58 +0800
|
|
Subject: [PATCH 82/85] uadk: wd_util - fix a theoretically infinite loop
|
|
|
|
In wd_init_ctx_set, it will try to get the ctx from the most
|
|
idle device. But requesting ctx from devices is an exclusive
|
|
behavior. And there is no lock to protect against multi-process
|
|
contention. In the worst situation, a process will always get
|
|
'EBUSY' from wd_request_ctx.
|
|
|
|
So here add a retry count to avoid a infinite loop.
|
|
|
|
Signed-off-by: Yang Shen <shenyang39@huawei.com>
|
|
---
|
|
wd_util.c | 8 +++++++-
|
|
1 file changed, 7 insertions(+), 1 deletion(-)
|
|
|
|
diff --git a/wd_util.c b/wd_util.c
|
|
index 8af0261..bfa3af0 100644
|
|
--- a/wd_util.c
|
|
+++ b/wd_util.c
|
|
@@ -2420,7 +2420,7 @@ static int wd_init_ctx_set(struct wd_init_attrs *attrs, struct uacce_dev_list *l
|
|
struct wd_ctx_config *ctx_config = attrs->ctx_config;
|
|
__u32 count = idx + ctx_set_num;
|
|
struct uacce_dev *dev;
|
|
- __u32 i;
|
|
+ __u32 i, cnt = 0;
|
|
|
|
/* If the ctx set number is 0, the initialization is skipped. */
|
|
if (!ctx_set_num)
|
|
@@ -2437,6 +2437,12 @@ static int wd_init_ctx_set(struct wd_init_attrs *attrs, struct uacce_dev_list *l
|
|
if (WD_IS_ERR(dev))
|
|
return WD_PTR_ERR(dev);
|
|
|
|
+ if (cnt++ > WD_INIT_RETRY_TIMES) {
|
|
+ WD_ERR("failed to request enough ctx due to timeout!\n");
|
|
+ return -WD_ETIMEDOUT;
|
|
+ }
|
|
+
|
|
+ /* self-decrease i to eliminate self-increase on next loop */
|
|
i--;
|
|
continue;
|
|
} else if (!ctx_config->ctxs[i].ctx) {
|
|
--
|
|
2.25.1
|
|
|