Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 6 May 2014 06:18:43 +0000 (UTC)
From:      "Kenneth D. Merry" <ken@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r265424 - head/sys/dev/mpr
Message-ID:  <201405060618.s466Ihcb016132@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: ken
Date: Tue May  6 06:18:43 2014
New Revision: 265424
URL: http://svnweb.freebsd.org/changeset/base/265424

Log:
  Fix a problem with async notifications in the mpr(4) driver.
  
  This problem only occurs on versions of FreeBSD prior to the recent CAM
  locking changes.  (i.e. stable/9 and older versions of stable/10)  This
  change should be a no-op for head and stable/10.
  
  If a path isn't specified, xpt_register_async() will create a fully
  wildcarded path and acquire a lock (the XPT lock in older versions,
  and via xpt_path_lock() in newer versions) to call xpt_action() for the
  XPT_SASYNC_CB CCB.  It will then drop the lock and if the requested event
  includes AC_FOUND_DEVICE or AC_PATH_REGISTERED, it will get the caller up
  to date with any device arrivals or path registrations.
  
  The issue is that before the locking changes, each SIM lock would get
  acquired in turn during the EDT tree traversal process.  If a path is
  specified for xpt_register_async(), it won't acquire and drop its own lock,
  but instead expects the caller to hold its own SIM lock.  That works for
  the first part of xpt_register_async(), but causes a recursive lock
  acquisition once the EDT traversal happens and it comes to the SIM in
  question.  And it isn't possible to call xpt_action() without holding a SIM
  lock.
  
  The locking changes fix this by using the XPT topology lock for EDT
  traversal, so it is no longer an issue to hold the SIM lock while calling
  xpt_register_async().
  
  The solution for FreeBSD versions before the locking changes is to request
  notification of all device arrivals (so we pass a NULL path into
  xpt_register_async()) and then filter out the arrivals that are not ours.
  
  MFC After:	3 days
  Sponsored by:	Spectra Logic Corporation

Modified:
  head/sys/dev/mpr/mpr_sas.c

Modified: head/sys/dev/mpr/mpr_sas.c
==============================================================================
--- head/sys/dev/mpr/mpr_sas.c	Tue May  6 04:22:37 2014	(r265423)
+++ head/sys/dev/mpr/mpr_sas.c	Tue May  6 06:18:43 2014	(r265424)
@@ -813,8 +813,49 @@ mpr_attach_sas(struct mpr_softc *sc)
 #else
 		event = AC_FOUND_DEVICE;
 #endif
+
+		/*
+		 * Prior to the CAM locking improvements, we can't call
+		 * xpt_register_async() with a particular path specified.
+		 *
+		 * If a path isn't specified, xpt_register_async() will
+		 * generate a wildcard path and acquire the XPT lock while
+		 * it calls xpt_action() to execute the XPT_SASYNC_CB CCB.
+		 * It will then drop the XPT lock once that is done.
+		 * 
+		 * If a path is specified for xpt_register_async(), it will
+		 * not acquire and drop the XPT lock around the call to
+		 * xpt_action().  xpt_action() asserts that the caller
+		 * holds the SIM lock, so the SIM lock has to be held when
+		 * calling xpt_register_async() when the path is specified.
+		 * 
+		 * But xpt_register_async calls xpt_for_all_devices(),
+		 * which calls xptbustraverse(), which will acquire each
+		 * SIM lock.  When it traverses our particular bus, it will
+		 * necessarily acquire the SIM lock, which will lead to a
+		 * recursive lock acquisition.
+		 * 
+		 * The CAM locking changes fix this problem by acquiring
+		 * the XPT topology lock around bus traversal in
+		 * xptbustraverse(), so the caller can hold the SIM lock
+		 * and it does not cause a recursive lock acquisition.
+		 *
+		 * These __FreeBSD_version values are approximate, especially
+		 * for stable/10, which is two months later than the actual
+		 * change.
+		 */
+
+#if (__FreeBSD_version < 1000703) || \
+    ((__FreeBSD_version >= 1100000) && (__FreeBSD_version < 1100002))
+		mpr_unlock(sc);
+		status = xpt_register_async(event, mprsas_async, sc,
+					    NULL);
+		mpr_lock(sc);
+#else
 		status = xpt_register_async(event, mprsas_async, sc,
 					    sassc->path);
+#endif
+
 		if (status != CAM_REQ_CMP) {
 			mpr_dprint(sc, MPR_ERROR,
 			    "Error %#x registering async handler for "
@@ -2988,6 +3029,18 @@ mprsas_async(void *callback_arg, uint32_
 			break;
 
 		/*
+		 * See the comment in mpr_attach_sas() for a detailed
+		 * explanation.  In these versions of FreeBSD we register
+		 * for all events and filter out the events that don't
+		 * apply to us.
+		 */
+#if (__FreeBSD_version < 1000703) || \
+    ((__FreeBSD_version >= 1100000) && (__FreeBSD_version < 1100002))
+		if (xpt_path_path_id(path) != sassc->sim->path_id)
+			break;
+#endif
+
+		/*
 		 * We should have a handle for this, but check to make sure.
 		 */
 		KASSERT(xpt_path_target_id(path) < sassc->maxtargets,
@@ -3044,8 +3097,21 @@ mprsas_async(void *callback_arg, uint32_
 	case AC_FOUND_DEVICE: {
 		struct ccb_getdev *cgd;
 
+		/*
+		 * See the comment in mpr_attach_sas() for a detailed
+		 * explanation.  In these versions of FreeBSD we register
+		 * for all events and filter out the events that don't
+		 * apply to us.
+		 */
+#if (__FreeBSD_version < 1000703) || \
+    ((__FreeBSD_version >= 1100000) && (__FreeBSD_version < 1100002))
+		if (xpt_path_path_id(path) != sc->sassc->sim->path_id)
+			break;
+#endif
+
 		cgd = arg;
 		mprsas_prepare_ssu(sc, path, cgd);
+
 #if (__FreeBSD_version < 901503) || \
     ((__FreeBSD_version >= 1000000) && (__FreeBSD_version < 1000006))
 		mprsas_check_eedp(sc, path, cgd);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201405060618.s466Ihcb016132>