From patchwork Wed Jun 5 14:50:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 13687024 Received: from 009.lax.mailroute.net (009.lax.mailroute.net [199.89.1.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3B44819D8A3 for ; Wed, 5 Jun 2024 14:51:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=199.89.1.12 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717599110; cv=none; b=J49hCVmUVJqGuc3/IIQg/0xIpzX4NGfccH1IImvtklBWCQXAGBUGgf66ntaYyE2P6qgLwVOY4FSStPRrjGcuC9f7heseW5P4wfyftsI5wComwCDiYqkIDJIxWJJkNunAZWsEiIjnkmWzmGCUnkwVpxPgMBxdCK4QDVoVv0LvZn0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717599110; c=relaxed/simple; bh=k6TBkKogCGBOGdS/ehVn0sIqejOoljb+798ywySdX9Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qbNqNSlrjnDg/ALwrRnTF22k0vCpNmgT8UNCwnp84Y903yGGZm+H1Lobe0SkdVAggLQIstcvUVhymt5FnsCP9Gb7uG0DfN2HaVzqbTfve6KSq0ZInLZW2PYyKht0hh9lHeU6TgGyVFlmcpnv63h5JdVcpgxDQBnFvdyKbJW/Lb4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=acm.org; spf=pass smtp.mailfrom=acm.org; dkim=pass (2048-bit key) header.d=acm.org header.i=@acm.org header.b=S9V5GNeT; arc=none smtp.client-ip=199.89.1.12 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=acm.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=acm.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=acm.org header.i=@acm.org header.b="S9V5GNeT" Received: from localhost (localhost [127.0.0.1]) by 009.lax.mailroute.net (Postfix) with ESMTP id 4VvVm45QgszlgMVV; Wed, 5 Jun 2024 14:51:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=acm.org; h= content-transfer-encoding:mime-version:references:in-reply-to :x-mailer:message-id:date:date:subject:subject:from:from :received:received; s=mr01; t=1717599105; x=1720191106; bh=LKWcZ Kgr9WtBiRSIv/1iiA76vNy5YvxFIbtqTDcNces=; b=S9V5GNeTF3An1i8KeFEeO T4l5Qq69vatU6kNBgFMVd8K2h5whrJhzMYgsvFuTiQ8I5sCaPMyHZLDmvBjDGoiE /e++ZNtcWCYEmbRAxIZrMcwuCVDhoiyZHXucBCi3eT/afekbcKJGLRUN/j/uV0p+ dsxYQxDI6Iwa0cIlP35qk8VJ0pnc49rhTSgfI3AjtbYO8c5drSep3EYqT//+cD+K Oa7gCsHSOWVN9bdF1fdy3OkaQy/m6FAWKjGtq7E8qyCNnYSaK17vBd5pKfkBI85t 7nGr0kUTLf5gOditGejFtBFkebXbTwRmj2D8vK4xCI/Jo4vOThZgnswIAPTx11S3 A== X-Virus-Scanned: by MailRoute Received: from 009.lax.mailroute.net ([127.0.0.1]) by localhost (009.lax [127.0.0.1]) (mroute_mailscanner, port 10029) with LMTP id fAz4kRzV33Wz; Wed, 5 Jun 2024 14:51:45 +0000 (UTC) Received: from bvanassche-glaptop2.roam.corp.google.com (unknown [65.117.37.195]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: bvanassche@acm.org) by 009.lax.mailroute.net (Postfix) with ESMTPSA id 4VvVlz2rp1zlgMVS; Wed, 5 Jun 2024 14:51:43 +0000 (UTC) From: Bart Van Assche To: Jason Gunthorpe Cc: Shinichiro Kawasaki , Zhu Yanjun , linux-rdma@vger.kernel.org, Bart Van Assche , Jason Gunthorpe , Leon Romanovsky , Joel Granados , Luis Chamberlain , Zhu Yanjun Subject: [PATCH 1/5] RDMA/iwcm: Use list_first_entry() where appropriate Date: Wed, 5 Jun 2024 08:50:57 -0600 Message-ID: <20240605145117.397751-2-bvanassche@acm.org> X-Mailer: git-send-email 2.45.1.288.g0e0cd299f1-goog In-Reply-To: <20240605145117.397751-1-bvanassche@acm.org> References: <20240605145117.397751-1-bvanassche@acm.org> Precedence: bulk X-Mailing-List: linux-rdma@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Improve source code readability by using list_first_entry() where appropriate. Signed-off-by: Bart Van Assche Reviewed-by: Zhu Yanjun --- drivers/infiniband/core/iwcm.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/infiniband/core/iwcm.c b/drivers/infiniband/core/iwcm.c index 0301fcad4b48..90d8f3d66990 100644 --- a/drivers/infiniband/core/iwcm.c +++ b/drivers/infiniband/core/iwcm.c @@ -143,8 +143,8 @@ static struct iwcm_work *get_work(struct iwcm_id_private *cm_id_priv) if (list_empty(&cm_id_priv->work_free_list)) return NULL; - work = list_entry(cm_id_priv->work_free_list.next, struct iwcm_work, - free_list); + work = list_first_entry(&cm_id_priv->work_free_list, struct iwcm_work, + free_list); list_del_init(&work->free_list); return work; } @@ -1023,8 +1023,8 @@ static void cm_work_handler(struct work_struct *_work) spin_lock_irqsave(&cm_id_priv->lock, flags); empty = list_empty(&cm_id_priv->work_list); while (!empty) { - work = list_entry(cm_id_priv->work_list.next, - struct iwcm_work, list); + work = list_first_entry(&cm_id_priv->work_list, + struct iwcm_work, list); list_del_init(&work->list); empty = list_empty(&cm_id_priv->work_list); levent = work->event; From patchwork Wed Jun 5 14:50:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 13687025 Received: from 009.lax.mailroute.net (009.lax.mailroute.net [199.89.1.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1124A19D8A3 for ; Wed, 5 Jun 2024 14:51:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=199.89.1.12 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717599116; cv=none; b=YKaTDhThKGGvpuZq83m+TFRjIj8ejDzTeU9IboEWiOt8pPY2Ee634kfKejip8sJfIO6axxpQ0diRzUc9q+lrltq008ik4MSgKKSPiVkqqm0Q4v9HFy+jhqp0d91VLXfDo+ZTXPyZePFbEyZoo+lS2Jf08xcw0IVG/dCyZ4nPQH8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717599116; c=relaxed/simple; bh=r/IFBp+yYlo9FQTgwQy2+xbNt3lwzK5MtMfJ+1R3RMI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CsOCzbJwLO1XP8o9nv0nTX3KOMvTyNnFMAXxwJxbYTQc+6KYyZ5PytUzPe+4E6CM4cOSKq9aHEBaHrn6VjwN4Ikj7kagpisBV2JTqn8QwX7Z8bcBdkaUjzwGIJ6Pqg17WWob2Uy/wSLyO2OaLU+7P/bL5c4gmUe7HS5QOsuqW20= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=acm.org; spf=pass smtp.mailfrom=acm.org; dkim=pass (2048-bit key) header.d=acm.org header.i=@acm.org header.b=m9Y+6pqb; arc=none smtp.client-ip=199.89.1.12 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=acm.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=acm.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=acm.org header.i=@acm.org header.b="m9Y+6pqb" Received: from localhost (localhost [127.0.0.1]) by 009.lax.mailroute.net (Postfix) with ESMTP id 4VvVmB3VgrzlgMVW; Wed, 5 Jun 2024 14:51:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=acm.org; h= content-transfer-encoding:mime-version:references:in-reply-to :x-mailer:message-id:date:date:subject:subject:from:from :received:received; s=mr01; t=1717599111; x=1720191112; bh=pRFWw nxDpbaPZ3mobvlFH89gOCKjm18/Izua5RjI8bw=; b=m9Y+6pqbn7giIVrCe4637 Oos8Ld45OZ3pNg99Qvl7GKbE5/MKbyIm5yM0A6PH/Vz65ef4l1XmceoLGmApsPj8 0TOrQo7Z8q5wKdFhfmA4uXwbPafSzQFBFU+fZQMR9BqXQnaDsnkTcab6Hd0GHAJ9 OVL9nR0Gvn3aQuvG23IqlARbGagaIphUEteeNIw4eWqeUCLSqq/pE/NPVgHazxq0 OHXohV7RdcvIbv7tQ2+GYAIkmvmhBQwViUEjYUu5YQIjWE3NqSYYrkTpsvkANvgO BnX/IaogpBAkXxlbzxVRyk+U1tDBVkoCjePl8TSTsVePX+mZtwcZcKx7ClNGDh3Q A== X-Virus-Scanned: by MailRoute Received: from 009.lax.mailroute.net ([127.0.0.1]) by localhost (009.lax [127.0.0.1]) (mroute_mailscanner, port 10029) with LMTP id 0ABlTBwXomLb; Wed, 5 Jun 2024 14:51:51 +0000 (UTC) Received: from bvanassche-glaptop2.roam.corp.google.com (unknown [65.117.37.195]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: bvanassche@acm.org) by 009.lax.mailroute.net (Postfix) with ESMTPSA id 4VvVm52Q67zlgMVS; Wed, 5 Jun 2024 14:51:49 +0000 (UTC) From: Bart Van Assche To: Jason Gunthorpe Cc: Shinichiro Kawasaki , Zhu Yanjun , linux-rdma@vger.kernel.org, Bart Van Assche , Jason Gunthorpe , Leon Romanovsky , Joel Granados , Luis Chamberlain , Zhu Yanjun Subject: [PATCH 2/5] RDMA/iwcm: Change the return type of iwcm_deref_id() Date: Wed, 5 Jun 2024 08:50:58 -0600 Message-ID: <20240605145117.397751-3-bvanassche@acm.org> X-Mailer: git-send-email 2.45.1.288.g0e0cd299f1-goog In-Reply-To: <20240605145117.397751-1-bvanassche@acm.org> References: <20240605145117.397751-1-bvanassche@acm.org> Precedence: bulk X-Mailing-List: linux-rdma@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Since iwcm_deref_id() returns either 0 or 1, change its return type from 'int' into 'bool'. Signed-off-by: Bart Van Assche Reviewed-by: Zhu Yanjun --- drivers/infiniband/core/iwcm.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/infiniband/core/iwcm.c b/drivers/infiniband/core/iwcm.c index 90d8f3d66990..ae9c12409f8a 100644 --- a/drivers/infiniband/core/iwcm.c +++ b/drivers/infiniband/core/iwcm.c @@ -206,17 +206,17 @@ static void free_cm_id(struct iwcm_id_private *cm_id_priv) /* * Release a reference on cm_id. If the last reference is being - * released, free the cm_id and return 1. + * released, free the cm_id and return 'true'. */ -static int iwcm_deref_id(struct iwcm_id_private *cm_id_priv) +static bool iwcm_deref_id(struct iwcm_id_private *cm_id_priv) { if (refcount_dec_and_test(&cm_id_priv->refcount)) { BUG_ON(!list_empty(&cm_id_priv->work_list)); free_cm_id(cm_id_priv); - return 1; + return true; } - return 0; + return false; } static void add_ref(struct iw_cm_id *cm_id) From patchwork Wed Jun 5 14:50:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 13687026 Received: from 009.lax.mailroute.net (009.lax.mailroute.net [199.89.1.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 22A4919D8A3 for ; Wed, 5 Jun 2024 14:52:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=199.89.1.12 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717599122; cv=none; b=Gm5P6399DKguySotMt7a8h/jF/OSFIV6zFFvU6gerauXdM8KGFa5ATe/DK52M1YMXf/bY/aVzs6qMeHlXMhfqXmw5KwR8yz8IUog21IfhGLgVKV5J/lfvSR9wzeubbtYLtwnQJK3XKgaT+etItvp2U3E8DviC6fcwBWYbD+OZEw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717599122; c=relaxed/simple; bh=wDm8oxVJqZI40k1iiq1qOwG8H4gAoNqGOvCJ49ZSntY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GYXu/MXi/aKvFgZf3pdvKm7lvWrLe9Q5tpgiPhjfOpb77sgwJvZS+BAIlQMg0B64eoSJ2+FYNdt8bWyV+kyGkLjtKnRfVjDxnKSiGfeRgmZEuQDKskMc6V/mJE/vPTJyIeVYN4j7IsJRqQsRYVfs/pXxacKVHOCkGfV4+TpvlAE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=acm.org; spf=pass smtp.mailfrom=acm.org; dkim=pass (2048-bit key) header.d=acm.org header.i=@acm.org header.b=mwVPKJ6e; arc=none smtp.client-ip=199.89.1.12 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=acm.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=acm.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=acm.org header.i=@acm.org header.b="mwVPKJ6e" Received: from localhost (localhost [127.0.0.1]) by 009.lax.mailroute.net (Postfix) with ESMTP id 4VvVmJ4kSHzlgMVV; Wed, 5 Jun 2024 14:52:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=acm.org; h= content-transfer-encoding:mime-version:references:in-reply-to :x-mailer:message-id:date:date:subject:subject:from:from :received:received; s=mr01; t=1717599117; x=1720191118; bh=dxKjZ lWEpeeiDoQUnXbj70tGUpxYAtXGTzInP6i7SJI=; b=mwVPKJ6eu6VLUsmDRTKIv tTBs5OPtr8i0+ri5eFhxJTKeXtuMEtfk5S0HzQ/qZwHcUpwcEPz7wDlt0lsSAinr DwbArqsUk1VqQSts4X3SllfWUuGGx0OYaywvJrzehjUX3XVlm1UFcZS52IcwVZ0G /pfR3waXeHC8VOBKL+33beTjc49MbRra0HPgJmy4imAfuz0NixQN3yrB0tDxSe1c 8RpQSNAiQczrjhjJsInLN/SNgyMm0KXwY1WxDWTT8WpF7uNOTZpm3yxcgGBJp2+x N5hiVTrLQl6Bybq+PurehC2WDkAxxVG+wAN9XNc64diuZdACinpJJiRaxqC2HEWU w== X-Virus-Scanned: by MailRoute Received: from 009.lax.mailroute.net ([127.0.0.1]) by localhost (009.lax [127.0.0.1]) (mroute_mailscanner, port 10029) with LMTP id n8AfIv_I3b5c; Wed, 5 Jun 2024 14:51:57 +0000 (UTC) Received: from bvanassche-glaptop2.roam.corp.google.com (unknown [65.117.37.195]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: bvanassche@acm.org) by 009.lax.mailroute.net (Postfix) with ESMTPSA id 4VvVmC36SWzlgMVS; Wed, 5 Jun 2024 14:51:55 +0000 (UTC) From: Bart Van Assche To: Jason Gunthorpe Cc: Shinichiro Kawasaki , Zhu Yanjun , linux-rdma@vger.kernel.org, Bart Van Assche , Jason Gunthorpe , Leon Romanovsky , Luis Chamberlain , Joel Granados , Zhu Yanjun Subject: [PATCH 3/5] RDMA/iwcm: Simplify cm_event_handler() Date: Wed, 5 Jun 2024 08:50:59 -0600 Message-ID: <20240605145117.397751-4-bvanassche@acm.org> X-Mailer: git-send-email 2.45.1.288.g0e0cd299f1-goog In-Reply-To: <20240605145117.397751-1-bvanassche@acm.org> References: <20240605145117.397751-1-bvanassche@acm.org> Precedence: bulk X-Mailing-List: linux-rdma@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 queue_work() can test efficiently whether or not work is pending. Hence, simplify cm_event_handler() by always calling queue_work() instead of only if the list with pending work is empty. Signed-off-by: Bart Van Assche --- drivers/infiniband/core/iwcm.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/drivers/infiniband/core/iwcm.c b/drivers/infiniband/core/iwcm.c index ae9c12409f8a..3d66aec36899 100644 --- a/drivers/infiniband/core/iwcm.c +++ b/drivers/infiniband/core/iwcm.c @@ -1093,11 +1093,8 @@ static int cm_event_handler(struct iw_cm_id *cm_id, } refcount_inc(&cm_id_priv->refcount); - if (list_empty(&cm_id_priv->work_list)) { - list_add_tail(&work->list, &cm_id_priv->work_list); - queue_work(iwcm_wq, &work->work); - } else - list_add_tail(&work->list, &cm_id_priv->work_list); + list_add_tail(&work->list, &cm_id_priv->work_list); + queue_work(iwcm_wq, &work->work); out: spin_unlock_irqrestore(&cm_id_priv->lock, flags); return ret; From patchwork Wed Jun 5 14:51:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 13687027 Received: from 009.lax.mailroute.net (009.lax.mailroute.net [199.89.1.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C1CB225774 for ; Wed, 5 Jun 2024 14:52:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=199.89.1.12 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717599133; cv=none; b=mHrnVFQrDcbWAwBBFJGBSDxZVed/63OT1lg+lFmZORoH8wlL6YcCBbYdAqBMVzh6p7v+AXCw54LD2K5+t/aUnmwBNpiGiHnhyo/xjGTs45kQLz4tImwjlX5fLq/BS8/c5oIv5fq/+aG2RoqjzdMx6gKf692Ctu3CqCrjqGOffxg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717599133; c=relaxed/simple; bh=hG2+BDNfy3pagO2sWcFkx0lXK/nck2spPLDruMjnR0I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Fj6/aoZqix3j9/fRW3fVTii27gmhU2arnGIVMJlcRLanm1iqGJWx1zkgIh/JUgdwOG+7CyyK5pc1IJ+CntbIzO18v82UXOIbGrtrFausHToe+0hl4lFcQ/wkXeDKpvJ+GDnbHIfJz/byq0LllV/FW85ZWhZajXJK5NyBnYy1Yjw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=acm.org; spf=pass smtp.mailfrom=acm.org; dkim=pass (2048-bit key) header.d=acm.org header.i=@acm.org header.b=bIqUh0+w; arc=none smtp.client-ip=199.89.1.12 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=acm.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=acm.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=acm.org header.i=@acm.org header.b="bIqUh0+w" Received: from localhost (localhost [127.0.0.1]) by 009.lax.mailroute.net (Postfix) with ESMTP id 4VvVmW2fGHzlgMVV; Wed, 5 Jun 2024 14:52:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=acm.org; h= content-transfer-encoding:mime-version:references:in-reply-to :x-mailer:message-id:date:date:subject:subject:from:from :received:received; s=mr01; t=1717599127; x=1720191128; bh=tPUDq vHHJnIoYtVbpAepuZthuvUDN03ZrbWJJYHu0wI=; b=bIqUh0+wKssnlfEgT87jf umqC+lvixPDa6bKzw2GMA2loyiRVzywSy8AjiYVcFux9UUQlOtwEAE/ji5cc5VaP NfYkQvbBxW7rk/MAjP0K8FyVbAOtbnyeIQWMpfi1AkLscBx8GbC3VSSl78lbPWtq tBe8uhFv6yK4o9xKxfscmnxt6PCUwlLPsDnix8tes03bP1A8AXM/L1qEqdz3Hatg O5Eh6m3s6T6ikTPjLmof6vGyK2c3rDbHyz8yIQQkHfF5ciUzM35WIrgiHUoQx/8D 0AqRpCthygiExU1TFn4F0SAdY26Vm1mgBg1v6Sdnrd+5cbaXuOMRQMcMBQ+qze/1 g== X-Virus-Scanned: by MailRoute Received: from 009.lax.mailroute.net ([127.0.0.1]) by localhost (009.lax [127.0.0.1]) (mroute_mailscanner, port 10029) with LMTP id U_w2qN5jHQlj; Wed, 5 Jun 2024 14:52:07 +0000 (UTC) Received: from bvanassche-glaptop2.roam.corp.google.com (unknown [65.117.37.195]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: bvanassche@acm.org) by 009.lax.mailroute.net (Postfix) with ESMTPSA id 4VvVmP1SjRzlgMVS; Wed, 5 Jun 2024 14:52:04 +0000 (UTC) From: Bart Van Assche To: Jason Gunthorpe Cc: Shinichiro Kawasaki , Zhu Yanjun , linux-rdma@vger.kernel.org, Bart Van Assche , Jason Gunthorpe , Leon Romanovsky , Zhu Yanjun , Joel Granados , Luis Chamberlain Subject: [PATCH 4/5] RDMA/iwcm: Simplify cm_work_handler() Date: Wed, 5 Jun 2024 08:51:00 -0600 Message-ID: <20240605145117.397751-5-bvanassche@acm.org> X-Mailer: git-send-email 2.45.1.288.g0e0cd299f1-goog In-Reply-To: <20240605145117.397751-1-bvanassche@acm.org> References: <20240605145117.397751-1-bvanassche@acm.org> Precedence: bulk X-Mailing-List: linux-rdma@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Instead of complicating the code to avoid a spin_lock_irqsave() / spin_lock_irqrestore() pair before returning, simplify the code by removing the local variable 'empty'. Signed-off-by: Bart Van Assche --- drivers/infiniband/core/iwcm.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/drivers/infiniband/core/iwcm.c b/drivers/infiniband/core/iwcm.c index 3d66aec36899..4424f430fc08 100644 --- a/drivers/infiniband/core/iwcm.c +++ b/drivers/infiniband/core/iwcm.c @@ -1017,16 +1017,13 @@ static void cm_work_handler(struct work_struct *_work) struct iw_cm_event levent; struct iwcm_id_private *cm_id_priv = work->cm_id; unsigned long flags; - int empty; int ret = 0; spin_lock_irqsave(&cm_id_priv->lock, flags); - empty = list_empty(&cm_id_priv->work_list); - while (!empty) { + while (!list_empty(&cm_id_priv->work_list)) { work = list_first_entry(&cm_id_priv->work_list, struct iwcm_work, list); list_del_init(&work->list); - empty = list_empty(&cm_id_priv->work_list); levent = work->event; put_work(work); spin_unlock_irqrestore(&cm_id_priv->lock, flags); @@ -1039,8 +1036,6 @@ static void cm_work_handler(struct work_struct *_work) pr_debug("dropping event %d\n", levent.event); if (iwcm_deref_id(cm_id_priv)) return; - if (empty) - return; spin_lock_irqsave(&cm_id_priv->lock, flags); } spin_unlock_irqrestore(&cm_id_priv->lock, flags); From patchwork Wed Jun 5 14:51:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 13687028 Received: from 009.lax.mailroute.net (009.lax.mailroute.net [199.89.1.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B5A0027450 for ; Wed, 5 Jun 2024 14:52:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=199.89.1.12 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717599142; cv=none; b=p0cScM5CYJX2lRo2doBMX7r/H7sHAcNeAJ1slQlA6icsfs5RkHewVO4knP8AeQeKBSp1NEXSeTdURkC1KD1SrxI90BNsgQ26NbFhPNWPxgbfOwf+DkkpQq5T7zofL8HTRWM8lTuCWX4MbcjnK0cI5JV+HQh9/2KKdqGmKXHD4rs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717599142; c=relaxed/simple; bh=TlKUs0z4HGQbT87QlP7EL88FFtI01S4xY4tN+HVAwns=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Qdqe0mCSph7rVIfXj9fEkwyz7RXGpam62TcfL9if8Z/KdMoAa1angyfK3vk3bchrXe2z0jAhIcS8G7VRv+h1sUHRDatdoel5zB331WCZ+wv3d9NDqnaMAzECLjskbw6CUGndmuyp4q9pQGFDTh0Of1MJ1WEzENSPjaI5zETuG60= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=acm.org; spf=pass smtp.mailfrom=acm.org; dkim=pass (2048-bit key) header.d=acm.org header.i=@acm.org header.b=KnfnMSlV; arc=none smtp.client-ip=199.89.1.12 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=acm.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=acm.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=acm.org header.i=@acm.org header.b="KnfnMSlV" Received: from localhost (localhost [127.0.0.1]) by 009.lax.mailroute.net (Postfix) with ESMTP id 4VvVmh1rlPzlgMVV; Wed, 5 Jun 2024 14:52:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=acm.org; h= content-transfer-encoding:mime-version:references:in-reply-to :x-mailer:message-id:date:date:subject:subject:from:from :received:received; s=mr01; t=1717599136; x=1720191137; bh=DHsoZ 4Tf+szqcoTBNHI8hXrUOmjHAAHzpWk3j4+V9Gk=; b=KnfnMSlVdXrJx7vNCQO7p b9twWsYmkU+yZt4SSYzwY67zwC1/QxKikg3fMEhc8JeENrOcWWxjE+7wYWeTVH2S HoaH8WQqOcTG6htU6csFxzqa1emsWZtLr58YT3nVdvXyuk5TdqDj2BZUt+6wrHt0 /eMw2Do/+XLDEaNdOxWk72mByvdIL4nnweOdhdtf49uYRO5sk5eYPXNFGByyeL4C eDh1+O+5lJJL6wU0aOe33JcgnaGRe2wsZ8Q3bEA+MYLBLcjPxxnUbWI7fZ4P19ua WK1qO1NqOXp3hykMLhX734PysD/GhaQXEDIv7GBoGKVILi3LjUeYWH8KyU/05kgV g== X-Virus-Scanned: by MailRoute Received: from 009.lax.mailroute.net ([127.0.0.1]) by localhost (009.lax [127.0.0.1]) (mroute_mailscanner, port 10029) with LMTP id kce4BlD2Lm03; Wed, 5 Jun 2024 14:52:16 +0000 (UTC) Received: from bvanassche-glaptop2.roam.corp.google.com (unknown [65.117.37.195]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: bvanassche@acm.org) by 009.lax.mailroute.net (Postfix) with ESMTPSA id 4VvVmZ1TjBzlgMVS; Wed, 5 Jun 2024 14:52:14 +0000 (UTC) From: Bart Van Assche To: Jason Gunthorpe Cc: Shinichiro Kawasaki , Zhu Yanjun , linux-rdma@vger.kernel.org, Bart Van Assche , Zhu Yanjun , Jason Gunthorpe , Leon Romanovsky , Luis Chamberlain , Joel Granados Subject: [PATCH 5/5] RDMA/iwcm: Fix a use-after-free related to destroying CM IDs Date: Wed, 5 Jun 2024 08:51:01 -0600 Message-ID: <20240605145117.397751-6-bvanassche@acm.org> X-Mailer: git-send-email 2.45.1.288.g0e0cd299f1-goog In-Reply-To: <20240605145117.397751-1-bvanassche@acm.org> References: <20240605145117.397751-1-bvanassche@acm.org> Precedence: bulk X-Mailing-List: linux-rdma@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 iw_conn_req_handler() associates a new struct rdma_id_private (conn_id) with an existing struct iw_cm_id (cm_id) as follows: conn_id->cm_id.iw = cm_id; cm_id->context = conn_id; cm_id->cm_handler = cma_iw_handler; rdma_destroy_id() frees both the cm_id and the struct rdma_id_private. Make sure that cm_work_handler() does not trigger a use-after-free by only freeing of the struct rdma_id_private after all pending work has finished. Cc: stable Reviewed-by: Zhu Yanjun Tested-by: Shin'ichiro Kawasaki Signed-off-by: Bart Van Assche --- drivers/infiniband/core/iwcm.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/drivers/infiniband/core/iwcm.c b/drivers/infiniband/core/iwcm.c index 4424f430fc08..1a6339f3a63f 100644 --- a/drivers/infiniband/core/iwcm.c +++ b/drivers/infiniband/core/iwcm.c @@ -368,8 +368,10 @@ EXPORT_SYMBOL(iw_cm_disconnect); * * Clean up all resources associated with the connection and release * the initial reference taken by iw_create_cm_id. + * + * Returns true if and only if the last cm_id_priv reference has been dropped. */ -static void destroy_cm_id(struct iw_cm_id *cm_id) +static bool destroy_cm_id(struct iw_cm_id *cm_id) { struct iwcm_id_private *cm_id_priv; struct ib_qp *qp; @@ -439,7 +441,7 @@ static void destroy_cm_id(struct iw_cm_id *cm_id) iwpm_remove_mapping(&cm_id->local_addr, RDMA_NL_IWCM); } - (void)iwcm_deref_id(cm_id_priv); + return iwcm_deref_id(cm_id_priv); } /* @@ -450,7 +452,8 @@ static void destroy_cm_id(struct iw_cm_id *cm_id) */ void iw_destroy_cm_id(struct iw_cm_id *cm_id) { - destroy_cm_id(cm_id); + if (!destroy_cm_id(cm_id)) + flush_workqueue(iwcm_wq); } EXPORT_SYMBOL(iw_destroy_cm_id); @@ -1031,7 +1034,7 @@ static void cm_work_handler(struct work_struct *_work) if (!test_bit(IWCM_F_DROP_EVENTS, &cm_id_priv->flags)) { ret = process_event(cm_id_priv, &levent); if (ret) - destroy_cm_id(&cm_id_priv->id); + WARN_ON_ONCE(destroy_cm_id(&cm_id_priv->id)); } else pr_debug("dropping event %d\n", levent.event); if (iwcm_deref_id(cm_id_priv))