linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Dae R. Jeong" <threeearcat@gmail.com>
To: Takashi Iwai <tiwai@suse.de>
Cc: perex@perex.cz, alsa-devel@alsa-project.org, kt0755@gmail.com,
	syzkaller@googlegroups.com, bammanag@purdue.edu,
	linux-kernel@vger.kernel.org
Subject: Re: BUG: soft lockup in snd_virmidi_output_trigger
Date: Fri, 27 Jul 2018 14:51:04 +0900	[thread overview]
Message-ID: <20180727055104.GA18733@dragonet> (raw)
In-Reply-To: <s5hbmatuue9.wl-tiwai@suse.de>

On Fri, Jul 27, 2018 at 07:20:30AM +0200, Takashi Iwai wrote:

I think there is a mistake on the reported-by tag.
The reported-by tag (e4c8abb920ef...) is for WARNING in port_delete.
I guess the tag below is correct.
Reported-by: syzbot+619d9f40141d826b097e@syzkaller.appspotmail.com
Could you please make sure that the reported-by tag is correct?

By the way, I can't reproduce the crash WARNING in port_delete so
far. I feel sad for saying this..
I really want to reproduce the crash and thus, to help to fix the
crash. If there is any progress on it, I will let you know
immediately.


Best regards,
Dae R. Jeong

> On Fri, 27 Jul 2018 06:13:22 +0200,
> Dae R. Jeong wrote:
> > 
> > I tested it and it worked.
> > Thanks a lot!
> 
> Good to hear.  Below is the final patch with a proper comment (and
> with syzbot reported-by, too) I'm going to queue to sound.git tree.
> 
> 
> thanks,
> 
> Takashi
> 
> -- 8< --
> 
> From: Takashi Iwai <tiwai@suse.de>
> Subject: [PATCH v2] ALSA: virmidi: Fix too long output trigger loop
> 
> The virmidi output trigger tries to parse the all available bytes and
> process sequencer events as much as possible.  In a normal situation,
> this is supposed to be relatively short, but a program may give a huge
> buffer and it'll take a long time in a single spin lock, which may
> eventually lead to a soft lockup.
> 
> This patch simply adds a workaround, a cond_resched() call in the loop
> if applicable.  A better solution would be to move the event processor
> into a work, but let's put a duct-tape quickly at first.
> 
> Reported-and-tested-by: Dae R. Jeong <threeearcat@gmail.com>
> Reported-by: syzbot+e4c8abb920efa77bace9@syzkaller.appspotmail.com
> Cc: <stable@vger.kernel.org>
> Signed-off-by: Takashi Iwai <tiwai@suse.de>
> ---
>  sound/core/seq/seq_virmidi.c | 10 ++++++++++
>  1 file changed, 10 insertions(+)
> 
> diff --git a/sound/core/seq/seq_virmidi.c b/sound/core/seq/seq_virmidi.c
> index 289ae6bb81d9..8ebbca554e99 100644
> --- a/sound/core/seq/seq_virmidi.c
> +++ b/sound/core/seq/seq_virmidi.c
> @@ -163,6 +163,7 @@ static void snd_virmidi_output_trigger(struct snd_rawmidi_substream *substream,
>  	int count, res;
>  	unsigned char buf[32], *pbuf;
>  	unsigned long flags;
> +	bool check_resched = !in_atomic();
>  
>  	if (up) {
>  		vmidi->trigger = 1;
> @@ -200,6 +201,15 @@ static void snd_virmidi_output_trigger(struct snd_rawmidi_substream *substream,
>  					vmidi->event.type = SNDRV_SEQ_EVENT_NONE;
>  				}
>  			}
> +			if (!check_resched)
> +				continue;
> +			/* do temporary unlock & cond_resched() for avoiding
> +			 * CPU soft lockup, which may happen via a write from
> +			 * a huge rawmidi buffer
> +			 */
> +			spin_unlock_irqrestore(&substream->runtime->lock, flags);
> +			cond_resched();
> +			spin_lock_irqsave(&substream->runtime->lock, flags);
>  		}
>  	out:
>  		spin_unlock_irqrestore(&substream->runtime->lock, flags);
> -- 
> 2.18.0
> 

  reply	other threads:[~2018-07-27  5:51 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-26  5:53 BUG: soft lockup in snd_virmidi_output_trigger Dae R. Jeong
2018-07-26 12:50 ` Takashi Iwai
2018-07-26 12:58   ` Dmitry Vyukov
2018-07-26 13:07     ` Takashi Iwai
2018-07-27  4:13   ` Dae R. Jeong
2018-07-27  5:20     ` Takashi Iwai
2018-07-27  5:51       ` Dae R. Jeong [this message]
2018-07-27  7:02         ` Takashi Iwai
  -- strict thread matches above, loose matches on Subject: below --
2018-04-09  5:58 syzbot
2018-04-09 13:03 ` Takashi Iwai
2018-04-09 13:52   ` Dmitry Vyukov

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=20180727055104.GA18733@dragonet \
    --to=threeearcat@gmail.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=bammanag@purdue.edu \
    --cc=kt0755@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=perex@perex.cz \
    --cc=syzkaller@googlegroups.com \
    --cc=tiwai@suse.de \
    /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).