mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: vigneshr@codeaurora.org
To: "Catalin Marinas" <catalin.marinas@arm.com>
Cc: "vigneshr@codeaurora.org" <vigneshr@codeaurora.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"bernd.schubert@itwm.fraunhofer.de" 
	<bernd.schubert@itwm.fraunhofer.de>
Subject: Re: Crash in crc32_le during kmemleak_scan()
Date: Fri, 15 May 2015 04:53:23 -0000	[thread overview]
Message-ID: <67b8401e956baaac1c54a9d8fd0019d6.squirrel@www.codeaurora.org> (raw)
In-Reply-To: <20150514112154.GD18655@e104818-lin.cambridge.arm.com>

>
> kmemleak_disable() may be called in an atomic context, so calling
> kthread_stop() here is not safe. We have a scan_should_stop() function
> which checks for the kmemleak_enabled variable but it doesn't seem to be
> enough.
>
> Basically the object_list has some vmalloc'ed objects. Scanning such
> objects is protected by the kmemleak_object.lock and the look-up by the
> kmemleak_lock. What happens during kmemleak_disable() is that we set
> kmemleak_enable to 0 and kmemleak_free() simply exits. When this happens
> during a scan, objects in the object_list are freed/vunmap'ed but
> kmemleak doesn't know about this until the clean-up completes (which, as
> you found, may be blocked on the scanning to complete).
>
> A patch I had but never managed to test it properly (as in reproducing
> the low mem conditions during a scan) postpones the kmemleak disabling
> until after the clean-up is finished. If it works for you, I'll add a
> proper commit message:
>
> -----8<-------------------------
>
> diff --git a/mm/kmemleak.c b/mm/kmemleak.c
> index 5405aff5a590..dcba05812678 100644
> --- a/mm/kmemleak.c
> +++ b/mm/kmemleak.c
> @@ -521,6 +521,10 @@ static struct kmemleak_object *create_object(unsigned
> long ptr, size_t size,
>  	struct kmemleak_object *object, *parent;
>  	struct rb_node **link, *rb_parent;
>
> +	/* stop further allocations while kmemleak is being disabled */
> +	if (kmemleak_error)
> +		return NULL;
> +
>  	object = kmem_cache_alloc(object_cache, gfp_kmemleak_mask(gfp));
>  	if (!object) {
>  		pr_warning("Cannot allocate a kmemleak_object structure\n");
> @@ -741,6 +745,10 @@ static void add_scan_area(unsigned long ptr, size_t
> size, gfp_t gfp)
>  	struct kmemleak_object *object;
>  	struct kmemleak_scan_area *area;
>
> +	/* stop further allocations while kmemleak is being disabled */
> +	if (kmemleak_error)
> +		return;
> +
>  	object = find_and_get_object(ptr, 1);
>  	if (!object) {
>  		kmemleak_warn("Adding scan area to unknown object at 0x%08lx\n",
> @@ -1127,7 +1135,7 @@ static bool update_checksum(struct kmemleak_object
> *object)
>   */
>  static int scan_should_stop(void)
>  {
> -	if (!kmemleak_enabled)
> +	if (kmemleak_error)
>  		return 1;
>
>  	/*
> @@ -1755,6 +1763,10 @@ static void kmemleak_do_cleanup(struct work_struct
> *work)
>  		pr_info("Kmemleak disabled without freeing internal data. "
>  			"Reclaim the memory with \"echo clear >
> /sys/kernel/debug/kmemleak\"\n");
>  	mutex_unlock(&scan_mutex);
> +
> +	/* stop any memory operation tracing */
> +	kmemleak_enabled = 0;
> +
>  }
>
>  static DECLARE_WORK(cleanup_work, kmemleak_do_cleanup);
> @@ -1769,12 +1781,11 @@ static void kmemleak_disable(void)
>  	if (cmpxchg(&kmemleak_error, 0, 1))
>  		return;
>
> -	/* stop any memory operation tracing */
> -	kmemleak_enabled = 0;
> -
>  	/* check whether it is too early for a kernel thread */
>  	if (kmemleak_initialized)
>  		schedule_work(&cleanup_work);
> +	else
> +		kmemleak_enabled = 0;
>
>  	pr_info("Kernel memory leak detector disabled\n");
>  }
>
> --
> Catalin
> --

Thank you for the explanation and the patch. I will give this a shot and
will get back with the results.

--
Thanks and regards,
Vignesh Radhakrishnan


QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member
of the Code Aurora Forum, hosted by The Linux Foundation.



  reply	other threads:[~2015-05-15  4:53 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-13 13:15 vigneshr
2015-05-14 11:21 ` Catalin Marinas
2015-05-15  4:53   ` vigneshr [this message]
2015-05-20 13:16 ` vigneshr
2015-05-21  5:45   ` vigneshr
2015-05-22 16:51     ` Catalin Marinas
2015-06-01  4:57       ` vigneshr
2015-06-19 10:30         ` vigneshr
2015-06-19 13:20           ` 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=67b8401e956baaac1c54a9d8fd0019d6.squirrel@www.codeaurora.org \
    --to=vigneshr@codeaurora.org \
    --cc=bernd.schubert@itwm.fraunhofer.de \
    --cc=catalin.marinas@arm.com \
    --cc=linux-kernel@vger.kernel.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

Powered by JetHome