Compare
7cbaa0f4579f48e92639c6abb761fdef8fbade47..cf1f186e08dadb5abc4410d10fe3ada7ebf801ae
perf/x86/intel/uncore: Fix DMR CXL CM invert filter
The DMR CXL CM PMU places its invert filter at config bit 21 and its
9-bit threshold at bits 23-31. However, dmr_uncore_cxlcm uses
GENERIC_PMON_RAW_EVENT_MASK, which covers the threshold through the
generic bit 23 invert field and bits 24-31 threshold field, but does not
include the relocated invert bit. As a result, uncore_pmu_event_init()
silently clears bit 21 and inv=1 programs the same configuration as
inv=0.
Add bit 21 to a DMR CXL CM-specific event mask so the requested invert
filter reaches hardware.
Fixes: 6daf2c35b835 ("perf/x86/intel/uncore: Add IMH PMON support for Diamond Rapids")
Signed-off-by: Guixiong Wei <weiguixiong@bytedance.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: Zide Chen <zide.chen@intel.com>
Link: https://patch.msgid.link/20261008051953.6293-2-weiguixiong@bytedance.com
Guixiong Wei <weiguixiong@bytedance.com> · 2026-10-08 05:19 UTC · committed by Peter Zijlstra
5 files changed,
+37
−63
- arch/x86/events/intel/uncore_snbep.c
- include/linux/futex.h
- include/linux/futex_types.h
- include/linux/irq-entry-common.h
- kernel/futex/core.c
modified arch/x86/events/intel/uncore_snbep.c
| @@ -474,6 +474,9 @@ | |||
| 474 | 474 | /* DMR */ | |
| 475 | 475 | #define DMR_IMH1_HIOP_MMIO_BASE 0x1ffff6ae7000 | |
| 476 | 476 | #define DMR_HIOP_MMIO_SIZE 0x8000 | |
| 477 | + | #define DMR_CXLCM_PMON_CTL_INVERT BIT(21) | |
| 478 | + | #define DMR_CXLCM_PMON_RAW_EVENT_MASK (GENERIC_PMON_RAW_EVENT_MASK | \ | |
| 479 | + | DMR_CXLCM_PMON_CTL_INVERT) | |
| 477 | 480 | #define DMR_CXLCM_EVENT_MASK_EXT 0xf | |
| 478 | 481 | #define DMR_HAMVF_EVENT_MASK_EXT 0xffffffff | |
| 479 | 482 | #define DMR_PCIE4_EVENT_MASK_EXT 0xffffff | |
| @@ -6696,7 +6699,7 @@ static struct event_constraint dmr_uncore_cxlcm_constraints[] = { | |||
| 6696 | 6699 | ||
| 6697 | 6700 | static struct intel_uncore_type dmr_uncore_cxlcm = { | |
| 6698 | 6701 | .name = "cxlcm", | |
| 6699 | - | .event_mask = GENERIC_PMON_RAW_EVENT_MASK, | |
| 6702 | + | .event_mask = DMR_CXLCM_PMON_RAW_EVENT_MASK, | |
| 6700 | 6703 | .event_mask_ext = DMR_CXLCM_EVENT_MASK_EXT, | |
| 6701 | 6704 | .constraints = dmr_uncore_cxlcm_constraints, | |
| 6702 | 6705 | .format_group = &dmr_cxlcm_uncore_format_group, | |
modified include/linux/futex.h
| @@ -23,32 +23,28 @@ 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) | |
| 26 | + | * (but private mapping on an mm, and reference taken on it) | |
| 27 | 27 | */ | |
| 28 | 28 | ||
| 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 */ | |
| 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 */ | |
| 31 | 31 | ||
| 32 | 32 | union futex_key { | |
| 33 | - | /* For FUT_OFF_INODE */ | |
| 34 | 33 | struct { | |
| 35 | 34 | u64 i_seq; | |
| 36 | 35 | unsigned long pgoff; | |
| 37 | 36 | unsigned int offset; | |
| 38 | 37 | /* unsigned int node; */ | |
| 39 | 38 | } shared; | |
| 40 | - | ||
| 41 | - | /* For FUT_OFF_MMSHARED or private */ | |
| 42 | 39 | struct { | |
| 43 | 40 | union { | |
| 44 | - | struct mm_struct *mm; /* for private */ | |
| 45 | - | u64 mm_seq; /* for FUT_OFF_MMSHARED */ | |
| 41 | + | struct mm_struct *mm; | |
| 42 | + | u64 __tmp; | |
| 46 | 43 | }; | |
| 47 | 44 | unsigned long address; | |
| 48 | 45 | unsigned int offset; | |
| 49 | 46 | /* unsigned int node; */ | |
| 50 | 47 | } private; | |
| 51 | - | ||
| 52 | 48 | struct { | |
| 53 | 49 | u64 ptr; | |
| 54 | 50 | unsigned long word; | |
| @@ -156,10 +152,11 @@ static inline void futex_set_vdso_cs_range(struct futex_mm_data *fd, unsigned in | |||
| 156 | 152 | static inline void futex_fixup_robust_unlock(struct pt_regs *regs) { } | |
| 157 | 153 | #endif /* !CONFIG_FUTEX_ROBUST_UNLOCK */ | |
| 158 | 154 | ||
| 159 | - | #ifdef CONFIG_FUTEX | |
| 155 | + | ||
| 156 | + | #if defined(CONFIG_FUTEX_PRIVATE_HASH) || defined(CONFIG_FUTEX_ROBUST_UNLOCK) | |
| 160 | 157 | void futex_mm_init(struct mm_struct *mm); | |
| 161 | 158 | #else | |
| 162 | 159 | static inline void futex_mm_init(struct mm_struct *mm) { } | |
| 163 | - | #endif /* !CONFIG_FUTEX */ | |
| 160 | + | #endif | |
| 164 | 161 | ||
| 165 | 162 | #endif /* _LINUX_FUTEX_H */ | |
modified include/linux/futex_types.h
| @@ -85,12 +85,10 @@ 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 | |
| 89 | 88 | */ | |
| 90 | 89 | struct futex_mm_data { | |
| 91 | 90 | struct futex_mm_phash phash; | |
| 92 | 91 | struct futex_unlock_cs_ranges unlock; | |
| 93 | - | atomic64_t unique_id; | |
| 94 | 92 | }; | |
| 95 | 93 | #else /* CONFIG_FUTEX */ | |
| 96 | 94 | struct futex_sched_data { }; | |
modified include/linux/irq-entry-common.h
| @@ -468,25 +468,6 @@ 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 | - | ||
| 490 | 471 | /** | |
| 491 | 472 | * irqentry_exit_to_kernel_mode_after_preempt - Establish trace, lockdep and RCU state | |
| 492 | 473 | * @regs: Pointer to current's pt_regs | |
| @@ -510,7 +491,7 @@ irqentry_exit_to_kernel_mode_after_preempt(struct pt_regs *regs, irqentry_state_ | |||
| 510 | 491 | */ | |
| 511 | 492 | if (state.exit_rcu) { | |
| 512 | 493 | instrumentation_begin(); | |
| 513 | - | irqentry_hrtimer_rearm_deferred(); | |
| 494 | + | hrtimer_rearm_deferred(); | |
| 514 | 495 | /* Tell the tracer that IRET will enable interrupts */ | |
| 515 | 496 | trace_hardirqs_on_prepare(); | |
| 516 | 497 | lockdep_hardirqs_on_prepare(); | |
| @@ -521,7 +502,7 @@ irqentry_exit_to_kernel_mode_after_preempt(struct pt_regs *regs, irqentry_state_ | |||
| 521 | 502 | } | |
| 522 | 503 | ||
| 523 | 504 | instrumentation_begin(); | |
| 524 | - | irqentry_hrtimer_rearm_deferred(); | |
| 505 | + | hrtimer_rearm_deferred(); | |
| 525 | 506 | /* Covers both tracing and lockdep */ | |
| 526 | 507 | trace_hardirqs_on(); | |
| 527 | 508 | instrumentation_end(); | |
modified kernel/futex/core.c
| @@ -439,51 +439,45 @@ 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 object (inode or mm). | |
| 442 | + | * Generate a machine wide unique identifier for this inode. | |
| 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. | |
| 446 | 458 | */ | |
| 447 | - | static u64 get_object_id(atomic64_t *object_seq) | |
| 459 | + | static u64 get_inode_sequence_number(struct inode *inode) | |
| 448 | 460 | { | |
| 449 | - | static atomic64_t last_assigned_seq; | |
| 461 | + | static atomic64_t i_seq; | |
| 450 | 462 | u64 old; | |
| 451 | 463 | ||
| 452 | - | /* Does the object already have a sequence number? */ | |
| 453 | - | old = atomic64_read(object_seq); | |
| 464 | + | /* Does the inode already have a sequence number? */ | |
| 465 | + | old = atomic64_read(&inode->i_sequence); | |
| 454 | 466 | if (likely(old)) | |
| 455 | 467 | return old; | |
| 456 | 468 | ||
| 457 | 469 | for (;;) { | |
| 458 | - | u64 new = atomic64_inc_return(&last_assigned_seq); | |
| 470 | + | u64 new = atomic64_inc_return(&i_seq); | |
| 459 | 471 | if (WARN_ON_ONCE(!new)) | |
| 460 | 472 | continue; | |
| 461 | 473 | ||
| 462 | 474 | old = 0; | |
| 463 | - | if (!atomic64_try_cmpxchg_relaxed(object_seq, &old, new)) | |
| 475 | + | if (!atomic64_try_cmpxchg_relaxed(&inode->i_sequence, &old, new)) | |
| 464 | 476 | return old; | |
| 465 | 477 | return new; | |
| 466 | 478 | } | |
| 467 | 479 | } | |
| 468 | 480 | ||
| 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 | - | ||
| 487 | 481 | /** | |
| 488 | 482 | * get_futex_key() - Get parameters which are the keys for a futex | |
| 489 | 483 | * @uaddr: virtual address of the futex | |
| @@ -689,8 +683,8 @@ again: | |||
| 689 | 683 | goto out; | |
| 690 | 684 | } | |
| 691 | 685 | ||
| 692 | - | key->both.offset |= FUT_OFF_MMSHARED; | |
| 693 | - | key->private.mm_seq = get_object_id(&mm->futex.unique_id); | |
| 686 | + | key->both.offset |= FUT_OFF_MMSHARED; /* ref taken on mm */ | |
| 687 | + | key->private.mm = mm; | |
| 694 | 688 | key->private.address = address; | |
| 695 | 689 | ||
| 696 | 690 | } else { | |
| @@ -2061,12 +2055,13 @@ static void futex_robust_unlock_init_mm(struct futex_mm_data *fd) | |||
| 2061 | 2055 | static inline void futex_robust_unlock_init_mm(struct futex_mm_data *fd) { } | |
| 2062 | 2056 | #endif /* !CONFIG_FUTEX_ROBUST_UNLOCK */ | |
| 2063 | 2057 | ||
| 2058 | + | #if defined(CONFIG_FUTEX_PRIVATE_HASH) || defined(CONFIG_FUTEX_ROBUST_UNLOCK) | |
| 2064 | 2059 | void futex_mm_init(struct mm_struct *mm) | |
| 2065 | 2060 | { | |
| 2066 | - | atomic64_set(&mm->futex.unique_id, 0); | |
| 2067 | 2061 | futex_hash_init_mm(&mm->futex); | |
| 2068 | 2062 | futex_robust_unlock_init_mm(&mm->futex); | |
| 2069 | 2063 | } | |
| 2064 | + | #endif | |
| 2070 | 2065 | ||
| 2071 | 2066 | int futex_hash_prctl(unsigned long arg2, unsigned long arg3, unsigned long arg4) | |
| 2072 | 2067 | { | |