Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp2497120ybz; Sun, 19 Apr 2020 02:50:00 -0700 (PDT) X-Google-Smtp-Source: APiQypLVBxAFXcffFzK6CG7a7n7KORflr3IncXEBnX0ZgX86ShKGvhRMzBroFxzWXwR+v0C4YrlI X-Received: by 2002:aa7:c401:: with SMTP id j1mr9525213edq.31.1587289800037; Sun, 19 Apr 2020 02:50:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587289800; cv=none; d=google.com; s=arc-20160816; b=oAGs0Ezb+ztEuWFodgTIaVIR68iXgUEyjooAOIY+elB/xOHLpxM7G1kDCacFYpfj8v KQQ11Hz5K3EsdlttjIVfcAjVyidOwzT/MDWVULn41V0mFtIww3zjCTKTvGeytrT74FNg JmLu2BCbVx3j//XkUyGRdGvQ1Vignq5IzxpBEOEK1o6fSvKWM5pgtWIsYPl8NH3q2R+7 M5GMtKDFYQf5XEGIr5hLd/zw8d+eovQxAx+lRyK6CfRh8CpQQaDR1FoDJnuJxoMDT49d BYX9vMv/vsN6jAXFO8vtTigKbLROt+MiWZDL2kAmHfqL2fpu7eEjF9eaxBfSAkaJeaoB WgGA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition:mime-version :message-id:subject:cc:to:from:date:dkim-signature; bh=t1mUlJFBauJJoQI/4DdFu/qGHWg9ioYSq6sgs7YFWqs=; b=rpKC3TcBdmqMjxgWeGnegomaKKAV23z+Bq1Awc69uMmM/rRtcEgtcTfVlckNBSkJvk saIAynm7kVhT4OtU+Dna1Sep+uhn1GUPKdca5LkLMIkZ8Y/9CNaAINnp4EeCLKu+9don WaAVc3p3reN2LNsra+2uGAY0DrUm0qmxE09E0gLv95ZgVmg22wBr/+JTvb6kx291iaoj 5ekY1OhkYc/cAFJVfvIw37BO4ZwUknaJoOwu4RaxuRyHigyLzs/VvDW6fLb3jv9HpuWz mOZq5nfAzUhzMYhT2WCuMhGXlVHUNa6WIyB0235q7IEaKJHsdEEOaGJas6yHES28Z2mW vh5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@konsulko.com header.s=google header.b=gENt8TWr; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w21si7616447edt.595.2020.04.19.02.49.37; Sun, 19 Apr 2020 02:50:00 -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=@konsulko.com header.s=google header.b=gENt8TWr; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725990AbgDSJop (ORCPT + 99 others); Sun, 19 Apr 2020 05:44:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38434 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1725832AbgDSJop (ORCPT ); Sun, 19 Apr 2020 05:44:45 -0400 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0138BC061A0C for ; Sun, 19 Apr 2020 02:44:44 -0700 (PDT) Received: by mail-wr1-x434.google.com with SMTP id f13so8222025wrm.13 for ; Sun, 19 Apr 2020 02:44:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=konsulko.com; s=google; h=date:from:to:cc:subject:message-id:mime-version:content-disposition; bh=t1mUlJFBauJJoQI/4DdFu/qGHWg9ioYSq6sgs7YFWqs=; b=gENt8TWr1gdMLI6Tzc/z7QWwbdUWe9XNvTThzpSqOPygNthR0tc6mz1QytQ8M9p1aV +ZyIqdX3OFL5dsKkJgunv9riMFmDXdwUZhI8CQTgPesEi9Qj1keG6cRnL/uQxvhMWvjN oe8yA6GOev1LXrLwPV8dVP2EueVSKjHRkCF3U= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition; bh=t1mUlJFBauJJoQI/4DdFu/qGHWg9ioYSq6sgs7YFWqs=; b=ir4oslWtaCPcH5kfvPFGXaXbMMLf0k5fVvDmVdhhNKoaz0SX1RWjSS4vfHQ2F8xRvX 4QHOEB4Yh+Ht9SGWpoPVnHKVxEf8UJsjT1R6US57LhYiBQ3a7KDPpF4jXkekh+192ODw JGXllDdjcaZ4VKyrg810vM0fgEVLgm8WaEZ4X8qJOFVgh36XVfucLRTxtpciD8eoMiaT 0LxWsJQsnG+FEMRcTlH+/tgg5/do7PnNVePhJi0ZlS9GsdrCYp7bInNPr++CkgeDOs3B oMpENnPaLS8hnxDp3Ldp0VnZ4B/K7raBn0sbgoPj9fV3vaOpdALVZ18eRJIBlhgQEPPB 7pcQ== X-Gm-Message-State: AGi0Puax/4zUJvOSv3J4VOxQ6zJk0/ZiVgJD5MKkqeSU+/p7eBYzNMM1 eki6As4Ow/yiN/HYkOG+AhaXW4qvRd0= X-Received: by 2002:a5d:6785:: with SMTP id v5mr12435117wru.376.1587289482742; Sun, 19 Apr 2020 02:44:42 -0700 (PDT) Received: from carbon ([94.26.108.4]) by smtp.gmail.com with ESMTPSA id h13sm27678202wrs.22.2020.04.19.02.44.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Apr 2020 02:44:42 -0700 (PDT) Date: Sun, 19 Apr 2020 12:44:39 +0300 From: Petko Manolov To: "Paul E . McKenney" Cc: LKML Subject: [RFC] WRITE_ONCE_INC() and friends Message-ID: <20200419094439.GA32841@carbon> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Paul, Recently I started reading up on KCSAN and at some point I ran into stuff like: WRITE_ONCE(ssp->srcu_lock_nesting[idx], ssp->srcu_lock_nesting[idx] + 1); WRITE_ONCE(p->mm->numa_scan_seq, READ_ONCE(p->mm->numa_scan_seq) + 1); Some of these are a bit eye-watering for me and could easily be converted to: WRITE_ONCE_INC(ssp->srcu_lock_nesting[idx]); WRITE_ONCE_INC(p->mm->numa_scan_seq); where the above macro could be either: #define WRITE_ONCE_INC(x) WRITE_ONCE(x, READ_ONCE(x) + 1) or the more relaxed version: #define WRITE_ONCE_INC(x) WRITE_ONCE(x, x + 1) I personally like the stronger version better as a) it doesn't seem to increase code size (relative to the relaxed one), and b) should be less prone to load tearing, etc. Given the growing popularity of KCSAN I expect a lot of concurrent code soon will get the READ_ONCE/WRITE_ONCE conversion. If you think the above makes sense we could also do this: #define WRITE_ONCE_DEC(x) WRITE_ONCE(x, READ_ONCE(x) - 1) #define WRITE_ONCE_ADD(x, v) WRITE_ONCE(x, READ_ONCE(x) + v) #define WRITE_ONCE_SUB(x, v) WRITE_ONCE(x, READ_ONCE(x) - v) cheers, Petko