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 3CF86C54E41 for ; Wed, 6 Mar 2024 20:12:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9775F6B0071; Wed, 6 Mar 2024 15:12:33 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 927246B0072; Wed, 6 Mar 2024 15:12:33 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7EE8B6B0074; Wed, 6 Mar 2024 15:12:33 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 706D06B0071 for ; Wed, 6 Mar 2024 15:12:33 -0500 (EST) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 3B58340298 for ; Wed, 6 Mar 2024 20:12:33 +0000 (UTC) X-FDA: 81867711786.30.AA9F5A4 Received: from mx0a-00190b01.pphosted.com (mx0a-00190b01.pphosted.com [67.231.149.131]) by imf07.hostedemail.com (Postfix) with ESMTP id DABB740015 for ; Wed, 6 Mar 2024 20:12:29 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=akamai.com header.s=jan2016.eng header.b=MCMBbqGv; dmarc=pass (policy=quarantine) header.from=akamai.com; spf=pass (imf07.hostedemail.com: domain of jbaron@akamai.com designates 67.231.149.131 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=1709755950; 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=emefHZakE6HNZ1TpPWmcBXM7ziPm7C6zlzbUYgZW+jU=; b=QJ+4rVIPyCSA7Z72smNoU3XW1WNTY+vli66ylyMc8qo3uA7FjevfBSkjXR1z4xZ5i8K0xv m29tDmT37WuclU7WECadbo63WN1uR9qvNLr+GamJ6epYWFWFZ8h5m4+OBec+CFNHwePy77 AMcGgs5VOIYjHh+JZiawBJzfrdJZieM= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=akamai.com header.s=jan2016.eng header.b=MCMBbqGv; dmarc=pass (policy=quarantine) header.from=akamai.com; spf=pass (imf07.hostedemail.com: domain of jbaron@akamai.com designates 67.231.149.131 as permitted sender) smtp.mailfrom=jbaron@akamai.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1709755950; a=rsa-sha256; cv=none; b=0xIgJrJDkv97K2HX4orU5SoU6BCcFwmnzAUbLtOsTG2iCjHU68ozOGCgbBIcPJd9nlbxHH rBgW89i0iVRJ/Pm6n9vz6a0HJemlqJ4pT4dhv7DAulikf8y0tqJkGi69Awwx2DHard7qVF 3RRo2H87LC4npebQW9XkZOHh+lK6b90= Received: from pps.filterd (m0122332.ppops.net [127.0.0.1]) by mx0a-00190b01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 4269jX6H026694; Wed, 6 Mar 2024 20:12:09 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=emefHZakE6HNZ1TpPWmcBXM7ziPm7C6zlzbUYgZW+jU=; b= MCMBbqGv6/9/0Dmqg3neFLdXqR/rsGd4m2XZd2ZibSXwsffSwtp38DnzsEejthNP hgpuIatT/m2dtMbGdp35tmFdury1c2Un+ELhjiNsOqI4OkWmx5z2a9zGmzj+KLZn ktOhAm5WxhfZQT/CMQirDnZXktJ5IN5ZMz0Sg16UNprbRfIYJBxWEHqIF4iXiwP5 OUCgHmZp+heZsFQ/XRooFLJdKZOSHOcc5ZdMTs+y3ZYLxhKmuKIQ+XVfTFqEyA0V o0hOZhuyMgSXmYoqCnmv+r4zGuQc/fzPgfeRBhODGnGqBjv1xaUDK/cEKmlbwv+5 Eai8c1Ld2hYMu0xau83f0g== Received: from prod-mail-ppoint1 (prod-mail-ppoint1.akamai.com [184.51.33.18] (may be forged)) by mx0a-00190b01.pphosted.com (PPS) with ESMTPS id 3wnhxwtf17-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 06 Mar 2024 20:12:09 +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 426Fe5wP007558; Wed, 6 Mar 2024 15:12:07 -0500 Received: from prod-mail-relay11.akamai.com ([172.27.118.250]) by prod-mail-ppoint1.akamai.com (PPS) with ESMTP id 3wm0b238we-1; Wed, 06 Mar 2024 15:12:07 -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 4E36F32E9B; Wed, 6 Mar 2024 20:12:07 +0000 (GMT) Message-ID: <854e523c-c467-47f6-b977-933cbaadeb62@akamai.com> Date: Wed, 6 Mar 2024 15:12:07 -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 , Steven Rostedt Cc: 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> From: Jason Baron In-Reply-To: <20240306193101.s2g33o4viqi2azf3@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=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2403060162 X-Proofpoint-GUID: JNqldSr41N-PhmmuRCJXIOHnE4atJn4Q X-Proofpoint-ORIG-GUID: JNqldSr41N-PhmmuRCJXIOHnE4atJn4Q 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 mlxscore=0 phishscore=0 adultscore=0 malwarescore=0 lowpriorityscore=0 clxscore=1011 priorityscore=1501 mlxlogscore=999 impostorscore=0 bulkscore=0 spamscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2402120000 definitions=main-2403060163 X-Rspamd-Queue-Id: DABB740015 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: bybhz3kxfj6jith98tusgnqwp64huxwx X-HE-Tag: 1709755949-848014 X-HE-Meta: U2FsdGVkX19zBSpvDjUk7UCptmz+b54rHt4m8oVt2i3sMLQ2gmp4rXjdKrjd6QzpyKxXelwlG6CWs+yNSDcDrhdimNCEAW7Cl3zgEDP5k8aSpDhyJ5qBJrkCXpehhsFU4Xg9gxQctP+DGqX58YShR+I+Q1gllBoIgn6aDaW+fUvMQPSLqrL3Bi5rwW1ekuoVgraqdxOVH0HdCczgqNuaqjZYsoHhlXijtUuf0vEPRpQbnirlcHpmiXf4QGYofhOa9KJUZAc300rQA2/eWdgJVGy48j4qf9xFPSe4qwcqVSGuz6lGlUIkgbSl+NCm6emng6VwIDCOLe7IHH+5AypBlDlB1FK16YbiQbfFxUaZLvol+QSYluqfZi6qTzRdFrdAkH4nM9+/JhECFRwtW/FexlRSbetk1wKvra0KixP1GtxRqYRXotSwcYkFGJi1/E6U21RhcrvrOuZ1Mad74HQd3CixoyKcWzER/b1+e2YSBKbCiv3tL/0OquicQQTp9wvD0aG8VnkU9tHKTFO6O7KfSd2Vo7O6eptLe5Lrgln8V4U0VqMPktKmmu0SJc/dtHQxeQMKLqBOF3tGddWcZlCrdfq3jQDXFG7gzzQT+laAVmOgmO9vsNVe2EH8gjMbATXfA1n+cargacCSE+52HHic1+uJWlQ/S+UAH6XtB/NJMpYcXKjm8rgR0HFe7ypC0nq5XcMMFOoT9KeEByQCky5m1ZpCvjOakQl5efIE468vvSdpHlZjgpFyj3OuWHIVV820+468NyhUgXWlnJ9Y+qzgb6kySrEyx7ZEoNnZlHv9+S/5QnFTFV1HKeO+5f3/MdwsVd3Us8h/nE4rtfDg8TYOdUUtw8vo9bFnuQnBLJpOY0TrJNIIw9psyjkhOQLPLsQSdut0PIcMvNDfhKH1Fc5PZL/SWhLwyDJeofrTUJ/2u7MOX2yL7NKywZSU0qFeKemqaGx5+lVINNdD3zHErwn P8scLDoh v8rFyZ4quHCetKalV26Oq521n8omNjCzNtuxbp/9LDQhEehoAAoJvpdhLTOnp/JDfaViR8YLsMJ4yM0k= 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 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. So I think a concurrent disable could then see the -1 in tmp and still trigger the WARN. 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? 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... Thanks, -Jason > > diff --git a/kernel/jump_label.c b/kernel/jump_label.c > index d9c822bbffb8..f29c47930d46 100644 > --- a/kernel/jump_label.c > +++ b/kernel/jump_label.c > @@ -191,11 +191,14 @@ EXPORT_SYMBOL_GPL(static_key_slow_inc); > > void static_key_enable_cpuslocked(struct static_key *key) > { > + int tmp; > + > STATIC_KEY_CHECK_USE(key); > lockdep_assert_cpus_held(); > > - if (atomic_read(&key->enabled) > 0) { > - WARN_ON_ONCE(atomic_read(&key->enabled) != 1); > + tmp = atomic_read(&key->enabled); > + if (tmp != 0) { > + WARN_ON_ONCE(tmp != 1); > return; > } > > @@ -222,11 +225,14 @@ EXPORT_SYMBOL_GPL(static_key_enable); > > void static_key_disable_cpuslocked(struct static_key *key) > { > + int tmp; > + > STATIC_KEY_CHECK_USE(key); > lockdep_assert_cpus_held(); > > - if (atomic_read(&key->enabled) != 1) { > - WARN_ON_ONCE(atomic_read(&key->enabled) != 0); > + tmp = atomic_read(&key->enabled); > + if (tmp != 1) { > + WARN_ON_ONCE(tmp != 0); > return; > } >