* [PATCH v3 0/2] KVM: arm64: make EL2 feature fields writable in ID_AA64MMFR1_EL1
@ 2025-09-11 11:46 Jinqian Yang
2025-09-11 11:46 ` [PATCH v3 1/2] KVM: arm64: Make ID_AA64MMFR1_EL1.{HCX, TWED} writable from userspace Jinqian Yang
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Jinqian Yang @ 2025-09-11 11:46 UTC (permalink / raw)
To: oliver.upton, yuzenghui, maz
Cc: linux-arm-kernel, kvmarm, linux-kernel, liuyonglong, wangzhou1,
yangjinqian1
Allow userspace to downgrade EL2 features (TWED, HCX) to ensure VM live
migration compatibility between hosts with varying feature support.
Although ID_AA64MMFR1_EL1.VH is an EL2 feature, it is still kept as non-
writable in userspace. When FEAT_E2H0 is not implemented, HCR_EL2.E2H is
res1. When E2H=1, EL2 operates in VHE mode. In this case, if userspace
modifies the VH bit to 0, the Guest's kernel will still run in vEL2, leading
to inconsistency.
v1: https://lore.kernel.org/linux-arm-kernel/20250325121126.1380681-1-yangjinqian1@huawei.com/
v2: https://lore.kernel.org/linux-arm-kernel/20250909034415.3822478-1-yangjinqian1@huawei.com/
Change Log:
v1->v2:
-Added support for downgrading TWED and VH fields.
-Added corresponding test cases to the set_id_regs selftest.
v2->v3:
-Kept VH non-writable.
-Separated kernel patches and self-test patches.
Jinqian Yang (2):
KVM: arm64: Make ID_AA64MMFR1_EL1.{HCX, TWED} writable from userspace
KVM: arm64: selftests: Test writes to ID_AA64MMFR1_EL1.{HCX, TWED}
arch/arm64/kvm/sys_regs.c | 2 --
tools/testing/selftests/kvm/arm64/set_id_regs.c | 2 ++
2 files changed, 2 insertions(+), 2 deletions(-)
--
2.33.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v3 1/2] KVM: arm64: Make ID_AA64MMFR1_EL1.{HCX, TWED} writable from userspace
2025-09-11 11:46 [PATCH v3 0/2] KVM: arm64: make EL2 feature fields writable in ID_AA64MMFR1_EL1 Jinqian Yang
@ 2025-09-11 11:46 ` Jinqian Yang
2025-09-12 21:51 ` Oliver Upton
2025-09-11 11:46 ` [PATCH v3 2/2] KVM: arm64: selftests: Test writes to ID_AA64MMFR1_EL1.{HCX, TWED} Jinqian Yang
2025-09-19 13:15 ` [PATCH v3 0/2] KVM: arm64: make EL2 feature fields writable in ID_AA64MMFR1_EL1 Marc Zyngier
2 siblings, 1 reply; 6+ messages in thread
From: Jinqian Yang @ 2025-09-11 11:46 UTC (permalink / raw)
To: oliver.upton, yuzenghui, maz
Cc: linux-arm-kernel, kvmarm, linux-kernel, liuyonglong, wangzhou1,
yangjinqian1
Allow userspace to downgrade {HCX, TWED} in ID_AA64MMFR1_EL1. Userspace can
only change the value from high to low.
Signed-off-by: Jinqian Yang <yangjinqian1@huawei.com>
---
arch/arm64/kvm/sys_regs.c | 2 --
1 file changed, 2 deletions(-)
diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c
index 82ffb3b3b3cf..db49beb8804e 100644
--- a/arch/arm64/kvm/sys_regs.c
+++ b/arch/arm64/kvm/sys_regs.c
@@ -3002,8 +3002,6 @@ static const struct sys_reg_desc sys_reg_descs[] = {
~(ID_AA64MMFR0_EL1_RES0 |
ID_AA64MMFR0_EL1_ASIDBITS)),
ID_WRITABLE(ID_AA64MMFR1_EL1, ~(ID_AA64MMFR1_EL1_RES0 |
- ID_AA64MMFR1_EL1_HCX |
- ID_AA64MMFR1_EL1_TWED |
ID_AA64MMFR1_EL1_XNX |
ID_AA64MMFR1_EL1_VH |
ID_AA64MMFR1_EL1_VMIDBits)),
--
2.33.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v3 2/2] KVM: arm64: selftests: Test writes to ID_AA64MMFR1_EL1.{HCX, TWED}
2025-09-11 11:46 [PATCH v3 0/2] KVM: arm64: make EL2 feature fields writable in ID_AA64MMFR1_EL1 Jinqian Yang
2025-09-11 11:46 ` [PATCH v3 1/2] KVM: arm64: Make ID_AA64MMFR1_EL1.{HCX, TWED} writable from userspace Jinqian Yang
@ 2025-09-11 11:46 ` Jinqian Yang
2025-09-19 13:15 ` [PATCH v3 0/2] KVM: arm64: make EL2 feature fields writable in ID_AA64MMFR1_EL1 Marc Zyngier
2 siblings, 0 replies; 6+ messages in thread
From: Jinqian Yang @ 2025-09-11 11:46 UTC (permalink / raw)
To: oliver.upton, yuzenghui, maz
Cc: linux-arm-kernel, kvmarm, linux-kernel, liuyonglong, wangzhou1,
yangjinqian1
Assert that the EL2 features {HCX, TWED} of ID_AA64MMFR1_EL1 are writable
from userspace. They are only allowed to be downgraded in userspace.
Signed-off-by: Jinqian Yang <yangjinqian1@huawei.com>
---
tools/testing/selftests/kvm/arm64/set_id_regs.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/tools/testing/selftests/kvm/arm64/set_id_regs.c b/tools/testing/selftests/kvm/arm64/set_id_regs.c
index d3bf9204409c..a889550d8aa4 100644
--- a/tools/testing/selftests/kvm/arm64/set_id_regs.c
+++ b/tools/testing/selftests/kvm/arm64/set_id_regs.c
@@ -165,7 +165,9 @@ static const struct reg_ftr_bits ftr_id_aa64mmfr0_el1[] = {
static const struct reg_ftr_bits ftr_id_aa64mmfr1_el1[] = {
REG_FTR_BITS(FTR_LOWER_SAFE, ID_AA64MMFR1_EL1, TIDCP1, 0),
REG_FTR_BITS(FTR_LOWER_SAFE, ID_AA64MMFR1_EL1, AFP, 0),
+ REG_FTR_BITS(FTR_LOWER_SAFE, ID_AA64MMFR1_EL1, HCX, 0),
REG_FTR_BITS(FTR_LOWER_SAFE, ID_AA64MMFR1_EL1, ETS, 0),
+ REG_FTR_BITS(FTR_LOWER_SAFE, ID_AA64MMFR1_EL1, TWED, 0),
REG_FTR_BITS(FTR_HIGHER_SAFE, ID_AA64MMFR1_EL1, SpecSEI, 0),
REG_FTR_BITS(FTR_LOWER_SAFE, ID_AA64MMFR1_EL1, PAN, 0),
REG_FTR_BITS(FTR_LOWER_SAFE, ID_AA64MMFR1_EL1, LO, 0),
--
2.33.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v3 1/2] KVM: arm64: Make ID_AA64MMFR1_EL1.{HCX, TWED} writable from userspace
2025-09-11 11:46 ` [PATCH v3 1/2] KVM: arm64: Make ID_AA64MMFR1_EL1.{HCX, TWED} writable from userspace Jinqian Yang
@ 2025-09-12 21:51 ` Oliver Upton
2025-09-14 20:27 ` Marc Zyngier
0 siblings, 1 reply; 6+ messages in thread
From: Oliver Upton @ 2025-09-12 21:51 UTC (permalink / raw)
To: Jinqian Yang
Cc: yuzenghui, maz, linux-arm-kernel, kvmarm, linux-kernel,
liuyonglong, wangzhou1
Hi Jinqian,
On Thu, Sep 11, 2025 at 07:46:20PM +0800, Jinqian Yang wrote:
> Allow userspace to downgrade {HCX, TWED} in ID_AA64MMFR1_EL1. Userspace can
> only change the value from high to low.
>
> Signed-off-by: Jinqian Yang <yangjinqian1@huawei.com>
> ---
> arch/arm64/kvm/sys_regs.c | 2 --
> 1 file changed, 2 deletions(-)
>
> diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c
> index 82ffb3b3b3cf..db49beb8804e 100644
> --- a/arch/arm64/kvm/sys_regs.c
> +++ b/arch/arm64/kvm/sys_regs.c
> @@ -3002,8 +3002,6 @@ static const struct sys_reg_desc sys_reg_descs[] = {
> ~(ID_AA64MMFR0_EL1_RES0 |
> ID_AA64MMFR0_EL1_ASIDBITS)),
> ID_WRITABLE(ID_AA64MMFR1_EL1, ~(ID_AA64MMFR1_EL1_RES0 |
> - ID_AA64MMFR1_EL1_HCX |
> - ID_AA64MMFR1_EL1_TWED |
> ID_AA64MMFR1_EL1_XNX |
> ID_AA64MMFR1_EL1_VH |
> ID_AA64MMFR1_EL1_VMIDBits)),
I still have a bone to pick with Marc regarding the NV implications of
this :) Attaching conversation below. Although for non-nested this LGTM.
On Tue, Sep 09, 2025 at 11:10:28AM +0100, Marc Zyngier wrote:
> My concern here is the transitive implications of FEAT_HCX being
> disabled: a quick look shows about 20 features that depend on
> FEAT_HCX, and we don't really track this. I can probably generate the
> dependency graph, but that's not going to be small. Or very useful.
>
> However, we should be able to let FEAT_HCX being disabled without
> problem if the downgrading is limited to non-EL2 VMs. Same thing for
> FEAT_VHE.
>
> What do you think?
So I'm a bit worried about making fields sometimes-writable, it creates
a very confusing UAPI behavior. On top of that, our writable masks are
currently static.
What if we treat the entire register as RES0 in this case? It seems to
be consistent with all the underlying bits / features being NI. A
mis-described VM isn't long for this world anyway (e.g. FEAT_SCTLR2 && !FEAT_HCX)
and in that case I'd prefer an approach that keeps the KVM code as
simple as possible.
We do, after all, expect some level of sanity from userspace of feature
dependencies as we do not enforce the dependency graph at the moment.
Hell, this could be useful for someone cross-migrating a nested VM from
a machine w/o FEAT_HCX to one that has it.
Thanks,
Oliver
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v3 1/2] KVM: arm64: Make ID_AA64MMFR1_EL1.{HCX, TWED} writable from userspace
2025-09-12 21:51 ` Oliver Upton
@ 2025-09-14 20:27 ` Marc Zyngier
0 siblings, 0 replies; 6+ messages in thread
From: Marc Zyngier @ 2025-09-14 20:27 UTC (permalink / raw)
To: Oliver Upton
Cc: Jinqian Yang, yuzenghui, linux-arm-kernel, kvmarm, linux-kernel,
liuyonglong, wangzhou1
On Fri, 12 Sep 2025 22:51:58 +0100,
Oliver Upton <oliver.upton@linux.dev> wrote:
>
> Hi Jinqian,
>
> On Thu, Sep 11, 2025 at 07:46:20PM +0800, Jinqian Yang wrote:
> > Allow userspace to downgrade {HCX, TWED} in ID_AA64MMFR1_EL1. Userspace can
> > only change the value from high to low.
> >
> > Signed-off-by: Jinqian Yang <yangjinqian1@huawei.com>
> > ---
> > arch/arm64/kvm/sys_regs.c | 2 --
> > 1 file changed, 2 deletions(-)
> >
> > diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c
> > index 82ffb3b3b3cf..db49beb8804e 100644
> > --- a/arch/arm64/kvm/sys_regs.c
> > +++ b/arch/arm64/kvm/sys_regs.c
> > @@ -3002,8 +3002,6 @@ static const struct sys_reg_desc sys_reg_descs[] = {
> > ~(ID_AA64MMFR0_EL1_RES0 |
> > ID_AA64MMFR0_EL1_ASIDBITS)),
> > ID_WRITABLE(ID_AA64MMFR1_EL1, ~(ID_AA64MMFR1_EL1_RES0 |
> > - ID_AA64MMFR1_EL1_HCX |
> > - ID_AA64MMFR1_EL1_TWED |
> > ID_AA64MMFR1_EL1_XNX |
> > ID_AA64MMFR1_EL1_VH |
> > ID_AA64MMFR1_EL1_VMIDBits)),
>
> I still have a bone to pick with Marc regarding the NV implications of
> this :) Attaching conversation below. Although for non-nested this LGTM.
>
> On Tue, Sep 09, 2025 at 11:10:28AM +0100, Marc Zyngier wrote:
> > My concern here is the transitive implications of FEAT_HCX being
> > disabled: a quick look shows about 20 features that depend on
> > FEAT_HCX, and we don't really track this. I can probably generate the
> > dependency graph, but that's not going to be small. Or very useful.
> >
> > However, we should be able to let FEAT_HCX being disabled without
> > problem if the downgrading is limited to non-EL2 VMs. Same thing for
> > FEAT_VHE.
> >
> > What do you think?
>
> So I'm a bit worried about making fields sometimes-writable, it creates
> a very confusing UAPI behavior. On top of that, our writable masks are
> currently static.
>
> What if we treat the entire register as RES0 in this case? It seems to
> be consistent with all the underlying bits / features being NI. A
> mis-described VM isn't long for this world anyway (e.g. FEAT_SCTLR2 && !FEAT_HCX)
> and in that case I'd prefer an approach that keeps the KVM code as
> simple as possible.
I've pushed out a branch implementing this[1], though it hasn't had
much testing yet. I'll post it once I've convinced myself that this is
sane enough.
M.
[1] https://git.kernel.org/pub/scm/linux/kernel/git/maz/arm-platforms.git/log/?h=kvm-arm64/el2-res0
--
Jazz isn't dead. It just smells funny.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v3 0/2] KVM: arm64: make EL2 feature fields writable in ID_AA64MMFR1_EL1
2025-09-11 11:46 [PATCH v3 0/2] KVM: arm64: make EL2 feature fields writable in ID_AA64MMFR1_EL1 Jinqian Yang
2025-09-11 11:46 ` [PATCH v3 1/2] KVM: arm64: Make ID_AA64MMFR1_EL1.{HCX, TWED} writable from userspace Jinqian Yang
2025-09-11 11:46 ` [PATCH v3 2/2] KVM: arm64: selftests: Test writes to ID_AA64MMFR1_EL1.{HCX, TWED} Jinqian Yang
@ 2025-09-19 13:15 ` Marc Zyngier
2 siblings, 0 replies; 6+ messages in thread
From: Marc Zyngier @ 2025-09-19 13:15 UTC (permalink / raw)
To: oliver.upton, yuzenghui, Jinqian Yang
Cc: linux-arm-kernel, kvmarm, linux-kernel, liuyonglong, wangzhou1
On Thu, 11 Sep 2025 19:46:19 +0800, Jinqian Yang wrote:
> Allow userspace to downgrade EL2 features (TWED, HCX) to ensure VM live
> migration compatibility between hosts with varying feature support.
>
> Although ID_AA64MMFR1_EL1.VH is an EL2 feature, it is still kept as non-
> writable in userspace. When FEAT_E2H0 is not implemented, HCR_EL2.E2H is
> res1. When E2H=1, EL2 operates in VHE mode. In this case, if userspace
> modifies the VH bit to 0, the Guest's kernel will still run in vEL2, leading
> to inconsistency.
>
> [...]
Applied to next, thanks!
[1/2] KVM: arm64: Make ID_AA64MMFR1_EL1.{HCX, TWED} writable from userspace
commit: 1a0b2bf6ff11d2e0438f3a7d1d299339edab96e8
[2/2] KVM: arm64: selftests: Test writes to ID_AA64MMFR1_EL1.{HCX, TWED}
commit: be8c9192eaeee21fdaacd72ad4ba992b9e42377b
Cheers,
M.
--
Without deviation from the norm, progress is not possible.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2025-09-19 13:15 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-11 11:46 [PATCH v3 0/2] KVM: arm64: make EL2 feature fields writable in ID_AA64MMFR1_EL1 Jinqian Yang
2025-09-11 11:46 ` [PATCH v3 1/2] KVM: arm64: Make ID_AA64MMFR1_EL1.{HCX, TWED} writable from userspace Jinqian Yang
2025-09-12 21:51 ` Oliver Upton
2025-09-14 20:27 ` Marc Zyngier
2025-09-11 11:46 ` [PATCH v3 2/2] KVM: arm64: selftests: Test writes to ID_AA64MMFR1_EL1.{HCX, TWED} Jinqian Yang
2025-09-19 13:15 ` [PATCH v3 0/2] KVM: arm64: make EL2 feature fields writable in ID_AA64MMFR1_EL1 Marc Zyngier
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).