aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Mackerras <paulus@ozlabs.org>2017-10-16 01:11:57 -0400
committerPaul Mackerras <paulus@ozlabs.org>2017-11-01 00:36:35 -0400
commit516f7898ae20d9dd902a85522676055a4de9dc9b (patch)
treea9e2eecb5c4533c685bc019213b1f572afb75c66
parent18c3640cefc7f1c6986b7be48f5013a8d5e394cb (diff)
KVM: PPC: Book3S HV: Allow for running POWER9 host in single-threaded mode
This patch allows for a mode on POWER9 hosts where we control all the threads of a core, much as we do on POWER8. The mode is controlled by a module parameter on the kvm_hv module, called "indep_threads_mode". The normal mode on POWER9 is the "independent threads" mode, with indep_threads_mode=Y, where the host is in SMT4 mode (or in fact any desired SMT mode) and each thread independently enters and exits from KVM guests without reference to what other threads in the core are doing. If indep_threads_mode is set to N at the point when a VM is started, KVM will expect every core that the guest runs on to be in single threaded mode (that is, threads 1, 2 and 3 offline), and will set the flag that prevents secondary threads from coming online. We can still use all four threads; the code that implements dynamic micro-threading on POWER8 will become active in over-commit situations and will allow up to three other VCPUs to be run on the secondary threads of the core whenever a VCPU is run. The reason for wanting this mode is that this will allow us to run HPT guests on a radix host on a POWER9 machine that does not support "mixed mode", that is, having some threads in a core be in HPT mode while other threads are in radix mode. It will also make it possible to implement a "strict threads" mode in future, if desired. Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
-rw-r--r--arch/powerpc/include/asm/kvm_host.h1
-rw-r--r--arch/powerpc/kvm/book3s_hv.c87
-rw-r--r--arch/powerpc/kvm/book3s_hv_rmhandlers.S2
3 files changed, 57 insertions, 33 deletions
diff --git a/arch/powerpc/include/asm/kvm_host.h b/arch/powerpc/include/asm/kvm_host.h
index d831a3883175..3aa5b577cd60 100644
--- a/arch/powerpc/include/asm/kvm_host.h
+++ b/arch/powerpc/include/asm/kvm_host.h
@@ -281,6 +281,7 @@ struct kvm_arch {
281 cpumask_t cpu_in_guest; 281 cpumask_t cpu_in_guest;
282 u8 radix; 282 u8 radix;
283 u8 fwnmi_enabled; 283 u8 fwnmi_enabled;
284 bool threads_indep;
284 pgd_t *pgtable; 285 pgd_t *pgtable;
285 u64 process_table; 286 u64 process_table;
286 struct dentry *debugfs_dir; 287 struct dentry *debugfs_dir;
diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c
index 040e102de4ef..b5fbf7617952 100644
--- a/arch/powerpc/kvm/book3s_hv.c
+++ b/arch/powerpc/kvm/book3s_hv.c
@@ -98,6 +98,10 @@ static int target_smt_mode;
98module_param(target_smt_mode, int, S_IRUGO | S_IWUSR); 98module_param(target_smt_mode, int, S_IRUGO | S_IWUSR);
99MODULE_PARM_DESC(target_smt_mode, "Target threads per core (0 = max)"); 99MODULE_PARM_DESC(target_smt_mode, "Target threads per core (0 = max)");
100 100
101static bool indep_threads_mode = true;
102module_param(indep_threads_mode, bool, S_IRUGO | S_IWUSR);
103MODULE_PARM_DESC(indep_threads_mode, "Independent-threads mode (only on POWER9)");
104
101#ifdef CONFIG_KVM_XICS 105#ifdef CONFIG_KVM_XICS
102static struct kernel_param_ops module_param_ops = { 106static struct kernel_param_ops module_param_ops = {
103 .set = param_set_int, 107 .set = param_set_int,
@@ -1734,9 +1738,9 @@ static int kvmppc_set_one_reg_hv(struct kvm_vcpu *vcpu, u64 id,
1734 * MMU mode (radix or HPT), unfortunately, but since we only support 1738 * MMU mode (radix or HPT), unfortunately, but since we only support
1735 * HPT guests on a HPT host so far, that isn't an impediment yet. 1739 * HPT guests on a HPT host so far, that isn't an impediment yet.
1736 */ 1740 */
1737static int threads_per_vcore(void) 1741static int threads_per_vcore(struct kvm *kvm)
1738{ 1742{
1739 if (cpu_has_feature(CPU_FTR_ARCH_300)) 1743 if (kvm->arch.threads_indep)
1740 return 1; 1744 return 1;
1741 return threads_per_subcore; 1745 return threads_per_subcore;
1742} 1746}
@@ -2228,11 +2232,10 @@ static void kvmppc_start_thread(struct kvm_vcpu *vcpu, struct kvmppc_vcore *vc)
2228 kvmppc_ipi_thread(cpu); 2232 kvmppc_ipi_thread(cpu);
2229} 2233}
2230 2234
2231static void kvmppc_wait_for_nap(void) 2235static void kvmppc_wait_for_nap(int n_threads)
2232{ 2236{
2233 int cpu = smp_processor_id(); 2237 int cpu = smp_processor_id();
2234 int i, loops; 2238 int i, loops;
2235 int n_threads = threads_per_vcore();
2236 2239
2237 if (n_threads <= 1) 2240 if (n_threads <= 1)
2238 return; 2241 return;
@@ -2319,7 +2322,7 @@ static void kvmppc_vcore_preempt(struct kvmppc_vcore *vc)
2319 2322
2320 vc->vcore_state = VCORE_PREEMPT; 2323 vc->vcore_state = VCORE_PREEMPT;
2321 vc->pcpu = smp_processor_id(); 2324 vc->pcpu = smp_processor_id();
2322 if (vc->num_threads < threads_per_vcore()) { 2325 if (vc->num_threads < threads_per_vcore(vc->kvm)) {
2323 spin_lock(&lp->lock); 2326 spin_lock(&lp->lock);
2324 list_add_tail(&vc->preempt_list, &lp->list); 2327 list_add_tail(&vc->preempt_list, &lp->list);
2325 spin_unlock(&lp->lock); 2328 spin_unlock(&lp->lock);
@@ -2357,7 +2360,7 @@ struct core_info {
2357 2360
2358/* 2361/*
2359 * This mapping means subcores 0 and 1 can use threads 0-3 and 4-7 2362 * This mapping means subcores 0 and 1 can use threads 0-3 and 4-7
2360 * respectively in 2-way micro-threading (split-core) mode. 2363 * respectively in 2-way micro-threading (split-core) mode on POWER8.
2361 */ 2364 */
2362static int subcore_thread_map[MAX_SUBCORES] = { 0, 4, 2, 6 }; 2365static int subcore_thread_map[MAX_SUBCORES] = { 0, 4, 2, 6 };
2363 2366
@@ -2373,7 +2376,14 @@ static void init_core_info(struct core_info *cip, struct kvmppc_vcore *vc)
2373 2376
2374static bool subcore_config_ok(int n_subcores, int n_threads) 2377static bool subcore_config_ok(int n_subcores, int n_threads)
2375{ 2378{
2376 /* Can only dynamically split if unsplit to begin with */ 2379 /*
2380 * POWER9 "SMT4" cores are permanently in what is effectively a 4-way split-core
2381 * mode, with one thread per subcore.
2382 */
2383 if (cpu_has_feature(CPU_FTR_ARCH_300))
2384 return n_subcores <= 4 && n_threads == 1;
2385
2386 /* On POWER8, can only dynamically split if unsplit to begin with */
2377 if (n_subcores > 1 && threads_per_subcore < MAX_SMT_THREADS) 2387 if (n_subcores > 1 && threads_per_subcore < MAX_SMT_THREADS)
2378 return false; 2388 return false;
2379 if (n_subcores > MAX_SUBCORES) 2389 if (n_subcores > MAX_SUBCORES)
@@ -2632,6 +2642,7 @@ static noinline void kvmppc_run_core(struct kvmppc_vcore *vc)
2632 int target_threads; 2642 int target_threads;
2633 int controlled_threads; 2643 int controlled_threads;
2634 int trap; 2644 int trap;
2645 bool is_power8;
2635 2646
2636 /* 2647 /*
2637 * Remove from the list any threads that have a signal pending 2648 * Remove from the list any threads that have a signal pending
@@ -2654,7 +2665,7 @@ static noinline void kvmppc_run_core(struct kvmppc_vcore *vc)
2654 * the number of threads per subcore, except on POWER9, 2665 * the number of threads per subcore, except on POWER9,
2655 * where it's 1 because the threads are (mostly) independent. 2666 * where it's 1 because the threads are (mostly) independent.
2656 */ 2667 */
2657 controlled_threads = threads_per_vcore(); 2668 controlled_threads = threads_per_vcore(vc->kvm);
2658 2669
2659 /* 2670 /*
2660 * Make sure we are running on primary threads, and that secondary 2671 * Make sure we are running on primary threads, and that secondary
@@ -2725,32 +2736,40 @@ static noinline void kvmppc_run_core(struct kvmppc_vcore *vc)
2725 cmd_bit = stat_bit = 0; 2736 cmd_bit = stat_bit = 0;
2726 split = core_info.n_subcores; 2737 split = core_info.n_subcores;
2727 sip = NULL; 2738 sip = NULL;
2739 is_power8 = cpu_has_feature(CPU_FTR_ARCH_207S)
2740 && !cpu_has_feature(CPU_FTR_ARCH_300);
2741
2728 if (split > 1) { 2742 if (split > 1) {
2729 /* threads_per_subcore must be MAX_SMT_THREADS (8) here */
2730 if (split == 2 && (dynamic_mt_modes & 2)) {
2731 cmd_bit = HID0_POWER8_1TO2LPAR;
2732 stat_bit = HID0_POWER8_2LPARMODE;
2733 } else {
2734 split = 4;
2735 cmd_bit = HID0_POWER8_1TO4LPAR;
2736 stat_bit = HID0_POWER8_4LPARMODE;
2737 }
2738 subcore_size = MAX_SMT_THREADS / split;
2739 sip = &split_info; 2743 sip = &split_info;
2740 memset(&split_info, 0, sizeof(split_info)); 2744 memset(&split_info, 0, sizeof(split_info));
2741 split_info.rpr = mfspr(SPRN_RPR);
2742 split_info.pmmar = mfspr(SPRN_PMMAR);
2743 split_info.ldbar = mfspr(SPRN_LDBAR);
2744 split_info.subcore_size = subcore_size;
2745 for (sub = 0; sub < core_info.n_subcores; ++sub) 2745 for (sub = 0; sub < core_info.n_subcores; ++sub)
2746 split_info.vc[sub] = core_info.vc[sub]; 2746 split_info.vc[sub] = core_info.vc[sub];
2747
2748 if (is_power8) {
2749 if (split == 2 && (dynamic_mt_modes & 2)) {
2750 cmd_bit = HID0_POWER8_1TO2LPAR;
2751 stat_bit = HID0_POWER8_2LPARMODE;
2752 } else {
2753 split = 4;
2754 cmd_bit = HID0_POWER8_1TO4LPAR;
2755 stat_bit = HID0_POWER8_4LPARMODE;
2756 }
2757 subcore_size = MAX_SMT_THREADS / split;
2758 split_info.rpr = mfspr(SPRN_RPR);
2759 split_info.pmmar = mfspr(SPRN_PMMAR);
2760 split_info.ldbar = mfspr(SPRN_LDBAR);
2761 split_info.subcore_size = subcore_size;
2762 } else {
2763 split_info.subcore_size = 1;
2764 }
2765
2747 /* order writes to split_info before kvm_split_mode pointer */ 2766 /* order writes to split_info before kvm_split_mode pointer */
2748 smp_wmb(); 2767 smp_wmb();
2749 } 2768 }
2750 for (thr = 0; thr < controlled_threads; ++thr) 2769 for (thr = 0; thr < controlled_threads; ++thr)
2751 paca[pcpu + thr].kvm_hstate.kvm_split_mode = sip; 2770 paca[pcpu + thr].kvm_hstate.kvm_split_mode = sip;
2752 2771
2753 /* Initiate micro-threading (split-core) if required */ 2772 /* Initiate micro-threading (split-core) on POWER8 if required */
2754 if (cmd_bit) { 2773 if (cmd_bit) {
2755 unsigned long hid0 = mfspr(SPRN_HID0); 2774 unsigned long hid0 = mfspr(SPRN_HID0);
2756 2775
@@ -2769,7 +2788,7 @@ static noinline void kvmppc_run_core(struct kvmppc_vcore *vc)
2769 /* Start all the threads */ 2788 /* Start all the threads */
2770 active = 0; 2789 active = 0;
2771 for (sub = 0; sub < core_info.n_subcores; ++sub) { 2790 for (sub = 0; sub < core_info.n_subcores; ++sub) {
2772 thr = subcore_thread_map[sub]; 2791 thr = is_power8 ? subcore_thread_map[sub] : sub;
2773 thr0_done = false; 2792 thr0_done = false;
2774 active |= 1 << thr; 2793 active |= 1 << thr;
2775 pvc = core_info.vc[sub]; 2794 pvc = core_info.vc[sub];
@@ -2796,18 +2815,18 @@ static noinline void kvmppc_run_core(struct kvmppc_vcore *vc)
2796 * the vcore pointer in the PACA of the secondaries. 2815 * the vcore pointer in the PACA of the secondaries.
2797 */ 2816 */
2798 smp_mb(); 2817 smp_mb();
2799 if (cmd_bit)
2800 split_info.do_nap = 1; /* ask secondaries to nap when done */
2801 2818
2802 /* 2819 /*
2803 * When doing micro-threading, poke the inactive threads as well. 2820 * When doing micro-threading, poke the inactive threads as well.
2804 * This gets them to the nap instruction after kvm_do_nap, 2821 * This gets them to the nap instruction after kvm_do_nap,
2805 * which reduces the time taken to unsplit later. 2822 * which reduces the time taken to unsplit later.
2806 */ 2823 */
2807 if (split > 1) 2824 if (cmd_bit) {
2825 split_info.do_nap = 1; /* ask secondaries to nap when done */
2808 for (thr = 1; thr < threads_per_subcore; ++thr) 2826 for (thr = 1; thr < threads_per_subcore; ++thr)
2809 if (!(active & (1 << thr))) 2827 if (!(active & (1 << thr)))
2810 kvmppc_ipi_thread(pcpu + thr); 2828 kvmppc_ipi_thread(pcpu + thr);
2829 }
2811 2830
2812 vc->vcore_state = VCORE_RUNNING; 2831 vc->vcore_state = VCORE_RUNNING;
2813 preempt_disable(); 2832 preempt_disable();
@@ -2841,10 +2860,10 @@ static noinline void kvmppc_run_core(struct kvmppc_vcore *vc)
2841 vc->vcore_state = VCORE_EXITING; 2860 vc->vcore_state = VCORE_EXITING;
2842 2861
2843 /* wait for secondary threads to finish writing their state to memory */ 2862 /* wait for secondary threads to finish writing their state to memory */
2844 kvmppc_wait_for_nap(); 2863 kvmppc_wait_for_nap(controlled_threads);
2845 2864
2846 /* Return to whole-core mode if we split the core earlier */ 2865 /* Return to whole-core mode if we split the core earlier */
2847 if (split > 1) { 2866 if (cmd_bit) {
2848 unsigned long hid0 = mfspr(SPRN_HID0); 2867 unsigned long hid0 = mfspr(SPRN_HID0);
2849 unsigned long loops = 0; 2868 unsigned long loops = 0;
2850 2869
@@ -3822,10 +3841,12 @@ static int kvmppc_core_init_vm_hv(struct kvm *kvm)
3822 /* 3841 /*
3823 * Track that we now have a HV mode VM active. This blocks secondary 3842 * Track that we now have a HV mode VM active. This blocks secondary
3824 * CPU threads from coming online. 3843 * CPU threads from coming online.
3825 * On POWER9, we only need to do this for HPT guests on a radix 3844 * On POWER9, we only need to do this if the "indep_threads_mode"
3826 * host, which is not yet supported. 3845 * module parameter has been set to N.
3827 */ 3846 */
3828 if (!cpu_has_feature(CPU_FTR_ARCH_300)) 3847 if (cpu_has_feature(CPU_FTR_ARCH_300))
3848 kvm->arch.threads_indep = indep_threads_mode;
3849 if (!kvm->arch.threads_indep)
3829 kvm_hv_vm_activated(); 3850 kvm_hv_vm_activated();
3830 3851
3831 /* 3852 /*
@@ -3865,7 +3886,7 @@ static void kvmppc_core_destroy_vm_hv(struct kvm *kvm)
3865{ 3886{
3866 debugfs_remove_recursive(kvm->arch.debugfs_dir); 3887 debugfs_remove_recursive(kvm->arch.debugfs_dir);
3867 3888
3868 if (!cpu_has_feature(CPU_FTR_ARCH_300)) 3889 if (!kvm->arch.threads_indep)
3869 kvm_hv_vm_deactivated(); 3890 kvm_hv_vm_deactivated();
3870 3891
3871 kvmppc_free_vcores(kvm); 3892 kvmppc_free_vcores(kvm);
diff --git a/arch/powerpc/kvm/book3s_hv_rmhandlers.S b/arch/powerpc/kvm/book3s_hv_rmhandlers.S
index fd2583ddc9a9..ae6c61641ade 100644
--- a/arch/powerpc/kvm/book3s_hv_rmhandlers.S
+++ b/arch/powerpc/kvm/book3s_hv_rmhandlers.S
@@ -385,6 +385,7 @@ kvm_secondary_got_guest:
385 ld r6, 0(r6) 385 ld r6, 0(r6)
386 mtspr SPRN_HDEC, r6 386 mtspr SPRN_HDEC, r6
387 /* and set per-LPAR registers, if doing dynamic micro-threading */ 387 /* and set per-LPAR registers, if doing dynamic micro-threading */
388BEGIN_FTR_SECTION
388 ld r6, HSTATE_SPLIT_MODE(r13) 389 ld r6, HSTATE_SPLIT_MODE(r13)
389 cmpdi r6, 0 390 cmpdi r6, 0
390 beq 63f 391 beq 63f
@@ -395,6 +396,7 @@ kvm_secondary_got_guest:
395 ld r0, KVM_SPLIT_LDBAR(r6) 396 ld r0, KVM_SPLIT_LDBAR(r6)
396 mtspr SPRN_LDBAR, r0 397 mtspr SPRN_LDBAR, r0
397 isync 398 isync
399END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_300)
39863: 40063:
399 /* Order load of vcpu after load of vcore */ 401 /* Order load of vcpu after load of vcore */
400 lwsync 402 lwsync