Received: by 2002:ac0:e34a:0:0:0:0:0 with SMTP id g10csp633178imn; Thu, 28 Jul 2022 11:03:10 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uBvOh/9M7WzVgGhnPglc80gLhoUb8K+ZpCGuSS58jxfrhJ6M9W+MAahx53SJc09//6WgBS X-Received: by 2002:a17:907:d26:b0:72b:8311:a167 with SMTP id gn38-20020a1709070d2600b0072b8311a167mr86009ejc.89.1659031390513; Thu, 28 Jul 2022 11:03:10 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1659031390; cv=pass; d=google.com; s=arc-20160816; b=c48k8YbgxMVxIuL+rxBxwAF7cO5NZcLEl/1El2iTyAgQt/0CP5O/K8WvZtbSAReNZr Q2qz3Gfanzxh46ToGQntgQ5JRCu3BX60j9sPI6Okt7bPTqyw5KtPn/HQW7epgNGJdgYl Uoldt7ZP5iF/FR7GlT0FUPQy7UjoQaZeXbu6xE9hsShlxAPDKATlD6u5OgNdsafYhMrX 8oX/3/AzgY1IjwuRAEaE1m5Mbtd+z0zxDBBcAzHBXWgt5eJDzef45vURcLIse3nz7Mid 1AzB5GhmN5CEx790VIWEkEh0tk/hwPirWakl+uMt8bLK9K/WtGaJ11sOXQwzTdwLnXdU 7W8w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :in-reply-to:from:references:cc:to:content-language:subject :user-agent:date:message-id:dkim-signature; bh=Z7wA359+j2HQLoqdTLxzv+GEWrJNiRQ4gdTiQTCCWXc=; b=on+BliplPNVIbWKK5V/OWU35Fcltw8cECcKfLVPzEGI6ORttCGxtMhPLnk/Y7rniES TSdHdjaZNF9dxjGIwfXH3yqTAkQcQbCTmhdrfa1ffXxORTOAlnFd2VyqSQK1rnp88WRz 0fYJ1oW+lxNsD+ydTcytCObZ/Q2zi9K7xoYcCHe09VH9GKR7x/bFXjd63APnyniGvvyJ 6xXwq87PEg0ckF1aDeIjfXUUSrxU50Q47twM936qX5rL3HWmUt5HGeq/4sgfJy7O3sd7 jbNSeEny0jEqLi1V0OkhEP0ljPm8f6SiQQLNZSVTQqrVflGkx/NvC+tkPgWko/c6EJ4S 3TOA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kunbus.com header.s=selector1 header.b=VkToFfd6; arc=pass (i=1 spf=pass spfdomain=kunbus.com dkim=pass dkdomain=kunbus.com dmarc=pass fromdomain=kunbus.com); 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=kunbus.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ep3-20020a1709069b4300b0072ac7db91e6si1022439ejc.610.2022.07.28.11.02.45; Thu, 28 Jul 2022 11:03:10 -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=@kunbus.com header.s=selector1 header.b=VkToFfd6; arc=pass (i=1 spf=pass spfdomain=kunbus.com dkim=pass dkdomain=kunbus.com dmarc=pass fromdomain=kunbus.com); 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=kunbus.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229556AbiG1Rga (ORCPT + 99 others); Thu, 28 Jul 2022 13:36:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45526 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229812AbiG1Rg1 (ORCPT ); Thu, 28 Jul 2022 13:36:27 -0400 Received: from EUR01-HE1-obe.outbound.protection.outlook.com (mail-eopbgr130050.outbound.protection.outlook.com [40.107.13.50]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 150C27390C; Thu, 28 Jul 2022 10:36:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MoS6Iqenge9tctIhqikN5c18DUWfOemlopMOkhZvhwUD+lLwX2p19SssC3e+u/EU3hY1TZrzCltXhFfhjt8xC4m0c19GaAgthsLcuozudU9ep1uOrEMQ1eJPqCIFaQaFifSfdhM67+DvyLSngiQuh8qWpjHMaE7xWkIOvRMecA7SSHkFJJXE7TgMJOhFfsGwJB/Wl7LDRu5KHHWfslziPHvYKPexix+YFEgg3Uu2KQiNsxnYM/AkfLl7wXQ9veKDuwUBIe3IKB7+aOYK45RgNm3B2nT6d7k4q4+lWP7DlqPWSt2u9+dpRRoOfGged9/mZ6PtSQBPZq3kXXnRSge7GQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Z7wA359+j2HQLoqdTLxzv+GEWrJNiRQ4gdTiQTCCWXc=; b=ff3gkk2iXiUD4iB1Qcvw0JoN5xYmLnyHu8cetmo+ssoHE0esAXt9JJJkGFLNr8zXKuu2pAzOaXsEtGuxczkOc5x5dYgKmov7SMJ3LAMRd5DfzXA2wu70KkPnnO/Nkw4wwSfPWhndQraVBXEFLc0Ntr7Z2L5aHZks44fBEszuDBLhBURpwHeoNFOisGxq1B947orPLOdna2b6Pldn7ZYofo0Id+OkDg5R96Uu20YTNvZJ1A1rWJM9TNQoG8v/QEYZV+ILlbr0H7/inywJcopIzBGEU/JkAEZyxLkFL0qMPbxYVG+OECkS2rrw+5ztBO22NJwEDhJpxenXn9lYmx9CMg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=kunbus.com; dmarc=pass action=none header.from=kunbus.com; dkim=pass header.d=kunbus.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kunbus.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Z7wA359+j2HQLoqdTLxzv+GEWrJNiRQ4gdTiQTCCWXc=; b=VkToFfd6V35UaBVIPG8JKji+BbAjojtIDhViE59htd/PIKL4FRrlRBOZhtwoILCqcsvmOO8FNb5Wzsa4RtDJChXzdSbG5EM3QdM2W59/vIKj4qgQMWNBwoxJ+1/u9rE1gvTnjSWUA/kmGv8wbaSZrgXQlQ7/avmXWxVo0BrTZr8= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=kunbus.com; Received: from VI1P193MB0413.EURP193.PROD.OUTLOOK.COM (2603:10a6:803:4e::14) by PAXP193MB1471.EURP193.PROD.OUTLOOK.COM (2603:10a6:102:136::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5458.19; Thu, 28 Jul 2022 17:36:23 +0000 Received: from VI1P193MB0413.EURP193.PROD.OUTLOOK.COM ([fe80::10dc:b784:6939:db99]) by VI1P193MB0413.EURP193.PROD.OUTLOOK.COM ([fe80::10dc:b784:6939:db99%6]) with mapi id 15.20.5458.025; Thu, 28 Jul 2022 17:36:23 +0000 Message-ID: <570976c3-8292-092d-5e0c-25eef63f7f3c@kunbus.com> Date: Thu, 28 Jul 2022 19:36:19 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: Re: [PATCH v7 07/10] tmp, tmp_tis: Implement usage counter for locality Content-Language: en-US To: Lino Sanfilippo , Jarkko Sakkinen 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, lukas@wunner.de, p.rosenberger@kunbus.com References: <20220629232653.1306735-1-LinoSanfilippo@gmx.de> <20220629232653.1306735-8-LinoSanfilippo@gmx.de> From: Lino Sanfilippo In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-ClientProxiedBy: FR3P281CA0140.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:95::12) To VI1P193MB0413.EURP193.PROD.OUTLOOK.COM (2603:10a6:803:4e::14) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: faeea984-fba7-44f9-ade3-08da70bfb08c X-MS-TrafficTypeDiagnostic: PAXP193MB1471:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: hK2XTCG/RM8pKdEdCskbwpxMnRu9fnUnVh+vU+e7Z3qqcukF/sPR8UYg5m3lYeWAjXJ8q+Yns7DN7o7DRtqQ2yt0aYDN89XGzSthX6/c8lRrdjgPnhjUA1PaVKabfBbnikLlXemE4XpvDI2RiGf6Q5iP+nqeElp+wdxYfWL5NSuYk+sFUtdDkRGplO6DbOpRAT+PsX2Q7l0xzTxwe5BguEzjZXMn1DYZ81vEDaQ2Irqf/lakIS8gLfuWMtqULOCLlORcKoMRSg57e1yMwu9t4edvOaRqxOkpQOCU63svMkKydBwFwkqGpNUaJuJYEDRIoB6tBTixFsO4SCA4alXQD58SgJxK9AU7yRKY6M0ElOXOZH3L/u64BMQ2DaXE9HR5+oBK1wa6HlXE7OmlKGRKbZNpJZ/mE38CcyqpWcx2up+iEYPapREtZPfsBcwWFkOMvSjm5y0JaoqXjCskIUABtmbZGqrPBII4WDCAEVkC+83bHxDd+sV6L97mYPXYBZT7bFEkncLlw6sHLX1NT3l3PzxxX1LMKOy3TWcrr6uyqFFkSvCFEwR/1jG53thA3PfkmQJ6siuP6GXxI9+6S9WqdHBwQfU8VbGtRUgeytPbcvLQurZeBRxxOWgtDdeyaCtNegDMAhT2C1F6NQ40qhek4vgY//mQ8qtPxxJ5Rj1uDPTi13jue6K7oWlPu1k5MrR91yc0lL29fJJXGx5bH8li1lwW6R09//RUbcCsGXZcmJdF3n6hcKwNeRTnA2Myxhd2s5n/d//gdZ4tlVzb9nLrzv1FT7Ww/MGfE78IJW4bFiyLnZHyqzZDaE9Kioa+f5eqZnpZvhD3PYBAYnBmJhDARPx54+LnI8y7JDMZyJe0q8E= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VI1P193MB0413.EURP193.PROD.OUTLOOK.COM;PTR:;CAT:NONE;SFS:(13230016)(4636009)(39840400004)(136003)(376002)(346002)(366004)(396003)(316002)(66946007)(83380400001)(31686004)(36756003)(38100700002)(107886003)(186003)(110136005)(53546011)(6506007)(31696002)(2906002)(66476007)(38350700002)(86362001)(8676002)(6512007)(52116002)(6486002)(2616005)(8936002)(4326008)(5660300002)(478600001)(66556008)(26005)(41300700001)(6666004)(43740500002)(45980500001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?Nkh0b0xlVWlTalFUdEpaTDJaRW1NK21GS1g4MjJkdmlnN0FwVmh2QkdDR3c2?= =?utf-8?B?RmtTN0U4U3Z6WE5yb3UvelNmcEpYc3JZZlJGcFY3THFnRU9Sb3ZWVkRHTzJV?= =?utf-8?B?eEViM3pzaVdOOG12bWZWQ0pnMTZUNUloSWczVEF0b3Z3b05NNVREdUF5NHJn?= =?utf-8?B?QUxRQzBKOUdWL0lsUU5BSXU4UmNiaUNsWEtXSytCWFJQYlhLODRxU2Y0c1pu?= =?utf-8?B?YUF3a1QzNTB3b2FRcTlITE1rTXZjQm4vTlo2WGtMU1FocFR5NHBzMThwck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FNFTW5VcVNvTUNDY3Yvd1REMDlWUlFveTlpbE5nMWdZ?= =?utf-8?B?ZEVUb2haRC94YmhIQmhaSEozVnc1R2ZuL0paZnJ6UnVHR3k4OUZDU0Q2Z29K?= =?utf-8?B?RkE9PQ==?= X-OriginatorOrg: kunbus.com X-MS-Exchange-CrossTenant-Network-Message-Id: faeea984-fba7-44f9-ade3-08da70bfb08c X-MS-Exchange-CrossTenant-AuthSource: VI1P193MB0413.EURP193.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Jul 2022 17:36:23.0826 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: aaa4d814-e659-4b0a-9698-1c671f11520b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: /rT86NylAdSPQmtQDADp42UL59YwbUVblyTXDJ//TeM2vrtTUb7hbk0Q8MUB9GeBdUo7oRmwd6lqnuM6KnyWNQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAXP193MB1471 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,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 04.07.22 19:45, Lino Sanfilippo wrote: > > > On 01.07.22 01:29, Jarkko Sakkinen wrote: > >> >> I'm kind of thinking that should tpm_tis_data have a lock for its >> contents? > > Most of the tpm_tis_data structure elements are set once during init and > then never changed but only read. So no need for locking for these. The > exceptions I see are > > - flags > - locality_count > - locality > > > whereby "flags" is accessed by atomic bit manipulating functions and thus > does not need extra locking. "locality_count" is protected by the locality_count_mutex. > "locality" is only set in check_locality() which is called from tpm_tis_request_locality_locked() > which holds the locality_count_mutex. So check_locality() is also protected by the locality_count_mutex > (which for this reason should probably rather be called locality_mutex since it protects both the "locality_count" > and the "locality" variable). > > There is one other place check_locality() is called from, namely the interrupt handler. This is also the only > place in which "locality" could be assigned another value than 0 (aka the default). In this case there > is no lock, so this could indeed by racy. > > The solution I see for this is: > 1. remove the entire loop that checks for the current locality, i.e. this code: > > if (interrupt & TPM_INTF_LOCALITY_CHANGE_INT) > for (i = 0; i < 5; i++) > if (check_locality(chip, i)) > break; > > So we avoid "locality" from being changed to something that is not the default. > > I wonder if we need tpm_tis_data->locality at all: the claimed locality is already tracked in chip->locality and in TPM TIS we never use anything else than locality 0 so it never changes. Is there any good reason not to remove it? Regards, Lino