Skip to content

Commit 5323922

Browse files
KAGA-KOKOIngo Molnar
authored andcommitted
x86/msr: Add missing __percpu annotations
Sparse rightfully complains about using a plain pointer for per CPU accessors: msr-smp.c:15:23: sparse: warning: incorrect type in initializer (different address spaces) msr-smp.c:15:23: sparse: expected void const [noderef] __percpu *__vpp_verify msr-smp.c:15:23: sparse: got struct msr * Add __percpu annotations to the related datastructure and function arguments to cure this. This also cures the related sparse warnings at the callsites in drivers/edac/amd64_edac.c. Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: Ingo Molnar <mingo@kernel.org> Link: https://lore.kernel.org/r/20240304005104.513181735@linutronix.de
1 parent 154fcf3 commit 5323922

File tree

5 files changed

+24
-24
lines changed

5 files changed

+24
-24
lines changed

arch/x86/include/asm/msr.h

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@
1212
#include <uapi/asm/msr.h>
1313
#include <asm/shared/msr.h>
1414

15+
#include <linux/percpu.h>
16+
1517
struct msr_info {
16-
u32 msr_no;
17-
struct msr reg;
18-
struct msr *msrs;
19-
int err;
18+
u32 msr_no;
19+
struct msr reg;
20+
struct msr __percpu *msrs;
21+
int err;
2022
};
2123

2224
struct msr_regs_info {
@@ -305,8 +307,8 @@ static inline int wrmsrl_safe(u32 msr, u64 val)
305307
return wrmsr_safe(msr, (u32)val, (u32)(val >> 32));
306308
}
307309

308-
struct msr *msrs_alloc(void);
309-
void msrs_free(struct msr *msrs);
310+
struct msr __percpu *msrs_alloc(void);
311+
void msrs_free(struct msr __percpu *msrs);
310312
int msr_set_bit(u32 msr, u8 bit);
311313
int msr_clear_bit(u32 msr, u8 bit);
312314

@@ -315,8 +317,8 @@ int rdmsr_on_cpu(unsigned int cpu, u32 msr_no, u32 *l, u32 *h);
315317
int wrmsr_on_cpu(unsigned int cpu, u32 msr_no, u32 l, u32 h);
316318
int rdmsrl_on_cpu(unsigned int cpu, u32 msr_no, u64 *q);
317319
int wrmsrl_on_cpu(unsigned int cpu, u32 msr_no, u64 q);
318-
void rdmsr_on_cpus(const struct cpumask *mask, u32 msr_no, struct msr *msrs);
319-
void wrmsr_on_cpus(const struct cpumask *mask, u32 msr_no, struct msr *msrs);
320+
void rdmsr_on_cpus(const struct cpumask *mask, u32 msr_no, struct msr __percpu *msrs);
321+
void wrmsr_on_cpus(const struct cpumask *mask, u32 msr_no, struct msr __percpu *msrs);
320322
int rdmsr_safe_on_cpu(unsigned int cpu, u32 msr_no, u32 *l, u32 *h);
321323
int wrmsr_safe_on_cpu(unsigned int cpu, u32 msr_no, u32 l, u32 h);
322324
int rdmsrl_safe_on_cpu(unsigned int cpu, u32 msr_no, u64 *q);
@@ -345,14 +347,14 @@ static inline int wrmsrl_on_cpu(unsigned int cpu, u32 msr_no, u64 q)
345347
return 0;
346348
}
347349
static inline void rdmsr_on_cpus(const struct cpumask *m, u32 msr_no,
348-
struct msr *msrs)
350+
struct msr __percpu *msrs)
349351
{
350-
rdmsr_on_cpu(0, msr_no, &(msrs[0].l), &(msrs[0].h));
352+
rdmsr_on_cpu(0, msr_no, raw_cpu_ptr(&msrs->l), raw_cpu_ptr(&msrs->h));
351353
}
352354
static inline void wrmsr_on_cpus(const struct cpumask *m, u32 msr_no,
353-
struct msr *msrs)
355+
struct msr __percpu *msrs)
354356
{
355-
wrmsr_on_cpu(0, msr_no, msrs[0].l, msrs[0].h);
357+
wrmsr_on_cpu(0, msr_no, raw_cpu_read(msrs->l), raw_cpu_read(msrs->h));
356358
}
357359
static inline int rdmsr_safe_on_cpu(unsigned int cpu, u32 msr_no,
358360
u32 *l, u32 *h)

arch/x86/include/asm/processor.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ struct vm86;
2020
#include <asm/page.h>
2121
#include <asm/pgtable_types.h>
2222
#include <asm/percpu.h>
23-
#include <asm/msr.h>
2423
#include <asm/desc_defs.h>
2524
#include <asm/nops.h>
2625
#include <asm/special_insns.h>

arch/x86/include/asm/tsc.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
#ifndef _ASM_X86_TSC_H
66
#define _ASM_X86_TSC_H
77

8-
#include <asm/processor.h>
98
#include <asm/cpufeature.h>
9+
#include <asm/processor.h>
10+
#include <asm/msr.h>
1011

1112
/*
1213
* Standard way to access the cycle counter.

arch/x86/lib/msr-smp.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@ static void __rdmsr_on_cpu(void *info)
99
{
1010
struct msr_info *rv = info;
1111
struct msr *reg;
12-
int this_cpu = raw_smp_processor_id();
1312

1413
if (rv->msrs)
15-
reg = per_cpu_ptr(rv->msrs, this_cpu);
14+
reg = this_cpu_ptr(rv->msrs);
1615
else
1716
reg = &rv->reg;
1817

@@ -23,10 +22,9 @@ static void __wrmsr_on_cpu(void *info)
2322
{
2423
struct msr_info *rv = info;
2524
struct msr *reg;
26-
int this_cpu = raw_smp_processor_id();
2725

2826
if (rv->msrs)
29-
reg = per_cpu_ptr(rv->msrs, this_cpu);
27+
reg = this_cpu_ptr(rv->msrs);
3028
else
3129
reg = &rv->reg;
3230

@@ -97,7 +95,7 @@ int wrmsrl_on_cpu(unsigned int cpu, u32 msr_no, u64 q)
9795
EXPORT_SYMBOL(wrmsrl_on_cpu);
9896

9997
static void __rwmsr_on_cpus(const struct cpumask *mask, u32 msr_no,
100-
struct msr *msrs,
98+
struct msr __percpu *msrs,
10199
void (*msr_func) (void *info))
102100
{
103101
struct msr_info rv;
@@ -124,7 +122,7 @@ static void __rwmsr_on_cpus(const struct cpumask *mask, u32 msr_no,
124122
* @msrs: array of MSR values
125123
*
126124
*/
127-
void rdmsr_on_cpus(const struct cpumask *mask, u32 msr_no, struct msr *msrs)
125+
void rdmsr_on_cpus(const struct cpumask *mask, u32 msr_no, struct msr __percpu *msrs)
128126
{
129127
__rwmsr_on_cpus(mask, msr_no, msrs, __rdmsr_on_cpu);
130128
}
@@ -138,7 +136,7 @@ EXPORT_SYMBOL(rdmsr_on_cpus);
138136
* @msrs: array of MSR values
139137
*
140138
*/
141-
void wrmsr_on_cpus(const struct cpumask *mask, u32 msr_no, struct msr *msrs)
139+
void wrmsr_on_cpus(const struct cpumask *mask, u32 msr_no, struct msr __percpu *msrs)
142140
{
143141
__rwmsr_on_cpus(mask, msr_no, msrs, __wrmsr_on_cpu);
144142
}

arch/x86/lib/msr.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
#define CREATE_TRACE_POINTS
77
#include <asm/msr-trace.h>
88

9-
struct msr *msrs_alloc(void)
9+
struct msr __percpu *msrs_alloc(void)
1010
{
11-
struct msr *msrs = NULL;
11+
struct msr __percpu *msrs = NULL;
1212

1313
msrs = alloc_percpu(struct msr);
1414
if (!msrs) {
@@ -20,7 +20,7 @@ struct msr *msrs_alloc(void)
2020
}
2121
EXPORT_SYMBOL(msrs_alloc);
2222

23-
void msrs_free(struct msr *msrs)
23+
void msrs_free(struct msr __percpu *msrs)
2424
{
2525
free_percpu(msrs);
2626
}

0 commit comments

Comments
 (0)