Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp23611pxp; Thu, 10 Mar 2022 21:26:23 -0800 (PST) X-Google-Smtp-Source: ABdhPJweRJCjXhZNKPHxeLDChK6TUUUMl16EfhROA+wviNp4CGyXGT9algZCxmp/HWTJ2tVX2HsF X-Received: by 2002:aa7:cd03:0:b0:415:e625:7b61 with SMTP id b3-20020aa7cd03000000b00415e6257b61mr7261091edw.248.1646976383748; Thu, 10 Mar 2022 21:26:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646976383; cv=none; d=google.com; s=arc-20160816; b=NvX7Hb/kajRolGjx/TKXgWmRuTQZka131AfVJ5eaoAKQiA7tWOypW9YHbLLqMo12rs Buz6BWcVLFZVrjzp4zT+chfvj+xqYuclZk3jJMFUmWVLT3sWr2BOKfSzG9bP3W7WyNjh ++fHNgUjXMbAPN14qWf5NSXYR7/kcvUQnIrXVtYLWJYKI6QgY86IeAzG4Mv6L5+oHeDK fNA2LqGI300NiyDpJwbaHtDEx8gLIwK2TU381mw9WFnF5pJm+lCR2p4+Biric9c/nO46 0FJa6b1svyf9or9iq25/4r3EJaAe2Z3SdpFWSlCWN9xe5+Nbtg1SeSGlWn8aWMjneoEz ZYlQ== 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=bRG+Fai5HnT//ie6Wwbdu6tW67kUCn+jn46tA4cqyMU=; b=0qtFtDp298vrgOcG+M8GxELA/KROsLDbg/Q0784e46iyFvzwlj7CaX/uiS+xQrlsx8 NvHTeItiC4d48X7zb20Qm6clijDykgVA6ZrJQvoTTCtAxMvYOyfgTkIkK/LSze9Hh/rV oE9a5WD1S14vfGVEmQHj7SvaiupTbo1tOD7bhLdUPeGhK4A3jo1feLIu0K47q5/JpuUz hWT93jljDXKKb9hf/FsjuaOVNiMQ9kX4juXwcU5CLvHY6zApkn5v0Ri+eUv8ATplW/VD kxTpu6QqJ7l1owKiVA3Cn2RwsQxo7LpIL1ajdULaSYanuWAyfRzpOLpYjsuCQ/p5Qreh 1nPQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id sa6-20020a170906eda600b006db8e7c2ecbsi1666129ejb.816.2022.03.10.21.25.56; Thu, 10 Mar 2022 21:26:23 -0800 (PST) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344029AbiCJVkc (ORCPT + 99 others); Thu, 10 Mar 2022 16:40:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56986 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344025AbiCJVka (ORCPT ); Thu, 10 Mar 2022 16:40:30 -0500 Received: from vps-vb.mhejs.net (vps-vb.mhejs.net [37.28.154.113]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5B9CAC0856; Thu, 10 Mar 2022 13:39:27 -0800 (PST) Received: from MUA by vps-vb.mhejs.net with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1nSQUm-0006It-FR; Thu, 10 Mar 2022 22:38:52 +0100 From: "Maciej S. Szmigiero" To: Paolo Bonzini Cc: Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Tom Lendacky , Brijesh Singh , Jon Grimm , David Kaplan , Boris Ostrovsky , Liam Merwick , kvm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/5] KVM: nSVM: Sync next_rip field from vmcb12 to vmcb02 Date: Thu, 10 Mar 2022 22:38:37 +0100 Message-Id: <19c757487eeeff5344ff3684fe9c090235b07d05.1646944472.git.maciej.szmigiero@oracle.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,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 From: "Maciej S. Szmigiero" The next_rip field of a VMCB is *not* an output-only field for a VMRUN. This field value (instead of the saved guest RIP) in used by the CPU for the return address pushed on stack when injecting a software interrupt or INT3 or INTO exception. Make sure this field gets synced from vmcb12 to vmcb02 when entering L2 or loading a nested state. Signed-off-by: Maciej S. Szmigiero --- arch/x86/kvm/svm/nested.c | 4 ++++ arch/x86/kvm/svm/svm.h | 1 + 2 files changed, 5 insertions(+) diff --git a/arch/x86/kvm/svm/nested.c b/arch/x86/kvm/svm/nested.c index d736ec6514ca..9656f0d6815c 100644 --- a/arch/x86/kvm/svm/nested.c +++ b/arch/x86/kvm/svm/nested.c @@ -366,6 +366,7 @@ void __nested_copy_vmcb_control_to_cache(struct kvm_vcpu *vcpu, to->nested_ctl = from->nested_ctl; to->event_inj = from->event_inj; to->event_inj_err = from->event_inj_err; + to->next_rip = from->next_rip; to->nested_cr3 = from->nested_cr3; to->virt_ext = from->virt_ext; to->pause_filter_count = from->pause_filter_count; @@ -638,6 +639,8 @@ static void nested_vmcb02_prepare_control(struct vcpu_svm *svm) svm->vmcb->control.int_state = svm->nested.ctl.int_state; svm->vmcb->control.event_inj = svm->nested.ctl.event_inj; svm->vmcb->control.event_inj_err = svm->nested.ctl.event_inj_err; + /* The return address pushed on stack by the CPU for some injected events */ + svm->vmcb->control.next_rip = svm->nested.ctl.next_rip; if (!nested_vmcb_needs_vls_intercept(svm)) svm->vmcb->control.virt_ext |= VIRTUAL_VMLOAD_VMSAVE_ENABLE_MASK; @@ -1348,6 +1351,7 @@ static void nested_copy_vmcb_cache_to_control(struct vmcb_control_area *dst, dst->nested_ctl = from->nested_ctl; dst->event_inj = from->event_inj; dst->event_inj_err = from->event_inj_err; + dst->next_rip = from->next_rip; dst->nested_cr3 = from->nested_cr3; dst->virt_ext = from->virt_ext; dst->pause_filter_count = from->pause_filter_count; diff --git a/arch/x86/kvm/svm/svm.h b/arch/x86/kvm/svm/svm.h index 93502d2a52ce..f757400fc933 100644 --- a/arch/x86/kvm/svm/svm.h +++ b/arch/x86/kvm/svm/svm.h @@ -138,6 +138,7 @@ struct vmcb_ctrl_area_cached { u64 nested_ctl; u32 event_inj; u32 event_inj_err; + u64 next_rip; u64 nested_cr3; u64 virt_ext; u32 clean;