From patchwork Fri Aug 31 14:16:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Wise X-Patchwork-Id: 10584151 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 850B21709 for ; Fri, 31 Aug 2018 15:55:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 724812C203 for ; Fri, 31 Aug 2018 15:55:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 64CA12C229; Fri, 31 Aug 2018 15:55:51 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F08512C21B for ; Fri, 31 Aug 2018 15:55:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728237AbeHaUD6 (ORCPT ); Fri, 31 Aug 2018 16:03:58 -0400 Received: from 72-48-214-68.dyn.grandenetworks.net ([72.48.214.68]:47554 "EHLO smtp.opengridcomputing.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727654AbeHaUD6 (ORCPT ); Fri, 31 Aug 2018 16:03:58 -0400 Received: by smtp.opengridcomputing.com (Postfix, from userid 503) id 9DAFA22788; Fri, 31 Aug 2018 10:55:49 -0500 (CDT) Message-Id: <264e959fc18a4e96fdfc43cfa348f95c3c9ee000.1535730794.git.swise@opengridcomputing.com> From: Steve Wise Date: Fri, 31 Aug 2018 07:16:03 -0700 Subject: [PATCH RFC] ib_uverbs: atomically flush and mark closed the comp event queue To: linux-rdma@vger.kernel.org Cc: jgg@ziepe.ca, dledford@redhat.com, matanb@mellanox.com Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Currently a uverbs completion event queue is flushed of events in ib_uverbs_comp_event_close() with the queue spinlock held and then released. Yet setting ev_queue->is_closed is not set until later in uverbs_hot_unplug_completion_event_file(). In between the time ib_uverbs_comp_event_close() releases the lock and uverbs_hot_unplug_completion_event_file() acquires the lock, a completion event can arrive and be inserted into the event queue by ib_uverbs_comp_handler(). This can cause a "double add" list_add warning or crash depending on the kernel configuration, or a memory leak because the event is never dequeued since the queue is already closed down. So move the setting of ev_queue->is_closed to ib_uverbs_comp_event_close(). Cc: stable@vger.kernel.org Fixes: 1e7710f3f656 ("IB/core: Change completion channel to use the reworked objects schema") Signed-off-by: Steve Wise --- I added the RFC tag because I'm not sure removing setting is_closed in uverbs_hot_unplug_completion_event_file() is correct. Can uverbs_hot_unplug_completion_event_file() be called w/o ib_uverbs_comp_event_close() being called first? Should is_closed be set in both places? --- drivers/infiniband/core/uverbs_main.c | 1 + drivers/infiniband/core/uverbs_std_types.c | 4 ---- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/drivers/infiniband/core/uverbs_main.c b/drivers/infiniband/core/uverbs_main.c index 823beca448e1..b3ef7db68bde 100644 --- a/drivers/infiniband/core/uverbs_main.c +++ b/drivers/infiniband/core/uverbs_main.c @@ -440,6 +440,7 @@ static int ib_uverbs_comp_event_close(struct inode *inode, struct file *filp) list_del(&entry->obj_list); kfree(entry); } + file->ev_queue.is_closed = 1; spin_unlock_irq(&file->ev_queue.lock); uverbs_close_fd(filp); diff --git a/drivers/infiniband/core/uverbs_std_types.c b/drivers/infiniband/core/uverbs_std_types.c index 203cc96ac6f5..76fc9b7fec59 100644 --- a/drivers/infiniband/core/uverbs_std_types.c +++ b/drivers/infiniband/core/uverbs_std_types.c @@ -199,10 +199,6 @@ static int uverbs_hot_unplug_completion_event_file(struct ib_uobject *uobj, uobj); struct ib_uverbs_event_queue *event_queue = &comp_event_file->ev_queue; - spin_lock_irq(&event_queue->lock); - event_queue->is_closed = 1; - spin_unlock_irq(&event_queue->lock); - if (why == RDMA_REMOVE_DRIVER_REMOVE) { wake_up_interruptible(&event_queue->poll_wait); kill_fasync(&event_queue->async_queue, SIGIO, POLL_IN);