Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1473144

Re: [PATCH] mm:Avoid soft lockup due to possible attempt of double locking object's lock in __delete_object

From Catalin Marinas <catalin.marinas@arm.com>
Newsgroups linux.kernel
Subject Re: [PATCH] mm:Avoid soft lockup due to possible attempt of double locking object's lock in __delete_object
Date 2016-08-31 10:00 +0200
Message-ID <sc8Bb-80v-9@gated-at.bofh.it> (permalink)
References <sc8Bb-80v-11@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On Tue, Aug 30, 2016 at 02:35:12PM -0400, Nicholas Krause wrote:
> This fixes a issue in the current locking logic of the function,
> __delete_object where we are trying to attempt to lock the passed
> object structure's spinlock again after being previously held
> elsewhere by the kmemleak code. Fix this by instead of assuming
> we are the only one contending for the object's lock their are
> possible other users and create two branches, one where we get
> the lock when calling spin_trylock_irqsave on the object's lock
> and the other when the lock is held else where by kmemleak.

Have you actually got a deadlock that requires this fix?

> --- a/mm/kmemleak.c
> +++ b/mm/kmemleak.c
> @@ -631,12 +631,19 @@ static void __delete_object(struct kmemleak_object *object)
>  
>  	/*
>  	 * Locking here also ensures that the corresponding memory block
> -	 * cannot be freed when it is being scanned.
> +	 * cannot be freed when it is being scanned. Further more the
> +	 * object's lock may have been previously holded by another holder
> +	 * in the kmemleak code, therefore attempt to lock the object's lock
> +	 * before holding it and unlocking it.
>  	 */
> -	spin_lock_irqsave(&object->lock, flags);
> -	object->flags &= ~OBJECT_ALLOCATED;
> -	spin_unlock_irqrestore(&object->lock, flags);
> -	put_object(object);
> +	if (spin_trylock_irqsave(&object->lock, flags)) {
> +		object->flags &= ~OBJECT_ALLOCATED;
> +		spin_unlock_irqrestore(&object->lock, flags);
> +		put_object(object);
> +	} else {
> +		object->flags &= ~OBJECT_ALLOCATED;
> +		put_object(object);
> +	}

NAK. This lock here is needed, as described in the comment, to prevent
an object being freed while it is being scanned. The scan_object()
function acquires the same lock and checks for OBJECT_ALLOCATED before
accessing the memory (which could be vmalloc'ed for example, so freeing
would cause a page fault).

-- 
Catalin

Back to linux.kernel | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Re: [PATCH] mm:Avoid soft lockup due to possible attempt of double  locking object's lock in __delete_object Catalin Marinas <catalin.marinas@arm.com> - 2016-08-31 10:00 +0200
  Re: [PATCH] mm:Avoid soft lockup due to possible attempt of double  locking object's lock in __delete_object Catalin Marinas <catalin.marinas@arm.com> - 2016-08-31 16:40 +0200
  Re: [PATCH] mm:Avoid soft lockup due to possible attempt of double locking object's lock in __delete_object Valdis.Kletnieks@vt.edu - 2016-08-31 23:10 +0200
    Re: [PATCH] mm:Avoid soft lockup due to possible attempt of double  locking object's lock in __delete_object Rik van Riel <riel@redhat.com> - 2016-09-07 03:00 +0200
      Re: [PATCH] mm:Avoid soft lockup due to possible attempt of double  locking object's lock in __delete_object Rik van Riel <riel@redhat.com> - 2016-09-07 03:30 +0200
  Re: [PATCH] mm:Avoid soft lockup due to possible attempt of double  locking object's lock in __delete_object Rik van Riel <riel@redhat.com> - 2016-09-07 02:50 +0200

csiph-web