From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D5E41C6379D for ; Tue, 27 Oct 2020 00:46:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A8F1F216FD for ; Tue, 27 Oct 2020 00:46:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603759567; bh=BIP6Ywvq2AJS2Oz7ARKJM4JshElUyl/dKPhlquHf2qM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=U4z5cz/Qw29nL/dZNcr8aaRevXPL2V+7PQbWx9zIaaD2pgmWgqAc7b2mLqaVguzEN Erh8is1/dXPiNZrAYoqDfKv2oGbvREjk32CB9dD4TFU15T8mDPZYXsVU86o1XBLViF 5mVmOYzjSkTxuv7xSMEPh1Xinn3Z4IDcUI6gwSkI= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2502394AbgJ0Anz (ORCPT ); Mon, 26 Oct 2020 20:43:55 -0400 Received: from mail.kernel.org ([198.145.29.99]:49976 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2409124AbgJZXub (ORCPT ); Mon, 26 Oct 2020 19:50:31 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 7F1CC20874; Mon, 26 Oct 2020 23:50:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603756231; bh=BIP6Ywvq2AJS2Oz7ARKJM4JshElUyl/dKPhlquHf2qM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WzOsG6cgwPxLccrZ4c9etEyFX/B4h6PUNc+1cxzoCxWx3k5MWAeCL13sgn9Q3lmZ+ BhSYspZIqenfRcvXH3ga/vNIiYsODz/D2o/nM5iy/YziK0nkmz7ODcufiWHN+SVNnC PqmFgn7kDfNVQ6ts0NTIgXacgIL4ExsFraGvv37k= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Magnus Karlsson , Alexei Starovoitov , Sasha Levin , netdev@vger.kernel.org, bpf@vger.kernel.org Subject: [PATCH AUTOSEL 5.9 069/147] samples/bpf: Fix possible deadlock in xdpsock Date: Mon, 26 Oct 2020 19:47:47 -0400 Message-Id: <20201026234905.1022767-69-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201026234905.1022767-1-sashal@kernel.org> References: <20201026234905.1022767-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org From: Magnus Karlsson [ Upstream commit 5a2a0dd88f0f267ac5953acd81050ae43a82201f ] Fix a possible deadlock in the l2fwd application in xdpsock that can occur when there is no space in the Tx ring. There are two ways to get the kernel to consume entries in the Tx ring: calling sendto() to make it send packets and freeing entries from the completion ring, as the kernel will not send a packet if there is no space for it to add a completion entry in the completion ring. The Tx loop in l2fwd only used to call sendto(). This patches adds cleaning the completion ring in that loop. Signed-off-by: Magnus Karlsson Signed-off-by: Alexei Starovoitov Link: https://lore.kernel.org/bpf/1599726666-8431-3-git-send-email-magnus.karlsson@gmail.com Signed-off-by: Sasha Levin --- samples/bpf/xdpsock_user.c | 1 + 1 file changed, 1 insertion(+) diff --git a/samples/bpf/xdpsock_user.c b/samples/bpf/xdpsock_user.c index 19c679456a0e2..ffb61d4bb93e9 100644 --- a/samples/bpf/xdpsock_user.c +++ b/samples/bpf/xdpsock_user.c @@ -1111,6 +1111,7 @@ static void l2fwd(struct xsk_socket_info *xsk, struct pollfd *fds) while (ret != rcvd) { if (ret < 0) exit_with_error(-ret); + complete_tx_l2fwd(xsk, fds); if (xsk_ring_prod__needs_wakeup(&xsk->tx)) kick_tx(xsk); ret = xsk_ring_prod__reserve(&xsk->tx, rcvd, &idx_tx); -- 2.25.1