All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrew Jones <drjones@redhat.com>
To: kvm@vger.kernel.org
Cc: rkrcmar@redhat.com, pbonzini@redhat.com, lvivier@redhat.com,
	thuth@redhat.com
Subject: [PATCH kvm-unit-tests 13/15] x86: enable environ
Date: Fri, 13 Jan 2017 19:15:31 +0100	[thread overview]
Message-ID: <20170113181533.15145-14-drjones@redhat.com> (raw)
In-Reply-To: <20170113181533.15145-1-drjones@redhat.com>

Give x86 unit tests access to environment variables. The
environment variables are passed to the unit test with
'-initrd env-file'.

Signed-off-by: Andrew Jones <drjones@redhat.com>
---
 x86/run         |  4 +++-
 lib/x86/setup.c | 16 ++++++++++++++++
 x86/cstart.S    |  2 ++
 x86/cstart64.S  |  2 ++
 4 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/x86/run b/x86/run
index 10a6e6d3421c..867a1cccd3ba 100755
--- a/x86/run
+++ b/x86/run
@@ -42,7 +42,9 @@ else
 	pc_testdev="-device testdev,chardev=testlog -chardev file,id=testlog,path=msr.out"
 fi
 
-command="${qemu} -nodefaults -enable-kvm $pc_testdev -vnc none -serial stdio $pci_testdev $hyperv_testdev -kernel"
+command="${qemu} -nodefaults -enable-kvm $pc_testdev -vnc none -serial stdio $pci_testdev $hyperv_testdev"
+[ -f "$ENV" ] && command+=" -initrd $ENV"
+command+=" -kernel"
 command="$(timeout_cmd) $command"
 echo ${command} "$@"
 
diff --git a/lib/x86/setup.c b/lib/x86/setup.c
index e5df6ce95b64..804ba3a1b86e 100644
--- a/lib/x86/setup.c
+++ b/lib/x86/setup.c
@@ -12,9 +12,15 @@
 #define MB_MOD_START	 0
 #define MB_MOD_END	 4
 
+#define ENV_SIZE 16384
+
+extern void setup_env(char *env, int size);
+
 char *initrd;
 u32 initrd_size;
 
+static char env[ENV_SIZE];
+
 void setup_get_initrd(u8 *bootinfo)
 {
 	u32 *mods_addr, *mod_start, *mod_end;
@@ -29,3 +35,13 @@ void setup_get_initrd(u8 *bootinfo)
 	initrd = (char *)(ulong)*mod_start;
 	initrd_size = *mod_end - *mod_start;
 }
+
+void setup_environ(void)
+{
+	if (initrd) {
+		/* environ is currently the only file in the initrd */
+		u32 size = MIN(initrd_size, ENV_SIZE);
+		memcpy(env, initrd, size);
+		setup_env(env, size);
+	}
+}
diff --git a/x86/cstart.S b/x86/cstart.S
index 7ab99cd20b7f..69b5c332cbcc 100644
--- a/x86/cstart.S
+++ b/x86/cstart.S
@@ -96,6 +96,7 @@ MSR_GS_BASE = 0xc0000101
 start:
         push %ebx
         call setup_get_initrd
+        call setup_environ
         mov mb_cmdline(%ebx), %eax
         mov %eax, __args
         call __setup_args
@@ -149,6 +150,7 @@ start32:
 	call enable_apic
 	call smp_init
 	call enable_x2apic
+        push $__environ
         push $__argv
         push __argc
         call main
diff --git a/x86/cstart64.S b/x86/cstart64.S
index 1c5182043703..004c014b5ba2 100644
--- a/x86/cstart64.S
+++ b/x86/cstart64.S
@@ -200,11 +200,13 @@ start64:
 	mov mb_boot_info(%rip), %rbx
 	mov %rbx, %rdi
 	call setup_get_initrd
+	call setup_environ
 	mov mb_cmdline(%rbx), %eax
 	mov %rax, __args(%rip)
 	call __setup_args
 	mov __argc(%rip), %edi
 	lea __argv(%rip), %rsi
+	lea __environ(%rip), %rdx
 	call main
 	mov %eax, %edi
 	call exit
-- 
2.9.3


  parent reply	other threads:[~2017-01-13 18:15 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-13 18:15 [PATCH kvm-unit-tests 00/15] Introduce an errata framework Andrew Jones
2017-01-13 18:15 ` [PATCH kvm-unit-tests 01/15] devicetree: improve dt_get_bootargs interface Andrew Jones
2017-01-13 18:15 ` [PATCH kvm-unit-tests 02/15] devicetree: introduce dt_get_initrd Andrew Jones
2017-01-13 18:15 ` [PATCH kvm-unit-tests 03/15] arm/arm64: better document setup Andrew Jones
2017-01-13 18:15 ` [PATCH kvm-unit-tests 04/15] powerpc: " Andrew Jones
2017-01-13 18:15 ` [PATCH kvm-unit-tests 05/15] arm/arm64: import initrd Andrew Jones
2017-01-13 18:15 ` [PATCH kvm-unit-tests 06/15] powerpc: " Andrew Jones
2017-01-13 18:15 ` [PATCH kvm-unit-tests 07/15] x86_64: mbi-cmdline is a 4 byte addr Andrew Jones
2017-01-13 18:15 ` [PATCH kvm-unit-tests 08/15] x86: import initrd Andrew Jones
2017-01-13 18:15 ` [PATCH kvm-unit-tests 09/15] lib/argv: fix coding style Andrew Jones
2017-01-13 18:15 ` [PATCH kvm-unit-tests 10/15] lib/argv: introduce setup_env and getenv Andrew Jones
2017-01-13 18:15 ` [PATCH kvm-unit-tests 11/15] arm/arm64: enable environ Andrew Jones
2017-01-13 18:15 ` [PATCH kvm-unit-tests 12/15] powerpc: " Andrew Jones
2017-01-13 18:15 ` Andrew Jones [this message]
2017-01-13 18:15 ` [PATCH kvm-unit-tests 14/15] README: reserve some environment variables Andrew Jones
2017-01-13 18:15 ` [PATCH kvm-unit-tests 15/15] Introduce lib/errata.h Andrew Jones
2017-03-03 14:40   ` Radim Krčmář

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170113181533.15145-14-drjones@redhat.com \
    --to=drjones@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=lvivier@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=rkrcmar@redhat.com \
    --cc=thuth@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.