Compare
bcec7fc2e224088daf94448d663b02e0d0b9c717..7cbaa0f4579f48e92639c6abb761fdef8fbade47
entry: Account the deferred hrtimer rearm as hardirq context for lockdep
On a desktop debug kernel (PROVE_LOCKING, KASAN, LOCKDEP_CHAINS_BITS=19)
lockdep switches itself off after about two days of uptime with
"BUG: MAX_LOCKDEP_CHAIN_HLOCKS too low!", and locking is not validated
until the next reboot. In the last such boot the pool ran out after 46.6
hours, and a fifth of it, 533509 of 2621431 chain hlocks in 63838 of
344717 chains, had been created by the deferred hrtimer rearm on return
from interrupt.
Make lockdep account that rearm as part of the timer interrupt it
belongs to.
Commit 15dd3a948855
("hrtimer: Push reprogramming timers into the interrupt return path")
moved the reprogramming of the clock event device out of the timer
interrupt into the interrupt return path. On return to kernel mode
irqentry_exit_to_kernel_mode_after_preempt() performs it after
irq_exit_rcu() has already left lockdep's hardirq context. lockdep
therefore records hrtimer_bases.lock and the timekeeper sequence count
as taken by the interrupted context, on top of the locks that context
holds, and every distinct held-lock stack an interrupt hits adds two
lock chains. When the rearm runs from irq_enter_rcu() or
__irq_exit_rcu() it is still inside lockdep's hardirq context, and there
the same acquisitions reuse one pair of chains.
The dependencies recorded on the return path are "lock held with
interrupts enabled -> hrtimer_bases.lock". Such a lock is hardirq-unsafe
and hrtimer_bases.lock is hardirq-safe, so a path in the reverse
direction is already reported by the irq-safety checks without these
edges.
Re-enter lockdep's hardirq context around the rearm on the kernel return
path. The return to user mode path holds no locks and is left alone, as
is the rearm in __schedule(), which runs under the runqueue lock.
With the same kernel tree, configuration and workload, one hour of
uptime including a full kernel build, the chains of this shape, with
hrtimer_bases.lock and optionally the timekeeper sequence count on top
of a held-lock stack outside the scheduler, go from 13266 (96187 chain
hlocks, 15.9% of those in use) to 4. Those 4 come from clock_was_set(),
which takes cpus_read_lock() and each CPU's hrtimer_bases.lock and reads
the clock under it.
Fixes: 15dd3a948855 ("hrtimer: Push reprogramming timers into the interrupt return path")
Signed-off-by: Mikhail Gavrilov <mikhail.v.gavrilov@gmail.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://patch.msgid.link/20261013071318.33300-1-mikhail.v.gavrilov@gmail.com
Mikhail Gavrilov <mikhail.v.gavrilov@gmail.com> · 2026-10-13 07:13 UTC · committed by Peter Zijlstra
21 files changed,
+79
−83
- fs/9p/v9fs.h
- fs/9p/vfs_super.c
- fs/afs/internal.h
- fs/afs/super.c
- fs/ext4/ext4.h
- fs/ext4/extents-test.c
- fs/ext4/extents.c
- fs/ext4/extents_status.c
- fs/ext4/extents_status.h
- fs/ext4/super.c
- fs/ocfs2/dlm/dlmcommon.h
- fs/ocfs2/dlm/dlmdebug.c
- fs/ocfs2/dlm/dlmrecovery.c
- fs/pipe.c
- include/linux/futex.h
- include/linux/futex_types.h
- include/linux/irq-entry-common.h
- include/linux/sched/signal.h
- kernel/futex/core.c
- kernel/watch_queue.c
- samples/pidfd/Makefile
modified fs/9p/v9fs.h
| @@ -137,7 +137,6 @@ struct v9fs_session_info { | |||
| 137 | 137 | struct list_head slist; /* list of sessions registered with v9fs */ | |
| 138 | 138 | struct rw_semaphore rename_sem; | |
| 139 | 139 | long session_lock_timeout; /* retry interval for blocking locks */ | |
| 140 | - | struct rcu_head rcu; /* v9fs_vfs_get_link_dotl() reads ->cache in rcu pathwalk */ | |
| 141 | 140 | }; | |
| 142 | 141 | ||
| 143 | 142 | #define NDENTRY_TIMEOUT_NEVER (-1U) | |
modified fs/9p/vfs_super.c
| @@ -173,8 +173,8 @@ static void v9fs_kill_super(struct super_block *s) | |||
| 173 | 173 | ||
| 174 | 174 | v9fs_session_cancel(v9ses); | |
| 175 | 175 | v9fs_session_close(v9ses); | |
| 176 | - | /* v9fs_vfs_get_link_dotl() may still read ->cache in rcu pathwalk */ | |
| 177 | - | kfree_rcu(v9ses, rcu); | |
| 176 | + | kfree(v9ses); | |
| 177 | + | s->s_fs_info = NULL; | |
| 178 | 178 | p9_debug(P9_DEBUG_VFS, "exiting kill_super\n"); | |
| 179 | 179 | } | |
| 180 | 180 | ||
modified fs/afs/internal.h
| @@ -251,8 +251,6 @@ struct afs_super_info { | |||
| 251 | 251 | struct afs_volume *volume; /* volume record */ | |
| 252 | 252 | enum afs_flock_mode flock_mode:8; /* File locking emulation mode */ | |
| 253 | 253 | bool dyn_root; /* True if dynamic root */ | |
| 254 | - | /* afs_atcell_get_link() reads ->net_ns in rcu pathwalk */ | |
| 255 | - | struct rcu_head rcu; | |
| 256 | 254 | }; | |
| 257 | 255 | ||
| 258 | 256 | static inline struct afs_super_info *AFS_FS_S(struct super_block *sb) | |
modified fs/afs/super.c
| @@ -523,7 +523,7 @@ static void afs_destroy_sbi(struct afs_super_info *as) | |||
| 523 | 523 | afs_put_volume(as->volume, afs_volume_trace_put_destroy_sbi); | |
| 524 | 524 | afs_unuse_cell(as->cell, afs_cell_trace_unuse_sbi); | |
| 525 | 525 | put_net(as->net_ns); | |
| 526 | - | kfree_rcu(as, rcu); | |
| 526 | + | kfree(as); | |
| 527 | 527 | } | |
| 528 | 528 | } | |
| 529 | 529 | ||
modified fs/ext4/ext4.h
| @@ -1774,8 +1774,6 @@ struct ext4_sb_info { | |||
| 1774 | 1774 | struct list_head s_es_list; /* List of inodes with reclaimable extents */ | |
| 1775 | 1775 | long s_es_nr_inode; | |
| 1776 | 1776 | struct ext4_es_stats s_es_stats; | |
| 1777 | - | /* ext4_get_link() reads the sbi in rcu pathwalk */ | |
| 1778 | - | struct rcu_head s_rcu; | |
| 1779 | 1777 | struct mb_cache *s_ea_block_cache; | |
| 1780 | 1778 | struct mb_cache *s_ea_inode_cache; | |
| 1781 | 1779 | ||
modified fs/ext4/extents-test.c
| @@ -151,7 +151,6 @@ static void extents_kunit_exit(struct kunit *test) | |||
| 151 | 151 | ||
| 152 | 152 | sbi = k_ctx.k_ei->vfs_inode.i_sb->s_fs_info; | |
| 153 | 153 | ext4_es_unregister_shrinker(sbi); | |
| 154 | - | ext4_es_destroy_stats(sbi); | |
| 155 | 154 | deactivate_super(sbi->s_sb); | |
| 156 | 155 | kfree(sbi); | |
| 157 | 156 | kfree(k_ctx.k_ei); | |
| @@ -341,7 +340,6 @@ out: | |||
| 341 | 340 | k_ctx.k_data = NULL; | |
| 342 | 341 | ||
| 343 | 342 | ext4_es_unregister_shrinker(sbi); | |
| 344 | - | ext4_es_destroy_stats(sbi); | |
| 345 | 343 | out_deactivate: | |
| 346 | 344 | deactivate_locked_super(sb); | |
| 347 | 345 | kfree(sbi); | |
modified fs/ext4/extents.c
| @@ -6409,7 +6409,6 @@ EXPORT_SYMBOL_FOR_EXT4_TEST(__ext4_ext_dirty); | |||
| 6409 | 6409 | EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_ext_zeroout); | |
| 6410 | 6410 | EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_es_register_shrinker); | |
| 6411 | 6411 | EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_es_unregister_shrinker); | |
| 6412 | - | EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_es_destroy_stats); | |
| 6413 | 6412 | EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_map_create_blocks); | |
| 6414 | 6413 | EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_es_init_tree); | |
| 6415 | 6414 | EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_es_lookup_extent); | |
modified fs/ext4/extents_status.c
| @@ -1881,17 +1881,12 @@ err1: | |||
| 1881 | 1881 | } | |
| 1882 | 1882 | ||
| 1883 | 1883 | void ext4_es_unregister_shrinker(struct ext4_sb_info *sbi) | |
| 1884 | - | { | |
| 1885 | - | shrinker_free(sbi->s_es_shrinker); | |
| 1886 | - | } | |
| 1887 | - | ||
| 1888 | - | /* ext4_get_link() bumps the hit and miss counters in rcu pathwalk */ | |
| 1889 | - | void ext4_es_destroy_stats(struct ext4_sb_info *sbi) | |
| 1890 | 1884 | { | |
| 1891 | 1885 | percpu_counter_destroy(&sbi->s_es_stats.es_stats_cache_hits); | |
| 1892 | 1886 | percpu_counter_destroy(&sbi->s_es_stats.es_stats_cache_misses); | |
| 1893 | 1887 | percpu_counter_destroy(&sbi->s_es_stats.es_stats_all_cnt); | |
| 1894 | 1888 | percpu_counter_destroy(&sbi->s_es_stats.es_stats_shk_cnt); | |
| 1889 | + | shrinker_free(sbi->s_es_shrinker); | |
| 1895 | 1890 | } | |
| 1896 | 1891 | ||
| 1897 | 1892 | /* | |
modified fs/ext4/extents_status.h
| @@ -238,7 +238,6 @@ static inline void ext4_es_store_pblock_status(struct extent_status *es, | |||
| 238 | 238 | ||
| 239 | 239 | extern int ext4_es_register_shrinker(struct ext4_sb_info *sbi); | |
| 240 | 240 | extern void ext4_es_unregister_shrinker(struct ext4_sb_info *sbi); | |
| 241 | - | extern void ext4_es_destroy_stats(struct ext4_sb_info *sbi); | |
| 242 | 241 | ||
| 243 | 242 | extern int ext4_seq_es_shrinker_info_show(struct seq_file *seq, void *v); | |
| 244 | 243 | ||
modified fs/ext4/super.c
| @@ -1279,14 +1279,6 @@ static void ext4_flex_groups_free(struct ext4_sb_info *sbi) | |||
| 1279 | 1279 | } | |
| 1280 | 1280 | } | |
| 1281 | 1281 | ||
| 1282 | - | static void ext4_put_sbi_rcu(struct rcu_head *head) | |
| 1283 | - | { | |
| 1284 | - | struct ext4_sb_info *sbi = container_of(head, struct ext4_sb_info, s_rcu); | |
| 1285 | - | ||
| 1286 | - | ext4_es_destroy_stats(sbi); | |
| 1287 | - | kfree(sbi); | |
| 1288 | - | } | |
| 1289 | - | ||
| 1290 | 1282 | static void ext4_put_super(struct super_block *sb) | |
| 1291 | 1283 | { | |
| 1292 | 1284 | struct ext4_sb_info *sbi = EXT4_SB(sb); | |
| @@ -1382,6 +1374,7 @@ static void ext4_put_super(struct super_block *sb) | |||
| 1382 | 1374 | ext4_stop_mmpd(sbi); | |
| 1383 | 1375 | ||
| 1384 | 1376 | brelse(sbi->s_sbh); | |
| 1377 | + | sb->s_fs_info = NULL; | |
| 1385 | 1378 | /* | |
| 1386 | 1379 | * Now that we are completely done shutting down the | |
| 1387 | 1380 | * superblock, we need to actually destroy the kobject. | |
| @@ -1394,8 +1387,7 @@ static void ext4_put_super(struct super_block *sb) | |||
| 1394 | 1387 | #if IS_ENABLED(CONFIG_UNICODE) | |
| 1395 | 1388 | utf8_unload(sb->s_encoding); | |
| 1396 | 1389 | #endif | |
| 1397 | - | /* ext4_get_link() reads the sbi and the counters in rcu pathwalk */ | |
| 1398 | - | call_rcu(&sbi->s_rcu, ext4_put_sbi_rcu); | |
| 1390 | + | kfree(sbi); | |
| 1399 | 1391 | } | |
| 1400 | 1392 | ||
| 1401 | 1393 | static struct kmem_cache *ext4_inode_cachep; | |
| @@ -5814,7 +5806,6 @@ failed_mount3a: | |||
| 5814 | 5806 | /* Drain deferred EA inode iputs from journal replay */ | |
| 5815 | 5807 | flush_delayed_work(&sbi->s_ea_inode_work); | |
| 5816 | 5808 | ext4_es_unregister_shrinker(sbi); | |
| 5817 | - | ext4_es_destroy_stats(sbi); | |
| 5818 | 5809 | failed_mount3: | |
| 5819 | 5810 | /* flush s_sb_upd_work before sbi destroy */ | |
| 5820 | 5811 | flush_work(&sbi->s_sb_upd_work); | |
modified fs/ocfs2/dlm/dlmcommon.h
| @@ -435,8 +435,6 @@ enum { | |||
| 435 | 435 | DLM_DEREF_LOCKRES_DONE = 522, | |
| 436 | 436 | }; | |
| 437 | 437 | ||
| 438 | - | extern spinlock_t dlm_reco_state_lock; | |
| 439 | - | ||
| 440 | 438 | struct dlm_reco_node_data | |
| 441 | 439 | { | |
| 442 | 440 | int state; | |
modified fs/ocfs2/dlm/dlmdebug.c
| @@ -736,11 +736,8 @@ static int debug_state_print(struct dlm_ctxt *dlm, char *buf, int len) | |||
| 736 | 736 | buf + out, len - out); | |
| 737 | 737 | out += scnprintf(buf + out, len - out, "\n"); | |
| 738 | 738 | ||
| 739 | - | spin_unlock(&dlm->spinlock); | |
| 740 | - | ||
| 741 | 739 | /* Recovery Node State: */ | |
| 742 | 740 | out += scnprintf(buf + out, len - out, "Recovery Node State:\n"); | |
| 743 | - | spin_lock(&dlm_reco_state_lock); | |
| 744 | 741 | list_for_each_entry(node, &dlm->reco.node_data, list) { | |
| 745 | 742 | switch (node->state) { | |
| 746 | 743 | case DLM_RECO_NODE_DATA_INIT: | |
| @@ -772,7 +769,7 @@ static int debug_state_print(struct dlm_ctxt *dlm, char *buf, int len) | |||
| 772 | 769 | node->node_num, state); | |
| 773 | 770 | } | |
| 774 | 771 | ||
| 775 | - | spin_unlock(&dlm_reco_state_lock); | |
| 772 | + | spin_unlock(&dlm->spinlock); | |
| 776 | 773 | ||
| 777 | 774 | return out; | |
| 778 | 775 | } | |
modified fs/ocfs2/dlm/dlmrecovery.c
| @@ -80,7 +80,7 @@ static int dlm_lockres_master_requery(struct dlm_ctxt *dlm, | |||
| 80 | 80 | ||
| 81 | 81 | static u64 dlm_get_next_mig_cookie(void); | |
| 82 | 82 | ||
| 83 | - | DEFINE_SPINLOCK(dlm_reco_state_lock); | |
| 83 | + | static DEFINE_SPINLOCK(dlm_reco_state_lock); | |
| 84 | 84 | static DEFINE_SPINLOCK(dlm_mig_cookie_lock); | |
| 85 | 85 | static u64 dlm_mig_cookie = 1; | |
| 86 | 86 | ||
modified fs/pipe.c
| @@ -838,11 +838,9 @@ pipe_fasync(int fd, struct file *filp, int on) | |||
| 838 | 838 | if (filp->f_mode & FMODE_READ) | |
| 839 | 839 | retval = fasync_helper(fd, filp, on, &pipe->fasync_readers); | |
| 840 | 840 | if ((filp->f_mode & FMODE_WRITE) && retval >= 0) { | |
| 841 | - | int read_ret = retval; | |
| 842 | - | ||
| 843 | 841 | retval = fasync_helper(fd, filp, on, &pipe->fasync_writers); | |
| 844 | - | /* Undo only a reader entry added by this call. */ | |
| 845 | - | if (retval < 0 && read_ret > 0) | |
| 842 | + | if (retval < 0 && (filp->f_mode & FMODE_READ)) | |
| 843 | + | /* this can happen only if on == T */ | |
| 846 | 844 | fasync_helper(-1, filp, 0, &pipe->fasync_readers); | |
| 847 | 845 | } | |
| 848 | 846 | mutex_unlock(&pipe->mutex); | |
modified include/linux/futex.h
| @@ -23,28 +23,32 @@ struct task_struct; | |||
| 23 | 23 | * 01 : Shared futex (PTHREAD_PROCESS_SHARED) | |
| 24 | 24 | * mapped on a file (reference on the underlying inode) | |
| 25 | 25 | * 10 : Shared futex (PTHREAD_PROCESS_SHARED) | |
| 26 | - | * (but private mapping on an mm, and reference taken on it) | |
| 26 | + | * (but private mapping on an mm) | |
| 27 | 27 | */ | |
| 28 | 28 | ||
| 29 | - | #define FUT_OFF_INODE 1 /* We set bit 0 if key has a reference on inode */ | |
| 30 | - | #define FUT_OFF_MMSHARED 2 /* We set bit 1 if key has a reference on mm */ | |
| 29 | + | #define FUT_OFF_INODE 1 /* We set bit 0 if shared key identifies an inode */ | |
| 30 | + | #define FUT_OFF_MMSHARED 2 /* We set bit 1 if shared key identifies an mm */ | |
| 31 | 31 | ||
| 32 | 32 | union futex_key { | |
| 33 | + | /* For FUT_OFF_INODE */ | |
| 33 | 34 | struct { | |
| 34 | 35 | u64 i_seq; | |
| 35 | 36 | unsigned long pgoff; | |
| 36 | 37 | unsigned int offset; | |
| 37 | 38 | /* unsigned int node; */ | |
| 38 | 39 | } shared; | |
| 40 | + | ||
| 41 | + | /* For FUT_OFF_MMSHARED or private */ | |
| 39 | 42 | struct { | |
| 40 | 43 | union { | |
| 41 | - | struct mm_struct *mm; | |
| 42 | - | u64 __tmp; | |
| 44 | + | struct mm_struct *mm; /* for private */ | |
| 45 | + | u64 mm_seq; /* for FUT_OFF_MMSHARED */ | |
| 43 | 46 | }; | |
| 44 | 47 | unsigned long address; | |
| 45 | 48 | unsigned int offset; | |
| 46 | 49 | /* unsigned int node; */ | |
| 47 | 50 | } private; | |
| 51 | + | ||
| 48 | 52 | struct { | |
| 49 | 53 | u64 ptr; | |
| 50 | 54 | unsigned long word; | |
| @@ -152,11 +156,10 @@ static inline void futex_set_vdso_cs_range(struct futex_mm_data *fd, unsigned in | |||
| 152 | 156 | static inline void futex_fixup_robust_unlock(struct pt_regs *regs) { } | |
| 153 | 157 | #endif /* !CONFIG_FUTEX_ROBUST_UNLOCK */ | |
| 154 | 158 | ||
| 155 | - | ||
| 156 | - | #if defined(CONFIG_FUTEX_PRIVATE_HASH) || defined(CONFIG_FUTEX_ROBUST_UNLOCK) | |
| 159 | + | #ifdef CONFIG_FUTEX | |
| 157 | 160 | void futex_mm_init(struct mm_struct *mm); | |
| 158 | 161 | #else | |
| 159 | 162 | static inline void futex_mm_init(struct mm_struct *mm) { } | |
| 160 | - | #endif | |
| 163 | + | #endif /* !CONFIG_FUTEX */ | |
| 161 | 164 | ||
| 162 | 165 | #endif /* _LINUX_FUTEX_H */ | |
modified include/linux/futex_types.h
| @@ -85,10 +85,12 @@ struct futex_unlock_cs_ranges { }; | |||
| 85 | 85 | * struct futex_mm_data - Futex related per MM data | |
| 86 | 86 | * @phash: Futex private hash related data | |
| 87 | 87 | * @unlock: Futex unlock VDSO critical sections | |
| 88 | + | * @unique_id: Unique ID of the MM, for FUT_OFF_MMSHARED futexes | |
| 88 | 89 | */ | |
| 89 | 90 | struct futex_mm_data { | |
| 90 | 91 | struct futex_mm_phash phash; | |
| 91 | 92 | struct futex_unlock_cs_ranges unlock; | |
| 93 | + | atomic64_t unique_id; | |
| 92 | 94 | }; | |
| 93 | 95 | #else /* CONFIG_FUTEX */ | |
| 94 | 96 | struct futex_sched_data { }; | |
modified include/linux/irq-entry-common.h
| @@ -468,6 +468,25 @@ static inline void irqentry_exit_to_kernel_mode_preempt(struct pt_regs *regs, | |||
| 468 | 468 | irqentry_exit_cond_resched(); | |
| 469 | 469 | } | |
| 470 | 470 | ||
| 471 | + | /* | |
| 472 | + | * The deferred hrtimer rearm is the tail of the timer interrupt, moved to the | |
| 473 | + | * interrupt return path so that it runs after a possible reschedule. By now | |
| 474 | + | * irq_exit_rcu() has left lockdep's hardirq context. Re-enter it for the | |
| 475 | + | * rearm, so that the hrtimer base lock and the timekeeping sequence count are | |
| 476 | + | * not chained onto the locks held by the interrupted context, which would add | |
| 477 | + | * new lock chains for every lock stack an interrupt hits. | |
| 478 | + | * | |
| 479 | + | * The rearm on return to user mode needs no such annotation: no locks are | |
| 480 | + | * held there, so it uses the same lock chains as the rearm in hardirq | |
| 481 | + | * context. | |
| 482 | + | */ | |
| 483 | + | static __always_inline void irqentry_hrtimer_rearm_deferred(void) | |
| 484 | + | { | |
| 485 | + | lockdep_hardirq_enter(); | |
| 486 | + | hrtimer_rearm_deferred(); | |
| 487 | + | lockdep_hardirq_exit(); | |
| 488 | + | } | |
| 489 | + | ||
| 471 | 490 | /** | |
| 472 | 491 | * irqentry_exit_to_kernel_mode_after_preempt - Establish trace, lockdep and RCU state | |
| 473 | 492 | * @regs: Pointer to current's pt_regs | |
| @@ -491,7 +510,7 @@ irqentry_exit_to_kernel_mode_after_preempt(struct pt_regs *regs, irqentry_state_ | |||
| 491 | 510 | */ | |
| 492 | 511 | if (state.exit_rcu) { | |
| 493 | 512 | instrumentation_begin(); | |
| 494 | - | hrtimer_rearm_deferred(); | |
| 513 | + | irqentry_hrtimer_rearm_deferred(); | |
| 495 | 514 | /* Tell the tracer that IRET will enable interrupts */ | |
| 496 | 515 | trace_hardirqs_on_prepare(); | |
| 497 | 516 | lockdep_hardirqs_on_prepare(); | |
| @@ -502,7 +521,7 @@ irqentry_exit_to_kernel_mode_after_preempt(struct pt_regs *regs, irqentry_state_ | |||
| 502 | 521 | } | |
| 503 | 522 | ||
| 504 | 523 | instrumentation_begin(); | |
| 505 | - | hrtimer_rearm_deferred(); | |
| 524 | + | irqentry_hrtimer_rearm_deferred(); | |
| 506 | 525 | /* Covers both tracing and lockdep */ | |
| 507 | 526 | trace_hardirqs_on(); | |
| 508 | 527 | instrumentation_end(); | |
modified include/linux/sched/signal.h
| @@ -130,8 +130,8 @@ struct signal_struct { | |||
| 130 | 130 | * process will inherit a flag if they should look for a | |
| 131 | 131 | * child_subreaper process at exit. | |
| 132 | 132 | */ | |
| 133 | - | bool is_child_subreaper; | |
| 134 | - | bool has_child_subreaper; | |
| 133 | + | unsigned int is_child_subreaper:1; | |
| 134 | + | unsigned int has_child_subreaper:1; | |
| 135 | 135 | unsigned int autoreap:1; | |
| 136 | 136 | ||
| 137 | 137 | #ifdef CONFIG_POSIX_TIMERS | |
modified kernel/futex/core.c
| @@ -439,45 +439,51 @@ struct hrtimer_sleeper *futex_setup_timer(ktime_t *time, struct hrtimer_sleeper | |||
| 439 | 439 | } | |
| 440 | 440 | ||
| 441 | 441 | /* | |
| 442 | - | * Generate a machine wide unique identifier for this inode. | |
| 442 | + | * Generate a machine wide unique identifier for this object (inode or mm). | |
| 443 | 443 | * | |
| 444 | 444 | * This relies on u64 not wrapping in the life-time of the machine; which with | |
| 445 | 445 | * 1ns resolution means almost 585 years. | |
| 446 | - | * | |
| 447 | - | * This further relies on the fact that a well formed program will not unmap | |
| 448 | - | * the file while it has a (shared) futex waiting on it. This mapping will have | |
| 449 | - | * a file reference which pins the mount and inode. | |
| 450 | - | * | |
| 451 | - | * If for some reason an inode gets evicted and read back in again, it will get | |
| 452 | - | * a new sequence number and will _NOT_ match, even though it is the exact same | |
| 453 | - | * file. | |
| 454 | - | * | |
| 455 | - | * It is important that futex_match() will never have a false-positive, esp. | |
| 456 | - | * for PI futexes that can mess up the state. The above argues that false-negatives | |
| 457 | - | * are only possible for malformed programs. | |
| 458 | 446 | */ | |
| 459 | - | static u64 get_inode_sequence_number(struct inode *inode) | |
| 447 | + | static u64 get_object_id(atomic64_t *object_seq) | |
| 460 | 448 | { | |
| 461 | - | static atomic64_t i_seq; | |
| 449 | + | static atomic64_t last_assigned_seq; | |
| 462 | 450 | u64 old; | |
| 463 | 451 | ||
| 464 | - | /* Does the inode already have a sequence number? */ | |
| 465 | - | old = atomic64_read(&inode->i_sequence); | |
| 452 | + | /* Does the object already have a sequence number? */ | |
| 453 | + | old = atomic64_read(object_seq); | |
| 466 | 454 | if (likely(old)) | |
| 467 | 455 | return old; | |
| 468 | 456 | ||
| 469 | 457 | for (;;) { | |
| 470 | - | u64 new = atomic64_inc_return(&i_seq); | |
| 458 | + | u64 new = atomic64_inc_return(&last_assigned_seq); | |
| 471 | 459 | if (WARN_ON_ONCE(!new)) | |
| 472 | 460 | continue; | |
| 473 | 461 | ||
| 474 | 462 | old = 0; | |
| 475 | - | if (!atomic64_try_cmpxchg_relaxed(&inode->i_sequence, &old, new)) | |
| 463 | + | if (!atomic64_try_cmpxchg_relaxed(object_seq, &old, new)) | |
| 476 | 464 | return old; | |
| 477 | 465 | return new; | |
| 478 | 466 | } | |
| 479 | 467 | } | |
| 480 | 468 | ||
| 469 | + | /* | |
| 470 | + | * This relies on the fact that a well formed program will not unmap | |
| 471 | + | * the file while it has a (shared) futex waiting on it. This mapping will have | |
| 472 | + | * a file reference which pins the mount and inode. | |
| 473 | + | * | |
| 474 | + | * If for some reason an inode gets evicted and read back in again, it will get | |
| 475 | + | * a new sequence number and will _NOT_ match, even though it is the exact same | |
| 476 | + | * file. | |
| 477 | + | * | |
| 478 | + | * It is important that futex_match() will never have a false-positive, esp. | |
| 479 | + | * for PI futexes that can mess up the state. The above argues that false-negatives | |
| 480 | + | * are only possible for malformed programs. | |
| 481 | + | */ | |
| 482 | + | static u64 get_inode_sequence_number(struct inode *inode) | |
| 483 | + | { | |
| 484 | + | return get_object_id(&inode->i_sequence); | |
| 485 | + | } | |
| 486 | + | ||
| 481 | 487 | /** | |
| 482 | 488 | * get_futex_key() - Get parameters which are the keys for a futex | |
| 483 | 489 | * @uaddr: virtual address of the futex | |
| @@ -683,8 +689,8 @@ again: | |||
| 683 | 689 | goto out; | |
| 684 | 690 | } | |
| 685 | 691 | ||
| 686 | - | key->both.offset |= FUT_OFF_MMSHARED; /* ref taken on mm */ | |
| 687 | - | key->private.mm = mm; | |
| 692 | + | key->both.offset |= FUT_OFF_MMSHARED; | |
| 693 | + | key->private.mm_seq = get_object_id(&mm->futex.unique_id); | |
| 688 | 694 | key->private.address = address; | |
| 689 | 695 | ||
| 690 | 696 | } else { | |
| @@ -2055,13 +2061,12 @@ static void futex_robust_unlock_init_mm(struct futex_mm_data *fd) | |||
| 2055 | 2061 | static inline void futex_robust_unlock_init_mm(struct futex_mm_data *fd) { } | |
| 2056 | 2062 | #endif /* !CONFIG_FUTEX_ROBUST_UNLOCK */ | |
| 2057 | 2063 | ||
| 2058 | - | #if defined(CONFIG_FUTEX_PRIVATE_HASH) || defined(CONFIG_FUTEX_ROBUST_UNLOCK) | |
| 2059 | 2064 | void futex_mm_init(struct mm_struct *mm) | |
| 2060 | 2065 | { | |
| 2066 | + | atomic64_set(&mm->futex.unique_id, 0); | |
| 2061 | 2067 | futex_hash_init_mm(&mm->futex); | |
| 2062 | 2068 | futex_robust_unlock_init_mm(&mm->futex); | |
| 2063 | 2069 | } | |
| 2064 | - | #endif | |
| 2065 | 2070 | ||
| 2066 | 2071 | int futex_hash_prctl(unsigned long arg2, unsigned long arg3, unsigned long arg4) | |
| 2067 | 2072 | { | |
modified kernel/watch_queue.c
| @@ -101,7 +101,7 @@ static bool post_one_notification(struct watch_queue *wqueue, | |||
| 101 | 101 | struct pipe_inode_info *pipe = wqueue->pipe; | |
| 102 | 102 | struct pipe_buffer *buf; | |
| 103 | 103 | struct page *page; | |
| 104 | - | unsigned int head, tail, note, offset, len, nr_notes; | |
| 104 | + | unsigned int head, tail, note, offset, len; | |
| 105 | 105 | bool done = false; | |
| 106 | 106 | ||
| 107 | 107 | spin_lock_irq(&pipe->rd_wait.lock); | |
| @@ -111,10 +111,8 @@ static bool post_one_notification(struct watch_queue *wqueue, | |||
| 111 | 111 | if (pipe_full(head, tail, pipe->ring_size)) | |
| 112 | 112 | goto lost; | |
| 113 | 113 | ||
| 114 | - | /* Pairs with the smp_store_release() in watch_queue_set_size(). */ | |
| 115 | - | nr_notes = smp_load_acquire(&wqueue->nr_notes); | |
| 116 | - | note = find_first_bit(wqueue->notes_bitmap, nr_notes); | |
| 117 | - | if (note >= nr_notes) | |
| 114 | + | note = find_first_bit(wqueue->notes_bitmap, wqueue->nr_notes); | |
| 115 | + | if (note >= wqueue->nr_notes) | |
| 118 | 116 | goto lost; | |
| 119 | 117 | ||
| 120 | 118 | page = wqueue->notes[note / WATCH_QUEUE_NOTES_PER_PAGE]; | |
| @@ -299,8 +297,7 @@ long watch_queue_set_size(struct pipe_inode_info *pipe, unsigned int nr_notes) | |||
| 299 | 297 | wqueue->notes = pages; | |
| 300 | 298 | wqueue->notes_bitmap = bitmap; | |
| 301 | 299 | wqueue->nr_pages = nr_pages; | |
| 302 | - | /* Pairs with the smp_load_acquire() in post_one_notification(). */ | |
| 303 | - | smp_store_release(&wqueue->nr_notes, nr_notes); | |
| 300 | + | wqueue->nr_notes = nr_notes; | |
| 304 | 301 | return 0; | |
| 305 | 302 | ||
| 306 | 303 | error_p: | |
modified samples/pidfd/Makefile
| @@ -1,4 +1,4 @@ | |||
| 1 | 1 | # SPDX-License-Identifier: GPL-2.0 | |
| 2 | - | userprogs-always-y += pidfd-metadata | |
| 2 | + | usertprogs-always-y += pidfd-metadata | |
| 3 | 3 | ||
| 4 | 4 | userccflags += -I usr/include | |