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 226F041DB0; Thu, 2 Mar 2023 02:30:30 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 1344640DFB; Thu, 2 Mar 2023 02:30:30 +0100 (CET) Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2080.outbound.protection.outlook.com [40.107.21.80]) by mails.dpdk.org (Postfix) with ESMTP id 8CED74021F for ; Thu, 2 Mar 2023 02:30:28 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=SCZRknj8hDE6SaLsM42nlMSXL326HqrxLVc3L5lUmfA=; b=f+LPwwty3HXPjSNMsjyL6b/YraFyTXeqqVYRcnvRiVR1mjziNPVKVZ/Ey0vdsdEEpyDkmACw1eOYnWVjVxj4GVrsCdCFFDLgTnAH3pYX+uHxh4tCo7uuLQo9SMjf+/lauM6Ea0g5BvBDROmCvT1so9rhKzYUk39KxpwLcSgH85c= Received: from DB6PR0501CA0032.eurprd05.prod.outlook.com (2603:10a6:4:67::18) by DB4PR08MB8030.eurprd08.prod.outlook.com (2603:10a6:10:38a::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6134.30; Thu, 2 Mar 2023 01:30:25 +0000 Received: from DBAEUR03FT032.eop-EUR03.prod.protection.outlook.com (2603:10a6:4:67:cafe::9a) by DB6PR0501CA0032.outlook.office365.com (2603:10a6:4:67::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6156.18 via Frontend Transport; Thu, 2 Mar 2023 01:30:25 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; pr=C Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by DBAEUR03FT032.mail.protection.outlook.com (100.127.142.185) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6156.18 via Frontend Transport; Thu, 2 Mar 2023 01:30:25 +0000 Received: ("Tessian outbound 55ffa3012b8f:v135"); Thu, 02 Mar 2023 01:30:25 +0000 X-CR-MTA-TID: 64aa7808 Received: from 6734d9943a5c.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 0C5875B0-0550-4C38-B92E-44AC0E444355.1; Thu, 02 Mar 2023 01:30:18 +0000 Received: from EUR04-HE1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 6734d9943a5c.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Thu, 02 Mar 2023 01:30:18 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ghi7EeG0ddAXysxl2mdG5QHIf8Wl+Y1SlMcSO9L0V6TZx8pmuPuUAyKeFpcgL9ktd7hAQPj4g+6Zn6EJshAAZ6jhBQflBBtkGS9uDE5+C2fT3eobm4o/0pSOl0vi2uH1eatv0bAGeXCvJxGFY+tlBCt3Ot3I36m87SkLLAGHj4eK2qgUeRyXf+x1qWfMw0YI9yrARLQ+mR2IEMak7sKow+nwzrVdEkfrECvIiBEwKMu0rJEaGWmHvhh3STrjZi8+Hm4jnPBi8p0PkKKTQ/MRtFKHC8KgD4aJen8S2TaeI4z75cE6DMZ4Fyh1q5upZ7b5abAVjj4NVTEAyIGk0uQgGg== 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=SCZRknj8hDE6SaLsM42nlMSXL326HqrxLVc3L5lUmfA=; b=dRyZk9ZtTFDROVAoKLT1iJT9h/Qf+Kos+be4o13hHWV+Ierp3JTPT7jEUT06RzGa8ByUBEhtNxN/wkALJhCy6V6NeafQrV6POVfQSGLMFCDyECtm96TgGhh+pF6ev+J41zXhuVoCfSvtv7YpMI6DD1/zMXtVH4PVb3NW79en6nh4G+oqWeI9tplIZdXrAe7OdQxd+FFZZ9Tw3qFNTTOZ3D7Dq/ii2LIpL8kTWjYBRydCGtSVVfh5wWV3lkFsbqI1N71GlKJZEF1P1SupAh7BPRvKbOjJNuijvqcrQljSmrWNZ1S/+Dp5DbBHjS9qQx347H15I3v9fMdhaSYX9WGoeA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=SCZRknj8hDE6SaLsM42nlMSXL326HqrxLVc3L5lUmfA=; b=f+LPwwty3HXPjSNMsjyL6b/YraFyTXeqqVYRcnvRiVR1mjziNPVKVZ/Ey0vdsdEEpyDkmACw1eOYnWVjVxj4GVrsCdCFFDLgTnAH3pYX+uHxh4tCo7uuLQo9SMjf+/lauM6Ea0g5BvBDROmCvT1so9rhKzYUk39KxpwLcSgH85c= Received: from DBAPR08MB5814.eurprd08.prod.outlook.com (2603:10a6:10:1b1::6) by GV2PR08MB9253.eurprd08.prod.outlook.com (2603:10a6:150:e3::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6156.17; Thu, 2 Mar 2023 01:30:14 +0000 Received: from DBAPR08MB5814.eurprd08.prod.outlook.com ([fe80::910e:e35f:b1eb:ae9]) by DBAPR08MB5814.eurprd08.prod.outlook.com ([fe80::910e:e35f:b1eb:ae9%5]) with mapi id 15.20.6156.018; Thu, 2 Mar 2023 01:30:14 +0000 From: Honnappa Nagarahalli To: Tyler Retzlaff , "dev@dpdk.org" , "david.marchand@redhat.com" CC: "thomas@monjalon.net" , nd , nd Subject: RE: [PATCH v2] eal: fix thread race in control thread creation Thread-Topic: [PATCH v2] eal: fix thread race in control thread creation Thread-Index: AQHZTIIr58vajsFiwkSJVw8aJEccNq7msuAg Date: Thu, 2 Mar 2023 01:30:13 +0000 Message-ID: References: <1677518230-1194-1-git-send-email-roretzla@linux.microsoft.com> <1677704982-2643-1-git-send-email-roretzla@linux.microsoft.com> In-Reply-To: <1677704982-2643-1-git-send-email-roretzla@linux.microsoft.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ts-tracking-id: 547BFC8C79174B4281A1DC2CCA0B76EE.0 x-checkrecipientchecked: true Authentication-Results-Original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; x-ms-traffictypediagnostic: DBAPR08MB5814:EE_|GV2PR08MB9253:EE_|DBAEUR03FT032:EE_|DB4PR08MB8030:EE_ X-MS-Office365-Filtering-Correlation-Id: a05d93e3-ea16-42ce-0908-08db1abdb2e7 x-ld-processed: f34e5979-57d9-4aaa-ad4d-b122a662184d,ExtAddr x-checkrecipientrouted: true nodisclaimer: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: VklsBhS+iWV+hHJABM1UG4vozfyZ4w3Z1rJ9oQHqtJai+ADUsoQMwVtUJvVFKPS+C1eZ+GxR12Q+tZ1Y/kfHaYbWnU7DJ18QapY9fhfs14H+rIyV2ucs0HQAAoWsgYg8bKfaT1r7SkwPyDNCAgKRIzsIMaftatiXc206J0t2GDCtOVv7H/lvmga2EmMroaBBHlzlpn4ev6jHihcYyu8h9WIXCSvCIlg04PbzpXnggTwLxAB2++TkSRCzSc9D6gv40bWZIeaxTS/kDaWWgR4nzVYDOoOWVgsTC56P5kkwoWN6zD8M9TzIb3Z9/1DbOadmWa651O4KMf3p/iadNY83s/O0Jzmi0kSrcNHcfIo6Z8/mOxJUzV/GpFXoyh6sj2Q9AD8KtOS4VLlXqwavz5Vgj1ZZw8B5lJdEpdP0AdY3PacfW7hcZOWqeQSDQNXqKiJ7vrKxIGlzQzrh9Hd83KlDFydmmMj7F6N97g3rjGKOxMnEgoyuU3uDmOE8J360hU3lnmYTdFqNNytsmh5Bfte0BKwVSLNwYNXxxtH5Ncgobz62NfE8FatAEyqMncfxIDZ194PfY9X98CxnOZ/0GRRqw+iQTqzSYdqQMXmAf7XNjQ6AAqKZw7XPXoa+L3uAVtzfFbZFxF1Olqi+M1OJVkFHk1p/JX6NT8GIEsswuWMUlVXdLqsT7M40cfpaEcEMQjR0Tie2CufRUIhZ2CQbD4SbFQ== X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DBAPR08MB5814.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230025)(4636009)(136003)(346002)(376002)(39860400002)(396003)(366004)(451199018)(83380400001)(66476007)(33656002)(122000001)(38100700002)(8936002)(478600001)(5660300002)(86362001)(55016003)(66446008)(38070700005)(186003)(9686003)(71200400001)(4326008)(53546011)(6506007)(66556008)(64756008)(7696005)(2906002)(76116006)(8676002)(52536014)(66946007)(316002)(41300700001)(110136005)(54906003); DIR:OUT; SFP:1101; Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-MS-Exchange-Transport-CrossTenantHeadersStamped: GV2PR08MB9253 Original-Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: DBAEUR03FT032.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: d6062692-0587-4802-f5b5-08db1abdabfe X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: lB5rrcOnruoWHWJKMoH7xbCyeGgAnm5dMbPnSmPxe91Eo0UJJganKy+pR34n3FzWrSoyZlM/8RY4YTyy2ooRSd9nC4/aCwaOtaP94J6DPyr6z6rdXN3zS0F3tc+yITGGDUx32QuMQQjaj92mLDBeXw4Rh/gP67typwNpXJzjScrfjR3QHc55QAyTDetBj1yegpb7kuDbrPnhlt4QVtwrUCFgPBSeSIsx6/EeMwW6mDYR8CfnxnxIt1SjPmW3BiH6dYlhFPT2X/5JoX6GaCWC7Q0O4nfIUGPNSEVqXGgb0U3n0BnT6V+RPs+DxNAbRasUAUCRKVuT5RZgNOmT9pZl4kAqF3hbi1NZw26wvsu2eObz5tm6diiixx7lWdDZBwG+rDoBgKQ1UTfULpaaguWXVE+cT03kUS54RaZuUmzC6TuQ+QGOBGlhWvKckhDztM6JriQ3uKYNfN5yuWpi4276bWE4Ae05zhpJnl7cGJLx8gvW+nL4FSzYxPO1D1eIFiNIxOnXHOW4k5oc4g0JZctHiAHCkOnu5w8gTaS7+Z/53RUFRnw7bscHyS2UeIyzX02jS5g+PoLPLaq8WpHOWNxVZWsHDqciyyyIWXYWx7TLmhyxha0lIedNYcpexASPl7M3lwfinr7i0y6R1E5sUcHas+NoGj7t+Vl39e3IaT9uMTUm+ks6XFsWpNlUZg225gzqRcsqp17lBkckm1nqr99vlw== X-Forefront-Antispam-Report: CIP:63.35.35.123; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:64aa7808-outbound-1.mta.getcheckrecipient.com; PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com; CAT:NONE; SFS:(13230025)(4636009)(346002)(39860400002)(396003)(136003)(376002)(451199018)(46966006)(40470700004)(36840700001)(336012)(47076005)(53546011)(8676002)(9686003)(186003)(26005)(81166007)(41300700001)(52536014)(82740400003)(55016003)(356005)(8936002)(40480700001)(478600001)(70586007)(86362001)(70206006)(40460700003)(4326008)(82310400005)(83380400001)(5660300002)(316002)(110136005)(33656002)(36860700001)(2906002)(7696005)(54906003)(6506007); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Mar 2023 01:30:25.5527 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a05d93e3-ea16-42ce-0908-08db1abdb2e7 X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d; Ip=[63.35.35.123]; Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: DBAEUR03FT032.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB4PR08MB8030 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: Tyler Retzlaff > Sent: Wednesday, March 1, 2023 3:10 PM > To: dev@dpdk.org; david.marchand@redhat.com > Cc: thomas@monjalon.net; Tyler Retzlaff > Subject: [PATCH v2] eal: fix thread race in control thread creation >=20 > When ctrl_thread_init transitions params->ctrl_thread_status from > CTRL_THREAD_LAUNCHING the creating thread and new thread may run > concurrently leading to unsynchronized access to params. IMO, the code will be simpler if we did not free 'params' in 'rte_thread_cr= eate_control'/'rte_ctrl_thread_create'. We could avoid creating the local c= opies of start_routine and the arg. See more comments below. >=20 > This permits races for both the failure and success paths after ctrl_thre= ad_status > is stored. > * params->ret may be loaded in ctrl_thread_init failure path > * params->arg may be loaded in ctrl_thread_start or > control_thread_start when calling start_routine. >=20 > For ctrl_thread_init remove the params->ret load and just return 1 since = it is > only interpreted as a indicator of success / failure of ctrl_thread_init. >=20 > For {ctrl,control}_thread_start store param->arg in stack allocated stora= ge prior > to calling ctrl_thread_init and use the copy when calling start_routine. >=20 > For control_thread_start if ctrl_thread_init fails just return 0 instead = of loading > params->ret, since the value returned is unused when ctrl_thread_status i= s set > to CTRL_THREAD_ERROR when ctrl_thread_init fails. >=20 > Fixes: 878b7468eacb ("eal: add platform agnostic control thread API") >=20 > Signed-off-by: Tyler Retzlaff > Reviewed-by: David Marchand > --- > lib/eal/common/eal_common_thread.c | 10 ++++++---- > 1 file changed, 6 insertions(+), 4 deletions(-) >=20 > diff --git a/lib/eal/common/eal_common_thread.c > b/lib/eal/common/eal_common_thread.c > index edb9d4e..079a385 100644 > --- a/lib/eal/common/eal_common_thread.c > +++ b/lib/eal/common/eal_common_thread.c > @@ -256,7 +256,7 @@ static int ctrl_thread_init(void *arg) > if (params->ret !=3D 0) { > __atomic_store_n(¶ms->ctrl_thread_status, > CTRL_THREAD_ERROR, __ATOMIC_RELEASE); > - return params->ret; > + return 1; > } >=20 > __atomic_store_n(¶ms->ctrl_thread_status, > @@ -268,23 +268,25 @@ static int ctrl_thread_init(void *arg) static void > *ctrl_thread_start(void *arg) { > struct rte_thread_ctrl_params *params =3D arg; > + void *start_arg =3D params->arg; > void *(*start_routine)(void *) =3D params->u.ctrl_start_routine; These copies can be avoided, code will be much simpler >=20 > if (ctrl_thread_init(arg) !=3D 0) > return NULL; >=20 > - return start_routine(params->arg); > + return start_routine(start_arg); We can free 'params' here after 'start_routine' returns. > } >=20 > static uint32_t control_thread_start(void *arg) { > struct rte_thread_ctrl_params *params =3D arg; > + void *start_arg =3D params->arg; > rte_thread_func start_routine =3D params->u.control_start_routine; >=20 > if (ctrl_thread_init(arg) !=3D 0) > - return params->ret; > + return 0; >=20 > - return start_routine(params->arg); > + return start_routine(start_arg); > } >=20 > int > -- > 1.8.3.1