From nobody Wed Nov 27 08:42:21 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1700032994; cv=none; d=zohomail.com; s=zohoarc; b=fSXZJi8tvSJg3mofZnGXyvHuutNjEQh/SxG4nADlFUeiWylgcXFEVjQZJNZCMwiW7phL8yupZe8hJf9sFzd3tfQFHMkgqMfBpGlluJ7rhhaFQHkUdO8rzzABuwX6UoR3sJS5onL+0gMbVozdxx/4e8bs19KT2ER7FP2rSPm0ul8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1700032994; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=kgqdSRMgJ366Q4WCV+AI/S5zraxjBvBDqOvkJLLWFWk=; b=Kwc3fOMydkUbwDvdum1QpOpXgWqSz5VbIKNrflE+j7pefvfZOe64U/huIYw7SciGfJj7BTIr84KbZ5sjCzNA20woDI6sMl8yuI3lyUFFlDSSmWuKINW1jZJrecy26pfA/n3wWaElBENHXvYyWtGSnQh4P4HYd/X7v8o6Ebo7zUk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1700032994300404.90355783808775; Tue, 14 Nov 2023 23:23:14 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r3AEo-0007rO-0G; Wed, 15 Nov 2023 02:23:04 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r3AEa-0007gX-Q2 for qemu-devel@nongnu.org; Wed, 15 Nov 2023 02:22:54 -0500 Received: from mgamail.intel.com ([192.55.52.115]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r3AEY-0005LS-V5 for qemu-devel@nongnu.org; Wed, 15 Nov 2023 02:22:48 -0500 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 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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1700032966; x=1731568966; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=vhVcnJA235Fj2gwGFH0mC11AUNmdkNpBg9xHCT6QPd4=; b=JknWKILmBo7EK3s+BC9x2skldrzwJhU9wSSb3xNZFdgSQBV7MJoUMyn6 DDyUL5TMbCNbw0bVbNxAJ+2j3uYw7ww3cJic13VSnvqxTu6uKXktTVYYa fAqZTquwWKucyEzNNGpQuxs/3P6WbMd74FdeLhlu0E5gYsjzLmtsZWoz4 li3Pu2Hp6r40UrGadlj2ivsOiTmTXf0kyNps61Q88RwBPAy7xIn1oUvdy znsKWc6e8ruvnZFpP9q8w6F1XQy/2ueVlmc3/cxA2q5h0DalAcY68sP90 G+nUWd90ZKhneo63rMbb5eo1VUQnB+lv3q5s3yQGCO1exMArmIFcKIzbj A==; X-IronPort-AV: E=McAfee;i="6600,9927,10894"; a="390623480" X-IronPort-AV: E=Sophos;i="6.03,304,1694761200"; d="scan'208";a="390623480" 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" From: Xiaoyao Li To: Paolo Bonzini , David Hildenbrand , Igor Mammedov , "Michael S . Tsirkin" , Marcel Apfelbaum , Richard Henderson , Peter Xu , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Cornelia Huck , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=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> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=192.55.52.115; envelope-from=xiaoyao.li@intel.com; helo=mgamail.intel.com X-Spam_score_int: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HK_RANDOM_ENVFROM=0.999, HK_RANDOM_FROM=0.999, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1700032994731100001 Content-Type: text/plain; charset="utf-8" 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); } =20 +/* 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 =3D tdx_shared_bit(cpu); hwaddr gpa =3D vmcall->in_r12 & ~shared_bit; bool private =3D !(vmcall->in_r12 & shared_bit); hwaddr size =3D vmcall->in_r13; + bool retry =3D false; int ret =3D 0; =20 vmcall->status_code =3D TDG_VP_VMCALL_INVALID_OPERAND; @@ -1085,12 +1089,25 @@ static void tdx_handle_map_gpa(X86CPU *cpu, struct = kvm_tdx_vmcall *vmcall) return; } =20 + if (size > TDX_MAP_GPA_MAX_LEN) { + retry =3D true; + size =3D TDX_MAP_GPA_MAX_LEN; + } + if (size > 0) { ret =3D kvm_convert_memory(gpa, size, private); } =20 if (!ret) { - vmcall->status_code =3D TDG_VP_VMCALL_SUCCESS; + if (retry) { + vmcall->status_code =3D TDG_VP_VMCALL_RETRY; + vmcall->out_r11 =3D gpa + size; + if (!private) { + vmcall->out_r11 |=3D shared_bit; + } + } else { + vmcall->status_code =3D TDG_VP_VMCALL_SUCCESS; + } } } =20 --=20 2.34.1