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 0B62E3B9D93 for ; Mon, 11 May 2026 09:04:13 +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=1778490255; cv=none; b=JjcwnKD+PgSKmCEINpf/E1nteJk6LiQ/4JlIfuXOUya2Metk0DHOc7i4k6l8EvU4EkwkVY1p8IoihXdPmrTtgmBzipmzfQ/62CiRPLZpipvl4gBtl5yPj2NsnhVg8D3QkyozXqQIR8ZpDbd28/iGW5WbL5vE2zlyOLoMCOOEiQc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778490255; c=relaxed/simple; bh=kbeC8rzPmxUpVwR5cb8LtaGHCXNFNmNT7voh9QmR/3I=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=bJmoW25QyWpxBMU5cDV92AJ3ZbCGqQ31SVBfq1wZdGtQpTrkKQGJDx0lpYi7x7Ir2SNEEioTg8An/O1Mh7baTndJdrdeOAp0my3Cf1s+F/mfmyqT5ySEmsda6rgKoq/k56YG/f/QhNex9VyNEI5zxl4XhgBlODwH/IwTuO6L2BM= 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=dU75EKnF; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=rbYaI6Ny; 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="dU75EKnF"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="rbYaI6Ny" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1778490252; 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=R9MIHVZ1NMFTjGw8qWZvRYjcRPTh67thc0mkpGrxtNM=; b=dU75EKnFGxK+5HRacB4B1k1D+nZp2T2ai/Bajx2ObM3GZA2sQcwZOaEIBCGwuniz6Cbprn 7lRQknRAIJlJz8jyaJp/hsqG2zT80Qq9JT29VlI3hVM4pDMkFUzg/qg3dgUz5QkYDUbkYW twSJno/VLtIB3IZWLpQswU/13hBXVPA= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-592-xim8ZSwHODWTnf_IiyfYEQ-1; Mon, 11 May 2026 05:04:11 -0400 X-MC-Unique: xim8ZSwHODWTnf_IiyfYEQ-1 X-Mimecast-MFC-AGG-ID: xim8ZSwHODWTnf_IiyfYEQ_1778490250 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-48a9592f666so26641695e9.1 for ; Mon, 11 May 2026 02:04:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1778490250; x=1779095050; 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=R9MIHVZ1NMFTjGw8qWZvRYjcRPTh67thc0mkpGrxtNM=; b=rbYaI6NyeyyILU1XZkY5uHECtlONP59SgSE+jLQyadEJzS81tjz4hD64ifrv959tdh Scc58zQbOa57YOZXxRCe9v+IFP+LpElV5Hl40f5b1RvZSQct4eRHSHxPWEH2qTD1lkjm l6I7sR4aahkRghGTAZwBic0/ZR18AwY80+7EbEQrToNRAaygGKL1TJBqLJ6fd0vI7GzQ BGdMOptoD6fA5NWN4u8PdFbiRoTWzendGaqXbsfIO0UagF2VSqiTlFoGIShMrTvAnCM/ e9KnVhQInKq3lKwPxBk/4WyqkDY4nVsG/CZQQmtbPT1va5Au/lBfvuVIRvqtuwDMd+Mw 6+AA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778490250; x=1779095050; 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=R9MIHVZ1NMFTjGw8qWZvRYjcRPTh67thc0mkpGrxtNM=; b=MYPFtNFKBk1rWizqNp09g/ErrcjCRgH34M5TCLTNDh7zQ30QdsBNoYhqtAgXfZMNtV xeqQojWl0mDV4Xv2gqKwFJtLyHtbybKkdU1xABiqI1D1ieUG17PGAJ5+BGc8iY6t4U2H Cnz/FRUR3x1nY4U5wYatbpM66OMLUUvGtptqFUsNUYeL29k4UQi7Rygg3rqY+UAATTIw 2fkzF5N4cOPIrqPTX2NXr+OIOpyvzNuJ6hMbYEhzxpCDDy/EVfxOhevp4Ydn2GDHxmRO iJUQ74a22LGwch2zCGpb+3K/zDqwBkUcAm07K72vlBelNMJVIm/neTUn13VB3Us/IJ2F U2rg== X-Gm-Message-State: AOJu0YxOTUBuvXSh320pA7MHfByat6I7hwhyZ9PaevctXlvn9CmOymCc a13lvRmFL4NSZdwvpqPmkYQKpg2J+CWvbDljF8e3iJNDYm7uJ7ne4QX5h5jN5UT46I+riWfwGH+ yTj6audYUzz0ETLZRa5DEYPMiBv4TME+4ZhOzzKOInVKPKeqW0wfCXsShrU9Chu4HjnVxmzecU6 wSZLnMUfaeVS1Ec+8UN34x5q+3lc7OYisp0R1NndTJcf8= X-Gm-Gg: Acq92OFi1P75ALCskYhynnWkGyVV+4qTjQuXFyXGBWk49NSuHy4OpBCdjNBaSKx7/96 mENkYdz3pULGPFyMD89HrAKBUesL36+axWHVIy0n/dwn7Zj5QkWTjEwAiwItdV1y2pRRZkMsIel MowgyF9CgT9YaydEfwS/VmfiwnHbJf0zNCqvLk1MrvSGDsmuYKnH4Ig7crlq5ERqRc5jj1JyCeO R8bFoWEpEdj1PaaR6ErrfI8Ys8gv8EOZ8wEHPQhFKz1WdSjUJDek1ckJvLfT7lT1bahXzn4JwOG X+STYQ+B+BG3vQlA7SgYZlRf5PGiXGyUYayehlt4lo8gz02iH1H5hXEDV2glmb+tIQWQRee1ZRf VrhLsDCmxkqCbOxky81uW2fmA+Lo0ZzWfNRySOI9W X-Received: by 2002:a05:600c:6299:b0:489:1f97:6b1d with SMTP id 5b1f17b1804b1-48e706edd0dmr143939285e9.28.1778490249190; Mon, 11 May 2026 02:04:09 -0700 (PDT) X-Received: by 2002:a05:600c:6299:b0:489:1f97:6b1d with SMTP id 5b1f17b1804b1-48e706edd0dmr143938055e9.28.1778490248435; Mon, 11 May 2026 02:04:08 -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 5b1f17b1804b1-48e702e6d41sm220651835e9.7.2026.05.11.02.04.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 May 2026 02:04:07 -0700 (PDT) Date: Mon, 11 May 2026 05:04:03 -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 resend v6 25/30] virtio_balloon: skip zeroing for host-zeroed reported pages Message-ID: <4a0f26ece4b662e928606a638959389bcff66b53.1778489843.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 fdfd828657dd..e5d11782ce41 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; + 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