From patchwork Tue Oct 26 00:02:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Hyong Youb Kim (hyonkim)" X-Patchwork-Id: 102796 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id CF168A0C47; Tue, 26 Oct 2021 02:03:03 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 4214740A4B; Tue, 26 Oct 2021 02:03:03 +0200 (CEST) Received: from alln-iport-1.cisco.com (alln-iport-1.cisco.com [173.37.142.88]) by mails.dpdk.org (Postfix) with ESMTP id 343974003E for ; Tue, 26 Oct 2021 02:03:02 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=cisco.com; i=@cisco.com; l=1868; q=dns/txt; s=iport; t=1635206582; x=1636416182; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=Vr+ODujKVpnW5OA3QRG5lEnIAoMjMkMEyiWu0UGBvGc=; b=PyqO4DhPr6i5mSkZYO5HJYdUeugzdeiln2UE/orXRSWbbp9McQBF6onl I76d/rf+Qemx2HKkLtMCrDAK+s36ir5vFoqdtV2iDx50vkyetg+L+Kfya rCaz0AAr/bybbac2/AUjHeJO+9w/g1VgYthVABFdtmFbz7JQDA4ISLZtR s=; X-IronPort-AV: E=Sophos;i="5.87,181,1631577600"; d="scan'208";a="765989242" Received: from rcdn-core-5.cisco.com ([173.37.93.156]) by alln-iport-1.cisco.com with ESMTP/TLS/DHE-RSA-SEED-SHA; 26 Oct 2021 00:03:01 +0000 Received: from cisco.com (savbu-usnic-a.cisco.com [10.193.184.48]) by rcdn-core-5.cisco.com (8.15.2/8.15.2) with ESMTP id 19Q030Q8004105; Tue, 26 Oct 2021 00:03:01 GMT Received: by cisco.com (Postfix, from userid 508933) id 8B03020F2005; Mon, 25 Oct 2021 17:03:00 -0700 (PDT) From: Hyong Youb Kim To: Ferruh Yigit Cc: dev@dpdk.org, Hyong Youb Kim , John Daley Date: Mon, 25 Oct 2021 17:02:56 -0700 Message-Id: <20211026000256.11492-1-hyonkim@cisco.com> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 X-Outbound-SMTP-Client: 10.193.184.48, savbu-usnic-a.cisco.com X-Outbound-Node: rcdn-core-5.cisco.com Subject: [dpdk-dev] [PATCH] net/enic: fix segfault caused by changing MTU X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 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" Changing MTU after the device start causes a segfault in the Rx handler. The MTU handler (enic_set_mtu) performs the following steps. 1. Stop NIC Rx 2. Change Rx handler '(struct rte_eth_dev)->rx_pkt_burst' to the dummy handler and sleep a while to quiesce 3. Re-allocate/initialize Rx structures 4. Change Rx handler back to the real handler (e.g. enic_noscatter_recv_pkts) enic_set_mtu does not update the recently introduced fast-path pointer '(struct rte_eth_fp_ops)->rx_pkt_burst'. Since rte_eth_rx_burst only uses the fast-path pointer, it keeps invoking the real Rx handler, not the dummy one set by (2). And, (3) causes a segfault in the real Rx handler (e.g. dereferencing freed structures). Fix the segfault by updating the fast-path pointer as well. Fixes: c87d435a4d79 ("ethdev: copy fast-path API into separate structure") Signed-off-by: Hyong Youb Kim Reviewed-by: John Daley --- drivers/net/enic/enic_main.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/net/enic/enic_main.c b/drivers/net/enic/enic_main.c index 21b1fffb14..42bf363529 100644 --- a/drivers/net/enic/enic_main.c +++ b/drivers/net/enic/enic_main.c @@ -1665,6 +1665,7 @@ int enic_set_mtu(struct enic *enic, uint16_t new_mtu) /* replace Rx function with a no-op to avoid getting stale pkts */ eth_dev->rx_pkt_burst = enic_dummy_recv_pkts; + rte_eth_fp_ops[enic->port_id].rx_pkt_burst = eth_dev->rx_pkt_burst; rte_mb(); /* Allow time for threads to exit the real Rx function. */ @@ -1699,6 +1700,7 @@ int enic_set_mtu(struct enic *enic, uint16_t new_mtu) /* put back the real receive function */ rte_mb(); enic_pick_rx_handler(eth_dev); + rte_eth_fp_ops[enic->port_id].rx_pkt_burst = eth_dev->rx_pkt_burst; rte_mb(); /* restart Rx traffic */