From patchwork Wed Mar 1 14:39:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Potapenko X-Patchwork-Id: 13156067 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 A7BFAC64ED6 for ; Wed, 1 Mar 2023 14:39:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 334B96B0073; Wed, 1 Mar 2023 09:39:42 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 2E4FB6B0074; Wed, 1 Mar 2023 09:39:42 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1AE556B0075; Wed, 1 Mar 2023 09:39:42 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 0C8F46B0073 for ; Wed, 1 Mar 2023 09:39:42 -0500 (EST) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id CEBB01A07C4 for ; Wed, 1 Mar 2023 14:39:41 +0000 (UTC) X-FDA: 80520588162.20.51B905D Received: from mail-ed1-f73.google.com (mail-ed1-f73.google.com [209.85.208.73]) by imf03.hostedemail.com (Postfix) with ESMTP id 185D720015 for ; Wed, 1 Mar 2023 14:39:38 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=hwwsMSyO; spf=pass (imf03.hostedemail.com: domain of 3qWP_YwYKCJQ49612F4CC492.0CA96BIL-AA8Jy08.CF4@flex--glider.bounces.google.com designates 209.85.208.73 as permitted sender) smtp.mailfrom=3qWP_YwYKCJQ49612F4CC492.0CA96BIL-AA8Jy08.CF4@flex--glider.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1677681579; 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-type:content-transfer-encoding:in-reply-to: references:dkim-signature; bh=JhZ8SEDoNzl+E2htjsUuUTMZqyHgHOmh7ac72ddETYs=; b=gP9MJ5nvJFqgs6fhIgOdmVsXfkUxFWOugZRw0cp62+MJJCi3mBxoiLK8aQl+OezKDMKlmb 9EgXVw+fc0+j6dR3dv3zrAG/rpGTPA0JOBq12UUnHR7fYOiJIgLbLOtyHpt/qVo0hr/V7e lnZyvDACptPnJxiAjG3YrV2dpJ/mY14= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=hwwsMSyO; spf=pass (imf03.hostedemail.com: domain of 3qWP_YwYKCJQ49612F4CC492.0CA96BIL-AA8Jy08.CF4@flex--glider.bounces.google.com designates 209.85.208.73 as permitted sender) smtp.mailfrom=3qWP_YwYKCJQ49612F4CC492.0CA96BIL-AA8Jy08.CF4@flex--glider.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1677681579; a=rsa-sha256; cv=none; b=10JrzKOm3CLBPFq4qKIYx5abd6N0ccQ1wgnRA6UgPTzAomE1Hhl94wjAlic9v/lUZwN66I 09k34xJB3GUILJ8fJC91cYX0knyWJAvqSnvnY2tAQ7nqwAm6Tb6QTBA7WZX6ZGY3iAsz41 Mq9J2RkO4CMSSJU79CibabPy6tb2LrI= Received: by mail-ed1-f73.google.com with SMTP id q13-20020a5085cd000000b004af50de0bcfso19760228edh.15 for ; Wed, 01 Mar 2023 06:39:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=JhZ8SEDoNzl+E2htjsUuUTMZqyHgHOmh7ac72ddETYs=; b=hwwsMSyOzkoBWayzQKOdFKIZfN+8rn6K+uZRqXexu7jTOCYjQq9ACST/vXXGgUa8CT 9PbkYANDhENEWpCTAac5mNG7ZIAElA8E4TlfoSG2z+sTpCuZtWZwUNcme6Nz5ZOi8bmI WuyGwo5xiOk2ylqXeLH4a6J07LtGg7Ap91k/9Mcx8NUjgjoD00YVOtKBU9sHuoMA8yE3 Onih1jNZmnQe2nEJA1yFuRFt5+jQMY1R2GMyNKX1qCR4BhaJrAA/7d3oi5VEphgCi5fm cZRBWCikluD1F4OG5qcDUFzHLUwgyg0Swg3+bo7tCkfOYvarkHR+O8quNjT/Nzoz7/3D eJkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=JhZ8SEDoNzl+E2htjsUuUTMZqyHgHOmh7ac72ddETYs=; b=Qrk9VE5kfCWHcaC8Uf2TIfw8cxWGExIFitCnSJRnUiU8xUL1VzLKURkaolLkVpiyBy JzLEKuwi+ErKunG/tuW0UMUEsvZNDIxVpOMEOd52NsZjlgnSZzu7NRmvVWusfeT6q48V Y8gN5KD467b0ZlErEzcmSNv+bOE4LUdyXjnq/tXiGUDAE/VjQif9MQt5PXWpzd4c0Svd qQEqYYgRRHG+6e3rCRWIBNYrovIeLZJNRA3hiOKy3uqqrNOp/gu/kyle1n6Y8G83oPQw 7KJnKthQMhrUNnsR0WW6pnLqMtYIx3wActUrD+H9oncN+pO1FxIUnQNVC0ZpbL8EAFah qpUg== X-Gm-Message-State: AO0yUKWCQ70wE2bLb5YHpUBbWcph02v2Xpvnsr8M0joBczHs1gomGVA/ 38kVojaXj8zi1jmgaI+xMx+vqi1Rb6g= X-Google-Smtp-Source: AK7set/soLRTnmi/Q6cCoxB5T4A5ekmdZ3mGiPUd6HKEr7VaR2a3N3ZNKHKp69dd1Rxd9h+HwywF0ggPLBQ= X-Received: from glider.muc.corp.google.com ([2a00:79e0:9c:201:3c31:b0cf:1498:e916]) (user=glider job=sendgmr) by 2002:a17:907:9491:b0:8ee:babc:d3f8 with SMTP id dm17-20020a170907949100b008eebabcd3f8mr5683794ejc.3.1677681577396; Wed, 01 Mar 2023 06:39:37 -0800 (PST) Date: Wed, 1 Mar 2023 15:39:30 +0100 Mime-Version: 1.0 X-Mailer: git-send-email 2.39.2.722.g9855ee24e9-goog Message-ID: <20230301143933.2374658-1-glider@google.com> Subject: [PATCH 1/4] x86: kmsan: Don't rename memintrinsics in uninstrumented files From: Alexander Potapenko To: glider@google.com Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, x86@kernel.org, dave.hansen@linux.intel.com, hpa@zytor.com, akpm@linux-foundation.org, elver@google.com, dvyukov@google.com, nathan@kernel.org, ndesaulniers@google.com, kasan-dev@googlegroups.com, Kees Cook X-Rspamd-Queue-Id: 185D720015 X-Stat-Signature: k3eggixxqjqxzfjpjgdjiztkwyhid7io X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1677681578-905608 X-HE-Meta: U2FsdGVkX1/eFzZNdePJOwHgMPyus+1F+G8BrgG4Qc/JG/Ug9ScPtrD3iiCfI3KzlK5284ymTuOcWMJOXQMEJsK3f8NzMPZI3HRP4LT/e/EQ57zFDIUy57x3eh/IYaqtGn2DyeGx78Rzux3TLKhkPD1wRUqsUSr5sptgmYiCKme0mpc4hjgqJKjsseCdFbf9+GN0B5uPe90Gpke21/54rHR+SugdPFr0cO8imbpdEoWTB+1Em8XlDuw8Q7dbI9/ob355K89RlNhdgdcYRyfrItC+iG8eU9vbcm8wSRe6+wdDBqApSY351sM3l7MwxFWjzUdM1pxMp61TTaYJGcewRoMjL7+p8GVVMTc9Lu+3LmR7t9tUOVEhdJwRuMrkSGroM50LQ9tvzi4xo4JOp53Mr+HTdODEeZqRJQYM4T81WsbWaiTpXvQfo754/1Frf0oUtkRilMQQiHwDraTy8WFAvHPgeD6iuTtaRUuh4n3pIU6iU1lnbi0uefug/h98dzXP1+rjD5RUpHqWde6PRxUm49eLf5LJjIEPQ4x5z3rUwXXxe6irXHse/1FUHzIZUsuEmB+H2T6dE58TwlERr0NisqcrlBwEFoN/W10xLMarISr3HThnXuQd5+JhP9P7gocPRAX6N3JAjl8unCTPFMb4K+tzBbljw0StuGw/07CKZmqXj9uiz1vaEAaUZiLMq5ywTRyPRhZwUCkK0aBl8ReAMbrjuZphKyae82D2EQGr3w0yyW8W/q0eLK1Pxjdmc7YOUujOVgCqYvhcoGI/GyKWSD+WPBLuZHDAWa42ra1McG8BKjG6PFBvuHMc4qfUUXny1NC6H9SIPnZZsobzNeBivbSslb56NnmaFzh5PsXEV5BMWAwaTKrL9hkd6iIAPH3ylklWXtUAtkaXjs4ZquZxX05F9+XTsnUipBXTX6QlA3GprQWZHJ3tAksVVkMePhEAFXPrLiGjEAjCtE1tSdd UxojVlC0 pJ7KLEwQToesrr3Yekni+q8ARQKxSUbOQkU+KW0zSvY7fmSrzz3cbvEkVcirtaRwbqmD9f05CtLAy4eNbkGBS2S/60EHd4bysmsHdNjcGNhaFBoRCxnktpP4oStQ4VsLd5fkfGnYYbxGHRmkZg9sP8G+wUuIVoZwMuz+rM9Lh33M4UyPrMK4dy6tJRIm2Mla+dydf31m2OMPVjH/00Fef6t++2rAxyKPfGgYo1IF+LBrINdWV/tdp5FR8ppbPuXQbf6+DWXm2n3a5g97vJxIQx+m0Jk0lZANfJ6oiq4ZapsX1Fzgf5rr6mueLT2moJa1pDvZ/vCClvV/QrsNvpRkmlKFd6GY7dKmHIRNcRIZajWDYPB8Ua/729cHzdv3iLCtNXAcWXfHIvj7knhUgjgz7w+pEHlb6Hj6SItiuiFntOWGLHPVMhqn3LE5dw0lteys08SutfzznpatRcYbFHM2ghWv2tsHUuWreA94WezEMcC18ZDev/MEnAjD7sW/tybRB+0U4cw1pjUKX0q+z/6ov5NhGgD2S9+YaETh4S7Hkh5MP0EaY8m4b3qpMa6mkrxBC/dEVeDyppoENRid8FevyUoEXVpAmNhWvtp9yM+DuYZIYCCJlCDcSlx5XNaU96FQ/lcAdSiQcW5CRQaK8bvFllHonUVNcsR/OK+nfCBeT/+iTxqwyIiDnaOj0/g== 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: KMSAN should be overriding calls to memset/memcpy/memmove and their __builtin_ versions in instrumented files, so there is no need to override them. In non-instrumented versions we are now required to leave memset() and friends intact, so we cannot replace them with __msan_XXX() functions. Cc: Kees Cook Suggested-by: Marco Elver Signed-off-by: Alexander Potapenko Reviewed-by: Marco Elver --- arch/x86/include/asm/string_64.h | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/arch/x86/include/asm/string_64.h b/arch/x86/include/asm/string_64.h index 888731ccf1f67..9be401d971a99 100644 --- a/arch/x86/include/asm/string_64.h +++ b/arch/x86/include/asm/string_64.h @@ -15,22 +15,11 @@ #endif #define __HAVE_ARCH_MEMCPY 1 -#if defined(__SANITIZE_MEMORY__) && defined(__NO_FORTIFY) -#undef memcpy -#define memcpy __msan_memcpy -#else extern void *memcpy(void *to, const void *from, size_t len); -#endif extern void *__memcpy(void *to, const void *from, size_t len); #define __HAVE_ARCH_MEMSET -#if defined(__SANITIZE_MEMORY__) && defined(__NO_FORTIFY) -extern void *__msan_memset(void *s, int c, size_t n); -#undef memset -#define memset __msan_memset -#else void *memset(void *s, int c, size_t n); -#endif void *__memset(void *s, int c, size_t n); #define __HAVE_ARCH_MEMSET16 @@ -70,13 +59,7 @@ static inline void *memset64(uint64_t *s, uint64_t v, size_t n) } #define __HAVE_ARCH_MEMMOVE -#if defined(__SANITIZE_MEMORY__) && defined(__NO_FORTIFY) -#undef memmove -void *__msan_memmove(void *dest, const void *src, size_t len); -#define memmove __msan_memmove -#else void *memmove(void *dest, const void *src, size_t count); -#endif void *__memmove(void *dest, const void *src, size_t count); int memcmp(const void *cs, const void *ct, size_t count); From patchwork Wed Mar 1 14:39:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Potapenko X-Patchwork-Id: 13156068 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 44F49C7EE36 for ; Wed, 1 Mar 2023 14:39:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C0EAE6B0074; Wed, 1 Mar 2023 09:39:43 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id BBEA66B0075; Wed, 1 Mar 2023 09:39:43 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A38866B007B; Wed, 1 Mar 2023 09:39:43 -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 9621C6B0074 for ; Wed, 1 Mar 2023 09:39:43 -0500 (EST) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 5FC5316019D for ; Wed, 1 Mar 2023 14:39:43 +0000 (UTC) X-FDA: 80520588246.08.FC7BBB0 Received: from mail-ed1-f73.google.com (mail-ed1-f73.google.com [209.85.208.73]) by imf16.hostedemail.com (Postfix) with ESMTP id 7DD7A180004 for ; Wed, 1 Mar 2023 14:39:41 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=TZbcESbs; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf16.hostedemail.com: domain of 3q2P_YwYKCJY6B834H6EE6B4.2ECB8DKN-CCAL02A.EH6@flex--glider.bounces.google.com designates 209.85.208.73 as permitted sender) smtp.mailfrom=3q2P_YwYKCJY6B834H6EE6B4.2ECB8DKN-CCAL02A.EH6@flex--glider.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1677681581; 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-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=GvEmc+TQ/70wBv4c0+3F8h651+3YM9ltVwHdaJENm+0=; b=WWkmV9EvnWCeFxRWJvcP2Aq/M08EdObPy4jnmj6h14UtlTA9MO4oYFFa7DS4qtizQltwxV OESHqFhNR8qGLUyY3dU1ccRCYOM0NX4duwrrKqeY/jXfSh8lTYMudrI/qjWv2kbuuVWtXL VwjOV7DvZsFjmCrV6lRox2Cy7vMxTmo= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=TZbcESbs; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf16.hostedemail.com: domain of 3q2P_YwYKCJY6B834H6EE6B4.2ECB8DKN-CCAL02A.EH6@flex--glider.bounces.google.com designates 209.85.208.73 as permitted sender) smtp.mailfrom=3q2P_YwYKCJY6B834H6EE6B4.2ECB8DKN-CCAL02A.EH6@flex--glider.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1677681581; a=rsa-sha256; cv=none; b=CQWUMUAFdIV9ehKdzwEV21PSpOY+LpnI05ItCORNsHaWywCVcygjQAv4/nvbVp68Ey9F8L AXCP4dIkGPCw6UjOG8yj2VKnk4erbft5zkOzpCGce1YIbITgfmjiz/4z4p2Y10OuTfhb+a g/tNXbJ2Hnohs5WTlaGLsLQjlEINKgA= Received: by mail-ed1-f73.google.com with SMTP id p36-20020a056402502400b004bb926a3d54so4263397eda.2 for ; Wed, 01 Mar 2023 06:39:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=GvEmc+TQ/70wBv4c0+3F8h651+3YM9ltVwHdaJENm+0=; b=TZbcESbsWwNX7ITUi/aZMlklXQLIxXSFS8qC4CBgfWLzgdWV4sw7TnmemklpH6W7Bc A7y93ECEz75USteW8FD3Y1XqRtJk5z3dpdOjwx44G2Jjuz+Z4hitvfk4TnGhEpzcwscE ecg0YS6TcupDfdmQ4FiWgzFt1XEr6a7zKBTWdlnNhV5j7eNaBRDBF61cN2PiP+iE5mTh 91+plLrvqvm2QV627pn0K767iy62E8FL4Syt1zWC06tG2/CxQdIgC4GhP+p/aeN6q3xd 8FPlln8dfQ68QkVsu4QnH0TBtMDPHUtGDPr6mhY3CY6Efu84yLWgr+mHbxwvH+VHgIa6 MHVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=GvEmc+TQ/70wBv4c0+3F8h651+3YM9ltVwHdaJENm+0=; b=CbNbR+56xMyB3NCAV2sA0y/YYLW/B7/CrEjVGRDYB7xv07Q3IiU8QFOxt7HDIoYXgx a5218ZP1I3cziCWiMAQD4yo09LjWRYiw1fUJ+VsAxHivAJH4f10QI9kWcA2Bkl7A4bqD 89Qzmey/9MPiHvGvwD8ie4JdU0btGPW7MRQk906BB5HISZelexqIoKfWpSa5RLijsNVN iBjVD8HfLJVnCVFtgHl0anu7gztDCeXprEKKztH2d6Vsn+89QVKTNOqhCAj+MLmt5Y37 cV+s/p/EmdMI8s//mR8pd8rDa+aEEYwI4edJR1NOiOa/HmpDrup4JQf9cm6f4HCVI0zO qxkg== X-Gm-Message-State: AO0yUKX/e1THBnAdwIGZY30toob4FBX2/Vrg4hOpTS71ghur6YmaxF8K NGfP0nvrQZCxRqXoDvFBSlsVNuZTixA= X-Google-Smtp-Source: AK7set+/E1TqZIMkRHLQhUF/c0Crs4CPmSPBSgdNL2StGzl+To/OODmTIOi2hun6qk3SVyMlWubpsRLL6g8= X-Received: from glider.muc.corp.google.com ([2a00:79e0:9c:201:3c31:b0cf:1498:e916]) (user=glider job=sendgmr) by 2002:a50:d6db:0:b0:4aa:a4df:23fc with SMTP id l27-20020a50d6db000000b004aaa4df23fcmr4014799edj.1.1677681579977; Wed, 01 Mar 2023 06:39:39 -0800 (PST) Date: Wed, 1 Mar 2023 15:39:31 +0100 In-Reply-To: <20230301143933.2374658-1-glider@google.com> Mime-Version: 1.0 References: <20230301143933.2374658-1-glider@google.com> X-Mailer: git-send-email 2.39.2.722.g9855ee24e9-goog Message-ID: <20230301143933.2374658-2-glider@google.com> Subject: [PATCH 2/4] kmsan: another take at fixing memcpy tests From: Alexander Potapenko To: glider@google.com Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, x86@kernel.org, dave.hansen@linux.intel.com, hpa@zytor.com, akpm@linux-foundation.org, elver@google.com, dvyukov@google.com, nathan@kernel.org, ndesaulniers@google.com, kasan-dev@googlegroups.com X-Rspamd-Queue-Id: 7DD7A180004 X-Rspamd-Server: rspam09 X-Rspam-User: X-Stat-Signature: 84k6iowfh7r9b4xu4fageeohqniixz3z X-HE-Tag: 1677681581-247856 X-HE-Meta: U2FsdGVkX1/Tkpgg9su4vJJiDDted05lduR/PplHgNdRAO2dFOSUA1Wy3wd9eURjn6O9a6smPeAAeQONbHZ+5wqMk3SdlhwkNrlEHZU/HVXB96hxHm2uI3sqzkQekNiJJEtayei/cyjq2hKngiprWnyDcWKOW12t02OQ39EyvCncnx0Rv9OBpxeIIRWgtnX/1tFrwLImXVGR6WAULvSUlV7ys3icZohPu8m4P1V4I0gHkzbqtpTTDDP/NYuC4sEWFLLlY8eOlKV3BHIDeNHidKQbjtrhiZo9FphJZYrrIE0KkZ7NJy94S+rChRjHmt02Z9u5NppgCYCLRtLHEXdZXITGqk84XG8axIE9bey4QqqmzRaygNVHRWLteDEDYNJpjFYP1s0KjLpuu7QdqFA0VMltEBy1EeZWJ6UvruNXSF8zDGKa/VPpF/1v3+b3m5ID702GeD5Mb8Vi9U2Rg+8Kxgb9wWOmzD/Urgcu71xho/f/bmPSMArtVTVzhaVWZ7uquWlZRRuAtATZgu29GHY9/SXwYCpZ8k01wTn65AYPV2n27O3ylpbOLz/T8DBB0x0qnE6FUH/KqUSiqbZS8HFP4WvGJabHoMlLCi5E3tFFvetY0dprb+5Cv/CfPaEcNDXw0GX3Qb+dAo0bq+aSg16CRhXYU7wr/7r8j+SsUar7OVZD7W52geZtD9JMNKezIMlg+kOtGnvRySJxL+eEymboch5PGFCsZ7CoDhT+H3fSlE4+M8s7kClT1DqwABCXqz0TytVz6H8m05ANto0XSdopjd7wtp9uwhQV2G3aYZ+rQfiAxcOkdNVuBTiW4BHXr6X9GBNCv7PbM99lxqYHM+Z1BX+nTKDMuBEOw1C+4Ty0ciFhrx6IjpDBfRSEGk8Mm53n5UpE0SerjiT0+wbIteV5FE4wVu1SYnr1PXeqleO0IyN583ZQSoTFmwU8JC2kQn/lG68ouRf+UEyjG3AMGFO vUS/NTFD A7xuZjmja3tdeTq5LeT8N744OjPBzvcil8WR2hMUPzbLWUCENr7Ou9VTMsQxV10tgs3JGbX0RJeP9wQKYy2U9S2j6X6a1eMdKE+Yo64PWgXy/oXl18CT2kmE2NDP2HF9HiJ4GmiRdt2IaG+U2YbXA6PHo1ba9hpBqApEzklcqb9cw7qPInnISkp51hW8vMzbQHmhByZGuICZppg1j/D9mxFJxIs87DA9VIg/Kpo8THnlKmDGX9ctaiz83ZBnkneMb8CDPwvZAmQOPG1uL8MWK3JZ6lqAJj5hbk0CrdyiAwFHR0RMyBju5KbEHCfPy+QCUr6DZgzhpN6xdaFQQEMxgpb0wXBzKcyvlqhR2xJTfIJDLqemlPEebiOJUEl4SQF+fapf0MCesjmmMPaf9HLl8U1PkH9pDRYHm+4ymnL7CTRhv0LnzHNOFKmAaTVvob1Z7NbUX7lx0Q6H1b+L0Mg+hB3W3Di7fFGZOw4gtg435rOoLzR6+KR6CRzehj5q0p7mSbU1JImx5q5KoJiAMuCKLUBAo6PdZz3n5O6U8MMYiwaO5YDwJPJ9ifbpdbGPJpIgmLJGDD6Cd0+9EwRqwUyJJKOO2s0h7RT6E0xn1lpiOAWUPr26FHILtfaG0Gw== 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: 5478afc55a21 ("kmsan: fix memcpy tests") uses OPTIMIZER_HIDE_VAR() to hide the uninitialized var from the compiler optimizations. However OPTIMIZER_HIDE_VAR(uninit) enforces an immediate check of @uninit, so memcpy tests did not actually check the behavior of memcpy(), because they always contained a KMSAN report. Replace OPTIMIZER_HIDE_VAR() with a file-local asm macro that just clobbers the memory, and add a test case for memcpy() that does not expect an error report. Also reflow kmsan_test.c with clang-format. Signed-off-by: Alexander Potapenko --- mm/kmsan/kmsan_test.c | 43 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 37 insertions(+), 6 deletions(-) diff --git a/mm/kmsan/kmsan_test.c b/mm/kmsan/kmsan_test.c index 088e21a48dc4b..cc98a3f4e0899 100644 --- a/mm/kmsan/kmsan_test.c +++ b/mm/kmsan/kmsan_test.c @@ -407,6 +407,36 @@ static void test_printk(struct kunit *test) KUNIT_EXPECT_TRUE(test, report_matches(&expect)); } +/* + * Prevent the compiler from optimizing @var away. Without this, Clang may + * notice that @var is uninitialized and drop memcpy() calls that use it. + * + * There is OPTIMIZER_HIDE_VAR() in linux/compier.h that we cannot use here, + * because it is implemented as inline assembly receiving @var as a parameter + * and will enforce a KMSAN check. + */ +#define DO_NOT_OPTIMIZE(var) asm("" ::: "memory") + +/* + * Test case: ensure that memcpy() correctly copies initialized values. + */ +static void test_init_memcpy(struct kunit *test) +{ + EXPECTATION_NO_REPORT(expect); + volatile int src; + volatile int dst = 0; + + // Ensure DO_NOT_OPTIMIZE() does not cause extra checks. + DO_NOT_OPTIMIZE(src); + src = 1; + kunit_info( + test, + "memcpy()ing aligned initialized src to aligned dst (no reports)\n"); + memcpy((void *)&dst, (void *)&src, sizeof(src)); + kmsan_check_memory((void *)&dst, sizeof(dst)); + KUNIT_EXPECT_TRUE(test, report_matches(&expect)); +} + /* * Test case: ensure that memcpy() correctly copies uninitialized values between * aligned `src` and `dst`. @@ -420,7 +450,7 @@ static void test_memcpy_aligned_to_aligned(struct kunit *test) kunit_info( test, "memcpy()ing aligned uninit src to aligned dst (UMR report)\n"); - OPTIMIZER_HIDE_VAR(uninit_src); + DO_NOT_OPTIMIZE(uninit_src); memcpy((void *)&dst, (void *)&uninit_src, sizeof(uninit_src)); kmsan_check_memory((void *)&dst, sizeof(dst)); KUNIT_EXPECT_TRUE(test, report_matches(&expect)); @@ -443,7 +473,7 @@ static void test_memcpy_aligned_to_unaligned(struct kunit *test) kunit_info( test, "memcpy()ing aligned uninit src to unaligned dst (UMR report)\n"); - OPTIMIZER_HIDE_VAR(uninit_src); + DO_NOT_OPTIMIZE(uninit_src); memcpy((void *)&dst[1], (void *)&uninit_src, sizeof(uninit_src)); kmsan_check_memory((void *)dst, 4); KUNIT_EXPECT_TRUE(test, report_matches(&expect)); @@ -467,13 +497,14 @@ static void test_memcpy_aligned_to_unaligned2(struct kunit *test) kunit_info( test, "memcpy()ing aligned uninit src to unaligned dst - part 2 (UMR report)\n"); - OPTIMIZER_HIDE_VAR(uninit_src); + DO_NOT_OPTIMIZE(uninit_src); memcpy((void *)&dst[1], (void *)&uninit_src, sizeof(uninit_src)); kmsan_check_memory((void *)&dst[4], sizeof(uninit_src)); KUNIT_EXPECT_TRUE(test, report_matches(&expect)); } -static noinline void fibonacci(int *array, int size, int start) { +static noinline void fibonacci(int *array, int size, int start) +{ if (start < 2 || (start == size)) return; array[start] = array[start - 1] + array[start - 2]; @@ -482,8 +513,7 @@ static noinline void fibonacci(int *array, int size, int start) { static void test_long_origin_chain(struct kunit *test) { - EXPECTATION_UNINIT_VALUE_FN(expect, - "test_long_origin_chain"); + EXPECTATION_UNINIT_VALUE_FN(expect, "test_long_origin_chain"); /* (KMSAN_MAX_ORIGIN_DEPTH * 2) recursive calls to fibonacci(). */ volatile int accum[KMSAN_MAX_ORIGIN_DEPTH * 2 + 2]; int last = ARRAY_SIZE(accum) - 1; @@ -515,6 +545,7 @@ static struct kunit_case kmsan_test_cases[] = { KUNIT_CASE(test_uaf), KUNIT_CASE(test_percpu_propagate), KUNIT_CASE(test_printk), + KUNIT_CASE(test_init_memcpy), KUNIT_CASE(test_memcpy_aligned_to_aligned), KUNIT_CASE(test_memcpy_aligned_to_unaligned), KUNIT_CASE(test_memcpy_aligned_to_unaligned2), From patchwork Wed Mar 1 14:39:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Potapenko X-Patchwork-Id: 13156069 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 85789C64ED6 for ; Wed, 1 Mar 2023 14:39:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2236C6B0075; Wed, 1 Mar 2023 09:39:46 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1D3B76B007B; Wed, 1 Mar 2023 09:39:46 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0745C6B007D; Wed, 1 Mar 2023 09:39:46 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id EDE0C6B0075 for ; Wed, 1 Mar 2023 09:39:45 -0500 (EST) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id C16FB40790 for ; Wed, 1 Mar 2023 14:39:45 +0000 (UTC) X-FDA: 80520588330.16.CAE4667 Received: from mail-ed1-f74.google.com (mail-ed1-f74.google.com [209.85.208.74]) by imf21.hostedemail.com (Postfix) with ESMTP id EF2341C0002 for ; Wed, 1 Mar 2023 14:39:43 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=DcQhFeZ5; spf=pass (imf21.hostedemail.com: domain of 3rmP_YwYKCJk9EB67K9HH9E7.5HFEBGNQ-FFDO35D.HK9@flex--glider.bounces.google.com designates 209.85.208.74 as permitted sender) smtp.mailfrom=3rmP_YwYKCJk9EB67K9HH9E7.5HFEBGNQ-FFDO35D.HK9@flex--glider.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1677681584; 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-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=h2FIkUEqU6YxkmcIL1AtVszo9ZqqtqhQ8yghIzSXGmA=; b=lw95epjBeJtyEZi551AxneSnYKUSGZYywho8xopzUi+ryn7eruwi+RZ3OLHjcH17vmRXnL nIeF+wr+qM3ggnpA0yKM3We8dgfM142jjjyBEkacowDlQ7+jkkNUiOMvi3Uw44N8CnCVcG QqfHUQ1tC2Y/EHie0R02GcyYizRxhJ0= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=DcQhFeZ5; spf=pass (imf21.hostedemail.com: domain of 3rmP_YwYKCJk9EB67K9HH9E7.5HFEBGNQ-FFDO35D.HK9@flex--glider.bounces.google.com designates 209.85.208.74 as permitted sender) smtp.mailfrom=3rmP_YwYKCJk9EB67K9HH9E7.5HFEBGNQ-FFDO35D.HK9@flex--glider.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1677681584; a=rsa-sha256; cv=none; b=JMHMZU7J8mjlLFAjijbDZfYlzGZaxsW2mHQWhNCtYUgvd6vVkPzUJr0LmFtnR3oWS9Z1mt 6yO5YSROp7hv7pYRIKcE6btnYgNrO/BJ4zvo3QloNcUaIBNHQSj1e2LLoSMFG2JucNxsNQ 8Kq1Kb6Pp7T5zJEvW8ZdjjRcM1oCl8M= Received: by mail-ed1-f74.google.com with SMTP id da15-20020a056402176f00b004ace822b750so19599450edb.20 for ; Wed, 01 Mar 2023 06:39:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=h2FIkUEqU6YxkmcIL1AtVszo9ZqqtqhQ8yghIzSXGmA=; b=DcQhFeZ5qGp+AKIQFJAYw7mSn3Y3zdJdiwbFpjR09nWHgumpyTqJ77smBudhJx90b2 +of4MO5DstJZPnWALbM1Of06Za2o7NytkJzXNNFiETyWdzrdaTvwzeqjQvfk8WKO4zWX nZ+35n8p65W1JWEwmllJK+DRCas7pBVJAabnp3AlbmD9fL442oIjUjwwK9Aw0IVzmE4G LaCLGdq2wBlsOXftBi7owZAHb13CKHLWbeuJyMfJKrGq7rXdtXxsVCEBJ1eC4cyZayTC p0+kMXLSlqoFuK/nAnKUEN/l83vYbnRP2DpS/RVn8EjMzruu3T02ZPom1pnLs708E3j1 cpHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=h2FIkUEqU6YxkmcIL1AtVszo9ZqqtqhQ8yghIzSXGmA=; b=mD2jCkLkbNfEoI7Jx4s04DirGykZv2AHpDnhfr0ruj5TKbMG2wg1k3wknB5P0rtDKG MtJYLr1QP+9YHjihN4dkPjPs1YVhyh8TvlLb06izE8cKA4v6S5cWJ6rdo0rLhvOPov1/ WFk+b1cDqtoL1uLHAsPy8ZSFW1YEQltAE8Zy8yEs0MNwdbvI9iOHmKWJfi5/yk/Iehr6 xw0LjFFtoP2uVBOdx1/FkUZjj/RQ+jUdde33/rsJGnZC0f31j5W4g3gjOLod9oD8gWPl 8xlbhAKOlX03aBPwxe8/VNVqG8XnLaDIYnA4OJWmKjHQfgzZ3a3rkiRW07mb88QB9eu5 tGgQ== X-Gm-Message-State: AO0yUKWRPOcYUiij69xS30SmAMy1kmvTwdPWdZdJwCOagP0FMl04NUv+ YdoCIjMzD/ane/cSqMUGlNGl6zXHBSw= X-Google-Smtp-Source: AK7set8s3Ggkq5cG5lUrm0qbBrwvCtbXX/8McRuVafkppgzT3vG80DIvRRgW6QRGvNCDsu1QYruyNWhJhlw= X-Received: from glider.muc.corp.google.com ([2a00:79e0:9c:201:3c31:b0cf:1498:e916]) (user=glider job=sendgmr) by 2002:a50:aa8b:0:b0:4ae:f648:950b with SMTP id q11-20020a50aa8b000000b004aef648950bmr3893580edc.7.1677681582665; Wed, 01 Mar 2023 06:39:42 -0800 (PST) Date: Wed, 1 Mar 2023 15:39:32 +0100 In-Reply-To: <20230301143933.2374658-1-glider@google.com> Mime-Version: 1.0 References: <20230301143933.2374658-1-glider@google.com> X-Mailer: git-send-email 2.39.2.722.g9855ee24e9-goog Message-ID: <20230301143933.2374658-3-glider@google.com> Subject: [PATCH 3/4] x86: kmsan: use C versions of memset16/memset32/memset64 From: Alexander Potapenko To: glider@google.com Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, x86@kernel.org, dave.hansen@linux.intel.com, hpa@zytor.com, akpm@linux-foundation.org, elver@google.com, dvyukov@google.com, nathan@kernel.org, ndesaulniers@google.com, kasan-dev@googlegroups.com, Geert Uytterhoeven , Daniel Vetter , Helge Deller , Tetsuo Handa X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: EF2341C0002 X-Stat-Signature: juaebz33xa3qt8h6kzaeqic51e7b1xep X-Rspam-User: X-HE-Tag: 1677681583-536785 X-HE-Meta: U2FsdGVkX1+izTPYQCeC4fqQ2MAD1IDj83ezkKLECMXcB0CxCYg0+MCXKEJKIbuVN7lKuy4VnlMHPfrKldw4YLStXXmTGu48J0wD6HjrN2Q7anKomDjZPZ2biKVEBAZt1IoWKmZjdWWnTlpi1GaQY79cfzvl/gm5O4bWgbSWSqzrJZQBjPlYq1M+H+Y2CU+5oS1SNQ0fWCv3zoduz7qB2RYG7EpS3T6KOjMtj1a7SpfaukzU8l+7BnniuaYffw6Dg7mcxIZpgzXn8fjjq4c9Z4yD6XkjOBwkAc6dCxeLy5QqAo9+8U0Fk7geqjabxYyesSsm+e1MlB0OZ6Fl4qRZaRJ6uZD6apRTLHNRRq1ahtMv2GjywmvK1BFmnIMDymcAO7V7Zq4I/+qTT9ntLFN1aeyzvakU0Qplr8eBSilBIPov9SrhqkBZTYFJEzFuvBQhfWZBlMo9SKP2Z68WfJyj9Ot3/51joachAV4AWrhMDEOtonFygUPGHjRTkbSQBSSNn+GCWaA8qUVmqHb2aoJwiVnr+zJ9cw6owMuA3fvafXfkofinoqURjxD9FV7NKUyc0FnkgaRJniRCbS9RnaLzhI+Wt4kWyePaKmuw6nyVpNV2Vdjqd9Vv7TmL2mE3DJSF1AnKUOz0q4Yot63hkRVLiyHP/CUFkI9vh9PIJtHRGK3qLV8Nek9SO/JlzqQE5ZgEf/RfDTsIMrWuPf7YmmlJ1IqdA1+91HBrUAoWxdAleh2NTAAGT8Pjc7CmjXeBPiH+uHG43VmCx74/7CyuypsPxfqZvy2ttXT6J+rdHhZDYjCTA2WciOyOP7JZqLg1B1MEfJFXbbkrKyqmVM6e2UERe0CGB0DK3oVRz4PUvZ1VYRiTWv4Gc1xtJ7ZGJA2mbTApzks66mlFvqkdyuIhfWUKJPwnvx5n+x0K8El8M1UGXP7TzkAAJ+d3qhdKxbTk6disBbFKMSO2c8LzDHDnSBH WrbsFcE6 /BrLPXyy5CBTNzlTC4LIQsGYcPf2aBxIB2eGWtpo9Kw0OYajTW0uW3NoUy8lRm2F7hd2IdGSn35IxokRP6Icig1kKiyy4fC4FFIjM+WbwmvgKCECUelZoGqjrbH+8G23FsdJqnWGpOL25b/eq4ujevA+pOiKMkla9VoRyqH5hrb/3nIDGQdxdfOn9fb9kGambtVh/kxgKYPs/B9OzOdfnKtBlee90jvQnmJ5eELOKZCjGZo05MGef5Hjfx/EfrPD+fFkD7cU56NYY8+ZeIEPWXWxwNAkMLA6+w6Spudiy6gDMz1vwWKxc8kkFOBRUsnBUTmrYby9LohYXR1oW/L9taXM3tnY1HcPuyrUnPpS1+yfSGzybocXlFsFvENQNqVwKgJa/fLeKF+lmeMunCyGeqkil2VxuQslp+fowE2NlFCARA38q9Y0QoGB9PjgdBp9Z9XWIiWcyQmtz5SNcDdSZyCT4AtaBYMq2Tk7nnhO2deRkd7Vh0AGSMTl986+dorU4n+QLsy1tXerkce5CNIhrgJzYUJCv5ihaPuPzYdiesnuv06hbJLzAZy3onOqKJ/qwYkmu15XEpGzctQesIKWzaNFyYw== 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: KMSAN must see as many memory accesses as possible to prevent false positive reports. Fall back to versions of memset16()/memset32()/memset64() implemented in lib/string.c instead of those written in assembly. Cc: Geert Uytterhoeven Cc: Daniel Vetter Cc: Helge Deller Suggested-by: Tetsuo Handa Signed-off-by: Alexander Potapenko Reviewed-by: Marco Elver --- arch/x86/include/asm/string_64.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/arch/x86/include/asm/string_64.h b/arch/x86/include/asm/string_64.h index 9be401d971a99..e9c736f4686f5 100644 --- a/arch/x86/include/asm/string_64.h +++ b/arch/x86/include/asm/string_64.h @@ -22,6 +22,11 @@ extern void *__memcpy(void *to, const void *from, size_t len); void *memset(void *s, int c, size_t n); void *__memset(void *s, int c, size_t n); +/* + * KMSAN needs to instrument as much code as possible. Use C versions of + * memsetXX() from lib/string.c under KMSAN. + */ +#if !defined(CONFIG_KMSAN) #define __HAVE_ARCH_MEMSET16 static inline void *memset16(uint16_t *s, uint16_t v, size_t n) { @@ -57,6 +62,7 @@ static inline void *memset64(uint64_t *s, uint64_t v, size_t n) : "memory"); return s; } +#endif #define __HAVE_ARCH_MEMMOVE void *memmove(void *dest, const void *src, size_t count); From patchwork Wed Mar 1 14:39:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Potapenko X-Patchwork-Id: 13156070 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 6941EC7EE2F for ; Wed, 1 Mar 2023 14:39:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 075806B007B; Wed, 1 Mar 2023 09:39:48 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 026EE6B007D; Wed, 1 Mar 2023 09:39:47 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DE2636B007E; Wed, 1 Mar 2023 09:39:47 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id D06A36B007B for ; Wed, 1 Mar 2023 09:39:47 -0500 (EST) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 936771A018E for ; Wed, 1 Mar 2023 14:39:47 +0000 (UTC) X-FDA: 80520588414.28.A953D88 Received: from mail-ed1-f73.google.com (mail-ed1-f73.google.com [209.85.208.73]) by imf16.hostedemail.com (Postfix) with ESMTP id BFDF6180020 for ; Wed, 1 Mar 2023 14:39:45 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=cATkgsuo; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf16.hostedemail.com: domain of 3sWP_YwYKCJwCHE9ANCKKCHA.8KIHEJQT-IIGR68G.KNC@flex--glider.bounces.google.com designates 209.85.208.73 as permitted sender) smtp.mailfrom=3sWP_YwYKCJwCHE9ANCKKCHA.8KIHEJQT-IIGR68G.KNC@flex--glider.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1677681585; 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-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=nI6aPFa9WKtq8ZRbJBabpyygWI3BetO7s5boeToCFf4=; b=q8LYDzKCvBtAalAaAkArvX7Liy2P/5CG9OFP+LEevgkSSer77zKlSKh9fhTYs9fVd5VCmR b6dSMivETrOZ6Fr2mQeud8GaTrud9izGYsb+IWQXk3JAEuyb81YfeLRolNXu6Wn50QfpRL GEbr3LrOR+QlbZHBUQoawxnLm9CEzyk= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=cATkgsuo; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf16.hostedemail.com: domain of 3sWP_YwYKCJwCHE9ANCKKCHA.8KIHEJQT-IIGR68G.KNC@flex--glider.bounces.google.com designates 209.85.208.73 as permitted sender) smtp.mailfrom=3sWP_YwYKCJwCHE9ANCKKCHA.8KIHEJQT-IIGR68G.KNC@flex--glider.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1677681585; a=rsa-sha256; cv=none; b=XEO3qiL5R2Pp3N0U8Gx1ixCd/9zeAJXP6xIcqEAympyaP3KKJHypt2kP5l2fAO5SMf60QN bkAHw2/zlFyP34XE1IqpmrfDef52LTYlhwfIuU++mNnl7CxGVy1k+h2KIfekjjVtSwOsYY xXOuWx4+oo5MDb06KCIU0ndCwlDuU+0= Received: by mail-ed1-f73.google.com with SMTP id p36-20020a056402502400b004bb926a3d54so4263743eda.2 for ; Wed, 01 Mar 2023 06:39:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=nI6aPFa9WKtq8ZRbJBabpyygWI3BetO7s5boeToCFf4=; b=cATkgsuouPJkBNjeAYA9+s1iR8apIqRMfi4XOoGeFHMEhEog2NEsq1DeNYIGai5Ak0 S3QmO80XpPCdudI8YFrtI32Eypmi77dH6qEyo+Fn16KbadIvqPWwzVb1NhC+Ap8tLi1Z 7/6EVmJlQHOY5Zxc9ILO9G3PR5FLohvlv81MJ6rJ/QZUcZOrNn3i34tb9JgkpYewI1U7 WRP+37VMuNFxMMT77lhKdJzvbMo5ZiHyh7h6ub9R8P004bZq0qY3Jl/0n2yOj+DeB2iO PbgCdp3Zi+2+zhfH98j+JOYUrHnfzL9wjwB4dlavlx2rz6xKg4yx7lSVUSBcOjrrNuc7 lAjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=nI6aPFa9WKtq8ZRbJBabpyygWI3BetO7s5boeToCFf4=; b=1GJ3hsmIvb1Qsng1Xo08q5HG3QfvNu+XI/3K4JTdbaeqpt5OVJRTYPpDsiLDXUowis 7LjbjUHLL0u8rSXZyRBZtV5FjxwUJgU+akS6ej06x5fPM28yVzXdny3deHs/7ySH4kfl lMBBIxUtCPbr5obFzWljOBJqJDM4wHxP8f2AVyDwXc80gdiepzSLZfet+fUozwij+juf DrwdEXVH5vlv6man80cYBQVDamaepWjuz9Y37A17XVrwWSw3YM9wrKwViZF4gWHVm0P7 a0OCQyr6vy2z2XWw/4VbW9I8A/4PeB96jCw2YLb7GwB3QMQMJCFK7iIsnASnq1FiHrhV CCwA== X-Gm-Message-State: AO0yUKVyHq1rq3/pWUFwGH2KNQFhG0541uuVkKOhgYZ4UJmu0EcUuEfq iMnkGlfSCocAWQD2v6Hx7pL4PN0qCWE= X-Google-Smtp-Source: AK7set93S1q2C0fosEy31BA46EXe+QoNnTidYRE1hF4D1mqRDUvDHPSE18kwxyuL0JHbses5B6pE+oEH8Vc= X-Received: from glider.muc.corp.google.com ([2a00:79e0:9c:201:3c31:b0cf:1498:e916]) (user=glider job=sendgmr) by 2002:a17:906:ce59:b0:888:b471:8e18 with SMTP id se25-20020a170906ce5900b00888b4718e18mr3181793ejb.8.1677681585154; Wed, 01 Mar 2023 06:39:45 -0800 (PST) Date: Wed, 1 Mar 2023 15:39:33 +0100 In-Reply-To: <20230301143933.2374658-1-glider@google.com> Mime-Version: 1.0 References: <20230301143933.2374658-1-glider@google.com> X-Mailer: git-send-email 2.39.2.722.g9855ee24e9-goog Message-ID: <20230301143933.2374658-4-glider@google.com> Subject: [PATCH 4/4] kmsan: add memsetXX tests From: Alexander Potapenko To: glider@google.com Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, x86@kernel.org, dave.hansen@linux.intel.com, hpa@zytor.com, akpm@linux-foundation.org, elver@google.com, dvyukov@google.com, nathan@kernel.org, ndesaulniers@google.com, kasan-dev@googlegroups.com X-Rspamd-Queue-Id: BFDF6180020 X-Rspamd-Server: rspam09 X-Rspam-User: X-Stat-Signature: g9hw6gphcawekfkzhythzjn4ohz8uxck X-HE-Tag: 1677681585-300527 X-HE-Meta: U2FsdGVkX18JA74lFfrdN85BAY8wo4oOpk1CCwNiI6RmrtofAsUElmaaRm/e4Szl6NSqmVzJt7omjexw7TKMqLaCEqnb57lMDLK55/EyAV/6t8STswvvmnPt0sFdgjHVkEH20M1Fw9MCJKXGaRAK404J4TdguH/UYTh2U4H1ORosSXmP+6c75otfwpUEzKF0MGLYEVN5iPXSomnaiSbzDYJZOVXX6waLKiUuyv7EbJeXtfVDoRUu7+x5F9RZ5G2N8WKNZ1Fre/s+HWSPpJMyl9nHe+tp884cBXfnh4k85fjfldY05CucKPZIGTqCAuygqkqEDlb0DukcuBIhyxBYRyavBpA08qHx6QmTp9TAMV5URsCEXgc+vRe3NKrLAMYrMFabv0luImlGvRbAzNIdhiphlA/pmNlftTOtorWYX3IyXz3dLX0V7oMVwSLyfAt61C9fmm6UTBonF45uCJ/qfyM6/lvXGfs1Ahtzw61ejnod7SoosNLTwtURa1lV62GsbiwdBirbsFw4+ZsytnhkDpvIJCBu0WCmBV4Ls25LEf9ShSwREM5xhy7oa16TJqZswzN3Dj3kiudCWm9q/ZAewydEQXBgrhOMkuHcWou03poIZo2kkaQxB0jfESesdWVHWS8GL+NTwpEyhilWIZNptGVlHqQe7JqXgWS9VvV6/eshvbTHwuuTkdh79iGKWAYaeQc/lkXtYpGWyShcyviSsjAs8VwIQA0omYAFON+Rto0hv7689UdgLVqQg1f6Q3JTtAfyDsWUAg/HUd4cGdJ2mvEpRtK98pLxbm5LJ6MLb0Ykf0/9l6Wc+cqHhHTJJgZsN4fnL5MQ0+67+SqTVlbrtPRBJe+Ggei+Hcn6dfsqKIOJWK7tQtHE9GrhLnR/mapeTC1ZSLle8rX7HbPseqrchTw7DC7/8A4GMue/SI4GwtgswR/1fZ02HLXSNZIJIpxD/0K9vXsfUgK/bg+B+3p iS1bhj1Z twEFmFib57D7oPw9ksJ8eUhb8Kpt43O5TSal3a8XLyIEIqpFrdc7kmp5vfwOcvl3T8XG57hZ3Uq5KDuZqXl4MUONvaZ3P9RSbw2jnG7e9ay0JqCXgZzWvLcvURgs10P3e28MuT95pBHk0nq9euD1Z9OkQliw2ROAu1gBLQHMyEWJRPCGtEE/FT32c1k4auXFvrV1zRJkgnSbahXlJ4j+3AMXBmm1nlK1g4BK79ni4Ht76Mj20GzrJGqBFDdWzOEA+/QiG7eW2MCuKWArHRok2XG8bfu2+rr+uWyAkeuQtxV8tRYSzvbV2PwEFVFbasGTe3FK1vlTeQWLX0o5mB9sS0m25wgEE1MDQf2c6Vu3p1tpJpYWO8xVdDlj7Xc60U9PwgYiH+L+DbbCJji1sZcreMsPQdk8Wfx7de3zvVW3HmBnZNLu5aK93KFO+hVWOJu75YLim3JgRYWYRDEGrqpscmblbDRk8/5wsmwlPGggpAUgdYv1FjeVkt1ZzVuLU30AH8mItLwfPBuyvK7+NIVElkJgsG2F6mDzSCJFPxSYrOm+J7s3+YECHJ4Av+efLN746E0bzA7mnNDWaohlc5IN/zGmJS0asYE9IhkwRT9n6gKGzf2LM7cGrML4K8A== 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: Add tests ensuring that memset16()/memset32()/memset64() are instrumented by KMSAN and correctly initialize the memory. Signed-off-by: Alexander Potapenko --- mm/kmsan/kmsan_test.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/mm/kmsan/kmsan_test.c b/mm/kmsan/kmsan_test.c index cc98a3f4e0899..e450a000441fb 100644 --- a/mm/kmsan/kmsan_test.c +++ b/mm/kmsan/kmsan_test.c @@ -503,6 +503,25 @@ static void test_memcpy_aligned_to_unaligned2(struct kunit *test) KUNIT_EXPECT_TRUE(test, report_matches(&expect)); } +/* Generate test cases for memset16(), memset32(), memset64(). */ +#define DEFINE_TEST_MEMSETXX(size, var_ty) \ + static void test_memset##size(struct kunit *test) \ + { \ + EXPECTATION_NO_REPORT(expect); \ + volatile var_ty uninit; \ + \ + kunit_info(test, \ + "memset" #size "() should initialize memory\n"); \ + DO_NOT_OPTIMIZE(uninit); \ + memset##size((var_ty *)&uninit, 0, 1); \ + kmsan_check_memory((void *)&uninit, sizeof(uninit)); \ + KUNIT_EXPECT_TRUE(test, report_matches(&expect)); \ + } + +DEFINE_TEST_MEMSETXX(16, uint16_t) +DEFINE_TEST_MEMSETXX(32, uint32_t) +DEFINE_TEST_MEMSETXX(64, uint64_t) + static noinline void fibonacci(int *array, int size, int start) { if (start < 2 || (start == size)) @@ -549,6 +568,9 @@ static struct kunit_case kmsan_test_cases[] = { KUNIT_CASE(test_memcpy_aligned_to_aligned), KUNIT_CASE(test_memcpy_aligned_to_unaligned), KUNIT_CASE(test_memcpy_aligned_to_unaligned2), + KUNIT_CASE(test_memset16), + KUNIT_CASE(test_memset32), + KUNIT_CASE(test_memset64), KUNIT_CASE(test_long_origin_chain), {}, };