Skip to contentSkip to conversation

: remove code duplication

PATCH In review Borislav Petkov 3 participants 18 messages Jul 6, 2009 – Sep 14, 2009 x86

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 : remove code duplication

Since rdmsr_on_cpus and wrmsr_on_cpus are almost identical, make them call into a common __rwmsr_on_cpus helper passing a function pointer arg to the actual MSR operation.

---
 arch/x86/lib/msr.c |   48 ++++++++++++++++++------------------------------
 1 files changed, 18 insertions(+), 30 deletions(-)
arch/x86/lib/msr.c +18 -30
index 1440b9c..20b6df5 100644
@@ -71,14 +71,9 @@ int wrmsr_on_cpu(unsigned int cpu, u32 msr_no, u32 l, u32 h)
 }
 EXPORT_SYMBOL(wrmsr_on_cpu);
 
-/* rdmsr on a bunch of CPUs
- *
- * @mask:       which CPUs
- * @msr_no:     which MSR
- * @msrs:       array of MSR values
- *
- */
-void rdmsr_on_cpus(const cpumask_t *mask, u32 msr_no, struct msr *msrs)
+static inline void __rwmsr_on_cpus(const cpumask_t *mask, u32 msr_no,
+				   struct msr *msrs,
+				   void (*msr_func) (void *info))
 {
 	struct msr_info rv;
 	int this_cpu;
@@ -95,11 +90,22 @@ void rdmsr_on_cpus(const cpumask_t *mask, u32 msr_no, struct msr *msrs)
 	 * smp_call_function_many has been fixed to not skip it.
 	 */
 	this_cpu = raw_smp_processor_id();
-	smp_call_function_single(this_cpu, __rdmsr_on_cpu, &rv, 1);
-
-	smp_call_function_many(mask, __rdmsr_on_cpu, &rv, 1);
+	smp_call_function_single(this_cpu, msr_func, &rv, 1);
+	smp_call_function_many(mask, msr_func, &rv, 1);
 	preempt_enable();
 }
+
+/* rdmsr on a bunch of CPUs
+ *
+ * @mask:       which CPUs
+ * @msr_no:     which MSR
+ * @msrs:       array of MSR values
+ *
+ */
+void rdmsr_on_cpus(const cpumask_t *mask, u32 msr_no, struct msr *msrs)
+{
+	__rwmsr_on_cpus(mask, msr_no, msrs, __rdmsr_on_cpu);
+}
 EXPORT_SYMBOL(rdmsr_on_cpus);
 
 /*
@@ -112,25 +118,7 @@ EXPORT_SYMBOL(rdmsr_on_cpus);
  */
 void wrmsr_on_cpus(const cpumask_t *mask, u32 msr_no, struct msr *msrs)
 {
-	struct msr_info rv;
-	int this_cpu;
-
-	memset(&rv, 0, sizeof(rv));
-
-	rv.off    = cpumask_first(mask);
-	rv.msrs   = msrs;
-	rv.msr_no = msr_no;
-
-	preempt_disable();
-	/*
-	 * FIXME: handle the CPU we're executing on separately for now until
-	 * smp_call_function_many has been fixed to not skip it.
-	 */
-	this_cpu = raw_smp_processor_id();
-	smp_call_function_single(this_cpu, __wrmsr_on_cpu, &rv, 1);
-
-	smp_call_function_many(mask, __wrmsr_on_cpu, &rv, 1);
-	preempt_enable();
+	__rwmsr_on_cpus(mask, msr_no, msrs, __wrmsr_on_cpu);
 }
 EXPORT_SYMBOL(wrmsr_on_cpus);
 
Signature · 1 line
1.6.3.3
#1 lore raw

arch/x86/lib/msr.c void rdmsr_on_cpus(const cpumask_t *mask, u32 msr_no, struct msr *msrs) · line 95

Quoted 5 lines · Borislav Petkov
arch/x86/lib/msr.c +2 -2
-
-	smp_call_function_many(mask, __rdmsr_on_cpu, &rv, 1);
+	smp_call_function_single(this_cpu, msr_func, &rv, 1);
+	smp_call_function_many(mask, msr_func, &rv, 1);
 	preempt_enable();

Why are you using smp_call_function_single() to execute something *on your own CPU*?

-hpa

#2 lore raw
Quoted 9 lines · H. Peter Anvin

arch/x86/lib/msr.c void rdmsr_on_cpus(const cpumask_t *mask, u32 msr_no, struct msr *msrs) · line 95

Quoted 5 lines · Borislav Petkov
arch/x86/lib/msr.c +2 -2
-
-	smp_call_function_many(mask, __rdmsr_on_cpu, &rv, 1);
+	smp_call_function_single(this_cpu, msr_func, &rv, 1);
+	smp_call_function_many(mask, msr_func, &rv, 1);
 	preempt_enable();

Why are you using smp_call_function_single() to execute something *on your own CPU*?

Actually, the more important question is why am I executing anything on my own CPU without first checking if it is in the cpumask _at_ _all_?! /me ducks behind the sofa.

The right thing to do should be something like the following:

preempt_disable();
this_cpu = raw_smp_processor_id();

if (cpumask_test_cpu(this_cpu, mask)) {
	local_irq_disable();
	msr_func(&rv);
	local_irq_enable();
}

smp_call_function_many(mask, msr_func, &rv, 1);
preempt_enable();

Patch coming up...

Signature · 8 lines
Regards/Gruss,
Boris.

Operating | Advanced Micro Devices GmbH
  System  | Karl-Hammerschmidt-Str. 34, 85609 Dornach b. München, Germany
 Research | Geschäftsführer: Thomas M. McCoy, Giuliano Meroni
  Center  | Sitz: Dornach, Gemeinde Aschheim, Landkreis München
  (OSRC)  | Registergericht München, HRB Nr. 43632
#3 lore raw
Quoted 10 lines · Borislav Petkov

Actually, the more important question is why am I executing anything on my own CPU without first checking if it is in the cpumask _at_ _all_?! /me ducks behind the sofa.

The right thing to do should be something like the following:

preempt_disable();
this_cpu = raw_smp_processor_id();

Quoted 9 lines
if (cpumask_test_cpu(this_cpu, mask)) {
	local_irq_disable();
	msr_func(&rv);
	local_irq_enable();
}

smp_call_function_many(mask, msr_func, &rv, 1);
preempt_enable();

I don't see why you're disabling local IRQs.

-hpa

Signature · 2 lines
H. Peter Anvin, Intel Open Source Technology Center
I work for Intel.  I don't speak on their behalf.
#4 lore raw

PATCH 1/1 : execute on the correct CPU subset (was: Re: [PATCH] [x86, msr]: remove code duplication)

Quoted 17 lines · H. Peter Anvin
Quoted 16 lines · Borislav Petkov

Actually, the more important question is why am I executing anything on my own CPU without first checking if it is in the cpumask _at_ _all_?! /me ducks behind the sofa.

The right thing to do should be something like the following:

preempt_disable();
this_cpu = raw_smp_processor_id();

if (cpumask_test_cpu(this_cpu, mask)) {
	local_irq_disable();
	msr_func(&rv);
	local_irq_enable();
}
Quoted 5 lines
Quoted 3 lines

smp_call_function_many(mask, msr_func, &rv, 1);
preempt_enable();

I don't see why you're disabling local IRQs.

I guess I was trying to be overly careful but can't seem to think of a case when this would be appropriate. Hmm...

--
From: Borislav Petkov <[email protected]>
Date: Mon, 6 Jul 2009 16:08:34 +0200
Subject: [PATCH] [x86, msr]: execute on the correct CPU subset

rdmsr_on_cpus/wrmsr_on_cpus were erroneously executing on the current CPU even in the case where it wasn't in the supplied bitmask. Add a check for that and handle accordingly.

While at it, since rdmsr_on_cpus and wrmsr_on_cpus are almost identical, fold them into a common __rwmsr_on_cpus helper passing a function pointer arg to the actual MSR operation.

---
 arch/x86/lib/msr.c |   53 +++++++++++++++++++--------------------------------
 1 files changed, 20 insertions(+), 33 deletions(-)
arch/x86/lib/msr.c +20 -33
index 1440b9c..8242b12 100644
@@ -71,14 +71,9 @@ int wrmsr_on_cpu(unsigned int cpu, u32 msr_no, u32 l, u32 h)
 }
 EXPORT_SYMBOL(wrmsr_on_cpu);
 
-/* rdmsr on a bunch of CPUs
- *
- * @mask:       which CPUs
- * @msr_no:     which MSR
- * @msrs:       array of MSR values
- *
- */
-void rdmsr_on_cpus(const cpumask_t *mask, u32 msr_no, struct msr *msrs)
+static inline void __rwmsr_on_cpus(const cpumask_t *mask, u32 msr_no,
+				   struct msr *msrs,
+				   void (*msr_func) (void *info))
 {
 	struct msr_info rv;
 	int this_cpu;
@@ -90,16 +85,26 @@ void rdmsr_on_cpus(const cpumask_t *mask, u32 msr_no, struct msr *msrs)
 	rv.msr_no = msr_no;
 
 	preempt_disable();
-	/*
-	 * FIXME: handle the CPU we're executing on separately for now until
-	 * smp_call_function_many has been fixed to not skip it.
-	 */
 	this_cpu = raw_smp_processor_id();
-	smp_call_function_single(this_cpu, __rdmsr_on_cpu, &rv, 1);
 
-	smp_call_function_many(mask, __rdmsr_on_cpu, &rv, 1);
+	if (cpumask_test_cpu(this_cpu, mask))
+		msr_func(&rv);
+
+	smp_call_function_many(mask, msr_func, &rv, 1);
 	preempt_enable();
 }
+
+/* rdmsr on a bunch of CPUs
+ *
+ * @mask:       which CPUs
+ * @msr_no:     which MSR
+ * @msrs:       array of MSR values
+ *
+ */
+void rdmsr_on_cpus(const cpumask_t *mask, u32 msr_no, struct msr *msrs)
+{
+	__rwmsr_on_cpus(mask, msr_no, msrs, __rdmsr_on_cpu);
+}
 EXPORT_SYMBOL(rdmsr_on_cpus);
 
 /*
@@ -112,25 +117,7 @@ EXPORT_SYMBOL(rdmsr_on_cpus);
  */
 void wrmsr_on_cpus(const cpumask_t *mask, u32 msr_no, struct msr *msrs)
 {
-	struct msr_info rv;
-	int this_cpu;
-
-	memset(&rv, 0, sizeof(rv));
-
-	rv.off    = cpumask_first(mask);
-	rv.msrs   = msrs;
-	rv.msr_no = msr_no;
-
-	preempt_disable();
-	/*
-	 * FIXME: handle the CPU we're executing on separately for now until
-	 * smp_call_function_many has been fixed to not skip it.
-	 */
-	this_cpu = raw_smp_processor_id();
-	smp_call_function_single(this_cpu, __wrmsr_on_cpu, &rv, 1);
-
-	smp_call_function_many(mask, __wrmsr_on_cpu, &rv, 1);
-	preempt_enable();
+	__rwmsr_on_cpus(mask, msr_no, msrs, __wrmsr_on_cpu);
 }
 EXPORT_SYMBOL(wrmsr_on_cpus);
 
Signature · 12 lines
1.6.3.3


-- 
Regards/Gruss,
Boris.

Operating | Advanced Micro Devices GmbH
  System  | Karl-Hammerschmidt-Str. 34, 85609 Dornach b. München, Germany
 Research | Geschäftsführer: Thomas M. McCoy, Giuliano Meroni
  Center  | Sitz: Dornach, Gemeinde Aschheim, Landkreis München
  (OSRC)  | Registergericht München, HRB Nr. 43632
#5 lore raw

Re: [PATCH] [x86, msr]: execute on the correct CPU subset (was: Re: [PATCH] [x86, msr]: remove code duplication)

Hi,

Quoted 36 lines · Borislav Petkov
Quoted 17 lines · H. Peter Anvin
Quoted 16 lines · Borislav Petkov

Actually, the more important question is why am I executing anything on my own CPU without first checking if it is in the cpumask _at_ _all_?! /me ducks behind the sofa.

The right thing to do should be something like the following:

preempt_disable();
this_cpu = raw_smp_processor_id();

if (cpumask_test_cpu(this_cpu, mask)) {
	local_irq_disable();
	msr_func(&rv);
	local_irq_enable();
}
Quoted 5 lines
Quoted 3 lines

smp_call_function_many(mask, msr_func, &rv, 1);
preempt_enable();

I don't see why you're disabling local IRQs.

I guess I was trying to be overly careful but can't seem to think of a case when this would be appropriate. Hmm...

--
From: Borislav Petkov <[email protected]>
Date: Mon, 6 Jul 2009 16:08:34 +0200
Subject: [PATCH] [x86, msr]: execute on the correct CPU subset

rdmsr_on_cpus/wrmsr_on_cpus were erroneously executing on the current CPU even in the case where it wasn't in the supplied bitmask. Add a check for that and handle accordingly.

Quoted 8 lines

While at it, since rdmsr_on_cpus and wrmsr_on_cpus are almost identical, fold them into a common __rwmsr_on_cpus helper passing a function pointer arg to the actual MSR operation.

---
 arch/x86/lib/msr.c |   53 +++++++++++++++++++--------------------------------
 1 files changed, 20 insertions(+), 33 deletions(-)

any comments on that one, NAK/AK? Since it is a fix and not changing the interface to external users, it might be a good idea to include it in 2.6.31, IMHO, no?

Signature · 8 lines
Regards/Gruss,
Boris.

Operating | Advanced Micro Devices GmbH
  System  | Karl-Hammerschmidt-Str. 34, 85609 Dornach b. München, Germany
 Research | Geschäftsführer: Thomas M. McCoy, Giuliano Meroni
  Center  | Sitz: Dornach, Gemeinde Aschheim, Landkreis München
  (OSRC)  | Registergericht München, HRB Nr. 43632
#6 lore raw

Re: [PATCH] [x86, msr]: execute on the correct CPU subset

Quoted 5 lines · Borislav Petkov

any comments on that one, NAK/AK? Since it is a fix and not changing the interface to external users, it might be a good idea to include it in 2.6.31, IMHO, no?

Yes, I also don't think it's a rush, so I'll take care of it when I get back from OLS.

-hpa

#7 lore raw

Re: [PATCH] [x86, msr]: execute on the correct CPU subset

In reply to Borislav Petkov
Quoted 6 lines · Borislav Petkov
arch/x86/lib/msr.c +0 -4
 	preempt_disable();
-	/*
-	 * FIXME: handle the CPU we're executing on separately for now until
-	 * smp_call_function_many has been fixed to not skip it.
-	 */

arch/x86/lib/msr.c void rdmsr_on_cpus(const cpumask_t *mask, u32 msr_no, struct msr *msrs) · line 95

Quoted 10 lines
arch/x86/lib/msr.c +4 -2
 	this_cpu = raw_smp_processor_id();
-	smp_call_function_single(this_cpu, __rdmsr_on_cpu, &rv, 1);
 
-	smp_call_function_many(mask, __rdmsr_on_cpu, &rv, 1);
+	if (cpumask_test_cpu(this_cpu, mask))
+		msr_func(&rv);
+
+	smp_call_function_many(mask, msr_func, &rv, 1);
 	preempt_enable();
 }

Any reason not to use get_cpu() ... put_cpu() instead?

-hpa

#8 lore raw

Re: [PATCH] [x86, msr]: execute on the correct CPU subset

Quoted 10 lines · H. Peter Anvin
Quoted 9 lines · Borislav Petkov
(quoted diff) +0 -5
 	preempt_disable();
-	/*
-	 * FIXME: handle the CPU we're executing on separately for now until
-	 * smp_call_function_many has been fixed to not skip it.
-	 */
 	this_cpu = raw_smp_processor_id();
-	smp_call_function_single(this_cpu, __rdmsr_on_cpu, &rv, 1);
Quoted 9 lines

Review

Quoted 7 lines
(quoted diff) +4 -1
-	smp_call_function_many(mask, __rdmsr_on_cpu, &rv, 1);
+	if (cpumask_test_cpu(this_cpu, mask))
+		msr_func(&rv);
+
+	smp_call_function_many(mask, msr_func, &rv, 1);
 	preempt_enable();
 }

Any reason not to use get_cpu() ... put_cpu() instead?

None, patch updated.

--
From: Borislav Petkov <[email protected]>
Date: Mon, 6 Jul 2009 16:08:34 +0200
Subject: [PATCH] [x86, msr]: execute on the correct CPU subset

rdmsr_on_cpus/wrmsr_on_cpus were erroneously executing on the current CPU even in the case where it wasn't in the supplied bitmask. Add a check for that and handle accordingly.

While at it, since rdmsr_on_cpus and wrmsr_on_cpus are almost identical, fold them call into a common __rwmsr_on_cpus helper passing a function pointer arg to the actual MSR operation.

---
 arch/x86/lib/msr.c |   58 +++++++++++++++++++--------------------------------
 1 files changed, 22 insertions(+), 36 deletions(-)
arch/x86/lib/msr.c +22 -36
index 1440b9c..cf879f0 100644
@@ -71,14 +71,9 @@ int wrmsr_on_cpu(unsigned int cpu, u32 msr_no, u32 l, u32 h)
 }
 EXPORT_SYMBOL(wrmsr_on_cpu);
 
-/* rdmsr on a bunch of CPUs
- *
- * @mask:       which CPUs
- * @msr_no:     which MSR
- * @msrs:       array of MSR values
- *
- */
-void rdmsr_on_cpus(const cpumask_t *mask, u32 msr_no, struct msr *msrs)
+static inline void __rwmsr_on_cpus(const cpumask_t *mask, u32 msr_no,
+				   struct msr *msrs,
+				   void (*msr_func) (void *info))
 {
 	struct msr_info rv;
 	int this_cpu;
@@ -89,16 +84,25 @@ void rdmsr_on_cpus(const cpumask_t *mask, u32 msr_no, struct msr *msrs)
 	rv.msrs	  = msrs;
 	rv.msr_no = msr_no;
 
-	preempt_disable();
-	/*
-	 * FIXME: handle the CPU we're executing on separately for now until
-	 * smp_call_function_many has been fixed to not skip it.
-	 */
-	this_cpu = raw_smp_processor_id();
-	smp_call_function_single(this_cpu, __rdmsr_on_cpu, &rv, 1);
+	this_cpu = get_cpu();
 
-	smp_call_function_many(mask, __rdmsr_on_cpu, &rv, 1);
-	preempt_enable();
+	if (cpumask_test_cpu(this_cpu, mask))
+		msr_func(&rv);
+
+	smp_call_function_many(mask, msr_func, &rv, 1);
+	put_cpu();
+}
+
+/* rdmsr on a bunch of CPUs
+ *
+ * @mask:       which CPUs
+ * @msr_no:     which MSR
+ * @msrs:       array of MSR values
+ *
+ */
+void rdmsr_on_cpus(const cpumask_t *mask, u32 msr_no, struct msr *msrs)
+{
+	__rwmsr_on_cpus(mask, msr_no, msrs, __rdmsr_on_cpu);
 }
 EXPORT_SYMBOL(rdmsr_on_cpus);
 
@@ -112,25 +116,7 @@ EXPORT_SYMBOL(rdmsr_on_cpus);
  */
 void wrmsr_on_cpus(const cpumask_t *mask, u32 msr_no, struct msr *msrs)
 {
-	struct msr_info rv;
-	int this_cpu;
-
-	memset(&rv, 0, sizeof(rv));
-
-	rv.off    = cpumask_first(mask);
-	rv.msrs   = msrs;
-	rv.msr_no = msr_no;
-
-	preempt_disable();
-	/*
-	 * FIXME: handle the CPU we're executing on separately for now until
-	 * smp_call_function_many has been fixed to not skip it.
-	 */
-	this_cpu = raw_smp_processor_id();
-	smp_call_function_single(this_cpu, __wrmsr_on_cpu, &rv, 1);
-
-	smp_call_function_many(mask, __wrmsr_on_cpu, &rv, 1);
-	preempt_enable();
+	__rwmsr_on_cpus(mask, msr_no, msrs, __wrmsr_on_cpu);
 }
 EXPORT_SYMBOL(wrmsr_on_cpus);
 
Signature · 12 lines
1.6.3.3


-- 
Regards/Gruss,
Boris.

Operating | Advanced Micro Devices GmbH
  System  | Karl-Hammerschmidt-Str. 34, 85609 Dornach b. München, Germany
 Research | Geschäftsführer: Thomas M. McCoy, Giuliano Meroni
  Center  | Sitz: Dornach, Gemeinde Aschheim, Landkreis München
  (OSRC)  | Registergericht München, HRB Nr. 43632
#9 lore raw

Re: [PATCH] [x86, msr]: execute on the correct CPU subset

In reply to H. Peter Anvin
Quoted 1 line · H. Peter Anvin

Any reason not to use get_cpu() ... put_cpu() instead?

In case you haven't applied the one from yesterday yet, here's a better one which uses struct cpumask * instead of cpumask_t.

--
From: Borislav Petkov <[email protected]>
Date: Mon, 6 Jul 2009 16:08:34 +0200
Subject: [PATCH] [x86, msr]: execute on the correct CPU subset

rdmsr_on_cpus/wrmsr_on_cpus were erroneously executing on the current CPU even in the case where it wasn't in the supplied bitmask. Add a check for that and handle accordingly.

While at it, since rdmsr_on_cpus and wrmsr_on_cpus are almost identical, fold them call into a common __rwmsr_on_cpus helper passing a function pointer arg to the actual MSR operation.

---
 arch/x86/include/asm/msr.h |    4 +-
 arch/x86/lib/msr.c         |   60 +++++++++++++++++---------------------------
 2 files changed, 25 insertions(+), 39 deletions(-)
arch/x86/include/asm/msr.h +2 -2
index 48ad9d2..988b067 100644
@@ -224,8 +224,8 @@ do {                                                            \
 #ifdef CONFIG_SMP
 int rdmsr_on_cpu(unsigned int cpu, u32 msr_no, u32 *l, u32 *h);
 int wrmsr_on_cpu(unsigned int cpu, u32 msr_no, u32 l, u32 h);
-void rdmsr_on_cpus(const cpumask_t *mask, u32 msr_no, struct msr *msrs);
-void wrmsr_on_cpus(const cpumask_t *mask, u32 msr_no, struct msr *msrs);
+void rdmsr_on_cpus(struct cpumask *mask, u32 msr_no, struct msr *msrs);
+void wrmsr_on_cpus(struct cpumask *mask, u32 msr_no, struct msr *msrs);
 int rdmsr_safe_on_cpu(unsigned int cpu, u32 msr_no, u32 *l, u32 *h);
 int wrmsr_safe_on_cpu(unsigned int cpu, u32 msr_no, u32 l, u32 h);
 #else  /*  CONFIG_SMP  */
arch/x86/lib/msr.c +23 -37

80 lines not on this page · raw message

Signature · 11 lines
1.6.3.3

-- 
Regards/Gruss,
Boris.

Operating | Advanced Micro Devices GmbH
  System  | Karl-Hammerschmidt-Str. 34, 85609 Dornach b. München, Germany
 Research | Geschäftsführer: Thomas M. McCoy, Giuliano Meroni
  Center  | Sitz: Dornach, Gemeinde Aschheim, Landkreis München
  (OSRC)  | Registergericht München, HRB Nr. 43632
#10 lore raw

Re: [PATCH] [x86, msr]: execute on the correct CPU subset

Quoted 6 lines · Borislav Petkov
Quoted 1 line · H. Peter Anvin

Any reason not to use get_cpu() ... put_cpu() instead?

In case you haven't applied the one from yesterday yet, here's a better one which uses struct cpumask * instead of cpumask_t.

Mangled patch (quoted-printable).

Furthermore, are there any users for this interface at this time?

-hpa

#11 lore raw

Re: [PATCH] [x86, msr]: execute on the correct CPU subset

Quoted 9 lines · H. Peter Anvin
Quoted 6 lines · Borislav Petkov
Quoted 1 line · H. Peter Anvin

Any reason not to use get_cpu() ... put_cpu() instead?

In case you haven't applied the one from yesterday yet, here's a better one which uses struct cpumask * instead of cpumask_t.

Mangled patch (quoted-printable).

Sorry about that, will resend tomorrow.

Quoted 1 line

Furthermore, are there any users for this interface at this time?

Yep, drivers/edac/amd64_edac.c.

Signature · 2 lines
Regards/Gruss,
    Boris.
#12 lore raw

Re: [PATCH] [x86, msr]: execute on the correct CPU subset

Quoted 5 lines · Borislav Petkov
Quoted 2 lines

Furthermore, are there any users for this interface at this time?

Yep, drivers/edac/amd64_edac.c.

So let's see... you're asking to change an in-use interface late in the -rc series when it has active users?

-hpa

#13 lore raw

Re: [PATCH] [x86, msr]: execute on the correct CPU subset

Quoted 9 lines · H. Peter Anvin
Quoted 5 lines · Borislav Petkov
Quoted 2 lines

Furthermore, are there any users for this interface at this time?

Yep, drivers/edac/amd64_edac.c.

So let's see... you're asking to change an in-use interface late in the -rc series when it has active users?

Ok, I could create a minimal patch with only the bugfix and send the remaining changes later during the next merge window, if that's preferred?

Signature · 2 lines
Regards/Gruss,
    Boris.
#14 lore raw

Re: [PATCH] [x86, msr]: execute on the correct CPU subset

Quoted 4 lines · Borislav Petkov
Quoted 3 lines · H. Peter Anvin
Quoted 2 lines · Borislav Petkov
Quoted 2 lines

Furthermore, are there any users for this interface at this time?

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

Yep, drivers/edac/amd64_edac.c.

So let's see... you're asking to change an in-use interface late in the -rc series when it has active users?

Ok, I could create a minimal patch with only the bugfix and send the remaining changes later during the next merge window, if that's preferred?

Send the remaining *incremental* changes now, I will put them into the queue for .32.

-hpa

#15 lore raw

PATCH 1/1 x86, msr: unify rdmsr_on_cpus/wrmsr_on_cpus

Since rdmsr_on_cpus and wrmsr_on_cpus are almost identical, unify them into a common __rwmsr_on_cpus helper thus avoiding code duplication.

While at it, convert cpumask_t's to const struct cpumask *.

---

This one is .32 material.

 arch/x86/include/asm/msr.h |    4 +-
 arch/x86/lib/msr.c         |   46 ++++++++++++++++++-------------------------
 2 files changed, 21 insertions(+), 29 deletions(-)
arch/x86/include/asm/msr.h +2 -2
index 48ad9d2..f2f4309 100644
@@ -224,8 +224,8 @@ do {                                                            \
 #ifdef CONFIG_SMP
 int rdmsr_on_cpu(unsigned int cpu, u32 msr_no, u32 *l, u32 *h);
 int wrmsr_on_cpu(unsigned int cpu, u32 msr_no, u32 l, u32 h);
-void rdmsr_on_cpus(const cpumask_t *mask, u32 msr_no, struct msr *msrs);
-void wrmsr_on_cpus(const cpumask_t *mask, u32 msr_no, struct msr *msrs);
+void rdmsr_on_cpus(const struct cpumask *mask, u32 msr_no, struct msr *msrs);
+void wrmsr_on_cpus(const struct cpumask *mask, u32 msr_no, struct msr *msrs);
 int rdmsr_safe_on_cpu(unsigned int cpu, u32 msr_no, u32 *l, u32 *h);
 int wrmsr_safe_on_cpu(unsigned int cpu, u32 msr_no, u32 l, u32 h);
 #else  /*  CONFIG_SMP  */
arch/x86/lib/msr.c +19 -27

68 lines not on this page · raw message

Signature · 1 line
1.6.3.3
#16 lore raw

Re: [PATCH] x86, msr: unify rdmsr_on_cpus/wrmsr_on_cpus

Hi Peter,

care to pick up the one below too while the merge window is still open?

Quoted 111 lines · Borislav Petkov

Since rdmsr_on_cpus and wrmsr_on_cpus are almost identical, unify them into a common __rwmsr_on_cpus helper thus avoiding code duplication.

While at it, convert cpumask_t's to const struct cpumask *.

---

This one is .32 material.

 arch/x86/include/asm/msr.h |    4 +-
 arch/x86/lib/msr.c         |   46 ++++++++++++++++++-------------------------
 2 files changed, 21 insertions(+), 29 deletions(-)
arch/x86/include/asm/msr.h +2 -2
index 48ad9d2..f2f4309 100644
@@ -224,8 +224,8 @@ do {                                                            \
 #ifdef CONFIG_SMP
 int rdmsr_on_cpu(unsigned int cpu, u32 msr_no, u32 *l, u32 *h);
 int wrmsr_on_cpu(unsigned int cpu, u32 msr_no, u32 l, u32 h);
-void rdmsr_on_cpus(const cpumask_t *mask, u32 msr_no, struct msr *msrs);
-void wrmsr_on_cpus(const cpumask_t *mask, u32 msr_no, struct msr *msrs);
+void rdmsr_on_cpus(const struct cpumask *mask, u32 msr_no, struct msr *msrs);
+void wrmsr_on_cpus(const struct cpumask *mask, u32 msr_no, struct msr *msrs);
 int rdmsr_safe_on_cpu(unsigned int cpu, u32 msr_no, u32 *l, u32 *h);
 int wrmsr_safe_on_cpu(unsigned int cpu, u32 msr_no, u32 l, u32 h);
 #else  /*  CONFIG_SMP  */
arch/x86/lib/msr.c +19 -27
index caa24ac..2f26cf4 100644
@@ -71,14 +71,9 @@ int wrmsr_on_cpu(unsigned int cpu, u32 msr_no, u32 l, u32 h)
 }
 EXPORT_SYMBOL(wrmsr_on_cpu);
 
-/* rdmsr on a bunch of CPUs
- *
- * @mask:       which CPUs
- * @msr_no:     which MSR
- * @msrs:       array of MSR values
- *
- */
-void rdmsr_on_cpus(const cpumask_t *mask, u32 msr_no, struct msr *msrs)
+static void __rwmsr_on_cpus(const struct cpumask *mask, u32 msr_no,
+			    struct msr *msrs,
+			    void (*msr_func) (void *info))
 {
 	struct msr_info rv;
 	int this_cpu;
@@ -92,11 +87,23 @@ void rdmsr_on_cpus(const cpumask_t *mask, u32 msr_no, struct msr *msrs)
 	this_cpu = get_cpu();
 
 	if (cpumask_test_cpu(this_cpu, mask))
-		__rdmsr_on_cpu(&rv);
+		msr_func(&rv);
 
-	smp_call_function_many(mask, __rdmsr_on_cpu, &rv, 1);
+	smp_call_function_many(mask, msr_func, &rv, 1);
 	put_cpu();
 }
+
+/* rdmsr on a bunch of CPUs
+ *
+ * @mask:       which CPUs
+ * @msr_no:     which MSR
+ * @msrs:       array of MSR values
+ *
+ */
+void rdmsr_on_cpus(const struct cpumask *mask, u32 msr_no, struct msr *msrs)
+{
+	__rwmsr_on_cpus(mask, msr_no, msrs, __rdmsr_on_cpu);
+}
 EXPORT_SYMBOL(rdmsr_on_cpus);
 
 /*
@@ -107,24 +114,9 @@ EXPORT_SYMBOL(rdmsr_on_cpus);
  * @msrs:       array of MSR values
  *
  */
-void wrmsr_on_cpus(const cpumask_t *mask, u32 msr_no, struct msr *msrs)
+void wrmsr_on_cpus(const struct cpumask *mask, u32 msr_no, struct msr *msrs)
 {
-	struct msr_info rv;
-	int this_cpu;
-
-	memset(&rv, 0, sizeof(rv));
-
-	rv.off    = cpumask_first(mask);
-	rv.msrs   = msrs;
-	rv.msr_no = msr_no;
-
-	this_cpu = get_cpu();
-
-	if (cpumask_test_cpu(this_cpu, mask))
-		__wrmsr_on_cpu(&rv);
-
-	smp_call_function_many(mask, __wrmsr_on_cpu, &rv, 1);
-	put_cpu();
+	__rwmsr_on_cpus(mask, msr_no, msrs, __wrmsr_on_cpu);
 }
 EXPORT_SYMBOL(wrmsr_on_cpus);
 
Signature · 6 lines
1.6.3.3

_______________________________________________
osrc-patches mailing list
[email protected]
https://ddcwww.amd.com/mailman/listinfo/osrc-patches
Signature · 8 lines
Regards/Gruss,
Boris.

Operating | Advanced Micro Devices GmbH
  System  | Karl-Hammerschmidt-Str. 34, 85609 Dornach b. München, Germany
 Research | Geschäftsführer: Andrew Bowd, Thomas M. McCoy, Giuliano Meroni
  Center  | Sitz: Dornach, Gemeinde Aschheim, Landkreis München
  (OSRC)  | Registergericht München, HRB Nr. 43632
#17 lore raw

PATCH 1/1 x86, msr: execute on the correct CPU subset

In reply to H. Peter Anvin

Make rdmsr_on_cpus/wrmsr_on_cpus execute on the current CPU only if it is in the supplied bitmask.

---
 arch/x86/lib/msr.c |   26 ++++++++++----------------
 1 files changed, 10 insertions(+), 16 deletions(-)
arch/x86/lib/msr.c +10 -16
index 1440b9c..caa24ac 100644
@@ -89,16 +89,13 @@ void rdmsr_on_cpus(const cpumask_t *mask, u32 msr_no, struct msr *msrs)
 	rv.msrs	  = msrs;
 	rv.msr_no = msr_no;
 
-	preempt_disable();
-	/*
-	 * FIXME: handle the CPU we're executing on separately for now until
-	 * smp_call_function_many has been fixed to not skip it.
-	 */
-	this_cpu = raw_smp_processor_id();
-	smp_call_function_single(this_cpu, __rdmsr_on_cpu, &rv, 1);
+	this_cpu = get_cpu();
+
+	if (cpumask_test_cpu(this_cpu, mask))
+		__rdmsr_on_cpu(&rv);
 
 	smp_call_function_many(mask, __rdmsr_on_cpu, &rv, 1);
-	preempt_enable();
+	put_cpu();
 }
 EXPORT_SYMBOL(rdmsr_on_cpus);
 
@@ -121,16 +118,13 @@ void wrmsr_on_cpus(const cpumask_t *mask, u32 msr_no, struct msr *msrs)
 	rv.msrs   = msrs;
 	rv.msr_no = msr_no;
 
-	preempt_disable();
-	/*
-	 * FIXME: handle the CPU we're executing on separately for now until
-	 * smp_call_function_many has been fixed to not skip it.
-	 */
-	this_cpu = raw_smp_processor_id();
-	smp_call_function_single(this_cpu, __wrmsr_on_cpu, &rv, 1);
+	this_cpu = get_cpu();
+
+	if (cpumask_test_cpu(this_cpu, mask))
+		__wrmsr_on_cpu(&rv);
 
 	smp_call_function_many(mask, __wrmsr_on_cpu, &rv, 1);
-	preempt_enable();
+	put_cpu();
 }
 EXPORT_SYMBOL(wrmsr_on_cpus);
 
Signature · 1 line
1.6.3.3