Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp2217336pxb; Wed, 30 Mar 2022 19:39:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwi168IEd60VlyVJaQpHKO7PH2oZ92yZCwyg+xDWBg2YB3sjyuSgt1SoxpR1Rqf3+3rklY0 X-Received: by 2002:a05:6a00:4293:b0:4fa:e005:7e99 with SMTP id bx19-20020a056a00429300b004fae0057e99mr2994990pfb.20.1648694340741; Wed, 30 Mar 2022 19:39:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648694340; cv=none; d=google.com; s=arc-20160816; b=UE7r9m1cLJqR5ETy9U+GjXltD0c2iM4duuZjO+TtnDUHujHUrTq33CYdDcUZCOH+ib nLWQVh9xwBliVs7CptuglFGVqSHl/VXy0MGxvlV4AtJ8L1UqGY9TuO0tc+0dhhmR84+k upBuglCMxFkHgqXAk7ChE8M1pMChaCCzNE601nCLxMCx60MALKRgYtOZikkim0gkqr0W ATPlGyXxpIFW1XYLRVlV8U5BsExDRi5pqrRvGgEf1qwZYNDWS8H9VHYARHTMjcDGveaP Sbeo2e3AtasgS5lq6iQjuvOK1Fqbq0F26IIB/S+8XK0OcoNpzT+PIN1LeBVClRMhgumF WIFA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:subject :from:references:cc:to:content-language:user-agent:mime-version:date :message-id; bh=I8e5/CX+mXatZQwp+GuJbfD7Og5VNPSv8SMaGe/w5NU=; b=sjIYo77PXG7cEOfdlyJg8K06AxSugJdL6eboJYEzmR1nKLMNO8cWfsFfstkv4SFkab lk3RYWQLWVecIU2woE30+SfDaZASeu1twtzGS0aumHbs8Xj5BVgA1yuNWmT454XmjsZr tBpt6VUKuT11Dxb4Caz525Ku1fpgoUYSTtKelKaNFnB4SmUWf1EP/rgGoFTvbF48r7NZ fl0qAWl46y8FjVnAEm+hnjcY+81jvRupvseY7nvoJuwlcctC+Q7vru5CI15EnpOG32s8 +Prb/A7mg1PW/WImBRPUfj4EpQ7oaOYu/WnOCfafrV4SucZOfPTJd/8oewSaJKJRPZis /Vqw== 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 f128-20020a62db86000000b004fac74c8c8asi22105606pfg.329.2022.03.30.19.39.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Mar 2022 19:39:00 -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 A6919A0BD5; Wed, 30 Mar 2022 19:33:11 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351515AbiC3WTT (ORCPT + 99 others); Wed, 30 Mar 2022 18:19:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42094 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233332AbiC3WTR (ORCPT ); Wed, 30 Mar 2022 18:19:17 -0400 Received: from vps-vb.mhejs.net (vps-vb.mhejs.net [37.28.154.113]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CB7DF443D7; Wed, 30 Mar 2022 15:17:29 -0700 (PDT) Received: from MUA by vps-vb.mhejs.net with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1nZgcj-00022J-9D; Thu, 31 Mar 2022 00:17:05 +0200 Message-ID: <8f9ae64a-dc64-6f46-8cd4-ffd2648a9372@maciej.szmigiero.name> Date: Thu, 31 Mar 2022 00:16:59 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.7.0 Content-Language: en-US To: Sean Christopherson Cc: Paolo Bonzini , 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 References: From: "Maciej S. Szmigiero" Subject: Re: [PATCH 3/5] KVM: nSVM: Don't forget about L1-injected events In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,NICE_REPLY_A, 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 On 30.03.2022 23:59, Sean Christopherson wrote: > On Thu, Mar 10, 2022, Maciej S. Szmigiero wrote: >> From: "Maciej S. Szmigiero" >> >> In SVM synthetic software interrupts or INT3 or INTO exception that L1 >> wants to inject into its L2 guest are forgotten if there is an intervening >> L0 VMEXIT during their delivery. >> >> They are re-injected correctly with VMX, however. >> >> This is because there is an assumption in SVM that such exceptions will be >> re-delivered by simply re-executing the current instruction. >> Which might not be true if this is a synthetic exception injected by L1, >> since in this case the re-executed instruction will be one already in L2, >> not the VMRUN instruction in L1 that attempted the injection. >> >> Leave the pending L1 -> L2 event in svm->nested.ctl.event_inj{,err} until >> it is either re-injected successfully or returned to L1 upon a nested >> VMEXIT. >> Make sure to always re-queue such event if returned in EXITINTINFO. >> >> The handling of L0 -> {L1, L2} event re-injection is left as-is to avoid >> unforeseen regressions. >> >> Signed-off-by: Maciej S. Szmigiero >> --- > > ... > >> @@ -3627,6 +3632,14 @@ static void svm_complete_interrupts(struct kvm_vcpu *vcpu) >> if (!(exitintinfo & SVM_EXITINTINFO_VALID)) >> return; >> >> + /* L1 -> L2 event re-injection needs a different handling */ >> + if (is_guest_mode(vcpu) && >> + exit_during_event_injection(svm, svm->nested.ctl.event_inj, >> + svm->nested.ctl.event_inj_err)) { >> + nested_svm_maybe_reinject(vcpu); > > Why is this manually re-injecting? More specifically, why does the below (out of > sight in the diff) code that re-queues the exception/interrupt not work? The > re-queued event should be picked up by nested_save_pending_event_to_vmcb12() and > propagatred to vmcb12. A L1 -> L2 injected event should either be re-injected until successfully injected into L2 or propagated to VMCB12 if there is a nested VMEXIT during its delivery. svm_complete_interrupts() does not do such re-injection in some cases (soft interrupts, soft exceptions, #VC) - it is trying to resort to emulation instead, which is incorrect in this case. I think it's better to split out this L1 -> L2 nested case to a separate function in nested.c rather than to fill svm_complete_interrupts() in already very large svm.c with "if" blocks here and there. Thanks, Maciej