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 A16F63C0A18 for ; Tue, 12 May 2026 21:07:20 +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=1778620042; cv=none; b=LN2bhI8RK8DDSZdWZ3EJNjLaphMjnZZanHHPc3Z8ruaE8593VtKuo0tLFhxSUq70WGwItdXlJnsZ9gy1gYNzWSzExE5zpTqpAfIiJqzxPpM4wIbfAQu/nKlU/kvkAoZLBfGoBjt5sc6/mys7XIrN9dhfbSm0ON/EUk7Z2kiYp3M= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778620042; c=relaxed/simple; bh=7NdesRjgSv1b1kpIKOcJU3ghhlgl5tyDeUkJhLpnmYA=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=BOIHPOceZ8ypcLJlfmwGdeZOYNpf4XB/ZAfi6H5HtfpNWoBcAJ+MDrZOXxWu/G1wIw+JoreDzJQjT8LmB65EEhl877CZqB0BwA70tXMwnyL17k963SG/DTOqwUcH6Ls5XcjrLSwpUt72+6MFBcQKtDQAgkGwdVqgyRJa/xoBhDY= 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=Lu9fGC3G; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=IWNr1JTH; 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="Lu9fGC3G"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="IWNr1JTH" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1778620039; 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=IXi+uVqRnkqRNPO9A5xD9TyHb3ak5Pg5n5rhgIRfmL4=; b=Lu9fGC3GDbj0+5WvYBp5LjwNgF1nTgWXKkprAICXDe7cWLnqvwd4etRv3x/PZdKVnapw7G 8/qIOkqmwQbGlPGr1o5IwqB2VONl9Rrah+Oqq1oBS8zrndi9/DJ0ZLxAafg4vvSZ2YZYik p881m12DVIeXyrpbbl8tz/D2z613/+A= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-104-1G3OOE-FPeKfjCoNtPkmIQ-1; Tue, 12 May 2026 17:07:17 -0400 X-MC-Unique: 1G3OOE-FPeKfjCoNtPkmIQ-1 X-Mimecast-MFC-AGG-ID: 1G3OOE-FPeKfjCoNtPkmIQ_1778620036 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-447f2ce5556so3916939f8f.2 for ; Tue, 12 May 2026 14:07:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1778620036; x=1779224836; 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=IXi+uVqRnkqRNPO9A5xD9TyHb3ak5Pg5n5rhgIRfmL4=; b=IWNr1JTHMdaiH5kN2pZC9g0F+ek66MZ2H7/upfznIaUrSOUF6iQdZFURGbPS6FbZOk XAPjvPhjnOgwIoh6/oqVf9TunAbmif/3ibYTkwGV9oun+xF02kKfPBx9KLKdQhojBPAK U62pxUAqOYSPTrH0MsBON5qM4I4l5YXB4aqZO4eLrS1vSsBaEFZbsmi9jOXS1uUB79Tr 1aNlYa/BxQJQpGCaZvyZ3qQtNSOB6OeqVcjsWPyOusYKwoYkO4UI+jJkmDZKV0LXx+Kn z/ONj4FMmTRQh0t4u7v6zvbNV5+PXJyMRwnSTyf+P1ig36HejukfaweDPxAvXPlq9p3z BSPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778620036; x=1779224836; 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=IXi+uVqRnkqRNPO9A5xD9TyHb3ak5Pg5n5rhgIRfmL4=; b=Hoh8Y13Lq2AtA4TIJpkVBytUvslw/AUJK9IQ3zk4aPGG1eYbFoQV9Qtsy/yi3iB2wy wc5YAC896REsR/0pJfiIUBJDtPVXNU1yHpItBf6uX03yE+AVEWLGn4TetZ5SelcbE/l0 xyieyu9h8ajboBiitGwtJAC+bBj9I/npe2mIXHoU5vISF5Os7dQxM6UvLeDJspkRF20j sXpgi7kTnP8nM6Y1kOHS+QjNa/3B+yGlj0QgI3chGvaPVSfaWjrq8TKEO8XhKddjnsM3 osjRW3VCq+Int2/XMTSpRMAXoYEKLfr7FVMqMtCRX+lzZyPjqD0lc7UABoIDV10iKPXF POpA== X-Gm-Message-State: AOJu0YyYxPiviL8rRTLqOiZa1+jEslwHUE750ofb5oWCdwIcgFI9VRA0 cq1SdgZ3Vv8dOSh5MktmrdVkPxMYkLZZxdN2b0l+0f3xcBFXWoxtLlw+t1CaHpwyOSv7XnlcPlK wwKWaTzj9L5wylMYkdxlPhRId2DlOZx+0YsLUBYuSOnegu2y6XDGqphcY2FqliJqUhxyq1TGrdz HWhJlBUkvwe4MJcdoP8inXRHypTc7UmB/zMKpQbRE5nqs= X-Gm-Gg: Acq92OEpAKsSAeLkY94F7QqpKB9mFHY6F/RUWmsCq32T+EVfxXG7UeBYiOLxDAxByly NtsQFmoGnUFr3UdOnRALbYj7nSStXBzW1Vkm96T6Sb4s7XcsfGUjjetVO3w8OOAUQ5+jc7ASDbD F8Gqvs6jtB9CHaQxdrI3pAhtJAmzdbFb3ZmpPl9mPibbAggQXpmaHv/oLKuOjEfcJUAyVQS2wRS YWjZ2utWZ7CkOfMLQBmC8j3FQu7mXFudvyxnishjdaT8/S1QVNnPEGw7O2ZGLEv9ioQGimGMm4P i1I21EEqfSwIqBtnt8VkwKTOycKcxMKdCV3967KhvD+IvwO3UfKWP3E2m3WSdDnOjbs7eJkjKR8 Zl2d6QegARh1TcGoSOAOTDqRokI4qwp6FDOnfK0hs X-Received: by 2002:a05:6000:40da:b0:44f:d9f8:c0e7 with SMTP id ffacd0b85a97d-45c77e635bfmr41918f8f.5.1778620035766; Tue, 12 May 2026 14:07:15 -0700 (PDT) X-Received: by 2002:a05:6000:40da:b0:44f:d9f8:c0e7 with SMTP id ffacd0b85a97d-45c77e635bfmr41834f8f.5.1778620035141; Tue, 12 May 2026 14:07:15 -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-458b3664e3esm19560446f8f.3.2026.05.12.14.07.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 May 2026 14:07:14 -0700 (PDT) Date: Tue, 12 May 2026 17:07:10 -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 23/31] virtio_balloon: submit reported pages as individual buffers Message-ID: 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 Submit each reported page as a separate virtqueue buffer instead of one buffer with an sg list of all pages. This avoids indirect descriptor allocation (kmalloc in the reporting path) and gives per-page used length feedback from the device. On error, the already-queued pages are kicked and drained before the error is returned. The caller (page_reporting_drain) then marks the batch as unreported, which is conservative but correct. Signed-off-by: Michael S. Tsirkin Assisted-by: Claude:claude-opus-4-6 --- drivers/virtio/virtio_balloon.c | 36 +++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c index 6a1a610c2cb1..fc43d0d7bbbc 100644 --- a/drivers/virtio/virtio_balloon.c +++ b/drivers/virtio/virtio_balloon.c @@ -202,25 +202,35 @@ 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; + unsigned int i, err = 0; /* We should always be able to add these buffers to an empty queue. */ - err = virtqueue_add_inbuf(vq, sg, nents, vb, GFP_NOWAIT); + for (i = 0; i < nents; i++) { + struct scatterlist one; - /* - * In the extremely unlikely case that something has occurred and we - * are able to trigger an error we will simply display a warning - * and exit without actually processing the pages. - */ - if (WARN_ON_ONCE(err)) - return err; + sg_init_table(&one, 1); + sg_set_page(&one, sg_page(&sg[i]), sg[i].length, + sg[i].offset); + err = virtqueue_add_inbuf(vq, &one, 1, &sg[i], GFP_NOWAIT); + if (WARN_ON_ONCE(err)) { + nents = i; + break; + } + } - virtqueue_kick(vq); + if (nents) { + virtqueue_kick(vq); - /* When host has read buffer, this completes via balloon_ack */ - wait_event(vb->acked, virtqueue_get_buf(vq, &unused)); + /* When host has read buffer, this completes via balloon_ack */ + for (i = 0; i < nents; i++) { + unsigned int unused; - return 0; + wait_event(vb->acked, + virtqueue_get_buf(vq, &unused)); + } + } + + return err; } static void set_page_pfns(struct virtio_balloon *vb, -- MST