Received: by 2002:ab2:788f:0:b0:1ee:8f2e:70ae with SMTP id b15csp295622lqi; Wed, 6 Mar 2024 18:33:10 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVR6axy6nFDBugiWQvl3fkjoXVFtRmtGIseWnIG4SqcfDXNO4Qm1a3RAWhjBZtQJ0smYGNgL7mla9TQ2GR31E7zHNpFxc+gv0btNtmPmQ== X-Google-Smtp-Source: AGHT+IFs1dtgw30cmMGYWHuPkGtPVZSIGh6QPxsIsN9JBnwdOGcu9mPmh+Ax42xBeCdKgBS334bQ X-Received: by 2002:a05:620a:5758:b0:788:2ae5:aec8 with SMTP id wj24-20020a05620a575800b007882ae5aec8mr6994779qkn.54.1709778790479; Wed, 06 Mar 2024 18:33:10 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709778790; cv=pass; d=google.com; s=arc-20160816; b=wrljcvH7T+gxnuoUI88/9wKlAeeLFIv7kQlsGIfnjSWIaGJCUweV6EhObkQDviETAm vOfJruZaNul8zU63yp6fqd3zyFuznLferQdzx3RpdFCaFhTSvPQrjeeUZ66UumX8Mduw kKk0YC6B4I8G6VcPDQA+XkA7MEDCGt2rqsa/NRsp9i3Bi39m+fjA3AJZUns90AdTS2DM AGmn7/wwPx+gBJR1z7v6xRONhD//D5wGASZxB9QiiMVBVz/RiScaCQFiyEsxxvsNwEsx 0P5T+FtHHsXYfazToWmySabc1KYvJbotBsSmgRsVAmFCFQd3+vG943ZkEq7RcDY427tB 57mA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :subject:cc:to:from:date; bh=kSKw/3fxy77Y6f8urqZ+CYmXE73dKpCAiigBK8PHD98=; fh=piGEbSvfnx1NBj/RBz9RwQDDFxR0gt88Sar8DfB9wvs=; b=fKlm42N6kkhQZS5tY5B+E86Tv5pRHUTdQGcpkEu1LE1VQJEIK9bBV2Tc3pJjMwmXAz gIchpBtZn+gJi0fU8IReiz85ssKu1LMcu870yaLF2u0SqSv7/PzuDYGmNjbzpVEb2HyA iPClPu1gBwcS3boPCefb271mK1kMHiYdcfDzi2Hb0xBlNVyy8Drc/lhxdf65aENOrqZE XcO5FYXZ8zj15iCSOn4UPLNhCrXCt1c5wcxPjFtwQyZ2lIvCYPnNynBviWGpsUbSWTHJ cj2q1nCMEGJ/e/BQTdFyKZc3AcC63wOkQ7HBx/52uCLzN24o5JippZQSSpR/fsh6FEDO rV9A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-94865-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-94865-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id u27-20020a05620a121b00b0078821efbd24si9613276qkj.93.2024.03.06.18.33.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Mar 2024 18:33:10 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-94865-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-94865-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-94865-linux.lists.archive=gmail.com@vger.kernel.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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 3639A1C21671 for ; Thu, 7 Mar 2024 02:33:10 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 780046139; Thu, 7 Mar 2024 02:33:04 +0000 (UTC) Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 02BBF1847 for ; Thu, 7 Mar 2024 02:33:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709778784; cv=none; b=W9UAO5hKyjYPf4CL1a+jDuvSzF4J/VC3FUMXTRnVIjrXU+GnaWYGrMHkmOSDtbFNVLXr4XwIQB7KgWne1aNB53lba4oa+259iGx2+mnGad9WIvtHJ0W8GMCJfY3yBiw7SOGIHp8W+sC+YMdCW1Nq92r9flqXPiLu7PF+xK6UPzk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709778784; c=relaxed/simple; bh=pkoOFmAvrD3wDqGDRfFIlNPEWvvmWyCwnppqJZic2vE=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=HyTw4p3m4jPU7wElUq8utnXkkR6GBzD0NQAuZ1t7ybqQ44BT4r5TT3xFXjtXzkOequwCP+3Yzrf//yKA9+WF15JE0gnRhZ+b2o+YnQgDXI4ARHILM902X8q5GSeK84+Ahzya5H/gDV/LHz1iDS5uRup6dJkoYi1YRgnAlrBghDY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4EF49C433F1; Thu, 7 Mar 2024 02:33:02 +0000 (UTC) Date: Wed, 6 Mar 2024 21:34:53 -0500 From: Steven Rostedt To: Josh Poimboeuf Cc: Jason Baron , Sam Sun , linux-kernel@vger.kernel.org, syzkaller@googlegroups.com, xrivendell7@gmail.com, ardb@kernel.org, peterz@infradead.org, linux-mm@kvack.org, akpm@linux-foundation.org, Paolo Bonzini Subject: Re: [Bug] WARNING in static_key_disable_cpuslocked Message-ID: <20240306213453.72f9a925@gandalf.local.home> In-Reply-To: <20240307013009.erbnug2mopx5yrnf@treble> References: <20240306105420.6a6bea2c@gandalf.local.home> <20240306193101.s2g33o4viqi2azf3@treble> <854e523c-c467-47f6-b977-933cbaadeb62@akamai.com> <20240306221650.sw3lha7kca2quv63@treble> <8f586bd2-c436-4334-92af-762a284e1101@akamai.com> <20240306234253.zporv6cypoc7yihs@treble> <20240307013009.erbnug2mopx5yrnf@treble> X-Mailer: Claws Mail 3.19.1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) 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-Transfer-Encoding: 7bit On Wed, 6 Mar 2024 17:30:09 -0800 Josh Poimboeuf wrote: > So, I think we can simplify this nicely by getting rid of the whole -1 > thing altogether: > > diff --git a/kernel/jump_label.c b/kernel/jump_label.c > index d9c822bbffb8..ef7eda7685b2 100644 > --- a/kernel/jump_label.c > +++ b/kernel/jump_label.c > @@ -194,20 +194,15 @@ void static_key_enable_cpuslocked(struct static_key *key) > STATIC_KEY_CHECK_USE(key); > lockdep_assert_cpus_held(); > > - if (atomic_read(&key->enabled) > 0) { > - WARN_ON_ONCE(atomic_read(&key->enabled) != 1); > + if (atomic_read(&key->enabled) == 1) > return; > - } > - > jump_label_lock(); > - if (atomic_read(&key->enabled) == 0) { > - atomic_set(&key->enabled, -1); > + > + if (atomic_cmpxchg(&key->enabled, 0, 1) == 0) > jump_label_update(key); > - /* > - * See static_key_slow_inc(). > - */ > - atomic_set_release(&key->enabled, 1); > - } > + else > + WARN_ON_ONCE(atomic_read(&key->enabled) != 1); > + > jump_label_unlock(); You may be able to clean it up more with: int tmp; tmp = atomic_read(&key->enabled); if (tmp == 1) return; jump_label_lock(); if (!tmp && atomic_try_cmpxchg(&key->enabled, &tmp, 1)) jump_label_update(key); else WARN_ON_ONCE(tmp != 1); jump_label_unlock(); ;-) -- Steve > } > EXPORT_SYMBOL_GPL(static_key_enable_cpuslocked); > @@ -225,14 +220,16 @@ void static_key_disable_cpuslocked(struct static_key *key) > STATIC_KEY_CHECK_USE(key); > lockdep_assert_cpus_held(); > > - if (atomic_read(&key->enabled) != 1) { > - WARN_ON_ONCE(atomic_read(&key->enabled) != 0); > + if (atomic_read(&key->enabled) == 0) > return; > - } > > jump_label_lock(); > - if (atomic_cmpxchg(&key->enabled, 1, 0)) > + > + if (atomic_cmpxchg(&key->enabled, 1, 0) == 1) > jump_label_update(key); > + else > + WARN_ON_ONCE(atomic_read(&key->enabled) != 0); > + > jump_label_unlock(); > } > EXPORT_SYMBOL_GPL(static_key_disable_cpuslocked);