Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp2203646iob; Thu, 5 May 2022 18:56:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwZ6jpw1nmABIsFKd5//ySgUp86ef258VZP+39uYHbavnRYTmkbSJ28GawP3ciGjJwArgFr X-Received: by 2002:a05:6402:5113:b0:427:f443:f63e with SMTP id m19-20020a056402511300b00427f443f63emr1136700edd.317.1651802191467; Thu, 05 May 2022 18:56:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651802191; cv=none; d=google.com; s=arc-20160816; b=r/jsSmGVW5n02/QamG2pSgzd/AGzWpKKBFo1Hl0zvgCiSXLi640CWQrf5GRRb6saTm QzSRVlCPTlu2mU8yHMjAKcMrOv3lAs9LdabwQTC8hxdiNiwBBFGQXAto5po+sSY7xgAf OJoRf6G201G705VmGLBABFrfbXwF/yCrWkM6r1owCZhibt1bicwdpkFmAGo0DMf1hwWd n4i8fW2UMVfuYgNYrGuHQRSZBKEHBtSkd7olvTrhD1XKi0S96HXH/pFgaKF9yh6u5xOK 6vSr8KcLSAPjS4h7PMCjaO29bc2jtVAa3FGdBv/HNCPvQopd2a0VnrDw4QO5Chu/BIrg Fl6g== 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=NVWcGV6DtVI/Wtoz49TJJctby/RrWmWwt0q8f0eKkGs=; b=aZyoZAb9fGCG7KofabxKRIk1DCo+jKAefknwhfNZCAOO8vZLXKVf7IEkqx7LTsrYiQ NT1NfGr70vg53bRHaWojTjV8zuivNdehDe1wNfdgrgELn+0kkvrUTMespZD1d8+blsVm piB1LKEeUfUxgLEEPxxMVAd8HbVVHTyr/W+dEUXEyhDG8pZ8zlM2vFIXRJGTTRqqCrfE DS8N5j04Djs/gfxRlk6o03p6U+riq2PggecP116eyeH1B5tBOLe6PMkC/iiozoqgyi/H F+MmOtyQ3nA7mUg7639QTVXrTa/SM1f3QIospmEJo7Ahulkrq5LZlr2yaJvMU40H3ZwG hY8Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=K6BWxUGz; 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 ec7-20020a170906b6c700b006f3dd45a277si4198298ejb.48.2022.05.05.18.56.07; Thu, 05 May 2022 18:56:31 -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=K6BWxUGz; 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 S1385393AbiEESaZ (ORCPT + 99 others); Thu, 5 May 2022 14:30:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37304 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1376753AbiEESUq (ORCPT ); Thu, 5 May 2022 14:20:46 -0400 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1AA165DBDC; Thu, 5 May 2022 11:16:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1651774584; x=1683310584; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=J4ioLk80QYEEpaXoOYW7VeLlRYf+vl8Y8/7LMbluPFM=; b=K6BWxUGz+xPNWcbwSX9N6uYWw/AsjgvI9hQVedqu9LZpcpZ7LDpaimMQ GWiXn133orzIHIbELDgEcwvJ4sQ9IcS1IYBimOapHnEwye+AzWTzaAU1O /L6UQbOJTyi7h0tGiuOToOy8CLjY9WkUf/0neztCrC6ZzU7KibW9AaIes 91sFxkX5rAdFG85TCxrNbvYRhTzKc1jICm5UWMXVYdJqTlUOMyc4T/T/D e3LmKLTsccJQqjRrht1QzTfgnHyVY9vZyXz9Vh8bhK1InLKsRmwakFHQQ 7qbAcmu2nNZpNF6/hsDBXbn2pLQD/O2c4zU6aaQI7CGuMUm/HTzXtHGif w==; X-IronPort-AV: E=McAfee;i="6400,9594,10338"; a="268354881" X-IronPort-AV: E=Sophos;i="5.91,202,1647327600"; d="scan'208";a="268354881" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 May 2022 11:15:55 -0700 X-IronPort-AV: E=Sophos;i="5.91,202,1647327600"; d="scan'208";a="665083473" Received: from ls.sc.intel.com (HELO localhost) ([143.183.96.54]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 May 2022 11:15:54 -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 Subject: [RFC PATCH v6 092/104] KVM: TDX: Handle TDX PV port io hypercall Date: Thu, 5 May 2022 11:15:26 -0700 Message-Id: <937aebe9071bd944b2672cdf949ae03deac1e2d1.1651774251.git.isaku.yamahata@intel.com> 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=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE 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 port IO hypercall to the KVM backend function. Signed-off-by: Isaku Yamahata Reviewed-by: Paolo Bonzini --- arch/x86/kvm/vmx/tdx.c | 57 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/arch/x86/kvm/vmx/tdx.c b/arch/x86/kvm/vmx/tdx.c index 631917eb873e..ee0cf5336ade 100644 --- a/arch/x86/kvm/vmx/tdx.c +++ b/arch/x86/kvm/vmx/tdx.c @@ -1002,6 +1002,61 @@ static int tdx_emulate_hlt(struct kvm_vcpu *vcpu) return kvm_emulate_halt_noskip(vcpu); } +static int tdx_complete_pio_in(struct kvm_vcpu *vcpu) +{ + struct x86_emulate_ctxt *ctxt = vcpu->arch.emulate_ctxt; + unsigned long val = 0; + int ret; + + WARN_ON(vcpu->arch.pio.count != 1); + + ret = ctxt->ops->pio_in_emulated(ctxt, vcpu->arch.pio.size, + vcpu->arch.pio.port, &val, 1); + WARN_ON(!ret); + + tdvmcall_set_return_code(vcpu, TDG_VP_VMCALL_SUCCESS); + tdvmcall_set_return_val(vcpu, val); + + return 1; +} + +static int tdx_emulate_io(struct kvm_vcpu *vcpu) +{ + struct x86_emulate_ctxt *ctxt = vcpu->arch.emulate_ctxt; + unsigned long val = 0; + unsigned int port; + int size, ret; + bool write; + + ++vcpu->stat.io_exits; + + size = tdvmcall_a0_read(vcpu); + write = tdvmcall_a1_read(vcpu); + port = tdvmcall_a2_read(vcpu); + + if (size != 1 && size != 2 && size != 4) { + tdvmcall_set_return_code(vcpu, TDG_VP_VMCALL_INVALID_OPERAND); + return 1; + } + + if (write) { + val = tdvmcall_a3_read(vcpu); + ret = ctxt->ops->pio_out_emulated(ctxt, size, port, &val, 1); + + /* No need for a complete_userspace_io callback. */ + vcpu->arch.pio.count = 0; + } else { + ret = ctxt->ops->pio_in_emulated(ctxt, size, port, &val, 1); + if (!ret) + vcpu->arch.complete_userspace_io = tdx_complete_pio_in; + else + tdvmcall_set_return_val(vcpu, val); + } + if (ret) + tdvmcall_set_return_code(vcpu, TDG_VP_VMCALL_SUCCESS); + return ret; +} + static int handle_tdvmcall(struct kvm_vcpu *vcpu) { if (tdvmcall_exit_type(vcpu)) @@ -1012,6 +1067,8 @@ static int handle_tdvmcall(struct kvm_vcpu *vcpu) return tdx_emulate_cpuid(vcpu); case EXIT_REASON_HLT: return tdx_emulate_hlt(vcpu); + case EXIT_REASON_IO_INSTRUCTION: + return tdx_emulate_io(vcpu); default: break; } -- 2.25.1