Re: [PATCH RFC 3/7] x86: clean up asm-x86/page*.h

2007-11-08 Thread Jeremy Fitzhardinge
Glauber de Oliveira Costa wrote:
> Not exactly.
> for the native_ functions,  there's room for code sharing.
> native_pgd_val, and native_pte_val seem to be the same, for at least
> pae and x86_64.
> As for the typedefs, the same thing can be done. Much like you did in
> paravirt.h, just split out between the < 3 and >= 3 levels.

Yeah, I see what you mean.  I'll play with it and see how it turns out.

J
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH RFC 3/7] x86: clean up asm-x86/page*.h

2007-11-08 Thread Glauber de Oliveira Costa
On Nov 8, 2007 6:59 PM, Jeremy Fitzhardinge <[EMAIL PROTECTED]> wrote:
> Glauber de Oliveira Costa wrote:
> > On Nov 7, 2007 11:50 PM, Jeremy Fitzhardinge <[EMAIL PROTECTED]> wrote:
> >
> >> +#define PAGETABLE_LEVELS   3
> >> +
> >> +typedef u64pteval_t;
> >> +typedef u64pmdval_t;
> >> +typedef u64pudval_t;
> >> +typedef u64pgdval_t;
> >> +
> >>
> >
> >
> >> -static inline unsigned long long native_pgd_val(pgd_t pgd)
> >> +static inline pgdval_t native_pgd_val(pgd_t pgd)
> >>  {
> >>
> > Maybe these kind of things, the typedef and native_xxx definitions can
> > go into the common header, after we define the PAGETABLE_LEVELS
> > constant?
> > I think the more goes into common headers, the better.
> >
>
> You mean put them in a common header, but conditionally by #if
> PAGETABLE_LEVELS?  I don't think that would be much of an improvement;
> it would just add more #ifs, which adds lines and conceptual
> complexity.  If you go that way, you may as well put everything in one
> header wrapped in #ifs, but personally I don't think that would help.

Not exactly.
for the native_ functions,  there's room for code sharing.
native_pgd_val, and native_pte_val seem to be the same, for at least
pae and x86_64.
As for the typedefs, the same thing can be done. Much like you did in
paravirt.h, just split out between the < 3 and >= 3 levels.

But if it turns out to be just code movement, and I'm wrong in my
supposition that we can turn three variants of the same code into two,
then I agree
with you, let's keep it this way.


-- 
Glauber de Oliveira Costa.
"Free as in Freedom"
http://glommer.net

"The less confident you are, the more serious you have to act."
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH RFC 3/7] x86: clean up asm-x86/page*.h

2007-11-08 Thread Jeremy Fitzhardinge
Glauber de Oliveira Costa wrote:
> On Nov 7, 2007 11:50 PM, Jeremy Fitzhardinge <[EMAIL PROTECTED]> wrote:
>   
>> +#define PAGETABLE_LEVELS   3
>> +
>> +typedef u64pteval_t;
>> +typedef u64pmdval_t;
>> +typedef u64pudval_t;
>> +typedef u64pgdval_t;
>> +
>> 
>
>   
>> -static inline unsigned long long native_pgd_val(pgd_t pgd)
>> +static inline pgdval_t native_pgd_val(pgd_t pgd)
>>  {
>> 
> Maybe these kind of things, the typedef and native_xxx definitions can
> go into the common header, after we define the PAGETABLE_LEVELS
> constant?
> I think the more goes into common headers, the better.
>   

You mean put them in a common header, but conditionally by #if
PAGETABLE_LEVELS?  I don't think that would be much of an improvement;
it would just add more #ifs, which adds lines and conceptual
complexity.  If you go that way, you may as well put everything in one
header wrapped in #ifs, but personally I don't think that would help.

J
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH RFC 3/7] x86: clean up asm-x86/page*.h

2007-11-08 Thread Glauber de Oliveira Costa
On Nov 7, 2007 11:50 PM, Jeremy Fitzhardinge <[EMAIL PROTECTED]> wrote:
> +#define PAGETABLE_LEVELS   3
> +
> +typedef u64pteval_t;
> +typedef u64pmdval_t;
> +typedef u64pudval_t;
> +typedef u64pgdval_t;
> +

> -static inline unsigned long long native_pgd_val(pgd_t pgd)
> +static inline pgdval_t native_pgd_val(pgd_t pgd)
>  {
Maybe these kind of things, the typedef and native_xxx definitions can
go into the common header, after we define the PAGETABLE_LEVELS
constant?
I think the more goes into common headers, the better.

> -static inline pte_t native_make_pte(unsigned long long val)
> +static inline pte_t native_make_pte(pteval_t val)
>  {
> return (pte_t) { .pte_low = val, .pte_high = (val >> 32) } ;
>  }
Although these make_xxx things can probably be just left here...


-- 
Glauber de Oliveira Costa.
"Free as in Freedom"
http://glommer.net

"The less confident you are, the more serious you have to act."
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH RFC 3/7] x86: clean up asm-x86/page*.h

2007-11-08 Thread Glauber de Oliveira Costa
On Nov 7, 2007 11:50 PM, Jeremy Fitzhardinge [EMAIL PROTECTED] wrote:
 +#define PAGETABLE_LEVELS   3
 +
 +typedef u64pteval_t;
 +typedef u64pmdval_t;
 +typedef u64pudval_t;
 +typedef u64pgdval_t;
 +

 -static inline unsigned long long native_pgd_val(pgd_t pgd)
 +static inline pgdval_t native_pgd_val(pgd_t pgd)
  {
Maybe these kind of things, the typedef and native_xxx definitions can
go into the common header, after we define the PAGETABLE_LEVELS
constant?
I think the more goes into common headers, the better.

 -static inline pte_t native_make_pte(unsigned long long val)
 +static inline pte_t native_make_pte(pteval_t val)
  {
 return (pte_t) { .pte_low = val, .pte_high = (val  32) } ;
  }
Although these make_xxx things can probably be just left here...


-- 
Glauber de Oliveira Costa.
Free as in Freedom
http://glommer.net

The less confident you are, the more serious you have to act.
-
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH RFC 3/7] x86: clean up asm-x86/page*.h

2007-11-08 Thread Jeremy Fitzhardinge
Glauber de Oliveira Costa wrote:
 Not exactly.
 for the native_ functions,  there's room for code sharing.
 native_pgd_val, and native_pte_val seem to be the same, for at least
 pae and x86_64.
 As for the typedefs, the same thing can be done. Much like you did in
 paravirt.h, just split out between the  3 and = 3 levels.

Yeah, I see what you mean.  I'll play with it and see how it turns out.

J
-
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH RFC 3/7] x86: clean up asm-x86/page*.h

2007-11-08 Thread Glauber de Oliveira Costa
On Nov 8, 2007 6:59 PM, Jeremy Fitzhardinge [EMAIL PROTECTED] wrote:
 Glauber de Oliveira Costa wrote:
  On Nov 7, 2007 11:50 PM, Jeremy Fitzhardinge [EMAIL PROTECTED] wrote:
 
  +#define PAGETABLE_LEVELS   3
  +
  +typedef u64pteval_t;
  +typedef u64pmdval_t;
  +typedef u64pudval_t;
  +typedef u64pgdval_t;
  +
 
 
 
  -static inline unsigned long long native_pgd_val(pgd_t pgd)
  +static inline pgdval_t native_pgd_val(pgd_t pgd)
   {
 
  Maybe these kind of things, the typedef and native_xxx definitions can
  go into the common header, after we define the PAGETABLE_LEVELS
  constant?
  I think the more goes into common headers, the better.
 

 You mean put them in a common header, but conditionally by #if
 PAGETABLE_LEVELS?  I don't think that would be much of an improvement;
 it would just add more #ifs, which adds lines and conceptual
 complexity.  If you go that way, you may as well put everything in one
 header wrapped in #ifs, but personally I don't think that would help.

Not exactly.
for the native_ functions,  there's room for code sharing.
native_pgd_val, and native_pte_val seem to be the same, for at least
pae and x86_64.
As for the typedefs, the same thing can be done. Much like you did in
paravirt.h, just split out between the  3 and = 3 levels.

But if it turns out to be just code movement, and I'm wrong in my
supposition that we can turn three variants of the same code into two,
then I agree
with you, let's keep it this way.


-- 
Glauber de Oliveira Costa.
Free as in Freedom
http://glommer.net

The less confident you are, the more serious you have to act.
-
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH RFC 3/7] x86: clean up asm-x86/page*.h

2007-11-08 Thread Jeremy Fitzhardinge
Glauber de Oliveira Costa wrote:
 On Nov 7, 2007 11:50 PM, Jeremy Fitzhardinge [EMAIL PROTECTED] wrote:
   
 +#define PAGETABLE_LEVELS   3
 +
 +typedef u64pteval_t;
 +typedef u64pmdval_t;
 +typedef u64pudval_t;
 +typedef u64pgdval_t;
 +
 

   
 -static inline unsigned long long native_pgd_val(pgd_t pgd)
 +static inline pgdval_t native_pgd_val(pgd_t pgd)
  {
 
 Maybe these kind of things, the typedef and native_xxx definitions can
 go into the common header, after we define the PAGETABLE_LEVELS
 constant?
 I think the more goes into common headers, the better.
   

You mean put them in a common header, but conditionally by #if
PAGETABLE_LEVELS?  I don't think that would be much of an improvement;
it would just add more #ifs, which adds lines and conceptual
complexity.  If you go that way, you may as well put everything in one
header wrapped in #ifs, but personally I don't think that would help.

J
-
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH RFC 3/7] x86: clean up asm-x86/page*.h

2007-11-07 Thread Jeremy Fitzhardinge
Unify common definitions in page*.h.  To simplify other code, I added
typedefs for the value of pte/pmd/pud/pgd values, so they can be used
symbolically elsewhere without needing to have lots of 32/64/PAE
tests.

Also, add PAGETABLE_LEVELS define so that other definitions can test
for it directly rather than using indirect 32/64/PAE tests.

Signed-off-by: Jeremy Fitzhardinge <[EMAIL PROTECTED]>

---
 include/asm-x86/page.h|   49 ++--
 include/asm-x86/page_32.h |   77 +
 include/asm-x86/page_64.h |   37 +++--
 3 files changed, 95 insertions(+), 68 deletions(-)

===
--- a/include/asm-x86/page.h
+++ b/include/asm-x86/page.h
@@ -1,13 +1,42 @@
+#ifndef _ASM_X86_PAGE_H
+#define _ASM_X86_PAGE_H
+
+#include 
+
+/* 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_SIZE-1) & __PHYSICAL_MASK)
+
+#define LARGE_PAGE_MASK (~(LARGE_PAGE_SIZE-1))
+#define LARGE_PAGE_SIZE (_AC(1,UL) << PMD_SHIFT)
+
 #ifdef __KERNEL__
-# ifdef CONFIG_X86_32
-#  include "page_32.h"
-# else
-#  include "page_64.h"
-# endif
+
+#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
+
+#ifndef 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 /* __KERNEL__ */
+#endif /* _ASM_X86_PAGE_H */
===
--- a/include/asm-x86/page_32.h
+++ b/include/asm-x86/page_32.h
@@ -1,16 +1,13 @@
 #ifndef _I386_PAGE_H
 #define _I386_PAGE_H
 
-/* PAGE_SHIFT determines the page size */
-#define PAGE_SHIFT 12
-#define PAGE_SIZE  (1UL << PAGE_SHIFT)
-#define PAGE_MASK  (~(PAGE_SIZE-1))
+#ifndef _ASM_X86_PAGE_H
+#error Include asm/page.h
+#endif
 
-#define LARGE_PAGE_MASK (~(LARGE_PAGE_SIZE-1))
-#define LARGE_PAGE_SIZE (1UL << PMD_SHIFT)
+#ifndef __ASSEMBLY__
 
-#ifdef __KERNEL__
-#ifndef __ASSEMBLY__
+#include 
 
 #ifdef CONFIG_X86_USE_3DNOW
 
@@ -43,71 +40,86 @@
  */
 extern int nx_enabled;
 
+/* macro to avoid #include hell */
+#define native_pud_val(pud)native_pgd_val((pud).pgd)
+
 #ifdef CONFIG_X86_PAE
+#define PAGETABLE_LEVELS   3
+
+typedef u64pteval_t;
+typedef u64pmdval_t;
+typedef u64pudval_t;
+typedef u64pgdval_t;
+
 typedef struct { unsigned long pte_low, pte_high; } pte_t;
-typedef struct { unsigned long long pmd; } pmd_t;
-typedef struct { unsigned long long pgd; } pgd_t;
+typedef struct { pmdval_t pmd; } pmd_t;
+typedef struct { pgdval_t pgd; } pgd_t;
 typedef struct { unsigned long long pgprot; } pgprot_t;
 
-static inline unsigned long long native_pgd_val(pgd_t pgd)
+static inline pgdval_t native_pgd_val(pgd_t pgd)
 {
return pgd.pgd;
 }
 
-static inline unsigned long long native_pmd_val(pmd_t pmd)
+static inline pmdval_t native_pmd_val(pmd_t pmd)
 {
return pmd.pmd;
 }
 
-static inline unsigned long long native_pte_val(pte_t pte)
+static inline pteval_t native_pte_val(pte_t pte)
 {
return pte.pte_low | ((unsigned long long)pte.pte_high << 32);
 }
 
-static inline pgd_t native_make_pgd(unsigned long long val)
+static inline pgd_t native_make_pgd(pgdval_t val)
 {
return (pgd_t) { val };
 }
 
-static inline pmd_t native_make_pmd(unsigned long long val)
+static inline pmd_t native_make_pmd(pmdval_t val)
 {
return (pmd_t) { val };
 }
 
-static inline pte_t native_make_pte(unsigned long long val)
+static inline pte_t native_make_pte(pteval_t val)
 {
return (pte_t) { .pte_low = val, .pte_high = (val >> 32) } ;
 }
 
-#ifndef CONFIG_PARAVIRT
-#define pmd_val(x) native_pmd_val(x)
-#define __pmd(x)   native_make_pmd(x)
-#endif
-
 #define HPAGE_SHIFT21
 #include 
 #else  /* !CONFIG_X86_PAE */
+
+#define PAGETABLE_LEVELS   2
+
+typedef u32pteval_t;
+typedef u32pmdval_t;
+typedef u32pgdval_t;
+
 typedef struct { unsigned long pte_low; } pte_t;
 typedef struct { unsigned long pgd; } pgd_t;
 typedef struct { unsigned long pgprot; } pgprot_t;
 #define boot_pte_t pte_t /* or would you rather have a typedef */
 
-static inline unsigned long native_pgd_val(pgd_t pgd)
+static inline pgdval_t native_pgd_val(pgd_t pgd)
 {
return pgd.pgd;
 }
 
-static inline unsigned long native_pte_val(pte_t pte)
+static inline pteval_t native_pte_val(pte_t pte)
 {
return 

[PATCH RFC 3/7] x86: clean up asm-x86/page*.h

2007-11-07 Thread Jeremy Fitzhardinge
Unify common definitions in page*.h.  To simplify other code, I added
typedefs for the value of pte/pmd/pud/pgd values, so they can be used
symbolically elsewhere without needing to have lots of 32/64/PAE
tests.

Also, add PAGETABLE_LEVELS define so that other definitions can test
for it directly rather than using indirect 32/64/PAE tests.

Signed-off-by: Jeremy Fitzhardinge [EMAIL PROTECTED]

---
 include/asm-x86/page.h|   49 ++--
 include/asm-x86/page_32.h |   77 +
 include/asm-x86/page_64.h |   37 +++--
 3 files changed, 95 insertions(+), 68 deletions(-)

===
--- a/include/asm-x86/page.h
+++ b/include/asm-x86/page.h
@@ -1,13 +1,42 @@
+#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_SIZE-1)  __PHYSICAL_MASK)
+
+#define LARGE_PAGE_MASK (~(LARGE_PAGE_SIZE-1))
+#define LARGE_PAGE_SIZE (_AC(1,UL)  PMD_SHIFT)
+
 #ifdef __KERNEL__
-# ifdef CONFIG_X86_32
-#  include page_32.h
-# else
-#  include page_64.h
-# endif
+
+#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
+
+#ifndef 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 /* __KERNEL__ */
+#endif /* _ASM_X86_PAGE_H */
===
--- a/include/asm-x86/page_32.h
+++ b/include/asm-x86/page_32.h
@@ -1,16 +1,13 @@
 #ifndef _I386_PAGE_H
 #define _I386_PAGE_H
 
-/* PAGE_SHIFT determines the page size */
-#define PAGE_SHIFT 12
-#define PAGE_SIZE  (1UL  PAGE_SHIFT)
-#define PAGE_MASK  (~(PAGE_SIZE-1))
+#ifndef _ASM_X86_PAGE_H
+#error Include asm/page.h
+#endif
 
-#define LARGE_PAGE_MASK (~(LARGE_PAGE_SIZE-1))
-#define LARGE_PAGE_SIZE (1UL  PMD_SHIFT)
+#ifndef __ASSEMBLY__
 
-#ifdef __KERNEL__
-#ifndef __ASSEMBLY__
+#include linux/types.h
 
 #ifdef CONFIG_X86_USE_3DNOW
 
@@ -43,71 +40,86 @@
  */
 extern int nx_enabled;
 
+/* macro to avoid #include hell */
+#define native_pud_val(pud)native_pgd_val((pud).pgd)
+
 #ifdef CONFIG_X86_PAE
+#define PAGETABLE_LEVELS   3
+
+typedef u64pteval_t;
+typedef u64pmdval_t;
+typedef u64pudval_t;
+typedef u64pgdval_t;
+
 typedef struct { unsigned long pte_low, pte_high; } pte_t;
-typedef struct { unsigned long long pmd; } pmd_t;
-typedef struct { unsigned long long pgd; } pgd_t;
+typedef struct { pmdval_t pmd; } pmd_t;
+typedef struct { pgdval_t pgd; } pgd_t;
 typedef struct { unsigned long long pgprot; } pgprot_t;
 
-static inline unsigned long long native_pgd_val(pgd_t pgd)
+static inline pgdval_t native_pgd_val(pgd_t pgd)
 {
return pgd.pgd;
 }
 
-static inline unsigned long long native_pmd_val(pmd_t pmd)
+static inline pmdval_t native_pmd_val(pmd_t pmd)
 {
return pmd.pmd;
 }
 
-static inline unsigned long long native_pte_val(pte_t pte)
+static inline pteval_t native_pte_val(pte_t pte)
 {
return pte.pte_low | ((unsigned long long)pte.pte_high  32);
 }
 
-static inline pgd_t native_make_pgd(unsigned long long val)
+static inline pgd_t native_make_pgd(pgdval_t val)
 {
return (pgd_t) { val };
 }
 
-static inline pmd_t native_make_pmd(unsigned long long val)
+static inline pmd_t native_make_pmd(pmdval_t val)
 {
return (pmd_t) { val };
 }
 
-static inline pte_t native_make_pte(unsigned long long val)
+static inline pte_t native_make_pte(pteval_t val)
 {
return (pte_t) { .pte_low = val, .pte_high = (val  32) } ;
 }
 
-#ifndef CONFIG_PARAVIRT
-#define pmd_val(x) native_pmd_val(x)
-#define __pmd(x)   native_make_pmd(x)
-#endif
-
 #define HPAGE_SHIFT21
 #include asm-generic/pgtable-nopud.h
 #else  /* !CONFIG_X86_PAE */
+
+#define PAGETABLE_LEVELS   2
+
+typedef u32pteval_t;
+typedef u32pmdval_t;
+typedef u32pgdval_t;
+
 typedef struct { unsigned long pte_low; } pte_t;
 typedef struct { unsigned long pgd; } pgd_t;
 typedef struct { unsigned long pgprot; } pgprot_t;
 #define boot_pte_t pte_t /* or would you rather have a typedef */
 
-static inline unsigned long native_pgd_val(pgd_t pgd)
+static inline pgdval_t native_pgd_val(pgd_t pgd)
 {
return pgd.pgd;
 }
 
-static inline unsigned long native_pte_val(pte_t pte)
+static inline pteval_t native_pte_val(pte_t pte)
 {