From nobody Tue Nov 26 14:38:04 2024 Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) (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 10B251917E7 for ; Fri, 18 Oct 2024 09:10:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729242630; cv=none; b=LjthrxatE0CgqtYY0KnWEy9q4QTlZUyq/TjorPvNVzfs37O7zXalqITHt+z9JqO0RNVKsHCJdwLrGGu6KGdRXFiHdu3zP3nYTbyy9vCy2buOYL1cW1IhLkr7yDzuZCC2yz6m3SUq3PO+iTeUbxQKt6J61qawd9EewFMBDon090o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729242630; c=relaxed/simple; bh=ShKnfVnA13yZAURxSbfkTfcYBLmCdqbi8FWGA7M737A=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=J9uld7v0xkDr1a87R6kWAA7+X8t5iYiqf/AwaZEEoQX/QNyw5/lkkcIHlvAJERiFhCqknE8ElpgQ052Idyh+9AmGmwnNedRYkOjITa8A4xCSpT2pzPNg7HYqxzYNxZEnfIdowdI9T8x3FrJMPKOLU8SVjldn/YA7dH9bWlzADEs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl; spf=none smtp.mailfrom=bgdev.pl; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b=0OrtOG6Y; arc=none smtp.client-ip=209.85.128.47 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 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="0OrtOG6Y" Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-4314c4cb752so18978495e9.2 for ; Fri, 18 Oct 2024 02:10:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1729242627; x=1729847427; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=U0tIf0jtJWFltu4ODvVnK3F2kIEgN0qMoeq7qRt5Wac=; b=0OrtOG6YydfSWJiPhZYVGmXhQP16KXqVllp5aPSNV8gJxOBCh/r1X+7TNHHJlcy/78 5p3vK1jr2ZDmJH5phMOMMDyu8UzvL6kx8oYLrqzEyMjPohjRHvXMdLtYdA3QbSSWDadZ ifUAHDVQXy8z5Dzs+BtYnF2bkwM70GR3M16rjJd8lWVxwmjoBtfulXMm9ve6QIdhdcgo lhk4fQCrDn22iuYRhdDoy/04FUrzlgPEbNxLpxNpUoQR1YOKhhvN5rS2UluDGXDnPKu7 ImcEsKWBPCjKCoSoDt9/QORN63Z/J1XLi/y2WzxMl1401KEx/5LlNBIJRSevHoeMhuJw OBGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729242627; x=1729847427; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=U0tIf0jtJWFltu4ODvVnK3F2kIEgN0qMoeq7qRt5Wac=; b=Ed6c42mzfDtSGtalozAZ7F4T59pstaq2dqcFsuLkfUCrmm9ehQmm+iZRHMJl1xXxvW acLwIq5+95yxZxghbYAoKtJoWKtNrkcMSochRL/KdMauKhwhWsYpFL2iGGAgTYjLqsuK pqnJqgJKBKUPfjs5C1U8lcUCpbFPcw7yeLJw1RK8FRrwUEFD/m3ohmi5O3RN8LccgHLC VbN3KzVa190ldr9Wy8dEKhyB6JaWPSKkDLf61Ydo4FAqU4od4eoqH5KRGCxb8MPjxxA1 2R6rgXoysVWK+fyRcY4J5d7ylRMP1W6lBrped35Y5eVsPQ3gNPlmwmEmg3TeWN98LFtJ UlrQ== X-Forwarded-Encrypted: i=1; AJvYcCXKcaMsXrrC6dn1tSQpcUr2dLyqGQwazv3j5pl6F2WoghRXFy5F9BezUDg7gUzVmInHFUBAwQTzkyjPUw4=@vger.kernel.org X-Gm-Message-State: AOJu0Yzonzo3FEvda1h+jayzqLavUHqwFUfidukQZnxXD3cnZ6Kf1dti OQqYAy+qzxA9XU7utsK2+7jNWmWmKYjzT28zPXIa5pGo2+kMYAJI2aouNNhtUbo= X-Google-Smtp-Source: AGHT+IGzh7emw0kamIRsyCmcyboccj8tMVEfGoaug2/eeFdI230uT4IxNKyEXz3mEkzh8Ug8d7T5Ug== X-Received: by 2002:a05:600c:35d3:b0:431:5f1c:8359 with SMTP id 5b1f17b1804b1-4316163bc87mr14364015e9.15.1729242627290; Fri, 18 Oct 2024 02:10:27 -0700 (PDT) Received: from [127.0.1.1] ([2a01:cb1d:dc:7e00:45a3:93e:5196:d8ce]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43160dbe76bsm18700455e9.10.2024.10.18.02.10.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Oct 2024 02:10:26 -0700 (PDT) From: Bartosz Golaszewski Date: Fri, 18 Oct 2024 11:10:13 +0200 Subject: [PATCH v5 5/8] gpiolib: add a per-gpio_device line state notification workqueue Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241018-gpio-notify-in-kernel-events-v5-5-c79135e58a1c@linaro.org> References: <20241018-gpio-notify-in-kernel-events-v5-0-c79135e58a1c@linaro.org> In-Reply-To: <20241018-gpio-notify-in-kernel-events-v5-0-c79135e58a1c@linaro.org> To: Linus Walleij , Bartosz Golaszewski , Kent Gibson Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2506; i=bartosz.golaszewski@linaro.org; h=from:subject:message-id; bh=0P2NY394anUazMVeFpGs/9LRMhoWr2qMp3sLio3SuhQ=; b=owEBbQKS/ZANAwAKARGnLqAUcddyAcsmYgBnEiX6qgpb2193BrTFH70zRNYR224K0KltZ2UYm orfLeQF1HqJAjMEAAEKAB0WIQQWnetsC8PEYBPSx58Rpy6gFHHXcgUCZxIl+gAKCRARpy6gFHHX cm1uD/9V/+YzJf5zaldzKgAUqnBq0Kq0Zo1xnpIzc6qJF7vydT8E2DZZrUoEzon3SmCQeH21KS5 0pAFsASGdyT5YjuYDs3ggyzxsU3vPg+uBrQSrk8yNpTuK3TeA6x6ZGDcJDnaafeZnIuLoZABETu yDi922XFAfFsTmRf3sZr0viwEgwbTjrtcuST7J0vk5eavz61PDU0wKxIcNHLsU1FBfpNKPBZdxP pXQK+5N1sZBKEWuk7KAWGkfxvx7AjbBDdMF2UPoYCMUgMLWvz/SIDOdKXKb2+YmDQwvGm2ST3gg 4X0TRHoiU7MhlydTq7GxkJ+fYyede8QFU5qsuBrH4VNV+9Va9/GpJCbkCwrUIYtIKhJoqpJ0xan tCU6qiXUnkv5KYweMozJST3Hk114AmFjXmYU/Rlpkbew6mr52UqTP+eshSUhq8f68d8C02OGuwD adaErvEiFmGGiNbfWThiS4jx+Q3LvR5/pyJoS/ZL6L/B/SU28gbxZ6NcrN2Xlzrtb1Nkk50C4dQ 2qwLbE+LLhOErOluTCcVTPbsnu8xYlNCXIGbECwy5Ooe14e6EFvWYkVoViG2xghKWNso0fl4ymz 5LaatgZxIoQ++Jqv/lN5U91jwjVy/dUobjiOy70WR/HK1CI274BxMTUDjsEnIHgmlir9x8oize3 D2yrXJ3bo4Fvs+A== X-Developer-Key: i=bartosz.golaszewski@linaro.org; a=openpgp; fpr=169DEB6C0BC3C46013D2C79F11A72EA01471D772 From: Bartosz Golaszewski In order to prepare the line state notification mechanism for working in atomic context as well, add a dedicated, high-priority, ordered workqueue to GPIO device which will be used to queue the events fron any context for them to be emitted always in process context. Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpiolib-cdev.c | 6 ++++++ drivers/gpio/gpiolib.h | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/drivers/gpio/gpiolib-cdev.c b/drivers/gpio/gpiolib-cdev.c index 0cba74381687..b242fdb1ad28 100644 --- a/drivers/gpio/gpiolib-cdev.c +++ b/drivers/gpio/gpiolib-cdev.c @@ -2749,6 +2749,11 @@ int gpiolib_cdev_register(struct gpio_device *gdev, = dev_t devt) gdev->chrdev.owner =3D THIS_MODULE; gdev->dev.devt =3D MKDEV(MAJOR(devt), gdev->id); =20 + gdev->line_state_wq =3D alloc_ordered_workqueue(dev_name(&gdev->dev), + WQ_HIGHPRI); + if (!gdev->line_state_wq) + return -ENOMEM; + ret =3D cdev_device_add(&gdev->chrdev, &gdev->dev); if (ret) return ret; @@ -2765,6 +2770,7 @@ int gpiolib_cdev_register(struct gpio_device *gdev, d= ev_t devt) =20 void gpiolib_cdev_unregister(struct gpio_device *gdev) { + destroy_workqueue(gdev->line_state_wq); cdev_device_del(&gdev->chrdev, &gdev->dev); blocking_notifier_call_chain(&gdev->device_notifier, 0, NULL); } diff --git a/drivers/gpio/gpiolib.h b/drivers/gpio/gpiolib.h index 8daba06eb472..8737e1641278 100644 --- a/drivers/gpio/gpiolib.h +++ b/drivers/gpio/gpiolib.h @@ -17,6 +17,7 @@ #include #include #include +#include =20 #define GPIOCHIP_NAME "gpiochip" =20 @@ -44,6 +45,8 @@ * @list: links gpio_device:s together for traversal * @line_state_notifier: used to notify subscribers about lines being * requested, released or reconfigured + * @line_state_wq: used to emit line state events from a separate thread in + * process context * @device_notifier: used to notify character device wait queues about the= GPIO * device being unregistered * @srcu: protects the pointer to the underlying GPIO chip @@ -70,6 +73,7 @@ struct gpio_device { void *data; struct list_head list; struct blocking_notifier_head line_state_notifier; + struct workqueue_struct *line_state_wq; struct blocking_notifier_head device_notifier; struct srcu_struct srcu; =20 --=20 2.43.0