Compare

2fabd2f406d0cf787be47b3bbeea99b30004033d..8ee2a09a1dbb257c9e828ad2497f8e4832dfb142

scsi: libiscsi: Reject a negative task index from parse_pdu_itt

A transport that implements parse_pdu_itt hands libiscsi an index taken
from the PDU, and both lookups bound it from above only:

      if (i >= session->cmds_max)

i and cmds_max are both int, so a negative index passes and
session->cmds[i] is read from before the array.

be2iscsi produces one. beiscsi_parse_pdu() assigns the raw tag,

      *index = (int)itt;

and beiscsi_complete_pdu() forwards an unsolicited NOP-In from the
hardware async ring without replacing its ITT, so the value is the
target's. It also reports the session's own age rather than the one in
the tag, which leaves the age comparison in iscsi_verify_itt() with
nothing to reject.

Bound the index from below in both lookups.

Fixes: bfead3b2cb46 ("[SCSI] be2iscsi: Adding msix and mcc_rings V3")
Cc: stable@vger.kernel.org
Reviewed-by: Mike Christie <michael.christie@oracle.com>
Signed-off-by: Yehyeong Lee <yhlee@isslab.korea.ac.kr>
Link: https://patch.msgid.link/20261007015842.634893-2-yhlee@isslab.korea.ac.kr
Signed-off-by: Martin K. Petersen (Oracle) <mkp@kernel.org>

Yehyeong Lee <yhlee@isslab.korea.ac.kr> · 2026-10-07 01:58 UTC · committed by Martin K. Petersen (Oracle)

Browse files
37 files changed, +394 −151
modified arch/arm/boot/dts/ti/omap/dra7xx-clocks.dtsi
@@ -1376,8 +1376,8 @@
1376 1376 clocks = <&apll_pcie_ck>;
1377 1377 #clock-cells = <0>;
1378 1378 reg = <0x021c>;
1379 - ti,dividers = <2>, <1>;
1380 1379 ti,bit-shift = <8>;
1380 + ti,max-div = <2>;
1381 1381 };
1382 1382
1383 1383 apll_pcie_clkvcoldo: clock-apll-pcie-clkvcoldo {
modified block/blk-zoned.c
@@ -2018,12 +2018,17 @@ static int disk_revalidate_zone_resources(struct gendisk *disk,
2018 2018 struct blk_revalidate_zone_args *args)
2019 2019 {
2020 2020 struct queue_limits *lim = &disk->queue->limits;
2021 + unsigned long long nr_zones;
2021 2022 unsigned int pool_size;
2022 2023 int ret = 0;
2023 2024
2024 2025 args->disk = disk;
2025 - args->nr_zones =
2026 - DIV_ROUND_UP_ULL(get_capacity(disk), lim->chunk_sectors);
2026 + nr_zones = DIV_ROUND_UP_ULL(get_capacity(disk), lim->chunk_sectors);
2027 + if (nr_zones > UINT_MAX) {
2028 + pr_warn("%s: Too many zones (%llu)\n", disk->disk_name, nr_zones);
2029 + return -EINVAL;
2030 + }
2031 + args->nr_zones = nr_zones;
2027 2032
2028 2033 /* Cached zone conditions: 1 byte per zone */
2029 2034 args->zones_cond = kzalloc(args->nr_zones, GFP_NOIO);
@@ -2131,6 +2136,12 @@ static int blk_revalidate_zone_cond(struct blk_zone *zone, unsigned int idx,
2131 2136 {
2132 2137 enum blk_zone_cond cond = zone->cond;
2133 2138
2139 + if (idx >= args->nr_zones) {
2140 + pr_warn("%s: Zone report index %u exceeds zone count %u\n",
2141 + args->disk->disk_name, idx, args->nr_zones);
2142 + return -EINVAL;
2143 + }
2144 +
2134 2145 /* Check that the zone condition is consistent with the zone type. */
2135 2146 switch (cond) {
2136 2147 case BLK_ZONE_COND_NOT_WP:
modified drivers/scsi/Kconfig
@@ -753,6 +753,7 @@ config SCSI_IBMVFC
753 753 tristate "IBM Virtual FC support"
754 754 depends on PPC_PSERIES && SCSI
755 755 depends on SCSI_FC_ATTRS
756 + depends on NVME_FC || NVME_FC=n
756 757 help
757 758 This is the IBM POWER Virtual FC Client
758 759
modified drivers/scsi/ch.c
@@ -112,7 +112,6 @@ typedef struct {
112 112 int minor;
113 113 char name[8];
114 114 struct scsi_device *device;
115 - struct scsi_device **dt; /* ptrs to data transfer elements */
116 115 u_int firsts[CH_TYPES];
117 116 u_int counts[CH_TYPES];
118 117 u_int voltags;
@@ -363,15 +362,10 @@ ch_readconfig(scsi_changer *ch)
363 362 vendor_labels[i]);
364 363 }
365 364
366 - /* look up the devices of the data transfer elements */
367 - ch->dt = kzalloc_objs(*ch->dt, ch->counts[CHET_DT]);
368 -
369 - if (!ch->dt) {
370 - kfree(buffer);
371 - return -ENOMEM;
372 - }
373 -
365 + /* report the devices of the data transfer elements */
374 366 for (elem = 0; elem < ch->counts[CHET_DT]; elem++) {
367 + struct scsi_device *sdev;
368 +
375 369 id = -1;
376 370 lun = 0;
377 371 if (elem < CH_DT_MAX && -1 != dt_id[elem]) {
@@ -387,10 +381,8 @@ ch_readconfig(scsi_changer *ch)
387 381 VPRINTK(KERN_INFO, "dt 0x%x: ",elem+ch->firsts[CHET_DT]);
388 382 if (data[6] & 0x80) {
389 383 VPRINTK(KERN_CONT, "not this SCSI bus\n");
390 - ch->dt[elem] = NULL;
391 384 } else if (0 == (data[6] & 0x30)) {
392 385 VPRINTK(KERN_CONT, "ID/LUN unknown\n");
393 - ch->dt[elem] = NULL;
394 386 } else {
395 387 id = ch->device->id;
396 388 lun = 0;
@@ -400,18 +392,16 @@ ch_readconfig(scsi_changer *ch)
400 392 }
401 393 if (-1 != id) {
402 394 VPRINTK(KERN_CONT, "ID %i, LUN %i, ",id,lun);
403 - ch->dt[elem] =
404 - scsi_device_lookup(ch->device->host,
405 - ch->device->channel,
406 - id,lun);
407 - if (!ch->dt[elem]) {
395 + sdev = scsi_device_lookup(ch->device->host,
396 + ch->device->channel,
397 + id, lun);
398 + if (!sdev) {
408 399 /* should not happen */
409 400 VPRINTK(KERN_CONT, "Huh? device not found!\n");
410 401 } else {
411 402 VPRINTK(KERN_CONT, "name: %8.8s %16.16s %4.4s\n",
412 - ch->dt[elem]->vendor,
413 - ch->dt[elem]->model,
414 - ch->dt[elem]->rev);
403 + sdev->vendor, sdev->model, sdev->rev);
404 + scsi_device_put(sdev);
415 405 }
416 406 }
417 407 }
@@ -575,7 +565,6 @@ static void ch_destroy(struct kref *ref)
575 565 scsi_changer *ch = container_of(ref, scsi_changer, ref);
576 566
577 567 ch->device = NULL;
578 - kfree(ch->dt);
579 568 kfree(ch);
580 569 }
581 570
modified drivers/scsi/fnic/fnic.h
@@ -31,7 +31,7 @@
31 31
32 32 #define DRV_NAME "fnic"
33 33 #define DRV_DESCRIPTION "Cisco FCoE HBA Driver"
34 - #define DRV_VERSION "1.9.0.0"
34 + #define DRV_VERSION "1.9.0.1"
35 35 #define PFX DRV_NAME ": "
36 36 #define DFX DRV_NAME "%d: "
37 37
modified drivers/scsi/fnic/fnic_isr.c
@@ -245,7 +245,14 @@ int fnic_set_intr_mode_msix(struct fnic *fnic)
245 245 unsigned int m = ARRAY_SIZE(fnic->wq);
246 246 unsigned int o = ARRAY_SIZE(fnic->hw_copy_wq);
247 247 unsigned int min_irqs = n + m + 1 + 1; /*rq, raw wq, wq, err*/
248 -
248 + /*
249 + * Make driver critical vectors unmanaged, or else it can get tied
250 + * to an offline CPU. This can happen when hyper-threading is off.
251 + */
252 + struct irq_affinity affd = {
253 + .pre_vectors = n + m + 1, /* rq, raw wq, 1 ioq */
254 + .post_vectors = 1, /* err */
255 + };
249 256 /*
250 257 * We need n RQs, m WQs, o Copy WQs, n+m+o CQs, and n+m+o+1 INTRs
251 258 * (last INTR is used for WQ/RQ errors and notification area)
@@ -263,8 +270,8 @@ int fnic_set_intr_mode_msix(struct fnic *fnic)
263 270 int vec_count = 0;
264 271 int vecs = fnic->rq_count + fnic->raw_wq_count + fnic->wq_copy_count + 1;
265 272
266 - vec_count = pci_alloc_irq_vectors(fnic->pdev, min_irqs, vecs,
267 - PCI_IRQ_MSIX | PCI_IRQ_AFFINITY);
273 + vec_count = pci_alloc_irq_vectors_affinity(fnic->pdev, min_irqs,
274 + vecs, PCI_IRQ_MSIX|PCI_IRQ_AFFINITY, &affd);
268 275 FNIC_ISR_DBG(KERN_INFO, fnic,
269 276 "allocated %d MSI-X vectors\n",
270 277 vec_count);
modified drivers/scsi/fnic/fnic_main.c
@@ -744,8 +744,19 @@ out_free_ioreq_tables:
744 744 return ret;
745 745 }
746 746
747 + static void fnic_mq_init_queue_map(struct fnic *fnic,
748 + struct blk_mq_queue_map *qmap)
749 + {
750 + unsigned int cpu;
751 +
752 + for_each_possible_cpu(cpu)
753 + qmap->mq_map[cpu] = 0;
754 + }
755 +
747 756 void fnic_mq_map_queues_cpus(struct Scsi_Host *host)
748 757 {
758 + const struct cpumask *mask;
759 + unsigned int queue, cpu;
749 760 struct fnic *fnic = *((struct fnic **) shost_priv(host));
750 761 struct pci_dev *l_pdev = fnic->pdev;
751 762 int intr_mode = fnic->config.intr_mode;
@@ -766,7 +777,35 @@ void fnic_mq_map_queues_cpus(struct Scsi_Host *host)
766 777 return;
767 778 }
768 779
769 - blk_mq_map_hw_queues(qmap, &l_pdev->dev, FNIC_PCI_OFFSET);
780 + fnic_mq_init_queue_map(fnic, qmap);
781 +
782 + /*
783 + * Setup CPU to Queue mapping for all managed MSI-X IRQs.
784 + * Q0 is driver critical and non-managed, hence start from Q1.
785 + */
786 + for (queue = 1; queue < qmap->nr_queues; queue++) {
787 + int irq_num = pci_irq_vector(fnic->pdev,
788 + queue + FNIC_PCI_OFFSET);
789 +
790 + if (irq_num < 0)
791 + continue;
792 +
793 + mask = pci_irq_get_affinity(fnic->pdev,
794 + queue + FNIC_PCI_OFFSET);
795 + if (!mask) {
796 + shost_printk(KERN_ERR, host,
797 + "failed to get irq_affinity map for queue:%d\n", irq_num);
798 + continue;
799 + }
800 + FNIC_MAIN_DBG(KERN_INFO, fnic,
801 + "got irq_affinity map for %d:\n", irq_num);
802 + for_each_cpu(cpu, mask) {
803 + qmap->mq_map[cpu] = qmap->queue_offset + queue;
804 + FNIC_MAIN_DBG(KERN_INFO, fnic,
805 + "[Q%d] cpu:%d <=> irq:%d\n",
806 + queue, cpu, irq_num);
807 + }
808 + }
770 809 }
771 810
772 811 static int fnic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
modified drivers/scsi/fnic/fnic_nvme.c
@@ -2216,7 +2216,7 @@ int nvfnic_add_tport(struct fnic *fnic, struct fnic_tport_s *tport,
2216 2216
2217 2217 int nvfnic_add_lport(struct fnic *fnic)
2218 2218 {
2219 - struct nvme_fc_port_info pinfo;
2219 + struct nvme_fc_port_info pinfo = {};
2220 2220 struct fnic_iport_s *iport = &fnic->iport;
2221 2221 int ret = 0;
2222 2222
modified drivers/scsi/ibmvscsi/ibmvfc-core.c
@@ -1894,7 +1894,7 @@ static void ibmvfc_log_error(struct ibmvfc_event *evt)
1894 1894 }
1895 1895
1896 1896 /**
1897 - * ibmvfc_relogin - Log back into the specified device
1897 + * ibmvfc_scsi_relogin - Log back into the specified device
1898 1898 * @sdev: scsi device struct
1899 1899 *
1900 1900 **/
@@ -4987,6 +4987,7 @@ static void ibmvfc_tgt_query_target(struct ibmvfc_target *tgt)
4987 4987 * ibmvfc_alloc_target - Allocate and initialize an ibmvfc target
4988 4988 * @vhost: ibmvfc host struct
4989 4989 * @target: Holds SCSI ID to allocate target forand the WWPN
4990 + * @protocol: protocol of the target to allocate
4990 4991 *
4991 4992 * Returns:
4992 4993 * 0 on success / other on failure
modified drivers/scsi/leapraid/leapraid_func.h
@@ -554,7 +554,6 @@ struct leapraid_fw_evt_work {
554 554 /**
555 555 * struct leapraid_fw_evt_struct - Firmware event handling structure
556 556 *
557 - * @fw_evt_name: Name of the firmware event.
558 557 * @fw_evt_thread: Workqueue used for processing firmware events.
559 558 * @fw_evt_lock: Spinlock protecting access to the firmware event list.
560 559 * @fw_evt_list: Linked list of pending firmware events.
@@ -565,7 +564,6 @@ struct leapraid_fw_evt_work {
565 564 */
566 565 struct leapraid_fw_evt_struct {
567 566 u32 leapraid_evt_masks[4];
568 - char fw_evt_name[48];
569 567 struct workqueue_struct *fw_evt_thread;
570 568 spinlock_t fw_evt_lock; /* protects firmware event */
571 569 struct list_head fw_evt_list;
modified drivers/scsi/leapraid/leapraid_os.c
@@ -2054,12 +2054,10 @@ static int leapraid_probe(struct pci_dev *pdev, const struct pci_device_id *id)
2054 2054 shost->transportt = leapraid_transport_template;
2055 2055 shost->unique_id = adapter->adapter_attr.id;
2056 2056
2057 - snprintf(adapter->fw_evt_s.fw_evt_name,
2058 - sizeof(adapter->fw_evt_s.fw_evt_name),
2059 - "fw_event_%s%d", LEAPRAID_DRIVER_NAME,
2060 - adapter->adapter_attr.id);
2061 2057 adapter->fw_evt_s.fw_evt_thread =
2062 - alloc_ordered_workqueue(adapter->fw_evt_s.fw_evt_name, 0);
2058 + alloc_ordered_workqueue("fw_event_%s%d", 0,
2059 + LEAPRAID_DRIVER_NAME,
2060 + adapter->adapter_attr.id);
2063 2061 if (!adapter->fw_evt_s.fw_evt_thread) {
2064 2062 dev_err(&adapter->pdev->dev,
2065 2063 "%s: Failed to create fw event workqueue\n", __func__);
modified drivers/scsi/libiscsi.c
@@ -1191,7 +1191,7 @@ struct iscsi_task *iscsi_itt_to_task(struct iscsi_conn *conn, itt_t itt)
1191 1191 session->tt->parse_pdu_itt(conn, itt, &i, NULL);
1192 1192 else
1193 1193 i = get_itt(itt);
1194 - if (i >= session->cmds_max)
1194 + if (i < 0 || i >= session->cmds_max)
1195 1195 return NULL;
1196 1196
1197 1197 return session->cmds[i];
@@ -1384,7 +1384,7 @@ int iscsi_verify_itt(struct iscsi_conn *conn, itt_t itt)
1384 1384 return ISCSI_ERR_BAD_ITT;
1385 1385 }
1386 1386
1387 - if (i >= session->cmds_max) {
1387 + if (i < 0 || i >= session->cmds_max) {
1388 1388 iscsi_conn_printk(KERN_ERR, conn,
1389 1389 "received invalid itt index %u (max cmds "
1390 1390 "%u.\n", i, session->cmds_max);
modified drivers/scsi/libiscsi_tcp.c
@@ -480,6 +480,9 @@ static int iscsi_tcp_data_in(struct iscsi_conn *conn, struct iscsi_task *task)
480 480 int datasn = be32_to_cpu(rhdr->datasn);
481 481 unsigned total_in_length = task->sc->sdb.length;
482 482
483 + if (task->sc->sc_data_direction != DMA_FROM_DEVICE)
484 + return ISCSI_ERR_PROTO;
485 +
483 486 /*
484 487 * lib iscsi will update this in the completion handling if there
485 488 * is status.
modified drivers/scsi/megaraid/megaraid_sas_base.c
@@ -1973,12 +1973,23 @@ megasas_set_nvme_device_properties(struct scsi_device *sdev,
1973 1973 {
1974 1974 struct megasas_instance *instance;
1975 1975 u32 mr_nvme_pg_size;
1976 + u64 max_prp_io;
1976 1977
1977 1978 instance = (struct megasas_instance *)sdev->host->hostdata;
1978 1979 mr_nvme_pg_size = max_t(u32, instance->nvme_page_size,
1979 1980 MR_DEFAULT_NVME_PAGE_SIZE);
1980 1981
1981 - lim->max_hw_sectors = max_io_size / 512;
1982 + /*
1983 + * megasas_make_prp_nvme() builds the PRP list in cmd->sg_frame without
1984 + * bounding it against that buffer, and spends one entry per page of
1985 + * it on the chain pointer. Cap the transfer at what the buffer holds,
1986 + * less one page for lists that start off a page boundary.
1987 + */
1988 + max_prp_io = (u64)((instance->max_chain_frame_sz / sizeof(u64)) -
1989 + (instance->max_chain_frame_sz / mr_nvme_pg_size) - 1) *
1990 + mr_nvme_pg_size;
1991 +
1992 + lim->max_hw_sectors = min_t(u64, max_io_size, max_prp_io) >> SECTOR_SHIFT;
1982 1993 lim->virt_boundary_mask = mr_nvme_pg_size - 1;
1983 1994 }
1984 1995
@@ -7875,7 +7886,9 @@ megasas_resume(struct device *dev)
7875 7886 goto fail_init_mfi;
7876 7887 }
7877 7888
7878 - if (megasas_get_ctrl_info(instance) != DCMD_SUCCESS)
7889 + scoped_guard(mutex, &instance->reset_mutex)
7890 + rval = megasas_get_ctrl_info(instance);
7891 + if (rval != DCMD_SUCCESS)
7879 7892 goto fail_init_mfi;
7880 7893
7881 7894 tasklet_init(&instance->isr_tasklet, instance->instancet->tasklet,
modified drivers/scsi/mpi3mr/mpi3mr_os.c
@@ -1094,10 +1094,13 @@ static void mpi3mr_refresh_tgtdevs(struct mpi3mr_ioc *mrioc)
1094 1094 {
1095 1095 struct mpi3mr_tgt_dev *tgtdev, *tgtdev_next;
1096 1096 struct mpi3mr_stgt_priv_data *tgt_priv;
1097 + struct scsi_target *starget;
1098 + unsigned long flags;
1097 1099
1098 1100 dprint_reset(mrioc, "refresh target devices: check for removals\n");
1099 1101 list_for_each_entry_safe(tgtdev, tgtdev_next, &mrioc->tgtdev_list,
1100 1102 list) {
1103 + spin_lock_irqsave(&mrioc->tgtdev_lock, flags);
1101 1104 if (((tgtdev->dev_handle == MPI3MR_INVALID_DEV_HANDLE) ||
1102 1105 tgtdev->is_hidden) &&
1103 1106 tgtdev->host_exposed && tgtdev->starget &&
@@ -1106,6 +1109,7 @@ static void mpi3mr_refresh_tgtdevs(struct mpi3mr_ioc *mrioc)
1106 1109 tgt_priv->dev_removed = 1;
1107 1110 atomic_set(&tgt_priv->block_io, 0);
1108 1111 }
1112 + spin_unlock_irqrestore(&mrioc->tgtdev_lock, flags);
1109 1113 }
1110 1114
1111 1115 list_for_each_entry_safe(tgtdev, tgtdev_next, &mrioc->tgtdev_list,
@@ -1127,15 +1131,25 @@ static void mpi3mr_refresh_tgtdevs(struct mpi3mr_ioc *mrioc)
1127 1131 tgtdev = NULL;
1128 1132 list_for_each_entry(tgtdev, &mrioc->tgtdev_list, list) {
1129 1133 if ((tgtdev->dev_handle != MPI3MR_INVALID_DEV_HANDLE) &&
1130 - !tgtdev->is_hidden) {
1131 - if (!tgtdev->host_exposed)
1134 + !tgtdev->is_hidden) {
1135 + if (!tgtdev->host_exposed) {
1132 1136 mpi3mr_report_tgtdev_to_host(mrioc,
1133 - tgtdev->perst_id);
1134 - else if (tgtdev->starget)
1135 - starget_for_each_device(tgtdev->starget,
1136 - (void *)tgtdev, mpi3mr_update_sdev);
1137 - }
1137 + tgtdev->perst_id);
1138 + continue;
1139 + }
1140 + spin_lock_irqsave(&mrioc->tgtdev_lock, flags);
1141 + starget = tgtdev->starget;
1142 + if (starget)
1143 + get_device(&starget->dev);
1144 + spin_unlock_irqrestore(&mrioc->tgtdev_lock, flags);
1145 + if (starget) {
1146 + starget_for_each_device(starget, (void *)tgtdev,
1147 + mpi3mr_update_sdev);
1148 + put_device(&starget->dev);
1149 + }
1150 + }
1138 1151 }
1152 + dprint_reset(mrioc, "refresh target devices: done\n");
1139 1153 }
1140 1154
1141 1155 /**
@@ -1515,6 +1529,8 @@ static void mpi3mr_devinfochg_evt_bh(struct mpi3mr_ioc *mrioc,
1515 1529 struct mpi3_device_page0 *dev_pg0)
1516 1530 {
1517 1531 struct mpi3mr_tgt_dev *tgtdev = NULL;
1532 + struct scsi_target *starget;
1533 + unsigned long flags;
1518 1534 u16 dev_handle = 0, perst_id = 0;
1519 1535
1520 1536 perst_id = le16_to_cpu(dev_pg0->persistent_id);
@@ -1535,9 +1551,18 @@ static void mpi3mr_devinfochg_evt_bh(struct mpi3mr_ioc *mrioc,
1535 1551 mpi3mr_report_tgtdev_to_host(mrioc, perst_id);
1536 1552 if (tgtdev->is_hidden && tgtdev->host_exposed)
1537 1553 mpi3mr_remove_tgtdev_from_host(mrioc, tgtdev);
1538 - if (!tgtdev->is_hidden && tgtdev->host_exposed && tgtdev->starget)
1539 - starget_for_each_device(tgtdev->starget, (void *)tgtdev,
1540 - mpi3mr_update_sdev);
1554 + if (!tgtdev->is_hidden && tgtdev->host_exposed) {
1555 + spin_lock_irqsave(&mrioc->tgtdev_lock, flags);
1556 + starget = tgtdev->starget;
1557 + if (starget)
1558 + get_device(&starget->dev);
1559 + spin_unlock_irqrestore(&mrioc->tgtdev_lock, flags);
1560 + if (starget) {
1561 + starget_for_each_device(starget, (void *)tgtdev,
1562 + mpi3mr_update_sdev);
1563 + put_device(&starget->dev);
1564 + }
1565 + }
1541 1566 out:
1542 1567 if (tgtdev)
1543 1568 mpi3mr_tgtdev_put(tgtdev);
modified drivers/scsi/mpi3mr/mpi3mr_transport.c
@@ -1428,9 +1428,15 @@ static struct mpi3mr_sas_port *mpi3mr_sas_port_add(struct mpi3mr_ioc *mrioc,
1428 1428 }
1429 1429
1430 1430 port = sas_port_alloc_num(mr_sas_node->parent_dev);
1431 + if (!port) {
1432 + ioc_err(mrioc, "failure at %s:%d/%s()!\n",
1433 + __FILE__, __LINE__, __func__);
1434 + goto out_fail;
1435 + }
1431 1436 if ((sas_port_add(port))) {
1432 1437 ioc_err(mrioc, "failure at %s:%d/%s()!\n",
1433 1438 __FILE__, __LINE__, __func__);
1439 + sas_port_free(port);
1434 1440 goto out_fail;
1435 1441 }
1436 1442
@@ -1501,6 +1507,8 @@ static struct mpi3mr_sas_port *mpi3mr_sas_port_add(struct mpi3mr_ioc *mrioc,
1501 1507 list_for_each_entry_safe(mr_sas_phy, next, &mr_sas_port->phy_list,
1502 1508 port_siblings)
1503 1509 list_del(&mr_sas_phy->port_siblings);
1510 + if (tgtdev)
1511 + mpi3mr_tgtdev_put(tgtdev);
1504 1512 kfree(mr_sas_port);
1505 1513 return NULL;
1506 1514 }
modified drivers/scsi/mpt3sas/mpt3sas_base.c
@@ -3238,7 +3238,10 @@ _base_assign_reply_queues(struct MPT3SAS_ADAPTER *ioc)
3238 3238 * corresponding to high iops queues.
3239 3239 */
3240 3240 if (ioc->high_iops_queues) {
3241 - mask = cpumask_of_node(dev_to_node(&ioc->pdev->dev));
3241 + int node = dev_to_node(&ioc->pdev->dev);
3242 +
3243 + mask = (node == NUMA_NO_NODE) ?
3244 + cpu_online_mask : cpumask_of_node(node);
3242 3245 for (index = 0; index < ioc->high_iops_queues;
3243 3246 index++) {
3244 3247 irq = pci_irq_vector(ioc->pdev, index);
modified drivers/scsi/pm8001/pm8001_init.c
@@ -58,15 +58,15 @@ MODULE_PARM_DESC(link_rate, "Enable link rate.\n"
58 58
59 59 bool pm8001_use_msix = true;
60 60 module_param_named(use_msix, pm8001_use_msix, bool, 0444);
61 - MODULE_PARM_DESC(zoned, "Use MSIX interrupts. Default: true");
61 + MODULE_PARM_DESC(use_msix, "Use MSIX interrupts. Default: true");
62 62
63 63 static bool pm8001_use_tasklet = true;
64 64 module_param_named(use_tasklet, pm8001_use_tasklet, bool, 0444);
65 - MODULE_PARM_DESC(zoned, "Use MSIX interrupts. Default: true");
65 + MODULE_PARM_DESC(use_tasklet, "Use tasklets for interrupt handling. Default: true");
66 66
67 67 static bool pm8001_read_wwn = true;
68 68 module_param_named(read_wwn, pm8001_read_wwn, bool, 0444);
69 - MODULE_PARM_DESC(zoned, "Get WWN from the controller. Default: true");
69 + MODULE_PARM_DESC(read_wwn, "Get WWN from the controller. Default: true");
70 70
71 71 uint pcs_event_log_severity = 0x03;
72 72 module_param(pcs_event_log_severity, int, 0644);
@@ -1029,8 +1029,8 @@ static u32 pm8001_request_msix(struct pm8001_hba_info *pm8001_ha)
1029 1029 &(pm8001_ha->irq_vector[i]));
1030 1030 if (rc) {
1031 1031 for (j = 0; j < i; j++) {
1032 - free_irq(pci_irq_vector(pm8001_ha->pdev, i),
1033 - &(pm8001_ha->irq_vector[i]));
1032 + free_irq(pci_irq_vector(pm8001_ha->pdev, j),
1033 + &pm8001_ha->irq_vector[j]);
1034 1034 }
1035 1035 pci_free_irq_vectors(pm8001_ha->pdev);
1036 1036 break;
modified drivers/scsi/qedi/qedi_main.c
@@ -2652,8 +2652,6 @@ retry_probe:
2652 2652 snprintf(host_buf, sizeof(host_buf), "host_%d", qedi->shost->host_no);
2653 2653 qedi_ops->common->set_name(qedi->cdev, host_buf);
2654 2654
2655 - qedi_ops->register_ops(qedi->cdev, &qedi_cb_ops, qedi);
2656 -
2657 2655 memset(&params, 0, sizeof(params));
2658 2656 params.mtu = DEF_PATH_MTU + IPV6_HDR_LEN + TCP_HDR_LEN;
2659 2657 qedi->ll2_mtu = DEF_PATH_MTU;
@@ -2670,6 +2668,7 @@ retry_probe:
2670 2668 spin_lock_init(&qedi->task_idx_lock);
2671 2669 mutex_init(&qedi->stats_lock);
2672 2670 }
2671 + qedi_ops->register_ops(qedi->cdev, &qedi_cb_ops, qedi);
2673 2672 qedi_ops->ll2->register_cb_ops(qedi->cdev, &qedi_ll2_cb_ops, qedi);
2674 2673 qedi_ops->ll2->start(qedi->cdev, &params);
2675 2674
modified drivers/scsi/qla2xxx/qla_os.c
@@ -352,7 +352,7 @@ MODULE_PARM_DESC(ql2xnvme_queues,
352 352
353 353 int ql2xfc2target = 1;
354 354 module_param(ql2xfc2target, int, 0444);
355 - MODULE_PARM_DESC(qla2xfc2target,
355 + MODULE_PARM_DESC(ql2xfc2target,
356 356 "Enables FC2 Target support. "
357 357 "0 - FC2 Target support is disabled. "
358 358 "1 - FC2 Target support is enabled (default).");
modified drivers/scsi/scsi.c
@@ -727,6 +727,7 @@ int scsi_cdl_enable(struct scsi_device *sdev, bool enable)
727 727 struct scsi_mode_data data;
728 728 struct scsi_sense_hdr sshdr;
729 729 char *buf_data;
730 + size_t avail, offset;
730 731 int len;
731 732
732 733 ret = scsi_mode_sense(sdev, 0x08, 0x0a, 0xf2, buf, sizeof(buf),
@@ -735,11 +736,24 @@ int scsi_cdl_enable(struct scsi_device *sdev, bool enable)
735 736 return -EINVAL;
736 737
737 738 /* Enable or disable CDL using the ATA feature page */
738 - len = min_t(size_t, sizeof(buf),
739 - data.length - data.header_length -
740 - data.block_descriptor_length);
741 - buf_data = buf + data.header_length +
742 - data.block_descriptor_length;
739 + avail = min_t(size_t, data.length, sizeof(buf));
740 + if (data.header_length > avail)
741 + return -EINVAL;
742 +
743 + offset = data.header_length;
744 + avail -= data.header_length;
745 +
746 + if (data.block_descriptor_length > avail)
747 + return -EINVAL;
748 +
749 + offset += data.block_descriptor_length;
750 + avail -= data.block_descriptor_length;
751 +
752 + if (avail < 5)
753 + return -EINVAL;
754 +
755 + buf_data = buf + offset;
756 + len = avail;
743 757
744 758 /*
745 759 * If we want to enable CDL and CDL is already enabled on the
modified drivers/scsi/scsi_bsg.c
@@ -18,6 +18,7 @@ struct scsi_bsg_uring_cmd_pdu {
18 18 struct bio *bio; /* mapped user buffer, unmap in task work */
19 19 struct request *req; /* block request, freed in task work */
20 20 u64 response_addr; /* user space response buffer address */
21 + u32 max_response_len; /* user response buffer size */
21 22 };
22 23 static_assert(sizeof(struct scsi_bsg_uring_cmd_pdu) <= sizeof_field(struct io_uring_cmd, pdu));
23 24
@@ -45,8 +46,8 @@ static void scsi_bsg_uring_task_cb(struct io_tw_req tw_req, io_tw_token_t tw)
45 46 if (scsi_status_is_check_condition(scmd->result)) {
46 47 driver_status = DRIVER_SENSE;
47 48 if (pdu->response_addr)
48 - sense_len_wr = min_t(u8, scmd->sense_len,
49 - SCSI_SENSE_BUFFERSIZE);
49 + sense_len_wr = min_t(unsigned int, pdu->max_response_len,
50 + scmd->sense_len);
50 51 }
51 52
52 53 if (sense_len_wr) {
@@ -76,12 +77,10 @@ static enum rq_end_io_ret scsi_bsg_uring_cmd_done(struct request *req,
76 77
77 78 static int scsi_bsg_map_user_buffer(struct request *req,
78 79 struct io_uring_cmd *ioucmd,
79 - unsigned int issue_flags, gfp_t gfp_mask)
80 + unsigned int issue_flags, gfp_t gfp_mask,
81 + bool is_write, u64 buf_addr,
82 + unsigned long buf_len)
80 83 {
81 - const struct bsg_uring_cmd *cmd = io_uring_sqe128_cmd(ioucmd->sqe, struct bsg_uring_cmd);
82 - bool is_write = cmd->dout_xfer_len > 0;
83 - u64 buf_addr = is_write ? cmd->dout_xferp : cmd->din_xferp;
84 - unsigned long buf_len = is_write ? cmd->dout_xfer_len : cmd->din_xfer_len;
85 84 struct iov_iter iter;
86 85 int ret;
87 86
@@ -104,21 +103,28 @@ static int scsi_bsg_uring_cmd(struct request_queue *q, struct io_uring_cmd *iouc
104 103 unsigned int issue_flags, bool open_for_write)
105 104 {
106 105 struct scsi_bsg_uring_cmd_pdu *pdu = scsi_bsg_uring_cmd_pdu(ioucmd);
107 - const struct bsg_uring_cmd *cmd = io_uring_sqe128_cmd(ioucmd->sqe, struct bsg_uring_cmd);
106 + const struct bsg_uring_cmd *cmd =
107 + io_uring_sqe128_cmd(ioucmd->sqe, struct bsg_uring_cmd);
108 108 struct scsi_cmnd *scmd;
109 109 struct request *req;
110 110 blk_mq_req_flags_t blk_flags = 0;
111 111 gfp_t gfp_mask = GFP_KERNEL;
112 + u64 request = READ_ONCE(cmd->request);
113 + u32 request_len = READ_ONCE(cmd->request_len);
114 + u64 dout_xferp = READ_ONCE(cmd->dout_xferp);
115 + u32 dout_xfer_len = READ_ONCE(cmd->dout_xfer_len);
116 + u64 din_xferp = READ_ONCE(cmd->din_xferp);
117 + u32 din_xfer_len = READ_ONCE(cmd->din_xfer_len);
112 118 int ret;
113 119
114 120 if (cmd->protocol != BSG_PROTOCOL_SCSI ||
115 121 cmd->subprotocol != BSG_SUB_PROTOCOL_SCSI_CMD)
116 122 return -EINVAL;
117 123
118 - if (!cmd->request || cmd->request_len == 0)
124 + if (!request || request_len == 0)
119 125 return -EINVAL;
120 126
121 - if (cmd->dout_xfer_len && cmd->din_xfer_len) {
127 + if (dout_xfer_len && din_xfer_len) {
122 128 pr_warn_once("BIDI support in bsg has been removed.\n");
123 129 return -EOPNOTSUPP;
124 130 }
@@ -131,20 +137,20 @@ static int scsi_bsg_uring_cmd(struct request_queue *q, struct io_uring_cmd *iouc
131 137 gfp_mask = GFP_NOWAIT;
132 138 }
133 139
134 - req = scsi_alloc_request(q, cmd->dout_xfer_len ?
140 + req = scsi_alloc_request(q, dout_xfer_len ?
135 141 REQ_OP_DRV_OUT : REQ_OP_DRV_IN, blk_flags);
136 142 if (IS_ERR(req))
137 143 return PTR_ERR(req);
138 144
139 145 scmd = blk_mq_rq_to_pdu(req);
140 - if (cmd->request_len > sizeof(scmd->cmnd)) {
146 + if (request_len > sizeof(scmd->cmnd)) {
141 147 ret = -EINVAL;
142 148 goto out_free_req;
143 149 }
144 - scmd->cmd_len = cmd->request_len;
150 + scmd->cmd_len = request_len;
145 151 scmd->allowed = SG_DEFAULT_RETRIES;
146 152
147 - if (copy_from_user(scmd->cmnd, uptr64(cmd->request), cmd->request_len)) {
153 + if (copy_from_user(scmd->cmnd, uptr64(request), request_len)) {
148 154 ret = -EFAULT;
149 155 goto out_free_req;
150 156 }
@@ -155,11 +161,16 @@ static int scsi_bsg_uring_cmd(struct request_queue *q, struct io_uring_cmd *iouc
155 161 }
156 162
157 163 pdu->response_addr = cmd->response;
158 - scmd->sense_len = cmd->max_response_len ?
159 - min(cmd->max_response_len, SCSI_SENSE_BUFFERSIZE) : SCSI_SENSE_BUFFERSIZE;
164 + pdu->max_response_len = cmd->max_response_len;
160 165
161 - if (cmd->dout_xfer_len || cmd->din_xfer_len) {
162 - ret = scsi_bsg_map_user_buffer(req, ioucmd, issue_flags, gfp_mask);
166 + if (dout_xfer_len || din_xfer_len) {
167 + bool is_write = dout_xfer_len > 0;
168 + u64 buf_addr = is_write ? dout_xferp : din_xferp;
169 + unsigned long buf_len = is_write ? dout_xfer_len : din_xfer_len;
170 +
171 + ret = scsi_bsg_map_user_buffer(req, ioucmd, issue_flags,
172 + gfp_mask, is_write, buf_addr,
173 + buf_len);
163 174 if (ret)
164 175 goto out_free_req;
165 176 pdu->bio = req->bio;
modified drivers/scsi/scsi_devinfo.c
@@ -161,7 +161,7 @@ static struct {
161 161 {"DGC", "DISK", NULL, BLIST_SPARSELUN}, /* EMC CLARiiON, no storage on LUN 0 */
162 162 {"EMC", "Invista", "*", BLIST_SPARSELUN | BLIST_LARGELUN},
163 163 {"EMC", "SYMMETRIX", NULL, BLIST_SPARSELUN | BLIST_LARGELUN |
164 - BLIST_REPORTLUN2 | BLIST_RETRY_ITF},
164 + BLIST_REPORTLUN2 | BLIST_RETRY_ITF | BLIST_SKIP_IO_HINTS},
165 165 {"EMULEX", "MD21/S2 ESDI", NULL, BLIST_SINGLELUN},
166 166 {"easyRAID", "16P", NULL, BLIST_NOREPORTLUN},
167 167 {"easyRAID", "X6P", NULL, BLIST_NOREPORTLUN},
modified drivers/scsi/sd_zbc.c
@@ -589,7 +589,7 @@ int sd_zbc_revalidate_zones(struct scsi_disk *sdkp)
589 589 int sd_zbc_read_zones(struct scsi_disk *sdkp, struct queue_limits *lim,
590 590 u8 buf[SD_BUF_SIZE])
591 591 {
592 - unsigned int nr_zones;
592 + u64 nr_zones;
593 593 u32 zone_blocks = 0;
594 594 int ret;
595 595
@@ -621,6 +621,12 @@ int sd_zbc_read_zones(struct scsi_disk *sdkp, struct queue_limits *lim,
621 621 goto err;
622 622
623 623 nr_zones = round_up(sdkp->capacity, zone_blocks) >> ilog2(zone_blocks);
624 + if (nr_zones > INT_MAX) {
625 + sd_printk(KERN_ERR, sdkp, "Too many zones (%llu)\n",
626 + nr_zones);
627 + ret = -EINVAL;
628 + goto err;
629 + }
624 630 sdkp->early_zone_info.nr_zones = nr_zones;
625 631 sdkp->early_zone_info.zone_blocks = zone_blocks;
626 632
modified drivers/scsi/st.c
@@ -3217,14 +3217,20 @@ static int set_location(struct scsi_tape *STp, unsigned int block, int partition
3217 3217 partition >= ST_NBR_PARTITIONS)
3218 3218 return (-EINVAL);
3219 3219 if (partition != STp->partition) {
3220 - if (get_location(STp, &blk, &p, 1))
3220 + /*
3221 + * Save the location for the partition the drive reports,
3222 + * not for STp->partition: after a reset STp->partition may
3223 + * not match the partition the drive is in.
3224 + */
3225 + if (get_location(STp, &blk, &p, 1) ||
3226 + p < 0 || p >= ST_NBR_PARTITIONS)
3221 3227 STps->last_block_valid = 0;
3222 3228 else {
3223 - STps->last_block_valid = 1;
3224 - STps->last_block_visited = blk;
3229 + STp->ps[p].last_block_valid = 1;
3230 + STp->ps[p].last_block_visited = blk;
3225 3231 DEBC_printk(STp, "Visited block %d for "
3226 3232 "partition %d saved.\n",
3227 - blk, STp->partition);
3233 + blk, p);
3228 3234 }
3229 3235 }
3230 3236
@@ -4509,11 +4515,11 @@ static void st_remove(struct scsi_device *SDp)
4509 4515 remove_cdevs(tpnt);
4510 4516
4511 4517 mutex_lock(&st_ref_mutex);
4512 - kref_put(&tpnt->kref, scsi_tape_release);
4513 - mutex_unlock(&st_ref_mutex);
4514 4518 spin_lock(&st_index_lock);
4515 4519 idr_remove(&st_index_idr, index);
4516 4520 spin_unlock(&st_index_lock);
4521 + kref_put(&tpnt->kref, scsi_tape_release);
4522 + mutex_unlock(&st_ref_mutex);
4517 4523 }
4518 4524
4519 4525 /**
modified drivers/scsi/xen-scsifront.c
@@ -367,6 +367,7 @@ static void scsifront_do_response(struct vscsifrnt_info *info,
367 367 struct vscsifrnt_shadow *shadow;
368 368
369 369 if (ring_rsp->rqid >= VSCSIIF_MAX_REQS ||
370 + !info->shadow[ring_rsp->rqid] ||
370 371 !info->shadow[ring_rsp->rqid]->inflight) {
371 372 scsifront_set_error(info, "illegal rqid returned by backend!");
372 373 return;
modified drivers/target/iscsi/iscsi_target.c
@@ -1533,8 +1533,10 @@ __iscsit_check_dataout_hdr(struct iscsit_conn *conn, void *buf,
1533 1533 */
1534 1534 if (se_cmd->transport_state & CMD_T_ABORTED) {
1535 1535 if (hdr->flags & ISCSI_FLAG_CMD_FINAL &&
1536 - --cmd->outstanding_r2ts < 1)
1536 + --cmd->outstanding_r2ts < 1) {
1537 1537 iscsit_stop_dataout_timer(cmd);
1538 + target_complete_cmd(se_cmd, SAM_STAT_TASK_ABORTED);
1539 + }
1538 1540
1539 1541 return iscsit_dump_data_payload(conn, payload_length, 1);
1540 1542 }
modified drivers/target/iscsi/iscsi_target_configfs.c
@@ -1306,17 +1306,24 @@ static ssize_t iscsi_disc_enforce_discovery_auth_store(struct config_item *item,
1306 1306 return -EINVAL;
1307 1307 }
1308 1308
1309 + if (iscsit_get_tpg(discovery_tpg) < 0)
1310 + return -EINVAL;
1311 +
1309 1312 param = iscsi_find_param_from_key(AUTHMETHOD,
1310 1313 discovery_tpg->param_list);
1311 - if (!param)
1312 - return -EINVAL;
1314 + if (!param) {
1315 + err = -EINVAL;
1316 + goto out;
1317 + }
1313 1318
1314 1319 if (op) {
1315 1320 /*
1316 1321 * Reset the AuthMethod key to CHAP.
1317 1322 */
1318 - if (iscsi_update_param_value(param, CHAP) < 0)
1319 - return -EINVAL;
1323 + if (iscsi_update_param_value(param, CHAP) < 0) {
1324 + err = -EINVAL;
1325 + goto out;
1326 + }
1320 1327
1321 1328 discovery_tpg->tpg_attrib.authentication = 1;
1322 1329 iscsit_global->discovery_acl.node_auth.enforce_discovery_auth = 1;
@@ -1327,8 +1334,10 @@ static ssize_t iscsi_disc_enforce_discovery_auth_store(struct config_item *item,
1327 1334 /*
1328 1335 * Reset the AuthMethod key to CHAP,None
1329 1336 */
1330 - if (iscsi_update_param_value(param, "CHAP,None") < 0)
1331 - return -EINVAL;
1337 + if (iscsi_update_param_value(param, "CHAP,None") < 0) {
1338 + err = -EINVAL;
1339 + goto out;
1340 + }
1332 1341
1333 1342 discovery_tpg->tpg_attrib.authentication = 0;
1334 1343 iscsit_global->discovery_acl.node_auth.enforce_discovery_auth = 0;
@@ -1337,7 +1346,10 @@ static ssize_t iscsi_disc_enforce_discovery_auth_store(struct config_item *item,
1337 1346 " Discovery TPG\n");
1338 1347 }
1339 1348
1340 - return count;
1349 + err = count;
1350 + out:
1351 + iscsit_put_tpg(discovery_tpg);
1352 + return err;
1341 1353 }
1342 1354
1343 1355 CONFIGFS_ATTR(iscsi_disc_, enforce_discovery_auth);
modified drivers/target/iscsi/iscsi_target_login.c
@@ -47,7 +47,7 @@ static struct iscsi_login *iscsi_login_init_conn(struct iscsit_conn *conn)
47 47 login->conn = conn;
48 48 login->first_request = 1;
49 49
50 - login->req_buf = kzalloc(MAX_KEY_VALUE_PAIRS, GFP_KERNEL);
50 + login->req_buf = kzalloc(MAX_KEY_VALUE_PAIRS + 1, GFP_KERNEL);
51 51 if (!login->req_buf) {
52 52 pr_err("Unable to allocate memory for response buffer.\n");
53 53 goto out_login;
modified drivers/target/target_core_transport.c
@@ -2359,7 +2359,7 @@ void target_do_delayed_work(struct work_struct *work)
2359 2359 struct se_device *dev = container_of(work, struct se_device,
2360 2360 delayed_cmd_work);
2361 2361
2362 - spin_lock(&dev->delayed_cmd_lock);
2362 + spin_lock_irq(&dev->delayed_cmd_lock);
2363 2363 while (!dev->ordered_sync_in_progress) {
2364 2364 struct se_cmd *cmd;
2365 2365
@@ -2380,12 +2380,12 @@ void target_do_delayed_work(struct work_struct *work)
2380 2380 dev->ordered_sync_in_progress = true;
2381 2381
2382 2382 list_del(&cmd->se_delayed_node);
2383 - spin_unlock(&dev->delayed_cmd_lock);
2383 + spin_unlock_irq(&dev->delayed_cmd_lock);
2384 2384
2385 2385 __target_execute_cmd(cmd, true);
2386 - spin_lock(&dev->delayed_cmd_lock);
2386 + spin_lock_irq(&dev->delayed_cmd_lock);
2387 2387 }
2388 - spin_unlock(&dev->delayed_cmd_lock);
2388 + spin_unlock_irq(&dev->delayed_cmd_lock);
2389 2389 }
2390 2390
2391 2391 static void transport_complete_ordered_sync(struct se_cmd *cmd)
modified drivers/ufs/core/ufs-mcq.c
@@ -312,20 +312,24 @@ static int ufshcd_mcq_get_tag(struct ufs_hba *hba, struct cq_entry *cqe)
312 312 UFSHCD_NUM_RESERVED;
313 313 }
314 314
315 + static void ufshcd_mcq_compl_cqe(struct ufs_hba *hba, struct cq_entry *cqe)
316 + {
317 + int tag = ufshcd_mcq_get_tag(hba, cqe);
318 +
319 + ufshcd_compl_one_cqe(hba, tag, cqe);
320 + /* After processing the CQE, mark it as an empty (invalid) entry. */
321 + cqe->command_desc_base_addr = 0;
322 + }
323 +
315 324 static void ufshcd_mcq_process_cqe(struct ufs_hba *hba,
316 325 struct ufs_hw_queue *hwq)
317 326 {
318 327 struct cq_entry *cqe = ufshcd_mcq_cur_cqe(hwq);
319 328
320 - if (cqe->command_desc_base_addr) {
321 - int tag = ufshcd_mcq_get_tag(hba, cqe);
322 -
323 - ufshcd_compl_one_cqe(hba, tag, cqe);
324 - /* After processed the cqe, mark it empty (invalid) entry */
325 - cqe->command_desc_base_addr = 0;
326 - } else {
329 + if (cqe->command_desc_base_addr)
330 + ufshcd_mcq_compl_cqe(hba, cqe);
331 + else
327 332 dev_err(hba->dev, "Abnormal CQ entry!\n");
328 - }
329 333 }
330 334
331 335 /*
@@ -333,7 +337,7 @@ static void ufshcd_mcq_process_cqe(struct ufs_hba *hba,
333 337 * controller disabled (HCE = 0). Reading host controller registers, e.g. the
334 338 * CQ tail pointer (CQTPy), may not be safe with the host controller disabled.
335 339 * Hence, iterate over all completion queue entries. This won't result in
336 - * double completions because ufshcd_mcq_process_cqe() clears a CQE after it
340 + * double completions because ufshcd_mcq_compl_cqe() clears a CQE after it
337 341 * has been processed.
338 342 */
339 343 void ufshcd_mcq_compl_all_cqes_lock(struct ufs_hba *hba,
@@ -344,13 +348,13 @@ void ufshcd_mcq_compl_all_cqes_lock(struct ufs_hba *hba,
344 348
345 349 spin_lock_irqsave(&hwq->cq_lock, flags);
346 350 while (entries > 0) {
347 - ufshcd_mcq_process_cqe(hba, hwq);
351 + struct cq_entry *cqe = ufshcd_mcq_cur_cqe(hwq);
352 +
353 + if (cqe->command_desc_base_addr)
354 + ufshcd_mcq_compl_cqe(hba, cqe);
348 355 ufshcd_mcq_inc_cq_head_slot(hwq);
349 356 entries--;
350 357 }
351 -
352 - ufshcd_mcq_update_cq_tail_slot(hwq);
353 - hwq->cq_head_slot = hwq->cq_tail_slot;
354 358 spin_unlock_irqrestore(&hwq->cq_lock, flags);
355 359 }
356 360
modified drivers/ufs/core/ufshcd.c
@@ -6044,8 +6044,6 @@ static bool ufshcd_mcq_force_compl_one(struct request *rq, void *priv)
6044 6044 if (blk_mq_is_reserved_rq(rq) || !hwq)
6045 6045 return true;
6046 6046
6047 - ufshcd_mcq_compl_all_cqes_lock(hba, hwq);
6048 -
6049 6047 /*
6050 6048 * For those cmds of which the cqes are not present in the cq, complete
6051 6049 * them explicitly.
@@ -6061,19 +6059,6 @@ static bool ufshcd_mcq_force_compl_one(struct request *rq, void *priv)
6061 6059 return true;
6062 6060 }
6063 6061
6064 - static bool ufshcd_mcq_compl_one(struct request *rq, void *priv)
6065 - {
6066 - struct scsi_device *sdev = rq->q->queuedata;
6067 - struct Scsi_Host *shost = sdev->host;
6068 - struct ufs_hba *hba = shost_priv(shost);
6069 - struct ufs_hw_queue *hwq = ufshcd_mcq_req_to_hwq(hba, rq);
6070 -
6071 - if (!blk_mq_is_reserved_rq(rq) && hwq)
6072 - ufshcd_mcq_poll_cqe_lock(hba, hwq);
6073 -
6074 - return true;
6075 - }
6076 -
6077 6062 /**
6078 6063 * ufshcd_mcq_compl_pending_transfer - MCQ mode function. It is
6079 6064 * invoked from the error handler context or ufshcd_host_reset_and_restore()
@@ -6088,10 +6073,18 @@ static bool ufshcd_mcq_compl_one(struct request *rq, void *priv)
6088 6073 static void ufshcd_mcq_compl_pending_transfer(struct ufs_hba *hba,
6089 6074 bool force_compl)
6090 6075 {
6091 - blk_mq_tagset_busy_iter(&hba->host->tag_set,
6092 - force_compl ? ufshcd_mcq_force_compl_one :
6093 - ufshcd_mcq_compl_one,
6094 - NULL);
6076 + int i;
6077 +
6078 + for (i = 0; i < hba->nr_hw_queues; i++) {
6079 + if (force_compl)
6080 + ufshcd_mcq_compl_all_cqes_lock(hba, &hba->uhq[i]);
6081 + else
6082 + ufshcd_mcq_poll_cqe_lock(hba, &hba->uhq[i]);
6083 + }
6084 +
6085 + if (force_compl)
6086 + blk_mq_tagset_busy_iter(&hba->host->tag_set,
6087 + ufshcd_mcq_force_compl_one, NULL);
6095 6088 }
6096 6089
6097 6090 /**
@@ -6817,11 +6810,17 @@ static void ufshcd_err_handling_prepare(struct ufs_hba *hba)
6817 6810 }
6818 6811 /* Wait for ongoing ufshcd_queuecommand() calls to finish. */
6819 6812 blk_mq_quiesce_tagset(&hba->host->tag_set);
6813 + /*
6814 + * Internal commands are submitted on the pseudo SCSI device. Let them
6815 + * through so that the error handler can recover the link.
6816 + */
6817 + blk_mq_unquiesce_queue(hba->host->pseudo_sdev->request_queue);
6820 6818 cancel_work_sync(&hba->eeh_work);
6821 6819 }
6822 6820
6823 6821 static void ufshcd_err_handling_unprepare(struct ufs_hba *hba)
6824 6822 {
6823 + blk_mq_quiesce_queue_nowait(hba->host->pseudo_sdev->request_queue);
6825 6824 blk_mq_unquiesce_tagset(&hba->host->tag_set);
6826 6825 ufshcd_release(hba);
6827 6826 if (ufshcd_is_clkscaling_supported(hba))
@@ -9550,6 +9549,7 @@ static void ufshcd_async_scan(void *data, async_cookie_t cookie)
9550 9549 ret = ufshcd_add_lus(hba);
9551 9550
9552 9551 out:
9552 + ufshcd_release(hba);
9553 9553 pm_runtime_put_sync(hba->dev);
9554 9554
9555 9555 if (ret)
@@ -11272,6 +11272,9 @@ int ufshcd_init(struct ufs_hba *hba, void __iomem *mmio_base, unsigned int irq)
11272 11272
11273 11273 ufshcd_init_clk_gating(hba);
11274 11274
11275 + /* Released by ufshcd_async_scan(), or by out_release on failure. */
11276 + ufshcd_hold(hba);
11277 +
11275 11278 ufshcd_init_clk_scaling(hba);
11276 11279
11277 11280 /*
@@ -11292,7 +11295,7 @@ int ufshcd_init(struct ufs_hba *hba, void __iomem *mmio_base, unsigned int irq)
11292 11295 err = devm_request_irq(dev, irq, ufshcd_intr, IRQF_SHARED, UFSHCD, hba);
11293 11296 if (err) {
11294 11297 dev_err(hba->dev, "request irq failed\n");
11295 - goto out_disable;
11298 + goto out_release;
11296 11299 } else {
11297 11300 hba->is_irq_enabled = true;
11298 11301 }
@@ -11308,7 +11311,7 @@ int ufshcd_init(struct ufs_hba *hba, void __iomem *mmio_base, unsigned int irq)
11308 11311 dev_err(hba->dev, "Host controller enable failed\n");
11309 11312 ufshcd_print_evt_hist(hba);
11310 11313 ufshcd_print_host_state(hba);
11311 - goto out_disable;
11314 + goto out_release;
11312 11315 }
11313 11316
11314 11317 INIT_DELAYED_WORK(&hba->rpm_dev_flush_recheck_work, ufshcd_rpm_dev_flush_recheck_work);
@@ -11322,7 +11325,7 @@ int ufshcd_init(struct ufs_hba *hba, void __iomem *mmio_base, unsigned int irq)
11322 11325
11323 11326 err = ufshcd_add_scsi_host(hba);
11324 11327 if (err)
11325 - goto out_disable;
11328 + goto out_release;
11326 11329
11327 11330 /* Hold auto suspend until async scan completes */
11328 11331 pm_runtime_get_sync(dev);
@@ -11342,7 +11345,7 @@ int ufshcd_init(struct ufs_hba *hba, void __iomem *mmio_base, unsigned int irq)
11342 11345
11343 11346 err = ufshcd_link_startup(hba);
11344 11347 if (err)
11345 - goto out_disable;
11348 + goto out_release;
11346 11349
11347 11350 if (hba->mcq_enabled)
11348 11351 ufshcd_config_mcq(hba);
@@ -11359,23 +11362,23 @@ int ufshcd_init(struct ufs_hba *hba, void __iomem *mmio_base, unsigned int irq)
11359 11362 /* Verify device initialization by sending NOP OUT UPIU */
11360 11363 err = ufshcd_verify_dev_init(hba);
11361 11364 if (err)
11362 - goto out_disable;
11365 + goto out_release;
11363 11366
11364 11367 /* Initiate UFS initialization, and waiting until completion */
11365 11368 err = ufshcd_complete_dev_init(hba);
11366 11369 if (err)
11367 - goto out_disable;
11370 + goto out_release;
11368 11371
11369 11372 err = ufshcd_device_params_init(hba);
11370 11373 if (err)
11371 - goto out_disable;
11374 + goto out_release;
11372 11375
11373 11376 err = ufshcd_post_device_init(hba);
11374 11377
11375 11378 initialized:
11376 11379 ufshcd_process_probe_result(hba, probe_start, err);
11377 11380 if (err)
11378 - goto out_disable;
11381 + goto out_release;
11379 11382
11380 11383 ufs_sysfs_add_nodes(hba->dev);
11381 11384 hba->dme_qos_sysfs_handle = sysfs_get_dirent(hba->dev->kobj.sd,
@@ -11386,6 +11389,8 @@ initialized:
11386 11389 ufshcd_pm_qos_init(hba);
11387 11390 return 0;
11388 11391
11392 + out_release:
11393 + ufshcd_release(hba);
11389 11394 out_disable:
11390 11395 hba->is_irq_enabled = false;
11391 11396 ufshcd_hba_exit(hba);
modified drivers/ufs/host/ufs-mediatek.c
@@ -509,6 +509,7 @@ static int ufs_mtk_mphy_power_on(struct ufs_hba *hba, bool on)
509 509 struct ufs_mtk_host *host = ufshcd_get_variant(hba);
510 510 struct phy *mphy = host->mphy;
511 511 struct arm_smccc_res res;
512 + int err;
512 513 int ret = 0;
513 514
514 515 if (!mphy || !(on ^ host->mphy_powered_on))
@@ -523,7 +524,18 @@ static int ufs_mtk_mphy_power_on(struct ufs_hba *hba, bool on)
523 524 usleep_range(200, 210);
524 525 ufs_mtk_va09_pwr_ctrl(res, 1);
525 526 }
526 - phy_power_on(mphy);
527 + ret = phy_power_on(mphy);
528 + if (ret) {
529 + if (ufs_mtk_is_va09_supported(hba)) {
530 + ufs_mtk_va09_pwr_ctrl(res, 0);
531 + err = regulator_disable(host->reg_va09);
532 + if (err)
533 + dev_err(hba->dev,
534 + "failed to unwind va09: %d\n", err);
535 + }
536 + dev_err(hba->dev, "failed to enable mphy: %d\n", ret);
537 + return ret;
538 + }
527 539 } else {
528 540 phy_power_off(mphy);
529 541 if (ufs_mtk_is_va09_supported(hba)) {
@@ -1295,7 +1307,9 @@ static int ufs_mtk_init(struct ufs_hba *hba)
1295 1307 *
1296 1308 * Enable phy clocks specifically here.
1297 1309 */
1298 - ufs_mtk_mphy_power_on(hba, true);
1310 + err = ufs_mtk_mphy_power_on(hba, true);
1311 + if (err)
1312 + goto out_variant_clear;
1299 1313
1300 1314 if (ufs_mtk_is_rtff_mtcmos(hba)) {
1301 1315 /* First Restore here, to avoid backup unexpected value */
modified drivers/ufs/host/ufs-qcom.c
@@ -715,6 +715,7 @@ static void ufs_qcom_link_startup_post_change(struct ufs_hba *hba)
715 715 static int ufs_qcom_link_startup_notify(struct ufs_hba *hba,
716 716 enum ufs_notify_change_status status)
717 717 {
718 + struct ufs_qcom_host *host = ufshcd_get_variant(hba);
718 719 int err = 0;
719 720
720 721 switch (status) {
@@ -737,6 +738,14 @@ static int ufs_qcom_link_startup_notify(struct ufs_hba *hba,
737 738 */
738 739 err = ufshcd_disable_host_tx_lcc(hba);
739 740
741 + /*
742 + * Restore HS/LS link startup mode set by bootloader
743 + * after UFS reset clears REG_UFS_DEBUG_SPARE_CFG.
744 + */
745 + if (host->hw_ver.major > 0x6 ||
746 + (host->hw_ver.major == 0x6 && host->hw_ver.minor >= 0x2))
747 + ufshcd_writel(hba, host->boot_spare_cfg,
748 + REG_UFS_DEBUG_SPARE_CFG);
740 749 break;
741 750 case POST_CHANGE:
742 751 ufs_qcom_link_startup_post_change(hba);
@@ -1325,7 +1334,7 @@ static void ufs_qcom_advertise_quirks(struct ufs_hba *hba)
1325 1334 static void ufs_qcom_set_phy_gear(struct ufs_qcom_host *host)
1326 1335 {
1327 1336 struct ufs_host_params *host_params = &host->host_params;
1328 - u32 val, dev_major;
1337 + u32 dev_major;
1329 1338
1330 1339 /*
1331 1340 * Default to powering up the PHY to the max gear possible, which is
@@ -1344,8 +1353,8 @@ static void ufs_qcom_set_phy_gear(struct ufs_qcom_host *host)
1344 1353 */
1345 1354 host->phy_gear = UFS_HS_G2;
1346 1355 } else if (host->hw_ver.major >= 0x5) {
1347 - val = ufshcd_readl(host->hba, REG_UFS_DEBUG_SPARE_CFG);
1348 - dev_major = FIELD_GET(UFS_DEV_VER_MAJOR_MASK, val);
1356 + host->boot_spare_cfg = ufshcd_readl(host->hba, REG_UFS_DEBUG_SPARE_CFG);
1357 + dev_major = FIELD_GET(UFS_DEV_VER_MAJOR_MASK, host->boot_spare_cfg);
1349 1358
1350 1359 /*
1351 1360 * Since the UFS device version is populated, let's remove the
@@ -2282,7 +2291,7 @@ static void ufs_qcom_config_scaling_param(struct ufs_hba *hba,
2282 2291 p->polling_ms = 60;
2283 2292 p->timer = DEVFREQ_TIMER_DELAYED;
2284 2293 d->upthreshold = 70;
2285 - d->downdifferential = 5;
2294 + d->downdifferential = 65;
2286 2295
2287 2296 hba->clk_scaling.suspend_on_no_request = true;
2288 2297 }
modified drivers/ufs/host/ufs-qcom.h
@@ -361,6 +361,7 @@ struct ufs_qcom_host {
361 361 bool esi_enabled;
362 362
363 363 u32 saved_tx_eq_g1_setting;
364 + u32 boot_spare_cfg;
364 365 };
365 366
366 367 struct ufs_qcom_drvdata {
modified drivers/ufs/host/ufshcd-pci.c
@@ -181,6 +181,25 @@ static int ufs_intel_lkf_pwr_change_notify(struct ufs_hba *hba,
181 181 return err;
182 182 }
183 183
184 + static int ufs_intel_nvl_pwr_change_notify(struct ufs_hba *hba,
185 + enum ufs_notify_change_status stage,
186 + struct ufs_pa_layer_attr *dev_req_params)
187 + {
188 + int adapt_val;
189 +
190 + if (stage != PRE_CHANGE || hba->ufs_version < ufshci_version(4, 0))
191 + return 0;
192 +
193 + if (dev_req_params->pwr_tx == FAST_MODE || dev_req_params->pwr_tx == FASTAUTO_MODE)
194 + adapt_val = PA_INITIAL_ADAPT;
195 + else
196 + adapt_val = PA_NO_ADAPT;
197 +
198 + ufshcd_dme_configure_adapt(hba, dev_req_params->gear_tx, adapt_val);
199 +
200 + return 0;
201 + }
202 +
184 203 static int ufs_intel_lkf_apply_dev_quirks(struct ufs_hba *hba)
185 204 {
186 205 u32 granularity, peer_granularity;
@@ -441,6 +460,43 @@ static int ufs_intel_mtl_init(struct ufs_hba *hba)
441 460 return ufs_intel_common_init(hba);
442 461 }
443 462
463 + static int ufs_intel_mcq_config_resource(struct ufs_hba *hba)
464 + {
465 + hba->mcq_base = hba->mmio_base + ufshcd_mcq_queue_cfg_addr(hba);
466 +
467 + return 0;
468 + }
469 +
470 + /*
471 + * This Intel UFS4.0 controller maps MCQ doorbell and interrupt-status
472 + * registers into the same PCI BAR as the legacy HCI space, at this
473 + * fixed offset/stride.
474 + */
475 + #define UFS_INTEL_SQDAO0 0x2800
476 + #define UFS_INTEL_SQISAO0 0x2814
477 + #define UFS_INTEL_CQDAO0 0x281C
478 + #define UFS_INTEL_CQISAO0 0x2824
479 + #define UFS_INTEL_MCQ_STRIDE 0x30
480 +
481 + static int ufs_intel_op_runtime_config(struct ufs_hba *hba)
482 + {
483 + struct ufshcd_mcq_opr_info_t *opr;
484 + int i;
485 +
486 + hba->mcq_opr[OPR_SQD].offset = UFS_INTEL_SQDAO0;
487 + hba->mcq_opr[OPR_SQIS].offset = UFS_INTEL_SQISAO0;
488 + hba->mcq_opr[OPR_CQD].offset = UFS_INTEL_CQDAO0;
489 + hba->mcq_opr[OPR_CQIS].offset = UFS_INTEL_CQISAO0;
490 +
491 + for (i = 0; i < OPR_MAX; i++) {
492 + opr = &hba->mcq_opr[i];
493 + opr->stride = UFS_INTEL_MCQ_STRIDE;
494 + opr->base = hba->mmio_base + opr->offset;
495 + }
496 +
497 + return 0;
498 + }
499 +
444 500 static int ufs_qemu_get_hba_mac(struct ufs_hba *hba)
445 501 {
446 502 return MAX_SUPP_MAC;
@@ -527,6 +583,9 @@ static struct ufs_hba_variant_ops ufs_intel_mtl_hba_vops = {
527 583 .exit = ufs_intel_common_exit,
528 584 .hce_enable_notify = ufs_intel_hce_enable_notify,
529 585 .link_startup_notify = ufs_intel_link_startup_notify,
586 + .pwr_change_notify = ufs_intel_nvl_pwr_change_notify,
587 + .mcq_config_resource = ufs_intel_mcq_config_resource,
588 + .op_runtime_config = ufs_intel_op_runtime_config,
530 589 .resume = ufs_intel_resume,
531 590 .device_reset = ufs_intel_device_reset,
532 591 };
modified drivers/ufs/host/ufshcd-pltfrm.c
@@ -206,7 +206,11 @@ static void ufshcd_init_lanes_per_dir(struct ufs_hba *hba)
206 206 dev_dbg(hba->dev,
207 207 "%s: failed to read lanes-per-direction, ret=%d\n",
208 208 __func__, ret);
209 - hba->lanes_per_direction = UFSHCD_DEFAULT_LANES_PER_DIRECTION;
209 + /* Old R-Car S4 DTBs lack "lanes-per-direction = <1>" */
210 + if (of_device_is_compatible(dev->of_node, "renesas,r8a779f0-ufs"))
211 + hba->lanes_per_direction = 1;
212 + else
213 + hba->lanes_per_direction = UFSHCD_DEFAULT_LANES_PER_DIRECTION;
210 214 }
211 215 }
212 216