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 4E75242AD5; Thu, 11 May 2023 10:10:25 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 2BFAC42D5E; Thu, 11 May 2023 10:10:25 +0200 (CEST) Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by mails.dpdk.org (Postfix) with ESMTP id 7225742D5D; Thu, 11 May 2023 10:10:22 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1683792623; x=1715328623; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=eckwQ+3ZfPmTruXRekqw+0ZOf2fC9qeep/sSVzI4GQE=; b=El+qE37No1P/QEvBFT6lGCu5RDoVkpgoIRqbU3gq/yZW7RrPoQPs4hrW mJ4rU7zHqIL1d0V5jKsft0QegBKLbMhoT1pJuoHd3O/annBfncL+trtMg GKh+PZagcjupGEiK+OT/Tn4mqVsErLLl6pNNTXD0wNmiuGUs3ijmlVIxp QKZNnz2O7olAI/6i3Wl3btosO6GjliGYsTyujUEpLsYzxdLNqZqH6Qmoz hbuQGckLn/cXcyZ3KcqWwALVRrzIAbIGXLowLapZUFz7cBNle3/++8PvT Gbf23c6iGBPYcl2nIhFZEPPQAILU9PnlqOmAq8aHLDCvnA+XjRHcld/RH A==; X-IronPort-AV: E=McAfee;i="6600,9927,10706"; a="339702740" X-IronPort-AV: E=Sophos;i="5.99,266,1677571200"; d="scan'208";a="339702740" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 May 2023 01:10:18 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10706"; a="702645279" X-IronPort-AV: E=Sophos;i="5.99,266,1677571200"; d="scan'208";a="702645279" Received: from fmsmsx602.amr.corp.intel.com ([10.18.126.82]) by fmsmga007.fm.intel.com with ESMTP; 11 May 2023 01:10:04 -0700 Received: from fmsmsx610.amr.corp.intel.com (10.18.126.90) by fmsmsx602.amr.corp.intel.com (10.18.126.82) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23; Thu, 11 May 2023 01:10:04 -0700 Received: from FMSEDG603.ED.cps.intel.com (10.1.192.133) by fmsmsx610.amr.corp.intel.com (10.18.126.90) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23 via Frontend Transport; Thu, 11 May 2023 01:10:04 -0700 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (104.47.66.43) by edgegateway.intel.com (192.55.55.68) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.23; Thu, 11 May 2023 01:10:04 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=eUC2U0C/8RaakhtfGpUimVrXIrk/QDFgTOt1+Noium2ooInc9w+LfMKAyVrsxHklEKYOBmg+6r36Cuensxk4262SWsj008xRORmpZlaAHfqiGsyzEw3n3VhDTSHiK4WeNedfPlnb4t8rz11J3WUoTmLF5vd9/eOafw4B62B73OONKA6TSD61CBQRXhltKHI2w4yUHl8cgXqfCadGjsbSjG9ok2QSxkJLTswljH3Di3jhpzvpUZBTDevK92y34vw+MdQc5udhuAdNXmbbi5wHfqA4XxqaxZueNnMPr3KscC4VabsbvfylOivIDTBGysXnGgU/c/RxAmSovXnsa2sLiQ== 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=DScc4oXErvh6TupFHrYT+qddD5yO2iuDToeHHYV0e8s=; b=ZFIem/x4nQVYczxhopTF7vgok7Gu1QH4lufzGAaQNo4RFYwTbrpDjHd2YBM4oSxAIHG2bICSVYz0YySIxHjeVZpqlV2lZfmQyq2XVcLLRS+OT42GZRm8taSolhvufcxVhem5/wswArSPbSN4qw4wuTYWgQk0vi7Nq4FDpF2JTsUWvL1jH/Fe+7uGHpu6rtG4pIcgjq137ka3/Cte6BoGtoUydKqCXxOIoxEH7+52HFJAv/xNtqr4DSJvvNjtnSLpquOskuERo/IvXgF6APqD0///3ZG1iAsG/tBRojRcg5W/636/9+j3CVegTWc1pR4E3prOcXpiSJnLfyyvIu9hlQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Received: from SN6PR11MB3504.namprd11.prod.outlook.com (2603:10b6:805:d0::17) by BL1PR11MB5509.namprd11.prod.outlook.com (2603:10b6:208:31f::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6387.20; Thu, 11 May 2023 08:10:02 +0000 Received: from SN6PR11MB3504.namprd11.prod.outlook.com ([fe80::e427:f0a6:8472:d0f6]) by SN6PR11MB3504.namprd11.prod.outlook.com ([fe80::e427:f0a6:8472:d0f6%6]) with mapi id 15.20.6387.019; Thu, 11 May 2023 08:10:02 +0000 From: "Xia, Chenbo" To: David Marchand , "dev@dpdk.org" CC: "stable@dpdk.org" , Maxime Coquelin , Yuanhan Liu Subject: RE: [PATCH] vhost: avoid sleeping under mutex Thread-Topic: [PATCH] vhost: avoid sleeping under mutex Thread-Index: AQHZXOCY4WhBi7gqJEyDEbyIkWDl2K9VBcHA Date: Thu, 11 May 2023 08:10:02 +0000 Message-ID: References: <20230322170524.2314715-1-david.marchand@redhat.com> In-Reply-To: <20230322170524.2314715-1-david.marchand@redhat.com> Accept-Language: en-US, zh-CN Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; x-ms-publictraffictype: Email x-ms-traffictypediagnostic: SN6PR11MB3504:EE_|BL1PR11MB5509:EE_ x-ms-office365-filtering-correlation-id: a226da4e-560c-4875-f814-08db51f71f09 x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: yyFEzUoFJFoLQZ6QgxKEE32OG7Hpyw5sRQ/24jdmBNzsuIIuCiFBbq3VRDu0XbZluN5idch7/Fqsd10MFfYDQWGO1En+rUzauHDlFDvmLsp/KeCYEFpwaDdPiF5CiVrCSMAJ+WAVOZ097TLDo6dA1zy6HbPsStZaoU64+THhYhaaUxsvogJ0MHkm30okI11JyO5UG8KrDPYGQc2zqCE7pmlf5UtKuyMDAIS7Y/EcgIZQzMN/RDzhTrxixu6Jmw1MR20T1kx7D2rwCUWXWfGpJbPYRIXVV1tyCJx12xQzr1pJZz82xxADUzdOHf3ZLW3HnfRhcZShUftss4MqXr9GyjbzK+Onl8GodDOlMkRF40WgLTyLSBrwxtbydZrh+fP0Z7sHjMsgFn+Aax9Crl8+P1vRuy819L14y6QQP0aNyMhRsD2lK/r7oWcWMW/+xVO2w3DY2m7RXiy2wRkrm54b2pNUxJ+sTFphHNEmv0EQYSw3OQQxJ+q+xX2e/NNlDMHFzYSvKtzuOU0/tIZhQM1Y6eAIMKY9kEhba7yPXpEHtd6ZH0oSxA+Yf86PuxkAOODA6ueF0ZwcWyZMkNcstDP0hV6IwKAHF0PvmQOOXA6UbMw= x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:SN6PR11MB3504.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230028)(346002)(366004)(396003)(376002)(136003)(39860400002)(451199021)(7696005)(71200400001)(8936002)(66946007)(54906003)(76116006)(66476007)(110136005)(66446008)(64756008)(2906002)(26005)(82960400001)(41300700001)(38100700002)(86362001)(38070700005)(52536014)(5660300002)(316002)(122000001)(8676002)(4326008)(66556008)(33656002)(55016003)(478600001)(53546011)(9686003)(6506007)(186003)(83380400001); DIR:OUT; SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?j4JC/p75+TAxy+50JQDKIUcSelDleEfA6RsIqOnsKG/ci3TZgfzlYIqTbof1?= =?us-ascii?Q?P5QyjA1isRsA0ClJ6xkYmzYl2y99HZgLejcRQBEc+iDkFMlW8nzsQHGE6+Lv?= =?us-ascii?Q?SLGvldm/nVRCuHUooCqYS0kQFGx87bHHE8Z4dnfNQ8zksxSHY8+wp4aYdx71?= =?us-ascii?Q?Ehy4vuyPSuSideKgXHr9FW6x9dQ02yXivMRMRuk3WtC/B3I6fc3WKIz4/zqq?= =?us-ascii?Q?Q5QDXMrCz85qbONRuSmJ4VHm8GyQ+LEAQWBcD6s73LMMEuGIqt2OHfKfYkO0?= =?us-ascii?Q?jJRbqm1V75CB1W6ABa7Cy0nLHCnikhCaUcrVSHfjT/CkCZdrbtPwMbtXlJJt?= =?us-ascii?Q?WShXjmsbXhKEGkv7I+oERYDeyB6eP3CYaaMor9EkopoSrWXvZ3+0/NJJ4u7S?= =?us-ascii?Q?ZKTSNGdcvlc4vh/bFAksUPq0hd8KOVuh6DjDFIKM0EZp7YuKd3DCTI9/krfy?= =?us-ascii?Q?reGnV02HQoeOwFx7q3dlpjw3uu6NMZeXvF73Bpee2FQgm5LVuhLkj8ZZZSMD?= =?us-ascii?Q?sO1XXK9At93pxeWb6P101rVOhzVrUw1XWyfvPpVh8kYHjqdnbDplU/aq/L6S?= =?us-ascii?Q?KUOk5GaOQmmgTySOWeNp6y0DOKfHk07aJBJPhAbjZZS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ktElyu0VynwZpDwHgpRmC2FI3aGnsP3/MzFF6yWuTLu?= =?us-ascii?Q?gXVHgGLbjogg1k4UqEI2MwuRECWWC2y0ksBaw2cO?= Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: SN6PR11MB3504.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: a226da4e-560c-4875-f814-08db51f71f09 X-MS-Exchange-CrossTenant-originalarrivaltime: 11 May 2023 08:10:02.2075 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: 1pGxf3P3gnasl0bmLeMqvTNiwmwiiemdWokQgxHnMNZim8HcJc/WDq6glZH3NixMv9uKxZQxA7kQ8nFS89Psiw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR11MB5509 X-OriginatorOrg: intel.com 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 Hi David, > -----Original Message----- > From: David Marchand > Sent: Thursday, March 23, 2023 1:05 AM > To: dev@dpdk.org > Cc: stable@dpdk.org; Maxime Coquelin ; Xia, > Chenbo ; Yuanhan Liu > Subject: [PATCH] vhost: avoid sleeping under mutex >=20 > Covscan reported: >=20 > 2. dpdk-21.11/lib/vhost/socket.c:852: lock_acquire: Calling function > "pthread_mutex_lock" acquires lock "vhost_user.mutex". > 23. dpdk-21.11/lib/vhost/socket.c:955: sleep: Call to > "vhost_user_reconnect_init" might sleep while holding lock > "vhost_user.mutex". > # 953| vsocket->reconnect =3D > !(flags & RTE_VHOST_USER_NO_RECONNECT); > # 954| if (vsocket->reconnect && reconn_tid =3D=3D 0) { > # 955|-> if (vhost_user_reconnect_init() !=3D 0) > # 956| goto out_mutex; > # 957| } >=20 > The reason for this warning is that vhost_user_reconnect_init() creates a > ctrl thread and calls nanosleep waiting for this thread to be ready, > while vhost_user.mutex is taken. >=20 > Move the call to vhost_user_reconnect_init() out of this mutex. >=20 > While at it, a pthread_t value should be considered opaque. > Instead of relying reconn_tid =3D=3D 0, use an internal flag in > vhost_user_reconnect_init(). Should we make reconn_tid not a global variable anymore then? Maybe a static pthread_t in vhost_user_reconnect_init? Thanks, Chenbo >=20 > Coverity issue: 373686 > Bugzilla ID: 981 > Fixes: e623e0c6d8a5 ("vhost: add reconnect ability") > Cc: stable@dpdk.org >=20 > Signed-off-by: David Marchand > --- > lib/vhost/socket.c | 17 ++++++++++++----- > 1 file changed, 12 insertions(+), 5 deletions(-) >=20 > diff --git a/lib/vhost/socket.c b/lib/vhost/socket.c > index 669c322e12..21002848e6 100644 > --- a/lib/vhost/socket.c > +++ b/lib/vhost/socket.c > @@ -498,8 +498,12 @@ vhost_user_client_reconnect(void *arg __rte_unused) > static int > vhost_user_reconnect_init(void) > { > + static bool reconn_init_done; > int ret; >=20 > + if (reconn_init_done) > + return 0; > + > ret =3D pthread_mutex_init(&reconn_list.mutex, NULL); > if (ret < 0) { > VHOST_LOG_CONFIG("thread", ERR, "%s: failed to initialize > mutex\n", __func__); > @@ -515,6 +519,8 @@ vhost_user_reconnect_init(void) > VHOST_LOG_CONFIG("thread", ERR, > "%s: failed to destroy reconnect mutex\n", > __func__); > + } else { > + reconn_init_done =3D true; > } >=20 > return ret; > @@ -866,6 +872,11 @@ rte_vhost_driver_register(const char *path, uint64_t > flags) > if (!path) > return -1; >=20 > + if ((flags & RTE_VHOST_USER_CLIENT) !=3D 0 && > + (flags & RTE_VHOST_USER_NO_RECONNECT) =3D=3D 0 && > + vhost_user_reconnect_init() !=3D 0) > + return -1; > + > pthread_mutex_lock(&vhost_user.mutex); >=20 > if (vhost_user.vsocket_cnt =3D=3D MAX_VHOST_SOCKET) { > @@ -961,11 +972,7 @@ rte_vhost_driver_register(const char *path, uint64_t > flags) > } >=20 > if ((flags & RTE_VHOST_USER_CLIENT) !=3D 0) { > - vsocket->reconnect =3D !(flags & RTE_VHOST_USER_NO_RECONNECT); > - if (vsocket->reconnect && reconn_tid =3D=3D 0) { > - if (vhost_user_reconnect_init() !=3D 0) > - goto out_mutex; > - } > + vsocket->reconnect =3D (flags & RTE_VHOST_USER_NO_RECONNECT) =3D=3D > 0; > } else { > vsocket->is_server =3D true; > } > -- > 2.39.2