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 D3AECA00BE; Tue, 10 May 2022 11:00:38 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id BA441406B4; Tue, 10 May 2022 11:00:38 +0200 (CEST) Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by mails.dpdk.org (Postfix) with ESMTP id E026C4069D for ; Tue, 10 May 2022 11:00:36 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1652173237; x=1683709237; h=from:to:subject:date:message-id:references:in-reply-to: content-transfer-encoding:mime-version; bh=ZwA5yp0C5+m5dsMR5ZHV3ZdIzUU7ruurEg+3a1ATlo4=; b=AX/1O768cVuhWDxhxXU4L5U1Zmlj4DPEf9E0Pu8qVMwUaCgk9d72DMv0 n2HrF4HVnbz5fc79GIznVGfbGhMuNRHTFnNb5gn6CJhAnHCZw75/pEePI YvQhqa1i8GHujZZ0jF3c6F6UjnB8TUO8AjkHZnZetfBKIDSV7V+e4YeKq d/+Cbo3JocWM01hIAThRfA/7pkPOW6/xTRObVljPJrhA106X2BLzJdU7B 0+Xr+e7e7N8vt5A11kEbOsXfeN/ICQWR8ltObtNh3C3lCD9glQwBks2SD dK4z2E2FiNfKHkHl6sK64jNBaw4ye4+1vVbaM4U1S/VjQs82ZeYnxAsDq w==; X-IronPort-AV: E=McAfee;i="6400,9594,10342"; a="329907186" X-IronPort-AV: E=Sophos;i="5.91,214,1647327600"; d="scan'208";a="329907186" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 May 2022 02:00:35 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.91,214,1647327600"; d="scan'208";a="696987967" Received: from orsmsx602.amr.corp.intel.com ([10.22.229.15]) by orsmga004.jf.intel.com with ESMTP; 10 May 2022 02:00:35 -0700 Received: from orsmsx608.amr.corp.intel.com (10.22.229.21) by ORSMSX602.amr.corp.intel.com (10.22.229.15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.27; Tue, 10 May 2022 02:00:35 -0700 Received: from orsmsx606.amr.corp.intel.com (10.22.229.19) by ORSMSX608.amr.corp.intel.com (10.22.229.21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.27; Tue, 10 May 2022 02:00:35 -0700 Received: from ORSEDG602.ED.cps.intel.com (10.7.248.7) by orsmsx606.amr.corp.intel.com (10.22.229.19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.27 via Frontend Transport; Tue, 10 May 2022 02:00:35 -0700 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (104.47.55.174) by edgegateway.intel.com (134.134.137.103) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2308.27; Tue, 10 May 2022 02:00:34 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mgbHK4My9e+DdXM3Rgzo+1ZiEELZ26H1tIF8CyLfXaddC+4TyfRQoh8zjc8+pE1+CbTbNb5IrPc792v6mG8orTU5al4x0+UuVYqTQE+yxS9tuDlVCBD944r0+etoYO2joPm6IU2b+mqbRhaLvAO76fyZVK/eotSZVxtk8GDbcYLfyELfMlv2etPtGgClfv7R8YMabRECR5jNZSpUiZo3RjMjq2MYKApm50fTeaevFTFqnnd7UDHM77yGwmkxzFwqKS/i4fOKF/yPLx2b47LHxhmAB44mHc9It6jOBeAG1ItczOobDmZ8mr+HiKL6csXura9XxbP3hsTb2NiEmck+ww== 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=j0a5sQw50NJ4Lq5/4BxwuOMZMTlYk5N1gq/m6meMWj0=; b=exjWOqWGAOpE9QShPhl8C+NNitG12NhUwq8SGtEx/neWhmIdOhs62L3e3F22UQNDdwKfh5V7cotLQmgh2z3K5xbe/l42Gbls5HkRCGebUw3rTplA6ycvXA1WdiTMGp3YVUpG1dK5miIygyXW8kfS9aOA9DxtZ3fMAMJA4tCGEBj7YxwHNPVDDCCdjAyJHeJVncl8ps4BortZMTKJRI1mMST9WeKZpz3nuPtTWIpd1NcmpzQI3+zr07WGmiwLLtBpNfZ8feWh/D3uJMD0SQtej5CotHOinuImdlH7qnUbg399TR6alCRZPqVyiGXQdZ/2hNk7Dsci4oYJgbbQ8K6Yfg== 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 BN9PR11MB5513.namprd11.prod.outlook.com (2603:10b6:408:102::11) by DM5PR11MB1609.namprd11.prod.outlook.com (2603:10b6:4:8::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5227.23; Tue, 10 May 2022 09:00:33 +0000 Received: from BN9PR11MB5513.namprd11.prod.outlook.com ([fe80::31c6:2ec8:2f71:42da]) by BN9PR11MB5513.namprd11.prod.outlook.com ([fe80::31c6:2ec8:2f71:42da%2]) with mapi id 15.20.5227.023; Tue, 10 May 2022 09:00:32 +0000 From: "Ding, Xuan" To: Maxime Coquelin , "dev@dpdk.org" , "Xia, Chenbo" , "Hu, Jiayu" , "Jiang, Cheng1" , "Pai G, Sunil" , "david.marchand@redhat.com" Subject: RE: [PATCH] vhost: add runtime locking check in unsafe APIs Thread-Topic: [PATCH] vhost: add runtime locking check in unsafe APIs Thread-Index: AQHYZEeLy3PDTn3EcEGLiK0Hn4JNL60Xz4mg Date: Tue, 10 May 2022 09:00:32 +0000 Message-ID: References: <20220510082528.1229104-1-maxime.coquelin@redhat.com> In-Reply-To: <20220510082528.1229104-1-maxime.coquelin@redhat.com> Accept-Language: zh-CN, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-product: dlpe-windows dlp-reaction: no-action dlp-version: 11.6.401.20 authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 9d047ca5-acbf-4378-75b5-08da32638a3b x-ms-traffictypediagnostic: DM5PR11MB1609:EE_ x-ld-processed: 46c98d88-e344-4ed4-8496-4ed7712e255d,ExtAddr x-microsoft-antispam-prvs: x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: nwVs7MaPygS79cgpLH5/MBZ/zy+XJn3aNPNeqR1F1jWtuZXfkuUJBlUlT4EO0J0ZVNIByoHkG15n4w7Mbl6J2B+SZIL4BPzwgt1MThFD24kwzedR9SYzvZZG/2MzLQSwDQrdwdzSs9rsivJzAFExrR4iXo+Soii1wbZfhMYLKA/LZIf+S3169rqp/YJoMs+oKbsirN7ncCJTPHhxzgnhHUdNlERfOBogsb8Kbiw9K3X10Fd7KUXGsC3P7J82xzmeGjU6Kvisr7RGrfcZmH4zhD0KmNKQhTLRW7HgHNpr6SHx1kKVrt0o/oC7EfB3minPGlrwD/IpBYRIFTYQ4X8nl2UwclJalDFOzb0ksvFNN0FbcFIRPVK6JYDq8ljmahCpcTNErJePfBJZOcjYdprhE5iW17HgLNXmZCpWht/PvRsjF8WlnscFDleuHSsbyux4rL9ZizKVY2R3dYLiXC7Rrv3ae6CxBW5YIWG/GkA9IvQSP0fYehFr7xXAPaq3kxcJ1mnm6fZpY64htKzbIoPb1bvkEpFeyueeYqZo1jz0fNkpByzgZrsnMDEzkt5LCP9ZD4cohJXD5e8nEEXZ0jcpiakCP+iKZb7L40pxpsazl40OE5s4LUWVHP7XER6dt3ZXplGct1uo2OopksQcl/0tHQGeRO5fg/lkeSG5UgCbYv2biWljVSnEbxQI4RA4Mmc1ZmQT5Jd05JSqo0o9dSR5FkEFLbGARbDEaYaMiVJfUms= x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BN9PR11MB5513.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(366004)(7696005)(38070700005)(38100700002)(86362001)(53546011)(71200400001)(508600001)(82960400001)(8936002)(6506007)(83380400001)(186003)(26005)(9686003)(921005)(122000001)(55016003)(33656002)(5660300002)(52536014)(110136005)(316002)(2906002)(64756008)(66446008)(66476007)(66556008)(66946007)(76116006)(8676002); DIR:OUT; SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?YNR850Hp7Aa0pcqfzCwgiEYfPY0WZJJRmWuqMpggdsl0GFNOe7AOyZasMfUb?= =?us-ascii?Q?Hhrek6QagMSwtaPy/o3IDWXuH6FjD5+rtmni51YAjG4cCSGUYsUUdZWPyC1I?= =?us-ascii?Q?UjAK2NkFjxg5u3xTaD88qKQxPdlxH6SuEAkFS+DwifmrNGApaBAVhu/o4opS?= =?us-ascii?Q?OOfhgUgiEJA8bh2OxBhtez0zL8PHnovkfey0MZ54HK6tJMKI6QEn8+dMh5o2?= =?us-ascii?Q?NAJ6W7qnv/eW7BMZHkxGIbBFXVgY6Fe1drwlDFHovdinG2vYfxbEQvmH9O3g?= =?us-ascii?Q?uTELZ8C059gnIUYxBck8V0YRwi9/DO36w4ng+nIQAed1W/Nq8azve8BEKaym?= =?us-ascii?Q?797+4s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K1H0dU6eX?= =?us-ascii?Q?9Ow+r187su2rBrVpY7FJ+n1RmlF4QQyk3HaWaM2rz5+YTpqjZVLUjlBghp9s?= =?us-ascii?Q?LRG3NISaQFBdJFw2b92i9JbgSkpcMCgJf7nhLNGfjNrXjF+Z9pbI8DTY3vrj?= =?us-ascii?Q?RNTPEngvs6PKZQYGdO71LEulMTxTPBU/lDnzDtWiOrtg3G77GMEakG+L7dIh?= =?us-ascii?Q?YcBS9vyiS+2YKBpikrdSyxJJ24B5T7jbob4qzYhVPKBvYGDvfd1lvo8uauUH?= =?us-ascii?Q?ZluJNw/hN0Mq4zercN8W+w6taFU8x6YAtWAdyDJUwoHYY3H9eXMFNIgiAnEU?= =?us-ascii?Q?AILUYDduFanDjV1YB3tbpN2rqcSdMqPnclIgs6CcxRa+bKQYZjqCSUQa9t7X?= =?us-ascii?Q?wOtx1jedBE4SUDFGcFe/6GltpEvryXTb6FRXFzpryV/+Nj5zbP/ybmfsXw0Q?= =?us-ascii?Q?QSnCHK3vvWWEROXY4a7nEdX96PnIDg0pCFHhDqeWDsHBAtwS0jXqSluXqN1U?= =?us-ascii?Q?l7vea5YxfQ=3D=3D?= 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: BN9PR11MB5513.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9d047ca5-acbf-4378-75b5-08da32638a3b X-MS-Exchange-CrossTenant-originalarrivaltime: 10 May 2022 09:00:32.8650 (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: +sNm1AdUAeD3ZTFzHFmIoFdHWbXD36ZEAx9FLtfA5GIXr0C70woFGGu/dYD4nm9wcofjJEi/tqJgS6HZYoHYPA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR11MB1609 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 Maxime, > -----Original Message----- > From: Maxime Coquelin > Sent: Tuesday, May 10, 2022 4:25 PM > To: dev@dpdk.org; Xia, Chenbo ; Ding, Xuan > ; Hu, Jiayu ; Jiang, Cheng1 > ; Pai G, Sunil ; > david.marchand@redhat.com > Cc: Maxime Coquelin > Subject: [PATCH] vhost: add runtime locking check in unsafe APIs >=20 > This patch adds runtime checks in unsafe Vhost async APIs, to ensure the > access lock is taken. >=20 > The detection won't work every time, as another thread could take the loc= k, > but it would help to detect misuse of these unsafe API. >=20 > Signed-off-by: Maxime Coquelin > --- > lib/vhost/vhost.c | 18 ++++++++++++++++++ > 1 file changed, 18 insertions(+) >=20 > diff --git a/lib/vhost/vhost.c b/lib/vhost/vhost.c index > df0bb9d043..39cbeb415c 100644 > --- a/lib/vhost/vhost.c > +++ b/lib/vhost/vhost.c > @@ -1732,6 +1732,12 @@ > rte_vhost_async_channel_register_thread_unsafe(int vid, uint16_t queue_id= ) > if (unlikely(vq =3D=3D NULL || !dev->async_copy)) > return -1; >=20 > + if (unlikely(!rte_spinlock_is_locked(&vq->access_lock))) { > + VHOST_LOG_CONFIG(ERR, "(%s) %s() called without access > lock taken.\n", > + dev->ifname, __func__); > + return -1; > + } > + > return async_channel_register(vid, queue_id); } >=20 > @@ -1796,6 +1802,12 @@ > rte_vhost_async_channel_unregister_thread_unsafe(int vid, uint16_t > queue_id) > if (vq =3D=3D NULL) > return -1; >=20 > + if (unlikely(!rte_spinlock_is_locked(&vq->access_lock))) { > + VHOST_LOG_CONFIG(ERR, "(%s) %s() called without access > lock taken.\n", > + dev->ifname, __func__); > + return -1; > + } > + > if (!vq->async) > return 0; >=20 > @@ -1925,6 +1937,12 @@ rte_vhost_async_get_inflight_thread_unsafe(int > vid, uint16_t queue_id) > if (vq =3D=3D NULL) > return ret; >=20 > + if (unlikely(!rte_spinlock_is_locked(&vq->access_lock))) { > + VHOST_LOG_CONFIG(ERR, "(%s) %s() called without access > lock taken.\n", > + dev->ifname, __func__); > + return -1; > + } > + > if (!vq->async) > return ret; Just to confirm, is the rte_vhost_clear_queue_thread_unsafe() API missed th= e check? Thanks, Xuan >=20 > -- > 2.35.1