diff options
author | Ingo Molnar <mingo@kernel.org> | 2016-09-22 05:15:38 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@kernel.org> | 2016-09-22 05:15:38 -0400 |
commit | baad92e34458fc051735c769437ab33719ebb2ef (patch) | |
tree | f301627afa3e951cc2f906da1546e5daca9355da /arch/x86 | |
parent | f43ea76cf310c3be95cb75ae1350cbe76a8f2380 (diff) | |
parent | 7d1e042314619115153a0f6f06e4552c09a50e13 (diff) |
Merge branch 'linus' into x86/platform, to pick up fixes
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Diffstat (limited to 'arch/x86')
32 files changed, 425 insertions, 299 deletions
diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index c580d8c33562..2a1f0ce7c59a 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig | |||
@@ -24,7 +24,6 @@ config X86 | |||
24 | select ARCH_DISCARD_MEMBLOCK | 24 | select ARCH_DISCARD_MEMBLOCK |
25 | select ARCH_HAS_ACPI_TABLE_UPGRADE if ACPI | 25 | select ARCH_HAS_ACPI_TABLE_UPGRADE if ACPI |
26 | select ARCH_HAS_ATOMIC64_DEC_IF_POSITIVE | 26 | select ARCH_HAS_ATOMIC64_DEC_IF_POSITIVE |
27 | select ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS | ||
28 | select ARCH_HAS_DEVMEM_IS_ALLOWED | 27 | select ARCH_HAS_DEVMEM_IS_ALLOWED |
29 | select ARCH_HAS_ELF_RANDOMIZE | 28 | select ARCH_HAS_ELF_RANDOMIZE |
30 | select ARCH_HAS_FAST_MULTIPLIER | 29 | select ARCH_HAS_FAST_MULTIPLIER |
diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c index ff574dad95cc..94dd4a31f5b3 100644 --- a/arch/x86/boot/compressed/eboot.c +++ b/arch/x86/boot/compressed/eboot.c | |||
@@ -1004,79 +1004,87 @@ static efi_status_t alloc_e820ext(u32 nr_desc, struct setup_data **e820ext, | |||
1004 | return status; | 1004 | return status; |
1005 | } | 1005 | } |
1006 | 1006 | ||
1007 | static efi_status_t exit_boot(struct boot_params *boot_params, | 1007 | struct exit_boot_struct { |
1008 | void *handle, bool is64) | 1008 | struct boot_params *boot_params; |
1009 | { | 1009 | struct efi_info *efi; |
1010 | struct efi_info *efi = &boot_params->efi_info; | ||
1011 | unsigned long map_sz, key, desc_size; | ||
1012 | efi_memory_desc_t *mem_map; | ||
1013 | struct setup_data *e820ext; | 1010 | struct setup_data *e820ext; |
1014 | const char *signature; | ||
1015 | __u32 e820ext_size; | 1011 | __u32 e820ext_size; |
1016 | __u32 nr_desc, prev_nr_desc; | 1012 | bool is64; |
1017 | efi_status_t status; | 1013 | }; |
1018 | __u32 desc_version; | ||
1019 | bool called_exit = false; | ||
1020 | u8 nr_entries; | ||
1021 | int i; | ||
1022 | |||
1023 | nr_desc = 0; | ||
1024 | e820ext = NULL; | ||
1025 | e820ext_size = 0; | ||
1026 | |||
1027 | get_map: | ||
1028 | status = efi_get_memory_map(sys_table, &mem_map, &map_sz, &desc_size, | ||
1029 | &desc_version, &key); | ||
1030 | |||
1031 | if (status != EFI_SUCCESS) | ||
1032 | return status; | ||
1033 | |||
1034 | prev_nr_desc = nr_desc; | ||
1035 | nr_desc = map_sz / desc_size; | ||
1036 | if (nr_desc > prev_nr_desc && | ||
1037 | nr_desc > ARRAY_SIZE(boot_params->e820_map)) { | ||
1038 | u32 nr_e820ext = nr_desc - ARRAY_SIZE(boot_params->e820_map); | ||
1039 | |||
1040 | status = alloc_e820ext(nr_e820ext, &e820ext, &e820ext_size); | ||
1041 | if (status != EFI_SUCCESS) | ||
1042 | goto free_mem_map; | ||
1043 | 1014 | ||
1044 | efi_call_early(free_pool, mem_map); | 1015 | static efi_status_t exit_boot_func(efi_system_table_t *sys_table_arg, |
1045 | goto get_map; /* Allocated memory, get map again */ | 1016 | struct efi_boot_memmap *map, |
1017 | void *priv) | ||
1018 | { | ||
1019 | static bool first = true; | ||
1020 | const char *signature; | ||
1021 | __u32 nr_desc; | ||
1022 | efi_status_t status; | ||
1023 | struct exit_boot_struct *p = priv; | ||
1024 | |||
1025 | if (first) { | ||
1026 | nr_desc = *map->buff_size / *map->desc_size; | ||
1027 | if (nr_desc > ARRAY_SIZE(p->boot_params->e820_map)) { | ||
1028 | u32 nr_e820ext = nr_desc - | ||
1029 | ARRAY_SIZE(p->boot_params->e820_map); | ||
1030 | |||
1031 | status = alloc_e820ext(nr_e820ext, &p->e820ext, | ||
1032 | &p->e820ext_size); | ||
1033 | if (status != EFI_SUCCESS) | ||
1034 | return status; | ||
1035 | } | ||
1036 | first = false; | ||
1046 | } | 1037 | } |
1047 | 1038 | ||
1048 | signature = is64 ? EFI64_LOADER_SIGNATURE : EFI32_LOADER_SIGNATURE; | 1039 | signature = p->is64 ? EFI64_LOADER_SIGNATURE : EFI32_LOADER_SIGNATURE; |
1049 | memcpy(&efi->efi_loader_signature, signature, sizeof(__u32)); | 1040 | memcpy(&p->efi->efi_loader_signature, signature, sizeof(__u32)); |
1050 | 1041 | ||
1051 | efi->efi_systab = (unsigned long)sys_table; | 1042 | p->efi->efi_systab = (unsigned long)sys_table_arg; |
1052 | efi->efi_memdesc_size = desc_size; | 1043 | p->efi->efi_memdesc_size = *map->desc_size; |
1053 | efi->efi_memdesc_version = desc_version; | 1044 | p->efi->efi_memdesc_version = *map->desc_ver; |
1054 | efi->efi_memmap = (unsigned long)mem_map; | 1045 | p->efi->efi_memmap = (unsigned long)*map->map; |
1055 | efi->efi_memmap_size = map_sz; | 1046 | p->efi->efi_memmap_size = *map->map_size; |
1056 | 1047 | ||
1057 | #ifdef CONFIG_X86_64 | 1048 | #ifdef CONFIG_X86_64 |
1058 | efi->efi_systab_hi = (unsigned long)sys_table >> 32; | 1049 | p->efi->efi_systab_hi = (unsigned long)sys_table_arg >> 32; |
1059 | efi->efi_memmap_hi = (unsigned long)mem_map >> 32; | 1050 | p->efi->efi_memmap_hi = (unsigned long)*map->map >> 32; |
1060 | #endif | 1051 | #endif |
1061 | 1052 | ||
1053 | return EFI_SUCCESS; | ||
1054 | } | ||
1055 | |||
1056 | static efi_status_t exit_boot(struct boot_params *boot_params, | ||
1057 | void *handle, bool is64) | ||
1058 | { | ||
1059 | unsigned long map_sz, key, desc_size, buff_size; | ||
1060 | efi_memory_desc_t *mem_map; | ||
1061 | struct setup_data *e820ext; | ||
1062 | __u32 e820ext_size; | ||
1063 | efi_status_t status; | ||
1064 | __u32 desc_version; | ||
1065 | struct efi_boot_memmap map; | ||
1066 | struct exit_boot_struct priv; | ||
1067 | |||
1068 | map.map = &mem_map; | ||
1069 | map.map_size = &map_sz; | ||
1070 | map.desc_size = &desc_size; | ||
1071 | map.desc_ver = &desc_version; | ||
1072 | map.key_ptr = &key; | ||
1073 | map.buff_size = &buff_size; | ||
1074 | priv.boot_params = boot_params; | ||
1075 | priv.efi = &boot_params->efi_info; | ||
1076 | priv.e820ext = NULL; | ||
1077 | priv.e820ext_size = 0; | ||
1078 | priv.is64 = is64; | ||
1079 | |||
1062 | /* Might as well exit boot services now */ | 1080 | /* Might as well exit boot services now */ |
1063 | status = efi_call_early(exit_boot_services, handle, key); | 1081 | status = efi_exit_boot_services(sys_table, handle, &map, &priv, |
1064 | if (status != EFI_SUCCESS) { | 1082 | exit_boot_func); |
1065 | /* | 1083 | if (status != EFI_SUCCESS) |
1066 | * ExitBootServices() will fail if any of the event | 1084 | return status; |
1067 | * handlers change the memory map. In which case, we | ||
1068 | * must be prepared to retry, but only once so that | ||
1069 | * we're guaranteed to exit on repeated failures instead | ||
1070 | * of spinning forever. | ||
1071 | */ | ||
1072 | if (called_exit) | ||
1073 | goto free_mem_map; | ||
1074 | |||
1075 | called_exit = true; | ||
1076 | efi_call_early(free_pool, mem_map); | ||
1077 | goto get_map; | ||
1078 | } | ||
1079 | 1085 | ||
1086 | e820ext = priv.e820ext; | ||
1087 | e820ext_size = priv.e820ext_size; | ||
1080 | /* Historic? */ | 1088 | /* Historic? */ |
1081 | boot_params->alt_mem_k = 32 * 1024; | 1089 | boot_params->alt_mem_k = 32 * 1024; |
1082 | 1090 | ||
@@ -1085,10 +1093,6 @@ get_map: | |||
1085 | return status; | 1093 | return status; |
1086 | 1094 | ||
1087 | return EFI_SUCCESS; | 1095 | return EFI_SUCCESS; |
1088 | |||
1089 | free_mem_map: | ||
1090 | efi_call_early(free_pool, mem_map); | ||
1091 | return status; | ||
1092 | } | 1096 | } |
1093 | 1097 | ||
1094 | /* | 1098 | /* |
diff --git a/arch/x86/configs/tiny.config b/arch/x86/configs/tiny.config index 4e2ecfa23c15..4b429df40d7a 100644 --- a/arch/x86/configs/tiny.config +++ b/arch/x86/configs/tiny.config | |||
@@ -1 +1,3 @@ | |||
1 | CONFIG_NOHIGHMEM=y | 1 | CONFIG_NOHIGHMEM=y |
2 | # CONFIG_HIGHMEM4G is not set | ||
3 | # CONFIG_HIGHMEM64G is not set | ||
diff --git a/arch/x86/crypto/sha256-mb/sha256_mb.c b/arch/x86/crypto/sha256-mb/sha256_mb.c index 89fa85e8b10c..6f97fb33ae21 100644 --- a/arch/x86/crypto/sha256-mb/sha256_mb.c +++ b/arch/x86/crypto/sha256-mb/sha256_mb.c | |||
@@ -485,10 +485,10 @@ static int sha_complete_job(struct mcryptd_hash_request_ctx *rctx, | |||
485 | 485 | ||
486 | req = cast_mcryptd_ctx_to_req(req_ctx); | 486 | req = cast_mcryptd_ctx_to_req(req_ctx); |
487 | if (irqs_disabled()) | 487 | if (irqs_disabled()) |
488 | rctx->complete(&req->base, ret); | 488 | req_ctx->complete(&req->base, ret); |
489 | else { | 489 | else { |
490 | local_bh_disable(); | 490 | local_bh_disable(); |
491 | rctx->complete(&req->base, ret); | 491 | req_ctx->complete(&req->base, ret); |
492 | local_bh_enable(); | 492 | local_bh_enable(); |
493 | } | 493 | } |
494 | } | 494 | } |
diff --git a/arch/x86/crypto/sha256-mb/sha256_mb_mgr_flush_avx2.S b/arch/x86/crypto/sha256-mb/sha256_mb_mgr_flush_avx2.S index b691da981cd9..a78a0694ddef 100644 --- a/arch/x86/crypto/sha256-mb/sha256_mb_mgr_flush_avx2.S +++ b/arch/x86/crypto/sha256-mb/sha256_mb_mgr_flush_avx2.S | |||
@@ -265,13 +265,14 @@ ENTRY(sha256_mb_mgr_get_comp_job_avx2) | |||
265 | vpinsrd $1, _args_digest+1*32(state, idx, 4), %xmm0, %xmm0 | 265 | vpinsrd $1, _args_digest+1*32(state, idx, 4), %xmm0, %xmm0 |
266 | vpinsrd $2, _args_digest+2*32(state, idx, 4), %xmm0, %xmm0 | 266 | vpinsrd $2, _args_digest+2*32(state, idx, 4), %xmm0, %xmm0 |
267 | vpinsrd $3, _args_digest+3*32(state, idx, 4), %xmm0, %xmm0 | 267 | vpinsrd $3, _args_digest+3*32(state, idx, 4), %xmm0, %xmm0 |
268 | movl _args_digest+4*32(state, idx, 4), tmp2_w | 268 | vmovd _args_digest(state , idx, 4) , %xmm0 |
269 | vpinsrd $1, _args_digest+5*32(state, idx, 4), %xmm1, %xmm1 | 269 | vpinsrd $1, _args_digest+5*32(state, idx, 4), %xmm1, %xmm1 |
270 | vpinsrd $2, _args_digest+6*32(state, idx, 4), %xmm1, %xmm1 | 270 | vpinsrd $2, _args_digest+6*32(state, idx, 4), %xmm1, %xmm1 |
271 | vpinsrd $3, _args_digest+7*32(state, idx, 4), %xmm1, %xmm1 | 271 | vpinsrd $3, _args_digest+7*32(state, idx, 4), %xmm1, %xmm1 |
272 | 272 | ||
273 | vmovdqu %xmm0, _result_digest(job_rax) | 273 | vmovdqu %xmm0, _result_digest(job_rax) |
274 | movl tmp2_w, _result_digest+1*16(job_rax) | 274 | offset = (_result_digest + 1*16) |
275 | vmovdqu %xmm1, offset(job_rax) | ||
275 | 276 | ||
276 | pop %rbx | 277 | pop %rbx |
277 | 278 | ||
diff --git a/arch/x86/crypto/sha512-mb/sha512_mb.c b/arch/x86/crypto/sha512-mb/sha512_mb.c index f4cf5b78fd36..d210174a52b0 100644 --- a/arch/x86/crypto/sha512-mb/sha512_mb.c +++ b/arch/x86/crypto/sha512-mb/sha512_mb.c | |||
@@ -497,10 +497,10 @@ static int sha_complete_job(struct mcryptd_hash_request_ctx *rctx, | |||
497 | 497 | ||
498 | req = cast_mcryptd_ctx_to_req(req_ctx); | 498 | req = cast_mcryptd_ctx_to_req(req_ctx); |
499 | if (irqs_disabled()) | 499 | if (irqs_disabled()) |
500 | rctx->complete(&req->base, ret); | 500 | req_ctx->complete(&req->base, ret); |
501 | else { | 501 | else { |
502 | local_bh_disable(); | 502 | local_bh_disable(); |
503 | rctx->complete(&req->base, ret); | 503 | req_ctx->complete(&req->base, ret); |
504 | local_bh_enable(); | 504 | local_bh_enable(); |
505 | } | 505 | } |
506 | } | 506 | } |
diff --git a/arch/x86/events/amd/core.c b/arch/x86/events/amd/core.c index e07a22bb9308..f5f4b3fbbbc2 100644 --- a/arch/x86/events/amd/core.c +++ b/arch/x86/events/amd/core.c | |||
@@ -119,8 +119,8 @@ static const u64 amd_perfmon_event_map[PERF_COUNT_HW_MAX] = | |||
119 | { | 119 | { |
120 | [PERF_COUNT_HW_CPU_CYCLES] = 0x0076, | 120 | [PERF_COUNT_HW_CPU_CYCLES] = 0x0076, |
121 | [PERF_COUNT_HW_INSTRUCTIONS] = 0x00c0, | 121 | [PERF_COUNT_HW_INSTRUCTIONS] = 0x00c0, |
122 | [PERF_COUNT_HW_CACHE_REFERENCES] = 0x0080, | 122 | [PERF_COUNT_HW_CACHE_REFERENCES] = 0x077d, |
123 | [PERF_COUNT_HW_CACHE_MISSES] = 0x0081, | 123 | [PERF_COUNT_HW_CACHE_MISSES] = 0x077e, |
124 | [PERF_COUNT_HW_BRANCH_INSTRUCTIONS] = 0x00c2, | 124 | [PERF_COUNT_HW_BRANCH_INSTRUCTIONS] = 0x00c2, |
125 | [PERF_COUNT_HW_BRANCH_MISSES] = 0x00c3, | 125 | [PERF_COUNT_HW_BRANCH_MISSES] = 0x00c3, |
126 | [PERF_COUNT_HW_STALLED_CYCLES_FRONTEND] = 0x00d0, /* "Decoder empty" event */ | 126 | [PERF_COUNT_HW_STALLED_CYCLES_FRONTEND] = 0x00d0, /* "Decoder empty" event */ |
diff --git a/arch/x86/events/amd/uncore.c b/arch/x86/events/amd/uncore.c index e6131d4454e6..65577f081d07 100644 --- a/arch/x86/events/amd/uncore.c +++ b/arch/x86/events/amd/uncore.c | |||
@@ -29,6 +29,8 @@ | |||
29 | 29 | ||
30 | #define COUNTER_SHIFT 16 | 30 | #define COUNTER_SHIFT 16 |
31 | 31 | ||
32 | static HLIST_HEAD(uncore_unused_list); | ||
33 | |||
32 | struct amd_uncore { | 34 | struct amd_uncore { |
33 | int id; | 35 | int id; |
34 | int refcnt; | 36 | int refcnt; |
@@ -39,7 +41,7 @@ struct amd_uncore { | |||
39 | cpumask_t *active_mask; | 41 | cpumask_t *active_mask; |
40 | struct pmu *pmu; | 42 | struct pmu *pmu; |
41 | struct perf_event *events[MAX_COUNTERS]; | 43 | struct perf_event *events[MAX_COUNTERS]; |
42 | struct amd_uncore *free_when_cpu_online; | 44 | struct hlist_node node; |
43 | }; | 45 | }; |
44 | 46 | ||
45 | static struct amd_uncore * __percpu *amd_uncore_nb; | 47 | static struct amd_uncore * __percpu *amd_uncore_nb; |
@@ -306,6 +308,7 @@ static int amd_uncore_cpu_up_prepare(unsigned int cpu) | |||
306 | uncore_nb->msr_base = MSR_F15H_NB_PERF_CTL; | 308 | uncore_nb->msr_base = MSR_F15H_NB_PERF_CTL; |
307 | uncore_nb->active_mask = &amd_nb_active_mask; | 309 | uncore_nb->active_mask = &amd_nb_active_mask; |
308 | uncore_nb->pmu = &amd_nb_pmu; | 310 | uncore_nb->pmu = &amd_nb_pmu; |
311 | uncore_nb->id = -1; | ||
309 | *per_cpu_ptr(amd_uncore_nb, cpu) = uncore_nb; | 312 | *per_cpu_ptr(amd_uncore_nb, cpu) = uncore_nb; |
310 | } | 313 | } |
311 | 314 | ||
@@ -319,6 +322,7 @@ static int amd_uncore_cpu_up_prepare(unsigned int cpu) | |||
319 | uncore_l2->msr_base = MSR_F16H_L2I_PERF_CTL; | 322 | uncore_l2->msr_base = MSR_F16H_L2I_PERF_CTL; |
320 | uncore_l2->active_mask = &amd_l2_active_mask; | 323 | uncore_l2->active_mask = &amd_l2_active_mask; |
321 | uncore_l2->pmu = &amd_l2_pmu; | 324 | uncore_l2->pmu = &amd_l2_pmu; |
325 | uncore_l2->id = -1; | ||
322 | *per_cpu_ptr(amd_uncore_l2, cpu) = uncore_l2; | 326 | *per_cpu_ptr(amd_uncore_l2, cpu) = uncore_l2; |
323 | } | 327 | } |
324 | 328 | ||
@@ -348,7 +352,7 @@ amd_uncore_find_online_sibling(struct amd_uncore *this, | |||
348 | continue; | 352 | continue; |
349 | 353 | ||
350 | if (this->id == that->id) { | 354 | if (this->id == that->id) { |
351 | that->free_when_cpu_online = this; | 355 | hlist_add_head(&this->node, &uncore_unused_list); |
352 | this = that; | 356 | this = that; |
353 | break; | 357 | break; |
354 | } | 358 | } |
@@ -388,13 +392,23 @@ static int amd_uncore_cpu_starting(unsigned int cpu) | |||
388 | return 0; | 392 | return 0; |
389 | } | 393 | } |
390 | 394 | ||
395 | static void uncore_clean_online(void) | ||
396 | { | ||
397 | struct amd_uncore *uncore; | ||
398 | struct hlist_node *n; | ||
399 | |||
400 | hlist_for_each_entry_safe(uncore, n, &uncore_unused_list, node) { | ||
401 | hlist_del(&uncore->node); | ||
402 | kfree(uncore); | ||
403 | } | ||
404 | } | ||
405 | |||
391 | static void uncore_online(unsigned int cpu, | 406 | static void uncore_online(unsigned int cpu, |
392 | struct amd_uncore * __percpu *uncores) | 407 | struct amd_uncore * __percpu *uncores) |
393 | { | 408 | { |
394 | struct amd_uncore *uncore = *per_cpu_ptr(uncores, cpu); | 409 | struct amd_uncore *uncore = *per_cpu_ptr(uncores, cpu); |
395 | 410 | ||
396 | kfree(uncore->free_when_cpu_online); | 411 | uncore_clean_online(); |
397 | uncore->free_when_cpu_online = NULL; | ||
398 | 412 | ||
399 | if (cpu == uncore->cpu) | 413 | if (cpu == uncore->cpu) |
400 | cpumask_set_cpu(cpu, uncore->active_mask); | 414 | cpumask_set_cpu(cpu, uncore->active_mask); |
diff --git a/arch/x86/events/intel/bts.c b/arch/x86/events/intel/bts.c index 0a6e393a2e62..bdcd6510992c 100644 --- a/arch/x86/events/intel/bts.c +++ b/arch/x86/events/intel/bts.c | |||
@@ -31,7 +31,17 @@ | |||
31 | struct bts_ctx { | 31 | struct bts_ctx { |
32 | struct perf_output_handle handle; | 32 | struct perf_output_handle handle; |
33 | struct debug_store ds_back; | 33 | struct debug_store ds_back; |
34 | int started; | 34 | int state; |
35 | }; | ||
36 | |||
37 | /* BTS context states: */ | ||
38 | enum { | ||
39 | /* no ongoing AUX transactions */ | ||
40 | BTS_STATE_STOPPED = 0, | ||
41 | /* AUX transaction is on, BTS tracing is disabled */ | ||
42 | BTS_STATE_INACTIVE, | ||
43 | /* AUX transaction is on, BTS tracing is running */ | ||
44 | BTS_STATE_ACTIVE, | ||
35 | }; | 45 | }; |
36 | 46 | ||
37 | static DEFINE_PER_CPU(struct bts_ctx, bts_ctx); | 47 | static DEFINE_PER_CPU(struct bts_ctx, bts_ctx); |
@@ -204,6 +214,15 @@ static void bts_update(struct bts_ctx *bts) | |||
204 | static int | 214 | static int |
205 | bts_buffer_reset(struct bts_buffer *buf, struct perf_output_handle *handle); | 215 | bts_buffer_reset(struct bts_buffer *buf, struct perf_output_handle *handle); |
206 | 216 | ||
217 | /* | ||
218 | * Ordering PMU callbacks wrt themselves and the PMI is done by means | ||
219 | * of bts::state, which: | ||
220 | * - is set when bts::handle::event is valid, that is, between | ||
221 | * perf_aux_output_begin() and perf_aux_output_end(); | ||
222 | * - is zero otherwise; | ||
223 | * - is ordered against bts::handle::event with a compiler barrier. | ||
224 | */ | ||
225 | |||
207 | static void __bts_event_start(struct perf_event *event) | 226 | static void __bts_event_start(struct perf_event *event) |
208 | { | 227 | { |
209 | struct bts_ctx *bts = this_cpu_ptr(&bts_ctx); | 228 | struct bts_ctx *bts = this_cpu_ptr(&bts_ctx); |
@@ -221,10 +240,13 @@ static void __bts_event_start(struct perf_event *event) | |||
221 | 240 | ||
222 | /* | 241 | /* |
223 | * local barrier to make sure that ds configuration made it | 242 | * local barrier to make sure that ds configuration made it |
224 | * before we enable BTS | 243 | * before we enable BTS and bts::state goes ACTIVE |
225 | */ | 244 | */ |
226 | wmb(); | 245 | wmb(); |
227 | 246 | ||
247 | /* INACTIVE/STOPPED -> ACTIVE */ | ||
248 | WRITE_ONCE(bts->state, BTS_STATE_ACTIVE); | ||
249 | |||
228 | intel_pmu_enable_bts(config); | 250 | intel_pmu_enable_bts(config); |
229 | 251 | ||
230 | } | 252 | } |
@@ -251,9 +273,6 @@ static void bts_event_start(struct perf_event *event, int flags) | |||
251 | 273 | ||
252 | __bts_event_start(event); | 274 | __bts_event_start(event); |
253 | 275 | ||
254 | /* PMI handler: this counter is running and likely generating PMIs */ | ||
255 | ACCESS_ONCE(bts->started) = 1; | ||
256 | |||
257 | return; | 276 | return; |
258 | 277 | ||
259 | fail_end_stop: | 278 | fail_end_stop: |
@@ -263,30 +282,34 @@ fail_stop: | |||
263 | event->hw.state = PERF_HES_STOPPED; | 282 | event->hw.state = PERF_HES_STOPPED; |
264 | } | 283 | } |
265 | 284 | ||
266 | static void __bts_event_stop(struct perf_event *event) | 285 | static void __bts_event_stop(struct perf_event *event, int state) |
267 | { | 286 | { |
287 | struct bts_ctx *bts = this_cpu_ptr(&bts_ctx); | ||
288 | |||
289 | /* ACTIVE -> INACTIVE(PMI)/STOPPED(->stop()) */ | ||
290 | WRITE_ONCE(bts->state, state); | ||
291 | |||
268 | /* | 292 | /* |
269 | * No extra synchronization is mandated by the documentation to have | 293 | * No extra synchronization is mandated by the documentation to have |
270 | * BTS data stores globally visible. | 294 | * BTS data stores globally visible. |
271 | */ | 295 | */ |
272 | intel_pmu_disable_bts(); | 296 | intel_pmu_disable_bts(); |
273 | |||
274 | if (event->hw.state & PERF_HES_STOPPED) | ||
275 | return; | ||
276 | |||
277 | ACCESS_ONCE(event->hw.state) |= PERF_HES_STOPPED; | ||
278 | } | 297 | } |
279 | 298 | ||
280 | static void bts_event_stop(struct perf_event *event, int flags) | 299 | static void bts_event_stop(struct perf_event *event, int flags) |
281 | { | 300 | { |
282 | struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events); | 301 | struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events); |
283 | struct bts_ctx *bts = this_cpu_ptr(&bts_ctx); | 302 | struct bts_ctx *bts = this_cpu_ptr(&bts_ctx); |
284 | struct bts_buffer *buf = perf_get_aux(&bts->handle); | 303 | struct bts_buffer *buf = NULL; |
304 | int state = READ_ONCE(bts->state); | ||
285 | 305 | ||
286 | /* PMI handler: don't restart this counter */ | 306 | if (state == BTS_STATE_ACTIVE) |
287 | ACCESS_ONCE(bts->started) = 0; | 307 | __bts_event_stop(event, BTS_STATE_STOPPED); |
288 | 308 | ||
289 | __bts_event_stop(event); | 309 | if (state != BTS_STATE_STOPPED) |
310 | buf = perf_get_aux(&bts->handle); | ||
311 | |||
312 | event->hw.state |= PERF_HES_STOPPED; | ||
290 | 313 | ||
291 | if (flags & PERF_EF_UPDATE) { | 314 | if (flags & PERF_EF_UPDATE) { |
292 | bts_update(bts); | 315 | bts_update(bts); |
@@ -296,6 +319,7 @@ static void bts_event_stop(struct perf_event *event, int flags) | |||
296 | bts->handle.head = | 319 | bts->handle.head = |
297 | local_xchg(&buf->data_size, | 320 | local_xchg(&buf->data_size, |
298 | buf->nr_pages << PAGE_SHIFT); | 321 | buf->nr_pages << PAGE_SHIFT); |
322 | |||
299 | perf_aux_output_end(&bts->handle, local_xchg(&buf->data_size, 0), | 323 | perf_aux_output_end(&bts->handle, local_xchg(&buf->data_size, 0), |
300 | !!local_xchg(&buf->lost, 0)); | 324 | !!local_xchg(&buf->lost, 0)); |
301 | } | 325 | } |
@@ -310,8 +334,20 @@ static void bts_event_stop(struct perf_event *event, int flags) | |||
310 | void intel_bts_enable_local(void) | 334 | void intel_bts_enable_local(void) |
311 | { | 335 | { |
312 | struct bts_ctx *bts = this_cpu_ptr(&bts_ctx); | 336 | struct bts_ctx *bts = this_cpu_ptr(&bts_ctx); |
337 | int state = READ_ONCE(bts->state); | ||
338 | |||
339 | /* | ||
340 | * Here we transition from INACTIVE to ACTIVE; | ||
341 | * if we instead are STOPPED from the interrupt handler, | ||
342 | * stay that way. Can't be ACTIVE here though. | ||
343 | */ | ||
344 | if (WARN_ON_ONCE(state == BTS_STATE_ACTIVE)) | ||
345 | return; | ||
346 | |||
347 | if (state == BTS_STATE_STOPPED) | ||
348 | return; | ||
313 | 349 | ||
314 | if (bts->handle.event && bts->started) | 350 | if (bts->handle.event) |
315 | __bts_event_start(bts->handle.event); | 351 | __bts_event_start(bts->handle.event); |
316 | } | 352 | } |
317 | 353 | ||
@@ -319,8 +355,15 @@ void intel_bts_disable_local(void) | |||
319 | { | 355 | { |
320 | struct bts_ctx *bts = this_cpu_ptr(&bts_ctx); | 356 | struct bts_ctx *bts = this_cpu_ptr(&bts_ctx); |
321 | 357 | ||
358 | /* | ||
359 | * Here we transition from ACTIVE to INACTIVE; | ||
360 | * do nothing for STOPPED or INACTIVE. | ||
361 | */ | ||
362 | if (READ_ONCE(bts->state) != BTS_STATE_ACTIVE) | ||
363 | return; | ||
364 | |||
322 | if (bts->handle.event) | 365 | if (bts->handle.event) |
323 | __bts_event_stop(bts->handle.event); | 366 | __bts_event_stop(bts->handle.event, BTS_STATE_INACTIVE); |
324 | } | 367 | } |
325 | 368 | ||
326 | static int | 369 | static int |
@@ -335,8 +378,6 @@ bts_buffer_reset(struct bts_buffer *buf, struct perf_output_handle *handle) | |||
335 | return 0; | 378 | return 0; |
336 | 379 | ||
337 | head = handle->head & ((buf->nr_pages << PAGE_SHIFT) - 1); | 380 | head = handle->head & ((buf->nr_pages << PAGE_SHIFT) - 1); |
338 | if (WARN_ON_ONCE(head != local_read(&buf->head))) | ||
339 | return -EINVAL; | ||
340 | 381 | ||
341 | phys = &buf->buf[buf->cur_buf]; | 382 | phys = &buf->buf[buf->cur_buf]; |
342 | space = phys->offset + phys->displacement + phys->size - head; | 383 | space = phys->offset + phys->displacement + phys->size - head; |
@@ -403,22 +444,37 @@ bts_buffer_reset(struct bts_buffer *buf, struct perf_output_handle *handle) | |||
403 | 444 | ||
404 | int intel_bts_interrupt(void) | 445 | int intel_bts_interrupt(void) |
405 | { | 446 | { |
447 | struct debug_store *ds = this_cpu_ptr(&cpu_hw_events)->ds; | ||
406 | struct bts_ctx *bts = this_cpu_ptr(&bts_ctx); | 448 | struct bts_ctx *bts = this_cpu_ptr(&bts_ctx); |
407 | struct perf_event *event = bts->handle.event; | 449 | struct perf_event *event = bts->handle.event; |
408 | struct bts_buffer *buf; | 450 | struct bts_buffer *buf; |
409 | s64 old_head; | 451 | s64 old_head; |
410 | int err; | 452 | int err = -ENOSPC, handled = 0; |
411 | 453 | ||
412 | if (!event || !bts->started) | 454 | /* |
413 | return 0; | 455 | * The only surefire way of knowing if this NMI is ours is by checking |
456 | * the write ptr against the PMI threshold. | ||
457 | */ | ||
458 | if (ds->bts_index >= ds->bts_interrupt_threshold) | ||
459 | handled = 1; | ||
460 | |||
461 | /* | ||
462 | * this is wrapped in intel_bts_enable_local/intel_bts_disable_local, | ||
463 | * so we can only be INACTIVE or STOPPED | ||
464 | */ | ||
465 | if (READ_ONCE(bts->state) == BTS_STATE_STOPPED) | ||
466 | return handled; | ||
414 | 467 | ||
415 | buf = perf_get_aux(&bts->handle); | 468 | buf = perf_get_aux(&bts->handle); |
469 | if (!buf) | ||
470 | return handled; | ||
471 | |||
416 | /* | 472 | /* |
417 | * Skip snapshot counters: they don't use the interrupt, but | 473 | * Skip snapshot counters: they don't use the interrupt, but |
418 | * there's no other way of telling, because the pointer will | 474 | * there's no other way of telling, because the pointer will |
419 | * keep moving | 475 | * keep moving |
420 | */ | 476 | */ |
421 | if (!buf || buf->snapshot) | 477 | if (buf->snapshot) |
422 | return 0; | 478 | return 0; |
423 | 479 | ||
424 | old_head = local_read(&buf->head); | 480 | old_head = local_read(&buf->head); |
@@ -426,18 +482,27 @@ int intel_bts_interrupt(void) | |||
426 | 482 | ||
427 | /* no new data */ | 483 | /* no new data */ |
428 | if (old_head == local_read(&buf->head)) | 484 | if (old_head == local_read(&buf->head)) |
429 | return 0; | 485 | return handled; |
430 | 486 | ||
431 | perf_aux_output_end(&bts->handle, local_xchg(&buf->data_size, 0), | 487 | perf_aux_output_end(&bts->handle, local_xchg(&buf->data_size, 0), |
432 | !!local_xchg(&buf->lost, 0)); | 488 | !!local_xchg(&buf->lost, 0)); |
433 | 489 | ||
434 | buf = perf_aux_output_begin(&bts->handle, event); | 490 | buf = perf_aux_output_begin(&bts->handle, event); |
435 | if (!buf) | 491 | if (buf) |
436 | return 1; | 492 | err = bts_buffer_reset(buf, &bts->handle); |
493 | |||
494 | if (err) { | ||
495 | WRITE_ONCE(bts->state, BTS_STATE_STOPPED); | ||
437 | 496 | ||
438 | err = bts_buffer_reset(buf, &bts->handle); | 497 | if (buf) { |
439 | if (err) | 498 | /* |
440 | perf_aux_output_end(&bts->handle, 0, false); | 499 | * BTS_STATE_STOPPED should be visible before |
500 | * cleared handle::event | ||
501 | */ | ||
502 | barrier(); | ||
503 | perf_aux_output_end(&bts->handle, 0, false); | ||
504 | } | ||
505 | } | ||
441 | 506 | ||
442 | return 1; | 507 | return 1; |
443 | } | 508 | } |
diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c index 2cbde2f449aa..4c9a79b9cd69 100644 --- a/arch/x86/events/intel/core.c +++ b/arch/x86/events/intel/core.c | |||
@@ -1730,9 +1730,11 @@ static __initconst const u64 knl_hw_cache_extra_regs | |||
1730 | * disabled state if called consecutively. | 1730 | * disabled state if called consecutively. |
1731 | * | 1731 | * |
1732 | * During consecutive calls, the same disable value will be written to related | 1732 | * During consecutive calls, the same disable value will be written to related |
1733 | * registers, so the PMU state remains unchanged. hw.state in | 1733 | * registers, so the PMU state remains unchanged. |
1734 | * intel_bts_disable_local will remain PERF_HES_STOPPED too in consecutive | 1734 | * |
1735 | * calls. | 1735 | * intel_bts events don't coexist with intel PMU's BTS events because of |
1736 | * x86_add_exclusive(x86_lbr_exclusive_lbr); there's no need to keep them | ||
1737 | * disabled around intel PMU's event batching etc, only inside the PMI handler. | ||
1736 | */ | 1738 | */ |
1737 | static void __intel_pmu_disable_all(void) | 1739 | static void __intel_pmu_disable_all(void) |
1738 | { | 1740 | { |
@@ -1742,8 +1744,6 @@ static void __intel_pmu_disable_all(void) | |||
1742 | 1744 | ||
1743 | if (test_bit(INTEL_PMC_IDX_FIXED_BTS, cpuc->active_mask)) | 1745 | if (test_bit(INTEL_PMC_IDX_FIXED_BTS, cpuc->active_mask)) |
1744 | intel_pmu_disable_bts(); | 1746 | intel_pmu_disable_bts(); |
1745 | else | ||
1746 | intel_bts_disable_local(); | ||
1747 | 1747 | ||
1748 | intel_pmu_pebs_disable_all(); | 1748 | intel_pmu_pebs_disable_all(); |
1749 | } | 1749 | } |
@@ -1771,8 +1771,7 @@ static void __intel_pmu_enable_all(int added, bool pmi) | |||
1771 | return; | 1771 | return; |
1772 | 1772 | ||
1773 | intel_pmu_enable_bts(event->hw.config); | 1773 | intel_pmu_enable_bts(event->hw.config); |
1774 | } else | 1774 | } |
1775 | intel_bts_enable_local(); | ||
1776 | } | 1775 | } |
1777 | 1776 | ||
1778 | static void intel_pmu_enable_all(int added) | 1777 | static void intel_pmu_enable_all(int added) |
@@ -2073,6 +2072,7 @@ static int intel_pmu_handle_irq(struct pt_regs *regs) | |||
2073 | */ | 2072 | */ |
2074 | if (!x86_pmu.late_ack) | 2073 | if (!x86_pmu.late_ack) |
2075 | apic_write(APIC_LVTPC, APIC_DM_NMI); | 2074 | apic_write(APIC_LVTPC, APIC_DM_NMI); |
2075 | intel_bts_disable_local(); | ||
2076 | __intel_pmu_disable_all(); | 2076 | __intel_pmu_disable_all(); |
2077 | handled = intel_pmu_drain_bts_buffer(); | 2077 | handled = intel_pmu_drain_bts_buffer(); |
2078 | handled += intel_bts_interrupt(); | 2078 | handled += intel_bts_interrupt(); |
@@ -2172,6 +2172,7 @@ done: | |||
2172 | /* Only restore PMU state when it's active. See x86_pmu_disable(). */ | 2172 | /* Only restore PMU state when it's active. See x86_pmu_disable(). */ |
2173 | if (cpuc->enabled) | 2173 | if (cpuc->enabled) |
2174 | __intel_pmu_enable_all(0, true); | 2174 | __intel_pmu_enable_all(0, true); |
2175 | intel_bts_enable_local(); | ||
2175 | 2176 | ||
2176 | /* | 2177 | /* |
2177 | * Only unmask the NMI after the overflow counters | 2178 | * Only unmask the NMI after the overflow counters |
diff --git a/arch/x86/events/intel/cqm.c b/arch/x86/events/intel/cqm.c index 783c49ddef29..8f82b02934fa 100644 --- a/arch/x86/events/intel/cqm.c +++ b/arch/x86/events/intel/cqm.c | |||
@@ -458,6 +458,11 @@ static void __intel_cqm_event_count(void *info); | |||
458 | static void init_mbm_sample(u32 rmid, u32 evt_type); | 458 | static void init_mbm_sample(u32 rmid, u32 evt_type); |
459 | static void __intel_mbm_event_count(void *info); | 459 | static void __intel_mbm_event_count(void *info); |
460 | 460 | ||
461 | static bool is_cqm_event(int e) | ||
462 | { | ||
463 | return (e == QOS_L3_OCCUP_EVENT_ID); | ||
464 | } | ||
465 | |||
461 | static bool is_mbm_event(int e) | 466 | static bool is_mbm_event(int e) |
462 | { | 467 | { |
463 | return (e >= QOS_MBM_TOTAL_EVENT_ID && e <= QOS_MBM_LOCAL_EVENT_ID); | 468 | return (e >= QOS_MBM_TOTAL_EVENT_ID && e <= QOS_MBM_LOCAL_EVENT_ID); |
@@ -1366,6 +1371,10 @@ static int intel_cqm_event_init(struct perf_event *event) | |||
1366 | (event->attr.config > QOS_MBM_LOCAL_EVENT_ID)) | 1371 | (event->attr.config > QOS_MBM_LOCAL_EVENT_ID)) |
1367 | return -EINVAL; | 1372 | return -EINVAL; |
1368 | 1373 | ||
1374 | if ((is_cqm_event(event->attr.config) && !cqm_enabled) || | ||
1375 | (is_mbm_event(event->attr.config) && !mbm_enabled)) | ||
1376 | return -EINVAL; | ||
1377 | |||
1369 | /* unsupported modes and filters */ | 1378 | /* unsupported modes and filters */ |
1370 | if (event->attr.exclude_user || | 1379 | if (event->attr.exclude_user || |
1371 | event->attr.exclude_kernel || | 1380 | event->attr.exclude_kernel || |
diff --git a/arch/x86/events/intel/ds.c b/arch/x86/events/intel/ds.c index 7ce9f3f669e6..9b983a474253 100644 --- a/arch/x86/events/intel/ds.c +++ b/arch/x86/events/intel/ds.c | |||
@@ -1274,18 +1274,18 @@ static void intel_pmu_drain_pebs_nhm(struct pt_regs *iregs) | |||
1274 | struct pebs_record_nhm *p = at; | 1274 | struct pebs_record_nhm *p = at; |
1275 | u64 pebs_status; | 1275 | u64 pebs_status; |
1276 | 1276 | ||
1277 | /* PEBS v3 has accurate status bits */ | 1277 | pebs_status = p->status & cpuc->pebs_enabled; |
1278 | pebs_status &= (1ULL << x86_pmu.max_pebs_events) - 1; | ||
1279 | |||
1280 | /* PEBS v3 has more accurate status bits */ | ||
1278 | if (x86_pmu.intel_cap.pebs_format >= 3) { | 1281 | if (x86_pmu.intel_cap.pebs_format >= 3) { |
1279 | for_each_set_bit(bit, (unsigned long *)&p->status, | 1282 | for_each_set_bit(bit, (unsigned long *)&pebs_status, |
1280 | MAX_PEBS_EVENTS) | 1283 | x86_pmu.max_pebs_events) |
1281 | counts[bit]++; | 1284 | counts[bit]++; |
1282 | 1285 | ||
1283 | continue; | 1286 | continue; |
1284 | } | 1287 | } |
1285 | 1288 | ||
1286 | pebs_status = p->status & cpuc->pebs_enabled; | ||
1287 | pebs_status &= (1ULL << x86_pmu.max_pebs_events) - 1; | ||
1288 | |||
1289 | /* | 1289 | /* |
1290 | * On some CPUs the PEBS status can be zero when PEBS is | 1290 | * On some CPUs the PEBS status can be zero when PEBS is |
1291 | * racing with clearing of GLOBAL_STATUS. | 1291 | * racing with clearing of GLOBAL_STATUS. |
@@ -1333,8 +1333,11 @@ static void intel_pmu_drain_pebs_nhm(struct pt_regs *iregs) | |||
1333 | continue; | 1333 | continue; |
1334 | 1334 | ||
1335 | event = cpuc->events[bit]; | 1335 | event = cpuc->events[bit]; |
1336 | WARN_ON_ONCE(!event); | 1336 | if (WARN_ON_ONCE(!event)) |
1337 | WARN_ON_ONCE(!event->attr.precise_ip); | 1337 | continue; |
1338 | |||
1339 | if (WARN_ON_ONCE(!event->attr.precise_ip)) | ||
1340 | continue; | ||
1338 | 1341 | ||
1339 | /* log dropped samples number */ | 1342 | /* log dropped samples number */ |
1340 | if (error[bit]) | 1343 | if (error[bit]) |
diff --git a/arch/x86/events/intel/pt.c b/arch/x86/events/intel/pt.c index 04bb5fb5a8d7..861a7d9cb60f 100644 --- a/arch/x86/events/intel/pt.c +++ b/arch/x86/events/intel/pt.c | |||
@@ -1074,6 +1074,11 @@ static void pt_addr_filters_fini(struct perf_event *event) | |||
1074 | event->hw.addr_filters = NULL; | 1074 | event->hw.addr_filters = NULL; |
1075 | } | 1075 | } |
1076 | 1076 | ||
1077 | static inline bool valid_kernel_ip(unsigned long ip) | ||
1078 | { | ||
1079 | return virt_addr_valid(ip) && kernel_ip(ip); | ||
1080 | } | ||
1081 | |||
1077 | static int pt_event_addr_filters_validate(struct list_head *filters) | 1082 | static int pt_event_addr_filters_validate(struct list_head *filters) |
1078 | { | 1083 | { |
1079 | struct perf_addr_filter *filter; | 1084 | struct perf_addr_filter *filter; |
@@ -1081,11 +1086,16 @@ static int pt_event_addr_filters_validate(struct list_head *filters) | |||
1081 | 1086 | ||
1082 | list_for_each_entry(filter, filters, entry) { | 1087 | list_for_each_entry(filter, filters, entry) { |
1083 | /* PT doesn't support single address triggers */ | 1088 | /* PT doesn't support single address triggers */ |
1084 | if (!filter->range) | 1089 | if (!filter->range || !filter->size) |
1085 | return -EOPNOTSUPP; | 1090 | return -EOPNOTSUPP; |
1086 | 1091 | ||
1087 | if (!filter->inode && !kernel_ip(filter->offset)) | 1092 | if (!filter->inode) { |
1088 | return -EINVAL; | 1093 | if (!valid_kernel_ip(filter->offset)) |
1094 | return -EINVAL; | ||
1095 | |||
1096 | if (!valid_kernel_ip(filter->offset + filter->size)) | ||
1097 | return -EINVAL; | ||
1098 | } | ||
1089 | 1099 | ||
1090 | if (++range > pt_cap_get(PT_CAP_num_address_ranges)) | 1100 | if (++range > pt_cap_get(PT_CAP_num_address_ranges)) |
1091 | return -EOPNOTSUPP; | 1101 | return -EOPNOTSUPP; |
@@ -1111,7 +1121,7 @@ static void pt_event_addr_filters_sync(struct perf_event *event) | |||
1111 | } else { | 1121 | } else { |
1112 | /* apply the offset */ | 1122 | /* apply the offset */ |
1113 | msr_a = filter->offset + offs[range]; | 1123 | msr_a = filter->offset + offs[range]; |
1114 | msr_b = filter->size + msr_a; | 1124 | msr_b = filter->size + msr_a - 1; |
1115 | } | 1125 | } |
1116 | 1126 | ||
1117 | filters->filter[range].msr_a = msr_a; | 1127 | filters->filter[range].msr_a = msr_a; |
diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h index a0ae610b9280..2131c4ce7d8a 100644 --- a/arch/x86/include/asm/uaccess.h +++ b/arch/x86/include/asm/uaccess.h | |||
@@ -433,7 +433,11 @@ do { \ | |||
433 | #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \ | 433 | #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \ |
434 | asm volatile("1: mov"itype" %1,%"rtype"0\n" \ | 434 | asm volatile("1: mov"itype" %1,%"rtype"0\n" \ |
435 | "2:\n" \ | 435 | "2:\n" \ |
436 | _ASM_EXTABLE_EX(1b, 2b) \ | 436 | ".section .fixup,\"ax\"\n" \ |
437 | "3:xor"itype" %"rtype"0,%"rtype"0\n" \ | ||
438 | " jmp 2b\n" \ | ||
439 | ".previous\n" \ | ||
440 | _ASM_EXTABLE_EX(1b, 3b) \ | ||
437 | : ltype(x) : "m" (__m(addr))) | 441 | : ltype(x) : "m" (__m(addr))) |
438 | 442 | ||
439 | #define __put_user_nocheck(x, ptr, size) \ | 443 | #define __put_user_nocheck(x, ptr, size) \ |
@@ -697,44 +701,15 @@ unsigned long __must_check _copy_from_user(void *to, const void __user *from, | |||
697 | unsigned long __must_check _copy_to_user(void __user *to, const void *from, | 701 | unsigned long __must_check _copy_to_user(void __user *to, const void *from, |
698 | unsigned n); | 702 | unsigned n); |
699 | 703 | ||
700 | #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS | 704 | extern void __compiletime_error("usercopy buffer size is too small") |
701 | # define copy_user_diag __compiletime_error | 705 | __bad_copy_user(void); |
702 | #else | ||
703 | # define copy_user_diag __compiletime_warning | ||
704 | #endif | ||
705 | |||
706 | extern void copy_user_diag("copy_from_user() buffer size is too small") | ||
707 | copy_from_user_overflow(void); | ||
708 | extern void copy_user_diag("copy_to_user() buffer size is too small") | ||
709 | copy_to_user_overflow(void) __asm__("copy_from_user_overflow"); | ||
710 | |||
711 | #undef copy_user_diag | ||
712 | |||
713 | #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS | ||
714 | |||
715 | extern void | ||
716 | __compiletime_warning("copy_from_user() buffer size is not provably correct") | ||
717 | __copy_from_user_overflow(void) __asm__("copy_from_user_overflow"); | ||
718 | #define __copy_from_user_overflow(size, count) __copy_from_user_overflow() | ||
719 | |||
720 | extern void | ||
721 | __compiletime_warning("copy_to_user() buffer size is not provably correct") | ||
722 | __copy_to_user_overflow(void) __asm__("copy_from_user_overflow"); | ||
723 | #define __copy_to_user_overflow(size, count) __copy_to_user_overflow() | ||
724 | 706 | ||
725 | #else | 707 | static inline void copy_user_overflow(int size, unsigned long count) |
726 | |||
727 | static inline void | ||
728 | __copy_from_user_overflow(int size, unsigned long count) | ||
729 | { | 708 | { |
730 | WARN(1, "Buffer overflow detected (%d < %lu)!\n", size, count); | 709 | WARN(1, "Buffer overflow detected (%d < %lu)!\n", size, count); |
731 | } | 710 | } |
732 | 711 | ||
733 | #define __copy_to_user_overflow __copy_from_user_overflow | 712 | static __always_inline unsigned long __must_check |
734 | |||
735 | #endif | ||
736 | |||
737 | static inline unsigned long __must_check | ||
738 | copy_from_user(void *to, const void __user *from, unsigned long n) | 713 | copy_from_user(void *to, const void __user *from, unsigned long n) |
739 | { | 714 | { |
740 | int sz = __compiletime_object_size(to); | 715 | int sz = __compiletime_object_size(to); |
@@ -743,36 +718,18 @@ copy_from_user(void *to, const void __user *from, unsigned long n) | |||
743 | 718 | ||
744 | kasan_check_write(to, n); | 719 | kasan_check_write(to, n); |
745 | 720 | ||
746 | /* | ||
747 | * While we would like to have the compiler do the checking for us | ||
748 | * even in the non-constant size case, any false positives there are | ||
749 | * a problem (especially when DEBUG_STRICT_USER_COPY_CHECKS, but even | ||
750 | * without - the [hopefully] dangerous looking nature of the warning | ||
751 | * would make people go look at the respecitive call sites over and | ||
752 | * over again just to find that there's no problem). | ||
753 | * | ||
754 | * And there are cases where it's just not realistic for the compiler | ||
755 | * to prove the count to be in range. For example when multiple call | ||
756 | * sites of a helper function - perhaps in different source files - | ||
757 | * all doing proper range checking, yet the helper function not doing | ||
758 | * so again. | ||
759 | * | ||
760 | * Therefore limit the compile time checking to the constant size | ||
761 | * case, and do only runtime checking for non-constant sizes. | ||
762 | */ | ||
763 | |||
764 | if (likely(sz < 0 || sz >= n)) { | 721 | if (likely(sz < 0 || sz >= n)) { |
765 | check_object_size(to, n, false); | 722 | check_object_size(to, n, false); |
766 | n = _copy_from_user(to, from, n); | 723 | n = _copy_from_user(to, from, n); |
767 | } else if (__builtin_constant_p(n)) | 724 | } else if (!__builtin_constant_p(n)) |
768 | copy_from_user_overflow(); | 725 | copy_user_overflow(sz, n); |
769 | else | 726 | else |
770 | __copy_from_user_overflow(sz, n); | 727 | __bad_copy_user(); |
771 | 728 | ||
772 | return n; | 729 | return n; |
773 | } | 730 | } |
774 | 731 | ||
775 | static inline unsigned long __must_check | 732 | static __always_inline unsigned long __must_check |
776 | copy_to_user(void __user *to, const void *from, unsigned long n) | 733 | copy_to_user(void __user *to, const void *from, unsigned long n) |
777 | { | 734 | { |
778 | int sz = __compiletime_object_size(from); | 735 | int sz = __compiletime_object_size(from); |
@@ -781,21 +738,17 @@ copy_to_user(void __user *to, const void *from, unsigned long n) | |||
781 | 738 | ||
782 | might_fault(); | 739 | might_fault(); |
783 | 740 | ||
784 | /* See the comment in copy_from_user() above. */ | ||
785 | if (likely(sz < 0 || sz >= n)) { | 741 | if (likely(sz < 0 || sz >= n)) { |
786 | check_object_size(from, n, true); | 742 | check_object_size(from, n, true); |
787 | n = _copy_to_user(to, from, n); | 743 | n = _copy_to_user(to, from, n); |
788 | } else if (__builtin_constant_p(n)) | 744 | } else if (!__builtin_constant_p(n)) |
789 | copy_to_user_overflow(); | 745 | copy_user_overflow(sz, n); |
790 | else | 746 | else |
791 | __copy_to_user_overflow(sz, n); | 747 | __bad_copy_user(); |
792 | 748 | ||
793 | return n; | 749 | return n; |
794 | } | 750 | } |
795 | 751 | ||
796 | #undef __copy_from_user_overflow | ||
797 | #undef __copy_to_user_overflow | ||
798 | |||
799 | /* | 752 | /* |
800 | * We rely on the nested NMI work to allow atomic faults from the NMI path; the | 753 | * We rely on the nested NMI work to allow atomic faults from the NMI path; the |
801 | * nested NMI paths are careful to preserve CR2. | 754 | * nested NMI paths are careful to preserve CR2. |
diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c index cea4fc19e844..f3e9b2df4b16 100644 --- a/arch/x86/kernel/apic/apic.c +++ b/arch/x86/kernel/apic/apic.c | |||
@@ -1623,6 +1623,9 @@ void __init enable_IR_x2apic(void) | |||
1623 | unsigned long flags; | 1623 | unsigned long flags; |
1624 | int ret, ir_stat; | 1624 | int ret, ir_stat; |
1625 | 1625 | ||
1626 | if (skip_ioapic_setup) | ||
1627 | return; | ||
1628 | |||
1626 | ir_stat = irq_remapping_prepare(); | 1629 | ir_stat = irq_remapping_prepare(); |
1627 | if (ir_stat < 0 && !x2apic_supported()) | 1630 | if (ir_stat < 0 && !x2apic_supported()) |
1628 | return; | 1631 | return; |
@@ -2090,7 +2093,6 @@ int generic_processor_info(int apicid, int version) | |||
2090 | return -EINVAL; | 2093 | return -EINVAL; |
2091 | } | 2094 | } |
2092 | 2095 | ||
2093 | num_processors++; | ||
2094 | if (apicid == boot_cpu_physical_apicid) { | 2096 | if (apicid == boot_cpu_physical_apicid) { |
2095 | /* | 2097 | /* |
2096 | * x86_bios_cpu_apicid is required to have processors listed | 2098 | * x86_bios_cpu_apicid is required to have processors listed |
@@ -2113,10 +2115,13 @@ int generic_processor_info(int apicid, int version) | |||
2113 | 2115 | ||
2114 | pr_warning("APIC: Package limit reached. Processor %d/0x%x ignored.\n", | 2116 | pr_warning("APIC: Package limit reached. Processor %d/0x%x ignored.\n", |
2115 | thiscpu, apicid); | 2117 | thiscpu, apicid); |
2118 | |||
2116 | disabled_cpus++; | 2119 | disabled_cpus++; |
2117 | return -ENOSPC; | 2120 | return -ENOSPC; |
2118 | } | 2121 | } |
2119 | 2122 | ||
2123 | num_processors++; | ||
2124 | |||
2120 | /* | 2125 | /* |
2121 | * Validate version | 2126 | * Validate version |
2122 | */ | 2127 | */ |
diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c index f5c69d8974e1..b81fe2d63e15 100644 --- a/arch/x86/kernel/cpu/amd.c +++ b/arch/x86/kernel/cpu/amd.c | |||
@@ -669,6 +669,17 @@ static void init_amd_gh(struct cpuinfo_x86 *c) | |||
669 | set_cpu_bug(c, X86_BUG_AMD_TLB_MMATCH); | 669 | set_cpu_bug(c, X86_BUG_AMD_TLB_MMATCH); |
670 | } | 670 | } |
671 | 671 | ||
672 | #define MSR_AMD64_DE_CFG 0xC0011029 | ||
673 | |||
674 | static void init_amd_ln(struct cpuinfo_x86 *c) | ||
675 | { | ||
676 | /* | ||
677 | * Apply erratum 665 fix unconditionally so machines without a BIOS | ||
678 | * fix work. | ||
679 | */ | ||
680 | msr_set_bit(MSR_AMD64_DE_CFG, 31); | ||
681 | } | ||
682 | |||
672 | static void init_amd_bd(struct cpuinfo_x86 *c) | 683 | static void init_amd_bd(struct cpuinfo_x86 *c) |
673 | { | 684 | { |
674 | u64 value; | 685 | u64 value; |
@@ -726,6 +737,7 @@ static void init_amd(struct cpuinfo_x86 *c) | |||
726 | case 6: init_amd_k7(c); break; | 737 | case 6: init_amd_k7(c); break; |
727 | case 0xf: init_amd_k8(c); break; | 738 | case 0xf: init_amd_k8(c); break; |
728 | case 0x10: init_amd_gh(c); break; | 739 | case 0x10: init_amd_gh(c); break; |
740 | case 0x12: init_amd_ln(c); break; | ||
729 | case 0x15: init_amd_bd(c); break; | 741 | case 0x15: init_amd_bd(c); break; |
730 | } | 742 | } |
731 | 743 | ||
diff --git a/arch/x86/kernel/cpu/microcode/amd.c b/arch/x86/kernel/cpu/microcode/amd.c index 27a0228c9cae..620ab06bcf45 100644 --- a/arch/x86/kernel/cpu/microcode/amd.c +++ b/arch/x86/kernel/cpu/microcode/amd.c | |||
@@ -54,6 +54,7 @@ static LIST_HEAD(pcache); | |||
54 | */ | 54 | */ |
55 | static u8 *container; | 55 | static u8 *container; |
56 | static size_t container_size; | 56 | static size_t container_size; |
57 | static bool ucode_builtin; | ||
57 | 58 | ||
58 | static u32 ucode_new_rev; | 59 | static u32 ucode_new_rev; |
59 | static u8 amd_ucode_patch[PATCH_MAX_SIZE]; | 60 | static u8 amd_ucode_patch[PATCH_MAX_SIZE]; |
@@ -281,18 +282,22 @@ static bool __init load_builtin_amd_microcode(struct cpio_data *cp, | |||
281 | void __init load_ucode_amd_bsp(unsigned int family) | 282 | void __init load_ucode_amd_bsp(unsigned int family) |
282 | { | 283 | { |
283 | struct cpio_data cp; | 284 | struct cpio_data cp; |
285 | bool *builtin; | ||
284 | void **data; | 286 | void **data; |
285 | size_t *size; | 287 | size_t *size; |
286 | 288 | ||
287 | #ifdef CONFIG_X86_32 | 289 | #ifdef CONFIG_X86_32 |
288 | data = (void **)__pa_nodebug(&ucode_cpio.data); | 290 | data = (void **)__pa_nodebug(&ucode_cpio.data); |
289 | size = (size_t *)__pa_nodebug(&ucode_cpio.size); | 291 | size = (size_t *)__pa_nodebug(&ucode_cpio.size); |
292 | builtin = (bool *)__pa_nodebug(&ucode_builtin); | ||
290 | #else | 293 | #else |
291 | data = &ucode_cpio.data; | 294 | data = &ucode_cpio.data; |
292 | size = &ucode_cpio.size; | 295 | size = &ucode_cpio.size; |
296 | builtin = &ucode_builtin; | ||
293 | #endif | 297 | #endif |
294 | 298 | ||
295 | if (!load_builtin_amd_microcode(&cp, family)) | 299 | *builtin = load_builtin_amd_microcode(&cp, family); |
300 | if (!*builtin) | ||
296 | cp = find_ucode_in_initrd(); | 301 | cp = find_ucode_in_initrd(); |
297 | 302 | ||
298 | if (!(cp.data && cp.size)) | 303 | if (!(cp.data && cp.size)) |
@@ -355,6 +360,7 @@ void load_ucode_amd_ap(void) | |||
355 | unsigned int cpu = smp_processor_id(); | 360 | unsigned int cpu = smp_processor_id(); |
356 | struct equiv_cpu_entry *eq; | 361 | struct equiv_cpu_entry *eq; |
357 | struct microcode_amd *mc; | 362 | struct microcode_amd *mc; |
363 | u8 *cont = container; | ||
358 | u32 rev, eax; | 364 | u32 rev, eax; |
359 | u16 eq_id; | 365 | u16 eq_id; |
360 | 366 | ||
@@ -371,8 +377,12 @@ void load_ucode_amd_ap(void) | |||
371 | if (check_current_patch_level(&rev, false)) | 377 | if (check_current_patch_level(&rev, false)) |
372 | return; | 378 | return; |
373 | 379 | ||
380 | /* Add CONFIG_RANDOMIZE_MEMORY offset. */ | ||
381 | if (!ucode_builtin) | ||
382 | cont += PAGE_OFFSET - __PAGE_OFFSET_BASE; | ||
383 | |||
374 | eax = cpuid_eax(0x00000001); | 384 | eax = cpuid_eax(0x00000001); |
375 | eq = (struct equiv_cpu_entry *)(container + CONTAINER_HDR_SZ); | 385 | eq = (struct equiv_cpu_entry *)(cont + CONTAINER_HDR_SZ); |
376 | 386 | ||
377 | eq_id = find_equiv_id(eq, eax); | 387 | eq_id = find_equiv_id(eq, eax); |
378 | if (!eq_id) | 388 | if (!eq_id) |
@@ -434,6 +444,10 @@ int __init save_microcode_in_initrd_amd(void) | |||
434 | else | 444 | else |
435 | container = cont_va; | 445 | container = cont_va; |
436 | 446 | ||
447 | /* Add CONFIG_RANDOMIZE_MEMORY offset. */ | ||
448 | if (!ucode_builtin) | ||
449 | container += PAGE_OFFSET - __PAGE_OFFSET_BASE; | ||
450 | |||
437 | eax = cpuid_eax(0x00000001); | 451 | eax = cpuid_eax(0x00000001); |
438 | eax = ((eax >> 8) & 0xf) + ((eax >> 20) & 0xff); | 452 | eax = ((eax >> 8) & 0xf) + ((eax >> 20) & 0xff); |
439 | 453 | ||
diff --git a/arch/x86/kernel/kvmclock.c b/arch/x86/kernel/kvmclock.c index 1d39bfbd26bb..3692249a70f1 100644 --- a/arch/x86/kernel/kvmclock.c +++ b/arch/x86/kernel/kvmclock.c | |||
@@ -289,6 +289,7 @@ void __init kvmclock_init(void) | |||
289 | put_cpu(); | 289 | put_cpu(); |
290 | 290 | ||
291 | x86_platform.calibrate_tsc = kvm_get_tsc_khz; | 291 | x86_platform.calibrate_tsc = kvm_get_tsc_khz; |
292 | x86_platform.calibrate_cpu = kvm_get_tsc_khz; | ||
292 | x86_platform.get_wallclock = kvm_get_wallclock; | 293 | x86_platform.get_wallclock = kvm_get_wallclock; |
293 | x86_platform.set_wallclock = kvm_set_wallclock; | 294 | x86_platform.set_wallclock = kvm_set_wallclock; |
294 | #ifdef CONFIG_X86_LOCAL_APIC | 295 | #ifdef CONFIG_X86_LOCAL_APIC |
diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c index ad5bc9578a73..1acfd76e3e26 100644 --- a/arch/x86/kernel/paravirt.c +++ b/arch/x86/kernel/paravirt.c | |||
@@ -56,12 +56,12 @@ asm (".pushsection .entry.text, \"ax\"\n" | |||
56 | ".popsection"); | 56 | ".popsection"); |
57 | 57 | ||
58 | /* identity function, which can be inlined */ | 58 | /* identity function, which can be inlined */ |
59 | u32 _paravirt_ident_32(u32 x) | 59 | u32 notrace _paravirt_ident_32(u32 x) |
60 | { | 60 | { |
61 | return x; | 61 | return x; |
62 | } | 62 | } |
63 | 63 | ||
64 | u64 _paravirt_ident_64(u64 x) | 64 | u64 notrace _paravirt_ident_64(u64 x) |
65 | { | 65 | { |
66 | return x; | 66 | return x; |
67 | } | 67 | } |
diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c index 2a6e84a30a54..4296beb8fdd3 100644 --- a/arch/x86/kernel/smpboot.c +++ b/arch/x86/kernel/smpboot.c | |||
@@ -100,10 +100,11 @@ EXPORT_PER_CPU_SYMBOL(cpu_info); | |||
100 | /* Logical package management. We might want to allocate that dynamically */ | 100 | /* Logical package management. We might want to allocate that dynamically */ |
101 | static int *physical_to_logical_pkg __read_mostly; | 101 | static int *physical_to_logical_pkg __read_mostly; |
102 | static unsigned long *physical_package_map __read_mostly;; | 102 | static unsigned long *physical_package_map __read_mostly;; |
103 | static unsigned long *logical_package_map __read_mostly; | ||
104 | static unsigned int max_physical_pkg_id __read_mostly; | 103 | static unsigned int max_physical_pkg_id __read_mostly; |
105 | unsigned int __max_logical_packages __read_mostly; | 104 | unsigned int __max_logical_packages __read_mostly; |
106 | EXPORT_SYMBOL(__max_logical_packages); | 105 | EXPORT_SYMBOL(__max_logical_packages); |
106 | static unsigned int logical_packages __read_mostly; | ||
107 | static bool logical_packages_frozen __read_mostly; | ||
107 | 108 | ||
108 | /* Maximum number of SMT threads on any online core */ | 109 | /* Maximum number of SMT threads on any online core */ |
109 | int __max_smt_threads __read_mostly; | 110 | int __max_smt_threads __read_mostly; |
@@ -277,14 +278,14 @@ int topology_update_package_map(unsigned int apicid, unsigned int cpu) | |||
277 | if (test_and_set_bit(pkg, physical_package_map)) | 278 | if (test_and_set_bit(pkg, physical_package_map)) |
278 | goto found; | 279 | goto found; |
279 | 280 | ||
280 | new = find_first_zero_bit(logical_package_map, __max_logical_packages); | 281 | if (logical_packages_frozen) { |
281 | if (new >= __max_logical_packages) { | ||
282 | physical_to_logical_pkg[pkg] = -1; | 282 | physical_to_logical_pkg[pkg] = -1; |
283 | pr_warn("APIC(%x) Package %u exceeds logical package map\n", | 283 | pr_warn("APIC(%x) Package %u exceeds logical package max\n", |
284 | apicid, pkg); | 284 | apicid, pkg); |
285 | return -ENOSPC; | 285 | return -ENOSPC; |
286 | } | 286 | } |
287 | set_bit(new, logical_package_map); | 287 | |
288 | new = logical_packages++; | ||
288 | pr_info("APIC(%x) Converting physical %u to logical package %u\n", | 289 | pr_info("APIC(%x) Converting physical %u to logical package %u\n", |
289 | apicid, pkg, new); | 290 | apicid, pkg, new); |
290 | physical_to_logical_pkg[pkg] = new; | 291 | physical_to_logical_pkg[pkg] = new; |
@@ -341,6 +342,7 @@ static void __init smp_init_package_map(void) | |||
341 | } | 342 | } |
342 | 343 | ||
343 | __max_logical_packages = DIV_ROUND_UP(total_cpus, ncpus); | 344 | __max_logical_packages = DIV_ROUND_UP(total_cpus, ncpus); |
345 | logical_packages = 0; | ||
344 | 346 | ||
345 | /* | 347 | /* |
346 | * Possibly larger than what we need as the number of apic ids per | 348 | * Possibly larger than what we need as the number of apic ids per |
@@ -352,10 +354,6 @@ static void __init smp_init_package_map(void) | |||
352 | memset(physical_to_logical_pkg, 0xff, size); | 354 | memset(physical_to_logical_pkg, 0xff, size); |
353 | size = BITS_TO_LONGS(max_physical_pkg_id) * sizeof(unsigned long); | 355 | size = BITS_TO_LONGS(max_physical_pkg_id) * sizeof(unsigned long); |
354 | physical_package_map = kzalloc(size, GFP_KERNEL); | 356 | physical_package_map = kzalloc(size, GFP_KERNEL); |
355 | size = BITS_TO_LONGS(__max_logical_packages) * sizeof(unsigned long); | ||
356 | logical_package_map = kzalloc(size, GFP_KERNEL); | ||
357 | |||
358 | pr_info("Max logical packages: %u\n", __max_logical_packages); | ||
359 | 357 | ||
360 | for_each_present_cpu(cpu) { | 358 | for_each_present_cpu(cpu) { |
361 | unsigned int apicid = apic->cpu_present_to_apicid(cpu); | 359 | unsigned int apicid = apic->cpu_present_to_apicid(cpu); |
@@ -369,6 +367,15 @@ static void __init smp_init_package_map(void) | |||
369 | set_cpu_possible(cpu, false); | 367 | set_cpu_possible(cpu, false); |
370 | set_cpu_present(cpu, false); | 368 | set_cpu_present(cpu, false); |
371 | } | 369 | } |
370 | |||
371 | if (logical_packages > __max_logical_packages) { | ||
372 | pr_warn("Detected more packages (%u), then computed by BIOS data (%u).\n", | ||
373 | logical_packages, __max_logical_packages); | ||
374 | logical_packages_frozen = true; | ||
375 | __max_logical_packages = logical_packages; | ||
376 | } | ||
377 | |||
378 | pr_info("Max logical packages: %u\n", __max_logical_packages); | ||
372 | } | 379 | } |
373 | 380 | ||
374 | void __init smp_store_boot_cpu_info(void) | 381 | void __init smp_store_boot_cpu_info(void) |
diff --git a/arch/x86/kvm/ioapic.c b/arch/x86/kvm/ioapic.c index 5f42d038fcb4..c7220ba94aa7 100644 --- a/arch/x86/kvm/ioapic.c +++ b/arch/x86/kvm/ioapic.c | |||
@@ -109,6 +109,7 @@ static void __rtc_irq_eoi_tracking_restore_one(struct kvm_vcpu *vcpu) | |||
109 | { | 109 | { |
110 | bool new_val, old_val; | 110 | bool new_val, old_val; |
111 | struct kvm_ioapic *ioapic = vcpu->kvm->arch.vioapic; | 111 | struct kvm_ioapic *ioapic = vcpu->kvm->arch.vioapic; |
112 | struct dest_map *dest_map = &ioapic->rtc_status.dest_map; | ||
112 | union kvm_ioapic_redirect_entry *e; | 113 | union kvm_ioapic_redirect_entry *e; |
113 | 114 | ||
114 | e = &ioapic->redirtbl[RTC_GSI]; | 115 | e = &ioapic->redirtbl[RTC_GSI]; |
@@ -117,16 +118,17 @@ static void __rtc_irq_eoi_tracking_restore_one(struct kvm_vcpu *vcpu) | |||
117 | return; | 118 | return; |
118 | 119 | ||
119 | new_val = kvm_apic_pending_eoi(vcpu, e->fields.vector); | 120 | new_val = kvm_apic_pending_eoi(vcpu, e->fields.vector); |
120 | old_val = test_bit(vcpu->vcpu_id, ioapic->rtc_status.dest_map.map); | 121 | old_val = test_bit(vcpu->vcpu_id, dest_map->map); |
121 | 122 | ||
122 | if (new_val == old_val) | 123 | if (new_val == old_val) |
123 | return; | 124 | return; |
124 | 125 | ||
125 | if (new_val) { | 126 | if (new_val) { |
126 | __set_bit(vcpu->vcpu_id, ioapic->rtc_status.dest_map.map); | 127 | __set_bit(vcpu->vcpu_id, dest_map->map); |
128 | dest_map->vectors[vcpu->vcpu_id] = e->fields.vector; | ||
127 | ioapic->rtc_status.pending_eoi++; | 129 | ioapic->rtc_status.pending_eoi++; |
128 | } else { | 130 | } else { |
129 | __clear_bit(vcpu->vcpu_id, ioapic->rtc_status.dest_map.map); | 131 | __clear_bit(vcpu->vcpu_id, dest_map->map); |
130 | ioapic->rtc_status.pending_eoi--; | 132 | ioapic->rtc_status.pending_eoi--; |
131 | rtc_status_pending_eoi_check_valid(ioapic); | 133 | rtc_status_pending_eoi_check_valid(ioapic); |
132 | } | 134 | } |
diff --git a/arch/x86/kvm/pmu_amd.c b/arch/x86/kvm/pmu_amd.c index 39b91127ef07..cd944435dfbd 100644 --- a/arch/x86/kvm/pmu_amd.c +++ b/arch/x86/kvm/pmu_amd.c | |||
@@ -23,8 +23,8 @@ | |||
23 | static struct kvm_event_hw_type_mapping amd_event_mapping[] = { | 23 | static struct kvm_event_hw_type_mapping amd_event_mapping[] = { |
24 | [0] = { 0x76, 0x00, PERF_COUNT_HW_CPU_CYCLES }, | 24 | [0] = { 0x76, 0x00, PERF_COUNT_HW_CPU_CYCLES }, |
25 | [1] = { 0xc0, 0x00, PERF_COUNT_HW_INSTRUCTIONS }, | 25 | [1] = { 0xc0, 0x00, PERF_COUNT_HW_INSTRUCTIONS }, |
26 | [2] = { 0x80, 0x00, PERF_COUNT_HW_CACHE_REFERENCES }, | 26 | [2] = { 0x7d, 0x07, PERF_COUNT_HW_CACHE_REFERENCES }, |
27 | [3] = { 0x81, 0x00, PERF_COUNT_HW_CACHE_MISSES }, | 27 | [3] = { 0x7e, 0x07, PERF_COUNT_HW_CACHE_MISSES }, |
28 | [4] = { 0xc2, 0x00, PERF_COUNT_HW_BRANCH_INSTRUCTIONS }, | 28 | [4] = { 0xc2, 0x00, PERF_COUNT_HW_BRANCH_INSTRUCTIONS }, |
29 | [5] = { 0xc3, 0x00, PERF_COUNT_HW_BRANCH_MISSES }, | 29 | [5] = { 0xc3, 0x00, PERF_COUNT_HW_BRANCH_MISSES }, |
30 | [6] = { 0xd0, 0x00, PERF_COUNT_HW_STALLED_CYCLES_FRONTEND }, | 30 | [6] = { 0xd0, 0x00, PERF_COUNT_HW_STALLED_CYCLES_FRONTEND }, |
diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index a45d8580f91e..5cede40e2552 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c | |||
@@ -422,6 +422,7 @@ struct nested_vmx { | |||
422 | struct list_head vmcs02_pool; | 422 | struct list_head vmcs02_pool; |
423 | int vmcs02_num; | 423 | int vmcs02_num; |
424 | u64 vmcs01_tsc_offset; | 424 | u64 vmcs01_tsc_offset; |
425 | bool change_vmcs01_virtual_x2apic_mode; | ||
425 | /* L2 must run next, and mustn't decide to exit to L1. */ | 426 | /* L2 must run next, and mustn't decide to exit to L1. */ |
426 | bool nested_run_pending; | 427 | bool nested_run_pending; |
427 | /* | 428 | /* |
@@ -435,6 +436,8 @@ struct nested_vmx { | |||
435 | bool pi_pending; | 436 | bool pi_pending; |
436 | u16 posted_intr_nv; | 437 | u16 posted_intr_nv; |
437 | 438 | ||
439 | unsigned long *msr_bitmap; | ||
440 | |||
438 | struct hrtimer preemption_timer; | 441 | struct hrtimer preemption_timer; |
439 | bool preemption_timer_expired; | 442 | bool preemption_timer_expired; |
440 | 443 | ||
@@ -924,7 +927,6 @@ static unsigned long *vmx_msr_bitmap_legacy; | |||
924 | static unsigned long *vmx_msr_bitmap_longmode; | 927 | static unsigned long *vmx_msr_bitmap_longmode; |
925 | static unsigned long *vmx_msr_bitmap_legacy_x2apic; | 928 | static unsigned long *vmx_msr_bitmap_legacy_x2apic; |
926 | static unsigned long *vmx_msr_bitmap_longmode_x2apic; | 929 | static unsigned long *vmx_msr_bitmap_longmode_x2apic; |
927 | static unsigned long *vmx_msr_bitmap_nested; | ||
928 | static unsigned long *vmx_vmread_bitmap; | 930 | static unsigned long *vmx_vmread_bitmap; |
929 | static unsigned long *vmx_vmwrite_bitmap; | 931 | static unsigned long *vmx_vmwrite_bitmap; |
930 | 932 | ||
@@ -2198,6 +2200,12 @@ static void vmx_vcpu_pi_load(struct kvm_vcpu *vcpu, int cpu) | |||
2198 | new.control) != old.control); | 2200 | new.control) != old.control); |
2199 | } | 2201 | } |
2200 | 2202 | ||
2203 | static void decache_tsc_multiplier(struct vcpu_vmx *vmx) | ||
2204 | { | ||
2205 | vmx->current_tsc_ratio = vmx->vcpu.arch.tsc_scaling_ratio; | ||
2206 | vmcs_write64(TSC_MULTIPLIER, vmx->current_tsc_ratio); | ||
2207 | } | ||
2208 | |||
2201 | /* | 2209 | /* |
2202 | * Switches to specified vcpu, until a matching vcpu_put(), but assumes | 2210 | * Switches to specified vcpu, until a matching vcpu_put(), but assumes |
2203 | * vcpu mutex is already taken. | 2211 | * vcpu mutex is already taken. |
@@ -2256,10 +2264,8 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu) | |||
2256 | 2264 | ||
2257 | /* Setup TSC multiplier */ | 2265 | /* Setup TSC multiplier */ |
2258 | if (kvm_has_tsc_control && | 2266 | if (kvm_has_tsc_control && |
2259 | vmx->current_tsc_ratio != vcpu->arch.tsc_scaling_ratio) { | 2267 | vmx->current_tsc_ratio != vcpu->arch.tsc_scaling_ratio) |
2260 | vmx->current_tsc_ratio = vcpu->arch.tsc_scaling_ratio; | 2268 | decache_tsc_multiplier(vmx); |
2261 | vmcs_write64(TSC_MULTIPLIER, vmx->current_tsc_ratio); | ||
2262 | } | ||
2263 | 2269 | ||
2264 | vmx_vcpu_pi_load(vcpu, cpu); | 2270 | vmx_vcpu_pi_load(vcpu, cpu); |
2265 | vmx->host_pkru = read_pkru(); | 2271 | vmx->host_pkru = read_pkru(); |
@@ -2508,7 +2514,7 @@ static void vmx_set_msr_bitmap(struct kvm_vcpu *vcpu) | |||
2508 | unsigned long *msr_bitmap; | 2514 | unsigned long *msr_bitmap; |
2509 | 2515 | ||
2510 | if (is_guest_mode(vcpu)) | 2516 | if (is_guest_mode(vcpu)) |
2511 | msr_bitmap = vmx_msr_bitmap_nested; | 2517 | msr_bitmap = to_vmx(vcpu)->nested.msr_bitmap; |
2512 | else if (cpu_has_secondary_exec_ctrls() && | 2518 | else if (cpu_has_secondary_exec_ctrls() && |
2513 | (vmcs_read32(SECONDARY_VM_EXEC_CONTROL) & | 2519 | (vmcs_read32(SECONDARY_VM_EXEC_CONTROL) & |
2514 | SECONDARY_EXEC_VIRTUALIZE_X2APIC_MODE)) { | 2520 | SECONDARY_EXEC_VIRTUALIZE_X2APIC_MODE)) { |
@@ -6363,13 +6369,6 @@ static __init int hardware_setup(void) | |||
6363 | if (!vmx_msr_bitmap_longmode_x2apic) | 6369 | if (!vmx_msr_bitmap_longmode_x2apic) |
6364 | goto out4; | 6370 | goto out4; |
6365 | 6371 | ||
6366 | if (nested) { | ||
6367 | vmx_msr_bitmap_nested = | ||
6368 | (unsigned long *)__get_free_page(GFP_KERNEL); | ||
6369 | if (!vmx_msr_bitmap_nested) | ||
6370 | goto out5; | ||
6371 | } | ||
6372 | |||
6373 | vmx_vmread_bitmap = (unsigned long *)__get_free_page(GFP_KERNEL); | 6372 | vmx_vmread_bitmap = (unsigned long *)__get_free_page(GFP_KERNEL); |
6374 | if (!vmx_vmread_bitmap) | 6373 | if (!vmx_vmread_bitmap) |
6375 | goto out6; | 6374 | goto out6; |
@@ -6392,8 +6391,6 @@ static __init int hardware_setup(void) | |||
6392 | 6391 | ||
6393 | memset(vmx_msr_bitmap_legacy, 0xff, PAGE_SIZE); | 6392 | memset(vmx_msr_bitmap_legacy, 0xff, PAGE_SIZE); |
6394 | memset(vmx_msr_bitmap_longmode, 0xff, PAGE_SIZE); | 6393 | memset(vmx_msr_bitmap_longmode, 0xff, PAGE_SIZE); |
6395 | if (nested) | ||
6396 | memset(vmx_msr_bitmap_nested, 0xff, PAGE_SIZE); | ||
6397 | 6394 | ||
6398 | if (setup_vmcs_config(&vmcs_config) < 0) { | 6395 | if (setup_vmcs_config(&vmcs_config) < 0) { |
6399 | r = -EIO; | 6396 | r = -EIO; |
@@ -6529,9 +6526,6 @@ out8: | |||
6529 | out7: | 6526 | out7: |
6530 | free_page((unsigned long)vmx_vmread_bitmap); | 6527 | free_page((unsigned long)vmx_vmread_bitmap); |
6531 | out6: | 6528 | out6: |
6532 | if (nested) | ||
6533 | free_page((unsigned long)vmx_msr_bitmap_nested); | ||
6534 | out5: | ||
6535 | free_page((unsigned long)vmx_msr_bitmap_longmode_x2apic); | 6529 | free_page((unsigned long)vmx_msr_bitmap_longmode_x2apic); |
6536 | out4: | 6530 | out4: |
6537 | free_page((unsigned long)vmx_msr_bitmap_longmode); | 6531 | free_page((unsigned long)vmx_msr_bitmap_longmode); |
@@ -6557,8 +6551,6 @@ static __exit void hardware_unsetup(void) | |||
6557 | free_page((unsigned long)vmx_io_bitmap_a); | 6551 | free_page((unsigned long)vmx_io_bitmap_a); |
6558 | free_page((unsigned long)vmx_vmwrite_bitmap); | 6552 | free_page((unsigned long)vmx_vmwrite_bitmap); |
6559 | free_page((unsigned long)vmx_vmread_bitmap); | 6553 | free_page((unsigned long)vmx_vmread_bitmap); |
6560 | if (nested) | ||
6561 | free_page((unsigned long)vmx_msr_bitmap_nested); | ||
6562 | 6554 | ||
6563 | free_kvm_area(); | 6555 | free_kvm_area(); |
6564 | } | 6556 | } |
@@ -6995,16 +6987,21 @@ static int handle_vmon(struct kvm_vcpu *vcpu) | |||
6995 | return 1; | 6987 | return 1; |
6996 | } | 6988 | } |
6997 | 6989 | ||
6990 | if (cpu_has_vmx_msr_bitmap()) { | ||
6991 | vmx->nested.msr_bitmap = | ||
6992 | (unsigned long *)__get_free_page(GFP_KERNEL); | ||
6993 | if (!vmx->nested.msr_bitmap) | ||
6994 | goto out_msr_bitmap; | ||
6995 | } | ||
6996 | |||
6998 | vmx->nested.cached_vmcs12 = kmalloc(VMCS12_SIZE, GFP_KERNEL); | 6997 | vmx->nested.cached_vmcs12 = kmalloc(VMCS12_SIZE, GFP_KERNEL); |
6999 | if (!vmx->nested.cached_vmcs12) | 6998 | if (!vmx->nested.cached_vmcs12) |
7000 | return -ENOMEM; | 6999 | goto out_cached_vmcs12; |
7001 | 7000 | ||
7002 | if (enable_shadow_vmcs) { | 7001 | if (enable_shadow_vmcs) { |
7003 | shadow_vmcs = alloc_vmcs(); | 7002 | shadow_vmcs = alloc_vmcs(); |
7004 | if (!shadow_vmcs) { | 7003 | if (!shadow_vmcs) |
7005 | kfree(vmx->nested.cached_vmcs12); | 7004 | goto out_shadow_vmcs; |
7006 | return -ENOMEM; | ||
7007 | } | ||
7008 | /* mark vmcs as shadow */ | 7005 | /* mark vmcs as shadow */ |
7009 | shadow_vmcs->revision_id |= (1u << 31); | 7006 | shadow_vmcs->revision_id |= (1u << 31); |
7010 | /* init shadow vmcs */ | 7007 | /* init shadow vmcs */ |
@@ -7024,6 +7021,15 @@ static int handle_vmon(struct kvm_vcpu *vcpu) | |||
7024 | skip_emulated_instruction(vcpu); | 7021 | skip_emulated_instruction(vcpu); |
7025 | nested_vmx_succeed(vcpu); | 7022 | nested_vmx_succeed(vcpu); |
7026 | return 1; | 7023 | return 1; |
7024 | |||
7025 | out_shadow_vmcs: | ||
7026 | kfree(vmx->nested.cached_vmcs12); | ||
7027 | |||
7028 | out_cached_vmcs12: | ||
7029 | free_page((unsigned long)vmx->nested.msr_bitmap); | ||
7030 | |||
7031 | out_msr_bitmap: | ||
7032 | return -ENOMEM; | ||
7027 | } | 7033 | } |
7028 | 7034 | ||
7029 | /* | 7035 | /* |
@@ -7098,6 +7104,10 @@ static void free_nested(struct vcpu_vmx *vmx) | |||
7098 | vmx->nested.vmxon = false; | 7104 | vmx->nested.vmxon = false; |
7099 | free_vpid(vmx->nested.vpid02); | 7105 | free_vpid(vmx->nested.vpid02); |
7100 | nested_release_vmcs12(vmx); | 7106 | nested_release_vmcs12(vmx); |
7107 | if (vmx->nested.msr_bitmap) { | ||
7108 | free_page((unsigned long)vmx->nested.msr_bitmap); | ||
7109 | vmx->nested.msr_bitmap = NULL; | ||
7110 | } | ||
7101 | if (enable_shadow_vmcs) | 7111 | if (enable_shadow_vmcs) |
7102 | free_vmcs(vmx->nested.current_shadow_vmcs); | 7112 | free_vmcs(vmx->nested.current_shadow_vmcs); |
7103 | kfree(vmx->nested.cached_vmcs12); | 7113 | kfree(vmx->nested.cached_vmcs12); |
@@ -8419,6 +8429,12 @@ static void vmx_set_virtual_x2apic_mode(struct kvm_vcpu *vcpu, bool set) | |||
8419 | { | 8429 | { |
8420 | u32 sec_exec_control; | 8430 | u32 sec_exec_control; |
8421 | 8431 | ||
8432 | /* Postpone execution until vmcs01 is the current VMCS. */ | ||
8433 | if (is_guest_mode(vcpu)) { | ||
8434 | to_vmx(vcpu)->nested.change_vmcs01_virtual_x2apic_mode = true; | ||
8435 | return; | ||
8436 | } | ||
8437 | |||
8422 | /* | 8438 | /* |
8423 | * There is not point to enable virtualize x2apic without enable | 8439 | * There is not point to enable virtualize x2apic without enable |
8424 | * apicv | 8440 | * apicv |
@@ -9472,8 +9488,10 @@ static inline bool nested_vmx_merge_msr_bitmap(struct kvm_vcpu *vcpu, | |||
9472 | { | 9488 | { |
9473 | int msr; | 9489 | int msr; |
9474 | struct page *page; | 9490 | struct page *page; |
9475 | unsigned long *msr_bitmap; | 9491 | unsigned long *msr_bitmap_l1; |
9492 | unsigned long *msr_bitmap_l0 = to_vmx(vcpu)->nested.msr_bitmap; | ||
9476 | 9493 | ||
9494 | /* This shortcut is ok because we support only x2APIC MSRs so far. */ | ||
9477 | if (!nested_cpu_has_virt_x2apic_mode(vmcs12)) | 9495 | if (!nested_cpu_has_virt_x2apic_mode(vmcs12)) |
9478 | return false; | 9496 | return false; |
9479 | 9497 | ||
@@ -9482,63 +9500,37 @@ static inline bool nested_vmx_merge_msr_bitmap(struct kvm_vcpu *vcpu, | |||
9482 | WARN_ON(1); | 9500 | WARN_ON(1); |
9483 | return false; | 9501 | return false; |
9484 | } | 9502 | } |
9485 | msr_bitmap = (unsigned long *)kmap(page); | 9503 | msr_bitmap_l1 = (unsigned long *)kmap(page); |
9486 | if (!msr_bitmap) { | 9504 | if (!msr_bitmap_l1) { |
9487 | nested_release_page_clean(page); | 9505 | nested_release_page_clean(page); |
9488 | WARN_ON(1); | 9506 | WARN_ON(1); |
9489 | return false; | 9507 | return false; |
9490 | } | 9508 | } |
9491 | 9509 | ||
9510 | memset(msr_bitmap_l0, 0xff, PAGE_SIZE); | ||
9511 | |||
9492 | if (nested_cpu_has_virt_x2apic_mode(vmcs12)) { | 9512 | if (nested_cpu_has_virt_x2apic_mode(vmcs12)) { |
9493 | if (nested_cpu_has_apic_reg_virt(vmcs12)) | 9513 | if (nested_cpu_has_apic_reg_virt(vmcs12)) |
9494 | for (msr = 0x800; msr <= 0x8ff; msr++) | 9514 | for (msr = 0x800; msr <= 0x8ff; msr++) |
9495 | nested_vmx_disable_intercept_for_msr( | 9515 | nested_vmx_disable_intercept_for_msr( |
9496 | msr_bitmap, | 9516 | msr_bitmap_l1, msr_bitmap_l0, |
9497 | vmx_msr_bitmap_nested, | ||
9498 | msr, MSR_TYPE_R); | 9517 | msr, MSR_TYPE_R); |
9499 | /* TPR is allowed */ | 9518 | |
9500 | nested_vmx_disable_intercept_for_msr(msr_bitmap, | 9519 | nested_vmx_disable_intercept_for_msr( |
9501 | vmx_msr_bitmap_nested, | 9520 | msr_bitmap_l1, msr_bitmap_l0, |
9502 | APIC_BASE_MSR + (APIC_TASKPRI >> 4), | 9521 | APIC_BASE_MSR + (APIC_TASKPRI >> 4), |
9503 | MSR_TYPE_R | MSR_TYPE_W); | 9522 | MSR_TYPE_R | MSR_TYPE_W); |
9523 | |||
9504 | if (nested_cpu_has_vid(vmcs12)) { | 9524 | if (nested_cpu_has_vid(vmcs12)) { |
9505 | /* EOI and self-IPI are allowed */ | ||
9506 | nested_vmx_disable_intercept_for_msr( | 9525 | nested_vmx_disable_intercept_for_msr( |
9507 | msr_bitmap, | 9526 | msr_bitmap_l1, msr_bitmap_l0, |
9508 | vmx_msr_bitmap_nested, | ||
9509 | APIC_BASE_MSR + (APIC_EOI >> 4), | 9527 | APIC_BASE_MSR + (APIC_EOI >> 4), |
9510 | MSR_TYPE_W); | 9528 | MSR_TYPE_W); |
9511 | nested_vmx_disable_intercept_for_msr( | 9529 | nested_vmx_disable_intercept_for_msr( |
9512 | msr_bitmap, | 9530 | msr_bitmap_l1, msr_bitmap_l0, |
9513 | vmx_msr_bitmap_nested, | ||
9514 | APIC_BASE_MSR + (APIC_SELF_IPI >> 4), | 9531 | APIC_BASE_MSR + (APIC_SELF_IPI >> 4), |
9515 | MSR_TYPE_W); | 9532 | MSR_TYPE_W); |
9516 | } | 9533 | } |
9517 | } else { | ||
9518 | /* | ||
9519 | * Enable reading intercept of all the x2apic | ||
9520 | * MSRs. We should not rely on vmcs12 to do any | ||
9521 | * optimizations here, it may have been modified | ||
9522 | * by L1. | ||
9523 | */ | ||
9524 | for (msr = 0x800; msr <= 0x8ff; msr++) | ||
9525 | __vmx_enable_intercept_for_msr( | ||
9526 | vmx_msr_bitmap_nested, | ||
9527 | msr, | ||
9528 | MSR_TYPE_R); | ||
9529 | |||
9530 | __vmx_enable_intercept_for_msr( | ||
9531 | vmx_msr_bitmap_nested, | ||
9532 | APIC_BASE_MSR + (APIC_TASKPRI >> 4), | ||
9533 | MSR_TYPE_W); | ||
9534 | __vmx_enable_intercept_for_msr( | ||
9535 | vmx_msr_bitmap_nested, | ||
9536 | APIC_BASE_MSR + (APIC_EOI >> 4), | ||
9537 | MSR_TYPE_W); | ||
9538 | __vmx_enable_intercept_for_msr( | ||
9539 | vmx_msr_bitmap_nested, | ||
9540 | APIC_BASE_MSR + (APIC_SELF_IPI >> 4), | ||
9541 | MSR_TYPE_W); | ||
9542 | } | 9534 | } |
9543 | kunmap(page); | 9535 | kunmap(page); |
9544 | nested_release_page_clean(page); | 9536 | nested_release_page_clean(page); |
@@ -9957,10 +9949,10 @@ static void prepare_vmcs02(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12) | |||
9957 | } | 9949 | } |
9958 | 9950 | ||
9959 | if (cpu_has_vmx_msr_bitmap() && | 9951 | if (cpu_has_vmx_msr_bitmap() && |
9960 | exec_control & CPU_BASED_USE_MSR_BITMAPS) { | 9952 | exec_control & CPU_BASED_USE_MSR_BITMAPS && |
9961 | nested_vmx_merge_msr_bitmap(vcpu, vmcs12); | 9953 | nested_vmx_merge_msr_bitmap(vcpu, vmcs12)) |
9962 | /* MSR_BITMAP will be set by following vmx_set_efer. */ | 9954 | ; /* MSR_BITMAP will be set by following vmx_set_efer. */ |
9963 | } else | 9955 | else |
9964 | exec_control &= ~CPU_BASED_USE_MSR_BITMAPS; | 9956 | exec_control &= ~CPU_BASED_USE_MSR_BITMAPS; |
9965 | 9957 | ||
9966 | /* | 9958 | /* |
@@ -10011,6 +10003,8 @@ static void prepare_vmcs02(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12) | |||
10011 | vmx->nested.vmcs01_tsc_offset + vmcs12->tsc_offset); | 10003 | vmx->nested.vmcs01_tsc_offset + vmcs12->tsc_offset); |
10012 | else | 10004 | else |
10013 | vmcs_write64(TSC_OFFSET, vmx->nested.vmcs01_tsc_offset); | 10005 | vmcs_write64(TSC_OFFSET, vmx->nested.vmcs01_tsc_offset); |
10006 | if (kvm_has_tsc_control) | ||
10007 | decache_tsc_multiplier(vmx); | ||
10014 | 10008 | ||
10015 | if (enable_vpid) { | 10009 | if (enable_vpid) { |
10016 | /* | 10010 | /* |
@@ -10767,6 +10761,14 @@ static void nested_vmx_vmexit(struct kvm_vcpu *vcpu, u32 exit_reason, | |||
10767 | else | 10761 | else |
10768 | vmcs_set_bits(PIN_BASED_VM_EXEC_CONTROL, | 10762 | vmcs_set_bits(PIN_BASED_VM_EXEC_CONTROL, |
10769 | PIN_BASED_VMX_PREEMPTION_TIMER); | 10763 | PIN_BASED_VMX_PREEMPTION_TIMER); |
10764 | if (kvm_has_tsc_control) | ||
10765 | decache_tsc_multiplier(vmx); | ||
10766 | |||
10767 | if (vmx->nested.change_vmcs01_virtual_x2apic_mode) { | ||
10768 | vmx->nested.change_vmcs01_virtual_x2apic_mode = false; | ||
10769 | vmx_set_virtual_x2apic_mode(vcpu, | ||
10770 | vcpu->arch.apic_base & X2APIC_ENABLE); | ||
10771 | } | ||
10770 | 10772 | ||
10771 | /* This is needed for same reason as it was needed in prepare_vmcs02 */ | 10773 | /* This is needed for same reason as it was needed in prepare_vmcs02 */ |
10772 | vmx->host_rsp = 0; | 10774 | vmx->host_rsp = 0; |
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 19f9f9e05c2a..699f8726539a 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c | |||
@@ -2743,16 +2743,16 @@ void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu) | |||
2743 | if (tsc_delta < 0) | 2743 | if (tsc_delta < 0) |
2744 | mark_tsc_unstable("KVM discovered backwards TSC"); | 2744 | mark_tsc_unstable("KVM discovered backwards TSC"); |
2745 | 2745 | ||
2746 | if (kvm_lapic_hv_timer_in_use(vcpu) && | ||
2747 | kvm_x86_ops->set_hv_timer(vcpu, | ||
2748 | kvm_get_lapic_tscdeadline_msr(vcpu))) | ||
2749 | kvm_lapic_switch_to_sw_timer(vcpu); | ||
2750 | if (check_tsc_unstable()) { | 2746 | if (check_tsc_unstable()) { |
2751 | u64 offset = kvm_compute_tsc_offset(vcpu, | 2747 | u64 offset = kvm_compute_tsc_offset(vcpu, |
2752 | vcpu->arch.last_guest_tsc); | 2748 | vcpu->arch.last_guest_tsc); |
2753 | kvm_x86_ops->write_tsc_offset(vcpu, offset); | 2749 | kvm_x86_ops->write_tsc_offset(vcpu, offset); |
2754 | vcpu->arch.tsc_catchup = 1; | 2750 | vcpu->arch.tsc_catchup = 1; |
2755 | } | 2751 | } |
2752 | if (kvm_lapic_hv_timer_in_use(vcpu) && | ||
2753 | kvm_x86_ops->set_hv_timer(vcpu, | ||
2754 | kvm_get_lapic_tscdeadline_msr(vcpu))) | ||
2755 | kvm_lapic_switch_to_sw_timer(vcpu); | ||
2756 | /* | 2756 | /* |
2757 | * On a host with synchronized TSC, there is no need to update | 2757 | * On a host with synchronized TSC, there is no need to update |
2758 | * kvmclock on vcpu->cpu migration | 2758 | * kvmclock on vcpu->cpu migration |
diff --git a/arch/x86/mm/kaslr.c b/arch/x86/mm/kaslr.c index ec8654f117d8..bda8d5eef04d 100644 --- a/arch/x86/mm/kaslr.c +++ b/arch/x86/mm/kaslr.c | |||
@@ -77,7 +77,7 @@ static inline unsigned long get_padding(struct kaslr_memory_region *region) | |||
77 | */ | 77 | */ |
78 | static inline bool kaslr_memory_enabled(void) | 78 | static inline bool kaslr_memory_enabled(void) |
79 | { | 79 | { |
80 | return kaslr_enabled() && !config_enabled(CONFIG_KASAN); | 80 | return kaslr_enabled() && !IS_ENABLED(CONFIG_KASAN); |
81 | } | 81 | } |
82 | 82 | ||
83 | /* Initialize base and padding for each memory region randomized with KASLR */ | 83 | /* Initialize base and padding for each memory region randomized with KASLR */ |
diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c index ecb1b69c1651..170cc4ff057b 100644 --- a/arch/x86/mm/pat.c +++ b/arch/x86/mm/pat.c | |||
@@ -927,9 +927,10 @@ int track_pfn_copy(struct vm_area_struct *vma) | |||
927 | } | 927 | } |
928 | 928 | ||
929 | /* | 929 | /* |
930 | * prot is passed in as a parameter for the new mapping. If the vma has a | 930 | * prot is passed in as a parameter for the new mapping. If the vma has |
931 | * linear pfn mapping for the entire range reserve the entire vma range with | 931 | * a linear pfn mapping for the entire range, or no vma is provided, |
932 | * single reserve_pfn_range call. | 932 | * reserve the entire pfn + size range with single reserve_pfn_range |
933 | * call. | ||
933 | */ | 934 | */ |
934 | int track_pfn_remap(struct vm_area_struct *vma, pgprot_t *prot, | 935 | int track_pfn_remap(struct vm_area_struct *vma, pgprot_t *prot, |
935 | unsigned long pfn, unsigned long addr, unsigned long size) | 936 | unsigned long pfn, unsigned long addr, unsigned long size) |
@@ -938,11 +939,12 @@ int track_pfn_remap(struct vm_area_struct *vma, pgprot_t *prot, | |||
938 | enum page_cache_mode pcm; | 939 | enum page_cache_mode pcm; |
939 | 940 | ||
940 | /* reserve the whole chunk starting from paddr */ | 941 | /* reserve the whole chunk starting from paddr */ |
941 | if (addr == vma->vm_start && size == (vma->vm_end - vma->vm_start)) { | 942 | if (!vma || (addr == vma->vm_start |
943 | && size == (vma->vm_end - vma->vm_start))) { | ||
942 | int ret; | 944 | int ret; |
943 | 945 | ||
944 | ret = reserve_pfn_range(paddr, size, prot, 0); | 946 | ret = reserve_pfn_range(paddr, size, prot, 0); |
945 | if (!ret) | 947 | if (ret == 0 && vma) |
946 | vma->vm_flags |= VM_PAT; | 948 | vma->vm_flags |= VM_PAT; |
947 | return ret; | 949 | return ret; |
948 | } | 950 | } |
@@ -997,7 +999,7 @@ void untrack_pfn(struct vm_area_struct *vma, unsigned long pfn, | |||
997 | resource_size_t paddr; | 999 | resource_size_t paddr; |
998 | unsigned long prot; | 1000 | unsigned long prot; |
999 | 1001 | ||
1000 | if (!(vma->vm_flags & VM_PAT)) | 1002 | if (vma && !(vma->vm_flags & VM_PAT)) |
1001 | return; | 1003 | return; |
1002 | 1004 | ||
1003 | /* free the chunk starting from pfn or the whole chunk */ | 1005 | /* free the chunk starting from pfn or the whole chunk */ |
@@ -1011,7 +1013,8 @@ void untrack_pfn(struct vm_area_struct *vma, unsigned long pfn, | |||
1011 | size = vma->vm_end - vma->vm_start; | 1013 | size = vma->vm_end - vma->vm_start; |
1012 | } | 1014 | } |
1013 | free_pfn_range(paddr, size); | 1015 | free_pfn_range(paddr, size); |
1014 | vma->vm_flags &= ~VM_PAT; | 1016 | if (vma) |
1017 | vma->vm_flags &= ~VM_PAT; | ||
1015 | } | 1018 | } |
1016 | 1019 | ||
1017 | /* | 1020 | /* |
diff --git a/arch/x86/pci/fixup.c b/arch/x86/pci/fixup.c index 837ea36a837d..6d52b94f4bb9 100644 --- a/arch/x86/pci/fixup.c +++ b/arch/x86/pci/fixup.c | |||
@@ -553,15 +553,21 @@ static void twinhead_reserve_killing_zone(struct pci_dev *dev) | |||
553 | DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x27B9, twinhead_reserve_killing_zone); | 553 | DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x27B9, twinhead_reserve_killing_zone); |
554 | 554 | ||
555 | /* | 555 | /* |
556 | * Broadwell EP Home Agent BARs erroneously return non-zero values when read. | 556 | * Device [8086:2fc0] |
557 | * Erratum HSE43 | ||
558 | * CONFIG_TDP_NOMINAL CSR Implemented at Incorrect Offset | ||
559 | * http://www.intel.com/content/www/us/en/processors/xeon/xeon-e5-v3-spec-update.html | ||
557 | * | 560 | * |
558 | * See http://www.intel.com/content/www/us/en/processors/xeon/xeon-e5-v4-spec-update.html | 561 | * Devices [8086:6f60,6fa0,6fc0] |
559 | * entry BDF2. | 562 | * Erratum BDF2 |
563 | * PCI BARs in the Home Agent Will Return Non-Zero Values During Enumeration | ||
564 | * http://www.intel.com/content/www/us/en/processors/xeon/xeon-e5-v4-spec-update.html | ||
560 | */ | 565 | */ |
561 | static void pci_bdwep_bar(struct pci_dev *dev) | 566 | static void pci_invalid_bar(struct pci_dev *dev) |
562 | { | 567 | { |
563 | dev->non_compliant_bars = 1; | 568 | dev->non_compliant_bars = 1; |
564 | } | 569 | } |
565 | DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, 0x6f60, pci_bdwep_bar); | 570 | DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, 0x2fc0, pci_invalid_bar); |
566 | DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, 0x6fa0, pci_bdwep_bar); | 571 | DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, 0x6f60, pci_invalid_bar); |
567 | DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, 0x6fc0, pci_bdwep_bar); | 572 | DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, 0x6fa0, pci_invalid_bar); |
573 | DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, 0x6fc0, pci_invalid_bar); | ||
diff --git a/arch/x86/pci/vmd.c b/arch/x86/pci/vmd.c index b814ca675131..7948be342ee9 100644 --- a/arch/x86/pci/vmd.c +++ b/arch/x86/pci/vmd.c | |||
@@ -41,6 +41,7 @@ static DEFINE_RAW_SPINLOCK(list_lock); | |||
41 | * @node: list item for parent traversal. | 41 | * @node: list item for parent traversal. |
42 | * @rcu: RCU callback item for freeing. | 42 | * @rcu: RCU callback item for freeing. |
43 | * @irq: back pointer to parent. | 43 | * @irq: back pointer to parent. |
44 | * @enabled: true if driver enabled IRQ | ||
44 | * @virq: the virtual IRQ value provided to the requesting driver. | 45 | * @virq: the virtual IRQ value provided to the requesting driver. |
45 | * | 46 | * |
46 | * Every MSI/MSI-X IRQ requested for a device in a VMD domain will be mapped to | 47 | * Every MSI/MSI-X IRQ requested for a device in a VMD domain will be mapped to |
@@ -50,6 +51,7 @@ struct vmd_irq { | |||
50 | struct list_head node; | 51 | struct list_head node; |
51 | struct rcu_head rcu; | 52 | struct rcu_head rcu; |
52 | struct vmd_irq_list *irq; | 53 | struct vmd_irq_list *irq; |
54 | bool enabled; | ||
53 | unsigned int virq; | 55 | unsigned int virq; |
54 | }; | 56 | }; |
55 | 57 | ||
@@ -122,7 +124,9 @@ static void vmd_irq_enable(struct irq_data *data) | |||
122 | unsigned long flags; | 124 | unsigned long flags; |
123 | 125 | ||
124 | raw_spin_lock_irqsave(&list_lock, flags); | 126 | raw_spin_lock_irqsave(&list_lock, flags); |
127 | WARN_ON(vmdirq->enabled); | ||
125 | list_add_tail_rcu(&vmdirq->node, &vmdirq->irq->irq_list); | 128 | list_add_tail_rcu(&vmdirq->node, &vmdirq->irq->irq_list); |
129 | vmdirq->enabled = true; | ||
126 | raw_spin_unlock_irqrestore(&list_lock, flags); | 130 | raw_spin_unlock_irqrestore(&list_lock, flags); |
127 | 131 | ||
128 | data->chip->irq_unmask(data); | 132 | data->chip->irq_unmask(data); |
@@ -136,8 +140,10 @@ static void vmd_irq_disable(struct irq_data *data) | |||
136 | data->chip->irq_mask(data); | 140 | data->chip->irq_mask(data); |
137 | 141 | ||
138 | raw_spin_lock_irqsave(&list_lock, flags); | 142 | raw_spin_lock_irqsave(&list_lock, flags); |
139 | list_del_rcu(&vmdirq->node); | 143 | if (vmdirq->enabled) { |
140 | INIT_LIST_HEAD_RCU(&vmdirq->node); | 144 | list_del_rcu(&vmdirq->node); |
145 | vmdirq->enabled = false; | ||
146 | } | ||
141 | raw_spin_unlock_irqrestore(&list_lock, flags); | 147 | raw_spin_unlock_irqrestore(&list_lock, flags); |
142 | } | 148 | } |
143 | 149 | ||
diff --git a/arch/x86/power/hibernate_64.c b/arch/x86/power/hibernate_64.c index a3e3ccc87138..9634557a5444 100644 --- a/arch/x86/power/hibernate_64.c +++ b/arch/x86/power/hibernate_64.c | |||
@@ -113,7 +113,7 @@ static int set_up_temporary_mappings(void) | |||
113 | return result; | 113 | return result; |
114 | } | 114 | } |
115 | 115 | ||
116 | temp_level4_pgt = (unsigned long)pgd - __PAGE_OFFSET; | 116 | temp_level4_pgt = __pa(pgd); |
117 | return 0; | 117 | return 0; |
118 | } | 118 | } |
119 | 119 | ||
diff --git a/arch/x86/um/ptrace_32.c b/arch/x86/um/ptrace_32.c index ebd4dd6ef73b..a7ef7b131e25 100644 --- a/arch/x86/um/ptrace_32.c +++ b/arch/x86/um/ptrace_32.c | |||
@@ -84,7 +84,10 @@ int putreg(struct task_struct *child, int regno, unsigned long value) | |||
84 | case EAX: | 84 | case EAX: |
85 | case EIP: | 85 | case EIP: |
86 | case UESP: | 86 | case UESP: |
87 | break; | ||
87 | case ORIG_EAX: | 88 | case ORIG_EAX: |
89 | /* Update the syscall number. */ | ||
90 | UPT_SYSCALL_NR(&child->thread.regs.regs) = value; | ||
88 | break; | 91 | break; |
89 | case FS: | 92 | case FS: |
90 | if (value && (value & 3) != 3) | 93 | if (value && (value & 3) != 3) |
diff --git a/arch/x86/um/ptrace_64.c b/arch/x86/um/ptrace_64.c index faab418876ce..0b5c184dd5b3 100644 --- a/arch/x86/um/ptrace_64.c +++ b/arch/x86/um/ptrace_64.c | |||
@@ -78,7 +78,11 @@ int putreg(struct task_struct *child, int regno, unsigned long value) | |||
78 | case RSI: | 78 | case RSI: |
79 | case RDI: | 79 | case RDI: |
80 | case RBP: | 80 | case RBP: |
81 | break; | ||
82 | |||
81 | case ORIG_RAX: | 83 | case ORIG_RAX: |
84 | /* Update the syscall number. */ | ||
85 | UPT_SYSCALL_NR(&child->thread.regs.regs) = value; | ||
82 | break; | 86 | break; |
83 | 87 | ||
84 | case FS: | 88 | case FS: |
diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c index 8ffb089b19a5..b86ebb1a9a7f 100644 --- a/arch/x86/xen/enlighten.c +++ b/arch/x86/xen/enlighten.c | |||
@@ -118,7 +118,7 @@ DEFINE_PER_CPU(struct vcpu_info *, xen_vcpu); | |||
118 | DEFINE_PER_CPU(struct vcpu_info, xen_vcpu_info); | 118 | DEFINE_PER_CPU(struct vcpu_info, xen_vcpu_info); |
119 | 119 | ||
120 | /* Linux <-> Xen vCPU id mapping */ | 120 | /* Linux <-> Xen vCPU id mapping */ |
121 | DEFINE_PER_CPU(int, xen_vcpu_id) = -1; | 121 | DEFINE_PER_CPU(uint32_t, xen_vcpu_id); |
122 | EXPORT_PER_CPU_SYMBOL(xen_vcpu_id); | 122 | EXPORT_PER_CPU_SYMBOL(xen_vcpu_id); |
123 | 123 | ||
124 | enum xen_domain_type xen_domain_type = XEN_NATIVE; | 124 | enum xen_domain_type xen_domain_type = XEN_NATIVE; |