Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp6158129rwl; Mon, 9 Jan 2023 05:04:28 -0800 (PST) X-Google-Smtp-Source: AMrXdXtkKpo217+h26PZ46wXwGA2H2rz0yyJTK5sDh62WGRKqHx2pwz1jHDDGal7flRyRocLbwk5 X-Received: by 2002:a05:6402:298e:b0:495:d1f4:7609 with SMTP id eq14-20020a056402298e00b00495d1f47609mr12161224edb.19.1673269467885; Mon, 09 Jan 2023 05:04:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673269467; cv=none; d=google.com; s=arc-20160816; b=RmUHD36FfSJC2whxhMUdYMlxPdKDfI0N4yBONyYuAWAwhq1LklPObV0TQH0ewt/MAw 4lEWPT4T2OruIRgKqrOko9ksJFw5a2S9Hr4pVtbrrl+iu4kuJi6iM1kqko1QObKqbvhJ GfYOhqlyz19kv26gqmJe+RKv1NfQHA+DcqFywHt8kb59r4dFkRu+eF5xgyx/aaQBCYF6 w9EhAW3Oqf/4RKjNU6BHYm46S2EMlAYH8B0P2TbtzWt/TzFXxyRD9Kyx3WB76Vh7K5mQ Y4HHuFxzTvvynZiHb/b3WlNpaUFZ4kh9ywlLZUGHSFSrsLe5RFkEyu1C1OTlqteGbYSb 7pLQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=H/sDmY/7GK4Q/+FB4BIupEXbTpdwKHUsEz5gMFLAhtw=; b=o5FfnnaA7HGPhxQqfBLicYD0jlPmxUjSgj5CSJPocDzqU/r9vhg9V/bv3D5KQRv6gA oW2yEj6sJKLm7pyr2r4nK+IsI9+oufUJ1SEHzcYUoecbGcuj6+LI5ABUquin/PP9+WG4 zb3at567rfK4yXDS35140PsCuNo1P6fIgjjhn/wzEitzV7jRYfSR/RKzc/D98o0yDTXG azMQOpmYwTv+3LXNbr9nedUBCqdP/77EKdyYXdjSadkW0IpZ2iR56N2tESPPa/TMtomv vyhmVcbGG357LKpCOwA8QB4HaQdOn5NF8iyZOM8PuysYuaGPg0Z9/SjUuCbiZqypx+Yr idWw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=pk11NsK0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w19-20020a05640234d300b0046b7410c015si10223814edc.18.2023.01.09.05.04.15; Mon, 09 Jan 2023 05:04:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=pk11NsK0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234041AbjAIMv5 (ORCPT + 52 others); Mon, 9 Jan 2023 07:51:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39188 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234182AbjAIMvh (ORCPT ); Mon, 9 Jan 2023 07:51:37 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1B8A46369; Mon, 9 Jan 2023 04:51:35 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id B9254B80D6D; Mon, 9 Jan 2023 12:51:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 155F3C433D2; Mon, 9 Jan 2023 12:51:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1673268692; bh=FLtPDF70FGfxYG+fPIQA1yKaLTx9bihKTRpDvvNDcIU=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=pk11NsK0SySFIjt4dNC3ISnWFkbe6NQUX5iLw+RD8t+djc29Oe+x9Etl0zxqJzm54 uj/VrgIAWrIKMibFIjsd8T2MamtQlvZpBO855C1/kU6YhgQ9+axL8eoK6OjTItAuGY tbmopaf0Kr2OLvlL5DvmaL6T4ef5TlwB825l8RpzeRi1AqLkDW20Gt343rk/R+4wpS sXgPAQSREqH20pbWB602cn0W98UsZTtWi/m5zm8F0r7ZxCOhTQslt/WTkyA1cb93Vb ndu3nV0HgIySwv/GrloC/3+LIrc9oB5ScjpJm5zuUhDO1PJAPh8p/RfXEiVIX96Apc EV6fZB1rbZYfA== Date: Mon, 9 Jan 2023 13:51:29 +0100 From: Frederic Weisbecker To: Zhouyi Zhou Cc: fweisbec@gmail.com, tglx@linutronix.de, mingo@kernel.org, paulmck@kernel.org, rcu@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH linux-next] mark access to tick_do_timer_cpu with READ_ONCE/WRITE_ONCE Message-ID: References: <20221219052128.18190-1-zhouzhouyi@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221219052128.18190-1-zhouzhouyi@gmail.com> X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Dec 19, 2022 at 01:21:28PM +0800, Zhouyi Zhou wrote: > mark access to tick_do_timer_cpu with READ_ONCE/WRITE_ONCE to fix concurrency bug > reported by KCSAN. > > Signed-off-by: Zhouyi Zhou > --- > During the rcutorture test on linux-next, > ./tools/testing/selftests/rcutorture/bin/torture.sh --do-kcsan --kcsan-kmake-arg "CC=clang-12" > following KCSAN BUG is reported: > [ 35.397089] BUG: KCSAN: data-race in tick_nohz_idle_stop_tick / tick_nohz_next_event^M > [ 35.400593] ^M > [ 35.401377] write to 0xffffffffb64b1270 of 4 bytes by task 0 on cpu 3:^M > [ 35.405325] tick_nohz_idle_stop_tick+0x14c/0x3e0^M > [ 35.407162] do_idle+0xf3/0x2a0^M > [ 35.408016] cpu_startup_entry+0x15/0x20^M > [ 35.409084] start_secondary+0x8f/0x90^M > [ 35.410207] secondary_startup_64_no_verify+0xe1/0xeb^M > [ 35.411607] ^M > [ 35.412042] no locks held by swapper/3/0.^M > [ 35.413172] irq event stamp: 53048^M > [ 35.414175] hardirqs last enabled at (53047): [] tick_nohz_idle_enter+0x104/0x140^M > [ 35.416681] hardirqs last disabled at (53048): [] do_idle+0x91/0x2a0^M > [ 35.418988] softirqs last enabled at (53038): [] __irq_exit_rcu+0x6e/0xc0^M > [ 35.421347] softirqs last disabled at (53029): [] __irq_exit_rcu+0x6e/0xc0^M > [ 35.423685] ^M > [ 35.424119] read to 0xffffffffb64b1270 of 4 bytes by task 0 on cpu 0:^M > [ 35.425870] tick_nohz_next_event+0x233/0x2b0^M > [ 35.427119] tick_nohz_idle_stop_tick+0x8f/0x3e0^M > [ 35.428386] do_idle+0xf3/0x2a0^M > [ 35.429265] cpu_startup_entry+0x15/0x20^M > [ 35.430429] rest_init+0x20c/0x210^M > [ 35.431382] arch_call_rest_init+0xe/0x10^M > [ 35.432508] start_kernel+0x544/0x600^M > [ 35.433519] secondary_startup_64_no_verify+0xe1/0xeb^M > > fix above bug by marking access to tick_do_timer_cpu with READ_ONCE/WRITE_ONCE This has been discussed before with passion: http://archive.lwn.net:8080/linux-kernel/1C65422C-FFA4-4651-893B-300FAF9C49DE@lca.pw/T/ To me data_race() would be more appropriate but that would need a changelog with proper analysis of the tick_do_timer_cpu state machine. One more thing on my TODO list, but feel free to beat me at it :-) Thanks.