mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Pekka Enberg <penberg@cs.helsinki.fi>
To: Catalin Marinas <catalin.marinas@arm.com>
Cc: Ingo Molnar <mingo@elte.hu>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Peter Zijlstra <a.p.zijlstra@chello.nl>,
	git-commits-head@vger.kernel.org
Subject: Re: Exiting with locks still held (was Re: [PATCH] kmemleak: Fix  scheduling-while-atomic bug)
Date: Thu, 2 Jul 2009 15:54:00 +0300	[thread overview]
Message-ID: <84144f020907020554n1b098e28o8b4a4a58a08728e3@mail.gmail.com> (raw)
In-Reply-To: <1246538899.13320.86.camel@pc1117.cambridge.arm.com>

Hi Catalin,

On Thu, Jul 2, 2009 at 3:48 PM, Catalin Marinas<catalin.marinas@arm.com> wrote:
> It could be but I can't figure out a solution. If there is only one task
> opening and closing the kmemleak file, everything is fine. In
> combination with shell piping I think I get the kmemleak file descriptor
> released from a different task than the one that opened it.
>
> For example, the badly written code below opens kmemleak and acquires
> the scan_mutex in the parent task but releases it in the child (it needs
> a few tries to trigger it). With waitpid() in parent everything is fine.
>
> #include <stdio.h>
> #include <sys/types.h>
> #include <sys/stat.h>
> #include <fcntl.h>
> #include <unistd.h>
> #include <sys/wait.h>
>
> int main(void)
> {
>        int fd = open("/sys/kernel/debug/kmemleak", O_RDONLY);
>
>        printf("fd = %d\n", fd);
>        if (fd < 0)
>                return 2;
>
>        if (!fork()) {
>                /* child */
>                sleep(2);
>                close(fd);
>                printf("fd closed in child\n");
>        }
>
>        return 0;
> }
>
> Running this gives (the ### lines are printed in the
> kmemleak_open/release functions):
>
> # ./cat-kmemleak
> ### kmemleak_open current->pid = 1409
> fd = 3
> =====================================
> [ BUG: lock held at task exit time! ]
> -------------------------------------
> cat-kmemleak/1409 is exiting with locks still held!
> 1 lock held by cat-kmemleak/1409:
>  #0:  (scan_mutex){+.+.+.}, at: [<c00662b1>] kmemleak_open+0x31/0x68
>
> stack backtrace:
> [<c0024025>] (unwind_backtrace+0x1/0x80) from [<c01cddd7>] (dump_stack+0xb/0xc)
> [<c01cddd7>] (dump_stack+0xb/0xc) from [<c0043d2d>] (debug_check_no_locks_held+0x49/0x64)
> [<c0043d2d>] (debug_check_no_locks_held+0x49/0x64) from [<c0031423>] (do_exit+0x3fb/0x43c)
> [<c0031423>] (do_exit+0x3fb/0x43c) from [<c00314c5>] (do_group_exit+0x61/0x80)
> [<c00314c5>] (do_group_exit+0x61/0x80) from [<c00314f3>] (sys_exit_group+0xf/0x14)
> [<c00314f3>] (sys_exit_group+0xf/0x14) from [<c001fc41>] (ret_fast_syscall+0x1/0x40)
>
> ### kmemleak_release current->pid = 1410
> fd closed in child
>
> Any suggestions? Thanks.

Well, you are not supposed to hold on to locks when returning from a
system call ("sys_open") anyway. You can probably do the exclusion
with a kmemcheck specific flag?

                        Pekka

  reply	other threads:[~2009-07-02 12:54 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <200907010300.n6130rRf026194@hera.kernel.org>
2009-07-01  7:53 ` [PATCH] kmemleak: Fix scheduling-while-atomic bug Ingo Molnar
2009-07-01  8:10   ` Pekka Enberg
2009-07-01  9:18   ` Catalin Marinas
2009-07-01  9:30     ` Ingo Molnar
2009-07-01  9:46       ` Catalin Marinas
2009-07-01 11:04         ` Ingo Molnar
2009-07-02 12:48           ` Exiting with locks still held (was Re: [PATCH] kmemleak: Fix scheduling-while-atomic bug) Catalin Marinas
2009-07-02 12:54             ` Pekka Enberg [this message]
2009-07-02 13:06               ` Catalin Marinas
2009-07-02 14:13               ` Catalin Marinas
2009-07-02 17:39                 ` Linus Torvalds
2009-07-03 10:18                   ` Catalin Marinas
2009-07-03  7:04             ` Ingo Molnar
2009-07-02  9:48       ` [PATCH] kmemleak: Fix scheduling-while-atomic bug Catalin Marinas
2009-07-03  7:00         ` [PATCH] kmemleak: Mark nice +10 Ingo Molnar
2009-07-03  8:09           ` Catalin Marinas
2009-07-08 13:33       ` [PATCH] kmemleak: Fix scheduling-while-atomic bug Catalin Marinas
2009-08-23  2:48         ` Ming Lei
2009-08-23 14:59           ` Catalin Marinas
2009-08-24  0:10             ` Ming Lei
2009-08-24 10:02               ` ACPI scheduling while atomic (was: Re: [PATCH] kmemleak: Fix scheduling-while-atomic bug) Catalin Marinas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=84144f020907020554n1b098e28o8b4a4a58a08728e3@mail.gmail.com \
    --to=penberg@cs.helsinki.fi \
    --cc=a.p.zijlstra@chello.nl \
    --cc=akpm@linux-foundation.org \
    --cc=catalin.marinas@arm.com \
    --cc=git-commits-head@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=torvalds@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®