From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <stable-bounces@dpdk.org>
Received: from dpdk.org (dpdk.org [92.243.14.124])
	by inbox.dpdk.org (Postfix) with ESMTP id 775B9A0350
	for <public@inbox.dpdk.org>; Mon, 22 Jun 2020 11:09:12 +0200 (CEST)
Received: from [92.243.14.124] (localhost [127.0.0.1])
	by dpdk.org (Postfix) with ESMTP id 6AD411C0D2;
	Mon, 22 Jun 2020 11:09:12 +0200 (CEST)
Received: from EUR03-VE1-obe.outbound.protection.outlook.com
 (mail-eopbgr50070.outbound.protection.outlook.com [40.107.5.70])
 by dpdk.org (Postfix) with ESMTP id 149EC1C0CC;
 Mon, 22 Jun 2020 11:09:11 +0200 (CEST)
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=yDSVahfrqxtcgo9ja6adbpVO/lIANF5RrZZrKkggGws=;
 b=aeIPKJ35R7U+39RHp4JWUyra5rdUbgM67WY45Tam/71ObTaY+CVfGkyvxwdHtrxpGFCLYFkBGdjB8HYOGcGNW6I24plE/pDxmt1hMp4qAFpDO4n1FQRN6KaJnltwgGtWbzxSV+c6ErCX8RdgStex4V0kNUYE71NocPsg6L3BNZA=
Received: from AM5PR0701CA0050.eurprd07.prod.outlook.com (2603:10a6:203:2::12)
 by AM6PR08MB3128.eurprd08.prod.outlook.com (2603:10a6:209:45::20)
 with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3109.25; Mon, 22 Jun
 2020 09:09:09 +0000
Received: from AM5EUR03FT044.eop-EUR03.prod.protection.outlook.com
 (2603:10a6:203:2:cafe::f) by AM5PR0701CA0050.outlook.office365.com
 (2603:10a6:203:2::12) with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3131.11 via Frontend
 Transport; Mon, 22 Jun 2020 09:09:09 +0000
X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123)
 smtp.mailfrom=arm.com; dpdk.org; dkim=pass (signature was verified)
 header.d=armh.onmicrosoft.com;dpdk.org; dmarc=bestguesspass 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;
Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by
 AM5EUR03FT044.mail.protection.outlook.com (10.152.17.56) with
 Microsoft SMTP
 Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id
 15.20.3109.22 via Frontend Transport; Mon, 22 Jun 2020 09:09:09 +0000
Received: ("Tessian outbound 022d32fb9a40:v59");
 Mon, 22 Jun 2020 09:09:09 +0000
X-CR-MTA-TID: 64aa7808
Received: from ed5b51e675e8.2
 by 64aa7808-outbound-1.mta.getcheckrecipient.com id
 C5A24B5D-FBF3-4BE3-8029-615E536332B2.1; 
 Mon, 22 Jun 2020 09:09:04 +0000
Received: from EUR03-VE1-obe.outbound.protection.outlook.com
 by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id ed5b51e675e8.2
 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384);
 Mon, 22 Jun 2020 09:09:04 +0000
ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none;
 b=CdE/9tRzIxM8SZSNlo65t/29N0V2p55E3aVcXJYAVpJuZ2hXZk0uiR+v4/OZskp3GwNDzJZbRGz/JLeXwHFk9XHleMh/3pfqP7kEjCtiLQh14fshBsokl+8Z5b6qQGnhRJ7nIXs7sYPsMIVf/drAKU5fuaM8FJesuNcmGzDrhuSsHwtgSAqiybS0l2UQMlMZ2ZsxYsE9vSsw7qBcdv60WeEzJdS5LRADnyzux2CSxTgon+2PCp8KxEODGz1WtQx7HZUlYRMacTdMwffrDzGXSE/9n+EZD49i4b4ENcVjeRLgeuToCuRmRBWMJuajcGwzErQODCnqhC/Dhs/+nRuiGw==
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-SenderADCheck;
 bh=yDSVahfrqxtcgo9ja6adbpVO/lIANF5RrZZrKkggGws=;
 b=TE0P4KJQ5yi+4hZINtQrWJ0XKVS+VrPJyxS89Dd4MhpuC+rVwyCCxF8d92c5ujyqteOTOVzLBBt7t4H9udvQcjvN0W3RMSUzwLaJAgkpRMyS0jGovT9QtrQmiTASmrko5gq204he0N/O9Syn/KKth4pvfferBw5otKZFSGYVNk/93mVPGgoHj4ZpoBgPNX94yclFrp8AcB8lt7ors9LKjbl/8Ws9nt1lwGYZOOuLB/VIRg5T+CrmIRq3DwQR6OQ4srV1Ii26aPlfg/kE7oo/tMX9N22s/RC+rZP9AU+PTlWPOf4ZosppIk678Nw/IQWiBKQkxB0rsFSBgOVps3/pkw==
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=yDSVahfrqxtcgo9ja6adbpVO/lIANF5RrZZrKkggGws=;
 b=aeIPKJ35R7U+39RHp4JWUyra5rdUbgM67WY45Tam/71ObTaY+CVfGkyvxwdHtrxpGFCLYFkBGdjB8HYOGcGNW6I24plE/pDxmt1hMp4qAFpDO4n1FQRN6KaJnltwgGtWbzxSV+c6ErCX8RdgStex4V0kNUYE71NocPsg6L3BNZA=
Received: from VE1PR08MB4640.eurprd08.prod.outlook.com (2603:10a6:802:b2::11)
 by VE1PR08MB4877.eurprd08.prod.outlook.com (2603:10a6:802:a4::18)
 with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3109.22; Mon, 22 Jun
 2020 09:09:02 +0000
Received: from VE1PR08MB4640.eurprd08.prod.outlook.com
 ([fe80::c2e:9ccb:a690:6863]) by VE1PR08MB4640.eurprd08.prod.outlook.com
 ([fe80::c2e:9ccb:a690:6863%6]) with mapi id 15.20.3109.027; Mon, 22 Jun 2020
 09:09:02 +0000
From: Phil Yang <Phil.Yang@arm.com>
To: "Carrillo, Erik G" <erik.g.carrillo@intel.com>, "dev@dpdk.org"
 <dev@dpdk.org>
CC: "drc@linux.vnet.ibm.com" <drc@linux.vnet.ibm.com>, Honnappa Nagarahalli
 <Honnappa.Nagarahalli@arm.com>, Ruifeng Wang <Ruifeng.Wang@arm.com>, Dharmik
 Thakkar <Dharmik.Thakkar@arm.com>, nd <nd@arm.com>, "stable@dpdk.org"
 <stable@dpdk.org>
Thread-Topic: [PATCH 1/3] eventdev: fix race condition on timer list counter
Thread-Index: AQHWRYO0C4+OtcPfIEys7qAlWeZDrqjkXggA
Date: Mon, 22 Jun 2020 09:09:02 +0000
Message-ID: <VE1PR08MB464096E31E30520EDA379093E9970@VE1PR08MB4640.eurprd08.prod.outlook.com>
References: <1591960798-24024-1-git-send-email-phil.yang@arm.com>
 <CY4PR1101MB2118653CE0272DB20268C2B9B99B0@CY4PR1101MB2118.namprd11.prod.outlook.com>
In-Reply-To: <CY4PR1101MB2118653CE0272DB20268C2B9B99B0@CY4PR1101MB2118.namprd11.prod.outlook.com>
Accept-Language: zh-CN, en-US
Content-Language: en-US
X-MS-Has-Attach: 
X-MS-TNEF-Correlator: 
x-ts-tracking-id: c11b7339-545d-49d8-a282-84712a3f6a8f.0
x-checkrecipientchecked: true
Authentication-Results-Original: intel.com; dkim=none (message not signed)
 header.d=none;intel.com; dmarc=none action=none header.from=arm.com;
x-originating-ip: [203.126.0.112]
x-ms-publictraffictype: Email
X-MS-Office365-Filtering-HT: Tenant
X-MS-Office365-Filtering-Correlation-Id: 79df2960-0122-4e22-8667-08d8168bec64
x-ms-traffictypediagnostic: VE1PR08MB4877:|AM6PR08MB3128:
x-ms-exchange-transport-forked: True
X-Microsoft-Antispam-PRVS: <AM6PR08MB3128FF243386E9C826C7A0B3E9970@AM6PR08MB3128.eurprd08.prod.outlook.com>
x-checkrecipientrouted: true
nodisclaimer: true
x-ms-oob-tlc-oobclassifiers: OLM:4941;OLM:4941;
x-forefront-prvs: 0442E569BC
X-MS-Exchange-SenderADCheck: 1
X-Microsoft-Antispam-Untrusted: BCL:0;
X-Microsoft-Antispam-Message-Info-Original: T7d84vzjj06p69rPfmgd28Y6Mpg3AXB+OjqQ6nOlqRtVRx73cqjdVqXUHrE29Fg4O/ZPJ/ZDLivC1VXI9IJnhP8cUwU0g7271KBSW4uqk2jEwKPoaYhi4DZHH46fN5scaKDHaKHtjk5haCEHpNEzqMmBd6tyi9Z6Dd/LWDV72mpPLRBtLba6tQnkeAymEtMDZZK5xiv4iuwUYT0GZ8DtG18NyVokG0/nXAerMZfS4A94PLuBf5LqG8kzANt/2V3UqOtfRSwbOaUPySlxQ8vD9vCXR5xDkAPlP7bd/NUz76X0/Pa07FxxdEk5XYa41OMdnH/Gh1O0wYTAe9neN/u5dA==
X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255; CTRY:; LANG:en;
 SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:VE1PR08MB4640.eurprd08.prod.outlook.com;
 PTR:; CAT:NONE; SFTY:;
 SFS:(4636009)(396003)(376002)(346002)(39860400002)(366004)(136003)(52536014)(33656002)(9686003)(316002)(2906002)(86362001)(478600001)(66446008)(66556008)(66476007)(55016002)(54906003)(64756008)(110136005)(76116006)(5660300002)(66946007)(26005)(6506007)(53546011)(8936002)(186003)(8676002)(7696005)(83380400001)(4326008)(71200400001);
 DIR:OUT; SFP:1101; 
x-ms-exchange-antispam-messagedata: UTfIJb9K1SK82L9wI7S5c67+x2+WuWPZDfwqlSzJvnB3Pw2A30aMJHDkUESLMDOLGkE9FVLSxXJEQVIJY5kD32+jjJXDgin1mfIRg2n5YIAQYPCNbbxppSUju62iQnOmPha/GCrYJlpMgktbQvVwI7ZrlIoLAWGschmZF23bzedv61+OW5ZnsZh9nYz/GfjQ+w+dC4i4v9mBiHKdBp+HKxduetI0vDeLR/+NXO0SQ8a0Jz9jM+DqcHayfKJE/HfnxFZw0CA87B+N0KQLWpIia1F0f17S9s7GUwrxp2h9ebaCwsIfI95eEN8WuzYJai2NM/cYRNdbjD/eeXRo/2GbCWTiWuMETugZojlM7GmNrYpe8NTv0ZwOArDx/GsDG364aZTnu3WhB7U87N62GWABaNmFN/w/2j/8ryIY/Y45TU4E19tVEtusA3UdaMaVQpHJQSdksL3tRo0UlPe6oSWIKl8YZKC8cTYTKw1yRh5Swuw=
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
MIME-Version: 1.0
X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1PR08MB4877
Original-Authentication-Results: intel.com; dkim=none (message not signed)
 header.d=none;intel.com; dmarc=none action=none header.from=arm.com;
X-EOPAttributedMessage: 0
X-MS-Exchange-Transport-CrossTenantHeadersStripped: AM5EUR03FT044.eop-EUR03.prod.protection.outlook.com
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; SFTY:;
 SFS:(4636009)(346002)(39860400002)(376002)(136003)(396003)(46966005)(70206006)(70586007)(33656002)(316002)(110136005)(52536014)(82740400003)(47076004)(54906003)(8936002)(2906002)(81166007)(4326008)(9686003)(450100002)(26005)(55016002)(86362001)(36906005)(186003)(5660300002)(8676002)(53546011)(6506007)(336012)(356005)(7696005)(82310400002)(478600001)(83380400001);
 DIR:OUT; SFP:1101; 
X-MS-Office365-Filtering-Correlation-Id-Prvs: dac99cba-6147-416f-8807-08d8168be847
X-Forefront-PRVS: 0442E569BC
X-Microsoft-Antispam: BCL:0;
X-Microsoft-Antispam-Message-Info: /MllVIFCjI3f4p7i3VhdwJ7D5prkkW8RVjg6pehG8SJFFcINo83tDh/wb7/94p+aLezSkWS+Sc0t6WwYcR8pMlk6Aw/DRDSenL6dzp3hj3yTq70Stg/mRpOr5BIxYbc00VQOFkVCYrWksbA1FAKTfNvWdLpiT1RIvLFxyyBh29SVK4UCztlrNgaAxHAF1Lf3HUFsVCR8t+eQvkJnuMQH4YdbWCW141yvi8zqHLfyOhgPbIl0BHw2SOoGFLc6QSZPD8ECTJaNAdCZQ1FWWFiYM7Bc+aciYl0EzuMQlMi/Bzhnto9pzMT/kW3fvLsj/mcBOCvE/JALmJLMsbuEiT5hmB/NiFoE5BioA/7bfXnIfXDE45ObsOno2SZOjXTd5MtM+DbQKo7Wf5akTIwdQLXZ9Q==
X-OriginatorOrg: arm.com
X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Jun 2020 09:09:09.4471 (UTC)
X-MS-Exchange-CrossTenant-Network-Message-Id: 79df2960-0122-4e22-8667-08d8168bec64
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-FromEntityHeader: HybridOnPrem
X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB3128
Subject: Re: [dpdk-stable] [PATCH 1/3] eventdev: fix race condition on timer
	list counter
X-BeenThere: stable@dpdk.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: patches for DPDK stable branches <stable.dpdk.org>
List-Unsubscribe: <https://mails.dpdk.org/options/stable>,
 <mailto:stable-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://mails.dpdk.org/archives/stable/>
List-Post: <mailto:stable@dpdk.org>
List-Help: <mailto:stable-request@dpdk.org?subject=help>
List-Subscribe: <https://mails.dpdk.org/listinfo/stable>,
 <mailto:stable-request@dpdk.org?subject=subscribe>
Errors-To: stable-bounces@dpdk.org
Sender: "stable" <stable-bounces@dpdk.org>

> -----Original Message-----
> From: Carrillo, Erik G <erik.g.carrillo@intel.com>
> Sent: Thursday, June 18, 2020 11:18 PM
> To: Phil Yang <Phil.Yang@arm.com>; dev@dpdk.org
> Cc: drc@linux.vnet.ibm.com; Honnappa Nagarahalli
> <Honnappa.Nagarahalli@arm.com>; Ruifeng Wang
> <Ruifeng.Wang@arm.com>; Dharmik Thakkar <Dharmik.Thakkar@arm.com>;
> nd <nd@arm.com>; stable@dpdk.org
> Subject: RE: [PATCH 1/3] eventdev: fix race condition on timer list count=
er
>=20
> Hi Phil,
>=20
> Good catch - thanks for the fix.   I've commented in-line:
>=20
> > -----Original Message-----
> > From: Phil Yang <phil.yang@arm.com>
> > Sent: Friday, June 12, 2020 6:20 AM
> > To: dev@dpdk.org; Carrillo, Erik G <erik.g.carrillo@intel.com>
> > Cc: drc@linux.vnet.ibm.com; honnappa.nagarahalli@arm.com;
> > ruifeng.wang@arm.com; dharmik.thakkar@arm.com; nd@arm.com;
> > stable@dpdk.org
> > Subject: [PATCH 1/3] eventdev: fix race condition on timer list counter
> >
> > The n_poll_lcores counter and poll_lcore array are shared between lcore=
s
> > and the update of these variables are out of the protection of spinlock=
 on
> > each lcore timer list. The read-modify-write operations of the counter =
are
> > not atomic, so it has the potential of race condition between lcores.
> >
> > Use c11 atomics with RELAXED ordering to prevent confliction.
> >
> > Fixes: cc7b73ea9e3b ("eventdev: add new software timer adapter")
> > Cc: erik.g.carrillo@intel.com
> > Cc: stable@dpdk.org
> >
> > Signed-off-by: Phil Yang <phil.yang@arm.com>
> > Reviewed-by: Dharmik Thakkar <dharmik.thakkar@arm.com>
> > Reviewed-by: Ruifeng Wang <ruifeng.wang@arm.com>
> > ---
> >  lib/librte_eventdev/rte_event_timer_adapter.c | 16 ++++++++++++----
> >  1 file changed, 12 insertions(+), 4 deletions(-)
> >
> > diff --git a/lib/librte_eventdev/rte_event_timer_adapter.c
> > b/lib/librte_eventdev/rte_event_timer_adapter.c
> > index 005459f..6a0e283 100644
> > --- a/lib/librte_eventdev/rte_event_timer_adapter.c
> > +++ b/lib/librte_eventdev/rte_event_timer_adapter.c
> > @@ -583,6 +583,7 @@ swtim_callback(struct rte_timer *tim)
> >  	uint16_t nb_evs_invalid =3D 0;
> >  	uint64_t opaque;
> >  	int ret;
> > +	int n_lcores;
> >
> >  	opaque =3D evtim->impl_opaque[1];
> >  	adapter =3D (struct rte_event_timer_adapter *)(uintptr_t)opaque;
> > @@ -605,8 +606,12 @@ swtim_callback(struct rte_timer *tim)
> >  				      "with immediate expiry value");
> >  		}
> >
> > -		if (unlikely(rte_atomic16_test_and_set(&sw-
> > >in_use[lcore].v)))
> > -			sw->poll_lcores[sw->n_poll_lcores++] =3D lcore;
> > +		if (unlikely(rte_atomic16_test_and_set(&sw-
> > >in_use[lcore].v))) {
> > +			n_lcores =3D __atomic_fetch_add(&sw->n_poll_lcores,
> > 1,
> > +						__ATOMIC_RELAXED);
>=20
> Just a nit, but let's align the continued line with the opening parenthes=
es in
> this location and below.  With these changes:

Thanks Erik.=20
I will do it in the new version.

>=20
> Acked-by: Erik Gabriel Carrillo <erik.g.carrillo@intel.com>
>=20
> > +			__atomic_store_n(&sw->poll_lcores[n_lcores],
> > lcore,
> > +						__ATOMIC_RELAXED);
> > +		}
> >  	} else {
> >  		EVTIM_BUF_LOG_DBG("buffered an event timer expiry
> > event");
> >
> > @@ -1011,6 +1016,7 @@ __swtim_arm_burst(const struct
> > rte_event_timer_adapter *adapter,
> >  	uint32_t lcore_id =3D rte_lcore_id();
> >  	struct rte_timer *tim, *tims[nb_evtims];
> >  	uint64_t cycles;
> > +	int n_lcores;
> >
> >  #ifdef RTE_LIBRTE_EVENTDEV_DEBUG
> >  	/* Check that the service is running. */ @@ -1033,8 +1039,10 @@
> > __swtim_arm_burst(const struct rte_event_timer_adapter *adapter,
> >  	if (unlikely(rte_atomic16_test_and_set(&sw->in_use[lcore_id].v))) {
> >  		EVTIM_LOG_DBG("Adding lcore id =3D %u to list of lcores to
> > poll",
> >  			      lcore_id);
> > -		sw->poll_lcores[sw->n_poll_lcores] =3D lcore_id;
> > -		++sw->n_poll_lcores;
> > +		n_lcores =3D __atomic_fetch_add(&sw->n_poll_lcores, 1,
> > +						__ATOMIC_RELAXED);
> > +		__atomic_store_n(&sw->poll_lcores[n_lcores], lcore_id,
> > +						__ATOMIC_RELAXED);
> >  	}
> >
> >  	ret =3D rte_mempool_get_bulk(sw->tim_pool, (void **)tims,
> > --
> > 2.7.4