Commit 9c7e37e5 authored by yangerkun's avatar yangerkun Committed by Zheng Zengkai
Browse files

pipe: Fix endless sleep problem due to the out-of-order

hulk inclusion
category: bugfix
bugzilla: 185885 https://gitee.com/openeuler/kernel/issues/I4DDEL



---------------------------

Thers is a out-of-order access problem which would cause endless sleep
when we use pipe with epoll.

The story is following, we assume the ring size is 2, the ring head
is 1, the ring tail is 0, task0 is write task, task1 is read task,
task2 is write task.
Task0                                   Task1           Task2
epoll_ctl(fd, EPOLL_CTL_ADD, ...)
  pipe_poll()
    poll_wait()
    tail = READ_ONCE(pipe->tail);
        // Re-order and get tail=0
                                        pipe_read
                                        tail++ //tail=1
                                                        pipe_write
                                                        head++ //head=2
    head = READ_ONCE(pipe->head);
        // head = 2
    check ring is full by head - tail
Task0 get head = 2 and tail = 0, so it mistake that the pipe ring is
full, then task0 is not add into ready list. If the ring is not full
anymore, task0 would not be woken up forever.

The reason of this problem is that we got inconsistent head/tail value
of the pipe ring, so we fix the problem by getting them protected.

Signed-off-by: default avataryangerkun <yangerkun@huawei.com>
Signed-off-by: default avatarZhang Xiaoxu <zhangxiaoxu5@huawei.com>
Reviewed-by: default avatarZhang Yi <yi.zhang@huawei.com>

Signed-off-by: default avatarChen Jun <chenjun102@huawei.com>
Signed-off-by: default avatarZheng Zengkai <zhengzengkai@huawei.com>
parent d7c0aef0
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment