x86: break mutual header inclusion
PATCH 1/1 x86: break mutual header inclusion
Hi,
What do you think about this? The new file (vm86_mask.h) could actually be embedded completely in processor-flags.h, but I went for what I believe is the safer approach.
This has been compile tested on x86_32 and x86_64 defconfig.
Vegard
From: Vegard Nossum <[email protected]>
Date: Tue, 27 May 2008 21:38:35 +0200
Subject: [PATCH] x86: break mutual header inclusion
This breaks up the mutual inclusion between headers ptrace.h and vm86.h by moving what's needed by both files into a new (minimal) file vm86_mask.h.
We also move #include lines to the top.
--- include/asm-x86/ptrace.h | 10 +++------- include/asm-x86/vm86.h | 9 ++------- include/asm-x86/vm86_mask.h | 12 ++++++++++++ 3 files changed, 17 insertions(+), 14 deletions(-) create mode 100644 include/asm-x86/vm86_mask.h
include/asm-x86/ptrace.h +3 -7
@@ -2,8 +2,10 @@#define _ASM_X86_PTRACE_H#include <linux/compiler.h> /* For __user */ +#include <asm/ds.h> /* the DS BTS struct is used for ptrace too */ +#include <asm/segment.h> #include <asm/ptrace-abi.h> - +#include <asm/vm86_mask.h> #ifndef __ASSEMBLY__
@@ -55,9 +57,6 @@ struct pt_regs { unsigned long ss; }; -#include <asm/vm86.h> -#include <asm/segment.h> -#endif /* __KERNEL__ */ #else /* __i386__ */
@@ -127,9 +126,6 @@ struct pt_regs {#ifdef __KERNEL__ -/* the DS BTS struct is used for ptrace as well */ -#include <asm/ds.h> -struct task_struct ;extern void ptrace_bts_take_timestamp (struct task_struct *,enum bts_qualifier );
include/asm-x86/vm86.h +2 -7
@@ -13,12 +13,8 @@*/ #include <asm/processor-flags.h> - -#ifdef CONFIG_VM86 -#define X86_VM_MASK X86_EFLAGS_VM -#else -#define X86_VM_MASK 0/* No VM86 support */ -#endif +#include <asm/ptrace.h> +#include <asm/vm86_mask.h> #define BIOSSEG 0x0f000
@@ -141,7 +137,6 @@ struct vm86plus_struct {* at the end of the structure. Look at ptrace.h to see the "normal" * setup. For user space layout see 'struct vm86_regs' above. */ -#include <asm/ptrace.h> struct kernel_vm86_regs {/*
include/asm-x86/vm86_mask.h new file +12 -0
@@ -0,0 +1,12 @@ +#ifndef ASM_X86_VM86_MASK +#define ASM_X86_VM86_MASK + +#include <asm/processor-flags.h> + +#ifdef CONFIG_VM86 +#define X86_VM_MASK X86_EFLAGS_VM +#else +#define X86_VM_MASK 0/* No VM86 support */ +#endif + +#endif
Signature · 1 line
1.5.4.1
Quoted 5 lines · Vegard Nossum
Hi,
What do you think about this? The new file (
vm86_mask.h) could actually be embedded completely inprocessor-flags.h, but I went for what I believe is the safer approach.
Breaking the mutual header inclusion is appreciated, but some comments are below.
Quoted 29 lines
This has been compile tested on
x86_32andx86_64defconfig.Vegard
...include/asm-x86/ptrace.h +3
-4@@ -2,8 +2,10 @@#define _ASM_X86_PTRACE_H#include <linux/compiler.h> /* For __user */ +#include <asm/ds.h> /* the DS BTS struct is used for ptrace too */ +#include <asm/segment.h> #include <asm/ptrace-abi.h> - +#include <asm/vm86_mask.h> #ifndef __ASSEMBLY__@@ -55,9 +57,6 @@ struct pt_regs { unsigned long ss; }; -#include <asm/vm86.h> -#include <asm/segment.h> -#endif /* __KERNEL__ */ #else /* __i386__ */
include/asm-x86/ptrace.h struct pt_regs { · line 131
Quoted 9 lines
include/asm-x86/ptrace.h +0
-3@@ -127,9 +126,6 @@ struct pt_regs {#ifdef __KERNEL__ -/* the DS BTS struct is used for ptrace as well */ -#include <asm/ds.h> -struct task_struct ;extern void ptrace_bts_take_timestamp (struct task_struct *,enum bts_qualifier );
Moving #include's out of an #ifdef __KERNEL__ can (and does here) break our userspace headers.
Running "make headers_check" after touching anything under include/ is recommended since it catches these problems.
Quoted 6 lines
...
include/asm-x86/vm86_mask.h new file +2
-0@@ -0,0 +1,12 @@ +#ifndef ASM_X86_VM86_MASK +#define ASM_X86_VM86_MASK
include/asm-x86/vm86_mask.h line 12
Quoted 10 lines
include/asm-x86/vm86_mask.h new file +10
-0+ +#include <asm/processor-flags.h> + +#ifdef CONFIG_VM86 +#define X86_VM_MASK X86_EFLAGS_VM +#else +#define X86_VM_MASK 0/* No VM86 support */ +#endif + +#endif
Do we need a new header for this or can it go into processor-flags.h ?
cu
Adrian
Signature · 4 lines
"Is there not promise of rain?" Ling Tan asked suddenly out
of the darkness. There had been need of rain for many days.
"Only a promise," Lao Er said.
Pearl S. Buck - Dragon SeedHi!
Quoted 9 lines · Adrian Bunk
Quoted 5 lines · Vegard Nossum
Hi,
What do you think about this? The new file (
vm86_mask.h) could actually be embedded completely inprocessor-flags.h, but I went for what I believe is the safer approach.Breaking the mutual header inclusion is appreciated, but some comments are below.
[...]
Quoted 5 lines
Quoted 5 lines
include/asm-x86/ptrace.h +0
-3-/* the DS BTS struct is used for ptrace as well */ -#include <asm/ds.h> -struct task_struct ;
Quoted 8 lines
Quoted 1 line
extern void
ptrace_bts_take_timestamp(struct task_struct *, enum bts_qualifier);Moving #include's out of an #ifdef
__KERNEL__can (and does here) break our userspace headers.Running "make
headers_check" after touching anything underinclude/is recommended since it catches these problems.
Ah, that's true. My mistake.
CHECK include/asm/ptrace.h
[...]/usr/include/asm/ptrace.h requires asm/ds.h, which does not exist in exported headers
What do you reckon is better here, to put #ifdef __KERNEL__ around the whole of ds.h and export it, or put #ifdef __KERNEL__ around the #include in ptrace.h? It feels wasteful to put it around the whole ds.h, since what is the point in exporting an empty file? On the other hand, it makes much more sense to put it there than in the "caller" in order to avoid the duplication of #ifdef __KERNEL__. So unless you prefer otherwise, I will choose the former (to export ds.h as well).
I hope you agree with the idea of moving the #include line to the top of the file, however?
Thanks for the tip, that is very useful. I didn't realize I should use that and I'm sorry for wasting your time with the first attempt :-(
Quoted 10 lines
Quoted 10 lines
...
include/asm-x86/vm86_mask.h new file +6
-0@@ -0,0 +1,12 @@ +#ifndef ASM_X86_VM86_MASK +#define ASM_X86_VM86_MASK + +#include <asm/processor-flags.h> + +#ifdef CONFIG_VM86
Quoted 8 lines
include/asm-x86/vm86_mask.h line 12
Quoted 6 lines
include/asm-x86/vm86_mask.h new file +6
-0+#define X86_VM_MASK X86_EFLAGS_VM +#else +#define X86_VM_MASK 0/* No VM86 support */ +#endif + +#endif Do we need a new header for this or can it go into
processor-flags.h?
It can go in there, yes. I will do that in the re-worked (hopefully correct) patch.
This business of breaking cycles is a bit nasty. There are very many traps to fall into, very many setups to break, and very little support from the tools to help you get it right (though with 'make headers_check' I am a little better off).
Thanks for the help :-)
Vegard
Signature · 4 lines
"The animistic metaphor of the bug that maliciously sneaked in while the programmer was not looking is intellectually dishonest as it disguises that the error is the programmer's own creation." -- E. W. Dijkstra, EWD1036
Quoted 35 lines · Vegard Nossum
Hi!
Quoted 9 lines · Adrian Bunk
Quoted 5 lines · Vegard Nossum
Hi,
What do you think about this? The new file (
vm86_mask.h) could actually be embedded completely inprocessor-flags.h, but I went for what I believe is the safer approach.Breaking the mutual header inclusion is appreciated, but some comments are below.
[...]
Quoted 5 lines
Quoted 5 lines
include/asm-x86/ptrace.h +0
-3-/* the DS BTS struct is used for ptrace as well */ -#include <asm/ds.h> -struct task_struct ;Quoted 8 lines
Quoted 1 line
extern void
ptrace_bts_take_timestamp(struct task_struct *, enum bts_qualifier);Moving #include's out of an #ifdef
__KERNEL__can (and does here) break our userspace headers.Running "make
headers_check" after touching anything underinclude/is recommended since it catches these problems.Ah, that's true. My mistake.
CHECK
include/asm/ptrace.h
[...]/usr/include/asm/ptrace.h requiresasm/ds.h, which does not exist in exported headers
Quoted 7 lines
What do you reckon is better here, to put #ifdef
__KERNEL__around the whole ofds.hand export it, or put #ifdef__KERNEL__around the #include inptrace.h? It feels wasteful to put it around the wholeds.h, since what is the point in exporting an empty file? On the other hand, it makes much more sense to put it there than in the "caller" in order to avoid the duplication of #ifdef__KERNEL__. So unless you prefer otherwise, I will choose the former (to exportds.has well).
Our userspace headers are an API, and offering empty previsously unexported headers to userspace sounds like the worse choice to me.
Additionally, asm/segment.h (and asm/vm86_mask.h) have the same problem.
Quoted 2 lines
I hope you agree with the idea of moving the #include line to the top of the file, however?
For me it looks good.
Quoted 2 lines
Thanks for the tip, that is very useful. I didn't realize I should use that and I'm sorry for wasting your time with the first attempt :-(
No problem, and I don't consider it a waste of time.
Quoted 4 lines
...
Thanks for the help :-)Vegard
cu
Adrian
Signature · 4 lines
"Is there not promise of rain?" Ling Tan asked suddenly out
of the darkness. There had been need of rain for many days.
"Only a promise," Lao Er said.
Pearl S. Buck - Dragon Seed