Received: by 2002:a05:7412:1e0b:b0:fc:a2b0:25d7 with SMTP id kr11csp111759rdb; Wed, 14 Feb 2024 14:39:37 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVqHAa+wtGCZ4COL0CxY77APagIwbxP+LKnG4twZKMn2Hdn/9lX+s39aWyiWn1htdPpf4ESCa2gJ7k2MiABroh5gB/XbwN+UYSS+ZIAAA== X-Google-Smtp-Source: AGHT+IG+VQxAN5CtnmDAfjr5y8hwZ52DQLF72P0wzcTm7jiM0vmVrqIPvEPw2aiDD1cD7bSfXPuC X-Received: by 2002:a05:6102:94b:b0:46e:caea:526c with SMTP id a11-20020a056102094b00b0046ecaea526cmr204797vsi.21.1707950377330; Wed, 14 Feb 2024 14:39:37 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707950377; cv=pass; d=google.com; s=arc-20160816; b=0UJn9gXk7N7XSA5ZCHLmfnxf7lzmvyai2XzRDNhaMKwqUIzvEJVgQBe7bk/YuNmTmE yc5zY3nOTSHRkPJFM84LWUXfaPSHuq8DxbNQUTyUIMkeSWbCtoW+gzP4RHCJuo2e/52S UN7bp3l3dwWhbI4bw4X0MQaScarZa67S8CtIUgTi02UYiM9sD0yzC/Hwgf38xMZTRSII ce63p5znvQQHUHunNi1AhT+fX6GOtlErd/CaxNzi9dSDExf6yeW0327Wg32dixNFZWLi NvljwM3IfeedyV47gWC3rQbVMEa0hYSQZE4szRpFD/PXymwwTsQCRkep6axM7cOrTuQb eCkg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=b4oJ7O5uXtHdoQDNZitFBZAfxacBiAtRwCnCravNnwU=; fh=BGd47bA3NgmVp9gOV7u6jqSIVOyzBJ/0H9W7KZFWLlw=; b=M5W9mB32vM3aJ18DwKfxA68IF7qZ3guxTgx9zekZqZ5Uty0j/eS94Un0B5guwXLqUq 6Iuso1GRqkzU+CMAvnfOnuad0+ZcqNqnDMT4K6ojvIC6VyAg1q2tFz7ZGi5oTXXdW0rR 3ypxXVXnC2kG+iJqtqHlBnQWnp3OXZRsbbDc0QzecyKfg6SUqAC3HY+UlF/gXqKojK1B 2lQzKXII8C/vn7i9mNZwwR+G/k2XK8qsn0l/6EDHR+uWBryJ5YKM3X8aerGrqeTl112W H/OGMGTO1ChHyAzYmMMAMrhI+5ugX9oPMr7jGmwK9ZfBQqjXKkspmggv34kvNQVtXzK+ Ph+A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2023-11-20 header.b=X95W3c9S; arc=pass (i=1 spf=pass spfdomain=oracle.com dkim=pass dkdomain=oracle.com dmarc=pass fromdomain=oracle.com); spf=pass (google.com: domain of linux-kernel+bounces-66066-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-66066-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com X-Forwarded-Encrypted: i=2; AJvYcCX6aNxqF6NEtI91XkIgpr09O3IROdZ67Ve2E5euWdcvJ1H+n8ZuMw7tCA71FMV7oRXscml9soEPDYYJrPdi3tkX/fr9Vifk8zisBs0c+w== Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id a10-20020a05622a02ca00b0042c69c92651si7097219qtx.723.2024.02.14.14.39.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Feb 2024 14:39:37 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-66066-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2023-11-20 header.b=X95W3c9S; arc=pass (i=1 spf=pass spfdomain=oracle.com dkim=pass dkdomain=oracle.com dmarc=pass fromdomain=oracle.com); spf=pass (google.com: domain of linux-kernel+bounces-66066-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-66066-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com 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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 0D5A71C22001 for ; Wed, 14 Feb 2024 22:39:37 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A50341474A4; Wed, 14 Feb 2024 22:36:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="X95W3c9S" Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) (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 EEE101468FD; Wed, 14 Feb 2024 22:36:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.165.32 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707950200; cv=none; b=rPIn+Q+1XD7HRPRXJLadoesOox7fiLHgCWyAb2cOZ/HSCh05qFTSg4J0kG3P0YBodNvAxnIw51n/mot+pyIWFkRzc1z3DGZDwOgBOrUjf2YnpOaeNdd0VvDRl2KhNkryFd4YJQD3OwyPRZD/XBlB8+6jNAVdrW2tziBIvJ17pd8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707950200; c=relaxed/simple; bh=8h3WjM/2k6NNW0IlEPjcYdWWKkzbtjALriacHK9e02k=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=NyVQ76OL7Ioxw4L8yIz7h6xXWAERnrUUnKt0XZK8hROPL5sGpnlBRsVi7lgxbU2HwH81cmPq7HLfLg8gNWVnpkeEn7hrPk0JkZMxdU49YcCjGOeBkIlqGoDLK9gkZs6priFzQ+xyNsNMJKBSGiTBHG+sEYFYm3ilZuDkVgsNz3Y= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=oracle.com; spf=pass smtp.mailfrom=oracle.com; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b=X95W3c9S; arc=none smtp.client-ip=205.220.165.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 41ELibl8028692; Wed, 14 Feb 2024 22:31:46 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=corp-2023-11-20; bh=b4oJ7O5uXtHdoQDNZitFBZAfxacBiAtRwCnCravNnwU=; b=X95W3c9SM1DlouEOCXta15LZI489m/283wE5mRGW5HADODGoiqwBtIHabYBMiLoJ6eTq 1mIFbMwol4ipetdqI6lWeLrrY/J1J6hKFI/Q7xbO5X6yzTPq1tRijPQHAD2vyClJAv0O b8J3WqyxoB2BdcHxIcfpmN5IuLBrvVoI4nGURUb0/s1wc3H1yzyRmDsr5fWjJYjRAPz3 ZisO/IvVUZ/EghzBz6br5af5LqWuKne9U6cJ2z5DTrWv4XhGj0n3tOHHxWHnricNutWN OS6RtpIxJwceBcY08PXwtJ44dKuCoyXnPZT8YizjDmArNCnIqvrBoYWchphWi9scAQxO bA== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3w91f00sry-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 14 Feb 2024 22:31:45 +0000 Received: from pps.filterd (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 41ELexle000607; Wed, 14 Feb 2024 22:31:44 GMT Received: from pps.reinject (localhost [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3w5yk9n7ew-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Wed, 14 Feb 2024 22:31:44 +0000 Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 41EMVTVI004281; Wed, 14 Feb 2024 22:31:43 GMT Received: from bur-virt-x6-2-100.us.oracle.com (bur-virt-x6-2-100.us.oracle.com [10.153.92.40]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3w5yk9n72r-13 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Wed, 14 Feb 2024 22:31:43 +0000 From: Ross Philipson To: linux-kernel@vger.kernel.org, x86@kernel.org, linux-integrity@vger.kernel.org, linux-doc@vger.kernel.org, linux-crypto@vger.kernel.org, kexec@lists.infradead.org, linux-efi@vger.kernel.org Cc: ross.philipson@oracle.com, dpsmith@apertussolutions.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, dave.hansen@linux.intel.com, ardb@kernel.org, mjg59@srcf.ucam.org, James.Bottomley@hansenpartnership.com, peterhuewe@gmx.de, jarkko@kernel.org, jgg@ziepe.ca, luto@amacapital.net, nivedita@alum.mit.edu, herbert@gondor.apana.org.au, davem@davemloft.net, kanth.ghatraju@oracle.com, trenchboot-devel@googlegroups.com Subject: [PATCH v8 12/15] tpm: Add ability to set the preferred locality the TPM chip uses Date: Wed, 14 Feb 2024 14:18:44 -0800 Message-Id: <20240214221847.2066632-13-ross.philipson@oracle.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20240214221847.2066632-1-ross.philipson@oracle.com> References: <20240214221847.2066632-1-ross.philipson@oracle.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-14_14,2024-02-14_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 phishscore=0 mlxscore=0 bulkscore=0 spamscore=0 malwarescore=0 adultscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2402140170 X-Proofpoint-ORIG-GUID: 6u0qho0pdR5oLqVesCM1T1HwwPG9_4kP X-Proofpoint-GUID: 6u0qho0pdR5oLqVesCM1T1HwwPG9_4kP Curently the locality is hard coded to 0 but for DRTM support, access is needed to localities 1 through 4. Signed-off-by: Ross Philipson --- drivers/char/tpm/tpm-chip.c | 24 +++++++++++++++++++++++- drivers/char/tpm/tpm-interface.c | 15 +++++++++++++++ drivers/char/tpm/tpm.h | 1 + include/linux/tpm.h | 10 ++++++++++ 4 files changed, 49 insertions(+), 1 deletion(-) diff --git a/drivers/char/tpm/tpm-chip.c b/drivers/char/tpm/tpm-chip.c index 42b1062e33cd..e4d591e8857b 100644 --- a/drivers/char/tpm/tpm-chip.c +++ b/drivers/char/tpm/tpm-chip.c @@ -44,7 +44,7 @@ static int tpm_request_locality(struct tpm_chip *chip) if (!chip->ops->request_locality) return 0; - rc = chip->ops->request_locality(chip, 0); + rc = chip->ops->request_locality(chip, chip->pref_locality); if (rc < 0) return rc; @@ -143,6 +143,27 @@ void tpm_chip_stop(struct tpm_chip *chip) } EXPORT_SYMBOL_GPL(tpm_chip_stop); +/** + * tpm_chip_preferred_locality() - set the TPM chip preferred locality to open + * @chip: a TPM chip to use + * @locality: the preferred locality + * + * Return: + * * true - Preferred locality set + * * false - Invalid locality specified + */ +bool tpm_chip_preferred_locality(struct tpm_chip *chip, int locality) +{ + if (locality < 0 || locality >=TPM_MAX_LOCALITY) + return false; + + mutex_lock(&chip->tpm_mutex); + chip->pref_locality = locality; + mutex_unlock(&chip->tpm_mutex); + return true; +} +EXPORT_SYMBOL_GPL(tpm_chip_preferred_locality); + /** * tpm_try_get_ops() - Get a ref to the tpm_chip * @chip: Chip to ref @@ -368,6 +389,7 @@ struct tpm_chip *tpm_chip_alloc(struct device *pdev, } chip->locality = -1; + chip->pref_locality = 0; return chip; out: diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c index 66b16d26eecc..7a758c6d6d09 100644 --- a/drivers/char/tpm/tpm-interface.c +++ b/drivers/char/tpm/tpm-interface.c @@ -273,6 +273,21 @@ int tpm_is_tpm2(struct tpm_chip *chip) } EXPORT_SYMBOL_GPL(tpm_is_tpm2); +/** + * tpm_preferred_locality() - set the TPM chip preferred locality to open + * @chip: a TPM chip to use + * @locality: the preferred locality + * + * Return: + * * true - Preferred locality set + * * false - Invalid locality specified + */ +bool tpm_preferred_locality(struct tpm_chip *chip, int locality) +{ + return tpm_chip_preferred_locality(chip, locality); +} +EXPORT_SYMBOL_GPL(tpm_preferred_locality); + /** * tpm_pcr_read - read a PCR value from SHA1 bank * @chip: a &struct tpm_chip instance, %NULL for the default chip diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h index 61445f1dc46d..389b117e68c2 100644 --- a/drivers/char/tpm/tpm.h +++ b/drivers/char/tpm/tpm.h @@ -267,6 +267,7 @@ static inline void tpm_msleep(unsigned int delay_msec) int tpm_chip_bootstrap(struct tpm_chip *chip); int tpm_chip_start(struct tpm_chip *chip); void tpm_chip_stop(struct tpm_chip *chip); +bool tpm_chip_preferred_locality(struct tpm_chip *chip, int locality); struct tpm_chip *tpm_find_get_ops(struct tpm_chip *chip); struct tpm_chip *tpm_chip_alloc(struct device *dev, diff --git a/include/linux/tpm.h b/include/linux/tpm.h index 4ee9d13749ad..a61d4e5e4b2d 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; @@ -170,6 +176,9 @@ struct tpm_chip { /* active locality */ int locality; + + /* preferred locality - default 0 */ + int pref_locality; }; #define TPM_HEADER_SIZE 10 @@ -421,6 +430,7 @@ static inline u32 tpm2_rc_value(u32 rc) #if defined(CONFIG_TCG_TPM) || defined(CONFIG_TCG_TPM_MODULE) extern int tpm_is_tpm2(struct tpm_chip *chip); +extern bool tpm_preferred_locality(struct tpm_chip *chip, int locality); extern __must_check int tpm_try_get_ops(struct tpm_chip *chip); extern void tpm_put_ops(struct tpm_chip *chip); extern ssize_t tpm_transmit_cmd(struct tpm_chip *chip, struct tpm_buf *buf, -- 2.39.3