lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20220809095358.2203355-1-alexander.atanasov@virtuozzo.com>
Date:   Tue,  9 Aug 2022 12:53:58 +0300
From:   Alexander Atanasov <alexander.atanasov@...tuozzo.com>
To:     "Michael S. Tsirkin" <mst@...hat.com>,
        David Hildenbrand <david@...hat.com>,
        Jason Wang <jasowang@...hat.com>
Cc:     kernel@...nvz.org,
        Alexander Atanasov <alexander.atanasov@...tuozzo.com>,
        Wei Liu <wei.liu@...nel.org>, Nadav Amit <namit@...are.com>,
        virtualization@...ts.linux-foundation.org,
        linux-kernel@...r.kernel.org
Subject: [PATCH v1 2/2] Drivers: virtio: balloon: Report inflated memory

Update the value in page_alloc on balloon fill/leak.

Cc: David Hildenbrand <david@...hat.com>
Cc: Wei Liu <wei.liu@...nel.org>
Cc: Nadav Amit <namit@...are.com>

Signed-off-by: Alexander Atanasov <alexander.atanasov@...tuozzo.com>
---
 drivers/virtio/virtio_balloon.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

Firts user, other balloons i will do if it is accepted to avoid too much emails.


diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c
index b9737da6c4dd..e2693ffbd48b 100644
--- a/drivers/virtio/virtio_balloon.c
+++ b/drivers/virtio/virtio_balloon.c
@@ -208,6 +208,16 @@ static void set_page_pfns(struct virtio_balloon *vb,
 					  page_to_balloon_pfn(page) + i);
 }
 
+static void update_meminfo(struct virtio_balloon *vb)
+{
+	long inflated_kb = vb->num_pages << (VIRTIO_BALLOON_PFN_SHIFT - 10);
+
+	if (virtio_has_feature(vb->vdev, VIRTIO_BALLOON_F_DEFLATE_ON_OOM))
+		inflated_kb = -inflated_kb;
+
+	atomic_long_set(&mem_balloon_inflated_kb, inflated_kb);
+}
+
 static unsigned int fill_balloon(struct virtio_balloon *vb, size_t num)
 {
 	unsigned int num_allocated_pages;
@@ -250,6 +260,7 @@ static unsigned int fill_balloon(struct virtio_balloon *vb, size_t num)
 	}
 
 	num_allocated_pages = vb->num_pfns;
+	update_meminfo(vb);
 	/* Did we get any? */
 	if (vb->num_pfns != 0)
 		tell_host(vb, vb->inflate_vq);
@@ -296,6 +307,7 @@ static unsigned int leak_balloon(struct virtio_balloon *vb, size_t num)
 	}
 
 	num_freed_pages = vb->num_pfns;
+	update_meminfo(vb);
 	/*
 	 * Note that if
 	 * virtio_has_feature(vdev, VIRTIO_BALLOON_F_MUST_TELL_HOST);
@@ -1089,6 +1101,7 @@ static void virtballoon_remove(struct virtio_device *vdev)
 
 	kern_unmount(balloon_mnt);
 #endif
+	update_meminfo(0);
 	kfree(vb);
 }
 
-- 
2.31.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ