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+tp884cBXfnh4k85fjfldY05CucKPZIGTqCAuygqkqEDlb0DukcuBIhyxBYRyavBpA08qHx6QmTp9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WOJu75YLim3JgRYWYRDEGrqpscmblbDRk8/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), {}, };