linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH V3] ACPI / GED: unregister interrupts during shutdown
@ 2017-12-08  4:40 Sinan Kaya
  2017-12-08 13:54 ` Rafael J. Wysocki
  0 siblings, 1 reply; 4+ messages in thread
From: Sinan Kaya @ 2017-12-08  4:40 UTC (permalink / raw)
  To: linux-acpi, timur
  Cc: linux-arm-msm, linux-arm-kernel, Sinan Kaya, Rafael J. Wysocki,
	Len Brown, linux-kernel

Some GED interrupts could be pending by the time we are doing a reboot.

Even though GED driver uses devm_request_irq() to register the interrupt
handler, the handler is not being freed on time during a shutdown since
the driver is missing a shutdown callback.

If the ACPI handler is no longer available, this causes an interrupt
storm and delays shutdown.

1. Don't use devm family of functions for IRQ registration/free
2. Keep track of the events since free_irq() requires the dev_id parameter
passed into the request_irq() function.
3. Call free_irq() on both remove and shutdown explicitly.

Signed-off-by: Sinan Kaya <okaya@codeaurora.org>
---
 drivers/acpi/evged.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++------
 1 file changed, 49 insertions(+), 6 deletions(-)

diff --git a/drivers/acpi/evged.c b/drivers/acpi/evged.c
index 46f0603..38cb00e 100644
--- a/drivers/acpi/evged.c
+++ b/drivers/acpi/evged.c
@@ -49,6 +49,11 @@
 
 #define MODULE_NAME	"acpi-ged"
 
+struct acpi_ged_device {
+	struct device *dev;
+	struct list_head event_list;
+};
+
 struct acpi_ged_event {
 	struct list_head node;
 	struct device *dev;
@@ -76,7 +81,8 @@ static acpi_status acpi_ged_request_interrupt(struct acpi_resource *ares,
 	unsigned int irq;
 	unsigned int gsi;
 	unsigned int irqflags = IRQF_ONESHOT;
-	struct device *dev = context;
+	struct acpi_ged_device *geddev = context;
+	struct device *dev = geddev->dev;
 	acpi_handle handle = ACPI_HANDLE(dev);
 	acpi_handle evt_handle;
 	struct resource r;
@@ -102,8 +108,6 @@ static acpi_status acpi_ged_request_interrupt(struct acpi_resource *ares,
 		return AE_ERROR;
 	}
 
-	dev_info(dev, "GED listening GSI %u @ IRQ %u\n", gsi, irq);
-
 	event = devm_kzalloc(dev, sizeof(*event), GFP_KERNEL);
 	if (!event)
 		return AE_ERROR;
@@ -116,26 +120,63 @@ static acpi_status acpi_ged_request_interrupt(struct acpi_resource *ares,
 	if (r.flags & IORESOURCE_IRQ_SHAREABLE)
 		irqflags |= IRQF_SHARED;
 
-	if (devm_request_threaded_irq(dev, irq, NULL, acpi_ged_irq_handler,
-				      irqflags, "ACPI:Ged", event)) {
+	if (request_threaded_irq(irq, NULL, acpi_ged_irq_handler,
+				 irqflags, "ACPI:Ged", event)) {
 		dev_err(dev, "failed to setup event handler for irq %u\n", irq);
 		return AE_ERROR;
 	}
 
+	dev_dbg(dev, "GED listening GSI %u @ IRQ %u\n", gsi, irq);
+	list_add_tail(&event->node, &geddev->event_list);
 	return AE_OK;
 }
 
 static int ged_probe(struct platform_device *pdev)
 {
+	struct acpi_ged_device *geddev;
 	acpi_status acpi_ret;
 
+	geddev = devm_kzalloc(&pdev->dev, sizeof(*geddev), GFP_KERNEL);
+	if (!geddev)
+		return -ENOMEM;
+
+	geddev->dev = &pdev->dev;
+	INIT_LIST_HEAD(&geddev->event_list);
 	acpi_ret = acpi_walk_resources(ACPI_HANDLE(&pdev->dev), "_CRS",
-				       acpi_ged_request_interrupt, &pdev->dev);
+				       acpi_ged_request_interrupt, geddev);
 	if (ACPI_FAILURE(acpi_ret)) {
 		dev_err(&pdev->dev, "unable to parse the _CRS record\n");
 		return -EINVAL;
 	}
+	platform_set_drvdata(pdev, geddev);
+
+	return 0;
+}
+
+static void ged_cleanup_irq(struct acpi_ged_device *geddev)
+{
+	struct acpi_ged_event *event, *next;
+
+	list_for_each_entry_safe(event, next, &geddev->event_list, node) {
+		free_irq(event->irq, event);
+		list_del(&event->node);
+		dev_dbg(geddev->dev, "GED releasing GSI %u @ IRQ %u\n",
+			 event->gsi, event->irq);
+	}
+}
+
+static void ged_shutdown(struct platform_device *pdev)
+{
+	struct acpi_ged_device *geddev = platform_get_drvdata(pdev);
+
+	ged_cleanup_irq(geddev);
+}
+
+static int ged_remove(struct platform_device *pdev)
+{
+	struct acpi_ged_device *geddev = platform_get_drvdata(pdev);
 
+	ged_cleanup_irq(geddev);
 	return 0;
 }
 
@@ -146,6 +187,8 @@ static int ged_probe(struct platform_device *pdev)
 
 static struct platform_driver ged_driver = {
 	.probe = ged_probe,
+	.remove = ged_remove,
+	.shutdown = ged_shutdown,
 	.driver = {
 		.name = MODULE_NAME,
 		.acpi_match_table = ACPI_PTR(ged_acpi_ids),
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH V3] ACPI / GED: unregister interrupts during shutdown
  2017-12-08  4:40 [PATCH V3] ACPI / GED: unregister interrupts during shutdown Sinan Kaya
@ 2017-12-08 13:54 ` Rafael J. Wysocki
  2017-12-09  1:54   ` Sinan Kaya
  0 siblings, 1 reply; 4+ messages in thread
From: Rafael J. Wysocki @ 2017-12-08 13:54 UTC (permalink / raw)
  To: Sinan Kaya
  Cc: ACPI Devel Maling List, Timur Tabi, linux-arm-msm,
	linux-arm-kernel, Rafael J. Wysocki, Len Brown,
	Linux Kernel Mailing List

On Fri, Dec 8, 2017 at 5:40 AM, Sinan Kaya <okaya@codeaurora.org> wrote:
> Some GED interrupts could be pending by the time we are doing a reboot.
>
> Even though GED driver uses devm_request_irq() to register the interrupt
> handler, the handler is not being freed on time during a shutdown since
> the driver is missing a shutdown callback.
>
> If the ACPI handler is no longer available, this causes an interrupt
> storm and delays shutdown.
>
> 1. Don't use devm family of functions for IRQ registration/free
> 2. Keep track of the events since free_irq() requires the dev_id parameter
> passed into the request_irq() function.
> 3. Call free_irq() on both remove and shutdown explicitly.
>
> Signed-off-by: Sinan Kaya <okaya@codeaurora.org>
> ---
>  drivers/acpi/evged.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++------
>  1 file changed, 49 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/acpi/evged.c b/drivers/acpi/evged.c
> index 46f0603..38cb00e 100644
> --- a/drivers/acpi/evged.c
> +++ b/drivers/acpi/evged.c
> @@ -49,6 +49,11 @@
>
>  #define MODULE_NAME    "acpi-ged"
>
> +struct acpi_ged_device {
> +       struct device *dev;
> +       struct list_head event_list;
> +};
> +
>  struct acpi_ged_event {
>         struct list_head node;
>         struct device *dev;
> @@ -76,7 +81,8 @@ static acpi_status acpi_ged_request_interrupt(struct acpi_resource *ares,
>         unsigned int irq;
>         unsigned int gsi;
>         unsigned int irqflags = IRQF_ONESHOT;
> -       struct device *dev = context;
> +       struct acpi_ged_device *geddev = context;
> +       struct device *dev = geddev->dev;
>         acpi_handle handle = ACPI_HANDLE(dev);
>         acpi_handle evt_handle;
>         struct resource r;
> @@ -102,8 +108,6 @@ static acpi_status acpi_ged_request_interrupt(struct acpi_resource *ares,
>                 return AE_ERROR;
>         }
>
> -       dev_info(dev, "GED listening GSI %u @ IRQ %u\n", gsi, irq);
> -
>         event = devm_kzalloc(dev, sizeof(*event), GFP_KERNEL);
>         if (!event)
>                 return AE_ERROR;
> @@ -116,26 +120,63 @@ static acpi_status acpi_ged_request_interrupt(struct acpi_resource *ares,
>         if (r.flags & IORESOURCE_IRQ_SHAREABLE)
>                 irqflags |= IRQF_SHARED;
>
> -       if (devm_request_threaded_irq(dev, irq, NULL, acpi_ged_irq_handler,
> -                                     irqflags, "ACPI:Ged", event)) {
> +       if (request_threaded_irq(irq, NULL, acpi_ged_irq_handler,
> +                                irqflags, "ACPI:Ged", event)) {
>                 dev_err(dev, "failed to setup event handler for irq %u\n", irq);
>                 return AE_ERROR;
>         }
>
> +       dev_dbg(dev, "GED listening GSI %u @ IRQ %u\n", gsi, irq);
> +       list_add_tail(&event->node, &geddev->event_list);
>         return AE_OK;
>  }
>
>  static int ged_probe(struct platform_device *pdev)
>  {
> +       struct acpi_ged_device *geddev;
>         acpi_status acpi_ret;
>
> +       geddev = devm_kzalloc(&pdev->dev, sizeof(*geddev), GFP_KERNEL);
> +       if (!geddev)
> +               return -ENOMEM;
> +
> +       geddev->dev = &pdev->dev;
> +       INIT_LIST_HEAD(&geddev->event_list);
>         acpi_ret = acpi_walk_resources(ACPI_HANDLE(&pdev->dev), "_CRS",
> -                                      acpi_ged_request_interrupt, &pdev->dev);
> +                                      acpi_ged_request_interrupt, geddev);
>         if (ACPI_FAILURE(acpi_ret)) {
>                 dev_err(&pdev->dev, "unable to parse the _CRS record\n");
>                 return -EINVAL;
>         }
> +       platform_set_drvdata(pdev, geddev);
> +
> +       return 0;
> +}
> +
> +static void ged_cleanup_irq(struct acpi_ged_device *geddev)
> +{
> +       struct acpi_ged_event *event, *next;
> +
> +       list_for_each_entry_safe(event, next, &geddev->event_list, node) {
> +               free_irq(event->irq, event);
> +               list_del(&event->node);
> +               dev_dbg(geddev->dev, "GED releasing GSI %u @ IRQ %u\n",
> +                        event->gsi, event->irq);
> +       }
> +}
> +
> +static void ged_shutdown(struct platform_device *pdev)
> +{
> +       struct acpi_ged_device *geddev = platform_get_drvdata(pdev);
> +
> +       ged_cleanup_irq(geddev);
> +}
> +
> +static int ged_remove(struct platform_device *pdev)
> +{
> +       struct acpi_ged_device *geddev = platform_get_drvdata(pdev);
>
> +       ged_cleanup_irq(geddev);

Do you really need this duplication?  You may as well call
ged_shutdown() from here.

And the local variable is redundant too.

I guess it would be better to just fold ged_cleanup_irq() into
ged_shutdown() and call that from ged_remove().

>         return 0;
>  }
>
> @@ -146,6 +187,8 @@ static int ged_probe(struct platform_device *pdev)
>
>  static struct platform_driver ged_driver = {
>         .probe = ged_probe,
> +       .remove = ged_remove,
> +       .shutdown = ged_shutdown,
>         .driver = {
>                 .name = MODULE_NAME,
>                 .acpi_match_table = ACPI_PTR(ged_acpi_ids),
> --

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH V3] ACPI / GED: unregister interrupts during shutdown
  2017-12-08 13:54 ` Rafael J. Wysocki
@ 2017-12-09  1:54   ` Sinan Kaya
  2017-12-09 14:12     ` Rafael J. Wysocki
  0 siblings, 1 reply; 4+ messages in thread
From: Sinan Kaya @ 2017-12-09  1:54 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: ACPI Devel Maling List, Timur Tabi, linux-arm-msm,
	linux-arm-kernel, Rafael J. Wysocki, Len Brown,
	Linux Kernel Mailing List

On 12/8/2017 8:54 AM, Rafael J. Wysocki wrote:
>> static int ged_remove(struct platform_device *pdev)
>> +{
>> +       struct acpi_ged_device *geddev = platform_get_drvdata(pdev);
>>
>> +       ged_cleanup_irq(geddev);
> Do you really need this duplication?  You may as well call
> ged_shutdown() from here.
> 
> And the local variable is redundant too.
> 
> I guess it would be better to just fold ged_cleanup_irq() into
> ged_shutdown() and call that from ged_remove().
> 

I originally tried to make these two APIs as common as possible and tried
calling shutdown from remove. However, the calling convention of shutdown
and remove are different. 

Shutdown returns void; whereas, remove returns an integer. That's why, I
created a common function and called from both places. 

I can probably make the calling parameter of ged_cleanup_irq() a pdev and
get rid of the additional casting in these two different functions. 

Let me know if you have a better idea.

-- 
Sinan Kaya
Qualcomm Datacenter Technologies, Inc. as an affiliate of Qualcomm Technologies, Inc.
Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH V3] ACPI / GED: unregister interrupts during shutdown
  2017-12-09  1:54   ` Sinan Kaya
@ 2017-12-09 14:12     ` Rafael J. Wysocki
  0 siblings, 0 replies; 4+ messages in thread
From: Rafael J. Wysocki @ 2017-12-09 14:12 UTC (permalink / raw)
  To: Sinan Kaya
  Cc: Rafael J. Wysocki, ACPI Devel Maling List, Timur Tabi,
	linux-arm-msm, linux-arm-kernel, Rafael J. Wysocki, Len Brown,
	Linux Kernel Mailing List

On Sat, Dec 9, 2017 at 2:54 AM, Sinan Kaya <okaya@codeaurora.org> wrote:
> On 12/8/2017 8:54 AM, Rafael J. Wysocki wrote:
>>> static int ged_remove(struct platform_device *pdev)
>>> +{
>>> +       struct acpi_ged_device *geddev = platform_get_drvdata(pdev);
>>>
>>> +       ged_cleanup_irq(geddev);
>> Do you really need this duplication?  You may as well call
>> ged_shutdown() from here.
>>
>> And the local variable is redundant too.
>>
>> I guess it would be better to just fold ged_cleanup_irq() into
>> ged_shutdown() and call that from ged_remove().
>>
>
> I originally tried to make these two APIs as common as possible and tried
> calling shutdown from remove. However, the calling convention of shutdown
> and remove are different.

Look at the code in your patch: ged_shutdown() does exactly the same
things as ged_remove(), except that ged_remove() returns 0 in addition
to that, so you can do it this way:

static int int ged_remove(struct platform_device *pdev)
{
       ged_shutdown(pdev);
       return 0;
}

Why wouldn't that work?

> Shutdown returns void; whereas, remove returns an integer. That's why, I
> created a common function and called from both places.
>
> I can probably make the calling parameter of ged_cleanup_irq() a pdev and
> get rid of the additional casting in these two different functions.
>
> Let me know if you have a better idea.

And with the above, you can fold your ged_cleanup_irq() into
ged_shutdown(), can't you?

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-12-09 14:12 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-12-08  4:40 [PATCH V3] ACPI / GED: unregister interrupts during shutdown Sinan Kaya
2017-12-08 13:54 ` Rafael J. Wysocki
2017-12-09  1:54   ` Sinan Kaya
2017-12-09 14:12     ` Rafael J. Wysocki

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).