Received: by 10.213.65.68 with SMTP id h4csp673496imn; Tue, 20 Mar 2018 12:22:33 -0700 (PDT) X-Google-Smtp-Source: AG47ELt4HBLJ3VwHtWtviA36Iud/EHKJ4c/zl9m7SFYLPFhn55EM8ZXAmiDcy1Vuokd4SDOkTHZP X-Received: by 2002:a17:902:820a:: with SMTP id x10-v6mr7220159pln.105.1521573753715; Tue, 20 Mar 2018 12:22:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521573753; cv=none; d=google.com; s=arc-20160816; b=EbJL0ZdyNlm/QKlBZAaJTcSD8lDxU2PKRRr71E+Uz96EOwMBAyLah3MvGs4r/0X7Fx 3s/a2yWdfrhYl7E+mUCT+Yqpc2EuXTQQLLFp+HTIKkLI6rzks3vzh6Zkp7jekpxT54CX aQXWZMa1DdMJsu40sCkKKq/+F5tTQR5NffRWGrkN0YOkpMSzOQZC1P2KoGhFRMql99+X 7He4+ofc5a8jgNKXvLzCsoKZ/BAvTEpCrUEjs5muVk6zQFcRi9wMYXpPVQTfBldqGYh5 HodjYoOTSHz7yir29z3KPhU0JgPxU7jyuGvNid4BUT055jwoVa8vMDfQKMB6XumfzLVn Mmng== 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=9ymhLiPqOmxxjpRDd8iNDU+qt1HtNmiuquhbhBM8iK4=; b=OO+u2dJz+SZgDtaOaVJJR0WAjBiVnBVN11XzrUkyOAapptkO4WXzgg73v/j6ZDwp4T W+PhQLP37luudhrS+MxGiXTh6ys9KnQU0L6p4Bx9gJ2S2MG/KS9PGZyjGBE24vbaOv9Y unEDbT8+xqtSUDOr4P+Ags9vzReAiVQK+Odhf0u6Ebflww35uEY0No6hxHsl88EvDBvg 4r19vGk2kwv0yUwbSsOvr0/C9sSXea4pbRzFSruZ7zIH0RRPq20N8le7I46PTmTBLr/U 1g3BJtdiJOZYRUcAgs58psIJg2DyUtnb8Ycj+HPn1i8Q8FQhywAtQXpjsXW5vypT+q2A uZGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2017-10-26 header.b=ulYybve8; 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 31-v6si2148337plg.227.2018.03.20.12.22.19; Tue, 20 Mar 2018 12:22:33 -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=ulYybve8; 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 S1751820AbeCTTUu (ORCPT + 99 others); Tue, 20 Mar 2018 15:20:50 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:59762 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751458AbeCTTUg (ORCPT ); Tue, 20 Mar 2018 15:20:36 -0400 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w2KJCIKa148109; Tue, 20 Mar 2018 19:20:10 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=9ymhLiPqOmxxjpRDd8iNDU+qt1HtNmiuquhbhBM8iK4=; b=ulYybve8UjTNHZ+0D7rDqbz9xWUJ0Ha9+khsOBfHjQZYbnmVj8skViaT8OsNuKiMfKcj Va1Cf53vvlq9qEQMyNYZ/DPQuRsPlDkiwD71Ickh6lOqrDcI4lmfG2PiuqKJhGiAlrxz 940s8uO/Xr/yRppImGQDxTtGGRlR+nf7dfbzIx57UC3tOzmjRPhJcuJd7g4KoYlDywrc 1QrSk2nU3as5epvslIugtoVjhzAOqv+3nUe+2LtRF2i/GbaC1G8Q5caHTHvlsbf/rXpf WNnzyr2fKJcFyNozHOQ2hb2DINYMfbP1Oapm9E+VGRnykdsNQt7z2adZHZIZ0DwuNMQX cA== Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by userp2120.oracle.com with ESMTP id 2gu88m0118-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 20 Mar 2018 19:20:10 +0000 Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id w2KJKAoh013505 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 20 Mar 2018 19:20:10 GMT Received: from abhmp0002.oracle.com (abhmp0002.oracle.com [141.146.116.8]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w2KJK9eU021536; Tue, 20 Mar 2018 19:20:09 GMT Received: from marawils-linux.us.oracle.com (/10.141.197.9) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 20 Mar 2018 12:20:09 -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 v5 5/7] xen/pvh: Move Xen code for getting mem map via hcall out of common file Date: Tue, 20 Mar 2018 12:19:46 -0700 Message-Id: <1521573586-17463-3-git-send-email-maran.wilson@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1521573369-17216-1-git-send-email-maran.wilson@oracle.com> References: <1521573369-17216-1-git-send-email-maran.wilson@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8838 signatures=668695 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-1803200127 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 | 28 ++++++++++++++-------------- arch/x86/xen/enlighten_pvh.c | 20 ++++++++++++++++++++ 2 files changed, 34 insertions(+), 14 deletions(-) diff --git a/arch/x86/platform/pvh/enlighten.c b/arch/x86/platform/pvh/enlighten.c index b463ee30517a..347ecb1860d5 100644 --- a/arch/x86/platform/pvh/enlighten.c +++ b/arch/x86/platform/pvh/enlighten.c @@ -7,9 +7,6 @@ #include #include -#include -#include - #include #include @@ -24,21 +21,24 @@ struct boot_params pvh_bootparams __attribute__((section(".data"))); struct hvm_start_info pvh_start_info; unsigned int pvh_start_info_sz = sizeof(pvh_start_info); +/* + * 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 08fc63d14ae5..00658d4bc4f4 100644 --- a/arch/x86/xen/enlighten_pvh.c +++ b/arch/x86/xen/enlighten_pvh.c @@ -1,10 +1,15 @@ #include +#include + #include +#include #include #include +#include + /* * PVH variables. * @@ -24,3 +29,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