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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 98E09C10F15 for ; Wed, 24 Apr 2024 23:05:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=R9m6YuO+Hefi0SH2drdre1LdK/zLxSK8ai3zxC64ywA=; b=IJ/Dm44ZTW1Pby UJF4CFEmVhJiSTk13IsIPUyWTrJZzhA14tWuqjNSEV2oENU9e++L2/1nM6mk7w6LD2d9TrIuu2fjd lp0YRpqdB6Lf6l96SyWeqbMin5iKDuGeXD3GMJEBY09W/2VyfuWZ4gTGEpAaun+YRv79vaqJLyyY4 K6GtdYdu/sGZwAf/xvuRfGtPfmyau8pkTQEn1QD3cG6XEphntmRfeVJIx/864mjPuC7Kjb5aB9Xm+ tui6JbpS/0BrqPUDKqiYz2EhI2VXozun0ojNjrKEMdJ68lRhWz3HyVXCKnmmAU4pJdju0i9vcZJhe ORjldGLaCNmMh8B9WSJg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rzlfp-00000006JYs-2xvF; Wed, 24 Apr 2024 23:05:09 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rzlfo-00000006JYf-2ktF for linux-arm-kernel@bombadil.infradead.org; Wed, 24 Apr 2024 23:05:08 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; 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; bh=ZkT+6J58bxSG5zYwuGwSSUyrEmL9IGY39TrZq4eGklU=; b=gguesAFcokKJCJyv+QBKjsgZkg Fxm+aLJmRjFH3615INiPM5LIlxwiF4CsTlJ1OgKbQRjMejaxSaekr0J5Q9EcfUVpHeF7vZyiSzeS9 p0OCpCAwDtAdvwws0QfVLDE2BS4eWwZljuMyX1OwIDrOMk+SLGSFTLRh/JDvLg/il3VcbmXD3ehLq kBCeD/cbRa/ECD0aoX2bXfVpS3VRV/N8ImQqlND9Jh3WnUW7qllGyGdHLcyhMeZBzNKtlC5Rq6fuj IhBplFbSM5K+cacg3KipHlduBx35xJl+lom25sOLDExia1u37DaBXudyimcXF0Sr9kTyQBN49TPBF qNo9oERg==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1rzlfg-0000000EdWW-2rpA; Wed, 24 Apr 2024 23:05:03 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 1000) id 5529830043E; Thu, 25 Apr 2024 01:05:00 +0200 (CEST) Date: Thu, 25 Apr 2024 01:05:00 +0200 From: Peter Zijlstra To: Kees Cook Cc: Mark Rutland , Will Deacon , Boqun Feng , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Jakub Kicinski , Catalin Marinas , Arnd Bergmann , Andrew Morton , "David S. Miller" , David Ahern , Eric Dumazet , Paolo Abeni , "Paul E. McKenney" , Uros Bizjak , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-arch@vger.kernel.org, netdev@vger.kernel.org, linux-hardening@vger.kernel.org Subject: Re: [PATCH 1/4] locking/atomic/x86: Silence intentional wrapping addition Message-ID: <20240424230500.GG12673@noisy.programming.kicks-ass.net> References: <20240424191225.work.780-kees@kernel.org> <20240424191740.3088894-1-keescook@chromium.org> <20240424224141.GX40213@noisy.programming.kicks-ass.net> <202404241542.6AFC3042C1@keescook> <20240424225436.GY40213@noisy.programming.kicks-ass.net> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20240424225436.GY40213@noisy.programming.kicks-ass.net> X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Thu, Apr 25, 2024 at 12:54:36AM +0200, Peter Zijlstra wrote: > On Wed, Apr 24, 2024 at 03:45:07PM -0700, Kees Cook wrote: > > On Thu, Apr 25, 2024 at 12:41:41AM +0200, Peter Zijlstra wrote: > > > On Wed, Apr 24, 2024 at 12:17:34PM -0700, Kees Cook wrote: > > > > > > > @@ -82,7 +83,7 @@ static __always_inline bool arch_atomic_add_negative(int i, atomic_t *v) > > > > > > > > static __always_inline int arch_atomic_add_return(int i, atomic_t *v) > > > > { > > > > - return i + xadd(&v->counter, i); > > > > + return wrapping_add(int, i, xadd(&v->counter, i)); > > > > } > > > > #define arch_atomic_add_return arch_atomic_add_return > > > > > > this is going to get old *real* quick :-/ > > > > > > This must be the ugliest possible way to annotate all this, and then > > > litter the kernel with all this... urgh. > > > > I'm expecting to have explicit wrapping type annotations soon[1], but for > > the atomics, it's kind of a wash on how intrusive the annotations get. I > > had originally wanted to mark the function (as I did in other cases) > > rather than using the helper, but Mark preferred it this way. I'm happy > > to do whatever! :) > > > > -Kees > > > > [1] https://github.com/llvm/llvm-project/pull/86618 > > This is arse-about-face. Signed stuff wraps per -fno-strict-overflow. > We've been writing code for years under that assumption. > > You want to mark the non-wrapping case. That is, anything that actively warns about signed overflow when build with -fno-strict-overflow is a bug. If you want this warning you have to explicitly mark things. Signed overflow is not UB, is not a bug. Now, it might be unexpected in some places, but fundamentally we run on 2s complement and expect 2s complement. If you want more, mark it so. _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel