Skip to content
  1. Jul 03, 2018
    • Bart Van Assche's avatar
      scsi: target: Avoid that EXTENDED COPY commands trigger lock inversion · 36d4cb46
      Bart Van Assche authored
      
      
      The approach for adding a device to the devices_idr data structure and for
      removing it is as follows:
      
      * &dev->dev_group.cg_item is initialized before a device is added to
        devices_idr.
      
      * If the reference count of a device drops to zero then
        target_free_device() removes the device from devices_idr.
      
      * All devices_idr manipulations are protected by device_mutex.
      
      This means that increasing the reference count of a device is sufficient to
      prevent removal from devices_idr and also that it is safe access
      dev_group.cg_item for any device that is referenced by devices_idr. Use
      this to modify target_find_device() and target_for_each_device() such that
      these functions no longer introduce a dependency between device_mutex and
      the configfs root inode mutex.
      
      Note: it is safe to pass a NULL pointer to config_item_put() and also to
      config_item_get_unless_zero().
      
      This patch prevents that lockdep reports the following complaint:
      
      ======================================================
      WARNING: possible circular locking dependency detected
      4.12.0-rc1-dbg+ #1 Not tainted
      ------------------------------------------------------
      rmdir/12053 is trying to acquire lock:
       (device_mutex#2){+.+.+.}, at: [<ffffffffa010afce>]
      target_free_device+0xae/0xf0 [target_core_mod]
      
      but task is already holding lock:
       (&sb->s_type->i_mutex_key#14){++++++}, at: [<ffffffff811c5c30>]
      vfs_rmdir+0x50/0x140
      
      which lock already depends on the new lock.
      
      the existing dependency chain (in reverse order) is:
      
      -> #1 (&sb->s_type->i_mutex_key#14){++++++}:
             lock_acquire+0x59/0x80
             down_write+0x36/0x70
             configfs_depend_item+0x3a/0xb0 [configfs]
             target_depend_item+0x13/0x20 [target_core_mod]
             target_xcopy_locate_se_dev_e4_iter+0x87/0x100 [target_core_mod]
             target_devices_idr_iter+0x16/0x20 [target_core_mod]
             idr_for_each+0x39/0xc0
             target_for_each_device+0x36/0x50 [target_core_mod]
             target_xcopy_locate_se_dev_e4+0x28/0x80 [target_core_mod]
             target_xcopy_do_work+0x2e9/0xdd0 [target_core_mod]
             process_one_work+0x1ca/0x3f0
             worker_thread+0x49/0x3b0
             kthread+0x109/0x140
             ret_from_fork+0x31/0x40
      
      -> #0 (device_mutex#2){+.+.+.}:
             __lock_acquire+0x101f/0x11d0
             lock_acquire+0x59/0x80
             __mutex_lock+0x7e/0x950
             mutex_lock_nested+0x16/0x20
             target_free_device+0xae/0xf0 [target_core_mod]
             target_core_dev_release+0x10/0x20 [target_core_mod]
             config_item_put+0x6e/0xb0 [configfs]
             configfs_rmdir+0x1a6/0x300 [configfs]
             vfs_rmdir+0xb7/0x140
             do_rmdir+0x1f4/0x200
             SyS_rmdir+0x11/0x20
             entry_SYSCALL_64_fastpath+0x23/0xc2
      
      other info that might help us debug this:
      
       Possible unsafe locking scenario:
      
             CPU0                    CPU1
             ----                    ----
        lock(&sb->s_type->i_mutex_key#14);
                                     lock(device_mutex#2);
                                     lock(&sb->s_type->i_mutex_key#14);
        lock(device_mutex#2);
      
       *** DEADLOCK ***
      
      3 locks held by rmdir/12053:
       #0:  (sb_writers#10){.+.+.+}, at: [<ffffffff811e223f>]
      mnt_want_write+0x1f/0x50
       #1:  (&sb->s_type->i_mutex_key#14/1){+.+.+.}, at: [<ffffffff811cb97e>]
      do_rmdir+0x15e/0x200
       #2:  (&sb->s_type->i_mutex_key#14){++++++}, at: [<ffffffff811c5c30>]
      vfs_rmdir+0x50/0x140
      
      stack backtrace:
      CPU: 3 PID: 12053 Comm: rmdir Not tainted 4.12.0-rc1-dbg+ #1
      Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS
      1.0.0-prebuilt.qemu-project.org 04/01/2014
      Call Trace:
       dump_stack+0x86/0xcf
       print_circular_bug+0x1c7/0x220
       __lock_acquire+0x101f/0x11d0
       lock_acquire+0x59/0x80
       __mutex_lock+0x7e/0x950
       mutex_lock_nested+0x16/0x20
       target_free_device+0xae/0xf0 [target_core_mod]
       target_core_dev_release+0x10/0x20 [target_core_mod]
       config_item_put+0x6e/0xb0 [configfs]
       configfs_rmdir+0x1a6/0x300 [configfs]
       vfs_rmdir+0xb7/0x140
       do_rmdir+0x1f4/0x200
       SyS_rmdir+0x11/0x20
       entry_SYSCALL_64_fastpath+0x23/0xc2
      
      Signed-off-by: default avatarBart Van Assche <bart.vanassche@wdc.com>
      [Rebased to handle conflict withe target_find_device removal]
      Signed-off-by: default avatarMike Christie <mchristi@redhat.com>
      
      Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
      36d4cb46
    • Bart Van Assche's avatar
      scsi: target: Use config_item_name() instead of open-coding it · 6f3bf5a2
      Bart Van Assche authored
      
      
      Some target code uses config_item_name() while other code accesses .ci_name
      directly. Make the target code consistent by switching to
      config_item_name().
      
      Signed-off-by: default avatarBart Van Assche <bart.vanassche@wdc.com>
      Reviewed-by: default avatarMike Christie <mchristi@redhat.com>
      Cc: Hannes Reinecke <hare@suse.com>
      Cc: Christoph Hellwig <hch@lst.de>
      Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
      6f3bf5a2
    • Ming Lei's avatar
      scsi: core: fix scsi_host_queue_ready · 265d59aa
      Ming Lei authored
      32872863
      
       ("scsi: avoid to hold host-wide counter of host_busy for
      scsi_mq") adds one extra check on scsi_host_busy(shost) in
      scsi_host_queue_ready(), which is wrong and not necessary, can causes
      booting stall on LSI53c895A.
      
      So remove the check.
      
      Cc: Omar Sandoval <osandov@fb.com>,
      Cc: "Martin K. Petersen" <martin.petersen@oracle.com>,
      Cc: James Bottomley <james.bottomley@hansenpartnership.com>,
      Cc: Christoph Hellwig <hch@lst.de>,
      Cc: Don Brace <don.brace@microsemi.com>
      Cc: Kashyap Desai <kashyap.desai@broadcom.com>
      Cc: Mike Snitzer <snitzer@redhat.com>
      Cc: Hannes Reinecke <hare@suse.de>
      Cc: Laurence Oberman <loberman@redhat.com>
      Cc: Bart Van Assche <bart.vanassche@wdc.com>
      Cc: Guenter Roeck <linux@roeck-us.net>
      Reported-by: default avatarGuenter Roeck <linux@roeck-us.net>
      Fixes: 32872863
      
       ("scsi: avoid to hold host-wide counter of host_busy for scsi_mq")
      Signed-off-by: default avatarMing Lei <ming.lei@redhat.com>
      Tested-by: default avatarGuenter Roeck <linux@roeck-us.net>
      Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
      265d59aa
    • Bart Van Assche's avatar
      scsi: klist: Make it safe to use klists in atomic context · 624fa779
      Bart Van Assche authored
      In the scsi_transport_srp implementation it cannot be avoided to
      iterate over a klist from atomic context when using the legacy block
      layer instead of blk-mq. Hence this patch that makes it safe to use
      klists in atomic context. This patch avoids that lockdep reports the
      following:
      
      WARNING: SOFTIRQ-safe -> SOFTIRQ-unsafe lock order detected
       Possible interrupt unsafe locking scenario:
      
             CPU0                    CPU1
             ----                    ----
        lock(&(&k->k_lock)->rlock);
                                     local_irq_disable();
                                     lock(&(&q->__queue_lock)->rlock);
                                     lock(&(&k->k_lock)->rlock);
        <Interrupt>
          lock(&(&q->__queue_lock)->rlock);
      
      stack backtrace:
      Workqueue: kblockd blk_timeout_work
      Call Trace:
       dump_stack+0xa4/0xf5
       check_usage+0x6e6/0x700
       __lock_acquire+0x185d/0x1b50
       lock_acquire+0xd2/0x260
       _raw_spin_lock+0x32/0x50
       klist_next+0x47/0x190
       device_for_each_child+0x8e/0x100
       srp_timed_out+0xaf/0x1d0 [scsi_transport_srp]
       scsi_times_out+0xd4/0x410 [scsi_mod]
       blk_rq_timed_out+0x36/0x70
       blk_timeout_work+0x1b5/0x220
       process_one_work+0x4fe/0xad0
       worker_thread+0x63/0x5a0
       kthread+0x1c1/0x1e0
       ret_from_fork+0x24/0x30
      
      See also commit c9ddf734
      
       ("scsi: scsi_transport_srp: Fix shost to
      rport translation").
      
      Signed-off-by: default avatarBart Van Assche <bart.vanassche@wdc.com>
      Cc: Martin K. Petersen <martin.petersen@oracle.com>
      Cc: James Bottomley <jejb@linux.vnet.ibm.com>
      Acked-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
      624fa779
    • Bart Van Assche's avatar
      scsi: sd_zbc: Remove an assignment from sd_zbc_setup_report_cmnd() · 68c3f904
      Bart Van Assche authored
      
      
      Since nr_bytes == blk_rq_bytes(rq) == rq->__data_len, the
      rq->__data_len = nr_bytes assignment does not modify the value of
      rq->__data_len. Hence remove that assignment. Note: the code in
      sd_done() that sets the residual to zero for zone report requests
      is not affected by this patch.
      
      Signed-off-by: default avatarBart Van Assche <bart.vanassche@wdc.com>
      Reviewed-by: default avatarDamien Le Moal <damien.lemoal@wdc.com>
      Cc: Hannes Reinecke <hare@suse.com>
      Cc: Johannes Thumshirn <jthumshirn@suse.de>
      Reviewed-by: default avatarJohannes Thumshirn <jthumshirn@suse.de>
      Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
      68c3f904
    • Dan Carpenter's avatar
      scsi: qedi: tidy up a size calculation · 915d9b71
      Dan Carpenter authored
      
      
      The id_tbl->table pointer points to unsigned long so static checkers
      complain that instead of 4 we should be allocating sizeof(long) bytes.
      
      We're trying to allocate enough bits for the bitmap.  The size variable is
      always 1024.  (1024 / 32 * 4) is the same as (1024 / 64 * 8) so this
      doesn't change runtime, but this is the more idiomatic way to do it and
      makes the static checker happy.
      
      [mkp: typo]
      
      Signed-off-by: default avatarDan Carpenter <dan.carpenter@oracle.com>
      Acked-by: default avatarManish Rangankar <Manish.Rangankar@cavium.com>
      Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
      915d9b71
    • Breno Leitao's avatar
      scsi: ibmvscsi: Improve strings handling · 1262dc09
      Breno Leitao authored
      
      
      Currently an open firmware property is copied into partition_name variable
      without keeping a room for \0.
      
      Later one, this variable (partition_name), which is 97 bytes long, is
      strncpyed into ibmvcsci_host_data->madapter_info->partition_name, which is
      96 bytes long, possibly truncating it 'again' and removing the \0.
      
      This patch simply decreases the partition name to 96 and just copy using
      strlcpy() which guarantees that the string is \0 terminated. I think there
      is no issue if this there is a truncation in this very first copy, i.e,
      when the open firmware property is read and copied into the driver for the
      very first time;
      
      This issue also causes the following warning on GCC 8:
      
      	drivers/scsi/ibmvscsi/ibmvscsi.c:281:2: warning:  strncpy  output may be truncated copying 96 bytes from a string of length 96 [-Wstringop-truncation]
      	...
      	inlined from  ibmvscsi_probe  at drivers/scsi/ibmvscsi/ibmvscsi.c:2221:7:
      	drivers/scsi/ibmvscsi/ibmvscsi.c:265:3: warning:  strncpy  specified bound 97 equals destination size [-Wstringop-truncation]
      
      CC: Bart Van Assche <bart.vanassche@wdc.com>
      CC: Tyrel Datwyler <tyreld@linux.vnet.ibm.com>
      Signed-off-by: default avatarBreno Leitao <leitao@debian.org>
      Acked-by: default avatarTyrel Datwyler <tyreld@linux.vnet.ibm.com>
      Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
      1262dc09
  2. Jun 27, 2018
  3. Jun 26, 2018
  4. Jun 22, 2018
  5. Jun 20, 2018