lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <43c197da-0ff7-5b95-0778-e5b19fa4f942@redhat.com>
Date:   Thu, 10 Jun 2021 13:46:27 +0200
From:   Paolo Bonzini <pbonzini@...hat.com>
To:     Yanan Wang <wangyanan55@...wei.com>,
        Axel Rasmussen <axelrasmussen@...gle.com>,
        Ben Gardon <bgardon@...gle.com>,
        Andrew Jones <drjones@...hat.com>
Cc:     kvm@...r.kernel.org, linux-kselftest@...r.kernel.org,
        linux-kernel@...r.kernel.org, yuzenghui@...wei.com,
        wanghaibin.wang@...wei.com
Subject: Re: [PATCH] KVM: selftests: Fix compiling errors when initializing
 the static structure

On 10/06/21 10:54, Yanan Wang wrote:
> Errors like below were produced from test_util.c when compiling the KVM
> selftests on my local platform.
> 
> lib/test_util.c: In function 'vm_mem_backing_src_alias':
> lib/test_util.c:177:12: error: initializer element is not constant
>      .flag = anon_flags,
>              ^~~~~~~~~~
> lib/test_util.c:177:12: note: (near initialization for 'aliases[0].flag')
> 
> The reason is that we are using non-const expressions to initialize the
> static structure, which will probably trigger a compiling error/warning
> on stricter GCC versions. Fix it by converting the two const variables
> "anon_flags" and "anon_huge_flags" into more stable macros.
> 
> Fixes: b3784bc28ccc0 ("KVM: selftests: refactor vm_mem_backing_src_type flags")
> Reported-by: Zenghui Yu <yuzenghui@...wei.com>
> Signed-off-by: Yanan Wang <wangyanan55@...wei.com>
> ---
>   tools/testing/selftests/kvm/lib/test_util.c | 38 ++++++++++-----------
>   1 file changed, 19 insertions(+), 19 deletions(-)
> 
> diff --git a/tools/testing/selftests/kvm/lib/test_util.c b/tools/testing/selftests/kvm/lib/test_util.c
> index 6ad6c8276b2e..af1031fed97f 100644
> --- a/tools/testing/selftests/kvm/lib/test_util.c
> +++ b/tools/testing/selftests/kvm/lib/test_util.c
> @@ -166,75 +166,75 @@ size_t get_def_hugetlb_pagesz(void)
>   	return 0;
>   }
>   
> +#define ANON_FLAGS	(MAP_PRIVATE | MAP_ANONYMOUS)
> +#define ANON_HUGE_FLAGS	(ANON_FLAGS | MAP_HUGETLB)
> +
>   const struct vm_mem_backing_src_alias *vm_mem_backing_src_alias(uint32_t i)
>   {
> -	static const int anon_flags = MAP_PRIVATE | MAP_ANONYMOUS;
> -	static const int anon_huge_flags = anon_flags | MAP_HUGETLB;
> -
>   	static const struct vm_mem_backing_src_alias aliases[] = {
>   		[VM_MEM_SRC_ANONYMOUS] = {
>   			.name = "anonymous",
> -			.flag = anon_flags,
> +			.flag = ANON_FLAGS,
>   		},
>   		[VM_MEM_SRC_ANONYMOUS_THP] = {
>   			.name = "anonymous_thp",
> -			.flag = anon_flags,
> +			.flag = ANON_FLAGS,
>   		},
>   		[VM_MEM_SRC_ANONYMOUS_HUGETLB] = {
>   			.name = "anonymous_hugetlb",
> -			.flag = anon_huge_flags,
> +			.flag = ANON_HUGE_FLAGS,
>   		},
>   		[VM_MEM_SRC_ANONYMOUS_HUGETLB_16KB] = {
>   			.name = "anonymous_hugetlb_16kb",
> -			.flag = anon_huge_flags | MAP_HUGE_16KB,
> +			.flag = ANON_HUGE_FLAGS | MAP_HUGE_16KB,
>   		},
>   		[VM_MEM_SRC_ANONYMOUS_HUGETLB_64KB] = {
>   			.name = "anonymous_hugetlb_64kb",
> -			.flag = anon_huge_flags | MAP_HUGE_64KB,
> +			.flag = ANON_HUGE_FLAGS | MAP_HUGE_64KB,
>   		},
>   		[VM_MEM_SRC_ANONYMOUS_HUGETLB_512KB] = {
>   			.name = "anonymous_hugetlb_512kb",
> -			.flag = anon_huge_flags | MAP_HUGE_512KB,
> +			.flag = ANON_HUGE_FLAGS | MAP_HUGE_512KB,
>   		},
>   		[VM_MEM_SRC_ANONYMOUS_HUGETLB_1MB] = {
>   			.name = "anonymous_hugetlb_1mb",
> -			.flag = anon_huge_flags | MAP_HUGE_1MB,
> +			.flag = ANON_HUGE_FLAGS | MAP_HUGE_1MB,
>   		},
>   		[VM_MEM_SRC_ANONYMOUS_HUGETLB_2MB] = {
>   			.name = "anonymous_hugetlb_2mb",
> -			.flag = anon_huge_flags | MAP_HUGE_2MB,
> +			.flag = ANON_HUGE_FLAGS | MAP_HUGE_2MB,
>   		},
>   		[VM_MEM_SRC_ANONYMOUS_HUGETLB_8MB] = {
>   			.name = "anonymous_hugetlb_8mb",
> -			.flag = anon_huge_flags | MAP_HUGE_8MB,
> +			.flag = ANON_HUGE_FLAGS | MAP_HUGE_8MB,
>   		},
>   		[VM_MEM_SRC_ANONYMOUS_HUGETLB_16MB] = {
>   			.name = "anonymous_hugetlb_16mb",
> -			.flag = anon_huge_flags | MAP_HUGE_16MB,
> +			.flag = ANON_HUGE_FLAGS | MAP_HUGE_16MB,
>   		},
>   		[VM_MEM_SRC_ANONYMOUS_HUGETLB_32MB] = {
>   			.name = "anonymous_hugetlb_32mb",
> -			.flag = anon_huge_flags | MAP_HUGE_32MB,
> +			.flag = ANON_HUGE_FLAGS | MAP_HUGE_32MB,
>   		},
>   		[VM_MEM_SRC_ANONYMOUS_HUGETLB_256MB] = {
>   			.name = "anonymous_hugetlb_256mb",
> -			.flag = anon_huge_flags | MAP_HUGE_256MB,
> +			.flag = ANON_HUGE_FLAGS | MAP_HUGE_256MB,
>   		},
>   		[VM_MEM_SRC_ANONYMOUS_HUGETLB_512MB] = {
>   			.name = "anonymous_hugetlb_512mb",
> -			.flag = anon_huge_flags | MAP_HUGE_512MB,
> +			.flag = ANON_HUGE_FLAGS | MAP_HUGE_512MB,
>   		},
>   		[VM_MEM_SRC_ANONYMOUS_HUGETLB_1GB] = {
>   			.name = "anonymous_hugetlb_1gb",
> -			.flag = anon_huge_flags | MAP_HUGE_1GB,
> +			.flag = ANON_HUGE_FLAGS | MAP_HUGE_1GB,
>   		},
>   		[VM_MEM_SRC_ANONYMOUS_HUGETLB_2GB] = {
>   			.name = "anonymous_hugetlb_2gb",
> -			.flag = anon_huge_flags | MAP_HUGE_2GB,
> +			.flag = ANON_HUGE_FLAGS | MAP_HUGE_2GB,
>   		},
>   		[VM_MEM_SRC_ANONYMOUS_HUGETLB_16GB] = {
>   			.name = "anonymous_hugetlb_16gb",
> -			.flag = anon_huge_flags | MAP_HUGE_16GB,
> +			.flag = ANON_HUGE_FLAGS | MAP_HUGE_16GB,
>   		},
>   		[VM_MEM_SRC_SHMEM] = {
>   			.name = "shmem",
> 

Queued, thanks.

Paolo

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ