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=-2.2 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_2 autolearn=no 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 78D26C3A59D for ; Fri, 16 Aug 2019 19:15:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 58C812171F for ; Fri, 16 Aug 2019 19:15:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727597AbfHPTPy (ORCPT ); Fri, 16 Aug 2019 15:15:54 -0400 Received: from mail.kernel.org ([198.145.29.99]:43268 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727545AbfHPTPy (ORCPT ); Fri, 16 Aug 2019 15:15:54 -0400 Received: from oasis.local.home (rrcs-76-79-140-27.west.biz.rr.com [76.79.140.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 79DD12077C; Fri, 16 Aug 2019 19:15:52 +0000 (UTC) Date: Fri, 16 Aug 2019 15:15:41 -0400 From: Steven Rostedt To: Mathieu Desnoyers Cc: linux-kernel , "Joel Fernandes, Google" , Peter Zijlstra , Thomas Gleixner , paulmck , Boqun Feng , Will Deacon , David Howells , Alan Stern , Linus Torvalds Subject: Re: [PATCH 1/1] Fix: trace sched switch start/stop racy updates Message-ID: <20190816151541.6864ff30@oasis.local.home> In-Reply-To: <623129606.21592.1565975960497.JavaMail.zimbra@efficios.com> References: <00000000000076ecf3059030d3f1@google.com> <20190816142643.13758-1-mathieu.desnoyers@efficios.com> <20190816122539.34fada7b@oasis.local.home> <623129606.21592.1565975960497.JavaMail.zimbra@efficios.com> X-Mailer: Claws Mail 3.17.3 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 16 Aug 2019 13:19:20 -0400 (EDT) Mathieu Desnoyers wrote: > ----- On Aug 16, 2019, at 12:25 PM, rostedt rostedt@goodmis.org wrote: > > > On Fri, 16 Aug 2019 10:26:43 -0400 Mathieu Desnoyers wrote: > > > [...] > >> > >> Also, write and read to/from those variables should be done with > >> WRITE_ONCE() and READ_ONCE(), given that those are read within tracing > >> probes without holding the sched_register_mutex. > >> > > > > I understand the READ_ONCE() but is the WRITE_ONCE() truly necessary? > > It's done while holding the mutex. It's not that critical of a path, > > and makes the code look ugly. > > The update is done while holding the mutex, but the read-side does not > hold that mutex, so it can observe the intermediate state caused by > store-tearing or invented stores which can be generated by the compiler > on the update-side. > > Please refer to the following LWN article: > > https://lwn.net/Articles/793253/ > > Sections: > - "Store tearing" > - "Invented stores" > > Arguably, based on that article, store tearing is only observed in the > wild for constants (which is not the case here), and invented stores > seem to require specific code patterns. But I wonder why we would ever want to > pair a fragile non-volatile store with a READ_ONCE() ? Considering the pain > associated to reproduce and hunt down this kind of issue in the wild, I would > be tempted to enforce that any READ_ONCE() operating on a variable would either > need to be paired with WRITE_ONCE() or with atomic operations, so those can > eventually be validated by static code checkers and code sanitizers. My issue is that this is just a case to decide if we should cache a comm or not. It's a helper, nothing more. There's no guarantee that something will get cached. -- Steve > > If coding style is your only concern here, we may want to consider > introducing new macros in compiler.h: > > WRITE_ONCE_INC(v) /* v++ */ > WRITE_ONCE_DEC(v) /* v-- */ > WRITE_ONCE_ADD(v, count) /* v += count */ > WRITE_ONCE_SUB(v, count) /* v -= count */ >