Red Hat axp-list: Linux on Alpha (1995-2022)
 help / color / mirror / Atom feed
* alpha patches for 2.1.25
@ 1997-02-06  2:06 Richard Henderson
  0 siblings, 0 replies; only message in thread
From: Richard Henderson @ 1997-02-06  2:06 UTC (permalink / raw)


Here are two patches to get 2.1.25 to build on the Alpha.

 o You cannot xchg to a short on the Alpha, so make
   fs_struct.umask an int.

 o An interim implementation of csum_partial_copy_from_user.
   I am working on an assembly version, but getting that tuned
   and demonstrably correct may take some time.

And on the side I think I found a bug in csum_ipv6_magic.  I did once
get a report that it wasn't working correctly; perhaps this is it.

r~

diff -rup linux-2.1.25/arch/alpha/lib/csum_ipv6_magic.S linux-cur/arch/alpha/lib/csum_ipv6_magic.S
--- linux-2.1.25/arch/alpha/lib/csum_ipv6_magic.S	Sun Nov 10 11:29:33 1996
+++ linux-cur/arch/alpha/lib/csum_ipv6_magic.S	Wed Feb  5 19:16:47 1997
@@ -61,8 +61,8 @@ csum_ipv6_magic:
 	extwl	$0,2,$1		# e0    :
 	zapnot	$0,3,$0		# .. e1 :
 	addq	$0,$1,$0	# e0    :
-	unop			#       :
-	not	$0,$0		# e0    :
+	not	$0,$0		# e1    :
+	zapnot	$0,3,$0		# e0    :
 	ret			# .. e1 :
 
 	.end csum_ipv6_magic
diff -rup linux-2.1.25/arch/alpha/lib/csum_partial_copy.c linux-cur/arch/alpha/lib/csum_partial_copy.c
--- linux-2.1.25/arch/alpha/lib/csum_partial_copy.c	Wed Jul 17 06:39:21 1996
+++ linux-cur/arch/alpha/lib/csum_partial_copy.c	Wed Feb  5 19:36:12 1997
@@ -7,6 +7,11 @@
  * we do for performance..
  */
 
+#include <linux/types.h>
+#include <asm/string.h>
+#include <asm/uaccess.h>
+
+
 #define ldq_u(x,y) \
 __asm__ __volatile__("ldq_u %0,%1":"=r" (x):"m" (*(unsigned long *)(y)))
 
@@ -31,17 +36,52 @@ __asm__ __volatile__("insql %1,%2,%0":"=
 #define insqh(x,y,z) \
 __asm__ __volatile__("insqh %1,%2,%0":"=r" (z):"r" (x),"r" (y))
 
+
+#define __get_user_u(x,ptr)				\
+({							\
+	long __guu_err;					\
+	__asm__ __volatile__(				\
+	"1:	ldq_u %0,%2\n"				\
+	"2:\n"						\
+	".section __ex_table,\"a\"\n"			\
+	"	.gprel32 1b\n"				\
+	"	lda %0,2b-1b(%1)\n"			\
+	".previous"					\
+		: "=r"(x), "=r"(__guu_err)		\
+		: "m"(__m(ptr)), "1"(0));		\
+	__guu_err;					\
+})
+
+#define __put_user_u(x,ptr)				\
+({							\
+	long __puu_err;					\
+	__asm__ __volatile__(				\
+	"1:	stq_u %2,%1\n"				\
+	"2:\n"						\
+	".section __ex_table,\"a\"\n"			\
+	"	.gprel32 1b"				\
+	"	lda $31,2b-1b(%0)\n"			\
+	".previous"					\
+		: "=r"(__puu_err)			\
+		: "m"(__m(addr)), "rJ"(x), "0"(0));	\
+	__puu_err;					\
+})
+
+
 /*
  * Ok. This isn't fun, but this is the EASY case.
  */
-static inline unsigned long csum_partial_copy_aligned(
-	unsigned long *src, unsigned long *dst,
-	long len, unsigned long checksum)
+static inline unsigned long
+csum_partial_cfu_aligned(unsigned long *src, unsigned long *dst,
+			 long len, unsigned long checksum,
+			 int *errp)
 {
 	unsigned long carry = 0;
+	int err = 0;
 
 	while (len >= 0) {
-		unsigned long word = *src;
+		unsigned long word;
+		err |= __get_user(word, src);
 		checksum += carry;
 		src++;
 		checksum += word;
@@ -54,7 +94,7 @@ static inline unsigned long csum_partial
 	checksum += carry;
 	if (len) {
 		unsigned long word, tmp;
-		word = *src;
+		err |= __get_user(word, src);
 		tmp = *dst;
 		mskql(word, len, word);
 		checksum += word;
@@ -63,28 +103,31 @@ static inline unsigned long csum_partial
 		*dst = word | tmp;
 		checksum += carry;
 	}
-	return checksum;	
+	if (err) *errp = err;
+	return checksum;
 }
 
 /*
  * This is even less fun, but this is still reasonably
  * easy.
  */
-static inline unsigned long csum_partial_copy_dest_aligned(
-	unsigned long *src, unsigned long *dst,
-	unsigned long soff,
-	long len, unsigned long checksum)
+static inline unsigned long
+csum_partial_cfu_dest_aligned(unsigned long *src, unsigned long *dst,
+			      unsigned long soff,
+			      long len, unsigned long checksum,
+			      int *errp)
 {
 	unsigned long first;
 	unsigned long word, carry;
 	unsigned long lastsrc = 7+len+(unsigned long)src;
+	int err = 0;
 
-	ldq_u(first,src);
+	err |= __get_user_u(first,src);
 	carry = 0;
 	while (len >= 0) {
 		unsigned long second;
 
-		ldq_u(second, src+1);
+		err |= __get_user_u(second, src+1);
 		extql(first, soff, word);
 		len -= 8;
 		src++;
@@ -102,7 +145,7 @@ static inline unsigned long csum_partial
 	if (len) {
 		unsigned long tmp;
 		unsigned long second;
-		ldq_u(second, lastsrc);
+		err |= __get_user_u(second, lastsrc);
 		tmp = *dst;
 		extql(first, soff, word);
 		extqh(second, soff, first);
@@ -114,25 +157,28 @@ static inline unsigned long csum_partial
 		*dst = word | tmp;
 		checksum += carry;
 	}
+	if (err) *errp = err;
 	return checksum;
 }
 
 /*
  * This is slightly less fun than the above..
  */
-static inline unsigned long csum_partial_copy_src_aligned(
-	unsigned long *src, unsigned long *dst,
-	unsigned long doff,
-	long len, unsigned long checksum,
-	unsigned long partial_dest)
+static inline unsigned long
+csum_partial_cfu_src_aligned(unsigned long *src, unsigned long *dst,
+			     unsigned long doff,
+			     long len, unsigned long checksum,
+			     unsigned long partial_dest,
+			     int *errp)
 {
 	unsigned long carry = 0;
 	unsigned long word;
+	int err = 0;
 
 	mskql(partial_dest, doff, partial_dest);
 	while (len >= 0) {
 		unsigned long second_dest;
-		word = *src;
+		err |= __get_user(word, src);
 		len -= 8;
 		insql(word, doff, second_dest);
 		checksum += carry;
@@ -147,7 +193,7 @@ static inline unsigned long csum_partial
 	checksum += carry;
 	if (len >= 0) {
 		unsigned long second_dest;
-		word = *src;
+		err |= __get_user(word, src);
 		mskql(word, len-doff, word);
 		checksum += word;
 		insql(word, doff, second_dest);
@@ -162,7 +208,7 @@ static inline unsigned long csum_partial
 		checksum += carry;
 	} else if (len & 7) {
 		unsigned long second_dest;
-		word = *src;
+		err |= __get_user(word, src);
 		ldq_u(second_dest, dst);
 		mskql(word, len-doff, word);
 		checksum += word;
@@ -172,6 +218,7 @@ static inline unsigned long csum_partial
 		stq_u(partial_dest | word | second_dest, dst);
 		checksum += carry;
 	}
+	if (err) *errp = err;
 	return checksum;
 }
 
@@ -179,24 +226,26 @@ static inline unsigned long csum_partial
  * This is so totally un-fun that it's frightening. Don't
  * look at this too closely, you'll go blind.
  */
-static inline unsigned long csum_partial_copy_unaligned(
-	unsigned long * src, unsigned long * dst,
-	unsigned long soff, unsigned long doff,
-	long len, unsigned long checksum,
-	unsigned long partial_dest)
+static inline unsigned long
+csum_partial_cfu_unaligned(unsigned long * src, unsigned long * dst,
+			   unsigned long soff, unsigned long doff,
+			   long len, unsigned long checksum,
+			   unsigned long partial_dest,
+			   int *errp)
 {
 	unsigned long carry = 0;
 	unsigned long first;
 	unsigned long lastsrc;
+	int err = 0;
 
-	ldq_u(first, src);
+	err |= __get_user_u(first, src);
 	lastsrc = 7+len+(unsigned long)src;
 	mskql(partial_dest, doff, partial_dest);
 	while (len >= 0) {
 		unsigned long second, word;
 		unsigned long second_dest;
 
-		ldq_u(second, src+1);
+		err |= __get_user_u(second, src+1);
 		extql(first, soff, word);
 		checksum += carry;
 		len -= 8;
@@ -216,8 +265,8 @@ static inline unsigned long csum_partial
 	if (len >= 0) {
 		unsigned long second, word;
 		unsigned long second_dest;
-		
-		ldq_u(second, lastsrc);
+
+		err |= __get_user_u(second, lastsrc);
 		extql(first, soff, word);
 		extqh(second, soff, first);
 		word |= first;
@@ -233,12 +282,12 @@ static inline unsigned long csum_partial
 			mskqh(second_dest, len, second_dest);
 			stq_u(partial_dest | second_dest, dst+1);
 		}
-		checksum += carry;			
+		checksum += carry;
 	} else if (len & 7) {
 		unsigned long second, word;
 		unsigned long second_dest;
 
-		ldq_u(second, lastsrc);
+		err |= __get_user_u(second, lastsrc);
 		extql(first, soff, word);
 		extqh(second, soff, first);
 		word |= first;
@@ -251,42 +300,51 @@ static inline unsigned long csum_partial
 		stq_u(partial_dest | word | second_dest, dst);
 		checksum += carry;
 	}
+	if (err) *errp = err;
 	return checksum;
 }
 
-unsigned int csum_partial_copy(char *src, char *dst, int len, int sum)
+unsigned int
+csum_partial_copy_from_user(int *errp, char *src, char *dst,
+			    int len, unsigned int sum)
 {
 	unsigned long checksum = (unsigned) sum;
 	unsigned long soff = 7 & (unsigned long) src;
 	unsigned long doff = 7 & (unsigned long) dst;
 
+	if (!access_ok(src, len, VERIFY_READ)) {
+		*errp = -EFAULT;
+		memset(dst, 0, len);
+		return checksum;
+	}
+
 	if (len) {
 		if (!doff) {
 			if (!soff)
-				checksum = csum_partial_copy_aligned(
+				checksum = csum_partial_cfu_aligned(
 					(unsigned long *) src,
 					(unsigned long *) dst,
-					len-8, checksum);
+					len-8, checksum, errp);
 			else
-				checksum = csum_partial_copy_dest_aligned(
+				checksum = csum_partial_cfu_dest_aligned(
 					(unsigned long *) src,
 					(unsigned long *) dst,
-					soff, len-8, checksum);
+					soff, len-8, checksum, errp);
 		} else {
 			unsigned long partial_dest;
 			ldq_u(partial_dest, dst);
 			if (!soff)
-				checksum = csum_partial_copy_src_aligned(
+				checksum = csum_partial_cfu_src_aligned(
 					(unsigned long *) src,
 					(unsigned long *) dst,
 					doff, len-8, checksum,
-					partial_dest);
+					partial_dest, errp);
 			else
-				checksum = csum_partial_copy_unaligned(
+				checksum = csum_partial_cfu_unaligned(
 					(unsigned long *) src,
 					(unsigned long *) dst,
 					soff, doff, len-8, checksum,
-					partial_dest);
+					partial_dest, errp);
 		}
 		/* 64 -> 33 bits */
 		checksum = (checksum & 0xffffffff) + (checksum >> 32);
@@ -297,4 +355,17 @@ unsigned int csum_partial_copy(char *src
 		checksum = (checksum & 0xffff) + (checksum >> 16);
 	}
 	return checksum;
+}
+
+unsigned int
+csum_partial_copy (const char *src, char *dst, int len, unsigned int sum)
+{
+	unsigned int ret;
+	int error = 0;
+
+	ret = csum_partial_copy_from_user(&error, src, dst, len, sum);
+	if (error)
+		printk("csum_partial_copy_old(): tell mingo to convert me!\n");
+
+	return ret;
 }
diff -rup linux-2.1.25/include/asm-alpha/checksum.h linux-cur/include/asm-alpha/checksum.h
--- linux-2.1.25/include/asm-alpha/checksum.h	Sat Nov 23 04:29:03 1996
+++ linux-cur/include/asm-alpha/checksum.h	Wed Feb  5 19:19:42 1997
@@ -44,9 +44,16 @@ unsigned int csum_partial_copy(const cha
 /*
  * the same as csum_partial, but copies from user space (but on the alpha
  * we have just one address space, so this is identical to the above)
+ *
+ * this is obsolete and will go away.
  */
 #define csum_partial_copy_fromuser csum_partial_copy
 
+/*
+ * this is a new version of the above that records errors it finds in *errp,
+ * but continues and zeros the rest of the buffer.
+ */
+unsigned int csum_partial_copy_from_user(int *errp, char *src, char *dst, int len, unsigned int sum);
 
 /*
  * this routine is used for miscellaneous IP-like checksums, mainly
diff -rup linux-2.1.25/include/linux/sched.h linux-cur/include/linux/sched.h
--- linux-2.1.25/include/linux/sched.h	Wed Feb  5 19:48:19 1997
+++ linux-cur/include/linux/sched.h	Wed Feb  5 19:22:23 1997
@@ -127,7 +127,7 @@ struct files_struct {
 
 struct fs_struct {
 	int count;
-	unsigned short umask;
+	int umask;
 	struct inode * root, * pwd;
 };
 

--
To unsubscribe: send e-mail to axp-list-request@redhat.com with
'unsubscribe' as the subject.  Do not send it to axp-list@redhat.com

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~1997-02-06  2:06 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1997-02-06  2:06 alpha patches for 2.1.25 Richard Henderson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox