Skip to contentSkip to conversation

coretemp 1/3 Add rdmsr_safe_on_cpu and

PATCH New Rudolf Marek 3 participants 3 messages Mar 20, 2007 – Mar 24, 2007

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 coretemp 1/3 Add rdmsr_safe_on_cpu and

Hello,

I will spin the new patches here, in this thread. However I dont know whom to address this patch - after it is well tested. Maybe I will convert the msr.c driver for this new calls too.

This patch adds support for _safe (exception handled) variants of rdmsr_on_cpu and wrmsr_on_cpu. This is needed for the new coretemp driver, which might step into non-existing MSR (poorly documented).

Signed-of-by: Rudolf Marek <r.marek at assembler.cz>

Alexey, are you the right person to pass this to? LKML maybe?

To correct my statement about the include file:

   CHK     include/linux/version.h
   CHK     include/linux/utsrelease.h
   CC      arch/x86_64/kernel/asm-offsets.s
In file included from include/asm/processor.h:16,
                  from include/linux/prefetch.h:14,
                  from include/linux/list.h:8,
                  from include/linux/module.h:10,
                  from include/linux/crypto.h:21,
                  from arch/x86_64/kernel/asm-offsets.c:7:

include/asm/msr.h: In function 'rdmsr_safe_on_cpu':
include/asm/msr.h:179: error: 'EIO' undeclared (first use in this function) include/asm/msr.h:179: error: (Each undeclared identifier is reported only once include/asm/msr.h:179: error: for each function it appears in.) include/asm/msr.h: In function 'wrmsr_safe_on_cpu':
include/asm/msr.h:183: error: 'EFAULT' undeclared (first use in this function)

Thanks,
Rudolf
-------------- next part --------------
A non-text attachment was scrubbed...
Name: add-msr-io-safe.patch
Type: text/x-patch
Size: 5442 bytes
Desc: not available
Url : http://lists.lm-sensors.org/pipermail/lm-sensors/attachments/20070320/0ede87d7/attachment-0001.bin

#1 lore raw

PATCH 1/1 coretemp 1/3 Add rdmsr_safe_on_cpu and

Quoted 5 lines · Rudolf Marek

Hello,

I will spin the new patches here, in this thread. However I dont know whom to address this patch - after it is well tested. Maybe I will convert the msr.c driver for this new calls too.

I did this conversion, both patches (coretemp 1/3 and the one below) should go upstream together.

According to MAINTAINERS, you should cc (for this patch, and maybe the other one too):
CPUID/MSR DRIVER

P:    H. Peter Anvin
M:    hpa at zytor.com
S:    Maintained

You might also want to cc all these people:
http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h°77ffb3b767c3efb44d00b998385a9cb127255c

Best regards,

Nicolas

Use safe functions provided by arch/*/lib/msr-on-cpu.c in arch/i386/kernel/msr.c.

Signed-off-by Nicolas Boichat <nicolas at boichat.ch>

---

 arch/i386/kernel/msr.c |  106 ++----------------------------------------------
 1 files changed, 4 insertions(+), 102 deletions(-)
arch/i386/kernel/msr.c +4 -102
index bcaa6e9..8cd0a91 100644
@@ -45,104 +45,6 @@
 
 static struct class *msr_class;
 
-static inline int wrmsr_eio(u32 reg, u32 eax, u32 edx)
-{
-	int err;
-
-	err = wrmsr_safe(reg, eax, edx);
-	if (err)
-		err = -EIO;
-	return err;
-}
-
-static inline int rdmsr_eio(u32 reg, u32 *eax, u32 *edx)
-{
-	int err;
-
-	err = rdmsr_safe(reg, eax, edx);
-	if (err)
-		err = -EIO;
-	return err;
-}
-
-#ifdef CONFIG_SMP
-
-struct msr_command {
-	int err;
-	u32 reg;
-	u32 data[2];
-};
-
-static void msr_smp_wrmsr(void *cmd_block)
-{
-	struct msr_command *cmd = (struct msr_command *)cmd_block;
-
-	cmd->err = wrmsr_eio(cmd->reg, cmd->data[0], cmd->data[1]);
-}
-
-static void msr_smp_rdmsr(void *cmd_block)
-{
-	struct msr_command *cmd = (struct msr_command *)cmd_block;
-
-	cmd->err = rdmsr_eio(cmd->reg, &cmd->data[0], &cmd->data[1]);
-}
-
-static inline int do_wrmsr(int cpu, u32 reg, u32 eax, u32 edx)
-{
-	struct msr_command cmd;
-	int ret;
-
-	preempt_disable();
-	if (cpu = smp_processor_id()) {
-		ret = wrmsr_eio(reg, eax, edx);
-	} else {
-		cmd.reg = reg;
-		cmd.data[0] = eax;
-		cmd.data[1] = edx;
-
-		smp_call_function_single(cpu, msr_smp_wrmsr, &cmd, 1, 1);
-		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;
-
-	preempt_disable();
-	if (cpu = smp_processor_id()) {
-		ret = rdmsr_eio(reg, eax, edx);
-	} else {
-		cmd.reg = reg;
-
-		smp_call_function_single(cpu, msr_smp_rdmsr, &cmd, 1, 1);
-
-		*eax = cmd.data[0];
-		*edx = cmd.data[1];
-
-		ret = cmd.err;
-	}
-	preempt_enable();
-	return ret;
-}
-
-#else				/* ! CONFIG_SMP */
-
-static inline int do_wrmsr(int cpu, u32 reg, u32 eax, u32 edx)
-{
-	return wrmsr_eio(reg, eax, edx);
-}
-
-static inline int do_rdmsr(int cpu, u32 reg, u32 *eax, u32 *edx)
-{
-	return rdmsr_eio(reg, eax, edx);
-}
-
-#endif				/* ! CONFIG_SMP */
-
 static loff_t msr_seek(struct file *file, loff_t offset, int orig)
 {
 	loff_t ret = -EINVAL;
@@ -174,9 +76,9 @@ static ssize_t msr_read(struct file *file, char __user * buf,
 		return -EINVAL;	/* Invalid chunk size */
 
 	for (; count; count -= 8) {
-		err = do_rdmsr(cpu, reg, &data[0], &data[1]);
+		err = rdmsr_safe_on_cpu(cpu, reg, &data[0], &data[1]);
 		if (err)
-			return err;
+			return -EIO;
 		if (copy_to_user(tmp, &data, 8))
 			return -EFAULT;
 		tmp += 2;
@@ -200,9 +102,9 @@ static ssize_t msr_write(struct file *file, const char __user *buf,
 	for (; count; count -= 8) {
 		if (copy_from_user(&data, tmp, 8))
 			return -EFAULT;
-		err = do_wrmsr(cpu, reg, data[0], data[1]);
+		err = wrmsr_safe_on_cpu(cpu, reg, data[0], data[1]);
 		if (err)
-			return err;
+			return -EIO;
 		tmp += 2;
 	}
 
#2 lore raw

PATCH 1/1 coretemp 1/3 Add rdmsr_safe_on_cpu and

In reply to Rudolf Marek
Quoted 133 lines · Nicolas Boichat

Use safe functions provided by arch/*/lib/msr-on-cpu.c in arch/i386/kernel/msr.c.

Signed-off-by Nicolas Boichat <nicolas at boichat.ch>

---

 arch/i386/kernel/msr.c |  106 ++----------------------------------------------
 1 files changed, 4 insertions(+), 102 deletions(-)
arch/i386/kernel/msr.c +2 -100
index bcaa6e9..8cd0a91 100644
@@ -45,104 +45,6 @@
 
 static struct class *msr_class;
 
-static inline int wrmsr_eio(u32 reg, u32 eax, u32 edx)
-{
-	int err;
-
-	err = wrmsr_safe(reg, eax, edx);
-	if (err)
-		err = -EIO;
-	return err;
-}
-
-static inline int rdmsr_eio(u32 reg, u32 *eax, u32 *edx)
-{
-	int err;
-
-	err = rdmsr_safe(reg, eax, edx);
-	if (err)
-		err = -EIO;
-	return err;
-}
-
-#ifdef CONFIG_SMP
-
-struct msr_command {
-	int err;
-	u32 reg;
-	u32 data[2];
-};
-
-static void msr_smp_wrmsr(void *cmd_block)
-{
-	struct msr_command *cmd = (struct msr_command *)cmd_block;
-
-	cmd->err = wrmsr_eio(cmd->reg, cmd->data[0], cmd->data[1]);
-}
-
-static void msr_smp_rdmsr(void *cmd_block)
-{
-	struct msr_command *cmd = (struct msr_command *)cmd_block;
-
-	cmd->err = rdmsr_eio(cmd->reg, &cmd->data[0], &cmd->data[1]);
-}
-
-static inline int do_wrmsr(int cpu, u32 reg, u32 eax, u32 edx)
-{
-	struct msr_command cmd;
-	int ret;
-
-	preempt_disable();
-	if (cpu = smp_processor_id()) {
-		ret = wrmsr_eio(reg, eax, edx);
-	} else {
-		cmd.reg = reg;
-		cmd.data[0] = eax;
-		cmd.data[1] = edx;
-
-		smp_call_function_single(cpu, msr_smp_wrmsr, &cmd, 1, 1);
-		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;
-
-	preempt_disable();
-	if (cpu = smp_processor_id()) {
-		ret = rdmsr_eio(reg, eax, edx);
-	} else {
-		cmd.reg = reg;
-
-		smp_call_function_single(cpu, msr_smp_rdmsr, &cmd, 1, 1);
-
-		*eax = cmd.data[0];
-		*edx = cmd.data[1];
-
-		ret = cmd.err;
-	}
-	preempt_enable();
-	return ret;
-}
-
-#else				/* ! CONFIG_SMP */
-
-static inline int do_wrmsr(int cpu, u32 reg, u32 eax, u32 edx)
-{
-	return wrmsr_eio(reg, eax, edx);
-}
-
-static inline int do_rdmsr(int cpu, u32 reg, u32 *eax, u32 *edx)
-{
-	return rdmsr_eio(reg, eax, edx);
-}
-
-#endif				/* ! CONFIG_SMP */
-
 static loff_t msr_seek(struct file *file, loff_t offset, int orig)
 {
 	loff_t ret = -EINVAL;
@@ -174,9 +76,9 @@ static ssize_t msr_read(struct file *file, char __user * buf,
 		return -EINVAL;	/* Invalid chunk size */
 
 	for (; count; count -= 8) {
-		err = do_rdmsr(cpu, reg, &data[0], &data[1]);
+		err = rdmsr_safe_on_cpu(cpu, reg, &data[0], &data[1]);
 		if (err)
-			return err;
+			return -EIO;
 		if (copy_to_user(tmp, &data, 8))
 			return -EFAULT;
 		tmp += 2;
@@ -200,9 +102,9 @@ static ssize_t msr_write(struct file *file, const char __user *buf,
 	for (; count; count -= 8) {

arch/i386/kernel/msr.c static ssize_t msr_write(struct file *file, const char __user *buf, · line 110

Quoted 10 lines
arch/i386/kernel/msr.c +2 -2
 		if (copy_from_user(&data, tmp, 8))
 			return -EFAULT;
-		err = do_wrmsr(cpu, reg, data[0], data[1]);
+		err = wrmsr_safe_on_cpu(cpu, reg, data[0], data[1]);
 		if (err)
-			return err;
+			return -EIO;
 		tmp += 2;
 	}
 

Patch looks OK to me.

Acked-by Jean Delvare <khali at linux-fr.org>
Signature · 1 line
Jean Delvare