Received: by 2002:ac0:aa62:0:0:0:0:0 with SMTP id w31-v6csp1938521ima; Thu, 25 Oct 2018 07:17:45 -0700 (PDT) X-Google-Smtp-Source: AJdET5e4XKWgi/fZDJv/y8a72BxBRpxr6MNg1p3zhXLUewt40eURdGuaWFM24IHh+E8HjvVg4pMf X-Received: by 2002:a63:65c7:: with SMTP id z190mr1663271pgb.249.1540477065669; Thu, 25 Oct 2018 07:17:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540477065; cv=none; d=google.com; s=arc-20160816; b=nbd/+7H0F/zi9evaF5DNpe0epof7OwAv+uLVvJa+m4WTvbILgGuh5rJV4JitvY2S+e jBmmkJNEF0byek+AxCKAhm6tYbH9DRhUOjEAHLerykL58n8nfcFSbf31TP/Aq5tAwgCR iyWMuHcIJdOGEg63jfdNnpXzfWQonjY6lJUhMxv/bYLMPf2cMkEbViqDBFS16cixPzS/ pbAniyl7g7bonAwGPSUXPMnKy5Zx1wnTTMCnr9c+g30/1rBFWCmgwk0PeUKlxG69tGw3 aD+rTag5GWZDM7da6DmprwEcBZVegU3vnDTBxAtpqbRzO52ooA1rA5Ct9re+gTxX2r/f qN6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=x8WEOK2Bd35Z8yDOHsAv9sbFB4NyCSkq3lc0rqE1hSI=; b=Cj5R9Uop0mrF4jywHnZf5PRa21TKzqDTQqwco8/MZ3PU+m4aaQjBF8CvLeGRl1RnZq ZrR8y+tRMpGJ4AvOdxfOJa8bDSSFG4+mi+G5Xd/kl57jAv48WlFVGgc4UVukQyu3ZjUV QtUMjzcGmgqS7WPBCUUKHfUKm6++A5PI7XZvstaSeie6c77zssE1XTq6hngVWFz8TITf T4hHTh3Dvc14xTl809cxuCRJykj6BJx3ZIapIJG4fudU44OLghi8oVjPA2d4MqTTOMDh 5b9EfrJMmEnb1iDp1lH/2laNfI50gXhDG33oQ3ribu8R2wcF+rAi8LQGmwR3N3rFSRKB 8jjw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=1zMxzdJB; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id 34-v6si7995580pgy.249.2018.10.25.07.17.02; Thu, 25 Oct 2018 07:17:45 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=1zMxzdJB; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1728078AbeJYWoS (ORCPT + 99 others); Thu, 25 Oct 2018 18:44:18 -0400 Received: from mail.kernel.org ([198.145.29.99]:52934 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727401AbeJYWoR (ORCPT ); Thu, 25 Oct 2018 18:44:17 -0400 Received: from sasha-vm.mshome.net (unknown [167.98.65.38]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id A1BDB20848; Thu, 25 Oct 2018 14:11:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1540476681; bh=LHHX4W1Cjw2bXCkCJStdF7Qks4/K2X/nA/+6jSmQJ4Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1zMxzdJBrbBy7WLHfAmUq2/CBsGswnfnDM5w0j2D51Dyn8Hcxv4ILr8zyot/xbp4X Zb0/scMnmBRI1rnyRh+yYiTNbQ46pHYJN0TrTpdK9QoKXTQblxYX6lQUmci7tr7+H3 /ERpz6VluW0TDDHn8nzsSCZrskifNlOzgKFaMDT4= From: Sasha Levin To: stable@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Noa Osherovich , Leon Romanovsky , Jason Gunthorpe , Sasha Levin Subject: [PATCH AUTOSEL 4.14 19/46] IB/mlx5: Avoid passing an invalid QP type to firmware Date: Thu, 25 Oct 2018 10:10:26 -0400 Message-Id: <20181025141053.213330-19-sashal@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181025141053.213330-1-sashal@kernel.org> References: <20181025141053.213330-1-sashal@kernel.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Noa Osherovich [ Upstream commit e7b169f34403becd3c9fd3b6e46614ab788f2187 ] During QP creation, the mlx5 driver translates the QP type to an internal value which is passed on to FW. There was no check to make sure that the translated value is valid, and -EINVAL was coerced into the mailbox command. Current firmware refuses this as an invalid QP type, but future/past firmware may do something else. Fixes: 09a7d9eca1a6c ('{net,IB}/mlx5: QP/XRCD commands via mlx5 ifc') Reviewed-by: Ilya Lesokhin Signed-off-by: Noa Osherovich Signed-off-by: Leon Romanovsky Signed-off-by: Jason Gunthorpe Signed-off-by: Sasha Levin --- drivers/infiniband/hw/mlx5/qp.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/infiniband/hw/mlx5/qp.c b/drivers/infiniband/hw/mlx5/qp.c index ef9ee6c328a1..dfc190055167 100644 --- a/drivers/infiniband/hw/mlx5/qp.c +++ b/drivers/infiniband/hw/mlx5/qp.c @@ -1527,6 +1527,7 @@ static int create_qp_common(struct mlx5_ib_dev *dev, struct ib_pd *pd, u32 uidx = MLX5_IB_DEFAULT_UIDX; struct mlx5_ib_create_qp ucmd; struct mlx5_ib_qp_base *base; + int mlx5_st; void *qpc; u32 *in; int err; @@ -1535,6 +1536,10 @@ static int create_qp_common(struct mlx5_ib_dev *dev, struct ib_pd *pd, spin_lock_init(&qp->sq.lock); spin_lock_init(&qp->rq.lock); + mlx5_st = to_mlx5_st(init_attr->qp_type); + if (mlx5_st < 0) + return -EINVAL; + if (init_attr->rwq_ind_tbl) { if (!udata) return -ENOSYS; @@ -1688,7 +1693,7 @@ static int create_qp_common(struct mlx5_ib_dev *dev, struct ib_pd *pd, qpc = MLX5_ADDR_OF(create_qp_in, in, qpc); - MLX5_SET(qpc, qpc, st, to_mlx5_st(init_attr->qp_type)); + MLX5_SET(qpc, qpc, st, mlx5_st); MLX5_SET(qpc, qpc, pm_state, MLX5_QP_PM_MIGRATED); if (init_attr->qp_type != MLX5_IB_QPT_REG_UMR) -- 2.17.1