Received: by 10.192.165.156 with SMTP id m28csp1204501imm; Mon, 16 Apr 2018 16:16:32 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/p3mDrYDcvztOuf8wxnOKvqy/rPHtaAkWhoH2ltavH87z9gHf43vCQv8L2e810sYZ7o8w6 X-Received: by 2002:a17:902:708a:: with SMTP id z10-v6mr17459432plk.315.1523920592295; Mon, 16 Apr 2018 16:16:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523920592; cv=none; d=google.com; s=arc-20160816; b=yZWAfiVKk49sVSRMPf/yoysHtRP9JE/KtynFJ2rxnVoiEF5PnQcNIh8EAzNjXmDJ2l dndithAWfIIej+Wrgch/n3cXwuglar31+5/O3wiy1upVIbVp8ngEHZSiG0dvwo2JX48o wdphIVQY8JpNsJaLGgiwaQqb+qsL11Dud646TmeTmvzriNuTXPe++D58z2VK+BWOIcKe HaTJPBXDoHkgnmv39KpP6We/y+md+11Lw/qTfIHPK4FUhcb0Ri6ZqOHaM1adLsM4+vXi kMGmmraN+QD37ufX7LvwpQ2v+yK9kcD+kl2TPaNEKSmAFDQgLmayML/K2FMgaudPpSce 4VEQ== 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:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=FLtMuJn01Jv19zZl2IBytkSG17nZpmsevfUnQZg7ypA=; b=r7IBpFMOzoVC7MJIddz3cI+jmaRELW0fZ3u7aIRnJVKsNoGptLAaI8ZyD9IU23J8+z Gmm1gEra6EW42uxD6uQa17TdVRKtX+Dsl0howfiGUrHuEv436FKkdM6cCV9nLEfe9BvP UM/7NUqJhUIe4iYg6fh+DbhEyBiOheyvE27lTr1V5NkjDfUOEDt6nUOg5L1NB6rJRhCO OSfrW659e+9BzdOcv0wFxwMPjEgJpiM+GdcJRVs2tTvjpSX4oM/nowfQaZyJZdya0erc mQSmWz+w6RpvH3eW2zxInWjr/0DZIkOiFrPU5i9/LfPrNqTNYM6+PmWWC3ZNkvIDDYV3 AjPg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2017-10-26 header.b=INEsP47G; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a13-v6si10278541plt.142.2018.04.16.16.16.16; Mon, 16 Apr 2018 16:16:32 -0700 (PDT) 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; dkim=pass header.i=@oracle.com header.s=corp-2017-10-26 header.b=INEsP47G; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752841AbeDPXOl (ORCPT + 99 others); Mon, 16 Apr 2018 19:14:41 -0400 Received: from aserp2120.oracle.com ([141.146.126.78]:41106 "EHLO aserp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750989AbeDPXOk (ORCPT ); Mon, 16 Apr 2018 19:14:40 -0400 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w3GNBr88134676; Mon, 16 Apr 2018 23:13:57 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2017-10-26; bh=FLtMuJn01Jv19zZl2IBytkSG17nZpmsevfUnQZg7ypA=; b=INEsP47GmZzGT4w7eIqgqGKWmLEZQod9jB3wlD1iy1YaAAOZabmOyPEGb1VC71G8Ug5l 7U8z4VkFzQ2AwAFqjFolu8wDF3ry71quCF6QuQwHN8rRcv8rTwoTrJjbC3bvy4NwrS2U Zi+XVtFSzNt1K2YvTnApdKl2zkJtn6MxIvUNMz3STuVMrmluaqn20rq+rB2ds6R+M7yv D9qZc7kmRF84gOvxvZU1BVeR9VBDBn6eR/e8/7gv7K9wyryPtAiBg5StJ9G4EXnBBj3Z SkVFDpBnf7mHLImE2IQvvkQeoe8lYNiVjx0C+rnY9PgqUu8Uct2eI/oA7Rk5BwRmWnca ZA== Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by aserp2120.oracle.com with ESMTP id 2hbamnqbe8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 16 Apr 2018 23:13:57 +0000 Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w3GNDurs026329 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 16 Apr 2018 23:13:56 GMT Received: from abhmp0011.oracle.com (abhmp0011.oracle.com [141.146.116.17]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w3GNDtM9010785; Mon, 16 Apr 2018 23:13:55 GMT Received: from marawils-linux.us.oracle.com (/10.141.196.252) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 16 Apr 2018 16:13:55 -0700 From: Maran Wilson To: x86@kernel.org, linux-kernel@vger.kernel.org, xen-devel@lists.xenproject.org, kvm@vger.kernel.org, pbonzini@redhat.com, jgross@suse.com Cc: tglx@linutronix.de, mingo@redhat.com, hpa@zytor.com, roger.pau@citrix.com, boris.ostrovsky@oracle.com, rkrcmar@redhat.com, maran.wilson@oracle.com Subject: [PATCH v7 7/7] KVM: x86: Allow Qemu/KVM to use PVH entry point Date: Mon, 16 Apr 2018 16:13:50 -0700 Message-Id: <1523920430-27952-1-git-send-email-maran.wilson@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1523920175-27287-1-git-send-email-maran.wilson@oracle.com> References: <1523920175-27287-1-git-send-email-maran.wilson@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8865 signatures=668698 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=7 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1711220000 definitions=main-1804160192 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org For certain applications it is desirable to rapidly boot a KVM virtual machine. In cases where legacy hardware and software support within the guest is not needed, Qemu should be able to boot directly into the uncompressed Linux kernel binary without the need to run firmware. There already exists an ABI to allow this for Xen PVH guests and the ABI is supported by Linux and FreeBSD: https://xenbits.xen.org/docs/unstable/misc/pvh.html This patch enables Qemu to use that same entry point for booting KVM guests. Signed-off-by: Maran Wilson Suggested-by: Konrad Rzeszutek Wilk Suggested-by: Boris Ostrovsky Tested-by: Boris Ostrovsky --- arch/x86/Kbuild | 2 +- arch/x86/Kconfig | 8 ++++++++ arch/x86/platform/pvh/Makefile | 4 ++-- arch/x86/platform/pvh/enlighten.c | 42 +++++++++++++++++++++++++++++---------- 4 files changed, 42 insertions(+), 14 deletions(-) diff --git a/arch/x86/Kbuild b/arch/x86/Kbuild index 2089e4414300..c625f57472f7 100644 --- a/arch/x86/Kbuild +++ b/arch/x86/Kbuild @@ -7,7 +7,7 @@ obj-$(CONFIG_KVM) += kvm/ # Xen paravirtualization support obj-$(CONFIG_XEN) += xen/ -obj-$(CONFIG_XEN_PVH) += platform/pvh/ +obj-$(CONFIG_PVH) += platform/pvh/ # Hyper-V paravirtualization support obj-$(subst m,y,$(CONFIG_HYPERV)) += hyperv/ diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index 8511d419e39f..26fef538d3ef 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -787,6 +787,14 @@ config PVH This option enables the PVH entry point for guest virtual machines as specified in the x86/HVM direct boot ABI. +config KVM_GUEST_PVH + bool "Support for running as a KVM PVH guest" + depends on KVM_GUEST + select PVH + ---help--- + This option enables starting KVM guests via the PVH entry point as + specified in the x86/HVM direct boot ABI. + config KVM_DEBUG_FS bool "Enable debug information for KVM Guests in debugfs" depends on KVM_GUEST && DEBUG_FS diff --git a/arch/x86/platform/pvh/Makefile b/arch/x86/platform/pvh/Makefile index 9fd25efcd2a3..5dec5067c9fb 100644 --- a/arch/x86/platform/pvh/Makefile +++ b/arch/x86/platform/pvh/Makefile @@ -1,5 +1,5 @@ # SPDX-License-Identifier: GPL-2.0 OBJECT_FILES_NON_STANDARD_head.o := y -obj-$(CONFIG_XEN_PVH) += enlighten.o -obj-$(CONFIG_XEN_PVH) += head.o +obj-$(CONFIG_PVH) += enlighten.o +obj-$(CONFIG_PVH) += head.o diff --git a/arch/x86/platform/pvh/enlighten.c b/arch/x86/platform/pvh/enlighten.c index c42a9f36ee9c..0c7f570d3c16 100644 --- a/arch/x86/platform/pvh/enlighten.c +++ b/arch/x86/platform/pvh/enlighten.c @@ -8,6 +8,8 @@ #include #include +#include + #include /* @@ -39,11 +41,28 @@ void __init __weak mem_map_via_hcall(struct boot_params *ptr __maybe_unused) BUG(); } -static void __init init_pvh_bootparams(void) +static void __init init_pvh_bootparams(bool xen_guest) { memset(&pvh_bootparams, 0, sizeof(pvh_bootparams)); - mem_map_via_hcall(&pvh_bootparams); + if ((pvh_start_info.version > 0) && (pvh_start_info.memmap_entries)) { + struct hvm_memmap_table_entry *ep; + int i; + + ep = __va(pvh_start_info.memmap_paddr); + pvh_bootparams.e820_entries = pvh_start_info.memmap_entries; + + for (i = 0; i < pvh_bootparams.e820_entries ; i++, ep++) { + pvh_bootparams.e820_table[i].addr = ep->addr; + pvh_bootparams.e820_table[i].size = ep->size; + pvh_bootparams.e820_table[i].type = ep->type; + } + } else if (xen_guest) { + mem_map_via_hcall(&pvh_bootparams); + } else { + /* Non-xen guests are not supported by version 0 */ + BUG(); + } if (pvh_bootparams.e820_entries < E820_MAX_ENTRIES_ZEROPAGE - 1) { pvh_bootparams.e820_table[pvh_bootparams.e820_entries].addr = @@ -74,7 +93,7 @@ static void __init init_pvh_bootparams(void) * environment (i.e. hardware_subarch 0). */ pvh_bootparams.hdr.version = 0x212; - pvh_bootparams.hdr.type_of_loader = (9 << 4) | 0; /* Xen loader */ + pvh_bootparams.hdr.type_of_loader = ((xen_guest ? 0x9 : 0xb) << 4) | 0; x86_init.acpi.get_root_pointer = pvh_get_root_pointer; } @@ -89,13 +108,10 @@ void __init __weak xen_pvh_init(void) BUG(); } -/* - * When we add support for other hypervisors like Qemu/KVM, this routine can - * selectively invoke the appropriate initialization based on guest type. - */ -static void hypervisor_specific_init(void) +static void hypervisor_specific_init(bool xen_guest) { - xen_pvh_init(); + if (xen_guest) + xen_pvh_init(); } /* @@ -104,13 +120,17 @@ static void hypervisor_specific_init(void) */ void __init xen_prepare_pvh(void) { + + u32 msr = xen_cpuid_base(); + bool xen_guest = !!msr; + if (pvh_start_info.magic != XEN_HVM_START_MAGIC_VALUE) { xen_raw_printk("Error: Unexpected magic value (0x%08x)\n", pvh_start_info.magic); BUG(); } - hypervisor_specific_init(); + hypervisor_specific_init(xen_guest); - init_pvh_bootparams(); + init_pvh_bootparams(xen_guest); } -- 2.16.1