Skip to content

Commit 5f361ea

Browse files
ShivaprasadGBhatnpiggin
authored andcommitted
ppc: spapr: Enable 2nd DAWR on Power10 pSeries machine
As per the PAPR, bit 0 of byte 64 in pa-features property indicates availability of 2nd DAWR registers. i.e. If this bit is set, 2nd DAWR is present, otherwise not. Use KVM_CAP_PPC_DAWR1 capability to find whether kvm supports 2nd DAWR or not. If it's supported, allow user to set the pa-feature bit in guest DT using cap-dawr1 machine capability. Reviewed-by: Nicholas Piggin <[email protected]> Reviewed-by: Harsh Prateek Bora <[email protected]> Signed-off-by: Ravi Bangoria <[email protected]> Signed-off-by: Shivaprasad G Bhat <[email protected]> Message-ID: <[email protected]> Signed-off-by: Nicholas Piggin <[email protected]>
1 parent 7ea6e12 commit 5f361ea

File tree

6 files changed

+96
-11
lines changed

6 files changed

+96
-11
lines changed

hw/ppc/spapr.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ static void spapr_dt_pa_features(SpaprMachineState *spapr,
246246
0x80, 0x00, 0x80, 0x00, 0x80, 0x00, /* 48 - 53 */
247247
/* 54: DecFP, 56: DecI, 58: SHA */
248248
0x80, 0x00, 0x80, 0x00, 0x80, 0x00, /* 54 - 59 */
249-
/* 60: NM atomic, 62: RNG */
249+
/* 60: NM atomic, 62: RNG, 64: DAWR1 (ISA 3.1) */
250250
0x80, 0x00, 0x80, 0x00, 0x00, 0x00, /* 60 - 65 */
251251
/* 68: DEXCR[SBHE|IBRTPDUS|SRAPD|NPHIE|PHIE] */
252252
0x00, 0x00, 0xce, 0x00, 0x00, 0x00, /* 66 - 71 */
@@ -295,6 +295,9 @@ static void spapr_dt_pa_features(SpaprMachineState *spapr,
295295
* in pa-features. So hide it from them. */
296296
pa_features[40 + 2] &= ~0x80; /* Radix MMU */
297297
}
298+
if (spapr_get_cap(spapr, SPAPR_CAP_DAWR1)) {
299+
pa_features[66] |= 0x80;
300+
}
298301

299302
_FDT((fdt_setprop(fdt, offset, "ibm,pa-features", pa_features, pa_size)));
300303
}
@@ -2163,6 +2166,7 @@ static const VMStateDescription vmstate_spapr = {
21632166
&vmstate_spapr_cap_rpt_invalidate,
21642167
&vmstate_spapr_cap_ail_mode_3,
21652168
&vmstate_spapr_cap_nested_papr,
2169+
&vmstate_spapr_cap_dawr1,
21662170
NULL
21672171
}
21682172
};
@@ -4680,6 +4684,7 @@ static void spapr_machine_class_init(ObjectClass *oc, void *data)
46804684
smc->default_caps.caps[SPAPR_CAP_CCF_ASSIST] = SPAPR_CAP_ON;
46814685
smc->default_caps.caps[SPAPR_CAP_FWNMI] = SPAPR_CAP_ON;
46824686
smc->default_caps.caps[SPAPR_CAP_RPT_INVALIDATE] = SPAPR_CAP_OFF;
4687+
smc->default_caps.caps[SPAPR_CAP_DAWR1] = SPAPR_CAP_ON;
46834688

46844689
/*
46854690
* This cap specifies whether the AIL 3 mode for

hw/ppc/spapr_caps.c

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,34 @@ static void cap_ail_mode_3_apply(SpaprMachineState *spapr,
696696
}
697697
}
698698

699+
static void cap_dawr1_apply(SpaprMachineState *spapr, uint8_t val,
700+
Error **errp)
701+
{
702+
ERRP_GUARD();
703+
704+
if (!val) {
705+
return; /* Disable by default */
706+
}
707+
708+
if (!ppc_type_check_compat(MACHINE(spapr)->cpu_type,
709+
CPU_POWERPC_LOGICAL_3_10, 0,
710+
spapr->max_compat_pvr)) {
711+
error_setg(errp, "DAWR1 supported only on POWER10 and later CPUs");
712+
error_append_hint(errp, "Try appending -machine cap-dawr1=off\n");
713+
return;
714+
}
715+
716+
if (kvm_enabled()) {
717+
if (!kvmppc_has_cap_dawr1()) {
718+
error_setg(errp, "DAWR1 not supported by KVM.");
719+
error_append_hint(errp, "Try appending -machine cap-dawr1=off");
720+
} else if (kvmppc_set_cap_dawr1(val) < 0) {
721+
error_setg(errp, "Error enabling cap-dawr1 with KVM.");
722+
error_append_hint(errp, "Try appending -machine cap-dawr1=off");
723+
}
724+
}
725+
}
726+
699727
SpaprCapabilityInfo capability_table[SPAPR_CAP_NUM] = {
700728
[SPAPR_CAP_HTM] = {
701729
.name = "htm",
@@ -831,6 +859,15 @@ SpaprCapabilityInfo capability_table[SPAPR_CAP_NUM] = {
831859
.type = "bool",
832860
.apply = cap_ail_mode_3_apply,
833861
},
862+
[SPAPR_CAP_DAWR1] = {
863+
.name = "dawr1",
864+
.description = "Allow 2nd Data Address Watchpoint Register (DAWR1)",
865+
.index = SPAPR_CAP_DAWR1,
866+
.get = spapr_cap_get_bool,
867+
.set = spapr_cap_set_bool,
868+
.type = "bool",
869+
.apply = cap_dawr1_apply,
870+
},
834871
};
835872

836873
static SpaprCapabilities default_caps_with_cpu(SpaprMachineState *spapr,
@@ -841,6 +878,11 @@ static SpaprCapabilities default_caps_with_cpu(SpaprMachineState *spapr,
841878

842879
caps = smc->default_caps;
843880

881+
if (!ppc_type_check_compat(cputype, CPU_POWERPC_LOGICAL_3_10,
882+
0, spapr->max_compat_pvr)) {
883+
caps.caps[SPAPR_CAP_DAWR1] = SPAPR_CAP_OFF;
884+
}
885+
844886
if (!ppc_type_check_compat(cputype, CPU_POWERPC_LOGICAL_3_00,
845887
0, spapr->max_compat_pvr)) {
846888
caps.caps[SPAPR_CAP_LARGE_DECREMENTER] = SPAPR_CAP_OFF;
@@ -975,6 +1017,7 @@ SPAPR_CAP_MIG_STATE(ccf_assist, SPAPR_CAP_CCF_ASSIST);
9751017
SPAPR_CAP_MIG_STATE(fwnmi, SPAPR_CAP_FWNMI);
9761018
SPAPR_CAP_MIG_STATE(rpt_invalidate, SPAPR_CAP_RPT_INVALIDATE);
9771019
SPAPR_CAP_MIG_STATE(ail_mode_3, SPAPR_CAP_AIL_MODE_3);
1020+
SPAPR_CAP_MIG_STATE(dawr1, SPAPR_CAP_DAWR1);
9781021

9791022
void spapr_caps_init(SpaprMachineState *spapr)
9801023
{

hw/ppc/spapr_hcall.c

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -822,11 +822,12 @@ static target_ulong h_set_mode_resource_set_ciabr(PowerPCCPU *cpu,
822822
return H_SUCCESS;
823823
}
824824

825-
static target_ulong h_set_mode_resource_set_dawr0(PowerPCCPU *cpu,
826-
SpaprMachineState *spapr,
827-
target_ulong mflags,
828-
target_ulong value1,
829-
target_ulong value2)
825+
static target_ulong h_set_mode_resource_set_dawr(PowerPCCPU *cpu,
826+
SpaprMachineState *spapr,
827+
target_ulong mflags,
828+
target_ulong resource,
829+
target_ulong value1,
830+
target_ulong value2)
830831
{
831832
CPUPPCState *env = &cpu->env;
832833

@@ -839,8 +840,15 @@ static target_ulong h_set_mode_resource_set_dawr0(PowerPCCPU *cpu,
839840
return H_P4;
840841
}
841842

842-
ppc_store_dawr0(env, value1);
843-
ppc_store_dawrx0(env, value2);
843+
if (resource == H_SET_MODE_RESOURCE_SET_DAWR0) {
844+
ppc_store_dawr0(env, value1);
845+
ppc_store_dawrx0(env, value2);
846+
} else if (resource == H_SET_MODE_RESOURCE_SET_DAWR1) {
847+
ppc_store_dawr1(env, value1);
848+
ppc_store_dawrx1(env, value2);
849+
} else {
850+
g_assert_not_reached();
851+
}
844852

845853
return H_SUCCESS;
846854
}
@@ -919,8 +927,9 @@ static target_ulong h_set_mode(PowerPCCPU *cpu, SpaprMachineState *spapr,
919927
args[3]);
920928
break;
921929
case H_SET_MODE_RESOURCE_SET_DAWR0:
922-
ret = h_set_mode_resource_set_dawr0(cpu, spapr, args[0], args[2],
923-
args[3]);
930+
case H_SET_MODE_RESOURCE_SET_DAWR1:
931+
ret = h_set_mode_resource_set_dawr(cpu, spapr, args[0], args[1],
932+
args[2], args[3]);
924933
break;
925934
case H_SET_MODE_RESOURCE_LE:
926935
ret = h_set_mode_resource_le(cpu, spapr, args[0], args[2], args[3]);

include/hw/ppc/spapr.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,10 @@ typedef enum {
8383
#define SPAPR_CAP_AIL_MODE_3 0x0C
8484
/* Nested PAPR */
8585
#define SPAPR_CAP_NESTED_PAPR 0x0D
86+
/* DAWR1 */
87+
#define SPAPR_CAP_DAWR1 0x0E
8688
/* Num Caps */
87-
#define SPAPR_CAP_NUM (SPAPR_CAP_NESTED_PAPR + 1)
89+
#define SPAPR_CAP_NUM (SPAPR_CAP_DAWR1 + 1)
8890

8991
/*
9092
* Capability Values
@@ -406,6 +408,7 @@ struct SpaprMachineState {
406408
#define H_SET_MODE_RESOURCE_SET_DAWR0 2
407409
#define H_SET_MODE_RESOURCE_ADDR_TRANS_MODE 3
408410
#define H_SET_MODE_RESOURCE_LE 4
411+
#define H_SET_MODE_RESOURCE_SET_DAWR1 5
409412

410413
/* Flags for H_SET_MODE_RESOURCE_LE */
411414
#define H_SET_MODE_ENDIAN_BIG 0
@@ -1003,6 +1006,7 @@ extern const VMStateDescription vmstate_spapr_cap_fwnmi;
10031006
extern const VMStateDescription vmstate_spapr_cap_rpt_invalidate;
10041007
extern const VMStateDescription vmstate_spapr_cap_ail_mode_3;
10051008
extern const VMStateDescription vmstate_spapr_wdt;
1009+
extern const VMStateDescription vmstate_spapr_cap_dawr1;
10061010

10071011
static inline uint8_t spapr_get_cap(SpaprMachineState *spapr, int cap)
10081012
{

target/ppc/kvm.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ static int cap_large_decr;
9292
static int cap_fwnmi;
9393
static int cap_rpt_invalidate;
9494
static int cap_ail_mode_3;
95+
static int cap_dawr1;
9596

9697
#ifdef CONFIG_PSERIES
9798
static int cap_papr;
@@ -152,6 +153,7 @@ int kvm_arch_init(MachineState *ms, KVMState *s)
152153
cap_ppc_nested_kvm_hv = kvm_vm_check_extension(s, KVM_CAP_PPC_NESTED_HV);
153154
cap_large_decr = kvmppc_get_dec_bits();
154155
cap_fwnmi = kvm_vm_check_extension(s, KVM_CAP_PPC_FWNMI);
156+
cap_dawr1 = kvm_vm_check_extension(s, KVM_CAP_PPC_DAWR1);
155157
/*
156158
* Note: setting it to false because there is not such capability
157159
* in KVM at this moment.
@@ -2114,6 +2116,16 @@ int kvmppc_set_fwnmi(PowerPCCPU *cpu)
21142116
return kvm_vcpu_enable_cap(cs, KVM_CAP_PPC_FWNMI, 0);
21152117
}
21162118

2119+
bool kvmppc_has_cap_dawr1(void)
2120+
{
2121+
return !!cap_dawr1;
2122+
}
2123+
2124+
int kvmppc_set_cap_dawr1(int enable)
2125+
{
2126+
return kvm_vm_enable_cap(kvm_state, KVM_CAP_PPC_DAWR1, 0, enable);
2127+
}
2128+
21172129
int kvmppc_smt_threads(void)
21182130
{
21192131
return cap_ppc_smt ? cap_ppc_smt : 1;

target/ppc/kvm_ppc.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ bool kvmppc_has_cap_htm(void);
6868
bool kvmppc_has_cap_mmu_radix(void);
6969
bool kvmppc_has_cap_mmu_hash_v3(void);
7070
bool kvmppc_has_cap_xive(void);
71+
bool kvmppc_has_cap_dawr1(void);
72+
int kvmppc_set_cap_dawr1(int enable);
7173
int kvmppc_get_cap_safe_cache(void);
7274
int kvmppc_get_cap_safe_bounds_check(void);
7375
int kvmppc_get_cap_safe_indirect_branch(void);
@@ -377,6 +379,16 @@ static inline bool kvmppc_has_cap_xive(void)
377379
return false;
378380
}
379381

382+
static inline bool kvmppc_has_cap_dawr1(void)
383+
{
384+
return false;
385+
}
386+
387+
static inline int kvmppc_set_cap_dawr1(int enable)
388+
{
389+
abort();
390+
}
391+
380392
static inline int kvmppc_get_cap_safe_cache(void)
381393
{
382394
return 0;

0 commit comments

Comments
 (0)