2018-10-29 23:28:32 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2018 Intel Corporation. All rights reserved.
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef PAGE_H
|
|
|
|
#define PAGE_H
|
|
|
|
|
2021-04-23 15:50:57 +08:00
|
|
|
#include <asm/lib/spinlock.h>
|
2020-02-28 22:15:58 +08:00
|
|
|
|
2018-10-29 23:28:32 +08:00
|
|
|
#define PAGE_SHIFT 12U
|
2018-11-30 13:16:14 +08:00
|
|
|
#define PAGE_SIZE (1U << PAGE_SHIFT)
|
2018-12-03 09:41:18 +08:00
|
|
|
#define PAGE_MASK 0xFFFFFFFFFFFFF000UL
|
2018-10-29 23:28:32 +08:00
|
|
|
|
2021-03-16 13:41:34 +08:00
|
|
|
#define MAXIMUM_PA_WIDTH 46U /* maximum physical-address width */
|
2021-03-10 12:00:25 +08:00
|
|
|
#define MAX_PHY_ADDRESS_SPACE (1UL << MAXIMUM_PA_WIDTH)
|
hv: page: use dynamic page allocation for pagetable mapping
For FuSa's case, we remove all dynamic memory allocation use in ACRN HV. Instead,
we use static memory allocation or embedded data structure. For pagetable page,
we prefer to use an index (hva for MMU, gpa for EPT) to get a page from a special
page pool. The special page pool should be big enougn for each possible index.
This is not a big problem when we don't support 64 bits MMIO. Without 64 bits MMIO
support, we could use the index to search addrss not larger than DRAM_SIZE + 4G.
However, if ACRN plan to support 64 bits MMIO in SOS, we could not use the static
memory alocation any more. This is because there's a very huge hole between the
top DRAM address and the bottom 64 bits MMIO address. We could not reserve such
many pages for pagetable mapping as the CPU physical address bits may very large.
This patch will use dynamic page allocation for pagetable mapping. We also need
reserve a big enough page pool at first. For HV MMU, we don't use 4K granularity
page table mapping, we need reserve PML4, PDPT and PD pages according the maximum
physical address space (PPT va and pa are identical mapping); For each VM EPT,
we reserve PML4, PDPT and PD pages according to the maximum physical address space
too, (the EPT address sapce can't beyond the physical address space), and we reserve
PT pages by real use cases of DRAM, low MMIO and high MMIO.
Signed-off-by: Li Fei1 <fei1.li@intel.com>
Tracked-On: #5788
2021-02-19 14:09:58 +08:00
|
|
|
|
2018-10-29 23:28:32 +08:00
|
|
|
/* size of the low MMIO address space: 2GB */
|
|
|
|
#define PLATFORM_LO_MMIO_SIZE 0x80000000UL
|
|
|
|
|
2019-02-26 09:18:12 +08:00
|
|
|
/* size of the high MMIO address space: 1GB */
|
|
|
|
#define PLATFORM_HI_MMIO_SIZE 0x40000000UL
|
|
|
|
|
2018-10-30 05:55:57 +08:00
|
|
|
#define PML4_PAGE_NUM(size) 1UL
|
|
|
|
#define PDPT_PAGE_NUM(size) (((size) + PML4E_SIZE - 1UL) >> PML4E_SHIFT)
|
|
|
|
#define PD_PAGE_NUM(size) (((size) + PDPTE_SIZE - 1UL) >> PDPTE_SHIFT)
|
|
|
|
#define PT_PAGE_NUM(size) (((size) + PDE_SIZE - 1UL) >> PDE_SHIFT)
|
|
|
|
|
|
|
|
|
2018-10-29 23:28:32 +08:00
|
|
|
struct page {
|
|
|
|
uint8_t contents[PAGE_SIZE];
|
|
|
|
} __aligned(PAGE_SIZE);
|
|
|
|
|
hv: page: use dynamic page allocation for pagetable mapping
For FuSa's case, we remove all dynamic memory allocation use in ACRN HV. Instead,
we use static memory allocation or embedded data structure. For pagetable page,
we prefer to use an index (hva for MMU, gpa for EPT) to get a page from a special
page pool. The special page pool should be big enougn for each possible index.
This is not a big problem when we don't support 64 bits MMIO. Without 64 bits MMIO
support, we could use the index to search addrss not larger than DRAM_SIZE + 4G.
However, if ACRN plan to support 64 bits MMIO in SOS, we could not use the static
memory alocation any more. This is because there's a very huge hole between the
top DRAM address and the bottom 64 bits MMIO address. We could not reserve such
many pages for pagetable mapping as the CPU physical address bits may very large.
This patch will use dynamic page allocation for pagetable mapping. We also need
reserve a big enough page pool at first. For HV MMU, we don't use 4K granularity
page table mapping, we need reserve PML4, PDPT and PD pages according the maximum
physical address space (PPT va and pa are identical mapping); For each VM EPT,
we reserve PML4, PDPT and PD pages according to the maximum physical address space
too, (the EPT address sapce can't beyond the physical address space), and we reserve
PT pages by real use cases of DRAM, low MMIO and high MMIO.
Signed-off-by: Li Fei1 <fei1.li@intel.com>
Tracked-On: #5788
2021-02-19 14:09:58 +08:00
|
|
|
struct page_pool {
|
|
|
|
struct page *start_page;
|
|
|
|
spinlock_t lock;
|
|
|
|
uint64_t bitmap_size;
|
|
|
|
uint64_t *bitmap;
|
|
|
|
uint64_t last_hint_id;
|
|
|
|
|
|
|
|
struct page *dummy_page;
|
2018-10-29 23:28:32 +08:00
|
|
|
};
|
|
|
|
|
hv: page: use dynamic page allocation for pagetable mapping
For FuSa's case, we remove all dynamic memory allocation use in ACRN HV. Instead,
we use static memory allocation or embedded data structure. For pagetable page,
we prefer to use an index (hva for MMU, gpa for EPT) to get a page from a special
page pool. The special page pool should be big enougn for each possible index.
This is not a big problem when we don't support 64 bits MMIO. Without 64 bits MMIO
support, we could use the index to search addrss not larger than DRAM_SIZE + 4G.
However, if ACRN plan to support 64 bits MMIO in SOS, we could not use the static
memory alocation any more. This is because there's a very huge hole between the
top DRAM address and the bottom 64 bits MMIO address. We could not reserve such
many pages for pagetable mapping as the CPU physical address bits may very large.
This patch will use dynamic page allocation for pagetable mapping. We also need
reserve a big enough page pool at first. For HV MMU, we don't use 4K granularity
page table mapping, we need reserve PML4, PDPT and PD pages according the maximum
physical address space (PPT va and pa are identical mapping); For each VM EPT,
we reserve PML4, PDPT and PD pages according to the maximum physical address space
too, (the EPT address sapce can't beyond the physical address space), and we reserve
PT pages by real use cases of DRAM, low MMIO and high MMIO.
Signed-off-by: Li Fei1 <fei1.li@intel.com>
Tracked-On: #5788
2021-02-19 14:09:58 +08:00
|
|
|
struct page *alloc_page(struct page_pool *pool);
|
2021-02-19 14:27:35 +08:00
|
|
|
void free_page(struct page_pool *pool, struct page *page);
|
2018-10-29 23:28:32 +08:00
|
|
|
#endif /* PAGE_H */
|