Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp4544288pxb; Sun, 14 Feb 2021 14:46:01 -0800 (PST) X-Google-Smtp-Source: ABdhPJwBQgHIi84pqJcG6KgAYAR9Imh7h3OhBH6U53V5V981fZChYH8dDn71M+BZ78aPXIvcz7lw X-Received: by 2002:a05:6402:4382:: with SMTP id o2mr13258313edc.371.1613342761123; Sun, 14 Feb 2021 14:46:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613342761; cv=none; d=google.com; s=arc-20160816; b=n7eKnhT0DR8MkP6TkEQzbtpSwtSuoP9l8zmeP8c9mCLwBGLZjw2MnDOjW5FtGHuzhk Zw1+qiA6hLsrjXH9PCK+967+j8dOlg2qb0Qz6ydzcJtrH3VpEiDxYRpriC2c0T14au7o vrIHaedCneyZtmdZ1+IKEBYVC3Qf9GtyPNWeu+8Yoj7DDNx2EA9OzVdDg1AziOSI0Kbf HYT86cFmGycsN+1rta8N2I9hQh34em1cLBheJKokq7Spp3sTFMHxJB0YRGptHw5Yp48q sQznpJ7iraYXZ42EuX8xZFAI4EAgCKLkK6j00T8bWzhNQk56SjFCfyR4K38PWY2sR6YU s6OQ== 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=sr90ghnrrGFMQJUJbkuM9kxkBCV/fRb8wi8FFVB7UVM=; b=iORiic1Q1mFYyf3Xl5uyNkJ+9CvmHChwmTAgfJgpazUpfC+iPfv+effhDOZedFP0F8 DmDpuNffQG7myiUCpSGsFHDG6SwWazRlUSYy/RJtrAua4uoEEihQ5UmNc7fQPUgQVwB0 TXvQQyRUOacqdcBSQACvKan6sCPzMLQPZa2qkTzoG1Dg1H6G3+IId1VkH7qWVOnhVDDc m9+WbcXdthIGoolGwB77qtZScAP0O8FGhBv6UcoL7gPiJYANhWtZjnGM4t/F7RJYqfDY g9laLG4iNplWanwM2nb3JSB4qPddYCbRHC7yoEtlO3OXkrNA9X3G5E26dcX0jkHLe8yL MFfQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@xen.org header.s=20200302mail header.b=zYsYKWf6; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z19si13175651edr.191.2021.02.14.14.44.52; Sun, 14 Feb 2021 14:46:01 -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=@xen.org header.s=20200302mail header.b=zYsYKWf6; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230059AbhBNVf0 (ORCPT + 99 others); Sun, 14 Feb 2021 16:35:26 -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