[PATCH 1/3] KVM: arm64: Add enum support to idreg sanitisation

Fuad Tabba fuad.tabba at linux.dev
Tue Nov 24 00:35:14 PST 2026


Hi Marc,

On Mon, 23 Nov 2026 19:24:55 +0000, Marc Zyngier <maz at kernel.org> wrote:
[...]
> diff --git a/arch/arm64/kvm/config.c b/arch/arm64/kvm/config.c
[...]
> +static struct resx compute_idreg_field_deps(struct kvm *kvm,
> +                                            const struct reg_bits_to_feat_map *map)
> +{
[...]
> +        for (tmp = map->idreg_field_deps; tmp->match; tmp++)
> +                if (tmp->match(kvm))
> +                        break;
> +
> +        resx.res0 = field_prep(map->bits, ~(tmp->bits));
> +        resx.res1 = field_prep(map->bits, tmp->bits);

Sashiko flagged the res0 line [1]. With the tables in patch 2 the loop
picks tmp at run time, and GCC 14 and clang 23 builds of config.c
don't trip the BUILD_BUG it describes.

nit: could you still compute res1 first and derive res0 from it, as
Sashiko suggests (res0 = map->bits & ~resx.res1)? That way
field_prep() is only passed values that fit the field, whatever the
compiler folds.

Reviewed-by: Fuad Tabba <fuad.tabba at linux.dev>

Cheers,
/fuad

[1] https://lore.kernel.org/all/sashiko-outbox-229945@kernel.org/



More information about the linux-arm-kernel mailing list