Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp302959rwb; Tue, 25 Jul 2023 16:21:27 -0700 (PDT) X-Google-Smtp-Source: APBJJlESxSyCNZHaIdlz/CrLPaBC/FCU83kC+CL2U7ojPly+mV8E2b4tIExreMVUE5xX71Tq2UHY X-Received: by 2002:a2e:7213:0:b0:2b6:9f95:46d9 with SMTP id n19-20020a2e7213000000b002b69f9546d9mr125334ljc.46.1690327287316; Tue, 25 Jul 2023 16:21:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690327287; cv=none; d=google.com; s=arc-20160816; b=AoOJ5fD5i7nE5E2p+TyHHlymo/GcZ4ZGOpfsndS3qQFexmzVnag+8v5C96W7IeBcsE cpVnOw/WK9XcYYgSZiAxN/A9osFvU7yCfH8k6T4zfyNz5huWGsJfcs/jPfLB8ThUzTtn o17ylDTbW+o08ONefazck+bFXcxqzsBpTQ3b+HLytnyIF+OK68l0n3pN+8FYYkocijbP Lhz0gaD+7O+iWURifH/8xO+g1rNAyH7NW5R4ksAmSWor/z918/LHVT3sZ9pHZ74DOurO Nq1H9K07pFKJWHWDjOe/NZq1OjtiNKqWAB7jC4sx5tO9EyQa2nTi09Xcrn8wsLJJ2Zue WxQg== 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=RLH9Aodc85coZ3nm/QlVbcxdr4nqUZYSDwMix4wFRjU=; fh=juxwNcA6iKwLISFgUCNwdoIYC0NKLUseq3xZdq25RR4=; b=ck1FeTK21wNgL6yjyYA4msj5E9n3r6y7rlq4qBakHVdg1m/sGjPr/ncaTG0z63GhUP IITVFvABMO58AObcrFvXD2KPB5QgDEfDwkeI9E74X5Jo44kAHN6dp0BpXMZyAIV/c0Th LF3Sn8FiUCv6NpU5YS8GdrigKNOm1KtQP/N7AzaR/ejJXVaF66rf1Wdtr8Vipgz3PS3U 3fLmz63kDYAmEUet8DrCwGaKtFuq13Ba1GS8OeByHxrbNRJ5R7xsY4GJrzmjFubRapSh MODbIUem0vzNGsTobJpk4iKSJY/HSlSEd31lgtq0avPK/ph6hXnM3pS4FZfFVJpsuQ2H Urmg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="VrqdoaG/"; 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 ga4-20020a170906b84400b00977e0843714si8309395ejb.1002.2023.07.25.16.21.03; Tue, 25 Jul 2023 16:21:27 -0700 (PDT) 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="VrqdoaG/"; 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 S233095AbjGYWZ3 (ORCPT + 99 others); Tue, 25 Jul 2023 18:25:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39358 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233027AbjGYWXU (ORCPT ); Tue, 25 Jul 2023 18:23:20 -0400 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 61BA155AE; Tue, 25 Jul 2023 15:18:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1690323519; x=1721859519; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ccMcBcc23AgnL9dY1KKhHHjOC35FCd6UT6pYEdXqS/4=; b=VrqdoaG/c9SSRnC1fXnESLE5GSATuKVV3Ia0CW1Cq1h7WxK2brY7FPp6 BLuoiA8cBYqIef5eSJv29mQjqcR09V9ZHvgfcspM/OGXbvfWYdMIQ3Jk+ Uc85EXoMAiEE+c5ZMyJW1JozsxYnQ66RwJhr9mwLtYGs9/+trWlQAMjvy GENHSCVLPjEl4ZISXniLFtJTVbp5xjyLfc8hMfPDshYkK/rzfEtbOHY4J asePxwZ0/EM+QouvyJLMrzEwpHiXEraQJVviKyN36c+xw2j574gI9g/ZP oJSKjxHC45qYidBfuPjbDeQ/ovVBlMmRWFqYcTht+lMMHSBIrx6bcQUD8 Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10782"; a="367882723" X-IronPort-AV: E=Sophos;i="6.01,231,1684825200"; d="scan'208";a="367882723" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Jul 2023 15:16:05 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10782"; a="840001920" X-IronPort-AV: E=Sophos;i="6.01,231,1684825200"; d="scan'208";a="840001920" Received: from ls.sc.intel.com (HELO localhost) ([172.25.112.31]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Jul 2023 15:16:04 -0700 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 , Kai Huang , Zhi Wang , chen.bo@intel.com, hang.yuan@intel.com, tina.zhang@intel.com Subject: [PATCH v15 097/115] KVM: TDX: Handle TDX PV rdmsr/wrmsr hypercall Date: Tue, 25 Jul 2023 15:14:48 -0700 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,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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 dc31b052f6a7..98bdcfc06283 100644 --- a/arch/x86/kvm/vmx/tdx.c +++ b/arch/x86/kvm/vmx/tdx.c @@ -1212,6 +1212,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)) @@ -1226,6 +1261,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