Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp2832528rwb; Fri, 20 Jan 2023 07:57:08 -0800 (PST) X-Google-Smtp-Source: AMrXdXts2UxS6E1oHLIR/JDCX/5yOcw1LcwL0fZvglKR8aOa9oSPNCVGNjyOgpujmxnd9CsKSl8E X-Received: by 2002:a17:907:6c16:b0:86f:3dfa:4016 with SMTP id rl22-20020a1709076c1600b0086f3dfa4016mr17948854ejc.7.1674230227959; Fri, 20 Jan 2023 07:57:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674230227; cv=none; d=google.com; s=arc-20160816; b=QC4v6fohvWCWYxDx9PXLQxaLVR4JKYyaw+XRxWy5BjxGBbWsZvi/HboLgatnBWbQq7 zZYaRuPT9O/HGZ3wIV15JFLeSVMDYpQaSF5ffMWeZy2OtFhhNQh1UD+j+fTjbyVpVJJo 0UjHpTFNhumCTCe502MtCP6jj9mlNvJEsv+KkHMydUDHNs7httIJeVrUn1ejNZblfHi6 vlSCb7LiSCpAQNRRhVBhsRk9eRySxzVD9Fwi42q58sPNQXKMCd6ePCu3Qcgk8Oc46jV+ f7JaQltRHdYn5FQULk6hqjL09/jgoj68kHtjpUp5aGJcj9IElhMYmZ3jf2S9CQpF3njY UvTA== 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; bh=OfZNyv+wqpfXHUuRbGDIFT6MJ32MTvSFAMU2tWVxdbw=; b=L1IKXzfvrnw5OqFYOX29vQ1vG7nE+WF5eQT3Ju2O/HPEbNH03Ufb6wjmeV916Y9lQE g1Mq69Qm/knmBu2O6neEAtIve+gtXKpYTl37D/bS8RbQAJQqsd1lRR/vCvQVWP53+rL0 KD7EdRdXqbSe+8SI+JxE/sPU4NMkwayNq7UaAj6/HHK4Fu77o1t1CPuTIdg0+xEFXXCN yhYNuGu/oMXIKAcIjnYMJ0dHUeKrh6GoYoYwzwEY5nLqb6MqMy3sIuW6ra5uUZefwLS1 XiGg9P+Rzm+sLdWux6w/sTfRHgfHuH04o8HNXcuHSu5aDyYbN0srxqHOtJ0RObcOHTgy RcYw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dd7-20020a1709069b8700b007ad9c8201e7si23386022ejc.93.2023.01.20.07.56.52; Fri, 20 Jan 2023 07:57:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231331AbjATPTL (ORCPT + 49 others); Fri, 20 Jan 2023 10:19:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50782 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231339AbjATPTJ (ORCPT ); Fri, 20 Jan 2023 10:19:09 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id C8A2FDB79A; Fri, 20 Jan 2023 07:19:05 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id B62521515; Fri, 20 Jan 2023 07:19:46 -0800 (PST) Received: from FVFF77S0Q05N (unknown [10.57.11.233]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 175CD3F67D; Fri, 20 Jan 2023 07:18:55 -0800 (PST) Date: Fri, 20 Jan 2023 15:18:48 +0000 From: Mark Rutland To: Yann Sionneau Cc: Arnd Bergmann , Jonathan Corbet , Thomas Gleixner , Marc Zyngier , Rob Herring , Krzysztof Kozlowski , Will Deacon , Peter Zijlstra , Boqun Feng , Eric Biederman , Kees Cook , Oleg Nesterov , Ingo Molnar , Waiman Long , "Aneesh Kumar K.V" , Andrew Morton , Nick Piggin , Paul Moore , Eric Paris , Christian Brauner , Paul Walmsley , Palmer Dabbelt , Albert Ou , Jules Maselbas , Guillaume Thouvenin , Clement Leger , Vincent Chardon , Marc =?utf-8?B?UG91bGhpw6hz?= , Julian Vetter , Samuel Jones , Ashley Lesdalons , Thomas Costis , Marius Gligor , Jonathan Borne , Julien Villette , Luc Michel , Louis Morhet , Julien Hascoet , Jean-Christophe Pince , Guillaume Missonnier , Alex Michon , Huacai Chen , WANG Xuerui , Shaokun Zhang , John Garry , Guangbin Huang , Bharat Bhushan , Bibo Mao , Atish Patra , "Jason A. Donenfeld" , Qi Liu , Jiaxun Yang , Catalin Marinas , Mark Brown , Janosch Frank , Alexey Dobriyan , Benjamin Mugnier , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-mm@kvack.org, linux-arch@vger.kernel.org, linux-audit@redhat.com, linux-riscv@lists.infradead.org, bpf@vger.kernel.org Subject: Re: [RFC PATCH v2 11/31] kvx: Add atomic/locking headers Message-ID: References: <20230120141002.2442-1-ysionneau@kalray.eu> <20230120141002.2442-12-ysionneau@kalray.eu> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230120141002.2442-12-ysionneau@kalray.eu> X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jan 20, 2023 at 03:09:42PM +0100, Yann Sionneau wrote: > Add common headers (atomic, bitops, barrier and locking) for basic > kvx support. > > Co-developed-by: Clement Leger > Signed-off-by: Clement Leger > Co-developed-by: Jules Maselbas > Signed-off-by: Jules Maselbas > Co-developed-by: Julian Vetter > Signed-off-by: Julian Vetter > Co-developed-by: Julien Villette > Signed-off-by: Julien Villette > Co-developed-by: Yann Sionneau > Signed-off-by: Yann Sionneau > --- > > Notes: > V1 -> V2: > - use {READ,WRITE}_ONCE for arch_atomic64_{read,set} > - use asm-generic/bitops/atomic.h instead of __test_and_*_bit > - removed duplicated includes > - rewrite xchg and cmpxchg in C using builtins for acswap insn Thanks for those changes. I see one issue below (instantiated a few times), but other than that this looks good to me. [...] > +#define ATOMIC64_RETURN_OP(op, c_op) \ > +static inline long arch_atomic64_##op##_return(long i, atomic64_t *v) \ > +{ \ > + long new, old, ret; \ > + \ > + do { \ > + old = v->counter; \ This should be arch_atomic64_read(v), in order to avoid the potential for the compiler to replay the access and introduce ABA races and other such problems. For details, see: https://lore.kernel.org/lkml/Y70SWXHDmOc3RhMd@osiris/ https://lore.kernel.org/lkml/Y71LoCIl+IFdy9D8@FVFF77S0Q05N/ I see that the generic 32-bit atomic code suffers from that issue, and we should fix it. > + new = old c_op i; \ > + ret = arch_cmpxchg(&v->counter, old, new); \ > + } while (ret != old); \ > + \ > + return new; \ > +} > + > +#define ATOMIC64_OP(op, c_op) \ > +static inline void arch_atomic64_##op(long i, atomic64_t *v) \ > +{ \ > + long new, old, ret; \ > + \ > + do { \ > + old = v->counter; \ Likewise, arch_atomic64_read(v) here. > + new = old c_op i; \ > + ret = arch_cmpxchg(&v->counter, old, new); \ > + } while (ret != old); \ > +} > + > +#define ATOMIC64_FETCH_OP(op, c_op) \ > +static inline long arch_atomic64_fetch_##op(long i, atomic64_t *v) \ > +{ \ > + long new, old, ret; \ > + \ > + do { \ > + old = v->counter; \ Likewise, arch_atomic64_read(v) here. > + new = old c_op i; \ > + ret = arch_cmpxchg(&v->counter, old, new); \ > + } while (ret != old); \ > + \ > + return old; \ > +} > + > +#define ATOMIC64_OPS(op, c_op) \ > + ATOMIC64_OP(op, c_op) \ > + ATOMIC64_RETURN_OP(op, c_op) \ > + ATOMIC64_FETCH_OP(op, c_op) > + > +ATOMIC64_OPS(and, &) > +ATOMIC64_OPS(or, |) > +ATOMIC64_OPS(xor, ^) > +ATOMIC64_OPS(add, +) > +ATOMIC64_OPS(sub, -) > + > +#undef ATOMIC64_OPS > +#undef ATOMIC64_FETCH_OP > +#undef ATOMIC64_OP > + > +static inline int arch_atomic_add_return(int i, atomic_t *v) > +{ > + int new, old, ret; > + > + do { > + old = v->counter; Likewise, arch_atomic64_read(v) here. > + new = old + i; > + ret = arch_cmpxchg(&v->counter, old, new); > + } while (ret != old); > + > + return new; > +} > + > +static inline int arch_atomic_sub_return(int i, atomic_t *v) > +{ > + return arch_atomic_add_return(-i, v); > +} > + > +#include > + > +#endif /* _ASM_KVX_ATOMIC_H */ Otherwise, the atomics look good to me. Thanks, Mark.