Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp1348997pxf; Fri, 19 Mar 2021 05:25:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyfQEJxppLSC5snvfIQZ/9HhQcRGUlRODjalis1yHPYJEgKdMxin9n5vZnzAHW0x7bjz4sn X-Received: by 2002:a17:906:3385:: with SMTP id v5mr3972695eja.539.1616156724542; Fri, 19 Mar 2021 05:25:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616156724; cv=none; d=google.com; s=arc-20160816; b=PhB6/CTaCry4icBfy1GhSlfzcbGDa/1vVzz10ViGFv9Se43MqZbMP48JFKcmKHkNwL 8l5y/yHt78gyShfMw4ARbzqZ5HKevbCDvuYX1GcJROku5VIMnuAm9m27mzdQMJH0TCJp YKmv/nfiXuuPnih/Qg6yTb6ri0OsyOEBI3/v5XCXecaXeQMsHgbDAwGJajEDoEBRUO7K pvu9uZEH7N8gtDSwlyZxBIhGR/lbiAZzDNb6kWb9Htk9U+dC+3v3hQatfQeYuoHHz3/n C15lBITxYLEtdoHyKUUST9Hpm1WQAs66dUShAo8MnV5RELszznI7jlP11wER1dAvrFyB wgRw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=mnLBCEVfd+V0GCxaiuBdHDEX9PO5ohf0pEsdxkXCJmk=; b=Ex6qyi8XDl+FO3/Ma5BtfaNMTEKHtHUmrwuXu5VkHISivtq18wiYeMWolKm2U5LJ4j 5EOmetPbnQyoC2kP+qJyT1NGwX+VEJcqfdGRukfrlsQyrSSYM0HhpvYKcvCdgiPnMTyz V93uKoGWILnKkQm7xnO9IUTXxuoXKmEE2E8l81u7602iyh0KtFkfv7oNXWd/JA4QjcEH /1tIGirRK3LjPwRy3JDIvKpl/2MAAA/5RLSgCV6IIeSLhYbBFpKgvmtpj7PNODp6bOnf gJi/0eDjlseIhAq3bKbJQI8KfEv6xodbRWXbOEHUBRKwuHAgg8gY7qU7w9UiOpWI1KuW E90A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=zaAKZpMl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v10si3897397eds.85.2021.03.19.05.25.02; Fri, 19 Mar 2021 05:25:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=zaAKZpMl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229866AbhCSMVm (ORCPT + 99 others); Fri, 19 Mar 2021 08:21:42 -0400 Received: from mail.kernel.org ([198.145.29.99]:59594 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231401AbhCSMVJ (ORCPT ); Fri, 19 Mar 2021 08:21:09 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 41E4064F6A; Fri, 19 Mar 2021 12:21:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1616156468; bh=yzUNqevlFbXe2wFS/Q4U2Es4UX4t22eR83ywGh0/E+I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=zaAKZpMlGwzWbvfxgVzeZR++/kqqlBKPaW28eTBidYEw1x5D2MiJhX2Cvbfh5WbIm xxJq4sSAEDb0/EzHZWzQ0FfWqtGvBw6vZdh8wdpGnFL+wafjk3bq4P7cUA6d2L7eBh wJ2Phh4U4tgzuyAunXao7+6gFIc8e1hN08MkLpoo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Nicolas Morey-Chaisemartin , Bart Van Assche , Jason Gunthorpe , Yi Zhang Subject: [PATCH 5.11 26/31] RDMA/srp: Fix support for unpopulated and unbalanced NUMA nodes Date: Fri, 19 Mar 2021 13:19:20 +0100 Message-Id: <20210319121748.047018321@linuxfoundation.org> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20210319121747.203523570@linuxfoundation.org> References: <20210319121747.203523570@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Nicolas Morey-Chaisemartin commit 2b5715fc17386a6223490d5b8f08d031999b0c0b upstream. The current code computes a number of channels per SRP target and spreads them equally across all online NUMA nodes. Each channel is then assigned a CPU within this node. In the case of unbalanced, or even unpopulated nodes, some channels do not get a CPU associated and thus do not get connected. This causes the SRP connection to fail. This patch solves the issue by rewriting channel computation and allocation: - Drop channel to node/CPU association as it had no real effect on locality but added unnecessary complexity. - Tweak the number of channels allocated to reduce CPU contention when possible: - Up to one channel per CPU (instead of up to 4 by node) - At least 4 channels per node, unless ch_count module parameter is used. Link: https://lore.kernel.org/r/9cb4d9d3-30ad-2276-7eff-e85f7ddfb411@suse.com Signed-off-by: Nicolas Morey-Chaisemartin Reviewed-by: Bart Van Assche Signed-off-by: Jason Gunthorpe Cc: Yi Zhang Signed-off-by: Greg Kroah-Hartman --- drivers/infiniband/ulp/srp/ib_srp.c | 116 ++++++++++++++---------------------- 1 file changed, 48 insertions(+), 68 deletions(-) --- a/drivers/infiniband/ulp/srp/ib_srp.c +++ b/drivers/infiniband/ulp/srp/ib_srp.c @@ -3628,7 +3628,7 @@ static ssize_t srp_create_target(struct struct srp_rdma_ch *ch; struct srp_device *srp_dev = host->srp_dev; struct ib_device *ibdev = srp_dev->dev; - int ret, node_idx, node, cpu, i; + int ret, i, ch_idx; unsigned int max_sectors_per_mr, mr_per_cmd = 0; bool multich = false; uint32_t max_iu_len; @@ -3753,81 +3753,61 @@ static ssize_t srp_create_target(struct goto out; ret = -ENOMEM; - if (target->ch_count == 0) + if (target->ch_count == 0) { target->ch_count = - max_t(unsigned int, num_online_nodes(), - min(ch_count ?: - min(4 * num_online_nodes(), - ibdev->num_comp_vectors), - num_online_cpus())); + min(ch_count ?: + max(4 * num_online_nodes(), + ibdev->num_comp_vectors), + num_online_cpus()); + } + target->ch = kcalloc(target->ch_count, sizeof(*target->ch), GFP_KERNEL); if (!target->ch) goto out; - node_idx = 0; - for_each_online_node(node) { - const int ch_start = (node_idx * target->ch_count / - num_online_nodes()); - const int ch_end = ((node_idx + 1) * target->ch_count / - num_online_nodes()); - const int cv_start = node_idx * ibdev->num_comp_vectors / - num_online_nodes(); - const int cv_end = (node_idx + 1) * ibdev->num_comp_vectors / - num_online_nodes(); - int cpu_idx = 0; - - for_each_online_cpu(cpu) { - if (cpu_to_node(cpu) != node) - continue; - if (ch_start + cpu_idx >= ch_end) - continue; - ch = &target->ch[ch_start + cpu_idx]; - ch->target = target; - ch->comp_vector = cv_start == cv_end ? cv_start : - cv_start + cpu_idx % (cv_end - cv_start); - spin_lock_init(&ch->lock); - INIT_LIST_HEAD(&ch->free_tx); - ret = srp_new_cm_id(ch); - if (ret) - goto err_disconnect; - - ret = srp_create_ch_ib(ch); - if (ret) - goto err_disconnect; - - ret = srp_alloc_req_data(ch); - if (ret) - goto err_disconnect; - - ret = srp_connect_ch(ch, max_iu_len, multich); - if (ret) { - char dst[64]; - - if (target->using_rdma_cm) - snprintf(dst, sizeof(dst), "%pIS", - &target->rdma_cm.dst); - else - snprintf(dst, sizeof(dst), "%pI6", - target->ib_cm.orig_dgid.raw); - shost_printk(KERN_ERR, target->scsi_host, - PFX "Connection %d/%d to %s failed\n", - ch_start + cpu_idx, - target->ch_count, dst); - if (node_idx == 0 && cpu_idx == 0) { - goto free_ch; - } else { - srp_free_ch_ib(target, ch); - srp_free_req_data(target, ch); - target->ch_count = ch - target->ch; - goto connected; - } + for (ch_idx = 0; ch_idx < target->ch_count; ++ch_idx) { + ch = &target->ch[ch_idx]; + ch->target = target; + ch->comp_vector = ch_idx % ibdev->num_comp_vectors; + spin_lock_init(&ch->lock); + INIT_LIST_HEAD(&ch->free_tx); + ret = srp_new_cm_id(ch); + if (ret) + goto err_disconnect; + + ret = srp_create_ch_ib(ch); + if (ret) + goto err_disconnect; + + ret = srp_alloc_req_data(ch); + if (ret) + goto err_disconnect; + + ret = srp_connect_ch(ch, max_iu_len, multich); + if (ret) { + char dst[64]; + + if (target->using_rdma_cm) + snprintf(dst, sizeof(dst), "%pIS", + &target->rdma_cm.dst); + else + snprintf(dst, sizeof(dst), "%pI6", + target->ib_cm.orig_dgid.raw); + shost_printk(KERN_ERR, target->scsi_host, + PFX "Connection %d/%d to %s failed\n", + ch_idx, + target->ch_count, dst); + if (ch_idx == 0) { + goto free_ch; + } else { + srp_free_ch_ib(target, ch); + srp_free_req_data(target, ch); + target->ch_count = ch - target->ch; + goto connected; } - - multich = true; - cpu_idx++; } - node_idx++; + multich = true; } connected: