Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp3875547pxb; Tue, 17 Nov 2020 06:00:34 -0800 (PST) X-Google-Smtp-Source: ABdhPJzmAm0DLaxUBUfmUd0CnTlu/yJfi1mUWPlYCoRgmLNENStbG5DSUdrEIdiCDTsQ8UpJealD X-Received: by 2002:a50:ed90:: with SMTP id h16mr20066572edr.255.1605621634320; Tue, 17 Nov 2020 06:00:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605621634; cv=none; d=google.com; s=arc-20160816; b=Or05kfXOnwTa+c2OqPDr4MVKDzTvtku1Df2Njp718h+H8sMeRFrSMI7pWVaRXXdkAF JSaQ4uIyAUlleqcQIk9Jn6hpNXD1GMpfvmoTgCDcGaMFP54dbt4VrbscwTqnNyP8Ww3a oONFY4bYNvBhp8eN0/XdkDiijLpmrzZWbASs9GvOuWuzVumVpqJSKn1V43+9q6yBvcz5 KB0bjut/PMa0e3aS2fwEfkClBB8NKv9rScJ8HfHXPMYAdTzE44ffVBb1FUL2EIY7//p5 hsGTtAFDbISDa0BpmZnMXot8PqVDLzTf29ROumaDe9F2nNW/roQk6zi7PqUb2PnDxFAN cBIA== 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=bNtKFohw5MToCO6v9rQ0UHUIpysAfRgnvpFm5cmbbAA=; b=PSSGvmMnQZK51Ss6zrAOnMZE0dVDgCZeW3E4j8+l5uXeHEuDtHBPQveGF2pyR/o+SM QMCWWVWt6HblxZzzb22ngdeIWl7aEVWG6kgrCSfKjfsC4mlBbBgY6cKLQY9OHBCfEIgK EZ/tXPbuQMDpCSSfuPJW0JH8TadAftHoeZXndUg5Xj8oG5hsXbGq/a0qrzaVPCAVyHZO ctMOrslb4R167m4+Fir1lWKYzZNBKarM+fF1EdYvXwoBLx786d13MqUSWRodyVualjNa 74jDT/2BNeHL3kh45khY7e5Pq+sAt6f/XpJ8IRvjnJqEzIwUbxum7nTzYmNJN8qtnjEL qBtA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=L0d8uI0X; 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 f13si13995229edx.450.2020.11.17.06.00.10; Tue, 17 Nov 2020 06:00:34 -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=L0d8uI0X; 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 S1730505AbgKQN5Z (ORCPT + 99 others); Tue, 17 Nov 2020 08:57:25 -0500 Received: from mail.kernel.org ([198.145.29.99]:53278 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730447AbgKQNTz (ORCPT ); Tue, 17 Nov 2020 08:19:55 -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 5E3E0241A6; Tue, 17 Nov 2020 13:19:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1605619195; bh=RBJ9y4/oa7/bY94unf5ZZ/waRSM/GIKyKc+JiZfknWc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=L0d8uI0X9fqH5yNnwxNGmGTXwsBQV+4wN5sI5q+u3qyyinVUvvlbsV9O7AhXJFDyS Uzvrdm6jJveAhVHkL+L7ex7ITouI7UTNQ4G0YpW1TQ0Pv/4twh79xitbR7JNIWWrus tg0p+jCOOAGh3/xQt0M9udygXq74Eq7/NPnEM41w= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Brian Bunker , Jitendra Khasdev , Hannes Reinecke , "Martin K. Petersen" , Sasha Levin Subject: [PATCH 4.19 042/101] scsi: scsi_dh_alua: Avoid crash during alua_bus_detach() Date: Tue, 17 Nov 2020 14:05:09 +0100 Message-Id: <20201117122115.140763276@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201117122113.128215851@linuxfoundation.org> References: <20201117122113.128215851@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: Hannes Reinecke [ Upstream commit 5faf50e9e9fdc2117c61ff7e20da49cd6a29e0ca ] alua_bus_detach() might be running concurrently with alua_rtpg_work(), so we might trip over h->sdev == NULL and call BUG_ON(). The correct way of handling it is to not set h->sdev to NULL in alua_bus_detach(), and call rcu_synchronize() before the final delete to ensure that all concurrent threads have left the critical section. Then we can get rid of the BUG_ON() and replace it with a simple if condition. Link: https://lore.kernel.org/r/1600167537-12509-1-git-send-email-jitendra.khasdev@oracle.com Link: https://lore.kernel.org/r/20200924104559.26753-1-hare@suse.de Cc: Brian Bunker Acked-by: Brian Bunker Tested-by: Jitendra Khasdev Reviewed-by: Jitendra Khasdev Signed-off-by: Hannes Reinecke Signed-off-by: Martin K. Petersen Signed-off-by: Sasha Levin --- drivers/scsi/device_handler/scsi_dh_alua.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/drivers/scsi/device_handler/scsi_dh_alua.c b/drivers/scsi/device_handler/scsi_dh_alua.c index c95c782b93a53..60c48dc5d9453 100644 --- a/drivers/scsi/device_handler/scsi_dh_alua.c +++ b/drivers/scsi/device_handler/scsi_dh_alua.c @@ -672,8 +672,8 @@ static int alua_rtpg(struct scsi_device *sdev, struct alua_port_group *pg) rcu_read_lock(); list_for_each_entry_rcu(h, &tmp_pg->dh_list, node) { - /* h->sdev should always be valid */ - BUG_ON(!h->sdev); + if (!h->sdev) + continue; h->sdev->access_state = desc[0]; } rcu_read_unlock(); @@ -719,7 +719,8 @@ static int alua_rtpg(struct scsi_device *sdev, struct alua_port_group *pg) pg->expiry = 0; rcu_read_lock(); list_for_each_entry_rcu(h, &pg->dh_list, node) { - BUG_ON(!h->sdev); + if (!h->sdev) + continue; h->sdev->access_state = (pg->state & SCSI_ACCESS_STATE_MASK); if (pg->pref) @@ -1160,7 +1161,6 @@ static void alua_bus_detach(struct scsi_device *sdev) spin_lock(&h->pg_lock); pg = rcu_dereference_protected(h->pg, lockdep_is_held(&h->pg_lock)); rcu_assign_pointer(h->pg, NULL); - h->sdev = NULL; spin_unlock(&h->pg_lock); if (pg) { spin_lock_irq(&pg->lock); @@ -1169,6 +1169,7 @@ static void alua_bus_detach(struct scsi_device *sdev) kref_put(&pg->kref, release_port_group); } sdev->handler_data = NULL; + synchronize_rcu(); kfree(h); } -- 2.27.0