From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id E7B9543E3E; Thu, 11 Apr 2024 08:18:00 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id AE3AB402A7; Thu, 11 Apr 2024 08:18:00 +0200 (CEST) Received: from mail-pg1-f170.google.com (mail-pg1-f170.google.com [209.85.215.170]) by mails.dpdk.org (Postfix) with ESMTP id 5BCEF40262 for ; Thu, 11 Apr 2024 08:17:59 +0200 (CEST) Received: by mail-pg1-f170.google.com with SMTP id 41be03b00d2f7-5ce2aada130so5253931a12.1 for ; Wed, 10 Apr 2024 23:17:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1712816278; x=1713421078; darn=dpdk.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=SAgaMYeKIIcJfc8LZ0/tnOURMbNe/+QXgY193kfrEcs=; b=GB/ceAzqm8gfmXlKbZG+GEI7odI2wJaFxpAUDeJBvYDXOiQfp9KkNp33zFqIJan+v6 haY4NP6DeeR4/jAlYJJWev2Li2QTLZ2K/NTlf+Kd1/TuAtg5yPtetxq8KXId6+8rGZgn P/GnNjHqngowNUwVB5QWiTUo90hgE1dmLGmjm9OmDg5bPskcOmIxpaT5UYSmPIkSO17A CmC7mZEuC3FdV5GVlUtCDHwi84ojwaijnFIW1S3ZcNJ7akd8GjYIc5eaMxLZ00lQCWaG FhC0ILLJYHx/pHuMhYJlYsxterm7oj/ePp8i89UBEOqNONdEM/vXpPXJJ1qqExRFs2Ic LfPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712816278; x=1713421078; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=SAgaMYeKIIcJfc8LZ0/tnOURMbNe/+QXgY193kfrEcs=; b=UOPoA3M1d8P6iXbivMswoppKi2hktYuRlGoN+mUTwa5wr32d6e4gs57luf1/QzlL4W Mxkhx2qBKyO4rO4CpauptxxiCrefrfMTUdGatkkGdDKMidWVFDZn/INTeVS8dDQiKXVW u4fGKy7Ca3J/9hQ9kWevXsWOFuMjWr0ImShs7O9pRKEl2K7aloy+n4UqRopH6087s6EO 9VgCLEFtEe7yzpnKyRhjlAEDbf5/1laAp+X+glcJcrQPClmXbadX7Aj5nLJgUgExsvfP 7v5IkaH7PdYwmfLkVPxh17b81M73+DdHFSiOlx+pvX4UQ4boHJ8/bpe7s1kWxk4o2Jv4 mP0Q== X-Gm-Message-State: AOJu0Yy0iVKWEbil+tyWjEVT0uTHWJlV8pLL/kQjxy7bmog65UTobOUP JgdMa6LCg3wzua3VE0QXA4xozn5ieTDT1rpCt2N8XQJcdB6vgQ4K3RRilxyjo6TMSLZ3k3FQ4d0 qDf8= X-Google-Smtp-Source: AGHT+IFhSYk6M/AMzclqLxHoi1XQkifooYplVpLGhr1ziZrY5R+M3sJReSOP64oSfL3UWhKFMRImyw== X-Received: by 2002:a05:6a21:7885:b0:1a7:73ed:7f8d with SMTP id bf5-20020a056a21788500b001a773ed7f8dmr5243619pzc.38.1712816278021; Wed, 10 Apr 2024 23:17:58 -0700 (PDT) Received: from localhost.localdomain ([61.213.176.12]) by smtp.gmail.com with ESMTPSA id m17-20020a170902db1100b001ddb4df7f70sm520060plx.304.2024.04.10.23.17.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Apr 2024 23:17:57 -0700 (PDT) From: hepeng To: dev@dpdk.org Cc: "hepeng.0320" Subject: [PATCH] mlx5: fix race at mlx5_dev_close Date: Thu, 11 Apr 2024 14:17:40 +0800 Message-Id: <20240411061740.16495-1-hepeng.0320@bytedance.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 From: "hepeng.0320" mlx5_dev_close currently will set priv->sh->port[priv->dev_port - 1].nl_ih_port_id to RTE_MAX_ETHPORTS to avoid mlx5_dev_interrupt_nl_cb to use the port's dev_private, because later the rte_eth_dev_close will free the dev_private and set the pointer to NULL. However, since mlx5_dev_interrupt_nl_cb is running in another thread, I think the race still exists. So perhaps an easy fix is to wait for 1ms to avoid this race. Signed-off-by: hepeng.0320 --- drivers/net/mlx5/mlx5.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/net/mlx5/mlx5.c b/drivers/net/mlx5/mlx5.c index d1a6382..283162f 100644 --- a/drivers/net/mlx5/mlx5.c +++ b/drivers/net/mlx5/mlx5.c @@ -2457,6 +2457,10 @@ mlx5_dev_close(struct rte_eth_dev *dev) * mlx5_os_mac_addr_flush() uses ibdev_path for retrieving * ifindex if Netlink fails. */ + + /* Avoid race condition if mlx5_dev_interrupt_nl_cb is running. */ + rte_delay_us_sleep(1000); + mlx5_free_shared_dev_ctx(priv->sh); if (priv->domain_id != RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID) { unsigned int c = 0; -- 2.11.0