lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <06d4f85b-b6c1-1952-b736-9cfd9aea17c2@redhat.com>
Date:   Fri, 15 Apr 2022 16:59:20 +0200
From:   Paolo Bonzini <pbonzini@...hat.com>
To:     isaku.yamahata@...el.com, kvm@...r.kernel.org,
        linux-kernel@...r.kernel.org
Cc:     isaku.yamahata@...il.com, Jim Mattson <jmattson@...gle.com>,
        erdemaktas@...gle.com, Connor Kuehl <ckuehl@...hat.com>,
        Sean Christopherson <seanjc@...gle.com>
Subject: Re: [RFC PATCH v5 093/104] KVM: TDX: Handle TDX PV port io hypercall

On 3/4/22 20:49, isaku.yamahata@...el.com wrote:
> From: Isaku Yamahata <isaku.yamahata@...el.com>
> 
> Wire up TDX PV port IO hypercall to the KVM backend function.
> 
> Signed-off-by: Isaku Yamahata <isaku.yamahata@...el.com>
> ---
>   arch/x86/kvm/vmx/tdx.c | 55 ++++++++++++++++++++++++++++++++++++++++++
>   1 file changed, 55 insertions(+)
> 
> diff --git a/arch/x86/kvm/vmx/tdx.c b/arch/x86/kvm/vmx/tdx.c
> index b0dcc2421649..c900347d0bc7 100644
> --- a/arch/x86/kvm/vmx/tdx.c
> +++ b/arch/x86/kvm/vmx/tdx.c
> @@ -959,6 +959,59 @@ 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;
> +
> +	++vcpu->stat.io_exits;
> +
> +	size = tdvmcall_p1_read(vcpu);
> +	port = tdvmcall_p3_read(vcpu);
> +
> +	if (size != 1 && size != 2 && size != 4) {
> +		tdvmcall_set_return_code(vcpu, TDG_VP_VMCALL_INVALID_OPERAND);
> +		return 1;
> +	}
> +
> +	if (!tdvmcall_p2_read(vcpu)) {
> +		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);
> +	} else {
> +		val = tdvmcall_p4_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;
> +	}
> +	if (ret)
> +		tdvmcall_set_return_code(vcpu, TDG_VP_VMCALL_SUCCESS);
> +	return ret;
> +}
> +
>   static int handle_tdvmcall(struct kvm_vcpu *vcpu)
>   {
>   	struct vcpu_tdx *tdx = to_tdx(vcpu);
> @@ -974,6 +1027,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;
>   	}

Reviewed-by: Paolo Bonzini <pbonzini@...hat.com>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ