Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp406903pxb; Wed, 3 Mar 2021 06:22:45 -0800 (PST) X-Google-Smtp-Source: ABdhPJy5mO6i/D3vtmwIzWypTQcZe5S4PI6ciruJQH4hnUs+OH7goDh0zDgX08lE5DdtclCRPWQD X-Received: by 2002:a17:907:1b21:: with SMTP id mp33mr25679745ejc.358.1614781360652; Wed, 03 Mar 2021 06:22:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614781360; cv=none; d=google.com; s=arc-20160816; b=eCVorgH9nB3/ImWdp4E/9+JxFeZ4V1lKtaXwZYpK4GW6mjt0QKNw0WP9dzfMYjiv29 UOkD1PUINj68Q+9gidH3nzXL0sBThljg7XUBqMciNIMDjDPqR9SRAiaQAD4Dl9Krw4yF x3qVPkSJHvpw69exe6q/8c6xMiDUlntp+Q4XqD6bQBDBdravd1GdZ952QxO6gxTW7Rv5 9c5219zLT/ki3GyHTBXHDM2qwYFyLNda3pWcWtSFJdoIA1376iJnwtfWkmsxKpFP4RkC GEIoQR7FG1jZQibMsKJI8BH14kRYiX/9G55Ia1WevkqtenHrEMvVGjjvIxNniiqcBh/7 feiw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=YY/oZkU/9Yv8jjtoLv3o1+W/1x/ED2UwQntq/lb6/5U=; b=EPgw/50PP0RCbEtWZIzvcKAeGmpbON+b3W/P9IyANvKh+e2LAgtP3gDX9tb6wEfgh2 QCik7Zk5p9A/B2yoy/ulRLHzjaPQ1EwkQqhHl/WLPQir4m2CTy6V24jZC64aSFaboOmQ rW3AmSqw3b5LuhpEnUWpGrdoxUzsz5DIFlqFNcfU6VWPRbjmqpoFqaSb68JaChq/vr8c QuJCZ1gruB3t+aSWBbPE4aZFODKiGTjapDA7U/cdAxhXL6dTvui3e8Gzk6HgFtFBnMa0 fxJS+wMExWBacjjDhPLRQFHO4Ais0JGraWyu8FuHqxQ7Y+RyKthY8oQgaSS3XuG2vGn5 z0CA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=LjrFJvDQ; 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=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o9si14886032eju.695.2021.03.03.06.21.42; Wed, 03 Mar 2021 06:22:40 -0800 (PST) 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=@linuxfoundation.org header.s=korg header.b=LjrFJvDQ; 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=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240025AbhCAUpZ (ORCPT + 99 others); Mon, 1 Mar 2021 15:45:25 -0500 Received: from mail.kernel.org ([198.145.29.99]:36106 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237558AbhCARIY (ORCPT ); Mon, 1 Mar 2021 12:08:24 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id F17156500A; Mon, 1 Mar 2021 16:41:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1614616892; bh=GdtgZNuFird63mYoLEQ+/N6skbrzCla4VJhO6TulXGE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LjrFJvDQF59kGc7AaLEJrKezNHmrCI8hZ8yWZBtCTztWtlmZ9TZanIOmCKlK6tBnj B3sujKHf9bsYJJ4H3ezGuxO0U5ax4e4VckVrLR61P19u4uIc5h46s71sanboQUI0ec 77UImGyw39+qEOlnF5B3QHYYMnk1skeamwOCJV+k= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Shay Drory , Leon Romanovsky , Jason Gunthorpe , Sasha Levin Subject: [PATCH 4.19 132/247] IB/umad: Return EPOLLERR in case of when device disassociated Date: Mon, 1 Mar 2021 17:12:32 +0100 Message-Id: <20210301161038.129991424@linuxfoundation.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210301161031.684018251@linuxfoundation.org> References: <20210301161031.684018251@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Shay Drory [ Upstream commit def4cd43f522253645b72c97181399c241b54536 ] Currently, polling a umad device will always works, even if the device was disassociated. A disassociated device should immediately return EPOLLERR from poll(). Otherwise userspace is endlessly hung on poll() with no idea that the device has been removed from the system. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Link: https://lore.kernel.org/r/20210125121339.837518-3-leon@kernel.org Signed-off-by: Shay Drory Signed-off-by: Leon Romanovsky Signed-off-by: Jason Gunthorpe Signed-off-by: Sasha Levin --- drivers/infiniband/core/user_mad.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/infiniband/core/user_mad.c b/drivers/infiniband/core/user_mad.c index db2ac5218c371..471a824be86c4 100644 --- a/drivers/infiniband/core/user_mad.c +++ b/drivers/infiniband/core/user_mad.c @@ -384,6 +384,11 @@ static ssize_t ib_umad_read(struct file *filp, char __user *buf, mutex_lock(&file->mutex); } + if (file->agents_dead) { + mutex_unlock(&file->mutex); + return -EIO; + } + packet = list_entry(file->recv_list.next, struct ib_umad_packet, list); list_del(&packet->list); @@ -642,10 +647,14 @@ static __poll_t ib_umad_poll(struct file *filp, struct poll_table_struct *wait) /* we will always be able to post a MAD send */ __poll_t mask = EPOLLOUT | EPOLLWRNORM; + mutex_lock(&file->mutex); poll_wait(filp, &file->recv_wait, wait); if (!list_empty(&file->recv_list)) mask |= EPOLLIN | EPOLLRDNORM; + if (file->agents_dead) + mask = EPOLLERR; + mutex_unlock(&file->mutex); return mask; } @@ -1262,6 +1271,7 @@ static void ib_umad_kill_port(struct ib_umad_port *port) list_for_each_entry(file, &port->file_list, port_list) { mutex_lock(&file->mutex); file->agents_dead = 1; + wake_up_interruptible(&file->recv_wait); mutex_unlock(&file->mutex); for (id = 0; id < IB_UMAD_MAX_AGENTS; ++id) -- 2.27.0