diff mbox series

[kvm-unit-tests,v2,1/3] lib: s390x: hw: rework do_detect_host so we don't need allocation

Message ID 20231031095519.73311-2-frankja@linux.ibm.com (mailing list archive)
State New, archived
Headers show
Series s390x: Improve console handling | expand

Commit Message

Janosch Frank Oct. 31, 2023, 9:55 a.m. UTC
The current implementation needs to allocate a page for stsi 1.1.1 and
3.2.2. As such it's not usable before the allocator is set
up.

Unfortunately we might end up with detect_host calls before the
allocator setup is done. For example in the SCLP console setup code.

Let's allocate the stsi storage on the stack to solve that problem.

Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
---
 lib/s390x/hardware.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

Comments

Claudio Imbrenda Oct. 31, 2023, 10 a.m. UTC | #1
On Tue, 31 Oct 2023 09:55:17 +0000
Janosch Frank <frankja@linux.ibm.com> wrote:

> The current implementation needs to allocate a page for stsi 1.1.1 and
> 3.2.2. As such it's not usable before the allocator is set
> up.
> 
> Unfortunately we might end up with detect_host calls before the
> allocator setup is done. For example in the SCLP console setup code.
> 
> Let's allocate the stsi storage on the stack to solve that problem.
> 
> Signed-off-by: Janosch Frank <frankja@linux.ibm.com>

I like this solution :)

Reviewed-by: Claudio Imbrenda <imbrenda@linux.ibm.com>

> ---
>  lib/s390x/hardware.c | 11 +++++------
>  1 file changed, 5 insertions(+), 6 deletions(-)
> 
> diff --git a/lib/s390x/hardware.c b/lib/s390x/hardware.c
> index 2bcf9c4c..21752562 100644
> --- a/lib/s390x/hardware.c
> +++ b/lib/s390x/hardware.c
> @@ -13,6 +13,7 @@
>  #include <libcflat.h>
>  #include <alloc_page.h>
>  #include <asm/arch_def.h>
> +#include <asm/page.h>
>  #include "hardware.h"
>  #include "stsi.h"
>  
> @@ -21,9 +22,10 @@ static const uint8_t qemu_ebcdic[] = { 0xd8, 0xc5, 0xd4, 0xe4 };
>  /* The string "KVM/" in EBCDIC */
>  static const uint8_t kvm_ebcdic[] = { 0xd2, 0xe5, 0xd4, 0x61 };
>  
> -static enum s390_host do_detect_host(void *buf)
> +static enum s390_host do_detect_host(void)
>  {
> -	struct sysinfo_3_2_2 *stsi_322 = buf;
> +	uint8_t buf[PAGE_SIZE] __attribute__((aligned(PAGE_SIZE)));
> +	struct sysinfo_3_2_2 *stsi_322 = (struct sysinfo_3_2_2 *)buf;
>  
>  	if (stsi_get_fc() == 2)
>  		return HOST_IS_LPAR;
> @@ -56,14 +58,11 @@ enum s390_host detect_host(void)
>  {
>  	static enum s390_host host = HOST_IS_UNKNOWN;
>  	static bool initialized = false;
> -	void *buf;
>  
>  	if (initialized)
>  		return host;
>  
> -	buf = alloc_page();
> -	host = do_detect_host(buf);
> -	free_page(buf);
> +	host = do_detect_host();
>  	initialized = true;
>  	return host;
>  }
diff mbox series

Patch

diff --git a/lib/s390x/hardware.c b/lib/s390x/hardware.c
index 2bcf9c4c..21752562 100644
--- a/lib/s390x/hardware.c
+++ b/lib/s390x/hardware.c
@@ -13,6 +13,7 @@ 
 #include <libcflat.h>
 #include <alloc_page.h>
 #include <asm/arch_def.h>
+#include <asm/page.h>
 #include "hardware.h"
 #include "stsi.h"
 
@@ -21,9 +22,10 @@  static const uint8_t qemu_ebcdic[] = { 0xd8, 0xc5, 0xd4, 0xe4 };
 /* The string "KVM/" in EBCDIC */
 static const uint8_t kvm_ebcdic[] = { 0xd2, 0xe5, 0xd4, 0x61 };
 
-static enum s390_host do_detect_host(void *buf)
+static enum s390_host do_detect_host(void)
 {
-	struct sysinfo_3_2_2 *stsi_322 = buf;
+	uint8_t buf[PAGE_SIZE] __attribute__((aligned(PAGE_SIZE)));
+	struct sysinfo_3_2_2 *stsi_322 = (struct sysinfo_3_2_2 *)buf;
 
 	if (stsi_get_fc() == 2)
 		return HOST_IS_LPAR;
@@ -56,14 +58,11 @@  enum s390_host detect_host(void)
 {
 	static enum s390_host host = HOST_IS_UNKNOWN;
 	static bool initialized = false;
-	void *buf;
 
 	if (initialized)
 		return host;
 
-	buf = alloc_page();
-	host = do_detect_host(buf);
-	free_page(buf);
+	host = do_detect_host();
 	initialized = true;
 	return host;
 }