mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Hillf Danton <hdanton@sina.com>
To: Yunseong Kim <ysk@kzalloc.com>
Cc: Dmitry Vyukov <dvyukov@google.com>,
	Andrey Konovalov <andreyknvl@gmail.com>,
	linux-kernel@vger.kernel.org,
	Tetsuo Handa <penguin-kernel@i-love.sakura.ne.jp>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
	Uladzislau Rezki <urezki@gmail.com>
Subject: Re: [PATCH v2] kcov, usb: Fix invalid context sleep in softirq path on PREEMPT_RT
Date: Sun,  3 Aug 2025 16:49:22 +0800	[thread overview]
Message-ID: <20250803084924.3785-1-hdanton@sina.com> (raw)
In-Reply-To: <18003f21-f83a-4bad-93b2-70273c03974f@kzalloc.com>

On Sun, 3 Aug 2025 12:07:11 +0900 Yunseong Kim wrote:
> On 8/3/25 11:34 오전, Hillf Danton wrote:
> > On Sat,  2 Aug 2025 14:26:49 +0000 Yunseong Kim wrote:
> >> +	raw_spin_unlock(&kcov_remote_lock);
> >>  
> >>  	/* Can only happen when in_task(). */
> >>  	if (!area) {
> 
> 		/* 1. Interrupts are temporarily re-enabled here. */
> 
> >> -		local_unlock_irqrestore(&kcov_percpu_data.lock, flags);
> >> +		local_irq_restore(flags);
> 
> 		/* 2. vmalloc() is called safely in a non-atomic context. */
> 
> >>  		area = vmalloc(size * sizeof(unsigned long));
> > 
> > Given irq disabled for the duration of the coverage collection section [1],
> > vmalloc does not work here [2].
> 
> 
> Thank you for the detailed review and for pointing out this critical
> interaction. You are absolutely correct that vmalloc() cannot be called
> from an atomic context with interrupts disabled, as it is a sleeping function.
> 
> However, upon closer inspection of the kcov_remote_start() function's
> control flow, it appears the original author anticipated this issue and
> implemented a safeguard. The vmalloc() call is explicitly wrapped by
> local_irq_restore() and local_irq_save():
> 
> >>  		if (!area) {
> >>  			kcov_put(kcov);
> >>  			return;
> >>  		}
> 
> 		/* 3. Interrupts are disabled again to protect the rest of the function. */
> 
> >> -		local_lock_irqsave(&kcov_percpu_data.lock, flags);
> >> +		local_irq_save(flags);
> >>  	}
> 
> This sequence ensures that the vmalloc() call itself does not happen in an
> IRQ-disabled context.
> 
> My patch reverts the per-CPU locking back to the local_irq_save/restore
> primitives but preserves this essential bracketing around the vmalloc() call.
> Therefore, the sleeping function bug should not occur.
> 
What you missed is the local_irq_save in kcov_remote_start_usb_softirq().
See comment [1] for detail.

> > [1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/include/linux/kcov.h#n73
> > [2] Subject: [RFC 0/7] vmallloc and non-blocking GFPs
> > https://lore.kernel.org/all/20250704152537.55724-1-urezki@gmail.com/
> 
> Additionally, I have tested this implementation by running syzkaller
> for a full day, and no issues were reported.
> 
> Perhaps a comment could be added here (I can volunteer to do so) to
> improve readability where the control flow isn’t obvious to future developers.
> 
> Thanks,
> 
> Yunseong Kim
> 
> 

      reply	other threads:[~2025-08-03  8:49 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-02 14:26 Yunseong Kim
2025-08-02 21:30 ` Greg Kroah-Hartman
2025-08-02 21:30 ` Greg Kroah-Hartman
2025-08-02 22:01   ` Yunseong Kim
2025-08-03  2:34 ` Hillf Danton
2025-08-03  3:07   ` Yunseong Kim
2025-08-03  8:49     ` Hillf Danton [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=20250803084924.3785-1-hdanton@sina.com \
    --to=hdanton@sina.com \
    --cc=andreyknvl@gmail.com \
    --cc=bigeasy@linutronix.de \
    --cc=dvyukov@google.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=penguin-kernel@i-love.sakura.ne.jp \
    --cc=urezki@gmail.com \
    --cc=ysk@kzalloc.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

all inboxes | Powered by JetHome®