All of lore.kernel.org
 help / color / mirror / Atom feed
From: Arnd Bergmann <arnd@arndb.de>
To: Mike Frysinger <vapier.adi@gmail.com>
Cc: linux-kernel@vger.kernel.org,
	uclinux-dist-devel@blackfin.uclinux.org,
	Michal Simek <monstr@monstr.eu>, Paul Mundt <lethal@linux-sh.org>
Subject: Re: [PATCH 05/17] Blackfin: convert to generic checksum code
Date: Fri, 19 Jun 2009 14:33:33 +0200	[thread overview]
Message-ID: <200906191433.34608.arnd@arndb.de> (raw)
In-Reply-To: <8bd0f97a0906190342s4261e85di9aa746058cbef9be@mail.gmail.com>

On Friday 19 June 2009, Mike Frysinger wrote:
> On Fri, Jun 19, 2009 at 05:05, Arnd Bergmann wrote:
> > x86 and blackfin are both little-endian, so your variant is correct
> > there. They add the 0x01 to the low byte of the 16-bit word, while
> > on big-endian machines, you have to add it to the high byte.
> 
> can we think of enough simple examples to through together an optional
> boot-time self test ?

sounds like a good idea.

> > I've committed the patch below now.
> 
> closer, but not quite just yet ...
> do_csum: mismatch 0x1700 != 0xa0d len:2
> do_csum: {  0xd, 0xa }

I've compared the code again with Paul's sh version and found another
difference in the handling of unaligned data.

> when do_csum does return correct values, csum_partial sometimes does not:
> csum_partial: mismatch 0x1101eefe != 0xffff len:32
> csum_partial: {  0x92, 0x3b, 0x0, 0x17, 0xcf, 0xc1, 0x90, 0xec, 0x1c,
> 0x3f, 0xff, 0x99, 0x80, 0x10, 0x0, 0x5c, 0x22, 0xfa, 0x0, 0x0, 0x1,
> 0x1, 0x8, 0xa, 0x6, 0x83, 0xdd, 0x50, 0xff, 0xfe, 0xdf, 0x58 }

That looks like it's both valid output. csum_partial returns a 32 bit
value that always needs to get passed to csum_fold in order to get
checked. 0x1101eefe and 0xffff both evaluate to 0xffff in csum_fold,
so this would just be an implementation detail, not a bug.

> btw, would it make sense to change do_csum like so:
> -static unsigned int do_csum(const unsigned char *buff, int len)
> +__weak unsigned int do_csum(const unsigned char *buff, int len)
> 
> after all, it looks like that's really the function most arches would
> want to hand optimize.  all the rest are simple standard wrappers are
> do_csum().  forcing an arch to copy & paste all the other functions
> just so they can implement an optimized do_csum() seems pretty
> unfriendly.  plus, it isnt like being static here makes any optimized
> difference -- it isnt going to get inlined anywhere in this file.

Agreed, this should be overridable by the architecture, I'll submit a patch
once we found out what caused the bugs.

> or rather than weaks (in case some toolchains force indirect pointer
> loading all the time), use the same interface as the rest of the
> generic checksum code:
> #ifndef do_csum
> static inline unsigned short from32to16(unsigned long x)
> {
>     ...
> }
> static unsigned int do_csum(const unsigned char *buff, int len)
> {
>     ...
> }
> #endif

I'd prefer the second version, I've done it that way all over
include/asm-generic, and weak functions tend to cause more trouble.

---
lib/checksum.c: Fix another endianess bug

will fold this patch into the previous one.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
--- a/lib/checksum.c
+++ b/lib/checksum.c
@@ -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++;
 	}

  reply	other threads:[~2009-06-19 12:35 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-06-14 12:01 [PATCH 00/17] Blackfin arch conversion to asm-generic Mike Frysinger
2009-06-14 12:01 ` [PATCH 01/17] Blackfin: use common test_bit() rather than __test_bit() Mike Frysinger
2009-06-14 12:01 ` [PATCH 02/17] Blackfin: pull in asm/io.h in ksyms for prototypes Mike Frysinger
2009-06-14 12:01 ` [PATCH 03/17] Blackfin: only build irqpanic.c when needed Mike Frysinger
2009-06-14 12:01 ` [PATCH 04/17] Blackfin: convert asm/ioctls.h to asm-generic/ioctls.h Mike Frysinger
2009-06-14 12:01 ` [PATCH 05/17] Blackfin: convert to generic checksum code Mike Frysinger
2009-06-15 11:04   ` Arnd Bergmann
2009-06-16 10:03     ` Mike Frysinger
2009-06-19  1:19     ` Mike Frysinger
2009-06-19  9:05       ` Arnd Bergmann
2009-06-19 10:42         ` Mike Frysinger
2009-06-19 12:33           ` Arnd Bergmann [this message]
2009-06-19 13:12             ` Mike Frysinger
2009-06-23 21:14               ` Arnd Bergmann
2009-06-23 21:53                 ` Mike Frysinger
2009-06-23 22:06                   ` Arnd Bergmann
2009-06-23 22:11                     ` Mike Frysinger
2009-09-19 19:08                 ` Mike Frysinger
2009-06-14 12:01 ` [PATCH 06/17] Blackfin: convert shm/sysv/ipc to asm-generic Mike Frysinger
2009-06-14 12:01 ` [PATCH 07/17] Blackfin: convert user/elf " Mike Frysinger
2009-06-14 12:01 ` [PATCH 08/17] Blackfin: convert socket/poll " Mike Frysinger
2009-06-14 12:01 ` [PATCH 09/17] Blackfin: convert simple headers " Mike Frysinger
2009-06-14 12:01 ` [PATCH 10/17] Blackfin: convert dma/pci " Mike Frysinger
2009-06-15 11:37   ` Arnd Bergmann
2009-06-16 10:00     ` Mike Frysinger
2009-06-14 12:01 ` [PATCH 11/17] Blackfin: convert termios " Mike Frysinger
2009-06-14 12:01 ` [PATCH 12/17] Blackfin: convert locking primitives " Mike Frysinger
2009-06-14 12:01 ` [PATCH 13/17] Blackfin: convert signal/mmap " Mike Frysinger
2009-06-14 12:01 ` [PATCH 14/17] Blackfin: convert irq/process " Mike Frysinger
2009-06-14 12:01 ` [PATCH 15/17] Blackfin: convert types " Mike Frysinger
2009-06-14 12:01 ` [PATCH 16/17] Blackfin: convert page/tlb " Mike Frysinger
2009-06-14 12:01 ` [PATCH 17/17] Blackfin: convert uaccess " Mike Frysinger
2009-06-15 11:42 ` [PATCH 00/17] Blackfin arch conversion " Arnd Bergmann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200906191433.34608.arnd@arndb.de \
    --to=arnd@arndb.de \
    --cc=lethal@linux-sh.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=monstr@monstr.eu \
    --cc=uclinux-dist-devel@blackfin.uclinux.org \
    --cc=vapier.adi@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.