Linux KVM/arm64 development list
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Steffen Eiden" <seiden@linux.ibm.com>
Cc: "Marc Zyngier" <maz@kernel.org>,
	"Heiko Carstens" <hca@linux.ibm.com>,
	linux-s390@vger.kernel.org, "Oliver Upton" <oupton@kernel.org>,
	"Alexander Gordeev" <agordeev@linux.ibm.com>,
	"Christian Borntraeger" <borntraeger@linux.ibm.com>,
	"Vasily Gorbik" <gor@linux.ibm.com>,
	kvm@vger.kernel.org, kvmarm@lists.linux.dev
Subject: Re: [PATCH v2 12/20] KVM: s390: arm64: Implement feature sanitisation
Date: Mon, 31 Aug 2026 20:11:54 +0000	[thread overview]
Message-ID: <20260831201154.9955C1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260831145536.913567-13-seiden@linux.ibm.com>

Thank you for your contribution! Sashiko AI review found 6 potential issue(s) to consider:
- [High] Hardware Feature Mis-mapping: ARM64_HAS_ECV_CNTPOFF maps to PAN instead of ECV
- [High] Hardware Feature Mis-mapping: ARM64_HAS_HCR_NV1 fails to account for CPUs that remove NV1
- [High] Incomplete Feature Check: ARM64_HAS_RASV1P1_EXTN omits the primary fallback check
- [High] Feature Leakage: MASK_RESERVED uses a blacklist approach, leaking unknown features to the guest
- [Low] Undefined reference to __qaaf_qmp causing potential linker errors
- [Low] Integer overflow in kvm_sae_max_vcpus due to u16 return type
--

commit ea4286d0301a7cdfe0535f60a7c1ca1b65c64103
Author: Steffen Eiden <seiden@linux.ibm.com>

KVM: s390: arm64: Implement feature sanitisation

Implement feature detection and sanitization for arm64 KVM guests on s390.
Queries hardware capabilities using the QAAF instruction and provides accessor
functions for capability mapping.

> diff --git a/arch/s390/kvm/arm64/feature.c b/arch/s390/kvm/arm64/feature.c
> new file mode 100644
> index 0000000000000..39c8ae7e951cf
> --- /dev/null
> +++ b/arch/s390/kvm/arm64/feature.c
> @@ -0,0 +1,165 @@
[ ... ]
> +#define MASK_RESERVED(_qaafp, _id)				\
> +	({							\
> +		u64 *_reg = &((_qaafp)->regs[QAAF_REG_##_id]);	\
> +		*_reg = (*_reg & ~_id##_RES0) | _id##_RES1;	\
> +	})

[Severity: High]
Does this blacklist approach inadvertently leak unknown features to the guest?

By clearing only the explicitly unarchitected RES0 bits, any valid CPU
features that are not recognized or handled by KVM will be passed through
unconditionally. This goes against the KVM invariants that new guest-visible
features should default off, which could allow a guest to use unsupported
features and lead to hardware traps or hypervisor state corruption.

[ ... ]
> +bool cpus_have_final_cap(unsigned int num)
> +{
> +	u64 reg_val;
> +
> +	switch (num) {
[ ... ]
> +	case ARM64_HAS_RASV1P1_EXTN:
> +		reg_val = read_sanitised_ftr_reg(SYS_ID_AA64PFR1_EL1);
> +		return SYS_FIELD_GET(ID_AA64PFR1_EL1, RAS_frac, reg_val) ==
> +		       ID_AA64PFR1_EL1_RAS_frac_RASv1p1;

[Severity: High]
Is this missing the primary check for the RAS extension?

The check looks exclusively at the fractional extension field RAS_frac in
ID_AA64PFR1_EL1, but ignores the primary ID_AA64PFR0_EL1.RAS field. On
modern CPUs that correctly advertise V1P1 support in ID_AA64PFR0_EL1, this
will return false and break feature discovery.

> +
> +	case ARM64_HAS_HCR_NV1:
> +		reg_val = read_sanitised_ftr_reg(SYS_ID_AA64MMFR2_EL1);
> +		return SYS_FIELD_GET(ID_AA64MMFR2_EL1, NV, reg_val) >=
> +		       ID_AA64MMFR2_EL1_NV_IMP;

[Severity: High]
Will this misidentify NV2-only systems as having NV1 support?

This check verifies if Nested Virtualization is implemented but ignores
the ID_AA64MMFR4_EL1.E2H0 field. On newer hosts that implement NV2 but
explicitly remove NV1 (such as the Apple M2 series), this function will
return true and attempt to use unsupported NV1 features.

[ ... ]
> +	case ARM64_HAS_ECV_CNTPOFF:
> +		reg_val = read_sanitised_ftr_reg(SYS_ID_AA64MMFR1_EL1);
> +		return SYS_FIELD_GET(ID_AA64MMFR1_EL1, PAN, reg_val) >=
> +		       ID_AA64MMFR1_EL1_PAN_IMP;

[Severity: High]
Does this check query the wrong register and field for Enhanced Counter
Virtualization (ECV)?

It is querying ID_AA64MMFR1_EL1.PAN instead of ID_AA64MMFR0_EL1.ECV. Because
PAN is widely supported on modern ARM64 CPUs, KVM will incorrectly assume
ECV is present, potentially causing undefined instruction exceptions or
timer misbehavior if those features are used.

> diff --git a/arch/s390/kvm/arm64/feature.h b/arch/s390/kvm/arm64/feature.h
> new file mode 100644
> index 0000000000000..9c902df1f26c6
> --- /dev/null
> +++ b/arch/s390/kvm/arm64/feature.h
> @@ -0,0 +1,87 @@
[ ... ]
> +static inline u32 kvm_sae_supported_sd_formats(void)
> +{
> +	extern struct qaaf_qmc_block __qaaf_qmp;
> +
> +	return __qaaf_qmp.ssdf;
> +}

[Severity: Low]
Is this referencing an undefined symbol?

The symbol __qaaf_qmp does not exist anywhere in the kernel (the actual
structure seems to be exposed via aef_qmc()). While this inline function
is currently dead code, calling it will cause a linker error.

[ ... ]
> +static inline u16 kvm_sae_max_vcpus(void)
> +{
> +	extern struct qaaf_qmc_block __qaaf_qmp;
> +
> +	/* QAAF QMP reports the max id not the max num */
> +	return __qaaf_qmp.maxncpu + 1;
> +}

[Severity: Low]
Can this result in an integer overflow?

The maxncpu field can reach 0xFFFF. Returning maxncpu + 1 cast to a u16
will overflow the 16-bit integer boundary and wrap around to 0. (Also, as
noted above, __qaaf_qmp is an unresolved symbol).

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260831145536.913567-1-seiden@linux.ibm.com?part=12

  reply	other threads:[~2026-08-31 20:11 UTC|newest]

Thread overview: 53+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-31 14:55 [PATCH v2 00/20] KVM: arm64 on s390 System Register Handling Steffen Eiden
2026-08-31 14:55 ` [PATCH v2 01/20] KVM: arm64: Refactor idreg caching into dedicated structure Steffen Eiden
2026-08-31 18:06   ` sashiko-bot
2026-08-31 14:55 ` [PATCH v2 02/20] KVM: arm64: Extract number of sys_reg_desc into a constant Steffen Eiden
2026-08-31 18:08   ` sashiko-bot
2026-09-01  7:48   ` Marc Zyngier
2026-08-31 14:55 ` [PATCH v2 03/20] arm64: sysreg: Define OSLSR_EL1_OSLK_MASK Steffen Eiden
2026-08-31 18:18   ` sashiko-bot
2026-09-01  7:51   ` Marc Zyngier
2026-09-01  9:25     ` Steffen Eiden
2026-09-02  7:49       ` Marc Zyngier
2026-08-31 14:55 ` [PATCH v2 04/20] arm64: Share more arm64 headers with s390 Steffen Eiden
2026-08-31 18:31   ` sashiko-bot
2026-09-01  8:08   ` Marc Zyngier
2026-08-31 14:55 ` [PATCH v2 05/20] KVM: s390: arm64: Prepare for sharing more arm64 code Steffen Eiden
2026-08-31 18:42   ` sashiko-bot
2026-09-01  8:15   ` Marc Zyngier
2026-08-31 14:55 ` [PATCH v2 06/20] KVM: arm64: Prepare sys_regs.c for sharing with s390 Steffen Eiden
2026-08-31 18:45   ` sashiko-bot
2026-09-01  8:17   ` Marc Zyngier
2026-09-01  9:29     ` Steffen Eiden
2026-08-31 14:55 ` [PATCH v2 07/20] KVM: arm64: Share more arm64 code " Steffen Eiden
2026-08-31 19:01   ` sashiko-bot
2026-09-01  8:30   ` Marc Zyngier
2026-08-31 14:55 ` [PATCH v2 08/20] s390: tools: Allow sharing arm64/kvm headers Steffen Eiden
2026-08-31 19:03   ` sashiko-bot
2026-08-31 14:55 ` [PATCH v2 09/20] s390: Introduce read/write ARM sysreg instructions Steffen Eiden
2026-08-31 19:16   ` sashiko-bot
2026-08-31 14:55 ` [PATCH v2 10/20] s390: Add functions to query arm guest time Steffen Eiden
2026-08-31 19:24   ` sashiko-bot
2026-08-31 14:55 ` [PATCH v2 11/20] KVM: s390: arm64: Query Available Arm features Steffen Eiden
2026-08-31 19:46   ` sashiko-bot
2026-09-01 11:44     ` Janosch Frank
2026-09-01 14:25       ` Steffen Eiden
2026-09-01 16:36         ` Janosch Frank
2026-08-31 14:55 ` [PATCH v2 12/20] KVM: s390: arm64: Implement feature sanitisation Steffen Eiden
2026-08-31 20:11   ` sashiko-bot [this message]
2026-08-31 14:55 ` [PATCH v2 13/20] KVM: s390: arm64: Implement arm sysreg managing infrastructure Steffen Eiden
2026-08-31 20:33   ` sashiko-bot
2026-08-31 14:55 ` [PATCH v2 14/20] KVM: s390: arm64: Integrate sysreg into the host Steffen Eiden
2026-08-31 21:15   ` sashiko-bot
2026-08-31 14:55 ` [PATCH v2 15/20] KVM: s390: arm64: Use QAAF init save area Steffen Eiden
2026-08-31 21:32   ` sashiko-bot
2026-08-31 14:55 ` [PATCH v2 16/20] KVM: s390: arm64: Implement exception injection Steffen Eiden
2026-08-31 21:38   ` sashiko-bot
2026-08-31 14:55 ` [PATCH v2 17/20] KVM: s390: arm64: Finalize page fault handling Steffen Eiden
2026-08-31 21:52   ` sashiko-bot
2026-08-31 14:55 ` [PATCH v2 18/20] KVM: s390: arm64: Implement SVE for arm guests Steffen Eiden
2026-08-31 22:16   ` sashiko-bot
2026-08-31 14:55 ` [PATCH v2 19/20] KVM: s390: arm64: Promote PTRAUTH capability Steffen Eiden
2026-08-31 22:35   ` sashiko-bot
2026-08-31 14:55 ` [PATCH v2 20/20] s390: Report AEF features to sysfs Steffen Eiden
2026-08-31 22:43   ` sashiko-bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260831201154.9955C1F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=agordeev@linux.ibm.com \
    --cc=borntraeger@linux.ibm.com \
    --cc=gor@linux.ibm.com \
    --cc=hca@linux.ibm.com \
    --cc=kvm@vger.kernel.org \
    --cc=kvmarm@lists.linux.dev \
    --cc=linux-s390@vger.kernel.org \
    --cc=maz@kernel.org \
    --cc=oupton@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=seiden@linux.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox