1. 29 Jul, 2021 3 commits
  2. 19 Jun, 2021 1 commit
  3. 01 Jun, 2021 3 commits
  4. 12 Dec, 2020 1 commit
    • Sebastian Andrzej Siewior's avatar
      sr: Remove in_interrupt() usage in sr_init_command(). · 31cc0776
      Sebastian Andrzej Siewior authored
      The in_interrupt() check in sr_init_command() is a leftover from the
      past, pre v2.3.16 era to be exact. Back then the ioctl() was served by
      `sr' itself and sector size changes by CDROMREADMODE2 (as noted in the
      comment) were accounted within sr's data structures which allowed a
      "lazy" reset so it could be skipped on the next request and reset back
      to the default value once the device node was closed or before a command
      from the blockqueue was issued.
      
      This does not work like that anymore. The CDROMREADMODE2 is served by
      cdrom's mmc_ioctl() function which may change the sector size but the
      `sr' driver does not learn about it and so its ->sector_size is not
      updated.
      The ioctl() resets the changed sector size back to 2048.
      sr_read_sector() also resets the sector size back to the default once it
      is done.
      
      Remove the conditional sector size update from sr_init_command() and
      sr_release() because it is not needed.
      
      Link: https://lkml.kernel.org/r/20201204164803.ovwurzs3257em2rp@linutronix.de
      
      Signed-off-by: default avatarSebastian Andrzej Siewior <bigeasy@linutronix.de>
      Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
      31cc0776
  5. 08 Oct, 2020 2 commits
  6. 10 Sep, 2020 2 commits
  7. 23 Aug, 2020 1 commit
  8. 10 Jun, 2020 2 commits
  9. 04 May, 2020 1 commit
  10. 27 Apr, 2020 1 commit
  11. 01 Apr, 2020 1 commit
    • Bart Van Assche's avatar
      scsi: sr: Fix sr_block_release() · 72655c0e
      Bart Van Assche authored
      This patch fixes the following two complaints:
      
      WARNING: CPU: 3 PID: 1326 at kernel/locking/mutex-debug.c:103 mutex_destroy+0x74/0x80
      Modules linked in: scsi_debug sd_mod t10_pi brd scsi_transport_iscsi af_packet crct10dif_pclmul sg aesni_intel glue_helper virtio_balloon button crypto_simd cryptd intel_agp intel_gtt agpgart ip_tables x_tables ipv6 nf_defrag_ipv6 autofs4 ext4 crc16 mbcache jbd2 hid_generic usbhid hid sr_mod cdrom ata_generic pata_acpi virtio_blk virtio_net net_failover failover ata_piix xhci_pci ahci libahci xhci_hcd i2c_piix4 libata virtio_pci usbcore i2c_core virtio_ring scsi_mod usb_common virtio [last unloaded: scsi_debug]
      CPU: 3 PID: 1326 Comm: systemd-udevd Not tainted 5.6.0-rc1-dbg+ #1
      Hardware name: Bochs Bochs, BIOS Bochs 01/01/2011
      RIP: 0010:mutex_destroy+0x74/0x80
      Call Trace:
       sr_kref_release+0xb9/0xd0 [sr_mod]
       scsi_cd_put+0x79/0x90 [sr_mod]
       sr_block_release+0x54/0x70 [sr_mod]
       __blkdev_put+0x2ce/0x3c0
       blkdev_put+0x68/0x220
       blkdev_close+0x4d/0x60
       __fput+0x170/0x3b0
       ____fput+0x12/0x20
       task_work_run+0xa2/0xf0
       exit_to_usermode_loop+0xeb/0xf0
       do_syscall_64+0x2be/0x300
       entry_SYSCALL_64_after_hwframe+0x49/0xbe
      RIP: 0033:0x7fa16d40aab7
      
      BUG: KASAN: use-after-free in __mutex_unlock_slowpath+0x98/0x420
      Read of size 8 at addr ffff8881c6e4f4b0 by task systemd-udevd/1326
      
      CPU: 3 PID: 1326 Comm: systemd-udevd Tainted: G        W         5.6.0-rc1-dbg+ #1
      Hardware name: Bochs Bochs, BIOS Bochs 01/01/2011
      Call Trace:
       dump_stack+0xa5/0xe6
       print_address_description.constprop.0+0x46/0x60
       __kasan_report.cold+0x7b/0x94
       kasan_report+0x16/0x20
       check_memory_region+0x140/0x1b0
       __kasan_check_read+0x15/0x20
       __mutex_unlock_slowpath+0x98/0x420
       mutex_unlock+0x16/0x20
       sr_block_release+0x5c/0x70 [sr_mod]
       __blkdev_put+0x2ce/0x3c0
      hardirqs last  enabled at (1875522): [<ffffffff81bb0696>] _raw_spin_unlock_irqrestore+0x56/0x70
       blkdev_put+0x68/0x220
       blkdev_close+0x4d/0x60
       __fput+0x170/0x3b0
       ____fput+0x12/0x20
       task_work_run+0xa2/0xf0
       exit_to_usermode_loop+0xeb/0xf0
       do_syscall_64+0x2be/0x300
       entry_SYSCALL_64_after_hwframe+0x49/0xbe
      RIP: 0033:0x7fa16d40aab7
      
      Allocated by task 3201:
       save_stack+0x23/0x90
       __kasan_kmalloc.constprop.0+0xcf/0xe0
       kasan_kmalloc+0xd/0x10
       kmem_cache_alloc_trace+0x161/0x3c0
       sr_probe+0x12f/0xb60 [sr_mod]
       really_probe+0x183/0x5d0
       driver_probe_device+0x13f/0x1a0
       __device_attach_driver+0xe6/0x150
       bus_for_each_drv+0x101/0x160
       __device_attach+0x183/0x230
       device_initial_probe+0x17/0x20
       bus_probe_device+0x110/0x130
       device_add+0xb7b/0xd40
       scsi_sysfs_add_sdev+0xe8/0x360 [scsi_mod]
       scsi_probe_and_add_lun+0xdc4/0x14c0 [scsi_mod]
       __scsi_scan_target+0x12d/0x850 [scsi_mod]
       scsi_scan_channel+0xcd/0xe0 [scsi_mod]
       scsi_scan_host_selected+0x182/0x190 [scsi_mod]
       store_scan+0x1e9/0x200 [scsi_mod]
       dev_attr_store+0x42/0x60
       sysfs_kf_write+0x8b/0xb0
       kernfs_fop_write+0x158/0x250
       __vfs_write+0x4c/0x90
       vfs_write+0x145/0x2c0
       ksys_write+0xd7/0x180
       __x64_sys_write+0x47/0x50
       do_syscall_64+0x6f/0x300
       entry_SYSCALL_64_after_hwframe+0x49/0xbe
      
      Freed by task 1326:
       save_stack+0x23/0x90
       __kasan_slab_free+0x13a/0x190
       kasan_slab_free+0x12/0x20
       kfree+0x109/0x410
       sr_kref_release+0xc1/0xd0 [sr_mod]
       scsi_cd_put+0x79/0x90 [sr_mod]
       sr_block_release+0x54/0x70 [sr_mod]
       __blkdev_put+0x2ce/0x3c0
       blkdev_put+0x68/0x220
       blkdev_close+0x4d/0x60
       __fput+0x170/0x3b0
       ____fput+0x12/0x20
       task_work_run+0xa2/0xf0
       exit_to_usermode_loop+0xeb/0xf0
       do_syscall_64+0x2be/0x300
       entry_SYSCALL_64_after_hwframe+0x49/0xbe
      
      Link: https://lore.kernel.org/r/20200330025151.10535-1-bvanassche@acm.org
      Fixes: 51a85881
      
       ("scsi: sr: get rid of sr global mutex")
      Cc: Merlijn Wajer <merlijn@archive.org>
      Cc: Arnd Bergmann <arnd@arndb.de>
      Cc: <stable@kernel.org>
      Acked-by: default avatarMerlijn Wajer <merlijn@archive.org>
      Signed-off-by: default avatarBart Van Assche <bvanassche@acm.org>
      Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
      72655c0e
  12. 24 Feb, 2020 2 commits
  13. 03 Jan, 2020 2 commits
  14. 21 May, 2019 2 commits
  15. 12 Apr, 2019 1 commit
    • Martin Wilck's avatar
      block: disk_events: introduce event flags · c92e2f04
      Martin Wilck authored
      Currently, an empty disk->events field tells the block layer not to
      forward media change events to user space. This was done in commit
      7c88a168
      
       ("block: don't propagate unlisted DISK_EVENTs to userland")
      in order to avoid events from "fringe" drivers to be forwarded to user
      space. By doing so, the block layer lost the information which events
      were supported by a particular block device, and most importantly,
      whether or not a given device supports media change events at all.
      
      Prepare for not interpreting the "events" field this way in the future
      any more. This is done by adding an additional field "event_flags" to
      struct gendisk, and two flag bits that can be set to have the device
      treated like one that had the "events" field set to a non-zero value
      before. This applies only to the sd and sr drivers, which are changed to
      set the new flags.
      
      The new flags are DISK_EVENT_FLAG_POLL to enforce polling of the device
      for synchronous events, and DISK_EVENT_FLAG_UEVENT to tell the
      blocklayer to generate udev events from kernel events.
      
      In order to add the event_flags field to struct gendisk, the events
      field is converted to an "unsigned short"; it doesn't need to hold
      values bigger than 2 anyway.
      
      This patch doesn't change behavior.
      Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
      Signed-off-by: default avatarMartin Wilck <mwilck@suse.com>
      Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
      c92e2f04
  16. 06 Feb, 2019 1 commit
  17. 10 Nov, 2018 1 commit
  18. 28 Sep, 2018 1 commit
  19. 26 Sep, 2018 1 commit
    • Bart Van Assche's avatar
      block: Move power management code into a new source file · bca6b067
      Bart Van Assche authored
      
      Move the code for runtime power management from blk-core.c into the
      new source file blk-pm.c. Move the corresponding declarations from
      <linux/blkdev.h> into <linux/blk-pm.h>. For CONFIG_PM=n, leave out
      the declarations of the functions that are not used in that mode.
      This patch not only reduces the number of #ifdefs in the block layer
      core code but also reduces the size of header file <linux/blkdev.h>
      and hence should help to reduce the build time of the Linux kernel
      if CONFIG_PM is not defined.
      Signed-off-by: default avatarBart Van Assche <bvanassche@acm.org>
      Reviewed-by: default avatarMing Lei <ming.lei@redhat.com>
      Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
      Cc: Jianchao Wang <jianchao.w.wang@oracle.com>
      Cc: Hannes Reinecke <hare@suse.com>
      Cc: Johannes Thumshirn <jthumshirn@suse.de>
      Cc: Alan Stern <stern@rowland.harvard.edu>
      Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
      bca6b067
  20. 03 Aug, 2018 1 commit
    • Bart Van Assche's avatar
      scsi: sr: Avoid that opening a CD-ROM hangs with runtime power management enabled · 1214fd7b
      Bart Van Assche authored
      Surround scsi_execute() calls with scsi_autopm_get_device() and
      scsi_autopm_put_device(). Note: removing sr_mutex protection from the
      scsi_cd_get() and scsi_cd_put() calls is safe because the purpose of
      sr_mutex is to serialize cdrom_*() calls.
      
      This patch avoids that complaints similar to the following appear in the
      kernel log if runtime power management is enabled:
      
      INFO: task systemd-udevd:650 blocked for more than 120 seconds.
           Not tainted 4.18.0-rc7-dbg+ #1
      "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message.
      systemd-udevd   D28176   650    513 0x00000104
      Call Trace:
      __schedule+0x444/0xfe0
      schedule+0x4e/0xe0
      schedule_preempt_disabled+0x18/0x30
      __mutex_lock+0x41c/0xc70
      mutex_lock_nested+0x1b/0x20
      __blkdev_get+0x106/0x970
      blkdev_get+0x22c/0x5a0
      blkdev_open+0xe9/0x100
      do_dentry_open.isra.19+0x33e/0x570
      vfs_open+0x7c/0xd0
      path_openat+0x6e3/0x1120
      do_filp_open+0x11c/0x1c0
      do_sys_open+0x208/0x2d0
      __x6...
      1214fd7b
  21. 11 Apr, 2018 1 commit
    • Jens Axboe's avatar
      sr: get/drop reference to device in revalidate and check_events · 2d097c50
      Jens Axboe authored
      We can't just use scsi_cd() to get the scsi_cd structure, we have
      to grab a live reference to the device. For both callbacks, we're
      not inside an open where we already hold a reference to the device.
      
      This fixes device removal/addition under concurrent device access,
      which otherwise could result in the below oops.
      
      NULL pointer dereference at 0000000000000010
      PGD 0 P4D 0
      Oops: 0000 [#1] PREEMPT SMP
      Modules linked in:
      sr 12:0:0:0: [sr2] scsi-1 drive
       scsi_debug crc_t10dif crct10dif_generic crct10dif_common nvme nvme_core sb_edac xl
      sr 12:0:0:0: Attached scsi CD-ROM sr2
       sr_mod cdrom btrfs xor zstd_decompress zstd_compress xxhash lzo_compress zlib_defc
      sr 12:0:0:0: Attached scsi generic sg7 type 5
       igb ahci libahci i2c_algo_bit libata dca [last unloaded: crc_t10dif]
      CPU: 43 PID: 4629 Comm: systemd-udevd Not tainted 4.16.0+ #650
      Hardware name: Dell Inc. PowerEdge T630/0NT78X, BIOS 2.3.4 11/09/2016
      RIP: 0010:sr_block_revalidate_disk+0x23/0x190 [s...
      2d097c50
  22. 09 Mar, 2018 1 commit
    • Maurizio Lombardi's avatar
      cdrom: do not call check_disk_change() inside cdrom_open() · 2bbea6e1
      Maurizio Lombardi authored
      when mounting an ISO filesystem sometimes (very rarely)
      the system hangs because of a race condition between two tasks.
      
      PID: 6766   TASK: ffff88007b2a6dd0  CPU: 0   COMMAND: "mount"
       #0 [ffff880078447ae0] __schedule at ffffffff8168d605
       #1 [ffff880078447b48] schedule_preempt_disabled at ffffffff8168ed49
       #2 [ffff880078447b58] __mutex_lock_slowpath at ffffffff8168c995
       #3 [ffff880078447bb8] mutex_lock at ffffffff8168bdef
       #4 [ffff880078447bd0] sr_block_ioctl at ffffffffa00b6818 [sr_mod]
       #5 [ffff880078447c10] blkdev_ioctl at ffffffff812fea50
       #6 [ffff880078447c70] ioctl_by_bdev at ffffffff8123a8b3
       #7 [ffff880078447c90] isofs_fill_super at ffffffffa04fb1e1 [isofs]
       #8 [ffff880078447da8] mount_bdev at ffffffff81202570
       #9 [ffff880078447e18] isofs_mount at ffffffffa04f9828 [isofs]
      #10 [ffff880078447e28] mount_fs at ffffffff81202d09
      #11 [ffff880078447e70] vfs_kern_mount at ffffffff8121ea8f
      #12 [ffff880078447ea8] do_mount at ffffffff81220fee
      #13 [ffff...
      2bbea6e1
  23. 25 Aug, 2017 1 commit
  24. 07 Apr, 2017 1 commit
  25. 14 Feb, 2017 1 commit
  26. 31 Jan, 2017 1 commit
    • Christoph Hellwig's avatar
      block: fold cmd_type into the REQ_OP_ space · aebf526b
      Christoph Hellwig authored
      
      Instead of keeping two levels of indirection for requests types, fold it
      all into the operations.  The little caveat here is that previously
      cmd_type only applied to struct request, while the request and bio op
      fields were set to plain REQ_OP_READ/WRITE even for passthrough
      operations.
      
      Instead this patch adds new REQ_OP_* for SCSI passthrough and driver
      private requests, althought it has to add two for each so that we
      can communicate the data in/out nature of the request.
      Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
      Signed-off-by: default avatarJens Axboe <axboe@fb.com>
      aebf526b
  27. 24 Dec, 2016 1 commit
  28. 04 Sep, 2016 1 commit
  29. 27 Jun, 2016 1 commit
    • Dan Williams's avatar
      block: convert to device_add_disk() · 0d52c756
      Dan Williams authored
      
      For block drivers that specify a parent device, convert them to use
      device_add_disk().
      
      This conversion was done with the following semantic patch:
      
          @@
          struct gendisk *disk;
          expression E;
          @@
      
          - disk->driverfs_dev = E;
          ...
          - add_disk(disk);
          + device_add_disk(E, disk);
      
          @@
          struct gendisk *disk;
          expression E1, E2;
          @@
      
          - disk->driverfs_dev = E1;
          ...
          E2 = disk;
          ...
          - add_disk(E2);
          + device_add_disk(E1, E2);
      
      ...plus some manual fixups for a few missed conversions.
      
      Cc: Jens Axboe <axboe@fb.com>
      Cc: Keith Busch <keith.busch@intel.com>
      Cc: Michael S. Tsirkin <mst@redhat.com>
      Cc: David Woodhouse <dwmw2@infradead.org>
      Cc: David S. Miller <davem@davemloft.net>
      Cc: James Bottomley <James.Bottomley@hansenpartnership.com>
      Cc: Ross Zwisler <ross.zwisler@linux.intel.com>
      Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
      Cc: Martin K. Petersen <martin.petersen@oracle.com>
      Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
      Reviewed-by: default avatarJohannes Thumshirn <jthumshirn@suse.de>
      Signed-off-by: default avatarDan Williams <dan.j.williams@intel.com>
      0d52c756
  30. 27 Jan, 2016 1 commit