diff mbox series

[kvm-unit-tests,v1] s390x: STFLE operates on doublewords

Message ID 20200401163305.31550-1-david@redhat.com (mailing list archive)
State New, archived
Headers show
Series [kvm-unit-tests,v1] s390x: STFLE operates on doublewords | expand

Commit Message

David Hildenbrand April 1, 2020, 4:33 p.m. UTC
STFLE operates on doublewords, not bytes. Passing in "256" resulted in
some ignored bits getting set. Not bad, but also not clean.

Let's just convert our stfle handling code to operate on doublewords.

Signed-off-by: David Hildenbrand <david@redhat.com>
---
 lib/s390x/asm/facility.h | 14 +++++++-------
 lib/s390x/io.c           |  2 +-
 2 files changed, 8 insertions(+), 8 deletions(-)

Comments

Christian Borntraeger April 1, 2020, 5:05 p.m. UTC | #1
On 01.04.20 18:33, David Hildenbrand wrote:
> STFLE operates on doublewords, not bytes. Passing in "256" resulted in
> some ignored bits getting set. Not bad, but also not clean.
> 
> Let's just convert our stfle handling code to operate on doublewords.
> 
> Signed-off-by: David Hildenbrand <david@redhat.com>

Reviewed-by: Christian Borntraeger <borntraeger@de.ibm.com>


> ---
>  lib/s390x/asm/facility.h | 14 +++++++-------
>  lib/s390x/io.c           |  2 +-
>  2 files changed, 8 insertions(+), 8 deletions(-)
> 
> diff --git a/lib/s390x/asm/facility.h b/lib/s390x/asm/facility.h
> index e34dc2c..def2705 100644
> --- a/lib/s390x/asm/facility.h
> +++ b/lib/s390x/asm/facility.h
> @@ -14,12 +14,12 @@
>  #include <asm/facility.h>
>  #include <asm/arch_def.h>
>  
> -#define NR_STFL_BYTES 256
> -extern uint8_t stfl_bytes[];
> +#define NB_STFL_DOUBLEWORDS 32
> +extern uint64_t stfl_doublewords[];
>  
>  static inline bool test_facility(int nr)
>  {
> -	return stfl_bytes[nr / 8] & (0x80U >> (nr % 8));
> +	return stfl_doublewords[nr / 64] & (0x8000000000000000UL >> (nr % 64));
>  }
>  
>  static inline void stfl(void)
> @@ -27,9 +27,9 @@ static inline void stfl(void)
>  	asm volatile("	stfl	0(0)\n" : : : "memory");
>  }
>  
> -static inline void stfle(uint8_t *fac, unsigned int len)
> +static inline void stfle(uint64_t *fac, unsigned int nb_doublewords)
>  {
> -	register unsigned long r0 asm("0") = len - 1;
> +	register unsigned long r0 asm("0") = nb_doublewords - 1;
>  
>  	asm volatile("	.insn	s,0xb2b00000,0(%1)\n"
>  		     : "+d" (r0) : "a" (fac) : "memory", "cc");
> @@ -40,9 +40,9 @@ static inline void setup_facilities(void)
>  	struct lowcore *lc = NULL;
>  
>  	stfl();
> -	memcpy(stfl_bytes, &lc->stfl, sizeof(lc->stfl));
> +	memcpy(stfl_doublewords, &lc->stfl, sizeof(lc->stfl));
>  	if (test_facility(7))
> -		stfle(stfl_bytes, NR_STFL_BYTES);
> +		stfle(stfl_doublewords, NB_STFL_DOUBLEWORDS);
>  }
>  
>  #endif
> diff --git a/lib/s390x/io.c b/lib/s390x/io.c
> index e091c37..c0f0bf7 100644
> --- a/lib/s390x/io.c
> +++ b/lib/s390x/io.c
> @@ -19,7 +19,7 @@
>  #include "smp.h"
>  
>  extern char ipl_args[];
> -uint8_t stfl_bytes[NR_STFL_BYTES] __attribute__((aligned(8)));
> +uint64_t stfl_doublewords[NB_STFL_DOUBLEWORDS];
>  
>  static struct spinlock lock;
>  
>
Janosch Frank April 2, 2020, 8:50 a.m. UTC | #2
On 4/1/20 6:33 PM, David Hildenbrand wrote:
> STFLE operates on doublewords, not bytes. Passing in "256" resulted in
> some ignored bits getting set. Not bad, but also not clean.
> 
> Let's just convert our stfle handling code to operate on doublewords.
> 
> Signed-off-by: David Hildenbrand <david@redhat.com>

Reviewed-by: Janosch Frank <frankja@linux.ibm.com>

> ---
>  lib/s390x/asm/facility.h | 14 +++++++-------
>  lib/s390x/io.c           |  2 +-
>  2 files changed, 8 insertions(+), 8 deletions(-)
> 
> diff --git a/lib/s390x/asm/facility.h b/lib/s390x/asm/facility.h
> index e34dc2c..def2705 100644
> --- a/lib/s390x/asm/facility.h
> +++ b/lib/s390x/asm/facility.h
> @@ -14,12 +14,12 @@
>  #include <asm/facility.h>
>  #include <asm/arch_def.h>
>  
> -#define NR_STFL_BYTES 256
> -extern uint8_t stfl_bytes[];
> +#define NB_STFL_DOUBLEWORDS 32
> +extern uint64_t stfl_doublewords[];
>  
>  static inline bool test_facility(int nr)
>  {
> -	return stfl_bytes[nr / 8] & (0x80U >> (nr % 8));
> +	return stfl_doublewords[nr / 64] & (0x8000000000000000UL >> (nr % 64));
>  }
>  
>  static inline void stfl(void)
> @@ -27,9 +27,9 @@ static inline void stfl(void)
>  	asm volatile("	stfl	0(0)\n" : : : "memory");
>  }
>  
> -static inline void stfle(uint8_t *fac, unsigned int len)
> +static inline void stfle(uint64_t *fac, unsigned int nb_doublewords)
>  {
> -	register unsigned long r0 asm("0") = len - 1;
> +	register unsigned long r0 asm("0") = nb_doublewords - 1;
>  
>  	asm volatile("	.insn	s,0xb2b00000,0(%1)\n"
>  		     : "+d" (r0) : "a" (fac) : "memory", "cc");
> @@ -40,9 +40,9 @@ static inline void setup_facilities(void)
>  	struct lowcore *lc = NULL;
>  
>  	stfl();
> -	memcpy(stfl_bytes, &lc->stfl, sizeof(lc->stfl));
> +	memcpy(stfl_doublewords, &lc->stfl, sizeof(lc->stfl));
>  	if (test_facility(7))
> -		stfle(stfl_bytes, NR_STFL_BYTES);
> +		stfle(stfl_doublewords, NB_STFL_DOUBLEWORDS);
>  }
>  
>  #endif
> diff --git a/lib/s390x/io.c b/lib/s390x/io.c
> index e091c37..c0f0bf7 100644
> --- a/lib/s390x/io.c
> +++ b/lib/s390x/io.c
> @@ -19,7 +19,7 @@
>  #include "smp.h"
>  
>  extern char ipl_args[];
> -uint8_t stfl_bytes[NR_STFL_BYTES] __attribute__((aligned(8)));
> +uint64_t stfl_doublewords[NB_STFL_DOUBLEWORDS];
>  
>  static struct spinlock lock;
>  
>
David Hildenbrand April 2, 2020, 8:51 a.m. UTC | #3
On 01.04.20 18:33, David Hildenbrand wrote:
> STFLE operates on doublewords, not bytes. Passing in "256" resulted in
> some ignored bits getting set. Not bad, but also not clean.
> 
> Let's just convert our stfle handling code to operate on doublewords.
> 
> Signed-off-by: David Hildenbrand <david@redhat.com>
> ---
>  lib/s390x/asm/facility.h | 14 +++++++-------
>  lib/s390x/io.c           |  2 +-
>  2 files changed, 8 insertions(+), 8 deletions(-)
> 
> diff --git a/lib/s390x/asm/facility.h b/lib/s390x/asm/facility.h
> index e34dc2c..def2705 100644
> --- a/lib/s390x/asm/facility.h
> +++ b/lib/s390x/asm/facility.h
> @@ -14,12 +14,12 @@
>  #include <asm/facility.h>
>  #include <asm/arch_def.h>
>  
> -#define NR_STFL_BYTES 256
> -extern uint8_t stfl_bytes[];
> +#define NB_STFL_DOUBLEWORDS 32
> +extern uint64_t stfl_doublewords[];
>  
>  static inline bool test_facility(int nr)
>  {
> -	return stfl_bytes[nr / 8] & (0x80U >> (nr % 8));
> +	return stfl_doublewords[nr / 64] & (0x8000000000000000UL >> (nr % 64));
>  }
>  
>  static inline void stfl(void)
> @@ -27,9 +27,9 @@ static inline void stfl(void)
>  	asm volatile("	stfl	0(0)\n" : : : "memory");
>  }
>  
> -static inline void stfle(uint8_t *fac, unsigned int len)
> +static inline void stfle(uint64_t *fac, unsigned int nb_doublewords)
>  {
> -	register unsigned long r0 asm("0") = len - 1;
> +	register unsigned long r0 asm("0") = nb_doublewords - 1;
>  
>  	asm volatile("	.insn	s,0xb2b00000,0(%1)\n"
>  		     : "+d" (r0) : "a" (fac) : "memory", "cc");
> @@ -40,9 +40,9 @@ static inline void setup_facilities(void)
>  	struct lowcore *lc = NULL;
>  
>  	stfl();
> -	memcpy(stfl_bytes, &lc->stfl, sizeof(lc->stfl));
> +	memcpy(stfl_doublewords, &lc->stfl, sizeof(lc->stfl));
>  	if (test_facility(7))
> -		stfle(stfl_bytes, NR_STFL_BYTES);
> +		stfle(stfl_doublewords, NB_STFL_DOUBLEWORDS);
>  }
>  
>  #endif
> diff --git a/lib/s390x/io.c b/lib/s390x/io.c
> index e091c37..c0f0bf7 100644
> --- a/lib/s390x/io.c
> +++ b/lib/s390x/io.c
> @@ -19,7 +19,7 @@
>  #include "smp.h"
>  
>  extern char ipl_args[];
> -uint8_t stfl_bytes[NR_STFL_BYTES] __attribute__((aligned(8)));
> +uint64_t stfl_doublewords[NB_STFL_DOUBLEWORDS];
>  
>  static struct spinlock lock;
>  
> 

Queued to

https://github.com/davidhildenbrand/kvm-unit-tests.git s390x-next

thanks for the review
diff mbox series

Patch

diff --git a/lib/s390x/asm/facility.h b/lib/s390x/asm/facility.h
index e34dc2c..def2705 100644
--- a/lib/s390x/asm/facility.h
+++ b/lib/s390x/asm/facility.h
@@ -14,12 +14,12 @@ 
 #include <asm/facility.h>
 #include <asm/arch_def.h>
 
-#define NR_STFL_BYTES 256
-extern uint8_t stfl_bytes[];
+#define NB_STFL_DOUBLEWORDS 32
+extern uint64_t stfl_doublewords[];
 
 static inline bool test_facility(int nr)
 {
-	return stfl_bytes[nr / 8] & (0x80U >> (nr % 8));
+	return stfl_doublewords[nr / 64] & (0x8000000000000000UL >> (nr % 64));
 }
 
 static inline void stfl(void)
@@ -27,9 +27,9 @@  static inline void stfl(void)
 	asm volatile("	stfl	0(0)\n" : : : "memory");
 }
 
-static inline void stfle(uint8_t *fac, unsigned int len)
+static inline void stfle(uint64_t *fac, unsigned int nb_doublewords)
 {
-	register unsigned long r0 asm("0") = len - 1;
+	register unsigned long r0 asm("0") = nb_doublewords - 1;
 
 	asm volatile("	.insn	s,0xb2b00000,0(%1)\n"
 		     : "+d" (r0) : "a" (fac) : "memory", "cc");
@@ -40,9 +40,9 @@  static inline void setup_facilities(void)
 	struct lowcore *lc = NULL;
 
 	stfl();
-	memcpy(stfl_bytes, &lc->stfl, sizeof(lc->stfl));
+	memcpy(stfl_doublewords, &lc->stfl, sizeof(lc->stfl));
 	if (test_facility(7))
-		stfle(stfl_bytes, NR_STFL_BYTES);
+		stfle(stfl_doublewords, NB_STFL_DOUBLEWORDS);
 }
 
 #endif
diff --git a/lib/s390x/io.c b/lib/s390x/io.c
index e091c37..c0f0bf7 100644
--- a/lib/s390x/io.c
+++ b/lib/s390x/io.c
@@ -19,7 +19,7 @@ 
 #include "smp.h"
 
 extern char ipl_args[];
-uint8_t stfl_bytes[NR_STFL_BYTES] __attribute__((aligned(8)));
+uint64_t stfl_doublewords[NB_STFL_DOUBLEWORDS];
 
 static struct spinlock lock;