Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp3124613pxm; Mon, 28 Feb 2022 12:33:15 -0800 (PST) X-Google-Smtp-Source: ABdhPJyt6pza4kr44Fw9EFWcGrAOEQeY93kPyMJrvXX3P4VmkjvorxQP025kdiUbhbT+21r7PrW5 X-Received: by 2002:a05:6a00:1d0c:b0:4e1:9846:3f34 with SMTP id a12-20020a056a001d0c00b004e198463f34mr23475623pfx.59.1646080395086; Mon, 28 Feb 2022 12:33:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646080395; cv=none; d=google.com; s=arc-20160816; b=BzRzapYeSBkJjhB9HzyL8z7W7DW5gy8YyhRa1ClBQ3q1MuKUV6U/ANefN5PdgE6SHX uci5XJCesvKF8NTJhqZhxqjV016KB9Ldya3PascHiTYJUnRp4tXI7xYdiHcONpeZMx3d xUu+h7HuTsk+KucO1wAN6lshazqsErqvcFIHl/roxuhNg4oS7/s3cq0Q9raDW9uMayq2 29G62WogEhiiteg5F5VhIvIaZrCC2P0iyoUEgzs4xnEJoty3NUT+HZkxNE2L0qH5PGeY TrPlnjj1f8F1GQjH0aTTeRWpc95QQPNJWARJLWS1CM/7MnSuq3S2nkC63eA4h1BU+Ktq +YnA== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=SE97nUCoQgsjM3ZnUKhOWf6INqaQW1rfHmBLrrwwrnE=; b=jDFgns6teN09+GqBCAdRqrtuNp4f5mFO0UCH3fGZsD+CuEI4jjbN+lcIcHHvy6f4ys MtI0HaA9MhsnmujPxIMOzyqCIwrDgSZcSXU02zyK0YnZE8Jylrt5x39XhghlTsLdpdFg G6z9COTfRSt1FMH7HgiS2JscGvUGLHpqXoP9iUe1xv0XoJg7Zk9DuxOfIiSTjzQGwpL5 t7avIEP30CH5gs44vuFXkUOrRDIdaar/0QBoI/JYRuvhMQLyYruEVT+1rv0wazZ/VgwI qifL0Cj063QC+zx0MhouFDcZ5wTKV6CH8LJaY9r2AQgfG2j0U7MR78GeIPs16EVRyPT0 rzYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=HjCUBuqd; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id j16-20020a170903029000b001516e6e465esi2931381plr.502.2022.02.28.12.33.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Feb 2022 12:33:15 -0800 (PST) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=HjCUBuqd; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 3A459E0F2; Mon, 28 Feb 2022 11:52:38 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229714AbiB1TxH (ORCPT + 99 others); Mon, 28 Feb 2022 14:53:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37214 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229705AbiB1Twv (ORCPT ); Mon, 28 Feb 2022 14:52:51 -0500 Received: from mail-ej1-x636.google.com (mail-ej1-x636.google.com [IPv6:2a00:1450:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B6ACACA0E3; Mon, 28 Feb 2022 11:52:11 -0800 (PST) Received: by mail-ej1-x636.google.com with SMTP id hw13so26994431ejc.9; Mon, 28 Feb 2022 11:52:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=SE97nUCoQgsjM3ZnUKhOWf6INqaQW1rfHmBLrrwwrnE=; b=HjCUBuqd57irJYB8osf17Ko1A6qfRwi8TZH4nzCHMeW7yc05d9hfgRtHB3S3gS9wk5 OPtTvBLcwa5UaKspXnCnc5U3ZvqyNnfYnEXY4HSJ1ElNlmZgCb0c3Fjlnfrdvukd5XOU 0Y4PLIqCFYbOeCQzNk/4H7qWoNSQCBfCQJyer41Vlbhf9wV0D33qKuD05mbt6+zOPMRi Db/MFx82xV9Ew622tCmuipMBM0HILAocjBluQeM5WDNc+sh6Nj+pvZKmfRbxIyCfXGFy m5ltLsThnS+AJbSz6PODwSnxuUQ6Vo+snke2ES7nMJjtJaEMPNv1Ce01We0d6JeSaLKt DlFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=SE97nUCoQgsjM3ZnUKhOWf6INqaQW1rfHmBLrrwwrnE=; b=GTziDsGcuMhz8AeENixXFaodIFq3Gr0uGYmYqlcpoPl1EZ2HBz4GJsLoKWWfw0rjOu kpPSEmLplL03TGnjiayUM+cMmHxzVdzHfKA800O1RtgIebZUmjSHbo9vBySs+K1nDOwM tuV+rvRoLJPCkqkzGd2miE0x2YinhpRYjfRmorVq69u6xdfdbdOjZsk7DjbgBwrleCxr //st6/ZhK75thZht2jUtYG7eA6BpYUkIDiJupvNfYSzV+QXMQWX9k26KrMqyEwT12z7g vBvCUYplDOV+qsyZeis29Tcixy+w89EiVsbuxy5sC6mE5A1frNAyL1QAJFOEqNkZYUU/ doHQ== X-Gm-Message-State: AOAM533GBKgGf6XxQ6r4038khGumqVkxyTwmeYonIq8vwWaShLMMTZoM 7E58+RAU5JUyWuMs2UNTgek8EJUKo0MBcw== X-Received: by 2002:a17:906:3e09:b0:6cf:cf2c:2c02 with SMTP id k9-20020a1709063e0900b006cfcf2c2c02mr16768199eji.291.1646077930253; Mon, 28 Feb 2022 11:52:10 -0800 (PST) Received: from nlaptop.localdomain (ptr-dtfv0poj8u7zblqwbt6.18120a2.ip6.access.telenet.be. [2a02:1811:cc83:eef0:f2b6:6987:9238:41ca]) by smtp.gmail.com with ESMTPSA id z11-20020a170906814b00b006a6be1e0f86sm4607513ejw.132.2022.02.28.11.52.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Feb 2022 11:52:09 -0800 (PST) From: Niels Dossche To: linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Dennis Dalessandro , Mike Marciniszyn , Jason Gunthorpe , Niels Dossche Subject: [PATCH] IB/rdmavt: add missing locks in rvt_ruc_loopback Date: Mon, 28 Feb 2022 20:51:44 +0100 Message-Id: <20220228195144.71946-1-dossche.niels@gmail.com> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The documentation of the function rvt_error_qp says both r_lock and s_lock need to be held when calling that function. It also asserts using lockdep that both of those locks are held. rvt_error_qp is called form rvt_send_cq, which is called from rvt_qp_complete_swqe, which is called from rvt_send_complete, which is called from rvt_ruc_loopback in two places. Both of these places do not hold r_lock. Fix this by acquiring a spin_lock of r_lock in both of these places. The r_lock acquiring cannot be added in rvt_qp_complete_swqe because some of its other callers already have r_lock acquired. Signed-off-by: Niels Dossche --- drivers/infiniband/sw/rdmavt/qp.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/infiniband/sw/rdmavt/qp.c b/drivers/infiniband/sw/rdmavt/qp.c index ae50b56e8913..3bac4f90a6d6 100644 --- a/drivers/infiniband/sw/rdmavt/qp.c +++ b/drivers/infiniband/sw/rdmavt/qp.c @@ -2775,7 +2775,7 @@ void rvt_qp_iter(struct rvt_dev_info *rdi, EXPORT_SYMBOL(rvt_qp_iter); /* - * This should be called with s_lock held. + * This should be called with s_lock and r_lock held. */ void rvt_send_complete(struct rvt_qp *qp, struct rvt_swqe *wqe, enum ib_wc_status status) @@ -3134,7 +3134,9 @@ void rvt_ruc_loopback(struct rvt_qp *sqp) rvp->n_loop_pkts++; flush_send: sqp->s_rnr_retry = sqp->s_rnr_retry_cnt; + spin_lock(&sqp->r_lock); rvt_send_complete(sqp, wqe, send_status); + spin_unlock(&sqp->r_lock); if (local_ops) { atomic_dec(&sqp->local_ops_pending); local_ops = 0; @@ -3188,7 +3190,9 @@ void rvt_ruc_loopback(struct rvt_qp *sqp) spin_unlock_irqrestore(&qp->r_lock, flags); serr_no_r_lock: spin_lock_irqsave(&sqp->s_lock, flags); + spin_lock(&sqp->r_lock); rvt_send_complete(sqp, wqe, send_status); + spin_unlock(&sqp->r_lock); if (sqp->ibqp.qp_type == IB_QPT_RC) { int lastwqe = rvt_error_qp(sqp, IB_WC_WR_FLUSH_ERR); -- 2.35.1