]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
KVM: arm64: Simplify handling of full register invalid constraint
authorMarc Zyngier <maz@kernel.org>
Mon, 2 Feb 2026 18:43:25 +0000 (18:43 +0000)
committerMarc Zyngier <maz@kernel.org>
Thu, 5 Feb 2026 09:02:13 +0000 (09:02 +0000)
Now that we embed the RESx bits in the register description, it becomes
easier to deal with registers that are simply not valid, as their
existence is not satisfied by the configuration (SCTLR2_ELx without
FEAT_SCTLR2, for example). Such registers essentially become RES0 for
any bit that wasn't already advertised as RESx.

Reviewed-by: Fuad Tabba <tabba@google.com>
Tested-by: Fuad Tabba <tabba@google.com>
Link: https://patch.msgid.link/20260202184329.2724080-17-maz@kernel.org
Signed-off-by: Marc Zyngier <maz@kernel.org>
arch/arm64/kvm/config.c

index 274ae049c4b33d5eec853737b74af1c36eac77d9..b37b40744db9470ed123720db7ac5ced632584bb 100644 (file)
@@ -1321,7 +1321,7 @@ static struct resx compute_reg_resx_bits(struct kvm *kvm,
                                         unsigned long require,
                                         unsigned long exclude)
 {
-       struct resx resx, tmp;
+       struct resx resx;
 
        resx = compute_resx_bits(kvm, r->bit_feat_map, r->bit_feat_map_sz,
                                 require, exclude);
@@ -1331,11 +1331,14 @@ static struct resx compute_reg_resx_bits(struct kvm *kvm,
                resx.res1 |= r->feat_map.masks->res1;
        }
 
-       tmp = compute_resx_bits(kvm, &r->feat_map, 1, require, exclude);
-
-       resx.res0 |= tmp.res0;
-       resx.res0 |= ~reg_feat_map_bits(&r->feat_map);
-       resx.res1 |= tmp.res1;
+       /*
+        * If the register itself was not valid, all the non-RESx bits are
+        * now considered RES0 (this matches the behaviour of registers such
+        * as SCTLR2 and TCR2). Weed out any potential (though unlikely)
+        * overlap with RES1 bits coming from the previous computation.
+        */
+       resx.res0 |= compute_resx_bits(kvm, &r->feat_map, 1, require, exclude).res0;
+       resx.res1 &= ~resx.res0;
 
        return resx;
 }