From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.210.46 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796512377; b=F86yaVKpG36+vf1eZfY6ihMBsS/KOGjqu9HyiJPjg3CxHefPvOl5YPPKAE/BC2Rds0Yh vH0vvL3qac8Foi0Z7NKgL+VTXDn9vomFTW08sV4LlhI1zZ32HJolsZXyCpZ8GR9nlXNDS eCGzioiL1zLa525Uzmo1c5rcJ90IWZjpWgnuuaVKT8C81qXhu2mInldIqRGggoy1f5Pho JROl4orokB6tVeYiG/UZ8lvfUKLHS9aR4pdcwL8IxAL8f56ip7i5SX/uVH3gexVwe44iF 7ZNAv3SWVR0d7vYKzdpbNLFUtFH1IaGHtAOHXb7YhZPzaMxT7XMrzQiQoz5/o6TjlrA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796512377; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Gm-Gg:X-Received:Received:From:To:Cc:Subject: Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=f9+0A7EthAJCf/vHofXAhWYGoijc5zlEg4EglnlGnLE=; b=B90WPitTccWuforZDkYJIBuheDMzE/1EnKEsV6lm/OCKDc+iGc99FCSUCTP0X656bLpA stxYCwi4WisaoRijFc1jeTwGrGUDDCQIyPu0wi9YVYsi5OLpjyFZ5ma7pAhluSGyhtXtk kibwKI/bVyt5/0hBiXKEOGMthT77A3yxagyNzDohHKA6JemvVCg3Jt0mHODkZlw/47EHs nbG6EddA8y1fbPXwGX27vm/wpkmQieAcE6KrUB1BEOAjmXZC5tiJ2i3wu3wcEb0vjNhTZ XCrhfJQKtOxAoJpBza/lwKPeVTQyhxlhbYr8hYs1qAao5BBXSpRcJMOjDgCAiE4/YhQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=kernel.dk; spf=pass smtp.mailfrom=kernel.dk; dkim=pass header.d=kernel.dk header.i=@kernel.dk header.a=rsa-sha256 header.s=google header.b=RpKddfFV; arc=none smtp.remote-ip=209.85.210.46 Received: from mail-ot1-f46.google.com (mail-ot1-f46.google.com [209.85.210.46]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DEE32606A32F for ; Sat, 5 Dec 2026 23:12:56 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org DEE32606A32F Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=kernel.dk Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kernel.dk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.dk header.i=@kernel.dk header.a=rsa-sha256 header.s=google header.b=RpKddfFV Received: by mail-ot1-f46.google.com with SMTP id 46e09a7af769-8451a619da7so1452624a34.1 for ; Sat, 05 Dec 2026 15:12:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.dk; s=google; t=1796512376; x=1797117176; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=f9+0A7EthAJCf/vHofXAhWYGoijc5zlEg4EglnlGnLE=; b=RpKddfFVTxymWh9f8NXMXUB7XUDTs1m+7YZnGripGj0cMS1q4coPfGGHVArYR0XXpM 8fUnGFEHjLSW1dNyq84vMjiS0BMHsDKRTyTFfUpLzMkIv/xPq+qsOgwBkSz7zOuBXLpd QWoUAbVoMdxJbbzhgjZq3pD3lfefcyaUB80KTj4ly4m7h07qf1BDP0dB4ZfoJY8PTn+f MXCOAmimVuUZiTcFuNG2ke9PO/bVHqnOR5iHaNTsWls3ZetZHFcVyIthEwVXgoeu/7vt Q/aHiBICfHAGbbXhw6fBaujDXNRxf8ntGtCjb5vR2aZ3ecvVaZCzdYRwlT3FWDlu95gL caLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796512376; x=1797117176; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=f9+0A7EthAJCf/vHofXAhWYGoijc5zlEg4EglnlGnLE=; b=bajliM1v6BXPnX0CiI7ucpmde4ZeA7INhhcxTPrxezmcjXOir1TXXWNA84/zLHg+OT JnAFQX2QeMfKf2U3DEZeZWVd+qerPsXczt7au2P4sLhd/k3hVl05IlGDSRm/mIKwp9lD qX33GvurXLuk8byetAVpS1d0MDOZ67zSISIOnHHAcD9EdJw8tixzB7sfInELIBxocSMH lwJXhin0A6E+ftvsKlHcV6LRQbUcnnyipeMaDdRXA3Xqw3T1+A4xsaeVrHWZKeaKemAH dw4PUATp0RTKTbVeuByTQwyH4S+HzYyBxi3TWWH47EexcBT2G8X4OLldeOfJL0lMqs/b qAAA== X-Gm-Message-State: APuU4Z9bazw0wl7skj+13sDjvPfWJC1HjZwvBaLB8p+Tlb4J4PBndFzX msAW79Blg8ZugdGBH4FyhYstnoawAZDStOn4Ay+qE8lowZhA6e2ioiQ1dgDNWeO99GvsCLfNnoE lKQFgA4A= X-Gm-Gg: AZFdTZe/dXifktvSaP4dHijltr8do1011Te6kUXOhkd9z6XaaroCC1JVM+6GJ/iU9qT lWWCpewfHClQuvR97Pu7oR5Fm3pCA918ahb6hVWzAq/ME2Oe1DjnAuYDb60HicDsdF3oJAIk8RW doNZgrDhiowXcVfao/3vIe6GoGagsHVJnUhm1gpP7CDCQXUc3Gy9djUgdDaSh42GL8KOspSBI/g gwaQ9NGbWHpwwF2q9KlwGw36ikasIFskB+p4wzUeOBspEdbyt3iZmvDXypKH7oHdV2/ozg36Ou2 v3nLMy2uOcvr6qO7Sd+Pzj98+gsbYQc/Fuh2fLIiI+VHsuQjOY4m6kCH0e/VICI6JUNpev7PLF8 RLmnzv5nzC5q9/cUukzO4o11bVqk2koClLCRLHz2uC9lbExxtSxMsROhEwfbSoFjWgxmcz64UJ/ eMWvX/80J9JAJQG+0WUdaGWvuSlD/xjUAcnwxDIDowyw7CORyt9SA5fPgvytmbnKIzQtZydxCg/ mfKYEiE503olumDWY73kFL1ARSnDo7Z0WmHkOOlsoo0Pw63Pt/k307lU0GAiLJBHffJkgZBalvQ dvMpXP1DdF1WYs8vJhc66f6sbi+hc1l3uLr+p9uk87S5hbiIY+MyXAfRjgvipKiNHUaZTZcysIn 8FSrFaol00EUsqzzTmiWjfmz7qGP3WJiFFMeL X-Received: by 2002:a05:6830:4c02:b0:862:ca2e:918a with SMTP id 46e09a7af769-863f89bfcf3mr7095225a34.19.1796512375927; Sat, 05 Dec 2026 15:12:55 -0800 (PST) Received: from r7625 ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-863f7dd42a8sm6279788a34.0.2026.12.05.15.12.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Dec 2026 15:12:55 -0800 (PST) From: Jens Axboe To: stable@vger.kernel.org Cc: io-uring@vger.kernel.org, gregkh@linuxfoundation.org Subject: [PATCH 6.6.y 12/13] io_uring: close poll activation race when enabling rings Date: Sat, 5 Dec 2026 23:12:32 +0000 Message-ID: <20261205231233.4140988-13-axboe@kernel.dk> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20261205231233.4140988-1-axboe@kernel.dk> References: <20261205231233.4140988-1-axboe@kernel.dk> X-Mailing-List: io-uring@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Andrea Parri Commit e20a070b2a2ba35411251850c8969c1ac1838433 upstream. An epoll waiter can hang with completions pending when polling a disabled SINGLE_ISSUER ring races with IORING_REGISTER_ENABLE_RINGS: CPU0 CPU1 ---- ---- io_activate_pollwq() submitter_task == NULL submitter_task = current wq_has_sleeper() == false poll_wait() Neither side retries the activation. The activation flag remains clear, so completion and deferred task work paths skip poll_wq wakeups. Cure this by registering the poll waiter before trying to activate poll_wq. The full barrier in poll_wait() pairs with the barrier in wq_has_sleeper(), which ensures that either the poller observes submitter_task or the ring enable path observes the waiter. Tested in a 2-vCPU x86-64 KVM guest with a reproducer that races EPOLL_CTL_ADD on a disabled ring against IORING_REGISTER_ENABLE_RINGS. v7.4-rc5 missed the wakeup in each of three runs, at iterations 177, 505 and 26826. With this patch, three runs of 100000 iterations passed. The bug was found with the help of an LLM, which was also used to write the fix, the changelog and the tests. Fixes: bca39f390585 ("io_uring: add lazy poll_wq activation") Cc: stable@vger.kernel.org Signed-off-by: Andrea Parri Link: https://patch.msgid.link/20261204174710.131485-1-parri.andrea@gmail.com Signed-off-by: Jens Axboe [axboe: 6.6 has ctx->poll_activated rather than IO_RING_F_POLL_ACTIVATED in ctx->int_flags] --- io_uring/io_uring.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c index 11f7679eba60..0f5b7ce5f618 100644 --- a/io_uring/io_uring.c +++ b/io_uring/io_uring.c @@ -3200,13 +3200,14 @@ static __poll_t io_uring_poll(struct file *file, poll_table *wait) struct io_ring_ctx *ctx = file->private_data; __poll_t mask = 0; - if (unlikely(!ctx->poll_activated)) - io_activate_pollwq(ctx); /* - * provides mb() which pairs with barrier from wq_has_sleeper - * call in io_commit_cqring + * The poll_wait() barrier pairs with wq_has_sleeper() on the CQ + * wakeup and ring enable paths. */ poll_wait(file, &ctx->poll_wq, wait); + /* A stale flag only causes a redundant activation attempt. */ + if (unlikely(!ctx->poll_activated)) + io_activate_pollwq(ctx); if (!io_sqring_full(ctx)) mask |= EPOLLOUT | EPOLLWRNORM; -- 2.55.0