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 C881A43DE3; Wed, 3 Apr 2024 09:22:37 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 5474C40144; Wed, 3 Apr 2024 09:22:37 +0200 (CEST) Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by mails.dpdk.org (Postfix) with ESMTP id D5B19400D7 for ; Wed, 3 Apr 2024 09:22:35 +0200 (CEST) Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 432K395I029137; Wed, 3 Apr 2024 00:22:24 -0700 Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2040.outbound.protection.outlook.com [104.47.66.40]) by mx0b-0016f401.pphosted.com (PPS) with ESMTPS id 3x809fxsdw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 03 Apr 2024 00:22:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=R+TcPJlAXKfJDYattMbiyP6Bwk59Liuvv6v+TtaJL0rm2dG5y7HHKo3lt/nDeOeD9oto1j5eZTMj7TEyi8Ht0hDMc7WVFk9Pi3XuOADU4Qi4uwk/CYaMvsr7VeiBGoRd+EJcwrZp/RP86J91jp09x8gS8fpbhp0HqHC/xgWHO2uSe6iF/20nRAtAJ9NXZ2MC+EExdxka7GuYv2AjNIWQoDLrbSt5sqrRsuoCYUFXqg8gFHv8rKdVPOLK1UIHWJ1e+dgqghgD8wdesAO2iDZ2uOv2n3YtwAE7Q8mxH/6XpyltoWcOpYkJsL+p42JYIxsNiHTZ8Y8zfrWG7+uovZdHrQ== 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=er/u3fUwyfm1WN27nk7tpRBhCkjBlvsoVPUIp4FVIrs=; b=ap2I/28SNAY+GTlRRF/4WTX4VvDlP+U8pbLv4N0e+XJE9ij8IzdHsMvolcW6Xoj7teQ4U9vu2hzxt2S7+Sgg6eymnyjpkV5ryaD5B+GLAM0Rtdp799CS3AXe0j7lLZeRsPYhKrCO9/E+oyR/pUv/5lzllKQTXeN7k2sayWPiz1oXMDWELCRWTiymAkUDyD9e1nRx7aejcl2Ian2T26EQ7KUiSPAfXyOGs1Qq7a5A9oYEeYL/tJREKTj+fpsjyDa8g2+F8l45zKSXF4Lm3ttrQEHMzCcd/SqAM0/py1DBTFRbQUS/6t5JFHC3TQyg2fpLOOtcij6Gy6Yf87jlqfPvMA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=marvell.com; dmarc=pass action=none header.from=marvell.com; dkim=pass header.d=marvell.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=er/u3fUwyfm1WN27nk7tpRBhCkjBlvsoVPUIp4FVIrs=; b=EbbtHe7T5H7xB5smXikwN3afCec4Z8W44ZLEs6cmXZ22uQQsnkD8NFDhoomuVxqAtypYJqdXVXhf7n+njWXXEe2PumSKMoK7BYcEF+dBfwjEmsDHbIY1dd5SJXxLDbErgp8jPV8h9k00iIgPb6H/+HJvu58r5fN7xP6lJ9Q+TzI= Received: from PH0PR18MB5071.namprd18.prod.outlook.com (2603:10b6:510:16b::15) by MN0PR18MB6039.namprd18.prod.outlook.com (2603:10b6:208:4be::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.46; Wed, 3 Apr 2024 07:22:19 +0000 Received: from PH0PR18MB5071.namprd18.prod.outlook.com ([fe80::b2bd:bab4:73f2:6c52]) by PH0PR18MB5071.namprd18.prod.outlook.com ([fe80::b2bd:bab4:73f2:6c52%7]) with mapi id 15.20.7409.042; Wed, 3 Apr 2024 07:22:19 +0000 From: Kiran Kumar Kokkilagadda To: Robin Jarry , "dev@dpdk.org" , Jerin Jacob , Nithin Kumar Dabilpuram , Zhirun Yan Subject: RE: [EXTERNAL] [PATCH v2] graph: avoid accessing graph list when getting stats Thread-Topic: [EXTERNAL] [PATCH v2] graph: avoid accessing graph list when getting stats Thread-Index: AQHahHRvkl35Cbi7SkSVpAVvFF+LjrFWJkbg Date: Wed, 3 Apr 2024 07:22:19 +0000 Message-ID: References: <20240325155303.770468-2-rjarry@redhat.com> <20240401203647.1909165-3-rjarry@redhat.com> In-Reply-To: <20240401203647.1909165-3-rjarry@redhat.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-publictraffictype: Email x-ms-traffictypediagnostic: PH0PR18MB5071:EE_|MN0PR18MB6039:EE_ x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: Z3ohASg82y8rnK1e8SG3U4p+r8YlteTk/4Wy8TZgzR9DEMIANcibSTJwAH5AtJmujhMCSjFD6lTRC3/IxfyEYPupM98W2cVFP3RC7e1mfbvZKRhnhHJ/D+Wdit14gb7lcGH5b3/oXL11JJBpY5y2iYy5LaHaCFn0RJ0cQ1WOOtkRUIMF6h+TbzEoNTwH7i0ZAhzm/jg9sZwZJoldRdjrpzfco8Eu8KCtXEaI1EOHvLjxc9hIvYYDKUlQ8sUKvuua74OVWwn85SF+JgVKdBUVX+FarAjCraVflWVFRcsNrMAJ/5Wb3k7zFdtU/6gWAEzO29qYhJrvUMRvaBLKvCZIUhi1JczjT3wCsu/JJwzFcFEZRbHzCduTsQm9O15bOYk9Z75DNybwIFH/16b5r6diPPDfA+ZtPkwCSCZLY0ATfNHM9C4DQC8/srrBv0HBXaOjQ47aziCEpXnu1arhA2QNS5v4K/2do5GLPPgjYhFzvJbseqEnxzOidvXmC0G69m4VlnUL1qXaFdzkePJbcTj/peoxSw8Cz3nFIi+/A9Nttk1wZZ6F23elkZtLDTzZLTbjtWMmV8Wc54HHqy4abWkSrR/cdSkR/rROMe+Ht169t5OPxXApby105WSTxLeAIogu65fxxxb6wHKSMuMEErig159dYKAMc3O70mO+wiz6wHg= x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:PH0PR18MB5071.namprd18.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230031)(1800799015)(376005)(366007); DIR:OUT; SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?tcVpPRwvyOXgpKVkmdwjhnwoRg/tpsQDoEOkKW3Kj1tPkbI/Ka5KRr8CgxMq?= =?us-ascii?Q?7FAyTmR3rYjbOkn/NPUEQ10da9Hwvrp17aHeUmJ5wihyl8vcQetgmvug8pSA?= =?us-ascii?Q?/YtYPul4YFI1U3hnmUGjqZJ1dZYsA2q2HDDWCP7R782rnVbdPqn81tEh2vHp?= =?us-ascii?Q?ONHGZDy2fUD7hodDrwFtIA2h+hQprQ1UvJYQvG1gZM6nrE7MTY+nylC1vEjp?= =?us-ascii?Q?BZw7ZEW45iNVqDcOSy3qOoy0GJEz607EFZDfY8s9XcwzpMj4zw9/oJTZIqqd?= =?us-ascii?Q?5TThxkbjcz+u6PufnENePxx5/HxEKe7/wy6t9Y9YmgFlcC2f+GPMq6dOIO8x?= =?us-ascii?Q?metcjOYsq8QcR3dsa0sOT9nJEx/lc8vVhdEbvS0l/Q8yYBQh3VXjROXQXeWI?= =?us-ascii?Q?9LTdlA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gu/34?= =?us-ascii?Q?Ohn2rA8h5XwvSKJDlIKPl8FBGwmF3PDbknN6mRp7NX9vYoMQaKIssVGrnZwC?= =?us-ascii?Q?lKqJuFzhDvYynSnSFXH7ioaM7ZszYd7GReWoFwehaxLV3s9f6q0ORd3x0G3g?= =?us-ascii?Q?hDvsvYxxpKvYHKNRNgvtGeB2I9PzkbC0QGNDBECOO6tTr1C6P91QWyxT40IV?= =?us-ascii?Q?Jvc+XzMKsSCgB9nCD63bsnfJRl84EO2773bX8k83N1AttVH+WgP07EXeyDCt?= =?us-ascii?Q?ODmSG3ghJP0s4ppbxZKfD5PadR1cRxHuEaIGdYhP?= Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: marvell.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: PH0PR18MB5071.namprd18.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 72328a03-bbc8-4326-79a8-08dc53aecc1a X-MS-Exchange-CrossTenant-originalarrivaltime: 03 Apr 2024 07:22:19.3059 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 70e1fb47-1155-421d-87fc-2e58f638b6e0 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: fIaOcRJbqPfzY+agdOmta/qULc7gFOvAM5NYASq8xXEHRal4pgNjoDYS/k6un/K7WHN5HP4AOX4NIFFHVzQr8Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN0PR18MB6039 X-Proofpoint-GUID: 3PHe_fsrKDXMzVdITxqnwDmc3tpDZ8mF X-Proofpoint-ORIG-GUID: 3PHe_fsrKDXMzVdITxqnwDmc3tpDZ8mF X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-04-03_06,2024-04-01_01,2023-05-22_02 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 > -----Original Message----- > From: Robin Jarry > Sent: Tuesday, April 2, 2024 2:07 AM > To: dev@dpdk.org; Jerin Jacob ; Kiran Kumar > Kokkilagadda ; Nithin Kumar Dabilpuram > ; Zhirun Yan > Subject: [EXTERNAL] [PATCH v2] graph: avoid accessing graph list when get= ting > stats >=20 > Prioritize security for external emails: Confirm sender and content safet= y > before clicking links or opening attachments >=20 > ---------------------------------------------------------------------- > In rte_graph_cluster_stats_get, the walk model of the first graph is chec= ked > to determine if multi-core dispatch specific counters should be updated o= r > not. This global list is accessed without any locks. >=20 > If the global list is modified by another thread while > rte_graph_cluster_stats_get is called, it can result in undefined behavio= ur. >=20 > Adding a lock would make it impossible to call rte_graph_cluster_stats_ge= t in > packet processing code paths. Avoid accessing the global list instead by > storing a bool field in the private rte_graph_cluster_stats structure. >=20 > Also update the default callback to avoid accessing the global list and u= se a > different default callback depending on the graph model. >=20 > Signed-off-by: Robin Jarry > --- Acked-by: Kiran Kumar Kokkilagadda >=20 > Notes: > v2: >=20 > * (kiran) removed unnecessary loop in stats_mem_init. >=20 > lib/graph/graph_stats.c | 57 ++++++++++++++++++++++++++--------------- > 1 file changed, 36 insertions(+), 21 deletions(-) >=20 > diff --git a/lib/graph/graph_stats.c b/lib/graph/graph_stats.c index > 2fb808b21ec5..d71451a17b95 100644 > --- a/lib/graph/graph_stats.c > +++ b/lib/graph/graph_stats.c > @@ -34,6 +34,7 @@ struct __rte_cache_aligned rte_graph_cluster_stats { > uint32_t cluster_node_size; /* Size of struct cluster_node */ > rte_node_t max_nodes; > int socket_id; > + bool dispatch; > void *cookie; > size_t sz; >=20 > @@ -74,17 +75,16 @@ print_banner_dispatch(FILE *f) } >=20 > static inline void > -print_banner(FILE *f) > +print_banner(FILE *f, bool dispatch) > { > - if > (rte_graph_worker_model_get(STAILQ_FIRST(graph_list_head_get())->graph) > =3D=3D > - RTE_GRAPH_MODEL_MCORE_DISPATCH) > + if (dispatch) > print_banner_dispatch(f); > else > print_banner_default(f); > } >=20 > static inline void > -print_node(FILE *f, const struct rte_graph_cluster_node_stats *stat) > +print_node(FILE *f, const struct rte_graph_cluster_node_stats *stat, > +bool dispatch) > { > double objs_per_call, objs_per_sec, cycles_per_call, ts_per_hz; > const uint64_t prev_calls =3D stat->prev_calls; @@ -104,8 +104,7 @@ > print_node(FILE *f, const struct rte_graph_cluster_node_stats *stat) > objs_per_sec =3D ts_per_hz ? (objs - prev_objs) / ts_per_hz : 0; > objs_per_sec /=3D 1000000; >=20 > - if > (rte_graph_worker_model_get(STAILQ_FIRST(graph_list_head_get())->graph) > =3D=3D > - RTE_GRAPH_MODEL_MCORE_DISPATCH) { > + if (dispatch) { > fprintf(f, > "|%-31s|%-15" PRIu64 "|%-15" PRIu64 "|%-15" PRIu64 > "|%-15" PRIu64 "|%-15" PRIu64 > @@ -123,20 +122,17 @@ print_node(FILE *f, const struct > rte_graph_cluster_node_stats *stat) } >=20 > static int > -graph_cluster_stats_cb(bool is_first, bool is_last, void *cookie, > +graph_cluster_stats_cb(bool dispatch, bool is_first, bool is_last, void > +*cookie, > const struct rte_graph_cluster_node_stats *stat) { > FILE *f =3D cookie; > - int model; > - > - model =3D > rte_graph_worker_model_get(STAILQ_FIRST(graph_list_head_get())->graph); >=20 > if (unlikely(is_first)) > - print_banner(f); > + print_banner(f, dispatch); > if (stat->objs) > - print_node(f, stat); > + print_node(f, stat, dispatch); > if (unlikely(is_last)) { > - if (model =3D=3D RTE_GRAPH_MODEL_MCORE_DISPATCH) > + if (dispatch) > boarder_model_dispatch(); > else > boarder(); > @@ -145,6 +141,20 @@ graph_cluster_stats_cb(bool is_first, bool is_last, > void *cookie, > return 0; > }; >=20 > +static int > +graph_cluster_stats_cb_rtc(bool is_first, bool is_last, void *cookie, > + const struct rte_graph_cluster_node_stats *stat) { > + return graph_cluster_stats_cb(false, is_first, is_last, cookie, stat); > +}; > + > +static int > +graph_cluster_stats_cb_dispatch(bool is_first, bool is_last, void *cooki= e, > + const struct rte_graph_cluster_node_stats > *stat) { > + return graph_cluster_stats_cb(true, is_first, is_last, cookie, stat); > +}; > + > static struct rte_graph_cluster_stats * stats_mem_init(struct cluster *= cluster, > const struct rte_graph_cluster_stats_param *prm) @@ -157,8 > +167,13 @@ stats_mem_init(struct cluster *cluster, >=20 > /* Fix up callback */ > fn =3D prm->fn; > - if (fn =3D=3D NULL) > - fn =3D graph_cluster_stats_cb; > + if (fn =3D=3D NULL) { > + const struct rte_graph *graph =3D cluster->graphs[0]->graph; > + if (graph->model =3D=3D RTE_GRAPH_MODEL_MCORE_DISPATCH) > + fn =3D graph_cluster_stats_cb_dispatch; > + else > + fn =3D graph_cluster_stats_cb_rtc; > + } >=20 > cluster_node_size =3D sizeof(struct cluster_node); > /* For a given cluster, max nodes will be the max number of graphs > */ @@ -350,6 +365,8 @@ rte_graph_cluster_stats_create(const struct > rte_graph_cluster_stats_param *prm) > if (stats_mem_populate(&stats, graph_fp, > graph_node)) > goto realloc_fail; > } > + if (graph->graph->model =3D=3D > RTE_GRAPH_MODEL_MCORE_DISPATCH) > + stats->dispatch =3D true; > } >=20 > /* Finally copy to hugepage memory to avoid pressure on rte_realloc > */ @@ -375,20 +392,18 @@ rte_graph_cluster_stats_destroy(struct > rte_graph_cluster_stats *stat) } >=20 > static inline void > -cluster_node_arregate_stats(struct cluster_node *cluster) > +cluster_node_arregate_stats(struct cluster_node *cluster, bool > +dispatch) > { > uint64_t calls =3D 0, cycles =3D 0, objs =3D 0, realloc_count =3D 0; > struct rte_graph_cluster_node_stats *stat =3D &cluster->stat; > uint64_t sched_objs =3D 0, sched_fail =3D 0; > struct rte_node *node; > rte_node_t count; > - int model; >=20 > - model =3D > rte_graph_worker_model_get(STAILQ_FIRST(graph_list_head_get())->graph); > for (count =3D 0; count < cluster->nb_nodes; count++) { > node =3D cluster->nodes[count]; >=20 > - if (model =3D=3D RTE_GRAPH_MODEL_MCORE_DISPATCH) { > + if (dispatch) { > sched_objs +=3D node->dispatch.total_sched_objs; > sched_fail +=3D node->dispatch.total_sched_fail; > } > @@ -403,7 +418,7 @@ cluster_node_arregate_stats(struct cluster_node > *cluster) > stat->objs =3D objs; > stat->cycles =3D cycles; >=20 > - if (model =3D=3D RTE_GRAPH_MODEL_MCORE_DISPATCH) { > + if (dispatch) { > stat->dispatch.sched_objs =3D sched_objs; > stat->dispatch.sched_fail =3D sched_fail; > } > @@ -433,7 +448,7 @@ rte_graph_cluster_stats_get(struct > rte_graph_cluster_stats *stat, bool skip_cb) > cluster =3D stat->clusters; >=20 > for (count =3D 0; count < stat->max_nodes; count++) { > - cluster_node_arregate_stats(cluster); > + cluster_node_arregate_stats(cluster, stat->dispatch); > if (!skip_cb) > rc =3D stat->fn(!count, (count =3D=3D stat->max_nodes - 1), > stat->cookie, &cluster->stat); > -- > 2.44.0