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 38C1EC4363A for ; Tue, 27 Oct 2020 00:04:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 01F3120882 for ; Tue, 27 Oct 2020 00:04:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603757058; bh=xXQCAi1UanTxXmdmTXNwci+zWfS1jsM/sBq4Gzk2pFY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=abEQyiBQoj2PKdQXZG1kteThKYyyjCkLtlSp9uJfkyv/leKG9IAheamFluiCJjkBm +kj1Mo69yVNbX/BNAxVue8BV/mwU7kqARZQ8NFauFT6Adp56YvFMptFdEbIk6LgD9C lMZDlqyZrhcE5fb5jGVtoRDrof+6D/HxbKOm78aQ= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2437597AbgJ0AEG (ORCPT ); Mon, 26 Oct 2020 20:04:06 -0400 Received: from mail.kernel.org ([198.145.29.99]:35182 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2411017AbgJZX4A (ORCPT ); Mon, 26 Oct 2020 19:56:00 -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 326CA22202; Mon, 26 Oct 2020 23:55:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603756559; bh=xXQCAi1UanTxXmdmTXNwci+zWfS1jsM/sBq4Gzk2pFY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BlGwyHU8vUZjhbt0rqJ/G4w4PQpxbbbS60VrFztXa30uOsO2aCw+M4StsHT3giiLt AwCF0AFygKj0kYhJFWoqoefZDvj9w8auNW8AgMXM1rdW6aZyBhxyU5KKSKoFyk205D +jMPl3/BP3cuYluMs/UloOptjyv0QLOOGUkDm0eI= 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.4 35/80] samples/bpf: Fix possible deadlock in xdpsock Date: Mon, 26 Oct 2020 19:54:31 -0400 Message-Id: <20201026235516.1025100-35-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201026235516.1025100-1-sashal@kernel.org> References: <20201026235516.1025100-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: linux-kernel@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 df011ac334022..79d1005ff2ee3 100644 --- a/samples/bpf/xdpsock_user.c +++ b/samples/bpf/xdpsock_user.c @@ -677,6 +677,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