Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp4566770ybi; Tue, 11 Jun 2019 08:42:48 -0700 (PDT) X-Google-Smtp-Source: APXvYqx8ww98U2/QFBdbG6zDNJfLFn15PVfVXSY1kZ4IcAROPPw2YY3fSGNsHGo+GQ2jlH9WlipK X-Received: by 2002:a17:90a:480d:: with SMTP id a13mr26601277pjh.40.1560267768813; Tue, 11 Jun 2019 08:42:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560267768; cv=none; d=google.com; s=arc-20160816; b=VeED0g9MSUNFNdlDe8W805py7M6zGc3BWM1/4bQwhGMrVmqlQD6vECHd+6JSCUt17o agJUIF8RR6AHETmtEJ0o+DNO/SFx79vG3isAR3r38mwJDkxewlWcrpW0N2KRb8e+iudO 9WP00lfWTgxGilmv7kRsSmAw/R+HPGmaxJSLiQ4g2swADAAiKxqM2a+XLKEs3+aZqwV5 Nqpx+EvgoaVrZh+T/zNYRrh1856ouEnWMjQPrQqzY6Vb4/nNtf/OOsgCTQt/07G0BHSj ZbNr4z22i9xeZ+MiuSqcPC8KpxT4l7E7hoDYiUGdqWpj9HtnC1nuGEra3IRr+yv5zTSB G+PA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:from; bh=FVTNkmVGFoGdBxUbM3RaOzA7kKK+c84IdqQOoJlBdpE=; b=Jsv5YW6xlRsA4kQm7eJF+LPFOX12t2lnXULnMDLt2f7eemViHcBQwObeJZspiQELc3 N7X211fJsOZ2QcshabzNlNc++lplmyaVeto5Fzv+DBcxijFDguxoQJVC2RDbogUGqGBe H7ujFDiuPSsD21ZvIVtf3IYiZ/KluvXrBIDQmXpV2c+zXCdrzJBaNDC9EmAbHzW/n0tu EVtJiWi2WYmOyUcdBffLkUTOR2FjWivgTdCPoXRr8tKbvyuxDreynPVIsp7eMbn7qB6Y BZz//DYzzJlFvbZeXXULLV3DNYXh1vCMJDSCSbe3N7awb4T1VylFG1+pLd1Bz8889Mph eN0g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a33si13073080plc.283.2019.06.11.08.42.34; Tue, 11 Jun 2019 08:42:48 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404245AbfFKOzX (ORCPT + 99 others); Tue, 11 Jun 2019 10:55:23 -0400 Received: from mx2.suse.de ([195.135.220.15]:52618 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2404071AbfFKOzT (ORCPT ); Tue, 11 Jun 2019 10:55:19 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id AF2D9AEF5; Tue, 11 Jun 2019 14:55:18 +0000 (UTC) From: Roman Penyaev Cc: Roman Penyaev , Andrew Morton , Al Viro , Linus Torvalds , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 09/14] epoll: support polling from userspace for ep_remove() Date: Tue, 11 Jun 2019 16:54:53 +0200 Message-Id: <20190611145458.9540-10-rpenyaev@suse.de> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190611145458.9540-1-rpenyaev@suse.de> References: <20190611145458.9540-1-rpenyaev@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit To: unlisted-recipients:; (no To-header on input) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On ep_remove() simply mark a user item with EPOLLREMOVE if the item was ready (i.e. has some bits set). That will prevent further user index entry creation on item ->bit reuse. Signed-off-by: Roman Penyaev Cc: Andrew Morton Cc: Al Viro Cc: Linus Torvalds Cc: linux-fsdevel@vger.kernel.org Cc: linux-kernel@vger.kernel.org --- fs/eventpoll.c | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/fs/eventpoll.c b/fs/eventpoll.c index 4f541f85c7e5..edf7ba28bce0 100644 --- a/fs/eventpoll.c +++ b/fs/eventpoll.c @@ -879,12 +879,30 @@ static __poll_t ep_scan_ready_list(struct eventpoll *ep, return res; } -static void epi_rcu_free(struct rcu_head *head) +static void epi_rcu_free_cb(struct rcu_head *head) { struct epitem *epi = container_of(head, struct epitem, rcu); kmem_cache_free(epi_cache, epi); } +static void uepi_rcu_free_cb(struct rcu_head *head) +{ + struct epitem *epi = container_of(head, struct epitem, rcu); + kmem_cache_free(uepi_cache, uep_item_from_epi(epi)); +} + +static void epi_rcu_free(struct eventpoll *ep, struct epitem *epi) +{ + /* + * Check if `ep` is polled by user here, in this function, not + * in the callback, in order not to control lifetime of the 'ep'. + */ + if (ep_polled_by_user(ep)) + call_rcu(&epi->rcu, uepi_rcu_free_cb); + else + call_rcu(&epi->rcu, epi_rcu_free_cb); +} + static inline int ep_get_bit(struct eventpoll *ep) { bool was_set; @@ -1156,10 +1174,14 @@ static int ep_remove(struct eventpoll *ep, struct epitem *epi) rb_erase_cached(&epi->rbn, &ep->rbr); - write_lock_irq(&ep->lock); - if (ep_is_linked(epi)) - list_del_init(&epi->rdllink); - write_unlock_irq(&ep->lock); + if (ep_polled_by_user(ep)) { + ep_remove_user_item(epi); + } else { + write_lock_irq(&ep->lock); + if (ep_is_linked(epi)) + list_del_init(&epi->rdllink); + write_unlock_irq(&ep->lock); + } wakeup_source_unregister(ep_wakeup_source(epi)); /* @@ -1169,7 +1191,7 @@ static int ep_remove(struct eventpoll *ep, struct epitem *epi) * ep->mtx. The rcu read side, reverse_path_check_proc(), does not make * use of the rbn field. */ - call_rcu(&epi->rcu, epi_rcu_free); + epi_rcu_free(ep, epi); atomic_long_dec(&ep->user->epoll_watches); -- 2.21.0