Received: by 2002:ab2:b82:0:b0:1f3:401:3cfb with SMTP id 2csp424613lqh; Thu, 28 Mar 2024 06:22:00 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXskUuyg4chrBNzOTqdwtj9DjPRxR17/g+VgXo/nsR8Gex3vqs1t+PopBd25T34gY0bVyoB1LqVBisxNIq2hcVbm5tMRxGf22C2dc2c8A== X-Google-Smtp-Source: AGHT+IFgEmH1ld3PVR0DKGL4NTYbnwfg0N1AtJylPCWZICYLRvr7fF+rjuK0ATGLVDu2BSVHkN71 X-Received: by 2002:a0c:c242:0:b0:696:b114:5d8f with SMTP id w2-20020a0cc242000000b00696b1145d8fmr2258084qvh.14.1711632119682; Thu, 28 Mar 2024 06:21:59 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711632119; cv=pass; d=google.com; s=arc-20160816; b=dDl9QxUexZEqGm5X/86GlgdHsahknPYLkJvLkPCP1xty16MdWmMUpcd8kgimFP/f8V fsH7d8mdqHpgsBXZu9hfmcfSc/3ExFpBU1f6UdhluR7W6iHyC/giByXwnGqDj4v8wG9k HmtkOh3T9VoSdfE+GO34dBOc2F9KxhAzQVVL4lIyjrcrWOjQ0CSGidQJdh9Ph47Afy5L aKC9wiYLj0OIqDu+uo1DrUVktcb7grc6tvSCKflZhJ8hpA/lk4N61EGczXtFiYS5WChP 927A84yt+SpBP2naU1jaf8zrCYZxTpcbbxgcx+cVglX5KhEBv4IC+vAW8266c/5ZbjBf 03wg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=+j13Kdv5QihWywK2a+FTahVeI3BhqezeJ2jDr5TcyUE=; fh=i/bfdwaFLbfFDSWRYvm8E8RifgyvCNTOKgKcNf3KTsY=; b=aAVGtq7LZoB1B8HzCgIRKJc/ohnrytx/fCix9Sw2Y/NiCElWxD6lDRgmcMcm5XYhqt ICR0C4HpDC4WVqgsFbz2CP70x4cbI5zD+LwUnXwjmT9h1jXuOuyWu86sc5w1L+briyp1 hQXAwTbn3C6tub2+au9FVE0Ve+jqQvorNaEXWS73HsoPpuX6E2kZwfzLpoSUYWqzYVH2 682VDVdaqpzFrUfqZuwdGO0Ze6+wunZyaqIv6bI2OuWq0qhwWe3uxbnaVpbRBW84dtFE i+2Hyit3sJlOM45wdfLKmb6SDo7/rqNaD18dLCp6KNJK8EKCqJBSWUBGOLBw+3YtutX3 q7bw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Cfl2+mhk; 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-122947-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-122947-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id q16-20020a0cfa10000000b0069687e15086si1375556qvn.380.2024.03.28.06.21.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Mar 2024 06:21:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-122947-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Cfl2+mhk; 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-122947-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-122947-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 2C1061C233B8 for ; Thu, 28 Mar 2024 13:21:59 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E3D0E80616; Thu, 28 Mar 2024 13:21:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="Cfl2+mhk" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.16]) (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 5A3C47D3E7; Thu, 28 Mar 2024 13:21:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.16 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711632106; cv=none; b=Gypjxh3rLhDstSfg6al+ChMCdNtKq7An7obG2LpBWcvHmZ26v0GqVLrElfl8BKczjCgVgLep6eFVizbCbdaSvhABaBCpRgtpvQcSGOno1irJub5snEPTr8v7mWh6ck24UVfl9o+uonGbetqiR5UFUyZJTvyE6wl9fzl/Y7b+NRk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711632106; c=relaxed/simple; bh=b3jNS8gEcTwmueSbmAZyxea0/9+2+uixNOONc4qQGxU=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=eDmOBPge6cep/4t9T1P2YCs0gDJLQvMHaGU17wPIstfT2winzIqJsc8GmB/3nHVghDMK/0CiU1vxiaeCyeU+sf+pUFHO0h3CpzXLLZEZEZFgqFmMXLiVp1sxcNwNJax+wRLjDmrC0F2czcq9W2g7i1OY+Vc8tcgfu2H5fNX8Fes= 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=Cfl2+mhk; arc=none smtp.client-ip=192.198.163.16 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=1711632105; x=1743168105; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=b3jNS8gEcTwmueSbmAZyxea0/9+2+uixNOONc4qQGxU=; b=Cfl2+mhkym1UcEw5K7kU+kEVpqDUov1Basqp2dcQn4bY+Tww4Msr6t+Q jDk7Fendal8fBukXzOwCAQv125vb9i+0GoZZ+O+3gP+G3ESn2UMazFgre nn7jwDJxpoifgvNZVtmjOtxHIZIfjpPgkRwZxIr7hswTgNVoD5OdKogMn x0CHoSyu9+v/cqwDRP15TGjTtaRPAZJ/j7LgnCYYINqFd6slHHr/yFC11 vKwcY5wyOXhZD3D1lAwQBQaad0SJ0EcuYt2dUSI4kS+d57fNoqKZm8HKd DD79OVzbTbS1ffBPow8BNbSxb6VqTmlht59nGp+tHDGvP6O0XL+wEY/4V A==; X-CSE-ConnectionGUID: AYHDKjCNToWhQKjlL0N9gA== X-CSE-MsgGUID: sl/2rkjPQ2S+EjmHJvYXEg== X-IronPort-AV: E=McAfee;i="6600,9927,11026"; a="7382977" X-IronPort-AV: E=Sophos;i="6.07,161,1708416000"; d="scan'208";a="7382977" Received: from orviesa003.jf.intel.com ([10.64.159.143]) by fmvoesa110.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Mar 2024 06:21:44 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,161,1708416000"; d="scan'208";a="21294611" Received: from xiaoyaol-hp-g830.ccr.corp.intel.com (HELO [10.124.224.7]) ([10.124.224.7]) by ORVIESA003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Mar 2024 06:21:41 -0700 Message-ID: <234c9998-c314-44bb-ad96-6af2cece7465@intel.com> Date: Thu, 28 Mar 2024 21:21:37 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v19 059/130] KVM: x86/tdp_mmu: Don't zap private pages for unsupported cases To: Chao Gao Cc: "Edgecombe, Rick P" , "Yamahata, Isaku" , "Zhang, Tina" , "seanjc@google.com" , "Huang, Kai" , "Chen, Bo2" , "sagis@google.com" , "isaku.yamahata@gmail.com" , "linux-kernel@vger.kernel.org" , "Aktas, Erdem" , "isaku.yamahata@linux.intel.com" , "pbonzini@redhat.com" , "Yuan, Hang" , "kvm@vger.kernel.org" References: <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> <5f07dd6c-b06a-49ed-ab16-24797c9f1bf7@intel.com> <20ef977a-75e5-4bbc-9acf-fa1250132138@intel.com> <783d85acd13fedafc6032a82f202eb74dc2bd214.camel@intel.com> Content-Language: en-US From: Xiaoyao Li In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 3/28/2024 6:17 PM, Chao Gao wrote: > On Thu, Mar 28, 2024 at 11:40:27AM +0800, Xiaoyao Li wrote: >> On 3/28/2024 11:04 AM, Edgecombe, Rick P wrote: >>> On Thu, 2024-03-28 at 09:30 +0800, Xiaoyao Li wrote: >>>>> The current ABI of KVM_EXIT_X86_RDMSR when TDs are created is nothing. So I don't see how this >>>>> is >>>>> any kind of ABI break. If you agree we shouldn't try to support MTRRs, do you have a different >>>>> exit >>>>> reason or behavior in mind? >>>> >>>> Just return error on TDVMCALL of RDMSR/WRMSR on TD's access of MTRR MSRs. >>> >>> MTRR appears to be configured to be type "Fixed" in the TDX module. So the guest could expect to be >>> able to use it and be surprised by a #GP. >>> >>> { >>> "MSB": "12", >>> "LSB": "12", >>> "Field Size": "1", >>> "Field Name": "MTRR", >>> "Configuration Details": null, >>> "Bit or Field Virtualization Type": "Fixed", >>> "Virtualization Details": "0x1" >>> }, >>> >>> If KVM does not support MTRRs in TDX, then it has to return the error somewhere or pretend to >>> support it (do nothing but not return an error). Returning an error to the guest would be making up >>> arch behavior, and to a lesser degree so would ignoring the WRMSR. >> >> The root cause is that it's a bad design of TDX to make MTRR fixed1. When >> guest reads MTRR CPUID as 1 while getting #VE on MTRR MSRs, it already breaks >> the architectural behavior. (MAC faces the similar issue , MCA is fixed1 as > > I won't say #VE on MTRR MSRs breaks anything. Writes to other MSRs (e.g. > TSC_DEADLINE MSR) also lead to #VE. If KVM can emulate the MSR accesses, #VE > should be fine. > > The problem is: MTRR CPUID feature is fixed 1 while KVM/QEMU doesn't know how > to virtualize MTRR especially given that KVM cannot control the memory type in > secure-EPT entries. yes, I partly agree on that "#VE on MTRR MSRs breaks anything". #VE is not a problem, the problem is if the #VE is opt-in or unconditional. For the TSC_DEADLINE_MSR, #VE is opt-in actually. CPUID(1).EXC[24].TSC_DEADLINE is configurable by VMM. Only when VMM configures the bit to 1, will the TD guest get #VE. If VMM configures it to 0, TD guest just gets #GP. This is the reasonable design. >> well while accessing MCA related MSRs gets #VE. This is why TDX is going to >> fix them by introducing new feature and make them configurable) >> >>> So that is why I lean towards >>> returning to userspace and giving the VMM the option to ignore it, return an error to the guest or >>> show an error to the user. >> >> "show an error to the user" doesn't help at all. Because user cannot fix it, >> nor does QEMU. > > The key point isn't who can fix/emulate MTRR MSRs. It is just KVM doesn't know > how to handle this situation and ask userspace for help. > > Whether or how userspace can handle the MSR writes isn't KVM's problem. It may be > better if KVM can tell userspace exactly in which cases KVM will exit to > userspace. But there is no such an infrastructure. > > An example is: in KVM CET series, we find it is complex for KVM instruction > emulator to emulate control flow instructions when CET is enabled. The > suggestion is also to punt to userspace (w/o any indication to userspace that > KVM would do this). Please point me to decision of CET? I'm interested in how userspace can help on that. >> >>> If KVM can't support the behavior, better to get an actual error in >>> userspace than a mysterious guest hang, right? >> What behavior do you mean? >> >>> Outside of what kind of exit it is, do you object to the general plan to punt to userspace? >>> >>> Since this is a TDX specific limitation, I guess there is KVM_EXIT_TDX_VMCALL as a general category >>> of TDVMCALLs that cannot be handled by KVM. > > Using KVM_EXIT_TDX_VMCALL looks fine. > > We need to explain why MTRR MSRs are handled in this way unlike other MSRs. > > It is better if KVM can tell userspace that MTRR virtualization isn't supported > by KVM for TDs. Then userspace should resolve the conflict between KVM and TDX > module on MTRR. But to report MTRR as unsupported, we need to make > GET_SUPPORTED_CPUID a vm-scope ioctl. I am not sure if it is worth the effort. My memory is that Sean dislike the vm-scope GET_SUPPORTED_CPUID for TDX when he was at Intel. Anyway, we can provide TDX specific interface to report SUPPORTED_CPUID in KVM_TDX_CAPABILITIES, if we really need it. > >> >> I just don't see any difference between handling it in KVM and handling it in >> userspace: either a) return error to guest or b) ignore the WRMSR.