From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AB96A3C988E for ; Tue, 12 May 2026 21:07:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778620058; cv=none; b=OOOiye4lP01JKgWNiwLoTac+UfEEXv7Q6j1H1CVt4G+rQ5yxcoVB8y6gjh76mV7dKc3KaaH/fDEr51QjJa5aIu+Mg5Ip3SiFsGB0pavozYeBg6iW6UzZ1SAno1Csx1fi92GXthPDHHDZmEYftQeR2YqDtj0pUYkNNnbtQZtVjH8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778620058; c=relaxed/simple; bh=rB0kVuhS6FNGgugvmVFgpcyoiK50boSLb3yg8KWs/3U=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=hni5yrkfupxzdlrkfG491PIDnKWUxLmm4Ki3W7BiYNxC4AAxfqG03KAQSWoKqOKMvzknuBR4NTGzyAM4yJZG8oqehRRBc1VCrq4y/+gkc6oj4obistzph9M8X6GZiDDIvB3Qfv0FVKoY9PSIIi6JNjbtps3FK9VvcrgL9lUiN/Q= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=AOR9wSGb; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=hg3GFU39; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="AOR9wSGb"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="hg3GFU39" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1778620055; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=FdwmuXhJZ1tztt+MOga5Lk/KutygLpMr1MIyeSBc//s=; b=AOR9wSGbKDaKQMNV5kzoXHWCiIrDmiVlNWwoCCyQSwg5IQGiKVZQhS2LMcWCpMG6i1kUbl /zcvjgEGtZlU0KiFUoCNP1DvsEbYNzgRNobYUDQywNTlxdq0RFEe/nUtZ1nJ/vwCmqOxhw +vdCvBT2azgBONnWcP+8NAhDJ5fP2wo= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-196-NalAIJjCPnqdg8UmeqKS4g-1; Tue, 12 May 2026 17:07:34 -0400 X-MC-Unique: NalAIJjCPnqdg8UmeqKS4g-1 X-Mimecast-MFC-AGG-ID: NalAIJjCPnqdg8UmeqKS4g_1778620053 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-44cc3c9b2feso5499691f8f.1 for ; Tue, 12 May 2026 14:07:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1778620051; x=1779224851; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=FdwmuXhJZ1tztt+MOga5Lk/KutygLpMr1MIyeSBc//s=; b=hg3GFU39J1yEkp5luuV70QoU9OU7iXFf4Yk3s5Ry+ox5Fr7zmEpjiZm8Qr4YHhDudw jAVQ6vClDVuhJFTHM9K4cUQwxqQyWI0Y6P1yuRScVRzqFCs6/06+qXHeF5hzoCisVgC9 yk9zgPoiHjRMS+ygNQxLyvj2fEYa7LQM5cU/AGmL9YUPe4HyzDat312ttGiKdekd0XK1 Kot34TvZ9dRugz2QLq9+BPi1a6CKN+7ZkPkbdpQyIRFXodsq1vazCLU5ltCpZ3jyTCWX j0fSISUu58/Ev30bk5h3tLUP9PiBghTrja9HaeltyCtn1lcfxZJnO6Z0KraOwfn7HGXL s7Fw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778620051; x=1779224851; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=FdwmuXhJZ1tztt+MOga5Lk/KutygLpMr1MIyeSBc//s=; b=oxRuM/Dl+SRos+DJXrkHtyJGptsuJN9fg4FEVqu2fCYv202P8K4DflgzwFXUf7KsuP aHQlMLShOT2ymO7042/p8me/AbOwrCRqwsRUpdXHaxgl7DBzpD8ur/4/IXdLvPU76x+T 2SA+xn42LaTjVPg5kzMqi3IkduOKQ/kSXgFmfvhKXjJhO+Vc2edMK5z9LOxCSXpFlPbU wicnkkcx+O830fOy7NuipkTtIbguSn9XDs1QtntMbj/9CF3nggX03C58z1wIB3by3qTd RYugN4qA3w75mwDx5RWJE3HyFELGya+ivW1OI9EfIh9DmSxgQB3BVt6suKd8R4i9NNix t7Aw== X-Gm-Message-State: AOJu0Yx6sq8vDdI74ClIpbPLDEUyPemk/VAImubZaKKF+Xu9R3+J95Vb BC3idZRnRf7EJ3i061F683U0RJIsY3cqSJLG/ICwc99il9AEqfGPeNc5gcXgGLeoVStuzbvqlmS BSAatftjwJy95WFxjusA5iaLwuzAjkZDJygQkgiQacuwsIDy3TpGQ+sPV+vyVy72SxnJmg7U6Ow bjiRg2Eu4UzxsL7puw9rD7Z7S3dyhGl9bCENiMbIKeL4o= X-Gm-Gg: Acq92OG80GXSf6bzrnwBZ46F/DA1KhDZ6GzE/2KTYFoftp5Z00fzDjNb8gmvRSx2hOH 9iPtk1Sr4ZQKmeIhxgWmQUcs6CQWnVfC/5N+PXB3ltcE04oE92xZ9C8KduZ7143UBe/E4d4zRVQ OKETL6TSpHQJYEQtr5u7dSe4XVdEtHLy/USOvf35B/lg/I34A77XEjvrf2NtG7AURGXiuX4AoKi QiwA+D/SWjsuKojI5vm8UPE20FexnDs0NOyaVmLFgo9n/MHFSK+rLxrUR8nADXBXXjBy2QJ/cus Wlc6+fajqs1lMrg2xxhAJPkAsdTsPyyQWuMgweFBFk7ePA+OxZQ4WdNKOrfIOMBuFuLPaYeRPt8 Pcp4VlPDAbfLxS7QF6JsCTv1Emgt+hqX/DMAna7eY X-Received: by 2002:a05:600c:3111:b0:48a:568f:ae6d with SMTP id 5b1f17b1804b1-48fc9a0b778mr6279155e9.8.1778620051372; Tue, 12 May 2026 14:07:31 -0700 (PDT) X-Received: by 2002:a05:600c:3111:b0:48a:568f:ae6d with SMTP id 5b1f17b1804b1-48fc9a0b778mr6278315e9.8.1778620050644; Tue, 12 May 2026 14:07:30 -0700 (PDT) Received: from redhat.com (IGLD-80-230-48-7.inter.net.il. [80.230.48.7]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-454917d57aesm35649963f8f.26.2026.05.12.14.07.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 May 2026 14:07:30 -0700 (PDT) Date: Tue, 12 May 2026 17:07:25 -0400 From: "Michael S. Tsirkin" To: linux-kernel@vger.kernel.org Cc: "David Hildenbrand (Arm)" , Jason Wang , Xuan Zhuo , Eugenio =?utf-8?B?UMOpcmV6?= , Muchun Song , Oscar Salvador , Andrew Morton , Lorenzo Stoakes , "Liam R. Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Brendan Jackman , Johannes Weiner , Zi Yan , Baolin Wang , Nico Pache , Ryan Roberts , Dev Jain , Barry Song , Lance Yang , Hugh Dickins , Matthew Brost , Joshua Hahn , Rakie Kim , Byungchul Park , Gregory Price , Ying Huang , Alistair Popple , Christoph Lameter , David Rientjes , Roman Gushchin , Harry Yoo , Axel Rasmussen , Yuanchu Xie , Wei Xu , Chris Li , Kairui Song , Kemeng Shi , Nhat Pham , Baoquan He , virtualization@lists.linux.dev, linux-mm@kvack.org, Andrea Arcangeli Subject: [PATCH v7 26/31] virtio_balloon: skip zeroing for host-zeroed reported pages Message-ID: <73b896d7fc1b4bb6127f234f5e1964d2764cbf9a.1778616612.git.mst@redhat.com> References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Implement VIRTIO_BALLOON_F_DEVICE_INIT_REPORTED (per virtio spec proposal): when negotiated, the device initializes reported pages (zeros, or poison_val if PAGE_POISON). Check per-page used length returned by the device to determine which reported pages were zeroed. If used_len matches the page size, the device successfully initialized the page (e.g. via MADV_DONTNEED), and we set the corresponding zeroed_bitmap bit. Gate host_zeroes_pages on the feature bit and page content: when PAGE_POISON is negotiated with non-zero poison_val, the device fills with poison not zeros, so pages are not zeroed. Clear the feature in validate() if REPORTING is not present or if PAGE_POISON is active with non-zero poison_val. See the virtio spec change: https://github.com/oasis-tcs/virtio-spec/issues/244 Signed-off-by: Michael S. Tsirkin Assisted-by: Claude:claude-opus-4-6 Assisted-by: cursor-agent:GPT-5.4-xhigh --- drivers/virtio/virtio_balloon.c | 22 ++++++++++++++++++++-- include/uapi/linux/virtio_balloon.h | 1 + 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c index fc43d0d7bbbc..6586699396b7 100644 --- a/drivers/virtio/virtio_balloon.c +++ b/drivers/virtio/virtio_balloon.c @@ -204,6 +204,8 @@ static int virtballoon_free_page_report(struct page_reporting_dev_info *pr_dev_i struct virtqueue *vq = vb->reporting_vq; unsigned int i, err = 0; + bitmap_zero(pr_dev_info->zeroed_bitmap, nents); + /* We should always be able to add these buffers to an empty queue. */ for (i = 0; i < nents; i++) { struct scatterlist one; @@ -223,10 +225,14 @@ static int virtballoon_free_page_report(struct page_reporting_dev_info *pr_dev_i /* When host has read buffer, this completes via balloon_ack */ for (i = 0; i < nents; i++) { - unsigned int unused; + struct scatterlist *entry; + unsigned int used_len; wait_event(vb->acked, - virtqueue_get_buf(vq, &unused)); + (entry = virtqueue_get_buf(vq, &used_len))); + if (used_len == entry->length) + set_bit(entry - sg, + pr_dev_info->zeroed_bitmap); } } @@ -1048,6 +1054,9 @@ static int virtballoon_probe(struct virtio_device *vdev) #endif vb->pr_dev_info.capacity = capacity; + vb->pr_dev_info.host_zeroes_pages = + virtio_has_feature(vdev, + VIRTIO_BALLOON_F_DEVICE_INIT_REPORTED); err = page_reporting_register(&vb->pr_dev_info); if (err) goto out_unregister_oom; @@ -1173,6 +1182,14 @@ 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 (!virtio_has_feature(vdev, VIRTIO_BALLOON_F_REPORTING)) + __virtio_clear_bit(vdev, VIRTIO_BALLOON_F_DEVICE_INIT_REPORTED); + + /* Device fills with poison_val, not zeros; disable zeroed hint */ + if (virtio_has_feature(vdev, VIRTIO_BALLOON_F_PAGE_POISON) && + !want_init_on_free()) + __virtio_clear_bit(vdev, VIRTIO_BALLOON_F_DEVICE_INIT_REPORTED); + __virtio_clear_bit(vdev, VIRTIO_F_ACCESS_PLATFORM); return 0; } @@ -1184,6 +1201,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 ee35a372805d..13074631f300 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 /* Device initializes reported pages */ /* Size of a PFN in the balloon interface. */ #define VIRTIO_BALLOON_PFN_SHIFT 12 -- MST