Received: by 2002:a05:7412:8d06:b0:f9:332d:97f1 with SMTP id bj6csp31956rdb; Mon, 18 Dec 2023 08:09:40 -0800 (PST) X-Google-Smtp-Source: AGHT+IGU3kDwX+T9NKw78W7Q6p8XIZR8ASL/P5Qm8VMm/Jj6p/j7fDK8F2AlAyyDuidPEiZd/6Ux X-Received: by 2002:a05:6a21:9985:b0:190:2ae6:c685 with SMTP id ve5-20020a056a21998500b001902ae6c685mr21045283pzb.42.1702915779933; Mon, 18 Dec 2023 08:09:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702915779; cv=none; d=google.com; s=arc-20160816; b=Gw5RNANYQOKd5qO4Xx/CNUdvWNfyS2/QOVddGcqeomiasie89bXcNooUXJJJPriR3w wtlgMhimgXKEXzhodYFajZHZIwHJ4QxfSs7OKBJV4R74UBAZLvE365T3mEIhE9tXBpUa FA8sta32YDiCyf54oCxRQ9d9AAD43Xb1niWX81ccmihzWrZaF0EiUzYKZhoSt2Tcvcjl J4oNpniltAsYw+g5T49TG865bi/M/O+kIagHB6ADjI0lbMujKKC18ZdscYZKh/Adlhtu EWI+uzRXcNBeZgU9EMgsw8LTcxQN4B5AbirF36hGFpY4/4Lib/AiW9xL7ne86mSP4M3c JFSA== 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=yGsftRUwsP12LQ30FBWYDs/WH5EY9TUOi7H6csPAxGw=; fh=erCAZt8TqRv2/z+YQ9HTYE4a5f7Y9g1zasafOXpHI3M=; b=oU/lurmFb4U6uRaRbjIsVUaZ5I3vqmaLmfinkLVMJpfRLQ+BGfZj8ybrozwoMKpBXY xAEURZgANujEVxgReqzqszvpur9UVVdizwv3Wps2M9Lt6Z7kCVtvBWENK4yG+TljrTL1 Zc/VF0806+OX90DO/y5Txn/FoNxVfD7Pp7/V90ppgpuTxGpLPHd4y2DpRHqWiYQMa70G oCtdKDOQm2zad3DJ458vWxi5CprbYeqzf8+2RPPDFLDkZmMyWtTS0g0u4PI6x6wlefnm Go6IyWe1quWyheeh+ZzIcH1OZxVGYUsA7Y8c9OtWXSgB2hhwrVjcXc0Up45Sql5Jvktn 4GLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bgdev-pl.20230601.gappssmtp.com header.s=20230601 header.b=U94XMpT0; spf=pass (google.com: domain of linux-kernel+bounces-4012-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-4012-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id u14-20020a65670e000000b005cd88fb773asi3445682pgf.298.2023.12.18.08.09.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Dec 2023 08:09:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-4012-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@bgdev-pl.20230601.gappssmtp.com header.s=20230601 header.b=U94XMpT0; spf=pass (google.com: domain of linux-kernel+bounces-4012-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-4012-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 0EEE0B2476B for ; Mon, 18 Dec 2023 16:02:35 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E3A55495DE; Mon, 18 Dec 2023 16:01:46 +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="U94XMpT0" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-ua1-f51.google.com (mail-ua1-f51.google.com [209.85.222.51]) (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 BD4D13D56F for ; Mon, 18 Dec 2023 16:01:44 +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-f51.google.com with SMTP id a1e0cc1a2514c-7c45acb3662so299915241.0 for ; Mon, 18 Dec 2023 08:01:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1702915303; x=1703520103; 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=yGsftRUwsP12LQ30FBWYDs/WH5EY9TUOi7H6csPAxGw=; b=U94XMpT0QLBlxq8bYxp3/sS8NKhOnDJNMoe95l8Kz6Jw2spo+XtO0leVWb4rHyjmzg qm13lwpczUpYXcJxdYiy8Wjd9BwBVhTb3nireB6o1cy4c4oVvnv+Zn2UCA0rFNS7bC6X Xu2UxEva3ThSP95xCHzymDKyA7yiqxdTGMNnk4jEYv4O5bcvR7nAjk3SLuaUx8u/gBya 7m6HuZ9b3fpu8LtmCL6DlK223mq5WWKkxYfyjd68zbOaUKXUCrVb2eoaZbcyWX5lGiBg qAahpqlPzE4/QkxUU5rab3zT/oXGuvfclkvG2TPqs++68qEVf1ZMxAClva155JhoftGG f7Zg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702915303; x=1703520103; 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=yGsftRUwsP12LQ30FBWYDs/WH5EY9TUOi7H6csPAxGw=; b=Mcx9vijVDxfmwULMRqsgXjaFhvf83VU2QzR4t1iKT+4xvt5MXYTsqeS6zAlhhbtP87 Oucvv1jYIATx9vp1KBdokg0sxcVAlOwQPFJuxxBXJHn/QdU5+rk/XFSrX5aiP5WGDu0I nuCwkl2G+9TjmPIbY36xLWiCqx+Mh4QL4qi/TCYwRHf0B/AIZJqYbWcBOLeSFVJbz5Mr YVPWD9kyEzWSrVwFJaTo6k0FtYMuzPgNC98Ee30clFPZ1Zz/tY/ODjvj0yfol0NfyHQp nB7OmNQ0ib1zVz8/aR9XPSMrtP0p45PYR4m+0eT+mZ/QUlIe5HYYv/adH8yJApYNxAEB nBPg== X-Gm-Message-State: AOJu0Ywi88RtOHLkvlaGQb5PyzEq8q37riQndlbHKFv6I8SUKiEu7Yzz Um2xLK3mUqCqVVCgP3OdmmMd1zvzXGKRKZuxd3B5Mw== X-Received: by 2002:a05:6122:180a:b0:4b6:d379:7f5 with SMTP id ay10-20020a056122180a00b004b6d37907f5mr510520vkb.1.1702915303687; Mon, 18 Dec 2023 08:01:43 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20231216001652.56276-1-warthog618@gmail.com> <20231216001652.56276-2-warthog618@gmail.com> In-Reply-To: From: Bartosz Golaszewski Date: Mon, 18 Dec 2023 17:01:32 +0100 Message-ID: Subject: Re: [PATCH v4 1/5] gpiolib: cdev: relocate debounce_period_us from struct gpio_desc To: Kent Gibson Cc: linux-kernel@vger.kernel.org, linux-gpio@vger.kernel.org, linus.walleij@linaro.org, andy@kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Mon, Dec 18, 2023 at 4:40=E2=80=AFPM Kent Gibson = wrote: > > On Mon, Dec 18, 2023 at 04:24:50PM +0100, Bartosz Golaszewski wrote: > > On Sat, Dec 16, 2023 at 1:17=E2=80=AFAM Kent Gibson wrote: > > > > > > Store the debounce period for a requested line locally, rather than i= n > > > the debounce_period_us field in the gpiolib struct gpio_desc. > > > > > > Add a global tree of lines containing supplemental line information > > > to make the debounce period available to be reported by the > > > GPIO_V2_GET_LINEINFO_IOCTL and the line change notifier. > > > > > > Signed-off-by: Kent Gibson > > > Reviewed-by: Andy Shevchenko > > > --- > > > drivers/gpio/gpiolib-cdev.c | 154 ++++++++++++++++++++++++++++++----= -- > > > 1 file changed, 132 insertions(+), 22 deletions(-) > > > > > > +static inline bool line_is_supplemental(struct line *line) > > > > Under v2 I suggested naming this line_has_suppinfo(). Any reason not > > to do it? I think it's more logical than saying "line is > > supplemental". The latter makes it seem as if certain line objects > > would "supplement" some third party with something. What this really > > checks is: does this line contain additional information. > > > > > My bad - responded to your first comment and then missed the rest. > > Agreed - the naming could be better. Will fix for v5. > > > > +{ > > > + return READ_ONCE(line->debounce_period_us); > > > +} > > > + > > > +static void line_set_debounce_period(struct line *line, > > > + unsigned int debounce_period_us) > > > +{ > > > + bool was_suppl =3D line_is_supplemental(line); > > > + > > > + WRITE_ONCE(line->debounce_period_us, debounce_period_us); > > > + > > > + if (line_is_supplemental(line) =3D=3D was_suppl) > > > + return; > > > + > > > + if (was_suppl) > > > + supinfo_erase(line); > > > + else > > > + supinfo_insert(line); > > > > Could you add a comment here saying it's called with the config mutex > > taken as at first glance it looks racy but actually isn't? > > > > Sure. Though it is also covered by the gdev->sem you added, right? > So the config_mutex is now redundant? > Should I document it is covered by both? > Or drop the config_mutex entirely? > No! The semaphore is a read-write semaphore and we can have multiple readers at once. This semaphore only protects us from the chip being set to NULL during a system call. It will also go away once I get the descriptor access serialized (or not - I'm figuring out a lockless approach) and finally use SRCU to protect gdev->chip. > And you wanted some comments to explain the logic? > I thought this is a common "has it changed" pattern, and so didn't > require additional explanation, but I guess not as common as I thought. > If line_set_debounce_period() could be called concurrently for the same line, this approach would be racy. It cannot but I want a comment here as I fear that if in the future we add some more attributes that constitute "supplemental info" and which may be changed outside of the config lock then this would in fact become racy. Bart > Cheers, > Kent.