Received: by 10.223.164.202 with SMTP id h10csp1606562wrb; Thu, 16 Nov 2017 00:52:24 -0800 (PST) X-Google-Smtp-Source: AGs4zMZVdBrm5dNunUDuw1bnkEtgGIRsaJvYTaV3uNP5X3u6VTCtYKZCQQkyurf4EIouuSDeaibS X-Received: by 10.99.103.70 with SMTP id b67mr970912pgc.211.1510822344595; Thu, 16 Nov 2017 00:52:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510822344; cv=none; d=google.com; s=arc-20160816; b=bB3R/9RfReMDnHuklgWYxvGxlTw/1QA5jKlTdaP6uL2df55oGUmr9rxJwAv4I7MYxe UsMsSQSaezt/C1stGU0goNE3zvcWUK7Fq33HJSEWAXCEBnQZdPdIwVKSkb/bf6Ob7Nkb i3EEEjJYqf/6750KrB75gjFFB41PeDIoXn2a99EP27nm4Ak4d7Uu/q5Mwk5YLyIeeyPz N7tc/hFqXej8bmAlBa/bclfuGU5AKx2Y8Ha85HXLw8L9w+bE8wCuTSOA1HIjBCpDhjMD CFed5cEDfBqPueB0L1sj8FfZASjE713pEuUaWc2U0/x46O+z2Z9Z+rV/KULGCk64040M OG0Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=eaBCttP2Kul1d5+HMlMTW1SIz/FUReyFjKQ8vFg2vtA=; b=jEOTh5pvJuDwXfCxHVfHQ8odBWJIgbpAF1vP/FFOlpEtBLd/RikUmYpkV0dGMa1abu zRnjfzNPB5e0TewcAGIg26xE972dh8jpZ4i6PGLfAyRGyi5MpPR93ybavuwTN6ICzwYE uTEWvMwcWHzjo8LP1X5ncGvv8I5LS/5516qWMn4bSjqk8Nz3HHv7sMl+cXzml+9syBtE Uipb8bZ2w9ZQYxoFaA+krBrTuxqdZZ+NkzF4fkk422gWxgv95gdF8HUinojdMcvLOd8Q YtJiECUU8HmLWy2kKs+udAQPLB5cYOMe/a2e/wr+pNgF0QKflujLfBLkU/BTvaJvUKpq PRkw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l91si520179plb.647.2017.11.16.00.52.12; Thu, 16 Nov 2017 00:52:24 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759186AbdKPHgY (ORCPT + 91 others); Thu, 16 Nov 2017 02:36:24 -0500 Received: from thoth.sbs.de ([192.35.17.2]:36706 "EHLO thoth.sbs.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1759109AbdKPHgM (ORCPT ); Thu, 16 Nov 2017 02:36:12 -0500 Received: from mail1.siemens.de (mail1.siemens.de [139.23.33.14]) by thoth.sbs.de (8.15.2/8.15.2) with ESMTPS id vAG7QsJK000892 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 16 Nov 2017 08:26:54 +0100 Received: from md1f2u6c.ww002.siemens.net ([167.87.32.158]) by mail1.siemens.de (8.15.2/8.15.2) with ESMTP id vAG7QrlR029336; Thu, 16 Nov 2017 08:26:54 +0100 From: Jan Kiszka To: Thomas Gleixner , Ingo Molnar , "H . Peter Anvin" Cc: x86@kernel.org, Linux Kernel Mailing List , jailhouse-dev@googlegroups.com Subject: [PATCH 02/10] x86: jailhouse: Add infrastructure for running in non-root cell Date: Thu, 16 Nov 2017 08:26:44 +0100 Message-Id: <160b45b696173511465a471a08143bcd9f09dd6e.1510817211.git.jan.kiszka@siemens.com> X-Mailer: git-send-email 2.12.3 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jan Kiszka The Jailhouse hypervisor is able to statically partition a multicore system into multiple so-called cells. Linux is used as boot loader and continues to run in the root cell after Jailhouse is enabled. Linux can also run in non-root cells. Jailhouse does not emulate usual x86 devices. It also provides no complex ACPI but basic platform information that the boot loader forwards via setup data. This adds the infrastructure to detect when running in a non-root cell so that the platform can be configured as required in succeeding steps. Support is limited to x86-64 so far, primarily because no boot loader stub exists for i386 and, thus, we wouldn't be able to test the 32-bit path. Signed-off-by: Jan Kiszka --- arch/x86/Kconfig | 12 ++++++ arch/x86/include/asm/hypervisor.h | 1 + arch/x86/include/asm/jailhouse_para.h | 27 +++++++++++++ arch/x86/kernel/Makefile | 2 + arch/x86/kernel/cpu/hypervisor.c | 4 ++ arch/x86/kernel/jailhouse.c | 76 +++++++++++++++++++++++++++++++++++ 6 files changed, 122 insertions(+) create mode 100644 arch/x86/include/asm/jailhouse_para.h create mode 100644 arch/x86/kernel/jailhouse.c diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index df3276d6bfe3..c5f4f4683b51 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -782,6 +782,18 @@ config KVM_DEBUG_FS Statistics are displayed in debugfs filesystem. Enabling this option may incur significant overhead. +config JAILHOUSE_GUEST + bool "Jailhouse non-root cell support" + depends on PARAVIRT && X86_64 + ---help--- + This option allows to run Linux as guest in a Jailhouse non-root + cell. You can leave this option disabled if you only want to start + Jailhouse and run Linux afterwards in the root cell. + + You likely also want to disable CONFIG_SUSPEND and CONFIG_SERIO to + avoid access to I/O resources that are usually not assigned to the + non-root cell. + config PARAVIRT_TIME_ACCOUNTING bool "Paravirtual steal time accounting" depends on PARAVIRT diff --git a/arch/x86/include/asm/hypervisor.h b/arch/x86/include/asm/hypervisor.h index 1b0a5abcd8ae..376085cb6244 100644 --- a/arch/x86/include/asm/hypervisor.h +++ b/arch/x86/include/asm/hypervisor.h @@ -37,6 +37,7 @@ enum x86_hypervisor_type { X86_HYPER_XEN_PV, X86_HYPER_XEN_HVM, X86_HYPER_KVM, + X86_HYPER_JAILHOUSE, }; struct hypervisor_x86 { diff --git a/arch/x86/include/asm/jailhouse_para.h b/arch/x86/include/asm/jailhouse_para.h new file mode 100644 index 000000000000..06a5f41d5451 --- /dev/null +++ b/arch/x86/include/asm/jailhouse_para.h @@ -0,0 +1,27 @@ +/* + * Jailhouse paravirt_ops implementation + * + * Copyright (c) Siemens AG, 2015-2017 + * + * Authors: + * Jan Kiszka + * + * This work is licensed under the terms of the GNU GPL, version 2. See + * the COPYING file in the top-level directory. + */ + +#ifndef _ASM_X86_JAILHOUSE_PARA_H +#define _ASM_X86_JAILHOUSE_PARA_H + +#include + +#ifdef CONFIG_JAILHOUSE_GUEST +bool jailhouse_paravirt(void); +#else +static inline bool jailhouse_paravirt(void) +{ + return false; +} +#endif + +#endif /* _ASM_X86_JAILHOUSE_PARA_H */ diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile index 81bb565f4497..aed9296dccd3 100644 --- a/arch/x86/kernel/Makefile +++ b/arch/x86/kernel/Makefile @@ -112,6 +112,8 @@ obj-$(CONFIG_PARAVIRT_SPINLOCKS)+= paravirt-spinlocks.o obj-$(CONFIG_PARAVIRT_CLOCK) += pvclock.o obj-$(CONFIG_X86_PMEM_LEGACY_DEVICE) += pmem.o +obj-$(CONFIG_JAILHOUSE_GUEST) += jailhouse.o + obj-$(CONFIG_EISA) += eisa.o obj-$(CONFIG_PCSPKR_PLATFORM) += pcspeaker.o diff --git a/arch/x86/kernel/cpu/hypervisor.c b/arch/x86/kernel/cpu/hypervisor.c index bea8d3e24f50..479ca4728de0 100644 --- a/arch/x86/kernel/cpu/hypervisor.c +++ b/arch/x86/kernel/cpu/hypervisor.c @@ -31,6 +31,7 @@ extern const struct hypervisor_x86 x86_hyper_ms_hyperv; extern const struct hypervisor_x86 x86_hyper_xen_pv; extern const struct hypervisor_x86 x86_hyper_xen_hvm; extern const struct hypervisor_x86 x86_hyper_kvm; +extern const struct hypervisor_x86 x86_hyper_jailhouse; static const __initconst struct hypervisor_x86 * const hypervisors[] = { @@ -45,6 +46,9 @@ static const __initconst struct hypervisor_x86 * const hypervisors[] = #ifdef CONFIG_KVM_GUEST &x86_hyper_kvm, #endif +#ifdef CONFIG_JAILHOUSE_GUEST + &x86_hyper_jailhouse, +#endif }; enum x86_hypervisor_type x86_hyper_type; diff --git a/arch/x86/kernel/jailhouse.c b/arch/x86/kernel/jailhouse.c new file mode 100644 index 000000000000..bc0f49a6172d --- /dev/null +++ b/arch/x86/kernel/jailhouse.c @@ -0,0 +1,76 @@ +/* + * Jailhouse paravirt_ops implementation + * + * Copyright (c) Siemens AG, 2015-2017 + * + * Authors: + * Jan Kiszka + * + * This work is licensed under the terms of the GNU GPL, version 2. See + * the COPYING file in the top-level directory. + */ + +#include +#include +#include +#include + +#define SETUP_JAILHOUSE 0x53484c4a /* "JLHS" */ + +#define SETUP_REQUIRED_VERSION 1 + +/* + * The boot loader is passing platform information via this Jailhouse-specific + * setup data structure. + */ +struct jailhouse_setup_data { + struct setup_data header; + u16 version; + u16 compatible_version; + u16 pm_timer_address; + u16 num_cpus; + u64 pci_mmconfig_base; + u8 standard_ioapic; + u8 cpu_ids[255]; +}; + +static uint32_t jailhouse_cpuid_base(void) +{ + if (boot_cpu_data.cpuid_level < 0 || + !boot_cpu_has(X86_FEATURE_HYPERVISOR)) + return 0; + + return hypervisor_cpuid_base("Jailhouse\0\0\0", 0); +} + +static uint32_t __init jailhouse_detect(void) +{ + return jailhouse_cpuid_base(); +} + +static void __init jailhouse_init_platform(void) +{ + u64 pa_data = boot_params.hdr.setup_data; + struct jailhouse_setup_data *data; + + data = early_memremap(pa_data, sizeof(*data)); + + if (data->header.type != SETUP_JAILHOUSE || + data->compatible_version > SETUP_REQUIRED_VERSION) + panic("Jailhouse: Unsupported setup data structure"); + + early_memunmap(data, sizeof(*data)); +} + +bool jailhouse_paravirt(void) +{ + return jailhouse_cpuid_base() != 0; +} + +const struct hypervisor_x86 x86_hyper_jailhouse __refconst = { + .name = "Jailhouse", + .detect = jailhouse_detect, + .init = { + .init_platform = jailhouse_init_platform, + }, +}; -- 2.12.3 From 1584578518544224013@xxx Mon Nov 20 09:57:15 +0000 2017 X-GM-THRID: 1584578518544224013 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread