Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp223336pxx; Wed, 28 Oct 2020 03:18:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxwe9yBzyiFnWDoPka3pUa+Dbf/pPrP2vEhtyGIdwqSSfKk1Ab/E7E0FFPr91QfTP6ZVN3/ X-Received: by 2002:a17:906:3cc:: with SMTP id c12mr6679158eja.210.1603880304916; Wed, 28 Oct 2020 03:18:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603880304; cv=none; d=google.com; s=arc-20160816; b=LVMK1+HuuyR5op9xHGhAo+9oGEQfHl4Btv7hie+mjN0eu9QhaDKb0lsOKb9ttFNpAU 2u76AeKKEXfiL+p27rLEEjdZeJYAfUs3zk86bq/+wxRrn3y+v3mkO0PDwo+LrCb8Phxy oNL+oPUPYSWR/W+mD0IKDPUK/arSDMm69mAbSqVDytz+wvOpKfPcrOOwUxvbpgo/JKqH pJwABNROY2Oo2K2oRziJySYOsoRGsqVWlx4lFIHbs7jatxSp+BJa//HsuzkiZ5+vtVyc S22hKeanaCCGLRjO5ieBgQf0aBWnMRWgYtuCChGAmy/67eTWZWHaBYinCsrEo5IgE6AT kyIw== 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=k1eDfxpFI6WajTOC/c8jBzsbJodcReyoUTeE/RswPhA=; b=sDGtlL5sBUUNJ0FCfumegLYoHkrheAcoN6CWnZViPqIc4YZUcXtYsPnRSlZX4pA/iy fpTH0epMgSqc6KnFHsu3WgSxwYWbmF4PaETXws+Ng6IH6bwM1j2mD3sSvF7hdqkkEQJx WMFK2fMXbrIe42DgsF6N+POepdH32NeiR3WKsNCIN+8UbCoE/HpG4TH2rsGDoDF4jCin UGoFfqxjThJD+KoUu+I24C9GHj5gr07NziZ5VlHBv4Re+OyBanaOAyJcpHvdQhEjOmm9 T96geoZ05hEGfvZ7k0211uKY/rYo65D1Olto5qCkL6dQldMLswkL2Uij1WQXzBhpt2s9 F9og== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Gu8uyq72; 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 y9si2654785ede.591.2020.10.28.03.18.02; Wed, 28 Oct 2020 03:18:24 -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=Gu8uyq72; 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 S1761049AbgJ0Ohq (ORCPT + 99 others); Tue, 27 Oct 2020 10:37:46 -0400 Received: from mail.kernel.org ([198.145.29.99]:36806 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1761006AbgJ0Ohm (ORCPT ); Tue, 27 Oct 2020 10:37:42 -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 AA19E20759; Tue, 27 Oct 2020 14:37:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603809462; bh=ztkl12GQR6cNGhXqfbGMj2z38KOAVYMM4dj/6xgAZKI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Gu8uyq721T28pJpxv974TOaFpcia73svS0EN1ELjVpYHw6JRLm5+qv4UBfuOB6Top 4iUup/yK5wKH9lMxdPJDX82oi7Ko0SaaIttyYpWiRbcvvfMTczRdKqPbUFnnUKUQRy kTkQKiqqpxgbqFSw2RaStf71XHJ4sPI4mE4uSmB0= 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.4 204/408] RDMA/hns: Add a check for current state before modifying QP Date: Tue, 27 Oct 2020 14:52:22 +0100 Message-Id: <20201027135504.564180604@linuxfoundation.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201027135455.027547757@linuxfoundation.org> References: <20201027135455.027547757@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: 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 8dd2d666f6875..730e50c87a760 100644 --- a/drivers/infiniband/hw/hns/hns_roce_qp.c +++ b/drivers/infiniband/hw/hns/hns_roce_qp.c @@ -1181,8 +1181,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 && -- 2.25.1