Received: by 2002:a05:6358:e9c4:b0:b2:91dc:71ab with SMTP id hc4csp4118556rwb; Sun, 7 Aug 2022 15:34:48 -0700 (PDT) X-Google-Smtp-Source: AA6agR4XyfgNifqUOR+KKdk1RdyKuEtThPITbPrsxyruMGdwNXsV2e3votoeVRzrY/OS04rToi56 X-Received: by 2002:a17:902:e88a:b0:16f:281:3f59 with SMTP id w10-20020a170902e88a00b0016f02813f59mr16194429plg.0.1659911688718; Sun, 07 Aug 2022 15:34:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659911688; cv=none; d=google.com; s=arc-20160816; b=tjYrF4JGE7nrkNikNomkveH7abx7c1XvvSvgiE7eX8FPNhmY+YFCR+9ntOu90w9cge yGOl3yUGYv7fYWvOOn+ZpNV7T+ti9ybYWoVi+NblCXxoPgNaTWWZ8+nNpUtR8OZ9ahKl midmO/UXC3Kad41LB+F/FNmNGxJlf/q0C1HjW5btPq1CnHquLmwnDxs1E3KisnaIJpiQ XoJac2EWLkcJp4IwxTXSglUW+KlXb2WJkeqx7InwuI8mqu5LyNz3dEUrPgi83nUApdBA xPZOziZkOwINOYqYVaW0ltgWFl7/rs0e+cWtPjBqVAyZUyShPJkf3jnoRwq8PyJrSKzB Xofw== 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=3G8CJSA6f4RuxkhTkAMOcw6C/m5YxlmUOCNqpcNa8+o=; b=Mxe9B0rUZtehM7YbO+7gPMtsJui+JDooX7RxnCwAQRKMwC89pv+qOIt5AWmzoM0InQ uYbmVxLpQ7nWUZVzsoduo0wyLTO1oAZ1PLESzkBzNi0O8CEX6q4EPombZtZPlUAsF9/P v6ucHIiUDfMkLfVMFc3+qJPNZfh9HVnX7wjTKLDpd1Y8Iu2nAP/dz5WX0KazXSw75ZRQ /eGxZPklIY4kcSmCshb+IMuWccAlhj9UOhUc/0v3xtPYwMQN9Lh8z8Q2piAjgCCTKGRg t9hC7NbdLcDnU6NPbnA6XyCyb75Gz6PSxGfHC1UXd2wMfsTjJxgCkRcpsIXqLySfFITP ITJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=HZRAoqLJ; 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 6-20020a630806000000b0041b0abf6cd2si8862091pgi.647.2022.08.07.15.34.35; Sun, 07 Aug 2022 15:34:48 -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=HZRAoqLJ; 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 S242559AbiHGWLd (ORCPT + 99 others); Sun, 7 Aug 2022 18:11:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52204 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241915AbiHGWHe (ORCPT ); Sun, 7 Aug 2022 18:07:34 -0400 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 30A08BC99; Sun, 7 Aug 2022 15:03: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=1659909804; x=1691445804; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=rgXQ0ahQQrRTJEuYFsv1+BAOo8K5g9YBrukApUYAxOU=; b=HZRAoqLJyNlnjr3lJCDZV0+L2jciZ11eKMP1A/zLhGFNbJg/AXQcxq+D 351ud5P9SkFYliGAkgkIJZDaPdDgOpBpuX9hkrbefZC4em0acitXs5cZD 73z3dICBRl/DAxfyuip6+pR5iV6ZjM8tE9o+ppeW1iJX1DlBgUB8RIw08 S3CMKJppM3WKUATZE45TM50mNaRrYWQu8wPNYoSoq/0CFHAlIayp/d8Py tI/3qONRtVcb/cGocrCHsVRu75ptTibLaNn6os03uqjyEbHMoPLa1MZdQ 9HPWPK1gkBKIoj61Yqtynqr6gZTvlwwmOzwxxmg+k0Yxuhk628kDnuPP/ w==; X-IronPort-AV: E=McAfee;i="6400,9594,10432"; a="270240406" X-IronPort-AV: E=Sophos;i="5.93,220,1654585200"; d="scan'208";a="270240406" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Aug 2022 15:02:43 -0700 X-IronPort-AV: E=Sophos;i="5.93,220,1654585200"; d="scan'208";a="663682746" Received: from ls.sc.intel.com (HELO localhost) ([143.183.96.54]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Aug 2022 15:02:43 -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: [PATCH v8 092/103] KVM: TDX: Handle TDX PV port io hypercall Date: Sun, 7 Aug 2022 15:02:17 -0700 Message-Id: <9b5e8466f128275e625cf4dc4b9ff6b38f68f8c6.1659854791.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=-5.0 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_PASS,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 aa3b569318bb..4230dbb9ece3 100644 --- a/arch/x86/kvm/vmx/tdx.c +++ b/arch/x86/kvm/vmx/tdx.c @@ -990,6 +990,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)) @@ -1000,6 +1055,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