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.129.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 3D6293E3DA2 for ; Wed, 20 May 2026 22:23:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779315798; cv=none; b=Td+dFscQQwwEq38H2ftpJwDzXCowFPtAs7ja1K/j0l/4BXiuXEjGjP7ZhubuXTXfJCA7Y6gw1PFjDaeaqqNFSYN6L+lUCTuKrfjUG5wyNgfBykbJoH6wEibs6gFLaeTIh5jsuAPPG/MHZbAIDBuu2nMtzlNS0IyK1nn/8PDCRMQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779315798; c=relaxed/simple; bh=o1q520LUtIf3WEFA+mnt5VZVOCpKdiGNtHAvZKuDwl4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=bmlKc9DMyUKUjh13ZqxrH2vJI4WNa0+XVTai1wGy2YBqprPkfJ+k9KFRM74myDL5oxnCphDfZ6d4CGhSyOBfalJLxg3yA8VvZ037Q1arhVvI5K9UBw0j2H7Ym1doR6CGiTgyl4q9/YXDPb7qmTajaKNx3+bHpNY9q3PmLR1k+R4= 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=gM8ly0/g; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=DHIBe+xT; arc=none smtp.client-ip=170.10.129.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="gM8ly0/g"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="DHIBe+xT" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1779315796; 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=PhUe/N+eFNvMvlBoMUh1oQQhfmsYB8gjnR/tug0hsFs=; b=gM8ly0/gT6k8YFQGXfmx/J4+shqp/WYOeko3CDS9oHOElS0Owrf9Pz5DAhDmTnEpkooT+B +vGpbpthEuQb3BxsQDW23Yosmt9jrzAPRomnJ/s1mCRZMXLhLS09sqAFOp9e7G/cie7Q2l 6Z2kiXR2M6TJPKM+aky1ake+Eb1Bm+M= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-649-yNlZyUZsOj6S5il-a-_rPw-1; Wed, 20 May 2026 18:23:15 -0400 X-MC-Unique: yNlZyUZsOj6S5il-a-_rPw-1 X-Mimecast-MFC-AGG-ID: yNlZyUZsOj6S5il-a-_rPw_1779315794 Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-44d83e45febso4336640f8f.0 for ; Wed, 20 May 2026 15:23:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1779315793; x=1779920593; 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=PhUe/N+eFNvMvlBoMUh1oQQhfmsYB8gjnR/tug0hsFs=; b=DHIBe+xTP0FDNzXozesKCQPmm4g2rQ0ejo+SX51iVb2wgznL3nimR5B8aUr3Iy4fOj 7kEOahUHgP4GxH2ckgtqqA4UqUm7lPIUdhdBGBJz4Cn4p3lYB/y3KtZ1oc5sh8JAvTD8 4Zg0nCU259UI1DBSgwrK0gpqfbDot0KJ2zT1gRWSLiVIkgdt8Krp55Dw3O68210XcIll n01o2reXIjGNan8zLmd5DRTbFFrIpUZB8LqpaKBozx6lcRyXjxlWDckQGQ8I7Oml2o8M OqDSqEYXsQ6MjoVRviZeWFhR9Djjhf3vShULecCheREIa/2wxdblMRtMB6/WDiJ1Y9Bl EPfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779315793; x=1779920593; 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=PhUe/N+eFNvMvlBoMUh1oQQhfmsYB8gjnR/tug0hsFs=; b=f73IkKoNSRnbrYToocwLUxixeFFf+rExPMcapSUwcYd4Y7fV3hlhBA/McFyUcVfLCf dDHvI51J4dqTp1s15qMz7WhFWmPEsE4yeJcFAvMFrEdUgg04gMXVkuDoCVTYdjzA7yaV mRKkaC921rsNEbXTIr5IS+2SSICDpQ4ZlzJxvn4eAV+3KeUiMMzVNg9WHq71SVeXi1I/ vO1ZYtpVPG0aVlLFqE9eYnIe0dofkcIFWIHDQDNyz86Ce5Ye891N9eIyw7bPOWETI+T/ 1I0otOA00S3VaVeyZQLrRglglkJJpti40aXJhMQh/koSJl44RoydlQQxat3ZscmBQ3D2 1THw== X-Gm-Message-State: AOJu0YyptVDW2rF2sFiN33YqNmhDlhmfPUjxdJp3fQh7MZewIK0M+gFJ Dwy/DtHNznwdBBR2w+k9QqsxC43Aj9gnsuCcKeFefOBBBCYAC9Uej4XQjcvT+B2O256GRf6UZvn /FTWhfzKMA4kejmggSBq5ymlAFO45ED7GibzeS2mH+/LlMNXRNBTOLkl3A+mkHR7JIUnivBILH+ MOsLJZoBdxlvu2SKEjI7nHQeqNxfCzhaHryDtUc4scw68= X-Gm-Gg: Acq92OFL/V7gPGeoQxsLsNjPkH7nGln0J+TDaPohdOfipfhefkAEzkxe1JWvpfanP5k i2Bl5Ya7Tg8oRLibRI96wxJTRlesWSIcMxMRE9lKqiqRtm6h3yt2mJzmM7ROFBebTmdS9fX/weD tGxj9t6HEPQgEr8Qo2y4hQMO3xFgotVMMn9QbTjfH0+jsRwwfYLUsyVg2XhFjiArqDv4I9VWPGr 6auhbovA+1+izY4qFfWrwp4fYcSxG3cikmJ5EYrJD3uGw8bzXiqL0zYzOiKEfMwCVx3RJR45srI +2CtaIdPsAY80iCj1emDdo0lkB9NCJB2yOCKIvcZ1q78UdCiIY2hQwufkGCKa+hbJk1lcS7pjWQ JRSF/fyLstkx2MfqEyjmtt9Y1EN6dVDiVqi5vBqPK0SA= X-Received: by 2002:a05:600d:6446:20b0:48f:c649:e6fa with SMTP id 5b1f17b1804b1-49035f6841amr2480315e9.15.1779315793512; Wed, 20 May 2026 15:23:13 -0700 (PDT) X-Received: by 2002:a05:600d:6446:20b0:48f:c649:e6fa with SMTP id 5b1f17b1804b1-49035f6841amr2479685e9.15.1779315792933; Wed, 20 May 2026 15:23:12 -0700 (PDT) Received: from redhat.com (IGLD-80-230-25-45.inter.net.il. [80.230.25.45]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-45da0fe13a7sm59877057f8f.29.2026.05.20.15.23.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 May 2026 15:23:12 -0700 (PDT) Date: Wed, 20 May 2026 18:23:08 -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 v8 31/37] virtio_balloon: skip zeroing for host-zeroed reported pages Message-ID: <4753c094c752fc97c7d3372b5ca7db9414b42ca3.1779315441.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 1fa1c7fa285f..e3afa6f32ba5 100644 --- a/drivers/virtio/virtio_balloon.c +++ b/drivers/virtio/virtio_balloon.c @@ -207,6 +207,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; @@ -226,10 +228,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); } } @@ -1051,6 +1057,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; @@ -1176,6 +1185,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); + /* * Balloon submits 1-2 sg entries max per buffer, virtqueue * sizes are 128+. Disable indirect descriptors to avoid @@ -1194,6 +1211,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