Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp6421697rwl; Mon, 9 Jan 2023 08:08:55 -0800 (PST) X-Google-Smtp-Source: AMrXdXv658H4aCPXaGr2kP/Wl5GRWKj8HKbl0/cr8BfyQJDbo7NlGfePHCMzN+uGnWVbVvu60mBI X-Received: by 2002:a17:902:c404:b0:192:5eee:323a with SMTP id k4-20020a170902c40400b001925eee323amr99471823plk.28.1673280535635; Mon, 09 Jan 2023 08:08:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673280535; cv=none; d=google.com; s=arc-20160816; b=WU75XpaXvb+Y1TEGIBvUhX0X9nUCo0M3lcuzPXeGOXg1WmRWgwM71mzwM9siwZ7zZT JXT7q/vM4u/xQJis/7/fNIs4uWiOuEWPt75H71etAnrXyIvxGY6TM5To6TphGN1Pxqz3 JA4Bl5wKyCXHSuxhUyvzJcbZfFWH/M8juFdnXnP+c2ZAATSnU/zzW5HkNQzxkrd6g1a9 0iXK6k/2QIBy2jzsVE9OJKUoXMe4eo68689kk+M204mGi7KzTIkAmP+zOIqXKme1Q7pF XGNkwDE9W1hT1u8jntYcgSC9NpYaxfe8JGF4BTmnpgDaQcF1GpfEPbSp3o3e8XUgZ+BL 4KLA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=gnaAG4YDJhYITmoc4JFALivyXUFRt7jauTm0mQYzMbQ=; b=J8DRINZwFRftC2r/j4jDS0fYUZ/LO2k3uaOxfE3bLxjBfa5376S5nQBZ2GctF09roc Pvnpkrj1aKuiqzMy217QV/iKAFpdwMz0HToRtG9732/LHf4gKMpHi6SWbB153DhFlhvL dsrvW/wpcjJVzZjGcck/sxJtLRwvfKfljpBLQ9tO/DvVoEIFRFAcZk4Fj5zTWmTVzjKU 5GQPxQMKqdrDNk3kGpeP58r66kLvi5+rNPXWElmJOqyxgrzaZpq/bVWc7/xHAFV2HxfL phfy9UUcFUvKs8uAO3piP6owSgxnMMF/KvEe1qFQw7XYIxDJAXpT/4N9ZTu67PaXOuen adzQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=CrmUUFgE; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n10-20020a63b44a000000b004793911ef21si9380984pgu.163.2023.01.09.08.08.48; Mon, 09 Jan 2023 08:08:55 -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=@gmail.com header.s=20210112 header.b=CrmUUFgE; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237287AbjAIP7a (ORCPT + 52 others); Mon, 9 Jan 2023 10:59:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39306 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237268AbjAIP7X (ORCPT ); Mon, 9 Jan 2023 10:59:23 -0500 Received: from mail-pl1-x62e.google.com (mail-pl1-x62e.google.com [IPv6:2607:f8b0:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ABFAB3B902; Mon, 9 Jan 2023 07:59:17 -0800 (PST) Received: by mail-pl1-x62e.google.com with SMTP id jl4so9964840plb.8; Mon, 09 Jan 2023 07:59:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=gnaAG4YDJhYITmoc4JFALivyXUFRt7jauTm0mQYzMbQ=; b=CrmUUFgEgmvDxgs5A/ywFQsggyIunQbSDeV8ufkm1vBRaa/INDWTY+EsCaw8oXK2/S FlWVQQPAGncAry0fIZS3oV95zVShMeJ35dEndt4MBH7cH6D/KbzFXwTenGx0e4gN6pz3 ze1OWOZGTq5BQhKmGfiHESF7eX96nqM1a1Dymd78oGwSKFKxI6wdkpb4hOVqz6aSA6kF PlnEEqn7IcEaiemhdsL8KC92Ngjv69jnXx2VCoh/tZuQNIWaVTAI2wXqRIdWIkiglgtU fxTq+eUA7d359jNUK4fT4Js77L/+4nz7XNMiNxK21CARbh0+73CPEahjd+lySbtYVRUJ /OVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=gnaAG4YDJhYITmoc4JFALivyXUFRt7jauTm0mQYzMbQ=; b=REPESrHgwJh3g2adS3S3+5i/e4ETH4ASVGFfTOihynKUjt00rrz+YOI1wcThRkQA0E Mit32a4pILvQnbUHV+gfZz3+ZFyaHQgeIsfzb15vFZ+jXfhfP3wfvitm1kFQtb9n84cV gNzAHvzcpWybtAwrSDyLViJ7CBVnsBsLp30UFH22UqBKH4Gi6/0wcKhyOj2IwrWp9tvL 1EoJP3j77JZQuKzvn17qT5Ma8wIU8HD80tgIaKZ53cbiDZxQjL94GMRnfs2p1DZq22dn egJDM0FOgxATGjs9tdzO+QRRW5oCv1UeT8xM+6l9Gpm2kngvwpB1dNNm3rKQV+mPAEdw V/dw== X-Gm-Message-State: AFqh2komyn9eJZcNU3NcWhwTaFqLto7waOQlfkUUBSFhkpSK39WWoUSK RUpbM0k7g0ThwRWPVYctM5WZrOaO4O7D+Bc62d4vnbufnZ0= X-Received: by 2002:a17:90a:4311:b0:214:291f:87b5 with SMTP id q17-20020a17090a431100b00214291f87b5mr5835174pjg.115.1673279956980; Mon, 09 Jan 2023 07:59:16 -0800 (PST) MIME-Version: 1.0 References: <20221219052128.18190-1-zhouzhouyi@gmail.com> <20230109152505.GA4070882@paulmck-ThinkPad-P17-Gen-1> In-Reply-To: <20230109152505.GA4070882@paulmck-ThinkPad-P17-Gen-1> From: Zhouyi Zhou Date: Mon, 9 Jan 2023 23:59:05 +0800 Message-ID: Subject: Re: [PATCH linux-next] mark access to tick_do_timer_cpu with READ_ONCE/WRITE_ONCE To: paulmck@kernel.org Cc: Frederic Weisbecker , fweisbec@gmail.com, tglx@linutronix.de, mingo@kernel.org, rcu@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,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, Jan 9, 2023 at 11:25 PM Paul E. McKenney wrote: > > On Mon, Jan 09, 2023 at 01:51:29PM +0100, Frederic Weisbecker wrote: > > 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. > > Please also an analysis of why the compiler cannot do any destructive > optimizations in this case. Maybe also comments. I want to try the analysis above, as a newbie I have taught myself LLVM for 3 years in my spare time ;-) > > > One more thing on my TODO list, but feel free to beat me at it :-) Please take your time ;-) Please don't look my next possible email as a reminder ;-) > > I know that feeling! ;-) > Thanx, Zhouyi > Thanx, Paul