Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp979775ybl; Wed, 4 Dec 2019 14:28:15 -0800 (PST) X-Google-Smtp-Source: APXvYqyxhsgVEAm/Q0hfsOnTN8vRkklbWn1xU+00iHoPa2VYGO6KJu0zYBlMnIDG/0L0OEAwQweT X-Received: by 2002:a05:6830:148d:: with SMTP id s13mr4525613otq.323.1575498495454; Wed, 04 Dec 2019 14:28:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1575498495; cv=none; d=google.com; s=arc-20160816; b=rW3YFADaeamQ2nT8K4fP3SnvXK1TXh6ZT88FUXbFRMshEHPdZvyNYVL1hoEvTiy8BC PQWIrLbs1UHhrrXELdoJVsUIGujzPliWEI/8V46NUMG9zPn90s0VpkwlV5AMaqWLZ2F4 z5Gc8QjWKXuo7ldM08uWgXdmya9qWzeaSez4FqTYYFajKV3+6UmPLOoR1zTRS3qjKxj6 MBu+6QLKd4998+bvUPun7CB8MT1MwuE3rn3vO700C64aGSqaXT5mKQdvBZ19XNNA9VCg sSdUXWvDGQNrl9i5icZdZWLaVFG3s++lGsOvkqgwnHFiFAlT6sD9LzTwudj2fOWrgsRo +6pg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=tAFoA1pfXHfuh5IVrrebPzs6UPD54i8tJnf9BhA9zqY=; b=t5b7CxGSjxq8Q9IoD0cK5SkFAh0a87hmmpcJ2YMgEfRlykpVtw4K+uem9Gd8dlMNe+ 5ZmXOrIc/dPun1RGsk3Web0yHIEpsogCDh/AvLbR8pkimT6ZPfBCcXUvfj8HZpeSEfhx H4ajNQKIjwyAhDduTFhr0B9elKwceBk+MoIZ1YVeA4db9/y9gSxahmBxrFprOcB3RG2r 71M1e+ojdnX/fzSKU5uMA5knlbemO8SInNGJc9KbkVKzYUHkUWeyRLpJ3YYZhZZxQkUz hK3Y4H5M2AtzlK7Yi9XTx84wD4RhXGoTtakRn0xPfgiREigy8FcLE1V3vTuu6u2YeaM1 2HFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=btLVHaGL; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id y130si4023018oiy.28.2019.12.04.14.27.50; Wed, 04 Dec 2019 14:28:15 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=btLVHaGL; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1728357AbfLDWZ7 (ORCPT + 99 others); Wed, 4 Dec 2019 17:25:59 -0500 Received: from mail-pg1-f195.google.com ([209.85.215.195]:40605 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728213AbfLDWZ7 (ORCPT ); Wed, 4 Dec 2019 17:25:59 -0500 Received: by mail-pg1-f195.google.com with SMTP id k25so542143pgt.7; Wed, 04 Dec 2019 14:25:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=tAFoA1pfXHfuh5IVrrebPzs6UPD54i8tJnf9BhA9zqY=; b=btLVHaGLK7ZZyT7Ik0vJTBBHaUjTSw26/Q4xnulPc2WD+wQAy0/CKV4cLwcwo7SRkR /7FvnLN/mQ5Uq21IPDhMV9uOs9gu10UI6xJYliNWS1Hu+snT8F18jn0bOCTtuEslB8SV 5LT6RCoiO9+ZpvNZt5LGV6ZC0Wh2VLcjrqmLoJrbvVH3TDzG8f2PGcQtb5JT/n+D1iVr DNCfNt6Y8QtISX2NBt4fSsDs5haqAN161+AigO0A90mKL5GwKXJO+nVMMw3tJ+QGBxpk X5eMiIZWxrNXYeXonhvFrbf1mgHTXWh030Pky632jnf1zd/K2L13KRrYMUL6YKd05/R5 sBGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=tAFoA1pfXHfuh5IVrrebPzs6UPD54i8tJnf9BhA9zqY=; b=U9MDH566iZ7AlnngzW031JsYWiuG/mUMsPXBmi8nxdUNFkDnBleraV5UueB4my2+ZB 9HS3gU5AgfMYETK1qsiAyR6kdww8GgdAgkvCprmL5nFHWG4HR51JHeMggoPgVNrwBTIH dvxvwuKrJAGgqqWizA0ULbzcg7J/yDGLNaVL7bRdLfxmUJPNo51+aU6HIjQt0sDfA+y2 kl30ZCPaxbbP6npbYSwPdjkKW114uWmXUnAz8mbKZ02+PsNdr7BPvS4owgBw2Tn702P4 RmyHHARQRl/GgOJzaFxdWlT0vm3nkaFYl5+/mE94CzWSt7GU2gR7/lDLn3G3+DV56z0d Jxng== X-Gm-Message-State: APjAAAVsI4oAHmeeIaWoSSq+1SO1S8sM7T0UGxyuyxmjGNU2cLa1PYSK +jAPXO5ytgXspE1C73cwB6QSVnbJRnetXIzXexo= X-Received: by 2002:a62:7590:: with SMTP id q138mr5641663pfc.241.1575498358358; Wed, 04 Dec 2019 14:25:58 -0800 (PST) MIME-Version: 1.0 References: <20191204155912.17590-1-brgl@bgdev.pl> <20191204155912.17590-8-brgl@bgdev.pl> In-Reply-To: <20191204155912.17590-8-brgl@bgdev.pl> From: Andy Shevchenko Date: Thu, 5 Dec 2019 00:25:46 +0200 Message-ID: Subject: Re: [PATCH v2 07/11] gpiolib: rework the locking mechanism for lineevent kfifo To: Bartosz Golaszewski Cc: Kent Gibson , Linus Walleij , "open list:GPIO SUBSYSTEM" , Linux Kernel Mailing List , Bartosz Golaszewski Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Dec 4, 2019 at 6:01 PM Bartosz Golaszewski wrote: > > From: Bartosz Golaszewski > > The read_lock mutex is supposed to prevent collisions between reading > and writing to the line event kfifo but it's actually only taken when > the events are being read from it. > > Drop the mutex entirely and reuse the spinlock made available to us in > the waitqueue struct. Take the lock whenever the fifo is modified or > inspected. Drop the call to kfifo_to_user() and instead first extract > the new element from kfifo when the lock is taken and only then pass > it on to the user after the spinlock is released. > My comments below. > + spin_lock(&le->wait.lock); > if (!kfifo_is_empty(&le->events)) > events = EPOLLIN | EPOLLRDNORM; > + spin_unlock(&le->wait.lock); Sound like a candidate to have kfifo_is_empty_spinlocked(). > struct lineevent_state *le = filep->private_data; > - unsigned int copied; > + struct gpioevent_data event; > int ret; > + if (count < sizeof(event)) > return -EINVAL; This still has an issue with compatible syscalls. See patch I have sent recently. I dunno how you see is the better way: a) apply mine and rebase your series, or b) otherwise. I can do b) if you think it shouldn't be backported. Btw, either way we have a benifits for the following one (I see you drop kfifo_to_user() and add event variable on stack). > + return sizeof(event); Also see comments in my patch regarding the event handling. -- With Best Regards, Andy Shevchenko