From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A820D3C9EDD for ; Mon, 4 May 2026 12:00:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.44 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777896043; cv=none; b=m10C+LQ90mfsmZBEWEIczf02PQ8R7l3IjFkgWpr3YnwQ/lWZ/H0ZGLlMFnrl/VWuP1yB3KqcNFfF/XBd/0plIC6QRfglYJnt9fB6IJvhxvg8UIM9POUSOVOZQKFP6+Y3bFEW07pWD+jrX2Fgk3GI78esgv8QkVXtkzbbGRi0F/o= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777896043; c=relaxed/simple; bh=Hl3CwSSKFL604+Bs52WMEy2/aMMaTyXNZKZlz0sf9iA=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=qx5ujBu1vcklO+Q2qiacp4nn6/vGwlirIqVbAnu8Fs0kJp9n/1Q0uBq7QIlvBvC/ulajcv6654rso7xGXi8NDk0sJ+dhhi1kCNKWhwyMlQwv3hDZyXgzKD+VWwTKrPrwUzGGKfiJmNMVhfENlzI5bUKIIPBgNaN25VaxQbs/nME= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=kRJ6xEPm; arc=none smtp.client-ip=209.85.128.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="kRJ6xEPm" Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-488a88aeec9so45090615e9.2 for ; Mon, 04 May 2026 05:00:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1777896037; x=1778500837; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=beppBlc4z/k/6sDHwfuJF7187wKyaJgaXtM+Bj5I6v4=; b=kRJ6xEPm4QqWIMTF0bieG4cV+jLdCh3jcgxRsQruyr1P/UJXX5oimOoVJnPGlfMDGS jSoCtkxnz5MpdfcRRzOFPqLdIgcozOHYp8zStoih7mKIk5xOKYG4KGHryHx5/fWpt9pK 3j9hXR0lXPV9BqMYF1vP0Zn97pHeydG8rf4tOT8oFAF/mb/pmewLu3CACu63IRcle3uS nR3AtuOn2ck344rTwuQinDkzgHz4lZwQKt0BnGIWJR0+uOMS+u/x39oeM+TsAZaSg3wt wmJCwdu6D7D1t/Nn089kDRInzIguNSm3uHCDlvFVJDgbV5uUYWXfy6OHwbsx2ag1qm7G vSlA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777896037; x=1778500837; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=beppBlc4z/k/6sDHwfuJF7187wKyaJgaXtM+Bj5I6v4=; b=CH9iPONOvxWTd9MaPTROUPG9fhqIgbtnbExQeN1kF5eHFR6gIMO5wf1oqhsJMNWvw0 pD6LoaWcTRjp5JbwQdk5ATwOW8JUl/oHHYRY+3UFGePeTZmwb1zv4YHO6lKrwhm08LnH r2SM1GhDuIv7DqM05xKNPbR4vYzifaxtjwL6+U4KPcpv7NVRt3gccc0Em0APC1dTrY/s TfbnUpNA6dGazKdB03wnDZs6Yaqbs+1Jua5ObBJxHFXbyem/44fqGTfBRbmeeNI2WORM RaDF6HQqNS8BKysaKJb9ERa20wB+7rdrHs6MU1C/R0BIeM0L3Un1/Q41LoQ/M/C2GrYx Ouqg== X-Forwarded-Encrypted: i=1; AFNElJ+EmjkXqxRl6vYrmviQxaxvj3DBQu/AHKLiC8nvnH2yl7HNz7YU/AmGT7fcA1NDgYGsiU+cTNaLbz7NpJQ=@vger.kernel.org X-Gm-Message-State: AOJu0Yxa33bVHv71t7HZHlCa+MQ4k8y9HU847BfTvEYwDZ3bWrPV6Ngv HEgRz1wGHfdB0UObDsbZ7qxcIiOxWK8kCbICV3Z+2LunQ3utOGowe//t X-Gm-Gg: AeBDietzvkbYixgzlcoZC2jqOjaFIwumO7me2zg7ijtl3Xu5b6fPl0s3LvzmnM+nHN2 a/8wqusVRz2OcLaRos4ylW289qwjLCUzSQM7U+21Gaxzy7PflAGPUCs0U+t7njKNB9uOxtmvE2U npcMrl7TU7+fLtqfzUSeYhot66V4oJPMCGa8ST/1P9a7WWZRZk45gwsG0bVTE7wUoBniBC9cMBB nmnxmb1kPkyRBc7ZDCRAIhWlyQLy81OzHUsTUxx4ULOw01ToTfcmsTV3aUgo2o1v2/ISRjQpRQb klsEgN02CW02tHhgy4wHCKs5bq31jmOX4DatKe+U8G0OYIPNHDu9ePIcuQKpk4bzNHcz9PCkTFo 6OWvJbt7G5EvW+e4lHVcmFUCZBaKsm59oUKNeMnrYzo3mOvEhqoy81cYUDofUOVbWKy29VbfVBh X3NOQw/6RVe2ln0vK4D8o4YV3e07UmxsXJmxAtGJcYJd1xrLwiYOpImW+Wrda0Cm9FDAkCdL/oE yLhlLVPnrg0HA== X-Received: by 2002:a05:600c:8b04:b0:485:40db:d40c with SMTP id 5b1f17b1804b1-48a9852f332mr148382325e9.3.1777896032816; Mon, 04 May 2026 05:00:32 -0700 (PDT) Received: from pumpkin (82-69-66-36.dsl.in-addr.zen.co.uk. [82.69.66.36]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-48a8ebb2fa5sm230452445e9.12.2026.05.04.05.00.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 May 2026 05:00:31 -0700 (PDT) Date: Mon, 4 May 2026 13:00:27 +0100 From: David Laight To: Christian Brauner Cc: Nam Cao , Soheil Hassas Yeganeh , Alexander Viro , Jan Kara , Shuah Khan , Davidlohr Bueso , Khazhismel Kumykov , Willem de Bruijn , Eric Dumazet , Jens Axboe , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, stable@vger.kernel.org Subject: Re: [PATCH 2/2] eventpoll: Fix epoll_wait() report false negative Message-ID: <20260504130027.50040ce6@pumpkin> In-Reply-To: <20260429-november-speisen-3084d769d316@brauner> References: <43d64ad765e2c47e958f01246320359b11379466.1752824628.git.namcao@linutronix.de> <20250718085948.3xXGcxeQ@linutronix.de> <20260429-november-speisen-3084d769d316@brauner> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; arm-unknown-linux-gnueabihf) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Wed, 29 Apr 2026 08:54:06 +0200 Christian Brauner wrote: > On Fri, Jul 18, 2025 at 10:59:48AM +0200, Nam Cao wrote: > > On Fri, Jul 18, 2025 at 09:38:27AM +0100, Soheil Hassas Yeganeh wrote: = =20 > > > On Fri, Jul 18, 2025 at 8:52=E2=80=AFAM Nam Cao wrote: =20 > > > > > > > > ep_events_available() checks for available events by looking at ep-= >rdllist > > > > and ep->ovflist. However, this is done without a lock, therefore the > > > > returned value is not reliable. Because it is possible that both ch= ecks on > > > > ep->rdllist and ep->ovflist are false while ep_start_scan() or > > > > ep_done_scan() is being executed on other CPUs, despite events are > > > > available. > > > > > > > > This bug can be observed by: > > > > > > > > 1. Create an eventpoll with at least one ready level-triggered ev= ent > > > > > > > > 2. Create multiple threads who do epoll_wait() with zero timeout.= The > > > > threads do not consume the events, therefore all epoll_wait() = should > > > > return at least one event. > > > > > > > > If one thread is executing ep_events_available() while another thre= ad is > > > > executing ep_start_scan() or ep_done_scan(), epoll_wait() may wrong= ly > > > > return no event for the former thread. =20 > > >=20 > > > That is the whole point of epoll_wait with a zero timeout. We would w= ant to > > > opportunistically poll without much overhead, which will have more > > > false positives. > > > A caller that calls with a zero timeout should retry later, and will > > > at some point observe the event. =20 > >=20 > > Is this a documented behavior that users expect? I do not see this in t= he > > man page. =20 >=20 > The selftests rely on this behavior that timeout=3D0 sees events from a > concurrently running producer. They would fail at a very higher rate > after this change - believe me I had a similar patch that changed > something in this area. I would explore the seqcount that Mateusz > suggested tbh. >=20 Does this scenario really affect any real programs? It doesn't make sense to have multiple threads looking for level-triggered events on a single epoll fd. When epoll returns an event you really need to do a (usually) read on the associated file descriptor before calling epoll again. To split the epoll processing between multiple threads you need lots of epoll fd with the underlying fd distributed between them and get the threads to process the epoll fd sequentially (eg by putting the fd in an array and using an atomic increment of a global array index to get the next epoll fd to process). -- David