From: "Michael S. Tsirkin" <mst@redhat.com>
To: linux-kernel@vger.kernel.org
Cc: "Andrew Morton" <akpm@linux-foundation.org>,
"David Hildenbrand" <david@kernel.org>,
"Vlastimil Babka" <vbabka@kernel.org>,
"Brendan Jackman" <jackmanb@google.com>,
"Michal Hocko" <mhocko@suse.com>,
"Suren Baghdasaryan" <surenb@google.com>,
"Jason Wang" <jasowang@redhat.com>,
"Andrea Arcangeli" <aarcange@redhat.com>,
"Dev Jain" <dev.jain@arm.com>,
"Geert Uytterhoeven" <geert@linux-m68k.org>,
"Greg Ungerer" <gerg@linux-m68k.org>,
"Gregory Price" <gourry@gourry.net>,
"Huang, Ying" <ying.huang@linux.alibaba.com>,
"Lance Yang" <lance.yang@linux.dev>,
"Lorenzo Stoakes" <ljs@kernel.org>,
"Magnus Lindholm" <linmag7@gmail.com>,
"Matthew Wilcox" <willy@infradead.org>,
"Miaohe Lin" <linmiaohe@huawei.com>, "Zi Yan" <ziy@nvidia.com>,
linux-mm@kvack.org, virtualization@lists.linux.dev,
"Jason Wang" <jasowangio@gmail.com>,
"Eugenio Pérez" <eperezma@redhat.com>,
"Xuan Zhuo" <xuanzhuo@linux.alibaba.com>
Subject: [PATCH v11 6/7] virtio_balloon: add DEVICE_INIT_REPORTED feature
Date: Thu, 19 Nov 2026 07:02:56 -0500 [thread overview]
Message-ID: <65c518234ce31fac3f6ed436455dcb415d4b1189.1795089715.git.mst@redhat.com> (raw)
In-Reply-To: <cover.1795089715.git.mst@redhat.com>
Add VIRTIO_BALLOON_F_DEVICE_INIT_REPORTED (bit 6) device feature.
When negotiated, the host zeros reported pages on reclaim.
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Assisted-by: LLM
---
drivers/virtio/virtio_balloon.c | 33 ++++++++++++++++++++++++++---
include/uapi/linux/virtio_balloon.h | 1 +
2 files changed, 31 insertions(+), 3 deletions(-)
diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c
index 8c1b47ec17a29..4c6630c5f9599 100644
--- a/drivers/virtio/virtio_balloon.c
+++ b/drivers/virtio/virtio_balloon.c
@@ -19,6 +19,7 @@
#include <linux/wait.h>
#include <linux/mm.h>
#include <linux/page_reporting.h>
+#include <linux/cc_platform.h>
/*
* Balloon device works in 4K page units. So each page is pointed to by
@@ -205,7 +206,9 @@ static int virtballoon_free_page_report(struct page_reporting_dev_info *pr_dev_i
struct virtio_balloon *vb =
container_of(pr_dev_info, struct virtio_balloon, pr_dev_info);
struct virtqueue *vq = vb->reporting_vq;
- unsigned int unused, err;
+ struct scatterlist *entry;
+ unsigned int len, i;
+ int err;
/* We should always be able to add these buffers to an empty queue. */
err = virtqueue_add_inbuf(vq, sg, nents, vb, GFP_NOWAIT);
@@ -221,9 +224,24 @@ static int virtballoon_free_page_report(struct page_reporting_dev_info *pr_dev_i
virtqueue_kick(vq);
/* When host has read buffer, this completes via balloon_ack */
- wait_event(vb->acked, virtqueue_get_buf(vq, &unused));
+ wait_event(vb->acked, virtqueue_get_buf(vq, &len));
- return 0;
+ if (!pr_dev_info->host_zeroes_pages)
+ return 0;
+
+ /*
+ * Only a fully initialized batch may be marked reported when reported
+ * pages are treated as zeroed. A short completion does not identify
+ * which pages were initialized, so reject the entire batch.
+ * Subtract each entry to avoid overflowing a total-length accumulator.
+ */
+ for_each_sg(sg, entry, nents, i) {
+ if (len < entry->length)
+ return -EIO;
+ len -= entry->length;
+ }
+
+ return len ? -EIO : 0;
}
static void set_page_pfns(struct virtio_balloon *vb,
@@ -1043,6 +1061,9 @@ static int virtballoon_probe(struct virtio_device *vdev)
#if defined(CONFIG_ARM64) && defined(CONFIG_ARM64_64K_PAGES)
vb->pr_dev_info.order = 5;
#endif
+ if (virtio_has_feature(vb->vdev,
+ VIRTIO_BALLOON_F_DEVICE_INIT_REPORTED))
+ vb->pr_dev_info.host_zeroes_pages = true;
vb->pr_dev_info.capacity = capacity;
err = page_reporting_register(&vb->pr_dev_info);
@@ -1189,6 +1210,11 @@ static int virtballoon_validate(struct virtio_device *vdev)
else if (!virtio_has_feature(vdev, VIRTIO_BALLOON_F_PAGE_POISON))
__virtio_clear_bit(vdev, VIRTIO_BALLOON_F_REPORTING);
+ if (cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT) ||
+ page_poisoning_enabled_static())
+ __virtio_clear_bit(vdev,
+ VIRTIO_BALLOON_F_DEVICE_INIT_REPORTED);
+
/*
* Disable indirect descriptors to avoid memory allocation in
* virtqueue_add during page reporting.
@@ -1205,6 +1231,7 @@ static unsigned int features[] = {
VIRTIO_BALLOON_F_FREE_PAGE_HINT,
VIRTIO_BALLOON_F_PAGE_POISON,
VIRTIO_BALLOON_F_REPORTING,
+ VIRTIO_BALLOON_F_DEVICE_INIT_REPORTED,
};
static struct virtio_driver virtio_balloon_driver = {
diff --git a/include/uapi/linux/virtio_balloon.h b/include/uapi/linux/virtio_balloon.h
index ee35a372805d4..17de46c629c2e 100644
--- a/include/uapi/linux/virtio_balloon.h
+++ b/include/uapi/linux/virtio_balloon.h
@@ -37,6 +37,7 @@
#define VIRTIO_BALLOON_F_FREE_PAGE_HINT 3 /* VQ to report free pages */
#define VIRTIO_BALLOON_F_PAGE_POISON 4 /* Guest is using page poisoning */
#define VIRTIO_BALLOON_F_REPORTING 5 /* Page reporting virtqueue */
+#define VIRTIO_BALLOON_F_DEVICE_INIT_REPORTED 6 /* Host zeroes reported pages */
/* Size of a PFN in the balloon interface. */
#define VIRTIO_BALLOON_PFN_SHIFT 12
--
MST
next prev parent reply other threads:[~2026-11-19 12:03 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-19 12:02 [PATCH v11 0/7] mm/virtio: skip redundant zeroing of host-zeroed reported pages Michael S. Tsirkin
2026-11-19 12:02 ` [PATCH v11 1/7] mm: add PG_zeroed page flag and buddy merge tracking Michael S. Tsirkin
2026-11-19 12:02 ` [PATCH v11 2/7] mm: page_reporting: support host-zeroed reported pages Michael S. Tsirkin
2026-11-19 12:02 ` [PATCH v11 3/7] mm: skip zeroing in vma_alloc_anon_folio_pmd for pre-zeroed pages Michael S. Tsirkin
2026-11-19 12:02 ` [PATCH v11 4/7] mm: skip zeroing of pre-zeroed order-0 user pages Michael S. Tsirkin
2026-11-19 12:02 ` [PATCH v11 5/7] mm: skip zeroing in alloc_anon_folio for pre-zeroed pages Michael S. Tsirkin
2026-11-19 12:02 ` Michael S. Tsirkin [this message]
2026-11-19 12:03 ` [PATCH v11 7/7] mm: page_reporting: add flush parameter with page budget Michael S. Tsirkin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=65c518234ce31fac3f6ed436455dcb415d4b1189.1795089715.git.mst@redhat.com \
--to=mst@redhat.com \
--cc=aarcange@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=david@kernel.org \
--cc=dev.jain@arm.com \
--cc=eperezma@redhat.com \
--cc=geert@linux-m68k.org \
--cc=gerg@linux-m68k.org \
--cc=gourry@gourry.net \
--cc=jackmanb@google.com \
--cc=jasowang@redhat.com \
--cc=jasowangio@gmail.com \
--cc=lance.yang@linux.dev \
--cc=linmag7@gmail.com \
--cc=linmiaohe@huawei.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=ljs@kernel.org \
--cc=mhocko@suse.com \
--cc=surenb@google.com \
--cc=vbabka@kernel.org \
--cc=virtualization@lists.linux.dev \
--cc=willy@infradead.org \
--cc=xuanzhuo@linux.alibaba.com \
--cc=ying.huang@linux.alibaba.com \
--cc=ziy@nvidia.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®