summaryrefslogtreecommitdiff
path: root/drivers/block
AgeCommit message (Collapse)Author
16 hoursMerge branch 'for-next' of ↵Mark Brown
https://git.kernel.org/pub/scm/linux/kernel/git/axboe/linux.git
16 hoursMerge branch 'modules-next' of ↵Mark Brown
https://git.kernel.org/pub/scm/linux/kernel/git/modules/linux.git
16 hoursMerge branch 'for-next' of ↵Mark Brown
https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git # Conflicts: # drivers/pci/pci.c # init/Kconfig # mm/internal.h
19 hoursMerge tag 'block-7.3-20261002' of ↵Linus Torvalds
git://git.kernel.org/pub/scm/linux/kernel/git/axboe/linux Pull block fixes from Jens Axboe: - NVMe fixes via Keith: - Fix an out-of-bounds write in nvmet_auth_challenge(), where sizeof() on a void pointer undercounted the challenge header and let a short AUTH_RECEIVE buffer pass the check - nvme-multipath fixes for an ANA log bounds check underflow, the command effects log lifetime for multipath heads, and only setting BLK_FEAT_ZONED after the zone info is known. - nvmet fixes for ns->enabled teardown ordering, rejecting I/O after the percpu ns reference is killed, device path preservation on allocation failure, and too-short SGL segments in pci-epf - nvme-tcp: revert the per-socket dynamic lockdep keys, and delay the socket reclassification - A DMA pool alignment quirk for the Micron 4100AT - Controller state/reset race fixes, and -Wformat-security workarounds - blk-mq: set RQF_USE_SCHED when the operation is known, and allow cached requests to be used for flush operations - Reject polled dio with user integrity metadata - Save the IRQ state in blkg_tryget_closest() - Set the zone write granularity in virtio_blk - ublk selftest fixes * tag 'block-7.3-20261002' of git://git.kernel.org/pub/scm/linux/kernel/git/axboe/linux: (23 commits) virtio_blk: set the zone write granularity nvme-multipath: set BLK_FEAT_ZONED only after the zone info is known nvme: fix command effects log lifetime for multipath heads nvmet: don't allow I/O admission after percpu ns reference is killed nvmet: defer setting ns->enabled to false in nvmet_ns_disable() nvmet: copy the hostid into the ctrl before creating PR pc_refs nvmet-auth: fix out-of-bounds write in nvmet_auth_challenge() nvmet: pci-epf: reject too-short SGL segments nvme-multipath: fix underflow in ANA log bounds checks nvme: work around all -Wformat-security warnings nvme: work around -Wformat-security warning nvme: do not reset controllers in NVME_CTRL_NEW state nvme-tcp: delay nvme_tcp_reclassify_socket() Revert "nvme-tcp: lockdep: use dynamic lockdep keys per socket instance" drbd: remove unused drbd_nl_mcgrps[] array blk-mq: allow cached requests to be used for flush operations blk-mq: set RQF_USE_SCHED when the operation is known block: reject polled dio with user integrity metadata selftests: ublk: fix unused_result error blk-cgroup: save IRQ state in blkg_tryget_closest() ...
36 hourszram: fix short reads from block_statePooyan Azad
read_block_state() formats each entry directly into the buffer supplied by read(). If the remaining buffer is too small for one complete record, snprintf() returns the full record length and the function stops without copying data or advancing the file position. A read from this debugfs file which is smaller than a record therefore returns zero at a non-EOF position and cannot make progress. Convert block_state to seq_file so formatted records are buffered independently of the userspace read size. Keep dev_lock held across each seq_file iteration and continue to protect individual entries with their slot locks. Link: https://lore.kernel.org/20260929071846.24829-1-pooyan.azadparvar@gmail.com Fixes: c0265342bff4 ("zram: introduce zram memory tracking") Signed-off-by: Pooyan Azad <pooyan.azadparvar@gmail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Closes: https://lore.kernel.org/r/CANC3H+LdtoydSp+o2ecErAw7k6R2+gRf9LyxcaoHv_mGhJmyQQ@mail.gmail.com/ Reviewed-by: Sergey Senozhatsky <senozhatsky@chromium.org> Tested-by: Sergey Senozhatsky <senozhatsky@chromium.org> Cc: Minchan Kim <minchan@kernel.org> Cc: Jens Axboe <axboe@kernel.dk>
36 hourszram: convert to SG-list zsmalloc object read APISergey Senozhatsky
Patch series "zsmallc: remove old object read API". zram remains the only user of old zsmalloc object read API. This series removes the old API and converts zram to use the new SG-list based API. This patch (of 2): zram remains the last user of old zsmalloc object read API, that performed linearisation on the zsmalloc side. There is a new SG-list API, that has a bunch of benefits. Switch zram to SG-list zsmalloc object read API. Link: https://lore.kernel.org/20260907105739.1793316-1-senozhatsky@chromium.org Link: https://lore.kernel.org/20260907105739.1793316-2-senozhatsky@chromium.org Signed-off-by: Sergey Senozhatsky <senozhatsky@chromium.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Cc: Minchan Kim <minchan@kernel.org> Cc: Nhat Pham <nphamcs@gmail.com>
36 hourszram: remove unreachable kernel_read_file_from_path() return checkSergey Senozhatsky
Sashiko reported that: kernel_read_file_from_path() returns negative error for zero-sized files, so we cannot have "sz == 0" return, remove it and use a generic error message instead. Link: https://lore.kernel.org/20260901051335.2202390-1-senozhatsky@chromium.org Signed-off-by: Sergey Senozhatsky <senozhatsky@chromium.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Cc: Haoqin Huang <haoqinhuang7@gmail.com>
36 hourszram: fix idle age_sec underflow in idle_store()Hao Jia
After commit 2e8ff2f51dde ("zram: use u32 for entry ac_time tracking"), idle_store() computes the idle cutoff as: cutoff = ktime_sub((u32)ktime_get_boottime_seconds(), age_sec); Because the left operand is cast to u32, when age_sec exceeds the current uptime the subtraction wraps modulo 2^32 and the huge result is zero-extended into the s64 cutoff. mark_idle() then marks every entry as idle instead of matching nothing. For instance, running echo 86400 > /sys/block/zramX/idle on a machine up for only two minutes marks all newly written pages idle and hands them to idle writeback and recompression. No slot can have been accessed before the system booted, so an age_sec that reaches back past uptime cannot match any slot. Return early in that case, without walking the table or taking any slot locks. Track the cutoff as time64_t rather than ktime_t. Both cutoff and ac_time are boot-time values in seconds, so a plain arithmetic comparison against ac_time in mark_idle() is correct and no ktime helpers are needed. Link: https://lore.kernel.org/20260828083149.45760-1-jiahao.kernel@gmail.com Fixes: 2e8ff2f51dde ("zram: use u32 for entry ac_time tracking") Signed-off-by: Hao Jia <jiahao1@lixiang.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Suggested-by: Sergey Senozhatsky <senozhatsky@chromium.org> Cc: Brian Geffon <bgeffon@google.com> Cc: Jens Axboe <axboe@kernel.dk> Cc: Minchan Kim <minchan@kernel.org> Cc: <stable@vger.kernel.org>
48 hoursMerge branch 'for-7.4/block' into for-nextJens Axboe
* for-7.4/block: block: amiflop: synchronize flush timer before track flush block: drop the cached plug time when blk_add_rq_to_plug() flushes ublk: drop the device reference outside ublk_ctl_mutex in DEL_DEV ublk: don't use an I/O scheduler by default
48 hoursblock: amiflop: synchronize flush timer before track flushRunyu Xiao
The amiflop track buffer is shared with the timer callback. timer_delete() does not wait for an in-flight callback, and that callback can rearm itself when it cannot acquire the floppy controller. A synchronous track flush can therefore race with the callback. Stop the timer before synchronous track writes and use timer_delete_sync() to wait for any callback already running. Keep callback rearming disabled until the write is complete. Apply this to the FDFMTTRK path as well. FDFLUSH, FDFMTTRK and close-time flushes run outside the blk-mq request callback. Freeze their queues so an in-flight request cannot change the shared track buffer while it is encoded and written. Restart the timer if a track remains dirty after a failed flush. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Cc: stable@vger.kernel.org Assisted-by: LLM Signed-off-by: Runyu Xiao <runyu.xiao@seu.edu.cn> Link: https://patch.msgid.link/20260930065951.2932739-1-runyu.xiao@seu.edu.cn Signed-off-by: Jens Axboe <axboe@kernel.dk>
48 hoursublk: drop the device reference outside ublk_ctl_mutex in DEL_DEVQiliang Yuan
ublk_ctrl_del_dev() drops its reference to the device while holding the global ublk_ctl_mutex. When this is the last reference, ublk_cdev_rel() frees the tag set, and blk_mq_free_tag_set() waits for the pending SRCU callbacks of the tag set with srcu_barrier(). Every DEL_DEV thus waits for an SRCU grace period with the mutex held, and deleting devices from several threads serializes on it. The release path doesn't need ublk_ctl_mutex. The device number is freed under ublk_idr_lock, and the last reference is already dropped without the mutex when the ublk server still has the char device open at DEL_DEV time, from ublk_ch_release_work_fn(). Drop the reference after unlocking ublk_ctl_mutex. ublk null target, 4000 single-queue devices, STOP_DEV + DEL_DEV issued from N threads, 16 vCPU KVM guest: threads before after 1 77.6 s 77.6 s 4 20.1 s 19.4 s 8 19.3 s 9.0 s 16 19.2 s 4.1 s Signed-off-by: Qiliang Yuan <odys.yuan@gmail.com> Reviewed-by: Ming Lei <tom.leiming@gmail.com> Link: https://patch.msgid.link/20261001-bug-ublk-del-dev-put-unlocked-v1-1-18e9bb9be727@gmail.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
48 hoursublk: don't use an I/O scheduler by defaultQiliang Yuan
Requests of a ublk device are handed to the ublk server through io_uring, and the server does its own queueing and ordering, so an I/O scheduler in front of the device only adds overhead. A single-queue ublk device still gets mq-deadline by default, which costs throughput on every I/O and an elevator setup on every START_DEV. Set BLK_MQ_F_NO_SCHED_BY_DEFAULT so that add_disk() selects "none", as loop does since commit 2112f5c1330a ("loop: Select I/O scheduler 'none' from inside add_disk()"). Doing it in the kernel also avoids switching the scheduler from user space after the device has been added, which waits for RCU grace periods. A scheduler can still be selected through sysfs. Zoned ublk devices don't need mq-deadline either, zone write plugging serializes writes per zone in the block layer since commit fde02699c242 ("block: mq-deadline: Remove support for zone write locking"). ublk null target, single-queue devices with depth 16, fio io_uring 4k randread at iodepth=16, 16 vCPU KVM guest: mq-deadline none 1 device 111K IOPS 342K IOPS 4 devices 286K IOPS 1070K IOPS START_DEV p50 (1000 devices) 8.53ms 0.36ms Signed-off-by: Qiliang Yuan <odys.yuan@gmail.com> Reviewed-by: Ming Lei <tom.leiming@gmail.com> Link: https://patch.msgid.link/20261001-bug-ublk-no-sched-by-default-v1-1-0bc91b6f075e@gmail.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
4 daysMerge branch 'block-7.3' into for-nextJens Axboe
* block-7.3: virtio_blk: set the zone write granularity
4 daysvirtio_blk: set the zone write granularityNiklas Cassel
virtblk_read_zoned_limits() reads the write granularity that the device reports in virtio_blk_zoned_characteristics and assigns it to the physical block size and to io_min, but never to the limit that is named after it. queue_limits.zone_write_granularity is left at zero, so blk_validate_zoned_limits() raises it to the logical block size: if (lim->zone_write_granularity < lim->logical_block_size) lim->zone_write_granularity = lim->logical_block_size; A device that reports a granularity coarser than its logical block size, which is what the field exists to express, therefore has it silently reduced. A 512e host managed disk passed through to a guest reports a logical block size of 512 and a write granularity of 4096, and the guest ends up with a zone write granularity of 512. bio_split_alignment() returns lim->zone_write_granularity if it is non-zero and bio_split_io_at() may split a bio with as per bio_split_alignment(). This can real to the write getting rejected by the host drive, as the write is not aligned to the physical block size. zonefs also takes its block size from bdev_zone_write_granularity(), so it would incorrectly use 512 on a disk that requires 4096. sd_zbc_read_zones() sets the limit from the physical block size for the same reason. NVMe ZNS and null_blk leave it unset, but the fallback gives the right answer for them, as their write granularity is the logical block size. virtio carries a separate value that may exceed it. Set the zone write granularity from the value that the device reports. Fixes: 95bfec41bd3d ("virtio-blk: add support for zoned block devices") Signed-off-by: Niklas Cassel <cassel@kernel.org> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> Link: https://patch.msgid.link/20260918140641.2031075-2-cassel@kernel.org Signed-off-by: Jens Axboe <axboe@kernel.dk>
4 daysMerge branch 'for-7.4/block' into for-nextJens Axboe
* for-7.4/block: rust: block: require `Sync` for `Operations::QueueData` rnull: configfs: add power to configfs features rnull: fix geometry store check-then-act across lock scopes rust: block: Fix GenDiskBuilder block size documentation rust: block: gen_disk: set fops.owner from driver module pointer rust: block: fix `Send` bound for `GenDisk` rust: block: rnull: use vertical import style rust: block: mq: remove redundant imports and format rust: block: mq: use vertical import style
4 daysrnull: configfs: add power to configfs featuresMalte Wechter
features displayed by configfs for rnull was inconsistent with the actual features available. This correctly exposes `power` as a feature, which is also consistent with the C null_blk driver. Fixes: d969d504bc13 ("rnull: enable configuration via `configfs`") Signed-off-by: Malte Wechter <maltewechter@gmail.com> Link: https://msgid.link/20260924-upstream-v7-3-rc3-v2-1-ca56ae7a73e9@gmail.com Signed-off-by: Andreas Hindborg <a.hindborg@kernel.org> Link: https://patch.msgid.link/20260929-rust-block-for-v7-4-rc1-b4-v1-8-642a4c1aebd7@kernel.org Signed-off-by: Jens Axboe <axboe@kernel.dk>
4 daysrnull: fix geometry store check-then-act across lock scopesQingxiao Xu
The blocksize/rotational/capacity/irqmode stores check powered under one Mutex acquisition, drop the guard, then update under a second acquisition. A concurrent power-on can create the live disk from stale geometry in between, leaving powered==true with config != live disk. Hold one guard for the powered check and the field update. Signed-off-by: Qingxiao Xu <qingxiao@tamu.edu> Link: https://msgid.link/20260908200845.405112-1-qingxiao@tamu.edu Signed-off-by: Andreas Hindborg <a.hindborg@kernel.org> Link: https://patch.msgid.link/20260929-rust-block-for-v7-4-rc1-b4-v1-7-642a4c1aebd7@kernel.org Signed-off-by: Jens Axboe <axboe@kernel.dk>
4 daysrust: block: rnull: use vertical import styleAlvin Sun
Convert `use` imports to vertical layout for better readability and maintainability. Signed-off-by: Alvin Sun <alvin.sun@linux.dev> Link: https://msgid.link/20260521-miscdev-use-format-v3-6-56240ca70d0c@linux.dev Signed-off-by: Andreas Hindborg <a.hindborg@kernel.org> Link: https://patch.msgid.link/20260929-rust-block-for-v7-4-rc1-b4-v1-3-642a4c1aebd7@kernel.org Signed-off-by: Jens Axboe <axboe@kernel.dk>
4 daysMerge branch 'for-7.4/block' into for-nextJens Axboe
* for-7.4/block: swim3: Fix FDEJECT ioctl for exclusive open swim: Fix FDEJECT ioctl for exclusive open swim: Return -EROFS when opened with BLK_OPEN_WRITE flag
4 daysswim3: Fix FDEJECT ioctl for exclusive openFinn Thain
The eject command from the util-linux package does not work with the swim3 driver: the drive doesn't eject anything and the command fails. Apparently, ioctl(fd, FDEJECT) returns -EBUSY after fd was opened O_EXCL. Fix this by checking ref_count for either 1 or -1. Either value means that the caller is the sole user of the disk. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Tested-by: Stan Johnson <userm57@yahoo.com> Signed-off-by: Finn Thain <fthain@linux-m68k.org> Link: https://patch.msgid.link/f4cb43726ee6f1cf159a6208f77b4cceea670a3c.1790641175.git.fthain@linux-m68k.org Signed-off-by: Jens Axboe <axboe@kernel.dk>
4 daysswim: Fix FDEJECT ioctl for exclusive openFinn Thain
The eject command from the util-linux package does not work with the swim driver: the drive doesn't eject anything and the command fails. Apparently, ioctl(fd, FDEJECT) returns -EBUSY when fd is opened O_EXCL. Fix this by checking ref_count for either 1 or -1. Either value means that the caller is the sole user of the disk. Fixes: 8852ecd97488 ("m68k: mac - Add SWIM floppy support") Tested-by: Stan Johnson <userm57@yahoo.com> Signed-off-by: Finn Thain <fthain@linux-m68k.org> Link: https://patch.msgid.link/ae3ee8e86833a2739d7857460cbe2addf4146088.1790641175.git.fthain@linux-m68k.org Signed-off-by: Jens Axboe <axboe@kernel.dk>
4 daysswim: Return -EROFS when opened with BLK_OPEN_WRITE flagFinn Thain
Write requests are not supported by the driver and produce IO errors as shown below. Avoid this by returning -EROFS when opened for writing. [ 4111.690000] I/O error, dev fd0, sector 2 op 0x1:(WRITE) flags 0x800800 phys_seg 1 prio class 2 [ 4111.700000] Buffer I/O error on dev fd0, logical block 2, lost async page write Fixes: 8852ecd97488 ("m68k: mac - Add SWIM floppy support") Tested-by: Stan Johnson <userm57@yahoo.com> Signed-off-by: Finn Thain <fthain@linux-m68k.org> Link: https://patch.msgid.link/327be6ca3c92c3411b5dfaeede014ed65a2d0f0f.1790641175.git.fthain@linux-m68k.org Signed-off-by: Jens Axboe <axboe@kernel.dk>
5 daysMerge branch 'for-7.4/block' into for-nextJens Axboe
* for-7.4/block: (53 commits) swim: Unexport global symbols swim: Define symbols for constants swim: Define macros for constants swim: Clean up whitespace swim: Remove unused macro definitions swim: Add some helpful references swim: Move swd initialization swim: Remove pointless specifiers swim: Don't search beyond the first data mark swim: Don't needlessly re-read sectors swim: Remove pointless mode0 register write swim: Revisit delays swim: Check drive ready bit swim: Deduplicate polling loops swim: Remove redundant RELAX actions swim: Convert to blocking queue swim: Fix buffer overflow swim: Don't use the mark register to read data swim: Check error register during sector read swim: Check for CRC errors ... Signed-off-by: Jens Axboe <axboe@kernel.dk>
5 daysMerge branch 'block-7.3' into for-nextJens Axboe
* block-7.3: (22 commits) nvme-multipath: set BLK_FEAT_ZONED only after the zone info is known nvme: fix command effects log lifetime for multipath heads nvmet: don't allow I/O admission after percpu ns reference is killed nvmet: defer setting ns->enabled to false in nvmet_ns_disable() nvmet: copy the hostid into the ctrl before creating PR pc_refs nvmet-auth: fix out-of-bounds write in nvmet_auth_challenge() nvmet: pci-epf: reject too-short SGL segments nvme-multipath: fix underflow in ANA log bounds checks nvme: work around all -Wformat-security warnings nvme: work around -Wformat-security warning nvme: do not reset controllers in NVME_CTRL_NEW state nvme-tcp: delay nvme_tcp_reclassify_socket() Revert "nvme-tcp: lockdep: use dynamic lockdep keys per socket instance" drbd: remove unused drbd_nl_mcgrps[] array blk-mq: allow cached requests to be used for flush operations blk-mq: set RQF_USE_SCHED when the operation is known block: reject polled dio with user integrity metadata selftests: ublk: fix unused_result error blk-cgroup: save IRQ state in blkg_tryget_closest() nvmet: preserve device path on allocation failure ...
9 daysdrbd: remove unused drbd_nl_mcgrps[] arrayArnd Bergmann
After the rework, two files have a copy of drbd_nl_mcgrps[], but one of them has no references: drivers/block/drbd/drbd_nl_gen.c:641:42: error: 'drbd_nl_mcgrps' defined but not used [-Werror=unused-const-variable=] 641 | static const struct genl_multicast_group drbd_nl_mcgrps[] = { | ^~~~~~~~~~~~~~ At the default warning level, -Wunused-const-variables is turned off, so this has gone unnoticed. Remove the extra variable. Fixes: 8098eeb693c4 ("drbd: replace genl_magic with explicit netlink serialization") Signed-off-by: Arnd Bergmann <arnd@arndb.de> Reviewed-by: Christoph Böhmwalder <christoph.boehmwalder@linbit.com> Link: https://patch.msgid.link/20260519203057.1340528-1-arnd@kernel.org Signed-off-by: Jens Axboe <axboe@kernel.dk>
10 daysswim: Unexport global symbolsFinn Thain
These symbols aren't used outside of this file so use local ones. No functional change. Reviewed-by: Laurent Vivier <laurent@vivier.eu> Signed-off-by: Finn Thain <fthain@linux-m68k.org> Tested-by: Stan Johnson <userm57@yahoo.com> Link: https://patch.msgid.link/0810de0df2a670d4d9ccad4e747be2c4b46f6d6e.1788513997.git.fthain@linux-m68k.org Signed-off-by: Jens Axboe <axboe@kernel.dk>
10 daysswim: Define symbols for constantsFinn Thain
Define local symbols to give some meaning to anonymous constants. No functional change. Reviewed-by: Laurent Vivier <laurent@vivier.eu> Signed-off-by: Finn Thain <fthain@linux-m68k.org> Tested-by: Stan Johnson <userm57@yahoo.com> Link: https://patch.msgid.link/7eee06428905fd7ad60909d9b5726c15cde1b844.1788513997.git.fthain@linux-m68k.org Signed-off-by: Jens Axboe <axboe@kernel.dk>
10 daysswim: Define macros for constantsFinn Thain
Define a SEL_MASK macro to name the anonymous constant. Define STEPPING rather than re-use STEP because the latter is a command bit macro (see also GCR_MODE vs. SETGCR). No functional change, just better readability. Reviewed-by: Laurent Vivier <laurent@vivier.eu> Signed-off-by: Finn Thain <fthain@linux-m68k.org> Tested-by: Stan Johnson <userm57@yahoo.com> Link: https://patch.msgid.link/64ee742adc48218962a989017b9dc5622e2932c7.1788513997.git.fthain@linux-m68k.org Signed-off-by: Jens Axboe <axboe@kernel.dk>
10 daysswim: Clean up whitespaceFinn Thain
No functional changes. Reviewed-by: Laurent Vivier <laurent@vivier.eu> Signed-off-by: Finn Thain <fthain@linux-m68k.org> Tested-by: Stan Johnson <userm57@yahoo.com> Link: https://patch.msgid.link/d33238b1b2c4a444ed3ae59d4444fafebb550921.1788513997.git.fthain@linux-m68k.org Signed-off-by: Jens Axboe <axboe@kernel.dk>
10 daysswim: Remove unused macro definitionsFinn Thain
Also remove the horizontal rule at the end of the macro definitions as it doesn't any add value, IMO. Reviewed-by: Laurent Vivier <laurent@vivier.eu> Signed-off-by: Finn Thain <fthain@linux-m68k.org> Tested-by: Stan Johnson <userm57@yahoo.com> Link: https://patch.msgid.link/d095be631aa91b6fd5704f4c159618d394a82414.1788513997.git.fthain@linux-m68k.org Signed-off-by: Jens Axboe <axboe@kernel.dk>
10 daysswim: Add some helpful referencesFinn Thain
These documents relate to the IWM, ISM, SWIM 1, 2, 3 and associated disk drives. No functional change. Reviewed-by: Laurent Vivier <laurent@vivier.eu> Signed-off-by: Finn Thain <fthain@linux-m68k.org> Tested-by: Stan Johnson <userm57@yahoo.com> Link: https://patch.msgid.link/082b79a3f2fa2ff5df9b51c582e01a8e47444613.1788513997.git.fthain@linux-m68k.org Signed-off-by: Jens Axboe <axboe@kernel.dk>
10 daysswim: Move swd initializationFinn Thain
For better readability, initialize the swd backpointer along with the other floppy_state struct members. No functional change. Reviewed-by: Laurent Vivier <laurent@vivier.eu> Signed-off-by: Finn Thain <fthain@linux-m68k.org> Tested-by: Stan Johnson <userm57@yahoo.com> Link: https://patch.msgid.link/613fa64bc857fecd141b5049eb9188ed72c9ec52.1788513997.git.fthain@linux-m68k.org Signed-off-by: Jens Axboe <axboe@kernel.dk>
10 daysswim: Remove pointless specifiersFinn Thain
If the compiler made these functions "as fast as possible" that wouldn't actually help because they involve slow mechanical operations. Remove pointless inline function specifiers. Reviewed-by: Laurent Vivier <laurent@vivier.eu> Signed-off-by: Finn Thain <fthain@linux-m68k.org> Tested-by: Stan Johnson <userm57@yahoo.com> Link: https://patch.msgid.link/e48ea61df817d30b5a50d1ced91c066b13cd47ae.1788513997.git.fthain@linux-m68k.org Signed-off-by: Jens Axboe <axboe@kernel.dk>
10 daysswim: Don't search beyond the first data markFinn Thain
The ISM chip does an automatic MFM gap/sync search when the Action bit is first set. That search may stop at any of a) post-index gap, b) address field gap or c) data field gap. To find the next sector header, the driver need not search at all. It only has to validate the mark bytes. Once the sector address mark has been validated, swim_read_sector_data() is called to read the sector contents. Between the sector address and data fields lies an intra-sector gap followed by a data field mark. After this mark is validated, the 512-byte data area is read into the IO request buffer. Problem is, if any byte in the data field mark is mis-read, the driver searches the whole sector and then reaches the data field mark in the following sector. The wrong sector is then read into the buffer, and swim_read_sector_data() returns success. The request is silently corrupted. The existing limit on polling loop iterations does constrain the search distance but is inherently tied to CPU speed. This is probably the reason why corruption was only observed on a 68030 system. Discontinue the mark search when the mark bytes fail validation. Fixes: 8852ecd97488 ("m68k: mac - Add SWIM floppy support") Signed-off-by: Finn Thain <fthain@linux-m68k.org> Tested-by: Stan Johnson <userm57@yahoo.com> Link: https://patch.msgid.link/f6c97153faa0aceceffd3a61d85c0a82903a6b3e.1788513997.git.fthain@linux-m68k.org Signed-off-by: Jens Axboe <axboe@kernel.dk>
10 daysswim: Don't needlessly re-read sectorsFinn Thain
floppy_read_sectors() is confusing because the `track' variable seems to conflate tracks and cylinders. Rename this variable, eliminate a division operation and adopt suitable integer types. For readahead to work effectively, small sequential reads should not require waiting for spindle rotation. Unfortunately, the present algorithm is very inefficient and does a lot of unnecessary waiting. E.g. if the device is asked to read sectors 1 thru 16, and if sector 9 happens to be under the heads, the driver will proceed to read sectors 9 thru 18, but discard the results, while it waits for sector 1 to arrive. If sector 1 couldn't be read on the first attempt and needs a retry, the driver will proceed to read sectors 2 thru 18, but discard the results, while it waits for sector 1 to come around again. In between reading sector 1 and sector 2, the driver needlessly calls swim_track() and swim_head() again. But what's worse is re-enabling interrupts after each sector, because on a 68030 system this can result in a full rotation between sectors (which would be a 200 ms wait). Floppy drivers usually implement a track cache that can be filled in a single rotation to solve such problems. But I think there is a simpler solution. After stepping the heads, use a sector bitmap to record sectors that were successfully read from the present track. Read (or retry, if need be) the requested sectors in whatever sequence they become available. Keep interrupts disabled until the whole track has passed under the read head. swim_read_sector() assumes that it can search a whole track by reading a fixed number of sector headers (essentially, fs->secpertrack) but this assumes no false sector headers are matched in the sector contents. To prevent that, call swim_read_sector_data() unconditionally after any valid sector header is matched. Fixes: 8852ecd97488 ("m68k: mac - Add SWIM floppy support") Signed-off-by: Finn Thain <fthain@linux-m68k.org> Tested-by: Stan Johnson <userm57@yahoo.com> Link: https://patch.msgid.link/dc4c1944edecb6778534b7b5535e6b6dd8d852ae.1788513997.git.fthain@linux-m68k.org Signed-off-by: Jens Axboe <axboe@kernel.dk>
10 daysswim: Remove pointless mode0 register writeFinn Thain
This write has no effect so remove it. (If side == 0 then no mode bit gets cleared. If side == 1 then mode bit 0 gets cleared but that's pointless because that bit is already clear here.) Reviewed-by: Laurent Vivier <laurent@vivier.eu> Signed-off-by: Finn Thain <fthain@linux-m68k.org> Tested-by: Stan Johnson <userm57@yahoo.com> Link: https://patch.msgid.link/acf12b671bbdbf5b986e41846f62ed8019d8d90b.1788513997.git.fthain@linux-m68k.org Signed-off-by: Jens Axboe <axboe@kernel.dk>
10 daysswim: Revisit delaysFinn Thain
AFAIK, timing requirements for the various FDHD drive mechanisms aren't well documented. But we do have the UPD72070 spec and secondary sources like swim3.c and mkLinux source code. This patch is needed to satisfy the requirements in the UPD72070 spec and follows mkLinux. Change the LSTRB pulse to 2 microseconds, because this is what mkLinux does. Inside Macintosh says, "Hold LSTRB high for at least one usec but not more than one msec". When a disk is ejected, pause before de-asserting /ENBL. Wait 150 us after the STEP command for valid signalling. Pause for 1 us after setting the step direction before sending the STEP command. Fixes: 8852ecd97488 ("m68k: mac - Add SWIM floppy support") Reviewed-by: Laurent Vivier <laurent@vivier.eu> Signed-off-by: Finn Thain <fthain@linux-m68k.org> Tested-by: Stan Johnson <userm57@yahoo.com> Link: https://patch.msgid.link/af356248a1e6a4fd956f71acf17feead27ba4918.1788513997.git.fthain@linux-m68k.org Signed-off-by: Jens Axboe <axboe@kernel.dk>
10 daysswim: Check drive ready bitFinn Thain
The drive provides a readiness signal that has to be tested before certain commands are issued to the drive. Rename the SEEK_COMPLETE flag as READY because that's how it's known in the documentation as well as the mkLinux source code. Poll for that signal after stepping the heads and also after switching to MFM mode, as that's what mkLinux does. Check for readiness when stepping because testing shows that some drives require this. Fixes: 8852ecd97488 ("m68k: mac - Add SWIM floppy support") Reviewed-by: Laurent Vivier <laurent@vivier.eu> Signed-off-by: Finn Thain <fthain@linux-m68k.org> Tested-by: Stan Johnson <userm57@yahoo.com> Link: https://patch.msgid.link/8d6fc833c719de2248b64ee521418b1032b1e509.1788513997.git.fthain@linux-m68k.org Signed-off-by: Jens Axboe <axboe@kernel.dk>
10 daysswim: Deduplicate polling loopsFinn Thain
Replace duplicated polling loops with poll_timeout_us(). Change the interruptible sleep to uninterruptible because signal delivery shouldn't be allowed to shorten delays required by the drive hardware. Change the timeout for the !STEP transition to 20 ms in accordance with the maximum interval required by the UPD72070 spec. The existing 1 second timeout is impractical considering the number of steps in a typical seek. Change the return type of swim_readbit() to bool because that way the bit names make sense i.e. the reader doesn't have to remember to invert the active-low logic used for drive signals. Fixes: 8852ecd97488 ("m68k: mac - Add SWIM floppy support") Reviewed-by: Laurent Vivier <laurent@vivier.eu> Signed-off-by: Finn Thain <fthain@linux-m68k.org> Tested-by: Stan Johnson <userm57@yahoo.com> Link: https://patch.msgid.link/0ea2d3313dea26f8b4c2abc4d29055ac95aeb74b.1788513997.git.fthain@linux-m68k.org Signed-off-by: Jens Axboe <axboe@kernel.dk>
10 daysswim: Remove redundant RELAX actionsFinn Thain
Wherever we have a swim_select() or swim_readbit() call there is an implicit RELAX. That means the caller doesn't have to do it. Remove the redundant code. BTW, Inside Macintosh says, "Be sure [...] that CA0 and CA1 are set high before changing SEL." Hence the RELAX found in swim_select(). The SwimIII driver in mkLinux also has that. But the swim3.c driver in Linux is odd: it scatters RELAX actions around as though SEL was not actually under its control... In anycase, swim.c really does control SEL so there's no need for that here. Reviewed-by: Laurent Vivier <laurent@vivier.eu> Signed-off-by: Finn Thain <fthain@linux-m68k.org> Tested-by: Stan Johnson <userm57@yahoo.com> Link: https://patch.msgid.link/08ab67c2780c9107b87a1ece8b5f9cb54a8cea70.1788513997.git.fthain@linux-m68k.org Signed-off-by: Jens Axboe <axboe@kernel.dk>
10 daysswim: Convert to blocking queueFinn Thain
These drives are slow: completing a request can take hundreds of milliseconds. Delays are managed by disabling interrupts judiciously and sleeping opportunistically. As of commit e3896d77b702 ("swim: convert to blk-mq"), a spinlock is taken in irq mode as soon as a request is issued. That lock is held for the duration of the request. Hence the driver sleeps while holding the lock which is forbidden. Adopt BLK_MQ_F_BLOCKING and remove the spinlock. Use a mutex to serialize requests from the two request queues. (The chip cannot simultaneously process requests on both internal and external drive.) Cc: Omar Sandoval <osandov@fb.com> Fixes: e3896d77b702 ("swim: convert to blk-mq") Reviewed-by: Laurent Vivier <laurent@vivier.eu> Signed-off-by: Finn Thain <fthain@linux-m68k.org> Tested-by: Stan Johnson <userm57@yahoo.com> Link: https://patch.msgid.link/d06b19132ec678d6168d158e10cd63e10da45607.1788513997.git.fthain@linux-m68k.org Signed-off-by: Jens Axboe <axboe@kernel.dk>
10 daysswim: Fix buffer overflowFinn Thain
The effect of this bug can be observed as swim_read_sector_data() inexplicably returning -5, or an error flag indicating that a mark byte was read from the data register, or other odd behviour. When copying bytes from the chip FIFO to the read buffer, the driver keeps count of the remaining buffer space using register %d4. A counter in register %d2 serves as a timeout. The driver polls (%a2), the handshake register, until flags indicate that byte(s) have arrived in the FIFO. movel #sector_size-1, %d4 read_new_data: movew #max_retry, %d2 read_data_loop: moveb %a2@, %d5 andb #0xc0, %d5 dbne %d2, read_data_loop beq data_exit moveb %a5@, %a4@+ andb #0x40, %d5 dbne %d4, read_new_data beq exit_loop Note that the exit_loop branch depends upon a flag in the handshake register and not on the remaining buffer space. Hence there may be no branch to exit_loop after %d4 is decremented to -1 (i.e. full buffer). moveb %a5@, %a4@+ dbra %d4, read_new_data exit_loop: Here is a second decrement of %d4 which can now reach -2. But the buffer bounds check is a comparison with -1, which is now ineffective. Hence the loop will continue copying until %d2 eventually reaches -1. Fix this bug by terminating the loop as soon as %d4 or %d2 reach -1. Reset the timeout whenever a byte is copied. Fixes: 8852ecd97488 ("m68k: mac - Add SWIM floppy support") Signed-off-by: Finn Thain <fthain@linux-m68k.org> Tested-by: Stan Johnson <userm57@yahoo.com> Link: https://patch.msgid.link/d8fceda197b840f892d9b511175e824ca2549f01.1788513997.git.fthain@linux-m68k.org Signed-off-by: Jens Axboe <axboe@kernel.dk>
10 daysswim: Don't use the mark register to read dataFinn Thain
If an unexpected mark byte were to be read from the data register, an error would be flagged. But no error gets flagged when such a byte is read from the mark register, which is misleading. Always use the data register except when a mark byte is expected. Fixes: 8852ecd97488 ("m68k: mac - Add SWIM floppy support") Reviewed-by: Laurent Vivier <laurent@vivier.eu> Signed-off-by: Finn Thain <fthain@linux-m68k.org> Tested-by: Stan Johnson <userm57@yahoo.com> Link: https://patch.msgid.link/fecd77b141bdd8a59ebae5f9efffccb155afdc4c.1788513997.git.fthain@linux-m68k.org Signed-off-by: Jens Axboe <axboe@kernel.dk>
10 daysswim: Check error register during sector readFinn Thain
Clear the error register only once before a sector read operation. Don't clear it afterwards -- the caller needs it. Check the error register in swim_read_sector() and return the appropriate error when necessary. Fully validate the sector header. Don't terminate the search loop early just because an erroneous sector header showed up. Fixes: 8852ecd97488 ("m68k: mac - Add SWIM floppy support") Reviewed-by: Laurent Vivier <laurent@vivier.eu> Signed-off-by: Finn Thain <fthain@linux-m68k.org> Tested-by: Stan Johnson <userm57@yahoo.com> Link: https://patch.msgid.link/efabd807f4ecf5cbc05b60e91ed69aa4c10691a8.1788513997.git.fthain@linux-m68k.org Signed-off-by: Jens Axboe <axboe@kernel.dk>
10 daysswim: Check for CRC errorsFinn Thain
After reading either the sector header or sector data, examine that flag in the handshake register which holds the result of the CRC calculation. CRC validation has to take place with the last byte still in the FIFO. This flag can't be checked by the caller because by then all bytes will have been retrieved from the FIFO. Return an error code when appropriate. Fixes: 8852ecd97488 ("m68k: mac - Add SWIM floppy support") Signed-off-by: Finn Thain <fthain@linux-m68k.org> Tested-by: Stan Johnson <userm57@yahoo.com> Link: https://patch.msgid.link/9bfcd0414192d1b95803c16701d62732ff6e8f3f.1788513997.git.fthain@linux-m68k.org Signed-off-by: Jens Axboe <axboe@kernel.dk>
10 daysswim: Simplify return value initializationFinn Thain
Initialize the error result once only. Update the result only after a successful read. Reviewed-by: Laurent Vivier <laurent@vivier.eu> Signed-off-by: Finn Thain <fthain@linux-m68k.org> Tested-by: Stan Johnson <userm57@yahoo.com> Link: https://patch.msgid.link/28322f0cbefd865bdfb679bab4352c111996795b.1788513997.git.fthain@linux-m68k.org Signed-off-by: Jens Axboe <axboe@kernel.dk>
10 daysswim: Handle FIFO timeout errorFinn Thain
When polling the FIFO for a mark byte in the sector header, don't return zero if the timeout counter has expired, return an error code. Reviewed-by: Laurent Vivier <laurent@vivier.eu> Fixes: 8852ecd97488 ("m68k: mac - Add SWIM floppy support") Signed-off-by: Finn Thain <fthain@linux-m68k.org> Tested-by: Stan Johnson <userm57@yahoo.com> Link: https://patch.msgid.link/aadb674d27d6e6d346d9b525597bf2e339c57e04.1788513997.git.fthain@linux-m68k.org Signed-off-by: Jens Axboe <axboe@kernel.dk>
10 daysswim: Add track zero recalibration delayFinn Thain
The UPD72070 spec indicates that the track zero sensor can take 3 ms to stabilize following a STEP command so add a call to msleep(). Remove the duplicate swim_readbit() call as there's no need for that once the sensor signal has stabilized. Reviewed-by: Laurent Vivier <laurent@vivier.eu> Fixes: 8852ecd97488 ("m68k: mac - Add SWIM floppy support") Signed-off-by: Finn Thain <fthain@linux-m68k.org> Tested-by: Stan Johnson <userm57@yahoo.com> Link: https://patch.msgid.link/6d17ca20a7286c1d74833b29510c506a66d96e6f.1788513997.git.fthain@linux-m68k.org Signed-off-by: Jens Axboe <axboe@kernel.dk>
10 daysswim: Recalibrate when drive is probedFinn Thain
Track zero recalibration can be slow and is normally done only once i.e. during system POST or boot-up. Recalibrate once after the drive is probed rather than every time the device is opened. Don't register the drive if recalibration fails. Park the heads before ejecting. Fixes: 8852ecd97488 ("m68k: mac - Add SWIM floppy support") Signed-off-by: Finn Thain <fthain@linux-m68k.org> Tested-by: Stan Johnson <userm57@yahoo.com> Link: https://patch.msgid.link/119e799afcc00d6bd4a479c31e0c960cb1a1d71b.1788513997.git.fthain@linux-m68k.org Signed-off-by: Jens Axboe <axboe@kernel.dk>
10 daysswim: Don't start motor until medium is presentFinn Thain
The spindle motor should not be running when a disk is to be inserted. Don't start the motor while the drive is empty. Reviewed-by: Laurent Vivier <laurent@vivier.eu> Fixes: 8852ecd97488 ("m68k: mac - Add SWIM floppy support") Signed-off-by: Finn Thain <fthain@linux-m68k.org> Tested-by: Stan Johnson <userm57@yahoo.com> Link: https://patch.msgid.link/7ea60e0bf6135b9bcd4be0991a257d4c5de22bb3.1788513997.git.fthain@linux-m68k.org Signed-off-by: Jens Axboe <axboe@kernel.dk>