From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C5319C433E6 for ; Mon, 31 Aug 2020 18:18:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A3CEA2071B for ; Mon, 31 Aug 2020 18:18:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1598897911; bh=J4WEUXtYe88E70OaG8y7dEtY7Vg35wzfoZDb+eraBN0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=w+boX4j+uPiJquXaoTzb/XWYn8phg7YSa+XJKsVZFteKgkKjh8g6w57UnK/kL1GcN gK6CQu9ZY9e6mjM60qQWYjmf6QQqXlzf5l4v4ZfgPeixPKQWRjCdz1ZRcfSRE7rx1u zDrXVo+xgaLKbMJwVKNmjggV5ZcHk2c4Z8Pnvgxs= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729646AbgHaSS3 (ORCPT ); Mon, 31 Aug 2020 14:18:29 -0400 Received: from mail.kernel.org ([198.145.29.99]:51680 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729040AbgHaSSH (ORCPT ); Mon, 31 Aug 2020 14:18:07 -0400 Received: from paulmck-ThinkPad-P72.home (unknown [50.45.173.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 2776D21531; Mon, 31 Aug 2020 18:18:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1598897887; bh=J4WEUXtYe88E70OaG8y7dEtY7Vg35wzfoZDb+eraBN0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MOB9L8AyWGGc3FqpxI8fhVn3XiEeRJtQyBVeQbXV9yWubhDhOXgErYy5FiSRAfWrk ITkjCTO6PpppWxuNEda4MxfwxtbA9B7s23ReuQ7j83W72OwoeFuTCuTXswRjeWdkM2 kHFK7dptWMGToWBpOfvRHIzPLVm6Z1TkHaOVjqSE= From: paulmck@kernel.org To: linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com, kernel-team@fb.com, mingo@kernel.org Cc: elver@google.com, andreyknvl@google.com, glider@google.com, dvyukov@google.com, cai@lca.pw, boqun.feng@gmail.com, "Paul E . McKenney" Subject: [PATCH kcsan 06/19] kcsan: Skew delay to be longer for certain access types Date: Mon, 31 Aug 2020 11:17:52 -0700 Message-Id: <20200831181805.1833-6-paulmck@kernel.org> X-Mailer: git-send-email 2.9.5 In-Reply-To: <20200831181715.GA1530@paulmck-ThinkPad-P72> References: <20200831181715.GA1530@paulmck-ThinkPad-P72> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Marco Elver For compound instrumentation and assert accesses, skew the watchpoint delay to be longer if randomized. This is useful to improve race detection for such accesses. For compound accesses we should increase the delay as we've aggregated both read and write instrumentation. By giving up 1 call into the runtime, we're less likely to set up a watchpoint and thus less likely to detect a race. We can balance this by increasing the watchpoint delay. For assert accesses, we know these are of increased interest, and we wish to increase our chances of detecting races for such checks. Note that, kcsan_udelay_{task,interrupt} define the upper bound delays. When randomized, delays are uniformly distributed between [0, delay]. Skewing the delay does not break this promise as long as the defined upper bounds are still adhered to. The current skew results in delays uniformly distributed between [delay/2, delay]. Acked-by: Peter Zijlstra (Intel) Signed-off-by: Marco Elver Signed-off-by: Paul E. McKenney --- kernel/kcsan/core.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/kernel/kcsan/core.c b/kernel/kcsan/core.c index 4c8b40b..95a364e 100644 --- a/kernel/kcsan/core.c +++ b/kernel/kcsan/core.c @@ -283,11 +283,15 @@ static __always_inline bool kcsan_is_enabled(void) return READ_ONCE(kcsan_enabled) && get_ctx()->disable_count == 0; } -static inline unsigned int get_delay(void) +static inline unsigned int get_delay(int type) { unsigned int delay = in_task() ? kcsan_udelay_task : kcsan_udelay_interrupt; + /* For certain access types, skew the random delay to be longer. */ + unsigned int skew_delay_order = + (type & (KCSAN_ACCESS_COMPOUND | KCSAN_ACCESS_ASSERT)) ? 1 : 0; + return delay - (IS_ENABLED(CONFIG_KCSAN_DELAY_RANDOMIZE) ? - prandom_u32_max(delay) : + prandom_u32_max(delay >> skew_delay_order) : 0); } @@ -470,7 +474,7 @@ kcsan_setup_watchpoint(const volatile void *ptr, size_t size, int type) * Delay this thread, to increase probability of observing a racy * conflicting access. */ - udelay(get_delay()); + udelay(get_delay(type)); /* * Re-read value, and check if it is as expected; if not, we infer a -- 2.9.5