Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp2730391pxv; Mon, 12 Jul 2021 00:06:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzfTGDjwwFrm9/6BIw/xV8qkjxInq3pIaAilQE2z6XcBIS/vbP3oF4G2yYtwlP768SLdNAb X-Received: by 2002:a02:9508:: with SMTP id y8mr8553257jah.28.1626073585414; Mon, 12 Jul 2021 00:06:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626073585; cv=none; d=google.com; s=arc-20160816; b=rzVVHLJWQc4JTqBqezan4vAUBCPJSInoAn7jeprIhOpAr0A1n7fWAfR337t8O/MM0/ K5go0Iw8O3qb7EtgzoVLwdrqX/sXDuRUlgdGMynfwyaaRwAHYFnJBVQ8QHiwY9qztyRU bPiKkurGcn3OpXs8/iXlU1dSdzxAALp9RXiT+vfZe8AtqaSCis1U0lVOAh57IK+FwZbf Kpv6wOl9nnICyU8oClkJQ5YPsFqENSMyFqICGkSrIqUcVmQW78uiQNo5zAE5ig5H20aF Lat67pGY26Vq6GqHZI5oLu/DLLvjaowxYVvoOnT0+RhUo/L7CCM4nyjOb3/6rTMu+yG3 tVew== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=PrPH6eb8OuvzdWKZGgiYEsDcgBb9pp0nsCxkSO0Gpjw=; b=Vcje5X3RmGNrclp+a6GcB1Fvbp4QQHI/94yMmH11+Ctg8/QgZLHs4prj0k2Tf39D7c 06w6xCaszSoacNonTG7IpegoeJA0j1UzCqFmIbwy1SHlerbeBau224hQ4SQr5+e/+lEa u/kEnXgW0agcxidZp0nwE7yfa778D3oqf+pyoFdtwogBp6qi0Zi1G1/88eSKlUZHt4sL xWdSuZdaeEhc0Ox8Nao9G8CP2InhHoJXe2t4E+xnoLT+DFxO4BsOcv7aH0SwDuS0lBNJ koQS1KLG0kP0jCIXhGdGEDkf3+OUYUBY6UHCDoCITUYMXHBIbDVKaBKRjaHf6Kr1ABB/ tiNQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=DFtA21UO; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x6si18719883ilv.67.2021.07.12.00.06.13; Mon, 12 Jul 2021 00:06:25 -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=@linuxfoundation.org header.s=korg header.b=DFtA21UO; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242315AbhGLHG3 (ORCPT + 99 others); Mon, 12 Jul 2021 03:06:29 -0400 Received: from mail.kernel.org ([198.145.29.99]:41510 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236498AbhGLGri (ORCPT ); Mon, 12 Jul 2021 02:47:38 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 63656611CB; Mon, 12 Jul 2021 06:43:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626072212; bh=dpu62USOhkEH0eOsgXGo/05l5BwgQmJSbp7R2YzhDS4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DFtA21UOvdepP2ojuTXhBXvYhYw1aFv4R9lJE0hF/M5PUrsesk4MRmsBd4PM+K8o9 qRtJjTbJ3RlRSvRdUoFjV+zDX3Oex6/pCc5vztHtui+U3anuzBO30zRGepa5g3ENvj b/xbaJviOgfASUSVI8S3N03TCwfuq3k81AtCMoeA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, =?UTF-8?q?H=C3=A5kon=20Bugge?= , Jason Gunthorpe , Sasha Levin Subject: [PATCH 5.10 402/593] RDMA/cma: Protect RMW with qp_mutex Date: Mon, 12 Jul 2021 08:09:22 +0200 Message-Id: <20210712060931.879039114@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210712060843.180606720@linuxfoundation.org> References: <20210712060843.180606720@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Håkon Bugge [ Upstream commit ca0c448d2b9f43e3175835d536853854ef544e22 ] The struct rdma_id_private contains three bit-fields, tos_set, timeout_set, and min_rnr_timer_set. These are set by accessor functions without any synchronization. If two or all accessor functions are invoked in close proximity in time, there will be Read-Modify-Write from several contexts to the same variable, and the result will be intermittent. Fixed by protecting the bit-fields by the qp_mutex in the accessor functions. The consumer of timeout_set and min_rnr_timer_set is in rdma_init_qp_attr(), which is called with qp_mutex held for connected QPs. Explicit locking is added for the consumers of tos and tos_set. This commit depends on ("RDMA/cma: Remove unnecessary INIT->INIT transition"), since the call to rdma_init_qp_attr() from cma_init_conn_qp() does not hold the qp_mutex. Fixes: 2c1619edef61 ("IB/cma: Define option to set ack timeout and pack tos_set") Fixes: 3aeffc46afde ("IB/cma: Introduce rdma_set_min_rnr_timer()") Link: https://lore.kernel.org/r/1624369197-24578-3-git-send-email-haakon.bugge@oracle.com Signed-off-by: Håkon Bugge Signed-off-by: Jason Gunthorpe Signed-off-by: Sasha Levin --- drivers/infiniband/core/cma.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/drivers/infiniband/core/cma.c b/drivers/infiniband/core/cma.c index d1e94147fb16..f2fd4bc2fbec 100644 --- a/drivers/infiniband/core/cma.c +++ b/drivers/infiniband/core/cma.c @@ -2476,8 +2476,10 @@ static int cma_iw_listen(struct rdma_id_private *id_priv, int backlog) if (IS_ERR(id)) return PTR_ERR(id); + mutex_lock(&id_priv->qp_mutex); id->tos = id_priv->tos; id->tos_set = id_priv->tos_set; + mutex_unlock(&id_priv->qp_mutex); id_priv->cm_id.iw = id; memcpy(&id_priv->cm_id.iw->local_addr, cma_src_addr(id_priv), @@ -2537,8 +2539,10 @@ static int cma_listen_on_dev(struct rdma_id_private *id_priv, cma_id_get(id_priv); dev_id_priv->internal_id = 1; dev_id_priv->afonly = id_priv->afonly; + mutex_lock(&id_priv->qp_mutex); dev_id_priv->tos_set = id_priv->tos_set; dev_id_priv->tos = id_priv->tos; + mutex_unlock(&id_priv->qp_mutex); ret = rdma_listen(&dev_id_priv->id, id_priv->backlog); if (ret) @@ -2585,8 +2589,10 @@ void rdma_set_service_type(struct rdma_cm_id *id, int tos) struct rdma_id_private *id_priv; id_priv = container_of(id, struct rdma_id_private, id); + mutex_lock(&id_priv->qp_mutex); id_priv->tos = (u8) tos; id_priv->tos_set = true; + mutex_unlock(&id_priv->qp_mutex); } EXPORT_SYMBOL(rdma_set_service_type); @@ -2613,8 +2619,10 @@ int rdma_set_ack_timeout(struct rdma_cm_id *id, u8 timeout) return -EINVAL; id_priv = container_of(id, struct rdma_id_private, id); + mutex_lock(&id_priv->qp_mutex); id_priv->timeout = timeout; id_priv->timeout_set = true; + mutex_unlock(&id_priv->qp_mutex); return 0; } @@ -3000,8 +3008,11 @@ static int cma_resolve_iboe_route(struct rdma_id_private *id_priv) u8 default_roce_tos = id_priv->cma_dev->default_roce_tos[id_priv->id.port_num - rdma_start_port(id_priv->cma_dev->device)]; - u8 tos = id_priv->tos_set ? id_priv->tos : default_roce_tos; + u8 tos; + mutex_lock(&id_priv->qp_mutex); + tos = id_priv->tos_set ? id_priv->tos : default_roce_tos; + mutex_unlock(&id_priv->qp_mutex); work = kzalloc(sizeof *work, GFP_KERNEL); if (!work) @@ -3048,8 +3059,10 @@ static int cma_resolve_iboe_route(struct rdma_id_private *id_priv) * PacketLifeTime = local ACK timeout/2 * as a reasonable approximation for RoCE networks. */ + mutex_lock(&id_priv->qp_mutex); route->path_rec->packet_life_time = id_priv->timeout_set ? id_priv->timeout - 1 : CMA_IBOE_PACKET_LIFETIME; + mutex_unlock(&id_priv->qp_mutex); if (!route->path_rec->mtu) { ret = -EINVAL; @@ -4073,8 +4086,11 @@ static int cma_connect_iw(struct rdma_id_private *id_priv, if (IS_ERR(cm_id)) return PTR_ERR(cm_id); + mutex_lock(&id_priv->qp_mutex); cm_id->tos = id_priv->tos; cm_id->tos_set = id_priv->tos_set; + mutex_unlock(&id_priv->qp_mutex); + id_priv->cm_id.iw = cm_id; memcpy(&cm_id->local_addr, cma_src_addr(id_priv), -- 2.30.2