Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp173519rdb; Mon, 22 Jan 2024 16:22:30 -0800 (PST) X-Google-Smtp-Source: AGHT+IFiwyRsrcrVRjnwUZ+vrD/BmCJvq01JwbKSa4MR9hqovaPa+3aFg7O8xLmQMB5/AEkKu0yX X-Received: by 2002:aa7:9d1e:0:b0:6da:b959:3782 with SMTP id k30-20020aa79d1e000000b006dab9593782mr6622802pfp.35.1705969350580; Mon, 22 Jan 2024 16:22:30 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705969350; cv=pass; d=google.com; s=arc-20160816; b=axt2Y+rGsCZUDnC1Rft0EiDrvoS9KkCGjY/QCVsv3M5r9j3b0btiV41xVjeqW4xcSI 8D1TKwutVp4mij7y7A9dvWgkuKzd9nca3eWPQEEe+RDh+l72DN7DSJ1SKFXy9Tnq9WWt CLhctyejvWf6nj49OmLAGpeX7IjaNMSIC4RRXgqtTC30spI/tOnN5A7fJ3brXjHrYBHa xBAC1m6Ef8ghWV31WgzoT3fzm3FoinxWh/7UEPXvdfoNKdyPU/VOjuhXS+YShv3blwEY wQQ5++cfSuQVKI+ktba/vmbiN8rSTxwO+vTqVePJRknTd0S5w59vkmZ9S0yVaJPmPGXO UAEw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=+dRcH+fawfEoOEO9EGGyGUr6qFE5u3BJbRmrGY9BraI=; fh=Itbyk7CEvizIrzGEESCqq3I2tZgG1kc/GkVOa3S7Hsg=; b=piRwjW+ysWiRLB/qie9xeqHhnmVIZ9fQMhCc2+kQUTx8M6YoGDGpmWO5zqjrji66rJ 6Unds8aZEPoAcVzee37NQk5pKgZlt668VPiCvjnfroz/QE/jC/nBLBccuJjK7ZPiS9C3 NTguK3clPjzH0h1BQvgcwaof/5IaeujzQO+27vvGl6zIbP63/9dmve/Pr73SMV+mf8jP SeBW/jhrsj7IIRKs1XI6UcVUhmyk2jReI/e7lmTJpyS9JTkfqYMspNKgnQtAjuSJ/An1 oiJy1X6PbhLgM7Arjwoct4BUymyoC7JCRbBV4yItJSnAqBmRbstME7wLMaeRYjQvYOyb 96wg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=lsjOnjEX; 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-34410-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-34410-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 e8-20020a056a0000c800b006db9604bf8esi10957015pfj.312.2024.01.22.16.22.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jan 2024 16:22:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-34410-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=lsjOnjEX; 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-34410-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-34410-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 B70A828BAA5 for ; Tue, 23 Jan 2024 00:16:35 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E63987A738; Mon, 22 Jan 2024 23:56:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="lsjOnjEX" Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.120]) (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 454F3745DC; Mon, 22 Jan 2024 23:56:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.55.52.120 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705967766; cv=none; b=PiSA9Xxt+BPckUCuPFNT//dhGJQKmWoYfJBPyJmUd8ShIoNuHDk8lnCRsV3ndTPRekAhPrY2Fxeo+J7W9soYnQppTt80BTyke8Jot6A/4mbzfsQz0tk7bwcyc32jFy7qpup/gGtlPkuZD5uaqLgnU7Xk22F4B+x9O/XsHxmzx5g= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705967766; c=relaxed/simple; bh=rQLBcMQMard5Ic4zE/SJhHu0R0s4kbDUZUfvH8x7Jkc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=uGbJaaPBPVTdxbxxAxSjz39VkWFlG9N7zyeFJgzGkWrobrxhCeNqIeB0nXf6e5bS/9kDVNuCWRHKfsRq8F42AVClNEe3tQkpOPFGjVJS1bKmjdItobghdl5NGBaDekop7+d/oGvWcHqRof9+KdoaNaHDATSS3xOUq1hnN8ETK3M= 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=lsjOnjEX; arc=none smtp.client-ip=192.55.52.120 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=1705967764; x=1737503764; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=rQLBcMQMard5Ic4zE/SJhHu0R0s4kbDUZUfvH8x7Jkc=; b=lsjOnjEXvt2OMxH+pY2KIrTe7UsImw8IMNiyzQ1FClPcldPye5aSqRP3 GOb4a64o2EM7cWQ5/zwx0PomDux/X/H8pvB//oR0a45XoTfzyerBYTd64 FH6SCZqrYsTquSonCEV7Cwp6sH6ABPrbDCAO8+O5hI1nRc+1ccysZdqjA qiYw8m8Vl9UwADz+rfppTobvQTy1/dIe24J2yGcNFcA3KFDx9i6Hf1QGA nRBwLGK2VGeSO2e2JR566QO3spZMptJOhINKKMw4uFUjecMS1pMsmxEcF zLFGs1IYEw27pGbgym9u9TUOCds3yXmO61jbwnrGdODiaj+XxOBZY+eLy w==; X-IronPort-AV: E=McAfee;i="6600,9927,10961"; a="400217875" X-IronPort-AV: E=Sophos;i="6.05,212,1701158400"; d="scan'208";a="400217875" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jan 2024 15:55:52 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.05,212,1701158400"; d="scan'208";a="27817989" Received: from ls.sc.intel.com (HELO localhost) ([172.25.112.31]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jan 2024 15:55:52 -0800 From: isaku.yamahata@intel.com To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: isaku.yamahata@intel.com, isaku.yamahata@gmail.com, Paolo Bonzini , erdemaktas@google.com, Sean Christopherson , Sagi Shahar , Kai Huang , chen.bo@intel.com, hang.yuan@intel.com, tina.zhang@intel.com Subject: [PATCH v18 101/121] KVM: TDX: Handle TDX PV rdmsr/wrmsr hypercall Date: Mon, 22 Jan 2024 15:54:17 -0800 Message-Id: <3c6030033218f169b636c50ee35af5d352797942.1705965635.git.isaku.yamahata@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Isaku Yamahata Wire up TDX PV rdmsr/wrmsr hypercall to the KVM backend function. Signed-off-by: Isaku Yamahata Reviewed-by: Paolo Bonzini --- arch/x86/kvm/vmx/tdx.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/arch/x86/kvm/vmx/tdx.c b/arch/x86/kvm/vmx/tdx.c index 396dd540f2d5..66d575cfd884 100644 --- a/arch/x86/kvm/vmx/tdx.c +++ b/arch/x86/kvm/vmx/tdx.c @@ -1379,6 +1379,41 @@ static int tdx_emulate_mmio(struct kvm_vcpu *vcpu) return 1; } +static int tdx_emulate_rdmsr(struct kvm_vcpu *vcpu) +{ + u32 index = tdvmcall_a0_read(vcpu); + u64 data; + + if (!kvm_msr_allowed(vcpu, index, KVM_MSR_FILTER_READ) || + kvm_get_msr(vcpu, index, &data)) { + trace_kvm_msr_read_ex(index); + tdvmcall_set_return_code(vcpu, TDG_VP_VMCALL_INVALID_OPERAND); + return 1; + } + trace_kvm_msr_read(index, data); + + tdvmcall_set_return_code(vcpu, TDG_VP_VMCALL_SUCCESS); + tdvmcall_set_return_val(vcpu, data); + return 1; +} + +static int tdx_emulate_wrmsr(struct kvm_vcpu *vcpu) +{ + u32 index = tdvmcall_a0_read(vcpu); + u64 data = tdvmcall_a1_read(vcpu); + + if (!kvm_msr_allowed(vcpu, index, KVM_MSR_FILTER_WRITE) || + kvm_set_msr(vcpu, index, data)) { + trace_kvm_msr_write_ex(index, data); + tdvmcall_set_return_code(vcpu, TDG_VP_VMCALL_INVALID_OPERAND); + return 1; + } + + trace_kvm_msr_write(index, data); + tdvmcall_set_return_code(vcpu, TDG_VP_VMCALL_SUCCESS); + return 1; +} + static int handle_tdvmcall(struct kvm_vcpu *vcpu) { if (tdvmcall_exit_type(vcpu)) @@ -1393,6 +1428,10 @@ static int handle_tdvmcall(struct kvm_vcpu *vcpu) return tdx_emulate_io(vcpu); case EXIT_REASON_EPT_VIOLATION: return tdx_emulate_mmio(vcpu); + case EXIT_REASON_MSR_READ: + return tdx_emulate_rdmsr(vcpu); + case EXIT_REASON_MSR_WRITE: + return tdx_emulate_wrmsr(vcpu); default: break; } -- 2.25.1