Received: by 2002:ab2:b82:0:b0:1f3:401:3cfb with SMTP id 2csp125202lqh; Wed, 27 Mar 2024 17:38:00 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVGl9RmCUJWHD2Cnq2Hw156XhaCfrnCRw6TnX4/SF5rTwt0IxEZxHGrZtRLTpxgbthvW7K599ywWPwNfInYw7h5d2z7LEDZVCSiJww65w== X-Google-Smtp-Source: AGHT+IHVzkaCa6q5SAq2Vzb7fYxsceo75v+9A1oX6mpPT+/Dx7gHoag573mhnwMNdvVg/WLG3KHU X-Received: by 2002:a05:6a20:f39d:b0:1a0:adbc:7a96 with SMTP id qr29-20020a056a20f39d00b001a0adbc7a96mr1551961pzb.36.1711586280612; Wed, 27 Mar 2024 17:38:00 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711586280; cv=pass; d=google.com; s=arc-20160816; b=q8EMBk9GIJBV9kEIbZ4d63pnQy+vfpS3Y+ymBYZ0k5+583PUsfCAn6CZy5dwcv01dk AFraoff68sNH8gw8kHSYxUZZr9LBNVUA8xvB1M+QLZIi9SWoydxTVq57AtcUFYHTkMRE d2JHLkKhozOyhFgYWtbDSf6yZu9U2RPOHGeZtzDgtmcfMAEeX2xxIeDPCarvK5fnRBVE g1FYqqYAbt55bY6ls1bZS0F3ZWElXreeWNCdPut+XSMkADzfZpQDEzRejLg0VNPpqi+L LAb9X/seDKu4R6aF1zJAIzuTVW15Bl7A5xnNW0QodehPN3xPGfTyGT4IbQ0pShWrAYJv mKoQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:message-id:subject:cc:to:from:date:dkim-signature; bh=528ysxV62M4fqYdkrNPqujVB0E8Efgt4C/GDWAk5/7M=; fh=7eFiIXU8f8XbfmaLj/HnpuZG7OC53lefmwtbCTlgCFw=; b=Od/Xu4jSOPEYtW8/wd9fYwLI237bsI/eIhcIEiLcoQwKM2nq6Apv9xFxXLXF82qaXg NM12Vl4Rq3uzxHuugIweT5gwyI2ho9fT82OIk9RUsHlqb/LDxTyV01W5Z2BM0Gw0BRDK l+Kc7dScuTkUOGnY80xeEjdt4uns1SsCtYizKi/exeM2wuVM8hAlYx3hVX+AEGNac1Lb ZF3fJ5MkfcaVzUB6wbgOzU+TR1rszmry1ewSaVkWy3jyCduQDBJJaRo5QnN+UNLP6j4v nJ2wnOmACwU5R9wmaxpV5ZtX8St/A/Ua+beD5VzJ4Z8uARIgWZVxqKqP4TysosYvgGr4 TjEA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=axSgu3pI; 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-122238-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-122238-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id c4-20020a170902b68400b001e206374109si229297pls.639.2024.03.27.17.38.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Mar 2024 17:38:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-122238-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=axSgu3pI; 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-122238-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-122238-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 68D2D2A6B4F for ; Thu, 28 Mar 2024 00:36:52 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A35491171C; Thu, 28 Mar 2024 00:36:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="axSgu3pI" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.17]) (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 17B5D817; Thu, 28 Mar 2024 00:36:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.17 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711586202; cv=none; b=OL3jiqniUZIABEl5RYDZZa0J0WNsBvvgZVFp8bMsH7Y+MHMYCeG9BBycOnfedd507bM5kUsLxcSBCL5rfaJ1d4Qgeoyxj81FxfsgVxA/AKOjJ/cPCb5dtfgAHNVKCw5mjA5g4Q2dN9/jZQG8RlGueRV+PGvwGykj+hnj5qzXabo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711586202; c=relaxed/simple; bh=bKy2b8DlGeDsZdgu01uYDVooRH0V8usjwDuPx2wkFeY=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=ViDXYriBLRe/nBPtrpomUICQeRt1xiub+EG7i+nScqTIuRAnOOPBTKu8x/ESEfqLQ6XrlS/CsyOHVITGLI8VaQqZJMyu9t3sfBZ2q0LSbZg3nI5NwTRltGEsBvTJRSjeumDWsYlCjJ2+Wl5tZbRZtgWrMaQ35+DXGLes6v8VchY= 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=axSgu3pI; arc=none smtp.client-ip=192.198.163.17 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=1711586201; x=1743122201; h=date:from:to:cc:subject:message-id:references: mime-version:content-transfer-encoding:in-reply-to; bh=bKy2b8DlGeDsZdgu01uYDVooRH0V8usjwDuPx2wkFeY=; b=axSgu3pINFmv37lkmwRFemEsboFFSATzLbisc/0W+tlYCNnnJ+FADXuJ VBluXruQNqmAw8Puny6YberExQax+RPQUrFc65DCDFYLksrobfOYYh3+o e8KzwmZbEqd69AJ7aulCM/UKJvC76hxi+EJgC78oMz+QwPGgYKy7RM3Uz yG6XubL3bGDC0+7P/3d8p9zBrd6/2MJujf9rM2SzLiNfg+e96dXDpi403 UVQ4pSgyJmwXktRDKbkCP+CZmObtMWgchacVUV+XOCkdHZPWZVjdX/q3Y K9qq33Sc4Wk8mgqPC+c2dkbeM4tm163PVgO9S5RMfWQkRYOJ2O5wMNBls w==; X-CSE-ConnectionGUID: YwhkT75tSr+/lG7ggSTZHQ== X-CSE-MsgGUID: uXuYcLYeS+mAqyXyuYF93w== X-IronPort-AV: E=McAfee;i="6600,9927,11026"; a="6583777" X-IronPort-AV: E=Sophos;i="6.07,160,1708416000"; d="scan'208";a="6583777" Received: from orviesa003.jf.intel.com ([10.64.159.143]) by fmvoesa111.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Mar 2024 17:36:38 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,160,1708416000"; d="scan'208";a="21121383" Received: from ls.sc.intel.com (HELO localhost) ([172.25.112.31]) by ORVIESA003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Mar 2024 17:36:38 -0700 Date: Wed, 27 Mar 2024 17:36:37 -0700 From: Isaku Yamahata To: Xiaoyao Li Cc: "Edgecombe, Rick P" , "Gao, Chao" , "Yamahata, Isaku" , "Zhang, Tina" , "seanjc@google.com" , "Huang, Kai" , "sean.j.christopherson@intel.com" , "Chen, Bo2" , "sagis@google.com" , "isaku.yamahata@linux.intel.com" , "linux-kernel@vger.kernel.org" , "Aktas, Erdem" , "isaku.yamahata@gmail.com" , "kvm@vger.kernel.org" , "Yuan, Hang" , "pbonzini@redhat.com" Subject: Re: [PATCH v19 059/130] KVM: x86/tdp_mmu: Don't zap private pages for unsupported cases Message-ID: <20240328003637.GM2444378@ls.amr.corp.intel.com> References: <20240325231058.GP2357401@ls.amr.corp.intel.com> <20240325233528.GQ2357401@ls.amr.corp.intel.com> <20db87741e356e22a72fadeda8ab982260f26705.camel@intel.com> <20240326174859.GB2444378@ls.amr.corp.intel.com> <481141ba-4bdf-40f3-9c32-585281c7aa6f@intel.com> <34ca8222fcfebf1d9b2ceb20e44582176d2cef24.camel@intel.com> <873263e8-371a-47a0-bba3-ed28fcc1fac0@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 Content-Transfer-Encoding: 8bit In-Reply-To: <873263e8-371a-47a0-bba3-ed28fcc1fac0@intel.com> On Thu, Mar 28, 2024 at 08:06:53AM +0800, Xiaoyao Li wrote: > On 3/28/2024 1:36 AM, Edgecombe, Rick P wrote: > > On Wed, 2024-03-27 at 10:54 +0800, Xiaoyao Li wrote: > > > > > If QEMU doesn't configure the msr filter list correctly, KVM has to handle > > > > > guest's MTRR MSR accesses. In my understanding, the > > > > > suggestion is KVM zap private memory mappings. > > TDX spec states that > > 18.2.1.4.1 Memory Type for Private and Opaque Access > > The memory type for private and opaque access semantics, which use a > private HKID, is WB. > > 18.2.1.4.2 Memory Type for Shared Accesses > > Intel SDM, Vol. 3, 28.2.7.2 Memory Type Used for Translated Guest- > Physical Addresses > > The memory type for shared access semantics, which use a shared HKID, > is determined as described below. Note that this is different from the > way memory type is determined by the hardware during non-root mode > operation. Rather, it is a best-effort approximation that is designed > to still allow the host VMM some control over memory type. > • For shared access during host-side (SEAMCALL) flows, the memory > type is determined by MTRRs. > • For shared access during guest-side flows (VM exit from the guest > TD), the memory type is determined by a combination of the Shared > EPT and MTRRs. > o If the memory type determined during Shared EPT walk is WB, then > the effective memory type for the access is determined by MTRRs. > o Else, the effective memory type for the access is UC. > > My understanding is that guest MTRR doesn't affect the memory type for > private memory. So we don't need to zap private memory mappings. So, there is no point to (try to) emulate MTRR. The direction is, don't advertise MTRR to the guest (new TDX module is needed.) or enforce the guest to not use MTRR (guest command line clearcpuid=mtrr). KVM will simply return error to guest access to MTRR related registers. QEMU or user space VMM can use the MSR filter if they want. > > > > > But guests won't accept memory again because no one > > > > > currently requests guests to do this after writes to MTRR MSRs. In this case, > > > > > guests may access unaccepted memory, causing infinite EPT violation loop > > > > > (assume SEPT_VE_DISABLE is set). This won't impact other guests/workloads on > > > > > the host. But I think it would be better if we can avoid wasting CPU resource > > > > > on the useless EPT violation loop. > > > > > > > > Qemu is expected to do it correctly.  There are manyways for userspace to go > > > > wrong.  This isn't specific to MTRR MSR. > > > > > > This seems incorrect. KVM shouldn't force userspace to filter some > > > specific MSRs. The semantic of MSR filter is userspace configures it on > > > its own will, not KVM requires to do so. > > > > I'm ok just always doing the exit to userspace on attempt to use MTRRs in a TD, and not rely on the > > MSR list. At least I don't see the problem. > > What is the exit reason in vcpu->run->exit_reason? KVM_EXIT_X86_RDMSR/WRMSR? > If so, it breaks the ABI on KVM_EXIT_X86_RDMSR/WRMSR. It's only when the user space requested it with the MSR filter. -- Isaku Yamahata