From nobody Fri May 3 01:28:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1583164596; cv=none; d=zohomail.com; s=zohoarc; b=WIfnjRXpY/XdBZ6QDjTt52SpkIvek5tf6bgzags6guT5qKsrNPkeDCnOF/gqiVN1Nmq3isMlYf0sqLwLru+5Oy7oWfJga2hYFcp66COZ6JdmgmpPZ0Rwx2fIbTifUXez7KuUdH/dTxo3ERSh9dOMrsXNV6SN2gdCEsHGPsFXwPQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1583164596; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=v1Z1n7Zyvjnt7U9rIVQbJuLGR7huzYYoB7gPGf8mlZM=; b=Q9hpB3YCbIyNdTe+W7fJI8hGzN7Gsg33bCeod1alv38rATgrwfrXHGKP2Uo4phA3wlypuzwcrnOlVcQwuRndrxi1VaGo6mEH8E9s/Q7i78e0LwlzE4nrBZKJWT5loQ2fovcIQHIPZOE9Q/WzfsBxMpw0ReIwGRKE2ZSWxPgYuWY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1583164596833592.9694128513554; Mon, 2 Mar 2020 07:56:36 -0800 (PST) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1j8nPu-0004EA-K0; Mon, 02 Mar 2020 15:55:38 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1j8nPt-0004E5-A0 for xen-devel@lists.xenproject.org; Mon, 02 Mar 2020 15:55:37 +0000 Received: from esa4.hc3370-68.iphmx.com (unknown [216.71.155.144]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 41691edc-5c9e-11ea-932e-bc764e2007e4; Mon, 02 Mar 2020 15:55:36 +0000 (UTC) X-Inumbo-ID: 41691edc-5c9e-11ea-932e-bc764e2007e4 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1583164536; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=RgqdBUX+c9cqV970cHWW+GqlPnZxNAo1T22Uo5zE7go=; b=SI3YmTN6Eqc5i4vmE1aqYGfkIaw4K190wGBQQKl2Ph7+4HwO9oNePvaX d5RIKGkwJOZgmCEg6yAyMJnnZ/pqYu8lWrZM/hgQp/q+qoDxCV8dmpbPW lM963jNEJ1u0kHgpLpoqNnJnJrevXP+YuTFWHBQS1a9leG5auV08WrCxf U=; Authentication-Results: esa4.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=roger.pau@citrix.com; spf=Pass smtp.mailfrom=roger.pau@citrix.com; spf=None smtp.helo=postmaster@mail.citrix.com Received-SPF: none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Received-SPF: None (esa4.hc3370-68.iphmx.com: no sender authenticity information available from domain of roger.pau@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa4.hc3370-68.iphmx.com; envelope-from="roger.pau@citrix.com"; x-sender="roger.pau@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa4.hc3370-68.iphmx.com: domain of roger.pau@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa4.hc3370-68.iphmx.com; envelope-from="roger.pau@citrix.com"; x-sender="roger.pau@citrix.com"; x-conformance=sidf_compatible; x-record-type="v=spf1"; x-record-text="v=spf1 ip4:209.167.231.154 ip4:178.63.86.133 ip4:195.66.111.40/30 ip4:85.115.9.32/28 ip4:199.102.83.4 ip4:192.28.146.160 ip4:192.28.146.107 ip4:216.52.6.88 ip4:216.52.6.188 ip4:162.221.158.21 ip4:162.221.156.83 ip4:168.245.78.127 ~all" Received-SPF: None (esa4.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa4.hc3370-68.iphmx.com; envelope-from="roger.pau@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: az7A6hgZRkR99j9p/uu5cmmtVOrECAr7YKWsFJoERmip0bU/A2mqZRf6ifTSTmSJ+RTk1hyOSx Yt5Pe+0EjZgrRLaOsPDPMrGraZTrhvmeL9FSFukpOSpRKfDSpaTSNQMr+721T2FnNyP9cMVH0I B+wGczorq1DYOPH+80HxtS8aMhcpLayRR49cn4XarfLdnGoZNL9NL7LsMKi6XdqNNf8X30GTTg KpN2j992zxyRcNSPL+EEa0vaXvKH8Z8xqfVlH78tyTXlfz1b92qLa0oe8t9JVXOiNZ1yGeS7Zs Hog= X-SBRS: 2.7 X-MesageID: 13904351 X-Ironport-Server: esa4.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.70,507,1574139600"; d="scan'208";a="13904351" From: Roger Pau Monne To: Date: Mon, 2 Mar 2020 16:55:09 +0100 Message-ID: <20200302155509.44753-1-roger.pau@citrix.com> X-Mailer: git-send-email 2.25.0 MIME-Version: 1.0 Subject: [Xen-devel] [PATCH] x86/dom0: improve PVH initrd and metadata placement 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: Andrew Cooper , Wei Liu , Jan Beulich , Roger Pau Monne Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Don't assume there's going to be enough space at the tail of the loaded kernel and instead try to find a suitable memory area where the initrd and metadata can be loaded. Reported-by: Andrew Cooper Signed-off-by: Roger Pau Monn=C3=A9 --- xen/arch/x86/hvm/dom0_build.c | 51 ++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/xen/arch/x86/hvm/dom0_build.c b/xen/arch/x86/hvm/dom0_build.c index eded87eaf5..a03bf2e663 100644 --- a/xen/arch/x86/hvm/dom0_build.c +++ b/xen/arch/x86/hvm/dom0_build.c @@ -490,6 +490,44 @@ static int __init pvh_populate_p2m(struct domain *d) #undef MB1_PAGES } =20 +static paddr_t find_memory(const struct domain *d, const struct elf_binary= *elf, + size_t size) +{ + paddr_t kernel_start =3D (paddr_t)elf->dest_base; + paddr_t kernel_end =3D (paddr_t)(elf->dest_base + elf->dest_size); + unsigned int i; + + for ( i =3D 0; i < d->arch.nr_e820; i++ ) + { + paddr_t start, end; + + if ( d->arch.e820[i].addr < MB(1) && + d->arch.e820[i].addr + d->arch.e820[i].size < MB(1) ) + continue; + + start =3D MAX(ROUNDUP(d->arch.e820[i].addr, PAGE_SIZE), MB(1)); + end =3D d->arch.e820[i].addr + d->arch.e820[i].size; + + /* Deal with the kernel being loaded in the region. */ + if ( kernel_start <=3D start && kernel_end >=3D start ) + /* Truncate the start of the region */ + start =3D ROUNDUP(kernel_end, PAGE_SIZE); + else if ( kernel_start <=3D end && kernel_end >=3D end ) + /* Truncate the end of the region */ + end =3D kernel_start; + /* Pick the biggest of the split regions */ + else if ( kernel_start - start > end - kernel_end ) + end =3D kernel_start; + else + start =3D ROUNDUP(kernel_end, PAGE_SIZE); + + if ( end - start >=3D size ) + return start; + } + + return INVALID_PADDR; +} + static int __init pvh_load_kernel(struct domain *d, const module_t *image, unsigned long image_headroom, module_t *initrd, void *image_base, @@ -546,7 +584,18 @@ static int __init pvh_load_kernel(struct domain *d, co= nst module_t *image, return rc; } =20 - last_addr =3D ROUNDUP(parms.virt_kend - parms.virt_base, PAGE_SIZE); + last_addr =3D find_memory(d, &elf, sizeof(start_info) + + initrd ? ROUNDUP(initrd->mod_end, PAGE_SIZE) + + sizeof(mod) + : 0 + + cmdline ? ROUNDUP(strlen(cmdline) + 1, + elf_64bit(&elf) ? 8 : 4) + : 0); + if ( last_addr =3D=3D INVALID_PADDR ) + { + printk("Unable to find a memory region to load initrd and metadata= \n"); + return -ENOMEM; + } =20 if ( initrd !=3D NULL ) { --=20 2.25.0 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel