diff options
Diffstat (limited to 'recipes-extended/qat/files/0001-usdm_drv-convert-mutex_lock-to-mutex_trylock-to-avio.patch')
-rw-r--r-- | recipes-extended/qat/files/0001-usdm_drv-convert-mutex_lock-to-mutex_trylock-to-avio.patch | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/recipes-extended/qat/files/0001-usdm_drv-convert-mutex_lock-to-mutex_trylock-to-avio.patch b/recipes-extended/qat/files/0001-usdm_drv-convert-mutex_lock-to-mutex_trylock-to-avio.patch new file mode 100644 index 0000000..04ff59e --- /dev/null +++ b/recipes-extended/qat/files/0001-usdm_drv-convert-mutex_lock-to-mutex_trylock-to-avio.patch | |||
@@ -0,0 +1,104 @@ | |||
1 | From acf49dcacc450830bf9ccad5dcd895ce1b8ba786 Mon Sep 17 00:00:00 2001 | ||
2 | From: Liwei Song <liwei.song@windriver.com> | ||
3 | Date: Thu, 22 Jul 2021 08:09:05 +0000 | ||
4 | Subject: [PATCH] usdm_drv: convert mutex_lock to mutex_trylock to aviod | ||
5 | deadlock | ||
6 | |||
7 | exist the following deadlock when run cpa_sample_code: | ||
8 | |||
9 | ====================================================== | ||
10 | WARNING: possible circular locking dependency detected | ||
11 | 5.10.47-yocto-standard #1 Tainted: G O | ||
12 | ------------------------------------------------------ | ||
13 | |||
14 | cpa_sample_code/2144 is trying to acquire lock: | ||
15 | ffffffffc04883d0 (&dev_mem_lock | ||
16 | ============================= | ||
17 | ){+.+.}-{3:3}, at: mem_mmap+0x32/0x160 [usdm_drv] | ||
18 | |||
19 | but task is already holding lock: | ||
20 | ff1ab034bf111278 (&mm->mmap_lock#2){++++}-{3:3}, at: vm_mmap_pgoff+0x99/0x100 | ||
21 | |||
22 | which lock already depends on the new lock. | ||
23 | |||
24 | the existing dependency chain (in reverse order) is: | ||
25 | |||
26 | -> #1 (&mm->mmap_lock#2){++++}-{3:3}: | ||
27 | __lock_acquire+0x4be/0x980 | ||
28 | lock_acquire+0xe1/0x2f0 | ||
29 | WARNING: suspicious RCU usage | ||
30 | __might_fault+0x5e/0x80 | ||
31 | _copy_to_user+0x23/0xa0 | ||
32 | mem_ioctl+0x2ed/0x3b5 [usdm_drv] | ||
33 | __x64_sys_ioctl+0x91/0xc0 | ||
34 | do_syscall_64+0x38/0x50 | ||
35 | entry_SYSCALL_64_after_hwframe+0x44/0xa9 | ||
36 | 5.10.47-yocto-standard #1 Tainted: G O | ||
37 | |||
38 | -> #0 (&dev_mem_lock){+.+.}-{3:3}: | ||
39 | check_prev_add+0x95/0xc00 | ||
40 | validate_chain+0x723/0xaa0 | ||
41 | __lock_acquire+0x4be/0x980 | ||
42 | lock_acquire+0xe1/0x2f0 | ||
43 | __mutex_lock+0x97/0x960 | ||
44 | mutex_lock_nested+0x1b/0x20 | ||
45 | mem_mmap+0x32/0x160 [usdm_drv] | ||
46 | ----------------------------- | ||
47 | mmap_region+0x423/0x6b0 | ||
48 | do_mmap+0x46a/0x5e0 | ||
49 | vm_mmap_pgoff+0xc5/0x100 | ||
50 | ksys_mmap_pgoff+0x1d0/0x230 | ||
51 | __x64_sys_mmap+0x33/0x40 | ||
52 | do_syscall_64+0x38/0x50 | ||
53 | entry_SYSCALL_64_after_hwframe+0x44/0xa9 | ||
54 | kernel/sched/core.c:7263 Illegal context switch in RCU-bh read-side critical section! | ||
55 | |||
56 | other info that might help us debug this: | ||
57 | |||
58 | Possible unsafe locking scenario: | ||
59 | |||
60 | CPU0 CPU1 | ||
61 | ---- ---- | ||
62 | lock(&mm->mmap_lock#2); | ||
63 | lock(&dev_mem_lock); | ||
64 | lock(&mm->mmap_lock#2); | ||
65 | lock(&dev_mem_lock); | ||
66 | |||
67 | *** DEADLOCK *** | ||
68 | |||
69 | convert mutex_lock to mutex_trylock which will return without wait. | ||
70 | |||
71 | Upstream-Status: Inappropriate | ||
72 | |||
73 | Signed-off-by: Liwei Song <liwei.song@windriver.com> | ||
74 | --- | ||
75 | .../utilities/libusdm_drv/linux/kernel_space/qae_mem_drv.c | 6 +++++- | ||
76 | 1 file changed, 5 insertions(+), 1 deletion(-) | ||
77 | |||
78 | diff --git a/quickassist/utilities/libusdm_drv/linux/kernel_space/qae_mem_drv.c b/quickassist/utilities/libusdm_drv/linux/kernel_space/qae_mem_drv.c | ||
79 | index e404647aafb2..2a4de14a0300 100644 | ||
80 | --- a/quickassist/utilities/libusdm_drv/linux/kernel_space/qae_mem_drv.c | ||
81 | +++ b/quickassist/utilities/libusdm_drv/linux/kernel_space/qae_mem_drv.c | ||
82 | @@ -87,6 +87,7 @@ | ||
83 | #include <linux/uaccess.h> | ||
84 | #include <linux/version.h> | ||
85 | #include <linux/hugetlb.h> | ||
86 | +#include <linux/delay.h> | ||
87 | |||
88 | #include "qae_mem_utils.h" | ||
89 | |||
90 | @@ -975,7 +976,10 @@ mem_mmap(struct file *fp, struct vm_area_struct *vma) | ||
91 | unsigned long size = vma->vm_end - vma->vm_start; | ||
92 | id = vma->vm_pgoff << PAGE_SHIFT; | ||
93 | |||
94 | - mutex_lock(&dev_mem_lock); | ||
95 | + while(!mutex_trylock(&dev_mem_lock)){ | ||
96 | + udelay(5); | ||
97 | + } | ||
98 | + | ||
99 | kmem = userMemGetInfo(fp, id); | ||
100 | if (!kmem) | ||
101 | { | ||
102 | -- | ||
103 | 2.29.2 | ||
104 | |||