From patchwork Tue Nov 5 12:43:44 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: 11227657 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 50EB41599 for ; Tue, 5 Nov 2019 12:45:41 +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 1EA40217F4 for ; Tue, 5 Nov 2019 12:45: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="sxVRbFb+" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1EA40217F4 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 1iRyBY-00011A-TR; Tue, 05 Nov 2019 12:43:48 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iRyBY-000115-2P for xen-devel@lists.xenproject.org; Tue, 05 Nov 2019 12:43:48 +0000 X-Inumbo-ID: e7dc0748-ffc9-11e9-9631-bc764e2007e4 Received: from EUR03-VE1-obe.outbound.protection.outlook.com (unknown [40.107.5.127]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id e7dc0748-ffc9-11e9-9631-bc764e2007e4; Tue, 05 Nov 2019 12:43:46 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FpCMMpfXLgUxiYZ10rJwTaTtlXxCpvAGzVHUc/hrO82DNPu2AQf8Nja4fGAYGxUUS3S82e8tLeFbZvBqK/++NWVgGQjzL2hjiqeBhVhWz1TNrgoozJM68LioPTkAZk2m8Lq5tgA6MAIkPIrHtqFXPAN7BysUHb3Bqtwr82Tw8YqQ7FP+dTodZughZmc0AyrLRa0EXiJWWMkZeCY5nmdogWdWLurZxRkbOtk2qVeqfyRMbyqqxxD2g+8gu1+HEFZHUnz9Y6jm4xMGG4VqudoM4qOw9yr798kBcs3BVp1KMG98rc1zTntN5ZNGirBDk37YQ41byfxu4jBttpLJ7WTAPg== 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=tSFxZyFOwMWPOXEM6BcrqbPuY4/ONycxrtjGxY6lKys=; b=UD9TUTuRZ8TD7apLx8jjFXwVUFj0sD5nSrUwosah+mdhUtTRrM98sx/gdl7iXg1W7m0ticrEd6tY6W/sPfT33brAYKSjFTGIPMS5zRXkFSBZC97XMWyXU2kSmllqsR7TsUUx1bRfTUwjxnUpMl1Lw0o0U1M+XCQKpxeVppoVY53q25raV1tHoxitLEU6NkmFEIe3PK8E6pFmIDuU/yGbi8KT2BxK/VVD616HvBkNf/UIExdlsU0rcnHyZ2FZba8LqWGaZjl6Ha7Mzu45o9Y8XOKt84ivHhk5NJc3/Bqk7lBOwc5rxfaJOCQCooW6O/J/sGtZe8ftP3lvlZtEVYuRKg== 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=tSFxZyFOwMWPOXEM6BcrqbPuY4/ONycxrtjGxY6lKys=; b=sxVRbFb+nLsgHDY0bKiGjhAHOftCuPFxKm7PtDGuza46icAeMaArpEHmTIV1V/Pi0VF/Dxn9wmx2cx6FH65XiM1aa5c3I3u1I3ujp4rygsPvYafEufCZR09Gdf4GrKzgKQmha1kwSe3YYKYkJ0D1hiJFxgVVBKD7AnamItBfbZM= Received: from AM6PR0202MB3413.eurprd02.prod.outlook.com (52.133.30.28) by AM6PR0202MB3367.eurprd02.prod.outlook.com (52.133.31.22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2408.24; Tue, 5 Nov 2019 12:43:44 +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.024; Tue, 5 Nov 2019 12:43:44 +0000 From: Alexandru Stefan ISAILA To: "xen-devel@lists.xenproject.org" Thread-Topic: [PATCH V1 1/2] x86/altp2m: Add hypercall to set a range of sve bits Thread-Index: AQHVk9ao9wGZEUCF0UWADMZln2TA+g== Date: Tue, 5 Nov 2019 12:43:44 +0000 Message-ID: <20191105124332.4380-1-aisaila@bitdefender.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: AM0PR10CA0014.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:208:17c::24) 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: 124f5a27-0633-41ce-29c8-08d761edcb1c x-ms-traffictypediagnostic: AM6PR0202MB3367:|AM6PR0202MB3367:|AM6PR0202MB3367: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:529; x-forefront-prvs: 0212BDE3BE x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(396003)(376002)(39860400002)(366004)(346002)(136003)(189003)(199004)(54906003)(4326008)(14444005)(256004)(6436002)(5640700003)(52116002)(6486002)(86362001)(2906002)(6116002)(316002)(8676002)(26005)(81156014)(186003)(50226002)(107886003)(3846002)(386003)(8936002)(64756008)(66066001)(66946007)(66446008)(66556008)(25786009)(2616005)(7416002)(6916009)(486006)(71190400001)(476003)(2351001)(5660300002)(66476007)(81166006)(478600001)(14454004)(1076003)(6512007)(99286004)(6506007)(102836004)(7736002)(36756003)(305945005)(2501003)(71200400001); DIR:OUT; SFP:1102; SCL:1; SRVR:AM6PR0202MB3367; H:AM6PR0202MB3413.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: d6dS16xmBod/ifDmf+LnPsRmlb4hM1UF3yUgSESdd01Ry6RXxwc9p2fHBSxWdLNE+Sc+Iq6x+wWVjmpSQmhmh5VBBqn/56Yo1L1JNVrg50vf0CgbWGtE/oEdLWpDNNC5ieV/mt7htKNaAEAxTs4qijHQBE/bdEICnKiIKPijHDcS0Cvf5hX7Zkjur2C5vl3zID87kM6LLiBcCOcdzDPa9w2nzTZLsaaybkQu/d3tS5pjJMdo/wezhm/B6YMg2kS/SgqJB5q3Qf9EYlOXETFDd52wOz/Ts9IdURvr3lVUi3hTFktvshJw6l2DHEUk+oNAbhBbMopOFtLmDhat8spm/W/ezUWV1Gbf6QdRyEhmnsTsYk5NaJZuska44qJ3NlF2yxS1dTCTPPrRLL03ImJU9k2n206g9PW9CYc6Am7c6TugpmvNaW4MePVNItWCXfH7 MIME-Version: 1.0 X-OriginatorOrg: bitdefender.com X-MS-Exchange-CrossTenant-Network-Message-Id: 124f5a27-0633-41ce-29c8-08d761edcb1c X-MS-Exchange-CrossTenant-originalarrivaltime: 05 Nov 2019 12:43:44.1577 (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: mVHAxYGVoPalwjaugTqEtiaVwGS9j+nDYFMZO8gMfC2B+V7waAvI7Csd1zPmFirtXYsONMs5jiAUV41sewS0ZsmbeEoKAM9+6FcV5aL/3/M= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR0202MB3367 Subject: [Xen-devel] [PATCH V1 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 --- tools/libxc/include/xenctrl.h | 3 ++ tools/libxc/xc_altp2m.c | 25 ++++++++++++++ xen/arch/x86/hvm/hvm.c | 28 +++++++++++++-- xen/arch/x86/mm/p2m.c | 61 +++++++++++++++++++++++++++++++++ xen/include/public/hvm/hvm_op.h | 4 ++- xen/include/xen/mem_access.h | 3 ++ 6 files changed, 121 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..d3d9f8c30f 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,31 @@ 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.gfn, + a.u.suppress_ve.nr, + a.u.suppress_ve.suppress_ve, + a.u.suppress_ve.view); + + if ( rc > 0 ) + { + a.u.suppress_ve.gfn = rc; + rc = -ERESTART; + + if ( __copy_field_to_guest(guest_handle_cast(arg, + xen_hvm_altp2m_op_t), + &a, u.suppress_ve.gfn) ) + 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..b2e63e75ff 100644 --- a/xen/arch/x86/mm/p2m.c +++ b/xen/arch/x86/mm/p2m.c @@ -3054,6 +3054,67 @@ out: return rc; } +/* + * Set/clear the #VE suppress bit for multiple pages. Only available on VMX. + */ +long p2m_set_suppress_ve_multi(struct domain *d, uint32_t start, uint32_t nr, + bool suppress_ve, unsigned int altp2m_idx) +{ + struct p2m_domain *host_p2m = p2m_get_hostp2m(d); + struct p2m_domain *ap2m = NULL; + struct p2m_domain *p2m; + long rc = 0; + + if ( altp2m_idx > 0 ) + { + if ( altp2m_idx >= MAX_ALTP2M || + d->arch.altp2m_eptp[altp2m_idx] == mfn_x(INVALID_MFN) ) + return -EINVAL; + + p2m = ap2m = d->arch.altp2m_p2m[altp2m_idx]; + } + else + p2m = host_p2m; + + p2m_lock(host_p2m); + + if ( ap2m ) + p2m_lock(ap2m); + + + while ( start < nr ) + { + p2m_access_t a; + p2m_type_t t; + mfn_t mfn; + + rc = altp2m_get_effective_entry(p2m, _gfn(start), &mfn, &t, &a, AP2MGET_query); + + if ( rc ) + a = p2m->default_access; + + rc = p2m->set_entry(p2m, _gfn(start), mfn, PAGE_ORDER_4K, t, a, suppress_ve); + + /* Try best effort for setting the whole range. */ + if ( rc ) + continue; + + /* Check for continuation if it's not the last iteration. */ + if ( nr > ++start && hypercall_preempt_check() ) + { + rc = start; + break; + } + } + + 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..bccfc45a07 100644 --- a/xen/include/public/hvm/hvm_op.h +++ b/xen/include/public/hvm/hvm_op.h @@ -42,7 +42,7 @@ 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; }; @@ -339,6 +339,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..0c776fc7f3 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); +long p2m_set_suppress_ve_multi(struct domain *d, uint32_t start, uint32_t nr, + bool suppress_ve, unsigned int altp2m_idx); + int p2m_get_suppress_ve(struct domain *d, gfn_t gfn, bool *suppress_ve, unsigned int altp2m_idx); From patchwork Tue Nov 5 12:43:48 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: 11227659 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 DAF5A14E5 for ; Tue, 5 Nov 2019 12:45: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 AB0FC217F4 for ; Tue, 5 Nov 2019 12:45: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="UUvxfRAD" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org AB0FC217F4 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 1iRyBd-00011L-5j; Tue, 05 Nov 2019 12:43:53 +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 1iRyBb-00011G-KR for xen-devel@lists.xenproject.org; Tue, 05 Nov 2019 12:43:51 +0000 X-Inumbo-ID: ea61ebcc-ffc9-11e9-a196-12813bfff9fa Received: from EUR04-DB3-obe.outbound.protection.outlook.com (unknown [40.107.6.139]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id ea61ebcc-ffc9-11e9-a196-12813bfff9fa; Tue, 05 Nov 2019 12:43:50 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=h7Lvia25Hc7bR6ZF0Wf3SNYOW0IC0jnkj4aKuTfHo0NlZS/sViyYcdLOHIHoqrC74SsvfGSQtggRowK86NGLBygxDS42JYugr7VWMUOOM6Zwo0FqYBTz9tZIH4lW4cOGmZwUOmMfADx8NoxG3LrOi+FFVpDtj3xdo/QaqpTSIiDedGSd5q7tNBOrcnDe0Fk11UQnOmTfAoZEqoJjLc+pcueX0k+yhSaYsHe9yFCaxpbv//I38d1QqJo0GTlC2kHf++EJtYSD0h57glO3ZjdJ+YV1lBRuPQxDOHP/iwp0Kp5IYxvIkM+P51oOaTnuN8+o9M1qKBmu5AzRBiqj88BqWg== 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=T6yJJH5ZhT84PCuYIi31YHlDdWVU0C1ZXEE/+H9/cH8=; b=jBgZlBKM0U/6vvlfwLf+wlH3KCNusw7zBBwLIOwzej8nyyRsbndtlavLzaDCLlt3IhCIFqo0BxeSPYvlye1oq8csAn7f15CGI//xrIj8vqge4nF5LP/sZRbWjaud8aYg7kWCShDsF/fkMfs3KBjf/inrYhnUQVyorAit7KtO3lZYfrx5I2ivpM8ef26lLWpwTkEMSOWoZwl95QN7Bk7lQSn+ME7p6HDHatwgdHU5ngJO3cQBdPOeSVtVT/TRQrt0trlUGYaPWta+az9GcqiY6vlx+fxZ3zNwb1CMy8WcUBG5BJe9DNjng3nC9bgUFq9BdXyTu0opGcdMdi6ehSl87g== 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=T6yJJH5ZhT84PCuYIi31YHlDdWVU0C1ZXEE/+H9/cH8=; b=UUvxfRADlVbR61FpLwHMotDdstYMkcqis3LTcluIv+iCPhatTFiMWxQAZQCdS4k3JbftIVC9SlLrIqH1eG+yAQdLPnqopNlSj0E+EfgGhLQZnvgOZdVy1tAmjaGFLXO3Fc5cEH/dH8pKIIV/MAvRU2mfa+7Hoybpeu42F094Kpc= Received: from AM6PR0202MB3413.eurprd02.prod.outlook.com (52.133.30.28) by AM6PR0202MB3381.eurprd02.prod.outlook.com (52.133.28.30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2408.24; Tue, 5 Nov 2019 12:43:48 +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.024; Tue, 5 Nov 2019 12:43:48 +0000 From: Alexandru Stefan ISAILA To: "xen-devel@lists.xenproject.org" Thread-Topic: [PATCH V1 2/2] x86/mm: Make use of the default access param from xc_altp2m_create_view Thread-Index: AQHVk9arLQo4LWM9kUCPbXccC8LyKw== Date: Tue, 5 Nov 2019 12:43:48 +0000 Message-ID: <20191105124332.4380-2-aisaila@bitdefender.com> References: <20191105124332.4380-1-aisaila@bitdefender.com> In-Reply-To: <20191105124332.4380-1-aisaila@bitdefender.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: AM0PR10CA0014.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:208:17c::24) 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: 0bcaf248-a1de-49f9-627a-08d761edcd9a x-ms-traffictypediagnostic: AM6PR0202MB3381:|AM6PR0202MB3381:|AM6PR0202MB3381: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:1850; x-forefront-prvs: 0212BDE3BE x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(39860400002)(346002)(136003)(366004)(396003)(376002)(199004)(189003)(5660300002)(386003)(6506007)(316002)(107886003)(66556008)(186003)(66476007)(66946007)(6486002)(66066001)(25786009)(6116002)(2616005)(446003)(11346002)(7416002)(66446008)(7736002)(102836004)(64756008)(478600001)(26005)(476003)(3846002)(305945005)(6916009)(99286004)(6512007)(2351001)(76176011)(81166006)(52116002)(36756003)(5640700003)(86362001)(1076003)(14454004)(4326008)(486006)(8676002)(71190400001)(71200400001)(50226002)(14444005)(256004)(8936002)(2501003)(2906002)(6436002)(81156014)(54906003); DIR:OUT; SFP:1102; SCL:1; SRVR:AM6PR0202MB3381; 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: RH4yG6K6Lm+2p0CwuUWOC//iMT3IEREK2SdfY4DWPOmTYH33+i8b6vjDjxniVd2j1t11rg4JUQfl6bKYmOMAIlifmOkTFAM6f8t6BJTlppIB2K+cqjEJzpSuVyRW7eZJTQihDoDfbbnrAxNdljB8vcuxxsBdh5CM20ee+4zeXgARiyw4ve64fTyxSsID1jrBeW/y3qDyMEBJzAN6pzTUMvXQFvYNoehfQWFjh3vLYOfIZ3fBcIZZamiczbkNOCvdjy9Y8PfB30HBVs2NhhBfUTe3lia4JvyVPZ6yP0FtFBlurBS6zTYb1R6Y2kRDUnsXCgQOu7VJVH3XLK3OSufNCChJ1gY/FslefmeL4erysXS500zUac9wCgonRCDqA7B6FALYNRC5DhHHU7Ev4a+3SLLnWXUa6iyUp+bruq01cR/nNPMZE9jV4IjMvqIS9tce MIME-Version: 1.0 X-OriginatorOrg: bitdefender.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0bcaf248-a1de-49f9-627a-08d761edcd9a X-MS-Exchange-CrossTenant-originalarrivaltime: 05 Nov 2019 12:43:48.3203 (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: jjdFsH0PxK+0FzlsuyTjdXI4Ek2LnUzDbBJ7gxjp4g4TVastdzl91zAD/OoegqtAEV9lbRRjY4RJW/tlk138ytuYdlbdUWnPWc80jr20u4k= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR0202MB3381 Subject: [Xen-devel] [PATCH V1 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 d3d9f8c30f..1239e4cbf0 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 b2e63e75ff..c07e369359 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 bccfc45a07..67f6f45610 100644 --- a/xen/include/public/hvm/hvm_op.h +++ b/xen/include/public/hvm/hvm_op.h @@ -241,8 +241,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;