mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Yinghai Lu <yinghai@kernel.org>
To: linux-kernel@vger.kernel.org, mingo@redhat.com, hpa@zytor.com,
	tglx@linutronix.de
Cc: linux-tip-commits@vger.kernel.org
Subject: Re: [tip:irq/core] genirq: Make nr_irqs runtime expandable
Date: Sat, 19 Feb 2011 11:07:37 -0800	[thread overview]
Message-ID: <4D6014F9.8040605@kernel.org> (raw)
In-Reply-To: <tip-e7bcecb7b1d29b9ad5af939149a945658620ca8f@git.kernel.org>

On 02/19/2011 04:15 AM, tip-bot for Thomas Gleixner wrote:
> Commit-ID:  e7bcecb7b1d29b9ad5af939149a945658620ca8f
> Gitweb:     http://git.kernel.org/tip/e7bcecb7b1d29b9ad5af939149a945658620ca8f
> Author:     Thomas Gleixner <tglx@linutronix.de>
> AuthorDate: Wed, 16 Feb 2011 17:12:57 +0100
> Committer:  Thomas Gleixner <tglx@linutronix.de>
> CommitDate: Sat, 19 Feb 2011 12:58:06 +0100
> 
> genirq: Make nr_irqs runtime expandable
> 
> We face more and more the requirement to expand nr_irqs at
> runtime. The reason are irq expanders which can not be detected in the
> early boot stage. So we speculate nr_irqs to have enough room. Further
> Xen needs extra irq numbers and we really want to avoid adding more
> "detection" code into the early boot. There is no real good reason why
> we need to limit nr_irqs at early boot.
> 
> Allow the allocation code to expand nr_irqs. We have already 8k extra
> number space in the allocation bitmap, so lets use it.
> 
> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
> ---
>  kernel/irq/irqdesc.c |   22 +++++++++++++++++++---
>  1 files changed, 19 insertions(+), 3 deletions(-)
> 
> diff --git a/kernel/irq/irqdesc.c b/kernel/irq/irqdesc.c
> index a250d3a..6f6644f 100644
> --- a/kernel/irq/irqdesc.c
> +++ b/kernel/irq/irqdesc.c
> @@ -206,6 +206,14 @@ struct irq_desc * __ref irq_to_desc_alloc_node(unsigned int irq, int node)
>  	return NULL;
>  }
>  
> +static int irq_expand_nr_irqs(unsigned int cnt)
> +{
> +	if (nr_irqs + cnt > IRQ_BITMAP_BITS)
> +		return -ENOMEM;
> +	nr_irqs += cnt;
> +	return 0;
> +}
> +
>  int __init early_irq_init(void)
>  {
>  	int i, initcnt, node = first_online_node;
> @@ -287,6 +295,12 @@ static inline int alloc_descs(unsigned int start, unsigned int cnt, int node)
>  {
>  	return start;
>  }
> +
> +static int irq_expand_nr_irqs(unsigned int cnt)
> +{
> +	return -ENOMEM;
> +}
> +
>  #endif /* !CONFIG_SPARSE_IRQ */
>  
>  /* Dynamic interrupt handling */
> @@ -335,9 +349,11 @@ irq_alloc_descs(int irq, unsigned int from, unsigned int cnt, int node)
>  	if (irq >=0 && start != irq)
>  		goto err;
>  
> -	ret = -ENOMEM;
> -	if (start >= nr_irqs)
> -		goto err;
> +	if (start >= nr_irqs) {
> +		ret = irq_expand_nr_irqs(cnt);
> +		if (ret)
> +			goto err;
> +	}

may need following patch.

[PATCH] genirq: use IRQ_BITMAP_BITS as search size

instead of nr_irqs.

Otherwise bitmap_find_next_area could exit with larger start and in extreme
case we could fail to get wrong irqs return.

For example:
IRQ_BITMAP_BITS=10240
nr_irqs=8192
cnt=2048

and bit 0 to bit 8190 are set already.

before patch start from bit_find_next_area() will be 8191+2048.
later irq_expand_nr_irqs will set nr_irqs 10240.
finally irq_alloc_descs will return [8191+2048, 8191+2048+2047] happily..

with this patch, will get correct [8191, 8191+2047]

Signed-off-by: Yinghai Lu <yinghai@kernel.org>

---
 kernel/irq/irqdesc.c |    5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Index: linux-2.6/kernel/irq/irqdesc.c
===================================================================
--- linux-2.6.orig/kernel/irq/irqdesc.c
+++ linux-2.6/kernel/irq/irqdesc.c
@@ -346,12 +346,13 @@ irq_alloc_descs(int irq, unsigned int fr
 
 	mutex_lock(&sparse_irq_lock);
 
-	start = bitmap_find_next_zero_area(allocated_irqs, nr_irqs, from, cnt, 0);
+	start = bitmap_find_next_zero_area(allocated_irqs, IRQ_BITMAP_BITS,
+						 from, cnt, 0);
 	ret = -EEXIST;
 	if (irq >=0 && start != irq)
 		goto err;
 
-	if (start >= nr_irqs) {
+	if (start + cnt > nr_irqs) {
 		ret = irq_expand_nr_irqs(cnt);
 		if (ret)
 			goto err;

       reply	other threads:[~2011-02-19 19:08 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <tip-e7bcecb7b1d29b9ad5af939149a945658620ca8f@git.kernel.org>
2011-02-19 19:07 ` Yinghai Lu [this message]
2011-02-21 13:37   ` Thomas Gleixner
2011-02-21 13:43     ` Thomas Gleixner
2011-02-21 15:56   ` Lars-Peter Clausen
2011-02-21 17:57     ` Yinghai Lu
2011-02-21 19:17     ` Thomas Gleixner
2011-02-21 20:22   ` [tip:irq/core] genirq: Use IRQ_BITMAP_BITS as search size in irq_alloc_descs() tip-bot for Yinghai Lu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4D6014F9.8040605@kernel.org \
    --to=yinghai@kernel.org \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=tglx@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome