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 X-Spam-Level: X-Spam-Status: No, score=-18.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D8342C43460 for ; Tue, 6 Apr 2021 15:20:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B1C7361363 for ; Tue, 6 Apr 2021 15:20:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345584AbhDFPUj (ORCPT ); Tue, 6 Apr 2021 11:20:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54632 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345574AbhDFPUf (ORCPT ); Tue, 6 Apr 2021 11:20:35 -0400 Received: from mail-pf1-x436.google.com (mail-pf1-x436.google.com [IPv6:2607:f8b0:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DCCE0C061756 for ; Tue, 6 Apr 2021 08:20:26 -0700 (PDT) Received: by mail-pf1-x436.google.com with SMTP id c204so6906242pfc.4 for ; Tue, 06 Apr 2021 08:20:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=3nOOElHtuWxIjwzeA4Qinf+awOERwf/3FOuhhm/HNjs=; b=DXRlea9AoD5zyghCYi8ymKEiSBVn7dC3We79fEcLjckA7HgurQXC9sPhgikxfaiDs2 8KAKCaBzmH481ePtDqo4g6kz7zbSRfyUx/DvlFAH6CHx5DUTBs5OP1BnjQOz+Gd3sg2M zwJmQYLdw561TJwF7XJexozk62vjy/+h4lWXWt3MLea5Oz9wiBmthw0kvzrE0Cgm438+ XvxTUqmU0QJRsyQ7CyvCrUAt+JNXM35W2OdV4cdgBIrNAdrHCWKJuShFQXQdyoKzsTgw E8SZ7jejXiHOFJqVmoQ2P8hCw3S952lQCIT7SwCj1dW1sI2OF48QOQhENP19wORlLoQH 0s0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=3nOOElHtuWxIjwzeA4Qinf+awOERwf/3FOuhhm/HNjs=; b=e7exPajVL+S3SqhzhxCzIIm6XT9W2hqGF9SlWMsbNEg38+J2V+PT0qqmkX6B3iwyZm tZ/pxbrwtjJ3ZHALqUwTHKnRggQ0VotYtOpDp5482TwJlVqlbtq3RiVeMyHZ+aq1LOmh /P1HIIk9dTa4WL4PssY/FZ62KpXMSdbpGUzvSdmlAgctTkm51Tbuqp82kdJGaT2Czf0w 7nwck+d/aAFLG5cKk35THOvmiv17H2YbbcgU8vQtV7m518nL7hWAuUr59VcPJQiY40q+ xcITXpZTr2WPB1zkei/z4m0+NUvjEAud8UfyQsZ9llBF0acWJcMXmMmxUGTg3bct7sDj 7yGA== X-Gm-Message-State: AOAM533px1Tiu9IgGv6OoBx2d5O5C9TNsSFZW9Fg0OB/45med/R2Rl3V 4nA9IjpHSl5i0Yv5Fa4PCihg8A== X-Google-Smtp-Source: ABdhPJwIlNMnMJhHkep8TJKMaoNN2Ei5py3EvYJq4iN+mOj72qEFF1vT7r+lHVAyRTf0ba12RUuvKQ== X-Received: by 2002:a63:4522:: with SMTP id s34mr27217308pga.250.1617722426232; Tue, 06 Apr 2021 08:20:26 -0700 (PDT) Received: from google.com (240.111.247.35.bc.googleusercontent.com. [35.247.111.240]) by smtp.gmail.com with ESMTPSA id p22sm2882027pjg.39.2021.04.06.08.20.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Apr 2021 08:20:25 -0700 (PDT) Date: Tue, 6 Apr 2021 15:20:21 +0000 From: Sean Christopherson To: Ashish Kalra Cc: Steve Rutherford , Paolo Bonzini , Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , Joerg Roedel , Borislav Petkov , Tom Lendacky , X86 ML , KVM list , LKML , Venu Busireddy , Brijesh Singh , Will Deacon , maz@kernel.org, Quentin Perret Subject: Re: [PATCH v11 08/13] KVM: X86: Introduce KVM_HC_PAGE_ENC_STATUS hypercall Message-ID: References: <4da0d40c309a21ba3952d06f346b6411930729c9.1617302792.git.ashish.kalra@amd.com> <20210406062248.GA22937@ashkalra_ubuntu_server> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Apr 06, 2021, Sean Christopherson wrote: > On Tue, Apr 06, 2021, Ashish Kalra wrote: > > On Mon, Apr 05, 2021 at 01:42:42PM -0700, Steve Rutherford wrote: > > > On Mon, Apr 5, 2021 at 7:28 AM Ashish Kalra wrote: > > > > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c > > > > index f7d12fca397b..ef5c77d59651 100644 > > > > --- a/arch/x86/kvm/x86.c > > > > +++ b/arch/x86/kvm/x86.c > > > > @@ -8273,6 +8273,18 @@ int kvm_emulate_hypercall(struct kvm_vcpu *vcpu) > > > > kvm_sched_yield(vcpu->kvm, a0); > > > > ret = 0; > > > > break; > > > > + case KVM_HC_PAGE_ENC_STATUS: { > > > > + int r; > > > > + > > > > + ret = -KVM_ENOSYS; > > > > + if (kvm_x86_ops.page_enc_status_hc) { > > > > + r = kvm_x86_ops.page_enc_status_hc(vcpu, a0, a1, a2); > > > > + if (r >= 0) > > > > + return r; > > > > + ret = r; > > > Style nit: Why not just set ret, and return ret if ret >=0? > > > > > > > But ret is "unsigned long", if i set ret and return, then i will return to guest > > even in case of error above ? > > As proposed, svm_page_enc_status_hc() already hooks complete_userspace_io(), so > this could be hoisted out of the switch statement. > > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c > index 16fb39503296..794dde3adfab 100644 > --- a/arch/x86/kvm/x86.c > +++ b/arch/x86/kvm/x86.c > @@ -8261,6 +8261,10 @@ int kvm_emulate_hypercall(struct kvm_vcpu *vcpu) > goto out; > } > > + /* comment goes here */ > + if (nr == KVM_HC_PAGE_ENC_STATUS && kvm_x86_ops.page_enc_status_hc) > + return static_call(kvm_x86_page_enc_status_hc(vcpu, a0, a1, a2)); Gah, the SEV implementation can also return -EINVAL, and that should fail the hypercall, not kill the guest. Normally we try to avoid output params, but in this case it might be less ugly to do: case KVM_HC_PAGE_ENC_STATUS: { if (!kvm_x86_ops.page_enc_status_hc) break; if (!static_call(kvm_x86_page_enc_status_hc(vcpu, a0, a1, a2, &ret)); return 0; break; > + > ret = -KVM_ENOSYS; > > switch (nr) { >