From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.5 required=3.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F18C0C388F7 for ; Sun, 25 Oct 2020 17:55:39 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 7F60F21D41 for ; Sun, 25 Oct 2020 17:55:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="DW5GXaNv"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="PqE+NIkC" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7F60F21D41 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Type:Cc: List-Subscribe:List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: In-Reply-To:MIME-Version:References:Message-ID:Subject:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=uMvESqHA2dE3fWQzeKMxIB9T6tBdiCIJPlrmBoamxvg=; b=DW5GXaNve+0KZfMIcUrI9HoVb xICbphofSWzPAVYzdtkcX+tE3r7pqyrOqwjOYDaK4ZiMD5JU9l12LEZ+Mjo9ZyB/4mfu1hsYUB8rI 1dMEPeAEGCa0twVO2rCXlI8zaoYeA6I0jfq8+Bu3tFb7o+ZrmVxMmiTPt3XV/NUK4jYjOmq1DUYex acRBYwlYnj6ZiI9VJb9TR/3+zfQ+wkmR9p6si8AmLstNrV+BoovqrRbPmeYRIkgHShCTCGxMe57IP mbI7gJ2pVEc1wlE0sB6G/GUrTAhpim2voxCRHTOkl0yxm2JPAtypqq9jEESD9u/Q2x8abyUPOE/4+ QBnfjqn8Q==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kWkDC-0001F0-JK; Sun, 25 Oct 2020 17:53:46 +0000 Received: from mail-qt1-x843.google.com ([2607:f8b0:4864:20::843]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kWkD8-0001ET-Fy for linux-arm-kernel@lists.infradead.org; Sun, 25 Oct 2020 17:53:43 +0000 Received: by mail-qt1-x843.google.com with SMTP id h12so74079qtc.9 for ; Sun, 25 Oct 2020 10:53:39 -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=WnvTU6VDuLEf+Rt2Zn1Gdt5ZWfNTNLLVWS72IF0h6Yk=; b=PqE+NIkCpidtvg9ccnzTZ8R6ZKaslUFa6jUfX78jzuqP4FeCXm1ehopZIeOpEIGvfV zUwuE0941wfby2vncTggj2xmv+C0VoORDdNOy4uXuo6t84MB+9Jla4/6B2D3nBcAmUlC aGa8wseNCWKTJIvsysxLs50d+eJ1g55WHEfTD7j9cwtlAf88IIkv6OPx1cr9xuFcHk+b 5mSZhYaceFpLEH7rkUNZgE5+zS/aHWq0j4XV3a8tEOAtltuqSLK1g4N62B+dBd1H+EAK Mi0g35eg6z2LdugxurSJut//sA73JpywiRfozrHFzOXvzEr3jekwqHflohiZowC6/zua ofvA== 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=WnvTU6VDuLEf+Rt2Zn1Gdt5ZWfNTNLLVWS72IF0h6Yk=; b=e+GlunchsfX/TOG68WBbZRd8EOChAUU8w+c7ix6zHqzGPz0pqI7NWgC/K8R2koypuh f9+GUu1UCvxCN0pPPDEau95X4NPNPE/HVO1ROKDqD3Qmv/uoquw+Lyf63w61P/e+7xbn kPLOZ40FKi1HwHAYgyeXR4ohrpSWpxQnqEuYnmqvBJ8qSbUqRK4ZxF98CfTesZjCIbj6 sJGLIeZ342cXa8ispuQltSDJrNqil1ciXWrpLeFwpqyXN+fCjwI3G5xICKavcSoQ8NpI qcpFV4WfqK1Jhmxb16S/CingSvqSVXAP0aPq4/9+MdoWDTiYOXpJl3XrlUfUqW+xRSkm EDlw== X-Gm-Message-State: AOAM5327e5eSHhRSirQbwkyrpJan7tzFaPKkia7qwBGiPO2w33qWsJaz Z11knA6EFbwRPK9k0cQNQ+o= X-Google-Smtp-Source: ABdhPJzNvr9/llgZ98dNMu3rcpa5WW5aUblpGe3+LAoh76G4bw+2TtSIZwfILvnr82QMbJLFomHv6A== X-Received: by 2002:ac8:7c97:: with SMTP id y23mr13455309qtv.48.1603648418004; Sun, 25 Oct 2020 10:53:38 -0700 (PDT) Received: from shinobu (072-189-064-225.res.spectrum.com. [72.189.64.225]) by smtp.gmail.com with ESMTPSA id k64sm4949218qkc.97.2020.10.25.10.53.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Oct 2020 10:53:36 -0700 (PDT) Date: Sun, 25 Oct 2020 13:53:22 -0400 From: William Breathitt Gray To: David Lechner Subject: Re: [PATCH v5 3/5] counter: Add character device interface Message-ID: <20201025175322.GA14219@shinobu> References: <00be1fccc672c5207f3b04fe4cc09c29e22641f4.1601170670.git.vilhelm.gray@gmail.com> <20201018165822.GE231549@shinobu> <20201025131809.GB3458@shinobu> MIME-Version: 1.0 In-Reply-To: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201025_135342_628979_3467545C X-CRM114-Status: GOOD ( 30.24 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kamel.bouhara@bootlin.com, gwendal@chromium.org, alexandre.torgue@st.com, linux-iio@vger.kernel.org, patrick.havelange@essensium.com, alexandre.belloni@bootlin.com, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, mcoquelin.stm32@gmail.com, syednwaris@gmail.com, linux-stm32@st-md-mailman.stormreply.com, jic23@kernel.org Content-Type: multipart/mixed; boundary="===============1007928199419333461==" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org --===============1007928199419333461== Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="NzB8fVQJ5HfG6fxh" Content-Disposition: inline --NzB8fVQJ5HfG6fxh Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sun, Oct 25, 2020 at 11:34:43AM -0500, David Lechner wrote: > On 10/25/20 8:18 AM, William Breathitt Gray wrote: > > 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 = *buf, > >>>>> + 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. > >>> > >>> 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. > >>> > >> > >> > >> The way I understand it, locking is only needed for concurrent readers > >> and locking between reader and writer is not needed. > >=20 > > 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? > >=20 > > William Breathitt Gray > >=20 >=20 > Even if we have the policy that only one file handle to the chrdev > can be open at a time, it is still possible that the it could be > read from multiple threads. So it I think it makes sense to keep > it just to be safe. All right, I'll keep the locks in the code for now to keep it safe in case we have multiple threads reading. William Breathitt Gray --NzB8fVQJ5HfG6fxh Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEk5I4PDJ2w1cDf/bghvpINdm7VJIFAl+Vu3IACgkQhvpINdm7 VJL6Gg/+Mlx2N3lg0kRzevbHYdReGI0UFjEyLqM3u6BmeS5zhbkHY+/QYF9Ak2Th AEe1tI0KJ3KrTiPRH8oEkbZ5f1eY58AovHPYByxzOBMDHx9Z2PUtRmdDF9jqU1mA kw0x/SMHc/Rznkzu44VHl1vLTRxpPDJ3a91PmuKEe5prF0BufeCh+4WdMpwQq1yH RmeaXWg5aKjQtIpjVFivkLjp5sBlP2dh51r34bEd1LA9wQ1FcSdoDe3Jxwwt8Wnx wySRy7nh/RIDp0CkgxdtJfNgSskJ+m/5/bVWCIqKcRkVJCApndX5N02c7C0573so biLq7YKWbF27KjMIyl22XwPxdhBW0CfN+nXGDM0rv8WtzE2qqtEbRe1t3oYGfMZK 6CtXjDL03JyGVIaZCT8XyeAkHhUJM5gxGKygfCRq+O1ftVdzsnDtlhxnmm4Wtn44 YKJvjN2Na66BN1jObZZvfaCSU+iaBqNapkcImB1BHGo6uiAjo/u63ZZNYDABvbbK corwSbj3kgu3kHXgnX9u6sR2pSMZeqcGT+uBNXt3F8tPkDd7UwSNjKswADQrY5GN bNIeee2fI5kmxdqitRPqCYSM4OgB4P/WsI7KgLcLsbH3uFRpb2rIIHGRgdfnWCc5 t/T9hQH0gczN1Beuyj+8MPM657zoQojz9l39rY1XA9dJ5iXhZuM= =gnpW -----END PGP SIGNATURE----- --NzB8fVQJ5HfG6fxh-- --===============1007928199419333461== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel --===============1007928199419333461==--