Skip to contentSkip to conversation

SCSI fixes for 7.4-rc4+

GIT PULL Merged James Bottomley 2 participants 2 messages Nov 29

Subsystems (10)
lore
Share & tools
lore

James Bottomley

author maintainer
#0 lore raw

The following changes since commit e550f2b2b4aab4c5f12db89d04d8978ce4ed7b4e:

scsi: mpi3mr: Validate reply frame size bounds (2026-11-08 22:36:12 -0500)

are available in the Git repository at:

https://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi.git/ tags/scsi-fixes

for you to fetch changes up to efd68f17acca65f581b9f2fa9ba50c8643ab544d:

scsi: mpt3sas: Validate data_out size before SMP link-reset check (2026-11-20 21:20:18 -0500)

----------------------------------------------------------------
Bug fixes, mostly in drivers. The only core change is to add service action in to the SCSI ioctl to support ATA depopulation. The largest driver fix is in ufs (decouple device lifecycle from devres) and the next largest is in the target code (compare all six ISID bytes identifying nexus) in the persistent reservation path.

----------------------------------------------------------------
Changyul Lee (1):
scsi: ch: Remove the minor from ch_index_idr after device_destroy()

Ciro Iriarte (1):
scsi: target: core: Compare all six ISID bytes when identifying a nexus

Kyle Mahlkuch (1):
scsi: lpfc: Fix race conditions in ELS retry handling

Laurence Oberman (2):
scsi: scsi_dh_alua: Set handler_data before alua_initialize()
scsi: mpt3sas: Fix off-by-one in NVMe PRP list transfer size limit

Louis Sautier (1):
scsi: mpt3sas: Fix out-of-bounds cpu_msix_table read on CPU hotplug

Niklas Cassel (1):
scsi: scsi_ioctl: Require write access for the depopulation commands

Stanley Jhu (4):
scsi: rpmb: core: Guard frame requests and teardown with mutex
scsi: ufs: rpmb: Decouple device lifecycle from devres to avoid UAF
scsi: ufs: rpmb: Drop the unregistered ufs_rpmb bus
scsi: ufs: ufs-pci: Check hba->vops in system PM callbacks

Terrence Adams (1):
scsi: pm8001: Offset hardware queue index for MSI-X pre-vector

Weibin Liu (1):
scsi: mpt3sas: Validate data_out size before SMP link-reset check

Weidong Wang (1):
scsi: libfc: Fix rport kref leak in fc_rport_enter_ready()

Xiangwu Lai (2):
scsi: ufs-mediatek: Use devm_regulator_get() for the va09 regulator
scsi: ufs-mediatek: Restore the M-PHY power state when va09 disable fails

Yehyeong Lee (1):
scsi: target: iscsi: Run the Time2Retain handler in process context

yong liu (1):
scsi: target: core: Disable protection processing for zero-block transfers

 drivers/misc/rpmb-core.c                   | 20 ++++++-
 drivers/scsi/ch.c                          |  6 ++-
 drivers/scsi/device_handler/scsi_dh_alua.c |  9 +++-
 drivers/scsi/libfc/fc_rport.c              |  9 ++--
 drivers/scsi/lpfc/lpfc_els.c               | 29 ++++++++---
 drivers/scsi/lpfc/lpfc_hbadisc.c           | 11 +++-
 drivers/scsi/mpt3sas/mpt3sas_base.c        | 16 +++---
 drivers/scsi/mpt3sas/mpt3sas_ctl.c         | 18 +++++--
 drivers/scsi/mpt3sas/mpt3sas_scsih.c       | 26 +++++++--
 drivers/scsi/pm8001/pm8001_defs.h          |  1 +
 drivers/scsi/pm8001/pm8001_init.c          | 15 +++---
 drivers/scsi/pm8001/pm80xx_hwi.c           | 13 +++--
 drivers/scsi/scsi_ioctl.c                  | 16 +++++-
 drivers/target/iscsi/iscsi_target.c        | 14 ++++-
 drivers/target/iscsi/iscsi_target_erl0.c   | 20 +++++--
 drivers/target/iscsi/iscsi_target_erl0.h   |  1 +
 drivers/target/iscsi/iscsi_target_login.c  |  1 +
 drivers/target/target_core_fabric_lib.c    |  9 ++--
 drivers/target/target_core_pr.c            | 46 ++++++++++++++--
 drivers/target/target_core_pr.h            |  1 +
 drivers/target/target_core_sbc.c           |  6 +++
 drivers/target/target_core_transport.c     |  2 +-
 drivers/ufs/core/ufs-rpmb.c                | 84 ++++++++++++++++--------------
 drivers/ufs/host/ufs-mediatek.c            | 21 +++++++-
 drivers/ufs/host/ufshcd-pci.c              |  4 +-
 include/linux/rpmb.h                       |  3 ++
 include/target/iscsi/iscsi_target_core.h   |  3 ++
 27 files changed, 304 insertions(+), 100 deletions(-)

With full diff below.

Regards,

James

---

drivers/misc/rpmb-core.c +18 -2
index ecf14acf230a..0fda893dd74d 100644
@@ -45,6 +45,8 @@ EXPORT_SYMBOL_GPL(rpmb_dev_put);
  * @rsp:	rpmb response frames
  * @rsp_len:	length of rpmb response frames in bytes
  *
+ * Context: Might sleep.
+ *
  * Returns: < 0 on failure
  */
 int rpmb_route_frames(struct rpmb_dev *rdev, u8 *req,
@@ -53,6 +55,10 @@ int rpmb_route_frames(struct rpmb_dev *rdev, u8 *req,
 	if (!req || !req_len || !rsp || !rsp_len)
 		return -EINVAL;
 
+	guard(mutex)(&rdev->lock);
+	if (!rdev->descr.route_frames)
+		return -ENODEV;
+
 	return rdev->descr.route_frames(rdev->dev.parent, req, req_len,
 					rsp, rsp_len);
 }
@@ -62,6 +68,7 @@ static void rpmb_dev_release(struct device *dev)
 {
 	struct rpmb_dev *rdev = to_rpmb_dev(dev);
 
+	mutex_destroy(&rdev->lock);
 	ida_free(&rpmb_ida, rdev->id);
 	kfree(rdev->descr.dev_id);
 	kfree(rdev);
@@ -123,8 +130,9 @@ EXPORT_SYMBOL_GPL(rpmb_interface_unregister);
  * rpmb_dev_unregister() - unregister RPMB partition from the RPMB subsystem
  * @rdev: the rpmb device to unregister
  *
- * This function should be called from the release function of the
- * underlying device used when the RPMB device was registered.
+ * This function should be called from the remove or unbind callback of the
+ * underlying device used when the RPMB device was registered, never from
+ * a device release callback.
  *
  * Returns: < 0 on failure
  */
@@ -133,6 +141,12 @@ int rpmb_dev_unregister(struct rpmb_dev *rdev)
 	if (!rdev)
 		return -EINVAL;
 
+	scoped_guard(mutex, &rdev->lock) {
+		if (!rdev->descr.route_frames)
+			return 0;
+		rdev->descr.route_frames = NULL;
+	}
+
 	device_del(&rdev->dev);
 
 	rpmb_dev_put(rdev);
@@ -164,6 +178,7 @@ struct rpmb_dev *rpmb_dev_register(struct device *dev,
 	rdev = kzalloc_obj(*rdev);
 	if (!rdev)
 		return ERR_PTR(-ENOMEM);
+	mutex_init(&rdev->lock);
 	rdev->descr = *descr;
 	rdev->descr.dev_id = kmemdup(descr->dev_id, descr->dev_id_len,
 				     GFP_KERNEL);
@@ -194,6 +209,7 @@ struct rpmb_dev *rpmb_dev_register(struct device *dev,
 err_free_dev_id:
 	kfree(rdev->descr.dev_id);
 err_free_rdev:
+	mutex_destroy(&rdev->lock);
 	kfree(rdev);
 	return ERR_PTR(ret);
 }
drivers/scsi/ch.c +5 -1
index b2c9fb71c9e0..390425671a3a 100644
@@ -952,11 +952,15 @@ static void ch_remove(struct scsi_device *sd)
 	scsi_changer *ch = dev_get_drvdata(dev);
 
 	spin_lock(&ch_index_lock);
-	idr_remove(&ch_index_idr, ch->minor);
+	idr_replace(&ch_index_idr, NULL, ch->minor);
 	dev_set_drvdata(dev, NULL);
 	spin_unlock(&ch_index_lock);
 
 	device_destroy(&ch_sysfs_class, MKDEV(SCSI_CHANGER_MAJOR, ch->minor));
+
+	spin_lock(&ch_index_lock);
+	idr_remove(&ch_index_idr, ch->minor);
+	spin_unlock(&ch_index_lock);
 	scsi_device_put(ch->device);
 	kref_put(&ch->ref, ch_destroy);
 }
drivers/scsi/device_handler/scsi_dh_alua.c +8 -1
index 87ac0a6d63e5..84ff3aed2c46 100644
@@ -1233,13 +1233,20 @@ static int alua_bus_attach(struct scsi_device *sdev)
 	INIT_LIST_HEAD(&h->node);
 
 	mutex_init(&h->init_mutex);
+	/*
+	 * alua_rtpg_queue() only queues an RTPG when sdev->handler_data
+	 * points at this alua_dh_data, so set it before alua_initialize()
+	 * otherwise the initial RTPG issued from alua_check_vpd() is
+	 * silently dropped and sdev->access_state is never populated.
+	 */
+	sdev->handler_data = h;
 	err = alua_initialize(sdev, h);
 	if (err != SCSI_DH_OK && err != SCSI_DH_DEV_OFFLINED)
 		goto failed;
 
-	sdev->handler_data = h;
 	return SCSI_DH_OK;
 failed:
+	sdev->handler_data = NULL;
 	kfree(h);
 	return err;
 }
drivers/scsi/libfc/fc_rport.c +5 -4
index c25979d96808..7b093854462e 100644
@@ -550,10 +550,11 @@ static void fc_rport_enter_ready(struct fc_rport_priv *rdata)
 
 	FC_RPORT_DBG(rdata, "Port is Ready\n");
 
-	kref_get(&rdata->kref);
-	if (rdata->event == RPORT_EV_NONE &&
-	    !queue_work(rport_event_queue, &rdata->event_work))
-		kref_put(&rdata->kref, fc_rport_destroy);
+	if (rdata->event == RPORT_EV_NONE) {
+		kref_get(&rdata->kref);
+		if (!queue_work(rport_event_queue, &rdata->event_work))
+			kref_put(&rdata->kref, fc_rport_destroy);
+	}
 
 	rdata->event = RPORT_EV_READY;
 }
drivers/scsi/lpfc/lpfc_els.c +23 -6
index 804aa7509b69..8d5bf2510d7a 100644
@@ -4477,18 +4477,35 @@ lpfc_issue_els_edc(struct lpfc_vport *vport, uint8_t retry)
 void
 lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp)
 {
-	struct lpfc_work_evt *evtp;
+	struct lpfc_hba *phba = vport->phba;
+	struct lpfc_work_evt *evtp = &nlp->els_retry_evt;
+	struct lpfc_nodelist *arg_ndlp = NULL;
+	unsigned long flags;
 
 	if (!test_and_clear_bit(NLP_DELAY_TMO, &nlp->nlp_flag))
 		return;
 	timer_delete_sync(&nlp->nlp_delayfunc);
 	nlp->nlp_last_elscmd = 0;
-	if (!list_empty(&nlp->els_retry_evt.evt_listp)) {
-		list_del_init(&nlp->els_retry_evt.evt_listp);
-		/* Decrement nlp reference count held for the delayed retry */
-		evtp = &nlp->els_retry_evt;
-		lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1);
+
+	/*
+	 * If retry event is queued, remove it under lock and consume
+	 * its payload to prevent double-put. The event holds a reference
+	 * to the nodelist that must be released exactly once.
+	 */
+	spin_lock_irqsave(&phba->hbalock, flags);
+	if (!list_empty(&evtp->evt_listp)) {
+		list_del_init(&evtp->evt_listp);
+		/* Take local copy and clear to prevent reuse */
+		arg_ndlp = (struct lpfc_nodelist *)evtp->evt_arg1;
+		evtp->evt_arg1 = NULL;
+		smp_wmb(); /* Ensure NULL visible before unlock */
 	}
+	spin_unlock_irqrestore(&phba->hbalock, flags);
+
+	/* Drop the event-held reference outside the lock */
+	if (arg_ndlp)
+		lpfc_nlp_put(arg_ndlp);
+
 	if (test_and_clear_bit(NLP_NPR_2B_DISC, &nlp->nlp_flag)) {
 		if (vport->num_disc_nodes) {
 			if (vport->port_state < LPFC_VPORT_READY) {
drivers/scsi/lpfc/lpfc_hbadisc.c +10 -1
index 57cdd669928c..b447b9acfe7b 100644
@@ -840,12 +840,21 @@ lpfc_work_list_done(struct lpfc_hba *phba)
 	while (!list_empty(&phba->work_list)) {
 		list_remove_head((&phba->work_list), evtp, typeof(*evtp),
 				 evt_listp);
+		/*
+		 * The ELS retry event can be requeued by lpfc_els_retry_delay()
+		 * as soon as hbalock is dropped. Consume the payload within the
+		 * hbalock to prevent reuse or double-put.
+		 */
+		if (evtp->evt == LPFC_EVT_ELS_RETRY) {
+			ndlp = (struct lpfc_nodelist *)(evtp->evt_arg1);
+			evtp->evt_arg1 = NULL;
+		}
 		spin_unlock_irq(&phba->hbalock);
 		hba_pci_err = test_bit(HBA_PCI_ERR, &phba->bit_flags);
 		free_evt = 1;
 		switch (evtp->evt) {
 		case LPFC_EVT_ELS_RETRY:
-			ndlp = (struct lpfc_nodelist *) (evtp->evt_arg1);
+			/* ndlp was already captured under hbalock */
 			if (!hba_pci_err) {
 				lpfc_els_retry_delay_handler(ndlp);
 				free_evt = 0; /* evt is part of ndlp */
drivers/scsi/mpt3sas/mpt3sas_base.c +8 -8
index 1af25a22611a..3df792a906c1 100644
@@ -3264,11 +3264,8 @@ _base_assign_reply_queues(struct MPT3SAS_ADAPTER *ioc)
 				goto fall_back;
 			}
 
-			for_each_cpu_and(cpu, mask, cpu_online_mask) {
-				if (cpu >= ioc->cpu_msix_table_sz)
-					break;
+			for_each_cpu(cpu, mask)
 				ioc->cpu_msix_table[cpu] = reply_q->msix_index;
-			}
 		}
 		return;
 	}
@@ -8410,15 +8407,18 @@ int
 mpt3sas_base_attach(struct MPT3SAS_ADAPTER *ioc)
 {
 	int r, i, rc;
-	int cpu_id, last_cpu_id = 0;
 
 	dinitprintk(ioc, ioc_info(ioc, "%s\n", __func__));
 
 	/* setup cpu_msix_table */
 	ioc->cpu_count = num_online_cpus();
-	for_each_online_cpu(cpu_id)
-		last_cpu_id = cpu_id;
-	ioc->cpu_msix_table_sz = last_cpu_id + 1;
+	/*
+	 * Allocate an entry for every possible CPU, because
+	 * _base_get_msix_index() indexes the table with
+	 * raw_smp_processor_id(), which can be a CPU brought online after
+	 * the adapter was attached.
+	 */
+	ioc->cpu_msix_table_sz = nr_cpu_ids;
 	ioc->cpu_msix_table = kzalloc(ioc->cpu_msix_table_sz, GFP_KERNEL);
 	ioc->reply_queue_count = 1;
 	if (!ioc->cpu_msix_table) {
drivers/scsi/mpt3sas/mpt3sas_ctl.c +15 -3
index 8bb947004885..b069dd384ed7 100644
@@ -57,9 +57,13 @@
 #include <linux/io.h>
 #include <linux/uaccess.h>
 
+#include <scsi/sas.h>
+
 #include "mpt3sas_base.h"
 #include "mpt3sas_ctl.h"
 
+/* PHY operation byte in an SMP PHY Control request */
+#define SMP_PHY_CONTROL_OP_OFFSET	10
 
 static struct fasync_struct *async_queue;
 static DECLARE_WAIT_QUEUE_HEAD(ctl_poll_wait);
@@ -959,13 +963,17 @@ _ctl_do_mpt_command(struct MPT3SAS_ADAPTER *ioc, struct mpt3_ioctl_command karg,
 		Mpi2SmpPassthroughRequest_t *smp_request =
 		    (Mpi2SmpPassthroughRequest_t *)mpi_request;
 		u8 *data;
+		bool immediate;
 
 		if (!ioc->multipath_on_hba) {
 			/* ioc determines which port to use */
 			smp_request->PhysicalPort = 0xFF;
 		}
-		if (smp_request->PassthroughFlags &
-		    MPI2_SMP_PT_REQ_PT_FLAGS_IMMEDIATE)
+
+		immediate = smp_request->PassthroughFlags &
+			    MPI2_SMP_PT_REQ_PT_FLAGS_IMMEDIATE;
+
+		if (immediate)
 			data = (u8 *)&smp_request->SGL;
 		else {
 			if (unlikely(data_out == NULL)) {
@@ -978,7 +986,11 @@ _ctl_do_mpt_command(struct MPT3SAS_ADAPTER *ioc, struct mpt3_ioctl_command karg,
 			data = data_out;
 		}
 
-		if (data[1] == 0x91 && (data[10] == 1 || data[10] == 2)) {
+		if ((immediate ||
+		     data_out_sz >= SMP_PHY_CONTROL_OP_OFFSET + 1) &&
+		    data[1] == SMP_PHY_CONTROL &&
+		    (data[10] == PHY_FUNC_LINK_RESET ||
+		     data[10] == PHY_FUNC_HARD_RESET)) {
 			ioc->ioc_link_reset_in_progress = 1;
 			ioc->ignore_loginfos = 1;
 		}
drivers/scsi/mpt3sas/mpt3sas_scsih.c +21 -5
index a77bbc3d2b66..04255286a2a6 100644
@@ -57,6 +57,14 @@
 
 #include "mpt3sas_base.h"
 
+/*
+ * Largest NVMe transfer whose PRP list fits in one NVME_PRP_PAGE_SIZE
+ * buffer (last entry reserved for the chain pointer) for any buffer
+ * offset: (4096 / 8 - 1) * 4096 = 2 MiB - 4 KiB.
+ */
+#define MPT3SAS_NVME_MAX_XFER \
+	((NVME_PRP_PAGE_SIZE / NVME_PRP_SIZE - 1) * NVME_PRP_PAGE_SIZE)
+
 #define RAID_CHANNEL 1
 
 #define PCIE_CHANNEL 2
@@ -2741,14 +2749,22 @@ scsih_sdev_configure(struct scsi_device *sdev, struct queue_limits *lim)
 		/*
 		 * The HBA firmware passes the NVMe drive's MDTS
 		 * (Maximum Data Transfer Size) up to the driver. However,
-		 * the driver hardcodes a 4K buffer size for the PRP list,
-		 * accommodating at most 512 entries. This strictly limits
-		 * the maximum supported NVMe I/O transfer to 2 MiB.
+		 * the driver hardcodes a 4K buffer size for the PRP list.
+		 * base_make_prp_nvme() reserves the last slot of that page
+		 * for a chain pointer, leaving 511 data PRP entries, and
+		 * PRP1 in the main message frame covers the first, possibly
+		 * partial, page.
+		 *
+		 * A transfer that is not page aligned spans one more page
+		 * than its length implies, so a 2 MiB I/O starting at a
+		 * non-zero page offset needs 512 list entries and overruns
+		 * the PRP buffer by one. Limit transfers to 511 pages, which
+		 * fits the PRP list for any starting offset.
 		 *
 		 * Cap max_hw_sectors to the smaller of the drive's reported
-		 * MDTS or the 2 MiB driver limit to prevent kernel oopses.
+		 * MDTS or the driver limit to prevent kernel oopses.
 		 */
-		lim->max_hw_sectors = SZ_2M >> SECTOR_SHIFT;
+		lim->max_hw_sectors = MPT3SAS_NVME_MAX_XFER >> SECTOR_SHIFT;
 		if (pcie_device->nvme_mdts)
 			lim->max_hw_sectors = min(lim->max_hw_sectors,
 					pcie_device->nvme_mdts >> SECTOR_SHIFT);
drivers/scsi/pm8001/pm8001_defs.h +1 -0
index a9605ca317f3..9b37a76d8b74 100644
@@ -178,6 +178,7 @@ enum port_type {
 #define	PM8001_MAX_INB_NUM	 64
 #define	PM8001_MAX_OUTB_NUM	 64
 #define	PM8001_CAN_QUEUE	 508	/* SCSI Queue depth */
+#define	PM8001_PRE_VECTORS	 1	/* non-affinitized housekeeping vector */
 
 /* Inbound/Outbound queue size */
 #define IOMB_SIZE_SPC		64
drivers/scsi/pm8001/pm8001_init.c +9 -6
index 5af81c73a8f8..b1788788b7ed 100644
@@ -104,8 +104,9 @@ static void pm8001_map_queues(struct Scsi_Host *shost)
 	struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
 	struct blk_mq_queue_map *qmap = &shost->tag_set.map[HCTX_TYPE_DEFAULT];
 
-	if (pm8001_ha->number_of_intr > 1) {
-		blk_mq_map_hw_queues(qmap, &pm8001_ha->pdev->dev, 1);
+	if (pm8001_ha->number_of_intr > PM8001_PRE_VECTORS) {
+		blk_mq_map_hw_queues(qmap, &pm8001_ha->pdev->dev,
+				     PM8001_PRE_VECTORS);
 		return;
 	}
 
@@ -977,10 +978,11 @@ static u32 pm8001_setup_msix(struct pm8001_hba_info *pm8001_ha)
 		 * include in the affinity spreading.
 		 */
 		struct irq_affinity desc = {
-			.pre_vectors = 1,
+			.pre_vectors = PM8001_PRE_VECTORS,
 		};
 		rc = pci_alloc_irq_vectors_affinity(
-				pm8001_ha->pdev, 2, PM8001_MAX_MSIX_VEC,
+				pm8001_ha->pdev, PM8001_PRE_VECTORS + 1,
+				PM8001_MAX_MSIX_VEC,
 				PCI_IRQ_MSIX | PCI_IRQ_AFFINITY, &desc);
 	}
 
@@ -1183,8 +1185,9 @@ static int pm8001_pci_probe(struct pci_dev *pdev,
 
 	PM8001_CHIP_DISP->chip_post_init(pm8001_ha);
 
-	if (pm8001_ha->number_of_intr > 1) {
-		shost->nr_hw_queues = pm8001_ha->number_of_intr - 1;
+	if (pm8001_ha->number_of_intr > PM8001_PRE_VECTORS) {
+		shost->nr_hw_queues = pm8001_ha->number_of_intr -
+				      PM8001_PRE_VECTORS;
 		/*
 		 * For now, ensure we're not sent too many commands by setting
 		 * host_tagset. This is also required if we start using request
drivers/scsi/pm8001/pm80xx_hwi.c +9 -4
index d2572dd66071..1d4f5ee861c1 100644
@@ -4328,14 +4328,19 @@ static int check_enc_sat_cmd(struct sas_task *task)
 	return ret;
 }
 
-static u32 pm80xx_chip_get_q_index(struct sas_task *task)
+static u32 pm80xx_chip_get_q_index(struct pm8001_hba_info *pm8001_ha,
+				   struct sas_task *task)
 {
 	struct request *rq = sas_task_find_rq(task);
 
 	if (!rq)
 		return 0;
 
-	return blk_mq_unique_tag_to_hwq(blk_mq_unique_tag(rq));
+	if (pm8001_ha->number_of_intr > PM8001_PRE_VECTORS)
+		return blk_mq_unique_tag_to_hwq(blk_mq_unique_tag(rq)) +
+		       PM8001_PRE_VECTORS;
+
+	return 0;
 }
 
 /**
@@ -4371,7 +4376,7 @@ static int pm80xx_chip_ssp_io_req(struct pm8001_hba_info *pm8001_ha,
 	ssp_cmd.ssp_iu.efb_prio_attr |= (task->ssp_task.task_attr & 7);
 	memcpy(ssp_cmd.ssp_iu.cdb, task->ssp_task.cmd->cmnd,
 		       task->ssp_task.cmd->cmd_len);
-	q_index = pm80xx_chip_get_q_index(task);
+	q_index = pm80xx_chip_get_q_index(pm8001_ha, task);
 
 	/* Check if encryption is set */
 	if (pm8001_ha->chip->encrypt &&
@@ -4510,7 +4515,7 @@ static int pm80xx_chip_sata_req(struct pm8001_hba_info *pm8001_ha,
 	u32 opc = OPC_INB_SATA_HOST_OPSTART;
 	memset(&sata_cmd, 0, sizeof(sata_cmd));
 
-	q_index = pm80xx_chip_get_q_index(task);
+	q_index = pm80xx_chip_get_q_index(pm8001_ha, task);
 
 	if (task->data_dir == DMA_NONE && !task->ata_task.use_ncq) {
 		ATAP = 0x04; /* no data*/
drivers/scsi/scsi_ioctl.c +15 -1
index bf049d9cb719..91525103d074 100644
@@ -300,7 +300,6 @@ bool scsi_cmd_allowed(unsigned char *cmd, bool open_for_write)
 	case GPCMD_VERIFY_10:
 	case VERIFY_16:
 	case REPORT_LUNS:
-	case SERVICE_ACTION_IN_16:
 	case RECEIVE_DIAGNOSTIC:
 	case MAINTENANCE_IN: /* also GPCMD_SEND_KEY, which is a write command */
 	case GPCMD_READ_BUFFER_CAPACITY:
@@ -330,6 +329,21 @@ bool scsi_cmd_allowed(unsigned char *cmd, bool open_for_write)
 	/* ZBC */
 	case ZBC_IN:
 		return true;
+	/*
+	 * The storage element depopulation commands share the opcode of the
+	 * read-only SERVICE ACTION IN(16) commands, but change the capacity
+	 * of the device and may destroy its data, so treat them as writing
+	 * commands.
+	 */
+	case SERVICE_ACTION_IN_16:
+		switch (cmd[1] & 0x1f) {
+		case SAI_REMOVE_ELEMENT_AND_TRUNCATE:
+		case SAI_RESTORE_ELEMENTS_AND_REBUILD:
+		case SAI_REMOVE_ELEMENT_AND_MODIFY_ZONES:
+			return open_for_write;
+		default:
+			return true;
+		}
 	/* Basic writing commands */
 	case WRITE_6:
 	case WRITE_10:
drivers/target/iscsi/iscsi_target.c +12 -2
index 03d618cd7672..2b4956f46c13 100644
@@ -4485,8 +4485,8 @@ int iscsit_close_session(struct iscsit_session *sess, bool can_sleep)
 
 	/*
 	 * If any other processes are accessing this session pointer we must
-	 * wait until they have completed.  If we are in an interrupt (the
-	 * time2retain handler) and contain and active session usage count we
+	 * wait until they have completed.  If we are the Time2Retain work
+	 * (can_sleep is false) and contain and active session usage count we
 	 * restart the timer and exit.
 	 */
 	if (iscsit_check_session_usage_count(sess, can_sleep)) {
@@ -4516,6 +4516,16 @@ int iscsit_close_session(struct iscsit_session *sess, bool can_sleep)
 	sess->sess_ops = NULL;
 	spin_unlock_bh(&se_tpg->session_lock);
 
+	/*
+	 * Neither the Time2Retain timer nor its work may outlive the session;
+	 * a work never runs twice at once, so this work finds a queued one.
+	 */
+	timer_delete_sync(&sess->time2retain_timer);
+	if (can_sleep)
+		cancel_work_sync(&sess->time2retain_work);
+	else
+		cancel_work(&sess->time2retain_work);
+
 	kfree(sess);
 	return 0;
 }
drivers/target/iscsi/iscsi_target_erl0.c +16 -4
index 24db6b07493e..036ddc1002f6 100644
@@ -741,15 +741,17 @@ int iscsit_check_post_dataout(
 	}
 }
 
-void iscsit_handle_time2retain_timeout(struct timer_list *t)
+void iscsit_time2retain_work(struct work_struct *work)
 {
-	struct iscsit_session *sess = timer_container_of(sess, t,
-							 time2retain_timer);
+	struct iscsit_session *sess = container_of(work, struct iscsit_session,
+						   time2retain_work);
 	struct iscsi_portal_group *tpg = sess->tpg;
 	struct se_portal_group *se_tpg = &tpg->tpg_se_tpg;
 
 	spin_lock_bh(&se_tpg->session_lock);
-	if (sess->time2retain_timer_flags & ISCSI_TF_STOP) {
+	/* A stop after the timer fired takes ->time2retain_fired back. */
+	if (!atomic_xchg(&sess->time2retain_fired, 0) ||
+	    (sess->time2retain_timer_flags & ISCSI_TF_STOP)) {
 		spin_unlock_bh(&se_tpg->session_lock);
 		return;
 	}
@@ -769,6 +771,15 @@ void iscsit_handle_time2retain_timeout(struct timer_list *t)
 	iscsit_close_session(sess, false);
 }
 
+void iscsit_handle_time2retain_timeout(struct timer_list *t)
+{
+	struct iscsit_session *sess = timer_container_of(sess, t,
+							 time2retain_timer);
+
+	atomic_set(&sess->time2retain_fired, 1);
+	queue_work(system_dfl_wq, &sess->time2retain_work);
+}
+
 void iscsit_start_time2retain_handler(struct iscsit_session *sess)
 {
 	int tpg_active;
@@ -814,6 +825,7 @@ int iscsit_stop_time2retain_timer(struct iscsit_session *sess)
 	timer_delete_sync(&sess->time2retain_timer);
 
 	spin_lock(&se_tpg->session_lock);
+	atomic_set(&sess->time2retain_fired, 0);
 	sess->time2retain_timer_flags &= ~ISCSI_TF_RUNNING;
 	pr_debug("Stopped Time2Retain Timer for SID: %u\n",
 			sess->sid);
drivers/target/iscsi/iscsi_target_erl0.h +1 -0
index 2a877d13977d..f0e157b0a2f5 100644
@@ -13,6 +13,7 @@ extern int iscsit_check_pre_dataout(struct iscsit_cmd *, unsigned char *);
 extern int iscsit_check_post_dataout(struct iscsit_cmd *, unsigned char *, u8);
 extern void iscsit_start_time2retain_handler(struct iscsit_session *);
 extern void iscsit_handle_time2retain_timeout(struct timer_list *t);
+void iscsit_time2retain_work(struct work_struct *work);
 extern int iscsit_stop_time2retain_timer(struct iscsit_session *);
 extern void iscsit_connection_reinstatement_rcfr(struct iscsit_conn *);
 extern void iscsit_cause_connection_reinstatement(struct iscsit_conn *, int);
drivers/target/iscsi/iscsi_target_login.c +1 -0
index c282b6a70296..fda04eb15d3a 100644
@@ -250,6 +250,7 @@ static int iscsi_login_zero_tsih_s1(
 
 	timer_setup(&sess->time2retain_timer,
 		    iscsit_handle_time2retain_timeout, 0);
+	INIT_WORK(&sess->time2retain_work, iscsit_time2retain_work);
 
 	ret = ida_alloc(&sess_ida, GFP_KERNEL);
 	if (ret < 0) {
drivers/target/target_core_fabric_lib.c +5 -4
index ad024009df56..ccfeba64518c 100644
@@ -372,10 +372,11 @@ static bool iscsi_parse_pr_out_transport_id(
 			return false;
 		}
 		/*
-		 * The registration code reads the ISID as a C string,
-		 * and its first 8 bytes with get_unaligned_be64(), so
-		 * require 8 bytes after the separator and a NUL inside
-		 * the rest of the descriptor.
+		 * The registration code reads the ISID as a C string, so
+		 * require a NUL inside the rest of the descriptor.  Keep the
+		 * existing minimum of 8 bytes after the separator: a valid
+		 * ISID is twelve hex digits, and target_isid_to_bin() falls
+		 * back to the first eight characters of anything else.
 		 */
 		if (buf + tid_len - p < 8 || !memchr(p, '\0', buf + tid_len - p)) {
 			pr_err("Incomplete or unterminated ISID in iSCSI Initiator port TransportID\n");
drivers/target/target_core_pr.c +42 -4

82 lines not on this page · raw message

drivers/target/target_core_pr.h +1 -0
index b793c99637ab..4debfe4be4d6 100644
@@ -72,6 +72,7 @@ extern void core_scsi3_free_pr_reg_from_nacl(struct se_device *,
 					     struct se_node_acl *);
 extern void core_scsi3_free_all_registrations(struct se_device *);
 extern unsigned char *core_scsi3_pr_dump_type(int);
+u64 target_isid_to_bin(const char *isid);
 
 extern sense_reason_t target_scsi3_emulate_pr_in(struct se_cmd *);
 extern sense_reason_t target_scsi3_emulate_pr_out(struct se_cmd *);
drivers/target/target_core_sbc.c +6 -0
index 21f5cb86d70c..560e62cef7dd 100644
@@ -721,6 +721,12 @@ sbc_check_prot(struct se_device *dev, struct se_cmd *cmd, unsigned char protect,
 	if (sbc_set_prot_op_checks(protect, fabric_prot, pi_prot_type, is_write, cmd))
 		return TCM_INVALID_CDB_FIELD;
 
+	if (!sectors) {
+		cmd->prot_op = TARGET_PROT_NORMAL;
+		cmd->prot_checks = 0;
+		pi_prot_type = TARGET_DIF_TYPE0_PROT;
+	}
+
 	cmd->prot_type = pi_prot_type;
 	cmd->prot_length = dev->prot_length * sectors;
 
drivers/target/target_core_transport.c +1 -1
index 927861c30afc..4629c9343bb6 100644
@@ -419,7 +419,7 @@ void __transport_register_session(
 			memset(&buf[0], 0, PR_REG_ISID_LEN);
 			se_tpg->se_tpg_tfo->sess_get_initiator_sid(se_sess,
 					&buf[0], PR_REG_ISID_LEN);
-			se_sess->sess_bin_isid = get_unaligned_be64(&buf[0]);
+			se_sess->sess_bin_isid = target_isid_to_bin(buf);
 		}
 
 		spin_lock_irqsave(&se_nacl->nacl_sess_lock, flags);
drivers/ufs/core/ufs-rpmb.c +44 -40

220 lines not on this page · raw message

drivers/ufs/host/ufs-mediatek.c +20 -1
index 5b6bff2cf9a2..caf186966c91 100644
@@ -541,6 +541,16 @@ static int ufs_mtk_mphy_power_on(struct ufs_hba *hba, bool on)
 		if (ufs_mtk_is_va09_supported(hba)) {
 			ufs_mtk_va09_pwr_ctrl(res, 0);
 			ret = regulator_disable(host->reg_va09);
+			if (ret) {
+				/*
+				 * The va09 regulator stays enabled, so
+				 * bring the M-PHY back up to keep the
+				 * software state in sync with the
+				 * hardware.
+				 */
+				ufs_mtk_va09_pwr_ctrl(res, 1);
+				phy_power_on(mphy);
+			}
 		}
 	}
 out:
@@ -692,7 +702,7 @@ static void ufs_mtk_init_va09_pwr_ctrl(struct ufs_hba *hba)
 {
 	struct ufs_mtk_host *host = ufshcd_get_variant(hba);
 
-	host->reg_va09 = regulator_get(hba->dev, "va09");
+	host->reg_va09 = devm_regulator_get(hba->dev, "va09");
 	if (IS_ERR(host->reg_va09))
 		dev_info(hba->dev, "failed to get va09");
 	else
@@ -1331,6 +1341,14 @@ static int ufs_mtk_init(struct ufs_hba *hba)
 	return err;
 }
 
+static void ufs_mtk_exit(struct ufs_hba *hba)
+{
+	struct ufs_mtk_host *host = ufshcd_get_variant(hba);
+
+	if (host)
+		ufs_mtk_mphy_power_on(hba, false);
+}
+
 static int ufs_mtk_negotiate_pwr_mode(struct ufs_hba *hba,
 				      const struct ufs_pa_layer_attr *dev_max_params,
 				      struct ufs_pa_layer_attr *dev_req_params)
@@ -2353,6 +2371,7 @@ static void ufs_mtk_config_scsi_dev(struct scsi_device *sdev)
 static const struct ufs_hba_variant_ops ufs_hba_mtk_vops = {
 	.name                = "mediatek.ufshci",
 	.init                = ufs_mtk_init,
+	.exit                = ufs_mtk_exit,
 	.get_ufs_hci_version = ufs_mtk_get_ufs_hci_version,
 	.setup_clocks        = ufs_mtk_setup_clocks,
 	.hce_enable_notify   = ufs_mtk_hce_enable_notify,
drivers/ufs/host/ufshcd-pci.c +2 -2
index 668b57403e62..f9abbbc436f4 100644
@@ -644,7 +644,7 @@ static int ufshcd_pci_suspend_prepare(struct device *dev)
 {
 	struct ufs_hba *hba = dev_get_drvdata(dev);
 
-	if (!strcmp(hba->vops->name, "intel-pci"))
+	if (hba->vops && !strcmp(hba->vops->name, "intel-pci"))
 		return ufs_intel_suspend_prepare(dev);
 
 	return ufshcd_suspend_prepare(dev);
@@ -654,7 +654,7 @@ static void ufshcd_pci_resume_complete(struct device *dev)
 {
 	struct ufs_hba *hba = dev_get_drvdata(dev);
 
-	if (!strcmp(hba->vops->name, "intel-pci")) {
+	if (hba->vops && !strcmp(hba->vops->name, "intel-pci")) {
 		ufs_intel_resume_complete(dev);
 		return;
 	}
include/linux/rpmb.h +3 -0
index ed3f8e431eff..11a5d2646e38 100644
@@ -7,6 +7,7 @@
 #define __RPMB_H__
 
 #include <linux/device.h>
+#include <linux/mutex.h>
 #include <linux/types.h>
 
 /**
@@ -48,12 +49,14 @@ struct rpmb_descr {
  * struct rpmb_dev - device which can support RPMB partition
  *
  * @dev              : device
+ * @lock             : serialises requests and protects them against teardown
  * @id               : device_id
  * @list_node        : linked list node
  * @descr            : RPMB description
  */
 struct rpmb_dev {
 	struct device dev;
+	struct mutex lock;
 	int id;
 	struct list_head list_node;
 	struct rpmb_descr descr;
include/target/iscsi/iscsi_target_core.h +3 -0
index 51ca80abacf7..5cc688b3f7d1 100644
@@ -7,6 +7,7 @@
 #include <linux/sched.h>
 #include <linux/socket.h>            /* struct sockaddr_storage */
 #include <linux/types.h>             /* u8 */
+#include <linux/workqueue.h>         /* struct work_struct */
 #include <scsi/iscsi_proto.h>        /* itt_t */
 #include <target/target_core_base.h> /* struct se_cmd */
 
@@ -682,6 +683,8 @@ struct iscsit_session {
 	struct completion	session_wait_comp;
 	struct completion	session_waiting_on_uc_comp;
 	struct timer_list	time2retain_timer;
+	struct work_struct	time2retain_work;
+	atomic_t		time2retain_fired;
 	struct iscsi_sess_ops	*sess_ops;
 	struct se_session	*se_sess;
 	struct iscsi_portal_group *tpg;