From patchwork Wed Feb 15 19:15:50 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?VmlsbGUgU3lyasOkbMOk?= X-Patchwork-Id: 9574839 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 4CAC260493 for ; Wed, 15 Feb 2017 19:16:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3A6C7284DA for ; Wed, 15 Feb 2017 19:16:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2EBC228506; Wed, 15 Feb 2017 19:16:07 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE autolearn=unavailable version=3.3.1 Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1D02A284F7 for ; Wed, 15 Feb 2017 19:16:05 +0000 (UTC) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id 1EDFE266D08; Wed, 15 Feb 2017 20:16:03 +0100 (CET) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id 03E59266D09; Wed, 15 Feb 2017 20:16:00 +0100 (CET) Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by alsa0.perex.cz (Postfix) with ESMTP id 0274A265142 for ; Wed, 15 Feb 2017 20:15:56 +0100 (CET) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 15 Feb 2017 11:15:53 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos; i="5.35,166,1484035200"; d="scan'208"; a="1127146816" Received: from stinkbox.fi.intel.com (HELO stinkbox) ([10.237.72.174]) by fmsmga002.fm.intel.com with SMTP; 15 Feb 2017 11:15:50 -0800 Received: by stinkbox (sSMTP sendmail emulation); Wed, 15 Feb 2017 21:15:50 +0200 From: ville.syrjala@linux.intel.com To: alsa-devel@alsa-project.org Date: Wed, 15 Feb 2017 21:15:50 +0200 Message-Id: <20170215191550.8790-1-ville.syrjala@linux.intel.com> X-Mailer: git-send-email 2.10.2 MIME-Version: 1.0 Cc: Takashi Iwai , intel-gfx@lists.freedesktop.org, Pierre-Louis Bossart Subject: [alsa-devel] [PATCH] ALSA: x86: Fix spinlock usage in the trigger callback X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP From: Ville Syrjälä Simply doing 'xset dpms force off' while playback is active seems sufficient to anger lockdep [1]. And it's of course correct that it's not safe to use regular spin_lock() outside the irq handler when the irq handler also wants to acquire the same lock. I believe the trigger callback can get called from both irq and non-irq context, so we need to to use spin_lock_irqsave() & co. here. The whole locking here looks somewhat suspicious, but I don't feel like digging into further, so here's just the minimal fix. [1] [ 168.303913] [drm:ilk_audio_codec_disable [i915]] Disable audio codec on port B, pipe B [ 168.306245] ================================= [ 168.311110] [ INFO: inconsistent lock state ] [ 168.315975] 4.10.0-rc8-ffrd+ #698 Tainted: G W [ 168.322198] --------------------------------- [ 168.327062] inconsistent {IN-HARDIRQ-W} -> {HARDIRQ-ON-W} usage. [ 168.333773] kworker/2:1/44 [HC0[0]:SC0[0]:HE1:SE1] takes: [ 168.339802] (&(&ctx->had_spinlock)->rlock){?.-...}, at: [] had_pcm_trigger+0x60/0x160 [snd_hdmi_lpe_audio] [ 168.352449] {IN-HARDIRQ-W} state was registered at: [ 168.357901] __lock_acquire+0x7b2/0x16c0 [ 168.362378] lock_acquire+0xba/0x220 [ 168.366468] _raw_spin_lock_irqsave+0x47/0x60 [ 168.371431] had_substream_get+0x23/0x50 [snd_hdmi_lpe_audio] [ 168.377950] display_pipe_interrupt_handler+0x78/0x1a0 [snd_hdmi_lpe_audio] [ 168.385828] __handle_irq_event_percpu+0x3f/0x3a0 [ 168.391180] handle_irq_event_percpu+0x24/0x60 [ 168.396239] handle_irq_event+0x3a/0x60 [ 168.400619] handle_simple_irq+0x79/0xa0 [ 168.405096] generic_handle_irq+0x22/0x30 [ 168.409718] intel_lpe_audio_irq_handler+0x24/0x80 [i915] [ 168.415878] valleyview_irq_handler+0x1da/0x230 [i915] [ 168.421715] __handle_irq_event_percpu+0x3f/0x3a0 [ 168.427067] handle_irq_event_percpu+0x24/0x60 [ 168.432126] handle_irq_event+0x3a/0x60 [ 168.436505] handle_edge_irq+0x94/0x150 [ 168.440886] handle_irq+0xb3/0x190 [ 168.444781] do_IRQ+0x69/0x130 [ 168.448287] ret_from_intr+0x0/0x19 [ 168.452280] cpuidle_enter_state+0xdb/0x360 [ 168.457047] cpuidle_enter+0x17/0x20 [ 168.461136] call_cpuidle+0x23/0x40 [ 168.465126] do_idle+0x18a/0x200 [ 168.468826] cpu_startup_entry+0x1d/0x30 [ 168.473303] rest_init+0x12c/0x140 [ 168.477200] start_kernel+0x402/0x40f [ 168.481385] x86_64_start_reservations+0x2a/0x2c [ 168.486640] x86_64_start_kernel+0xea/0xed [ 168.491313] verify_cpu+0x0/0xfc [ 168.495012] irq event stamp: 28481 [ 168.498810] hardirqs last enabled at (28481): [] _raw_spin_unlock_irq+0x2c/0x60 [ 168.508824] hardirqs last disabled at (28480): [] _raw_spin_lock_irq+0x18/0x60 [ 168.518645] softirqs last enabled at (28442): [] neigh_periodic_work+0x219/0x320 [ 168.528755] softirqs last disabled at (28438): [] neigh_periodic_work+0x39/0x320 [ 168.538767] other info that might help us debug this: [ 168.546052] Possible unsafe locking scenario: [ 168.552664] CPU0 [ 168.555390] ---- [ 168.558116] lock(&(&ctx->had_spinlock)->rlock); [ 168.563371] [ 168.566291] lock(&(&ctx->had_spinlock)->rlock); [ 168.571741] *** DEADLOCK *** [ 168.578355] 3 locks held by kworker/2:1/44: [ 168.583025] #0: ("events"){.+.+.+}, at: [] process_one_work+0x15f/0x6e0 [ 168.592357] #1: ((&ctx->hdmi_audio_wq)){+.+.+.}, at: [] process_one_work+0x15f/0x6e0 [ 168.602959] #2: (&ctx->mutex){+.+.+.}, at: [] had_audio_wq+0x48/0x6de [snd_hdmi_lpe_audio] [ 168.614145] stack backtrace: [ 168.619011] CPU: 2 PID: 44 Comm: kworker/2:1 Tainted: G W 4.10.0-rc8-ffrd+ #698 [ 168.628441] Hardware name: Intel Corp. VALLEYVIEW C0 PLATFORM/BYT-T FFD8, BIOS BLAKFF81.X64.0088.R10.1403240443 FFD8_X64_R_2014_13_1_00 03/24/2014 [ 168.643111] Workqueue: events had_audio_wq [snd_hdmi_lpe_audio] [ 168.649725] Call Trace: [ 168.652448] dump_stack+0x67/0x90 [ 168.656149] print_usage_bug+0x20b/0x210 [ 168.660530] mark_lock+0x648/0x6c0 [ 168.664328] ? print_shortest_lock_dependencies+0x1d0/0x1d0 [ 168.670553] __lock_acquire+0x638/0x16c0 [ 168.674935] lock_acquire+0xba/0x220 [ 168.678929] ? had_pcm_trigger+0x60/0x160 [snd_hdmi_lpe_audio] [ 168.685447] _raw_spin_lock+0x3f/0x50 [ 168.689536] ? had_pcm_trigger+0x60/0x160 [snd_hdmi_lpe_audio] [ 168.696054] had_pcm_trigger+0x60/0x160 [snd_hdmi_lpe_audio] [ 168.702383] snd_pcm_do_stop+0x45/0x50 [snd_pcm] [ 168.707545] snd_pcm_action_single+0x32/0x80 [snd_pcm] [ 168.713289] snd_pcm_action+0x118/0x120 [snd_pcm] [ 168.718549] snd_pcm_stop+0x1a/0x20 [snd_pcm] [ 168.723415] had_audio_wq+0x35e/0x6de [snd_hdmi_lpe_audio] [ 168.729545] process_one_work+0x1eb/0x6e0 [ 168.734022] ? process_one_work+0x15f/0x6e0 [ 168.738693] worker_thread+0x4f/0x4a0 [ 168.742781] ? schedule+0x4a/0x90 [ 168.746483] ? preempt_count_sub+0xa6/0x110 [ 168.751154] kthread+0x10e/0x150 [ 168.754757] ? apply_wqattrs_commit+0x90/0x90 [ 168.759621] ? kthread_create_on_node+0x40/0x40 [ 168.764681] ? umh_complete+0x30/0x30 [ 168.768770] ? call_usermodehelper_exec_async+0x13a/0x150 [ 168.774802] ret_from_fork+0x2e/0x40 [ 168.779412] [drm:intel_disable_pipe [i915]] disabling pipe B Cc: Takashi Iwai Cc: Pierre-Louis Bossart Signed-off-by: Ville Syrjälä Reviewed-by: Chris Wilson --- sound/x86/intel_hdmi_audio.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sound/x86/intel_hdmi_audio.c b/sound/x86/intel_hdmi_audio.c index c0a080e5d1f4..2748766b3f25 100644 --- a/sound/x86/intel_hdmi_audio.c +++ b/sound/x86/intel_hdmi_audio.c @@ -1154,6 +1154,7 @@ static int had_pcm_hw_free(struct snd_pcm_substream *substream) static int had_pcm_trigger(struct snd_pcm_substream *substream, int cmd) { int retval = 0; + unsigned long flags; struct snd_intelhad *intelhaddata; intelhaddata = snd_pcm_substream_chip(substream); @@ -1180,12 +1181,12 @@ static int had_pcm_trigger(struct snd_pcm_substream *substream, int cmd) case SNDRV_PCM_TRIGGER_STOP: case SNDRV_PCM_TRIGGER_PAUSE_PUSH: case SNDRV_PCM_TRIGGER_SUSPEND: - spin_lock(&intelhaddata->had_spinlock); + spin_lock_irqsave(&intelhaddata->had_spinlock, flags); /* Stop reporting BUFFER_DONE/UNDERRUN to above layers */ intelhaddata->stream_info.running = false; - spin_unlock(&intelhaddata->had_spinlock); + spin_unlock_irqrestore(&intelhaddata->had_spinlock, flags); /* Disable Audio */ had_enable_audio(intelhaddata, false); /* Reset buffer pointers */