Received: by 2002:a05:6a10:eb17:0:0:0:0 with SMTP id hx23csp269069pxb; Fri, 3 Sep 2021 01:30:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzPyioS8eX2p1Mp1A/899RoDVFQkzM2ayPmN68P5DqOPhh1bWLnSBTmduXe1wKMa9mic7Ot X-Received: by 2002:a17:906:6009:: with SMTP id o9mr2916863ejj.266.1630657844878; Fri, 03 Sep 2021 01:30:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630657844; cv=none; d=google.com; s=arc-20160816; b=kD8vprilKv1yE4/EOrGzofIgAZpLUfSwabGzLuaQqylzPMOOMnHiO0S3vGrkWH5v/n /tWuwdUjhTzstz+N8f4l6poyLpXOOAIvoi1fuFZOE0PGH6/WuDClj4+RW5x7Flzw8/5a 0m6qasNIaE903fBkyn7TXh0trV63UHWkOC+GUWBbRsP8HVEvPjQLIM3287/v2F937cbV po/XT7bhafJU9m89Sw6JP2U3Y5kCHzQhpoI78hwV/Q8oIKcFw1vqIoPe7tXcZal4NP8h eq8ozuga/8WlAOjYagZmGKpuxH0CNkMQ9y/UtXC/Lz8poW8NLEv84V/jRrIwYYE8QfxZ g8vw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=784omy9+f5Am5nR2Vqkl2J0I13vidMEZa3qsfoNTT4c=; b=mOxL/UujpDqjLjC3kb4otAEjoOZF4n5G2C8LorkkYdS/RdeSmcRSvYVl3KyXqWRiw5 r39T0UMPIdeyCio5jstTD+/iHxnWgRLdn0kiGeoKaL3vQYvxSVqoRuoqSmICXDgPBnrv 1LpDb3IVFbjLBTWStqJk+AiAdWti0g3LM8JuMDaCL+1h26R0rJd7VaxjOa9K22gcmQMv ifGQZotHvPkHNYSWK+vY9G5wfQnE7D++31E7iuH+tAGmtqBnhLQdKbkj6vgnq+ifKvw0 nmP3KJ9fp4Z/sCSD1RadmJmXhidE8uJjDLJoNKG2AP1zhyY4O3f5I9oAbPmQIxPxjI3m WZOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=OoruEPaO; 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=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e18si4578136edj.207.2021.09.03.01.30.21; Fri, 03 Sep 2021 01:30:44 -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=@redhat.com header.s=mimecast20190719 header.b=OoruEPaO; 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=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348250AbhICI0j (ORCPT + 99 others); Fri, 3 Sep 2021 04:26:39 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:53256 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348171AbhICI0j (ORCPT ); Fri, 3 Sep 2021 04:26:39 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1630657539; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=784omy9+f5Am5nR2Vqkl2J0I13vidMEZa3qsfoNTT4c=; b=OoruEPaOqG+v63x8EC8z3lC03T5j2aFWlTDvLGYlbr4ex366xDZMXlubhUnYh5XyuQWffs Y/wxjSpkPLREc5gTW5gI4+e91NQi5qUDJ+Fe41PP4POfhYd7NlX8jG38EWpxvXotUAhgZl 443VhpwTdii+vL+N+J7A28uGf9RdacI= Received: from mail-ej1-f70.google.com (mail-ej1-f70.google.com [209.85.218.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-197-hL5bNUS7MvehW4wyeZH6Vw-1; Fri, 03 Sep 2021 04:25:38 -0400 X-MC-Unique: hL5bNUS7MvehW4wyeZH6Vw-1 Received: by mail-ej1-f70.google.com with SMTP id v19-20020a170906b013b02905b2f1bbf8f3so2347795ejy.6 for ; Fri, 03 Sep 2021 01:25:37 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=784omy9+f5Am5nR2Vqkl2J0I13vidMEZa3qsfoNTT4c=; b=GLjNSHpOHwUupQ3f3dv8l2aOTaLTlHYFUzRHGS6GxoC71/nbYAX2roUcpY/OAcwI2i C5Fv+ge/zipl98G7BC1SPfBRcjdHXUx9baNFrRd1vV30T92ihFplEtWoT0PFHqlbLRzp iwXaUSgHSlKQmi2D5bmJrzsbVAXEXgPq5deiw6IIBN08MeA29iFfZrvUzz7RDo9NL//U Oxvpzpw6/DjuTw1g0z15s2Tt9m4KGPEMxTXVLunw/c59WahjEsaz+9MmF97k6NhPIEWt Rlst6lURR6qACwj0+3dFgwHwRAE1o6YY2EmNgbDKqTAo2nCBKGGTKVH1HDZoVljO6egZ PNpA== X-Gm-Message-State: AOAM530Jxv36wlymDHiLTbxEySE1zP0kSYe8wWhfb4mH1LH2F5DnrmZR 5ndYygwB7TzcvDJG6MfzEkbV379XhXmhG5eYZJ7DFuVPp4wZCzgYD6FzVWYPI+w8eYCMGOnWsf2 cate53CQb0bWBd/p6OD8rJr+i X-Received: by 2002:a17:906:fcda:: with SMTP id qx26mr2880456ejb.121.1630657536933; Fri, 03 Sep 2021 01:25:36 -0700 (PDT) X-Received: by 2002:a17:906:fcda:: with SMTP id qx26mr2880426ejb.121.1630657536690; Fri, 03 Sep 2021 01:25:36 -0700 (PDT) Received: from gator.home (cst2-174-132.cust.vodafone.cz. [31.30.174.132]) by smtp.gmail.com with ESMTPSA id o19sm2450076edr.18.2021.09.03.01.25.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Sep 2021 01:25:36 -0700 (PDT) Date: Fri, 3 Sep 2021 10:25:34 +0200 From: Andrew Jones To: Raghavendra Rao Ananta Cc: Paolo Bonzini , Marc Zyngier , James Morse , Alexandru Elisei , Suzuki K Poulose , kvm@vger.kernel.org, Catalin Marinas , Peter Shier , linux-kernel@vger.kernel.org, Will Deacon , kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org Subject: Re: [PATCH v3 08/12] KVM: arm64: selftests: Add light-weight spinlock support Message-ID: <20210903082534.jz3r2defqnrt2ee6@gator.home> References: <20210901211412.4171835-1-rananta@google.com> <20210901211412.4171835-9-rananta@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210901211412.4171835-9-rananta@google.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Sep 01, 2021 at 09:14:08PM +0000, 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; > + > + 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"); > +} > -- Reviewed-by: Andrew Jones It makes sense that the explicit barriers in kvm-unit-tests weren't also inherited, because we already have the implicit barriers with these ld/st instruction variants. (I suppose we could improve the kvm-unit-tests implementation at some point.) Thanks, drew