From patchwork Mon Mar 6 11:13:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Potapenko X-Patchwork-Id: 13160984 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 46D52C61DA4 for ; Mon, 6 Mar 2023 11:13:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A7EA46B007B; Mon, 6 Mar 2023 06:13:32 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A070E6B007D; Mon, 6 Mar 2023 06:13:32 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8811D6B007E; Mon, 6 Mar 2023 06:13:32 -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 789076B007B for ; Mon, 6 Mar 2023 06:13:32 -0500 (EST) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 47778120BBA for ; Mon, 6 Mar 2023 11:13:32 +0000 (UTC) X-FDA: 80538212664.28.9A1C51B Received: from mail-ed1-f74.google.com (mail-ed1-f74.google.com [209.85.208.74]) by imf08.hostedemail.com (Postfix) with ESMTP id 65535160015 for ; Mon, 6 Mar 2023 11:13:30 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=P5DhRm6l; spf=pass (imf08.hostedemail.com: domain of 32coFZAYKCKwSXUPQdSaaSXQ.OaYXUZgj-YYWhMOW.adS@flex--glider.bounces.google.com designates 209.85.208.74 as permitted sender) smtp.mailfrom=32coFZAYKCKwSXUPQdSaaSXQ.OaYXUZgj-YYWhMOW.adS@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=1678101210; 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=i1L+pZCwrwV8WFeqR7MKglAsPEnoOPqo6PmA3RfPAYI=; b=NpaLXQMPd1Jn3brmzqsvSEo8ySpGAGF1BHbw8fKGmya7Da/Ad0g7TCW40AC1nYFQDS7jDw CticjdW//9a95YUmIlA9pqvbd6OpRv7+ir6ium4JD3QNGv4AAEMqaf6MOUYaGN4wAEmDyu 8hCMFt6qBcDN4vuW6aH06j40WX+q6nc= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=P5DhRm6l; spf=pass (imf08.hostedemail.com: domain of 32coFZAYKCKwSXUPQdSaaSXQ.OaYXUZgj-YYWhMOW.adS@flex--glider.bounces.google.com designates 209.85.208.74 as permitted sender) smtp.mailfrom=32coFZAYKCKwSXUPQdSaaSXQ.OaYXUZgj-YYWhMOW.adS@flex--glider.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1678101210; a=rsa-sha256; cv=none; b=wjjiGMrjG0euzb3I57m121987te1kW2+qqZDu15HKwI+HT+MFQD2oYGqOxo43q6eTjWl9f ulO9JB8cjOZGFQhzgAcmMUzCavejb2ea0MbomZ6JQ1fvNdNaR/8ad8LfujYf9rK2HLGYKs JK5CjGUTLHiC1AWYYhTKoMoeHcMJs5w= Received: by mail-ed1-f74.google.com with SMTP id dn8-20020a05640222e800b004bd35dd76a9so13409310edb.13 for ; Mon, 06 Mar 2023 03:13:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1678101209; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=i1L+pZCwrwV8WFeqR7MKglAsPEnoOPqo6PmA3RfPAYI=; b=P5DhRm6lyoKz3NoNdsdxwrRj/MfjpheohwuDiF7EpSFlNNXCKBaoHIBOiHLSs4Yzre 6zEPjyPu0V4FkWh1Jtnal2exA5k4WwW8AbTrCkoXx4RjCcJewqsOrcNgnaLuTBJEze/l VGuQ7KdXumG/1Oc8kkYYtbRiCbr1ZMr0hDisTKb/hBPLVRcl7r3dM9ZwyLhLY7bgcvph KiQP1/tCcC74t9C7yVQwSeKAFhacYwFs5vhzrqyMo5OOr6N+uRAZB0CYJdq9/1YDnZhg tYmjh5t8WjxwwB84qFIiW9FlQDDLzJjnFU3PfE7CAheT6nZrosN+8/etsfpD+UY+qiot Q12A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678101209; 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=i1L+pZCwrwV8WFeqR7MKglAsPEnoOPqo6PmA3RfPAYI=; b=W6/WZ7wVKTB8/q/4Ucivju5AvzLKQAHxZMRfMr1w/BHTDSz9xSWKoNOX9PrYaiMKSI 0+BSB64wr4DOYi6Wh5P9J5Bf/rvZa2jQm6nmgEqC7FMzH9Dr8r2ert9/LYjpimoDUID/ gVO4mYPasncgU2nsu1N5k+ouUQJ7eVJq7mWI3/YYdtY1tKMZBUABzmuMcbgQdtR58CpS a3i5DKDWKdFdYLu1aK4KBsSBMYAmZZnDYXQdXz24XTMstztZqEJdOCFR8bkF6/aKuYXq t4hFX3n3n3tB+3FS62VQFH9wYANzMNx464JmfQ1+zJz51p50bEa44j8pgazhM6dNpagF U8BQ== X-Gm-Message-State: AO0yUKUeDx4NPFd4SHWSmVogm9T26Rx84mLfJNNvwYjI3DhK9xz47uJM gMyDE22T6jR8jNJ6nmrlAu0/F8T2p+I= X-Google-Smtp-Source: AK7set8HRrR3WYNCNKrhw5eYGbtiDR8z1X0sw4OF9TB+cqX5mY5fOft5pn76XHBrFTvkLNhtM87td2wBZZA= X-Received: from glider.muc.corp.google.com ([2a00:79e0:9c:201:b93a:5d85:6f2c:517d]) (user=glider job=sendgmr) by 2002:a17:906:4f94:b0:8b1:7de9:b39b with SMTP id o20-20020a1709064f9400b008b17de9b39bmr5034537eju.1.1678101209226; Mon, 06 Mar 2023 03:13:29 -0800 (PST) Date: Mon, 6 Mar 2023 12:13:22 +0100 In-Reply-To: <20230306111322.205724-1-glider@google.com> Mime-Version: 1.0 References: <20230306111322.205724-1-glider@google.com> X-Mailer: git-send-email 2.40.0.rc0.216.gc4246ad0f0-goog Message-ID: <20230306111322.205724-2-glider@google.com> Subject: [PATCH 2/2] kmsan: add test_stackdepot_roundtrip From: Alexander Potapenko To: glider@google.com Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, akpm@linux-foundation.org, elver@google.com, dvyukov@google.com, kasan-dev@googlegroups.com X-Rspamd-Queue-Id: 65535160015 X-Stat-Signature: 9xmkossnd6jeq64ndrpurseskxrxoz44 X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1678101210-114107 X-HE-Meta: U2FsdGVkX18VN5MKGycxFE6zEA2RcBFez7puQI3FQ4BkkvwXPrhi6ebzFx9C5cV4yvIXteueL50bnIu6Uo+DvHniQr6grm5lM1zxYO9eGdirTjKDFjT8m4FeFEr+epNw6KoJkIHqkajj+dLZ7NXwMBZEe8c3Duv7fhgS3LZUz/OG3Rn+cymVf7uS5Lte+FUx6Z65OaTBqOY3UL0ZhTJPvPgS4Pxien74asN+sq0kgIXR3jhYtaA93mVVIw8c27GpWMQ+mvzKWf9ToHuSJMU1mMbSGA/kZx8BMKPkhR6BZJYEOlAw2gNWFfrVbEgWZOJ1cyASx9zyyxXJN9EFCJ9FSzY+deEtGRJNizvh/y2+cGeJkF5JC8IE5C3h1aq9B+hztYocz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jY6O8HLdnkzCBC7dvlgupgBSyLT+CZh4RDHd34CeCWQirbsIMwWfdL1lCrYRxpOWSqqIM1/6ZsSHnvyd3w/J1BYhP7oqs03geMZFz7FVzvXoezqq3ngU/VYNF6ZfhSziv2oRdUZSflmVh+WOXunCFYCa97K6Vmh5oZUariHLo3K2IWblseKWuJi8FwDIwI3MzNcHxce 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: Ensure that KMSAN does not report false positives in instrumented callers of stack_depot_save(), stack_depot_print(), and stack_depot_fetch(). Signed-off-by: Alexander Potapenko --- mm/kmsan/kmsan_test.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/mm/kmsan/kmsan_test.c b/mm/kmsan/kmsan_test.c index 7095d3fbb23ac..d9eb141c27aa4 100644 --- a/mm/kmsan/kmsan_test.c +++ b/mm/kmsan/kmsan_test.c @@ -551,6 +551,36 @@ static void test_long_origin_chain(struct kunit *test) KUNIT_EXPECT_TRUE(test, report_matches(&expect)); } +/* + * Test case: ensure that saving/restoring/printing stacks to/from stackdepot + * does not trigger errors. + * + * KMSAN uses stackdepot to store origin stack traces, that's why we do not + * instrument lib/stackdepot.c. Yet it must properly mark its outputs as + * initialized because other kernel features (e.g. netdev tracker) may also + * access stackdepot from instrumented code. + */ +static void test_stackdepot_roundtrip(struct kunit *test) +{ + unsigned long src_entries[16], *dst_entries; + unsigned int src_nentries, dst_nentries; + EXPECTATION_NO_REPORT(expect); + depot_stack_handle_t handle; + + kunit_info(test, "testing stackdepot roundtrip (no reports)\n"); + + src_nentries = + stack_trace_save(src_entries, ARRAY_SIZE(src_entries), 1); + handle = stack_depot_save(src_entries, src_nentries, GFP_KERNEL); + stack_depot_print(handle); + dst_nentries = stack_depot_fetch(handle, &dst_entries); + KUNIT_EXPECT_TRUE(test, src_nentries == dst_nentries); + + kmsan_check_memory((void *)dst_entries, + sizeof(*dst_entries) * dst_nentries); + KUNIT_EXPECT_TRUE(test, report_matches(&expect)); +} + static struct kunit_case kmsan_test_cases[] = { KUNIT_CASE(test_uninit_kmalloc), KUNIT_CASE(test_init_kmalloc), @@ -573,6 +603,7 @@ static struct kunit_case kmsan_test_cases[] = { KUNIT_CASE(test_memset32), KUNIT_CASE(test_memset64), KUNIT_CASE(test_long_origin_chain), + KUNIT_CASE(test_stackdepot_roundtrip), {}, };