diff mbox series

[kvm-unit-tests,v2,2/2] s390x: Fix gcc 12 warning about array bounds

Message ID 20220520140546.311193-3-scgl@linux.ibm.com (mailing list archive)
State New, archived
Headers show
Series s390x: Avoid gcc 12 warnings | expand

Commit Message

Janis Schoetterl-Glausch May 20, 2022, 2:05 p.m. UTC
gcc 12 warns about pointer constant <4k dereference.
Silence the warning by using the extern lowcore symbol to derive the
pointers. This way gcc cannot conclude that the pointer is <4k.

Signed-off-by: Janis Schoetterl-Glausch <scgl@linux.ibm.com>
---
 lib/s390x/asm/mem.h | 4 ++++
 s390x/emulator.c    | 5 +++--
 s390x/skey.c        | 2 +-
 3 files changed, 8 insertions(+), 3 deletions(-)

Comments

Claudio Imbrenda May 24, 2022, 7:31 a.m. UTC | #1
On Fri, 20 May 2022 16:05:46 +0200
Janis Schoetterl-Glausch <scgl@linux.ibm.com> wrote:

> gcc 12 warns about pointer constant <4k dereference.
> Silence the warning by using the extern lowcore symbol to derive the
> pointers. This way gcc cannot conclude that the pointer is <4k.
> 
> Signed-off-by: Janis Schoetterl-Glausch <scgl@linux.ibm.com>
> ---
>  lib/s390x/asm/mem.h | 4 ++++
>  s390x/emulator.c    | 5 +++--
>  s390x/skey.c        | 2 +-
>  3 files changed, 8 insertions(+), 3 deletions(-)
> 
> diff --git a/lib/s390x/asm/mem.h b/lib/s390x/asm/mem.h
> index 845c00cc..e7901fe0 100644
> --- a/lib/s390x/asm/mem.h
> +++ b/lib/s390x/asm/mem.h
> @@ -7,6 +7,10 @@
>   */
>  #ifndef _ASMS390X_MEM_H_
>  #define _ASMS390X_MEM_H_
> +#include <asm/arch_def.h>
> +
> +/* pointer to 0 used to avoid compiler warnings */
> +uint8_t *mem_all = (uint8_t *)&lowcore;

this is defined in a .h, so maybe it's better to declare it static?


although maybe you can simply declare a macro like this:

#define MEM(x) ((void *)((uint8_t *)&lowcore + (x)))

and then just use MEM(x)...

(please find a less generic name for MEM, though)

>  
>  #define SKEY_ACC	0xf0
>  #define SKEY_FP		0x08
> diff --git a/s390x/emulator.c b/s390x/emulator.c
> index c9182ea4..afc3c213 100644
> --- a/s390x/emulator.c
> +++ b/s390x/emulator.c
> @@ -12,6 +12,7 @@
>  #include <asm/cpacf.h>
>  #include <asm/interrupt.h>
>  #include <asm/float.h>
> +#include <asm/mem.h>
>  #include <linux/compiler.h>
>  
>  static inline void __test_spm_ipm(uint8_t cc, uint8_t key)
> @@ -138,7 +139,7 @@ static __always_inline void __test_cpacf_invalid_parm(unsigned int opcode)
>  {
>  	report_prefix_push("invalid parm address");
>  	expect_pgm_int();
> -	__cpacf_query(opcode, (void *) -1);
> +	__cpacf_query(opcode, (cpacf_mask_t *)&mem_all[-1]);

...for example here MEM(-1)

>  	check_pgm_int_code(PGM_INT_CODE_ADDRESSING);
>  	report_prefix_pop();
>  }
> @@ -148,7 +149,7 @@ static __always_inline void __test_cpacf_protected_parm(unsigned int opcode)
>  	report_prefix_push("protected parm address");
>  	expect_pgm_int();
>  	low_prot_enable();
> -	__cpacf_query(opcode, (void *) 8);
> +	__cpacf_query(opcode, (cpacf_mask_t *)&mem_all[8]);

... MEM(8)

>  	low_prot_disable();
>  	check_pgm_int_code(PGM_INT_CODE_PROTECTION);
>  	report_prefix_pop();
> diff --git a/s390x/skey.c b/s390x/skey.c
> index 32bf1070..42bf598c 100644
> --- a/s390x/skey.c
> +++ b/s390x/skey.c
> @@ -349,7 +349,7 @@ static void test_set_prefix(void)
>  	set_storage_key(pagebuf, 0x28, 0);
>  	expect_pgm_int();
>  	install_page(root, virt_to_pte_phys(root, pagebuf), 0);
> -	set_prefix_key_1((uint32_t *)2048);
> +	set_prefix_key_1((uint32_t *)&mem_all[2048]);

... MEM(2048)

>  	install_page(root, 0, 0);
>  	check_pgm_int_code(PGM_INT_CODE_PROTECTION);
>  	report(get_prefix() == old_prefix, "did not set prefix");
Janis Schoetterl-Glausch May 24, 2022, 9:35 a.m. UTC | #2
On 5/24/22 09:31, Claudio Imbrenda wrote:
> On Fri, 20 May 2022 16:05:46 +0200
> Janis Schoetterl-Glausch <scgl@linux.ibm.com> wrote:
> 
>> gcc 12 warns about pointer constant <4k dereference.
>> Silence the warning by using the extern lowcore symbol to derive the
>> pointers. This way gcc cannot conclude that the pointer is <4k.
>>
>> Signed-off-by: Janis Schoetterl-Glausch <scgl@linux.ibm.com>
>> ---
>>  lib/s390x/asm/mem.h | 4 ++++
>>  s390x/emulator.c    | 5 +++--
>>  s390x/skey.c        | 2 +-
>>  3 files changed, 8 insertions(+), 3 deletions(-)
>>
>> diff --git a/lib/s390x/asm/mem.h b/lib/s390x/asm/mem.h
>> index 845c00cc..e7901fe0 100644
>> --- a/lib/s390x/asm/mem.h
>> +++ b/lib/s390x/asm/mem.h
>> @@ -7,6 +7,10 @@
>>   */
>>  #ifndef _ASMS390X_MEM_H_
>>  #define _ASMS390X_MEM_H_
>> +#include <asm/arch_def.h>
>> +
>> +/* pointer to 0 used to avoid compiler warnings */
>> +uint8_t *mem_all = (uint8_t *)&lowcore;
> 
> this is defined in a .h, so maybe it's better to declare it static?
> 
> 
> although maybe you can simply declare a macro like this:
> 
> #define MEM(x) ((void *)((uint8_t *)&lowcore + (x)))
> 
> and then just use MEM(x)...
> 
> (please find a less generic name for MEM, though)

MEM_ALL
MEM_ABS
MEM_OPAQUE
OPAQUE_PTR

Suggestions welcome, the last would be my favorite.

[...]
diff mbox series

Patch

diff --git a/lib/s390x/asm/mem.h b/lib/s390x/asm/mem.h
index 845c00cc..e7901fe0 100644
--- a/lib/s390x/asm/mem.h
+++ b/lib/s390x/asm/mem.h
@@ -7,6 +7,10 @@ 
  */
 #ifndef _ASMS390X_MEM_H_
 #define _ASMS390X_MEM_H_
+#include <asm/arch_def.h>
+
+/* pointer to 0 used to avoid compiler warnings */
+uint8_t *mem_all = (uint8_t *)&lowcore;
 
 #define SKEY_ACC	0xf0
 #define SKEY_FP		0x08
diff --git a/s390x/emulator.c b/s390x/emulator.c
index c9182ea4..afc3c213 100644
--- a/s390x/emulator.c
+++ b/s390x/emulator.c
@@ -12,6 +12,7 @@ 
 #include <asm/cpacf.h>
 #include <asm/interrupt.h>
 #include <asm/float.h>
+#include <asm/mem.h>
 #include <linux/compiler.h>
 
 static inline void __test_spm_ipm(uint8_t cc, uint8_t key)
@@ -138,7 +139,7 @@  static __always_inline void __test_cpacf_invalid_parm(unsigned int opcode)
 {
 	report_prefix_push("invalid parm address");
 	expect_pgm_int();
-	__cpacf_query(opcode, (void *) -1);
+	__cpacf_query(opcode, (cpacf_mask_t *)&mem_all[-1]);
 	check_pgm_int_code(PGM_INT_CODE_ADDRESSING);
 	report_prefix_pop();
 }
@@ -148,7 +149,7 @@  static __always_inline void __test_cpacf_protected_parm(unsigned int opcode)
 	report_prefix_push("protected parm address");
 	expect_pgm_int();
 	low_prot_enable();
-	__cpacf_query(opcode, (void *) 8);
+	__cpacf_query(opcode, (cpacf_mask_t *)&mem_all[8]);
 	low_prot_disable();
 	check_pgm_int_code(PGM_INT_CODE_PROTECTION);
 	report_prefix_pop();
diff --git a/s390x/skey.c b/s390x/skey.c
index 32bf1070..42bf598c 100644
--- a/s390x/skey.c
+++ b/s390x/skey.c
@@ -349,7 +349,7 @@  static void test_set_prefix(void)
 	set_storage_key(pagebuf, 0x28, 0);
 	expect_pgm_int();
 	install_page(root, virt_to_pte_phys(root, pagebuf), 0);
-	set_prefix_key_1((uint32_t *)2048);
+	set_prefix_key_1((uint32_t *)&mem_all[2048]);
 	install_page(root, 0, 0);
 	check_pgm_int_code(PGM_INT_CODE_PROTECTION);
 	report(get_prefix() == old_prefix, "did not set prefix");