Received: by 10.223.185.116 with SMTP id b49csp6505620wrg; Wed, 28 Feb 2018 10:31:00 -0800 (PST) X-Google-Smtp-Source: AH8x226UPP0O4eTcVI+pdVFsN0QSgLRgkV7I+O9Xomiq0cxt3Eh0/IzcpoRqHi9NcvnPwMWxriUK X-Received: by 2002:a17:902:6bc6:: with SMTP id m6-v6mr19315033plt.100.1519842660065; Wed, 28 Feb 2018 10:31:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519842660; cv=none; d=google.com; s=arc-20160816; b=YVNnbGSnRYhWF3eZWxBVFnyV6B2QBLT228pzmqHf7/4OZqikeo4f/9tbBCwaDOLowo rtiN4wptklimpv7UZorpBQyvhOuKVvO7K36pslP9hrQQeB7fogOwZLcPvdxQhJ+excr6 3GhJffjzj3D2GZq5QtOClo2LQDJq/wNNyC7VPoEk1eqRaXJO/waw/CMXez23vGf82MAJ JgmAYngcZ1R9bufc+8YDzPTF+1CKCQSjA/o+vEisck1xsB3YGxKR7r5aU8YRiF70HG5Y ZzWmsX0RIVoJ/Od7eVctlgXGF/L/FndrzfXr3lUWkrLmw6zTbpdbFEngYbRoWcUTNBZh PGSw== 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=WhVN4vJc/3o/DM9329n8zeF36pD+r4h+Z6q1+VtOocw=; b=JpQO4gYYBLzgOfO5sZXAiQQILlarM6VztVeP6tv2mITYZxrXEoVdqQg5iu9ktVfxzK fB3Sj1pyD2ocWShMwBnPOa8GpAuH/cmDgszHNwczRV0RSY0kjL1RZX5GTPZUZyrdZMLo hkPD40Ip3rKfdAPsqCsoJdYv8zGGbfenb2WJyXdLtEqEloIwGEE1UqoX8dxNVeg+4KNF hOKz9cpmHQQdkopThIha3CIfuUT+IfHzu7P1mtkk5OAYinOOt8QTMe3ksLdgo5eKg2mR V8C4JLwReyGEH+Us4//TJVadt1Z4xSnX/1JNKMWp6RFVZuQVgbEEHkkw5SE2Wm+u+eim Bb2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2017-10-26 header.b=s0iSGDeH; 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 a16si1326088pgw.58.2018.02.28.10.30.44; Wed, 28 Feb 2018 10:31:00 -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; dkim=pass header.i=@oracle.com header.s=corp-2017-10-26 header.b=s0iSGDeH; 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 S932891AbeB1S3f (ORCPT + 99 others); Wed, 28 Feb 2018 13:29:35 -0500 Received: from userp2130.oracle.com ([156.151.31.86]:56546 "EHLO userp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932494AbeB1S33 (ORCPT ); Wed, 28 Feb 2018 13:29:29 -0500 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 w1SIQYpM030736; Wed, 28 Feb 2018 18:28:47 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=WhVN4vJc/3o/DM9329n8zeF36pD+r4h+Z6q1+VtOocw=; b=s0iSGDeHC8eEewY8z1rTmzgcfYQp+GOu5ZLdlloG8tKTiJ4EYj8ir4xhkXP9QIa3c4OG OkCkMZgaLiaYlHcecuWXDTkCLYnzQpDdES7L+9VFw2BPAJG+bXN33BetGSiQjJAtZVe5 FfolPuCveDgZqOZYqArOxC9SuY6RA/XzKC+K37jPuOZC5g7EyeIJkMwAKrrPCIqeHijw KN/92ve2hWr5FRdYppUPEkMlTlw4MlFEcw1G7lGXa3LsiJteGpB15p5tN4iBNuI/Hhtj unlrUFJaywFqhzndHgRcwrJjY+UtV/7xqWTtRMaGuIzyKYVtsvWoYIJNoZGXdWezevw+ Tw== Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by userp2130.oracle.com with ESMTP id 2gdygbrvv7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 28 Feb 2018 18:28:47 +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 w1SISlGF004853 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 28 Feb 2018 18:28:47 GMT Received: from abhmp0007.oracle.com (abhmp0007.oracle.com [141.146.116.13]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w1SISkX3029753; Wed, 28 Feb 2018 18:28:46 GMT Received: from marawils-linux.us.oracle.com (/10.141.197.9) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 28 Feb 2018 10:28:45 -0800 From: Maran Wilson To: pbonzini@redhat.com, jgross@suse.com, boris.ostrovsky@oracle.com, roger.pau@citrix.com, andrew.cooper3@citrix.com, hch@infradead.org, JBeulich@suse.com, x86@kernel.org, xen-devel@lists.xenproject.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: tglx@linutronix.de, mingo@redhat.com, hpa@zytor.com, rkrcmar@redhat.com, jpoimboe@redhat.com, bp@suse.de, kirill.shutemov@linux.intel.com, thomas.lendacky@amd.com, luto@kernel.org, maran.wilson@oracle.com, dave.hansen@linux.intel.com, davem@davemloft.net, gregkh@linuxfoundation.org, mchehab@kernel.org, linus.walleij@linaro.org, rdunlap@infradead.org Subject: [RFC PATCH v4 5/7] xen/pvh: Move Xen code for getting mem map via hcall out of common file Date: Wed, 28 Feb 2018 10:28:01 -0800 Message-Id: <1519842483-8887-6-git-send-email-maran.wilson@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1519842483-8887-1-git-send-email-maran.wilson@oracle.com> References: <1519842483-8887-1-git-send-email-maran.wilson@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8818 signatures=668682 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-1802280224 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 --- arch/x86/pvh.c | 28 ++++++++++++++-------------- arch/x86/xen/enlighten_pvh.c | 20 ++++++++++++++++++++ 2 files changed, 34 insertions(+), 14 deletions(-) diff --git a/arch/x86/pvh.c b/arch/x86/pvh.c index 2d7a7f4958cb..6e9f6a6e97b3 100644 --- a/arch/x86/pvh.c +++ b/arch/x86/pvh.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 833c441a20df..3a830caef8ee 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. * @@ -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