Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp3209811pxb; Mon, 9 Nov 2020 05:40:10 -0800 (PST) X-Google-Smtp-Source: ABdhPJyro5xggXlF9YJ+NCmOLcAfKfkuef0ncqPwmgdGt0QUX9jIPzSLWFBrDtmgp6Kc7CiMkvmG X-Received: by 2002:a17:906:7247:: with SMTP id n7mr14788600ejk.174.1604929210378; Mon, 09 Nov 2020 05:40:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604929210; cv=none; d=google.com; s=arc-20160816; b=de66J7VY8rHj60oZlVEE3NqscN8AOxReUFGOQR7F5hkT7ijsFaR8XmkYhlPQ8nYTwK F0fgCq1AalbjTmqbIjhOKeMmaDe3+OqmJEnz07wKPopAJTk4iNP8O/5D7SIWtLLKsjV7 /xFxKgx26WiowwAEfUZ4nrGW9CBO4gqh10OyybfN0Zbv3Wx7XdRhIRlTyejxroLLkCYz /KXzv5dCErHCbvwYTIDQBSQD83SOxh2dXprFZaXJmRKPpK+sVIzRxnMzpdF6uyTcohMR daHzkDAWLn8z5LbgZplD6/Y8EAdUQY+eLCXk48dH0BNFYxAfMkpUSmgGho0Sy+4MaLIa qjbA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=NIjVl8DIMkkMedaiLS2FJGM4lVhaUoD+yBkaeYko8Cc=; b=VGHKPniWjxOhvWNYwzBIhx2NWHbCLXhfY2aRZw6Ele/nzxi1BCYRub2IzDZtQ6zb1m szh3AWPU/ooVyJJ/UCHfW2kLkPWxL+CJtjBYoUlr6GxfPAjmyI5xmTzRTGORatKc1hrj 78pXICAao9YmWJMF0aoLApONDgvctBPM8v8rlLrAbNLxZDeGO79J2Dbu/lWsigRxMqDV r7lGRQU2gCEV6a2KNNlb8CJz/Tb1nix9LWplPc5dyZK+Mess661RukgCZ85/87Bxo9td ENyx5ZzPBGlZhbzFg6WSTj3KznxGWEzwQ5arJ8J7gJNINxRg8lC7aAjxdfPicEGW5Xqo q5iw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ds8ATcy1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n15si7834245eje.742.2020.11.09.05.39.43; Mon, 09 Nov 2020 05:40:10 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ds8ATcy1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731927AbgKINg1 (ORCPT + 99 others); Mon, 9 Nov 2020 08:36:27 -0500 Received: from mail.kernel.org ([198.145.29.99]:57668 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729661AbgKINEp (ORCPT ); Mon, 9 Nov 2020 08:04:45 -0500 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 79D8F20663; Mon, 9 Nov 2020 13:04:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604927085; bh=SCX2Bvt7RIbKtlNwma4O1ggwwDDo9Fw7byanKlpDy2E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ds8ATcy1wa7G5IPRuADtBrAPTmgMLuMx4q5Wphjq4iWgyfbCI+uRbN6WHEczrTFRp AT7CI/8CHkyTRForw4GooTn2rUhQSSAseHrERrMQDVlrw25XG/+fEDhD748kMzTHva OACxblIBlq5BlZIcKl40v8itGRhmVqVYjk7qt6LA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Christoph Hellwig , "Ewan D. Milne" , Hannes Reinecke , Bart Van Assche , Lee Duncan , Ming Lei , "Martin K. Petersen" , Sasha Levin Subject: [PATCH 4.9 105/117] scsi: core: Dont start concurrent async scan on same host Date: Mon, 9 Nov 2020 13:55:31 +0100 Message-Id: <20201109125030.680000430@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201109125025.630721781@linuxfoundation.org> References: <20201109125025.630721781@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ming Lei [ Upstream commit 831e3405c2a344018a18fcc2665acc5a38c3a707 ] The current scanning mechanism is supposed to fall back to a synchronous host scan if an asynchronous scan is in progress. However, this rule isn't strictly respected, scsi_prep_async_scan() doesn't hold scan_mutex when checking shost->async_scan. When scsi_scan_host() is called concurrently, two async scans on same host can be started and a hang in do_scan_async() is observed. Fixes this issue by checking & setting shost->async_scan atomically with shost->scan_mutex. Link: https://lore.kernel.org/r/20201010032539.426615-1-ming.lei@redhat.com Cc: Christoph Hellwig Cc: Ewan D. Milne Cc: Hannes Reinecke Cc: Bart Van Assche Reviewed-by: Lee Duncan Reviewed-by: Bart Van Assche Signed-off-by: Ming Lei Signed-off-by: Martin K. Petersen Signed-off-by: Sasha Levin --- drivers/scsi/scsi_scan.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/scsi/scsi_scan.c b/drivers/scsi/scsi_scan.c index 67f6f134abc44..397deb69c6595 100644 --- a/drivers/scsi/scsi_scan.c +++ b/drivers/scsi/scsi_scan.c @@ -1734,15 +1734,16 @@ static void scsi_sysfs_add_devices(struct Scsi_Host *shost) */ static struct async_scan_data *scsi_prep_async_scan(struct Scsi_Host *shost) { - struct async_scan_data *data; + struct async_scan_data *data = NULL; unsigned long flags; if (strncmp(scsi_scan_type, "sync", 4) == 0) return NULL; + mutex_lock(&shost->scan_mutex); if (shost->async_scan) { shost_printk(KERN_DEBUG, shost, "%s called twice\n", __func__); - return NULL; + goto err; } data = kmalloc(sizeof(*data), GFP_KERNEL); @@ -1753,7 +1754,6 @@ static struct async_scan_data *scsi_prep_async_scan(struct Scsi_Host *shost) goto err; init_completion(&data->prev_finished); - mutex_lock(&shost->scan_mutex); spin_lock_irqsave(shost->host_lock, flags); shost->async_scan = 1; spin_unlock_irqrestore(shost->host_lock, flags); @@ -1768,6 +1768,7 @@ static struct async_scan_data *scsi_prep_async_scan(struct Scsi_Host *shost) return data; err: + mutex_unlock(&shost->scan_mutex); kfree(data); return NULL; } -- 2.27.0