From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id CB962C38A23 for ; Fri, 20 Jan 2023 19:03:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1674241396; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=HKMolucf0pZRYmgENQ3GoKW+Zuq9ejlcjXS+yAJhLgU=; b=XeoqvnV8oItdDoJDDw/Gfso6GPcL2tvyauQJQwFxsih6esI4bcDbXKg6QJsAr83EuaIy+1 aA4LQP6KtmS0wLp4qWNqTZrB8NPZli0PAppt/Jpluck1hUFgtjvp36bABVFvnLK6E4OHQE 2ZRczKmn4Ley2RMqzTP3199NodY8Oj4= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-556-HBSi-uxvOyuh-sYvUBBFvQ-1; Fri, 20 Jan 2023 14:03:15 -0500 X-MC-Unique: HBSi-uxvOyuh-sYvUBBFvQ-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 589B73C13A05; Fri, 20 Jan 2023 19:02:56 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4992F1121315; Fri, 20 Jan 2023 19:02:56 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 3F8D119465B6; Fri, 20 Jan 2023 19:02:56 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 1162B1946588 for ; Fri, 20 Jan 2023 15:25:48 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id E698D2026D2B; Fri, 20 Jan 2023 15:25:47 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast03.extmail.prod.ext.rdu2.redhat.com [10.11.55.19]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DE4902026D68 for ; Fri, 20 Jan 2023 15:25:47 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id BD30788B7D7 for ; Fri, 20 Jan 2023 15:25:47 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by relay.mimecast.com with ESMTP id us-mta-277-gccQkcHKNA-QTjhFs_G--A-1; Fri, 20 Jan 2023 10:25:43 -0500 X-MC-Unique: gccQkcHKNA-QTjhFs_G--A-1 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 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 In-Reply-To: <20230120141002.2442-12-ysionneau@kalray.eu> X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-Mailman-Approved-At: Fri, 20 Jan 2023 19:02:49 +0000 X-BeenThere: linux-audit@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Audit Discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Jason A. Donenfeld" , Marc =?utf-8?B?UG91bGhpw6hz?= , linux-doc@vger.kernel.org, Peter Zijlstra , Catalin Marinas , Atish Patra , Jiaxun Yang , Julien Hascoet , Clement Leger , linux-mm@kvack.org, devicetree@vger.kernel.org, Louis Morhet , Krzysztof Kozlowski , linux-riscv@lists.infradead.org, Will Deacon , Guangbin Huang , Alex Michon , Thomas Costis , Jonathan Corbet , Jonathan Borne , Marc Zyngier , Huacai Chen , bpf@vger.kernel.org, Ingo Molnar , linux-arch@vger.kernel.org, Jean-Christophe Pince , Waiman Long , Bharat Bhushan , Qi Liu , Alexey Dobriyan , Luc Michel , John Garry , Ashley Lesdalons , Albert Ou , Kees Cook , Arnd Bergmann , Samuel Jones , Boqun Feng , Guillaume Thouvenin , Julian Vetter , Nick Piggin , Shaokun Zhang , Rob Herring , Bibo Mao , Paul Walmsley , WANG Xuerui , linux-audit@redhat.com, Thomas Gleixner , Marius Gligor , Janosch Frank , Julien Villette , Jules Maselbas , Christian Brauner , Benjamin Mugnier , Vincent Chardon , Guillaume Missonnier , Oleg Nesterov , Eric Paris , linux-kernel@vger.kernel.org, Mark Brown , Palmer Dabbelt , Eric Biederman , "Aneesh Kumar K.V" , Andrew Morton Errors-To: linux-audit-bounces@redhat.com Sender: "Linux-audit" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 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. -- Linux-audit mailing list Linux-audit@redhat.com https://listman.redhat.com/mailman/listinfo/linux-audit