mirror of
https://github.com/raspberrypi/linux.git
synced 2025-12-17 15:24:33 +00: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>
55 lines
1.4 KiB
C
55 lines
1.4 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
/*
|
|
* Copyright (C) 2019, Google LLC.
|
|
*
|
|
* Tests for the IA32_XSS MSR.
|
|
*/
|
|
#include <sys/ioctl.h>
|
|
|
|
#include "test_util.h"
|
|
#include "kvm_util.h"
|
|
#include "vmx.h"
|
|
|
|
#define MSR_BITS 64
|
|
|
|
int main(int argc, char *argv[])
|
|
{
|
|
bool xss_in_msr_list;
|
|
struct kvm_vm *vm;
|
|
struct kvm_vcpu *vcpu;
|
|
uint64_t xss_val;
|
|
int i, r;
|
|
|
|
/* Create VM */
|
|
vm = vm_create_with_one_vcpu(&vcpu, NULL);
|
|
|
|
TEST_REQUIRE(kvm_cpu_has(X86_FEATURE_XSAVES));
|
|
|
|
xss_val = vcpu_get_msr(vcpu, MSR_IA32_XSS);
|
|
TEST_ASSERT(xss_val == 0,
|
|
"MSR_IA32_XSS should be initialized to zero");
|
|
|
|
vcpu_set_msr(vcpu, MSR_IA32_XSS, xss_val);
|
|
|
|
/*
|
|
* At present, KVM only supports a guest IA32_XSS value of 0. Verify
|
|
* that trying to set the guest IA32_XSS to an unsupported value fails.
|
|
* Also, in the future when a non-zero value succeeds check that
|
|
* IA32_XSS is in the list of MSRs to save/restore.
|
|
*/
|
|
xss_in_msr_list = kvm_msr_is_in_save_restore_list(MSR_IA32_XSS);
|
|
for (i = 0; i < MSR_BITS; ++i) {
|
|
r = _vcpu_set_msr(vcpu, MSR_IA32_XSS, 1ull << i);
|
|
|
|
/*
|
|
* Setting a list of MSRs returns the entry that "faulted", or
|
|
* the last entry +1 if all MSRs were successfully written.
|
|
*/
|
|
TEST_ASSERT(!r || r == 1, KVM_IOCTL_ERROR(KVM_SET_MSRS, r));
|
|
TEST_ASSERT(r != 1 || xss_in_msr_list,
|
|
"IA32_XSS was able to be set, but was not in save/restore list");
|
|
}
|
|
|
|
kvm_vm_free(vm);
|
|
}
|