From nobody Sat May 4 02:44:40 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=1613038687; cv=none; d=zohomail.com; s=zohoarc; b=nU/xFHYaZfKjnb0TOfdlppxctZS3vAxb2BMhNmJxsuPj2vpiaQg3J0VBLJXv9A2ONSfwb06LkSEcKIZW+OV0IGQ65UqYb++o/DhiuByTculhxcD2RymvBohDUAFZGPdJzUjnIyq1qrmbrYasne55OEjeJLHHqjYvsqIjHlGJHLc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1613038687; 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=EdBaXbPjwuisXp+wA3ceCVG/oi9M98Y6TOFrfwWaHa8=; b=ZhyoGpo/MeEKObVtyVWXiNxbpvnoTDbYSaSMmRTqKaej08XHOZS6twJ94EB237MsdbTWX5dU742zmodIqW2GZekrp56rpRoaXHrebjPG07QL9sIoqZuN+SCAxJauZOeW9yo24Qa5+hilTMKwQil8C9JmzukWpvhFuUEUUcFiRpw= 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 1613038687457230.21354157540202; Thu, 11 Feb 2021 02:18:07 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.83797.156817 (Exim 4.92) (envelope-from ) id 1lA92i-0001ZV-Ul; Thu, 11 Feb 2021 10:17:48 +0000 Received: by outflank-mailman (output) from mailman id 83797.156817; Thu, 11 Feb 2021 10:17:48 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lA92i-0001ZF-M8; Thu, 11 Feb 2021 10:17:48 +0000 Received: by outflank-mailman (input) for mailman id 83797; Thu, 11 Feb 2021 10:17:47 +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 1lA92h-0001VI-7o for xen-devel@lists.xenproject.org; Thu, 11 Feb 2021 10:17:47 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 0feffe05-2a7d-4ce3-8742-72cb4290f884; Thu, 11 Feb 2021 10:17:41 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 2F592ADE3; Thu, 11 Feb 2021 10:17:40 +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: 0feffe05-2a7d-4ce3-8742-72cb4290f884 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=1613038660; 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=EdBaXbPjwuisXp+wA3ceCVG/oi9M98Y6TOFrfwWaHa8=; b=Hxp5lciP0+R7TqImPb1Oi0mOF1Kt4gS8HSFGF77fTX3A5UvKadVDgCggHJxuXESqpwWZlr XXEY8jwagjCeQ20jMrUsdk4x8278lK28+Vn5MRXaJ8eeZdMTvVfKWMeL9iXotkOhz7jmpw qiiDgnuNfHNzpjoj4iJqFS4N6cnFV8w= 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 v2 1/8] xen/events: reset affinity of 2-level event when tearing it down Date: Thu, 11 Feb 2021 11:16:09 +0100 Message-Id: <20210211101616.13788-2-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210211101616.13788-1-jgross@suse.com> References: <20210211101616.13788-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 Sat May 4 02:44:40 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=1613038688; cv=none; d=zohomail.com; s=zohoarc; b=Vu175c5e1PsjZfhuzSJ9DYJ4cBAGQdyvvpAf+7q2MyeefMRNrMN23XRcYRM5q0CvxbsI8WdjH2dPHNoJs0PBkP9ZTVATrN9MRe80rH22Bdp7ILcm0AL5Sceq6PxeEmawb+iE+xkdFRrF0vnbJtQxIomDzxFQmvE73TJvy4QaoEA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1613038688; 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=HEEw8iLlJTo+Mbgy6leJfOc3B11dwWPLWfDt8dTcsoaW/c+Dqt4WjV1tLfFZdFp5hMqU1Oc6uvC20ryXMtEtIWSmSW3M0bzHiYN6pi7GSPx0B79KaghzhqtcfPDnOdnVsg7gk1UfTv+i25B22grz9uR3OkxQG2rbz8MS1aB/2rQ= 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 1613038687910269.2711504961637; Thu, 11 Feb 2021 02:18:07 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.83796.156811 (Exim 4.92) (envelope-from ) id 1lA92i-0001Yo-Ft; Thu, 11 Feb 2021 10:17:48 +0000 Received: by outflank-mailman (output) from mailman id 83796.156811; Thu, 11 Feb 2021 10:17:48 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lA92i-0001Yh-CM; Thu, 11 Feb 2021 10:17:48 +0000 Received: by outflank-mailman (input) for mailman id 83796; Thu, 11 Feb 2021 10:17:46 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lA92g-0001Uu-Nr for xen-devel@lists.xenproject.org; Thu, 11 Feb 2021 10:17:46 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 7325ca90-66f4-46d3-8126-5d42ffe92f14; Thu, 11 Feb 2021 10:17:41 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 42709AEE5; Thu, 11 Feb 2021 10:17:40 +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: 7325ca90-66f4-46d3-8126-5d42ffe92f14 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=1613038660; 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=f6mXAjuRCbzMf35BDEDWXTNA6DVlLvcAIChLY3m7jKJkXro1baLzQOjC1iXUb5JEebuLeO 4+UyZ9/AnZQmz8mMOePJZBkC4fy2koCnhIu4EXJOm3Z8yb46lYhgyNtHTuCxtQyUJtcSRC WDmMJJ57vhgngsOi6bgwDZnZNFSiNVs= 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 v2 2/8] xen/events: don't unmask an event channel when an eoi is pending Date: Thu, 11 Feb 2021 11:16:10 +0100 Message-Id: <20210211101616.13788-3-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210211101616.13788-1-jgross@suse.com> References: <20210211101616.13788-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 --- 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 Sat May 4 02:44:40 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=1613038687; cv=none; d=zohomail.com; s=zohoarc; b=J0eCn4DsS/3lEy2MlIJIVNlvk1aRu4n8AcEcCFYetattl9jjlCXKJ7dxPayu1zxk3QCSedQS38KdXwXCHWtG2dwaNRZjjg7XEft5K4GyBIc2K6t9yAhsHl97BTW1L6Z0WWAdndNgb8wnhvhMXYTPgqmXn0h3aWVFdAXczrtxm3A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1613038687; 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=p4KSkF0c5fU4qCPg8or+1uqqop6uTe4bYlvvnGDRxWY=; b=IY7zb5Lrnu7a/wuJoXtLX5teslfUCKJhm+2mkcsLH4VezEb8SNad/KL06aNHm+XQnNOPeeoV+a0sqBPCYt/u455dYzBYbVTB0rbcFlDaF1eRC+/ians4GkLd9qXdom2gw4NknMq9UAlNWRfmcqvKyJiDSyPnnC/NrWutyw9CMN0= 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 161303868753689.56455094739863; Thu, 11 Feb 2021 02:18:07 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.83795.156799 (Exim 4.92) (envelope-from ) id 1lA92e-0001WM-6n; Thu, 11 Feb 2021 10:17:44 +0000 Received: by outflank-mailman (output) from mailman id 83795.156799; Thu, 11 Feb 2021 10:17:44 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lA92e-0001WF-3O; Thu, 11 Feb 2021 10:17:44 +0000 Received: by outflank-mailman (input) for mailman id 83795; Thu, 11 Feb 2021 10:17:42 +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 1lA92c-0001VI-FC for xen-devel@lists.xenproject.org; Thu, 11 Feb 2021 10:17:42 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 3863bdfc-b802-4643-845d-1182e4a74dc7; Thu, 11 Feb 2021 10:17:41 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 6C4EBAEE6; Thu, 11 Feb 2021 10:17:40 +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: 3863bdfc-b802-4643-845d-1182e4a74dc7 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=1613038660; 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=p4KSkF0c5fU4qCPg8or+1uqqop6uTe4bYlvvnGDRxWY=; b=DivHVvXIK3d+2H8s2mJSXlaS/ID6mGaFcAur+N//M0KKelVsACyazfqTdU4OBJdNvQbyLH gkM2KGQRRMZzRO4po/06SU5P4EBCoFB8pFlh44T9iVqutpsjQ14Y2is+xeZcc8XjsMhUbm QwWpkI3/YayYR7YxkZ8FR36tCXSQ7i4= From: Juergen Gross To: xen-devel@lists.xenproject.org, linux-kernel@vger.kernel.org Cc: Juergen Gross , Boris Ostrovsky , Stefano Stabellini , Julien Grall Subject: [PATCH v2 3/8] xen/events: avoid handling the same event on two cpus at the same time Date: Thu, 11 Feb 2021 11:16:11 +0100 Message-Id: <20210211101616.13788-4-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210211101616.13788-1-jgross@suse.com> References: <20210211101616.13788-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. 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_b= ase.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 *inf= o, bool spurious) } =20 info->eoi_time =3D 0; + smp_store_release(&info->is_active, 0); do_unmask(info, EVT_MASK_REASON_EOI_PENDING); } =20 @@ -809,13 +811,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 + smp_store_release(&info->is_active, 0); clear_evtchn(evtchn); =20 if (pirq_needs_eoi(data->irq)) { @@ -1640,6 +1644,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,11 +1829,13 @@ 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); + 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; =20 + smp_store_release(&info->is_active, 0); clear_evtchn(evtchn); } =20 @@ -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 =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)) + 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) --=20 2.26.2 From nobody Sat May 4 02:44:40 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=1613038687; cv=none; d=zohomail.com; s=zohoarc; b=dI0UB9KgLg0sPy9L6LP2OGmyfnWZRwZE6jvJb4d6rvEdXes9NOkP0TUG4BuAyG9mRoD4uoi5b7NSULadkzpfH6+i8hlC5WipRaoisHVQiLqTkbDFpXBAZukugugT0dExLeekoi7JYoHiAXPG42VT4ORJtD7P9NIREjn/W1V97pk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1613038687; 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=Rhogk/kmOD28gajRsMGG1ocHU7evgTnTuSlQWFIoQW8=; b=ed+erh2adq+zQ3VMb8TLYbAR0Alz1Qh4SFBkGjaJspz84CTAPGq1d1DqszoKFkYuXnlriAKIiR//AY5TA3oXQj+0M1f8VTh5YMhIBVs0lOAjd3qYEbzvIs5vqczJUsR39ukhuCMsyUjjoV0SklbNWAFiUbiGn48ZB4gv05croEs= 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 1613038687424346.7127804399149; Thu, 11 Feb 2021 02:18:07 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.83799.156840 (Exim 4.92) (envelope-from ) id 1lA92n-0001gG-Ki; Thu, 11 Feb 2021 10:17:53 +0000 Received: by outflank-mailman (output) from mailman id 83799.156840; Thu, 11 Feb 2021 10:17:53 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lA92n-0001fu-BQ; Thu, 11 Feb 2021 10:17:53 +0000 Received: by outflank-mailman (input) for mailman id 83799; Thu, 11 Feb 2021 10:17:52 +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 1lA92m-0001VI-7p for xen-devel@lists.xenproject.org; Thu, 11 Feb 2021 10:17:52 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id d9b06e69-c918-459a-a5f1-acebf056e50c; Thu, 11 Feb 2021 10:17:41 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id ACC86AF0F; Thu, 11 Feb 2021 10:17:40 +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: d9b06e69-c918-459a-a5f1-acebf056e50c 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=1613038660; 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=Rhogk/kmOD28gajRsMGG1ocHU7evgTnTuSlQWFIoQW8=; b=on0/DGg+97nD1nkvxkD4VEqz3oR9LkeQaHrptcUN0K8YljfnjFg68saLoRag5dRxWts5xM gcYtqhCRJfyj1qxrUcVplOvFvSQTRp245Dkbp+hx1i7zitTFMX0alfy6CbM8J1j2ZIVT3N SkPqcYJ4CUuD45OjfSfrPTh+cYiLMW0= 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 Subject: [PATCH v2 4/8] xen/netback: fix spurious event detection for common event case Date: Thu, 11 Feb 2021 11:16:12 +0100 Message-Id: <20210211101616.13788-5-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210211101616.13788-1-jgross@suse.com> References: <20210211101616.13788-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. 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 Sat May 4 02:44:40 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=1613038704; cv=none; d=zohomail.com; s=zohoarc; b=IrWca8+A0JuonaMtTWyJQskPpfNkCV7/lrT2BhqiPZW3Bdy4wo0c9/GNxaCCOMwaH2mQz85qPJF2zItZIS0fLumw0fAkefXluUVjOsLP/nrhQPpZ/r1t9fNn95bwigNDeb3uXR0Vp7g/i7wsGCmR2CsvTDcfNOn3tTCabSD52pA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1613038704; 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=GuZoq58aOVo3oObGxElFNA6Kt6uHHJGIx8cU5W0ZP10=; b=fqbwQb5TZ5KtE5ehj+oaZFpaE5pp+3nmnEbphyR3+4Y9BcQkS1iN0SAwgO6+cWsgIJlu5xGF5agkjyI1Qp4cHVrRaBJtjUQ4HQLM6XuXx5yDbO95PlkiTF7qIGjzfs1GM+zvqNttLq1I7Yp3vkzYbJMr9O563uW44Vel5xw3z6s= 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 1613038703678283.9945852403124; Thu, 11 Feb 2021 02:18:23 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.83802.156883 (Exim 4.92) (envelope-from ) id 1lA932-000234-1L; Thu, 11 Feb 2021 10:18:08 +0000 Received: by outflank-mailman (output) from mailman id 83802.156883; Thu, 11 Feb 2021 10:18:07 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lA931-00022r-QU; Thu, 11 Feb 2021 10:18:07 +0000 Received: by outflank-mailman (input) for mailman id 83802; Thu, 11 Feb 2021 10:18:07 +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 1lA931-0001VI-8G for xen-devel@lists.xenproject.org; Thu, 11 Feb 2021 10:18:07 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 09455c06-ebbd-40b2-89ca-328d4c41e203; Thu, 11 Feb 2021 10:17:42 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 15E18AF10; Thu, 11 Feb 2021 10:17:41 +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: 09455c06-ebbd-40b2-89ca-328d4c41e203 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=1613038661; 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=GuZoq58aOVo3oObGxElFNA6Kt6uHHJGIx8cU5W0ZP10=; b=pkhP3Lm6mYei0SahyUSTm/T2kQz6sZJb4OOfYj17bDA4br/IXuvFtdkIqsVKGzyShv5OAu d2jT8J1SIJXORUUW+PIgw04KHUOaCD+hJsA+vIGj4gqWcvMkTnOKQA1VjrHXTh++V8bUVG uSR2A9MHYHVSyHQrz3LZL1TxHbdjHfI= 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 v2 5/8] xen/events: link interdomain events to associated xenbus device Date: Thu, 11 Feb 2021 11:16:13 +0100 Message-Id: <20210211101616.13788-6-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210211101616.13788-1-jgross@suse.com> References: <20210211101616.13788-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 --- 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 f7e22330dcef..a5cce4c626c2 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, @@ -1158,7 +1165,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; @@ -1178,7 +1186,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; @@ -1205,7 +1213,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 @@ -1254,27 +1262,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); @@ -1387,7 +1395,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); @@ -1422,14 +1430,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 @@ -1442,14 +1449,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); } @@ -1723,7 +1730,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 Sat May 4 02:44:40 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=1613038698; cv=none; d=zohomail.com; s=zohoarc; b=f9+JV21nzvGpWfWn0jqPkVRQMW4TsYVxJMqiGsAV52cMPXqI9TKoPDeZE1PgzME3vNbjsKE6FULid3I+8aijQZYB93K2eROmu2BRyRCXG1E72FeYn+iZqpskz59CZ2rq88tzNf+OgMAIYOHWeOyRQLE4EHMe6yk5IP4VoaizMws= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1613038698; 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=3cGioF3XhVwmtqHEwtIlRzTuYQpd1I+EFdYzeGvtMh0=; b=EoU6dpXw3Dcgc/yMcrcH1eLHaUOmxKU8dwD1lArNVImDvISlRJdOobBqPL5+Ta+8CKCfJQv8Bn0u7WWd6LReSSDv3477JD5PaD7LLkJwGdFYustQnKp4HXXA/aRhyPAUVLB6lnPrwq5pkbxmpxqj3j/j1IziPgSYXAroN/o16a4= 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 1613038697878843.1733426635988; Thu, 11 Feb 2021 02:18:17 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.83801.156871 (Exim 4.92) (envelope-from ) id 1lA92x-0001wA-KM; Thu, 11 Feb 2021 10:18:03 +0000 Received: by outflank-mailman (output) from mailman id 83801.156871; Thu, 11 Feb 2021 10:18:03 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lA92x-0001w1-Em; Thu, 11 Feb 2021 10:18:03 +0000 Received: by outflank-mailman (input) for mailman id 83801; Thu, 11 Feb 2021 10:18:02 +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 1lA92w-0001VI-8E for xen-devel@lists.xenproject.org; Thu, 11 Feb 2021 10:18:02 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 146ca085-a6ed-4f37-b0fd-9402351e30fd; Thu, 11 Feb 2021 10:17:42 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 3841FAF11; Thu, 11 Feb 2021 10:17:41 +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: 146ca085-a6ed-4f37-b0fd-9402351e30fd 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=1613038661; 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=3cGioF3XhVwmtqHEwtIlRzTuYQpd1I+EFdYzeGvtMh0=; b=nJWGxbfsZic/fqYIe+mxFP821DzSm6m2XntEhzUHGLp8ReTw/1Z9p6Wf+Zog36NLKvRkvP aBBHU2g6Du1VAciaM66Ag1GwoVvwYFf2dWM8ssG4kS8RlcudQi1k9volZsavYT1ss5EL3j JZviBo2JsyCZQjZJXlTkzxRB8siacRs= From: Juergen Gross To: xen-devel@lists.xenproject.org, linux-kernel@vger.kernel.org Cc: Juergen Gross , Boris Ostrovsky , Stefano Stabellini Subject: [PATCH v2 6/8] xen/events: add per-xenbus device event statistics and settings Date: Thu, 11 Feb 2021 11:16:14 +0100 Message-Id: <20210211101616.13788-7-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210211101616.13788-1-jgross@suse.com> References: <20210211101616.13788-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 a5cce4c626c2..48210c1e62e3 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; } @@ -950,6 +962,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 @@ -960,6 +973,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; } @@ -1623,6 +1641,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) @@ -1654,6 +1673,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 18ffd0551b54..9494ecad3c92 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 2c43b0ef1e4d..13ee375a1f05 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 Sat May 4 02:44:40 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=1613038693; cv=none; d=zohomail.com; s=zohoarc; b=BRHNGoIaKb6rGlXyXpiYOPw3/zvhgaZjacIRsyJG4elAVArmoTfgHgKJEWFQNQN0ayrko2Uh/A5/lLT36Y87+oF3FvqJoui9/B3L141BmMh+hrr0nGcRbpPA8IGslqNr/av823mKNjfzFoz/sfha0nSkaSam2hx7ZMRMqoochSg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1613038693; 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=G6CBQvx8Idj2NAIO4FPMBPqp4/9q/qHdcnOjB7Vu8+oT7loXIla2dOpD1OTBbrEMUL4gvKm1gao79Zkwvok+9McK2ponK7OAQH8Eicr82DXckZ0tk9zDz8/8RXb8HwWqnqOGH/qCetR4Lhq1TuJ5T32zLSrn2W4xR4eKTBepZso= 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 1613038692627339.05828634706756; Thu, 11 Feb 2021 02:18:12 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.83800.156859 (Exim 4.92) (envelope-from ) id 1lA92s-0001oJ-9C; Thu, 11 Feb 2021 10:17:58 +0000 Received: by outflank-mailman (output) from mailman id 83800.156859; Thu, 11 Feb 2021 10:17:58 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lA92s-0001o6-4H; Thu, 11 Feb 2021 10:17:58 +0000 Received: by outflank-mailman (input) for mailman id 83800; Thu, 11 Feb 2021 10:17:57 +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 1lA92r-0001VI-7w for xen-devel@lists.xenproject.org; Thu, 11 Feb 2021 10:17:57 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id c958570c-1b54-4414-a274-bdc203af6dae; Thu, 11 Feb 2021 10:17:42 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 6FD2CAF49; Thu, 11 Feb 2021 10:17:41 +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: c958570c-1b54-4414-a274-bdc203af6dae 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=1613038661; 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=LmkY0cY/xUPQabBZ2K6py6iwlNSohSvZqtVGIKhgfs/Vd+e3i0HPowZRhK5GJgyUl5o28/ Lx47YRJ3EXvR1/z8sPJDmrvUc6rf00u386Gf1+f8cdN9vhlSbjkIEU7foEmfSwD4BZQf/a zldb9aBFKnXvuTux4U/p6Gw35AZbFbs= 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 v2 7/8] xen/evtch: use smp barriers for user event ring Date: Thu, 11 Feb 2021 11:16:15 +0100 Message-Id: <20210211101616.13788-8-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210211101616.13788-1-jgross@suse.com> References: <20210211101616.13788-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 Sat May 4 02:44:40 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=1613038688; cv=none; d=zohomail.com; s=zohoarc; b=BZDxapseON0FLdQonHLqkfxE2PDLqITzDapwvwgFvV1+IoN3DD9SduqSn17u2d5Vy2NqrGaLUDbsEN4p+Lnf1T9STIYvK1W82xhA+AH/iHK9jVN7nnnnd9SlY4N6AQs780UYxV3Ef+SldEuISN+hscWjSIdbxYnBQqvB4HQFwBE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1613038688; 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=lYH24KPMu2VG4s1NBLZlXtQTIXh2Tv25DANk+uAGYuo=; b=kPabflopz2xBbUwumIuwNUpn7EZHLyyn3n3tGTq0HQGuTDezh9xBAcLGdekcRpEXVpePBkJ/JjwKtHbJBXhFRtd+vZ4J0cr2FL0JAAIx8t0DSUnpkQdMDrXQdXT4s/4xOsCtmL7Zq3/0q790e3cilmT402uAZBxa/71GSUPdU+Y= 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 1613038688049136.2284750918916; Thu, 11 Feb 2021 02:18:08 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.83798.156835 (Exim 4.92) (envelope-from ) id 1lA92n-0001fJ-5Y; Thu, 11 Feb 2021 10:17:53 +0000 Received: by outflank-mailman (output) from mailman id 83798.156835; Thu, 11 Feb 2021 10:17:53 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lA92n-0001fA-1v; Thu, 11 Feb 2021 10:17:53 +0000 Received: by outflank-mailman (input) for mailman id 83798; Thu, 11 Feb 2021 10:17:51 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lA92l-0001Uu-O2 for xen-devel@lists.xenproject.org; Thu, 11 Feb 2021 10:17:51 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 8cb82252-c671-4eed-821b-f7d2d3151973; Thu, 11 Feb 2021 10:17:42 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 98FF9AF50; Thu, 11 Feb 2021 10:17:41 +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: 8cb82252-c671-4eed-821b-f7d2d3151973 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=1613038661; 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=lYH24KPMu2VG4s1NBLZlXtQTIXh2Tv25DANk+uAGYuo=; b=u1DgoxnpEm4vOpyw48CO18ajkHrDW1uvBzT3RfgWYFijSi0+reRlAnvlKP1gg0r4P9Pi7i Vu5847ApQb2x84mlacvWnCjsZcJwu0yHNhZeZttlgZKVZRpMXgD4XgZOCcNZ5ySrNx83tW UvkSODeyNjTFab6FqCgs6SMINmH3iSc= From: Juergen Gross To: xen-devel@lists.xenproject.org, linux-kernel@vger.kernel.org Cc: Juergen Gross , Boris Ostrovsky , Stefano Stabellini Subject: [PATCH v2 8/8] xen/evtchn: use READ/WRITE_ONCE() for accessing ring indices Date: Thu, 11 Feb 2021 11:16:16 +0100 Message-Id: <20210211101616.13788-9-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210211101616.13788-1-jgross@suse.com> References: <20210211101616.13788-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 --- V2: - modify all accesses (Julien Grall) --- 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..620008f89dbe 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++) { + if (cons =3D=3D prod++) { + WRITE_ONCE(u->ring_prod, 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