From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8BAFDC5475B for ; Wed, 6 Mar 2024 23:42:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E0EAF6B00BB; Wed, 6 Mar 2024 18:42:58 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id DBECE6B00BC; Wed, 6 Mar 2024 18:42:58 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C86546B00BD; Wed, 6 Mar 2024 18:42:58 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id B870E6B00BB for ; Wed, 6 Mar 2024 18:42:58 -0500 (EST) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 7F5DD80571 for ; Wed, 6 Mar 2024 23:42:58 +0000 (UTC) X-FDA: 81868242036.20.6228320 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf07.hostedemail.com (Postfix) with ESMTP id CBB824000F for ; Wed, 6 Mar 2024 23:42:56 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=hZa7c3ch; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf07.hostedemail.com: domain of jpoimboe@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=jpoimboe@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1709768576; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=YRRJPgOIm3AhotX6vBnJdwb5yjXpiPKyeqILzc2y6wI=; b=tPoKYPkYArVbsKENN4Y1k1G/irqvzo5rPQcMXz4CMh8uRJRV/JXW1PSJRIDUJOxCV83FGQ OENi7LLOb8bX4rBPYciwaCxdvlWKXUdvCxW7c4Dg+5dTZN6DKPIf0jZQ+L2v8fcWxPYT30 WKajqM5YQKL+pTgZs4AD9kAc+A3Lbm4= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=hZa7c3ch; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf07.hostedemail.com: domain of jpoimboe@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=jpoimboe@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1709768576; a=rsa-sha256; cv=none; b=1ckxs2+I074lBU8C9/zYFeBTocYzxUnr5gCcTJxDoUg+FZvBWV0ol6uQnsYsYLgILGBPJ9 zNO45T6Nii2eFfl4GdZqYeeTT8oaYByd99pUmnC/axFKwed9y6rCIQpEYqpRq3WpW7dyLo OvAf+NG2oU9LmJXk5YCgLoN8rv2O6cU= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id BBCED618EC; Wed, 6 Mar 2024 23:42:55 +0000 (UTC) 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> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <8f586bd2-c436-4334-92af-762a284e1101@akamai.com> X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: CBB824000F X-Stat-Signature: uu4rsjh6w94yjwxbqud8bzh7wu3rthwg X-HE-Tag: 1709768576-248706 X-HE-Meta: U2FsdGVkX19LgHisNCLMmXdVdHj0OR6v/OTxEjgniwD9TWtDRlxKUpjYQlKXaAHd2/ug5dXzH3Nsp9DlLj6tyWvi08lPF2jSvsp5Q9eoDaBzqjTqJUVrH63tH/sOBn35k+xcFVIIcpaNFbVgqtqNLPlmcEfItthyajzLYAcZJHgQZmIhb35+llz/zJJhCZOeNXr+75xLRpIq7Ib46Ky4uXd0gbSo8XpT8enkQqv0k0hcmD3NYi5kkFNQVH+BmfUqAJCy1lxdiMuRTkXDTNvdmtVi8aVxPsMpCftY+CJrdah8Hou602kMAUa2o2N6Pq7X7s9vTCB86Q50nxucYfqinr/08LoeOJ6kSN8V2qey2d+HBpUttCJcyZQ8oemGq3Y360KfdXGUBpZsoExxpnEkeWclaKamL2Yh8AWGRDc89jDVF43p8hfJpGyU6ck7vrNaQ8iVK/6HOkDqo/HRrb/tf6LOiIykVfaEfmNNMC41fqVZRI5oD5njursay1dKStPPADqZV1Gv3l8JO6J0HvNMZHOy33VgDvNGCr5eCkMZ6JXWIHbQD4X/d47/9rIKa7HXMJlQMP194/UykKm8Vs1YxDhl/Yh0mU9raeXaHVdAjZ0TlyuxVbbAIXfJCZZLL477+EYRdfWszuVqBIA6MnpdUFyHhMXOYfSWPvlzcHpTSx6gubGjkW/4tLM11aQJ60U995nIcM+qlW/udt95F9lxSnsY4ShZbFK1JKjTruhVMd2iRnxVxDEk0tkBh1+Tcy7nzxhS1Ksut0DA2++enioTZ1vvLpdgGCsMx8OvIPC3HOr/WhClKq95HIHzYNMPced2bD8+oFj5eMCs3Q/Ig3nCkVHmkGqe705/1TeEGHfRj6W/VYf0ycRqaWDOEhPhX316czv5/+iaiVsghdqEI3tDTf5IxtHiwjDk9BVzLcHkf77I4U+J4c0opM/+NSondsXfe9E0EBPki0R4PCdjz+q vPG+4nib wRfJsMiuKe76NdqPq5tBbY+7Cubl6OQ598UUbA/bjscrcwSB8v+m5CoeHYf+GHItkLvVrB1Vy/VpGCOHa7Ah0YO0XsQYAyBINabNz1QNlrBU0haGTEXYHgfn01DNOtpNEGKazRbzVpoyfM8XrzDXqd+KwMVyRumbkkCoos7Jn32LImk1+2YGYYEm08anz0sYOIghIA63+mC30U+a+uVEkxKloG6eQsHit5KPeWf43oJQicu7R3OUW+R7aCQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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