From patchwork Wed Nov 6 15:35:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandru Stefan ISAILA X-Patchwork-Id: 11230619 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 D3C141575 for ; Wed, 6 Nov 2019 15:36: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 A397B217F5 for ; Wed, 6 Nov 2019 15:36: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="j6qTXB7/" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A397B217F5 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 1iSNKs-0005g1-DO; Wed, 06 Nov 2019 15:35:06 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iSNKq-0005fv-SG for xen-devel@lists.xenproject.org; Wed, 06 Nov 2019 15:35:04 +0000 X-Inumbo-ID: 001e113e-00ab-11ea-9631-bc764e2007e4 Received: from EUR04-VI1-obe.outbound.protection.outlook.com (unknown [40.107.8.117]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 001e113e-00ab-11ea-9631-bc764e2007e4; Wed, 06 Nov 2019 15:35:03 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gT9qQHjQnDbH5vutipgDJBUhNPkqckYw3qsVp8ATNIt+dKVaHuBpCYYUnMfCI4/dvEOlXEgBZ6wrOFBA/0kt+onP4aCpggWDQxg4vhgHlFmMu9TIlP5HyV4IEhlyMhhBxHSqSJ9PIhvs838huxzmxz2wn7DB8xFowpf1QQTxRTkCyAXlDcSIYMXNUACv4128k+hkN7yYTMq4QrKHg1ZU8K1e8oiF2H5pGJg4n1G6VPk32y2y7FN0cQnVpWvjJ3laHggdggmij08Ntyo1O+ypUzmNPiU+sl5ROia54vrDIVcMQXoTXNq1x1u9QPQKnvtjpuvQEsTTBuzMtYAI+L1ACg== 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=hkQP+B8wCPT0iUGKIDmKlXk0NJnRPGX2rzhBinZpGuo=; b=Qo834bKLsdaqhh8rv/tRIBCtBKZPzuIL6HSGjP0MlVb7I0jBy/37rguyXbyN5lyYqH6w5sPPF7o6rYaMl9lGK4wfTwF58jT+w4cy74KYMkGt/cHcnSAJSiHEiMxNnYj2BdN3fwxgG8AVwqezrEphwfNRmDtzL6cjEG/2RmZbluUVIN6mQ0cSDtN22VGcO4ad35eWFfW0h0YAlzVR0LTb4h5AGwJMNnYeybp5euXRFkuV11NYpeGJ0GGMuQVe95S8qRRtxlnTFdFZRI3P6Bdkl0O8nMPnQXjotQiYgxHs5ca2SRFFnXOFuMW2fZ6wchKDI5RJ1DW35pVAphVpc26xRQ== 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=hkQP+B8wCPT0iUGKIDmKlXk0NJnRPGX2rzhBinZpGuo=; b=j6qTXB7/ovX26vkJH4rmOQejITbWytDPUuEs772Hk8cMYdHf8Z3L/wIJq6TsB3kSGGCF8G5UbJpMUk0Xmi0PL47MEfktyq8MkGoV1PHRC9yUAVmrM6g2JqLk/QwRMc62nwZQcTi6NcfIDZFjjnevv6PGccJvOg9zmBP77fe0GWo= Received: from AM6PR0202MB3413.eurprd02.prod.outlook.com (52.133.30.28) by AM6PR0202MB3287.eurprd02.prod.outlook.com (52.133.30.13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2408.24; Wed, 6 Nov 2019 15:35:02 +0000 Received: from AM6PR0202MB3413.eurprd02.prod.outlook.com ([fe80::a569:5be5:9861:577d]) by AM6PR0202MB3413.eurprd02.prod.outlook.com ([fe80::a569:5be5:9861:577d%5]) with mapi id 15.20.2408.025; Wed, 6 Nov 2019 15:35:01 +0000 From: Alexandru Stefan ISAILA To: "xen-devel@lists.xenproject.org" Thread-Topic: [PATCH V2 1/2] x86/altp2m: Add hypercall to set a range of sve bits Thread-Index: AQHVlLfBrDM8T0M9gEmymLFobxrGFA== Date: Wed, 6 Nov 2019 15:35:01 +0000 Message-ID: <20191106153442.12776-1-aisaila@bitdefender.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: AM0PR0102CA0056.eurprd01.prod.exchangelabs.com (2603:10a6:208::33) To AM6PR0202MB3413.eurprd02.prod.outlook.com (2603:10a6:209:1c::28) 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: d6988609-822f-4beb-b98c-08d762cee36d x-ms-traffictypediagnostic: AM6PR0202MB3287:|AM6PR0202MB3287:|AM6PR0202MB3287: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:626; x-forefront-prvs: 02135EB356 x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(979002)(346002)(376002)(366004)(396003)(136003)(39860400002)(199004)(189003)(3846002)(2501003)(6116002)(6916009)(2906002)(1076003)(14454004)(5660300002)(305945005)(25786009)(7736002)(478600001)(7416002)(6512007)(86362001)(107886003)(5640700003)(486006)(8676002)(36756003)(6486002)(2616005)(50226002)(6436002)(476003)(316002)(52116002)(99286004)(186003)(26005)(4326008)(54906003)(386003)(102836004)(6506007)(71200400001)(64756008)(66556008)(66476007)(71190400001)(66446008)(66946007)(2351001)(8936002)(81166006)(81156014)(14444005)(256004)(66066001)(969003)(989001)(999001)(1009001)(1019001); DIR:OUT; SFP:1102; SCL:1; SRVR:AM6PR0202MB3287; H:AM6PR0202MB3413.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: 4t9JgMvG8WLrbTSLplOuuM6Y+IFVupmB2lnWGtp0tMogtFb/v8Gb0ns3q3TJeiMFj3ZR4fSrPIPwEvzRf8b/ymM2VrVCCbMTtkIbaZMmJXpKvHqwo8vaszddP8rEO6wXgDBmPMGR9/Bk1/P4g8yAc/EFuDCYEuwiUF1/P460ZXQDXHdo1zOOggNtk9eVKLaAVGdZIsL5OLshyEsNKsIlLeeHXEkbdv0xpXrUeAH+irGjNZ2f83OX6BmmO8g/iB73sdLrtrO6xPaKdquq/Soj3vmDEWMz3Q2hxb7TvoQDKXiHVYYpUF9K9ThOCnnauql1Y02rF+g1IsEMSdYa0UWg99HYMMWQ7QAu3MCAmTg31LE8zWjHP3oNSXfv8vTlwHJ9Ue2hVPhzswXcGQporiADXoAo9D6dan3b+114OSZ5+94uZDdhJk7KtiRnI4ryMAP6 MIME-Version: 1.0 X-OriginatorOrg: bitdefender.com X-MS-Exchange-CrossTenant-Network-Message-Id: d6988609-822f-4beb-b98c-08d762cee36d X-MS-Exchange-CrossTenant-originalarrivaltime: 06 Nov 2019 15:35:01.6497 (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: 6t+yLDIcach9o/aXBPcUzNkoHgW5uaBmyRw+Od4VVfYpAwXsSZNFKBNb+9K+BBwfriCp6uQUO2Dm362QwFBw7W0paLTQuQ2MJSYE7wfXjog= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR0202MB3287 Subject: [Xen-devel] [PATCH V2 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 , "sstabellini@kernel.org" , "julien@xen.org" , Razvan COJOCARU , "wl@xen.org" , "konrad.wilk@oracle.com" , "george.dunlap@eu.citrix.com" , "andrew.cooper3@citrix.com" , "ian.jackson@eu.citrix.com" , "tamas@tklengyel.com" , "jbeulich@suse.com" , Alexandru Stefan ISAILA , "roger.pau@citrix.com" 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 Reviewed-by: Tamas K Lengyel --- Changes since V1: - Remove "continue" - Add a new field in xen_hvm_altp2m_suppress_ve to store the continuation value - Have p2m_set_suppress_ve_multi() take xen_hvm_altp2m_suppress_ve as a param. --- tools/libxc/include/xenctrl.h | 3 ++ tools/libxc/xc_altp2m.c | 25 ++++++++++++++ xen/arch/x86/hvm/hvm.c | 20 ++++++++++-- xen/arch/x86/mm/p2m.c | 58 +++++++++++++++++++++++++++++++++ xen/include/public/hvm/hvm_op.h | 5 ++- xen/include/xen/mem_access.h | 3 ++ 6 files changed, 111 insertions(+), 3 deletions(-) diff --git a/tools/libxc/include/xenctrl.h b/tools/libxc/include/xenctrl.h index f4431687b3..21b644f459 100644 --- a/tools/libxc/include/xenctrl.h +++ b/tools/libxc/include/xenctrl.h @@ -1923,6 +1923,9 @@ 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 start_gfn, + uint32_t nr, bool sve); 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..6605d9abbe 100644 --- a/tools/libxc/xc_altp2m.c +++ b/tools/libxc/xc_altp2m.c @@ -234,6 +234,31 @@ 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 start_gfn, + uint32_t nr, bool sve) +{ + 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.view = view_id; + arg->u.suppress_ve.gfn = start_gfn; + arg->u.suppress_ve.suppress_ve = sve; + arg->u.suppress_ve.nr = nr; + + rc = xencall2(handle->xcall, __HYPERVISOR_hvm_op, HVMOP_altp2m, + HYPERCALL_BUFFER_AS_ARG(arg)); + 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 06a7b40107..66ed8b8e3e 100644 --- a/xen/arch/x86/hvm/hvm.c +++ b/xen/arch/x86/hvm/hvm.c @@ -4535,6 +4535,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: @@ -4681,7 +4682,7 @@ static int do_altp2m_op( break; case HVMOP_altp2m_set_suppress_ve: - if ( a.u.suppress_ve.pad1 || a.u.suppress_ve.pad2 ) + if ( a.u.suppress_ve.pad1 ) rc = -EINVAL; else { @@ -4693,8 +4694,23 @@ static int do_altp2m_op( } break; + case HVMOP_altp2m_set_suppress_ve_multi: + if ( a.u.suppress_ve.pad1 || !a.u.suppress_ve.nr ) + rc = -EINVAL; + else + { + rc = p2m_set_suppress_ve_multi(d, &a.u.suppress_ve); + + if ( rc == -ERESTART ) + if ( __copy_field_to_guest(guest_handle_cast(arg, + xen_hvm_altp2m_op_t), + &a, u.suppress_ve.opaque) ) + rc = -EFAULT; + } + break; + case HVMOP_altp2m_get_suppress_ve: - if ( a.u.suppress_ve.pad1 || a.u.suppress_ve.pad2 ) + if ( a.u.suppress_ve.pad1 ) rc = -EINVAL; else { diff --git a/xen/arch/x86/mm/p2m.c b/xen/arch/x86/mm/p2m.c index e5e4349dea..9e1335065d 100644 --- a/xen/arch/x86/mm/p2m.c +++ b/xen/arch/x86/mm/p2m.c @@ -3054,6 +3054,64 @@ 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* 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->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 ( start < sve->nr ) + { + 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; + + p2m->set_entry(p2m, _gfn(start), mfn, PAGE_ORDER_4K, t, a, sve->suppress_ve); + + /* Check for continuation if it's not the last iteration. */ + if ( sve->nr > ++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..9834ce0aea 100644 --- a/xen/include/public/hvm/hvm_op.h +++ b/xen/include/public/hvm/hvm_op.h @@ -42,8 +42,9 @@ struct xen_hvm_altp2m_suppress_ve { uint16_t view; uint8_t suppress_ve; /* Boolean type. */ uint8_t pad1; - uint32_t pad2; + uint32_t nr; uint64_t gfn; + uint64_t opaque; }; #if __XEN_INTERFACE_VERSION__ < 0x00040900 @@ -339,6 +340,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; diff --git a/xen/include/xen/mem_access.h b/xen/include/xen/mem_access.h index e4d24502e0..ffecd2650e 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* suppress_ve); + int p2m_get_suppress_ve(struct domain *d, gfn_t gfn, bool *suppress_ve, unsigned int altp2m_idx); From patchwork Wed Nov 6 15:35:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandru Stefan ISAILA X-Patchwork-Id: 11230621 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 899261709 for ; Wed, 6 Nov 2019 15:36:43 +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 5A778217F5 for ; Wed, 6 Nov 2019 15:36:43 +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="hkgRxm0f" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5A778217F5 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 1iSNKw-0005gs-R4; Wed, 06 Nov 2019 15:35:10 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iSNKv-0005ge-SM for xen-devel@lists.xenproject.org; Wed, 06 Nov 2019 15:35:09 +0000 X-Inumbo-ID: 0234edd0-00ab-11ea-984a-bc764e2007e4 Received: from EUR04-VI1-obe.outbound.protection.outlook.com (unknown [40.107.8.100]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 0234edd0-00ab-11ea-984a-bc764e2007e4; Wed, 06 Nov 2019 15:35:07 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ajXtNcWhf/9vOrjHwEwPuWqpxClPMCdouMbb3/tPjJB1YOy5lj2SmeQlCJlehC447K++X6a6erreh6HIyDUhJ122cNvqfoI3hWK/2/SzT14Z2d3RybjO2/GDowf2oh6fP5Fp+5A8w2bie4jILpeLXhtH5grqg5JRZVUeTQdQs5KXPNsPiQdQgSorHGyAhYjyZzIq6ATpn3nRLXrkT3FH5AFc8p1hJJ+ziW+FngZ8X83MYOXsCKWkoVrap//f7Edqu0YhZhIBFpzx6xgoP5TkWqItgXovEVviRjS9hrfYLIyGtbXlCr8x6VaV5JtazmtPOWVYVXBNNMd8Nh0PaVvaeQ== 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=o7I+4KtjRD3nRHm1f0/0Szz90D8lmEMyRoa1GQNyxUk=; b=dbQdMv34DDwrcGaY77jG7W9zPDENFR2QrIRJRIyKkIFToYNnPI7SLb6KgtojhiK36Rm4baMSlejk7Oc5KsGcMyVq91axwI1VeYK0YA+DOHfqhFVcwN4kh+7RPeRX2QD+bsWZ27/rsrGmVB4jCE8ELwcIB7bk1PNZvjMBpizvljn1DxbBeWcYsmNSmlbD42rYuAsuVSKYSL8U39UbzoOX0biSNF8PUnjy+dG4Uoq2uxsgXuljvyC8FD8Q/7HHca+9nRGueokndxSKV2kEJjYS7kGzR2Lw9QKwTL2k/w7fR2IWkSpWSsmusVMd3mwd2BPRg3noRL7a2qk+j1Um1udlHg== 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=o7I+4KtjRD3nRHm1f0/0Szz90D8lmEMyRoa1GQNyxUk=; b=hkgRxm0fBdT78/eLgfAXHBCtl8AZbw6SJW11uWkc3F4YDntdfkfDWVNYy7N47hMQs/ucdqKsG6ETD/A2OY5zflLd8vzSs4QdSUc7YPvDnU7LqimPaN1W7KsyZSF9YeHZhvLS1dSV8db/7wVuKq/sAaoiltlrh6hwi4JifFro1ck= Received: from AM6PR0202MB3413.eurprd02.prod.outlook.com (52.133.30.28) by AM6PR0202MB3287.eurprd02.prod.outlook.com (52.133.30.13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2408.24; Wed, 6 Nov 2019 15:35:05 +0000 Received: from AM6PR0202MB3413.eurprd02.prod.outlook.com ([fe80::a569:5be5:9861:577d]) by AM6PR0202MB3413.eurprd02.prod.outlook.com ([fe80::a569:5be5:9861:577d%5]) with mapi id 15.20.2408.025; Wed, 6 Nov 2019 15:35:05 +0000 From: Alexandru Stefan ISAILA To: "xen-devel@lists.xenproject.org" Thread-Topic: [PATCH V2 2/2] x86/mm: Make use of the default access param from xc_altp2m_create_view Thread-Index: AQHVlLfDr+RM8TY7GUOAeWVMyfSIGA== Date: Wed, 6 Nov 2019 15:35:05 +0000 Message-ID: <20191106153442.12776-2-aisaila@bitdefender.com> References: <20191106153442.12776-1-aisaila@bitdefender.com> In-Reply-To: <20191106153442.12776-1-aisaila@bitdefender.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: AM0PR0102CA0056.eurprd01.prod.exchangelabs.com (2603:10a6:208::33) To AM6PR0202MB3413.eurprd02.prod.outlook.com (2603:10a6:209:1c::28) 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: c70138a8-1994-4e18-ad54-08d762cee5b3 x-ms-traffictypediagnostic: AM6PR0202MB3287:|AM6PR0202MB3287:|AM6PR0202MB3287: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:1850; x-forefront-prvs: 02135EB356 x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(346002)(376002)(366004)(396003)(136003)(39860400002)(199004)(189003)(3846002)(2501003)(6116002)(6916009)(2906002)(1076003)(14454004)(5660300002)(305945005)(25786009)(7736002)(478600001)(7416002)(6512007)(86362001)(107886003)(5640700003)(486006)(446003)(8676002)(36756003)(6486002)(2616005)(50226002)(6436002)(11346002)(476003)(316002)(76176011)(52116002)(99286004)(186003)(26005)(4326008)(54906003)(386003)(102836004)(6506007)(71200400001)(64756008)(66556008)(66476007)(71190400001)(66446008)(66946007)(2351001)(8936002)(81166006)(81156014)(14444005)(256004)(66066001); DIR:OUT; SFP:1102; SCL:1; SRVR:AM6PR0202MB3287; H:AM6PR0202MB3413.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: k4F2qDbRCsoXj6wSWuB5nIEUN1u4T5Jkyl6RNv6idI/9+/AUoGLqi1yGEu8RSVJ6OFsIdYyVFxN6EVrzo6Ktg03oQK7ejj00nAeAxl6HR7HTioTXaQu3Y0qu5Rxo5vQvOUn2Xf2f3xELZswh0c5ABzqeDnrBuVkw3h9GdXwwUQT+EDWhejq2EFZr6BGgmG2twUD6xVnCpVVQNhrTpxUG74eN1yduRDwj7X5f5tMxN5ajtI6FdAdvThWfj42NP3nvI/ZXk8xK5otQflq7aGueZE6HCF1XkfjcFIr4cQhKYerm5yipVEf1EF9CTIMoca++8sElVllxw3ppUTT3gnLn1W3B+tbBdE/ZuIqs5kcMr8HZv4csEMliSFk0JsYEAFDSE8IlZOHj4mOj+FBsCt/L0H5OAgrXwdtAwODxWsGpku7TEDhJMyPFtehJpfYlBEQT MIME-Version: 1.0 X-OriginatorOrg: bitdefender.com X-MS-Exchange-CrossTenant-Network-Message-Id: c70138a8-1994-4e18-ad54-08d762cee5b3 X-MS-Exchange-CrossTenant-originalarrivaltime: 06 Nov 2019 15:35:05.6425 (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: VkP4mKKW7Y0el8UjqIWxe6z1r33RmnJXDmcv9JJz8YmrJ2W6PJ6KjetIzjswuyIA8FE8Ed81KQzUvXK6u2dIS+KhIw9vWLrNsfVwXMf8eKk= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR0202MB3287 Subject: [Xen-devel] [PATCH V2 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 , "sstabellini@kernel.org" , "julien@xen.org" , Razvan COJOCARU , "wl@xen.org" , "konrad.wilk@oracle.com" , "george.dunlap@eu.citrix.com" , "andrew.cooper3@citrix.com" , "ian.jackson@eu.citrix.com" , "tamas@tklengyel.com" , "jbeulich@suse.com" , Alexandru Stefan ISAILA , "roger.pau@citrix.com" 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 Reviewed-by: Tamas K Lengyel Acked-by: George Dunlap --- xen/arch/x86/hvm/hvm.c | 3 ++- xen/arch/x86/mm/p2m-ept.c | 5 +++-- xen/arch/x86/mm/p2m.c | 31 ++++++++++++++++++++++++++----- xen/include/asm-x86/hvm/vmx/vmx.h | 3 ++- xen/include/asm-x86/p2m.h | 3 ++- xen/include/public/hvm/hvm_op.h | 2 -- 6 files changed, 35 insertions(+), 12 deletions(-) diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c index 66ed8b8e3e..84f836a5c9 100644 --- a/xen/arch/x86/hvm/hvm.c +++ b/xen/arch/x86/hvm/hvm.c @@ -4669,7 +4669,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/p2m-ept.c b/xen/arch/x86/mm/p2m-ept.c index 220990f017..e62e749ec5 100644 --- a/xen/arch/x86/mm/p2m-ept.c +++ b/xen/arch/x86/mm/p2m-ept.c @@ -1345,13 +1345,14 @@ void setup_ept_dump(void) register_keyhandler('D', ept_dump_p2m_table, "dump VT-x EPT tables", 0); } -void p2m_init_altp2m_ept(struct domain *d, unsigned int i) +void p2m_init_altp2m_ept(struct domain *d, unsigned int i, + p2m_access_t default_access) { struct p2m_domain *p2m = d->arch.altp2m_p2m[i]; struct p2m_domain *hostp2m = p2m_get_hostp2m(d); struct ept_data *ept; - p2m->default_access = hostp2m->default_access; + p2m->default_access = default_access; p2m->domain = hostp2m->domain; p2m->global_logdirty = hostp2m->global_logdirty; diff --git a/xen/arch/x86/mm/p2m.c b/xen/arch/x86/mm/p2m.c index 9e1335065d..e45a2c3c44 100644 --- a/xen/arch/x86/mm/p2m.c +++ b/xen/arch/x86/mm/p2m.c @@ -2528,7 +2528,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; @@ -2554,7 +2555,7 @@ static int p2m_activate_altp2m(struct domain *d, unsigned int idx) goto out; } - p2m_init_altp2m_ept(d, idx); + p2m_init_altp2m_ept(d, idx, hvmmem_default_access); out: p2m_unlock(p2m); @@ -2565,6 +2566,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; @@ -2572,17 +2574,36 @@ 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; + static const p2m_access_t memaccess[] = { +#define ACCESS(ac) [XENMEM_access_##ac] = p2m_access_##ac + ACCESS(n), + ACCESS(r), + ACCESS(w), + ACCESS(rw), + ACCESS(x), + ACCESS(rx), + ACCESS(wx), + ACCESS(rwx), + ACCESS(rx2rw), + ACCESS(n2rwx), +#undef ACCESS + }; + + if ( hvmmem_default_access > XENMEM_access_default ) + return rc; + altp2m_list_lock(d); for ( i = 0; i < MAX_ALTP2M; i++ ) @@ -2590,7 +2611,7 @@ 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); + rc = p2m_activate_altp2m(d, i, memaccess[hvmmem_default_access]); if ( !rc ) *idx = i; diff --git a/xen/include/asm-x86/hvm/vmx/vmx.h b/xen/include/asm-x86/hvm/vmx/vmx.h index ebaa74449b..a9601e8f7e 100644 --- a/xen/include/asm-x86/hvm/vmx/vmx.h +++ b/xen/include/asm-x86/hvm/vmx/vmx.h @@ -598,7 +598,8 @@ void ept_p2m_uninit(struct p2m_domain *p2m); void ept_walk_table(struct domain *d, unsigned long gfn); bool_t ept_handle_misconfig(uint64_t gpa); void setup_ept_dump(void); -void p2m_init_altp2m_ept(struct domain *d, unsigned int i); +void p2m_init_altp2m_ept(struct domain *d, unsigned int i, + p2m_access_t default_access); /* Locate an alternate p2m by its EPTP */ unsigned int p2m_find_altp2m_by_eptp(struct domain *d, uint64_t eptp); 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 9834ce0aea..fbe4b53d8d 100644 --- a/xen/include/public/hvm/hvm_op.h +++ b/xen/include/public/hvm/hvm_op.h @@ -242,8 +242,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;