Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp2591788pxt; Mon, 9 Aug 2021 04:27:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwl8LzYyPqBt9ZCOiHVmvt2apI1+tULDC5wNl7JaEhueGsOk8/co87FVcU2kZNqx4DAZWiy X-Received: by 2002:a05:6402:440e:: with SMTP id y14mr29478321eda.38.1628508458143; Mon, 09 Aug 2021 04:27:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628508458; cv=none; d=google.com; s=arc-20160816; b=qKakY6ULIvm/l3kgE2zuD4DVvJPf3ZgQ7X/uXE+834WGNRvpc60Lzrxe5nk1Lygflg HErVMBe4XtkM3qnuKER8pgDg7KZCcbeX0ee7lOnTkOGjVu0uf/1pWOBUhO5sTE1lw3/a WI+PYxGF+s52u17d91MA9Jp+70Dl+wPu4TSpjjadzahhS8De7rYfjAN0lA9Wk63ixeEE tVdsgh4kwHHBk3QUkD+Q+W2KuD88XBopa7k5/ufcy5UxnFj2EyWy+Qalw5udW6TqDZ2x gkrHjPozW123AQMZk+GqXDjvFfUHV8tHb0vli/a9iMjzEBWsc3jFx+aRNiO7oA072YTb seDA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=ydXqiAdNSjBzhuq33PSd4SOBXITdQ3zj3AJIcpBrcC0=; b=uK3lMYHVrTj5DqyiN9aeQ3D5sFxkaIKUfmlIV+x1vyosuojoiZeyfZBo9fTnkgbhKx scqtU8nj/i6MFf6hsciADA6IoaLpXCa1ywKlDKhNhtsJopvV+RYclYdhQUOMMYdrd0Qy zISRRAWs2rXPo0S9JIKroZX+eEwwqehc+uWsX6lZ1TlvWacOM7lZVjDkic303MRJfbpc mtO4Z0pHgT8Sq9nVH3r0/4WDQ0EUi05rGr/vsqqoRi+cprSSPW82RAGN9y2NJLsvt+l+ s5KITQY7s6F8+WBfJxuC+Iby32TfErIsC1+l2I0Mrwev6lTR2A5HWNdJNGtwoGmOg0gp BFIg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=ACFrOCrP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n21si17628935edt.352.2021.08.09.04.27.12; Mon, 09 Aug 2021 04:27:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=ACFrOCrP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235174AbhHIL0H (ORCPT + 99 others); Mon, 9 Aug 2021 07:26:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59710 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235178AbhHIL0E (ORCPT ); Mon, 9 Aug 2021 07:26:04 -0400 Received: from mail-qt1-x84a.google.com (mail-qt1-x84a.google.com [IPv6:2607:f8b0:4864:20::84a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0AABFC0613D3 for ; Mon, 9 Aug 2021 04:25:44 -0700 (PDT) Received: by mail-qt1-x84a.google.com with SMTP id q10-20020a05622a04cab0290267bc0213a9so7484832qtx.0 for ; Mon, 09 Aug 2021 04:25:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=ydXqiAdNSjBzhuq33PSd4SOBXITdQ3zj3AJIcpBrcC0=; b=ACFrOCrPC/gWYLJhrHcvZMryCeWRxLmYeAVxd7PxobMhHBsItOpjOhhG0fQ776uxp4 5kZWjUVhU6EHhuYOYxy4j1JTin04wc8uUJYZu9D3smwb4D3ph5pjLNMMShBRwKVSFmuI zvJ919MH+EyPEcv/0tvSJ21+2d8vVh7fWBrpJ439A3tGx4kY7kIJgeNvU66WVWPqApij +F6VMymsPOUzQouIuyzd/erwIPVn91HbkRllcDtRCJ511rxvyibrwJ5oV4CbWLhTHG84 2EYJCU33XE7Y4iuGFe6DWvVtXkucf7dGHdo0fvz8zbX55/5q8LhU0Hm4AllOI13ZGNNF ObgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=ydXqiAdNSjBzhuq33PSd4SOBXITdQ3zj3AJIcpBrcC0=; b=dW1dfz8MA9A2TYChEmB8fZqkA2PN/YnB5cLed7BIJk5jFdOJ/y1ZjKDfxhbR/rXm8Q X89+e9ZIUqSxRadpwOyYdFJD4W4/PVjPPNVxreOYL8rV5Ruo84zPk7kWiD0PsSMtddbf 24/XZlf04lrrS8qP8VQG6sER5Xu6FsKjLtLC0awKaE1ari9z2kH+N22kN6YX9wwKi5X9 WTGmO5caVTMSFZx0iC9DAJ4TyC2c5ziV4Y9oOwOkwWvaPIhFPFBV9KbgYtZfO3SORtNc wB95FGhFjTm2nMxOIrqtVo+TEHzT/FnJMOIIQ/kSUPVFxqpU33aNzeYGYqz+BTWbVJkq z4QQ== X-Gm-Message-State: AOAM533IjQK7KRMJdkdP2dEbyDzCfJGXNtCnTrPiMs9hQn9J8mt0vnye wIWvNfKUMpvn6O74FtNSCadYjO4+XQ== X-Received: from elver.muc.corp.google.com ([2a00:79e0:15:13:e5a3:e652:2b8b:ef12]) (user=elver job=sendgmr) by 2002:a0c:e908:: with SMTP id a8mr23093025qvo.61.1628508343117; Mon, 09 Aug 2021 04:25:43 -0700 (PDT) Date: Mon, 9 Aug 2021 13:25:11 +0200 In-Reply-To: <20210809112516.682816-1-elver@google.com> Message-Id: <20210809112516.682816-4-elver@google.com> Mime-Version: 1.0 References: <20210809112516.682816-1-elver@google.com> X-Mailer: git-send-email 2.32.0.605.g8dce9f2422-goog Subject: [PATCH 3/8] kcsan: test: Fix flaky test case From: Marco Elver To: elver@google.com, paulmck@kernel.org Cc: mark.rutland@arm.com, dvyukov@google.com, glider@google.com, boqun.feng@gmail.com, kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If CONFIG_KCSAN_REPORT_VALUE_CHANGE_ONLY=n, then we may also see data races between the writers only. If we get unlucky and never capture a read-write data race, but only the write-write data races, then the test_no_value_change* test cases may incorrectly fail. The second problem is that the initial value needs to be reset, as otherwise we might actually observe a value change at the start. Fix it by also looking for the write-write data races, and resetting the value to what will be written. Signed-off-by: Marco Elver --- kernel/kcsan/kcsan_test.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/kernel/kcsan/kcsan_test.c b/kernel/kcsan/kcsan_test.c index d93f226327af..e282c1166373 100644 --- a/kernel/kcsan/kcsan_test.c +++ b/kernel/kcsan/kcsan_test.c @@ -493,17 +493,24 @@ static void test_concurrent_races(struct kunit *test) __no_kcsan static void test_novalue_change(struct kunit *test) { - const struct expect_report expect = { + const struct expect_report expect_rw = { .access = { { test_kernel_write_nochange, &test_var, sizeof(test_var), KCSAN_ACCESS_WRITE }, { test_kernel_read, &test_var, sizeof(test_var), 0 }, }, }; + const struct expect_report expect_ww = { + .access = { + { test_kernel_write_nochange, &test_var, sizeof(test_var), KCSAN_ACCESS_WRITE }, + { test_kernel_write_nochange, &test_var, sizeof(test_var), KCSAN_ACCESS_WRITE }, + }, + }; bool match_expect = false; + test_kernel_write_nochange(); /* Reset value. */ begin_test_checks(test_kernel_write_nochange, test_kernel_read); do { - match_expect = report_matches(&expect); + match_expect = report_matches(&expect_rw) || report_matches(&expect_ww); } while (!end_test_checks(match_expect)); if (IS_ENABLED(CONFIG_KCSAN_REPORT_VALUE_CHANGE_ONLY)) KUNIT_EXPECT_FALSE(test, match_expect); @@ -518,17 +525,24 @@ static void test_novalue_change(struct kunit *test) __no_kcsan static void test_novalue_change_exception(struct kunit *test) { - const struct expect_report expect = { + const struct expect_report expect_rw = { .access = { { test_kernel_write_nochange_rcu, &test_var, sizeof(test_var), KCSAN_ACCESS_WRITE }, { test_kernel_read, &test_var, sizeof(test_var), 0 }, }, }; + const struct expect_report expect_ww = { + .access = { + { test_kernel_write_nochange_rcu, &test_var, sizeof(test_var), KCSAN_ACCESS_WRITE }, + { test_kernel_write_nochange_rcu, &test_var, sizeof(test_var), KCSAN_ACCESS_WRITE }, + }, + }; bool match_expect = false; + test_kernel_write_nochange_rcu(); /* Reset value. */ begin_test_checks(test_kernel_write_nochange_rcu, test_kernel_read); do { - match_expect = report_matches(&expect); + match_expect = report_matches(&expect_rw) || report_matches(&expect_ww); } while (!end_test_checks(match_expect)); KUNIT_EXPECT_TRUE(test, match_expect); } -- 2.32.0.605.g8dce9f2422-goog