Received: by 2002:ab2:69cc:0:b0:1f4:be93:e15a with SMTP id n12csp259295lqp; Fri, 12 Apr 2024 17:40:49 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVULu4LGdGHMwIKLT1ZIFZI/eqFCwKlNFu+cDjRgw3zd4C/orr5uXVK/zwkb6bmi99wYxXQDhFhzoUjU7rNSdxehiO/z9B/2lnJjH9mKA== X-Google-Smtp-Source: AGHT+IGHehGxUSmljllBX6hJVlb88BNNN+gWavzC7MY2eLOCSrE4JSCF/mYdgs/VAPTwa9LYeTr6 X-Received: by 2002:a05:6a00:1390:b0:6ea:bb00:dbb6 with SMTP id t16-20020a056a00139000b006eabb00dbb6mr4802243pfg.8.1712968849549; Fri, 12 Apr 2024 17:40:49 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712968849; cv=pass; d=google.com; s=arc-20160816; b=S2jfk6sjjITHh4svhbnpcI4x20psL/gQu5GjTlgj2nT655YFikvLEDcjrpKmk4Q0DL EtcGG0YiA9apashgUgQmHDhEhnhuX128fbmH2qQLJKHgWVuov17NBXyDvqRkTbuQ4szE 5FSwvhF2Ag96UiINCewriHadGXxFZkhJ7GwrbyCZS9Cz9N6tIoJIQG59EogH/p44xpDb PDszkASuuONPQ3uQhDb0MoC/zxK7FiGvjj4+ThF2vlaBDpQyxljDHQnpiftHxqlvUQaz dQDHWan21zPIKz9DidiBc2BFFYBgJx850aLEdzkq8fpIu7B1g6cMgVE6XrzH0TJhrWvI B6lQ== 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=BCQjHiGzxw7kiyR2kCjIwTumGE9fyc4qfUzB7KJ3SR8=; fh=L9f02vpVZo600kc53cBakbdX0PzoeO0NeB9pPguEteo=; b=DSjDS+UYYlg9rGwOVv+azg6EUCaxfaRcba8MZ+ZHjAf1I2g+R1pCCNZmpSf+kKtfPA Y0BUlRofDffjX0uOZmmvenTtOFDwmvJ5OYoAlupz/z+IYzqBGbUXfaY4Zi7RSbsLXn13 bvzZOQVYhD0LzMfhDeE/4VT/5b4BMfNH1r01X3id9x7QUYmYkWDe46xY2cut842V/eK6 Z9dkx5hsUISJ972LxZKOriqFa+C79YmnkSAtQfrg0CigwmCaBClf+5k4EV0NA0f2sDmQ VmbGdcgMzvXwG7FvXR1Mk5TKjRlD2KwQzWi0xeud4GBT1kLr0im1mhv2v0dOzy2fs8m9 4uNA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=JVXzOag1; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-143457-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-143457-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. [147.75.48.161]) by mx.google.com with ESMTPS id ei52-20020a056a0080f400b006ed2baf9b5fsi4158666pfb.134.2024.04.12.17.40.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Apr 2024 17:40:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-143457-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=JVXzOag1; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-143457-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-143457-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 29E3FB21D39 for ; Sat, 13 Apr 2024 00:40:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1E832440C; Sat, 13 Apr 2024 00:40:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="JVXzOag1" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.11]) (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 ACA6A7E9; Sat, 13 Apr 2024 00:40:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.11 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712968836; cv=none; b=EXU2YPOkDLp0slVc46d1Kgi/EJNbvc6qu219Z7PnafcZ54gmCqJY0jNQ0BYj3DfPvdWSqtL3WvZk8JA0Nlude8IrR0/TLUT3bP1RnN4lNCOgtsVQwPjo7ONMNP/UqQnnXFrMk/roWnyIE1VY9/kuSTlY9srBALwveH6+oU6oacw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712968836; c=relaxed/simple; bh=Z10XwQjxuMwXDF/1cSayzrUktgk7iSm3++jlMAlIwJA=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=lLzbFkpT+C1/mL/XoC/A21Obxh+r5Qq51V4mDmytGJxjV34LP7KdLX6xzZ5oUsSfdhPHRILmnmi//NWG6t79aXgvpEpE+0HrOtmjSBPOxmddcfWWrlvisHoTGCMzVPBPIPZQf/6FfGQ5fcWWguv1tG7Pnhf1LNd5wuMsbFCv6G0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=JVXzOag1; arc=none smtp.client-ip=192.198.163.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=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=1712968834; x=1744504834; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=Z10XwQjxuMwXDF/1cSayzrUktgk7iSm3++jlMAlIwJA=; b=JVXzOag1IvWsZChBDprDDtuz4rXqMyJk42Lj57sRzuUClnQYsREkjmvl zZyDJo9iwLNTmOX9yNLsn6Ihsm0vWk3wGmoP+bMxyAXbUMc55sL6g2ePO kRXXOJk1yQknZPYSZssrLLNB5VuUbkEa0/x1lpbAI0XcWvD+GkrLTbF1J JmwG7YEElQqoauUuva6ldfPDXve5QY8sv8BwIej6R02l3A7NVBz+Df2ui +hEr/67Tlcz9z1EQn7Gpf1d3qhDiJbHs5X99mYUdKPpOTahvg7FlHVij5 +XETh+ptSPZEACp1l1UVhXYPRBJ/qXwLeaSDYrC8yeQ1SyswvbZ2H4ky1 w==; X-CSE-ConnectionGUID: Ihqbk3h5QdaWy7NA1RNHfw== X-CSE-MsgGUID: 0BRL+2QrQpOe4BYl9nXDsA== X-IronPort-AV: E=McAfee;i="6600,9927,11042"; a="19044707" X-IronPort-AV: E=Sophos;i="6.07,197,1708416000"; d="scan'208";a="19044707" Received: from orviesa009.jf.intel.com ([10.64.159.149]) by fmvoesa105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Apr 2024 17:40:33 -0700 X-CSE-ConnectionGUID: TiJFT1IvTOWAT+qhIZD25g== X-CSE-MsgGUID: N0CR4kfuS56j9VXpeJQ8mw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,197,1708416000"; d="scan'208";a="21373992" Received: from ls.sc.intel.com (HELO localhost) ([172.25.112.31]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Apr 2024 17:40:32 -0700 Date: Fri, 12 Apr 2024 17:40:31 -0700 From: Isaku Yamahata To: Sean Christopherson Cc: Isaku Yamahata , Reinette Chatre , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, isaku.yamahata@gmail.com, Paolo Bonzini , erdemaktas@google.com, Sagi Shahar , Kai Huang , chen.bo@intel.com, hang.yuan@intel.com, tina.zhang@intel.com, isaku.yamahata@linux.intel.com Subject: Re: [PATCH v19 087/130] KVM: TDX: handle vcpu migration over logical processor Message-ID: <20240413004031.GQ3039520@ls.amr.corp.intel.com> References: <0c3efffa-8dd5-4231-8e90-e0241f058a20@intel.com> <20240412214201.GO3039520@ls.amr.corp.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: On Fri, Apr 12, 2024 at 03:46:05PM -0700, Sean Christopherson wrote: > On Fri, Apr 12, 2024, Isaku Yamahata wrote: > > On Fri, Apr 12, 2024 at 09:15:29AM -0700, Reinette Chatre wrote: > > > > +void tdx_mmu_release_hkid(struct kvm *kvm) > > > > +{ > > > > + while (__tdx_mmu_release_hkid(kvm) == -EBUSY) > > > > + ; > > > > } > > > > > > As I understand, __tdx_mmu_release_hkid() returns -EBUSY > > > after TDH.VP.FLUSH has been sent for every vCPU followed by > > > TDH.MNG.VPFLUSHDONE, which returns TDX_FLUSHVP_NOT_DONE. > > > > > > Considering earlier comment that a retry of TDH.VP.FLUSH is not > > > needed, why is this while() loop here that sends the > > > TDH.VP.FLUSH again to all vCPUs instead of just a loop within > > > __tdx_mmu_release_hkid() to _just_ resend TDH.MNG.VPFLUSHDONE? > > > > > > Could it be possible for a vCPU to appear during this time, thus > > > be missed in one TDH.VP.FLUSH cycle, to require a new cycle of > > > TDH.VP.FLUSH? > > > > Yes. There is a race between closing KVM vCPU fd and MMU notifier release hook. > > When KVM vCPU fd is closed, vCPU context can be loaded again. > > But why is _loading_ a vCPU context problematic? It's nothing problematic. It becomes a bit harder to understand why tdx_mmu_release_hkid() issues IPI on each loop. I think it's reasonable to make the normal path easy and to complicate/penalize the destruction path. Probably I should've added comment on the function. -- Isaku Yamahata