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 DAA7DA0C43; Fri, 22 Oct 2021 23:14:34 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 4535B410EF; Fri, 22 Oct 2021 23:14:33 +0200 (CEST) Received: from NAM02-DM3-obe.outbound.protection.outlook.com (mail-dm3nam07on2071.outbound.protection.outlook.com [40.107.95.71]) by mails.dpdk.org (Postfix) with ESMTP id D7243410EE for ; Fri, 22 Oct 2021 23:14:31 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mfFhxNKxK2h+zYiidDEC0x9ymcXng7HJoZaqK6V5kozStil+uyGeBN4EEbbhlTOck+N+cQ+/SHMc2XFskd9zFrYEPLwFGcxnA1o2iX4jM81XouinRhNLQEOeeRPr3XaDv0Egl7JqGAmNW0QSNrILeWXcIWIXTw5vG/ZaWwNXYAF1fFHX9OxNmVBAmDjC4h2pk2CNAC4CQbTMtRRyuGp7pesDSXhpoje4+G2/fVhhzSHjrCceeirtNWOdM+j9VPIoboYQjB5eC3ZiEsbHOui/ZZVnDELqktLlGd79LD9ZTl0wBLrLy56yhMxaBtk9FazIorv68PUe4tWE2trVD3BO7Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=tTivB7WySVcB93Ki9ED9uIkRGP4ZsK8KwNs3KeEiJLE=; b=AKRsVBaEjgzQpfgVsvBzhh6M1AoM0hq9vU0PMeo5jqH9VS6yUAug/eHT5/6JjlV3db4Pexlf5Td6WuyGYWdotDYHF82VSa+PRILKhHnkTTQsYodS/bMiNItQW5lzTRxhcKCrpYvBc1ELt5GOgMhSXIOGE74YBBU+dZuiWVaYDnSB4tHFIL3A0XeXQkZH9lgiDdRQ9/r07BzGiXLDGuDgruNTBPF+1+ISFzKkCLWQDJTo4Q0N7mibKQOnVcGZrE23WH11y+Vo/kxFwqZLSjhSNrudm67+3aIRapGqQZVGhhvx305Kv/BODTRYA2cRhBDG5MzvCN6+RSw2iiqAghluaQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.34) smtp.rcpttodomain=dpdk.org smtp.mailfrom=nvidia.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=tTivB7WySVcB93Ki9ED9uIkRGP4ZsK8KwNs3KeEiJLE=; b=OHtk7d60uvBQeq51hYbLDOW1Xrke2OZaO+D2HqbUpE7qfcguXv6zdZc3BU7iYJTFzyQmQB0iZGXE/OFFF8kz5TKb+n5nBx/eRbHCNxGNq3HiibT5geber2UZiu+nnHuUFMWwXR2Q/BVKnK5oOYr3vN/dIFO1qbekrRnwXGCFTkqNlxO5jsI/32LzP58qwkjUdvsG77OWlJwEyAxQYSlyLtfdDjDQvIEEC6jPji6/wk51sHbvDT3WZxop6XAqwq3hVZE6U0x1pHyJJzS51mncOZlJ1MLgWTctocVR9qEFNDVdFds1nipu/FC1H5tMNI7DuxToaL22EzHLAnM7cbSGzw== Received: from DM6PR02CA0058.namprd02.prod.outlook.com (2603:10b6:5:177::35) by MN2PR12MB4815.namprd12.prod.outlook.com (2603:10b6:208:1bf::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.18; Fri, 22 Oct 2021 21:14:29 +0000 Received: from DM6NAM11FT004.eop-nam11.prod.protection.outlook.com (2603:10b6:5:177:cafe::2a) by DM6PR02CA0058.outlook.office365.com (2603:10b6:5:177::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.16 via Frontend Transport; Fri, 22 Oct 2021 21:14:29 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.34) smtp.mailfrom=nvidia.com; dpdk.org; dkim=none (message not signed) header.d=none;dpdk.org; dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.34 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.34; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.34) by DM6NAM11FT004.mail.protection.outlook.com (10.13.172.217) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4628.16 via Frontend Transport; Fri, 22 Oct 2021 21:14:29 +0000 Received: from nvidia.com (172.20.187.6) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Fri, 22 Oct 2021 21:14:27 +0000 From: Bing Zhao To: , , CC: , Date: Sat, 23 Oct 2021 00:14:07 +0300 Message-ID: <20211022211407.315068-2-bingz@nvidia.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20211022211407.315068-1-bingz@nvidia.com> References: <20211022211407.315068-1-bingz@nvidia.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [172.20.187.6] X-ClientProxiedBy: HQMAIL107.nvidia.com (172.20.187.13) To HQMAIL107.nvidia.com (172.20.187.13) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 14a13237-6190-4b93-449b-08d995a0ef78 X-MS-TrafficTypeDiagnostic: MN2PR12MB4815: X-LD-Processed: 43083d15-7273-40c1-b7db-39efd9ccc17a,ExtAddr X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: bsgPGm9iAQi6XkbMRGxqFlOLLA8r/HntVf2bu4mLJJopcNN97zeYLXLXZTB+PZVq1unRuPWaA9BpJk221u8tikkW1/HP5VMdYJUMgpkGjIQTexUOvsG8kDC9q4JUXfVmnJSpfq/VlulmJW5J0xfTZUDioBUPW84yO9gxPgQXPVHZXo5WCtb7iv3bWEhm2EHkqoyuXu+psGPLJrnYnHcsHtYcKIzW0RrstQoCLwPXuU73S4H0jEyhN2FVnqLI+XMr73lvmJZI3ljegZI4qXRDM+KSYpuFWymBKNZt2okAMfyuXHGexFaw/7tkJi9+JyWhEQCxWsoPKxrIZk1wjcFUWVSuXOtID9qizBz8saW1ySJM+LR4zwcV72Ztjqsy2K7h2vO2gUJSsIWvNbnhb24EI7kwFHVuJ2DQ6k9/UgoSIga0g50UA9YIUtJPlOy2iJkx8Lm3/4eL+OipgpY9cd73hS9jZfUSgVVCngpv5GLe0Z2IJvDGTBxjPSSSCA5M13nfdJ03Ld5idp8N8GldyEp1NRTmXbWORqGgTYjXdQ0HwT+a+Dgzx3T+xrEEuJatbd9zkfPkfQN2e9RhMMr4oru82wk0XtHgGCFnqqKOiUiczRkrESpAv0EjCnrbM1ah4Xr/dIOEk4Fy2nVr0nmUHzr9GOeHPC8vWvasUXNaQvWN6k7TwxJ2OHrcNeQFHZqjrYzWGvtJYofwxuffbbjDEcEfjg== X-Forefront-Antispam-Report: CIP:216.228.112.34; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:schybrid03.nvidia.com; CAT:NONE; SFS:(4636009)(36840700001)(46966006)(356005)(8936002)(70586007)(2906002)(36906005)(83380400001)(508600001)(316002)(82310400003)(6666004)(110136005)(70206006)(54906003)(16526019)(8676002)(2616005)(26005)(5660300002)(7696005)(47076005)(7636003)(1076003)(86362001)(55016002)(336012)(426003)(36860700001)(36756003)(4326008)(6286002)(186003); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Oct 2021 21:14:29.3408 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 14a13237-6190-4b93-449b-08d995a0ef78 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.112.34]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT004.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB4815 Subject: [dpdk-dev] [PATCH 2/2] ethdev: fix the race condition for fp ops reset 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" In the function "eth_dev_fp_ops_reset", a structure assignment operation is used to reset one queue's callback functions, etc., but it is not thread safe. The structure assignment is not atomic, a lot of instructions will be generated. Right now, since not all the fields are needed, the fields in the "dummy_ops" which is not set explicitly will be 0s based on the specification and compiler behavior. In order to make "fpo" has the same content with "dummy_ops", some clearing to 0 operation is needed. By checking the object instructions (e.g. with GCC 4.8.5) 0x0000000000a58317 <+35>: mov %rsi,%rdi 0x0000000000a5831a <+38>: mov %rdx,%rcx => 0x0000000000a5831d <+41>: rep stos %rax,%es:(%rdi) 0x0000000000a58320 <+44>: mov -0x38(%rsp),%rax 0x0000000000a58325 <+49>: lea -0xe0(%rip),%rdx // # 0xa5824c It shows that "rep stos" will clear the "fpo" structure before assigning new values. In the other thread, if some data path Tx / Rx functions are still running, there is a risk to get 0 instead of the correct dummy content. 1. qd = p->rxq.data[queue_id] 2. (void **)&p->rxq.clbk[queue_id] "data" and "clbk" may be observed with NULL (0) in other threads. Even it is temporary, the accessing to a NULL pointer will cause a crash. Using "memcpy" could get rid of this. Fixes: c87d435a4d79 ("ethdev: copy fast-path API into separate structure") Cc: konstantin.ananyev@intel.com Signed-off-by: Bing Zhao --- lib/ethdev/ethdev_private.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ethdev/ethdev_private.c b/lib/ethdev/ethdev_private.c index fbc3df91ad..cda9a6e228 100644 --- a/lib/ethdev/ethdev_private.c +++ b/lib/ethdev/ethdev_private.c @@ -206,7 +206,7 @@ eth_dev_fp_ops_reset(struct rte_eth_fp_ops *fpo) .txq = {.data = dummy_data, .clbk = dummy_data,}, }; - *fpo = dummy_ops; + rte_memcpy(fpo, &dummy_ops, sizeof(struct rte_eth_fp_ops)); } void -- 2.27.0