Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp1271466pxb; Thu, 24 Mar 2022 16:34:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz1OCAtr7hUSFBJU+vTg54S+GJNmkfxyPdLExksON35hzI6SMp09SQrEQbdcJEwZHOpvs8v X-Received: by 2002:a17:90b:4d88:b0:1c7:3d39:34c5 with SMTP id oj8-20020a17090b4d8800b001c73d3934c5mr9204446pjb.20.1648164885792; Thu, 24 Mar 2022 16:34:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648164885; cv=none; d=google.com; s=arc-20160816; b=iRBmf9dSHlPgL2uGeMbHFHlugUCnVzB6vK5dk/imZJvpUlLqEMXUky3kTydccmlUNM wZoz9SogMjeaZC+R2SGzflBlZfjA3wdCG4zz+k7347ADbH9tsvQxIXZVsP4WujWpx1CM iIq93Wu5JNZpNT5lZNtwAt/60CUWl867iCedlPsowdvsKNU/5jrfITjZ1mPHq/qj8dn/ IGU/q4Pup45a1/uC7Fcn2E+ggjwzwFmrvLKd/n4thwJIfWqyO9+1mULIZSqwnyeS18/0 9S3Z6d4s/1rKW3w+17wgtDB83o0DZMrEpS/V1JQj/PQaMtVvJWgLz7VSd/ZxeoZxmCyE fe1w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=av3oVTkIuwelRb9H5lhGzDrkVDnLj9TLsCFgqEGBm3c=; b=TS83dvdNfCyRNB4Yuo8WrQpC20P99zyeYozjFvBirkdXOHyDFqjj3ntl6rKGpO2CcJ /YbBplZ3vNXrLXNpGdCXniT7ampCTsW1rg1UGjAmDDXFUR48jrVMVtGlgyTCEoJr6xoX ZdwxDfnoI/CDw5oeSs3v4yrVIf93Zo2lCTZffBjT1zuFR93jDgSdK2KryDa3jEy+v+pK OkOwwVsnnUOf1Hq9NWrmr9bFaUVLiRr7K8rHXqmsA8/y9AXbq8trHn3RIuc8gBw7qRJN pD4KpKlAtgXEs8RQE2qEEbkEevr4de+sQtXxOL7CvvLPKNmIjTH21SjSHQL+Jq7TYrX6 QQaQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=nc042apV; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id nu7-20020a17090b1b0700b001c4ea95a3bfsi1187590pjb.63.2022.03.24.16.34.31; Thu, 24 Mar 2022 16:34:45 -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=@gmail.com header.s=20210112 header.b=nc042apV; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343634AbiCWRz3 (ORCPT + 99 others); Wed, 23 Mar 2022 13:55:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43098 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234034AbiCWRz1 (ORCPT ); Wed, 23 Mar 2022 13:55:27 -0400 Received: from mail-pj1-x1036.google.com (mail-pj1-x1036.google.com [IPv6:2607:f8b0:4864:20::1036]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 44111B7D8; Wed, 23 Mar 2022 10:53:52 -0700 (PDT) Received: by mail-pj1-x1036.google.com with SMTP id bx24-20020a17090af49800b001c6872a9e4eso2568836pjb.5; Wed, 23 Mar 2022 10:53:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=av3oVTkIuwelRb9H5lhGzDrkVDnLj9TLsCFgqEGBm3c=; b=nc042apVOa/LPU90QaefUbTbXVcxNcYhxef20yaJri9DYzk5KjZyCYFhFzV5HSeJY0 GbjKDOeKzgXufOPBUPQikaXjZM4KsvVmrY//P3Lbyg4g1Kf0zRPJk31rA/c/7g1mBlEA BSDnY5k4WtMcxH+cbQuAMifTDFN25f8iVglUiDfQZjUUNOQyjDPdlRCDadw38jAE4EAW di8V6uxednFOWFHWlDaQi54GWtzxf8d97d/r7QguBDTudmaZhqyfL7BpWqZ6EZP6mfev ax85S7N/bmznNFwyv5+aARRMOUqb3IUFA3B1ihvzaGyGKXHtL0BtBqLEGU/C017eu8// AjOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=av3oVTkIuwelRb9H5lhGzDrkVDnLj9TLsCFgqEGBm3c=; b=3V7hZYnmiIIhKg1CDP/EAwTkcZJUvsfBrBqkimlbDB3wjd+RIGbJPg14naoii+RDMt 8H9waH2o7ND8X4QG3sa04ZVXoNA/IqjDzzoQdPaQXmzJji+blUNkihEbFsSiLVlPmiAe DXKDAymz3S830CNbA+uTVxbhaa9wZp1TI75TO+UmzDxvaDbaKxwJ5Qna+mKJtvoNbTEg 8bLjSZ43MG1Owxv3tNA7RY+S4r/Eupj+D6vaxe7qE0bIQDHKZd/wD5IzvkXGbj74dN0R wfNF+acs7/3dhDAcQWPc2wi3fcVyyUM6gJZERbc7hJpW0KDyXnAujK5vifbNKFKySfYL 2D8w== X-Gm-Message-State: AOAM533OfHPSH1e4KMzcLOejfTnRj60+lGM1B5v5up9Lb2K9ECcE2YUh iKHGmheWpWkSpdxItI6vahbIvMwFbUx1lw== X-Received: by 2002:a17:902:ea0c:b0:154:16a6:7025 with SMTP id s12-20020a170902ea0c00b0015416a67025mr1332608plg.104.1648058032076; Wed, 23 Mar 2022 10:53:52 -0700 (PDT) Received: from localhost ([192.55.54.52]) by smtp.gmail.com with ESMTPSA id s30-20020a056a001c5e00b004f73f27aa40sm515081pfw.161.2022.03.23.10.53.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Mar 2022 10:53:51 -0700 (PDT) Date: Wed, 23 Mar 2022 10:53:49 -0700 From: Isaku Yamahata To: Sagi Shahar Cc: "Yamahata, Isaku" , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, isaku.yamahata@gmail.com, Paolo Bonzini , Jim Mattson , Erdem Aktas , Connor Kuehl , Sean Christopherson Subject: Re: [RFC PATCH v5 083/104] KVM: x86: Split core of hypercall emulation to helper function Message-ID: <20220323175349.GF1964605@ls.amr.corp.intel.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,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 On Mon, Mar 21, 2022 at 11:32:21AM -0700, Sagi Shahar wrote: > > 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); > > - > > - nr = kvm_rax_read(vcpu); > > - a0 = kvm_rbx_read(vcpu); > > - a1 = kvm_rcx_read(vcpu); > > - a2 = kvm_rdx_read(vcpu); > > - a3 = kvm_rsi_read(vcpu); > > + unsigned long ret; > > > > trace_kvm_hypercall(nr, a0, a1, a2, a3); > > > > - op_64_bit = is_64_bit_hypercall(vcpu); > > if (!op_64_bit) { > > nr &= 0xFFFFFFFF; > > a0 &= 0xFFFFFFFF; > > @@ -9118,11 +9107,6 @@ int kvm_emulate_hypercall(struct kvm_vcpu *vcpu) > > a3 &= 0xFFFFFFFF; > > } > > > > - if (static_call(kvm_x86_get_cpl)(vcpu) != 0) { > > - ret = -KVM_EPERM; > > - goto out; > > - } > > - > > ret = -KVM_ENOSYS; > > > > switch (nr) { > > @@ -9181,6 +9165,34 @@ int kvm_emulate_hypercall(struct kvm_vcpu *vcpu) > > ret = -KVM_ENOSYS; > > break; > > } > > + return ret; > > +} > > +EXPORT_SYMBOL_GPL(__kvm_emulate_hypercall); > > + > > +int kvm_emulate_hypercall(struct kvm_vcpu *vcpu) > > +{ > > + 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); > > + > > + nr = kvm_rax_read(vcpu); > > + a0 = kvm_rbx_read(vcpu); > > + a1 = kvm_rcx_read(vcpu); > > + a2 = kvm_rdx_read(vcpu); > > + a3 = kvm_rsi_read(vcpu); > > + op_64_bit = is_64_bit_mode(vcpu); > > I think this should be "op_64_bit = is_64_bit_hypercall(vcpu);" > is_64_bit_mode was replaced with is_64_bit_hypercall to support > protected guests here: > https://lore.kernel.org/all/87cztf8h43.fsf@vitty.brq.redhat.com/T/ > > Without it, op_64_bit will be set to 0 for TD VMs which will cause the > upper 32 bit of the registers to be cleared in __kvm_emulate_hypercall Oops, thanks for pointing it out. I'll fix it up with next respin. -- Isaku Yamahata