From patchwork Tue Mar 11 10:01:28 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 14011428 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 251451E2606 for ; Tue, 11 Mar 2025 10:01:49 +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=1741687311; cv=none; b=BB9g2IFzMSmnWfRzxd7kneZm8HapS2zao/cMkv88g6LxZqZqpP02ZkxSSB7qbuuzyEql+qmWrAP911entwURAk9PjeODdOrm7/ft9s79y8s9FzTUAWkCiZaIkWRnw95BwFvDkxLfPEYtcnecjE4T1n05CaW837LybhCfiS1zbks= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741687311; c=relaxed/simple; bh=tmLfihRSJ8aDEwLZQLrfPa2kgVJ8yB6EH9+mM+3ad6o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YvvPtSqU1ML3TZ2cZ9Wxc/4NgtLnKIOF0z+xYxF2+pwOnSMvZhhnU8R+RtQDI5DuxLS1ajDGmMn5dJzdjlVjTeAySdkiGzFz3xXDXd6mjb30gAvwPVpfDNVKJJEszKqsJrA3GcteD/MzO1x8bVIZn+U8Htnv7idmxr1RqTJwZoM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none 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=KFz1DLLO; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none 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="KFz1DLLO" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1741687309; 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=t42YH129GwFgWuMlejLOiuh/mbs5CWsg7YDBlF++gYY=; b=KFz1DLLOAn9vKbjdA8kP8TbSm+qvT1tHmxXQSnLlRswEwCuh3P8YCG202H3kcJH+3zhsGO ocVDSBE3geKsU19QjJcLwDbRtb9NyfNyBQnr1713+GmXnH/E+4j2AwEF0b7YG8gvOMmSDE ODF8oAc59jywwlsfXvjJWo+RZ4sFWmU= Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-658-DWDvL6ICNW-nIW9NGXE-zQ-1; Tue, 11 Mar 2025 06:01:47 -0400 X-MC-Unique: DWDvL6ICNW-nIW9NGXE-zQ-1 X-Mimecast-MFC-AGG-ID: DWDvL6ICNW-nIW9NGXE-zQ_1741687306 Received: by mail-ej1-f71.google.com with SMTP id a640c23a62f3a-ac1e442740cso478998966b.1 for ; Tue, 11 Mar 2025 03:01:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741687306; x=1742292106; 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=t42YH129GwFgWuMlejLOiuh/mbs5CWsg7YDBlF++gYY=; b=nZHIVEJuNQRH8O2EwdXDRYicyk7fyMbw17tD2sYyfQVcSutCRYctPd3ktk5aB55aFp FLWjQUy36CUZhbNUmjq5di3YHUES+mX63CeqRFpMPYKyJvlXUGMxF/aZX8emMzRcNppa EtGR/nz8KxCry/b3JiYQDDoAAXP3Y7U9BwlnPklu0/qDpcAsvNNTDyQrb3Cxp5TLafHF PMof6Zg1ixqzPoWzLFI93E6agPzwtIGeTVvA9057G5BGYhWmaFd2vTj+U+3yXqyV2P3X FPcgA4Kv8n7W0LNlPKagb5DoRIRO6grHU7osMPcxBqlIkKc4QTWwIYCEsIy+s5VtB3mL UBag== X-Gm-Message-State: AOJu0YxNwrV8ef8S5YzTyisB7oghRi1zT0advqPjPeH1S8Sq6Ybx8aYD v2cEq0y8ZB0UvB1TpJh1Z92QeMXNFLfeluIqikxYBqtnRQ95zPjn9yUK+oQPtCLVvdGg8xem5zj /KUN3puP9jMssCIa+1osmVS1o7821Ytg8SyM6c6xTtS9dTQMgxNCiA+XxNOMpfLnnAw== X-Gm-Gg: ASbGncsnReaLrDl+bt/++xB8FGaisggigl8t/WDwlPYbcReNENDGQxfqMfasR+n+WHe ylHG1xJOcClBDgvjiF5xremCMX+p42k5FeJ2JRvG8oQtgSGuWfHdWxUT2/rOrTxQ5QCiXTW7Ung uS7lPWe60QNELvm6eT1oGBC1azld23lfvQO8BObQ+o1GERWKmaVCL5DUifR2pGBaQ9UBO8Wliqc Mdde3FOda0jVM3tB0RsTWukxmT4VJeoWjjs7Uq1Wzize6LhzOXqXWj3PYBNHxJE2/RU1JW7Lnaf dhVG8Zs7CH+gCqh8nZIWFINOd+sINF+Ag8dpaFfQqWGm+oL/qcg47osPmy1lHjGG7d8p6VZb X-Received: by 2002:a17:907:828a:b0:ac2:c424:c316 with SMTP id a640c23a62f3a-ac2c424cd75mr129985666b.57.1741687306210; Tue, 11 Mar 2025 03:01:46 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFMJt108SROCVxYPGya/bj/Hfjcf3W0nRTrMsVifumnlQBsPRx2yIzQLmb7aDWeXBKljmIlkw== X-Received: by 2002:a17:907:828a:b0:ac2:c424:c316 with SMTP id a640c23a62f3a-ac2c424cd75mr129971366b.57.1741687304300; Tue, 11 Mar 2025 03:01:44 -0700 (PDT) Received: from localhost.localdomain (host-79-46-200-29.retail.telecomitalia.it. [79.46.200.29]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ac27d922c58sm519476466b.40.2025.03.11.03.01.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Mar 2025 03:01:43 -0700 (PDT) From: Stefano Garzarella To: Jarkko Sakkinen Cc: linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, James Bottomley , Peter Huewe , Jason Gunthorpe , Stefano Garzarella Subject: [RFC PATCH 1/3] tpm: add send_recv() op in tpm_class_ops Date: Tue, 11 Mar 2025 11:01:28 +0100 Message-ID: <20250311100130.42169-2-sgarzare@redhat.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250311100130.42169-1-sgarzare@redhat.com> References: <20250311100130.42169-1-sgarzare@redhat.com> Precedence: bulk X-Mailing-List: linux-integrity@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Some devices do not support interrupts and provide a single operation to send the command and receive the response on the same buffer. To support this scenario, a driver could set TPM_CHIP_FLAG_IRQ in the chip's flags to get recv() to be called immediately after send() in tpm_try_transmit(), or it needs to implement .status() to return 0, and set both .req_complete_mask and .req_complete_val to 0. In order to simplify these drivers and avoid temporary buffers to be used between the .send() and .recv() callbacks, introduce a new callback send_recv(). If that callback is defined, it is called in tpm_try_transmit() to send the command and receive the response on the same buffer in a single call. Suggested-by: Jason Gunthorpe Signed-off-by: Stefano Garzarella --- include/linux/tpm.h | 2 ++ drivers/char/tpm/tpm-interface.c | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/include/linux/tpm.h b/include/linux/tpm.h index 20a40ade8030..9baf10240a3d 100644 --- a/include/linux/tpm.h +++ b/include/linux/tpm.h @@ -88,6 +88,8 @@ struct tpm_class_ops { 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_recv)(struct tpm_chip *chip, u8 *buf, size_t buf_len, + size_t cmd_len); 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/tpm-interface.c b/drivers/char/tpm/tpm-interface.c index b1daa0d7b341..9a6e4b320a8f 100644 --- a/drivers/char/tpm/tpm-interface.c +++ b/drivers/char/tpm/tpm-interface.c @@ -82,6 +82,12 @@ static ssize_t tpm_try_transmit(struct tpm_chip *chip, void *buf, size_t bufsiz) return -E2BIG; } + if (chip->ops->send_recv) { + rc = 0; + len = chip->ops->send_recv(chip, buf, bufsiz, count); + goto out_send_recv; + } + rc = chip->ops->send(chip, buf, count); if (rc < 0) { if (rc != -EPIPE) @@ -124,6 +130,7 @@ static ssize_t tpm_try_transmit(struct tpm_chip *chip, void *buf, size_t bufsiz) out_recv: len = chip->ops->recv(chip, buf, bufsiz); +out_send_recv: if (len < 0) { rc = len; dev_err(&chip->dev, "tpm_transmit: tpm_recv: error %d\n", rc); From patchwork Tue Mar 11 10:01:29 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 14011429 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 CF1C0231A24 for ; Tue, 11 Mar 2025 10:01:52 +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=1741687314; cv=none; b=nJuPEwyUSsadpf94auCB9zpARCzuoIHkjZEGDIhp29izvkk8kGR7xOAVdO412RP+tNf0LkeGmai+lI0uZzJyBC9MJa88XI2a9bg4j1RfjZ7v0pNlXjX2+E43U5Fsozrdaey7FyUvPJ07VCEKRW0cg4k/4KyjQCH31E1jIHqPHvA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741687314; c=relaxed/simple; bh=Jm2/ux1vKHax2qopOtD5cqQYVayOaqNeh+rZVk6cOwM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MX1HE5xWA3E0aKaWU9wgNuX2Fuzgpbz72ikqBrnuKNUNzpH27zYt5ZwTFi5dHRqam96PqhLZaIl5oyMzqZKDm9SqYWE/umV53OQuK3yxjWQYLU1RYQ29xwWRsUFz6kT13YHCp40osW7EQOy0f6ERbXGNRCvZLgV4q03lPZ6Qsxc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none 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=GZ6wp+tB; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none 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="GZ6wp+tB" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1741687312; 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=KPPKTGvTQZd77Cs+WjdLnlEj4HAhCixTZCeAE7Dlt2w=; b=GZ6wp+tBjnV7bd4i6Q4NEZ1cRfKUNZP4YaDUJ2/1v9r1/ViJi15xOLUhVGlkQRHTsArWwb 1EeDX5zdpUzFo6o1fTDRLZFf54cFaOZZz/hw+ltFYBLjWNbYhJ70syVKspO/wXG9vU2fgR uoG+hHoVVusdQZiUZ5TOAnbm9ttrfdA= Received: from mail-ej1-f70.google.com (mail-ej1-f70.google.com [209.85.218.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-672-JQLKiP5jOh6SvwSr00XTgA-1; Tue, 11 Mar 2025 06:01:50 -0400 X-MC-Unique: JQLKiP5jOh6SvwSr00XTgA-1 X-Mimecast-MFC-AGG-ID: JQLKiP5jOh6SvwSr00XTgA_1741687309 Received: by mail-ej1-f70.google.com with SMTP id a640c23a62f3a-ac297c7a0c2so175327366b.3 for ; Tue, 11 Mar 2025 03:01:50 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741687309; x=1742292109; 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=KPPKTGvTQZd77Cs+WjdLnlEj4HAhCixTZCeAE7Dlt2w=; b=HF1v5TtA5NsuuR4RE8JMaggAOveHPtnKy0jPKLHl3kxz7eHH3ndD9rqj7PTlHOx6nL 8pnNVWStDuVvRHlZPMUH2bJW7jz5O5Xrhxmwkv3LU6qOf8jjix4aHI0+ACqa0f51RCio Xw29+Fl48a/uoMffgYigFxnILL4ptnO1sMEaUnWeyM5dCzXnTCmiu2uG8kvaFl5aKtKf +Ip/zs0w6zoOi14BiF+0+a3ji0l2GBAMGICxwxcE1lPzrR6SP4Fmns8B68TPZv+bxTjK 00Omu/v8Cqy+PJXmZcwWAZwNv1Hc9Yc724w3Eh7CILgNWh2ShGg7QeQNYQoQ4EsadpOR vdHA== X-Gm-Message-State: AOJu0YykNZBNXLttyvpTsIvuTKvFGDWR3KaD+nCQhtqNrLtzc3qu5jwP 2R0J86u8a7klRPHaYJbR7HRNpwYUOAHtA/ETnwIw3Sqq7iTjBQJ4FaMsWqObKucNCidQu/w8IjD 9f52TYk2Y/+WXDA8f3XzAfJ8oAkUEtY8xzKJWg5VRYYewmED5+w3ma8pAEbhBKNxYJw== X-Gm-Gg: ASbGnctdKEBArANkQbVr52vVKkvXpA8oyZCkVKTH0eo6GqlM9y8Vd2gDtRYfQHvCJaa Zj3P3sjS5VKlgiqr3NnMjjnMAtuaUXGx61ovJVHyt0DyNUUbelN6oc9i3uWMSU2w36/tywTioQA DxFF5BMch5HnAUlYkNzrxoMOpXz28GRiwoS9BWQ7VQ3OLLx2AtVoNczVixW07XMhEibbKIeuQmh 6zJOIg1jScA+GAeBtxYcVZ/Dxqz15gtK7mcf3iMx/WRd7z0PcNYRA93wPh8fXbqoUovcGZw4VmQ 4ephEoC2cWM8BPM8FN3QX3Zfhe1JdGnY6vVo8t17XnkA5HFT43C+ss8wkQ7ukB3P9TuIE+u8 X-Received: by 2002:a17:907:7213:b0:abf:6f87:c732 with SMTP id a640c23a62f3a-ac2b9de96d4mr330695166b.20.1741687309277; Tue, 11 Mar 2025 03:01:49 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEbKu5HMA42qiS6MJ30Na3MKSdLChwgJ/VZYOOUxT/L4wbU6L/bdxGQ/p9i7lzsXp61vSa7QA== X-Received: by 2002:a17:907:7213:b0:abf:6f87:c732 with SMTP id a640c23a62f3a-ac2b9de96d4mr330685666b.20.1741687308530; Tue, 11 Mar 2025 03:01:48 -0700 (PDT) Received: from localhost.localdomain (host-79-46-200-29.retail.telecomitalia.it. [79.46.200.29]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ac296527b70sm382964466b.58.2025.03.11.03.01.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Mar 2025 03:01:47 -0700 (PDT) From: Stefano Garzarella To: Jarkko Sakkinen Cc: linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, James Bottomley , Peter Huewe , Jason Gunthorpe , Stefano Garzarella Subject: [RFC PATCH 2/3] tpm/tpm_ftpm_tee: use send_recv() op Date: Tue, 11 Mar 2025 11:01:29 +0100 Message-ID: <20250311100130.42169-3-sgarzare@redhat.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250311100130.42169-1-sgarzare@redhat.com> References: <20250311100130.42169-1-sgarzare@redhat.com> Precedence: bulk X-Mailing-List: linux-integrity@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 This driver does not support interrupts, and receiving the response is synchronous with sending the command. It used an internal buffer to cache the response when .send() is called, and then return it when .recv() is called. Let's simplify the driver by implementing the new send_recv() op, so that we can also remove the 4KB internal buffer used to cache the response. Signed-off-by: Stefano Garzarella Tested-by: Jens Wiklander --- Note: I don't know how to test this driver, so I just build it. If someone can test it, or tell me how to do, it will be great! --- drivers/char/tpm/tpm_ftpm_tee.h | 4 -- drivers/char/tpm/tpm_ftpm_tee.c | 86 ++++++++------------------------- 2 files changed, 21 insertions(+), 69 deletions(-) diff --git a/drivers/char/tpm/tpm_ftpm_tee.h b/drivers/char/tpm/tpm_ftpm_tee.h index f98daa7bf68c..72b2f5c41274 100644 --- a/drivers/char/tpm/tpm_ftpm_tee.h +++ b/drivers/char/tpm/tpm_ftpm_tee.h @@ -23,16 +23,12 @@ * @chip: struct tpm_chip instance registered with tpm framework. * @state: internal state * @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 139556b21cc6..f0393d843780 100644 --- a/drivers/char/tpm/tpm_ftpm_tee.c +++ b/drivers/char/tpm/tpm_ftpm_tee.c @@ -31,45 +31,19 @@ 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_recv() - 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. + * @buf_len: the size of the buffer. + * @cmd_len: the number of bytes to send. * * 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_recv(struct tpm_chip *chip, u8 *buf, + size_t buf_len, size_t cmd_len) { struct ftpm_tee_private *pvt_data = dev_get_drvdata(chip->dev.parent); size_t resp_len; @@ -80,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) { @@ -103,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, }, }; @@ -115,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, @@ -156,38 +129,21 @@ 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_len) { + dev_err(&chip->dev, + "%s: Invalid size in recv: buf_len=%zd, resp_len=%zd\n", + __func__, buf_len, resp_len); + return -EIO; + } - /* sanity checks look good, cache the response */ - memcpy(pvt_data->resp_buf, temp_buf, resp_len); - pvt_data->resp_len = resp_len; - - return 0; -} - -static void ftpm_tee_tpm_op_cancel(struct tpm_chip *chip) -{ - /* not supported */ -} - -static u8 ftpm_tee_tpm_op_status(struct tpm_chip *chip) -{ - return 0; -} + memcpy(buf, temp_buf, resp_len); -static bool ftpm_tee_tpm_req_canceled(struct tpm_chip *chip, u8 status) -{ - return false; + 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, - .cancel = ftpm_tee_tpm_op_cancel, - .status = ftpm_tee_tpm_op_status, - .req_complete_mask = 0, - .req_complete_val = 0, - .req_canceled = ftpm_tee_tpm_req_canceled, + .send_recv = ftpm_tee_tpm_op_send_recv, }; /* From patchwork Tue Mar 11 10:01:30 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 14011430 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 61D0822D7A5 for ; Tue, 11 Mar 2025 10:01:58 +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=1741687319; cv=none; b=uB0Rzg/WjyB3Y8wJwag9I649NVdzjO837xCxdDlc5EJCVqaI39z8e3Jz5YLoqllXpgJFTIOpHpSUUQIeTtFhhzspbSySfEpjj47eOI/iMFP9ZHCiyulqtupoyuQeSUdgyOvsPwAiVfQH9JzrCtC34ARKXIaF/98zPsWj+Vq/fIo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741687319; c=relaxed/simple; bh=NPMtqpwCVKN/t6dM0TTZRO7xhNc09lkELwdXpym2pPg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YJQf9dRf9x8NKd6hi+pFzs1Mbvj34fs5IVnJI71A2xmzyPWvsaLoY8HLL/RdctGHK2eUJzvch8Urg37KDiFswZOZRat9/PToXTYyWCfeqImEBlmFyYu9S8CPC6jaEfWn84DaF90PVbfzRYtQhorWgrnKT2y18eDAwinKePH6EjA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none 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=dKEoMRHt; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none 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="dKEoMRHt" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1741687317; 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=R8AbLV0QZow5eKDSyCJQccGErTMPbE7El3aX8DLCI50=; b=dKEoMRHtY5l+u5n4ebz/9gbHaQvXcXsQm48ve2hivKIaXDoe43C636D53uU8PTTQDZ6USh FJQi+nf8SHXQG5ANeLsslumYue6N3EUWNQ3QFQH5EItpY4/xRrCoU/7T5ENpq8bz724se4 8Ex+0yw054/cPFAqFQzboQxwldXGw3U= Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-154-h2rD0jODNRqH-aLwZNJ1Lw-1; Tue, 11 Mar 2025 06:01:55 -0400 X-MC-Unique: h2rD0jODNRqH-aLwZNJ1Lw-1 X-Mimecast-MFC-AGG-ID: h2rD0jODNRqH-aLwZNJ1Lw_1741687315 Received: by mail-ej1-f69.google.com with SMTP id a640c23a62f3a-ac29ae0b2fbso203066966b.0 for ; Tue, 11 Mar 2025 03:01:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741687315; x=1742292115; 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=R8AbLV0QZow5eKDSyCJQccGErTMPbE7El3aX8DLCI50=; b=UTAYSTq7dSSE2JanfWbDI43FcPMeCLYbPVWC/liGkksYNkxMCmKotpEzH9dmApWZO9 6PZIy8OKBrt/FV8ArQujKheIeGfmA7ao7qGyFo30K/kO1MHYFnxEPmDUveY5V//nZvOp LznxVAPOWbqsGS6i4WYMUbAC+bDsgaydO41o3jmvqQ7TosqOoKMyojRu0d/0BxnoVhyC OwhuvgPOquudjU/Wv+Ln1VFILaAUBJrM4zNyqhAKn3IzvrxvruG0+ZNh3uNHdkr6EGP9 3nUP30jUZy4wbvwU/weRSZ4Xn4I8Uf2IX8FvR42t6P+Gg/BgtxY1rP0NUZ6fPgIDdS9R 1z/A== X-Gm-Message-State: AOJu0YwX1CPvjwCgSSrD3tzP/x5oQoRrcUEF6cJZCmlesHMkHuvvHgQf 6z2gvJ5dq7Jt0hGqY5lwNDAFNuyEvUQCi1iEC/e2H103fYf9ZlcPz1wVKDkD9cOpBUtTxkHIEBi yDPIXRZHr1KTigVyB0lRWWy1ghd4XNo/oZ0PcpIR5M5bBnJlNilYd0V5v1LgKERueWQ== X-Gm-Gg: ASbGncuitJtjJkuwJwvLG5alqOvH9hZTcXHkrV64WNlb55Hu2tc88AzG6i+CwB6Ab+U kSzsrju/kNMMjNh4ZpyTp4bRDVhWJ+P/ryRoBatXBWWZEoYJXXnvgucL8CcEvse9rk9ODySjIAr MFW/mfuyTLvCC/8TmKedQ1VoIOowVQ/25mOkz069atU1f1mt9fPtKY/JUuk9GXWN3TOdE8dx8cA zXWXgF/bAjHDPK6JC7Y9IgOdunIxP80MtSE+Lx+8lvNBEI59FuX7azEDe22GCGL/hYyA7EvSfC0 1/M7TOBYSksrUQwc1sWfnueiVBcaFxwY+qPdJ5p2nXtPbs+6sBEaPBOyfcEg5rD4ebK81W6I X-Received: by 2002:a17:906:f589:b0:abf:d4a9:a0a5 with SMTP id a640c23a62f3a-ac252f8e28fmr1854096966b.45.1741687314608; Tue, 11 Mar 2025 03:01:54 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGQ38gLVsp3SfDC4i23YFLhiD4lGnf7z9JZYc5KUOq4ySpfuIH/T3U1+SixSbQ8V0WVV7O7aA== X-Received: by 2002:a17:906:f589:b0:abf:d4a9:a0a5 with SMTP id a640c23a62f3a-ac252f8e28fmr1854092166b.45.1741687313983; Tue, 11 Mar 2025 03:01:53 -0700 (PDT) Received: from localhost.localdomain (host-79-46-200-29.retail.telecomitalia.it. [79.46.200.29]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ac239485d55sm903426166b.67.2025.03.11.03.01.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Mar 2025 03:01:52 -0700 (PDT) From: Stefano Garzarella To: Jarkko Sakkinen Cc: linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, James Bottomley , Peter Huewe , Jason Gunthorpe , Stefano Garzarella Subject: [RFC PATCH 3/3] tpm/tpm_svsm: use send_recv() op Date: Tue, 11 Mar 2025 11:01:30 +0100 Message-ID: <20250311100130.42169-4-sgarzare@redhat.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250311100130.42169-1-sgarzare@redhat.com> References: <20250311100130.42169-1-sgarzare@redhat.com> Precedence: bulk X-Mailing-List: linux-integrity@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 This driver does not support interrupts, and receiving the response is synchronous with sending the command. Let's simplify the driver by implementing the new send_recv() op. Signed-off-by: Stefano Garzarella --- Note: this is based on "[PATCH v3 0/4] Enlightened vTPM support for SVSM on SEV-SNP" series [1]. If we will merge this series before it, we can just ignore this patch and I'll squash these changes in that series. [1] https://lore.kernel.org/linux-integrity/20250311094225.35129-1-sgarzare@redhat.com/ --- drivers/char/tpm/tpm_svsm.c | 46 ++++++++----------------------------- 1 file changed, 9 insertions(+), 37 deletions(-) diff --git a/drivers/char/tpm/tpm_svsm.c b/drivers/char/tpm/tpm_svsm.c index 5540d0227eed..63208313f86e 100644 --- a/drivers/char/tpm/tpm_svsm.c +++ b/drivers/char/tpm/tpm_svsm.c @@ -25,60 +25,32 @@ struct tpm_svsm_priv { u8 locality; }; -static int tpm_svsm_send(struct tpm_chip *chip, u8 *buf, size_t len) +static int tpm_svsm_send_recv(struct tpm_chip *chip, u8 *buf, size_t buf_len, + size_t cmd_len) { struct tpm_svsm_priv *priv = dev_get_drvdata(&chip->dev); int ret; ret = svsm_vtpm_fill_cmd_req((struct tpm_send_cmd_req *)priv->buffer, - priv->locality, buf, len); + priv->locality, 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. */ - 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_parse_cmd_resp((struct tpm_send_cmd_resp *)priv->buffer, - buf, len); -} - -static void tpm_svsm_cancel(struct tpm_chip *chip) -{ - /* not supported */ -} - -static u8 tpm_svsm_status(struct tpm_chip *chip) -{ - return 0; -} - -static bool tpm_svsm_req_canceled(struct tpm_chip *chip, u8 status) -{ - return false; + buf, buf_len); } static struct tpm_class_ops tpm_chip_ops = { .flags = TPM_OPS_AUTO_STARTUP, - .recv = tpm_svsm_recv, - .send = tpm_svsm_send, - .cancel = tpm_svsm_cancel, - .status = tpm_svsm_status, - .req_complete_mask = 0, - .req_complete_val = 0, - .req_canceled = tpm_svsm_req_canceled, + .send_recv = tpm_svsm_send_recv, }; static int __init tpm_svsm_probe(struct platform_device *pdev)