From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 77B6D8827; Mon, 23 Dec 2024 16:17:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734970624; cv=none; b=u9X3zJp9KByKtBL01pPeLq0+L8RmvLewAGG7ehXXWlwKQIFZSoarbBvR8DTj2BNMNNGlx7QD/kXoRUElLi9di4DeaxW2mUzxhhsk6Jl0HPmEGYWip47Hg9rCoA4FtRnurLJikrfCXgSCfxsAKN13FmT8krLJy3/VBmm3qyh/DCw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734970624; c=relaxed/simple; bh=f44IOrbwDtJJXnE1grl98VTcoxX2Ho9f0hALF76TW6Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=V66voXo8ofNIOgCbcyJUCcuv1msjhaQqoHW37A921GTYG3/JIxAv+YYWJXhhe5u475xo7p88ZIugtQv9VaAnDhoDjNeaUbX7dR2Us+xL2RseT26j5h6ow0yBabc4AM16lMvsBodqkixleOOX8PYApnx7S4JodejRfpBolb+L/kw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=qHQ+hRr5; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="qHQ+hRr5" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E2FACC4CED3; Mon, 23 Dec 2024 16:17:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1734970624; bh=f44IOrbwDtJJXnE1grl98VTcoxX2Ho9f0hALF76TW6Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qHQ+hRr5JhntSF2FaWxFCzWhhdlzIr8Ud44ruB887VkLgU3isWYTxRg+2WR+bA4tS y2f/vX0oYbBd8EIZH7rfOe+u3NZroVnh93NE+aICgYa5ocIwR3Zk94/tXyTSSDdTfd vP4ss6H4qIE7z/lPb0wok4zLduJO3qR5mTkdTaGA= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Guangguan Wang , Paolo Abeni , "David S. Miller" , Sasha Levin Subject: [PATCH 6.1 20/83] net/smc: check sndbuf_space again after NOSPACE flag is set in smc_poll Date: Mon, 23 Dec 2024 16:58:59 +0100 Message-ID: <20241223155354.413810252@linuxfoundation.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241223155353.641267612@linuxfoundation.org> References: <20241223155353.641267612@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Guangguan Wang [ Upstream commit 679e9ddcf90dbdf98aaaa71a492454654b627bcb ] When application sending data more than sndbuf_space, there have chances application will sleep in epoll_wait, and will never be wakeup again. This is caused by a race between smc_poll and smc_cdc_tx_handler. application tasklet smc_tx_sendmsg(len > sndbuf_space) | epoll_wait for EPOLL_OUT,timeout=0 | smc_poll | if (!smc->conn.sndbuf_space) | | smc_cdc_tx_handler | atomic_add sndbuf_space | smc_tx_sndbuf_nonfull | if (!test_bit SOCK_NOSPACE) | do not sk_write_space; set_bit SOCK_NOSPACE; | return mask=0; | Application will sleep in epoll_wait as smc_poll returns 0. And smc_cdc_tx_handler will not call sk_write_space because the SOCK_NOSPACE has not be set. If there is no inflight cdc msg, sk_write_space will not be called any more, and application will sleep in epoll_wait forever. So check sndbuf_space again after NOSPACE flag is set to break the race. Fixes: 8dce2786a290 ("net/smc: smc_poll improvements") Signed-off-by: Guangguan Wang Suggested-by: Paolo Abeni Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- net/smc/af_smc.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/net/smc/af_smc.c b/net/smc/af_smc.c index 868e722aef06..aeeb6e62361f 100644 --- a/net/smc/af_smc.c +++ b/net/smc/af_smc.c @@ -2789,6 +2789,13 @@ static __poll_t smc_poll(struct file *file, struct socket *sock, } else { sk_set_bit(SOCKWQ_ASYNC_NOSPACE, sk); set_bit(SOCK_NOSPACE, &sk->sk_socket->flags); + + if (sk->sk_state != SMC_INIT) { + /* Race breaker the same way as tcp_poll(). */ + smp_mb__after_atomic(); + if (atomic_read(&smc->conn.sndbuf_space)) + mask |= EPOLLOUT | EPOLLWRNORM; + } } if (atomic_read(&smc->conn.bytes_to_rcv)) mask |= EPOLLIN | EPOLLRDNORM; -- 2.39.5