public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Ingo Molnar <mingo@elte.hu>
To: Yinghai Lu <yinghai@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>,
	"H. Peter Anvin" <hpa@zytor.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Jesse Barnes <jbarnes@virtuousgeek.org>,
	Len Brown <lenb@kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	linux-pci@vger.kernel.org,
	ACPI Devel Maling List <linux-acpi@vger.kernel.org>
Subject: Re: [PATCH 3/7] x86: fix alloc_mptable
Date: Mon, 11 May 2009 10:22:58 +0200	[thread overview]
Message-ID: <20090511082258.GC5636@elte.hu> (raw)
In-Reply-To: <4A01C3BB.1000609@kernel.org>


* Yinghai Lu <yinghai@kernel.org> wrote:

> fix the condition checking.
> 
> [ Impact: make alloc_mptable working ]
> 
> Signed-off-by: Yinghai Lu <yinghai@kernel.org>
> 
> ---
>  arch/x86/kernel/mpparse.c |   15 +++++++++------
>  1 file changed, 9 insertions(+), 6 deletions(-)
> 
> Index: linux-2.6/arch/x86/kernel/mpparse.c
> ===================================================================
> --- linux-2.6.orig/arch/x86/kernel/mpparse.c
> +++ linux-2.6/arch/x86/kernel/mpparse.c
> @@ -873,21 +873,24 @@ inline void __init check_irq_src(struct
>  static int check_slot(unsigned long mpc_new_phys, unsigned long mpc_new_length,
>  		      int count)
>  {
> +	int ret = 0;
> +
>  	if (!mpc_new_phys) {
> -		pr_info("No spare slots, try to append...take your risk, "
> +		pr_warning("No spare slots, try to append...take your risk, "
>  			"new mpc_length %x\n", count);
>  	} else {
> -		if (count <= mpc_new_length)
> +		if (count <= mpc_new_length) {
>  			pr_info("No spare slots, try to append..., "
>  				"new mpc_length %x\n", count);
> -		else {
> +			ret = 1;
> +		} else {
>  			pr_err("mpc_new_length %lx is too small\n",
>  				mpc_new_length);
> -			return -1;
> +			ret = -1;
>  		}
>  	}
>  
> -	return 0;
> +	return ret;
>  }
>  
>  static int  __init replace_intsrc_all(struct mpc_table *mpc,
> @@ -946,7 +949,7 @@ static int  __init replace_intsrc_all(st
>  		} else {
>  			struct mpc_intsrc *m = (struct mpc_intsrc *)mpt;
>  			count += sizeof(struct mpc_intsrc);
> -			if (!check_slot(mpc_new_phys, mpc_new_length, count))
> +			if (check_slot(mpc_new_phys, mpc_new_length, count) < 0)
>  				goto out;
>  			assign_to_mpc_intsrc(&mp_irqs[i], m);
>  			mpc->length = count;

hm, i modified this to the code attached below instead. Things like:

> -		pr_info("No spare slots, try to append...take your risk, "
> +		pr_warning("No spare slots, try to append...take your risk, "
>  			"new mpc_length %x\n", count);

are not acceptable at all. If there's _anything_ wrong with code 
like this, if we run out of a static pool of slots, we dont try to 
hack our way out of it... Instead we inform the user and bail out 
ASAP!

A predictable, well working way out of a resource shortage is _way_ 
more important than trying to clinge to some functionality and 
hoping that it will be all fine ...

So ... please describe under which conditions we can run out of 
slots, and what the options are in that situation.

	Ingo

------------------------------>
Subject: x86: fix alloc_mptable()
From: Yinghai Lu <yinghai@kernel.org>
Date: Wed, 06 May 2009 10:07:07 -0700

Fix the conditions when we stop updating the mptable due to
running out of slots.

[ Impact: fix memory corruption / non-working update_mptable boot parameter ]

Signed-off-by: Yinghai Lu <yinghai@kernel.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Jesse Barnes <jbarnes@virtuousgeek.org>
Cc: Len Brown <lenb@kernel.org>
LKML-Reference: <4A01C3BB.1000609@kernel.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
---
 arch/x86/kernel/mpparse.c |   25 +++++++++----------------
 1 file changed, 9 insertions(+), 16 deletions(-)

Index: tip/arch/x86/kernel/mpparse.c
===================================================================
--- tip.orig/arch/x86/kernel/mpparse.c
+++ tip/arch/x86/kernel/mpparse.c
@@ -870,24 +870,17 @@ static
 inline void __init check_irq_src(struct mpc_intsrc *m, int *nr_m_spare) {}
 #endif /* CONFIG_X86_IO_APIC */
 
-static int check_slot(unsigned long mpc_new_phys, unsigned long mpc_new_length,
-		      int count)
+static int
+check_slot(unsigned long mpc_new_phys, unsigned long mpc_new_length, int count)
 {
-	if (!mpc_new_phys) {
-		pr_info("No spare slots, try to append...take your risk, "
-			"new mpc_length %x\n", count);
-	} else {
-		if (count <= mpc_new_length)
-			pr_info("No spare slots, try to append..., "
-				"new mpc_length %x\n", count);
-		else {
-			pr_err("mpc_new_length %lx is too small\n",
-				mpc_new_length);
-			return -1;
-		}
+	int ret = 0;
+
+	if (!mpc_new_phys || count <= mpc_new_length) {
+		WARN(1, "update_mptable: No spare slots (length: %x)\n", count);
+		return -1;
 	}
 
-	return 0;
+	return ret;
 }
 
 static int  __init replace_intsrc_all(struct mpc_table *mpc,
@@ -946,7 +939,7 @@ static int  __init replace_intsrc_all(st
 		} else {
 			struct mpc_intsrc *m = (struct mpc_intsrc *)mpt;
 			count += sizeof(struct mpc_intsrc);
-			if (!check_slot(mpc_new_phys, mpc_new_length, count))
+			if (check_slot(mpc_new_phys, mpc_new_length, count) < 0)
 				goto out;
 			assign_to_mpc_intsrc(&mp_irqs[i], m);
 			mpc->length = count;

  reply	other threads:[~2009-05-11  8:24 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-05-06 17:05 [PATCH 1/7] x86/acpi: remove compress irq trick for 32bit Yinghai Lu
2009-05-06 17:06 ` [PATCH 2/7] x86/acpi: calling mp_config_acpi_gsi in mp_register_gsi -v2 Yinghai Lu
2009-05-11  9:52   ` [tip:irq/numa] x86/acpi: call mp_config_acpi_gsi() in mp_register_gsi() tip-bot for Yinghai Lu
2009-05-14 16:20   ` [PATCH 2/7] x86/acpi: calling mp_config_acpi_gsi in mp_register_gsi -v2 Len Brown
2009-05-14 17:43     ` Yinghai Lu
2009-05-06 17:07 ` [PATCH 3/7] x86: fix alloc_mptable Yinghai Lu
2009-05-11  8:22   ` Ingo Molnar [this message]
2009-05-11  9:52   ` [tip:irq/numa] x86: fix alloc_mptable() tip-bot for Yinghai Lu
2009-05-06 17:07 ` [PATCH 4/7] x86/acpi: move pin_programmed bit map to io_apic.c Yinghai Lu
2009-05-11  9:52   ` [tip:irq/numa] " tip-bot for Yinghai Lu
2009-05-06 17:08 ` [PATCH 5/7] x86/pci: add 4 more return param in IO_APIC_get_PCI_irq_vector Yinghai Lu
2009-05-07 14:10   ` Ingo Molnar
2009-05-11  8:28   ` Ingo Molnar
2009-05-11 19:40     ` Yinghai Lu
2009-05-11 21:37       ` Ingo Molnar
2009-05-11 22:55         ` [PATCH] x86: introduce io_apic_irq_attr -v2 Yinghai Lu
2009-05-12 10:32           ` Ingo Molnar
2009-05-12 15:17             ` Yinghai Lu
2009-05-12 18:02             ` Yinghai Lu
2009-05-18  7:39           ` [tip:irq/numa] x86, apic: introduce io_apic_irq_attr tip-bot for Yinghai Lu
2009-05-11  9:05   ` [PATCH 5/7] x86/pci: add 4 more return param in IO_APIC_get_PCI_irq_vector Ingo Molnar
2009-05-11  9:52   ` [tip:irq/numa] x86/pci: add 4 more return parameters to IO_APIC_get_PCI_irq_vector() tip-bot for Yinghai Lu
2009-05-06 17:08 ` [PATCH 6/7] x86/acpi: move setup io apic routing out of ACPI macro scope Yinghai Lu
2009-05-11  9:53   ` [tip:irq/numa] x86/acpi: move setup io apic routing out of CONFIG_ACPI scope tip-bot for Yinghai Lu
2009-05-06 17:10 ` [PATCH 7/7] x86/pci: update pirq_enable_irq to setup io apic routing -v2 Yinghai Lu
2009-05-07 14:12   ` Ingo Molnar
2009-05-07 16:52     ` Jesse Barnes
2009-05-11  7:49       ` Ingo Molnar
2009-05-11  9:53   ` [tip:irq/numa] x86/pci: update pirq_enable_irq() to setup io apic routing tip-bot for Yinghai Lu
2009-05-11  9:52 ` [tip:irq/numa] x86/acpi: remove irq-compression trick on 32-bit 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=20090511082258.GC5636@elte.hu \
    --to=mingo@elte.hu \
    --cc=akpm@linux-foundation.org \
    --cc=hpa@zytor.com \
    --cc=jbarnes@virtuousgeek.org \
    --cc=lenb@kernel.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=tglx@linutronix.de \
    --cc=yinghai@kernel.org \
    /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