Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp4452929rdh; Wed, 29 Nov 2023 01:48:44 -0800 (PST) X-Google-Smtp-Source: AGHT+IGmEZAL7uoAi6C8tDbsDWCMSVm31MmgY/M9XX0rNf3we7ybsOXCGBxHC9/4BxKvCBiTx4JQ X-Received: by 2002:a17:902:d4c7:b0:1d0:1257:d35b with SMTP id o7-20020a170902d4c700b001d01257d35bmr2647087plg.67.1701251324334; Wed, 29 Nov 2023 01:48:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701251324; cv=none; d=google.com; s=arc-20160816; b=BZ9XXbHxxI3k4CE9G9lPUYn9MZ0EGPUKbRIw8k02Bob6kpq1nR0/RP0F0svO6Cj+Sk y2sc2lPMB4HAa8pGdW2vteILf0LORCKW317RqceliixdM8fvNoOFt1oBY3zJuBLOrLnW nXmYke+JvH/vJ4RUP1VkkeFSzMRq/yh+b+wKuCj0qtPhIOk102RI+LFwWwuhWROLpGMJ nb0x6+D9cMBx/tBM9Fk2lkTljulKq1efVVbbd34s78boFk692rLBu0wUFLmZWPuYBOfH KE7plLD3rAAaj3TNtv9XukdUcfWN6kav6CZUKVIKYIcODXmGGwpkPzO9xiDKTx3MXv0Q HEbA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=P2rgTryUC7omMha5X6EMcPqS1AlWzrwrifAdAslVYwg=; fh=KWvyQxL3Ff+3WPSMjlYu+P4255AmcMULAsFol6M1vNI=; b=V77XkFclh8RjTM8emoO97780jseDPfNHj3QdVD3XqGO9xnnqvNlm3PqiXm42SNiAP3 mHaiU0BfFgOVYk+GDlptvDtHk8USXhArbvaEcPcSl9LoGyBq/G4yNCMLOKrCGNjLjJN+ m8Wdab1laiz+e/z8AOYi3Iz+qHwHuW0/4E/Rv0TGAsp8j8ClHFn5pb7NSZwPisXFXzmo YbxKzYUFWA7ydQ+J52mMiMr+2xhKNzkdbQuB8zR+8o2VEvk+/KVXqQDW1Suws3voIsSx EvZfdcxa/KZ1zqKbhZnrm6FUUw92OdnQDtHY3E5J3wNZ5NyXZrfaMXlhwzlaXsb5lb94 WUNA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=hisilicon.com Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id m6-20020a170902db0600b001cfd35ec1eesi6328190plx.519.2023.11.29.01.48.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Nov 2023 01:48:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=hisilicon.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 7F361803C969; Wed, 29 Nov 2023 01:48:40 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230267AbjK2JsW (ORCPT + 99 others); Wed, 29 Nov 2023 04:48:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40140 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229940AbjK2JsF (ORCPT ); Wed, 29 Nov 2023 04:48:05 -0500 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4811819B6; Wed, 29 Nov 2023 01:48:10 -0800 (PST) Received: from kwepemi500006.china.huawei.com (unknown [172.30.72.56]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4SgDyJ70R0zvR9X; Wed, 29 Nov 2023 17:47:36 +0800 (CST) Received: from localhost.localdomain (10.67.165.2) by kwepemi500006.china.huawei.com (7.221.188.68) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Wed, 29 Nov 2023 17:48:08 +0800 From: Junxian Huang To: , CC: , , , Subject: [PATCH for-rc 3/6] RDMA/hns: Add a max length of gid table Date: Wed, 29 Nov 2023 17:44:31 +0800 Message-ID: <20231129094434.134528-4-huangjunxian6@hisilicon.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20231129094434.134528-1-huangjunxian6@hisilicon.com> References: <20231129094434.134528-1-huangjunxian6@hisilicon.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.67.165.2] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To kwepemi500006.china.huawei.com (7.221.188.68) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Wed, 29 Nov 2023 01:48:40 -0800 (PST) IB-core and rdma-core restrict the sgid_index specified by users, which is uint8_t/u8 data type, to only be within the range of 0-255, so it's meaningless to support excessively large gid_table_len. On the other hand, ib-core creates as many sysfs gid files as gid_table_len, most of which are not only useless because of the reason above, but also greatly increase the traversal time of the sysfs gid files for applications. This patch limits the maximum length of gid table to 256. Signed-off-by: Junxian Huang --- drivers/infiniband/hw/hns/hns_roce_hw_v2.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/drivers/infiniband/hw/hns/hns_roce_hw_v2.c b/drivers/infiniband/hw/hns/hns_roce_hw_v2.c index 1ceeedfa225f..8126922b4e21 100644 --- a/drivers/infiniband/hw/hns/hns_roce_hw_v2.c +++ b/drivers/infiniband/hw/hns/hns_roce_hw_v2.c @@ -2055,6 +2055,7 @@ static void set_hem_page_size(struct hns_roce_dev *hr_dev) /* Apply all loaded caps before setting to hardware */ static void apply_func_caps(struct hns_roce_dev *hr_dev) { +#define MAX_GID_TBL_LEN 256 struct hns_roce_caps *caps = &hr_dev->caps; struct hns_roce_v2_priv *priv = hr_dev->priv; @@ -2090,8 +2091,14 @@ static void apply_func_caps(struct hns_roce_dev *hr_dev) caps->gmv_entry_sz = HNS_ROCE_V3_GMV_ENTRY_SZ; caps->gmv_hop_num = HNS_ROCE_HOP_NUM_0; - caps->gid_table_len[0] = caps->gmv_bt_num * - (HNS_HW_PAGE_SIZE / caps->gmv_entry_sz); + + /* It's meaningless to support excessively large gid_table_len, + * as the type of sgid_index in kernel struct ib_global_route + * and userspace struct ibv_global_route are u8/uint8_t (0-255). + */ + caps->gid_table_len[0] = min_t(u32, MAX_GID_TBL_LEN, + caps->gmv_bt_num * + (HNS_HW_PAGE_SIZE / caps->gmv_entry_sz)); caps->gmv_entry_num = caps->gmv_bt_num * (PAGE_SIZE / caps->gmv_entry_sz); -- 2.30.0