Received: by 2002:a05:7208:9594:b0:7e:5202:c8b4 with SMTP id gs20csp1515372rbb; Mon, 26 Feb 2024 11:43:42 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXxlzwCc+JToGHIVJEhQzF/WRVOn5CN1myMisgWBMHWUYAORNysEnRGONLGdd8IZPc76YL/q2b5Ql8IKul/VVlkHvY8i3MSDl0GAmKg+w== X-Google-Smtp-Source: AGHT+IFIYKN/qLnQStNk8ttDJMnNsH1Q28XQ/B1ZHwihhCmyAV/B91F3ea5AdKd1vEo2CuZdDNC5 X-Received: by 2002:a17:902:7805:b0:1db:f033:9f9b with SMTP id p5-20020a170902780500b001dbf0339f9bmr7320330pll.9.1708976622202; Mon, 26 Feb 2024 11:43:42 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708976622; cv=pass; d=google.com; s=arc-20160816; b=RBSYOxIsT6ZsGHuLGfTxjg65WgcOV0JV2kZQG5J/TOaN4claq+v4cBoOPDXURv9E/R QownqIOeSg0VlnrXZ3gSSgeTxJeyLxjWMH+BbmOSQREeRZIR4YE2cbS6V8vv6WRxRujB Tc5UlttMyFeObrBm0++BSnRv7YsG3z/pZu9kneRWCzUQ7xlxrGZg04obO3FavMnx7Lue UBdFQzCVeA677axT5UZ4kHkGjGiX/I9HrVSJxrmTagHhII+zG5ozAoLwAP2PtO0laRzS 9t2XYDLuTCj/GoaA+57nLLcL+Y6PB5UWKoN8VzQU4M5xz5x1kzquHgYdtrYUP6nO3OGo 42iw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=qrDWpOKnlMjRwjWk4GrWSy7q/OusrHjSPM87xF0+BIk=; fh=P/quV/w7uXmndbL78FtEpLTNkJRPx4LJS51PzREvtL8=; b=XDvn73qk/KM/vNSUx8p8Xdwp1qKVPUA5BBIP4okNonuRxHeb64vvdLPNEVL8zREILj Z8QhdtQ9X9Mo8HwcvZ4XQB9xhSHVx/1N8PGsfKlzAkRjjPNEzwKXA/XA8JioYB2YU4IK 5rVmpE3Mj1/JJfjww1BE18FttZL9Fm29CUjf5QrktajBuchYpjxiujrkdi3l0u206iA5 Nk1BHc/P1inBwYWysUkWR4XNsJf/aGpeob8BF/Wz62V+0qQ+zj4YQt4b9ODmheV7hqgT xsO0Ger2R1rL/p5d4azIEnSfbslt+yJ91nmuMf89c9XQGP6kCd0AmsZ325s+P23QZjNe gtXA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="i/rGofxx"; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-82229-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-82229-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id d8-20020a170903230800b001dc6699f553si77078plh.360.2024.02.26.11.43.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 11:43:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-82229-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="i/rGofxx"; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-82229-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-82229-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 16297B23550 for ; Mon, 26 Feb 2024 19:21:50 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3837B12F59F; Mon, 26 Feb 2024 19:21:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="i/rGofxx" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.9]) (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 E5BEE12DDAB; Mon, 26 Feb 2024 19:21:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.9 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708975301; cv=none; b=ct4uIiPheXS8KGgKSMKX2IyQbBPDnUPE9gC/ZALzfEk8t7OzuFdkpNwtiinY86itYTnFoNkaMOlpV/PcgJPj1eLB99QAsdBmNFwYfKPR121yg5cjfWEs3zYgsQwX0U+Hpgnua+hGfX6rxQ9vmH/JlBfa/ICu1Hs9IoQW7n1LYsY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708975301; c=relaxed/simple; bh=BhwZDP9hYJk+cNxTWcvUP6DCeBXECSJ839dFR9fsm+0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=UzxshBbMM0hq51+KA84EWMx0JADYz/+OGTgFjnvRbi2UyGiQ2fQAdFJ+fK6egkTXT3Buiw+0zSYrP02FhPXb0BB/q1E+8ap+Eg7DYUnfnnBH/n0K+7q829ZJLcTjtAgDxISo+f2QnE/WSG1jsQP+BrIkqi1N1Cp/A/MPyu4EHXA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=i/rGofxx; arc=none smtp.client-ip=198.175.65.9 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1708975301; x=1740511301; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=BhwZDP9hYJk+cNxTWcvUP6DCeBXECSJ839dFR9fsm+0=; b=i/rGofxxyW+jvY6VwQ0y6CB7GqSvxPRHSMZVWACITy0axE9FT49LDAJo D1pDibMZgSKDu/xLqcgB0X5V73B/9okNyWLXjlP5D0vh7fWzSQfw0f/8a iXG462b/nloL7zMJ6k6RyT6dgUsVQBfF1IcYA8U0V78NqdnOiyN3LXw+U KQW8i5xIh5kCL+6qs7h/QuOuIo4Xcru5/3RdJQ6wl3RULAvjMMIFOx8Wq qnfE+xW4agRlp7aL0qGII/ncP/mrtYTfkpfKIUc1Dc/an8/L9Gh3BSZJf D0XgX0iwU5aOXpynrGqmLUvbkqzGJEvAk2iVpE/hlRekwo++Rq16kTRDN Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10996"; a="25752823" X-IronPort-AV: E=Sophos;i="6.06,186,1705392000"; d="scan'208";a="25752823" Received: from orviesa004.jf.intel.com ([10.64.159.144]) by orvoesa101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Feb 2024 11:21:39 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,186,1705392000"; d="scan'208";a="11448181" Received: from ls.sc.intel.com (HELO localhost) ([172.25.112.31]) by orviesa004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Feb 2024 11:21:38 -0800 Date: Mon, 26 Feb 2024 11:21:37 -0800 From: Isaku Yamahata To: Binbin Wu Cc: isaku.yamahata@intel.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, isaku.yamahata@gmail.com, Paolo Bonzini , erdemaktas@google.com, Sean Christopherson , Sagi Shahar , Kai Huang , chen.bo@intel.com, hang.yuan@intel.com, tina.zhang@intel.com, isaku.yamahata@linux.intel.com Subject: Re: [PATCH v18 060/121] KVM: TDX: TDP MMU TDX support Message-ID: <20240226192137.GP177224@ls.amr.corp.intel.com> References: <9da45a6a-a40b-4768-90d0-d7de674baec1@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <9da45a6a-a40b-4768-90d0-d7de674baec1@linux.intel.com> On Tue, Jan 30, 2024 at 11:31:22PM +0800, Binbin Wu wrote: > > + > > +/* > > + * TLB shoot down procedure: > > + * There is a global epoch counter and each vcpu has local epoch counter. > > + * - TDH.MEM.RANGE.BLOCK(TDR. level, range) on one vcpu > > + * This blocks the subsequenct creation of TLB translation on that range. > > + * This corresponds to clear the present bit(all RXW) in EPT entry > > + * - TDH.MEM.TRACK(TDR): advances the epoch counter which is global. > > + * - IPI to remote vcpus > > + * - TDExit and re-entry with TDH.VP.ENTER on remote vcpus > > + * - On re-entry, TDX module compares the local epoch counter with the global > > + * epoch counter. If the local epoch counter is older than the global epoch > > + * counter, update the local epoch counter and flushes TLB. > > + */ > > +static void tdx_track(struct kvm *kvm) > > +{ > > + struct kvm_tdx *kvm_tdx = to_kvm_tdx(kvm); > > + u64 err; > > + > > + KVM_BUG_ON(!is_hkid_assigned(kvm_tdx), kvm); > > + /* If TD isn't finalized, it's before any vcpu running. */ > > + if (unlikely(!is_td_finalized(kvm_tdx))) > > + return; > > + > > + /* > > + * tdx_flush_tlb() waits for this function to issue TDH.MEM.TRACK() by > > + * the counter. The counter is used instead of bool because multiple > > + * TDH_MEM_TRACK() can be issued concurrently by multiple vcpus. > > + */ > > + atomic_inc(&kvm_tdx->tdh_mem_track); > > + /* > > + * KVM_REQ_TLB_FLUSH waits for the empty IPI handler, ack_flush(), with > > + * KVM_REQUEST_WAIT. > > + */ > > + kvm_make_all_cpus_request(kvm, KVM_REQ_TLB_FLUSH); > > + > > + do { > > + /* > > + * kvm_flush_remote_tlbs() doesn't allow to return error and > > + * retry. > > + */ > > + err = tdh_mem_track(kvm_tdx->tdr_pa); > > + } while (unlikely((err & TDX_SEAMCALL_STATUS_MASK) == TDX_OPERAND_BUSY)); > > Why the sequence of the code is different from the description of the > function. > In the description, do the TDH.MEM.TRACK before IPIs. > But in the code, do TDH.MEM.TRACK after IPIs? It's intentional to handle IPI in parallel as we already introduced tdh_mem_track. -- Isaku Yamahata