linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Arnd Bergmann <arnd@arndb.de>
To: Cliff Wickman <cpw@sgi.com>, Mijo Safradin <safradin@de.ibm.com>,
	Christoph Lameter <clameter@sgi.com>,
	Lee Schermerhorn <lee.schermerhorn@hp.com>,
	linuxppc-dev@ozlabs.org
Subject: [PATCH] numactl: fix libnuma on big-endian 64-bit systems
Date: Thu, 4 Dec 2008 18:34:45 +0100	[thread overview]
Message-ID: <200812041834.45931.arnd@arndb.de> (raw)

The read-mask function assumes that it is running in 32-bit mode,
by addressing the bitmask as a series of int values, instead of
longs. This is broken as can easily be reproduced by running numademo
on a bit-endian 64-bit system.

Changing the addressing to use 'long' values fixes the problem.

Reported-by: Mijo Safradin <safradin@de.ibm.com>

---

Note: the set_nodemask_size() function is broken as well, it seems
to always set the nodemask size to "17" with the s2nbits implementation.
The fallback path in there looks correct.

--- a/libnuma.c	2008-12-04 14:25:30.000000000 +0100
+++ b/libnuma.c	2008-11-20 13:40:29.000000000 +0100
@@ -392,9 +372,9 @@ read_mask(char *s, struct bitmask *bmp)
 {
 	char *end = s;
 	char *prevend;
-	unsigned long *start = bmp->maskp;
-	unsigned long *p = start;
-	unsigned long *q;
+	unsigned int *start = (unsigned int *)bmp->maskp;
+	unsigned int *p = start;
+	unsigned int *q;
 	unsigned int i;
 	unsigned int n = 0;
 
@@ -431,14 +411,14 @@
 	}
 
 	/* Poor mans fls() */
-	for(i = sizeof(long) * 8 - 1; i >= 0; i--)
+	for(i = 31; i >= 0; i--)
 		if (test_bit(i, start + n))
 			break;
 
 	/*
 	 * Return the last bit set
 	 */
-	return ((sizeof(unsigned long)*8) * n) + i;
+	return ((sizeof(unsigned int)*8) * n) + i;
 }
 
 /*

             reply	other threads:[~2008-12-04 17:34 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-12-04 17:34 Arnd Bergmann [this message]
2008-12-04 17:46 ` [PATCH] numactl: fix libnuma on big-endian 64-bit systems Lee Schermerhorn
2008-12-04 20:49   ` Arnd Bergmann
2008-12-04 20:51     ` [PATCH, v2] " Arnd Bergmann
2008-12-05 15:12       ` Arnd Bergmann

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=200812041834.45931.arnd@arndb.de \
    --to=arnd@arndb.de \
    --cc=clameter@sgi.com \
    --cc=cpw@sgi.com \
    --cc=lee.schermerhorn@hp.com \
    --cc=linuxppc-dev@ozlabs.org \
    --cc=safradin@de.ibm.com \
    /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;
as well as URLs for NNTP newsgroup(s).