Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp4588461yba; Tue, 30 Apr 2019 00:33:53 -0700 (PDT) X-Google-Smtp-Source: APXvYqzmYbhPTNj3dpsqmIJmrb5+cu5ZQetaoK5R75TDy7OReq+GYgp4W4iJsyBmEhcF34epuwJH X-Received: by 2002:a17:902:820c:: with SMTP id x12mr65388036pln.199.1556609633083; Tue, 30 Apr 2019 00:33:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556609633; cv=none; d=google.com; s=arc-20160816; b=Vyv7KEVQyegkNtBKUR6gUl1B3VXuD3Ev7B7boey3MJD+Lc831ZuER1eYKbuiKki0x3 ab5KckEUsHJQrdA/AZW0sKhYg6KfxZu1gygZDT+oSXaoweqKcAYq8rhy1KfEvvFO12g7 lKne+C24uP9TFxz5N8jtn7eae73D24gmfr3TMQnvAQAng9iYSTXn55tquLhHyqD5pita q5KjxOxCq5ut9JixcdoPHt6RAPKWIGaL0pSSuGR3Wt9PrdMSg3JGaZC+QBnA3m+whuWB wpZqSlE7ORwpsBbQgYd6QSvFPSWeTQXsvh9cMuHyanU+JgH81gVnE10g+t0+O0sCgyPd +8AA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:subject:cc:to:from:message-id:date; bh=pCFYqwFjE5Hpqeaoq4muD3p6/qVPOEVGc6cmPYMaoP8=; b=xiLBq4aGUR1YpkXXtUWu7+Frlz5qFIFV9gnY1yhsMbLL48C6svsQgyjUeaVicMHLqQ NbidYGcvcngyuf137tEN4Rk8T8hdlLFyosL8UQy8BzYKS666DxHatZlpMooDo24xQP/4 ac+dokVeFuRlfKZNVYnw4xvA05IX8I6hzWfHDVLGAjW2YrZavThDZX7frqPXCi0btMZ+ wz53h7VXQHwi9O8pK6KAzZ3lZpwWoWOOgDIBcSSiMNgmTyW1yVlCwQiypIdQw8eAcScb iVh/yvE5CGw2XHJjQWqJBZVt+8I+wMFjwqeITMDFqqvPRDBEzPpNffSlCCH3VSPHjMGH fZ7A== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k3si37313855pfc.91.2019.04.30.00.33.37; Tue, 30 Apr 2019 00:33:53 -0700 (PDT) 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726458AbfD3Hbf (ORCPT + 99 others); Tue, 30 Apr 2019 03:31:35 -0400 Received: from mx2.suse.de ([195.135.220.15]:47374 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725769AbfD3Hbe (ORCPT ); Tue, 30 Apr 2019 03:31:34 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 67FF2AE00; Tue, 30 Apr 2019 07:31:33 +0000 (UTC) Date: Tue, 30 Apr 2019 09:31:32 +0200 Message-ID: From: Takashi Iwai To: "Song liwei" Cc: , "Yu Zhao" , "Mark Brown" , "Keyon Jie" , "Jaroslav Kysela" , "linux-kernel" Subject: Re: [PATCH] ALSA: hda: check RIRB to avoid use NULL pointer In-Reply-To: <1556604653-47363-1-git-send-email-liwei.song@windriver.com> References: <1556604653-47363-1-git-send-email-liwei.song@windriver.com> 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=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 30 Apr 2019 08:10:53 +0200, Song liwei wrote: > > From: Liwei Song > > Fix the following BUG: > > BUG: unable to handle kernel NULL pointer dereference at 000000000000000c > Workqueue: events azx_probe_work [snd_hda_intel] > RIP: 0010:snd_hdac_bus_update_rirb+0x80/0x160 [snd_hda_core] > Call Trace: > > azx_interrupt+0x78/0x140 [snd_hda_codec] > __handle_irq_event_percpu+0x49/0x300 > handle_irq_event_percpu+0x23/0x60 > handle_irq_event+0x3c/0x60 > handle_edge_irq+0xdb/0x180 > handle_irq+0x23/0x30 > do_IRQ+0x6a/0x140 > common_interrupt+0xf/0xf > > The Call Trace happened when run kdump on a NFS rootfs system. > Exist the following calling sequence when boot the second kernel: > > azx_first_init() > --> azx_acquire_irq() > <-- interrupt come in, azx_interrupt() was called > --> hda_intel_init_chip() > --> azx_init_chip() > --> snd_hdac_bus_init_chip() > --> snd_hdac_bus_init_cmd_io(); > --> init rirb.buf and corb.buf > > Interrupt happened after azx_acquire_irq() while RIRB still didn't got > initialized, then NULL pointer will be used when process the interrupt. > > Check the value of RIRB to ensure it is not NULL, to aviod some special > case may hang the system. > > Fixes: 14752412721c ("ALSA: hda - Add the controller helper codes to hda-core module") > Signed-off-by: Liwei Song Oh, that's indeed a race there. But I guess the check introduced by the patch is still error-prone. Basically the interrupt handling should be moved after the chip initialization. I suppose that your platform uses the shared interrupt, not the MSI? In anyway, alternative (and likely more certain) fix would be to move the azx_acquir_irq() call like the patch below (note: totally untested). Could you check whether it works? thanks, Takashi --- a/sound/pci/hda/hda_intel.c +++ b/sound/pci/hda/hda_intel.c @@ -1788,9 +1788,6 @@ static int azx_first_init(struct azx *chip) chip->msi = 0; } - if (azx_acquire_irq(chip, 0) < 0) - return -EBUSY; - pci_set_master(pci); synchronize_irq(bus->irq); @@ -1904,6 +1901,9 @@ static int azx_first_init(struct azx *chip) return -ENODEV; } + if (azx_acquire_irq(chip, 0) < 0) + return -EBUSY; + strcpy(card->driver, "HDA-Intel"); strlcpy(card->shortname, driver_short_names[chip->driver_type], sizeof(card->shortname));