From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:53088) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RaFid-0002iV-29 for qemu-devel@nongnu.org; Mon, 12 Dec 2011 18:55:40 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RaFib-0003mU-Ur for qemu-devel@nongnu.org; Mon, 12 Dec 2011 18:55:39 -0500 Received: from e35.co.us.ibm.com ([32.97.110.153]:42080) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RaFib-0003le-Oz for qemu-devel@nongnu.org; Mon, 12 Dec 2011 18:55:37 -0500 Received: from /spool/local by e35.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 12 Dec 2011 16:55:30 -0700 Received: from d03av03.boulder.ibm.com (d03av03.boulder.ibm.com [9.17.195.169]) by d03relay03.boulder.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id pBCNsZHW155256 for ; Mon, 12 Dec 2011 16:54:35 -0700 Received: from d03av03.boulder.ibm.com (loopback [127.0.0.1]) by d03av03.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id pBCNsYJk009498 for ; Mon, 12 Dec 2011 16:54:35 -0700 Message-ID: <4EE69439.9020401@linux.vnet.ibm.com> Date: Mon, 12 Dec 2011 18:54:33 -0500 From: Stefan Berger MIME-Version: 1.0 References: <1323717136-21661-1-git-send-email-stefanb@linux.vnet.ibm.com> <1323717136-21661-3-git-send-email-stefanb@linux.vnet.ibm.com> <4EE68CD5.2080103@codemonkey.ws> In-Reply-To: <4EE68CD5.2080103@codemonkey.ws> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH V13 2/7] Add TPM (frontend) hardware interface (TPM TIS) to Qemu List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Anthony Liguori Cc: mst@redhat.com, qemu-devel@nongnu.org, andreas.niederl@iaik.tugraz.at On 12/12/2011 06:23 PM, Anthony Liguori wrote: > On 12/12/2011 01:12 PM, Stefan Berger wrote: >> This patch adds the main code of the TPM frontend driver, the TPM TIS >> interface, to Qemu. The code is largely based on the previous >> implementation >> for Xen but has been significantly extended to meet the standard's >> requirements, such as the support for changing of localities and all the >> functionality of the available flags. >> >> Communication with the backend (i.e., for Xen or the libtpms-based one) >> is cleanly separated through an interface which the backend driver needs >> to implement. >> >> The TPM TIS driver's backend was previously chosen in the code added >> to arch_init. The frontend holds a pointer to the chosen backend >> (interface). >> >> Communication with the backend is largely based on signals and >> conditions. >> Whenever the frontend has collected a complete packet, it will signal >> the backend, which then starts processing the command. Once the result >> has been returned, the backend invokes a callback function >> (tis_tpm_receive_cb()). >> >> The one tricky part is support for VM suspend while the TPM is >> processing >> a command. In this case the frontend driver is waiting for the backend >> to return the result of the last command before shutting down. It waits >> on a condition for a signal from the backend, which is delivered in >> tis_tpm_receive_cb(). >> >> Testing the proper functioning of the different flags and localities >> cannot be done from user space when running in Linux for example, since >> access to the address space of the TPM TIS interface is not possible. >> Also >> the Linux driver itself does not exercise all functionality. So, for >> testing there is a fairly extensive test suite as part of the SeaBIOS >> patches >> since from within the BIOS one can have full access to all the TPM's >> registers. >> >> >> Signed-off-by: Stefan Berger [...] >> + >> +/* >> + * Send a TPM request. >> + * Call this with the state_lock held so we can sync with the receive >> + * callback. >> + */ >> +static void tpm_tis_tpm_send(TPMState *s, uint8_t locty) >> +{ >> + TPMTISState *tis =&s->s.tis; >> +#ifdef DEBUG_TIS >> + tpm_tis_show_buffer(&tis->loc[locty].w_buffer, "tpm_tis: To TPM"); >> +#endif >> + s->command_locty = locty; >> + s->cmd_locty =&tis->loc[locty]; >> + >> + /* w_offset serves as length indicator for length of data; >> + it's reset when the response comes back */ >> + tis->loc[locty].state = TPM_TIS_STATE_EXECUTION; >> + tis->loc[locty].sts&= ~TPM_TIS_STS_EXPECT; >> + >> + s->to_tpm_execute = true; >> + qemu_cond_signal(&s->to_tpm_cond); > > The locking seems to presume that the device model is re-entrant which > it's not today. Am I missing something here? > The TPM TIS frontend communicates with the TPM backend via a condition notifying it when a complete buffer with a TPM request has been received. The TPM backend is running as a thread, created via qemu_thread_create(). This is the design that was driven by the libtpms-based implementation. Stefan