Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp562141rwb; Thu, 12 Jan 2023 09:20:32 -0800 (PST) X-Google-Smtp-Source: AMrXdXuHjBwiQPLQM4Ayiimt/cQBGl1UVnWQiAK69ru8bJKgKfNEew+EVPJ4R5wbC+/ul5YellIS X-Received: by 2002:a50:eacc:0:b0:46c:ec6f:43d7 with SMTP id u12-20020a50eacc000000b0046cec6f43d7mr87533322edp.19.1673544032176; Thu, 12 Jan 2023 09:20:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673544032; cv=none; d=google.com; s=arc-20160816; b=XfOysQVGXJiQD9ybJkNynDQsikc9JmpvS3KvgGG/ixoBEXt9daHiPl+8Pivm2rcj+N VO5xRHDB2vm8QGspkmiP59jm8g6jIfPai99PE7+ZLxwD+nhZ10xpijOhwb6MnURx8WWY qmkz5bc+BD4PaIGYxgUBNCeMmwvtusMmw1iJqijLI3ply/hjHM3gW5wM5QQSbiAYz9dd iyn+/msP7AbIDjnSIkeMCVPkl8uo8uNcNGBJwdeLdgUrUdqY1azMhHxiEqCnMgA89ueq 3rSSpcJW1Y9mgt6fAL/V2JQwWZUQMd5hwPRa0ikh3N+i8YnemJGuUBK31IewPusyahLB gFbg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=LOcKxSIMtDtgHenwHj3ZkSZDlkF57YyE/JVXYnZyD+U=; b=kxJHsYa635PgbEMYmy71SBcins6RYqgQXRxfWcv5VcXV4LesA9fRl7C77tDtnZtwCy l2aCOvl9OQWFKQ2jhbotb+A9P1gHkLgx01Du67Qoq4bZLsD0r7yza2VHY/5GrczIwsrC LrUkGwlAKu2nqrtDDOfn9QlhCCoLa2wBVEO4wRMv6/8L52lmVLRrNtDTMXBmWYiyi5K4 HtT0rW2IYyNGG4tFh/4/X0tdzub0G4sNzOQcVBf+FSNwGJrpoMVj5VZN7vxDEWRgGXAR YEVZXpNDns5eK8kaAIfIT/KO1+/KAFHmzqObt3ONxGjvZ+JGQgsgB8vPti84J3l1tM2m 7UOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=hqpdr1gW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f12-20020a056402194c00b00499b50657d6si11499380edz.531.2023.01.12.09.20.19; Thu, 12 Jan 2023 09:20:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=hqpdr1gW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240571AbjALQkj (ORCPT + 50 others); Thu, 12 Jan 2023 11:40:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42552 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232215AbjALQh0 (ORCPT ); Thu, 12 Jan 2023 11:37:26 -0500 Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 681AFC74B; Thu, 12 Jan 2023 08:33:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1673541226; x=1705077226; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=VkEtMXOs1uY9rmNV2MPiIbRwiuHxp5oFXsKNHFcu5OI=; b=hqpdr1gWyyBoMdL04Zp5uaLXuZ5KOwANCSTw/xOFqOBRaj34VyCpB65u SzA44CO/KYemcAnUQvI5MPOQoNIBu4rXYtwoysKkjIGuZLYwM/eSA2Axu 1KPEApr4ti4o7Voirqf/M+uQkN2mOGUjEnBLGQr+nn6o+lBcSsHC0nT0i T/EUCH+9noqMLZqN249+Q/Xa6gk59Oii87A1irMhgjjq2u5hbgc0uOsPj gX89dPHEouBO65MH/cB/sFCo2hAHMN1UzZG4x0Et2krDfdbojXriINCEY uQda2B1c47130f+VN5wHa143lRBKzUq59gdbl9uvQVzjK9ae4qvmpkmTU w==; X-IronPort-AV: E=McAfee;i="6500,9779,10588"; a="386089756" X-IronPort-AV: E=Sophos;i="5.97,211,1669104000"; d="scan'208";a="386089756" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jan 2023 08:33:37 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10588"; a="726372579" X-IronPort-AV: E=Sophos;i="5.97,211,1669104000"; d="scan'208";a="726372579" Received: from ls.sc.intel.com (HELO localhost) ([143.183.96.54]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jan 2023 08:33:36 -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 , David Matlack Subject: [PATCH v11 097/113] KVM: TDX: Handle TDX PV rdmsr/wrmsr hypercall Date: Thu, 12 Jan 2023 08:32:45 -0800 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 5d8894899055..5dc7dae55c57 100644 --- a/arch/x86/kvm/vmx/tdx.c +++ b/arch/x86/kvm/vmx/tdx.c @@ -1146,6 +1146,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)) @@ -1160,6 +1195,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