Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp947471imd; Thu, 1 Nov 2018 08:02:12 -0700 (PDT) X-Google-Smtp-Source: AJdET5czh0omRGBo6hIi4todeh8r8mjy3Ok1QLcSNb/Hs22NzBMg0ceS7w8KuhKRjzREyLpaVCkH X-Received: by 2002:aa7:800b:: with SMTP id j11-v6mr7873069pfi.73.1541084532148; Thu, 01 Nov 2018 08:02:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1541084532; cv=none; d=google.com; s=arc-20160816; b=LBmRzjEtDK8qgYYl5q3b6SvoZHfL0K32hvmPvUOYV8kVc3covMrB0sFqTdPNHi94GD ZsXLFLmphBQaZgN7t3lRsnRGetdP97DDoiA0e41OazgY+7dAJJ7debQw0Gx2flp5MnjB lB9mlJ/kSaz8oY+cyLb+pz/AOnseXy86egHXKYj+Cjur86pu6viWKFyJnIt6C6I2Mg3y TrU3pblHAm+bZPcXdw1snjMc/KMpRp6dbdo3kIrzrx9FAyKNql88vcRQWx9kvFviIfys haNjj0hNnPpyUQHQVPoBclkrVqhhwPVqAws5gRTr6a0ZFbDTK9qs15wszQhKmLHxG5Ds ItjA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=+Rt73Dkjs07M2EcZc58W7I7bXnGaShUh703bpJozHxs=; b=bmxSYnkm2TMNqw82cCE3HB0xBV7KABCUJ4me/Vbh0cJy+WiagO0D+g5yZjcNo3HBrq ijXk4egBLp8v7qVuIpOAHhjDwy8AXAVaJ4UnwQ1os5hsI8VGLMfA9N0TySuELWBec2eI sXWuwIbuQcqWtTtTH66fE6E6ZpuHTZtioAWOUKQM9+XjCuw6KC0dNgEh4mlRMue3tbhV h0PVSS8ID0Y25cKQiL2/xt5K1ONALdlq8lGZ90V8d/q9j0xqH+ANN2zBnb+DbCCXmV/L detxtenWsUN5c2P0znDrPxJyeJcxLHKiQWHe2KYcuJ5JkVRkbIBI0Gxryqcjwzos2Xrf WtLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=QxfYez8d; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n11-v6si6644411plg.300.2018.11.01.08.01.56; Thu, 01 Nov 2018 08:02:12 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=QxfYez8d; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728900AbeKBAEG (ORCPT + 99 others); Thu, 1 Nov 2018 20:04:06 -0400 Received: from merlin.infradead.org ([205.233.59.134]:52034 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728440AbeKBAEF (ORCPT ); Thu, 1 Nov 2018 20:04:05 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=+Rt73Dkjs07M2EcZc58W7I7bXnGaShUh703bpJozHxs=; b=QxfYez8di/tjSKl0d4uXLdjw8 Qh9+4+H80o9W5ZaFFgn2RytbCxiV+XYrXcvapx57mvZ/kjzhFJL4TuwB0jfiv5LXADFrx3xlWH/3F Bm4mv7XcnrUfzuyfhKr6P2XDMxrwSxZnNrIa7e0CfmWz81voW81Dp7XMuj8m0yYza3cd+99CbxPRO Vz4pf9+v1WoNlCM8G7mY3IDP4ecPaf3AOavv1l4AcDlvagHUCRGR5oa0Wr5J1I0hFLZnS7rjyifsz NT5fkdg5sA+rlsNuofZqBu9htiulkOWkzurb4sVM206Ddsnxp8eFlbHinDCwsI7NxJ4YkyQiUz2Db bKC4siUSQ==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=hirez.programming.kicks-ass.net) by merlin.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1gIERU-0003x5-92; Thu, 01 Nov 2018 14:59:28 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 3C67620297BC6; Thu, 1 Nov 2018 15:59:26 +0100 (CET) Date: Thu, 1 Nov 2018 15:59:26 +0100 From: Peter Zijlstra To: Mark Rutland Cc: Trond Myklebust , "linux@roeck-us.net" , "paul.burton@mips.com" , "linux-kernel@vger.kernel.org" , "ralf@linux-mips.org" , "jlayton@kernel.org" , "linuxppc-dev@lists.ozlabs.org" , "bfields@fieldses.org" , "linux-mips@linux-mips.org" , "linux-nfs@vger.kernel.org" , "akpm@linux-foundation.org" , "anna.schumaker@netapp.com" , "jhogan@kernel.org" , "netdev@vger.kernel.org" , "davem@davemloft.net" , "arnd@arndb.de" , "paulus@samba.org" , "mpe@ellerman.id.au" , "benh@kernel.crashing.org" , Will Deacon , Boqun Feng Subject: Re: [RFC PATCH] lib: Introduce generic __cmpxchg_u64() and use it where needed Message-ID: <20181101145926.GE3178@hirez.programming.kicks-ass.net> References: <1541015538-11382-1-git-send-email-linux@roeck-us.net> <20181031213240.zhh7dfcm47ucuyfl@pburton-laptop> <20181031220253.GA15505@roeck-us.net> <20181031233235.qbedw3pinxcuk7me@pburton-laptop> <4e2438a23d2edf03368950a72ec058d1d299c32e.camel@hammerspace.com> <20181101131846.biyilr2msonljmij@lakrids.cambridge.arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20181101131846.biyilr2msonljmij@lakrids.cambridge.arm.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Nov 01, 2018 at 01:18:46PM +0000, Mark Rutland wrote: > > My one question (and the reason why I went with cmpxchg() in the first > > place) would be about the overflow behaviour for atomic_fetch_inc() and > > friends. I believe those functions should be OK on x86, so that when we > > overflow the counter, it behaves like an unsigned value and wraps back > > around. Is that the case for all architectures? > > > > i.e. are atomic_t/atomic64_t always guaranteed to behave like u32/u64 > > on increment? > > > > I could not find any documentation that explicitly stated that they > > should. > > Peter, Will, I understand that the atomic_t/atomic64_t ops are required > to wrap per 2's-complement. IIUC the refcount code relies on this. > > Can you confirm? There is quite a bit of core code that hard assumes 2s-complement. Not only for atomics but for any signed integer type. Also see the kernel using -fno-strict-overflow which implies -fwrapv, which defines signed overflow to behave like 2s-complement (and rids us of that particular UB).