Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp3900446rdh; Tue, 28 Nov 2023 06:52:55 -0800 (PST) X-Google-Smtp-Source: AGHT+IFDKjIWOMoZaN0N13vdhs0RgJD/c08Uz7h4rzzRiIdQ4yI/d6n/KsdUArk5YKv5mwvVlQiP X-Received: by 2002:a17:902:d2cb:b0:1cf:de3e:e4c9 with SMTP id n11-20020a170902d2cb00b001cfde3ee4c9mr8400424plc.29.1701183175356; Tue, 28 Nov 2023 06:52:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701183175; cv=none; d=google.com; s=arc-20160816; b=qsAYrnstrstr152+9QaoEXyx1vsZc98lMcoc1InxQ5agzNrNH8Ce02+nRiLrp35WmG mEamAaEdzbR+9BQc/SAUEVLR/37gHiJeIO+EWtns7gUpxHyl4qIxnEtJ+GBs7mbw0GDP Npvtgiv3rr9ndDh8+LUqGE9e2UQTbd02iKszyM8iUubK82R22w+wGEAiJBSzK2jum85s NrI0WreyqFznUQS6X3nH68YPPVQiHndD6k6fFpzJWQk2UPI5xMf3wZRtvOT3WtlkHLAu PDglsqrYfF11kVjgBXRVtFv+GQhLVtPMw8BHMeT+hOlH0/n3A9tUF2kjAlNmkSmVy9BO zmfA== 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=EUFCdjj6KweraZbgFnvcdT6qQJR48sxHc17tLoetRbs=; fh=sv81ABL2sr7c7amww2e8YruQ/5JC/dgEi5QoFH/az/E=; b=TYxQxEZSbD3wG5iFLxuy4uLEQ5Yc1U2QVqToihu6WJVxmph8KqRnJoq1wTOA8HTb87 cHeu2tiWrvuByf6lPg0jPne+8G9yHm8jCMUQMf+dRBSU8yCbSITsTanlv9oX8RZBeUAx J+tUWnXr8NRn4pd3mlvIWxs0jdvW0F0s2N9JDFqq1hSRqN/S/0WNc2YLkA5XExmL4sGK Y8+B5rgryukZtc/RwWJEX0yzmMNUuc3u0ex86FHW7h46xDyTLOHzMhLqghJICXLY7zrf yvtfvxRfdmrQqoe1Y2JMn3g3irTrtUFDYvPjUpP6eNUPwr5IUiBNk670RLgfhlC7cnBw Vtdw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bgdev-pl.20230601.gappssmtp.com header.s=20230601 header.b=Ipu1x7sa; 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 Return-Path: Received: from morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id n17-20020a170902e55100b001cfee3a03c1si2361866plf.470.2023.11.28.06.52.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Nov 2023 06:52:55 -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=@bgdev-pl.20230601.gappssmtp.com header.s=20230601 header.b=Ipu1x7sa; 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 Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 555FB81DAADC; Tue, 28 Nov 2023 06:52:51 -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 S1346412AbjK1OwW (ORCPT + 99 others); Tue, 28 Nov 2023 09:52:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35520 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346390AbjK1OwM (ORCPT ); Tue, 28 Nov 2023 09:52:12 -0500 Received: from mail-vk1-xa30.google.com (mail-vk1-xa30.google.com [IPv6:2607:f8b0:4864:20::a30]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EEA9C1707 for ; Tue, 28 Nov 2023 06:52:17 -0800 (PST) Received: by mail-vk1-xa30.google.com with SMTP id 71dfb90a1353d-4ac1988ca66so3033655e0c.0 for ; Tue, 28 Nov 2023 06:52:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1701183137; x=1701787937; 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=EUFCdjj6KweraZbgFnvcdT6qQJR48sxHc17tLoetRbs=; b=Ipu1x7sa1LVGcPnrZhioSIe0f7XKV5BzbJNuadbQ7MTnRj+X/2jzk9t7qk7sSnKjZx pbydwfW61TqZ3oPr3kOe0Q09Pzr9uX6JevrhntxrcxcqcA/38n1RREM0UcpkBesV4K8S krzXTAayILIRxqxLv7xA4egfNcYGf0skEt47jzP0H+TAcV/aNHJ8kJiOelfrDo84311W g1xcwqnLN8hV0dOlBY5MGZJhhSb+9ucrChgE9n4DL+L9vzPAz20zjprECKXJ8oCsI8AJ wm2Ib1CZ5pEVigsm9zm+hHo699PuI2/IacQitFjIaH7288bt9SllW+vcjy1qGIO4nlm5 Z9KA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701183137; x=1701787937; 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=EUFCdjj6KweraZbgFnvcdT6qQJR48sxHc17tLoetRbs=; b=oSxIp5Ftmo+rWi8o0TWTSV6ILRHf61DanXBwRWJhLVZbbBzNRehV1xDCA8TDC5JbWV W4HsGLy94Fc4fVi7wirSSEw+a3dPq/TgqZPNZW7PeswclWS5P5krb0Mj5vCiX/wQlYnJ btXDNW8WoNik3LY3xqWy+M+odGCjoA2EFN3VTV06T7ondfAiDqUumDwOT0y0L1SHqVpT YMfxq7ZDDwfqB/dhboSVOUcgkTbRSAiCVo1ZK0BJrGHF654l8mueEK1+ym5lyvJwHWYn wch9++eHPeTyzuVKAJNf6aTTITZU/uvrOBbQII15jB2Z+H8NrhJDpTd+eACpuy7XVsMZ YTXw== X-Gm-Message-State: AOJu0YyuKiZrJBiQDhlA90QCShDnc8xZbhSRN4rZbJOVHASNhrGUo1jZ wv3YkRvkfGiQjJUW/xNJAfQZ1eTlmiOOhX2qspDyOpKIgwuoEFKl X-Received: by 2002:a1f:c582:0:b0:4ab:da7a:c573 with SMTP id v124-20020a1fc582000000b004abda7ac573mr10394319vkf.8.1701183136967; Tue, 28 Nov 2023 06:52:16 -0800 (PST) MIME-Version: 1.0 References: <20231127193716.63143-1-brgl@bgdev.pl> <20231127193716.63143-2-brgl@bgdev.pl> In-Reply-To: From: Bartosz Golaszewski Date: Tue, 28 Nov 2023 15:52:05 +0100 Message-ID: Subject: Re: [PATCH 2/2] gpio: use a mutex to protect the list of GPIO devices To: Linus Walleij Cc: Andy Shevchenko , Kent Gibson , linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, 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]); Tue, 28 Nov 2023 06:52:51 -0800 (PST) On Tue, Nov 28, 2023 at 3:21=E2=80=AFPM Linus Walleij wrote: > > On Mon, Nov 27, 2023 at 8:37=E2=80=AFPM Bartosz Golaszewski wrote: > > > From: Bartosz Golaszewski > > > > The global list of GPIO devices is never modified or accessed from > > atomic context so it's fine to protect it using a mutex. Add a new > > global lock dedicated to the gpio_devices list and use it whenever > > accessing or modifying it. > > > > While at it: fold the sysfs registering of existing devices into > > gpiolib.c and make gpio_devices static within its compilation unit. > > > > Signed-off-by: Bartosz Golaszewski > > Nice! I might have found some snag: > > gpio_device_find() still does guard(spinlock_irqsave)(&gpio_lock); > shouldn't that be switched to the mutex? > Good catch! > On top of this I can update my patch to the delete the comment > for gpio_lock to just rename that thing to gpio_descriptor_lock > and document it as such. > No need, this will soon go away anyway. See below. > But when I think about it: gpio[_decriptor]_lock can now (after this > patch) be moved into struct gpio_chip as it is really just protecting > the descriptors on the same chip from simultaneous modification, > especially desc->flags. This is a BIG WIN because it makes it a local > lock not a global one, do you wanna try it or should I? (On top of > these two patches, then.) > I will have the series making locking in GPIOLIB more fine-grained ready tomorrow or on Thursday. It will have separate locks for each descriptor. We will use spinlock or mutex per descriptor depending on the value of gc->can_sleep. I think it should work fine as a sleeping chip can always use a mutex and a non-sleeping one cannot have sleeping callbacks (correct me if I'm wrong). We don't need to lock the GPIO device or chip separately - the descriptor structs will stay alive as long as there's a live reference to the GPIO device. GPIO device will have an SRCU cookie for protecting API calls against removal of the chip. To summarize: one mutex for the GPIO device list, one lock per GPIO descriptor and SRCU protection of the GPIO device's chip. Does it make sense? Bart > Yours, > Linus Walleij