From mboxrd@z Thu Jan 1 00:00:00 1970 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3B6B7C4321E for ; Tue, 29 Nov 2022 10:57:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:CC:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=o1HcVRSDItCKaphbI/rpuq9Lt06S7rRKoemGy2yqoQo=; b=a4VeHZA5keiIvE tSdylYnsFz5nNKP/wIekOS/roZrKMuUcELa5yobrkXDyxr5ZiK23KD3wa2/421tqxcyD0UI+02uoF 6ZIxcrezvSyvIgXtYV5SPm1p8sCGpuAZm57WcTmdkCgjEVw0Iy6rIp9euRmviczcByXDxrWEtIk9b 0Y1n80ZNTm1mLQje6aX8rqfgeAst3E4RV12hDYVr85Mjo8piehfsATh3WwpK3nm4H9nq4kNAS5IGQ g+hZy6ICrnQTKP0jSY4IIQcXZM6gd2WY49V2ENoyg92y4DH2S02QYCdwKiR0aDKaYp4myJ4i3QYUc M6PnDxc82HqlO1taq2yw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ozyHU-008NEe-8w; Tue, 29 Nov 2022 10:56:04 +0000 Received: from esa.microchip.iphmx.com ([68.232.153.233]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1ozyHR-008NCs-88 for linux-arm-kernel@lists.infradead.org; Tue, 29 Nov 2022 10:56:03 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1669719361; x=1701255361; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=14JeKXWHSLqj+2WYk+/+WfhIsZZ1QfsK4ISNpY3uTsc=; b=15mLTSn95iEey0KcZrtZbHYzQQbevr7H4S8Mb/3hhmc3oPY7r80nSpmF Cq+9htAV10PBbrCgksevDPQdfGQ3MehVYT9vjg5leC/aOW3G1jDBrRmju rk+SitnWFfUpkQa6gJSPMWOE5rjADWKf9V83SdKsdKweh01FJ5fVW5cAt /miFni79wE8+Hcgk5l/eejgUeV9YvAl1ZyznbHdQFpsyGLb9zgJn31qnz 2pIwb1fTddIjt+wsHs8Ui+LeWwtp2NCSVqPrMFINxV3r/1luPp+3fzUp4 LPp+k7cOuUIIpxucaAmavSZaC8iiaRcLhYhn+TbjcpZQEmzjj1eYo5zFS g==; X-IronPort-AV: E=Sophos;i="5.96,202,1665471600"; d="scan'208";a="190964478" Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa3.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 29 Nov 2022 03:55:56 -0700 Received: from chn-vm-ex01.mchp-main.com (10.10.85.143) by chn-vm-ex04.mchp-main.com (10.10.85.152) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.12; Tue, 29 Nov 2022 03:55:55 -0700 Received: from localhost (10.10.115.15) by chn-vm-ex01.mchp-main.com (10.10.85.143) with Microsoft SMTP Server id 15.1.2507.12 via Frontend Transport; Tue, 29 Nov 2022 03:55:55 -0700 Date: Tue, 29 Nov 2022 12:00:58 +0100 From: Horatiu Vultur To: Alexander Lobakin CC: , , , , , , , , , , , Subject: Re: [PATCH net-next] net: microchip: vcap: Change how the rule id is generated Message-ID: <20221129110058.uv2zqjscwyvku46t@soft-dev3-1> References: <20221128142959.8325-1-horatiu.vultur@microchip.com> <20221128144042.2097491-1-alexandr.lobakin@intel.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20221128144042.2097491-1-alexandr.lobakin@intel.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221129_025601_361379_86529296 X-CRM114-Status: GOOD ( 31.05 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The 11/28/2022 15:40, Alexander Lobakin wrote: Hi Olek, > > From: Horatiu Vultur > Date: Mon, 28 Nov 2022 15:29:59 +0100 > > > Currently whenever a new rule id is generated, it picks up the next > > number bigger than previous id. So it would always be 1, 2, 3, etc. > > When the rule with id 1 will be deleted and a new rule will be added, > > it will have the id 4 and not id 1. > > In theory this can be a problem if at some point a rule will be added > > and removed ~0 times. Then no more rules can be added because there > > are no more ids. > > > > Change this such that when a new rule is added, search for an empty > > rule id starting with value of 1 as value 0 is reserved. > > > > Fixes: c9da1ac1c212 ("net: microchip: sparx5: Adding initial tc flower support for VCAP API") > > Signed-off-by: Horatiu Vultur > > --- > > drivers/net/ethernet/microchip/vcap/vcap_api.c | 7 +------ > > drivers/net/ethernet/microchip/vcap/vcap_api.h | 1 - > > 2 files changed, 1 insertion(+), 7 deletions(-) > > > > diff --git a/drivers/net/ethernet/microchip/vcap/vcap_api.c b/drivers/net/ethernet/microchip/vcap/vcap_api.c > > index b50d002b646dc..b65819f3a927f 100644 > > --- a/drivers/net/ethernet/microchip/vcap/vcap_api.c > > +++ b/drivers/net/ethernet/microchip/vcap/vcap_api.c > > @@ -974,17 +974,12 @@ static u32 vcap_next_rule_addr(u32 addr, struct vcap_rule_internal *ri) > > /* Assign a unique rule id and autogenerate one if id == 0 */ > > static u32 vcap_set_rule_id(struct vcap_rule_internal *ri) > > { > > - u32 next_id; > > - > > if (ri->data.id != 0) > > return ri->data.id; > > > > - next_id = ri->vctrl->rule_id + 1; > > - > > - for (next_id = ri->vctrl->rule_id + 1; next_id < ~0; ++next_id) { > > + for (u32 next_id = 1; next_id < ~0; ++next_id) { > > if (!vcap_lookup_rule(ri->vctrl, next_id)) { > > Or you can simply use IDA/IDR/XArray which takes care of all this :) Thanks for the great suggestion. From what I can see IDR would be a great match for this. Then we can also change the function 'vcap_lookup_rule' to use IDR. On the other side, we will not continuously add/remove entries from the VCAP, so I was not sure if it is worth bringing the IDR(with the radix tree) for this. Anyway I am open for IDR suggestion. But lets wait for the VCAP maintainer to see what he thinks. > > > > ri->data.id = next_id; > > - ri->vctrl->rule_id = next_id; > > break; > > } > > } > > diff --git a/drivers/net/ethernet/microchip/vcap/vcap_api.h b/drivers/net/ethernet/microchip/vcap/vcap_api.h > > index ca4499838306f..689c7270f2a89 100644 > > --- a/drivers/net/ethernet/microchip/vcap/vcap_api.h > > +++ b/drivers/net/ethernet/microchip/vcap/vcap_api.h > > @@ -268,7 +268,6 @@ struct vcap_operations { > > > > /* VCAP API Client control interface */ > > struct vcap_control { > > - u32 rule_id; /* last used rule id (unique across VCAP instances) */ > > struct vcap_operations *ops; /* client supplied operations */ > > const struct vcap_info *vcaps; /* client supplied vcap models */ > > const struct vcap_statistics *stats; /* client supplied vcap stats */ > > -- > > 2.38.0 > > Thanks, > Olek -- /Horatiu _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel