Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp3429131iog; Mon, 27 Jun 2022 16:12:15 -0700 (PDT) X-Google-Smtp-Source: AGRyM1t2pEUTNYDp4Hcan9Zze8qFA4BUKpAS6jsp7gKXj8ex4L1HPSubV4QIPZ5lusakDBflDw35 X-Received: by 2002:a17:90a:f8d6:b0:1ee:e6b1:d52 with SMTP id l22-20020a17090af8d600b001eee6b10d52mr6359499pjd.158.1656371535690; Mon, 27 Jun 2022 16:12:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656371535; cv=none; d=google.com; s=arc-20160816; b=NhGF74yv10fq3XNqm31sTaCBv5dG5x1NrnkRrvNUpQgcByKpHESdCwyvZGDB/WBrlk AMgpxaSUwHMnPSZpOnqMNuS2XZG/Dnyh4vvq8BKMnK31V8gNwckGFwmeIrkBspAMsRWD JvMGbVFLDezPIpgiYQ/lATn4/Z63s3YqXTN99q4ogFtoWxs70tDDmvwWYs7uGAZYEE83 JxKczgq9CfoGCDOcaO2+LuN+X6EkcSL4SZwg+Q/n5KoeIfqNigmn7H79FKi+YqAuKSyE /Q3UY3AoPdL6KSegSACaI2+Xk223bpQZjy6xz1dVghIO6pDt0h7QA/E3DH80l1nrV+VQ J4Vw== 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=at5c7JR5eB38F+OjWhap60qAEcn090e8Ycn2tZViK/Q=; b=pKbAG82V7QyX5Z43XOYUHW1nrfrTPSU0oSrTUW+7/a3YTl97UJz6MT1/xHPdsbEU4V N9L0xsu3cteRgwfxidHAXB2Cv9fBQu/zsmEWVXx2lS9HxrbhB/cF9l5NeC/Q/0um1BRW iHTmmEJgePg4RP0oBh+BC4LiA+xMLqeqFrAOAcrbk3n8cZVX1sIvUz1iuH0DiX0ooIRd 12fxyH37KRGmJ7bxfM5XLHDgki51qOC94Dk/+X03wn/9p1n+filmkMLdo3QzKSnRGP9v yQGYW4elywqgD+77sUe0cFqMiWywBdmWJB+9rC9JjUEVXBgMHJThkxRLn07/7ZSfUvLd TG0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=eSKXUb6d; 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 o16-20020a634e50000000b004113ecbaa43si3062253pgl.836.2022.06.27.16.12.03; Mon, 27 Jun 2022 16:12:15 -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=eSKXUb6d; 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 S242395AbiF0WBl (ORCPT + 99 others); Mon, 27 Jun 2022 18:01:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59338 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241584AbiF0Vzv (ORCPT ); Mon, 27 Jun 2022 17:55:51 -0400 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7FED217E12; Mon, 27 Jun 2022 14:55:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1656366908; x=1687902908; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=/PYwWPGHO/1+qPoFaj/W0MK8YqX25A5UyWr9XEuPVxU=; b=eSKXUb6dyhFxLKmRdM86KAVnoYpOXg2SgsLJ2NMqMw5XxH4vfJ+v8gJY g1Tz2aaHaUaaynUbRcwWAfQS6p43QLtKxOH1SXUyQzeoYbMVMRykkSnDW 55ApuBJ2siKFohc4z6XQspxKGAeIaCq5AFm4qV7vW/GTIZUMddp+X07BW os4oKymRmUs1oAv6Vb6Ond0pEs17eqgcxQgeQws1JFdsNVweDcWMd+ELW dT8mPIk1n7/X52uq7noNBYiLcf7K59SoLajZ3at9sZ4m7+TovQs1sNdU2 hwTJM1N7sir6ONrSu9/2raYkmL3ToZXUeMDjNon6kBSSlkU+UndVO9oKC Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10391"; a="279116142" X-IronPort-AV: E=Sophos;i="5.92,227,1650956400"; d="scan'208";a="279116142" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jun 2022 14:55:01 -0700 X-IronPort-AV: E=Sophos;i="5.92,227,1650956400"; d="scan'208";a="657863739" 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; 27 Jun 2022 14:55:01 -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 Subject: [PATCH v7 091/102] KVM: TDX: Handle TDX PV port io hypercall Date: Mon, 27 Jun 2022 14:54:23 -0700 Message-Id: <39fb8acbd90c1b5e91eb92710cb7eb992d168e39.1656366338.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.5 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 15dc0ae61e0f..a62586a83b80 100644 --- a/arch/x86/kvm/vmx/tdx.c +++ b/arch/x86/kvm/vmx/tdx.c @@ -1003,6 +1003,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)) @@ -1013,6 +1068,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