Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp1874104pxb; Thu, 7 Oct 2021 17:34:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy7y0XMPWeF+AdpSfl4BPaEBmC1udDh6pdHhNFu/+ol3ANYxJ0XV2X8wANkuPwkZ8jtZBh/ X-Received: by 2002:a17:90b:4f46:: with SMTP id pj6mr8364592pjb.63.1633653257855; Thu, 07 Oct 2021 17:34:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633653257; cv=none; d=google.com; s=arc-20160816; b=zgWNw1ffxosyYCSNTqlLeNdZAAbzJNBMJqkb8ezSUz2ILgHRR0wMj78GRnbXChyLtB a942NZprv/lQMNd5+zuxU8p2uc5Z66n6pdIYjm5OfdPtQihy5X9VT6eBRtZKaJOgIk8x nR24Z31Riu+cjrchC0ZjDX9ZP3nWMB4X4ZDG2GG+MJ3mf3+4h6siCHOScUbcqHoxc6w3 efT/eGSezT+w/QDYQfHF+bTQ7cp3fFvSRTv78MH74lX9vPycRYsUBhasChfxgakyrT72 pYFjMgN5Bw9SbSNsz6xYcjGrTaSTtG4nlmo8ysInHyjYPJfBl4oIoClbSmvukbMWAx1/ 0QTA== 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=Q7y95FHiaft0lqoqJNHjM0WpKZuDHTR8jqan7ASS4mc=; b=t7j2fdfc7Sv18aZrhe52WL0FqRQpW8Fbe1YQY5Ol9/7qg+VWMIpfpjUvwfqnVo+sex WPpuQefM7SgQfrRR41zs7Rjl0r7uwr0RQgbIEABjwQvewxfSII3LOVVOvwduXnF14Hiq 21q82RRccAanl1onAL9BECfbg9+/ojdYf/DTk+Rdc5fFXey7DbHOPuOWUx0nlVMXQeAX 5kchhx5NyeSyuHlGcIJDm8D2Rci9LlhZCuCE9MJPMdXfs5nviBx1Yu9QAkGhGFq5HWNA Ff8dAS1u+dEFWI0PGZPlSFMg6Wx9JDpDm85zt8X0t19Vbu21Cr2e6xtdQb6mwJvf4Naz hYCg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=l71lnosf; 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 d20si1357621pgl.42.2021.10.07.17.34.04; Thu, 07 Oct 2021 17:34:17 -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=l71lnosf; 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 S242500AbhJGXhh (ORCPT + 99 others); Thu, 7 Oct 2021 19:37:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42624 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242591AbhJGXhM (ORCPT ); Thu, 7 Oct 2021 19:37:12 -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 9297BC061776 for ; Thu, 7 Oct 2021 16:35:14 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id i83-20020a252256000000b005b67a878f56so10075937ybi.17 for ; Thu, 07 Oct 2021 16:35:14 -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=Q7y95FHiaft0lqoqJNHjM0WpKZuDHTR8jqan7ASS4mc=; b=l71lnosf3HrI9aon/pt84xBBqjPvBzcdmQk34E6QmaZ5JHCUgHDmwxcybuFjVIMIWE DfdROrINx5+ZTq7qnZCDLThV0G9tJnyxuVdst9iasCeJ0Ekpv2K7jNrbjx1MIG8EqeNq vUHEi35UsuqDXC9Wf9+CSPx6nFgOAhC688SK0QDcRaKvseHIUat5El6C59j7YUWItsl/ dbVH1XRCILfzOd7Aqo4Ktn2T+t8Yt6LVXHFhRKtCJwkUcHgJXWqpMcoQWhXLSijGDF3v qPUcNy1AS0Dt+O7cJxJ7JU6Nzi3fhXGwc/geU/Pmuf8eeT4TzydnMukbrTx4dRN9RhOI hajw== 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=Q7y95FHiaft0lqoqJNHjM0WpKZuDHTR8jqan7ASS4mc=; b=pUOqVLMkFDLQYon5TylPlkqPpIguJ64EWLj7/X4oWsfUG3JBqIV4x9xzI4E4Fo2B1M dyDR9w4adLevANyY6jVCEMZeTq7U71VHlg5FRb2MnMm21BV4fVk/seaSocTQAlS4kzV8 k+ZxtuPZzHHAFeQz929VpxOCB+GxlI/ZO8wsyNYlmnMzEJxWlV1xUGtll0qZrtbDTrWP gnVAViV7JjzR3V+Xt2XcGFMCyHK4odTs+bSamISZLNQtTe/kVllUHUDQHqd9td8+L2kM 23keoqrAE0Tvj5AFDCQlP8tgS92dgT/cy0hdpN110ZwnCVT1VWs17f/RIqNwfmBBHVKy 9WUg== X-Gm-Message-State: AOAM5305wtJ/FJD/EdZL2dPiH3ua2DUBtU4bvxvfevtXmPLe3YF8ukj/ CpieOlqjc/iRIpbW5Ig6ByRz0Ns3yHya X-Received: from rananta-virt.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1bcc]) (user=rananta job=sendgmr) by 2002:a25:2a91:: with SMTP id q139mr8300650ybq.146.1633649713791; Thu, 07 Oct 2021 16:35:13 -0700 (PDT) Date: Thu, 7 Oct 2021 23:34:35 +0000 In-Reply-To: <20211007233439.1826892-1-rananta@google.com> Message-Id: <20211007233439.1826892-12-rananta@google.com> Mime-Version: 1.0 References: <20211007233439.1826892-1-rananta@google.com> X-Mailer: git-send-email 2.33.0.882.g93a45727a2-goog Subject: [PATCH v8 11/15] 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 d1774f461393..d8fb91a5ea7b 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.882.g93a45727a2-goog