All of lore.kernel.org
 help / color / mirror / Atom feed
* Re: Lock problems in linux/tools/perf/util/dso.c
       [not found] <4C0186FE-729D-4F77-947D-11933BA38818@gmail.com>
@ 2021-12-29 19:08 ` Namhyung Kim
  2021-12-30  2:42   ` Ryan Cai
  0 siblings, 1 reply; 3+ messages in thread
From: Namhyung Kim @ 2021-12-29 19:08 UTC (permalink / raw)
  To: Ryan Cai
  Cc: Adrian Hunter, Peter Zijlstra, Arnaldo Carvalho de Melo,
	Mark Rutland, Alexander Shishkin, Song Liu, Yonghong Song,
	linux-kernel, netdev

Hello,

On Wed, Dec 22, 2021 at 3:33 AM Ryan Cai <ycaibb@gmail.com> 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
>
>
>
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Lock problems in linux/tools/perf/util/dso.c
  2021-12-29 19:08 ` Lock problems in linux/tools/perf/util/dso.c Namhyung Kim
@ 2021-12-30  2:42   ` Ryan Cai
  2022-01-04 19:33     ` Namhyung Kim
  0 siblings, 1 reply; 3+ messages in thread
From: Ryan Cai @ 2021-12-30  2:42 UTC (permalink / raw)
  To: Namhyung Kim
  Cc: Adrian Hunter, Peter Zijlstra, Arnaldo Carvalho de Melo,
	Mark Rutland, Alexander Shishkin, Song Liu, Yonghong Song,
	linux-kernel, netdev

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" <namhyung@kernel.org> wrote:

    Hello,

    On Wed, Dec 22, 2021 at 3:33 AM Ryan Cai <ycaibb@gmail.com> 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
    >
    >
    >
    >



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Lock problems in linux/tools/perf/util/dso.c
  2021-12-30  2:42   ` Ryan Cai
@ 2022-01-04 19:33     ` Namhyung Kim
  0 siblings, 0 replies; 3+ messages in thread
From: Namhyung Kim @ 2022-01-04 19:33 UTC (permalink / raw)
  To: Ryan Cai
  Cc: Adrian Hunter, Peter Zijlstra, Arnaldo Carvalho de Melo,
	Mark Rutland, Alexander Shishkin, Song Liu, Yonghong Song,
	linux-kernel, netdev

On Wed, Dec 29, 2021 at 6:42 PM Ryan Cai <ycaibb@gmail.com> 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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-01-04 19:33 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <4C0186FE-729D-4F77-947D-11933BA38818@gmail.com>
2021-12-29 19:08 ` Lock problems in linux/tools/perf/util/dso.c Namhyung Kim
2021-12-30  2:42   ` Ryan Cai
2022-01-04 19:33     ` Namhyung Kim

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.