From patchwork Wed Nov 14 14:40:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Iwai X-Patchwork-Id: 997778 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-ide-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.de Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 42w6cS2jCXz9s5c for ; Thu, 15 Nov 2018 01:40:56 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726295AbeKOAoZ (ORCPT ); Wed, 14 Nov 2018 19:44:25 -0500 Received: from mx2.suse.de ([195.135.220.15]:37242 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725828AbeKOAoZ (ORCPT ); Wed, 14 Nov 2018 19:44:25 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id B8A68B0ED; Wed, 14 Nov 2018 14:40:53 +0000 (UTC) From: Takashi Iwai To: Jens Axboe Cc: linux-ide@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] ata: Fix racy link clearance Date: Wed, 14 Nov 2018 15:40:50 +0100 Message-Id: <20181114144050.12630-1-tiwai@suse.de> X-Mailer: git-send-email 2.19.1 MIME-Version: 1.0 Sender: linux-ide-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ide@vger.kernel.org The ap->sff_pio_task_link gets cleared in a racy way in ata_sff_flush_pio_task(). This may lead to BUG_ON() check in the work, and screw up the whole system. Along with it, replace BUG_ON() with WARN_ON() and let the work quit gracefully. It's no end of the world, after all. Signed-off-by: Takashi Iwai --- drivers/ata/libata-sff.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/ata/libata-sff.c b/drivers/ata/libata-sff.c index c5ea0fc635e5..28ef46ef656d 100644 --- a/drivers/ata/libata-sff.c +++ b/drivers/ata/libata-sff.c @@ -1271,9 +1271,8 @@ void ata_sff_flush_pio_task(struct ata_port *ap) */ spin_lock_irq(ap->lock); ap->hsm_task_state = HSM_ST_IDLE; - spin_unlock_irq(ap->lock); - ap->sff_pio_task_link = NULL; + spin_unlock_irq(ap->lock); if (ata_msg_ctl(ap)) ata_port_dbg(ap, "%s: EXIT\n", __func__); @@ -1283,14 +1282,17 @@ static void ata_sff_pio_task(struct work_struct *work) { struct ata_port *ap = container_of(work, struct ata_port, sff_pio_task.work); - struct ata_link *link = ap->sff_pio_task_link; + struct ata_link *link; struct ata_queued_cmd *qc; u8 status; int poll_next; spin_lock_irq(ap->lock); - BUG_ON(ap->sff_pio_task_link == NULL); + link = ap->sff_pio_task_link; + if (WARN_ON(!link)) + goto out_unlock; + /* qc can be NULL if timeout occurred */ qc = ata_qc_from_tag(ap, link->active_tag); if (!qc) {