Received: by 2002:ab2:69cc:0:b0:1f4:be93:e15a with SMTP id n12csp1729271lqp; Mon, 15 Apr 2024 15:48:42 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXY6EkgZ99994/HI/D1R/YueUZI08dF3ZihWD5+CuRfG/Rq1ds1Ufi/fBoPA+H55rY3hCwKc9t35c/0BsB417+2vwyRByHlHf0SQ3qELw== X-Google-Smtp-Source: AGHT+IEbrQVogO+RsoBhutPJVBZTcKPSk1WTESj99sRldoHf2+7iAP3lW5IjsY+AFodd89w3xtkf X-Received: by 2002:a2e:9e11:0:b0:2d8:54b3:954b with SMTP id e17-20020a2e9e11000000b002d854b3954bmr6975966ljk.53.1713221322472; Mon, 15 Apr 2024 15:48:42 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713221322; cv=pass; d=google.com; s=arc-20160816; b=l8ZsRQ4XQ0A5wr4Evb/WHPZtsJcpV+s5hGUvWFK+UHKcba9zdok/VAD9QHf7jlUzs8 RRALGfdAsubTV3k/+WrS81Q94fFCcek2PnUJyJ8exD9YjsJAV+1TqOaZEUKBMxTThdTq 6CqxWzZUfgOBmOiREchHEp4kjvNAjpaabQCCIRFHcYNpPTgzWdsd5vaELAJL5h2uVSDE kPBxDwOTJRuWeUs/zY/k7+29MDcFR48ZrH7slO1MeeDeglDqlGYmGpdhHsREkxajzWWH Cc3WU6de9u8gZTbqcmCxPNZ98dNaznTgWJb3nGeY7sa5GPdiRPSx302DW6gzUTTVxeu/ 9aVw== 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=UgsEVbpnOg+cq0QWkSApgJ2q384+u1wJj/imY7bqkVw=; fh=L9f02vpVZo600kc53cBakbdX0PzoeO0NeB9pPguEteo=; b=SzuGSkfgVYbXAvPqrexbFNn7KdlRHEpxG09tqID2404gk4m3GgaMpDOBPfO1/vda1Y 05mDlkJFEaz6QrRpIf2wCxj+c2Hzhwu2Ioc0rBqkVDv8cwu+vRLrkpcHtENWzaBRiagC Jdhht/1ZucbXgYtJDb/7N8xMmS2FX8JgR6NTzvUSbriqT7yxtn8cV6YXWFG7F21rMIHN X+QIFqdYc1KJbnDOqDuXpphu28l/OhVhGG5OkLoolWrbRTLRxVnZl7Pk7MZ4JmXt4Ajj X8KraqJhaUpafZexr0gLbKWA9qLCAcSR0LHHHIYhXOwVwvEGFDF6lLt0xvP45R9oI6Lc z0hQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=kHbzJNbX; 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-145978-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-145978-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id er14-20020a056402448e00b0056e51b8d0c2si4949653edb.412.2024.04.15.15.48.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Apr 2024 15:48:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-145978-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=kHbzJNbX; 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-145978-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-145978-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 35EC11F21F21 for ; Mon, 15 Apr 2024 22:48:42 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9F17C1586DB; Mon, 15 Apr 2024 22:48:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="kHbzJNbX" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.10]) (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 546F8156225; Mon, 15 Apr 2024 22:48:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.10 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713221311; cv=none; b=GGDyruO16hP6xJMB64meA4wOcAPCw2v0Ckim+MVYEJmr+WgU9FPMy/e50o4A/l+VtE5biBnLTBk7ypV686CyZ6MIRPIAohEkGbvyC6hnRlg7Afx/IVreAUoQW9u+VIBpbjbHZS6Vql0dgKXsZpo8GJvv2fvH8UkcuQQ6tQJ3/2c= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713221311; c=relaxed/simple; bh=nUQM7IIu77cfAfVW2e5v/L0PLjdgIG4WZ2e/s/EVWNY=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=WQjjCXVRRLKPv7Z+MY3R8n3FjfnLa/z5WYm6MTR4dyy/KP501ZDuS/CFJgog3lqRj2Fnqa9dVphYkTrlIEvMsj0lWeawH361VQYj8zpkA6PJaFudhVYWemk46JSAsyt7o3Nhnj0AYg3KQ+APiOSiUO1dbpobAPIq3dM8Zcpprn0= 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=kHbzJNbX; arc=none smtp.client-ip=192.198.163.10 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=1713221310; x=1744757310; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=nUQM7IIu77cfAfVW2e5v/L0PLjdgIG4WZ2e/s/EVWNY=; b=kHbzJNbXyTvz2acu6/1PjW3JyIWbSG3eWG3XkbxbBK8pqdEimCRlUCse HpGFiWQL//HQumEVklDTNwGoxrH5dvNfFuhwQMSDbzx+OEtuA1qgvwEoH LX5dAUKiEFc8Eb+mupJwwWFBtMUxEPfH40Xj6NfTSkGrTKDJCtjzPsJSa 8hNsBvLz1E0Z7Rpqcta/BueM6BIZVpQrKZELxNibOOF9FaNgnu1mxmQPm OA1nT1x5w7MP4/GBTAtTeD8ODNPHEEQ2gPwcxkYkD7R5pgGCHAlu0ddgu IGy0cTGeLniksIjGIPPLPU7uVNQMTBIXSjJ8JVqqUCoWmYJL5GxZOohS6 Q==; X-CSE-ConnectionGUID: hlD6TPjMTJe7nKX8iW+eRQ== X-CSE-MsgGUID: Vm0E9kw/TAWyx0YTS3KdJw== X-IronPort-AV: E=McAfee;i="6600,9927,11045"; a="20025755" X-IronPort-AV: E=Sophos;i="6.07,204,1708416000"; d="scan'208";a="20025755" Received: from fmviesa007.fm.intel.com ([10.60.135.147]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Apr 2024 15:48:29 -0700 X-CSE-ConnectionGUID: 1JIoJDmsTKW3GcwmcbntJw== X-CSE-MsgGUID: QDqeAMD/QsegfQkS7B7ytg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,204,1708416000"; d="scan'208";a="22142145" Received: from ls.sc.intel.com (HELO localhost) ([172.25.112.31]) by fmviesa007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Apr 2024 15:48:29 -0700 Date: Mon, 15 Apr 2024 15:48:28 -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: <20240415224828.GS3039520@ls.amr.corp.intel.com> References: <0c3efffa-8dd5-4231-8e90-e0241f058a20@intel.com> <20240412214201.GO3039520@ls.amr.corp.intel.com> <20240413004031.GQ3039520@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 Mon, Apr 15, 2024 at 06:49:35AM -0700, Sean Christopherson wrote: > On Fri, Apr 12, 2024, Isaku Yamahata wrote: > > 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. > > By "problematic", I meant, why can that result in a "missed in one TDH.VP.FLUSH > cycle"? AFAICT, loading a vCPU shouldn't cause that vCPU to be associated from > the TDX module's perspective, and thus shouldn't trigger TDX_FLUSHVP_NOT_DONE. > > I.e. looping should be unnecessary, no? The loop is unnecessary with the current code. The possible future optimization is to reduce destruction time of Secure-EPT somehow. One possible option is to release HKID while vCPUs are still alive and destruct Secure-EPT with multiple vCPU context. Because that's future optimization, we can ignore it at this phase. -- Isaku Yamahata