Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1921190pxk; Sat, 26 Sep 2020 09:34:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwhI1bpoaF0YTaYvJ7VC4gou7GqjMGmzB7gC6fUuJsIi5/fMz+twfF37MUV+ON31GgmZWmW X-Received: by 2002:a17:906:c0d0:: with SMTP id bn16mr8042841ejb.279.1601138074222; Sat, 26 Sep 2020 09:34:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601138074; cv=none; d=google.com; s=arc-20160816; b=vB70rs43orFAjZfVHUR7XRBw8B/3jXmq/rrzFnGLIpKaxmrC+1uGOtN4Hkg0EsykKc 7YiDP79Mvw1XugRMshXBcuPPnygnOKC6PRzBV8jnV2pl8RhjJgj12M85TXHQq1U/lCE+ xor29l9iiknbnpkDKonjKwrbGaf0887M4WPx1rNyEXmFT4LEw3nxMgKAwK2D2tjQPqCw o1s7D+2NQpr6RHOPEMW7GCJMuKc84b4q4mzFVImfIrb/BUELd2jihhLZn3mXA3d4m9SV BdmD4uRg64C2Y1sLmSc3Xy8uoMBI3cTa007CCV30ToG5E6te34bgcwQcpYzylzFO/sSz hD0w== 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=mvGz7fsSzQyG47W1/0kt8/LOxSWmeEYp8+sMo1z9HUE=; b=nQjdEcCPUhXVGMgJ6i1AyG73vBJdpzjI72qIrEyyuqwNarhiagxgiUDCRZgoRClyDx cN/8G9dKlRXBi/qYZMb7OIpJk/9OmYW1lHGk7zEwSVaIP0qeuc1TgReOUUVaWti3EFPL xwsQctpHkWyjveC7uZmFtOI4d7FkFBMp+tGT2lt0Dzo8gPvilRdPMPDu+5CP3OdfLZwp +LYA/K+lMMFN3eq+jUx3Ig6aRDlym/kGhpAXXP49LAuPA6z5RyR3y8zyPidoH5DUQ9rx 5JCDd0s+bloEYJ6b+ytjtGj+vI20XDp5UCIMZMVj+dNKdGp3BRkSJv3AdKKGMwYS2TEE 8z2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=j18SszrI; 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 dr13si3617980ejc.638.2020.09.26.09.34.11; Sat, 26 Sep 2020 09:34:34 -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=j18SszrI; 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 S1729291AbgIZQdU (ORCPT + 99 others); Sat, 26 Sep 2020 12:33:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41230 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728504AbgIZQdT (ORCPT ); Sat, 26 Sep 2020 12:33:19 -0400 Received: from mail-pl1-x641.google.com (mail-pl1-x641.google.com [IPv6:2607:f8b0:4864:20::641]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C7D6AC0613CE for ; Sat, 26 Sep 2020 09:33:19 -0700 (PDT) Received: by mail-pl1-x641.google.com with SMTP id bb1so1011362plb.2 for ; Sat, 26 Sep 2020 09:33:19 -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=mvGz7fsSzQyG47W1/0kt8/LOxSWmeEYp8+sMo1z9HUE=; b=j18SszrIGHglF5HogqSQsLrk58lP8fECmVsnU5yfOkqc1W0HCJU1XuoZWoSIGhCw8O 5BStnOqQow7SWPPTqSlIcqGVqAw/vVxjHtQ/Q1W5D+EbZaryvm/j2R/qcMgcPnAAXJ+P plaUHOPH8H18NjpTtFiQzfPWrswFQIWoggbK0= 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=mvGz7fsSzQyG47W1/0kt8/LOxSWmeEYp8+sMo1z9HUE=; b=UX9sy4xawJXPNnSYEpKdgbPZE/6Nx+SLQB+8anZnhUGEDWbfD6HhYHa/4vFJYcDV3Y 5FUB2Y9nA8s0enKXxwmN8pr+XsG8YGemvgPs4ll287vyztthtE+Ckx96K3xIthskJ2ep lzmWOp+OATTalNTGNwq/K8QCkM4CwReUsQfy8hFwqkgW1csuC7y67RTpGVXvHCvwge3E KtLd7qhVMqleZ0mp+0RhqUxL5eTOAl+auUQLniLJH5ie/5j3Iph33cvBSiz5Xtr0AQh9 Ybske59aWLDrO6JPVIchOCYovlzNlf9KZQxYqH9+IwhLY4t1L/rhP9NZIFT9LMC5wh2D lO0A== X-Gm-Message-State: AOAM530e0pVImacYT+54v7YN6oYSCtP1kHXhA4Xbz5V+U/kefYUx6+Fw 9x44cFYWKm6kyPprebyj+hNnxw== X-Received: by 2002:a17:90a:4b42:: with SMTP id o2mr2367400pjl.205.1601137999302; Sat, 26 Sep 2020 09:33:19 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id w14sm5767645pfu.87.2020.09.26.09.33.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 26 Sep 2020 09:33:18 -0700 (PDT) Date: Sat, 26 Sep 2020 09:33:17 -0700 From: Kees Cook To: Shuah Khan Cc: 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, joel@joelfernandes.org, 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: <202009260930.9252966D@keescook> References: <202009251650.193E2AD@keescook> <7d8f86ab-4333-afa1-6523-e42ae5c7d9b2@linuxfoundation.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <7d8f86ab-4333-afa1-6523-e42ae5c7d9b2@linuxfoundation.org> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Sep 25, 2020 at 06:13:37PM -0600, Shuah Khan wrote: > On 9/25/20 5:52 PM, Kees Cook wrote: > > On Fri, Sep 25, 2020 at 05:47:14PM -0600, Shuah Khan wrote: > > > -- Addressed Kees's comments: > > > 1. Non-atomic counters renamed to counter_simple32 and counter_simple64 > > > to clearly indicate size. > > > 2. Added warning for counter_simple* usage and it should be used only > > > when there is no need for atomicity. > > > 3. Renamed counter_atomic to counter_atomic32 to clearly indicate size. > > > 4. Renamed counter_atomic_long to counter_atomic64 and it now uses > > > atomic64_t ops and indicates size. > > > 5. Test updated for the API renames. > > > 6. Added helper functions for test results printing > > > 7. Verified that the test module compiles in kunit env. and test > > > module can be loaded to run the test. > > > > Thanks for all of this! > > > > > 8. Updated Documentation to reflect the intent to make the API > > > restricted so it can never be used to guard object lifetimes > > > and state management. I left _return ops for now, inc_return > > > is necessary for now as per the discussion we had on this topic. > > > > I still *really* do not want dec_return() to exist. That is asking for > > trouble. I'd prefer inc_return() not exist either, but I can live with > > it. ;) > > > > Thanks. I am equally concerned about adding anything that can be used to > guard object lifetimes. So I will make sure this set won't expand and > plan to remove dec_return() if we don't find any usages. I would like it much stronger than "if". dec_return() needs to be just dec() and read(). It will not be less efficient (since they're both inlines), but it _will_ create a case where the atomicity cannot be used for ref counting. My point is that anything that _requires_ dec_return() (or, frankly, inc_return()) is _not_ "just" a statistical counter. It may not be a refcounter, but it relies on the inc/dec atomicity for some reason beyond counting in once place and reporting it in another. -- Kees Cook