From nobody Tue Nov 26 17:30:11 2024 Received: from mail-wm1-f50.google.com (mail-wm1-f50.google.com [209.85.128.50]) (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 483AD1D432D for ; Thu, 17 Oct 2024 08:14:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729152876; cv=none; b=OUdOM/mVz9fzc3TQCx/i996QQSlyKd5jGNCsYk6cS5XpzGhWBjCm6rgHbRWlyx67SD5dj1GQZbgQoCuE1/kv6kmP0FBolWrQuFGm6Pa4IT8uTwRx4a0jMMYhYFR3+phWf5CyLeF161qaEcRBkQVmn64gMbfLUnVPvj/nr43iNc0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729152876; c=relaxed/simple; bh=ShKnfVnA13yZAURxSbfkTfcYBLmCdqbi8FWGA7M737A=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=gaVDvXbSt0BbW+r3RvHY+BfoRgoTykVELijawl8a4PjpBEX5MBpbmbUleWenHhEwU8vriNluVAdMZBvLS1M8pDg6fq3MTM8BO+XgYiCeMg203RPm+ChUtgbOimWBhqROQsQh8uwGbVujj1blm1OFztKZGDNC6YbTpuOwDM7ByKU= 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=GTwMu2rx; arc=none smtp.client-ip=209.85.128.50 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="GTwMu2rx" Received: by mail-wm1-f50.google.com with SMTP id 5b1f17b1804b1-42f6bec84b5so7353125e9.1 for ; Thu, 17 Oct 2024 01:14:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1729152869; x=1729757669; 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=GTwMu2rxDD2gO/6jJjiZ8eoFRQ5zG6r0m/jb67a7KIKYrZek/qE00hT/k59q5nxUze MoT1Ft/vNeEkadbafCeva+e5fnSC5qmIDEnvz9FJlAAAe8vSETSOVDqhXCIyAVb3pqRG HQFA9LzIrIJ8KCBARZnAu9vlxtwkDsAQUbrGjUl+aouB+O/3ZxEqTzSiaq10bd/Pw8Fw 7ecHNG9WghLHHwvEpreCJRDiO6OBCNnIQxGsTG6fXEjITbQPL78nECY6rVM5w02sT+kk OkxaeJs2Sf/cA4N4MDCDJUHO9ca5SDr5idc3q+Cd3jVx2O3109UywMKjFndMkBH9Ut9F RCWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729152869; x=1729757669; 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=oi8/z/JwAhqLskN2Lp/F5tuhgZJTr3MO+9tLeH1VGwprU3BCUhI8Q9rs2Gxz9njn1l s2V5US/jqtAM83lfwvAroUw+aS6OtZirXiw/G1CYkDVZcQ9VTp8MLAZW5BcKfTwnMP7d GGkluASCt9riBldac9/t9zj3ytLSmNVrEboWa5lZ/FB+37yMEi4FF/WrLsNkr4l7BYE0 izu74hPlpcB8MhCvz77Hc+FKf8q7n6MSN70+nVUjA9yc49V48HckEVybqFA4J6pYpQJc tGQVMkHtWFO4MoGjwqLodbWB0dBwrPJuXwH6HGrqqKAygzhtgxMwSBw4mcVnr2BzNaJe 3GbQ== X-Forwarded-Encrypted: i=1; AJvYcCUSonkCPydd3j7TqX8WvUHaz7MmUUwqJ9D31livsyr53HXa0TRU4JBqd6QJ0jecZkM0nnqTXuALxqZVeX8=@vger.kernel.org X-Gm-Message-State: AOJu0Yy5jTuYBtE4gMn5yJtHKKKxatSUOFB5kEmdX9orwptJQJcK8clY zmPFDqcHbxkpKcJRwhOTEDMp7tDz1D8zMiSzpEfoKi0SIDECYYnfzFitK4I+t74= X-Google-Smtp-Source: AGHT+IGMTAgLIra3AwC4js0TpQefOyARSjB66JJbjktTXIzzaEulPCK8EZEQPJ+r+DlSkK0sB46KMg== X-Received: by 2002:a05:600c:19c6:b0:430:54a4:5ad7 with SMTP id 5b1f17b1804b1-4314a295480mr58184505e9.1.1729152869469; Thu, 17 Oct 2024 01:14:29 -0700 (PDT) Received: from [127.0.1.1] ([2a01:cb1d:dc:7e00:3831:fc61:16eb:d0df]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43158c61ae2sm17855695e9.46.2024.10.17.01.14.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Oct 2024 01:14:28 -0700 (PDT) From: Bartosz Golaszewski Date: Thu, 17 Oct 2024 10:14:13 +0200 Subject: [PATCH v4 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: <20241017-gpio-notify-in-kernel-events-v4-5-64bc05f3be0c@linaro.org> References: <20241017-gpio-notify-in-kernel-events-v4-0-64bc05f3be0c@linaro.org> In-Reply-To: <20241017-gpio-notify-in-kernel-events-v4-0-64bc05f3be0c@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/ZANAwAKARGnLqAUcddyAcsmYgBnEMddVOmN85FNOqbwEfYAB3HukIVwmEvIMEHLF B9/yJf8WlyJAjMEAAEKAB0WIQQWnetsC8PEYBPSx58Rpy6gFHHXcgUCZxDHXQAKCRARpy6gFHHX crDmEAC4/89OesDABkpdoqYlHW2PfH2sn5oG7KRFR6qFTp3t+zpvYXzRCZ3KSOg+WxuFTkMCjdE WxSJ1BiaA8TlB+kGKCP37xD4HuzMrtd52hp17AkFYV/4giuJAwrdeSrB44Lvqj1oav6Wk7RRA27 LFQzd0vnWSPytvCq3awxuUriJ9eMWSz9XWfzGplHlT3kAokxiRZnd1rTEJegDPMcLzdgkstZ0Dx ORlmkBmK62iKsW31zkGdBhsVJ0+tMJkYv6ince22DmpKULMe8llCRWgFH8Eq44rR727oST7rA4O nGEx08FDtwXGc4C0LcBd7ned7i8ei6CQ+8TfFArV5UDYpgWpFYg8my5ezJYWkkvo15X+Vw//PO8 K+wCLDq7MdqBfLOpxDi753gpXrcG0wFmg1xJMbfoBxi+fBPZvJR9dywonDOJ0p5C4iqEdSZFa0N 2FQtTqvW/xbVSLXxOoWn4wcCrrJ2EcHot0jb23igDjtgAS/i0YFYdPrdNUTLyhc65Etqv+dRxU1 TM3mMlYGLS2zYslBhHXrcfCY5ipKGc0PsnZaS5N1i0/XMp48lQI+ea2khElxFX2EJJEVH9WIHQB Q/Kv8Qnx7reGIbHWSqXIMApnRG/c40yMcrb7a0iE4F5IA2s6vqz6V+rhwDD5PgY6BNgjOj0fs6M TXbNga2uxdaIVrw== 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