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 CDF06C54E41 for ; Wed, 6 Mar 2024 22:40:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 689396B00A0; Wed, 6 Mar 2024 17:40:38 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 638F76B00AB; Wed, 6 Mar 2024 17:40:38 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5009F6B00AC; Wed, 6 Mar 2024 17:40:38 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 410726B00A0 for ; Wed, 6 Mar 2024 17:40:38 -0500 (EST) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 107B840C76 for ; Wed, 6 Mar 2024 22:40:38 +0000 (UTC) X-FDA: 81868084956.12.900BD3C Received: from mx0b-00190b01.pphosted.com (mx0b-00190b01.pphosted.com [67.231.157.127]) by imf30.hostedemail.com (Postfix) with ESMTP id C9EDF80010 for ; Wed, 6 Mar 2024 22:40:35 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=akamai.com header.s=jan2016.eng header.b=DG3ySLI1; dmarc=pass (policy=quarantine) header.from=akamai.com; spf=pass (imf30.hostedemail.com: domain of jbaron@akamai.com designates 67.231.157.127 as permitted sender) smtp.mailfrom=jbaron@akamai.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1709764836; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=9lGiShM8KJAIIqJroksHJTiyzZj4gxT5ZJZvfyYW3To=; b=HK//XS8cry0HFRDhdDU3UFejP0O8dIuhFWtLLq7BJ05tk1/JwnjorX5yUNAUfR1PeSc811 AJv5PZk6EHBkFgyEcESegvKYYn9vywpHfzIZVUrmjpjmUJLSNFgZ433+zeiSdoui6tgrTn Pc5nktJHk+0y3mMyJd/8Q1N0AtiH4EQ= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=akamai.com header.s=jan2016.eng header.b=DG3ySLI1; dmarc=pass (policy=quarantine) header.from=akamai.com; spf=pass (imf30.hostedemail.com: domain of jbaron@akamai.com designates 67.231.157.127 as permitted sender) smtp.mailfrom=jbaron@akamai.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1709764836; a=rsa-sha256; cv=none; b=7DKIJVtwMxY1XB6GFpRp9vK1F+I+9Xz7XpYgvizjgqz7YyFLARuUvdCDDSm1LQAHLpr7aJ iMqDbr5ghpyJ8VkN1cwRXMz0xi7cQ40Z4jpH7smRdtyEVmK5xNp6qA5XgWLZqz0i9CxauI pxpIcQuW9lHDlBKNPzaRsJKvS695ep0= Received: from pps.filterd (m0122331.ppops.net [127.0.0.1]) by mx0b-00190b01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 426IZslP008609; Wed, 6 Mar 2024 22:40:13 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=akamai.com; h= message-id:date:mime-version:subject:to:cc:references:from :in-reply-to:content-type:content-transfer-encoding; s= jan2016.eng; bh=9lGiShM8KJAIIqJroksHJTiyzZj4gxT5ZJZvfyYW3To=; b= DG3ySLI1eL1/QMp775EcMl7NcpY4VRvJ7xV+ke97E4NyI3gPRpJ79L1DJAWJaPpH XfMMywIakkrYp4aHch2maqeG+Etv0CWcP3YVCl//xojgBWj8vbaeE2XUut3Nd5gZ xGwyXDMxhfJFjMAAkIIR8B9MfAmB3gDGFlxfzgkMrE2sybKaGQDzoJHcGQiYxjz7 2C8b5fkqzCwheTKaXFLcO2aY3I6JlgMhOCgNQxFTVvQ6N5gMeqTh6GUdd2lr1pDe omBz6yfY3OxRsA/Es3+jgXya+/qbGmiJUKd+5+GZBUe931XbZom0nqWHDeZHt5KL NWXmGPDN5LKrQwDXeTWwFg== Received: from prod-mail-ppoint1 (prod-mail-ppoint1.akamai.com [184.51.33.18] (may be forged)) by mx0b-00190b01.pphosted.com (PPS) with ESMTPS id 3wnhxwuqtp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 06 Mar 2024 22:40:12 +0000 (GMT) Received: from pps.filterd (prod-mail-ppoint1.akamai.com [127.0.0.1]) by prod-mail-ppoint1.akamai.com (8.17.1.19/8.17.1.19) with ESMTP id 426KiaZd007517; Wed, 6 Mar 2024 17:40:12 -0500 Received: from prod-mail-relay11.akamai.com ([172.27.118.250]) by prod-mail-ppoint1.akamai.com (PPS) with ESMTP id 3wm0b23hf2-1; Wed, 06 Mar 2024 17:40:11 -0500 Received: from [172.19.35.123] (bos-lpa4700a.bos01.corp.akamai.com [172.19.35.123]) by prod-mail-relay11.akamai.com (Postfix) with ESMTP id 8990932E9B; Wed, 6 Mar 2024 22:40:11 +0000 (GMT) Message-ID: <8f586bd2-c436-4334-92af-762a284e1101@akamai.com> Date: Wed, 6 Mar 2024 17:40:11 -0500 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [Bug] WARNING in static_key_disable_cpuslocked Content-Language: en-US To: Josh Poimboeuf 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 References: <20240306105420.6a6bea2c@gandalf.local.home> <20240306193101.s2g33o4viqi2azf3@treble> <854e523c-c467-47f6-b977-933cbaadeb62@akamai.com> <20240306221650.sw3lha7kca2quv63@treble> From: Jason Baron In-Reply-To: <20240306221650.sw3lha7kca2quv63@treble> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-03-06_12,2024-03-05_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 phishscore=0 malwarescore=0 suspectscore=0 mlxscore=0 spamscore=0 bulkscore=0 mlxlogscore=517 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2403060181 X-Proofpoint-GUID: xlQRlCxMYCLpV9SfyJtbU8EamUsfkC6V X-Proofpoint-ORIG-GUID: xlQRlCxMYCLpV9SfyJtbU8EamUsfkC6V X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-03-06_12,2024-03-05_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 adultscore=0 bulkscore=0 spamscore=0 priorityscore=1501 impostorscore=0 malwarescore=0 phishscore=0 lowpriorityscore=0 mlxscore=0 mlxlogscore=330 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2402120000 definitions=main-2403060182 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: C9EDF80010 X-Stat-Signature: 415oigjfgac3nbrphedu5guft3kjcbsa X-Rspam-User: X-HE-Tag: 1709764835-778040 X-HE-Meta: U2FsdGVkX19v6b/Gcr+exGutIAhDJLJ4hkvZnJKKdK8ayHnQMD938kMiVMrbSFlMrrEcrxtYws1f9qEvDLGYsfU0sqvqzY5QwXwRGCPUnJ+yALPAaSQ921kVBy3xerEcXcj0wFQxKoySmb21BCD3Zcl/awjw/w4fYyyIDoTXaDWzS5UXX7g3fY26hwa8+5V08ALsrqetvYSd/a+Q8sKnXRQko9toCF68a+rYXRMVja7K7Q8turFoNa5TGAQpNbN27cDh0wEZKxUfJjtOw0+1UIY8Fbo4I8h7jjkKX4QjlfB1q8CWukgD8VquGS+W2HLKzkN8vLo/Wl0/vhACh38z2UVnri1I3IGUsXL1WCDz11ndCoqQQtY56tusOx9FZBvoqIQd2nbUfdtrkmMAsD7uAQbnrR2qxKSeXr9N1XHAbnd65JmZTxLAHTPd9bvUq5rTTwgzpfA2UzequaKTM5Z2Sx8bqYU1PDzcC1myCiSNaWHATrcqSJAe84ccdOyvLTtmoBAG9UP8NXScBL6kKB8y9xHbGU5D1Qw92QYXyEs3Az9z8owz8eeEb/hTpYGktPEzzc+AzFmwk2kqDtEOnTN4Sfaej8tQO7GXPw0r55NhRw0LmOmpPvQX653PS36w5hifpuwiZ02jvrbvMniSutyo/vzhOvNDmnLOpdvXJadHBC8uvWnrH+jNEa4UPVrB+6lI5S8G0CS+78V4CIe/4fPkXLN4PKRBgxqpDYaJoNF/r4usdKg8W7Ql175Y0gap7WE78+MH5I/1ZzZGotYjnuvw5x7z0BFSv0EgBys8Humeo/C1hpxfhqUzDsKubuRIvHmTmRHpx6DKAmCqgXYOzXz49xTZUnlUOXRChhkPLx8KHfN4ye2CGOIbpUFVvLJ4bM7ojnxIayNL677XpG2bVnhOVWvDsOrR3gGwfJu5Iuo/eHQJA9tbOna/XeTWB5E/hEE2QHQHJR1Q+HYUSxW1tLC U0bzEy80 sFFd7oyOUCgUN2nbMYqxxVKwqFWdKnK+egC+spMF9Ueyq9gQAQuVHZD5qt/1ESBES8ZGs/9JBr0MAsjo= 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 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. > >> 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. >