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 7E2F03F58EF for ; Fri, 29 May 2026 15:25:08 +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=1780068309; cv=none; b=CpcQiBYH48+2IraHat+ejBEf7MiXdDFzgw5MfxFHa3e3xbqz3mu8xGyvrSmFfDi6G+vUXwKJ1kuHK3caBjRJxzvOo1r5Y0DlYqlJ6Gc0Ub3LlJl+0BvoqmhT2q8qTiAaGYeE648rxN49In9MGVIlkdVG3BOLj9uzcPg9+uoasu4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780068309; 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=ZRAVInN6myWza3OEwEfUGrD39PHZ2WcyR1iY4bQJbFYpnbF0xC4Jd1mnZcmXzAnLRg6xUbFvnZVAmCFMzWi8srs6kV3YQla6WKqs5T5rxFPLE8zdS7QXhiRm3G9znVXCGFgwVKojS56t7fWAR5MI22J5DRQ8t7CCxZj64zzFaLw= 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=fYVEgBqE; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=XKewBRfZ; 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="fYVEgBqE"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="XKewBRfZ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1780068307; 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=fYVEgBqEe1qSgXWuALGrKjW3mmSCrUARkkCVUtGUU40ktLfKASxU3618FN5qF5AMh5satp iIZoxo2ZrIIwrz9Ycr3j26U0aKuIIHw4ErMbJJ1zcN9KyqprNE/PDnYY8bH/gL0vbo9Epr 6wJjriPBK3oIY8Y/I+hpWt9hWZp6Zik= 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-459-tfB6behaOmOAzb0Ji90dgw-1; Fri, 29 May 2026 11:25:06 -0400 X-MC-Unique: tfB6behaOmOAzb0Ji90dgw-1 X-Mimecast-MFC-AGG-ID: tfB6behaOmOAzb0Ji90dgw_1780068305 Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-45e2f74da10so12750297f8f.2 for ; Fri, 29 May 2026 08:25:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1780068305; x=1780673105; 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=XKewBRfZz55RITf/GuGRkjPaVLKBAGOkRdxyi+PcqlRYyTbn3nTg4pOgcytaIrnOKq hX9XCjEwye1lsMO5+WeClh0NBo2NE7ZFSYLn5GD4LFT7QXEr4SKE0cyUQ+tm3rgzmNvG tMEokeZKtXGoST7jB55xqEuovkRmZpw8ZIXKB40OygLBcPgYC+OLClM/XBHe6OYEF9rx q7Xw3RGnaH9HML7c5id7FktfIaS77its/f0rWewOF+FYVkmWw2ZI6i/KpS/PREc7u9RF yHT4tyOlSpeJRiYlM4vBx/oiR8szgZD0oC3NUvsRPEj7ejaPM6CRjCypHv5agQioMnjz 7IRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780068305; x=1780673105; 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=OsJy92bhmXzwuO6FmnLR0mXyf3UNlPlNS4GDU4SeHGzom4FDpuJa2zf4/xCo2uM5Or Kx/GfJHB3LrqmBO7HDKTiIdg1+FiubgH9XMFb2MwEABnf+aBOVnaFWHuyXd8o3v4ysNY UScJiXQuJ8x2nE9IH2QulyatkdDgXBX73lnc5NOBrMDglOOcY3faKSYnYlZlJWOfzugK Ao+f3mfrxQeTI2QPfWS8uxtuOtwtvxc6V1LSCRyPgC58ZcZgTGCpgOJCiNNfCw3RFMzo e/AF4cXqZ0JqZykd98XMArim6RZmN6rx0K8XAsudH99QuncwEWdaB6BSlYNAVfp0xQt4 CuRA== X-Gm-Message-State: AOJu0YyEJ0iaAK4GHrB6Fj9C/xkk6MkLrCJHL2Vl6tMtamwp/H9LkI9y jVjye8M1Q7fEkLAJXPVh2QZRBwBtF1WTBcDnaK0utVPcXbHb7/GdFZ7bbx+RlkcLzm/8ciGRhJq qSw4r4eSBnTCtT7IMvBU+n2ypiwd5SQJfjTS5kzuGQPOjbxmGAHXZ1TX/p8QOF02pCYUK9YannQ 6dKIL6WCoDVAvV1bxT3Xuzfv+SWC9qZI3TJ52TclooD1I= X-Gm-Gg: Acq92OHFkMTyv/oMySwvsmZzj5eh39mKh4ltW0qwj4K4+pX/FegNbYEnjo8FhaRjWF8 7y02+tMhy1hdmSeLn4tI5N8l3bZhoQ0Q4DfWTD7mrZEoPK24YGsa2uuz4BNYkrmTKstne1H+OuS P8M2s0SBohWa/ovjZSgyJoPAbxcz8xnjWyq0fz+ZFuySrGuRV+b2hry/WBRKzQxAL0PPCS3G9/G 9L1oC22d4K0myjTfqzA7+4i3/B3wXHELvC3EfF2e1JhnhPQ1S36n5W1hN/2ZJLgwgXjqciIL5lx n2lB+USOp9TcawBsCvvx2mC+zm8v2YB6parvnm9vvDEGdgQBdPnS9OcLssPlSpIDRcNcHh6SPo+ XSOA7KknE+lGBWwkSXWFWJCjdbllK/wF0AsmvfwjTy8PwPY5DISPCMQ== X-Received: by 2002:adf:f690:0:b0:45e:73b4:85cc with SMTP id ffacd0b85a97d-45ef6b815f2mr388346f8f.35.1780068304727; Fri, 29 May 2026 08:25:04 -0700 (PDT) X-Received: by 2002:adf:f690:0:b0:45e:73b4:85cc with SMTP id ffacd0b85a97d-45ef6b815f2mr388225f8f.35.1780068303965; Fri, 29 May 2026 08:25:03 -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-45ef34b47eesm4828235f8f.9.2026.05.29.08.24.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 May 2026 08:25:03 -0700 (PDT) Date: Fri, 29 May 2026 11:24:59 -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 v9 31/37] virtio_balloon: skip zeroing for host-zeroed reported pages Message-ID: <6bff99e8890ea91c93e3e8f0c27ddb3b5b2528eb.1780067978.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