Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp7077466rwr; Tue, 25 Apr 2023 07:50:57 -0700 (PDT) X-Google-Smtp-Source: AKy350bygANlpcD3Q8Xkt6Eo5W9Q+fbjVhx6lziKp+G0Bkunp3BSKUB8bKceAFgwCj/egJVZFwA4 X-Received: by 2002:a17:90a:3004:b0:246:681c:71fd with SMTP id g4-20020a17090a300400b00246681c71fdmr17021187pjb.6.1682434256739; Tue, 25 Apr 2023 07:50:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682434256; cv=none; d=google.com; s=arc-20160816; b=D8x7M4UwgKO0bYTeINyGunqk2n9yBhU2b2Ux1gcos6fKzbkHTVOg+gOxeRJSNujnpv dd2oS6qnP+Knvq8UfHPaG15NaXmYzFqUHBSW/lPD8Rp8/noQzA6bpT7yccU1g7Lomca2 z78mqIcTHLwWa+hBI4WBlInLxc2Sf8nvzR+cFJJ8CFGCQqDtPiGS8TdQeIZGH9qibB/k FoZi3MXrr9IUJgjQNMp4RKI7iGWCbQZAJUO6u4hzmGGgSA+oY74Hs7ddxYGAkiZGYxWj RKV0RXb/6Huz5X6BMUzKtNz8VolLNEF//F8HWF+8VlxXWiuIZ0YewME3ZJUEe54s0ajx OTKw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=M+Kciq4hJIDYLEDnU0UIcGmZY1J3YxtbOm5Cg6g5pVg=; b=A57zBD6WXnH+sjnuiO8x7bDDwPqTDZ7/K4ONKVxgNP5+wSb7I/tnASNH94RkApeyup oJrnsHwqwy3Qe/zXzelUUdcCvQJ/zO5jN4tfWtXd+zDeXOQftuQ8UmlQWVxBJwI2eDaT jyROVRRTTDsbBDGwFKqBuPggquy9xW1kx+nkaJj449iW2o5HP6L2CVn52eH9TGgip5f3 QBiBN162l/owEdxCyZCLcDDQbI+GR05GXYDpfhLIuZKLpN5Kqfw5FQMHDap2gMTX7PSm HmWHwd2JqypRUWqdhrKgudoyyemHT0xe7Gdnaz31MUCtqW5MFugXl+GfZSHVZ0yh4fr/ VaMg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=LFw5nBu2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 88-20020a17090a09e100b00247ad11b6d3si14489080pjo.88.2023.04.25.07.50.36; Tue, 25 Apr 2023 07:50:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=LFw5nBu2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234311AbjDYOqF (ORCPT + 99 others); Tue, 25 Apr 2023 10:46:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55178 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233973AbjDYOqD (ORCPT ); Tue, 25 Apr 2023 10:46:03 -0400 Received: from out-28.mta1.migadu.com (out-28.mta1.migadu.com [95.215.58.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B12E31999 for ; Tue, 25 Apr 2023 07:46:01 -0700 (PDT) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1682433959; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=M+Kciq4hJIDYLEDnU0UIcGmZY1J3YxtbOm5Cg6g5pVg=; b=LFw5nBu2KadgbWyvmbsRvjD/6sieiKQWyAp/6dVO1crcGazdwQhfgdXbhOZk1yTjMbgyaG soH4NCIHENOdI3mja/k8Huvvl4hHtlOEtbyXjsbst+WYb4FHE+GB4wJNbVdxd5urcBs6ej 61RhANkSFbxulmIRXoVcDrUEEDyWojY= From: Cai Huoqing To: cai.huoqing@linux.dev Cc: Jakub Kicinski , "David S. Miller" , Eric Dumazet , Paolo Abeni , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] netdevsim: fib: Make use of rhashtable_iter Date: Tue, 25 Apr 2023 22:45:55 +0800 Message-Id: <20230425144556.98799-1-cai.huoqing@linux.dev> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, TO_EQ_FM_DIRECT_MX,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Iterating 'fib_rt_ht' by rhashtable_walk_next and rhashtable_iter directly instead of using list_for_each, because each entry of fib_rt_ht can be found by rhashtable API. And remove fib_rt_list. Signed-off-by: Cai Huoqing --- drivers/net/netdevsim/fib.c | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/drivers/net/netdevsim/fib.c b/drivers/net/netdevsim/fib.c index a1f91ff8ec56..1a50c8e14665 100644 --- a/drivers/net/netdevsim/fib.c +++ b/drivers/net/netdevsim/fib.c @@ -48,7 +48,6 @@ struct nsim_fib_data { struct nsim_per_fib_data ipv6; struct nsim_fib_entry nexthops; struct rhashtable fib_rt_ht; - struct list_head fib_rt_list; struct mutex fib_lock; /* Protects FIB HT and list */ struct notifier_block nexthop_nb; struct rhashtable nexthop_ht; @@ -75,7 +74,6 @@ struct nsim_fib_rt_key { struct nsim_fib_rt { struct nsim_fib_rt_key key; struct rhash_head ht_node; - struct list_head list; /* Member of fib_rt_list */ }; struct nsim_fib4_rt { @@ -247,12 +245,6 @@ static void nsim_fib_rt_init(struct nsim_fib_data *data, fib_rt->key.prefix_len = prefix_len; fib_rt->key.family = family; fib_rt->key.tb_id = tb_id; - list_add(&fib_rt->list, &data->fib_rt_list); -} - -static void nsim_fib_rt_fini(struct nsim_fib_rt *fib_rt) -{ - list_del(&fib_rt->list); } static struct nsim_fib_rt *nsim_fib_rt_lookup(struct rhashtable *fib_rt_ht, @@ -295,7 +287,6 @@ nsim_fib4_rt_create(struct nsim_fib_data *data, static void nsim_fib4_rt_destroy(struct nsim_fib4_rt *fib4_rt) { fib_info_put(fib4_rt->fi); - nsim_fib_rt_fini(&fib4_rt->common); kfree(fib4_rt); } @@ -570,7 +561,6 @@ nsim_fib6_rt_create(struct nsim_fib_data *data, for (i--; i >= 0; i--) { nsim_fib6_rt_nh_del(fib6_rt, rt_arr[i]); } - nsim_fib_rt_fini(&fib6_rt->common); kfree(fib6_rt); return ERR_PTR(err); } @@ -582,7 +572,6 @@ static void nsim_fib6_rt_destroy(struct nsim_fib6_rt *fib6_rt) list_for_each_entry_safe(iter, tmp, &fib6_rt->nh_list, list) nsim_fib6_rt_nh_del(fib6_rt, iter->rt); WARN_ON_ONCE(!list_empty(&fib6_rt->nh_list)); - nsim_fib_rt_fini(&fib6_rt->common); kfree(fib6_rt); } @@ -1091,7 +1080,9 @@ static void nsim_fib_dump_inconsistent(struct notifier_block *nb) { struct nsim_fib_data *data = container_of(nb, struct nsim_fib_data, fib_nb); - struct nsim_fib_rt *fib_rt, *fib_rt_tmp; + struct nsim_fib_rt *fib_rt; + struct rhashtable_iter hti; + struct rhash_head *pos; /* Flush the work to make sure there is no race with notifications. */ flush_work(&data->fib_event_work); @@ -1099,9 +1090,12 @@ static void nsim_fib_dump_inconsistent(struct notifier_block *nb) /* The notifier block is still not registered, so we do not need to * take any locks here. */ - list_for_each_entry_safe(fib_rt, fib_rt_tmp, &data->fib_rt_list, list) { - rhashtable_remove_fast(&data->fib_rt_ht, &fib_rt->ht_node, + rhashtable_walk_enter(&data->fib_rt_ht, &hti); + rhashtable_walk_start(&hti); + while ((pos = rhashtable_walk_next(&hti))) { + rhashtable_remove_fast(&data->fib_rt_ht, hti.p, nsim_fib_rt_ht_params); + fib_rt = rhashtable_walk_peek(&hti); nsim_fib_rt_free(fib_rt, data); } @@ -1501,17 +1495,24 @@ static void nsim_fib_flush_work(struct work_struct *work) { struct nsim_fib_data *data = container_of(work, struct nsim_fib_data, fib_flush_work); - struct nsim_fib_rt *fib_rt, *fib_rt_tmp; + struct nsim_fib_rt *fib_rt; + struct rhashtable_iter hti; + struct rhash_head *pos; + /* Process pending work. */ flush_work(&data->fib_event_work); mutex_lock(&data->fib_lock); - list_for_each_entry_safe(fib_rt, fib_rt_tmp, &data->fib_rt_list, list) { - rhashtable_remove_fast(&data->fib_rt_ht, &fib_rt->ht_node, + rhashtable_walk_enter(&data->fib_rt_ht, &hti); + rhashtable_walk_start(&hti); + while ((pos = rhashtable_walk_next(&hti))) { + rhashtable_remove_fast(&data->fib_rt_ht, hti.p, nsim_fib_rt_ht_params); + fib_rt = rhashtable_walk_peek(&hti); nsim_fib_rt_free(fib_rt, data); } + mutex_unlock(&data->fib_lock); } @@ -1571,7 +1572,6 @@ struct nsim_fib_data *nsim_fib_create(struct devlink *devlink, goto err_debugfs_exit; mutex_init(&data->fib_lock); - INIT_LIST_HEAD(&data->fib_rt_list); err = rhashtable_init(&data->fib_rt_ht, &nsim_fib_rt_ht_params); if (err) goto err_rhashtable_nexthop_destroy; @@ -1661,7 +1661,6 @@ void nsim_fib_destroy(struct devlink *devlink, struct nsim_fib_data *data) rhashtable_free_and_destroy(&data->nexthop_ht, nsim_nexthop_free, data); WARN_ON_ONCE(!list_empty(&data->fib_event_queue)); - WARN_ON_ONCE(!list_empty(&data->fib_rt_list)); mutex_destroy(&data->fib_lock); mutex_destroy(&data->nh_lock); nsim_fib_debugfs_exit(data); -- 2.34.1