From patchwork Wed Jul 11 08:09:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hannes Reinecke X-Patchwork-Id: 10519117 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 55F936028E for ; Wed, 11 Jul 2018 08:09:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 47D1328DAC for ; Wed, 11 Jul 2018 08:09:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3C15128DB7; Wed, 11 Jul 2018 08:09:50 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DA79B28DAC for ; Wed, 11 Jul 2018 08:09:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726701AbeGKIMw (ORCPT ); Wed, 11 Jul 2018 04:12:52 -0400 Received: from mx2.suse.de ([195.135.220.15]:52756 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726205AbeGKIMv (ORCPT ); Wed, 11 Jul 2018 04:12:51 -0400 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 D6A78AEBE; Wed, 11 Jul 2018 08:09:46 +0000 (UTC) From: Hannes Reinecke To: "Martin K. Petersen" Cc: Christoph Hellwig , James Bottomley , linux-scsi@vger.kernel.org, Hannes Reinecke , Hannes Reinecke Subject: [PATCH 4/4] fcoe: hold disc_mutex when traversing rport lists Date: Wed, 11 Jul 2018 10:09:30 +0200 Message-Id: <20180711080930.24400-5-hare@suse.de> X-Mailer: git-send-email 2.12.3 In-Reply-To: <20180711080930.24400-1-hare@suse.de> References: <20180711080930.24400-1-hare@suse.de> Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When calling either fc_rport_logon() or fc_rport_logoff() during rport list traversal we cannot use the RCU list traversal, as either of these functions will be taking a mutex. So we need to partially revert commit a407c593398c to take the disc mutex during traversal. We should, however, continue to use krefs to ensure that the rport object will not be freed from under us. Fixes: a407c593398c ("scsi: libfc: Fixup disc_mutex handling") Signed-off-by: Hannes Reinecke Reviewed-by: Johannes Thumshirn --- drivers/scsi/fcoe/fcoe_ctlr.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/drivers/scsi/fcoe/fcoe_ctlr.c b/drivers/scsi/fcoe/fcoe_ctlr.c index ea23c8dffc25..b42bfc790e04 100644 --- a/drivers/scsi/fcoe/fcoe_ctlr.c +++ b/drivers/scsi/fcoe/fcoe_ctlr.c @@ -2175,15 +2175,13 @@ static void fcoe_ctlr_disc_stop_locked(struct fc_lport *lport) { struct fc_rport_priv *rdata; - rcu_read_lock(); + mutex_lock(&lport->disc.disc_mutex); list_for_each_entry_rcu(rdata, &lport->disc.rports, peers) { if (kref_get_unless_zero(&rdata->kref)) { fc_rport_logoff(rdata); kref_put(&rdata->kref, fc_rport_destroy); } } - rcu_read_unlock(); - mutex_lock(&lport->disc.disc_mutex); lport->disc.disc_callback = NULL; mutex_unlock(&lport->disc.disc_mutex); } @@ -2712,7 +2710,7 @@ static unsigned long fcoe_ctlr_vn_age(struct fcoe_ctlr *fip) unsigned long deadline; next_time = jiffies + msecs_to_jiffies(FIP_VN_BEACON_INT * 10); - rcu_read_lock(); + mutex_lock(&lport->disc.disc_mutex); list_for_each_entry_rcu(rdata, &lport->disc.rports, peers) { if (!kref_get_unless_zero(&rdata->kref)) continue; @@ -2733,7 +2731,7 @@ static unsigned long fcoe_ctlr_vn_age(struct fcoe_ctlr *fip) next_time = deadline; kref_put(&rdata->kref, fc_rport_destroy); } - rcu_read_unlock(); + mutex_unlock(&lport->disc.disc_mutex); return next_time; } @@ -3080,8 +3078,6 @@ static void fcoe_ctlr_vn_disc(struct fcoe_ctlr *fip) mutex_lock(&disc->disc_mutex); callback = disc->pending ? disc->disc_callback : NULL; disc->pending = 0; - mutex_unlock(&disc->disc_mutex); - rcu_read_lock(); list_for_each_entry_rcu(rdata, &disc->rports, peers) { if (!kref_get_unless_zero(&rdata->kref)) continue; @@ -3090,7 +3086,7 @@ static void fcoe_ctlr_vn_disc(struct fcoe_ctlr *fip) fc_rport_login(rdata); kref_put(&rdata->kref, fc_rport_destroy); } - rcu_read_unlock(); + mutex_unlock(&disc->disc_mutex); if (callback) callback(lport, DISC_EV_SUCCESS); }