From patchwork Mon Aug 13 20:32:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tadeusz Struk X-Patchwork-Id: 10564795 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8A94815A6 for ; Mon, 13 Aug 2018 20:32:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7F6C829822 for ; Mon, 13 Aug 2018 20:32:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7338F2984A; Mon, 13 Aug 2018 20:32:51 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8B3B629827 for ; Mon, 13 Aug 2018 20:32:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730119AbeHMXQh (ORCPT ); Mon, 13 Aug 2018 19:16:37 -0400 Received: from mga17.intel.com ([192.55.52.151]:55729 "EHLO mga17.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728540AbeHMXQg (ORCPT ); Mon, 13 Aug 2018 19:16:36 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 13 Aug 2018 13:32:48 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,234,1531810800"; d="scan'208";a="248535350" Received: from tstruk-mobl1.jf.intel.com ([10.7.196.170]) by orsmga005.jf.intel.com with ESMTP; 13 Aug 2018 13:32:48 -0700 Subject: [PATCH v5 0/2] tpm: add support for nonblocking operation From: Tadeusz Struk To: jarkko.sakkinen@linux.intel.com Cc: flihp@twobit.us, jgg@ziepe.ca, linux-integrity@vger.kernel.org, linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org, tadeusz.struk@intel.com Date: Mon, 13 Aug 2018 13:32:48 -0700 Message-ID: <153419236870.8189.15489652816512817246.stgit@tstruk-mobl1.jf.intel.com> User-Agent: StGit/unknown-version MIME-Version: 1.0 Sender: linux-integrity-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The TCG SAPI specification [1] defines a set of functions, which allow applications to use the TPM device in either blocking or non-blocking fashion. Each command defined by the specification has a corresponding Tss2_Sys__Prepare() and Tss2_Sys__Complete() call, which together with Tss2_Sys_ExecuteAsync() is designed to allow asynchronous mode of operation. Currently the TPM driver supports only blocking calls, which doesn't allow asynchronous IO operations. This patch changes it and adds support for nonblocking write and a new poll function to enable applications, which want to take advantage of this feature. The new functionality can be tested using standard TPM tools implemented in [2], together with modified TCTI from [3], and an example application by Philip Tricca [4]. Here is a short description from Philip: "The example application `glib-tss2-event` uses a glib main event loop to create an RSA 2048 primary key in the TPM2 NULL hierarchy while using a glib timer event to time the operation. A GSource object is used to generate an event when the FD underlying the tss2 function call has data ready. While the application waits for an event indicating that the CreatePrimary operation is complete, it counts timer events that occur every 100ms. Once the CreatePrimary operation completes the number of timer events that occurred is used to make a rough calculation of the elapsed time. This value is then printed to the console. This takes ~300 lines of C code and requires no management or synchronization of threads. The glib GMainContext is "just a poll() loop" according to the glib documentation here: https://developer.gnome.org/programming-guidelines/stable/main-contexts.html.en and so supporting 'poll' is the easiest way to integrate with glib / gtk+. This is true of any other event system that relies on 'poll' instead of worker threads." [1] https://trustedcomputinggroup.org/wp-content/uploads/TSS_SAPI_Version-1.1_Revision-22_review_030918.pdf [2] https://github.com/tpm2-software/tpm2-tools [3] https://github.com/tstruk/tpm2-tss/tree/async [4] https://github.com/flihp/glib-tss2-async-example --- Changes in v5: - Changed the workqueue allocation time back from the first user interface open to module init. Changes in v4: - Changed the way buffer_mutex is handled in nonblocking mode so that it is not held when write() returns to user space. Changes in v3: - Fixed problem reported by 0-dey kbuild test robot around __exitcall. It complained because there is a module_exit() in another file already. - Added info on example application from Philip Changes in v2: - Split the change into two separate patches. First patch adds a pointer to the space to the struct file_priv to have access to it from the async job. This is to avoid memory allocations on every write call. Now everything what's needed is in the file_priv struct. - Renamed the 'work' member of the timer to avoid confusion. Now there are 'timeout_work' and 'async_work'. - Removed the global wait queue and moved it to file_priv. - Only creating the work queue when the first file is opened. Tadeusz Struk (2): tpm: add ptr to the tpm_space struct to file_priv tpm: add support for nonblocking operation drivers/char/tpm/tpm-dev-common.c | 150 +++++++++++++++++++++++++++---------- drivers/char/tpm/tpm-dev.c | 22 +++-- drivers/char/tpm/tpm-dev.h | 19 +++-- drivers/char/tpm/tpm-interface.c | 1 drivers/char/tpm/tpm.h | 1 drivers/char/tpm/tpmrm-dev.c | 31 ++++---- 6 files changed, 152 insertions(+), 72 deletions(-) -- TS