Received: by 10.223.185.116 with SMTP id b49csp882031wrg; Wed, 14 Feb 2018 08:21:50 -0800 (PST) X-Google-Smtp-Source: AH8x227aG8C1vi4ZAxxraPrYgg8pGRJHjxK4oYqVFEPglrG2oTviKGIEM/SO+w2g1iVelcbR9O6I X-Received: by 2002:a17:902:2c83:: with SMTP id n3-v6mr5096535plb.227.1518625310128; Wed, 14 Feb 2018 08:21:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518625310; cv=none; d=google.com; s=arc-20160816; b=Ah69WlLdAgCGbhGKe1rNP0GNehaTy5WAuH5TZQ7HPFHeIof+mxrbAgBMbzhq/YfP2+ 99e0L+hBwjq8EW5godcRpc0/to74TO0qrHgJrgjYFJhu+0DJzqlntkfXUP6mzCbzX2P9 cAWKETaaRWnlHyWUVKXdad9Fp5IcO+F/6+NNHrPXzfoiar0gT05DiB/OEYRdaxgsgqSH 4IN3Fw7gk3Om5BmwDsaYYa8Do8Gx922JbAkGo29pnBazPt7bPAM+IPd8hGTSS4wVZz0K Qcn2b0nQE4C/4ZO7nZlWnAca56VxxoX5y2z/Ik/s03ymMzP92WoY+Em9q17WhJQTxyPK 7SZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :organization:references:in-reply-to:date:cc:to:from:subject :message-id:arc-authentication-results; bh=vdrvJRGadUbGDZ4Z74E5eYspCYNSVQwkXNmZ4/+fuf8=; b=fFxiDNCiY60BVCNsNvEmPuaUW/nm6UMRHTLrh3FO9flGjoET42Iv7yB+Kluhp/Qtmk ecsmaRu7gVdIbf76PtrXFZYqwc0nRPQTREF4bwm2+PnkDkOvo6TvSUqRLt9Y5l6wkzat ZnkC1bdYpkVcsae8dRaOWaEf5FF0pVZaQOlPjITEvhh+GBDmVeD9lF/9xTOdy6YdP4SO UzBqqkcfM7NOjsfkc+2B+JfXfGbf8SPBE4e+JC2TvB4MJHal4yyMf7m4xQ5YJetImRVQ Tnu8bIdVUHz997bdCPW2Y38Q4TtcNpTFG3K7nJKc1Yog4gs9mk0qWdzGTVy6yMxwsBNp xkDQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=codethink.co.uk Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f4-v6si1256165plm.163.2018.02.14.08.21.34; Wed, 14 Feb 2018 08:21:50 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=codethink.co.uk Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1032360AbeBNQU2 (ORCPT + 99 others); Wed, 14 Feb 2018 11:20:28 -0500 Received: from imap1.codethink.co.uk ([176.9.8.82]:55252 "EHLO imap1.codethink.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1032203AbeBNQU0 (ORCPT ); Wed, 14 Feb 2018 11:20:26 -0500 Received: from [167.98.27.229] (helo=xylophone) by imap1.codethink.co.uk with esmtpsa (Exim 4.84_2 #1 (Debian)) id 1elznH-00066T-S8; Wed, 14 Feb 2018 16:20:28 +0000 Message-ID: <1518625223.3422.19.camel@codethink.co.uk> Subject: Re: [PATCH 4.4 20/87] ALSA: pcm: Allow aborting mutex lock at OSS read/write loops From: Ben Hutchings To: Takashi Iwai Cc: stable@vger.kernel.org, Greg Kroah-Hartman , LKML Date: Wed, 14 Feb 2018 16:20:23 +0000 In-Reply-To: References: <20180115123349.252309699@linuxfoundation.org> <20180115123351.309626066@linuxfoundation.org> <1516750548.3417.34.camel@codethink.co.uk> Organization: Codethink Ltd. Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.22.6-1+deb9u1 Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Ben. -- Ben Hutchings Software Developer, Codethink Ltd.