From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3583B8595B; Thu, 25 Apr 2024 10:15:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714040126; cv=none; b=O/RRX0aJXoNXQ+goVKvX4KMAl+3FHo05UUJv3TGbYEQdbbeIvnOHuB1nBl8VKG5vvsWBL1T5ESkeLMM9nGg9Qd+zywtS7S74sIaeEY+5T/Od0n0U/vuSl1eJEsTU0NSvqLDfcKhC++b5S/DczaNP8gjfNUiKdcOaVZAy51oNsvE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714040126; c=relaxed/simple; bh=Qq1AnccoHrm0GNohxKCpb5x/v0HAT6PjJOBCntlXYtY=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=s6WST0OEfYvhV5RFeizsnFeOU9uCi7iYeCR0dQH7n5XUsLWncDTeL4gorLF0GJ+LqmetWc6sSPML1yZmZXrKkgqt9Md2hT8Ktpi9A1PupTg/3zc9mtQPfAQNPaFes4HkNkaodG8sinFDf7oj2/nFY+ymo11ia0ngvG/oVe8UYRA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com 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 C52511063; Thu, 25 Apr 2024 03:15:52 -0700 (PDT) Received: from FVFF77S0Q05N (unknown [10.57.21.118]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id B875E3F64C; Thu, 25 Apr 2024 03:15:20 -0700 (PDT) Date: Thu, 25 Apr 2024 11:15:17 +0100 From: Mark Rutland To: Kees Cook Cc: Peter Zijlstra , 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: References: <20240424191225.work.780-kees@kernel.org> <20240424191740.3088894-1-keescook@chromium.org> <20240424224141.GX40213@noisy.programming.kicks-ass.net> <202404241542.6AFC3042C1@keescook> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <202404241542.6AFC3042C1@keescook> 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! :) To be clear, I dislike the function annotation because then it applies to *everything* within the function, which is overly broad and the intent becomes unclear. That makes it painful to refactor the code (since e.g. if we want to add another operation to the function which *should not* wrap, that gets silenced too). I'm happy with something that applies to specific types/variables or specific operations (which is what these patches do). As to whether or not we do this at all I'll have to defer to Peter. Mark.