Received: by 2002:a05:6a10:eb17:0:0:0:0 with SMTP id hx23csp442682pxb; Thu, 9 Sep 2021 04:42:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzTZ9yIYcNjVd11TF4T1X86wAacOjB2GhVn4oVOQHztX01+CSeJOQ9jgayicQd156HPT+1o X-Received: by 2002:aa7:d0c9:: with SMTP id u9mr2680902edo.167.1631187722964; Thu, 09 Sep 2021 04:42:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631187722; cv=none; d=google.com; s=arc-20160816; b=ujERzusr9GKXmCvrzcv+CQXi+2oFM4u10TE9b3Pq80nGnG2+nKsnNl+xkgK4YsN3IJ 1yQ6czkNrs0ZPq9+klJfz17euBt/C/m3h+gw+eyaimKC1jMqDPkv9a5VihihvNBkk6AL HIHaBIKNugu1q6D6Hj0t6XVGF6MYgRFRDVq5O4S1Pd4qEyAvxxA/pi8sByXVNQwMelv3 Jklgs66Dj2LGqOZ1lCnEfiCKjffr7oTLqKf9LVD+LGSacZom4syFb6Rksm0hLuYV+aXC TFq0u57lGxl2QSBI0pJ8xmx4smLYM6gpph7xqhgXuvqn/MZHQ/cCB2/wPnoNIJFlCV58 sMow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=yPuYasrEUMcc5FH4MhOcIN+yZpvUOPgfYQyvojBmuSU=; b=iMogMlM/WQFJBT4XksF6sSQXJ0zFa1/OWu8ti+q96Ywh5XKrV4k9WS675ZyTPTuK+u 7wYFRt5BAoW209C4aztpHAUygEUj1MjFlIH7ZwS7EF48kSyNRFLUeSvkSD+SS9thtCsK PX9wxHeqYlC1/uoLMHFLglquVdfuk1n/IC9zDbAymawTwVVJD2GvMARx2wkfCSCGcdoW 4DIRyEeSCUnnYNaBz1y+IQvQK5CiNeV1tgmYRGuh4SR3tFoGDd0vRoTnFh2hRlcubXKn k6MBzPAzpwDHM1xmlweu0z+PaBR6kQEmLIyfH7Csd17hOaqVME04MyegbBXwRaTbxa3c G3kg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h25si1573926edv.624.2021.09.09.04.41.38; Thu, 09 Sep 2021 04:42:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236222AbhIILjT (ORCPT + 99 others); Thu, 9 Sep 2021 07:39:19 -0400 Received: from out30-56.freemail.mail.aliyun.com ([115.124.30.56]:55617 "EHLO out30-56.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235658AbhIILjK (ORCPT ); Thu, 9 Sep 2021 07:39:10 -0400 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R111e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=alimailimapcm10staff010182156082;MF=houwenlong93@linux.alibaba.com;NM=1;PH=DS;RN=13;SR=0;TI=SMTPD_---0Unnf9Xb_1631187478; Received: from localhost(mailfrom:houwenlong93@linux.alibaba.com fp:SMTPD_---0Unnf9Xb_1631187478) by smtp.aliyun-inc.com(127.0.0.1); Thu, 09 Sep 2021 19:37:59 +0800 From: Hou Wenlong To: kvm@vger.kernel.org Cc: Paolo Bonzini , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org (maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)), "H. Peter Anvin" , linux-kernel@vger.kernel.org (open list:X86 ARCHITECTURE (32-BIT AND 64-BIT)) Subject: [PATCH 2/3] kvm: x86: Refactor kvm_emulate_hypercall() to no skip instruction Date: Thu, 9 Sep 2021 19:37:55 +0800 Message-Id: <961516749b864f8f8397905cc5d4a7db60f45dbe.1631186996.git.houwenlong93@linux.alibaba.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Refactor kvm_emulate_hypercall() to no skip instruction, it can be used in next patch for emulating hypercall in instruction emulation. Signed-off-by: Hou Wenlong --- arch/x86/kvm/x86.c | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 4e2836b94a01..b8d799e1c57c 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -8636,17 +8636,11 @@ static int complete_hypercall_exit(struct kvm_vcpu *vcpu) return kvm_skip_emulated_instruction(vcpu); } -int kvm_emulate_hypercall(struct kvm_vcpu *vcpu) +static int kvm_emulate_hypercall_noskip(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); @@ -8664,11 +8658,6 @@ int kvm_emulate_hypercall(struct kvm_vcpu *vcpu) a3 &= 0xFFFFFFFF; } - if (static_call(kvm_x86_get_cpl)(vcpu) != 0) { - static_call(kvm_x86_handle_hypercall_fail)(vcpu); - return 1; - } - ret = -KVM_ENOSYS; switch (nr) { @@ -8733,7 +8722,28 @@ int kvm_emulate_hypercall(struct kvm_vcpu *vcpu) kvm_rax_write(vcpu, ret); ++vcpu->stat.hypercalls; - return kvm_skip_emulated_instruction(vcpu); + return 1; +} + +int kvm_emulate_hypercall(struct kvm_vcpu *vcpu) +{ + int ret; + + if (kvm_xen_hypercall_enabled(vcpu->kvm)) + return kvm_xen_hypercall(vcpu); + + if (kvm_hv_hypercall_enabled(vcpu)) + return kvm_hv_hypercall(vcpu); + + if (static_call(kvm_x86_get_cpl)(vcpu) != 0) { + static_call(kvm_x86_handle_hypercall_fail)(vcpu); + return 1; + } + + ret = kvm_emulate_hypercall_noskip(vcpu); + if (ret) + return kvm_skip_emulated_instruction(vcpu); + return ret; } EXPORT_SYMBOL_GPL(kvm_emulate_hypercall); -- 2.31.1