From patchwork Tue Apr 8 08:32:05 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 14042394 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (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 355F12641C6 for ; Tue, 8 Apr 2025 08:32:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744101143; cv=none; b=Yukwey2dvCSZg48zeMeMvHstDmkJ5fhFOqIOi72M0TtwyL2ZnsQbLfToV1RG90YxeHZsIw559WHn8U32oSgsdd2Y8ef91niGCpWHtjjrENo1VYHZuxc+OmF9erw2IUHz8IM6qjFcTX+Wdwl0LMKSDdSl6vXZ8ZJCrQk20pv1sUY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744101143; c=relaxed/simple; bh=5MM8pORZWnScwf6ewALVw4cjhS6Azxp4msVUGK1bi68=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=maTX6sy6GfxV3pv+G+X8CbufKgwjNv6nu40hnvhgMrhap49F4ivnyn7fS2zl83Bfx+Tq0n0i++cuC+85MiLygDrBFswAQfq6gVJz+5sWXt0s2+jCb+T2971kV6WDqg2iTUzz/bmbeOIDU+rCU0AuVfEzTNqZ3DSkXi0oCX1iPW0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=Do/tZspE; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Do/tZspE" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1744101140; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zjSC2fEEv9F3kmldtv2lcizGFa35FlkMCGJDC9bTagU=; b=Do/tZspEyQj8VsJGb4oT+KoEgIcWTSrdgmjxjMvfqfSnbEDAgn+WdNONxJnrBqHXzOujox j/L/f++4VH5WRD8JG6avRr9RANosaCVsdQacNHcPrIMLqJZCWZv4+J1I5r17CjNQAlap6Z jnvjnnSyFaRIsrWCqCSSCf/t4y6uE10= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-287-2d_q8BO9NDiKO2Z4rlM3nw-1; Tue, 08 Apr 2025 04:32:18 -0400 X-MC-Unique: 2d_q8BO9NDiKO2Z4rlM3nw-1 X-Mimecast-MFC-AGG-ID: 2d_q8BO9NDiKO2Z4rlM3nw_1744101138 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-43cf172ffe1so43655975e9.3 for ; Tue, 08 Apr 2025 01:32:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744101137; x=1744705937; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zjSC2fEEv9F3kmldtv2lcizGFa35FlkMCGJDC9bTagU=; b=w2oj7+J7XyCm3zuv3+FkZ46JzKWT1t0Ntu+Jy3pE6B+w5CpNo242A24fXWG9kDQWa1 4XLzWeOaK/ZbB6kfxzm0Z2npkc9X+iM9nNzqmVSSoJFVbObmiluJBvuiOOAg6Zfy2lik Rh0RQKAzAffygiHT4z98MYdMagN7czPiLiZLG5unQMOKbjm0AyArMOqD2kvLt5GnmnSd uzK1DCccHULd9RGnjf5LHh04HmDgEG3rqUDgalqNvh9y+PhIyfqdRcThBMfpKodISVml qL3LeXoRbyOoH4K1N+Y7ODdrJzoWftKgg276vCxkeOwEURCzGrexGvK0pESXCY8iXdPR PHJA== X-Forwarded-Encrypted: i=1; AJvYcCXfwjbcmyvbvNMcEeo62e+2an8O5HgX8Ag5uXDwJFAZLCe4qnwCKKyk2s2yVPDFeXS/SZS4w6OCe8OPyqWVcNQ=@vger.kernel.org X-Gm-Message-State: AOJu0YxE8E8/VrTeJi6ojg+xXm9d3V43Ru/gJC7I03gW9dAbQ7bZcwLG 2ZAzTJZgxZO85QtEUFE/lvkcPqeegKVU3ld4mOp/wISfU4oudWwvxKvy8mBU8eq+EEet/2QTZOT A0viOuARiYDBtqt/NKc9ERNWAJq80hDn7e2qXyKiL/gH7nQa6FET3kfBL57JjJLCRWg== X-Gm-Gg: ASbGncsXDYZPvzrghTtLSzecbLDTnV9zwc+cWva5o7VmxGb8EVJieiND9Ad3kSa8Oof BcvQR5JrB1e5LxitUxB1IX4zuguUsRvYO9UxmjRGP5BrvIvtmEm2y+Wb0FCO2R5WslW56OzWvPw 8tccIg9R5KCFxsk6Pk3csoH8nHZlAkPcN7Jt5SkjMC/AhGd7UUMTL2/O0ijS2Fde3iUbl0NCvlh Ty+M5JtRaFHHABNpowQdrXMhyA5MoiexTjP9yy1mIR8N2fLMPLUAYaaE9inDtMjAmADbksS7tyU 1cZI5yno3RrKuMSskWKZKRD1Jdsqg0iFlg7wUtO25y614Lye+Kvqxkb4e3YUEqPVTg== X-Received: by 2002:a05:600c:3549:b0:43c:e481:3353 with SMTP id 5b1f17b1804b1-43ecf90aae2mr165784725e9.17.1744101137413; Tue, 08 Apr 2025 01:32:17 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG1jLFoe9t+FYg7K9VMsmfzan32hNxAZLIXvfWMRelSw02WoNY+Bh5SYNrx5pWATENrhHoAVg== X-Received: by 2002:a05:600c:3549:b0:43c:e481:3353 with SMTP id 5b1f17b1804b1-43ecf90aae2mr165784005e9.17.1744101136729; Tue, 08 Apr 2025 01:32:16 -0700 (PDT) Received: from stex1.redhat.com (host-79-53-30-213.retail.telecomitalia.it. [79.53.30.213]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43ec342827fsm155384365e9.6.2025.04.08.01.32.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Apr 2025 01:32:15 -0700 (PDT) From: Stefano Garzarella To: Jarkko Sakkinen Cc: Alexandre Belloni , Nicolas Ferre , linux-kernel@vger.kernel.org, Claudiu Beznea , linux-arm-kernel@lists.infradead.org, Jens Wiklander , linuxppc-dev@lists.ozlabs.org, Michael Ellerman , Sumit Garg , Christophe Leroy , linux-integrity@vger.kernel.org, Jason Gunthorpe , Madhavan Srinivasan , Naveen N Rao , Nicholas Piggin , Peter Huewe , James Bottomley , Stefano Garzarella Subject: [PATCH v2 1/4] tpm: add buf_size parameter in the .send callback Date: Tue, 8 Apr 2025 10:32:05 +0200 Message-ID: <20250408083208.43512-2-sgarzare@redhat.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250408083208.43512-1-sgarzare@redhat.com> References: <20250408083208.43512-1-sgarzare@redhat.com> Precedence: bulk X-Mailing-List: linux-integrity@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Stefano Garzarella In preparation for the next commit, add a new `buf_size` parameter to the `.send` callback in `tpm_class_ops` which contains the entire buffer size. In this patch it is pretty much ignored by all drivers, but it will be used in the next patch. Also rename the previous parameter `len` to `cmd_len` in the declaration to make it clear that it contains the length in bytes of the command stored in the buffer. The semantics don't change and it can be used as before by drivers. This is an optimization since the drivers could get it from the header, but let's avoid duplicating code. While we are here, resolve a checkpatch warning: WARNING: Unnecessary space before function pointer arguments #66: FILE: include/linux/tpm.h:90: + int (*send) (struct tpm_chip *chip, u8 *buf, size_t cmd_len, Suggested-by: Jarkko Sakkinen Signed-off-by: Stefano Garzarella --- I'm not sure about 3 things about this patch: 1. Since `buf_size` is pretty much ignored, is it better to merge this patch with the next one? I kept it separate because we touch all the drivers here, so I think it's better to have this change in a separate patch to make it clear that we are not touching anything in the drivers, but I'm open to merge it if you prefer. 2. I avoided changing the previous parameter in the drivers (`len` or `count`) to keep the changes minimal, but if you prefer I can use `cmd_len` everywhere. 3. Fix the checkpatch warning mentioned in the description. Thanks, Stefano --- include/linux/tpm.h | 3 ++- drivers/char/tpm/st33zp24/st33zp24.c | 2 +- drivers/char/tpm/tpm-interface.c | 2 +- drivers/char/tpm/tpm_atmel.c | 3 ++- drivers/char/tpm/tpm_crb.c | 2 +- drivers/char/tpm/tpm_ftpm_tee.c | 4 +++- drivers/char/tpm/tpm_i2c_atmel.c | 3 ++- drivers/char/tpm/tpm_i2c_infineon.c | 3 ++- drivers/char/tpm/tpm_i2c_nuvoton.c | 3 ++- drivers/char/tpm/tpm_ibmvtpm.c | 6 ++++-- drivers/char/tpm/tpm_infineon.c | 3 ++- drivers/char/tpm/tpm_nsc.c | 3 ++- drivers/char/tpm/tpm_svsm.c | 3 ++- drivers/char/tpm/tpm_tis_core.c | 3 ++- drivers/char/tpm/tpm_tis_i2c_cr50.c | 6 ++++-- drivers/char/tpm/tpm_vtpm_proxy.c | 4 +++- drivers/char/tpm/xen-tpmfront.c | 3 ++- 17 files changed, 37 insertions(+), 19 deletions(-) diff --git a/include/linux/tpm.h b/include/linux/tpm.h index 6c3125300c00..2e38edd5838c 100644 --- a/include/linux/tpm.h +++ b/include/linux/tpm.h @@ -87,7 +87,8 @@ struct tpm_class_ops { const u8 req_complete_val; bool (*req_canceled)(struct tpm_chip *chip, u8 status); int (*recv) (struct tpm_chip *chip, u8 *buf, size_t len); - int (*send) (struct tpm_chip *chip, u8 *buf, size_t len); + int (*send)(struct tpm_chip *chip, u8 *buf, size_t cmd_len, + size_t buf_size); void (*cancel) (struct tpm_chip *chip); u8 (*status) (struct tpm_chip *chip); void (*update_timeouts)(struct tpm_chip *chip, diff --git a/drivers/char/tpm/st33zp24/st33zp24.c b/drivers/char/tpm/st33zp24/st33zp24.c index c0771980bc2f..3de68bca1740 100644 --- a/drivers/char/tpm/st33zp24/st33zp24.c +++ b/drivers/char/tpm/st33zp24/st33zp24.c @@ -300,7 +300,7 @@ static irqreturn_t tpm_ioserirq_handler(int irq, void *dev_id) * send TPM commands through the I2C bus. */ static int st33zp24_send(struct tpm_chip *chip, unsigned char *buf, - size_t len) + size_t len, size_t buf_size) { struct st33zp24_dev *tpm_dev = dev_get_drvdata(&chip->dev); u32 status, i, size, ordinal; diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c index 8d7e4da6ed53..3b6ddcdb4051 100644 --- a/drivers/char/tpm/tpm-interface.c +++ b/drivers/char/tpm/tpm-interface.c @@ -106,7 +106,7 @@ static ssize_t tpm_try_transmit(struct tpm_chip *chip, void *buf, size_t bufsiz) return -E2BIG; } - rc = chip->ops->send(chip, buf, count); + rc = chip->ops->send(chip, buf, count, bufsiz); if (rc < 0) { if (rc != -EPIPE) dev_err(&chip->dev, diff --git a/drivers/char/tpm/tpm_atmel.c b/drivers/char/tpm/tpm_atmel.c index 54a0360a3c95..5733168bfc26 100644 --- a/drivers/char/tpm/tpm_atmel.c +++ b/drivers/char/tpm/tpm_atmel.c @@ -148,7 +148,8 @@ static int tpm_atml_recv(struct tpm_chip *chip, u8 *buf, size_t count) return size; } -static int tpm_atml_send(struct tpm_chip *chip, u8 *buf, size_t count) +static int tpm_atml_send(struct tpm_chip *chip, u8 *buf, size_t count, + size_t buf_size) { struct tpm_atmel_priv *priv = dev_get_drvdata(&chip->dev); int i; diff --git a/drivers/char/tpm/tpm_crb.c b/drivers/char/tpm/tpm_crb.c index 876edf2705ab..38f765a44a97 100644 --- a/drivers/char/tpm/tpm_crb.c +++ b/drivers/char/tpm/tpm_crb.c @@ -426,7 +426,7 @@ static int tpm_crb_smc_start(struct device *dev, unsigned long func_id) } #endif -static int crb_send(struct tpm_chip *chip, u8 *buf, size_t len) +static int crb_send(struct tpm_chip *chip, u8 *buf, size_t len, size_t buf_size) { struct crb_priv *priv = dev_get_drvdata(&chip->dev); int rc = 0; diff --git a/drivers/char/tpm/tpm_ftpm_tee.c b/drivers/char/tpm/tpm_ftpm_tee.c index 53ba28ccd5d3..637cc8b6599e 100644 --- a/drivers/char/tpm/tpm_ftpm_tee.c +++ b/drivers/char/tpm/tpm_ftpm_tee.c @@ -64,12 +64,14 @@ static int ftpm_tee_tpm_op_recv(struct tpm_chip *chip, u8 *buf, size_t count) * @chip: the tpm_chip description as specified in driver/char/tpm/tpm.h * @buf: the buffer to send. * @len: the number of bytes to send. + * @buf_size: the size of the buffer. * * Return: * In case of success, returns 0. * On failure, -errno */ -static int ftpm_tee_tpm_op_send(struct tpm_chip *chip, u8 *buf, size_t len) +static int ftpm_tee_tpm_op_send(struct tpm_chip *chip, u8 *buf, size_t len, + size_t buf_size) { struct ftpm_tee_private *pvt_data = dev_get_drvdata(chip->dev.parent); size_t resp_len; diff --git a/drivers/char/tpm/tpm_i2c_atmel.c b/drivers/char/tpm/tpm_i2c_atmel.c index d1d27fdfe523..572f97cb9e89 100644 --- a/drivers/char/tpm/tpm_i2c_atmel.c +++ b/drivers/char/tpm/tpm_i2c_atmel.c @@ -37,7 +37,8 @@ struct priv_data { u8 buffer[sizeof(struct tpm_header) + 25]; }; -static int i2c_atmel_send(struct tpm_chip *chip, u8 *buf, size_t len) +static int i2c_atmel_send(struct tpm_chip *chip, u8 *buf, size_t len, + size_t buf_size) { struct priv_data *priv = dev_get_drvdata(&chip->dev); struct i2c_client *client = to_i2c_client(chip->dev.parent); diff --git a/drivers/char/tpm/tpm_i2c_infineon.c b/drivers/char/tpm/tpm_i2c_infineon.c index 81d8a78dc655..25d6ae3a4cc1 100644 --- a/drivers/char/tpm/tpm_i2c_infineon.c +++ b/drivers/char/tpm/tpm_i2c_infineon.c @@ -514,7 +514,8 @@ static int tpm_tis_i2c_recv(struct tpm_chip *chip, u8 *buf, size_t count) return size; } -static int tpm_tis_i2c_send(struct tpm_chip *chip, u8 *buf, size_t len) +static int tpm_tis_i2c_send(struct tpm_chip *chip, u8 *buf, size_t len, + size_t buf_size) { int rc, status; ssize_t burstcnt; diff --git a/drivers/char/tpm/tpm_i2c_nuvoton.c b/drivers/char/tpm/tpm_i2c_nuvoton.c index 3c3ee5f551db..169078ce6ac4 100644 --- a/drivers/char/tpm/tpm_i2c_nuvoton.c +++ b/drivers/char/tpm/tpm_i2c_nuvoton.c @@ -350,7 +350,8 @@ static int i2c_nuvoton_recv(struct tpm_chip *chip, u8 *buf, size_t count) * tpm.c can skip polling for the data to be available as the interrupt is * waited for here */ -static int i2c_nuvoton_send(struct tpm_chip *chip, u8 *buf, size_t len) +static int i2c_nuvoton_send(struct tpm_chip *chip, u8 *buf, size_t len, + size_t buf_size) { struct priv_data *priv = dev_get_drvdata(&chip->dev); struct device *dev = chip->dev.parent; diff --git a/drivers/char/tpm/tpm_ibmvtpm.c b/drivers/char/tpm/tpm_ibmvtpm.c index 76d048f63d55..660a7f9da1d8 100644 --- a/drivers/char/tpm/tpm_ibmvtpm.c +++ b/drivers/char/tpm/tpm_ibmvtpm.c @@ -191,13 +191,15 @@ static int tpm_ibmvtpm_resume(struct device *dev) * tpm_ibmvtpm_send() - Send a TPM command * @chip: tpm chip struct * @buf: buffer contains data to send - * @count: size of buffer + * @count: length of the command + * @buf_size: size of the buffer * * Return: * 0 on success, * -errno on error */ -static int tpm_ibmvtpm_send(struct tpm_chip *chip, u8 *buf, size_t count) +static int tpm_ibmvtpm_send(struct tpm_chip *chip, u8 *buf, size_t count, + size_t buf_size) { struct ibmvtpm_dev *ibmvtpm = dev_get_drvdata(&chip->dev); bool retry = true; diff --git a/drivers/char/tpm/tpm_infineon.c b/drivers/char/tpm/tpm_infineon.c index 2d2ae37153ba..7896fdacd156 100644 --- a/drivers/char/tpm/tpm_infineon.c +++ b/drivers/char/tpm/tpm_infineon.c @@ -312,7 +312,8 @@ static int tpm_inf_recv(struct tpm_chip *chip, u8 * buf, size_t count) return -EIO; } -static int tpm_inf_send(struct tpm_chip *chip, u8 * buf, size_t count) +static int tpm_inf_send(struct tpm_chip *chip, u8 *buf, size_t count, + size_t buf_size) { int i; int ret; diff --git a/drivers/char/tpm/tpm_nsc.c b/drivers/char/tpm/tpm_nsc.c index 0f62bbc940da..12aedef3c50e 100644 --- a/drivers/char/tpm/tpm_nsc.c +++ b/drivers/char/tpm/tpm_nsc.c @@ -178,7 +178,8 @@ static int tpm_nsc_recv(struct tpm_chip *chip, u8 * buf, size_t count) return size; } -static int tpm_nsc_send(struct tpm_chip *chip, u8 * buf, size_t count) +static int tpm_nsc_send(struct tpm_chip *chip, u8 *buf, size_t count, + size_t buf_size) { struct tpm_nsc_priv *priv = dev_get_drvdata(&chip->dev); u8 data; diff --git a/drivers/char/tpm/tpm_svsm.c b/drivers/char/tpm/tpm_svsm.c index b9242c9eab87..b8aa7eb567de 100644 --- a/drivers/char/tpm/tpm_svsm.c +++ b/drivers/char/tpm/tpm_svsm.c @@ -25,7 +25,8 @@ struct tpm_svsm_priv { void *buffer; }; -static int tpm_svsm_send(struct tpm_chip *chip, u8 *buf, size_t len) +static int tpm_svsm_send(struct tpm_chip *chip, u8 *buf, size_t len, + size_t buf_size) { struct tpm_svsm_priv *priv = dev_get_drvdata(&chip->dev); int ret; diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c index ed0d3d8449b3..5641a73ce280 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -580,7 +580,8 @@ static int tpm_tis_send_main(struct tpm_chip *chip, const u8 *buf, size_t len) return rc; } -static int tpm_tis_send(struct tpm_chip *chip, u8 *buf, size_t len) +static int tpm_tis_send(struct tpm_chip *chip, u8 *buf, size_t len, + size_t buf_size) { int rc, irq; struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev); diff --git a/drivers/char/tpm/tpm_tis_i2c_cr50.c b/drivers/char/tpm/tpm_tis_i2c_cr50.c index 3b55a7b05c46..1914b368472d 100644 --- a/drivers/char/tpm/tpm_tis_i2c_cr50.c +++ b/drivers/char/tpm/tpm_tis_i2c_cr50.c @@ -546,13 +546,15 @@ static int tpm_cr50_i2c_tis_recv(struct tpm_chip *chip, u8 *buf, size_t buf_len) * tpm_cr50_i2c_tis_send() - TPM transmission callback. * @chip: A TPM chip. * @buf: Buffer to send. - * @len: Buffer length. + * @len: Command length. + * @buf_size: Buffer size. * * Return: * - 0: Success. * - -errno: A POSIX error code. */ -static int tpm_cr50_i2c_tis_send(struct tpm_chip *chip, u8 *buf, size_t len) +static int tpm_cr50_i2c_tis_send(struct tpm_chip *chip, u8 *buf, size_t len, + size_t buf_size) { size_t burstcnt, limit, sent = 0; u8 tpm_go[4] = { TPM_STS_GO }; diff --git a/drivers/char/tpm/tpm_vtpm_proxy.c b/drivers/char/tpm/tpm_vtpm_proxy.c index 8fe4a01eea12..beaa84428b49 100644 --- a/drivers/char/tpm/tpm_vtpm_proxy.c +++ b/drivers/char/tpm/tpm_vtpm_proxy.c @@ -322,11 +322,13 @@ static int vtpm_proxy_is_driver_command(struct tpm_chip *chip, * @chip: tpm chip to use * @buf: send buffer * @count: bytes to send + * @buf_size: size of the buffer * * Return: * 0 in case of success, negative error value otherwise. */ -static int vtpm_proxy_tpm_op_send(struct tpm_chip *chip, u8 *buf, size_t count) +static int vtpm_proxy_tpm_op_send(struct tpm_chip *chip, u8 *buf, size_t count, + size_t buf_size) { struct proxy_dev *proxy_dev = dev_get_drvdata(&chip->dev); diff --git a/drivers/char/tpm/xen-tpmfront.c b/drivers/char/tpm/xen-tpmfront.c index 80cca3b83b22..66a4dbb4a4d8 100644 --- a/drivers/char/tpm/xen-tpmfront.c +++ b/drivers/char/tpm/xen-tpmfront.c @@ -131,7 +131,8 @@ static size_t shr_data_offset(struct vtpm_shared_page *shr) return struct_size(shr, extra_pages, shr->nr_extra_pages); } -static int vtpm_send(struct tpm_chip *chip, u8 *buf, size_t count) +static int vtpm_send(struct tpm_chip *chip, u8 *buf, size_t count, + size_t buf_size) { struct tpm_private *priv = dev_get_drvdata(&chip->dev); struct vtpm_shared_page *shr = priv->shr; From patchwork Tue Apr 8 08:32:06 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 14042395 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 5481925EFA3 for ; Tue, 8 Apr 2025 08:32:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744101146; cv=none; b=KTGkR+X5t25wXzoEz1CmS45wK0oAassU8lf1suF9u7OucrIQEr/CLzZN1P84xT19cBik20/zTw/JJb7hnhyJrhEnhG5O2CLvB6pw/w0wUvd70XjMeExqT4/r/ZezVklCZYUgXltkKsbtuqHVY5YkFUsu8sEV9Z5ddYLB/0nCQg0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744101146; c=relaxed/simple; bh=WvbgwlAGGsl+4IleITMI6e4y/KHe7f57c66lAWpy3NI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=f8iY3SUCDrHb2uVTUOmCyS0w+7UirNOO7wW/KNSCOfr9gs57YzXearuv5IRegokWc3vfVFKl0uOoeREl3DWoyZR7FFKoui7j4aKQP1vkKXDmORAywskQSHWNX49QJE8rif+aHK7RLv6N/vMqvOi0JFSzlMc1s5tjxvgyi1Sq4lY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=QzYIbl3l; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="QzYIbl3l" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1744101144; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=QDE/YZIPCEEz/h330X/plomZy4BudCgqspAc85dgVok=; b=QzYIbl3lvtm3aKVhR8N6vqyZcmVUPaBGR6S1oYXEaPRHX7m3zN89lrKRnW5kIiQCIpIv7m WUfC3sdtPLnMQ0LSEw0xnHM2yDomt4jA61TGaLhNGxRh3+/eCaKDZLsfStufrVqNTk9YCp Hx+fahkvYDTAMfP5iifjmk7w4j62KMs= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-450-dAgLTURlN42sOFiT6-a45Q-1; Tue, 08 Apr 2025 04:32:23 -0400 X-MC-Unique: dAgLTURlN42sOFiT6-a45Q-1 X-Mimecast-MFC-AGG-ID: dAgLTURlN42sOFiT6-a45Q_1744101142 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-43d51bd9b45so36341515e9.1 for ; Tue, 08 Apr 2025 01:32:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744101142; x=1744705942; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=QDE/YZIPCEEz/h330X/plomZy4BudCgqspAc85dgVok=; b=RtlgO5DClv3YKhBJLsrSOl0qY7yXfOvU8Ej/kSHBX++/3AU9i34HLOwTpHGErGwq3v jQq/OYCh+4dFUlA/+HkMN23unKnRjFi+wkjC4O26i1eKgXwUIzEeadqsOuydwoy1gcny bWEB7XmZ2vibJKqJLE5t5eo+yzIMCdeTi1cN2mvrAgHn0eohiweKX1ZX7QhNzpks4y17 KApF4dLNzMOnikDt7jar/5CluFA11YIzEZ5mETIqiKnlru8BXyQ5/ojz7D9YDGJV2uGo uYYIm9YXpGPRU47AUpBtUIJpXEhdazAn8mP70RzRO1HLglQiVpnsFpKLJtsBsqnGh+PQ WBnQ== X-Forwarded-Encrypted: i=1; AJvYcCXNmSo/SqfKw7ZPyDtcLHcDrkYhHikXwOO94pSieHYmx5MNlVw4LhEW0CzJAd3zz5McQo/SYDaWv5pCDQylJcg=@vger.kernel.org X-Gm-Message-State: AOJu0YyHXjxv0lza3419KCbMoiiGj4tNxfnr+gh77k4jxdMBq96gWrHi K/tHqDICTYat5Ok79ZQm07gkeCyWUaHMFD5k5Qh8c2lfUaJxItEtFSyqdR6TQC4vXEHhyXFsBcT 1ZFCZk14BygPuN5YaF4Ax1NudZIev3XBupWDVBKKpaW5uG28J0n8qwiAHpRVVhTCb/A== X-Gm-Gg: ASbGncstBi5EHnUtdBq4ItoCAk7wEV+oCxqi2QQ/qaGrA5bbQXtP5jMqC0XxiRYWDSf qpIBIguWgQ3HjYe/xlJYZGT4hfws/mNWT06oG8p/mz7pzV/WO3YcSvV0ZNPylXqX2V4tKCIq0ZF txip3Q2zW9JFf9DVCjRxZidNWAghKsLZLqkBe31FuXqXYbKMSy8NctFXLa8xQoBMw+DxUBCYFXJ w1kDnHGwzES9AgCZBYHSelZQNDOf9TZHagU9QzpQVbUgpJT0rtYzqJEUBdC3Ru9uWlEVBMUXwmn kZH6/V1dlyNoYp0wes6x1fNJOiCJySN9dwD+EHTcNGYmhZ3Ndx0Pwhc2Kp4JJJ52Qw== X-Received: by 2002:a05:600c:1e13:b0:439:8c80:6af4 with SMTP id 5b1f17b1804b1-43ecf8d0b48mr141342835e9.19.1744101141991; Tue, 08 Apr 2025 01:32:21 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHQhp1MgrEqOjc+4MW66KZXrp62NtlwXCuZ1w3QWz8IsRQIARyOk/4wlryzdly6gRSlx08ezQ== X-Received: by 2002:a05:600c:1e13:b0:439:8c80:6af4 with SMTP id 5b1f17b1804b1-43ecf8d0b48mr141342355e9.19.1744101141383; Tue, 08 Apr 2025 01:32:21 -0700 (PDT) Received: from stex1.redhat.com (host-79-53-30-213.retail.telecomitalia.it. [79.53.30.213]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-39c3009680dsm14051923f8f.7.2025.04.08.01.32.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Apr 2025 01:32:20 -0700 (PDT) From: Stefano Garzarella To: Jarkko Sakkinen Cc: Alexandre Belloni , Nicolas Ferre , linux-kernel@vger.kernel.org, Claudiu Beznea , linux-arm-kernel@lists.infradead.org, Jens Wiklander , linuxppc-dev@lists.ozlabs.org, Michael Ellerman , Sumit Garg , Christophe Leroy , linux-integrity@vger.kernel.org, Jason Gunthorpe , Madhavan Srinivasan , Naveen N Rao , Nicholas Piggin , Peter Huewe , James Bottomley , Stefano Garzarella Subject: [PATCH v2 2/4] tpm: support devices with synchronous send() Date: Tue, 8 Apr 2025 10:32:06 +0200 Message-ID: <20250408083208.43512-3-sgarzare@redhat.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250408083208.43512-1-sgarzare@redhat.com> References: <20250408083208.43512-1-sgarzare@redhat.com> Precedence: bulk X-Mailing-List: linux-integrity@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Stefano Garzarella Some devices do not support interrupts and provide a single synchronous operation to send the command and receive the response on the same buffer. Currently, these types of drivers must use an internal buffer where they temporarily store the response between .send() and recv() calls. Introduce a new flag (TPM_CHIP_FLAG_SYNC) to support synchronous send(). If that flag is set by the driver, tpm_try_transmit() will use the send() callback to send the command and receive the response on the same buffer synchronously. In that case send() return the number of bytes of the response on success, or -errno on failure. Suggested-by: Jason Gunthorpe Suggested-by: Jarkko Sakkinen Signed-off-by: Stefano Garzarella --- include/linux/tpm.h | 1 + drivers/char/tpm/tpm-interface.c | 18 +++++++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/include/linux/tpm.h b/include/linux/tpm.h index 2e38edd5838c..0e9746dc9d30 100644 --- a/include/linux/tpm.h +++ b/include/linux/tpm.h @@ -350,6 +350,7 @@ enum tpm_chip_flags { TPM_CHIP_FLAG_SUSPENDED = BIT(8), TPM_CHIP_FLAG_HWRNG_DISABLED = BIT(9), TPM_CHIP_FLAG_DISABLE = BIT(10), + TPM_CHIP_FLAG_SYNC = BIT(11), }; #define to_tpm_chip(d) container_of(d, struct tpm_chip, dev) diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c index 3b6ddcdb4051..9fbe84b5a131 100644 --- a/drivers/char/tpm/tpm-interface.c +++ b/drivers/char/tpm/tpm-interface.c @@ -114,8 +114,17 @@ static ssize_t tpm_try_transmit(struct tpm_chip *chip, void *buf, size_t bufsiz) return rc; } - /* A sanity check. send() should just return zero on success e.g. - * not the command length. + /* Synchronous devices return the response directly during the send() + * call in the same buffer. + */ + if (chip->flags & TPM_CHIP_FLAG_SYNC) { + len = rc; + rc = 0; + goto out_send_sync; + } + + /* A sanity check. send() of asynchronous devices should just return + * zero on success e.g. not the command length. */ if (rc > 0) { dev_warn(&chip->dev, @@ -151,7 +160,10 @@ static ssize_t tpm_try_transmit(struct tpm_chip *chip, void *buf, size_t bufsiz) if (len < 0) { rc = len; dev_err(&chip->dev, "tpm_transmit: tpm_recv: error %d\n", rc); - } else if (len < TPM_HEADER_SIZE || len != be32_to_cpu(header->length)) + return rc; + } +out_send_sync: + if (len < TPM_HEADER_SIZE || len != be32_to_cpu(header->length)) rc = -EFAULT; return rc ? rc : len; From patchwork Tue Apr 8 08:32:07 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 14042396 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (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 145BD264611 for ; Tue, 8 Apr 2025 08:32:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744101151; cv=none; b=GxQNFioi4wqFJw1BhqKZoHKewaZ2kC6CoLFv4mXj5IhhfuyJsaYH7Ul3p/SHAd9pev8OAFq+Ml3aG4eNqK7PImGwLLfalPmn3HNw0ff+znSkwudCb6WPNaGFnS4kPPJRFRkXn5ye8g6m9VrgIPEIt0jFMXZIvdQNctC+SZ/G6Is= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744101151; c=relaxed/simple; bh=U1qC/sy3KM3pFlSOrOxYv2VmI/J+Xj4HkqFlDY7nkB0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oybUemCMZAWjlISjzOTyUbEGP7ItA2Qc66m6wb5wxUYNghbqJyKrIUzjiOZohrFebMt0c1LRA3n32b6omYnJU9vVTe49JiBUJ/+8W9ZMTyW03DYQPMzhM+ezd8Y6sIrDZfYn51nNht2Qt44DyV8T9YAjAvkVa1nkjxTuKaHPyIc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=Ra7NiWGY; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Ra7NiWGY" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1744101149; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0jjogm03xe8uH9FEbFpCE/wwTjsk8lbbHkAYLp5l0W8=; b=Ra7NiWGY0V4yEsseV5LOEAtiUvOTi+cknemd1ClGoKoo244WO5z3bkB9TiJoyu4OpVSeJd 1x4Ji27kZQtk1zEEJ6gUxFUXkPvAff8AIro/Zrmcm7Go7r0ziH1D8Bi79+bS9uTJz8ujk7 BAMgEZqq62VPgdeRMljK2BRClxjHyrg= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-533-jWz-R_FOOCWHf4yHIUVw4w-1; Tue, 08 Apr 2025 04:32:27 -0400 X-MC-Unique: jWz-R_FOOCWHf4yHIUVw4w-1 X-Mimecast-MFC-AGG-ID: jWz-R_FOOCWHf4yHIUVw4w_1744101147 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-43cf172ffe1so43657795e9.3 for ; Tue, 08 Apr 2025 01:32:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744101147; x=1744705947; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0jjogm03xe8uH9FEbFpCE/wwTjsk8lbbHkAYLp5l0W8=; b=vaj6eIufdaUq4A/0+I121cB9OZiLIL+WlJZgFoPzn3KA9kydXkOB9przgB/YtRcKPV c/czuDbpyH83D8ok1ErL/UE0/FJvOVZo2UJclhYqjhOGi77GJk6oBKd2FFCUAO8YMz1H RkqfHE/e2bG2mAUBN65bgzsHYg03i9ryTCczC+TNyjTaSTTOBs/X4kAswl9+ucWjmn4M lwZXDj+Qr3ACen9HvpddOAZTqjpx9op9Jux39L//R4NN1v3JcDVpE0MODDLIxYCNvjTq vNcq0GskG9TFlUuo4WSgezdzWVCSkPMqN/x/NW2whRcRr9BcgqB1Eo5gCCdKQOl1mEsF fnsQ== X-Forwarded-Encrypted: i=1; AJvYcCUq5n/Ua93nxyqV8cZni0r/rXuz/Cx0wVkAOg2Khwk8eLxqR3w4MglOoK9apqUx7VuxzWrXtPAfK2/fIFj6Xpc=@vger.kernel.org X-Gm-Message-State: AOJu0YyqmWTNyQGuQ9TPAgCDWXwiNl19xwoMd75Qd5/MnMIT3z8vZGaZ goQZ9/oTASB/5WulWopW+OgNAJLW9BZNRYoIRDMwYGRdAiMKt6Q2oUplk58pBNcPThlYM+MSCia vlxzJUK5Mi+06DXSGtcT9LQkOg48TI4+pqobYQLPeQAnoCjo8HofI5MWgFY6CesS9RQ== X-Gm-Gg: ASbGncsBSAP2GfI06tlnip36ZSyrpYb4liTCraBxxC0vT/626wYK0HB1weSyYFTcuES AVo3+US4Qsnpl4hE8sG1vYnHS3Q2icQ8Gy0i9tYFC2q+IbvTkxwGVQgIpZlvQ4A1Ln/i2sSCOjl LqnN4pfnxI2d0czbPk7/KqNjKNvWizIi4P0WyVdLrsZ10TUMFT17rPzELBz8dQLpigZxXIJ7CLy 9DFod3sojdn+j4WYo9gbfWkmrKjSOePS/Sd91dQQ8L5TRTV7FZPJJPfQNlSL5JbpWkMGjJQEOu6 GmwKKZsiwhDZC2tFtPaDZ72KUyRGBvB37QTwwPGemBDyD+HSZ1rGHDo/bIFQ9FI6Pw== X-Received: by 2002:a05:600c:3489:b0:43c:f87c:24ce with SMTP id 5b1f17b1804b1-43ecf9c77ecmr122637485e9.21.1744101146620; Tue, 08 Apr 2025 01:32:26 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGO0mHtfU6tjdIaTwIU3mFKYSEAXTq1PTv+mq26VUWkOFRfaSqPIV+zWD9QaZteOnlwamweeA== X-Received: by 2002:a05:600c:3489:b0:43c:f87c:24ce with SMTP id 5b1f17b1804b1-43ecf9c77ecmr122637075e9.21.1744101146092; Tue, 08 Apr 2025 01:32:26 -0700 (PDT) Received: from stex1.redhat.com (host-79-53-30-213.retail.telecomitalia.it. [79.53.30.213]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-39c3020d661sm14565216f8f.66.2025.04.08.01.32.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Apr 2025 01:32:25 -0700 (PDT) From: Stefano Garzarella To: Jarkko Sakkinen Cc: Alexandre Belloni , Nicolas Ferre , linux-kernel@vger.kernel.org, Claudiu Beznea , linux-arm-kernel@lists.infradead.org, Jens Wiklander , linuxppc-dev@lists.ozlabs.org, Michael Ellerman , Sumit Garg , Christophe Leroy , linux-integrity@vger.kernel.org, Jason Gunthorpe , Madhavan Srinivasan , Naveen N Rao , Nicholas Piggin , Peter Huewe , James Bottomley , Stefano Garzarella Subject: [PATCH v2 3/4] tpm/tpm_ftpm_tee: support TPM_CHIP_FLAG_SYNC Date: Tue, 8 Apr 2025 10:32:07 +0200 Message-ID: <20250408083208.43512-4-sgarzare@redhat.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250408083208.43512-1-sgarzare@redhat.com> References: <20250408083208.43512-1-sgarzare@redhat.com> Precedence: bulk X-Mailing-List: linux-integrity@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Stefano Garzarella This driver does not support interrupts, and receiving the response is synchronous with sending the command. So we can set TPM_CHIP_FLAG_SYNC to support synchronous send() and return responses in the same buffer used for commands. This way we don't need the 4KB internal buffer used to cache the response before .send() and .recv(). Also we don't need to implement recv() op. Signed-off-by: Stefano Garzarella --- @Jens @Sumit can you test/review this patch again since we changed the core a bit adding TPM_CHIP_FLAG_SYNC instead of send_recv() op? Thanks, Stefano v2: - set TPM_CHIP_FLAG_SYNC and support it in the new send() - removed Jens' T-b v1: - added Jens' T-b --- drivers/char/tpm/tpm_ftpm_tee.h | 4 --- drivers/char/tpm/tpm_ftpm_tee.c | 64 ++++++++++----------------------- 2 files changed, 19 insertions(+), 49 deletions(-) diff --git a/drivers/char/tpm/tpm_ftpm_tee.h b/drivers/char/tpm/tpm_ftpm_tee.h index e39903b7ea07..8d5c3f0d2879 100644 --- a/drivers/char/tpm/tpm_ftpm_tee.h +++ b/drivers/char/tpm/tpm_ftpm_tee.h @@ -22,16 +22,12 @@ * struct ftpm_tee_private - fTPM's private data * @chip: struct tpm_chip instance registered with tpm framework. * @session: fTPM TA session identifier. - * @resp_len: cached response buffer length. - * @resp_buf: cached response buffer. * @ctx: TEE context handler. * @shm: Memory pool shared with fTPM TA in TEE. */ struct ftpm_tee_private { struct tpm_chip *chip; u32 session; - size_t resp_len; - u8 resp_buf[MAX_RESPONSE_SIZE]; struct tee_context *ctx; struct tee_shm *shm; }; diff --git a/drivers/char/tpm/tpm_ftpm_tee.c b/drivers/char/tpm/tpm_ftpm_tee.c index 637cc8b6599e..b9adc040ca6d 100644 --- a/drivers/char/tpm/tpm_ftpm_tee.c +++ b/drivers/char/tpm/tpm_ftpm_tee.c @@ -31,46 +31,18 @@ static const uuid_t ftpm_ta_uuid = 0x82, 0xCB, 0x34, 0x3F, 0xB7, 0xF3, 0x78, 0x96); /** - * ftpm_tee_tpm_op_recv() - retrieve fTPM response. - * @chip: the tpm_chip description as specified in driver/char/tpm/tpm.h. - * @buf: the buffer to store data. - * @count: the number of bytes to read. - * - * Return: - * In case of success the number of bytes received. - * On failure, -errno. - */ -static int ftpm_tee_tpm_op_recv(struct tpm_chip *chip, u8 *buf, size_t count) -{ - struct ftpm_tee_private *pvt_data = dev_get_drvdata(chip->dev.parent); - size_t len; - - len = pvt_data->resp_len; - if (count < len) { - dev_err(&chip->dev, - "%s: Invalid size in recv: count=%zd, resp_len=%zd\n", - __func__, count, len); - return -EIO; - } - - memcpy(buf, pvt_data->resp_buf, len); - pvt_data->resp_len = 0; - - return len; -} - -/** - * ftpm_tee_tpm_op_send() - send TPM commands through the TEE shared memory. + * ftpm_tee_tpm_op_send() - send TPM commands through the TEE shared memory + * and retrieve the response. * @chip: the tpm_chip description as specified in driver/char/tpm/tpm.h - * @buf: the buffer to send. - * @len: the number of bytes to send. + * @buf: the buffer to send and to store the response. + * @cmd_len: the number of bytes to send. * @buf_size: the size of the buffer. * * Return: - * In case of success, returns 0. + * In case of success, returns the number of bytes received. * On failure, -errno */ -static int ftpm_tee_tpm_op_send(struct tpm_chip *chip, u8 *buf, size_t len, +static int ftpm_tee_tpm_op_send(struct tpm_chip *chip, u8 *buf, size_t cmd_len, size_t buf_size) { struct ftpm_tee_private *pvt_data = dev_get_drvdata(chip->dev.parent); @@ -82,16 +54,15 @@ static int ftpm_tee_tpm_op_send(struct tpm_chip *chip, u8 *buf, size_t len, struct tee_param command_params[4]; struct tee_shm *shm = pvt_data->shm; - if (len > MAX_COMMAND_SIZE) { + if (cmd_len > MAX_COMMAND_SIZE) { dev_err(&chip->dev, "%s: len=%zd exceeds MAX_COMMAND_SIZE supported by fTPM TA\n", - __func__, len); + __func__, cmd_len); return -EIO; } memset(&transceive_args, 0, sizeof(transceive_args)); memset(command_params, 0, sizeof(command_params)); - pvt_data->resp_len = 0; /* Invoke FTPM_OPTEE_TA_SUBMIT_COMMAND function of fTPM TA */ transceive_args = (struct tee_ioctl_invoke_arg) { @@ -105,7 +76,7 @@ static int ftpm_tee_tpm_op_send(struct tpm_chip *chip, u8 *buf, size_t len, .attr = TEE_IOCTL_PARAM_ATTR_TYPE_MEMREF_INPUT, .u.memref = { .shm = shm, - .size = len, + .size = cmd_len, .shm_offs = 0, }, }; @@ -117,7 +88,7 @@ static int ftpm_tee_tpm_op_send(struct tpm_chip *chip, u8 *buf, size_t len, return PTR_ERR(temp_buf); } memset(temp_buf, 0, (MAX_COMMAND_SIZE + MAX_RESPONSE_SIZE)); - memcpy(temp_buf, buf, len); + memcpy(temp_buf, buf, cmd_len); command_params[1] = (struct tee_param) { .attr = TEE_IOCTL_PARAM_ATTR_TYPE_MEMREF_INOUT, @@ -158,17 +129,20 @@ static int ftpm_tee_tpm_op_send(struct tpm_chip *chip, u8 *buf, size_t len, __func__, resp_len); return -EIO; } + if (resp_len > buf_size) { + dev_err(&chip->dev, + "%s: resp_len=%zd exceeds buf_size=%zd\n", + __func__, resp_len, buf_size); + return -EIO; + } - /* sanity checks look good, cache the response */ - memcpy(pvt_data->resp_buf, temp_buf, resp_len); - pvt_data->resp_len = resp_len; + memcpy(buf, temp_buf, resp_len); - return 0; + return resp_len; } static const struct tpm_class_ops ftpm_tee_tpm_ops = { .flags = TPM_OPS_AUTO_STARTUP, - .recv = ftpm_tee_tpm_op_recv, .send = ftpm_tee_tpm_op_send, }; @@ -253,7 +227,7 @@ static int ftpm_tee_probe(struct device *dev) } pvt_data->chip = chip; - pvt_data->chip->flags |= TPM_CHIP_FLAG_TPM2; + pvt_data->chip->flags |= TPM_CHIP_FLAG_TPM2 | TPM_CHIP_FLAG_SYNC; /* Create a character device for the fTPM */ rc = tpm_chip_register(pvt_data->chip); From patchwork Tue Apr 8 08:32:08 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 14042397 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 117062185B8 for ; Tue, 8 Apr 2025 08:32:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744101157; cv=none; b=piEPz6QUFQBxADk+OzIULlhaz28gXaExCy8LPC319ENx/wiDdtpglMB6KyFIW9hgjJpgyG4ECZV9uhRoCchWf/xgEK1Zo6frrVard/JJgeKiSizw7E9GDhacswzOpIrnCYinPmbk1d1TrfHzX8BJavi27wWvIL7VbonMcfMpdwc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744101157; c=relaxed/simple; bh=dUF2TBEutX2KGJiQNuMfxIqRjcPoQb9fYtWfjZ52S5A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OnEcd3J+vySRmCbz3Ytn2Md95yOXL9I1yJEEVlCkpoGDpIJx41SxRisbeoxRtsGZCmdeIPP8hIhtfjH4XvRhK46/ZBQ6Uhr8MP/8JJtUxLtnxupcnM8c/L7SdNK/pv5n+IOIyoCLyqeviO/BkIUzvYQOJ0ETSPnDw7JNnC6zuDw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=MS5Jnv/t; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="MS5Jnv/t" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1744101153; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+UWgpwscQp73PyDMRD5EZKbcQGdo2l2UKgmDSHNPifY=; b=MS5Jnv/tvC2qH9QsF8wHAoyeYxPPj6MrI0UxHZt+hZMqX6cwVr1OB4iJZcCbAsolkUrpg8 bQEK8Dm/McrHeGIv2hy/iseI9R+KTvk8u6PkJpPieA3uTx5IFauEGv7b3zKrDUvGh/kJ+G aSmBGL/TDFGjZrbqtgipBxcUOFFN9hY= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-414-DVg_As4BOCiHYVfHMXl_Fg-1; Tue, 08 Apr 2025 04:32:32 -0400 X-MC-Unique: DVg_As4BOCiHYVfHMXl_Fg-1 X-Mimecast-MFC-AGG-ID: DVg_As4BOCiHYVfHMXl_Fg_1744101151 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-43cfda30a3cso31308305e9.3 for ; Tue, 08 Apr 2025 01:32:32 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744101151; x=1744705951; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+UWgpwscQp73PyDMRD5EZKbcQGdo2l2UKgmDSHNPifY=; b=HTW2rl1BbzoWfLDDjtPqZJ8hBjh+3NR7FpKsZp+0RlFPBHpN4GpV81a/DKyaWgvFVI nd4uOqLPmlpytjg4pD3cSGi+DNq77brpG8aVrEH8wqMEre41AhsJiLpiFyURksoTtPKe H7xTL99zxGpqyapk8IGSDI4vIsy9mYT049507IfxnWC+0sS8jq7t6b8/WdzaqHccpZV9 jlq0nun1tOuOKyUfWKrw0BxHqp4bUjm+igr484nQBir0YMKvppapT5ZQP81qZA8yhTLC b6t8+a3Zc9xcibMx76tMYJ0INH+xmpbVbBR2U8vbO1g8kkreYGmx1CniAhxXqEuSdvik l2PQ== X-Forwarded-Encrypted: i=1; AJvYcCWqjHJqdgmeYQ0t/0Me2pY9kg6MDPxw1UG8fShglNTPpg9fpYklhYR+y9lCHozX43Gy5G6ICMpGawvXGjS5JhY=@vger.kernel.org X-Gm-Message-State: AOJu0YxToTRQzOiuIJKjyyUEiUWeJsKcquqjPaIbX0eYWTpoBUdqJIS1 jIL0csq38u+O2jcLajE5gBitQ4iKNxrChxajd5Jm1exvg1U7lHLdHaG/aaoGkouErRDE5vxhR4N u+I7UHiLC7e/61nJSfO5bEpLn+aiaM4Xt6CE+U1dig4g4cUAV3V9tQ9zPt7u0Qmevew== X-Gm-Gg: ASbGncsrU1+w8JQmBKR/Efz4q/Np3avcJaSjaaEOaSvw+gbqZSqkoKyjY0hcLSxGBkd cFPTGSizWmdIVuz7Ih2sG3D6dVY23wC+eeXN0BYokgLFUIAudLJuYrwG56avy4sIXwjFSXlXa9D OH0hhdXyU6mhXfu6Dudj8xab6pdrKZQkxjDqXOwRMU1q83WaWaKL+mO5cJSf3qXmh9pTZ/A2Deg cJWHbYO46Yv6+JY1ZE8rPb7oz51o81HxI3uCg25PwuKgjxAjrsRIxU9kTIYIRWjfMbOBqb2hLv1 2xz1uz+Bd7NFFa6LXs0BrLhRTAWGiv7yQL4f4Ga2/0eenCElPIGt2tTJPgtd/IYpLg== X-Received: by 2002:a05:600c:1384:b0:43c:fffc:7886 with SMTP id 5b1f17b1804b1-43ecf85f216mr158235485e9.8.1744101151416; Tue, 08 Apr 2025 01:32:31 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHz2ZKXaEi+HUCetPqQ0pAcpS8InkZmoD9d7JUgJGma+dknJFHnGD8z9oUR2s/51/65NGDLdw== X-Received: by 2002:a05:600c:1384:b0:43c:fffc:7886 with SMTP id 5b1f17b1804b1-43ecf85f216mr158235025e9.8.1744101150843; Tue, 08 Apr 2025 01:32:30 -0700 (PDT) Received: from stex1.redhat.com (host-79-53-30-213.retail.telecomitalia.it. [79.53.30.213]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43ec17b1352sm154886505e9.37.2025.04.08.01.32.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Apr 2025 01:32:30 -0700 (PDT) From: Stefano Garzarella To: Jarkko Sakkinen Cc: Alexandre Belloni , Nicolas Ferre , linux-kernel@vger.kernel.org, Claudiu Beznea , linux-arm-kernel@lists.infradead.org, Jens Wiklander , linuxppc-dev@lists.ozlabs.org, Michael Ellerman , Sumit Garg , Christophe Leroy , linux-integrity@vger.kernel.org, Jason Gunthorpe , Madhavan Srinivasan , Naveen N Rao , Nicholas Piggin , Peter Huewe , James Bottomley , Stefano Garzarella Subject: [PATCH v2 4/4] tpm/tpm_svsm: support TPM_CHIP_FLAG_SYNC Date: Tue, 8 Apr 2025 10:32:08 +0200 Message-ID: <20250408083208.43512-5-sgarzare@redhat.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250408083208.43512-1-sgarzare@redhat.com> References: <20250408083208.43512-1-sgarzare@redhat.com> Precedence: bulk X-Mailing-List: linux-integrity@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Stefano Garzarella This driver does not support interrupts, and receiving the response is synchronous with sending the command. So we can set TPM_CHIP_FLAG_SYNC to support synchronous send() and return responses in the same buffer used for commands. This way we don't need to implement recv() op. Keep using the same pre-allocated buffer to avoid having to allocate it for each command. We need the buffer to have the header required by the SVSM protocol and the command contiguous in memory. Signed-off-by: Stefano Garzarella --- drivers/char/tpm/tpm_svsm.c | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/drivers/char/tpm/tpm_svsm.c b/drivers/char/tpm/tpm_svsm.c index b8aa7eb567de..547d4c4f7a53 100644 --- a/drivers/char/tpm/tpm_svsm.c +++ b/drivers/char/tpm/tpm_svsm.c @@ -25,38 +25,32 @@ struct tpm_svsm_priv { void *buffer; }; -static int tpm_svsm_send(struct tpm_chip *chip, u8 *buf, size_t len, +static int tpm_svsm_send(struct tpm_chip *chip, u8 *buf, size_t cmd_len, size_t buf_size) { struct tpm_svsm_priv *priv = dev_get_drvdata(&chip->dev); int ret; - ret = svsm_vtpm_cmd_request_fill(priv->buffer, 0, buf, len); + ret = svsm_vtpm_cmd_request_fill(priv->buffer, 0, buf, cmd_len); if (ret) return ret; /* * The SVSM call uses the same buffer for the command and for the - * response, so after this call, the buffer will contain the response - * that can be used by .recv() op. + * response, so after this call, the buffer will contain the response. + * + * Note: we have to use an internal buffer because the device in SVSM + * expects the svsm_vtpm header + data to be physically contiguous. */ - return snp_svsm_vtpm_send_command(priv->buffer); -} - -static int tpm_svsm_recv(struct tpm_chip *chip, u8 *buf, size_t len) -{ - struct tpm_svsm_priv *priv = dev_get_drvdata(&chip->dev); + ret = snp_svsm_vtpm_send_command(priv->buffer); + if (ret) + return ret; - /* - * The internal buffer contains the response after we send the command - * to SVSM. - */ - return svsm_vtpm_cmd_response_parse(priv->buffer, buf, len); + return svsm_vtpm_cmd_response_parse(priv->buffer, buf, buf_size); } static struct tpm_class_ops tpm_chip_ops = { .flags = TPM_OPS_AUTO_STARTUP, - .recv = tpm_svsm_recv, .send = tpm_svsm_send, }; @@ -88,6 +82,7 @@ static int __init tpm_svsm_probe(struct platform_device *pdev) dev_set_drvdata(&chip->dev, priv); + chip->flags |= TPM_CHIP_FLAG_SYNC; err = tpm2_probe(chip); if (err) return err;