Message ID | a71d1903267b84afdb0e54fa2ac55540ab2f9357.1588278317.git.hongyxia@amazon.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | Remove the direct map | expand |
On Thu, Apr 30, 2020 at 09:44:11PM +0100, Hongyan Xia wrote: > From: Hongyan Xia <hongyxia@amazon.com> > > Also, introduce a wrapper around vmap that maps a contiguous range for > boot allocations. > > Signed-off-by: Hongyan Xia <hongyxia@amazon.com> > --- > xen/drivers/acpi/osl.c | 9 ++++++++- > xen/include/xen/vmap.h | 5 +++++ > 2 files changed, 13 insertions(+), 1 deletion(-) > > diff --git a/xen/drivers/acpi/osl.c b/xen/drivers/acpi/osl.c > index 4c8bb7839e..d0762dad4e 100644 > --- a/xen/drivers/acpi/osl.c > +++ b/xen/drivers/acpi/osl.c > @@ -219,7 +219,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_boot_pages(mfn, PFN_UP(sz)); > + } > > ptr = xmalloc_bytes(sz); > ASSERT(!ptr || is_xmalloc_memory(ptr)); > @@ -244,5 +248,8 @@ void __init acpi_os_free_memory(void *ptr) > if (is_xmalloc_memory(ptr)) > xfree(ptr); > else if (ptr && system_state == SYS_STATE_early_boot) > + { > + vunmap(ptr); > init_boot_pages(__pa(ptr), __pa(ptr) + PAGE_SIZE); > + } > } > diff --git a/xen/include/xen/vmap.h b/xen/include/xen/vmap.h > index 369560e620..c70801e195 100644 > --- a/xen/include/xen/vmap.h > +++ b/xen/include/xen/vmap.h > @@ -23,6 +23,11 @@ void *vmalloc_xen(size_t size); > void *vzalloc(size_t size); > void vfree(void *va); > > +static inline void *vmap_boot_pages(mfn_t mfn, unsigned int nr_pages) Nothing seems to tie this to boot pages only. Maybe it is better to name it after what it does, like vmap_mfns? > +{ > + return __vmap(&mfn, nr_pages, 1, 1, PAGE_HYPERVISOR, VMAP_DEFAULT); > +} > + > void __iomem *ioremap(paddr_t, size_t); > > static inline void iounmap(void __iomem *va) > -- > 2.24.1.AMZN >
On Fri, 2020-05-01 at 12:02 +0000, Wei Liu wrote: > On Thu, Apr 30, 2020 at 09:44:11PM +0100, Hongyan Xia wrote: > > From: Hongyan Xia <hongyxia@amazon.com> > > > > Also, introduce a wrapper around vmap that maps a contiguous range > > for > > boot allocations. > > > > Signed-off-by: Hongyan Xia <hongyxia@amazon.com> > > --- > > xen/drivers/acpi/osl.c | 9 ++++++++- > > xen/include/xen/vmap.h | 5 +++++ > > 2 files changed, 13 insertions(+), 1 deletion(-) > > > > diff --git a/xen/drivers/acpi/osl.c b/xen/drivers/acpi/osl.c > > index 4c8bb7839e..d0762dad4e 100644 > > --- a/xen/drivers/acpi/osl.c > > +++ b/xen/drivers/acpi/osl.c > > @@ -219,7 +219,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_boot_pages(mfn, PFN_UP(sz)); > > + } > > > > ptr = xmalloc_bytes(sz); > > ASSERT(!ptr || is_xmalloc_memory(ptr)); > > @@ -244,5 +248,8 @@ void __init acpi_os_free_memory(void *ptr) > > if (is_xmalloc_memory(ptr)) > > xfree(ptr); > > else if (ptr && system_state == SYS_STATE_early_boot) > > + { > > + vunmap(ptr); > > init_boot_pages(__pa(ptr), __pa(ptr) + PAGE_SIZE); > > + } > > } > > diff --git a/xen/include/xen/vmap.h b/xen/include/xen/vmap.h > > index 369560e620..c70801e195 100644 > > --- a/xen/include/xen/vmap.h > > +++ b/xen/include/xen/vmap.h > > @@ -23,6 +23,11 @@ void *vmalloc_xen(size_t size); > > void *vzalloc(size_t size); > > void vfree(void *va); > > > > +static inline void *vmap_boot_pages(mfn_t mfn, unsigned int > > nr_pages) > > Nothing seems to tie this to boot pages only. Maybe it is better to > name > it after what it does, like vmap_mfns? Hmm, indeed nothing so special about *boot* pages. Will change. Hongyan
Hi, On Thu, 30 Apr 2020 at 21:44, Hongyan Xia <hx242@xen.org> wrote: > > From: Hongyan Xia <hongyxia@amazon.com> > > Also, introduce a wrapper around vmap that maps a contiguous range for > boot allocations. > > Signed-off-by: Hongyan Xia <hongyxia@amazon.com> > --- > xen/drivers/acpi/osl.c | 9 ++++++++- > xen/include/xen/vmap.h | 5 +++++ > 2 files changed, 13 insertions(+), 1 deletion(-) > > diff --git a/xen/drivers/acpi/osl.c b/xen/drivers/acpi/osl.c > index 4c8bb7839e..d0762dad4e 100644 > --- a/xen/drivers/acpi/osl.c > +++ b/xen/drivers/acpi/osl.c > @@ -219,7 +219,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_boot_pages(mfn, PFN_UP(sz)); > + } > > ptr = xmalloc_bytes(sz); > ASSERT(!ptr || is_xmalloc_memory(ptr)); > @@ -244,5 +248,8 @@ void __init acpi_os_free_memory(void *ptr) > if (is_xmalloc_memory(ptr)) > xfree(ptr); > else if (ptr && system_state == SYS_STATE_early_boot) > + { > + vunmap(ptr); > init_boot_pages(__pa(ptr), __pa(ptr) + PAGE_SIZE); __pa(ptr) can only work on the direct map. Even worth, on Arm it will fault because there is no mapping. I think you will want to use vmap_to_mfn() before calling vunmap(). Cheers,
On Fri, 2020-05-01 at 22:35 +0100, Julien Grall wrote: > Hi, > > On Thu, 30 Apr 2020 at 21:44, Hongyan Xia <hx242@xen.org> wrote: > > > > From: Hongyan Xia <hongyxia@amazon.com> > > > > Also, introduce a wrapper around vmap that maps a contiguous range > > for > > boot allocations. > > > > Signed-off-by: Hongyan Xia <hongyxia@amazon.com> > > --- > > xen/drivers/acpi/osl.c | 9 ++++++++- > > xen/include/xen/vmap.h | 5 +++++ > > 2 files changed, 13 insertions(+), 1 deletion(-) > > > > diff --git a/xen/drivers/acpi/osl.c b/xen/drivers/acpi/osl.c > > index 4c8bb7839e..d0762dad4e 100644 > > --- a/xen/drivers/acpi/osl.c > > +++ b/xen/drivers/acpi/osl.c > > @@ -219,7 +219,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_boot_pages(mfn, PFN_UP(sz)); > > + } > > > > ptr = xmalloc_bytes(sz); > > ASSERT(!ptr || is_xmalloc_memory(ptr)); > > @@ -244,5 +248,8 @@ void __init acpi_os_free_memory(void *ptr) > > if (is_xmalloc_memory(ptr)) > > xfree(ptr); > > else if (ptr && system_state == SYS_STATE_early_boot) > > + { > > + vunmap(ptr); > > init_boot_pages(__pa(ptr), __pa(ptr) + PAGE_SIZE); > > __pa(ptr) can only work on the direct map. Even worth, on Arm it will > fault because there is no mapping. > I think you will want to use vmap_to_mfn() before calling vunmap(). Thanks for spotting this. This is definitely wrong. Will revise. Hongyan
diff --git a/xen/drivers/acpi/osl.c b/xen/drivers/acpi/osl.c index 4c8bb7839e..d0762dad4e 100644 --- a/xen/drivers/acpi/osl.c +++ b/xen/drivers/acpi/osl.c @@ -219,7 +219,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_boot_pages(mfn, PFN_UP(sz)); + } ptr = xmalloc_bytes(sz); ASSERT(!ptr || is_xmalloc_memory(ptr)); @@ -244,5 +248,8 @@ void __init acpi_os_free_memory(void *ptr) if (is_xmalloc_memory(ptr)) xfree(ptr); else if (ptr && system_state == SYS_STATE_early_boot) + { + vunmap(ptr); init_boot_pages(__pa(ptr), __pa(ptr) + PAGE_SIZE); + } } diff --git a/xen/include/xen/vmap.h b/xen/include/xen/vmap.h index 369560e620..c70801e195 100644 --- a/xen/include/xen/vmap.h +++ b/xen/include/xen/vmap.h @@ -23,6 +23,11 @@ void *vmalloc_xen(size_t size); void *vzalloc(size_t size); void vfree(void *va); +static inline void *vmap_boot_pages(mfn_t mfn, unsigned int nr_pages) +{ + return __vmap(&mfn, nr_pages, 1, 1, PAGE_HYPERVISOR, VMAP_DEFAULT); +} + void __iomem *ioremap(paddr_t, size_t); static inline void iounmap(void __iomem *va)