From patchwork Tue Jul 9 15:09:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 56275 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id D8B681B9B2; Tue, 9 Jul 2019 17:09:52 +0200 (CEST) Received: from mail-pg1-f195.google.com (mail-pg1-f195.google.com [209.85.215.195]) by dpdk.org (Postfix) with ESMTP id 1468B1B997 for ; Tue, 9 Jul 2019 17:09:50 +0200 (CEST) Received: by mail-pg1-f195.google.com with SMTP id i18so9590341pgl.11 for ; Tue, 09 Jul 2019 08:09:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=8v7OSOzARnVHBELM/KAu2BccRvpC7XvWrmT3Mxp8KjI=; b=gN5rPci9ZotEg20QdOzfhSCAoUmhZDPV41yQNPBy+Mh6SeebuxaDcFv2INL0tbY1ex F5rnWRHTYlyaYFO5WDFjQprOcxc0w3fUv1jW/iGwMWeAy3yuxJjHxUXDraH++uIgBiKE nVRv758SFdYvkL+qHTz3n/wTlu+5yGXOWFKVC+EQAPoTG8EEmnxJG6ak2+EhCfxcIgSA ClPGR38UAxlLNSXt1k4App+ty4mfE9EGCqL9n6YFfhsk0FqXrMWj1eqOcWdqM36szQsT xuwhB9ZR9QmmDXD7Yzf2w4XDxJ3IPSbObZxgEoV8/T0phebLU4knZNHXndPClzEKGOxu izbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=8v7OSOzARnVHBELM/KAu2BccRvpC7XvWrmT3Mxp8KjI=; b=Wnls8pLosJZHzmrbAWtrVWw9FQ9tDO4BOWXADv+4a3hhY9gS6Sv301mje9hsQjal06 InX7Jy4UjPLMsHnn07iUFIWBn2NUYZasXpjrIA5pje9F8TYSgeVLClNYE4srxXOwHs6u Z3iPwSPa0I8unzMXsadodk3aYELn09mDQaw43twAqxMiSR7F/jTwv100t9HpKuI4A1pE 6EEXm1Tue0aHJfnpiH3Arkuee3Imlp/uaeTJQGPTGHX7ru0tKFn47j/FncoosYyJzD9c S7WEUqScx9hgAKY2xEuvLdJIyHsFOWwH4wU6IZ926Oill0J6F9MRtVV6i9Dm7yFtjyBs XKCg== X-Gm-Message-State: APjAAAWjpUZaWtXne2s46oklRFLrKgOUYv6I3o45pIemDPxosbEeGtKb /lNQL5FeQwI6slvsqG0EuZ6A5nJ7 X-Google-Smtp-Source: APXvYqz8OyAKWr13IuY6wgH3WXWsOiudcDkcDcmjTM8U+u0V0qqT4PbuRSYnPDn5GGOqdWM23ersbw== X-Received: by 2002:a17:90a:b104:: with SMTP id z4mr646692pjq.102.1562684988830; Tue, 09 Jul 2019 08:09:48 -0700 (PDT) Received: from hermes.lan (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id u134sm20151651pfc.19.2019.07.09.08.09.47 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Tue, 09 Jul 2019 08:09:47 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Date: Tue, 9 Jul 2019 08:09:39 -0700 Message-Id: <20190709150939.31338-3-stephen@networkplumber.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190709150939.31338-1-stephen@networkplumber.org> References: <20190709150939.31338-1-stephen@networkplumber.org> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v3 2/2] examples/multi_process - fix crash in mp_client with sparse ports X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" From: Stephen Hemminger The mp_client crashes if run on Azure or any system where ethdev ports are owned. In that case, the tx_buffer and tx_stats for the real port were initialized correctly, but the wrong port was used. For example if the server has Ports 3 and 5. Then calling rte_eth_tx_buffer_flush on any other buffer will dereference null because the tx buffer for that port was not allocated. Also: - the flush code is common enough that it should not be marked unlikely - combine conditions to reduce indentation - avoid unnecessary if() if sent is zero. Fixes: e2366e74e029 ("examples: use buffered Tx") Signed-off-by: Stephen Hemminger --- .../client_server_mp/mp_client/client.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/examples/multi_process/client_server_mp/mp_client/client.c b/examples/multi_process/client_server_mp/mp_client/client.c index c23dd3f378f7..361d90b54b2d 100644 --- a/examples/multi_process/client_server_mp/mp_client/client.c +++ b/examples/multi_process/client_server_mp/mp_client/client.c @@ -246,19 +246,19 @@ main(int argc, char *argv[]) for (;;) { uint16_t i, rx_pkts; - uint16_t port; rx_pkts = rte_ring_dequeue_burst(rx_ring, pkts, PKT_READ_SIZE, NULL); - if (unlikely(rx_pkts == 0)){ - if (need_flush) - for (port = 0; port < ports->num_ports; port++) { - sent = rte_eth_tx_buffer_flush(ports->id[port], client_id, - tx_buffer[port]); - if (unlikely(sent)) - tx_stats->tx[port] += sent; - } + if (rx_pkts == 0 && need_flush) { + for (i = 0; i < ports->num_ports; i++) { + uint16_t port = ports->id[i]; + + sent = rte_eth_tx_buffer_flush(port, + client_id, + tx_buffer[port]); + tx_stats->tx[port] += sent; + } need_flush = 0; continue; }