Received: by 2002:a25:f815:0:0:0:0:0 with SMTP id u21csp2512224ybd; Mon, 24 Jun 2019 07:42:31 -0700 (PDT) X-Google-Smtp-Source: APXvYqwoJjbjwY0y1G6rQOr+OnZfyC4No7dybzgOtzYB2LvQCOzE3njK8qG5uq7u+xp124F1nyFa X-Received: by 2002:a17:90a:bc0c:: with SMTP id w12mr23951463pjr.111.1561387351510; Mon, 24 Jun 2019 07:42:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561387351; cv=none; d=google.com; s=arc-20160816; b=ZjVMSfVpKH0O9o9B/MdUixflTjGs+1eAP8AS/URe0dPzE0oIaDWMn9rC+YRCKkenju F6a/qYL9mobdHBN20gri2HPxOevBO526mstNAych06PYYgOZKhZmo31DWzmVnML8yRms zwPRsw/JlhHGyjapAhmFHr9ScEdQpmOSTk2r1O8sNNmO0En31HXRF8jxgeYhFPgzfRie CyxNSBWlSZuml+IabMxkEn7RZU1oKV61DOI0LxqlxCz+eY8PrSYXACgOhka1HO9MdQrD nvy35VyHrRNr6AecLpfmnKcM/LpSQ8dWmJ9+JwzvnB0DN8+eLJDz4v9sCcVltlUCwFEI Jc+w== 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=+yIaOMaFTW0RxG53obCN9BkECo9DhbgHBWeyNH30vJw=; b=wmqb2a34CQQIU0SylHISPe0cwxAkBOwh9eItQAk56PPEXaUM8LxByVEK6sDkMeblGb JvOT8z9ngtwTo59kyyQqNNl0SXsx/tcn/w+xNmMpzuQtGrNEgtjSgHEjXFQi6noXA5pU ZNXDcZAIHYJ7BxB/JuPCoWWZtXGIJp2xF6cikPtvlD5J+J5IX5i2v1C8HJA4IsrwqhKi cVl4/r1JsKmuilKTd2aSK7fNjEH4GQ+/8QiQXBKRf3H5hVrdZA+G7IGlRhmVjtjAJ6Yr HgLKyL12ZjJ6DMzMEbUJ1w91M0Qy81zrPkB5aVINS1Fpv/5ZSxJil5LBUqIW4JLdYMf7 Mmzw== 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 m11si10406352pll.111.2019.06.24.07.42.15; Mon, 24 Jun 2019 07:42:31 -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 S1729111AbfFXOmF (ORCPT + 99 others); Mon, 24 Jun 2019 10:42:05 -0400 Received: from mx2.suse.de ([195.135.220.15]:50396 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728852AbfFXOmD (ORCPT ); Mon, 24 Jun 2019 10:42:03 -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 80B88AEC3; Mon, 24 Jun 2019 14:42:02 +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 v5 07/14] epoll: call ep_add_event_to_uring() from ep_poll_callback() Date: Mon, 24 Jun 2019 16:41:44 +0200 Message-Id: <20190624144151.22688-8-rpenyaev@suse.de> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190624144151.22688-1-rpenyaev@suse.de> References: <20190624144151.22688-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 Each ep_poll_callback() is called when fd calls wakeup() on epfd. So account new event in user ring. The tricky part here is EPOLLONESHOT. Since we are lockless we have to be deal with ep_poll_callbacks() called in paralle, thus use cmpxchg to clear public event bits and filter out concurrent call from another cpu. 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 | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/fs/eventpoll.c b/fs/eventpoll.c index 3b1f6a210247..cc4612e28e03 100644 --- a/fs/eventpoll.c +++ b/fs/eventpoll.c @@ -1565,6 +1565,29 @@ struct file *get_epoll_tfile_raw_ptr(struct file *file, int tfd, } #endif /* CONFIG_CHECKPOINT_RESTORE */ +/** + * Atomically clear public event bits and return %true if the old value has + * public event bits set. + */ +static inline bool ep_clear_public_event_bits(struct epitem *epi) +{ + __poll_t old, flags; + + /* + * Here we race with ourselves and with ep_modify(), which can + * change the event bits. In order not to override events updated + * by ep_modify() we have to do cmpxchg. + */ + + old = READ_ONCE(epi->event.events); + do { + flags = old; + } while ((old = cmpxchg(&epi->event.events, flags, + flags & EP_PRIVATE_BITS)) != flags); + + return flags & ~EP_PRIVATE_BITS; +} + /** * Adds a new entry to the tail of the list in a lockless way, i.e. * multiple CPUs are allowed to call this function concurrently. @@ -1684,6 +1707,20 @@ static int ep_poll_callback(struct epitem *epi, __poll_t pollflags) if (pollflags && !(pollflags & epi->event.events)) goto out_unlock; + if (ep_polled_by_user(ep)) { + /* + * For polled descriptor from user we have to disable events on + * callback path in case of one-shot. + */ + if ((epi->event.events & EPOLLONESHOT) && + !ep_clear_public_event_bits(epi)) + /* Race is lost, another callback has cleared events */ + goto out_unlock; + + ep_add_event_to_uring(epi, pollflags); + goto wakeup; + } + /* * If we are transferring events to userspace, we can hold no locks * (because we're accessing user memory, and because of linux f_op->poll() @@ -1703,6 +1740,7 @@ static int ep_poll_callback(struct epitem *epi, __poll_t pollflags) ep_pm_stay_awake_rcu(epi); } +wakeup: /* * Wake up ( if active ) both the eventpoll wait list and the ->poll() * wait list. -- 2.21.0