mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Chuck Ebbert <76306.1226@compuserve.com>
To: Robert Love <rml@tech9.net>
Cc: linux-kernel <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] New cpu macro and i386 cleanup
Date: Sat, 5 Apr 2003 17:17:33 -0500	[thread overview]
Message-ID: <200304051719_MC3-1-3328-B238@compuserve.com> (raw)

Robert Love wrote:


> On a glance, it looked like at least some of them were.


Looks like do_rdmsr is not disabling preempt.  This should fix
it (compiled not tested.)


diff -u --exclude-from=/home/me/.exclude -r linux-2.5.66-ref/arch/i386/kernel/cpuid.c linux-2.5.66-uni/arch/i386/kernel/cpuid.c
--- linux-2.5.66-ref/arch/i386/kernel/cpuid.c	Sat Mar 29 09:16:32 2003
+++ linux-2.5.66-uni/arch/i386/kernel/cpuid.c	Fri Apr  4 18:45:19 2003
@ -56,7 +56,7 @
 {
   struct cpuid_command *cmd = (struct cpuid_command *) cmd_block;
   
-  if ( cmd->cpu == smp_processor_id() )
+  if ( is_current_cpu(cmd->cpu) )
     cpuid(cmd->reg, &cmd->data[0], &cmd->data[1], &cmd->data[2], &cmd->data[3]);
 }
 
@ -65,7 +65,7 @
   struct cpuid_command cmd;
   
   preempt_disable();
-  if ( cpu == smp_processor_id() ) {
+  if ( is_current_cpu(cpu) ) {
     cpuid(reg, &data[0], &data[1], &data[2], &data[3]);
   } else {
     cmd.cpu  = cpu;
diff -u --exclude-from=/home/me/.exclude -r linux-2.5.66-ref/arch/i386/kernel/msr.c linux-2.5.66-uni/arch/i386/kernel/msr.c
--- linux-2.5.66-ref/arch/i386/kernel/msr.c	Sat Mar 29 09:16:32 2003
+++ linux-2.5.66-uni/arch/i386/kernel/msr.c	Sat Apr  5 16:18:29 2003
@ -100,7 +100,7 @
 {
   struct msr_command *cmd = (struct msr_command *) cmd_block;
   
-  if ( cmd->cpu == smp_processor_id() )
+  if ( is_current_cpu(cmd->cpu) )
     cmd->err = wrmsr_eio(cmd->reg, cmd->data[0], cmd->data[1]);
 }
 
@ -108,7 +108,7 @
 {
   struct msr_command *cmd = (struct msr_command *) cmd_block;
   
-  if ( cmd->cpu == smp_processor_id() )
+  if ( is_current_cpu(cmd->cpu) )
     cmd->err = rdmsr_eio(cmd->reg, &cmd->data[0], &cmd->data[1]);
 }
 
@ -118,29 +118,31 @
   int ret;
 
   preempt_disable();
-  if ( cpu == smp_processor_id() ) {
+  if ( is_current_cpu(cpu) )
     ret = wrmsr_eio(reg, eax, edx);
-    preempt_enable();
-    return ret;
-  } else {
+  else {
     cmd.cpu = cpu;
     cmd.reg = reg;
     cmd.data[0] = eax;
     cmd.data[1] = edx;
     
     smp_call_function(msr_smp_wrmsr, &cmd, 1, 1);
-    preempt_enable();
-    return cmd.err;
+
+    ret = cmd.err;
   }
+  preempt_enable();
+  return ret;
 }
 
 static inline int do_rdmsr(int cpu, u32 reg, u32 *eax, u32 *edx)
 {
   struct msr_command cmd;
+  int ret;
 
-  if ( cpu == smp_processor_id() ) {
-    return rdmsr_eio(reg, eax, edx);
-  } else {
+  preempt_disable();
+  if ( is_current_cpu(cpu) )
+    ret = rdmsr_eio(reg, eax, edx);
+  else {
     cmd.cpu = cpu;
     cmd.reg = reg;
 
@ -148,9 +150,10 @
     
     *eax = cmd.data[0];
     *edx = cmd.data[1];
-
-    return cmd.err;
+    ret = cmd.err;
   }
+  preempt_enable();
+  return ret;
 }
 
 #else /* ! CONFIG_SMP */
diff -u --exclude-from=/home/me/.exclude -r linux-2.5.66-ref/include/linux/smp.h linux-2.5.66-uni/include/linux/smp.h
--- linux-2.5.66-ref/include/linux/smp.h	Tue Mar  4 22:29:21 2003
+++ linux-2.5.66-uni/include/linux/smp.h	Sat Apr  5 16:33:09 2003
@ -134,6 +134,12 @
 }
 #endif /* !SMP */
 
+	/* is_current_cpu() is not preempt-safe.
+	 * Use 'cpu == get_cpu()' and then put_cpu()
+	 * if preempt not already disabled.
+	 */
+#define is_current_cpu(cpu)	((cpu) == smp_processor_id())
+
 #define get_cpu()		({ preempt_disable(); smp_processor_id(); })
 #define put_cpu()		preempt_enable()
 #define put_cpu_no_resched()	preempt_enable_no_resched()
diff -u --exclude-from=/home/me/.exclude -r linux-2.5.66-ref/include/linux/threads.h linux-2.5.66-uni/include/linux/threads.h
--- linux-2.5.66-ref/include/linux/threads.h	Tue Mar  4 22:28:55 2003
+++ linux-2.5.66-uni/include/linux/threads.h	Sat Mar 29 11:01:55 2003
@ -20,6 +20,9 @
 #define NR_CPUS		1
 #endif
 
+#define FIRST_CPU	0
+#define LAST_CPU	(NR_CPUS - 1)
+
 #define MIN_THREADS_LEFT_FOR_ROOT 4
 
 /*



--
 Chuck
 I am not a number!

             reply	other threads:[~2003-04-05 22:08 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-04-05 22:17 Chuck Ebbert [this message]
  -- strict thread matches above, loose matches on Subject: below --
2003-04-05 10:24 Chuck Ebbert
2003-04-05 18:56 ` Robert Love
2003-04-05  0:29 Chuck Ebbert
2003-04-05  1:05 ` Robert Love

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200304051719_MC3-1-3328-B238@compuserve.com \
    --to=76306.1226@compuserve.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rml@tech9.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®