Received: by 2002:a05:6a10:83d0:0:0:0:0 with SMTP id o16csp74661pxh; Thu, 7 Apr 2022 14:25:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwDq8PGGGMeWQlsWFHi+GGCVN6TTCLc/N8CObqy25M7GtO9EweQSTpfRwTGhfvdzeGzWLUS X-Received: by 2002:a17:902:c2d8:b0:154:b384:917b with SMTP id c24-20020a170902c2d800b00154b384917bmr16400982pla.58.1649366709697; Thu, 07 Apr 2022 14:25:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649366709; cv=none; d=google.com; s=arc-20160816; b=eO46gkWUbNL3UVNoScD5sF1SYnhcLHNtxe+zAC+oOMDODNYYz/nB7fYbK6X0X2ZmmF 9TetXhrQM8IV0Srqdyx6sUqzD1nDvNW+GOe8fT5apz5UoiRC6xE7K9w/jOEVQBZCP/2b EI3rcAloEvBU+GXIL+dWJVnFI9sfbkXXsh+OTnoYMAMxsfMQ8ae9vo6Hy78Fh4PRSBN0 PzxDLzZICG1jHwlDe3Cc+MkDAcGUZLs5qYn0L8FZltcVyIHx2RkI4x0/PJReOcTmrYLE RcNfS29Dltb6UKlbnS5GbK/DJnnZqG2SxlSNo2K2zgoQ4TI1EYdhse/immkCoOg86ue3 tbZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=jgcFIANEmV3DqgP0seVeVyH30NWV2QqOukTsdkt/MFU=; b=m/rEr1enk1IuuhqiVPWthroRuzoClv5lT76xqzXvyOtrbQnU2haYeD6B+xAwmNc3Dm cC+sMifDPDOQ7HjpGaPBEznttEGUGQTHhNtJ5VmlxUtiypQJg120/dPXvYJQYT5dyVUw IW8cymTzP/Oms9Bpuk+KWD6kGrKrbcL4fM/ROvFMf/LW74SdfekbuhUxVB3I9gKnnd30 2YHHaIqUkcVAn4jwBPLWh42R726kpQaMGRpgzKRUnmiGR7kuOryWutZaTVRIM3xN5OIx WSTGwaot90pW44zNlzkHyFTbDWAXlz/BrI8cN+L3x5f5QZ++91jMu7in1N6/6z2ofY8z T8yQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=GzFwkDGI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id nv5-20020a17090b1b4500b001cac971d844si3188126pjb.31.2022.04.07.14.25.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Apr 2022 14:25:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=GzFwkDGI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 62AC348CC50; Thu, 7 Apr 2022 13:16:41 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343596AbiDGNPH (ORCPT + 99 others); Thu, 7 Apr 2022 09:15:07 -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-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 X-Spam-Status: No, score=-4.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,RDNS_NONE,SPF_HELO_NONE, T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 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 >