Skip to contentSkip to conversation

asm-generic fixes

GIT PULL Arnd Bergmann 2 participants 3 messages Jun 23, 2009

Subsystems (2)
lore
Share & tools
lore

Arnd Bergmann

author maintainer
#0 lore raw

Hi Linus,

Please pull this set of fixes for include/asm-generic and the checksum code from

git://git.kernel.org:/pub/scm/linux/kernel/git/arnd/asm-generic.git for-linus

---
Arnd Bergmann (4):
asm-generic: drop HARDIRQ_BITS definition from hardirq.h
asm-generic: list Arnd as asm-generic maintainer
asm-generic: hook up new system calls lib/checksum.c: fix endianess bug

Mike Frysinger (2):
asm-generic: uaccess: add missing access_ok() check to strnlen_user()
asm-generic: uaccess: fix up local access_ok() usage

Paul Mundt (1):
asm-generic: add dummy pgprot_noncached()

 MAINTAINERS                   |    8 ++++++++
 include/asm-generic/hardirq.h |   13 -------------
 include/asm-generic/pgtable.h |    4 ++++
 include/asm-generic/uaccess.h |   14 ++++++++------
 include/asm-generic/unistd.h  |    7 ++++++-
 lib/checksum.c                |   10 +++++++++-
 6 files changed, 35 insertions(+), 21 deletions(-)
MAINTAINERS +8 -0
index 02f6f78..b85cf35 100644
@@ -2482,6 +2482,14 @@ F:	drivers/net/wan/pc300too.c
 F:	drivers/net/wan/pci200syn.c
 F:	drivers/net/wan/wanxl*
 
+GENERIC INCLUDE/ASM HEADER FILES
+P:	Arnd Bergmann
+M:	[email protected]
+L:	[email protected]
+T:	git git://git.kernel.org/pub/scm/linux/kernel/git/arnd/asm-generic.git
+S:	Maintained
+F:	include/asm-generic
+
 GFS2 FILE SYSTEM
 P:	Steven Whitehouse
 M:	[email protected]
include/asm-generic/hardirq.h +0 -13
index 3d5d2c9..23bb4da 100644
@@ -11,19 +11,6 @@ typedef struct {
 
 #include <linux/irq_cpustat.h>	/* Standard mappings for irq_cpustat_t above */
 
-#ifndef HARDIRQ_BITS
-#define HARDIRQ_BITS	8
-#endif
-
-/*
- * The hardirq mask has to be large enough to have
- * space for potentially all IRQ sources in the system
- * nesting on a single CPU:
- */
-#if (1 << HARDIRQ_BITS) < NR_IRQS
-# error HARDIRQ_BITS is too low!
-#endif
-
 #ifndef ack_bad_irq
 static inline void ack_bad_irq(unsigned int irq)
 {
include/asm-generic/pgtable.h +4 -0
index e410f60..e2bd73e 100644
@@ -129,6 +129,10 @@ static inline void ptep_set_wrprotect(struct mm_struct *mm, unsigned long addres
 #define move_pte(pte, prot, old_addr, new_addr)	(pte)
 #endif
 
+#ifndef pgprot_noncached
+#define pgprot_noncached(prot)	(prot)
+#endif
+
 #ifndef pgprot_writecombine
 #define pgprot_writecombine pgprot_noncached
 #endif
include/asm-generic/uaccess.h +8 -6
index 6d8cab2..b218b85 100644
@@ -163,7 +163,7 @@ static inline __must_check long __copy_to_user(void __user *to,
 #define put_user(x, ptr)					\
 ({								\
 	might_sleep();						\
-	__access_ok(ptr, sizeof (*ptr)) ?			\
+	access_ok(VERIFY_WRITE, ptr, sizeof(*ptr)) ?		\
 		__put_user(x, ptr) :				\
 		-EFAULT;					\
 })
@@ -219,7 +219,7 @@ extern int __put_user_bad(void) __attribute__((noreturn));
 #define get_user(x, ptr)					\
 ({								\
 	might_sleep();						\
-	__access_ok(ptr, sizeof (*ptr)) ?			\
+	access_ok(VERIFY_READ, ptr, sizeof(*ptr)) ?		\
 		__get_user(x, ptr) :				\
 		-EFAULT;					\
 })
@@ -244,7 +244,7 @@ static inline long copy_from_user(void *to,
 		const void __user * from, unsigned long n)
 {
 	might_sleep();
-	if (__access_ok(from, n))
+	if (access_ok(VERIFY_READ, from, n))
 		return __copy_from_user(to, from, n);
 	else
 		return n;
@@ -254,7 +254,7 @@ static inline long copy_to_user(void __user *to,
 		const void *from, unsigned long n)
 {
 	might_sleep();
-	if (__access_ok(to, n))
+	if (access_ok(VERIFY_WRITE, to, n))
 		return __copy_to_user(to, from, n);
 	else
 		return n;
@@ -278,7 +278,7 @@ __strncpy_from_user(char *dst, const char __user *src, long count)
 static inline long
 strncpy_from_user(char *dst, const char __user *src, long count)
 {
-	if (!__access_ok(src, 1))
+	if (!access_ok(VERIFY_READ, src, 1))
 		return -EFAULT;
 	return __strncpy_from_user(dst, src, count);
 }
@@ -291,6 +291,8 @@ strncpy_from_user(char *dst, const char __user *src, long count)
 #ifndef strnlen_user
 static inline long strnlen_user(const char __user *src, long n)
 {
+	if (!access_ok(VERIFY_READ, src, 1))
+		return 0;
 	return strlen((void * __force)src) + 1;
 }
 #endif
@@ -316,7 +318,7 @@ static inline __must_check unsigned long
 clear_user(void __user *to, unsigned long n)
 {
 	might_sleep();
-	if (!__access_ok(to, n))
+	if (!access_ok(VERIFY_WRITE, to, n))
 		return n;
 
 	return __clear_user(to, n);
include/asm-generic/unistd.h +6 -1
index 5b34b62..1125e5a 100644
@@ -618,8 +618,13 @@ __SYSCALL(__NR_migrate_pages, sys_migrate_pages)
 __SYSCALL(__NR_move_pages, sys_move_pages)
 #endif
 
+#define __NR_rt_tgsigqueueinfo 240
+__SYSCALL(__NR_rt_tgsigqueueinfo, sys_rt_tgsigqueueinfo)
+#define __NR_perf_counter_open 241
+__SYSCALL(__NR_perf_counter_open, sys_perf_counter_open)
+
 #undef __NR_syscalls
-#define __NR_syscalls 240
+#define __NR_syscalls 242
 
 /*
  * All syscalls below here should go away really,
lib/checksum.c +9 -1
index 12e5a1c..b2e2fd4 100644
@@ -55,7 +55,11 @@ static unsigned int do_csum(const unsigned char *buff, int len)
 		goto out;
 	odd = 1 & (unsigned long) buff;
 	if (odd) {
+#ifdef __LITTLE_ENDIAN
 		result = *buff;
+#else
+		result += (*buff << 8);
+#endif
 		len--;
 		buff++;
 	}
@@ -71,7 +75,7 @@ static unsigned int do_csum(const unsigned char *buff, int len)
 		if (count) {
 			unsigned long carry = 0;
 			do {
-				unsigned long w = *(unsigned long *) buff;
+				unsigned long w = *(unsigned int *) buff;
 				count--;
 				buff += 4;
 				result += carry;
@@ -87,7 +91,11 @@ static unsigned int do_csum(const unsigned char *buff, int len)
 		}
 	}
 	if (len & 1)
+#ifdef __LITTLE_ENDIAN
+		result += *buff;
+#else
 		result += (*buff << 8);
+#endif
 	result = from32to16(result);
 	if (odd)
 		result = ((result >> 8) & 0xff) | ((result & 0xff) << 8);
#1 lore raw

lib/checksum.c static unsigned int do_csum(const unsigned char *buff, int len) · line 81

Quoted 9 lines · Arnd Bergmann
lib/checksum.c +1 -1
@@ -71,7 +75,7 @@ static unsigned int do_csum(const unsigned char *buff, int len)
 		if (count) {
 			unsigned long carry = 0;
 			do {
-				unsigned long w = *(unsigned long *) buff;
+				unsigned long w = *(unsigned int *) buff;
 				count--;
 				buff += 4;
 				result += carry;

I don't think this is sufficient.

You might need to make 'result', 'carry', and 'w' be 'unsigned int' too.

Why? Because the final folding is only doen from 32-bit to 16 bit, we don't do the whole 64-bit to 32-bit to 16-bit chain.

Now, it's possible (even likely) that even with a 64-bit word, we'll never actually do large enough areas that 'result' would ever have very many bits set in the 32+ bit region, and since we do end up folding to 16 bits twice (once after the loop and once at the end), it _probably_ gets things right in most cases. But I doubt "probably" is strong enough. Somebody should check.

Or just see arch/alpha/lib/checksum.c, which does the whole 64-bit case. Maybe lib/checksum.c should be lib/checksum_{32,64}.c.

Linus

author maintainer
#2 lore raw
Quoted 1 line · Linus Torvalds

You might need to make 'result', 'carry', and 'w' be 'unsigned int' too.

Yes, you're right.

Quoted 6 lines

Now, it's possible (even likely) that even with a 64-bit word, we'll never actually do large enough areas that 'result' would ever have very many bits set in the 32+ bit region, and since we do end up folding to 16 bits twice (once after the loop and once at the end), it probably gets things right in most cases. But I doubt "probably" is strong enough. Somebody should check.

I think it would overrun only if we have more than 65536 u32 words of 0xffffffff in a single IP packet, on a 64 bit machine. A more obvious reason to change it is that it relies on from32to16() actually behaving like a from47to16() function on 64-bit. Changing it to use unsigned int throughout makes it both more obvious and more consistent between 32 and 64 bit unsigned long types.

Quoted 2 lines

Or just see arch/alpha/lib/checksum.c, which does the whole 64-bit case. Maybe lib/checksum.c should be lib/checksum_{32,64}.c.

Mike Frysinger earlier suggested just making the do_csum function optional in this file because this is the one that most architectures would override.

The alpha code is the only 64-bit platform implementing do_csum in C, so if Richard wants to use the generic code in its current form, he could simply override the do_csum implementation.

I've now added these two patches:

commit 217a8c7b6af924379a2083439b4bb606f332e7b1

Author: Arnd Bergmann <[email protected]>
Date:   Tue Jun 23 21:37:26 2009 +0200

lib/checksum.c: make do_csum optional

Mike Frysinger suggested that do_csum should be optional so that an architecture can use the generic checksum code but still provide an optimized fast-path for the most critical function.

This can mean an implementation using inline assembly, or in case of Alpha one using 64-bit arithmetic in C.

lib/checksum.c +2 -0
index 886b48d..b08c2d0 100644
@@ -37,6 +37,7 @@
 
 #include <asm/byteorder.h>
 
+#ifndef do_csum
 static inline unsigned short from32to16(unsigned int x)
 {
 	/* add up 16-bit and 16-bit for 16+c bit */
@@ -102,6 +103,7 @@ static unsigned int do_csum(const unsigned char *buff, int len)
 out:
 	return result;
 }
+#endif
 
 /*
  *	This is a version of ip_compute_csum() optimized for IP headers,

commit 5cb59758c3e2170b24e9c0d659eb6c03872155c0

Author: Arnd Bergmann <[email protected]>
Date:   Tue Jun 23 21:22:58 2009 +0200

lib/checksum.c: use 32-bit arithmetic consistently

The use of 'unsigned long' variables in the 32-bit part of do_csum() is confusing at best, and potentially broken for long input on 64-bit machines.

This changes the code to use 'unsigned int' instead, which makes the code behave in the same (correct) way on both 32 and 64 bit machines.

lib/checksum.c +4 -4
index b2e2fd4..886b48d 100644
@@ -37,7 +37,7 @@
 
 #include <asm/byteorder.h>
 
-static inline unsigned short from32to16(unsigned long x)
+static inline unsigned short from32to16(unsigned int x)
 {
 	/* add up 16-bit and 16-bit for 16+c bit */
 	x = (x & 0xffff) + (x >> 16);
@@ -49,7 +49,7 @@ static inline unsigned short from32to16(unsigned long x)
 static unsigned int do_csum(const unsigned char *buff, int len)
 {
 	int odd, count;
-	unsigned long result = 0;
+	unsigned int result = 0;
 
 	if (len <= 0)
 		goto out;
@@ -73,9 +73,9 @@ static unsigned int do_csum(const unsigned char *buff, int len)
 		}
 		count >>= 1;		/* nr of 32-bit words.. */
 		if (count) {
-			unsigned long carry = 0;
+			unsigned int carry = 0;
 			do {
-				unsigned long w = *(unsigned int *) buff;
+				unsigned int w = *(unsigned int *) buff;
 				count--;
 				buff += 4;
 				result += carry;