Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp1625609rdb; Thu, 7 Dec 2023 04:47:04 -0800 (PST) X-Google-Smtp-Source: AGHT+IGKQRaWKzQtZw0P/73PsSSNOLNNm3Dvy31I3J24by6CtemwQWZOYUnpd1wriTnw0Y0nPw9E X-Received: by 2002:a05:6358:3422:b0:170:53c2:5c9e with SMTP id h34-20020a056358342200b0017053c25c9emr3343694rwd.7.1701953223847; Thu, 07 Dec 2023 04:47:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701953223; cv=none; d=google.com; s=arc-20160816; b=C/B9Lly/0afBhX4jgbjwVMN6eMcpycl8nPXa6tsKbskWG7Z4JDar9o5rVzufSk3Fv0 YiDA4JNb8Nr7F5wrBotslehBVFSn+tk1chUvx7T0Zn9cZphuuA3CU7tvhvQzGlUePil5 KKIbw1KnMiVHh7vSRSWPROVPoShIg3iLNKTw6C5EM9dG/J8sHp9WZFoGdDC1gIu8gjI+ tLKSk0AfYjJtvOj9OXClwhEKeFxuQMGzwBtg4AHwm8Xdyq4FS7p/RdpncWKhqkR8frNc bfS+3jrjHOmSxmNf77JhFVByZx0+CzBQpyc6ikqFcCu+VI3rY6J0CAgZz7iZ/6MPE1Ce W9Lg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=rHfqqy7VSfkSG99E4cdZjp3eHb2ShoLvFftEF8wWjOQ=; fh=9jXItEXcBm8uL5X+Hf4KMgRStLZRJy0L0pmMTZF1+B4=; b=iBb6gpaMv/0/s6/Boh7Q4tRrwCw91bCLnxDILrvpLFluZC/+kvkhU02HROgW1WmTHj zvBZm6DglyttJg67P7NAezwy+8Pa8vz5BgnFCL4ssQx1P85HxwKLCaCoxhyy2hVgg1+R I2ccyAUqry/2UPphfVRfOIMJzlLjZrKaQgwHMB4Ys+ybKmRI/D4HPzvhxXWI8CNzI3hE DdwQI+zMDaDydbg4heJF1KwOw5KnyaAqfvNmZO9xbOkc6OASQUXt1B0msdQ3fJI2iKl/ CZnGK07in0B/CijhrQg/lH809V5f61rMN6fgyy5gd7Vhg8yWegJjFdSkYC4eP0bUEJIz 1xwA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=WFtHqGGM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id u186-20020a6385c3000000b005644a9be955si1172987pgd.179.2023.12.07.04.47.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Dec 2023 04:47:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=WFtHqGGM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 0D4FD803EBAF; Thu, 7 Dec 2023 04:47:01 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379458AbjLGMqa (ORCPT + 99 others); Thu, 7 Dec 2023 07:46:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38144 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232585AbjLGMqX (ORCPT ); Thu, 7 Dec 2023 07:46:23 -0500 Received: from mail-yb1-xb2b.google.com (mail-yb1-xb2b.google.com [IPv6:2607:f8b0:4864:20::b2b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BE1AA10DA; Thu, 7 Dec 2023 04:46:29 -0800 (PST) Received: by mail-yb1-xb2b.google.com with SMTP id 3f1490d57ef6-db547d3631fso1052690276.1; Thu, 07 Dec 2023 04:46:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701953189; x=1702557989; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=rHfqqy7VSfkSG99E4cdZjp3eHb2ShoLvFftEF8wWjOQ=; b=WFtHqGGMvS/oZ3PlURTFdhwBGyTexUB80CkWy8RhJ2ZEmAjhm53f61RXaxV5wBiPoi k+CzyuZbJIXZ8WdfP6PgENHraJT12NMJcBc9HMXe3thfg2uBeSANqCGpCJ7mFdDVLehT VN2kR96RMREE9ZGwMMvr9KIA/CBElKaW6Fmb/iauPxptQEWrS97c8CYYWWa62VUHqAq/ vLkAuYrNSS0zokite/BYdKOeslJuf03Dea2CtqwiWTt4SZCEapAh/16Y/nOfcE+Enops 2Nr4mbSPbc2wQdrmwL4iac747aUsNU0b4BZQpYrhaxydQz1WGM7YiYGstIgeNI3mQLSG SjrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701953189; x=1702557989; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=rHfqqy7VSfkSG99E4cdZjp3eHb2ShoLvFftEF8wWjOQ=; b=wGe8FK3AA48ajjKkA6pwcQJBAsPlN64HAWpOHWMItoi1fCi4vNNKBoPBUC4tBzuYae SM4Iiift9mURvLlrB3YLFE0O+ZII3mOw+I2zHhpRQPUUjFf2sFVWrng4l/58YAthOrE+ a2NxbaBxDNlXQiJjvnZ+gOrcfgo/F9EFfgu+lgJHqhKyd9gJHo9jZ+6k7EgvpVgo4fZd WViYSmP7cYsiAt/g4RSemucd43OEa9qAxqXNFUTUr7MPY4RjUzR1wXGPFm+0AZSuRoIV jtYkQJGghNkb9vSWY9PFWWWMlRD1AkADzuayHtW/qFNFgi+ObL9Kdg+X9WCu0xKgdmsp acoQ== X-Gm-Message-State: AOJu0YyHSIHW0dnZ/vbiZmjHdfl8ZtasKdnaIRZ0FQfbY6yTEnXefj3W QyKLV1QICNxg0YhLgybw5ASq9EBIxnpDLjxLVqQ= X-Received: by 2002:a25:aa6a:0:b0:db7:dad0:60c1 with SMTP id s97-20020a25aa6a000000b00db7dad060c1mr2364100ybi.78.1701953188938; Thu, 07 Dec 2023 04:46:28 -0800 (PST) MIME-Version: 1.0 References: <20231204180603.470421-1-gnstark@salutedevices.com> <20231204180603.470421-2-gnstark@salutedevices.com> <81798fe5-f89e-482f-b0d0-674ccbfc3666@redhat.com> <29584eb6-fa10-4ce0-9fa3-0c409a582445@salutedevices.com> <17a9fede-30e8-4cd5-ae02-fe34e11f5c20@csgroup.eu> <2a68534b-9e64-4d6e-8a49-eeab0889841b@salutedevices.com> <3275dec3-fd19-4aa1-8eba-441fd64cc185@csgroup.eu> In-Reply-To: <3275dec3-fd19-4aa1-8eba-441fd64cc185@csgroup.eu> From: Andy Shevchenko Date: Thu, 7 Dec 2023 14:45:52 +0200 Message-ID: Subject: Re: [PATCH v2 01/10] devm-helpers: introduce devm_mutex_init To: Christophe Leroy Cc: George Stark , Hans de Goede , "pavel@ucw.cz" , "lee@kernel.org" , "vadimp@nvidia.com" , "mpe@ellerman.id.au" , "npiggin@gmail.com" , "mazziesaccount@gmail.com" , "jic23@kernel.org" , "peterz@infradead.org" , Waiman Long , "mingo@redhat.com" , "will@kernel.org" , "boqun.feng@gmail.com" , "linux-leds@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "linuxppc-dev@lists.ozlabs.org" , "kernel@salutedevices.com" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Thu, 07 Dec 2023 04:47:01 -0800 (PST) On Thu, Dec 7, 2023 at 2:31=E2=80=AFPM Christophe Leroy wrote: > Le 07/12/2023 =C3=A0 12:59, Andy Shevchenko a =C3=A9crit : > > On Thu, Dec 7, 2023 at 1:23=E2=80=AFAM George Stark wrote: > >> On 12/7/23 01:37, Christophe Leroy wrote: > >>> Le 06/12/2023 =C3=A0 23:14, Christophe Leroy a =C3=A9crit : > >>>> Le 06/12/2023 =C3=A0 19:58, George Stark a =C3=A9crit : > >>>>> On 12/6/23 18:01, Hans de Goede wrote: > >>>>>> On 12/4/23 19:05, George Stark wrote: ... > >>>>>> mutex_destroy() only actually does anything if CONFIG_DEBUG_MUTEXE= S > >>>>>> is set, otherwise it is an empty inline-stub. > >>>>>> > >>>>>> Adding a devres resource to the device just to call an empty inlin= e > >>>>>> stub which is a no-op seems like a waste of resources. IMHO it > >>>>>> would be better to change this to: > >>>>>> > >>>>>> static inline int devm_mutex_init(struct device *dev, struct mutex > >>>>>> *lock) > >>>>>> { > >>>>>> mutex_init(lock); > >>>>>> #ifdef CONFIG_DEBUG_MUTEXES > >>>>>> return devm_add_action_or_reset(dev, devm_mutex_release, l= ock); ^^^^ (1) > >>>>>> #else > >>>>>> return 0; > >>>>>> #endif > >>>>>> } > >>>>>> > >>>>>> To avoid the unnecessary devres allocation when > >>>>>> CONFIG_DEBUG_MUTEXES is not set. > >>>>> > >>>>> Honestly saying I don't like unnecessary devres allocation either b= ut > >>>>> the proposed approach has its own price: > >>>>> > >>>>> 1) we'll have more than one place with branching if mutex_destroy i= s > >>>>> empty or not using indirect condition. If suddenly mutex_destroy i= s > >>>>> extended for non-debug code (in upstream branch or e.g. by someone = for > >>>>> local debug) than there'll be a problem. > >>>>> > >>>>> 2) If mutex_destroy is empty or not depends on CONFIG_PREEMPT_RT op= tion > >>>>> too. When CONFIG_PREEMPT_RT is on mutex_destroy is always empty. > >>>>> > >>>>> As I see it only the mutex interface (mutex.h) has to say definitel= y if > >>>>> mutex_destroy must be called. Probably we could add some define to > >>>>> include/linux/mutex.h,like IS_MUTEX_DESTROY_REQUIRED and declare it= near > >>>>> mutex_destroy definition itself. > >>>>> > >>>>> I tried to put devm_mutex_init itself in mutex.h and it could've he= lped > >>>>> too but it's not the place for devm API. > >>>>> > >>>> > >>>> What do you mean by "it's not the place for devm API" ? > >>>> > >>>> If you do a 'grep devm_ include/linux/' you'll find devm_ functions = in > >>>> almost 100 .h files. Why wouldn't mutex.h be the place for > >>>> devm_mutex_init() ? > >> mutex.h's maintainers believe so. > >> > >> https://lore.kernel.org/lkml/070c174c-057a-46de-ae8e-836e9e20eceb@salu= tedevices.com/T/#mb42e1d7760816b0cedd3130e08f29690496b5ac2 > >>> > >>> Looking at it closer, I have the feeling that you want to do similar = to > >>> devm_gpio_request() in linux/gpio.h : > >>> > >>> In linux/mutex.h, add a prototype for devm_mutex_init() when > >>> CONFIG_DEBUG_MUTEXES is defined and an empty static inline otherwise. > >>> Then define devm_mutex_init() in kernel/locking/mutex-debug.c > >> > >> Yes, this would be almost perfect decision. BTW just as in linux/gpio.= h > >> we wouldn't have to include whole "linux/device.h" into mutex.h, only > >> add forward declaration of struct device; > >> > >>> Wouldn't that work ? > > > > No. It will require inclusion of device.h (which is a twisted hell > > from the header perspective) into mutex.h. Completely unappreciated > > move. > > I see no reason for including device.h, I think a forward declaration of > struct device would be enough, as done in linux/gpio.h > > Am I missing something ? Yes, see (1) above. If you want to have it in the header, you must provide an API, which is located in device.h. The idea about mutex-debug.c is interesting, but the file naming and the devm_*() API for _initing_ the mutex seems confusing. --=20 With Best Regards, Andy Shevchenko