Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp512910pxu; Sun, 25 Oct 2020 08:05:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx1lFnwKWV42020ISZh+yMZapMROTCQ5i7ShXOhK9XjSNcQVP2vcZdf2vSgSYwqdUi7wd+T X-Received: by 2002:a50:fd17:: with SMTP id i23mr11153238eds.50.1603638309287; Sun, 25 Oct 2020 08:05:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603638309; cv=none; d=google.com; s=arc-20160816; b=0D/kbaS9QEExWfWsS2S2QhAklJwBva7wS9q/PLntoOSOi3PqmLle2Fc0OyLTa9Gfw1 bROfLEv32VDOxhJW3Cg9jHMIxtJXmiyZcHx/SNbwbqr0po0TalcS3p6PWY538IbH3lfJ h/nv/Cy7bmq9XSUxB8BCH/AZAWyYrJArjXagWEi4Sny0Nj6AU4ZwCuKY6V1i/i/mJj6S TxbZcgUBLrPi1cb+dDYZ4vBHSXjEVEedPYGHTGPTvMX6mqpdl1u6Grls4OAbIgrsuU17 4kLODe1ikw+Yc3rMomnYPDx0hzO++Du9Zdwg6hCgJG+NTHfD+ohN9u1pN6UDSOo0QeR/ pPkA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=MO3IwgFsTuuAQb69apcANcklu+gz2Tub8fis0XXwpSs=; b=pII4PLwSx5a9PWJQr7vwV7upqiz83WYHqgXDfp+nQsmtkFxMzLtH4suFhMFfh0uIvB H9heLf5hVOVNqeUJkT9iLy8movrLf9we1y/ZdHUIoqov61aLKHlm/nDBbdjd4mXCPRqP JFL6OioWHLXFDlyoZaz0iTPJKmrMotbV28bh7gKPe2368BKPGVQVvNL7HPpllQ4bD0Jr whWI+1Q9egM+aBwdwJpzyU+ekl3cnLJWSzXnlvx5ACF+gt41ypKlZuQLeVlu03uPLMDf 2LfdeJKhfoTbBLW0dCyR9SHJjzBreAUmFPG55oX7SyswQSGDV/5AWJL0ctwXSuwo/AOJ Gcfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=LlUxpVS1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u1si5208083ejz.572.2020.10.25.08.04.29; Sun, 25 Oct 2020 08:05:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=LlUxpVS1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1416242AbgJYNSP (ORCPT + 99 others); Sun, 25 Oct 2020 09:18:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37294 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729022AbgJYNSO (ORCPT ); Sun, 25 Oct 2020 09:18:14 -0400 Received: from mail-qk1-x744.google.com (mail-qk1-x744.google.com [IPv6:2607:f8b0:4864:20::744]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2C68FC0613CE; Sun, 25 Oct 2020 06:18:14 -0700 (PDT) Received: by mail-qk1-x744.google.com with SMTP id r7so5968034qkf.3; Sun, 25 Oct 2020 06:18:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=MO3IwgFsTuuAQb69apcANcklu+gz2Tub8fis0XXwpSs=; b=LlUxpVS1OaD+CeUBXrHMQWS+9BXnKIfgj5wmrUKZT5pL+Y/rDiYUzqZN7mkbI83bDM pO12lEGNkAYK2ITrMnQPoJUxojGxCJM9uXUJjfOPGP3olHT8+ZfFhq4g9m1UO6WUqhRq skojFLE08/yUGaP9dAdnYgCVWLYuZe8/nOtl/fyM4ycl4dwkXroiB3VWnYfaZ2iO8QzM 3zKdF4u3wMKG1JSAVnQRznN46F0cTTIU78q4NsUxbgBNYIaZ015R50+Vf1xQpeD+xbZB NnRqiHY8uCsBhaUymXn8u9VZZFwOpOsA+luVzJ6FQcKxSsfbG9R4CjzuB/kjYLN3l4L0 fL7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=MO3IwgFsTuuAQb69apcANcklu+gz2Tub8fis0XXwpSs=; b=NH+SMx0MjYjy1NJztam1tW8rTbsb9zJMAdfJ/EDblrQxtrWxTQcdFXlfFuiYEEfpWS vw9+kRpxK4kA26KWRCnuro6ljMt7EDWvQUV+Zx96qTjc3idawzJBiDbvBB4G5qhXaVJ8 KmibCSfvCemen/gsPc3AUQmOXp4cozNN7oWDhLQYMd3Xfn+0XI/b9n70BSfoOs8xdrff 2gb4YK6yWnCRZuLW8aIzvXf9rj2h3W4x7LTNByHSdawQVrPLyp+5gAZA3uGiY5SakrLv JpjsgcUDL8gG71jgZivn7RG+FvqxNzgNzQSwqF4a4L8yN1Hsm6rTfgcGygcngBYINkxA sdpw== X-Gm-Message-State: AOAM533Ykvekd+jeK9fsIFl0Zmwxaw4W92q71SPQBZ//fIVZ8btrNtT1 ojZRapbRCc8lwVSyq4wLg/c= X-Received: by 2002:a37:a407:: with SMTP id n7mr11745316qke.248.1603631893378; Sun, 25 Oct 2020 06:18:13 -0700 (PDT) Received: from shinobu (072-189-064-225.res.spectrum.com. [72.189.64.225]) by smtp.gmail.com with ESMTPSA id 19sm4563158qki.33.2020.10.25.06.18.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Oct 2020 06:18:12 -0700 (PDT) Date: Sun, 25 Oct 2020 09:18:09 -0400 From: William Breathitt Gray To: David Lechner Cc: jic23@kernel.org, kamel.bouhara@bootlin.com, gwendal@chromium.org, alexandre.belloni@bootlin.com, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, syednwaris@gmail.com, patrick.havelange@essensium.com, fabrice.gasnier@st.com, mcoquelin.stm32@gmail.com, alexandre.torgue@st.com Subject: Re: [PATCH v5 3/5] counter: Add character device interface Message-ID: <20201025131809.GB3458@shinobu> References: <00be1fccc672c5207f3b04fe4cc09c29e22641f4.1601170670.git.vilhelm.gray@gmail.com> <20201018165822.GE231549@shinobu> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="wzJLGUyc3ArbnUjN" Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --wzJLGUyc3ArbnUjN Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, Oct 20, 2020 at 11:06:42AM -0500, David Lechner wrote: > On 10/18/20 11:58 AM, William Breathitt Gray wrote: > > On Wed, Oct 14, 2020 at 05:40:44PM -0500, David Lechner wrote: > >> On 9/26/20 9:18 PM, William Breathitt Gray wrote: > >>> +static ssize_t counter_chrdev_read(struct file *filp, char __user *b= uf, > >>> + size_t len, loff_t *f_ps) > >>> +{ > >>> + struct counter_device *const counter =3D filp->private_data; > >>> + int err; > >>> + unsigned long flags; > >>> + unsigned int copied; > >>> + > >>> + if (len < sizeof(struct counter_event)) > >>> + return -EINVAL; > >>> + > >>> + do { > >>> + if (kfifo_is_empty(&counter->events)) { > >>> + if (filp->f_flags & O_NONBLOCK) > >>> + return -EAGAIN; > >>> + > >>> + err =3D wait_event_interruptible(counter->events_wait, > >>> + !kfifo_is_empty(&counter->events)); > >>> + if (err) > >>> + return err; > >>> + } > >>> + > >>> + raw_spin_lock_irqsave(&counter->events_lock, flags); > >>> + err =3D kfifo_to_user(&counter->events, buf, len, &copied); > >>> + raw_spin_unlock_irqrestore(&counter->events_lock, flags); > >>> + if (err) > >>> + return err; > >>> + } while (!copied); > >>> + > >>> + return copied; > >>> +} > >> > >> All other uses of kfifo_to_user() I saw use a mutex instead of spin > >> lock. I don't see a reason for disabling interrupts here. > >=20 > > The Counter character device interface is special in this case because > > counter->events could be accessed from an interrupt context. This is > > possible if counter_push_event() is called for an interrupt (as is the > > case for the 104_quad_8 driver). In this case, we can't use mutex > > because we can't sleep in an interrupt context, so our only option is to > > use spin lock. > >=20 >=20 >=20 > The way I understand it, locking is only needed for concurrent readers > and locking between reader and writer is not needed. You're right, it does say in the kfifo.h comments that with only one concurrent reader and one current write, we don't need extra locking to use these macros. Because we only have one kfifo_to_user() operating on counter->events, does that mean we don't need locking at all here for the counter_chrdev_read() function? William Breathitt Gray --wzJLGUyc3ArbnUjN Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEk5I4PDJ2w1cDf/bghvpINdm7VJIFAl+VexEACgkQhvpINdm7 VJICoBAAw8HLhwVk1o7CRK0hVoeMc0fdPh59yHCvT33kbxnA92J0zxnjH+MuGVAJ kOWu3CLQ1s0+qhTGMmSfGUUCODAsN9+2IE+it0LnW1cbHw0xw7MBK0vaIkyAKNG4 T3eWQCUYGEwDFWRqSvSCIUBJlAEQPVKcgyntEdgPASaWheL4Do/iGg6QvV3KRVb2 gnzdcQO5sgN+2YVVlhoB3KoeJRVTgskq+S/9b7tw3yDxtyxMCX8huiKXsm0jHMiZ fX8pxf0ni/ht/RLcpTjX7r0n34aL8HU3Owfqkq8DGsYiQ5Jc8AdJ6OAI2hgPifpZ NzwyeFfxAtohot+GZa5RsXewEK8M0kHxnO2MyaxUTrVNZ623p6aWm3h3gNiwpuFg 2V+mDCSTPN5y0q0Bg0k6n3c7cGWnItY9/UJnNJiUg8zinEzWfM5jwcM6LAOVj5pS EEdlzXu6IFR+T16m7N2bdR1EcAyB95OFkFL0IX9oOLcXYRmWRHQIBiFoEJXitNYQ X7ZXuKQmQpNoFP6kR4oRkvT/SQlt/jXJMw745PJKOgnQnOpV0dGYt8CMZnjI350k WJzvTVmWLSq3xzuXzB7egNqDUzl3u3GZiYBU7PkzTRAmxM3ZcCcKbntbMwOshYZz NKIcZpApO1tXWlSfm3A81N+heHtPlKFgxjHqxsQPbRaWzm1h5MU= =jRkJ -----END PGP SIGNATURE----- --wzJLGUyc3ArbnUjN--