From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Cyrus-Session-Id: sloti22d1t05-3258100-1518626596-2-7860529298434710685 X-Sieve: CMU Sieve 3.0 X-Spam-known-sender: no X-Spam-score: 0.0 X-Spam-hits: BAYES_00 -1.9, HEADER_FROM_DIFFERENT_DOMAINS 0.001, ME_NOAUTH 0.01, RCVD_IN_DNSWL_HI -5, T_RP_MATCHES_RCVD -0.01, LANGUAGES en, BAYES_USED global, SA_VERSION 3.4.0 X-Spam-source: IP='209.132.180.67', Host='vger.kernel.org', Country='US', FromHeader='de', MailFrom='org' X-Spam-charsets: plain='UTF-8' X-Resolved-to: greg@kroah.com X-Delivered-to: greg@kroah.com X-Mail-from: stable-owner@vger.kernel.org ARC-Seal: i=1; a=rsa-sha256; cv=none; d=messagingengine.com; s=arctest; t=1518626595; b=K783y4OnMWUEZdRPQyXU5xGlwW49H5nciUNL0OZmD8cwTwA zo7ot1Zuezhet6ew/eQ91AWJVhYOCz2cxD9YitAv2IJcwcuFKW84JGVFe7emaiNR 8Aw05gV1X+Y6Px68Y1jpJCkAHil+hs3fjsUImdP8wQiYyttRUQwlAydJw48bGaHx FsuWbspRzMoKAsn5r474WzVuEbyIpMYJfKOX2M8WKR1UCYQCzt8u9ArLKYNuGLAe GGzR7goJVwrI2lWh0bOItEhRE11hUQXA31efImfyjhlcOo+89bV7Lv29YZTZtdoj YoczyN2vFdYhZElsr358ZoM/EmXXIf4isOuWmqg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=date:message-id:from:to:cc:subject :in-reply-to:references:mime-version:content-type :content-transfer-encoding:sender:list-id; s=arctest; t= 1518626595; bh=KER9B/tFdxPlGrogMX9UejWnizOJr3el68nRjr9ZpYk=; b=a DrJD73w99Yuj3Y1LlLFQxfH9uvMH4s4E0azhfd2JXAew0o3xYxAGPRj4V+FxEWCJ LGWXYR1ySu8+QTkGr60ywrWnEaclovTHwz7MhoQuCPyhCSKmeGrVEyHoB5PhibRv fSEFxf0T6ZmemAgQMbk189JbWticrY1lLKz6adnsc1imofDdLAS9RrjDgCOidLwe 9uKmOoKv+rspg+JLXgXmuFmxQeLiAtKURg4hN9IVgx9NgH6I1kAEgwGT33MlJ86q N+RPu+9qxUm+MPdI2z2Cz1Cd0+19q9yM9Ed24S2gpfv+vQwoNPe3nOBBL5twDpBU saHgOYvXwBGlGQgAZCD+w== ARC-Authentication-Results: i=1; mx2.messagingengine.com; arc=none (no signatures found); dkim=none (no signatures found); dmarc=none (p=none,has-list-id=yes,d=none) header.from=suse.de; iprev=pass policy.iprev=209.132.180.67 (vger.kernel.org); spf=none smtp.mailfrom=stable-owner@vger.kernel.org smtp.helo=vger.kernel.org; x-aligned-from=fail; x-ptr=pass x-ptr-helo=vger.kernel.org x-ptr-lookup=vger.kernel.org; x-return-mx=pass smtp.domain=vger.kernel.org smtp.result=pass smtp_org.domain=kernel.org smtp_org.result=pass smtp_is_org_domain=no header.domain=suse.de header.result=pass header_is_org_domain=yes Authentication-Results: mx2.messagingengine.com; arc=none (no signatures found); dkim=none (no signatures found); dmarc=none (p=none,has-list-id=yes,d=none) header.from=suse.de; iprev=pass policy.iprev=209.132.180.67 (vger.kernel.org); spf=none smtp.mailfrom=stable-owner@vger.kernel.org smtp.helo=vger.kernel.org; x-aligned-from=fail; x-ptr=pass x-ptr-helo=vger.kernel.org x-ptr-lookup=vger.kernel.org; x-return-mx=pass smtp.domain=vger.kernel.org smtp.result=pass smtp_org.domain=kernel.org smtp_org.result=pass smtp_is_org_domain=no header.domain=suse.de header.result=pass header_is_org_domain=yes Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1032662AbeBNQnM (ORCPT ); Wed, 14 Feb 2018 11:43:12 -0500 Received: from mx2.suse.de ([195.135.220.15]:45604 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1032509AbeBNQnL (ORCPT ); Wed, 14 Feb 2018 11:43:11 -0500 Date: Wed, 14 Feb 2018 17:43:09 +0100 Message-ID: From: Takashi Iwai To: Ben Hutchings Cc: stable@vger.kernel.org, Greg Kroah-Hartman , LKML Subject: Re: [PATCH 4.4 20/87] ALSA: pcm: Allow aborting mutex lock at OSS read/write loops In-Reply-To: <1518625223.3422.19.camel@codethink.co.uk> References: <20180115123349.252309699@linuxfoundation.org> <20180115123351.309626066@linuxfoundation.org> <1516750548.3417.34.camel@codethink.co.uk> <1518625223.3422.19.camel@codethink.co.uk> 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/25.3 (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=UTF-8 Content-Transfer-Encoding: 8bit Sender: stable-owner@vger.kernel.org X-Mailing-List: stable@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-Mailing-List: linux-kernel@vger.kernel.org List-ID: On Wed, 14 Feb 2018 17:20:23 +0100, Ben Hutchings wrote: > > On Mon, 2018-02-12 at 09:34 +0100, Takashi Iwai wrote: > > On Wed, 24 Jan 2018 00:35:48 +0100, > > Ben Hutchings wrote: > > > > > > On Mon, 2018-01-15 at 13:34 +0100, Greg Kroah-Hartman wrote: > > > > 4.4-stable review patch.  If anyone has any objections, please let me know. > > > > > > > > ------------------ > > > > > > > > From: Takashi Iwai > > > > > > > > commit 900498a34a3ac9c611e9b425094c8106bdd7dc1c upstream. > > > > > > > > PCM OSS read/write loops keep taking the mutex lock for the whole > > > > read/write, and this might take very long when the exceptionally high > > > > amount of data is given.  Also, since it invokes with mutex_lock(), > > > > the concurrent read/write becomes unbreakable. > > > > > > > > This patch tries to address these issues by replacing mutex_lock() > > > > with mutex_lock_interruptible(), and also splits / re-takes the lock > > > > at each read/write period chunk, so that it can switch the context > > > > more finely if requested. > > > > > > [...] > > > > @@ -1414,18 +1417,18 @@ static ssize_t snd_pcm_oss_write1(struct > > > >   xfer += tmp; > > > >   if ((substream->f_flags & O_NONBLOCK) != 0 && > > > >       tmp != runtime->oss.period_bytes) > > > > - break; > > > > + tmp = -EAGAIN; > > > >   } > > > > + err: > > > > + mutex_unlock(&runtime->oss.params_lock); > > > > + if (tmp < 0) > > > > + break; > > > >   if (signal_pending(current)) { > > > >   tmp = -ERESTARTSYS; > > > > - goto err; > > > > + break; > > > >   } > > > > + tmp = 0; > > > >   } > > > > - mutex_unlock(&runtime->oss.params_lock); > > > > - return xfer; > > > > - > > > > - err: > > > > - mutex_unlock(&runtime->oss.params_lock); > > > >   return xfer > 0 ? (snd_pcm_sframes_t)xfer : tmp; > > > >  } > > > > > > [...] > > > > > > Some of the "goto err" statements in the loop are conditional on tmp <= > > > 0, but if tmp == 0 this will no longer terminate the loop.  Is that > > > intentional or a bug? > > > > The patch rather fixes the endless loop: the signal_pending() check is > > added after goto err, so that it aborts the loop properly. > > Let me rephrase then: if snd_pcm_oss_write2() returns 0, does that > imply that signal_pending() is true? If there is any other reason that > it could return 0, then this appears to introduce a bug. In some condition (depending on the plugin / conversion and partial write) it may return zero, but practically seen it doesn't happen in the whole this loop. Takashi