Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3318869pxj; Tue, 11 May 2021 01:33:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw5Ezn3rdu+Q6syrBzsLGe8EkPHiFwts2eIw20QYy9auAQXmbpKYOk4NZs/PKpwGaf88S1N X-Received: by 2002:a05:6e02:e0d:: with SMTP id a13mr25392028ilk.270.1620721982217; Tue, 11 May 2021 01:33:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620721982; cv=none; d=google.com; s=arc-20160816; b=wwyOXOtJf8TsfFFlOz52TVScOHEnPoe9nhi0rT2WnkB3gGVHX6IShsBAmc2hpfe3fA jA5oPPnHpgpsoQStFyxkOGtJWncKMW1dd4BHtvmZZfgk0mtk7DDNkAmCMNAW16xgITvG +b27a7mAp0RSoKjTpIFsG5WUEpNk2OdQqmUcGURL22OmnxXgKI/oCoejbOKrfIMmvfXV hZ0xfqujUSCNBY9uesp8Ya8bS1Fph9Hl6bKgrsliC5bf/ZRF07B+7cEcvuF8nZpNaOka IMKJdeuZTZHmGmBzM6PeRedsDkZqtdUG1ppnqi9ky75irSWOFX7Zwp49J4aJeuaSh36p 70sg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=dPamkTnGKSb3ykAihzvV9PM+JyepaLpodU2zt2OAr7Y=; b=cijnD6uYv9/XnrBGjbvzNNmcM0uwG3ec4KvcTLyQLhQ9vsUeiSnttCgwYjZgFfr0pT DbR8jBYh8m+79xaZV4KtRlHN1gEgHYuhgwRUW4urK94q9IMUicMCWy0sz4JkuEort/1H 0iYoWdIxhQxWk7lqPWlFWIa9SagcBPW/ZxVyj4Z61asFfgRR09H6z2IQiAbyytF60on2 Mumai1gTIydKYy9Gda9/qpoFgRytcWZFAMT1H7CGftZQ9xO952oJSDEmx2Orh5LTCDJb eUO6/8UNvjrMrCaKLNu8GB9iEhPi06Mf71j150feAs0DqPZMjmNUsvYcNtqCOq+VRVdB aiAw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=H7Kf27d7; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b24si7379757jar.82.2021.05.11.01.32.50; Tue, 11 May 2021 01:33:02 -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=k20201202 header.b=H7Kf27d7; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231286AbhEKIc7 (ORCPT + 99 others); Tue, 11 May 2021 04:32:59 -0400 Received: from mail.kernel.org ([198.145.29.99]:42602 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230333AbhEKIcj (ORCPT ); Tue, 11 May 2021 04:32:39 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 239A961928; Tue, 11 May 2021 08:22:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1620721356; bh=9BZAAzBXUsFnxzBksVs8V35KTMzLRNT1T8uiN0llGBY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=H7Kf27d7iss6/EhpRGz72Q3VdPMJlJvC/jIZseQo7Yu3hyYKLFy0+uz+ZM2jsIfpc ovfaC9tuciJyEWCk+aZu1e1qP9kza6Bo9gbvpVel6vYCxXMxCuoW2PTPCY+EQTr6ov DzWAFJr9kXYd/ZToDQzmPG7QLAmZRz08rW8NPGxojw4zVUVMQxqsVlVl1Tq5TwIpKi 6UYF4Pdzw1Wff0CYX3oEdgGDIBuq0sewvolAoiBEu7Lprp6buZ4YtevaHIFiROL4em P+tHhMYGT7HMg6abd47luIWOSMImGq8lMjk93QaoLPh9CZyahLx6KSpQ3IDSpGDqo7 mYm62fqCOYGJA== From: Leon Romanovsky To: Doug Ledford , Jason Gunthorpe Cc: linux-kernel@vger.kernel.org, linux-rdma@vger.kernel.org, Mark Zhang , Sean Hefty Subject: [PATCH rdma-next v3 3/8] IB/cm: Call the correct message free functions in cm_send_handler() Date: Tue, 11 May 2021 11:22:07 +0300 Message-Id: <2b7b09d9c9f53a5c7c3695919828234e9f873fe4.1620720467.git.leonro@nvidia.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jason Gunthorpe There are now three destroy functions for the cm_msg, and all places except the general send completion handler use the correct function. Fix cm_send_handler() to detect which kind of message is being completed and destroy it using the correct function with the correct locking. Signed-off-by: Jason Gunthorpe Signed-off-by: Leon Romanovsky --- drivers/infiniband/core/cm.c | 52 +++++++++++++++++------------------- 1 file changed, 25 insertions(+), 27 deletions(-) diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c index 94613275edcc..8dbc39ea4612 100644 --- a/drivers/infiniband/core/cm.c +++ b/drivers/infiniband/core/cm.c @@ -3795,22 +3795,26 @@ static int cm_sidr_rep_handler(struct cm_work *work) return -EINVAL; } -static void cm_process_send_error(struct ib_mad_send_buf *msg, +static void cm_process_send_error(struct cm_id_private *cm_id_priv, + struct ib_mad_send_buf *msg, + enum ib_cm_state state, enum ib_wc_status wc_status) { - struct cm_id_private *cm_id_priv; - struct ib_cm_event cm_event; - enum ib_cm_state state; + struct ib_cm_event cm_event = {}; int ret; - memset(&cm_event, 0, sizeof cm_event); - cm_id_priv = msg->context[0]; - /* Discard old sends or ones without a response. */ spin_lock_irq(&cm_id_priv->lock); - state = (enum ib_cm_state) (unsigned long) msg->context[1]; - if (msg != cm_id_priv->msg || state != cm_id_priv->id.state) - goto discard; + if (msg != cm_id_priv->msg) { + spin_unlock_irq(&cm_id_priv->lock); + cm_free_msg(msg); + return; + } + cm_free_priv_msg(msg); + + if (state != cm_id_priv->id.state || wc_status == IB_WC_SUCCESS || + wc_status == IB_WC_WR_FLUSH_ERR) + goto out_unlock; trace_icm_mad_send_err(state, wc_status); switch (state) { @@ -3833,26 +3837,27 @@ static void cm_process_send_error(struct ib_mad_send_buf *msg, cm_event.event = IB_CM_SIDR_REQ_ERROR; break; default: - goto discard; + goto out_unlock; } spin_unlock_irq(&cm_id_priv->lock); cm_event.param.send_status = wc_status; /* No other events can occur on the cm_id at this point. */ ret = cm_id_priv->id.cm_handler(&cm_id_priv->id, &cm_event); - cm_free_msg(msg); if (ret) ib_destroy_cm_id(&cm_id_priv->id); return; -discard: +out_unlock: spin_unlock_irq(&cm_id_priv->lock); - cm_free_msg(msg); } static void cm_send_handler(struct ib_mad_agent *mad_agent, struct ib_mad_send_wc *mad_send_wc) { struct ib_mad_send_buf *msg = mad_send_wc->send_buf; + struct cm_id_private *cm_id_priv = msg->context[0]; + enum ib_cm_state state = + (enum ib_cm_state)(unsigned long)msg->context[1]; struct cm_port *port; u16 attr_index; @@ -3865,7 +3870,7 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent, * set to a cm_id), and is not a REJ, then it is a send that was * manually retried. */ - if (!msg->context[0] && (attr_index != CM_REJ_COUNTER)) + if (!cm_id_priv && (attr_index != CM_REJ_COUNTER)) msg->retries = 1; atomic_long_add(1 + msg->retries, @@ -3875,18 +3880,11 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent, &port->counter_group[CM_XMIT_RETRIES]. counter[attr_index]); - switch (mad_send_wc->status) { - case IB_WC_SUCCESS: - case IB_WC_WR_FLUSH_ERR: - cm_free_msg(msg); - break; - default: - if (msg->context[0] && msg->context[1]) - cm_process_send_error(msg, mad_send_wc->status); - else - cm_free_msg(msg); - break; - } + if (cm_id_priv) + cm_process_send_error(cm_id_priv, msg, state, + mad_send_wc->status); + else + cm_free_response_msg(msg); } static void cm_work_handler(struct work_struct *_work) -- 2.31.1