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 71F173C141F for ; Wed, 20 May 2026 22:22:57 +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=1779315778; cv=none; b=RM3wPH4FekOLzQukfMV6E6dsHd8FsMzDs8q+pxoQAP+EFKKoXrMuvJtuAc0XT76P+oosyeuxn/zIT52tQqmVaQpWFqdbmYqC54s8/EwtxvQc1iu3CYowq6/BmZ1WTQ9GYVPxQTHYPovT9PrTD1Muw7A43Fir2PwM3kBh9DgtaCk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779315778; c=relaxed/simple; bh=NEUFfCyJTTjkAORA91qK34iLisrtuxPbcfRlH9SPC6Q=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=g4BuKhXiX0MxJI4SV5tD7KmqXWTRL3Ra210FMlvXDJiPT4yNEp59oYk8zp/tymjngdcat4/v34vS3TfwabFC2UJsa9GEbMRlQTv6cZP7RpcdmyYv6nxZ9LyxLFBseYmYK7TrOVQM3nLc1HNIFBMe6StyvuLclqpSgmjW8LXsF4Y= 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=eXgqmevv; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=mF6bEu3n; 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="eXgqmevv"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="mF6bEu3n" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1779315776; 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=TrGGx5WHa8djlqQq7KjWOiK6GbnTz3UET362lIFlLIk=; b=eXgqmevvLDR4oRp2y93dTmB0mPqFYKHq1JyrKVFXMETkW4g/rKvBDt2bDxSCwxlr0rfPIl qU3tyAodUCX2P03e0U9ni8BXSgyH76CMTeFxeaX09m70OqAZcud6iWJUBe3GNhaSDC45cc vHlvVS/ivNS3r8EagF5nx9u79O0N+F4= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-394-0izGewMmMoGwZQgR-7BS3w-1; Wed, 20 May 2026 18:22:54 -0400 X-MC-Unique: 0izGewMmMoGwZQgR-7BS3w-1 X-Mimecast-MFC-AGG-ID: 0izGewMmMoGwZQgR-7BS3w_1779315773 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-488d1b5bca0so22074975e9.2 for ; Wed, 20 May 2026 15:22:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1779315773; x=1779920573; 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=TrGGx5WHa8djlqQq7KjWOiK6GbnTz3UET362lIFlLIk=; b=mF6bEu3nJKJc734WNeeSvIC2fFpqMI0HTdR+L5/bVKOOMOqMOujWpo9+ppQaVT6e9r Bz+ILlbiHZIvHJgtvL4VcGO8OCdAA8vj/QqUfUNw1ejpFrbzONEBTMJfTxVWOEco2iDA WkxGQPz4GjItpo3+I+QMruHm1tnN9XBz9uBHdNyAc7OzAEwh7hFxpEUiKio92tISkk6N 0MIqLXpNcweEp2SI/0pI25onkC0h7N0mEqLwdp5Qk0MKIXrm5ixuN83GIghl2AdTRZWn GNxjgqPeRWEBe/BZ1zi89//I9E3RgkUOJhCYEZXQQOw32zXQ2YoAE2U5aMc10bXBKLdF Oj3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779315773; x=1779920573; 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=TrGGx5WHa8djlqQq7KjWOiK6GbnTz3UET362lIFlLIk=; b=HHkrlHv5REO4DZxkCh9YKOTMjFZkoZzZIhCctDZDAh+T8xoj8ywtBi1IxCo3RvFJYE CaUq7+focqErMxsEmvClRx2DZoMm6HkXIp/0D3X3aAMhm+nkBNCr8hzPcH8sGoeiPwEF xF3kr0//tALOz8tXcJt8Uj170AUKKwG6uhoUYJT0ysoiITdZ4v1UxiUpqmFqUgY01t0o DAiRPg6ABoGGKtathHWYlOxlpoIv+6cF+/pYm9Zbs708F2qgDaCZD1bvE/bTf5V4rOZW y8kpvX+Tp475V0cXIrYPiTmkT+zU4Q7J9QIXlpeHvpSV5LA1igI7d0CymAHS73yvy1XX wEwA== X-Gm-Message-State: AOJu0Yy+YlCfoPFj95RyIkti7348W0386qwoau3OQ/PkhhhPPztMVUI8 o/trlOLdK8U9Iplr1f3yUrsbDv5hUShbGqCuwweE0FxakG9lsx8Mj68zXBIxES541QCW3uI3FXB 1qQqmucb8ZhNnpD7VBqseXXyXUSSxtpSxV3OxY2e+gdAwA3wC12+8p98ADfg8ZrCrpiNrO5pA4Z oAuWy1HYDQe+JtAiUs+I7IJL/zTFXQPnobe+PNl3lw8T0= X-Gm-Gg: Acq92OHeGWMd7aM2jTN86x7nt0U5dN+ivvFMYoRq2CnwLtWTSdrHPVoSXmDiE89LC6c yQeGhb21Zy8VczMWVcvAhvCgG4EeTX6qVmB7jgjj4m2xHxnCc+nFf3zAIFx1wS8uVnwsmyCTvdc HBEx0McjSqKASgw5ONsjr2SnQgY9EQUGCsf+NxXInBqOLM1oqs8sqnwBBV9SKp2wdJQhghLHtcT UbS5ybSXk3nSO/Tl17Ht0xqZcY/rA88m9HErR59sfmmZ/3yokj5q2Ff5CGuigF9Zx0n0rVIRnt+ 58SAe3RYRjtTlTTWuNL452KaUF5EwfbYrLZ91sMMYT5RvCnpDdzG0srpyzk1PEuK4sQsyjIt7ox loiHkgifHo1YWw4k+QZ9c9Zp7yWi/n8QXVjvg9Z/5UVU= X-Received: by 2002:a05:600c:840f:b0:48f:d1c0:721e with SMTP id 5b1f17b1804b1-490360539b9mr3370895e9.12.1779315773033; Wed, 20 May 2026 15:22:53 -0700 (PDT) X-Received: by 2002:a05:600c:840f:b0:48f:d1c0:721e with SMTP id 5b1f17b1804b1-490360539b9mr3370055e9.12.1779315772346; Wed, 20 May 2026 15:22:52 -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 5b1f17b1804b1-49033d525ddsm23122965e9.6.2026.05.20.15.22.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 May 2026 15:22:51 -0700 (PDT) Date: Wed, 20 May 2026 18:22:47 -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 27/37] virtio_balloon: submit reported pages as individual buffers Message-ID: <0050d961a817b109ac032d121f095fb1fcc1fc5a.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 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. Note: if the virtqueue is broken, wait_event on virtqueue_get_buf hangs. This is a pre-existing issue: the old single-buffer code had the same hang. EVENT_IDX is not a concern: callbacks were never disabled, so the virtqueue manages used_event automatically. Signed-off-by: Michael S. Tsirkin Assisted-by: Claude:claude-opus-4-6 --- drivers/virtio/virtio_balloon.c | 40 +++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c index 6a1a610c2cb1..53b4a3984e7d 100644 --- a/drivers/virtio/virtio_balloon.c +++ b/drivers/virtio/virtio_balloon.c @@ -187,7 +187,9 @@ static void tell_host(struct virtio_balloon *vb, struct virtqueue *vq) sg_init_one(&sg, vb->pfns, sizeof(vb->pfns[0]) * vb->num_pfns); - /* We should always be able to add one buffer to an empty queue. */ + /* We made sure the vq is large enough so we should always + * be able to add one buffer to an empty queue. + */ virtqueue_add_outbuf(vq, &sg, 1, vb, GFP_KERNEL); virtqueue_kick(vq); @@ -202,25 +204,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