Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp2230321ybe; Tue, 3 Sep 2019 09:42:58 -0700 (PDT) X-Google-Smtp-Source: APXvYqyiERArer+0f1kQkpXf83P9f7fb7wIKS5taJmlC/37Pf7SP1E7z4xv4NhQjTHCARGCSk8xv X-Received: by 2002:a63:2264:: with SMTP id t36mr29825311pgm.87.1567528977856; Tue, 03 Sep 2019 09:42:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567528977; cv=none; d=google.com; s=arc-20160816; b=i4WP2YSGQql8G5v7qPA7z5xtttj+5RhT9Mv2MQjdfIkNuwzGPu8GQtse3P+nmqXXEy 9IPdRLWiUJegx0KEvwBlFuCeEjT+K0vuTwU+ho8UcDkv795pNoFzGfYu+s94LMYFU3Tt HHGwNaw5Jubr8va9nuifbdvcFwRk2drA2qfhKgodMCRlEcljbc5C7K0pN8+A9fw+4YWK 7a16uDtM5YEbDBCNjTaURlYgt76tQB1cz8oZ7Mo87WYKyBu+AreZvMWLsKWL59cVhU7I bubuJebY+Sv0ePFjR0pfGDh4pBYvAwqHVy/gQRQPcdtV9KJ6gVgUBxiPJiqidRR7m9LZ XAkw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=veu+/OzyjOweT7nUGGfDvIMRugwGhzu7M/Rx5S0A4Kc=; b=Q//siq/CMRAddzsAALpWUHlrztUjXuUW+XLbMVxDEhCiT1YTaU9kFHKXY0g0MmIzO3 HQ9+xHhRC7alRO5HbLhGDBWmF7Nb+kVHEGMhqgCBmABCKtzRZZ6oydyH6gTQnynd+IBD PZmRpEm7izRazWgFIZsWm5mAPBxt5alaDJ4YCnU+5xR+6FBun47aVmGI6P3IGG2N1NEU OoqiKSfjSxGKuWN/de8bTIpSQkcL6kOQe3rj26B7YHItBE9uEFKBcwqJ71GMUfMti0SA QleqQGsZSARDk+80vkkcXEreO5Aadd2xBGJ0bwTP0FIK9G5FxhalsiHf53griL3K8RDf 4B4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=gfpXAegA; 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 f15si15350225plm.292.2019.09.03.09.42.42; Tue, 03 Sep 2019 09:42:57 -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=gfpXAegA; 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 S1730226AbfICQZA (ORCPT + 99 others); Tue, 3 Sep 2019 12:25:00 -0400 Received: from mail.kernel.org ([198.145.29.99]:44632 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730194AbfICQY5 (ORCPT ); Tue, 3 Sep 2019 12:24:57 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (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 7D52523697; Tue, 3 Sep 2019 16:24:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1567527896; bh=ClRwCvx8HHpkFwO3LeGjqjqNIj13E59y3JUVDZqeXGg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gfpXAegAvu3TWt4HSrhXA9VdtXFeb2ze8ju3j2jm8R20jV3e8axUYvR35XCcwC8d4 MqJgrxEqqsykGqY9mz6JUL2xRt+AsAh7N8n89ylk6+YdYjh64S5Edlzyeis7P5qxnb q7wSPaz7sP52tYhH3RMRRoiEzRUt10LcKUEGFIis= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Mike Marciniszyn , "Michael J . Ruhl" , Dennis Dalessandro , Doug Ledford , linux-rdma@vger.kernel.org Subject: [PATCH AUTOSEL 5.2 09/23] IB/rdmavt: Add new completion inline Date: Tue, 3 Sep 2019 12:24:10 -0400 Message-Id: <20190903162424.6877-9-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190903162424.6877-1-sashal@kernel.org> References: <20190903162424.6877-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Mike Marciniszyn There is opencoded send completion logic all over all the drivers. We need to convert to this routine to enforce ordering issues for completions. This routine fixes an ordering issue where the read of the SWQE fields necessary for creating the completion can race with a post send if the post send catches a send queue at the edge of being full. Is is possible in that situation to read SWQE fields that are being written. This new routine insures that SWQE fields are read prior to advancing the index that post send uses to determine queue fullness. Reviewed-by: Michael J. Ruhl Signed-off-by: Mike Marciniszyn Signed-off-by: Dennis Dalessandro Signed-off-by: Doug Ledford --- include/rdma/rdmavt_qp.h | 72 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/include/rdma/rdmavt_qp.h b/include/rdma/rdmavt_qp.h index 68e38c20afc04..6014f17669071 100644 --- a/include/rdma/rdmavt_qp.h +++ b/include/rdma/rdmavt_qp.h @@ -737,6 +737,78 @@ static inline void rvt_put_qp_swqe(struct rvt_qp *qp, struct rvt_swqe *wqe) atomic_dec(&ibah_to_rvtah(wqe->ud_wr.ah)->refcount); } +/** + * rvt_qp_sqwe_incr - increment ring index + * @qp: the qp + * @val: the starting value + * + * Return: the new value wrapping as appropriate + */ +static inline u32 +rvt_qp_swqe_incr(struct rvt_qp *qp, u32 val) +{ + if (++val >= qp->s_size) + val = 0; + return val; +} + +/** + * rvt_qp_complete_swqe - insert send completion + * @qp - the qp + * @wqe - the send wqe + * @opcode - wc operation (driver dependent) + * @status - completion status + * + * Update the s_last information, and then insert a send + * completion into the completion + * queue if the qp indicates it should be done. + * + * See IBTA 10.7.3.1 for info on completion + * control. + * + * Return: new last + */ +static inline u32 +rvt_qp_complete_swqe(struct rvt_qp *qp, + struct rvt_swqe *wqe, + enum ib_wc_opcode opcode, + enum ib_wc_status status) +{ + bool need_completion; + u64 wr_id; + u32 byte_len, last; + int flags = wqe->wr.send_flags; + + rvt_put_qp_swqe(qp, wqe); + + need_completion = + !(flags & RVT_SEND_RESERVE_USED) && + (!(qp->s_flags & RVT_S_SIGNAL_REQ_WR) || + (flags & IB_SEND_SIGNALED) || + status != IB_WC_SUCCESS); + if (need_completion) { + wr_id = wqe->wr.wr_id; + byte_len = wqe->length; + /* above fields required before writing s_last */ + } + last = rvt_qp_swqe_incr(qp, qp->s_last); + /* see rvt_qp_is_avail() */ + smp_store_release(&qp->s_last, last); + if (need_completion) { + struct ib_wc w = { + .wr_id = wr_id, + .status = status, + .opcode = opcode, + .qp = &qp->ibqp, + .byte_len = byte_len, + }; + + rvt_cq_enter(ibcq_to_rvtcq(qp->ibqp.send_cq), &w, + status != IB_WC_SUCCESS); + } + return last; +} + extern const int ib_rvt_state_ops[]; struct rvt_dev_info; -- 2.20.1