Received: by 2002:ab2:788f:0:b0:1ee:8f2e:70ae with SMTP id b15csp231467lqi; Wed, 6 Mar 2024 15:44:19 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVMoWYVH+/88sVMmcAyalssXIWA/z7vjY28X83VuuOZwa/N5Y9EUpCCfaLu/VILbSwiN1uT+bldRZ6W/7wnJZuafHJPRg7wFpxcDM27xg== X-Google-Smtp-Source: AGHT+IHugG7PsVADbOpYa6DxsMkBlmDVAi7f/zt0x8eW2kdyyd3Vcgk82ZmtYI/q6wSY89Nznjj+ X-Received: by 2002:a9d:6b86:0:b0:6e4:d8b7:eb8c with SMTP id b6-20020a9d6b86000000b006e4d8b7eb8cmr8024655otq.21.1709768659475; Wed, 06 Mar 2024 15:44:19 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709768659; cv=pass; d=google.com; s=arc-20160816; b=hqlEQjGkxmerw0hKwnFE+eCbxMqAFbaiYe2rKxA0X+b1qN8DHWpaKNiSye3+RbO872 vYr7W5sLmKjJr7lmxUVj6gYCrgAo/BBvBO027tUDQNZM4I4KVLKDOIe1rYEK9Fy+50hO n/PvWPknwPcHS08hlQXJ8piVc6YIoqk5LwyaNQ+s3QbJRHaKK0ibwwWnLAl4+mAZPdxf WTY+o3K5Sfd3wFzbOhQQHDvUAsMT1+OJpnTkSSgCL9X6u8GzuUCg9cdEVn/dvsNaN/UO EgPSs22EWPqIDAd3T9ml9/iqAP0jEQVnNzUKCv+TgF2yJvjx1yYJUQinE6cfBFIHjn2p EJNA== 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=YRRJPgOIm3AhotX6vBnJdwb5yjXpiPKyeqILzc2y6wI=; fh=8kDUlIJ8ZNX/c5aaAUNfprl8VAlRjOAH9Xs9ZhVz4iA=; b=05II3mvxGZmQ+8q7w46n7Llcw81dJLqnkGOqLboShQMwr/DI3Z29bPZeHE5VAhA/Dy rSKzQOPpgfnTeZWjGTrt3+sOQLa4GQ1nnao2s8MjKKJW5skKlyTGXhfdoPkLe7i4CW26 xnFj+EIYSNRgKGpwM35bm7/a0zjVJA1pD2C7cdwyj0AMfJCGDd9t3vtpNl2I2SqcCIbK 0nFB80SHlfRP0swsxbz+mmTylRebT+G7nHUwnnz5ph7joepQsTTPnuckEe87elTgGcKg YEXTzV2CRHwmvJxNk57BuwKYxQWz7uQhhlcg6XkdFPKSCAdtoHvsg8UwyNg5djXnxc4M 8QDw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=hZa7c3ch; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-94743-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-94743-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 r202-20020a632bd3000000b005dc4895ec80si2194262pgr.159.2024.03.06.15.44.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Mar 2024 15:44:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-94743-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=hZa7c3ch; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-94743-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-94743-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 24E4128131F for ; Wed, 6 Mar 2024 23:44:19 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DE35A2868D; Wed, 6 Mar 2024 23:42:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="hZa7c3ch" 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 0D8121D539 for ; Wed, 6 Mar 2024 23:42:55 +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=1709768576; cv=none; b=oT9njD8KkdxMurOwDziUTBhIpk5RMSc9j/RaQMOQ6Xk9YhxleCO4HivhYF8ZyvMM79sNwhdXEMeCFh8710tfAqKGACkkaqQjN0YWnyEbGwFvppburDPPVjuO8mHmgOMfD/alCVWWx9SGMfESEx3yhbY5NdJ46N8vXZyvJmgtnL4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709768576; c=relaxed/simple; bh=UcIj1NgElwaYVIBc4qGuz5BB8JG1G2ZXHw9GrTQfZqQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=RQZt7AyhOAfh2UglM1ld/oGeskSmYYqLjBunJG1nC7ECC7KEoo1EKRh1xpqMgTdXE66tfGqGpniBx84F3ahpHdQLIwMvgr41a4EvYxdC+WC+gNQ7qiGOfF9S+uZaL6iJewLyxKio5w4Zj1KtL0WkY0eBbzXuybmb+B+nWsvEBxs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=hZa7c3ch; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 21698C433C7; Wed, 6 Mar 2024 23:42:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1709768575; bh=UcIj1NgElwaYVIBc4qGuz5BB8JG1G2ZXHw9GrTQfZqQ=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=hZa7c3ch/j0MhN56RFaxAHFPOqcRbGkZoHG07cI7OhP4hLzyBnf635aWoyWUPODmo HnnaFhUtb6usrMMnZhGe5UJRnNjr4JOipoBFX/Jl3B5inxP4UbGmSt4zZvbFca/J4i yjyGubgFueVxZCPGroXAc30i8bSzEXvRM2ztYqwjyA3v/Ne7MPn4rXprSEX3uNbNGx EUl2rs5vsxVi+Ph8kvyg7jQBlrDnD0fVJJJYyUxd42aKR1NVDxL567ibl4hZgpePfz hEeQzRKN9Tm1njmuJG5khh4umJFVUNejcjEP8onmANHCpahcfN7QkJC6WuVwBmaivN 4OZ7HDdPyGdqw== Date: Wed, 6 Mar 2024 15:42:53 -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: <20240306234253.zporv6cypoc7yihs@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> 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: <8f586bd2-c436-4334-92af-762a284e1101@akamai.com> On Wed, Mar 06, 2024 at 05:40:11PM -0500, Jason Baron wrote: > > > On 3/6/24 5:16 PM, Josh Poimboeuf wrote: > > 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. > > hmm, right but I think in this case the reproducer is writing to a sysfs > file to enable/disable randomly so i'm not sure if there is anything that > would enforce that ordering. I guess you could try the reproducer, I haven't > really looked at it in any detail. > > The code in question here is in mm/vmscan.c which actually already takes the > local 'state_mutex' for some cases. So that could be extended I think easily > to avoid this warning. Hm, right... For now I'll just continue to allow "disable before enable" (or "double disable") since it may be harmless and I don't want to introduce any unnecessary constraints, unless we manage to convince ourselves that it's the right thing to do. I'll work up a patch. -- Josh