Skip to content

Commit b35875d

Browse files
Quentin PerretMarc Zyngier
authored andcommitted
KVM: arm64: Make hyp_page::order a u8
We don't need 16 bits to store the hyp page order, and we'll need some bits to store page ownership data soon, so let's reduce the order member. Tested-by: Fuad Tabba <[email protected]> Reviewed-by: Fuad Tabba <[email protected]> Signed-off-by: Quentin Perret <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Marc Zyngier <[email protected]>
1 parent d4fc42a commit b35875d

File tree

3 files changed

+13
-12
lines changed

3 files changed

+13
-12
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#include <nvhe/memory.h>
88
#include <nvhe/spinlock.h>
99

10-
#define HYP_NO_ORDER USHRT_MAX
10+
#define HYP_NO_ORDER ((u8)(~0))
1111

1212
struct hyp_pool {
1313
/*
@@ -19,11 +19,11 @@ struct hyp_pool {
1919
struct list_head free_area[NR_PAGE_ORDERS];
2020
phys_addr_t range_start;
2121
phys_addr_t range_end;
22-
unsigned short max_order;
22+
u8 max_order;
2323
};
2424

2525
/* Allocation */
26-
void *hyp_alloc_pages(struct hyp_pool *pool, unsigned short order);
26+
void *hyp_alloc_pages(struct hyp_pool *pool, u8 order);
2727
void hyp_split_page(struct hyp_page *page);
2828
void hyp_get_page(struct hyp_pool *pool, void *addr);
2929
void hyp_put_page(struct hyp_pool *pool, void *addr);

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,9 @@ static inline enum pkvm_page_state pkvm_getstate(enum kvm_pgtable_prot prot)
4141
}
4242

4343
struct hyp_page {
44-
unsigned short refcount;
45-
unsigned short order;
44+
u16 refcount;
45+
u8 order;
46+
u8 reserved;
4647
};
4748

4849
extern u64 __hyp_vmemmap;

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ u64 __hyp_vmemmap;
3232
*/
3333
static struct hyp_page *__find_buddy_nocheck(struct hyp_pool *pool,
3434
struct hyp_page *p,
35-
unsigned short order)
35+
u8 order)
3636
{
3737
phys_addr_t addr = hyp_page_to_phys(p);
3838

@@ -51,7 +51,7 @@ static struct hyp_page *__find_buddy_nocheck(struct hyp_pool *pool,
5151
/* Find a buddy page currently available for allocation */
5252
static struct hyp_page *__find_buddy_avail(struct hyp_pool *pool,
5353
struct hyp_page *p,
54-
unsigned short order)
54+
u8 order)
5555
{
5656
struct hyp_page *buddy = __find_buddy_nocheck(pool, p, order);
5757

@@ -94,7 +94,7 @@ static void __hyp_attach_page(struct hyp_pool *pool,
9494
struct hyp_page *p)
9595
{
9696
phys_addr_t phys = hyp_page_to_phys(p);
97-
unsigned short order = p->order;
97+
u8 order = p->order;
9898
struct hyp_page *buddy;
9999

100100
memset(hyp_page_to_virt(p), 0, PAGE_SIZE << p->order);
@@ -129,7 +129,7 @@ static void __hyp_attach_page(struct hyp_pool *pool,
129129

130130
static struct hyp_page *__hyp_extract_page(struct hyp_pool *pool,
131131
struct hyp_page *p,
132-
unsigned short order)
132+
u8 order)
133133
{
134134
struct hyp_page *buddy;
135135

@@ -183,7 +183,7 @@ void hyp_get_page(struct hyp_pool *pool, void *addr)
183183

184184
void hyp_split_page(struct hyp_page *p)
185185
{
186-
unsigned short order = p->order;
186+
u8 order = p->order;
187187
unsigned int i;
188188

189189
p->order = 0;
@@ -195,10 +195,10 @@ void hyp_split_page(struct hyp_page *p)
195195
}
196196
}
197197

198-
void *hyp_alloc_pages(struct hyp_pool *pool, unsigned short order)
198+
void *hyp_alloc_pages(struct hyp_pool *pool, u8 order)
199199
{
200-
unsigned short i = order;
201200
struct hyp_page *p;
201+
u8 i = order;
202202

203203
hyp_spin_lock(&pool->lock);
204204

0 commit comments

Comments
 (0)