Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp1312494rwl; Fri, 7 Apr 2023 13:38:09 -0700 (PDT) X-Google-Smtp-Source: AKy350bNz1fYwcGbBwWdCQHnDBBHCRZ7cPI2Ia9mNW54lq+8C0KD4B/x19HQxsH+sFOL7RW1Wt4s X-Received: by 2002:a17:902:e889:b0:19a:a815:2858 with SMTP id w9-20020a170902e88900b0019aa8152858mr4700296plg.51.1680899888704; Fri, 07 Apr 2023 13:38:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680899888; cv=none; d=google.com; s=arc-20160816; b=hc1qoRIndMHcayjOlP4XQp8ih2J2GKdddy5mWklH3m9cT2PhhUH1qaTWXd85fRvVb7 2bYaoKeiKfarTSMz1JgTy8myBQRkyCA/u94/R72K840QWDDiPVJFt1fLIXOCsvOYj9Dq RQCYfsaWJ9gWqOiNvgLJOGBk+Q+rRrXkPDWP5ex0bS3ls06X0PyErCLFvUsuhFbDMyjn E+T/OlhkT62Emcq2iHgJCibqI/C45fO9YRpNS4L0hM9to1VhDSSesybmc6G8KgT2sZ6H cr9JD989exOBVNDmGMT5UGCHYuLHu43vBvco9Ikz6bCq5l34nHAQqHTYfk/QenjdnPWz bGmw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=5XaRDW3OetA625hdcSwN0p/tnpqaSBDliFuySM4XEd8=; b=iqXcPLg6j0sBTcmRHEe38+6ZhyL1lOmEtELVwIYiATXaL79f+7AK8kyHXld8NTQtpe SzQa4j+1PSVonLvkzGb7VhzKf0S1HG3LOhyL5vyOWpi9OOULgKavVR2pViMgm+uo+cBd sjTQcu+NfOokINhqnjxnONTv2P5MxWHb7YG3/W74u+Mdv/aBJ9/s5pCg4q2B845C60RZ kDKafYPZUY19scalxh1zzgNcWaMKXs4LOSFOMcMW+t+hEtgJItBsUXizWDUNaT4dQpN7 2F8Qcmgq4uOih5Gd1cZwM+7iJkml2/HRGXJZrMMsZFlKPSul7HNYJJsLJuE5bweJXIrp zS2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=eqb9e1JT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 206-20020a6302d7000000b00513f1464b0esi4077253pgc.618.2023.04.07.13.37.57; Fri, 07 Apr 2023 13:38:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=eqb9e1JT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229843AbjDGUh1 (ORCPT + 99 others); Fri, 7 Apr 2023 16:37:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37216 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229822AbjDGUhZ (ORCPT ); Fri, 7 Apr 2023 16:37:25 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6D10CCA08; Fri, 7 Apr 2023 13:36:49 -0700 (PDT) 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=5XaRDW3OetA625hdcSwN0p/tnpqaSBDliFuySM4XEd8=; b=eqb9e1JTvWzk3hxUjexfZZJCkP gffH1elQTuqL4yXVNnbJRrvwo6WPKTIqffiOz2+o1VXx8TE5/D4WmjNMPr4Ac8M4nJh/jXGWaYaOl ZK7+2PafVo0toBktdP3YUQ5o+XBmwmbQmGQfkzqiaogbhMYLJpt+aRYSfKfc+oF27G5KfkP+8D5S0 luculWVhA2WYxBLLVA1YiHa5ZjTYv/nQaM9rDs502ddXfxA3OFwDOEK2EZ9c6DOh29pnyBPiRi2OR 7dmXbbU+x35WgDNqNAfrC8oLQ29IIfMbAbfWSKxVCaji8jD45gXjrzPe4t5DVTXjivy3iw0Zkval0 e08s/Cjw==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1pksow-001Bg4-Fv; Fri, 07 Apr 2023 20:36:30 +0000 Date: Fri, 7 Apr 2023 21:36:30 +0100 From: Matthew Wilcox To: Luis Chamberlain Cc: david@redhat.com, patches@lists.linux.dev, linux-modules@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, pmladek@suse.com, petr.pavlu@suse.com, prarit@redhat.com, torvalds@linux-foundation.org, gregkh@linuxfoundation.org, rafael@kernel.org, christophe.leroy@csgroup.eu, tglx@linutronix.de, peterz@infradead.org, song@kernel.org, rppt@kernel.org, dave@stgolabs.net, vbabka@suse.cz, mhocko@suse.com, dave.hansen@linux.intel.com, colin.i.king@gmail.com, jim.cromie@gmail.com, catalin.marinas@arm.com, jbaron@akamai.com, rick.p.edgecombe@intel.com Subject: Re: [PATCH v2 1/2] Change DEFINE_SEMAPHORE() to take a number argument Message-ID: References: <20230405203505.1343562-1-mcgrof@kernel.org> <20230405203505.1343562-2-mcgrof@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230405203505.1343562-2-mcgrof@kernel.org> X-Spam-Status: No, score=-2.5 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Apr 05, 2023 at 01:35:04PM -0700, Luis Chamberlain wrote: > diff --git a/include/linux/semaphore.h b/include/linux/semaphore.h > index 6694d0019a68..2d6aa3fd7861 100644 > --- a/include/linux/semaphore.h > +++ b/include/linux/semaphore.h > @@ -25,8 +25,15 @@ struct semaphore { > .wait_list = LIST_HEAD_INIT((name).wait_list), \ > } > > -#define DEFINE_SEMAPHORE(name) \ > - struct semaphore name = __SEMAPHORE_INITIALIZER(name, 1) > +/* > + * There is a big difference between a binary semaphore and a mutex. > + * You cannot call mutex_unlock() from IRQ context because it takes an > + * internal mutex spin_lock in a non-IRQ-safe manner. Both try_lock() > + * and unlock() can be called from IRQ context. A mutex must also be > + * released in the same context that locked it. > + */ I think this confuses cause and effect. How about this: /* * Binary semaphores and mutexes differ in that mutexes have an owner * so they cannot be used from interrupt context and cannot be passed * from one thread to another. down_trylock() and up() can be called * from interrupt context. */ Or this: /* * Unlike mutexes, binary semaphores do not have an owner, so up() can * be called in a different thread from the one which called down(). * It is also safe to call down_trylock() and up() from interrupt * context. */ I'd like to mention completions as an alternative to semaphores, but can't figure out a nice way to fit that in.