From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751611AbdJ1MyU (ORCPT ); Sat, 28 Oct 2017 08:54:20 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:9467 "EHLO szxga04-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751179AbdJ1Mwa (ORCPT ); Sat, 28 Oct 2017 08:52:30 -0400 From: Hou Tao To: CC: , , , , , Subject: [RFC][PATCH 5/8] epoll: iterate epi in file->f_ep_links by using list_first_or_null_rcu Date: Sat, 28 Oct 2017 20:58:24 +0800 Message-ID: <1509195507-29037-6-git-send-email-houtao1@huawei.com> X-Mailer: git-send-email 2.7.5 In-Reply-To: <1509195507-29037-1-git-send-email-houtao1@huawei.com> References: <1509195507-29037-1-git-send-email-houtao1@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.175.124.28] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A090204.59F47D84.008F,ss=1,re=0.000,recu=0.000,reip=0.000,cl=1,cld=1,fgs=0, ip=0.0.0.0, so=2014-11-16 11:51:01, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: ccad9611fbed56f66f584ab7a27061a3 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When eventpoll_release_file() iterates epitem in file->f_ep_links, the epitem may be removed by ep_free(). To protect again the concurrent writer, iterate file->f_ep_links by using rcu_read_lock() and list_first_or_null_rcu() Signed-off-by: Hou Tao --- fs/eventpoll.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/fs/eventpoll.c b/fs/eventpoll.c index 18de596..e1e4796 100644 --- a/fs/eventpoll.c +++ b/fs/eventpoll.c @@ -1033,12 +1033,22 @@ void eventpoll_release_file(struct file *file) * * Besides, ep_remove() acquires the lock, so we can't hold it here. */ - list_for_each_entry_safe(epi, next, &file->f_ep_links, fllink) { + rcu_read_lock(); + while (true) { + epi = list_first_or_null_rcu(&file->f_ep_links, struct epitem, fllink); + if (!epi) + break; + ep = epi->ep; + rcu_read_unlock(); + mutex_lock_nested(&ep->mtx, 0); ep_remove(ep, epi); mutex_unlock(&ep->mtx); + + rcu_read_lock(); } + rcu_read_unlock(); /* * The file can not been added to tfile_check_list again, because -- 2.7.5