diff mbox series

[3/3] KVM: arm64: Raise KVM's reported debug architecture to v8.2

Message ID 20211029003202.158161-4-oupton@google.com (mailing list archive)
State New, archived
Headers show
Series KVM: arm64: Fixes for the exposed debug architecture | expand

Commit Message

Oliver Upton Oct. 29, 2021, 12:32 a.m. UTC
The additions made to the Debug architecture between v8.0 and v8.2 are
only applicable to external debug. KVM does not (and likely will never)
support external debug, so KVM can proudly report support for v8.2 to
its guests.

Raise the reported Debug architecture to v8.2. Additionally, v8.2 makes
FEAT_DoubleLock optional. Even though KVM never supported it in the
first place, report DoubleLock as not implemented now as the
architecture permits it for v8.2.

Cc: Reiji Watanabe <reijiw@google.com>
Cc: Ricardo Koller <ricarkol@google.com>
Suggested-by: Marc Zyngier <maz@kernel.org>
Signed-off-by: Oliver Upton <oupton@google.com>
---
 arch/arm64/kvm/sys_regs.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

Comments

Marc Zyngier Oct. 29, 2021, 11:31 a.m. UTC | #1
On Fri, 29 Oct 2021 01:32:02 +0100,
Oliver Upton <oupton@google.com> wrote:
> 
> The additions made to the Debug architecture between v8.0 and v8.2 are
> only applicable to external debug. KVM does not (and likely will never)
> support external debug, so KVM can proudly report support for v8.2 to
> its guests.
> 
> Raise the reported Debug architecture to v8.2. Additionally, v8.2 makes
> FEAT_DoubleLock optional. Even though KVM never supported it in the
> first place, report DoubleLock as not implemented now as the
> architecture permits it for v8.2.
> 
> Cc: Reiji Watanabe <reijiw@google.com>
> Cc: Ricardo Koller <ricarkol@google.com>
> Suggested-by: Marc Zyngier <maz@kernel.org>
> Signed-off-by: Oliver Upton <oupton@google.com>
> ---
>  arch/arm64/kvm/sys_regs.c | 9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c
> index 0840ae081290..f56ee5830d18 100644
> --- a/arch/arm64/kvm/sys_regs.c
> +++ b/arch/arm64/kvm/sys_regs.c
> @@ -1109,9 +1109,14 @@ static u64 read_id_reg(const struct kvm_vcpu *vcpu,
>  				 ARM64_FEATURE_MASK(ID_AA64ISAR1_GPI));
>  		break;
>  	case SYS_ID_AA64DFR0_EL1:
> -		/* Limit debug to ARMv8.0 */
> +		/* Limit debug to ARMv8.2 */
>  		val &= ~ARM64_FEATURE_MASK(ID_AA64DFR0_DEBUGVER);
> -		val |= FIELD_PREP(ARM64_FEATURE_MASK(ID_AA64DFR0_DEBUGVER), 6);
> +		val |= FIELD_PREP(ARM64_FEATURE_MASK(ID_AA64DFR0_DEBUGVER), 8);
> +
> +		/* Hide DoubleLock from guests */
> +		val &= ~ARM64_FEATURE_MASK(ID_AA64DFR0_DOUBLELOCK);
> +		val |= FIELD_PREP(ARM64_FEATURE_MASK(ID_AA64DFR0_DOUBLELOCK), 0CF);
> +

One issue with that is that this will break migration from an older
kernel (DFR0 will be different between source and destination).

You'll need a set_user handler and deal with it in a similar way to
CSV2/CSV3.

Thanks,

	M.
Oliver Upton Oct. 29, 2021, 6:18 p.m. UTC | #2
Hey Marc,

On Fri, Oct 29, 2021 at 4:31 AM Marc Zyngier <maz@kernel.org> wrote:
>
> On Fri, 29 Oct 2021 01:32:02 +0100,
> Oliver Upton <oupton@google.com> wrote:
[...]
> >       case SYS_ID_AA64DFR0_EL1:
> > -             /* Limit debug to ARMv8.0 */
> > +             /* Limit debug to ARMv8.2 */
> >               val &= ~ARM64_FEATURE_MASK(ID_AA64DFR0_DEBUGVER);
> > -             val |= FIELD_PREP(ARM64_FEATURE_MASK(ID_AA64DFR0_DEBUGVER), 6);
> > +             val |= FIELD_PREP(ARM64_FEATURE_MASK(ID_AA64DFR0_DEBUGVER), 8);
> > +
> > +             /* Hide DoubleLock from guests */
> > +             val &= ~ARM64_FEATURE_MASK(ID_AA64DFR0_DOUBLELOCK);
> > +             val |= FIELD_PREP(ARM64_FEATURE_MASK(ID_AA64DFR0_DOUBLELOCK), 0CF);
> > +
>
> One issue with that is that this will break migration from an older
> kernel (DFR0 will be different between source and destination).
>
> You'll need a set_user handler and deal with it in a similar way to
> CSV2/CSV3.

Yeah, definitely so. In that case, unless we're strongly motivated to
expose these changes soon, I'll just punt the ID register changes
until Reiji's series [1] lands, as anything I add for a writable DFR0
will invariably be scrapped in favor of his work.

I'll post v2 of this series folding in your feedback (thx for quick
review, btw), less this patch.

[1] https://patchwork.kernel.org/project/kvm/cover/20211012043535.500493-1-reijiw@google.com/

--
Thanks,
Oliver
Marc Zyngier Nov. 1, 2021, 10:21 a.m. UTC | #3
On Fri, 29 Oct 2021 19:18:13 +0100,
Oliver Upton <oupton@google.com> wrote:
> 
> Hey Marc,
> 
> On Fri, Oct 29, 2021 at 4:31 AM Marc Zyngier <maz@kernel.org> wrote:
> >
> > On Fri, 29 Oct 2021 01:32:02 +0100,
> > Oliver Upton <oupton@google.com> wrote:
> [...]
> > >       case SYS_ID_AA64DFR0_EL1:
> > > -             /* Limit debug to ARMv8.0 */
> > > +             /* Limit debug to ARMv8.2 */
> > >               val &= ~ARM64_FEATURE_MASK(ID_AA64DFR0_DEBUGVER);
> > > -             val |= FIELD_PREP(ARM64_FEATURE_MASK(ID_AA64DFR0_DEBUGVER), 6);
> > > +             val |= FIELD_PREP(ARM64_FEATURE_MASK(ID_AA64DFR0_DEBUGVER), 8);
> > > +
> > > +             /* Hide DoubleLock from guests */
> > > +             val &= ~ARM64_FEATURE_MASK(ID_AA64DFR0_DOUBLELOCK);
> > > +             val |= FIELD_PREP(ARM64_FEATURE_MASK(ID_AA64DFR0_DOUBLELOCK), 0CF);
> > > +
> >
> > One issue with that is that this will break migration from an older
> > kernel (DFR0 will be different between source and destination).
> >
> > You'll need a set_user handler and deal with it in a similar way to
> > CSV2/CSV3.
> 
> Yeah, definitely so. In that case, unless we're strongly motivated to
> expose these changes soon, I'll just punt the ID register changes
> until Reiji's series [1] lands, as anything I add for a writable DFR0
> will invariably be scrapped in favor of his work.

Yeah, I think that's a sensible thing to do. I need to find the
bandwidth to look into these patches...

> I'll post v2 of this series folding in your feedback (thx for quick
> review, btw), less this patch.

Thanks,

	M.
diff mbox series

Patch

diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c
index 0840ae081290..f56ee5830d18 100644
--- a/arch/arm64/kvm/sys_regs.c
+++ b/arch/arm64/kvm/sys_regs.c
@@ -1109,9 +1109,14 @@  static u64 read_id_reg(const struct kvm_vcpu *vcpu,
 				 ARM64_FEATURE_MASK(ID_AA64ISAR1_GPI));
 		break;
 	case SYS_ID_AA64DFR0_EL1:
-		/* Limit debug to ARMv8.0 */
+		/* Limit debug to ARMv8.2 */
 		val &= ~ARM64_FEATURE_MASK(ID_AA64DFR0_DEBUGVER);
-		val |= FIELD_PREP(ARM64_FEATURE_MASK(ID_AA64DFR0_DEBUGVER), 6);
+		val |= FIELD_PREP(ARM64_FEATURE_MASK(ID_AA64DFR0_DEBUGVER), 8);
+
+		/* Hide DoubleLock from guests */
+		val &= ~ARM64_FEATURE_MASK(ID_AA64DFR0_DOUBLELOCK);
+		val |= FIELD_PREP(ARM64_FEATURE_MASK(ID_AA64DFR0_DOUBLELOCK), 0xf);
+
 		/* Limit guests to PMUv3 for ARMv8.4 */
 		val = cpuid_feature_cap_perfmon_field(val,
 						      ID_AA64DFR0_PMUVER_SHIFT,