From: Colin Didier Subject: [PATCH][VTPM manager] backend listener not required Date: Mon, 2 Feb 2009 21:17:10 +0900 Message-ID: <20090202121710.GA2520@cybione.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="zYM0uCDKw75PZbzx" Return-path: Content-Disposition: inline List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: xen-devel@lists.xensource.com List-Id: xen-devel@lists.xenproject.org --zYM0uCDKw75PZbzx Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Hello, This simple patch tests if the VTPM backend is present or not (if the device file /dev/vtpm exists) and launch the backend listener only if it is present. So if you only run HVM domains you don't need to build and load the VTPM backend (the module tpmbk). Of course, without the backend you won't be able to use VTPM inside a pv DomU. Cheers, Colin Didier -- Colin Didier http://cybione.org/~cdidier/ --zYM0uCDKw75PZbzx Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="vtpm_managerd-be_exists.diff" diff -r 3155a367b476 tools/vtpm_manager/manager/vtpmd.c --- a/tools/vtpm_manager/manager/vtpmd.c Tue Jan 27 16:06:29 2009 +0000 +++ b/tools/vtpm_manager/manager/vtpmd.c Mon Feb 02 21:01:56 2009 +0900 @@ -66,6 +66,9 @@ #define VTPM_TYPE_PVM_STRING "pvm" #define VTPM_TYPE_HVM_STRING "hvm" +// the backend is running or not? +static int be_exists; + struct vtpm_thread_params_s { vtpm_ipc_handle_t *tx_ipc_h; vtpm_ipc_handle_t *rx_ipc_h; @@ -159,9 +162,15 @@ */ memset(&dmi_res->DMI_measurement, 0xcc, sizeof(TPM_DIGEST)); - if (vm_type == VTPM_TYPE_PVM) - vm_type_string = (BYTE *)&VTPM_TYPE_PVM_STRING; - else + if (vm_type == VTPM_TYPE_PVM) { + if (be_exists) + vm_type_string = (BYTE *)&VTPM_TYPE_PVM_STRING; + else { + vtpmlogerror(VTPM_LOG_VTPM, "The backend is not running!\n"); + status = TPM_IOERROR; + goto abort_egress; + } + } else vm_type_string = (BYTE *)&VTPM_TYPE_HVM_STRING; // Launch DMI @@ -284,6 +293,7 @@ // ------------------- Set up file ipc structures ---------- #ifdef DUMMY_BACKEND + be_exists = TRUE; if ( (vtpm_ipc_init(&tx_dummy_ipc_h, VTPM_DUMMY_TX_BE_FNAME, O_RDWR, TRUE) != 0) || (vtpm_ipc_init(&rx_dummy_ipc_h, VTPM_DUMMY_RX_BE_FNAME, O_RDWR, TRUE) != 0) ) { @@ -294,10 +304,14 @@ tx_be_ipc_h = &tx_dummy_ipc_h; rx_be_ipc_h = &rx_dummy_ipc_h; #else - vtpm_ipc_init(&real_be_ipc_h, VTPM_BE_FNAME, O_RDWR, FALSE); + be_exists = access(VTPM_BE_FNAME, F_OK) == 0 ? TRUE : FALSE; + if (be_exists) { + vtpm_ipc_init(&real_be_ipc_h, VTPM_BE_FNAME, O_RDWR, FALSE); - tx_be_ipc_h = &real_be_ipc_h; - rx_be_ipc_h = &real_be_ipc_h; + tx_be_ipc_h = &real_be_ipc_h; + rx_be_ipc_h = &real_be_ipc_h; + } else + vtpmloginfo(VTPM_LOG_VTPM, "There is no " VTPM_BE_FNAME ", so the backend listener is disabled (pv guest won't have a VTPM).\n"); #endif if ( (vtpm_ipc_init(&rx_tpm_ipc_h, VTPM_RX_TPM_FNAME, O_RDONLY, TRUE) != 0) || @@ -341,10 +355,12 @@ vtpm_lock_init(); vtpm_globals->master_pid = pthread_self(); - - if (pthread_create(&be_thread, NULL, vtpm_manager_thread, &be_thread_params) != 0) { - vtpmlogerror(VTPM_LOG_VTPM, "Failed to launch BE Thread.\n"); - exit(-1); + + if (be_exists) { + if (pthread_create(&be_thread, NULL, vtpm_manager_thread, &be_thread_params) != 0) { + vtpmlogerror(VTPM_LOG_VTPM, "Failed to launch BE Thread.\n"); + exit(-1); + } } if (pthread_create(&dmi_thread, NULL, vtpm_manager_thread, &dmi_thread_params) != 0) { @@ -359,7 +375,8 @@ } //Join the other threads until exit time. - pthread_join(be_thread, NULL); + if (be_exists) + pthread_join(be_thread, NULL); pthread_join(dmi_thread, NULL); pthread_join(hp_thread, NULL); --zYM0uCDKw75PZbzx Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --zYM0uCDKw75PZbzx--