Skip to content

Commit beb2e44

Browse files
committed
x86/cpu: KVM: Move macro to encode PAT value to common header
Move pat/memtype.c's PAT() macro to msr-index.h as PAT_VALUE(), and use it in KVM to define the default (Power-On / RESET) PAT value instead of open coding an inscrutable magic number. No functional change intended. Reviewed-by: Xiaoyao Li <[email protected]> Reviewed-by: Kai Huang <[email protected]> Reviewed-by: Thomas Gleixner <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Sean Christopherson <[email protected]>
1 parent e7e80b6 commit beb2e44

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

arch/x86/include/asm/msr-index.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,12 @@
377377

378378
#define MSR_IA32_CR_PAT 0x00000277
379379

380+
#define PAT_VALUE(p0, p1, p2, p3, p4, p5, p6, p7) \
381+
((X86_MEMTYPE_ ## p0) | (X86_MEMTYPE_ ## p1 << 8) | \
382+
(X86_MEMTYPE_ ## p2 << 16) | (X86_MEMTYPE_ ## p3 << 24) | \
383+
(X86_MEMTYPE_ ## p4 << 32) | (X86_MEMTYPE_ ## p5 << 40) | \
384+
(X86_MEMTYPE_ ## p6 << 48) | (X86_MEMTYPE_ ## p7 << 56))
385+
380386
#define MSR_IA32_DEBUGCTLMSR 0x000001d9
381387
#define MSR_IA32_LASTBRANCHFROMIP 0x000001db
382388
#define MSR_IA32_LASTBRANCHTOIP 0x000001dc

arch/x86/kvm/x86.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ static inline unsigned int __shrink_ple_window(unsigned int val,
103103
return max(val, min);
104104
}
105105

106-
#define MSR_IA32_CR_PAT_DEFAULT 0x0007040600070406ULL
106+
#define MSR_IA32_CR_PAT_DEFAULT \
107+
PAT_VALUE(WB, WT, UC_MINUS, UC, WB, WT, UC_MINUS, UC)
107108

108109
void kvm_service_local_tlb_flush_requests(struct kvm_vcpu *vcpu);
109110
int kvm_check_nested_events(struct kvm_vcpu *vcpu);

arch/x86/mm/pat/memtype.c

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -248,12 +248,6 @@ void pat_cpu_init(void)
248248
void __init pat_bp_init(void)
249249
{
250250
struct cpuinfo_x86 *c = &boot_cpu_data;
251-
#define PAT(p0, p1, p2, p3, p4, p5, p6, p7) \
252-
((X86_MEMTYPE_ ## p0) | (X86_MEMTYPE_ ## p1 << 8) | \
253-
(X86_MEMTYPE_ ## p2 << 16) | (X86_MEMTYPE_ ## p3 << 24) | \
254-
(X86_MEMTYPE_ ## p4 << 32) | (X86_MEMTYPE_ ## p5 << 40) | \
255-
(X86_MEMTYPE_ ## p6 << 48) | (X86_MEMTYPE_ ## p7 << 56))
256-
257251

258252
if (!IS_ENABLED(CONFIG_X86_PAT))
259253
pr_info_once("x86/PAT: PAT support disabled because CONFIG_X86_PAT is disabled in the kernel.\n");
@@ -284,7 +278,7 @@ void __init pat_bp_init(void)
284278
* NOTE: When WC or WP is used, it is redirected to UC- per
285279
* the default setup in __cachemode2pte_tbl[].
286280
*/
287-
pat_msr_val = PAT(WB, WT, UC_MINUS, UC, WB, WT, UC_MINUS, UC);
281+
pat_msr_val = PAT_VALUE(WB, WT, UC_MINUS, UC, WB, WT, UC_MINUS, UC);
288282
}
289283

290284
/*
@@ -319,7 +313,7 @@ void __init pat_bp_init(void)
319313
* NOTE: When WT or WP is used, it is redirected to UC- per
320314
* the default setup in __cachemode2pte_tbl[].
321315
*/
322-
pat_msr_val = PAT(WB, WC, UC_MINUS, UC, WB, WC, UC_MINUS, UC);
316+
pat_msr_val = PAT_VALUE(WB, WC, UC_MINUS, UC, WB, WC, UC_MINUS, UC);
323317
} else {
324318
/*
325319
* Full PAT support. We put WT in slot 7 to improve
@@ -347,13 +341,12 @@ void __init pat_bp_init(void)
347341
* The reserved slots are unused, but mapped to their
348342
* corresponding types in the presence of PAT errata.
349343
*/
350-
pat_msr_val = PAT(WB, WC, UC_MINUS, UC, WB, WP, UC_MINUS, WT);
344+
pat_msr_val = PAT_VALUE(WB, WC, UC_MINUS, UC, WB, WP, UC_MINUS, WT);
351345
}
352346

353347
memory_caching_control |= CACHE_PAT;
354348

355349
init_cache_modes(pat_msr_val);
356-
#undef PAT
357350
}
358351

359352
static DEFINE_SPINLOCK(memtype_lock); /* protects memtype accesses */

0 commit comments

Comments
 (0)