Skip to content

Commit 3d3ca41

Browse files
Toshi KaniIngo Molnar
authored andcommitted
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 <[email protected]> Signed-off-by: Borislav Petkov <[email protected]> Cc: Andrew Morton <[email protected]> Cc: Andy Lutomirski <[email protected]> Cc: Borislav Petkov <[email protected]> Cc: Brian Gerst <[email protected]> Cc: Denys Vlasenko <[email protected]> Cc: [email protected] Cc: H. Peter Anvin <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Luis R. Rodriguez <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: [email protected] Cc: linux-mm <[email protected]> Cc: [email protected] Link: http://lkml.kernel.org/r/[email protected] Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Ingo Molnar <[email protected]>
1 parent 9b3aca6 commit 3d3ca41

File tree

4 files changed

+47
-19
lines changed

4 files changed

+47
-19
lines changed

arch/x86/include/asm/mtrr.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ static inline u8 mtrr_type_lookup(u64 addr, u64 end)
5555
/*
5656
* Return no-MTRRs:
5757
*/
58-
return 0xff;
58+
return MTRR_TYPE_INVALID;
5959
}
6060
#define mtrr_save_fixed_ranges(arg) do {} while (0)
6161
#define mtrr_save_state() do {} while (0)

arch/x86/include/uapi/asm/mtrr.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ struct mtrr_state_type {
103103
#define MTRRIOC_GET_PAGE_ENTRY _IOWR(MTRR_IOCTL_BASE, 8, struct mtrr_gentry)
104104
#define MTRRIOC_KILL_PAGE_ENTRY _IOW(MTRR_IOCTL_BASE, 9, struct mtrr_sentry)
105105

106-
/* These are the region types */
106+
/* MTRR memory types, which are defined in SDM */
107107
#define MTRR_TYPE_UNCACHABLE 0
108108
#define MTRR_TYPE_WRCOMB 1
109109
/*#define MTRR_TYPE_ 2*/
@@ -113,5 +113,11 @@ struct mtrr_state_type {
113113
#define MTRR_TYPE_WRBACK 6
114114
#define MTRR_NUM_TYPES 7
115115

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
116122

117123
#endif /* _UAPI_ASM_X86_MTRR_H */

arch/x86/kernel/cpu/mtrr/generic.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ static int check_type_overlap(u8 *prev, u8 *curr)
104104

105105
/*
106106
* Error/Semi-error returns:
107-
* 0xFF - when MTRR is not enabled
107+
* MTRR_TYPE_INVALID - when MTRR is not enabled
108108
* *repeat == 1 implies [start:end] spanned across MTRR range and type returned
109109
* corresponds only to [start:*partial_end].
110110
* Caller has to lookup again for [*partial_end:end].
@@ -117,10 +117,10 @@ static u8 __mtrr_type_lookup(u64 start, u64 end, u64 *partial_end, int *repeat)
117117

118118
*repeat = 0;
119119
if (!mtrr_state_set)
120-
return 0xFF;
120+
return MTRR_TYPE_INVALID;
121121

122122
if (!(mtrr_state.enabled & MTRR_STATE_MTRR_ENABLED))
123-
return 0xFF;
123+
return MTRR_TYPE_INVALID;
124124

125125
/* Make end inclusive end, instead of exclusive */
126126
end--;
@@ -151,7 +151,7 @@ static u8 __mtrr_type_lookup(u64 start, u64 end, u64 *partial_end, int *repeat)
151151
* Look of multiple ranges matching this address and pick type
152152
* as per MTRR precedence
153153
*/
154-
prev_match = 0xFF;
154+
prev_match = MTRR_TYPE_INVALID;
155155
for (i = 0; i < num_var_ranges; ++i) {
156156
unsigned short start_state, end_state, inclusive;
157157

@@ -206,7 +206,7 @@ static u8 __mtrr_type_lookup(u64 start, u64 end, u64 *partial_end, int *repeat)
206206
continue;
207207

208208
curr_match = mtrr_state.var_ranges[i].base_lo & 0xff;
209-
if (prev_match == 0xFF) {
209+
if (prev_match == MTRR_TYPE_INVALID) {
210210
prev_match = curr_match;
211211
continue;
212212
}
@@ -220,7 +220,7 @@ static u8 __mtrr_type_lookup(u64 start, u64 end, u64 *partial_end, int *repeat)
220220
return MTRR_TYPE_WRBACK;
221221
}
222222

223-
if (prev_match != 0xFF)
223+
if (prev_match != MTRR_TYPE_INVALID)
224224
return prev_match;
225225

226226
return mtrr_state.def_type;
@@ -229,7 +229,7 @@ static u8 __mtrr_type_lookup(u64 start, u64 end, u64 *partial_end, int *repeat)
229229
/*
230230
* Returns the effective MTRR type for the region
231231
* Error return:
232-
* 0xFF - when MTRR is not enabled
232+
* MTRR_TYPE_INVALID - when MTRR is not enabled
233233
*/
234234
u8 mtrr_type_lookup(u64 start, u64 end)
235235
{

arch/x86/mm/pgtable.c

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -563,16 +563,22 @@ void native_set_fixmap(enum fixed_addresses idx, phys_addr_t phys,
563563
}
564564

565565
#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+
*/
566576
int pud_set_huge(pud_t *pud, phys_addr_t addr, pgprot_t prot)
567577
{
568578
u8 mtrr;
569579

570-
/*
571-
* Do not use a huge page when the range is covered by non-WB type
572-
* of MTRRs.
573-
*/
574580
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))
576582
return 0;
577583

578584
prot = pgprot_4k_2_large(prot);
@@ -584,16 +590,22 @@ int pud_set_huge(pud_t *pud, phys_addr_t addr, pgprot_t prot)
584590
return 1;
585591
}
586592

593+
/**
594+
* pmd_set_huge - setup kernel PMD mapping
595+
*
596+
* MTRR can override PAT memory types with 4KiB granularity. Therefore,
597+
* this function does not set up a huge page when the range is covered
598+
* by a non-WB type of MTRR. MTRR_TYPE_INVALID indicates that MTRR are
599+
* disabled.
600+
*
601+
* Returns 1 on success and 0 on failure.
602+
*/
587603
int pmd_set_huge(pmd_t *pmd, phys_addr_t addr, pgprot_t prot)
588604
{
589605
u8 mtrr;
590606

591-
/*
592-
* Do not use a huge page when the range is covered by non-WB type
593-
* of MTRRs.
594-
*/
595607
mtrr = mtrr_type_lookup(addr, addr + PMD_SIZE);
596-
if ((mtrr != MTRR_TYPE_WRBACK) && (mtrr != 0xFF))
608+
if ((mtrr != MTRR_TYPE_WRBACK) && (mtrr != MTRR_TYPE_INVALID))
597609
return 0;
598610

599611
prot = pgprot_4k_2_large(prot);
@@ -605,6 +617,11 @@ int pmd_set_huge(pmd_t *pmd, phys_addr_t addr, pgprot_t prot)
605617
return 1;
606618
}
607619

620+
/**
621+
* pud_clear_huge - clear kernel PUD mapping when it is set
622+
*
623+
* Returns 1 on success and 0 on failure (no PUD map is found).
624+
*/
608625
int pud_clear_huge(pud_t *pud)
609626
{
610627
if (pud_large(*pud)) {
@@ -615,6 +632,11 @@ int pud_clear_huge(pud_t *pud)
615632
return 0;
616633
}
617634

635+
/**
636+
* pmd_clear_huge - clear kernel PMD mapping when it is set
637+
*
638+
* Returns 1 on success and 0 on failure (no PMD map is found).
639+
*/
618640
int pmd_clear_huge(pmd_t *pmd)
619641
{
620642
if (pmd_large(*pmd)) {

0 commit comments

Comments
 (0)