Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3022595rwb; Mon, 15 Aug 2022 16:20:04 -0700 (PDT) X-Google-Smtp-Source: AA6agR50UlmFO/ScQJHP/XZQtpVZoW0LRQdq+S2BDEXKBmYonMF92jX+qOmk0VQvBpQPS1jCeXvk X-Received: by 2002:a17:902:d50a:b0:16e:e1c1:dfa7 with SMTP id b10-20020a170902d50a00b0016ee1c1dfa7mr19291521plg.160.1660605604622; Mon, 15 Aug 2022 16:20:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660605604; cv=none; d=google.com; s=arc-20160816; b=SbQ7zhpEGfmS187IpYMBlPz2EXj1164hI1mwd3cioQpkTZ5nSjgObCIbcS3emetd6W 1uuYQ8PmVq0AAoioIBy+mq5nZhZTsd8krh8WPhm303BAyioyD4SQiBCKUeQfy2iAL/AJ NOz0ENpDy8wRtmdy96IP7C39vSH93jH2xOHpVcZekT34t/3CuccaxmxFR9EGiRGN1DN4 GNHR5y3KFPQxcMcTTVJT4g7OnfHbwn+HfSLEW6sH0lZ6Q/RJJRiAj48xkAVGudc3DgzQ larBZi7ku9pHBNwSozbiUMpfd3OpcjKYt1UpZhe0+hkybjEFl5pbq2siWRmERd/nALuF 2sbA== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=wCQuHgVoPx3HlzWZjFTSDmFCT2nOK7VUC7EJ23elZxo=; b=QOVQV8n+37wcx7Iw/ag9iowo8UIovIucgjbX2UMYBIO0/4s1NrtYE2sQXKZzWbqhu4 kH8ynimyMXWxVxEdOfYL4LAId0wEsaoPnwuvjdhQoB3pacHvoXPHzjG+4iDOa8eklnjd 1/adf6dhbPwlISPUkaQGHyrzHUB27OpoGxLx0UswJEGDJ3CK8k/8tSJPRdjgZqAS87wD /kosW0k8HiFkq6DRSEI6mr7BHgvBIUWog1BVzFoKKXt1CQqlqGCyzxQV/TbODY53qJ/e AlUrmq+WDFFKWZzDm5mEA/Ojd+TD5tXjeso9N/om/sz63M7PdhnCuFvIG71H0O+Gn5Bf 3FKQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=xuFEkvfD; 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=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id jf1-20020a170903268100b0016f9027610dsi10232889plb.234.2022.08.15.16.19.53; Mon, 15 Aug 2022 16:20:04 -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=@linuxfoundation.org header.s=korg header.b=xuFEkvfD; 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=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242364AbiHOVcG (ORCPT + 99 others); Mon, 15 Aug 2022 17:32:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45036 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348044AbiHOV0w (ORCPT ); Mon, 15 Aug 2022 17:26:52 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2502315734; Mon, 15 Aug 2022 12:22:50 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 26AA361029; Mon, 15 Aug 2022 19:22:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 28BD0C433D6; Mon, 15 Aug 2022 19:22:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660591368; bh=ONiKSiNfoJ7cyniodmbLoVS9aaexIl6o8kiTkIsPUC0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xuFEkvfD0OTB5CfVKmMZMyXVAbwbHhrdrq3Id4wIgfDnawiHFOUuKvePSd/KG0nly vmxfGkpvco73GCJDV2hcfENOb+WZOfsIKJO5ev/OacVjJQC/W0mN7vRlBOAi4oqCeG qhokFOXrCO1MeNvWo6bplkO3zpXok4rl04VdnZRs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Maxim Levitsky , Sean Christopherson , "Maciej S. Szmigiero" , Paolo Bonzini , Sasha Levin Subject: [PATCH 5.18 0557/1095] KVM: SVM: Stuff next_rip on emulated INT3 injection if NRIPS is supported Date: Mon, 15 Aug 2022 19:59:16 +0200 Message-Id: <20220815180452.600078706@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180429.240518113@linuxfoundation.org> References: <20220815180429.240518113@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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: Sean Christopherson [ Upstream commit 3741aec4c38fa4123ab08ae552f05366d4fd05d8 ] 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 Message-Id: Signed-off-by: Paolo Bonzini Signed-off-by: Sasha Levin --- 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 e4c736d74fcb..e5a154f0d2ab 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -390,6 +390,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; } @@ -3616,7 +3620,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. -- 2.35.1