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 94267C4345F for ; Wed, 24 Apr 2024 22:51:39 +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=y0On3YfUPOIvzQO+5TUCPrF4on5Q0RpNMsYDFn5VwEM=; b=aHKDnXwYfXjGXK 6RUCK5qxvCgm/Ipl9V0dXXM7VNGS1GsY7A8OTR2RT6wLumyPYSHHlKGW4yk1qPcOlegikDge+Mtoy 15WcxAQEdC2nZ+h97jK4yInSqrWBFLDQLnsr4VXsKQnxO1gVkEGCL9lzns7gF9UJ24mXBG7tNpPPb Lyj7Ww9fzh7g07UjzgKpg/sxAMNMORsvbsNbp2nwZQ6/k/hEohUAlcC8Bisb6/QClrFAQhqX1qhSn xso3+RE6ydcNe2FXhBJBIqd27T+CFnEZHMjBDX2n0tsusod/bj6b8ayapTKn2e6tlQ2Lg0L0eAJEe ciEOGtZfxCZJALAnk+XQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rzlSa-00000006HAi-1ycr; Wed, 24 Apr 2024 22:51:28 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rzlSZ-00000006HAH-0O9D for linux-arm-kernel@bombadil.infradead.org; Wed, 24 Apr 2024 22:51:27 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.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; bh=uDrKK9MVu5GzHed4YiXOORHenuiRjCroUzkRtpq7Xr8=; b=IILmx88mD8vjiMwqrMmrre+9AR zlcY2kqPjYZncZiBJFj6pnDAU0ZhhuV4rlxSZ7HcxKqBCjBa6OOs5ocvCCax/S8NxxWj84EAxqbEL MFaNqZ2luw6imVBZuIGe/aG75GB7MYXZ5lbY0rcrAoNUxUNRBMpXuO1Am0ZJdsHYjENsjxw6Ycf9d 99F8TBD+1jTtbHGf1q71XtM4hbBSu5Sgx4e9bcidXHlwPBNvG5kZMloqH84s7AtrC9VybE9Mi1Ref bJ1tegqi+pDWrgGvKx5eWVrDjQV3HCkjx2HtVZHUWlmRO6p1QgZOtIk+xYyIuM3ifm9ITathoorRw g3AhKNoQ==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1rzlSU-00000001qPk-444P; Wed, 24 Apr 2024 22:51:23 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 1000) id 8F02930040C; Thu, 25 Apr 2024 00:51:22 +0200 (CEST) Date: Thu, 25 Apr 2024 00:51:22 +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: <20240424225122.GF12673@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> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20240424224141.GX40213@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: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. Also, what drugs is involved with __builtin_add_overflow() ? Per -fno-strict-overflow everything is 2s complement and you can just do the unsigned add. Over the years we've been writing code with the express knowledge that everything wraps properly, this annotation is going to be utter pain. As I've said before, add an explicit non-wrapping type and use that for the cases you care about actually not wrapping. NAK _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel