From nobody Tue Oct 18 06:03:14 2022 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4Ms3FG57Mxz4g848; Tue, 18 Oct 2022 06:03:14 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Ms3FG4dZWz3c6F; Tue, 18 Oct 2022 06:03:14 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1666072994; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=8QMLyracHMrqhMkeK/j3SYbrMZjxtekl0bxwfPKh0X0=; b=cCaeTl9YTrkGM/sxp6XenFBnBZR6cLdB6T83nz8pWWFx34TzkEkPFGMkd2YpJgHQyuQ9Aj oh98hcI7nsJ7jZqXI8fQ7CMS1uRmeIBENTptkHV1+ZKSNC9/IqiBtfcG4xaVX0BDYIUlJI 96xOcLIqlzZCxKq+D9HirPYi5e5KgAxq+pvQOtlhGhR9OMi0bAZFP61e1eHhIBaV4s4UJR z3jtbg/wnndb6oqXU1kpB9u/jiuKKzQfYp/ICYPXiAwNxWdZ2bk4YU4D3ukX2neNZbKrGb 66p0zv4DeBU9u0vpIZlTN9Xm86RF8Uavv4tuhMUBBQcRLFMw+pp5sUZ1iao44w== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4Ms3FG3b3Nz157v; Tue, 18 Oct 2022 06:03:14 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 29I63EuN097489; Tue, 18 Oct 2022 06:03:14 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 29I63EL1097488; Tue, 18 Oct 2022 06:03:14 GMT (envelope-from git) Date: Tue, 18 Oct 2022 06:03:14 GMT Message-Id: <202210180603.29I63EL1097488@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Colin Percival Subject: git: 023a025b5cb1 - main - x86: Add support for PVH version 1 memmap List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: cperciva X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 023a025b5cb1534f98f387e41911bbdeba06684e Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1666072994; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=8QMLyracHMrqhMkeK/j3SYbrMZjxtekl0bxwfPKh0X0=; b=A14UFAnqkn6m3vAIWrdLP5ZG1hYSYE7xLwfqOOBYKfhW5glQxI/vTC3G0RO/AKspan6Awn 22T+tIYSyd6ChWjqJ9r7gyDy9vf7U6hzG7Zu56qvymG9O/WHcRMlWsJjkYx7yDGxSLA4Be r8ug6X8m3yaiee5UcgPpp6YNdurlHcxSKb/x08w9LlRnWlWp4mPGXqr/a2nQ89TqYg0p1Y Z+Upm6h+j0ds+v75jcm4qEI9IX4C7kGiiyW5hhh/P2cssBsL1GnaAazXvEmHU/qIt2ymW1 1bd00N+0oZz+yASL/iSt88dGap87woJI4KKmVU5xSYULkD2IS0hWCQTIxVWgWQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1666072994; a=rsa-sha256; cv=none; b=JhSopsSIfBGQhGuMjZs6/TTrr1Jgdp+n7OuckWRpmtSZd9jIZd+vzFVzjLTiXStkRQh6hP sphZU/kcXCIvy9YuYgS6wJ3WfDLUCJ1OwBIUKEppqAMirMDe6B5FnSJXuDB+pQrSiaXTkL Cs9yhyP0K2mNLteoJOZh9/N6ydChHKqO/Ujx1taquj7B94/G+x4dp9p6q1EgT6dzpc0PJh sGpwN6qoqBUHo3uKgRYoveByCk3yg1sngC8vHIGm/FAnYzTOK21OldiGE2V09FIYl8o24S XAm0PCbZOzihIVeygNqnx6TpMFxszKj5h+cco664cUniQSanisxeiRWDkdIUaQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by cperciva: URL: https://cgit.FreeBSD.org/src/commit/?id=023a025b5cb1534f98f387e41911bbdeba06684e commit 023a025b5cb1534f98f387e41911bbdeba06684e Author: Colin Percival AuthorDate: 2022-07-13 00:45:41 +0000 Commit: Colin Percival CommitDate: 2022-10-18 06:02:22 +0000 x86: Add support for PVH version 1 memmap Version 0 of PVH booting uses a Xen hypercall to retrieve the system memory map; in version 1 the memory map can be provided via the start_info structure. Using the memory map from the version 1 start_info structure allows FreeBSD to use PVH booting on systems other than Xen, e.g. on the Firecracker VM. Reviewed by: royger Sponsored by: https://www.patreon.com/cperciva Differential Revision: https://reviews.freebsd.org/D35800 --- sys/x86/xen/pv.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/sys/x86/xen/pv.c b/sys/x86/xen/pv.c index 796b3ca844de..845c2d7222eb 100644 --- a/sys/x86/xen/pv.c +++ b/sys/x86/xen/pv.c @@ -94,7 +94,7 @@ uint64_t hammer_time_xen(vm_paddr_t); /*--------------------------- Forward Declarations ---------------------------*/ static caddr_t xen_pvh_parse_preload_data(uint64_t); -static void xen_pvh_parse_memmap(caddr_t, vm_paddr_t *, int *); +static void pvh_parse_memmap(caddr_t, vm_paddr_t *, int *); /*---------------------------- Extern Declarations ---------------------------*/ /* @@ -108,7 +108,7 @@ struct init_ops xen_pvh_init_ops = { .parse_preload_data = xen_pvh_parse_preload_data, .early_clock_source_init = xen_clock_init, .early_delay = xen_delay, - .parse_memmap = xen_pvh_parse_memmap, + .parse_memmap = pvh_parse_memmap, }; static struct bios_smap xen_smap[MAX_E820_ENTRIES]; @@ -395,6 +395,36 @@ xen_pvh_parse_preload_data(uint64_t modulep) return (kmdp); } +static void +pvh_parse_memmap_start_info(caddr_t kmdp, vm_paddr_t *physmap, + int *physmap_idx) +{ + const struct hvm_memmap_table_entry * entries; + size_t nentries; + size_t i; + + /* Extract from HVM start_info. */ + entries = (struct hvm_memmap_table_entry *)(start_info->memmap_paddr + KERNBASE); + nentries = start_info->memmap_entries; + + /* Convert into E820 format and handle one by one. */ + for (i = 0; i < nentries; i++) { + struct bios_smap entry; + + entry.base = entries[i].addr; + entry.length = entries[i].size; + + /* + * Luckily for us, the XEN_HVM_MEMMAP_TYPE_* values exactly + * match the SMAP_TYPE_* values so we don't need to translate + * anything here. + */ + entry.type = entries[i].type; + + bios_add_smap_entries(&entry, 1, physmap, physmap_idx); + } +} + static void xen_pvh_parse_memmap(caddr_t kmdp, vm_paddr_t *physmap, int *physmap_idx) { @@ -416,3 +446,18 @@ xen_pvh_parse_memmap(caddr_t kmdp, vm_paddr_t *physmap, int *physmap_idx) bios_add_smap_entries(xen_smap, size, physmap, physmap_idx); } + +static void +pvh_parse_memmap(caddr_t kmdp, vm_paddr_t *physmap, int *physmap_idx) +{ + + /* + * If version >= 1 and memmap_paddr != 0, use the memory map provided + * in the start_info structure; if not, we're running under legacy + * Xen and need to use the Xen hypercall. + */ + if ((start_info->version >= 1) && (start_info->memmap_paddr != 0)) + pvh_parse_memmap_start_info(kmdp, physmap, physmap_idx); + else + xen_pvh_parse_memmap(kmdp, physmap, physmap_idx); +}