Subject: port-vax/14614: VAX assembly in vax/in{4,}_cksum.c broken.
To: None <gnats-bugs@gnats.netbsd.org>
From: Rhialto <rhialto@azenomei.knuffel.net>
List: netbsd-bugs
Date: 11/17/2001 15:31:00
>Number:         14614
>Category:       port-vax
>Synopsis:       VAX assembly in vax/in{4,}_cksum.c broken.
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    port-vax-maintainer
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Nov 17 06:32:01 PST 2001
>Closed-Date:
>Last-Modified:
>Originator:     Rhialto
>Release:        <NetBSD-current source date>
>Organization:
	
>Environment:
	
System: NetBSD azenomei.falu.nl 1.5.1_BETA NetBSD 1.5.1_BETA (AZENOMEI) #0: Sun Apr 22 00:38:14 CEST 2001 rhialto@azenomei.falu.nl:/vol1/rhialto/cvs/netbsd-1-5/syssrc/sys/arch/alpha/compile/AZENOMEI alpha

Really, VAX 1.5.2 and -current

>Description:
	The assembly in /sys/arch/vax/vax/in{4,}_cksum.c is broken.
	It fails to specify the side-effect on variable w.
	And if you lie to the compiler, it will get its revenge.
	In this case, when you don't optimize, it will reload w for
	each use and the side-effect will be lost.
>How-To-Repeat:
	Compile a VAX kernel wiþh -O0. All network traffic has incorrect
	checksums now.
>Fix:

Index: in4_cksum.c
===================================================================
RCS file: /cvsroot/syssrc/sys/arch/vax/vax/in4_cksum.c,v
retrieving revision 1.4
diff -u -r1.4 in4_cksum.c
--- in4_cksum.c	2001/05/19 23:47:19	1.4
+++ in4_cksum.c	2001/11/16 02:08:19
@@ -100,8 +100,8 @@
 #define SWAP		{sum <<= 8;}		/* depends on recent REDUCE */
 
 #define Asm     __asm __volatile
-#define ADDL    Asm("addl2 (%2)+,%0" : "=r" (sum) : "0" (sum), "r" (w))
-#define ADWC    Asm("adwc  (%2)+,%0" : "=r" (sum) : "0" (sum), "r" (w))
+#define ADDL    Asm("addl2 (%0)+,%1": "=r" (w), "=r" (sum): "0" (w), "1" (sum))
+#define ADWC    Asm("adwc  (%0)+,%1": "=r" (w), "=r" (sum): "0" (w), "1" (sum))
 #define ADDC    Asm("adwc     $0,%0" : "=r" (sum) : "0" (sum))
 #define UNSWAP  Asm("rotl  $8,%0,%0" : "=r" (sum) : "0" (sum))
 #define ADDBYTE	{sum += *w; SWAP; byte_swapped ^= 1;}
Index: in_cksum.c
===================================================================
RCS file: /cvsroot/syssrc/sys/arch/vax/vax/in_cksum.c,v
retrieving revision 1.5
diff -u -r1.5 in_cksum.c
--- in_cksum.c	2000/06/07 19:31:33	1.5
+++ in_cksum.c	2001/11/16 02:08:19
@@ -56,8 +56,8 @@
 #define SWAP		{sum <<= 8;}		/* depends on recent REDUCE */
 
 #define Asm     __asm __volatile
-#define ADDL    Asm("addl2 (%2)+,%0" : "=r" (sum) : "0" (sum), "r" (w))
-#define ADWC    Asm("adwc  (%2)+,%0" : "=r" (sum) : "0" (sum), "r" (w))
+#define ADDL    Asm("addl2 (%0)+,%1": "=r" (w), "=r" (sum): "0" (w), "1" (sum))
+#define ADWC    Asm("adwc  (%0)+,%1": "=r" (w), "=r" (sum): "0" (w), "1" (sum))
 #define ADDC    Asm("adwc     $0,%0" : "=r" (sum) : "0" (sum))
 #define UNSWAP  Asm("rotl  $8,%0,%0" : "=r" (sum) : "0" (sum))
 #define ADDBYTE	{sum += *w; SWAP; byte_swapped ^= 1;}

-Olaf.
-- 
___ Olaf 'Rhialto' Seibert - rhialto@     --Soep van de dag, wat zal dat zijn
\X/ xs4all.nl --wat kan dat wezen, beter maar het ergste vrezen -Boy Bensdorp
>Release-Note:
>Audit-Trail:
>Unformatted: