Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'scsi-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi

Pull SCSI fixes from James Bottomley:
"Two small fixes, one re-fix of a previous fix and five patches sorting
out hotplug in the bnx2X class of drivers. The latter is rather
involved, but necessary because these drivers have started dropping
lockdep recursion warnings on the hotplug lock because of its
conversion to a percpu rwsem"

* tag 'scsi-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi:
scsi: sg: only check for dxfer_len greater than 256M
scsi: aacraid: reading out of bounds
scsi: qedf: Limit number of CQs
scsi: bnx2i: Simplify cpu hotplug code
scsi: bnx2fc: Simplify CPU hotplug code
scsi: bnx2i: Prevent recursive cpuhotplug locking
scsi: bnx2fc: Prevent recursive cpuhotplug locking
scsi: bnx2fc: Plug CPU hotplug race

+69 -171
+4 -3
drivers/scsi/aacraid/aachba.c
··· 3198 3198 return -EBUSY; 3199 3199 if (copy_from_user(&qd, arg, sizeof (struct aac_query_disk))) 3200 3200 return -EFAULT; 3201 - if (qd.cnum == -1) 3201 + if (qd.cnum == -1) { 3202 + if (qd.id < 0 || qd.id >= dev->maximum_num_containers) 3203 + return -EINVAL; 3202 3204 qd.cnum = qd.id; 3203 - else if ((qd.bus == -1) && (qd.id == -1) && (qd.lun == -1)) 3204 - { 3205 + } else if ((qd.bus == -1) && (qd.id == -1) && (qd.lun == -1)) { 3205 3206 if (qd.cnum < 0 || qd.cnum >= dev->maximum_num_containers) 3206 3207 return -EINVAL; 3207 3208 qd.instance = dev->scsi_host_ptr->host_no;
+15 -53
drivers/scsi/bnx2fc/bnx2fc_fcoe.c
··· 2624 2624 }; 2625 2625 2626 2626 /** 2627 - * bnx2fc_percpu_thread_create - Create a receive thread for an 2628 - * online CPU 2627 + * bnx2fc_cpu_online - Create a receive thread for an online CPU 2629 2628 * 2630 2629 * @cpu: cpu index for the online cpu 2631 2630 */ 2632 - static void bnx2fc_percpu_thread_create(unsigned int cpu) 2631 + static int bnx2fc_cpu_online(unsigned int cpu) 2633 2632 { 2634 2633 struct bnx2fc_percpu_s *p; 2635 2634 struct task_struct *thread; ··· 2638 2639 thread = kthread_create_on_node(bnx2fc_percpu_io_thread, 2639 2640 (void *)p, cpu_to_node(cpu), 2640 2641 "bnx2fc_thread/%d", cpu); 2642 + if (IS_ERR(thread)) 2643 + return PTR_ERR(thread); 2644 + 2641 2645 /* bind thread to the cpu */ 2642 - if (likely(!IS_ERR(thread))) { 2643 - kthread_bind(thread, cpu); 2644 - p->iothread = thread; 2645 - wake_up_process(thread); 2646 - } 2646 + kthread_bind(thread, cpu); 2647 + p->iothread = thread; 2648 + wake_up_process(thread); 2649 + return 0; 2647 2650 } 2648 2651 2649 - static void bnx2fc_percpu_thread_destroy(unsigned int cpu) 2652 + static int bnx2fc_cpu_offline(unsigned int cpu) 2650 2653 { 2651 2654 struct bnx2fc_percpu_s *p; 2652 2655 struct task_struct *thread; ··· 2662 2661 thread = p->iothread; 2663 2662 p->iothread = NULL; 2664 2663 2665 - 2666 2664 /* Free all work in the list */ 2667 2665 list_for_each_entry_safe(work, tmp, &p->work_list, list) { 2668 2666 list_del_init(&work->list); ··· 2673 2673 2674 2674 if (thread) 2675 2675 kthread_stop(thread); 2676 - } 2677 - 2678 - 2679 - static int bnx2fc_cpu_online(unsigned int cpu) 2680 - { 2681 - printk(PFX "CPU %x online: Create Rx thread\n", cpu); 2682 - bnx2fc_percpu_thread_create(cpu); 2683 - return 0; 2684 - } 2685 - 2686 - static int bnx2fc_cpu_dead(unsigned int cpu) 2687 - { 2688 - printk(PFX "CPU %x offline: Remove Rx thread\n", cpu); 2689 - bnx2fc_percpu_thread_destroy(cpu); 2690 2676 return 0; 2691 2677 } 2692 2678 ··· 2747 2761 spin_lock_init(&p->fp_work_lock); 2748 2762 } 2749 2763 2750 - get_online_cpus(); 2751 - 2752 - for_each_online_cpu(cpu) 2753 - bnx2fc_percpu_thread_create(cpu); 2754 - 2755 - rc = cpuhp_setup_state_nocalls(CPUHP_AP_ONLINE_DYN, 2756 - "scsi/bnx2fc:online", 2757 - bnx2fc_cpu_online, NULL); 2764 + rc = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "scsi/bnx2fc:online", 2765 + bnx2fc_cpu_online, bnx2fc_cpu_offline); 2758 2766 if (rc < 0) 2759 - goto stop_threads; 2767 + goto stop_thread; 2760 2768 bnx2fc_online_state = rc; 2761 2769 2762 - cpuhp_setup_state_nocalls(CPUHP_SCSI_BNX2FC_DEAD, "scsi/bnx2fc:dead", 2763 - NULL, bnx2fc_cpu_dead); 2764 - put_online_cpus(); 2765 - 2766 2770 cnic_register_driver(CNIC_ULP_FCOE, &bnx2fc_cnic_cb); 2767 - 2768 2771 return 0; 2769 2772 2770 - stop_threads: 2771 - for_each_online_cpu(cpu) 2772 - bnx2fc_percpu_thread_destroy(cpu); 2773 - put_online_cpus(); 2773 + stop_thread: 2774 2774 kthread_stop(l2_thread); 2775 2775 free_wq: 2776 2776 destroy_workqueue(bnx2fc_wq); ··· 2775 2803 struct fcoe_percpu_s *bg; 2776 2804 struct task_struct *l2_thread; 2777 2805 struct sk_buff *skb; 2778 - unsigned int cpu = 0; 2779 2806 2780 2807 /* 2781 2808 * NOTE: Since cnic calls register_driver routine rtnl_lock, ··· 2815 2844 if (l2_thread) 2816 2845 kthread_stop(l2_thread); 2817 2846 2818 - get_online_cpus(); 2819 - /* Destroy per cpu threads */ 2820 - for_each_online_cpu(cpu) { 2821 - bnx2fc_percpu_thread_destroy(cpu); 2822 - } 2823 - 2824 - cpuhp_remove_state_nocalls(bnx2fc_online_state); 2825 - cpuhp_remove_state_nocalls(CPUHP_SCSI_BNX2FC_DEAD); 2826 - 2827 - put_online_cpus(); 2847 + cpuhp_remove_state(bnx2fc_online_state); 2828 2848 2829 2849 destroy_workqueue(bnx2fc_wq); 2830 2850 /*
+23 -22
drivers/scsi/bnx2fc/bnx2fc_hwi.c
··· 1008 1008 return work; 1009 1009 } 1010 1010 1011 + /* Pending work request completion */ 1012 + static void bnx2fc_pending_work(struct bnx2fc_rport *tgt, unsigned int wqe) 1013 + { 1014 + unsigned int cpu = wqe % num_possible_cpus(); 1015 + struct bnx2fc_percpu_s *fps; 1016 + struct bnx2fc_work *work; 1017 + 1018 + fps = &per_cpu(bnx2fc_percpu, cpu); 1019 + spin_lock_bh(&fps->fp_work_lock); 1020 + if (fps->iothread) { 1021 + work = bnx2fc_alloc_work(tgt, wqe); 1022 + if (work) { 1023 + list_add_tail(&work->list, &fps->work_list); 1024 + wake_up_process(fps->iothread); 1025 + spin_unlock_bh(&fps->fp_work_lock); 1026 + return; 1027 + } 1028 + } 1029 + spin_unlock_bh(&fps->fp_work_lock); 1030 + bnx2fc_process_cq_compl(tgt, wqe); 1031 + } 1032 + 1011 1033 int bnx2fc_process_new_cqes(struct bnx2fc_rport *tgt) 1012 1034 { 1013 1035 struct fcoe_cqe *cq; ··· 1064 1042 /* Unsolicited event notification */ 1065 1043 bnx2fc_process_unsol_compl(tgt, wqe); 1066 1044 } else { 1067 - /* Pending work request completion */ 1068 - struct bnx2fc_work *work = NULL; 1069 - struct bnx2fc_percpu_s *fps = NULL; 1070 - unsigned int cpu = wqe % num_possible_cpus(); 1071 - 1072 - fps = &per_cpu(bnx2fc_percpu, cpu); 1073 - spin_lock_bh(&fps->fp_work_lock); 1074 - if (unlikely(!fps->iothread)) 1075 - goto unlock; 1076 - 1077 - work = bnx2fc_alloc_work(tgt, wqe); 1078 - if (work) 1079 - list_add_tail(&work->list, 1080 - &fps->work_list); 1081 - unlock: 1082 - spin_unlock_bh(&fps->fp_work_lock); 1083 - 1084 - /* Pending work request completion */ 1085 - if (fps->iothread && work) 1086 - wake_up_process(fps->iothread); 1087 - else 1088 - bnx2fc_process_cq_compl(tgt, wqe); 1045 + bnx2fc_pending_work(tgt, wqe); 1089 1046 num_free_sqes++; 1090 1047 } 1091 1048 cqe++;
+15 -49
drivers/scsi/bnx2i/bnx2i_init.c
··· 404 404 405 405 406 406 /** 407 - * bnx2i_percpu_thread_create - Create a receive thread for an 408 - * online CPU 407 + * bnx2i_cpu_online - Create a receive thread for an online CPU 409 408 * 410 409 * @cpu: cpu index for the online cpu 411 410 */ 412 - static void bnx2i_percpu_thread_create(unsigned int cpu) 411 + static int bnx2i_cpu_online(unsigned int cpu) 413 412 { 414 413 struct bnx2i_percpu_s *p; 415 414 struct task_struct *thread; ··· 418 419 thread = kthread_create_on_node(bnx2i_percpu_io_thread, (void *)p, 419 420 cpu_to_node(cpu), 420 421 "bnx2i_thread/%d", cpu); 422 + if (IS_ERR(thread)) 423 + return PTR_ERR(thread); 424 + 421 425 /* bind thread to the cpu */ 422 - if (likely(!IS_ERR(thread))) { 423 - kthread_bind(thread, cpu); 424 - p->iothread = thread; 425 - wake_up_process(thread); 426 - } 426 + kthread_bind(thread, cpu); 427 + p->iothread = thread; 428 + wake_up_process(thread); 429 + return 0; 427 430 } 428 431 429 - 430 - static void bnx2i_percpu_thread_destroy(unsigned int cpu) 432 + static int bnx2i_cpu_offline(unsigned int cpu) 431 433 { 432 434 struct bnx2i_percpu_s *p; 433 435 struct task_struct *thread; ··· 451 451 spin_unlock_bh(&p->p_work_lock); 452 452 if (thread) 453 453 kthread_stop(thread); 454 - } 455 - 456 - static int bnx2i_cpu_online(unsigned int cpu) 457 - { 458 - pr_info("bnx2i: CPU %x online: Create Rx thread\n", cpu); 459 - bnx2i_percpu_thread_create(cpu); 460 - return 0; 461 - } 462 - 463 - static int bnx2i_cpu_dead(unsigned int cpu) 464 - { 465 - pr_info("CPU %x offline: Remove Rx thread\n", cpu); 466 - bnx2i_percpu_thread_destroy(cpu); 467 454 return 0; 468 455 } 469 456 ··· 498 511 p->iothread = NULL; 499 512 } 500 513 501 - get_online_cpus(); 502 - 503 - for_each_online_cpu(cpu) 504 - bnx2i_percpu_thread_create(cpu); 505 - 506 - err = cpuhp_setup_state_nocalls(CPUHP_AP_ONLINE_DYN, 507 - "scsi/bnx2i:online", 508 - bnx2i_cpu_online, NULL); 514 + err = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "scsi/bnx2i:online", 515 + bnx2i_cpu_online, bnx2i_cpu_offline); 509 516 if (err < 0) 510 - goto remove_threads; 517 + goto unreg_driver; 511 518 bnx2i_online_state = err; 512 - 513 - cpuhp_setup_state_nocalls(CPUHP_SCSI_BNX2I_DEAD, "scsi/bnx2i:dead", 514 - NULL, bnx2i_cpu_dead); 515 - put_online_cpus(); 516 519 return 0; 517 520 518 - remove_threads: 519 - for_each_online_cpu(cpu) 520 - bnx2i_percpu_thread_destroy(cpu); 521 - put_online_cpus(); 521 + unreg_driver: 522 522 cnic_unregister_driver(CNIC_ULP_ISCSI); 523 523 unreg_xport: 524 524 iscsi_unregister_transport(&bnx2i_iscsi_transport); ··· 525 551 static void __exit bnx2i_mod_exit(void) 526 552 { 527 553 struct bnx2i_hba *hba; 528 - unsigned cpu = 0; 529 554 530 555 mutex_lock(&bnx2i_dev_lock); 531 556 while (!list_empty(&adapter_list)) { ··· 542 569 } 543 570 mutex_unlock(&bnx2i_dev_lock); 544 571 545 - get_online_cpus(); 546 - 547 - for_each_online_cpu(cpu) 548 - bnx2i_percpu_thread_destroy(cpu); 549 - 550 - cpuhp_remove_state_nocalls(bnx2i_online_state); 551 - cpuhp_remove_state_nocalls(CPUHP_SCSI_BNX2I_DEAD); 552 - put_online_cpus(); 572 + cpuhp_remove_state(bnx2i_online_state); 553 573 554 574 iscsi_unregister_transport(&bnx2i_iscsi_transport); 555 575 cnic_unregister_driver(CNIC_ULP_ISCSI);
+2 -1
drivers/scsi/qedf/qedf.h
··· 528 528 #define QEDF_WRITE (1 << 0) 529 529 #define MAX_FIBRE_LUNS 0xffffffff 530 530 531 - #define QEDF_MAX_NUM_CQS 8 531 + #define MIN_NUM_CPUS_MSIX(x) min_t(u32, x->dev_info.num_cqs, \ 532 + num_online_cpus()) 532 533 533 534 /* 534 535 * PCI function probe defines
+9 -11
drivers/scsi/qedf/qedf_main.c
··· 2760 2760 * we allocation is the minimum off: 2761 2761 * 2762 2762 * Number of CPUs 2763 - * Number of MSI-X vectors 2764 - * Max number allocated in hardware (QEDF_MAX_NUM_CQS) 2763 + * Number allocated by qed for our PCI function 2765 2764 */ 2766 - qedf->num_queues = min((unsigned int)QEDF_MAX_NUM_CQS, 2767 - num_online_cpus()); 2765 + qedf->num_queues = MIN_NUM_CPUS_MSIX(qedf); 2768 2766 2769 2767 QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_DISC, "Number of CQs is %d.\n", 2770 2768 qedf->num_queues); ··· 2960 2962 goto err1; 2961 2963 } 2962 2964 2965 + /* Learn information crucial for qedf to progress */ 2966 + rc = qed_ops->fill_dev_info(qedf->cdev, &qedf->dev_info); 2967 + if (rc) { 2968 + QEDF_ERR(&(qedf->dbg_ctx), "Failed to dev info.\n"); 2969 + goto err1; 2970 + } 2971 + 2963 2972 /* queue allocation code should come here 2964 2973 * order should be 2965 2974 * slowpath_start ··· 2981 2976 goto err2; 2982 2977 } 2983 2978 qed_ops->common->update_pf_params(qedf->cdev, &qedf->pf_params); 2984 - 2985 - /* Learn information crucial for qedf to progress */ 2986 - rc = qed_ops->fill_dev_info(qedf->cdev, &qedf->dev_info); 2987 - if (rc) { 2988 - QEDF_ERR(&(qedf->dbg_ctx), "Failed to dev info.\n"); 2989 - goto err1; 2990 - } 2991 2979 2992 2980 /* Record BDQ producer doorbell addresses */ 2993 2981 qedf->bdq_primary_prod = qedf->dev_info.primary_dbq_rq_addr;
+1 -30
drivers/scsi/sg.c
··· 751 751 return count; 752 752 } 753 753 754 - static bool sg_is_valid_dxfer(sg_io_hdr_t *hp) 755 - { 756 - switch (hp->dxfer_direction) { 757 - case SG_DXFER_NONE: 758 - if (hp->dxferp || hp->dxfer_len > 0) 759 - return false; 760 - return true; 761 - case SG_DXFER_FROM_DEV: 762 - /* 763 - * for SG_DXFER_FROM_DEV we always set dxfer_len to > 0. dxferp 764 - * can either be NULL or != NULL so there's no point in checking 765 - * it either. So just return true. 766 - */ 767 - return true; 768 - case SG_DXFER_TO_DEV: 769 - case SG_DXFER_TO_FROM_DEV: 770 - if (!hp->dxferp || hp->dxfer_len == 0) 771 - return false; 772 - return true; 773 - case SG_DXFER_UNKNOWN: 774 - if ((!hp->dxferp && hp->dxfer_len) || 775 - (hp->dxferp && hp->dxfer_len == 0)) 776 - return false; 777 - return true; 778 - default: 779 - return false; 780 - } 781 - } 782 - 783 754 static int 784 755 sg_common_write(Sg_fd * sfp, Sg_request * srp, 785 756 unsigned char *cmnd, int timeout, int blocking) ··· 771 800 "sg_common_write: scsi opcode=0x%02x, cmd_size=%d\n", 772 801 (int) cmnd[0], (int) hp->cmd_len)); 773 802 774 - if (!sg_is_valid_dxfer(hp)) 803 + if (hp->dxfer_len >= SZ_256M) 775 804 return -EINVAL; 776 805 777 806 k = sg_start_req(srp, cmnd);
-2
include/linux/cpuhotplug.h
··· 39 39 CPUHP_PCI_XGENE_DEAD, 40 40 CPUHP_IOMMU_INTEL_DEAD, 41 41 CPUHP_LUSTRE_CFS_DEAD, 42 - CPUHP_SCSI_BNX2FC_DEAD, 43 - CPUHP_SCSI_BNX2I_DEAD, 44 42 CPUHP_WORKQUEUE_PREP, 45 43 CPUHP_POWER_NUMA_PREPARE, 46 44 CPUHP_HRTIMERS_PREPARE,