From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DAC6BC67790 for ; Fri, 27 Jul 2018 07:02:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 835AE20873 for ; Fri, 27 Jul 2018 07:02:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 835AE20873 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729489AbeG0IWj (ORCPT ); Fri, 27 Jul 2018 04:22:39 -0400 Received: from mx2.suse.de ([195.135.220.15]:52506 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725988AbeG0IWj (ORCPT ); Fri, 27 Jul 2018 04:22:39 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 5D8B3B603; Fri, 27 Jul 2018 07:02:08 +0000 (UTC) Date: Fri, 27 Jul 2018 09:02:07 +0200 Message-ID: From: Takashi Iwai To: "Dae R. Jeong" 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 In-Reply-To: <20180727055104.GA18733@dragonet> References: <20180726055326.GA12625@dragonet> <20180727041322.GA13067@dragonet> <20180727055104.GA18733@dragonet> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI/1.14.6 (Maruoka) FLIM/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL/10.8 Emacs/26 (x86_64-suse-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 27 Jul 2018 07:51:04 +0200, Dae R. Jeong wrote: > > 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? Indeed, corrected now. Thanks. > 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. This looks like a sheer race condition. Thanks for your help in anyway! Takashi > > 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 > > 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 > > Reported-by: syzbot+e4c8abb920efa77bace9@syzkaller.appspotmail.com > > Cc: > > Signed-off-by: Takashi Iwai > > --- > > 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 > > >