From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753319AbdK1VhO (ORCPT ); Tue, 28 Nov 2017 16:37:14 -0500 Received: from bombadil.infradead.org ([65.50.211.133]:45508 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752794AbdK1Vdd (ORCPT ); Tue, 28 Nov 2017 16:33:33 -0500 From: Matthew Wilcox Cc: Matthew Wilcox , Chris Mi , Jiri Pirko , "David S . Miller" , Cong Wang , Jamal Hadi Salim , Daniel Borkmann , Eric Biggers , Lai Jiangshan , Tejun Heo , Rehas Sachdeva , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 13/17] cls_u32: Reinstate cyclic allocation Date: Tue, 28 Nov 2017 13:33:08 -0800 Message-Id: <20171128213312.28983-14-willy@infradead.org> X-Mailer: git-send-email 2.9.5 In-Reply-To: <20171128213312.28983-1-willy@infradead.org> References: <20171128213312.28983-1-willy@infradead.org> To: unlisted-recipients:; (no To-header on input) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Matthew Wilcox Commit e7614370d6f0 ("net_sched: use idr to allocate u32 filter handles) converted htid allocation to use the IDR. The ID allocated by this scheme changes; it used to be cyclic, but now always allocates the lowest available. The IDR supports cyclic allocation, so just use the right function. Signed-off-by: Matthew Wilcox --- net/sched/cls_u32.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/net/sched/cls_u32.c b/net/sched/cls_u32.c index 9d48674a70e0..e65b47483dc0 100644 --- a/net/sched/cls_u32.c +++ b/net/sched/cls_u32.c @@ -316,19 +316,13 @@ static void *u32_get(struct tcf_proto *tp, u32 handle) return u32_lookup_key(ht, handle); } +/* Protected by rtnl lock */ static u32 gen_new_htid(struct tc_u_common *tp_c, struct tc_u_hnode *ptr) { - unsigned long idr_index; - int err; - - /* This is only used inside rtnl lock it is safe to increment - * without read _copy_ update semantics - */ - err = idr_alloc_ext(&tp_c->handle_idr, ptr, &idr_index, - 1, 0x7FF, GFP_KERNEL); - if (err) + int id = idr_alloc_cyclic(&tp_c->handle_idr, ptr, 1, 0x7FF, GFP_KERNEL); + if (id < 0) return 0; - return (u32)(idr_index | 0x800) << 20; + return (id | 0x800U) << 20; } static struct hlist_head *tc_u_common_hash; -- 2.15.0