Skip to content

Commit 2af5e7b

Browse files
himadricsSasha Levin
authored andcommitted
Drivers: hv: balloon: Remove dependencies on guest page size
Hyper-V assumes page size to be 4K. This might not be the case for ARM64 architecture. Hence use hyper-v specific page size and page shift definitions to avoid conflicts between different host and guest page sizes on ARM64. Also, remove some old and incorrect comments and redefine ballooning granularities to handle larger page sizes correctly. Signed-off-by: Himadri Pandya <[email protected]> Reviewed-by: Michael Kelley <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent 53edce0 commit 2af5e7b

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

drivers/hv/hv_balloon.c

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <linux/percpu_counter.h>
2424

2525
#include <linux/hyperv.h>
26+
#include <asm/hyperv-tlfs.h>
2627

2728
#define CREATE_TRACE_POINTS
2829
#include "hv_trace_balloon.h"
@@ -341,8 +342,6 @@ struct dm_unballoon_response {
341342
*
342343
* mem_range: Memory range to hot add.
343344
*
344-
* On Linux we currently don't support this since we cannot hot add
345-
* arbitrary granularity of memory.
346345
*/
347346

348347
struct dm_hot_add {
@@ -477,7 +476,7 @@ module_param(pressure_report_delay, uint, (S_IRUGO | S_IWUSR));
477476
MODULE_PARM_DESC(pressure_report_delay, "Delay in secs in reporting pressure");
478477
static atomic_t trans_id = ATOMIC_INIT(0);
479478

480-
static int dm_ring_size = (5 * PAGE_SIZE);
479+
static int dm_ring_size = 20 * 1024;
481480

482481
/*
483482
* Driver specific state.
@@ -493,10 +492,10 @@ enum hv_dm_state {
493492
};
494493

495494

496-
static __u8 recv_buffer[PAGE_SIZE];
497-
static __u8 balloon_up_send_buffer[PAGE_SIZE];
498-
#define PAGES_IN_2M 512
499-
#define HA_CHUNK (32 * 1024)
495+
static __u8 recv_buffer[HV_HYP_PAGE_SIZE];
496+
static __u8 balloon_up_send_buffer[HV_HYP_PAGE_SIZE];
497+
#define PAGES_IN_2M (2 * 1024 * 1024 / PAGE_SIZE)
498+
#define HA_CHUNK (128 * 1024 * 1024 / PAGE_SIZE)
500499

501500
struct hv_dynmem_device {
502501
struct hv_device *dev;
@@ -1076,7 +1075,7 @@ static void process_info(struct hv_dynmem_device *dm, struct dm_info_msg *msg)
10761075
__u64 *max_page_count = (__u64 *)&info_hdr[1];
10771076

10781077
pr_info("Max. dynamic memory size: %llu MB\n",
1079-
(*max_page_count) >> (20 - PAGE_SHIFT));
1078+
(*max_page_count) >> (20 - HV_HYP_PAGE_SHIFT));
10801079
}
10811080

10821081
break;
@@ -1218,7 +1217,7 @@ static unsigned int alloc_balloon_pages(struct hv_dynmem_device *dm,
12181217

12191218
for (i = 0; (i * alloc_unit) < num_pages; i++) {
12201219
if (bl_resp->hdr.size + sizeof(union dm_mem_page_range) >
1221-
PAGE_SIZE)
1220+
HV_HYP_PAGE_SIZE)
12221221
return i * alloc_unit;
12231222

12241223
/*
@@ -1274,9 +1273,9 @@ static void balloon_up(struct work_struct *dummy)
12741273

12751274
/*
12761275
* We will attempt 2M allocations. However, if we fail to
1277-
* allocate 2M chunks, we will go back to 4k allocations.
1276+
* allocate 2M chunks, we will go back to PAGE_SIZE allocations.
12781277
*/
1279-
alloc_unit = 512;
1278+
alloc_unit = PAGES_IN_2M;
12801279

12811280
avail_pages = si_mem_available();
12821281
floor = compute_balloon_floor();
@@ -1292,7 +1291,7 @@ static void balloon_up(struct work_struct *dummy)
12921291
}
12931292

12941293
while (!done) {
1295-
memset(balloon_up_send_buffer, 0, PAGE_SIZE);
1294+
memset(balloon_up_send_buffer, 0, HV_HYP_PAGE_SIZE);
12961295
bl_resp = (struct dm_balloon_response *)balloon_up_send_buffer;
12971296
bl_resp->hdr.type = DM_BALLOON_RESPONSE;
12981297
bl_resp->hdr.size = sizeof(struct dm_balloon_response);
@@ -1491,7 +1490,7 @@ static void balloon_onchannelcallback(void *context)
14911490

14921491
memset(recv_buffer, 0, sizeof(recv_buffer));
14931492
vmbus_recvpacket(dev->channel, recv_buffer,
1494-
PAGE_SIZE, &recvlen, &requestid);
1493+
HV_HYP_PAGE_SIZE, &recvlen, &requestid);
14951494

14961495
if (recvlen > 0) {
14971496
dm_msg = (struct dm_message *)recv_buffer;

0 commit comments

Comments
 (0)