From patchwork Wed Nov 15 20:30:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Leoshkevich X-Patchwork-Id: 13457300 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2093BC54FB9 for ; Wed, 15 Nov 2023 20:35:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8BB6D80040; Wed, 15 Nov 2023 15:35:08 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7D2F580038; Wed, 15 Nov 2023 15:35:08 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5B25580040; Wed, 15 Nov 2023 15:35:08 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 406D88003F for ; Wed, 15 Nov 2023 15:35:08 -0500 (EST) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 1CD601CB61E for ; Wed, 15 Nov 2023 20:35:08 +0000 (UTC) X-FDA: 81461343096.21.32AA0E7 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by imf11.hostedemail.com (Postfix) with ESMTP id D43EA4001A for ; Wed, 15 Nov 2023 20:35:05 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b=Um1Q9Qho; dmarc=pass (policy=none) header.from=ibm.com; spf=pass (imf11.hostedemail.com: domain of iii@linux.ibm.com designates 148.163.158.5 as permitted sender) smtp.mailfrom=iii@linux.ibm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1700080505; a=rsa-sha256; cv=none; b=35b7gSm+jVDHIHejVSy8h0YkHT6zonwTM3FSqiO9drRx8pB6KJwh2e5zJpiha4P9TPrphW yWUN74GDSxhS8aQVnpzqNdR377a62N52y5lqsJyL1AwjAV49tkURjGOJWs/oudJCM5Mpsv COO17AjUo4nofXg4lcYLfgQDcXp7odw= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b=Um1Q9Qho; dmarc=pass (policy=none) header.from=ibm.com; spf=pass (imf11.hostedemail.com: domain of iii@linux.ibm.com designates 148.163.158.5 as permitted sender) smtp.mailfrom=iii@linux.ibm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1700080505; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=nq9e5Kh1g7nUcH6hHoYLD2BDAEyO/grN3klBejPwfzM=; b=DZt2nblggeHhisM26/aCfXNBpwE+Rvx8nzY1iLPZgWSpSe1Eg29tn8ZnWJHLJhxXMD8V0n RQ8Y8cD1cJx5rbn1ZwdllklS8Psqf/ta/WT8XyI4ZzMm1ydC2cvQfNVihBIrXgYxkQLLok hvzUqO5SA8TTLN9XQ95OC/GpSb7Dp6A= Received: from pps.filterd (m0356516.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3AFKKGTF020216; Wed, 15 Nov 2023 20:35:00 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=nq9e5Kh1g7nUcH6hHoYLD2BDAEyO/grN3klBejPwfzM=; b=Um1Q9Qholsw0ojBN6dlk7AT6jZ6hU1TGcl9R0e2Pzr0R4Sr1cTfoFznAb6kOACesvz9P pE5ItJ2GD3cWNrOMSlPSpQlWX/UGHivgwQVS71xIgVX+3qxj+4D6HDxqLWC5mgYx3Db+ /3VARMtbx7BW0+xDGLvueDZ3l3vgA75iW/oufkHI8iQXQcQJduEazYnXeYwjNFf51cmv eKwt/HptZV9/jttbT0tpVOCwOtzrVkoomnrDCoyWzufLjy14QPn9tFr+ioProi+NvAfT qfv47VzXcCzJXyZcbAc8Dc8lntbalZc1g3fJ+UXUTzYtALSgIFsPhM2RPubXHJbtYFg7 zQ== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3ud4xc8cje-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 15 Nov 2023 20:35:00 +0000 Received: from m0356516.ppops.net (m0356516.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 3AFKMA2V026068; Wed, 15 Nov 2023 20:34:59 GMT Received: from ppma21.wdc07v.mail.ibm.com (5b.69.3da9.ip4.static.sl-reverse.com [169.61.105.91]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3ud4xc8cj2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 15 Nov 2023 20:34:59 +0000 Received: from pps.filterd (ppma21.wdc07v.mail.ibm.com [127.0.0.1]) by ppma21.wdc07v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 3AFKIusa015453; Wed, 15 Nov 2023 20:34:58 GMT Received: from smtprelay06.fra02v.mail.ibm.com ([9.218.2.230]) by ppma21.wdc07v.mail.ibm.com (PPS) with ESMTPS id 3uamxnj0qm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 15 Nov 2023 20:34:58 +0000 Received: from smtpav01.fra02v.mail.ibm.com (smtpav01.fra02v.mail.ibm.com [10.20.54.100]) by smtprelay06.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 3AFKYtlr42074872 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 15 Nov 2023 20:34:55 GMT Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id EC46F2004B; Wed, 15 Nov 2023 20:34:54 +0000 (GMT) Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9A57520040; Wed, 15 Nov 2023 20:34:53 +0000 (GMT) Received: from heavy.boeblingen.de.ibm.com (unknown [9.179.9.51]) by smtpav01.fra02v.mail.ibm.com (Postfix) with ESMTP; Wed, 15 Nov 2023 20:34:53 +0000 (GMT) From: Ilya Leoshkevich To: Alexander Gordeev , Alexander Potapenko , Andrew Morton , Christoph Lameter , David Rientjes , Joonsoo Kim , Marco Elver , Masami Hiramatsu , Pekka Enberg , Steven Rostedt , Vasily Gorbik , Vlastimil Babka Cc: Christian Borntraeger , Dmitry Vyukov , Hyeonggon Yoo <42.hyeyoo@gmail.com>, kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-s390@vger.kernel.org, linux-trace-kernel@vger.kernel.org, Mark Rutland , Roman Gushchin , Sven Schnelle , Ilya Leoshkevich Subject: [PATCH 27/32] s390/string: Add KMSAN support Date: Wed, 15 Nov 2023 21:30:59 +0100 Message-ID: <20231115203401.2495875-28-iii@linux.ibm.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231115203401.2495875-1-iii@linux.ibm.com> References: <20231115203401.2495875-1-iii@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: ui8k3Y8VmDpWZcOWLfPqxXUDgEJ41dXf X-Proofpoint-GUID: UXrJJp2IUCZ86lgkxA4hnMPl1rgWzyiC X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.987,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-11-15_20,2023-11-15_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 malwarescore=0 phishscore=0 mlxscore=0 lowpriorityscore=0 adultscore=0 clxscore=1015 suspectscore=0 mlxlogscore=999 spamscore=0 priorityscore=1501 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311060000 definitions=main-2311150163 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: D43EA4001A X-Stat-Signature: bt414ipj9shaxhe7fntkzki1fpp46o7p X-HE-Tag: 1700080505-703186 X-HE-Meta: U2FsdGVkX19V2n+v5DClyhsG89adVAdd2LHK5l39J2CrvuKlJI1JMqJGCtgk+9hSnvm4KDB6xCHVhWthLjSN7WbVUYL0iieIY9Zra6JQbPrF1Kmn5eQemsmkflFSeVXmZu5zzegKZfs1vqalI9fWr5Ct2bZup69+fgkI3s1DzpDqEpCVp1HjzEXa2z8dMOmuRUes+VDB5o5CJIMOiHbEekp1VoCs7wshgmLSRatAwUSEaAbHoUsnikhtQRcvv3OjWxPxTKJmIYnm544yleAA6FiTgR3xQk56lWTUQyav6o9Il3mtjstAXN4D2KmmIsLlpkccShCf+x+QNPIje1Ii1WyanC+/p8ipk7Kc+/Y2o2JvcfyulLeGeyx0/1lvmqdhiGgHsduADmHgStgqQEwUC9BuABSSVLx16uMdJ65TbZ671GuCs8AkUJ9WmBlxQ9Cpbadn5+20hn4Kni4EpVGaCDpWKshKe9dc5rPDuwIxD7tFN/H9yhkCaQaE/Fbx/c3c3tamgQsVl1PjMP/4qeLyqRPGM4pedaeztytOmoQw+cKcufL3s/N7IUEmoH8fajqyvDDdVDeAOgLOAZZ4+r5Vju5GuwdhpHsZJAI4NxFzAIauQr0xBO6Hk9sFaJGbEiThcBhB+ISjVNCINyv7A2kXszVdRGjJTY60pOl1LrXCrpw5Y1UC+GgsAlOOuozIvBLPr9VoRG/LCArnmR564hS2vqkdUzveRtRlbS/NjTdTs1kDIhybh52/Q/xUUKXNngGL/rNCrG7KN4Qj1t/MI1g6M5DxoXhhNL1lbVNqRLnsw8pOSY7OWnga2G3iJzTS02k1FWIZAxe1KJqmprF5d0zE6lRB/xNQrRKolERZhDFjWglytrJvyAp7/XX+Wvf9AHTEVhVHqhnV7crDBMREnEoww6cR2BexWJGEetXH3/23MsqVvASk8KcpcKg1pbORia91XB6ZnJJ3PYG9txnGnt6 Q/Gu+1DL LQAXu1BOYLJI6Ro9ZBs1tSPiWZCqWRaREJwZuGYWL7A+70Zvb3Rky7iL2Vq7xVs29zTW7b770gpfdY/0jn1kK0pI8tth5y+WXM321StAP9VpKeL8u8GHTIp53vzqTEUE8VUno8FxwyEZ6FWYGIkiU0dp5OkRtSzTwSoHM8V8MY048j0Zw8Qzo//7IeULrp1tGz4kH8oSEQ4aATAgbCzZTgykA9Q== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Add KMSAN support for the s390 implementations of the string functions. Do this similar to how it's already done for KASAN, except that the optimized memset{16,32,64}() functions need to be disabled: it's important for KMSAN to know that they initialized something. Signed-off-by: Ilya Leoshkevich --- arch/s390/boot/string.c | 15 +++++++++++ arch/s390/include/asm/string.h | 49 ++++++++++++++++++++-------------- 2 files changed, 44 insertions(+), 20 deletions(-) diff --git a/arch/s390/boot/string.c b/arch/s390/boot/string.c index faccb33b462c..6d886c84075b 100644 --- a/arch/s390/boot/string.c +++ b/arch/s390/boot/string.c @@ -4,8 +4,14 @@ #include #undef CONFIG_KASAN #undef CONFIG_KASAN_GENERIC +#undef CONFIG_KMSAN #include "../lib/string.c" +/* + * Duplicate some functions from the common lib/string.c + * instead of fully including it. + */ + int strncmp(const char *cs, const char *ct, size_t count) { unsigned char c1, c2; @@ -22,6 +28,15 @@ int strncmp(const char *cs, const char *ct, size_t count) return 0; } +void *memset64(uint64_t *s, uint64_t v, size_t count) +{ + uint64_t *xs = s; + + while (count--) + *xs++ = v; + return s; +} + char *skip_spaces(const char *str) { while (isspace(*str)) diff --git a/arch/s390/include/asm/string.h b/arch/s390/include/asm/string.h index 351685de53d2..94925024cb26 100644 --- a/arch/s390/include/asm/string.h +++ b/arch/s390/include/asm/string.h @@ -15,15 +15,12 @@ #define __HAVE_ARCH_MEMCPY /* gcc builtin & arch function */ #define __HAVE_ARCH_MEMMOVE /* gcc builtin & arch function */ #define __HAVE_ARCH_MEMSET /* gcc builtin & arch function */ -#define __HAVE_ARCH_MEMSET16 /* arch function */ -#define __HAVE_ARCH_MEMSET32 /* arch function */ -#define __HAVE_ARCH_MEMSET64 /* arch function */ void *memcpy(void *dest, const void *src, size_t n); void *memset(void *s, int c, size_t n); void *memmove(void *dest, const void *src, size_t n); -#ifndef CONFIG_KASAN +#if !defined(CONFIG_KASAN) && !defined(CONFIG_KMSAN) #define __HAVE_ARCH_MEMCHR /* inline & arch function */ #define __HAVE_ARCH_MEMCMP /* arch function */ #define __HAVE_ARCH_MEMSCAN /* inline & arch function */ @@ -36,6 +33,9 @@ void *memmove(void *dest, const void *src, size_t n); #define __HAVE_ARCH_STRNCPY /* arch function */ #define __HAVE_ARCH_STRNLEN /* inline & arch function */ #define __HAVE_ARCH_STRSTR /* arch function */ +#define __HAVE_ARCH_MEMSET16 /* arch function */ +#define __HAVE_ARCH_MEMSET32 /* arch function */ +#define __HAVE_ARCH_MEMSET64 /* arch function */ /* Prototypes for non-inlined arch strings functions. */ int memcmp(const void *s1, const void *s2, size_t n); @@ -44,7 +44,7 @@ size_t strlcat(char *dest, const char *src, size_t n); char *strncat(char *dest, const char *src, size_t n); char *strncpy(char *dest, const char *src, size_t n); char *strstr(const char *s1, const char *s2); -#endif /* !CONFIG_KASAN */ +#endif /* !defined(CONFIG_KASAN) && !defined(CONFIG_KMSAN) */ #undef __HAVE_ARCH_STRCHR #undef __HAVE_ARCH_STRNCHR @@ -74,21 +74,6 @@ void *__memset16(uint16_t *s, uint16_t v, size_t count); void *__memset32(uint32_t *s, uint32_t v, size_t count); void *__memset64(uint64_t *s, uint64_t v, size_t count); -static inline void *memset16(uint16_t *s, uint16_t v, size_t count) -{ - return __memset16(s, v, count * sizeof(v)); -} - -static inline void *memset32(uint32_t *s, uint32_t v, size_t count) -{ - return __memset32(s, v, count * sizeof(v)); -} - -static inline void *memset64(uint64_t *s, uint64_t v, size_t count) -{ - return __memset64(s, v, count * sizeof(v)); -} - #if !defined(IN_ARCH_STRING_C) && (!defined(CONFIG_FORTIFY_SOURCE) || defined(__NO_FORTIFY)) #ifdef __HAVE_ARCH_MEMCHR @@ -194,6 +179,27 @@ static inline size_t strnlen(const char * s, size_t n) return end - s; } #endif + +#ifdef __HAVE_ARCH_MEMSET16 +static inline void *memset16(uint16_t *s, uint16_t v, size_t count) +{ + return __memset16(s, v, count * sizeof(v)); +} +#endif + +#ifdef __HAVE_ARCH_MEMSET32 +static inline void *memset32(uint32_t *s, uint32_t v, size_t count) +{ + return __memset32(s, v, count * sizeof(v)); +} +#endif + +#ifdef __HAVE_ARCH_MEMSET64 +static inline void *memset64(uint64_t *s, uint64_t v, size_t count) +{ + return __memset64(s, v, count * sizeof(v)); +} +#endif #else /* IN_ARCH_STRING_C */ void *memchr(const void * s, int c, size_t n); void *memscan(void *s, int c, size_t n); @@ -201,6 +207,9 @@ char *strcat(char *dst, const char *src); char *strcpy(char *dst, const char *src); size_t strlen(const char *s); size_t strnlen(const char * s, size_t n); +void *memset16(uint16_t *s, uint16_t v, size_t count); +void *memset32(uint32_t *s, uint32_t v, size_t count); +void *memset64(uint64_t *s, uint64_t v, size_t count); #endif /* !IN_ARCH_STRING_C */ #endif /* __S390_STRING_H_ */