Skip to content

Commit d978b9c

Browse files
Quentin PerretMarc Zyngier
authored andcommitted
KVM: arm64: Remove hyp_pool pointer from struct hyp_page
Each struct hyp_page currently contains a pointer to a hyp_pool struct where the page should be freed if its refcount reaches 0. However, this information can always be inferred from the context in the EL2 code, so drop the pointer to save a few bytes in the vmemmap. Signed-off-by: Quentin Perret <qperret@google.com> Signed-off-by: Marc Zyngier <maz@kernel.org> Link: https://lore.kernel.org/r/20210608114518.748712-6-qperret@google.com
1 parent 7c350ea commit d978b9c

5 files changed

Lines changed: 28 additions & 13 deletions

File tree

arch/arm64/kvm/hyp/include/nvhe/gfp.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ struct hyp_pool {
2424

2525
/* Allocation */
2626
void *hyp_alloc_pages(struct hyp_pool *pool, unsigned int order);
27-
void hyp_get_page(void *addr);
28-
void hyp_put_page(void *addr);
27+
void hyp_get_page(struct hyp_pool *pool, void *addr);
28+
void hyp_put_page(struct hyp_pool *pool, void *addr);
2929

3030
/* Used pages cannot be freed */
3131
int hyp_pool_init(struct hyp_pool *pool, u64 pfn, unsigned int nr_pages,

arch/arm64/kvm/hyp/include/nvhe/memory.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,9 @@
77

88
#include <linux/types.h>
99

10-
struct hyp_pool;
1110
struct hyp_page {
1211
unsigned int refcount;
1312
unsigned int order;
14-
struct hyp_pool *pool;
1513
};
1614

1715
extern u64 __hyp_vmemmap;

arch/arm64/kvm/hyp/nvhe/mem_protect.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,16 @@ static void *host_s2_zalloc_page(void *pool)
4343
return hyp_alloc_pages(pool, 0);
4444
}
4545

46+
static void host_s2_get_page(void *addr)
47+
{
48+
hyp_get_page(&host_s2_pool, addr);
49+
}
50+
51+
static void host_s2_put_page(void *addr)
52+
{
53+
hyp_put_page(&host_s2_pool, addr);
54+
}
55+
4656
static int prepare_s2_pool(void *pgt_pool_base)
4757
{
4858
unsigned long nr_pages, pfn;
@@ -60,8 +70,8 @@ static int prepare_s2_pool(void *pgt_pool_base)
6070
.phys_to_virt = hyp_phys_to_virt,
6171
.virt_to_phys = hyp_virt_to_phys,
6272
.page_count = hyp_page_count,
63-
.get_page = hyp_get_page,
64-
.put_page = hyp_put_page,
73+
.get_page = host_s2_get_page,
74+
.put_page = host_s2_put_page,
6575
};
6676

6777
return 0;

arch/arm64/kvm/hyp/nvhe/page_alloc.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -174,20 +174,18 @@ static void __hyp_put_page(struct hyp_pool *pool, struct hyp_page *p)
174174
* section to guarantee transient states (e.g. a page with null refcount but
175175
* not yet attached to a free list) can't be observed by well-behaved readers.
176176
*/
177-
void hyp_put_page(void *addr)
177+
void hyp_put_page(struct hyp_pool *pool, void *addr)
178178
{
179179
struct hyp_page *p = hyp_virt_to_page(addr);
180-
struct hyp_pool *pool = hyp_page_to_pool(p);
181180

182181
hyp_spin_lock(&pool->lock);
183182
__hyp_put_page(pool, p);
184183
hyp_spin_unlock(&pool->lock);
185184
}
186185

187-
void hyp_get_page(void *addr)
186+
void hyp_get_page(struct hyp_pool *pool, void *addr)
188187
{
189188
struct hyp_page *p = hyp_virt_to_page(addr);
190-
struct hyp_pool *pool = hyp_page_to_pool(p);
191189

192190
hyp_spin_lock(&pool->lock);
193191
hyp_page_ref_inc(p);
@@ -236,7 +234,6 @@ int hyp_pool_init(struct hyp_pool *pool, u64 pfn, unsigned int nr_pages,
236234
/* Init the vmemmap portion */
237235
p = hyp_phys_to_page(phys);
238236
for (i = 0; i < nr_pages; i++) {
239-
p[i].pool = pool;
240237
p[i].order = 0;
241238
hyp_set_page_refcounted(&p[i]);
242239
}

arch/arm64/kvm/hyp/nvhe/setup.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,16 @@ static void *hyp_zalloc_hyp_page(void *arg)
137137
return hyp_alloc_pages(&hpool, 0);
138138
}
139139

140+
static void hpool_get_page(void *addr)
141+
{
142+
hyp_get_page(&hpool, addr);
143+
}
144+
145+
static void hpool_put_page(void *addr)
146+
{
147+
hyp_put_page(&hpool, addr);
148+
}
149+
140150
void __noreturn __pkvm_init_finalise(void)
141151
{
142152
struct kvm_host_data *host_data = this_cpu_ptr(&kvm_host_data);
@@ -160,8 +170,8 @@ void __noreturn __pkvm_init_finalise(void)
160170
.zalloc_page = hyp_zalloc_hyp_page,
161171
.phys_to_virt = hyp_phys_to_virt,
162172
.virt_to_phys = hyp_virt_to_phys,
163-
.get_page = hyp_get_page,
164-
.put_page = hyp_put_page,
173+
.get_page = hpool_get_page,
174+
.put_page = hpool_put_page,
165175
};
166176
pkvm_pgtable.mm_ops = &pkvm_pgtable_mm_ops;
167177

0 commit comments

Comments
 (0)