eal/windows: fix memory management macros usage

Message ID 20231114170529.176665-1-getelson@nvidia.com (mailing list archive)
State Accepted, archived
Delegated to: David Marchand
Headers
Series eal/windows: fix memory management macros usage |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/loongarch-compilation success Compilation OK
ci/loongarch-unit-testing success Unit Testing PASS
ci/github-robot: build success github build: passed
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-compile-amd64-testing success Testing PASS
ci/iol-sample-apps-testing warning Testing issues
ci/iol-unit-amd64-testing fail Testing issues
ci/iol-unit-arm64-testing success Testing PASS
ci/iol-compile-arm64-testing success Testing PASS
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS
ci/intel-Functional success Functional PASS

Commit Message

Gregory Etelson Nov. 14, 2023, 5:05 p.m. UTC
  Windows compilation with cross-mingw on Fedora 39 failed
because MEM_REPLACE_PLACEHOLDER and MEM_RESERVE_PLACEHOLDER were
already defined in the compiler environment:

eal_memory.c:77: error: "MEM_REPLACE_PLACEHOLDER" redefined
/usr/x86_64-w64-mingw32/sys-root/mingw/include/winnt.h:5710: note:
this is the location of the previous definition

eal_memory.c:78: error: "MEM_RESERVE_PLACEHOLDER" redefined
/usr/x86_64-w64-mingw32/sys-root/mingw/include/winnt.h:5715: note:
this is the location of the previous definition

The patch masks MEM_REPLACE_PLACEHOLDER and MEM_RESERVE_PLACEHOLDER
macros if they were pre-defined by compiler.

The patch also masks MEM_COALESCE_PLACEHOLDERS and
MEM_PRESERVE_PLACEHOLDER to prevent similar errors.

Fixes: 2a5d547a4a9b ("eal/windows: implement basic memory management")

Cc: stable@dpdk.org
Signed-off-by: Gregory Etelson <getelson@nvidia.com>
---
 lib/eal/windows/eal_memory.c | 8 ++++++++
 1 file changed, 8 insertions(+)
  

Comments

Tyler Retzlaff Nov. 14, 2023, 5:46 p.m. UTC | #1
On Tue, Nov 14, 2023 at 07:05:29PM +0200, Gregory Etelson wrote:
> Windows compilation with cross-mingw on Fedora 39 failed
> because MEM_REPLACE_PLACEHOLDER and MEM_RESERVE_PLACEHOLDER were
> already defined in the compiler environment:
> 
> eal_memory.c:77: error: "MEM_REPLACE_PLACEHOLDER" redefined
> /usr/x86_64-w64-mingw32/sys-root/mingw/include/winnt.h:5710: note:
> this is the location of the previous definition
> 
> eal_memory.c:78: error: "MEM_RESERVE_PLACEHOLDER" redefined
> /usr/x86_64-w64-mingw32/sys-root/mingw/include/winnt.h:5715: note:
> this is the location of the previous definition
> 
> The patch masks MEM_REPLACE_PLACEHOLDER and MEM_RESERVE_PLACEHOLDER
> macros if they were pre-defined by compiler.
> 
> The patch also masks MEM_COALESCE_PLACEHOLDERS and
> MEM_PRESERVE_PLACEHOLDER to prevent similar errors.
> 
> Fixes: 2a5d547a4a9b ("eal/windows: implement basic memory management")
> 
> Cc: stable@dpdk.org
> Signed-off-by: Gregory Etelson <getelson@nvidia.com>
> ---

since we are duplicating something that comes from something else that
has been duplicated out of windows WDK here it might be a reasonable
safety check to verify that our duplicated values match our
expectations?

#ifndef MEM_COALESCE_PLACEHOLDERS
#define MEM_COALESCE_PLACEHOLDERS 0x00000001
#else
static_assert(MEM_COALESCE_PLACEHOLDERS == 0x00000001, "...")
#endif

either way, this is straight forward.

Acked-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
  
Gregory Etelson Nov. 14, 2023, 6:16 p.m. UTC | #2
Hello Tyler,

>
> since we are duplicating something that comes from something else that
> has been duplicated out of windows WDK here it might be a reasonable
> safety check to verify that our duplicated values match our
> expectations?

MEM_COALESCE_PLACEHOLDERS, MEM_PRESERVE_PLACEHOLDER,
MEM_REPLACE_PLACEHOLDER and MEM_RESERVE_PLACEHOLDER
are defined in Win32 API.

DPDK has no expectations about these values. DPDK needs them as parameters 
to the VirtualX function calls.
It looks like the macros were added to EAL because they were missing in 
mingw.

Once compiler environment was fixed, the proper order was restored.

Regards,
Gregory


>
> #ifndef MEM_COALESCE_PLACEHOLDERS
> #define MEM_COALESCE_PLACEHOLDERS 0x00000001
> #else
> static_assert(MEM_COALESCE_PLACEHOLDERS == 0x00000001, "...")
> #endif
>
> either way, this is straight forward.
>
> Acked-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
>
>
  
Tyler Retzlaff Nov. 14, 2023, 6:22 p.m. UTC | #3
On Tue, Nov 14, 2023 at 08:16:22PM +0200, Etelson, Gregory wrote:
> Hello Tyler,
> 
> >
> >since we are duplicating something that comes from something else that
> >has been duplicated out of windows WDK here it might be a reasonable
> >safety check to verify that our duplicated values match our
> >expectations?
> 
> MEM_COALESCE_PLACEHOLDERS, MEM_PRESERVE_PLACEHOLDER,
> MEM_REPLACE_PLACEHOLDER and MEM_RESERVE_PLACEHOLDER
> are defined in Win32 API.
> 
> DPDK has no expectations about these values. DPDK needs them as
> parameters to the VirtualX function calls.
> It looks like the macros were added to EAL because they were missing
> in mingw.
> 
> Once compiler environment was fixed, the proper order was restored.

yes, there is a lag between when names appear in the actual WDK and when
mingw takes a the snapshot of the headers. so long as the copy they take
is only from released WDK versions that align with an OS we shouldn't
expect the values to change but if the duplicated names in dpdk were
based upon an insider (preview version of SDK) value that later got changed
there could be a misalignment. unlikely but possible.

> 
> Regards,
> Gregory
> 
> 
> >
> >#ifndef MEM_COALESCE_PLACEHOLDERS
> >#define MEM_COALESCE_PLACEHOLDERS 0x00000001
> >#else
> >static_assert(MEM_COALESCE_PLACEHOLDERS == 0x00000001, "...")
> >#endif
> >
> >either way, this is straight forward.
> >
> >Acked-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
> >
> >
  
Gregory Etelson Nov. 14, 2023, 7:14 p.m. UTC | #4
Hello Tyler,

>>>
>>> since we are duplicating something that comes from something else that
>>> has been duplicated out of windows WDK here it might be a reasonable
>>> safety check to verify that our duplicated values match our
>>> expectations?
>>
>> MEM_COALESCE_PLACEHOLDERS, MEM_PRESERVE_PLACEHOLDER,
>> MEM_REPLACE_PLACEHOLDER and MEM_RESERVE_PLACEHOLDER
>> are defined in Win32 API.
>>
>> DPDK has no expectations about these values. DPDK needs them as
>> parameters to the VirtualX function calls.
>> It looks like the macros were added to EAL because they were missing
>> in mingw.
>>
>> Once compiler environment was fixed, the proper order was restored.
>
> yes, there is a lag between when names appear in the actual WDK and when
> mingw takes a the snapshot of the headers. so long as the copy they take
> is only from released WDK versions that align with an OS we shouldn't
> expect the values to change but if the duplicated names in dpdk were
> based upon an insider (preview version of SDK) value that later got changed
> there could be a misalignment. unlikely but possible.
>

DPDK matrix works with official OS compiler versions.
Such compilers will not provide bad API.
As for non-official compilers or releases, they come without any warranty.

Regards,
Gregory
  
Dmitry Kozlyuk Nov. 14, 2023, 7:19 p.m. UTC | #5
2023-11-14 10:22 (UTC-0800), Tyler Retzlaff:
> On Tue, Nov 14, 2023 at 08:16:22PM +0200, Etelson, Gregory wrote:
> > Hello Tyler,
> >   
> > >
> > >since we are duplicating something that comes from something else that
> > >has been duplicated out of windows WDK here it might be a reasonable
> > >safety check to verify that our duplicated values match our
> > >expectations?  
> > 
> > MEM_COALESCE_PLACEHOLDERS, MEM_PRESERVE_PLACEHOLDER,
> > MEM_REPLACE_PLACEHOLDER and MEM_RESERVE_PLACEHOLDER
> > are defined in Win32 API.
> > 
> > DPDK has no expectations about these values. DPDK needs them as
> > parameters to the VirtualX function calls.
> > It looks like the macros were added to EAL because they were missing
> > in mingw.
> > 
> > Once compiler environment was fixed, the proper order was restored.  
> 
> yes, there is a lag between when names appear in the actual WDK and when
> mingw takes a the snapshot of the headers. so long as the copy they take
> is only from released WDK versions that align with an OS we shouldn't
> expect the values to change but if the duplicated names in dpdk were
> based upon an insider (preview version of SDK) value that later got changed
> there could be a misalignment. unlikely but possible.

I think we should trust the toolchain unless there is an known bug,
i.e. the patch is good as-is.
  
Dmitry Kozlyuk Nov. 14, 2023, 7:19 p.m. UTC | #6
2023-11-14 19:05 (UTC+0200), Gregory Etelson:
> Windows compilation with cross-mingw on Fedora 39 failed
> because MEM_REPLACE_PLACEHOLDER and MEM_RESERVE_PLACEHOLDER were
> already defined in the compiler environment:
> 
> eal_memory.c:77: error: "MEM_REPLACE_PLACEHOLDER" redefined
> /usr/x86_64-w64-mingw32/sys-root/mingw/include/winnt.h:5710: note:
> this is the location of the previous definition
> 
> eal_memory.c:78: error: "MEM_RESERVE_PLACEHOLDER" redefined
> /usr/x86_64-w64-mingw32/sys-root/mingw/include/winnt.h:5715: note:
> this is the location of the previous definition
> 
> The patch masks MEM_REPLACE_PLACEHOLDER and MEM_RESERVE_PLACEHOLDER
> macros if they were pre-defined by compiler.
> 
> The patch also masks MEM_COALESCE_PLACEHOLDERS and
> MEM_PRESERVE_PLACEHOLDER to prevent similar errors.
> 
> Fixes: 2a5d547a4a9b ("eal/windows: implement basic memory management")
> 
> Cc: stable@dpdk.org
> Signed-off-by: Gregory Etelson <getelson@nvidia.com>

Acked-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
  
Thomas Monjalon Nov. 22, 2023, 4:47 p.m. UTC | #7
14/11/2023 20:19, Dmitry Kozlyuk:
> 2023-11-14 19:05 (UTC+0200), Gregory Etelson:
> > Windows compilation with cross-mingw on Fedora 39 failed
> > because MEM_REPLACE_PLACEHOLDER and MEM_RESERVE_PLACEHOLDER were
> > already defined in the compiler environment:
> > 
> > eal_memory.c:77: error: "MEM_REPLACE_PLACEHOLDER" redefined
> > /usr/x86_64-w64-mingw32/sys-root/mingw/include/winnt.h:5710: note:
> > this is the location of the previous definition
> > 
> > eal_memory.c:78: error: "MEM_RESERVE_PLACEHOLDER" redefined
> > /usr/x86_64-w64-mingw32/sys-root/mingw/include/winnt.h:5715: note:
> > this is the location of the previous definition
> > 
> > The patch masks MEM_REPLACE_PLACEHOLDER and MEM_RESERVE_PLACEHOLDER
> > macros if they were pre-defined by compiler.
> > 
> > The patch also masks MEM_COALESCE_PLACEHOLDERS and
> > MEM_PRESERVE_PLACEHOLDER to prevent similar errors.
> > 
> > Fixes: 2a5d547a4a9b ("eal/windows: implement basic memory management")
> > 
> > Cc: stable@dpdk.org
> > Signed-off-by: Gregory Etelson <getelson@nvidia.com>
> 
> Acked-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>

Acked-by: Thomas Monjalon <thomas@monjalon.net>
  
David Marchand Nov. 22, 2023, 4:56 p.m. UTC | #8
On Tue, Nov 14, 2023 at 6:06 PM Gregory Etelson <getelson@nvidia.com> wrote:
>
> Windows compilation with cross-mingw on Fedora 39 failed
> because MEM_REPLACE_PLACEHOLDER and MEM_RESERVE_PLACEHOLDER were
> already defined in the compiler environment:
>
> eal_memory.c:77: error: "MEM_REPLACE_PLACEHOLDER" redefined
> /usr/x86_64-w64-mingw32/sys-root/mingw/include/winnt.h:5710: note:
> this is the location of the previous definition
>
> eal_memory.c:78: error: "MEM_RESERVE_PLACEHOLDER" redefined
> /usr/x86_64-w64-mingw32/sys-root/mingw/include/winnt.h:5715: note:
> this is the location of the previous definition
>
> The patch masks MEM_REPLACE_PLACEHOLDER and MEM_RESERVE_PLACEHOLDER
> macros if they were pre-defined by compiler.
>
> The patch also masks MEM_COALESCE_PLACEHOLDERS and
> MEM_PRESERVE_PLACEHOLDER to prevent similar errors.
>
> Fixes: 2a5d547a4a9b ("eal/windows: implement basic memory management")
> Cc: stable@dpdk.org
>
> Signed-off-by: Gregory Etelson <getelson@nvidia.com>

Acked-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
Acked-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
Acked-by: Thomas Monjalon <thomas@monjalon.net>

For the record, the same issue has been reported with Ubuntu 23.10.

Applied, thanks.
  

Patch

diff --git a/lib/eal/windows/eal_memory.c b/lib/eal/windows/eal_memory.c
index 215d768e2c..31410a41fd 100644
--- a/lib/eal/windows/eal_memory.c
+++ b/lib/eal/windows/eal_memory.c
@@ -72,10 +72,18 @@  static VirtualAlloc2_type VirtualAlloc2_ptr;
 
 #ifdef RTE_TOOLCHAIN_GCC
 
+#ifndef MEM_COALESCE_PLACEHOLDERS
 #define MEM_COALESCE_PLACEHOLDERS 0x00000001
+#endif
+#ifndef MEM_PRESERVE_PLACEHOLDER
 #define MEM_PRESERVE_PLACEHOLDER  0x00000002
+#endif
+#ifndef MEM_REPLACE_PLACEHOLDER
 #define MEM_REPLACE_PLACEHOLDER   0x00004000
+#endif
+#ifndef MEM_RESERVE_PLACEHOLDER
 #define MEM_RESERVE_PLACEHOLDER   0x00040000
+#endif
 
 int
 eal_mem_win32api_init(void)