Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp9089500pxu; Mon, 28 Dec 2020 06:22:44 -0800 (PST) X-Google-Smtp-Source: ABdhPJzPdrREDpfKxbQWuRBbKUINTw321SmV+bG9yeeflcxD6LXD6hOLKcwMm/BV46oPzuFHlxXc X-Received: by 2002:a05:6402:c0b:: with SMTP id co11mr41640699edb.180.1609165364431; Mon, 28 Dec 2020 06:22:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609165364; cv=none; d=google.com; s=arc-20160816; b=0+JFx2Bvt/9mAwz+OaVpmowKybgwIamLyeqYqcXUdYuLc6itZunnHMBMs5RXfIOLnW /AeIFwPrRJJz8in/y9IaFb/8tnKnCGA5L67hbJSKw238UoRyyiI0rWnJBqSgt52gmsFF hxH14w+DyAXZhWARXke8/icK9j1QJRm1Jd0JMa/AY9I3HpwO+ZT41rCDOjbr0Z140nHm dNAv+NJZmG9CaT4qVKoe1B8UJDk7Q0+om8DP1S4cHcSOSjWVytmHwoTl8e4vHWCbRgyo 8HOgdaHkFM3E8zqt0owrie+tQ/q3j8Oor66zI46LWCalYcs7bdcrJESinzfEWrV/COe4 G2bA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=GcJbYHiD7Mjdqe16yTUxpSPiYpC/jvmNJyfqbSRLDYE=; b=lhWLACaKixVcSqaew70STl90RIAal934dmLOr27pDvwwo5VXFIMhZQS+e9IFRW4ihP DmSwBasUI0TaCxlh2QFgkIoD+Nfp26wO1PQu7zSEHaKEF+AIFpxVAZAOdTw+XN0KCWI4 8KMT4NZm+XEEjU2dKItb+PW8DYbhS87Wg0904KDAPcFFSK5Of3XWg6589c4XcS5MjkyZ Xp2b5EeX1TMYgdYhWqeZK+sWWkLc4SGPrPuChjPezHGRufROwlXJht1lTIhz/a3wHLxM +j0SbIP8X4bgZT7re+pNkzZckFZP70cyfNQl9oAM3Fstjhg/A09O+irdXGyoBaCvoqWo f/iQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=NUpX2Oei; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y2si18174682ejw.525.2020.12.28.06.22.21; Mon, 28 Dec 2020 06:22:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=NUpX2Oei; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2437774AbgL1OU1 (ORCPT + 99 others); Mon, 28 Dec 2020 09:20:27 -0500 Received: from mail.kernel.org ([198.145.29.99]:55670 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2437756AbgL1OUV (ORCPT ); Mon, 28 Dec 2020 09:20:21 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 861D2206E5; Mon, 28 Dec 2020 14:19:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1609165175; bh=4X371F7lEJI/Lc7h9xUNP6ceNwUzEUDsuASy1FPiDHE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NUpX2OeicOGSIo/+sk1S2H/HHMWH7ZHozpsdKYThpP+kLsU+WTcULAQChhvz/YKoS jBAy3IUb1OfTJnM8beWDiCELSYb+uYk4Fgh8dV9qYgZI/sWTqEOWJOEGaOKtPnkatN zY0RJWubeXHya35n4h7Vi+xkIVuG25Ofjs38SiVU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Magnus Karlsson , Daniel Borkmann , Sasha Levin Subject: [PATCH 5.10 411/717] samples/bpf: Fix possible hang in xdpsock with multiple threads Date: Mon, 28 Dec 2020 13:46:49 +0100 Message-Id: <20201228125040.666742163@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201228125020.963311703@linuxfoundation.org> References: <20201228125020.963311703@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Magnus Karlsson [ Upstream commit 092fde0f863b72b67c4d6dc03844f5658fc00a35 ] Fix a possible hang in xdpsock that can occur when using multiple threads. In this case, one or more of the threads might get stuck in the while-loop in tx_only after the user has signaled the main thread to stop execution. In this case, no more Tx packets will be sent, so a thread might get stuck in the aforementioned while-loop. Fix this by introducing a test inside the while-loop to check if the benchmark has been terminated. If so, return from the function. Fixes: cd9e72b6f210 ("samples/bpf: xdpsock: Add option to specify batch size") Signed-off-by: Magnus Karlsson Signed-off-by: Daniel Borkmann Link: https://lore.kernel.org/bpf/20201210163407.22066-1-magnus.karlsson@gmail.com Signed-off-by: Sasha Levin --- samples/bpf/xdpsock_user.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/samples/bpf/xdpsock_user.c b/samples/bpf/xdpsock_user.c index 1149e94ca32fd..33c58de58626c 100644 --- a/samples/bpf/xdpsock_user.c +++ b/samples/bpf/xdpsock_user.c @@ -1250,6 +1250,8 @@ static void tx_only(struct xsk_socket_info *xsk, u32 *frame_nb, int batch_size) while (xsk_ring_prod__reserve(&xsk->tx, batch_size, &idx) < batch_size) { complete_tx_only(xsk, batch_size); + if (benchmark_done) + return; } for (i = 0; i < batch_size; i++) { -- 2.27.0