Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

x86/mm/mtrr: Use symbolic define as a retval for disabled MTRRs

mtrr_type_lookup() returns verbatim 0xFF when MTRRs are
disabled. This patch defines MTRR_TYPE_INVALID to clarify the
meaning of this value, and documents its usage.

Document the return values of the kernel virtual address mapping
helpers pud_set_huge(), pmd_set_huge, pud_clear_huge() and
pmd_clear_huge().

There is no functional change in this patch.

Signed-off-by: Toshi Kani <toshi.kani@hp.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: Elliott@hp.com
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Luis R. Rodriguez <mcgrof@suse.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: dave.hansen@intel.com
Cc: linux-mm <linux-mm@kvack.org>
Cc: pebolle@tiscali.nl
Link: http://lkml.kernel.org/r/1431714237-880-5-git-send-email-toshi.kani@hp.com
Link: http://lkml.kernel.org/r/1432628901-18044-5-git-send-email-bp@alien8.de
Signed-off-by: Ingo Molnar <mingo@kernel.org>

authored by

Toshi Kani and committed by
Ingo Molnar
3d3ca416 9b3aca62

+47 -19
+1 -1
arch/x86/include/asm/mtrr.h
··· 55 55 /* 56 56 * Return no-MTRRs: 57 57 */ 58 - return 0xff; 58 + return MTRR_TYPE_INVALID; 59 59 } 60 60 #define mtrr_save_fixed_ranges(arg) do {} while (0) 61 61 #define mtrr_save_state() do {} while (0)
+7 -1
arch/x86/include/uapi/asm/mtrr.h
··· 103 103 #define MTRRIOC_GET_PAGE_ENTRY _IOWR(MTRR_IOCTL_BASE, 8, struct mtrr_gentry) 104 104 #define MTRRIOC_KILL_PAGE_ENTRY _IOW(MTRR_IOCTL_BASE, 9, struct mtrr_sentry) 105 105 106 - /* These are the region types */ 106 + /* MTRR memory types, which are defined in SDM */ 107 107 #define MTRR_TYPE_UNCACHABLE 0 108 108 #define MTRR_TYPE_WRCOMB 1 109 109 /*#define MTRR_TYPE_ 2*/ ··· 113 113 #define MTRR_TYPE_WRBACK 6 114 114 #define MTRR_NUM_TYPES 7 115 115 116 + /* 117 + * Invalid MTRR memory type. mtrr_type_lookup() returns this value when 118 + * MTRRs are disabled. Note, this value is allocated from the reserved 119 + * values (0x7-0xff) of the MTRR memory types. 120 + */ 121 + #define MTRR_TYPE_INVALID 0xff 116 122 117 123 #endif /* _UAPI_ASM_X86_MTRR_H */
+7 -7
arch/x86/kernel/cpu/mtrr/generic.c
··· 104 104 105 105 /* 106 106 * Error/Semi-error returns: 107 - * 0xFF - when MTRR is not enabled 107 + * MTRR_TYPE_INVALID - when MTRR is not enabled 108 108 * *repeat == 1 implies [start:end] spanned across MTRR range and type returned 109 109 * corresponds only to [start:*partial_end]. 110 110 * Caller has to lookup again for [*partial_end:end]. ··· 117 117 118 118 *repeat = 0; 119 119 if (!mtrr_state_set) 120 - return 0xFF; 120 + return MTRR_TYPE_INVALID; 121 121 122 122 if (!(mtrr_state.enabled & MTRR_STATE_MTRR_ENABLED)) 123 - return 0xFF; 123 + return MTRR_TYPE_INVALID; 124 124 125 125 /* Make end inclusive end, instead of exclusive */ 126 126 end--; ··· 151 151 * Look of multiple ranges matching this address and pick type 152 152 * as per MTRR precedence 153 153 */ 154 - prev_match = 0xFF; 154 + prev_match = MTRR_TYPE_INVALID; 155 155 for (i = 0; i < num_var_ranges; ++i) { 156 156 unsigned short start_state, end_state, inclusive; 157 157 ··· 206 206 continue; 207 207 208 208 curr_match = mtrr_state.var_ranges[i].base_lo & 0xff; 209 - if (prev_match == 0xFF) { 209 + if (prev_match == MTRR_TYPE_INVALID) { 210 210 prev_match = curr_match; 211 211 continue; 212 212 } ··· 220 220 return MTRR_TYPE_WRBACK; 221 221 } 222 222 223 - if (prev_match != 0xFF) 223 + if (prev_match != MTRR_TYPE_INVALID) 224 224 return prev_match; 225 225 226 226 return mtrr_state.def_type; ··· 229 229 /* 230 230 * Returns the effective MTRR type for the region 231 231 * Error return: 232 - * 0xFF - when MTRR is not enabled 232 + * MTRR_TYPE_INVALID - when MTRR is not enabled 233 233 */ 234 234 u8 mtrr_type_lookup(u64 start, u64 end) 235 235 {
+32 -10
arch/x86/mm/pgtable.c
··· 563 563 } 564 564 565 565 #ifdef CONFIG_HAVE_ARCH_HUGE_VMAP 566 + /** 567 + * pud_set_huge - setup kernel PUD mapping 568 + * 569 + * MTRR can override PAT memory types with 4KiB granularity. Therefore, 570 + * this function does not set up a huge page when the range is covered 571 + * by a non-WB type of MTRR. MTRR_TYPE_INVALID indicates that MTRR are 572 + * disabled. 573 + * 574 + * Returns 1 on success and 0 on failure. 575 + */ 566 576 int pud_set_huge(pud_t *pud, phys_addr_t addr, pgprot_t prot) 567 577 { 568 578 u8 mtrr; 569 579 570 - /* 571 - * Do not use a huge page when the range is covered by non-WB type 572 - * of MTRRs. 573 - */ 574 580 mtrr = mtrr_type_lookup(addr, addr + PUD_SIZE); 575 - if ((mtrr != MTRR_TYPE_WRBACK) && (mtrr != 0xFF)) 581 + if ((mtrr != MTRR_TYPE_WRBACK) && (mtrr != MTRR_TYPE_INVALID)) 576 582 return 0; 577 583 578 584 prot = pgprot_4k_2_large(prot); ··· 590 584 return 1; 591 585 } 592 586 587 + /** 588 + * pmd_set_huge - setup kernel PMD mapping 589 + * 590 + * MTRR can override PAT memory types with 4KiB granularity. Therefore, 591 + * this function does not set up a huge page when the range is covered 592 + * by a non-WB type of MTRR. MTRR_TYPE_INVALID indicates that MTRR are 593 + * disabled. 594 + * 595 + * Returns 1 on success and 0 on failure. 596 + */ 593 597 int pmd_set_huge(pmd_t *pmd, phys_addr_t addr, pgprot_t prot) 594 598 { 595 599 u8 mtrr; 596 600 597 - /* 598 - * Do not use a huge page when the range is covered by non-WB type 599 - * of MTRRs. 600 - */ 601 601 mtrr = mtrr_type_lookup(addr, addr + PMD_SIZE); 602 - if ((mtrr != MTRR_TYPE_WRBACK) && (mtrr != 0xFF)) 602 + if ((mtrr != MTRR_TYPE_WRBACK) && (mtrr != MTRR_TYPE_INVALID)) 603 603 return 0; 604 604 605 605 prot = pgprot_4k_2_large(prot); ··· 617 605 return 1; 618 606 } 619 607 608 + /** 609 + * pud_clear_huge - clear kernel PUD mapping when it is set 610 + * 611 + * Returns 1 on success and 0 on failure (no PUD map is found). 612 + */ 620 613 int pud_clear_huge(pud_t *pud) 621 614 { 622 615 if (pud_large(*pud)) { ··· 632 615 return 0; 633 616 } 634 617 618 + /** 619 + * pmd_clear_huge - clear kernel PMD mapping when it is set 620 + * 621 + * Returns 1 on success and 0 on failure (no PMD map is found). 622 + */ 635 623 int pmd_clear_huge(pmd_t *pmd) 636 624 { 637 625 if (pmd_large(*pmd)) {