public inbox for linux-scsi@vger.kernel.org
 help / color / mirror / Atom feed
From: Robert Love <robert.w.love@intel.com>
To: linux-scsi@vger.kernel.org
Cc: Neil Horman <nhorman@tuxdriver.com>, Yi Zou <yi.zou@intel.com>
Subject: [PATCH 18/21] fcoe: close race on link speed detection in fcoe code
Date: Tue, 19 Feb 2013 11:32:10 -0800	[thread overview]
Message-ID: <20130219193210.10192.26226.stgit@fritz> (raw)
In-Reply-To: <20130219193031.10192.33777.stgit@fritz>

From: Neil Horman <nhorman@tuxdriver.com>

When creating an fcoe interfce, we call fcoe_link_speed_update before we add the
lports fcoe interface to the fc_hostlist.  Since network device events like
NETDEV_CHANGE are only processed if an fcoe interface is found with an
underlying netdev that matches the netdev of the event.  Since this processing
in fcoe_device_notification is how link_speed changes get communicated to the
libfc  code (via fcoe_link_speed_update), we have a race condition - if a
NETDEV_CHANGE event is sent after the call to fcoe_link_speed_update in
fcoe_netdev_config, but before we add the interface to the fc_hostlist, we will
loose the event and attributes like /sys/class/fc_host/hostX/speed will not get
updated properly.

Fix this by moving the add to the fc_hostlist above the serialized call to
fcoe_netdev_config, ensuring that we catch netdev envents before we make a
direct call to fcoe_link_speed_update.

Also use this opportunity to clean up access to the fc_hostlist a bit by
creating a fcoe_hostlist_del accessor and replacing the cleanup in fcoe_exit to
use it properly.

Tested by myself successfully

[ Comment over 80 chars broken into multi-line by Robert Love to
  satisfy checkpatch.pl ]

Signed-off-by: Neil Horman <nhorman@tuxdriver.com>
Reviewed-by: Yi Zou <yi.zou@intel.com>
Signed-off-by: Robert Love <robert.w.love@intel.com>
---
 drivers/scsi/fcoe/fcoe.c |   31 +++++++++++++++++++++++++++----
 1 file changed, 27 insertions(+), 4 deletions(-)

diff --git a/drivers/scsi/fcoe/fcoe.c b/drivers/scsi/fcoe/fcoe.c
index 0b33368..d605700 100644
--- a/drivers/scsi/fcoe/fcoe.c
+++ b/drivers/scsi/fcoe/fcoe.c
@@ -86,6 +86,7 @@ static int fcoe_link_ok(struct fc_lport *);
 
 static struct fc_lport *fcoe_hostlist_lookup(const struct net_device *);
 static int fcoe_hostlist_add(const struct fc_lport *);
+static void fcoe_hostlist_del(const struct fc_lport *);
 
 static int fcoe_device_notification(struct notifier_block *, ulong, void *);
 static void fcoe_dev_setup(void);
@@ -1119,6 +1120,12 @@ static struct fc_lport *fcoe_if_create(struct fcoe_interface *fcoe,
 	port->min_queue_depth = FCOE_MIN_QUEUE_DEPTH;
 	INIT_WORK(&port->destroy_work, fcoe_destroy_work);
 
+	/*
+	 * Need to add the lport to the hostlist
+	 * so we catch NETDEV_CHANGE events.
+	 */
+	fcoe_hostlist_add(lport);
+
 	/* configure a fc_lport including the exchange manager */
 	rc = fcoe_lport_config(lport);
 	if (rc) {
@@ -1190,6 +1197,7 @@ static struct fc_lport *fcoe_if_create(struct fcoe_interface *fcoe,
 out_lp_destroy:
 	fc_exch_mgr_free(lport);
 out_host_put:
+	fcoe_hostlist_del(lport);
 	scsi_host_put(lport->host);
 out:
 	return ERR_PTR(rc);
@@ -2313,9 +2321,6 @@ static int _fcoe_create(struct net_device *netdev, enum fip_state fip_mode,
 	/* setup DCB priority attributes. */
 	fcoe_dcb_create(fcoe);
 
-	/* add to lports list */
-	fcoe_hostlist_add(lport);
-
 	/* start FIP Discovery and FLOGI */
 	lport->boot_time = jiffies;
 	fc_fabric_login(lport);
@@ -2523,6 +2528,24 @@ static int fcoe_hostlist_add(const struct fc_lport *lport)
 	return 0;
 }
 
+/**
+ * fcoe_hostlist_del() - Remove the FCoE interface identified by a local
+ *			 port to the hostlist
+ * @lport: The local port that identifies the FCoE interface to be added
+ *
+ * Locking: must be called with the RTNL mutex held
+ *
+ */
+static void fcoe_hostlist_del(const struct fc_lport *lport)
+{
+	struct fcoe_interface *fcoe;
+	struct fcoe_port *port;
+
+	port = lport_priv(lport);
+	fcoe = port->priv;
+	list_del(&fcoe->list);
+	return;
+}
 
 static struct fcoe_transport fcoe_sw_transport = {
 	.name = {FCOE_TRANSPORT_DEFAULT},
@@ -2613,9 +2636,9 @@ static void __exit fcoe_exit(void)
 	/* releases the associated fcoe hosts */
 	rtnl_lock();
 	list_for_each_entry_safe(fcoe, tmp, &fcoe_hostlist, list) {
-		list_del(&fcoe->list);
 		ctlr = fcoe_to_ctlr(fcoe);
 		port = lport_priv(ctlr->lp);
+		fcoe_hostlist_del(port->lport);
 		queue_work(fcoe_wq, &port->destroy_work);
 	}
 	rtnl_unlock();


  parent reply	other threads:[~2013-02-19 19:32 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-02-19 19:30 [PATCH 00/21] libfc, libfcoe and fcoe updates for 3.9 Robert Love
2013-02-19 19:30 ` [PATCH 01/21] libfc: fix REC handling Robert Love
2013-02-19 19:30 ` [PATCH 02/21] Documentation: Add missing devices/ to devices path Robert Love
2013-02-19 19:30 ` [PATCH 03/21] libfcoe: Save some memory and optimize name lookups Robert Love
2013-02-19 19:30 ` [PATCH 04/21] libfcoe: Add fcoe_sysfs debug logging level Robert Love
2013-02-19 19:30 ` [PATCH 05/21] libfcoe, fcoe, bnx2fc: Add new fcoe control interface Robert Love
2013-02-19 19:31 ` [PATCH 06/21] fcoe: Use the fcoe_sysfs " Robert Love
2013-02-19 19:31 ` [PATCH 07/21] bnx2fc: " Robert Love
2013-02-19 19:31 ` [PATCH 08/21] libfc, libfcoe, fcoe: Convert debug_logging macros to pr_info Robert Love
2013-02-19 19:31 ` [PATCH 09/21] fcoe: prep work to start consolidate the usage of fcoe_netdev Robert Love
2013-02-19 19:31 ` [PATCH 10/21] fcoe: add support to the get_netdev() for fcoe_interface Robert Love
2013-02-19 19:31 ` [PATCH 11/21] libfcoe, fcoe: move fcoe_link_speed_update() to libfcoe and export it Robert Love
2013-02-19 19:31 ` [PATCH 12/21] libfcoe, fcoe: consolidate the fcoe_ctlr_get_lesb/fcoe_get_lesb Robert Love
2013-02-19 19:31 ` [PATCH 13/21] bnx2fc: add support to get_netdev for bnx2f_interface Robert Love
2013-02-19 19:31 ` [PATCH 14/21] bnx2fc: use fcoe_link_speed_update() from the exported symbol in libfcoe Robert Love
2013-02-19 19:31 ` [PATCH 15/21] bnx2fc: use fcoe_get_lesb/fcoe_ctlr_get_lesb() directly from libfcoe Robert Love
2013-02-19 19:31 ` [PATCH 16/21] debris left by "[SCSI] libfcoe: Remove mutex_trylock/restart_syscall checks" Robert Love
2013-02-19 19:32 ` [PATCH 17/21] UAPI: (Scripted) Disintegrate include/scsi/fc Robert Love
2013-02-19 19:32 ` Robert Love [this message]
2013-02-19 19:32 ` [PATCH 19/21] fcoe: Fix deadlock while deleting FCoE interface with NPIV ports Robert Love
2013-02-19 19:32 ` [PATCH 20/21] libfcoe: Handle CVL while waiting to select an FCF Robert Love
2013-02-19 19:32 ` [PATCH 21/21] libfc: XenServer fails to mount root filesystem Robert Love
2013-02-19 21:01 ` [PATCH 00/21] libfc, libfcoe and fcoe updates for 3.9 Love, Robert W

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20130219193210.10192.26226.stgit@fritz \
    --to=robert.w.love@intel.com \
    --cc=linux-scsi@vger.kernel.org \
    --cc=nhorman@tuxdriver.com \
    --cc=yi.zou@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox