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 0DC78C76196 for ; Fri, 31 Mar 2023 04:13:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4CC486B0078; Fri, 31 Mar 2023 00:13:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 47CAC900003; Fri, 31 Mar 2023 00:13:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 346F7900002; Fri, 31 Mar 2023 00:13:38 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 244C96B0078 for ; Fri, 31 Mar 2023 00:13:38 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id E9712A0657 for ; Fri, 31 Mar 2023 04:13:37 +0000 (UTC) X-FDA: 80627874474.23.FBF6A5E Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf21.hostedemail.com (Postfix) with ESMTP id 4AAE11C000F for ; Fri, 31 Mar 2023 04:13:36 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=CP+72kPP; spf=none (imf21.hostedemail.com: domain of mcgrof@infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=mcgrof@infradead.org; dmarc=fail reason="No valid SPF, DKIM not aligned (relaxed)" header.from=kernel.org (policy=none) ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1680236016; h=from:from:sender: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=6s8/wXq1GxsV1r8etdzH1BpK1sI7285si77FNcbGlkk=; b=7ECrze5YfjQah4E+GGY4ix/S/9jzfrq2BcS4bbb1dspGZGak/xH1aN+spKXJS7TpzKubCT 9TViGNqwgL5jY2hkSikHQgZbhazbyoKk51ivQvE1DOEnCbS+wAdqp+uJFdg6TYwp57S9L+ Zb7OITMQ//JMUcxml1nG6m8h2AAWvfQ= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=CP+72kPP; spf=none (imf21.hostedemail.com: domain of mcgrof@infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=mcgrof@infradead.org; dmarc=fail reason="No valid SPF, DKIM not aligned (relaxed)" header.from=kernel.org (policy=none) ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1680236016; a=rsa-sha256; cv=none; b=kQ295xZWFutD4RpuUwlqXvJ3I6hrY5fTj31JakYKVNZ1Zur96kXjeBEYe3eLan6ct3GA0G hyhQeymzVunw0wIt6NVQgfClyBxsc9KBJpaWqv5Tk9Y0hSjHSV/npAsobaDmUxM9IdQ/Gb yIiZQHuWkKbpVFnXoMX4KPLpxZZo+HM= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Sender:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=6s8/wXq1GxsV1r8etdzH1BpK1sI7285si77FNcbGlkk=; b=CP+72kPPTJpNo9iaz6wxgKX8kW Q39hPK0hJZpdYDPekETkH3PSjf98L3qwdvirSqoSNGBCU71pt6cuxa0jcwNirlBBu3xVBpdCqaMri jkzEH/xjSNJMG64PIyJukIPmNo9b3mKlNzYzu9vveLhhs2+p3E7HUrBtfxQxtudKNSnntp3ZCB4rE lzMF7JUdxwzHRFO31GahMgy17RUU5bq0FLmXqiO5VQzTw21Yr6/D1RFrzGE1EodfzjOMHv2ZtlVRO TcwyTcrkRrbbK0CuMe6/iattalDH7w2oQnZWjaYS8g/eBgMlj1aQ3b5Qemk57s38tkRVllfmxns5u z3citFrQ==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.96 #2 (Red Hat Linux)) id 1pi68n-005mck-01; Fri, 31 Mar 2023 04:13:29 +0000 Date: Thu, 30 Mar 2023 21:13:28 -0700 From: Luis Chamberlain To: Matthew Wilcox Cc: Linus Torvalds , Peter Zijlstra , Petr Mladek , Sergey Senozhatsky , david@redhat.com, patches@lists.linux.dev, linux-modules@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, petr.pavlu@suse.com, prarit@redhat.com, gregkh@linuxfoundation.org, rafael@kernel.org, christophe.leroy@csgroup.eu, tglx@linutronix.de, song@kernel.org, rppt@kernel.org, vbabka@suse.cz, mhocko@suse.com, dave.hansen@linux.intel.com Subject: Re: [PATCH 4/7] sempahore: add a helper for a concurrency limiter Message-ID: References: <20230329053149.3976378-1-mcgrof@kernel.org> <20230329053149.3976378-5-mcgrof@kernel.org> <20230329072112.GG4253@hirez.programming.kicks-ass.net> <20230329091935.GP4253@hirez.programming.kicks-ass.net> <20230330115626.GA124812@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Stat-Signature: 3xzi9bsa3a1r1damocati1t61ad3ipji X-Rspam-User: X-Rspamd-Queue-Id: 4AAE11C000F X-Rspamd-Server: rspam06 X-HE-Tag: 1680236016-342717 X-HE-Meta: U2FsdGVkX1/nEuUx0u18JdtWVHmQz02dpUaroeVc8i0VU9C1LIw3AOiaDdnRK+ZKYoosZxeRCamFllN6wETAhlb4X6yzPdEGg3IyTKPkAcQXtWHOoSjRTo+khr2RGEtTLoqCTMkqKihKOiBxhKjv1ohszJS3a2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PUFj3MIf0Sy1W09FvDudxU5MLAq3+R2evFduvEi/VoWkLPIMd9CuVVJ1zG+YEYLo0En/ZMPfMyWGIUbViQ8Ktij4g0Bfg= 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: On Fri, Mar 31, 2023 at 05:06:17AM +0100, Matthew Wilcox wrote: > On Thu, Mar 30, 2023 at 08:45:52PM -0700, Luis Chamberlain wrote: > > diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c > > index 291d4167fab8..00c9fcd90e1a 100644 > > --- a/arch/x86/kernel/cpu/intel.c > > +++ b/arch/x86/kernel/cpu/intel.c > > @@ -1177,7 +1177,7 @@ static const struct { > > static struct ratelimit_state bld_ratelimit; > > > > static unsigned int sysctl_sld_mitigate = 1; > > -static DEFINE_SEMAPHORE(buslock_sem); > > +static DEFINE_MUTEX(buslock_sem); > > > > #ifdef CONFIG_PROC_SYSCTL > > static struct ctl_table sld_sysctls[] = { > > @@ -1315,7 +1315,7 @@ static void split_lock_init(void) > > static void __split_lock_reenable_unlock(struct work_struct *work) > > { > > sld_update_msr(true); > > - up(&buslock_sem); > > + mutex_unlock(&buslock_sem); > > } > > > > static DECLARE_DELAYED_WORK(sl_reenable_unlock, __split_lock_reenable_unlock); > > ^^^ clearly unsafe. __split_lock_reenable_unlock() is called as a > delayed_work(), ie not in the context of the mutex locker. lockdep > will freak out at this. > > > @@ -351,12 +351,12 @@ virt_efi_set_variable_nonblocking(efi_char16_t *name, efi_guid_t *vendor, > > { > > efi_status_t status; > > > > - if (down_trylock(&efi_runtime_lock)) > > + if (!mutex_trylock(&efi_runtime_lock)) > > return EFI_NOT_READY; > > looks to me like this can be called while we're oopsing. if that's in > non-process context, lockdep will get angry. > > > @@ -149,10 +149,10 @@ EXPORT_SYMBOL_NS_GPL(efivar_lock, EFIVAR); > > */ > > int efivar_trylock(void) > > { > > - if (down_trylock(&efivars_lock)) > > + if (!mutex_trylock(&efivars_lock)) > > also can be called from oops context. > > > @@ -228,7 +228,7 @@ adb_probe_task(void *x) > > do_adb_reset_bus(); > > pr_debug("adb: finished probe task...\n"); > > > > - up(&adb_probe_mutex); > > + mutex_unlock(&adb_probe_mutex); > > adb_probe_task() can be called from a different context than the lock > holder. > > > @@ -10594,7 +10594,7 @@ static bool bnx2x_prev_is_path_marked(struct bnx2x *bp) > > struct bnx2x_prev_path_list *tmp_list; > > bool rc = false; > > > > - if (down_trylock(&bnx2x_prev_sem)) > > + if (!mutex_trylock(&bnx2x_prev_sem)) > > bet you this can be called from interrupt context. > > this really isn't something to use coccinelle for. Coccinelle gives you what *would* happen, its up to us to review if the conversion is correct. Thanks for the feedback, seems like we're not going there for some users, contrary to what we expected. Luis