Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp165280pxb; Mon, 2 Nov 2020 17:28:37 -0800 (PST) X-Google-Smtp-Source: ABdhPJxr+vGH4dgUFGQOHzl+BzcGLZuEtL+pr61loeahEga8VBcoSSNgvgoeUvjhyCv2NU0GWPT6 X-Received: by 2002:a17:906:2558:: with SMTP id j24mr3511632ejb.329.1604366917127; Mon, 02 Nov 2020 17:28:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604366917; cv=none; d=google.com; s=arc-20160816; b=b9/INxPIFL4QbVIbqWfhvFrmjKLRIpnhTMxCYdAM/9+08KnhMrpDvNhKZ/J5BfURIP 3wVJGdlq0+BCMiYTPfKnWlMZ71aQKViLK7LsrIQXjAjOSPtjoNCnvWIiLmZNnRuMDzQO 9yyGkeJAQOxltXqnzcvWb9/VsjwqbiXDIUXwkqLhSXkFJ+PqUjKzCGJUJPyYQ4augFRB JsxXKyiZNyFQR2fpqGqC2svYAt8HCmJ+b53eVRi9WlbLUK4ioVnBdhjxo+1xJRhX3TnI 8y+G9yoDLNjO1FP4OjlgbvVVXNY+8DL8dTMHuBXMv3HzDjivXOtuOy/8oJiFayVfXkOB si2Q== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=jfOLkELIDagTcrQF3sztvMW1SqyT1Q2ZhZzVJAo9Hns=; b=DGJ7dnIB3OKF30d3BhmM7/YvnSSGu9XKWNxE+QQo/zJ5IAATCNG7uAO0Kh7RvLOmxH wY+WF5DVIJPYwuW4OOXdjKBdenWBKq0KJBcySEOradL6+c6h1ARRDV9dA6PHGtR+ppng epuG/nWecS09i3JgdowP6x+G0rn6ia3vpxCEl/pLaxEdf6D33upB8D1y9AFWX67ZFtj0 l5wklnHmXJi5AAm4LiMd7YVTuS3b7ib5JSxzzfhgL3tpTOJ774Pp218KTfj+u/tW3HTh Pg7diNohUjizeJhUZkGiou+YVrwenghmD81cv5EHqTesvc3cQvgbk3SYjBW+lM1kTroz iVnA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=mB0CJdNW; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id cw10si5688860edb.135.2020.11.02.17.28.14; Mon, 02 Nov 2020 17:28:37 -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=mB0CJdNW; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728219AbgKCBYL (ORCPT + 99 others); Mon, 2 Nov 2020 20:24:11 -0500 Received: from mail.kernel.org ([198.145.29.99]:35138 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728096AbgKCBU0 (ORCPT ); Mon, 2 Nov 2020 20:20:26 -0500 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 25CA822470; Tue, 3 Nov 2020 01:20:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604366425; bh=s6Ohnr9qvDXvw5RYnAX7G1WAuGXYpoxuoPw8bgU/29w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mB0CJdNW927fP2jWHhBnNZ3jNJYL+ithNd3ASbsmI4CfKXbIt0MZabFdWddvZlDzV cN0WYgA0JScEdZsXyB2XKs9AAIYibGem56EXiGbYkBAB9nBuTFC+xfy2E/ohS9q5kO eBziFPoZk8nLZYuYnitZJPojMvUtxvEXaYidAjf0= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Ming Lei , Christoph Hellwig , "Ewan D . Milne" , Hannes Reinecke , Bart Van Assche , Lee Duncan , "Martin K . Petersen" , Sasha Levin , linux-scsi@vger.kernel.org Subject: [PATCH AUTOSEL 5.4 13/24] scsi: core: Don't start concurrent async scan on same host Date: Mon, 2 Nov 2020 20:19:56 -0500 Message-Id: <20201103012007.183429-13-sashal@kernel.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20201103012007.183429-1-sashal@kernel.org> References: <20201103012007.183429-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore 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 058079f915f18..79232cef1af16 100644 --- a/drivers/scsi/scsi_scan.c +++ b/drivers/scsi/scsi_scan.c @@ -1715,15 +1715,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); @@ -1734,7 +1735,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); @@ -1749,6 +1749,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