Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 2 Sep 2011 08:40:01 -0400
From:      John Baldwin <jhb@freebsd.org>
To:        Robert Millan <rmh@debian.org>
Cc:        freebsd-current@freebsd.org
Subject:   Re: [PATCH] Fix NKPT kernel config option
Message-ID:  <201109020840.01128.jhb@freebsd.org>
In-Reply-To: <CAOfDtXMy%2B8pmNhRODwmutXUtrbmYgv-0cwdF8dR_AkkM=uQf4g@mail.gmail.com>
References:  <CAOfDtXPDAyeZX7adW5Hixa2XwyOFgic=FRU6ipUHZcY15JVQaQ@mail.gmail.com> <201109011728.13979.jhb@freebsd.org> <CAOfDtXMy%2B8pmNhRODwmutXUtrbmYgv-0cwdF8dR_AkkM=uQf4g@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Friday, September 02, 2011 1:23:16 am Robert Millan wrote:
> 2011/9/1 John Baldwin <jhb@freebsd.org>:
> > In general we force the relevant C files to use opt_*.h includes and avoid
> > nested includes of those in headers.
> 
> With this approach I can't trust that this feature will do the right
> thing.  I would rather modify pmap.h by hand than run the unnecessary
> risk.
> 
> > Do you know of any C files that do
> > are using NKPT (or values derived from it) without including opt_pmap.h?
> 
> Many.  To obtain a full list, I suggest you put something like:
> 
> #ifdef NKPT
> #warning nkpt:good
> #else
> #warning nkpt:bad
> #endif
> 
> in pmap.h and build with "WERROR="

This is rather pointless as it dosen't catch the places that actually _use_
NKPT.  The <machine/pmap.h> header is used in lots of places for other things
it defines such as 'struct pmap' itself.  However, NKPT is a purely MD item
that is only used in the amd64 code itself.  Specifically, it is used here:

amd64/minidump_machdep.c:       for (va = VM_MIN_KERNEL_ADDRESS; va < MAX(KERNBASE + NKPT * NBPDR,
amd64/minidump_machdep.c:       for (va = VM_MIN_KERNEL_ADDRESS; va < MAX(KERNBASE + NKPT * NBPDR,
amd64/pmap.c:   KPTphys = allocpages(firstaddr, NKPT);
amd64/pmap.c:   for (i = 0; i < NKPT; i++) {
amd64/pmap.c:   for (i = 0; i < NKPT; i++) {
amd64/pmap.c:   if (KERNBASE < addr && addr <= KERNBASE + NKPT * NBPDR)
conf/NOTES:options      NKPT=31
include/pmap.h:#ifndef NKPT
include/pmap.h:#define  NKPT            32
include/pmap.h:#define NKPDPE           howmany(NKPT, NPDEPG)/* number of kernel PDP slots */

This gives uses in amd64/minidump_machdep.c and amd64/pmap.c and to define
the macro NKPDPE.  That macro is also MD and is only used here:

amd64/pmap.c:   KPDphys = allocpages(firstaddr, NKPDPE);
amd64/pmap.c:   for (i = 0; i < NKPDPE; i++) {
include/pmap.h:#define NKPDPE           howmany(NKPT, NPDEPG)/* number of kernel PDP slots */

Thus, the only two files that use NKPT are amd64/minidump_machdep.c and
amd64/pmap.c.  Both of these files include "opt_pmap.h":

amd64/minidump_machdep.c:#include "opt_pmap.h"
amd64/pmap.c:#include "opt_pmap.h"

A more useful test would be to alter pmap.h so it says:

#ifndef NKPT
#define NKPT doesnt_compile
#endif

and build a kernel config that contains 'options NKPT=31'.  It will build
just fine as the sabotaged default value will never get used.

Were NKPT to be widely used, the correct fix would still not be to add an
include of opt_pmap.h to <machine/pmap.h>.  Instead, the corect fix would be
to move the option to opt_global.h as is done for things like SMP,
INVARIANTS, etc.

-- 
John Baldwin



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201109020840.01128.jhb>