From patchwork Wed Dec 11 20:27:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Berger X-Patchwork-Id: 1207905 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47Y7ns173kz9sRH for ; Thu, 12 Dec 2019 07:29:37 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.vnet.ibm.com Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 47Y7nr61bnzDqYh for ; Thu, 12 Dec 2019 07:29:36 +1100 (AEDT) X-Original-To: slof@lists.ozlabs.org Delivered-To: slof@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=linux.vnet.ibm.com (client-ip=148.163.158.5; helo=mx0a-001b2d01.pphosted.com; envelope-from=stefanb@linux.vnet.ibm.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.vnet.ibm.com Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 47Y7ll5Y56zDqJc for ; Thu, 12 Dec 2019 07:27:44 +1100 (AEDT) Received: from pps.filterd (m0098414.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id xBBKGgtj028872; Wed, 11 Dec 2019 15:27:41 -0500 Received: from ppma05wdc.us.ibm.com (1b.90.2fa9.ip4.static.sl-reverse.com [169.47.144.27]) by mx0b-001b2d01.pphosted.com with ESMTP id 2wu4t6d3s8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Dec 2019 15:27:41 -0500 Received: from pps.filterd (ppma05wdc.us.ibm.com [127.0.0.1]) by ppma05wdc.us.ibm.com (8.16.0.27/8.16.0.27) with SMTP id xBBKEuaP026508; Wed, 11 Dec 2019 20:27:40 GMT Received: from b01cxnp22033.gho.pok.ibm.com (b01cxnp22033.gho.pok.ibm.com [9.57.198.23]) by ppma05wdc.us.ibm.com with ESMTP id 2wtdq7b85k-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Dec 2019 20:27:40 +0000 Received: from b01ledav003.gho.pok.ibm.com (b01ledav003.gho.pok.ibm.com [9.57.199.108]) by b01cxnp22033.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id xBBKReMx45416840 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 11 Dec 2019 20:27:40 GMT Received: from b01ledav003.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6BB65B205F; Wed, 11 Dec 2019 20:27:40 +0000 (GMT) Received: from b01ledav003.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5E60AB206B; Wed, 11 Dec 2019 20:27:40 +0000 (GMT) Received: from newfield.pok.ibm.com (unknown [9.47.158.66]) by b01ledav003.gho.pok.ibm.com (Postfix) with ESMTP; Wed, 11 Dec 2019 20:27:40 +0000 (GMT) From: Stefan Berger To: slof@lists.ozlabs.org Date: Wed, 11 Dec 2019 15:27:08 -0500 Message-Id: <20191211202728.127996-14-stefanb@linux.vnet.ibm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191211202728.127996-1-stefanb@linux.vnet.ibm.com> References: <20191211202728.127996-1-stefanb@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.95, 18.0.572 definitions=2019-12-11_06:2019-12-11, 2019-12-11 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 bulkscore=0 impostorscore=0 spamscore=0 clxscore=1015 suspectscore=15 mlxscore=0 mlxlogscore=999 malwarescore=0 adultscore=0 phishscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-1910280000 definitions=main-1912110168 Subject: [SLOF] [PATCH v4 13/33] tpm: Add TPM firmware API call pass-through-to-tpm X-BeenThere: slof@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Patches for https://github.com/aik/SLOF" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kevin@koconnor.net MIME-Version: 1.0 Errors-To: slof-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "SLOF" This patch adds support for the firmware API call pass-through-to-tpm. Signed-off-by: Stefan Berger Reviewed-by: Nikunj A Dadhania --- board-qemu/slof/vio-vtpm-cdriver.fs | 8 +++++ board-qemu/slof/vtpm-sml.fs | 10 ++++++ lib/libtpm/tcgbios.c | 52 +++++++++++++++++++++++++++++ lib/libtpm/tcgbios.h | 1 + lib/libtpm/tpm.code | 11 ++++++ lib/libtpm/tpm.in | 1 + lib/libtpm/tpm_drivers.h | 3 ++ 7 files changed, 86 insertions(+) diff --git a/board-qemu/slof/vio-vtpm-cdriver.fs b/board-qemu/slof/vio-vtpm-cdriver.fs index de69e2d..0699c4d 100644 --- a/board-qemu/slof/vio-vtpm-cdriver.fs +++ b/board-qemu/slof/vio-vtpm-cdriver.fs @@ -122,6 +122,14 @@ false VALUE vtpm-debug? THEN ; +\ firmware API call +: pass-through-to-tpm ( buf-addr buf-size -- response-size ) + " pass-through-to-tpm" vtpm-call-forward IF + 2drop + 0 + THEN +; + \ firmware API call : get-maximum-cmd-size ( -- maximum-size ) " get-maximum-cmd-size" vtpm-call-forward IF diff --git a/board-qemu/slof/vtpm-sml.fs b/board-qemu/slof/vtpm-sml.fs index bf0d55e..c51765b 100644 --- a/board-qemu/slof/vtpm-sml.fs +++ b/board-qemu/slof/vtpm-sml.fs @@ -94,6 +94,16 @@ log-base LOG-SIZE tpm-set-log-parameters THEN ; +: pass-through-to-tpm ( buf-addr cmd-size -- rsp-size ) + vtpm-debug? IF + ." Call to pass-through-to-tpm" cr + THEN + tpm-pass-through-to-tpm ( rsp-size ) + vtpm-debug? IF + ." VTPM: Return value from tpm-pass-through-to-tpm: " dup . cr + THEN +; + \ \ internal API calls \ diff --git a/lib/libtpm/tcgbios.c b/lib/libtpm/tcgbios.c index 9114d64..38fa545 100644 --- a/lib/libtpm/tcgbios.c +++ b/lib/libtpm/tcgbios.c @@ -837,3 +837,55 @@ uint32_t tpm_get_maximum_cmd_size(void) return MIN(cpu_to_be32(trgb.buffersize), spapr_vtpm_get_buffersize()); } + +static bool pass_through_to_tpm(unsigned char *req, + uint32_t reqlen, + enum tpm_duration_type to_t, + unsigned char *rsp, + uint32_t *rsplen) +{ + struct tpm_req_header *trqh; + int ret; + + if (!tpm_is_working()) + return TCGBIOS_FATAL_COM_ERROR; + + trqh = (struct tpm_req_header *)req; + if (reqlen < sizeof(*trqh)) + return TCGBIOS_INVALID_INPUT_PARA; + + ret = tpmhw_transmit(0, trqh, rsp, rsplen, to_t); + if (ret) + return TCGBIOS_FATAL_COM_ERROR; + + return 0; +} + +/* + * tpm_pass_through_to_tpm: Function for interfacing with the firmware API + * + * buf: buffer holding the command; also used for holding the entire response + * cmdlen: length of the command in the buffer + * + * Returns 0 in case of failure, the size of the response otherwise. + */ +uint32_t tpm_pass_through_to_tpm(unsigned char *buf, uint32_t cmdlen) +{ + uint32_t resplen = PAPR_VTPM_MAX_BUFFER_SIZE; + + /* + * API spec: caller must ensure that the buffer is large + * enough to receive the full response into + * the same buffer where the command is in. + * We anticipate the largest possible buffer + * the driver supports in 'resplen'. + * For duration we use the worst-case timeout 'LONG' + * so that any command can be sent and will not time out. + */ + if (pass_through_to_tpm(buf, cmdlen, + TPM_DURATION_TYPE_LONG, + buf, &resplen)) + return 0; + + return resplen; +} diff --git a/lib/libtpm/tcgbios.h b/lib/libtpm/tcgbios.h index 6eb6751..5beaa53 100644 --- a/lib/libtpm/tcgbios.h +++ b/lib/libtpm/tcgbios.h @@ -35,6 +35,7 @@ uint32_t tpm_measure_bcv_mbr(uint32_t bootdrv, const uint8_t *addr, uint32_t tpm_add_event_separators(uint32_t start_pcr, uint32_t end_pcr); uint32_t tpm_process_opcode(uint8_t op, bool verbose); uint32_t tpm_get_maximum_cmd_size(void); +uint32_t tpm_pass_through_to_tpm(unsigned char *buf, uint32_t cmdlen); /* flags returned by tpm_get_state */ #define TPM_STATE_ENABLED 1 diff --git a/lib/libtpm/tpm.code b/lib/libtpm/tpm.code index ecfba8c..adf1f01 100644 --- a/lib/libtpm/tpm.code +++ b/lib/libtpm/tpm.code @@ -172,3 +172,14 @@ PRIM(tpm_X2d_get_X2d_maximum_X2d_cmd_X2d_size) PUSH; TOS.n = tpm_get_maximum_cmd_size(); MIRP + +/*******************************************************************/ +/* Firmware API */ +/* SLOF: tpm-pass-through-to-tpm (buf-addr cmd-size -- rsp-size) */ +/* LIBTPM: respsize = tpm_pass_through_to_tpm(buf, cmdsize) */ +/*******************************************************************/ +PRIM(tpm_X2d_pass_X2d_through_X2d_to_X2d_tpm) + int cmdsize = TOS.n; POP; + void *buf = TOS.a; + TOS.n = tpm_pass_through_to_tpm(buf, cmdsize); +MIRP diff --git a/lib/libtpm/tpm.in b/lib/libtpm/tpm.in index 1bd393e..f0c92e2 100644 --- a/lib/libtpm/tpm.in +++ b/lib/libtpm/tpm.in @@ -28,3 +28,4 @@ cod(tpm-get-state) cod(tpm-is-working) cod(tpm-measure-scrtm) cod(tpm-get-maximum-cmd-size) +cod(tpm-pass-through-to-tpm) diff --git a/lib/libtpm/tpm_drivers.h b/lib/libtpm/tpm_drivers.h index ab2e152..96bd32d 100644 --- a/lib/libtpm/tpm_drivers.h +++ b/lib/libtpm/tpm_drivers.h @@ -70,6 +70,9 @@ typedef enum { VTPM_DRV_ERROR_SML_HANDED_OVER = 14, } vtpm_drv_error; +/* the max. buffer size by the external TPM is 4k */ +#define PAPR_VTPM_MAX_BUFFER_SIZE 4096 + /* exported functions */ bool spapr_is_vtpm_present(void); void spapr_vtpm_finalize(void);