From nobody Sat May 4 07:15:35 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; dmarc=pass(p=reject dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1638874450; cv=none; d=zohomail.com; s=zohoarc; b=LxfS90HoViMSUNosulCbFB51jdLBD2KELyMpyQFEQCNJdCUXs6VOGgCOMSioRUHNHQHRFWR010DNbxfxFmwoqbVeL4rc7ulXorU6J5SrgoUUfglRBQawillGwzWALfCwecuIs70Sb6p5N/q5UQW2DMfn2dTJg+Wu7CLwAmeIFMU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1638874450; 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=aunG+6MbHzXoShzx1GMa0daX74LhjHr6sa51++OleKc=; b=PLOk+TC0lzdIcS/nu9R5iqGvpZAoNAYm3dTC2Ui7jNIIli/8kUI1uCi0UU1nfsMsIGt93igM7zz/ySyHftJfYrueahMk3o5v8ItbtAPtfHuXhTeKQ4fMOiw0L1evP/pOD8PFP7yWU85NV4KgE/a1ZFmSvt+IS+tQlZDmMatV8JY= ARC-Authentication-Results: i=1; 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; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1638874450262150.12364069594548; Tue, 7 Dec 2021 02:54:10 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.240869.417625 (Exim 4.92) (envelope-from ) id 1muY6f-0007bE-KC; Tue, 07 Dec 2021 10:53:57 +0000 Received: by outflank-mailman (output) from mailman id 240869.417625; Tue, 07 Dec 2021 10:53:57 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1muY6f-0007b6-GN; Tue, 07 Dec 2021 10:53:57 +0000 Received: by outflank-mailman (input) for mailman id 240869; Tue, 07 Dec 2021 10:53:56 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1muY6e-0007ZY-Nc for xen-devel@lists.xenproject.org; Tue, 07 Dec 2021 10:53:56 +0000 Received: from esa1.hc3370-68.iphmx.com (esa1.hc3370-68.iphmx.com [216.71.145.142]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id f833264e-574b-11ec-a831-37629979565c; Tue, 07 Dec 2021 11:53:55 +0100 (CET) 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: f833264e-574b-11ec-a831-37629979565c DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1638874435; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=D7++fhzoY5NWbD5Y83bEMQFPNo1ym85KhSzs/zIuiyA=; b=KMq8qKoGhEuT348bBaBD3sOHdQ6bv1epIGNHTWRiubxFsYFUNpEwPN+H Ow68ONU5mr0kVfFdctEb3/IDfODkjRiHdoooxx7cRFzWSeG7pnIrPVGds 1qCS5EE/exAJg6cGAoWs0sjOAUa/F5ZnidjyMQ+Kgo801sKQPCO4lSvk9 I=; Authentication-Results: esa1.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none IronPort-SDR: dt+gcHzbw+IghTrs6Y9yWDtVdrHZ0IJqqCQqaeELLI4qBa1p96yxj6egxuJL7bJGOtyNpqeMt+ HXF/LLsI/fW2+c1hu3dngvRPjNqqwsCafgCGiV4dOr9zbUIIqyCk3MxpeWU09Yg+DTGXyccYJd KUXeiTA3BSxwgo8WuQA7HniXVfAOJwdylK7H9b6n2pDT2TWuJIMnA/CqQTf85bbwCyvbhn+mR3 EIE9Mf2uSn6Fh352VK0uBXU9efhA/yzYD7cDq6IJawDrqCYYiUEdkUdpg9f3uVHb8cOmBzvquY Qh8P8qVn81GeJRuZn0ewaqvS X-SBRS: 5.1 X-MesageID: 59828125 X-Ironport-Server: esa1.hc3370-68.iphmx.com X-Remote-IP: 162.221.156.83 X-Policy: $RELAYED IronPort-Data: A9a23:RZs2naIKuMu/DqCxFE+R6JIlxSXFcZb7ZxGr2PjKsXjdYENS0zMHz WcbUD3VOf7fZWH9eI93PY7n/B4OsJXdzt9jG1RlqX01Q3x08seUXt7xwmUcns+xwm8vaGo9s q3yv/GZdJhcokcxIn5BC5C5xZVG/fjgqoHUVaiUZUideSc+EH140Eg7xLZj6mJVqYPR7z2l6 IuaT/L3YDdJ6xYsWo7Dw/vewP/HlK2aVAIw5jTSV9gS1LPtvyB94KYkDbOwNxPFrrx8RYZWc QphIIaRpQs19z91Yj+sfy2SnkciGtY+NiDW4pZatjTLbrGvaUXe345iXMfwZ3u7hB2ErsE29 9dG7qWcbiEgYZ/dvPQsDjRhRnQW0a1uoNcrIFC6uM2XiUbHb2Ht07NlC0Re0Y8wo7gtRzsUr LpBdW5LPkvra+GemdpXTsFFgMg5IdatF4QYonx6lhnSDOo8QICFSKLPjTNd9Gph1poeRKyDD yYfQWVXVBj4JDxCBnwoK5IOhuSVpnzVbTIN/Tp5ooJoujOOnWSdyoPFL979atGMA8JPkS6wh EjL4mD4CREyL8GExHyO9XfErv/Cm2b3VZwfEJW89+V2mxuDy2oLEhoUWFCn5/6jhSaDt8l3c hJOvHB09O5rqRLtHoKVswCETGCssy8NHOVSGLYDxCarw/Xm8iKJNzUpd2sUADA5j/MeSTsv3 16PutrmAz1zrbGYIU6gGqeoQSCaYnZMczJbDcMQZU5cuoS4/tlv5v7aZo87SPbdszHjJd3nL 9lmRgAajq5bs8ME3r7TEbvv02P1/cihouLYC2zqsoOZAuFRON/Ni2+AswGzARN8wGGxFAbpg ZT8s5LChN3i9LnU/MB3fM0DHauy+9GOOyDGjFhkEvEJrmr2qy76I94Iumkiei+F1/ronhezP yfuVf55vscPbBNGk4cpC25ONyja5fe5Tom0PhwlRtFPfoJwZGe6ENJGPiatM5TWuBF0y8kXY M7DGe71VCpyIfk3nVKeGrZGuZd2l39W+I8mbc2ip/hR+eHFPyD9pHZsGAbmU93VG4vY+liIq IgGaJPRo/idOcWnChTqHUcoBQhiBRAG6Vre8KS7r8aPfVhrHn8PEfjUze9zcoBphf0NxOzJ4 mu8SglTz1+m3S/LLgCDa3ZCbrLzXMkg8SJnbHJ0ZVv4iWI+ZYuP7bsEc8dld7cQ6+E+n+V/S OMIepvcD60XGCjH4TkUcbL0sJdmKEawnQuLMif8OGo/cpdsShbn4NjhegezpiACAjDu7Zk1o qG61xOdSp0GHlwwAMHTYfOp7lWwoXlCx74iAxqWeoFeIRy+/pJrJir9iu4MD/sNcRiTlCGH0 wu2AAsDobWfqYEC79SU17uPqJ2kErUiExMCTXXb97u/KQLT4nGnnd1bSO+NcD3QCDH09aGla bkHxv3wKqRazlNDso46GLd316MuodDoouYCnAhjGXzKaXWtC69hfSbajZUe6PUVy+8LoxayV 2KO5sJeaOeAN87SGVIMIBYoM7aY3vYOlziOtfk4LS0WPsOsEGZrhamKAySxtQ== IronPort-HdrOrdr: A9a23:83Ab7qOB6VbppsBcTvmjsMiBIKoaSvp037Eqv3oedfUzSL3gqy nOpoV86faaslYssR0b9exofZPwJE80lqQFhrX5X43SPzUO0VHAROoJgLcKgQeQfxEWntQtrZ uIGJIeNDSfNzdHZL7BkWuFL+o= X-IronPort-AV: E=Sophos;i="5.87,293,1631592000"; d="scan'208";a="59828125" From: Andrew Cooper To: Xen-devel CC: Andrew Cooper , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Wei Liu Subject: [PATCH 1/3] x86/boot: Drop pte_update_limit from physical relocation logic Date: Tue, 7 Dec 2021 10:53:37 +0000 Message-ID: <20211207105339.28440-2-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20211207105339.28440-1-andrew.cooper3@citrix.com> References: <20211207105339.28440-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @citrix.com) X-ZM-MESSAGEID: 1638874452402100001 This check has existed in one form or another since c/s 369bafdb1c1 "xen: B= ig changes to x86 start-of-day" in 2007. Even then, AFAICT, it wasn't necessa= ry because there was a clean split between the statically created entries (L3 = and higher) and the dynamically created ones (L2 and lower). Without dissecting the myriad changes over the past 14 years, I'm pretty certain Xen only booted by accident when l2_xenmap[0] was handled specially and skipped the pte_update_limit check which would have left it corrupt. Nevertheless, as of right now, all non-leaf PTEs (the first loop), and all = 2M xenmap leaf mappings (the second loop) need relocating. They are no unused mappings in the range, no mappings which will be encountered multiple times, and it is unlikely that such mappings would be introduced. Signed-off-by: Andrew Cooper Reviewed-by: Jan Beulich --- CC: Jan Beulich CC: Roger Pau Monn=C3=A9 CC: Wei Liu --- xen/arch/x86/setup.c | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c index c8641c227d9a..0492856292cf 100644 --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -1230,7 +1230,6 @@ void __init noreturn __start_xen(unsigned long mbi_p) l3_pgentry_t *pl3e; l2_pgentry_t *pl2e; int i, j, k; - unsigned long pte_update_limit; =20 /* Select relocation address. */ xen_phys_start =3D end - reloc_size; @@ -1238,14 +1237,6 @@ void __init noreturn __start_xen(unsigned long mbi_p) bootsym(trampoline_xen_phys_start) =3D xen_phys_start; =20 /* - * No PTEs pointing above this address are candidates for relo= cation. - * Due to possibility of partial overlap of the end of source = image - * and the beginning of region for destination image some PTEs= may - * point to addresses in range [e, e + XEN_IMG_OFFSET). - */ - pte_update_limit =3D PFN_DOWN(e); - - /* * Perform relocation to new physical address. * Before doing so we must sync static/global data with main m= emory * with a barrier(). After this we must *not* modify static/gl= obal @@ -1267,8 +1258,7 @@ void __init noreturn __start_xen(unsigned long mbi_p) { /* Not present, 1GB mapping, or already relocated? */ if ( !(l3e_get_flags(*pl3e) & _PAGE_PRESENT) || - (l3e_get_flags(*pl3e) & _PAGE_PSE) || - (l3e_get_pfn(*pl3e) >=3D pte_update_limit) ) + (l3e_get_flags(*pl3e) & _PAGE_PSE) ) continue; *pl3e =3D l3e_from_intpte(l3e_get_intpte(*pl3e) + xen_phys_start); @@ -1277,8 +1267,7 @@ void __init noreturn __start_xen(unsigned long mbi_p) { /* Not present, PSE, or already relocated? */ if ( !(l2e_get_flags(*pl2e) & _PAGE_PRESENT) || - (l2e_get_flags(*pl2e) & _PAGE_PSE) || - (l2e_get_pfn(*pl2e) >=3D pte_update_limit) ) + (l2e_get_flags(*pl2e) & _PAGE_PSE) ) continue; *pl2e =3D l2e_from_intpte(l2e_get_intpte(*pl2e) + xen_phys_start); @@ -1291,8 +1280,7 @@ void __init noreturn __start_xen(unsigned long mbi_p) for ( i =3D 0; i < L2_PAGETABLE_ENTRIES; i++, pl2e++ ) { if ( !(l2e_get_flags(*pl2e) & _PAGE_PRESENT) || - !(l2e_get_flags(*pl2e) & _PAGE_PSE) || - (l2e_get_pfn(*pl2e) >=3D pte_update_limit) ) + !(l2e_get_flags(*pl2e) & _PAGE_PSE) ) continue; =20 *pl2e =3D l2e_from_intpte(l2e_get_intpte(*pl2e) + xen_phys= _start); --=20 2.11.0 From nobody Sat May 4 07:15:35 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; dmarc=pass(p=reject dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1638874452; cv=none; d=zohomail.com; s=zohoarc; b=c1Xl6UjH2ug0S8DlBEA3lJhfLLeu4+rM1f+wQYLOq9Y//UnWcRnvP2mPpjR0zw3IrFvFI0JuVxVRyrizjvI6JAKRPmMzoCdFGJQgfssrX3kdvkmYKfpBHewG//p7hvEPl3l4Rf/JHXWNUeCtyRWtsFl8rKs2kRPnr8DbNMQaCQA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1638874452; 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=uBVn7w/Ki/zS5EtpobjwugNErTEXgxsqCSHsc9ciY+o=; b=nsjsaZ/QsDAiT/83FeBxVE7vZ0SaRaeS/gXyEk0HspXA7zlupWL2whtg0aOEuEXSpaYHCGvhSak3vu3wkzm1NJBTNP/q5cBqo/hKLDxGswrbPvCWK6C8HxpJmlthqkSoypLk5PJ31K8gVCHMH02f/dBT7463alwxLs6OGdayuE8= ARC-Authentication-Results: i=1; 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; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1638874452081996.2987590175336; Tue, 7 Dec 2021 02:54:12 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.240870.417637 (Exim 4.92) (envelope-from ) id 1muY6g-0007sk-U5; Tue, 07 Dec 2021 10:53:58 +0000 Received: by outflank-mailman (output) from mailman id 240870.417637; Tue, 07 Dec 2021 10:53:58 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1muY6g-0007sc-Oi; Tue, 07 Dec 2021 10:53:58 +0000 Received: by outflank-mailman (input) for mailman id 240870; Tue, 07 Dec 2021 10:53:57 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1muY6f-0007ZY-Gr for xen-devel@lists.xenproject.org; Tue, 07 Dec 2021 10:53:57 +0000 Received: from esa3.hc3370-68.iphmx.com (esa3.hc3370-68.iphmx.com [216.71.145.155]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id f840c68d-574b-11ec-a831-37629979565c; Tue, 07 Dec 2021 11:53:55 +0100 (CET) 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: f840c68d-574b-11ec-a831-37629979565c DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1638874435; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=aUo9w7NMA0gJRwpoUWuXtmPLfdUrj41MF7NAi5apEPM=; b=GsExAMTQ4cNOQqKGMnzD5LLbSIYPrxzp3UFpU7jO/4evCmNvgfWGxakC KBXGbkC1D5zrA3YNF/UZqth5O5ynAA6+PnTKOEdW+fUsF/pZtACVtdxQT EznM01ej2YmsEum/HfzClkL5U3QCXkdQFNqREM4INhp7ZfmFcMIw4nVMd w=; Authentication-Results: esa3.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none IronPort-SDR: K5HH7TtBnxror/G2Vpmn5l+DQYHY+lld85s1mk+DyljgLRMN/Csta2bCssmH6EDZ1D5jprrY9D r8SKCVf0CHd7IDbWS3ewrDbnnaJjfLFOX3YA9WE9WyIUtegMUCviYNcwB4ZnLWZNkmheRkfodN lw9EWevD1Cg6h/pxYCEE4dCRBZitbXwDNMhQHmCQuY1zItZlB8vgiZT2TaC8s7/2UZeZpNyRyQ SxdMZGtzSvyTAbsS4b/sDO1h4SGfcgYmprfj+/Hsq+XcR8G1K/B95Hoh2KtpMqyzpAHtE5MtdU BLvDVB6x6zJIu3GKmJc2aRHr X-SBRS: 5.1 X-MesageID: 59450633 X-Ironport-Server: esa3.hc3370-68.iphmx.com X-Remote-IP: 162.221.156.83 X-Policy: $RELAYED IronPort-Data: A9a23:An7c4qhLDtd61D3LX/aIGtBNX161WRcKZh0ujC45NGQN5FlHY01je htvXzuDa63fMWvxedxxa4++/UxVuZLRy4JnTgM+rSA3HyIb9cadCdqndUqhZCn6wu8v7a5EA 2fyTvGacajYm1eF/k/F3oAMKRCQ7InQLlbGILes1htZGEk0F0/NtTo5w7Rg29Qw3oDja++wk YiaT/P3aQfNNwFcagr424rbwP+4lK2v0N+wlgVWicFj5DcypVFMZH4sDfjZw0/DaptVBoaHq 9Prl9lVyI97EyAFUbtJmp6jGqEDryW70QKm0hK6UID66vROS7BbPg/W+5PwZG8O4whlkeydx /1y6Y3udBgLZpHTmcsPdTh1OgheIKZZreqvzXiX6aR/zmXDenrohf5vEFs3LcsT/eMf7WNmr KJCbmpXN1ba2rzwkOnTpupE36zPKOHCOo8Ft24m5jbeFfs8GrjIQrnQ5M8e1zA17ixLNauPO 5dBN2E0BPjGS1pAfVolKspnpbiDr0n6Y2FV8l6rgKVitgA/yyQuieOwYbI5YOeiWsF9jkue4 GXc8AzRIDsXKdiewjqt6W+3i6nEmiaTcJIfEvi0++BnhHWXx3cPE1sGWF2ju/67h0WiHdVFJ CQpFjEG9PZoshbxF5+kAkP+8CXsUgMgt8R4LLErtjyS6PLo/Ae2FE4lYxdoSMEtq5pjLdA17 WOhk9TsDD1plbSaT3OB67uZxQ+P1TgpwXwqPnFdE1ZcizX3iMRq10+UEI4/eEKgpoStQWmY/ tyckMQpa1z/Z+Yv3r7zw13IiinESnPhHl9svVW/so5IA2pEiG+Zi26AtQmzARVodt/xory9U J8swZf20Qz2JcvR/BFhuc1UdF1T296LMSfHnXlkFIQ7+jKm9haLJN4LsGEnehkxaJ5YJ1cFh XM/XisLu/du0IaCN/crM+pd9ex0pUQfKTgVfq+NNYcfCnSAXASG4DtvdSatM5PFyyARfVUEE c7DK66EVC9CYYw+lWbeb7pNgNcDm3FlrUuOFM+T8vhS+efHDJJjYexeawXmgyFQxP7snTg5B P4DbZbXkEsGD7WlCsQVmKZKRW03wbEALcieg6RqmiSre2KKwUktVK3cx60PYYtgk/gHn+vE5 CjlCERZ1ED+lTvMLgDTMiJvb7bmXJBeq3MnPHNzYQb0iiZ7OYv/vr0Cc5YXfKU88LAxx/BDU PRYKd6LBe5CS2qb9m1FP4X9toFraD+imRmKY3i+eDE6cpM5H17J99bocxHB7i4LCibr58Iyr 6f5jlHQQIYZRhQkB8HTMar9w1S0tHkbueRzQ0qXfYUDJBSyqNBncnWjgOU2LscALQT46gGbj wvGUw0FoeTtopMu9IWbj66zsIr0QfB1GVBXHjeH4O/uZzXa5Geq3aRJTP2MIWLGTGrx9aivO bdVwvX7PKFVlVpGqdMhQbNizKZ47Nrzvb5KiA9jGSyTPVisD7phJFiA3NVO6fIRluMI51PuV xLd4MReNJWIJNjhQQwYKwcSZ+ie0e0Zx2vJ5vMvLUSmvCJ68dJri6mJ08VgXMCFEIZIDQ== IronPort-HdrOrdr: A9a23:e/zODanN99YMCd+BDK2sanFgIwXpDfLW3DAbv31ZSRFFG/Fw9/ rCoB3U73/JYVcqKRUdcLW7UpVoLkmyyXcY2+cs1NSZLWzbUQmTXeJfBOLZqlWNJ8SXzIVgPM xbAspD4bPLbGSTjazBkXSF+9RL+qj6zEh/792usEuETmtRGt9dBx8SMHf9LqXvLjM2fqbQEv Cnl6x6jgvlQ1s7ROKhCEIIWuDSzue77q4PMXY9dmcaABDlt0LR1ILH X-IronPort-AV: E=Sophos;i="5.87,293,1631592000"; d="scan'208";a="59450633" From: Andrew Cooper To: Xen-devel CC: Andrew Cooper , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Wei Liu Subject: [PATCH 2/3] x86/boot: Drop move_memory() and use memcpy() directly Date: Tue, 7 Dec 2021 10:53:38 +0000 Message-ID: <20211207105339.28440-3-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20211207105339.28440-1-andrew.cooper3@citrix.com> References: <20211207105339.28440-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @citrix.com) X-ZM-MESSAGEID: 1638874452785100003 The way move_memory() sets up the virtual mappings means that there are alw= ays two non-overlapping regions. The virtual layout means that memmove()'s forward/backwards check doesn't do what the caller intends, as the check ou= ght to be performed in physical space rather than virtual. Luckily both callers already provide non-overlapping mappings, so this bug doesn't manifest, and we can move to memcpy() to avoid a backwards copy. Backwards rep movs's are typically far slower than forwards copies. Furthermore, both callers already have suitable directmap mappings. There = is no need to spend time managing early boot mappings, or chunking the copy through them. For the main Xen relocation, we can read out of the virtual mapping that we= 're executing on, and write directly into the directmap. In fact, this removes one dependency on Xen being "at 0" (the XEN_IMG_OFFSET passed as src) for relocation to occur. For the module relocation, just transcribe the move_memory() call into an equivalent memcpy(). Signed-off-by: Andrew Cooper --- CC: Jan Beulich CC: Roger Pau Monn=C3=A9 CC: Wei Liu --- xen/arch/x86/setup.c | 58 +++++-------------------------------------------= ---- 1 file changed, 5 insertions(+), 53 deletions(-) diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c index 0492856292cf..a6ff450daab7 100644 --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -413,53 +413,6 @@ void *__init bootstrap_map(const module_t *mod) return ret; } =20 -static void *__init move_memory( - uint64_t dst, uint64_t src, unsigned int size, bool keep) -{ - unsigned int blksz =3D BOOTSTRAP_MAP_LIMIT - BOOTSTRAP_MAP_BASE; - unsigned int mask =3D (1L << L2_PAGETABLE_SHIFT) - 1; - - if ( src + size > BOOTSTRAP_MAP_BASE ) - blksz >>=3D 1; - - while ( size ) - { - module_t mod; - unsigned int soffs =3D src & mask; - unsigned int doffs =3D dst & mask; - unsigned int sz; - void *d, *s; - - mod.mod_start =3D (src - soffs) >> PAGE_SHIFT; - mod.mod_end =3D soffs + size; - if ( mod.mod_end > blksz ) - mod.mod_end =3D blksz; - sz =3D mod.mod_end - soffs; - s =3D bootstrap_map(&mod); - - mod.mod_start =3D (dst - doffs) >> PAGE_SHIFT; - mod.mod_end =3D doffs + size; - if ( mod.mod_end > blksz ) - mod.mod_end =3D blksz; - if ( sz > mod.mod_end - doffs ) - sz =3D mod.mod_end - doffs; - d =3D bootstrap_map(&mod); - - memmove(d + doffs, s + soffs, sz); - - dst +=3D sz; - src +=3D sz; - size -=3D sz; - - if ( keep ) - return size ? NULL : d + doffs; - - bootstrap_map(NULL); - } - - return NULL; -} - #undef BOOTSTRAP_MAP_LIMIT =20 static uint64_t __init consider_modules( @@ -1243,7 +1196,7 @@ void __init noreturn __start_xen(unsigned long mbi_p) * data until after we have switched to the relocated pagetabl= es! */ barrier(); - move_memory(e, XEN_IMG_OFFSET, _end - _start, 1); + memcpy(__va(__pa(_start)), _start, _end - _start); =20 /* Walk idle_pg_table, relocating non-leaf entries. */ pl4e =3D __va(__pa(idle_pg_table)); @@ -1300,8 +1253,6 @@ void __init noreturn __start_xen(unsigned long mbi_p) "1" (__va(__pa(cpu0_stack))), "2" (STACK_SIZE / 8) : "memory" ); =20 - bootstrap_map(NULL); - printk("New Xen image base address: %#lx\n", xen_phys_start); } =20 @@ -1325,9 +1276,10 @@ void __init noreturn __start_xen(unsigned long mbi_p) (headroom || ((end - size) >> PAGE_SHIFT) > mod[j].mod_start) ) { - move_memory(end - size + headroom, - (uint64_t)mod[j].mod_start << PAGE_SHIFT, - mod[j].mod_end, 0); + memcpy(__va(end - size + headroom), + __va((uint64_t)mod[j].mod_start << PAGE_SHIFT), + mod[j].mod_end); + mod[j].mod_start =3D (end - size) >> PAGE_SHIFT; mod[j].mod_end +=3D headroom; mod[j].reserved =3D 1; --=20 2.11.0 From nobody Sat May 4 07:15:35 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; dmarc=pass(p=reject dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1638874460; cv=none; d=zohomail.com; s=zohoarc; b=MkGEyCgXVniVjSyxjAPtUafn3C/9RUNAWWj8Zbah8vHIftCbwPzM7Rd0D6jAJeqngc6YSblWd714w+5/S749zmeNWLrwOQqQahAJbPC2kIvj2m9SlO1VMLihOQaj4feIIvrE4HNINu7Ky7pMWVjnymhLL/rHAwB0ecSCMPSPNjY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1638874460; 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=eh5kclOP2Fig+qgY1g+ClqOgJrbhcCABejmPXedKPv4=; b=L3M1FYbynyseXGkGV0bwkMPyKSK06841/IzBpDcdoo5F/32A6GbVJ8K4UgadNsvDS0Um5UVNhhcC5dnL3VVzV0BZPz0Jel3jjTzrm2A0VaPXYf3gDlxByW7WLELGK5lIqVey2tQur0G7DZxwifA59MtqZ+q8sqGaAIzRnf56r9I= ARC-Authentication-Results: i=1; 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; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1638874460121889.5399654647996; Tue, 7 Dec 2021 02:54:20 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.240875.417659 (Exim 4.92) (envelope-from ) id 1muY6o-0000Bo-L2; Tue, 07 Dec 2021 10:54:06 +0000 Received: by outflank-mailman (output) from mailman id 240875.417659; Tue, 07 Dec 2021 10:54:06 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1muY6o-0000B6-Gb; Tue, 07 Dec 2021 10:54:06 +0000 Received: by outflank-mailman (input) for mailman id 240875; Tue, 07 Dec 2021 10:54:05 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1muY6n-0007ZY-IQ for xen-devel@lists.xenproject.org; Tue, 07 Dec 2021 10:54:05 +0000 Received: from esa5.hc3370-68.iphmx.com (esa5.hc3370-68.iphmx.com [216.71.155.168]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id fd4fab96-574b-11ec-a831-37629979565c; Tue, 07 Dec 2021 11:54:04 +0100 (CET) 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: fd4fab96-574b-11ec-a831-37629979565c DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1638874444; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Fbig8ZrshkFGK596jPWQZGyoDDWpC3fZiJfWDk+IDGU=; b=KIcx92tjufdGfKmXRg09ye9cDaVbXR4t9euHnMx3Km4sUGIBh0rlgDdi adKEEK8etJZXxl9H9IkaLeSb1rqBSDpSUAEF98nM4H5zXE8J2Rstxc5/D NuE2ssFeTMEO2SO7epIeWoRAk8cJOD4d50owB4aJp8o5ApP1ZcS2KkX0R Y=; Authentication-Results: esa5.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none IronPort-SDR: OWEdGLEuOdn8Ms4IOSKYbFVQOki0Azv0nsLgY5gdxuAnngZ4mmE92Lj2m/dnqSkp6smVumcKEK /Uafh8pze9xYxI0w8wK6pG8Y1v0uoTmF6vM7iWTBATByQI6grGG4dYBaNZb8/d5EB3HAjVtgjD 5kaauncSMaQi93aHjUhQda55xmhcz60GJfkKQLYi0oDLYDWhnbi/rFwQHy4tr6MvI3uYOXPHqK CqMTlBGFX8oYFJFyYIPfB3lqSl5VEwlKzhnaLTArd5D6TNmW+1aruXIxQCNYjXpOGEAGaY+4R6 vF2Tsm/DV4MPjFqcPJTjOrpC X-SBRS: 5.1 X-MesageID: 58948462 X-Ironport-Server: esa5.hc3370-68.iphmx.com X-Remote-IP: 162.221.156.83 X-Policy: $RELAYED IronPort-Data: A9a23:t2zT2qMjybxlMUfvrR2dkMFynXyQoLVcMsEvi/4bfWQNrUom0zcDx 2YeDWqBaKmDMWf1ctglboS09BhU6JfSx9c1QQto+SlhQUwRpJueD7x1DKtR0wB+jCHnZBg6h ynLQoCYdKjYdpJYz/uUGuCJQUNUjMlkfZKhTr6bUsxNbVU8En5400o8w7RRbrNA2rBVPSvc4 bsenOWHULOV82Yc3rU8sv/rRLtH5ZweiRtA1rAMTakjUGz2zhH5OKk3N6CpR0YUd6EPdgKMq 0Qv+5nilo/R109F5tpICd8XeGVSKlLZFVDmZna7x8FOK/WNz8A/+v9TCRYSVatYozGooPVIl uxEiYCtVV87PqOVxeEQdzANRkmSPYUekFPGCX22sMjVxEzaaXr8hf5pCSnaP6VBpLwxWzsXs 6VFdnZdNXhvhMrvqF6/YsBqit4uM4/AO4QHt2s75TrYEewnUdbIRKCiCdpwgWdh2pASQ6y2i 8wxSQFfcxH6Oxt0JmgaNbRhlcOvpFWmWmgNwL6SjfVuuDWCpOBr65DyNPLFd9rMQt9a9m66j G/b+2XyAjkBKceSjzGC9xqEluLJ2C/2Ro8WPLm57eJxxk2ewHQJDx8bXkf9puO24nNSQPoGd RZSoHB36/Fvqgr7FbERQiFUvlaAnyE5YoRpGtEm9R3V2KraulucC0wtG2sphMMdiOc6Qjkj1 1msltzvBCByvLD9dU9x5ot4vhvpZ3FLcDZqiTssCFJcvoK9+N1bYgfnF447SMaIYsvJ9SYcK txghAw3nP0tgMECzM1XFniX0mv39vAlouPYjzg7v15JDCslNeZJhKTysDA3CMqsy67DETG8U IAswZT20Qz3JcjleNaxaOsMBqq1wP2OLSfRh1Vid7F4qW/9qyf9I9gKuG0gTKuMDirjUWW2C HI/RCsLvMMDVJdURfEfj32N5zQCkvG7SIWNugH8ZdtSeJlhHDJrDwk1DXN8K1vFyRB2+YlmY M/zWZ/1UR4yVPQ2pBLrFrx1+eJ6mUgDKZb7GMmTI+KPiuHFOhZ4iN4tbTOzUwzOxP/e/ViOr Y8Ab5DiJtc2eLSWXxQ7OLU7dTgiRUXXz7iv8aS7r8aPfVhrHn8PEfjUze9zcoBphf0NxOzJ4 mu8SglTz1+m3S/LLgCDa3ZCbrLzXMkg8SJnbHJ0ZVv4iWI+ZYuP7bsEc8dld7cQ6+E+n+V/S OMIepvcD60XGCjH4TkUcbL0sJdmKEawnQuLMif8OGo/cpdsShbn4NjhegezpiACAjDu7Zk1o qG61xOdSp0GHlwwAMHTYfOp7lWwoXlCx74iAxqWeoFeIRy+/pJrJir9iu4MD/sNcRiTlCGH0 wu2AAsDobWfqYEC79SU17uPqJ2kErUiExMCTXXb97u/KQLT4nGnnd1bSO+NcD3QCDH09aGla bkHxv3wKqRazlNDso46GLd316MuodDoouYCnAhjGXzKaXWtC69hfSbajZUe6PUVy+8LoxayV 2KO5sJeaOeAN87SGVIMIBYoM7aY3vYOlziOtfk4LS0WPsOsEGZrhamKAySxtQ== IronPort-HdrOrdr: A9a23:54NIH6rPXRN33PNiKsPkMKQaV5oTeYIsimQD101hICG8cqSj+f xG+85rrCMc6QxhPk3I9urhBEDtex/hHNtOkOws1NSZLW7bUQmTXeJfBOLZqlWKcUDDH6xmpM NdmsBFeaXN5DNB7PoSjjPWLz9Z+qjkzJyV X-IronPort-AV: E=Sophos;i="5.87,293,1631592000"; d="scan'208";a="58948462" From: Andrew Cooper To: Xen-devel CC: Andrew Cooper , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Wei Liu Subject: [PATCH 3/3] x86/boot: Don't double-copy the stack during physical relocation Date: Tue, 7 Dec 2021 10:53:39 +0000 Message-ID: <20211207105339.28440-4-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20211207105339.28440-1-andrew.cooper3@citrix.com> References: <20211207105339.28440-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @citrix.com) X-ZM-MESSAGEID: 1638874462301100001 cpu0_stack is contained within .data, which means the memcpy() already take= s a snapshot at the start of the critical region. Later, when we switch to the relocated Xen, we do end up losing updates to = the local variables, but that's fine because the only variables we've modified = go out of scope after the printk(). Use this properly to avoid copying the wh= ole stack (32k) a second time. Signed-off-by: Andrew Cooper --- CC: Jan Beulich CC: Roger Pau Monn=C3=A9 CC: Wei Liu Ever so slightly RFC, as it has only had light testing, but I'm confident in the reasoning. --- xen/arch/x86/setup.c | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c index a6ff450daab7..c04c68a09b47 100644 --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -1183,6 +1183,7 @@ void __init noreturn __start_xen(unsigned long mbi_p) l3_pgentry_t *pl3e; l2_pgentry_t *pl2e; int i, j, k; + unsigned long tmp; =20 /* Select relocation address. */ xen_phys_start =3D end - reloc_size; @@ -1193,7 +1194,8 @@ void __init noreturn __start_xen(unsigned long mbi_p) * Perform relocation to new physical address. * Before doing so we must sync static/global data with main m= emory * with a barrier(). After this we must *not* modify static/gl= obal - * data until after we have switched to the relocated pagetabl= es! + * data, or locals that need to survive, until after we have + * switched to the relocated pagetables! */ barrier(); memcpy(__va(__pa(_start)), _start, _end - _start); @@ -1239,18 +1241,21 @@ void __init noreturn __start_xen(unsigned long mbi_= p) *pl2e =3D l2e_from_intpte(l2e_get_intpte(*pl2e) + xen_phys= _start); } =20 - /* Re-sync the stack and then switch to relocated pagetables. = */ + /* + * Switch to relocated pagetables. This also discards updates= to + * any local variables since the memmove() call above, but tha= t's + * fine because we don't use any of them again. + */ asm volatile ( - "rep movsq ; " /* re-sync the stack */ - "movq %%cr4,%%rsi ; " - "andb $0x7f,%%sil ; " - "movq %%rsi,%%cr4 ; " /* CR4.PGE =3D=3D 0 */ - "movq %[pg],%%cr3 ; " /* CR3 =3D=3D new pagetables */ - "orb $0x80,%%sil ; " - "movq %%rsi,%%cr4 " /* CR4.PGE =3D=3D 1 */ - : "=3D&S" (i), "=3D&D" (i), "=3D&c" (i) /* All outputs dis= carded. */ - : [pg] "r" (__pa(idle_pg_table)), "0" (cpu0_stack), - "1" (__va(__pa(cpu0_stack))), "2" (STACK_SIZE / 8) + "mov %%cr4, %[cr4]\n\t" + "andb $~%c[pge], %b[cr4]\n\t" + "mov %[cr4], %%cr4\n\t" /* CR4.PGE =3D 0 */ + "mov %[cr3], %%cr3\n\t" /* CR3 =3D new pagetables */ + "orb $%c[pge], %b[cr4]\n\t" + "mov %[cr4], %%cr4\n\t" /* CR4.PGE =3D 1 */ + : [cr4] "=3D&a" (tmp) /* Could be "r", but "a" makes bette= r asm */ + : [cr3] "r" (__pa(idle_pg_table)), + [pge] "i" (X86_CR4_PGE) : "memory" ); =20 printk("New Xen image base address: %#lx\n", xen_phys_start); --=20 2.11.0 From nobody Sat May 4 07:15:35 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; dmarc=pass(p=reject dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1671221923; cv=none; d=zohomail.com; s=zohoarc; b=CwJjmacpyOuQ+Uj8Pb2+x4Zbu+fMvpqcfq+sYLmymrZ2zF7YaMQ4yjgXF5OJHdGsAKJi+gEZ0GYsrOySbrcONS3K1IdCb3GQK8d7iMfZCsHfVaIaXt4R22DFiG/Q/VSnG4jkGzXJB0I+9Z1Quk2RICaCRg9fdzPenVGJByjfJMU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1671221923; 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=BhtoBFx21MgIi06OxpxWy370Dw0N+mNNt4bqs3MZU/E=; b=FzReTIK78Qe/DAB/unsUNFJ0ucVCo48hYWumkYDirnnMaE+yB268cTBW/btpRorihBcn3+olTFdZJ2cE6QxxHmR0GxpFJK/gf3MHzzsO/5y7mtggNNnxznvE93TazxXlNieSPhywCBBDZ2Op7CcfDc5cSDEVfYonv1475Q5K4aY= ARC-Authentication-Results: i=1; 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; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1671221923763959.8124673243092; Fri, 16 Dec 2022 12:18:43 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.465019.723583 (Exim 4.92) (envelope-from ) id 1p6H9f-0001La-VU; Fri, 16 Dec 2022 20:18:03 +0000 Received: by outflank-mailman (output) from mailman id 465019.723583; Fri, 16 Dec 2022 20:18:03 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1p6H9f-0001LT-SL; Fri, 16 Dec 2022 20:18:03 +0000 Received: by outflank-mailman (input) for mailman id 465019; Fri, 16 Dec 2022 20:18:03 +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 1p6H9f-0001LH-7S for xen-devel@lists.xenproject.org; Fri, 16 Dec 2022 20:18:03 +0000 Received: from esa5.hc3370-68.iphmx.com (esa5.hc3370-68.iphmx.com [216.71.155.168]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id bb6ffae7-7d7e-11ed-91b6-6bf2151ebd3b; Fri, 16 Dec 2022 21:18:00 +0100 (CET) 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: bb6ffae7-7d7e-11ed-91b6-6bf2151ebd3b DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1671221880; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=S6FzN93gtSC3Nd88id0fqMKXDA+tulWU9iDOGYxt1H0=; b=fJzwQsc1Guy47cm009bY5Z1jmqFqYdLuo2ZvQb3tdVnnXsFSKg2pYIhX Zw36XloXzY08xXLZHAp+QWthyfHCKqgd2l9anYJ9GdifEZ/g+LV+uxmVV raD8DhWeY+O69p8cAKDcAXGxX0vIsqhkGhcZX0utocPTG+zCKNlZTFrpG g=; Authentication-Results: esa5.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none X-SBRS: 4.0 X-MesageID: 87781711 X-Ironport-Server: esa5.hc3370-68.iphmx.com X-Remote-IP: 162.221.156.83 X-Policy: $RELAYED IronPort-Data: A9a23:N5LK3qrtzBluVgcG6+RXu5PhPCheBmINZRIvgKrLsJaIsI4StFCzt garIBmFPfiPMDH8ftokYYm0oUgG7J/WyodiTAc5qSA1Qn4W+JuZCYyVIHmrMnLJJKUvbq7FA +Y2MYCccZ9uHhcwgj/3b9ANeFEljfngqoLUUbKCYWYpAFc+E0/NsDo788YhmIlknNOlNA2Ev NL2sqX3NUSsnjV5KQr40YrawP9UlKm06W1wUmAWP6gR5gaEzidNV/rzGInqR5fGatgMdgKFb 76rIIGRpgvx4xorA9W5pbf3GmVirmn6ZFXmZtJ+AsBOszAazsAA+v9T2Mk0MC+7vw6hjdFpo OihgLTrIesf0g8gr8xGO/VQO3kW0aSrY9YrK1Dn2SCY5xWun3cBX5yCpaz5VGEV0r8fPI1Ay RAXACkJQRCbnLqw+bOia8BWt8ICBpnSGoxK7xmMzRmBZRonaZXKQqGM7t5ExjYgwMtJGJ4yZ eJAN2ApNk6ZJUQSZBFHU/rSn8/x7pX7WxRepEiYuuwc5G/LwRYq+LPsLMDUapqBQsA9ckOw9 j2Zrz2mW0hy2Nq3lwbf41n0gP7zjAyiBrgfBZe59sFwjwjGroAUIEJPDgbqyRWjsWahX/pPJ kpS/TAhxYAi+UruQtTjUhmQpH+fogVaS9dWC/c96gyG1uzT+QnxLkouQyNFadcmnNQrXjFs3 ViM9+4FHhQ27ufTEyjEsO7J83XiYkD5MFPuewcdSSQF+8K7prgylzPmdOdlMYTlt/v6TGSYL y+xkAAygLAajMgu3qq9/Ezajz/EmqUlXjLZ9S2MADv7s1oRiJqNItXxtAOFtaoowJOxFAHpg ZQSpySJAAni57mpnTfFfugCFarBCx2tYGyF2g4H83XMGl2QF5+fkWJ4umkWyKRBaJxsldrVj Kj752tsCGd7ZifCUEOOS9vZ5z4W5abhD8/5cfvfc8BDZJN8HCfeon43PxfNgTm3yxlz+U3aB Xt8WZ/8ZUv29Iw9lGbmLwvj+eFDKt8CKZP7GsmgkkXPPUu2b3+JU7YVWGZinchghJ5oVD79q o4FX+PTkkU3bQELSnWPmWLlBQxQfCdT6FGfg5A/S9Nv1SI9QDB4UqaJm+l5E2Gn9owM/tr1E riGchcw4DLCabfvc21mtlgLhGvTYKtC IronPort-HdrOrdr: A9a23:x9Vmm6glD4YQcH+bJ5Yqb+jXLHBQXh4ji2hC6mlwRA09TyX5ra 2TdZUgpHrJYVMqMk3I9uruBEDtex3hHP1OkOss1NWZPDUO0VHARO1fBOPZqAEIcBeOldK1u5 0AT0B/YueAd2STj6zBkXSF+wBL+qj6zEiq792usEuEVWtRGsVdB58SMHfiLqVxLjM2YqYRJd 6nyedsgSGvQngTZtTTPAh/YwCSz+e78q4PeHQ9dmca1DU= X-IronPort-AV: E=Sophos;i="5.96,251,1665460800"; d="scan'208";a="87781711" From: Andrew Cooper To: Xen-devel CC: Andrew Cooper , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Wei Liu Subject: [PATCH v2-ish] x86/boot: Factor move_xen() out of __start_xen() Date: Fri, 16 Dec 2022 20:17:49 +0000 Message-ID: <20221216201749.32164-1-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20211207105339.28440-1-andrew.cooper3@citrix.com> References: <20211207105339.28440-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @citrix.com) X-ZM-MESSAGEID: 1671221924995100001 Partly for clarity because there is a lot of subtle magic at work here. Expand the commentary of what's going on. Also, because there is no need to double copy the stack (32kB) to retrieve local values spilled to the stack under the old alias, when all of the aforementioned local variables are going out of scope anyway. There is also a logic change when walking l2_xenmap[]. The old logic would skip recursing into 4k mappings; this would corrupt Xen if it were used. There are no 4k mappings in l2_xenmap[] this early on boot, so assert the property instead of leaving a latent breakage. Signed-off-by: Andrew Cooper --- CC: Jan Beulich CC: Roger Pau Monn=C3=A9 CC: Wei Liu We probably want to drop PGE from XEN_MINIMAL_CR4. It will simplify several boot paths which don't need to care about global pages, and PGE is conditio= nal anyway now with the PCID support. v2-ish: * Split out previous series. Was previously "x86/boot: Don't double-copy = the stack during physical relocation" reworked to remove the risk of losing local stack updated we might care about. Note that putting a printk() in the critical region wouldn't have worked ev= en with the old logic, and is not a reduction in functionality caused by this patch avoiding the second stack copy. --- xen/arch/x86/setup.c | 178 +++++++++++++++++++++++++++++++----------------= ---- 1 file changed, 108 insertions(+), 70 deletions(-) diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c index 4102aae76dde..830502f2d0d9 100644 --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -467,6 +467,113 @@ static void __init move_memory( } } =20 +static void __init noinline move_xen(void) +{ + l4_pgentry_t *pl4e; + l3_pgentry_t *pl3e; + l2_pgentry_t *pl2e; + unsigned long tmp; + int i, j, k; + + /* + * The caller has selected xen_phys_start, ensuring that the old and n= ew + * locations do not overlap. Make it so. + * + * Prevent the compiler from reordering anything across this point. S= uch + * things will end badly. + */ + barrier(); + + /* + * Copy out of the current alias, into the directmap at the new locati= on. + * This includes a snapshot of the current stack. + */ + memcpy(__va(__pa(_start)), _start, _end - _start); + + /* + * We are now in a critical region. Any write (modifying a global, + * spilling a local to the stack, etc) via the current alias will get = lost + * when we switch to the new pagetables. This even means no printk()'s + * debugging purposes. + * + * Walk the soon-to-be-used pagetables in the new location, relocating= all + * intermediate (non-leaf) entries to point to their new-location + * equivalents. All writes are via the directmap alias. + */ + pl4e =3D __va(__pa(idle_pg_table)); + for ( i =3D 0 ; i < L4_PAGETABLE_ENTRIES; i++, pl4e++ ) + { + if ( !(l4e_get_flags(*pl4e) & _PAGE_PRESENT) ) + continue; + + *pl4e =3D l4e_from_intpte(l4e_get_intpte(*pl4e) + xen_phys_start); + pl3e =3D __va(l4e_get_paddr(*pl4e)); + for ( j =3D 0; j < L3_PAGETABLE_ENTRIES; j++, pl3e++ ) + { + if ( !(l3e_get_flags(*pl3e) & _PAGE_PRESENT) || + (l3e_get_flags(*pl3e) & _PAGE_PSE) ) + continue; + + *pl3e =3D l3e_from_intpte(l3e_get_intpte(*pl3e) + xen_phys_sta= rt); + pl2e =3D __va(l3e_get_paddr(*pl3e)); + for ( k =3D 0; k < L2_PAGETABLE_ENTRIES; k++, pl2e++ ) + { + if ( !(l2e_get_flags(*pl2e) & _PAGE_PRESENT) || + (l2e_get_flags(*pl2e) & _PAGE_PSE) ) + continue; + + *pl2e =3D l2e_from_intpte(l2e_get_intpte(*pl2e) + xen_phys= _start); + } + } + } + + /* + * Walk the soon-to-be-used l2_xenmap[], relocating all the leaf mappi= ngs + * so text/data/bss etc refer to the new location in memory. + */ + pl2e =3D __va(__pa(l2_xenmap)); + for ( i =3D 0; i < L2_PAGETABLE_ENTRIES; i++, pl2e++ ) + { + if ( !(l2e_get_flags(*pl2e) & _PAGE_PRESENT) ) + continue; + + /* + * We don't have 4k mappings in l2_xenmap[] at this point in boot,= nor + * is this anticipated to change. Simply assert the fact, rather = than + * introducing dead logic to decend into l1 tables. + */ + ASSERT(l2e_get_flags(*pl2e) & _PAGE_PSE); + + *pl2e =3D l2e_from_intpte(l2e_get_intpte(*pl2e) + xen_phys_start); + } + + /* + * Switch to relocated pagetables, shooting down global mappings as we= go. + */ + asm volatile ( + "mov %%cr4, %[cr4]\n\t" + "andb $~%c[pge], %b[cr4]\n\t" + "mov %[cr4], %%cr4\n\t" /* CR4.PGE =3D 0 */ + "mov %[cr3], %%cr3\n\t" /* CR3 =3D new pagetables */ + "orb $%c[pge], %b[cr4]\n\t" + "mov %[cr4], %%cr4\n\t" /* CR4.PGE =3D 1 */ + : [cr4] "=3D&a" (tmp) /* Could be "r", but "a" makes better asm */ + : [cr3] "r" (__pa(idle_pg_table)), + [pge] "i" (X86_CR4_PGE) + : "memory" ); + + /* + * End of the critical region. Updates to locals and globals now work= as + * expected. + * + * Updates to local variables which have been spilled to the stack sin= ce + * the memcpy() have been lost. But we don't care, because they're all + * going out of scope imminently. + */ + + printk("New Xen image base address: %#lx\n", xen_phys_start); +} + #undef BOOTSTRAP_MAP_LIMIT =20 static uint64_t __init consider_modules( @@ -1255,81 +1362,12 @@ void __init noreturn __start_xen(unsigned long mbi_= p) */ if ( (end > s) && (end - reloc_size + XEN_IMG_OFFSET >=3D __pa(_en= d)) ) { - l4_pgentry_t *pl4e; - l3_pgentry_t *pl3e; - l2_pgentry_t *pl2e; - int i, j, k; - /* Select relocation address. */ xen_phys_start =3D end - reloc_size; e =3D xen_phys_start + XEN_IMG_OFFSET; bootsym(trampoline_xen_phys_start) =3D xen_phys_start; =20 - /* - * Perform relocation to new physical address. - * Before doing so we must sync static/global data with main m= emory - * with a barrier(). After this we must *not* modify static/gl= obal - * data until after we have switched to the relocated pagetabl= es! - */ - barrier(); - memcpy(__va(__pa(_start)), _start, _end - _start); - - /* Walk idle_pg_table, relocating non-leaf entries. */ - pl4e =3D __va(__pa(idle_pg_table)); - for ( i =3D 0 ; i < L4_PAGETABLE_ENTRIES; i++, pl4e++ ) - { - if ( !(l4e_get_flags(*pl4e) & _PAGE_PRESENT) ) - continue; - *pl4e =3D l4e_from_intpte(l4e_get_intpte(*pl4e) + - xen_phys_start); - pl3e =3D __va(l4e_get_paddr(*pl4e)); - for ( j =3D 0; j < L3_PAGETABLE_ENTRIES; j++, pl3e++ ) - { - /* Not present, 1GB mapping, or already relocated? */ - if ( !(l3e_get_flags(*pl3e) & _PAGE_PRESENT) || - (l3e_get_flags(*pl3e) & _PAGE_PSE) ) - continue; - *pl3e =3D l3e_from_intpte(l3e_get_intpte(*pl3e) + - xen_phys_start); - pl2e =3D __va(l3e_get_paddr(*pl3e)); - for ( k =3D 0; k < L2_PAGETABLE_ENTRIES; k++, pl2e++ ) - { - /* Not present, PSE, or already relocated? */ - if ( !(l2e_get_flags(*pl2e) & _PAGE_PRESENT) || - (l2e_get_flags(*pl2e) & _PAGE_PSE) ) - continue; - *pl2e =3D l2e_from_intpte(l2e_get_intpte(*pl2e) + - xen_phys_start); - } - } - } - - /* Walk l2_xenmap[], relocating 2M superpage leaves. */ - pl2e =3D __va(__pa(l2_xenmap)); - for ( i =3D 0; i < L2_PAGETABLE_ENTRIES; i++, pl2e++ ) - { - if ( !(l2e_get_flags(*pl2e) & _PAGE_PRESENT) || - !(l2e_get_flags(*pl2e) & _PAGE_PSE) ) - continue; - - *pl2e =3D l2e_from_intpte(l2e_get_intpte(*pl2e) + xen_phys= _start); - } - - /* Re-sync the stack and then switch to relocated pagetables. = */ - asm volatile ( - "rep movsq ; " /* re-sync the stack */ - "movq %%cr4,%%rsi ; " - "andb $0x7f,%%sil ; " - "movq %%rsi,%%cr4 ; " /* CR4.PGE =3D=3D 0 */ - "movq %[pg],%%cr3 ; " /* CR3 =3D=3D new pagetables */ - "orb $0x80,%%sil ; " - "movq %%rsi,%%cr4 " /* CR4.PGE =3D=3D 1 */ - : "=3D&S" (i), "=3D&D" (i), "=3D&c" (i) /* All outputs dis= carded. */ - : [pg] "r" (__pa(idle_pg_table)), "0" (cpu0_stack), - "1" (__va(__pa(cpu0_stack))), "2" (STACK_SIZE / 8) - : "memory" ); - - printk("New Xen image base address: %#lx\n", xen_phys_start); + move_xen(); } =20 /* Is the region suitable for relocating the multiboot modules? */ --=20 2.11.0 From nobody Sat May 4 07:15:35 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; dmarc=pass(p=reject dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1670622224; cv=none; d=zohomail.com; s=zohoarc; b=XCR2XVTi4avyG0BEVJE01HBeS2ynW66Jc0Y3b+glNH8WvWFpdPlNav8y1sSj5BcWUYuKIRHlXnK3/d/GxbRwpL38FMMkDCMWl0+mcywsm7fyFI+wDRhw/EUGMmfLfXC2W7tz0l9gEUN3QdBrMfJguYF3WrPIGmZ2ZIv6BJbPIl0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1670622224; 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=CnI+XzNMBUheCnND1V1/mZBkxibFSwG+y7QLE2F9HpM=; b=b/7ACXKJz3fQf5Kd2THG5prtw5L5ECYtRq4XngIJJ3YAw5t0OZeBBFp/S/Dd/ZmYI1XMJjG0K4g3M4+W785Q3wlmCbbujVP5+7bFIJlkjAif2zoBDp1FSwzbzcMOuDdTxdmIEMzuzOzGAOEKvAZKahNh+BAIuPI98lqVO1V/i6c= ARC-Authentication-Results: i=1; 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; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1670622224708633.07492493497; Fri, 9 Dec 2022 13:43:44 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.458248.716142 (Exim 4.92) (envelope-from ) id 1p3l96-00044J-D2; Fri, 09 Dec 2022 21:43:04 +0000 Received: by outflank-mailman (output) from mailman id 458248.716142; Fri, 09 Dec 2022 21:43:04 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1p3l96-00044C-A7; Fri, 09 Dec 2022 21:43:04 +0000 Received: by outflank-mailman (input) for mailman id 458248; Fri, 09 Dec 2022 21:43:03 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1p3l94-000445-NU for xen-devel@lists.xenproject.org; Fri, 09 Dec 2022 21:43:03 +0000 Received: from esa6.hc3370-68.iphmx.com (esa6.hc3370-68.iphmx.com [216.71.155.175]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 71c83d76-780a-11ed-8fd2-01056ac49cbb; Fri, 09 Dec 2022 22:42:59 +0100 (CET) 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: 71c83d76-780a-11ed-8fd2-01056ac49cbb DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1670622179; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=FR/SFLoYdR2QkEkTF92LvNk+qsaDxfKWW3VWAuwwPEw=; b=X80owFAInGbR2gVSJDF8s2+4G4xfHEX37/VRebccYml17E1kE6NAcjPs auN7flt1AFERspa7BRPuoNbQgd0v5zR8njJW++WyC5o2HGxo5/clKcvG+ 0QeYiVBeTdfxZMH2skoXydY+npjlFGeStaCIcMHiC3MBPb4PgNJYeSD2k g=; Authentication-Results: esa6.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none X-SBRS: 4.0 X-MesageID: 87162377 X-Ironport-Server: esa6.hc3370-68.iphmx.com X-Remote-IP: 162.221.156.83 X-Policy: $RELAYED IronPort-Data: A9a23:CTNigqjj0yZrnzpMc1LY8hcGX161dRAKZh0ujC45NGQN5FlHY01je htvXG/QM/2Cazf8cttxYY/goxxU7cDQz9BlTVNq+So9FCkb9cadCdqndUqhZCn6wu8v7q5Ex 55HNoSfdpBcolv0/ErF3m3J9CEkvU2wbuOgTrWCYmUpH1QMpB4J0XpLg/Q+jpNjne+3CgaMv cKai8DEMRqu1iUc3lg8sspvkzsy+qWs0N8klgZmP6oS5gePzyJ94K83fsldEVOpGuG4IcbiL wrz5OnR1n/U+R4rFuSknt7TGqHdauePVeQmoiM+t5mK2nCulARrukoIHKN0hXNsoyeIh7hMJ OBl7vRcf+uL0prkw4zxWzEAe8130DYvFLXveRBTuuTLp6HKnueFL1yDwyjaMKVBktubD12i+ tQGKjoLfBOO2tjr2b6mErFr39kjdo70adZ3VnFIlVk1DN4jSJHHBa7L+cVZzHE7gcUm8fT2P pRDL2A1NVKZPkMJagx/5JEWxY9EglHWdTFCpU3Tjq0w+2XJlyR60aT3McqTcduPLSlQthbH/ zycpDumav0cHP2h2xzV41P0vd/ognn8XJM4H5C39PE/1TV/wURMUUZLBDNXu8KRlUqWS99Zb UsO9UIGj4I/6UiqRdnVRACjrTiPuRt0c8pdFag25R+AzoLQ4h2FHS4UQzhZctskucQqAzsw2 Te0c8jBXGI19ufPEDTEq+nS/Wja1TUpwXEqey0OSxkG7oTZ/Zg/k0qXSY9+EPTykYigcd3v+ AyioC87jrQVqMcE0aSn4FzK6w6RSoj1oh0dvVuOAD/8hu9tTMv8PtHztwCHhRpVBNzBJmRtq kTojCR3AAomKZiW3BKAT+wWdF1Cz6bUaWaM6bKD8nRIythMx5JBVdoIiN2dDB0zWirhRdMOS BG7hO+pzMUPVEZGlIcuC25LN+wkzLL7CfPuXe3OY9xFb/BZLVHYpH83PR7JhT+3zCDAdJ3T3 r/CIa6R4YsyU/w7nFJauc9CuVPU+szO7TyKHs2qp/hW+bGfeGSUWd843KimN4gEAFe/iFyNq b53bpLaoyizpcWiOkE7B6ZPdwFVRZX6bLiqw/FqmhmreVQ2QDF+UK6ImdvMueVNxsxoqwsBx VnlMmcw9bY1rSevxdmiApy7VI7SYA== IronPort-HdrOrdr: A9a23:xTJRVqo9KGRopjwIEevml5IaV5oteYIsimQD101hICG8cqSj+P xG+85rsyMc6QxhP03I9urgBEDtex7hHNtOkOss1NSZLW3bUQmTTL2KhLGKq1aLJ8S9zJ856U 4JSdkGNDSaNzZHZKjBjDVQa+xQo+W6zA== X-IronPort-AV: E=Sophos;i="5.96,232,1665460800"; d="scan'208";a="87162377" From: Andrew Cooper To: Xen-devel CC: Andrew Cooper , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Wei Liu Subject: [PATCH v2-ish] x86/boot: Relocate Xen using memcpy() directly Date: Fri, 9 Dec 2022 21:42:44 +0000 Message-ID: <20221209214244.17965-1-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20211207105339.28440-1-andrew.cooper3@citrix.com> References: <20211207105339.28440-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @citrix.com) X-ZM-MESSAGEID: 1670622227125100001 We can relocate Xen by reading out of the virtual mapping that we're execut= ing on, and write directly into the directmap. In fact, this removes one dependency on Xen being "at 0" (the XEN_IMG_OFFSET passed as src) for relocation to occur. This removes all the temporary pagetable handling under the covers of move_memory(), and results in a forward copy rather than a chunked backwards copy (caused by move_memory() always constructing src and dst in a way to trigger memmove() to copy backwards). With the penultimate caller of move_memory() dropped, clean up the API. Dr= op the keep boolean, folding in 0 from the final caller, and drop the return address which has been unused since c/s 0b76ce20de85 ("x86/setup: don't relocate the VGA hole.") in 2007. Signed-off-by: Andrew Cooper Reviewed-by: Jan Beulich --- CC: Jan Beulich CC: Roger Pau Monn=C3=A9 CC: Wei Liu v2-ish: * Split out previous series. This was the "easy to shuffle" work that sti= ll gets a win. Everything else I'm going to rework differently, so will ha= ve to be deferred for now. --- xen/arch/x86/setup.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c index 6bb5bc7c84be..4102aae76dde 100644 --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -425,8 +425,8 @@ void *__init bootstrap_map(const module_t *mod) return ret; } =20 -static void *__init move_memory( - uint64_t dst, uint64_t src, unsigned int size, bool keep) +static void __init move_memory( + uint64_t dst, uint64_t src, unsigned int size) { unsigned int blksz =3D BOOTSTRAP_MAP_LIMIT - BOOTSTRAP_MAP_BASE; unsigned int mask =3D (1L << L2_PAGETABLE_SHIFT) - 1; @@ -463,13 +463,8 @@ static void *__init move_memory( src +=3D sz; size -=3D sz; =20 - if ( keep ) - return size ? NULL : d + doffs; - bootstrap_map(NULL); } - - return NULL; } =20 #undef BOOTSTRAP_MAP_LIMIT @@ -1277,7 +1272,7 @@ void __init noreturn __start_xen(unsigned long mbi_p) * data until after we have switched to the relocated pagetabl= es! */ barrier(); - move_memory(e, XEN_IMG_OFFSET, _end - _start, 1); + memcpy(__va(__pa(_start)), _start, _end - _start); =20 /* Walk idle_pg_table, relocating non-leaf entries. */ pl4e =3D __va(__pa(idle_pg_table)); @@ -1334,8 +1329,6 @@ void __init noreturn __start_xen(unsigned long mbi_p) "1" (__va(__pa(cpu0_stack))), "2" (STACK_SIZE / 8) : "memory" ); =20 - bootstrap_map(NULL); - printk("New Xen image base address: %#lx\n", xen_phys_start); } =20 @@ -1361,7 +1354,7 @@ void __init noreturn __start_xen(unsigned long mbi_p) { move_memory(end - size + headroom, (uint64_t)mod[j].mod_start << PAGE_SHIFT, - mod[j].mod_end, 0); + mod[j].mod_end); mod[j].mod_start =3D (end - size) >> PAGE_SHIFT; mod[j].mod_end +=3D headroom; mod[j].reserved =3D 1; --=20 2.11.0