Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 23 Jun 2001 15:40:39 +1000 (EST)
From:      Bruce Evans <bde@zeta.org.au>
To:        Matthew Jacob <mjacob@feral.com>
Cc:        John Baldwin <jhb@FreeBSD.org>, cvs-all@FreeBSD.org, cvs-committers@FreeBSD.org, Peter Wemm <peter@FreeBSD.org>
Subject:   Re: D'oh!
Message-ID:  <Pine.BSF.4.21.0106231508410.45551-100000@besplex.bde.org>
In-Reply-To: <20010622152459.X21527-100000@wonky.feral.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Fri, 22 Jun 2001, Matthew Jacob wrote:

> Aghh.... internally to the kernel physmem is in units of pages for alpha or
> the oldie moldy 'clicks' for i386. What *was* I thinking?  It's really just
> the sysctl representation, no?

No.  The kernel variable is in pages, but the sysctl scales it to bytes
using broken scaling code:

On i386's, the sshould-be-deprecated MI interface ctob() is used for
scaling.  ctob() is:

	/* clicks to bytes */
	#define ctob(x)	((x)<<PAGE_SHIFT)

when (x) has type int (like the physmem variable), this overflows to
a negative int when the result should be >= 2GB.  When the result
should be 4GB, it overflows to 0.  When the result should be > 4GB,
it overflows worse.  Next, this int is passed to sysctl_int() which
copies it out using:

	error = SYSCTL_IN(req, arg1, sizeof(int));

so userland sees an int.  Peter's change just hides the previous overflows
by making sysctl(8) print this int using the bogus format %u.

On alphas, the scaling code is actually correct.  ctob() is broken on
alphas in the same was as on i386's, but the sysctl doesn't use it; it
uses alpha_ptob(), which works up to size (2^64 - 1 page).  The result
of alpha_ptob() is unsigned long.  Next, this unsigned long is corrupted
to an int by passing it to sysctl_int().  The remaining bugs are the same
as on i386's.

There are many other bugs and bogons in the conversion macros in
<machine/param.h>.  Most seriously, dbtob() is broken on alphas.

Bruce


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe cvs-all" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.4.21.0106231508410.45551-100000>