blk-mq: Rework blk-mq timeout handling again
Subsystems (14)
v10 cover blk-mq: Rework blk-mq timeout handling again
Hello Jens,
This is the tenth incarnation of the blk-mq timeout handling rework. All previously posted comments should have been addressed. Please consider this patch series for inclusion in the upstream kernel.
Bart.
Changes compared to v9:
- Addressed multiple comments related to patch 1/2: added CONFIG_ARCH_HAVE_CMPXCHG64 for riscv, modified features/locking/cmpxchg64/arch-support.txt as requested and made the order of the symbols in the arch/*/Kconfig alphabetical where possible.
Changes compared to v8:
- Split into two patches.
- Moved the spin_lock_init() call from blk_mq_rq_ctx_init() into blk_mq_init_request().
- Fixed the deadline set by blk_add_timer().
- Surrounded the das_lock member with #ifndef CONFIG_ARCH_HAVE_CMPXCHG64 / #endif.
Changes compared to v7:
- Fixed the generation number mechanism. Note: with this patch applied the behavior of the block layer does not depend on the generation number.
- Added more 32-bit architectures to the list of architectures on which cmpxchg64() should not be used.
Changes compared to v6:
- Used a union instead of bit manipulations to store multiple values into a single 64-bit field.
- Reduced the size of the timeout field from 64 to 32 bits.
- Made sure that the block layer still builds with this patch applied for the sh and mips architectures.
- Fixed two sparse warnings that were introduced by this patch in the WRITE_ONCE() calls.
Changes compared to v5:
- Restored the synchronize_rcu() call between marking a request for timeout handling and the actual timeout handling to avoid that timeout handling starts while .queue_rq() is still in progress if the timeout is very short.
- Only use cmpxchg() if another context could attempt to change the request state concurrently. Use WRITE_ONCE() otherwise.
Changes compared to v4:
- Addressed multiple review comments from Christoph. The most important are that atomic_long_cmpxchg() has been changed into cmpxchg() and also that there is now a nice and clean split between the legacy and blk-mq versions of blk_add_timer().
- Changed the patch name and modified the patch description because there is disagreement about whether or not the v4.16 blk-mq core can complete a single request twice. Kept the "Cc: stable" tag because of
https://bugzilla.kernel.org/show_bug.cgi?id=199077.
Changes compared to v3 (see also https://www.mail-archive.com/[email protected]/msg20073.html):
- Removed the spinlock again that was introduced to protect the request state.
v4 uses atomic_long_cmpxchg() instead.
- Split __deadline into two variables - one for the legacy block layer and one
for blk-mq.
Changes compared to v2 (https://www.mail-archive.com/[email protected]/msg18338.html):
- Rebased and retested on top of kernel v4.16.
Changes compared to v1 (https://www.mail-archive.com/[email protected]/msg18089.html):
- Removed the gstate and aborted_gstate members of struct request and used
the __deadline member to encode both the generation and state information.
Bart Van Assche (2):
arch/*: Add CONFIG_ARCH_HAVE_CMPXCHG64
blk-mq: Rework blk-mq timeout handling again
.../features/locking/cmpxchg64/arch-support.txt | 33 ++++ arch/Kconfig | 3 + arch/alpha/Kconfig | 1 + arch/arm/Kconfig | 1 + arch/arm64/Kconfig | 1 + arch/ia64/Kconfig | 1 + arch/m68k/Kconfig | 1 + arch/mips/Kconfig | 1 + arch/parisc/Kconfig | 1 + arch/powerpc/Kconfig | 1 + arch/riscv/Kconfig | 1 + arch/s390/Kconfig | 1 + arch/sparc/Kconfig | 1 + arch/x86/Kconfig | 1 + arch/xtensa/Kconfig | 1 + block/blk-core.c | 6 - block/blk-mq-debugfs.c | 1 - block/blk-mq.c | 183 ++++++--------------- block/blk-mq.h | 117 ++++++++++--- block/blk-timeout.c | 95 ++++++----- block/blk.h | 14 +- include/linux/blkdev.h | 47 +++--- 22 files changed, 279 insertions(+), 233 deletions(-) create mode 100644 Documentation/features/locking/cmpxchg64/arch-support.txt
Signature · 1 line
2.16.3
PATCH v10 1/2 arch/*: Add CONFIG_ARCH_HAVE_CMPXCHG64
The next patch in this series introduces a call to cmpxchg64() in the block layer core for those architectures on which this functionality is available. Make it possible to test whether cmpxchg64() is available by introducing CONFIG_ARCH_HAVE_CMPXCHG64.
--- .../features/locking/cmpxchg64/arch-support.txt | 33 ++++++++++++++++++++++ arch/Kconfig | 3 ++ arch/alpha/Kconfig | 1 + arch/arm/Kconfig | 1 + arch/arm64/Kconfig | 1 + arch/ia64/Kconfig | 1 + arch/m68k/Kconfig | 1 + arch/mips/Kconfig | 1 + arch/parisc/Kconfig | 1 + arch/powerpc/Kconfig | 1 + arch/riscv/Kconfig | 1 + arch/s390/Kconfig | 1 + arch/sparc/Kconfig | 1 + arch/x86/Kconfig | 1 + arch/xtensa/Kconfig | 1 + 15 files changed, 49 insertions(+) create mode 100644 Documentation/features/locking/cmpxchg64/arch-support.txt
Documentation/features/locking/cmpxchg64/arch-support.txt new file +33 -0
@@ -0,0 +1,33 @@ +# +# Feature name: cmpxchg64 +# Kconfig: ARCH_HAVE_CMPXCHG64 +# description: arch supports the cmpxchg64() API +# + ----------------------- + | arch |status| + ----------------------- + | alpha: | ok | + | arc: | .. | + | arm: | ok | + | arm64: | ok | + | c6x: | .. | + | h8300: | .. | + | hexagon: | .. | + | ia64: | ok | + | m68k: | ok | + | microblaze: | .. | + | mips: | ok | + | nds32: | .. | + | nios2: | .. | + | openrisc: | .. | + | parisc: | ok | + | powerpc: | ok | + | riscv: | ok | + | s390: | ok | + | sh: | .. | + | sparc: | ok | + | um: | .. | + | unicore32: | .. | + | x86: | ok | + | xtensa: | ok | + -----------------------
arch/Kconfig +3 -0
@@ -358,6 +358,9 @@ config HAVE_ALIGNED_STRUCT_PAGE on a struct page for better performance. However selecting this might increase the size of a struct page by a word. +config ARCH_HAVE_CMPXCHG64 + bool + config HAVE_CMPXCHG_LOCAL bool
arch/alpha/Kconfig +1 -0
@@ -15,6 +15,7 @@ config ALPHA select AUTO_IRQ_AFFINITY if SMP select GENERIC_IRQ_SHOW select ARCH_WANT_IPC_PARSE_VERSION + select ARCH_HAVE_CMPXCHG64 select ARCH_HAVE_NMI_SAFE_CMPXCHG select AUDIT_ARCH select GENERIC_CLOCKEVENTS
arch/arm/Kconfig +1 -0
@@ -13,6 +13,7 @@ config ARM select ARCH_HAS_STRICT_KERNEL_RWX if MMU && !XIP_KERNEL select ARCH_HAS_STRICT_MODULE_RWX if MMU select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCAST + select ARCH_HAVE_CMPXCHG64 if !THUMB2_KERNEL select ARCH_HAVE_CUSTOM_GPIO_H select ARCH_HAS_GCOV_PROFILE_ALL select ARCH_MIGHT_HAVE_PC_PARPORT
arch/arm64/Kconfig +1 -0
@@ -22,6 +22,7 @@ config ARM64 select ARCH_HAS_STRICT_KERNEL_RWX select ARCH_HAS_STRICT_MODULE_RWX select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCAST + select ARCH_HAVE_CMPXCHG64 select ARCH_HAVE_NMI_SAFE_CMPXCHG select ARCH_INLINE_READ_LOCK if !PREEMPT select ARCH_INLINE_READ_LOCK_BH if !PREEMPT
arch/ia64/Kconfig +1 -0
@@ -41,6 +41,7 @@ config IA64 select GENERIC_PENDING_IRQ if SMP select GENERIC_IRQ_SHOW select GENERIC_IRQ_LEGACY + select ARCH_HAVE_CMPXCHG64 select ARCH_HAVE_NMI_SAFE_CMPXCHG select GENERIC_IOMAP select GENERIC_SMP_IDLE_THREAD
arch/m68k/Kconfig +1 -0
@@ -11,6 +11,7 @@ config M68K select GENERIC_ATOMIC64 select HAVE_UID16 select VIRT_TO_BUS + select ARCH_HAVE_CMPXCHG64 select ARCH_HAVE_NMI_SAFE_CMPXCHG if RMW_INSNS select GENERIC_CPU_DEVICES select GENERIC_IOMAP
arch/mips/Kconfig +1 -0
@@ -7,6 +7,7 @@ config MIPS select ARCH_DISCARD_MEMBLOCK select ARCH_HAS_ELF_RANDOMIZE select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCAST + select ARCH_HAVE_CMPXCHG64 if 64BIT select ARCH_SUPPORTS_UPROBES select ARCH_USE_BUILTIN_BSWAP select ARCH_USE_CMPXCHG_LOCKREF if 64BIT
arch/parisc/Kconfig +1 -0
@@ -30,6 +30,7 @@ config PARISC select GENERIC_ATOMIC64 if !64BIT select GENERIC_IRQ_PROBE select GENERIC_PCI_IOMAP + select ARCH_HAVE_CMPXCHG64 select ARCH_HAVE_NMI_SAFE_CMPXCHG select GENERIC_SMP_IDLE_THREAD select GENERIC_CPU_DEVICES
arch/powerpc/Kconfig +1 -0
@@ -149,6 +149,7 @@ config PPC select ARCH_HAS_UACCESS_FLUSHCACHE if PPC64 select ARCH_HAS_UBSAN_SANITIZE_ALL select ARCH_HAS_ZONE_DEVICE if PPC_BOOK3S_64 + select ARCH_HAVE_CMPXCHG64 if PPC64 select ARCH_HAVE_NMI_SAFE_CMPXCHG select ARCH_MIGHT_HAVE_PC_PARPORT select ARCH_MIGHT_HAVE_PC_SERIO
arch/riscv/Kconfig +1 -0
@@ -8,6 +8,7 @@ config RISCV select OF select OF_EARLY_FLATTREE select OF_IRQ + select ARCH_HAVE_CMPXCHG64 select ARCH_WANT_FRAME_POINTERS select CLONE_BACKWARDS select COMMON_CLK
arch/s390/Kconfig +1 -0
@@ -73,6 +73,7 @@ config S390 select ARCH_HAS_STRICT_KERNEL_RWX select ARCH_HAS_STRICT_MODULE_RWX select ARCH_HAS_UBSAN_SANITIZE_ALL + select ARCH_HAVE_CMPXCHG64 select ARCH_HAVE_NMI_SAFE_CMPXCHG select ARCH_INLINE_READ_LOCK select ARCH_INLINE_READ_LOCK_BH
arch/sparc/Kconfig +1 -0
@@ -75,6 +75,7 @@ config SPARC64 select HAVE_PERF_EVENTS select PERF_USE_VMALLOC select IRQ_PREFLOW_FASTEOI + select ARCH_HAVE_CMPXCHG64 select ARCH_HAVE_NMI_SAFE_CMPXCHG select HAVE_C_RECORDMCOUNT select NO_BOOTMEM
arch/x86/Kconfig +1 -0
@@ -67,6 +67,7 @@ config X86 select ARCH_HAS_SYNC_CORE_BEFORE_USERMODE select ARCH_HAS_UBSAN_SANITIZE_ALL select ARCH_HAS_ZONE_DEVICE if X86_64 + select ARCH_HAVE_CMPXCHG64 select ARCH_HAVE_NMI_SAFE_CMPXCHG select ARCH_MIGHT_HAVE_ACPI_PDC if ACPI select ARCH_MIGHT_HAVE_PC_PARPORT
arch/xtensa/Kconfig +1 -0
@@ -4,6 +4,7 @@ config ZONE_DMA config XTENSA def_bool y + select ARCH_HAVE_CMPXCHG64 select ARCH_NO_COHERENT_DMA_MMAP if !MMU select ARCH_WANT_FRAME_POINTERS select ARCH_WANT_IPC_PARSE_VERSION
Signature · 1 line
2.16.3
PATCH v10 2/2 blk-mq: Rework blk-mq timeout handling again
In reply to Bart Van AsscheRecently the blk-mq timeout handling code was reworked. See also Tejun Heo, "[PATCHSET v4] blk-mq: reimplement timeout handling", 08 Jan 2018
(https://www.mail-archive.com/[email protected]/msg16985.html).
This patch reworks the blk-mq timeout handling code again. The timeout handling code is simplified by introducing a state machine per request. This change avoids that the blk-mq timeout handling code ignores completions that occur after blk_mq_check_expired() has been called and before blk_mq_rq_timed_out() has reset rq->aborted_gstate. If a block driver timeout handler always returns BLK_EH_RESET_TIMER then the result will be that the request never terminates.
Fix this race as follows:
- Replace the __deadline member of struct request by a new member called das that contains the generation number, state and deadline. Only 32 bits are used for the deadline field such that all three fields occupy only 64 bits. This change reduces the maximum supported request timeout value from (2**63/HZ) to (2**31/HZ).
- Remove all request member variables that became superfluous due to this change: gstate, gstate_seq and aborted_gstate_sync.
- Remove the request state information that became superfluous due to this patch, namely RQF_MQ_TIMEOUT_EXPIRED.
- Remove the code that became superfluous due to this change, namely the RCU lock and unlock statements in blk_mq_complete_request() and also the synchronize_rcu() call in the timeout handler.
Notes:
- A spinlock is used to protect atomic changes of rq->das on those architectures that do not provide a cmpxchg64() implementation.
- Atomic instructions are only used to update the request state if a concurrent request state change could be in progress.
- blk_add_timer() has been split into two functions - one for the legacy block layer and one for blk-mq.
--- block/blk-core.c | 6 -- block/blk-mq-debugfs.c | 1 - block/blk-mq.c | 183 ++++++++++++++----------------------------------- block/blk-mq.h | 117 +++++++++++++++++++++++-------- block/blk-timeout.c | 95 ++++++++++++++----------- block/blk.h | 14 ++-- include/linux/blkdev.h | 47 ++++++------- 7 files changed, 230 insertions(+), 233 deletions(-)
block/blk-core.c +0 -6
@@ -198,12 +198,6 @@ void blk_rq_init(struct request_queue *q, struct request *rq) rq->internal_tag =-1 ; rq->start_time_ns =ktime_get_ns (); rq->part =NULL ; -seqcount_init (&rq->gstate_seq); -u64_stats_init (&rq->aborted_gstate_sync); -/* -* See comment of blk_mq_init_request -*/ -WRITE_ONCE (rq->gstate,MQ_RQ_GEN_INC ); }EXPORT_SYMBOL (blk_rq_init);
block/blk-mq-debugfs.c +0 -1
@@ -344,7 +344,6 @@ static const char *const rqf_name[] = {RQF_NAME (STATS ),RQF_NAME (SPECIAL_PAYLOAD ),RQF_NAME (ZONE_WRITE_LOCKED ), -RQF_NAME (MQ_TIMEOUT_EXPIRED ), RQF_NAME(MQ_POLL_SLEPT), };#undef RQF_NAME
block/blk-mq.c +52 -131
293 lines not on this page · raw message
block/blk-mq.h +90 -27
151 lines not on this page · raw message
block/blk-timeout.c +56 -39
121 lines not on this page · raw message
block/blk.h +8 -6
@@ -170,6 +170,8 @@ static inline bool bio_integrity_endio(struct bio *bio)void blk_timeout_work (struct work_struct *work);unsigned long blk_rq_timeout (unsigned long timeout);void blk_add_timer (struct request *req); +void blk_mq_add_timer (struct request *req,enum mq_rq_state old, +enum mq_rq_state new);void blk_delete_timer (struct request *);
@@ -191,21 +193,21 @@ void blk_account_io_done(struct request *req, u64 now);/* * EH timer and IO completion will both attempt to 'grab' the request, make * sure that only one of them succeeds. Steal the bottom bit of the -* __deadline field for this. +* das field for this. */ static inline int blk_mark_rq_complete (struct request *rq) { -return test_and_set_bit (0 , &rq->__deadline); +return test_and_set_bit (0 , &rq->das.legacy_deadline); }static inline void blk_clear_rq_complete (struct request *rq) { -clear_bit (0 , &rq->__deadline); +clear_bit (0 , &rq->das.legacy_deadline); }static inline bool blk_rq_is_complete (struct request *rq) { -return test_bit (0 , &rq->__deadline); +return test_bit (0 , &rq->das.legacy_deadline); }/*
@@ -314,12 +316,12 @@ static inline void req_set_nomerge(struct request_queue *q, struct request *req)*/ static inline void blk_rq_set_deadline (struct request *rq,unsigned long time) { - rq->__deadline = time & ~0x1UL ; + rq->das.legacy_deadline = time & ~0x1UL ; }static inline unsigned long blk_rq_deadline (struct request *rq) { -return rq->__deadline & ~0x1UL ; +return rq->das.legacy_deadline & ~0x1UL ; }/*
include/linux/blkdev.h +24 -23
76 lines not on this page · raw message
Signature · 1 line
2.16.3
v9 cover blk-mq: Rework blk-mq timeout handling again
In reply to Bart Van AsscheHello Jens,
This is the ninth incarnation of the blk-mq timeout handling rework. All previously posted comments have been addressed. Please consider this patch series for inclusion in the upstream kernel.
Bart.
Changes compared to v8:
- Split into two patches.
- Moved the spin_lock_init() call from blk_mq_rq_ctx_init() into blk_mq_init_request().
- Fixed the deadline set by blk_add_timer().
- Surrounded the das_lock member with #ifndef CONFIG_ARCH_HAVE_CMPXCHG64 / #endif.
Changes compared to v7:
- Fixed the generation number mechanism. Note: with this patch applied the behavior of the block layer does not depend on the generation number.
- Added more 32-bit architectures to the list of architectures on which cmpxchg64() should not be used.
Changes compared to v6:
- Used a union instead of bit manipulations to store multiple values into a single 64-bit field.
- Reduced the size of the timeout field from 64 to 32 bits.
- Made sure that the block layer still builds with this patch applied for the sh and mips architectures.
- Fixed two sparse warnings that were introduced by this patch in the WRITE_ONCE() calls.
Changes compared to v5:
- Restored the synchronize_rcu() call between marking a request for timeout handling and the actual timeout handling to avoid that timeout handling starts while .queue_rq() is still in progress if the timeout is very short.
- Only use cmpxchg() if another context could attempt to change the request state concurrently. Use WRITE_ONCE() otherwise.
Changes compared to v4:
- Addressed multiple review comments from Christoph. The most important are that atomic_long_cmpxchg() has been changed into cmpxchg() and also that there is now a nice and clean split between the legacy and blk-mq versions of blk_add_timer().
- Changed the patch name and modified the patch description because there is disagreement about whether or not the v4.16 blk-mq core can complete a single request twice. Kept the "Cc: stable" tag because of
https://bugzilla.kernel.org/show_bug.cgi?id=199077.
Changes compared to v3 (see also https://www.mail-archive.com/[email protected]/msg20073.html):
- Removed the spinlock again that was introduced to protect the request state.
v4 uses atomic_long_cmpxchg() instead.
- Split __deadline into two variables - one for the legacy block layer and one
for blk-mq.
Changes compared to v2 (https://www.mail-archive.com/[email protected]/msg18338.html):
- Rebased and retested on top of kernel v4.16.
Changes compared to v1 (https://www.mail-archive.com/[email protected]/msg18089.html):
- Removed the gstate and aborted_gstate members of struct request and used
the __deadline member to encode both the generation and state information.
Bart Van Assche (2):
arch/*: Add CONFIG_ARCH_HAVE_CMPXCHG64
blk-mq: Rework blk-mq timeout handling again
.../features/locking/cmpxchg64/arch-support.txt | 31 ++++ arch/Kconfig | 3 + arch/alpha/Kconfig | 1 + arch/arm/Kconfig | 1 + arch/arm64/Kconfig | 1 + arch/ia64/Kconfig | 1 + arch/m68k/Kconfig | 1 + arch/mips/Kconfig | 1 + arch/parisc/Kconfig | 1 + arch/powerpc/Kconfig | 1 + arch/s390/Kconfig | 1 + arch/sparc/Kconfig | 1 + arch/x86/Kconfig | 1 + arch/xtensa/Kconfig | 1 + block/blk-core.c | 6 - block/blk-mq-debugfs.c | 1 - block/blk-mq.c | 183 ++++++--------------- block/blk-mq.h | 117 ++++++++++--- block/blk-timeout.c | 95 ++++++----- block/blk.h | 14 +- include/linux/blkdev.h | 47 +++--- 21 files changed, 276 insertions(+), 233 deletions(-) create mode 100644 Documentation/features/locking/cmpxchg64/arch-support.txt
Signature · 1 line
2.16.3
PATCH v9 1/2 arch/*: Add CONFIG_ARCH_HAVE_CMPXCHG64
In reply to Bart Van AsscheThe next patch in this series introduces a call to cmpxchg64() in the block layer core for those architectures on which this functionality is available. Make it possible to test whether cmpxchg64() is available by introducing CONFIG_ARCH_HAVE_CMPXCHG64.
f
--- .../features/locking/cmpxchg64/arch-support.txt | 31 ++++++++++++++++++++++ arch/Kconfig | 3 +++ arch/alpha/Kconfig | 1 + arch/arm/Kconfig | 1 + arch/arm64/Kconfig | 1 + arch/ia64/Kconfig | 1 + arch/m68k/Kconfig | 1 + arch/mips/Kconfig | 1 + arch/parisc/Kconfig | 1 + arch/powerpc/Kconfig | 1 + arch/s390/Kconfig | 1 + arch/sparc/Kconfig | 1 + arch/x86/Kconfig | 1 + arch/xtensa/Kconfig | 1 + 14 files changed, 46 insertions(+) create mode 100644 Documentation/features/locking/cmpxchg64/arch-support.txt
Documentation/features/locking/cmpxchg64/arch-support.txt new file +31 -0
@@ -0,0 +1,31 @@ +# +# Feature name: cmpxchg64 +# Kconfig: ARCH_HAVE_CMPXCHG64 +# description: arch supports the cmpxchg64() API +# + ----------------------- + | arch |status| + ----------------------- + | alpha: | ok | + | arc: | TODO | + | arm: |!thumb| + | arm64: | ok | + | c6x: | TODO | + | h8300: | TODO | + | hexagon: | TODO | + | ia64: | ok | + | m68k: | ok | + | microblaze: | TODO | + | mips: |64-bit| + | nios2: | TODO | + | openrisc: | TODO | + | parisc: | ok | + | powerpc: |64-bit| + | s390: | ok | + | sh: | TODO | + | sparc: | ok | + | um: | TODO | + | unicore32: | TODO | + | x86: | ok | + | xtensa: | ok | + -----------------------
arch/Kconfig +3 -0
@@ -358,6 +358,9 @@ config HAVE_ALIGNED_STRUCT_PAGE on a struct page for better performance. However selecting this might increase the size of a struct page by a word. +config ARCH_HAVE_CMPXCHG64 + bool + config HAVE_CMPXCHG_LOCAL bool
arch/alpha/Kconfig +1 -0
@@ -16,6 +16,7 @@ config ALPHA select GENERIC_IRQ_SHOW select ARCH_WANT_IPC_PARSE_VERSION select ARCH_HAVE_NMI_SAFE_CMPXCHG + select ARCH_HAVE_CMPXCHG64 select AUDIT_ARCH select GENERIC_CLOCKEVENTS select GENERIC_CPU_VULNERABILITIES
arch/arm/Kconfig +1 -0
@@ -21,6 +21,7 @@ config ARM select ARCH_SUPPORTS_ATOMIC_RMW select ARCH_USE_BUILTIN_BSWAP select ARCH_USE_CMPXCHG_LOCKREF + select ARCH_HAVE_CMPXCHG64 if !THUMB2_KERNEL select ARCH_WANT_IPC_PARSE_VERSION select BUILDTIME_EXTABLE_SORT if MMU select CLONE_BACKWARDS
arch/arm64/Kconfig +1 -0
@@ -23,6 +23,7 @@ config ARM64 select ARCH_HAS_STRICT_MODULE_RWX select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCAST select ARCH_HAVE_NMI_SAFE_CMPXCHG + select ARCH_HAVE_CMPXCHG64 select ARCH_INLINE_READ_LOCK if !PREEMPT select ARCH_INLINE_READ_LOCK_BH if !PREEMPT select ARCH_INLINE_READ_LOCK_IRQ if !PREEMPT
arch/ia64/Kconfig +1 -0
@@ -42,6 +42,7 @@ config IA64 select GENERIC_IRQ_SHOW select GENERIC_IRQ_LEGACY select ARCH_HAVE_NMI_SAFE_CMPXCHG + select ARCH_HAVE_CMPXCHG64 select GENERIC_IOMAP select GENERIC_SMP_IDLE_THREAD select ARCH_TASK_STRUCT_ON_STACK
arch/m68k/Kconfig +1 -0
@@ -12,6 +12,7 @@ config M68K select HAVE_UID16 select VIRT_TO_BUS select ARCH_HAVE_NMI_SAFE_CMPXCHG if RMW_INSNS + select ARCH_HAVE_CMPXCHG64 select GENERIC_CPU_DEVICES select GENERIC_IOMAP select GENERIC_STRNCPY_FROM_USER if MMU
arch/mips/Kconfig +1 -0
@@ -10,6 +10,7 @@ config MIPS select ARCH_SUPPORTS_UPROBES select ARCH_USE_BUILTIN_BSWAP select ARCH_USE_CMPXCHG_LOCKREF if 64BIT + select ARCH_HAVE_CMPXCHG64 if 64BIT select ARCH_USE_QUEUED_RWLOCKS select ARCH_USE_QUEUED_SPINLOCKS select ARCH_WANT_IPC_PARSE_VERSION
arch/parisc/Kconfig +1 -0
@@ -31,6 +31,7 @@ config PARISC select GENERIC_IRQ_PROBE select GENERIC_PCI_IOMAP select ARCH_HAVE_NMI_SAFE_CMPXCHG + select ARCH_HAVE_CMPXCHG64 select GENERIC_SMP_IDLE_THREAD select GENERIC_CPU_DEVICES select GENERIC_STRNCPY_FROM_USER
arch/powerpc/Kconfig +1 -0
@@ -150,6 +150,7 @@ config PPC select ARCH_HAS_UBSAN_SANITIZE_ALL select ARCH_HAS_ZONE_DEVICE if PPC_BOOK3S_64 select ARCH_HAVE_NMI_SAFE_CMPXCHG + select ARCH_HAVE_CMPXCHG64 select ARCH_MIGHT_HAVE_PC_PARPORT select ARCH_MIGHT_HAVE_PC_SERIO select ARCH_OPTIONAL_KERNEL_RWX if ARCH_HAS_STRICT_KERNEL_RWX
arch/s390/Kconfig +1 -0
@@ -74,6 +74,7 @@ config S390 select ARCH_HAS_STRICT_MODULE_RWX select ARCH_HAS_UBSAN_SANITIZE_ALL select ARCH_HAVE_NMI_SAFE_CMPXCHG + select ARCH_HAVE_CMPXCHG64 select ARCH_INLINE_READ_LOCK select ARCH_INLINE_READ_LOCK_BH select ARCH_INLINE_READ_LOCK_IRQ
arch/sparc/Kconfig +1 -0
@@ -76,6 +76,7 @@ config SPARC64 select PERF_USE_VMALLOC select IRQ_PREFLOW_FASTEOI select ARCH_HAVE_NMI_SAFE_CMPXCHG + select ARCH_HAVE_CMPXCHG64 select HAVE_C_RECORDMCOUNT select NO_BOOTMEM select HAVE_ARCH_AUDITSYSCALL
arch/x86/Kconfig +1 -0
@@ -68,6 +68,7 @@ config X86 select ARCH_HAS_UBSAN_SANITIZE_ALL select ARCH_HAS_ZONE_DEVICE if X86_64 select ARCH_HAVE_NMI_SAFE_CMPXCHG + select ARCH_HAVE_CMPXCHG64 select ARCH_MIGHT_HAVE_ACPI_PDC if ACPI select ARCH_MIGHT_HAVE_PC_PARPORT select ARCH_MIGHT_HAVE_PC_SERIO
arch/xtensa/Kconfig +1 -0
@@ -23,6 +23,7 @@ config XTENSA select HAVE_DMA_CONTIGUOUS select HAVE_EXIT_THREAD select HAVE_FUNCTION_TRACER + select ARCH_HAVE_CMPXCHG64 select HAVE_FUTEX_CMPXCHG if !MMU select HAVE_HW_BREAKPOINT if PERF_EVENTS select HAVE_IRQ_TIME_ACCOUNTING
Signature · 1 line
2.16.3
PATCH v9 2/2 blk-mq: Rework blk-mq timeout handling again
In reply to Bart Van AsscheRecently the blk-mq timeout handling code was reworked. See also Tejun Heo, "[PATCHSET v4] blk-mq: reimplement timeout handling", 08 Jan 2018
(https://www.mail-archive.com/[email protected]/msg16985.html).
This patch reworks the blk-mq timeout handling code again. The timeout handling code is simplified by introducing a state machine per request. This change avoids that the blk-mq timeout handling code ignores completions that occur after blk_mq_check_expired() has been called and before blk_mq_rq_timed_out() has reset rq->aborted_gstate. If a block driver timeout handler always returns BLK_EH_RESET_TIMER then the result will be that the request never terminates.
Fix this race as follows:
- Replace the __deadline member of struct request by a new member called das that contains the generation number, state and deadline. Only 32 bits are used for the deadline field such that all three fields occupy only 64 bits. This change reduces the maximum supported request timeout value from (2**63/HZ) to (2**31/HZ).
- Remove all request member variables that became superfluous due to this change: gstate, gstate_seq and aborted_gstate_sync.
- Remove the request state information that became superfluous due to this patch, namely RQF_MQ_TIMEOUT_EXPIRED.
- Remove the code that became superfluous due to this change, namely the RCU lock and unlock statements in blk_mq_complete_request() and also the synchronize_rcu() call in the timeout handler.
Notes:
- A spinlock is used to protect atomic changes of rq->das on those architectures that do not provide a cmpxchg64() implementation.
- Atomic instructions are only used to update the request state if a concurrent request state change could be in progress.
- blk_add_timer() has been split into two functions - one for the legacy block layer and one for blk-mq.
--- block/blk-core.c | 6 -- block/blk-mq-debugfs.c | 1 - block/blk-mq.c | 183 ++++++++++++++----------------------------------- block/blk-mq.h | 117 +++++++++++++++++++++++-------- block/blk-timeout.c | 95 ++++++++++++++----------- block/blk.h | 14 ++-- include/linux/blkdev.h | 47 ++++++------- 7 files changed, 230 insertions(+), 233 deletions(-)
block/blk-core.c +0 -6
@@ -198,12 +198,6 @@ void blk_rq_init(struct request_queue *q, struct request *rq) rq->internal_tag =-1 ; rq->start_time_ns =ktime_get_ns (); rq->part =NULL ; -seqcount_init (&rq->gstate_seq); -u64_stats_init (&rq->aborted_gstate_sync); -/* -* See comment of blk_mq_init_request -*/ -WRITE_ONCE (rq->gstate,MQ_RQ_GEN_INC ); }EXPORT_SYMBOL (blk_rq_init);
block/blk-mq-debugfs.c +0 -1
@@ -344,7 +344,6 @@ static const char *const rqf_name[] = {RQF_NAME (STATS ),RQF_NAME (SPECIAL_PAYLOAD ),RQF_NAME (ZONE_WRITE_LOCKED ), -RQF_NAME (MQ_TIMEOUT_EXPIRED ), RQF_NAME(MQ_POLL_SLEPT), };#undef RQF_NAME
block/blk-mq.c +52 -131
293 lines not on this page · raw message
block/blk-mq.h +90 -27
151 lines not on this page · raw message
block/blk-timeout.c +56 -39
121 lines not on this page · raw message
block/blk.h +8 -6
@@ -170,6 +170,8 @@ static inline bool bio_integrity_endio(struct bio *bio)void blk_timeout_work (struct work_struct *work);unsigned long blk_rq_timeout (unsigned long timeout);void blk_add_timer (struct request *req); +void blk_mq_add_timer (struct request *req,enum mq_rq_state old, +enum mq_rq_state new);void blk_delete_timer (struct request *);
@@ -191,21 +193,21 @@ void blk_account_io_done(struct request *req, u64 now);/* * EH timer and IO completion will both attempt to 'grab' the request, make * sure that only one of them succeeds. Steal the bottom bit of the -* __deadline field for this. +* das field for this. */ static inline int blk_mark_rq_complete (struct request *rq) { -return test_and_set_bit (0 , &rq->__deadline); +return test_and_set_bit (0 , &rq->das.legacy_deadline); }static inline void blk_clear_rq_complete (struct request *rq) { -clear_bit (0 , &rq->__deadline); +clear_bit (0 , &rq->das.legacy_deadline); }static inline bool blk_rq_is_complete (struct request *rq) { -return test_bit (0 , &rq->__deadline); +return test_bit (0 , &rq->das.legacy_deadline); }/*
@@ -314,12 +316,12 @@ static inline void req_set_nomerge(struct request_queue *q, struct request *req)*/ static inline void blk_rq_set_deadline (struct request *rq,unsigned long time) { - rq->__deadline = time & ~0x1UL ; + rq->das.legacy_deadline = time & ~0x1UL ; }static inline unsigned long blk_rq_deadline (struct request *rq) { -return rq->__deadline & ~0x1UL ; +return rq->das.legacy_deadline & ~0x1UL ; }/*
include/linux/blkdev.h +24 -23
76 lines not on this page · raw message
Signature · 1 line
2.16.3
Re: [PATCH v10 1/2] arch/*: Add CONFIG_ARCH_HAVE_CMPXCHG64
In reply to Bart Van Asschearch/powerpc/Kconfig config PPC · line 155
Quoted 12 lines · Bart Van Assche
arch/powerpc/Kconfig +1
-0@@ -149,6 +149,7 @@ config PPC select ARCH_HAS_UACCESS_FLUSHCACHE if PPC64 select ARCH_HAS_UBSAN_SANITIZE_ALL select ARCH_HAS_ZONE_DEVICE if PPC_BOOK3S_64 + select ARCH_HAVE_CMPXCHG64 if PPC64 select ARCH_HAVE_NMI_SAFE_CMPXCHG select ARCH_MIGHT_HAVE_PC_PARPORT select ARCH_MIGHT_HAVE_PC_SERIO
LGTM. Thanks.
cheers
Re: [PATCH v9 1/2] arch/*: Add CONFIG_ARCH_HAVE_CMPXCHG64
In reply to Bart Van Asschearch/Kconfig config HAVE_ALIGNED_STRUCT_PAGE · line 362
Quoted 2 lines
arch/Kconfig +2
-0+config ARCH_HAVE_CMPXCHG64 + bool
64-bit architectures must support this as long is 64-bits wide.
So this should have a
default y if 64BIT
which also means you only need to explicitly select in on 32-bit architectures that support 64-bit cmpxchg.
I've been looking at this carefully, and I don't think we need cmpxchg64 at all, and we don't need anywhere near as many cmpxchg operations either.
The only reason to include the deadline in the atomic operation is the blk_abort_request case, as the blk_mq_add_timer never modifies the deadline of a request that someone could be racing with. So if we introduce a new aborted state for use by blk_abort_request we can modify the deadline separately (and in fact have a common field with the legacy path).
Also anytime we call blk_mq_change_rq_state and don't care about the previous state it is a pretty clear indicator that we aren't racing with anyone else For blk_mq_free_request that obviously is the case as the request must have completed before, and for the requeue case we assume that. If it isn't the case we have a deeper problem going way back.
Below is a lightly tested patch on top of yours to implement these suggestions, and also making sure we only access the generation/state using WRITE_ONCE, READ_ONLY and cmpxchg to avoid any races due to reordering.
block/blk-mq.c +79 -33
@@ -274,6 +274,40 @@ bool blk_mq_can_queue(struct blk_mq_hw_ctx *hctx) }EXPORT_SYMBOL (blk_mq_can_queue); +/** +* blk_mq_change_rq_state - atomically test and set request state +* @rq: Request pointer. +* @old_state: Old request state. +* @new_state: New request state. +* +* Returns %true if and only if the old state was @old and if the state has +* been changed into @new. +*/ +static inline bool blk_mq_change_rq_state (struct request *rq, +enum mq_rq_state old_state,enum mq_rq_state new_state) +{ +union request_sag sag =READ_ONCE (rq->sag); +union request_sag old = sag, new = sag; + +BUILD_BUG_ON (sizeof (union request_sag ) !=sizeof (u32)); + + old.state = old_state; + new.state = new_state; +return cmpxchg (&rq->sag.val, old.val, new.val) == old.val; +} + +static inline void blk_mq_set_rq_state (struct request *rq, +enum mq_rq_state new_state) +{ +union request_sag sag =READ_ONCE (rq->sag); + +if (new_state ==MQ_RQ_IN_FLIGHT ) + sag.generation++; + sag.state = new_state; + +WRITE_ONCE (rq->sag, sag); +} +static struct request *blk_mq_rq_ctx_init (struct blk_mq_alloc_data *data,unsigned int tag,unsigned int op) {
@@ -318,7 +352,7 @@ static struct request *blk_mq_rq_ctx_init(struct blk_mq_alloc_data *data, rq->special =NULL ;/* tag was already set */ rq->extra_len =0 ; -WARN_ON_ONCE (rq->das.state !=MQ_RQ_IDLE ); +WARN_ON_ONCE (blk_mq_rq_state (rq) !=MQ_RQ_IDLE );INIT_LIST_HEAD (&rq->timeout_list); rq->timeout =0 ;
@@ -494,8 +528,7 @@ void blk_mq_free_request(struct request *rq)if (blk_rq_rl (rq))blk_put_rl (blk_rq_rl (rq)); -if (!blk_mq_change_rq_state (rq,blk_mq_rq_state (rq),MQ_RQ_IDLE )) -WARN_ON_ONCE (true); +blk_mq_set_rq_state (rq,MQ_RQ_IDLE );if (rq->tag !=-1 )blk_mq_put_tag (hctx, hctx->tags, ctx, rq->tag);if (sched_tag !=-1 )
@@ -619,6 +652,14 @@ int blk_mq_request_started(struct request *rq) }EXPORT_SYMBOL_GPL (blk_mq_request_started); +static inline void __blk_mq_start_request (struct request *rq) +{ + rq->__deadline = jiffies + + (rq->timeout ? rq->timeout : rq->q->rq_timeout); +__blk_add_timer (rq, rq->__deadline); +blk_mq_set_rq_state (rq,MQ_RQ_IN_FLIGHT ); +} +void blk_mq_start_request (struct request *rq) {struct request_queue *q = rq->q;
@@ -636,7 +677,7 @@ void blk_mq_start_request(struct request *rq)wbt_issue (q->rq_wb, rq); } -blk_mq_add_timer (rq,MQ_RQ_IDLE ,MQ_RQ_IN_FLIGHT ); +__blk_mq_start_request (rq);if (q->dma_drain_size &&blk_rq_bytes (rq)) {/*
@@ -652,16 +693,18 @@ EXPORT_SYMBOL(blk_mq_start_request);static void __blk_mq_requeue_request (struct request *rq) {struct request_queue *q = rq->q; -enum mq_rq_state old_state =blk_mq_rq_state (rq);blk_mq_put_driver_tag (rq);trace_block_rq_requeue (q, rq);wbt_requeue (q->rq_wb, rq); -if (old_state !=MQ_RQ_IDLE ) { -if (!blk_mq_change_rq_state (rq, old_state,MQ_RQ_IDLE )) -WARN_ON_ONCE (true); +/* +* Note: the driver must ensure this doesn't race with completions or +* timeouts. +*/ +if (blk_mq_rq_state (rq) !=MQ_RQ_IDLE ) { +blk_mq_set_rq_state (rq,MQ_RQ_IDLE );if (q->dma_drain_size &&blk_rq_bytes (rq)) rq->nr_phys_segments--; }
@@ -778,7 +821,7 @@ static void blk_mq_rq_timed_out(struct request *req, bool reserved)__blk_mq_complete_request (req);break ;case BLK_EH_RESET_TIMER : -blk_mq_add_timer (req,MQ_RQ_COMPLETE ,MQ_RQ_IN_FLIGHT ); +__blk_mq_start_request (req);break ;case BLK_EH_NOT_HANDLED :break ;
@@ -792,23 +835,26 @@ static void blk_mq_check_expired(struct blk_mq_hw_ctx *hctx, struct request *rq, void *priv, bool reserved) { struct blk_mq_timeout_data *data = priv; -union blk_deadline_and_state das =READ_ONCE (rq->das);unsigned long now = jiffies; -int32_t diff_jiffies = das.deadline - now; -int32_t diff_next = das.deadline - data->next; -enum mq_rq_state rq_state = das.state; +unsigned long deadline =READ_ONCE (rq->__deadline); +union request_sag sag =READ_ONCE (rq->sag); +union request_sag aborted_sag = sag; +long diff_jiffies = deadline - now; +long diff_next = deadline - data->next;/* -* Make sure that rq->aborted_gstate != rq->das if rq->deadline has not +* Make sure that rq->aborted_sag != rq->sag if rq->deadline has not * yet been reached even if a request gets recycled before -* blk_mq_terminate_expired() is called and the value of rq->deadline +* blk_mq_terminate_expired() is called and the value of rq->__deadline * is not modified due to the request recycling. */ - rq->aborted_gstate = das; - rq->aborted_gstate.generation ^= (1UL <<29 ); -if (diff_jiffies <=0 && rq_state ==MQ_RQ_IN_FLIGHT ) { -/* request timed out */ - rq->aborted_gstate = das; + aborted_sag.generation ^= (1u <<29 ); +WRITE_ONCE (rq->aborted_sag, aborted_sag); + +if (sag.state ==MQ_RQ_ABORTED || + (sag.state ==MQ_RQ_IN_FLIGHT && diff_jiffies <=0 )) { +/* request aborted or timed out */ +WRITE_ONCE (rq->aborted_sag, sag); data->nr_expired++; hctx->nr_expired++; }else if (!data->next_set) {
@@ -819,23 +865,21 @@ static void blk_mq_check_expired(struct blk_mq_hw_ctx *hctx,/* data->next is later than deadline; reduce data->next. */ data->next += diff_next; } - }static void blk_mq_terminate_expired (struct blk_mq_hw_ctx *hctx,struct request *rq,void *priv,bool reserved) { -union blk_deadline_and_state old_val = rq->aborted_gstate; -union blk_deadline_and_state new_val = old_val; - - new_val.state =MQ_RQ_COMPLETE ; +union request_sag old =READ_ONCE (rq->aborted_sag); +union request_sag new = old;/* -* We marked @rq->aborted_gstate and waited for ongoing .queue_rq() -* calls. If rq->das has not changed that means that it -* is now safe to change the request state and to handle the timeout. +* We marked @rq->aborted_sag and waited for ongoing .queue_rq() calls. +* If rq->sag has not changed that means that it is now safe to change +* the request state and to handle the timeout. */ -if (blk_mq_set_rq_state (rq, old_val, new_val)) + new.state =MQ_RQ_COMPLETE ; +if (cmpxchg (&rq->sag.val, old.val, new.val) == old.val)blk_mq_rq_timed_out (rq, reserved); }
@@ -916,6 +960,12 @@ static void blk_mq_timeout_work(struct work_struct *work)blk_queue_exit (q); } +void blk_mq_abort_request (struct request *rq) +{ +if (blk_mq_change_rq_state (rq,MQ_RQ_IN_FLIGHT ,MQ_RQ_ABORTED )) +kblockd_schedule_work (&rq->q->timeout_work); +} +struct flush_busy_ctx_data {struct blk_mq_hw_ctx *hctx;struct list_head *list;
@@ -1983,10 +2033,6 @@ static int blk_mq_init_request(struct blk_mq_tag_set *set, struct request *rq, {int ret; -#ifndef CONFIG_ARCH_HAVE_CMPXCHG64 -spin_lock_init (&rq->das_lock); -#endif -if (set->ops->init_request) { ret = set->ops->init_request (set, rq, hctx_idx, node);if (ret)
block/blk-mq.h +4 -97
134 lines not on this page · raw message
block/blk-timeout.c +2 -34
@@ -157,14 +157,7 @@ void blk_timeout_work(struct work_struct *work)void blk_abort_request (struct request *req) {if (req->q->mq_ops) { -/* -* All we need to ensure is that timeout scan takes place -* immediately and that scan sees the new timeout value. -* No need for fancy synchronizations. -*/ -if (blk_mq_rq_set_deadline (req, jiffies,MQ_RQ_IN_FLIGHT , -MQ_RQ_IN_FLIGHT )) -kblockd_schedule_work (&req->q->timeout_work); +blk_mq_abort_request (req); }else {if (blk_mark_rq_complete (req))return ;
@@ -185,7 +178,7 @@ unsigned long blk_rq_timeout(unsigned long timeout)return timeout; } -static void __blk_add_timer (struct request *req,unsigned long deadline) +void __blk_add_timer (struct request *req,unsigned long deadline) {struct request_queue *q = req->q;unsigned long expiry;
@@ -238,28 +231,3 @@ void blk_add_timer(struct request *req)return __blk_add_timer (req, deadline); } - -/** -* blk_mq_add_timer - set the deadline for a single request -* @req: request for which to set the deadline. -* @old: current request state. -* @new: new request state. -* -* Sets the deadline of a request if and only if it has state @old and -* at the same time changes the request state from @old into @new. The caller -* must guarantee that the request state won't be modified while this function -* is in progress. -*/ -void blk_mq_add_timer (struct request *req,enum mq_rq_state old, -enum mq_rq_state new) -{ -struct request_queue *q = req->q; -unsigned long deadline; - -if (!req->timeout) - req->timeout = q->rq_timeout; - deadline = jiffies + req->timeout; -if (!blk_mq_rq_set_deadline (req, deadline, old, new)) -WARN_ON_ONCE (true); -return __blk_add_timer (req, deadline); -}
block/blk.h +7 -8
@@ -170,8 +170,7 @@ static inline bool bio_integrity_endio(struct bio *bio)void blk_timeout_work (struct work_struct *work);unsigned long blk_rq_timeout (unsigned long timeout);void blk_add_timer (struct request *req); -void blk_mq_add_timer (struct request *req,enum mq_rq_state old, -enum mq_rq_state new); +void __blk_add_timer (struct request *req,unsigned long deadline);void blk_delete_timer (struct request *);
@@ -193,21 +192,21 @@ void blk_account_io_done(struct request *req, u64 now);/* * EH timer and IO completion will both attempt to 'grab' the request, make * sure that only one of them succeeds. Steal the bottom bit of the -* das field for this. +* __deadline field for this. */ static inline int blk_mark_rq_complete (struct request *rq) { -return test_and_set_bit (0 , &rq->das.legacy_deadline); +return test_and_set_bit (0 , &rq->__deadline); }static inline void blk_clear_rq_complete (struct request *rq) { -clear_bit (0 , &rq->das.legacy_deadline); +clear_bit (0 , &rq->__deadline); }static inline bool blk_rq_is_complete (struct request *rq) { -return test_bit (0 , &rq->das.legacy_deadline); +return test_bit (0 , &rq->__deadline); }/*
@@ -316,12 +315,12 @@ static inline void req_set_nomerge(struct request_queue *q, struct request *req)*/ static inline void blk_rq_set_deadline (struct request *rq,unsigned long time) { - rq->das.legacy_deadline = time & ~0x1UL ; + rq->__deadline = time & ~0x1UL ; }static inline unsigned long blk_rq_deadline (struct request *rq) { -return rq->das.legacy_deadline & ~0x1UL ; +return rq->__deadline & ~0x1UL ; }/*
include/linux/blkdev.h +12 -19
@@ -130,14 +130,12 @@ typedef __u32 __bitwise req_flags_t;#define RQF_NOMERGE_FLAGS \ (RQF_STARTED | RQF_SOFTBARRIER | RQF_FLUSH_SEQ | RQF_SPECIAL_PAYLOAD) -union blk_deadline_and_state { +union request_sag {struct { -uint32_t generation:30 ; -uint32_t state:2 ; -uint32_t deadline; +u32 generation :30 ; +u32 state :2 ; }; -unsigned long legacy_deadline; -uint64_t das; +u32 val; };/*
@@ -242,24 +240,19 @@ struct request {unsigned int extra_len;/* length of alignment and padding */ -/* -* ->aborted_gstate is used by the timeout to claim a specific -* recycle instance of this request. See blk_mq_timeout_work(). -*/ -union blk_deadline_and_state aborted_gstate; - -#ifndef CONFIG_ARCH_HAVE_CMPXCHG64 -spinlock_t das_lock; -#endif +/* +* ->aborted_sagis used by the timeout to claim a specific recycle +* instance of this request. See blk_mq_timeout_work(). +*/ +union request_sag sag; +union request_sag aborted_sag;/* * Access through blk_rq_deadline() and blk_rq_set_deadline(), * blk_mark_rq_complete(), blk_clear_rq_complete() and -* blk_rq_is_complete() for legacy queues or blk_mq_rq_state(), -* blk_mq_change_rq_state() and blk_mq_rq_set_deadline() for -* blk-mq queues. +* blk_rq_is_complete() for legacy queues. */ -union blk_deadline_and_state das; +unsigned long __deadline;struct list_head timeout_list;
T24gV2VkLCAyMDE4LTA1LTE2IGF0IDE0OjUxICswMjAwLCBDaHJpc3RvcGggSGVsbHdpZyB3cm90 ZToNCj4gSSd2ZSBiZWVuIGxvb2tpbmcgYXQgdGhpcyBjYXJlZnVsbHksIGFuZCBJIGRvbid0IHRo aW5rIHdlIG5lZWQgY21weGNoZzY0DQo+IGF0IGFsbCwgYW5kIHdlIGRvbid0IG5lZWQgYW55d2hl cmUgbmVhciBhcyBtYW55IGNtcHhjaGcgb3BlcmF0aW9ucyBlaXRoZXIuDQo+IA0KPiBUaGUgb25s eSByZWFzb24gdG8gaW5jbHVkZSB0aGUgZGVhZGxpbmUgaW4gdGhlIGF0b21pYyBvcGVyYXRpb24g aXMgdGhlDQo+IGJsa19hYm9ydF9yZXF1ZXN0IGNhc2UsIGFzIHRoZSBibGtfbXFfYWRkX3RpbWVy IG5ldmVyIG1vZGlmaWVzIHRoZQ0KPiBkZWFkbGluZSBvZiBhIHJlcXVlc3QgdGhhdCBzb21lb25l IGNvdWxkIGJlIHJhY2luZyB3aXRoLiAgU28gaWYgd2UNCj4gaW50cm9kdWNlIGEgbmV3IGFib3J0 ZWQgc3RhdGUgZm9yIHVzZSBieSBibGtfYWJvcnRfcmVxdWVzdCB3ZSBjYW4gbW9kaWZ5DQo+IHRo ZSBkZWFkbGluZSBzZXBhcmF0ZWx5IChhbmQgaW4gZmFjdCBoYXZlIGEgY29tbW9uIGZpZWxkIHdp dGggdGhlIGxlZ2FjeQ0KPiBwYXRoKS4NCg0KVGhlcmUgaXMgYW5vdGhlciByZWFzb24gdGhlIGRl YWRsaW5lIGlzIGluY2x1ZGVkIGluIHRoZSBhdG9taWMgb3BlcmF0aW9uLA0KbmFtZWx5IHRvIGhh bmRsZSByYWNlcyBiZXR3ZWVuIHRoZSBCTEtfRUhfUkVTRVRfVElNRVIgY2FzZSBpbiBibGtfbXFf cnFfdGltZWRfb3V0KCkNCmFuZCBibGtfbXFfY29tcGxldGVfcmVxdWVzdCgpLiBJIGRvbid0IHRo aW5rIHRoYXQgcmFjZSBpcyBhZGRyZXNzZWQgcHJvcGVybHkgYnkNCnlvdXIgcGF0Y2guIEkgd2ls bCBzZWUgd2hhdCBJIGNhbiBkbyB0byBhZGRyZXNzIHRoYXQgcmFjZSB3aXRob3V0IHVzaW5nIDY0 LWJpdA0KYXRvbWljIG9wZXJhdGlvbnMuDQoNCkJhcnQuDQoNCg0KDQo=
Quoted 5 lines · Bart Van Assche
There is another reason the deadline is included in the atomic operation, namely to handle races between the
BLK_EH_RESET_TIMERcase inblk_mq_rq_timed_out()andblk_mq_complete_request(). I don't think that race is addressed properly by your patch. I will see what I can do to address that race without using 64-bit atomic operations.
I might be missing something here, so please help me understand what is missing.
If we restart the timer in blk_mq_rq_timed_out we also bump the generation at the same time as we reset the deadline in your old patch. With this patch we only bump the generation, but that should be enough to address the rest, or not?
T24gV2VkLCAyMDE4LTA1LTE2IGF0IDE4OjI0ICswMjAwLCBoY2hAbHN0LmRlIHdyb3RlOg0KPiBP biBXZWQsIE1heSAxNiwgMjAxOCBhdCAwNDoxNzo0MlBNICswMDAwLCBCYXJ0IFZhbiBBc3NjaGUg d3JvdGU6DQo+ID4gVGhlcmUgaXMgYW5vdGhlciByZWFzb24gdGhlIGRlYWRsaW5lIGlzIGluY2x1 ZGVkIGluIHRoZSBhdG9taWMgb3BlcmF0aW9uLA0KPiA+IG5hbWVseSB0byBoYW5kbGUgcmFjZXMg YmV0d2VlbiB0aGUgQkxLX0VIX1JFU0VUX1RJTUVSIGNhc2UgaW4gYmxrX21xX3JxX3RpbWVkX291 dCgpDQo+ID4gYW5kIGJsa19tcV9jb21wbGV0ZV9yZXF1ZXN0KCkuIEkgZG9uJ3QgdGhpbmsgdGhh dCByYWNlIGlzIGFkZHJlc3NlZCBwcm9wZXJseSBieQ0KPiA+IHlvdXIgcGF0Y2guIEkgd2lsbCBz ZWUgd2hhdCBJIGNhbiBkbyB0byBhZGRyZXNzIHRoYXQgcmFjZSB3aXRob3V0IHVzaW5nIDY0LWJp dA0KPiA+IGF0b21pYyBvcGVyYXRpb25zLg0KPiANCj4gSSBtaWdodCBiZSBtaXNzaW5nIHNvbWV0 aGluZyBoZXJlLCBzbyBwbGVhc2UgaGVscCBtZSB1bmRlcnN0YW5kDQo+IHdoYXQgaXMgbWlzc2lu Zy4NCj4gDQo+IElmIHdlIHJlc3RhcnQgdGhlIHRpbWVyIGluIGJsa19tcV9ycV90aW1lZF9vdXQg d2UgYWxzbyBidW1wIHRoZQ0KPiBnZW5lcmF0aW9uIGF0IHRoZSBzYW1lIHRpbWUgYXMgd2UgcmVz ZXQgdGhlIGRlYWRsaW5lIGluIHlvdXIgb2xkDQo+IHBhdGNoLiAgV2l0aCB0aGlzIHBhdGNoIHdl IG9ubHkgYnVtcCB0aGUgZ2VuZXJhdGlvbiwgYnV0IHRoYXQgc2hvdWxkDQo+IGJlIGVub3VnaCB0 byBhZGRyZXNzIHRoZSByZXN0LCBvciBub3Q/DQoNCkhlbGxvIENocmlzdG9waCwNCg0KSSB0aGlu ayB5b3VyIHBhdGNoIGNoYW5nZXMgdGhlIG9yZGVyIG9mIGNoYW5naW5nIHRoZSByZXF1ZXN0IHN0 YXRlIGFuZA0KY2FsbGluZyBtb2RfdGltZXIoKS4gSW4gbXkgcGF0Y2ggdGhlIHJlcXVlc3Qgc3Rh dGUgYW5kIHRoZSBkZWFkbGluZSBhcmUNCnVwZGF0ZWQgZmlyc3QgYW5kIG1vZF90aW1lcigpIGlz IGNhbGxlZCBhZnRlcndhcmRzLiBJIHRoaW5rIHlvdXIgcGF0Y2gNCmNoYW5nZXMgdGhlIG9yZGVy IG9mIHRoZXNlIG9wZXJhdGlvbnMgaW50byB0aGUgZm9sbG93aW5nOg0KKDEpIF9fYmxrX21xX3N0 YXJ0X3JlcXVlc3QoKSBzZXRzIHRoZSByZXF1ZXN0IGRlYWRsaW5lLg0KKDIpIF9fYmxrX21xX3N0 YXJ0X3JlcXVlc3QoKSBjYWxscyBfX2Jsa19hZGRfdGltZXIoKSB3aGljaCBpbiB0dXJuIGNhbGxz DQogICAgbW9kX3RpbWVyKCkuDQooMykgX19ibGtfbXFfc3RhcnRfcmVxdWVzdCgpIGNoYW5nZXMg dGhlIHJlcXVlc3Qgc3RhdGUgaW50byBNUV9SUV9JTl9GTElHSFQuDQoNCkluIHRoZSB1bmxpa2Vs eSBldmVudCBvZiBhIHNpZ25pZmljYW50IGRlbGF5IGJldHdlZW4gKDIpIGFuZCAoMykgaXQgY2Fu DQpoYXBwZW4gdGhhdCB0aGUgdGltZXIgZmlyZXMgYW5kIGV4YW1pbmVzIGFuZCBpZ25vcmVzIHRo ZSByZXF1ZXN0IGJlY2F1c2UNCml0cyBzdGF0ZSBkaWZmZXJzIGZyb20gTVFfUlFfSU5fRkxJR0hU LiBJZiB0aGUgcmVxdWVzdCBmb3Igd2hpY2ggdGhpcw0KaGFwcGVuZWQgdGltZXMgb3V0IGl0cyB0 aW1lb3V0IHdpbGwgb25seSBiZSBoYW5kbGVkIHRoZSBuZXh0IHRpbWUNCmJsa19tcV90aW1lb3V0 X3dvcmsoKSBpcyBjYWxsZWQuIElzIHRoaXMgdGhlIGJlaGF2aW9yIHlvdSBpbnRlbmRlZD8NCg0K VGhhbmtzLA0KDQpCYXJ0Lg0K
Quoted 6 lines · Bart Van Assche
I think your patch changes the order of changing the request state and calling
mod_timer(). In my patch the request state and the deadline are updated first andmod_timer()is called afterwards. I think your patch changes the order of these operations into the following:
(1)__blk_mq_start_request()sets the request deadline.
(2)__blk_mq_start_request()calls__blk_add_timer()which in turn calls
Quoted 8 lines
mod_timer().(3)
__blk_mq_start_request()changes the request state intoMQ_RQ_IN_FLIGHT.In the unlikely event of a significant delay between (2) and (3) it can happen that the timer fires and examines and ignores the request because its state differs from
MQ_RQ_IN_FLIGHT. If the request for which this happened times out its timeout will only be handled the next timeblk_mq_timeout_work()is called. Is this the behavior you intended?
We can move the timer manipulation after the change easily I think. It would make sense to add comments explaining the ordering.
T24gV2VkLCAyMDE4LTA1LTE2IGF0IDE5OjMxICswMjAwLCBoY2hAbHN0LmRlIHdyb3RlOg0KPiBP biBXZWQsIE1heSAxNiwgMjAxOCBhdCAwNDo0Nzo1NFBNICswMDAwLCBCYXJ0IFZhbiBBc3NjaGUg d3JvdGU6DQo+ID4gSSB0aGluayB5b3VyIHBhdGNoIGNoYW5nZXMgdGhlIG9yZGVyIG9mIGNoYW5n aW5nIHRoZSByZXF1ZXN0IHN0YXRlIGFuZA0KPiA+IGNhbGxpbmcgbW9kX3RpbWVyKCkuIEluIG15 IHBhdGNoIHRoZSByZXF1ZXN0IHN0YXRlIGFuZCB0aGUgZGVhZGxpbmUgYXJlDQo+ID4gdXBkYXRl ZCBmaXJzdCBhbmQgbW9kX3RpbWVyKCkgaXMgY2FsbGVkIGFmdGVyd2FyZHMuIEkgdGhpbmsgeW91 ciBwYXRjaA0KPiA+IGNoYW5nZXMgdGhlIG9yZGVyIG9mIHRoZXNlIG9wZXJhdGlvbnMgaW50byB0 aGUgZm9sbG93aW5nOg0KPiA+ICgxKSBfX2Jsa19tcV9zdGFydF9yZXF1ZXN0KCkgc2V0cyB0aGUg cmVxdWVzdCBkZWFkbGluZS4NCj4gPiAoMikgX19ibGtfbXFfc3RhcnRfcmVxdWVzdCgpIGNhbGxz IF9fYmxrX2FkZF90aW1lcigpIHdoaWNoIGluIHR1cm4gY2FsbHMNCj4gPiAgICAgbW9kX3RpbWVy KCkuDQo+ID4gKDMpIF9fYmxrX21xX3N0YXJ0X3JlcXVlc3QoKSBjaGFuZ2VzIHRoZSByZXF1ZXN0 IHN0YXRlIGludG8gTVFfUlFfSU5fRkxJR0hULg0KPiA+IA0KPiA+IEluIHRoZSB1bmxpa2VseSBl dmVudCBvZiBhIHNpZ25pZmljYW50IGRlbGF5IGJldHdlZW4gKDIpIGFuZCAoMykgaXQgY2FuDQo+ ID4gaGFwcGVuIHRoYXQgdGhlIHRpbWVyIGZpcmVzIGFuZCBleGFtaW5lcyBhbmQgaWdub3JlcyB0 aGUgcmVxdWVzdCBiZWNhdXNlDQo+ID4gaXRzIHN0YXRlIGRpZmZlcnMgZnJvbSBNUV9SUV9JTl9G TElHSFQuIElmIHRoZSByZXF1ZXN0IGZvciB3aGljaCB0aGlzDQo+ID4gaGFwcGVuZWQgdGltZXMg b3V0IGl0cyB0aW1lb3V0IHdpbGwgb25seSBiZSBoYW5kbGVkIHRoZSBuZXh0IHRpbWUNCj4gPiBi bGtfbXFfdGltZW91dF93b3JrKCkgaXMgY2FsbGVkLiBJcyB0aGlzIHRoZSBiZWhhdmlvciB5b3Ug aW50ZW5kZWQ/DQo+IA0KPiBXZSBjYW4gbW92ZSB0aGUgdGltZXIgbWFuaXB1bGF0aW9uIGFmdGVy IHRoZSBjaGFuZ2UgZWFzaWx5IEkgdGhpbmsuDQo+IEl0IHdvdWxkIG1ha2Ugc2Vuc2UgdG8gYWRk IGNvbW1lbnRzIGV4cGxhaW5pbmcgdGhlIG9yZGVyaW5nLg0KDQpIZWxsbyBDaHJpc3RvcGgsDQoN CkknbSBhZnJhaWQgdGhhdCBjb3VsZCBsZWFkIHRvIG1vZF90aW1lcigpIGJlaW5nIGNhbGxlZCBp biBhbm90aGVyIG9yZGVyIHRoYW4NCmludGVuZGVkLiBJZiBlLmcuIHRoZSBjb2RlIHRoYXQgaGFu ZGxlcyBCTEtfRUhfUkVTRVRfVElNRVIgY2hhbmdlcyB0aGUgcmVxdWVzdA0Kc3RhdGUgZmlyc3Qg dG8gaW4tZmxpZ2h0IGFuZCBuZXh0IGNhbGxzIG1vZF90aW1lcigpIHRoZW4gaXQgY2FuIGhhcHBl biB0aGF0DQphbm90aGVyIGNvbnRleHQgY29tcGxldGVzIGFuZCByZXN0YXJ0cyB0aGUgcmVxdWVz dCwgcmVzdWx0aW5nIGluIGEgY29uY3VycmVudA0KbW9kX3RpbWVyKCkgY2FsbC4gSSdtIG5vdCBz dXJlIHJlb3JkZXJpbmcgb2YgdGhlIG1vZF90aW1lcigpIGNhbGxzIHdvdWxkIHJlc3VsdA0KaW4g Y29ycmVjdCBiZWhhdmlvci4NCg0KQmFydC4NCg0KDQo=
Re: [PATCH v10 1/2] arch/*: Add CONFIG_ARCH_HAVE_CMPXCHG64
In reply to Bart Van AsscheQuoted 44 lines · On Tue, 15 May 2018 15:51:20 PDT (-0700), [email protected] wrote:
The next patch in this series introduces a call to
cmpxchg64()in the block layer core for those architectures on which this functionality is available. Make it possible to test whethercmpxchg64()is available by introducingCONFIG_ARCH_HAVE_CMPXCHG64.Signed-off-by Bart Van Assche <[email protected]>Cc Catalin Marinas <[email protected]>Cc Will Deacon <[email protected]>Cc Tony Luck <[email protected]>Cc Fenghua Yu <[email protected]>Cc Geert Uytterhoeven <[email protected]>Cc "James E.J. Bottomley" <[email protected]>Cc Helge Deller <[email protected]>Cc Benjamin Herrenschmidt <[email protected]>Cc Paul Mackerras <[email protected]>Cc Michael Ellerman <[email protected]>Cc Martin Schwidefsky <[email protected]>Cc Heiko Carstens <[email protected]>Cc David S. Miller <[email protected]>Cc Thomas Gleixner <[email protected]>Cc Ingo Molnar <[email protected]>Cc H. Peter Anvin <[email protected]>Cc Chris Zankel <[email protected]>Cc Max Filippov <[email protected]>Cc Arnd Bergmann <[email protected]>Cc Jonathan Corbet <[email protected]>--- .../features/locking/cmpxchg64/arch-support.txt | 33 ++++++++++++++++++++++ arch/Kconfig | 3 ++ arch/alpha/Kconfig | 1 + arch/arm/Kconfig | 1 + arch/arm64/Kconfig | 1 + arch/ia64/Kconfig | 1 + arch/m68k/Kconfig | 1 + arch/mips/Kconfig | 1 + arch/parisc/Kconfig | 1 + arch/powerpc/Kconfig | 1 + arch/riscv/Kconfig | 1 + arch/s390/Kconfig | 1 + arch/sparc/Kconfig | 1 + arch/x86/Kconfig | 1 + arch/xtensa/Kconfig | 1 + 15 files changed, 49 insertions(+) create mode 100644 Documentation/features/locking/cmpxchg64/arch-support.txt
[...]
arch/riscv/Kconfig config RISCV · line 14
Quoted 10 lines
arch/riscv/Kconfig +1
-0@@ -8,6 +8,7 @@ config RISCV select OF select OF_EARLY_FLATTREE select OF_IRQ + select ARCH_HAVE_CMPXCHG64 select ARCH_WANT_FRAME_POINTERS select CLONE_BACKWARDS select COMMON_CLK
If I understand correctly, we should only have ARCH_HAVE_CMPXCHG64 on 64-bit RISC-V systems so this should look something like
select ARCH_HAVE_CMPXCHG64 if 64BIT
Of course, the RV32I port is broken right now so it's not a big deal, but we're working through making it less broken...