From patchwork Sat Mar 4 17:45:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bob Pearson X-Patchwork-Id: 13159979 X-Patchwork-Delegate: jgg@ziepe.ca Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 706D4C678D5 for ; Sat, 4 Mar 2023 17:46:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229701AbjCDRqq (ORCPT ); Sat, 4 Mar 2023 12:46:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52064 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229698AbjCDRqp (ORCPT ); Sat, 4 Mar 2023 12:46:45 -0500 Received: from mail-ot1-x32a.google.com (mail-ot1-x32a.google.com [IPv6:2607:f8b0:4864:20::32a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B62FA1B31D for ; Sat, 4 Mar 2023 09:46:44 -0800 (PST) Received: by mail-ot1-x32a.google.com with SMTP id e9-20020a056830200900b00694651d19f6so299135otp.12 for ; Sat, 04 Mar 2023 09:46:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1677952004; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=k9BoHEwgKUbosGePv1yHqss3X8jvJed/Fb/ZUDuPZtQ=; b=UXZPVCHU0sc1MsiO8elucDqyCGeAp/eAFWkDIhJb2jDJ2mGVDS35BkHMqnTsDV4Vm3 GVrgWTThBDCB9tn9gC26y0bWztqF77rwOGgrEzPPtCZDpNVtMamEFt1Smb+yP/fPs7FH SpOLsqSZll+Nq8M3QY68afWPGl82xJ/mRnwX5w4YzJ2aaeUFmSZ2XB94ZIvMdVuYM8Mt lztr1aZcxZ19dCq3iW7MmXtF788aetmOHASYll+9SsS4jXzth7lynWopWnmsd5d8iIH5 GRUYM31/4Uj+wufhEL0o+N3PbUk5P30ExxGjJ4/9XPNXj2c8lomvDZXkWbnKMJrV1swk MLUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677952004; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=k9BoHEwgKUbosGePv1yHqss3X8jvJed/Fb/ZUDuPZtQ=; b=fuVyNKcCt9BlnLtCkZRH+iNzx5Rc0+NeQRNna2UNxU8DQGP86JJRhs9ZDOZwEjf5dC q4EpI0iMon9jOcQ1NqsCoxeVXRLEm0GPNpxDZkmpOUZdIF2fm48yqiog5C0d0lCnX9yU GTupoGnDliwCnz9mrkteIzuYz2Byk+yWffaC23T7sF+NVS/1WtUGEP9Fv2oH8sCoAO3d ZX6BaqlHc+TVIaW8sv9G3Lqtk/2BrNLdRKZWdJM1xenoubJPqetOHmUuLNgt5UkzbzgK trds/SFDzr/JFp96hNGQV+6pcIqhcGAlxpaF1K2Sy7rhxpCf/7IhmWWnj/wR6PJmjtD7 6rWQ== X-Gm-Message-State: AO0yUKWDoczhrmERVHlf8WWtD2erRjjmEHQvsistsMSu56ZHMnL1hzXP HAqOouqB0QhTkrvSemX73AI= X-Google-Smtp-Source: AK7set9cBjIlX7q/qYKZcRdaeC9/WYRWSjUzzNwbimjS3loroQr7JJe2dGot9UFnTajb7+AjXK8Ilw== X-Received: by 2002:a9d:861:0:b0:690:958e:f0e9 with SMTP id 88-20020a9d0861000000b00690958ef0e9mr2579534oty.1.1677952004091; Sat, 04 Mar 2023 09:46:44 -0800 (PST) Received: from rpearson-X570-AORUS-PRO-WIFI.tx.rr.com (2603-8081-140c-1a00-f848-0c36-f4e0-0517.res6.spectrum.com. [2603:8081:140c:1a00:f848:c36:f4e0:517]) by smtp.gmail.com with ESMTPSA id a1-20020a056830008100b0068bcadcad5bsm2311227oto.57.2023.03.04.09.46.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 Mar 2023 09:46:43 -0800 (PST) From: Bob Pearson To: jgg@nvidia.com, zyjzyj2000@gmail.com, jhack@hpe.com, matsuda-daisuke@fujitsu.com, linux-rdma@vger.kernel.org Cc: Bob Pearson Subject: [PATCH for-next v3 1/8] RDMA/rxe: Convert tasklet args to queue pairs Date: Sat, 4 Mar 2023 11:45:27 -0600 Message-Id: <20230304174533.11296-2-rpearsonhpe@gmail.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230304174533.11296-1-rpearsonhpe@gmail.com> References: <20230304174533.11296-1-rpearsonhpe@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org Originally is was thought that the tasklet machinery in rxe_task.c would be used in other applications but that has not happened for years. This patch replaces the 'void *arg' by struct 'rxe_qp *qp' in the parameters to the tasklet calls. This change will have no affect on performance but may make the code a little clearer. Signed-off-by: Bob Pearson --- drivers/infiniband/sw/rxe/rxe_comp.c | 3 +-- drivers/infiniband/sw/rxe/rxe_loc.h | 6 +++--- drivers/infiniband/sw/rxe/rxe_req.c | 3 +-- drivers/infiniband/sw/rxe/rxe_resp.c | 3 +-- drivers/infiniband/sw/rxe/rxe_task.c | 11 ++++++----- drivers/infiniband/sw/rxe/rxe_task.h | 9 +++++---- 6 files changed, 17 insertions(+), 18 deletions(-) diff --git a/drivers/infiniband/sw/rxe/rxe_comp.c b/drivers/infiniband/sw/rxe/rxe_comp.c index 876057e3ee3c..cbfa16b3a490 100644 --- a/drivers/infiniband/sw/rxe/rxe_comp.c +++ b/drivers/infiniband/sw/rxe/rxe_comp.c @@ -575,9 +575,8 @@ static void free_pkt(struct rxe_pkt_info *pkt) ib_device_put(dev); } -int rxe_completer(void *arg) +int rxe_completer(struct rxe_qp *qp) { - struct rxe_qp *qp = (struct rxe_qp *)arg; struct rxe_dev *rxe = to_rdev(qp->ibqp.device); struct rxe_send_wqe *wqe = NULL; struct sk_buff *skb = NULL; diff --git a/drivers/infiniband/sw/rxe/rxe_loc.h b/drivers/infiniband/sw/rxe/rxe_loc.h index 839de34cf4c9..804b15e929dd 100644 --- a/drivers/infiniband/sw/rxe/rxe_loc.h +++ b/drivers/infiniband/sw/rxe/rxe_loc.h @@ -170,9 +170,9 @@ void rxe_srq_cleanup(struct rxe_pool_elem *elem); void rxe_dealloc(struct ib_device *ib_dev); -int rxe_completer(void *arg); -int rxe_requester(void *arg); -int rxe_responder(void *arg); +int rxe_completer(struct rxe_qp *qp); +int rxe_requester(struct rxe_qp *qp); +int rxe_responder(struct rxe_qp *qp); /* rxe_icrc.c */ int rxe_icrc_init(struct rxe_dev *rxe); diff --git a/drivers/infiniband/sw/rxe/rxe_req.c b/drivers/infiniband/sw/rxe/rxe_req.c index 899c8779f800..f2dc2d191e16 100644 --- a/drivers/infiniband/sw/rxe/rxe_req.c +++ b/drivers/infiniband/sw/rxe/rxe_req.c @@ -635,9 +635,8 @@ static int rxe_do_local_ops(struct rxe_qp *qp, struct rxe_send_wqe *wqe) return 0; } -int rxe_requester(void *arg) +int rxe_requester(struct rxe_qp *qp) { - struct rxe_qp *qp = (struct rxe_qp *)arg; struct rxe_dev *rxe = to_rdev(qp->ibqp.device); struct rxe_pkt_info pkt; struct sk_buff *skb; diff --git a/drivers/infiniband/sw/rxe/rxe_resp.c b/drivers/infiniband/sw/rxe/rxe_resp.c index 4217eec03a94..7cb1b962d665 100644 --- a/drivers/infiniband/sw/rxe/rxe_resp.c +++ b/drivers/infiniband/sw/rxe/rxe_resp.c @@ -1443,9 +1443,8 @@ static void rxe_drain_req_pkts(struct rxe_qp *qp, bool notify) queue_advance_consumer(q, q->type); } -int rxe_responder(void *arg) +int rxe_responder(struct rxe_qp *qp) { - struct rxe_qp *qp = (struct rxe_qp *)arg; struct rxe_dev *rxe = to_rdev(qp->ibqp.device); enum resp_states state; struct rxe_pkt_info *pkt = NULL; diff --git a/drivers/infiniband/sw/rxe/rxe_task.c b/drivers/infiniband/sw/rxe/rxe_task.c index 60b90e33a884..959cc6229a34 100644 --- a/drivers/infiniband/sw/rxe/rxe_task.c +++ b/drivers/infiniband/sw/rxe/rxe_task.c @@ -11,7 +11,7 @@ int __rxe_do_task(struct rxe_task *task) { int ret; - while ((ret = task->func(task->arg)) == 0) + while ((ret = task->func(task->qp)) == 0) ; task->ret = ret; @@ -29,7 +29,7 @@ static void do_task(struct tasklet_struct *t) int cont; int ret; struct rxe_task *task = from_tasklet(task, t, tasklet); - struct rxe_qp *qp = (struct rxe_qp *)task->arg; + struct rxe_qp *qp = (struct rxe_qp *)task->qp; unsigned int iterations = RXE_MAX_ITERATIONS; spin_lock_bh(&task->lock); @@ -54,7 +54,7 @@ static void do_task(struct tasklet_struct *t) do { cont = 0; - ret = task->func(task->arg); + ret = task->func(task->qp); spin_lock_bh(&task->lock); switch (task->state) { @@ -91,9 +91,10 @@ static void do_task(struct tasklet_struct *t) task->ret = ret; } -int rxe_init_task(struct rxe_task *task, void *arg, int (*func)(void *)) +int rxe_init_task(struct rxe_task *task, struct rxe_qp *qp, + int (*func)(struct rxe_qp *)) { - task->arg = arg; + task->qp = qp; task->func = func; task->destroyed = false; diff --git a/drivers/infiniband/sw/rxe/rxe_task.h b/drivers/infiniband/sw/rxe/rxe_task.h index 7b88129702ac..41efd5fd49b0 100644 --- a/drivers/infiniband/sw/rxe/rxe_task.h +++ b/drivers/infiniband/sw/rxe/rxe_task.h @@ -22,18 +22,19 @@ struct rxe_task { struct tasklet_struct tasklet; int state; spinlock_t lock; - void *arg; - int (*func)(void *arg); + struct rxe_qp *qp; + int (*func)(struct rxe_qp *qp); int ret; bool destroyed; }; /* * init rxe_task structure - * arg => parameter to pass to fcn + * qp => parameter to pass to func * func => function to call until it returns != 0 */ -int rxe_init_task(struct rxe_task *task, void *arg, int (*func)(void *)); +int rxe_init_task(struct rxe_task *task, struct rxe_qp *qp, + int (*func)(struct rxe_qp *)); /* cleanup task */ void rxe_cleanup_task(struct rxe_task *task); From patchwork Sat Mar 4 17:45:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bob Pearson X-Patchwork-Id: 13159980 X-Patchwork-Delegate: jgg@ziepe.ca Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2DBF2C678DB for ; Sat, 4 Mar 2023 17:46:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229698AbjCDRqr (ORCPT ); Sat, 4 Mar 2023 12:46:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52070 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229625AbjCDRqq (ORCPT ); Sat, 4 Mar 2023 12:46:46 -0500 Received: from mail-ot1-x32e.google.com (mail-ot1-x32e.google.com [IPv6:2607:f8b0:4864:20::32e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A68101B337 for ; Sat, 4 Mar 2023 09:46:45 -0800 (PST) Received: by mail-ot1-x32e.google.com with SMTP id o4-20020a9d6d04000000b00694127788f4so3185628otp.6 for ; Sat, 04 Mar 2023 09:46:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1677952005; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=2t+RYCR+GPDypYJCw/mzDu3u7+tUDxfIXpU6DUOVASg=; b=qoF52apaze6NQBt4j6FqyFN44B6CS5pRdBWQUQ6bM0/5ybXGCTWLClVqfs3e6Z5Z3w lpBvloC99nrumGEX2gar8cSt0cqKH3A4R+2IIL3+oRzR533MwQesc1yHs2khElWS6q4E rZ44wV5S7MtEG+YPiIb3qP/Ofhupk5sO/jwVyURE525ZqZso2flOpEU8XLEsmBlZofiS yZKm2QzxA8g3R6ObZdVhXhdrUOs+HxuZReDWSspTZeS7MxQrA7RltlSg+TaizHXNmqZy IRGqyY8ElUL5Ox+tKOCfKtUb8VBkTtP/+D5ys5iYq6Qy9WiERSFozS+emcoYNn0d7hJ1 rX7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677952005; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=2t+RYCR+GPDypYJCw/mzDu3u7+tUDxfIXpU6DUOVASg=; b=3w86GnHaGLUT9wAAFCBVFwr2l6IiCEcX9as1TBcAwzLi0+YpE1sK9k8tmieIgTEAa4 hK8+hNrhiWxLepCQxc8DjGnQJIBR2ul5/wh6gzDPf5ZBno9ootzVR9pjxTrBziD/I/ZT JGj2GKy35hB3X7LuDYOk+DFiPM1Mf3r0w2HKm+SDDFYngfsGpOD9/yt6498/2e/FJzyO qHHutAnYh6/Q9E72A/BJghT9OLg1AAlnsLtey2hdd3QVbLJffolfo7fPHg9mQOiJhSQv TY7b9EA1/lJFmG12s8C8h6Tg5ymzlgUXS/qnRQRh5Z0Q8j8G8t0aiE41hZQ/iOdAlvLo 6Pjw== X-Gm-Message-State: AO0yUKWCbegn7TPl8DJM9EQnR9SF/IC0nqZYN0UqsdphwFlXA8CNwqdX JrXCUmNvLjssXdVIS9x0A/M= X-Google-Smtp-Source: AK7set+dp47XvDTpj9DPNl2rlXANWhTvgyKCMY+vcB2S4e32HNpmovHh2Lv/DyVkyUdL61FTyN+8pA== X-Received: by 2002:a9d:7307:0:b0:693:bdd8:819f with SMTP id e7-20020a9d7307000000b00693bdd8819fmr4828216otk.1.1677952005062; Sat, 04 Mar 2023 09:46:45 -0800 (PST) Received: from rpearson-X570-AORUS-PRO-WIFI.tx.rr.com (2603-8081-140c-1a00-f848-0c36-f4e0-0517.res6.spectrum.com. [2603:8081:140c:1a00:f848:c36:f4e0:517]) by smtp.gmail.com with ESMTPSA id a1-20020a056830008100b0068bcadcad5bsm2311227oto.57.2023.03.04.09.46.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 Mar 2023 09:46:44 -0800 (PST) From: Bob Pearson To: jgg@nvidia.com, zyjzyj2000@gmail.com, jhack@hpe.com, matsuda-daisuke@fujitsu.com, linux-rdma@vger.kernel.org Cc: Bob Pearson Subject: [PATCH for-next v3 2/8] RDMA/rxe: Warn if refcnt zero in rxe_put Date: Sat, 4 Mar 2023 11:45:28 -0600 Message-Id: <20230304174533.11296-3-rpearsonhpe@gmail.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230304174533.11296-1-rpearsonhpe@gmail.com> References: <20230304174533.11296-1-rpearsonhpe@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org This patch adds a WARN_ON if the reference count of the object passed to __rxe_put() is <= 0. This can only happen if there is a bug in the rxe driver but has bad consequences if there is. Signed-off-by: Bob Pearson --- drivers/infiniband/sw/rxe/rxe_pool.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/infiniband/sw/rxe/rxe_pool.c b/drivers/infiniband/sw/rxe/rxe_pool.c index 3f6bd672cc2d..1b160e36b751 100644 --- a/drivers/infiniband/sw/rxe/rxe_pool.c +++ b/drivers/infiniband/sw/rxe/rxe_pool.c @@ -244,6 +244,8 @@ int __rxe_get(struct rxe_pool_elem *elem) int __rxe_put(struct rxe_pool_elem *elem) { + if (WARN_ON(kref_read(&elem->ref_cnt) <= 0)) + return 0; return kref_put(&elem->ref_cnt, rxe_elem_release); } From patchwork Sat Mar 4 17:45:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bob Pearson X-Patchwork-Id: 13159981 X-Patchwork-Delegate: jgg@ziepe.ca Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D7DBEC64EC4 for ; Sat, 4 Mar 2023 17:46:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229709AbjCDRqs (ORCPT ); Sat, 4 Mar 2023 12:46:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52088 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229625AbjCDRqs (ORCPT ); Sat, 4 Mar 2023 12:46:48 -0500 Received: from mail-oa1-x33.google.com (mail-oa1-x33.google.com [IPv6:2001:4860:4864:20::33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B33AB1B337 for ; Sat, 4 Mar 2023 09:46:46 -0800 (PST) Received: by mail-oa1-x33.google.com with SMTP id 586e51a60fabf-176261d7f45so6741834fac.11 for ; Sat, 04 Mar 2023 09:46:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1677952006; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=gy4MUf6ImzMyVsqFV+19sqrqNEbtSZnRPY2EyyDlDOE=; b=HbhmKGZzLxP34K4IV2XySW6vDLlH4pqHD067FIT7OPj9BPjZODvsgFaXm8MN/SCRA0 ZoZMg1eUHCz23VoWIGJXWJRWw0yc1MWGqEuvZcss5i6bBRJmR+211ziu3YKZg7ZXaq6C JNIZyPF1Lg0A91zb/8sQjqN5YCBrhjI9FbKJzrE59RHifuRbZyCV8d/gfJa1Zy6s2k98 e0Eyu43xuvgivPup1QGyfOeNtkJhqBbIO4Yb08HTgtrbpgegxYi9N4HwnDQSZ9mY+2GY g2ZsM9+vbBQTrxeUBxbAdEVhEaDI2FpWZuVprnhWIdzqdNWeR1v0SqhN3bNZG6wfoL3s +IpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677952006; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=gy4MUf6ImzMyVsqFV+19sqrqNEbtSZnRPY2EyyDlDOE=; b=4Vvl2wqE2hnvnLuLcwKTCEYCviYH2CAIfWvz3q02m5D8T/Edknvz/Yn82HSwSqcUH4 yfiGrDSILeklLOlKDby9DJG6hXfXSxsfsP4YVMsBA5X0PDGcoPR5xtkb47MstEIWb0qq ylAG9OgNHdPayQR81opbO3zBDG+0teNC4f6ASmXssPRR1IWFmHvJsitPWVsHYDxV4MVW RO15qgF9bWtrquQAWxQkwyjuax4gm4ag6qY6WNYrSqEfGZobPopkXrXuRSX11paRee8N uQGTu6n7nrz/IjtvxN13dlomaCoUbwTC4JOhsQJLJfpJnRT4GVelloPqyfGqMRbUFMsf rQew== X-Gm-Message-State: AO0yUKXrO5j/vuwEekm1zCkAXg0cm4MHxMJzEQqRKcseM9mtVwPTS2TH q04eJ8RFbDG7mwT+c6j1q18= X-Google-Smtp-Source: AK7set/PTUiO1ySDLDmwgegNFPigxrtXvBsrS0sadluOev0bVokM4Rna3Hzhi2txLV6m8ajE75J7dg== X-Received: by 2002:a05:6870:d1c5:b0:176:46ba:2744 with SMTP id b5-20020a056870d1c500b0017646ba2744mr3968303oac.19.1677952006003; Sat, 04 Mar 2023 09:46:46 -0800 (PST) Received: from rpearson-X570-AORUS-PRO-WIFI.tx.rr.com (2603-8081-140c-1a00-f848-0c36-f4e0-0517.res6.spectrum.com. [2603:8081:140c:1a00:f848:c36:f4e0:517]) by smtp.gmail.com with ESMTPSA id a1-20020a056830008100b0068bcadcad5bsm2311227oto.57.2023.03.04.09.46.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 Mar 2023 09:46:45 -0800 (PST) From: Bob Pearson To: jgg@nvidia.com, zyjzyj2000@gmail.com, jhack@hpe.com, matsuda-daisuke@fujitsu.com, linux-rdma@vger.kernel.org Cc: Bob Pearson , Ian Ziemba Subject: [PATCH for-next v3 3/8] RDMA/rxe: Cleanup reset state handling in rxe_resp.c Date: Sat, 4 Mar 2023 11:45:29 -0600 Message-Id: <20230304174533.11296-4-rpearsonhpe@gmail.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230304174533.11296-1-rpearsonhpe@gmail.com> References: <20230304174533.11296-1-rpearsonhpe@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org Cleanup the handling of qp in the error state, reset state and during rxe_qp_do_cleanup. The error state does about the same thing as the others but has code spread all over. This patch combines them in a cleaner way. Signed-off-by: Ian Ziemba Signed-off-by: Bob Pearson --- drivers/infiniband/sw/rxe/rxe.h | 1 - drivers/infiniband/sw/rxe/rxe_resp.c | 107 ++++++++++++++------------- 2 files changed, 57 insertions(+), 51 deletions(-) diff --git a/drivers/infiniband/sw/rxe/rxe.h b/drivers/infiniband/sw/rxe/rxe.h index bd8a8ea4ea8f..d33dd6cf83d3 100644 --- a/drivers/infiniband/sw/rxe/rxe.h +++ b/drivers/infiniband/sw/rxe/rxe.h @@ -133,7 +133,6 @@ enum resp_states { RESPST_ERR_LENGTH, RESPST_ERR_CQ_OVERFLOW, RESPST_ERROR, - RESPST_RESET, RESPST_DONE, RESPST_EXIT, }; diff --git a/drivers/infiniband/sw/rxe/rxe_resp.c b/drivers/infiniband/sw/rxe/rxe_resp.c index 7cb1b962d665..8f9bbb14fa7a 100644 --- a/drivers/infiniband/sw/rxe/rxe_resp.c +++ b/drivers/infiniband/sw/rxe/rxe_resp.c @@ -42,7 +42,6 @@ static char *resp_state_name[] = { [RESPST_ERR_LENGTH] = "ERR_LENGTH", [RESPST_ERR_CQ_OVERFLOW] = "ERR_CQ_OVERFLOW", [RESPST_ERROR] = "ERROR", - [RESPST_RESET] = "RESET", [RESPST_DONE] = "DONE", [RESPST_EXIT] = "EXIT", }; @@ -69,17 +68,6 @@ static inline enum resp_states get_req(struct rxe_qp *qp, { struct sk_buff *skb; - if (qp->resp.state == QP_STATE_ERROR) { - while ((skb = skb_dequeue(&qp->req_pkts))) { - rxe_put(qp); - kfree_skb(skb); - ib_device_put(qp->ibqp.device); - } - - /* go drain recv wr queue */ - return RESPST_CHK_RESOURCE; - } - skb = skb_peek(&qp->req_pkts); if (!skb) return RESPST_EXIT; @@ -334,24 +322,6 @@ static enum resp_states check_resource(struct rxe_qp *qp, { struct rxe_srq *srq = qp->srq; - if (qp->resp.state == QP_STATE_ERROR) { - if (qp->resp.wqe) { - qp->resp.status = IB_WC_WR_FLUSH_ERR; - return RESPST_COMPLETE; - } else if (!srq) { - qp->resp.wqe = queue_head(qp->rq.queue, - QUEUE_TYPE_FROM_CLIENT); - if (qp->resp.wqe) { - qp->resp.status = IB_WC_WR_FLUSH_ERR; - return RESPST_COMPLETE; - } else { - return RESPST_EXIT; - } - } else { - return RESPST_EXIT; - } - } - if (pkt->mask & (RXE_READ_OR_ATOMIC_MASK | RXE_ATOMIC_WRITE_MASK)) { /* it is the requesters job to not send * too many read/atomic ops, we just @@ -1425,22 +1395,66 @@ static enum resp_states do_class_d1e_error(struct rxe_qp *qp) } } -static void rxe_drain_req_pkts(struct rxe_qp *qp, bool notify) +/* drain incoming request packet queue */ +static void rxe_drain_req_pkts(struct rxe_qp *qp) { struct sk_buff *skb; - struct rxe_queue *q = qp->rq.queue; while ((skb = skb_dequeue(&qp->req_pkts))) { rxe_put(qp); kfree_skb(skb); ib_device_put(qp->ibqp.device); } +} + +/* complete receive wqe with flush error */ +static int complete_flush(struct rxe_qp *qp, struct rxe_recv_wqe *wqe) +{ + struct rxe_cqe cqe = {}; + struct ib_wc *wc = &cqe.ibwc; + struct ib_uverbs_wc *uwc = &cqe.uibwc; + + if (qp->rcq->is_user) { + uwc->status = IB_WC_WR_FLUSH_ERR; + uwc->qp_num = qp_num(qp); + uwc->wr_id = wqe->wr_id; + } else { + wc->status = IB_WC_WR_FLUSH_ERR; + wc->qp = &qp->ibqp; + wc->wr_id = wqe->wr_id; + } + + if (rxe_cq_post(qp->rcq, &cqe, 0)) + return -ENOMEM; + + return 0; +} + +/* drain and optionally complete the recive queue + * if unable to complete a wqe stop completing and + * just flush the remaining wqes + */ +static void rxe_drain_recv_queue(struct rxe_qp *qp, bool notify) +{ + struct rxe_queue *q = qp->rq.queue; + struct rxe_recv_wqe *wqe; + int err; - if (notify) + if (qp->srq) return; - while (!qp->srq && q && queue_head(q, q->type)) + while ((wqe = queue_head(q, q->type))) { + if (notify) { + err = complete_flush(qp, wqe); + if (err) { + rxe_dbg_qp(qp, "complete failed for recv wqe"); + notify = 0; + } + } queue_advance_consumer(q, q->type); + } + + qp->resp.wqe = NULL; } int rxe_responder(struct rxe_qp *qp) @@ -1453,20 +1467,18 @@ int rxe_responder(struct rxe_qp *qp) if (!rxe_get(qp)) return -EAGAIN; - qp->resp.aeth_syndrome = AETH_ACK_UNLIMITED; - - if (!qp->valid) + if (!qp->valid || qp->resp.state == QP_STATE_ERROR || + qp->resp.state == QP_STATE_RESET) { + bool notify = qp->valid && + (qp->resp.state == QP_STATE_ERROR); + rxe_drain_req_pkts(qp); + rxe_drain_recv_queue(qp, notify); goto exit; + } - switch (qp->resp.state) { - case QP_STATE_RESET: - state = RESPST_RESET; - break; + qp->resp.aeth_syndrome = AETH_ACK_UNLIMITED; - default: - state = RESPST_GET_REQ; - break; - } + state = RESPST_GET_REQ; while (1) { rxe_dbg_qp(qp, "state = %s\n", resp_state_name[state]); @@ -1625,11 +1637,6 @@ int rxe_responder(struct rxe_qp *qp) goto exit; - case RESPST_RESET: - rxe_drain_req_pkts(qp, false); - qp->resp.wqe = NULL; - goto exit; - case RESPST_ERROR: qp->resp.goto_error = 0; rxe_dbg_qp(qp, "moved to error state\n"); From patchwork Sat Mar 4 17:45:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bob Pearson X-Patchwork-Id: 13159982 X-Patchwork-Delegate: jgg@ziepe.ca Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A8070C678D5 for ; Sat, 4 Mar 2023 17:46:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229712AbjCDRqt (ORCPT ); Sat, 4 Mar 2023 12:46:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52106 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229707AbjCDRqs (ORCPT ); Sat, 4 Mar 2023 12:46:48 -0500 Received: from mail-oi1-x22d.google.com (mail-oi1-x22d.google.com [IPv6:2607:f8b0:4864:20::22d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9A1C51B551 for ; Sat, 4 Mar 2023 09:46:47 -0800 (PST) Received: by mail-oi1-x22d.google.com with SMTP id bm20so4175949oib.7 for ; Sat, 04 Mar 2023 09:46:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1677952007; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=f/Za0rNoBjmoBQCKcEt9mr20V3Sb0ypL/7khrurHRBE=; b=JJ1aLUihRHAmYtJl7F/DzXp2+xlmmZHHRwtuSeckxerwiKIZWgSmKmlZgnLLOAFE7K WyD/+cSFHyduNPlRUkTM9MlhuFlLRrxIt4usKi8C9NboV2YKHcBrmYgCDi7LH2LxXfj8 ebNYLAuW2+o5DEXT9msy2c9ufV/BNxHxJA2JwDe/LecRGaEsgJ9/Jop44OELUh+HTJU8 UlgD2EDvoRGJr3EYWan7H7Tj8XVQhk105ySdFfckq48xDGwK2J4hx9/OF7XdHfJ2Er7e DDJ9fAjWVnJIdTYr0wDOAdMdWbWTCTt+oAvdtQgtzXoDwwcGyUUQz1KSsjm7YJOBlOPc z/WA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677952007; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=f/Za0rNoBjmoBQCKcEt9mr20V3Sb0ypL/7khrurHRBE=; b=JJeEkGXeELzoyFvCr0yaNnYHIO3YrihWLyCKdd4liNcJ5g7ptixvq3LA4Sj0ZjGMjN dXRTO8typpAxwQ8s+CVvxxplrbLWVaT8P6xa4yljDRNPIjRTMnqxTNSeby8lakic+Zvq kpQ1KT6GCh1nfMh0hsXQqnw4b0M5XDSgWPTMOI+f2yzDnZ/D9H6QjoOGMezY/2g5bZhE TcMxlTjBnaad08FGr7qh0hYqDhWGBOJlC7naR5cP355k9upwk5iCiIarb9ebosnGBhnO R4sFUsNvLUXz6tskPHyIueG3mGDW11d8lale9FYeAZDm9IGDz13riabuqAKiuIL+HP7K TRSQ== X-Gm-Message-State: AO0yUKXcJ/KOIbzH7mgivLsK+u8BVvO7NUmVVAY4GLE6385OONLb2OD3 JNTUvCYYLh0lnbM7KE3814Gn91jnhmk= X-Google-Smtp-Source: AK7set+LiWicwCrV7DwAMFEDxxVaYEE7+YGSpWGbZgsqTIRrTlAHeKSr1TocDKiPqx738lCrKq1ZzA== X-Received: by 2002:a05:6808:60e:b0:384:3774:603a with SMTP id y14-20020a056808060e00b003843774603amr2300983oih.14.1677952006960; Sat, 04 Mar 2023 09:46:46 -0800 (PST) Received: from rpearson-X570-AORUS-PRO-WIFI.tx.rr.com (2603-8081-140c-1a00-f848-0c36-f4e0-0517.res6.spectrum.com. [2603:8081:140c:1a00:f848:c36:f4e0:517]) by smtp.gmail.com with ESMTPSA id a1-20020a056830008100b0068bcadcad5bsm2311227oto.57.2023.03.04.09.46.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 Mar 2023 09:46:46 -0800 (PST) From: Bob Pearson To: jgg@nvidia.com, zyjzyj2000@gmail.com, jhack@hpe.com, matsuda-daisuke@fujitsu.com, linux-rdma@vger.kernel.org Cc: Bob Pearson , Ian Ziemba Subject: [PATCH for-next v3 4/8] RDMA/rxe: Cleanup error state handling in rxe_comp.c Date: Sat, 4 Mar 2023 11:45:30 -0600 Message-Id: <20230304174533.11296-5-rpearsonhpe@gmail.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230304174533.11296-1-rpearsonhpe@gmail.com> References: <20230304174533.11296-1-rpearsonhpe@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org Cleanup the handling of qp in the error state, reset state and during rxe_qp_do_cleanup. Make the same as rxe_resp.c Signed-off-by: Ian Ziemba Signed-off-by: Bob Pearson --- v3: Didn't set wqe.status to IB_WC_WR_FLUSH_ERR when flushing send queue. This broke blktests which calls modify qp to set qp to IB_QPS_ERR and waits for the flushed cqe's. drivers/infiniband/sw/rxe/rxe_comp.c | 55 +++++++++++++++++++++++----- drivers/infiniband/sw/rxe/rxe_cq.c | 1 + drivers/infiniband/sw/rxe/rxe_resp.c | 28 +++++++------- 3 files changed, 61 insertions(+), 23 deletions(-) diff --git a/drivers/infiniband/sw/rxe/rxe_comp.c b/drivers/infiniband/sw/rxe/rxe_comp.c index cbfa16b3a490..f7ab0dfe1034 100644 --- a/drivers/infiniband/sw/rxe/rxe_comp.c +++ b/drivers/infiniband/sw/rxe/rxe_comp.c @@ -542,25 +542,60 @@ static inline enum comp_state complete_wqe(struct rxe_qp *qp, return COMPST_GET_WQE; } -static void rxe_drain_resp_pkts(struct rxe_qp *qp, bool notify) +/* drain incoming response packet queue */ +static void drain_resp_pkts(struct rxe_qp *qp) { struct sk_buff *skb; - struct rxe_send_wqe *wqe; - struct rxe_queue *q = qp->sq.queue; while ((skb = skb_dequeue(&qp->resp_pkts))) { rxe_put(qp); kfree_skb(skb); ib_device_put(qp->ibqp.device); } +} + +/* complete send wqe with flush error */ +static int flush_send_wqe(struct rxe_qp *qp, struct rxe_send_wqe *wqe) +{ + struct rxe_cqe cqe = {}; + struct ib_wc *wc = &cqe.ibwc; + struct ib_uverbs_wc *uwc = &cqe.uibwc; + int err; + + if (qp->is_user) { + uwc->wr_id = wqe->wr.wr_id; + uwc->status = IB_WC_WR_FLUSH_ERR; + uwc->qp_num = qp->ibqp.qp_num; + } else { + wc->wr_id = wqe->wr.wr_id; + wc->status = IB_WC_WR_FLUSH_ERR; + wc->qp = &qp->ibqp; + } + + err = rxe_cq_post(qp->scq, &cqe, 0); + if (err) + rxe_dbg_cq(qp->scq, "post cq failed, err = %d", err); + + return err; +} + +/* drain and optionally complete the send queue + * if unable to complete a wqe, i.e. cq is full, stop + * completing and flush the remaining wqes + */ +static void flush_send_queue(struct rxe_qp *qp, bool notify) +{ + struct rxe_send_wqe *wqe; + struct rxe_queue *q = qp->sq.queue; + int err; while ((wqe = queue_head(q, q->type))) { if (notify) { - wqe->status = IB_WC_WR_FLUSH_ERR; - do_complete(qp, wqe); - } else { - queue_advance_consumer(q, q->type); + err = flush_send_wqe(qp, wqe); + if (err) + notify = 0; } + queue_advance_consumer(q, q->type); } } @@ -589,8 +624,10 @@ int rxe_completer(struct rxe_qp *qp) if (!qp->valid || qp->comp.state == QP_STATE_ERROR || qp->comp.state == QP_STATE_RESET) { - rxe_drain_resp_pkts(qp, qp->valid && - qp->comp.state == QP_STATE_ERROR); + bool notify = qp->valid && + (qp->comp.state == QP_STATE_ERROR); + drain_resp_pkts(qp); + flush_send_queue(qp, notify); goto exit; } diff --git a/drivers/infiniband/sw/rxe/rxe_cq.c b/drivers/infiniband/sw/rxe/rxe_cq.c index 22fbc198e5d1..66a13c935d50 100644 --- a/drivers/infiniband/sw/rxe/rxe_cq.c +++ b/drivers/infiniband/sw/rxe/rxe_cq.c @@ -114,6 +114,7 @@ int rxe_cq_post(struct rxe_cq *cq, struct rxe_cqe *cqe, int solicited) full = queue_full(cq->queue, QUEUE_TYPE_TO_CLIENT); if (unlikely(full)) { + rxe_err_cq(cq, "queue full"); spin_unlock_irqrestore(&cq->cq_lock, flags); if (cq->ibcq.event_handler) { ev.device = cq->ibcq.device; diff --git a/drivers/infiniband/sw/rxe/rxe_resp.c b/drivers/infiniband/sw/rxe/rxe_resp.c index 8f9bbb14fa7a..2f71183449f9 100644 --- a/drivers/infiniband/sw/rxe/rxe_resp.c +++ b/drivers/infiniband/sw/rxe/rxe_resp.c @@ -1396,7 +1396,7 @@ static enum resp_states do_class_d1e_error(struct rxe_qp *qp) } /* drain incoming request packet queue */ -static void rxe_drain_req_pkts(struct rxe_qp *qp) +static void drain_req_pkts(struct rxe_qp *qp) { struct sk_buff *skb; @@ -1408,33 +1408,35 @@ static void rxe_drain_req_pkts(struct rxe_qp *qp) } /* complete receive wqe with flush error */ -static int complete_flush(struct rxe_qp *qp, struct rxe_recv_wqe *wqe) +static int flush_recv_wqe(struct rxe_qp *qp, struct rxe_recv_wqe *wqe) { struct rxe_cqe cqe = {}; struct ib_wc *wc = &cqe.ibwc; struct ib_uverbs_wc *uwc = &cqe.uibwc; + int err; if (qp->rcq->is_user) { + uwc->wr_id = wqe->wr_id; uwc->status = IB_WC_WR_FLUSH_ERR; uwc->qp_num = qp_num(qp); - uwc->wr_id = wqe->wr_id; } else { + wc->wr_id = wqe->wr_id; wc->status = IB_WC_WR_FLUSH_ERR; wc->qp = &qp->ibqp; - wc->wr_id = wqe->wr_id; } - if (rxe_cq_post(qp->rcq, &cqe, 0)) - return -ENOMEM; + err = rxe_cq_post(qp->rcq, &cqe, 0); + if (err) + rxe_dbg_cq(qp->rcq, "post cq failed err = %d", err); - return 0; + return err; } /* drain and optionally complete the recive queue * if unable to complete a wqe stop completing and * just flush the remaining wqes */ -static void rxe_drain_recv_queue(struct rxe_qp *qp, bool notify) +static void flush_recv_queue(struct rxe_qp *qp, bool notify) { struct rxe_queue *q = qp->rq.queue; struct rxe_recv_wqe *wqe; @@ -1445,11 +1447,9 @@ static void rxe_drain_recv_queue(struct rxe_qp *qp, bool notify) while ((wqe = queue_head(q, q->type))) { if (notify) { - err = complete_flush(qp, wqe); - if (err) { - rxe_dbg_qp(qp, "complete failed for recv wqe"); + err = flush_recv_wqe(qp, wqe); + if (err) notify = 0; - } } queue_advance_consumer(q, q->type); } @@ -1471,8 +1471,8 @@ int rxe_responder(struct rxe_qp *qp) qp->resp.state == QP_STATE_RESET) { bool notify = qp->valid && (qp->resp.state == QP_STATE_ERROR); - rxe_drain_req_pkts(qp); - rxe_drain_recv_queue(qp, notify); + drain_req_pkts(qp); + flush_recv_queue(qp, notify); goto exit; } From patchwork Sat Mar 4 17:45:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bob Pearson X-Patchwork-Id: 13159983 X-Patchwork-Delegate: jgg@ziepe.ca Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 910D7C64EC4 for ; Sat, 4 Mar 2023 17:46:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229561AbjCDRqv (ORCPT ); Sat, 4 Mar 2023 12:46:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52190 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229711AbjCDRqu (ORCPT ); Sat, 4 Mar 2023 12:46:50 -0500 Received: from mail-ot1-x334.google.com (mail-ot1-x334.google.com [IPv6:2607:f8b0:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D16141B572 for ; Sat, 4 Mar 2023 09:46:48 -0800 (PST) Received: by mail-ot1-x334.google.com with SMTP id l16-20020a9d4c10000000b006944b17058cso2976771otf.2 for ; Sat, 04 Mar 2023 09:46:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1677952008; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=IGvVu9UP1kN4tY4HLfoBPjtQL2U8Fkq/aq9vMca1XFY=; b=OnmoqnE0t3PvHZQgi12z5lN8tpTtIIf3vSdwPc4wWyaNA5F1VOAZzJqJVi4EXKnrcW 4irV+Sma5/tYeCRcrV6dgRmoxhhCTm3LjUY1W6cQztatsLf9J94kuHUzlyiSTiQ6F5JB /7Jr1t+dHbMx0TL5MqAE85XLMfIPfSmQMQ/qj9mGu8blFC0PAF75GolkhWCL64HxAcNG 1kvV4IwZRJuSkg/GvU6l9jKIkvbV7siNRKrXMMunMqeQqzGP4P2OY56ptZ/ZbKWRonTz 5sOpscI3ENIZ3ma/s6U27bONLdXMhnpEyh0xrFcz1MaxaiINPlzxF12dyF+HWck1EgU7 fu8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677952008; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=IGvVu9UP1kN4tY4HLfoBPjtQL2U8Fkq/aq9vMca1XFY=; b=NX6V1nqg5jC63GeojmAIbuqJJ0JuWUlLKdJjcpfBIIWxtk6Kj4v8Qakr26OKNYyefM owc/V87oYlka6huOGR/SZsYqcWu8S0g8hHqE9Tp6S82DWEq1gqZSxKG0Mpl1o7+8L8/U sEb4Dz6DU84yhUBWOgLlaVdTluj33ESYSDP5xzHOG9NCfpJ+WfC0hSOJwtULiLsrfpKL 09R8LiPmerlz7lVhUsTmVYZBF8t/06d4MzwWk1SP/G2MI2HbuOGTuZj39oYaMEyJr9ra O/oydhcJ+2Fc/ZPeQ5qPD4sCpVoYBAduI/jLZICJFX2Mfc74hF8ywElU3voDoruGOMQo KWAQ== X-Gm-Message-State: AO0yUKWDdf+JDWzwVFSP4AKqaoZIxJNKXeei2jWM1OGqQaiasaQaKzPw KLe1PdrhKE2/NB0ZrnCq2YiTZypuE0w= X-Google-Smtp-Source: AK7set8Aku3Eu5CGlluEu0utSLPeprUGrVYNL2prrLBaA6MEfQJLGwFBT3biplOimd9b12wp/OGyAw== X-Received: by 2002:a05:6830:349d:b0:690:eb17:89f7 with SMTP id c29-20020a056830349d00b00690eb1789f7mr3958471otu.15.1677952008040; Sat, 04 Mar 2023 09:46:48 -0800 (PST) Received: from rpearson-X570-AORUS-PRO-WIFI.tx.rr.com (2603-8081-140c-1a00-f848-0c36-f4e0-0517.res6.spectrum.com. [2603:8081:140c:1a00:f848:c36:f4e0:517]) by smtp.gmail.com with ESMTPSA id a1-20020a056830008100b0068bcadcad5bsm2311227oto.57.2023.03.04.09.46.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 Mar 2023 09:46:47 -0800 (PST) From: Bob Pearson To: jgg@nvidia.com, zyjzyj2000@gmail.com, jhack@hpe.com, matsuda-daisuke@fujitsu.com, linux-rdma@vger.kernel.org Cc: Bob Pearson Subject: [PATCH for-next v3 5/8] RDMA/rxe: Remove qp reference counting in tasks Date: Sat, 4 Mar 2023 11:45:31 -0600 Message-Id: <20230304174533.11296-6-rpearsonhpe@gmail.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230304174533.11296-1-rpearsonhpe@gmail.com> References: <20230304174533.11296-1-rpearsonhpe@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org Currently each of the three tasklets requester, completer and responder in the rxe driver take and release a reference to the qp argument at the beginning and end of the subroutines. The caller passing in the qp argument should be responsible for holding a reference to qp so these are not required. Further doing so breaks the qp cleanup code in rxe_qp_do_cleanup which calls these routines after all the references have been dropped so they cannot drain the packet and work request queues as intended. In fact if these routines are deferred by calling tasklet_schedule there is no guarantee that the calling code does have a qp reference. That is a bug in rxe_task.c which will be fixed later in this series. Signed-off-by: Bob Pearson --- drivers/infiniband/sw/rxe/rxe_comp.c | 5 ----- drivers/infiniband/sw/rxe/rxe_req.c | 5 ----- drivers/infiniband/sw/rxe/rxe_resp.c | 4 ---- 3 files changed, 14 deletions(-) diff --git a/drivers/infiniband/sw/rxe/rxe_comp.c b/drivers/infiniband/sw/rxe/rxe_comp.c index f7ab0dfe1034..7aa8e90bdfe4 100644 --- a/drivers/infiniband/sw/rxe/rxe_comp.c +++ b/drivers/infiniband/sw/rxe/rxe_comp.c @@ -619,9 +619,6 @@ int rxe_completer(struct rxe_qp *qp) enum comp_state state; int ret; - if (!rxe_get(qp)) - return -EAGAIN; - if (!qp->valid || qp->comp.state == QP_STATE_ERROR || qp->comp.state == QP_STATE_RESET) { bool notify = qp->valid && @@ -824,7 +821,5 @@ int rxe_completer(struct rxe_qp *qp) out: if (pkt) free_pkt(pkt); - rxe_put(qp); - return ret; } diff --git a/drivers/infiniband/sw/rxe/rxe_req.c b/drivers/infiniband/sw/rxe/rxe_req.c index f2dc2d191e16..abc65c54bfd6 100644 --- a/drivers/infiniband/sw/rxe/rxe_req.c +++ b/drivers/infiniband/sw/rxe/rxe_req.c @@ -653,9 +653,6 @@ int rxe_requester(struct rxe_qp *qp) struct rxe_ah *ah; struct rxe_av *av; - if (!rxe_get(qp)) - return -EAGAIN; - if (unlikely(!qp->valid)) goto exit; @@ -844,7 +841,5 @@ int rxe_requester(struct rxe_qp *qp) exit: ret = -EAGAIN; out: - rxe_put(qp); - return ret; } diff --git a/drivers/infiniband/sw/rxe/rxe_resp.c b/drivers/infiniband/sw/rxe/rxe_resp.c index 2f71183449f9..01e3cbea8445 100644 --- a/drivers/infiniband/sw/rxe/rxe_resp.c +++ b/drivers/infiniband/sw/rxe/rxe_resp.c @@ -1464,9 +1464,6 @@ int rxe_responder(struct rxe_qp *qp) struct rxe_pkt_info *pkt = NULL; int ret; - if (!rxe_get(qp)) - return -EAGAIN; - if (!qp->valid || qp->resp.state == QP_STATE_ERROR || qp->resp.state == QP_STATE_RESET) { bool notify = qp->valid && @@ -1658,6 +1655,5 @@ int rxe_responder(struct rxe_qp *qp) exit: ret = -EAGAIN; out: - rxe_put(qp); return ret; } From patchwork Sat Mar 4 17:45:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bob Pearson X-Patchwork-Id: 13159984 X-Patchwork-Delegate: jgg@ziepe.ca Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 118C9C678DB for ; Sat, 4 Mar 2023 17:46:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229717AbjCDRqw (ORCPT ); Sat, 4 Mar 2023 12:46:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52264 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229715AbjCDRqv (ORCPT ); Sat, 4 Mar 2023 12:46:51 -0500 Received: from mail-oa1-x2c.google.com (mail-oa1-x2c.google.com [IPv6:2001:4860:4864:20::2c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AA2DE1BAE1 for ; Sat, 4 Mar 2023 09:46:49 -0800 (PST) Received: by mail-oa1-x2c.google.com with SMTP id 586e51a60fabf-17264e9b575so6754323fac.9 for ; Sat, 04 Mar 2023 09:46:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1677952009; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Jv6kagLBc5L/7qIzPYC6G0WZ1fByyFireELn/eI6LR8=; b=eJ67j4YJTl33ZIQayc7XTimUd6/APC4oW/7fzX1x1hz2PlpH9Ye1ty63MSWcJ8/YDq fjdQD1eQJtRoK33JRtKxTNjqiceVMi4jAQe/R/tQpMsGScv/VDwsoWPJiCNYxfDWfL+q 26tdYZvnu/B1pW9iY2o088B2jwO9Zq7GPw4F2R39Q/ulNmmcANChmMSAJIOIquNK0ltX RH9N/oueBIMuiMwyusdx3r/J3D083nY1OZOa7BPFLVHOl1tFv5Elxt4zNrlvUcLuJZZd EVT2oxWuibnDWTlaeWoRFE5Dll41nXP6mCt0lwZ9OYnzSb+6FMgCEylK5ZdpBst1pCLU zacQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677952009; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Jv6kagLBc5L/7qIzPYC6G0WZ1fByyFireELn/eI6LR8=; b=xhkGwcgQiOuW5Wn1ekWPngoNBhprl4VsoOr22uwyPDlT3DynoTDph3DKjxfa17uGzs HwbACYzDK4TGuIyD7REgKe47JVGhcTpe41De4fsfDjx46JPJDA4WwE1dnHauc/2dCFst ylizOly3gIud12g2JFzURE7o+GC9rvmcy76jfyJcrBj4RtY6E0dU3RPMCyqS8UPaAAhl i9B4maS87fGUG6bKbJIzwYTNLMlUPDroXTAGSqZdEUU9d7/WCue2j1p1u6lGEpB+lmLH M35V8FV5ywaor/jVTyKgGxfWoDcGiVSCsJP+/gX2RfmxPATgCzqAglfM+5n3ykMo2wfb Yo0w== X-Gm-Message-State: AO0yUKVa/PFcpS752Pa76uuw59UA+tT6eiQUYngsr9uy2WNQaWed+dkr jSdjqFbP2b0tyCdwxodid+Z8OYOczxc= X-Google-Smtp-Source: AK7set8EFxi1cHKzHBxmBu9/LfwTko7o8VJjDefScsXujGxbNawYPEq3BtDCWgk43ArLrlBRpr7E3w== X-Received: by 2002:a05:6870:8a22:b0:176:2533:2164 with SMTP id p34-20020a0568708a2200b0017625332164mr3919671oaq.42.1677952009003; Sat, 04 Mar 2023 09:46:49 -0800 (PST) Received: from rpearson-X570-AORUS-PRO-WIFI.tx.rr.com (2603-8081-140c-1a00-f848-0c36-f4e0-0517.res6.spectrum.com. [2603:8081:140c:1a00:f848:c36:f4e0:517]) by smtp.gmail.com with ESMTPSA id a1-20020a056830008100b0068bcadcad5bsm2311227oto.57.2023.03.04.09.46.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 Mar 2023 09:46:48 -0800 (PST) From: Bob Pearson To: jgg@nvidia.com, zyjzyj2000@gmail.com, jhack@hpe.com, matsuda-daisuke@fujitsu.com, linux-rdma@vger.kernel.org Cc: Bob Pearson , Ian Ziemba Subject: [PATCH for-next v3 6/8] RDMA/rxe: Remove __rxe_do_task() Date: Sat, 4 Mar 2023 11:45:32 -0600 Message-Id: <20230304174533.11296-7-rpearsonhpe@gmail.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230304174533.11296-1-rpearsonhpe@gmail.com> References: <20230304174533.11296-1-rpearsonhpe@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org The subroutine __rxe_do_task is not thread safe and it has no way to guarantee that the tasks, which are designed with the assumption that they are non-reentrant, are not reentered. All of its uses are non-performance critical. This patch replaces calls to __rxe_do_task with calls to rxe_sched_task. It also removes irrelevant or unneeded if tests. Instead of calling the task machinery a single call to the tasklet function (rxe_requester, etc.) is sufficient to draing the queues if task execution has been disabled or stopped. Together these changes allow the removal of __rxe_do_task. Signed-off-by: Ian Ziemba Signed-off-by: Bob Pearson --- drivers/infiniband/sw/rxe/rxe_qp.c | 56 +++++++++------------------- drivers/infiniband/sw/rxe/rxe_task.c | 13 ------- drivers/infiniband/sw/rxe/rxe_task.h | 6 --- 3 files changed, 17 insertions(+), 58 deletions(-) diff --git a/drivers/infiniband/sw/rxe/rxe_qp.c b/drivers/infiniband/sw/rxe/rxe_qp.c index c954dd9394ba..49891f8ed4e6 100644 --- a/drivers/infiniband/sw/rxe/rxe_qp.c +++ b/drivers/infiniband/sw/rxe/rxe_qp.c @@ -473,29 +473,23 @@ static void rxe_qp_reset(struct rxe_qp *qp) { /* stop tasks from running */ rxe_disable_task(&qp->resp.task); - - /* stop request/comp */ - if (qp->sq.queue) { - if (qp_type(qp) == IB_QPT_RC) - rxe_disable_task(&qp->comp.task); - rxe_disable_task(&qp->req.task); - } + rxe_disable_task(&qp->comp.task); + rxe_disable_task(&qp->req.task); /* move qp to the reset state */ qp->req.state = QP_STATE_RESET; qp->comp.state = QP_STATE_RESET; qp->resp.state = QP_STATE_RESET; - /* let state machines reset themselves drain work and packet queues - * etc. - */ - __rxe_do_task(&qp->resp.task); + /* drain work and packet queuesc */ + rxe_requester(qp); + rxe_completer(qp); + rxe_responder(qp); - if (qp->sq.queue) { - __rxe_do_task(&qp->comp.task); - __rxe_do_task(&qp->req.task); + if (qp->rq.queue) + rxe_queue_reset(qp->rq.queue); + if (qp->sq.queue) rxe_queue_reset(qp->sq.queue); - } /* cleanup attributes */ atomic_set(&qp->ssn, 0); @@ -518,13 +512,8 @@ static void rxe_qp_reset(struct rxe_qp *qp) /* reenable tasks */ rxe_enable_task(&qp->resp.task); - - if (qp->sq.queue) { - if (qp_type(qp) == IB_QPT_RC) - rxe_enable_task(&qp->comp.task); - - rxe_enable_task(&qp->req.task); - } + rxe_enable_task(&qp->comp.task); + rxe_enable_task(&qp->req.task); } /* drain the send queue */ @@ -533,10 +522,7 @@ static void rxe_qp_drain(struct rxe_qp *qp) if (qp->sq.queue) { if (qp->req.state != QP_STATE_DRAINED) { qp->req.state = QP_STATE_DRAIN; - if (qp_type(qp) == IB_QPT_RC) - rxe_sched_task(&qp->comp.task); - else - __rxe_do_task(&qp->comp.task); + rxe_sched_task(&qp->comp.task); rxe_sched_task(&qp->req.task); } } @@ -552,11 +538,7 @@ void rxe_qp_error(struct rxe_qp *qp) /* drain work and packet queues */ rxe_sched_task(&qp->resp.task); - - if (qp_type(qp) == IB_QPT_RC) - rxe_sched_task(&qp->comp.task); - else - __rxe_do_task(&qp->comp.task); + rxe_sched_task(&qp->comp.task); rxe_sched_task(&qp->req.task); } @@ -773,24 +755,20 @@ static void rxe_qp_do_cleanup(struct work_struct *work) qp->valid = 0; qp->qp_timeout_jiffies = 0; - rxe_cleanup_task(&qp->resp.task); if (qp_type(qp) == IB_QPT_RC) { del_timer_sync(&qp->retrans_timer); del_timer_sync(&qp->rnr_nak_timer); } + rxe_cleanup_task(&qp->resp.task); rxe_cleanup_task(&qp->req.task); rxe_cleanup_task(&qp->comp.task); /* flush out any receive wr's or pending requests */ - if (qp->req.task.func) - __rxe_do_task(&qp->req.task); - - if (qp->sq.queue) { - __rxe_do_task(&qp->comp.task); - __rxe_do_task(&qp->req.task); - } + rxe_requester(qp); + rxe_completer(qp); + rxe_responder(qp); if (qp->sq.queue) rxe_queue_cleanup(qp->sq.queue); diff --git a/drivers/infiniband/sw/rxe/rxe_task.c b/drivers/infiniband/sw/rxe/rxe_task.c index 959cc6229a34..a67f48545443 100644 --- a/drivers/infiniband/sw/rxe/rxe_task.c +++ b/drivers/infiniband/sw/rxe/rxe_task.c @@ -6,19 +6,6 @@ #include "rxe.h" -int __rxe_do_task(struct rxe_task *task) - -{ - int ret; - - while ((ret = task->func(task->qp)) == 0) - ; - - task->ret = ret; - - return ret; -} - /* * this locking is due to a potential race where * a second caller finds the task already running diff --git a/drivers/infiniband/sw/rxe/rxe_task.h b/drivers/infiniband/sw/rxe/rxe_task.h index 41efd5fd49b0..99585e40cef9 100644 --- a/drivers/infiniband/sw/rxe/rxe_task.h +++ b/drivers/infiniband/sw/rxe/rxe_task.h @@ -39,12 +39,6 @@ int rxe_init_task(struct rxe_task *task, struct rxe_qp *qp, /* cleanup task */ void rxe_cleanup_task(struct rxe_task *task); -/* - * raw call to func in loop without any checking - * can call when tasklets are disabled - */ -int __rxe_do_task(struct rxe_task *task); - void rxe_run_task(struct rxe_task *task); void rxe_sched_task(struct rxe_task *task); From patchwork Sat Mar 4 17:45:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bob Pearson X-Patchwork-Id: 13159985 X-Patchwork-Delegate: jgg@ziepe.ca Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 56C61C64EC4 for ; Sat, 4 Mar 2023 17:46:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229721AbjCDRqy (ORCPT ); Sat, 4 Mar 2023 12:46:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52190 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229707AbjCDRqw (ORCPT ); Sat, 4 Mar 2023 12:46:52 -0500 Received: from mail-ot1-x332.google.com (mail-ot1-x332.google.com [IPv6:2607:f8b0:4864:20::332]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8B7981BAFD for ; Sat, 4 Mar 2023 09:46:50 -0800 (PST) Received: by mail-ot1-x332.google.com with SMTP id p13-20020a9d744d000000b0069438f0db7eso3191963otk.3 for ; Sat, 04 Mar 2023 09:46:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1677952010; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=o+2eRgZ8KYhml2H2Y6U9wDqhJyraTfw9SmXx0o4tRZc=; b=hfwZ0juf51smDu4eVU0GGPEAcVj584BMIDp+IoO9JHotguPFh65msXsl3VmwIhKok5 8tEKwxAJBFI6YQMoVhP5uIEpcXVpGgNwC50aQYPUqDHN9ZbCYSWF75Nqbv8CljXyDNxu huEis8javDhkTerMrBP6ThpsRUtSLaHBbQoh74N5i2GhOAaxy8BUymt4dgF+6+HPuisQ LoUpaa8RmGR9PBrG7+DoMK/iPDdQ3nESdfUUFTbphCYt1Ukd/WQ9ivY0ES/qrdmbFMk+ 3JuhbDYc8ySFoDRb9t5KKczKCLlRBWS4wQq943/tsd/sG7n6VkVFCYhzqbtxui5fpu70 sBQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677952010; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=o+2eRgZ8KYhml2H2Y6U9wDqhJyraTfw9SmXx0o4tRZc=; b=YRLiENxF33S7zTRVNEuMTbwm7QfhwyZhc2cXNAhGhK89xbSl0mWLGDM8X4yqeuf0x1 dEFTmCwRGQUomJCnBnq9vSUMCwLVA4++8ZSZJMp+P/kHkzfyUJWfp9djO7CM+yWVmZmH UErfxEwGcaPLIFFWD3lc2htpU2drk8soXo9F+Y2O8oQxoj3UhGVN9Nx9vuKitA3Vk3nX wWarNRxQ74fEBIBdIhXHZ6QN9YqGBRXusnUlp06Rpw9Zv8f0KoBUYaylYJbamNqI+Brc fBAoHB3w+WG+z76c1dmeyb1pMZ5LxLNR/m7qTGPm01bSiT5SaPmY31QTViz0kANiOVmF 8/uw== X-Gm-Message-State: AO0yUKXm2esUJCma8cmGF2QWFelgqbchQVjZZc1yPaVH6Aik49vJ6pp3 FhqWxclRl9mArDr2/ZKKDtM= X-Google-Smtp-Source: AK7set/axC767nh6yUC2hpzS6Bz/SXKwQyG2hQrQFjHKo9fCtmHSf3S20HlxzOSL5ZjtnQqXdYOdOQ== X-Received: by 2002:a05:6830:4ac:b0:693:c3bb:8392 with SMTP id l12-20020a05683004ac00b00693c3bb8392mr5315262otd.7.1677952009932; Sat, 04 Mar 2023 09:46:49 -0800 (PST) Received: from rpearson-X570-AORUS-PRO-WIFI.tx.rr.com (2603-8081-140c-1a00-f848-0c36-f4e0-0517.res6.spectrum.com. [2603:8081:140c:1a00:f848:c36:f4e0:517]) by smtp.gmail.com with ESMTPSA id a1-20020a056830008100b0068bcadcad5bsm2311227oto.57.2023.03.04.09.46.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 Mar 2023 09:46:49 -0800 (PST) From: Bob Pearson To: jgg@nvidia.com, zyjzyj2000@gmail.com, jhack@hpe.com, matsuda-daisuke@fujitsu.com, linux-rdma@vger.kernel.org Cc: Bob Pearson , Ian Ziemba Subject: [PATCH for-next v3 7/8] RDMA/rxe: Make tasks schedule each other Date: Sat, 4 Mar 2023 11:45:33 -0600 Message-Id: <20230304174533.11296-8-rpearsonhpe@gmail.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230304174533.11296-1-rpearsonhpe@gmail.com> References: <20230304174533.11296-1-rpearsonhpe@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org Replace rxe_run_task() by rxe_sched_task() when tasks call each other. These are not performance critical and mainly involve error paths but they run the risk of causing deadlocks. Signed-off-by: Ian Ziemba Signed-off-by: Bob Pearson --- drivers/infiniband/sw/rxe/rxe_comp.c | 8 ++++---- drivers/infiniband/sw/rxe/rxe_req.c | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/infiniband/sw/rxe/rxe_comp.c b/drivers/infiniband/sw/rxe/rxe_comp.c index 7aa8e90bdfe4..2c70cdcd55dc 100644 --- a/drivers/infiniband/sw/rxe/rxe_comp.c +++ b/drivers/infiniband/sw/rxe/rxe_comp.c @@ -322,7 +322,7 @@ static inline enum comp_state check_ack(struct rxe_qp *qp, qp->comp.psn = pkt->psn; if (qp->req.wait_psn) { qp->req.wait_psn = 0; - rxe_run_task(&qp->req.task); + rxe_sched_task(&qp->req.task); } } return COMPST_ERROR_RETRY; @@ -473,7 +473,7 @@ static void do_complete(struct rxe_qp *qp, struct rxe_send_wqe *wqe) */ if (qp->req.wait_fence) { qp->req.wait_fence = 0; - rxe_run_task(&qp->req.task); + rxe_sched_task(&qp->req.task); } } @@ -487,7 +487,7 @@ static inline enum comp_state complete_ack(struct rxe_qp *qp, if (qp->req.need_rd_atomic) { qp->comp.timeout_retry = 0; qp->req.need_rd_atomic = 0; - rxe_run_task(&qp->req.task); + rxe_sched_task(&qp->req.task); } } @@ -767,7 +767,7 @@ int rxe_completer(struct rxe_qp *qp) RXE_CNT_COMP_RETRY); qp->req.need_retry = 1; qp->comp.started_retry = 1; - rxe_run_task(&qp->req.task); + rxe_sched_task(&qp->req.task); } goto done; diff --git a/drivers/infiniband/sw/rxe/rxe_req.c b/drivers/infiniband/sw/rxe/rxe_req.c index abc65c54bfd6..745731140a54 100644 --- a/drivers/infiniband/sw/rxe/rxe_req.c +++ b/drivers/infiniband/sw/rxe/rxe_req.c @@ -753,7 +753,7 @@ int rxe_requester(struct rxe_qp *qp) qp->req.wqe_index); wqe->state = wqe_state_done; wqe->status = IB_WC_SUCCESS; - rxe_run_task(&qp->comp.task); + rxe_sched_task(&qp->comp.task); goto done; } payload = mtu; @@ -837,7 +837,7 @@ int rxe_requester(struct rxe_qp *qp) qp->req.wqe_index = queue_next_index(qp->sq.queue, qp->req.wqe_index); wqe->state = wqe_state_error; qp->req.state = QP_STATE_ERROR; - rxe_run_task(&qp->comp.task); + rxe_sched_task(&qp->comp.task); exit: ret = -EAGAIN; out: From patchwork Sat Mar 4 17:45:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bob Pearson X-Patchwork-Id: 13159986 X-Patchwork-Delegate: jgg@ziepe.ca Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E752DC678D5 for ; Sat, 4 Mar 2023 17:46:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229711AbjCDRqz (ORCPT ); Sat, 4 Mar 2023 12:46:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52304 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229707AbjCDRqy (ORCPT ); Sat, 4 Mar 2023 12:46:54 -0500 Received: from mail-oa1-x2c.google.com (mail-oa1-x2c.google.com [IPv6:2001:4860:4864:20::2c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AB4611BAC7 for ; Sat, 4 Mar 2023 09:46:51 -0800 (PST) Received: by mail-oa1-x2c.google.com with SMTP id 586e51a60fabf-17235c8dab9so6771186fac.7 for ; Sat, 04 Mar 2023 09:46:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1677952011; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=IDnnS1X2195xhN62BFYlB0BCPR/h96fihQQj+cQ9uvQ=; b=FTyz1WU6Xldx0CTDciCMmNKud+2fDqinBurirg9B0hMzqC856ud5Z6V2xfb3f/KzTr 5nQ/9AsaN4gaZbMGV7WpvkrCGosqFZIdQw7HHlzKcdNIM/NaloNN7aC0HfO6qIsa/aeM Om3nNXHyEUcgBCuiZgggl99JkQ6HEabznthtEdwfjNlOMF/2o9NMRPYnCc5wuFGwrHNJ QfSPY0KUsPy6bzmdCX09YleuEDmBAzeqrj+30Pcg0vJCl3izhGRTI4bmYrCMdCqVYSkW /GaJMtfxp+KV2cBSusMaecP16rTirhc7oPjn1ZisaiwImRHgHYj5+ds/Rn6khMqh1KS1 KECA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677952011; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=IDnnS1X2195xhN62BFYlB0BCPR/h96fihQQj+cQ9uvQ=; b=tzRAab/hn/sZD0JVxuDBP5/XkYv/eFWAPDdDqp4CgDkWN0jY+dBvaJN3L9JZRgCVwb G93nvYGpL+4AS6piSSxq0idwIjEVaZPCHGqImc2UAqVZPW+TI9E6YhoSooZjH/7l9dw4 87lVZSi8ezDJbfHvmR0BAUAC+7J0huKql1NYADVKga1XrC2TPsJWCWIt0j7K1vniK0Zl nKL6SZqL9wDPnts/vopo/TdGw0TVE/A8wTgV2AOidpSf8hIvNFzTj/EfXoAzIPwKgt4/ OSeIuvWLdt9FX5Wia+Da+i5PaV7S+eZiXOl5vbVCKLuDLydxHsNhanyQYgqSycb9duop sBsg== X-Gm-Message-State: AO0yUKVObXmQj0oxydHpKdv0TjEdvoQ+eM+g+t6Oex9J5rfS32ESklYg 0dYszDGlLGFYHZAPI8JvcXxK8ty0/44= X-Google-Smtp-Source: AK7set/73ZuX2czMDqEVrsfZN91qq22c8IHcIbb1eD/qBqRg0kIOcmgPpinAKne92uDuNfkjPn2oEw== X-Received: by 2002:a05:6870:c6a9:b0:172:36bf:e281 with SMTP id cv41-20020a056870c6a900b0017236bfe281mr5295874oab.23.1677952010823; Sat, 04 Mar 2023 09:46:50 -0800 (PST) Received: from rpearson-X570-AORUS-PRO-WIFI.tx.rr.com (2603-8081-140c-1a00-f848-0c36-f4e0-0517.res6.spectrum.com. [2603:8081:140c:1a00:f848:c36:f4e0:517]) by smtp.gmail.com with ESMTPSA id a1-20020a056830008100b0068bcadcad5bsm2311227oto.57.2023.03.04.09.46.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 Mar 2023 09:46:50 -0800 (PST) From: Bob Pearson To: jgg@nvidia.com, zyjzyj2000@gmail.com, jhack@hpe.com, matsuda-daisuke@fujitsu.com, linux-rdma@vger.kernel.org Cc: Bob Pearson Subject: [PATCH for-next v3 8/8] RDMA/rxe: Rewrite rxe_task.c Date: Sat, 4 Mar 2023 11:45:34 -0600 Message-Id: <20230304174533.11296-9-rpearsonhpe@gmail.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230304174533.11296-1-rpearsonhpe@gmail.com> References: <20230304174533.11296-1-rpearsonhpe@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org This patch is a major rewrite of the tasklet routines in rxe_task.c. The main motivation for this is the realization that the code violates the safety of the qp pointer by correct reference counting. When a tasklet is scheduled from a verbs API the calling thread has a valid reference to the qp and schedules the tasklet to run at a later time carrying a pointer to the qp. Once the calling code returns however the qp can be destroyed at any time. In order to correct this a reference to the qp must be taken when the task is scheduled and held until it finishes running. This is complicated by the tasklet library not alwys running a task that is scheduled depending on whether someone else has scheduled it. This patch moves the logic for deciding whether to run or schedule a task outside of do_task() and guarantees that there is only one copy of the task scheduled or running at a time. Secondly the separate flags controlling teardown and draining of the task are included in the task state machine and all references to the state are protected by spinlocks to avoid consistency and memory barrier issues. Signed-off-by: Bob Pearson --- drivers/infiniband/sw/rxe/rxe_task.c | 266 +++++++++++++++++++++------ drivers/infiniband/sw/rxe/rxe_task.h | 8 +- 2 files changed, 218 insertions(+), 56 deletions(-) diff --git a/drivers/infiniband/sw/rxe/rxe_task.c b/drivers/infiniband/sw/rxe/rxe_task.c index a67f48545443..fea9a517c8d9 100644 --- a/drivers/infiniband/sw/rxe/rxe_task.c +++ b/drivers/infiniband/sw/rxe/rxe_task.c @@ -6,56 +6,128 @@ #include "rxe.h" -/* - * this locking is due to a potential race where - * a second caller finds the task already running - * but looks just after the last call to func +/* Check if task is idle i.e. not running, not scheduled in + * tasklet queue and not draining. If so move to busy to + * reserve a slot in do_task() by setting to busy and taking + * a qp reference to cover the gap from now until the task finishes. + * state will move out of busy if task returns a non zero value + * in do_task(). If state is already busy it is raised to armed + * to indicate to do_task that additional pass should be made + * over the task. + * Context: caller should hold task->lock. + * Returns: true if state transitioned from idle to busy else false. + */ +static bool __reserve_if_idle(struct rxe_task *task) +{ + WARN_ON(rxe_read(task->qp) <= 0); + + if (task->tasklet.state & TASKLET_STATE_SCHED) + return false; + + if (task->state == TASK_STATE_IDLE) { + rxe_get(task->qp); + task->state = TASK_STATE_BUSY; + task->num_sched++; + return true; + } + + if (task->state == TASK_STATE_BUSY) + task->state = TASK_STATE_ARMED; + + return false; +} + +/* check if task is idle or drained and not currently + * scheduled in the tasklet queue. This routine is + * called by rxe_cleanup_task or rxe_disable_task to + * see if the queue is empty. + * Context: caller should hold task->lock. + * Returns true if done else false. + */ +static bool __is_done(struct rxe_task *task) +{ + if (task->tasklet.state & TASKLET_STATE_SCHED) + return false; + + if (task->state == TASK_STATE_IDLE || + task->state == TASK_STATE_DRAINED) { + return true; + } + + return false; +} + +/* a locked version of __is_done */ +static bool is_done(struct rxe_task *task) +{ + unsigned long flags; + int done; + + spin_lock_irqsave(&task->lock, flags); + done = __is_done(task); + spin_unlock_irqrestore(&task->lock, flags); + + return done; +} + +/* do_task is a wrapper for the three tasks (requester, + * completer, responder) and calls them in a loop until + * they return a non-zero value. It is called either + * directly by rxe_run_task or indirectly if rxe_sched_task + * schedules the task. They must call __reserve_if_idle to + * move the task to busy before calling or scheduling. + * The task can also be moved to drained or invalid + * by calls to rxe-cleanup_task or rxe_disable_task. + * In that case tasks which get here are not executed but + * just flushed. The tasks are designed to look to see if + * there is work to do and do part of it before returning + * here with a return value of zero until all the work + * has been consumed then it retuens a non-zero value. + * The number of times the task can be run is limited by + * max iterations so one task cannot hold the cpu forever. */ static void do_task(struct tasklet_struct *t) { int cont; int ret; struct rxe_task *task = from_tasklet(task, t, tasklet); - struct rxe_qp *qp = (struct rxe_qp *)task->qp; - unsigned int iterations = RXE_MAX_ITERATIONS; + unsigned int iterations; + unsigned long flags; + int resched = 0; - spin_lock_bh(&task->lock); - switch (task->state) { - case TASK_STATE_START: - task->state = TASK_STATE_BUSY; - spin_unlock_bh(&task->lock); - break; - - case TASK_STATE_BUSY: - task->state = TASK_STATE_ARMED; - fallthrough; - case TASK_STATE_ARMED: - spin_unlock_bh(&task->lock); - return; + WARN_ON(rxe_read(task->qp) <= 0); - default: - spin_unlock_bh(&task->lock); - rxe_dbg_qp(qp, "failed with bad state %d\n", task->state); + spin_lock_irqsave(&task->lock, flags); + if (task->state >= TASK_STATE_DRAINED) { + rxe_put(task->qp); + task->num_done++; + spin_unlock_irqrestore(&task->lock, flags); return; } + spin_unlock_irqrestore(&task->lock, flags); do { + iterations = RXE_MAX_ITERATIONS; cont = 0; - ret = task->func(task->qp); - spin_lock_bh(&task->lock); + do { + ret = task->func(task->qp); + } while (ret == 0 && iterations-- > 0); + + spin_lock_irqsave(&task->lock, flags); switch (task->state) { case TASK_STATE_BUSY: if (ret) { - task->state = TASK_STATE_START; - } else if (iterations--) { - cont = 1; + task->state = TASK_STATE_IDLE; } else { - /* reschedule the tasklet and exit + /* This can happen if the client + * can add work faster than the + * tasklet can finish it. + * Reschedule the tasklet and exit * the loop to give up the cpu */ - tasklet_schedule(&task->tasklet); - task->state = TASK_STATE_START; + task->state = TASK_STATE_IDLE; + resched = 1; } break; @@ -68,72 +140,158 @@ static void do_task(struct tasklet_struct *t) cont = 1; break; + case TASK_STATE_DRAINING: + if (ret) + task->state = TASK_STATE_DRAINED; + else + cont = 1; + break; + default: - rxe_dbg_qp(qp, "failed with bad state %d\n", - task->state); + WARN_ON(1); + rxe_info_qp(task->qp, "unexpected task state = %d", task->state); + } + + if (!cont) { + task->num_done++; + if (WARN_ON(task->num_done != task->num_sched)) + rxe_err_qp(task->qp, "%ld tasks scheduled, %ld tasks done", + task->num_sched, task->num_done); } - spin_unlock_bh(&task->lock); + spin_unlock_irqrestore(&task->lock, flags); } while (cont); task->ret = ret; + + if (resched) + rxe_sched_task(task); + + rxe_put(task->qp); } int rxe_init_task(struct rxe_task *task, struct rxe_qp *qp, int (*func)(struct rxe_qp *)) { - task->qp = qp; - task->func = func; - task->destroyed = false; + WARN_ON(rxe_read(qp) <= 0); + + task->qp = qp; + task->func = func; tasklet_setup(&task->tasklet, do_task); - task->state = TASK_STATE_START; + task->state = TASK_STATE_IDLE; spin_lock_init(&task->lock); return 0; } +/* rxe_cleanup_task is only called from rxe_do_qp_cleanup in + * process context. The qp is already completed with no + * remaining references. Once the queue is drained the + * task is moved to invalid and returns. The qp cleanup + * code then calls the task functions directly without + * using the task struct to drain any late arriving packets + * or work requests. + */ void rxe_cleanup_task(struct rxe_task *task) { - bool idle; + unsigned long flags; - /* - * Mark the task, then wait for it to finish. It might be - * running in a non-tasklet (direct call) context. - */ - task->destroyed = true; + spin_lock_irqsave(&task->lock, flags); + if (!__is_done(task) && task->state < TASK_STATE_DRAINED) { + task->state = TASK_STATE_DRAINING; + } else { + task->state = TASK_STATE_INVALID; + spin_unlock_irqrestore(&task->lock, flags); + return; + } + spin_unlock_irqrestore(&task->lock, flags); - do { - spin_lock_bh(&task->lock); - idle = (task->state == TASK_STATE_START); - spin_unlock_bh(&task->lock); - } while (!idle); + /* now the task cannot be scheduled or run just wait + * for the previously scheduled tasks to finish. + */ + while (!is_done(task)) + cond_resched(); tasklet_kill(&task->tasklet); + + spin_lock_irqsave(&task->lock, flags); + task->state = TASK_STATE_INVALID; + spin_unlock_irqrestore(&task->lock, flags); } +/* run the task inline if it is currently idle + * cannot call do_task holding the lock + */ void rxe_run_task(struct rxe_task *task) { - if (task->destroyed) - return; + unsigned long flags; + int run; + + WARN_ON(rxe_read(task->qp) <= 0); - do_task(&task->tasklet); + spin_lock_irqsave(&task->lock, flags); + run = __reserve_if_idle(task); + spin_unlock_irqrestore(&task->lock, flags); + + if (run) + do_task(&task->tasklet); } +/* schedule the task to run later as a tasklet. + * the tasklet)schedule call can be called holding + * the lock. + */ void rxe_sched_task(struct rxe_task *task) { - if (task->destroyed) - return; + unsigned long flags; + + WARN_ON(rxe_read(task->qp) <= 0); - tasklet_schedule(&task->tasklet); + spin_lock_irqsave(&task->lock, flags); + if (__reserve_if_idle(task)) + tasklet_schedule(&task->tasklet); + spin_unlock_irqrestore(&task->lock, flags); } +/* rxe_disable/enable_task are only called from + * rxe_modify_qp in process context. Task is moved + * to the drained state by do_task. + */ void rxe_disable_task(struct rxe_task *task) { + unsigned long flags; + + WARN_ON(rxe_read(task->qp) <= 0); + + spin_lock_irqsave(&task->lock, flags); + if (!__is_done(task) && task->state < TASK_STATE_DRAINED) { + task->state = TASK_STATE_DRAINING; + } else { + task->state = TASK_STATE_DRAINED; + spin_unlock_irqrestore(&task->lock, flags); + return; + } + spin_unlock_irqrestore(&task->lock, flags); + + while (!is_done(task)) + cond_resched(); + tasklet_disable(&task->tasklet); } void rxe_enable_task(struct rxe_task *task) { + unsigned long flags; + + WARN_ON(rxe_read(task->qp) <= 0); + + spin_lock_irqsave(&task->lock, flags); + if (task->state == TASK_STATE_INVALID) { + spin_unlock_irqrestore(&task->lock, flags); + return; + } + task->state = TASK_STATE_IDLE; tasklet_enable(&task->tasklet); + spin_unlock_irqrestore(&task->lock, flags); } diff --git a/drivers/infiniband/sw/rxe/rxe_task.h b/drivers/infiniband/sw/rxe/rxe_task.h index 99585e40cef9..facb7c8e3729 100644 --- a/drivers/infiniband/sw/rxe/rxe_task.h +++ b/drivers/infiniband/sw/rxe/rxe_task.h @@ -8,9 +8,12 @@ #define RXE_TASK_H enum { - TASK_STATE_START = 0, + TASK_STATE_IDLE = 0, TASK_STATE_BUSY = 1, TASK_STATE_ARMED = 2, + TASK_STATE_DRAINING = 3, + TASK_STATE_DRAINED = 4, + TASK_STATE_INVALID = 5, }; /* @@ -25,7 +28,8 @@ struct rxe_task { struct rxe_qp *qp; int (*func)(struct rxe_qp *qp); int ret; - bool destroyed; + long num_sched; + long num_done; }; /*