From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5F3F8C67871 for ; Tue, 25 Oct 2022 01:13:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229871AbiJYBNr (ORCPT ); Mon, 24 Oct 2022 21:13:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36482 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231472AbiJYBN2 (ORCPT ); Mon, 24 Oct 2022 21:13:28 -0400 Received: from mout.gmx.net (mout.gmx.net [212.227.17.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9EE5E1C843C; Mon, 24 Oct 2022 17:25:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1666657540; bh=2a8mkpddzspnTrIRyjDTVLJRXQkyLPiHPxjXNUgcIig=; h=X-UI-Sender-Class:Date:Subject:To:Cc:References:From:In-Reply-To; b=Nn03TyqkZwxFAMRG2uTBWXVv9Lo33w+f6OjH+DOOW7PbqgoI2aSAt5l88bd7of7vQ uQ1WS3tHByaOWgl2LfBz/m+qGoMzQeeAh2HF+0hw8bLJbMoAraw4YM5d/qOzNUeYQ2 YgAEIonfljkyBRRmGfUww/GEECCHNl10IQqeQ1pU= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from [192.168.2.83] ([84.162.5.241]) by mail.gmx.net (mrgmx105 [212.227.17.168]) with ESMTPSA (Nemesis) id 1N4zAy-1pCahs2HuW-010vAv; Tue, 25 Oct 2022 02:25:40 +0200 Message-ID: <0094438d-cf8e-da81-c969-119f90baf3db@gmx.de> Date: Tue, 25 Oct 2022 02:25:39 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.2.2 Subject: Re: [PATCH v8 08/11] tpm, tpm: Implement usage counter for locality Content-Language: en-US To: Jarkko Sakkinen , Lukas Wunner Cc: 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 References: <20221017235732.10145-1-LinoSanfilippo@gmx.de> <20221017235732.10145-9-LinoSanfilippo@gmx.de> <20221018062508.GB25237@wunner.de> From: Lino Sanfilippo In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:qQ4IHt/U6ocipV4Dxu3NbTQMjffawFWFuuca3MhFEIpycsYmc8Y cBPU2xrVt1CrHtsHZQrz1DU7c/i50Ws+CIWbDPRIoDfbnaI1BBvOCbRjH57FIgIGp6SlGDS 80i4PNh4fCqNam+R9rZAZnZzpVzAYXxbm/URStLrytAZNdM/VdjfALkYaAzIVFC/S+GH4PO Bw+aBKllTYCBUcHT+NAkA== X-UI-Out-Filterresults: notjunk:1;V03:K0:RYCmhr6w+Nk=:dj9Ek1J0oIBVP5T8p2S9Pi TkWcgj22dK+QSwLUD8/d+L92rXf2Lr3JPQNnm5Rxkx8kjhpuUdBoynxV89KhCLmP4PVDLPvyo XnoXj4c/quQHwz6+0HEsmmqHgJt3E2ZY5pUCEfJTEz1F1qylIikCPInY4LmhWz/r9P+XECBW2 BsmxoTpKPm+YGRCtWinBJkU/HRiP1vyKiPwGLNFoRdet7M7lHQ7d5JNOE80YFBFANYP5D1Sje STdI70JaWowqRganf9RogSHWfBig8ZbR4N3AV2ZOpdQKCyPAp4qNu/kxk7vcxjLrfp5mXdNq+ JRHlWzNRYwYKKlBoTHMR/Q61lyQR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e4cdbb8GeDOU TnRXymWPOiqUnlEXvMuv+OXbk4blqTxPSmgRXulvsOg9f+/zmPCx6k226OlMwXLNh44awE2yE 8poAZSoeO+dhZT3NqxknLC3dgpR5DGF1t5JAS2k6fgdiiEL8os3Y8kngDTcC03WDp/IfJFWoE sdtKH0xiaZR5pvwbxE/qWmr9s2EhHJXVUanpC6VQ83VnD Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 23.10.22 07:26, Jarkko Sakkinen wrote: > 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 T= IS >>> driver: >>> Request the locality from the TPM if it has not been claimed yet, othe= rwise >>> only increment the counter. Also release the locality if the counter i= s 0 >>> otherwise only decrement the counter. Ensure thread-safety by protecti= ng >>> 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 wit= h >>> each other. >> [...] >>> +static int tpm_tis_release_locality(struct tpm_chip *chip, int l) >>> { >>> struct tpm_tis_data *priv =3D 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 =3D=3D 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. > I actually tried to implement this via kref but then came to the conclusion it is rather not a good choice for our case. Please see my response to your former request to implement this via kref: https://lore.kernel.org/all/09eefdab-f677-864a-99f7-869d7a8744c2@gmx.de/ Regards, Lino