linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Pekka Enberg <penberg@kernel.org>
To: Christoph Lameter <cl@linux.com>
Cc: linux-mm@kvack.org, waiman.long@hp.com, rientjes@google.com
Subject: Re: [PATCH] slub: prevent validate_slab() error due to race condition
Date: Thu, 16 Aug 2012 10:02:25 +0300 (EEST)	[thread overview]
Message-ID: <alpine.LFD.2.02.1208160944400.2133@tux.localdomain> (raw)
In-Reply-To: <alpine.DEB.2.00.1205301254080.31078@router.home>

On Wed, 30 May 2012, Christoph Lameter wrote:
> Subject: slub: Take node lock during object free checks
> 
> Only applies to scenarios where debugging is on:
> 
> Validation of slabs can currently occur while debugging
> information is updated from the fast paths of the allocator.
> This results in various races where we get false reports about
> slab metadata not being in order.
> 
> This patch makes the fast paths take the node lock so that
> serialization with slab validation will occur. Causes additional
> slowdown in debug scenarios.
> 
> Reported-by: Waiman Long <Waiman.Long@hp.com>
> Signed-off-by: Christoph Lameter <cl@linux.com>

Applied! Thanks and sorry for the delay.

> 
> ---
>  mm/slub.c |   30 ++++++++++++++++++------------
>  1 file changed, 18 insertions(+), 12 deletions(-)
> 
> Index: linux-2.6/mm/slub.c
> ===================================================================
> --- linux-2.6.orig/mm/slub.c	2012-05-21 08:58:30.000000000 -0500
> +++ linux-2.6/mm/slub.c	2012-05-30 12:53:29.000000000 -0500
> @@ -1082,13 +1082,13 @@ bad:
>  	return 0;
>  }
> 
> -static noinline int free_debug_processing(struct kmem_cache *s,
> -		 struct page *page, void *object, unsigned long addr)
> +static noinline struct kmem_cache_node *free_debug_processing(
> +	struct kmem_cache *s, struct page *page, void *object,
> +	unsigned long addr, unsigned long *flags)
>  {
> -	unsigned long flags;
> -	int rc = 0;
> +	struct kmem_cache_node *n = get_node(s, page_to_nid(page));
> 
> -	local_irq_save(flags);
> +	spin_lock_irqsave(&n->list_lock, *flags);
>  	slab_lock(page);
> 
>  	if (!check_slab(s, page))
> @@ -1126,15 +1126,19 @@ static noinline int free_debug_processin
>  		set_track(s, object, TRACK_FREE, addr);
>  	trace(s, page, object, 0);
>  	init_object(s, object, SLUB_RED_INACTIVE);
> -	rc = 1;
>  out:
>  	slab_unlock(page);
> -	local_irq_restore(flags);
> -	return rc;
> +	/*
> +	 * Keep node_lock to preserve integrity
> +	 * until the object is actually freed
> +	 */
> +	return n;
> 
>  fail:
> +	slab_unlock(page);
> +	spin_unlock_irqrestore(&n->list_lock, *flags);
>  	slab_fix(s, "Object at 0x%p not freed", object);
> -	goto out;
> +	return NULL;
>  }
> 
>  static int __init setup_slub_debug(char *str)
> @@ -1227,8 +1231,9 @@ static inline void setup_object_debug(st
>  static inline int alloc_debug_processing(struct kmem_cache *s,
>  	struct page *page, void *object, unsigned long addr) { return 0; }
> 
> -static inline int free_debug_processing(struct kmem_cache *s,
> -	struct page *page, void *object, unsigned long addr) { return 0; }
> +static inline struct kmem_cache_node *free_debug_processing(
> +	struct kmem_cache *s, struct page *page, void *object,
> +	unsigned long addr, unsigned long *flags) { return NULL; }
> 
>  static inline int slab_pad_check(struct kmem_cache *s, struct page *page)
>  			{ return 1; }
> @@ -2445,7 +2450,8 @@ static void __slab_free(struct kmem_cach
> 
>  	stat(s, FREE_SLOWPATH);
> 
> -	if (kmem_cache_debug(s) && !free_debug_processing(s, page, x, addr))
> +	if (kmem_cache_debug(s) &&
> +		!(n = free_debug_processing(s, page, x, addr, &flags)))
>  		return;
> 
>  	do {
> 

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

      reply	other threads:[~2012-08-16  7:02 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-26 18:57 [PATCH] slub: prevent validate_slab() error due to race condition Waiman Long
2012-04-26 19:12 ` Eric Dumazet
2012-04-26 19:20   ` Don Morris
2012-04-26 19:44     ` Eric Dumazet
2012-04-27 14:59 ` Christoph Lameter
2012-04-27 20:10   ` Waiman Long
2012-04-30  6:35     ` Pekka Enberg
2012-05-01 20:23       ` Christoph Lameter
     [not found]         ` <alpine.LFD.2.02.1205300946170.2681@tux.localdomain>
     [not found]           ` <alpine.DEB.2.00.1205301039420.29257@router.home>
2012-05-30 17:54             ` Christoph Lameter
2012-08-16  7:02               ` Pekka Enberg [this message]

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=alpine.LFD.2.02.1208160944400.2133@tux.localdomain \
    --to=penberg@kernel.org \
    --cc=cl@linux.com \
    --cc=linux-mm@kvack.org \
    --cc=rientjes@google.com \
    --cc=waiman.long@hp.com \
    /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;
as well as URLs for NNTP newsgroup(s).