Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp2650447pxu; Mon, 7 Dec 2020 11:46:23 -0800 (PST) X-Google-Smtp-Source: ABdhPJy/08h0CEMrONZhfE5VhX1x+kQxNwzEKTu82xP1sJm0bed7UB31Bu/gpluZRuyukW6f+2EQ X-Received: by 2002:a17:906:4482:: with SMTP id y2mr20498282ejo.342.1607370382818; Mon, 07 Dec 2020 11:46:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607370382; cv=none; d=google.com; s=arc-20160816; b=mf3kBA6B/FgTC1COIZenv75h+4dWm4dIZF11dZgmPeWATUSzbOby1EgI81097t1MyI x3VFRAu7u1U3A4/jzjWZ5eE4UqBbp4ttFni4/8+leZbrFx5fGmMvPjQERtogpvtVOGqm 1sxQawTvWZxb5bvnb8IhHwAXRkDORejtLAdJcluKZ6grCsFvvXlvFBMvC+XMpDBfBCtb +/CxvTywsrsqOUxoGJ/QK9YMi9Pkn0yCQHiEU2dkVtR0BCMH8s0Kaoc3IZEn1h9+v+Zp eZhziiebGGIedxcgMTdbkoJUF8hsMt0NoyyE+nCS/jEymWB6vKWYB2IEs5G1M8WD5thv jIoQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:references :in-reply-to:subject:cc:to:dkim-signature:dkim-signature:from; bh=I334otsRnjsdPvZNHbr6PY/AxaoibaWvPiqif0DnRJQ=; b=Z4cYpa5cO3fFvKStJUNa+Fm/2B/UaoFkyP0cCYj1kAtiJ0ApmG8mhbTkugQ3AGRXoz Jhrvwe+Yo+5V41CvvhnrIsaGj5sxbtGk5bnQLGpAeNCB6KU7OGU3ziksOhi3x8PLdmfF YNV8VnPBG29loMYixHpqWeKOWulKdiYBLJAqDT+RF6CuviNrHWAM93XBJ60APMf2Szw+ TyPDp0IyZ5kOs3dDrx2Sj9obWymJKFYWIqS+zVgoacxg66HVt/HXK3pIajpPqSQ455hp cVev3tOQ2QlyWOjLjdSkdKaZlnQDtnuGb33gdpzx2XKoob1WCoxuk2WelUDXrYsUKwQ2 3e1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=JZByJyfF; dkim=neutral (no key) header.i=@linutronix.de header.b=iWz5rZ60; 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=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x17si7280037ejw.478.2020.12.07.11.45.59; Mon, 07 Dec 2020 11:46:22 -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=@linutronix.de header.s=2020 header.b=JZByJyfF; dkim=neutral (no key) header.i=@linutronix.de header.b=iWz5rZ60; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725995AbgLGToD (ORCPT + 99 others); Mon, 7 Dec 2020 14:44:03 -0500 Received: from Galois.linutronix.de ([193.142.43.55]:38484 "EHLO galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725808AbgLGToD (ORCPT ); Mon, 7 Dec 2020 14:44:03 -0500 From: Thomas Gleixner DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1607370201; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=I334otsRnjsdPvZNHbr6PY/AxaoibaWvPiqif0DnRJQ=; b=JZByJyfFmV0EhRPwqzzi+wmjs2CjVeN5+RRB0rc76BuIQQpNTBqr+mZN8qvu5Gmcsn9b2f jWg5sSC4b7/l50RmsuVuDQsYZf7YnUg7sXKrxB2tAppho6b5BJcCAxkJpwx8wUOcx1Ao3o Z5ybNdP7LJS8XNdfyqUpOjGXvMo/EnY5wNwcTENI/G9iYpC+J1bTK52P04DuSFE0OgMpDV XfHO9VrKs54LAq23igdAJtS24Lkq7KtIpl5nJ93NGzifTFNHHHSwqDLpttqTVvap6ClZzS cV0GGL/eNiAMTNgRKrn5IjjpcOO+oYI4Mm8GkTGsaihOPXUNqb+TW7ZCVOqbHg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1607370201; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=I334otsRnjsdPvZNHbr6PY/AxaoibaWvPiqif0DnRJQ=; b=iWz5rZ60m9F4yyaFdHSTlDi1PJXZWUurgulnQya5jua2xiG9HSIYpZLxgOsJ6NJoFVoCQk t1/nYwc2w4hqhCDw== To: Marco Elver Cc: Peter Zijlstra , LKML , kasan-dev , "Paul E. McKenney" , 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 In-Reply-To: References: <20201206211253.919834182@linutronix.de> <20201206212002.876987748@linutronix.de> <20201207120943.GS3021@hirez.programming.kicks-ass.net> <87y2i94igo.fsf@nanos.tec.linutronix.de> Date: Mon, 07 Dec 2020 20:43:21 +0100 Message-ID: <87eek14d2e.fsf@nanos.tec.linutronix.de> MIME-Version: 1.0 Content-Type: text/plain Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Dec 07 2020 at 19:19, 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: >> > 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. I agree. Lets keep it simple and have the data_race() only covering the actual access to the racy variable, struct member. The worst case we could end up with would be if (data_race(A) == data_race(B)) which would still be clearly isolated. The racy part is not the comparison, it's the accesses which can cause random results for the comparison. Thanks, tglx