Skip to content

Commit 7f5faaa

Browse files
committed
Merge tag 'perf-urgent-2020-08-15' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull perf fixes from Ingo Molnar: "Misc fixes, an expansion of perf syscall access to CAP_PERFMON privileged tools, plus a RAPL HW-enablement for Intel SPR platforms" * tag 'perf-urgent-2020-08-15' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: perf/x86/rapl: Add support for Intel SPR platform perf/x86/rapl: Support multiple RAPL unit quirks perf/x86/rapl: Fix missing psys sysfs attributes hw_breakpoint: Remove unused __register_perf_hw_breakpoint() declaration kprobes: Remove show_registers() function prototype perf/core: Take over CAP_SYS_PTRACE creds to CAP_PERFMON capability
2 parents eb1319a + bcfd218 commit 7f5faaa

File tree

3 files changed

+38
-15
lines changed

3 files changed

+38
-15
lines changed

arch/x86/events/rapl.c

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,17 @@ struct rapl_pmus {
130130
struct rapl_pmu *pmus[];
131131
};
132132

133+
enum rapl_unit_quirk {
134+
RAPL_UNIT_QUIRK_NONE,
135+
RAPL_UNIT_QUIRK_INTEL_HSW,
136+
RAPL_UNIT_QUIRK_INTEL_SPR,
137+
};
138+
133139
struct rapl_model {
134140
struct perf_msr *rapl_msrs;
135141
unsigned long events;
136142
unsigned int msr_power_unit;
137-
bool apply_quirk;
143+
enum rapl_unit_quirk unit_quirk;
138144
};
139145

140146
/* 1/2^hw_unit Joule */
@@ -612,14 +618,28 @@ static int rapl_check_hw_unit(struct rapl_model *rm)
612618
for (i = 0; i < NR_RAPL_DOMAINS; i++)
613619
rapl_hw_unit[i] = (msr_rapl_power_unit_bits >> 8) & 0x1FULL;
614620

621+
switch (rm->unit_quirk) {
615622
/*
616623
* DRAM domain on HSW server and KNL has fixed energy unit which can be
617624
* different than the unit from power unit MSR. See
618625
* "Intel Xeon Processor E5-1600 and E5-2600 v3 Product Families, V2
619626
* of 2. Datasheet, September 2014, Reference Number: 330784-001 "
620627
*/
621-
if (rm->apply_quirk)
628+
case RAPL_UNIT_QUIRK_INTEL_HSW:
629+
rapl_hw_unit[PERF_RAPL_RAM] = 16;
630+
break;
631+
/*
632+
* SPR shares the same DRAM domain energy unit as HSW, plus it
633+
* also has a fixed energy unit for Psys domain.
634+
*/
635+
case RAPL_UNIT_QUIRK_INTEL_SPR:
622636
rapl_hw_unit[PERF_RAPL_RAM] = 16;
637+
rapl_hw_unit[PERF_RAPL_PSYS] = 0;
638+
break;
639+
default:
640+
break;
641+
}
642+
623643

624644
/*
625645
* Calculate the timer rate:
@@ -665,7 +685,7 @@ static const struct attribute_group *rapl_attr_update[] = {
665685
&rapl_events_pkg_group,
666686
&rapl_events_ram_group,
667687
&rapl_events_gpu_group,
668-
&rapl_events_gpu_group,
688+
&rapl_events_psys_group,
669689
NULL,
670690
};
671691

@@ -698,7 +718,6 @@ static struct rapl_model model_snb = {
698718
.events = BIT(PERF_RAPL_PP0) |
699719
BIT(PERF_RAPL_PKG) |
700720
BIT(PERF_RAPL_PP1),
701-
.apply_quirk = false,
702721
.msr_power_unit = MSR_RAPL_POWER_UNIT,
703722
.rapl_msrs = intel_rapl_msrs,
704723
};
@@ -707,7 +726,6 @@ static struct rapl_model model_snbep = {
707726
.events = BIT(PERF_RAPL_PP0) |
708727
BIT(PERF_RAPL_PKG) |
709728
BIT(PERF_RAPL_RAM),
710-
.apply_quirk = false,
711729
.msr_power_unit = MSR_RAPL_POWER_UNIT,
712730
.rapl_msrs = intel_rapl_msrs,
713731
};
@@ -717,7 +735,6 @@ static struct rapl_model model_hsw = {
717735
BIT(PERF_RAPL_PKG) |
718736
BIT(PERF_RAPL_RAM) |
719737
BIT(PERF_RAPL_PP1),
720-
.apply_quirk = false,
721738
.msr_power_unit = MSR_RAPL_POWER_UNIT,
722739
.rapl_msrs = intel_rapl_msrs,
723740
};
@@ -726,15 +743,15 @@ static struct rapl_model model_hsx = {
726743
.events = BIT(PERF_RAPL_PP0) |
727744
BIT(PERF_RAPL_PKG) |
728745
BIT(PERF_RAPL_RAM),
729-
.apply_quirk = true,
746+
.unit_quirk = RAPL_UNIT_QUIRK_INTEL_HSW,
730747
.msr_power_unit = MSR_RAPL_POWER_UNIT,
731748
.rapl_msrs = intel_rapl_msrs,
732749
};
733750

734751
static struct rapl_model model_knl = {
735752
.events = BIT(PERF_RAPL_PKG) |
736753
BIT(PERF_RAPL_RAM),
737-
.apply_quirk = true,
754+
.unit_quirk = RAPL_UNIT_QUIRK_INTEL_HSW,
738755
.msr_power_unit = MSR_RAPL_POWER_UNIT,
739756
.rapl_msrs = intel_rapl_msrs,
740757
};
@@ -745,14 +762,22 @@ static struct rapl_model model_skl = {
745762
BIT(PERF_RAPL_RAM) |
746763
BIT(PERF_RAPL_PP1) |
747764
BIT(PERF_RAPL_PSYS),
748-
.apply_quirk = false,
765+
.msr_power_unit = MSR_RAPL_POWER_UNIT,
766+
.rapl_msrs = intel_rapl_msrs,
767+
};
768+
769+
static struct rapl_model model_spr = {
770+
.events = BIT(PERF_RAPL_PP0) |
771+
BIT(PERF_RAPL_PKG) |
772+
BIT(PERF_RAPL_RAM) |
773+
BIT(PERF_RAPL_PSYS),
774+
.unit_quirk = RAPL_UNIT_QUIRK_INTEL_SPR,
749775
.msr_power_unit = MSR_RAPL_POWER_UNIT,
750776
.rapl_msrs = intel_rapl_msrs,
751777
};
752778

753779
static struct rapl_model model_amd_fam17h = {
754780
.events = BIT(PERF_RAPL_PKG),
755-
.apply_quirk = false,
756781
.msr_power_unit = MSR_AMD_RAPL_POWER_UNIT,
757782
.rapl_msrs = amd_rapl_msrs,
758783
};
@@ -787,6 +812,7 @@ static const struct x86_cpu_id rapl_model_match[] __initconst = {
787812
X86_MATCH_INTEL_FAM6_MODEL(ICELAKE_X, &model_hsx),
788813
X86_MATCH_INTEL_FAM6_MODEL(COMETLAKE_L, &model_skl),
789814
X86_MATCH_INTEL_FAM6_MODEL(COMETLAKE, &model_skl),
815+
X86_MATCH_INTEL_FAM6_MODEL(SAPPHIRERAPIDS_X, &model_spr),
790816
X86_MATCH_VENDOR_FAM(AMD, 0x17, &model_amd_fam17h),
791817
X86_MATCH_VENDOR_FAM(HYGON, 0x18, &model_amd_fam17h),
792818
{},

include/linux/hw_breakpoint.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ register_wide_hw_breakpoint(struct perf_event_attr *attr,
7272
void *context);
7373

7474
extern int register_perf_hw_breakpoint(struct perf_event *bp);
75-
extern int __register_perf_hw_breakpoint(struct perf_event *bp);
7675
extern void unregister_hw_breakpoint(struct perf_event *bp);
7776
extern void unregister_wide_hw_breakpoint(struct perf_event * __percpu *cpu_events);
7877

@@ -119,8 +118,6 @@ register_wide_hw_breakpoint(struct perf_event_attr *attr,
119118
void *context) { return NULL; }
120119
static inline int
121120
register_perf_hw_breakpoint(struct perf_event *bp) { return -ENOSYS; }
122-
static inline int
123-
__register_perf_hw_breakpoint(struct perf_event *bp) { return -ENOSYS; }
124121
static inline void unregister_hw_breakpoint(struct perf_event *bp) { }
125122
static inline void
126123
unregister_wide_hw_breakpoint(struct perf_event * __percpu *cpu_events) { }

kernel/events/core.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11706,15 +11706,15 @@ SYSCALL_DEFINE5(perf_event_open,
1170611706
goto err_task;
1170711707

1170811708
/*
11709-
* Reuse ptrace permission checks for now.
11709+
* Preserve ptrace permission check for backwards compatibility.
1171011710
*
1171111711
* We must hold exec_update_mutex across this and any potential
1171211712
* perf_install_in_context() call for this new event to
1171311713
* serialize against exec() altering our credentials (and the
1171411714
* perf_event_exit_task() that could imply).
1171511715
*/
1171611716
err = -EACCES;
11717-
if (!ptrace_may_access(task, PTRACE_MODE_READ_REALCREDS))
11717+
if (!perfmon_capable() && !ptrace_may_access(task, PTRACE_MODE_READ_REALCREDS))
1171811718
goto err_cred;
1171911719
}
1172011720

0 commit comments

Comments
 (0)