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 380D5C77B60 for ; Fri, 31 Mar 2023 04:06:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 56D206B0074; Fri, 31 Mar 2023 00:06:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 51D606B0075; Fri, 31 Mar 2023 00:06:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3E4A36B0078; Fri, 31 Mar 2023 00:06:41 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 2E1EE6B0074 for ; Fri, 31 Mar 2023 00:06:41 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 0186AAC1F7 for ; Fri, 31 Mar 2023 04:06:40 +0000 (UTC) X-FDA: 80627857002.09.7F80BFB Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf02.hostedemail.com (Postfix) with ESMTP id 89CEB8000F for ; Fri, 31 Mar 2023 04:06:37 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=J1eZx8Rm; spf=none (imf02.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1680235598; 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=gBX524btH9snFWHEFtS36Ef/+oCds0DOnnoMhfwMpMA=; b=AyntV4FbsGvnavSk2Juw9cwui1CrooBILrqxTIYcuv9YGBlNFiI4PQjPbavMCP3Twkt7Y4 xk5A7NXDa8/yxU8XBqqSWVyBDdVlR2Ee/6EcN08iKh7df0g8Fnji7hZwI2kzTvSZkZ2K9r KmnEPDalxPWfRJeWr7VELBYh1pTSmdU= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=J1eZx8Rm; spf=none (imf02.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1680235598; a=rsa-sha256; cv=none; b=BN9NRQi8OU8bYmss/qqkwn26Hl7wlOHDPiXzflRC2EMO8upYf+nWqNR+UPz19xWytDRvTD 8lAedppVUkfunzMpBhS+JUNwlOSgX1FEF3jJ4noMcpkUX+TNCaWqG9b8SxDnoRA6/E5rZ0 6yl1ZrF3UGraA2v8Qthx66t3pzMgy64= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=gBX524btH9snFWHEFtS36Ef/+oCds0DOnnoMhfwMpMA=; b=J1eZx8Rm7eysxvm+rRg6aidaJ5 EGFAyV5KfQyxXPN9YFGgTfqF6YmMSxY/FV/CmA79NzzL7oSkW/V9lKfAVv6mwsatzXGp4BqvbAuMN XBUhT/rUA5CPn1K3nq2RIQPRW7cARbZR0X3duW6ogmIepNETe/GVQx72OM6rQw3X2SMKVxNcYkNxS Tc6cEWSAOelrW9o8mCm+JSXZjsWwBzNkoYerEK5fbL7xcme213r4+GZLK2OaWv5RNjfjVDRNBFJ4P i7QXH9DzxP8NyCHnerM5zHKUcI8t14VI60PhR/CwgeCDND7pSHApYpHfpwwd7Df1L9qJqM2hJ4KcE QGYNq4AQ==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1pi61p-00B4Tq-CB; Fri, 31 Mar 2023 04:06:17 +0000 Date: Fri, 31 Mar 2023 05:06:17 +0100 From: Matthew Wilcox To: Luis Chamberlain 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-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 89CEB8000F X-Rspam-User: X-Stat-Signature: 15zwfbk69yiow9m3zfszc19h7nsmhpxu X-HE-Tag: 1680235597-844876 X-HE-Meta: U2FsdGVkX1+BRPuQAG1SOS0gyx2nU6nngVg4xvVpnw2T9CGE1dBP1SXPNU/OTWEi0fAinDG1iDFJZSAPAopryetEK7boVmSCZGicq5WUKgYLgI9gQX1hrgISl/A00d3KApoj+9FXm8UabDX/3wX5j/WcTo9Mbn0adJmWpFN2FinTRG7afiHc8ws22pjIRlheg8/2C+i6GzGLGikaKtpHaSngjtacN4cuptw8diqGOtorPXnmbLKwOz8E9nu7zD4Nn+NsEOXzSKpY/QW4gCNjLhnGpgHuuFsZmpHA/JOb3jLxITx9ooeB+3J7Yy7m80tbgd42DUFA/6Wpl0s737CVLhTWIA5q/OvUHL0KRrr3P6IYTb0UWxKNC75eTj0kJeZEWUauYjFJ+bKLBASHCwffMElSChhr5kcdI4FUUQV/7lmpUU6OuNxAPycZx3H72YtFm8zhj4PXlw7vTrWMqbBHvx8uPpcdwhECU10dMJztw6PUyf9BxZsD0xWXJ4UsyVVgvq1py5x82zC2kTuy9K2EWnIT4qo+G2eX4sfPZBfCc1VL0hbXTt4DrOcHFZuWrYevE6RonBVHpLwaP41pUO5wPowTXrkZawPQ7kQTO90RSz/BPjtxaV4XVW14TL+eYTn0AH8+Y6x7E/WYdsoMEPCXs7kF0z7k1LUHFU0iir1nIB77Rf6htOE8AX6X9p/Ur08WI3Vcaev4YkI28O+jdKQE4fw/qCTs66xYq6DsKpCS9QViJwlgK1NiptZNn6xTw7q+MLuopWsVOMQA1mhet8n251lzkFVih+vYRmeTCO8j265rN9gNO06Z1UGo+6NIrQbkfght07BensgGF54iJ+a5q6Bw5xL+wGGzdWq8kHzQaFjQjwplODEBTS7BTiGarfadHS0bXUKSIK+1Q7hUHfFFy9LLv9GEiuSbt/weCFs5W7SL6888dCllylIrBUgvB11WGeLy+/oWFnSefVVPilJ KwbjgRUj A3Yv/W8lerFEh4Bi7olfjPSoztR9RRMZAaD7vD4uVUPg91ExU/Nkd0wtWhcsiqYVhihVYYpL2M7qNfnqDJl75TbQzWWEGRUalj8SiNsy0R6Q+UR/VDRArBFFAM1uxCQg8eP4IlxNKprbHD5HRndt/lnlFHgYaeQObX02h 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 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.