[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH 2/2] xen/events: increment refcnt only if event channel is refcounted


  • To: Juergen Gross <jgross@xxxxxxxx>, "linux-kernel@xxxxxxxxxxxxxxx" <linux-kernel@xxxxxxxxxxxxxxx>
  • From: Oleksandr Tyshchenko <Oleksandr_Tyshchenko@xxxxxxxx>
  • Date: Sun, 17 Mar 2024 16:03:41 +0000
  • Accept-language: en-US, ru-RU
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=epam.com; dmarc=pass action=none header.from=epam.com; dkim=pass header.d=epam.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=smMv8DutK5AvTFrpMG2RuL8Lil3iKk+bApA6CRuQv20=; b=kv+ZXmreuMg0JeyDu7u5Rj9+vmMzh/I8EsSywDAlr1/W/s6nwNkLSgDUCVPYgEhg2g/ljbrAIozHqMh7KiOS47lLypvooLdDW1d2aTAtp2w/KOVwvoydnellt3IiLsNCaRn88um61gjgrjdsR4ds00nPQcEiL96PRWes+/5NXfuGhD2tK6Z8a43oyXFskEFriaTYRN8AqyBGH/jY7kolziWoUqSsMGV0q/Mfj9aGmt4McaBdVtqF/JJBtI1broMj4Z0X++/BPgObvRJXCLVnjkskf4uOSrcxbX5FoBmg+sJNet8aK/BoFJrNyGqIZljdl/6PEJpRfT+KVXsPutKkpQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=P8dwVar/nWMLx7IhvEbFjCFDxokiSdxNoJF8aSKfVNRQlHPQgIfnQEnyFfD/f+xr01PfX3vUjxTnC3aPHvaJyZ+ayk791MM3z76KRlSiHH1VBXe3TWdMIekz2mTdmCBUsldPGdTfbQ82ZW+ahWjowoVp1yrZweuIlJ6iDy47bl1sVKdsYqnCtcvfq62J29/Iqhbj/RCuB0qev4eogkRLi0rVhWmmZrmbcsgJUQ0/OByAgZWTG7Xly1Xwn8+CFVKy4pNdBDx/TprJsxy0XuAB5B0E4Of8TE6PhzmFt6DEkJP1KBGFERaCWUXGJ0i7yQE2eCScd/ZYjD1rlqCklDORsg==
  • Cc: Stefano Stabellini <sstabellini@xxxxxxxxxx>, "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • Delivery-date: Sun, 17 Mar 2024 16:03:59 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Thread-index: AQHadRYYap97PRUEWUyJa/zlA+m6fbE8Hy2A
  • Thread-topic: [PATCH 2/2] xen/events: increment refcnt only if event channel is refcounted


On 13.03.24 09:14, Juergen Gross wrote:


Hello Juergen

> In bind_evtchn_to_irq_chip() don't increment the refcnt of the event
> channel blindly. In case the event channel is NOT refcounted, issue a
> warning instead.
> 
> Add an additional safety net by doing the refcnt increment only if the
> caller has specified IRQF_SHARED in the irqflags parameter.
> 
> Fixes: 9e90e58c11b7 ("xen: evtchn: Allow shared registration of IRQ handers")
> Signed-off-by: Juergen Gross <jgross@xxxxxxxx>


Reviewed-by: Oleksandr Tyshchenko <oleksandr_tyshchenko@xxxxxxxx>


> ---
>   drivers/xen/events/events_base.c | 22 +++++++++++++---------
>   1 file changed, 13 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/xen/events/events_base.c 
> b/drivers/xen/events/events_base.c
> index 2faa4bf78c7a..81effbd53dc5 100644
> --- a/drivers/xen/events/events_base.c
> +++ b/drivers/xen/events/events_base.c
> @@ -1190,7 +1190,7 @@ int xen_pirq_from_irq(unsigned irq)
>   EXPORT_SYMBOL_GPL(xen_pirq_from_irq);
>   
>   static int bind_evtchn_to_irq_chip(evtchn_port_t evtchn, struct irq_chip 
> *chip,
> -                                struct xenbus_device *dev)
> +                                struct xenbus_device *dev, bool shared)
>   {
>       int ret = -ENOMEM;
>       struct irq_info *info;
> @@ -1224,7 +1224,8 @@ static int bind_evtchn_to_irq_chip(evtchn_port_t 
> evtchn, struct irq_chip *chip,
>                */
>               bind_evtchn_to_cpu(info, 0, false);
>       } else if (!WARN_ON(info->type != IRQT_EVTCHN)) {
> -             info->refcnt++;
> +             if (shared && !WARN_ON(info->refcnt < 0))
> +                     info->refcnt++;
>       }
>   
>       ret = info->irq;
> @@ -1237,13 +1238,13 @@ static int bind_evtchn_to_irq_chip(evtchn_port_t 
> evtchn, struct irq_chip *chip,
>   
>   int bind_evtchn_to_irq(evtchn_port_t evtchn)
>   {
> -     return bind_evtchn_to_irq_chip(evtchn, &xen_dynamic_chip, NULL);
> +     return bind_evtchn_to_irq_chip(evtchn, &xen_dynamic_chip, NULL, false);
>   }
>   EXPORT_SYMBOL_GPL(bind_evtchn_to_irq);
>   
>   int bind_evtchn_to_irq_lateeoi(evtchn_port_t evtchn)
>   {
> -     return bind_evtchn_to_irq_chip(evtchn, &xen_lateeoi_chip, NULL);
> +     return bind_evtchn_to_irq_chip(evtchn, &xen_lateeoi_chip, NULL, false);
>   }
>   EXPORT_SYMBOL_GPL(bind_evtchn_to_irq_lateeoi);
>   
> @@ -1295,7 +1296,8 @@ static int bind_ipi_to_irq(unsigned int ipi, unsigned 
> int cpu)
>   
>   static int bind_interdomain_evtchn_to_irq_chip(struct xenbus_device *dev,
>                                              evtchn_port_t remote_port,
> -                                            struct irq_chip *chip)
> +                                            struct irq_chip *chip,
> +                                            bool shared)
>   {
>       struct evtchn_bind_interdomain bind_interdomain;
>       int err;
> @@ -1307,14 +1309,14 @@ static int bind_interdomain_evtchn_to_irq_chip(struct 
> xenbus_device *dev,
>                                         &bind_interdomain);
>   
>       return err ? : bind_evtchn_to_irq_chip(bind_interdomain.local_port,
> -                                            chip, dev);
> +                                            chip, dev, shared);
>   }
>   
>   int bind_interdomain_evtchn_to_irq_lateeoi(struct xenbus_device *dev,
>                                          evtchn_port_t remote_port)
>   {
>       return bind_interdomain_evtchn_to_irq_chip(dev, remote_port,
> -                                                &xen_lateeoi_chip);
> +                                                &xen_lateeoi_chip, false);
>   }
>   EXPORT_SYMBOL_GPL(bind_interdomain_evtchn_to_irq_lateeoi);
>   
> @@ -1430,7 +1432,8 @@ static int bind_evtchn_to_irqhandler_chip(evtchn_port_t 
> evtchn,
>   {
>       int irq, retval;
>   
> -     irq = bind_evtchn_to_irq_chip(evtchn, chip, NULL);
> +     irq = bind_evtchn_to_irq_chip(evtchn, chip, NULL,
> +                                   irqflags & IRQF_SHARED);
>       if (irq < 0)
>               return irq;
>       retval = request_irq(irq, handler, irqflags, devname, dev_id);
> @@ -1471,7 +1474,8 @@ static int bind_interdomain_evtchn_to_irqhandler_chip(
>   {
>       int irq, retval;
>   
> -     irq = bind_interdomain_evtchn_to_irq_chip(dev, remote_port, chip);
> +     irq = bind_interdomain_evtchn_to_irq_chip(dev, remote_port, chip,
> +                                               irqflags & IRQF_SHARED);
>       if (irq < 0)
>               return irq;
>   

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.