Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp5060180rwi; Sat, 22 Oct 2022 22:45:35 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7/L1qWZ9FHsF+udu2ps+8R7nL18TU0adO9XsAoblODcEVVLZHlh1ytPHkTP6OQ+xMww8cA X-Received: by 2002:a17:902:ec83:b0:185:581a:1c with SMTP id x3-20020a170902ec8300b00185581a001cmr26742163plg.78.1666503925486; Sat, 22 Oct 2022 22:45:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666503925; cv=none; d=google.com; s=arc-20160816; b=oF7mYUbBzq3Ovph3B0z3evwgVH/fh1h8tBWxmZAl6Wt5jaYZJPMYKDasgovq90tr54 vvpW8YYTmxEouXec8xOSZfY8m+hdI3t3S58jFySxs0qPF7lTSbAQvcWuJyrzUDThifbk 6OCjz1w3GVPXM+Bm5ryp/oUDby45P77HKDrmuTH1ve1Kip+ufiuduxpM+EIgvqWUqiDa SuEE4Pb4hKmtBmr1Fr2NPnFCyBQfBeHH2KgfwamBzSIKVoNW/rgUD99psQkACLrq6iIV HijIUFi4XnwLd8I7eHHgJhLlWO7B3RqsoP3GrFFw3/EmFJfZRsuu6qekfVaLahHLJDsW cAvw== 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=7att1dpIgUOiu3VS8Sl+AmqXA1rm47+jIoG5BJHSGgE=; b=X44wXc55hnkZJc3tQ35DElEmKuezh4qA5I9jITSxkHgl2xiPiFs6ug9GTykdLneQu0 +YDkyTNapryAKyR4YCEsbToiMRbirvAf8Q1FSTCtWhDHypv0os02ZK4eOGcoMyHv3apn aE3d5bRmR9IBL3ESg2TMhQ2T38P1LnBWcf7U2RYQ1DgTgi3HKbrL8vM2cyKTYPwSibLk LSMuEXRL4jA4T8SlpkFOFL4UcvR8hfnlmWxyx8zz71Bk21RaOMebCHjsJhSpPxvB7ExW y9unCaLP2iVp8uZIF+vgsPvCBtTUFqk5/KCqajWutjDeEwO8tzFUHs1owtpH8ZaXGZ2h 8WuA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=niYHUErc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n5-20020a170903110500b001785307f3cfsi35425407plh.577.2022.10.22.22.45.09; Sat, 22 Oct 2022 22:45:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=niYHUErc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229781AbiJWF0m (ORCPT + 99 others); Sun, 23 Oct 2022 01:26:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36620 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229515AbiJWF0k (ORCPT ); Sun, 23 Oct 2022 01:26:40 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5C6296EF2D; Sat, 22 Oct 2022 22:26:40 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 02AAF60B14; Sun, 23 Oct 2022 05:26:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 10A9EC433D6; Sun, 23 Oct 2022 05:26:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1666502799; bh=YyQMDEejPGZYx8p4Xq1tA0q8Sq/LtL9ohhkKWCtCGZs=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=niYHUErcTXTU8VApGnc69TE3T/wqJF75rT8BNf92v0LWoFNQ5EOcTBD1PoOJQs0t9 LXZgiKGYMUy9Xuime5eAhWoqGvGVs6oFQNLrtvgRtKPd9D9TpqvSt0hDm9oZF8yKa+ Bhehr4cYfJQXF6XumoagnylXYl1s9egNTA5vYAkA0EK1nweO9Q+tLQCIhrvNX2P+VY yINEMEoI1wLbqHhXHddUy5lqeOTaOn1VOV1G698hoEafKNP+eAaRZ7i6rtNkfeddBB OppzLJ5uthtW4OBuIOSCMNsF6d0OesaWMcNpQ3pDSwhPH0YTb06dHeOkidJZSC1t/5 kcGQ9zTA7xHsw== Date: Sun, 23 Oct 2022 08:26:32 +0300 From: Jarkko Sakkinen To: Lukas Wunner Cc: Lino Sanfilippo , peterhuewe@gmx.de, jgg@ziepe.ca, stefanb@linux.vnet.ibm.com, linux@mniewoehner.de, linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, jandryuk@gmail.com, pmenzel@molgen.mpg.de, l.sanfilippo@kunbus.com, p.rosenberger@kunbus.com Subject: Re: [PATCH v8 08/11] tpm, tpm: Implement usage counter for locality Message-ID: References: <20221017235732.10145-1-LinoSanfilippo@gmx.de> <20221017235732.10145-9-LinoSanfilippo@gmx.de> <20221018062508.GB25237@wunner.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221018062508.GB25237@wunner.de> X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Oct 18, 2022 at 08:25:08AM +0200, Lukas Wunner wrote: > On Tue, Oct 18, 2022 at 01:57:29AM +0200, Lino Sanfilippo wrote: > > Implement a usage counter for the (default) locality used by the TPM TIS > > driver: > > Request the locality from the TPM if it has not been claimed yet, otherwise > > only increment the counter. Also release the locality if the counter is 0 > > otherwise only decrement the counter. Ensure thread-safety by protecting > > the counter with a mutex. > > > > This allows to request and release the locality from a thread and the > > interrupt handler at the same time without the danger to interfere with > > each other. > [...] > > +static int tpm_tis_release_locality(struct tpm_chip *chip, int l) > > { > > struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev); > > > > - tpm_tis_write8(priv, TPM_ACCESS(l), TPM_ACCESS_ACTIVE_LOCALITY); > > + mutex_lock(&priv->locality_count_mutex); > > + priv->locality_count--; > > + if (priv->locality_count == 0) > > + tpm_tis_release_locality_locked(priv, l); > > + mutex_unlock(&priv->locality_count_mutex); > > > > return 0; > > } > > Hm, any reason not to use struct kref for the locality counter? > Provides correct memory ordering (no mutex needed) and allows for > calling a release function too upon reaching 0. I proposed for last version kref. I have no idea why this is still using mutex. And now I apparently have proposed rcu for the whole struct (forgot what I had put my feedback for earlier version). This keeps being confusing patch as the commit message does not really go to the bottom line why mutex is really the best possible choice here. BR, Jarkko