Skip to contentSkip to conversation

2.6.18 Headers - Long

DISCUSSION Jim Gifford 9 participants 18 messages Jul 12, 2006 – Aug 29, 2006

lore
Share & tools
lore
#0 lore raw

I was really glad to see that something was going to be done with the headers, but I don't think it's enough. I'm going to share my concerns and hopefully we can all figure what is the right thing to do.

First off, my research in this has been going on since LLH announced that it was not going to produce any more headers. I started a project to sanitize the headers myself. http://headers.cross-lfs.org.

I will only document one issue, but there are several more like this in the kernel.

I'm going to use the MIPS architecture in my example, along with the file page.h.

With the 2.6.18 headers, the file that gets created looks like this. If you notice on lines 17, 20, 23, 26, and 34 they all use CONFIG_{...}, these variables are called from linux/autoconf.h. Yes, the simple fix would be to include this file.

1.

     /*
  2.
      * This file is subject to the terms and conditions of the GNU
     General Public
  3.
      * License.  See the file "COPYING" in the main directory of this
     archive
  4.
      * for more details.
  5.
      *
  6.
      * Copyright (C) 1994 - 1999, 2000, 03 Ralf Baechle
  7.
      * Copyright (C) 1999, 2000 Silicon Graphics, Inc.
  8.
      */
  9.
     #ifndef _ASM_PAGE_H
 10.
     #define _ASM_PAGE_H

11.

12.

13.

14.

     /*
 15.
      * PAGE_SHIFT determines the page size
 16.
      */
 17.
     #ifdef CONFIG_PAGE_SIZE_4KB
 18.
     #define PAGE_SHIFT      12
 19.
     #endif
 20.
     #ifdef CONFIG_PAGE_SIZE_8KB
 21.
     #define PAGE_SHIFT      13
 22.
     #endif
 23.
     #ifdef CONFIG_PAGE_SIZE_16KB
 24.
     #define PAGE_SHIFT      14
 25.
     #endif
 26.
     #ifdef CONFIG_PAGE_SIZE_64KB
 27.
     #define PAGE_SHIFT      16
 28.
     #endif
 29.
     #define PAGE_SIZE       (1UL << PAGE_SHIFT)
 30.
     #define PAGE_MASK       (~((1 << PAGE_SHIFT) - 1))

31.

32.

33.

34.

     #ifdef CONFIG_LIMITED_DMA
 35.
     #define WANT_PAGE_VIRTUAL
 36.
     #endif

37.

38.

     #include <asm-generic/memory_model.h>
 39.
     #include <asm-generic/page.h>

40.

41.

     #endif /* _ASM_PAGE_H */

Here's the header I produce with my sanitize script, I use a glibc call to get the information, which would be more appropriate for the user space. This is very similar to what LLH provided. Even my example is not prefect due to line 14.

  1.
     #define _ASM_PAGE_H
  2.
      
  3.
     #include <unistd.h>
  4.

5.

     #define PAGE_SIZE       (getpagesize())
  6.
     static __inline__ int getpageshift()
  7.
     {
  8.
         int pagesize = getpagesize();
  9.
         return (__builtin_clz(pagesize) ^ 31);
 10.
     }
 11.
     #define PAGE_SHIFT      (getpageshift())
 12.
     #define PAGE_MASK       (~(PAGE_SIZE-1))

13.

14.

     #ifdef CONFIG_LIMITED_DMA
 15.
     #define WANT_PAGE_VIRTUAL
 16.
     #endif

17.

18.

     #endif /* !(_ASM_PAGE_H) */

So even with the new headers_install, the headers still need to be sanitized to overcome the missing variables from linux/autoconf.h.

Just wanted to bring this up to everyone's attention and look forward to helping get things resolved.

#1 lore raw
Quoted 2 lines · Jim Gifford

I will only document one issue, but there are several more like this in the kernel.

Please elaborate, preferably in 'diff -u' form as below...

Quoted 2 lines

I'm going to use the MIPS architecture in my example, along with the file page.h.

[PATCH] Reduce user-visible noise in asm-mips/page.h

Since PAGE_SIZE is variable according to configuration options, don't expose it to userspace. Userspace should be using sysconf(_SC_PAGE_SIZE) instead. Move some other noise inside __KERNEL__ too while we're at it.

include/asm-mips/page.h +2 -4
index 6ed1151..ee2ef88 100644
@@ -14,8 +14,6 @@ #ifdef __KERNEL__
 
 #include <spaces.h>
 
-#endif
-
 /*
  * PAGE_SHIFT determines the page size
  */
@@ -35,7 +33,6 @@ #define PAGE_SIZE	(1UL << PAGE_SHIFT)
 #define PAGE_MASK       (~((1 << PAGE_SHIFT) - 1))
 
 
-#ifdef __KERNEL__
 #ifndef __ASSEMBLY__
 
 extern void clear_page(void * page);
@@ -168,7 +165,6 @@ #define VM_DATA_DEFAULT_FLAGS	(VM_READ |
 #define UNCAC_ADDR(addr)	((addr) - PAGE_OFFSET + UNCAC_BASE)
 #define CAC_ADDR(addr)		((addr) - UNCAC_BASE + PAGE_OFFSET)
 
-#endif /* defined (__KERNEL__) */
 
 #ifdef CONFIG_LIMITED_DMA
 #define WANT_PAGE_VIRTUAL
@@ -177,4 +173,6 @@ #endif
 #include <asm-generic/memory_model.h>
 #include <asm-generic/page.h>
 
+#endif /* defined (__KERNEL__) */
+
 #endif /* _ASM_PAGE_H */
Signature · 1 line
dwmw2
#2 lore raw

David,
There are several of them like that. I'll just list the files, and
the issues

asm-ia64/page.h - Config variables
asm-sparc/page.h - Config variables
asm-sparc64/page.h - Config variables
asm-powerpc/page.h - Config variables

I'll go through the rest over the next few days.

#3 lore raw
Quoted 3 lines · Jim Gifford

asm-ia64/page.h - Config variables
asm-sparc/page.h - Config variables
asm-sparc64/page.h - Config variables

Yeah, just as with MIPS, the bits which are affected by CONFIG variables just shouldn't be outside the __KERNEL__ ifdef at all -- they shouldn't be seen.

Quoted 1 line

asm-powerpc/page.h - Config variables

Er, asm-powerpc/page.h is empty after unifdef, which is entirely correect. In fact asm/page.h is one of the files which should probably be removed from user visibility entirely. There's nothing there which userspace should see, in general.

Signature · 1 line
dwmw2
#4 lore raw

Unfortunately, a lot programs out there are using page.h, and a lot of people are using that in their programs. The 2 program I know for sure that use page.h are glibc and util-linux.

#5 lore raw
Quoted 2 lines · Jim Gifford

Unfortunately, a lot programs out there are using page.h, and a lot of people are using that in their programs.

.... and they're all broken....
(hint: page size on many platforms is a kernel compile option, eg not a constant)

#13 lore raw
In reply to Jim Gifford
Quoted 3 lines · Jim Gifford

Unfortunately, a lot programs out there are using page.h, and a lot of people are using that in their programs. The 2 program I know for sure that use page.h are glibc and util-linux.

I don't believe glibc does. It certainly copes fine with an empty page.h on PowerPC.

Signature · 1 line
dwmw2
#14 lore raw
In reply to Jim Gifford
Quoted 3 lines · Jim Gifford

Unfortunately, a lot programs out there are using page.h, and a lot of people are using that in their programs. The 2 program I know for sure that use page.h are glibc and util-linux.

util-linux should be using getpagesize() or sysconf(_SC_PAGESIZE) from the C library. And libc should be getting the page size within ldso (or _start for static apps) by parsing the AT_PAGESZ entry from the ELF auxiliary vector. Should that be 0 (i.e. because the kernel is horribly broken) then and only then should libc fall back to guessing, i.e. a page size of 4k. A quick check shows that glibc, uClibc, and klibc all get this right. But you are right, that util-linux looks to have this wrong in a few places. I expect fixing the kernel headers will get that fixed in short order. :-)

-Erik

--
Erik B. Andersen http://codepoet-consulting.com/
--This message was written using 73% post-consumer electrons--

#6 lore raw
In reply to Arjan van de Ven
Quoted 5 lines · Arjan van de Ven
Quoted 2 lines · Jim Gifford

Unfortunately, a lot programs out there are using page.h, and a lot of people are using that in their programs.

.... and they're all broken....

More to the point, now we're doing this from upstream we can be _consistent_ about telling them to sod off and fix their broken crap.

We no longer have to deal with cries of 'but it works on $SOMEDISTRO' when another distro tries to impose some sanity rather than just pandering to it.

Kernel headers are _not_ a library of random crap for userspace to use.

Signature · 1 line
dwmw2
#7 lore raw

From: David Woodhouse <[email protected]>
Date: Fri, 14 Jul 2006 21:16:42 +0100

Quoted 8 lines

More to the point, now we're doing this from upstream we can be _consistent_ about telling them to sod off and fix their broken crap.

We no longer have to deal with cries of 'but it works on $SOMEDISTRO' when another distro tries to impose some sanity rather than just pandering to it.

Kernel headers are _not_ a library of random crap for userspace to use.

I totally agree. When I saw that some dists make asm/page.h define PAGE_SIZE to "getpagesize()" for userspace, I nearly crapped myself.

That is insane, and encourages the problem to persist instead of encouraging the right fix.

#15 lore raw
In reply to David Woodhouse
Quoted 10 lines · David Woodhouse
Quoted 2 lines · Jim Gifford

I will only document one issue, but there are several more like this in the kernel.

Please elaborate, preferably in 'diff -u' form as below...

Quoted 2 lines

I'm going to use the MIPS architecture in my example, along with the file page.h.

[PATCH] Reduce user-visible noise in asm-mips/page.h

The right fix is to not expose page.h at all on any architecture. There's nothing userspace should care about in this file.

#8 lore raw
In reply to David Miller

When I wrote my script to sanitize, I was really surprised on which headers gets utilized and which ones didn't.. I have it down to the bare minimums in my script.

As far as glibc goes, from my people who are helping me the alpha architecture is the culprit there.

Do we have a list of what headers are "user-space" and which ones should not be "user-space"?

Also David W, let me know what I can do to help you out, a lot of people on my end want to get this working properly.

Who's maintaining util-linux these days, we probably should get a patch to them.

#9 lore raw
Quoted 7 lines · On Fri, 14 Jul 2006 13:57:39 -0700 Jim Gifford wrote:

When I wrote my script to sanitize, I was really surprised on which
headers gets utilized and which ones didn't.. I have it down to the bare minimums in my script.

As far as glibc goes, from my people who are helping me the alpha architecture is the culprit there.

Quoted 8 lines

Do we have a list of what headers are "user-space" and which ones should not be "user-space"?

Also David W, let me know what I can do to help you out, a lot of people on my end want to get this working properly.

Who's maintaining util-linux these days, we probably should get a patch to them.

Adrian Bunk <[email protected]>

---
~Randy

#12 lore raw
In reply to David Miller
Quoted 5 lines · David Miller

I totally agree. When I saw that some dists make asm/page.h define PAGE_SIZE to "getpagesize()" for userspace, I nearly crapped myself.

That is insane, and encourages the problem to persist instead of encouraging the right fix.

Until a week or two ago, we had no mechanism with which to implement the 'right fix'. Any distribution taking the initiative and reducing visibility of stuff like that would be inundated with complaints that "it works OK on other distributions".

We can be stricter now that we have some expectation of _consistency_ across distributions.

Signature · 1 line
dwmw2
#11 lore raw
In reply to Jim Gifford
Quoted 2 lines · Jim Gifford

Do we have a list of what headers are "user-space" and which ones should not be "user-space"?

Well, we have the lists in include/*/Kbuild files, of course -- but that's all. As I've stated before, I've been somewhat liberal with the exports to far, to match what's currently (ab)used, because I wanted to concentrate on the _mechanism_, not the policy.

The intention is that we can now start to tighten it up -- I've already sent the patches which drop asm/atomic.h and asm/io.h, and there are more which should go. Next on that list (and already commented as such in include/asm-generic/Kbuild.asm) are asm/page.h and asm/elf.h.

Quoted 2 lines

Also David W, let me know what I can do to help you out, a lot of people on my end want to get this working properly.

Thanks. One thing you can do which would be extremely useful is to investigate dropping page.h and elf.h, and make sure that stuff like gdb (and anything using ptrace.h) will still build. Then just look for anything else which should be removed from view. The git repository at
http://git.kernel.org/git/?p=linux/kernel/git/dwmw2/kernel-headers.git
(git://git.kernel.org/pub/scm/linux/kernel/git/dwmw2/kernel-headers.git)
should help with that task. Provide patches to move stuff within #ifdef __KERNEL__ or to move it to unexported files.

There are some who think that it would be nice to get rid of __KERNEL__ entirely -- files would be either entirely exported, or not at all. I don't think we necessarily need to go that far; the export step with unifdef isn't so bad.

Signature · 1 line
dwmw2
#10 lore raw
In reply to Randy.Dunlap

On 15 Jul 2006, Randy Dunlap prattled cheerily:

Quoted 6 lines · On Fri, 14 Jul 2006 13:57:39 -0700 Jim Gifford wrote:
Quoted 3 lines

Who's maintaining util-linux these days, we probably should get a patch to them.

Adrian Bunk <[email protected]>

... and I sent him a patch months ago, and it was applied: the cramfs tools in util-linux no longer use PAGE_SIZE, and hasn't since 2.13-pre5. (mkswap still references it, but that usage is *optional* and doesn't happen if PAGE_SIZE isn't defined.)

#16 lore raw
In reply to David Woodhouse
Quoted 5 lines · David Woodhouse
Quoted 2 lines · Jim Gifford

I will only document one issue, but there are several more like this in the kernel.

Please elaborate, preferably in 'diff -u' form as below...

Got any more, Jim?

Quoted 2 lines
Quoted 2 lines

I'm going to use the MIPS architecture in my example, along with the file page.h.

Ralf, you haven't applied this yet AFAICT...

Quoted 46 lines

[PATCH] Reduce user-visible noise in asm-mips/page.h

Since PAGE_SIZE is variable according to configuration options, don't expose it to userspace. Userspace should be using sysconf(_SC_PAGE_SIZE) instead. Move some other noise inside __KERNEL__ too while we're at it.

include/asm-mips/page.h +2 -4
index 6ed1151..ee2ef88 100644
@@ -14,8 +14,6 @@ #ifdef __KERNEL__
 
 #include <spaces.h>
 
-#endif
-
 /*
  * PAGE_SHIFT determines the page size
  */
@@ -35,7 +33,6 @@ #define PAGE_SIZE	(1UL << PAGE_SHIFT)
 #define PAGE_MASK       (~((1 << PAGE_SHIFT) - 1))
 
 
-#ifdef __KERNEL__
 #ifndef __ASSEMBLY__
 
 extern void clear_page(void * page);
@@ -168,7 +165,6 @@ #define VM_DATA_DEFAULT_FLAGS	(VM_READ |
 #define UNCAC_ADDR(addr)	((addr) - PAGE_OFFSET + UNCAC_BASE)
 #define CAC_ADDR(addr)		((addr) - UNCAC_BASE + PAGE_OFFSET)
 
-#endif /* defined (__KERNEL__) */
 
 #ifdef CONFIG_LIMITED_DMA
 #define WANT_PAGE_VIRTUAL
@@ -177,4 +173,6 @@ #endif
 #include <asm-generic/memory_model.h>
 #include <asm-generic/page.h>
 
+#endif /* defined (__KERNEL__) */
+
 #endif /* _ASM_PAGE_H */
Signature · 1 line
dwmw2
#17 lore raw
Quoted 1 line · David Woodhouse

Ralf, you haven't applied this yet AFAICT...

Well, it now is.

Ralf