From patchwork Wed Nov 15 07:15:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiaoyao Li X-Patchwork-Id: 13456362 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 57C05BA43 for ; Wed, 15 Nov 2023 07:22:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="ck+SC4LT" Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 541EDD1 for ; Tue, 14 Nov 2023 23:22:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1700032967; x=1731568967; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=vhVcnJA235Fj2gwGFH0mC11AUNmdkNpBg9xHCT6QPd4=; b=ck+SC4LTn6pcJIglUy71ZoVCSI80ZYzqiny6No7OAX/SEbKNV2/kTjeW Jl7GWSANkTLGhoW4Rz7QsjSzyP0jEv0JJstQjQBIbjjlgLSC16c6IgbNR /iL4Xw1hlZDXJ8jd29feF9Vh552O9rg892su2SZ9RLPff6uoKvpnrJsaW w9ZXOUjEpQOslnhWnwmd3u4fbxroVRA7RMm6ep7cJ/si9/IUMAOuGtegE RNYaBSPdRLeHOu8szri+6I4YkqVOXY2T3mfUr43yhVaVTcOt/Sqvk/7pj wdYG1avk4s5xV/zAXKcUzCNPiyjG4A173C4VA9vfXG0N0YuLBFBtq5MQq Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10894"; a="390623479" X-IronPort-AV: E=Sophos;i="6.03,304,1694761200"; d="scan'208";a="390623479" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Nov 2023 23:22:45 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10894"; a="714800296" X-IronPort-AV: E=Sophos;i="6.03,304,1694761200"; d="scan'208";a="714800296" Received: from lxy-clx-4s.sh.intel.com ([10.239.48.52]) by orsmga003.jf.intel.com with ESMTP; 14 Nov 2023 23:22:39 -0800 From: Xiaoyao Li To: Paolo Bonzini , David Hildenbrand , Igor Mammedov , "Michael S . Tsirkin" , Marcel Apfelbaum , Richard Henderson , Peter Xu , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Cornelia Huck , =?utf-8?q?Daniel_P_=2E_Berrang=C3=A9?= , Eric Blake , Markus Armbruster , Marcelo Tosatti Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org, xiaoyao.li@intel.com, Michael Roth , Sean Christopherson , Claudio Fontana , Gerd Hoffmann , Isaku Yamahata , Chenyi Qiang Subject: [PATCH v3 55/70] i386/tdx: Limit the range size for MapGPA Date: Wed, 15 Nov 2023 02:15:04 -0500 Message-Id: <20231115071519.2864957-56-xiaoyao.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231115071519.2864957-1-xiaoyao.li@intel.com> References: <20231115071519.2864957-1-xiaoyao.li@intel.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Isaku Yamahata If the range for TDG.VP.VMCALL is too large, process the limited size and return retry error. It's bad for VMM to take too long time, e.g. second order, with blocking vcpu execution. It results in too many missing timer interrupts. Signed-off-by: Isaku Yamahata Signed-off-by: Xiaoyao Li --- target/i386/kvm/tdx.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/target/i386/kvm/tdx.c b/target/i386/kvm/tdx.c index b17258f17fd0..96a10b0bb190 100644 --- a/target/i386/kvm/tdx.c +++ b/target/i386/kvm/tdx.c @@ -1061,12 +1061,16 @@ static hwaddr tdx_shared_bit(X86CPU *cpu) return (cpu->phys_bits > 48) ? BIT_ULL(51) : BIT_ULL(47); } +/* 64MB at most in one call. What value is appropriate? */ +#define TDX_MAP_GPA_MAX_LEN (64 * 1024 * 1024) + static void tdx_handle_map_gpa(X86CPU *cpu, struct kvm_tdx_vmcall *vmcall) { hwaddr shared_bit = tdx_shared_bit(cpu); hwaddr gpa = vmcall->in_r12 & ~shared_bit; bool private = !(vmcall->in_r12 & shared_bit); hwaddr size = vmcall->in_r13; + bool retry = false; int ret = 0; vmcall->status_code = TDG_VP_VMCALL_INVALID_OPERAND; @@ -1085,12 +1089,25 @@ static void tdx_handle_map_gpa(X86CPU *cpu, struct kvm_tdx_vmcall *vmcall) return; } + if (size > TDX_MAP_GPA_MAX_LEN) { + retry = true; + size = TDX_MAP_GPA_MAX_LEN; + } + if (size > 0) { ret = kvm_convert_memory(gpa, size, private); } if (!ret) { - vmcall->status_code = TDG_VP_VMCALL_SUCCESS; + if (retry) { + vmcall->status_code = TDG_VP_VMCALL_RETRY; + vmcall->out_r11 = gpa + size; + if (!private) { + vmcall->out_r11 |= shared_bit; + } + } else { + vmcall->status_code = TDG_VP_VMCALL_SUCCESS; + } } }