Received: by 2002:ab2:784b:0:b0:1fd:adc2:8405 with SMTP id m11csp336507lqp; Mon, 10 Jun 2024 05:56:28 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVQ0URvkyyOJEd7MksUOfi3/ExFqTWqaccEht5sgAmKlCGdW76WiM/f2axSJ9C+UDBTX7oWQinrxHOGOQP3/KpmbIY5ZUuUxEGUzt+LMg== X-Google-Smtp-Source: AGHT+IEfO9pVZSg6Q1AZtSeksIriOWWQkn7llr58DreDq5QSAmdb/8DnqtVZozVnwyvumDP+e2cG X-Received: by 2002:a05:6a00:cc5:b0:705:964e:d9f3 with SMTP id d2e1a72fcca58-705964ee540mr2918118b3a.11.1718024188344; Mon, 10 Jun 2024 05:56:28 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718024188; cv=pass; d=google.com; s=arc-20160816; b=iHU8oZhXFA6iENIpFdhhcnKVBAnm/XXXPibJM1GOo2bkpmNcxdY/rHR3s1c/9PFBbk AUsTJw0/68xb4kRBN6kgChN8jCasZPTIR/giJU/0m4V9pkV4T6IN2yxJjD/uUQrhj17S E1ZLHv2f6Uv6/gJJ3smBIE+1oo9HxEz2VVGhjtLqOeYS+s/+z8zLn9VaaNZ3MCTcKGLw AoDrrBAWYdDTKWpNr2CdSYY+fzx1utfhoa27GiyebwA3WWUPaEvvy3DknBVaGcedWac2 uOyZ+ipz9ko/qNsJleitTlQojpXuFRzOtLRH47CC35K7zHdATkXuWS1t8K9WbYNVVvsR NyhA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=date:mime-version:list-unsubscribe:list-subscribe:list-id :precedence:references:subject:cc:to:from:dkim-signature :dkim-signature:message-id; bh=VC6lH3dC9sC0pTK2Lu8vCn78JTXMe8396fISayi/2Vc=; fh=SJ221ozUQKE1gMXz18gHJLS2vw73dxI/wEW1L5tRolE=; b=JylFdafp3Dz0tFlN9YOOeZcAunGDRdvQL7W3o4Nf2roBOZMLFCq6EhKHW/HIKMBWzA B6b0xLroy1Qu7KE8WU2M1YrCeii6DuTjmeOLhNVKWXOXb7OpiLNVFvpMTihbBVQYz4pQ FEFTuRXpXkeH4jHekGkALuNJ6XIi1EPPbuQz+FbOH3avTZuGkwQCqJXnZofj/urEIhGm qXjqDS2sxg1VdvbCqwz4RT2iAUJgegw91beDXA0nf0S7/XVOd8YT+tc5NxBytcFYHVBd aOMxp7FQ3frwHRdhpKJQvOj4mcPQEOa9o1AWH8CfzgI4EHQszy7b0JKzb+jDPyvbwrBy Nklg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=W6jTctGx; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-208174-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-208174-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id 41be03b00d2f7-6f3318ef039si948702a12.68.2024.06.10.05.56.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jun 2024 05:56:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-208174-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=W6jTctGx; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-208174-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-208174-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de 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 1054FB212DC for ; Mon, 10 Jun 2024 12:47:20 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D90D9811E2; Mon, 10 Jun 2024 12:46:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="W6jTctGx"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="pOTQN9Ei" Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A7C5881211 for ; Mon, 10 Jun 2024 12:46:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718023601; cv=none; b=alivhNN09EQj1PYffUDsN4WZJacBiilX8BhRHJRF4I8lthFepTy0OYzYJQImIz2lMSAn9dhzpCheFvWHs6nBZINz2RUB8cNC4ga076W0cEAb8lGQITHjGBAf0CnauAgReOAFK7401S3Cgd+Gnzxw6hM+b9i7O7IkGL7kBilEhmI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718023601; c=relaxed/simple; bh=3f/P+yKfDD1JJ3JmMZTVY0zvYt/RZf6q4FDQnJb9lfI=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=eXnp8LeyHeyKiqbBmHs7H0/vVUKhEhXRGuq9Skemv98FjSrlgWfHtKJKF3IEahHPcm2RNtsoQWnD+vJZXi3lsjY8feJ7drUIy50PrUnY9BOdKBTTHd9nF9/4jG3pzEmcbsy/ltS6klhG+pZngiKHvQ5fbNyD4Vg6qrAUc9dm6rs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=W6jTctGx; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=pOTQN9Ei; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Message-ID: <20240610124406.484973160@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1718023598; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=VC6lH3dC9sC0pTK2Lu8vCn78JTXMe8396fISayi/2Vc=; b=W6jTctGxznSs+d0Vc0T3v2pyTyX8ZeWi4ZJPm4e3cz2qxlCRGnZITUy+rnTqy7u8XDyHru AT5yh1xlA5MrDfaCaK1cZEpMnrqrdyupPA8JTmk+AjsWYuBsyW6bRBHHouDlRdWeRoIcwF sn1SUxVdUfj2JIPDWEjpWIsF5nvvFHuctnRUfOGJl6czNPWRsl8fujGWgbOMom/Mlf+9MU I+Dq5r71wVKDZe+8ujBURIC3JGBzC47Yfb3eYv16dWJRpu9LLNGSF5/TwuTYXQMc14kJdO kNQViAEoFMl0eVRCFY1DhMjpEg5pYi41nljNGip2aQsezJK1Gr0ITIK7xTdMsg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1718023598; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=VC6lH3dC9sC0pTK2Lu8vCn78JTXMe8396fISayi/2Vc=; b=pOTQN9EifyeiNBTLQTvhWd26e5r9OUy2JFMVMc4M7N9XpACKLeQv/vSC43WmwKZC14Q+xj HBWpnM94Bw7tuJBQ== From: Thomas Gleixner To: LKML Cc: Steven Rostedt , Sam Sun , x86@kernel.org, syzkaller-bugs@googlegroups.com, xrivendell7@gmail.com Subject: [patch 3/4] jump_label: Clarify condition in static_key_fast_inc_not_disabled() References: <87bk49xf15.ffs@tglx> <20240610124258.109097511@linutronix.de> 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=UTF-8 Date: Mon, 10 Jun 2024 14:46:37 +0200 (CEST) The second part of if (v <= 0 || (v + 1) < 0) is not immediately obvious that it acts as overflow protection. Check explicitely for v == INT_MAX instead and add a proper comment how this is used at the call sites. Signed-off-by: Thomas Gleixner --- kernel/jump_label.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) --- a/kernel/jump_label.c +++ b/kernel/jump_label.c @@ -132,12 +132,15 @@ bool static_key_fast_inc_not_disabled(st /* * Negative key->enabled has a special meaning: it sends * static_key_slow_inc/dec() down the slow path, and it is non-zero - * so it counts as "enabled" in jump_label_update(). Note that - * atomic_inc_unless_negative() checks >= 0, so roll our own. + * so it counts as "enabled" in jump_label_update(). + * + * The INT_MAX overflow condition is either used by the networking + * code to reset or detected in the slow path of + * static_key_slow_inc_cpuslocked(). */ v = atomic_read(&key->enabled); do { - if (v <= 0 || (v + 1) < 0) + if (v <= 0 || v == INT_MAX) return false; } while (!likely(atomic_try_cmpxchg(&key->enabled, &v, v + 1)));