From patchwork Tue May 28 10:48:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Potapenko X-Patchwork-Id: 13676466 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 D5BCFC25B78 for ; Tue, 28 May 2024 10:48:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 63D106B0099; Tue, 28 May 2024 06:48:20 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5ECCB6B009A; Tue, 28 May 2024 06:48:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4B6AB6B009B; Tue, 28 May 2024 06:48:20 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 258D66B0099 for ; Tue, 28 May 2024 06:48:20 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id C009AA0439 for ; Tue, 28 May 2024 10:48:19 +0000 (UTC) X-FDA: 82167480318.14.927E8DA Received: from mail-ej1-f73.google.com (mail-ej1-f73.google.com [209.85.218.73]) by imf02.hostedemail.com (Postfix) with ESMTP id E1CA98000E for ; Tue, 28 May 2024 10:48:17 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=Efqsy2rg; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf02.hostedemail.com: domain of 3b7ZVZgYKCGwQVSNObQYYQVO.MYWVSXeh-WWUfKMU.YbQ@flex--glider.bounces.google.com designates 209.85.218.73 as permitted sender) smtp.mailfrom=3b7ZVZgYKCGwQVSNObQYYQVO.MYWVSXeh-WWUfKMU.YbQ@flex--glider.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1716893298; 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=RTgy0iA5o4eiMLkf5DZA1XVIVBf+wcR0MiDC6AwIp5o=; b=cHCK+zz9cWebAmn46R41MsjdW2HzZ0WERVP5M9XhpVCVlNTsC3dXy14y3hmkqXLQVUHV/v sbIe0Qzg2Ru/BaghsnNCy5PmvLMG3FfpgrIU6z+3+rtzFl58glhECe/s8TuuY6AzM4Ce+A +TgLx8etDfUqT7om5WlCMZy7c5qHj5Q= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=Efqsy2rg; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf02.hostedemail.com: domain of 3b7ZVZgYKCGwQVSNObQYYQVO.MYWVSXeh-WWUfKMU.YbQ@flex--glider.bounces.google.com designates 209.85.218.73 as permitted sender) smtp.mailfrom=3b7ZVZgYKCGwQVSNObQYYQVO.MYWVSXeh-WWUfKMU.YbQ@flex--glider.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1716893298; a=rsa-sha256; cv=none; b=0UWLIU9h1+MV1fih18un6oWnB8v+etfn1G/iVdfSPNz5QZs+4VNjlil4T3XuZIg/tUmyg8 K4vRmmiS9DH3cxA0EmArf3e0q6ow6Iwby3krdtLl+WTz4Rm9/6vy4n9dOTwQcD4o4JQ7TQ Sre/2HEHeHGnBW1itjVSNwkg4No7NLc= Received: by mail-ej1-f73.google.com with SMTP id a640c23a62f3a-a6335fdc8easo34508466b.3 for ; Tue, 28 May 2024 03:48:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1716893296; x=1717498096; darn=kvack.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=RTgy0iA5o4eiMLkf5DZA1XVIVBf+wcR0MiDC6AwIp5o=; b=Efqsy2rg4587M7eO0JbIFk3Uif3rH+oF7bEPCbiKbnxYG7i2c7lE+ZqW7iUGTQnm1d jkq++n9GP0mKwpYOmIr6J1rFGBGIw9D/mVhR6met/Sv/o2x9qQQ06aIvgnEjMa9IZmKw 7kHFe/TVQqHlrk2Xw5WO4QK6fInnk54o8F5NJP6XJceADqbL4erEBWS7G8+jTTazqLxV AXOefGEwiEYCUXnd/9tG+NEJCJdV7C6PSr8bdOWxeXvAcIKG23QB3q6QrC/D3fwhjoIT jHe17A3QioK4zJnUYCwC5rWpMBU0y9fKtmTH215j431BjVDdzziw6jmdMYSrjwIlLl5s cqQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716893296; x=1717498096; 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=RTgy0iA5o4eiMLkf5DZA1XVIVBf+wcR0MiDC6AwIp5o=; b=tIO3t1KRd5kuB6DyLhBia8WG7u493F1tBkkTYgv7Tzcqp6L4rIt/gOs5F4wRsG0cqS F9L5OsWsEFDt0/8YBIhFBzf4HZMY6/RKyUfMG5NSeJXtr7Rwkm6NRM4/7CKU2EZW3XkQ 3RKlyxxnDC7x+C2iwpQDvsRKCnzWrkG12i2u7+y/1eBSrXrQ9tnkZd8QX8PfVEzuSfPY yQx/OQYdeIlsZ7ubUHjVPCCB9COu0S+6UkYev9gB+E/MAur15IVqgH/H+swm4MlJWJRO JGTkIrUE5Jo5dU6c5aT3Ic3lMSFKt10PcIqaqeU7LehgprX3NJzNX+FeE3fx0KXOKDPe ucCA== X-Forwarded-Encrypted: i=1; AJvYcCXhNyCyOAh241JD1CmMTxF5KIWNfKBdaRweMyfthC9y8Ow1rwTc60yYi3UafsJSVBxwW+vB71XpQu9sVqmLRAx0Zzo= X-Gm-Message-State: AOJu0Yy5ok9dUPrFs27VG3LBiy1jCEGnaxXsNRIZXH/WSgzJAn4KmuEy /NlvVlSoFB77EtXZugPR6zxpZkItkjKNEMdLkbPPcoUMThThunFP03PIBw0djF5yFulWeBGi6Vx WIQ== X-Google-Smtp-Source: AGHT+IET+wqbCwieBcRKi1iNrPHSEZCrZnq1lsNKlL4c9ImOIZieVkTk1hpvy/CeH7ks20L//eHDRYvdSOU= X-Received: from glider.muc.corp.google.com ([2a00:79e0:9c:201:6416:417e:596:420a]) (user=glider job=sendgmr) by 2002:a17:906:478c:b0:a61:9678:91e2 with SMTP id a640c23a62f3a-a62642e76e2mr1061566b.9.1716893295944; Tue, 28 May 2024 03:48:15 -0700 (PDT) Date: Tue, 28 May 2024 12:48:07 +0200 In-Reply-To: <20240528104807.738758-1-glider@google.com> Mime-Version: 1.0 References: <20240528104807.738758-1-glider@google.com> X-Mailer: git-send-email 2.45.1.288.g0e0cd299f1-goog Message-ID: <20240528104807.738758-2-glider@google.com> Subject: [PATCH 2/2] kmsan: introduce test_unpoison_memory() From: Alexander Potapenko To: glider@google.com Cc: elver@google.com, dvyukov@google.com, akpm@linux-foundation.org, bjohannesmeyer@gmail.com, linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com, linux-mm@kvack.org X-Rspamd-Queue-Id: E1CA98000E X-Stat-Signature: gejo86kwwnhj75bnfb44j8r6da8yeuo5 X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1716893297-840942 X-HE-Meta: U2FsdGVkX1+hEnWbh6u26xc+hVQRt+i/VIr6K7mPmAR9wvV9YEoegWefaxbEdy61tkBy0TqVJfSaoBEmTTosP0IicqezzNb/1HkOA1ogeJFo2FW/OwVRGDAqtSSOe95r66uJYuWlMwisNnFbVLTR/HDOy6PfLNQJReXNFLNUhauWTvIkH9Xi/10b3zRBW6gwwLLuNueA64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GxlMr+c7W4CxsqPhNQsVNpJ31ITYxyP9hO6zOtp2lvXZhdONQ/XJt26cPGhY7GDDiXUw+wvzajwTPL5nNm32PUR9XvtTvK6D3qCd6Llu255M+K9agTjCOw1BlrTT8QitkfjovNHMoY1ycN9dwjJjJc5n6MGuKUPI0orBaD5y9RO0TC8Z2tblSOk3wIzlPSAQOUM+EfVOK4A4ncIRpsdla4JyQH6jLr/PM/N6Ayjg+x3UpIqoqOmBh6pvp+9BGVBF5e8OOusi12jyno/nFdulYr+pxhHDV9TqhkSLsZNey1g6xAGR/w5udRi9fRDDtEed6ucNpuLkamQPdc3QU+avyjOWnzQDuMKVm44qDmoCgdwjjdQSHHaLck/M= 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: From: Brian Johannesmeyer Add a regression test to ensure that kmsan_unpoison_memory() works the same as an unpoisoning operation added by the instrumentation. The test has two subtests: one that checks the instrumentation, and one that checks kmsan_unpoison_memory(). Each subtest initializes the first byte of a 4-byte buffer, then checks that the other 3 bytes are uninitialized. Signed-off-by: Brian Johannesmeyer Link: https://lore.kernel.org/lkml/20240524232804.1984355-1-bjohannesmeyer@gmail.com/T/ [glider@google.com: change description, remove comment about failing test case] Signed-off-by: Alexander Potapenko --- mm/kmsan/kmsan_test.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/mm/kmsan/kmsan_test.c b/mm/kmsan/kmsan_test.c index 07d3a3a5a9c52..018069aba92be 100644 --- a/mm/kmsan/kmsan_test.c +++ b/mm/kmsan/kmsan_test.c @@ -614,6 +614,32 @@ static void test_stackdepot_roundtrip(struct kunit *test) KUNIT_EXPECT_TRUE(test, report_matches(&expect)); } +/* + * Test case: ensure that kmsan_unpoison_memory() and the instrumentation work + * the same. + */ +static void test_unpoison_memory(struct kunit *test) +{ + EXPECTATION_UNINIT_VALUE_FN(expect, "test_unpoison_memory"); + volatile char a[4], b[4]; + + kunit_info( + test, + "unpoisoning via the instrumentation vs. kmsan_unpoison_memory() (2 UMR reports)\n"); + + /* Initialize a[0] and check a[1]--a[3]. */ + a[0] = 0; + kmsan_check_memory((char *)&a[1], 3); + KUNIT_EXPECT_TRUE(test, report_matches(&expect)); + + report_reset(); + + /* Initialize b[0] and check b[1]--b[3]. */ + kmsan_unpoison_memory((char *)&b[0], 1); + kmsan_check_memory((char *)&b[1], 3); + KUNIT_EXPECT_TRUE(test, report_matches(&expect)); +} + static struct kunit_case kmsan_test_cases[] = { KUNIT_CASE(test_uninit_kmalloc), KUNIT_CASE(test_init_kmalloc), @@ -637,6 +663,7 @@ static struct kunit_case kmsan_test_cases[] = { KUNIT_CASE(test_memset64), KUNIT_CASE(test_long_origin_chain), KUNIT_CASE(test_stackdepot_roundtrip), + KUNIT_CASE(test_unpoison_memory), {}, };