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