Received: by 2002:a89:48b:0:b0:1f5:f2ab:c469 with SMTP id a11csp1015554lqd; Thu, 25 Apr 2024 03:42:29 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCU3ePRWOHqc152OHcOC1SVSfw4KXO3VQTVj44gMnkjn8xT+t7IS+m11iDyePs/WEoR87GESSD7+JYmssCWXpFRo9s6HUWQp+Gx/h3AfqQ== X-Google-Smtp-Source: AGHT+IHG4sUeeO4yz7e6R94OTRpLHQN0LPAATTOIIIyjW2heyuB3bP7DopfewTgFMMe70J/otGKy X-Received: by 2002:a05:6a20:b920:b0:1aa:59cb:781c with SMTP id fe32-20020a056a20b92000b001aa59cb781cmr4565422pzb.13.1714041749407; Thu, 25 Apr 2024 03:42:29 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714041749; cv=pass; d=google.com; s=arc-20160816; b=M/XqAG5t5dV9dl4LHCqYmLLvSY49MAHM7vaWsYorq5aiM2keyrixBDCLAfXIto/EPU XpDr/YoZ5tC4OjMBQT8NR0Zw9ZcSL2NNEF5ywPMyYb5xubqvBFuI/20nmb8pkrowOHfx 7xOvV3QWyEO8/snT5f4Fd9qQI+ZcLru81/ayjQSXcW+/cUSfi86uBEAd0kky64JCNm70 7Hqe3/JFX2wQQEZFW5FnycM6oQwHhCl+v4XbuaBHMu34uF5BGCqmLBrgyVf6X5IZ8K+2 z4ORZHuoaOokVEmSzkBCpvPgWFBUt+s2k4kTBx9QDqVW2WvDEoqnR0YKg6u9UHnuCoin mTTg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date; bh=9bA6AzGS5WFcC0wDzID/z99SEPPZHlLCnW34t0fpvJE=; fh=W1likFFaSALvNjbn+txHkPcpv+YQu7jSoS4ckj2yzqU=; b=lLyCreURyF+oVUErXbhXGzfv/cn68iyq4Z/UijiafSf0E/iE8nkzeSbkwG+zXlCUwO BmiYZORNJoHZJbbndB8bbsomILLYF2IFWzYEEuTxV7q3XvBTR4yq5vWm9J0Hm1dpAoy1 LhukYHZPE4d0vjV6UoipmhJjDbe4CUjT6Sb9GtwsH+16yTrieNGngfnR7ouBy6SmE2wH M6DkJ6L4DBoRdZcjPoLYtk3Bq7gb6N0W2MbMnYbPD3zeWs5S2IQyYBtl1cTIWvz8wkva DyoeRlcmTOigqCed3SG/zrkS/exjZVLCIWp/ok2Auxwu/9P9GMFAz6+ghfXUKkBNXwrW YlDw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-158371-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-158371-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id a20-20020a056a000c9400b006eb418ce81csi13593445pfv.149.2024.04.25.03.42.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Apr 2024 03:42:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-158371-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-158371-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-158371-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id B7E94B216C9 for ; Thu, 25 Apr 2024 10:15:46 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 15880126F1D; Thu, 25 Apr 2024 10:15:27 +0000 (UTC) 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: linux-kernel@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.