Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3297132pxk; Mon, 28 Sep 2020 13:36:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxNW+Cm1mmWEsltW7pXZYyp05x8cK6g2Aj8XkhQ+xyl5WVplQzbdYn79S1Ya7MM+PqnyvY9 X-Received: by 2002:a05:6402:7d2:: with SMTP id u18mr3891988edy.69.1601325384779; Mon, 28 Sep 2020 13:36:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601325384; cv=none; d=google.com; s=arc-20160816; b=MwMZkvmrMZ0+KDdZoCWiO+SyaBw7LDoLwBrkRWriWYpp8TwQvMKYtrM/lDb8H2hjkR VE22+Vq2a7jmxgVvpWR1gOs+EqncyTDVFANAXHT2sC3MCX0rmqdoRR1w07Td6BVXN9Mf nRAPyhNI3xVKSW6RQsenefRV9ssW/rxrIy0+a6PEaVJZABVXwJbW0qJC7UQ0VGflo5RU QusyaNS8naGv/4vUWLrXWLLcfSCgM7P0VAnJShVAp0YjIxKbv6zb4IKdkmXP08KeKOg9 wMHYEJ28slWNdTe3ZsPVBqdpqhz3PlfLSEag3CcWxd+8PqvmN+mLfqiaqh5R++50Vsu1 KL7g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=fSqGGre3K5gDxqZQhBBAgkB/XW4ArHnxdL9/PVe8UEw=; b=HjXvpgk7nvcrw9grrJN02hjtYpJlJAeGlqqXoLGOErd6s6SHTn1mP/kjY6EkyBo8CL BjNnoDP+kl0l1x1yMjz4cBo95N5o/sv781y82GO9x0MjrbwAMT8sQkXVdAr0m/2l+/f0 QzNn1/7wijc00Qn5cXSZ3NptYT7jioRSjmMBQOfqVuF9q6sIgLkouyorATHDjzS69Kk2 pMBgcjOSkRpm/4FEUuHXnKBjwVMiwacKBuVwTpqnJmd1Zm104nQFiCJ0orFTHrVxQe0X iWtIwmwAlbk/5wLtHsfJ9YdBdCDisvIJ8CQjby/mmacYK3/nH8TlKJnj2xhqRM8+wyRF fx5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=NhEgCMqv; 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=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a4si1599782edq.101.2020.09.28.13.36.01; Mon, 28 Sep 2020 13:36:24 -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=@chromium.org header.s=google header.b=NhEgCMqv; 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=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726830AbgI1Uee (ORCPT + 99 others); Mon, 28 Sep 2020 16:34:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40056 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726607AbgI1Uee (ORCPT ); Mon, 28 Sep 2020 16:34:34 -0400 Received: from mail-pf1-x441.google.com (mail-pf1-x441.google.com [IPv6:2607:f8b0:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3D958C061755 for ; Mon, 28 Sep 2020 13:34:34 -0700 (PDT) Received: by mail-pf1-x441.google.com with SMTP id z19so2212885pfn.8 for ; Mon, 28 Sep 2020 13:34:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=fSqGGre3K5gDxqZQhBBAgkB/XW4ArHnxdL9/PVe8UEw=; b=NhEgCMqvIk+RvaHqH61RFdho/oyavhy1mnawXx73Z32KtMmWrdQ3TF3Wdl5xGJWAF4 HJ7MvCec9xWmOfe2vmH4pRHVPw4F2RLEFJS+4IHA6SOXqWq1vixOup+3/VsF76zS/3fH NNK2l+sjcwTbNoDengDe+AnKeGhAQtj5ceh68= 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:references :mime-version:content-disposition:in-reply-to; bh=fSqGGre3K5gDxqZQhBBAgkB/XW4ArHnxdL9/PVe8UEw=; b=EnhDGc3zFdut3pXghCtY8vqRdtMgYeP98HDGJOQQ5fQy1qO7x1DvSuPJl7Cy6xnmYU gnsG4DV3snV6nOQnGQOS2TSpkHl7oXSprHkXHLIxX5UU4Ldt6juz+kRpUORAZkk0UnRq 347sqzw9hIBZELxPZsns5p7FplRN6IiqdWZKqbVpVq++JtKuTegqDA93J8j1CJ5EZpH7 U95mzazhW73mBnldsVqeX4LqUsQ7fMeEaTG24BLDDpFHDS1cUMym7Z2rhsL0xlVqok1v hieCgqZ1c8OuxsDQN42P5kwHvGPCcy+FkJ6tp/UG0fhit7N5FtzrU8jSIxscwfOIqLCs jNsw== X-Gm-Message-State: AOAM530JMoJtIL1OsWwqkNgDrWs/ZXm/OEn3LjoLNuPx9cB2aE6G7Whs FkMkyo7+qaLuLjomSnwx7emwEA== X-Received: by 2002:a17:902:7589:b029:d2:686a:4ede with SMTP id j9-20020a1709027589b02900d2686a4edemr1142882pll.45.1601325273788; Mon, 28 Sep 2020 13:34:33 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id t14sm2209702pgm.42.2020.09.28.13.34.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Sep 2020 13:34:32 -0700 (PDT) Date: Mon, 28 Sep 2020 13:34:31 -0700 From: Kees Cook To: Joel Fernandes Cc: Shuah Khan , corbet@lwn.net, gregkh@linuxfoundation.org, shuah@kernel.org, rafael@kernel.org, johannes@sipsolutions.net, lenb@kernel.org, james.morse@arm.com, tony.luck@intel.com, bp@alien8.de, arve@android.com, tkjos@android.com, maco@android.com, christian@brauner.io, hridya@google.com, surenb@google.com, minyard@acm.org, arnd@arndb.de, mchehab@kernel.org, rric@kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-acpi@vger.kernel.org, devel@driverdev.osuosl.org, openipmi-developer@lists.sourceforge.net, linux-edac@vger.kernel.org Subject: Re: [PATCH 00/11] Introduce Simple atomic and non-atomic counters Message-ID: <202009281331.444F36A7B@keescook> References: <20200927233526.GA500818@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200927233526.GA500818@google.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Sep 27, 2020 at 07:35:26PM -0400, Joel Fernandes wrote: > On Fri, Sep 25, 2020 at 05:47:14PM -0600, Shuah Khan wrote: > > This patch series is a result of discussion at the refcount_t BOF > > the Linux Plumbers Conference. In this discussion, we identified > > a need for looking closely and investigating atomic_t usages in > > the kernel when it is used strictly as a counter without it > > controlling object lifetimes and state changes. > > > > There are a number of atomic_t usages in the kernel where atomic_t api > > is used strictly for counting and not for managing object lifetime. In > > some cases, atomic_t might not even be needed. > > > > The purpose of these counters is twofold: 1. clearly differentiate > > atomic_t counters from atomic_t usages that guard object lifetimes, > > hence prone to overflow and underflow errors. It allows tools that scan > > for underflow and overflow on atomic_t usages to detect overflow and > > underflows to scan just the cases that are prone to errors. 2. provides > > non-atomic counters for cases where atomic isn't necessary. > > Nice series :) > > It appears there is no user of counter_simple in this series other than the > selftest. Would you be planning to add any conversions in the series itself, > for illustration of use? Sorry if I missed a usage. > > Also how do we guard against atomicity of counter_simple RMW operations? Is > the implication that it should be guarded using other synchronization to > prevent lost-update problem? > > Some more comments: > > 1. atomic RMW operations that have a return value are fully ordered. Would > you be adding support to counter_simple for such ordering as well, for > consistency? No -- there is no atomicity guarantee for counter_simple. I would prefer counter_simple not exist at all, specifically for this reason. > 2. I felt counter_atomic and counter_atomic64 would be nice equivalents to > the atomic and atomic64 naming currently used (i.e. dropping the '32'). > However that is just my opinion and I am ok with either naming. I had asked that they be size-named to avoid any confusion (i.e. we're making a new API). -- Kees Cook