* [PATCH v3 0/4] Enable writable for idregs DFR0,PFR0, MMFR{0,1,2}
@ 2023-04-05 17:21 Jing Zhang
2023-04-05 17:21 ` [PATCH v3 1/4] KVM: arm64: Enable writable for ID_AA64DFR0_EL1 Jing Zhang
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Jing Zhang @ 2023-04-05 17:21 UTC (permalink / raw)
To: KVM, KVMARM, ARMLinux, Marc Zyngier, Oliver Upton
Cc: Will Deacon, Paolo Bonzini, James Morse, Alexandru Elisei,
Suzuki K Poulose, Fuad Tabba, Reiji Watanabe,
Raghavendra Rao Ananta, Jing Zhang
This patch series enable userspace writable for below idregs:
ID_AA64DFR0_EL1, ID_DFR0_EL1, ID_AA64PFR0_EL1, ID_AA64MMFR{0, 1, 2}_EL1.
It is based on below series which add infrastructure for writable idregs:
https://lore.kernel.org/all/20230404035344.4043856-1-jingzhangos@google.com
---
* v2 -> v3
- Rebase on v6 of writable idregs series.
- Enable writable for ID_AA64PFR0_EL1 and ID_AA64MMFR{0, 1, 2}_EL1.
* v1 -> v2
- Rebase on latest patch series [1] of enabling writable ID register.
[1] https://lore.kernel.org/all/20230402183735.3011540-1-jingzhangos@google.com
[v1] https://lore.kernel.org/all/20230326011950.405749-1-jingzhangos@google.com
[v2] https://lore.kernel.org/all/20230403003723.3199828-1-jingzhangos@google.com
---
Jing Zhang (4):
KVM: arm64: Enable writable for ID_AA64DFR0_EL1
KVM: arm64: Enable writable for ID_DFR0_EL1
KVM: arm64: Enable writable for ID_AA64PFR0_EL1
KVM: arm64: Enable writable for ID_AA64MMFR{0, 1, 2}_EL1
arch/arm64/kvm/id_regs.c | 68 ++++++++++++++++++++++++++++++++++------
1 file changed, 58 insertions(+), 10 deletions(-)
base-commit: 8ee379b1b7b23b0cffdfc988cbe94108188f68b5
--
2.40.0.348.gf938b09366-goog
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v3 1/4] KVM: arm64: Enable writable for ID_AA64DFR0_EL1
2023-04-05 17:21 [PATCH v3 0/4] Enable writable for idregs DFR0,PFR0, MMFR{0,1,2} Jing Zhang
@ 2023-04-05 17:21 ` Jing Zhang
2023-04-05 17:21 ` [PATCH v3 2/4] KVM: arm64: Enable writable for ID_DFR0_EL1 Jing Zhang
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Jing Zhang @ 2023-04-05 17:21 UTC (permalink / raw)
To: KVM, KVMARM, ARMLinux, Marc Zyngier, Oliver Upton
Cc: Will Deacon, Paolo Bonzini, James Morse, Alexandru Elisei,
Suzuki K Poulose, Fuad Tabba, Reiji Watanabe,
Raghavendra Rao Ananta, Jing Zhang
Since number of context-aware breakpoints must be no more than number
of supported breakpoints according to Arm ARM, return an error if
userspace tries to set CTX_CMPS field to such value.
Signed-off-by: Jing Zhang <jingzhangos@google.com>
---
arch/arm64/kvm/id_regs.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/arch/arm64/kvm/id_regs.c b/arch/arm64/kvm/id_regs.c
index 33968ada29bb..ca26fdabcf66 100644
--- a/arch/arm64/kvm/id_regs.c
+++ b/arch/arm64/kvm/id_regs.c
@@ -336,10 +336,15 @@ static int set_id_aa64dfr0_el1(struct kvm_vcpu *vcpu,
const struct sys_reg_desc *rd,
u64 val)
{
- u8 pmuver, host_pmuver;
+ u8 pmuver, host_pmuver, brps, ctx_cmps;
bool valid_pmu;
int ret;
+ brps = FIELD_GET(ID_AA64DFR0_EL1_BRPs_MASK, val);
+ ctx_cmps = FIELD_GET(ID_AA64DFR0_EL1_CTX_CMPs_MASK, val);
+ if (ctx_cmps > brps)
+ return -EINVAL;
+
host_pmuver = kvm_arm_pmu_get_pmuver_limit();
/*
@@ -592,7 +597,7 @@ const struct sys_reg_desc id_reg_descs[KVM_ARM_ID_REG_NUM] = {
.get_user = get_id_reg,
.set_user = set_id_aa64dfr0_el1,
.reset = read_sanitised_id_aa64dfr0_el1,
- .val = ID_AA64DFR0_EL1_PMUVer_MASK, },
+ .val = GENMASK(63, 0), },
ID_SANITISED(ID_AA64DFR1_EL1),
ID_UNALLOCATED(5, 2),
ID_UNALLOCATED(5, 3),
--
2.40.0.348.gf938b09366-goog
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v3 2/4] KVM: arm64: Enable writable for ID_DFR0_EL1
2023-04-05 17:21 [PATCH v3 0/4] Enable writable for idregs DFR0,PFR0, MMFR{0,1,2} Jing Zhang
2023-04-05 17:21 ` [PATCH v3 1/4] KVM: arm64: Enable writable for ID_AA64DFR0_EL1 Jing Zhang
@ 2023-04-05 17:21 ` Jing Zhang
2023-04-05 17:21 ` [PATCH v3 3/4] KVM: arm64: Enable writable for ID_AA64PFR0_EL1 Jing Zhang
2023-04-05 17:21 ` [PATCH v3 4/4] KVM: arm64: Enable writable for ID_AA64MMFR{0, 1, 2}_EL1 Jing Zhang
3 siblings, 0 replies; 5+ messages in thread
From: Jing Zhang @ 2023-04-05 17:21 UTC (permalink / raw)
To: KVM, KVMARM, ARMLinux, Marc Zyngier, Oliver Upton
Cc: Will Deacon, Paolo Bonzini, James Morse, Alexandru Elisei,
Suzuki K Poulose, Fuad Tabba, Reiji Watanabe,
Raghavendra Rao Ananta, Jing Zhang
All valid fields in ID_DFR0_EL1 are writable from usrespace with this
change.
Signed-off-by: Jing Zhang <jingzhangos@google.com>
---
arch/arm64/kvm/id_regs.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/arm64/kvm/id_regs.c b/arch/arm64/kvm/id_regs.c
index ca26fdabcf66..11d3a1d46ee5 100644
--- a/arch/arm64/kvm/id_regs.c
+++ b/arch/arm64/kvm/id_regs.c
@@ -548,7 +548,7 @@ const struct sys_reg_desc id_reg_descs[KVM_ARM_ID_REG_NUM] = {
.set_user = set_id_dfr0_el1,
.visibility = aa32_id_visibility,
.reset = read_sanitised_id_dfr0_el1,
- .val = ID_DFR0_EL1_PerfMon_MASK, },
+ .val = GENMASK(63, 0), },
ID_HIDDEN(ID_AFR0_EL1),
AA32_ID_SANITISED(ID_MMFR0_EL1),
AA32_ID_SANITISED(ID_MMFR1_EL1),
--
2.40.0.348.gf938b09366-goog
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v3 3/4] KVM: arm64: Enable writable for ID_AA64PFR0_EL1
2023-04-05 17:21 [PATCH v3 0/4] Enable writable for idregs DFR0,PFR0, MMFR{0,1,2} Jing Zhang
2023-04-05 17:21 ` [PATCH v3 1/4] KVM: arm64: Enable writable for ID_AA64DFR0_EL1 Jing Zhang
2023-04-05 17:21 ` [PATCH v3 2/4] KVM: arm64: Enable writable for ID_DFR0_EL1 Jing Zhang
@ 2023-04-05 17:21 ` Jing Zhang
2023-04-05 17:21 ` [PATCH v3 4/4] KVM: arm64: Enable writable for ID_AA64MMFR{0, 1, 2}_EL1 Jing Zhang
3 siblings, 0 replies; 5+ messages in thread
From: Jing Zhang @ 2023-04-05 17:21 UTC (permalink / raw)
To: KVM, KVMARM, ARMLinux, Marc Zyngier, Oliver Upton
Cc: Will Deacon, Paolo Bonzini, James Morse, Alexandru Elisei,
Suzuki K Poulose, Fuad Tabba, Reiji Watanabe,
Raghavendra Rao Ananta, Jing Zhang
Return an error if userspace tries to set SVE field of the register
to a value that conflicts with SVE configuration for the guest.
SIMD/FP/SVE fields of the requested value are validated according to
Arm ARM.
Signed-off-by: Jing Zhang <jingzhangos@google.com>
---
arch/arm64/kvm/id_regs.c | 21 ++++++++++++++++++++-
1 file changed, 20 insertions(+), 1 deletion(-)
diff --git a/arch/arm64/kvm/id_regs.c b/arch/arm64/kvm/id_regs.c
index 11d3a1d46ee5..20d1a2d2a0cc 100644
--- a/arch/arm64/kvm/id_regs.c
+++ b/arch/arm64/kvm/id_regs.c
@@ -283,6 +283,9 @@ static u64 read_sanitised_id_aa64pfr0_el1(struct kvm_vcpu *vcpu,
val &= ~ARM64_FEATURE_MASK(ID_AA64PFR0_EL1_AMU);
+ if (!system_supports_sve())
+ val &= ~ARM64_FEATURE_MASK(ID_AA64PFR0_EL1_SVE);
+
return val;
}
@@ -291,6 +294,22 @@ static int set_id_aa64pfr0_el1(struct kvm_vcpu *vcpu,
u64 val)
{
u8 csv2, csv3;
+ int fp, simd;
+ bool has_sve = id_aa64pfr0_sve(val);
+
+ simd = cpuid_feature_extract_signed_field(val, ID_AA64PFR0_EL1_AdvSIMD_SHIFT);
+ fp = cpuid_feature_extract_signed_field(val, ID_AA64PFR0_EL1_FP_SHIFT);
+ /* AdvSIMD field must have the same value as FP field */
+ if (simd != fp)
+ return -EINVAL;
+
+ /* fp must be supported when sve is supported */
+ if (has_sve && (fp < 0))
+ return -EINVAL;
+
+ /* Check if there is a conflict with a request via KVM_ARM_VCPU_INIT */
+ if (vcpu_has_sve(vcpu) ^ has_sve)
+ return -EPERM;
/*
* Allow AA64PFR0_EL1.CSV2 to be set from userspace as long as
@@ -582,7 +601,7 @@ const struct sys_reg_desc id_reg_descs[KVM_ARM_ID_REG_NUM] = {
.get_user = get_id_reg,
.set_user = set_id_aa64pfr0_el1,
.reset = read_sanitised_id_aa64pfr0_el1,
- .val = ID_AA64PFR0_EL1_CSV2_MASK | ID_AA64PFR0_EL1_CSV3_MASK, },
+ .val = GENMASK(63, 0), },
ID_SANITISED(ID_AA64PFR1_EL1),
ID_UNALLOCATED(4, 2),
ID_UNALLOCATED(4, 3),
--
2.40.0.348.gf938b09366-goog
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v3 4/4] KVM: arm64: Enable writable for ID_AA64MMFR{0, 1, 2}_EL1
2023-04-05 17:21 [PATCH v3 0/4] Enable writable for idregs DFR0,PFR0, MMFR{0,1,2} Jing Zhang
` (2 preceding siblings ...)
2023-04-05 17:21 ` [PATCH v3 3/4] KVM: arm64: Enable writable for ID_AA64PFR0_EL1 Jing Zhang
@ 2023-04-05 17:21 ` Jing Zhang
3 siblings, 0 replies; 5+ messages in thread
From: Jing Zhang @ 2023-04-05 17:21 UTC (permalink / raw)
To: KVM, KVMARM, ARMLinux, Marc Zyngier, Oliver Upton
Cc: Will Deacon, Paolo Bonzini, James Morse, Alexandru Elisei,
Suzuki K Poulose, Fuad Tabba, Reiji Watanabe,
Raghavendra Rao Ananta, Jing Zhang
Enable writable from userspace for ID_AA64MMFR{0, 1, 2}_EL1.
Added a macro for defining general writable idregs.
Signed-off-by: Jing Zhang <jingzhangos@google.com>
---
arch/arm64/kvm/id_regs.c | 36 ++++++++++++++++++++++++++++++------
1 file changed, 30 insertions(+), 6 deletions(-)
diff --git a/arch/arm64/kvm/id_regs.c b/arch/arm64/kvm/id_regs.c
index 20d1a2d2a0cc..29e344d3c8be 100644
--- a/arch/arm64/kvm/id_regs.c
+++ b/arch/arm64/kvm/id_regs.c
@@ -164,9 +164,6 @@ u64 kvm_arm_read_id_reg(const struct kvm_vcpu *vcpu, u32 id)
val |= FIELD_PREP(ARM64_FEATURE_MASK(ID_DFR0_EL1_PerfMon),
pmuver_to_perfmon(vcpu_pmuver(vcpu)));
break;
- case SYS_ID_AA64MMFR2_EL1:
- val &= ~ID_AA64MMFR2_EL1_CCIDX_MASK;
- break;
case SYS_ID_MMFR4_EL1:
val &= ~ARM64_FEATURE_MASK(ID_MMFR4_EL1_CCIDX);
break;
@@ -488,6 +485,18 @@ static int set_id_dfr0_el1(struct kvm_vcpu *vcpu,
return 0;
}
+static u64 read_sanitised_id_aa64mmfr2_el1(struct kvm_vcpu *vcpu,
+ const struct sys_reg_desc *rd)
+{
+ u64 val;
+ u32 id = reg_to_encoding(rd);
+
+ val = read_sanitised_ftr_reg(id);
+ val &= ~ID_AA64MMFR2_EL1_CCIDX_MASK;
+
+ return val;
+}
+
/*
* Since reset() callback and field val are not used for idregs, they will be
* used for specific purposes for idregs.
@@ -510,6 +519,16 @@ static int set_id_dfr0_el1(struct kvm_vcpu *vcpu,
.val = 0, \
}
+#define ID_SANITISED_WRITABLE(name) { \
+ SYS_DESC(SYS_##name), \
+ .access = access_id_reg, \
+ .get_user = get_id_reg, \
+ .set_user = set_id_reg, \
+ .visibility = id_visibility, \
+ .reset = general_read_kvm_sanitised_reg,\
+ .val = GENMASK(63, 0), \
+}
+
/* sys_reg_desc initialiser for known cpufeature ID registers */
#define AA32_ID_SANITISED(name) { \
SYS_DESC(SYS_##name), \
@@ -636,9 +655,14 @@ const struct sys_reg_desc id_reg_descs[KVM_ARM_ID_REG_NUM] = {
ID_UNALLOCATED(6, 7),
/* CRm=7 */
- ID_SANITISED(ID_AA64MMFR0_EL1),
- ID_SANITISED(ID_AA64MMFR1_EL1),
- ID_SANITISED(ID_AA64MMFR2_EL1),
+ ID_SANITISED_WRITABLE(ID_AA64MMFR0_EL1),
+ ID_SANITISED_WRITABLE(ID_AA64MMFR1_EL1),
+ { SYS_DESC(SYS_ID_AA64MMFR2_EL1),
+ .access = access_id_reg,
+ .get_user = get_id_reg,
+ .set_user = set_id_reg,
+ .reset = read_sanitised_id_aa64mmfr2_el1,
+ .val = GENMASK(63, 0), },
ID_UNALLOCATED(7, 3),
ID_UNALLOCATED(7, 4),
ID_UNALLOCATED(7, 5),
--
2.40.0.348.gf938b09366-goog
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply related [flat|nested] 5+ messages in thread
end of thread, other threads:[~2023-04-05 17:22 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-04-05 17:21 [PATCH v3 0/4] Enable writable for idregs DFR0,PFR0, MMFR{0,1,2} Jing Zhang
2023-04-05 17:21 ` [PATCH v3 1/4] KVM: arm64: Enable writable for ID_AA64DFR0_EL1 Jing Zhang
2023-04-05 17:21 ` [PATCH v3 2/4] KVM: arm64: Enable writable for ID_DFR0_EL1 Jing Zhang
2023-04-05 17:21 ` [PATCH v3 3/4] KVM: arm64: Enable writable for ID_AA64PFR0_EL1 Jing Zhang
2023-04-05 17:21 ` [PATCH v3 4/4] KVM: arm64: Enable writable for ID_AA64MMFR{0, 1, 2}_EL1 Jing Zhang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).