From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 67B4AC433F5 for ; Thu, 7 Apr 2022 13:13:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343599AbiDGNPI (ORCPT ); Thu, 7 Apr 2022 09:15:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60782 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239076AbiDGNPF (ORCPT ); Thu, 7 Apr 2022 09:15:05 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 0ED075D662 for ; Thu, 7 Apr 2022 06:13:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1649337185; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jgcFIANEmV3DqgP0seVeVyH30NWV2QqOukTsdkt/MFU=; b=GzFwkDGIzbVxQVc9iAqiJsasxCZpMA+7rRpOgrTk1YJD9IKXr2TXWk4UBnFia8Eh6ke1ha mZFRaSCBy4WAYVu1HPOCd25pLlQi1QV23XaJsM4oNMQchOmlu/clnDAiNIMHMXXA9Y3ABO fb9pObPJ2MZc7J2m/Wb++B2o1QkZWsk= Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-440-mcka_iBXMOC94cQnPKp0sA-1; Thu, 07 Apr 2022 09:13:02 -0400 X-MC-Unique: mcka_iBXMOC94cQnPKp0sA-1 Received: by mail-ed1-f69.google.com with SMTP id l14-20020aa7cace000000b003f7f8e1cbbdso2909582edt.20 for ; Thu, 07 Apr 2022 06:13:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=jgcFIANEmV3DqgP0seVeVyH30NWV2QqOukTsdkt/MFU=; b=wXMazJQ+KiF0+Zv3Nl5i+25JgMqv3KV8wT32xKy40kfeSADtMRbDyst95uFYkSGPdq gI6GCe6AnqK4u7SHlWlxHxdPiEfOQQ5+YacWzMkGDKA3ru50u2pyy0/aYf0ThezQM6vo Bip6N4Ox1skhEF/Y6XMP0dr+1HlWf1uqGYG6S3nfMkmlQuFnL9rpTS7P7OE/+d70nwS7 wJGsGSvVX2sArutK5433Qs0LnwPaRjJI1tBEkzMcYOID6QGDlUUgDcYOhSWJvTaAPLSZ WnSkA/fwKsWHWRKXbVzAeu8kGjrF46yEe8RGzqRHXGHll++zkPDLOFOKpP9StGtg+N77 EtDQ== X-Gm-Message-State: AOAM5300xCvbPcL983T3Gl4SwJJtfyu5jqEXp9IGiz6CaWCs0XaquxTL 6lCoZKef39DzsLVucjnGW5Ow2owiPP/04jYuu/Yj/doAgwiuQXC/37qoBmlYyq5FKN6gCdKHP8X 5lweHwPsjCaRpZ1dOeLPyzBZd X-Received: by 2002:a05:6402:2681:b0:419:4564:1bd4 with SMTP id w1-20020a056402268100b0041945641bd4mr14180703edd.358.1649337180934; Thu, 07 Apr 2022 06:13:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyirsd+HTZRX9NhaFwuw4B/4zFy4Zr6O7O5P+ww+XWhCTiAg+z91MGP9ytIn8PHipyYG95rMA== X-Received: by 2002:a05:6402:2681:b0:419:4564:1bd4 with SMTP id w1-20020a056402268100b0041945641bd4mr14180678edd.358.1649337180711; Thu, 07 Apr 2022 06:13:00 -0700 (PDT) Received: from ?IPV6:2001:b07:6468:f312:c8dd:75d4:99ab:290a? ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.googlemail.com with ESMTPSA id s3-20020a1709067b8300b006e4a6dee49dsm7703235ejo.184.2022.04.07.06.12.58 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 07 Apr 2022 06:12:59 -0700 (PDT) Message-ID: <1eac9040-f75f-8838-bd75-521cb666c61a@redhat.com> Date: Thu, 7 Apr 2022 15:12:57 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.7.0 Subject: Re: [RFC PATCH v5 083/104] KVM: x86: Split core of hypercall emulation to helper function Content-Language: en-US To: Sagi Shahar , "Yamahata, Isaku" Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, isaku.yamahata@gmail.com, Jim Mattson , Erdem Aktas , Connor Kuehl , Sean Christopherson References: From: Paolo Bonzini In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 3/21/22 19:32, Sagi Shahar wrote: > On Fri, Mar 4, 2022 at 12:00 PM wrote: >> >> From: Sean Christopherson >> >> By necessity, TDX will use a different register ABI for hypercalls. >> Break out the core functionality so that it may be reused for TDX. >> >> Signed-off-by: Sean Christopherson >> Signed-off-by: Isaku Yamahata >> --- >> arch/x86/include/asm/kvm_host.h | 4 +++ >> arch/x86/kvm/x86.c | 54 ++++++++++++++++++++------------- >> 2 files changed, 37 insertions(+), 21 deletions(-) >> >> diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h >> index 8dab9f16f559..33b75b0e3de1 100644 >> --- a/arch/x86/include/asm/kvm_host.h >> +++ b/arch/x86/include/asm/kvm_host.h >> @@ -1818,6 +1818,10 @@ void kvm_request_apicv_update(struct kvm *kvm, bool activate, >> void __kvm_request_apicv_update(struct kvm *kvm, bool activate, >> unsigned long bit); >> >> +unsigned long __kvm_emulate_hypercall(struct kvm_vcpu *vcpu, unsigned long nr, >> + unsigned long a0, unsigned long a1, >> + unsigned long a2, unsigned long a3, >> + int op_64_bit); >> int kvm_emulate_hypercall(struct kvm_vcpu *vcpu); >> >> int kvm_mmu_page_fault(struct kvm_vcpu *vcpu, gpa_t cr2_or_gpa, u64 error_code, >> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c >> index 314ae43e07bf..9acb33a17445 100644 >> --- a/arch/x86/kvm/x86.c >> +++ b/arch/x86/kvm/x86.c >> @@ -9090,26 +9090,15 @@ static int complete_hypercall_exit(struct kvm_vcpu *vcpu) >> return kvm_skip_emulated_instruction(vcpu); >> } >> >> -int kvm_emulate_hypercall(struct kvm_vcpu *vcpu) >> +unsigned long __kvm_emulate_hypercall(struct kvm_vcpu *vcpu, unsigned long nr, >> + unsigned long a0, unsigned long a1, >> + unsigned long a2, unsigned long a3, >> + int op_64_bit) >> { >> - unsigned long nr, a0, a1, a2, a3, ret; >> - int op_64_bit; >> - >> - if (kvm_xen_hypercall_enabled(vcpu->kvm)) >> - return kvm_xen_hypercall(vcpu); >> - >> - if (kvm_hv_hypercall_enabled(vcpu)) >> - return kvm_hv_hypercall(vcpu); Please keep Xen and Hyper-V hypercalls to kvm_emulate_hypercall (more on this in the reply to patch 89). __kvm_emulate_hypercall should only handle KVM hypercalls. >> + if (static_call(kvm_x86_get_cpl)(vcpu) != 0) { >> + ret = -KVM_EPERM; >> + goto out; >> + } Is this guaranteed by TDG.VP.VMCALL? Paolo >> + ret = __kvm_emulate_hypercall(vcpu, nr, a0, a1, a2, a3, op_64_bit); >> out: >> if (!op_64_bit) >> ret = (u32)ret; >> -- >> 2.25.1 >> > > Sagi >