Commit 414de89d authored by Raghavendra Rao Ananta's avatar Raghavendra Rao Ananta Committed by Marc Zyngier
Browse files

KVM: arm64: selftests: Add light-weight spinlock support



Add a simpler version of spinlock support for ARM64 for
the guests to use.

The implementation is loosely based on the spinlock
implementation in kvm-unit-tests.

Signed-off-by: default avatarRaghavendra Rao Ananta <rananta@google.com>
Reviewed-by: default avatarOliver Upton <oupton@google.com>
Reviewed-by: default avatarAndrew Jones <drjones@redhat.com>
Signed-off-by: default avatarMarc Zyngier <maz@kernel.org>
Link: https://lore.kernel.org/r/20211007233439.1826892-12-rananta@google.com
parent 17229bdc
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -35,7 +35,7 @@ endif

LIBKVM = lib/assert.c lib/elf.c lib/io.c lib/kvm_util.c lib/rbtree.c lib/sparsebit.c lib/test_util.c lib/guest_modes.c lib/perf_test_util.c
LIBKVM_x86_64 = lib/x86_64/apic.c lib/x86_64/processor.c lib/x86_64/vmx.c lib/x86_64/svm.c lib/x86_64/ucall.c lib/x86_64/handlers.S
LIBKVM_aarch64 = lib/aarch64/processor.c lib/aarch64/ucall.c lib/aarch64/handlers.S
LIBKVM_aarch64 = lib/aarch64/processor.c lib/aarch64/ucall.c lib/aarch64/handlers.S lib/aarch64/spinlock.c
LIBKVM_s390x = lib/s390x/processor.c lib/s390x/ucall.c lib/s390x/diag318_test_handler.c

TEST_GEN_PROGS_x86_64 = x86_64/cr4_cpuid_sync_test
+13 −0
Original line number Diff line number Diff line
/* SPDX-License-Identifier: GPL-2.0 */

#ifndef SELFTEST_KVM_ARM64_SPINLOCK_H
#define SELFTEST_KVM_ARM64_SPINLOCK_H

struct spinlock {
	int v;
};

extern void spin_lock(struct spinlock *lock);
extern void spin_unlock(struct spinlock *lock);

#endif /* SELFTEST_KVM_ARM64_SPINLOCK_H */
+27 −0
Original line number Diff line number Diff line
// SPDX-License-Identifier: GPL-2.0
/*
 * ARM64 Spinlock support
 */
#include <stdint.h>

#include "spinlock.h"

void spin_lock(struct spinlock *lock)
{
	int val, res;

	asm volatile(
	"1:	ldaxr	%w0, [%2]\n"
	"	cbnz	%w0, 1b\n"
	"	mov	%w0, #1\n"
	"	stxr	%w1, %w0, [%2]\n"
	"	cbnz	%w1, 1b\n"
	: "=&r" (val), "=&r" (res)
	: "r" (&lock->v)
	: "memory");
}

void spin_unlock(struct spinlock *lock)
{
	asm volatile("stlr wzr, [%0]\n"	: : "r" (&lock->v) : "memory");
}