From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 51267C7EE43 for ; Thu, 24 Aug 2023 08:35:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240491AbjHXIe6 (ORCPT ); Thu, 24 Aug 2023 04:34:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56186 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240641AbjHXIe4 (ORCPT ); Thu, 24 Aug 2023 04:34:56 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.126]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C5F031724 for ; Thu, 24 Aug 2023 01:34:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1692866094; x=1724402094; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=+YaBz0JbTkdfg50z18lO5jNRK2nQ1KYA+FqnKCx2caU=; b=DKEMcOZ0G5AEVS6jxFCapAVTTWaYGoufuEp3Swr6YiHieI4T+TO/JbdW KHkPKM/WQSVaPQ1f4WazpcuW1UA5pYqe1iMJwEy+l8G9jGDMi350zCxWz SMkXXGNRzwSNFfTQKjVxnR4LCndtGhhs++iOmkIVkfR7oZR2LVsYuReLO 78+2STXKmBFeGJf6WG1k/EfP5k+eXJHI91paltOTCniOBuL6lF6C+HVhr /ijSxWg6gDqhHTsoKVyCjEu3I9VfFicQLUPAvfwNZnm+KYMmpbrYrAzMz UX+xVHFEt8WXdhTVtoyGHIySPy/wLx00iybQBdle81oHUi1TaMRVC88B0 Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10811"; a="359365469" X-IronPort-AV: E=Sophos;i="6.01,195,1684825200"; d="scan'208";a="359365469" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Aug 2023 01:34:54 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10811"; a="802465560" X-IronPort-AV: E=Sophos;i="6.01,195,1684825200"; d="scan'208";a="802465560" Received: from xiaoyaol-hp-g830.ccr.corp.intel.com (HELO [10.93.16.81]) ([10.93.16.81]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Aug 2023 01:34:48 -0700 Message-ID: <5db417d4-473c-06c4-d760-70516065aea5@intel.com> Date: Thu, 24 Aug 2023 16:34:45 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Firefox/102.0 Thunderbird/102.14.0 Subject: Re: [PATCH v2 43/58] i386/tdx: setup a timer for the qio channel Content-Language: en-US To: Chenyi Qiang , Paolo Bonzini , Richard Henderson , "Michael S. Tsirkin" , Marcel Apfelbaum , Igor Mammedov , Ani Sinha , Peter Xu , David Hildenbrand , =?UTF-8?Q?Philippe_Mathieu-Daud=c3=a9?= , =?UTF-8?Q?Daniel_P=2e_Berrang=c3=a9?= , Cornelia Huck , Eric Blake , Markus Armbruster , Marcelo Tosatti , Gerd Hoffmann Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org, Eduardo Habkost , Laszlo Ersek , Isaku Yamahata , erdemaktas@google.com References: <20230818095041.1973309-1-xiaoyao.li@intel.com> <20230818095041.1973309-44-xiaoyao.li@intel.com> <7629706c-0b7e-a8d5-ed52-21c6eeecd184@intel.com> From: Xiaoyao Li In-Reply-To: <7629706c-0b7e-a8d5-ed52-21c6eeecd184@intel.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org On 8/24/2023 3:21 PM, Chenyi Qiang wrote: > > > On 8/18/2023 5:50 PM, Xiaoyao Li wrote: >> From: Chenyi Qiang >> >> To avoid no response from QGS server, setup a timer for the transaction. If >> timeout, make it an error and interrupt guest. Define the threshold of time >> to 30s at present, maybe change to other value if not appropriate. >> >> Extract the common cleanup code to make it more clear. >> >> Signed-off-by: Chenyi Qiang >> Signed-off-by: Xiaoyao Li >> --- >> target/i386/kvm/tdx.c | 151 ++++++++++++++++++++++++------------------ >> 1 file changed, 85 insertions(+), 66 deletions(-) >> >> diff --git a/target/i386/kvm/tdx.c b/target/i386/kvm/tdx.c >> index 3cb2163a0335..fa658ce1f2e4 100644 >> --- a/target/i386/kvm/tdx.c >> +++ b/target/i386/kvm/tdx.c >> @@ -1002,6 +1002,7 @@ struct tdx_get_quote_task { >> struct tdx_get_quote_header hdr; >> int event_notify_interrupt; >> QIOChannelSocket *ioc; >> + QEMUTimer timer; >> }; >> >> struct x86_msi { >> @@ -1084,13 +1085,48 @@ static void tdx_td_notify(struct tdx_get_quote_task *t) >> } >> } >> >> +static void tdx_getquote_task_cleanup(struct tdx_get_quote_task *t, bool outlen_overflow) >> +{ >> + MachineState *ms; >> + TdxGuest *tdx; >> + >> + if (t->hdr.error_code != cpu_to_le64(TDX_VP_GET_QUOTE_SUCCESS) && !outlen_overflow) { >> + t->hdr.out_len = cpu_to_le32(0); >> + } >> + >> + /* Publish the response contents before marking this request completed. */ >> + smp_wmb(); >> + if (address_space_write( >> + &address_space_memory, t->gpa, >> + MEMTXATTRS_UNSPECIFIED, &t->hdr, sizeof(t->hdr)) != MEMTX_OK) { >> + error_report("TDX: failed to update GetQuote header."); >> + } >> + tdx_td_notify(t); >> + >> + if (t->ioc->fd > 0) { >> + qemu_set_fd_handler(t->ioc->fd, NULL, NULL, NULL); >> + } >> + qio_channel_close(QIO_CHANNEL(t->ioc), NULL); >> + object_unref(OBJECT(t->ioc)); >> + timer_del(&t->timer); > > Xiaoyao, I guess you missed a bug fix patch here as t->timer could be > uninitialized and then timer_del() will cause segv. Thanks for the reminding. I'll update this patch to include the fix. Thanks, -Xiaoyao >> + g_free(t->out_data); >> + g_free(t); >> + >> + /* Maintain the number of in-flight requests. */ >> + ms = MACHINE(qdev_get_machine()); >> + tdx = TDX_GUEST(ms->cgs); >> + qemu_mutex_lock(&tdx->lock); >> + tdx->quote_generation_num--; >> + qemu_mutex_unlock(&tdx->lock); >> +} >> + >