Received: by 2002:ab2:6203:0:b0:1f5:f2ab:c469 with SMTP id o3csp189799lqt; Thu, 18 Apr 2024 12:01:55 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXsWheuFvGTADIVm/pll4ej8aSzTxp3FkKnz5R16k6vEKKgsuI7S6ugZSWMKbunH+Rs2yRGGos6FMMbcft5roM/TEKcsCtdjfvXALn3yg== X-Google-Smtp-Source: AGHT+IGXdy8XxVIMUezbS1HzH2HoUxx9yiQZyjXvcEOUr6WwPSbvHsmbkfSsNU+lmXiKfh9IZeiK X-Received: by 2002:a9d:7484:0:b0:6ea:2c61:542a with SMTP id t4-20020a9d7484000000b006ea2c61542amr4354937otk.0.1713466915164; Thu, 18 Apr 2024 12:01:55 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713466915; cv=pass; d=google.com; s=arc-20160816; b=qN7AAi6pHeNJ7aSyYwu6aGhJCJiTPCpCpuyavZL49NVKPgy0I5dszB7u3Ukzeka6yq kPoOvApcFFaMuNcgRe62sEDWTJW9CT33VYmYJMCRwhkIPEf4PdzRi1ncy42oc/laYH5F bqpzTj6z4XAS8gFodzgW3WtkxTuMuwTl4wVnFSsG8H25Vq764iw2hwm+NRnM9J6P2eAr KdhKY86CrK6cIiCVojX1zd+OalJhXa+LE5FI5y0jKOKq/fzKQt4ngOSXPXu3eO8CVlqW r3ANBdAzdM9PLrDdNH+kSYGwSi6gJ5G6HJKLYUcOgS0hAOshXfMKfotrdftsufHyExZ0 Ny9Q== 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:references:cc:to:subject :user-agent:mime-version:list-unsubscribe:list-subscribe:list-id :precedence:date:message-id:dkim-signature; bh=CSfLRfbR1LZ+EjxumKxWNNpWVEEHgQCOxxJVLEsK/YA=; fh=oxfV6fPpjOQ4UDeNyM0dDAHhjThTgOkYEc1uIGPBXfg=; b=HVlXIc91pP48O4d/SrjWrEJhA6qJnl0ufYjv8vFEbb3cKfiNPJczheuIM59f3Jhmd8 3O2rXn8OkampZgJEby10jhHCwS8Z86LRFnRj1N+aspxSbkt83zYYIgdXJ9mYMUWL/h89 RzvVJfAf/hEScZti2o/h61BJVY7c6e7TZDTu1HBVHe9n4CsbucKJOvfeGbwY1Bwa1koy orniMZd9sryVIvo6hxrizjZojVuJ9Vjyvcc3xVRFUfg+mJmW6no/kLFBskTfiHCjuOc9 11zn2qELYD4a7XJZ+4cXinEm27Vzsj83dW3xVugkf8M/f3gWZnTASSE9kF1XabTBmsih 5RsQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="Wa8N0//G"; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-150180-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-150180-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 hy3-20020a67e7c3000000b0047a2a50b72csi528334vsb.357.2024.04.18.12.01.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Apr 2024 12:01:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-150180-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="Wa8N0//G"; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-150180-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-150180-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 E99BD1C22EEE for ; Thu, 18 Apr 2024 13:36:53 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C31C6161330; Thu, 18 Apr 2024 13:36:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="Wa8N0//G" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) (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 D63BD81AA2; Thu, 18 Apr 2024 13:36:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.19 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713447404; cv=none; b=dLsMpXzb1DAhcJvQPE1HqtaM5mDg4FhnRDfioa/2/fD3tYbAdeMUcjoM2xa7e9AfY8aSoCRqMZ3LnWygQICHHAvTBVyGcLYkwf/XD5qLDS73u7wqZnpmdxRilY9eeddUC9oNXRfaRd25MPI/nOLa1RRMRh2L52A6oG5UizQszYw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713447404; c=relaxed/simple; bh=nnJhdz3RIU81gHJNHF88zbSY6Ik4uNHyK5+aop10vZg=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=bn1reZRO9VPt81BUymy+FIiM3uVk0y3XM3JR4s9TT9KI3GopStKzdhMPJXnZuyxftc9rfsd0HkM7at7ks7WlTY76RGqhoLucJASSGMFkRupwsCiCsP8pSRhbdvlye6RK2K0KcsiAjnC5ijjZ5wPVDEc7wmSaEMjxgNoPoe7uFvI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=Wa8N0//G; arc=none smtp.client-ip=198.175.65.19 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1713447402; x=1744983402; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=nnJhdz3RIU81gHJNHF88zbSY6Ik4uNHyK5+aop10vZg=; b=Wa8N0//Gn2VhxkBvhIp84ct1a3jyVots7CaZYB6PZpSr5Fmr/HGbpWP0 NdIg5mZ+DL4kalFiFPVYDodrPw/DA7QMWPqPdy3tMlw/N2e4ISM/W7tu+ VqiFORTqSCG9Qprb/U/zgtm/FT0DjtRkfV9f9JXmsJTkl2DM9wKt16KQy YMILz4j5qva2UM8M++agpJ4GY+vTYp/UE2Jk5cGpoz4ckbAi0Ve/mzA/8 2/FRU+K56ha3crX13RSZKdEo7d7ieBI9l6DOUTMQYOGaMUqk1k67bgRDm 0WaOe/3pjymOp9Sx1395f/DMg80MHuRajefbBNBeQQX3wpRANplo62cdR w==; X-CSE-ConnectionGUID: dGg9lTguRWekbuqNU1SipQ== X-CSE-MsgGUID: fNQLfqDnSfaLxWif+3Dntg== X-IronPort-AV: E=McAfee;i="6600,9927,11047"; a="8866932" X-IronPort-AV: E=Sophos;i="6.07,212,1708416000"; d="scan'208";a="8866932" Received: from orviesa002.jf.intel.com ([10.64.159.142]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Apr 2024 06:36:41 -0700 X-CSE-ConnectionGUID: zwrx9StiRcawW8mQNxNsEw== X-CSE-MsgGUID: TYbXT4BQRQ6ozsUBxTk4tw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,212,1708416000"; d="scan'208";a="53926653" Received: from binbinwu-mobl.ccr.corp.intel.com (HELO [10.124.236.140]) ([10.124.236.140]) by orviesa002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Apr 2024 06:36:38 -0700 Message-ID: <4ae8893f-b3dc-4768-887a-b6a680654479@linux.intel.com> Date: Thu, 18 Apr 2024 21:36:35 +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 111/130] KVM: TDX: Implement callbacks for MSR operations for TDX To: Isaku Yamahata , Sean Christopherson Cc: 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 References: <62f8890cb90e49a3e0b0d5946318c0267b80c540.1708933498.git.isaku.yamahata@intel.com> <20240404234238.GW2444378@ls.amr.corp.intel.com> From: Binbin Wu In-Reply-To: <20240404234238.GW2444378@ls.amr.corp.intel.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 4/5/2024 7:42 AM, Isaku Yamahata wrote: > On Wed, Apr 03, 2024 at 08:14:04AM -0700, > Sean Christopherson wrote: > >> On Mon, Feb 26, 2024, isaku.yamahata@intel.com wrote: >>> diff --git a/arch/x86/kvm/vmx/tdx.c b/arch/x86/kvm/vmx/tdx.c >>> index 389bb95d2af0..c8f991b69720 100644 >>> --- a/arch/x86/kvm/vmx/tdx.c >>> +++ b/arch/x86/kvm/vmx/tdx.c >>> @@ -1877,6 +1877,76 @@ void tdx_get_exit_info(struct kvm_vcpu *vcpu, u32 *reason, >>> *error_code = 0; >>> } >>> >>> +static bool tdx_is_emulated_kvm_msr(u32 index, bool write) >>> +{ >>> + switch (index) { >>> + case MSR_KVM_POLL_CONTROL: >>> + return true; >>> + default: >>> + return false; >>> + } >>> +} >>> + >>> +bool tdx_has_emulated_msr(u32 index, bool write) >>> +{ >>> + switch (index) { >>> + case MSR_IA32_UCODE_REV: >>> + case MSR_IA32_ARCH_CAPABILITIES: >>> + case MSR_IA32_POWER_CTL: >>> + case MSR_IA32_CR_PAT: >>> + case MSR_IA32_TSC_DEADLINE: >>> + case MSR_IA32_MISC_ENABLE: >>> + case MSR_PLATFORM_INFO: >>> + case MSR_MISC_FEATURES_ENABLES: >>> + case MSR_IA32_MCG_CAP: >>> + case MSR_IA32_MCG_STATUS: >>> + case MSR_IA32_MCG_CTL: >>> + case MSR_IA32_MCG_EXT_CTL: >>> + case MSR_IA32_MC0_CTL ... MSR_IA32_MCx_CTL(KVM_MAX_MCE_BANKS) - 1: >>> + case MSR_IA32_MC0_CTL2 ... MSR_IA32_MCx_CTL2(KVM_MAX_MCE_BANKS) - 1: >>> + /* MSR_IA32_MCx_{CTL, STATUS, ADDR, MISC, CTL2} */ >>> + return true; >>> + case APIC_BASE_MSR ... APIC_BASE_MSR + 0xff: >>> + /* >>> + * x2APIC registers that are virtualized by the CPU can't be >>> + * emulated, KVM doesn't have access to the virtual APIC page. >>> + */ >>> + switch (index) { >>> + case X2APIC_MSR(APIC_TASKPRI): >>> + case X2APIC_MSR(APIC_PROCPRI): >>> + case X2APIC_MSR(APIC_EOI): >>> + case X2APIC_MSR(APIC_ISR) ... X2APIC_MSR(APIC_ISR + APIC_ISR_NR): >>> + case X2APIC_MSR(APIC_TMR) ... X2APIC_MSR(APIC_TMR + APIC_ISR_NR): >>> + case X2APIC_MSR(APIC_IRR) ... X2APIC_MSR(APIC_IRR + APIC_ISR_NR): >>> + return false; >>> + default: >>> + return true; >>> + } >>> + case MSR_IA32_APICBASE: >>> + case MSR_EFER: >>> + return !write; >> Meh, for literally two MSRs, just open code them in tdx_set_msr() and drop the >> @write param. Or alternatively add: >> >> static bool tdx_is_read_only_msr(u32 msr){ >> { >> return msr == MSR_IA32_APICBASE || msr == MSR_EFER; >> } > Sure will add. > >>> + case 0x4b564d00 ... 0x4b564dff: >> This is silly, just do >> >> case MSR_KVM_POLL_CONTROL: >> return false; Shoud return true here, right? >> >> and let everything else go through the default statement, no? > Now tdx_is_emulated_kvm_msr() is trivial, will open code it. > > >>> + /* KVM custom MSRs */ >>> + return tdx_is_emulated_kvm_msr(index, write); >>> + default: >>> + return false; >>> + } >>> +} >>> + >>>