From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751443AbdJ1Mwl (ORCPT ); Sat, 28 Oct 2017 08:52:41 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:9536 "EHLO szxga05-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751156AbdJ1Mwc (ORCPT ); Sat, 28 Oct 2017 08:52:32 -0400 From: Hou Tao To: CC: , , , , , Subject: [RFC][PATCH 3/8] epoll: remove file from tfile_check_list when releasing file Date: Sat, 28 Oct 2017 20:58:22 +0800 Message-ID: <1509195507-29037-4-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.0A090203.59F47D80.0073,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: 9aed945cc579ad36002a71c745d737c2 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Before the removal of epmutex, the acquisition of epmutex in eventpoll_release_file() will prevent the freeing of file, so it's OK to iterate files in tfile_check_list. And now epmutex is removed, so when releasing file, we need to remove file from tfile_check_list to ensure the validity of file. Signed-off-by: Hou Tao --- fs/eventpoll.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/fs/eventpoll.c b/fs/eventpoll.c index 44ea587..998c635 100644 --- a/fs/eventpoll.c +++ b/fs/eventpoll.c @@ -1029,6 +1029,18 @@ void eventpoll_release_file(struct file *file) ep_remove(ep, epi); mutex_unlock(&ep->mtx); } + + /* + * The file can not been added to tfile_check_list again, because + * (1) its refcnt has been zero, so ep_ctrl() can no longer get its reference + * (2) its related ep items have been removed, so ep_loop_check_proc() + * can not get the file by ep->rbr + */ + if (!list_empty_careful(&file->f_tfile_llink)) { + mutex_lock(&epmutex); + list_del_init(&file->f_tfile_llink); + mutex_unlock(&epmutex); + } } static int ep_alloc(struct eventpoll **pep) -- 2.7.5