From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.3 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 478EDC43381 for ; Sun, 14 Feb 2021 21:35:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1B3BB64E12 for ; Sun, 14 Feb 2021 21:35:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230077AbhBNVfb (ORCPT ); Sun, 14 Feb 2021 16:35:31 -0500 Received: from mail.xenproject.org ([104.130.215.37]:39614 "EHLO mail.xenproject.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230042AbhBNVfU (ORCPT ); Sun, 14 Feb 2021 16:35:20 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=Content-Transfer-Encoding:Content-Type:In-Reply-To: MIME-Version:Date:Message-ID:From:References:Cc:To:Subject; bh=sr90ghnrrGFMQJUJbkuM9kxkBCV/fRb8wi8FFVB7UVM=; b=zYsYKWf6svYxuu2NL22bZxT/Ki lWJTcTuHslPksK7qPqnxkie4ebX1D1ya7QT4OZX3xO0iYKAn+GNR+CLRzAyCVlTJcgxXjka4p3ijV X28cbCzHUG8LUdXlGxuGd0XUvOAZrdLuVW0hJt7Ro21kji+Nwi8ZZPg1kTL68MNE2ouI=; Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lBP2H-00039D-1g; Sun, 14 Feb 2021 21:34:33 +0000 Received: from [54.239.6.185] (helo=a483e7b01a66.ant.amazon.com) by xenbits.xenproject.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1lBP2G-0008FF-Pr; Sun, 14 Feb 2021 21:34:32 +0000 Subject: Re: [PATCH v2 3/8] xen/events: avoid handling the same event on two cpus at the same time To: Juergen Gross , xen-devel@lists.xenproject.org, linux-kernel@vger.kernel.org Cc: Boris Ostrovsky , Stefano Stabellini References: <20210211101616.13788-1-jgross@suse.com> <20210211101616.13788-4-jgross@suse.com> From: Julien Grall Message-ID: Date: Sun, 14 Feb 2021 21:34:31 +0000 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.7.1 MIME-Version: 1.0 In-Reply-To: <20210211101616.13788-4-jgross@suse.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-GB Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Juergen, On 11/02/2021 10:16, Juergen Gross wrote: > When changing the cpu affinity of an event it can happen today that > (with some unlucky timing) the same event will be handled on the old > and the new cpu at the same time. > > Avoid that by adding an "event active" flag to the per-event data and > call the handler only if this flag isn't set. > > Reported-by: Julien Grall > Signed-off-by: Juergen Gross > --- > V2: > - new patch > --- > drivers/xen/events/events_base.c | 19 +++++++++++++++---- > 1 file changed, 15 insertions(+), 4 deletions(-) > > diff --git a/drivers/xen/events/events_base.c b/drivers/xen/events/events_base.c > index e157e7506830..f7e22330dcef 100644 > --- a/drivers/xen/events/events_base.c > +++ b/drivers/xen/events/events_base.c > @@ -102,6 +102,7 @@ struct irq_info { > #define EVT_MASK_REASON_EXPLICIT 0x01 > #define EVT_MASK_REASON_TEMPORARY 0x02 > #define EVT_MASK_REASON_EOI_PENDING 0x04 > + u8 is_active; /* Is event just being handled? */ > unsigned irq; > evtchn_port_t evtchn; /* event channel */ > unsigned short cpu; /* cpu bound */ > @@ -622,6 +623,7 @@ static void xen_irq_lateeoi_locked(struct irq_info *info, bool spurious) > } > > info->eoi_time = 0; > + smp_store_release(&info->is_active, 0); > do_unmask(info, EVT_MASK_REASON_EOI_PENDING); > } > > @@ -809,13 +811,15 @@ static void pirq_query_unmask(int irq) > > static void eoi_pirq(struct irq_data *data) > { > - evtchn_port_t evtchn = evtchn_from_irq(data->irq); > + struct irq_info *info = info_for_irq(data->irq); > + evtchn_port_t evtchn = info ? info->evtchn : 0; > struct physdev_eoi eoi = { .irq = pirq_from_irq(data->irq) }; > int rc = 0; > > if (!VALID_EVTCHN(evtchn)) > return; > > + smp_store_release(&info->is_active, 0); Would you mind to explain why you are using the release semantics? It is also not clear to me if there are any expected ordering between clearing is_active and clearing the pending bit. > clear_evtchn(evtchn); The 2 lines here seems to be a common pattern in this patch. So I would suggest to create a new helper. > > if (pirq_needs_eoi(data->irq)) { > @@ -1640,6 +1644,8 @@ void handle_irq_for_port(evtchn_port_t port, struct evtchn_loop_ctrl *ctrl) > } > > info = info_for_irq(irq); > + if (xchg_acquire(&info->is_active, 1)) > + return; > > if (ctrl->defer_eoi) { > info->eoi_cpu = smp_processor_id(); > @@ -1823,11 +1829,13 @@ static void disable_dynirq(struct irq_data *data) > > static void ack_dynirq(struct irq_data *data) > { > - evtchn_port_t evtchn = evtchn_from_irq(data->irq); > + struct irq_info *info = info_for_irq(data->irq); > + evtchn_port_t evtchn = info ? info->evtchn : 0; > > if (!VALID_EVTCHN(evtchn)) > return; > > + smp_store_release(&info->is_active, 0); > clear_evtchn(evtchn); > } > > @@ -1969,10 +1977,13 @@ static void restore_cpu_ipis(unsigned int cpu) > /* Clear an irq's pending state, in preparation for polling on it */ > void xen_clear_irq_pending(int irq) > { > - evtchn_port_t evtchn = evtchn_from_irq(irq); > + struct irq_info *info = info_for_irq(irq); > + evtchn_port_t evtchn = info ? info->evtchn : 0; > > - if (VALID_EVTCHN(evtchn)) > + if (VALID_EVTCHN(evtchn)) { > + smp_store_release(&info->is_active, 0); > clear_evtchn(evtchn); > + } > } > EXPORT_SYMBOL(xen_clear_irq_pending); > void xen_set_irq_pending(int irq) > -- Julien Grall