All of lore.kernel.org
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	stable@vger.kernel.org, Clemens Ladisch <clemens@ladisch.de>,
	Takashi Sakamoto <o-takashi@sakamocchi.jp>,
	Takashi Iwai <tiwai@suse.de>
Subject: [PATCH 4.9 04/44] ALSA: firewire-lib: Fix stall of process context at packet error
Date: Tue, 27 Jun 2017 16:12:16 +0200	[thread overview]
Message-ID: <20170627141108.072361650@linuxfoundation.org> (raw)
In-Reply-To: <20170627141107.865578528@linuxfoundation.org>

4.9-stable review patch.  If anyone has any objections, please let me know.

------------------

From: Takashi Sakamoto <o-takashi@sakamocchi.jp>

commit 4a9bfafc64f44ef83de4e00ca1b57352af6cd8c2 upstream.

At Linux v3.5, packet processing can be done in process context of ALSA
PCM application as well as software IRQ context for OHCI 1394. Below is
an example of the callgraph (some calls are omitted).

ioctl(2) with e.g. HWSYNC
(sound/core/pcm_native.c)
->snd_pcm_common_ioctl1()
  ->snd_pcm_hwsync()
    ->snd_pcm_stream_lock_irq
    (sound/core/pcm_lib.c)
    ->snd_pcm_update_hw_ptr()
      ->snd_pcm_udpate_hw_ptr0()
        ->struct snd_pcm_ops.pointer()
        (sound/firewire/*)
        = Each handler on drivers in ALSA firewire stack
          (sound/firewire/amdtp-stream.c)
          ->amdtp_stream_pcm_pointer()
            (drivers/firewire/core-iso.c)
            ->fw_iso_context_flush_completions()
              ->struct fw_card_driver.flush_iso_completion()
              (drivers/firewire/ohci.c)
              = flush_iso_completions()
                ->struct fw_iso_context.callback.sc
                (sound/firewire/amdtp-stream.c)
                = in_stream_callback() or out_stream_callback()
                  ->...
    ->snd_pcm_stream_unlock_irq

When packet queueing error occurs or detecting invalid packets in
'in_stream_callback()' or 'out_stream_callback()', 'snd_pcm_stop_xrun()'
is called on local CPU with disabled IRQ.

(sound/firewire/amdtp-stream.c)
in_stream_callback() or out_stream_callback()
->amdtp_stream_pcm_abort()
  ->snd_pcm_stop_xrun()
    ->snd_pcm_stream_lock_irqsave()
    ->snd_pcm_stop()
    ->snd_pcm_stream_unlock_irqrestore()

The process is stalled on the CPU due to attempt to acquire recursive lock.

[  562.630853] INFO: rcu_sched detected stalls on CPUs/tasks:
[  562.630861]      2-...: (1 GPs behind) idle=37d/140000000000000/0 softirq=38323/38323 fqs=7140
[  562.630862]      (detected by 3, t=15002 jiffies, g=21036, c=21035, q=5933)
[  562.630866] Task dump for CPU 2:
[  562.630867] alsa-source-OXF R  running task        0  6619      1 0x00000008
[  562.630870] Call Trace:
[  562.630876]  ? vt_console_print+0x79/0x3e0
[  562.630880]  ? msg_print_text+0x9d/0x100
[  562.630883]  ? up+0x32/0x50
[  562.630885]  ? irq_work_queue+0x8d/0xa0
[  562.630886]  ? console_unlock+0x2b6/0x4b0
[  562.630888]  ? vprintk_emit+0x312/0x4a0
[  562.630892]  ? dev_vprintk_emit+0xbf/0x230
[  562.630895]  ? do_sys_poll+0x37a/0x550
[  562.630897]  ? dev_printk_emit+0x4e/0x70
[  562.630900]  ? __dev_printk+0x3c/0x80
[  562.630903]  ? _raw_spin_lock+0x20/0x30
[  562.630909]  ? snd_pcm_stream_lock+0x31/0x50 [snd_pcm]
[  562.630914]  ? _snd_pcm_stream_lock_irqsave+0x2e/0x40 [snd_pcm]
[  562.630918]  ? snd_pcm_stop_xrun+0x16/0x70 [snd_pcm]
[  562.630922]  ? in_stream_callback+0x3e6/0x450 [snd_firewire_lib]
[  562.630925]  ? handle_ir_packet_per_buffer+0x8e/0x1a0 [firewire_ohci]
[  562.630928]  ? ohci_flush_iso_completions+0xa3/0x130 [firewire_ohci]
[  562.630932]  ? fw_iso_context_flush_completions+0x15/0x20 [firewire_core]
[  562.630935]  ? amdtp_stream_pcm_pointer+0x2d/0x40 [snd_firewire_lib]
[  562.630938]  ? pcm_capture_pointer+0x19/0x20 [snd_oxfw]
[  562.630943]  ? snd_pcm_update_hw_ptr0+0x47/0x3d0 [snd_pcm]
[  562.630945]  ? poll_select_copy_remaining+0x150/0x150
[  562.630947]  ? poll_select_copy_remaining+0x150/0x150
[  562.630952]  ? snd_pcm_update_hw_ptr+0x10/0x20 [snd_pcm]
[  562.630956]  ? snd_pcm_hwsync+0x45/0xb0 [snd_pcm]
[  562.630960]  ? snd_pcm_common_ioctl1+0x1ff/0xc90 [snd_pcm]
[  562.630962]  ? futex_wake+0x90/0x170
[  562.630966]  ? snd_pcm_capture_ioctl1+0x136/0x260 [snd_pcm]
[  562.630970]  ? snd_pcm_capture_ioctl+0x27/0x40 [snd_pcm]
[  562.630972]  ? do_vfs_ioctl+0xa3/0x610
[  562.630974]  ? vfs_read+0x11b/0x130
[  562.630976]  ? SyS_ioctl+0x79/0x90
[  562.630978]  ? entry_SYSCALL_64_fastpath+0x1e/0xad

This commit fixes the above bug. This assumes two cases:
1. Any error is detected in software IRQ context of OHCI 1394 context.
In this case, PCM substream should be aborted in packet handler. On the
other hand, it should not be done in any process context. TO distinguish
these two context, use 'in_interrupt()' macro.
2. Any error is detect in process context of ALSA PCM application.
In this case, PCM substream should not be aborted in packet handler
because PCM substream lock is acquired. The task to abort PCM substream
should be done in ALSA PCM core. For this purpose, SNDRV_PCM_POS_XRUN is
returned at 'struct snd_pcm_ops.pointer()'.

Suggested-by: Clemens Ladisch <clemens@ladisch.de>
Fixes: e9148dddc3c7("ALSA: firewire-lib: flush completed packets when reading PCM position")
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

---
 sound/firewire/amdtp-stream.c |    8 ++++++--
 sound/firewire/amdtp-stream.h |    2 +-
 2 files changed, 7 insertions(+), 3 deletions(-)

--- a/sound/firewire/amdtp-stream.c
+++ b/sound/firewire/amdtp-stream.c
@@ -606,7 +606,9 @@ static void out_stream_callback(struct f
 		cycle = increment_cycle_count(cycle, 1);
 		if (handle_out_packet(s, cycle, i) < 0) {
 			s->packet_index = -1;
-			amdtp_stream_pcm_abort(s);
+			if (in_interrupt())
+				amdtp_stream_pcm_abort(s);
+			WRITE_ONCE(s->pcm_buffer_pointer, SNDRV_PCM_POS_XRUN);
 			return;
 		}
 	}
@@ -658,7 +660,9 @@ static void in_stream_callback(struct fw
 	/* Queueing error or detecting invalid payload. */
 	if (i < packets) {
 		s->packet_index = -1;
-		amdtp_stream_pcm_abort(s);
+		if (in_interrupt())
+			amdtp_stream_pcm_abort(s);
+		WRITE_ONCE(s->pcm_buffer_pointer, SNDRV_PCM_POS_XRUN);
 		return;
 	}
 
--- a/sound/firewire/amdtp-stream.h
+++ b/sound/firewire/amdtp-stream.h
@@ -124,7 +124,7 @@ struct amdtp_stream {
 	/* For a PCM substream processing. */
 	struct snd_pcm_substream *pcm;
 	struct tasklet_struct period_tasklet;
-	unsigned int pcm_buffer_pointer;
+	snd_pcm_uframes_t pcm_buffer_pointer;
 	unsigned int pcm_period_pointer;
 
 	/* To wait for first packet. */

  parent reply	other threads:[~2017-06-27 14:38 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-27 14:12 [PATCH 4.9 00/44] 4.9.35-stable review Greg Kroah-Hartman
2017-06-27 14:12 ` [PATCH 4.9 01/44] clk: sunxi-ng: a31: Correct lcd1-ch1 clock register offset Greg Kroah-Hartman
2017-06-27 14:12 ` [PATCH 4.9 03/44] xen-blkback: dont leak stack data via response ring Greg Kroah-Hartman
2017-06-27 14:12 ` Greg Kroah-Hartman [this message]
2017-06-27 14:12 ` [PATCH 4.9 05/44] ALSA: pcm: Dont treat NULL chmap as a fatal error Greg Kroah-Hartman
2017-06-27 14:12 ` [PATCH 4.9 06/44] fs/exec.c: account for argv/envp pointers Greg Kroah-Hartman
2017-06-27 14:12 ` [PATCH 4.9 07/44] powerpc/perf: Fix oops when kthread execs user process Greg Kroah-Hartman
2017-06-27 14:12 ` [PATCH 4.9 08/44] autofs: sanity check status reported with AUTOFS_DEV_IOCTL_FAIL Greg Kroah-Hartman
2017-06-27 14:12 ` [PATCH 4.9 09/44] lib/cmdline.c: fix get_options() overflow while parsing ranges Greg Kroah-Hartman
2017-06-27 14:12 ` [PATCH 4.9 10/44] perf/x86/intel: Add 1G DTLB load/store miss support for SKL Greg Kroah-Hartman
2017-06-27 14:12 ` [PATCH 4.9 11/44] KVM: s390: gaccess: fix real-space designation asce handling for gmap shadows Greg Kroah-Hartman
2017-06-27 14:12 ` [PATCH 4.9 12/44] KVM: PPC: Book3S HV: Preserve userspace HTM state properly Greg Kroah-Hartman
2017-06-27 14:12 ` [PATCH 4.9 13/44] KVM: PPC: Book3S HV: Context-switch EBB registers properly Greg Kroah-Hartman
2017-06-27 14:12 ` [PATCH 4.9 14/44] CIFS: Improve readdir verbosity Greg Kroah-Hartman
2017-06-27 14:12 ` [PATCH 4.9 15/44] cxgb4: notify uP to route ctrlq compl to rdma rspq Greg Kroah-Hartman
2017-06-27 14:12 ` [PATCH 4.9 16/44] HID: Add quirk for Dell PIXART OEM mouse Greg Kroah-Hartman
2017-06-27 14:12 ` [PATCH 4.9 17/44] signal: Only reschedule timers on signals timers have sent Greg Kroah-Hartman
2017-06-27 14:12 ` [PATCH 4.9 18/44] powerpc/kprobes: Pause function_graph tracing during jprobes handling Greg Kroah-Hartman
2017-06-27 14:12 ` [PATCH 4.9 19/44] powerpc/64s: Handle data breakpoints in Radix mode Greg Kroah-Hartman
2017-06-27 14:12 ` [PATCH 4.9 20/44] Input: i8042 - add Fujitsu Lifebook AH544 to notimeout list Greg Kroah-Hartman
2017-06-27 14:12 ` [PATCH 4.9 21/44] brcmfmac: add parameter to pass error code in firmware callback Greg Kroah-Hartman
2017-06-27 14:12 ` [PATCH 4.9 22/44] brcmfmac: use firmware callback upon failure to load Greg Kroah-Hartman
2017-06-27 14:12 ` [PATCH 4.9 23/44] brcmfmac: unbind all devices upon failure in firmware callback Greg Kroah-Hartman
2017-06-27 14:12 ` [PATCH 4.9 24/44] time: Fix clock->read(clock) race around clocksource changes Greg Kroah-Hartman
2017-06-27 14:12 ` [PATCH 4.9 25/44] time: Fix CLOCK_MONOTONIC_RAW sub-nanosecond accounting Greg Kroah-Hartman
2017-06-27 14:12 ` [PATCH 4.9 26/44] arm64/vdso: Fix nsec handling for CLOCK_MONOTONIC_RAW Greg Kroah-Hartman
2017-06-27 14:12 ` [PATCH 4.9 27/44] target: Fix kref->refcount underflow in transport_cmd_finish_abort Greg Kroah-Hartman
2017-06-27 14:12 ` [PATCH 4.9 28/44] iscsi-target: Fix delayed logout processing greater than SECONDS_FOR_LOGOUT_COMP Greg Kroah-Hartman
2017-06-27 14:12 ` [PATCH 4.9 29/44] iscsi-target: Reject immediate data underflow larger than SCSI transfer length Greg Kroah-Hartman
2017-06-27 14:12 ` [PATCH 4.9 30/44] drm/radeon: add a PX quirk for another K53TK variant Greg Kroah-Hartman
2017-06-27 14:12 ` [PATCH 4.9 31/44] drm/radeon: add a quirk for Toshiba Satellite L20-183 Greg Kroah-Hartman
2017-06-27 14:12 ` [PATCH 4.9 35/44] of: Add check to of_scan_flat_dt() before accessing initial_boot_params Greg Kroah-Hartman
2017-06-27 14:12 ` [PATCH 4.9 37/44] usb: gadget: f_fs: avoid out of bounds access on comp_desc Greg Kroah-Hartman
2017-06-27 14:12 ` [PATCH 4.9 38/44] rt2x00: avoid introducing a USB dependency in the rt2x00lib module Greg Kroah-Hartman
2017-06-27 14:12 ` [PATCH 4.9 39/44] net: phy: Initialize mdio clock at probe function Greg Kroah-Hartman
2017-06-27 14:12   ` Greg Kroah-Hartman
2017-06-27 14:12 ` [PATCH 4.9 40/44] dmaengine: bcm2835: Fix cyclic DMA period splitting Greg Kroah-Hartman
2017-06-27 14:12 ` [PATCH 4.9 41/44] spi: double time out tolerance Greg Kroah-Hartman
2017-06-27 14:12 ` [PATCH 4.9 42/44] net: phy: fix marvell phy status reading Greg Kroah-Hartman
2017-06-27 14:12 ` [PATCH 4.9 43/44] jump label: fix passing kbuild_cflags when checking for asm goto support Greg Kroah-Hartman
2017-06-27 14:12 ` [PATCH 4.9 44/44] brcmfmac: fix uninitialized warning in brcmf_usb_probe_phase2() Greg Kroah-Hartman
2017-06-27 17:29 ` [PATCH 4.9 00/44] 4.9.35-stable review Sumit Semwal
2017-06-28 12:03   ` Greg Kroah-Hartman
     [not found] ` <59529e31.06d41c0a.2fd63.4a34@mx.google.com>
2017-06-27 18:32   ` Greg Kroah-Hartman
2017-06-27 19:03 ` Guenter Roeck
2017-06-28 13:53 ` Shuah Khan

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=20170627141108.072361650@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=clemens@ladisch.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=o-takashi@sakamocchi.jp \
    --cc=stable@vger.kernel.org \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.