Hello,
On Wed, Dec 22, 2021 at 3:33 AM Ryan Cai <[email protected]> wrote:
>
> Hi, I found a potential lock problem in dso_data_get_fd. Because the inconsistent branch conditions of pthread_mutex_lock(&dso__data_open_lock) and pthread_mutex_unlock(&dso__data_open_lock), it is possible that the lock dso__data_open_lock is not released in the dso_data_get_fd. Also, I have a question on why the branch condition of pthread_mutex_lock(&dso__data_open_lock) is <0. I think that the branch condition should be !=0, because pthread_mutex_lock would return 0 when succeeding. Looking forward to further discussion. One this bug is confirmed, I can send a patch.
Please fix your mail client to wrap around 80 characters.
1. dso__data_get_fd() should be paired with dso__data_put_fd()
when it returns non-negative. It'd unlock the mutex.
2. I've checked the man page and it seems you're right.
It just says that it'd return an error number or zero.
https://linux.die.net/man/3/pthread_mutex_lock
Thanks,
Namhyung
>
>
>
> https://github.com/torvalds/linux/blob/e851dfae4371d3c751f1e18e8eb5eba993de1467/tools/perf/util/dso.c#L708-L722
>
>
>
> Best,
>
> Ryan
>
>
>
>
Hi, Namhyung,
1. Indeed, I got wrong here.
2. Yes, the branch should be if (pthread_mutex_lock(&dso__data_open_lock))
instead of if (pthread_mutex_lock(&dso__data_open_lock) < 0).
Could I send a patch?
Best,
Ryan
On 30/12/2021, 3:08 AM, "Namhyung Kim" <[email protected]> wrote:
Hello,
On Wed, Dec 22, 2021 at 3:33 AM Ryan Cai <[email protected]> wrote:
>
> Hi, I found a potential lock problem in dso_data_get_fd. Because the inconsistent branch conditions of pthread_mutex_lock(&dso__data_open_lock) and pthread_mutex_unlock(&dso__data_open_lock), it is possible that the lock dso__data_open_lock is not released in the dso_data_get_fd. Also, I have a question on why the branch condition of pthread_mutex_lock(&dso__data_open_lock) is <0. I think that the branch condition should be !=0, because pthread_mutex_lock would return 0 when succeeding. Looking forward to further discussion. One this bug is confirmed, I can send a patch.
Please fix your mail client to wrap around 80 characters.
1. dso__data_get_fd() should be paired with dso__data_put_fd()
when it returns non-negative. It'd unlock the mutex.
2. I've checked the man page and it seems you're right.
It just says that it'd return an error number or zero.
https://linux.die.net/man/3/pthread_mutex_lock
Thanks,
Namhyung
>
>
>
> https://github.com/torvalds/linux/blob/e851dfae4371d3c751f1e18e8eb5eba993de1467/tools/perf/util/dso.c#L708-L722
>
>
>
> Best,
>
> Ryan
>
>
>
>
On Wed, Dec 29, 2021 at 6:42 PM Ryan Cai <[email protected]> wrote:
>
> Hi, Namhyung,
>
> 1. Indeed, I got wrong here.
> 2. Yes, the branch should be if (pthread_mutex_lock(&dso__data_open_lock))
> instead of if (pthread_mutex_lock(&dso__data_open_lock) < 0).
>
> Could I send a patch?
Sure!
Thanks,
Namhyung