]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
Change the balloon driver internals to 64-bits.
authorOliver Kurth <okurth@vmware.com>
Tue, 5 Jun 2018 22:47:37 +0000 (15:47 -0700)
committerOliver Kurth <okurth@vmware.com>
Tue, 5 Jun 2018 22:47:37 +0000 (15:47 -0700)
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.

open-vm-tools/modules/freebsd/vmmemctl/os.c
open-vm-tools/modules/shared/vmmemctl/backdoor_balloon.c
open-vm-tools/modules/shared/vmmemctl/backdoor_balloon.h
open-vm-tools/modules/shared/vmmemctl/vmballoon.c
open-vm-tools/modules/shared/vmmemctl/vmballoon.h

index 5621398edbd78d6e698fabeb17933397acad2193..0894abfb622bab5f608f33b470bc34e7282d49f4 100644 (file)
@@ -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);
 
index 9bf41630ba0676b526717e72e85ae0513113491e..b6633f6a8a840858ee524a7d8b6ba12bf3e33fb5 100644 (file)
@@ -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]);
index 7256c71eaadb0e7e6cf9ec9df850bdaf3d7f02be..6097d2979067873596dea2ba09c4954aa4b39a72 100644 (file)
@@ -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
 
 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_ */
index 85251801fe2ed05f2dbce2e9357bd5efaaf6a8bd..05eddb7a16da9cefd032119338315cd40f0d5a06 100644 (file)
@@ -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
index 42c760142fc3a78ec4e461fe9ed457ea614a1cd1..84b400fb570e90150b980610a9353d393699b666 100644 (file)
@@ -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;
 
 /*