Received: by 2002:a05:6500:1b45:b0:1f5:f2ab:c469 with SMTP id cz5csp995014lqb; Wed, 17 Apr 2024 18:10:14 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVrq5WB9iihNUmuy7UCiOszsCDrRCGCLTbf+WwPPS6XhJ2WQ7QeLNxKhGCH36IWGQTcNc+UtCRNs4XywmcZKaOvUBMDPBsMWbpSLHy+1g== X-Google-Smtp-Source: AGHT+IEq5rs//bb+4xGE+tMyGGxtNmfABc9d4CioJ/ULbyfCyAwEqdfFPlz+iMuxjn3ZhJm4MRAu X-Received: by 2002:a17:906:28d6:b0:a55:41fd:a013 with SMTP id p22-20020a17090628d600b00a5541fda013mr755423ejd.23.1713402614628; Wed, 17 Apr 2024 18:10:14 -0700 (PDT) Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id cm15-20020a170906f58f00b00a5559e70c1csi222890ejd.254.2024.04.17.18.10.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Apr 2024 18:10:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-149381-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="SCo/jink"; arc=fail (signature failed); spf=pass (google.com: domain of linux-kernel+bounces-149381-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-149381-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 3521A1F21727 for ; Thu, 18 Apr 2024 01:10:14 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EC59324B4A; Thu, 18 Apr 2024 01:09:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="SCo/jink" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.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 CD05053AC; Thu, 18 Apr 2024 01:09:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=192.198.163.9 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713402592; cv=fail; b=OkGSHutn3fO0Mk4sn8sur3+8h7uM4uSHee67TZtkScUlxZiMusGANDXjBGb5GhwfmHVBQYHfITmYJeq8r6ybIvCos+YTNwZTWwGsPvN1Gh67Udc3IZBJphLQu/7As12+0kV3Y/dxI2bX4D4J1gE6RMNZbidV4xQXouH5Ix+HBQc= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713402592; c=relaxed/simple; bh=X0mTM25pvuVJu0sNOILs5kY9oKOKmY10kiN3qMauWdQ=; h=Message-ID:Date:Subject:To:CC:References:From:In-Reply-To: Content-Type:MIME-Version; b=YTqLoMkB9LTSnoXDCY4LgOedfQqRJK+WemTC9CZWZo2gnCg54PVBK3a0kvFGOKQw5M8S4lGe5WvR2yJ8X1WVhfNzUDdj1/sSYo48N9wwNTQRXyLzsr0flnduPToUFaSH3A8W1w/pd/pN25VZifZikFun9JkCI4NaNK1UfRVR5+k= ARC-Authentication-Results:i=2; 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=SCo/jink; arc=fail smtp.client-ip=192.198.163.9 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=1713402591; x=1744938591; h=message-id:date:subject:to:cc:references:from: in-reply-to:content-transfer-encoding:mime-version; bh=X0mTM25pvuVJu0sNOILs5kY9oKOKmY10kiN3qMauWdQ=; b=SCo/jinkE0IMBL6muVukl64VmnngAlM6NSuvrh6Ju0LzYqtTlJYNS05w 7EyNJuP/tscVEjOAF9vm6tGxpRgNfjCy9Y95ZaAF9TqZUHuq8v8t3yVuz zziq6vSLcli3dUHu39LJs6Wf3LqttGTt6Xtq7H8cZH7mdH5A38rlVQJ00 GrExwp1b3oxxqrMA0ezYhDbmacZVdvGJrsQMHI8IpaILsHLeeqpe6rJB9 WzURfTR21vcrn93VFvVFewgK7ofppRbzKXKY72FBeCdGW18nxEC+YEW/C q5VjNbnGx/Wm/+RB4zcRA2G5OwOgci4zPGnuW+5vIC//i94Z0sx3FhGeQ w==; X-CSE-ConnectionGUID: na23GvwKTMW7gAYUEYfv1A== X-CSE-MsgGUID: 6e9pCN9bQUSmvD1hTr2CmQ== X-IronPort-AV: E=McAfee;i="6600,9927,11047"; a="19627829" X-IronPort-AV: E=Sophos;i="6.07,210,1708416000"; d="scan'208";a="19627829" Received: from fmviesa008.fm.intel.com ([10.60.135.148]) by fmvoesa103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Apr 2024 18:09:47 -0700 X-CSE-ConnectionGUID: o39bujFVQE++AbjuOifc6A== X-CSE-MsgGUID: PWaUS4tCR/qLVVeaUshaZA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,210,1708416000"; d="scan'208";a="22896776" Received: from orsmsx602.amr.corp.intel.com ([10.22.229.15]) by fmviesa008.fm.intel.com with ESMTP/TLS/AES256-GCM-SHA384; 17 Apr 2024 18:09:46 -0700 Received: from orsmsx610.amr.corp.intel.com (10.22.229.23) by ORSMSX602.amr.corp.intel.com (10.22.229.15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Wed, 17 Apr 2024 18:09:46 -0700 Received: from orsmsx602.amr.corp.intel.com (10.22.229.15) by ORSMSX610.amr.corp.intel.com (10.22.229.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Wed, 17 Apr 2024 18:09:45 -0700 Received: from orsedg603.ED.cps.intel.com (10.7.248.4) by orsmsx602.amr.corp.intel.com (10.22.229.15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35 via Frontend Transport; Wed, 17 Apr 2024 18:09:45 -0700 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (104.47.56.168) by edgegateway.intel.com (134.134.137.100) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.35; Wed, 17 Apr 2024 18:09:45 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=j25/2ZyqRKZ7aktOcixCyoVz7z3SSoTYjo1aqYqeVGW2/HuNiuJFksy+AM0o26X/M/dABuGgr4eBYYwV0Cuocenitr4A8TEkxxG/iqI/tiU7src1ncl8EtWqSr+0I8QhwcIJb8hqzVXkIsCaLt5L9/ePzB97T0a3RY17xnUtlsxu6b9GfqbDVJB9ukbzEmGdGxOREl+3f/4S5R2FaKojIax93BGHMa9JaU+YWReXscUNxH+7uk5GMoejnuwutW/syGFOFDJkXTxbBaO5lNcznGnfYu26wUMYuOAy2K1wFXwy+ofHJwInFW5PGnb0GdSguls9WlHFsr9UdPSvli8SvA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Cl2zoA2L2KHnxWCIJi+2YQcr5L8ul8MMwExQ1ezhusw=; b=O7fHnq7qNnDY0AZVQG9wMnnTn29ew9pVIoMv14zgoOvFnuFwct0mFTmPPNJL69IyEO9QcLsf1Uv0YVTuGYdl36jLG9qEOsXFFvupDHpXzWNzRT/v4JfWHZte6nPrAMLPv4yYXxCBe8tlpBCs/RU5FQD3unzIovZxVcvszQz+yi1GPGhZaP4xLS1QXmh+WK4gUmUqLDIRV9K8Buv4b2F4cIVXXUSddGZ9+NiwGyZ1HT6sMs2YTYcT4bgBdqb1toJY5K6BpEzO2HN9agYp65rZI8Xw8u73IEqO8QLsC0SDZ1raUVjV72jCHegKbyYw8TShzHvhZVRA7zV83ZRTQYljDA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; Received: from BL1PR11MB5978.namprd11.prod.outlook.com (2603:10b6:208:385::18) by SA1PR11MB5778.namprd11.prod.outlook.com (2603:10b6:806:23f::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7472.26; Thu, 18 Apr 2024 01:09:42 +0000 Received: from BL1PR11MB5978.namprd11.prod.outlook.com ([fe80::ef2c:d500:3461:9b92]) by BL1PR11MB5978.namprd11.prod.outlook.com ([fe80::ef2c:d500:3461:9b92%4]) with mapi id 15.20.7472.037; Thu, 18 Apr 2024 01:09:42 +0000 Message-ID: Date: Thu, 18 Apr 2024 13:09:31 +1200 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v19 087/130] KVM: TDX: handle vcpu migration over logical processor To: Isaku Yamahata CC: Sean Christopherson , "Chatre, Reinette" , "kvm@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "isaku.yamahata@gmail.com" , Paolo Bonzini , "Aktas, Erdem" , Sagi Shahar , "Chen, Bo2" , "Yuan, Hang" , "Zhang, Tina" , "isaku.yamahata@linux.intel.com" References: <0c3efffa-8dd5-4231-8e90-e0241f058a20@intel.com> <20240412214201.GO3039520@ls.amr.corp.intel.com> <20240413004031.GQ3039520@ls.amr.corp.intel.com> <20240415224828.GS3039520@ls.amr.corp.intel.com> <20240416164432.GZ3039520@ls.amr.corp.intel.com> Content-Language: en-US From: "Huang, Kai" In-Reply-To: <20240416164432.GZ3039520@ls.amr.corp.intel.com> Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 7bit X-ClientProxiedBy: BY5PR03CA0004.namprd03.prod.outlook.com (2603:10b6:a03:1e0::14) To BL1PR11MB5978.namprd11.prod.outlook.com (2603:10b6:208:385::18) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL1PR11MB5978:EE_|SA1PR11MB5778:EE_ X-MS-Office365-Filtering-Correlation-Id: 205d5ba5-6d6e-4dde-4ff5-08dc5f443a83 X-LD-Processed: 46c98d88-e344-4ed4-8496-4ed7712e255d,ExtAddr X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: w/nIndK8QOaScLvu+F+TAduJuU16ah0trUo8yLv9vy1ro/tMj9neae8hQ+ARDw2RMXNtHXnBXRuHIQoVkQEx2+BC9QqrpkUYFHoinljWSon/bIppWsn9RvEKOfFFilXIPSvZAdzdZawWYaj8OPf4vXf+UzudmE9vQ2mWhqUVaO9YtBkEa4tlesGjPJ+aPKPUk1eA/sLsctKfZDUVuxlaZv4CePNE4BcIHnR6zlTArrYq/dvNu65F4wA6GKqJGDPDDyFk6O+WXGFRX31lge7AIZZSr5lNCB4pLdWIc0rMiq+r0r3X7v1/wdYF4jbIZFjQq92PpA1f7hippNWXnR/rl24+9vNV9dbaNuD9axqUel/nhbRvNtVbBwKe09GsUqhxfVZQneCq/yIOqZVIPFrc2IbI1+7pP5apSkHSrQQK7hIZjw6CGsK0dQ7VzNZlXCvkU2VuCsthKUsCLyiQN5wgZArEukhz9+FK5g8G7Snp4yguuJ3n5Dg8lga2Ss3ESkyRFk7PG8B/I5nn9yw/A8hcAaEgjGw9EuoS6YHApTKAg+U58TCODDsCemXBaJYTt7O6e8zQleCDM+qazlUZ0LNOE0bV5x8n/6PGUdgcPTH7JeKPh3z3TZHSMkgmgo89dd/2nA19URKAqae16wnM7aUajs1QAEClZG6dK9/VP5jNczs= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BL1PR11MB5978.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(366007)(1800799015)(376005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?bjhTWlVESkZodURWRnJNaTI2U2JSZWptM3FPbVNMM1pvZHEvVjJlRjQ5WFRF?= =?utf-8?B?YTdRb29CanBsNXRBbXFVYU80WWtWV2llYURQZFNJT3B4RXZFU2x0Rnk1SElH?= =?utf-8?B?UUYxNmRIYXczT3BwQ3pWSVkrc003dlhVaG95aXo2WVBGRm9RNGZnN1lvSFdv?= =?utf-8?B?RFM1WjQ2Ly81VVE1NDFDbzJ4QnhzMEQ2VTNMQmpYdjNkYXA3UnYvam1XS2JJ?= =?utf-8?B?aUQwQnNYa09EQzZzRGVNbWF6YjQ4REhCLy9oM3BYdXJr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bjJzZ0RaQ1lWSnVnaXJoVGNMaTZadnV2cGUzaWdUMGlMU2tmQmh3cVRsVFh2?= =?utf-8?Q?s7Odcjzr7krrJezeFZ2MVwZsM?= X-MS-Exchange-CrossTenant-Network-Message-Id: 205d5ba5-6d6e-4dde-4ff5-08dc5f443a83 X-MS-Exchange-CrossTenant-AuthSource: BL1PR11MB5978.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Apr 2024 01:09:42.5868 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 1EDelQdHvMhC9k+447idzrjGQsme+RemwIIJXfK3rRcP59LpJmwvpHcTM1TPl4hqUAHJdcld5R2h3unrXTxL6w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR11MB5778 X-OriginatorOrg: intel.com On 17/04/2024 4:44 am, Isaku Yamahata wrote: > On Tue, Apr 16, 2024 at 12:05:31PM +1200, > "Huang, Kai" wrote: > >> >> >> On 16/04/2024 10:48 am, Yamahata, Isaku wrote: >>> 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. >> >> I kinda lost here. >> >> I thought in the current v19 code, you have already implemented this >> optimization? >> >> Or is this optimization totally different from what we discussed in an >> earlier patch? >> >> https://lore.kernel.org/lkml/8feaba8f8ef249950b629f3a8300ddfb4fbcf11c.camel@intel.com/ > > That's only the first step. We can optimize it further with multiple vCPUs > context. OK. Let's put aside how important these optimizations are and whether they should be done in the initial TDX support, I think the right way to organize the patches is to bring functionality first and then put performance optimization later. That can make both writing code and code review easier. And more importantly, the "performance optimization" can be discussed _separately_. For example, as mentioned in the link above, I think the optimization of "releasing HKID in the MMU notifier release to improve TD teardown latency" complicates things a lot, e.g., not only to the TD creation/teardown sequence, but also here -- w/o it we don't even need to consider the race between vCPU load and MMU notifier release: https://lore.kernel.org/kvm/20240412214201.GO3039520@ls.amr.corp.intel.com/ So I think we should start with implementing these sequences in "normal way" first, and then do the optimization(s) later. And to me the "normal way" for TD creation/destruction we can just do: 1) Use normal SEPT sequence to teardown private EPT page table; 2) Do VP.FLUSH when vCPU is destroyed 3) Do VPFLUSHDONE after all vCPUs are destroyed 4) release HKID at last stage of destroying VM. For vCPU migration, you do VP.FLUSH on the old pCPU before you load the vCPU to the new pCPU, as shown in this patch. Then you don't need to cover the silly code change around tdx_mmu_release_hkid() in this patch. Am I missing anything?