x86: unify asm/page.h
PATCH 1/1 x86: unify asm/page.h
Hi Ingo,
Here's a series which concentrates on unifying and cleaning up asm-86/page*.h. Each patch in the series restricts itself to doing one thing fairly simply, so it should be fairly low-risk and easy to bisect.
The early version of this patch got rid of asm/page_32|64.h entirely, but I decided the resulting #ifdef hell was too hard to deal with, so I moved purely 32/64-bit specific stuff into their own files.
Thanks,
J
PATCH 1/1 x86: add _AT() macro to conditionally cast
# HG changeset patch
# User Jeremy Fitzhardinge <[email protected]> # Date 1199317452 28800
# Node ID f7e7db3facd9406545103164f9be8f9ba1a2b549 # Parent 4d9a413a0f4c1d98dbea704f0366457b5117045d
x86: add _AT() macro to conditionally cast
Define _AT(type, value) to conditionally cast a value when compiling C code, but not when used in assembler.
--- include/linux/const.h | 5 +++++ 1 file changed, 5 insertions(+)
include/linux/const.h +5 -0
@@ -7,13 +7,18 @@* C code. Therefore we cannot annotate them always with * 'UL' and other type specifiers unilaterally. We * use the following macros to deal with this. +* +* Similarly, _AT() will cast an expression with a type in C, but +* leave it unchanged in asm. */ #ifdef __ASSEMBLY__#define _AC (X ,Y ) X +#define _AT (T ,X ) X#else #define __AC (X ,Y ) (X##Y)#define _AC (X ,Y ) __AC(X,Y) +#define _AT (T ,X ) ((T)(X))#endif #endif /* !(_LINUX_CONST_H) */
PATCH 1/1 x86: page.h: unify page copying and clearing
In reply to Jeremy Fitzhardinge# HG changeset patch
# User Jeremy Fitzhardinge <[email protected]> # Date 1199317362 28800
# Node ID 4d9a413a0f4c1d98dbea704f0366457b5117045d # Parent ba0ec40a50a7aef1a3153cea124c35e261f5a2df
x86: page.h: unify page copying and clearing
Move, and to some extent unify, the various page copying and clearing functions. The only unification here is that both architectures use the same function for copying/clearing user and kernel pages.
--- include/asm-x86/page.h | 55 +++++++++++++++++++++++++++++++++++++++++++++ include/asm-x86/page_32.h | 53 ------------------------------------------- include/asm-x86/page_64.h | 20 ---------------- 3 files changed, 55 insertions(+), 73 deletions(-)
include/asm-x86/page.h +55 -0
@@ -70,6 +70,11 @@#define KERNEL_TEXT_SIZE (40*1024*1024)#define KERNEL_TEXT_START _AC(0xffffffff80000000, UL) +#ifndef __ASSEMBLY__ +void clear_page (void *page); +void copy_page (void *to,void *from); +#endif /* !__ASSEMBLY__ */ +#endif /* CONFIG_X86_64 */ #ifdef CONFIG_X86_32
@@ -98,6 +103,34 @@#define HAVE_ARCH_HUGETLB_UNMAPPED_AREA #endif +#ifndef __ASSEMBLY__ +#ifdef CONFIG_X86_USE_3DNOW +#include <asm/mmx.h> + +static inline void clear_page (void *page) +{ +mmx_clear_page (page); +} + +static inline void copy_page (void *to,void *from) +{ +mmx_copy_page (to, from); +} +#else /* !CONFIG_X86_USE_3DNOW */ +#include <linux/string.h> + +static inline void clear_page (void *page) +{ +memset (page,0 ,PAGE_SIZE ); +} + +static inline void copy_page (void *to,void *from) +{ +memcpy (to, from,PAGE_SIZE ); +} +#endif /* CONFIG_X86_3DNOW */ +#endif /* !__ASSEMBLY__ */ +#endif /* CONFIG_X86_32 */ #define PAGE_OFFSET ((unsigned long)__PAGE_OFFSET)
@@ -107,6 +140,28 @@ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC) +#ifndef __ASSEMBLY__ +struct page ; + +static void inline clear_user_page (void *page,unsigned long vaddr, +struct page *pg) +{ +clear_page (page); +} + +static void inline copy_user_page (void *to,void *from,unsigned long vaddr, +struct page *topage) +{ +copy_page (to, from); +} + +#define __alloc_zeroed_user_highpage (movableflags, vma, vaddr) \ + alloc_page_vma(GFP_HIGHUSER | __GFP_ZERO | movableflags, vma, vaddr) +#define __HAVE_ARCH_ALLOC_ZEROED_USER_HIGHPAGE + +#endif /* __ASSEMBLY__ */ + +#ifdef CONFIG_X86_32 # include "page_32.h" #else
include/asm-x86/page_32.h +0 -53
59 lines not on this page · raw message
include/asm-x86/page_64.h +0 -20
@@ -7,26 +7,6 @@ extern unsigned long end_pfn;extern unsigned long end_pfn;extern unsigned long end_pfn_map; -void clear_page (void *page); -void copy_page (void *to,void *from); - -struct page ; - -static void inline clear_user_page (void *page,unsigned long vaddr, -struct page *pg) -{ -clear_page (page); -} - -static void inline copy_user_page (void *to,void *from,unsigned long vaddr, -struct page *topage) -{ -copy_page (to, from); -} - -#define __alloc_zeroed_user_highpage (movableflags, vma, vaddr) \ - alloc_page_vma(GFP_HIGHUSER | __GFP_ZERO | movableflags, vma, vaddr) -#define __HAVE_ARCH_ALLOC_ZEROED_USER_HIGHPAGE/* * These are used to make use of C type-checking.. */
PATCH 1/1 x86: page.h: move pa and va related things
In reply to Jeremy Fitzhardinge# HG changeset patch
# User Jeremy Fitzhardinge <[email protected]> # Date 1199319656 28800
# Node ID d617b72a0cc9d14bde2087d065c36d4ed3265761 # Parent 3bd7db6e85e66e7f3362874802df26a82fcb2d92
x86: page.h: move pa and va related things
Move and unify the virtual<->physical address space conversion functions.
--- include/asm-x86/page.h | 24 ++++++++++++++++++++++++ include/asm-x86/page_32.h | 11 ----------- include/asm-x86/page_64.h | 13 ------------- 3 files changed, 24 insertions(+), 24 deletions(-)
include/asm-x86/page.h +24 -0
@@ -79,6 +79,9 @@#ifndef __ASSEMBLY__void clear_page (void *page);void copy_page (void *to,void *from); + +extern unsigned long __phys_addr (unsigned long ); +#define __phys_reloc_hide (x) (x)/* * These are used to make use of C type-checking..
@@ -174,6 +177,13 @@ static inline pte_t native_make_pte(unsi#endif #ifndef __ASSEMBLY__ +#define __phys_addr (x) ((x)-PAGE_OFFSET) +#define __phys_reloc_hide (x) RELOC_HIDE((x), 0) + +#ifdef CONFIG_FLATMEM +#define pfn_valid (pfn) ((pfn) < max_mapnr) +#endif /* CONFIG_FLATMEM */ +#ifdef CONFIG_X86_USE_3DNOW #include <asm/mmx.h>
@@ -299,6 +309,20 @@ static inline pmdval_t native_pmd_val(pm#endif /* CONFIG_PARAVIRT */ +#define __pa (x) __phys_addr((unsigned long)(x)) +/* __pa_symbol should be used for C visible symbols. +This seems to be the official gcc blessed way to do such arithmetic. */ +#define __pa_symbol (x) __pa(__phys_reloc_hide((unsigned long)(x))) + +#define __va (x) ((void *)((unsigned long)(x)+PAGE_OFFSET)) + +#define __boot_va (x) __va(x) +#define __boot_pa (x) __pa(x) + +#define virt_to_page (kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT) +#define pfn_to_kaddr (pfn) __va((pfn) << PAGE_SHIFT) +#define virt_addr_valid (kaddr) pfn_valid(__pa(kaddr) >> PAGE_SHIFT) +#endif /* __ASSEMBLY__ */
include/asm-x86/page_32.h +0 -11
@@ -29,18 +29,7 @@ extern int page_is_ram(unsigned long pag#define VMALLOC_RESERVE ((unsigned long)__VMALLOC_RESERVE)#define MAXMEM (-__PAGE_OFFSET-__VMALLOC_RESERVE) -#define __pa (x) ((unsigned long)(x)-PAGE_OFFSET) -/* __pa_symbol should be used for C visible symbols. -This seems to be the official gcc blessed way to do such arithmetic. */ -#define __pa_symbol (x) __pa(RELOC_HIDE((unsigned long)(x),0)) -#define __va (x) ((void *)((unsigned long)(x)+PAGE_OFFSET)) -#define pfn_to_kaddr (pfn) __va((pfn) << PAGE_SHIFT) -#ifdef CONFIG_FLATMEM -#define pfn_valid (pfn) ((pfn) < max_mapnr) -#endif /* CONFIG_FLATMEM */ -#define virt_to_page (kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT) -#define virt_addr_valid (kaddr) pfn_valid(__pa(kaddr) >> PAGE_SHIFT)#include <asm-generic/memory_model.h> #include <asm-generic/page.h>
include/asm-x86/page_64.h +0 -13
@@ -16,20 +16,7 @@ extern unsigned long phys_base;#include <asm/bug.h> -extern unsigned long __phys_addr (unsigned long ); -#endif /* __ASSEMBLY__ */ - -#define __pa (x) __phys_addr((unsigned long)(x)) -#define __pa_symbol (x) __phys_addr((unsigned long)(x)) - -#define __va (x) ((void *)((unsigned long)(x)+PAGE_OFFSET)) -#define __boot_va (x) __va(x) -#define __boot_pa (x) __pa(x) - -#define virt_to_page (kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT) -#define virt_addr_valid (kaddr) pfn_valid(__pa(kaddr) >> PAGE_SHIFT) -#define pfn_to_kaddr (pfn) __va((pfn) << PAGE_SHIFT)#define __HAVE_ARCH_GATE_AREA 1#define vmemmap ((struct page *)VMEMMAP_START)
PATCH 1/1 x86: page.h: unify constants
In reply to Jeremy Fitzhardinge# HG changeset patch
# User Jeremy Fitzhardinge <[email protected]> # Date 1199317360 28800
# Node ID ba0ec40a50a7aef1a3153cea124c35e261f5a2df # Parent c45c263179cb78284b6b869c574457df088027d1
x86: page.h: unify constants
There are many constants which are shared by 32 and 64-bit.
--- include/asm-x86/page.h | 130 +++++++++++++++++++++++++++++++++++++++++---- include/asm-x86/page_32.h | 46 --------------- include/asm-x86/page_64.h | 73 ------------------------- 3 files changed, 119 insertions(+), 130 deletions(-)
include/asm-x86/page.h +114 -11
@@ -1,13 +1,116 @@ -#ifdef __KERNEL__ -# ifdef CONFIG_X86_32 -# include "page_32.h" -# else -# include "page_64.h" -# endif +#ifndef _ASM_X86_PAGE_H +#define _ASM_X86_PAGE_H + +#include <linux/const.h> + +/* PAGE_SHIFT determines the page size */ +#define PAGE_SHIFT 12 +#define PAGE_SIZE (_AC(1,UL) << PAGE_SHIFT) +#define PAGE_MASK (~(PAGE_SIZE-1)) + +#define PHYSICAL_PAGE_MASK (PAGE_MASK & __PHYSICAL_MASK) + +#define LARGE_PAGE_SIZE (_AC(1,UL) << PMD_SHIFT) +#define LARGE_PAGE_MASK (~(LARGE_PAGE_SIZE-1)) + +#define HPAGE_SHIFT PMD_SHIFT +#define HPAGE_SIZE (_AC(1,UL) << HPAGE_SHIFT) +#define HPAGE_MASK (~(HPAGE_SIZE - 1)) +#define HUGETLB_PAGE_ORDER (HPAGE_SHIFT - PAGE_SHIFT) + +/* to align the pointer to the (next) page boundary */ +#define PAGE_ALIGN (addr) (((addr)+PAGE_SIZE-1)&PAGE_MASK) + +#define __PHYSICAL_MASK ((_AC(1,UL) << __PHYSICAL_MASK_SHIFT) - 1) +#define __VIRTUAL_MASK ((_AC(1,UL) << __VIRTUAL_MASK_SHIFT) - 1) + + +#ifdef CONFIG_X86_64 +#define THREAD_ORDER 1 +#define THREAD_SIZE (PAGE_SIZE << THREAD_ORDER) +#define CURRENT_MASK (~(THREAD_SIZE-1)) + +#define EXCEPTION_STACK_ORDER 0 +#define EXCEPTION_STKSZ (PAGE_SIZE << EXCEPTION_STACK_ORDER) + +#define DEBUG_STACK_ORDER (EXCEPTION_STACK_ORDER + 1) +#define DEBUG_STKSZ (PAGE_SIZE << DEBUG_STACK_ORDER) + +#define IRQSTACK_ORDER 2 +#define IRQSTACKSIZE (PAGE_SIZE << IRQSTACK_ORDER) + +#define STACKFAULT_STACK 1 +#define DOUBLEFAULT_STACK 2 +#define NMI_STACK 3 +#define DEBUG_STACK 4 +#define MCE_STACK 5 +#define N_EXCEPTION_STACKS 5/* hw limit: 7 */ + +#define __PAGE_OFFSET _AC(0xffff810000000000, UL) + +#define __PHYSICAL_START CONFIG_PHYSICAL_START +#define __KERNEL_ALIGN 0x200000 + +/* +* Make sure kernel is aligned to 2MB address. Catching it at compile +* time is better. Change your config file and compile the kernel +* for a 2MB aligned address (CONFIG_PHYSICAL_START) +*/ +#if (CONFIG_PHYSICAL_START % __KERNEL_ALIGN) !=0 +#error "CONFIG_PHYSICAL_START must be a multiple of 2MB" +#endif + +#define __START_KERNEL (__START_KERNEL_map + __PHYSICAL_START) +#define __START_KERNEL_map _AC(0xffffffff80000000, UL) + +/* See Documentation/x86_64/mm.txt for a description of the memory map. */ +#define __PHYSICAL_MASK_SHIFT 46 +#define __VIRTUAL_MASK_SHIFT 48 + +#define KERNEL_TEXT_SIZE (40*1024*1024) +#define KERNEL_TEXT_START _AC(0xffffffff80000000, UL) + +#endif /* CONFIG_X86_64 */ + +#ifdef CONFIG_X86_32 + +/* +* This handles the memory map. +* +* A __PAGE_OFFSET of 0xC0000000 means that the kernel has +* a virtual address space of one gigabyte, which limits the +* amount of physical memory you can use to about 950MB. +* +* If you want more physical memory than this then see the CONFIG_HIGHMEM4G +* and CONFIG_HIGHMEM64G options in the kernel configuration. +*/ +#define __PAGE_OFFSET _AC(CONFIG_PAGE_OFFSET, UL) + +#ifdef CONFIG_X86_PAE +#define __PHYSICAL_MASK_SHIFT 36 +#define __VIRTUAL_MASK_SHIFT 32 +#else /* !CONFIG_X86_PAE */ +#define __PHYSICAL_MASK_SHIFT 32 +#define __VIRTUAL_MASK_SHIFT 32 +#endif /* CONFIG_X86_PAE */ + +#ifdef CONFIG_HUGETLB_PAGE +#define HAVE_ARCH_HUGETLB_UNMAPPED_AREA +#endif + +#endif /* CONFIG_X86_32 */ + +#define PAGE_OFFSET ((unsigned long)__PAGE_OFFSET) + +#define VM_DATA_DEFAULT_FLAGS \ + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0 ) | \ + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC) + + +#ifdef CONFIG_X86_32 +# include "page_32.h" #else -# ifdef __i386__ -# include "page_32.h" -# else -# include "page_64.h" -# endif +# include "page_64.h" #endif + +#endif /* _ASM_X86_PAGE_H */
include/asm-x86/page_32.h +0 -46
85 lines not on this page · raw message
include/asm-x86/page_64.h +0 -69
86 lines not on this page · raw message
Re: [PATCH 1 of 8] x86: page.h: unify constants
include/asm-x86/page.h line 19
Quoted 9 lines
include/asm-x86/page.h +8
-0+ +#define LARGE_PAGE_SIZE (_AC(1,UL) << PMD_SHIFT) +#define LARGE_PAGE_MASK (~(LARGE_PAGE_SIZE-1)) + +#define HPAGE_SHIFT PMD_SHIFT +#define HPAGE_SIZE (_AC(1,UL) << HPAGE_SHIFT) +#define HPAGE_MASK (~(HPAGE_SIZE - 1)) +#define HUGETLB_PAGE_ORDER (HPAGE_SHIFT - PAGE_SHIFT)
This will actually stop being the same soon with GB pages which are only supported on 64bit.
Quoted 4 lines
include/asm-x86/page.h +4
-0+ +#ifdef CONFIG_X86_64 +#define THREAD_ORDER 1 +#define THREAD_SIZE (PAGE_SIZE << THREAD_ORDER)
include/asm-x86/page.h line 40
Quoted 10 lines
include/asm-x86/page.h +10
-0+#define CURRENT_MASK (~(THREAD_SIZE-1)) + +#define EXCEPTION_STACK_ORDER 0 +#define EXCEPTION_STKSZ (PAGE_SIZE << EXCEPTION_STACK_ORDER) + +#define DEBUG_STACK_ORDER (EXCEPTION_STACK_ORDER + 1) +#define DEBUG_STKSZ (PAGE_SIZE << DEBUG_STACK_ORDER) + +#define IRQSTACK_ORDER 2 +#define IRQSTACKSIZE (PAGE_SIZE << IRQSTACK_ORDER)
This all seems hardly 64bit specific (except for THREAD_ORDER but you can probably handle that in Kconfig or just get rid of it for 32bit)
Quoted 1 line
+#define
__PHYSICAL_STARTCONFIG_PHYSICAL_START
Also not 64bit specific
include/asm-x86/page.h line 90
Quoted 2 lines
include/asm-x86/page.h +2
-0+#ifdef CONFIG_X86_PAE +#define __PHYSICAL_MASK_SHIFT 36
I originally added the PHYSICAL_MASK stuff to deal with masking off NX, but I must admit it wasn't the best idea I ever had. It would be probably better to just get rid of it and always mask off the high reserved flags bit explicitely. If you make that 0 then there should be no special case for PAE.
-Andi
Re: [PATCH 1 of 8] x86: page.h: unify constants
Quoted 4 lines · Andi Kleen
Quoted 4 lines
include/asm-x86/page.h +4
-0+ +#define LARGE_PAGE_SIZE (_AC(1,UL) << PMD_SHIFT) +#define LARGE_PAGE_MASK (~(LARGE_PAGE_SIZE-1)) +
Quoted 9 lines
include/asm-x86/page.h line 19
Quoted 5 lines
include/asm-x86/page.h +4
-0+#define HPAGE_SHIFT PMD_SHIFT +#define HPAGE_SIZE (_AC(1,UL) << HPAGE_SHIFT) +#define HPAGE_MASK (~(HPAGE_SIZE - 1)) +#define HUGETLB_PAGE_ORDER (HPAGE_SHIFT - PAGE_SHIFT)This will actually stop being the same soon with GB pages which are only supported on 64bit.
I was wondering about that. Will you always use GB pages, or will there be two classes of huge pages, or will it be a runtime/compiletime config?
Quoted 11 lines
Quoted 11 lines
include/asm-x86/page.h +11
-0+ +#ifdef CONFIG_X86_64 +#define THREAD_ORDER 1 +#define THREAD_SIZE (PAGE_SIZE << THREAD_ORDER) +#define CURRENT_MASK (~(THREAD_SIZE-1)) + +#define EXCEPTION_STACK_ORDER 0 +#define EXCEPTION_STKSZ (PAGE_SIZE << EXCEPTION_STACK_ORDER) + +#define DEBUG_STACK_ORDER (EXCEPTION_STACK_ORDER + 1) +#define DEBUG_STKSZ (PAGE_SIZE << DEBUG_STACK_ORDER)
Quoted 9 lines
include/asm-x86/page.h line 40
Quoted 4 lines
include/asm-x86/page.h +3
-0+ +#define IRQSTACK_ORDER 2 +#define IRQSTACKSIZE (PAGE_SIZE << IRQSTACK_ORDER)This all seems hardly 64bit specific (except for
THREAD_ORDERbut you can probably handle that inKconfigor just get rid of it for 32bit)
They're only used by 64-bit at the moment, aren't they? Or are you suggesting 32-bit could use them too? There's no corresponding definitions on the 32-bit side at the moment.
Quoted 5 lines
Quoted 2 lines
+#define
__PHYSICAL_STARTCONFIG_PHYSICAL_STARTAlso not 64bit specific
It's use is 64-bit specific though, isn't it?
Quoted 10 lines
include/asm-x86/page.h line 90
Quoted 3 lines
include/asm-x86/page.h +2
-0+#ifdef CONFIG_X86_PAE +#define __PHYSICAL_MASK_SHIFT 36I originally added the
PHYSICAL_MASKstuff to deal with masking off NX, but I must admit it wasn't the best idea I ever had. It would be probably better to just get rid of it and always mask off the high reserved flags bit explicitely. If you make that 0 then there should be no special case for PAE.
Hm, OK. I thought different 64-bit implementations might have different sized physical address spaces or something.
J
Re: [PATCH 1 of 8] x86: page.h: unify constants
Quoted 15 lines · Jeremy Fitzhardinge
Quoted 4 lines · Andi Kleen
Quoted 4 lines
include/asm-x86/page.h +4
-0+ +#define LARGE_PAGE_SIZE (_AC(1,UL) << PMD_SHIFT) +#define LARGE_PAGE_MASK (~(LARGE_PAGE_SIZE-1)) +Quoted 9 lines
include/asm-x86/page.h line 19
Quoted 5 lines
include/asm-x86/page.h +4
-0+#define HPAGE_SHIFT PMD_SHIFT +#define HPAGE_SIZE (_AC(1,UL) << HPAGE_SHIFT) +#define HPAGE_MASK (~(HPAGE_SIZE - 1)) +#define HUGETLB_PAGE_ORDER (HPAGE_SHIFT - PAGE_SHIFT)This will actually stop being the same soon with GB pages which are only supported on 64bit.
Quoted 1 line
I was wondering about that. Will you always use GB pages, or will there be
When available and not disabled yes.
Quoted 1 line
two classes of huge pages, or will it be a runtime/compiletime config?
hugetlbfs will use different classes of huge pages depending on configuration (I haven't posted those patches yet, only those for the direct mapping) That all is expressed by different macros.
All runtime; I expect no CONFIGs involved, except that 32bit won't have it since the architecture doesn't support it there.
Quoted 22 lines
Quoted 12 lines
Quoted 12 lines
include/asm-x86/page.h +11
-0+ +#ifdef CONFIG_X86_64 +#define THREAD_ORDER 1 +#define THREAD_SIZE (PAGE_SIZE << THREAD_ORDER) +#define CURRENT_MASK (~(THREAD_SIZE-1)) + +#define EXCEPTION_STACK_ORDER 0 +#define EXCEPTION_STKSZ (PAGE_SIZE << EXCEPTION_STACK_ORDER) + +#define DEBUG_STACK_ORDER (EXCEPTION_STACK_ORDER + 1) +#define DEBUG_STKSZ (PAGE_SIZE << DEBUG_STACK_ORDER)Quoted 9 lines
include/asm-x86/page.h line 40
Quoted 4 lines
include/asm-x86/page.h +3
-0+ +#define IRQSTACK_ORDER 2 +#define IRQSTACKSIZE (PAGE_SIZE << IRQSTACK_ORDER)This all seems hardly 64bit specific (except for
THREAD_ORDERbut you can probably handle that inKconfigor just get rid of it for 32bit)
Quoted 1 line
They're only used by 64-bit at the moment, aren't they? Or are you
THREAD_ORDER should be used on 32bit too.
32bit also has the equivalent of irq stacks (quite similar) and exception stacks (somewhat different). Currently they use other defines, but they could use the same. Also i386 has varying irqstack orders disabling them with 8k stacks, but that is something that would be best dropped and irqstacks always used imho.
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
+#define
__PHYSICAL_STARTCONFIG_PHYSICAL_STARTAlso not 64bit specific
It's use is 64-bit specific though, isn't it?
It might be, but it's not a 64bit specific concept.
Quoted 13 lines
Quoted 12 lines
include/asm-x86/page.h line 90
Quoted 4 lines
include/asm-x86/page.h +2
-0+#ifdef CONFIG_X86_PAE +#define __PHYSICAL_MASK_SHIFT 36I originally added the
PHYSICAL_MASKstuff to deal with masking off NX, but I must admit it wasn't the best idea I ever had. It would be probably better to just get rid of it and always mask off the high reserved flags bit
explicitely. If you make that 0 then there should be no special case for PAE.
Quoted 2 lines
Hm, OK. I thought different 64-bit implementations might have different sized physical address spaces or something.
Yes they do, but hardcoding that doesn't make sense because it varies. We already got CPUs with 36, 38, 40 and 48 bits phys size.
The only size that could be hard coded would be 52 bit (theoretical max), but that also doesn't make sense if all we want to do is to mask off NX.
The only code that needs to know the real physical size is the MTRR code, but that one gets it from CPUID as it should.
-Andi
Re: [PATCH 1 of 8] x86: page.h: unify constants
Quoted 9 lines · Andi Kleen
THREAD_ORDERshould be used on 32bit too.32bit also has the equivalent of irq stacks (quite similar) and exception stacks (somewhat different). Currently they use other defines, but they could use the same. Also i386 has varying
irqstack orders disabling them with 8k stacks, but that is something
that would be best dropped and irqstacks always used imho.
[...]
It might be, but it's not a 64bit specific concept.
OK. That's out of the scope of these particular patches, since they're restricting themselves to just unifying what's there. Another pass could definitely tidy a lot more up.
Quoted 5 lines
Yes they do, but hardcoding that doesn't make sense because it varies. We already got CPUs with 36, 38, 40 and 48 bits phys size.
The only size that could be hard coded would be 52 bit (theoretical max), but that also doesn't make sense if all we want to do is to mask off NX.
OK. I'll see how much removing it gains us.
J
PATCH 1/1 x86: page.h: move and unify types for pagetable entry definitions
In reply to Jeremy Fitzhardinge# HG changeset patch
# User Jeremy Fitzhardinge <[email protected]>
# Date 1199319654 28800
# Node ID 3bd7db6e85e66e7f3362874802df26a82fcb2d92
# Parent f7e7db3facd9406545103164f9be8f9ba1a2b549
x86: page.h: move and unify types for pagetable entry definitions
This patch:
1. Defines arch-specific types for the contents of a pagetable entry. That is, 32-bit entries for 32-bit non-PAE, and 64-bit entries for 32-bit PAE and 64-bit. However, even though the latter two are the same size, they're defined with different types in order to retain compatibility with printk format strings, etc.
2. Defines arch-specific pte_t. This is different because 32-bit PAE defines it in two halves, whereas 32-bit PAE and 64-bit define it as a single entry. All the other pagetable levels can be defined in a common way. This also defines arch-specific pte_val/make_pte functions.
3. Define PAGETABLE_LEVELS for each architecture variation, for later use.
4. Define common pagetable entry accessors in a paravirt-compatible way. (64-bit does not yet use paravirt-ops in any way).
5. Convert a few instances of using a *_val() as an lvalue where it is no longer a macro. There are still places in the 64-bit code which use pte_val() as an lvalue.
--- include/asm-x86/page.h | 139 +++++++++++++++++++++++++++++++++++++++++- include/asm-x86/page_32.h | 83 ------------------------- include/asm-x86/page_64.h | 22 ------ include/asm-x86/pgtable_64.h | 6 - 4 files changed, 141 insertions(+), 109 deletions(-)
include/asm-x86/page.h +141 -1
@@ -9,6 +9,7 @@#define PAGE_MASK (~(PAGE_SIZE-1))#define PHYSICAL_PAGE_MASK (PAGE_MASK & __PHYSICAL_MASK) +#define PTE_MASK PHYSICAL_PAGE_MASK#define LARGE_PAGE_SIZE (_AC(1,UL) << PMD_SHIFT)#define LARGE_PAGE_MASK (~(LARGE_PAGE_SIZE-1))
@@ -21,11 +22,16 @@/* to align the pointer to the (next) page boundary */ #define PAGE_ALIGN (addr) (((addr)+PAGE_SIZE-1)&PAGE_MASK) -#define __PHYSICAL_MASK ((_AC(1,UL) << __PHYSICAL_MASK_SHIFT) - 1) +#define __PHYSICAL_MASK _AT(phys_addr_t, (_AC(1,ULL) << __PHYSICAL_MASK_SHIFT) - 1)#define __VIRTUAL_MASK ((_AC(1,UL) << __VIRTUAL_MASK_SHIFT) - 1) +#ifndef __ASSEMBLER__ +#include <linux/types.h> +#endif #ifdef CONFIG_X86_64 +#define PAGETABLE_LEVELS 4 +#define THREAD_ORDER 1#define THREAD_SIZE (PAGE_SIZE << THREAD_ORDER)#define CURRENT_MASK (~(THREAD_SIZE-1))
@@ -73,6 +79,22 @@#ifndef __ASSEMBLY__void clear_page (void *page);void copy_page (void *to,void *from); + +/* +* These are used to make use of C type-checking.. +*/ +typedef unsigned long pteval_t ; +typedef unsigned long pmdval_t ; +typedef unsigned long pudval_t ; +typedef unsigned long pgdval_t ; +typedef unsigned long pgprotval_t ; +typedef unsigned long phys_addr_t ; + +typedef struct {pteval_t pte; }pte_t ; + +#define native_pte_val (x) ((x).pte) +#define native_make_pte (x) ((pte_t) { (x) } ) +#endif /* !__ASSEMBLY__ */ #endif /* CONFIG_X86_64 */
@@ -94,9 +116,57 @@ void copy_page(void *to, void *from);#ifdef CONFIG_X86_PAE #define __PHYSICAL_MASK_SHIFT 36#define __VIRTUAL_MASK_SHIFT 32 +#define PAGETABLE_LEVELS 3 + +#ifndef __ASSEMBLY__ +typedef u64 pteval_t ; +typedef u64 pmdval_t ; +typedef u64 pudval_t ; +typedef u64 pgdval_t ; +typedef u64 pgprotval_t ; +typedef u64 phys_addr_t ; + +typedef struct {unsigned long pte_low, pte_high; }pte_t ; + +static inline unsigned long long native_pte_val (pte_t pte) +{ +return pte.pte_low | ((unsigned long long )pte.pte_high <<32 ); +} + +static inline pte_t native_make_pte (unsigned long long val) +{ +return (pte_t ) { .pte_low = val, .pte_high = (val >>32 ) } ; +} + +#endif /* __ASSEMBLY__ +*/ #else /* !CONFIG_X86_PAE */ #define __PHYSICAL_MASK_SHIFT 32#define __VIRTUAL_MASK_SHIFT 32 +#define PAGETABLE_LEVELS 2 + +#ifndef __ASSEMBLY__ +typedef unsigned long pteval_t ; +typedef unsigned long pmdval_t ; +typedef unsigned long pudval_t ; +typedef unsigned long pgdval_t ; +typedef unsigned long pgprotval_t ; +typedef unsigned long phys_addr_t ; + +typedef struct {pteval_t pte_low; }pte_t ; +typedef pte_t boot_pte_t ; + +static inline unsigned long native_pte_val (pte_t pte) +{ +return pte.pte_low; +} + +static inline pte_t native_make_pte (unsigned long val) +{ +return (pte_t ) { .pte_low = val }; +} + +#endif /* __ASSEMBLY__ */ #endif /* CONFIG_X86_PAE */ #ifdef CONFIG_HUGETLB_PAGE
@@ -159,6 +229,76 @@ static void inline copy_user_page(void * alloc_page_vma(GFP_HIGHUSER | __GFP_ZERO | movableflags, vma, vaddr)#define __HAVE_ARCH_ALLOC_ZEROED_USER_HIGHPAGE +typedef struct {pgdval_t pgd; }pgd_t ; +typedef struct {pgprotval_t pgprot; }pgprot_t ; + +static inline pgd_t native_make_pgd (pgdval_t val) +{ +return (pgd_t ) { val }; +} + +static inline pgdval_t native_pgd_val (pgd_t pgd) +{ +return pgd.pgd; +} + +#if PAGETABLE_LEVELS >=3 +#if PAGETABLE_LEVELS ==4 +typedef struct {pudval_t pud; }pud_t ; + +static inline pud_t native_make_pud (pmdval_t val) +{ +return (pud_t ) { val }; +} + +static inline pudval_t native_pud_val (pud_t pud) +{ +return pud.pud; +} +#else /* PAGETABLE_LEVELS == 3 */ +#include <asm-generic/pgtable-nopud.h> +#endif /* PAGETABLE_LEVELS == 4 */ + +typedef struct {pmdval_t pmd; }pmd_t ; + +static inline pmd_t native_make_pmd (pmdval_t val) +{ +return (pmd_t ) { val }; +} + +static inline pmdval_t native_pmd_val (pmd_t pmd) +{ +return pmd.pmd; +} +#else /* PAGETABLE_LEVELS == 2 */ +#include <asm-generic/pgtable-nopmd.h> +#endif /* PAGETABLE_LEVELS >= 3 */ + +#define pgprot_val (x) ((x).pgprot) +#define __pgprot (x) ((pgprot_t) { (x) } ) + +#ifdef CONFIG_PARAVIRT +#include <asm/paravirt.h> +#else /* !CONFIG_PARAVIRT */ + +#define pgd_val (x) native_pgd_val(x) +#define __pgd (x) native_make_pgd(x) + +#ifndef __PAGETABLE_PUD_FOLDED +#define pud_val (x) native_pud_val(x) +#define __pud (x) native_make_pud(x) +#endif + +#ifndef __PAGETABLE_PMD_FOLDED +#define pmd_val (x) native_pmd_val(x) +#define __pmd (x) native_make_pmd(x) +#endif + +#define pte_val (x) native_pte_val(x) +#define __pte (x) native_make_pte(x) + +#endif /* CONFIG_PARAVIRT */ +#endif /* __ASSEMBLY__ */
include/asm-x86/page_32.h +0 -83
89 lines not on this page · raw message
include/asm-x86/page_64.h +0 -22
@@ -7,30 +7,8 @@ extern unsigned long end_pfn;extern unsigned long end_pfn;extern unsigned long end_pfn_map; -/* -* These are used to make use of C type-checking.. -*/ -typedef struct {unsigned long pte; }pte_t ; -typedef struct {unsigned long pmd; }pmd_t ; -typedef struct {unsigned long pud; }pud_t ; -typedef struct {unsigned long pgd; }pgd_t ; -#define PTE_MASK PHYSICAL_PAGE_MASK - -typedef struct {unsigned long pgprot; }pgprot_t ;extern unsigned long phys_base; - -#define pte_val (x) ((x).pte) -#define pmd_val (x) ((x).pmd) -#define pud_val (x) ((x).pud) -#define pgd_val (x) ((x).pgd) -#define pgprot_val (x) ((x).pgprot) - -#define __pte (x) ((pte_t) { (x) } ) -#define __pmd (x) ((pmd_t) { (x) } ) -#define __pud (x) ((pud_t) { (x) } ) -#define __pgd (x) ((pgd_t) { (x) } ) -#define __pgprot (x) ((pgprot_t) { (x) } )#endif /* !__ASSEMBLY__ */
include/asm-x86/pgtable_64.h +3 -3
@@ -79,12 +79,12 @@ static inline void set_pte(pte_t *dst, pstatic inline void set_pmd (pmd_t *dst,pmd_t val) { -pmd_val (*dst) =pmd_val (val); + *dst = val; }static inline void set_pud (pud_t *dst,pud_t val) { -pud_val (*dst) =pud_val (val); + *dst = val; }static inline void pud_clear (pud_t *pud)
@@ -94,7 +94,7 @@ static inline void pud_clear (pud_t *pudstatic inline void set_pgd (pgd_t *dst,pgd_t val) { -pgd_val (*dst) =pgd_val (val); + *dst = val; }static inline void pgd_clear (pgd_t * pgd)
PATCH 1/1 x86/efi: fix improper use of lvalue
In reply to Jeremy Fitzhardinge# HG changeset patch
# User Jeremy Fitzhardinge <[email protected]> # Date 1199391030 28800
# Node ID 5d35c92fdf0e2c52edbb6fc4ccd06c7f65f25009 # Parent 22f6a5902285b58bfc1fbbd9e183498c9017bd78 x86/efi: fix improper use of lvalue
pgd_val is no longer valid as an lvalue, so don't try to assign to it.
--- arch/x86/kernel/efi_64.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/efi_64.c +1 -1
@@ -84,7 +84,7 @@ void __init efi_call_phys_prelog(void)local_irq_save (efi_flags);early_runtime_code_mapping_set_exec (1 ); vaddress = (unsigned long )__va (0x0UL ); -pgd_val (save_pgd) =pgd_val (*pgd_offset_k (0x0UL )); + save_pgd = *pgd_offset_k (0x0UL );set_pgd (pgd_offset_k (0x0UL ), *pgd_offset_k (vaddress));__flush_tlb_all (); }
PATCH 1/1 x86: page.h: move remaining bits and pieces
In reply to Jeremy Fitzhardinge# HG changeset patch
# User Jeremy Fitzhardinge <[email protected]> # Date 1199319657 28800
# Node ID bba9287641ff90e836d090d80b5c0a846aab7162 # Parent d617b72a0cc9d14bde2087d065c36d4ed3265761
x86: page.h: move remaining bits and pieces
Move the remaining odds and ends into page.h.
--- include/asm-x86/page.h | 23 +++++++++++++++++++++++ include/asm-x86/page_32.h | 17 ----------------- include/asm-x86/page_64.h | 13 ------------- 3 files changed, 23 insertions(+), 30 deletions(-)
include/asm-x86/page.h +23 -0
@@ -80,6 +80,10 @@ void clear_page(void *page);void clear_page (void *page);void copy_page (void *to,void *from); +extern unsigned long end_pfn; +extern unsigned long end_pfn_map; +extern unsigned long phys_base; +extern unsigned long __phys_addr (unsigned long );#define __phys_reloc_hide (x) (x)
@@ -97,6 +101,8 @@ typedef struct { pteval_t pte; } pte_t;#define native_pte_val (x) ((x).pte)#define native_make_pte (x) ((pte_t) { (x) } ) + +#define vmemmap ((struct page *)VMEMMAP_START)#endif /* !__ASSEMBLY__ */
@@ -183,6 +189,19 @@ static inline pte_t native_make_pte(unsi#ifdef CONFIG_FLATMEM #define pfn_valid (pfn) ((pfn) < max_mapnr)#endif /* CONFIG_FLATMEM */ + +extern int nx_enabled; + +/* +* This much address space is reserved for vmalloc() and iomap() +* as well as fixmap mappings. +*/ +extern unsigned int __VMALLOC_RESERVE; +extern int sysctl_legacy_va_layout; +extern int page_is_ram (unsigned long pagenr); + +#define VMALLOC_RESERVE ((unsigned long)__VMALLOC_RESERVE) +#define MAXMEM (-__PAGE_OFFSET-__VMALLOC_RESERVE)#ifdef CONFIG_X86_USE_3DNOW #include <asm/mmx.h>
@@ -325,6 +344,10 @@ static inline pmdval_t native_pmd_val(pm#endif /* __ASSEMBLY__ */ +#include <asm-generic/memory_model.h> +#include <asm-generic/page.h> + +#define __HAVE_ARCH_GATE_AREA 1#ifdef CONFIG_X86_32 # include "page_32.h"
include/asm-x86/page_32.h +0 -17
@@ -7,7 +7,6 @@/* * These are used to make use of C type-checking.. */ -extern int nx_enabled;#endif /* !__ASSEMBLY__ */
@@ -15,26 +14,10 @@ extern int nx_enabled;struct vm_area_struct ; -/* -* This much address space is reserved for vmalloc() and iomap() -* as well as fixmap mappings. -*/ -extern unsigned int __VMALLOC_RESERVE; - -extern int sysctl_legacy_va_layout; - -extern int page_is_ram (unsigned long pagenr); -#endif /* __ASSEMBLY__ */ -#define VMALLOC_RESERVE ((unsigned long)__VMALLOC_RESERVE) -#define MAXMEM (-__PAGE_OFFSET-__VMALLOC_RESERVE) -#include <asm-generic/memory_model.h> -#include <asm-generic/page.h> - -#define __HAVE_ARCH_GATE_AREA 1#endif /* __KERNEL__ */ #endif /* _I386_PAGE_H */
include/asm-x86/page_64.h +0 -13
@@ -4,25 +4,12 @@#ifdef __KERNEL__#ifndef __ASSEMBLY__ -extern unsigned long end_pfn; -extern unsigned long end_pfn_map; - - -extern unsigned long phys_base; -#endif /* !__ASSEMBLY__ */ #ifndef __ASSEMBLY__ -#include <asm/bug.h> #endif /* __ASSEMBLY__ */ - -#define __HAVE_ARCH_GATE_AREA 1 -#define vmemmap ((struct page *)VMEMMAP_START) - -#include <asm-generic/memory_model.h> -#include <asm-generic/page.h> #endif /* __KERNEL__ */
PATCH 1/1 x86: page.h: move things back to their own files
In reply to Jeremy Fitzhardinge# HG changeset patch
# User Jeremy Fitzhardinge <[email protected]> # Date 1199321648 28800
# Node ID 22f6a5902285b58bfc1fbbd9e183498c9017bd78 # Parent bba9287641ff90e836d090d80b5c0a846aab7162
x86: page.h: move things back to their own files
Oops, asm/page.h has turned into an #ifdef hellhole. Move 32/64-specific things back to their own headers to make it somewhat comprehensible...
--- include/asm-x86/page.h | 212 +-------------------------------------------- include/asm-x86/page_32.h | 123 +++++++++++++++++++++++--- include/asm-x86/page_64.h | 74 ++++++++++++++- 3 files changed, 187 insertions(+), 222 deletions(-)
include/asm-x86/Kbuild +1 -2
@@ -15,8 +15,7 @@ unifdef-y += mce.h unifdef-y += mce.h unifdef-y += msr.h unifdef-y += mtrr.h -unifdef-y += page_32.h -unifdef-y += page_64.h +unifdef-y += page.h unifdef-y += posix_types_32.h unifdef-y += posix_types_64.h unifdef-y += ptrace.h
include/asm-x86/page.h +6 -206
229 lines not on this page · raw message
include/asm-x86/page_32.h +112 -11
135 lines not on this page · raw message
include/asm-x86/page_64.h +69 -5
85 lines not on this page · raw message
Quoted 6 lines · Jeremy Fitzhardinge
Hi Ingo,
Here's a series which concentrates on unifying and cleaning up
asm-86/page*.h. Each patch in the series restricts itself to doing one thing fairly simply, so it should be fairly low-risk and easy to bisect.
thanks Jeremy, i have applied your patches to x86.git.
Quoted 3 lines
The early version of this patch got rid of asm/page_32|64.h entirely, but I decided the resulting #ifdef hell was too hard to deal with, so I moved purely 32/64-bit specific stuff into their own files.
agreed - and the result certainly looks clean.
Ingo