<div dir="auto"><div><br><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Sep 27, 2023, 16:09 Ferruh Yigit <<a href="mailto:ferruh.yigit@amd.com">ferruh.yigit@amd.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On 9/27/2023 2:48 PM, Stanisław Kardach wrote:<br>
> On Wed, Sep 27, 2023 at 1:55 PM Ferruh Yigit <<a href="mailto:ferruh.yigit@amd.com" target="_blank" rel="noreferrer">ferruh.yigit@amd.com</a>> wrote:<br>
>><br>
>> On 9/21/2023 3:49 PM, Stanisław Kardach wrote:<br>
>>> On Thu, Sep 21, 2023, 15:18 Tummala, Sivaprasad<br>
>>> <<a href="mailto:Sivaprasad.Tummala@amd.com" target="_blank" rel="noreferrer">Sivaprasad.Tummala@amd.com</a> <mailto:<a href="mailto:Sivaprasad.Tummala@amd.com" target="_blank" rel="noreferrer">Sivaprasad.Tummala@amd.com</a>>> wrote:<br>
>>><br>
>>>     [AMD Official Use Only - General]<br>
>>><br>
>>>     > -----Original Message-----<br>
>>>     > From: David Marchand <<a href="mailto:david.marchand@redhat.com" target="_blank" rel="noreferrer">david.marchand@redhat.com</a><br>
>>>     <mailto:<a href="mailto:david.marchand@redhat.com" target="_blank" rel="noreferrer">david.marchand@redhat.com</a>>><br>
>>>     > Sent: Wednesday, September 20, 2023 1:05 PM<br>
>>>     > To: Stanisław Kardach <<a href="mailto:kda@semihalf.com" target="_blank" rel="noreferrer">kda@semihalf.com</a><br>
>>>     <mailto:<a href="mailto:kda@semihalf.com" target="_blank" rel="noreferrer">kda@semihalf.com</a>>>; Tummala, Sivaprasad<br>
>>>     > <<a href="mailto:Sivaprasad.Tummala@amd.com" target="_blank" rel="noreferrer">Sivaprasad.Tummala@amd.com</a> <mailto:<a href="mailto:Sivaprasad.Tummala@amd.com" target="_blank" rel="noreferrer">Sivaprasad.Tummala@amd.com</a>>><br>
>>>     > Cc: Ruifeng Wang <<a href="mailto:ruifeng.wang@arm.com" target="_blank" rel="noreferrer">ruifeng.wang@arm.com</a><br>
>>>     <mailto:<a href="mailto:ruifeng.wang@arm.com" target="_blank" rel="noreferrer">ruifeng.wang@arm.com</a>>>; Min Zhou <<a href="mailto:zhoumin@loongson.cn" target="_blank" rel="noreferrer">zhoumin@loongson.cn</a><br>
>>>     <mailto:<a href="mailto:zhoumin@loongson.cn" target="_blank" rel="noreferrer">zhoumin@loongson.cn</a>>>;<br>
>>>     > David Christensen <<a href="mailto:drc@linux.vnet.ibm.com" target="_blank" rel="noreferrer">drc@linux.vnet.ibm.com</a><br>
>>>     <mailto:<a href="mailto:drc@linux.vnet.ibm.com" target="_blank" rel="noreferrer">drc@linux.vnet.ibm.com</a>>>; Bruce Richardson<br>
>>>     > <<a href="mailto:bruce.richardson@intel.com" target="_blank" rel="noreferrer">bruce.richardson@intel.com</a> <mailto:<a href="mailto:bruce.richardson@intel.com" target="_blank" rel="noreferrer">bruce.richardson@intel.com</a>>>;<br>
>>>     Konstantin Ananyev<br>
>>>     > <<a href="mailto:konstantin.v.ananyev@yandex.ru" target="_blank" rel="noreferrer">konstantin.v.ananyev@yandex.ru</a><br>
>>>     <mailto:<a href="mailto:konstantin.v.ananyev@yandex.ru" target="_blank" rel="noreferrer">konstantin.v.ananyev@yandex.ru</a>>>; dev <<a href="mailto:dev@dpdk.org" target="_blank" rel="noreferrer">dev@dpdk.org</a><br>
>>>     <mailto:<a href="mailto:dev@dpdk.org" target="_blank" rel="noreferrer">dev@dpdk.org</a>>>; Yigit, Ferruh<br>
>>>     > <<a href="mailto:Ferruh.Yigit@amd.com" target="_blank" rel="noreferrer">Ferruh.Yigit@amd.com</a> <mailto:<a href="mailto:Ferruh.Yigit@amd.com" target="_blank" rel="noreferrer">Ferruh.Yigit@amd.com</a>>>; Thomas<br>
>>>     Monjalon <<a href="mailto:thomas@monjalon.net" target="_blank" rel="noreferrer">thomas@monjalon.net</a> <mailto:<a href="mailto:thomas@monjalon.net" target="_blank" rel="noreferrer">thomas@monjalon.net</a>>><br>
>>>     > Subject: Re: [PATCH v2 2/2] eal: remove NUMFLAGS enumeration<br>
>>>     ><br>
>>>     > Caution: This message originated from an External Source. Use<br>
>>>     proper caution<br>
>>>     > when opening attachments, clicking links, or responding.<br>
>>>     ><br>
>>>     ><br>
>>>     > On Wed, Sep 20, 2023 at 8:01 AM Stanisław Kardach<br>
>>>     <<a href="mailto:kda@semihalf.com" target="_blank" rel="noreferrer">kda@semihalf.com</a> <mailto:<a href="mailto:kda@semihalf.com" target="_blank" rel="noreferrer">kda@semihalf.com</a>>> wrote:<br>
>>>     > ><br>
>>>     > > On Tue, Sep 19, 2023 at 4:47 PM David Marchand<br>
>>>     > <<a href="mailto:david.marchand@redhat.com" target="_blank" rel="noreferrer">david.marchand@redhat.com</a> <mailto:<a href="mailto:david.marchand@redhat.com" target="_blank" rel="noreferrer">david.marchand@redhat.com</a>>> wrote:<br>
>>>     > > <snip><br>
>>>     > > > > Also I see you're still removing the RTE_CPUFLAG_NUMFLAGS<br>
>>>     (what I call a<br>
>>>     > last element canary). Why? If you're concerned with ABI, then<br>
>>>     we're talking about<br>
>>>     > an application linking dynamically with DPDK or talking via some<br>
>>>     RPC channel with<br>
>>>     > another DPDK application. So clashing with this definition does<br>
>>>     not come into<br>
>>>     > question. One should rather use rte_cpu_get_flag_enabled().<br>
>>>     > > > > Also if you want to introduce new features, one would add<br>
>>>     them yo the<br>
>>>     > rte_cpuflags headers, unless you'd like to not add those and keep an<br>
>>>     > undocumented list "above" the last defined element.<br>
>>>     > > > > Could you explain a bit more Your use-case?<br>
>>>     > > ><br>
>>>     > > > Hey Stanislaw,<br>
>>>     > > ><br>
>>>     > > > Talking generically, one problem with such pattern (having a LAST,<br>
>>>     > > > or MAX enum) is when an array sized with such a symbol is exposed.<br>
>>>     > > > As I mentionned in the past, this can have unwanted effects:<br>
>>>     > > ><br>
>>>     <a href="https://patchwork.dpdk.org/project/dpdk/patch/20230919140430.3251493" rel="noreferrer noreferrer" target="_blank">https://patchwork.dpdk.org/project/dpdk/patch/20230919140430.3251493</a><br>
>>>     <<a href="https://patchwork.dpdk.org/project/dpdk/patch/20230919140430.3251493" rel="noreferrer noreferrer" target="_blank">https://patchwork.dpdk.org/project/dpdk/patch/20230919140430.3251493</a>><br>
>>>     > > > -<a href="http://1-david.marchand@redhat.com/" rel="noreferrer noreferrer" target="_blank">1-david.marchand@redhat.com/</a><br>
>>>     <<a href="http://1-david.marchand@redhat.com/" rel="noreferrer noreferrer" target="_blank">http://1-david.marchand@redhat.com/</a>><br>
>>>     ><br>
>>>     > Argh... who broke copy/paste in my browser ?!<br>
>>>     > Wrt to MAX and arrays, I wanted to point at:<br>
>>>     ><br>
>>>     <a href="http://inbox.dpdk.org/dev/CAJFAV8xs5CVdE2xwRtaxk5vE_PiQMV5LY5tKStk3R1gOuR" rel="noreferrer noreferrer" target="_blank">http://inbox.dpdk.org/dev/CAJFAV8xs5CVdE2xwRtaxk5vE_PiQMV5LY5tKStk3R1gOuR</a> <<a href="http://inbox.dpdk.org/dev/CAJFAV8xs5CVdE2xwRtaxk5vE_PiQMV5LY5tKStk3R1gOuR" rel="noreferrer noreferrer" target="_blank">http://inbox.dpdk.org/dev/CAJFAV8xs5CVdE2xwRtaxk5vE_PiQMV5LY5tKStk3R1gOuR</a>><br>
>>>     > <a href="http://TsUw@mail.gmail.com/" rel="noreferrer noreferrer" target="_blank">TsUw@mail.gmail.com/</a> <<a href="http://TsUw@mail.gmail.com/" rel="noreferrer noreferrer" target="_blank">http://TsUw@mail.gmail.com/</a>><br>
>>>     ><br>
>>>     > > I agree, though I'd argue "LAST" and "MAX" semantics are a bit<br>
>>>     different. "LAST"<br>
>>>     > delimits the known enumeration territory while "MAX" is more of a<br>
>>>     `constepxr`<br>
>>>     > value type.<br>
>>>     > > ><br>
>>>     > > > Another issue is when an existing enum meaning changes: from the<br>
>>>     > > > application pov, the (old) MAX value is incorrect, but for the<br>
>>>     > > > library pov, a new meaning has been associated.<br>
>>>     > > > This may trigger bugs in the application when calling a function<br>
>>>     > > > that returns such an enum which never return this MAX value in<br>
>>>     the past.<br>
>>>     > > ><br>
>>>     > > > For at least those two reasons, removing those canary elements is<br>
>>>     > > > being done in DPDK.<br>
>>>     > > ><br>
>>>     > > > This specific removal has been announced:<br>
>>>     > > ><br>
>>>     <a href="https://patchwork.dpdk.org/project/dpdk/patch/20230919140430.3251493" rel="noreferrer noreferrer" target="_blank">https://patchwork.dpdk.org/project/dpdk/patch/20230919140430.3251493</a><br>
>>>     <<a href="https://patchwork.dpdk.org/project/dpdk/patch/20230919140430.3251493" rel="noreferrer noreferrer" target="_blank">https://patchwork.dpdk.org/project/dpdk/patch/20230919140430.3251493</a>><br>
>>>     > > > -<a href="http://1-david.marchand@redhat.com/" rel="noreferrer noreferrer" target="_blank">1-david.marchand@redhat.com/</a><br>
>>>     <<a href="http://1-david.marchand@redhat.com/" rel="noreferrer noreferrer" target="_blank">http://1-david.marchand@redhat.com/</a>><br>
>>>     > > Thanks for pointing this out but did you mean to link to the<br>
>>>     patch again here?<br>
>>>     ><br>
>>>     > Sorry, same here, bad copy/paste :-(.<br>
>>>     ><br>
>>>     > The intended link is:<br>
>>>     <a href="https://git.dpdk.org/dpdk/commit/?id=5da7c13521" rel="noreferrer noreferrer" target="_blank">https://git.dpdk.org/dpdk/commit/?id=5da7c13521</a><br>
>>>     <<a href="https://git.dpdk.org/dpdk/commit/?id=5da7c13521" rel="noreferrer noreferrer" target="_blank">https://git.dpdk.org/dpdk/commit/?id=5da7c13521</a>><br>
>>>     > The deprecation notice was badly formulated and this patch here is<br>
>>>     consistent with<br>
>>>     > it.<br>
>>>     ><br>
>>>     ><br>
>>>     > > ><br>
>>>     > > > Now, practically, when I look at the cpuflags API, I don't see us<br>
>>>     > > > exposed to those two issues wrt rte_cpu_flag_t, so maybe this<br>
>>>     change<br>
>>>     > > > is unneeded.<br>
>>>     > > > But on the other hand, is it really an issue for an application to<br>
>>>     > > > lose this (internal) information?<br>
>>>     > > I doubt it, maybe it could be used as a sanity check for<br>
>>>     choosing proper functors<br>
>>>     > in the application. Though the initial description of the reason<br>
>>>     behind this patch was<br>
>>>     > to not break the ABI and I don't think it does that. What it does<br>
>>>     is enforces users to<br>
>>>     > use explicit cpu flag values which is a good thing. Though if so,<br>
>>>     then it should be<br>
>>>     > stated in the commit description.<br>
>>>     ><br>
>>>     > I agree.<br>
>>>     > Siva, can you work on a new revision?<br>
>>>     ><br>
>>>     David, Stanislaw,<br>
>>><br>
>>>     The original motivation of this patch was to avoid ABI breakage with<br>
>>>     the introduction of new CPU flag<br>
>>>     "RTE_CPUFLAG_MONITORX"<br>
>>>     (<a href="http://mails.dpdk.org/archives/test-report/2023-April/382489.html" rel="noreferrer noreferrer" target="_blank">http://mails.dpdk.org/archives/test-report/2023-April/382489.html</a><br>
>>>     <<a href="http://mails.dpdk.org/archives/test-report/2023-April/382489.html" rel="noreferrer noreferrer" target="_blank">http://mails.dpdk.org/archives/test-report/2023-April/382489.html</a>>).<br>
>>><br>
>>>     Because of ABI breakage, the feature was postponed to this release.<br>
>>>     <a href="https://patchwork.dpdk.org/project/dpdk/patch/20230413115334.43172-3-sivaprasad.tummala@amd.com/" rel="noreferrer noreferrer" target="_blank">https://patchwork.dpdk.org/project/dpdk/patch/20230413115334.43172-3-sivaprasad.tummala@amd.com/</a> <<a href="https://patchwork.dpdk.org/project/dpdk/patch/20230413115334.43172-3-sivaprasad.tummala@amd.com/" rel="noreferrer noreferrer" target="_blank">https://patchwork.dpdk.org/project/dpdk/patch/20230413115334.43172-3-sivaprasad.tummala@amd.com/</a>><br>
>>><br>
>>> This test is flawed, reason being that the NUMFLAGS should not be<br>
>>> treated as a flag value and instead as a canary but this test is not<br>
>>> taking into account.<br>
>>><br>
>><br>
>> Hi Stanislaw,<br>
>><br>
>> Why test is flawed?<br>
>><br>
>> The enum in in the public header, so the 'RTE_CPUFLAG_NUMFLAGS' enum<br>
>> item, and there are APIs using the enum, so the enum exchanged between<br>
>> shared library and the application.<br>
> In a similar way lots of Linux uapi headers contain bits that should<br>
> not be used directly, even though they are defined there. The reason<br>
> for that is the C language syntax, not necessarily the intent of a<br>
> developer.<br>
> Since NUMFLAGS was a canary to make the flag handling code easier, it<br>
> should not be treated as a "real" value and hence my suggestion of a<br>
> flawed test. That said, NUMFLAGS does not bring enough value to not<br>
> remove it. :)<br>
><br>
<br>
Both it doesn't enough value to hang on, and we don't have control on<br>
how it is used by the application once it is exposed by the library.<br>
<br>
<br>
>><br>
>> Similar thing discussed before and when enum exchanged between<br>
>> application and shared library, there is an ABI breakage risk when enum<br>
>> extended and general tendency is to eliminate the MAX value to reduce<br>
>> the risk.<br>
> Agreed though as I have mentioned before, "MAX" has a different<br>
> semantics than "NUM". Then again since we have rte_cpu_feature_table,<br>
> we can RTE_DIM to check the user input.<br>
><br>
<br>
Their usage and intention on having them is same I think, can you please<br>
elaborate what is the difference between MAX and NUM enum items that is<br>
added as last item in an enum?<br></blockquote></div></div><div dir="auto">MAX specifies a semantic numerical value, such as MTU. NUM counts elements in an enumeration where elements describe some items and their value is just an implementation detail.</div><div dir="auto"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
<br>
>><br>
>><br>
>> When enum value sent from library to application, it is more clear that<br>
>> this can cause an ABI breakage, because application can receive a value<br>
>> that it is not aware in the build time, which can cause unexpected behavior.<br>
>> Simply think about a case application allocated array in<br>
>> 'RTE_CPUFLAG_NUMFLAGS' size and directly accessing the array index based<br>
>> on returned enum item value, if the enum extended in the new version of<br>
>> the shared library, this can cause invalid memory access in application.<br>
> Using the NUM enum element (which serves as a last item canary) to<br>
> size an array is not a good idea unless it's returned from a runtime<br>
> call. Otherwise one hits issues that you've described.<br>
><br>
<br>
I agree :), but that is a way to describe how it can be a problem.<br>
Also last time I argued similar to what you said, that application<br>
should check against MAX value before using it but I have been told<br>
not to assume what application does. My take from it is, expect worst<br>
from application as a library side developer.<br>
<br>
<br>
>><br>
>> When enum value sent from application to library, I am not quite sure<br>
>> how problematic it is to be honest. Like being in the<br>
>> 'rte_cpu_get_flag_enabled()' & 'rte_cpu_get_flag_name()' in question.<br>
>> Only when application sends 'RTE_CPUFLAG_NUMFLAGS' to<br>
>> 'rte_cpu_get_flag_name()', it expects a NULL returned, but this won't<br>
>> happen in new version of the shared library, not sure if this can cause<br>
>> any problem for the application.<br>
>> But as I mentioned, general guidance is to eliminate this kind of MAX<br>
>> enum value usage.<br>
>><br>
>><br>
>> And for this specific issue, although usage of the enum in<br>
>> 'rte_cpu_get_flag_enabled()' & 'rte_cpu_get_flag_name()' APIs is not<br>
>> clear if it cause ABI breakage,<br>
>> enum being embedded into the 'struct rte_bbdev_driver_info' struct<br>
>> doesn't leave a question, since this struct is returned from library to<br>
>> the application and change in the enum causes an ABI breakage.<br>
> Enum size does not change irrespective of changing its values. So<br>
> size-wise it's not an ABI breakage. Re-ordering values is an ABI<br>
> breakage.><br>
<br>
Agree it is not size-wise issue. But still an issue.<br>
<br>
<br>
>><br>
>><br>
>> Briefly, I think even appending to the end of 'enum rte_cpu_flag_t'<br>
>> cause ABI breakage and removing 'RTE_CPUFLAG_NUMFLAGS' helps to extend<br>
>> this enum in the future.<br>
>> And an outstanding deprecation notice already exists for this:<br>
>> <a href="https://git.dpdk.org/dpdk/tree/doc/guides/rel_notes/deprecation.rst?h=v23.07#n63" rel="noreferrer noreferrer" target="_blank">https://git.dpdk.org/dpdk/tree/doc/guides/rel_notes/deprecation.rst?h=v23.07#n63</a><br>
>><br>
>><br>
>>> Your change did not break the ABI because you have properly added the<br>
>>> new flag at the end.<br>
>>> So I would ask to change the commit description to mention that NUMFLAGS<br>
>>> is removed to:<br>
>>> 1. Prevent users from treating it as a usable value or an array size.<br>
>>> 2. Prevent false-positive failures in the ABI test.<br>
>>><br>
>>> Also it would be good to link to the aforementioned ABI test failure to<br>
>>> give readers some context when inspecting the git tree.<br>
>>><br>
>>><br>
>>><br>
>>>     Can you please add what exactly needs to be reworked in the new version.<br>
>>><br>
>>>     ><br>
>>>     > Thanks.<br>
>>>     ><br>
>>>     > --<br>
>>>     > David Marchand<br>
>>><br>
>><br>
> <br>
> <br>
<br>
</blockquote></div></div></div>