From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by dpdk.org (Postfix) with ESMTP id BE2E61B2B0 for ; Tue, 25 Sep 2018 16:41:42 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 25 Sep 2018 07:41:41 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,302,1534834800"; d="scan'208";a="73580529" Received: from irsmsx102.ger.corp.intel.com ([163.33.3.155]) by fmsmga008.fm.intel.com with ESMTP; 25 Sep 2018 07:41:28 -0700 Received: from irsmsx105.ger.corp.intel.com ([169.254.7.54]) by IRSMSX102.ger.corp.intel.com ([169.254.2.180]) with mapi id 14.03.0319.002; Tue, 25 Sep 2018 15:41:28 +0100 From: "Ananyev, Konstantin" To: Filip Pudak CC: "dev@dpdk.org" Thread-Topic: [PATCH] acl: fix classify with no rules in ctx Thread-Index: AQHUVNsksLtwF9v3rUO04RbQxVJ4+aUBEIQg Date: Tue, 25 Sep 2018 14:41:27 +0000 Message-ID: <2601191342CEEE43887BDE71AB977258EA95B1A1@irsmsx105.ger.corp.intel.com> References: <20180925142030.136569-1-filip.pudak@ericsson.com> In-Reply-To: <20180925142030.136569-1-filip.pudak@ericsson.com> Accept-Language: en-IE, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiMzM2N2MwZjYtNDQyMy00MWZkLWJlYjgtMGNmYTFlNzE2ZjgzIiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX05UIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE3LjEwLjE4MDQuNDkiLCJUcnVzdGVkTGFiZWxIYXNoIjoidUFRK2ZHV0lcL0grMGFUbzk0cE1SZnl4WEJKZkg2T1p0NGFTcmt5XC91dXJVVUMxaW1xZU5tQlpyUnFhWllWNndEIn0= x-ctpclassification: CTP_NT dlp-product: dlpe-windows dlp-version: 11.0.400.15 dlp-reaction: no-action x-originating-ip: [163.33.239.180] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: Re: [dpdk-dev] [PATCH] acl: fix classify with no rules in ctx X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 25 Sep 2018 14:41:44 -0000 Hi Filip, >=20 > Executing classify with no context or a context without any rules added > to it leads to a crash. This patch introduces checks for acl to ensure > possibility to defer creation of rules until a later point. A new > return value is introduced to allow the user of the API to decide how > to treat the specific scenario when the context is "empty" of rules. I don't think the patch is really needed. classify() is a data-path function, so obviously we try to avoid extra chec= ks here. from rte_acl.h: "... Note, that it is a caller's responsibility to ensure that input parame= ters * are valid and point to correct memory locations." Again if ctx->num_rules !=3D 0 it doesn't guarantee that build already comp= leted successfully and it is ok to call classify().=20 If you need - you can always do these checks just before calling rte_acl_cl= assify().=20 Konstantin >=20 > Signed-off-by: Filip Pudak > --- > lib/librte_acl/rte_acl.c | 10 ++++++++-- > lib/librte_acl/rte_acl.h | 2 ++ > 2 files changed, 10 insertions(+), 2 deletions(-) >=20 > diff --git a/lib/librte_acl/rte_acl.c b/lib/librte_acl/rte_acl.c > index 2f1243c..4a6a894 100644 > --- a/lib/librte_acl/rte_acl.c > +++ b/lib/librte_acl/rte_acl.c > @@ -121,10 +121,16 @@ rte_acl_classify_alg(const struct rte_acl_ctx *ctx,= const uint8_t **data, > uint32_t *results, uint32_t num, uint32_t categories, > enum rte_acl_classify_alg alg) > { > - if (categories !=3D 1 && > - ((RTE_ACL_RESULTS_MULTIPLIER - 1) & categories) !=3D 0) > + if (ctx =3D=3D NULL || (categories !=3D 1 && > + ((RTE_ACL_RESULTS_MULTIPLIER - 1) & categories) !=3D 0)) > return -EINVAL; >=20 > + if (ctx->num_rules =3D=3D 0) { > + RTE_LOG(INFO, ACL, "Cannot perform acl classify with no = rules added!\n"); > + memset(results, 0, categories * num * sizeof(uint32_t)); > + return -ENODATA; > + } > + > return classify_fns[alg](ctx, data, results, num, categories); > } >=20 > diff --git a/lib/librte_acl/rte_acl.h b/lib/librte_acl/rte_acl.h > index aa22e70..3e56fe5 100644 > --- a/lib/librte_acl/rte_acl.h > +++ b/lib/librte_acl/rte_acl.h > @@ -272,6 +272,7 @@ enum rte_acl_classify_alg { > * @return > * zero on successful completion. > * -EINVAL for incorrect arguments. > + * -ENODATA if the context does not contain any rules to classify agai= nst. > */ > extern int > rte_acl_classify(const struct rte_acl_ctx *ctx, > @@ -312,6 +313,7 @@ rte_acl_classify(const struct rte_acl_ctx *ctx, > * @return > * zero on successful completion. > * -EINVAL for incorrect arguments. > + * -ENODATA if the context does not contain any rules to classify agai= nst. > */ > extern int > rte_acl_classify_alg(const struct rte_acl_ctx *ctx, > -- > 2.9.0