From patchwork Mon May 13 13:40:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elias El Yandouzi X-Patchwork-Id: 13663463 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 3D439C25B10 for ; Mon, 13 May 2024 13:41:12 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.720924.1123972 (Exim 4.92) (envelope-from ) id 1s6VvK-0003Fv-4y; Mon, 13 May 2024 13:41:02 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 720924.1123972; Mon, 13 May 2024 13:41:02 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1s6VvK-0003Fm-0Q; Mon, 13 May 2024 13:41:02 +0000 Received: by outflank-mailman (input) for mailman id 720924; Mon, 13 May 2024 13:41:01 +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 1s6VvJ-0002lY-3x for xen-devel@lists.xenproject.org; Mon, 13 May 2024 13:41:01 +0000 Received: from smtp-fw-2101.amazon.com (smtp-fw-2101.amazon.com [72.21.196.25]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 6e11da8b-112e-11ef-b4bb-af5377834399; Mon, 13 May 2024 15:40:59 +0200 (CEST) Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO smtpout.prod.us-east-1.prod.farcaster.email.amazon.dev) ([10.43.8.6]) by smtp-border-fw-2101.iad2.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 May 2024 13:40:57 +0000 Received: from EX19MTAUEC002.ant.amazon.com [10.0.0.204:28640] by smtpin.naws.us-east-1.prod.farcaster.email.amazon.dev [10.0.23.176:2525] with esmtp (Farcaster) id 8f053902-e51d-4042-8390-6b1417a00a31; Mon, 13 May 2024 13:40:56 +0000 (UTC) Received: from EX19D008UEA001.ant.amazon.com (10.252.134.62) by EX19MTAUEC002.ant.amazon.com (10.252.135.253) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.28; Mon, 13 May 2024 13:40:55 +0000 Received: from EX19MTAUWB001.ant.amazon.com (10.250.64.248) by EX19D008UEA001.ant.amazon.com (10.252.134.62) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.28; Mon, 13 May 2024 13:40:55 +0000 Received: from dev-dsk-eliasely-1a-fd74790f.eu-west-1.amazon.com (10.253.91.118) by mail-relay.amazon.com (10.250.64.254) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.28 via Frontend Transport; Mon, 13 May 2024 13:40:53 +0000 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: 6e11da8b-112e-11ef-b4bb-af5377834399 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1715607660; x=1747143660; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=X8yfiUTton8c3NyUnbJj3YCfUh5a4EGoBhji2snIQBs=; b=qmryHJ0I4tVzQwvtg9aHAIn9ubq1V8ZQ1PSQEVy2ZYDmKZxAuiCK5uZ4 fobIhFtE0WKejzDTdZT1YJuij76Ik1qirXc0iiCy9DCsyCfzfcy1IcK9E Z5l8AmsR8FYT7dXcXIw9JKo+q6pLyK8zpYLbHLjvnkV6bKlq4/5Ah78co M=; X-IronPort-AV: E=Sophos;i="6.08,158,1712620800"; d="scan'208";a="400810201" X-Farcaster-Flow-ID: 8f053902-e51d-4042-8390-6b1417a00a31 From: Elias El Yandouzi To: CC: , , , Wei Liu , Jan Beulich , Andrew Cooper , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Wei Wang , Julien Grall , Elias El Yandouzi Subject: [PATCH V3 (resend) 02/19] x86/pv: Domheap pages should be mapped while relocating initrd Date: Mon, 13 May 2024 13:40:29 +0000 Message-ID: <20240513134046.82605-3-eliasely@amazon.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240513134046.82605-1-eliasely@amazon.com> References: <20240513134046.82605-1-eliasely@amazon.com> MIME-Version: 1.0 From: Wei Liu Xen shouldn't use domheap page as if they were xenheap pages. Map and unmap pages accordingly. Signed-off-by: Wei Liu Signed-off-by: Wei Wang Signed-off-by: Julien Grall Signed-off-by: Elias El Yandouzi ---- Changes in V3: * Rename commit title * Rework the for loop copying the pages Changes in V2: * Get rid of mfn_to_virt * Don't open code copy_domain_page() Changes since Hongyan's version: * Add missing newline after the variable declaration diff --git a/xen/arch/x86/pv/dom0_build.c b/xen/arch/x86/pv/dom0_build.c index d8043fa58a..807296c280 100644 --- a/xen/arch/x86/pv/dom0_build.c +++ b/xen/arch/x86/pv/dom0_build.c @@ -618,18 +618,24 @@ int __init dom0_construct_pv(struct domain *d, if ( d->arch.physaddr_bitsize && ((mfn + count - 1) >> (d->arch.physaddr_bitsize - PAGE_SHIFT)) ) { + unsigned int nr_pages = 1UL << order; + order = get_order_from_pages(count); page = alloc_domheap_pages(d, order, MEMF_no_scrub); if ( !page ) panic("Not enough RAM for domain 0 initrd\n"); + for ( count = -count; order--; ) if ( count & (1UL << order) ) { free_domheap_pages(page, order); page += 1UL << order; + nr_pages -= 1UL << order; } - memcpy(page_to_virt(page), mfn_to_virt(initrd->mod_start), - initrd_len); + + for ( ; nr_pages-- ; page++, mfn++ ) + copy_domain_page(page_to_mfn(page), _mfn(mfn)); + mpt_alloc = (paddr_t)initrd->mod_start << PAGE_SHIFT; init_domheap_pages(mpt_alloc, mpt_alloc + PAGE_ALIGN(initrd_len));