From patchwork Thu Oct 19 18:02:48 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stefan Berger X-Patchwork-Id: 10018131 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 52229600CC for ; Thu, 19 Oct 2017 18:18:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4D3A228DCD for ; Thu, 19 Oct 2017 18:18:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 41AF528DEA; Thu, 19 Oct 2017 18:18:06 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id A070628DCD for ; Thu, 19 Oct 2017 18:18:05 +0000 (UTC) Received: from localhost ([::1]:50739 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e5FOO-0002ez-Rr for patchwork-qemu-devel@patchwork.kernel.org; Thu, 19 Oct 2017 14:18:04 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36346) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e5FAS-0007Rq-7d for qemu-devel@nongnu.org; Thu, 19 Oct 2017 14:03:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e5FAL-0007Q4-57 for qemu-devel@nongnu.org; Thu, 19 Oct 2017 14:03:40 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:51662) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e5FAK-0007O7-Od for qemu-devel@nongnu.org; Thu, 19 Oct 2017 14:03:33 -0400 Received: from pps.filterd (m0098404.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id v9JI2RPf047473 for ; Thu, 19 Oct 2017 14:03:30 -0400 Received: from e13.ny.us.ibm.com (e13.ny.us.ibm.com [129.33.205.203]) by mx0a-001b2d01.pphosted.com with ESMTP id 2dpvu3rt40-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Thu, 19 Oct 2017 14:03:29 -0400 Received: from localhost by e13.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 19 Oct 2017 14:03:28 -0400 Received: from b01cxnp23034.gho.pok.ibm.com (9.57.198.29) by e13.ny.us.ibm.com (146.89.104.200) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 19 Oct 2017 14:03:25 -0400 Received: from b01ledav001.gho.pok.ibm.com (b01ledav001.gho.pok.ibm.com [9.57.199.106]) by b01cxnp23034.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v9JI3P6r41484508; Thu, 19 Oct 2017 18:03:25 GMT Received: from b01ledav001.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 60A9628048; Thu, 19 Oct 2017 14:03:18 -0400 (EDT) Received: from sbct-3.watson.ibm.com (unknown [9.47.158.153]) by b01ledav001.gho.pok.ibm.com (Postfix) with ESMTP id 52BF52803E; Thu, 19 Oct 2017 14:03:18 -0400 (EDT) From: Stefan Berger To: qemu-devel@nongnu.org Date: Thu, 19 Oct 2017 14:02:48 -0400 X-Mailer: git-send-email 2.5.5 In-Reply-To: <1508436175-1596-1-git-send-email-stefanb@linux.vnet.ibm.com> References: <1508436175-1596-1-git-send-email-stefanb@linux.vnet.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 x-cbid: 17101918-0008-0000-0000-0000029339B4 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00007919; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000238; SDB=6.00933480; UDB=6.00470184; IPR=6.00713768; BA=6.00005651; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00017610; XFM=3.00000015; UTC=2017-10-19 18:03:27 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17101918-0009-0000-0000-0000370F089D Message-Id: <1508436175-1596-15-git-send-email-stefanb@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-10-19_09:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=1 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1707230000 definitions=main-1710190247 X-MIME-Autoconverted: from 8bit to quoted-printable by mx0a-001b2d01.pphosted.com id v9JI2RPf047473 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.156.1 Subject: [Qemu-devel] [PULL v1 14/21] tpm: add TPMBackendCmd to hold the request state X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Stefan Berger , marcandre.lureau@gmail.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Marc-André Lureau This simplifies a bit locality handling, and argument passing, and could pave the way to queuing requests (if that makes sense). Signed-off-by: Marc-André Lureau Reviewed-by: Stefan Berger Signed-off-by: Stefan Berger --- backends/tpm.c | 6 +++--- hw/tpm/tpm_emulator.c | 29 +++++++++++++++-------------- hw/tpm/tpm_int.h | 1 + hw/tpm/tpm_passthrough.c | 24 +++++------------------- hw/tpm/tpm_tis.c | 18 +++++++++++++----- include/sysemu/tpm_backend.h | 16 +++++++++++++--- 6 files changed, 50 insertions(+), 44 deletions(-) diff --git a/backends/tpm.c b/backends/tpm.c index 34e8208..dc7c831 100644 --- a/backends/tpm.c +++ b/backends/tpm.c @@ -25,7 +25,7 @@ static void tpm_backend_worker_thread(gpointer data, gpointer user_data) TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s); assert(k->handle_request != NULL); - k->handle_request(s); + k->handle_request(s, (TPMBackendCmd *)data); } static void tpm_backend_thread_end(TPMBackend *s) @@ -76,9 +76,9 @@ bool tpm_backend_had_startup_error(TPMBackend *s) return s->had_startup_error; } -void tpm_backend_deliver_request(TPMBackend *s) +void tpm_backend_deliver_request(TPMBackend *s, TPMBackendCmd *cmd) { - g_thread_pool_push(s->thread_pool, NULL, NULL); + g_thread_pool_push(s->thread_pool, cmd, NULL); } void tpm_backend_reset(TPMBackend *s) diff --git a/hw/tpm/tpm_emulator.c b/hw/tpm/tpm_emulator.c index 8fbe9ad..0b1a99f 100644 --- a/hw/tpm/tpm_emulator.c +++ b/hw/tpm/tpm_emulator.c @@ -172,28 +172,29 @@ static int tpm_emulator_set_locality(TPMEmulator *tpm_emu, uint8_t locty_number) return 0; } -static void tpm_emulator_handle_request(TPMBackend *tb) +static void tpm_emulator_handle_request(TPMBackend *tb, TPMBackendCmd *cmd) { TPMEmulator *tpm_emu = TPM_EMULATOR(tb); - TPMLocality *locty = NULL; - bool selftest_done = false; Error *err = NULL; DPRINTF("processing TPM command"); - locty = tb->tpm_state->locty_data; - if (tpm_emulator_set_locality(tpm_emu, - tb->tpm_state->locty_number) < 0 || - tpm_emulator_unix_tx_bufs(tpm_emu, locty->w_buffer.buffer, - locty->w_offset, locty->r_buffer.buffer, - locty->r_buffer.size, &selftest_done, - &err) < 0) { - tpm_util_write_fatal_error_response(locty->r_buffer.buffer, - locty->r_buffer.size); - error_report_err(err); + if (tpm_emulator_set_locality(tpm_emu, tb->tpm_state->locty_number) < 0) { + goto error; + } + + if (tpm_emulator_unix_tx_bufs(tpm_emu, cmd->in, cmd->in_len, + cmd->out, cmd->out_len, + &cmd->selftest_done, &err) < 0) { + goto error; } - tb->recv_data_callback(tb->tpm_state, selftest_done); + tb->recv_data_callback(tb->tpm_state); + return; + +error: + tpm_util_write_fatal_error_response(cmd->out, cmd->out_len); + error_report_err(err); } static int tpm_emulator_probe_caps(TPMEmulator *tpm_emu) diff --git a/hw/tpm/tpm_int.h b/hw/tpm/tpm_int.h index f2f285b..6d7b3dc 100644 --- a/hw/tpm/tpm_int.h +++ b/hw/tpm/tpm_int.h @@ -26,6 +26,7 @@ struct TPMState { uint8_t locty_number; TPMLocality *locty_data; + TPMBackendCmd cmd; char *backend; TPMBackend *be_driver; diff --git a/hw/tpm/tpm_passthrough.c b/hw/tpm/tpm_passthrough.c index 0ae4596..93d72b8 100644 --- a/hw/tpm/tpm_passthrough.c +++ b/hw/tpm/tpm_passthrough.c @@ -137,30 +137,16 @@ err_exit: return ret; } -static int tpm_passthrough_unix_transfer(TPMPassthruState *tpm_pt, - const TPMLocality *locty_data, - bool *selftest_done) -{ - return tpm_passthrough_unix_tx_bufs(tpm_pt, - locty_data->w_buffer.buffer, - locty_data->w_offset, - locty_data->r_buffer.buffer, - locty_data->r_buffer.size, - selftest_done); -} - -static void tpm_passthrough_handle_request(TPMBackend *tb) +static void tpm_passthrough_handle_request(TPMBackend *tb, TPMBackendCmd *cmd) { TPMPassthruState *tpm_pt = TPM_PASSTHROUGH(tb); - bool selftest_done = false; - DPRINTF("tpm_passthrough: processing command\n"); + DPRINTF("tpm_passthrough: processing command %p\n", cmd); - tpm_passthrough_unix_transfer(tpm_pt, - tb->tpm_state->locty_data, - &selftest_done); + tpm_passthrough_unix_tx_bufs(tpm_pt, cmd->in, cmd->in_len, + cmd->out, cmd->out_len, &cmd->selftest_done); - tb->recv_data_callback(tb->tpm_state, selftest_done); + tb->recv_data_callback(tb->tpm_state); } static void tpm_passthrough_reset(TPMBackend *tb) diff --git a/hw/tpm/tpm_tis.c b/hw/tpm/tpm_tis.c index 345a4fb..ffed7bf 100644 --- a/hw/tpm/tpm_tis.c +++ b/hw/tpm/tpm_tis.c @@ -215,7 +215,15 @@ static void tpm_tis_tpm_send(TPMState *s, uint8_t locty) */ tis->loc[locty].state = TPM_TIS_STATE_EXECUTION; - tpm_backend_deliver_request(s->be_driver); + s->cmd = (TPMBackendCmd) { + .locty = locty, + .in = s->locty_data->w_buffer.buffer, + .in_len = s->locty_data->w_offset, + .out = s->locty_data->r_buffer.buffer, + .out_len = s->locty_data->r_buffer.size + }; + + tpm_backend_deliver_request(s->be_driver, &s->cmd); } /* raise an interrupt if allowed */ @@ -352,7 +360,7 @@ static void tpm_tis_receive_bh(void *opaque) { TPMState *s = opaque; TPMTISEmuState *tis = &s->s.tis; - uint8_t locty = s->locty_number; + uint8_t locty = s->cmd.locty; tpm_tis_sts_set(&tis->loc[locty], TPM_TIS_STS_VALID | TPM_TIS_STS_DATA_AVAILABLE); @@ -371,11 +379,11 @@ static void tpm_tis_receive_bh(void *opaque) /* * Callback from the TPM to indicate that the response was received. */ -static void tpm_tis_receive_cb(TPMState *s, - bool is_selftest_done) +static void tpm_tis_receive_cb(TPMState *s) { TPMTISEmuState *tis = &s->s.tis; - uint8_t locty = s->locty_number; + bool is_selftest_done = s->cmd.selftest_done; + uint8_t locty = s->cmd.locty; uint8_t l; if (is_selftest_done) { diff --git a/include/sysemu/tpm_backend.h b/include/sysemu/tpm_backend.h index 9c83a51..3bb90be 100644 --- a/include/sysemu/tpm_backend.h +++ b/include/sysemu/tpm_backend.h @@ -30,7 +30,16 @@ typedef struct TPMBackendClass TPMBackendClass; typedef struct TPMBackend TPMBackend; -typedef void (TPMRecvDataCB)(TPMState *, bool selftest_done); +typedef void (TPMRecvDataCB)(TPMState *); + +typedef struct TPMBackendCmd { + uint8_t locty; + const uint8_t *in; + uint32_t in_len; + uint8_t *out; + uint32_t out_len; + bool selftest_done; +} TPMBackendCmd; struct TPMBackend { Object parent; @@ -76,7 +85,7 @@ struct TPMBackendClass { void (*opened)(TPMBackend *s, Error **errp); - void (*handle_request)(TPMBackend *s); + void (*handle_request)(TPMBackend *s, TPMBackendCmd *cmd); }; /** @@ -121,11 +130,12 @@ bool tpm_backend_had_startup_error(TPMBackend *s); /** * tpm_backend_deliver_request: * @s: the backend to send the request to + * @cmd: the command to deliver * * Send a request to the backend. The backend will then send the request * to the TPM implementation. */ -void tpm_backend_deliver_request(TPMBackend *s); +void tpm_backend_deliver_request(TPMBackend *s, TPMBackendCmd *cmd); /** * tpm_backend_reset: