From patchwork Mon Feb 26 08:26:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Isaku Yamahata X-Patchwork-Id: 206447 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp1950862dyb; Mon, 26 Feb 2024 01:06:58 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUVOC9kv5WoE2b+746LwTs9nSHPBnSMkddBzd2AbjcQT7ACIASQ7uFiBOh9rJvcGViaVlMByHgtIABycEWjkpGfy3V3mQ== X-Google-Smtp-Source: AGHT+IHvijWfeWzfMAzaDQzTdK6lo773p43mc8BaSsweQTooJhukjOwjQkirAzcFmdRQtcH7yvJ6 X-Received: by 2002:a05:622a:393:b0:42e:8c25:f95e with SMTP id j19-20020a05622a039300b0042e8c25f95emr729478qtx.15.1708938418774; Mon, 26 Feb 2024 01:06:58 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708938418; cv=pass; d=google.com; s=arc-20160816; b=d0iL1fpI8I7ZkMTRkou2X3H2wxr6zWQGgD5QMpNmzbXa5iMf6LP+4V/D3JxG6Vyu2H Q3O1bEamA3wqYsOa7mw+F/LwaydiTjVdxS1TQZAZBjBPf335vDUgyMh21et1/BUs3hE2 f8aLolFhXPM6CTHinnOB264FfTqzNaibO9qN3dTxs+iCss345fsAJmD1HbhUyrnDqRVO LNr6UphbfzUg/Zsvh/JIO6SP1SrjQK8I+BBHXZIiSwUbAnfxdMUe1Tw8Cc7YAuunSH8u XvtsJMu0mBmmdMCf1n/9w4e1eM5k21AyVmnUOik8j7XIxlgBMNMbWlIELLSxaAOydSrJ aXNw== 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=tk66tQIlI/jBJsMD0fz9rrc26ndcvINPBs70J7l5zKE=; fh=Itbyk7CEvizIrzGEESCqq3I2tZgG1kc/GkVOa3S7Hsg=; b=PfcRaZVrjELQxqx3M2LXbIdkmpzsebYlACUqZmez+VBJjgCIqw1jjwLz7tyNGS2aU9 0CTFbZJUJIrXlSHCw2Zx7z1Hj9KDJ/O79M15gbcPF4GFrDOwwnDpj8mYfqZcpLUUaj7m REH52Oy2pQa4YvfzqyU7192qBABqHGTolCUmULFxorARWbAgRVGgHMrTY26YbU7r4HWq 0e/IqJxPUj3TyWtUn4JEmpQM635IKic6lkcpIO4tdezG4cEQHKCVfTTrx3Bo9chySJtt OhhK92bz1hk/7GkDvUoVp2mNycG4unqcaZe2DcnrZKJ5GKvJ1JoE3BkWJsQPduN6eqpX OkMQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=SbtD+5cs; 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-80876-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80876-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id f17-20020ac85d11000000b0042e76eba305si4588979qtx.520.2024.02.26.01.06.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 01:06:58 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-80876-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=SbtD+5cs; 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-80876-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80876-ouuuleilei=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 E55341C235A2 for ; Mon, 26 Feb 2024 09:06:39 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 74B2012CDA6; Mon, 26 Feb 2024 08:29:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="SbtD+5cs" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.8]) (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 AD37112AAE9; Mon, 26 Feb 2024 08:29:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.8 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708936150; cv=none; b=Y9rg2g9TLrbMt63Z+dxOVJTzLTICsBozySyEPAnQOCM4tfoxkto6MCkFjuqc7oaCBEVu3IXbtDCRKfdvaReuKGAtFpuIu3dluCMUMeb62SIV9xSawEetVSqDHyqhor+oyZFEUcYYGBJRImfKemEYVr/fjId6OicTpJ6fLclO8z4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708936150; c=relaxed/simple; bh=+2fCF+WzvIZcAkBJTQ/JIVXOSBWrPoxPrF9MU/Z9Lmg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=tgXY6lkVxyQ5fHJqjpOd8CLjACBdPHTb2K4R1SoHBR1emEjCZL3fLp4ucSbRpww+8+bohzkazxCgf6OSqwRdLoOpXX3MySxU7bjSt7M2hTndDgHcz0EaPdeLm5uD5eIJ63IJukm+Cn9A6Gd8fR2XM3fjEsP1qIJh/z/dpEohFIE= 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=SbtD+5cs; arc=none smtp.client-ip=192.198.163.8 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=1708936148; x=1740472148; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=+2fCF+WzvIZcAkBJTQ/JIVXOSBWrPoxPrF9MU/Z9Lmg=; b=SbtD+5csX/fsJlIOrA9PWvkGGQePK5AMfqofVa0abRLzzYV8wK7LArPI O2OcVyo2yE5Z7e9rPVnb/6mDLd8jC3sq+FSEgVu6EOhNFKbfxlx1eh/r0 3xYl8yonJNpLdLVSXioz9+gPs7ddJQqQr+WS6Ns7iIwjvQ/BIJsXDVaI4 1ENuXym9VctCZ1C1oSy7oN+xBbWwe1Qbga6mfzg7nM9xvNyEV5hq4HASx fJr0ZMJL1IZ62sXsppkD7coYbqCwUbwT0hd7Zb8Vef5qUsui0ocdHEDA0 CNfFo39Ft1bFNG+XWcR9fsqlw3Rgg/BfR948ifLe1QmsmVU1eVRsM09YN A==; X-IronPort-AV: E=McAfee;i="6600,9927,10995"; a="20751351" X-IronPort-AV: E=Sophos;i="6.06,185,1705392000"; d="scan'208";a="20751351" Received: from fmviesa008.fm.intel.com ([10.60.135.148]) by fmvoesa102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Feb 2024 00:29:06 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,185,1705392000"; d="scan'208";a="6735080" Received: from ls.sc.intel.com (HELO localhost) ([172.25.112.31]) by fmviesa008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Feb 2024 00:29:05 -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 v19 112/130] KVM: TDX: Handle TDX PV rdmsr/wrmsr hypercall Date: Mon, 26 Feb 2024 00:26:54 -0800 Message-Id: <1fbd5bb56fc607d279deff729272b19b109fb524.1708933498.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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791951811395801809 X-GMAIL-MSGID: 1791951811395801809 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 c8f991b69720..4c635bfcaf7a 100644 --- a/arch/x86/kvm/vmx/tdx.c +++ b/arch/x86/kvm/vmx/tdx.c @@ -1329,6 +1329,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, TDVMCALL_INVALID_OPERAND); + return 1; + } + trace_kvm_msr_read(index, data); + + tdvmcall_set_return_code(vcpu, TDVMCALL_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, TDVMCALL_INVALID_OPERAND); + return 1; + } + + trace_kvm_msr_write(index, data); + tdvmcall_set_return_code(vcpu, TDVMCALL_SUCCESS); + return 1; +} + static int handle_tdvmcall(struct kvm_vcpu *vcpu) { if (tdvmcall_exit_type(vcpu)) @@ -1343,6 +1378,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; }