From nobody Thu Nov 28 09:48:36 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=RiversideResearch.org); dmarc=pass(p=none dis=none) header.from=RiversideResearch.org ARC-Seal: i=2; a=rsa-sha256; t=1670961041; cv=pass; d=zohomail.com; s=zohoarc; b=naomV+x8nfGRH2VNZvxz6PHlwqqP/E2vQAZLIoV4nx0xktnQCCqRnMv1qnRamVvYwJqdz8vRqWlDE9UrOPmwT5Z1dyLIUhIYQWmqKqQARlpVP8rlld8MHOX6SWRa97wTM9X5CLDRLeOo1BWI/U3SovPPrf3W/uOBO7sMEUICUVY= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1670961041; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=I0PsUDkmjU8ZqrhC77SP7qB92xlR9kM72Qt2ugNECpA=; b=CZvSQxDZhcR49sASXI4QthPNl9GxBtcPCBPo3/iF5leu+5F+ZwvVVtxpUHw3/SQ0u1Fv+ebAhG8UMx+BgBYv8RgTge1PYDbDhCJA7Ax6xpb5HKTGtu7gZAhMMrsZAHr/8I1CKGM8NpuK5QKJWpDFq3aquZ9ImUxfxFcK0I8dA2U= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=RiversideResearch.org); dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1670961041925900.0595515399488; Tue, 13 Dec 2022 11:50:41 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.461118.719154 (Exim 4.92) (envelope-from ) id 1p5BI8-0002MD-S2; Tue, 13 Dec 2022 19:50:16 +0000 Received: by outflank-mailman (output) from mailman id 461118.719154; Tue, 13 Dec 2022 19:50:16 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1p5BI8-0002M6-Oe; Tue, 13 Dec 2022 19:50:16 +0000 Received: by outflank-mailman (input) for mailman id 461118; Tue, 13 Dec 2022 19:50:15 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1p5BI7-0002M0-55 for xen-devel@lists.xenproject.org; Tue, 13 Dec 2022 19:50:15 +0000 Received: from USG02-BN3-obe.outbound.protection.office365.us (mail-bn3usg02on0095.outbound.protection.office365.us [23.103.208.95]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 5b8422b5-7b1f-11ed-8fd2-01056ac49cbb; Tue, 13 Dec 2022 20:50:13 +0100 (CET) Received: from BN0P110MB1642.NAMP110.PROD.OUTLOOK.COM (2001:489a:200:185::22) by BN0P110MB1548.NAMP110.PROD.OUTLOOK.COM (2001:489a:200:186::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.19; Tue, 13 Dec 2022 19:50:11 +0000 Received: from BN0P110MB1642.NAMP110.PROD.OUTLOOK.COM ([fe80::81df:6431:7a2d:4610]) by BN0P110MB1642.NAMP110.PROD.OUTLOOK.COM ([fe80::81df:6431:7a2d:4610%5]) with mapi id 15.20.5880.019; Tue, 13 Dec 2022 19:50:11 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 5b8422b5-7b1f-11ed-8fd2-01056ac49cbb ARC-Seal: i=1; a=rsa-sha256; s=arcselector5401; d=microsoft.com; cv=none; b=sEwwqX+hQl3R+O9CVk4C7NL5UrlDq8/TOqaN1DCpWwtJfs47mA8gEgGJVRtrRA1Z2ARSCpIf+OFVwAIGokrNFrjw0sVQ84lU2W3ora0hc1+J4YfUdQ2HjIrdzXE3Izuku2VbtLeITic+hsG0Ngprr9eRc0QvwxyhbGj+SPSyBzAN6sGR+riEksPhUTcltG6egt8dBrXtnMpoSugsGs+qGYjwlXvrUEBaZQBZ/jrU2/RZ2hcUdofNzProAaYzAC9JtJvvSY5+QaJ7PHgem1qrf6fMixPN0xc7C89Am0EevHLLAj39iwqg+MpR9s2k9Dw9dGDdZ4JlZErvjDNY3s+zfQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector5401; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=I0PsUDkmjU8ZqrhC77SP7qB92xlR9kM72Qt2ugNECpA=; b=dpX60XY5mfugGZGnAFw7EdWakLrRNnLT+uS/E3fhfKzBC5iux2OoGsjP5y4FKHCHsKirDtOG7FgYSVwFMyB/YaIxvNufnQcSLqJfV9FdxHRTfMFQSQKCJ3rzDm0dU+pcWSXZ9Q7TskrscW4FZFbTHlHth0T9YMY019JFI8veHqSxXJsHHvX9XP2CUyZlI/ft2yUUehFTDVFm750f048aFvxA66NSEJg+YWjMG2f5QwEgEBiavUWjfqOoH5neC0biCGxlYVCa4Fd+oyRvWVg21LjU7kGqS6zKqtBexOZYD5BNHmYCFYDvjxSO+wSTE54XY3tsL50qEwIGNW8CNIWwZw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=riversideresearch.org; dmarc=pass action=none header.from=riversideresearch.org; dkim=pass header.d=riversideresearch.org; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=riversideresearch.org; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=I0PsUDkmjU8ZqrhC77SP7qB92xlR9kM72Qt2ugNECpA=; b=qE8asZl9Igx8921sStM9BDszW1nVghv9Oog12oBcuYk9xbu7QgPAJXHXsz/HGqRDkE8iRt1Lp54Y5THp0OsvtSfaC+BzEROXev5Yp+A25Y2qgWseRwvvDHGn7Kw3tJvErSNQq3/qW4RTAbBrTR+fMQUhpRfrx8V0fpdeep8XBlzIlkx2EH4N3w28yCgnS9lJE73ZxL4bhtCVBoQ6cvrbRy5JAXie3506a2d0ww6EyzG1ADsZm9XIwcw12hK6meg+LTNZvPNKKPycWu7QVU+AjTZDuvqSRuRKJejx+LyaMXf2ujYJsitHNsdrHqGxWBWUaTbvK0vT5Cw6pNv3SBJGzQ== From: "Smith, Jackson" To: "Smith, Jackson" CC: "Brookes, Scott" , Xen-devel , Stefano Stabellini , Julien Grall , "bertrand.marquis@arm.com" , "jbeulich@suse.com" , Andrew Cooper , =?iso-8859-1?Q?Roger_Pau_Monn=E9?= , George Dunlap , "demi@invisiblethingslab.com" , "Daniel P. Smith" , "christopher.w.clark@gmail.com" Subject: [RFC 1/4] Add VMF Hypercall Thread-Topic: [RFC 1/4] Add VMF Hypercall Thread-Index: AQHZDywch81VanlmwUKrsDP9tDkwnQ== Date: Tue, 13 Dec 2022 19:50:11 +0000 Message-ID: References: In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: suggested_attachment_session_id: 0f26b3df-fdae-edcd-dd64-bdcb516094da authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=RiversideResearch.org; x-ms-publictraffictype: Email x-ms-traffictypediagnostic: BN0P110MB1642:EE_|BN0P110MB1548:EE_ x-ms-office365-filtering-correlation-id: 23a5c9e5-4aae-4066-b453-08dadd433ef9 x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: 0xT7MpEoVqmChA2wI5osg3VqrI8nKc7Wkw5gP2mrbLrtaEDEdAYfmrterikgwteL5JAMyfvJkZUjMSPTBRmGY1ymGZkx4ICDfPl9bDwPhqELfb05Z1kKcBlpx10yZVHs0UTxnXwL9xY4VUjJhp1AWlrQBi6cr3JpTiq/+pnXZ36F/d42u0F8Z0lXtOV3Wb4Ap6yPLpCn85mhHNJhVMaYeebvLbpMVDW9L3nawwT4hUbhR3d+34NbAda1N7tdsPpPYOzrgRj3Sug8j8bshRCQYabMr1TyRKIF+gVqhMZ8JN8uBghETaLsfMYNVjoTrZK1MR/GhoDIuctqeRiypHuU9Y7W0cgvs56jiiweoD4aWhUw3u8FYjHzyYKdbvVWiuRzfxwCZJ2Yu7F/qxyZf/jc+oUWceyddq1u+FFc73IPwYjJKeR6v1C3hyg9Y5+qDudMEL0pjqcz5B29bou5LSAssgYWFGl1PzEcjN3gqxUp6v6GoROZoQvnwnt9cCkMYylzIJfYZvUwYGegTbPWqLZnSaIwfgYvlY3xfq+2T/q7+7UmwSt54nWys4nZZTkDaK1vWA1v+MsiNyi7wShJoD+LVMYEj9PYbhKCfd4mwzoBz/nWHgXjClMGVyMK9FgjJWkd3oQ3Ag3bg+Vz2flZa0Hpgg== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BN0P110MB1642.NAMP110.PROD.OUTLOOK.COM;PTR:;CAT:NONE;SFS:(13230022)(366004)(451199015)(64756008)(6200100001)(38070700005)(2906002)(38100700002)(5660300002)(7416002)(8936002)(33656002)(83380400001)(52536014)(6862004)(76116006)(66556008)(71200400001)(86362001)(8676002)(54906003)(4326008)(6506007)(55016003)(7696005)(122000001)(82960400001)(66946007)(508600001)(66446008)(9686003)(66476007)(26005)(186003)(2940100002)(85282002);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: Q4JICLo5CJNYi0RHdrzPVdK62sw73Ux7/KlpJWGMn2o4rlqJ1i1qOXVwoT6g+nBvIvAlTgz207/Qwd+9Jopz5NMFnSyuD4CVH/XmaTs66/31OHbhg9NZlk3EuvkthpFp61KUuphFALZdIOK/LsP3x6iuKY3J7Mk5yMdf04YBgj7q3mRfwkiz6OtM+PC1mpcQQjPZ0HNXO+OVvusIemoDILXicWwYio08PLdncNx0k4p5pNPDeeweTwNP4hWWQs1mFppX+edkxWS5R5LBy7zExYeGD+iP8HgqPqqbvfxH+V1Ey7HqpvvB1OCZryakDYGAuKb8OUGY0fkMKobUyafEK0Q+4YiTL4DVQTPVtn9dOsHPE38UDxQam/syXwZ0oPWgAoixljoZUI6EmMGSsdDYGGfbs0JGGfOvL3nE4UnOJ9c= Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: riversideresearch.org X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: BN0P110MB1642.NAMP110.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-Network-Message-Id: 23a5c9e5-4aae-4066-b453-08dadd433ef9 X-MS-Exchange-CrossTenant-originalarrivaltime: 13 Dec 2022 19:50:11.5289 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: bfc64a8d-9064-4c64-91c3-9d10b44c1cb6 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN0P110MB1548 X-ZohoMail-DKIM: pass (identity @riversideresearch.org) X-ZM-MESSAGEID: 1670961043639100001 Content-Type: text/plain; charset="utf-8" This commit introduces a new vmf_op hypercall. If desired, could be merged into an exisiting hypercall. Also, introduce a VMF Kconfig option and xen/vmf.h, defining the arch speci= fic functions that must be implmented to support vmf. --- tools/include/xenctrl.h | 2 + tools/libs/ctrl/xc_private.c | 5 ++ tools/libs/ctrl/xc_private.h | 5 ++ xen/arch/x86/guest/xen/hypercall_page.S | 2 + xen/common/Kconfig | 3 + xen/common/Makefile | 1 + xen/common/vmf.c | 111 ++++++++++++++++++++++++++++= ++++ xen/include/hypercall-defs.c | 6 ++ xen/include/public/vmf.h | 24 +++++++ xen/include/public/xen.h | 3 + xen/include/xen/vmf.h | 20 ++++++ 11 files changed, 182 insertions(+) create mode 100644 xen/common/vmf.c create mode 100644 xen/include/public/vmf.h create mode 100644 xen/include/xen/vmf.h diff --git a/tools/include/xenctrl.h b/tools/include/xenctrl.h index 2303787..804ddba 100644 --- a/tools/include/xenctrl.h +++ b/tools/include/xenctrl.h @@ -1604,6 +1604,8 @@ long xc_memory_op(xc_interface *xch, unsigned int cmd= , void *arg, size_t len); =20 int xc_version(xc_interface *xch, int cmd, void *arg); =20 +int xc_vmf_op(xc_interface *xch, unsigned int cmd, uint32_t domid); + int xc_flask_op(xc_interface *xch, xen_flask_op_t *op); =20 /* diff --git a/tools/libs/ctrl/xc_private.c b/tools/libs/ctrl/xc_private.c index 2f99a7d..44fe9ba 100644 --- a/tools/libs/ctrl/xc_private.c +++ b/tools/libs/ctrl/xc_private.c @@ -555,6 +555,11 @@ int xc_version(xc_interface *xch, int cmd, void *arg) return rc; } =20 +int xc_vmf_op(xc_interface *xch, unsigned int cmd, uint32_t domid) +{ + return do_vmf_op(xch, cmd, domid); +} + unsigned long xc_make_page_below_4G( xc_interface *xch, uint32_t domid, unsigned long mfn) { diff --git a/tools/libs/ctrl/xc_private.h b/tools/libs/ctrl/xc_private.h index ed960c6..fb72cb4 100644 --- a/tools/libs/ctrl/xc_private.h +++ b/tools/libs/ctrl/xc_private.h @@ -222,6 +222,11 @@ static inline int do_xen_version(xc_interface *xch, in= t cmd, xc_hypercall_buffer cmd, HYPERCALL_BUFFER_AS_ARG(dest)); } =20 +static inline int do_vmf_op(xc_interface *xch, unsigned int cmd, uint32_t = domid) +{ + return xencall2(xch->xcall, __HYPERVISOR_vmf_op, cmd, domid); +} + static inline int do_physdev_op(xc_interface *xch, int cmd, void *op, size= _t len) { int ret =3D -1; diff --git a/xen/arch/x86/guest/xen/hypercall_page.S b/xen/arch/x86/guest/x= en/hypercall_page.S index 9958d02..2efdd58 100644 --- a/xen/arch/x86/guest/xen/hypercall_page.S +++ b/xen/arch/x86/guest/xen/hypercall_page.S @@ -70,6 +70,8 @@ DECLARE_HYPERCALL(arch_5) DECLARE_HYPERCALL(arch_6) DECLARE_HYPERCALL(arch_7) =20 +DECLARE_HYPERCALL(vmf_op) + /* * Local variables: * tab-width: 8 diff --git a/xen/common/Kconfig b/xen/common/Kconfig index f1ea319..3bf92b8 100644 --- a/xen/common/Kconfig +++ b/xen/common/Kconfig @@ -92,6 +92,9 @@ config STATIC_MEMORY =20 If unsure, say N. =20 +config VMF + bool "Virtual Memory Fuse Support" + menu "Speculative hardening" =20 config INDIRECT_THUNK diff --git a/xen/common/Makefile b/xen/common/Makefile index 3baf83d..fb9118d 100644 --- a/xen/common/Makefile +++ b/xen/common/Makefile @@ -48,6 +48,7 @@ obj-y +=3D timer.o obj-$(CONFIG_TRACEBUFFER) +=3D trace.o obj-y +=3D version.o obj-y +=3D virtual_region.o +obj-$(CONFIG_VMF) +=3D vmf.o obj-y +=3D vm_event.o obj-y +=3D vmap.o obj-y +=3D vsprintf.o diff --git a/xen/common/vmf.c b/xen/common/vmf.c new file mode 100644 index 0000000..20c61d1 --- /dev/null +++ b/xen/common/vmf.c @@ -0,0 +1,111 @@ +/*************************************************************************= ***** + * vmf.c + *=20 + * Common implementation of the VMF hypercall + */ + +#include +#include + +#include +#include + +static void dump_domain_vcpus(struct domain *d) +{ + struct vcpu *v; + int i; + + if (d =3D=3D NULL) { + printk("NULL\n"); + return; + } + + printk("Domain: %d (%d vcpus)\n", d->domain_id, d->max_vcpus); +#if defined(CONFIG_ARM_64) + printk(" vttbr: 0x%lx\n", d->arch.p2m.vttbr); +#endif + + i =3D 0; + for_each_vcpu(d, v) + { + printk(" vcpu [%d: id=3D%d, proc=3D%d]: \n", i++, v->vcpu_id, v->= processor); + /* archvcpu for arm has: */ +#if defined(CONFIG_ARM_64) + printk(" .ttbr0 is 0x%lx\n", v->arch.ttbr0); + printk(" .ttbr1 is 0x%lx\n", v->arch.ttbr1); +#endif + } +} + +static void dump_domains(void) +{ + struct domain *d; + + for_each_domain(d) + dump_domain_vcpus(d); + + /* Dump system domains */ + printk("IDLE DOMAIN:\n"); + dump_domain_vcpus(idle_vcpu[0]->domain); + printk("HARDWARE DOMAIN:\n"); + dump_domain_vcpus(hardware_domain); + printk("XEN DOMAIN:\n"); + dump_domain_vcpus(dom_xen); + printk("IO DOMAIN:\n"); + dump_domain_vcpus(dom_io); +} + +long do_vmf_op(unsigned int cmd, domid_t domid) +{ + int ret =3D 0; + struct domain *d =3D NULL; + + printk("VMF hypercall: "); + + if (domid =3D=3D DOMID_IDLE) { + printk("Xen\n"); + } else if ((domid < DOMID_FIRST_RESERVED) && (d =3D get_domain_by_id(d= omid))) { + printk("Domain(%d)\n", domid); + } else { + printk("Invalid domain id (%d)\n", domid); + ret =3D -1; + goto out; + } + + switch (cmd) { + case XENVMF_dump_info: + if (d) { + vmf_dump_domain_info(d); + } else { + dump_domains(); + vmf_dump_xen_info(); + } + break; + + case XENVMF_dump_tables: + if (d) + vmf_dump_domain_tables(d); + else + vmf_dump_xen_tables(); + break; + + case XENVMF_unmap: + printk("BLOW VIRTUAL MEMORY FUSE:\n"); + if (d) { + printk("Unmapping Domain(%d)\n", d->domain_id); + vmf_unmap_guest(d); + } else { + printk("Locking Virtual Memory Configuration\n"); + vmf_lock_xen_pgtables(); + } + break; + + default: + printk("Not Implemented\n"); + break; + } + +out: + printk("Done!\n"); + return ret; +} diff --git a/xen/include/hypercall-defs.c b/xen/include/hypercall-defs.c index 1896121..fb61bc6 100644 --- a/xen/include/hypercall-defs.c +++ b/xen/include/hypercall-defs.c @@ -166,6 +166,9 @@ vm_assist(unsigned int cmd, unsigned int type) event_channel_op(int cmd, void *arg) mmuext_op(mmuext_op_t *uops, unsigned int count, unsigned int *pdone, unsi= gned int foreigndom) multicall(multicall_entry_t *call_list, unsigned int nr_calls) +#if defined(CONFIG_VMF) +vmf_op(unsigned int cmd, domid_t domid) +#endif #ifdef CONFIG_PV mmu_update(mmu_update_t *ureqs, unsigned int count, unsigned int *pdone, u= nsigned int foreigndom) stack_switch(unsigned long ss, unsigned long esp) @@ -239,6 +242,9 @@ update_va_mapping compat do - = - - set_timer_op compat do compat do - event_channel_op_compat do do - - dep xen_version compat do compat do do +#if defined(CONFIG_VMF) +vmf_op do do do do do +#endif console_io do do do do do physdev_op_compat compat do - - dep #if defined(CONFIG_GRANT_TABLE) diff --git a/xen/include/public/vmf.h b/xen/include/public/vmf.h new file mode 100644 index 0000000..a5ec004 --- /dev/null +++ b/xen/include/public/vmf.h @@ -0,0 +1,24 @@ +/* SPDX-License-Identifier: MIT */ +/*************************************************************************= ***** + * vmf.h + * + */ + +#ifndef __XEN_PUBLIC_VMF_H__ +#define __XEN_PUBLIC_VMF_H__ + +#define XENVMF_dump_info 1 +#define XENVMF_dump_tables 2 +#define XENVMF_unmap 11 + +#endif /* __XEN_PUBLIC_VMF_H__ */ + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/xen/include/public/xen.h b/xen/include/public/xen.h index 920567e..077000c 100644 --- a/xen/include/public/xen.h +++ b/xen/include/public/xen.h @@ -125,6 +125,9 @@ DEFINE_XEN_GUEST_HANDLE(xen_ulong_t); #define __HYPERVISOR_arch_6 54 #define __HYPERVISOR_arch_7 55 =20 +/* custom vmf hypercall */ +#define __HYPERVISOR_vmf_op 56 + /* ` } */ =20 /* diff --git a/xen/include/xen/vmf.h b/xen/include/xen/vmf.h new file mode 100644 index 0000000..f4b350c --- /dev/null +++ b/xen/include/xen/vmf.h @@ -0,0 +1,20 @@ +/*************************************************************************= ***** + * vmf.h + *=20 + * Public VMF interface to be implemented in arch specific code + */ + +#ifndef __XEN_VMF_H__ +#define __XEN_VMF_H__ + +struct domain; + +void vmf_dump_xen_info(void); +void vmf_dump_domain_info(struct domain *d); +void vmf_dump_xen_tables(void); +void vmf_dump_domain_tables(struct domain *d); + +void vmf_unmap_guest(struct domain *d); +void vmf_lock_xen_pgtables(void); + +#endif /* __XEN_VMF_H__ */ --=20 2.7.4 From nobody Thu Nov 28 09:48:36 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=RiversideResearch.org); dmarc=pass(p=none dis=none) header.from=RiversideResearch.org ARC-Seal: i=2; a=rsa-sha256; t=1670961211; cv=pass; d=zohomail.com; s=zohoarc; b=mDsl/ln+AnlD1gZkjnM5xQOfA/fyFhaGSiPMgSY5SCJCkEEbNTLCq5AHmuJ2PGjqvX/X74PJo4Ks8P/9EPcXDPCyZizsD2Gfc+bx5x/tSD2baUt746EoTKmrke/AWHg8v8Oonpo0dA11TNefXXYke1qG3Pq3VAVA+2tb1Mfk0zE= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1670961211; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=pHSvZrTZQtWFI7F16rrfG3KOpPlzn9NPjYA2g0/qmS8=; b=G1M7znCgWHDyLMGonAkzSh6/fyrnEBHfTrKtfKjD8Ni4C9BZEGAEmld04lEX9mhJvqgHY/6ZwZccZ85SuqGS0mShVa0Naf4FshQfKxPKTvaUFLrClgc/y0OnWycd/eJbbFYLt+xFwFmerGdn/KK7W4Avw7OGQHcyK0eI6BU7hbU= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=RiversideResearch.org); dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1670961211248543.2009262599595; Tue, 13 Dec 2022 11:53:31 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.461126.719165 (Exim 4.92) (envelope-from ) id 1p5BKv-0002zZ-8z; Tue, 13 Dec 2022 19:53:09 +0000 Received: by outflank-mailman (output) from mailman id 461126.719165; Tue, 13 Dec 2022 19:53:09 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1p5BKv-0002zS-65; Tue, 13 Dec 2022 19:53:09 +0000 Received: by outflank-mailman (input) for mailman id 461126; Tue, 13 Dec 2022 19:53:07 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1p5BKt-0002zI-J2 for xen-devel@lists.xenproject.org; Tue, 13 Dec 2022 19:53:07 +0000 Received: from USG02-BN3-obe.outbound.protection.office365.us (mail-bn3usg02on0124.outbound.protection.office365.us [23.103.208.124]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id c268770a-7b1f-11ed-8fd2-01056ac49cbb; Tue, 13 Dec 2022 20:53:06 +0100 (CET) Received: from BN0P110MB1642.NAMP110.PROD.OUTLOOK.COM (2001:489a:200:185::22) by BN0P110MB1692.NAMP110.PROD.OUTLOOK.COM (2001:489a:200:186::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.19; Tue, 13 Dec 2022 19:53:02 +0000 Received: from BN0P110MB1642.NAMP110.PROD.OUTLOOK.COM ([fe80::81df:6431:7a2d:4610]) by BN0P110MB1642.NAMP110.PROD.OUTLOOK.COM ([fe80::81df:6431:7a2d:4610%5]) with mapi id 15.20.5880.019; Tue, 13 Dec 2022 19:53:02 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: c268770a-7b1f-11ed-8fd2-01056ac49cbb ARC-Seal: i=1; a=rsa-sha256; s=arcselector5401; d=microsoft.com; cv=none; b=tnvgy/xTAJuKoLYyk/KSQLpuol8U3VjmsSAGbzsOfNnUX9eafwae9MP279xtvki9zBzrbLMQSUAmQ7nggyOKM1omI7pc6Z8CLYy5Q3VwV7V2+Jlm5pVQJG/FmeUZ3mlsYfWfftN9P9sbgfFnzrPiLFJoWRmUgcutDsbO77gQYtNee4bxdoYyicVev91fJCKz3BSf8O7fvUjFTLWAbpfSeR9Y8ZpE80/Jd1RJsEEL4rZTSPqys84F+huIS8rBkaKm9+jaR7L/hY4UaXNkkp/1jcPKZtxQcJd6f3su+JKIqlsCjmajSpf9tY7kjMMBprcsyaQ4DY8OxwrRhj6a18oZeQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector5401; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=pHSvZrTZQtWFI7F16rrfG3KOpPlzn9NPjYA2g0/qmS8=; b=CppTCcgYWyROidHWmbHX75/ZWNdmGln7ZHwteVuSvmIC6ZnGFDPl1tIB6u/MUQTAa17FzHVs+DEZjUz1AGLgyhKfSvjYnFV+780cqoOh44skiWN3vQdM4ryhulKKn8MgSOYiMJN7DX5Fd+++AYRl0Rd90GwurmSdIgv1r/mQclFGOcaozNw1jDjp5EZARff9TgQDTHgGNQ+XQHpybPCOI2sZZZeF2V6lAZoMzjyYwWFcVLx9/IHsFUns809jh606GpHNDTo4vj1ThlrIThYXidvd+ReQSjsIe5xdZQsT8eeM1CTHzPafgSz2nlV2u5k5NlBaaSzkXliQ0JgFKe/xMg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=riversideresearch.org; dmarc=pass action=none header.from=riversideresearch.org; dkim=pass header.d=riversideresearch.org; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=riversideresearch.org; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=pHSvZrTZQtWFI7F16rrfG3KOpPlzn9NPjYA2g0/qmS8=; b=rFBqmPhFr44D3GoNKdcl16bBZqxZwpRjDJtvrxytPbZdVZNqxjMcM87Yw3ZWp6YzjvQmYsHia7kile9+wdhUdRdyzRSCDNslTFWZslllTfRL8T157iKlEceyMJa3m8OYggMq3ZBuS55i3vnsKRCXe3wshq/jk4BfBiaA/l3VMkODlqTZWG2utKEE3KXfFInhB8vNqLOrtIrS/65i8mLCSTdUwKkYfPOgvtL2BLCZQ4iGzq5Y14zVWB/HuGzAzDNQe3iTiz1dOOA6dEm6Q8OlOEfSCZP0V26KBorxXKlS7bwF9E6ZcuSvfm7K/vOU7DYTA+1WN6O82tE4Il7qDHay2Q== From: "Smith, Jackson" To: "Smith, Jackson" CC: "Brookes, Scott" , Xen-devel , Stefano Stabellini , Julien Grall , "bertrand.marquis@arm.com" , "jbeulich@suse.com" , Andrew Cooper , =?iso-8859-1?Q?Roger_Pau_Monn=E9?= , George Dunlap , "demi@invisiblethingslab.com" , "Daniel P. Smith" , "christopher.w.clark@gmail.com" Subject: [RFC 2/4] Add VMF tool Thread-Topic: [RFC 2/4] Add VMF tool Thread-Index: AQHZDyyCZmiYxt72lUSeSdNxVMCy4A== Date: Tue, 13 Dec 2022 19:53:02 +0000 Message-ID: References: In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: suggested_attachment_session_id: 909825dd-f06a-34b3-d508-9ecb7894b4f7 authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=RiversideResearch.org; x-ms-publictraffictype: Email x-ms-traffictypediagnostic: BN0P110MB1642:EE_|BN0P110MB1692:EE_ x-ms-office365-filtering-correlation-id: 9891cc48-a4b6-4cbb-3e06-08dadd43a518 x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: nCakgadVebztqIerCv/2u6rfRGwe9XHMdLSO6WfssGvXzOPSU1za6JNXH6P33cRLZeKs5C2jRt094hZL1VFvpiJThW5zImmY+ww26SCTmUnjYdxjVvtk5lC8tFMnF0v9Gv/MXXvBKfinisVRWTCSby9FywhAcf5D0z4HRrRlnUj2/cXP0OuSxXMj5KSnQQkabjbL8uW4pKnDiytTjeRwhAsj0USIVWNBCyLkiiwA6yt7HAC+Dt2vazEKlASb6l3waYQc9Zk9j1ISiM0parASKeR1FFnYNDQVER5MTXZ2oINqOcdbWBM9cXmyWNXMowxTQkWOuBgUiPWy6ahWJ66wK0JQLWX9jRywH3D759xL5U9LNLq/RlicZjdUfe0zAsRB4iqWZgScP9QJ49d9Z01xG996uJumYKT+GVx6MQmaCz2Hy/dotjTUiv9geEUENZutjW6oX3Nb8HyYmbADuvwFMntXi8H7awQYIqtj6adhmVnyctFZ9tEM9wSSvjmsZ/9a2gBqWjJ/jh9e4aJqrdhA00RVZJYxSYUWkvKOlSobUWh9zJTn/NKMCSLb2mgxMGlzKgVexF5XKazsTDiRxmquQ4wXsYqQbokTG+Z0J9TFzZAS6DX+L9v5wA0skMucCw5HeKq+Up+vpxrGba1rdsaHBg== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BN0P110MB1642.NAMP110.PROD.OUTLOOK.COM;PTR:;CAT:NONE;SFS:(13230022)(366004)(451199015)(33656002)(5660300002)(7416002)(8936002)(83380400001)(6200100001)(6862004)(52536014)(38070700005)(2906002)(38100700002)(508600001)(71200400001)(8676002)(66556008)(6506007)(9686003)(186003)(26005)(2940100002)(66476007)(122000001)(7696005)(4326008)(76116006)(64756008)(82960400001)(54906003)(66446008)(86362001)(55016003)(66946007)(85282002);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: SPxrhJKb3NQixgyTO97nAykM34le54EgEMKzDTlqZfhSN6Pq/AV/6/KCpP0N1JAYquJxPHjslVXYBxg2VLPDpb39NvfhTHrgiq6eBVL9rj08HDXNl9+4pmuqFWGjO7/EnB/PEu5nyZ+1uX6b3PB2CMcK092FvSWSR3VccbN0ZRJqXv80vKIdP8R+OhOYTxJJvGRk9HO5eolvo3J0coEx/wcH3beykKZnzbIus8Cx2paz2j3hdZtHUCCaS17Nr2xCiE0KS1VNBPNsmJENUM3d9Ox5wxIcRdzvcSyOmChFSQ97HIuTBRFHJ3FA6Bi0uBBRclKcP9WW6LmU608KwNlUcYHZFywJG/KAyk7pvvdRBPrnDmBVjS9nYAJFI4Ii5mBa6B/qlLp0Wv6QoyRVQA37RwTBvHNxjjEQQztUbGefwBc= Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: riversideresearch.org X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: BN0P110MB1642.NAMP110.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-Network-Message-Id: 9891cc48-a4b6-4cbb-3e06-08dadd43a518 X-MS-Exchange-CrossTenant-originalarrivaltime: 13 Dec 2022 19:53:02.8566 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: bfc64a8d-9064-4c64-91c3-9d10b44c1cb6 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN0P110MB1692 X-ZohoMail-DKIM: pass (identity @riversideresearch.org) X-ZM-MESSAGEID: 1670961213143100001 Content-Type: text/plain; charset="utf-8" VMF tool for calling vmf_op hypercall. Eventually should be merged into xl = and related libraries. --- tools/Makefile | 1 + tools/vmf/Makefile | 32 +++++++++++++++++++++++++++ tools/vmf/vmf.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++= ++++ 3 files changed, 98 insertions(+) create mode 100644 tools/vmf/Makefile create mode 100644 tools/vmf/vmf.c diff --git a/tools/Makefile b/tools/Makefile index 7997535..ccf36a1 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -9,6 +9,7 @@ SUBDIRS-y +=3D libs SUBDIRS-y +=3D flask SUBDIRS-y +=3D fuzz SUBDIRS-y +=3D xenstore +SUBDIRS-y +=3D vmf SUBDIRS-y +=3D misc SUBDIRS-y +=3D examples SUBDIRS-y +=3D hotplug diff --git a/tools/vmf/Makefile b/tools/vmf/Makefile new file mode 100644 index 0000000..ac5073b --- /dev/null +++ b/tools/vmf/Makefile @@ -0,0 +1,32 @@ +XEN_ROOT=3D$(CURDIR)/../.. +include $(XEN_ROOT)/tools/Rules.mk + +CFLAGS +=3D $(CFLAGS_libxenctrl) +LDLIBS +=3D $(LDLIBS_libxenctrl) + +.PHONY: all +all: build + +.PHONY: build +build: vmf + +.PHONY: install +install: build + $(INSTALL_DIR) $(DESTDIR)$(bindir) + $(INSTALL_PROG) vmf $(DESTDIR)$(bindir)/vmf + +.PHONY: uninstall +uninstall: + rm -f $(DESTDIR)$(bindir)/vmf + +.PHONY: clean +clean: + $(RM) -f $(DEPS_RM) vmf vmf.o + +.PHONY: distclean +distclean: clean + +vmf: vmf.o Makefile + $(CC) $(LDFLAGS) $< -o $@ $(LDLIBS) $(APPEND_LDFLAGS) + +-include $(DEPS_INCLUDE) diff --git a/tools/vmf/vmf.c b/tools/vmf/vmf.c new file mode 100644 index 0000000..8b7b293 --- /dev/null +++ b/tools/vmf/vmf.c @@ -0,0 +1,65 @@ +#include +#include +#include +#include + +#include +#include + +int call(unsigned int cmd, unsigned int domid) +{ + int ret; + + xc_interface *xch =3D xc_interface_open(NULL, NULL, 0); + ret =3D xc_vmf_op(xch, cmd, domid); + xc_interface_close(xch); + + return ret; +} + +void help(const char *arg0) +{ + printf("Usage:\n"); + printf(" %s dump\n", arg0); + printf(" %s info \n", arg0); + printf(" %s tables \n", arg0); + printf(" %s unmap \n", arg0); + printf(" %s lock\n", arg0); +} + +int get_domid(const char *str) { + char *endptr; + long domid =3D strtol(str, &endptr, 10); + if (domid >=3D 0) + return (int)domid; + + printf("Invalid domid (%ld)\n", domid); + exit(1); +} + +int main(int argc, const char* argv[]) +{ + int domid; + if (argc =3D=3D 2) { + domid =3D DOMID_IDLE; + } else if (argc =3D=3D 3) { + domid =3D get_domid(argv[2]); + } else { + help(argv[0]); + return 0; + } + +#define ARG(cmd) ((strcmp(cmd, argv[1]) =3D=3D 0)) + + if (ARG("info")) + return call(XENVMF_dump_info, domid); + else if (ARG("tables")) + return call(XENVMF_dump_tables, domid); + else if (ARG("unmap")) + return call(XENVMF_unmap, domid); + else if (ARG("lock") && (argc =3D=3D 2)) + return call(XENVMF_unmap, DOMID_IDLE); + + help(argv[0]); + return 0; +} --=20 2.7.4 From nobody Thu Nov 28 09:48:36 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=RiversideResearch.org); dmarc=pass(p=none dis=none) header.from=RiversideResearch.org ARC-Seal: i=2; a=rsa-sha256; t=1670961278; cv=pass; d=zohomail.com; s=zohoarc; b=IUB9zPqXHJ+aBGHHVVNgoHH5zXbMyO1olVgYDEf9mWlrmK9eQZONCaS9T4XEXTDjUDOPKZJ52uvjF6/wJjdQorkGEBwfIXGTM6NmiwtHk+Qbz/HC3S6ddiSa+iastmnP6/F2XjSWGmaV946nsGWlKYqVehrAc6tnpocNAULA9Hg= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1670961278; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=I0hQaAJM6caWYQsVLchpOdKLdgvJiFe099wRxpfgIbQ=; b=YWt8R7L/Z34kraFD6p5tMxt9HJL9Z3UWcQNbdBEtPoqhLcopbYTNFi2YISi8DSUj2Vd8l3kix3s6s6rxm+EWyVz2Kep1I7PhoPuAI3C1TUJyqe43yDKvNtCT3a5qAAbUX1RxiMr3wfItTEXkGIaLFpHO8Wr+HPaMwFES7bB8IF4= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=RiversideResearch.org); dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1670961278667485.64983134411534; Tue, 13 Dec 2022 11:54:38 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.461134.719176 (Exim 4.92) (envelope-from ) id 1p5BLw-0003Yf-I1; Tue, 13 Dec 2022 19:54:12 +0000 Received: by outflank-mailman (output) from mailman id 461134.719176; Tue, 13 Dec 2022 19:54:12 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1p5BLw-0003YY-FN; Tue, 13 Dec 2022 19:54:12 +0000 Received: by outflank-mailman (input) for mailman id 461134; Tue, 13 Dec 2022 19:54:11 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1p5BLv-0003YK-0r for xen-devel@lists.xenproject.org; Tue, 13 Dec 2022 19:54:11 +0000 Received: from USG02-BN3-obe.outbound.protection.office365.us (mail-bn3usg02on0094.outbound.protection.office365.us [23.103.208.94]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id e85604e7-7b1f-11ed-91b6-6bf2151ebd3b; Tue, 13 Dec 2022 20:54:10 +0100 (CET) Received: from BN0P110MB1642.NAMP110.PROD.OUTLOOK.COM (2001:489a:200:185::22) by BN0P110MB1144.NAMP110.PROD.OUTLOOK.COM (2001:489a:200:16c::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.19; Tue, 13 Dec 2022 19:54:07 +0000 Received: from BN0P110MB1642.NAMP110.PROD.OUTLOOK.COM ([fe80::81df:6431:7a2d:4610]) by BN0P110MB1642.NAMP110.PROD.OUTLOOK.COM ([fe80::81df:6431:7a2d:4610%5]) with mapi id 15.20.5880.019; Tue, 13 Dec 2022 19:54:07 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: e85604e7-7b1f-11ed-91b6-6bf2151ebd3b ARC-Seal: i=1; a=rsa-sha256; s=arcselector5401; d=microsoft.com; cv=none; b=O+/0vzajBh+OmvEUVk170fpT1FVhL9xZerkWC9wVoBhm+76ZUfWDDiSq53jgf484a0FCKz7iykqFkUS1g+NzXrBdWOgjdKYTnDBVkOUPqpbcCyIrbTxWfo1+XlATZ+tCexOiqankzhuunFudI9knhUczE7H35F3/nze2i7Uj0oXNp+x7avawrMOx87K2Y/N7pdb7Y8nw62H20CUh629cV8HpGsodfD9bpdoGkXql/0Xure20hcaFD9L1rKSXUCJmhDRXeoomnmhRna9NDsY+OsABU4hgVMtReoHw9HPyfXhf9aalzsDbZWdUboprJoXimBZLAqxn3qL52TYFlIOqmA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector5401; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=I0hQaAJM6caWYQsVLchpOdKLdgvJiFe099wRxpfgIbQ=; b=1CKsVqn1PcNis65wzRqOGVxOjJkHRIBph4jSu8QzQUZppcZ2pg8KDzg6FLmy4XIYVzN8lDeXgN/fIseSD1659V3cUYgszp6f1Dxiczc35cCaqHMCunlQ+TZ/PCMTaqDbQ0jHZoijOO6RXA+3vvkBircDtzU/kEIXsb9EoDXX76yqybIjO32PBgW35nVrH2/y8DpYPhiJV4F40jKQj8bmKl+2uGV9lGDfJ1Hwr6HBBghju6NS9+QwaVG0WEC1HTINSN4/rLcMEShzX7TPoJKvQcIfqtSqypybIJBNbSD58zj/waMQVJ8MjIwd6k56OD75wzEOIt7lFe2lvq22YJvGwA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=riversideresearch.org; dmarc=pass action=none header.from=riversideresearch.org; dkim=pass header.d=riversideresearch.org; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=riversideresearch.org; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=I0hQaAJM6caWYQsVLchpOdKLdgvJiFe099wRxpfgIbQ=; b=KYG33CvJUZs56K0bN5ZPLS9FkDuZEnHLZJeKc1TgVkE+BSmez5lfQTS3nqd1eN4nSk9BW4Obvi6FCO6kLZVUu9xsmUl4LxSx2rkM1J98SOJYSKbXRQz7irM/BCLXuRA2mkIxJ+FbDwiTT79SH11CGRY05URcogiFzMHjWAbKuPMAsG9KH4CyTxjzLoiXeHZu2DKRW7d+RF0gBoUr+gij+ZnSwAQspGI1ibzJ+L6CoUrcpiL+RGK5F7YT/8X/Gt2J0Tget54eb7nJ24jkdY+TEPhKGnEmM6u6EUbs95O6kGYf4uX2gPWkx+00iEkoR7D/Dpj4hihchsBGRvWHkBdPYg== From: "Smith, Jackson" To: "Smith, Jackson" CC: "Brookes, Scott" , Xen-devel , Stefano Stabellini , Julien Grall , "bertrand.marquis@arm.com" , "jbeulich@suse.com" , Andrew Cooper , =?iso-8859-1?Q?Roger_Pau_Monn=E9?= , George Dunlap , "demi@invisiblethingslab.com" , "Daniel P. Smith" , "christopher.w.clark@gmail.com" Subject: [RFC 3/4] Add xen superpage splitting support to arm Thread-Topic: [RFC 3/4] Add xen superpage splitting support to arm Thread-Index: AQHZDyypbad3do/0AUGsmgE77Sct8w== Date: Tue, 13 Dec 2022 19:54:07 +0000 Message-ID: References: In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: suggested_attachment_session_id: a5e26e9e-108f-3533-e10a-338a3d7bfe08 authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=RiversideResearch.org; x-ms-publictraffictype: Email x-ms-traffictypediagnostic: BN0P110MB1642:EE_|BN0P110MB1144:EE_ x-ms-office365-filtering-correlation-id: 5f3813f8-b491-42a9-268d-08dadd43cbde x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: 7XpYaVGp3N8EOCa2JupsF7Ms8g0/3Bm5wueOBuuz2r/8w2s1QH6z466VbVgkaDeBXmlLwsRTczgcTK5zpitTcH185bMmdpWxaPOg/2i/uIUPwajJ+hN4u0odtKoBYCZNGDjn7vg/lX16FQ4vISQU8gFfWPzKC/+bBW1+hod13nVdMKp2XEnqF0JejL8/SsqFG2lyU7IwtZhKn874ERf5p0XJ6A7ww36YLl9t9VZSD+BSE0jW0pUfZ1OMRpaW43+sb0zc9JMIIT3sUbMxh/yFnKJThkv8CSTfdAOoepB3LducXSPJSbAUVIadhekZXyA2S/tR7jNJVTHapb3GEONr9xAfrTCMey7aKMVoqCY1HvFtD/1khO5m90ICpJK5v+q42v84KZhaT2L4eS6rS0kE4hzXjSbQVUp4kS/sUTQ+6Fjkj3yrEOZ2OkIhchk9UzTLIYaPvkh6qXq1NX5vpzRqbX6Yve9UnlGyXgm3UAsVYj3KZPQJBnBcJWtRbHJioH2AKj9s5S+/YdBt1U6waJTT7g4Kltn9lx5UAY3UpwYioqZ/DRF3GpVOZ058lb/f4sXrCOjKUpa3DQi4/S1YvoHwuDiEFOaVUZfHxsOL+RJ7WEu9DkJA0uFV9RV5LepqigCByyf5PazZ5wqD8U0iWbkqtg== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BN0P110MB1642.NAMP110.PROD.OUTLOOK.COM;PTR:;CAT:NONE;SFS:(13230022)(366004)(451199015)(6506007)(83380400001)(7696005)(9686003)(2940100002)(508600001)(2906002)(6200100001)(86362001)(55016003)(33656002)(54906003)(38100700002)(82960400001)(38070700005)(76116006)(71200400001)(66556008)(66476007)(26005)(4326008)(66946007)(64756008)(8676002)(186003)(66446008)(8936002)(7416002)(6862004)(122000001)(5660300002)(52536014)(85282002);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: 32tv+ytXFtOPFk15lgXZU+fK8Ft0ParkAqR3ZHgLV0XCrRfT+TuM4K7OCz0QJEjECOc5Y6wlVu2Mg3SrlvJj5B3BHfk6j+7SQvV9GwP1XwVAliUF+DSRgvM2HmQwXq3e18dnvoxTrzzkoxllX1Fz6jaRD3lkhtujXspxPEQYBC8bmNEvMDAWgTC7TgdQ/L/7UNcuCfziTQmgkgebVo0wXAMMnWlPUD9xr10Ryg8BuRS9pi4aH/b90JZ7O8PHuIAKYt7iTHdd3nc6sjAWT0yvTiS1owoKjsY9FZf+yqmv8fKQfLIsGEx4+2TZId2rOCoIHnTp3Xh2Ktz1HBqbD38o73G9VtYA6F1dm7QpL3s6yMviV0B59QEk0Ce7IC/hZnuTjxK50GUU8erXt1e2jfJykCuvYRQeaqWFYpkRSOMx8LM= Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: riversideresearch.org X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: BN0P110MB1642.NAMP110.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-Network-Message-Id: 5f3813f8-b491-42a9-268d-08dadd43cbde X-MS-Exchange-CrossTenant-originalarrivaltime: 13 Dec 2022 19:54:07.8758 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: bfc64a8d-9064-4c64-91c3-9d10b44c1cb6 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN0P110MB1144 X-ZohoMail-DKIM: pass (identity @riversideresearch.org) X-ZM-MESSAGEID: 1670961280035100001 Content-Type: text/plain; charset="utf-8" Updates xen_pt_update_entry function from xen/arch/arm/mm.c to automatically split superpages as needed. --- xen/arch/arm/mm.c | 91 +++++++++++++++++++++++++++++++++++++++++++++++----= ---- 1 file changed, 78 insertions(+), 13 deletions(-) diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index 6301752..91b9c2b 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -753,8 +753,78 @@ static int create_xen_table(lpae_t *entry) } =20 #define XEN_TABLE_MAP_FAILED 0 -#define XEN_TABLE_SUPER_PAGE 1 -#define XEN_TABLE_NORMAL_PAGE 2 +#define XEN_TABLE_NORMAL_PAGE 1 + +/* More or less taken from p2m_split_superpage, without the p2m stuff */ +static bool xen_split_superpage(lpae_t *entry, unsigned int level, + unsigned int target, const unsigned int *o= ffsets) +{ + struct page_info *page; + lpae_t pte, *table; + unsigned int i; + bool rv =3D true; + + mfn_t mfn =3D lpae_get_mfn(*entry); + unsigned int next_level =3D level + 1; + unsigned int level_order =3D XEN_PT_LEVEL_ORDER(next_level); + + ASSERT(level < target); + ASSERT(lpae_is_superpage(*entry, level)); + + page =3D alloc_domheap_page(NULL, 0); + if ( !page ) + return false; + + table =3D __map_domain_page(page); + + /* + * We are either splitting a first level 1G page into 512 second level + * 2M pages, or a second level 2M page into 512 third level 4K pages. + */ + for ( i =3D 0; i < XEN_PT_LPAE_ENTRIES; i++ ) + { + lpae_t *new_entry =3D table + i; + + /* + * Use the content of the superpage entry and override + * the necessary fields. So the correct permission are kept. + */ + pte =3D *entry; + lpae_set_mfn(pte, mfn_add(mfn, i << level_order)); + + /* + * First and second level pages set walk.table =3D 0, but third + * level entries set walk.table =3D 1. + */ + pte.walk.table =3D (next_level =3D=3D 3); + + write_pte(new_entry, pte); + } + + /* + * Shatter superpage in the page to the level we want to make the + * changes. + * This is done outside the loop to avoid checking the offset to + * know whether the entry should be shattered for every entry. + */ + if ( next_level !=3D target ) + rv =3D xen_split_superpage(table + offsets[next_level], + level + 1, target, offsets); + + clean_dcache_va_range(table, PAGE_SIZE); + unmap_domain_page(table); + + /* + * Generate the entry for this new table we created, + * and write it back in place of the superpage entry. + */ + pte =3D mfn_to_xen_entry(page_to_mfn(page), MT_NORMAL); + pte.pt.table =3D 1; + write_pte(entry, pte); + clean_dcache(*entry); + + return rv; +} =20 /* * Take the currently mapped table, find the corresponding entry, @@ -767,16 +837,15 @@ static int create_xen_table(lpae_t *entry) * XEN_TABLE_MAP_FAILED: Either read_only was set and the entry * was empty, or allocating a new page failed. * XEN_TABLE_NORMAL_PAGE: next level mapped normally - * XEN_TABLE_SUPER_PAGE: The next entry points to a superpage. */ static int xen_pt_next_level(bool read_only, unsigned int level, - lpae_t **table, unsigned int offset) + lpae_t **table, const unsigned int *offsets) { lpae_t *entry; int ret; mfn_t mfn; =20 - entry =3D *table + offset; + entry =3D *table + offsets[level]; =20 if ( !lpae_is_valid(*entry) ) { @@ -790,7 +859,8 @@ static int xen_pt_next_level(bool read_only, unsigned i= nt level, =20 /* The function xen_pt_next_level is never called at the 3rd level */ if ( lpae_is_mapping(*entry, level) ) - return XEN_TABLE_SUPER_PAGE; + /* Shatter the superpage before continuing */ + xen_split_superpage(entry, level, level + 1, offsets); =20 mfn =3D lpae_get_mfn(*entry); =20 @@ -915,7 +985,7 @@ static int xen_pt_update_entry(mfn_t root, unsigned lon= g virt, table =3D xen_map_table(root); for ( level =3D HYP_PT_ROOT_LEVEL; level < target; level++ ) { - rc =3D xen_pt_next_level(read_only, level, &table, offsets[level]); + rc =3D xen_pt_next_level(read_only, level, &table, offsets); if ( rc =3D=3D XEN_TABLE_MAP_FAILED ) { /* @@ -941,12 +1011,7 @@ static int xen_pt_update_entry(mfn_t root, unsigned l= ong virt, break; } =20 - if ( level !=3D target ) - { - mm_printk("%s: Shattering superpage is not supported\n", __func__); - rc =3D -EOPNOTSUPP; - goto out; - } + BUG_ON( level !=3D target ); =20 entry =3D table + offsets[level]; =20 --=20 2.7.4 From nobody Thu Nov 28 09:48:36 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=RiversideResearch.org); dmarc=pass(p=none dis=none) header.from=RiversideResearch.org ARC-Seal: i=2; a=rsa-sha256; t=1670961361; cv=pass; d=zohomail.com; s=zohoarc; b=RBLGSJJgb9L5MrRS4Lha4qFdDCpSNHVHUp8oPsUudEND+HpmhDLWIea/1FMmt1m0PTuGqCrHO+hTe0uFfi5ryow14UCnnxTIdetLC9TpiQnTrWaJHKgWjOitcw8Dy6eHRO1WtWdzoJt/cRiuEbkoAbj5RAVS8xZQvYBebfW3ZP4= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1670961361; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=8IMI+mmkmPVmMi766DubIF+lD8dUSlj9ua78sytnAyM=; b=WuE0hdpNCXmgQKLleCi0/gpK6pYV1170UteZuDM0efPxJ80e40ginoBQlwWZs7QIe49O+X69lxU3/wb51jS5Wch2m9jdx4JxyhV+vEBLmS4RiQdi7KFsN+dw3rczfBHx3UQjlExFijuZf9TcopW8RN/oqtb7vywSbgJP7YwHRxk= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=RiversideResearch.org); dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1670961360975870.73950104223; Tue, 13 Dec 2022 11:56:00 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.461144.719187 (Exim 4.92) (envelope-from ) id 1p5BNM-0004DQ-2j; Tue, 13 Dec 2022 19:55:40 +0000 Received: by outflank-mailman (output) from mailman id 461144.719187; Tue, 13 Dec 2022 19:55:40 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1p5BNL-0004DJ-Vl; Tue, 13 Dec 2022 19:55:39 +0000 Received: by outflank-mailman (input) for mailman id 461144; Tue, 13 Dec 2022 19:55:39 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1p5BNL-0004DD-81 for xen-devel@lists.xenproject.org; Tue, 13 Dec 2022 19:55:39 +0000 Received: from USG02-BN3-obe.outbound.protection.office365.us (mail-bn3usg02on0102.outbound.protection.office365.us [23.103.208.102]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 1c7be157-7b20-11ed-8fd2-01056ac49cbb; Tue, 13 Dec 2022 20:55:37 +0100 (CET) Received: from BN0P110MB1642.NAMP110.PROD.OUTLOOK.COM (2001:489a:200:185::22) by BN0P110MB1723.NAMP110.PROD.OUTLOOK.COM (2001:489a:200:16f::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.19; Tue, 13 Dec 2022 19:55:34 +0000 Received: from BN0P110MB1642.NAMP110.PROD.OUTLOOK.COM ([fe80::81df:6431:7a2d:4610]) by BN0P110MB1642.NAMP110.PROD.OUTLOOK.COM ([fe80::81df:6431:7a2d:4610%5]) with mapi id 15.20.5880.019; Tue, 13 Dec 2022 19:55:34 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 1c7be157-7b20-11ed-8fd2-01056ac49cbb ARC-Seal: i=1; a=rsa-sha256; s=arcselector5401; d=microsoft.com; cv=none; b=imL7yCjurKa27rC7dgfE9HCqhq2TiwWcoSEFvXDBAG5kMKLiPyAVNqOfs7lECKpHAkrzyNSBJsfXX/2PMt7m0tv2gQdZVwbYC3cMFzX9bJSj1XV5ChmXeqpLzrwQItDfyRAKFdQrfqvpipV74TwigptuzKK0Xn2huMKgbmXYA4egtvLudr2UTenrIq9ilQMqj90wjvnSZ4r1y4sgSGOi1lH9zd1x+P+E9VD9MpNr61EvkxFMwcTCGEo7TxMpnYxrloRwjs6ESpI8lMDUR8WEE1jBRmOr6aIug3eAcWzyPYlIBAxI5+HE+wIM8o9OVW9SeDuhnAKY48OSm7VvPhORzA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector5401; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=8IMI+mmkmPVmMi766DubIF+lD8dUSlj9ua78sytnAyM=; b=wC6IgpssASedNx2cvzJHW+WDfM/Tka3DNL46sE0PVLvl7FzPrtK78gMTQjd6CBz8pLueKdX3XoCaGKtWPx1Dm3j3Rc5RS4WSGrf5Jy0kCYCc/uHNl7VWvYcku+p6XuLqhq1x05ZOWXlDx0WTs2xZ6Bu8y5Fl5lCRO3Qa6v0s0UFxqqnyVBgwnOGBNgojcRslKIna7QZIxDqSPAHZrBeTOGYPvTf0xx43gJAGHGrmv7SMGz0WxuBENAVZQtX2wDshM7p76cWT19S+P5RqFxcg27qKNOqO60HfR3N0hpGbd81UzlJnkBBteBdbWsgCr+Hgv4BtLYuOEhxj4o8YbS567A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=riversideresearch.org; dmarc=pass action=none header.from=riversideresearch.org; dkim=pass header.d=riversideresearch.org; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=riversideresearch.org; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=8IMI+mmkmPVmMi766DubIF+lD8dUSlj9ua78sytnAyM=; b=ZoCWXtXVTv1GMonMKnUjoZWIlVDNS3C/tcHIdJ8GMB+eChENikRlbn1cypGgT3dP6KWEb90yaOLN68qgtCpjt2t7jWzubcWgUAvF4epzuHcHOyfgI15QG+6re12NZDTdT+JiSTv1L8mQFl0me/vB6Z+2In+95+cmO+QchriWbptYrSi+XGxd+nC141IFQx1/fD+JLf06kE7lxd/3oncbnESZpZsg/cWYYK/n2jkw4NDZt8LiJJa5r5dAB7I+BrwVBaelwB45bOgS9rY1r/mmghqEOm3UmlDUgnMxyg/Phs0m2E0oQHrmdC1j4sp2g5Uc+PFO+18d8TqOg4QF3Ekfew== From: "Smith, Jackson" To: "Smith, Jackson" CC: "Brookes, Scott" , Xen-devel , Stefano Stabellini , Julien Grall , "bertrand.marquis@arm.com" , "jbeulich@suse.com" , Andrew Cooper , =?iso-8859-1?Q?Roger_Pau_Monn=E9?= , George Dunlap , "demi@invisiblethingslab.com" , "Daniel P. Smith" , "christopher.w.clark@gmail.com" Subject: [RFC 4/4] Implement VMF for arm64 Thread-Topic: [RFC 4/4] Implement VMF for arm64 Thread-Index: AQHZDyzdNLqpW42xnEGVL+R/wWY6pg== Date: Tue, 13 Dec 2022 19:55:34 +0000 Message-ID: References: In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: suggested_attachment_session_id: c8fc6a6e-64fc-8b95-9f14-261ab31ebef3 authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=RiversideResearch.org; x-ms-publictraffictype: Email x-ms-traffictypediagnostic: BN0P110MB1642:EE_|BN0P110MB1723:EE_ x-ms-office365-filtering-correlation-id: d191301d-682b-4a07-86f5-08dadd43ffa8 x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: 4CPAHUiMcyua0BIinpi+oOCBLmY/iVlBxOOEIKZrdIJscUMnXvhgzJXp75JK5prO3KqIHWJQhTGQ6obOaNBIFdLXPdS/YYUJX7tzophdFDkeRp+SIfMKd0QvpQfhOgcaKbA2mde3b7y8MkEMHBmRbzzUlO6HttTlOX9GRbDfHOjrc5FEkPKgwCr2k2yX/bzol4Q0WKwVvXCAEAh0HMHuZACn6AnSdQoCfq3C5i2U58TTQ/CkKhVkz3EGK3s7MW/NgBDDflztsVmS6FEaQvF3o8znCeBQM4haRQA/A6flceQXV/lDAj4ePerP+9qzsjy9uitH7n6535JdaX1IA+0aAyBdCI0VbmhdPsO+1xnjpa5hQBydUmp+UxKxoYNFbT6nRowUtRa7dt2dYw+S68yAn+4rwovl54DdIxLY3lTmS9XpxRo/9aMIHjjNj2vZ7Rz7G9L934BTxRg3Ejnmtvb1BEDdPPQ6oTsiitqi5sxNtSeQH826N/jMwSmjVzohWIX+3NXs7uC+PIhNOQQHB7daP7bNfONLU29Mbv/6BxP1rNvsulAW+X82udHvUffpG/4BozbyFvhNmJwKZjuNo2s3gj/smMS1fdKgMG1c/Md3wr1gEpFl4iQu7W3R0s3TQq8CdRmmiQyv31QBpTrDUadZT61SrJOtCVwrdwTV85a0IrCrXYbLFo6F4Jh5f98fW5eM x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BN0P110MB1642.NAMP110.PROD.OUTLOOK.COM;PTR:;CAT:NONE;SFS:(13230022)(366004)(451199015)(7696005)(2906002)(33656002)(66946007)(86362001)(6506007)(186003)(508600001)(6200100001)(9686003)(2940100002)(83380400001)(4326008)(66556008)(64756008)(66476007)(76116006)(6862004)(26005)(52536014)(5660300002)(122000001)(7416002)(30864003)(82960400001)(8936002)(8676002)(54906003)(71200400001)(38070700005)(38100700002)(66446008)(55016003)(2004002)(21314003)(85282002);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: 9oz6PTr2lz0cxAWTwBFXqzjvmZj1AYqsuiYvpd7O2r3l8Mkg0wwu+CsT8lB0FSLxkLtuEeEizXSfvB+SXEyB7gOZEIOU/6Gw3v6hD+3RA5JOoPQaonVPPuqG+aurEbhyCvrZfuF6ij/Q1wQEQz9ATESYiT6QYLUZsD2gc2hq0DgUYhH/Tw0mhyIGPLMzqV0oKC0W+iSzD3Flevg/jk2QwQ57CCHeLZvFROBTM5Gzes19SP+6PvuErWTZsbqqVyGn9DAVgZ1Ga/lBjsPRo6IK2SVyLykYLkQE/7y5KudKfxQztxuOSYwdGhQOIzI20EGygGTMriwfGMbrhxRTziLESGhRjTBY2Q1uBNftvU1I14w/d6KUjX6bW3kiF2AvoNXl1+E4siv14xdZjhRU8GZBInWfmojDMJqgKHY45wpRFcw= Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: riversideresearch.org X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: BN0P110MB1642.NAMP110.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-Network-Message-Id: d191301d-682b-4a07-86f5-08dadd43ffa8 X-MS-Exchange-CrossTenant-originalarrivaltime: 13 Dec 2022 19:55:34.7816 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: bfc64a8d-9064-4c64-91c3-9d10b44c1cb6 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN0P110MB1723 X-ZohoMail-DKIM: pass (identity @riversideresearch.org) X-ZM-MESSAGEID: 1670961362231100001 Content-Type: text/plain; charset="utf-8" Implements the functions from xen/vmf.h for arm64. Introduces an xen/arch/arm/mm-walk.c helper file for walking an entire page table structure. --- xen/arch/arm/Makefile | 1 + xen/arch/arm/include/asm/mm-walk.h | 53 ++++++++++ xen/arch/arm/include/asm/mm.h | 11 +++ xen/arch/arm/mm-walk.c | 181 +++++++++++++++++++++++++++++++++ xen/arch/arm/mm.c | 198 +++++++++++++++++++++++++++++++++= +++- xen/common/Kconfig | 2 + 6 files changed, 445 insertions(+), 1 deletion(-) create mode 100644 xen/arch/arm/include/asm/mm-walk.h create mode 100644 xen/arch/arm/mm-walk.c diff --git a/xen/arch/arm/Makefile b/xen/arch/arm/Makefile index 4d076b2..e358452 100644 --- a/xen/arch/arm/Makefile +++ b/xen/arch/arm/Makefile @@ -37,6 +37,7 @@ obj-y +=3D kernel.init.o obj-$(CONFIG_LIVEPATCH) +=3D livepatch.o obj-y +=3D mem_access.o obj-y +=3D mm.o +obj-y +=3D mm-walk.o obj-y +=3D monitor.o obj-y +=3D p2m.o obj-y +=3D percpu.o diff --git a/xen/arch/arm/include/asm/mm-walk.h b/xen/arch/arm/include/asm/= mm-walk.h new file mode 100644 index 0000000..770cc89 --- /dev/null +++ b/xen/arch/arm/include/asm/mm-walk.h @@ -0,0 +1,53 @@ +#ifndef __ARM_MM_WALK_H__ +#define __ARM_MM_WALK_H__ + +#include + +#define RECURSIVE_IDX ((unsigned long)(XEN_PT_LPAE_ENTRIES-1)) +#define RECURSIVE_VA (RECURSIVE_IDX << ZEROETH_SHIFT) + +/* + * Remove all mappings in these tables from Xen's address space + * Only makes sense if walking a guest's tables + */ +#define WALK_HIDE_GUEST_MAPPING (1U << 0) +/* + * Remove all mappings to these tables from Xen's address space + * Makes sense if walking a guest's table (hide guest tables from Xen) + * Or if walking Xen's tables (lock Xen's virtual memory configuration) + */ +#define WALK_HIDE_GUEST_TABLE (1U << 1) + +/* + * Before we can hide individual table entires, + * we need to split the directmap superpages + */ +#define WALK_SPLIT_DIRECTMAP_TABLE (1U << 2) +/* + * Like walk table hide, but using recursive mapping + * to bypass walking directmap when table is in the directmap + */ +#define WALK_HIDE_DIRECTMAP_TABLE (1U << 3) + +/* These are useful for development/debug */ +/* Show all pte's for a given address space */ +#define WALK_DUMP_ENTRIES (1U << 4) +/* Show all mappings for a given address space */ +#define WALK_DUMP_MAPPINGS (1U << 5) + +/* + * Given the value of a ttbr register, this function walks every valid ent= ry in the trie + * (As opposed to dump_pt_walk, which follows a single address from root t= o leaf) + */ +void do_walk_tables(paddr_t ttbr, int root_level, int nr_root_tables, int = flags); + +#endif /* __ARM_MM_WALK_H__ */ +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/xen/arch/arm/include/asm/mm.h b/xen/arch/arm/include/asm/mm.h index 68adcac..2e85885 100644 --- a/xen/arch/arm/include/asm/mm.h +++ b/xen/arch/arm/include/asm/mm.h @@ -209,6 +209,17 @@ extern void mmu_init_secondary_cpu(void); * For Arm64, map the region in the directmap area. */ extern void setup_directmap_mappings(unsigned long base_mfn, unsigned long= nr_mfns); +/* Shatter superpages for these mfns if needed */ +extern int split_directmap_mapping(unsigned long mfn, unsigned long nr_mfn= s); +/* Remove these mfns from the directmap */ +extern int destroy_directmap_mapping(unsigned long mfn, unsigned long nr_m= fns); +/* + * Remove this mfn from the directmap (bypassing normal update code) + * This is a workaround for current pgtable update code, which cannot be u= sed + * to remove directmap table entries from the directmap (because they are + * needed to walk the directmap) + */ +extern void destroy_directmap_table(unsigned long mfn); /* Map a frame table to cover physical addresses ps through pe */ extern void setup_frametable_mappings(paddr_t ps, paddr_t pe); /* map a physical range in virtual memory */ diff --git a/xen/arch/arm/mm-walk.c b/xen/arch/arm/mm-walk.c new file mode 100644 index 0000000..48f9b2d --- /dev/null +++ b/xen/arch/arm/mm-walk.c @@ -0,0 +1,181 @@ +/* + * xen/arch/arm/mm-walk.c + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include +#include + +#include +#include + +typedef struct { + /* Keeps track of all the table offsets so we can reconstruct the VA i= f we need to */ + int off[4]; + + /* Keeps track of root level so we can make sense of the table offsets= */ + int root_level; + int root_table_idx; /* only meaningful when nr_root_tables > 1 */ +} walk_info_t; + +/* + * Turn a walk_info_t into a virtual address + * + * XXX: This only applies to the lower VA range + * Ie. if you are looking at a table in ttbr1, this is different + * XXX: doesn't work for concat tables right now either + */ +static unsigned long walk_to_va(int level, walk_info_t *walk) +{ +/* #define off_valid(x) (((x) <=3D level) && ((x) >=3D walk->root_level)) = */ +#define off_valid(x) ((x) <=3D level) +#define off_val(x) ((u64)(off_valid(x) ? walk->off[x] : 0)) + + return (off_val(0) << ZEROETH_SHIFT) \ + | (off_val(1) << FIRST_SHIFT) \ + | (off_val(2) << SECOND_SHIFT) \ + | (off_val(3) << THIRD_SHIFT); +} + +/* Prints each entry in the form "\t @XTH TABLE:0.0.0.0 =3D 0xENTRY" */ +static void dump_entry(int level, lpae_t pte, walk_info_t *walk) +{ + int i; + static const char *level_strs[4] =3D { "0TH", "1ST", "2ND", "3RD" }; + ASSERT(level <=3D 3); + + for (i =3D 0; i < level; i++) + printk(" "); + + printk("@%s %i:", level_strs[level], walk->root_table_idx); + + for (i =3D walk->root_level; i < level; i++) + printk("%d.", walk->off[i]); + + printk("%d =3D 0x%lx\n", walk->off[level], pte.bits); +} + +/* Prints each mapping in the form IA:0xIA -> OFN:0xOFN XG,M,K */ +static void dump_mapping(int level, lpae_t pte, walk_info_t *walk) +{ + unsigned long va; + unsigned long ofn =3D pte.walk.base; + const char *size[4] =3D {"??", "1G", "2M", "4K"}; + + ASSERT(level >=3D 1); + ASSERT(level <=3D 3); + + va =3D walk_to_va(level, walk); + + /* ofn stands for output frame number.. I just made it up. */ + printk("0x%lx -> 0x%lx %s\n", va, ofn, size[level]); +} + +/* Recursive walk function */ +static void walk_table(mfn_t mfn, int level, walk_info_t *walk, int flags) +{ + lpae_t *table; + + #define i (walk->off[level]) + + BUG_ON(level > 3); + + table =3D map_domain_page(mfn); + for ( i =3D 0; i < XEN_PT_LPAE_ENTRIES; i++ ) + { + lpae_t pte =3D table[i]; + if ( !lpae_is_valid(pte) ) + continue; + + /* Skip recursive mapping */ + if ( level =3D=3D 0 && i =3D=3D RECURSIVE_IDX ) + continue; + + if ( flags & WALK_DUMP_ENTRIES ) + dump_entry(level, pte, walk); + + if ( lpae_is_mapping(pte, level) ) + { + /* Do mapping related things */ + if ( flags & WALK_DUMP_MAPPINGS ) + dump_mapping(level, pte, walk); + if ( flags & WALK_HIDE_GUEST_MAPPING ) + /* Destroy all of Xen's mappings to the physical frames co= vered by this entry */ + destroy_directmap_mapping(pte.walk.base, 1 << XEN_PT_LEVEL= _ORDER(level)); + } + else if ( lpae_is_table(pte, level) ) + { + /* else, pte is a table: recurse! */ + walk_table(lpae_get_mfn(pte), level + 1, walk, flags); + + /* Note that the entry is a normal entry in xen's page tables = */ + if ( flags & WALK_HIDE_GUEST_TABLE ) + /* + * This call will look up the table pointed to by this ent= ry in the directmap + * and remove it in the typical way + * This leaves the table intact, but removes the directmap= mapping to it, hiding it from xen + */ + destroy_directmap_mapping(pte.walk.base, 1); + if ( flags & WALK_SPLIT_DIRECTMAP_TABLE ) + /* + * This call will look up the table pointed to by this ent= ry in the directmap + * and make sure that it has it's own l3 entry, splitting = superpages if needed + */ + split_directmap_mapping(pte.walk.base, 1); + if ( flags & WALK_HIDE_DIRECTMAP_TABLE ) + /* + * This call will look up the table pointed to by this ent= ry in the directmap + * and (now that it has it's own l3 entry) overwrite that = entry with 0's + * This leaves the table intact, but removes the directmap= mapping to it, hiding it from xen + */ + destroy_directmap_table(pte.walk.base); + } + /* else, invalid pte, level =3D=3D 3, vaild =3D=3D true, table =3D= false */ + } + unmap_domain_page(table); + + #undef i +} + +void do_walk_tables(paddr_t ttbr, int root_level, int nr_root_tables, int = flags) +{ + int i; + mfn_t root =3D maddr_to_mfn(ttbr & PADDR_MASK); + walk_info_t walk =3D { + .off =3D {0}, + .root_level =3D root_level, + }; + + BUG_ON( !mfn_x(root) || !mfn_valid(root) ); + + for ( i =3D 0; i < nr_root_tables; i++, root =3D mfn_add(root, 1) ) { + walk.root_table_idx =3D i; + walk_table(root, root_level, &walk, flags); + + /* Our walk doesn't consider the root table, so do that here */ + if ( flags & WALK_SPLIT_DIRECTMAP_TABLE ) + split_directmap_mapping(mfn_x(root), 1); + if ( flags & WALK_HIDE_GUEST_TABLE ) + destroy_directmap_mapping(mfn_x(root), 1); + if ( flags & WALK_HIDE_DIRECTMAP_TABLE ) + destroy_directmap_table(mfn_x(root)); + } +} + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index 91b9c2b..64e9efd 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -21,11 +21,13 @@ #include #include #include +#include =20 #include =20 #include #include +#include =20 #include =20 @@ -1164,7 +1166,8 @@ static int xen_pt_update(unsigned long virt, * * XXX: Add a check. */ - const mfn_t root =3D virt_to_mfn(THIS_CPU_PGTABLE); + /* TODO: does this change have a negative performance impact? */ + const mfn_t root =3D maddr_to_mfn(READ_SYSREG64(TTBR0_EL2)); =20 /* * The hardware was configured to forbid mapping both writeable and @@ -1273,6 +1276,199 @@ int modify_xen_mappings(unsigned long s, unsigned l= ong e, unsigned int flags) return xen_pt_update(s, INVALID_MFN, (e - s) >> PAGE_SHIFT, flags); } =20 +static void insert_recursive_mapping(void) +{ + uint64_t ttbr =3D READ_SYSREG64(TTBR0_EL2); + const mfn_t root_mfn =3D maddr_to_mfn(ttbr & PADDR_MASK); + lpae_t *pgtable =3D map_domain_page(root_mfn); + + lpae_t pte =3D mfn_to_xen_entry(root_mfn, MT_NORMAL); + pte.pt.table =3D 1; + + spin_lock(&xen_pt_lock); + + write_pte(&pgtable[RECURSIVE_IDX], pte); + clean_dcache(pgtable[RECURSIVE_IDX]); + + unmap_domain_page(pgtable); + spin_unlock(&xen_pt_lock); +} + +/* + * Converts va to a table pointer through the recursive mapping + * Only valid for the current address space obviously + */ +static lpae_t *va_to_table(int level, unsigned long va) +{ + /* Shift everything by 9 for each walk we skip */ + /* Last off shifted out becomes becomes offset into page */ + for ( ;level <=3D 3; level++ ) { + va >>=3D XEN_PT_LPAE_SHIFT; + va |=3D RECURSIVE_VA; + } + + /* Mask out any offset, in case caller is asking about a misalligned v= a */ + va &=3D ~0x7; + return (lpae_t *)va; +} + +/* + * Zero out the table at level when walking to virt + * Do this through the recursive mapping, in case we have already + * removed part of the directmap and can't walk to that entry + */ +static void clear_pte_directly(int level, void *virt) +{ + unsigned long va =3D (unsigned long)virt; + lpae_t empty =3D {.pt =3D {0x0}}; + lpae_t *table; + + spin_lock(&xen_pt_lock); + + /* We're assuming we can safely remove an entry at `level` */ + /* This depends on va not living in a superpage */ + BUG_ON(level > 1 && !va_to_table(1, va)->pt.table); + BUG_ON(level > 2 && !va_to_table(2, va)->pt.table); + + table =3D va_to_table(level, va); + write_pte(table, empty); + clean_dcache(*table); + flush_xen_tlb_range_va((vaddr_t)table, sizeof(*table)); + + spin_unlock(&xen_pt_lock); +} + +static void remove_recursive_mapping(void) +{ + clear_pte_directly(0, (void *)RECURSIVE_VA); +} + +static int modify_virt_mapping(void *virt, int nr_pages, int flags) +{ + unsigned long va =3D (unsigned long)virt; + return modify_xen_mappings(va, va + (PAGE_SIZE * nr_pages), flags); +} + +static int destroy_virt_mapping(void *virt, int nr_pages) +{ + return modify_virt_mapping(virt, nr_pages, 0); +} + +static int modify_directmap_mapping(unsigned long mfn, unsigned long nr_mf= ns, int flags) +{ + if ( mfn & pfn_hole_mask ) + { + printk("** Skipping mfn 0x%lx because it lives in the pfn hole **\= n", mfn); + return 0; + } + + return modify_virt_mapping(__mfn_to_virt(mfn), nr_mfns, flags); +} + +int split_directmap_mapping(unsigned long mfn, unsigned long nr_mfns) +{ + return modify_directmap_mapping(mfn, nr_mfns, PAGE_HYPERVISOR); +} + +int destroy_directmap_mapping(unsigned long mfn, unsigned long nr_mfns) +{ + return modify_directmap_mapping(mfn, nr_mfns, 0); +} + +void destroy_directmap_table(unsigned long mfn) +{ + BUG_ON(mfn & pfn_hole_mask); + clear_pte_directly(3, __mfn_to_virt(mfn)); +} + +static void unmap_xen_root_tables(void) +{ + destroy_virt_mapping(xen_xenmap, 1); + destroy_virt_mapping(xen_fixmap, 1); + destroy_virt_mapping(xen_second, 1); +#if defined(CONFIG_ARM_64) + destroy_virt_mapping(xen_first, 1); + destroy_virt_mapping(xen_pgtable, 1); +#endif +} + +static void walk_hyp_tables(int flags) +{ + uint64_t httbr =3D READ_SYSREG64(TTBR0_EL2); + do_walk_tables(httbr, HYP_PT_ROOT_LEVEL, 1, flags); +} + +static void walk_guest_tables(struct domain *d, int flags) +{ + uint64_t vttbr =3D d->arch.p2m.vttbr; + do_walk_tables(vttbr, P2M_ROOT_LEVEL, 1<arch.p2m.vttbr; + uint64_t httbr =3D READ_SYSREG64(TTBR0_EL2); + + printk("Dump domain info...\n"); + printk("guest mfn =3D 0x%lx\n", paddr_to_pfn(vttbr & PADDR_MASK)); + printk("xen mfn =3D 0x%lx\n", paddr_to_pfn(httbr & PADDR_MASK)); +} + +void vmf_dump_xen_tables() +{ + walk_hyp_tables(WALK_DUMP_MAPPINGS | WALK_DUMP_ENTRIES); +} + +void vmf_dump_domain_tables(struct domain *d) +{ + walk_guest_tables(d, WALK_DUMP_MAPPINGS | WALK_DUMP_ENTRIES); +} + /* Release all __init and __initdata ranges to be reused */ void free_init_memory(void) { diff --git a/xen/common/Kconfig b/xen/common/Kconfig index 3bf92b8..c087371 100644 --- a/xen/common/Kconfig +++ b/xen/common/Kconfig @@ -94,6 +94,8 @@ config STATIC_MEMORY =20 config VMF bool "Virtual Memory Fuse Support" + depends on ARM_64 + default y =20 menu "Speculative hardening" =20 --=20 2.7.4