Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp1324227rdb; Mon, 19 Feb 2024 11:17:26 -0800 (PST) X-Forwarded-Encrypted: i=4; AJvYcCWZKhdsxqok3c+VBbzFz6QMIyGgHSbiE4xECdkXWPH7FDIiiA1LvPQlhNh7iSnhB5nKP2Md2LLM2JvybkxFBcaXymRLtE4KaQC42d9KZQ== X-Google-Smtp-Source: AGHT+IGbPIBG5DD8rCogwr50v2PH4V2ksqqK5c0kss75uY1myof3ia6SLNS4Vs51kBy0Jp/paclV X-Received: by 2002:a17:902:bd05:b0:1d5:6d76:997a with SMTP id p5-20020a170902bd0500b001d56d76997amr13282400pls.28.1708370245982; Mon, 19 Feb 2024 11:17:25 -0800 (PST) ARC-Seal: i=3; a=rsa-sha256; t=1708370245; cv=pass; d=google.com; s=arc-20160816; b=IhWR5NcHyTLtDV6ExacWf9P72OJxMNThHyH8Ej3o5tdmghu7vh0QtiRAWdu2OD7ruG a1csBZaTe8HfVe/+IeGigZVLeN8k/pbgp+Mgsl6sE+gPq3EEVjopSwRQ5jTweP/xeMC+ pyUFv5683iRNhh210F1wyDfvePKPaYt8M51iPW9EyNIthYWNm73Xf4gA9vm7rPFTYiCV ng4Z1Ws0Caq67R5WbNGlg9od31VuS7Mu/svJ+o313MPTNcYjQayMtGw9FnrXAgFRm6YZ rszYVt5asgAZ2C9WntcLBzyqCIPyut1jXVG8zLviay2Ka6R623H1fzwz8S+f7Gad745/ RdTg== ARC-Message-Signature: i=3; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:autocrypt:from:references:cc :to:content-language:subject:user-agent:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:date:message-id :dkim-signature; bh=+RfZps3cyaLzR9UeIkba7ZBflCqpBn2VxVNa1QfnSeE=; fh=Sjm8umqysapQcFhMRG6HIc2xZmduAf4emRfXg7F1idQ=; b=Q9QFo72FMFqMXtfQwWi/SXA0x4r1SGOv/E5QhJ/AYp/Ox9SNpblxDfiXwnpUCPY8ir WWoj60vfxh89Xn9/NgO5sZKROUYXvaYkKBLKDa+f3A/vf1RUWCnSjc8nbZWhU9tJIvrR 9V/KjZK1/1tYf1oqZfkCjcb1LgajLL2++q5oKUi96Hk/z790OWqm9jr5PecjZjhm0gFC hzb0Lo/l9yu46ft3AAcR3YOH+v9rXnvcAlmHIHO111NuKgmiFv8cHZxgVI+aBEaSteuZ f0B5lhkdtWcjjcYq7z8UQw80Lb6qt+enyvjcjVvjtT9E85Oc1Tx2P/svgZGEnkI6EHtc SlsQ==; dara=google.com ARC-Authentication-Results: i=3; mx.google.com; dkim=pass header.i=@apertussolutions.com header.s=zoho header.b=QG9iEtjd; arc=pass (i=2 spf=pass spfdomain=apertussolutions.com dkim=pass dkdomain=apertussolutions.com); spf=pass (google.com: domain of linux-kernel+bounces-71858-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-71858-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id q9-20020a17090311c900b001db9e68b35asi4753174plh.363.2024.02.19.11.17.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Feb 2024 11:17:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-71858-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@apertussolutions.com header.s=zoho header.b=QG9iEtjd; arc=pass (i=2 spf=pass spfdomain=apertussolutions.com dkim=pass dkdomain=apertussolutions.com); spf=pass (google.com: domain of linux-kernel+bounces-71858-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-71858-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 8AD9B282AC7 for ; Mon, 19 Feb 2024 19:17:25 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1E80650278; Mon, 19 Feb 2024 19:17:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=apertussolutions.com header.i=dpsmith@apertussolutions.com header.b="QG9iEtjd" Received: from sender3-of-o59.zoho.com (sender3-of-o59.zoho.com [136.143.184.59]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F2E0C47F7E; Mon, 19 Feb 2024 19:17:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=136.143.184.59 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708370234; cv=pass; b=gkZIetanvdNAffiI8Gb1RNtisARM2VIml2xkyb8/CEnSqYDMJUgcMre2qi7owojFVnuiVDD3jxBnrVsdpg3ir4Wck3LfLWvYqmMIJ4eTtyElgmPLRhcEsbsSkcdr1Csw5btNWwYQMrtITbUu4uKMdziNzhDDHT3Bmtm2sxcnocI= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708370234; c=relaxed/simple; bh=/NKpxGD4L7EZ3oebf7IN7JxEddgVhdF8nAb587/mLtg=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=N5VmtxtOKyCn6/O9PFKI0OPW1AnbA9lIoCkKR6decXnGF5+iQGoFW7+VSQZZZuyiYxZrfBbgm6M5ZhnF4QCP775QEotIcTJzfYbLA9f4ifW2G2+dbxVCiw6ZtKoQBUEnI/gu+eZ3NS9HRPZ5AbAj2nIFMZI2ENXxRvNA/cGCjAw= ARC-Authentication-Results:i=2; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=apertussolutions.com; spf=pass smtp.mailfrom=apertussolutions.com; dkim=pass (1024-bit key) header.d=apertussolutions.com header.i=dpsmith@apertussolutions.com header.b=QG9iEtjd; arc=pass smtp.client-ip=136.143.184.59 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=apertussolutions.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=apertussolutions.com ARC-Seal: i=1; a=rsa-sha256; t=1708370223; cv=none; d=zohomail.com; s=zohoarc; b=Ww1DrypyPmcYPD+U8LEKtS9w0mNW5PrTfCOJG7I877E4jZxn7jnXXWT2M7h/kcIaMm+4LrLqKwJgNS2U06gj2/WEBHnptVp1BI6V/RXiE7QDNkT+VNC0dfDyEHXv3oZ/Ya0jM0GZltpaFcjPp67ZEtAfnXkKLmjHYBoTEiVUL+s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1708370223; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To; bh=+RfZps3cyaLzR9UeIkba7ZBflCqpBn2VxVNa1QfnSeE=; b=EkY/vD6b6Pxq4Mw3++1cuf0Iog/XKnUwlXE+TaPPYseLVaNgCTFDJxjuSlsjsVjYcpuG2RaPajcbXstWrin5/IXn6oXHHqk6FWIPSg/b+4IyOy/0hRpjwKDgq2H3imp82CHBKdYykuYlSKVuJcrgTKrQPYEKzQVK5VMLSW2GQhY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=apertussolutions.com; spf=pass smtp.mailfrom=dpsmith@apertussolutions.com; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1708370223; s=zoho; d=apertussolutions.com; i=dpsmith@apertussolutions.com; h=Message-ID:Date:Date:MIME-Version:Subject:Subject:To:To:Cc:Cc:References:From:From:In-Reply-To:Content-Type:Content-Transfer-Encoding:Message-Id:Reply-To; bh=+RfZps3cyaLzR9UeIkba7ZBflCqpBn2VxVNa1QfnSeE=; b=QG9iEtjdxpLN7XM3isLANmCXuV/HvEnLyji5lW26/sbIdBC9dxbTqjhzBsiQJnto YAtvqn2ZnyaBcht3z3/R7s4g5YmSv6W11OQoQ4e5nc9nIzuRaAa2ahx9hNd5Byibm91 r9Cm/L0/AdvP2YhTjpGwYRc2w6bTT7GAERhbm/44= Received: from [10.10.1.138] (static-72-81-132-2.bltmmd.fios.verizon.net [72.81.132.2]) by mx.zohomail.com with SMTPS id 1708370222028706.4166130361724; Mon, 19 Feb 2024 11:17:02 -0800 (PST) Message-ID: <2dd76ebf-b25d-447f-8abe-30e3423c4cdb@apertussolutions.com> Date: Mon, 19 Feb 2024 14:17:00 -0500 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 2/3] tpm: ensure tpm is in known state at startup Content-Language: en-US To: Jarkko Sakkinen , Jason Gunthorpe , linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Ross Philipson , Peter Huewe References: <20240131170824.6183-1-dpsmith@apertussolutions.com> <20240131170824.6183-3-dpsmith@apertussolutions.com> From: "Daniel P. Smith" Autocrypt: addr=dpsmith@apertussolutions.com; keydata= xsJuBFYrueARCACPWL3r2bCSI6TrkIE/aRzj4ksFYPzLkJbWLZGBRlv7HQLvs6i/K4y/b4fs JDq5eL4e9BdfdnZm/b+K+Gweyc0Px2poDWwKVTFFRgxKWq9R7McwNnvuZ4nyXJBVn7PTEn/Z G7D08iZg94ZsnUdeXfgY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Q9AP94+xjtFfJ8gj5c7PVx06Zv9rcmFUqQspZ5wSEkvxOuQQEAg6qEsPYegI7iByLVzNEg 7B7fUG7pqWIfMqFwFghYhQzOwU0EViu54BAIAL6MXXNlrJ5tRUf+KMBtVz1LJQZRt/uxWrCb T06nZjnbp2UcceuYNbISOVHGXTzu38r55YzpkEA8eURQf+5hjtvlrOiHxvpD+Z6WcpV6rrMB kcAKWiZTQihW2HoGgVB3gwG9dCh+n0X5OzliAMiGK2a5iqnIZi3o0SeW6aME94bSkTkuj6/7 OmH9KAzK8UnlhfkoMg3tXW8L6/5CGn2VyrjbB/rcrbIR4mCQ+yCUlocuOjFCJhBd10AG1IcX OXUa/ux+/OAV9S5mkr5Fh3kQxYCTcTRt8RY7+of9RGBk10txi94dXiU2SjPbassvagvu/hEi twNHms8rpkSJIeeq0/cAAwUH/jV3tXpaYubwcL2tkk5ggL9Do+/Yo2WPzXmbp8vDiJPCvSJW rz2NrYkd/RoX+42DGqjfu8Y04F9XehN1zZAFmCDUqBMa4tEJ7kOT1FKJTqzNVcgeKNBGcT7q 27+wsqbAerM4A0X/F/ctjYcKwNtXck1Bmd/T8kiw2IgyeOC+cjyTOSwKJr2gCwZXGi5g+2V8 NhJ8n72ISPnOh5KCMoAJXmCF+SYaJ6hIIFARmnuessCIGw4ylCRIU/TiXK94soilx5aCqb1z ke943EIUts9CmFAHt8cNPYOPRd20pPu4VFNBuT4fv9Ys0iv0XGCEP+sos7/pgJ3gV3pCOric p15jV4PCYQQYEQgACQUCViu54AIbDAAKCRBTc6WbYpR8Khu7AP9NJrBUn94C/3PeNbtQlEGZ NV46Mx5HF0P27lH3sFpNrwD/dVdZ5PCnHQYBZ287ZxVfVr4Zuxjo5yJbRjT93Hl0vMY= In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-ZohoMailClient: External On 2/1/24 17:33, Jarkko Sakkinen wrote: > On Wed Jan 31, 2024 at 7:08 PM EET, Daniel P. Smith wrote: >> When tis core initializes, it assumes all localities are closed. There > ~~~~~~~~ > tpm_tis_core > >> are cases when this may not be the case. This commit addresses this by >> ensuring all localities are closed before initializing begins. > > Remove the last sentence and replace with this paragraph: > > "Address this by ensuring all the localities are closed in the beginning > of tpm_tis_core_init(). There are environments, like Intel TXT, which > may leave a locality open. Close all localities to start from a known > state." okay. > BTW, why we should motivated to take this patch anyway? Without this change, in this scenario the driver is unnecessarily thrashing the TPM with locality requests/relinquishes pairs for which will never take effect and that the TPM must do state change tracking. While I am confident that TPM chips are resilient to such abuse, I do not think it would be good form to knowingly allow such behavior to occur. > Since the patch is not marked as a bug fix the commit message must pitch > why it is important to care. As far as I am aware, the TPM driver has always made this assumption, so I guess it could be written as a bug against the first commit of the driver. The reality is that it is more the case that the TPM driver has never completely supported higher localities. While there has been logic to support localities interface, the driver has always been hard wired to use locality 0. Basically, this change makes the TPM driver function correctly when multiple localities are in use. I can write it up either way, just let me know. >> Signed-off-by: Daniel P. Smith >> Signed-off-by: Ross Philipson >> --- >> drivers/char/tpm/tpm_tis_core.c | 11 ++++++++++- >> include/linux/tpm.h | 6 ++++++ >> 2 files changed, 16 insertions(+), 1 deletion(-) >> >> diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c >> index 4176d3bd1f04..5709f87991d9 100644 >> --- a/drivers/char/tpm/tpm_tis_core.c >> +++ b/drivers/char/tpm/tpm_tis_core.c >> @@ -1109,7 +1109,7 @@ int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq, >> u32 intmask; >> u32 clkrun_val; >> u8 rid; >> - int rc, probe; >> + int rc, probe, i; >> struct tpm_chip *chip; >> >> chip = tpmm_chip_alloc(dev, &tpm_tis); >> @@ -1170,6 +1170,15 @@ int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq, >> goto out_err; >> } >> >> + /* >> + * There are environments, like Intel TXT, that may leave a TPM >> + * locality open. Close all localities to start from a known state. >> + */ >> + for (i = 0; i <= TPM_MAX_LOCALITY; i++) { >> + if (check_locality(chip, i)) >> + tpm_tis_relinquish_locality(chip, i); >> + } >> + >> /* Take control of the TPM's interrupt hardware and shut it off */ >> rc = tpm_tis_read32(priv, TPM_INT_ENABLE(priv->locality), &intmask); >> if (rc < 0) >> diff --git a/include/linux/tpm.h b/include/linux/tpm.h >> index 4ee9d13749ad..abe0d44d00ee 100644 >> --- a/include/linux/tpm.h >> +++ b/include/linux/tpm.h >> @@ -116,6 +116,12 @@ struct tpm_chip_seqops { >> const struct seq_operations *seqops; >> }; >> >> +/* >> + * The maximum locality (0 - 4) for a TPM, as defined in section 3.2 of the >> + * Client Platform Profile Specification. >> + */ >> +#define TPM_MAX_LOCALITY 4 >> + >> struct tpm_chip { >> struct device dev; >> struct device devs; > > Is there a dependency to 1/3? There is no direct dependency between these patches, but 1 and 2 are necessary to resolve the issue at hand while 3 corrects the return value behavior of the locality request function. v/r, dps