Received: by 2002:a89:d88:0:b0:1fa:5c73:8e2d with SMTP id eb8csp2554454lqb; Tue, 28 May 2024 03:48:43 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCX4LVcHaQ7iYDW2woaSnav50fpG6VgLdTDOjru3Xk4IoLB0quPd7QujUmMpZGkZBzNLY5Cm978vwTaUYyIhWPyu+DbZ0gZKkcbbea51oA== X-Google-Smtp-Source: AGHT+IE7hhgI2M8Z0es17CisbPVDUwSSglmT8QX2Yh21HIrvXBsoNaLGl7lbBMLQCEB89tPLUUTL X-Received: by 2002:a05:620a:b12:b0:792:bc5b:8420 with SMTP id af79cd13be357-794ab13e6bbmr1222587385a.68.1716893322985; Tue, 28 May 2024 03:48:42 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716893322; cv=pass; d=google.com; s=arc-20160816; b=Lj1iXt96tlLCSPEpGVJ1yoofjWVMXYvRl8mdYdowejO/v1CZpsVyceGDP/JIaR62rh td74shh1izBUYPvQBXc4Jibw58YYR8lOuxldGs/RvejIW3AZcLLOvIQC/z3l7xs16Zgm HcP5TsYsUyt+0TgOJZFFsDs/rIOD/7PRzH4m9l/JmP0hDJodfRqNzzGSBLIuD3VEIgWf 4xs0cRbIMDqKLxyeq/r3juMfhfo1A6UcYu1nhQUtWZG0xOiJP/ag3uUF1vm/414Vnv+L OYg/Hc4grs1iwo8z/0K3Jfgnr7CqqiSk4GFkLImefM7cjw38wAA3u6cTOerkveINDz0b XdJg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:references:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:in-reply-to:date :dkim-signature; bh=RTgy0iA5o4eiMLkf5DZA1XVIVBf+wcR0MiDC6AwIp5o=; fh=VsZYWgBTUAJoZ/U8uF6F1oEYVp/lw0+QxMx7+dYl+zE=; b=mOizbnbjAsBpyGUTteIZsWGaXwLzloRsDcSR8OO8tXERQJftKrlRGME2TTqjdqOIT9 063dbzKUvSyc5r+WF/16G8xa6bRFGT/hYnhCc0fMPhzWZNofy3vrBcN+JxINPCNtdSgZ yPCxFGRKc2hZsHVr0IgcgsEdulAw3bskpTqHtYSVvsNveGxdJ16SObSSoUZd9Y+MetEx G78S3h5UgbJ5urDTz8ssZ074bVVV3f3PypPq+Sf3jOyPTkMcBZ2p5lo6AS2hewT4fljp SjXKoR8TQNeS2qYyGDzsNxRgkR1duKMgN3dyTGIRdIL7+GZcej5EPppWq+cXNJRbHp0K TOzw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=sRVMaajs; arc=pass (i=1 spf=pass spfdomain=flex--glider.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-192132-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-192132-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id af79cd13be357-794abd4e9bfsi976639785a.645.2024.05.28.03.48.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 May 2024 03:48:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-192132-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=sRVMaajs; arc=pass (i=1 spf=pass spfdomain=flex--glider.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-192132-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-192132-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id AD6861C21E75 for ; Tue, 28 May 2024 10:48:34 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5371B16C698; Tue, 28 May 2024 10:48:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="sRVMaajs" Received: from mail-ej1-f73.google.com (mail-ej1-f73.google.com [209.85.218.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E552916C683 for ; Tue, 28 May 2024 10:48:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.73 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716893299; cv=none; b=WQ3CHnO3munLxAd9z7qA/m2li5iiw6V82Y09XI5fFjX8FzOMvH4IGqCrR8Ne+4N1luEpAX+4+zlmT5x9uEfREjWL8/C3R5IbN8fDHWBaLZmjhFiY7B/Nx+wxmAKwgtfFDEX5FHKg9cGdjGfa7ZOvIFPHekxscUF9d13+baWi5ks= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716893299; c=relaxed/simple; bh=/K9BBxive3sS8BvywGTbjSYc7BG14dKbtYRg2rAsHCs=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=dQB6ETGuMo/iz2Bo+N192DiNweXzcreYnlcLsw6RB6MncsXheho260vnRTafX6GPtfJPc4RjJjmOaF2A1Lc2j5fMs4J7EuVhCi6BDrVcYxlbSXu+mvIHCUWGNDtfo5Kc+c9kfA772Y7JDcXqBZi86VF9jJBXNK5Zdj5cbWWEiZ0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--glider.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=sRVMaajs; arc=none smtp.client-ip=209.85.218.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--glider.bounces.google.com Received: by mail-ej1-f73.google.com with SMTP id a640c23a62f3a-a6269ad7288so36272766b.2 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=vger.kernel.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=sRVMaajs0W0/gEj/EsK5SqZhX6DzUfrb2gUGPP2P8/UvvauPmrVxYahJWVWzRm9g66 4JBvmkd9aYZuMRNLhHYso7Hfq0NATZUky7aRhPjI7E+DidM4DJw6dLPvh/aKpV2kkzWt xyZw7iMm7WSSCfujH4dWPSYMDaLwoYTY5q7nyaHZLs0SpfPJzMa9zSj21ZAwGXhYj4bH v1F3utl6xtdGpdistGQ20Fm2OQRdCkX7tKVHGCZZ1AIP4YPH4vccHQWxZdp1k9eMDm7b sCHQuxiWYrOt27CLQZ6pTNIfSi222TAgUwTGKJl26/D7pdGX4/HsDyEjRHgsm6thIUfa kD7w== 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=CIAb/WT6Hkpshf//4APF+dQ/9qXShp4xi+cinFJMPYMr4L3S8JwEWL/fgYyGKHykZK 8xDkSZQrwrpAVTtDMo+VocT3C5aG/3VS5+VbCPOroU51ItqFgSJyi4lz2akPcuXb+06r NWxxgSkH8zZdksLIjWBrPG+V6OvKNBhnxy/rI0TauSF75pdAYa71Ai4aj8byC+zvHztH RwNX1UjK8Nlo7SinM5joODJSXnJIp7OOb4/qRxDaNGugIm6oO7Hm78Plc9hJdrz6Idz1 CfB21RSv/1b/4zPI78Nk5hNdk3sfcuIFermabgVy65WUQsedjsLunZp/1Y6MzKgLNp58 hFPQ== X-Forwarded-Encrypted: i=1; AJvYcCVQ81VgjMl+un/gGjyEywt9nbGUi0vC4vInUgmMD+UzgHMZ0HTOY5E7rSDKLih00U98ov5yL2jLfRBMqsPjzmYyZGxKwO7ZSPoOktwN X-Gm-Message-State: AOJu0YyfBBejl6GnIfVLC7pfRX19PeZPgqKsnb7FnxU7HddAEJHkPouw q88qwcbsqPxeh485EHdLuvCirp5TwDTR1gb4Ss7Jb0v1NKsrcWodAovVqtzlcXI9MPAFz1LCMNv uWA== 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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 Content-Type: text/plain; charset="UTF-8" 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), {}, }; -- 2.45.1.288.g0e0cd299f1-goog