Received: by 2002:a89:48b:0:b0:1f5:f2ab:c469 with SMTP id a11csp736018lqd; Wed, 24 Apr 2024 15:45:19 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXFM4ySNUa2FlJZtrlRG0lOvRM/lQSkmCx6a7PJ6tv3fhATXVoLLQAiHWAcKCL3KUbsngYk2ZrJ3kewNWYoZFFCh48uK8tte78kfgcUkQ== X-Google-Smtp-Source: AGHT+IGzhnQgIN5t4VdCiKoKax+fp7zRi6eLD1wqUX/2vjuZNfT1bshw9ag+bplBD6I11FrRB0kO X-Received: by 2002:a50:c00f:0:b0:56c:2ef7:f3e6 with SMTP id r15-20020a50c00f000000b0056c2ef7f3e6mr2597812edb.0.1713998719182; Wed, 24 Apr 2024 15:45:19 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713998719; cv=pass; d=google.com; s=arc-20160816; b=UDr/taM6gy9nfufBokwDZDB+hWHgthYYKLpvaYTDwulOLAdl8PyDNzainDxzBAVgPu AxtMN/Z5BdSs8MX+CVNw0PapP7CX6CWg2JDfsEvSsLzCBM9XhwTQHJrJyygcFpRbZ4eu u9QZ+FPm4eCXN6tkrxGCuR2IpQI6dtoSLx2zmPT0wuHmdJyeTOGg4RZS2baslSczmkiq 7AIFqj2J2GXxzsgbQSiOXJohYVbt0u5Havt4br0t2T3A7kt+g1L99d5wwUa/1PUu8bMc Kjgh8PgYQ2aC3V0plMZkuIHD82Y5SuSVx4mcF4tJV8HOzzPtI58cv0eSUX3fEhcLPzyq YJZw== 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:dkim-signature; bh=bQ7aAoW8uYuZUJ8c+fQ05Y2fxYHEV3uQB6MRkhy36Ug=; fh=V9HQ3Pn/Tp+I/bBe2Zw5RHZ/ku64dIgLdZvCXH6alUY=; b=ddKhIgBubaTYHb/08XAkSiEfeBuma33Cb9ax0p4pjw78reyYSEeYi5baddJ1xmorF5 zwVzMnufa27gq3RKYTrjV+rL3AEyn6ScuQKCtwG8DLo5UROAJvKpL1awLChKMH/f70df pYrAMz4cE/YEixu7SjAYQuGM57p3GwGZfbLRC5jOOJsoLJ08r3XXDwpVDPcaJQ63qCvX Yr7lOxAGwqZ4XYWkMI1RlgDG2tQ97/rAPnw9RKA0vG7erKohNah1rjIkT6EoJq0S90af Kuivj+PWAd/7yu6cU2QEoSG/tkCchrtk5JDoQGhPH4sYN0G4xjKo32GfgOUM1bFa9iaD uSZw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Ip2IuUZ5; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-157799-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-157799-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id dg21-20020a0564021d1500b0056e07a2e666si8957735edb.193.2024.04.24.15.45.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Apr 2024 15:45:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-157799-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Ip2IuUZ5; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-157799-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-157799-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org 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 am.mirrors.kernel.org (Postfix) with ESMTPS id DD8381F2413B for ; Wed, 24 Apr 2024 22:45:18 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 80A8716EBE4; Wed, 24 Apr 2024 22:45:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="Ip2IuUZ5" Received: from mail-pf1-f177.google.com (mail-pf1-f177.google.com [209.85.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 796A716E873 for ; Wed, 24 Apr 2024 22:45:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.177 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713998710; cv=none; b=jU7uYm45+QGolAL0uizOonMMZkvRc7gK60aVk3qzdfCGwpq9/agNhnDSPUeXMJshA6ambHZdg4Rfq5u6bzb7yI5hNUPW9LVmXMTyQ56szvmkNh+0Ucw+gUo2tPrNO3kk5SMZr9DDvU0nw+Maruh2mlNIQFfNiGPuD8xDc3IrY/k= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713998710; c=relaxed/simple; bh=PesUfngxJz9TzB+RXrKPi6gidufT5NJWBpNfqP6UeSg=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=nCMX2NAQjXP+PmF2FtZnU/LxEv4yE9w0X2riOJmc/SJZ+T3GcNz/Iz8Vi6kQXgjnoxCYjZ3e246ZPyt2fEjDOc5GswZ92Z7U7w4N/Yvwy4NxY/7zFwNd7hkFAz52zd5rFDPblMbYnoxSKVIjVaXhYBG3oLgbsv6hIQDMKlx9eTg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=Ip2IuUZ5; arc=none smtp.client-ip=209.85.210.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Received: by mail-pf1-f177.google.com with SMTP id d2e1a72fcca58-6eddff25e4eso373786b3a.3 for ; Wed, 24 Apr 2024 15:45:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1713998709; x=1714603509; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=bQ7aAoW8uYuZUJ8c+fQ05Y2fxYHEV3uQB6MRkhy36Ug=; b=Ip2IuUZ5LfeaeG8LgTT7FPRSNVprS1WtQ8j+0rOBMsdFH8RkkiUSJdxlYmcWm0keco D0VyxtpaYBK3q8eO/87uN8z81J/XdcHp44mFnYRtTQyLFhhWKfvbInbP/sym7rPhnNN8 73IKrRKCZtycqCXOrZtxQ2k6kD6uCr8YzTm4E= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713998709; x=1714603509; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=bQ7aAoW8uYuZUJ8c+fQ05Y2fxYHEV3uQB6MRkhy36Ug=; b=DxFjaB8M4SJ/CqXdPzYROUevaWbwHULYdCkFtjvwP88yEOJjJ4ZKifxmcNJ+7+UZgL BSVwVoIm7fyUaMmzaT0CsQIQnV0LSdsY90Nrw/18ZQPCbvY819dRSBJy+FOQdCcvbxya yeHsBfJczONs3dfr0ij3ZlCZp8LSjkdbXVKKNGXunmEWYMUjNPxt0zto3+gdU/EVrzdM dmprPUIz+S2v22GCzAEVm0I45Y+QtDoKJDtDiI2AeWOP0NOpRu9xfLDRi7pnAG3qkXfh 9NJTm9b1JY5a1rR3woUWzPnBIbxXwi+JyDHRZTvilj8QbJEAeT5ZAT1MQBI/DJvNMp3J JdGw== X-Forwarded-Encrypted: i=1; AJvYcCWjuS3o0FVkt/8WvkgHIYAWDJP0ikbeUE7gpBeq5MWZ8StP5RPHMaFRoa0jmA5T1h2Lm2GYNewCbI5o00d6i673gy/tPDtWZcvOBiVO X-Gm-Message-State: AOJu0Yz/TVKk4uJHdItt+kM8LWOS1m+w/qA3v0pVoR3uWzbGIZIqvjco YwRqZN0XZqJ5ZgfsNHIuRj3uPS+YtMzFSEEIC9ScrYZdW5cdedxJanuY9QL9Dw== X-Received: by 2002:a05:6a00:4fcb:b0:6eb:2b:43b4 with SMTP id le11-20020a056a004fcb00b006eb002b43b4mr5470380pfb.27.1713998708861; Wed, 24 Apr 2024 15:45:08 -0700 (PDT) Received: from www.outflux.net ([198.0.35.241]) by smtp.gmail.com with ESMTPSA id ln2-20020a056a003cc200b006eff6f669a1sm11902767pfb.30.2024.04.24.15.45.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Apr 2024 15:45:08 -0700 (PDT) Date: Wed, 24 Apr 2024 15:45:07 -0700 From: Kees Cook To: Peter Zijlstra 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: <202404241542.6AFC3042C1@keescook> References: <20240424191225.work.780-kees@kernel.org> <20240424191740.3088894-1-keescook@chromium.org> <20240424224141.GX40213@noisy.programming.kicks-ass.net> 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: <20240424224141.GX40213@noisy.programming.kicks-ass.net> 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 -- Kees Cook