Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp79981imu; Wed, 7 Nov 2018 21:12:18 -0800 (PST) X-Google-Smtp-Source: AJdET5dxJ4S1gD7xYLk0W3VwOLi8iPCICNR96F/qvYlWKJKmcE/5mLchGvzQINVvhTGdcnMWDK9b X-Received: by 2002:a62:ab05:: with SMTP id p5-v6mr3177326pff.211.1541653938083; Wed, 07 Nov 2018 21:12:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541653938; cv=none; d=google.com; s=arc-20160816; b=j1VIGMx1vGgQm2myLzxRuWtGaixyRmgvElGj8jl1VIUGzhhEnBYSRaowGMQKAteFtu DdwPl4iz+J8JDqVJmmie9A1HpW3q9gsSoZScX9f7dLvhYswSLFOz1/P1ib+WAlCOP+cG lsh7ExoR9FdrYYqZYOxqBYXlVEb7+KtTOMkZtP7wwVEGN9XXiCRIX9zrcAbeRuKBc5RX LyqoZnKVCKO5wq6yqircguZPhdb6Vr/fd0ZBmxNxXJSVd9zt3SX3PJeDqY5z8ZP+cD5v JNec9Z9nm+sOiAKFrDEMFi4vg7novPADmyjF45TK7Wpdqy9KmQaXNrj/QubCn7Aw8z1K D2pQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=0xGAVZPJeSeZOz56caYWEUo3z82lFfLFOrOaIIfQQy8=; b=j/6O+sdzZlAS9nmOXCvwD6ptXR5q8U1uVc+oV8Hycj+9sx4kHU+PsyUhbQb7wdeS0R dWtcNJPDY1rwx7laDAurhJTiGPiGUAO43X0fkIRpbn5VmTNICA4mtYHO0ODr9xSRCJ+q 784NtWI9CdX5aw7iJa+iMnSmIopIUA4LmeXM1BLomEwmg92JjCUbXupLO8sr+SkTYf9q xIPTP/xY/kPbECTH92v+LhIPQaFDXc7i+KR4x6PpPatqjjw0lHcFa6UZx32pVJfFtUZS y9oO+eaff2unrbTI6b+dSpQ9SSs5UZ6YEo8jE+Qa7tRVFpolF7Mk54VAP5bAAR0bqj8W ckmg== 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 k2-v6si3044738plt.254.2018.11.07.21.11.40; Wed, 07 Nov 2018 21:12:18 -0800 (PST) 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 S1728958AbeKHOoH (ORCPT + 99 others); Thu, 8 Nov 2018 09:44:07 -0500 Received: from smtp2.provo.novell.com ([137.65.250.81]:56621 "EHLO smtp2.provo.novell.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728915AbeKHOoG (ORCPT ); Thu, 8 Nov 2018 09:44:06 -0500 Received: from linux-r8p5.suse.de (prv-ext-foundry1int.gns.novell.com [137.65.251.240]) by smtp2.provo.novell.com with ESMTP (TLS encrypted); Wed, 07 Nov 2018 22:10:18 -0700 From: Davidlohr Bueso To: akpm@linux-foundation.org Cc: jbaron@akamai.com, viro@zeniv.linux.org.uk, dave@stgolabs.net, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Davidlohr Bueso Subject: [PATCH 2/6] fs/epoll: simplify ep_send_events_proc() ready-list loop Date: Wed, 7 Nov 2018 21:10:02 -0800 Message-Id: <20181108051006.18751-3-dave@stgolabs.net> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20181108051006.18751-1-dave@stgolabs.net> References: <20181108051006.18751-1-dave@stgolabs.net> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The current logic is a bit convoluted. Lets simplify this with a standard list_for_each_entry_safe() loop instead and just break out after maxevents is reached. While at it, remove an unnecessary indentation level in the loop when there are in fact ready events. Signed-off-by: Davidlohr Bueso --- fs/eventpoll.c | 73 +++++++++++++++++++++++++++++----------------------------- 1 file changed, 37 insertions(+), 36 deletions(-) diff --git a/fs/eventpoll.c b/fs/eventpoll.c index 7ad020f1353b..101d46b81f64 100644 --- a/fs/eventpoll.c +++ b/fs/eventpoll.c @@ -1624,21 +1624,22 @@ static __poll_t ep_send_events_proc(struct eventpoll *ep, struct list_head *head { struct ep_send_events_data *esed = priv; __poll_t revents; - struct epitem *epi; - struct epoll_event __user *uevent; + struct epitem *epi, *tmp; + struct epoll_event __user *uevent = esed->events; struct wakeup_source *ws; poll_table pt; init_poll_funcptr(&pt, NULL); + esed->res = 0; /* * We can loop without lock because we are passed a task private list. * Items cannot vanish during the loop because ep_scan_ready_list() is * holding "mtx" during this call. */ - for (esed->res = 0, uevent = esed->events; - !list_empty(head) && esed->res < esed->maxevents;) { - epi = list_first_entry(head, struct epitem, rdllink); + list_for_each_entry_safe(epi, tmp, head, rdllink) { + if (esed->res >= esed->maxevents) + break; /* * Activate ep->ws before deactivating epi->ws to prevent @@ -1658,42 +1659,42 @@ static __poll_t ep_send_events_proc(struct eventpoll *ep, struct list_head *head list_del_init(&epi->rdllink); - revents = ep_item_poll(epi, &pt, 1); - /* * If the event mask intersect the caller-requested one, * deliver the event to userspace. Again, ep_scan_ready_list() - * is holding "mtx", so no operations coming from userspace + * is holding ep->mtx, so no operations coming from userspace * can change the item. */ - if (revents) { - if (__put_user(revents, &uevent->events) || - __put_user(epi->event.data, &uevent->data)) { - list_add(&epi->rdllink, head); - ep_pm_stay_awake(epi); - if (!esed->res) - esed->res = -EFAULT; - return 0; - } - esed->res++; - uevent++; - if (epi->event.events & EPOLLONESHOT) - epi->event.events &= EP_PRIVATE_BITS; - else if (!(epi->event.events & EPOLLET)) { - /* - * If this file has been added with Level - * Trigger mode, we need to insert back inside - * the ready list, so that the next call to - * epoll_wait() will check again the events - * availability. At this point, no one can insert - * into ep->rdllist besides us. The epoll_ctl() - * callers are locked out by - * ep_scan_ready_list() holding "mtx" and the - * poll callback will queue them in ep->ovflist. - */ - list_add_tail(&epi->rdllink, &ep->rdllist); - ep_pm_stay_awake(epi); - } + revents = ep_item_poll(epi, &pt, 1); + if (!revents) + continue; + + if (__put_user(revents, &uevent->events) || + __put_user(epi->event.data, &uevent->data)) { + list_add(&epi->rdllink, head); + ep_pm_stay_awake(epi); + if (!esed->res) + esed->res = -EFAULT; + return 0; + } + esed->res++; + uevent++; + if (epi->event.events & EPOLLONESHOT) + epi->event.events &= EP_PRIVATE_BITS; + else if (!(epi->event.events & EPOLLET)) { + /* + * If this file has been added with Level + * Trigger mode, we need to insert back inside + * the ready list, so that the next call to + * epoll_wait() will check again the events + * availability. At this point, no one can insert + * into ep->rdllist besides us. The epoll_ctl() + * callers are locked out by + * ep_scan_ready_list() holding "mtx" and the + * poll callback will queue them in ep->ovflist. + */ + list_add_tail(&epi->rdllink, &ep->rdllist); + ep_pm_stay_awake(epi); } } -- 2.16.4