From patchwork Mon Jan 27 13:23:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Alexandru Stefan ISAILA X-Patchwork-Id: 11352627 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 407B8924 for ; Mon, 27 Jan 2020 13:24:42 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1175A20702 for ; Mon, 27 Jan 2020 13:24:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=bitdefender.onmicrosoft.com header.i=@bitdefender.onmicrosoft.com header.b="ryeGJqMH" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1175A20702 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=bitdefender.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iw4MY-0003HL-H6; Mon, 27 Jan 2020 13:23:34 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iw4MX-0003GD-Ay for xen-devel@lists.xenproject.org; Mon, 27 Jan 2020 13:23:33 +0000 X-Inumbo-ID: 36079714-4108-11ea-854d-12813bfff9fa Received: from EUR04-HE1-obe.outbound.protection.outlook.com (unknown [40.107.7.93]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 36079714-4108-11ea-854d-12813bfff9fa; Mon, 27 Jan 2020 13:23:31 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TygHtVXnRBE5ILNe9gYswGlJ7cKjm4mkcdtL758haXB1LHt5CEhnThsGMEi4yTqHrbzRhrP7XXdr6skTPV1Py0PDa9nBOnkkPC4s34BRZnly9YI5olGdEzUvn4fPlVEuIzZHODZVap11oIU9zc2Nl5xLxm7HivVZ0KuU8tDo458A0W2m9taYiAZ0Fme15s1t2oT8jutolh4DCkU417uNGBzgI1TrhtwSqXekYCfOyLG6dJawHL2gxlmmC5UX+AC4FYjqITLXLveCCzjNKMlmWMka9yukULPLxrZV7anAuhIUow54OkBQo3z44G0NOnC/81WyTPf6NuYRuLnTOjkN5Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=LPcRWWBBZpB1Km32umONy5IVPuktAYkd44gOG3uQyxc=; b=Jo5AuwgVzj0vf66sC6CovwlBOwPvwHczSsfFvCBhDt51yutMOxl9SpdZV4fAWF7Mo6aTt+CPiLUg6I3s6BJjHk4Z8wC0ryK5Bdqko/AUzbXZFt/ZrIbdyycCQobB1+dvHShqcFvVF+X1QgY88PK1gEkptOTSOjnkULh+vQO/ZM+C8bBoDkyf4gaDjIUfBN7PA/IUDOIm07/U77WfMqA5f1XBu9lc0GrnRp1IFHCQaZfROZoeXez603Pp3S9FFywmiVmLhWXnumWyH+H/0h4s0D0fahRUnxh9bAX8baX9Zm4qGzEpW/bzHCiW+Qc6xgbJMbBPiBqfIFMKQTx4ezFW5w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=bitdefender.com; dmarc=pass action=none header.from=bitdefender.com; dkim=pass header.d=bitdefender.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bitdefender.onmicrosoft.com; s=selector2-bitdefender-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=LPcRWWBBZpB1Km32umONy5IVPuktAYkd44gOG3uQyxc=; b=ryeGJqMHx40saEtkFJEJ5pLZPulnp0Bezt8bN76Qx8uXAdwLFPgbjlayjafMTLIPSA9prE8bcQJg3DWxuoqVd7j8nYb5kGJOMARqZsg0QYUJTZCMkNxp57zCcR+Kwr2Vn3FDdLyCioT+cOQVZx4mua4gNOx189P8BdUZuwjOJio= Received: from DB6PR02MB2999.eurprd02.prod.outlook.com (10.170.219.144) by DB6PR02MB3254.eurprd02.prod.outlook.com (10.170.220.160) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2665.24; Mon, 27 Jan 2020 13:23:29 +0000 Received: from DB6PR02MB2999.eurprd02.prod.outlook.com ([fe80::f1c2:7dd1:1131:1c1d]) by DB6PR02MB2999.eurprd02.prod.outlook.com ([fe80::f1c2:7dd1:1131:1c1d%7]) with mapi id 15.20.2665.025; Mon, 27 Jan 2020 13:23:29 +0000 Received: from aisaila-Latitude-E5570.dsd.bitdefender.biz (91.199.104.6) by ZR0P278CA0037.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:1d::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2665.20 via Frontend Transport; Mon, 27 Jan 2020 13:23:27 +0000 From: Alexandru Stefan ISAILA To: "xen-devel@lists.xenproject.org" Thread-Topic: [PATCH V1] x86/altp2m: Hypercall to set altp2m view view visibility Thread-Index: AQHV1RT2AjuEIok8ykyd6z7MdpITdw== Date: Mon, 27 Jan 2020 13:23:29 +0000 Message-ID: <20200127132252.4934-1-aisaila@bitdefender.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: ZR0P278CA0037.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:1d::6) To DB6PR02MB2999.eurprd02.prod.outlook.com (2603:10a6:6:17::16) authentication-results: spf=none (sender IP is ) smtp.mailfrom=aisaila@bitdefender.com; x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.17.1 x-originating-ip: [91.199.104.6] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: ab53b58a-7383-4797-b5ff-08d7a32c1901 x-ms-traffictypediagnostic: DB6PR02MB3254:|DB6PR02MB3254: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:2657; x-forefront-prvs: 02951C14DC x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(376002)(346002)(366004)(136003)(396003)(39850400004)(199004)(189003)(36756003)(6486002)(54906003)(5660300002)(956004)(7416002)(86362001)(2616005)(8936002)(81166006)(81156014)(8676002)(1076003)(16526019)(186003)(478600001)(66556008)(66446008)(64756008)(66476007)(6512007)(66946007)(26005)(52116002)(6916009)(6506007)(4326008)(316002)(2906002)(71200400001); DIR:OUT; SFP:1102; SCL:1; SRVR:DB6PR02MB3254; H:DB6PR02MB2999.eurprd02.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; received-spf: None (protection.outlook.com: bitdefender.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: /bgSz3HlcDjUVOtDxoX1Xp7AJtVuJJlWYu1BsfMrHCyIHGIaMsNjdX/ika1D9sxDISgOgF8q6OZMVaHNDd2nGrozfW9Ty+hOW32DTz4X8Lvu0gUTIZecSTtLGkWZzpDNhza1XCEV0emLg0Ojtm5wGQ7U2N/R1kkMk8UGUX12JOAeaqaPBp1FtvrjziqNsF1eXZ4qyNEbbHbr4rO78xDNv5Uon0oJennVm3us7XJkKKDFFFI1nRsjKo3Gqpq7pVSqyUgfslWnDtqJMlAuLWo+t8+bh166z3Ja9flsVw5SMmLncFfF31y8yZxwNndT9AKag1j+3VgkmiqEHbo2N/O7L0NVzL4IKLuRVXrDoNGirhz6u7mmlqdwf2vRrhjko9CkKeXQooywiHONmfm6Tvnqhhomh3TEGenwgwmI6D78tyZieNN6WXu+TvxySKcEDlHj x-ms-exchange-antispam-messagedata: N/l2ljgK62+H3B4NIYVTNV4VUD2KFpmrzWdAsSHtQaTIFRe98oOBLrTfO6i6LMwhzrUjlYq2aSuyTZKTnmxfRz/XBZyKxz22E9q3FyLrO06tt/vAZfyiZf+wla67/anfxUlf7fqG7rfJkyPBPZeB5w== Content-ID: <5C8C4FF807E2C744A0356122B918B1A4@eurprd02.prod.outlook.com> MIME-Version: 1.0 X-OriginatorOrg: bitdefender.com X-MS-Exchange-CrossTenant-Network-Message-Id: ab53b58a-7383-4797-b5ff-08d7a32c1901 X-MS-Exchange-CrossTenant-originalarrivaltime: 27 Jan 2020 13:23:29.2633 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 487baf29-f1da-469a-9221-243f830c36f3 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: K0jBh+W32cmhnEjYDq2VOL3jujJ+rN1YBtsxW3TmKVHzvarq299ZeOIvec325h+Fxy/L0ITEG80Ca6pxnB0Fji2eKonHWfleKTXn+B5RGNs= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB6PR02MB3254 Subject: [Xen-devel] [PATCH V1] x86/altp2m: Hypercall to set altp2m view view visibility X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Kevin Tian , Stefano Stabellini , Julien Grall , Jun Nakajima , Wei Liu , Konrad Rzeszutek Wilk , George Dunlap , Andrew Cooper , Ian Jackson , Alexandru Stefan ISAILA , =?utf-8?q?Roger_Pau_Monn?= =?utf-8?q?=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" At this moment a guest can call vmfunc to change the altp2m view. This should be limited in order to avoid any unwanted view switch. The new xc_altp2m_set_visibility() solves this by making views invisible to vmfunc. This is done by having a separate arch.altp2m_working_eptp that is populated and made invalid in the same places as altp2m_eptp. This is written to EPTP_LIST_ADDR. The views are made in/visible by marking them with INVALID_MFN or copying them back from altp2m_eptp. To have consistency the visibility also applies to p2m_switch_domain_altp2m_by_id(). Signed-off-by: Alexandru Isaila --- CC: Ian Jackson CC: Wei Liu CC: Andrew Cooper CC: George Dunlap CC: Jan Beulich CC: Julien Grall CC: Konrad Rzeszutek Wilk CC: Stefano Stabellini CC: "Roger Pau Monné" CC: Jun Nakajima CC: Kevin Tian CC: George Dunlap --- tools/libxc/include/xenctrl.h | 2 ++ tools/libxc/xc_altp2m.c | 24 ++++++++++++++++++++++++ xen/arch/x86/hvm/hvm.c | 25 +++++++++++++++++++++++++ xen/arch/x86/hvm/vmx/vmx.c | 2 +- xen/arch/x86/mm/hap/hap.c | 15 +++++++++++++++ xen/arch/x86/mm/p2m-ept.c | 1 + xen/arch/x86/mm/p2m.c | 5 ++++- xen/include/asm-x86/domain.h | 1 + xen/include/public/hvm/hvm_op.h | 10 ++++++++++ 9 files changed, 83 insertions(+), 2 deletions(-) diff --git a/tools/libxc/include/xenctrl.h b/tools/libxc/include/xenctrl.h index cc4eb1e3d3..dbea7861e7 100644 --- a/tools/libxc/include/xenctrl.h +++ b/tools/libxc/include/xenctrl.h @@ -1943,6 +1943,8 @@ int xc_altp2m_change_gfn(xc_interface *handle, uint32_t domid, xen_pfn_t new_gfn); int xc_altp2m_get_vcpu_p2m_idx(xc_interface *handle, uint32_t domid, uint32_t vcpuid, uint16_t *p2midx); +int xc_altp2m_set_visibility(xc_interface *handle, uint32_t domid, + uint16_t view_id, bool visible); /** * Mem paging operations. diff --git a/tools/libxc/xc_altp2m.c b/tools/libxc/xc_altp2m.c index 46fb725806..6987c9541f 100644 --- a/tools/libxc/xc_altp2m.c +++ b/tools/libxc/xc_altp2m.c @@ -410,3 +410,27 @@ int xc_altp2m_get_vcpu_p2m_idx(xc_interface *handle, uint32_t domid, xc_hypercall_buffer_free(handle, arg); return rc; } + +int xc_altp2m_set_visibility(xc_interface *handle, uint32_t domid, + uint16_t view_id, bool visible) +{ + int rc; + + DECLARE_HYPERCALL_BUFFER(xen_hvm_altp2m_op_t, arg); + + arg = xc_hypercall_buffer_alloc(handle, arg, sizeof(*arg)); + if ( arg == NULL ) + return -1; + + arg->version = HVMOP_ALTP2M_INTERFACE_VERSION; + arg->cmd = HVMOP_altp2m_set_visibility; + arg->domain = domid; + arg->u.set_visibility.altp2m_idx = view_id; + arg->u.set_visibility.visible = visible; + + rc = xencall2(handle->xcall, __HYPERVISOR_hvm_op, HVMOP_altp2m, + HYPERCALL_BUFFER_AS_ARG(arg)); + + xc_hypercall_buffer_free(handle, arg); + return rc; +} diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c index 0b93609a82..a41e9b6356 100644 --- a/xen/arch/x86/hvm/hvm.c +++ b/xen/arch/x86/hvm/hvm.c @@ -4537,6 +4537,7 @@ static int do_altp2m_op( case HVMOP_altp2m_get_mem_access: case HVMOP_altp2m_change_gfn: case HVMOP_altp2m_get_p2m_idx: + case HVMOP_altp2m_set_visibility: break; default: @@ -4814,6 +4815,30 @@ static int do_altp2m_op( break; } + case HVMOP_altp2m_set_visibility: + { + uint16_t altp2m_idx = a.u.set_visibility.altp2m_idx; + + if ( a.u.set_visibility.pad || a.u.set_visibility.pad2 ) + rc = -EINVAL; + else + { + if ( !altp2m_active(d) || !hap_enabled(d) ) + { + rc = -EOPNOTSUPP; + break; + } + + if ( a.u.set_visibility.visible ) + d->arch.altp2m_working_eptp[altp2m_idx] = + d->arch.altp2m_eptp[altp2m_idx]; + else + d->arch.altp2m_working_eptp[altp2m_idx] = + mfn_x(INVALID_MFN); + } + break; + } + default: ASSERT_UNREACHABLE(); } diff --git a/xen/arch/x86/hvm/vmx/vmx.c b/xen/arch/x86/hvm/vmx/vmx.c index b262d38a7c..65fe75383f 100644 --- a/xen/arch/x86/hvm/vmx/vmx.c +++ b/xen/arch/x86/hvm/vmx/vmx.c @@ -2139,7 +2139,7 @@ static void vmx_vcpu_update_vmfunc_ve(struct vcpu *v) { v->arch.hvm.vmx.secondary_exec_control |= mask; __vmwrite(VM_FUNCTION_CONTROL, VMX_VMFUNC_EPTP_SWITCHING); - __vmwrite(EPTP_LIST_ADDR, virt_to_maddr(d->arch.altp2m_eptp)); + __vmwrite(EPTP_LIST_ADDR, virt_to_maddr(d->arch.altp2m_working_eptp)); if ( cpu_has_vmx_virt_exceptions ) { diff --git a/xen/arch/x86/mm/hap/hap.c b/xen/arch/x86/mm/hap/hap.c index 3d93f3451c..5969ec8922 100644 --- a/xen/arch/x86/mm/hap/hap.c +++ b/xen/arch/x86/mm/hap/hap.c @@ -488,8 +488,17 @@ int hap_enable(struct domain *d, u32 mode) goto out; } + if ( (d->arch.altp2m_working_eptp = alloc_xenheap_page()) == NULL ) + { + rv = -ENOMEM; + goto out; + } + for ( i = 0; i < MAX_EPTP; i++ ) + { d->arch.altp2m_eptp[i] = mfn_x(INVALID_MFN); + d->arch.altp2m_working_eptp[i] = mfn_x(INVALID_MFN); + } for ( i = 0; i < MAX_ALTP2M; i++ ) { @@ -523,6 +532,12 @@ void hap_final_teardown(struct domain *d) d->arch.altp2m_eptp = NULL; } + if ( d->arch.altp2m_working_eptp ) + { + free_xenheap_page(d->arch.altp2m_working_eptp); + d->arch.altp2m_working_eptp = NULL; + } + for ( i = 0; i < MAX_ALTP2M; i++ ) p2m_teardown(d->arch.altp2m_p2m[i]); } diff --git a/xen/arch/x86/mm/p2m-ept.c b/xen/arch/x86/mm/p2m-ept.c index 05a5526e08..0e740ed58e 100644 --- a/xen/arch/x86/mm/p2m-ept.c +++ b/xen/arch/x86/mm/p2m-ept.c @@ -1361,6 +1361,7 @@ void p2m_init_altp2m_ept(struct domain *d, unsigned int i) ept = &p2m->ept; ept->mfn = pagetable_get_pfn(p2m_get_pagetable(p2m)); d->arch.altp2m_eptp[array_index_nospec(i, MAX_EPTP)] = ept->eptp; + d->arch.altp2m_working_eptp[array_index_nospec(i, MAX_EPTP)] = ept->eptp; } unsigned int p2m_find_altp2m_by_eptp(struct domain *d, uint64_t eptp) diff --git a/xen/arch/x86/mm/p2m.c b/xen/arch/x86/mm/p2m.c index 49cc138362..008357b761 100644 --- a/xen/arch/x86/mm/p2m.c +++ b/xen/arch/x86/mm/p2m.c @@ -2531,6 +2531,7 @@ void p2m_flush_altp2m(struct domain *d) { p2m_reset_altp2m(d, i, ALTP2M_DEACTIVATE); d->arch.altp2m_eptp[i] = mfn_x(INVALID_MFN); + d->arch.altp2m_working_eptp[i] = mfn_x(INVALID_MFN); } altp2m_list_unlock(d); @@ -2651,6 +2652,8 @@ int p2m_destroy_altp2m_by_id(struct domain *d, unsigned int idx) p2m_reset_altp2m(d, idx, ALTP2M_DEACTIVATE); d->arch.altp2m_eptp[array_index_nospec(idx, MAX_EPTP)] = mfn_x(INVALID_MFN); + d->arch.altp2m_working_eptp[array_index_nospec(idx, MAX_EPTP)] = + mfn_x(INVALID_MFN); rc = 0; } } @@ -2677,7 +2680,7 @@ int p2m_switch_domain_altp2m_by_id(struct domain *d, unsigned int idx) rc = -EINVAL; altp2m_list_lock(d); - if ( d->arch.altp2m_eptp[idx] != mfn_x(INVALID_MFN) ) + if ( d->arch.altp2m_working_eptp[idx] != mfn_x(INVALID_MFN) ) { for_each_vcpu( d, v ) if ( idx != vcpu_altp2m(v).p2midx ) diff --git a/xen/include/asm-x86/domain.h b/xen/include/asm-x86/domain.h index a3ae5d9a20..9d36f490e4 100644 --- a/xen/include/asm-x86/domain.h +++ b/xen/include/asm-x86/domain.h @@ -326,6 +326,7 @@ struct arch_domain struct p2m_domain *altp2m_p2m[MAX_ALTP2M]; mm_lock_t altp2m_list_lock; uint64_t *altp2m_eptp; + uint64_t *altp2m_working_eptp; #endif /* NB. protected by d->event_lock and by irq_desc[irq].lock */ diff --git a/xen/include/public/hvm/hvm_op.h b/xen/include/public/hvm/hvm_op.h index 610e020a62..17a29615ed 100644 --- a/xen/include/public/hvm/hvm_op.h +++ b/xen/include/public/hvm/hvm_op.h @@ -317,6 +317,13 @@ struct xen_hvm_altp2m_get_vcpu_p2m_idx { uint16_t altp2m_idx; }; +struct xen_hvm_altp2m_set_visibility { + uint16_t altp2m_idx; + uint8_t visible; + uint8_t pad; + uint32_t pad2; +}; + struct xen_hvm_altp2m_op { uint32_t version; /* HVMOP_ALTP2M_INTERFACE_VERSION */ uint32_t cmd; @@ -349,6 +356,8 @@ struct xen_hvm_altp2m_op { #define HVMOP_altp2m_get_p2m_idx 14 /* Set the "Supress #VE" bit for a range of pages */ #define HVMOP_altp2m_set_suppress_ve_multi 15 +/* Set visibility for a given altp2m view */ +#define HVMOP_altp2m_set_visibility 16 domid_t domain; uint16_t pad1; uint32_t pad2; @@ -366,6 +375,7 @@ struct xen_hvm_altp2m_op { struct xen_hvm_altp2m_suppress_ve_multi suppress_ve_multi; struct xen_hvm_altp2m_vcpu_disable_notify disable_notify; struct xen_hvm_altp2m_get_vcpu_p2m_idx get_vcpu_p2m_idx; + struct xen_hvm_altp2m_set_visibility set_visibility; uint8_t pad[64]; } u; };