Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp223643iob; Mon, 2 May 2022 17:43:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyzcfVR8SxlWf0VuMwaAknSob/xuro4M+a62Z7bSGP0uu8FEaQU13RXdZu4Cg63PLgZg23+ X-Received: by 2002:a17:90b:4a8a:b0:1d2:f7ba:8728 with SMTP id lp10-20020a17090b4a8a00b001d2f7ba8728mr1941399pjb.43.1651538584725; Mon, 02 May 2022 17:43:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651538584; cv=none; d=google.com; s=arc-20160816; b=AYvTllClb9YkS3mZ8Mz9Yi56MThZqIvK17hRXgFWxqdWfWbbYmJDk5uN/6fProKoq7 Zm+5hc9SgO78YSiaNgpCBJn14zbAv+xx4lchX7AR592ZpAEuoUbMfpj5GDbjphMi2rki Kw4HiYciqZzcv16ZP3oBrbwKEIJEKKIwQU5IaNZ2uiKijXqa1+yTV6r1TKSogR3qsIzC 5yaHFjNZMClZZmrpivkBd5OB4/BW2AjllO9JxpDiJDlZR60rKFpd6wrQNCkMbaVzzGc6 R4xl5UCHFT0aQfdYAfhS8JhKK60w+U2ogttaT0jWL+mrtkY5YZ+oru8J+trSB45wPwX6 fMag== 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=16G+i/DyxC7/crgQtTJIJkq4igOOlUdWdSrWNvn7q/g=; b=t1rkrJOiQPhgiEenk8gNq6e29wuERx0Z5DHHlWo7o1p10p9klSdl43KoIfvjMq6P5R TZPAH5g1XPieB0nmr/+0kExgjfgCi67sEqQYdvq+cRvOlSSEJXXroGEYHPLeg3VI2xgL QVGtNCg7KPv+/PFQl7UOwwJvHE8XtuMgzAHGST+GSkR7sVNde32MoNI32m7jwmRuW6R+ l/AOVHsczaaUEpiEZKRPJ9ZamPiQZdteC7ZXEx7+lIrTC1Vb860zJ11eebenNPTx4Duq YmtKWo5hN+UhrKRKFzHdoG07oRyAdpY7emX+CNtMUB0WkBhQ1YusbHLoM1l7zqNAwarq i0AQ== ARC-Authentication-Results: i=1; mx.google.com; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id i190-20020a6387c7000000b0039890725054si14130732pge.711.2022.05.02.17.43.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 May 2022 17:43:04 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 40EAE41F88; Mon, 2 May 2022 17:33:04 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376725AbiEAWLn (ORCPT + 99 others); Sun, 1 May 2022 18:11:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44284 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1355597AbiEAWLi (ORCPT ); Sun, 1 May 2022 18:11:38 -0400 Received: from vps-vb.mhejs.net (vps-vb.mhejs.net [37.28.154.113]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CC04B26118; Sun, 1 May 2022 15:08:09 -0700 (PDT) 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 1nlHjX-0008NO-BV; Mon, 02 May 2022 00:08:03 +0200 From: "Maciej S. Szmigiero" To: Paolo Bonzini , Sean Christopherson Cc: Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Maxim Levitsky , kvm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 04/12] KVM: SVM: Stuff next_rip on emulated INT3 injection if NRIPS is supported Date: Mon, 2 May 2022 00:07:28 +0200 Message-Id: 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, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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: Sean Christopherson If NRIPS is supported in hardware but disabled in KVM, set next_rip to the next RIP when advancing RIP as part of emulating INT3 injection. There is no flag to tell the CPU that KVM isn't using next_rip, and so leaving next_rip is left as is will result in the CPU pushing garbage onto the stack when vectoring the injected event. Reviewed-by: Maxim Levitsky Fixes: 66b7138f9136 ("KVM: SVM: Emulate nRIP feature when reinjecting INT3") Signed-off-by: Sean Christopherson Signed-off-by: Maciej S. Szmigiero --- arch/x86/kvm/svm/svm.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index 1a719f47a964..a05a4e521400 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -392,6 +392,10 @@ static void svm_queue_exception(struct kvm_vcpu *vcpu) */ (void)svm_skip_emulated_instruction(vcpu); rip = kvm_rip_read(vcpu); + + if (boot_cpu_has(X86_FEATURE_NRIPS)) + svm->vmcb->control.next_rip = rip; + svm->int3_rip = rip + svm->vmcb->save.cs.base; svm->int3_injected = rip - old_rip; } @@ -3701,7 +3705,7 @@ static void svm_complete_interrupts(struct kvm_vcpu *vcpu) /* * If NextRIP isn't enabled, KVM must manually advance RIP prior to * injecting the soft exception/interrupt. That advancement needs to - * be unwound if vectoring didn't complete. Note, the _new_ event may + * be unwound if vectoring didn't complete. Note, the new event may * not be the injected event, e.g. if KVM injected an INTn, the INTn * hit a #NP in the guest, and the #NP encountered a #PF, the #NP will * be the reported vectored event, but RIP still needs to be unwound.