Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp1106175ybh; Wed, 18 Mar 2020 15:13:15 -0700 (PDT) X-Google-Smtp-Source: ADFU+vsSlwWowHKm9HRAioHTONRtRYgMx9uObXpIAOo8xf8wToTSpLpjrfZL7Q7fEYNHzax/Rrxd X-Received: by 2002:aca:bfc6:: with SMTP id p189mr118051oif.21.1584569595162; Wed, 18 Mar 2020 15:13:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584569595; cv=none; d=google.com; s=arc-20160816; b=pSMR/Jlh7HYDZqNFsZ/RnKnGSQ6Wf4y+cCuxQ4YMQaNgG/26G3m2s4569H/lgYMCzw wq6L2UlkXTmpaT3EvThRQXxCwetec9b0DWpeOglw6Yc2jHYorEOpqVv5CIXrKoXJvTVs bn7fFalF/3ON+jM+wyByW7h9Je+SLN11/9kMVOjMpGIwUHwFpr3+KGiMSbxMJCjlZf2a ZfH/yJnVuEEERU/33R2I0zpVnTA3MhXmF3ZtC/4S5YuK+X8c4CdmkcecEz9nZLQiPfgD DU7Mo03tNACk1tj6LyRL+bYS/Oa7xQEnjfO7bWuGOrjW0WFRFDxAqoTJV6aNXMmMV7nr t9mA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:subject:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to; bh=Uayz6v48OtHR22YncfdJ3LAsexgWekBqA/tHfWm80os=; b=BlOrjtmYBgdNuJgpplmNCD6L4VYTkFXkdwhh6mFHnx78FNMdegNwWzOcXxRty4Zgz+ K63y7Hu+ole/i5d6DdEpbFqqLvfNER6JqVlwSOKCr+stf2wgUXoqWpyd88OvHfaWnQmk mxbb312Ed1VZr4FRMllMa3mZtwZzdNGNUGnloLqJuA96OTD997Wd5ZWWQUXpwjtHR8+I F3bpHgxhYWJk7MaLCClxl7OGGUVan5v7fnMNdG9KopyC+Qu31ouNr0MtXhLGvefmsoUB VvNCjm5pTFMPQTy12V3uQtuFr+KOH63GQ7u/W4XtdX41yN4rqZ69nIGBhq6jD588yJkZ 8gSQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a205si3829oif.159.2020.03.18.15.13.02; Wed, 18 Mar 2020 15:13:15 -0700 (PDT) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727279AbgCRWMo (ORCPT + 99 others); Wed, 18 Mar 2020 18:12:44 -0400 Received: from ale.deltatee.com ([207.54.116.67]:55594 "EHLO ale.deltatee.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726663AbgCRWMn (ORCPT ); Wed, 18 Mar 2020 18:12:43 -0400 Received: from guinness.priv.deltatee.com ([172.16.1.162]) by ale.deltatee.com with esmtp (Exim 4.92) (envelope-from ) id 1jEgut-0000dp-Ap; Wed, 18 Mar 2020 16:12:00 -0600 To: Thomas Gleixner , LKML Cc: Peter Zijlstra , Linus Torvalds , Ingo Molnar , Will Deacon , "Paul E . McKenney" , Joel Fernandes , Steven Rostedt , Randy Dunlap , Sebastian Andrzej Siewior , Kurt Schwemmer , Bjorn Helgaas , linux-pci@vger.kernel.org, Felipe Balbi , Greg Kroah-Hartman , linux-usb@vger.kernel.org, Kalle Valo , "David S. Miller" , linux-wireless@vger.kernel.org, netdev@vger.kernel.org, Oleg Nesterov , Davidlohr Bueso , Michael Ellerman , Arnd Bergmann , linuxppc-dev@lists.ozlabs.org References: <20200318204302.693307984@linutronix.de> <20200318204407.607241357@linutronix.de> From: Logan Gunthorpe Message-ID: <2256dbd5-8f1d-70c5-8855-855638ce3ef4@deltatee.com> Date: Wed, 18 Mar 2020 16:11:56 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0 MIME-Version: 1.0 In-Reply-To: <20200318204407.607241357@linutronix.de> Content-Type: text/plain; charset=utf-8 Content-Language: en-CA Content-Transfer-Encoding: 7bit X-SA-Exim-Connect-IP: 172.16.1.162 X-SA-Exim-Rcpt-To: linuxppc-dev@lists.ozlabs.org, arnd@arndb.de, mpe@ellerman.id.au, dave@stgolabs.net, oleg@redhat.com, netdev@vger.kernel.org, linux-wireless@vger.kernel.org, davem@davemloft.net, kvalo@codeaurora.org, linux-usb@vger.kernel.org, gregkh@linuxfoundation.org, balbi@kernel.org, linux-pci@vger.kernel.org, bhelgaas@google.com, kurt.schwemmer@microsemi.com, bigeasy@linutronix.de, rdunlap@infradead.org, rostedt@goodmis.org, joel@joelfernandes.org, paulmck@kernel.org, will@kernel.org, mingo@kernel.org, torvalds@linux-foundation.org, peterz@infradead.org, linux-kernel@vger.kernel.org, tglx@linutronix.de X-SA-Exim-Mail-From: logang@deltatee.com X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on ale.deltatee.com X-Spam-Level: X-Spam-Status: No, score=-8.8 required=5.0 tests=ALL_TRUSTED,BAYES_00, GREYLIST_ISWHITE,MYRULES_EXCLUSIVE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Subject: Re: [patch V2 02/15] pci/switchtec: Replace completion wait queue usage for poll X-SA-Exim-Version: 4.2.1 (built Wed, 08 May 2019 21:11:16 +0000) X-SA-Exim-Scanned: Yes (on ale.deltatee.com) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2020-03-18 2:43 p.m., Thomas Gleixner wrote: > From: Sebastian Andrzej Siewior > > The poll callback is using the completion wait queue and sticks it into > poll_wait() to wake up pollers after a command has completed. > > This works to some extent, but cannot provide EPOLLEXCLUSIVE support > because the waker side uses complete_all() which unconditionally wakes up > all waiters. complete_all() is required because completions internally use > exclusive wait and complete() only wakes up one waiter by default. > > This mixes conceptually different mechanisms and relies on internal > implementation details of completions, which in turn puts contraints on > changing the internal implementation of completions. > > Replace it with a regular wait queue and store the state in struct > switchtec_user. > > Signed-off-by: Sebastian Andrzej Siewior > Acked-by: Peter Zijlstra (Intel) While I've been against open coding the completion in this driver for a while, I'm convinced by the EPOLLEXCLUSIVE argument for this change. I've reviewed and lightly tested the change with hardware: Reviewed-by: Logan Gunthorpe Thanks, Logan > Cc: Kurt Schwemmer > Cc: Logan Gunthorpe > Cc: Bjorn Helgaas > Cc: linux-pci@vger.kernel.org > --- > V2: Reworded changelog. > --- > drivers/pci/switch/switchtec.c | 22 +++++++++++++--------- > 1 file changed, 13 insertions(+), 9 deletions(-) > > --- a/drivers/pci/switch/switchtec.c > +++ b/drivers/pci/switch/switchtec.c > @@ -52,10 +52,11 @@ struct switchtec_user { > > enum mrpc_state state; > > - struct completion comp; > + wait_queue_head_t cmd_comp; > struct kref kref; > struct list_head list; > > + bool cmd_done; > u32 cmd; > u32 status; > u32 return_code; > @@ -77,7 +78,7 @@ static struct switchtec_user *stuser_cre > stuser->stdev = stdev; > kref_init(&stuser->kref); > INIT_LIST_HEAD(&stuser->list); > - init_completion(&stuser->comp); > + init_waitqueue_head(&stuser->cmd_comp); > stuser->event_cnt = atomic_read(&stdev->event_cnt); > > dev_dbg(&stdev->dev, "%s: %p\n", __func__, stuser); > @@ -175,7 +176,7 @@ static int mrpc_queue_cmd(struct switcht > kref_get(&stuser->kref); > stuser->read_len = sizeof(stuser->data); > stuser_set_state(stuser, MRPC_QUEUED); > - reinit_completion(&stuser->comp); > + stuser->cmd_done = false; > list_add_tail(&stuser->list, &stdev->mrpc_queue); > > mrpc_cmd_submit(stdev); > @@ -222,7 +223,8 @@ static void mrpc_complete_cmd(struct swi > memcpy_fromio(stuser->data, &stdev->mmio_mrpc->output_data, > stuser->read_len); > out: > - complete_all(&stuser->comp); > + stuser->cmd_done = true; > + wake_up_interruptible(&stuser->cmd_comp); > list_del_init(&stuser->list); > stuser_put(stuser); > stdev->mrpc_busy = 0; > @@ -529,10 +531,11 @@ static ssize_t switchtec_dev_read(struct > mutex_unlock(&stdev->mrpc_mutex); > > if (filp->f_flags & O_NONBLOCK) { > - if (!try_wait_for_completion(&stuser->comp)) > + if (!stuser->cmd_done) > return -EAGAIN; > } else { > - rc = wait_for_completion_interruptible(&stuser->comp); > + rc = wait_event_interruptible(stuser->cmd_comp, > + stuser->cmd_done); > if (rc < 0) > return rc; > } > @@ -580,7 +583,7 @@ static __poll_t switchtec_dev_poll(struc > struct switchtec_dev *stdev = stuser->stdev; > __poll_t ret = 0; > > - poll_wait(filp, &stuser->comp.wait, wait); > + poll_wait(filp, &stuser->cmd_comp, wait); > poll_wait(filp, &stdev->event_wq, wait); > > if (lock_mutex_and_test_alive(stdev)) > @@ -588,7 +591,7 @@ static __poll_t switchtec_dev_poll(struc > > mutex_unlock(&stdev->mrpc_mutex); > > - if (try_wait_for_completion(&stuser->comp)) > + if (stuser->cmd_done) > ret |= EPOLLIN | EPOLLRDNORM; > > if (stuser->event_cnt != atomic_read(&stdev->event_cnt)) > @@ -1272,7 +1275,8 @@ static void stdev_kill(struct switchtec_ > > /* Wake up and kill any users waiting on an MRPC request */ > list_for_each_entry_safe(stuser, tmpuser, &stdev->mrpc_queue, list) { > - complete_all(&stuser->comp); > + stuser->cmd_done = true; > + wake_up_interruptible(&stuser->cmd_comp); > list_del_init(&stuser->list); > stuser_put(stuser); > } >