Received: by 2002:a05:6500:2018:b0:1fb:9675:f89d with SMTP id t24csp874467lqh; Fri, 31 May 2024 23:18:53 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXAdTwdV4EFZztvwtwBXi51SU9KDvRZlQM5YgfueVnv0tHCIlwbOjuOHF6sHlCDnILXOJ4JQW9JTaC2jeifpG//h2ODc2Ya/kmlKFiteA== X-Google-Smtp-Source: AGHT+IEprei+SRxY3xKwZbD+YSE64DWcz7g3GlWpbPnof5jEKrk77WjG3y9TpYpqiJWMR/IHqvAg X-Received: by 2002:ac8:7c47:0:b0:43e:201e:bec0 with SMTP id d75a77b69052e-43ff54ff729mr35001121cf.50.1717222733299; Fri, 31 May 2024 23:18:53 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717222733; cv=pass; d=google.com; s=arc-20160816; b=ihuieJHK1ClCbRkupEfPE4DdIquex8EorZjkfrEOpdInADGlwVmNorXCqSxJafOYAb b+4c1Mf+H5ewZJ+KHxjzQXtgyEF5S5GaHjTQkn40+2rIJGBeHfHwzlRqnnwdEbxU8pKz BALtxGfRcUFXjaESALK53KQj0QtK29UQjjWcAxmnho39S+ndNWahOFr7rZKPIsc514Vy L3IF1eOtr6Y46ObbhHvRBpRrJxf5rgYiQPjdojY+KL4nRkdmpqaq1KU7E09XAryn+6dL dvdsI9Ksw/9EY7rOPO3nhD42w/P2Yn3+SomCFyohGWuppR5zmykAMjxkLG5rwZ7EA/R8 kvmQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=iJsUYeHsba9Zz3KMaenQGOvpMrrcTvNsXr3lILMV6K0=; fh=oGzkccDWXl0/EsQaQFxMDIiWtc84oaBWYnP4cI3RX4o=; b=Gvy3iS1Kb31tRyY9Ah0owBnhCiBYbJ0+pEhUTJvpZvMd1ZgW793MNd/+VaffmxROOC RpZ3i5bqTMn5YzGFRmMMjrLS2EDufVfUXkd1Z6KqFMkHKpgIdDsqrk9FW9efvFbY7ZT5 88gZvs7GyMEnOPa3oFbXl4WzXPlqANIsHI14S8J3/+liOGgbhsD3nbln94U7m0Qrv/U1 HJpoiNlier04ZhBhdbySIG/Lv9dEYCRr0BXoWxeGZh2S31bTCA3cFPGJ16v4Sw0se+Kw CsWHW0N7rNm8Wb2Mx4Czn/PYQfZfRhWBZD3O2q03Evn+OLuDnbGSs696sV5sEv1XzVg4 xLmg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=T3l21jx6; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-197720-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-197720-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id d75a77b69052e-43ff23dbe4bsi28424741cf.206.2024.05.31.23.18.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 May 2024 23:18:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-197720-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=T3l21jx6; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-197720-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-197720-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 0C28D1C223C7 for ; Sat, 1 Jun 2024 06:18:53 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3652C168C7; Sat, 1 Jun 2024 06:18:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="T3l21jx6" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4B569134BC; Sat, 1 Jun 2024 06:18:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717222724; cv=none; b=Yqngz9KLYlkvjr7uZCWW/rPegnwEnSQ050CezQ7oH4toToP1nR1e16Tnd8ZbI3cci51ht0x4bn13trDA5j+ZN4DrCqwTWwX62tCkOlv49/1P5W2lN39MUlgM0ijVACTn/Ft+Fql3YLk6NN7kc4Pv1wabVEPEReOPm67q1Jrkofo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717222724; c=relaxed/simple; bh=qv/TpTCLIjAt2eWLAMdx+nkTx3R9H3xNd5p/PM0KR/Y=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=d0vohHBlIUnbimfzeCKVv+lJfd0xavFKPQPuwCm+ivb5T/xoo8IJsZ6UlN8/gHmaX5dcQXGxy3QXwWhQf6ne/+rIlTpejm4INb03MoTDcPTfGkVuhJaHHgahzFgqJv1yOrDy0a0fzwhNm0mERhse4S0ZaFXIa8izneQ/hvyLxA8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=T3l21jx6; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id DC514C4AF11; Sat, 1 Jun 2024 06:18:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1717222723; bh=qv/TpTCLIjAt2eWLAMdx+nkTx3R9H3xNd5p/PM0KR/Y=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=T3l21jx6DRIWYURgryuGOT3ad9rDOO3VpyZ+i7KLuV3CcXvTubeGccG9yaHbBfJpY LsrboZ2sQWcX9Ec/3B69HuI2DM9AN2sbX2oU2rv+UPKctEENjsZN3ASah5wZia7ZK3 RNc651eTlMdCQiTtGD9ElY2qefzF2jz335808HGpaAPQZDz9k6TXGPKefYGoTbxyvg l0IAo0pij8zWp3qwUG62akh6IMydtrt0QifAulzwqW5jbbYmLZfoENjqQ7JyCHmInL jznE2vMfiu0ThzP5s4rWrOEo4GqI3tS5wfe6DIgNbuelsCyxK0vo7pd/AyLGoiISdF o0D+603L2oJlw== Received: by mail-ej1-f41.google.com with SMTP id a640c23a62f3a-a653972487fso228595366b.1; Fri, 31 May 2024 23:18:43 -0700 (PDT) X-Forwarded-Encrypted: i=1; AJvYcCXmfREBp6USUf3OnTP63Gx95HISStyRzVj8AY6KotvZpuXgFZf3nW7yWNR5aBIMWDb8RVmih7ArtGxC8cS06GAifyQZpkwr6LA0nixNJw6KGX/9bruaYwfYwulkLSzQf/q97ZgCXErIUKWh2EkGHcPiSPoojRFy6qu+472yM4892xupPw== X-Gm-Message-State: AOJu0YytL21p8ZuEH/VB0HE6rMYkLcaMNzgIIWzeWwxSCfdEJox1hcp+ 2l2tzEehhLZ4kGUrcSDpzne8jpN7qy9rV7NbXCUa6LFVJCaF0i/x3KfeRZFCjRj9t82ZsdRKmLt egIlezFRPXcvy9+MtzyW5zzRIor4= X-Received: by 2002:a17:906:4114:b0:a68:b6c7:516b with SMTP id a640c23a62f3a-a68b6c75209mr37608866b.73.1717222722373; Fri, 31 May 2024 23:18:42 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240528151052.313031-1-alexghiti@rivosinc.com> <20240528151052.313031-8-alexghiti@rivosinc.com> <39a9b28c-2792-45ce-a8c6-1703cab0f2de@ghiti.fr> In-Reply-To: From: Guo Ren Date: Sat, 1 Jun 2024 14:18:30 +0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 7/7] riscv: Add qspinlock support based on Zabha extension To: Andrea Parri Cc: Alexandre Ghiti , Alexandre Ghiti , Jonathan Corbet , Paul Walmsley , Palmer Dabbelt , Albert Ou , Peter Zijlstra , Ingo Molnar , Will Deacon , Waiman Long , Boqun Feng , Arnd Bergmann , Leonardo Bras , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, linux-arch@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, May 31, 2024 at 11:52=E2=80=AFPM Andrea Parri wrote: > > > > > + select ARCH_USE_QUEUED_SPINLOCKS if TOOLCHAIN_HAS_ZABHA > > > IIUC, we should make sure qspinlocks run with ARCH_WEAK_RELEASE_ACQUI= RE, > > > perhaps a similar select for the latter? (not a kconfig expert) > > > > > > Where did you see this dependency? And if that is really a dependency o= f > > qspinlocks, shouldn't this be under CONFIG_QUEUED_SPINLOCKS? (not a Kco= nfig > > expert too). > > The comment on smp_mb__after_unlock_lock() in include/linux/rcupdate.h > (the barrier is currently only used by the RCU subsystem) recalls: > > /* > * Place this after a lock-acquisition primitive to guarantee that > * an UNLOCK+LOCK pair acts as a full barrier. This guarantee applies > * if the UNLOCK and LOCK are executed by the same CPU or if the > * UNLOCK and LOCK operate on the same lock variable. > */ > #ifdef CONFIG_ARCH_WEAK_RELEASE_ACQUIRE > #define smp_mb__after_unlock_lock() smp_mb() /* Full ordering for lo= ck. */ > #else /* #ifdef CONFIG_ARCH_WEAK_RELEASE_ACQUIRE */ > #define smp_mb__after_unlock_lock() do { } while (0) > #endif /* #else #ifdef CONFIG_ARCH_WEAK_RELEASE_ACQUIRE */ > > Architectures whose UNLOCK+LOCK implementation does not (already) meet > the required "full barrier" ordering property (currently, only powerpc) > can overwrite the "default"/common #define for this barrier (NOP) and > meet the ordering by opting in for ARCH_WEAK_RELEASE_ACQUIRE. > > The (current) "generic" ticket lock implementation provides "the full > barrier" in its LOCK operations (hence in part. in UNLOCK+LOCK), cf. > > arch_spin_trylock() -> atomic_try_cmpxchg() > arch_spin_lock() -> atomic_fetch_add() > -> atomic_cond_read_acquire(); smp_mb() > > but the "UNLOCK+LOCK pairs act as a full barrier" property doesn't hold > true for riscv (and powerpc) when switching over to queued spinlock. Yes. > OTOH, I see no particular reason for other "users" of queued spinlocks > (notably, x86 and arm64) for selecting ARCH_WEAK_RELEASE_ACQUIRE. I looked at the riscv-unprivileged ppo section, seems RISC-V .rl -> .aq has RCsc annotations. ref: Explicit Synchronization 5. has an acquire annotation 6. has a release annotation 7. a and b both have RCsc annotations And for qspinlock: unlock: smp_store_release(&lock->locked, 0); lock: if (likely(atomic_try_cmpxchg_acquire(&lock->val, &val, _Q_LOCKED_V= AL))) If the hardware has Store-Release and CAS instructions, they all obey Explicit Synchronization rules. Then RISC-V "UNLOCK+LOCK" pairs act as a full barrier, right? > > But does this address your concern? Let me know if I misunderstood it. > > Andrea --=20 Best Regards Guo Ren