From patchwork Tue Oct 27 13:50:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 312456 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F1FC6C838BD for ; Tue, 27 Oct 2020 15:47:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BAE2622400 for ; Tue, 27 Oct 2020 15:47:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603813671; bh=5u6CHnLpB3HGmcjBHJMqx7m7IYnaG5oATwrGpnFRLQQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=eo0De4Lcb2fg34S6/uVMlxKB5WXBOXmhxoS1h7JhoSU3CB/Y9MKO82r75qNMfo0zw 7r0z7SX50NXm//0ZnEsF6XDdnePYRxYaMovoAZw5sM41VhK8A+WqqYmait5dNo6TM1 Jsxj+vZbQHgd/jUlAJ007F7RigW9fNhxqOlS+Dqw= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1802076AbgJ0Ppb (ORCPT ); Tue, 27 Oct 2020 11:45:31 -0400 Received: from mail.kernel.org ([198.145.29.99]:57594 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1801062AbgJ0PiS (ORCPT ); Tue, 27 Oct 2020 11:38:18 -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 45E4C207C3; Tue, 27 Oct 2020 15:38:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603813097; bh=5u6CHnLpB3HGmcjBHJMqx7m7IYnaG5oATwrGpnFRLQQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UTiplpyM79h3UwrghIKj3vO66Ti9kUN70jfqluaapkwjaHYrrs/E771fM8NuQaZDS gLQArJ7m/SDr6oelxgHk98Oe0aFQzuUE8D/7OihTXCM2YLS04nePZd0629BvwDXlaX vE6dGtFTbe61HMDWjO7sb7GLlZ9+U9blHt+M4XU0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Lang Cheng , Weihang Li , Jason Gunthorpe , Sasha Levin Subject: [PATCH 5.9 409/757] RDMA/hns: Add a check for current state before modifying QP Date: Tue, 27 Oct 2020 14:50:59 +0100 Message-Id: <20201027135509.753789733@linuxfoundation.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201027135450.497324313@linuxfoundation.org> References: <20201027135450.497324313@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Lang Cheng [ Upstream commit e0ef0f68c4c0d85b1eb63f38d5d10324361280e8 ] It should be considered an illegal operation if the ULP attempts to modify a QP from another state to the current hardware state. Otherwise, the ULP can modify some fields of QPC at any time. For example, for a QP in state of RTS, modify it from RTR to RTS can change the PSN, which is always not as expected. Fixes: 9a4435375cd1 ("IB/hns: Add driver files for hns RoCE driver") Link: https://lore.kernel.org/r/1598353674-24270-1-git-send-email-liweihang@huawei.com Signed-off-by: Lang Cheng Signed-off-by: Weihang Li Signed-off-by: Jason Gunthorpe Signed-off-by: Sasha Levin --- drivers/infiniband/hw/hns/hns_roce_qp.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/infiniband/hw/hns/hns_roce_qp.c b/drivers/infiniband/hw/hns/hns_roce_qp.c index c063c450c715f..975281f034685 100644 --- a/drivers/infiniband/hw/hns/hns_roce_qp.c +++ b/drivers/infiniband/hw/hns/hns_roce_qp.c @@ -1161,8 +1161,10 @@ int hns_roce_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, mutex_lock(&hr_qp->mutex); - cur_state = attr_mask & IB_QP_CUR_STATE ? - attr->cur_qp_state : (enum ib_qp_state)hr_qp->state; + if (attr_mask & IB_QP_CUR_STATE && attr->cur_qp_state != hr_qp->state) + goto out; + + cur_state = hr_qp->state; new_state = attr_mask & IB_QP_STATE ? attr->qp_state : cur_state; if (ibqp->uobject &&