Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2928438pxa; Tue, 18 Aug 2020 01:37:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJytgHYnUcfBWTQiyUZPBIEc63seiB2F5k683rVywGMeFxdPawsb1xfo16+62SD4bKQiz3ZH X-Received: by 2002:a17:906:af72:: with SMTP id os18mr18494871ejb.43.1597739872483; Tue, 18 Aug 2020 01:37:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597739872; cv=none; d=google.com; s=arc-20160816; b=GRzjvacooPAlprTX040v2yOb/6qH2w4HqPZbJHfNiKWFn6UPP/nTjpSDUQFhWQ7Bf5 eStZEY386o9z+wKAgbeyUvXwMoqva7DTRtVK86pPpkCLSIvjrxvT5v07HAEI319KrwLU kM+AKQLDJ5HztzLqK/hvflD2womrUhsHhZyRH4u17cQ+I432xkFExpRJ3HFx7gilQNF4 Ty/llZYU5zFw7Sq+bkgECS3RGxQatdhdsoUci+QGQPyAFvxGNwJWo1kDSSZG+9AHWTVA EgsKQzRRBEOZW9E+tW0z7X/EnE6c2iyIWFKqiFnqANy0zWQEPDfN8rE+9WshURWe5Y7z ARrg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=VaNLfRHzjmAhC1MdbIpHRe1zX0H+Foac1RDS2VP3MjY=; b=lnWvNVbFMgA3ukx+k+KzklazaJlG/MH0dqvOnOXs46g5Ep3x2taJlXVyRHqDYaCg3Y axntRM5P7GGikWx8QUWXxnbkMwntGV/Vg8iSQ5Ba7Mv+hAlsxSqbuNwOJHAUX+d4io95 075fCcWcnLm96a1DYJSCkRaFe/edUeo/9YHiv5cjoQnd8ufPfgyw4BOQbddL0mVjSy+I CG2FFuuuiNPKU95M7BDVfz1aK/4ynnBrX/EK+vg7/ZgNObh5ODKVrfL1UOXI3lgg2o76 dncfZzRJTOe6EhqjQcGzlkA/MA1kILLw31y8m/8Q3wfLSTPt9/GQj0wSPePu+30mGjJi fZ3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=V8m3BO+x; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h13si12977729edv.463.2020.08.18.01.37.29; Tue, 18 Aug 2020 01:37:52 -0700 (PDT) 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=@google.com header.s=20161025 header.b=V8m3BO+x; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726581AbgHRIen (ORCPT + 99 others); Tue, 18 Aug 2020 04:34:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52076 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726043AbgHRIem (ORCPT ); Tue, 18 Aug 2020 04:34:42 -0400 Received: from mail-oi1-x242.google.com (mail-oi1-x242.google.com [IPv6:2607:f8b0:4864:20::242]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5FC43C061389 for ; Tue, 18 Aug 2020 01:34:41 -0700 (PDT) Received: by mail-oi1-x242.google.com with SMTP id u24so16134205oic.7 for ; Tue, 18 Aug 2020 01:34:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=VaNLfRHzjmAhC1MdbIpHRe1zX0H+Foac1RDS2VP3MjY=; b=V8m3BO+xQsaDn6apX6pTobxkTbSUhaMeuMiydfuHreAWCgHIaA991/fUS80QjjH6tr 9Lfd3ND0qs72vIyYPvdS6NX4eSyCjqJVLGkwnfxit5pv0DWj0rzvb75ZfUBuogBAKUEI ZCM+qe2Qpg8RDHCsOOwIW77ytRIC3Oh97zJ80dKa7gO0DSp4imvOur356ErhatfrY7ow 4xJg4OQdWztwPcPMt/d45VF32M4g4plqkKxpWjzFAjts+apj2yvLW4Nw6pF6l2X1i6Lv rBCIYWRNFhsVsun8E2QDtNBeFTf+/IwwbOb7SNoenOgPJJA9D6tXe9vH8SJJJ81AAEuf LbHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=VaNLfRHzjmAhC1MdbIpHRe1zX0H+Foac1RDS2VP3MjY=; b=VP4HhgUk5miSNo6FaAinq6vncnxAHtql40+qJs1uSjONELFSqYj5QDYt6pwj/Twoi5 7SyU20oBfNeVA1xEhg8z2JoI+DqtS0vDRqOHrZBG1gYXs4JOrQ25t3CAWLr6rw2DdP2c rm0wf+sgJcfbAZCpoqD9DTKWxitb2RDO5MpA3/iiPhMu8s20+ExKpPc4zijh6s2O+1Kz ZakkUMK7PUjkGnBDqRee7Kxc8HOY175WJuXancOEZrqseUSuPRD7Piuoi9mydCwcz84I sseeWYDnZZY/cTdRJcAMpB7Rnlg5f0p25GmSpIS8LjNGpcIFh9htsWyFJMdM+ED3Flv6 AC7g== X-Gm-Message-State: AOAM533bx8JOmNNZ9gQbYrZlwwwVQSkaGYnEZND3NriFgwcvwranE2qO J2qVO8VXwIKhNTyUrKhwJerHpCJqTiZE3bKIOZf60Q== X-Received: by 2002:aca:5145:: with SMTP id f66mr12152867oib.172.1597739680577; Tue, 18 Aug 2020 01:34:40 -0700 (PDT) MIME-Version: 1.0 References: <20200813163859.1542009-1-elver@google.com> In-Reply-To: <20200813163859.1542009-1-elver@google.com> From: Marco Elver Date: Tue, 18 Aug 2020 10:34:28 +0200 Message-ID: Subject: Re: [PATCH] bitops, kcsan: Partially revert instrumentation for non-atomic bitops To: Marco Elver , "Paul E. McKenney" Cc: Will Deacon , Arnd Bergmann , Mark Rutland , linux-arch , Dmitry Vyukov , kasan-dev , LKML Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 13 Aug 2020 at 18:39, Marco Elver wrote: > Previous to the change to distinguish read-write accesses, when > CONFIG_KCSAN_ASSUME_PLAIN_WRITES_ATOMIC=y is set, KCSAN would consider > the non-atomic bitops as atomic. We want to partially revert to this > behaviour, but with one important distinction: report racing > modifications, since lost bits due to non-atomicity are certainly > possible. > > Given the operations here only modify a single bit, assuming > non-atomicity of the writer is sufficient may be reasonable for certain > usage (and follows the permissible nature of the "assume plain writes > atomic" rule). In other words: > > 1. We want non-atomic read-modify-write races to be reported; > this is accomplished by kcsan_check_read(), where any > concurrent write (atomic or not) will generate a report. > > 2. We do not want to report races with marked readers, but -do- > want to report races with unmarked readers; this is > accomplished by the instrument_write() ("assume atomic > write" with Kconfig option set). > > With the above rules, when KCSAN_ASSUME_PLAIN_WRITES_ATOMIC is selected, > it is hoped that KCSAN's reporting behaviour is better aligned with > current expected permissible usage for non-atomic bitops. > > Note that, a side-effect of not telling KCSAN that the accesses are > read-writes, is that this information is not displayed in the access > summary in the report. It is, however, visible in inline-expanded stack > traces. For now, it does not make sense to introduce yet another special > case to KCSAN's runtime, only to cater to the case here. > > Signed-off-by: Marco Elver > Cc: Dmitry Vyukov > Cc: Paul E. McKenney > Cc: Will Deacon > --- > As discussed, partially reverting behaviour for non-atomic bitops when > KCSAN_ASSUME_PLAIN_WRITES_ATOMIC is selected. > > I'd like to avoid more special cases in KCSAN's runtime to cater to > cases like this, not only because it adds more complexity, but it > invites more special cases to be added. If there are other such > primitives, we likely have to do it on a case-by-case basis as well, and > justify carefully for each such case. But currently, as far as I can > tell, the bitops are truly special, simply because we do know each op > just touches a single bit. > --- > .../bitops/instrumented-non-atomic.h | 30 +++++++++++++++++-- > 1 file changed, 27 insertions(+), 3 deletions(-) Paul, if it looks good to you, feel free to pick it up. Thanks, -- Marco