From patchwork Fri Mar 3 14:14: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: 13158846 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 40407C64EC4 for ; Fri, 3 Mar 2023 14:14:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C6C9E6B0074; Fri, 3 Mar 2023 09:14:43 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C1E596B0075; Fri, 3 Mar 2023 09:14:43 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B0BB06B0078; Fri, 3 Mar 2023 09:14:43 -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 A1B0F6B0074 for ; Fri, 3 Mar 2023 09:14:43 -0500 (EST) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 61A9A408DA for ; Fri, 3 Mar 2023 14:14:43 +0000 (UTC) X-FDA: 80527782846.19.3AD0F47 Received: from mail-ed1-f73.google.com (mail-ed1-f73.google.com [209.85.208.73]) by imf02.hostedemail.com (Postfix) with ESMTP id 8DF8F80016 for ; Fri, 3 Mar 2023 14:14:41 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=hMY2yJzs; spf=pass (imf02.hostedemail.com: domain of 3zwACZAYKCP4mrojkxmuumrk.iusrot03-ssq1giq.uxm@flex--glider.bounces.google.com designates 209.85.208.73 as permitted sender) smtp.mailfrom=3zwACZAYKCP4mrojkxmuumrk.iusrot03-ssq1giq.uxm@flex--glider.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1677852881; a=rsa-sha256; cv=none; b=eFQtSmYn65ZdLBLQ2t4h0Pzdhv086MPEFY0Wp5KEfkkEAKhcZlL6hh+CxDf6W/UlGDEoFt C4etSswwcGBmzzBhJ1Zm+8PwTDc1IZxIjFC3E5rezJGxMiXgrg+HwtwwETs/woW/OFECjP gkWHnbIdul2goaUL/YsKtQPspuQ+m2s= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=hMY2yJzs; spf=pass (imf02.hostedemail.com: domain of 3zwACZAYKCP4mrojkxmuumrk.iusrot03-ssq1giq.uxm@flex--glider.bounces.google.com designates 209.85.208.73 as permitted sender) smtp.mailfrom=3zwACZAYKCP4mrojkxmuumrk.iusrot03-ssq1giq.uxm@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=1677852881; 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=2N/CPy1IFmLQesHjkxJB5VDmlDO65TUQOL9xC78XNWQ=; b=j7e9vAyNK4tvKMfuz4zcyocuo27XksJSZ0zDj9CKkFW3x+41KM3LvcYbPOIUDFncAX/+2g HulYXA+YrMGeMPrNRwO0cJbDWueDd+vfxIkcLDzyeUE5hXIup/Y9qhbGtdOEsrHtTmcL1e vRnhT9ouGl3PUSJ9x1rTMX/n4SmFqEc= Received: by mail-ed1-f73.google.com with SMTP id t9-20020a056402524900b004af59c073abso4181457edd.6 for ; Fri, 03 Mar 2023 06:14:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1677852880; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=2N/CPy1IFmLQesHjkxJB5VDmlDO65TUQOL9xC78XNWQ=; b=hMY2yJzsPf2YWJ9SnaLFMvgZa7mnCcGkPNLMoITa/8FWMXegqQl7kIJo/qWbFtv42K JUF3gcDP0cfK67S+1mdFC2TbAWAnhoc3q+tRpdXFcLyhBGTf0Opvr/qYA8Z6Oj+oe1PO azhktU12eLJhoB1eKldndx4jeQwB0Xkm5Yro83Pn9TkvQpP34l1jQU1wvOMFDuojTwoy nr3zYZv12m4lPIMp4NLUZBH3EtP7QEL/MlNPFBicPOgSwAROS0En6PD9ETZi/dZ8EYZt S93zuhDgiY/Zn126O3o8Vab4eMVHJMeE2Mpw/mURlt/0t2gHwSJCXA5K1fqYu1PAdxYy lHZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677852880; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=2N/CPy1IFmLQesHjkxJB5VDmlDO65TUQOL9xC78XNWQ=; b=wE54duVG8PtUNetYMvjxtecXoJw3DinaopPcq+E1oyl0aRhWMTYx/VrIg35hZUwGjb fVqxAO8VHxXm3RPghwL/cJ5em1Qoi+BveZM/7dgDzxPbbG87DwkxYX9yiTceBfZD+CY3 Gset+G34b2F9K9EAxlpahU94vlxWGmRq1IQLc6ExdsWeDDpoqMHauo+PWRMOE4FqmrrN zIonodyJa4ZFeaQUlMMTs+TDzQ86s8vvUkrXqSUJIx+XJSgwRHfcKoVMwKf0RpP3hfJY 0vpHBeA82EYhjTxTbFm3IFyzz0U1kl9cikFFoGfZr0ugvgFSi/H3xbNFylewC07Ai3Vd LQow== X-Gm-Message-State: AO0yUKU9a3fdlU+nWnur8lpyugus7ioqIz3B9jBUV1MBNbGb6yT5PMYt PQyXld+cZBZX/N5ZZ7vul9spB4O0Y7Q= X-Google-Smtp-Source: AK7set/QK/eNvPtl5qmRXYLEBXFksBQrVDShOV/MqLWGsB02mS/d8mUxfHAqI+8j0Y0o6fWedP51UKjMacs= X-Received: from glider.muc.corp.google.com ([2a00:79e0:9c:201:f11e:2fac:5069:a04d]) (user=glider job=sendgmr) by 2002:a50:ab1e:0:b0:4ab:4933:225b with SMTP id s30-20020a50ab1e000000b004ab4933225bmr1157914edc.6.1677852879922; Fri, 03 Mar 2023 06:14:39 -0800 (PST) Date: Fri, 3 Mar 2023 15:14:30 +0100 Mime-Version: 1.0 X-Mailer: git-send-email 2.40.0.rc0.216.gc4246ad0f0-goog Message-ID: <20230303141433.3422671-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-Rspam-User: X-Rspamd-Queue-Id: 8DF8F80016 X-Rspamd-Server: rspam01 X-Stat-Signature: y3tqhue7igsxrid3ktgydd6uusswjpky X-HE-Tag: 1677852881-825806 X-HE-Meta: U2FsdGVkX19sWXms9gR9igAVfKxhnUD1uh8QgeCGL5+KON+bck9RiLcmOipy4IASa2/dzwpqWGxLLA6PP3azHMOBVUcL8OSdfqYcPmMMUCA2+22g2ovvcSpR3o9VbbcRicANRFs5blO1Hkvmm2LyZRYnutfqW5Iu4RV4+Iy6OTF8IKxJMjxjIj9XcWpoZQ7fUnmH8qyg6g5grggrxfo9yIpxuQwiFHd38T3mxfSJhP4StPzKyWZ3NtCdybGcxu5S+1mPutHddx3ffrhU/yTQK9F8C7KbOdhWBrIbHrW/W/kbw6SnSjWsvUkoNu/DQnkQAMv5PBrDFUbC/Ds+DQyR7CnnLu+s/7+4WlsKaIsenBfawl62/cyt4VMWe25mi+WyR8VEB5n0Ofq1WUVNrC26hSrO4EjGD42XxwNpNlzeBxhxVDveOnj0F57Y9J76J/Cr0kjzJoeVFRn6W/S2A+5qtpCzMZtThpIW032mZX1+F0rxD7w847UH3zgP6QFE7mYvc9KSGtRyCwnYrK9n9cPiLnUkPskwVIW7gGoVGSYDn8KwmyMeRWxU/VQkFE4AsKjCZlqpCnY8VIwNu0ORfIEmmpK1kH4pyMazPtHLN4zZzlq3hgsizY6Kkgay0HpdXYBygElnPe6ETZvZDfoz/OdSyYjf1o+KIce4wdPptG4QeZqO0enZrVjCh+TXJSkvCLR3kiztCu2rN4VcxGyNvBotGRdILmon0mW+ciEEx1/Hbc3eeHevDMbdhEdMqNBkVflErStaXt2a1W/qHtGnAk8wtZZEC2dhi+13O/cNJOdwuHClFyRB1jbVov6DFXcBOu6JZTYVQebL4mBjo7B/nO5nGBrpG+TlaEFSKuYM63soQgAV2ve7mo843QflY4FoxtSxHGeNkCuNsh3EpmOlS4A1BT2MarLRkDlXWtnM3r2C8X6FSA/fF65MwJ+88duP92T3Vd1pmKkf3DWQ72bZTBe LR243cf0 7FkO0q8TSjrOus+LNAVckGYcLWv/Q5GLrh86i+eLQkUdZrmPCxbRpq422aJL9vlDv8NcoEV623S1G2pzjZwh5Lp9icKSWh1rBY0oFU39oDpw9T6qvURc7IVyhG60B6xbsuCqoKe6idAgzC8V1CRzxDrwT3xRh1PBf0K9ldDW53RE9Sh1ozyy77TFpZ9MuYO99WUNvjI3UmJWwRXTz4xPRxhfrzOilEPOk+Z93rTDOodFXC0HDTTbymzKEq2orCPx90TJiXqAM1AnSkXGkTHg/A3xNN9C1x/qyADmrn5uN7gqAzF4K0Iu9j4Vh/XsUsHEQ1nZFUNCZ9VYq6neCb06jekocbCjep8voNGsY8GaKVJoCQg2TKrp+vamXwwyXUO5cYhHNjQRtg6EAVID6KXzMQmI9Ee3A2wJwZZrAqTaZ5H08m+EtRFp83AEvlSDPOYkVYGopZjEdxiiLOSz7MIlivBQc5rbEVj6oauzjlH60ibO7cvkFi9Ep3rvTflREhN7ohrTar6DyMFgnTbyRFt/GbS9VSTSaMmn9W+A3BhyZjiFud8oG/n81Lnk7Vq0SHHtx9lFmJuh06Si/J/cz4VFYovVShsaBCDKOqLbQJqVRwp18b9SSTq4WCLAeubL99+HwaIf2mAKTygySjTs0mwABqbjxqKh75v6EkxF6W/KxpPofiDPM0UNRZjmkZA== 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: clang -fsanitize=kernel-memory already replaces calls to memset/memcpy/memmove and their __builtin_ versions with __msan_memset/__msan_memcpy/__msan_memmove 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 --- v2: - updated patch description --- 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 Fri Mar 3 14:14: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: 13158847 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 5311FC64EC4 for ; Fri, 3 Mar 2023 14:14:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B34976B0075; Fri, 3 Mar 2023 09:14:47 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id AE44D6B0078; Fri, 3 Mar 2023 09:14:47 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9AC3F6B007B; Fri, 3 Mar 2023 09:14:47 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 8B2D16B0075 for ; Fri, 3 Mar 2023 09:14:47 -0500 (EST) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 5AC191A120A for ; Fri, 3 Mar 2023 14:14:47 +0000 (UTC) X-FDA: 80527783014.01.FF2E6AA Received: from mail-ed1-f74.google.com (mail-ed1-f74.google.com [209.85.208.74]) by imf07.hostedemail.com (Postfix) with ESMTP id 5C6AB4001A for ; Fri, 3 Mar 2023 14:14:45 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=ZfSfmqBM; spf=pass (imf07.hostedemail.com: domain of 30wACZAYKCAQkpmhivksskpi.gsqpmry1-qqozego.svk@flex--glider.bounces.google.com designates 209.85.208.74 as permitted sender) smtp.mailfrom=30wACZAYKCAQkpmhivksskpi.gsqpmry1-qqozego.svk@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=1677852885; 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=NzrUAKqOf4lIqj2sXdyqoZ2Q8eXyDe5JYgJyXOtPsCY=; b=WQhv3TU2y877Xv20FD2r4dFfMpWKZLzCt3uLIOpvO32EvhihDmJOmnTjlKg9bF1CVHQ8Ri 5XfgwupE5VCCewcwUSZWrLUx0O7MHx+p5LlLkjcOasbH2snhGB++AvMyAZv1L0NhLZZSXE 53cFKbaIFsrnvk8oOKzSULsZ1zBReAU= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=ZfSfmqBM; spf=pass (imf07.hostedemail.com: domain of 30wACZAYKCAQkpmhivksskpi.gsqpmry1-qqozego.svk@flex--glider.bounces.google.com designates 209.85.208.74 as permitted sender) smtp.mailfrom=30wACZAYKCAQkpmhivksskpi.gsqpmry1-qqozego.svk@flex--glider.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1677852885; a=rsa-sha256; cv=none; b=oFhiYqHmeXGyY5VUuVo8pRedITFLtRAC6rVnZPA+ycx4YkZzKayMcTj13h36WZFEkzsTVL 53bjw1WAAqXFxCr2cpTDA2mW/HFIwd8tIF9Q6yrO8cHLoQZHKISJDfJWnJ4/SC5hfhwDtR n/llDnuIkVQ+Y9aAuNtd3cfiXtiAfkQ= Received: by mail-ed1-f74.google.com with SMTP id fi8-20020a056402550800b004a26cc7f6cbso4199316edb.4 for ; Fri, 03 Mar 2023 06:14:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1677852884; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=NzrUAKqOf4lIqj2sXdyqoZ2Q8eXyDe5JYgJyXOtPsCY=; b=ZfSfmqBMuJ+vwMDxG5i4+5C+tNEglr4loWmKR6Z0RkZfjr+jAbJCKs+E8HdnY+/484 U4Tnah/k4Gjd5sm2yqp/0nKmTL54cbtEXdkKAgXSe42PIyTbE0SRGadQQmam3JIAUfvC a5ouWadlWnMykwg3du4wr7YFd0UA4Nmn97zesSEosU4X3DChC2nSvSKQyOpTfHECBKv7 gZXhfuN9a1gIdRxhqPU3dNXM0LfelTB/RT1xvfB+vRM3dNsvbeS0WfFdt8jqYekhXOzi 337mBrnvoEXkOMuKAADUY1doomtGT8K8uQlYbbOdXMj9ai3/IQ/6zMJlcrmOBZHFmz/Z uWtQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677852884; 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=NzrUAKqOf4lIqj2sXdyqoZ2Q8eXyDe5JYgJyXOtPsCY=; b=vMDJga7kvrlZgIz3VXVXy/3xw5TIe0tuA9DAZeegYgd+2QgxwRJM94lq48oji4qTkH w8Fi7/0/xN0ZU8CTwjzApJ76m8XC0jLnIMvUGKbU3yIeT0FlqPfCJwNTI3T60dXd/RVr 53+1BFXL6SBcwP0FcMew9B4kuk4EP44EK8MlhO71EMUVHuiwTrid8OV7/yo42EV8GAhA vegoegcVZvFwcaDr262SFwK1xITeSD6PYowzpmRlZqb6wOKvSUwHhmHfy6nSzqJl2axr Ot/solYZXDj6avTTyBUSBLIRiOjqk/j/qBWGj3KbifxDknQqLoNQHg2EKxMXrGKRnsCw zyFQ== X-Gm-Message-State: AO0yUKVHiK38vqEL7nnj1mlp9C9cURx2jfx54JsJyqyjbHHqrZ8WHkCy UAk8HzPERiCGsYXlPURT9nvwjjqZLkI= X-Google-Smtp-Source: AK7set/ri2KO3ck28J8157MsDMD6j/YADvayhd/o5Bx0+wq3TM1Izsb9bN9BvUkIU9PbDIbEffR6U3aO/6Q= X-Received: from glider.muc.corp.google.com ([2a00:79e0:9c:201:f11e:2fac:5069:a04d]) (user=glider job=sendgmr) by 2002:a17:906:d041:b0:8bf:e82a:2988 with SMTP id bo1-20020a170906d04100b008bfe82a2988mr938462ejb.4.1677852883928; Fri, 03 Mar 2023 06:14:43 -0800 (PST) Date: Fri, 3 Mar 2023 15:14:31 +0100 In-Reply-To: <20230303141433.3422671-1-glider@google.com> Mime-Version: 1.0 References: <20230303141433.3422671-1-glider@google.com> X-Mailer: git-send-email 2.40.0.rc0.216.gc4246ad0f0-goog Message-ID: <20230303141433.3422671-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-Stat-Signature: xci15ok58r8ktr8fsiw799a6j7c37dqh X-Rspam-User: X-Rspamd-Queue-Id: 5C6AB4001A X-Rspamd-Server: rspam06 X-HE-Tag: 1677852885-191735 X-HE-Meta: U2FsdGVkX1/qFUkO79uywh+teWlfz6Yb29I6xkDmvy4FyukhbTYgGp1Ooa+/i50WMBaKUsTa+sbFi3zKH3JrJPSCYWubO20HC5eOHRNScB1dkf2CQCkUhiSHxjahEk4VlViRxBpM+VHfUYi+kI6TfNQaHpTBbmehXzZC2bfS8Y4pKqKcaEDSFUiyHpuyhWteWMoQwzXcYQ4iljWLYzqE7SVOfiVQ3a7VTH3Lwi0kZhhNvB3qcbVo8Vo69/Df0j8TgcJ92gngYXFZHKKEecuAjrgyeHPF68DLBmFKGL4bJVkc7RSNRVY1UxA6sK9YvFqewF8NSNih8ud6lMYTqH5aB1gBHsg1TylDjoggiCgbtrn9kurjz1jAiMDX2qkZvEDE0HaVUTzkjDsrvbn9JCnMMkol3z9eimsjvzJwINJXmrLDSV9J2MNJ0ER2wFR3cQHqm57IK22zbqXjPgjwjtLGIAk4QIa6jVI/TytFwDaFz5IEioOw3sjcR78iTlakq9YhTw/kDFoAfp5k4z9UM4EVFsepNoMxi8BgOlHdJ6Ny4sBhBT7ChCjAKSVdKqq4V1ZcBPsBLubZVR6DAZAp2Jm/p/9qrFScBEiyrD9vMxzjE7/RxcHQUFLnRhGEVutfRfoL24kUtshg7z3GTRemS2wX1lspnpzcgDJkT4Sauo0Y8oh0s/5TxVemoe8Ce9OtrlRpFOEogLqs1loC7jG/lohaHiGnuiWOQ+Ef6dvQzNYoPIEWK1MjLXufpN9Bu8m5GSSMxm5WvNE0dS+VEYpjIWejV0T494g7n+89IYu1fdlh97Il8UJ64jk2PLudd/vWsGv3WRmuIPeY16YzBY1c6PW1TVVE4SYdrIsYN4yhqbn3wtkK3LMXpFRMQDETZyVHfCoHGXPNcrBo3Tt1RjACi02THQU7Tdg4DtFX2iULBQXuDcbyo9cenK/meQNeakcKfeWA+BdrCuCXsngZw9LquFr aaVsmB7T sGCyLs/NzOiUsEzHvt92csxgl8bRcmfLnWtKTrx601HTwlt/CU4IFPoktGYk+NcL2XeNLoUFmJNtRs3IXtsRbwGmgFiKtPm+3q3vpUsMXFeBVYwXrHB1oHWHoAlGNdirqXVL06FssNCo0HfJu8lt6y1WM5Ii1DWOvNSf1m+9Gmz4lFd1c0OJGLRSNt9UEOA8paZBUPo95vg/A4/E2jOwJhKfBkmMOownLuVh3GOvpNsaPIaaMKPcEzyFfz68H+vHda4jws7ooJPew2fbompwpjAqx3jQWXPeW7ClrUKh9GQVV9qMMV5QY8k/NR1pPlwOt6jUAeMRrwkftYbSi5d7AhnGVmSE/UM+p4mfIApw6Xtv1AMtpAXuZKA+4SeF34Cc1zeaDqtSswchoHef07Ngu+FNqSXS25V/ggmbu3TbBjXZMxQzlwDvN9DUbWt2wunb33/0w5Vrz7Hv7M53dQQeAwGfnLNtfPA6AtBTF2slio/nF4tdnaJi+FHGI3FxjbTAvJRS0am64Idj3KBJmUePUvUMkssXlqohjlzK+PLebsBU8zrRoAtUeBrCx1/dzWFuIn9zBQq4FXPn41tMBWRtPhrok2/v4iV8cKlfEw9DnCsQsfy4eEtiyIeH0bg== 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: commit 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 macro that just clobbers the memory with a barrier(), 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 Reviewed-by: Marco Elver --- v2: - replace inline assembly with a barrier(), update comments --- mm/kmsan/kmsan_test.c | 44 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 38 insertions(+), 6 deletions(-) diff --git a/mm/kmsan/kmsan_test.c b/mm/kmsan/kmsan_test.c index 088e21a48dc4b..aeddfdd4f679f 100644 --- a/mm/kmsan/kmsan_test.c +++ b/mm/kmsan/kmsan_test.c @@ -407,6 +407,37 @@ 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. Same is true for e.g. barrier_data(var). + */ +#define DO_NOT_OPTIMIZE(var) barrier() + +/* + * Test case: ensure that memcpy() correctly copies initialized values. + * Also serves as a regression test to ensure DO_NOT_OPTIMIZE() does not cause + * extra checks. + */ +static void test_init_memcpy(struct kunit *test) +{ + EXPECTATION_NO_REPORT(expect); + volatile int src; + volatile int dst = 0; + + 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 +451,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 +474,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 +498,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 +514,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 +546,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 Fri Mar 3 14:14: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: 13158849 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 8F8EDC64EC4 for ; Fri, 3 Mar 2023 14:21:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2F17B6B0078; Fri, 3 Mar 2023 09:21:55 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 2A1E56B007D; Fri, 3 Mar 2023 09:21:55 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 168EC6B0080; Fri, 3 Mar 2023 09:21:55 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 0666F6B0078 for ; Fri, 3 Mar 2023 09:21:55 -0500 (EST) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id DD421ABA25 for ; Fri, 3 Mar 2023 14:21:54 +0000 (UTC) X-FDA: 80527800948.15.4C4A661 Received: from mail-wm1-f74.google.com (mail-wm1-f74.google.com [209.85.128.74]) by imf24.hostedemail.com (Postfix) with ESMTP id E913F18001C for ; Fri, 3 Mar 2023 14:21:52 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=tlAJFWQb; spf=pass (imf24.hostedemail.com: domain of 31gACZAYKCAcnspklynvvnsl.jvtspu14-ttr2hjr.vyn@flex--glider.bounces.google.com designates 209.85.128.74 as permitted sender) smtp.mailfrom=31gACZAYKCAcnspklynvvnsl.jvtspu14-ttr2hjr.vyn@flex--glider.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1677853313; a=rsa-sha256; cv=none; b=jc8yYea5TPWRJ6TX1ZJJX6Wj2GNMe1MeBaYwL117jMP/NEZn+jwe+qjIgmoftROChxPLcD WLq+2bLZBWYWPeTpGHAhm1Zc+SKb8VOLD67T7/4BJCwpT7Aqr52Vg/c/eU1tTOZZF0mh5Y x7jz8aN7EAa7hi0Eym/c68uO+iCRUTM= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=tlAJFWQb; spf=pass (imf24.hostedemail.com: domain of 31gACZAYKCAcnspklynvvnsl.jvtspu14-ttr2hjr.vyn@flex--glider.bounces.google.com designates 209.85.128.74 as permitted sender) smtp.mailfrom=31gACZAYKCAcnspklynvvnsl.jvtspu14-ttr2hjr.vyn@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=1677853313; 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=NAtSFGVTwhm/tX8WamH/Zd7xaJyhhcixand9gS9KqOo=; b=2vk1coYtjUFZFQ8Fm641iNIXfn1U2it9qI5eujry+kAndjss83EtJEyg10q1mk5iynzejJ nUZ/l5tNe2ZaKIRePKKZbySDQlh9UzCRwbyQ+bh2+rKLG/9Ov0e0RK43lfJYE2LKF2/Ntd 9psN5hbXGLpnykY4Pplbx6iCyu2f+Nk= Received: by mail-wm1-f74.google.com with SMTP id s18-20020a7bc392000000b003deaf780ab6so1072163wmj.4 for ; Fri, 03 Mar 2023 06:21:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1677853311; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=NAtSFGVTwhm/tX8WamH/Zd7xaJyhhcixand9gS9KqOo=; b=tlAJFWQb1a8DmXOV1S6Nv1PvWVzoK80hhYLo2g6Yvo8IYTwFe+UxNximwHce2BtK0K SNJHISOlptqfn9oLcdeY0bKTHs8alEL6yCwSDfU2rYl7sWJunjp0IjUFlItUt/MdaiX4 3vdPU2ZafKLVykHU/WMZX41Ra9tbK+pKU1C7Jm0xThmHLpU1z/Ct7S+NaAbLpQnn/dpq 4IjzWyARt7zP+PhPI7viEdfDZmTobONxyVbjWvTFtYVVOjBVvAJAWr2ACwChWO/Y/3Tm NYIn35yJ2f7jfgaWqnq1cEnHNmTC3dKVMuKhicvVpcjiGzcI3R4p71dHEW9514lXte5f s9zg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677853311; 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=NAtSFGVTwhm/tX8WamH/Zd7xaJyhhcixand9gS9KqOo=; b=NM0hQ61jRQU/LV8CSC42IlDede3XnlggLBA9UcGGRoz04ivG3vlTXjkMWPEHACOykX OgdTwNn2813zF7nEeZT3DsnFYWprNdSKJYQov59h8rVo9WEQy9idwh55IxXru3bz1yTc 8av1R5FtMz1emHg2PDjnVs4udFJXl9/MzpF5KfgLq7qAzyS6uCcuZkaEN6j0NtaDz3l3 S1NnpyoPg5cAmm+IqB3WPzvWd+Br0OwIOUAkr4NluVkBdgtCsYENflYEayeGrOm5IOfJ t1apd3K4ukiqEdMUE8c297YtNmX79Bd4KOUD0nH3B+Q41nodWxzHCTevyjNuoqNN/NNh nW0w== X-Gm-Message-State: AO0yUKXcB+GCZbR4TqPa013OVRxZqOUSZeBWptBzV3VPM/SW5jx73Uqg oNLB5KiX1D/gziJix72e6R0aKXWEQtU= X-Google-Smtp-Source: AK7set9ovVaTOZsd0wnlPkswC0ekqTesP61gdVe/s0v8ISscKbGWSxjuV4vTctRIUgfB7uruGzs1glnmf18= X-Received: from glider.muc.corp.google.com ([2a00:79e0:9c:201:f11e:2fac:5069:a04d]) (user=glider job=sendgmr) by 2002:a50:d581:0:b0:4bf:7914:98c5 with SMTP id v1-20020a50d581000000b004bf791498c5mr1171964edi.4.1677852886570; Fri, 03 Mar 2023 06:14:46 -0800 (PST) Date: Fri, 3 Mar 2023 15:14:32 +0100 In-Reply-To: <20230303141433.3422671-1-glider@google.com> Mime-Version: 1.0 References: <20230303141433.3422671-1-glider@google.com> X-Mailer: git-send-email 2.40.0.rc0.216.gc4246ad0f0-goog Message-ID: <20230303141433.3422671-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-Rspam-User: X-Rspamd-Queue-Id: E913F18001C X-Rspamd-Server: rspam01 X-Stat-Signature: c51dafhnjs4grta6nx1shg9j67niegqu X-HE-Tag: 1677853312-865864 X-HE-Meta: U2FsdGVkX1+NVo8X9rcCebqd8eaE3c6MexD8qaZcMO1239TsNwWxr6fwNVuZkcfmkcAroV6GwURb5LNE7LVXMX3ipfn45TXXAsauEizGbYx8ZEYCq6E4I05Qfi3b4vpOgcV/QWNAi+9//Z+M1Zc2LH+6H990K4v1u+4BOr60b2++/t9jyK8JhiGdChXB57q78l/Rw368TY/rrSWFK3xXzP2UyXx0AXcqSz4ezaYT4jjlTN6wXXjRDCgpgqCskdlM4qR/ZjUmB4UBatCWgGBrvxHXMkQCK1W6qTnJtvbSJ8yYieUw64K1trkjCEKtgYmeIFxsWADBKMCF++dbgbeeDt084FCPbtk2IsDNGTkL3HdTKXZw2U+MuZCyM/LCzeeUXpiJvpRMLwc+yYSAV2am9TNitwWri2wxRhaygYD25GnmieiuZp1y7tteRgVLy7hLNzXA/Ui0XljVP/t7EL+dZZ/smIE1Wg6auHnWxgKGtPxF+tugnPJO1R5IsBtKg9Nd8mLNkxTc+svnVqpGKsTt9tTNCzsWqlAlILVcwsA4XruKBwol/+5PNAGCr0pJiZPs3tXAHUSQ+zZu27b9W1KLaH/JrdBuJ7JF/71SN4rOTQG6tf27Z7Cj+pKmiuOndsBujetTess3lrd2ohvvMXH9bZcP51EbLSU+GcayoTPvFcmFgbLDJ+buc5kAyheInnsmDqF0PxtfmlEKNN6RxVCzOV4/rEEkVAQKQAM8TjGXhHy2PkOXKI+O8y/Rq2iv8zi8lE62QvOGMWJ33bFslgcOsgqVfdR2djlFnCLU2onl7WheGws6i/r+ho6nMku/CU5+Np42maTpsCtIu3DoQQFSg1F97fXOzRVrCY6XP9vL7loCUV95mfQ3JyxeP2CFyfeC8Be0WyYbxewY+wfYrrgSPHCJcrFc8V9BmScOMLFGgh+7Auh+hGRWwp9HEh9FAfHjeZOvgFQj7K6aueByadi tX1fuwEh Y7nYD85m85MYFA0PeUYshyJTWhx5XZQnEN7Z7yRdJ5GKYGuZirqJ3cFNUXBjA9BaMdI+N0hvvnw9rHHe2NFmukeRRr2MrnpJn/ycIYcbPfRmqZU8+8u3nEtT4+r8gv7d+UHXk/NfWA5yNekioie9Mfxr6zfY6T80iFHwi1Dk/tJZHYgUTPNhbkGfF1czxbjQM9V7MnkHt4vz/joEZvPW0NblyA/28vd2lecBmBsmt0SN37xHQArJ09Em1ooIgzo6UrZ4w/ziUi1eraH2yiHdkQhEDV6W6Tj21ArI5Y6obO2QlR1PMdnYrUvp3QpbrA1v2W+53spRpDgKG1bclFejFe3XPTq+V52yYXxzwboBpOTvJSo1+pAs/QsABpOqmly3LPeYQRLIzmwsR+ZgEvTDJAk5FeSktW+Xxm9IFa55N8fmf9LiI2a7/SX6MlRTZKWFKRILKBIL8XjWFn2tTDFJ60xqs9f/IjmuqiHefRQfiCgH8pPc+jiWZv+UdDWpJuz1cxrH8b385HRpaAXKzN9HHPsm4Xf86u/SPCtLs/C4U5mc22o92hsAbT1C/0vLLSbbZK5y1KylM7SuP2w62JhElFUIe7fseVSuYblA0obrvWENSqmyH1mH5g2qktmDwFg6t7KgB8h904WbGbwKQQ3QhPLw7+oNKliAxf3v4+LHv4VQJGW3w7NetYQEPBg== 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 Fri Mar 3 14:14: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: 13158848 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 6EA29C64EC4 for ; Fri, 3 Mar 2023 14:14:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 012606B0078; Fri, 3 Mar 2023 09:14:53 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id F02A86B007B; Fri, 3 Mar 2023 09:14:52 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DA4586B007D; Fri, 3 Mar 2023 09:14:52 -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 C80946B0078 for ; Fri, 3 Mar 2023 09:14:52 -0500 (EST) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id A028C120A4A for ; Fri, 3 Mar 2023 14:14:52 +0000 (UTC) X-FDA: 80527783224.29.79198AC Received: from mail-ed1-f74.google.com (mail-ed1-f74.google.com [209.85.208.74]) by imf03.hostedemail.com (Postfix) with ESMTP id 63EC620020 for ; Fri, 3 Mar 2023 14:14:50 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=XZGeQDWe; spf=pass (imf03.hostedemail.com: domain of 32QACZAYKCAoqvsno1qyyqvo.mywvsx47-wwu5kmu.y1q@flex--glider.bounces.google.com designates 209.85.208.74 as permitted sender) smtp.mailfrom=32QACZAYKCAoqvsno1qyyqvo.mywvsx47-wwu5kmu.y1q@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=1677852890; 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=rwOqGFiMpxVm/Yf2TCVg/tAOnz+fk0oI0q2ct+QMnRo=; b=CFvrrTZTo5a7mTnH6pM8qnB33WJuqUi7e++BF9SRWNAGW3G1GqeZvtCsWmBJPtLOEgZsNh 5KxcMWTlvPFPkHY22gcURiuywEH/fr1GYwuf40kS+SPCWHAu4CVsMVxt16CyCYJlXiJ6Np ULnw7IuWBb2JBJktf6cIJnbHcp0O3fU= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=XZGeQDWe; spf=pass (imf03.hostedemail.com: domain of 32QACZAYKCAoqvsno1qyyqvo.mywvsx47-wwu5kmu.y1q@flex--glider.bounces.google.com designates 209.85.208.74 as permitted sender) smtp.mailfrom=32QACZAYKCAoqvsno1qyyqvo.mywvsx47-wwu5kmu.y1q@flex--glider.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1677852890; a=rsa-sha256; cv=none; b=i9a6lnGvBMXP0fiuoZqn3V+0l4s+ZbBdwwMPXi0oWWFQJni+SdXUF03ZAThQvM9hdKbRF7 DNlMcgQRKD0lxQRBysrSFpTiI0OzDdRPQ+djvPBKm6o4u6AI0r6LHv02MMj49DyH42FPaZ xoU5Zlh3aTDksuUTc2tlJ9R+keMSYfM= Received: by mail-ed1-f74.google.com with SMTP id r6-20020aa7c146000000b004acd97105ffso4138141edp.19 for ; Fri, 03 Mar 2023 06:14:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1677852889; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=rwOqGFiMpxVm/Yf2TCVg/tAOnz+fk0oI0q2ct+QMnRo=; b=XZGeQDWe4Pd5npHcAau0EzkvzHXKKNrGOH18yXzhEAmcYUZLbneOiYfhArq3rRCAZy GBbL3GsmlGQfzQ5SfxzKMgTFZEUEozH+Or/E60HwnODlceqj0C3HRmJbt7oN2LKCfPJB WhsQRvh03bRnXHE23IhTee0WmZOV7wI6BD1JQHMUVMgPFTpIWoulVpH3dQbdsiw8/T9J 5TcP4NGjzxEa/ZJAP3crz6HfyNfIP1dIzC/ax7dquihg4zVwhhLGbI8jCGiV7Fd5VKtM dPhh1sc5W7VFazYm2ehiDohwqAS/RO0qdmBIFJm84GXSSdH9KLss/voUPFZtPSSBR+Ew t8/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677852889; 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=rwOqGFiMpxVm/Yf2TCVg/tAOnz+fk0oI0q2ct+QMnRo=; b=j5pK65AE/CcfmBMSjKrp4trN1ZvswrU8P/d4rtXzs2rYVk3lbuRPyC3y6oa5u3gHIV R7qh7RarBUs4djZqMYEpUYKId2Av6v5Yo/Vuh9AfpYVWHTXOpryG82bVTGAUBrrOIAZR +O4Y0vhN2QMV05iSYGtsdfMcE8oaKBoAA2FY4/r0uEGEcauKxVwCc2yBKFYIq99l3o0v YzoaZJr5db6djEeSv4NjqD5ny/FvQxaTqgjc6OOWkYYxcRNrp4uQddqwBbQi2o8uVvEj rLNY4MQz6ixRc3X4fnpa08tO//BeQZDcvMZkIZNYGBkfF49g9Mpx3s6/Out2jmo3QqAD QTAA== X-Gm-Message-State: AO0yUKXj7OAGe4+bbg/9q9wTh2sp2qPlgxTv6lGvPZJlXeDTmoeOHUEg H1pwL+Q7Pk0NwuK+HulW7tJShVknBKs= X-Google-Smtp-Source: AK7set9r+yMP2FHj07wsqj7PjZE1ezap7iMthzxqlJBoACzjCEvFQP5Ey8Gv3jQTqbJVfvH5zLMGOYTOGuc= X-Received: from glider.muc.corp.google.com ([2a00:79e0:9c:201:f11e:2fac:5069:a04d]) (user=glider job=sendgmr) by 2002:a50:cd81:0:b0:4af:6e08:30c with SMTP id p1-20020a50cd81000000b004af6e08030cmr962152edi.4.1677852889146; Fri, 03 Mar 2023 06:14:49 -0800 (PST) Date: Fri, 3 Mar 2023 15:14:33 +0100 In-Reply-To: <20230303141433.3422671-1-glider@google.com> Mime-Version: 1.0 References: <20230303141433.3422671-1-glider@google.com> X-Mailer: git-send-email 2.40.0.rc0.216.gc4246ad0f0-goog Message-ID: <20230303141433.3422671-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-Server: rspam05 X-Rspamd-Queue-Id: 63EC620020 X-Stat-Signature: h9jha17nhnuzmtduu4kbigyay98ky5yk X-Rspam-User: X-HE-Tag: 1677852890-541061 X-HE-Meta: U2FsdGVkX181JempxvtD6lgDg2c4QWZIBSBsxJ/6nBdQUXcydDhUqExQsrlZVCZ/hFEtBqUQ46AVLUe97vXKCQAoXipU3gECN6LbT/tb1jEsPYTMAXyxvDx26br/SWSFNW7EVltc9UIIRP/cI4UOIKSQlxBOUC1vk7XO6E1Mw437qKIn+dSuRMT8B5/xMJIX1ANq1lvr3yuew+PePhLC5V5VtTjwjMbYLHVySm+B62TUdRBqJNpuGXRvmpinWsnCCU6m9S4DThbQpTFGayKGRss+6ONccLqBpB1N79xn6jv3OpFqceCw6SuxyDTXD7xElPUtTXxO0cZ9tMh5Gf7O/bvZ6DglQCCFltV7V+dbP3DxPv5kzPpTxRIYcf9AQTGplOW/gOpwG6XDYILfzAZcg09XdmxSZXPUw+xd6p0Hn7VLPUZmZ4683NqLXzaKZffLCIpp1PZ/c5powc1c5BnZ3/d+EUOi4mAGmlM+nayfOsN5EYmR+mFbkY1VSmk7YDFPb6xhXHHRQHTHqA1ntKwpB5JaFiDbVYEOu0FCC+pbJEe2o0sFxnUBjr92VXf1QfpEbXQeF88Q+29JVnz86ug/2yN49Pt+LHS38HKCEeb+yTzjn8QgXaphwEZW4CK4gGSu3pb9Bz6kUhHWn1l7FlgxWisYhSDG8YRI+VucTAbGChYvcfABP6YJSTcqD561+L7Yq3T1MUfrTHm7kSr6WoGriWidzXwJS+L/DLs2sSRGlr+/lmuzUij32hcq3i+Ss4CHos+5g9f3xs0o80+bdnEV6kskEz7UI/bhRojMOQhqZs5AZUe401T4+MohLvzMhx5GElpcEUwExfXtdFCZm4SLFEyB0dEDeK+LleFTOwSi1Wjw2V6gexKrmPOkfnLOg4fqQP0UP/2o2PPHddRQSXvWEXGzWBtXahe04LgA9SHEuVz0wtSZ6Q7Wvio/0Em9zOuO4/UekYfa72ilvQYLlG0 mh6UW5rH o04Bw7LGNs1MnqPO6Ic/LmakT9Lm9W0Sos4QJmINUrOtZG+C4jA+2dgXa+GXN24nHukbtXiDjkEd4pK5BO+nqtFoPFNU6Q9ouIIEEDlae/jsnZl10GGsjMbxfbJ+0dt0JmPHztqXsLfzw3xT1q7UZy+GEJKpiKzf2wSLmcqtr7yiUHxasy7Ov1YFWg6AhKVPnmLEovOUrkpHQzYHPiwmvOp+LWCM7UePHdbEgdiP1kJ3ma+Ax1ZWi5ThbQdLLTZvFY4QObnyK2NdB6433t1zvlSEJ248tCxl1Xrycj68i8gZpxxAjK88xAnVAFQqvlEo/ktjads3nFK0Gq+MG/c1CQiwilk1ceq5bDY18Ntt0hiAYkvDJkUhGxCA1pijqahzi+P2/Pm335nlciQAoDSQ/v4/6baILcg/sB93EAnViubI2v24Z55asjqhNclpyw6I5Ao7X+Ieob+yWE9T4NPnmiLHg9ttceQEjpF87j0F/fc3+Ixr/VLU8d0AQQZ1itoVWtCb3f2qDhOt1B5ULF4gYCYWLK9cMMPiP6vgwVdGhci+ZzY0TNNl3zz2AxSiDGxvQOojkhbPfnBLGJwlgyXsIMXLaMO8uJ4VYVgJf03b1Y3KmXGFkhOBNmuYQrQ== 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 Reviewed-by: Marco Elver --- v2: - drop a redundant parameter of DEFINE_TEST_MEMSETXX() --- 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 aeddfdd4f679f..7095d3fbb23ac 100644 --- a/mm/kmsan/kmsan_test.c +++ b/mm/kmsan/kmsan_test.c @@ -504,6 +504,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) \ + static void test_memset##size(struct kunit *test) \ + { \ + EXPECTATION_NO_REPORT(expect); \ + volatile uint##size##_t uninit; \ + \ + kunit_info(test, \ + "memset" #size "() should initialize memory\n"); \ + DO_NOT_OPTIMIZE(uninit); \ + memset##size((uint##size##_t *)&uninit, 0, 1); \ + kmsan_check_memory((void *)&uninit, sizeof(uninit)); \ + KUNIT_EXPECT_TRUE(test, report_matches(&expect)); \ + } + +DEFINE_TEST_MEMSETXX(16) +DEFINE_TEST_MEMSETXX(32) +DEFINE_TEST_MEMSETXX(64) + static noinline void fibonacci(int *array, int size, int start) { if (start < 2 || (start == size)) @@ -550,6 +569,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), {}, };