Skip to content

Commit

Permalink
unify generic instances of csum_partial_copy_nocheck()
Browse files Browse the repository at this point in the history
quite a few architectures have the same csum_partial_copy_nocheck() -
simply memcpy() the data and then return the csum of the copy.

hexagon, parisc, ia64, s390, um: explicitly spelled out that way.

arc, arm64, csky, h8300, m68k/nommu, microblaze, mips/GENERIC_CSUM, nds32,
nios2, openrisc, riscv, unicore32: end up picking the same thing spelled
out in lib/checksum.h (with varying amounts of perversions along the way).

everybody else (alpha, arm, c6x, m68k/mmu, mips/!GENERIC_CSUM, powerpc,
sh, sparc, x86, xtensa) have non-generic variants.  For all except c6x
the declaration is in their asm/checksum.h.  c6x uses the wrapper
from asm-generic/checksum.h that would normally lead to the lib/checksum.h
instance, but in case of c6x we end up using an asm function from arch/c6x
instead.

Screw that mess - have architectures with private instances define
_HAVE_ARCH_CSUM_AND_COPY in their asm/checksum.h and have the default
one right in net/checksum.h conditional on _HAVE_ARCH_CSUM_AND_COPY
*not* defined.

Signed-off-by: Al Viro <[email protected]>
  • Loading branch information
Al Viro committed Aug 20, 2020
1 parent 3ea7ca8 commit 6e41c58
Show file tree
Hide file tree
Showing 22 changed files with 21 additions and 116 deletions.
1 change: 1 addition & 0 deletions arch/alpha/include/asm/checksum.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ extern __wsum csum_partial(const void *buff, int len, __wsum sum);
* better 64-bit) boundary
*/
#define _HAVE_ARCH_COPY_AND_CSUM_FROM_USER
#define _HAVE_ARCH_CSUM_AND_COPY
__wsum csum_and_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *errp);

__wsum csum_partial_copy_nocheck(const void *src, void *dst, int len, __wsum sum);
Expand Down
1 change: 1 addition & 0 deletions arch/arm/include/asm/checksum.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ __wsum
csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);

#define _HAVE_ARCH_COPY_AND_CSUM_FROM_USER
#define _HAVE_ARCH_CSUM_AND_COPY
static inline
__wsum csum_and_copy_from_user (const void __user *src, void *dst,
int len, __wsum sum, int *err_ptr)
Expand Down
3 changes: 3 additions & 0 deletions arch/c6x/include/asm/checksum.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ csum_tcpudp_nofold(__be32 saddr, __be32 daddr, __u32 len,
}
#define csum_tcpudp_nofold csum_tcpudp_nofold

#define _HAVE_ARCH_CSUM_AND_COPY
extern __wsum csum_partial_copy_nocheck(const void *src, void *dst, int len, __wsum sum);

#include <asm-generic/checksum.h>

#endif /* _ASM_C6X_CHECKSUM_H */
11 changes: 0 additions & 11 deletions arch/hexagon/include/asm/checksum.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,6 @@
#define do_csum do_csum
unsigned int do_csum(const void *voidptr, int len);

/*
* the same as csum_partial, but copies from src while it
* checksums
*
* here even more important to align src and dst on a 32-bit (or even
* better 64-bit) boundary
*/
#define csum_partial_copy_nocheck csum_partial_copy_nocheck
__wsum csum_partial_copy_nocheck(const void *src, void *dst,
int len, __wsum sum);

/*
* computes the checksum of the TCP/UDP pseudo-header
* returns a 16-bit checksum, already complemented
Expand Down
11 changes: 0 additions & 11 deletions arch/hexagon/lib/checksum.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,14 +176,3 @@ unsigned int do_csum(const void *voidptr, int len)

return 0xFFFF & sum0;
}

/*
* copy from ds while checksumming, otherwise like csum_partial
*/
__wsum
csum_partial_copy_nocheck(const void *src, void *dst, int len, __wsum sum)
{
memcpy(dst, src, len);
return csum_partial(dst, len, sum);
}
EXPORT_SYMBOL(csum_partial_copy_nocheck);
3 changes: 0 additions & 3 deletions arch/ia64/include/asm/checksum.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ extern __wsum csum_tcpudp_nofold(__be32 saddr, __be32 daddr,
*/
extern __wsum csum_partial(const void *buff, int len, __wsum sum);

extern __wsum csum_partial_copy_nocheck(const void *src, void *dst,
int len, __wsum sum);

/*
* This routine is used for miscellaneous IP-like checksums, mainly in
* icmp.c
Expand Down
15 changes: 0 additions & 15 deletions arch/ia64/lib/csum_partial_copy.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,18 +96,3 @@ unsigned long do_csum_c(const unsigned char * buff, int len, unsigned int psum)
out:
return result;
}

/*
* XXX Fixme
*
* This is very ugly but temporary. THIS NEEDS SERIOUS ENHANCEMENTS.
* But it's very tricky to get right even in C.
*/
__wsum
csum_partial_copy_nocheck(const void *src, void *dst, int len, __wsum sum)
{
memcpy(dst, src, len);
return csum_partial(dst, len, sum);
}

EXPORT_SYMBOL(csum_partial_copy_nocheck);
1 change: 1 addition & 0 deletions arch/m68k/include/asm/checksum.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ __wsum csum_partial(const void *buff, int len, __wsum sum);
*/

#define _HAVE_ARCH_COPY_AND_CSUM_FROM_USER
#define _HAVE_ARCH_CSUM_AND_COPY
extern __wsum csum_and_copy_from_user(const void __user *src,
void *dst,
int len, __wsum sum,
Expand Down
2 changes: 1 addition & 1 deletion arch/mips/include/asm/checksum.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ __wsum csum_and_copy_to_user(const void *src, void __user *dst, int len,
* the same as csum_partial, but copies from user space (but on MIPS
* we have just one address space, so this is identical to the above)
*/
#define _HAVE_ARCH_CSUM_AND_COPY
__wsum csum_partial_copy_nocheck(const void *src, void *dst,
int len, __wsum sum);
#define csum_partial_copy_nocheck csum_partial_copy_nocheck

/*
* Fold a partial checksum without adding pseudo headers
Expand Down
4 changes: 0 additions & 4 deletions arch/nios2/include/asm/checksum.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@

/* Take these from lib/checksum.c */
extern __wsum csum_partial(const void *buff, int len, __wsum sum);
__wsum csum_partial_copy_nocheck(const void *src, void *dst, int len,
__wsum sum);
#define csum_partial_copy_nocheck csum_partial_copy_nocheck

extern __sum16 ip_fast_csum(const void *iph, unsigned int ihl);
extern __sum16 ip_compute_csum(const void *buff, int len);

Expand Down
8 changes: 0 additions & 8 deletions arch/parisc/include/asm/checksum.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,6 @@
*/
extern __wsum csum_partial(const void *, int, __wsum);

/*
* The same as csum_partial, but copies from src while it checksums.
*
* Here even more important to align src and dst on a 32-bit (or even
* better 64-bit) boundary
*/
extern __wsum csum_partial_copy_nocheck(const void *, void *, int, __wsum);

/*
* Optimized for IP headers, which always checksum on 4 octet boundaries.
*
Expand Down
17 changes: 0 additions & 17 deletions arch/parisc/lib/checksum.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,20 +106,3 @@ __wsum csum_partial(const void *buff, int len, __wsum sum)
}

EXPORT_SYMBOL(csum_partial);

/*
* copy while checksumming, otherwise like csum_partial
*/
__wsum csum_partial_copy_nocheck(const void *src, void *dst,
int len, __wsum sum)
{
/*
* It's 2:30 am and I don't feel like doing it real ...
* This is lots slower than the real thing (tm)
*/
sum = csum_partial(src, len, sum);
memcpy(dst, src, len);

return sum;
}
EXPORT_SYMBOL(csum_partial_copy_nocheck);
1 change: 1 addition & 0 deletions arch/powerpc/include/asm/checksum.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ extern __wsum csum_and_copy_from_user(const void __user *src, void *dst,
extern __wsum csum_and_copy_to_user(const void *src, void __user *dst,
int len, __wsum sum, int *err_ptr);

#define _HAVE_ARCH_CSUM_AND_COPY
#define csum_partial_copy_nocheck(src, dst, len, sum) \
csum_partial_copy_generic((src), (dst), (len), (sum), NULL, NULL)

Expand Down
7 changes: 0 additions & 7 deletions arch/s390/include/asm/checksum.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,6 @@ csum_partial(const void *buff, int len, __wsum sum)
return sum;
}

static inline __wsum
csum_partial_copy_nocheck (const void *src, void *dst, int len, __wsum sum)
{
memcpy(dst,src,len);
return csum_partial(dst, len, sum);
}

/*
* Fold a partial checksum without adding pseudo headers
*/
Expand Down
1 change: 1 addition & 0 deletions arch/sh/include/asm/checksum_32.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
int len, __wsum sum,
int *src_err_ptr, int *dst_err_ptr);

#define _HAVE_ARCH_CSUM_AND_COPY
/*
* Note: when you get a NULL pointer exception here this means someone
* passed in an incorrect kernel address to one of these functions.
Expand Down
1 change: 1 addition & 0 deletions arch/sparc/include/asm/checksum.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* SPDX-License-Identifier: GPL-2.0 */
#ifndef ___ASM_SPARC_CHECKSUM_H
#define ___ASM_SPARC_CHECKSUM_H
#define _HAVE_ARCH_CSUM_AND_COPY
#define _HAVE_ARCH_COPY_AND_CSUM_FROM_USER
#if defined(__sparc__) && defined(__arch64__)
#include <asm/checksum_64.h>
Expand Down
1 change: 1 addition & 0 deletions arch/x86/include/asm/checksum.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* SPDX-License-Identifier: GPL-2.0 */
#define _HAVE_ARCH_COPY_AND_CSUM_FROM_USER 1
#define HAVE_CSUM_COPY_USER
#define _HAVE_ARCH_CSUM_AND_COPY
#ifdef CONFIG_X86_32
# include <asm/checksum_32.h>
#else
Expand Down
16 changes: 0 additions & 16 deletions arch/x86/um/asm/checksum.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,6 @@
*/
extern __wsum csum_partial(const void *buff, int len, __wsum sum);

/*
* Note: when you get a NULL pointer exception here this means someone
* passed in an incorrect kernel address to one of these functions.
*
* If you use these functions directly please don't forget the
* access_ok().
*/

static __inline__
__wsum csum_partial_copy_nocheck(const void *src, void *dst,
int len, __wsum sum)
{
memcpy(dst, src, len);
return csum_partial(dst, len, sum);
}

/**
* csum_fold - Fold and invert a 32bit checksum.
* sum: 32bit unfolded sum
Expand Down
1 change: 1 addition & 0 deletions arch/xtensa/include/asm/checksum.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
int len, __wsum sum,
int *src_err_ptr, int *dst_err_ptr);

#define _HAVE_ARCH_CSUM_AND_COPY
/*
* Note: when you get a NULL pointer exception here this means someone
* passed in an incorrect kernel address to one of these functions.
Expand Down
12 changes: 0 additions & 12 deletions include/asm-generic/checksum.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,6 @@
*/
extern __wsum csum_partial(const void *buff, int len, __wsum sum);

/*
* the same as csum_partial, but copies from src while it
* checksums
*
* here even more important to align src and dst on a 32-bit (or even
* better 64-bit) boundary
*/
#ifndef csum_partial_copy_nocheck
__wsum csum_partial_copy_nocheck(const void *src, void *dst, int len,
__wsum sum);
#endif

#ifndef ip_fast_csum
/*
* This is a version of ip_compute_csum() optimized for IP headers,
Expand Down
9 changes: 9 additions & 0 deletions include/net/checksum.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@ static __inline__ __wsum csum_and_copy_to_user
}
#endif

#ifndef _HAVE_ARCH_CSUM_AND_COPY
static inline __wsum
csum_partial_copy_nocheck(const void *src, void *dst, int len, __wsum sum)
{
memcpy(dst, src, len);
return csum_partial(dst, len, sum);
}
#endif

#ifndef HAVE_ARCH_CSUM_ADD
static inline __wsum csum_add(__wsum csum, __wsum addend)
{
Expand Down
11 changes: 0 additions & 11 deletions lib/checksum.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,17 +145,6 @@ __sum16 ip_compute_csum(const void *buff, int len)
}
EXPORT_SYMBOL(ip_compute_csum);

/*
* copy from ds while checksumming, otherwise like csum_partial
*/
__wsum
csum_partial_copy_nocheck(const void *src, void *dst, int len, __wsum sum)
{
memcpy(dst, src, len);
return csum_partial(dst, len, sum);
}
EXPORT_SYMBOL(csum_partial_copy_nocheck);

#ifndef csum_tcpudp_nofold
static inline u32 from64to32(u64 x)
{
Expand Down

0 comments on commit 6e41c58

Please sign in to comment.