diff options
| -rw-r--r-- | arch/x86/mm/pat.c | 39 | ||||
| -rw-r--r-- | drivers/char/mem.c | 41 | ||||
| -rw-r--r-- | include/asm-x86/pgtable.h | 9 |
3 files changed, 59 insertions, 30 deletions
diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c index 72c0f6097402..64cc0c18233e 100644 --- a/arch/x86/mm/pat.c +++ b/arch/x86/mm/pat.c | |||
| @@ -419,3 +419,42 @@ int free_memtype(u64 start, u64 end) | |||
| 419 | return err; | 419 | return err; |
| 420 | } | 420 | } |
| 421 | 421 | ||
| 422 | |||
| 423 | /* /dev/mem interface. Use the previous mapping */ | ||
| 424 | pgprot_t phys_mem_access_prot(struct file *file, unsigned long pfn, | ||
| 425 | unsigned long size, pgprot_t vma_prot) | ||
| 426 | { | ||
| 427 | return vma_prot; | ||
| 428 | } | ||
| 429 | |||
| 430 | int phys_mem_access_prot_allowed(struct file *file, unsigned long pfn, | ||
| 431 | unsigned long size, pgprot_t *vma_prot) | ||
| 432 | { | ||
| 433 | |||
| 434 | if (file->f_flags & O_SYNC) { | ||
| 435 | *vma_prot = pgprot_noncached(*vma_prot); | ||
| 436 | return 1; | ||
| 437 | } | ||
| 438 | |||
| 439 | #ifdef CONFIG_X86_32 | ||
| 440 | /* | ||
| 441 | * On the PPro and successors, the MTRRs are used to set | ||
| 442 | * memory types for physical addresses outside main memory, | ||
| 443 | * so blindly setting UC or PWT on those pages is wrong. | ||
| 444 | * For Pentiums and earlier, the surround logic should disable | ||
| 445 | * caching for the high addresses through the KEN pin, but | ||
| 446 | * we maintain the tradition of paranoia in this code. | ||
| 447 | */ | ||
| 448 | if (!pat_wc_enabled && | ||
| 449 | ! ( test_bit(X86_FEATURE_MTRR, boot_cpu_data.x86_capability) || | ||
| 450 | test_bit(X86_FEATURE_K6_MTRR, boot_cpu_data.x86_capability) || | ||
| 451 | test_bit(X86_FEATURE_CYRIX_ARR, boot_cpu_data.x86_capability) || | ||
| 452 | test_bit(X86_FEATURE_CENTAUR_MCR, boot_cpu_data.x86_capability)) && | ||
| 453 | (pfn << PAGE_SHIFT) >= __pa(high_memory)) { | ||
| 454 | *vma_prot = pgprot_noncached(*vma_prot); | ||
| 455 | return 1; | ||
| 456 | } | ||
| 457 | #endif | ||
| 458 | |||
| 459 | return 1; | ||
| 460 | } | ||
diff --git a/drivers/char/mem.c b/drivers/char/mem.c index 83495885ada0..56b2fb4fbc93 100644 --- a/drivers/char/mem.c +++ b/drivers/char/mem.c | |||
| @@ -41,36 +41,7 @@ | |||
| 41 | */ | 41 | */ |
| 42 | static inline int uncached_access(struct file *file, unsigned long addr) | 42 | static inline int uncached_access(struct file *file, unsigned long addr) |
| 43 | { | 43 | { |
| 44 | #if defined(__i386__) && !defined(__arch_um__) | 44 | #if defined(CONFIG_IA64) |
| 45 | /* | ||
| 46 | * On the PPro and successors, the MTRRs are used to set | ||
| 47 | * memory types for physical addresses outside main memory, | ||
| 48 | * so blindly setting PCD or PWT on those pages is wrong. | ||
| 49 | * For Pentiums and earlier, the surround logic should disable | ||
| 50 | * caching for the high addresses through the KEN pin, but | ||
| 51 | * we maintain the tradition of paranoia in this code. | ||
| 52 | */ | ||
| 53 | if (file->f_flags & O_SYNC) | ||
| 54 | return 1; | ||
| 55 | return !( test_bit(X86_FEATURE_MTRR, boot_cpu_data.x86_capability) || | ||
| 56 | test_bit(X86_FEATURE_K6_MTRR, boot_cpu_data.x86_capability) || | ||
| 57 | test_bit(X86_FEATURE_CYRIX_ARR, boot_cpu_data.x86_capability) || | ||
| 58 | test_bit(X86_FEATURE_CENTAUR_MCR, boot_cpu_data.x86_capability) ) | ||
| 59 | && addr >= __pa(high_memory); | ||
| 60 | #elif defined(__x86_64__) && !defined(__arch_um__) | ||
| 61 | /* | ||
| 62 | * This is broken because it can generate memory type aliases, | ||
| 63 | * which can cause cache corruptions | ||
| 64 | * But it is only available for root and we have to be bug-to-bug | ||
| 65 | * compatible with i386. | ||
| 66 | */ | ||
| 67 | if (file->f_flags & O_SYNC) | ||
| 68 | return 1; | ||
| 69 | /* same behaviour as i386. PAT always set to cached and MTRRs control the | ||
| 70 | caching behaviour. | ||
| 71 | Hopefully a full PAT implementation will fix that soon. */ | ||
| 72 | return 0; | ||
| 73 | #elif defined(CONFIG_IA64) | ||
| 74 | /* | 45 | /* |
| 75 | * On ia64, we ignore O_SYNC because we cannot tolerate memory attribute aliases. | 46 | * On ia64, we ignore O_SYNC because we cannot tolerate memory attribute aliases. |
| 76 | */ | 47 | */ |
| @@ -283,6 +254,12 @@ static ssize_t write_mem(struct file * file, const char __user * buf, | |||
| 283 | return written; | 254 | return written; |
| 284 | } | 255 | } |
| 285 | 256 | ||
| 257 | int __attribute__((weak)) phys_mem_access_prot_allowed(struct file *file, | ||
| 258 | unsigned long pfn, unsigned long size, pgprot_t *vma_prot) | ||
| 259 | { | ||
| 260 | return 1; | ||
| 261 | } | ||
| 262 | |||
| 286 | #ifndef __HAVE_PHYS_MEM_ACCESS_PROT | 263 | #ifndef __HAVE_PHYS_MEM_ACCESS_PROT |
| 287 | static pgprot_t phys_mem_access_prot(struct file *file, unsigned long pfn, | 264 | static pgprot_t phys_mem_access_prot(struct file *file, unsigned long pfn, |
| 288 | unsigned long size, pgprot_t vma_prot) | 265 | unsigned long size, pgprot_t vma_prot) |
| @@ -336,6 +313,10 @@ static int mmap_mem(struct file * file, struct vm_area_struct * vma) | |||
| 336 | if (!range_is_allowed(vma->vm_pgoff, size)) | 313 | if (!range_is_allowed(vma->vm_pgoff, size)) |
| 337 | return -EPERM; | 314 | return -EPERM; |
| 338 | 315 | ||
| 316 | if (!phys_mem_access_prot_allowed(file, vma->vm_pgoff, size, | ||
| 317 | &vma->vm_page_prot)) | ||
| 318 | return -EINVAL; | ||
| 319 | |||
| 339 | vma->vm_page_prot = phys_mem_access_prot(file, vma->vm_pgoff, | 320 | vma->vm_page_prot = phys_mem_access_prot(file, vma->vm_pgoff, |
| 340 | size, | 321 | size, |
| 341 | vma->vm_page_prot); | 322 | vma->vm_page_prot); |
diff --git a/include/asm-x86/pgtable.h b/include/asm-x86/pgtable.h index f1d9f4a03f6f..1902f0aed6c1 100644 --- a/include/asm-x86/pgtable.h +++ b/include/asm-x86/pgtable.h | |||
| @@ -289,6 +289,15 @@ static inline pte_t pte_modify(pte_t pte, pgprot_t newprot) | |||
| 289 | 289 | ||
| 290 | #define canon_pgprot(p) __pgprot(pgprot_val(p) & __supported_pte_mask) | 290 | #define canon_pgprot(p) __pgprot(pgprot_val(p) & __supported_pte_mask) |
| 291 | 291 | ||
| 292 | #ifndef __ASSEMBLY__ | ||
| 293 | #define __HAVE_PHYS_MEM_ACCESS_PROT | ||
| 294 | struct file; | ||
| 295 | pgprot_t phys_mem_access_prot(struct file *file, unsigned long pfn, | ||
| 296 | unsigned long size, pgprot_t vma_prot); | ||
| 297 | int phys_mem_access_prot_allowed(struct file *file, unsigned long pfn, | ||
| 298 | unsigned long size, pgprot_t *vma_prot); | ||
| 299 | #endif | ||
| 300 | |||
| 292 | #ifdef CONFIG_PARAVIRT | 301 | #ifdef CONFIG_PARAVIRT |
| 293 | #include <asm/paravirt.h> | 302 | #include <asm/paravirt.h> |
| 294 | #else /* !CONFIG_PARAVIRT */ | 303 | #else /* !CONFIG_PARAVIRT */ |
