Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp1481185pxb; Wed, 2 Feb 2022 06:03:23 -0800 (PST) X-Google-Smtp-Source: ABdhPJxA9HMabaW0iKdL2qjHcgD8zZzME4WskJPlNFFA0p+DNo+NCdc6zQqOlBvId+1HM5VCVnV6 X-Received: by 2002:a63:904c:: with SMTP id a73mr24636042pge.449.1643810603205; Wed, 02 Feb 2022 06:03:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643810603; cv=none; d=google.com; s=arc-20160816; b=WuS6vzYqkDyLe3tJPtgKLCgT2zx8oWz6wi9MvyN1V5+5h5tlVTAADnkJM5Bkfwt2MW Ub8q+4tyJvzdDYRzXDmemXByvNHPCCJCi/VmZpalWLyIoNvOmflUicizLxR8X+Dvo+WB fRNkFR106K9kvtEdHmMMI0lrFnVgi8uESYKgiInGEWQmlPhpaezn97SIy3pz3LJgfRmX N+yDc+JUAA9lq+/UD+/i2NUgPNBeWIXi7VLZyh4f5hZgR8F9Q8oOfzaAWmTOS0afpWhM lrri6bQbEGD8XGiRTjJvVEUpuaEk5UaF73k7hOdL1pbV7Wrh8eKjLjyxD2BQ9ZBs6Gbr ykBA== 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=2CxPyuHcSSMfylbMraAFLznZLkw0l2GAqkTDlOgQsho=; b=Xbm/G6ZPJ5v3kGyz42X2e/WiWMLxnvHcGZm3a66XLy4mnbbeJkptfCIcrNftv0AKrn 7Gjm81qJNe8tlSeXQJV2pi8RZ6Gx9r67WM3z3rzTkq0ZPLbchycRPNMNMlsNF2Xe+lag L4VIwEctsoUIBpsbCbkhAirxCjwi3LUnvUmZmpWsj88oNq+aF5Ep25zRXJUC3Ut1+byV fR0z/Geh3oYI47gmzNpABVR5bOc3fi4u+NoFg2GO1ui1XA7QRAgwnHuEtu8TEmj3Nv6q momjjd2SsVNOenWqqXdHcx5J+nlXNj/lSgBqGUzsdSSGvnuKBqAmRtzeFQKLPJuuv6MM mGOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="Ky1Nq/91"; 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 c20si4864661pjs.50.2022.02.02.06.03.10; Wed, 02 Feb 2022 06:03:23 -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="Ky1Nq/91"; 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 S237871AbiBAMMG (ORCPT + 99 others); Tue, 1 Feb 2022 07:12:06 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:29620 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237870AbiBAMMD (ORCPT ); Tue, 1 Feb 2022 07:12:03 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1643717523; 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=2CxPyuHcSSMfylbMraAFLznZLkw0l2GAqkTDlOgQsho=; b=Ky1Nq/9180lqha6dIvdc3w9JpCEnBT7YwLYCNti5hopmmMVG3gL5WPpZKOKXgqFFk4gacS YO8kLALXm5W65v2QMRWF+BPQzCAmkEYb0wDhFrg1REUDkEUl22qxpUPG0pQ3xRkYwG+vDb SDBGKAQ2fSvrleF1OYev3+FurTUQbhI= Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-658--IY5cIVYO--Grv970cn_rA-1; Tue, 01 Feb 2022 07:12:02 -0500 X-MC-Unique: -IY5cIVYO--Grv970cn_rA-1 Received: by mail-ed1-f72.google.com with SMTP id h21-20020aa7c955000000b0040390b2bfc5so8565911edt.15 for ; Tue, 01 Feb 2022 04:12:02 -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=2CxPyuHcSSMfylbMraAFLznZLkw0l2GAqkTDlOgQsho=; b=Ak5fxmkdSzCDuxOLGqifYLW23+LGq86LYZ1iBWvqqdxYxV0eNO8J1yAhV5V09Aa3cv 99uQpNOeBz3v0/1wGukvhhkxNFJyMWF9bebfxsjKyrowLs1TIkBNdRwxZRCyY0jbhyac /w8tBatBl++KtfrVARnQUNJrOIe5eqQ1ickgjFoK7tfTljnQSWc6hVsUfmADoRtE61/a 1hXSRfHInDGDB8AdbWOL9zx6lJBpa7mGkzA7NCVjiUBlEAluqktbkUjweAsODVbdcUf+ dQkyRs24oJUFYdwSC9h3c9/sJ728su7C4AgW/QocxcnjC8gi8T8FMJtNMJTuABX946gZ ndHg== X-Gm-Message-State: AOAM531sh+WfwE665S5Y8D054w7GLFBUQms/FGNdSVcZ77YFWgyoxeTY x1ye8laVU/7zcjpHq+bxBIyIuEanQqy8oso23iKEdnEdWKPXxvAXhYm+2Caf3sy+qWFizfa+LNq T+ZgO+sL3OzuVpgm7Rcs7yE73 X-Received: by 2002:a05:6402:2688:: with SMTP id w8mr24569148edd.393.1643717520906; Tue, 01 Feb 2022 04:12:00 -0800 (PST) X-Received: by 2002:a05:6402:2688:: with SMTP id w8mr24569133edd.393.1643717520681; Tue, 01 Feb 2022 04:12:00 -0800 (PST) Received: from ?IPV6:2001:b07:6468:f312:c8dd:75d4:99ab:290a? ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.googlemail.com with ESMTPSA id gr24sm14313941ejb.185.2022.02.01.04.11.59 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 01 Feb 2022 04:12:00 -0800 (PST) Message-ID: Date: Tue, 1 Feb 2022 13:11:59 +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 RESEND v2] KVM: VMX: Dont' send posted IRQ if vCPU == this vCPU and vCPU is IN_GUEST_MODE Content-Language: en-US To: Wanpeng Li , linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel References: <1643111979-36447-1-git-send-email-wanpengli@tencent.com> From: Paolo Bonzini In-Reply-To: <1643111979-36447-1-git-send-email-wanpengli@tencent.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 1/25/22 12:59, Wanpeng Li wrote: > From: Wanpeng Li > > When delivering a virtual interrupt, don't actually send a posted interrupt > if the target vCPU is also the currently running vCPU and is IN_GUEST_MODE, > in which case the interrupt is being sent from a VM-Exit fastpath and the > core run loop in vcpu_enter_guest() will manually move the interrupt from > the PIR to vmcs.GUEST_RVI. IRQs are disabled while IN_GUEST_MODE, thus > there's no possibility of the virtual interrupt being sent from anything > other than KVM, i.e. KVM won't suppress a wake event from an IRQ handler > (see commit fdba608f15e2, "KVM: VMX: Wake vCPU when delivering posted IRQ > even if vCPU == this vCPU"). > > Eliding the posted interrupt restores the performance provided by the > combination of commits 379a3c8ee444 ("KVM: VMX: Optimize posted-interrupt > delivery for timer fastpath") and 26efe2fd92e5 ("KVM: VMX: Handle > preemption timer fastpath"). > > Thanks Sean for better comments. > > Suggested-by: Chao Gao > Reviewed-by: Sean Christopherson > Signed-off-by: Wanpeng Li > --- > arch/x86/kvm/vmx/vmx.c | 40 +++++++++++++++++++++------------------- > 1 file changed, 21 insertions(+), 19 deletions(-) > > diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c > index fe06b02994e6..e06377c9a4cf 100644 > --- a/arch/x86/kvm/vmx/vmx.c > +++ b/arch/x86/kvm/vmx/vmx.c > @@ -3908,31 +3908,33 @@ static inline void kvm_vcpu_trigger_posted_interrupt(struct kvm_vcpu *vcpu, > #ifdef CONFIG_SMP > if (vcpu->mode == IN_GUEST_MODE) { > /* > - * The vector of interrupt to be delivered to vcpu had > - * been set in PIR before this function. > + * The vector of the virtual has already been set in the PIR. > + * Send a notification event to deliver the virtual interrupt > + * unless the vCPU is the currently running vCPU, i.e. the > + * event is being sent from a fastpath VM-Exit handler, in > + * which case the PIR will be synced to the vIRR before > + * re-entering the guest. > * > - * Following cases will be reached in this block, and > - * we always send a notification event in all cases as > - * explained below. > + * When the target is not the running vCPU, the following > + * possibilities emerge: > * > - * Case 1: vcpu keeps in non-root mode. Sending a > - * notification event posts the interrupt to vcpu. > + * Case 1: vCPU stays in non-root mode. Sending a notification > + * event posts the interrupt to the vCPU. > * > - * Case 2: vcpu exits to root mode and is still > - * runnable. PIR will be synced to vIRR before the > - * next vcpu entry. Sending a notification event in > - * this case has no effect, as vcpu is not in root > - * mode. > + * Case 2: vCPU exits to root mode and is still runnable. The > + * PIR will be synced to the vIRR before re-entering the guest. > + * Sending a notification event is ok as the host IRQ handler > + * will ignore the spurious event. > * > - * Case 3: vcpu exits to root mode and is blocked. > - * vcpu_block() has already synced PIR to vIRR and > - * never blocks vcpu if vIRR is not cleared. Therefore, > - * a blocked vcpu here does not wait for any requested > - * interrupts in PIR, and sending a notification event > - * which has no effect is safe here. > + * Case 3: vCPU exits to root mode and is blocked. vcpu_block() > + * has already synced PIR to vIRR and never blocks the vCPU if > + * the vIRR is not empty. Therefore, a blocked vCPU here does > + * not wait for any requested interrupts in PIR, and sending a > + * notification event also results in a benign, spurious event. > */ > > - apic->send_IPI_mask(get_cpu_mask(vcpu->cpu), pi_vec); > + if (vcpu != kvm_get_running_vcpu()) > + apic->send_IPI_mask(get_cpu_mask(vcpu->cpu), pi_vec); > return; > } > #endif Queued, thanks. Paolo