linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	stable@vger.kernel.org, Al Viro <viro@zeniv.linux.org.uk>
Subject: [PATCH 5.8 83/85] epoll: replace ->visited/visited_list with generation count
Date: Mon,  5 Oct 2020 17:27:19 +0200	[thread overview]
Message-ID: <20201005142118.726966971@linuxfoundation.org> (raw)
In-Reply-To: <20201005142114.732094228@linuxfoundation.org>

From: Al Viro <viro@zeniv.linux.org.uk>

commit 18306c404abe18a0972587a6266830583c60c928 upstream.

removes the need to clear it, along with the races.

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

---
 fs/eventpoll.c |   27 ++++++++-------------------
 1 file changed, 8 insertions(+), 19 deletions(-)

--- a/fs/eventpoll.c
+++ b/fs/eventpoll.c
@@ -218,8 +218,7 @@ struct eventpoll {
 	struct file *file;
 
 	/* used to optimize loop detection check */
-	struct list_head visited_list_link;
-	int visited;
+	u64 gen;
 
 #ifdef CONFIG_NET_RX_BUSY_POLL
 	/* used to track busy poll napi_id */
@@ -274,6 +273,8 @@ static long max_user_watches __read_most
  */
 static DEFINE_MUTEX(epmutex);
 
+static u64 loop_check_gen = 0;
+
 /* Used to check for epoll file descriptor inclusion loops */
 static struct nested_calls poll_loop_ncalls;
 
@@ -283,9 +284,6 @@ static struct kmem_cache *epi_cache __re
 /* Slab cache used to allocate "struct eppoll_entry" */
 static struct kmem_cache *pwq_cache __read_mostly;
 
-/* Visited nodes during ep_loop_check(), so we can unset them when we finish */
-static LIST_HEAD(visited_list);
-
 /*
  * List of files with newly added links, where we may need to limit the number
  * of emanating paths. Protected by the epmutex.
@@ -1971,13 +1969,12 @@ static int ep_loop_check_proc(void *priv
 	struct epitem *epi;
 
 	mutex_lock_nested(&ep->mtx, call_nests + 1);
-	ep->visited = 1;
-	list_add(&ep->visited_list_link, &visited_list);
+	ep->gen = loop_check_gen;
 	for (rbp = rb_first_cached(&ep->rbr); rbp; rbp = rb_next(rbp)) {
 		epi = rb_entry(rbp, struct epitem, rbn);
 		if (unlikely(is_file_epoll(epi->ffd.file))) {
 			ep_tovisit = epi->ffd.file->private_data;
-			if (ep_tovisit->visited)
+			if (ep_tovisit->gen == loop_check_gen)
 				continue;
 			error = ep_call_nested(&poll_loop_ncalls,
 					ep_loop_check_proc, epi->ffd.file,
@@ -2018,18 +2015,8 @@ static int ep_loop_check_proc(void *priv
  */
 static int ep_loop_check(struct eventpoll *ep, struct file *file)
 {
-	int ret;
-	struct eventpoll *ep_cur, *ep_next;
-
-	ret = ep_call_nested(&poll_loop_ncalls,
+	return ep_call_nested(&poll_loop_ncalls,
 			      ep_loop_check_proc, file, ep, current);
-	/* clear visited list */
-	list_for_each_entry_safe(ep_cur, ep_next, &visited_list,
-							visited_list_link) {
-		ep_cur->visited = 0;
-		list_del(&ep_cur->visited_list_link);
-	}
-	return ret;
 }
 
 static void clear_tfile_check_list(void)
@@ -2199,6 +2186,7 @@ int do_epoll_ctl(int epfd, int op, int f
 			error = epoll_mutex_lock(&epmutex, 0, nonblock);
 			if (error)
 				goto error_tgt_fput;
+			loop_check_gen++;
 			full_check = 1;
 			if (is_file_epoll(tf.file)) {
 				error = -ELOOP;
@@ -2262,6 +2250,7 @@ int do_epoll_ctl(int epfd, int op, int f
 error_tgt_fput:
 	if (full_check) {
 		clear_tfile_check_list();
+		loop_check_gen++;
 		mutex_unlock(&epmutex);
 	}
 



  parent reply	other threads:[~2020-10-05 15:35 UTC|newest]

Thread overview: 99+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-05 15:25 [PATCH 5.8 00/85] 5.8.14-rc1 review Greg Kroah-Hartman
2020-10-05 15:25 ` [PATCH 5.8 01/85] io_uring: always delete double poll wait entry on match Greg Kroah-Hartman
2020-10-05 15:25 ` [PATCH 5.8 02/85] btrfs: fix filesystem corruption after a device replace Greg Kroah-Hartman
2020-10-05 15:25 ` [PATCH 5.8 03/85] mmc: sdhci: Workaround broken command queuing on Intel GLK based IRBIS models Greg Kroah-Hartman
2020-10-05 15:26 ` [PATCH 5.8 04/85] USB: gadget: f_ncm: Fix NDP16 datagram validation Greg Kroah-Hartman
2020-10-05 15:26 ` [PATCH 5.8 05/85] Revert "usbip: Implement a match function to fix usbip" Greg Kroah-Hartman
2020-10-06 13:26   ` M. Vefa Bicakci
2020-10-07  9:13     ` Greg Kroah-Hartman
2020-10-08  8:56       ` M. Vefa Bicakci
2020-10-08  9:25         ` Greg Kroah-Hartman
2020-10-08  9:37           ` M. Vefa Bicakci
2020-10-05 15:26 ` [PATCH 5.8 06/85] usbcore/driver: Fix specific driver selection Greg Kroah-Hartman
2020-10-05 15:26 ` [PATCH 5.8 07/85] usbcore/driver: Fix incorrect downcast Greg Kroah-Hartman
2020-10-05 15:26 ` [PATCH 5.8 08/85] usbcore/driver: Accommodate usbip Greg Kroah-Hartman
2020-10-05 15:26 ` [PATCH 5.8 09/85] gpio: siox: explicitly support only threaded irqs Greg Kroah-Hartman
2020-10-05 15:26 ` [PATCH 5.8 10/85] gpio: mockup: fix resource leak in error path Greg Kroah-Hartman
2020-10-05 15:26 ` [PATCH 5.8 11/85] gpio: tc35894: fix up tc35894 interrupt configuration Greg Kroah-Hartman
2020-10-05 15:26 ` [PATCH 5.8 12/85] gpio: amd-fch: correct logic of GPIO_LINE_DIRECTION Greg Kroah-Hartman
2020-10-05 15:26 ` [PATCH 5.8 13/85] clk: samsung: Keep top BPLL mux on Exynos542x enabled Greg Kroah-Hartman
2020-10-05 15:26 ` [PATCH 5.8 14/85] clk: socfpga: stratix10: fix the divider for the emac_ptp_free_clk Greg Kroah-Hartman
2020-10-05 15:26 ` [PATCH 5.8 15/85] scsi: iscsi: iscsi_tcp: Avoid holding spinlock while calling getpeername() Greg Kroah-Hartman
2020-10-05 15:26 ` [PATCH 5.8 16/85] i2c: i801: Exclude device from suspend direct complete optimization Greg Kroah-Hartman
2020-10-05 15:26 ` [PATCH 5.8 17/85] Input: i8042 - add nopnp quirk for Acer Aspire 5 A515 Greg Kroah-Hartman
2020-10-05 15:26 ` [PATCH 5.8 18/85] iio: adc: qcom-spmi-adc5: fix driver name Greg Kroah-Hartman
2020-10-05 15:26 ` [PATCH 5.8 19/85] ftrace: Move RCU is watching check after recursion check Greg Kroah-Hartman
2020-10-05 15:26 ` [PATCH 5.8 20/85] tracing: Fix trace_find_next_entry() accounting of temp buffer size Greg Kroah-Hartman
2020-10-05 15:26 ` [PATCH 5.8 21/85] memstick: Skip allocating card when removing host Greg Kroah-Hartman
2020-10-05 15:26 ` [PATCH 5.8 22/85] drm/amdgpu: restore proper ref count in amdgpu_display_crtc_set_config Greg Kroah-Hartman
2020-10-05 15:26 ` [PATCH 5.8 23/85] xen/events: dont use chip_data for legacy IRQs Greg Kroah-Hartman
2020-10-05 15:26 ` [PATCH 5.8 24/85] clocksource/drivers/timer-gx6605s: Fixup counter reload Greg Kroah-Hartman
2020-10-05 15:26 ` [PATCH 5.8 25/85] vboxsf: Fix the check for the old binary mount-arguments struct Greg Kroah-Hartman
2020-10-05 15:26 ` [PATCH 5.8 26/85] mt76: mt7915: use ieee80211_free_txskb to free tx skbs Greg Kroah-Hartman
2020-10-05 15:26 ` [PATCH 5.8 27/85] libbpf: Remove arch-specific include path in Makefile Greg Kroah-Hartman
2020-10-05 15:26 ` [PATCH 5.8 28/85] drivers/net/wan/hdlc_fr: Add needed_headroom for PVC devices Greg Kroah-Hartman
2020-10-05 15:26 ` [PATCH 5.8 29/85] Revert "wlcore: Adding suppoprt for IGTK key in wlcore driver" Greg Kroah-Hartman
2020-10-05 15:26 ` [PATCH 5.8 30/85] drm/sun4i: mixer: Extend regmap max_register Greg Kroah-Hartman
2020-10-05 15:26 ` [PATCH 5.8 31/85] hv_netvsc: Cache the current data path to avoid duplicate call and message Greg Kroah-Hartman
2020-10-05 15:26 ` [PATCH 5.8 32/85] net: dec: de2104x: Increase receive ring size for Tulip Greg Kroah-Hartman
2020-10-05 15:26 ` [PATCH 5.8 33/85] rndis_host: increase sleep time in the query-response loop Greg Kroah-Hartman
2020-10-05 15:26 ` [PATCH 5.8 34/85] nvme-pci: disable the write zeros command for Intel 600P/P3100 Greg Kroah-Hartman
2020-10-05 15:26 ` [PATCH 5.8 35/85] nvme-core: get/put ctrl and transport module in nvme_dev_open/release() Greg Kroah-Hartman
2020-10-05 15:26 ` [PATCH 5.8 36/85] fuse: fix the ->direct_IO() treatment of iov_iter Greg Kroah-Hartman
2020-10-05 15:26 ` [PATCH 5.8 37/85] drivers/net/wan/lapbether: Make skb->protocol consistent with the header Greg Kroah-Hartman
2020-10-05 15:26 ` [PATCH 5.8 38/85] drivers/net/wan/hdlc: Set skb->protocol before transmitting Greg Kroah-Hartman
2020-10-05 15:26 ` [PATCH 5.8 39/85] mac80211: Fix radiotap header channel flag for 6GHz band Greg Kroah-Hartman
2020-10-05 15:26 ` [PATCH 5.8 40/85] mac80211: do not allow bigger VHT MPDUs than the hardware supports Greg Kroah-Hartman
2020-10-05 15:26 ` [PATCH 5.8 41/85] tracing: Make the space reserved for the pid wider Greg Kroah-Hartman
2020-10-05 15:26 ` [PATCH 5.8 42/85] tools/io_uring: fix compile breakage Greg Kroah-Hartman
2020-10-05 15:26 ` [PATCH 5.8 43/85] io_uring: mark statx/files_update/epoll_ctl as non-SQPOLL Greg Kroah-Hartman
2020-10-05 15:26 ` [PATCH 5.8 44/85] cpuidle: psci: Fix suspicious RCU usage Greg Kroah-Hartman
2020-10-05 15:26 ` [PATCH 5.8 45/85] spi: fsl-espi: Only process interrupts for expected events Greg Kroah-Hartman
2020-10-05 15:26 ` [PATCH 5.8 46/85] net: dsa: felix: fix some key offsets for IP4_TCP_UDP VCAP IS2 entries Greg Kroah-Hartman
2020-10-05 15:26 ` [PATCH 5.8 47/85] nvme-pci: fix NULL req in completion handler Greg Kroah-Hartman
2020-10-05 15:26 ` [PATCH 5.8 48/85] nvme-fc: fail new connections to a deleted host or remote port Greg Kroah-Hartman
2020-10-05 15:26 ` [PATCH 5.8 49/85] scripts/kallsyms: skip ppc compiler stub *.long_branch.* / *.plt_branch.* Greg Kroah-Hartman
2020-10-05 15:26 ` [PATCH 5.8 50/85] gpio: sprd: Clear interrupt when setting the type as edge Greg Kroah-Hartman
2020-10-05 15:26 ` [PATCH 5.8 51/85] phy: ti: am654: Fix a leak in serdes_am654_probe() Greg Kroah-Hartman
2020-10-05 15:26 ` [PATCH 5.8 52/85] pinctrl: mvebu: Fix i2c sda definition for 98DX3236 Greg Kroah-Hartman
2020-10-05 15:26 ` [PATCH 5.8 53/85] nfs: Fix security label length not being reset Greg Kroah-Hartman
2020-10-05 15:26 ` [PATCH 5.8 54/85] NFSv4.2: fix clients attribute cache management for copy_file_range Greg Kroah-Hartman
2020-10-05 15:26 ` [PATCH 5.8 55/85] pNFS/flexfiles: Ensure we initialise the mirror bsizes correctly on read Greg Kroah-Hartman
2020-10-05 15:26 ` [PATCH 5.8 56/85] clk: tegra: Always program PLL_E when enabled Greg Kroah-Hartman
2020-10-05 15:26 ` [PATCH 5.8 57/85] clk: tegra: Fix missing prototype for tegra210_clk_register_emc() Greg Kroah-Hartman
2020-10-05 15:26 ` [PATCH 5.8 58/85] dmaengine: dmatest: Prevent to run on misconfigured channel Greg Kroah-Hartman
2020-10-05 15:26 ` [PATCH 5.8 59/85] clk: samsung: exynos4: mark chipid clock as CLK_IGNORE_UNUSED Greg Kroah-Hartman
2020-10-05 15:26 ` [PATCH 5.8 60/85] scsi: target: Fix lun lookup for TARGET_SCF_LOOKUP_LUN_FROM_TAG case Greg Kroah-Hartman
2020-10-05 15:26 ` [PATCH 5.8 61/85] iommu/exynos: add missing put_device() call in exynos_iommu_of_xlate() Greg Kroah-Hartman
2020-10-05 15:26 ` [PATCH 5.8 62/85] gpio: pca953x: Fix uninitialized pending variable Greg Kroah-Hartman
2020-10-05 15:26 ` [PATCH 5.8 63/85] gpio/aspeed-sgpio: enable access to all 80 input & output sgpios Greg Kroah-Hartman
2020-10-05 15:27 ` [PATCH 5.8 64/85] gpio/aspeed-sgpio: dont enable all interrupts by default Greg Kroah-Hartman
2020-10-05 15:27 ` [PATCH 5.8 65/85] gpio: aspeed: fix ast2600 bank properties Greg Kroah-Hartman
2020-10-05 15:27 ` [PATCH 5.8 66/85] i2c: cpm: Fix i2c_ram structure Greg Kroah-Hartman
2020-10-05 15:27 ` [PATCH 5.8 67/85] i2c: npcm7xx: Clear LAST bit after a failed transaction Greg Kroah-Hartman
2020-10-05 15:27 ` [PATCH 5.8 68/85] Input: trackpoint - enable Synaptics trackpoints Greg Kroah-Hartman
2020-10-05 15:27 ` [PATCH 5.8 69/85] blk-mq: call commit_rqs while list empty but error happen Greg Kroah-Hartman
2020-10-05 15:27 ` [PATCH 5.8 70/85] scripts/dtc: only append to HOST_EXTRACFLAGS instead of overwriting Greg Kroah-Hartman
2020-10-05 15:27 ` [PATCH 5.8 71/85] autofs: use __kernel_write() for the autofs pipe writing Greg Kroah-Hartman
2020-10-05 15:27 ` [PATCH 5.8 72/85] pinctrl: qcom: sm8250: correct sdc2_clk Greg Kroah-Hartman
2020-10-05 15:27 ` [PATCH 5.8 73/85] pinctrl: mediatek: check mtk_is_virt_gpio input parameter Greg Kroah-Hartman
2020-10-05 15:27 ` [PATCH 5.8 74/85] gpio: pca953x: Correctly initialize registers 6 and 7 for PCA957x Greg Kroah-Hartman
2020-10-05 15:27 ` [PATCH 5.8 75/85] iommu/amd: Fix the overwritten field in IVMD header Greg Kroah-Hartman
2020-10-05 15:27 ` [PATCH 5.8 76/85] pipe: remove pipe_wait() and fix wakeup race with splice Greg Kroah-Hartman
2020-10-05 15:27 ` [PATCH 5.8 77/85] random32: Restore __latent_entropy attribute on net_rand_state Greg Kroah-Hartman
2020-10-05 15:27 ` [PATCH 5.8 78/85] gpiolib: Fix line event handling in syscall compatible mode Greg Kroah-Hartman
2020-10-05 15:27 ` [PATCH 5.8 79/85] drm/i915/gvt: Fix port number for BDW on EDID region setup Greg Kroah-Hartman
2020-10-05 15:27 ` [PATCH 5.8 80/85] scsi: sd: sd_zbc: Fix handling of host-aware ZBC disks Greg Kroah-Hartman
2020-10-05 15:27 ` [PATCH 5.8 81/85] scsi: sd: sd_zbc: Fix ZBC disk initialization Greg Kroah-Hartman
2020-10-05 15:27 ` [PATCH 5.8 82/85] epoll: do not insert into poll queues until all sanity checks are done Greg Kroah-Hartman
2020-10-05 15:27 ` Greg Kroah-Hartman [this message]
2020-10-05 15:27 ` [PATCH 5.8 84/85] epoll: EPOLL_CTL_ADD: close the race in decision to take fast path Greg Kroah-Hartman
2020-10-05 15:27 ` [PATCH 5.8 85/85] ep_create_wakeup_source(): dentry name can change under you Greg Kroah-Hartman
2020-10-06  0:18 ` [PATCH 5.8 00/85] 5.8.14-rc1 review Shuah Khan
2020-10-07  9:12   ` Greg Kroah-Hartman
2020-10-06  5:27 ` Naresh Kamboju
2020-10-07  9:12   ` Greg Kroah-Hartman
2020-10-06  8:58 ` Jeffrin Jose T
2020-10-06  9:12 ` Jeffrin Jose T
2020-10-06 18:18 ` Guenter Roeck
2020-10-07  9:11   ` Greg Kroah-Hartman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201005142118.726966971@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).