Received: by 10.213.65.68 with SMTP id h4csp1152024imn; Wed, 4 Apr 2018 13:34:51 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+F+fe6Jj29sTprSt3xYe4xiiTHBp4TYXCX7bg8JhD8GoVGbxAChKhX1Jt/vNwPBCiEL2cE X-Received: by 2002:a17:902:8f84:: with SMTP id z4-v6mr20040786plo.210.1522874091354; Wed, 04 Apr 2018 13:34:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522874091; cv=none; d=google.com; s=arc-20160816; b=YtEp66GMXa/4na1bGbQA1FW6rxFtI4hdlEH8a29dzvzFuRakRGmuM2QkHpM/vwTNji aZJMqNkr+YpALhOvP5dIaZgjp+Jj0ZPlTQVHPiNAJvPhT7MZdSACdmRnJnRwWx+DCCPW bP+TFse8AuHDgJFwClUoD+CQNA9OMgCHazssJbFGEDGgjIxs35vkGdzjlRJdjC/uAJJn 118NjkXIXho5GOEMeLtGwevDXilrcZ4bBU6Jm+Zvix2ZpPIwvFmTyIZppanBUVzzG8fQ QvkYz2lTBAXx0q6PM51eB0w06xFq3o0d/4dZrvTApU4x/P9c9LroGZ7FtNOS3hwThg+T Lhmg== 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=T79MSrHBPqLX5v0lO+3fP/ZMhCpgjj2nykPszsjQGnU=; b=X1kU6s0gL4+rsfG+xF4DtP/P/VSCk0qtNLmWomuTgCTXs5/+1tQ+ckI2TyYKsCRNwz nvpOwYSP0SbhJGmIFT+ZqyfiCBG6SZkB5DuTrVt+oGtCEguP0pkgTrANXrOJDc1YLXuF YdvNCp0iu4XdTrMW7xuT9zMTXmSOqKKx3e6j9qLNISIiRDkhtnOV3tBr0KS9vwFvcDlq YvR79yFkqiQqXsb0+uCj/cwbG2QZTo02CmnnEsOTAhwKDqckXXyLUxy3UCZ8NgNOc3iA GMbnYlW80VcEefyNIxRKBciKRGmNQEAkxsRJ5eMTEvENlL9y6kH5IPFv9F0wVrR4sXAd ostQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2017-10-26 header.b=ocLecwpk; 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 x12-v6si3981220plw.169.2018.04.04.13.34.37; Wed, 04 Apr 2018 13:34:51 -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=ocLecwpk; 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 S1752463AbeDDUdI (ORCPT + 99 others); Wed, 4 Apr 2018 16:33:08 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:38550 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752336AbeDDUdG (ORCPT ); Wed, 4 Apr 2018 16:33:06 -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 w34KW5vj096344; Wed, 4 Apr 2018 20:32: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=T79MSrHBPqLX5v0lO+3fP/ZMhCpgjj2nykPszsjQGnU=; b=ocLecwpku+dS3Pr/LBbZS23F3ayqCW2jzBaCXHza7FKUvLiun1tQXcpFKs7sWr3PMaUI kDWW2kRJaG2qI5exIWh2nQ1aY9aj4LFezfjAd2cIL1wmEvwuaY4kMvJAfWMllChkqohb 7hiweVsewKVyTXHTozU3QxcrQBTEGZLklOY2Ea6vySipeDjOBh1GYBScMIx5c51K6h6U 8C29GQ0liD8ywAbpATVJv31QoUUYgtiutb+ncAot9AMPerpxxlkL5Osolq38ljgNTiEQ nHLsHg0qcgxRxfypyRzSSS4J4oCd5ShBZUuB8zl189Mi9eX2Enk8fJHE0vcDNZ3JqQAR AA== Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by userp2120.oracle.com with ESMTP id 2h55tt0048-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 04 Apr 2018 20:32:49 +0000 Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w34KWmCj017160 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 4 Apr 2018 20:32:48 GMT Received: from abhmp0004.oracle.com (abhmp0004.oracle.com [141.146.116.10]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w34KWlEu022822; Wed, 4 Apr 2018 20:32:47 GMT Received: from marawils-linux.us.oracle.com (/10.141.197.9) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 04 Apr 2018 13:32:47 -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 v6 5/7] xen/pvh: Move Xen code for getting mem map via hcall out of common file Date: Wed, 4 Apr 2018 13:32:42 -0700 Message-Id: <1522873962-18156-3-git-send-email-maran.wilson@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1522873659-17572-1-git-send-email-maran.wilson@oracle.com> References: <1522873659-17572-1-git-send-email-maran.wilson@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8853 signatures=668697 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-1804040198 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 edcff7de0529..efbceba8db4f 100644 --- a/arch/x86/platform/pvh/enlighten.c +++ b/arch/x86/platform/pvh/enlighten.c @@ -8,9 +8,6 @@ #include #include -#include -#include - #include #include @@ -30,21 +27,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 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