]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
KVM: selftests: Fix shift of 32 bit unsigned int more than 32 bits
authorColin Ian King <colin.i.king@gmail.com>
Thu, 23 May 2024 15:41:02 +0000 (16:41 +0100)
committerSean Christopherson <seanjc@google.com>
Wed, 5 Jun 2024 13:16:09 +0000 (06:16 -0700)
Currrentl a 32 bit 1u value is being shifted more than 32 bits causing
overflow and incorrect checking of bits 32-63. Fix this by using the
BIT_ULL macro for shifting bits.

Detected by cppcheck:
sev_init2_tests.c:108:34: error: Shifting 32-bit value by 63 bits is
undefined behaviour [shiftTooManyBits]

Fixes: dfc083a181ba ("selftests: kvm: add tests for KVM_SEV_INIT2")
Signed-off-by: Colin Ian King <colin.i.king@gmail.com>
Link: https://lore.kernel.org/r/20240523154102.2236133-1-colin.i.king@gmail.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
tools/testing/selftests/kvm/x86_64/sev_init2_tests.c

index 7a4a61be119b15b354ec98f6914b94fe04efa388..3fb967f40c6a1626d1d2cff1032c0e2562c8a205 100644 (file)
@@ -105,11 +105,11 @@ void test_features(uint32_t vm_type, uint64_t supported_features)
        int i;
 
        for (i = 0; i < 64; i++) {
-               if (!(supported_features & (1u << i)))
+               if (!(supported_features & BIT_ULL(i)))
                        test_init2_invalid(vm_type,
                                &(struct kvm_sev_init){ .vmsa_features = BIT_ULL(i) },
                                "unknown feature");
-               else if (KNOWN_FEATURES & (1u << i))
+               else if (KNOWN_FEATURES & BIT_ULL(i))
                        test_init2(vm_type,
                                &(struct kvm_sev_init){ .vmsa_features = BIT_ULL(i) });
        }