Open himanshujha199640 opened 5 years ago
Ah, maybe the analysis fails to understand that:
dentry->d_inode->i_lock == inode->i_lock
Context:
struct inode *inode = dentry->d_inode;
....
spin_unlock(&inode->i_lock);
Looks like a aliasing limitation: https://clang.llvm.org/docs/ThreadSafetyAnalysis.html#no-alias-analysis
himanshu@himanshu-Vostro-3559:~/gtbit/gsoc19/thread-safety-demo$ cat -n aliasing.c; clang -c -Wthread-safety aliasing.c
1 struct Mutex {
2 int mutex;
3 } __attribute__((capability("mutex")));
4
5
6 void acquire(struct Mutex *lock) __attribute__((acquire_capability(lock)));
7 void release(struct Mutex *lock) __attribute__((release_capability(lock)));
8
9 struct priv {
10 struct Mutex lock;
11 };
12
13 struct a {
14 struct priv *p;
15 };
16
17 struct b {
18 struct a *bar;
19 };
20
21 void test (struct b *foo) __attribute__((release_capability(&foo->bar->p->lock))) {
22 struct a *check = foo->bar;
23
24 release(&check->p->lock);
25 }
aliasing.c:24:2: warning: releasing mutex 'check->p->lock' that was not held [-Wthread-safety-analysis]
release(&check->p->lock);
^
aliasing.c:25:1: warning: mutex 'foo->bar->p->lock' is still held at the end of function [-Wthread-safety-analysis]
}
^
aliasing.c:21:42: note: mutex acquired here
void test (struct b *foo) __attribute__((release_capability(&foo->bar->p->lock))) {
^
2 warnings generated.
https://elixir.bootlin.com/linux/v5.2-rc2/source/fs/dcache.c#L368 I was going to mark it as
__no_thread_safety_analysis
for the following warning:But instead decided to try:
And it doesn't seem to work which appears to be a simple fix. I get weird warning: