Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2015725pxb; Fri, 5 Mar 2021 05:33:15 -0800 (PST) X-Google-Smtp-Source: ABdhPJxJwuC8wb3U0YGgxOiduCdYbCPttxn8hyC0UaR1AmGmIl6mlG3xK71ikRXBRqM/K96jmKv8 X-Received: by 2002:a17:906:5453:: with SMTP id d19mr2200392ejp.150.1614951194885; Fri, 05 Mar 2021 05:33:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614951194; cv=none; d=google.com; s=arc-20160816; b=f582ezloOsnrAmOmC/MfJ2Q6hYEloCQSjayYgw4sPljZTAzJoibE5MwYcfa+yp+Lfi XVKtFYKuSxJds/I3FJYqcXl5uUUVkL7Pv980SpPmdWBjMETV5yUSWQeC5U1fjHcK3XhP seMA1Cu/ZisGKIIQ7xfdy61njEnFdD3neN2cbniLkZAGeLTJbFluOWTqKJ/HHPDQVzFk K6dkYSB5DgX/bYeK9YTKPb0KBwC2i4q5KRJlF2VyGmr2gl/Yz4pkVbezzLD6dwfskEhX lcqVnxTvah7wd6hp75MPi9KZh4bG0sWMkM4V0FwUcgZU1MWZerwTJo22R/qRV/fW7HsD 68Qg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=9OVHV4aIQmKNqeY5ezSY/nhnAn51P/hCc3Ft8x+FhLo=; b=op+Qy2qJtTQ2dyv/FzVsqZoemr3EgWT4pE0B2StNtzecfPBkBg22i5Ft6QfENHgYgs +o4sCHc+29RsJscMpn/V0k1IbG5MqcD/Jlig9XCyId+voiiA9S9qGuZM1cyd+x08bNOb ltNSkGqOAEFJ/mbikmtC/aSNIrsts+DQSk2nzlOVlUYp3/zRWYQcwu1p+S99UG5qi/0I nV+nIA6FYjKj5fiYQ9sfW0A6/zPkpQaQFeel3HEAE2DZKIbPe1ZPO3N9OpfCwJZRt51v nKT4ZZy6aIvk7tGBUyS9RfCdab5A1Dz/swUJYbAbMc/qt/ilMAlbKC2RkSf1Y5t+rnwC yndA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=UrU4L3+j; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z1si1545004edp.254.2021.03.05.05.32.50; Fri, 05 Mar 2021 05:33:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=UrU4L3+j; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S230327AbhCENax (ORCPT + 99 others); Fri, 5 Mar 2021 08:30:53 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:30071 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230373AbhCENag (ORCPT ); Fri, 5 Mar 2021 08:30:36 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1614951036; 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=9OVHV4aIQmKNqeY5ezSY/nhnAn51P/hCc3Ft8x+FhLo=; b=UrU4L3+jqyfBm4qaZaXMMQqBCT4NiDm03UVWL7dXUll6Ngq/luBdQEeyeP5O4R3ULdn5kS ZJIr5+vwNX1pKCmyAr2FjMxjcbiqN+zptsHLaWEId1MoDY6obu+NC4Qmb1ZPYOUVBiarr2 +idtafNCTu7rCKD/oWFr8oGlw3T63dM= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-214-CIBran0bORSXkgIEpjnOUA-1; Fri, 05 Mar 2021 08:30:35 -0500 X-MC-Unique: CIBran0bORSXkgIEpjnOUA-1 Received: by mail-wm1-f69.google.com with SMTP id y9so403456wma.4 for ; Fri, 05 Mar 2021 05:30:34 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=9OVHV4aIQmKNqeY5ezSY/nhnAn51P/hCc3Ft8x+FhLo=; b=F/mVivVLGHO4IKsRZ0ObLAIhgk7Ts5iNlWcBjAdd8uM5svEUqnIW4tHAgEIX3fid5Q ks8FYikMYzJ4MqnTQ2Uc9V4+baxbQdX0L3Alos+OIMwEdMlEl8grT3iaC5fPNlzV89zh n4UFjeSzDm/t6jZPf/nDxSEnN3VbaIyllVU1WaKEXfVCal7fY3snsBK24CoiM27e99yr vATimeLW5dFVXVg4hInGDBqCHPhrWwB8kQdwkDkl0pk2u6JSsV2tLinKgsvA3QgFsSo2 K6zsc7+qB65MHQS0Uk+emRmU0GhteJJSK3PZDNiIAVWS6SSyWzvzmmv4doY2fA5X4NzM +Uvg== X-Gm-Message-State: AOAM530zOiDAmySptQShfpSGCQnYIfXAqESmDD1tkAIzClIht9Rxn7Sq XoINMZhNFfj80RPinenGZqqi1zVcrqpTfINWhqzdjzbySTGFWCl25JISpguNTvbFfJVq0MabDMQ V3QUi1fQvj0cPcRTD4sVyiEf32lvKdpGqJV/iNbScoCHmxdqrA6G0YlA9bEsi+aaPS24I5aR+mY QI X-Received: by 2002:adf:e60a:: with SMTP id p10mr9547403wrm.291.1614951033468; Fri, 05 Mar 2021 05:30:33 -0800 (PST) X-Received: by 2002:adf:e60a:: with SMTP id p10mr9547380wrm.291.1614951033305; Fri, 05 Mar 2021 05:30:33 -0800 (PST) Received: from ?IPv6:2001:b07:6468:f312:c8dd:75d4:99ab:290a? ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id j125sm4445967wmb.44.2021.03.05.05.30.32 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 05 Mar 2021 05:30:32 -0800 (PST) Subject: Re: [PATCH] KVM: x86: Ensure deadline timer has truly expired before posting its IRQ To: Sean Christopherson Cc: Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, linux-kernel@vger.kernel.org References: <20210305021808.3769732-1-seanjc@google.com> From: Paolo Bonzini Message-ID: <27bc885c-e257-3353-6146-15fdd40f5d4c@redhat.com> Date: Fri, 5 Mar 2021 14:30:30 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.0 MIME-Version: 1.0 In-Reply-To: <20210305021808.3769732-1-seanjc@google.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 05/03/21 03:18, Sean Christopherson wrote: > When posting a deadline timer interrupt, open code the checks guarding > __kvm_wait_lapic_expire() in order to skip the lapic_timer_int_injected() > check in kvm_wait_lapic_expire(). The injection check will always fail > since the interrupt has not yet be injected. Moving the call after > injection would also be wrong as that wouldn't actually delay delivery > of the IRQ if it is indeed sent via posted interrupt. > > Fixes: 010fd37fddf6 ("KVM: LAPIC: Reduce world switch latency caused by timer_advance_ns") > Cc: stable@vger.kernel.org > Signed-off-by: Sean Christopherson > --- > arch/x86/kvm/lapic.c | 11 ++++++++++- > 1 file changed, 10 insertions(+), 1 deletion(-) > > diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c > index 45d40bfacb7c..cb8ebfaccfb6 100644 > --- a/arch/x86/kvm/lapic.c > +++ b/arch/x86/kvm/lapic.c > @@ -1642,7 +1642,16 @@ static void apic_timer_expired(struct kvm_lapic *apic, bool from_timer_fn) > } > > if (kvm_use_posted_timer_interrupt(apic->vcpu)) { > - kvm_wait_lapic_expire(vcpu); > + /* > + * Ensure the guest's timer has truly expired before posting an > + * interrupt. Open code the relevant checks to avoid querying > + * lapic_timer_int_injected(), which will be false since the > + * interrupt isn't yet injected. Waiting until after injecting > + * is not an option since that won't help a posted interrupt. > + */ > + if (vcpu->arch.apic->lapic_timer.expired_tscdeadline && > + vcpu->arch.apic->lapic_timer.timer_advance_ns) > + __kvm_wait_lapic_expire(vcpu); > kvm_apic_inject_pending_timer_irqs(apic); > return; > } > Queued, thanks. Paolo