aboutsummaryrefslogtreecommitdiffstats
path: root/arch/x86/mm/pat.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/x86/mm/pat.c')
-rw-r--r--arch/x86/mm/pat.c88
1 files changed, 59 insertions, 29 deletions
diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
index 85cbd3cd3723..7b61036427df 100644
--- a/arch/x86/mm/pat.c
+++ b/arch/x86/mm/pat.c
@@ -333,11 +333,23 @@ int reserve_memtype(u64 start, u64 end, unsigned long req_type,
333 req_type & _PAGE_CACHE_MASK); 333 req_type & _PAGE_CACHE_MASK);
334 } 334 }
335 335
336 is_range_ram = pagerange_is_ram(start, end); 336 if (new_type)
337 if (is_range_ram == 1) 337 *new_type = actual_type;
338 return reserve_ram_pages_type(start, end, req_type, new_type); 338
339 else if (is_range_ram < 0) 339 /*
340 return -EINVAL; 340 * For legacy reasons, some parts of the physical address range in the
341 * legacy 1MB region is treated as non-RAM (even when listed as RAM in
342 * the e820 tables). So we will track the memory attributes of this
343 * legacy 1MB region using the linear memtype_list always.
344 */
345 if (end >= ISA_END_ADDRESS) {
346 is_range_ram = pagerange_is_ram(start, end);
347 if (is_range_ram == 1)
348 return reserve_ram_pages_type(start, end, req_type,
349 new_type);
350 else if (is_range_ram < 0)
351 return -EINVAL;
352 }
341 353
342 new = kmalloc(sizeof(struct memtype), GFP_KERNEL); 354 new = kmalloc(sizeof(struct memtype), GFP_KERNEL);
343 if (!new) 355 if (!new)
@@ -347,9 +359,6 @@ int reserve_memtype(u64 start, u64 end, unsigned long req_type,
347 new->end = end; 359 new->end = end;
348 new->type = actual_type; 360 new->type = actual_type;
349 361
350 if (new_type)
351 *new_type = actual_type;
352
353 spin_lock(&memtype_lock); 362 spin_lock(&memtype_lock);
354 363
355 if (cached_entry && start >= cached_start) 364 if (cached_entry && start >= cached_start)
@@ -437,11 +446,19 @@ int free_memtype(u64 start, u64 end)
437 if (is_ISA_range(start, end - 1)) 446 if (is_ISA_range(start, end - 1))
438 return 0; 447 return 0;
439 448
440 is_range_ram = pagerange_is_ram(start, end); 449 /*
441 if (is_range_ram == 1) 450 * For legacy reasons, some parts of the physical address range in the
442 return free_ram_pages_type(start, end); 451 * legacy 1MB region is treated as non-RAM (even when listed as RAM in
443 else if (is_range_ram < 0) 452 * the e820 tables). So we will track the memory attributes of this
444 return -EINVAL; 453 * legacy 1MB region using the linear memtype_list always.
454 */
455 if (end >= ISA_END_ADDRESS) {
456 is_range_ram = pagerange_is_ram(start, end);
457 if (is_range_ram == 1)
458 return free_ram_pages_type(start, end);
459 else if (is_range_ram < 0)
460 return -EINVAL;
461 }
445 462
446 spin_lock(&memtype_lock); 463 spin_lock(&memtype_lock);
447 list_for_each_entry(entry, &memtype_list, nd) { 464 list_for_each_entry(entry, &memtype_list, nd) {
@@ -601,12 +618,13 @@ void unmap_devmem(unsigned long pfn, unsigned long size, pgprot_t vma_prot)
601 * Reserved non RAM regions only and after successful reserve_memtype, 618 * Reserved non RAM regions only and after successful reserve_memtype,
602 * this func also keeps identity mapping (if any) in sync with this new prot. 619 * this func also keeps identity mapping (if any) in sync with this new prot.
603 */ 620 */
604static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t vma_prot) 621static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
622 int strict_prot)
605{ 623{
606 int is_ram = 0; 624 int is_ram = 0;
607 int id_sz, ret; 625 int id_sz, ret;
608 unsigned long flags; 626 unsigned long flags;
609 unsigned long want_flags = (pgprot_val(vma_prot) & _PAGE_CACHE_MASK); 627 unsigned long want_flags = (pgprot_val(*vma_prot) & _PAGE_CACHE_MASK);
610 628
611 is_ram = pagerange_is_ram(paddr, paddr + size); 629 is_ram = pagerange_is_ram(paddr, paddr + size);
612 630
@@ -625,15 +643,24 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t vma_prot)
625 return ret; 643 return ret;
626 644
627 if (flags != want_flags) { 645 if (flags != want_flags) {
628 free_memtype(paddr, paddr + size); 646 if (strict_prot || !is_new_memtype_allowed(want_flags, flags)) {
629 printk(KERN_ERR 647 free_memtype(paddr, paddr + size);
630 "%s:%d map pfn expected mapping type %s for %Lx-%Lx, got %s\n", 648 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
631 current->comm, current->pid, 649 " for %Lx-%Lx, got %s\n",
632 cattr_name(want_flags), 650 current->comm, current->pid,
633 (unsigned long long)paddr, 651 cattr_name(want_flags),
634 (unsigned long long)(paddr + size), 652 (unsigned long long)paddr,
635 cattr_name(flags)); 653 (unsigned long long)(paddr + size),
636 return -EINVAL; 654 cattr_name(flags));
655 return -EINVAL;
656 }
657 /*
658 * We allow returning different type than the one requested in
659 * non strict case.
660 */
661 *vma_prot = __pgprot((pgprot_val(*vma_prot) &
662 (~_PAGE_CACHE_MASK)) |
663 flags);
637 } 664 }
638 665
639 /* Need to keep identity mapping in sync */ 666 /* Need to keep identity mapping in sync */
@@ -689,6 +716,7 @@ int track_pfn_vma_copy(struct vm_area_struct *vma)
689 unsigned long vma_start = vma->vm_start; 716 unsigned long vma_start = vma->vm_start;
690 unsigned long vma_end = vma->vm_end; 717 unsigned long vma_end = vma->vm_end;
691 unsigned long vma_size = vma_end - vma_start; 718 unsigned long vma_size = vma_end - vma_start;
719 pgprot_t pgprot;
692 720
693 if (!pat_enabled) 721 if (!pat_enabled)
694 return 0; 722 return 0;
@@ -702,7 +730,8 @@ int track_pfn_vma_copy(struct vm_area_struct *vma)
702 WARN_ON_ONCE(1); 730 WARN_ON_ONCE(1);
703 return -EINVAL; 731 return -EINVAL;
704 } 732 }
705 return reserve_pfn_range(paddr, vma_size, __pgprot(prot)); 733 pgprot = __pgprot(prot);
734 return reserve_pfn_range(paddr, vma_size, &pgprot, 1);
706 } 735 }
707 736
708 /* reserve entire vma page by page, using pfn and prot from pte */ 737 /* reserve entire vma page by page, using pfn and prot from pte */
@@ -710,7 +739,8 @@ int track_pfn_vma_copy(struct vm_area_struct *vma)
710 if (follow_phys(vma, vma_start + i, 0, &prot, &paddr)) 739 if (follow_phys(vma, vma_start + i, 0, &prot, &paddr))
711 continue; 740 continue;
712 741
713 retval = reserve_pfn_range(paddr, PAGE_SIZE, __pgprot(prot)); 742 pgprot = __pgprot(prot);
743 retval = reserve_pfn_range(paddr, PAGE_SIZE, &pgprot, 1);
714 if (retval) 744 if (retval)
715 goto cleanup_ret; 745 goto cleanup_ret;
716 } 746 }
@@ -741,7 +771,7 @@ cleanup_ret:
741 * Note that this function can be called with caller trying to map only a 771 * Note that this function can be called with caller trying to map only a
742 * subrange/page inside the vma. 772 * subrange/page inside the vma.
743 */ 773 */
744int track_pfn_vma_new(struct vm_area_struct *vma, pgprot_t prot, 774int track_pfn_vma_new(struct vm_area_struct *vma, pgprot_t *prot,
745 unsigned long pfn, unsigned long size) 775 unsigned long pfn, unsigned long size)
746{ 776{
747 int retval = 0; 777 int retval = 0;
@@ -758,14 +788,14 @@ int track_pfn_vma_new(struct vm_area_struct *vma, pgprot_t prot,
758 if (is_linear_pfn_mapping(vma)) { 788 if (is_linear_pfn_mapping(vma)) {
759 /* reserve the whole chunk starting from vm_pgoff */ 789 /* reserve the whole chunk starting from vm_pgoff */
760 paddr = (resource_size_t)vma->vm_pgoff << PAGE_SHIFT; 790 paddr = (resource_size_t)vma->vm_pgoff << PAGE_SHIFT;
761 return reserve_pfn_range(paddr, vma_size, prot); 791 return reserve_pfn_range(paddr, vma_size, prot, 0);
762 } 792 }
763 793
764 /* reserve page by page using pfn and size */ 794 /* reserve page by page using pfn and size */
765 base_paddr = (resource_size_t)pfn << PAGE_SHIFT; 795 base_paddr = (resource_size_t)pfn << PAGE_SHIFT;
766 for (i = 0; i < size; i += PAGE_SIZE) { 796 for (i = 0; i < size; i += PAGE_SIZE) {
767 paddr = base_paddr + i; 797 paddr = base_paddr + i;
768 retval = reserve_pfn_range(paddr, PAGE_SIZE, prot); 798 retval = reserve_pfn_range(paddr, PAGE_SIZE, prot, 0);
769 if (retval) 799 if (retval)
770 goto cleanup_ret; 800 goto cleanup_ret;
771 } 801 }