From patchwork Fri Apr 26 14:01:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew Cooper X-Patchwork-Id: 13644888 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D9881C4345F for ; Fri, 26 Apr 2024 14:01:57 +0000 (UTC) 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 X-Outflank-Mailman: Message body and most headers restored to incoming version 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-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_Pau_Monn=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 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é 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 = mbi->mods_count - 1; j >= 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 start. + */ unsigned long headroom = j ? 0 : modules_headroom; unsigned long size = PAGE_ALIGN(headroom + mod[j].mod_end); From patchwork Fri Apr 26 14:01:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew Cooper X-Patchwork-Id: 13644890 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id F335BC4345F for ; Fri, 26 Apr 2024 14:02:16 +0000 (UTC) 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 X-Outflank-Mailman: Message body and most headers restored to incoming version 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-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_Pau_Monn=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 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 nop. 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, and explain what's going on. This is more robust and will allow for fixing other 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é 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 = (paddr_t)initrd->mod_start << PAGE_SHIFT; - init_domheap_pages(mpt_alloc, - mpt_alloc + PAGE_ALIGN(initrd_len)); - initrd->mod_start = initrd_mfn = mfn_x(page_to_mfn(page)); + initrd_mfn = 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 = 0; } - initrd->mod_end = 0; + initrd = LIST_POISON1; /* No longer valid to use. */ 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 = (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); 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 >= initrd_pfn ) { if ( pfn < initrd_pfn + PFN_UP(initrd_len) ) - mfn = initrd->mod_start + (pfn - initrd_pfn); + mfn = initrd_mfn + (pfn - initrd_pfn); else mfn -= 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 node) return nr; } -void __init discard_initial_images(void) +void __init discard_initial_images(void) /* a.k.a. free multiboot modules */ { unsigned int i; @@ -302,6 +302,13 @@ void __init discard_initial_images(void) { uint64_t start = (uint64_t)initial_images[i].mod_start << PAGE_SHIFT; + /* + * Sometimes the initrd is mapped, rather than copied, into dom0. + * end=0 signifies that we should leave it alone. + */ + if ( initial_images[i].mod_end == 0 ) + continue; + init_domheap_pages(start, start + PAGE_ALIGN(initial_images[i].mod_end)); } From patchwork Fri Apr 26 14:01:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew Cooper X-Patchwork-Id: 13644887 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E375FC04FFE for ; Fri, 26 Apr 2024 14:01:57 +0000 (UTC) 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 X-Outflank-Mailman: Message body and most headers restored to incoming version 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-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_Pau_Monn=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 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é 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, const module_t *image, { void *image_start = image_base + image_headroom; unsigned long image_len = image->mod_end; + unsigned long initrd_len = 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, const module_t *image, * simplify it. */ last_addr = 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, const module_t *image, if ( initrd != NULL ) { rc = hvm_copy_to_guest_phys(last_addr, mfn_to_virt(initrd->mod_start), - 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, const module_t *image, } mod.paddr = last_addr; - mod.size = initrd->mod_end; - last_addr += ROUNDUP(initrd->mod_end, elf_64bit(&elf) ? 8 : 4); + mod.size = initrd_len; + last_addr += ROUNDUP(initrd_len, elf_64bit(&elf) ? 8 : 4); if ( initrd->string ) { char *str = __va(initrd->string);