Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp743638pxb; Thu, 2 Sep 2021 14:10:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyJ8SgdDBKEGE0aOnpncW1bHy4HYcegZDYatrAe+UnWbWi8OnCYrWKn8QOC/fq8BzvVBupQ X-Received: by 2002:a17:907:6297:: with SMTP id nd23mr206516ejc.62.1630617038331; Thu, 02 Sep 2021 14:10:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630617038; cv=none; d=google.com; s=arc-20160816; b=TMOD7NREZZMEmjEUHvSbD/628UbRJYxA3iiAWTBH+5qG+PgTStfC/DLBCSXmneWyZC ees8R4ALqLpZ4bmZ2bLmyEG+yqKkoabfWOiX/RDsNn+Bg5Frr4yihFnCPg8POhn36zgi myrN1nUsRKtu9LH9/Adww2YKe11i2XMPwGO1ELcFJOXrPWP0JVasAJxuIIGwZdDEvI2k x023dsE0QrTt1dhhMFnCqX3yyeu14NE0/HUa72Olv+f6AMyxMbyH+6PCVHG5xnvjoh5q t8B49iErYR7cYmckC3AADSoSIvcz92825tmLvNyXBciAW4zjVxBFQwgoRuWRmQTyPomJ WmRQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=XguslLdPIXxVxFmZIelMYc4XAgNZi0tFqmUYgQxOp5M=; b=OLuI6NfHL0LKvv4tSjn/YgRMkDzroDQVHouIMQG4O7AjGFNeC1IgpfPdZmSbHTix4W 7Wot/tlPfIHTvw0wRAAUkn9hFNBWprwlA9zCTySJT3rkl713UcMKGQ7SauVSxowofCPx 2MBfLMLg3t8ZQrtLAzKIZlrYXl+TUEESRbIKZrJxgakPGUCcKJ/klE1j43MKdv/5vXvU zf06xz0JTnBIN9UBuPns9xApEXg6lBzs1cb8K6dJTbsPCuSidWAk4FBSTXoafL9UJzJx wmBPE0735m1HTPBmd+HHyge3ZUob2eoMkcE10sYPbWzRM7UrxQiOYzADy9poVzCYw9sE 8PmA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=GRl6nsj+; 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 g4si3174770eds.455.2021.09.02.14.09.59; Thu, 02 Sep 2021 14:10:38 -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=20161025 header.b=GRl6nsj+; 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 S1346400AbhIBVIN (ORCPT + 99 others); Thu, 2 Sep 2021 17:08:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56712 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344283AbhIBVIM (ORCPT ); Thu, 2 Sep 2021 17:08:12 -0400 Received: from mail-lf1-x135.google.com (mail-lf1-x135.google.com [IPv6:2a00:1450:4864:20::135]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7D45EC061757 for ; Thu, 2 Sep 2021 14:07:13 -0700 (PDT) Received: by mail-lf1-x135.google.com with SMTP id t12so7058980lfg.9 for ; Thu, 02 Sep 2021 14:07:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=XguslLdPIXxVxFmZIelMYc4XAgNZi0tFqmUYgQxOp5M=; b=GRl6nsj+q44z1Ha5UTrEb/YbOYWdRlaK0fubHiqDSnXS8sWWJcwTGWoDIW2UCbn6Zr Cin4HyfAIjK1TVjdigRZ9ja7ecjITroQf2sZC4PC79Xaz+k+vtV6XvjQXxLLGFS3Tgvd rZxyeNE+Shn/fy1exk3CDfTmR+G77EyuLt2WAGw8j5ATWWbDt8eRpAfxm4LgmHc7p2us SdVcNLtNJiQPkMgU50e+CmDwIvKnHFdoc0jTOcrwRN3F83mIHv0PA+s/3GaM1tNx243Z gMITCnX0rWgJVXu10k47y/pC6aRMKRjTFKL60xjdzuDoDoXohJ5vAGs0C1TJ9uxuED5z b2tA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=XguslLdPIXxVxFmZIelMYc4XAgNZi0tFqmUYgQxOp5M=; b=GW7sf6wXcaPIBYA4f1I6p/Se7PeTea0N5fYdV7kXLpHWP//UyP9RKDcXCu4YhxT+4J NmDQoz+EWILlLiuYB0jNrycui/CKz65j4+vPZt4KaHHWYrf7Pf3uI73YJbuOQZjKZP1O InyWEIgyKjX4BJrQw5Xr86Kum6cePinsZi8wSF8eIxPSZrA4OkP6YvrOR6WRDUETgYZd FnkQ7Ndf6eb4XXEv6TOFwqwIByvTDny7+LiP0d+W2lZUfOVzqSI7XMVbTrf7Mi05DKNA bwuTgaEXFcoE+tdutKk93upcGSBBMACaUIf5iv03/dLiO2KUWCDSmEpwEbSJdOjB/qiM J78Q== X-Gm-Message-State: AOAM531RSvAGX+fSeujWeVkcFgypNg2XijCugT0fPPVGBoZsw5rmBlSd nSMtySTsNsylKJ+EoUkhH1Yb8tdp3gB7YTISxUKRrQ== X-Received: by 2002:a05:6512:6c3:: with SMTP id u3mr80050lff.411.1630616831502; Thu, 02 Sep 2021 14:07:11 -0700 (PDT) MIME-Version: 1.0 References: <20210901211412.4171835-1-rananta@google.com> <20210901211412.4171835-9-rananta@google.com> In-Reply-To: <20210901211412.4171835-9-rananta@google.com> From: Oliver Upton Date: Thu, 2 Sep 2021 14:06:58 -0700 Message-ID: Subject: Re: [PATCH v3 08/12] KVM: arm64: selftests: Add light-weight spinlock support To: Raghavendra Rao Ananta Cc: Paolo Bonzini , Marc Zyngier , James Morse , Alexandru Elisei , Suzuki K Poulose , Catalin Marinas , Will Deacon , Peter Shier , Ricardo Koller , Reiji Watanabe , Jing Zhang , 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 On Wed, Sep 1, 2021 at 2:14 PM Raghavendra Rao Ananta wrote: > > 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 > --- > 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..6d66a3dac237 > --- /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) > +{ > + uint32_t val, res; nit: use 'int' to match the lock value type. > + > + 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.153.gba50c8fa24-goog > Otherwise, LGTM. Reviewed-by: Oliver Upton