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 AFB58A034F; Mon, 11 Oct 2021 08:35:18 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 709CD40E01; Mon, 11 Oct 2021 08:35:18 +0200 (CEST) Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by mails.dpdk.org (Postfix) with ESMTP id 7E5A940142 for ; Mon, 11 Oct 2021 08:35:16 +0200 (CEST) Received: from pps.filterd (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 19B5au7K010266; Mon, 11 Oct 2021 06:35:15 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : content-type : mime-version; s=corp-2021-07-09; bh=DbSmWvVjfRQxOp0CJrYzVXOaAVSzeFEEOkmLWpYaGFE=; b=QztnlzUisisp/UEcZe/boejweD3C52tLUx2uiyh/wK3kktlR3+0n1bvGIT+XERzyg5s5 dTE/zVH7EPndlNv4l7eCrEOj5Ochxp2M1Nbya5dug4fqs750GP2boY7f3TTMrVSkBQcO U7dpGZqWt7KOdL/T790urIRlvbjiBnAAt7GsPfVFJtZ6l939H9f9CYmgI63OAkYh4Aj0 UnHZHKBCzst/jeG3BCw/J56rQ8CmQ8SjWu7MlzGjIYKrKJNHvnSElEvLWz9fC6CtJcix 9wGsrngIz9RVzolrR30MpEPBM4lmPSbxH1wHhGG8C3VLLxPkzeiKDTzn42uZbklLVPKc 5Q== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by mx0b-00069f02.pphosted.com with ESMTP id 3bkw3j26v8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 11 Oct 2021 06:35:15 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.1.2/8.16.1.2) with SMTP id 19B6Z2Vt135643; Mon, 11 Oct 2021 06:35:14 GMT Received: from nam04-bn8-obe.outbound.protection.outlook.com (mail-bn8nam08lp2044.outbound.protection.outlook.com [104.47.74.44]) by userp3020.oracle.com with ESMTP id 3bkyv7qy5a-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 11 Oct 2021 06:35:14 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jsqi3j4UL3oKIFTpY42ju2VwJh7Em5PToz7WIEve7O4vobfzR97hhAlWehXPIFG+AQTzWjWkpo6KPujKLx7mei3RQTS21BdlqUZxNQaIS4eTspN5NX1o0b0PDeqoqvRw1+pokCMh9KqVPkGYAy2kMc0MEiHeJsgtxA+o4gR7nU/XOqAo0v3ipo1Ht5PrFjpdk3iY7nCx37vBt45qxCUyNp2XXUwj8tA02WML/Sm5YQVcqgeTWWIkaupHydoDZq7f08PXWSXEWujefAPPyKWqqvKmLJy//qW3eqsXUaHsXJbgJjdAuPVpY/CO/kBVQtnBzSAVqUYz+txK4mPOrtF+Pw== 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=DbSmWvVjfRQxOp0CJrYzVXOaAVSzeFEEOkmLWpYaGFE=; b=NIS26T+qbvmpBgUm+ByISjgIlVkeiToHQzRt4MEl1nrafInjdmZg+lKRP0kqqFPLbWaRUsyRfTRw/D/sS/i3ZmWEFMsToOOzzjTpYaXNYlTjgHdMJmmmiFR3z/MnFXXZlkK9royudQIku/Zb5rGu65cDABre3Cs1aAt5YD6apUSL6DzoLAhuNzaZmynxg0QPgkIJERA8gq+01IRAmu0rFc3jtJIPGvotGZiiYKhCJgj+7bSQrqtx/9D0iOzFGdu2UK24BwNcjKTH8z7hVhK9ZsgQUCONfAA/GNwBNeNXDAhCP3U36ASo+7cTIRIOmPgZKg/5EDS36appoQOhz5vTdw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=DbSmWvVjfRQxOp0CJrYzVXOaAVSzeFEEOkmLWpYaGFE=; b=x67kG7ZYgokTJVWo/QAanYCc8+fJxvz67XlmAiFnQfa1g/8v/ID0oTig8eTr+qPmryoXPxx48lioPWJokJ1C6+51YqmLr9G+ShEe2uy4Xh+Sm7LU0BUkZg/uQ9CHv5MNwSoC0pQO9ntAZhPxbr6XtUGQCZXorW78qu+daLGf6Ik= Received: from BYAPR10MB3541.namprd10.prod.outlook.com (2603:10b6:a03:11d::14) by SJ0PR10MB4702.namprd10.prod.outlook.com (2603:10b6:a03:2af::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.19; Mon, 11 Oct 2021 06:35:11 +0000 Received: from BYAPR10MB3541.namprd10.prod.outlook.com ([fe80::84a7:486a:ead6:ef9c]) by BYAPR10MB3541.namprd10.prod.outlook.com ([fe80::84a7:486a:ead6:ef9c%7]) with mapi id 15.20.4587.026; Mon, 11 Oct 2021 06:35:11 +0000 From: Sahithi Singam To: "ferruh.yigit@intel.com" CC: "dev@dpdk.org" , "eladv6@gmail.com" Thread-Topic: [PATCH] kni: fix kernel deadlock due to async changes Thread-Index: Ade+aezcC52TM4mvQV+DvaUdb5MkQg== Date: Mon, 11 Oct 2021 06:35:11 +0000 Message-ID: Accept-Language: en-GB, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: intel.com; dkim=none (message not signed) header.d=none;intel.com; dmarc=none action=none header.from=oracle.com; x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 40117384-d5aa-4a8c-e0d0-08d98c8146f9 x-ms-traffictypediagnostic: SJ0PR10MB4702: x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:10000; x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: Z23nTHMnwJTyXIYEi2ag+jk9EeOojdFVC1jJ6nFtxntSeOMcd0seKPzL2YpbQ4ztKZwUzwk3hbtmMtLRxgNlKjtkM9hQqwyIU51/8rqXfAHEWurz8g6viOO/SGuM8cEJf2t37r8Fe6lpq954jNaepWu2Gklsv1EOqXA2kaj9lxkNb/VH27Gk6vQlKnrcwYHpP6cQyjayqyFHjH++1mNtfz2joNdS7oto+O+2RqgzJVobYZTg4IPp14QZKJ338mw6QrRlA3L64xb6raJ4BwkJigD0gm5lDI/nev0iy6DA9MJ225eUlOOKJZNK5YCzLZIe5BgSboVrKlZirFz0gxGnwKWuvmWpOkHNC0c/Y/WxRV8mJTKEIPBX5GM5Fi5W/T+hyEugT7tvClUlvicifMYhYM6QUnF2ITWw9cKkJ1xijC3HNs9Rp7HOLCNP8UBJFkFGb4jtnXDbWoW8NBb+nFnt/UoCtf8VfnGA+/vYIWVXqPqAELsIAmaN5lIFsL5GQ/8Ey5ni5WoTOrFhbhgEETmIMn3/4B6OdbN+0Il0Q61USgjzWU8gUwPtCi4lxxLJ7OFBbIzReI5FG9L/Uue7Y8m/jMFC6SETYrOXei+f+kx6l6Fk10cv51kPK/WeDQLu5y8Tnm+DX+HJzhzMNYrD3YNJX3Ia+gr3AYXO9L+unFe3cVJlCr8NPd254GSe2BaqLYjzZJcIFlj0/ovDjbKN6To+vg== x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BYAPR10MB3541.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(366004)(316002)(4326008)(71200400001)(66556008)(66446008)(7696005)(54906003)(2906002)(186003)(44832011)(76116006)(6506007)(66946007)(9686003)(64756008)(66476007)(38070700005)(122000001)(8936002)(86362001)(5660300002)(8676002)(52536014)(55016002)(508600001)(83380400001)(33656002)(6916009)(38100700002); DIR:OUT; SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?ZXNT5kqquPcbhKQL0KaBXKc3cStbfBXJOd1juagem0yImhvIRV63dybXaj0f?= =?us-ascii?Q?Ci5t3KAxFNAPYZVFtXLSW/ub7BGQvtYNMmHjlmDST44l2Je0znEYgSzC/UzL?= =?us-ascii?Q?mxRyaCCX65aIKmiqxA92HcLluwq4coaXkwzplkCjCQypP5N/YwFmMgFqlKue?= =?us-ascii?Q?2wNFy4F4P0xc9O4eSOHSlBmYmNd+koYOixUN29EW6a+r/gK/OojaWqdBHbGw?= =?us-ascii?Q?rQBprB/39NuMxX0djw/NGfjbLaMYVaBQptpHzLYSnJ+UJZ+st39L+BHESqN2?= =?us-ascii?Q?uQutZ1xd06UpMbMwZaD5geRXQT7fxte06pb4KAX57g7cvaadk7RnjHB1EVjk?= =?us-ascii?Q?dsuEV89YyRKofVkURTMe3DR6oIYQC/DNaxdil47pWG2EekI2TGUbB55NvtoH?= =?us-ascii?Q?idIF/lZ4Oy3PbZkxeCiuaeSceWCVTYGCCrpwS8KYXXgEk6k71SewZg7IHGxz?= =?us-ascii?Q?G3QaRpCfE+4jy3KZxuHgPqQRVE6DKfg6CWeQZ2udY4fM3PpAU0ULRyiN8EFP?= =?us-ascii?Q?Vw4poHd1pfLgJUgcV5BGwc4JRYv8bmvT0P0CNOpoh2VCavcrZLzawzSHeQ/R?= =?us-ascii?Q?1IS+2pKI+mT090+eViXNGiJE8Ybd65UKhjhm0dS/GLQdtIE/Sp2mxoE06Trq?= =?us-ascii?Q?52OyOLN9bJ9Amr7UF8nyNK7IX5DvlK5osowcdyOuq/mWtkpRSYamIOnD/Fhl?= =?us-ascii?Q?oCgcunnTJJXJNcduO4joS85FQZ3HmXA/Gz88WFDKhmKRr7qcLA9iy2v6BIK+?= =?us-ascii?Q?5qIh7jmA/wZ962EMAt1CN6zk21CfBqafenuOULFYYx3L9cVdH8Z8uPSos3eF?= =?us-ascii?Q?bp+RX+EFaWEZjGdTzRoJcLJHN7NotIJgo2cOPk9xev8+ry/Vd9SW3tCLatuS?= =?us-ascii?Q?gCubTQBu/WjmrBWanL72Kt0lim1x4rw+aHHFY83EFcXpUio2IpPeOG/gB1gb?= =?us-ascii?Q?SmFR/SzYMf0V/j2GQugolTn5rXqbkUYPxesaJFvgeAvGpRWYAFqXxOrAYVdo?= =?us-ascii?Q?YKyhsgnF2rflWrV1cJa9HUVwYWSYzWMb0jKC/z4ph/Ci1Jjkqpn2ur3kk7HV?= =?us-ascii?Q?ZOyrw1A5TObvr3+Qjf29cDCT++mZYiXd5A+Rm2YDF2nNwFzdXsLm6Iml/Yw+?= =?us-ascii?Q?cpACSe/j4IXQqVEHOdvsDUDLjuW4x09SxP/aNGB4WmQnC2vXAZxzJDSIoiqK?= =?us-ascii?Q?j5TZoA5TUKNwobE4JGEaGsELF1tYwI3sZhurtZavmQvN1VKYsUFDebMpPm0B?= =?us-ascii?Q?dhHeVYtblOxW/7es2wTu15UJIxHG7/E7yuZy1y0EGgvD5FnrojUnVTK9H57T?= =?us-ascii?Q?xZPr11RVFhOefPUT4nnXYqPSpOr0QLtUO8Zr05jMMi7kl2I3ipFuq2q1TC1v?= =?us-ascii?Q?mxHarB6/Bd/8kMl3LFC6P3kkvNk5?= x-ms-exchange-transport-forked: True MIME-Version: 1.0 X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: BYAPR10MB3541.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 40117384-d5aa-4a8c-e0d0-08d98c8146f9 X-MS-Exchange-CrossTenant-originalarrivaltime: 11 Oct 2021 06:35:11.8277 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: uRBoTuVWVNwKDronu6UyDL93K2aOTVsh4t4q9M4aSev70fG/VSoD1XzKOEOsHtfvkNKcUTTdvlxo9790qA7M9t3hoGPHQyclKmnG4g0DrzU= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR10MB4702 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10133 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 adultscore=0 bulkscore=0 mlxscore=0 spamscore=0 mlxlogscore=999 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2109230001 definitions=main-2110110038 X-Proofpoint-GUID: M0rUULXuYq3Gy4S4roI0v8ufcgm-vY4_ X-Proofpoint-ORIG-GUID: M0rUULXuYq3Gy4S4roI0v8ufcgm-vY4_ Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable X-Content-Filtered-By: Mailman/MimeDel 2.1.29 Subject: [dpdk-dev] [PATCH] kni: fix kernel deadlock due to async changes 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 Sender: "dev" From: Sahithi Singam > Async user request changes resulted in a kernel deadlock when used with lin= ux kernel version>=3D 5.12. Starting from linux kernel version 5.12, a new global semaphore dev_addr_se= m was introduced in dev_set_mac_address_user() function that should be acqu= ired and released along with rtnl_lock when a mac address set request was r= eceived from userspace. When a mac address set request is received on KNI interface, before sending= request to userspace, kni code is releasing rtnl_lock without releasing de= v_addr_sem semaphore. After receiving a response it is again trying to hold= rtnl_lock. These changes were added as part of async user request changes = to fix a kernel deadlock with bifurcated devices. This code is resulting in deadlock as kni is just releasing rtnl_lock witho= ut releasing semaphore while mac address set request on some other device = could have acquired rtnl_lock and could be waiting for dev_addr_sem held by= the current device. As a solution, support async user request changes based on a module paramet= er. This will limit kernel deadlock issue to users using KNI over bifurcate= d devices with kernel versions >=3D 5.12. Bugzilla ID: 816 Fixes: 631217c76135 ("kni: fix kernel deadlock with bifurcated device") Cc: eladv6@gmail.com Signed-off-by: Sahithi Singam > --- kernel/linux/kni/kni_dev.h | 3 +++ kernel/linux/kni/kni_misc.c | 11 +++++++++++ kernel/linux/kni/kni_net.c |= 46 ++++++++++++++++++++++++++------------------- 3 files changed, 41 insertions(+), 19 deletions(-) diff --git a/kernel/linux/kni/kni_dev.h b/kernel/linux/kni/kni_dev.h index = c15da311..ea9d23a 100644 --- a/kernel/linux/kni/kni_dev.h +++ b/kernel/linux/kni/kni_dev.h @@ -34,6 +34,9 @@ /* Default carrier state for created KNI network interfaces */ extern uint= 32_t kni_dflt_carrier; +/* Asynchronous userspace request support */ extern int async_support; + /** * A structure describing the private information for a kni device. */ diff --git a/kernel/linux/kni/kni_misc.c b/kernel/linux/kni/kni_misc.c inde= x 2b464c4..685067d 100644 --- a/kernel/linux/kni/kni_misc.c +++ b/kernel/linux/kni/kni_misc.c @@ -41,6 +41,9 @@ static char *carrier; uint32_t kni_dflt_carrier; +/* Asynchronous userspace request support */ int async_support; + #define KNI_DEV_IN_USE_BIT_NUM 0 /* Bit number for device in use */ static int kni_net_id; @@ -659,3 +662,11 @@ struct kni_net { "\t\ton Interfaces will be created with carrier state set to on.\n" "\t\t" ); + +module_param(async_support, int, 0); +MODULE_PARM_DESC(async_support, +"Support KNI async user request (default=3D0):\n" +"\t\t0 Async user request not supported.\n" +"\t\tother Async user request supported.\n" +"\t\t" +); diff --git a/kernel/linux/kni/kni_net.c b/kernel/linux/kni/kni_net.c index = 611719b..664f4b7 100644 --- a/kernel/linux/kni/kni_net.c +++ b/kernel/linux/kni/kni_net.c @@ -111,14 +111,16 @@ uint32_t num; int ret_val; - ASSERT_RTNL(); + if (async_support !=3D 0) { + ASSERT_RTNL(); - /* If we need to wait and RTNL mutex is held - * drop the mutex and hold reference to keep device - */ - if (req->async =3D=3D 0) { - dev_hold(dev); - rtnl_unlock(); + /* If we need to wait and RTNL mutex is held + * drop the mutex and hold reference to keep dev= ice + */ + if (req->async =3D=3D 0) { + dev_hold(dev); + rtnl_unlock(); + } } mutex_lock(&kni->sync_lock); @@ -132,12 +134,15 @@ goto fail; } - /* No result available since request is handled - * asynchronously. set response to success. - */ - if (req->async !=3D 0) { - req->result =3D 0; - goto async; + if (async_support !=3D 0) { + /* No result available since request is handled + * asynchronously. set response to success. + */ + if (req->async !=3D 0) { + req->result =3D 0; + ret =3D 0; + goto fail; + } } ret_val =3D wait_event_interruptible_timeout(kni->wq, @@ -155,14 +160,15 @@ } memcpy(req, kni->sync_kva, sizeof(struct rte_kni_request)); -async: ret =3D 0; fail: mutex_unlock(&kni->sync_lock); - if (req->async =3D=3D 0) { - rtnl_lock(); - dev_put(dev); + if (async_support !=3D 0) { + if (req->async =3D=3D 0) { + rtnl_lock(); + dev_put(dev); + } } return ret; } @@ -207,8 +213,10 @@ /* Setting if_up to 0 means down */ req.if_up =3D 0; - /* request async because of the deadlock problem */ - req.async =3D 1; + if (async_support !=3D 0) { + /* request async because of the deadlock proble= m */ + req.async =3D 1; + } ret =3D kni_net_process_request(dev, &req); -- 1.8.3.1