Skip to content

Commit 9ff0251

Browse files
committed
Merge branch 'topic/ppc-kvm' into next
Merge the powerpc KVM topic branch.
2 parents 90e812a + ca8dad0 commit 9ff0251

File tree

14 files changed

+189
-8
lines changed

14 files changed

+189
-8
lines changed

Documentation/arch/powerpc/kvm-nested.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,9 @@ table information.
546546
+--------+-------+----+--------+----------------------------------+
547547
| 0x1052 | 0x08 | RW | T | CTRL |
548548
+--------+-------+----+--------+----------------------------------+
549-
| 0x1053-| | | | Reserved |
549+
| 0x1053 | 0x08 | RW | T | DPDES |
550+
+--------+-------+----+--------+----------------------------------+
551+
| 0x1054-| | | | Reserved |
550552
| 0x1FFF | | | | |
551553
+--------+-------+----+--------+----------------------------------+
552554
| 0x2000 | 0x04 | RW | T | CR |

Documentation/virt/kvm/api.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2439,8 +2439,11 @@ registers, find a list below:
24392439
PPC KVM_REG_PPC_PSSCR 64
24402440
PPC KVM_REG_PPC_DEC_EXPIRY 64
24412441
PPC KVM_REG_PPC_PTCR 64
2442+
PPC KVM_REG_PPC_HASHKEYR 64
2443+
PPC KVM_REG_PPC_HASHPKEYR 64
24422444
PPC KVM_REG_PPC_DAWR1 64
24432445
PPC KVM_REG_PPC_DAWRX1 64
2446+
PPC KVM_REG_PPC_DEXCR 64
24442447
PPC KVM_REG_PPC_TM_GPR0 64
24452448
...
24462449
PPC KVM_REG_PPC_TM_GPR31 64

arch/powerpc/include/asm/guest-state-buffer.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
#define KVMPPC_GSID_HASHKEYR 0x1050
8282
#define KVMPPC_GSID_HASHPKEYR 0x1051
8383
#define KVMPPC_GSID_CTRL 0x1052
84+
#define KVMPPC_GSID_DPDES 0x1053
8485

8586
#define KVMPPC_GSID_CR 0x2000
8687
#define KVMPPC_GSID_PIDR 0x2001
@@ -110,7 +111,7 @@
110111
#define KVMPPC_GSE_META_COUNT (KVMPPC_GSE_META_END - KVMPPC_GSE_META_START + 1)
111112

112113
#define KVMPPC_GSE_DW_REGS_START KVMPPC_GSID_GPR(0)
113-
#define KVMPPC_GSE_DW_REGS_END KVMPPC_GSID_CTRL
114+
#define KVMPPC_GSE_DW_REGS_END KVMPPC_GSID_DPDES
114115
#define KVMPPC_GSE_DW_REGS_COUNT \
115116
(KVMPPC_GSE_DW_REGS_END - KVMPPC_GSE_DW_REGS_START + 1)
116117

arch/powerpc/include/asm/kvm_book3s.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,7 @@ static inline u##size kvmppc_get_##reg(struct kvm_vcpu *vcpu) \
594594

595595

596596
KVMPPC_BOOK3S_VCORE_ACCESSOR(vtb, 64, KVMPPC_GSID_VTB)
597+
KVMPPC_BOOK3S_VCORE_ACCESSOR(dpdes, 64, KVMPPC_GSID_DPDES)
597598
KVMPPC_BOOK3S_VCORE_ACCESSOR_GET(arch_compat, 32, KVMPPC_GSID_LOGICAL_PVR)
598599
KVMPPC_BOOK3S_VCORE_ACCESSOR_GET(lpcr, 64, KVMPPC_GSID_LPCR)
599600
KVMPPC_BOOK3S_VCORE_ACCESSOR_SET(tb_offset, 64, KVMPPC_GSID_TB_OFFSET)

arch/powerpc/include/asm/kvm_book3s_64.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -684,6 +684,11 @@ int kvmhv_nestedv2_set_ptbl_entry(unsigned long lpid, u64 dw0, u64 dw1);
684684
int kvmhv_nestedv2_parse_output(struct kvm_vcpu *vcpu);
685685
int kvmhv_nestedv2_set_vpa(struct kvm_vcpu *vcpu, unsigned long vpa);
686686

687+
int kmvhv_counters_tracepoint_regfunc(void);
688+
void kmvhv_counters_tracepoint_unregfunc(void);
689+
int kvmhv_get_l2_counters_status(void);
690+
void kvmhv_set_l2_counters_status(int cpu, bool status);
691+
687692
#endif /* CONFIG_KVM_BOOK3S_HV_POSSIBLE */
688693

689694
#endif /* __ASM_KVM_BOOK3S_64_H__ */

arch/powerpc/include/asm/kvm_host.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,9 @@ struct kvm_vcpu_arch {
599599
ulong dawrx0;
600600
ulong dawr1;
601601
ulong dawrx1;
602+
ulong dexcr;
603+
ulong hashkeyr;
604+
ulong hashpkeyr;
602605
ulong ciabr;
603606
ulong cfar;
604607
ulong ppr;

arch/powerpc/include/asm/lppaca.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ struct lppaca {
6262
u8 donate_dedicated_cpu; /* Donate dedicated CPU cycles */
6363
u8 fpregs_in_use;
6464
u8 pmcregs_in_use;
65-
u8 reserved8[28];
65+
u8 l2_counters_enable; /* Enable usage of counters for KVM guest */
66+
u8 reserved8[27];
6667
__be64 wait_state_cycles; /* Wait cycles for this proc */
6768
u8 reserved9[28];
6869
__be16 slb_count; /* # of SLBs to maintain */
@@ -92,9 +93,13 @@ struct lppaca {
9293
/* cacheline 4-5 */
9394

9495
__be32 page_ins; /* CMO Hint - # page ins by OS */
95-
u8 reserved12[148];
96+
u8 reserved12[28];
97+
volatile __be64 l1_to_l2_cs_tb;
98+
volatile __be64 l2_to_l1_cs_tb;
99+
volatile __be64 l2_runtime_tb;
100+
u8 reserved13[96];
96101
volatile __be64 dtl_idx; /* Dispatch Trace Log head index */
97-
u8 reserved13[96];
102+
u8 reserved14[96];
98103
} ____cacheline_aligned;
99104

100105
#define lppaca_of(cpu) (*paca_ptrs[cpu]->lppaca_ptr)

arch/powerpc/include/uapi/asm/kvm.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,9 @@ struct kvm_ppc_cpu_char {
645645
#define KVM_REG_PPC_SIER3 (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xc3)
646646
#define KVM_REG_PPC_DAWR1 (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xc4)
647647
#define KVM_REG_PPC_DAWRX1 (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xc5)
648+
#define KVM_REG_PPC_DEXCR (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xc6)
649+
#define KVM_REG_PPC_HASHKEYR (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xc7)
650+
#define KVM_REG_PPC_HASHPKEYR (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xc8)
648651

649652
/* Transactional Memory checkpointed state:
650653
* This is all GPRs, all VSX regs and a subset of SPRs

arch/powerpc/kvm/book3s_hv.c

Lines changed: 101 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2305,7 +2305,7 @@ static int kvmppc_get_one_reg_hv(struct kvm_vcpu *vcpu, u64 id,
23052305
*val = get_reg_val(id, kvmppc_get_siar_hv(vcpu));
23062306
break;
23072307
case KVM_REG_PPC_SDAR:
2308-
*val = get_reg_val(id, kvmppc_get_siar_hv(vcpu));
2308+
*val = get_reg_val(id, kvmppc_get_sdar_hv(vcpu));
23092309
break;
23102310
case KVM_REG_PPC_SIER:
23112311
*val = get_reg_val(id, kvmppc_get_sier_hv(vcpu, 0));
@@ -2349,6 +2349,15 @@ static int kvmppc_get_one_reg_hv(struct kvm_vcpu *vcpu, u64 id,
23492349
case KVM_REG_PPC_DAWRX1:
23502350
*val = get_reg_val(id, kvmppc_get_dawrx1_hv(vcpu));
23512351
break;
2352+
case KVM_REG_PPC_DEXCR:
2353+
*val = get_reg_val(id, kvmppc_get_dexcr_hv(vcpu));
2354+
break;
2355+
case KVM_REG_PPC_HASHKEYR:
2356+
*val = get_reg_val(id, kvmppc_get_hashkeyr_hv(vcpu));
2357+
break;
2358+
case KVM_REG_PPC_HASHPKEYR:
2359+
*val = get_reg_val(id, kvmppc_get_hashpkeyr_hv(vcpu));
2360+
break;
23522361
case KVM_REG_PPC_CIABR:
23532362
*val = get_reg_val(id, kvmppc_get_ciabr_hv(vcpu));
23542363
break;
@@ -2540,7 +2549,7 @@ static int kvmppc_set_one_reg_hv(struct kvm_vcpu *vcpu, u64 id,
25402549
vcpu->arch.mmcrs = set_reg_val(id, *val);
25412550
break;
25422551
case KVM_REG_PPC_MMCR3:
2543-
*val = get_reg_val(id, vcpu->arch.mmcr[3]);
2552+
kvmppc_set_mmcr_hv(vcpu, 3, set_reg_val(id, *val));
25442553
break;
25452554
case KVM_REG_PPC_PMC1 ... KVM_REG_PPC_PMC8:
25462555
i = id - KVM_REG_PPC_PMC1;
@@ -2592,6 +2601,15 @@ static int kvmppc_set_one_reg_hv(struct kvm_vcpu *vcpu, u64 id,
25922601
case KVM_REG_PPC_DAWRX1:
25932602
kvmppc_set_dawrx1_hv(vcpu, set_reg_val(id, *val) & ~DAWRX_HYP);
25942603
break;
2604+
case KVM_REG_PPC_DEXCR:
2605+
kvmppc_set_dexcr_hv(vcpu, set_reg_val(id, *val));
2606+
break;
2607+
case KVM_REG_PPC_HASHKEYR:
2608+
kvmppc_set_hashkeyr_hv(vcpu, set_reg_val(id, *val));
2609+
break;
2610+
case KVM_REG_PPC_HASHPKEYR:
2611+
kvmppc_set_hashpkeyr_hv(vcpu, set_reg_val(id, *val));
2612+
break;
25952613
case KVM_REG_PPC_CIABR:
25962614
kvmppc_set_ciabr_hv(vcpu, set_reg_val(id, *val));
25972615
/* Don't allow setting breakpoints in hypervisor code */
@@ -4108,6 +4126,77 @@ static void vcpu_vpa_increment_dispatch(struct kvm_vcpu *vcpu)
41084126
}
41094127
}
41104128

4129+
/* Helper functions for reading L2's stats from L1's VPA */
4130+
#ifdef CONFIG_PPC_PSERIES
4131+
static DEFINE_PER_CPU(u64, l1_to_l2_cs);
4132+
static DEFINE_PER_CPU(u64, l2_to_l1_cs);
4133+
static DEFINE_PER_CPU(u64, l2_runtime_agg);
4134+
4135+
int kvmhv_get_l2_counters_status(void)
4136+
{
4137+
return firmware_has_feature(FW_FEATURE_LPAR) &&
4138+
get_lppaca()->l2_counters_enable;
4139+
}
4140+
4141+
void kvmhv_set_l2_counters_status(int cpu, bool status)
4142+
{
4143+
if (!firmware_has_feature(FW_FEATURE_LPAR))
4144+
return;
4145+
if (status)
4146+
lppaca_of(cpu).l2_counters_enable = 1;
4147+
else
4148+
lppaca_of(cpu).l2_counters_enable = 0;
4149+
}
4150+
4151+
int kmvhv_counters_tracepoint_regfunc(void)
4152+
{
4153+
int cpu;
4154+
4155+
for_each_present_cpu(cpu) {
4156+
kvmhv_set_l2_counters_status(cpu, true);
4157+
}
4158+
return 0;
4159+
}
4160+
4161+
void kmvhv_counters_tracepoint_unregfunc(void)
4162+
{
4163+
int cpu;
4164+
4165+
for_each_present_cpu(cpu) {
4166+
kvmhv_set_l2_counters_status(cpu, false);
4167+
}
4168+
}
4169+
4170+
static void do_trace_nested_cs_time(struct kvm_vcpu *vcpu)
4171+
{
4172+
struct lppaca *lp = get_lppaca();
4173+
u64 l1_to_l2_ns, l2_to_l1_ns, l2_runtime_ns;
4174+
u64 *l1_to_l2_cs_ptr = this_cpu_ptr(&l1_to_l2_cs);
4175+
u64 *l2_to_l1_cs_ptr = this_cpu_ptr(&l2_to_l1_cs);
4176+
u64 *l2_runtime_agg_ptr = this_cpu_ptr(&l2_runtime_agg);
4177+
4178+
l1_to_l2_ns = tb_to_ns(be64_to_cpu(lp->l1_to_l2_cs_tb));
4179+
l2_to_l1_ns = tb_to_ns(be64_to_cpu(lp->l2_to_l1_cs_tb));
4180+
l2_runtime_ns = tb_to_ns(be64_to_cpu(lp->l2_runtime_tb));
4181+
trace_kvmppc_vcpu_stats(vcpu, l1_to_l2_ns - *l1_to_l2_cs_ptr,
4182+
l2_to_l1_ns - *l2_to_l1_cs_ptr,
4183+
l2_runtime_ns - *l2_runtime_agg_ptr);
4184+
*l1_to_l2_cs_ptr = l1_to_l2_ns;
4185+
*l2_to_l1_cs_ptr = l2_to_l1_ns;
4186+
*l2_runtime_agg_ptr = l2_runtime_ns;
4187+
}
4188+
4189+
#else
4190+
int kvmhv_get_l2_counters_status(void)
4191+
{
4192+
return 0;
4193+
}
4194+
4195+
static void do_trace_nested_cs_time(struct kvm_vcpu *vcpu)
4196+
{
4197+
}
4198+
#endif
4199+
41114200
static int kvmhv_vcpu_entry_nestedv2(struct kvm_vcpu *vcpu, u64 time_limit,
41124201
unsigned long lpcr, u64 *tb)
41134202
{
@@ -4116,6 +4205,11 @@ static int kvmhv_vcpu_entry_nestedv2(struct kvm_vcpu *vcpu, u64 time_limit,
41164205
int trap;
41174206
long rc;
41184207

4208+
if (vcpu->arch.doorbell_request) {
4209+
vcpu->arch.doorbell_request = 0;
4210+
kvmppc_set_dpdes(vcpu, 1);
4211+
}
4212+
41194213
io = &vcpu->arch.nestedv2_io;
41204214

41214215
msr = mfmsr();
@@ -4156,6 +4250,10 @@ static int kvmhv_vcpu_entry_nestedv2(struct kvm_vcpu *vcpu, u64 time_limit,
41564250

41574251
timer_rearm_host_dec(*tb);
41584252

4253+
/* Record context switch and guest_run_time data */
4254+
if (kvmhv_get_l2_counters_status())
4255+
do_trace_nested_cs_time(vcpu);
4256+
41594257
return trap;
41604258
}
41614259

@@ -6519,6 +6617,7 @@ static void kvmppc_book3s_exit_hv(void)
65196617

65206618
module_init(kvmppc_book3s_init_hv);
65216619
module_exit(kvmppc_book3s_exit_hv);
6620+
MODULE_DESCRIPTION("KVM on Book3S (POWER8 and later) in hypervisor mode");
65226621
MODULE_LICENSE("GPL");
65236622
MODULE_ALIAS_MISCDEV(KVM_MINOR);
65246623
MODULE_ALIAS("devname:kvm");

arch/powerpc/kvm/book3s_hv.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ KVMPPC_BOOK3S_HV_VCPU_ACCESSOR(dawr0, 64, KVMPPC_GSID_DAWR0)
116116
KVMPPC_BOOK3S_HV_VCPU_ACCESSOR(dawr1, 64, KVMPPC_GSID_DAWR1)
117117
KVMPPC_BOOK3S_HV_VCPU_ACCESSOR(dawrx0, 64, KVMPPC_GSID_DAWRX0)
118118
KVMPPC_BOOK3S_HV_VCPU_ACCESSOR(dawrx1, 64, KVMPPC_GSID_DAWRX1)
119+
KVMPPC_BOOK3S_HV_VCPU_ACCESSOR(dexcr, 64, KVMPPC_GSID_DEXCR)
120+
KVMPPC_BOOK3S_HV_VCPU_ACCESSOR(hashkeyr, 64, KVMPPC_GSID_HASHKEYR)
121+
KVMPPC_BOOK3S_HV_VCPU_ACCESSOR(hashpkeyr, 64, KVMPPC_GSID_HASHPKEYR)
119122
KVMPPC_BOOK3S_HV_VCPU_ACCESSOR(ciabr, 64, KVMPPC_GSID_CIABR)
120123
KVMPPC_BOOK3S_HV_VCPU_ACCESSOR(wort, 64, KVMPPC_GSID_WORT)
121124
KVMPPC_BOOK3S_HV_VCPU_ACCESSOR(ppr, 64, KVMPPC_GSID_PPR)

0 commit comments

Comments
 (0)