Skip to content

Commit

Permalink
IB/umad: Return EPOLLERR in case of when device disassociated
Browse files Browse the repository at this point in the history
[ Upstream commit def4cd4 ]

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: 1da177e ("Linux-2.6.12-rc2")
Link: https://lore.kernel.org/r/20210125121339.837518-3-leon@kernel.org
Signed-off-by: Shay Drory <shayd@nvidia.com>
Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
shayshyi authored and gregkh committed Mar 4, 2021
1 parent 1598e9e commit 69ca7a1
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions drivers/infiniband/core/user_mad.c
Expand Up @@ -397,6 +397,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);

Expand Down Expand Up @@ -658,10 +663,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;
}
Expand Down Expand Up @@ -1341,6 +1350,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)
Expand Down

0 comments on commit 69ca7a1

Please sign in to comment.