Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp3643968imm; Mon, 18 Jun 2018 01:26:26 -0700 (PDT) X-Google-Smtp-Source: ADUXVKL/I5/D9B2Ao2TkHoJHbVNdhpDTAeN1lTyudIOxgQH9E0zP6mB47JXW5gCa0dSd5bc1efoe X-Received: by 2002:a63:40c7:: with SMTP id n190-v6mr10244826pga.248.1529310385961; Mon, 18 Jun 2018 01:26:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529310385; cv=none; d=google.com; s=arc-20160816; b=JWU+i6GkRyaB2HlZkOpUhNFtzgaekq0dcip/XX268Dlivsm8o1aHCPa3+p5ey6h7rf 8gw7LCxRkrJaCq+UhgakDaBmYBzFV2Mrh2qulSBbGJs2TRXCMVHRAedRtK7LoBv8e/c4 r1tIbDo6I63kBxR53Lke+4BlGAiabIMuZFmEm0paZfAC7QKVrVaOnKfhHevioK83obe1 XAUEnZontLRS0k1l/KgrREPvyTLAXJ6dHIW+lNBwm5jCj1JmIi/mUguxzDZOIZ106ijg Q+ETx6JgXYAJKW1T4F9llOPv8uH/ZDHXogN5SJIZQm9q7QXv+Q4rjad9s/RbrAf54TIL 48aQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=k3YAqluBh2x3T77aWM8b03y4EYfkyc/blryqyw2VCAs=; b=dM5Tkv0bcIqr0DSgyLERSphtmoYTOOTFZtEv3RZ/w/LZCgoC73dFjU8D9F2uUwkaO4 o6eJ9l3aNBLFbsGsYIwDqkZbl4o18iyfhrbuZwGhv9Pk73yI+Kw4qBsS3FA8+X6IQ5KR 8UREqmpJ+WegEWdNMPfAGFQKNmdyB+o/dopPsJLdV0B17RHKREnhkoFPgETfVFwiMuNZ Um/vwOmKOo1J4vDj2ETbDZ0s7hHKKhmFWYtY005oWoV5F1Z+Z44taQFwvRNLM6+qPLu+ nA8y4KNNnC64oifVPxztaKgPgvSk5weHQa7vj3V+3TlIksoBkQOlcBn4Lm1Bb877oEs9 Gr9w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x2-v6si13217715pfn.315.2018.06.18.01.26.12; Mon, 18 Jun 2018 01:26:25 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965845AbeFRIZi (ORCPT + 99 others); Mon, 18 Jun 2018 04:25:38 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:56576 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965354AbeFRIZf (ORCPT ); Mon, 18 Jun 2018 04:25:35 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 85CE7C9E; Mon, 18 Jun 2018 08:25:34 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Marian Rotariu , Paolo Bonzini , Sasha Levin Subject: [PATCH 4.16 221/279] x86: Delay skip of emulated hypercall instruction Date: Mon, 18 Jun 2018 10:13:26 +0200 Message-Id: <20180618080617.988782810@linuxfoundation.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180618080608.851973560@linuxfoundation.org> References: <20180618080608.851973560@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.16-stable review patch. If anyone has any objections, please let me know. ------------------ From: Marian Rotariu [ Upstream commit 6356ee0c9602004e0a3b4b2dad68ee2ee9385b17 ] The IP increment should be done after the hypercall emulation, after calling the various handlers. In this way, these handlers can accurately identify the the IP of the VMCALL if they need it. This patch keeps the same functionality for the Hyper-V handler which does not use the return code of the standard kvm_skip_emulated_instruction() call. Signed-off-by: Marian Rotariu [Hyper-V hypercalls also need kvm_skip_emulated_instruction() - Paolo] Signed-off-by: Paolo Bonzini Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- arch/x86/kvm/hyperv.c | 2 +- arch/x86/kvm/x86.c | 19 +++++++++++-------- 2 files changed, 12 insertions(+), 9 deletions(-) --- a/arch/x86/kvm/hyperv.c +++ b/arch/x86/kvm/hyperv.c @@ -1223,7 +1223,7 @@ static int kvm_hv_hypercall_complete_use struct kvm_run *run = vcpu->run; kvm_hv_hypercall_set_result(vcpu, run->hyperv.u.hcall.result); - return 1; + return kvm_skip_emulated_instruction(vcpu); } int kvm_hv_hypercall(struct kvm_vcpu *vcpu) --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -6553,12 +6553,13 @@ void kvm_vcpu_deactivate_apicv(struct kv int kvm_emulate_hypercall(struct kvm_vcpu *vcpu) { unsigned long nr, a0, a1, a2, a3, ret; - int op_64_bit, r; + int op_64_bit; - r = kvm_skip_emulated_instruction(vcpu); - - if (kvm_hv_hypercall_enabled(vcpu->kvm)) - return kvm_hv_hypercall(vcpu); + if (kvm_hv_hypercall_enabled(vcpu->kvm)) { + if (!kvm_hv_hypercall(vcpu)) + return 0; + goto out; + } nr = kvm_register_read(vcpu, VCPU_REGS_RAX); a0 = kvm_register_read(vcpu, VCPU_REGS_RBX); @@ -6579,7 +6580,7 @@ int kvm_emulate_hypercall(struct kvm_vcp if (kvm_x86_ops->get_cpl(vcpu) != 0) { ret = -KVM_EPERM; - goto out; + goto out_error; } switch (nr) { @@ -6599,12 +6600,14 @@ int kvm_emulate_hypercall(struct kvm_vcp ret = -KVM_ENOSYS; break; } -out: +out_error: if (!op_64_bit) ret = (u32)ret; kvm_register_write(vcpu, VCPU_REGS_RAX, ret); + +out: ++vcpu->stat.hypercalls; - return r; + return kvm_skip_emulated_instruction(vcpu); } EXPORT_SYMBOL_GPL(kvm_emulate_hypercall);