Received: by 2002:ab2:788f:0:b0:1ee:8f2e:70ae with SMTP id b15csp194361lqi; Wed, 6 Mar 2024 14:16:59 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCU40ZEkbYmStW3IsliyLOBc0zYG3rRoY7z9YQqSLbrfKwMS+vWEBrO5sfnG78h147+4TI3L2kX6NqlReuAgcG1bHgCi90rHUvk/Xx+NqA== X-Google-Smtp-Source: AGHT+IEAURePpMuqmeKFlbvFXj6SFvXyQCjdmVaRKoxR2kfe4YNxvtr/BTyagoTleLU7mSrU/Ek0 X-Received: by 2002:a9d:6e87:0:b0:6e5:390:5b44 with SMTP id a7-20020a9d6e87000000b006e503905b44mr2041754otr.30.1709763419524; Wed, 06 Mar 2024 14:16:59 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709763419; cv=pass; d=google.com; s=arc-20160816; b=gk6pe2OCryDsxLppc1b6HjwhOa1rGumx4t+hDPX5OXx0vmaaY5vY42BFKpFPRJvxso WgdRczF5xMij5kry0jxqRjpMfMvUHsyh5On7dtH0HH4wg4/9ja4jRQD0wOgto1gtynW+ 5CrvzXHBVxxWa8AMLp8ZUJ+W0u/OP6rz4M7HhgJymaptJlK7ce/AJoXBJthN1vbegjDj R0uRnmEe45hYaFaawWUMHAnjHgAtLow8b9FC4IbOmTsjDNR36Vx7QhanvKKJn7Kz43cu OoaWAmxSUkHrEM3yWPwsTKlZz3SlqAenq8WPtLw8s0H+zq+R1/rm8UThTDMu8wmolYFQ 3iVA== 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=cNfaJ/SbpTdq34rD+dYmgvg3l8qbBt0ysk8M1vSjfvE=; fh=8kDUlIJ8ZNX/c5aaAUNfprl8VAlRjOAH9Xs9ZhVz4iA=; b=D98dC9Aegwjx2QH9c8WxhHrcnMXPgMeM4TEPA1Hg4dpo/XNy4Q0MzsQ4YYD/YeM/Bq GELXno5TB9eOU7NP1s326HgIdJ5qfHvF2USGuh+Tzaiiz/5jgBh3qyGNnTFUk6Bf6QA3 fBdqXD9MlFnn8RE8pp1jVOzFWORcwLbIpTNK/X+pDBGIVXyLvcBoP5j5iVhAILiR/zhH 1q0iVQt1AgkvRhKjGLEvNJxcR64YiZIkpt3fvYL6itWSWRjZTlcptukKfgNXxItX3H4p ILgmy4XZlCgoZs2o3g96mILIIBVELgjNjdiMDWCZJx8/CU55cRBlVSvSS4w0wV9EOBrD 2tRw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=KAHb35XV; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-94642-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-94642-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id r13-20020a63e50d000000b005dcbb9cf3a4si13029530pgh.129.2024.03.06.14.16.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Mar 2024 14:16:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-94642-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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=KAHb35XV; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-94642-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-94642-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 1B1D628240C for ; Wed, 6 Mar 2024 22:16:59 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 33C771BC4B; Wed, 6 Mar 2024 22:16:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="KAHb35XV" 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 593F21BC22 for ; Wed, 6 Mar 2024 22:16:53 +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=1709763413; cv=none; b=qrx3rpgjwKPz0Zv7p/1tq+spWmeyYAknX1evVbPZ2hoSUN9tteSvep7/iGxD4mMPish6XTAwGyI2hNjfgP+9VxzF7ocVuBj81s8bMPCK0h/UfDx2TOGPvjFD1GYa1kqs7+g/R/UImo9amnP+wuz3oQ3ajpF6DehiazOJL4mEllU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709763413; c=relaxed/simple; bh=YM/H338B8M01FdZ46y0o1dHxsvV8JzksBNCBnoZtyNw=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=RV7IuufSS24v92I5ciHciMxR9O493S1NtANE6nqH29JCDLDnBbn1YyXGeYFqEwjHtupjH2r47FsWpfFsLiy78a6GN0luprJ482NhROfjcENZEDAOlc0OsX2WgudtMdiqZ7VyqT7PDkIO56fcJGaKXyEu6tsmNglCMX+5mv4e8xU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=KAHb35XV; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 71FBFC433C7; Wed, 6 Mar 2024 22:16:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1709763412; bh=YM/H338B8M01FdZ46y0o1dHxsvV8JzksBNCBnoZtyNw=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=KAHb35XVNOAsbZEKcgCqU8E/MP7fIzvLwtSBgmbKQVVGokuSzV15djI/zw9fqrC+h m9/0EkQXCwKysGi/k11GzlM0JKQD+liQ57lPVMC9C6kH9TH+2nTLQPNuHWS9Lztpvp Ki6xJ8j9+MG/hjkAwl4rQ7RATa0xd+L5gZiv5c5iGNyvScuaFXD+kLvxcRmhi0cyr3 /ye6KLpPNxI4kEVBiT0Gq0uvSjXj6CCbfFrJ6GPTpmkxxgcYgUsxoGOCnAKuuQ8qfn GsuqPgBrUL7iTtH1rbsiqcq4Jc3DHxgvEhML2JJrDZOsLWe9XLpG9EuB3J6mvjWcbi Qvdl8uFDh99CQ== Date: Wed, 6 Mar 2024 14:16:50 -0800 From: Josh Poimboeuf To: Jason Baron Cc: Steven Rostedt , 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: <20240306221650.sw3lha7kca2quv63@treble> References: <20240306105420.6a6bea2c@gandalf.local.home> <20240306193101.s2g33o4viqi2azf3@treble> <854e523c-c467-47f6-b977-933cbaadeb62@akamai.com> 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 Content-Disposition: inline In-Reply-To: <854e523c-c467-47f6-b977-933cbaadeb62@akamai.com> On Wed, Mar 06, 2024 at 03:12:07PM -0500, Jason Baron wrote: > > > On 3/6/24 2:31 PM, Josh Poimboeuf wrote: > > On Wed, Mar 06, 2024 at 10:54:20AM -0500, Steven Rostedt wrote: > > > Now I guess the question is, why is something trying to disable something > > > that is not enabled? Is the above scenario OK? Or should the users of > > > static_key also prevent this? > > > > Apparently that's an allowed scenario, as the jump label code seems to > > be actively trying to support it. Basically the last one "wins". > > > > See for example: > > > > 1dbb6704de91 ("jump_label: Fix concurrent static_key_enable/disable()") > > > > Also the purpose of the first atomic_read() is to do a quick test before > > grabbing the jump lock. So instead of grabbing the jump lock earlier, > > it should actually do the first test atomically: > > Makes sense but the enable path can also set key->enabled to -1. Ah, this code is really subtle :-/ > So I think a concurrent disable could then see the -1 in tmp and still > trigger the WARN. I think this shouldn't be possible, for the same reason that static_key_slow_try_dec() warns on -1: key->enabled can only be -1 during the first enable. And disable should never be called before then. > So I think we could change the WARN to be: > WARN_ON_ONCE(tmp != 0 && tmp != -1). And also add a similar check > for enable if we have enable vs enable racing? My patch subtly changed the "key->enabled > 0" to "key->enabled != 0". If I change that back then it should be fine. > Although it seems like the set key->enabled to -1 while used in the inc/dec > API isn't really doing anything in the enable/disable part here? > But then the key->enabled I think has to move in front of the > jump_label_update() to make that part work right... Yeah, this code needs better comments. Let me turn it into a proper patch. -- Josh