{"id":819457,"url":"http://patchwork.ozlabs.org/api/patches/819457/?format=json","web_url":"http://patchwork.ozlabs.org/project/qemu-devel/patch/1506590409-28857-5-git-send-email-amarnath.valluri@intel.com/","project":{"id":14,"url":"http://patchwork.ozlabs.org/api/projects/14/?format=json","name":"QEMU Development","link_name":"qemu-devel","list_id":"qemu-devel.nongnu.org","list_email":"qemu-devel@nongnu.org","web_url":"","scm_url":"","webscm_url":"","list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<1506590409-28857-5-git-send-email-amarnath.valluri@intel.com>","list_archive_url":null,"date":"2017-09-28T09:20:05","name":"[v9,4/8] tpm-backend: Made few interface methods optional","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"1f330c699d3604f614f7de36dfa53ddd2e3a54e6","submitter":{"id":71320,"url":"http://patchwork.ozlabs.org/api/people/71320/?format=json","name":"Valluri, Amarnath","email":"amarnath.valluri@intel.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/qemu-devel/patch/1506590409-28857-5-git-send-email-amarnath.valluri@intel.com/mbox/","series":[{"id":5516,"url":"http://patchwork.ozlabs.org/api/series/5516/?format=json","web_url":"http://patchwork.ozlabs.org/project/qemu-devel/list/?series=5516","date":"2017-09-28T09:20:02","name":"Provide support for the software TPM","version":9,"mbox":"http://patchwork.ozlabs.org/series/5516/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/819457/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/819457/checks/","tags":{},"related":[],"headers":{"Return-Path":"<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@bilbo.ozlabs.org","Authentication-Results":"ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=nongnu.org\n\t(client-ip=2001:4830:134:3::11; helo=lists.gnu.org;\n\tenvelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n\treceiver=<UNKNOWN>)","Received":["from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11])\n\t(using TLSv1 with cipher AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3y2q6s6S22z9t38\n\tfor <incoming@patchwork.ozlabs.org>;\n\tThu, 28 Sep 2017 19:25:41 +1000 (AEST)","from localhost ([::1]:58116 helo=lists.gnu.org)\n\tby lists.gnu.org with esmtp (Exim 4.71) (envelope-from\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>)\n\tid 1dxV4d-0005Rs-V3\n\tfor incoming@patchwork.ozlabs.org; Thu, 28 Sep 2017 05:25:40 -0400","from eggs.gnu.org ([2001:4830:134:3::10]:59229)\n\tby lists.gnu.org with esmtp (Exim 4.71)\n\t(envelope-from <amarnath.valluri@intel.com>) id 1dxUyN-0000tD-2L\n\tfor qemu-devel@nongnu.org; Thu, 28 Sep 2017 05:19:12 -0400","from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)\n\t(envelope-from <amarnath.valluri@intel.com>) id 1dxUyG-0000mx-Kv\n\tfor qemu-devel@nongnu.org; Thu, 28 Sep 2017 05:19:11 -0400","from mga11.intel.com ([192.55.52.93]:13925)\n\tby eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32)\n\t(Exim 4.71) (envelope-from <amarnath.valluri@intel.com>)\n\tid 1dxUyG-0000bz-AV\n\tfor qemu-devel@nongnu.org; Thu, 28 Sep 2017 05:19:04 -0400","from orsmga005.jf.intel.com ([10.7.209.41])\n\tby fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384;\n\t28 Sep 2017 02:19:03 -0700","from avallurigigabyte.fi.intel.com ([10.237.68.147])\n\tby orsmga005.jf.intel.com with ESMTP; 28 Sep 2017 02:19:02 -0700"],"X-ExtLoop1":"1","X-IronPort-AV":"E=Sophos;i=\"5.42,449,1500966000\"; d=\"scan'208\";a=\"154306577\"","From":"Amarnath Valluri <amarnath.valluri@intel.com>","To":"qemu-devel@nongnu.org","Date":"Thu, 28 Sep 2017 12:20:05 +0300","Message-Id":"<1506590409-28857-5-git-send-email-amarnath.valluri@intel.com>","X-Mailer":"git-send-email 2.7.4","In-Reply-To":"<1506590409-28857-1-git-send-email-amarnath.valluri@intel.com>","References":"<1506590409-28857-1-git-send-email-amarnath.valluri@intel.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=UTF-8","Content-Transfer-Encoding":"8bit","X-detected-operating-system":"by eggs.gnu.org: Genre and OS details not\n\trecognized.","X-Received-From":"192.55.52.93","Subject":"[Qemu-devel] [PATCH v9 4/8] tpm-backend: Made few interface methods\n\toptional","X-BeenThere":"qemu-devel@nongnu.org","X-Mailman-Version":"2.1.21","Precedence":"list","List-Id":"<qemu-devel.nongnu.org>","List-Unsubscribe":"<https://lists.nongnu.org/mailman/options/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>","List-Archive":"<http://lists.nongnu.org/archive/html/qemu-devel/>","List-Post":"<mailto:qemu-devel@nongnu.org>","List-Help":"<mailto:qemu-devel-request@nongnu.org?subject=help>","List-Subscribe":"<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=subscribe>","Cc":"Amarnath Valluri <amarnath.valluri@intel.com>, =?utf-8?q?Marc-Andr?=\n\t=?utf-8?b?w6kgTHVyZWF1?= <marcandre.lureau@gmail.com>,\n\tStefan Berger <stefanb@linux.vnet.ibm.com>","Errors-To":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org","Sender":"\"Qemu-devel\"\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>"},"content":"This allows backend implementations left optional interface methods.\nFor mandatory methods assertion checks added.\n\nTook the opportunity to remove unused methods:\n - tpm_backend_get_desc()\n - TPMDriverOps->handle_startup_error\n\nSigned-off-by: Amarnath Valluri <amarnath.valluri@intel.com>\nReviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>\nReviewed-by: Stefan Berger<stefanb@linux.vnet.ibm.com>\n---\n backends/tpm.c               | 39 ++++++++++++++++++++++++---------------\n hw/tpm/tpm_passthrough.c     | 36 +-----------------------------------\n include/sysemu/tpm_backend.h | 13 ++-----------\n tpm.c                        |  2 +-\n 4 files changed, 28 insertions(+), 62 deletions(-)","diff":"diff --git a/backends/tpm.c b/backends/tpm.c\nindex cf5abf1..8911597 100644\n--- a/backends/tpm.c\n+++ b/backends/tpm.c\n@@ -44,13 +44,6 @@ enum TpmType tpm_backend_get_type(TPMBackend *s)\n     return k->ops->type;\n }\n \n-const char *tpm_backend_get_desc(TPMBackend *s)\n-{\n-    TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s);\n-\n-    return k->ops->desc();\n-}\n-\n int tpm_backend_init(TPMBackend *s, TPMState *state,\n                      TPMRecvDataCB *datacb)\n {\n@@ -58,12 +51,14 @@ int tpm_backend_init(TPMBackend *s, TPMState *state,\n \n     s->tpm_state = state;\n     s->recv_data_callback = datacb;\n+    s->had_startup_error = false;\n \n-    return k->ops->init(s);\n+    return k->ops->init ? k->ops->init(s) : 0;\n }\n \n int tpm_backend_startup_tpm(TPMBackend *s)\n {\n+    int res = 0;\n     TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s);\n \n     /* terminate a running TPM */\n@@ -73,20 +68,24 @@ int tpm_backend_startup_tpm(TPMBackend *s)\n                                        NULL);\n     g_thread_pool_push(s->thread_pool, (gpointer)TPM_BACKEND_CMD_INIT, NULL);\n \n-    return k->ops->startup_tpm(s);\n+    res = k->ops->startup_tpm ? k->ops->startup_tpm(s) : 0;\n+\n+    s->had_startup_error = (res != 0);\n+\n+    return res;\n }\n \n bool tpm_backend_had_startup_error(TPMBackend *s)\n {\n-    TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s);\n-\n-    return k->ops->had_startup_error(s);\n+    return s->had_startup_error;\n }\n \n size_t tpm_backend_realloc_buffer(TPMBackend *s, TPMSizedBuffer *sb)\n {\n     TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s);\n \n+    assert(k->ops->realloc_buffer);\n+\n     return k->ops->realloc_buffer(sb);\n }\n \n@@ -100,15 +99,21 @@ void tpm_backend_reset(TPMBackend *s)\n {\n     TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s);\n \n-    k->ops->reset(s);\n+    if (k->ops->reset) {\n+        k->ops->reset(s);\n+    }\n \n     tpm_backend_thread_end(s);\n+\n+    s->had_startup_error = false;\n }\n \n void tpm_backend_cancel_cmd(TPMBackend *s)\n {\n     TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s);\n \n+    assert(k->ops->cancel_cmd);\n+\n     k->ops->cancel_cmd(s);\n }\n \n@@ -116,20 +121,24 @@ bool tpm_backend_get_tpm_established_flag(TPMBackend *s)\n {\n     TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s);\n \n-    return k->ops->get_tpm_established_flag(s);\n+    return k->ops->get_tpm_established_flag ?\n+           k->ops->get_tpm_established_flag(s) : false;\n }\n \n int tpm_backend_reset_tpm_established_flag(TPMBackend *s, uint8_t locty)\n {\n     TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s);\n \n-    return k->ops->reset_tpm_established_flag(s, locty);\n+    return k->ops->reset_tpm_established_flag ?\n+           k->ops->reset_tpm_established_flag(s, locty) : 0;\n }\n \n TPMVersion tpm_backend_get_tpm_version(TPMBackend *s)\n {\n     TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s);\n \n+    assert(k->ops->get_tpm_version);\n+\n     return k->ops->get_tpm_version(s);\n }\n \ndiff --git a/hw/tpm/tpm_passthrough.c b/hw/tpm/tpm_passthrough.c\nindex 815a72e..4c21e52 100644\n--- a/hw/tpm/tpm_passthrough.c\n+++ b/hw/tpm/tpm_passthrough.c\n@@ -54,7 +54,6 @@ struct TPMPassthruState {\n     bool tpm_executing;\n     bool tpm_op_canceled;\n     int cancel_fd;\n-    bool had_startup_error;\n \n     TPMVersion tpm_version;\n };\n@@ -227,29 +226,11 @@ static void tpm_passthrough_handle_request(TPMBackend *tb, TPMBackendCmd cmd)\n     }\n }\n \n-/*\n- * Start the TPM (thread). If it had been started before, then terminate\n- * and start it again.\n- */\n-static int tpm_passthrough_startup_tpm(TPMBackend *tb)\n-{\n-    return 0;\n-}\n-\n static void tpm_passthrough_reset(TPMBackend *tb)\n {\n-    TPMPassthruState *tpm_pt = TPM_PASSTHROUGH(tb);\n-\n     DPRINTF(\"tpm_passthrough: CALL TO TPM_RESET!\\n\");\n \n     tpm_passthrough_cancel_cmd(tb);\n-\n-    tpm_pt->had_startup_error = false;\n-}\n-\n-static int tpm_passthrough_init(TPMBackend *tb)\n-{\n-    return 0;\n }\n \n static bool tpm_passthrough_get_tpm_established_flag(TPMBackend *tb)\n@@ -264,13 +245,6 @@ static int tpm_passthrough_reset_tpm_established_flag(TPMBackend *tb,\n     return 0;\n }\n \n-static bool tpm_passthrough_get_startup_error(TPMBackend *tb)\n-{\n-    TPMPassthruState *tpm_pt = TPM_PASSTHROUGH(tb);\n-\n-    return tpm_pt->had_startup_error;\n-}\n-\n static size_t tpm_passthrough_realloc_buffer(TPMSizedBuffer *sb)\n {\n     size_t wanted_size = 4096; /* Linux tpm.c buffer size */\n@@ -309,11 +283,6 @@ static void tpm_passthrough_cancel_cmd(TPMBackend *tb)\n     }\n }\n \n-static const char *tpm_passthrough_create_desc(void)\n-{\n-    return \"Passthrough TPM backend driver\";\n-}\n-\n static TPMVersion tpm_passthrough_get_tpm_version(TPMBackend *tb)\n {\n     TPMPassthruState *tpm_pt = TPM_PASSTHROUGH(tb);\n@@ -453,13 +422,10 @@ static const QemuOptDesc tpm_passthrough_cmdline_opts[] = {\n static const TPMDriverOps tpm_passthrough_driver = {\n     .type                     = TPM_TYPE_PASSTHROUGH,\n     .opts                     = tpm_passthrough_cmdline_opts,\n-    .desc                     = tpm_passthrough_create_desc,\n+    .desc                     = \"Passthrough TPM backend driver\",\n     .create                   = tpm_passthrough_create,\n-    .init                     = tpm_passthrough_init,\n-    .startup_tpm              = tpm_passthrough_startup_tpm,\n     .realloc_buffer           = tpm_passthrough_realloc_buffer,\n     .reset                    = tpm_passthrough_reset,\n-    .had_startup_error        = tpm_passthrough_get_startup_error,\n     .cancel_cmd               = tpm_passthrough_cancel_cmd,\n     .get_tpm_established_flag = tpm_passthrough_get_tpm_established_flag,\n     .reset_tpm_established_flag = tpm_passthrough_reset_tpm_established_flag,\ndiff --git a/include/sysemu/tpm_backend.h b/include/sysemu/tpm_backend.h\nindex 202ec8d..9ea7072 100644\n--- a/include/sysemu/tpm_backend.h\n+++ b/include/sysemu/tpm_backend.h\n@@ -47,6 +47,7 @@ struct TPMBackend {\n     TPMState *tpm_state;\n     GThreadPool *thread_pool;\n     TPMRecvDataCB *recv_data_callback;\n+    bool had_startup_error;\n \n     char *id;\n     enum TpmModel fe_model;\n@@ -75,7 +76,7 @@ struct TPMDriverOps {\n     enum TpmType type;\n     const QemuOptDesc *opts;\n     /* get a descriptive text of the backend to display to the user */\n-    const char *(*desc)(void);\n+    const char *desc;\n \n     TPMBackend *(*create)(QemuOpts *opts, const char *id);\n \n@@ -83,8 +84,6 @@ struct TPMDriverOps {\n     int (*init)(TPMBackend *t);\n     /* start up the TPM on the backend */\n     int (*startup_tpm)(TPMBackend *t);\n-    /* returns true if nothing will ever answer TPM requests */\n-    bool (*had_startup_error)(TPMBackend *t);\n \n     size_t (*realloc_buffer)(TPMSizedBuffer *sb);\n \n@@ -109,14 +108,6 @@ struct TPMDriverOps {\n enum TpmType tpm_backend_get_type(TPMBackend *s);\n \n /**\n- * tpm_backend_get_desc:\n- * @s: the backend\n- *\n- * Returns a human readable description of the backend.\n- */\n-const char *tpm_backend_get_desc(TPMBackend *s);\n-\n-/**\n  * tpm_backend_init:\n  * @s: the backend to initialized\n  * @state: TPMState\ndiff --git a/tpm.c b/tpm.c\nindex b19b1a3..db14849 100644\n--- a/tpm.c\n+++ b/tpm.c\n@@ -62,7 +62,7 @@ static void tpm_display_backend_drivers(void)\n             continue;\n         }\n         fprintf(stderr, \"%12s   %s\\n\",\n-                TpmType_str(i), be_drivers[i]->desc());\n+                TpmType_str(i), be_drivers[i]->desc);\n     }\n     fprintf(stderr, \"\\n\");\n }\n","prefixes":["v9","4/8"]}