Received: by 2002:ab2:784b:0:b0:1fd:adc2:8405 with SMTP id m11csp336641lqp; Mon, 10 Jun 2024 05:56:44 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXMdkKNzXT3aQU64iDhssmgDslUn5X1/tbTCyfvRJDu4xYvlyF+doikM0lsq/tTeObGpOAuwyj5edJW4neM1VvzGETi3lPUbKYCaTF0Bg== X-Google-Smtp-Source: AGHT+IGKsd0h7NSyFM2szZ6XrvyIeFVD587Kj6P5rmxP//vobUOah2e4nz/5Q113iAjPHt7Ka+yq X-Received: by 2002:a17:902:e742:b0:1f2:f761:c3c with SMTP id d9443c01a7336-1f6d03c1a75mr100945845ad.68.1718024204429; Mon, 10 Jun 2024 05:56:44 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718024204; cv=pass; d=google.com; s=arc-20160816; b=gZc/UT/hOwQMFSEETqkSHB/fOIbWaJl+Y9Lbm1b0PffuFNo+Gw2Vf9H+/vfq7Tp6ah k2K238Vl4LxYo/yvLocdbGIMJLSZ61K78lcQwA3Mp8YmDyYdZ0vBu5Kj+kB6ugvhpUpH O2AeQ4MYvXEQgjb7UqU52cVSLy4H/U4huyzK3PwVRGNpXFJQZXAiFPRW12ddl4XkdchP +VW+zSFW80K5xhzVJKur6SvH2s+usRhBBmVgYJ7YurJTU0Bkau+AgA0/F8L9u9kNo1fb ikaj+HjCSyQ4clCsrbgJqsIjX/8P1jwlwtkUAzUfxk1qApvzVdYrKuSnfFrvDOHKijI9 WQow== 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=6YG0UjVZ2COICpcGaXkn7bT56v/DQnx1rLutVdszFN8=; fh=SJ221ozUQKE1gMXz18gHJLS2vw73dxI/wEW1L5tRolE=; b=N4/ykw2eiLQRSivfDYDpA/TVlgIOu08bawra7dFcWC2+djkAFFf3TglaujJvxrOS4h 8m5EH4Fcojd0P7i/GUwlumbhzX5/GdcYYaeD0i4+1WqJz+/YCsGYDqyKn+N4fj3UdCCf 7Q8QyiwhCQiFB2VcKDyr3yBuhBH6k0zmsFdNB5Zug94hdTqDPyEYKX9Q9PLqBt25qnCA VOEsnWOU8QQtsNF2Kirb+2clTdjrPUjZ1Gp3IFayzm6Kz4IXEIT9h9Wez4S1mZ1GH7Zn gKVSPfcxKzKQitZASarMqEASz7jX6CAbOBEBx3HBYzPnTA3zoFE6FTbUkUbVTnSs+wG1 NEyw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=1ae8f6d+; 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-208175-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-208175-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 d9443c01a7336-1f6da3b6b2bsi52266605ad.235.2024.06.10.05.56.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jun 2024 05:56:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-208175-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=1ae8f6d+; 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-208175-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-208175-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 8AD2EB22C81 for ; Mon, 10 Jun 2024 12:47:34 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5CCE784D13; Mon, 10 Jun 2024 12:46:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="1ae8f6d+"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="rdmqu4fD" 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 2C40A823CE for ; Mon, 10 Jun 2024 12:46:40 +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=1718023602; cv=none; b=Zr66wlL8crVoLb08oCYvEKSsJxpkk4fOkv0C8dmhurVNJOOVOqo+wCN24WFPhpZx3TIYjwMU8nofBO/X1BH490HdX34hbVY8C5+y+yoNFJddt3ymj0pfO4Mb+3jScC+uj/BfjExON0PCGSV79XLJ6iltBtYV5rtxn0aa6JbF+fw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718023602; c=relaxed/simple; bh=DzfzfEOYrS5hRroqqM63QoncLtcbJosXf0SN2GkmGYw=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=HnNFMKrR4KNkhOf4vsixE8LzykmsvGtlCZ9TgEm+V7i3qlXg2yDJDPzK/l6Us3A0FKaPINywVmaRQZRKpA2ZOVT/IfCtmgxtkPiSaGNd7wo3dIhGz+ykOaKani7zVR52WzChgFrlTFFCfFzt5Vxr4JeePNPW6TE2pDl7zpzVwt4= 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=1ae8f6d+; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=rdmqu4fD; 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.548322963@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1718023599; 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=6YG0UjVZ2COICpcGaXkn7bT56v/DQnx1rLutVdszFN8=; b=1ae8f6d+738dLW/DcQCym/msZK5WZIsZijFafDFY4feUxd4pZuUcKa1BSXnKmDRBHjD5Tr GEj5hH48cj/TffXwAAO4JQZ960K9kmMyua9fASlTNhUy+ZcQDEnZriSxohCPVjLNNVh1Zh hUwLZQUs3aQmUqtGoxCjRkJAE+WmU53gwGgyKncnVpWCr/ThLVrwn9y+djrzytF3gOHnLA Z6W1S/CqE30hNkSsB+2fCEh+dThO36lyeUjll6LzStW8a9/0QIOGDQD/ude6jGuzupQgAU mF8h8e4bJqaqtNW8s48dwm1OEa5C7we76cMX94jSPk/azXpHgOasrN8MCZuWMQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1718023599; 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=6YG0UjVZ2COICpcGaXkn7bT56v/DQnx1rLutVdszFN8=; b=rdmqu4fDZwdgg9hVq+KvgzLnTfjhJWIvHjiU3TN/Lvq6deQbPWM/rQ0gGTjx9XgtcBOcQN IT7F1TAyJYzaasAg== From: Thomas Gleixner To: LKML Cc: Steven Rostedt , Sam Sun , x86@kernel.org, syzkaller-bugs@googlegroups.com, xrivendell7@gmail.com Subject: [patch 4/4] jump_label: Simplify and clarify static_key_fast_inc_cpus_locked() 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:39 +0200 (CEST) Make the code more obvious and add proper comments to avoid future head scratching. Signed-off-by: Thomas Gleixner --- kernel/jump_label.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) --- a/kernel/jump_label.c +++ b/kernel/jump_label.c @@ -162,22 +162,24 @@ bool static_key_slow_inc_cpuslocked(stru if (static_key_fast_inc_not_disabled(key)) return true; - jump_label_lock(); - if (atomic_read(&key->enabled) == 0) { - atomic_set(&key->enabled, -1); + guard(mutex)(&jump_label_mutex); + /* Try to mark it as 'enabling in progress. */ + if (!atomic_cmpxchg(&key->enabled, 0, -1)) { jump_label_update(key); /* - * Ensure that if the above cmpxchg loop observes our positive - * value, it must also observe all the text changes. + * Ensure that when static_key_fast_inc_not_disabled() or + * static_key_slow_try_dec() observe the positive value, + * they must also observe all the text changes. */ atomic_set_release(&key->enabled, 1); } else { - if (WARN_ON_ONCE(!static_key_fast_inc_not_disabled(key))) { - jump_label_unlock(); + /* + * While holding the mutex this should never observe + * anything else than a value >= 1 and succeed + */ + if (WARN_ON_ONCE(!static_key_fast_inc_not_disabled(key))) return false; - } } - jump_label_unlock(); return true; }