Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp2650896pxu; Mon, 7 Dec 2020 11:47:12 -0800 (PST) X-Google-Smtp-Source: ABdhPJxwwfcQWVzd3AzkX1ILppCU7xbETIbh7gMRXkCNxxy3Eg0DtNVB47TmoG5N/L68Q1uhpCLa X-Received: by 2002:a05:6402:456:: with SMTP id p22mr21432857edw.26.1607370432122; Mon, 07 Dec 2020 11:47:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607370432; cv=none; d=google.com; s=arc-20160816; b=W1o5/Y0ITkYh47THg3i7S/uhcabKru8LTVtOj79u5zseFzikuNSNGyEUP5EMH5B/Pv 9mlHSNPU7uuCKOl5PiOzwYD27to8+sWd7C8sxflHJl8cZh3OBD1H0k0/ctGcs3ZTlPOn EDwpSYaYOKwj+na75LF/MjURM8w78WQ8UB19iWcoTeHPCgQXN+OLW4UvybGmO5/FjbfM ShLqMUchk2O34jNcIkN+BdMzPoBMOnn/MNCZN7wvoLlc1kZum8bEiciRAbDrmbmtnuJh lnXeyCNmp5wVkj6HZQ1Cc1UEr3ez+z1ntX1wRXKPvwNVd7K6ScoyERVmmfGrPBQk+HZI 2IgQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:reply-to:message-id:subject:cc:to:from :dkim-signature:date; bh=s9TbkhmGrBs7L19UzBiTcx3edgSr5tmaoL0n6gSqs3Y=; b=TkVpeiCeg1DfpnXYirzEe/e51QDQ8hCiRmbf8THxbODXFKlRAR13jrVpmgyTNx5rav T9+XEBfsgrkqCiCawztWDK7vSOgakWenWnFtxCo3w5mawrtb20oSOtEEmrrd/ew6AVL2 50HEdKlrXJund2tvA3JuW+bOx7kJCGvyiKq9lnN9PIIvGho5ijJhoq/IeuoKVwcTOxOv FSsUHFi86ESh6/CUJB6O+B0EKBuOYFpcv2LplQyqPcul3ZCU4C0yrhYadVB6mCNFvvSr bfB1ru3qz0ItQja8L/m1x5NSKvDeiYb65cC5XjKqVcGQnBNTLS/EQlf6wA4fxCwjWbhe eJag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=V1kAKtuI; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r24si8696317edv.579.2020.12.07.11.46.49; Mon, 07 Dec 2020 11:47:12 -0800 (PST) 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=@kernel.org header.s=k20201202 header.b=V1kAKtuI; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726873AbgLGTor (ORCPT + 99 others); Mon, 7 Dec 2020 14:44:47 -0500 Received: from mail.kernel.org ([198.145.29.99]:60166 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725822AbgLGTor (ORCPT ); Mon, 7 Dec 2020 14:44:47 -0500 Date: Mon, 7 Dec 2020 11:44:06 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1607370246; bh=YpSaQ97s0/LeG9gYyAiylgUPcNxspCmUmFADpTfEoj0=; h=From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=V1kAKtuIVZylUBLCt60SDMYtUz8DnWI+X8dDv60tOOVb69OlbtJa/55hpPTn6KPFR zSDxVGuA9UzyAwYl2HdwfdZx+jupbgrvfTo/or4o25FzpXMPLLfVCvmrCljo+F3HRq fcqy/+ytItnwZajcjVIAtp1/dR/dQWrO928KUZ3WPVxKQXv/7Gpu4InSxiEXsWOu85 CcG3zQ24CkuPADpDROfQUtF7ehWf8KkuFPMbUHH13cDtXf5Ks/PZJ2O5ItT7UMa6l1 LBfKtgyXULk+/8kxGb+KcqT0gE6QXmdhntsUdc8T6OteHvZb+47HQvrV1liLfAMDdt MeqWd7irt0pQg== From: "Paul E. McKenney" To: Marco Elver Cc: Thomas Gleixner , Peter Zijlstra , LKML , kasan-dev , Ingo Molnar , Frederic Weisbecker , Will Deacon , Naresh Kamboju , syzbot+23a256029191772c2f02@syzkaller.appspotmail.com, syzbot+56078ac0b9071335a745@syzkaller.appspotmail.com, syzbot+867130cb240c41f15164@syzkaller.appspotmail.com Subject: Re: [patch 3/3] tick: Annotate tick_do_timer_cpu data races Message-ID: <20201207194406.GK2657@paulmck-ThinkPad-P72> Reply-To: paulmck@kernel.org References: <20201206211253.919834182@linutronix.de> <20201206212002.876987748@linutronix.de> <20201207120943.GS3021@hirez.programming.kicks-ass.net> <87y2i94igo.fsf@nanos.tec.linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Dec 07, 2020 at 07:19:51PM +0100, Marco Elver wrote: > On Mon, 7 Dec 2020 at 18:46, Thomas Gleixner wrote: > > On Mon, Dec 07 2020 at 13:09, Peter Zijlstra wrote: > > > On Sun, Dec 06, 2020 at 10:12:56PM +0100, Thomas Gleixner wrote: > > >> + if (data_race(tick_do_timer_cpu) == TICK_DO_TIMER_BOOT) { > > > > > > I prefer the form: > > > > > > if (data_race(tick_do_timer_cpu == TICK_DO_TIMER_BOOT)) { > > > > > > But there doesn't yet seem to be sufficient data_race() usage in the > > > kernel to see which of the forms is preferred. Do we want to bike-shed > > > this now and document the outcome somewhere? > > > > Yes please before we get a gazillion of patches changing half of them > > half a year from now. > > That rule should be as simple as possible. The simplest would be: > "Only enclose the smallest required expression in data_race(); keep > the number of required data_race() expressions to a minimum." (=> want > least amount of code inside data_race() with the least number of > data_race()s). > > In the case here, that'd be the "if (data_race(tick_do_timer_cpu) == > ..." variant. > > Otherwise there's the possibility that we'll end up with accesses > inside data_race() that we hadn't planned for. For example, somebody > refactors some code replacing constants with variables. > > I currently don't know what the rule for Peter's preferred variant > would be, without running the risk of some accidentally data_race()'d > accesses. > > Thoughts? I am also concerned about inadvertently covering code with data_race(). Also, in this particular case, why data_race() rather than READ_ONCE()? Do we really expect the compiler to be able to optimize this case significantly without READ_ONCE()? Thanx, Paul