Skip to content

Commit

Permalink
KVM: selftests: Mark "guest_saw_irq" as volatile in xen_shinfo_test
Browse files Browse the repository at this point in the history
Tag "guest_saw_irq" as "volatile" to ensure that the compiler will never
optimize away lookups.  Relying on the compiler thinking that the flag
is global and thus might change also works, but it's subtle, less robust,
and looks like a bug at first glance, e.g. risks being "fixed" and
breaking the test.

Make the flag "static" as well since convincing the compiler it's global
is no longer necessary.

Alternatively, the flag could be accessed with {READ,WRITE}_ONCE(), but
literally every access would need the wrappers, and eking out performance
isn't exactly top priority for selftests.

Signed-off-by: Sean Christopherson <seanjc@google.com>
Message-Id: <20221013211234.1318131-17-seanjc@google.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
  • Loading branch information
Sean Christopherson authored and Paolo Bonzini committed Oct 28, 2022
1 parent a51abbb commit 5addaf5
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion tools/testing/selftests/kvm/x86_64/xen_shinfo_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ struct {
struct kvm_irq_routing_entry entries[2];
} irq_routes;

bool guest_saw_irq;
static volatile bool guest_saw_irq;

static void evtchn_handler(struct ex_regs *regs)
{
Expand Down

0 comments on commit 5addaf5

Please sign in to comment.