From patchwork Fri Feb 18 00:35:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bob Pearson X-Patchwork-Id: 12750825 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 E70CEC4332F for ; Fri, 18 Feb 2022 00:36:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229457AbiBRAg6 (ORCPT ); Thu, 17 Feb 2022 19:36:58 -0500 Received: from gmail-smtp-in.l.google.com ([23.128.96.19]:33864 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230019AbiBRAg5 (ORCPT ); Thu, 17 Feb 2022 19:36:57 -0500 Received: from mail-oi1-x22e.google.com (mail-oi1-x22e.google.com [IPv6:2607:f8b0:4864:20::22e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 16A602612F for ; Thu, 17 Feb 2022 16:36:42 -0800 (PST) Received: by mail-oi1-x22e.google.com with SMTP id q5so1412841oij.6 for ; Thu, 17 Feb 2022 16:36:42 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=HCikr/21UBQgDZaKxWYexvox9IwibwcSTcDjepolExE=; b=Kgrv/x13azUEwcxZ/xOk3D+cL/Oe1thqH7AXW98mYs8xDQiQ6MRvEVquT5aIgaQ44N mtsK4AWVFG4GCO4wJn77D7vdd5aM4FIRc/CSY/Lpx/Iw+Re1lbyak1otxZjCXewTSeZN pqmJ5UZ4TnY2ckOXnocxurGtccM5Kfl0+wIpKnfvIvRAKiZKeT8JO252JvV3aU8Utn6/ kK06lhxhaSKAWy9POWw95jxL04OVzVcerVrYrhlJBigh5rcuJElvypc1KayZAXpl7lex HOsaHjrJ9nciIl8xUJXsjWZfq6SSbHnjfdL6P9QB9WNYoMrHwmdJ5ar1vRgN8Sr0gzfR bIxQ== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=HCikr/21UBQgDZaKxWYexvox9IwibwcSTcDjepolExE=; b=rNuoh/+Du4ZY5azazL5043fhii537dNMOp38kVTe4J0KbpLuCQs3/8wSlNeNOPkdzO WOWM5aPB9SU4Hrd8PjVWP7Tbhj5pgJFbZA357igdCYj5bM3pOPeHgobO6L9oOJDIA3us RYzkfRAK1Qjo9SUB4CHh+MWVK3gWOVBYwjujwTUSoZ/YfujBFa6WU8zyRZpQKQwWsbLU Hmie74yw4l0HNFYW+cDJx5pWJnye7UkNM2dkSzaeIt+ODKhCmRKcu5RyjCxBfbM2hiLG 9UsrTPWH98IDt+DokpyEDU4xL/dj/rpcgZzZh7frXX2BipVV7BEP9Bs4BOycUvwwi11K x67Q== X-Gm-Message-State: AOAM533/pi4lsCuwBEWSFIzWBTRjot9sColm0pp97iLgl7wBIPtX5q7u cdSQyj0ZRvFL5uiNqABFu/U= X-Google-Smtp-Source: ABdhPJzbPhg9ddQMzOsK2l9T+D7TpDpxHW8koExSDUT+PmFIZ5Tzt4LDTnbQGbxmEsRWADjn8Sl9JQ== X-Received: by 2002:aca:42c6:0:b0:2cc:a020:c00f with SMTP id p189-20020aca42c6000000b002cca020c00fmr2246435oia.86.1645144601448; Thu, 17 Feb 2022 16:36:41 -0800 (PST) Received: from ubuntu-21.tx.rr.com (2603-8081-140c-1a00-1772-15fa-cf3f-3cd5.res6.spectrum.com. [2603:8081:140c:1a00:1772:15fa:cf3f:3cd5]) by smtp.googlemail.com with ESMTPSA id t31sm19698299oaa.9.2022.02.17.16.36.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Feb 2022 16:36:41 -0800 (PST) From: Bob Pearson To: jgg@nvidia.com, zyjzyj2000@gmail.com, linux-rdma@vger.kernel.org Cc: Bob Pearson Subject: [PATCH for-next v12 1/6] RDMA/rxe: Add code to cleanup mcast memory Date: Thu, 17 Feb 2022 18:35:39 -0600 Message-Id: <20220218003543.205799-2-rpearsonhpe@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220218003543.205799-1-rpearsonhpe@gmail.com> References: <20220218003543.205799-1-rpearsonhpe@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org Well behaved applications will free all memory allocated by multicast. If this fails rdma-core will detach all qp's from multicast groups when an application terminates. This patch prints a warning and cleans out memory allocated by multicast if both of these fail to occur. Signed-off-by: Bob Pearson --- drivers/infiniband/sw/rxe/rxe.c | 2 ++ drivers/infiniband/sw/rxe/rxe_loc.h | 1 + drivers/infiniband/sw/rxe/rxe_mcast.c | 38 +++++++++++++++++++++++++++ 3 files changed, 41 insertions(+) diff --git a/drivers/infiniband/sw/rxe/rxe.c b/drivers/infiniband/sw/rxe/rxe.c index 3520eb2db685..603b0156f889 100644 --- a/drivers/infiniband/sw/rxe/rxe.c +++ b/drivers/infiniband/sw/rxe/rxe.c @@ -29,6 +29,8 @@ void rxe_dealloc(struct ib_device *ib_dev) rxe_pool_cleanup(&rxe->mr_pool); rxe_pool_cleanup(&rxe->mw_pool); + rxe_cleanup_mcast(rxe); + if (rxe->tfm) crypto_free_shash(rxe->tfm); } diff --git a/drivers/infiniband/sw/rxe/rxe_loc.h b/drivers/infiniband/sw/rxe/rxe_loc.h index 409efeecd581..0bc1b7e2877c 100644 --- a/drivers/infiniband/sw/rxe/rxe_loc.h +++ b/drivers/infiniband/sw/rxe/rxe_loc.h @@ -44,6 +44,7 @@ struct rxe_mcg *rxe_lookup_mcg(struct rxe_dev *rxe, union ib_gid *mgid); int rxe_attach_mcast(struct ib_qp *ibqp, union ib_gid *mgid, u16 mlid); int rxe_detach_mcast(struct ib_qp *ibqp, union ib_gid *mgid, u16 mlid); void rxe_cleanup_mcg(struct kref *kref); +void rxe_cleanup_mcast(struct rxe_dev *rxe); /* rxe_mmap.c */ struct rxe_mmap_info { diff --git a/drivers/infiniband/sw/rxe/rxe_mcast.c b/drivers/infiniband/sw/rxe/rxe_mcast.c index 4935fe5c5868..447d78bea28b 100644 --- a/drivers/infiniband/sw/rxe/rxe_mcast.c +++ b/drivers/infiniband/sw/rxe/rxe_mcast.c @@ -388,3 +388,41 @@ int rxe_detach_mcast(struct ib_qp *ibqp, union ib_gid *mgid, u16 mlid) return rxe_detach_mcg(rxe, qp, mgid); } + +/** + * rxe_cleanup_mcast - cleanup all resources still held by mcast + * @rxe: rxe object + * + * Called when rxe device is unloaded. Walk red-black tree to + * find all mcg's and then walk mcg->qp_list to find all mca's and + * free them. + * + * This is belt and suspenders. These should have been recovered + * already by the application else rdma-core. + */ +void rxe_cleanup_mcast(struct rxe_dev *rxe) +{ + struct rb_root *root = &rxe->mcg_tree; + struct rb_node *node, *next; + struct rxe_mcg *mcg; + struct rxe_mca *mca, *tmp; + + if (RB_EMPTY_ROOT(root)) + return; /* expected behavior */ + + pr_warn("RDMA/core bug: Recovering leaked multicast resources\n"); + + for (node = rb_first(root); node; node = next) { + next = rb_next(node); + mcg = rb_entry(node, typeof(*mcg), node); + + spin_lock_bh(&rxe->mcg_lock); + list_for_each_entry_safe(mca, tmp, &mcg->qp_list, qp_list) + kfree(mca); + + __rxe_remove_mcg(mcg); + spin_unlock_bh(&rxe->mcg_lock); + + kfree(mcg); + } +} From patchwork Fri Feb 18 00:35:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bob Pearson X-Patchwork-Id: 12750828 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 3A683C433F5 for ; Fri, 18 Feb 2022 00:36:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229734AbiBRAg6 (ORCPT ); Thu, 17 Feb 2022 19:36:58 -0500 Received: from gmail-smtp-in.l.google.com ([23.128.96.19]:33910 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230072AbiBRAg5 (ORCPT ); Thu, 17 Feb 2022 19:36:57 -0500 Received: from mail-oi1-x22b.google.com (mail-oi1-x22b.google.com [IPv6:2607:f8b0:4864:20::22b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A4A882C11F for ; Thu, 17 Feb 2022 16:36:42 -0800 (PST) Received: by mail-oi1-x22b.google.com with SMTP id 4so1390789oil.11 for ; Thu, 17 Feb 2022 16:36:42 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=CtZA+JkSi3WFhaVptCJyn0Ywy6jNakeNMbN8MYs1F0U=; b=GWC0UAgaF+6Epl/7G9JBJBb6DRUDYe9yBT0F3sFTg1H+QfRvqo9aTDoLjdTm7ZMCsA ZbGHxd9EusDYwj09cOtW8FJAxalaOrG5JUztwFxTV4ufcmZqoOxEN/WItCn02UhqdKW8 vm9KQaqeLUoyykjmATUksfjjb2WfikoO81BIY2hbrLWNgmR5ec3vpi7gqEiJwViMi7Hb LiJd+hjX+2JK9q5ZlsY/qiEzXr1qeonj5pC0E2fcrvH6ue2lWv83VE4giTr9hoadbman GNWIboQVyma9vSauTr/hYlKjL1WSqySs1FKPfiq86z8s8rOHlKka52Op+kMDtXTisZoM MixA== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=CtZA+JkSi3WFhaVptCJyn0Ywy6jNakeNMbN8MYs1F0U=; b=eIL/F4yi6zF711J4r6bA8FTuYxK52+1+UP+gBfKeiVmCS/dhxZQfjg9tai/NUOYrTC ZSj0cC7a3S9YWhu5c+APbrk3ANroo8YMc2IwwBonWQckijQkJyGqMW5NCNQB8ZPQsvGP nvcOTU6NQZRiuEo5kovsEpZdCpVazGLqgoaEUSG6wJCXJo11y/h4HnhiYwdzkg+niDFy ZB4H0qa1v+eU1U8aNeB4pCNPxmLR3YarTu8QeCX8Ml8Qiok5SmcUD2vMaCjMbZO/bGHb utyk5TJafwiLUnF3YdXVf3XHcZg4tkMPtpRK62dMemqSDB0XvF7cq6HZ2ZceNzG7mupT WKJA== X-Gm-Message-State: AOAM530BONVcus9fC+6GHnmTfgKotJoBSi3xHk6juofqzxJ5Tjfh/15D wV6Oo2wRn1QrT6LLdPzGitQ= X-Google-Smtp-Source: ABdhPJzLwoXsXoJFYquz2K1PwqsIDOz9sQl7409tdfcTvNIKXZ2DhqrhYWZbEa3Uvef9+NS1J86Pdw== X-Received: by 2002:a05:6808:1301:b0:2ce:6ee7:2cfb with SMTP id y1-20020a056808130100b002ce6ee72cfbmr3735541oiv.297.1645144602078; Thu, 17 Feb 2022 16:36:42 -0800 (PST) Received: from ubuntu-21.tx.rr.com (2603-8081-140c-1a00-1772-15fa-cf3f-3cd5.res6.spectrum.com. [2603:8081:140c:1a00:1772:15fa:cf3f:3cd5]) by smtp.googlemail.com with ESMTPSA id t31sm19698299oaa.9.2022.02.17.16.36.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Feb 2022 16:36:41 -0800 (PST) From: Bob Pearson To: jgg@nvidia.com, zyjzyj2000@gmail.com, linux-rdma@vger.kernel.org Cc: Bob Pearson Subject: [PATCH for-next v12 2/6] RDMA/rxe: Collect mca init code in a subroutine Date: Thu, 17 Feb 2022 18:35:40 -0600 Message-Id: <20220218003543.205799-3-rpearsonhpe@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220218003543.205799-1-rpearsonhpe@gmail.com> References: <20220218003543.205799-1-rpearsonhpe@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org Collect initialization code for struct rxe_mca into a subroutine, __rxe_init_mca(), to cleanup rxe_attach_mcg() in rxe_mcast.c. Check limit on total number of attached qp's. Signed-off-by: Bob Pearson --- drivers/infiniband/sw/rxe/rxe_mcast.c | 58 ++++++++++++++++++++------- drivers/infiniband/sw/rxe/rxe_verbs.h | 1 + 2 files changed, 44 insertions(+), 15 deletions(-) diff --git a/drivers/infiniband/sw/rxe/rxe_mcast.c b/drivers/infiniband/sw/rxe/rxe_mcast.c index 447d78bea28b..53db0984a9a1 100644 --- a/drivers/infiniband/sw/rxe/rxe_mcast.c +++ b/drivers/infiniband/sw/rxe/rxe_mcast.c @@ -259,6 +259,46 @@ static void rxe_destroy_mcg(struct rxe_mcg *mcg) spin_unlock_irqrestore(&mcg->rxe->mcg_lock, flags); } +/** + * __rxe_init_mca - initialize a new mca holding lock + * @qp: qp object + * @mcg: mcg object + * @mca: empty space for new mca + * + * Context: caller must hold references on qp and mcg, rxe->mcg_lock + * and pass memory for new mca + * + * Returns: 0 on success else an error + */ +static int __rxe_init_mca(struct rxe_qp *qp, struct rxe_mcg *mcg, + struct rxe_mca *mca) +{ + struct rxe_dev *rxe = to_rdev(qp->ibqp.device); + int n; + + n = atomic_inc_return(&rxe->mcg_attach); + if (n > rxe->attr.max_total_mcast_qp_attach) { + atomic_dec(&rxe->mcg_attach); + return -ENOMEM; + } + + n = atomic_inc_return(&mcg->qp_num); + if (n > rxe->attr.max_mcast_qp_attach) { + atomic_dec(&mcg->qp_num); + atomic_dec(&rxe->mcg_attach); + return -ENOMEM; + } + + atomic_inc(&qp->mcg_num); + + rxe_add_ref(qp); + mca->qp = qp; + + list_add_tail(&mca->qp_list, &mcg->qp_list); + + return 0; +} + static int rxe_attach_mcg(struct rxe_dev *rxe, struct rxe_qp *qp, struct rxe_mcg *mcg) { @@ -291,22 +331,9 @@ static int rxe_attach_mcg(struct rxe_dev *rxe, struct rxe_qp *qp, } } - /* check limits after checking if already attached */ - if (atomic_inc_return(&mcg->qp_num) > rxe->attr.max_mcast_qp_attach) { - atomic_dec(&mcg->qp_num); + err = __rxe_init_mca(qp, mcg, mca); + if (err) kfree(mca); - err = -ENOMEM; - goto out; - } - - /* protect pointer to qp in mca */ - rxe_add_ref(qp); - mca->qp = qp; - - atomic_inc(&qp->mcg_num); - list_add(&mca->qp_list, &mcg->qp_list); - - err = 0; out: spin_unlock_irqrestore(&rxe->mcg_lock, flags); return err; @@ -329,6 +356,7 @@ static int rxe_detach_mcg(struct rxe_dev *rxe, struct rxe_qp *qp, if (mca->qp == qp) { list_del(&mca->qp_list); atomic_dec(&qp->mcg_num); + atomic_dec(&rxe->mcg_attach); rxe_drop_ref(qp); /* if the number of qp's attached to the diff --git a/drivers/infiniband/sw/rxe/rxe_verbs.h b/drivers/infiniband/sw/rxe/rxe_verbs.h index 20fe3ee6589d..6b15251ff67a 100644 --- a/drivers/infiniband/sw/rxe/rxe_verbs.h +++ b/drivers/infiniband/sw/rxe/rxe_verbs.h @@ -401,6 +401,7 @@ struct rxe_dev { spinlock_t mcg_lock; struct rb_root mcg_tree; atomic_t mcg_num; + atomic_t mcg_attach; spinlock_t pending_lock; /* guard pending_mmaps */ struct list_head pending_mmaps; From patchwork Fri Feb 18 00:35:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bob Pearson X-Patchwork-Id: 12750826 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 C91A5C43217 for ; Fri, 18 Feb 2022 00:36:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230023AbiBRAg7 (ORCPT ); Thu, 17 Feb 2022 19:36:59 -0500 Received: from gmail-smtp-in.l.google.com ([23.128.96.19]:33978 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229931AbiBRAg6 (ORCPT ); Thu, 17 Feb 2022 19:36:58 -0500 Received: from mail-oi1-x231.google.com (mail-oi1-x231.google.com [IPv6:2607:f8b0:4864:20::231]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 462BD31200 for ; Thu, 17 Feb 2022 16:36:43 -0800 (PST) Received: by mail-oi1-x231.google.com with SMTP id x193so1473019oix.0 for ; Thu, 17 Feb 2022 16:36:43 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=bBKd18xtZScg/tYiH1GX5Afq48PxutZy5Io/riDzpx8=; b=X50DzE2BdT0yBCZ59/liU/zAcKsB0XF7jNeydwqkRkQRJL9+tKaIrww7oRDZbX+MPl VR3nigzZTXZXOKTigOitW2bRbu4zu+dznMRg9KN/e7f2Rxbmaxu36PxzTk8eLsT9Dn6X 5BGrG3qyMlReAH9A3T0vgK6/mJdTEkfc+Jue+Ku1UmGrfJcBlX/MtOWMTCZoveT3/bKr aGPu5i4KlGgEue8BjXMCzfVd5iVrW8JlwNeEAFPRMZfKZQcpCcfevmk6x+6WyckBHdTV VuW3iXdjXPrz4BfEhrWlTpmR4hRvgOxCbf8hcbUXYrG0homt8uh4jcBqmbwUxi5AQhcw QAXA== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=bBKd18xtZScg/tYiH1GX5Afq48PxutZy5Io/riDzpx8=; b=NIa2/sGgOFqdh9V1Wc83YM4j8KXiM+loYYxilQiwGF5QVhnWe8+iS7tGADwU25ELpZ bkxq8/qnEMnIW2hPheYnrDNomNnWFZ+wGJ5480lqXKWjTfeNtui/6e1CcMYXhTCHOwtV 0E4YDWUf9BSNjPgjVMXaouJzaL+YnR+Z/Cd4lipk9QfHli6MFkGAMdwVfvCMA5rMCaKV I+WdVku2T3V2o6G58iRHSmxdx7k+2LAnPVglIPGsjj0xBdYKKEDUuFEgmchmLrQEYSbP AFcPPj3r4CxIJ4ml+D3FciBs0Af6zGhgYPq5m0Nqw41oPqfPMiprfFEMP2NJVwcP1kIp kbYA== X-Gm-Message-State: AOAM531k+1AtgSmKb55lPClmSLjZNqIbY6IDiFkmXNFblC8uKAgU8iyp syp/c93wHTaJgtvh2Ma6T/Q= X-Google-Smtp-Source: ABdhPJySXQdi0b4mcRbL0ng1BnT5Dgg0m9E1MTAvhr4iGUjRSrZSkrERbkjd0bBbur/3Dno3T5cnYQ== X-Received: by 2002:a05:6808:2108:b0:2d4:3ad1:6625 with SMTP id r8-20020a056808210800b002d43ad16625mr4027860oiw.74.1645144602664; Thu, 17 Feb 2022 16:36:42 -0800 (PST) Received: from ubuntu-21.tx.rr.com (2603-8081-140c-1a00-1772-15fa-cf3f-3cd5.res6.spectrum.com. [2603:8081:140c:1a00:1772:15fa:cf3f:3cd5]) by smtp.googlemail.com with ESMTPSA id t31sm19698299oaa.9.2022.02.17.16.36.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Feb 2022 16:36:42 -0800 (PST) From: Bob Pearson To: jgg@nvidia.com, zyjzyj2000@gmail.com, linux-rdma@vger.kernel.org Cc: Bob Pearson Subject: [PATCH for-next v12 3/6] RDMA/rxe: Collect cleanup mca code in a subroutine Date: Thu, 17 Feb 2022 18:35:41 -0600 Message-Id: <20220218003543.205799-4-rpearsonhpe@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220218003543.205799-1-rpearsonhpe@gmail.com> References: <20220218003543.205799-1-rpearsonhpe@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org Collect cleanup code for struct rxe_mca into a subroutine, __rxe_cleanup_mca() called in rxe_detach_mcg() in rxe_mcast.c. Signed-off-by: Bob Pearson --- drivers/infiniband/sw/rxe/rxe_mcast.c | 41 +++++++++++++++++---------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/drivers/infiniband/sw/rxe/rxe_mcast.c b/drivers/infiniband/sw/rxe/rxe_mcast.c index 53db0984a9a1..0f0655e81d40 100644 --- a/drivers/infiniband/sw/rxe/rxe_mcast.c +++ b/drivers/infiniband/sw/rxe/rxe_mcast.c @@ -339,13 +339,31 @@ static int rxe_attach_mcg(struct rxe_dev *rxe, struct rxe_qp *qp, return err; } +/** + * __rxe_cleanup_mca - cleanup mca object holding lock + * @mca: mca object + * @mcg: mcg object + * + * Context: caller must hold a reference to mcg and rxe->mcg_lock + */ +static void __rxe_cleanup_mca(struct rxe_mca *mca, struct rxe_mcg *mcg) +{ + list_del(&mca->qp_list); + + atomic_dec(&mcg->qp_num); + atomic_dec(&mcg->rxe->mcg_attach); + atomic_dec(&mca->qp->mcg_num); + rxe_drop_ref(mca->qp); + + kfree(mca); +} + static int rxe_detach_mcg(struct rxe_dev *rxe, struct rxe_qp *qp, union ib_gid *mgid) { struct rxe_mcg *mcg; struct rxe_mca *mca, *tmp; unsigned long flags; - int err; mcg = rxe_lookup_mcg(rxe, mgid); if (!mcg) @@ -354,37 +372,30 @@ static int rxe_detach_mcg(struct rxe_dev *rxe, struct rxe_qp *qp, spin_lock_irqsave(&rxe->mcg_lock, flags); list_for_each_entry_safe(mca, tmp, &mcg->qp_list, qp_list) { if (mca->qp == qp) { - list_del(&mca->qp_list); - atomic_dec(&qp->mcg_num); - atomic_dec(&rxe->mcg_attach); - rxe_drop_ref(qp); + __rxe_cleanup_mca(mca, mcg); /* if the number of qp's attached to the * mcast group falls to zero go ahead and * tear it down. This will not free the * object since we are still holding a ref - * from the get key above. + * from the get key above */ - if (atomic_dec_return(&mcg->qp_num) <= 0) + if (atomic_read(&mcg->qp_num) <= 0) __rxe_destroy_mcg(mcg); /* drop the ref from get key. This will free the * object if qp_num is zero. */ kref_put(&mcg->ref_cnt, rxe_cleanup_mcg); - kfree(mca); - err = 0; - goto out_unlock; + + spin_unlock_irqrestore(&rxe->mcg_lock, flags); + return 0; } } /* we didn't find the qp on the list */ - kref_put(&mcg->ref_cnt, rxe_cleanup_mcg); - err = -EINVAL; - -out_unlock: spin_unlock_irqrestore(&rxe->mcg_lock, flags); - return err; + return -EINVAL; } int rxe_attach_mcast(struct ib_qp *ibqp, union ib_gid *mgid, u16 mlid) From patchwork Fri Feb 18 00:35:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bob Pearson X-Patchwork-Id: 12750830 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 8C97AC433FE for ; Fri, 18 Feb 2022 00:36:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230019AbiBRAhG (ORCPT ); Thu, 17 Feb 2022 19:37:06 -0500 Received: from gmail-smtp-in.l.google.com ([23.128.96.19]:34842 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230146AbiBRAhF (ORCPT ); Thu, 17 Feb 2022 19:37:05 -0500 Received: from mail-ot1-x336.google.com (mail-ot1-x336.google.com [IPv6:2607:f8b0:4864:20::336]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C456B31237 for ; Thu, 17 Feb 2022 16:36:45 -0800 (PST) Received: by mail-ot1-x336.google.com with SMTP id a7-20020a9d5c87000000b005ad1467cb59so912152oti.5 for ; Thu, 17 Feb 2022 16:36:45 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=h8YV6G4SA28VG3l3LlgZPG/Xvx1jl/CM5kjGq324Qq8=; b=errBIHRt9ZtTVzrpddJjCAbZp/7vDxqAmdsbur4BwpdJwRg8pfsFQ7ArpZlFnL4VL6 RiI6Uu6cIsmSnxu81JqDHKy5S6ujS+riY8kqJIRx9CBlGnI6SjcQYQ8TI2ysFJCDyPLi w0UohUGINBac9j/fj/ajwQRP+9x1AqXSYiRCtN7PN0MClQDdxbQhCx5ol1xsVu+ioXQG UgDN3aNiuecCD6tzKM7Cwy2HCuTMtfX3c8TNPAS3AW/xQKGbbbutWtrkZwBbHeFlpQ2f JHXSSiPbFs9zDPjQ5pImGB0x3hAOgKDb9VjU+tLq19Nl5PDqSnFQNyQUQhewJBudl/qu 4wsQ== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=h8YV6G4SA28VG3l3LlgZPG/Xvx1jl/CM5kjGq324Qq8=; b=P75dHDXfNRWsxhawXAYQLLQJ7uTDJxcNE24+vCEaLkpjQrXENXE7+HCNCiTm1Zn4Uu vJluwaEDneHMH+nxogOWcl0k/Ob3fO+S7UYnOhucc14GzSCnqVWSC0CPjJ1Ziy4v4DDw E7sluI9lLzYOY/5w20oRrVwhYgSA3cf4lj/4N445QrwByD586xOh0v8Ln2Z+tZGk4r3r E18y//PsqW+RIzoWv+QHPBYKBPn12kECBZ51a+HwAQ2VPXwl+QsZWbK+6dsMFHvH1TwH iJg5ov/AAoU7L9JylT7m6u3ggWRVV0OJG3BQBYOcg2OpXfEvE9s2LEK9484SXniL2M1T MP8Q== X-Gm-Message-State: AOAM532f9/9oIrZC8gm1focAqh6vJJzM7AXyqQWoOosDcI0y+YmDqVK8 0zVyKyJ0tE/W2oyfWGHqQDI= X-Google-Smtp-Source: ABdhPJxwVnqtd6/5onAKUHdGsXMS4Uc1Ewg3v6xwoaG/qsSPmMoRtMh9fqvCgHB3w9tBckm7MdFylw== X-Received: by 2002:a9d:1283:0:b0:5ad:1073:1436 with SMTP id g3-20020a9d1283000000b005ad10731436mr1766835otg.370.1645144603577; Thu, 17 Feb 2022 16:36:43 -0800 (PST) Received: from ubuntu-21.tx.rr.com (2603-8081-140c-1a00-1772-15fa-cf3f-3cd5.res6.spectrum.com. [2603:8081:140c:1a00:1772:15fa:cf3f:3cd5]) by smtp.googlemail.com with ESMTPSA id t31sm19698299oaa.9.2022.02.17.16.36.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Feb 2022 16:36:43 -0800 (PST) From: Bob Pearson To: jgg@nvidia.com, zyjzyj2000@gmail.com, linux-rdma@vger.kernel.org Cc: Bob Pearson Subject: [PATCH for-next v12 4/6] RDMA/rxe: Cleanup rxe_mcast.c Date: Thu, 17 Feb 2022 18:35:42 -0600 Message-Id: <20220218003543.205799-5-rpearsonhpe@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220218003543.205799-1-rpearsonhpe@gmail.com> References: <20220218003543.205799-1-rpearsonhpe@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org Finish adding subroutine comment headers to subroutines in rxe_mcast.c. Make minor api change cleanups. Signed-off-by: Bob Pearson --- drivers/infiniband/sw/rxe/rxe_mcast.c | 97 +++++++++++++++++++++------ 1 file changed, 78 insertions(+), 19 deletions(-) diff --git a/drivers/infiniband/sw/rxe/rxe_mcast.c b/drivers/infiniband/sw/rxe/rxe_mcast.c index 0f0655e81d40..349a6fac2fcc 100644 --- a/drivers/infiniband/sw/rxe/rxe_mcast.c +++ b/drivers/infiniband/sw/rxe/rxe_mcast.c @@ -1,12 +1,33 @@ // SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB /* + * Copyright (c) 2022 Hewlett Packard Enterprise, Inc. All rights reserved. * Copyright (c) 2016 Mellanox Technologies Ltd. All rights reserved. * Copyright (c) 2015 System Fabric Works, Inc. All rights reserved. */ +/* + * rxe_mcast.c implements driver support for multicast transport. + * It is based on two data structures struct rxe_mcg ('mcg') and + * struct rxe_mca ('mca'). An mcg is allocated each time a qp is + * attached to a new mgid for the first time. These are indexed by + * a red-black tree using the mgid. This data structure is searched + * for the mcg when a multicast packet is received and when another + * qp is attached to the same mgid. It is cleaned up when the last qp + * is detached from the mcg. Each time a qp is attached to an mcg an + * mca is created. It holds a pointer to the qp and is added to a list + * of qp's that are attached to the mcg. The qp_list is used to replicate + * mcast packets in the rxe receive path. + */ + #include "rxe.h" -#include "rxe_loc.h" +/** + * rxe_mcast_add - add multicast address to rxe device + * @rxe: rxe device object + * @mgid: multicast address as a gid + * + * Returns 0 on success else an error + */ static int rxe_mcast_add(struct rxe_dev *rxe, union ib_gid *mgid) { unsigned char ll_addr[ETH_ALEN]; @@ -16,6 +37,13 @@ static int rxe_mcast_add(struct rxe_dev *rxe, union ib_gid *mgid) return dev_mc_add(rxe->ndev, ll_addr); } +/** + * rxe_mcast_delete - delete multicast address from rxe device + * @rxe: rxe device object + * @mgid: multicast address as a gid + * + * Returns 0 on success else an error + */ static int rxe_mcast_delete(struct rxe_dev *rxe, union ib_gid *mgid) { unsigned char ll_addr[ETH_ALEN]; @@ -216,7 +244,7 @@ static struct rxe_mcg *rxe_get_mcg(struct rxe_dev *rxe, union ib_gid *mgid) /** * rxe_cleanup_mcg - cleanup mcg for kref_put - * @kref: + * @kref: struct kref embnedded in mcg */ void rxe_cleanup_mcg(struct kref *kref) { @@ -299,9 +327,17 @@ static int __rxe_init_mca(struct rxe_qp *qp, struct rxe_mcg *mcg, return 0; } -static int rxe_attach_mcg(struct rxe_dev *rxe, struct rxe_qp *qp, - struct rxe_mcg *mcg) +/** + * rxe_attach_mcg - attach qp to mcg if not already attached + * @qp: qp object + * @mcg: mcg object + * + * Context: caller must hold reference on qp and mcg. + * Returns: 0 on success else an error + */ +static int rxe_attach_mcg(struct rxe_mcg *mcg, struct rxe_qp *qp) { + struct rxe_dev *rxe = mcg->rxe; struct rxe_mca *mca, *tmp; unsigned long flags; int err; @@ -358,17 +394,19 @@ static void __rxe_cleanup_mca(struct rxe_mca *mca, struct rxe_mcg *mcg) kfree(mca); } -static int rxe_detach_mcg(struct rxe_dev *rxe, struct rxe_qp *qp, - union ib_gid *mgid) +/** + * rxe_detach_mcg - detach qp from mcg + * @mcg: mcg object + * @qp: qp object + * + * Returns: 0 on success else an error if qp is not attached. + */ +static int rxe_detach_mcg(struct rxe_mcg *mcg, struct rxe_qp *qp) { - struct rxe_mcg *mcg; + struct rxe_dev *rxe = mcg->rxe; struct rxe_mca *mca, *tmp; unsigned long flags; - mcg = rxe_lookup_mcg(rxe, mgid); - if (!mcg) - return -EINVAL; - spin_lock_irqsave(&rxe->mcg_lock, flags); list_for_each_entry_safe(mca, tmp, &mcg->qp_list, qp_list) { if (mca->qp == qp) { @@ -378,16 +416,11 @@ static int rxe_detach_mcg(struct rxe_dev *rxe, struct rxe_qp *qp, * mcast group falls to zero go ahead and * tear it down. This will not free the * object since we are still holding a ref - * from the get key above + * from the caller */ if (atomic_read(&mcg->qp_num) <= 0) __rxe_destroy_mcg(mcg); - /* drop the ref from get key. This will free the - * object if qp_num is zero. - */ - kref_put(&mcg->ref_cnt, rxe_cleanup_mcg); - spin_unlock_irqrestore(&rxe->mcg_lock, flags); return 0; } @@ -398,6 +431,14 @@ static int rxe_detach_mcg(struct rxe_dev *rxe, struct rxe_qp *qp, return -EINVAL; } +/** + * rxe_attach_mcast - attach qp to multicast group (see IBA-11.3.1) + * @ibqp: (IB) qp object + * @mgid: multicast IP address + * @mlid: multicast LID, ignored for RoCEv2 (see IBA-A17.5.6) + * + * Returns: 0 on success else an errno + */ int rxe_attach_mcast(struct ib_qp *ibqp, union ib_gid *mgid, u16 mlid) { int err; @@ -410,22 +451,40 @@ int rxe_attach_mcast(struct ib_qp *ibqp, union ib_gid *mgid, u16 mlid) if (IS_ERR(mcg)) return PTR_ERR(mcg); - err = rxe_attach_mcg(rxe, qp, mcg); + err = rxe_attach_mcg(mcg, qp); /* if we failed to attach the first qp to mcg tear it down */ if (atomic_read(&mcg->qp_num) == 0) rxe_destroy_mcg(mcg); kref_put(&mcg->ref_cnt, rxe_cleanup_mcg); + return err; } +/** + * rxe_detach_mcast - detach qp from multicast group (see IBA-11.3.2) + * @ibqp: address of (IB) qp object + * @mgid: multicast IP address + * @mlid: multicast LID, ignored for RoCEv2 (see IBA-A17.5.6) + * + * Returns: 0 on success else an errno + */ int rxe_detach_mcast(struct ib_qp *ibqp, union ib_gid *mgid, u16 mlid) { struct rxe_dev *rxe = to_rdev(ibqp->device); struct rxe_qp *qp = to_rqp(ibqp); + struct rxe_mcg *mcg; + int err; + + mcg = rxe_lookup_mcg(rxe, mgid); + if (!mcg) + return -EINVAL; - return rxe_detach_mcg(rxe, qp, mgid); + err = rxe_detach_mcg(mcg, qp); + kref_put(&mcg->ref_cnt, rxe_cleanup_mcg); + + return err; } /** From patchwork Fri Feb 18 00:35:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bob Pearson X-Patchwork-Id: 12750829 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 7D463C433EF for ; Fri, 18 Feb 2022 00:36:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229931AbiBRAhF (ORCPT ); Thu, 17 Feb 2022 19:37:05 -0500 Received: from gmail-smtp-in.l.google.com ([23.128.96.19]:34696 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230019AbiBRAhE (ORCPT ); Thu, 17 Feb 2022 19:37:04 -0500 Received: from mail-oi1-x22c.google.com (mail-oi1-x22c.google.com [IPv6:2607:f8b0:4864:20::22c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 107743121E for ; Thu, 17 Feb 2022 16:36:45 -0800 (PST) Received: by mail-oi1-x22c.google.com with SMTP id v25so1431958oiv.2 for ; Thu, 17 Feb 2022 16:36:45 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=nHH2kN1qaHun2fFYMfE2C2Cg4rCPKgUgoK974Y7RcTA=; b=ob0eht6Ax3rIuGVbh+3jZSXuqTwhmPwKYowK4scHDgE+hAK4CcD5DelsJbKosckwE1 9GUK3EKw/mIzGOA6P8uXS5e8v4HqXVJnDSnbSPtawty1XNF93QlFRwfKhr/35ol7JJNc e/xn57EV37YXSD0VItXc0OpnbH9NW8/MHltnvf+imzhh4WK9jZYFMHP1jWqd/LooWH6P vykBeNdvtiiotZY5cK4HKUTnziQzVYW8AqXRHeJ+nswglZ0WFjzGyRjfTfdyon71dYlL FatJFcx619ciD59wJjnz3SPSEvXobP2nAgCmJcuRmllE3un2N6ZtIcewzOiSa2s95z45 FIgg== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=nHH2kN1qaHun2fFYMfE2C2Cg4rCPKgUgoK974Y7RcTA=; b=YswVqrJfXczhvWrnd6lxwIeR+5CWTq9kCFH+bAIGxsutuRJ7NBsXaeFjEgXqEviyWa fj7aAtpiq4CsCKPcFRq0P/o6qi+/K0g6I0EX/xvjHMoJVHTdnb9bbtqFkl3R6kEcT7PC ES43BUB+3bgYibetZd06URalleLutF7fFjYKunI38IMMNA8g5Uq1Le4y//UhNBvo8cVp VW66ARj2PQm58NMR+n6JuyV4I3HPxBjrtRXWjmP3EjfnEM9Zl/ho6oczgoojcyKRLvHG ewxJDZXVAnchTUubFip50Lc1V8fsGmr04XtM4JaQwRf1/tmtkM3RiLyWnTvzlfxukU87 VVNA== X-Gm-Message-State: AOAM533xPXG9RSvqmTsVjnXwNUD7F6Gst1jL+UGjUeDOsuZ7yCvAiTO7 DfLTvQI/TkZvh1lgBpEf3vCYu4k5V7M= X-Google-Smtp-Source: ABdhPJzBym5ObBoZEe1dEIkG4sz8M5e9Wxays/vGZxPchv6Mm5RoC6J8L7pkajpDeaapCsz4NCm18A== X-Received: by 2002:a05:6808:1926:b0:2ce:6a75:b7f2 with SMTP id bf38-20020a056808192600b002ce6a75b7f2mr2332288oib.185.1645144604345; Thu, 17 Feb 2022 16:36:44 -0800 (PST) Received: from ubuntu-21.tx.rr.com (2603-8081-140c-1a00-1772-15fa-cf3f-3cd5.res6.spectrum.com. [2603:8081:140c:1a00:1772:15fa:cf3f:3cd5]) by smtp.googlemail.com with ESMTPSA id t31sm19698299oaa.9.2022.02.17.16.36.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Feb 2022 16:36:44 -0800 (PST) From: Bob Pearson To: jgg@nvidia.com, zyjzyj2000@gmail.com, linux-rdma@vger.kernel.org Cc: Bob Pearson Subject: [PATCH for-next v12 5/6] RDMA/rxe: For mcast copy qp list to temp array Date: Thu, 17 Feb 2022 18:35:43 -0600 Message-Id: <20220218003543.205799-6-rpearsonhpe@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220218003543.205799-1-rpearsonhpe@gmail.com> References: <20220218003543.205799-1-rpearsonhpe@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org Currently rxe_rcv_mcast_pkt performs most of its work under the rxe->mcg_lock and calls into rxe_rcv which queues the packets to the responder and completer tasklets holding the lock which is a very bad idea. This patch walks the qp_list in mcg and copies the qp addresses to a temporary array under the lock but does the rest of the work without holding the lock. The critical section is now very small. Signed-off-by: Bob Pearson --- drivers/infiniband/sw/rxe/rxe_recv.c | 103 +++++++++++++++++---------- 1 file changed, 64 insertions(+), 39 deletions(-) diff --git a/drivers/infiniband/sw/rxe/rxe_recv.c b/drivers/infiniband/sw/rxe/rxe_recv.c index 53924453abef..9b21cbb22602 100644 --- a/drivers/infiniband/sw/rxe/rxe_recv.c +++ b/drivers/infiniband/sw/rxe/rxe_recv.c @@ -232,11 +232,15 @@ static inline void rxe_rcv_pkt(struct rxe_pkt_info *pkt, struct sk_buff *skb) static void rxe_rcv_mcast_pkt(struct rxe_dev *rxe, struct sk_buff *skb) { + struct sk_buff *skb_copy; struct rxe_pkt_info *pkt = SKB_TO_PKT(skb); + struct rxe_pkt_info *pkt_copy; struct rxe_mcg *mcg; struct rxe_mca *mca; struct rxe_qp *qp; + struct rxe_qp **qp_array; union ib_gid dgid; + int n, nmax; int err; if (skb->protocol == htons(ETH_P_IP)) @@ -248,68 +252,89 @@ static void rxe_rcv_mcast_pkt(struct rxe_dev *rxe, struct sk_buff *skb) /* lookup mcast group corresponding to mgid, takes a ref */ mcg = rxe_lookup_mcg(rxe, &dgid); if (!mcg) - goto drop; /* mcast group not registered */ + goto err_drop; /* mcast group not registered */ + + /* this is the current number of qp's attached to mcg plus a + * little room in case new qp's are attached between here + * and when we finish walking the qp list. If someone can + * attach more than 4 new qp's we will miss forwarding + * packets to those qp's. This is actually OK since UD is + * a unreliable service. + */ + nmax = atomic_read(&mcg->qp_num) + 4; + qp_array = kmalloc_array(nmax, sizeof(qp), GFP_KERNEL); + n = 0; spin_lock_bh(&rxe->mcg_lock); - - /* this is unreliable datagram service so we let - * failures to deliver a multicast packet to a - * single QP happen and just move on and try - * the rest of them on the list - */ list_for_each_entry(mca, &mcg->qp_list, qp_list) { - qp = mca->qp; + /* protect the qp pointers in the list */ + rxe_add_ref(mca->qp); + qp_array[n++] = mca->qp; + if (n == nmax) + break; + } + spin_unlock_bh(&rxe->mcg_lock); + nmax = n; + kref_put(&mcg->ref_cnt, rxe_cleanup_mcg); - /* validate qp for incoming packet */ + for (n = 0; n < nmax; n++) { + qp = qp_array[n]; + + /* since this is an unreliable transport if + * one of the qp's fails to pass these checks + * just don't forward a packet and continue + * on to the other qp's. If there aren't any + * drop the skb + */ err = check_type_state(rxe, pkt, qp); - if (err) + if (err) { + rxe_drop_ref(qp); + if (n == nmax - 1) + goto err_free; continue; + } err = check_keys(rxe, pkt, bth_qpn(pkt), qp); - if (err) + if (err) { + rxe_drop_ref(qp); + if (n == nmax - 1) + goto err_free; continue; + } - /* for all but the last QP create a new clone of the - * skb and pass to the QP. Pass the original skb to - * the last QP in the list. + /* for all but the last qp create a new copy(clone) + * of the skb and pass to the qp. Pass the original + * skb to the last qp in the list unless it failed + * checks above */ - if (mca->qp_list.next != &mcg->qp_list) { - struct sk_buff *cskb; - struct rxe_pkt_info *cpkt; - - cskb = skb_clone(skb, GFP_ATOMIC); - if (unlikely(!cskb)) + if (n < nmax - 1) { + skb_copy = skb_clone(skb, GFP_KERNEL); + if (unlikely(!skb_copy)) { + rxe_drop_ref(qp); continue; + } if (WARN_ON(!ib_device_try_get(&rxe->ib_dev))) { - kfree_skb(cskb); - break; + kfree_skb(skb_copy); + rxe_drop_ref(qp); + continue; } - cpkt = SKB_TO_PKT(cskb); - cpkt->qp = qp; - rxe_add_ref(qp); - rxe_rcv_pkt(cpkt, cskb); + pkt_copy = SKB_TO_PKT(skb_copy); + pkt_copy->qp = qp; + rxe_rcv_pkt(pkt_copy, skb_copy); } else { pkt->qp = qp; - rxe_add_ref(qp); rxe_rcv_pkt(pkt, skb); - skb = NULL; /* mark consumed */ } } - spin_unlock_bh(&rxe->mcg_lock); - - kref_put(&mcg->ref_cnt, rxe_cleanup_mcg); - - if (likely(!skb)) - return; - - /* This only occurs if one of the checks fails on the last - * QP in the list above - */ + kfree(qp_array); + return; -drop: +err_free: + kfree(qp_array); +err_drop: kfree_skb(skb); ib_device_put(&rxe->ib_dev); } From patchwork Fri Feb 18 00:35:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bob Pearson X-Patchwork-Id: 12750831 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 ABC8EC433F5 for ; Fri, 18 Feb 2022 00:36:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230098AbiBRAhH (ORCPT ); Thu, 17 Feb 2022 19:37:07 -0500 Received: from gmail-smtp-in.l.google.com ([23.128.96.19]:34914 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230111AbiBRAhG (ORCPT ); Thu, 17 Feb 2022 19:37:06 -0500 Received: from mail-oo1-xc2f.google.com (mail-oo1-xc2f.google.com [IPv6:2607:f8b0:4864:20::c2f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7636631204 for ; Thu, 17 Feb 2022 16:36:47 -0800 (PST) Received: by mail-oo1-xc2f.google.com with SMTP id p206-20020a4a2fd7000000b0031bfec11983so1625554oop.13 for ; Thu, 17 Feb 2022 16:36:47 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=O3jITvxHsmfjM2foI63paWiJpQ6hbFJZ0L2SyxXtHAA=; b=QEWe+6a0v88BxtXZRQuvkAOVe0VdFyl41Fe1eWq0fzz9yWj14wVXntlgNxvipYdY7N dy0S46H4WkQCsf0xpAEIO6A+DdP6jANaXWZqB5sguE3KQEJzi5yVI95zyCSda11XiFIH gNL735d+d54S58DfEUV4SJjwqTE+6PGbGGBsK+rfIe4DKvt4Iyt6GDPlz3cV+E4kZR6a 3igxfH8snFZBIL5mrWM0mclVb2orwvTgX/8kRJAojU09ibJgyVrOaSpmxSDan2/AMuuJ Zqdu00h2X34EXWpiSC5E8p6y6nls2fdYod5vKg9DCHwmtcSEU2y6xlzFWVHYaNhDFmbd yQZQ== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=O3jITvxHsmfjM2foI63paWiJpQ6hbFJZ0L2SyxXtHAA=; b=dSmmGngB/UVrxi9E2ClwTwmqGwXBYTc4PEMrczPP0yHTujjuMzTn04cwGVdQw7H0Eq UoUAEvuMa3zZ78Uh9aNb2YyL9YnW/NlSt7Bv9t6RXf3Gxoe/TTOjT3bj9kUvWcsInO7i 3vkLDRqE8eD0aHiOJa/g3WuaBG/xMfkj6l/KSAVbMMqFKi716X+S8aYhsU/lU+KaHnG3 Fgyny2GNQXWLEQIOQHHAr3M++gt0OfuL+Y0seqrHze5LiL2hjEt13NsMTUY0zpqgIQXt mveJBDjEwV+CPYtSIIgLBNtAstkeDFLla5GigMkhxo0vijs8vGdJV2M4QqAHzugYJubn h1tg== X-Gm-Message-State: AOAM531jBGYab1wiXeXGvN9Ut6LWDBlUXy98TbxcC3/+h+vfSc+R207x WJiL4CU0PfFBPuP6HTBrAgo= X-Google-Smtp-Source: ABdhPJz4ly0mRQajTi2TXMMVZVSuSGOQk1d7O9rXBYf1qIhahZbejZT2snsCVDAOWJHVBz/A43jtcA== X-Received: by 2002:a05:6870:d58b:b0:d2:8d1d:c12 with SMTP id u11-20020a056870d58b00b000d28d1d0c12mr3432189oao.108.1645144605115; Thu, 17 Feb 2022 16:36:45 -0800 (PST) Received: from ubuntu-21.tx.rr.com (2603-8081-140c-1a00-1772-15fa-cf3f-3cd5.res6.spectrum.com. [2603:8081:140c:1a00:1772:15fa:cf3f:3cd5]) by smtp.googlemail.com with ESMTPSA id t31sm19698299oaa.9.2022.02.17.16.36.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Feb 2022 16:36:44 -0800 (PST) From: Bob Pearson To: jgg@nvidia.com, zyjzyj2000@gmail.com, linux-rdma@vger.kernel.org Cc: Bob Pearson Subject: [PATCH for-next v12 6/6] RDMA/rxe: Convert mca read locking to RCU Date: Thu, 17 Feb 2022 18:35:44 -0600 Message-Id: <20220218003543.205799-7-rpearsonhpe@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220218003543.205799-1-rpearsonhpe@gmail.com> References: <20220218003543.205799-1-rpearsonhpe@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org Replace spinlock with rcu read locks for read side operations on mca in rxe_recv.c and rxe_mcast.c. Signed-off-by: Bob Pearson --- drivers/infiniband/sw/rxe/rxe_mcast.c | 97 +++++++++++++++++---------- drivers/infiniband/sw/rxe/rxe_recv.c | 6 +- drivers/infiniband/sw/rxe/rxe_verbs.h | 2 + 3 files changed, 67 insertions(+), 38 deletions(-) diff --git a/drivers/infiniband/sw/rxe/rxe_mcast.c b/drivers/infiniband/sw/rxe/rxe_mcast.c index 349a6fac2fcc..2bfec3748e1e 100644 --- a/drivers/infiniband/sw/rxe/rxe_mcast.c +++ b/drivers/infiniband/sw/rxe/rxe_mcast.c @@ -17,6 +17,12 @@ * mca is created. It holds a pointer to the qp and is added to a list * of qp's that are attached to the mcg. The qp_list is used to replicate * mcast packets in the rxe receive path. + * + * The highest performance operations are mca list traversal when + * processing incoming multicast packets which need to be fanned out + * to the attached qp's. This list is protected by RCU locking for read + * operations and a spinlock in the rxe_dev struct for write operations. + * The red-black tree is protected by the same spinlock. */ #include "rxe.h" @@ -288,7 +294,7 @@ static void rxe_destroy_mcg(struct rxe_mcg *mcg) } /** - * __rxe_init_mca - initialize a new mca holding lock + * __rxe_init_mca_rcu - initialize a new mca holding lock * @qp: qp object * @mcg: mcg object * @mca: empty space for new mca @@ -298,8 +304,8 @@ static void rxe_destroy_mcg(struct rxe_mcg *mcg) * * Returns: 0 on success else an error */ -static int __rxe_init_mca(struct rxe_qp *qp, struct rxe_mcg *mcg, - struct rxe_mca *mca) +static int __rxe_init_mca_rcu(struct rxe_qp *qp, struct rxe_mcg *mcg, + struct rxe_mca *mca) { struct rxe_dev *rxe = to_rdev(qp->ibqp.device); int n; @@ -322,7 +328,10 @@ static int __rxe_init_mca(struct rxe_qp *qp, struct rxe_mcg *mcg, rxe_add_ref(qp); mca->qp = qp; - list_add_tail(&mca->qp_list, &mcg->qp_list); + kref_get(&mcg->ref_cnt); + mca->mcg = mcg; + + list_add_tail_rcu(&mca->qp_list, &mcg->qp_list); return 0; } @@ -343,14 +352,14 @@ static int rxe_attach_mcg(struct rxe_mcg *mcg, struct rxe_qp *qp) int err; /* check to see if the qp is already a member of the group */ - spin_lock_irqsave(&rxe->mcg_lock, flags); - list_for_each_entry(mca, &mcg->qp_list, qp_list) { + rcu_read_lock(); + list_for_each_entry_rcu(mca, &mcg->qp_list, qp_list) { if (mca->qp == qp) { - spin_unlock_irqrestore(&rxe->mcg_lock, flags); + rcu_read_unlock(); return 0; } } - spin_unlock_irqrestore(&rxe->mcg_lock, flags); + rcu_read_unlock(); /* speculative alloc new mca without using GFP_ATOMIC */ mca = kzalloc(sizeof(*mca), GFP_KERNEL); @@ -367,7 +376,7 @@ static int rxe_attach_mcg(struct rxe_mcg *mcg, struct rxe_qp *qp) } } - err = __rxe_init_mca(qp, mcg, mca); + err = __rxe_init_mca_rcu(qp, mcg, mca); if (err) kfree(mca); out: @@ -376,15 +385,16 @@ static int rxe_attach_mcg(struct rxe_mcg *mcg, struct rxe_qp *qp) } /** - * __rxe_cleanup_mca - cleanup mca object holding lock - * @mca: mca object - * @mcg: mcg object + * __rxe_destroy_mca - free mca resources + * @head: rcu_head embedded in mca * * Context: caller must hold a reference to mcg and rxe->mcg_lock + * all rcu read operations should be compelete */ -static void __rxe_cleanup_mca(struct rxe_mca *mca, struct rxe_mcg *mcg) +static void __rxe_destroy_mca(struct rcu_head *head) { - list_del(&mca->qp_list); + struct rxe_mca *mca = container_of(head, typeof(*mca), rcu); + struct rxe_mcg *mcg = mca->mcg; atomic_dec(&mcg->qp_num); atomic_dec(&mcg->rxe->mcg_attach); @@ -394,6 +404,19 @@ static void __rxe_cleanup_mca(struct rxe_mca *mca, struct rxe_mcg *mcg) kfree(mca); } +/** + * __rxe_cleanup_mca_rcu - cleanup mca object holding lock + * @mca: mca object + * @mcg: mcg object + * + * Context: caller must hold a reference to mcg and rxe->mcg_lock + */ +static void __rxe_cleanup_mca_rcu(struct rxe_mca *mca, struct rxe_mcg *mcg) +{ + list_del_rcu(&mca->qp_list); + call_rcu(&mca->rcu, __rxe_destroy_mca); +} + /** * rxe_detach_mcg - detach qp from mcg * @mcg: mcg object @@ -404,31 +427,35 @@ static void __rxe_cleanup_mca(struct rxe_mca *mca, struct rxe_mcg *mcg) static int rxe_detach_mcg(struct rxe_mcg *mcg, struct rxe_qp *qp) { struct rxe_dev *rxe = mcg->rxe; - struct rxe_mca *mca, *tmp; - unsigned long flags; + struct rxe_mca *mca; + int ret; - spin_lock_irqsave(&rxe->mcg_lock, flags); - list_for_each_entry_safe(mca, tmp, &mcg->qp_list, qp_list) { - if (mca->qp == qp) { - __rxe_cleanup_mca(mca, mcg); - - /* if the number of qp's attached to the - * mcast group falls to zero go ahead and - * tear it down. This will not free the - * object since we are still holding a ref - * from the caller - */ - if (atomic_read(&mcg->qp_num) <= 0) - __rxe_destroy_mcg(mcg); - - spin_unlock_irqrestore(&rxe->mcg_lock, flags); - return 0; - } + spin_lock_bh(&rxe->mcg_lock); + list_for_each_entry_rcu(mca, &mcg->qp_list, qp_list) { + if (mca->qp == qp) + goto found; } /* we didn't find the qp on the list */ - spin_unlock_irqrestore(&rxe->mcg_lock, flags); - return -EINVAL; + ret = -EINVAL; + goto done; + +found: + __rxe_cleanup_mca_rcu(mca, mcg); + + /* if the number of qp's attached to the + * mcast group falls to zero go ahead and + * tear it down. This will not free the + * object since we are still holding a ref + * from the caller + */ + if (atomic_read(&mcg->qp_num) <= 0) + __rxe_destroy_mcg(mcg); + + ret = 0; +done: + spin_unlock_bh(&rxe->mcg_lock); + return ret; } /** diff --git a/drivers/infiniband/sw/rxe/rxe_recv.c b/drivers/infiniband/sw/rxe/rxe_recv.c index 9b21cbb22602..c2cab85c6576 100644 --- a/drivers/infiniband/sw/rxe/rxe_recv.c +++ b/drivers/infiniband/sw/rxe/rxe_recv.c @@ -265,15 +265,15 @@ static void rxe_rcv_mcast_pkt(struct rxe_dev *rxe, struct sk_buff *skb) qp_array = kmalloc_array(nmax, sizeof(qp), GFP_KERNEL); n = 0; - spin_lock_bh(&rxe->mcg_lock); - list_for_each_entry(mca, &mcg->qp_list, qp_list) { + rcu_read_lock(); + list_for_each_entry_rcu(mca, &mcg->qp_list, qp_list) { /* protect the qp pointers in the list */ rxe_add_ref(mca->qp); qp_array[n++] = mca->qp; if (n == nmax) break; } - spin_unlock_bh(&rxe->mcg_lock); + rcu_read_unlock(); nmax = n; kref_put(&mcg->ref_cnt, rxe_cleanup_mcg); diff --git a/drivers/infiniband/sw/rxe/rxe_verbs.h b/drivers/infiniband/sw/rxe/rxe_verbs.h index 6b15251ff67a..4ee51de50b95 100644 --- a/drivers/infiniband/sw/rxe/rxe_verbs.h +++ b/drivers/infiniband/sw/rxe/rxe_verbs.h @@ -364,7 +364,9 @@ struct rxe_mcg { struct rxe_mca { struct list_head qp_list; + struct rcu_head rcu; struct rxe_qp *qp; + struct rxe_mcg *mcg; }; struct rxe_port {