All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH V2] acpi: add support for extended IRQ to PCI link
@ 2015-11-12  6:14 Sinan Kaya
  2015-11-12  6:14 ` [PATCH] " Sinan Kaya
  0 siblings, 1 reply; 32+ messages in thread
From: Sinan Kaya @ 2015-11-12  6:14 UTC (permalink / raw)
  To: linux-acpi, timur, cov, jcm; +Cc: Sinan Kaya

The ACPI compiler uses the extended format when used
interrupt numbers are greater than 256. The PCI link code
currently only supports simple interrupt format. The IRQ
numbers are represented using 32 bits when extended IRQ
syntax. This patch changes the interrupt number type to
32 bits and places an upper limit of 1020 as possible
interrupt id.

1020 is the maximum interrupt ID that can be assigned to
an ARM SPI interrupt according to ARM architecture.

Additional checks have been placed to prevent out of bounds
writes.

Changes from V1: (https://lkml.org/lkml/2015/11/8/162)
* change the commit text to include 1020 magic interrupt number
limitation
* cleanup multiple levels of if statements

Sinan Kaya (1):
  acpi: add support for extended IRQ to PCI link

 drivers/acpi/pci_link.c | 28 +++++++++++++++++-----------
 1 file changed, 17 insertions(+), 11 deletions(-)

-- 
Qualcomm Technologies, Inc. on behalf of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project


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

* [PATCH] acpi: add support for extended IRQ to PCI link
  2015-11-12  6:14 [PATCH V2] acpi: add support for extended IRQ to PCI link Sinan Kaya
@ 2015-11-12  6:14 ` Sinan Kaya
  2015-11-12  9:56   ` Andy Shevchenko
  0 siblings, 1 reply; 32+ messages in thread
From: Sinan Kaya @ 2015-11-12  6:14 UTC (permalink / raw)
  To: linux-acpi, timur, cov, jcm
  Cc: Sinan Kaya, Rafael J. Wysocki, Len Brown, linux-kernel

The ACPI compiler uses the extended format when used
interrupt numbers are greater than 256. The PCI link code
currently only supports simple interrupt format. The IRQ
numbers are represented using 32 bits when extended IRQ
syntax. This patch changes the interrupt number type to
32 bits and places an upper limit of 1020 as possible
interrupt id.

1020 is the maximum interrupt ID that can be assigned to
an ARM SPI interrupt according to ARM architecture.

Additional checks have been placed to prevent out of bounds
writes.

Signed-off-by: Sinan Kaya <okaya@codeaurora.org>
---
 drivers/acpi/pci_link.c | 28 +++++++++++++++++-----------
 1 file changed, 17 insertions(+), 11 deletions(-)

diff --git a/drivers/acpi/pci_link.c b/drivers/acpi/pci_link.c
index 7c8408b..a2becab 100644
--- a/drivers/acpi/pci_link.c
+++ b/drivers/acpi/pci_link.c
@@ -1,6 +1,7 @@
 /*
  *  pci_link.c - ACPI PCI Interrupt Link Device Driver ($Revision: 34 $)
  *
+ *  Copyright (c) 2015, The Linux Foundation. All rights reserved.
  *  Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com>
  *  Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
  *  Copyright (C) 2002       Dominik Brodowski <devel@brodo.de>
@@ -67,12 +68,12 @@ static struct acpi_scan_handler pci_link_handler = {
  * later even the link is disable. Instead, we just repick the active irq
  */
 struct acpi_pci_link_irq {
-	u8 active;		/* Current IRQ */
+	u32 active;		/* Current IRQ */
 	u8 triggering;		/* All IRQs */
 	u8 polarity;		/* All IRQs */
 	u8 resource_type;
 	u8 possible_count;
-	u8 possible[ACPI_PCI_LINK_MAX_POSSIBLE];
+	u32 possible[ACPI_PCI_LINK_MAX_POSSIBLE];
 	u8 initialized:1;
 	u8 reserved:7;
 };
@@ -437,7 +438,7 @@ static int acpi_pci_link_set(struct acpi_pci_link *link, int irq)
  * enabled system.
  */
 
-#define ACPI_MAX_IRQS		256
+#define ACPI_MAX_IRQS		1020
 #define ACPI_MAX_ISA_IRQ	16
 
 #define PIRQ_PENALTY_PCI_AVAILABLE	(0)
@@ -493,7 +494,8 @@ int __init acpi_irq_penalty_init(void)
 					    penalty;
 			}
 
-		} else if (link->irq.active) {
+		} else if (link->irq.active &&
+			(link->irq.active < ACPI_MAX_IRQS)) {
 			acpi_irq_penalty[link->irq.active] +=
 			    PIRQ_PENALTY_PCI_POSSIBLE;
 		}
@@ -541,14 +543,16 @@ static int acpi_pci_link_allocate(struct acpi_pci_link *link)
 	else
 		irq = link->irq.possible[link->irq.possible_count - 1];
 
-	if (acpi_irq_balance || !link->irq.active) {
+	if ((acpi_irq_balance || !link->irq.active) && (irq < ACPI_MAX_IRQS)) {
 		/*
-		 * Select the best IRQ.  This is done in reverse to promote
-		 * the use of IRQs 9, 10, 11, and >15.
+		 * Select the best IRQ.  This is done in reverse to
+		 * promote the use of IRQs 9, 10, 11, and >15.
 		 */
-		for (i = (link->irq.possible_count - 1); i >= 0; i--) {
-			if (acpi_irq_penalty[irq] >
-			    acpi_irq_penalty[link->irq.possible[i]])
+		i = link->irq.possible_count;
+		while (--i) {
+			if ((link->irq.possible[i] < ACPI_MAX_IRQS) &&
+			    (acpi_irq_penalty[irq] >
+			    acpi_irq_penalty[link->irq.possible[i]]))
 				irq = link->irq.possible[i];
 		}
 	}
@@ -568,7 +572,9 @@ static int acpi_pci_link_allocate(struct acpi_pci_link *link)
 			    acpi_device_bid(link->device));
 		return -ENODEV;
 	} else {
-		acpi_irq_penalty[link->irq.active] += PIRQ_PENALTY_PCI_USING;
+		if (link->irq.active < ACPI_MAX_IRQS)
+			acpi_irq_penalty[link->irq.active] +=
+				PIRQ_PENALTY_PCI_USING;
 		printk(KERN_WARNING PREFIX "%s [%s] enabled at IRQ %d\n",
 		       acpi_device_name(link->device),
 		       acpi_device_bid(link->device), link->irq.active);
-- 
Qualcomm Technologies, Inc. on behalf of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project


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

* Re: [PATCH] acpi: add support for extended IRQ to PCI link
  2015-11-12  6:14 ` [PATCH] " Sinan Kaya
@ 2015-11-12  9:56   ` Andy Shevchenko
  2015-11-12 15:04     ` Sinan Kaya
  0 siblings, 1 reply; 32+ messages in thread
From: Andy Shevchenko @ 2015-11-12  9:56 UTC (permalink / raw)
  To: Sinan Kaya
  Cc: linux-acpi, Timur Tabi, cov, jcm, Rafael J. Wysocki, Len Brown,
	linux-kernel

On Thu, Nov 12, 2015 at 8:14 AM, Sinan Kaya <okaya@codeaurora.org> wrote:
> The ACPI compiler uses the extended format when used
> interrupt numbers are greater than 256. The PCI link code
> currently only supports simple interrupt format. The IRQ
> numbers are represented using 32 bits when extended IRQ
> syntax. This patch changes the interrupt number type to
> 32 bits and places an upper limit of 1020 as possible
> interrupt id.
>
> 1020 is the maximum interrupt ID that can be assigned to
> an ARM SPI interrupt according to ARM architecture.

I think it worth to put these lines in the code as well.

>
> Additional checks have been placed to prevent out of bounds
> writes.
>
> Signed-off-by: Sinan Kaya <okaya@codeaurora.org>
> ---
>  drivers/acpi/pci_link.c | 28 +++++++++++++++++-----------
>  1 file changed, 17 insertions(+), 11 deletions(-)
>
> diff --git a/drivers/acpi/pci_link.c b/drivers/acpi/pci_link.c
> index 7c8408b..a2becab 100644
> --- a/drivers/acpi/pci_link.c
> +++ b/drivers/acpi/pci_link.c
> @@ -1,6 +1,7 @@
>  /*
>   *  pci_link.c - ACPI PCI Interrupt Link Device Driver ($Revision: 34 $)
>   *
> + *  Copyright (c) 2015, The Linux Foundation. All rights reserved.
>   *  Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com>
>   *  Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
>   *  Copyright (C) 2002       Dominik Brodowski <devel@brodo.de>
> @@ -67,12 +68,12 @@ static struct acpi_scan_handler pci_link_handler = {
>   * later even the link is disable. Instead, we just repick the active irq
>   */
>  struct acpi_pci_link_irq {
> -       u8 active;              /* Current IRQ */
> +       u32 active;             /* Current IRQ */
>         u8 triggering;          /* All IRQs */
>         u8 polarity;            /* All IRQs */
>         u8 resource_type;
>         u8 possible_count;
> -       u8 possible[ACPI_PCI_LINK_MAX_POSSIBLE];
> +       u32 possible[ACPI_PCI_LINK_MAX_POSSIBLE];
>         u8 initialized:1;
>         u8 reserved:7;
>  };
> @@ -437,7 +438,7 @@ static int acpi_pci_link_set(struct acpi_pci_link *link, int irq)
>   * enabled system.
>   */
>
> -#define ACPI_MAX_IRQS          256
> +#define ACPI_MAX_IRQS          1020
>  #define ACPI_MAX_ISA_IRQ       16
>
>  #define PIRQ_PENALTY_PCI_AVAILABLE     (0)
> @@ -493,7 +494,8 @@ int __init acpi_irq_penalty_init(void)
>                                             penalty;
>                         }
>
> -               } else if (link->irq.active) {
> +               } else if (link->irq.active &&
> +                       (link->irq.active < ACPI_MAX_IRQS)) {
>                         acpi_irq_penalty[link->irq.active] +=
>                             PIRQ_PENALTY_PCI_POSSIBLE;
>                 }
> @@ -541,14 +543,16 @@ static int acpi_pci_link_allocate(struct acpi_pci_link *link)
>         else
>                 irq = link->irq.possible[link->irq.possible_count - 1];
>
> -       if (acpi_irq_balance || !link->irq.active) {
> +       if ((acpi_irq_balance || !link->irq.active) && (irq < ACPI_MAX_IRQS)) {
>                 /*

> -                * Select the best IRQ.  This is done in reverse to promote
> -                * the use of IRQs 9, 10, 11, and >15.
> +                * Select the best IRQ.  This is done in reverse to
> +                * promote the use of IRQs 9, 10, 11, and >15.

What was changed here?

>                  */
> -               for (i = (link->irq.possible_count - 1); i >= 0; i--) {
> -                       if (acpi_irq_penalty[irq] >
> -                           acpi_irq_penalty[link->irq.possible[i]])
> +               i = link->irq.possible_count;
> +               while (--i) {
> +                       if ((link->irq.possible[i] < ACPI_MAX_IRQS) &&
> +                           (acpi_irq_penalty[irq] >
> +                           acpi_irq_penalty[link->irq.possible[i]]))
>                                 irq = link->irq.possible[i];
>                 }
>         }
> @@ -568,7 +572,9 @@ static int acpi_pci_link_allocate(struct acpi_pci_link *link)
>                             acpi_device_bid(link->device));
>                 return -ENODEV;
>         } else {
> -               acpi_irq_penalty[link->irq.active] += PIRQ_PENALTY_PCI_USING;
> +               if (link->irq.active < ACPI_MAX_IRQS)
> +                       acpi_irq_penalty[link->irq.active] +=
> +                               PIRQ_PENALTY_PCI_USING;
>                 printk(KERN_WARNING PREFIX "%s [%s] enabled at IRQ %d\n",
>                        acpi_device_name(link->device),
>                        acpi_device_bid(link->device), link->irq.active);


-- 
With Best Regards,
Andy Shevchenko

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

* Re: [PATCH] acpi: add support for extended IRQ to PCI link
  2015-11-12  9:56   ` Andy Shevchenko
@ 2015-11-12 15:04     ` Sinan Kaya
  2015-11-12 15:17       ` Andy Shevchenko
  0 siblings, 1 reply; 32+ messages in thread
From: Sinan Kaya @ 2015-11-12 15:04 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: linux-acpi, Timur Tabi, cov, jcm, Rafael J. Wysocki, Len Brown,
	linux-kernel

On 11/12/2015 4:56 AM, Andy Shevchenko wrote:
> On Thu, Nov 12, 2015 at 8:14 AM, Sinan Kaya <okaya@codeaurora.org> wrote:
>> The ACPI compiler uses the extended format when used
>> interrupt numbers are greater than 256. The PCI link code
>> currently only supports simple interrupt format. The IRQ
>> numbers are represented using 32 bits when extended IRQ
>> syntax. This patch changes the interrupt number type to
>> 32 bits and places an upper limit of 1020 as possible
>> interrupt id.
>>
>> 1020 is the maximum interrupt ID that can be assigned to
>> an ARM SPI interrupt according to ARM architecture.
> 
> I think it worth to put these lines in the code as well.
> 

ok

>>
>> Additional checks have been placed to prevent out of bounds
>> writes.
>>
>> Signed-off-by: Sinan Kaya <okaya@codeaurora.org>
>> ---
>>  drivers/acpi/pci_link.c | 28 +++++++++++++++++-----------
>>  1 file changed, 17 insertions(+), 11 deletions(-)
>>
>> diff --git a/drivers/acpi/pci_link.c b/drivers/acpi/pci_link.c
>> index 7c8408b..a2becab 100644
>> --- a/drivers/acpi/pci_link.c
>> +++ b/drivers/acpi/pci_link.c
>> @@ -1,6 +1,7 @@
>>  /*
>>   *  pci_link.c - ACPI PCI Interrupt Link Device Driver ($Revision: 34 $)
>>   *
>> + *  Copyright (c) 2015, The Linux Foundation. All rights reserved.
>>   *  Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com>
>>   *  Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
>>   *  Copyright (C) 2002       Dominik Brodowski <devel@brodo.de>
>> @@ -67,12 +68,12 @@ static struct acpi_scan_handler pci_link_handler = {
>>   * later even the link is disable. Instead, we just repick the active irq
>>   */
>>  struct acpi_pci_link_irq {
>> -       u8 active;              /* Current IRQ */
>> +       u32 active;             /* Current IRQ */
>>         u8 triggering;          /* All IRQs */
>>         u8 polarity;            /* All IRQs */
>>         u8 resource_type;
>>         u8 possible_count;
>> -       u8 possible[ACPI_PCI_LINK_MAX_POSSIBLE];
>> +       u32 possible[ACPI_PCI_LINK_MAX_POSSIBLE];
>>         u8 initialized:1;
>>         u8 reserved:7;
>>  };
>> @@ -437,7 +438,7 @@ static int acpi_pci_link_set(struct acpi_pci_link *link, int irq)
>>   * enabled system.
>>   */
>>
>> -#define ACPI_MAX_IRQS          256
>> +#define ACPI_MAX_IRQS          1020
>>  #define ACPI_MAX_ISA_IRQ       16
>>
>>  #define PIRQ_PENALTY_PCI_AVAILABLE     (0)
>> @@ -493,7 +494,8 @@ int __init acpi_irq_penalty_init(void)
>>                                             penalty;
>>                         }
>>
>> -               } else if (link->irq.active) {
>> +               } else if (link->irq.active &&
>> +                       (link->irq.active < ACPI_MAX_IRQS)) {
>>                         acpi_irq_penalty[link->irq.active] +=
>>                             PIRQ_PENALTY_PCI_POSSIBLE;
>>                 }
>> @@ -541,14 +543,16 @@ static int acpi_pci_link_allocate(struct acpi_pci_link *link)
>>         else
>>                 irq = link->irq.possible[link->irq.possible_count - 1];
>>
>> -       if (acpi_irq_balance || !link->irq.active) {
>> +       if ((acpi_irq_balance || !link->irq.active) && (irq < ACPI_MAX_IRQS)) {
>>                 /*
> 
>> -                * Select the best IRQ.  This is done in reverse to promote
>> -                * the use of IRQs 9, 10, 11, and >15.
>> +                * Select the best IRQ.  This is done in reverse to
>> +                * promote the use of IRQs 9, 10, 11, and >15.
> 
> What was changed here?

See your comments here.
https://lkml.org/lkml/2015/11/8/231

> 
>>                  */
>> -               for (i = (link->irq.possible_count - 1); i >= 0; i--) {
>> -                       if (acpi_irq_penalty[irq] >
>> -                           acpi_irq_penalty[link->irq.possible[i]])
>> +               i = link->irq.possible_count;
>> +               while (--i) {
>> +                       if ((link->irq.possible[i] < ACPI_MAX_IRQS) &&
>> +                           (acpi_irq_penalty[irq] >
>> +                           acpi_irq_penalty[link->irq.possible[i]]))
>>                                 irq = link->irq.possible[i];
>>                 }
>>         }
>> @@ -568,7 +572,9 @@ static int acpi_pci_link_allocate(struct acpi_pci_link *link)
>>                             acpi_device_bid(link->device));
>>                 return -ENODEV;
>>         } else {
>> -               acpi_irq_penalty[link->irq.active] += PIRQ_PENALTY_PCI_USING;
>> +               if (link->irq.active < ACPI_MAX_IRQS)
>> +                       acpi_irq_penalty[link->irq.active] +=
>> +                               PIRQ_PENALTY_PCI_USING;
>>                 printk(KERN_WARNING PREFIX "%s [%s] enabled at IRQ %d\n",
>>                        acpi_device_name(link->device),
>>                        acpi_device_bid(link->device), link->irq.active);
> 
> 


-- 
Sinan Kaya
Qualcomm Technologies, Inc. on behalf of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a
Linux Foundation Collaborative Project

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

* Re: [PATCH] acpi: add support for extended IRQ to PCI link
  2015-11-12 15:04     ` Sinan Kaya
@ 2015-11-12 15:17       ` Andy Shevchenko
  2015-11-12 15:54         ` okaya
  0 siblings, 1 reply; 32+ messages in thread
From: Andy Shevchenko @ 2015-11-12 15:17 UTC (permalink / raw)
  To: Sinan Kaya
  Cc: linux-acpi, Timur Tabi, cov, jcm, Rafael J. Wysocki, Len Brown,
	linux-kernel

On Thu, Nov 12, 2015 at 5:04 PM, Sinan Kaya <okaya@codeaurora.org> wrote:
> On 11/12/2015 4:56 AM, Andy Shevchenko wrote:
>> On Thu, Nov 12, 2015 at 8:14 AM, Sinan Kaya <okaya@codeaurora.org> wrote:
>>> -       if (acpi_irq_balance || !link->irq.active) {
>>> +       if ((acpi_irq_balance || !link->irq.active) && (irq < ACPI_MAX_IRQS)) {
>>>                 /*
>>
>>> -                * Select the best IRQ.  This is done in reverse to promote
>>> -                * the use of IRQs 9, 10, 11, and >15.
>>> +                * Select the best IRQ.  This is done in reverse to
>>> +                * promote the use of IRQs 9, 10, 11, and >15.
>>
>> What was changed here?
>
> See your comments here.
> https://lkml.org/lkml/2015/11/8/231

So, you refer to narrow commentary blocks, right?
It was about *new* code, leave as is what was before your patch series.

-- 
With Best Regards,
Andy Shevchenko

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

* Re: [PATCH] acpi: add support for extended IRQ to PCI link
  2015-11-12 15:17       ` Andy Shevchenko
@ 2015-11-12 15:54         ` okaya
  2015-11-12 15:58           ` Timur Tabi
  0 siblings, 1 reply; 32+ messages in thread
From: okaya @ 2015-11-12 15:54 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Sinan Kaya, linux-acpi, Timur Tabi, cov, jcm, Rafael J. Wysocki,
	Len Brown, linux-kernel

> On Thu, Nov 12, 2015 at 5:04 PM, Sinan Kaya <okaya@codeaurora.org> wrote:
>> On 11/12/2015 4:56 AM, Andy Shevchenko wrote:
>>> On Thu, Nov 12, 2015 at 8:14 AM, Sinan Kaya <okaya@codeaurora.org>
>>> wrote:
>>>> -       if (acpi_irq_balance || !link->irq.active) {
>>>> +       if ((acpi_irq_balance || !link->irq.active) && (irq <
>>>> ACPI_MAX_IRQS)) {
>>>>                 /*
>>>
>>>> -                * Select the best IRQ.  This is done in reverse to
>>>> promote
>>>> -                * the use of IRQs 9, 10, 11, and >15.
>>>> +                * Select the best IRQ.  This is done in reverse to
>>>> +                * promote the use of IRQs 9, 10, 11, and >15.
>>>
>>> What was changed here?
>>
>> See your comments here.
>> https://lkml.org/lkml/2015/11/8/231
>
> So, you refer to narrow commentary blocks, right?
> It was about *new* code, leave as is what was before your patch series.
>
> --
> With Best Regards,
> Andy Shevchenko
>

This is what it was before.

>         if (acpi_irq_balance || !link->irq.active) {
> -               /*
> -                * Select the best IRQ.  This is done in reverse to promote
> -                * the use of IRQs 9, 10, 11, and >15.
> -                */
> -               for (i = (link->irq.possible_count - 1); i >= 0; i--) {
> -                       if (acpi_irq_penalty[irq] >
> -                           acpi_irq_penalty[link->irq.possible[i]])
> -                               irq = link->irq.possible[i];

I added a range check for link->irq.possible[i] and irq into this code.



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

* Re: [PATCH] acpi: add support for extended IRQ to PCI link
  2015-11-12 15:54         ` okaya
@ 2015-11-12 15:58           ` Timur Tabi
  0 siblings, 0 replies; 32+ messages in thread
From: Timur Tabi @ 2015-11-12 15:58 UTC (permalink / raw)
  To: okaya, Andy Shevchenko
  Cc: linux-acpi, cov, jcm, Rafael J. Wysocki, Len Brown, linux-kernel

okaya@codeaurora.org wrote:
> This is what it was before.
>
>> >         if (acpi_irq_balance || !link->irq.active) {
>> >-               /*
>> >-                * Select the best IRQ.  This is done in reverse to promote
>> >-                * the use of IRQs 9, 10, 11, and >15.
>> >-                */
>> >-               for (i = (link->irq.possible_count - 1); i >= 0; i--) {
>> >-                       if (acpi_irq_penalty[irq] >
>> >-                           acpi_irq_penalty[link->irq.possible[i]])
>> >-                               irq = link->irq.possible[i];
> I added a range check for link->irq.possible[i] and irq into this code.
>
>

This change:

-	 * Select the best IRQ.  This is done in reverse to promote
-	 * the use of IRQs 9, 10, 11, and >15.
+	 * Select the best IRQ.  This is done in reverse to
+	 * promote the use of IRQs 9, 10, 11, and >15.

is an unrelated whitespace change.  It doesn't belong in this patch.

-- 
Sent by an employee of the Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the
Code Aurora Forum, hosted by The Linux Foundation.

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

* Re: [PATCH] acpi: add support for extended IRQ to PCI link
  2015-11-08 20:35   ` Andy Shevchenko
  (?)
@ 2015-11-09 22:29     ` Sinan Kaya
  -1 siblings, 0 replies; 32+ messages in thread
From: Sinan Kaya @ 2015-11-09 22:29 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: linux-acpi, timur, cov, jcm, Andy Gross, linux-arm-msm,
	linux-arm Mailing List, Rafael J. Wysocki, Len Brown,
	linux-kernel



On 11/8/2015 3:35 PM, Andy Shevchenko wrote:
> On Sun, Nov 8, 2015 at 6:07 PM, Sinan Kaya <okaya@codeaurora.org> wrote:
>> The ACPI compiler uses the extended format when
>> used interrupt numbers are greater than 256.
>> The PCI link code currently only supports simple
>> interrupt format. The IRQ numbers are represented
>> using 32 bits when extended IRQ syntax. This patch
>> changes the interrupt number type to 32 bits and
>> places an upper limit of 1020 as possible interrupt
>> id. Additional checks have been placed to prevent
>> out of bounds writes.
>
> In commit messages and in comments I see this narrow lines, any reason
> to make them short, except increasing number of lines?
>

done

>>          if (acpi_irq_balance || !link->irq.active) {
>> -               /*
>> -                * Select the best IRQ.  This is done in reverse to promote
>> -                * the use of IRQs 9, 10, 11, and >15.
>> -                */
>> -               for (i = (link->irq.possible_count - 1); i >= 0; i--) {
>> -                       if (acpi_irq_penalty[irq] >
>> -                           acpi_irq_penalty[link->irq.possible[i]])
>> -                               irq = link->irq.possible[i];
>> +
>> +               if (irq < ACPI_MAX_IRQS) {
>> +                       /*
>> +                        * Select the best IRQ.  This is done in reverse to
>> +                        * promote the use of IRQs 9, 10, 11, and >15.
>> +                        */
>> +                       for (i = (link->irq.possible_count - 1); i >= 0;
>> +                               i--) {
>
> Why not
>
> if ((acpi_irq_balance || !link->irq.active) && irq < ACPI_MAX_IRQS) {
>   int i = link->irq.possible_count;
>
>   while (--i) {
>   …
>   }
> }

done

>
>> +                               if ((link->irq.possible[i] < ACPI_MAX_IRQS) &&
>> +                                   (acpi_irq_penalty[irq] >
>> +                                   acpi_irq_penalty[link->irq.possible[i]]))
>> +                                       irq = link->irq.possible[i];
>> +                       }
>>                  }
>>          }
>>          if (acpi_irq_penalty[irq] >= PIRQ_PENALTY_ISA_ALWAYS) {
>

-- 
Sinan Kaya
Qualcomm Technologies, Inc. on behalf of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a 
Linux Foundation Collaborative Project
--
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH] acpi: add support for extended IRQ to PCI link
@ 2015-11-09 22:29     ` Sinan Kaya
  0 siblings, 0 replies; 32+ messages in thread
From: Sinan Kaya @ 2015-11-09 22:29 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: linux-acpi, timur, cov, jcm, Andy Gross, linux-arm-msm,
	linux-arm Mailing List, Rafael J. Wysocki, Len Brown,
	linux-kernel



On 11/8/2015 3:35 PM, Andy Shevchenko wrote:
> On Sun, Nov 8, 2015 at 6:07 PM, Sinan Kaya <okaya@codeaurora.org> wrote:
>> The ACPI compiler uses the extended format when
>> used interrupt numbers are greater than 256.
>> The PCI link code currently only supports simple
>> interrupt format. The IRQ numbers are represented
>> using 32 bits when extended IRQ syntax. This patch
>> changes the interrupt number type to 32 bits and
>> places an upper limit of 1020 as possible interrupt
>> id. Additional checks have been placed to prevent
>> out of bounds writes.
>
> In commit messages and in comments I see this narrow lines, any reason
> to make them short, except increasing number of lines?
>

done

>>          if (acpi_irq_balance || !link->irq.active) {
>> -               /*
>> -                * Select the best IRQ.  This is done in reverse to promote
>> -                * the use of IRQs 9, 10, 11, and >15.
>> -                */
>> -               for (i = (link->irq.possible_count - 1); i >= 0; i--) {
>> -                       if (acpi_irq_penalty[irq] >
>> -                           acpi_irq_penalty[link->irq.possible[i]])
>> -                               irq = link->irq.possible[i];
>> +
>> +               if (irq < ACPI_MAX_IRQS) {
>> +                       /*
>> +                        * Select the best IRQ.  This is done in reverse to
>> +                        * promote the use of IRQs 9, 10, 11, and >15.
>> +                        */
>> +                       for (i = (link->irq.possible_count - 1); i >= 0;
>> +                               i--) {
>
> Why not
>
> if ((acpi_irq_balance || !link->irq.active) && irq < ACPI_MAX_IRQS) {
>   int i = link->irq.possible_count;
>
>   while (--i) {
>   …
>   }
> }

done

>
>> +                               if ((link->irq.possible[i] < ACPI_MAX_IRQS) &&
>> +                                   (acpi_irq_penalty[irq] >
>> +                                   acpi_irq_penalty[link->irq.possible[i]]))
>> +                                       irq = link->irq.possible[i];
>> +                       }
>>                  }
>>          }
>>          if (acpi_irq_penalty[irq] >= PIRQ_PENALTY_ISA_ALWAYS) {
>

-- 
Sinan Kaya
Qualcomm Technologies, Inc. on behalf of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a 
Linux Foundation Collaborative Project

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

* [PATCH] acpi: add support for extended IRQ to PCI link
@ 2015-11-09 22:29     ` Sinan Kaya
  0 siblings, 0 replies; 32+ messages in thread
From: Sinan Kaya @ 2015-11-09 22:29 UTC (permalink / raw)
  To: linux-arm-kernel



On 11/8/2015 3:35 PM, Andy Shevchenko wrote:
> On Sun, Nov 8, 2015 at 6:07 PM, Sinan Kaya <okaya@codeaurora.org> wrote:
>> The ACPI compiler uses the extended format when
>> used interrupt numbers are greater than 256.
>> The PCI link code currently only supports simple
>> interrupt format. The IRQ numbers are represented
>> using 32 bits when extended IRQ syntax. This patch
>> changes the interrupt number type to 32 bits and
>> places an upper limit of 1020 as possible interrupt
>> id. Additional checks have been placed to prevent
>> out of bounds writes.
>
> In commit messages and in comments I see this narrow lines, any reason
> to make them short, except increasing number of lines?
>

done

>>          if (acpi_irq_balance || !link->irq.active) {
>> -               /*
>> -                * Select the best IRQ.  This is done in reverse to promote
>> -                * the use of IRQs 9, 10, 11, and >15.
>> -                */
>> -               for (i = (link->irq.possible_count - 1); i >= 0; i--) {
>> -                       if (acpi_irq_penalty[irq] >
>> -                           acpi_irq_penalty[link->irq.possible[i]])
>> -                               irq = link->irq.possible[i];
>> +
>> +               if (irq < ACPI_MAX_IRQS) {
>> +                       /*
>> +                        * Select the best IRQ.  This is done in reverse to
>> +                        * promote the use of IRQs 9, 10, 11, and >15.
>> +                        */
>> +                       for (i = (link->irq.possible_count - 1); i >= 0;
>> +                               i--) {
>
> Why not
>
> if ((acpi_irq_balance || !link->irq.active) && irq < ACPI_MAX_IRQS) {
>   int i = link->irq.possible_count;
>
>   while (--i) {
>   ?
>   }
> }

done

>
>> +                               if ((link->irq.possible[i] < ACPI_MAX_IRQS) &&
>> +                                   (acpi_irq_penalty[irq] >
>> +                                   acpi_irq_penalty[link->irq.possible[i]]))
>> +                                       irq = link->irq.possible[i];
>> +                       }
>>                  }
>>          }
>>          if (acpi_irq_penalty[irq] >= PIRQ_PENALTY_ISA_ALWAYS) {
>

-- 
Sinan Kaya
Qualcomm Technologies, Inc. on behalf of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a 
Linux Foundation Collaborative Project

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

* Re: [PATCH] acpi: add support for extended IRQ to PCI link
  2015-11-09  0:05       ` Timur Tabi
@ 2015-11-09 21:49         ` Rafael J. Wysocki
  -1 siblings, 0 replies; 32+ messages in thread
From: Rafael J. Wysocki @ 2015-11-09 21:49 UTC (permalink / raw)
  To: Timur Tabi
  Cc: Sinan Kaya, linux-acpi, cov, jcm, agross, linux-arm-msm,
	linux-arm-kernel, Len Brown, linux-kernel

On Sunday, November 08, 2015 06:05:48 PM Timur Tabi wrote:
> Sinan Kaya wrote:
> >>
> > 1020 is the maximum interrupt ID that can be directed to an ARM SPI
> > interrupt according to ARM architecture.
> 
> IMHO, that's something that belongs in the patch description.

Good point.

Thanks,
Rafael

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

* [PATCH] acpi: add support for extended IRQ to PCI link
@ 2015-11-09 21:49         ` Rafael J. Wysocki
  0 siblings, 0 replies; 32+ messages in thread
From: Rafael J. Wysocki @ 2015-11-09 21:49 UTC (permalink / raw)
  To: linux-arm-kernel

On Sunday, November 08, 2015 06:05:48 PM Timur Tabi wrote:
> Sinan Kaya wrote:
> >>
> > 1020 is the maximum interrupt ID that can be directed to an ARM SPI
> > interrupt according to ARM architecture.
> 
> IMHO, that's something that belongs in the patch description.

Good point.

Thanks,
Rafael

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

* Re: [PATCH] acpi: add support for extended IRQ to PCI link
  2015-11-09 13:50       ` Timur Tabi
@ 2015-11-09 16:28         ` Sinan Kaya
  -1 siblings, 0 replies; 32+ messages in thread
From: Sinan Kaya @ 2015-11-09 16:28 UTC (permalink / raw)
  To: Timur Tabi, Jiang Liu, linux-acpi, cov, jcm
  Cc: agross, linux-arm-msm, linux-arm-kernel, Rafael J. Wysocki,
	Len Brown, linux-kernel



On 11/9/2015 8:50 AM, Timur Tabi wrote:
> Sinan Kaya wrote:
>>
>> I'm concerned about this though since you warned. This used to consume
>> 1024 bytes now 4096 bytes.
>>
>> static int acpi_irq_penalty[ACPI_MAX_IRQS] = {
>>      PIRQ_PENALTY_ISA_ALWAYS,    /* IRQ0 timer */
>> ...
>> }
>
> As long as it's not ever put on the stack, it should be fine.
>

Alright...

If 1k global is OK, 4k global should be OK too.

-- 
Sinan Kaya
Qualcomm Technologies, Inc. on behalf of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a 
Linux Foundation Collaborative Project

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

* [PATCH] acpi: add support for extended IRQ to PCI link
@ 2015-11-09 16:28         ` Sinan Kaya
  0 siblings, 0 replies; 32+ messages in thread
From: Sinan Kaya @ 2015-11-09 16:28 UTC (permalink / raw)
  To: linux-arm-kernel



On 11/9/2015 8:50 AM, Timur Tabi wrote:
> Sinan Kaya wrote:
>>
>> I'm concerned about this though since you warned. This used to consume
>> 1024 bytes now 4096 bytes.
>>
>> static int acpi_irq_penalty[ACPI_MAX_IRQS] = {
>>      PIRQ_PENALTY_ISA_ALWAYS,    /* IRQ0 timer */
>> ...
>> }
>
> As long as it's not ever put on the stack, it should be fine.
>

Alright...

If 1k global is OK, 4k global should be OK too.

-- 
Sinan Kaya
Qualcomm Technologies, Inc. on behalf of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a 
Linux Foundation Collaborative Project

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

* Re: [PATCH] acpi: add support for extended IRQ to PCI link
  2015-11-09  5:45     ` Sinan Kaya
@ 2015-11-09 13:50       ` Timur Tabi
  -1 siblings, 0 replies; 32+ messages in thread
From: Timur Tabi @ 2015-11-09 13:50 UTC (permalink / raw)
  To: Sinan Kaya, Jiang Liu, linux-acpi, cov, jcm
  Cc: agross, linux-arm-msm, linux-arm-kernel, Rafael J. Wysocki,
	Len Brown, linux-kernel

Sinan Kaya wrote:
>
> I'm concerned about this though since you warned. This used to consume
> 1024 bytes now 4096 bytes.
>
> static int acpi_irq_penalty[ACPI_MAX_IRQS] = {
>      PIRQ_PENALTY_ISA_ALWAYS,    /* IRQ0 timer */
> ...
> }

As long as it's not ever put on the stack, it should be fine.

-- 
Sent by an employee of the Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the
Code Aurora Forum, hosted by The Linux Foundation.

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

* [PATCH] acpi: add support for extended IRQ to PCI link
@ 2015-11-09 13:50       ` Timur Tabi
  0 siblings, 0 replies; 32+ messages in thread
From: Timur Tabi @ 2015-11-09 13:50 UTC (permalink / raw)
  To: linux-arm-kernel

Sinan Kaya wrote:
>
> I'm concerned about this though since you warned. This used to consume
> 1024 bytes now 4096 bytes.
>
> static int acpi_irq_penalty[ACPI_MAX_IRQS] = {
>      PIRQ_PENALTY_ISA_ALWAYS,    /* IRQ0 timer */
> ...
> }

As long as it's not ever put on the stack, it should be fine.

-- 
Sent by an employee of the Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the
Code Aurora Forum, hosted by The Linux Foundation.

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

* Re: [PATCH] acpi: add support for extended IRQ to PCI link
  2015-11-09  5:45     ` Sinan Kaya
@ 2015-11-09  8:45       ` Jiang Liu
  -1 siblings, 0 replies; 32+ messages in thread
From: Jiang Liu @ 2015-11-09  8:45 UTC (permalink / raw)
  To: Sinan Kaya, linux-acpi, timur, cov, jcm
  Cc: agross, linux-arm-msm, linux-arm-kernel, Rafael J. Wysocki,
	Len Brown, linux-kernel

On 2015/11/9 13:45, Sinan Kaya wrote:
> 
> 
> On 11/9/2015 12:24 AM, Jiang Liu wrote:
>>> +    u32 possible[ACPI_PCI_LINK_MAX_POSSIBLE];
>>> >      u8 initialized:1;
>>> >      u8 reserved:7;
>>> >  };
>> Hi Sinan,
>>     This data structure become some sort of big, any idea to reduce
>> memory consumption?
>> Thanks,
>> Gerry
>>
> Hi Gerry,
> 
> There are two constants in the code.
> 
> #define ACPI_PCI_LINK_MAX_POSSIBLE    16
> 
> I changed the data type above. Previously it was consuming 16 bytes now
> 64 bytes.
Aha, I made a mistake. ACPI_PCI_LINK_MAX_POSSIBLE hasn't been changed,
so the space increasing is not so big:)

> 
> The second one is this.
> 
> #define ACPI_MAX_IRQS 256
> 
> I changed ACPI_MAX_IRQS to 1020 from 256. Let's assume 1024.
> 
> I'm concerned about this though since you warned. This used to consume
> 1024 bytes now 4096 bytes.
> 
> static int acpi_irq_penalty[ACPI_MAX_IRQS] = {
>     PIRQ_PENALTY_ISA_ALWAYS,    /* IRQ0 timer */
> ...
> }
> 
> Sinan
> 

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

* [PATCH] acpi: add support for extended IRQ to PCI link
@ 2015-11-09  8:45       ` Jiang Liu
  0 siblings, 0 replies; 32+ messages in thread
From: Jiang Liu @ 2015-11-09  8:45 UTC (permalink / raw)
  To: linux-arm-kernel

On 2015/11/9 13:45, Sinan Kaya wrote:
> 
> 
> On 11/9/2015 12:24 AM, Jiang Liu wrote:
>>> +    u32 possible[ACPI_PCI_LINK_MAX_POSSIBLE];
>>> >      u8 initialized:1;
>>> >      u8 reserved:7;
>>> >  };
>> Hi Sinan,
>>     This data structure become some sort of big, any idea to reduce
>> memory consumption?
>> Thanks,
>> Gerry
>>
> Hi Gerry,
> 
> There are two constants in the code.
> 
> #define ACPI_PCI_LINK_MAX_POSSIBLE    16
> 
> I changed the data type above. Previously it was consuming 16 bytes now
> 64 bytes.
Aha, I made a mistake. ACPI_PCI_LINK_MAX_POSSIBLE hasn't been changed,
so the space increasing is not so big:)

> 
> The second one is this.
> 
> #define ACPI_MAX_IRQS 256
> 
> I changed ACPI_MAX_IRQS to 1020 from 256. Let's assume 1024.
> 
> I'm concerned about this though since you warned. This used to consume
> 1024 bytes now 4096 bytes.
> 
> static int acpi_irq_penalty[ACPI_MAX_IRQS] = {
>     PIRQ_PENALTY_ISA_ALWAYS,    /* IRQ0 timer */
> ...
> }
> 
> Sinan
> 

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

* Re: [PATCH] acpi: add support for extended IRQ to PCI link
  2015-11-09  5:24   ` Jiang Liu
@ 2015-11-09  5:45     ` Sinan Kaya
  -1 siblings, 0 replies; 32+ messages in thread
From: Sinan Kaya @ 2015-11-09  5:45 UTC (permalink / raw)
  To: Jiang Liu, linux-acpi, timur, cov, jcm
  Cc: agross, linux-arm-msm, linux-arm-kernel, Rafael J. Wysocki,
	Len Brown, linux-kernel



On 11/9/2015 12:24 AM, Jiang Liu wrote:
>> +	u32 possible[ACPI_PCI_LINK_MAX_POSSIBLE];
>> >  	u8 initialized:1;
>> >  	u8 reserved:7;
>> >  };
> Hi Sinan,
> 	This data structure become some sort of big, any idea to reduce
> memory consumption?
> Thanks,
> Gerry
>
Hi Gerry,

There are two constants in the code.

#define ACPI_PCI_LINK_MAX_POSSIBLE	16

I changed the data type above. Previously it was consuming 16 bytes now 
64 bytes.

The second one is this.

#define ACPI_MAX_IRQS 256

I changed ACPI_MAX_IRQS to 1020 from 256. Let's assume 1024.

I'm concerned about this though since you warned. This used to consume 
1024 bytes now 4096 bytes.

static int acpi_irq_penalty[ACPI_MAX_IRQS] = {
	PIRQ_PENALTY_ISA_ALWAYS,	/* IRQ0 timer */
...
}

Sinan

-- 
Sinan Kaya
Qualcomm Technologies, Inc. on behalf of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a 
Linux Foundation Collaborative Project

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

* [PATCH] acpi: add support for extended IRQ to PCI link
@ 2015-11-09  5:45     ` Sinan Kaya
  0 siblings, 0 replies; 32+ messages in thread
From: Sinan Kaya @ 2015-11-09  5:45 UTC (permalink / raw)
  To: linux-arm-kernel



On 11/9/2015 12:24 AM, Jiang Liu wrote:
>> +	u32 possible[ACPI_PCI_LINK_MAX_POSSIBLE];
>> >  	u8 initialized:1;
>> >  	u8 reserved:7;
>> >  };
> Hi Sinan,
> 	This data structure become some sort of big, any idea to reduce
> memory consumption?
> Thanks,
> Gerry
>
Hi Gerry,

There are two constants in the code.

#define ACPI_PCI_LINK_MAX_POSSIBLE	16

I changed the data type above. Previously it was consuming 16 bytes now 
64 bytes.

The second one is this.

#define ACPI_MAX_IRQS 256

I changed ACPI_MAX_IRQS to 1020 from 256. Let's assume 1024.

I'm concerned about this though since you warned. This used to consume 
1024 bytes now 4096 bytes.

static int acpi_irq_penalty[ACPI_MAX_IRQS] = {
	PIRQ_PENALTY_ISA_ALWAYS,	/* IRQ0 timer */
...
}

Sinan

-- 
Sinan Kaya
Qualcomm Technologies, Inc. on behalf of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a 
Linux Foundation Collaborative Project

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

* Re: [PATCH] acpi: add support for extended IRQ to PCI link
  2015-11-08 16:07 ` Sinan Kaya
@ 2015-11-09  5:24   ` Jiang Liu
  -1 siblings, 0 replies; 32+ messages in thread
From: Jiang Liu @ 2015-11-09  5:24 UTC (permalink / raw)
  To: Sinan Kaya, linux-acpi, timur, cov, jcm
  Cc: agross, linux-arm-msm, linux-arm-kernel, Rafael J. Wysocki,
	Len Brown, linux-kernel

On 2015/11/9 0:07, Sinan Kaya wrote:
> The ACPI compiler uses the extended format when
> used interrupt numbers are greater than 256.
> The PCI link code currently only supports simple
> interrupt format. The IRQ numbers are represented
> using 32 bits when extended IRQ syntax. This patch
> changes the interrupt number type to 32 bits and
> places an upper limit of 1020 as possible interrupt
> id. Additional checks have been placed to prevent
> out of bounds writes.
> 
> Signed-off-by: Sinan Kaya <okaya@codeaurora.org>
> ---
>  drivers/acpi/pci_link.c | 35 ++++++++++++++++++++++-------------
>  1 file changed, 22 insertions(+), 13 deletions(-)
> 
> diff --git a/drivers/acpi/pci_link.c b/drivers/acpi/pci_link.c
> index 7c8408b..18a9190 100644
> --- a/drivers/acpi/pci_link.c
> +++ b/drivers/acpi/pci_link.c
> @@ -1,6 +1,7 @@
>  /*
>   *  pci_link.c - ACPI PCI Interrupt Link Device Driver ($Revision: 34 $)
>   *
> + *  Copyright (c) 2015, The Linux Foundation. All rights reserved.
>   *  Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com>
>   *  Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
>   *  Copyright (C) 2002       Dominik Brodowski <devel@brodo.de>
> @@ -67,12 +68,12 @@ static struct acpi_scan_handler pci_link_handler = {
>   * later even the link is disable. Instead, we just repick the active irq
>   */
>  struct acpi_pci_link_irq {
> -	u8 active;		/* Current IRQ */
> +	u32 active;		/* Current IRQ */
>  	u8 triggering;		/* All IRQs */
>  	u8 polarity;		/* All IRQs */
>  	u8 resource_type;
>  	u8 possible_count;
> -	u8 possible[ACPI_PCI_LINK_MAX_POSSIBLE];
> +	u32 possible[ACPI_PCI_LINK_MAX_POSSIBLE];
>  	u8 initialized:1;
>  	u8 reserved:7;
>  };
Hi Sinan,
	This data structure become some sort of big, any idea to reduce
memory consumption?
Thanks,
Gerry

> @@ -437,7 +438,7 @@ static int acpi_pci_link_set(struct acpi_pci_link *link, int irq)
>   * enabled system.
>   */
>  
> -#define ACPI_MAX_IRQS		256
> +#define ACPI_MAX_IRQS		1020
>  #define ACPI_MAX_ISA_IRQ	16
>  
>  #define PIRQ_PENALTY_PCI_AVAILABLE	(0)
> @@ -493,7 +494,8 @@ int __init acpi_irq_penalty_init(void)
>  					    penalty;
>  			}
>  
> -		} else if (link->irq.active) {
> +		} else if (link->irq.active &&
> +			(link->irq.active < ACPI_MAX_IRQS)) {
>  			acpi_irq_penalty[link->irq.active] +=
>  			    PIRQ_PENALTY_PCI_POSSIBLE;
>  		}
> @@ -542,14 +544,19 @@ static int acpi_pci_link_allocate(struct acpi_pci_link *link)
>  		irq = link->irq.possible[link->irq.possible_count - 1];
>  
>  	if (acpi_irq_balance || !link->irq.active) {
> -		/*
> -		 * Select the best IRQ.  This is done in reverse to promote
> -		 * the use of IRQs 9, 10, 11, and >15.
> -		 */
> -		for (i = (link->irq.possible_count - 1); i >= 0; i--) {
> -			if (acpi_irq_penalty[irq] >
> -			    acpi_irq_penalty[link->irq.possible[i]])
> -				irq = link->irq.possible[i];
> +
> +		if (irq < ACPI_MAX_IRQS) {
> +			/*
> +			 * Select the best IRQ.  This is done in reverse to
> +			 * promote the use of IRQs 9, 10, 11, and >15.
> +			 */
> +			for (i = (link->irq.possible_count - 1); i >= 0;
> +				i--) {
> +				if ((link->irq.possible[i] < ACPI_MAX_IRQS) &&
> +				    (acpi_irq_penalty[irq] >
> +				    acpi_irq_penalty[link->irq.possible[i]]))
> +					irq = link->irq.possible[i];
> +			}
>  		}
>  	}
>  	if (acpi_irq_penalty[irq] >= PIRQ_PENALTY_ISA_ALWAYS) {
> @@ -568,7 +575,9 @@ static int acpi_pci_link_allocate(struct acpi_pci_link *link)
>  			    acpi_device_bid(link->device));
>  		return -ENODEV;
>  	} else {
> -		acpi_irq_penalty[link->irq.active] += PIRQ_PENALTY_PCI_USING;
> +		if (link->irq.active < ACPI_MAX_IRQS)
> +			acpi_irq_penalty[link->irq.active] +=
> +				PIRQ_PENALTY_PCI_USING;
>  		printk(KERN_WARNING PREFIX "%s [%s] enabled at IRQ %d\n",
>  		       acpi_device_name(link->device),
>  		       acpi_device_bid(link->device), link->irq.active);
> 

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

* [PATCH] acpi: add support for extended IRQ to PCI link
@ 2015-11-09  5:24   ` Jiang Liu
  0 siblings, 0 replies; 32+ messages in thread
From: Jiang Liu @ 2015-11-09  5:24 UTC (permalink / raw)
  To: linux-arm-kernel

On 2015/11/9 0:07, Sinan Kaya wrote:
> The ACPI compiler uses the extended format when
> used interrupt numbers are greater than 256.
> The PCI link code currently only supports simple
> interrupt format. The IRQ numbers are represented
> using 32 bits when extended IRQ syntax. This patch
> changes the interrupt number type to 32 bits and
> places an upper limit of 1020 as possible interrupt
> id. Additional checks have been placed to prevent
> out of bounds writes.
> 
> Signed-off-by: Sinan Kaya <okaya@codeaurora.org>
> ---
>  drivers/acpi/pci_link.c | 35 ++++++++++++++++++++++-------------
>  1 file changed, 22 insertions(+), 13 deletions(-)
> 
> diff --git a/drivers/acpi/pci_link.c b/drivers/acpi/pci_link.c
> index 7c8408b..18a9190 100644
> --- a/drivers/acpi/pci_link.c
> +++ b/drivers/acpi/pci_link.c
> @@ -1,6 +1,7 @@
>  /*
>   *  pci_link.c - ACPI PCI Interrupt Link Device Driver ($Revision: 34 $)
>   *
> + *  Copyright (c) 2015, The Linux Foundation. All rights reserved.
>   *  Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com>
>   *  Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
>   *  Copyright (C) 2002       Dominik Brodowski <devel@brodo.de>
> @@ -67,12 +68,12 @@ static struct acpi_scan_handler pci_link_handler = {
>   * later even the link is disable. Instead, we just repick the active irq
>   */
>  struct acpi_pci_link_irq {
> -	u8 active;		/* Current IRQ */
> +	u32 active;		/* Current IRQ */
>  	u8 triggering;		/* All IRQs */
>  	u8 polarity;		/* All IRQs */
>  	u8 resource_type;
>  	u8 possible_count;
> -	u8 possible[ACPI_PCI_LINK_MAX_POSSIBLE];
> +	u32 possible[ACPI_PCI_LINK_MAX_POSSIBLE];
>  	u8 initialized:1;
>  	u8 reserved:7;
>  };
Hi Sinan,
	This data structure become some sort of big, any idea to reduce
memory consumption?
Thanks,
Gerry

> @@ -437,7 +438,7 @@ static int acpi_pci_link_set(struct acpi_pci_link *link, int irq)
>   * enabled system.
>   */
>  
> -#define ACPI_MAX_IRQS		256
> +#define ACPI_MAX_IRQS		1020
>  #define ACPI_MAX_ISA_IRQ	16
>  
>  #define PIRQ_PENALTY_PCI_AVAILABLE	(0)
> @@ -493,7 +494,8 @@ int __init acpi_irq_penalty_init(void)
>  					    penalty;
>  			}
>  
> -		} else if (link->irq.active) {
> +		} else if (link->irq.active &&
> +			(link->irq.active < ACPI_MAX_IRQS)) {
>  			acpi_irq_penalty[link->irq.active] +=
>  			    PIRQ_PENALTY_PCI_POSSIBLE;
>  		}
> @@ -542,14 +544,19 @@ static int acpi_pci_link_allocate(struct acpi_pci_link *link)
>  		irq = link->irq.possible[link->irq.possible_count - 1];
>  
>  	if (acpi_irq_balance || !link->irq.active) {
> -		/*
> -		 * Select the best IRQ.  This is done in reverse to promote
> -		 * the use of IRQs 9, 10, 11, and >15.
> -		 */
> -		for (i = (link->irq.possible_count - 1); i >= 0; i--) {
> -			if (acpi_irq_penalty[irq] >
> -			    acpi_irq_penalty[link->irq.possible[i]])
> -				irq = link->irq.possible[i];
> +
> +		if (irq < ACPI_MAX_IRQS) {
> +			/*
> +			 * Select the best IRQ.  This is done in reverse to
> +			 * promote the use of IRQs 9, 10, 11, and >15.
> +			 */
> +			for (i = (link->irq.possible_count - 1); i >= 0;
> +				i--) {
> +				if ((link->irq.possible[i] < ACPI_MAX_IRQS) &&
> +				    (acpi_irq_penalty[irq] >
> +				    acpi_irq_penalty[link->irq.possible[i]]))
> +					irq = link->irq.possible[i];
> +			}
>  		}
>  	}
>  	if (acpi_irq_penalty[irq] >= PIRQ_PENALTY_ISA_ALWAYS) {
> @@ -568,7 +575,9 @@ static int acpi_pci_link_allocate(struct acpi_pci_link *link)
>  			    acpi_device_bid(link->device));
>  		return -ENODEV;
>  	} else {
> -		acpi_irq_penalty[link->irq.active] += PIRQ_PENALTY_PCI_USING;
> +		if (link->irq.active < ACPI_MAX_IRQS)
> +			acpi_irq_penalty[link->irq.active] +=
> +				PIRQ_PENALTY_PCI_USING;
>  		printk(KERN_WARNING PREFIX "%s [%s] enabled at IRQ %d\n",
>  		       acpi_device_name(link->device),
>  		       acpi_device_bid(link->device), link->irq.active);
> 

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

* Re: [PATCH] acpi: add support for extended IRQ to PCI link
  2015-11-09  0:04     ` Sinan Kaya
@ 2015-11-09  0:05       ` Timur Tabi
  -1 siblings, 0 replies; 32+ messages in thread
From: Timur Tabi @ 2015-11-09  0:05 UTC (permalink / raw)
  To: Sinan Kaya, linux-acpi, cov, jcm
  Cc: agross, linux-arm-msm, linux-arm-kernel, Rafael J. Wysocki,
	Len Brown, linux-kernel

Sinan Kaya wrote:
>>
> 1020 is the maximum interrupt ID that can be directed to an ARM SPI
> interrupt according to ARM architecture.

IMHO, that's something that belongs in the patch description.

-- 
Sent by an employee of the Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the
Code Aurora Forum, hosted by The Linux Foundation.

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

* [PATCH] acpi: add support for extended IRQ to PCI link
@ 2015-11-09  0:05       ` Timur Tabi
  0 siblings, 0 replies; 32+ messages in thread
From: Timur Tabi @ 2015-11-09  0:05 UTC (permalink / raw)
  To: linux-arm-kernel

Sinan Kaya wrote:
>>
> 1020 is the maximum interrupt ID that can be directed to an ARM SPI
> interrupt according to ARM architecture.

IMHO, that's something that belongs in the patch description.

-- 
Sent by an employee of the Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the
Code Aurora Forum, hosted by The Linux Foundation.

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

* Re: [PATCH] acpi: add support for extended IRQ to PCI link
  2015-11-08 16:11   ` Timur Tabi
@ 2015-11-09  0:04     ` Sinan Kaya
  -1 siblings, 0 replies; 32+ messages in thread
From: Sinan Kaya @ 2015-11-09  0:04 UTC (permalink / raw)
  To: Timur Tabi, linux-acpi, cov, jcm
  Cc: agross, linux-arm-msm, linux-arm-kernel, Rafael J. Wysocki,
	Len Brown, linux-kernel



On 11/8/2015 11:11 AM, Timur Tabi wrote:
> Sinan Kaya wrote:
>> -#define ACPI_MAX_IRQS        256
>> +#define ACPI_MAX_IRQS        1020
>
> Why 1020?  Why not 1024?
>
1020 is the maximum interrupt ID that can be directed to an ARM SPI 
interrupt according to ARM architecture.

-- 
Sinan Kaya
Qualcomm Technologies, Inc. on behalf of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a 
Linux Foundation Collaborative Project

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

* [PATCH] acpi: add support for extended IRQ to PCI link
@ 2015-11-09  0:04     ` Sinan Kaya
  0 siblings, 0 replies; 32+ messages in thread
From: Sinan Kaya @ 2015-11-09  0:04 UTC (permalink / raw)
  To: linux-arm-kernel



On 11/8/2015 11:11 AM, Timur Tabi wrote:
> Sinan Kaya wrote:
>> -#define ACPI_MAX_IRQS        256
>> +#define ACPI_MAX_IRQS        1020
>
> Why 1020?  Why not 1024?
>
1020 is the maximum interrupt ID that can be directed to an ARM SPI 
interrupt according to ARM architecture.

-- 
Sinan Kaya
Qualcomm Technologies, Inc. on behalf of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a 
Linux Foundation Collaborative Project

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

* Re: [PATCH] acpi: add support for extended IRQ to PCI link
  2015-11-08 16:07 ` Sinan Kaya
@ 2015-11-08 20:35   ` Andy Shevchenko
  -1 siblings, 0 replies; 32+ messages in thread
From: Andy Shevchenko @ 2015-11-08 20:35 UTC (permalink / raw)
  To: Sinan Kaya
  Cc: linux-acpi, timur, cov, jcm, Andy Gross, linux-arm-msm,
	linux-arm Mailing List, Rafael J. Wysocki, Len Brown,
	linux-kernel

On Sun, Nov 8, 2015 at 6:07 PM, Sinan Kaya <okaya@codeaurora.org> wrote:
> The ACPI compiler uses the extended format when
> used interrupt numbers are greater than 256.
> The PCI link code currently only supports simple
> interrupt format. The IRQ numbers are represented
> using 32 bits when extended IRQ syntax. This patch
> changes the interrupt number type to 32 bits and
> places an upper limit of 1020 as possible interrupt
> id. Additional checks have been placed to prevent
> out of bounds writes.

In commit messages and in comments I see this narrow lines, any reason
to make them short, except increasing number of lines?

> --- a/drivers/acpi/pci_link.c
> +++ b/drivers/acpi/pci_link.c
> @@ -1,6 +1,7 @@
>  /*
>   *  pci_link.c - ACPI PCI Interrupt Link Device Driver ($Revision: 34 $)
>   *
> + *  Copyright (c) 2015, The Linux Foundation. All rights reserved.
>   *  Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com>
>   *  Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
>   *  Copyright (C) 2002       Dominik Brodowski <devel@brodo.de>
> @@ -67,12 +68,12 @@ static struct acpi_scan_handler pci_link_handler = {
>   * later even the link is disable. Instead, we just repick the active irq
>   */
>  struct acpi_pci_link_irq {
> -       u8 active;              /* Current IRQ */
> +       u32 active;             /* Current IRQ */
>         u8 triggering;          /* All IRQs */
>         u8 polarity;            /* All IRQs */
>         u8 resource_type;
>         u8 possible_count;
> -       u8 possible[ACPI_PCI_LINK_MAX_POSSIBLE];
> +       u32 possible[ACPI_PCI_LINK_MAX_POSSIBLE];
>         u8 initialized:1;
>         u8 reserved:7;
>  };
> @@ -437,7 +438,7 @@ static int acpi_pci_link_set(struct acpi_pci_link *link, int irq)
>   * enabled system.
>   */
>
> -#define ACPI_MAX_IRQS          256
> +#define ACPI_MAX_IRQS          1020
>  #define ACPI_MAX_ISA_IRQ       16
>
>  #define PIRQ_PENALTY_PCI_AVAILABLE     (0)
> @@ -493,7 +494,8 @@ int __init acpi_irq_penalty_init(void)
>                                             penalty;
>                         }
>
> -               } else if (link->irq.active) {
> +               } else if (link->irq.active &&
> +                       (link->irq.active < ACPI_MAX_IRQS)) {
>                         acpi_irq_penalty[link->irq.active] +=
>                             PIRQ_PENALTY_PCI_POSSIBLE;
>                 }
> @@ -542,14 +544,19 @@ static int acpi_pci_link_allocate(struct acpi_pci_link *link)
>                 irq = link->irq.possible[link->irq.possible_count - 1];
>
>         if (acpi_irq_balance || !link->irq.active) {
> -               /*
> -                * Select the best IRQ.  This is done in reverse to promote
> -                * the use of IRQs 9, 10, 11, and >15.
> -                */
> -               for (i = (link->irq.possible_count - 1); i >= 0; i--) {
> -                       if (acpi_irq_penalty[irq] >
> -                           acpi_irq_penalty[link->irq.possible[i]])
> -                               irq = link->irq.possible[i];
> +
> +               if (irq < ACPI_MAX_IRQS) {
> +                       /*
> +                        * Select the best IRQ.  This is done in reverse to
> +                        * promote the use of IRQs 9, 10, 11, and >15.
> +                        */
> +                       for (i = (link->irq.possible_count - 1); i >= 0;
> +                               i--) {

Why not

if ((acpi_irq_balance || !link->irq.active) && irq < ACPI_MAX_IRQS) {
 int i = link->irq.possible_count;

 while (--i) {
 …
 }
}

> +                               if ((link->irq.possible[i] < ACPI_MAX_IRQS) &&
> +                                   (acpi_irq_penalty[irq] >
> +                                   acpi_irq_penalty[link->irq.possible[i]]))
> +                                       irq = link->irq.possible[i];
> +                       }
>                 }
>         }
>         if (acpi_irq_penalty[irq] >= PIRQ_PENALTY_ISA_ALWAYS) {

-- 
With Best Regards,
Andy Shevchenko

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

* [PATCH] acpi: add support for extended IRQ to PCI link
@ 2015-11-08 20:35   ` Andy Shevchenko
  0 siblings, 0 replies; 32+ messages in thread
From: Andy Shevchenko @ 2015-11-08 20:35 UTC (permalink / raw)
  To: linux-arm-kernel

On Sun, Nov 8, 2015 at 6:07 PM, Sinan Kaya <okaya@codeaurora.org> wrote:
> The ACPI compiler uses the extended format when
> used interrupt numbers are greater than 256.
> The PCI link code currently only supports simple
> interrupt format. The IRQ numbers are represented
> using 32 bits when extended IRQ syntax. This patch
> changes the interrupt number type to 32 bits and
> places an upper limit of 1020 as possible interrupt
> id. Additional checks have been placed to prevent
> out of bounds writes.

In commit messages and in comments I see this narrow lines, any reason
to make them short, except increasing number of lines?

> --- a/drivers/acpi/pci_link.c
> +++ b/drivers/acpi/pci_link.c
> @@ -1,6 +1,7 @@
>  /*
>   *  pci_link.c - ACPI PCI Interrupt Link Device Driver ($Revision: 34 $)
>   *
> + *  Copyright (c) 2015, The Linux Foundation. All rights reserved.
>   *  Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com>
>   *  Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
>   *  Copyright (C) 2002       Dominik Brodowski <devel@brodo.de>
> @@ -67,12 +68,12 @@ static struct acpi_scan_handler pci_link_handler = {
>   * later even the link is disable. Instead, we just repick the active irq
>   */
>  struct acpi_pci_link_irq {
> -       u8 active;              /* Current IRQ */
> +       u32 active;             /* Current IRQ */
>         u8 triggering;          /* All IRQs */
>         u8 polarity;            /* All IRQs */
>         u8 resource_type;
>         u8 possible_count;
> -       u8 possible[ACPI_PCI_LINK_MAX_POSSIBLE];
> +       u32 possible[ACPI_PCI_LINK_MAX_POSSIBLE];
>         u8 initialized:1;
>         u8 reserved:7;
>  };
> @@ -437,7 +438,7 @@ static int acpi_pci_link_set(struct acpi_pci_link *link, int irq)
>   * enabled system.
>   */
>
> -#define ACPI_MAX_IRQS          256
> +#define ACPI_MAX_IRQS          1020
>  #define ACPI_MAX_ISA_IRQ       16
>
>  #define PIRQ_PENALTY_PCI_AVAILABLE     (0)
> @@ -493,7 +494,8 @@ int __init acpi_irq_penalty_init(void)
>                                             penalty;
>                         }
>
> -               } else if (link->irq.active) {
> +               } else if (link->irq.active &&
> +                       (link->irq.active < ACPI_MAX_IRQS)) {
>                         acpi_irq_penalty[link->irq.active] +=
>                             PIRQ_PENALTY_PCI_POSSIBLE;
>                 }
> @@ -542,14 +544,19 @@ static int acpi_pci_link_allocate(struct acpi_pci_link *link)
>                 irq = link->irq.possible[link->irq.possible_count - 1];
>
>         if (acpi_irq_balance || !link->irq.active) {
> -               /*
> -                * Select the best IRQ.  This is done in reverse to promote
> -                * the use of IRQs 9, 10, 11, and >15.
> -                */
> -               for (i = (link->irq.possible_count - 1); i >= 0; i--) {
> -                       if (acpi_irq_penalty[irq] >
> -                           acpi_irq_penalty[link->irq.possible[i]])
> -                               irq = link->irq.possible[i];
> +
> +               if (irq < ACPI_MAX_IRQS) {
> +                       /*
> +                        * Select the best IRQ.  This is done in reverse to
> +                        * promote the use of IRQs 9, 10, 11, and >15.
> +                        */
> +                       for (i = (link->irq.possible_count - 1); i >= 0;
> +                               i--) {

Why not

if ((acpi_irq_balance || !link->irq.active) && irq < ACPI_MAX_IRQS) {
 int i = link->irq.possible_count;

 while (--i) {
 ?
 }
}

> +                               if ((link->irq.possible[i] < ACPI_MAX_IRQS) &&
> +                                   (acpi_irq_penalty[irq] >
> +                                   acpi_irq_penalty[link->irq.possible[i]]))
> +                                       irq = link->irq.possible[i];
> +                       }
>                 }
>         }
>         if (acpi_irq_penalty[irq] >= PIRQ_PENALTY_ISA_ALWAYS) {

-- 
With Best Regards,
Andy Shevchenko

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

* Re: [PATCH] acpi: add support for extended IRQ to PCI link
  2015-11-08 16:07 ` Sinan Kaya
@ 2015-11-08 16:11   ` Timur Tabi
  -1 siblings, 0 replies; 32+ messages in thread
From: Timur Tabi @ 2015-11-08 16:11 UTC (permalink / raw)
  To: Sinan Kaya, linux-acpi, cov, jcm
  Cc: agross, linux-arm-msm, linux-arm-kernel, Rafael J. Wysocki,
	Len Brown, linux-kernel

Sinan Kaya wrote:
> -#define ACPI_MAX_IRQS		256
> +#define ACPI_MAX_IRQS		1020

Why 1020?  Why not 1024?

-- 
Sent by an employee of the Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the
Code Aurora Forum, hosted by The Linux Foundation.

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

* [PATCH] acpi: add support for extended IRQ to PCI link
@ 2015-11-08 16:11   ` Timur Tabi
  0 siblings, 0 replies; 32+ messages in thread
From: Timur Tabi @ 2015-11-08 16:11 UTC (permalink / raw)
  To: linux-arm-kernel

Sinan Kaya wrote:
> -#define ACPI_MAX_IRQS		256
> +#define ACPI_MAX_IRQS		1020

Why 1020?  Why not 1024?

-- 
Sent by an employee of the Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the
Code Aurora Forum, hosted by The Linux Foundation.

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

* [PATCH] acpi: add support for extended IRQ to PCI link
@ 2015-11-08 16:07 ` Sinan Kaya
  0 siblings, 0 replies; 32+ messages in thread
From: Sinan Kaya @ 2015-11-08 16:07 UTC (permalink / raw)
  To: linux-acpi, timur, cov, jcm
  Cc: agross, linux-arm-msm, linux-arm-kernel, Sinan Kaya,
	Rafael J. Wysocki, Len Brown, linux-kernel

The ACPI compiler uses the extended format when
used interrupt numbers are greater than 256.
The PCI link code currently only supports simple
interrupt format. The IRQ numbers are represented
using 32 bits when extended IRQ syntax. This patch
changes the interrupt number type to 32 bits and
places an upper limit of 1020 as possible interrupt
id. Additional checks have been placed to prevent
out of bounds writes.

Signed-off-by: Sinan Kaya <okaya@codeaurora.org>
---
 drivers/acpi/pci_link.c | 35 ++++++++++++++++++++++-------------
 1 file changed, 22 insertions(+), 13 deletions(-)

diff --git a/drivers/acpi/pci_link.c b/drivers/acpi/pci_link.c
index 7c8408b..18a9190 100644
--- a/drivers/acpi/pci_link.c
+++ b/drivers/acpi/pci_link.c
@@ -1,6 +1,7 @@
 /*
  *  pci_link.c - ACPI PCI Interrupt Link Device Driver ($Revision: 34 $)
  *
+ *  Copyright (c) 2015, The Linux Foundation. All rights reserved.
  *  Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com>
  *  Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
  *  Copyright (C) 2002       Dominik Brodowski <devel@brodo.de>
@@ -67,12 +68,12 @@ static struct acpi_scan_handler pci_link_handler = {
  * later even the link is disable. Instead, we just repick the active irq
  */
 struct acpi_pci_link_irq {
-	u8 active;		/* Current IRQ */
+	u32 active;		/* Current IRQ */
 	u8 triggering;		/* All IRQs */
 	u8 polarity;		/* All IRQs */
 	u8 resource_type;
 	u8 possible_count;
-	u8 possible[ACPI_PCI_LINK_MAX_POSSIBLE];
+	u32 possible[ACPI_PCI_LINK_MAX_POSSIBLE];
 	u8 initialized:1;
 	u8 reserved:7;
 };
@@ -437,7 +438,7 @@ static int acpi_pci_link_set(struct acpi_pci_link *link, int irq)
  * enabled system.
  */
 
-#define ACPI_MAX_IRQS		256
+#define ACPI_MAX_IRQS		1020
 #define ACPI_MAX_ISA_IRQ	16
 
 #define PIRQ_PENALTY_PCI_AVAILABLE	(0)
@@ -493,7 +494,8 @@ int __init acpi_irq_penalty_init(void)
 					    penalty;
 			}
 
-		} else if (link->irq.active) {
+		} else if (link->irq.active &&
+			(link->irq.active < ACPI_MAX_IRQS)) {
 			acpi_irq_penalty[link->irq.active] +=
 			    PIRQ_PENALTY_PCI_POSSIBLE;
 		}
@@ -542,14 +544,19 @@ static int acpi_pci_link_allocate(struct acpi_pci_link *link)
 		irq = link->irq.possible[link->irq.possible_count - 1];
 
 	if (acpi_irq_balance || !link->irq.active) {
-		/*
-		 * Select the best IRQ.  This is done in reverse to promote
-		 * the use of IRQs 9, 10, 11, and >15.
-		 */
-		for (i = (link->irq.possible_count - 1); i >= 0; i--) {
-			if (acpi_irq_penalty[irq] >
-			    acpi_irq_penalty[link->irq.possible[i]])
-				irq = link->irq.possible[i];
+
+		if (irq < ACPI_MAX_IRQS) {
+			/*
+			 * Select the best IRQ.  This is done in reverse to
+			 * promote the use of IRQs 9, 10, 11, and >15.
+			 */
+			for (i = (link->irq.possible_count - 1); i >= 0;
+				i--) {
+				if ((link->irq.possible[i] < ACPI_MAX_IRQS) &&
+				    (acpi_irq_penalty[irq] >
+				    acpi_irq_penalty[link->irq.possible[i]]))
+					irq = link->irq.possible[i];
+			}
 		}
 	}
 	if (acpi_irq_penalty[irq] >= PIRQ_PENALTY_ISA_ALWAYS) {
@@ -568,7 +575,9 @@ static int acpi_pci_link_allocate(struct acpi_pci_link *link)
 			    acpi_device_bid(link->device));
 		return -ENODEV;
 	} else {
-		acpi_irq_penalty[link->irq.active] += PIRQ_PENALTY_PCI_USING;
+		if (link->irq.active < ACPI_MAX_IRQS)
+			acpi_irq_penalty[link->irq.active] +=
+				PIRQ_PENALTY_PCI_USING;
 		printk(KERN_WARNING PREFIX "%s [%s] enabled at IRQ %d\n",
 		       acpi_device_name(link->device),
 		       acpi_device_bid(link->device), link->irq.active);
-- 
Qualcomm Technologies, Inc. on behalf of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project


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

* [PATCH] acpi: add support for extended IRQ to PCI link
@ 2015-11-08 16:07 ` Sinan Kaya
  0 siblings, 0 replies; 32+ messages in thread
From: Sinan Kaya @ 2015-11-08 16:07 UTC (permalink / raw)
  To: linux-arm-kernel

The ACPI compiler uses the extended format when
used interrupt numbers are greater than 256.
The PCI link code currently only supports simple
interrupt format. The IRQ numbers are represented
using 32 bits when extended IRQ syntax. This patch
changes the interrupt number type to 32 bits and
places an upper limit of 1020 as possible interrupt
id. Additional checks have been placed to prevent
out of bounds writes.

Signed-off-by: Sinan Kaya <okaya@codeaurora.org>
---
 drivers/acpi/pci_link.c | 35 ++++++++++++++++++++++-------------
 1 file changed, 22 insertions(+), 13 deletions(-)

diff --git a/drivers/acpi/pci_link.c b/drivers/acpi/pci_link.c
index 7c8408b..18a9190 100644
--- a/drivers/acpi/pci_link.c
+++ b/drivers/acpi/pci_link.c
@@ -1,6 +1,7 @@
 /*
  *  pci_link.c - ACPI PCI Interrupt Link Device Driver ($Revision: 34 $)
  *
+ *  Copyright (c) 2015, The Linux Foundation. All rights reserved.
  *  Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com>
  *  Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
  *  Copyright (C) 2002       Dominik Brodowski <devel@brodo.de>
@@ -67,12 +68,12 @@ static struct acpi_scan_handler pci_link_handler = {
  * later even the link is disable. Instead, we just repick the active irq
  */
 struct acpi_pci_link_irq {
-	u8 active;		/* Current IRQ */
+	u32 active;		/* Current IRQ */
 	u8 triggering;		/* All IRQs */
 	u8 polarity;		/* All IRQs */
 	u8 resource_type;
 	u8 possible_count;
-	u8 possible[ACPI_PCI_LINK_MAX_POSSIBLE];
+	u32 possible[ACPI_PCI_LINK_MAX_POSSIBLE];
 	u8 initialized:1;
 	u8 reserved:7;
 };
@@ -437,7 +438,7 @@ static int acpi_pci_link_set(struct acpi_pci_link *link, int irq)
  * enabled system.
  */
 
-#define ACPI_MAX_IRQS		256
+#define ACPI_MAX_IRQS		1020
 #define ACPI_MAX_ISA_IRQ	16
 
 #define PIRQ_PENALTY_PCI_AVAILABLE	(0)
@@ -493,7 +494,8 @@ int __init acpi_irq_penalty_init(void)
 					    penalty;
 			}
 
-		} else if (link->irq.active) {
+		} else if (link->irq.active &&
+			(link->irq.active < ACPI_MAX_IRQS)) {
 			acpi_irq_penalty[link->irq.active] +=
 			    PIRQ_PENALTY_PCI_POSSIBLE;
 		}
@@ -542,14 +544,19 @@ static int acpi_pci_link_allocate(struct acpi_pci_link *link)
 		irq = link->irq.possible[link->irq.possible_count - 1];
 
 	if (acpi_irq_balance || !link->irq.active) {
-		/*
-		 * Select the best IRQ.  This is done in reverse to promote
-		 * the use of IRQs 9, 10, 11, and >15.
-		 */
-		for (i = (link->irq.possible_count - 1); i >= 0; i--) {
-			if (acpi_irq_penalty[irq] >
-			    acpi_irq_penalty[link->irq.possible[i]])
-				irq = link->irq.possible[i];
+
+		if (irq < ACPI_MAX_IRQS) {
+			/*
+			 * Select the best IRQ.  This is done in reverse to
+			 * promote the use of IRQs 9, 10, 11, and >15.
+			 */
+			for (i = (link->irq.possible_count - 1); i >= 0;
+				i--) {
+				if ((link->irq.possible[i] < ACPI_MAX_IRQS) &&
+				    (acpi_irq_penalty[irq] >
+				    acpi_irq_penalty[link->irq.possible[i]]))
+					irq = link->irq.possible[i];
+			}
 		}
 	}
 	if (acpi_irq_penalty[irq] >= PIRQ_PENALTY_ISA_ALWAYS) {
@@ -568,7 +575,9 @@ static int acpi_pci_link_allocate(struct acpi_pci_link *link)
 			    acpi_device_bid(link->device));
 		return -ENODEV;
 	} else {
-		acpi_irq_penalty[link->irq.active] += PIRQ_PENALTY_PCI_USING;
+		if (link->irq.active < ACPI_MAX_IRQS)
+			acpi_irq_penalty[link->irq.active] +=
+				PIRQ_PENALTY_PCI_USING;
 		printk(KERN_WARNING PREFIX "%s [%s] enabled at IRQ %d\n",
 		       acpi_device_name(link->device),
 		       acpi_device_bid(link->device), link->irq.active);
-- 
Qualcomm Technologies, Inc. on behalf of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project

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

end of thread, other threads:[~2015-11-12 15:58 UTC | newest]

Thread overview: 32+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-11-12  6:14 [PATCH V2] acpi: add support for extended IRQ to PCI link Sinan Kaya
2015-11-12  6:14 ` [PATCH] " Sinan Kaya
2015-11-12  9:56   ` Andy Shevchenko
2015-11-12 15:04     ` Sinan Kaya
2015-11-12 15:17       ` Andy Shevchenko
2015-11-12 15:54         ` okaya
2015-11-12 15:58           ` Timur Tabi
  -- strict thread matches above, loose matches on Subject: below --
2015-11-08 16:07 Sinan Kaya
2015-11-08 16:07 ` Sinan Kaya
2015-11-08 16:11 ` Timur Tabi
2015-11-08 16:11   ` Timur Tabi
2015-11-09  0:04   ` Sinan Kaya
2015-11-09  0:04     ` Sinan Kaya
2015-11-09  0:05     ` Timur Tabi
2015-11-09  0:05       ` Timur Tabi
2015-11-09 21:49       ` Rafael J. Wysocki
2015-11-09 21:49         ` Rafael J. Wysocki
2015-11-08 20:35 ` Andy Shevchenko
2015-11-08 20:35   ` Andy Shevchenko
2015-11-09 22:29   ` Sinan Kaya
2015-11-09 22:29     ` Sinan Kaya
2015-11-09 22:29     ` Sinan Kaya
2015-11-09  5:24 ` Jiang Liu
2015-11-09  5:24   ` Jiang Liu
2015-11-09  5:45   ` Sinan Kaya
2015-11-09  5:45     ` Sinan Kaya
2015-11-09  8:45     ` Jiang Liu
2015-11-09  8:45       ` Jiang Liu
2015-11-09 13:50     ` Timur Tabi
2015-11-09 13:50       ` Timur Tabi
2015-11-09 16:28       ` Sinan Kaya
2015-11-09 16:28         ` Sinan Kaya

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.