Skip to content

Commit 414de89

Browse files
rananta468Marc Zyngier
authored andcommitted
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: Raghavendra Rao Ananta <[email protected]> Reviewed-by: Oliver Upton <[email protected]> Reviewed-by: Andrew Jones <[email protected]> Signed-off-by: Marc Zyngier <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 17229bd commit 414de89

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

tools/testing/selftests/kvm/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ endif
3535

3636
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
3737
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
38-
LIBKVM_aarch64 = lib/aarch64/processor.c lib/aarch64/ucall.c lib/aarch64/handlers.S
38+
LIBKVM_aarch64 = lib/aarch64/processor.c lib/aarch64/ucall.c lib/aarch64/handlers.S lib/aarch64/spinlock.c
3939
LIBKVM_s390x = lib/s390x/processor.c lib/s390x/ucall.c lib/s390x/diag318_test_handler.c
4040

4141
TEST_GEN_PROGS_x86_64 = x86_64/cr4_cpuid_sync_test
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
3+
#ifndef SELFTEST_KVM_ARM64_SPINLOCK_H
4+
#define SELFTEST_KVM_ARM64_SPINLOCK_H
5+
6+
struct spinlock {
7+
int v;
8+
};
9+
10+
extern void spin_lock(struct spinlock *lock);
11+
extern void spin_unlock(struct spinlock *lock);
12+
13+
#endif /* SELFTEST_KVM_ARM64_SPINLOCK_H */
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
/*
3+
* ARM64 Spinlock support
4+
*/
5+
#include <stdint.h>
6+
7+
#include "spinlock.h"
8+
9+
void spin_lock(struct spinlock *lock)
10+
{
11+
int val, res;
12+
13+
asm volatile(
14+
"1: ldaxr %w0, [%2]\n"
15+
" cbnz %w0, 1b\n"
16+
" mov %w0, #1\n"
17+
" stxr %w1, %w0, [%2]\n"
18+
" cbnz %w1, 1b\n"
19+
: "=&r" (val), "=&r" (res)
20+
: "r" (&lock->v)
21+
: "memory");
22+
}
23+
24+
void spin_unlock(struct spinlock *lock)
25+
{
26+
asm volatile("stlr wzr, [%0]\n" : : "r" (&lock->v) : "memory");
27+
}

0 commit comments

Comments
 (0)