From nobody Thu Nov 28 11:39:18 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=RiversideResearch.org); dmarc=pass(p=none dis=none) header.from=RiversideResearch.org ARC-Seal: i=2; a=rsa-sha256; t=1670961278; cv=pass; d=zohomail.com; s=zohoarc; b=IUB9zPqXHJ+aBGHHVVNgoHH5zXbMyO1olVgYDEf9mWlrmK9eQZONCaS9T4XEXTDjUDOPKZJ52uvjF6/wJjdQorkGEBwfIXGTM6NmiwtHk+Qbz/HC3S6ddiSa+iastmnP6/F2XjSWGmaV946nsGWlKYqVehrAc6tnpocNAULA9Hg= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1670961278; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=I0hQaAJM6caWYQsVLchpOdKLdgvJiFe099wRxpfgIbQ=; b=YWt8R7L/Z34kraFD6p5tMxt9HJL9Z3UWcQNbdBEtPoqhLcopbYTNFi2YISi8DSUj2Vd8l3kix3s6s6rxm+EWyVz2Kep1I7PhoPuAI3C1TUJyqe43yDKvNtCT3a5qAAbUX1RxiMr3wfItTEXkGIaLFpHO8Wr+HPaMwFES7bB8IF4= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=RiversideResearch.org); dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1670961278667485.64983134411534; Tue, 13 Dec 2022 11:54:38 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.461134.719176 (Exim 4.92) (envelope-from ) id 1p5BLw-0003Yf-I1; Tue, 13 Dec 2022 19:54:12 +0000 Received: by outflank-mailman (output) from mailman id 461134.719176; Tue, 13 Dec 2022 19:54:12 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1p5BLw-0003YY-FN; Tue, 13 Dec 2022 19:54:12 +0000 Received: by outflank-mailman (input) for mailman id 461134; Tue, 13 Dec 2022 19:54:11 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1p5BLv-0003YK-0r for xen-devel@lists.xenproject.org; Tue, 13 Dec 2022 19:54:11 +0000 Received: from USG02-BN3-obe.outbound.protection.office365.us (mail-bn3usg02on0094.outbound.protection.office365.us [23.103.208.94]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id e85604e7-7b1f-11ed-91b6-6bf2151ebd3b; Tue, 13 Dec 2022 20:54:10 +0100 (CET) Received: from BN0P110MB1642.NAMP110.PROD.OUTLOOK.COM (2001:489a:200:185::22) by BN0P110MB1144.NAMP110.PROD.OUTLOOK.COM (2001:489a:200:16c::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.19; Tue, 13 Dec 2022 19:54:07 +0000 Received: from BN0P110MB1642.NAMP110.PROD.OUTLOOK.COM ([fe80::81df:6431:7a2d:4610]) by BN0P110MB1642.NAMP110.PROD.OUTLOOK.COM ([fe80::81df:6431:7a2d:4610%5]) with mapi id 15.20.5880.019; Tue, 13 Dec 2022 19:54:07 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: e85604e7-7b1f-11ed-91b6-6bf2151ebd3b ARC-Seal: i=1; a=rsa-sha256; s=arcselector5401; d=microsoft.com; cv=none; b=O+/0vzajBh+OmvEUVk170fpT1FVhL9xZerkWC9wVoBhm+76ZUfWDDiSq53jgf484a0FCKz7iykqFkUS1g+NzXrBdWOgjdKYTnDBVkOUPqpbcCyIrbTxWfo1+XlATZ+tCexOiqankzhuunFudI9knhUczE7H35F3/nze2i7Uj0oXNp+x7avawrMOx87K2Y/N7pdb7Y8nw62H20CUh629cV8HpGsodfD9bpdoGkXql/0Xure20hcaFD9L1rKSXUCJmhDRXeoomnmhRna9NDsY+OsABU4hgVMtReoHw9HPyfXhf9aalzsDbZWdUboprJoXimBZLAqxn3qL52TYFlIOqmA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector5401; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=I0hQaAJM6caWYQsVLchpOdKLdgvJiFe099wRxpfgIbQ=; b=1CKsVqn1PcNis65wzRqOGVxOjJkHRIBph4jSu8QzQUZppcZ2pg8KDzg6FLmy4XIYVzN8lDeXgN/fIseSD1659V3cUYgszp6f1Dxiczc35cCaqHMCunlQ+TZ/PCMTaqDbQ0jHZoijOO6RXA+3vvkBircDtzU/kEIXsb9EoDXX76yqybIjO32PBgW35nVrH2/y8DpYPhiJV4F40jKQj8bmKl+2uGV9lGDfJ1Hwr6HBBghju6NS9+QwaVG0WEC1HTINSN4/rLcMEShzX7TPoJKvQcIfqtSqypybIJBNbSD58zj/waMQVJ8MjIwd6k56OD75wzEOIt7lFe2lvq22YJvGwA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=riversideresearch.org; dmarc=pass action=none header.from=riversideresearch.org; dkim=pass header.d=riversideresearch.org; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=riversideresearch.org; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=I0hQaAJM6caWYQsVLchpOdKLdgvJiFe099wRxpfgIbQ=; b=KYG33CvJUZs56K0bN5ZPLS9FkDuZEnHLZJeKc1TgVkE+BSmez5lfQTS3nqd1eN4nSk9BW4Obvi6FCO6kLZVUu9xsmUl4LxSx2rkM1J98SOJYSKbXRQz7irM/BCLXuRA2mkIxJ+FbDwiTT79SH11CGRY05URcogiFzMHjWAbKuPMAsG9KH4CyTxjzLoiXeHZu2DKRW7d+RF0gBoUr+gij+ZnSwAQspGI1ibzJ+L6CoUrcpiL+RGK5F7YT/8X/Gt2J0Tget54eb7nJ24jkdY+TEPhKGnEmM6u6EUbs95O6kGYf4uX2gPWkx+00iEkoR7D/Dpj4hihchsBGRvWHkBdPYg== From: "Smith, Jackson" To: "Smith, Jackson" CC: "Brookes, Scott" , Xen-devel , Stefano Stabellini , Julien Grall , "bertrand.marquis@arm.com" , "jbeulich@suse.com" , Andrew Cooper , =?iso-8859-1?Q?Roger_Pau_Monn=E9?= , George Dunlap , "demi@invisiblethingslab.com" , "Daniel P. Smith" , "christopher.w.clark@gmail.com" Subject: [RFC 3/4] Add xen superpage splitting support to arm Thread-Topic: [RFC 3/4] Add xen superpage splitting support to arm Thread-Index: AQHZDyypbad3do/0AUGsmgE77Sct8w== Date: Tue, 13 Dec 2022 19:54:07 +0000 Message-ID: References: In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: suggested_attachment_session_id: a5e26e9e-108f-3533-e10a-338a3d7bfe08 authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=RiversideResearch.org; x-ms-publictraffictype: Email x-ms-traffictypediagnostic: BN0P110MB1642:EE_|BN0P110MB1144:EE_ x-ms-office365-filtering-correlation-id: 5f3813f8-b491-42a9-268d-08dadd43cbde x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: 7XpYaVGp3N8EOCa2JupsF7Ms8g0/3Bm5wueOBuuz2r/8w2s1QH6z466VbVgkaDeBXmlLwsRTczgcTK5zpitTcH185bMmdpWxaPOg/2i/uIUPwajJ+hN4u0odtKoBYCZNGDjn7vg/lX16FQ4vISQU8gFfWPzKC/+bBW1+hod13nVdMKp2XEnqF0JejL8/SsqFG2lyU7IwtZhKn874ERf5p0XJ6A7ww36YLl9t9VZSD+BSE0jW0pUfZ1OMRpaW43+sb0zc9JMIIT3sUbMxh/yFnKJThkv8CSTfdAOoepB3LducXSPJSbAUVIadhekZXyA2S/tR7jNJVTHapb3GEONr9xAfrTCMey7aKMVoqCY1HvFtD/1khO5m90ICpJK5v+q42v84KZhaT2L4eS6rS0kE4hzXjSbQVUp4kS/sUTQ+6Fjkj3yrEOZ2OkIhchk9UzTLIYaPvkh6qXq1NX5vpzRqbX6Yve9UnlGyXgm3UAsVYj3KZPQJBnBcJWtRbHJioH2AKj9s5S+/YdBt1U6waJTT7g4Kltn9lx5UAY3UpwYioqZ/DRF3GpVOZ058lb/f4sXrCOjKUpa3DQi4/S1YvoHwuDiEFOaVUZfHxsOL+RJ7WEu9DkJA0uFV9RV5LepqigCByyf5PazZ5wqD8U0iWbkqtg== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BN0P110MB1642.NAMP110.PROD.OUTLOOK.COM;PTR:;CAT:NONE;SFS:(13230022)(366004)(451199015)(6506007)(83380400001)(7696005)(9686003)(2940100002)(508600001)(2906002)(6200100001)(86362001)(55016003)(33656002)(54906003)(38100700002)(82960400001)(38070700005)(76116006)(71200400001)(66556008)(66476007)(26005)(4326008)(66946007)(64756008)(8676002)(186003)(66446008)(8936002)(7416002)(6862004)(122000001)(5660300002)(52536014)(85282002);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: 32tv+ytXFtOPFk15lgXZU+fK8Ft0ParkAqR3ZHgLV0XCrRfT+TuM4K7OCz0QJEjECOc5Y6wlVu2Mg3SrlvJj5B3BHfk6j+7SQvV9GwP1XwVAliUF+DSRgvM2HmQwXq3e18dnvoxTrzzkoxllX1Fz6jaRD3lkhtujXspxPEQYBC8bmNEvMDAWgTC7TgdQ/L/7UNcuCfziTQmgkgebVo0wXAMMnWlPUD9xr10Ryg8BuRS9pi4aH/b90JZ7O8PHuIAKYt7iTHdd3nc6sjAWT0yvTiS1owoKjsY9FZf+yqmv8fKQfLIsGEx4+2TZId2rOCoIHnTp3Xh2Ktz1HBqbD38o73G9VtYA6F1dm7QpL3s6yMviV0B59QEk0Ce7IC/hZnuTjxK50GUU8erXt1e2jfJykCuvYRQeaqWFYpkRSOMx8LM= Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: riversideresearch.org X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: BN0P110MB1642.NAMP110.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-Network-Message-Id: 5f3813f8-b491-42a9-268d-08dadd43cbde X-MS-Exchange-CrossTenant-originalarrivaltime: 13 Dec 2022 19:54:07.8758 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: bfc64a8d-9064-4c64-91c3-9d10b44c1cb6 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN0P110MB1144 X-ZohoMail-DKIM: pass (identity @riversideresearch.org) X-ZM-MESSAGEID: 1670961280035100001 Content-Type: text/plain; charset="utf-8" Updates xen_pt_update_entry function from xen/arch/arm/mm.c to automatically split superpages as needed. --- xen/arch/arm/mm.c | 91 +++++++++++++++++++++++++++++++++++++++++++++++----= ---- 1 file changed, 78 insertions(+), 13 deletions(-) diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index 6301752..91b9c2b 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -753,8 +753,78 @@ static int create_xen_table(lpae_t *entry) } =20 #define XEN_TABLE_MAP_FAILED 0 -#define XEN_TABLE_SUPER_PAGE 1 -#define XEN_TABLE_NORMAL_PAGE 2 +#define XEN_TABLE_NORMAL_PAGE 1 + +/* More or less taken from p2m_split_superpage, without the p2m stuff */ +static bool xen_split_superpage(lpae_t *entry, unsigned int level, + unsigned int target, const unsigned int *o= ffsets) +{ + struct page_info *page; + lpae_t pte, *table; + unsigned int i; + bool rv =3D true; + + mfn_t mfn =3D lpae_get_mfn(*entry); + unsigned int next_level =3D level + 1; + unsigned int level_order =3D XEN_PT_LEVEL_ORDER(next_level); + + ASSERT(level < target); + ASSERT(lpae_is_superpage(*entry, level)); + + page =3D alloc_domheap_page(NULL, 0); + if ( !page ) + return false; + + table =3D __map_domain_page(page); + + /* + * We are either splitting a first level 1G page into 512 second level + * 2M pages, or a second level 2M page into 512 third level 4K pages. + */ + for ( i =3D 0; i < XEN_PT_LPAE_ENTRIES; i++ ) + { + lpae_t *new_entry =3D table + i; + + /* + * Use the content of the superpage entry and override + * the necessary fields. So the correct permission are kept. + */ + pte =3D *entry; + lpae_set_mfn(pte, mfn_add(mfn, i << level_order)); + + /* + * First and second level pages set walk.table =3D 0, but third + * level entries set walk.table =3D 1. + */ + pte.walk.table =3D (next_level =3D=3D 3); + + write_pte(new_entry, pte); + } + + /* + * Shatter superpage in the page to the level we want to make the + * changes. + * This is done outside the loop to avoid checking the offset to + * know whether the entry should be shattered for every entry. + */ + if ( next_level !=3D target ) + rv =3D xen_split_superpage(table + offsets[next_level], + level + 1, target, offsets); + + clean_dcache_va_range(table, PAGE_SIZE); + unmap_domain_page(table); + + /* + * Generate the entry for this new table we created, + * and write it back in place of the superpage entry. + */ + pte =3D mfn_to_xen_entry(page_to_mfn(page), MT_NORMAL); + pte.pt.table =3D 1; + write_pte(entry, pte); + clean_dcache(*entry); + + return rv; +} =20 /* * Take the currently mapped table, find the corresponding entry, @@ -767,16 +837,15 @@ static int create_xen_table(lpae_t *entry) * XEN_TABLE_MAP_FAILED: Either read_only was set and the entry * was empty, or allocating a new page failed. * XEN_TABLE_NORMAL_PAGE: next level mapped normally - * XEN_TABLE_SUPER_PAGE: The next entry points to a superpage. */ static int xen_pt_next_level(bool read_only, unsigned int level, - lpae_t **table, unsigned int offset) + lpae_t **table, const unsigned int *offsets) { lpae_t *entry; int ret; mfn_t mfn; =20 - entry =3D *table + offset; + entry =3D *table + offsets[level]; =20 if ( !lpae_is_valid(*entry) ) { @@ -790,7 +859,8 @@ static int xen_pt_next_level(bool read_only, unsigned i= nt level, =20 /* The function xen_pt_next_level is never called at the 3rd level */ if ( lpae_is_mapping(*entry, level) ) - return XEN_TABLE_SUPER_PAGE; + /* Shatter the superpage before continuing */ + xen_split_superpage(entry, level, level + 1, offsets); =20 mfn =3D lpae_get_mfn(*entry); =20 @@ -915,7 +985,7 @@ static int xen_pt_update_entry(mfn_t root, unsigned lon= g virt, table =3D xen_map_table(root); for ( level =3D HYP_PT_ROOT_LEVEL; level < target; level++ ) { - rc =3D xen_pt_next_level(read_only, level, &table, offsets[level]); + rc =3D xen_pt_next_level(read_only, level, &table, offsets); if ( rc =3D=3D XEN_TABLE_MAP_FAILED ) { /* @@ -941,12 +1011,7 @@ static int xen_pt_update_entry(mfn_t root, unsigned l= ong virt, break; } =20 - if ( level !=3D target ) - { - mm_printk("%s: Shattering superpage is not supported\n", __func__); - rc =3D -EOPNOTSUPP; - goto out; - } + BUG_ON( level !=3D target ); =20 entry =3D table + offsets[level]; =20 --=20 2.7.4