Skip to content

Commit 69ca7a1

Browse files
shayshyigregkh
authored andcommitted
IB/umad: Return EPOLLERR in case of when device disassociated
[ 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>
1 parent 1598e9e commit 69ca7a1

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

‎drivers/infiniband/core/user_mad.c‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,11 @@ static ssize_t ib_umad_read(struct file *filp, char __user *buf,
397397
mutex_lock(&file->mutex);
398398
}
399399

400+
if (file->agents_dead) {
401+
mutex_unlock(&file->mutex);
402+
return -EIO;
403+
}
404+
400405
packet = list_entry(file->recv_list.next, struct ib_umad_packet, list);
401406
list_del(&packet->list);
402407

@@ -658,10 +663,14 @@ static __poll_t ib_umad_poll(struct file *filp, struct poll_table_struct *wait)
658663
/* we will always be able to post a MAD send */
659664
__poll_t mask = EPOLLOUT | EPOLLWRNORM;
660665

666+
mutex_lock(&file->mutex);
661667
poll_wait(filp, &file->recv_wait, wait);
662668

663669
if (!list_empty(&file->recv_list))
664670
mask |= EPOLLIN | EPOLLRDNORM;
671+
if (file->agents_dead)
672+
mask = EPOLLERR;
673+
mutex_unlock(&file->mutex);
665674

666675
return mask;
667676
}
@@ -1341,6 +1350,7 @@ static void ib_umad_kill_port(struct ib_umad_port *port)
13411350
list_for_each_entry(file, &port->file_list, port_list) {
13421351
mutex_lock(&file->mutex);
13431352
file->agents_dead = 1;
1353+
wake_up_interruptible(&file->recv_wait);
13441354
mutex_unlock(&file->mutex);
13451355

13461356
for (id = 0; id < IB_UMAD_MAX_AGENTS; ++id)

0 commit comments

Comments
 (0)