1 // SPDX-License-Identifier: GPL-2.0-only 2 /* 3 * Copyright 2002, 2003 Andi Kleen, SuSE Labs. 4 * 5 * Wrappers of assembly checksum functions for x86-64. 6 */ 7 #include <asm/checksum.h> 8 #include <linux/export.h> 9 #include <linux/uaccess.h> 10 #include <asm/smap.h> 11 12 /** 13 * csum_and_copy_from_user - Copy and checksum from user space. 14 * @src: source address (user space) 15 * @dst: destination address 16 * @len: number of bytes to be copied. 17 * 18 * Returns an 32bit unfolded checksum of the buffer. 19 * src and dst are best aligned to 64bits. 20 */ 21 __wsum 22 csum_and_copy_from_user(const void __user *src, void *dst, int len) 23 { 24 __wsum sum; 25 26 might_sleep(); 27 if (!user_access_begin(src, len)) 28 return 0; 29 sum = csum_partial_copy_generic((__force const void *)src, dst, len); 30 user_access_end(); 31 return sum; 32 } 33 34 /** 35 * csum_and_copy_to_user - Copy and checksum to user space. 36 * @src: source address 37 * @dst: destination address (user space) 38 * @len: number of bytes to be copied. 39 * 40 * Returns an 32bit unfolded checksum of the buffer. 41 * src and dst are best aligned to 64bits. 42 */ 43 __wsum 44 csum_and_copy_to_user(const void *src, void __user *dst, int len) 45 { 46 __wsum sum; 47 48 might_sleep(); 49 if (!user_access_begin(dst, len)) 50 return 0; 51 sum = csum_partial_copy_generic(src, (void __force *)dst, len); 52 user_access_end(); 53 return sum; 54 } 55 56 /** 57 * csum_partial_copy_nocheck - Copy and checksum. 58 * @src: source address 59 * @dst: destination address 60 * @len: number of bytes to be copied. 61 * 62 * Returns an 32bit unfolded checksum of the buffer. 63 */ 64 __wsum 65 csum_partial_copy_nocheck(const void *src, void *dst, int len) 66 { 67 return csum_partial_copy_generic(src, dst, len); 68 } 69 EXPORT_SYMBOL(csum_partial_copy_nocheck); 70 71