Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp243076pxb; Mon, 13 Sep 2021 18:09:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzmoXAJcKWUJrf/8ACDZBvjkudiZAQuv8DVbtTPaWna1beqnsi6jmV3ktqk0ar2iH88PoOe X-Received: by 2002:aa7:d598:: with SMTP id r24mr16282215edq.285.1631581775081; Mon, 13 Sep 2021 18:09:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631581775; cv=none; d=google.com; s=arc-20160816; b=A6BIidobv4Vl+NwtUmBdOob29ihW99sF7nHCJ8lzX/uewctOohH4Z133hHGVe6iZs7 /lAQRY/q+MG1CKJe1lQV4xOwUC8iPMCr1yln8JBwCnoDk6evRCE2ZcVu7d5UtnhMtudz REQ3hXviJBgx5XYgLI8zhD6Wroct88FeCRs9cH/zjnyAaUpiWs3DBwpnmyD9i4hLq2Oq Ua6xqKbU/WzHk5nthaLyX/ZLBAEzo/NAh5MFr/uM8j4DXOBGJh4rzvELdLkXUzX6YOS2 RLIN+cWF0cwOmx37er63/c3Hg+I93WA6SK6Rilb+lTngbaclkuY+nKOBRlb1k+OWozPH 1H+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=ap1ftYDLPyFEEpyKZVnsUXcIKPkxVpyeCr5WbufecSE=; b=N0mgmHcKhv6xM7ILgagxPNx12rCEgtGRAqqt+SwW32txKc0JWeADcJgeIHReqXJr1o jpFHK4pmPpVQbFT/sB4csW242+yZkrY6R6MynpzOhuit69uDCYGABWFPgrtFbsI7DMV5 HR1zgi1O99sWIy4rCN77gCRmhjomZPz5cmpKfpTo5ii64eeeKpLUA5A2VmgVnJF+VFNa KqFd3Jwox7HjlOXIA1DcKpzKkcyyEsLA/lqwtsZskNkCcJOPY5/O3sbw4o4hNqMZU51N FptgP3lYLY/Q2D/Bj2lLBbZecS9F/EXhfL3EBerKIkyXSafbY2KV6ky94rvgWLK8R2zy YKHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=AcXDQW2a; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w9si10062021edx.466.2021.09.13.18.09.11; Mon, 13 Sep 2021 18:09:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=AcXDQW2a; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348241AbhIMUwc (ORCPT + 99 others); Mon, 13 Sep 2021 16:52:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50004 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348128AbhIMUwA (ORCPT ); Mon, 13 Sep 2021 16:52:00 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CAB2BC061787 for ; Mon, 13 Sep 2021 13:50:06 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id i77-20020a25d150000000b005b1d20152b0so1406494ybg.14 for ; Mon, 13 Sep 2021 13:50:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=ap1ftYDLPyFEEpyKZVnsUXcIKPkxVpyeCr5WbufecSE=; b=AcXDQW2aX/QCoLBVgoVJAic/OiD0O6S8CfBLkjc0B2CrqFqCk5uLbsW6dJ4AFTLoZ6 Q2fftByGxtmCVMO2u6KMLhIyIdazkzO201OZ9A5JT+ZqwGc+PBXVGk13OgEm6dpt+OVy tDK89/2nsaMFN7jzfdNG34E7Do7K3rl24xmBNAq460Cpk9o9a7et3W/7f30CSnjchjV1 ZHAGyVgrJwN9+dg/w8X+UejF2PudA2Q95PuQqJjz+x6IfN0UuGB0rKNYA8QBD8CrfYIu pT5zJb+fAGKajNcU9X/9r0AcMHwnxJiD2DBJ1eEHmMlOO3c+l1t+vhfS330MAOk8IBqW VMKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=ap1ftYDLPyFEEpyKZVnsUXcIKPkxVpyeCr5WbufecSE=; b=1Q520Qn7qeEf0eUm2USqwYE2yIwrv36NP0Ep/tMryZWUCXpxrOyTZVaJL/VdACJZGP 8Qfj38ymkELvvL83l/+HbHkqUj4odKXapM+h9duSiYzyXQGeWmujT4KOh2tRDnP3ATiW 2ZjPuE8/cbeRZ2O7lRC8fxqwZgAQ8Tpg8Lc64S/wNwR0jQfkafnHy0h0ONxTivQcHw5s CQKS4ulYgD6xESQmKrJO89RyPE4AGEIWgQbpKZDnq2VReYUQf9YGZwJ66o0tK3ogJ4Hj E4ofOQCKsa5tzjKyBxzLYSq1V+Uhu44sRX5t6GJ55bfqGBtvIepaAtDkCcbsT+8AWK1L PR/w== X-Gm-Message-State: AOAM5325/dvFDb60s0vnlcX2InbGdyK0Dn5JcD9udNW68z8VEkqhrnJk FYTaTPp/Iz1m+wp/7SWXHnecIQoQKrfu X-Received: from rananta-virt.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1bcc]) (user=rananta job=sendgmr) by 2002:a5b:443:: with SMTP id s3mr18599130ybp.299.1631566206070; Mon, 13 Sep 2021 13:50:06 -0700 (PDT) Date: Mon, 13 Sep 2021 20:49:26 +0000 In-Reply-To: <20210913204930.130715-1-rananta@google.com> Message-Id: <20210913204930.130715-11-rananta@google.com> Mime-Version: 1.0 References: <20210913204930.130715-1-rananta@google.com> X-Mailer: git-send-email 2.33.0.309.g3052b89438-goog Subject: [PATCH v5 10/14] KVM: arm64: selftests: Add light-weight spinlock support From: Raghavendra Rao Ananta To: Paolo Bonzini , Marc Zyngier , Andrew Jones , James Morse , Alexandru Elisei , Suzuki K Poulose Cc: Catalin Marinas , Will Deacon , Peter Shier , Ricardo Koller , Oliver Upton , Reiji Watanabe , Jing Zhang , Raghavendra Rao Anata , linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org, kvm@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Reviewed-by: Oliver Upton Reviewed-by: Andrew Jones --- tools/testing/selftests/kvm/Makefile | 2 +- .../selftests/kvm/include/aarch64/spinlock.h | 13 +++++++++ .../selftests/kvm/lib/aarch64/spinlock.c | 27 +++++++++++++++++++ 3 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 tools/testing/selftests/kvm/include/aarch64/spinlock.h create mode 100644 tools/testing/selftests/kvm/lib/aarch64/spinlock.c diff --git a/tools/testing/selftests/kvm/Makefile b/tools/testing/selftests/kvm/Makefile index 5d05801ab816..61f0d376af99 100644 --- a/tools/testing/selftests/kvm/Makefile +++ b/tools/testing/selftests/kvm/Makefile @@ -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 diff --git a/tools/testing/selftests/kvm/include/aarch64/spinlock.h b/tools/testing/selftests/kvm/include/aarch64/spinlock.h new file mode 100644 index 000000000000..cf0984106d14 --- /dev/null +++ b/tools/testing/selftests/kvm/include/aarch64/spinlock.h @@ -0,0 +1,13 @@ +/* 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 */ diff --git a/tools/testing/selftests/kvm/lib/aarch64/spinlock.c b/tools/testing/selftests/kvm/lib/aarch64/spinlock.c new file mode 100644 index 000000000000..a076e780be5d --- /dev/null +++ b/tools/testing/selftests/kvm/lib/aarch64/spinlock.c @@ -0,0 +1,27 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * ARM64 Spinlock support + */ +#include + +#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"); +} -- 2.33.0.309.g3052b89438-goog