From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BEEDCC433FE for ; Wed, 30 Mar 2022 21:59:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237854AbiC3WBS (ORCPT ); Wed, 30 Mar 2022 18:01:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47430 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240323AbiC3WBN (ORCPT ); Wed, 30 Mar 2022 18:01:13 -0400 Received: from mail-pf1-x436.google.com (mail-pf1-x436.google.com [IPv6:2607:f8b0:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DAFD615A18 for ; Wed, 30 Mar 2022 14:59:27 -0700 (PDT) Received: by mail-pf1-x436.google.com with SMTP id z16so20097316pfh.3 for ; Wed, 30 Mar 2022 14:59:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=pDli6+hXKC5s9n1yl7hKexNUnpgD/mpYIhN4/2AX5LU=; b=Gc2pDpTunHkktjornaePqzCCgmOxkEvSJzLj7EEubIMjrBvHn3RSRu4y5Qv67AVdzo SVCXaeFUgPAbKgal6d4L1Y3MbeJaMiNFdU70/mxN20GMw9oSk0/dUBlJ76VAek5Gk7Wx btapBOJgOgS2Q1HXBEh4DnZ5tRUYpE48oOt+Dl8lovxojKPyLdl9uoRmJ5T8SKLTZkGm VMIHP3vrO2SlafqSHsNLiwF/T99xTdqwmkqIPEJOF69wCmLOWBRTYF/DSVmIAeKemcpW IOBjnNjeKnEKjZ2P23B64COvNr9CfHiFafff2FrknHawfHzmtd18JR6bsyVeuovIuhS4 QyBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=pDli6+hXKC5s9n1yl7hKexNUnpgD/mpYIhN4/2AX5LU=; b=0A6VsX+bGB5Pmixb/2P0HL88DoG6LOohIwfkJfqfiRMTcEHhPIGr1XUOC+hDbvPYiv pJcW50+kBOwSO8omGkx7EKPWqkMQiu+fvgMrlV6NvgkCmlLwnu9HJTQCBdaaF2n39u+W ygqtQMN5Con8B3jiGSJLe+liiwlCbDweeLxV+2TCLs71f36eYE0G5VTigpBQwEesKgwk b6jY9P3SJyHnH5UuoC5X/1ZKuD5ErEHVq+zcucblza4BLoPANbsHaATg3MijsE8hqUVS /f9cbbTYExpwVTbsjRVCYtjE5xMA156ROEEvww4n+u6oeYkNxV4fLpC299ib5oTfetSZ KeYg== X-Gm-Message-State: AOAM530/QFL3O9lmh7C/u4Ua716wa4N/lQRVkZcoRl9AQy6TVp4OqW80 bt/VKfjOyeKRg0GayVTiqKJVcA== X-Google-Smtp-Source: ABdhPJxxd83aMw81ffo9S+PVRWOuyN4iX3CWmeMqXWj9BHgs6Jz1dI869Hf+NQhCZfAXBOqoUTvZIA== X-Received: by 2002:a62:7b97:0:b0:4fa:7a9a:6523 with SMTP id w145-20020a627b97000000b004fa7a9a6523mr1667883pfc.80.1648677567059; Wed, 30 Mar 2022 14:59:27 -0700 (PDT) Received: from google.com (157.214.185.35.bc.googleusercontent.com. [35.185.214.157]) by smtp.gmail.com with ESMTPSA id cn9-20020a056a00340900b004fad845e9besm22785110pfb.57.2022.03.30.14.59.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Mar 2022 14:59:26 -0700 (PDT) Date: Wed, 30 Mar 2022 21:59:22 +0000 From: Sean Christopherson To: "Maciej S. Szmigiero" 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 Subject: Re: [PATCH 3/5] KVM: nSVM: Don't forget about L1-injected events Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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.