mirror of
https://github.com/torvalds/linux.git
synced 2026-04-22 08:44:02 -04:00
Define _GNU_SOURCE is the base CFLAGS instead of relying on selftests to
manually #define _GNU_SOURCE, which is repetitive and error prone. E.g.
kselftest_harness.h requires _GNU_SOURCE for asprintf(), but if a selftest
includes kvm_test_harness.h after stdio.h, the include guards result in
the effective version of stdio.h consumed by kvm_test_harness.h not
defining asprintf():
In file included from x86_64/fix_hypercall_test.c:12:
In file included from include/kvm_test_harness.h:11:
../kselftest_harness.h:1169:2: error: call to undeclared function
'asprintf'; ISO C99 and later do not support implicit function declarations
[-Wimplicit-function-declaration]
1169 | asprintf(&test_name, "%s%s%s.%s", f->name,
| ^
When including the rseq selftest's "library" code, #undef _GNU_SOURCE so
that rseq.c controls whether or not it wants to build with _GNU_SOURCE.
Reported-by: Muhammad Usama Anjum <usama.anjum@collabora.com>
Acked-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
Acked-by: Oliver Upton <oliver.upton@linux.dev>
Acked-by: Anup Patel <anup@brainfault.org>
Reviewed-by: Muhammad Usama Anjum <usama.anjum@collabora.com>
Link: https://lore.kernel.org/r/20240423190308.2883084-1-seanjc@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
46 lines
1.1 KiB
C
46 lines
1.1 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
/*
|
|
* Copyright (C) 2023, Google LLC.
|
|
*/
|
|
#include <sys/ioctl.h>
|
|
|
|
#include "test_util.h"
|
|
#include "kvm_util.h"
|
|
#include "vmx.h"
|
|
|
|
void test_hwcr_bit(struct kvm_vcpu *vcpu, unsigned int bit)
|
|
{
|
|
const uint64_t ignored = BIT_ULL(3) | BIT_ULL(6) | BIT_ULL(8);
|
|
const uint64_t valid = BIT_ULL(18) | BIT_ULL(24);
|
|
const uint64_t legal = ignored | valid;
|
|
uint64_t val = BIT_ULL(bit);
|
|
uint64_t actual;
|
|
int r;
|
|
|
|
r = _vcpu_set_msr(vcpu, MSR_K7_HWCR, val);
|
|
TEST_ASSERT(val & ~legal ? !r : r == 1,
|
|
"Expected KVM_SET_MSRS(MSR_K7_HWCR) = 0x%lx to %s",
|
|
val, val & ~legal ? "fail" : "succeed");
|
|
|
|
actual = vcpu_get_msr(vcpu, MSR_K7_HWCR);
|
|
TEST_ASSERT(actual == (val & valid),
|
|
"Bit %u: unexpected HWCR 0x%lx; expected 0x%lx",
|
|
bit, actual, (val & valid));
|
|
|
|
vcpu_set_msr(vcpu, MSR_K7_HWCR, 0);
|
|
}
|
|
|
|
int main(int argc, char *argv[])
|
|
{
|
|
struct kvm_vm *vm;
|
|
struct kvm_vcpu *vcpu;
|
|
unsigned int bit;
|
|
|
|
vm = vm_create_with_one_vcpu(&vcpu, NULL);
|
|
|
|
for (bit = 0; bit < BITS_PER_LONG; bit++)
|
|
test_hwcr_bit(vcpu, bit);
|
|
|
|
kvm_vm_free(vm);
|
|
}
|