Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp951072pxb; Wed, 6 Apr 2022 05:09:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxKhSlLkrp0Il/J1CS9WTsCRy4iavU0aztEV/eqNrLuRMixLVHkddpOuYuRS+FCV8AJHHa/ X-Received: by 2002:a17:90a:9416:b0:1ca:9cff:7877 with SMTP id r22-20020a17090a941600b001ca9cff7877mr9631848pjo.141.1649246955124; Wed, 06 Apr 2022 05:09:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649246955; cv=none; d=google.com; s=arc-20160816; b=BAhWNqJH3LUY5uifO3+XjqO5H1q7XdjSZ8kd1K+uwY9RDxBKokhMakrHqv1H7QFgEj lSo5nSDWs078jPbgt5YNjduehmcHdg0yJK+QaViKD6fbBBKwnwLTmEktQVUpQJK1iLzk Lgcysorf7Rv5t7QdTYvd15Trw41H/IwR0xLnPJm3reCt23TI6+dPzpzAkKUCIuPrbUCZ n39ZXWxfapx3dQa313lxA/3+6pe2Ihtf//7MoFhR+5BBYUdqYX47pePncT49s1+mv2PY 4ogpUiEcftF172ULrXnqe2/0VancvfZI8dGuMQPvhoAZF3ki9l9YJgr8HQ15yLHq7Qd/ HF9A== 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=qGT5dE3cikuLg0b9p10qdGk9Usm93557jJLEm3WbVTc=; b=CmGBTZ3EsQySV+Q6U4Qk8eef8hcmlULYnMBm2DmNUjJbnyLxcPJDpr4qhEues2sZo9 usyKE2NyFq8e2mtvAsayZY0kpVzRk+CDBt5mOBKsgfndre8dGVAuRMW0xSX8mZ78szfU 5ZATNOx2ardysCN/Q6ezNY9KAoWIXPtjZ2ALdBXdW5dt/viZ2nQ8x04zqy+bP+/T0QS7 w8aWOQ6HKDVEgktN5ebeQiUgmBLEttsmJtZd4VOHKUxscYiWE0YduorkYbbWS9epHazj Yay33M4k9Y/h0gK9tozimE+m052s1lVi6OmjSbuBGFQTdZvf1kH5kuliIJoRr6CuIWHw K/uw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=dUnSRqhe; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id n2-20020a63f802000000b003816043ee92si15735019pgh.135.2022.04.06.05.09.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Apr 2022 05:09:15 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=dUnSRqhe; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 5EDD84F997B; Wed, 6 Apr 2022 03:41:14 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1574990AbiDEXCO (ORCPT + 99 others); Tue, 5 Apr 2022 19:02:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47618 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349243AbiDEJt2 (ORCPT ); Tue, 5 Apr 2022 05:49:28 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 34EE12316D; Tue, 5 Apr 2022 02:43:16 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sin.source.kernel.org (Postfix) with ESMTPS id 6F9A3CE1C90; Tue, 5 Apr 2022 09:43:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 82E65C385A2; Tue, 5 Apr 2022 09:43:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649151792; bh=XvGBi4JdV/9rcjiZAmcDAgtrI9eNHKirifLBD5bIVy0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dUnSRqhei1uBHKmMFbUjkhCwVXPU6uEW8gCrEZiWbA61KAoW6yQUuIMSFyVs5cl2q fglQMWUeXlI1v/NyY9baOOOVzkf5bhfyP6lGhjgDDPz0vK7Z+gYcL/921JR68jPLLz 28An1aHAtIe98uKlhi84QyeWT2vKdvmf04sp0dCE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, =?UTF-8?q?Niklas=20S=C3=B6derlund?= , Simon Horman , Daniel Borkmann , Sasha Levin Subject: [PATCH 5.15 544/913] samples/bpf, xdpsock: Fix race when running for fix duration of time Date: Tue, 5 Apr 2022 09:26:46 +0200 Message-Id: <20220405070356.155559003@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070339.801210740@linuxfoundation.org> References: <20220405070339.801210740@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Niklas Söderlund [ Upstream commit 8fa42d78f6354bb96ad3a079dcbef528ca9fa9e0 ] When running xdpsock for a fix duration of time before terminating using --duration=, there is a race condition that may cause xdpsock to terminate immediately. When running for a fixed duration of time the check to determine when to terminate execution is in is_benchmark_done() and is being executed in the context of the poller thread, if (opt_duration > 0) { unsigned long dt = (get_nsecs() - start_time); if (dt >= opt_duration) benchmark_done = true; } However start_time is only set after the poller thread have been created. This leaves a small window when the poller thread is starting and calls is_benchmark_done() for the first time that start_time is not yet set. In that case start_time have its initial value of 0 and the duration check fails as it do not correlate correctly for the applications start time and immediately sets benchmark_done which in turn terminates the xdpsock application. Fix this by setting start_time before creating the poller thread. Fixes: d3f11b018f6c ("samples/bpf: xdpsock: Add duration option to specify how long to run") Signed-off-by: Niklas Söderlund Signed-off-by: Simon Horman Signed-off-by: Daniel Borkmann Link: https://lore.kernel.org/bpf/20220315102948.466436-1-niklas.soderlund@corigine.com Signed-off-by: Sasha Levin --- samples/bpf/xdpsock_user.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/samples/bpf/xdpsock_user.c b/samples/bpf/xdpsock_user.c index 49d7a6ad7e39..1fb79b3ecdd5 100644 --- a/samples/bpf/xdpsock_user.c +++ b/samples/bpf/xdpsock_user.c @@ -1673,14 +1673,15 @@ int main(int argc, char **argv) setlocale(LC_ALL, ""); + prev_time = get_nsecs(); + start_time = prev_time; + if (!opt_quiet) { ret = pthread_create(&pt, NULL, poller, NULL); if (ret) exit_with_error(ret); } - prev_time = get_nsecs(); - start_time = prev_time; if (opt_bench == BENCH_RXDROP) rx_drop_all(); -- 2.34.1