From: Dave Kleikamp <hidden> Date: 2008-06-10 22:00:56
Allow an application to enable Strong Access Ordering on specific pages of
memory on Power 7 hardware. Currently, power has a weaker memory model than
x86. Implementing a stronger memory model allows an emulator to more
efficiently translate x86 code into power code, resulting in faster code
execution.
On Power 7 hardware, storing 0b1110 in the WIMG bits of the hpte enables
strong access ordering mode for the memory page. This patchset allows a
user to specify which pages are thus enabled by passing a new protection
bit through mmap() and mprotect(). I have tentatively defined this bit,
PROT_SAO, as 0x10.
In order to accomplish this, I had to modify the architecture-independent
code to allow the architecture to deal with additional protection bits.
Patches built against 2.6.26-rc5.
Any and all suggestions, complaints, flames, insults, etc. are appreciated.
Thanks,
Shaggy
From: Dave Kleikamp <hidden> Date: 2008-06-10 22:01:02
powerpc: hash_huge_page() should get the WIMG bits from the lpte
Signed-off-by: Dave Kleikamp <redacted>
---
arch/powerpc/mm/hugetlbpage.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff -Nurp linux000/arch/powerpc/mm/hugetlbpage.c linux001/arch/powerpc/mm/hugetlbpage.c
@@ -502,9 +502,8 @@ repeat:new_pte=(new_pte&~_PAGE_HPTEFLAGS)|_PAGE_HASHPTE;/* Add in WIMG bits */-/* XXX We should store these in the pte */-/* --BenH: I think they are ... */-rflags|=_PAGE_COHERENT;+rflags|=(new_pte&(_PAGE_WRITETHRU|_PAGE_NO_CACHE|+_PAGE_COHERENT|_PAGE_GUARDED));/* Insert into the hash table, primary slot */slot=ppc_md.hpte_insert(hpte_group,va,pa,rflags,0,
From: Dave Kleikamp <hidden> Date: 2008-06-10 22:01:13
powerpc: Define flags for Strong Access Ordering
This patch defines:
- PROT_SAO, which is passed into mmap() and mprotect() in the prot field
- VM_SAO in vma->vm_flags, and
- _PAGE_SAO, the combination of WIMG bits in the pte that enables strong
access ordering for the page.
NOTE: There doesn't seem to be a precedent for architecture-dependent vm_flags.
It may be better to define VM_SAO somewhere in include/asm-powerpc/. Since
vm_flags is a long, defining it in the high-order word would help prevent a
collision with any newly added values in architecture-independent code.
Signed-off-by: Dave Kleikamp <redacted>
---
include/asm-powerpc/mman.h | 2 ++
include/asm-powerpc/pgtable-ppc64.h | 3 +++
include/linux/mm.h | 1 +
3 files changed, 6 insertions(+)
diff -Nurp linux002/include/asm-powerpc/mman.h linux003/include/asm-powerpc/mman.h
From: Dave Kleikamp <hidden> Date: 2008-06-10 22:01:24
powerpc: Add Strong Access Ordering
Things I don't like about this patch:
1. All the includes I added to asm-powerpc/mman.h
2. It doesn't look like mmap() used to validate prot. Now instead of
ignoring invalid values, it will return -EINVAL. Could this be a problem?
3. Are these new functions in any hot paths that the extra instructions will
add any significant overhead?
Signed-off-by: Dave Kleikamp <redacted>
---
arch/powerpc/kernel/syscalls.c | 3 +++
include/asm-powerpc/mman.h | 26 ++++++++++++++++++++++++++
2 files changed, 29 insertions(+)
diff -Nurp linux004/arch/powerpc/kernel/syscalls.c linux005/arch/powerpc/kernel/syscalls.c
From: Dave Kleikamp <hidden> Date: 2008-06-10 22:01:26
powerpc: Define CPU_FTR_SAO
This is just a placeholder to make the patchset compilable.
Signed-off-by: Dave Kleikamp <redacted>
---
include/asm-powerpc/cputable.h | 1 +
1 file changed, 1 insertion(+)
diff -Nurp linux003/include/asm-powerpc/cputable.h linux004/include/asm-powerpc/cputable.h
From: Dave Kleikamp <hidden> Date: 2008-06-10 22:01:40
powerpc: Don't clear _PAGE_COHERENT when _PAGE_SAO is set
This is a placeholder. Benh tells me that he will come up with a better fix.
Signed-off-by: Dave Kleikamp <redacted>
---
arch/powerpc/platforms/pseries/lpar.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff -Nurp linux005/arch/powerpc/platforms/pseries/lpar.c linux006/arch/powerpc/platforms/pseries/lpar.c
From: Andrew Morton <akpm@linux-foundation.org> Date: 2008-06-10 22:14:23
On Tue, 10 Jun 2008 18:01:07 -0400
Dave Kleikamp [off-list ref] wrote:
mm: Allow architectures to define additional protection bits
This patch allows architectures to define functions to deal with
additional protections bits for mmap() and mprotect().
arch_calc_vm_prot_bits() maps additonal protection bits to vm_flags
arch_vm_get_page_prot() maps additional vm_flags to the vma's vm_page_prot
arch_validate_prot() checks for valid values of the protection bits
Note: vm_get_page_prot() is now pretty ugly. Suggestions?
It didn't get any better, no ;)
I wonder if we can do the ORing after doing the protection_map[]
lookup. I guess that's illogical even if it happens to work.
argh, another HAVE_ARCH_foo.
A good (but verbose) way of doing this is to nuke the ifdefs and just
go and define these three things for each architecture. That can be
done via copy-n-paste into include/asm-*/mman.h or #include
<asm-generic/arch-mman.h>(?) within each asm/mman.h.
Another way would be
#ifndef arch_calc_vm_prot_bits
#define arch_calc_vm_prot_bits(prot) ...
quoted hunk
+/*
* Optimisation macro. It is equivalent to:
* (x & bit1) ? bit2 : 0
* but this version is faster.
From: Sergei Shtylyov <hidden> Date: 2008-06-10 22:26:14
Hello.
Dave Kleikamp wrote:
quoted hunk
powerpc: Don't clear _PAGE_COHERENT when _PAGE_SAO is set
This is a placeholder. Benh tells me that he will come up with a better fix.
Signed-off-by: Dave Kleikamp <redacted>
---
arch/powerpc/platforms/pseries/lpar.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff -Nurp linux005/arch/powerpc/platforms/pseries/lpar.c linux006/arch/powerpc/platforms/pseries/lpar.c
From: Dave Kleikamp <hidden> Date: 2008-06-11 03:08:30
On Wed, 2008-06-11 at 02:26 +0400, Sergei Shtylyov wrote:
Hello.
Dave Kleikamp wrote:
quoted
powerpc: Don't clear _PAGE_COHERENT when _PAGE_SAO is set
This is a placeholder. Benh tells me that he will come up with a better fix.
Signed-off-by: Dave Kleikamp <redacted>
---
arch/powerpc/platforms/pseries/lpar.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff -Nurp linux005/arch/powerpc/platforms/pseries/lpar.c linux006/arch/powerpc/platforms/pseries/lpar.c
From: Dave Kleikamp <hidden> Date: 2008-06-11 15:47:17
On Tue, 2008-06-10 at 15:14 -0700, Andrew Morton wrote:
On Tue, 10 Jun 2008 18:01:07 -0400
Dave Kleikamp [off-list ref] wrote:
quoted
mm: Allow architectures to define additional protection bits
This patch allows architectures to define functions to deal with
additional protections bits for mmap() and mprotect().
arch_calc_vm_prot_bits() maps additonal protection bits to vm_flags
arch_vm_get_page_prot() maps additional vm_flags to the vma's vm_page_prot
arch_validate_prot() checks for valid values of the protection bits
Note: vm_get_page_prot() is now pretty ugly. Suggestions?
It didn't get any better, no ;)
I wonder if we can do the ORing after doing the protection_map[]
lookup. I guess that's illogical even if it happens to work.
I guess we can live with it. Just holding out hope that someone might
see a nicer way to do it.
Sorry. I didn't realize HAVE_ARCH_foo was so evil.
A good (but verbose) way of doing this is to nuke the ifdefs and just
go and define these three things for each architecture. That can be
done via copy-n-paste into include/asm-*/mman.h or #include
<asm-generic/arch-mman.h>(?) within each asm/mman.h.
Another way would be
#ifndef arch_calc_vm_prot_bits
#define arch_calc_vm_prot_bits(prot) ...
I think I prefer this method. I'll get rid of HAVE_ARCH_PROT_BITS.
Thanks,
Shaggy
--
David Kleikamp
IBM Linux Technology Center