Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp388012pxk; Fri, 11 Sep 2020 09:33:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw5XjeW1lvjrbsQK/wkDb84m4oBkjfF1wK7ZsRK74Ct/69RHHMidpQ74pEgpbjupDZerjIp X-Received: by 2002:a17:906:724b:: with SMTP id n11mr2888342ejk.328.1599842017516; Fri, 11 Sep 2020 09:33:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599842017; cv=none; d=google.com; s=arc-20160816; b=GENZSqt9WSwwvE9GAbNAHckRrAD2ZCyhZt0JTRTEdYQ3N76L0jQPd/+KUr+jmgKc0c OJYePFjtLDEIwMV4SaSke4+kP/Xsp8iQYVJXs4OlOlgkQNJZhtrzREb68Lgbad/s6Q4/ S0KpLzPuPfXJE1fQZT26/jiOtURUJ2yVOWCfCnTJN9fvk/kH4hC7oruN1Fjki+hxa4dU 6S02LJ3LfXb6YPHYCr9bTYfknoLoLEOabkzAKbCIE9PhTrt/OZ352sW0x4q3T8cpvRsM RAtM/jvv1sOK/xgAbXzSFVocrHo3b5YUGmEDQV18P8rfJPfZrvTbRHr0a6UlKE0f7jix tDPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=dx1B56cXJznq2Pl5JNnfm1/ths8a/F4Hf3CtHlSvWkA=; b=WW8e7FbLxH6wN8VcXszpaptdnFalgdCVfdVtvk0Zau3pQCQcHht42tbwwgkLyH/ua6 u6IMK9RrPt5N6nkib4Lb9B+ZcC3xpuQOksdhDeJ+494XglMCRVjaD96Rv+bzItj+6Dv1 kEogjcjiJAcBCPjgLjRhr0bJUxXwVypG4tY1xDVRaZHyETwXCAyG+Q5/QXJcvVHBakdM n5qTDIad4kD9gskFNjkjwM/iFteAPCBzo8VyRiyqNxpyQY/nmKJ9pjAb+WDf5vhOJlnn TMeldO/Ff5ITg08PoLEg7TjqDEKBIDodUnAfeX3Tv9TJQl+bRc5JakqcyKcjFlQZFOd3 XNqw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=M7v+1825; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c24si1576533eja.263.2020.09.11.09.33.14; Fri, 11 Sep 2020 09:33:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=M7v+1825; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726253AbgIKQc3 (ORCPT + 99 others); Fri, 11 Sep 2020 12:32:29 -0400 Received: from mail.kernel.org ([198.145.29.99]:53914 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726456AbgIKPTJ (ORCPT ); Fri, 11 Sep 2020 11:19:09 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id BE62422210; Fri, 11 Sep 2020 12:59:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1599829196; bh=eVcYg1cJOefDsu6kms7fDMPDr5i2bdkGkA+Hpm7nYuo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=M7v+1825Fz4yuLgDuq4UUEfq3IcawKemnxKy4/mFBbFcn/NYMMBp1WHtz9S+2TtOH pqZYXC3rYitnzWDY6lt3h02Oghx2H7Ohd5vxijo+cMLrmcgJabp2fK2A3N5kjwbCYd pLrDhHciXVbLieCND2X5c6Uq9E+oUhvUGq6rTJuc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Leon Romanovsky , Jason Gunthorpe , Sasha Levin Subject: [PATCH 5.8 05/16] RDMA/cma: Remove unneeded locking for req paths Date: Fri, 11 Sep 2020 14:47:22 +0200 Message-Id: <20200911122459.843026940@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200911122459.585735377@linuxfoundation.org> References: <20200911122459.585735377@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jason Gunthorpe [ Upstream commit cc9c037343898eb7a775e6b81d092ee21eeff218 ] The REQ flows are concerned that once the handler is called on the new cm_id the ULP can choose to trigger a rdma_destroy_id() concurrently at any time. However, this is not true, while the ULP can call rdma_destroy_id(), it immediately blocks on the handler_mutex which prevents anything harmful from running concurrently. Remove the confusing extra locking and refcounts and make the handler_mutex protecting state during destroy more clear. Link: https://lore.kernel.org/r/20200723070707.1771101-4-leon@kernel.org Signed-off-by: Leon Romanovsky Signed-off-by: Jason Gunthorpe Signed-off-by: Sasha Levin --- drivers/infiniband/core/cma.c | 31 ++++++------------------------- 1 file changed, 6 insertions(+), 25 deletions(-) diff --git a/drivers/infiniband/core/cma.c b/drivers/infiniband/core/cma.c index 04151c301e851..11f43204fee77 100644 --- a/drivers/infiniband/core/cma.c +++ b/drivers/infiniband/core/cma.c @@ -1831,21 +1831,21 @@ static void cma_leave_mc_groups(struct rdma_id_private *id_priv) void rdma_destroy_id(struct rdma_cm_id *id) { - struct rdma_id_private *id_priv; + struct rdma_id_private *id_priv = + container_of(id, struct rdma_id_private, id); enum rdma_cm_state state; - id_priv = container_of(id, struct rdma_id_private, id); - trace_cm_id_destroy(id_priv); - state = cma_exch(id_priv, RDMA_CM_DESTROYING); - cma_cancel_operation(id_priv, state); - /* * Wait for any active callback to finish. New callbacks will find * the id_priv state set to destroying and abort. */ mutex_lock(&id_priv->handler_mutex); + trace_cm_id_destroy(id_priv); + state = cma_exch(id_priv, RDMA_CM_DESTROYING); mutex_unlock(&id_priv->handler_mutex); + cma_cancel_operation(id_priv, state); + rdma_restrack_del(&id_priv->res); if (id_priv->cma_dev) { if (rdma_cap_ib_cm(id_priv->id.device, 1)) { @@ -2205,19 +2205,9 @@ static int cma_ib_req_handler(struct ib_cm_id *cm_id, cm_id->context = conn_id; cm_id->cm_handler = cma_ib_handler; - /* - * Protect against the user destroying conn_id from another thread - * until we're done accessing it. - */ - cma_id_get(conn_id); ret = cma_cm_event_handler(conn_id, &event); if (ret) goto err3; - /* - * Acquire mutex to prevent user executing rdma_destroy_id() - * while we're accessing the cm_id. - */ - mutex_lock(&lock); if (cma_comp(conn_id, RDMA_CM_CONNECT) && (conn_id->id.qp_type != IB_QPT_UD)) { trace_cm_send_mra(cm_id->context); @@ -2226,13 +2216,11 @@ static int cma_ib_req_handler(struct ib_cm_id *cm_id, mutex_unlock(&lock); mutex_unlock(&conn_id->handler_mutex); mutex_unlock(&listen_id->handler_mutex); - cma_id_put(conn_id); if (net_dev) dev_put(net_dev); return 0; err3: - cma_id_put(conn_id); /* Destroy the CM ID by returning a non-zero value. */ conn_id->cm_id.ib = NULL; err2: @@ -2409,11 +2397,6 @@ static int iw_conn_req_handler(struct iw_cm_id *cm_id, memcpy(cma_src_addr(conn_id), laddr, rdma_addr_size(laddr)); memcpy(cma_dst_addr(conn_id), raddr, rdma_addr_size(raddr)); - /* - * Protect against the user destroying conn_id from another thread - * until we're done accessing it. - */ - cma_id_get(conn_id); ret = cma_cm_event_handler(conn_id, &event); if (ret) { /* User wants to destroy the CM ID */ @@ -2421,13 +2404,11 @@ static int iw_conn_req_handler(struct iw_cm_id *cm_id, cma_exch(conn_id, RDMA_CM_DESTROYING); mutex_unlock(&conn_id->handler_mutex); mutex_unlock(&listen_id->handler_mutex); - cma_id_put(conn_id); rdma_destroy_id(&conn_id->id); return ret; } mutex_unlock(&conn_id->handler_mutex); - cma_id_put(conn_id); out: mutex_unlock(&listen_id->handler_mutex); -- 2.25.1