From patchwork Fri Apr 26 11:42:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 10919065 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A43B614B6 for ; Fri, 26 Apr 2019 11:44:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9056128E0B for ; Fri, 26 Apr 2019 11:44:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8326928E11; Fri, 26 Apr 2019 11:44:06 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 1DEC728E0B for ; Fri, 26 Apr 2019 11:44:06 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hJzF8-0007Ts-2H; Fri, 26 Apr 2019 11:42:14 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hJzF7-0007Tn-2h for xen-devel@lists.xenproject.org; Fri, 26 Apr 2019 11:42:13 +0000 X-Inumbo-ID: 53ea1ff2-6818-11e9-843c-bc764e045a96 Received: from prv1-mh.provo.novell.com (unknown [137.65.248.33]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 53ea1ff2-6818-11e9-843c-bc764e045a96; Fri, 26 Apr 2019 11:42:11 +0000 (UTC) Received: from INET-PRV1-MTA by prv1-mh.provo.novell.com with Novell_GroupWise; Fri, 26 Apr 2019 05:42:10 -0600 Message-Id: <5CC2EE8E02000078002296B6@prv1-mh.provo.novell.com> X-Mailer: Novell GroupWise Internet Agent 18.1.0 Date: Fri, 26 Apr 2019 05:42:06 -0600 From: "Jan Beulich" To: "xen-devel" Mime-Version: 1.0 Content-Disposition: inline Subject: [Xen-devel] [PATCH] x86/IRQ: don't keep EOI timer running without need X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Stefano Stabellini , Wei Liu , Konrad Rzeszutek Wilk , George Dunlap , Andrew Cooper , Ian Jackson , Tim Deegan , Julien Grall Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP The timer needs to remain active only until all pending IRQ instances have seen EOIs from their respective domains. Stop it when the in-flight count has reached zero in desc_guest_eoi(). Note that this is race free (with __do_IRQ_guest()), as the IRQ descriptor lock is being held at that point. Also pull up stopping of the timer in __do_IRQ_guest() itself: Instead of stopping it immediately before re-setting, stop it as soon as we've made it past any early returns from the function (and hence we're sure it'll get set again). Finally bail from the actual timer handler in case we find the timer already active again by the time we've managed to acquire the IRQ descriptor lock. Without this we may forcibly EOI an IRQ immediately after it got sent to a guest. For this, timer_is_active() gets split out of active_timer(), deliberately moving just one of the two ASSERT()s (to allow the function to be used also on a never initialized timer). Signed-off-by: Jan Beulich --- a/xen/arch/x86/irq.c +++ b/xen/arch/x86/irq.c @@ -1115,6 +1115,9 @@ static void irq_guest_eoi_timer_fn(void action = (irq_guest_action_t *)desc->action; + if ( timer_is_active(&action->eoi_timer) ) + goto out; + if ( action->ack_type != ACKTYPE_NONE ) { unsigned int i; @@ -1167,6 +1170,9 @@ static void __do_IRQ_guest(int irq) return; } + if ( action->ack_type != ACKTYPE_NONE ) + stop_timer(&action->eoi_timer); + if ( action->ack_type == ACKTYPE_EOI ) { sp = pending_eoi_sp(peoi); @@ -1194,7 +1200,6 @@ static void __do_IRQ_guest(int irq) if ( action->ack_type != ACKTYPE_NONE ) { - stop_timer(&action->eoi_timer); migrate_timer(&action->eoi_timer, smp_processor_id()); set_timer(&action->eoi_timer, NOW() + MILLISECS(1)); } @@ -1457,6 +1462,8 @@ void desc_guest_eoi(struct irq_desc *des return; } + stop_timer(&action->eoi_timer); + if ( action->ack_type == ACKTYPE_UNMASK ) { ASSERT(cpumask_empty(action->cpu_eoi_map)); --- a/xen/common/timer.c +++ b/xen/common/timer.c @@ -282,11 +282,10 @@ static inline void timer_unlock(struct t }) -static bool_t active_timer(struct timer *timer) +static bool active_timer(const struct timer *timer) { ASSERT(timer->status >= TIMER_STATUS_inactive); - ASSERT(timer->status <= TIMER_STATUS_in_list); - return (timer->status >= TIMER_STATUS_in_heap); + return timer_is_active(timer); } --- a/xen/include/xen/timer.h +++ b/xen/include/xen/timer.h @@ -75,6 +75,19 @@ bool timer_expires_before(struct timer * #define timer_is_expired(t) timer_expires_before(t, NOW()) +/* + * True if a timer is active. + * + * Unlike for timer_expires_before(), it is the caller's responsibility to + * use suitable locking such that the returned value isn't stale by the time + * it gets acted upon. + */ +static inline bool timer_is_active(const struct timer *timer) +{ + ASSERT(timer->status <= TIMER_STATUS_in_list); + return timer->status >= TIMER_STATUS_in_heap; +} + /* Migrate a timer to a different CPU. The timer may be currently active. */ void migrate_timer(struct timer *timer, unsigned int new_cpu);