From nobody Sun May 5 02:16:31 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1613749264337205.65113398863605; Fri, 19 Feb 2021 07:41:04 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.86930.163539 (Exim 4.92) (envelope-from ) id 1lD7tZ-0002FO-SN; Fri, 19 Feb 2021 15:40:41 +0000 Received: by outflank-mailman (output) from mailman id 86930.163539; Fri, 19 Feb 2021 15:40:41 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lD7tZ-0002FH-PS; Fri, 19 Feb 2021 15:40:41 +0000 Received: by outflank-mailman (input) for mailman id 86930; Fri, 19 Feb 2021 15:40:40 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lD7tY-0002F7-7O for xen-devel@lists.xenproject.org; Fri, 19 Feb 2021 15:40:40 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 4c6d1683-92bd-4b9a-9465-7bbe691d60bf; Fri, 19 Feb 2021 15:40:39 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 16522ACBF; Fri, 19 Feb 2021 15:40:38 +0000 (UTC) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 4c6d1683-92bd-4b9a-9465-7bbe691d60bf X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1613749238; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=FO0fz98U2g5weSeglUcsg+1IlA+co2jioZAxAjIzYHw=; b=QHsiSyjEB+XxqHutx5nmU495s5WuRT0+qc5uj4y7BVCW2JiShJb0alShJHO9TdfRz2ErIk oECbNApBN2vIETzf/74XNNkgdqqKi1NF/cJVQDze0mmLQXz/o0ELCqD4f7DDFbTncYvnLU PMx2UHjoxGknPHWP9OyA2OLZyRYUoR0= From: Juergen Gross To: xen-devel@lists.xenproject.org, linux-kernel@vger.kernel.org Cc: Juergen Gross , Boris Ostrovsky , Stefano Stabellini , stable@vger.kernel.org, Julien Grall , Julien Grall Subject: [PATCH v3 1/8] xen/events: reset affinity of 2-level event when tearing it down Date: Fri, 19 Feb 2021 16:40:23 +0100 Message-Id: <20210219154030.10892-2-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210219154030.10892-1-jgross@suse.com> References: <20210219154030.10892-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) Content-Type: text/plain; charset="utf-8" When creating a new event channel with 2-level events the affinity needs to be reset initially in order to avoid using an old affinity from earlier usage of the event channel port. So when tearing an event channel down reset all affinity bits. The same applies to the affinity when onlining a vcpu: all old affinity settings for this vcpu must be reset. As percpu events get initialized before the percpu event channel hook is called, resetting of the affinities happens after offlining a vcpu (this is working, as initial percpu memory is zeroed out). Cc: stable@vger.kernel.org Reported-by: Julien Grall Signed-off-by: Juergen Gross Reviewed-by: Julien Grall --- V2: - reset affinity when tearing down the event (Julien Grall) --- drivers/xen/events/events_2l.c | 15 +++++++++++++++ drivers/xen/events/events_base.c | 1 + drivers/xen/events/events_internal.h | 8 ++++++++ 3 files changed, 24 insertions(+) diff --git a/drivers/xen/events/events_2l.c b/drivers/xen/events/events_2l.c index da87f3a1e351..a7f413c5c190 100644 --- a/drivers/xen/events/events_2l.c +++ b/drivers/xen/events/events_2l.c @@ -47,6 +47,11 @@ static unsigned evtchn_2l_max_channels(void) return EVTCHN_2L_NR_CHANNELS; } =20 +static void evtchn_2l_remove(evtchn_port_t evtchn, unsigned int cpu) +{ + clear_bit(evtchn, BM(per_cpu(cpu_evtchn_mask, cpu))); +} + static void evtchn_2l_bind_to_cpu(evtchn_port_t evtchn, unsigned int cpu, unsigned int old_cpu) { @@ -355,9 +360,18 @@ static void evtchn_2l_resume(void) EVTCHN_2L_NR_CHANNELS/BITS_PER_EVTCHN_WORD); } =20 +static int evtchn_2l_percpu_deinit(unsigned int cpu) +{ + memset(per_cpu(cpu_evtchn_mask, cpu), 0, sizeof(xen_ulong_t) * + EVTCHN_2L_NR_CHANNELS/BITS_PER_EVTCHN_WORD); + + return 0; +} + static const struct evtchn_ops evtchn_ops_2l =3D { .max_channels =3D evtchn_2l_max_channels, .nr_channels =3D evtchn_2l_max_channels, + .remove =3D evtchn_2l_remove, .bind_to_cpu =3D evtchn_2l_bind_to_cpu, .clear_pending =3D evtchn_2l_clear_pending, .set_pending =3D evtchn_2l_set_pending, @@ -367,6 +381,7 @@ static const struct evtchn_ops evtchn_ops_2l =3D { .unmask =3D evtchn_2l_unmask, .handle_events =3D evtchn_2l_handle_events, .resume =3D evtchn_2l_resume, + .percpu_deinit =3D evtchn_2l_percpu_deinit, }; =20 void __init xen_evtchn_2l_init(void) diff --git a/drivers/xen/events/events_base.c b/drivers/xen/events/events_b= ase.c index e850f79351cb..6c539db81f8f 100644 --- a/drivers/xen/events/events_base.c +++ b/drivers/xen/events/events_base.c @@ -368,6 +368,7 @@ static int xen_irq_info_pirq_setup(unsigned irq, static void xen_irq_info_cleanup(struct irq_info *info) { set_evtchn_to_irq(info->evtchn, -1); + xen_evtchn_port_remove(info->evtchn, info->cpu); info->evtchn =3D 0; channels_on_cpu_dec(info); } diff --git a/drivers/xen/events/events_internal.h b/drivers/xen/events/even= ts_internal.h index 0a97c0549db7..18a4090d0709 100644 --- a/drivers/xen/events/events_internal.h +++ b/drivers/xen/events/events_internal.h @@ -14,6 +14,7 @@ struct evtchn_ops { unsigned (*nr_channels)(void); =20 int (*setup)(evtchn_port_t port); + void (*remove)(evtchn_port_t port, unsigned int cpu); void (*bind_to_cpu)(evtchn_port_t evtchn, unsigned int cpu, unsigned int old_cpu); =20 @@ -54,6 +55,13 @@ static inline int xen_evtchn_port_setup(evtchn_port_t ev= tchn) return 0; } =20 +static inline void xen_evtchn_port_remove(evtchn_port_t evtchn, + unsigned int cpu) +{ + if (evtchn_ops->remove) + evtchn_ops->remove(evtchn, cpu); +} + static inline void xen_evtchn_port_bind_to_cpu(evtchn_port_t evtchn, unsigned int cpu, unsigned int old_cpu) --=20 2.26.2 From nobody Sun May 5 02:16:31 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1613749263; cv=none; d=zohomail.com; s=zohoarc; b=O6kXlmVjhTcwn6m4RGJDtxbtK8JmkTR/a6FDfiOTNrNhG12/6Jgl74V+Iy5CIpGoIEP1bLrA2yKwxsuBEC6M4/AUgrEuLqnQE1psvRL7n8qFSko0Mdkz7EUF4SqgeslVjOwe0Hw12BrsMOSeaekhEVZps/y5dhLCF8DvayNXF2g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1613749263; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=3oKwFjI7QJbP3FIEeR3qa2NxeJ0L76eV38hLUEb9hjo=; b=Z0qPpHQ4FmX2fU5HbwVPlkNp/6mkq/kJ/7TKsnb7Ify6AuWxRTTI9+uZ0pTXsYepnjQZHwgN37olyTc26rWnihyWEs+aXgAMR3JNAaUwCRnJijobqLLVKC6XS7hwmGRIB0Ga+TE3tw4hCpwMKlXf/jc0QZ1GCQ+qOy3SNvM9fSw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1613749262748697.8776525232436; Fri, 19 Feb 2021 07:41:02 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.86933.163571 (Exim 4.92) (envelope-from ) id 1lD7te-0002JY-SK; Fri, 19 Feb 2021 15:40:46 +0000 Received: by outflank-mailman (output) from mailman id 86933.163571; Fri, 19 Feb 2021 15:40:46 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lD7te-0002JI-Hs; Fri, 19 Feb 2021 15:40:46 +0000 Received: by outflank-mailman (input) for mailman id 86933; Fri, 19 Feb 2021 15:40:45 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lD7tc-0002F7-Vf for xen-devel@lists.xenproject.org; Fri, 19 Feb 2021 15:40:44 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 4387be5f-7ab4-46f3-840c-020f1ce719c3; Fri, 19 Feb 2021 15:40:39 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 48961AEE7; Fri, 19 Feb 2021 15:40:38 +0000 (UTC) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 4387be5f-7ab4-46f3-840c-020f1ce719c3 X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1613749238; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3oKwFjI7QJbP3FIEeR3qa2NxeJ0L76eV38hLUEb9hjo=; b=Krq+2gAPtl2iwBk9OuqOgdBVyD8pTmW+cAprW8bgBNVfAHrb+ZskD1FHPqIDjh3m0fr6xh aZ+CpDR7AuySaiogHQX+JCH2eUdJ9zIM4Uw+yiBWCY8TfxV6PECxUtU7c4Vbb4YLFO9FSv 7t7T3Vp9+/dR5Si/Ui3GUKoIJuvlaF8= From: Juergen Gross To: xen-devel@lists.xenproject.org, linux-kernel@vger.kernel.org Cc: Juergen Gross , Boris Ostrovsky , Stefano Stabellini , stable@vger.kernel.org, Julien Grall Subject: [PATCH v3 2/8] xen/events: don't unmask an event channel when an eoi is pending Date: Fri, 19 Feb 2021 16:40:24 +0100 Message-Id: <20210219154030.10892-3-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210219154030.10892-1-jgross@suse.com> References: <20210219154030.10892-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) Content-Type: text/plain; charset="utf-8" An event channel should be kept masked when an eoi is pending for it. When being migrated to another cpu it might be unmasked, though. In order to avoid this keep three different flags for each event channel to be able to distinguish "normal" masking/unmasking from eoi related masking/unmasking and temporary masking. The event channel should only be able to generate an interrupt if all flags are cleared. Cc: stable@vger.kernel.org Fixes: 54c9de89895e0a36047 ("xen/events: add a new late EOI evtchn framewor= k") Reported-by: Julien Grall Signed-off-by: Juergen Gross Reviewed-by: Julien Grall --- V2: - introduce a lock around masking/unmasking - merge patch 3 into this one (Jan Beulich) --- drivers/xen/events/events_2l.c | 7 -- drivers/xen/events/events_base.c | 102 +++++++++++++++++++++------ drivers/xen/events/events_fifo.c | 7 -- drivers/xen/events/events_internal.h | 6 -- 4 files changed, 81 insertions(+), 41 deletions(-) diff --git a/drivers/xen/events/events_2l.c b/drivers/xen/events/events_2l.c index a7f413c5c190..b8f2f971c2f0 100644 --- a/drivers/xen/events/events_2l.c +++ b/drivers/xen/events/events_2l.c @@ -77,12 +77,6 @@ static bool evtchn_2l_is_pending(evtchn_port_t port) return sync_test_bit(port, BM(&s->evtchn_pending[0])); } =20 -static bool evtchn_2l_test_and_set_mask(evtchn_port_t port) -{ - struct shared_info *s =3D HYPERVISOR_shared_info; - return sync_test_and_set_bit(port, BM(&s->evtchn_mask[0])); -} - static void evtchn_2l_mask(evtchn_port_t port) { struct shared_info *s =3D HYPERVISOR_shared_info; @@ -376,7 +370,6 @@ static const struct evtchn_ops evtchn_ops_2l =3D { .clear_pending =3D evtchn_2l_clear_pending, .set_pending =3D evtchn_2l_set_pending, .is_pending =3D evtchn_2l_is_pending, - .test_and_set_mask =3D evtchn_2l_test_and_set_mask, .mask =3D evtchn_2l_mask, .unmask =3D evtchn_2l_unmask, .handle_events =3D evtchn_2l_handle_events, diff --git a/drivers/xen/events/events_base.c b/drivers/xen/events/events_b= ase.c index 6c539db81f8f..e157e7506830 100644 --- a/drivers/xen/events/events_base.c +++ b/drivers/xen/events/events_base.c @@ -97,13 +97,18 @@ struct irq_info { short refcnt; u8 spurious_cnt; u8 is_accounted; - enum xen_irq_type type; /* type */ + short type; /* type: IRQT_* */ + u8 mask_reason; /* Why is event channel masked */ +#define EVT_MASK_REASON_EXPLICIT 0x01 +#define EVT_MASK_REASON_TEMPORARY 0x02 +#define EVT_MASK_REASON_EOI_PENDING 0x04 unsigned irq; evtchn_port_t evtchn; /* event channel */ unsigned short cpu; /* cpu bound */ unsigned short eoi_cpu; /* EOI must happen on this cpu-1 */ unsigned int irq_epoch; /* If eoi_cpu valid: irq_epoch of event */ u64 eoi_time; /* Time in jiffies when to EOI. */ + spinlock_t lock; =20 union { unsigned short virq; @@ -152,6 +157,7 @@ static DEFINE_RWLOCK(evtchn_rwlock); * evtchn_rwlock * IRQ-desc lock * percpu eoi_list_lock + * irq_info->lock */ =20 static LIST_HEAD(xen_irq_list_head); @@ -302,6 +308,8 @@ static int xen_irq_info_common_setup(struct irq_info *i= nfo, info->irq =3D irq; info->evtchn =3D evtchn; info->cpu =3D cpu; + info->mask_reason =3D EVT_MASK_REASON_EXPLICIT; + spin_lock_init(&info->lock); =20 ret =3D set_evtchn_to_irq(evtchn, irq); if (ret < 0) @@ -450,6 +458,34 @@ unsigned int cpu_from_evtchn(evtchn_port_t evtchn) return ret; } =20 +static void do_mask(struct irq_info *info, u8 reason) +{ + unsigned long flags; + + spin_lock_irqsave(&info->lock, flags); + + if (!info->mask_reason) + mask_evtchn(info->evtchn); + + info->mask_reason |=3D reason; + + spin_unlock_irqrestore(&info->lock, flags); +} + +static void do_unmask(struct irq_info *info, u8 reason) +{ + unsigned long flags; + + spin_lock_irqsave(&info->lock, flags); + + info->mask_reason &=3D ~reason; + + if (!info->mask_reason) + unmask_evtchn(info->evtchn); + + spin_unlock_irqrestore(&info->lock, flags); +} + #ifdef CONFIG_X86 static bool pirq_check_eoi_map(unsigned irq) { @@ -586,7 +622,7 @@ static void xen_irq_lateeoi_locked(struct irq_info *inf= o, bool spurious) } =20 info->eoi_time =3D 0; - unmask_evtchn(evtchn); + do_unmask(info, EVT_MASK_REASON_EOI_PENDING); } =20 static void xen_irq_lateeoi_worker(struct work_struct *work) @@ -831,7 +867,8 @@ static unsigned int __startup_pirq(unsigned int irq) goto err; =20 out: - unmask_evtchn(evtchn); + do_unmask(info, EVT_MASK_REASON_EXPLICIT); + eoi_pirq(irq_get_irq_data(irq)); =20 return 0; @@ -858,7 +895,7 @@ static void shutdown_pirq(struct irq_data *data) if (!VALID_EVTCHN(evtchn)) return; =20 - mask_evtchn(evtchn); + do_mask(info, EVT_MASK_REASON_EXPLICIT); xen_evtchn_close(evtchn); xen_irq_info_cleanup(info); } @@ -1691,10 +1728,10 @@ void rebind_evtchn_irq(evtchn_port_t evtchn, int ir= q) } =20 /* Rebind an evtchn so that it gets delivered to a specific cpu */ -static int xen_rebind_evtchn_to_cpu(evtchn_port_t evtchn, unsigned int tcp= u) +static int xen_rebind_evtchn_to_cpu(struct irq_info *info, unsigned int tc= pu) { struct evtchn_bind_vcpu bind_vcpu; - int masked; + evtchn_port_t evtchn =3D info ? info->evtchn : 0; =20 if (!VALID_EVTCHN(evtchn)) return -1; @@ -1710,7 +1747,7 @@ static int xen_rebind_evtchn_to_cpu(evtchn_port_t evt= chn, unsigned int tcpu) * Mask the event while changing the VCPU binding to prevent * it being delivered on an unexpected VCPU. */ - masked =3D test_and_set_mask(evtchn); + do_mask(info, EVT_MASK_REASON_TEMPORARY); =20 /* * If this fails, it usually just indicates that we're dealing with a @@ -1720,8 +1757,7 @@ static int xen_rebind_evtchn_to_cpu(evtchn_port_t evt= chn, unsigned int tcpu) if (HYPERVISOR_event_channel_op(EVTCHNOP_bind_vcpu, &bind_vcpu) >=3D 0) bind_evtchn_to_cpu(evtchn, tcpu, false); =20 - if (!masked) - unmask_evtchn(evtchn); + do_unmask(info, EVT_MASK_REASON_TEMPORARY); =20 return 0; } @@ -1760,7 +1796,7 @@ static int set_affinity_irq(struct irq_data *data, co= nst struct cpumask *dest, unsigned int tcpu =3D select_target_cpu(dest); int ret; =20 - ret =3D xen_rebind_evtchn_to_cpu(evtchn_from_irq(data->irq), tcpu); + ret =3D xen_rebind_evtchn_to_cpu(info_for_irq(data->irq), tcpu); if (!ret) irq_data_update_effective_affinity(data, cpumask_of(tcpu)); =20 @@ -1769,18 +1805,20 @@ static int set_affinity_irq(struct irq_data *data, = const struct cpumask *dest, =20 static void enable_dynirq(struct irq_data *data) { - evtchn_port_t evtchn =3D evtchn_from_irq(data->irq); + struct irq_info *info =3D info_for_irq(data->irq); + evtchn_port_t evtchn =3D info ? info->evtchn : 0; =20 if (VALID_EVTCHN(evtchn)) - unmask_evtchn(evtchn); + do_unmask(info, EVT_MASK_REASON_EXPLICIT); } =20 static void disable_dynirq(struct irq_data *data) { - evtchn_port_t evtchn =3D evtchn_from_irq(data->irq); + struct irq_info *info =3D info_for_irq(data->irq); + evtchn_port_t evtchn =3D info ? info->evtchn : 0; =20 if (VALID_EVTCHN(evtchn)) - mask_evtchn(evtchn); + do_mask(info, EVT_MASK_REASON_EXPLICIT); } =20 static void ack_dynirq(struct irq_data *data) @@ -1799,18 +1837,40 @@ static void mask_ack_dynirq(struct irq_data *data) ack_dynirq(data); } =20 +static void lateeoi_ack_dynirq(struct irq_data *data) +{ + struct irq_info *info =3D info_for_irq(data->irq); + evtchn_port_t evtchn =3D info ? info->evtchn : 0; + + if (VALID_EVTCHN(evtchn)) { + do_mask(info, EVT_MASK_REASON_EOI_PENDING); + clear_evtchn(evtchn); + } +} + +static void lateeoi_mask_ack_dynirq(struct irq_data *data) +{ + struct irq_info *info =3D info_for_irq(data->irq); + evtchn_port_t evtchn =3D info ? info->evtchn : 0; + + if (VALID_EVTCHN(evtchn)) { + do_mask(info, EVT_MASK_REASON_EXPLICIT | + EVT_MASK_REASON_EOI_PENDING); + clear_evtchn(evtchn); + } +} + static int retrigger_dynirq(struct irq_data *data) { - evtchn_port_t evtchn =3D evtchn_from_irq(data->irq); - int masked; + struct irq_info *info =3D info_for_irq(data->irq); + evtchn_port_t evtchn =3D info ? info->evtchn : 0; =20 if (!VALID_EVTCHN(evtchn)) return 0; =20 - masked =3D test_and_set_mask(evtchn); + do_mask(info, EVT_MASK_REASON_TEMPORARY); set_evtchn(evtchn); - if (!masked) - unmask_evtchn(evtchn); + do_unmask(info, EVT_MASK_REASON_TEMPORARY); =20 return 1; } @@ -2024,8 +2084,8 @@ static struct irq_chip xen_lateeoi_chip __read_mostly= =3D { .irq_mask =3D disable_dynirq, .irq_unmask =3D enable_dynirq, =20 - .irq_ack =3D mask_ack_dynirq, - .irq_mask_ack =3D mask_ack_dynirq, + .irq_ack =3D lateeoi_ack_dynirq, + .irq_mask_ack =3D lateeoi_mask_ack_dynirq, =20 .irq_set_affinity =3D set_affinity_irq, .irq_retrigger =3D retrigger_dynirq, diff --git a/drivers/xen/events/events_fifo.c b/drivers/xen/events/events_f= ifo.c index b234f1766810..ad9fe51d3fb3 100644 --- a/drivers/xen/events/events_fifo.c +++ b/drivers/xen/events/events_fifo.c @@ -209,12 +209,6 @@ static bool evtchn_fifo_is_pending(evtchn_port_t port) return sync_test_bit(EVTCHN_FIFO_BIT(PENDING, word), BM(word)); } =20 -static bool evtchn_fifo_test_and_set_mask(evtchn_port_t port) -{ - event_word_t *word =3D event_word_from_port(port); - return sync_test_and_set_bit(EVTCHN_FIFO_BIT(MASKED, word), BM(word)); -} - static void evtchn_fifo_mask(evtchn_port_t port) { event_word_t *word =3D event_word_from_port(port); @@ -423,7 +417,6 @@ static const struct evtchn_ops evtchn_ops_fifo =3D { .clear_pending =3D evtchn_fifo_clear_pending, .set_pending =3D evtchn_fifo_set_pending, .is_pending =3D evtchn_fifo_is_pending, - .test_and_set_mask =3D evtchn_fifo_test_and_set_mask, .mask =3D evtchn_fifo_mask, .unmask =3D evtchn_fifo_unmask, .handle_events =3D evtchn_fifo_handle_events, diff --git a/drivers/xen/events/events_internal.h b/drivers/xen/events/even= ts_internal.h index 18a4090d0709..4d3398eff9cd 100644 --- a/drivers/xen/events/events_internal.h +++ b/drivers/xen/events/events_internal.h @@ -21,7 +21,6 @@ struct evtchn_ops { void (*clear_pending)(evtchn_port_t port); void (*set_pending)(evtchn_port_t port); bool (*is_pending)(evtchn_port_t port); - bool (*test_and_set_mask)(evtchn_port_t port); void (*mask)(evtchn_port_t port); void (*unmask)(evtchn_port_t port); =20 @@ -84,11 +83,6 @@ static inline bool test_evtchn(evtchn_port_t port) return evtchn_ops->is_pending(port); } =20 -static inline bool test_and_set_mask(evtchn_port_t port) -{ - return evtchn_ops->test_and_set_mask(port); -} - static inline void mask_evtchn(evtchn_port_t port) { return evtchn_ops->mask(port); --=20 2.26.2 From nobody Sun May 5 02:16:31 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1613749263; cv=none; d=zohomail.com; s=zohoarc; b=QP6yJiOEjeYA38WPlJMruvzKbAIgnbVob6F6zaM73qYCGABtQoxOgJjTJANkIYW50e3jtYmXOdgcdhFM7DobRDvDsfIUflBQ6HK1/hls229UNuNq1wD8SKN3nvlDAKKFRdHnOifDBJtmOZ3OKgZnACCz7CPqolDYzNc2p6p+ORo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1613749263; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=l3hsQtjVhbUJuzJrwS+bXrEjvj+YDAiuRUM066+18HU=; b=hpXlmEUrmEISKcKPa7d2Ympkl90mpvFf0SkHDOQYpYf+irOthSkrkMzDJsD4QrHkPR+xRUyCkzN/mtdrlJAOF6AFWqRnzGXB5bGlgX8pi8RJl4iuMlwLLeE+tESa+QbgNQBKEFnVhmRYK2aZ04UYzbAR0s7WovoAL5B7GSquEkw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1613749263097395.45555827725286; Fri, 19 Feb 2021 07:41:03 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.86932.163564 (Exim 4.92) (envelope-from ) id 1lD7te-0002Il-D8; Fri, 19 Feb 2021 15:40:46 +0000 Received: by outflank-mailman (output) from mailman id 86932.163564; Fri, 19 Feb 2021 15:40:46 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lD7te-0002Ie-8v; Fri, 19 Feb 2021 15:40:46 +0000 Received: by outflank-mailman (input) for mailman id 86932; Fri, 19 Feb 2021 15:40:45 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lD7tc-0002F6-V2 for xen-devel@lists.xenproject.org; Fri, 19 Feb 2021 15:40:44 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id db1eec34-b373-4506-9779-f75a822cf7ce; Fri, 19 Feb 2021 15:40:39 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 7C5A8AF23; Fri, 19 Feb 2021 15:40:38 +0000 (UTC) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: db1eec34-b373-4506-9779-f75a822cf7ce X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1613749238; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=l3hsQtjVhbUJuzJrwS+bXrEjvj+YDAiuRUM066+18HU=; b=Mc5dLu2iK4ri54BVS8sVlgoCdpzZyxnZb6PrS1izcSrnyoWAfPFIU02dYvCgRltNbGbIHW oI3sqwmM0Q2vgPMX7v3/FBtanmeY4inkYGxGOt//Jb19mpHGoSbfO8NU+nPaL4L7JnOwyJ lXkAGmpRFn162CNsNJmSx3FibIYwqZw= From: Juergen Gross To: xen-devel@lists.xenproject.org, linux-kernel@vger.kernel.org Cc: Juergen Gross , Boris Ostrovsky , Stefano Stabellini , stable@vger.kernel.org, Julien Grall Subject: [PATCH v3 3/8] xen/events: avoid handling the same event on two cpus at the same time Date: Fri, 19 Feb 2021 16:40:25 +0100 Message-Id: <20210219154030.10892-4-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210219154030.10892-1-jgross@suse.com> References: <20210219154030.10892-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) Content-Type: text/plain; charset="utf-8" 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. Cc: stable@vger.kernel.org Reported-by: Julien Grall Signed-off-by: Juergen Gross Reviewed-by: Julien Grall --- V2: - new patch V3: - use common helper for end of handler action (Julien Grall) - move setting is_active to 0 for lateeoi (Boris Ostrovsky) --- drivers/xen/events/events_base.c | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/drivers/xen/events/events_base.c b/drivers/xen/events/events_b= ase.c index e157e7506830..9d7ba7623510 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 */ @@ -791,6 +792,12 @@ static void xen_evtchn_close(evtchn_port_t port) BUG(); } =20 +static void event_handler_exit(struct irq_info *info) +{ + smp_store_release(&info->is_active, 0); + clear_evtchn(info->evtchn); +} + static void pirq_query_unmask(int irq) { struct physdev_irq_status_query irq_status; @@ -809,14 +816,15 @@ static void pirq_query_unmask(int irq) =20 static void eoi_pirq(struct irq_data *data) { - evtchn_port_t evtchn =3D evtchn_from_irq(data->irq); + struct irq_info *info =3D info_for_irq(data->irq); + evtchn_port_t evtchn =3D info ? info->evtchn : 0; struct physdev_eoi eoi =3D { .irq =3D pirq_from_irq(data->irq) }; int rc =3D 0; =20 if (!VALID_EVTCHN(evtchn)) return; =20 - clear_evtchn(evtchn); + event_handler_exit(info); =20 if (pirq_needs_eoi(data->irq)) { rc =3D HYPERVISOR_physdev_op(PHYSDEVOP_eoi, &eoi); @@ -1640,6 +1648,8 @@ void handle_irq_for_port(evtchn_port_t port, struct e= vtchn_loop_ctrl *ctrl) } =20 info =3D info_for_irq(irq); + if (xchg_acquire(&info->is_active, 1)) + return; =20 if (ctrl->defer_eoi) { info->eoi_cpu =3D smp_processor_id(); @@ -1823,12 +1833,11 @@ static void disable_dynirq(struct irq_data *data) =20 static void ack_dynirq(struct irq_data *data) { - evtchn_port_t evtchn =3D evtchn_from_irq(data->irq); - - if (!VALID_EVTCHN(evtchn)) - return; + struct irq_info *info =3D info_for_irq(data->irq); + evtchn_port_t evtchn =3D info ? info->evtchn : 0; =20 - clear_evtchn(evtchn); + if (VALID_EVTCHN(evtchn)) + event_handler_exit(info); } =20 static void mask_ack_dynirq(struct irq_data *data) @@ -1844,7 +1853,7 @@ static void lateeoi_ack_dynirq(struct irq_data *data) =20 if (VALID_EVTCHN(evtchn)) { do_mask(info, EVT_MASK_REASON_EOI_PENDING); - clear_evtchn(evtchn); + event_handler_exit(info); } } =20 @@ -1856,7 +1865,7 @@ static void lateeoi_mask_ack_dynirq(struct irq_data *= data) if (VALID_EVTCHN(evtchn)) { do_mask(info, EVT_MASK_REASON_EXPLICIT | EVT_MASK_REASON_EOI_PENDING); - clear_evtchn(evtchn); + event_handler_exit(info); } } =20 @@ -1969,10 +1978,11 @@ 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 =3D evtchn_from_irq(irq); + struct irq_info *info =3D info_for_irq(irq); + evtchn_port_t evtchn =3D info ? info->evtchn : 0; =20 if (VALID_EVTCHN(evtchn)) - clear_evtchn(evtchn); + event_handler_exit(info); } EXPORT_SYMBOL(xen_clear_irq_pending); void xen_set_irq_pending(int irq) --=20 2.26.2 From nobody Sun May 5 02:16:31 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1613749268; cv=none; d=zohomail.com; s=zohoarc; b=W95B2zLSaAVUZhKgQyPZtUaXWwdNB+YnTBOsckNOvJVoLtYJVrkM9W1Bj4odHwhklDd+TykTSOR3PH5Ic8vK9dZ15FgTdMO9s8AQCptGAPvmn7nx2YG0bTol+OZ3vxTUr0DbOvRr6fpqooX4IXk7Yc6fGhhH9mbzY9YxGaYNMF8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1613749268; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=QmVbRiyGhWjgyRhmW9maPS5XeYQ8D0P7LNo1+euH3hI=; b=FZkua0s/d+dLTZ9qA+NbFWL+tdy2A58NDz5DHalyEGjUUF4DEtBOooXq21PfwOfMPhrNJrvFCufbbxi3XQXuwh1Ca9II1ZMaEq3y+MMHOd+QosO9iuT4ZtQbiMCE2dXH+idOnvUaLRIHx9J55LeOpN9Tl9WDvJ5hfZ6AlpxfL2M= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 16137492678391005.1759124040564; Fri, 19 Feb 2021 07:41:07 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.86934.163588 (Exim 4.92) (envelope-from ) id 1lD7tk-0002QA-0W; Fri, 19 Feb 2021 15:40:52 +0000 Received: by outflank-mailman (output) from mailman id 86934.163588; Fri, 19 Feb 2021 15:40:51 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lD7tj-0002Q1-Sa; Fri, 19 Feb 2021 15:40:51 +0000 Received: by outflank-mailman (input) for mailman id 86934; Fri, 19 Feb 2021 15:40:50 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lD7th-0002F6-V9 for xen-devel@lists.xenproject.org; Fri, 19 Feb 2021 15:40:49 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id d945f9fa-43c4-4d82-b864-f9b70dc12d2e; Fri, 19 Feb 2021 15:40:39 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id C5B9AB10B; Fri, 19 Feb 2021 15:40:38 +0000 (UTC) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: d945f9fa-43c4-4d82-b864-f9b70dc12d2e X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1613749238; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=QmVbRiyGhWjgyRhmW9maPS5XeYQ8D0P7LNo1+euH3hI=; b=kUPpmw0yKQA70gsRODhJFsj/8eUsG8GG0hrbpqX7y81r0C26/2h9EUbs0xUKId7cwep9Am gireTmt9iiSmUipV/+ZpaGWiJ2siBWquCtwD2sAbj6VLLHfWhdZl4VbbcwKpZAGnf74FYh QpyLJ4Yxuslqb5hRXglPLi6uk8bEdGY= From: Juergen Gross To: xen-devel@lists.xenproject.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Juergen Gross , Wei Liu , Paul Durrant , "David S. Miller" , Jakub Kicinski , stable@vger.kernel.org, Jan Beulich , Wei Liu Subject: [PATCH v3 4/8] xen/netback: fix spurious event detection for common event case Date: Fri, 19 Feb 2021 16:40:26 +0100 Message-Id: <20210219154030.10892-5-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210219154030.10892-1-jgross@suse.com> References: <20210219154030.10892-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) Content-Type: text/plain; charset="utf-8" In case of a common event for rx and tx queue the event should be regarded to be spurious if no rx and no tx requests are pending. Unfortunately the condition for testing that is wrong causing to decide a event being spurious if no rx OR no tx requests are pending. Fix that plus using local variables for rx/tx pending indicators in order to split function calls and if condition. Cc: stable@vger.kernel.org Fixes: 23025393dbeb3b ("xen/netback: use lateeoi irq binding") Signed-off-by: Juergen Gross Reviewed-by: Jan Beulich Reviewed-by: Paul Durrant Reviewed-by: Wei Liu --- V2: - new patch, fixing FreeBSD performance issue --- drivers/net/xen-netback/interface.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/net/xen-netback/interface.c b/drivers/net/xen-netback/= interface.c index acb786d8b1d8..e02a4fbb74de 100644 --- a/drivers/net/xen-netback/interface.c +++ b/drivers/net/xen-netback/interface.c @@ -162,13 +162,15 @@ irqreturn_t xenvif_interrupt(int irq, void *dev_id) { struct xenvif_queue *queue =3D dev_id; int old; + bool has_rx, has_tx; =20 old =3D atomic_fetch_or(NETBK_COMMON_EOI, &queue->eoi_pending); WARN(old, "Interrupt while EOI pending\n"); =20 - /* Use bitwise or as we need to call both functions. */ - if ((!xenvif_handle_tx_interrupt(queue) | - !xenvif_handle_rx_interrupt(queue))) { + has_tx =3D xenvif_handle_tx_interrupt(queue); + has_rx =3D xenvif_handle_rx_interrupt(queue); + + if (!has_rx && !has_tx) { atomic_andnot(NETBK_COMMON_EOI, &queue->eoi_pending); xen_irq_lateeoi(irq, XEN_EOI_FLAG_SPURIOUS); } --=20 2.26.2 From nobody Sun May 5 02:16:31 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1613749271; cv=none; d=zohomail.com; s=zohoarc; b=Ng/1dZoZVgiwFcUIr0nHxECfeBZ1nw7UnFWMSfW5hmzMXlusD4I/mPrCPEGGGubhk14lz3EyiLri21oonbDHu5msXc2yOn+tSUmM6IiAuhA26nuFnEnOcLyvSQG+tOsjB4Rp6djr7yH5GTuKa2pTEXDH2mlvC+EXAvX+CVaiX34= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1613749271; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Ak07w92nb7YZjr3VNNPBcdRWHdpt4Qfsb+0QEiXHvow=; b=mlbQX5DM3Jj/nxLxKbdg96ux5oOZFlQosyLvOBl8HW9XxhbPARrGxw/TF5qxH5c3nfmDd8S5nDhGr2e9zLusLhRHZWwIsdgUF05UCFWTOPmPrd1C37pGp8n/y+zd3TlpL+kGFPuCn+YZpzJC6suIs34Pnuhsd7i7DXDM1gaDeVQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1613749271959614.0177647755312; Fri, 19 Feb 2021 07:41:11 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.86937.163618 (Exim 4.92) (envelope-from ) id 1lD7tp-0002b6-Mh; Fri, 19 Feb 2021 15:40:57 +0000 Received: by outflank-mailman (output) from mailman id 86937.163618; Fri, 19 Feb 2021 15:40:57 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lD7tp-0002ag-C5; Fri, 19 Feb 2021 15:40:57 +0000 Received: by outflank-mailman (input) for mailman id 86937; Fri, 19 Feb 2021 15:40:55 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lD7tm-0002F7-Vw for xen-devel@lists.xenproject.org; Fri, 19 Feb 2021 15:40:55 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id b9c76555-797f-4038-8c26-98d27ef634e8; Fri, 19 Feb 2021 15:40:40 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 349CDB112; Fri, 19 Feb 2021 15:40:39 +0000 (UTC) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: b9c76555-797f-4038-8c26-98d27ef634e8 X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1613749239; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Ak07w92nb7YZjr3VNNPBcdRWHdpt4Qfsb+0QEiXHvow=; b=m4oBqkbD/J0XMEHCZgXSg4TG7sdainHTuh9UGcR5bUtj6PJT9S5rbPq0yawzRopsO1fKg/ fjSM1x0hUPEPyBkPo6wvzAa/BWiMgBbeMiebc2U5iC19UpbuoIMh3EdMB1hDw5ObeZ9Tyc FCiyRKbsyQ6RmR5diqVsVt7inPEpljI= From: Juergen Gross To: xen-devel@lists.xenproject.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-scsi@vger.kernel.org Cc: Juergen Gross , Konrad Rzeszutek Wilk , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Jens Axboe , Wei Liu , Paul Durrant , "David S. Miller" , Jakub Kicinski , Boris Ostrovsky , Stefano Stabellini Subject: [PATCH v3 5/8] xen/events: link interdomain events to associated xenbus device Date: Fri, 19 Feb 2021 16:40:27 +0100 Message-Id: <20210219154030.10892-6-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210219154030.10892-1-jgross@suse.com> References: <20210219154030.10892-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) Content-Type: text/plain; charset="utf-8" In order to support the possibility of per-device event channel settings (e.g. lateeoi spurious event thresholds) add a xenbus device pointer to struct irq_info() and modify the related event channel binding interfaces to take the pointer to the xenbus device as a parameter instead of the domain id of the other side. While at it remove the stale prototype of bind_evtchn_to_irq_lateeoi(). Signed-off-by: Juergen Gross Reviewed-by: Boris Ostrovsky Reviewed-by: Wei Liu Reviewed-by: Paul Durrant Reviewed-by: Roger Pau Monn=C3=A9 --- drivers/block/xen-blkback/xenbus.c | 2 +- drivers/net/xen-netback/interface.c | 16 +++++------ drivers/xen/events/events_base.c | 41 +++++++++++++++++------------ drivers/xen/pvcalls-back.c | 4 +-- drivers/xen/xen-pciback/xenbus.c | 2 +- drivers/xen/xen-scsiback.c | 2 +- include/xen/events.h | 7 ++--- 7 files changed, 41 insertions(+), 33 deletions(-) diff --git a/drivers/block/xen-blkback/xenbus.c b/drivers/block/xen-blkback= /xenbus.c index 9860d4842f36..c2aaf690352c 100644 --- a/drivers/block/xen-blkback/xenbus.c +++ b/drivers/block/xen-blkback/xenbus.c @@ -245,7 +245,7 @@ static int xen_blkif_map(struct xen_blkif_ring *ring, g= rant_ref_t *gref, if (req_prod - rsp_prod > size) goto fail; =20 - err =3D bind_interdomain_evtchn_to_irqhandler_lateeoi(blkif->domid, + err =3D bind_interdomain_evtchn_to_irqhandler_lateeoi(blkif->be->dev, evtchn, xen_blkif_be_int, 0, "blkif-backend", ring); if (err < 0) goto fail; diff --git a/drivers/net/xen-netback/interface.c b/drivers/net/xen-netback/= interface.c index e02a4fbb74de..50a94e58c150 100644 --- a/drivers/net/xen-netback/interface.c +++ b/drivers/net/xen-netback/interface.c @@ -630,13 +630,13 @@ int xenvif_connect_ctrl(struct xenvif *vif, grant_ref= _t ring_ref, unsigned int evtchn) { struct net_device *dev =3D vif->dev; + struct xenbus_device *xendev =3D xenvif_to_xenbus_device(vif); void *addr; struct xen_netif_ctrl_sring *shared; RING_IDX rsp_prod, req_prod; int err; =20 - err =3D xenbus_map_ring_valloc(xenvif_to_xenbus_device(vif), - &ring_ref, 1, &addr); + err =3D xenbus_map_ring_valloc(xendev, &ring_ref, 1, &addr); if (err) goto err; =20 @@ -650,7 +650,7 @@ int xenvif_connect_ctrl(struct xenvif *vif, grant_ref_t= ring_ref, if (req_prod - rsp_prod > RING_SIZE(&vif->ctrl)) goto err_unmap; =20 - err =3D bind_interdomain_evtchn_to_irq_lateeoi(vif->domid, evtchn); + err =3D bind_interdomain_evtchn_to_irq_lateeoi(xendev, evtchn); if (err < 0) goto err_unmap; =20 @@ -673,8 +673,7 @@ int xenvif_connect_ctrl(struct xenvif *vif, grant_ref_t= ring_ref, vif->ctrl_irq =3D 0; =20 err_unmap: - xenbus_unmap_ring_vfree(xenvif_to_xenbus_device(vif), - vif->ctrl.sring); + xenbus_unmap_ring_vfree(xendev, vif->ctrl.sring); vif->ctrl.sring =3D NULL; =20 err: @@ -719,6 +718,7 @@ int xenvif_connect_data(struct xenvif_queue *queue, unsigned int tx_evtchn, unsigned int rx_evtchn) { + struct xenbus_device *dev =3D xenvif_to_xenbus_device(queue->vif); struct task_struct *task; int err; =20 @@ -755,7 +755,7 @@ int xenvif_connect_data(struct xenvif_queue *queue, if (tx_evtchn =3D=3D rx_evtchn) { /* feature-split-event-channels =3D=3D 0 */ err =3D bind_interdomain_evtchn_to_irqhandler_lateeoi( - queue->vif->domid, tx_evtchn, xenvif_interrupt, 0, + dev, tx_evtchn, xenvif_interrupt, 0, queue->name, queue); if (err < 0) goto err; @@ -766,7 +766,7 @@ int xenvif_connect_data(struct xenvif_queue *queue, snprintf(queue->tx_irq_name, sizeof(queue->tx_irq_name), "%s-tx", queue->name); err =3D bind_interdomain_evtchn_to_irqhandler_lateeoi( - queue->vif->domid, tx_evtchn, xenvif_tx_interrupt, 0, + dev, tx_evtchn, xenvif_tx_interrupt, 0, queue->tx_irq_name, queue); if (err < 0) goto err; @@ -776,7 +776,7 @@ int xenvif_connect_data(struct xenvif_queue *queue, snprintf(queue->rx_irq_name, sizeof(queue->rx_irq_name), "%s-rx", queue->name); err =3D bind_interdomain_evtchn_to_irqhandler_lateeoi( - queue->vif->domid, rx_evtchn, xenvif_rx_interrupt, 0, + dev, rx_evtchn, xenvif_rx_interrupt, 0, queue->rx_irq_name, queue); if (err < 0) goto err; diff --git a/drivers/xen/events/events_base.c b/drivers/xen/events/events_b= ase.c index 9d7ba7623510..b60df189ecbc 100644 --- a/drivers/xen/events/events_base.c +++ b/drivers/xen/events/events_base.c @@ -63,6 +63,7 @@ #include #include #include +#include #include =20 #include "events_internal.h" @@ -121,6 +122,7 @@ struct irq_info { unsigned char flags; uint16_t domid; } pirq; + struct xenbus_device *interdomain; } u; }; =20 @@ -322,11 +324,16 @@ static int xen_irq_info_common_setup(struct irq_info = *info, } =20 static int xen_irq_info_evtchn_setup(unsigned irq, - evtchn_port_t evtchn) + evtchn_port_t evtchn, + struct xenbus_device *dev) { struct irq_info *info =3D info_for_irq(irq); + int ret; =20 - return xen_irq_info_common_setup(info, irq, IRQT_EVTCHN, evtchn, 0); + ret =3D xen_irq_info_common_setup(info, irq, IRQT_EVTCHN, evtchn, 0); + info->u.interdomain =3D dev; + + return ret; } =20 static int xen_irq_info_ipi_setup(unsigned cpu, @@ -1162,7 +1169,8 @@ int xen_pirq_from_irq(unsigned irq) } EXPORT_SYMBOL_GPL(xen_pirq_from_irq); =20 -static int bind_evtchn_to_irq_chip(evtchn_port_t evtchn, struct irq_chip *= chip) +static int bind_evtchn_to_irq_chip(evtchn_port_t evtchn, struct irq_chip *= chip, + struct xenbus_device *dev) { int irq; int ret; @@ -1182,7 +1190,7 @@ static int bind_evtchn_to_irq_chip(evtchn_port_t evtc= hn, struct irq_chip *chip) irq_set_chip_and_handler_name(irq, chip, handle_edge_irq, "event"); =20 - ret =3D xen_irq_info_evtchn_setup(irq, evtchn); + ret =3D xen_irq_info_evtchn_setup(irq, evtchn, dev); if (ret < 0) { __unbind_from_irq(irq); irq =3D ret; @@ -1209,7 +1217,7 @@ static int bind_evtchn_to_irq_chip(evtchn_port_t evtc= hn, struct irq_chip *chip) =20 int bind_evtchn_to_irq(evtchn_port_t evtchn) { - return bind_evtchn_to_irq_chip(evtchn, &xen_dynamic_chip); + return bind_evtchn_to_irq_chip(evtchn, &xen_dynamic_chip, NULL); } EXPORT_SYMBOL_GPL(bind_evtchn_to_irq); =20 @@ -1258,27 +1266,27 @@ static int bind_ipi_to_irq(unsigned int ipi, unsign= ed int cpu) return irq; } =20 -static int bind_interdomain_evtchn_to_irq_chip(unsigned int remote_domain, +static int bind_interdomain_evtchn_to_irq_chip(struct xenbus_device *dev, evtchn_port_t remote_port, struct irq_chip *chip) { struct evtchn_bind_interdomain bind_interdomain; int err; =20 - bind_interdomain.remote_dom =3D remote_domain; + bind_interdomain.remote_dom =3D dev->otherend_id; bind_interdomain.remote_port =3D remote_port; =20 err =3D HYPERVISOR_event_channel_op(EVTCHNOP_bind_interdomain, &bind_interdomain); =20 return err ? : bind_evtchn_to_irq_chip(bind_interdomain.local_port, - chip); + chip, dev); } =20 -int bind_interdomain_evtchn_to_irq_lateeoi(unsigned int remote_domain, +int bind_interdomain_evtchn_to_irq_lateeoi(struct xenbus_device *dev, evtchn_port_t remote_port) { - return bind_interdomain_evtchn_to_irq_chip(remote_domain, remote_port, + return bind_interdomain_evtchn_to_irq_chip(dev, remote_port, &xen_lateeoi_chip); } EXPORT_SYMBOL_GPL(bind_interdomain_evtchn_to_irq_lateeoi); @@ -1391,7 +1399,7 @@ static int bind_evtchn_to_irqhandler_chip(evtchn_port= _t evtchn, { int irq, retval; =20 - irq =3D bind_evtchn_to_irq_chip(evtchn, chip); + irq =3D bind_evtchn_to_irq_chip(evtchn, chip, NULL); if (irq < 0) return irq; retval =3D request_irq(irq, handler, irqflags, devname, dev_id); @@ -1426,14 +1434,13 @@ int bind_evtchn_to_irqhandler_lateeoi(evtchn_port_t= evtchn, EXPORT_SYMBOL_GPL(bind_evtchn_to_irqhandler_lateeoi); =20 static int bind_interdomain_evtchn_to_irqhandler_chip( - unsigned int remote_domain, evtchn_port_t remote_port, + struct xenbus_device *dev, evtchn_port_t remote_port, irq_handler_t handler, unsigned long irqflags, const char *devname, void *dev_id, struct irq_chip *chip) { int irq, retval; =20 - irq =3D bind_interdomain_evtchn_to_irq_chip(remote_domain, remote_port, - chip); + irq =3D bind_interdomain_evtchn_to_irq_chip(dev, remote_port, chip); if (irq < 0) return irq; =20 @@ -1446,14 +1453,14 @@ static int bind_interdomain_evtchn_to_irqhandler_ch= ip( return irq; } =20 -int bind_interdomain_evtchn_to_irqhandler_lateeoi(unsigned int remote_doma= in, +int bind_interdomain_evtchn_to_irqhandler_lateeoi(struct xenbus_device *de= v, evtchn_port_t remote_port, irq_handler_t handler, unsigned long irqflags, const char *devname, void *dev_id) { - return bind_interdomain_evtchn_to_irqhandler_chip(remote_domain, + return bind_interdomain_evtchn_to_irqhandler_chip(dev, remote_port, handler, irqflags, devname, dev_id, &xen_lateeoi_chip); } @@ -1727,7 +1734,7 @@ void rebind_evtchn_irq(evtchn_port_t evtchn, int irq) so there should be a proper type */ BUG_ON(info->type =3D=3D IRQT_UNBOUND); =20 - (void)xen_irq_info_evtchn_setup(irq, evtchn); + (void)xen_irq_info_evtchn_setup(irq, evtchn, NULL); =20 mutex_unlock(&irq_mapping_update_lock); =20 diff --git a/drivers/xen/pvcalls-back.c b/drivers/xen/pvcalls-back.c index a7d293fa8d14..b47fd8435061 100644 --- a/drivers/xen/pvcalls-back.c +++ b/drivers/xen/pvcalls-back.c @@ -348,7 +348,7 @@ static struct sock_mapping *pvcalls_new_active_socket( map->bytes =3D page; =20 ret =3D bind_interdomain_evtchn_to_irqhandler_lateeoi( - fedata->dev->otherend_id, evtchn, + fedata->dev, evtchn, pvcalls_back_conn_event, 0, "pvcalls-backend", map); if (ret < 0) goto out; @@ -948,7 +948,7 @@ static int backend_connect(struct xenbus_device *dev) goto error; } =20 - err =3D bind_interdomain_evtchn_to_irq_lateeoi(dev->otherend_id, evtchn); + err =3D bind_interdomain_evtchn_to_irq_lateeoi(dev, evtchn); if (err < 0) goto error; fedata->irq =3D err; diff --git a/drivers/xen/xen-pciback/xenbus.c b/drivers/xen/xen-pciback/xen= bus.c index e7c692cfb2cf..5188f02e75fb 100644 --- a/drivers/xen/xen-pciback/xenbus.c +++ b/drivers/xen/xen-pciback/xenbus.c @@ -124,7 +124,7 @@ static int xen_pcibk_do_attach(struct xen_pcibk_device = *pdev, int gnt_ref, pdev->sh_info =3D vaddr; =20 err =3D bind_interdomain_evtchn_to_irqhandler_lateeoi( - pdev->xdev->otherend_id, remote_evtchn, xen_pcibk_handle_event, + pdev->xdev, remote_evtchn, xen_pcibk_handle_event, 0, DRV_NAME, pdev); if (err < 0) { xenbus_dev_fatal(pdev->xdev, err, diff --git a/drivers/xen/xen-scsiback.c b/drivers/xen/xen-scsiback.c index 862162dca33c..8b59897b2df9 100644 --- a/drivers/xen/xen-scsiback.c +++ b/drivers/xen/xen-scsiback.c @@ -799,7 +799,7 @@ static int scsiback_init_sring(struct vscsibk_info *inf= o, grant_ref_t ring_ref, sring =3D (struct vscsiif_sring *)area; BACK_RING_INIT(&info->ring, sring, PAGE_SIZE); =20 - err =3D bind_interdomain_evtchn_to_irq_lateeoi(info->domid, evtchn); + err =3D bind_interdomain_evtchn_to_irq_lateeoi(info->dev, evtchn); if (err < 0) goto unmap_page; =20 diff --git a/include/xen/events.h b/include/xen/events.h index 8ec418e30c7f..c204262d9fc2 100644 --- a/include/xen/events.h +++ b/include/xen/events.h @@ -12,10 +12,11 @@ #include #include =20 +struct xenbus_device; + unsigned xen_evtchn_nr_channels(void); =20 int bind_evtchn_to_irq(evtchn_port_t evtchn); -int bind_evtchn_to_irq_lateeoi(evtchn_port_t evtchn); int bind_evtchn_to_irqhandler(evtchn_port_t evtchn, irq_handler_t handler, unsigned long irqflags, const char *devname, @@ -35,9 +36,9 @@ int bind_ipi_to_irqhandler(enum ipi_vector ipi, unsigned long irqflags, const char *devname, void *dev_id); -int bind_interdomain_evtchn_to_irq_lateeoi(unsigned int remote_domain, +int bind_interdomain_evtchn_to_irq_lateeoi(struct xenbus_device *dev, evtchn_port_t remote_port); -int bind_interdomain_evtchn_to_irqhandler_lateeoi(unsigned int remote_doma= in, +int bind_interdomain_evtchn_to_irqhandler_lateeoi(struct xenbus_device *de= v, evtchn_port_t remote_port, irq_handler_t handler, unsigned long irqflags, --=20 2.26.2 From nobody Sun May 5 02:16:31 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1613749277; cv=none; d=zohomail.com; s=zohoarc; b=hpuu2FvU8/4iivCFWhVKGS1k5j7fFN1adAF8WbPbVKv6hvF+LQ2JvbUu7UD+USXNhUNauNryVtw1+owG5x4C8oDNBuyZedRpixXCBOO8F0QLc1LC53ElD53a5UlBRyBFLXYHJ7qRqarVjO8wOnAtk0OFcj51lSNaobqpgX9gFq8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1613749277; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=6VpM+WfMANjvkY5w7Gc3UZ8tT64NvTb2gpQ7A/fT8ao=; b=JdU+eEE7JgyLxFqvyXRR0b6WhsSr3YyyNGd3idHyxYr+MiKJMzLQHTeYYcgYty5sZbu9vaks8q1h8wWHrGZAtlxEFXkm716y2JFj5s/+GX3TkbODg+r+tcjkqt6M5UaeHlnNq+MYJeNJCS8U9FYIyghV13Io34EaYg8EgK3Qw18= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1613749277502788.0224641859149; Fri, 19 Feb 2021 07:41:17 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.86938.163636 (Exim 4.92) (envelope-from ) id 1lD7tt-0002im-VX; Fri, 19 Feb 2021 15:41:01 +0000 Received: by outflank-mailman (output) from mailman id 86938.163636; Fri, 19 Feb 2021 15:41:01 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lD7tt-0002ic-P4; Fri, 19 Feb 2021 15:41:01 +0000 Received: by outflank-mailman (input) for mailman id 86938; Fri, 19 Feb 2021 15:41:00 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lD7tr-0002F6-VV for xen-devel@lists.xenproject.org; Fri, 19 Feb 2021 15:41:00 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id a996cdc6-4437-4d1d-ac26-0ef392d6b9b6; Fri, 19 Feb 2021 15:40:40 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 5717EB113; Fri, 19 Feb 2021 15:40:39 +0000 (UTC) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: a996cdc6-4437-4d1d-ac26-0ef392d6b9b6 X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1613749239; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6VpM+WfMANjvkY5w7Gc3UZ8tT64NvTb2gpQ7A/fT8ao=; b=bvKz+jSrLdLNwd5s+FG6C4BKp/wBnu2wr9z2vfOmJ6cWicKe/y0A5AFof5tF2XSXaFqiWW wO5XbI53YJWxw5Mq1h/yWAjyLBJuRNB4rFCHFn0z4tXncQ8Ffjp+CHP9IvO92IAYAT7bOS h1XcIapQO8Q1rwbguFV1CFoIGtsMR30= From: Juergen Gross To: xen-devel@lists.xenproject.org, linux-kernel@vger.kernel.org Cc: Juergen Gross , Boris Ostrovsky , Stefano Stabellini Subject: [PATCH v3 6/8] xen/events: add per-xenbus device event statistics and settings Date: Fri, 19 Feb 2021 16:40:28 +0100 Message-Id: <20210219154030.10892-7-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210219154030.10892-1-jgross@suse.com> References: <20210219154030.10892-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) Content-Type: text/plain; charset="utf-8" Add syfs nodes for each xenbus device showing event statistics (number of events and spurious events, number of associated event channels) and for setting a spurious event threshold in case a frontend is sending too many events without being rogue on purpose. Signed-off-by: Juergen Gross Reviewed-by: Boris Ostrovsky --- V2: - add documentation (Boris Ostrovsky) --- .../ABI/testing/sysfs-devices-xenbus | 41 ++++++++++++ drivers/xen/events/events_base.c | 27 +++++++- drivers/xen/xenbus/xenbus_probe.c | 66 +++++++++++++++++++ include/xen/xenbus.h | 7 ++ 4 files changed, 139 insertions(+), 2 deletions(-) create mode 100644 Documentation/ABI/testing/sysfs-devices-xenbus diff --git a/Documentation/ABI/testing/sysfs-devices-xenbus b/Documentation= /ABI/testing/sysfs-devices-xenbus new file mode 100644 index 000000000000..fd796cb4f315 --- /dev/null +++ b/Documentation/ABI/testing/sysfs-devices-xenbus @@ -0,0 +1,41 @@ +What: /sys/devices/*/xenbus/event_channels +Date: February 2021 +Contact: Xen Developers mailing list +Description: + Number of Xen event channels associated with a kernel based + paravirtualized device frontend or backend. + +What: /sys/devices/*/xenbus/events +Date: February 2021 +Contact: Xen Developers mailing list +Description: + Total number of Xen events received for a Xen pv device + frontend or backend. + +What: /sys/devices/*/xenbus/jiffies_eoi_delayed +Date: February 2021 +Contact: Xen Developers mailing list +Description: + Summed up time in jiffies the EOI of an interrupt for a Xen + pv device has been delayed in order to avoid stalls due to + event storms. This value rising is a first sign for a rogue + other end of the pv device. + +What: /sys/devices/*/xenbus/spurious_events +Date: February 2021 +Contact: Xen Developers mailing list +Description: + Number of events received for a Xen pv device which did not + require any action. Too many spurious events in a row will + trigger delayed EOI processing. + +What: /sys/devices/*/xenbus/spurious_threshold +Date: February 2021 +Contact: Xen Developers mailing list +Description: + Controls the tolerated number of subsequent spurious events + before delayed EOI processing is triggered for a Xen pv + device. Default is 1. This can be modified in case the other + end of the pv device is issuing spurious events on a regular + basis and is known not to be malicious on purpose. Raising + the value for such cases can improve pv device performance. diff --git a/drivers/xen/events/events_base.c b/drivers/xen/events/events_b= ase.c index b60df189ecbc..a3636fb03417 100644 --- a/drivers/xen/events/events_base.c +++ b/drivers/xen/events/events_base.c @@ -332,6 +332,8 @@ static int xen_irq_info_evtchn_setup(unsigned irq, =20 ret =3D xen_irq_info_common_setup(info, irq, IRQT_EVTCHN, evtchn, 0); info->u.interdomain =3D dev; + if (dev) + atomic_inc(&dev->event_channels); =20 return ret; } @@ -606,18 +608,28 @@ static void xen_irq_lateeoi_locked(struct irq_info *i= nfo, bool spurious) return; =20 if (spurious) { + struct xenbus_device *dev =3D info->u.interdomain; + unsigned int threshold =3D 1; + + if (dev && dev->spurious_threshold) + threshold =3D dev->spurious_threshold; + if ((1 << info->spurious_cnt) < (HZ << 2)) { if (info->spurious_cnt !=3D 0xFF) info->spurious_cnt++; } - if (info->spurious_cnt > 1) { - delay =3D 1 << (info->spurious_cnt - 2); + if (info->spurious_cnt > threshold) { + delay =3D 1 << (info->spurious_cnt - 1 - threshold); if (delay > HZ) delay =3D HZ; if (!info->eoi_time) info->eoi_cpu =3D smp_processor_id(); info->eoi_time =3D get_jiffies_64() + delay; + if (dev) + atomic_add(delay, &dev->jiffies_eoi_delayed); } + if (dev) + atomic_inc(&dev->spurious_events); } else { info->spurious_cnt =3D 0; } @@ -954,6 +966,7 @@ static void __unbind_from_irq(unsigned int irq) =20 if (VALID_EVTCHN(evtchn)) { unsigned int cpu =3D cpu_from_irq(irq); + struct xenbus_device *dev; =20 xen_evtchn_close(evtchn); =20 @@ -964,6 +977,11 @@ static void __unbind_from_irq(unsigned int irq) case IRQT_IPI: per_cpu(ipi_to_irq, cpu)[ipi_from_irq(irq)] =3D -1; break; + case IRQT_EVTCHN: + dev =3D info->u.interdomain; + if (dev) + atomic_dec(&dev->event_channels); + break; default: break; } @@ -1627,6 +1645,7 @@ void handle_irq_for_port(evtchn_port_t port, struct e= vtchn_loop_ctrl *ctrl) { int irq; struct irq_info *info; + struct xenbus_device *dev; =20 irq =3D get_evtchn_to_irq(port); if (irq =3D=3D -1) @@ -1658,6 +1677,10 @@ void handle_irq_for_port(evtchn_port_t port, struct = evtchn_loop_ctrl *ctrl) if (xchg_acquire(&info->is_active, 1)) return; =20 + dev =3D (info->type =3D=3D IRQT_EVTCHN) ? info->u.interdomain : NULL; + if (dev) + atomic_inc(&dev->events); + if (ctrl->defer_eoi) { info->eoi_cpu =3D smp_processor_id(); info->irq_epoch =3D __this_cpu_read(irq_epoch); diff --git a/drivers/xen/xenbus/xenbus_probe.c b/drivers/xen/xenbus/xenbus_= probe.c index 8a75092bb148..97f0d234482d 100644 --- a/drivers/xen/xenbus/xenbus_probe.c +++ b/drivers/xen/xenbus/xenbus_probe.c @@ -206,6 +206,65 @@ void xenbus_otherend_changed(struct xenbus_watch *watc= h, } EXPORT_SYMBOL_GPL(xenbus_otherend_changed); =20 +#define XENBUS_SHOW_STAT(name) \ +static ssize_t show_##name(struct device *_dev, \ + struct device_attribute *attr, \ + char *buf) \ +{ \ + struct xenbus_device *dev =3D to_xenbus_device(_dev); \ + \ + return sprintf(buf, "%d\n", atomic_read(&dev->name)); \ +} \ +static DEVICE_ATTR(name, 0444, show_##name, NULL) + +XENBUS_SHOW_STAT(event_channels); +XENBUS_SHOW_STAT(events); +XENBUS_SHOW_STAT(spurious_events); +XENBUS_SHOW_STAT(jiffies_eoi_delayed); + +static ssize_t show_spurious_threshold(struct device *_dev, + struct device_attribute *attr, + char *buf) +{ + struct xenbus_device *dev =3D to_xenbus_device(_dev); + + return sprintf(buf, "%d\n", dev->spurious_threshold); +} + +static ssize_t set_spurious_threshold(struct device *_dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + struct xenbus_device *dev =3D to_xenbus_device(_dev); + unsigned int val; + ssize_t ret; + + ret =3D kstrtouint(buf, 0, &val); + if (ret) + return ret; + + dev->spurious_threshold =3D val; + + return count; +} + +static DEVICE_ATTR(spurious_threshold, 0644, show_spurious_threshold, + set_spurious_threshold); + +static struct attribute *xenbus_attrs[] =3D { + &dev_attr_event_channels.attr, + &dev_attr_events.attr, + &dev_attr_spurious_events.attr, + &dev_attr_jiffies_eoi_delayed.attr, + &dev_attr_spurious_threshold.attr, + NULL +}; + +static const struct attribute_group xenbus_group =3D { + .name =3D "xenbus", + .attrs =3D xenbus_attrs, +}; + int xenbus_dev_probe(struct device *_dev) { struct xenbus_device *dev =3D to_xenbus_device(_dev); @@ -253,6 +312,11 @@ int xenbus_dev_probe(struct device *_dev) return err; } =20 + dev->spurious_threshold =3D 1; + if (sysfs_create_group(&dev->dev.kobj, &xenbus_group)) + dev_warn(&dev->dev, "sysfs_create_group on %s failed.\n", + dev->nodename); + return 0; fail_put: module_put(drv->driver.owner); @@ -269,6 +333,8 @@ int xenbus_dev_remove(struct device *_dev) =20 DPRINTK("%s", dev->nodename); =20 + sysfs_remove_group(&dev->dev.kobj, &xenbus_group); + free_otherend_watch(dev); =20 if (drv->remove) { diff --git a/include/xen/xenbus.h b/include/xen/xenbus.h index bf3cfc7c35d0..0b1386073d49 100644 --- a/include/xen/xenbus.h +++ b/include/xen/xenbus.h @@ -88,6 +88,13 @@ struct xenbus_device { struct completion down; struct work_struct work; struct semaphore reclaim_sem; + + /* Event channel based statistics and settings. */ + atomic_t event_channels; + atomic_t events; + atomic_t spurious_events; + atomic_t jiffies_eoi_delayed; + unsigned int spurious_threshold; }; =20 static inline struct xenbus_device *to_xenbus_device(struct device *dev) --=20 2.26.2 From nobody Sun May 5 02:16:31 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1613749266; cv=none; d=zohomail.com; s=zohoarc; b=oEzZmLgoXEoRd/602XbecctOl+TWhB8m9HUeubKvqZ4Cf10116FiGwIwc+/zd8M8eJ43DEL9WSPa75yAzT5NSfwZ5f4sr1R0fixnK94zajWx2RH0Rnis6ShWhLgQdedRCmdrNh1pukOTNrozE+YMVd4TF8zxAe2TjWPqb85EN7o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1613749266; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=nYiBLOOS0jKaGXZR/xdp5WHTi+5sOW1v2m88NDrZNbI=; b=U5ltbnW4z37Otz7ULsTFJqmG64Cy2I43A2HJdZzl8rcsCFA6uwY63vfnSdI/bFa0aAUR0F9/W73risuh+AFo0CECEfznLwotY2428t7xI17vZR+IWTvo2yZ4W+xHELUo4nIvzG9UGPwNJYrG+fOp/Q2fxt2oI/b9Ks7FR/bFLwg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1613749265775821.199198147273; Fri, 19 Feb 2021 07:41:05 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.86935.163595 (Exim 4.92) (envelope-from ) id 1lD7tk-0002R3-FH; Fri, 19 Feb 2021 15:40:52 +0000 Received: by outflank-mailman (output) from mailman id 86935.163595; Fri, 19 Feb 2021 15:40:52 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lD7tk-0002Qo-7w; Fri, 19 Feb 2021 15:40:52 +0000 Received: by outflank-mailman (input) for mailman id 86935; Fri, 19 Feb 2021 15:40:50 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lD7th-0002F7-Vq for xen-devel@lists.xenproject.org; Fri, 19 Feb 2021 15:40:50 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 17195ed2-3ee0-4ae2-ad36-57118e02a687; Fri, 19 Feb 2021 15:40:40 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 8FC36B114; Fri, 19 Feb 2021 15:40:39 +0000 (UTC) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 17195ed2-3ee0-4ae2-ad36-57118e02a687 X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1613749239; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=nYiBLOOS0jKaGXZR/xdp5WHTi+5sOW1v2m88NDrZNbI=; b=mqlyaLZe/YgvYSsQIvPpN9XoaMOuiHW3Pbur9d3Wz3NOMHY4Oy4s66u3aQWq9fxarixX/O Ey3afn8U9k0KK6JKqUCXGc1zWME5EppFL1W/JOkfTp3ilVzkPrWMZUrxql+Y+EqqtO2aWl dpSxPChifLttkm90i7WQkWP8NL1KFr4= From: Juergen Gross To: xen-devel@lists.xenproject.org, linux-kernel@vger.kernel.org Cc: Juergen Gross , Boris Ostrovsky , Stefano Stabellini , Andrew Cooper , Jan Beulich Subject: [PATCH v3 7/8] xen/evtchn: use smp barriers for user event ring Date: Fri, 19 Feb 2021 16:40:29 +0100 Message-Id: <20210219154030.10892-8-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210219154030.10892-1-jgross@suse.com> References: <20210219154030.10892-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) Content-Type: text/plain; charset="utf-8" The ring buffer for user events is local to the given kernel instance, so smp barriers are fine for ensuring consistency. Reported-by: Andrew Cooper Signed-off-by: Juergen Gross Reviewed-by: Jan Beulich --- drivers/xen/evtchn.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/xen/evtchn.c b/drivers/xen/evtchn.c index a7a85719a8c8..421382c73d88 100644 --- a/drivers/xen/evtchn.c +++ b/drivers/xen/evtchn.c @@ -173,7 +173,7 @@ static irqreturn_t evtchn_interrupt(int irq, void *data) =20 if ((u->ring_prod - u->ring_cons) < u->ring_size) { *evtchn_ring_entry(u, u->ring_prod) =3D evtchn->port; - wmb(); /* Ensure ring contents visible */ + smp_wmb(); /* Ensure ring contents visible */ if (u->ring_cons =3D=3D u->ring_prod++) { wake_up_interruptible(&u->evtchn_wait); kill_fasync(&u->evtchn_async_queue, @@ -245,7 +245,7 @@ static ssize_t evtchn_read(struct file *file, char __us= er *buf, } =20 rc =3D -EFAULT; - rmb(); /* Ensure that we see the port before we copy it. */ + smp_rmb(); /* Ensure that we see the port before we copy it. */ if (copy_to_user(buf, evtchn_ring_entry(u, c), bytes1) || ((bytes2 !=3D 0) && copy_to_user(&buf[bytes1], &u->ring[0], bytes2))) --=20 2.26.2 From nobody Sun May 5 02:16:31 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1613749271; cv=none; d=zohomail.com; s=zohoarc; b=mrO+BFve5ZmRZHg59yv+9tYuy2ymwVKau/gPLdA/O/nZN7cAFxKDjDe4QMxzPwSyJ5YBJ+zjQPvSMWbzhNKZB9VejzonRt4ZFCss2PxnhB572JXILil0VGHAgPjVGPy1vRo/dQaj9ueWQjLKqmUfAGsb2HSB05b9Uw+D6uwhSzw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1613749271; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=dflticAMbc09PwXAGDjeFedypgLhrYxdjLRQqHKEDDU=; b=iCbfGQVxYbrkZMHwYsQYSGwJAlTSd23JAnmRudByyoKl7m4pGngRof8BaL54gRM5Tb2Df9hs7t3UfN1mJpBpR3qOCsr4BV9Mh/zBzGXSTssMgma8WEg8mcgrnEAdUYlygmhcPRKG1NY1NURPXlI9THjncdVMTxf/85muxF6mCLc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1613749271411807.2762192034783; Fri, 19 Feb 2021 07:41:11 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.86936.163612 (Exim 4.92) (envelope-from ) id 1lD7tp-0002a4-7M; Fri, 19 Feb 2021 15:40:57 +0000 Received: by outflank-mailman (output) from mailman id 86936.163612; Fri, 19 Feb 2021 15:40:57 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lD7tp-0002Zr-1Q; Fri, 19 Feb 2021 15:40:57 +0000 Received: by outflank-mailman (input) for mailman id 86936; Fri, 19 Feb 2021 15:40:55 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lD7tm-0002F6-VW for xen-devel@lists.xenproject.org; Fri, 19 Feb 2021 15:40:55 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id d4088ab8-1c64-409b-ae27-ad1bf24d0844; Fri, 19 Feb 2021 15:40:40 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id B65E9B115; Fri, 19 Feb 2021 15:40:39 +0000 (UTC) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: d4088ab8-1c64-409b-ae27-ad1bf24d0844 X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1613749239; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dflticAMbc09PwXAGDjeFedypgLhrYxdjLRQqHKEDDU=; b=cAj/RR/Np2Vu9mTDqZssOVj4+tOadc3EcJK5OUtUYHgAsHlAkUaM7EnBllZPfqdGIbJiFN EixYe2DRhOopG/yuDiYRwWsU8do5usxDeCMFtoxvVAkcN6xMoINQmWwvZIObrIh6jbFbvN GI/e8gT4izrCIcwyQ6tiv+FG6FYEIsA= From: Juergen Gross To: xen-devel@lists.xenproject.org, linux-kernel@vger.kernel.org Cc: Juergen Gross , Boris Ostrovsky , Stefano Stabellini Subject: [PATCH v3 8/8] xen/evtchn: use READ/WRITE_ONCE() for accessing ring indices Date: Fri, 19 Feb 2021 16:40:30 +0100 Message-Id: <20210219154030.10892-9-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210219154030.10892-1-jgross@suse.com> References: <20210219154030.10892-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) Content-Type: text/plain; charset="utf-8" For avoiding read- and write-tearing by the compiler use READ_ONCE() and WRITE_ONCE() for accessing the ring indices in evtchn.c. Signed-off-by: Juergen Gross Reviewed-by: Boris Ostrovsky --- V2: - modify all accesses (Julien Grall) V3: - fix incrementing producer index (Ross Lagerwall) --- drivers/xen/evtchn.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/drivers/xen/evtchn.c b/drivers/xen/evtchn.c index 421382c73d88..c99415a70051 100644 --- a/drivers/xen/evtchn.c +++ b/drivers/xen/evtchn.c @@ -162,6 +162,7 @@ static irqreturn_t evtchn_interrupt(int irq, void *data) { struct user_evtchn *evtchn =3D data; struct per_user_data *u =3D evtchn->user; + unsigned int prod, cons; =20 WARN(!evtchn->enabled, "Interrupt for port %u, but apparently not enabled; per-user %p\n", @@ -171,10 +172,14 @@ static irqreturn_t evtchn_interrupt(int irq, void *da= ta) =20 spin_lock(&u->ring_prod_lock); =20 - if ((u->ring_prod - u->ring_cons) < u->ring_size) { - *evtchn_ring_entry(u, u->ring_prod) =3D evtchn->port; + prod =3D READ_ONCE(u->ring_prod); + cons =3D READ_ONCE(u->ring_cons); + + if ((prod - cons) < u->ring_size) { + *evtchn_ring_entry(u, prod) =3D evtchn->port; smp_wmb(); /* Ensure ring contents visible */ - if (u->ring_cons =3D=3D u->ring_prod++) { + WRITE_ONCE(u->ring_prod, prod + 1); + if (cons =3D=3D prod) { wake_up_interruptible(&u->evtchn_wait); kill_fasync(&u->evtchn_async_queue, SIGIO, POLL_IN); @@ -210,8 +215,8 @@ static ssize_t evtchn_read(struct file *file, char __us= er *buf, if (u->ring_overflow) goto unlock_out; =20 - c =3D u->ring_cons; - p =3D u->ring_prod; + c =3D READ_ONCE(u->ring_cons); + p =3D READ_ONCE(u->ring_prod); if (c !=3D p) break; =20 @@ -221,7 +226,7 @@ static ssize_t evtchn_read(struct file *file, char __us= er *buf, return -EAGAIN; =20 rc =3D wait_event_interruptible(u->evtchn_wait, - u->ring_cons !=3D u->ring_prod); + READ_ONCE(u->ring_cons) !=3D READ_ONCE(u->ring_prod)); if (rc) return rc; } @@ -251,7 +256,7 @@ static ssize_t evtchn_read(struct file *file, char __us= er *buf, copy_to_user(&buf[bytes1], &u->ring[0], bytes2))) goto unlock_out; =20 - u->ring_cons +=3D (bytes1 + bytes2) / sizeof(evtchn_port_t); + WRITE_ONCE(u->ring_cons, c + (bytes1 + bytes2) / sizeof(evtchn_port_t)); rc =3D bytes1 + bytes2; =20 unlock_out: @@ -552,7 +557,9 @@ static long evtchn_ioctl(struct file *file, /* Initialise the ring to empty. Clear errors. */ mutex_lock(&u->ring_cons_mutex); spin_lock_irq(&u->ring_prod_lock); - u->ring_cons =3D u->ring_prod =3D u->ring_overflow =3D 0; + WRITE_ONCE(u->ring_cons, 0); + WRITE_ONCE(u->ring_prod, 0); + u->ring_overflow =3D 0; spin_unlock_irq(&u->ring_prod_lock); mutex_unlock(&u->ring_cons_mutex); rc =3D 0; @@ -595,7 +602,7 @@ static __poll_t evtchn_poll(struct file *file, poll_tab= le *wait) struct per_user_data *u =3D file->private_data; =20 poll_wait(file, &u->evtchn_wait, wait); - if (u->ring_cons !=3D u->ring_prod) + if (READ_ONCE(u->ring_cons) !=3D READ_ONCE(u->ring_prod)) mask |=3D EPOLLIN | EPOLLRDNORM; if (u->ring_overflow) mask =3D EPOLLERR; --=20 2.26.2