All of lore.kernel.org
 help / color / mirror / Atom feed
From: Elias El Yandouzi <eliasely@amazon.com>
To: <xen-devel@lists.xenproject.org>
Cc: <julien@xen.org>, <pdurrant@amazon.com>, <dwmw@amazon.com>,
	Hongyan Xia <hongyxia@amazon.com>,
	Andrew Cooper <andrew.cooper3@citrix.com>,
	"George Dunlap" <george.dunlap@citrix.com>,
	Jan Beulich <jbeulich@suse.com>,
	"Stefano Stabellini" <sstabellini@kernel.org>,
	Wei Liu <wl@xen.org>, Julien Grall <jgrall@amazon.com>,
	Elias El Yandouzi <eliasely@amazon.com>
Subject: [PATCH v2] acpi: vmap pages in acpi_os_alloc_memory
Date: Tue, 16 Jan 2024 18:50:33 +0000	[thread overview]
Message-ID: <20240116185056.15000-5-eliasely@amazon.com> (raw)
In-Reply-To: <20240116185056.15000-1-eliasely@amazon.com>

From: Hongyan Xia <hongyxia@amazon.com>

Also, introduce a wrapper around vmap that maps a contiguous range for
boot allocations. Unfortunately, the new helper cannot be a static inline
because the dependencies are a mess. We would need to re-include
asm/page.h (was removed in aa4b9d1ee653 "include: don't use asm/page.h
from common headers") and it doesn't look to be enough anymore
because bits from asm/cpufeature.h is used in the definition of PAGE_NX.

Lastly, with the move to vmap(), it is now easier to find the size
of the mapping. So pass the whole area to init_boot_pages() rather than
just the first page.

Signed-off-by: Hongyan Xia <hongyxia@amazon.com>
Signed-off-by: Julien Grall <jgrall@amazon.com>
Signed-off-by: Elias El Yandouzi <eliasely@amazon.com>

----

    Changes in v2:
        * Rename vmap_contig_pages() to vmap_contig()
        * Rename nr_pages to nr to be consistent with vmap() parameters
        * Pass the whole region to init_boot_pages()

    Changes since Hongyan's version:
        * Rename vmap_boot_pages() to vmap_contig_pages()
        * Move the new helper in vmap.c to avoid compilation issue
        * Don't use __pa() to translate the virtual address

diff --git a/xen/common/vmap.c b/xen/common/vmap.c
index 171271fae3..966a7e763f 100644
--- a/xen/common/vmap.c
+++ b/xen/common/vmap.c
@@ -245,6 +245,11 @@ void *vmap(const mfn_t *mfn, unsigned int nr)
     return __vmap(mfn, 1, nr, 1, PAGE_HYPERVISOR, VMAP_DEFAULT);
 }
 
+void *vmap_contig(mfn_t mfn, unsigned int nr)
+{
+    return __vmap(&mfn, nr, 1, 1, PAGE_HYPERVISOR, VMAP_DEFAULT);
+}
+
 unsigned int vmap_size(const void *va)
 {
     unsigned int pages = vm_size(va, VMAP_DEFAULT);
diff --git a/xen/drivers/acpi/osl.c b/xen/drivers/acpi/osl.c
index 389505f786..ab80d6b2a9 100644
--- a/xen/drivers/acpi/osl.c
+++ b/xen/drivers/acpi/osl.c
@@ -221,7 +221,11 @@ void *__init acpi_os_alloc_memory(size_t sz)
 	void *ptr;
 
 	if (system_state == SYS_STATE_early_boot)
-		return mfn_to_virt(mfn_x(alloc_boot_pages(PFN_UP(sz), 1)));
+	{
+		mfn_t mfn = alloc_boot_pages(PFN_UP(sz), 1);
+
+		return vmap_contig(mfn, PFN_UP(sz));
+	}
 
 	ptr = xmalloc_bytes(sz);
 	ASSERT(!ptr || is_xmalloc_memory(ptr));
@@ -246,5 +250,11 @@ void __init acpi_os_free_memory(void *ptr)
 	if (is_xmalloc_memory(ptr))
 		xfree(ptr);
 	else if (ptr && system_state == SYS_STATE_early_boot)
-		init_boot_pages(__pa(ptr), __pa(ptr) + PAGE_SIZE);
+	{
+		paddr_t addr = mfn_to_maddr(vmap_to_mfn(ptr));
+		unsigned int nr = vmap_size(ptr);
+
+		vunmap(ptr);
+		init_boot_pages(addr, addr + nr * PAGE_SIZE);
+	}
 }
diff --git a/xen/include/xen/vmap.h b/xen/include/xen/vmap.h
index 24c85de490..0c16baa85f 100644
--- a/xen/include/xen/vmap.h
+++ b/xen/include/xen/vmap.h
@@ -15,6 +15,7 @@ void vm_init_type(enum vmap_region type, void *start, void *end);
 void *__vmap(const mfn_t *mfn, unsigned int granularity, unsigned int nr,
              unsigned int align, unsigned int flags, enum vmap_region type);
 void *vmap(const mfn_t *mfn, unsigned int nr);
+void *vmap_contig(mfn_t mfn, unsigned int nr);
 void vunmap(const void *va);
 
 void *vmalloc(size_t size);
-- 
2.40.1



  parent reply	other threads:[~2024-01-16 18:52 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-16 18:50 [PATCH v2] Remove the directmap Elias El Yandouzi
2024-01-16 18:50 ` [PATCH v2] xen/vmap: Check the page has been mapped in vm_init_type() Elias El Yandouzi
2024-01-16 18:50 ` [PATCH v2] x86/setup: Move vm_init() before acpi calls Elias El Yandouzi
2024-01-16 18:50 ` [PATCH v2] xen/vmap: Introduce vmap_size() and use it Elias El Yandouzi
2024-01-16 18:50 ` Elias El Yandouzi [this message]
2024-01-16 18:50 ` [PATCH v2] xen/numa: vmap the pages for memnodemap Elias El Yandouzi
2024-01-16 18:50 ` [PATCH v2] x86/srat: vmap the pages for acpi_slit Elias El Yandouzi
2024-01-16 18:50 ` [PATCH v2] x86: Map/unmap pages in restore_all_guests Elias El Yandouzi
2024-01-16 18:50 ` [PATCH v2] x86/pv: Domheap pages should be mapped while relocating initrd Elias El Yandouzi
2024-01-16 18:50 ` [PATCH v2] x86/pv: Rewrite how building PV dom0 handles domheap mappings Elias El Yandouzi
2024-01-16 18:50 ` [PATCH v2] x86/pv: Map L4 page table for shim domain Elias El Yandouzi
2024-01-16 18:50 ` [PATCH v2] x86: Lift mapcache variable to the arch level Elias El Yandouzi
2024-01-16 18:50 ` [PATCH v2] x86/mapcache: Initialise the mapcache for the idle domain Elias El Yandouzi
2024-01-16 18:50 ` [PATCH v2] x86: Add a boot option to enable and disable the direct map Elias El Yandouzi
2024-01-16 18:50 ` [PATCH v2] xen/arm: fixmap: Rename the fixmap slots to follow the x86 convention Elias El Yandouzi
2024-01-16 18:50 ` [PATCH v2] xen/x86: Add support for the PMAP Elias El Yandouzi
2024-01-16 18:50 ` [PATCH v2] xen/x86: Add build assertion for fixmap entries Elias El Yandouzi
2024-01-16 18:50 ` [PATCH v2] x86/domain_page: Remove the fast paths when mfn is not in the directmap Elias El Yandouzi
2024-01-16 18:50 ` [PATCH v2] xen/page_alloc: Add a path for xenheap when there is no direct map Elias El Yandouzi
2024-01-16 18:50 ` [PATCH v2] x86/setup: Leave early boot slightly earlier Elias El Yandouzi
2024-01-16 18:50 ` [PATCH v2] x86/setup: vmap heap nodes when they are outside the direct map Elias El Yandouzi
2024-01-16 18:50 ` [PATCH v2] x86/setup: Do not create valid mappings when directmap=no Elias El Yandouzi
2024-01-16 18:50 ` [PATCH v2] Rename mfn_to_virt() calls Elias El Yandouzi
2024-01-16 18:50 ` [PATCH v2] Rename maddr_to_virt() calls Elias El Yandouzi
2024-01-16 18:50 ` [PATCH v2] xen/arm32: mm: Rename 'first' to 'root' in init_secondary_pagetables() Elias El Yandouzi
2024-01-16 18:50 ` [PATCH v2] xen/arm64: mm: Use per-pCPU page-tables Elias El Yandouzi
2024-01-16 18:50 ` [PATCH v2] xen/arm64: Implement a mapcache for arm64 Elias El Yandouzi
2024-01-16 18:50 ` [PATCH v2] xen/arm64: Allow the admin to enable/disable the directmap Elias El Yandouzi
2024-01-16 19:22 ` [PATCH v2] Remove " Elias El Yandouzi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240116185056.15000-5-eliasely@amazon.com \
    --to=eliasely@amazon.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=dwmw@amazon.com \
    --cc=george.dunlap@citrix.com \
    --cc=hongyxia@amazon.com \
    --cc=jbeulich@suse.com \
    --cc=jgrall@amazon.com \
    --cc=julien@xen.org \
    --cc=pdurrant@amazon.com \
    --cc=sstabellini@kernel.org \
    --cc=wl@xen.org \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.