aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRalf Ramsauer2019-05-07 07:52:29 -0500
committerJan Kiszka2019-05-12 02:10:51 -0500
commit740b64fedf47a7a45d0850ea6e3b016e7a9d2cff (patch)
tree5723ed7d7d55c09a05d6ba547bca4b9147c3e6c0
parentfe7ec7cf9340cdc616bba017676f7a8092528a54 (diff)
downloadti-jailhouse-740b64fedf47a7a45d0850ea6e3b016e7a9d2cff.tar.gz
ti-jailhouse-740b64fedf47a7a45d0850ea6e3b016e7a9d2cff.tar.xz
ti-jailhouse-740b64fedf47a7a45d0850ea6e3b016e7a9d2cff.zip
inmates: x86: AMD: use the correct vmmcall instruction
I silently broke AMD inmates a while ago. In 4d6eb915ca78, I removed the call of hypercall_init() without reintroducing it at the right location again. No one noticed so far, as the bug (crash of the cell due to a wrong instruction) only happens on AMD machines only if they use the virtual debugging console. Instead of calling hypercall_init() somewhere inside printk, let's move it to setup.c, as we now have a arch_init_early() routine, which is the right place for these kind of initialisations. Also remove X86_FEATURE_VMX, it was never used. Fixes: 4d6eb915ca78e ("inmates: x86: Use virtual console as additional console") Signed-off-by: Ralf Ramsauer <ralf.ramsauer@oth-regensburg.de> [Jan: also remove hypercall_init from inmate.h] Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
-rw-r--r--inmates/lib/x86/Makefile2
-rw-r--r--inmates/lib/x86/hypercall.c61
-rw-r--r--inmates/lib/x86/include/inmate.h2
-rw-r--r--inmates/lib/x86/setup.c20
4 files changed, 20 insertions, 65 deletions
diff --git a/inmates/lib/x86/Makefile b/inmates/lib/x86/Makefile
index 15db65f8..97a37341 100644
--- a/inmates/lib/x86/Makefile
+++ b/inmates/lib/x86/Makefile
@@ -40,7 +40,7 @@ include $(INMATES_LIB)/Makefile.lib
40 40
41always := lib.a lib32.a 41always := lib.a lib32.a
42 42
43TARGETS := header.o hypercall.o ioapic.o printk.o setup.o smp.o uart.o 43TARGETS := header.o ioapic.o printk.o setup.o smp.o uart.o
44TARGETS += ../alloc.o ../pci.o ../string.o ../cmdline.o ../setup.o 44TARGETS += ../alloc.o ../pci.o ../string.o ../cmdline.o ../setup.o
45TARGETS += ../uart-8250.o ../printk.o 45TARGETS += ../uart-8250.o ../printk.o
46TARGETS_64_ONLY := int.o mem.o pci.o timing.o 46TARGETS_64_ONLY := int.o mem.o pci.o timing.o
diff --git a/inmates/lib/x86/hypercall.c b/inmates/lib/x86/hypercall.c
deleted file mode 100644
index fc5cd5ac..00000000
--- a/inmates/lib/x86/hypercall.c
+++ /dev/null
@@ -1,61 +0,0 @@
1/*
2 * Jailhouse, a Linux-based partitioning hypervisor
3 *
4 * Copyright (c) Valentine Sinitsyn, 2014
5 *
6 * Authors:
7 * Valentine Sinitsyn <valentine.sinitsyn@gmail.com>
8 *
9 * This work is licensed under the terms of the GNU GPL, version 2. See
10 * the COPYING file in the top-level directory.
11 *
12 * Alternatively, you can use or redistribute this file under the following
13 * BSD license:
14 *
15 * Redistribution and use in source and binary forms, with or without
16 * modification, are permitted provided that the following conditions
17 * are met:
18 *
19 * 1. Redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer.
21 *
22 * 2. Redistributions in binary form must reproduce the above copyright
23 * notice, this list of conditions and the following disclaimer in the
24 * documentation and/or other materials provided with the distribution.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
27 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
30 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
36 * THE POSSIBILITY OF SUCH DAMAGE.
37 */
38
39#include <inmate.h>
40
41#define X86_FEATURE_VMX (1 << 5)
42
43bool jailhouse_use_vmcall = true;
44
45#define AUTHENTIC_AMD(n) (((const u32 *)"AuthenticAMD")[n])
46
47void hypercall_init(void)
48{
49 u32 eax, ebx, ecx, edx;
50
51 asm volatile("cpuid"
52 : "=a" (eax), "=b" (ebx), "=c" (ecx), "=d" (edx)
53 : "a" (0)
54 : "memory"
55 );
56
57 if (ebx == AUTHENTIC_AMD(0) &&
58 edx == AUTHENTIC_AMD(1) &&
59 ecx == AUTHENTIC_AMD(2))
60 jailhouse_use_vmcall = false;
61}
diff --git a/inmates/lib/x86/include/inmate.h b/inmates/lib/x86/include/inmate.h
index 5fe4e102..b6bc6145 100644
--- a/inmates/lib/x86/include/inmate.h
+++ b/inmates/lib/x86/include/inmate.h
@@ -235,8 +235,6 @@ void ioapic_pin_set_vector(unsigned int pin,
235 enum ioapic_trigger_mode trigger_mode, 235 enum ioapic_trigger_mode trigger_mode,
236 unsigned int vector); 236 unsigned int vector);
237 237
238void hypercall_init(void);
239
240unsigned long pm_timer_read(void); 238unsigned long pm_timer_read(void);
241 239
242unsigned long tsc_read_ns(void); 240unsigned long tsc_read_ns(void);
diff --git a/inmates/lib/x86/setup.c b/inmates/lib/x86/setup.c
index f79fd736..869e0962 100644
--- a/inmates/lib/x86/setup.c
+++ b/inmates/lib/x86/setup.c
@@ -1,10 +1,12 @@
1/* 1/*
2 * Jailhouse, a Linux-based partitioning hypervisor 2 * Jailhouse, a Linux-based partitioning hypervisor
3 * 3 *
4 * Copyright (c) OTH Regensburg, 2018 4 * Copyright (c) OTH Regensburg, 2018-2019
5 * Copyright (c) Valentine Sinitsyn, 2014
5 * 6 *
6 * Authors: 7 * Authors:
7 * Ralf Ramsauer <ralf.ramsauer@oth-regensburg.de> 8 * Ralf Ramsauer <ralf.ramsauer@oth-regensburg.de>
9 * Valentine Sinitsyn <valentine.sinitsyn@gmail.com>
8 * 10 *
9 * This work is licensed under the terms of the GNU GPL, version 2. See 11 * This work is licensed under the terms of the GNU GPL, version 2. See
10 * the COPYING file in the top-level directory. 12 * the COPYING file in the top-level directory.
@@ -38,6 +40,22 @@
38 40
39#include <inmate.h> 41#include <inmate.h>
40 42
43#define AUTHENTIC_AMD(n) (((const u32 *)"AuthenticAMD")[n])
44
45bool jailhouse_use_vmcall = true;
46
41void arch_init_early(void) 47void arch_init_early(void)
42{ 48{
49 u32 eax, ebx, ecx, edx;
50
51 asm volatile("cpuid"
52 : "=a" (eax), "=b" (ebx), "=c" (ecx), "=d" (edx)
53 : "a" (0)
54 : "memory"
55 );
56
57 if (ebx == AUTHENTIC_AMD(0) &&
58 edx == AUTHENTIC_AMD(1) &&
59 ecx == AUTHENTIC_AMD(2))
60 jailhouse_use_vmcall = false;
43} 61}