Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp195782pxm; Tue, 1 Mar 2022 18:24:19 -0800 (PST) X-Google-Smtp-Source: ABdhPJz1NsouGsL9v5Jw5r3pcVj5occdK4kjzcSvLfgSEJpCPEITKi9kFSctrHc0CWygZ6GPGDcF X-Received: by 2002:a17:906:c214:b0:6b3:d0d6:9fe6 with SMTP id d20-20020a170906c21400b006b3d0d69fe6mr20654363ejz.150.1646187859655; Tue, 01 Mar 2022 18:24:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646187859; cv=none; d=google.com; s=arc-20160816; b=saBQzjl1KHcnHeahWij3GC7xaWt0YQdodGh/mpRgBp3povKeSj2lgiGnISPmhlWFZL nMQvhPLhqgtY+2vU4xbtwKq+PsOnrkK8Ytxt1hwQIaJRyx8RUwLAX1Xb1nY11qGfytJy MoiLXAYCqW+aNNc/xZzKs1VVChINajZ9ksOfj2CtrsdlRGiO9wpOoYC0hXPE6CNVaa+G 1DEfOA0cdF/a77sOax8eYpiQkRkyVmeK64O9KuhHIlobYWtVoroEK4zFxkgsa0wzOlZ2 JossTWO5OWkh0l9OYuPjAiotpuWvDf4XTnQD3RuwTLoWWLNITJwA8YOB87zxfis0mY1u cVYw== 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:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=PIJRnLFY1UWXUOWR2QU+D8DLrJdFCZESqRQM5Q/WC7w=; b=05vbPHU6srSTm+XXTepDrrLBHWB8lsGHAYFaUvRjGikjse5uvwwy+fnmIxW9TQfrGX /6X2/05KC7tHpitG0oAbXnMaNokKhzsLUiV2dk2aWmMewDEi7c/V3wHJLcYRvLeE+WIe Zos50wUV6bKcQ6fW0kE4r4sdT1E8mTZygXJPgKt6hf5P5jM+5XJC9XQO3pZSwQGSXvlG gHGYIuL4nqUdf8rJXhMctfAAnXhQMGaytZxkCXlmukHy9CZHdJ2v65TB52lxsL/8fZXp o98L6tdZnmvMVQP2NZaq9OHD77JvUxJ4JC9U6H8mwBtQAr5fkommmIIbh5y3kH4xMaiX TU9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Vg0TLwt8; 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=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ak17-20020a170906889100b006d6368b1bd2si9565754ejc.688.2022.03.01.18.23.49; Tue, 01 Mar 2022 18:24:19 -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; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Vg0TLwt8; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235953AbiCARLb (ORCPT + 99 others); Tue, 1 Mar 2022 12:11:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55456 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233780AbiCARL3 (ORCPT ); Tue, 1 Mar 2022 12:11:29 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 792C552B33 for ; Tue, 1 Mar 2022 09:10:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1646154643; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=PIJRnLFY1UWXUOWR2QU+D8DLrJdFCZESqRQM5Q/WC7w=; b=Vg0TLwt8PNqnexac+GrYpmCbvWC7VHXN73Q8DlwF4/ZfHt9/98xqMceP+46DZnj0Ue3fiP pqCeuTgi/P259OpZa/jBqo6pB6xyBzAn958Rapwf+SKIdKd0ayiBE1tkBMLySOTIolOjwq S++y7GUFOJl/+w4J4WtUQZ5VKdm3y0s= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-613-6_Lub75sNk-_r_PsNZ5X4A-1; Tue, 01 Mar 2022 12:10:40 -0500 X-MC-Unique: 6_Lub75sNk-_r_PsNZ5X4A-1 Received: by mail-wm1-f71.google.com with SMTP id l19-20020a05600c4f1300b003818783847eso385622wmq.2 for ; Tue, 01 Mar 2022 09:10:40 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=PIJRnLFY1UWXUOWR2QU+D8DLrJdFCZESqRQM5Q/WC7w=; b=MDv1p8cXHcHkWFFqlGR8Fy0lViBdCYk2Dq774+M+4azsS4Fn9bj/YUyUfL4IDoTN1A S7IIM3A1S9snRjujz0wNFh9UF/xArwxWmZoEgODSU0xln/YxjtXs+sSPJ16Ap4vKg1Ln nPXth5c6X3j+9xW8cajBffJfyxVClI9/FEc+Bz/2C22jBXdO0qIFFS3xdFvlF1CQ+bEt CfubQWkx684U05W8SD9C3cx/avMdc0vGolKCwK3W9Bcy6Sw+0e81/aTCCwWsqxQB2lzI HRqnqY0OdGnr2A3uXUAT8V+NY/ap3c7Oae7NiMsu9GMphSK4ukOoAR+s7CMvh8DmL+3b BipQ== X-Gm-Message-State: AOAM533Rmjb5wdMae55aT+wvBUjzBGpvHNTufmTHzEKB7Y9L1bffBrMA kPM7X7hCVmx9B3eiKF+xcVdc6oqdvie8lZnD3wg+8/OrDzm8FAI+CVl2PTZ1IpQHnw9TGONpHol PkcuOuAx6/hfYFOXAZPpSvW7J X-Received: by 2002:adf:d089:0:b0:1ed:9e86:2144 with SMTP id y9-20020adfd089000000b001ed9e862144mr19799480wrh.363.1646154639290; Tue, 01 Mar 2022 09:10:39 -0800 (PST) X-Received: by 2002:adf:d089:0:b0:1ed:9e86:2144 with SMTP id y9-20020adfd089000000b001ed9e862144mr19799450wrh.363.1646154638858; Tue, 01 Mar 2022 09:10:38 -0800 (PST) Received: from ?IPV6:2001:b07:6468:f312:5e2c:eb9a:a8b6:fd3e? ([2001:b07:6468:f312:5e2c:eb9a:a8b6:fd3e]) by smtp.googlemail.com with ESMTPSA id n4-20020a05600c4f8400b00380e45cd564sm3715244wmq.8.2022.03.01.09.10.34 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 01 Mar 2022 09:10:38 -0800 (PST) Message-ID: Date: Tue, 1 Mar 2022 18:10:33 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.5.0 Subject: Re: [PATCH MANUALSEL 5.10 2/2] KVM: x86: nSVM: deal with L1 hypervisor that intercepts interrupts but lets L2 control them Content-Language: en-US To: Sasha Levin , linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Maxim Levitsky , tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, kvm@vger.kernel.org References: <20220222140532.211620-1-sashal@kernel.org> <20220222140532.211620-2-sashal@kernel.org> From: Paolo Bonzini In-Reply-To: <20220222140532.211620-2-sashal@kernel.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 2/22/22 15:05, Sasha Levin wrote: > From: Maxim Levitsky > > [ Upstream commit 2b0ecccb55310a4b8ad5d59c703cf8c821be6260 ] > > Fix a corner case in which the L1 hypervisor intercepts > interrupts (INTERCEPT_INTR) and either doesn't set > virtual interrupt masking (V_INTR_MASKING) or enters a > nested guest with EFLAGS.IF disabled prior to the entry. > > In this case, despite the fact that L1 intercepts the interrupts, > KVM still needs to set up an interrupt window to wait before > injecting the INTR vmexit. > > Currently the KVM instead enters an endless loop of 'req_immediate_exit'. > > Exactly the same issue also happens for SMIs and NMI. > Fix this as well. > > Note that on VMX, this case is impossible as there is only > 'vmexit on external interrupts' execution control which either set, > in which case both host and guest's EFLAGS.IF > are ignored, or not set, in which case no VMexits are delivered. > > Signed-off-by: Maxim Levitsky > Message-Id: <20220207155447.840194-8-mlevitsk@redhat.com> > Signed-off-by: Paolo Bonzini > Signed-off-by: Sasha Levin > --- > arch/x86/kvm/svm/svm.c | 17 +++++++++++++---- > 1 file changed, 13 insertions(+), 4 deletions(-) > > diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c > index d515c8e68314c..ec9586a30a50c 100644 > --- a/arch/x86/kvm/svm/svm.c > +++ b/arch/x86/kvm/svm/svm.c > @@ -3237,11 +3237,13 @@ static int svm_nmi_allowed(struct kvm_vcpu *vcpu, bool for_injection) > if (svm->nested.nested_run_pending) > return -EBUSY; > > + if (svm_nmi_blocked(vcpu)) > + return 0; > + > /* An NMI must not be injected into L2 if it's supposed to VM-Exit. */ > if (for_injection && is_guest_mode(vcpu) && nested_exit_on_nmi(svm)) > return -EBUSY; > - > - return !svm_nmi_blocked(vcpu); > + return 1; > } > > static bool svm_get_nmi_mask(struct kvm_vcpu *vcpu) > @@ -3293,9 +3295,13 @@ bool svm_interrupt_blocked(struct kvm_vcpu *vcpu) > static int svm_interrupt_allowed(struct kvm_vcpu *vcpu, bool for_injection) > { > struct vcpu_svm *svm = to_svm(vcpu); > + > if (svm->nested.nested_run_pending) > return -EBUSY; > > + if (svm_interrupt_blocked(vcpu)) > + return 0; > + > /* > * An IRQ must not be injected into L2 if it's supposed to VM-Exit, > * e.g. if the IRQ arrived asynchronously after checking nested events. > @@ -3303,7 +3309,7 @@ static int svm_interrupt_allowed(struct kvm_vcpu *vcpu, bool for_injection) > if (for_injection && is_guest_mode(vcpu) && nested_exit_on_intr(svm)) > return -EBUSY; > > - return !svm_interrupt_blocked(vcpu); > + return 1; > } > > static void enable_irq_window(struct kvm_vcpu *vcpu) > @@ -4023,11 +4029,14 @@ static int svm_smi_allowed(struct kvm_vcpu *vcpu, bool for_injection) > if (svm->nested.nested_run_pending) > return -EBUSY; > > + if (svm_smi_blocked(vcpu)) > + return 0; > + > /* An SMI must not be injected into L2 if it's supposed to VM-Exit. */ > if (for_injection && is_guest_mode(vcpu) && nested_exit_on_smi(svm)) > return -EBUSY; > > - return !svm_smi_blocked(vcpu); > + return 1; > } > > static int svm_pre_enter_smm(struct kvm_vcpu *vcpu, char *smstate) Acked-by: Paolo Bonzini Paolo