Received: by 10.223.176.5 with SMTP id f5csp1928159wra; Thu, 8 Feb 2018 05:54:51 -0800 (PST) X-Google-Smtp-Source: AH8x224jDPiMLh/DD+L/Cx+G+BVnf1crjTptiIMovT8y/9yau13r6U/lffoeKLAh4vK9FGCBWL2F X-Received: by 10.98.33.199 with SMTP id o68mr802351pfj.78.1518098091067; Thu, 08 Feb 2018 05:54:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518098091; cv=none; d=google.com; s=arc-20160816; b=uSMh5dbNG0u1B6nLZyVamCDxZPaHsV2OAit6eW/sF53nu5AAzzzlTpUG8TcJwjOw4t iLNdYdbcJU5w9OW85wLViKHyz+9MDAxSavvJOuYHM/2GoqjqCRRqrehpBtGePbd2OBTg p/I8ZtsUExFsCzrVe5GiUoxWTKX+xgAHz8/m5KHkwvSiU3Zjpaf6mFVIB09wyh4INBaf j3wxv52Brb0lRX37lIyc27V6K1HU/2axDerinkWXwn/C7i7I2Hm5hz8pTX8GiGGYr3HC sO8g9x4Qm2NxzFnXPFYdCniSeAZI/rxBg25KwypVQAZVuU7oiVjdQXyfyUGegJZ67T9f 8vVA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:arc-authentication-results; bh=gWWQJ5e6AfJqDLSptgeZudIJ7coawXD/UY7q1xCkXfo=; b=OALZ+JWAPu0tjeuzUbffp8cgnlrqQlO2lN5YFmi6mptU9Ggta3rZW5scmVtiJlzpdI dJp3pCH0VEjfkO+My6T13L0wkHjxYlE/TwQ8aSIRkpXdrcktzMYHMAVcBxG2oHZM+n6F PqhdMbc6wHxhf9oMSkujHDPnCV30xMJX9dHZuLwKft5FDTwpDRqklzdUgBxgFSYpQjnK 3Wj5cjYasPpyLM2BVOBwMGERJjLMF4QhGZQXTjpbDQQJxSxBOZq4jQyW/jEFFBu8Ge7v OOMGHYjkxE4nZDDaTBw2DkUbv1YsYIDHgHkIETPDKkVeK91bT/KES5HVN2EB7HduLsXi tsag== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 33-v6si13106pll.161.2018.02.08.05.54.36; Thu, 08 Feb 2018 05:54:51 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751968AbeBHNx6 (ORCPT + 99 others); Thu, 8 Feb 2018 08:53:58 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:33336 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751094AbeBHNx5 (ORCPT ); Thu, 8 Feb 2018 08:53:57 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8DD1A4040073; Thu, 8 Feb 2018 13:53:56 +0000 (UTC) Received: from [10.36.116.177] (ovpn-116-177.ams2.redhat.com [10.36.116.177]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D8483B07B0; Thu, 8 Feb 2018 13:53:54 +0000 (UTC) Subject: Re: [PATCH] x86/kvm/vmx: Don't halt vcpu when L1 is injecting events to L2 To: Liran Alon Cc: chao.gao@intel.com, mingo@redhat.com, x86@kernel.org, tglx@linutronix.de, rkrcmar@redhat.com, linux-kernel@vger.kernel.org, hpa@zytor.com, kvm@vger.kernel.org References: <94d2625d-5055-4834-ba3c-b1a25117b762@default> From: Paolo Bonzini Message-ID: <0c2d277d-7e2c-838e-a207-1e107e832762@redhat.com> Date: Thu, 8 Feb 2018 14:53:53 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.2 MIME-Version: 1.0 In-Reply-To: <94d2625d-5055-4834-ba3c-b1a25117b762@default> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Thu, 08 Feb 2018 13:53:56 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Thu, 08 Feb 2018 13:53:56 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'pbonzini@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 08/02/2018 13:09, Liran Alon wrote: > ----- pbonzini@redhat.com wrote: >> On 08/02/2018 06:13, Chao Gao wrote: >>> Because virtual interrupt delivery may wake L2 vcpu, if VID is >>> enabled, do the same thing -- don't halt L2. >> >> This second part seems wrong to me, or at least overly general. >> Perhaps you mean if RVI>0? > > I would first recommend to split this commit. > The first commit should handle only the case of vectoring VM entry. > It should also specify in commit message it is based on Intel SDM 26.6.2 Activity State: > ("If the VM entry is vectoring, the logical processor is in the active state after VM entry.") > That part in code seems correct to me. I agree. > The second commit seems wrong to me as-well. > (I would also mention here it is based on Intel SDM 26.6.5 > Interrupt-Window Exiting and Virtual-Interrupt Delivery: > "These events wake the logical processor if it just entered the HLT state because of a VM entry") > > Paolo, I think that your suggestion is not sufficient as well. > Consider the case that APIC's TPR blocks interrupt specified in RVI. That's true. It should be RVI>PPR. > Otherwise, kvm_vcpu_halt() will change mp_state to KVM_MP_STATE_HALTED. > Eventually, vcpu_run() will call vcpu_block() which will reach kvm_vcpu_has_events(). > That function is responsible for checking if there is any pending interrupts. > Including, pending interrupts as a result of VID enabled and RVI>0 > (While also taking into account the APIC's TPR). > The logic that checks for pending interrupts is kvm_cpu_has_interrupt() > which eventually reach apic_has_interrupt_for_ppr(). > If APICv is enabled, apic_has_interrupt_for_ppr() will call vmx_sync_pir_to_irr() > which calls vmx_hwapic_irr_update(). > > However, max_irr returned to apic_has_interrupt_for_ppr() does not consider the interrupt > pending in RVI. Which I think is the real bug to fix here. > In the non-nested case, RVI can never be larger than max_irr because that is how L0 KVM manages RVI. > However, in the nested case, L1 can set RVI in VMCS arbitrary > (we just copy GUEST_INTR_STATUS from vmcs01 into vmcs02). > > A possible patch to fix this is to change vmx_hwapic_irr_update() such that > if is_guest_mode(vcpu)==true, we should return max(max_irr, rvi) and return > that value into apic_has_interrupt_for_ppr(). > Need to verify that it doesn't break other flows but I think it makes sense. > What do you think? Yeah, I think it makes sense though I'd need to look a lot more at arch/x86/kvm/lapic.c and arch/x86/kvm/vmx.c to turn that into a patch! Paolo