Received: by 10.192.165.156 with SMTP id m28csp1204264imm; Mon, 16 Apr 2018 16:16:16 -0700 (PDT) X-Google-Smtp-Source: AIpwx48uNuXyLpOBGVfSUQkykmojb0Kb9arqbDhVrD0PctQPtkE7CYVW+xZln5BZdF4TGPBRm6+2 X-Received: by 10.101.83.65 with SMTP id w1mr14541494pgr.111.1523920576005; Mon, 16 Apr 2018 16:16:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523920575; cv=none; d=google.com; s=arc-20160816; b=UKRrkx3n0Fby0yC/kdoovDZk+q6tyEvMxbbP96kvG5ZD98gRYNvqmf/CHUiiHEUDzQ 6J3HrMRGAxlcC9tiXOAwHaYj3mEEmYApmoKMoDQHW5zAaQGtwbadxoqCPdcbKZeuYkpm cHyZwI1EVoEPhNNB+pqBBQcfEhnyeARpS9vllfNg2DZIXzY9eVd/gLCr3x/Yq6tHE9gw fEV/Qm9t0ewMhRZym8th+gmldmzrJZJ7GayPL2vpCaX5/Y8OKGU55hfC5+5uCC44AUcd 1nYFid9icYhbVOmqAsUdh/BPoVjFhCfLMUXsO6sTrxgvbkELsrWVPcd6WMocAqKVrPCx Jipw== 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=T0v25j75g+XYZ2ZhfFC3NKyxx8+KJfPrtuP0p3NTLB8=; b=EMuHOr6Bify2mRIX6tLvHeCA79TusOpWxX8gD4uYiFO9Xv8JTFc+YUIBVcLopNWGr4 4M966Z7VC1EoTZtwox15BxvPr3ajRyE3Abjcmx0C0NrDm8NDYP+2SvgOl1NhY7cFH4oe PgSSAiVD66hCg+INd8i6SEuXCfcEfP6CZ2hFHL51DMpwnEG7hY9etkM8McrysHAg4LWv HoC2OEyRJBFYMIQF6mX20A5ByNgQiJBvSHSDUknpewJSXp5R/6YWpIJ91Vzi5d/Q/0lt 536XwleE537xYpWgqSvepTTN4XlcJXybh2CrFy4pWZA8tiJou4TO2rFgz6Qz7XSpdXyy gT6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2017-10-26 header.b=b5XtpGMN; 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 m39-v6si12945941plg.570.2018.04.16.16.16.01; Mon, 16 Apr 2018 16:16:15 -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=b5XtpGMN; 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 S1752648AbeDPXOV (ORCPT + 99 others); Mon, 16 Apr 2018 19:14:21 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:35270 "EHLO userp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751182AbeDPXN3 (ORCPT ); Mon, 16 Apr 2018 19:13:29 -0400 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w3GNAsrd042486; Mon, 16 Apr 2018 23:12:49 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=T0v25j75g+XYZ2ZhfFC3NKyxx8+KJfPrtuP0p3NTLB8=; b=b5XtpGMNLsogBVgUOTsisRblyJhgIs0Gxc9rQdQyxvX0/EkRz3iLMhvfVJE+/7rXq2rt FcApplAp2ix0sacTr4O/xRisGnGUvrin/wKpxfyhEAdViP9PmWgVidHIQuwiRSs1vqdB nh6NE/Galxn7WVgUBPC17ITsWasNNFJTsDPMHuoTf1jckpbzyOEEoDKx5qnaeRPKWhs2 StuZWA3/bUAIifj/2esq+Dwyxy2wZhvvo+Oso9Fne/o3KDwI/rwdb5LqVzSdtTxgMKXn ZuVhKHRt3TZ+jgUXpsAhrn4HzXxwJREQD8PzhEsWOd6FG1wexPI1YN8ZBuD6nwV5OzDC gA== Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by userp2130.oracle.com with ESMTP id 2hbam5ybc7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 16 Apr 2018 23:12:48 +0000 Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserv0022.oracle.com (8.14.4/8.14.4) with ESMTP id w3GNCltu001707 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 16 Apr 2018 23:12:47 GMT Received: from abhmp0007.oracle.com (abhmp0007.oracle.com [141.146.116.13]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w3GNCk2W010315; Mon, 16 Apr 2018 23:12:47 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:12:46 -0700 From: Maran Wilson To: x86@kernel.org, xen-devel@lists.xenproject.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, pbonzini@redhat.com, jgross@suse.com Cc: boris.ostrovsky@oracle.com, tglx@linutronix.de, mingo@redhat.com, hpa@zytor.com, roger.pau@citrix.com, rkrcmar@redhat.com, maran.wilson@oracle.com Subject: [PATCH v7 5/7] xen/pvh: Move Xen code for getting mem map via hcall out of common file Date: Mon, 16 Apr 2018 16:12:40 -0700 Message-Id: <1523920360-27743-3-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=0 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 We need to refactor PVH entry code so that support for other hypervisors like Qemu/KVM can be added more easily. The original design for PVH entry in Xen guests relies on being able to obtain the memory map from the hypervisor using a hypercall. When we extend the PVH entry ABI to support other hypervisors like Qemu/KVM, a new mechanism will be added that allows the guest to get the memory map without needing to use hypercalls. For Xen guests, the hypercall approach will still be supported. In preparation for adding support for other hypervisors, we can move the code that uses hypercalls into the Xen specific file. This will allow us to compile kernels in the future without CONFIG_XEN that are still capable of being booted as a Qemu/KVM guest via the PVH entry point. Signed-off-by: Maran Wilson Reviewed-by: Juergen Gross --- arch/x86/platform/pvh/enlighten.c | 29 ++++++++++++++--------------- arch/x86/xen/enlighten_pvh.c | 20 ++++++++++++++++++++ 2 files changed, 34 insertions(+), 15 deletions(-) diff --git a/arch/x86/platform/pvh/enlighten.c b/arch/x86/platform/pvh/enlighten.c index edcff7de0529..c42a9f36ee9c 100644 --- a/arch/x86/platform/pvh/enlighten.c +++ b/arch/x86/platform/pvh/enlighten.c @@ -8,10 +8,6 @@ #include #include -#include -#include - -#include #include /* @@ -30,21 +26,24 @@ static u64 pvh_get_root_pointer(void) return pvh_start_info.rsdp_paddr; } +/* + * Xen guests are able to obtain the memory map from the hypervisor via the + * HYPERVISOR_memory_op hypercall. + * If we are trying to boot a Xen PVH guest, it is expected that the kernel + * will have been configured to provide an override for this routine to do + * just that. + */ +void __init __weak mem_map_via_hcall(struct boot_params *ptr __maybe_unused) +{ + xen_raw_printk("Error: Could not find memory map\n"); + BUG(); +} + static void __init init_pvh_bootparams(void) { - struct xen_memory_map memmap; - int rc; - memset(&pvh_bootparams, 0, sizeof(pvh_bootparams)); - memmap.nr_entries = ARRAY_SIZE(pvh_bootparams.e820_table); - set_xen_guest_handle(memmap.buffer, pvh_bootparams.e820_table); - rc = HYPERVISOR_memory_op(XENMEM_memory_map, &memmap); - if (rc) { - xen_raw_printk("XENMEM_memory_map failed (%d)\n", rc); - BUG(); - } - pvh_bootparams.e820_entries = memmap.nr_entries; + mem_map_via_hcall(&pvh_bootparams); if (pvh_bootparams.e820_entries < E820_MAX_ENTRIES_ZEROPAGE - 1) { pvh_bootparams.e820_table[pvh_bootparams.e820_entries].addr = diff --git a/arch/x86/xen/enlighten_pvh.c b/arch/x86/xen/enlighten_pvh.c index bb5784f354b8..0141dd1d21e2 100644 --- a/arch/x86/xen/enlighten_pvh.c +++ b/arch/x86/xen/enlighten_pvh.c @@ -1,11 +1,16 @@ #include +#include + #include #include +#include #include #include +#include + /* * PVH variables. * @@ -25,3 +30,18 @@ void __init xen_pvh_init(void) pfn = __pa(hypercall_page); wrmsr_safe(msr, (u32)pfn, (u32)(pfn >> 32)); } + +void __init mem_map_via_hcall(struct boot_params *boot_params_p) +{ + struct xen_memory_map memmap; + int rc; + + memmap.nr_entries = ARRAY_SIZE(boot_params_p->e820_table); + set_xen_guest_handle(memmap.buffer, boot_params_p->e820_table); + rc = HYPERVISOR_memory_op(XENMEM_memory_map, &memmap); + if (rc) { + xen_raw_printk("XENMEM_memory_map failed (%d)\n", rc); + BUG(); + } + boot_params_p->e820_entries = memmap.nr_entries; +} -- 2.16.1