Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp7606415rdb; Thu, 4 Jan 2024 01:39:48 -0800 (PST) X-Google-Smtp-Source: AGHT+IGkAUQgocxYgOWvPNGzLozu56y/FKeWwdb0h1J5RinW6Ehh5s6cR+CLz6DSOcPoTT8/7Ugk X-Received: by 2002:a9d:74c6:0:b0:6dc:128:f269 with SMTP id a6-20020a9d74c6000000b006dc0128f269mr318594otl.53.1704361187832; Thu, 04 Jan 2024 01:39:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704361187; cv=none; d=google.com; s=arc-20160816; b=IU2C/d/eezSnvmgNi/05YCDoQozeYazj9LilrlUNuosRQ/1Ajg+N1UMMMVlS3ZRCB+ w74DTHlvZIbwhuY+qfW1uXhWQh/C9N7D/FKMvI8vW/z/xw0OpM2KA5Nwh8Qlt3KO2F5n pd3k/H3EQ0o2i7axovxBgMYKH0CKtD3aPqKALDOBWTkFsJRtz+9F5Qn5J51E6xI4fJYu Hx4MmySaDAYTXU3gczMi2biI5I//f+qE6neUvdURMYFM3r4UhMkMGjkKCZAf+AEIQgec GwnqReZwiPsvhrkMO7ftnv6Sf6HFTfeVyLaTpAocgrJoJnN0pdi4+EV047Dc9+j3mwks i9lQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=61KUe9jqsXYQoO1QYQkTPTk8aeh1CA04cUXPGRuI+s4=; fh=kmduAntvCxYKWJxf0o5GnU6TlPpo49/gb3O/sJ4FX9Y=; b=KNLWWZJcXSyxjHgbh2qdTosFXYPNylfUQC8IkO7Om0hhuW2ZWAt5NWzNPgajqDg8Gg pj6k5LD9opFWhSho1uujMu6R8Oli2vRyRQ5fM/nB6BEntTC0eGf+i1YEw9uOEVw9r+Dk EAUFSTUlkRpnPpqiTToswcOxm5F4rMNBhHn/NTCdDDWouxA5SAxH7XM842bw+vobjWGB OuELlZSq4Ho7QFzdtGpliLSfz3Oh+IYpgaBkev74zsF7a6wAQ4R+Aj0vJeSFN3y6Gg8M RNBmNb8ay/RqXGTv4FbRMhhp6HHp8xIkZhgazBvmaVYF3MWDVgcoEJSwB63QQcwmtpVJ uHtw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bgdev-pl.20230601.gappssmtp.com header.s=20230601 header.b=aSOsN92H; spf=pass (google.com: domain of linux-kernel+bounces-16454-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-16454-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id u14-20020a63234e000000b0059f0cebd04csi4011265pgm.722.2024.01.04.01.39.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jan 2024 01:39:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-16454-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@bgdev-pl.20230601.gappssmtp.com header.s=20230601 header.b=aSOsN92H; spf=pass (google.com: domain of linux-kernel+bounces-16454-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-16454-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 78905285D4C for ; Thu, 4 Jan 2024 09:39:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E0F14208C5; Thu, 4 Jan 2024 09:39:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b="aSOsN92H" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-ua1-f45.google.com (mail-ua1-f45.google.com [209.85.222.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 92719208C0 for ; Thu, 4 Jan 2024 09:39:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bgdev.pl Received: by mail-ua1-f45.google.com with SMTP id a1e0cc1a2514c-7cc7d0cc419so114813241.2 for ; Thu, 04 Jan 2024 01:39:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1704361178; x=1704965978; 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=61KUe9jqsXYQoO1QYQkTPTk8aeh1CA04cUXPGRuI+s4=; b=aSOsN92HHr/ys1+v+LlpsnalHLS9rchbo3C/zFi+gLSvBo5CjQCcM2enJDd2/GLzkE BCSgWxKeSoSWilSa2cz010MOrD6N9QGew9X6UWFw71yppwI3tL3Ur7BI9TIk8jld4l88 v93JkJkSLs1+7RNBaC5wnAZAHWuF7llm3P0c+kIPMgZo1Az3PEU0G4pDOm8TAKQd0L3T 2y09fFJVJEl45EinAVL5VkdVj0y3ahcq81rc7pNbMuon5gNc42h+smUVKfhtNmjrdZmb Mx1gLRK55mf8ylr1xN/Ex9xgrKQ1kQ7wisoU0yO5PXu4nf3U8FhJSqRUW1Wy6QR8/1Bj 0V8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704361178; x=1704965978; 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=61KUe9jqsXYQoO1QYQkTPTk8aeh1CA04cUXPGRuI+s4=; b=fqyCUqpLdkowJ9F6sr5+q9ka/qEeu9D7a0uDwKTQAPQ7m/FC6q3RXLToLeC6jAG956 GiW4Y0ZRtqryuTtdfKGxDX82mrntqavDTAC2lB6FKrEwMe6fMCjyBrwAFHv72JFAYHeW Ew4PLN7azNv3+BY8uC1NJmGQLImhNWYcZXP5qqXS2HlheeMC+nLTC1Ef4v2vW4AS8c2a lRTmosvRJSB+8Ch562fEpnM5Mp6uVvXY6A09LKL5faO0EWrVAifIOSbkqOD8rTUadWPL TPHjGKqxS0CyR0BGFk7w5VS8c3uc7falbRsgebdZKK5aqZFE38Jm8GctYjDQelKzs2+0 QdvQ== X-Gm-Message-State: AOJu0Ywn5t6v+6hb+7MP05etmh6AMsWQ/q33ob3PCLMKUTbBHELXKGqN 32z1WS54iwqhJBQ2Jy5kHocMXnGylwpKIfzX2z6gff7yRnTYlhp7KWEo+42f X-Received: by 2002:a05:6102:14a7:b0:466:f402:3db7 with SMTP id d39-20020a05610214a700b00466f4023db7mr227210vsv.35.1704361178510; Thu, 04 Jan 2024 01:39:38 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240102155949.73434-1-brgl@bgdev.pl> In-Reply-To: <20240102155949.73434-1-brgl@bgdev.pl> From: Bartosz Golaszewski Date: Thu, 4 Jan 2024 10:39:27 +0100 Message-ID: Subject: Re: [PATCH v2 0/3] gpiolib: use a read-write semaphore to protect the GPIO device list To: Linus Walleij Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Tue, Jan 2, 2024 at 4:59=E2=80=AFPM Bartosz Golaszewski = wrote: > > From: Bartosz Golaszewski > > I'm still figuring out how to keep GPIO descriptors coherent while > (mostly) lockless. In the meantime, I found a potential race-condition > during GPIO descriptor lookup and also figured that the correct way to > protect the GPIO device list is actually a read-write semaphore as we're > not modifying the list very often and readers should be able to iterate > over it concurrently. > > The first patch in this series is new in v2. I realized that we must not > wait until .release() to remove the GPIO device from the list as this is > why pinning down the GPIO device list during lookup would never work - > we always could end up re-taking a reference to an object that was being > released if it got looked up between when the last reference is dropped > and the object is finally removed from the device list. > > v1 -> v2: > - add patch 1/3 to fix a release timing issue > > Bartosz Golaszewski (3): > gpiolib: remove the GPIO device from the list when it's unregistered > gpiolib: replace the GPIO device mutex with a read-write semaphore > gpiolib: pin GPIO devices in place during descriptor lookup > > drivers/gpio/gpiolib-sysfs.c | 2 +- > drivers/gpio/gpiolib.c | 62 ++++++++++++++++++++---------------- > drivers/gpio/gpiolib.h | 2 +- > 3 files changed, 36 insertions(+), 30 deletions(-) > > -- > 2.40.1 > Series applied. Bart