Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp354619rdb; Tue, 23 Jan 2024 01:29:07 -0800 (PST) X-Google-Smtp-Source: AGHT+IFiSIZpoadP2y+AzMs9RTRsjqxxaYxF63r34M1jvOAr2s5nAGD3uzFQ9EeEyA5XhddO+cEn X-Received: by 2002:a05:6a20:6a29:b0:19c:4d79:a820 with SMTP id p41-20020a056a206a2900b0019c4d79a820mr2013531pzk.19.1706002147625; Tue, 23 Jan 2024 01:29:07 -0800 (PST) Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id u20-20020a17090ae01400b0028ff56f1cd9si9514771pjy.51.2024.01.23.01.29.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Jan 2024 01:29:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-34996-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; arc=fail (body hash mismatch); spf=pass (google.com: domain of linux-kernel+bounces-34996-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-34996-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 49244287582 for ; Tue, 23 Jan 2024 09:28:00 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9738D5A0F8; Tue, 23 Jan 2024 09:27:35 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AB76257894; Tue, 23 Jan 2024 09:27:32 +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=1706002055; cv=none; b=ctw+aAnJQ0RImERsx6AKVX5Q6+4GdyDWlD3qwpv4hxrTLjZQT0q5vzy+UyOP8SRhSI8t89Y2JgOIBtUlSGVlsV1NI3KNjaIn8fu03I0Di6j5P2Eq/Y+t4Vc0G/A8SVsTqBxyyU1ChAr4y3buSq19OCcV0G2mtnrckHTeqiR/hDI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706002055; c=relaxed/simple; bh=JysJK2JlLSGAqooo7PY7sHFbY2NERVJ2AeZzg9T9Avs=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=GYITShRv65SI0CSI03bGXJWqSYw10KyF+5gNfF2PKUVcn6BJjZEw9lI2VrFKq7YGWMAPFzWE1gYYMoHn8w4gunWfxKiggJbHpLVLXu7ZBIPkjzke8kKJ5jkBQd9rZ7XJ3ohoT8ZkhdtB+5lIaBys2M181/6FVj2iqPL6+ojuk40= 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 6F7261FB; Tue, 23 Jan 2024 01:28:17 -0800 (PST) Received: from FVFF77S0Q05N (unknown [10.57.48.47]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id C27CC3F5A1; Tue, 23 Jan 2024 01:27:29 -0800 (PST) Date: Tue, 23 Jan 2024 09:27:26 +0000 From: Mark Rutland To: Kees Cook Cc: linux-hardening@vger.kernel.org, Will Deacon , Peter Zijlstra , Boqun Feng , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , "Gustavo A. R. Silva" , Bill Wendling , Justin Stitt , linux-kernel@vger.kernel.org Subject: Re: [PATCH 10/82] locking/atomic/x86: Silence intentional wrapping addition Message-ID: References: <20240122235208.work.748-kees@kernel.org> <20240123002814.1396804-10-keescook@chromium.org> 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: <20240123002814.1396804-10-keescook@chromium.org> On Mon, Jan 22, 2024 at 04:26:45PM -0800, Kees Cook wrote: > Annotate atomic_add_return() to avoid signed overflow instrumentation. > It is expected to wrap around. > > Cc: Will Deacon > Cc: Peter Zijlstra > Cc: Boqun Feng > Cc: Mark Rutland > Cc: Thomas Gleixner > Cc: Ingo Molnar > Cc: Borislav Petkov > Cc: Dave Hansen > Cc: x86@kernel.org > Cc: "H. Peter Anvin" > Signed-off-by: Kees Cook > --- > arch/x86/include/asm/atomic.h | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h > index 55a55ec04350..4120cdd87da8 100644 > --- a/arch/x86/include/asm/atomic.h > +++ b/arch/x86/include/asm/atomic.h > @@ -80,7 +80,7 @@ static __always_inline bool arch_atomic_add_negative(int i, atomic_t *v) > } > #define arch_atomic_add_negative arch_atomic_add_negative > > -static __always_inline int arch_atomic_add_return(int i, atomic_t *v) > +static __always_inline __signed_wrap int arch_atomic_add_return(int i, atomic_t *v) > { > return i + xadd(&v->counter, i); > } I think that here (and in the arm64 patch) it'd be better to use add_wrap() on the specific statement, i.e. have: static __always_inline int arch_atomic_add_return(int i, atomic_t *v) { return add_wrap(i, xadd(&v->counter, i)); } .. since otherwise the annotation could applly to the '+' or something else (e.g. if the 'xadd() part is a special macro), and the annotation might unexpectedly hide things if we add other statements here in future. Mark. > -- > 2.34.1 >