Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 29 Aug 2019 17:02:02 +0000 (UTC)
From:      Alexander Motin <mav@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r351606 - in head/sys/cam: ata mmc nvme scsi
Message-ID:  <201908291702.x7TH22xM006558@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: mav
Date: Thu Aug 29 17:02:02 2019
New Revision: 351606
URL: https://svnweb.freebsd.org/changeset/base/351606

Log:
  Take proper lock in ses_setphyspath_callback().
  
  XPT_DEV_ADVINFO call should be protected by the lock of the specific
  device it is addressed to, not the lock of SES device.  In some weird
  case, probably with hardware violating standards, it sometimes caused
  NULL dereference due to race.
  
  To protect from it further, add lock assertion to *_dev_advinfo().
  
  MFC after:	1 week
  Sponsored by:	iXsystems, Inc.

Modified:
  head/sys/cam/ata/ata_xpt.c
  head/sys/cam/mmc/mmc_xpt.c
  head/sys/cam/nvme/nvme_xpt.c
  head/sys/cam/scsi/scsi_enc_ses.c
  head/sys/cam/scsi/scsi_xpt.c

Modified: head/sys/cam/ata/ata_xpt.c
==============================================================================
--- head/sys/cam/ata/ata_xpt.c	Thu Aug 29 13:46:54 2019	(r351605)
+++ head/sys/cam/ata/ata_xpt.c	Thu Aug 29 17:02:02 2019	(r351606)
@@ -1726,8 +1726,9 @@ ata_dev_advinfo(union ccb *start_ccb)
 {
 	struct cam_ed *device;
 	struct ccb_dev_advinfo *cdai;
-	off_t amt; 
+	off_t amt;
 
+	xpt_path_assert(start_ccb->ccb_h.path, MA_OWNED);
 	start_ccb->ccb_h.status = CAM_REQ_INVALID;
 	device = start_ccb->ccb_h.path->device;
 	cdai = &start_ccb->cdai;

Modified: head/sys/cam/mmc/mmc_xpt.c
==============================================================================
--- head/sys/cam/mmc/mmc_xpt.c	Thu Aug 29 13:46:54 2019	(r351605)
+++ head/sys/cam/mmc/mmc_xpt.c	Thu Aug 29 17:02:02 2019	(r351606)
@@ -341,6 +341,7 @@ mmc_dev_advinfo(union ccb *start_ccb)
 	struct ccb_dev_advinfo *cdai;
 	off_t amt;
 
+	xpt_path_assert(start_ccb->ccb_h.path, MA_OWNED);
 	start_ccb->ccb_h.status = CAM_REQ_INVALID;
 	device = start_ccb->ccb_h.path->device;
 	cdai = &start_ccb->cdai;

Modified: head/sys/cam/nvme/nvme_xpt.c
==============================================================================
--- head/sys/cam/nvme/nvme_xpt.c	Thu Aug 29 13:46:54 2019	(r351605)
+++ head/sys/cam/nvme/nvme_xpt.c	Thu Aug 29 17:02:02 2019	(r351606)
@@ -588,8 +588,9 @@ nvme_dev_advinfo(union ccb *start_ccb)
 {
 	struct cam_ed *device;
 	struct ccb_dev_advinfo *cdai;
-	off_t amt; 
+	off_t amt;
 
+	xpt_path_assert(start_ccb->ccb_h.path, MA_OWNED);
 	start_ccb->ccb_h.status = CAM_REQ_INVALID;
 	device = start_ccb->ccb_h.path->device;
 	cdai = &start_ccb->cdai;

Modified: head/sys/cam/scsi/scsi_enc_ses.c
==============================================================================
--- head/sys/cam/scsi/scsi_enc_ses.c	Thu Aug 29 13:46:54 2019	(r351605)
+++ head/sys/cam/scsi/scsi_enc_ses.c	Thu Aug 29 17:02:02 2019	(r351606)
@@ -1027,7 +1027,7 @@ ses_setphyspath_callback(enc_softc_t *enc, enc_element
 
 	args = (ses_setphyspath_callback_args_t *)arg;
 	old_physpath = malloc(MAXPATHLEN, M_SCSIENC, M_WAITOK|M_ZERO);
-	cam_periph_lock(enc->periph);
+	xpt_path_lock(path);
 	xpt_setup_ccb(&cdai.ccb_h, path, CAM_PRIORITY_NORMAL);
 	cdai.ccb_h.func_code = XPT_DEV_ADVINFO;
 	cdai.buftype = CDAI_TYPE_PHYS_PATH;
@@ -1052,7 +1052,7 @@ ses_setphyspath_callback(enc_softc_t *enc, enc_element
 		if (cdai.ccb_h.status == CAM_REQ_CMP)
 			args->num_set++;
 	}
-	cam_periph_unlock(enc->periph);
+	xpt_path_unlock(path);
 	free(old_physpath, M_SCSIENC);
 }
 

Modified: head/sys/cam/scsi/scsi_xpt.c
==============================================================================
--- head/sys/cam/scsi/scsi_xpt.c	Thu Aug 29 13:46:54 2019	(r351605)
+++ head/sys/cam/scsi/scsi_xpt.c	Thu Aug 29 17:02:02 2019	(r351606)
@@ -2515,6 +2515,7 @@ scsi_dev_advinfo(union ccb *start_ccb)
 	struct ccb_dev_advinfo *cdai;
 	off_t amt;
 
+	xpt_path_assert(start_ccb->ccb_h.path, MA_OWNED);
 	start_ccb->ccb_h.status = CAM_REQ_INVALID;
 	device = start_ccb->ccb_h.path->device;
 	cdai = &start_ccb->cdai;



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