From 0a0452b7a1aa19bdd1fc9c0bacc5d5a99c08d067 Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Tue, 23 Aug 2011 07:40:20 -0700 Subject: [PATCH] prepare SVM subsystem to support also other consitency modells --- arch/x86/include/asm/page.h | 7 +++++-- arch/x86/include/asm/svm.h | 5 ++++- arch/x86/mm/page.c | 10 +++++----- arch/x86/mm/svm.c | 4 ++-- include/metalsvm/stdlib.h | 2 +- kernel/tests.c | 5 +++-- 6 files changed, 20 insertions(+), 13 deletions(-) diff --git a/arch/x86/include/asm/page.h b/arch/x86/include/asm/page.h index 5a07a76d..5d35ac53 100644 --- a/arch/x86/include/asm/page.h +++ b/arch/x86/include/asm/page.h @@ -41,7 +41,8 @@ #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */ #define _PAGE_BIT_PAT 7 /* on 4KB pages */ #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */ -#define _PAGE_BIT_SVM 9 /* mark a virtual address range as used by the SVM system */ +#define _PAGE_BIT_SVM_STRONG 9 /* mark a virtual address range as used by the SVM system */ +#define _PAGE_BIT_SVM_LAZYRELEASE 10 /* mark a virtual address range as used by the SVM system */ /// Page is present #define PG_PRESENT (1 << _PAGE_BIT_PRESENT) @@ -66,7 +67,9 @@ /// Pattern flag #define PG_PAT (1 << _PAGE_BIT_PAT) /// This virtual address range is used by SVM system as marked -#define PG_SVM (1 << _PAGE_BIT_SVM) +#define PG_SVM_STRONG (1 << _PAGE_BIT_SVM_STRONG) +/// This virtual address range is used by SVM system as marked +#define PG_SVM_LAZYRELEASE (1 << _PAGE_BIT_SVM_LAZYRELEASE) /// This is a whole set of flags (PRESENT,RW,ACCESSED,DIRTY) for kernelspace tables #define KERN_TABLE (PG_PRESENT|PG_RW|PG_ACCESSED|PG_DIRTY) diff --git a/arch/x86/include/asm/svm.h b/arch/x86/include/asm/svm.h index cd2737ea..301fda74 100644 --- a/arch/x86/include/asm/svm.h +++ b/arch/x86/include/asm/svm.h @@ -31,6 +31,9 @@ extern "C" { #ifdef CONFIG_ROCKCREEK +#define SVM_STRONG (1 << 0) +#define SVM_LAZYRELEASE (1 << 1) + /** @brief Init routine of the SVM subsystem * * @return @@ -46,7 +49,7 @@ int svm_init(void); * * @return Pointer to the new memory range */ -void* svmmalloc(size_t size); +void* svmmalloc(size_t sizei, uint32_t flags); /** @brief Frees memory, which is managed by the SVM subsystem * diff --git a/arch/x86/mm/page.c b/arch/x86/mm/page.c index 7321a413..d2c4d4bd 100644 --- a/arch/x86/mm/page.c +++ b/arch/x86/mm/page.c @@ -355,9 +355,9 @@ size_t map_region(size_t viraddr, size_t phyaddr, uint32_t npages, uint32_t flag if (flags & MAP_MPE) pgt->entries[index] |= PG_MPE; #endif - if (flags & MAP_SVM) + if (flags & MAP_SVM_STRONG) #ifndef SVM_WB - pgt->entries[index] |= PG_SVM|PG_PWT; + pgt->entries[index] |= PG_SVM_STRONG|PG_PWT; #else pgt->entries[index] |= PG_SVM; #endif @@ -404,9 +404,9 @@ int change_page_permissions(size_t start, size_t end, uint32_t flags) phyaddr = pgt->entries[index2] & 0xFFFFF000; newflags = pgt->entries[index2] & 0xFFF; // get old flags - if ((newflags & PG_SVM) && !(newflags & PG_PRESENT) && (flags & (VMA_READ|VMA_WRITE) && !(flags & VMA_NOACCESS))) + if ((newflags & PG_SVM_STRONG) && !(newflags & PG_PRESENT) && (flags & (VMA_READ|VMA_WRITE) && !(flags & VMA_NOACCESS))) newflags |= PG_PRESENT; - else if ((newflags & PG_SVM) && (newflags & PG_PRESENT) && (flags & VMA_NOACCESS)) + else if ((newflags & PG_SVM_STRONG) && (newflags & PG_PRESENT) && (flags & VMA_NOACCESS)) newflags &= ~PG_PRESENT; // update flags @@ -636,7 +636,7 @@ static void pagefault_handler(struct state *s) pgt = (page_table_t*) ((KERNEL_SPACE - 1024*PAGE_SIZE + index1*PAGE_SIZE) & 0xFFFFF000); if (!pgt || !(pgt->entries[index2])) goto default_handler; - if (pgt->entries[index2] & PG_SVM) + if (pgt->entries[index2] & PG_SVM_STRONG) if (!svm_access_request(viraddr)) return; diff --git a/arch/x86/mm/svm.c b/arch/x86/mm/svm.c index 10a55d49..fbf26d2a 100644 --- a/arch/x86/mm/svm.c +++ b/arch/x86/mm/svm.c @@ -137,11 +137,11 @@ int svm_access_request(size_t addr) return change_page_permissions(addr, addr+PAGE_SIZE, VMA_READ|VMA_WRITE|VMA_CACHEABLE); } -void* svmmalloc(size_t size) +void* svmmalloc(size_t size, uint32_t consitency) { size_t phyaddr, viraddr, i; uint32_t flags; - uint32_t map_flags = MAP_KERNEL_SPACE|MAP_MPE|MAP_SVM; + uint32_t map_flags = MAP_KERNEL_SPACE|MAP_MPE|MAP_SVM_STRONG; // currently, we allocate memory in page size granulation size = (size + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1); diff --git a/include/metalsvm/stdlib.h b/include/metalsvm/stdlib.h index 3849745e..1c8eec47 100644 --- a/include/metalsvm/stdlib.h +++ b/include/metalsvm/stdlib.h @@ -48,7 +48,7 @@ extern "C" { #ifdef CONFIG_ROCKCREEK #define MAP_MPE (1 << 8) #endif -#define MAP_SVM (1 << 9) +#define MAP_SVM_STRONG (1 << 9) #define MAP_NO_ACCESS (1 << 10) void NORETURN abort(void); diff --git a/kernel/tests.c b/kernel/tests.c index 7ad3c4f1..6cff1758 100644 --- a/kernel/tests.c +++ b/kernel/tests.c @@ -115,7 +115,8 @@ int mail_ping(void* arg) { return 0; } -#define N 1024 +//#define N 1024 +#define N 513 volatile static int* A[N]; volatile static int* B[N]; @@ -172,7 +173,7 @@ static int svm_test(void *arg) #endif // allocate and initialize SVM region - A[0] = (int*) svmmalloc(3*N*N*sizeof(int)); + A[0] = (int*) svmmalloc(3*N*N*sizeof(int), SVM_STRONG); if (!my_ue) memset((void*) A[0], 0x00, 3*N*N*sizeof(int));