public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [patch] numa: fix BUILD_BUG_ON for node_read_distance
@ 2010-03-10 22:50 David Rientjes
  2010-03-10 22:58 ` Greg KH
  0 siblings, 1 reply; 4+ messages in thread
From: David Rientjes @ 2010-03-10 22:50 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: linux-kernel

node_read_distance() has a BUILD_BUG_ON() to prevent buffer overruns when
the number of nodes printed will exceed the buffer length.

Each node only needs four chars: three for distance (maximum distance is
255) and one for a seperating space or a trailing newline.

Signed-off-by: David Rientjes <rientjes@google.com>
---
 drivers/base/node.c |    7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/base/node.c b/drivers/base/node.c
--- a/drivers/base/node.c
+++ b/drivers/base/node.c
@@ -165,8 +165,11 @@ static ssize_t node_read_distance(struct sys_device * dev,
 	int len = 0;
 	int i;
 
-	/* buf currently PAGE_SIZE, need ~4 chars per node */
-	BUILD_BUG_ON(MAX_NUMNODES*4 > PAGE_SIZE/2);
+	/*
+	 * buf is currently PAGE_SIZE in length and each node needs 4 chars
+	 * at the most (distance + space or newline).
+	 */
+	BUILD_BUG_ON(MAX_NUMNODES*4 > PAGE_SIZE);
 
 	for_each_online_node(i)
 		len += sprintf(buf + len, "%s%d", i ? " " : "", node_distance(nid, i));

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

* Re: [patch] numa: fix BUILD_BUG_ON for node_read_distance
  2010-03-10 22:50 [patch] numa: fix BUILD_BUG_ON for node_read_distance David Rientjes
@ 2010-03-10 22:58 ` Greg KH
  2010-03-10 23:05   ` David Rientjes
  0 siblings, 1 reply; 4+ messages in thread
From: Greg KH @ 2010-03-10 22:58 UTC (permalink / raw)
  To: David Rientjes; +Cc: linux-kernel

On Wed, Mar 10, 2010 at 02:50:21PM -0800, David Rientjes wrote:
> node_read_distance() has a BUILD_BUG_ON() to prevent buffer overruns when
> the number of nodes printed will exceed the buffer length.
> 
> Each node only needs four chars: three for distance (maximum distance is
> 255) and one for a seperating space or a trailing newline.

Is this causing a problem as-is today that we need to resolve for
2.6.34?  Or is this 2.6.35 material?

Who chose this original number, and why is it off by 1/2?

thanks,

greg k-h

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

* Re: [patch] numa: fix BUILD_BUG_ON for node_read_distance
  2010-03-10 22:58 ` Greg KH
@ 2010-03-10 23:05   ` David Rientjes
  2010-03-10 23:11     ` Greg KH
  0 siblings, 1 reply; 4+ messages in thread
From: David Rientjes @ 2010-03-10 23:05 UTC (permalink / raw)
  To: Greg KH; +Cc: linux-kernel

On Wed, 10 Mar 2010, Greg KH wrote:

> > node_read_distance() has a BUILD_BUG_ON() to prevent buffer overruns when
> > the number of nodes printed will exceed the buffer length.
> > 
> > Each node only needs four chars: three for distance (maximum distance is
> > 255) and one for a seperating space or a trailing newline.
> 
> Is this causing a problem as-is today that we need to resolve for
> 2.6.34?  Or is this 2.6.35 material?
> 

It's not needed at least for x86 for 2.6.34 since the max 
CONFIG_NODES_SHIFT is 9.  I don't know about other architectures with 
different ranges or page sizes.

I'm going to push a change to the x86 maintainers to increase that max 
CONFIG_NODES_SHIFT to 10 hopefully for 2.6.35, that's where we run into 
this error.

> Who chose this original number, and why is it off by 1/2?
> 

It's earlier than the git history, but there's no reason to divide 
PAGE_SIZE in half.  We've been running machines with this patch for well 
over a year and /sys/devices/system/node/nodeN/distance works just fine 
with 1K nodes.

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

* Re: [patch] numa: fix BUILD_BUG_ON for node_read_distance
  2010-03-10 23:05   ` David Rientjes
@ 2010-03-10 23:11     ` Greg KH
  0 siblings, 0 replies; 4+ messages in thread
From: Greg KH @ 2010-03-10 23:11 UTC (permalink / raw)
  To: David Rientjes; +Cc: linux-kernel

On Wed, Mar 10, 2010 at 03:05:47PM -0800, David Rientjes wrote:
> On Wed, 10 Mar 2010, Greg KH wrote:
> 
> > > node_read_distance() has a BUILD_BUG_ON() to prevent buffer overruns when
> > > the number of nodes printed will exceed the buffer length.
> > > 
> > > Each node only needs four chars: three for distance (maximum distance is
> > > 255) and one for a seperating space or a trailing newline.
> > 
> > Is this causing a problem as-is today that we need to resolve for
> > 2.6.34?  Or is this 2.6.35 material?
> > 
> 
> It's not needed at least for x86 for 2.6.34 since the max 
> CONFIG_NODES_SHIFT is 9.  I don't know about other architectures with 
> different ranges or page sizes.
> 
> I'm going to push a change to the x86 maintainers to increase that max 
> CONFIG_NODES_SHIFT to 10 hopefully for 2.6.35, that's where we run into 
> this error.

Ok, I'll queue this up for .35, thanks.

greg k-h

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

end of thread, other threads:[~2010-03-10 23:13 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-03-10 22:50 [patch] numa: fix BUILD_BUG_ON for node_read_distance David Rientjes
2010-03-10 22:58 ` Greg KH
2010-03-10 23:05   ` David Rientjes
2010-03-10 23:11     ` Greg KH

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox