From: Oliver Kurth Date: Tue, 5 Jun 2018 22:47:37 +0000 (-0700) Subject: Change the balloon driver internals to 64-bits. X-Git-Tag: stable-11.0.0~555 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ab11ce6bd158f9bb08de323ba9b518b259ee2488;p=thirdparty%2Fopen-vm-tools.git Change the balloon driver internals to 64-bits. As a first step towards making the driver being able to balloon 16TB+, let's change all the internals to use 64-bits values for the counters. Initially, I wanted to only touch the windows driver, as this is the one that we really care about, but since some code and datastructure are shared, I had to modify pretty much all drivers. The next step will be to change the drivers capabilities by adding BALLOON_64_BIT_TARGET. --- diff --git a/open-vm-tools/modules/freebsd/vmmemctl/os.c b/open-vm-tools/modules/freebsd/vmmemctl/os.c index 5621398ed..0894abfb6 100644 --- a/open-vm-tools/modules/freebsd/vmmemctl/os.c +++ b/open-vm-tools/modules/freebsd/vmmemctl/os.c @@ -816,8 +816,8 @@ vmmemctl_sysctl(SYSCTL_HANDLER_ARGS) /* format size info */ len += snprintf(buf + len, sizeof(buf) - len, - "target: %8d pages\n" - "current: %8d pages\n", + "target: %8"FMT64"u pages\n" + "current: %8"FMT64"u pages\n", stats->nPagesTarget, stats->nPages); diff --git a/open-vm-tools/modules/shared/vmmemctl/backdoor_balloon.c b/open-vm-tools/modules/shared/vmmemctl/backdoor_balloon.c index 9bf41630b..b6633f6a8 100644 --- a/open-vm-tools/modules/shared/vmmemctl/backdoor_balloon.c +++ b/open-vm-tools/modules/shared/vmmemctl/backdoor_balloon.c @@ -1,5 +1,5 @@ /********************************************************* - * Copyright (C) 2012,2014 VMware, Inc. All rights reserved. + * Copyright (C) 2012,2014,2018 VMware, Inc. All rights reserved. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published @@ -78,9 +78,9 @@ static int BackdoorCmd(uint16 cmd, // IN - size_t arg1, // IN + uint64 arg1, // IN uint32 arg2, // IN - uint32 *out, // OUT + uint64 *out, // OUT int *resetFlag) // OUT { Backdoor_proto bp; @@ -88,7 +88,8 @@ BackdoorCmd(uint16 cmd, // IN /* prepare backdoor args */ bp.in.cx.halfs.low = cmd; - bp.in.size = arg1; + bp.in.size = (size_t)arg1; + ASSERT(bp.in.size == arg1); bp.in.si.word = arg2; /* invoke backdoor */ @@ -103,11 +104,19 @@ BackdoorCmd(uint16 cmd, // IN } if (out) { +#ifdef VM_X86_64 + if (cmd == BALLOON_BDOOR_CMD_START) { + *out = bp.out.cx.quad; + } else { + *out = bp.out.bx.quad; + } +#else if (cmd == BALLOON_BDOOR_CMD_START) { *out = bp.out.cx.word; } else { *out = bp.out.bx.word; } +#endif } return status; @@ -134,7 +143,7 @@ int Backdoor_MonitorStart(Balloon *b, // IN/OUT uint32 protoVersion) // IN { - uint32 capabilities; + uint64 capabilities; int status = BackdoorCmd(BALLOON_BDOOR_CMD_START, protoVersion, 0, &capabilities, &b->resetFlag); /* @@ -191,6 +200,14 @@ Backdoor_MonitorGuestType(Balloon *b) // IN/OUT } +static Bool +BackdoorHasCapability(Balloon *b, + uint32 capability) +{ + return (b->hypervisorCapabilities & capability) == capability; +} + + /* *---------------------------------------------------------------------- * @@ -221,23 +238,29 @@ Backdoor_MonitorGuestType(Balloon *b) // IN/OUT int Backdoor_MonitorGetTarget(Balloon *b, // IN/OUT - uint32 *target) // OUT + uint64 *target) // OUT { - unsigned long limit; - uint32 limit32; + uint64 limit; int status; limit = OS_ReservedPageGetLimit(); - /* Ensure limit fits in 32-bits */ - limit32 = (uint32)limit; - if (limit32 != limit) { - return BALLOON_FAILURE; + if (!BackdoorHasCapability(b, BALLOON_64_BIT_TARGET)) { + uint32 limit32; + /* Ensure limit fits in 32-bits */ + limit32 = (uint32)limit; + if (limit32 != limit) { + return BALLOON_FAILURE; + } } status = BackdoorCmd(BALLOON_BDOOR_CMD_TARGET, limit, 0, target, &b->resetFlag); + if (!BackdoorHasCapability(b, BALLOON_64_BIT_TARGET)) { + *target = MAX(MAX_UINT32, *target); + } + /* update stats */ STATS_INC(b->stats.target); if (status != BALLOON_SUCCESS) { @@ -270,18 +293,23 @@ Backdoor_MonitorGetTarget(Balloon *b, // IN/OUT int Backdoor_MonitorLockPage(Balloon *b, // IN/OUT PPN64 ppn, // IN - uint32 *target) // OUT + uint64 *target) // OUT { int status; - uint32 ppn32 = (uint32)ppn; - /* Ensure PPN fits in 32-bits, i.e. guest memory is limited to 16TB. */ - if (ppn32 != ppn) { - return BALLOON_ERROR_PPN_INVALID; + if (!BackdoorHasCapability(b, BALLOON_64_BIT_TARGET)) { + uint32 ppn32 = (uint32)ppn; + /* Ensure PPN fits in 32-bits, i.e. guest memory is limited to 16TB. */ + if (ppn32 != ppn) { + return BALLOON_ERROR_PPN_INVALID; + } } - status = BackdoorCmd(BALLOON_BDOOR_CMD_LOCK, ppn32, 0, target, + status = BackdoorCmd(BALLOON_BDOOR_CMD_LOCK, ppn, 0, target, &b->resetFlag); + if (!BackdoorHasCapability(b, BALLOON_64_BIT_TARGET)) { + *target = MAX(MAX_UINT32, *target); + } /* update stats */ STATS_INC(b->stats.lock[FALSE]); @@ -314,18 +342,24 @@ Backdoor_MonitorLockPage(Balloon *b, // IN/OUT int Backdoor_MonitorUnlockPage(Balloon *b, // IN/OUT PPN64 ppn, // IN - uint32 *target) // OUT + uint64 *target) // OUT { int status; - uint32 ppn32 = (uint32)ppn; - /* Ensure PPN fits in 32-bits, i.e. guest memory is limited to 16TB. */ - if (ppn32 != ppn) { - return BALLOON_ERROR_PPN_INVALID; + if (!BackdoorHasCapability(b, BALLOON_64_BIT_TARGET)) { + uint32 ppn32 = (uint32)ppn; + + /* Ensure PPN fits in 32-bits, i.e. guest memory is limited to 16TB. */ + if (ppn32 != ppn) { + return BALLOON_ERROR_PPN_INVALID; + } } - status = BackdoorCmd(BALLOON_BDOOR_CMD_UNLOCK, ppn32, 0, target, + status = BackdoorCmd(BALLOON_BDOOR_CMD_UNLOCK, ppn, 0, target, &b->resetFlag); + if (!BackdoorHasCapability(b, BALLOON_64_BIT_TARGET)) { + *target = MAX(MAX_UINT32, *target); + } /* update stats */ STATS_INC(b->stats.unlock[FALSE]); @@ -357,7 +391,7 @@ Backdoor_MonitorLockPagesBatched(Balloon *b, // IN/OUT PPN64 ppn, // IN uint32 nPages, // IN int isLargePage, // IN - uint32 *target) // OUT + uint64 *target) // OUT { int status; uint16 cmd; @@ -369,6 +403,9 @@ Backdoor_MonitorLockPagesBatched(Balloon *b, // IN/OUT } status = BackdoorCmd(cmd, (size_t)ppn, nPages, target, &b->resetFlag); + if (!BackdoorHasCapability(b, BALLOON_64_BIT_TARGET)) { + *target = MAX(MAX_UINT32, *target); + } /* update stats */ STATS_INC(b->stats.lock[isLargePage]); @@ -400,7 +437,7 @@ Backdoor_MonitorUnlockPagesBatched(Balloon *b, // IN/OUT PPN64 ppn, // IN uint32 nPages, // IN int isLargePage, // IN - uint32 *target) // OUT + uint64 *target) // OUT { int status; uint16 cmd; @@ -412,6 +449,9 @@ Backdoor_MonitorUnlockPagesBatched(Balloon *b, // IN/OUT } status = BackdoorCmd(cmd, (size_t)ppn, nPages, target, &b->resetFlag); + if (!BackdoorHasCapability(b, BALLOON_64_BIT_TARGET)) { + *target = MAX(MAX_UINT32, *target); + } /* update stats */ STATS_INC(b->stats.unlock[isLargePage]); diff --git a/open-vm-tools/modules/shared/vmmemctl/backdoor_balloon.h b/open-vm-tools/modules/shared/vmmemctl/backdoor_balloon.h index 7256c71ea..6097d2979 100644 --- a/open-vm-tools/modules/shared/vmmemctl/backdoor_balloon.h +++ b/open-vm-tools/modules/shared/vmmemctl/backdoor_balloon.h @@ -1,5 +1,5 @@ /********************************************************* - * Copyright (C) 2007,2014 VMware, Inc. All rights reserved. + * Copyright (C) 2007,2014,2018 VMware, Inc. All rights reserved. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published @@ -71,12 +71,12 @@ int Backdoor_MonitorStart(Balloon *b, uint32 protoVersion); int Backdoor_MonitorGuestType(Balloon *b); -int Backdoor_MonitorGetTarget(Balloon *b, uint32 *target); -int Backdoor_MonitorLockPage(Balloon *b, PPN64 ppn, uint32 *target); -int Backdoor_MonitorUnlockPage(Balloon *b, PPN64 ppn, uint32 *target); +int Backdoor_MonitorGetTarget(Balloon *b, uint64 *target); +int Backdoor_MonitorLockPage(Balloon *b, PPN64 ppn, uint64 *target); +int Backdoor_MonitorUnlockPage(Balloon *b, PPN64 ppn, uint64 *target); int Backdoor_MonitorLockPagesBatched(Balloon *b, PPN64 ppn, uint32 nPages, - int isLargePages, uint32 *target); + int isLargePages, uint64 *target); int Backdoor_MonitorUnlockPagesBatched(Balloon *b, PPN64 ppn, uint32 nPages, - int isLargePages, uint32 *target); + int isLargePages, uint64 *target); #endif /* _BACKDOOR_BALLOON_H_ */ diff --git a/open-vm-tools/modules/shared/vmmemctl/vmballoon.c b/open-vm-tools/modules/shared/vmmemctl/vmballoon.c index 85251801f..05eddb7a1 100644 --- a/open-vm-tools/modules/shared/vmmemctl/vmballoon.c +++ b/open-vm-tools/modules/shared/vmmemctl/vmballoon.c @@ -103,19 +103,19 @@ extern "C" { * Balloon operations */ static void BalloonPageFree(Balloon *b, int isLargePage); -static void BalloonAdjustSize(Balloon *b, uint32 target); +static void BalloonAdjustSize(Balloon *b, uint64 target); static void BalloonReset(Balloon *b); static void BalloonAddPage(Balloon *b, uint16 idx, PageHandle page); static void BalloonAddPageBatched(Balloon *b, uint16 idx, PageHandle page); static int BalloonLock(Balloon *b, uint16 nPages, int isLargePage, - uint32 *target); + uint64 *target); static int BalloonLockBatched(Balloon *b, uint16 nPages, int isLargePages, - uint32 *target); + uint64 *target); static int BalloonUnlock(Balloon *b, uint16 nPages, int isLargePages, - uint32 *target); + uint64 *target); static int BalloonUnlockBatched(Balloon *b, uint16 nPages, int IsLargePages, - uint32 *target); + uint64 *target); /* * Globals @@ -429,7 +429,7 @@ void Balloon_QueryAndExecute(void) { Balloon *b = &globalBalloon; - uint32 target = 0; // Silence compiler warning. + uint64 target = 0; // Silence compiler warning. int status; /* update stats */ @@ -749,7 +749,7 @@ BalloonPageFree(Balloon *b, // IN/OUT static void BalloonInflate(Balloon *b, // IN/OUT - uint32 target) // IN + uint64 target) // IN { uint32 nEntries; unsigned int rate; @@ -922,7 +922,7 @@ static int BalloonLockBatched(Balloon *b, // IN/OUT uint16 nEntries, // IN int isLargePages, // IN - uint32 *target) // OUT + uint64 *target) // OUT { int status; uint32 i; @@ -1037,7 +1037,7 @@ static int BalloonUnlockBatched(Balloon *b, // IN/OUT uint16 nEntries, // IN int isLargePages, // IN - uint32 *target) // OUT + uint64 *target) // OUT { uint32 i; int status = BALLOON_SUCCESS; @@ -1139,9 +1139,9 @@ static int BalloonLock(Balloon *b, // IN/OUT uint16 nPages, // IN int isLargePage, // IN - uint32 *target) // OUT + uint64 *target) // OUT { - PPNTMP pagePPN; + PPN64 pagePPN; BalloonChunk *chunk; int status; @@ -1214,9 +1214,9 @@ static int BalloonUnlock(Balloon *b, // IN/OUT uint16 nPages, // IN int isLargePage, // IN - uint32 *target) // OUT + uint64 *target) // OUT { - PPNTMP pagePPN = PA_2_PPN(OS_ReservedPageGetPA(b->pageHandle)); + PPN64 pagePPN = PA_2_PPN(OS_ReservedPageGetPA(b->pageHandle)); int status = Backdoor_MonitorUnlockPage(b, pagePPN, target); ASSERT(!isLargePage); @@ -1286,7 +1286,7 @@ BalloonAddPage(Balloon *b, // IN/OUT static void BalloonDeflateInt(Balloon *b, // IN/OUT - uint32 target, // IN + uint64 target, // IN int isLargePages) // IN { int status = BALLOON_SUCCESS; @@ -1378,7 +1378,7 @@ BalloonDeflateInt(Balloon *b, // IN/OUT static void BalloonDeflate(Balloon *b, // IN/OUT - uint32 target) // IN + uint64 target) // IN { /* Prefer to unlock small pages over unlocking large pages */ BalloonDeflateInt(b, target, FALSE); @@ -1405,7 +1405,7 @@ BalloonDeflate(Balloon *b, // IN/OUT static void BalloonAdjustSize(Balloon *b, // IN/OUT - uint32 target) // IN + uint64 target) // IN { /* * When we only deal with large pages it can happen that we overshoot our diff --git a/open-vm-tools/modules/shared/vmmemctl/vmballoon.h b/open-vm-tools/modules/shared/vmmemctl/vmballoon.h index 42c760142..84b400fb5 100644 --- a/open-vm-tools/modules/shared/vmmemctl/vmballoon.h +++ b/open-vm-tools/modules/shared/vmmemctl/vmballoon.h @@ -1,5 +1,5 @@ /********************************************************* - * Copyright (C) 2000-2012,2014 VMware, Inc. All rights reserved. + * Copyright (C) 2000-2012,2014,2018 VMware, Inc. All rights reserved. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published @@ -84,8 +84,8 @@ typedef enum BalloonPageAllocType { typedef struct { /* current status */ - uint32 nPages; - uint32 nPagesTarget; + uint64 nPages; + uint64 nPagesTarget; /* adjustment rates */ uint32 rateNoSleepAlloc; @@ -147,10 +147,10 @@ typedef struct { BalloonGuest guestType; /* balloon size (in small pages) */ - int nPages; + uint64 nPages; /* target balloon size (in small pages) */ - int nPagesTarget; + uint64 nPagesTarget; /* reset flag */ int resetFlag; @@ -182,8 +182,8 @@ typedef struct { typedef struct BalloonOps { void (*addPage)(Balloon *b, uint16 idx, PageHandle entries); - int (*lock)(Balloon *b, uint16 nPages, int isLargePages, uint32 *target); - int (*unlock)(Balloon *b, uint16 nPages, int isLargePages, uint32 *target); + int (*lock)(Balloon *b, uint16 nPages, int isLargePages, uint64 *target); + int (*unlock)(Balloon *b, uint16 nPages, int isLargePages, uint64 *target); } BalloonOps; /*