From nobody Wed May 14 10:45:32 2025
Delivered-To: importer@patchew.org
Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28
as permitted sender) client-ip=209.132.183.28;
envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com;
Authentication-Results: mx.zohomail.com;
spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as
permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com;
dmarc=pass(p=none dis=none) header.from=redhat.com
Return-Path:
Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by
mx.zohomail.com
with SMTPS id 1524498293750818.6672192040611;
Mon, 23 Apr 2018 08:44:53 -0700 (PDT)
Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com
[10.5.11.16])
(using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits))
(No client certificate requested)
by mx1.redhat.com (Postfix) with ESMTPS id CB46B59;
Mon, 23 Apr 2018 15:44:51 +0000 (UTC)
Received: from colo-mx.corp.redhat.com
(colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20])
by smtp.corp.redhat.com (Postfix) with ESMTPS id 82B4A65370;
Mon, 23 Apr 2018 15:44:50 +0000 (UTC)
Received: from lists01.pubmisc.prod.ext.phx2.redhat.com
(lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33])
by colo-mx.corp.redhat.com (Postfix) with ESMTP id DF50F1809547;
Mon, 23 Apr 2018 15:44:47 +0000 (UTC)
Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com
[10.11.54.4])
by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP
id w3NFiikF024407 for ;
Mon, 23 Apr 2018 11:44:44 -0400
Received: by smtp.corp.redhat.com (Postfix)
id 735F7200BCB2; Mon, 23 Apr 2018 15:44:44 +0000 (UTC)
Received: from moe.brq.redhat.com (unknown [10.43.2.192])
by smtp.corp.redhat.com (Postfix) with ESMTP id 178FC2026DFD
for ; Mon, 23 Apr 2018 15:44:43 +0000 (UTC)
From: Michal Privoznik
To: libvir-list@redhat.com
Date: Mon, 23 Apr 2018 17:44:38 +0200
Message-Id:
<905d66675fae0c9d37a4f759a1f106920e622daa.1524498278.git.mprivozn@redhat.com>
X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4
X-loop: libvir-list@redhat.com
Subject: [libvirt] [PATCH] virNumaGetHugePageInfo: Return page_avail and
page_free as ULL
X-BeenThere: libvir-list@redhat.com
X-Mailman-Version: 2.1.12
Precedence: junk
List-Id: Development discussions about the libvirt library & tools
List-Unsubscribe: ,
List-Archive:
List-Post:
List-Help:
List-Subscribe: ,
MIME-Version: 1.0
Content-Transfer-Encoding: quoted-printable
Sender: libvir-list-bounces@redhat.com
Errors-To: libvir-list-bounces@redhat.com
X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16
X-Greylist: Sender IP whitelisted,
not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]);
Mon, 23 Apr 2018 15:44:52 +0000 (UTC)
X-ZohoMail: RSF_0 Z_629925259 SPT_0
Content-Type: text/plain; charset="utf-8"
https://bugzilla.redhat.com/show_bug.cgi?id=3D1569678
On some large systems (with ~400GB of RAM) it is possible for
unsigned int to overflow in which case we report invalid number
of 4K pages pool size. Switch to unsigned long long.
Signed-off-by: Michal Privoznik
Reviewed-by: Daniel P. Berrang=C3=A9
---
src/conf/capabilities.c | 5 +++--
src/conf/capabilities.h | 2 +-
src/util/virhostmem.c | 2 +-
src/util/virnuma.c | 32 ++++++++++++++++++--------------
src/util/virnuma.h | 8 ++++----
tests/virnumamock.c | 4 ++--
6 files changed, 29 insertions(+), 24 deletions(-)
diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c
index c4ee7efb5f..dd2fc77f91 100644
--- a/src/conf/capabilities.c
+++ b/src/conf/capabilities.c
@@ -816,7 +816,7 @@ virCapabilitiesFormatNUMATopology(virBufferPtr buf,
cells[i]->mem);
=20
for (j =3D 0; j < cells[i]->npageinfo; j++) {
- virBufferAsprintf(buf, "%zu
\n",
+ virBufferAsprintf(buf, "%llu=
pages>\n",
cells[i]->pageinfo[j].size,
cells[i]->pageinfo[j].avail);
}
@@ -1351,7 +1351,8 @@ virCapabilitiesGetNUMAPagesInfo(int node,
int *npageinfo)
{
int ret =3D -1;
- unsigned int *pages_size =3D NULL, *pages_avail =3D NULL;
+ unsigned int *pages_size =3D NULL;
+ unsigned long long *pages_avail =3D NULL;
size_t npages, i;
=20
if (virNumaGetPages(node, &pages_size, &pages_avail, NULL, &npages) < =
0)
diff --git a/src/conf/capabilities.h b/src/conf/capabilities.h
index 694a3590bf..f0a06a24df 100644
--- a/src/conf/capabilities.h
+++ b/src/conf/capabilities.h
@@ -107,7 +107,7 @@ typedef struct _virCapsHostNUMACellPageInfo virCapsHost=
NUMACellPageInfo;
typedef virCapsHostNUMACellPageInfo *virCapsHostNUMACellPageInfoPtr;
struct _virCapsHostNUMACellPageInfo {
unsigned int size; /* page size in kibibytes */
- size_t avail; /* the size of pool */
+ unsigned long long avail; /* the size of pool */
};
=20
typedef struct _virCapsHostNUMACell virCapsHostNUMACell;
diff --git a/src/util/virhostmem.c b/src/util/virhostmem.c
index 11efe8c502..c923a1edf5 100644
--- a/src/util/virhostmem.c
+++ b/src/util/virhostmem.c
@@ -783,7 +783,7 @@ virHostMemGetFreePages(unsigned int npages,
for (cell =3D startCell; cell <=3D lastCell; cell++) {
for (i =3D 0; i < npages; i++) {
unsigned int page_size =3D pages[i];
- unsigned int page_free;
+ unsigned long long page_free;
=20
if (virNumaGetPageInfo(cell, page_size, 0, NULL, &page_free) <=
0)
goto cleanup;
diff --git a/src/util/virnuma.c b/src/util/virnuma.c
index bebe301f8d..784db0a7ce 100644
--- a/src/util/virnuma.c
+++ b/src/util/virnuma.c
@@ -563,8 +563,8 @@ virNumaGetHugePageInfoDir(char **path, int node)
static int
virNumaGetHugePageInfo(int node,
unsigned int page_size,
- unsigned int *page_avail,
- unsigned int *page_free)
+ unsigned long long *page_avail,
+ unsigned long long *page_free)
{
int ret =3D -1;
char *path =3D NULL;
@@ -579,7 +579,7 @@ virNumaGetHugePageInfo(int node,
if (virFileReadAll(path, 1024, &buf) < 0)
goto cleanup;
=20
- if (virStrToLong_ui(buf, &end, 10, page_avail) < 0 ||
+ if (virStrToLong_ull(buf, &end, 10, page_avail) < 0 ||
*end !=3D '\n') {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("unable to parse: %s"),
@@ -598,7 +598,7 @@ virNumaGetHugePageInfo(int node,
if (virFileReadAll(path, 1024, &buf) < 0)
goto cleanup;
=20
- if (virStrToLong_ui(buf, &end, 10, page_free) < 0 ||
+ if (virStrToLong_ull(buf, &end, 10, page_free) < 0 ||
*end !=3D '\n') {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("unable to parse: %s"),
@@ -645,8 +645,8 @@ int
virNumaGetPageInfo(int node,
unsigned int page_size,
unsigned long long huge_page_sum,
- unsigned int *page_avail,
- unsigned int *page_free)
+ unsigned long long *page_avail,
+ unsigned long long *page_free)
{
int ret =3D -1;
long system_page_size =3D virGetSystemPageSize();
@@ -709,8 +709,8 @@ virNumaGetPageInfo(int node,
int
virNumaGetPages(int node,
unsigned int **pages_size,
- unsigned int **pages_avail,
- unsigned int **pages_free,
+ unsigned long long **pages_avail,
+ unsigned long long **pages_free,
size_t *npages)
{
int ret =3D -1;
@@ -718,7 +718,9 @@ virNumaGetPages(int node,
DIR *dir =3D NULL;
int direrr =3D 0;
struct dirent *entry;
- unsigned int *tmp_size =3D NULL, *tmp_avail =3D NULL, *tmp_free =3D NU=
LL;
+ unsigned int *tmp_size =3D NULL;
+ unsigned long long *tmp_avail =3D NULL;
+ unsigned long long *tmp_free =3D NULL;
unsigned int ntmp =3D 0;
size_t i;
bool exchange;
@@ -744,7 +746,9 @@ virNumaGetPages(int node,
=20
while (dir && (direrr =3D virDirRead(dir, &entry, path)) > 0) {
const char *page_name =3D entry->d_name;
- unsigned int page_size, page_avail =3D 0, page_free =3D 0;
+ unsigned int page_size;
+ unsigned long long page_avail =3D 0;
+ unsigned long long page_free =3D 0;
char *end;
=20
/* Just to give you a hint, we're dealing with this:
@@ -934,8 +938,8 @@ int
virNumaGetPageInfo(int node ATTRIBUTE_UNUSED,
unsigned int page_size ATTRIBUTE_UNUSED,
unsigned long long huge_page_sum ATTRIBUTE_UNUSED,
- unsigned int *page_avail ATTRIBUTE_UNUSED,
- unsigned int *page_free ATTRIBUTE_UNUSED)
+ unsigned long long *page_avail ATTRIBUTE_UNUSED,
+ unsigned long long *page_free ATTRIBUTE_UNUSED)
{
virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
_("page info is not supported on this platform"));
@@ -946,8 +950,8 @@ virNumaGetPageInfo(int node ATTRIBUTE_UNUSED,
int
virNumaGetPages(int node ATTRIBUTE_UNUSED,
unsigned int **pages_size ATTRIBUTE_UNUSED,
- unsigned int **pages_avail ATTRIBUTE_UNUSED,
- unsigned int **pages_free ATTRIBUTE_UNUSED,
+ unsigned long long **pages_avail ATTRIBUTE_UNUSED,
+ unsigned long long **pages_free ATTRIBUTE_UNUSED,
size_t *npages ATTRIBUTE_UNUSED)
{
virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
diff --git a/src/util/virnuma.h b/src/util/virnuma.h
index e4e1fd0b97..a3ffb6d6c7 100644
--- a/src/util/virnuma.h
+++ b/src/util/virnuma.h
@@ -52,12 +52,12 @@ int virNumaGetNodeCPUs(int node, virBitmapPtr *cpus) AT=
TRIBUTE_NOINLINE;
int virNumaGetPageInfo(int node,
unsigned int page_size,
unsigned long long huge_page_sum,
- unsigned int *page_avail,
- unsigned int *page_free);
+ unsigned long long *page_avail,
+ unsigned long long *page_free);
int virNumaGetPages(int node,
unsigned int **pages_size,
- unsigned int **pages_avail,
- unsigned int **pages_free,
+ unsigned long long **pages_avail,
+ unsigned long long **pages_free,
size_t *npages)
ATTRIBUTE_NONNULL(5) ATTRIBUTE_NOINLINE;
int virNumaSetPagePoolSize(int node,
diff --git a/tests/virnumamock.c b/tests/virnumamock.c
index d8f90b81b3..475efc1f34 100644
--- a/tests/virnumamock.c
+++ b/tests/virnumamock.c
@@ -125,8 +125,8 @@ virNumaGetDistances(int node ATTRIBUTE_UNUSED,
int
virNumaGetPages(int node,
unsigned int **pages_size,
- unsigned int **pages_avail,
- unsigned int **pages_free,
+ unsigned long long **pages_avail,
+ unsigned long long **pages_free,
size_t *npages)
{
const int pages_def[] =3D { 4, 2 * 1024, 1 * 1024 * 1024};
--=20
2.16.1
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list