Re: Lock problems in linux/tools/perf/util/dso.c

3 messages, 2 authors, 2022-01-04 · open the first message on its own page

Re: Lock problems in linux/tools/perf/util/dso.c

From: Namhyung Kim <namhyung@kernel.org>
Date: 2021-12-29 19:08:40

Hello,

On Wed, Dec 22, 2021 at 3:33 AM Ryan Cai [off-list ref] 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


Re: Lock problems in linux/tools/perf/util/dso.c

From: Ryan Cai <hidden>
Date: 2021-12-30 02:42:36

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" [off-list ref] wrote:

    Hello,

    On Wed, Dec 22, 2021 at 3:33 AM Ryan Cai [off-list ref] 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
    >
    >
    >
    >

Re: Lock problems in linux/tools/perf/util/dso.c

From: Namhyung Kim <namhyung@kernel.org>
Date: 2022-01-04 19:33:53

On Wed, Dec 29, 2021 at 6:42 PM Ryan Cai [off-list ref] 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
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help