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 3B6DAA034C for ; Mon, 8 Aug 2022 11:42:48 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 1AAEB42B73; Mon, 8 Aug 2022 11:42:48 +0200 (CEST) Received: from NAM02-BN1-obe.outbound.protection.outlook.com (mail-bn1nam07on2046.outbound.protection.outlook.com [40.107.212.46]) by mails.dpdk.org (Postfix) with ESMTP id 77AC142B71; Mon, 8 Aug 2022 11:42:46 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Ka+UlnAJWFfJjzSn7Y7bf4Kwb0FipSYp7/AQLjwjuP81m7Sn6QGyvwl7CJl/AHZ6zbR4jlhJhKGLIXncLlDFY8Piw4N/gtrxXo3JWLUC6eDErKynbfToEfk69Js7u8VUfF1VU14SZrBTq2hr7kGP8c2SKOTSZDRjUptuhEEjDKElxrMYUqwTP8QTXBUJqgzw8wgS/0mi9I3+9atePxALmO8geQ9yHUOCvkditgP3zKel1WRvQSZEi62KHwEjqe2P+ew1MRME54JKkCvxvGCMup8t72FsU08WcvXzu7xrXnqnLOIoy+6imZAQzs0+5xxgpFH6bU4/bLuzMDZTeJXmkA== 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=2Ew8YKNL6er9fJJXtmEIEyNBR39toWXDP/bk6jbT/SY=; b=gkBx/OkTYBQC7qHL//0OMMAc98F04gfU/+S5XDLohnv8H2dyGakOrq59UnWUpaw8NiAXGIdDlbq5jfIfB7UuxWHF0qzqk4a0Vez+x3k0KGfyR2t3utHRnzr21xK1K692tDCFztyw4cN5artuDSrlDEUT/QKn+8wbaFheUHlxDCjSYhcJsbISNvw8JLD+cANprpmPa6eiIpztyNUTi0u8G8WbRgk1H+QC5Y8BUtYrF5qLdDmaBmxt6bnLQK2k+nKsbsvqM7qCjJp769gUCka8CGTraJKT86mZQUEvxmi41czA1RFTryIVLDYg2otgzbrGwTkrnQ3S0IIyyAzU00Ccig== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 12.22.5.236) smtp.rcpttodomain=oktetlabs.ru smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject 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=2Ew8YKNL6er9fJJXtmEIEyNBR39toWXDP/bk6jbT/SY=; b=hyCfdYghlMwqjj/vQogR8IWHlTNvm2mPVLRUOCP3Rm9sw+/sbymBNiZXL+Dm7ziWdrGgD1TMAeD+RuN2sa4NCHn7En3J9cf9Z/BWnISg+q5ZLDIzOX3fTVzAj7IoebXgxR8lXWQBIlD3lDfr7g+bOw4rcAxBok98PJUGbjgxTxyNBF6OwxCd2sT/Y4L5IuEb88oY2TfQZJjUbSxu4GdAf9/jEGhb9u+EudMf3QHQTXLClbOPos26DvhzllU+QVcXPpScKBONHyX5JUUEyxbDTWv+e2aXdRaSTaN37nmtm4zca1y2AD2MDCmljaC/d6jsnIZivtDtMTjn+sBORGkZWg== Received: from MW4PR02CA0013.namprd02.prod.outlook.com (2603:10b6:303:16d::13) by CO6PR12MB5409.namprd12.prod.outlook.com (2603:10b6:5:357::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5504.15; Mon, 8 Aug 2022 09:42:44 +0000 Received: from CO1NAM11FT031.eop-nam11.prod.protection.outlook.com (2603:10b6:303:16d:cafe::71) by MW4PR02CA0013.outlook.office365.com (2603:10b6:303:16d::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5504.16 via Frontend Transport; Mon, 8 Aug 2022 09:42:44 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 12.22.5.236) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 12.22.5.236 as permitted sender) receiver=protection.outlook.com; client-ip=12.22.5.236; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (12.22.5.236) by CO1NAM11FT031.mail.protection.outlook.com (10.13.174.118) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.5504.14 via Frontend Transport; Mon, 8 Aug 2022 09:42:42 +0000 Received: from rnnvmail202.nvidia.com (10.129.68.7) by DRHQMAIL109.nvidia.com (10.27.9.19) with Microsoft SMTP Server (TLS) id 15.0.1497.32; Mon, 8 Aug 2022 09:42:42 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by rnnvmail202.nvidia.com (10.129.68.7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.26; Mon, 8 Aug 2022 02:42:41 -0700 Received: from nvidia.com (10.127.8.11) by mail.nvidia.com (10.129.68.8) with Microsoft SMTP Server id 15.2.986.26 via Frontend Transport; Mon, 8 Aug 2022 02:42:40 -0700 From: Dmitry Kozlyuk To: CC: Olivier Matz , Andrew Rybchenko , Subject: [PATCH 1/2] mempool: make event callbacks process-private Date: Mon, 8 Aug 2022 12:42:35 +0300 Message-ID: <20220808094236.3395516-2-dkozlyuk@nvidia.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220808094236.3395516-1-dkozlyuk@nvidia.com> References: <20220808094236.3395516-1-dkozlyuk@nvidia.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: c1bab691-2834-4efd-953a-08da79225776 X-MS-TrafficTypeDiagnostic: CO6PR12MB5409:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: s8LG6dWJwX5zu/FLua6ddfD8x24Nq5YDx6ldkNMy95xtgzGoreDW0Wp6F3YqiN5ik8b7GaOf8EjqH8FqhuNzhj+J4C3Ve5GNTBixM1J3h4ulVdx+fSYAFNcPBsbuAlC/EMliQJgztrYPDRUirw4o0hGoN6t+LIqTk7UwOoX+UvhHmA/Qt4DUoq95APhpvJD07Ose/VLCjSRDhvz9qzoglBiO6XKq48aWKGvwRrQCpFzTesb5FIJ9NySxJdoOnCE5d1lIOkIp9rAU1QY9snmn7YvLIu2I9tw/Wb7b5Tnx3BVvDGz89lDUeHl6p+VyFnPcjjenIsByHCYlU1vcW7c5Prof5kWvU1tH3YxjXKxA4XGh7/AbPxu3eaj2cw2PfosIMhNPMQ/BJq3aVTbj17VMCWYBfRAEvnHz4gC6XETJlvnZKpElQUJ1eApJzM5JP3mBzxFSOZa2azFV+I5oO7A2F6kiuJiwIIQJdM40LHbnKHCztqdr6ClU74p8zkRrmJooxs+J/ecNto9DMHPGTy3on2rIsBHMaK5IaM1zrCPumVH+IGrh6LrREYR9F8DHENclPbuUUEYKmtYGH8WzCV9v5Rla8p0W1aUl1IEeF4A9iHK5VraKE52bH2QleJSzbJhWlU8ndSoegWNJumV80n2Dkpb8Mhm6N8M9hg1uvP7FiShAnA25ZusX1uySvqkGRAMAWu2Ii4sDOtTthQnb5hX0iwmpQgdlZYLLYUZyWnVfZdt+n9jQZQ3QNP5BbWx3AiF0eDVGVsDi7laUWXBELiru/N5hSe7tLx5opkuT4gqyQeNqAVXgotec4w75vDo7wmBcKUyKnGEJcNYWw180jeSjqA== X-Forefront-Antispam-Report: CIP:12.22.5.236; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:InfoNoRecords; CAT:NONE; SFS:(13230016)(4636009)(376002)(346002)(39860400002)(396003)(136003)(40470700004)(36840700001)(46966006)(70206006)(70586007)(36756003)(8676002)(4326008)(1076003)(55016003)(186003)(316002)(86362001)(8936002)(40460700003)(5660300002)(478600001)(54906003)(6916009)(336012)(83380400001)(7696005)(2906002)(356005)(6286002)(82740400003)(26005)(41300700001)(6666004)(81166007)(47076005)(82310400005)(426003)(2616005)(40480700001)(36860700001)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Aug 2022 09:42:42.8334 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c1bab691-2834-4efd-953a-08da79225776 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[12.22.5.236]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT031.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO6PR12MB5409 X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org Callbacks for mempool events were registered in a process-shared tailq. This was inherently incorrect because the same function may be loaded to a different address in each process. Make the tailq process-private. Use the EAL tailq lock to reduce the number of different locks this module operates. Fixes: da2b9cb25e5f ("mempool: add event callbacks") Cc: stable@dpdk.org Signed-off-by: Dmitry Kozlyuk --- lib/mempool/rte_mempool.c | 54 ++++++++++----------------------------- lib/mempool/rte_mempool.h | 2 ++ 2 files changed, 16 insertions(+), 40 deletions(-) diff --git a/lib/mempool/rte_mempool.c b/lib/mempool/rte_mempool.c index de59009baf..1e039f6247 100644 --- a/lib/mempool/rte_mempool.c +++ b/lib/mempool/rte_mempool.c @@ -36,12 +36,10 @@ static struct rte_tailq_elem rte_mempool_tailq = { }; EAL_REGISTER_TAILQ(rte_mempool_tailq) -TAILQ_HEAD(mempool_callback_list, rte_tailq_entry); +TAILQ_HEAD(mempool_callback_tailq, mempool_callback_data); -static struct rte_tailq_elem callback_tailq = { - .name = "RTE_MEMPOOL_CALLBACK", -}; -EAL_REGISTER_TAILQ(callback_tailq) +static struct mempool_callback_tailq callback_tailq = + TAILQ_HEAD_INITIALIZER(callback_tailq); /* Invoke all registered mempool event callbacks. */ static void @@ -1372,6 +1370,7 @@ void rte_mempool_walk(void (*func)(struct rte_mempool *, void *), } struct mempool_callback_data { + TAILQ_ENTRY(mempool_callback_data) callbacks; rte_mempool_event_callback *func; void *user_data; }; @@ -1380,14 +1379,11 @@ static void mempool_event_callback_invoke(enum rte_mempool_event event, struct rte_mempool *mp) { - struct mempool_callback_list *list; - struct rte_tailq_entry *te; + struct mempool_callback_data *cb; void *tmp_te; rte_mcfg_tailq_read_lock(); - list = RTE_TAILQ_CAST(callback_tailq.head, mempool_callback_list); - RTE_TAILQ_FOREACH_SAFE(te, list, next, tmp_te) { - struct mempool_callback_data *cb = te->data; + RTE_TAILQ_FOREACH_SAFE(cb, &callback_tailq, callbacks, tmp_te) { rte_mcfg_tailq_read_unlock(); cb->func(event, mp, cb->user_data); rte_mcfg_tailq_read_lock(); @@ -1399,10 +1395,7 @@ int rte_mempool_event_callback_register(rte_mempool_event_callback *func, void *user_data) { - struct mempool_callback_list *list; - struct rte_tailq_entry *te = NULL; struct mempool_callback_data *cb; - void *tmp_te; int ret; if (func == NULL) { @@ -1411,36 +1404,23 @@ rte_mempool_event_callback_register(rte_mempool_event_callback *func, } rte_mcfg_tailq_write_lock(); - list = RTE_TAILQ_CAST(callback_tailq.head, mempool_callback_list); - RTE_TAILQ_FOREACH_SAFE(te, list, next, tmp_te) { - cb = te->data; + TAILQ_FOREACH(cb, &callback_tailq, callbacks) { if (cb->func == func && cb->user_data == user_data) { ret = -EEXIST; goto exit; } } - te = rte_zmalloc("mempool_cb_tail_entry", sizeof(*te), 0); - if (te == NULL) { - RTE_LOG(ERR, MEMPOOL, - "Cannot allocate event callback tailq entry!\n"); - ret = -ENOMEM; - goto exit; - } - - cb = rte_malloc("mempool_cb_data", sizeof(*cb), 0); + cb = calloc(1, sizeof(*cb)); if (cb == NULL) { - RTE_LOG(ERR, MEMPOOL, - "Cannot allocate event callback!\n"); - rte_free(te); + RTE_LOG(ERR, MEMPOOL, "Cannot allocate event callback!\n"); ret = -ENOMEM; goto exit; } cb->func = func; cb->user_data = user_data; - te->data = cb; - TAILQ_INSERT_TAIL(list, te, next); + TAILQ_INSERT_TAIL(&callback_tailq, cb, callbacks); ret = 0; exit: @@ -1453,27 +1433,21 @@ int rte_mempool_event_callback_unregister(rte_mempool_event_callback *func, void *user_data) { - struct mempool_callback_list *list; - struct rte_tailq_entry *te = NULL; struct mempool_callback_data *cb; int ret = -ENOENT; rte_mcfg_tailq_write_lock(); - list = RTE_TAILQ_CAST(callback_tailq.head, mempool_callback_list); - TAILQ_FOREACH(te, list, next) { - cb = te->data; + TAILQ_FOREACH(cb, &callback_tailq, callbacks) { if (cb->func == func && cb->user_data == user_data) { - TAILQ_REMOVE(list, te, next); + TAILQ_REMOVE(&callback_tailq, cb, callbacks); ret = 0; break; } } rte_mcfg_tailq_write_unlock(); - if (ret == 0) { - rte_free(te); - rte_free(cb); - } + if (ret == 0) + free(cb); rte_errno = -ret; return ret; } diff --git a/lib/mempool/rte_mempool.h b/lib/mempool/rte_mempool.h index 3ada37cb86..bfc1f3c823 100644 --- a/lib/mempool/rte_mempool.h +++ b/lib/mempool/rte_mempool.h @@ -1847,6 +1847,8 @@ typedef void (rte_mempool_event_callback)( * Register a callback function invoked on mempool life cycle event. * The function will be invoked in the process * that performs an action which triggers the callback. + * Registration is process-private, + * i.e. each process must manage callbacks on its own if needed. * * @param func * Callback function. -- 2.25.1