From patchwork Thu Nov 21 15:02:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Alexandru Stefan ISAILA X-Patchwork-Id: 11256371 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 329C9138C for ; Thu, 21 Nov 2019 15:03: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 02707206EC for ; Thu, 21 Nov 2019 15:03:41 +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="k8th5x5G" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 02707206EC 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 1iXnyQ-0001ux-GB; Thu, 21 Nov 2019 15:02:22 +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 1iXnyP-0001us-Cq for xen-devel@lists.xenproject.org; Thu, 21 Nov 2019 15:02:21 +0000 X-Inumbo-ID: e994f5ce-0c6f-11ea-a339-12813bfff9fa Received: from EUR02-VE1-obe.outbound.protection.outlook.com (unknown [40.107.2.94]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id e994f5ce-0c6f-11ea-a339-12813bfff9fa; Thu, 21 Nov 2019 15:02:19 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=IQdq47uHJCuzoB/2dTBcf79NOaJuUcEggRqlk1pQX0njicl4uB2HRHmpCv03/JBY9c5m6FSZ8jbjf9zYGGROgpHeWjosLFMvhT8nmVuSVvQNbiConWnZo2fBjE868hNT0FGuedwSnjxfXkgVUp9TEVfxFf0/FjaSY0Tm65kw3R+lanikwfk7d9W41aW9E9yDFO4Ui1ZUu7aBKxPH/e2SLdxRAR00I2eAifUwS8Oohs6JSiAFMMPk4cjexs6SSepY+CudR5pjE9OFhN+6oYsuv3u16N4P+kQbHVAsZqKkF5K97UnAzai8mcCTfmT6faslO8WLXrtdaZWA3Yh8Xqoqmw== 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=59z+eG03zjvMgRHcpv1j4y3oWgelTvTr5JuPmv1WRcs=; b=HE9Exmtgv2zatxf08hg/EO7rqHMsuUR+j0Uykjld9ywpFzTP8NC6KwDHGn5WHVSDGwqUCm45TP2p9Ds+fOj9KM+KHUd0uOy/OcrlnhhZoTybzYt+HyKLmhBh+SG6dhrsSDRHRzKrWkgYZv+uVvnLT8dBwBqj65zwOMwmx0FOW3ylrFKeCK2Je8tPJmH0b8AOg45wwWqtjnxzejnrMPvBhB3hd4aGbir94nrd5ohWXDKlwKpM4cM7IFjORPOf0T8BjCZQGNS/IgUsr3bAhr2Np1MC2ux8EJm+ukFVuxFuYQZ8/dqMrkRRwS6Yq+GQ/6DUBfp6/1tQKp5zg0Vk7jzi4Q== 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=59z+eG03zjvMgRHcpv1j4y3oWgelTvTr5JuPmv1WRcs=; b=k8th5x5GJxlG6lkCQVIz7if1PPjxKblLXMHCXNojCdqTf0dEZa8T6anYVUTDiP2fD4bSFdfppDB3uuZTEAIpaZeSZdjZdUeNuh7dnonJtoV0FJikeeVnj9NcXv743UrGfqbEqKojkW6EuaHXcEU1FsWE4EQHBqca1QxpE6U9K00= Received: from AM0PR02MB5553.eurprd02.prod.outlook.com (10.255.30.78) by AM0PR02MB5396.eurprd02.prod.outlook.com (10.255.31.207) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2474.17; Thu, 21 Nov 2019 15:02:17 +0000 Received: from AM0PR02MB5553.eurprd02.prod.outlook.com ([fe80::8cec:7638:734c:89d]) by AM0PR02MB5553.eurprd02.prod.outlook.com ([fe80::8cec:7638:734c:89d%4]) with mapi id 15.20.2474.019; Thu, 21 Nov 2019 15:02:17 +0000 From: Alexandru Stefan ISAILA To: "xen-devel@lists.xenproject.org" Thread-Topic: [PATCH V3 1/2] x86/altp2m: Add hypercall to set a range of sve bits Thread-Index: AQHVoHyqPG/1qImaik2u7wxoJD4v5w== Date: Thu, 21 Nov 2019 15:02:17 +0000 Message-ID: <20191121150124.15865-1-aisaila@bitdefender.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: FR2P281CA0005.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:a::15) To AM0PR02MB5553.eurprd02.prod.outlook.com (2603:10a6:208:160::14) 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: 9537b848-e5ed-49ff-1a58-08d76e93cce0 x-ms-traffictypediagnostic: AM0PR02MB5396:|AM0PR02MB5396:|AM0PR02MB5396: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:612; x-forefront-prvs: 0228DDDDD7 x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(366004)(396003)(39860400002)(376002)(346002)(136003)(199004)(189003)(2906002)(5640700003)(107886003)(6512007)(4326008)(6116002)(25786009)(36756003)(3846002)(7736002)(305945005)(7416002)(66066001)(6436002)(6486002)(2351001)(86362001)(6916009)(2501003)(26005)(186003)(478600001)(316002)(256004)(14444005)(8936002)(50226002)(66446008)(2616005)(8676002)(81156014)(1076003)(81166006)(66476007)(5660300002)(52116002)(14454004)(99286004)(386003)(71200400001)(66946007)(6506007)(71190400001)(102836004)(64756008)(66556008)(54906003); DIR:OUT; SFP:1102; SCL:1; SRVR:AM0PR02MB5396; H:AM0PR02MB5553.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: NoCK5/jUdn8LaiCtRQquFShmyD9+1cSXdXQFpWTEQs4zSTbCaxwEmuWbMoLu7ovETqJ+mH30FnJ3sFsRVTMRrcOdxB3wrQAP5cx+yjF/16dIEAWNVSSaPuBUB51kmUzylxUf/1dglnI3PqS6/ffrRCjwYgzNX/IEiu0IzmwIJFgvKu30c3YDIo96zjHAnksV4O8MkwGF+Avg1XZ7LXP20QpMkMmMkWgAKnVxYk741rJmPB4lvlMezQxVt5qfFzye2WNAENxxMFo6Bqd6DG2ko/Gf0dNiVDSn53+dfdG+piuayzCQzkC6sJ4G3n2xN5enrBIKP3gId26Ns6zsaaGT7sUbSQjVpBU41T3dljedltFcN+o0ESq1pCOufoPrHeqSEIqf4AfNdS9VnscthLR1Tx41ZdwsHBmf6TIF3vRQpMirDESGvHEjJaUgqHMRtCQZ Content-ID: MIME-Version: 1.0 X-OriginatorOrg: bitdefender.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9537b848-e5ed-49ff-1a58-08d76e93cce0 X-MS-Exchange-CrossTenant-originalarrivaltime: 21 Nov 2019 15:02:17.5039 (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: 6oLZHOwxXDLTXYxjEeo8svFRm3F+gY84bKtCmyYRot9CyxiQzPqhPU+eCYZatbVm5yTsxwaM+QrF7KRwmhs1TcG5/g2uBCvijPIijRUwLHI= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR02MB5396 Subject: [Xen-devel] [PATCH V3 1/2] x86/altp2m: Add hypercall to set a range of sve bits 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: Petre Ovidiu PIRCALABU , Stefano Stabellini , Julien Grall , Razvan COJOCARU , Wei Liu , Konrad Rzeszutek Wilk , George Dunlap , Andrew Cooper , Ian Jackson , Tamas K Lengyel , Jan Beulich , 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" By default the sve bits are not set. This patch adds a new hypercall, xc_altp2m_set_supress_ve_multi(), to set a range of sve bits. The core function, p2m_set_suppress_ve_multi(), does not brake in case of a error and it is doing a best effort for setting the bits in the given range. A check for continuation is made in order to have preemption on big ranges. 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: George Dunlap CC: Razvan Cojocaru CC: Tamas K Lengyel CC: Petre Pircalabu --- Changes since V2: - Add a new structure "xen_hvm_altp2m_suppress_ve_multi" - Copy the gfn of the first error to the caller - Revert xen_hvm_altp2m_suppress_ve - Add a mechanism to save the first error. --- tools/libxc/include/xenctrl.h | 4 +++ tools/libxc/xc_altp2m.c | 30 +++++++++++++++++ xen/arch/x86/hvm/hvm.c | 13 +++++++ xen/arch/x86/mm/p2m.c | 60 +++++++++++++++++++++++++++++++++ xen/include/public/hvm/hvm_op.h | 14 ++++++++ xen/include/xen/mem_access.h | 3 ++ 6 files changed, 124 insertions(+) diff --git a/tools/libxc/include/xenctrl.h b/tools/libxc/include/xenctrl.h index f4431687b3..356533e391 100644 --- a/tools/libxc/include/xenctrl.h +++ b/tools/libxc/include/xenctrl.h @@ -1923,6 +1923,10 @@ int xc_altp2m_switch_to_view(xc_interface *handle, uint32_t domid, uint16_t view_id); int xc_altp2m_set_suppress_ve(xc_interface *handle, uint32_t domid, uint16_t view_id, xen_pfn_t gfn, bool sve); +int xc_altp2m_set_supress_ve_multi(xc_interface *handle, uint32_t domid, + uint16_t view_id, xen_pfn_t first_gfn, + xen_pfn_t last_gfn, bool sve, + xen_pfn_t *error); int xc_altp2m_get_suppress_ve(xc_interface *handle, uint32_t domid, uint16_t view_id, xen_pfn_t gfn, bool *sve); int xc_altp2m_set_mem_access(xc_interface *handle, uint32_t domid, diff --git a/tools/libxc/xc_altp2m.c b/tools/libxc/xc_altp2m.c index 09dad0355e..03bd651a61 100644 --- a/tools/libxc/xc_altp2m.c +++ b/tools/libxc/xc_altp2m.c @@ -234,6 +234,36 @@ int xc_altp2m_set_suppress_ve(xc_interface *handle, uint32_t domid, return rc; } +int xc_altp2m_set_supress_ve_multi(xc_interface *handle, uint32_t domid, + uint16_t view_id, xen_pfn_t first_gfn, + xen_pfn_t last_gfn, bool sve, + xen_pfn_t *error) +{ + 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_suppress_ve_multi; + arg->domain = domid; + arg->u.suppress_ve_multi.view = view_id; + arg->u.suppress_ve_multi.first_gfn = first_gfn; + arg->u.suppress_ve_multi.last_gfn = last_gfn; + arg->u.suppress_ve_multi.suppress_ve = sve; + + rc = xencall2(handle->xcall, __HYPERVISOR_hvm_op, HVMOP_altp2m, + HYPERCALL_BUFFER_AS_ARG(arg)); + + if ( arg->u.suppress_ve_multi.first_error ) + *error = arg->u.suppress_ve_multi.first_error; + + xc_hypercall_buffer_free(handle, arg); + return rc; +} + int xc_altp2m_set_mem_access(xc_interface *handle, uint32_t domid, uint16_t view_id, xen_pfn_t gfn, xenmem_access_t access) diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c index 818e705fd1..8a2d4325f9 100644 --- a/xen/arch/x86/hvm/hvm.c +++ b/xen/arch/x86/hvm/hvm.c @@ -4553,6 +4553,7 @@ static int do_altp2m_op( case HVMOP_altp2m_destroy_p2m: case HVMOP_altp2m_switch_p2m: case HVMOP_altp2m_set_suppress_ve: + case HVMOP_altp2m_set_suppress_ve_multi: case HVMOP_altp2m_get_suppress_ve: case HVMOP_altp2m_set_mem_access: case HVMOP_altp2m_set_mem_access_multi: @@ -4711,6 +4712,18 @@ static int do_altp2m_op( } break; + case HVMOP_altp2m_set_suppress_ve_multi: + if ( a.u.suppress_ve_multi.pad1 || !a.u.suppress_ve_multi.pad2 ) + rc = -EINVAL; + else + { + rc = p2m_set_suppress_ve_multi(d, &a.u.suppress_ve_multi); + + if ( __copy_to_guest(arg, &a, 1) ) + rc = -EFAULT; + } + break; + case HVMOP_altp2m_get_suppress_ve: if ( a.u.suppress_ve.pad1 || a.u.suppress_ve.pad2 ) rc = -EINVAL; diff --git a/xen/arch/x86/mm/p2m.c b/xen/arch/x86/mm/p2m.c index ba126f790a..2b51a7f50f 100644 --- a/xen/arch/x86/mm/p2m.c +++ b/xen/arch/x86/mm/p2m.c @@ -3059,6 +3059,66 @@ out: return rc; } +/* + * Set/clear the #VE suppress bit for multiple pages. Only available on VMX. + */ +int p2m_set_suppress_ve_multi(struct domain *d, + struct xen_hvm_altp2m_suppress_ve_multi *sve) +{ + struct p2m_domain *host_p2m = p2m_get_hostp2m(d); + struct p2m_domain *ap2m = NULL; + struct p2m_domain *p2m; + uint64_t start = sve->opaque ?: sve->first_gfn; + int rc = 0; + + if ( sve->view > 0 ) + { + if ( sve->view >= MAX_ALTP2M || + d->arch.altp2m_eptp[sve->view] == mfn_x(INVALID_MFN) ) + return -EINVAL; + + p2m = ap2m = d->arch.altp2m_p2m[sve->view]; + } + else + p2m = host_p2m; + + p2m_lock(host_p2m); + + if ( ap2m ) + p2m_lock(ap2m); + + + while ( sve->last_gfn >= start ) + { + p2m_access_t a; + p2m_type_t t; + mfn_t mfn; + + if ( altp2m_get_effective_entry(p2m, _gfn(start), &mfn, &t, &a, AP2MGET_query) ) + a = p2m->default_access; + + if ( p2m->set_entry(p2m, _gfn(start), mfn, PAGE_ORDER_4K, t, a, + sve->suppress_ve) && !sve->first_error ) + sve->first_error = start; /* Save the gfn from of the first error */ + + /* Check for continuation if it's not the last iteration. */ + if ( sve->last_gfn >= ++start && hypercall_preempt_check() ) + { + rc = -ERESTART; + break; + } + } + + sve->opaque = start; + + if ( ap2m ) + p2m_unlock(ap2m); + + p2m_unlock(host_p2m); + + return rc; +} + int p2m_get_suppress_ve(struct domain *d, gfn_t gfn, bool *suppress_ve, unsigned int altp2m_idx) { diff --git a/xen/include/public/hvm/hvm_op.h b/xen/include/public/hvm/hvm_op.h index 353f8034d9..10ba0149f1 100644 --- a/xen/include/public/hvm/hvm_op.h +++ b/xen/include/public/hvm/hvm_op.h @@ -46,6 +46,17 @@ struct xen_hvm_altp2m_suppress_ve { uint64_t gfn; }; +struct xen_hvm_altp2m_suppress_ve_multi { + uint16_t view; + uint8_t suppress_ve; /* Boolean type. */ + uint8_t pad1; + uint32_t pad2; + uint64_t first_gfn; + uint64_t last_gfn; + uint64_t opaque; + uint64_t first_error; /* Gfn of the first error. */ +}; + #if __XEN_INTERFACE_VERSION__ < 0x00040900 /* Set the logical level of one of a domain's PCI INTx wires. */ @@ -339,6 +350,8 @@ struct xen_hvm_altp2m_op { #define HVMOP_altp2m_vcpu_disable_notify 13 /* Get the active vcpu p2m index */ #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 domid_t domain; uint16_t pad1; uint32_t pad2; @@ -353,6 +366,7 @@ struct xen_hvm_altp2m_op { struct xen_hvm_altp2m_change_gfn change_gfn; struct xen_hvm_altp2m_set_mem_access_multi set_mem_access_multi; struct xen_hvm_altp2m_suppress_ve suppress_ve; + 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; uint8_t pad[64]; diff --git a/xen/include/xen/mem_access.h b/xen/include/xen/mem_access.h index e4d24502e0..00e594a0ad 100644 --- a/xen/include/xen/mem_access.h +++ b/xen/include/xen/mem_access.h @@ -75,6 +75,9 @@ long p2m_set_mem_access_multi(struct domain *d, int p2m_set_suppress_ve(struct domain *d, gfn_t gfn, bool suppress_ve, unsigned int altp2m_idx); +int p2m_set_suppress_ve_multi(struct domain *d, + struct xen_hvm_altp2m_suppress_ve_multi *suppress_ve); + int p2m_get_suppress_ve(struct domain *d, gfn_t gfn, bool *suppress_ve, unsigned int altp2m_idx); From patchwork Thu Nov 21 15:02:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Alexandru Stefan ISAILA X-Patchwork-Id: 11256369 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 7668C6C1 for ; Thu, 21 Nov 2019 15:03:40 +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 45C0A206DA for ; Thu, 21 Nov 2019 15:03:40 +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="Sl4bLRXx" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 45C0A206DA 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 1iXnyW-0001wS-U1; Thu, 21 Nov 2019 15:02:28 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iXnyV-0001wI-Fb for xen-devel@lists.xenproject.org; Thu, 21 Nov 2019 15:02:27 +0000 X-Inumbo-ID: ed33291c-0c6f-11ea-adbe-bc764e2007e4 Received: from EUR04-VI1-obe.outbound.protection.outlook.com (unknown [2a01:111:f400:fe0e::714]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id ed33291c-0c6f-11ea-adbe-bc764e2007e4; Thu, 21 Nov 2019 15:02:25 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bN9dM0VYm9QkFNYa8ZnMh4wyBb0J3pe1hU4eFVBkObS9s9ofzwQZ4XTJHY/NuRsWRqN0LlInLub+KcBd9H911EXt2Lzj9qcCcryXhD1aV2lFPVOWHgUhcp8UTFk3GdT1LLhFJCdcChMSSJkWEFuplWp0bQn8xgfNV2RTjbGusONdgczJjKawcjqbxeVOuOUMJVXa35Fq5j7YKbChLPTRErKUA5esfe8OhuHPeimd8EHcrtOB4bgPk/KPG8DIs6/uJEK0QcK9DYSz2h9KcF6vFhbBFll5TepwHQJezjbZ83sTJNA5f85D/eumPzXhK0wdMBGId+QY886+aEj0HgU79w== 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=oX2Gn/OCswMxcRBFpIBBybEAaMTTuWUmwwv01x0P22g=; b=Up/P61/LC4DNZDkOJlChmrvYfEA6kldLO3SSvWuybby4Cd4MR1CIo1koOTHodjuBNxwK+TRSSFgr3jcM6N06dyhLsHZN2CQbgKsoatYJBatDdzeJifmrlvl7qy8NJPoL2DTIP3V0Esn8fX5rcroWtPPtUbcOVEOfo2olkvpA2UnP07pi5Ce4HZMk+XFL+ItIYNYwlhghqBawWx1mBdooENpaPAXDGm389NpJ9C3RVzsxVCovmBWZt01ZXIMl0vhvZNFmvtBhWfIm/2t9Io1aNzpUgX2+OK8HarqDhsATW7UvVHjjCCWmo9qe45qva3YQiSores36JUL2tKlsmQC5Xg== 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=oX2Gn/OCswMxcRBFpIBBybEAaMTTuWUmwwv01x0P22g=; b=Sl4bLRXxXkSvz5H62iRlDrw2j3jJFI/IxCj5Nyv3Jz2/xu7R436fEgVveMUDex+5BAEHAcnxzJuOoWznphcvSbg+NpGw39SNRuw2F9R1bFst0XA4JemeyzVU/nk74Exh/P3OL5zpjCw3svAcw90gjkm0svoWLsBeY69zeeHXXw8= Received: from AM0PR02MB5553.eurprd02.prod.outlook.com (10.255.30.78) by AM0PR02MB5858.eurprd02.prod.outlook.com (52.132.213.14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2451.30; Thu, 21 Nov 2019 15:02:23 +0000 Received: from AM0PR02MB5553.eurprd02.prod.outlook.com ([fe80::8cec:7638:734c:89d]) by AM0PR02MB5553.eurprd02.prod.outlook.com ([fe80::8cec:7638:734c:89d%4]) with mapi id 15.20.2474.019; Thu, 21 Nov 2019 15:02:23 +0000 From: Alexandru Stefan ISAILA To: "xen-devel@lists.xenproject.org" Thread-Topic: [PATCH V3 2/2] x86/mm: Make use of the default access param from xc_altp2m_create_view Thread-Index: AQHVoHytGfGqS+cYyU6c6j3Ysa8x8g== Date: Thu, 21 Nov 2019 15:02:23 +0000 Message-ID: <20191121150124.15865-2-aisaila@bitdefender.com> References: <20191121150124.15865-1-aisaila@bitdefender.com> In-Reply-To: <20191121150124.15865-1-aisaila@bitdefender.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: FR2P281CA0005.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:a::15) To AM0PR02MB5553.eurprd02.prod.outlook.com (2603:10a6:208:160::14) 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: dda0c9cd-0cbd-4676-b696-08d76e93d03f x-ms-traffictypediagnostic: AM0PR02MB5858:|AM0PR02MB5858:|AM0PR02MB5858: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:2958; x-forefront-prvs: 0228DDDDD7 x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(346002)(376002)(39860400002)(366004)(396003)(136003)(189003)(199004)(2501003)(3846002)(54906003)(5640700003)(26005)(6436002)(66066001)(186003)(5660300002)(386003)(6506007)(6512007)(2351001)(7736002)(52116002)(36756003)(305945005)(7416002)(76176011)(316002)(81156014)(81166006)(99286004)(64756008)(66476007)(50226002)(8936002)(66556008)(66446008)(66946007)(2906002)(14454004)(6486002)(4326008)(8676002)(25786009)(71200400001)(71190400001)(6916009)(102836004)(86362001)(478600001)(1076003)(14444005)(256004)(11346002)(446003)(2616005)(6116002); DIR:OUT; SFP:1102; SCL:1; SRVR:AM0PR02MB5858; H:AM0PR02MB5553.eurprd02.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A: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: 6rI5KPy5oTDcxxuWCtJni1iOd9yVWn9dyWeq/KUtp/pnBhxgL4gTnMFFmizWMQK4veztQ/FH+kIR5NL25Sef3UcY/mv30rPRQMcfsm1fTNBII2PL+C5ewtDzjcULJyE4aeDYFdF8Wr5coF+wEw933F7eOWTu6xq22od3IPGc8Z4Levdyrpf+5g+hJohEhbU6YhB7kM67OmPi7V861wWWR5oVDUxeAN3sMipsSQLy9dCdhT20s5/9rrqG5dTk/5gwm9rYhEiLM52zZtqer/+/Gw9cYyqwLpwLDqkRcjHaK9Ki2Rc1KcH3HoC997XGW30JWqAFVmcNGFN0Vum2GQL1LsAyU1pp/JA8zUGbNAThSbj4teTYdN5Ba85/N/DBGdx4pJ8ea9pyQw2mE8uY9nEr0E0rkU+SrBFu8sbn88bYcIEFMiRlfxaHF+MOZcz8KUJ2 Content-ID: <1FB06FA4CA58054E99AD7EB8AFC996C2@eurprd02.prod.outlook.com> MIME-Version: 1.0 X-OriginatorOrg: bitdefender.com X-MS-Exchange-CrossTenant-Network-Message-Id: dda0c9cd-0cbd-4676-b696-08d76e93d03f X-MS-Exchange-CrossTenant-originalarrivaltime: 21 Nov 2019 15:02:23.0987 (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: AjoY2ckbJNw59PkC6eq7/zukuBMvfcWSVEYtuztX/vzgNRP8nKWNlU2QAg1/ve/DNguzDePam2OEtK5oWU8/oRmTzLWyA+4Zsm2uHn1jeSU= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR02MB5858 Subject: [Xen-devel] [PATCH V3 2/2] x86/mm: Make use of the default access param from xc_altp2m_create_view 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: Petre Ovidiu PIRCALABU , Kevin Tian , Stefano Stabellini , Julien Grall , Razvan COJOCARU , Wei Liu , Konrad Rzeszutek Wilk , George Dunlap , Andrew Cooper , Ian Jackson , Tamas K Lengyel , Jan Beulich , Jun Nakajima , 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 the default_access param from xc_altp2m_create_view is not used. This patch assigns default_access to p2m->default_access at the time of initializing a new altp2m view. Signed-off-by: Alexandru Isaila --- CC: Jan Beulich CC: Andrew Cooper CC: Wei Liu CC: "Roger Pau Monné" CC: George Dunlap CC: Ian Jackson CC: Julien Grall CC: Konrad Rzeszutek Wilk CC: Stefano Stabellini CC: Razvan Cojocaru CC: Tamas K Lengyel CC: Petre Pircalabu CC: George Dunlap CC: Jun Nakajima CC: Kevin Tian --- Changes since V2: - Drop static from xenmem_access_to_p2m_access() and declare it in mem_access.h - Use xenmem_access_to_p2m_access() in p2m_init_next_altp2m() - Pull out the p2m specifics from p2m_init_altp2m_ept(). --- xen/arch/x86/hvm/hvm.c | 3 ++- xen/arch/x86/mm/mem_access.c | 6 +++--- xen/arch/x86/mm/p2m-ept.c | 6 ------ xen/arch/x86/mm/p2m.c | 29 +++++++++++++++++++++++++---- xen/include/asm-x86/p2m.h | 3 ++- xen/include/public/hvm/hvm_op.h | 2 -- xen/include/xen/mem_access.h | 4 ++++ 7 files changed, 36 insertions(+), 17 deletions(-) diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c index 8a2d4325f9..82ead91cad 100644 --- a/xen/arch/x86/hvm/hvm.c +++ b/xen/arch/x86/hvm/hvm.c @@ -4687,7 +4687,8 @@ static int do_altp2m_op( } case HVMOP_altp2m_create_p2m: - if ( !(rc = p2m_init_next_altp2m(d, &a.u.view.view)) ) + if ( !(rc = p2m_init_next_altp2m(d, &a.u.view.view, + a.u.view.hvmmem_default_access)) ) rc = __copy_to_guest(arg, &a, 1) ? -EFAULT : 0; break; diff --git a/xen/arch/x86/mm/mem_access.c b/xen/arch/x86/mm/mem_access.c index 320b9fe621..0639056748 100644 --- a/xen/arch/x86/mm/mem_access.c +++ b/xen/arch/x86/mm/mem_access.c @@ -314,9 +314,9 @@ static int set_mem_access(struct domain *d, struct p2m_domain *p2m, return rc; } -static bool xenmem_access_to_p2m_access(struct p2m_domain *p2m, - xenmem_access_t xaccess, - p2m_access_t *paccess) +bool xenmem_access_to_p2m_access(struct p2m_domain *p2m, + xenmem_access_t xaccess, + p2m_access_t *paccess) { static const p2m_access_t memaccess[] = { #define ACCESS(ac) [XENMEM_access_##ac] = p2m_access_##ac diff --git a/xen/arch/x86/mm/p2m-ept.c b/xen/arch/x86/mm/p2m-ept.c index f06e51904a..2bdc93b689 100644 --- a/xen/arch/x86/mm/p2m-ept.c +++ b/xen/arch/x86/mm/p2m-ept.c @@ -1357,13 +1357,7 @@ void p2m_init_altp2m_ept(struct domain *d, unsigned int i) struct p2m_domain *hostp2m = p2m_get_hostp2m(d); struct ept_data *ept; - p2m->default_access = hostp2m->default_access; - p2m->domain = hostp2m->domain; - - p2m->global_logdirty = hostp2m->global_logdirty; p2m->ept.ad = hostp2m->ept.ad; - p2m->min_remapped_gfn = gfn_x(INVALID_GFN); - p2m->max_mapped_pfn = p2m->max_remapped_gfn = 0; ept = &p2m->ept; ept->mfn = pagetable_get_pfn(p2m_get_pagetable(p2m)); d->arch.altp2m_eptp[i] = ept->eptp; diff --git a/xen/arch/x86/mm/p2m.c b/xen/arch/x86/mm/p2m.c index 2b51a7f50f..18f5b2ef29 100644 --- a/xen/arch/x86/mm/p2m.c +++ b/xen/arch/x86/mm/p2m.c @@ -25,6 +25,7 @@ #include /* copy_from_guest() */ #include +#include #include #include #include @@ -2533,7 +2534,8 @@ void p2m_flush_altp2m(struct domain *d) altp2m_list_unlock(d); } -static int p2m_activate_altp2m(struct domain *d, unsigned int idx) +static int p2m_activate_altp2m(struct domain *d, unsigned int idx, + p2m_access_t hvmmem_default_access) { struct p2m_domain *hostp2m, *p2m; int rc; @@ -2559,6 +2561,12 @@ static int p2m_activate_altp2m(struct domain *d, unsigned int idx) goto out; } + p2m->default_access = hvmmem_default_access; + p2m->domain = hostp2m->domain; + p2m->global_logdirty = hostp2m->global_logdirty; + p2m->min_remapped_gfn = gfn_x(INVALID_GFN); + p2m->max_mapped_pfn = p2m->max_remapped_gfn = 0; + p2m_init_altp2m_ept(d, idx); out: @@ -2570,6 +2578,7 @@ static int p2m_activate_altp2m(struct domain *d, unsigned int idx) int p2m_init_altp2m_by_id(struct domain *d, unsigned int idx) { int rc = -EINVAL; + struct p2m_domain *hostp2m = p2m_get_hostp2m(d); if ( idx >= MAX_ALTP2M ) return rc; @@ -2577,16 +2586,23 @@ int p2m_init_altp2m_by_id(struct domain *d, unsigned int idx) altp2m_list_lock(d); if ( d->arch.altp2m_eptp[idx] == mfn_x(INVALID_MFN) ) - rc = p2m_activate_altp2m(d, idx); + rc = p2m_activate_altp2m(d, idx, hostp2m->default_access); altp2m_list_unlock(d); return rc; } -int p2m_init_next_altp2m(struct domain *d, uint16_t *idx) +int p2m_init_next_altp2m(struct domain *d, uint16_t *idx, + uint16_t hvmmem_default_access) { int rc = -EINVAL; unsigned int i; + p2m_access_t a; + struct p2m_domain *p2m; + + + if ( hvmmem_default_access > XENMEM_access_default ) + return rc; altp2m_list_lock(d); @@ -2595,7 +2611,12 @@ int p2m_init_next_altp2m(struct domain *d, uint16_t *idx) if ( d->arch.altp2m_eptp[i] != mfn_x(INVALID_MFN) ) continue; - rc = p2m_activate_altp2m(d, i); + p2m = d->arch.altp2m_p2m[i]; + + if ( !xenmem_access_to_p2m_access(p2m, hvmmem_default_access, &a) ) + return -EINVAL; + + rc = p2m_activate_altp2m(d, i, a); if ( !rc ) *idx = i; diff --git a/xen/include/asm-x86/p2m.h b/xen/include/asm-x86/p2m.h index 94285db1b4..321d5e70a8 100644 --- a/xen/include/asm-x86/p2m.h +++ b/xen/include/asm-x86/p2m.h @@ -884,7 +884,8 @@ bool p2m_altp2m_get_or_propagate(struct p2m_domain *ap2m, unsigned long gfn_l, int p2m_init_altp2m_by_id(struct domain *d, unsigned int idx); /* Find an available alternate p2m and make it valid */ -int p2m_init_next_altp2m(struct domain *d, uint16_t *idx); +int p2m_init_next_altp2m(struct domain *d, uint16_t *idx, + uint16_t hvmmem_default_access); /* Make a specific alternate p2m invalid */ int p2m_destroy_altp2m_by_id(struct domain *d, unsigned int idx); diff --git a/xen/include/public/hvm/hvm_op.h b/xen/include/public/hvm/hvm_op.h index 10ba0149f1..bd44cd0f58 100644 --- a/xen/include/public/hvm/hvm_op.h +++ b/xen/include/public/hvm/hvm_op.h @@ -252,8 +252,6 @@ DEFINE_XEN_GUEST_HANDLE(xen_hvm_altp2m_vcpu_disable_notify_t); struct xen_hvm_altp2m_view { /* IN/OUT variable */ uint16_t view; - /* Create view only: default access type - * NOTE: currently ignored */ uint16_t hvmmem_default_access; /* xenmem_access_t */ }; typedef struct xen_hvm_altp2m_view xen_hvm_altp2m_view_t; diff --git a/xen/include/xen/mem_access.h b/xen/include/xen/mem_access.h index 00e594a0ad..e0ab5b2775 100644 --- a/xen/include/xen/mem_access.h +++ b/xen/include/xen/mem_access.h @@ -58,6 +58,10 @@ typedef enum { /* NOTE: Assumed to be only 4 bits right now on x86. */ } p2m_access_t; +bool xenmem_access_to_p2m_access(struct p2m_domain *p2m, + xenmem_access_t xaccess, + p2m_access_t *paccess); + /* * Set access type for a region of gfns. * If gfn == INVALID_GFN, sets the default access type.