Skip to contentSkip to conversation

x86, msr: define msr chunksize

PATCH In review Fabian Frederick 2 participants 2 messages Oct 17, 2014

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/4 x86, msr: define msr chunksize

define MSR_CHUNK_SIZE instead of hard-coded value (8).

---
 arch/x86/include/asm/msr.h |  2 ++
 arch/x86/kernel/msr.c      | 18 +++++++++---------
 2 files changed, 11 insertions(+), 9 deletions(-)
arch/x86/include/asm/msr.h +2 -0
index de36f22..f28a5a2 100644
@@ -39,6 +39,8 @@ static inline unsigned long long native_read_tscp(unsigned int *aux)
 	return low | ((u64)high << 32);
 }
 
+#define MSR_CHUNK_SIZE 8
+
 /*
  * both i386 and x86_64 returns 64-bit value in edx:eax, but gcc's "A"
  * constraint has different meanings. For i386, "A" means exactly
arch/x86/kernel/msr.c +9 -9
index c9603ac..f1f3ed0 100644
@@ -75,19 +75,19 @@ static ssize_t msr_read(struct file *file, char __user *buf,
 	int err = 0;
 	ssize_t bytes = 0;
 
-	if (count % 8)
+	if (count % MSR_CHUNK_SIZE)
 		return -EINVAL;	/* Invalid chunk size */
 
-	for (; count; count -= 8) {
+	for (; count; count -= MSR_CHUNK_SIZE) {
 		err = rdmsr_safe_on_cpu(cpu, reg, &data[0], &data[1]);
 		if (err)
 			break;
-		if (copy_to_user(tmp, &data, 8)) {
+		if (copy_to_user(tmp, &data, MSR_CHUNK_SIZE)) {
 			err = -EFAULT;
 			break;
 		}
 		tmp += 2;
-		bytes += 8;
+		bytes += MSR_CHUNK_SIZE;
 	}
 
 	return bytes ? bytes : err;
@@ -103,11 +103,11 @@ static ssize_t msr_write(struct file *file, const char __user *buf,
 	int err = 0;
 	ssize_t bytes = 0;
 
-	if (count % 8)
+	if (count % MSR_CHUNK_SIZE)
 		return -EINVAL;	/* Invalid chunk size */
 
-	for (; count; count -= 8) {
-		if (copy_from_user(&data, tmp, 8)) {
+	for (; count; count -= MSR_CHUNK_SIZE) {
+		if (copy_from_user(&data, tmp, MSR_CHUNK_SIZE)) {
 			err = -EFAULT;
 			break;
 		}
@@ -115,7 +115,7 @@ static ssize_t msr_write(struct file *file, const char __user *buf,
 		if (err)
 			break;
 		tmp += 2;
-		bytes += 8;
+		bytes += MSR_CHUNK_SIZE;
 	}
 
 	return bytes ? bytes : err;
@@ -124,7 +124,7 @@ static ssize_t msr_write(struct file *file, const char __user *buf,
 static long msr_ioctl(struct file *file, unsigned int ioc, unsigned long arg)
 {
 	u32 __user *uregs = (u32 __user *)arg;
-	u32 regs[8];
+	u32 regs[MSR_CHUNK_SIZE];
 	int cpu = iminor(file_inode(file));
 	int err;
 
Signature · 1 line
1.9.3
maintainer
#1 lore raw
Quoted 3 lines · Fabian Frederick

define MSR_CHUNK_SIZE instead of hard-coded value (8).

I don't like the name, as it isn't a "chunk" but the actual width of an MSR.

Furthermore, the last hunk is just plain wrong; the 8 there refers to the number of registers and not to the width of an MSR.

-hpa