Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp3197923pxb; Mon, 9 Nov 2020 05:23:31 -0800 (PST) X-Google-Smtp-Source: ABdhPJzdIrtQCLp0aRTgWB+bVIEDWpvmvTztrAC7huZsJ28tuhxiuyPxWFjjR9OlpNgS7qPRrFmE X-Received: by 2002:a17:906:fa1b:: with SMTP id lo27mr14706255ejb.216.1604928211357; Mon, 09 Nov 2020 05:23:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604928211; cv=none; d=google.com; s=arc-20160816; b=Nh+8jO1JLbFtOkfCZ1CLaPmTHV1qz+BktZABRcRjxTaKyeC9nQWfYZy0biC6nHEYDf +kqmblpTnHXYcyLNbjQA50O0e9MW9O80mRgYuC+nCxgGj4A+CAPNrF6hNFhnLSibBSyL MujzETp+XQ4qxWQvnju1qKT25/SMt9BlL8Dl0/v1xRiJgdz7oYwT6DP4kAEb+96iaIib p/Ynm/qFCUdiXEygPJ1bo43pu9yi8pQdJpKYX0b0v1CBogbZexi7xR280efgZWUPvaML DSVIIT7JCpScgbeq4+tsCkptCnpt7Df7edb5Dq/LIUzu9vj5jgPby4mbFvgSHVM8FEy0 u3Mw== 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=UMGsX8aX+u6HopO5jXAp3Ee4sQgcHMb0zGf44DIYMDw=; b=mbMAFaOrcMcUZSrNDPp1nw1khEabypaP3mMd/MbM4+217uAPLwLyGuvxXqA1D020bR pQN/5pxM5TCB1dqZurB3FzvgPW/4LUorFx8LD2tG/GySLewUsLPWhHahQ1I25EzlJb5H n5hycjIIMoQ8sRDepZM4uXSKCKuJfa+iwZFkqFYuGrradY2X6RW6SMmPj4GgTnJ9qb/q +6V17JdD4MupnJ8C6BtQ1xCkD1z+Fu5PGkUyVyyNIG6YBc3ZW+aTHChHqRM794Qqrtk4 6bMh8e+VNTiVucV4/C9Y54dKYDHvSOTLmhOrIpUNLN8XLSkviZakqUanf1NVNa0sXTE5 90sg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=K5ULh+w2; 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 61si7205551edc.400.2020.11.09.05.23.08; Mon, 09 Nov 2020 05:23:31 -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=K5ULh+w2; 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 S2387846AbgKINTv (ORCPT + 99 others); Mon, 9 Nov 2020 08:19:51 -0500 Received: from mail.kernel.org ([198.145.29.99]:47310 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387837AbgKINTu (ORCPT ); Mon, 9 Nov 2020 08:19:50 -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 DB2F522203; Mon, 9 Nov 2020 13:19:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604927989; bh=nC8cboVWH1YROKvwVzP82ppAtTQk2sOk7bmIlq4ryLM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=K5ULh+w2xm9uCE3Ui07Z5q+7oxogkZbNP9EBWAp+jRFt5s//jmpUfpUML+0Q3/FGX JjPGZ3FSlfmy0d6GacNh5/IMw+hVvBgsohPom/zABNF2fy8zcK8KkIH5i5tFfchoQF ipb/5AnoCtbarWscgy3KBZ8DJuR6zsO9hAtvfqdg= 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 5.9 089/133] scsi: core: Dont start concurrent async scan on same host Date: Mon, 9 Nov 2020 13:55:51 +0100 Message-Id: <20201109125034.986025157@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201109125030.706496283@linuxfoundation.org> References: <20201109125030.706496283@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 f2437a7570ce8..9af50e6f94c4c 100644 --- a/drivers/scsi/scsi_scan.c +++ b/drivers/scsi/scsi_scan.c @@ -1714,15 +1714,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); @@ -1733,7 +1734,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); @@ -1748,6 +1748,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