From nobody Mon May 20 04:53:37 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=1714140130; cv=none; d=zohomail.com; s=zohoarc; b=MR68lvv/WfUnJEAUIMVTwi7egdpD/soNoqFbUPGAQD+OWCAnAv50P/N75DXSrO8AAl6O3qLOdA7UifhMmdh1E+tyr+dLHeHulHXOG6EajfAqaWbfstWbgIWs2vOMrivHHoZpgr8o7NvnFyq5760pcy8pFlCUTtXOZXOXS6drPjk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1714140130; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=fs3g/4u7PsSjEgvku7tHk5LGTz36XpTJalrA46jZNVI=; b=PeqgAbJm3oB+vBb7J7Vmd2hRcDfEcPt2C5GamXSmYU/m1r5FZI2xBckdquMZmyz1mcstTQoTlzaV4l1hfA6t93Mi9sqMiM3c6KE7IOIc+XYZM9O1SyMiYk3thWf62GKn2CB8gjkC5VD5nNgNGOacbFWBhgwbITXu8wKX9KE5Fh0= 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 1714140130024669.1001889895058; Fri, 26 Apr 2024 07:02:10 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.712820.1113678 (Exim 4.92) (envelope-from ) id 1s0M96-0008Rg-So; Fri, 26 Apr 2024 14:01:48 +0000 Received: by outflank-mailman (output) from mailman id 712820.1113678; Fri, 26 Apr 2024 14:01:48 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1s0M96-0008RZ-Q9; Fri, 26 Apr 2024 14:01:48 +0000 Received: by outflank-mailman (input) for mailman id 712820; Fri, 26 Apr 2024 14:01:46 +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 1s0M94-0008CS-QH for xen-devel@lists.xenproject.org; Fri, 26 Apr 2024 14:01:46 +0000 Received: from mail-ej1-x62f.google.com (mail-ej1-x62f.google.com [2a00:1450:4864:20::62f]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 83d2b586-03d5-11ef-b4bb-af5377834399; Fri, 26 Apr 2024 16:01:44 +0200 (CEST) Received: by mail-ej1-x62f.google.com with SMTP id a640c23a62f3a-a587831809eso259910966b.1 for ; Fri, 26 Apr 2024 07:01:44 -0700 (PDT) Received: from andrewcoop.citrite.net (default-46-102-197-194.interdsl.co.uk. [46.102.197.194]) by smtp.gmail.com with ESMTPSA id cd9-20020a170906b34900b00a5264576138sm10646714ejb.35.2024.04.26.07.01.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Apr 2024 07:01:42 -0700 (PDT) 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: 83d2b586-03d5-11ef-b4bb-af5377834399 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1714140104; x=1714744904; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=fs3g/4u7PsSjEgvku7tHk5LGTz36XpTJalrA46jZNVI=; b=mXz57k/0woT2RrscIbN+XoT7vYP4JVv8YhTm85pddcZe7njIhDkvdoKsQtwNLfvTqp s+0QIBHWH6te1AMIWACxU9lJrnfy/5xYWMbIAiymiODbbkZ9iUnIF48iNR4ydyWiiYOd 3+3fO/JZK28okRJNaE1Z7c8Sf4Ep+fiIM5c8Y= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714140104; x=1714744904; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=fs3g/4u7PsSjEgvku7tHk5LGTz36XpTJalrA46jZNVI=; b=NzqjPJpmkv7lHtD2QAvQdPpT+rJSl0e2xP+W3K6UjrACeX9OYuBydD7smzYnEwydvW UozcNh/sCSuAn3FYJt6zzkQl6QVmBEWkx8MFbBszqQ/pEswJvLe06EzdCNOShIfBqosq Og+HFFNZ8xLyraLQDdFfAAQZe4DtWoe+QMsCY8bAtKkXpWbmhxkWSQI5EYAq/BvRa8um ENSele3koC7LJA2vFZnFOqXzhBgovHutF7vw4FTY874sX8CcQ8zoFgb9aGPeq271KDwo UURX7+AdzIqymNlG5AlAonIEJj4M7aSM8+8dVyZykZKEX+FJ8tFJHPRlYi+KK67pl3dB RLug== X-Gm-Message-State: AOJu0YxeD5kUUU8r5gjcM5yBFNwx4RbDncasBfF622FODXST4nsKGH1g JlxyIFyB16qQJ7P5AgwV5X6Ni/gebos4fDeYMMntItcffQVqLWn3q2ogAQ8GHguB83a6ByZwqYQ 9 X-Google-Smtp-Source: AGHT+IHnij1wJjyb1RladpCBx/rNBYm1byBB9qPuEIty9/cYewQBU0Bh7k5PjK1m5Na4Cqrx/KVI3A== X-Received: by 2002:a17:906:4a10:b0:a58:c0da:34a3 with SMTP id w16-20020a1709064a1000b00a58c0da34a3mr2008087eju.33.1714140104031; Fri, 26 Apr 2024 07:01:44 -0700 (PDT) From: Andrew Cooper To: Xen-devel Cc: Andrew Cooper , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Stefano Stabellini , Daniel Smith , Christopher Clark Subject: [PATCH 1/3] x86/boot: Explain how moving mod[0] works Date: Fri, 26 Apr 2024 15:01:38 +0100 Message-Id: <20240426140140.465506-2-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20240426140140.465506-1-andrew.cooper3@citrix.com> References: <20240426140140.465506-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: 1714140131616100001 modules_headroom is a misleading name as it applies strictly to mod[0] only, and the movement loop is deeply unintuitive and completely undocumented. Provide help to whomever needs to look at this code next. Signed-off-by: Andrew Cooper Acked-by: Jan Beulich Reviewed-by: Jason Andryuk --- CC: Jan Beulich CC: Roger Pau Monn=C3=A9 CC: Stefano Stabellini CC: Daniel Smith CC: Christopher Clark --- xen/arch/x86/setup.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c index caf235c6286d..59907fae095f 100644 --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -1432,6 +1432,11 @@ void asmlinkage __init noreturn __start_xen(unsigned= long mbi_p) /* Is the region suitable for relocating the multiboot modules? */ for ( j =3D mbi->mods_count - 1; j >=3D 0; j-- ) { + /* + * 'headroom' is a guess for the decompressed size and + * decompressor overheads of mod[0] (the dom0 kernel). When we + * move mod[0], we incorperate this as extra space at the star= t. + */ unsigned long headroom =3D j ? 0 : modules_headroom; unsigned long size =3D PAGE_ALIGN(headroom + mod[j].mod_end); =20 --=20 2.30.2 From nobody Mon May 20 04:53:37 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=1714140143; cv=none; d=zohomail.com; s=zohoarc; b=cj+R7Skx/uEdn+kgXGNC/hb0nh3PVLtN0MfJZ63YvMuvaOMoZhrmKHFvUzTs+hriuml2z4Wrm4yJVbe3b//lzLj9AdIMX0gfP7bExxF163aNXvX+y/k6kSI3fvMlz43B6+Fv/45b1I6Tpzh3+wM9LLOgGFODDyMZb5NxoLfOHfE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1714140143; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=veQcubcMyTJwESdhZazD648xU+qEXNmLcmOyg8n0kxM=; b=UdvV7DesBa877aUJbqcWBiNptgsled5YQT8ozbGMuAaJNbBEsEB0Bqx+jrEeLku64zlODhLHAcOKQF1uBAL9+czcnKUVetv9i4vvBYBlVWYTccLyaptqXWwVRrlHFMWY+WFm7RJjzoXnfr1PvF58N0vbSf5FMU94NL+aukG/iOA= 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 1714140143781556.1390294570649; Fri, 26 Apr 2024 07:02:23 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.712821.1113684 (Exim 4.92) (envelope-from ) id 1s0M97-0008V6-8k; Fri, 26 Apr 2024 14:01:49 +0000 Received: by outflank-mailman (output) from mailman id 712821.1113684; Fri, 26 Apr 2024 14:01:49 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1s0M97-0008UY-2e; Fri, 26 Apr 2024 14:01:49 +0000 Received: by outflank-mailman (input) for mailman id 712821; Fri, 26 Apr 2024 14:01:47 +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 1s0M95-0008CS-Hv for xen-devel@lists.xenproject.org; Fri, 26 Apr 2024 14:01:47 +0000 Received: from mail-ej1-x633.google.com (mail-ej1-x633.google.com [2a00:1450:4864:20::633]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 847220ec-03d5-11ef-b4bb-af5377834399; Fri, 26 Apr 2024 16:01:45 +0200 (CEST) Received: by mail-ej1-x633.google.com with SMTP id a640c23a62f3a-a556d22fa93so259910766b.3 for ; Fri, 26 Apr 2024 07:01:45 -0700 (PDT) Received: from andrewcoop.citrite.net (default-46-102-197-194.interdsl.co.uk. [46.102.197.194]) by smtp.gmail.com with ESMTPSA id cd9-20020a170906b34900b00a5264576138sm10646714ejb.35.2024.04.26.07.01.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Apr 2024 07:01:44 -0700 (PDT) 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: 847220ec-03d5-11ef-b4bb-af5377834399 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1714140105; x=1714744905; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=veQcubcMyTJwESdhZazD648xU+qEXNmLcmOyg8n0kxM=; b=vZk8m4RHZPnB5zFFexR7CkcLjAgONhLRWxgf+aW2c+P974T1TuCKT35MpT829MAUft P6xCgxtmxzA1l1L3L5u0R7Eh49d7eIFT5EPf2qeremPP4EK/D6smxpbs3KPrMVJI69I9 au8pPmyKYgFmEL0p/DcZ6Uu5V/RQSL9ongV4M= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714140105; x=1714744905; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=veQcubcMyTJwESdhZazD648xU+qEXNmLcmOyg8n0kxM=; b=LG+tdoiXQIIohLjAvbuGX1FNFjGSqLJnQJU9RYT5QkTTjNpgnUk0kGpvhPMFjQxpjK hGAjF8/RmaKXy8sZVCYby1vtmZLmiL4Aqj4VGfKHzfx4kIcUKJLjlJHeLVmRacovyjBP 2KVLDaJbkTVonkUoH5wj87UuSzV1Caf7UN1iwptvQ5IQAsDUCu5m/2bujw+kiZEOCEYe wOnIoc112YhRUCPGn4okvAZ6ivgTufBKF1dvRK2DWxVfhpluSWzQ3XjWQXjY+oFtplcm yM143xIOOZOk1LVThzcJRuAFFUm9jkxA0mPDw4bwyT5TQgGuo4zigPOWzp0FTZB0QsWS +13w== X-Gm-Message-State: AOJu0YzoushOYVpIyJa5uKqLx6m1flMswPBNiXnsl+q13jKRXlggZ88r f/nswbcFXnCHynpamLq/j2uUisvnTfWa+pEhqEfIBe+2RHZwjJ7nN8ulCBKv6St93QfQFDZMAw3 8 X-Google-Smtp-Source: AGHT+IEj8vXvCopGaO4X7dStaBJ9uvmEkLYNnY0dcfRkjLKnRFpM2yYWaQLzOc6QAsV0QYdMaNgRUA== X-Received: by 2002:a17:906:fa98:b0:a52:36e1:c139 with SMTP id lt24-20020a170906fa9800b00a5236e1c139mr1682397ejb.4.1714140104904; Fri, 26 Apr 2024 07:01:44 -0700 (PDT) From: Andrew Cooper To: Xen-devel Cc: Andrew Cooper , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Stefano Stabellini , Daniel Smith , Christopher Clark Subject: [PATCH 2/3] x86/boot: Explain discard_initial_images() and untangle PV initrd handling Date: Fri, 26 Apr 2024 15:01:39 +0100 Message-Id: <20240426140140.465506-3-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20240426140140.465506-1-andrew.cooper3@citrix.com> References: <20240426140140.465506-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: 1714140145488100001 discard_initial_images() frees the memory backing the boot modules. It is called by dom0_construct_pv{,h}(), but obtains the module list by global pointer which is why there is no apparent link with the initrd pointer. Generally, module contents are copied into dom0 as it's being built, but the initrd for PV dom0 might be directly mapped instead of copied. dom0_construct_pv() does it's own ad-hoc freeing of the module in the copy case, and points the global reference at the new copy, then sets the size to 0. This only functions because init_domheap_pages(x, x) happens to be a no= p. Delete the ad-hoc freeing, and leave it to discard_initial_images(). This requires (not) adjusting initd->mod_start in the copy case, and only setting the size to 0 in the mapping case. Alter discard_initial_images() to explicitly check for an ignored module, a= nd explain what's going on. This is more robust and will allow for fixing oth= er problems with module handling. The later logic in dom0_construct_pv() now cannot use initrd->mod_start, but that's fine because initrd_mfn is already a duplicate of the information wanted, and is more consistent with initrd_{pfn,len} used elsewhere. Invalidate the initrd pointer with LIST_POISON1 to make it clearer that it shouldn't be used. No practical change in behaviour, but a substantial reduction in the complexity of how this works. Signed-off-by: Andrew Cooper --- CC: Jan Beulich CC: Roger Pau Monn=C3=A9 CC: Stefano Stabellini CC: Daniel Smith CC: Christopher Clark In other akward questions, why does initial_images_nrpages() account for all modules when only 1 or 2 are relevant for how we construct dom0 ? --- xen/arch/x86/pv/dom0_build.c | 22 +++++++++++----------- xen/arch/x86/setup.c | 9 ++++++++- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/xen/arch/x86/pv/dom0_build.c b/xen/arch/x86/pv/dom0_build.c index d8043fa58a27..64d9984b8308 100644 --- a/xen/arch/x86/pv/dom0_build.c +++ b/xen/arch/x86/pv/dom0_build.c @@ -630,18 +630,20 @@ int __init dom0_construct_pv(struct domain *d, } memcpy(page_to_virt(page), mfn_to_virt(initrd->mod_start), initrd_len); - mpt_alloc =3D (paddr_t)initrd->mod_start << PAGE_SHIFT; - init_domheap_pages(mpt_alloc, - mpt_alloc + PAGE_ALIGN(initrd_len)); - initrd->mod_start =3D initrd_mfn =3D mfn_x(page_to_mfn(page)); + initrd_mfn =3D mfn_x(page_to_mfn(page)); } else { while ( count-- ) if ( assign_pages(mfn_to_page(_mfn(mfn++)), 1, d, 0) ) BUG(); + /* + * Mapped rather than copied. Tell discard_initial_images() to + * ignore it. + */ + initrd->mod_end =3D 0; } - initrd->mod_end =3D 0; + initrd =3D LIST_POISON1; /* No longer valid to use. */ =20 iommu_memory_setup(d, "initrd", mfn_to_page(_mfn(initrd_mfn)), PFN_UP(initrd_len), &flush_flags); @@ -653,12 +655,10 @@ int __init dom0_construct_pv(struct domain *d, if ( domain_tot_pages(d) < nr_pages ) printk(" (%lu pages to be allocated)", nr_pages - domain_tot_pages(d)); - if ( initrd ) - { - mpt_alloc =3D (paddr_t)initrd->mod_start << PAGE_SHIFT; + if ( initrd_len ) printk("\n Init. ramdisk: %"PRIpaddr"->%"PRIpaddr, - mpt_alloc, mpt_alloc + initrd_len); - } + pfn_to_paddr(initrd_mfn), + pfn_to_paddr(initrd_mfn) + initrd_len); =20 printk("\nVIRTUAL MEMORY ARRANGEMENT:\n"); printk(" Loaded kernel: %p->%p\n", _p(vkern_start), _p(vkern_end)); @@ -881,7 +881,7 @@ int __init dom0_construct_pv(struct domain *d, if ( pfn >=3D initrd_pfn ) { if ( pfn < initrd_pfn + PFN_UP(initrd_len) ) - mfn =3D initrd->mod_start + (pfn - initrd_pfn); + mfn =3D initrd_mfn + (pfn - initrd_pfn); else mfn -=3D PFN_UP(initrd_len); } diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c index 59907fae095f..785a46a44995 100644 --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -294,7 +294,7 @@ unsigned long __init initial_images_nrpages(nodeid_t no= de) return nr; } =20 -void __init discard_initial_images(void) +void __init discard_initial_images(void) /* a.k.a. free multiboot modules = */ { unsigned int i; =20 @@ -302,6 +302,13 @@ void __init discard_initial_images(void) { uint64_t start =3D (uint64_t)initial_images[i].mod_start << PAGE_S= HIFT; =20 + /* + * Sometimes the initrd is mapped, rather than copied, into dom0. + * end=3D0 signifies that we should leave it alone. + */ + if ( initial_images[i].mod_end =3D=3D 0 ) + continue; + init_domheap_pages(start, start + PAGE_ALIGN(initial_images[i].mod_end)); } --=20 2.30.2 From nobody Mon May 20 04:53:37 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=1714140132; cv=none; d=zohomail.com; s=zohoarc; b=ChsLti0IS8kx8tavIbe5wJMESGXR1iC+I1gKyeLlBdspoArKM/3B7GJhJRtCeUmsa/RDstd4ZYicEfHWxsJVTEe2GJZYBEZ//br4pFA7nv62YqgUjzqTPEuPZjIXx2JXXARcmD41C7VDW3pSgO7fCWVst2suRLvtvkf6xZLZ/S0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1714140132; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=xeM/RCPSV+ID4MLdicSmYmkIWjkyBfbsjTrcmvtyVG4=; b=JQHB9gy2XP4hDw850GE5ctxQBE4AHrqXdmqXaEpstQPyRBEiVSSTTVj/o083vMn2OnPhRjPTqHUK1HOQomvBlU4dWBj0oM93rZqav4lc5m7c7ocP+dbQItJB/eUqcR+hXbbd1bzOBsrArZwl7R2mVCnZ/DEcnJsL7QLhlWWDgVQ= 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 1714140132057995.9515740332645; Fri, 26 Apr 2024 07:02:12 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.712822.1113689 (Exim 4.92) (envelope-from ) id 1s0M97-00006g-If; Fri, 26 Apr 2024 14:01:49 +0000 Received: by outflank-mailman (output) from mailman id 712822.1113689; Fri, 26 Apr 2024 14:01:49 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1s0M97-00005H-9T; Fri, 26 Apr 2024 14:01:49 +0000 Received: by outflank-mailman (input) for mailman id 712822; Fri, 26 Apr 2024 14:01:48 +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 1s0M96-0008CS-Gg for xen-devel@lists.xenproject.org; Fri, 26 Apr 2024 14:01:48 +0000 Received: from mail-ej1-x630.google.com (mail-ej1-x630.google.com [2a00:1450:4864:20::630]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 84ef6a17-03d5-11ef-b4bb-af5377834399; Fri, 26 Apr 2024 16:01:46 +0200 (CEST) Received: by mail-ej1-x630.google.com with SMTP id a640c23a62f3a-a5883518135so255336966b.3 for ; Fri, 26 Apr 2024 07:01:46 -0700 (PDT) Received: from andrewcoop.citrite.net (default-46-102-197-194.interdsl.co.uk. [46.102.197.194]) by smtp.gmail.com with ESMTPSA id cd9-20020a170906b34900b00a5264576138sm10646714ejb.35.2024.04.26.07.01.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Apr 2024 07:01:45 -0700 (PDT) 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: 84ef6a17-03d5-11ef-b4bb-af5377834399 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1714140106; x=1714744906; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=xeM/RCPSV+ID4MLdicSmYmkIWjkyBfbsjTrcmvtyVG4=; b=OZ4lOPhN3yh5GHIYkiK6Y69+hb2BKrIPvXPoVsbCPtYBY9XQj3Y5cH52UFB5WWbZhq g/p27HExZbFEgZuF0oDzswg6cJZqOrUQvP0P66EFvneqiUSrlo87OgzPO/LF3shPx7SY 9mPw3rvy9hCuYh2JEnUrsrppbd4YWIZYYZoCg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714140106; x=1714744906; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xeM/RCPSV+ID4MLdicSmYmkIWjkyBfbsjTrcmvtyVG4=; b=c94Hpaw303vhxPXvYCJX05NuYjq7nU40XcLBq/nhCAikuEZBjFmxqe7fvEmaxJ29Jh eSa8CLqg0YAukzdvQBrVW6yydZqjz0HGfOkZzpCtveEeQg73wXR5FhrWdxHzcQCANHGB j8jxBCqeN/1wrKfWqQB7/D7JCyBCgs48ag5bDW/xMEH1v5H3pUABbSTCoDkYHBMdDXuF 4lXKdqdKXvAdgtpdBUIJbyJ/K2O3q5BywMq6tA5QyIctyRQ1qW4qPhagDw2NIBmIeTq4 ldGHL6FNvomKS3uCcfkBU8NO0gSP2yhE+oT+Pcdo07vQrP008fxFHVGYZSxTJAmfzVpk FgrQ== X-Gm-Message-State: AOJu0Yy21GO2QqBNhst5u1ikkLtMmbX3tlj3PFKRY+nv3BOh2JCXLzgi qOJdvam9/bc4C8G98CD0ZhneLumYaG6d/347tz5eREVMc8EhNt3ESmH78KPglytBbBEcC/6FbnQ n X-Google-Smtp-Source: AGHT+IHXYzsYv7isaIpXd/H2FGGVqrIpSvN9UrZRbkeAhfvNg0Rod0Zj+Jbpr22V3Soh08zCR09Cng== X-Received: by 2002:a17:906:f748:b0:a55:b021:c0b1 with SMTP id jp8-20020a170906f74800b00a55b021c0b1mr2631322ejb.9.1714140105903; Fri, 26 Apr 2024 07:01:45 -0700 (PDT) From: Andrew Cooper To: Xen-devel Cc: Andrew Cooper , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Stefano Stabellini , Daniel Smith , Christopher Clark Subject: [PATCH 3/3] x86/boot: Refactor pvh_load_kernel() to have an initrd_len local Date: Fri, 26 Apr 2024 15:01:40 +0100 Message-Id: <20240426140140.465506-4-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20240426140140.465506-1-andrew.cooper3@citrix.com> References: <20240426140140.465506-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: 1714140133548100003 The expression get more complicated when ->mod_end isn't being abused as a size field. Introduce and use a initrd_len local variable. No functional change. Signed-off-by: Andrew Cooper Reviewed-by: Jan Beulich --- CC: Jan Beulich CC: Roger Pau Monn=C3=A9 CC: Stefano Stabellini CC: Daniel Smith CC: Christopher Clark --- xen/arch/x86/hvm/dom0_build.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/xen/arch/x86/hvm/dom0_build.c b/xen/arch/x86/hvm/dom0_build.c index ac71d43a6b3f..b0cb96c3bc76 100644 --- a/xen/arch/x86/hvm/dom0_build.c +++ b/xen/arch/x86/hvm/dom0_build.c @@ -650,6 +650,7 @@ static int __init pvh_load_kernel(struct domain *d, con= st module_t *image, { void *image_start =3D image_base + image_headroom; unsigned long image_len =3D image->mod_end; + unsigned long initrd_len =3D initrd ? initrd->mod_end : 0; struct elf_binary elf; struct elf_dom_parms parms; paddr_t last_addr; @@ -710,7 +711,7 @@ static int __init pvh_load_kernel(struct domain *d, con= st module_t *image, * simplify it. */ last_addr =3D find_memory(d, &elf, sizeof(start_info) + - (initrd ? ROUNDUP(initrd->mod_end, PAGE_SIZE) + + (initrd ? ROUNDUP(initrd_len, PAGE_SIZE) + sizeof(mod) : 0) + (cmdline ? ROUNDUP(strlen(cmdline) + 1, @@ -725,7 +726,7 @@ static int __init pvh_load_kernel(struct domain *d, con= st module_t *image, if ( initrd !=3D NULL ) { rc =3D hvm_copy_to_guest_phys(last_addr, mfn_to_virt(initrd->mod_s= tart), - initrd->mod_end, v); + initrd_len, v); if ( rc ) { printk("Unable to copy initrd to guest\n"); @@ -733,8 +734,8 @@ static int __init pvh_load_kernel(struct domain *d, con= st module_t *image, } =20 mod.paddr =3D last_addr; - mod.size =3D initrd->mod_end; - last_addr +=3D ROUNDUP(initrd->mod_end, elf_64bit(&elf) ? 8 : 4); + mod.size =3D initrd_len; + last_addr +=3D ROUNDUP(initrd_len, elf_64bit(&elf) ? 8 : 4); if ( initrd->string ) { char *str =3D __va(initrd->string); --=20 2.30.2