git: 583480174ee7 - stable/13 - cam: don't lock while handling an AC_UNIT_ATTENTION

From: Robert Wing <rew_at_FreeBSD.org>
Date: Thu, 10 Feb 2022 19:43:43 UTC
The branch stable/13 has been updated by rew:

URL: https://cgit.FreeBSD.org/src/commit/?id=583480174ee7f4af92f0c5302884a7eece5b12f3

commit 583480174ee7f4af92f0c5302884a7eece5b12f3
Author:     Robert Wing <rew@FreeBSD.org>
AuthorDate: 2022-01-04 01:21:58 +0000
Commit:     Robert Wing <rew@FreeBSD.org>
CommitDate: 2022-02-10 19:43:18 +0000

    cam: don't lock while handling an AC_UNIT_ATTENTION
    
    Don't take the device_mtx lock in daasync() when handling an
    AC_UNIT_ATTENTION. Instead, assert the lock is held before modifying the
    periph's softc flags.
    
    The device_mtx lock is taken in xptdevicetraverse() before daasync()
    is eventually called in xpt_async_bcast().
    
    PR:             240917, 226510, 226578
    Reviewed by:    imp
    MFC after:      3 weeks
    Differential Revision: https://reviews.freebsd.org/D27735
    
    (cherry picked from commit bb8441184bab60cd8a07c2b94bd6c4ae8b56ec25)
---
 sys/cam/scsi/scsi_da.c | 15 +++++----------
 1 file changed, 5 insertions(+), 10 deletions(-)

diff --git a/sys/cam/scsi/scsi_da.c b/sys/cam/scsi/scsi_da.c
index f710e82eda9b..8b1e1c0e0d46 100644
--- a/sys/cam/scsi/scsi_da.c
+++ b/sys/cam/scsi/scsi_da.c
@@ -2150,7 +2150,7 @@ daasync(void *callback_arg, u_int32_t code,
 		}
 		break;
 	}
-	case AC_UNIT_ATTENTION:
+	case AC_UNIT_ATTENTION:		/* Called for this path: periph locked */
 	{
 		union ccb *ccb;
 		int error_code, sense_key, asc, ascq;
@@ -2160,9 +2160,7 @@ daasync(void *callback_arg, u_int32_t code,
 
 		/*
 		 * Handle all UNIT ATTENTIONs except our own, as they will be
-		 * handled by daerror(). Since this comes from a different periph,
-		 * that periph's lock is held, not ours, so we have to take it ours
-		 * out to touch softc flags.
+		 * handled by daerror().
 		 */
 		if (xpt_path_periph(ccb->ccb_h.path) != periph &&
 		    scsi_extract_sense_ccb(ccb,
@@ -2170,22 +2168,19 @@ daasync(void *callback_arg, u_int32_t code,
 			if (asc == 0x2A && ascq == 0x09) {
 				xpt_print(ccb->ccb_h.path,
 				    "Capacity data has changed\n");
-				cam_periph_lock(periph);
+				cam_periph_assert(periph, MA_OWNED);
 				softc->flags &= ~DA_FLAG_PROBED;
 				dareprobe(periph);
-				cam_periph_unlock(periph);
 			} else if (asc == 0x28 && ascq == 0x00) {
-				cam_periph_lock(periph);
+				cam_periph_assert(periph, MA_OWNED);
 				softc->flags &= ~DA_FLAG_PROBED;
-				cam_periph_unlock(periph);
 				disk_media_changed(softc->disk, M_NOWAIT);
 			} else if (asc == 0x3F && ascq == 0x03) {
 				xpt_print(ccb->ccb_h.path,
 				    "INQUIRY data has changed\n");
-				cam_periph_lock(periph);
+				cam_periph_assert(periph, MA_OWNED);
 				softc->flags &= ~DA_FLAG_PROBED;
 				dareprobe(periph);
-				cam_periph_unlock(periph);
 			}
 		}
 		break;