All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Michael S. Tsirkin" <mst@redhat.com>
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: Re: [PATCH v11 6/7] virtio_balloon: add DEVICE_INIT_REPORTED feature
Date: Fri, 20 Nov 2026 12:03:29 +0000	[thread overview]
Message-ID: <sashiko-outbox-225115@kernel.org> (raw)
In-Reply-To: <65c518234ce31fac3f6ed436455dcb415d4b1189.1795089715.git.mst@redhat.com>

Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [High] virtio_balloon: 32-bit used length overflow in
  virtballoon_free_page_report()
- [High] virtio_balloon: stale PG_zeroed flag on free pages across
  hibernation resume
- [Medium] virtio_balloon: missing feature dependency checks in
  virtballoon_validate()
--

commit 45401c714e001e18d0bb9e4b0f46a6691e93f0cb
Author: Michael S. Tsirkin <mst@redhat.com>

virtio_balloon: add DEVICE_INIT_REPORTED feature

This commit adds support for the VIRTIO_BALLOON_F_DEVICE_INIT_REPORTED
feature, allowing page reporting to mark reported pages as zeroed when the
host initializes them on reclaim.

> 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
[ ... ]
> @@ -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;
>  }

[Severity: High]
Can virtqueue_get_buf() ever return a len large enough for a batch of 4 GiB
or more?

The Virtio used ring stores a 32-bit __virtio32 len field, so len is at most
U32_MAX (4 GiB - 1).  On CONFIG_ARM64_64K_PAGES, MAX_PAGE_ORDER is 13
(512 MiB per block) and capacity is up to PAGE_REPORTING_CAPACITY (32), so a
single scatterlist batch of 8 or more order-13 blocks totals 4 GiB to 16 GiB.
For any batch of 4 GiB or more, subtracting entry->length from the 32-bit len
always hits len < entry->length and returns -EIO, causing
page_reporting_cycle() to abort without marking the pages reported and retry
the same blocks on every reporting pass.

> @@ -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;

[Severity: High]
Does enabling host_zeroes_pages leave stale PG_zeroed flags on free buddy
pages across hibernation resume when want_init_on_free() and
page_poisoning_enabled() are false?

During hibernation snapshot creation, free buddy page frames are excluded
from the image, while the vmemmap pages containing their struct page entries
(with PG_zeroed set by page_reporting_drain()) are saved.  During resume, the
boot kernel uses those free physical page frames as temporary safe pages for
struct pbe chains and image buffers, and swsusp_arch_resume() restores the
saved struct page entries with PG_zeroed still set.  Afterward,
clear_or_poison_free_pages() only zeroes free pages when
page_poisoning_enabled() or want_init_on_free() is true:

kernel/power/snapshot.c:clear_or_poison_free_pages() {
    ...
	if (page_poisoning_enabled() || want_init_on_free()) {
		memory_bm_position_reset(bm);
		pfn = memory_bm_next_pfn(bm);
		while (pfn != BM_END_OF_MAP) {
			if (pfn_valid(pfn))
				clear_or_poison_free_page(pfn_to_page(pfn));
    ...
}

In the default configuration where both are disabled, post_alloc_hook() and
vma_alloc_zeroed_movable_folio() see PG_zeroed set and skip zeroing, handing
dirty resume-kernel memory to __GFP_ZERO allocations and userspace page
faults.

> @@ -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);

[Severity: Medium]
Should virtballoon_validate() clear VIRTIO_BALLOON_F_DEVICE_INIT_REPORTED
when VIRTIO_BALLOON_F_REPORTING is not set, and keep VIRTIO_BALLOON_F_REPORTING
enabled when want_init_on_free() is satisfied by
VIRTIO_BALLOON_F_DEVICE_INIT_REPORTED?

If VIRTIO_BALLOON_F_REPORTING is absent or cleared above,
VIRTIO_BALLOON_F_DEVICE_INIT_REPORTED remains set in vdev->features_array,
which can cause virtio_features_ok() to fail probe with -ENODEV on a device
that requires VIRTIO_BALLOON_F_REPORTING as a prerequisite.  In addition,
when want_init_on_free() is true and page_poisoning_enabled_static() is
false, the check above clears VIRTIO_BALLOON_F_REPORTING if the device does
not offer VIRTIO_BALLOON_F_PAGE_POISON, even when
VIRTIO_BALLOON_F_DEVICE_INIT_REPORTED guarantees zeroed pages.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1795089715.git.mst@redhat.com?part=6


  reply	other threads:[~2026-11-20 12:03 UTC|newest]

Thread overview: 15+ 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-20 12:03   ` sashiko-bot
2026-11-19 12:02 ` [PATCH v11 2/7] mm: page_reporting: support host-zeroed reported pages Michael S. Tsirkin
2026-11-20 12:03   ` sashiko-bot
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-20 12:03   ` sashiko-bot
2026-11-19 12:02 ` [PATCH v11 4/7] mm: skip zeroing of pre-zeroed order-0 user pages Michael S. Tsirkin
2026-11-20 12:03   ` sashiko-bot
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-20 12:03   ` sashiko-bot
2026-11-19 12:02 ` [PATCH v11 6/7] virtio_balloon: add DEVICE_INIT_REPORTED feature Michael S. Tsirkin
2026-11-20 12:03   ` sashiko-bot [this message]
2026-11-19 12:03 ` [PATCH v11 7/7] mm: page_reporting: add flush parameter with page budget Michael S. Tsirkin
2026-11-20 12:03   ` sashiko-bot

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=sashiko-outbox-225115@kernel.org \
    --to=sashiko-bot@kernel.org \
    --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-mm@kvack.org \
    --cc=ljs@kernel.org \
    --cc=mhocko@suse.com \
    --cc=mst@redhat.com \
    --cc=sashiko-reviews@lists.linux.dev \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.