All of lore.kernel.org
 help / color / mirror / Atom feed
From: Manfred Spraul <manfred@colorfullife.com>
To: cgel.zte@gmail.com, akpm@linux-foundation.org
Cc: vvs@virtuozzo.com, shakeelb@google.com, rdunlap@infradead.org,
	dbueso@suse.de, unixbhaskar@gmail.com, chi.minghao@zte.com.cn,
	arnd@arndb.de, linux-kernel@vger.kernel.org,
	Zeal Robot <zealci@zte.com.cn>
Subject: Re: [PATCH] ipc/sem: do not sleep with a spin lock held
Date: Wed, 22 Dec 2021 12:45:33 +0100	[thread overview]
Message-ID: <63840bf3-2199-3240-bdfa-abb55518b5f9@colorfullife.com> (raw)
In-Reply-To: <20211222081026.484058-1-chi.minghao@zte.com.cn>

Hi Minghao,

On 12/22/21 09:10, cgel.zte@gmail.com wrote:
> From: Minghao Chi <chi.minghao@zte.com.cn>
>
> We can't call kvfree() with a spin lock held, so defer it.
>
> Reported-by: Zeal Robot <zealci@zte.com.cn>
> Signed-off-by: Minghao Chi <chi.minghao@zte.com.cn>

Could you add

Fixes: fc37a3b8b438 ("[PATCH] ipc sem: use kvmalloc for sem_undo 
allocation")

Cc: stable@vger.kernel.org

I will review/test the change in the next few days.

Especially, I would like to check if there are further instances where 
the same mistake was made.

> /**
> * kvfree() - Free memory.
> * @addr: Pointer to allocated memory.
> *
> * kvfree frees memory allocated by any of vmalloc(), kmalloc() or 
> kvmalloc().
> * It is slightly more efficient to use kfree() or vfree() if you are 
> certain
> * that you know which one to use.
> *
> * Context: Either preemptible task context or not-NMI interrupt.
> */
>
As an independent change: Should we add a


       might_sleep_if(!in_interrupt());

into kvfree(), to trigger bugs more easily?

> ---
>   ipc/sem.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/ipc/sem.c b/ipc/sem.c
> index 6693daf4fe11..0dbdb98fdf2d 100644
> --- a/ipc/sem.c
> +++ b/ipc/sem.c
> @@ -1964,6 +1964,7 @@ static struct sem_undo *find_alloc_undo(struct ipc_namespace *ns, int semid)
>   	 */
>   	un = lookup_undo(ulp, semid);
>   	if (un) {
> +		spin_unlock(&ulp->lock);
>   		kvfree(new);
>   		goto success;
>   	}
> @@ -1976,9 +1977,8 @@ static struct sem_undo *find_alloc_undo(struct ipc_namespace *ns, int semid)
>   	ipc_assert_locked_object(&sma->sem_perm);
>   	list_add(&new->list_id, &sma->list_id);
>   	un = new;
> -
> -success:
>   	spin_unlock(&ulp->lock);
> +success:
>   	sem_unlock(sma, -1);
>   out:
>   	return un;



  reply	other threads:[~2021-12-22 11:45 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-22  8:10 [PATCH] ipc/sem: do not sleep with a spin lock held cgel.zte
2021-12-22 11:45 ` Manfred Spraul [this message]
2021-12-22 15:31   ` Vasily Averin
2021-12-22 15:50     ` Vasily Averin
2021-12-22 17:06       ` Manfred Spraul
2021-12-22 17:38         ` Vasily Averin
2021-12-22 19:08           ` Vasily Averin
2021-12-23  2:37   ` [PATCH v2] " cgel.zte
2021-12-23  2:56   ` cgel.zte
2021-12-23  3:12   ` cgel.zte
2022-01-03  9:27     ` Jiri Slaby
2022-01-03 17:17       ` Manfred Spraul
2022-01-04 18:20         ` Shakeel Butt
2022-01-04 18:20     ` Shakeel Butt
2022-01-04 20:18       ` Manfred Spraul

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=63840bf3-2199-3240-bdfa-abb55518b5f9@colorfullife.com \
    --to=manfred@colorfullife.com \
    --cc=akpm@linux-foundation.org \
    --cc=arnd@arndb.de \
    --cc=cgel.zte@gmail.com \
    --cc=chi.minghao@zte.com.cn \
    --cc=dbueso@suse.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rdunlap@infradead.org \
    --cc=shakeelb@google.com \
    --cc=unixbhaskar@gmail.com \
    --cc=vvs@virtuozzo.com \
    --cc=zealci@zte.com.cn \
    /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 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.