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 0A16B42B746 for ; Fri, 29 May 2026 15:24:47 +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=1780068289; cv=none; b=oorZQuKsjD5VnCKKatTbVPpRLxTd0SgQf1wVNw2JwR0zIfUfxUnM7cWgNdLQipHEVTtBiCYr0CEgBivHupSSeT4kBk+9O5qBH9zjuxvUbyvZ3baVOK9HeTxqZm/E1MQCWwY0vlY97VLrYpvfGbI+0qfO/0n/SL5B2oCt0n+8nmo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780068289; c=relaxed/simple; bh=NEUFfCyJTTjkAORA91qK34iLisrtuxPbcfRlH9SPC6Q=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=XZyqdnZZLRj+sSGxiQFLKjAYmCagI/wtJCWpREgt2Up9yPDW0nlSk1EUDiwPntF2Uun+ir4LvRGfxmI4WIuzekj1U5Z37bArblreTpZGrU6jApAtA9z1v+OhzUU7aC/lamoHhG3pamALlcD/5T5HNTIWeS+quBxtDgn+eF8mr6g= 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=frM9KVVe; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=Lu3Xy2j7; 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="frM9KVVe"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="Lu3Xy2j7" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1780068287; 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=frM9KVVeVfXxn8IG5spbZuNswEja8O5FiksbmqsRJq5d/INTQ1DfWYWtYSd6Sqzt1t+KyZ fhTyQF7LWK2dkX/UdolxG9UYiOyBINMqQF33/dmrt05ykq5svvk9wTKTrCo2CmHgOVPYCF YQhAGjtbLm4lMEVFVT68Jj9U/lfxwXY= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-623-q9q37VMQN1SzyM4tpfpsWw-1; Fri, 29 May 2026 11:24:45 -0400 X-MC-Unique: q9q37VMQN1SzyM4tpfpsWw-1 X-Mimecast-MFC-AGG-ID: q9q37VMQN1SzyM4tpfpsWw_1780068284 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-45ef3aeeb41so385149f8f.1 for ; Fri, 29 May 2026 08:24:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1780068284; x=1780673084; 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=Lu3Xy2j7SnJiEOvoT3am1A5cs8DAFghQxwjOPnI8ZvPK+cmOiOi5xmfZPxQRVICKpN 6fXVIP6obq4qcc5y1RJkbdDTvW0PSsTVfXHYW2eKMRPjdzcwwPvlQg+lDMIYoll2HkmS N2V6sMhqiOFSdMwACvcu20poAs0YR//SAR9l/4helqFpAbl2iEZvPyit+CdgsLrRijBB PHAL7uUHcNQv9vVGEzehvGcsTUi7PnmJev0rTjStkWN+N8FtwhtTm21RBtWeqxm21G4i cA6xn4t+aP3ohmIeWBuLClcK61Xq++xzWHJyLSV3jEFsmDaL8puWpZbyrjYHS9rRq7HX EClw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780068284; x=1780673084; 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=oXWzQCph03kHe3IgN58v7vMrvO6JuSqUW6WresDodjkboB4j3wXFRNSU2lIT1w5jx1 9RtlU+2+MIkJ7r0g50eqX5PfbedZzRM+fyL8PjiU2smBmmaU+5viSto0E2Edf+r99gCe OMbyUHCd0TmLPqFht/QdqTXCpaom8qCQElUswuFF1U/1lfV7F1ZKYSdWXCre8QD+Vy3P SQSjMBozZK4HXN849pKjBJwevYPTXV7h9UX1kMdf94nZS5/a1pTkMAcWtYfmfpMmzieM uu5quv5kBD5LoZcUvJBvepnI9BbiU/kbpOj3aWAtwxrBeJdBE4oG/8VitkQPeeKjw9oj eWcg== X-Gm-Message-State: AOJu0YwYshPMxgoWCzJuM7gfDziZhKXmRIhEAFbt4lvS9ikcIAiujIvw hQA3jbq+d/1zhWZRpDgQuviHcfyq/rldI+ZeaQ/9PZwYKi28ZzD4wYdXIxjCgZP7YqPQeExuVw8 NOfQjkOSUuy95z8/W5Vn/QuHuQzZ5Te8ZooFxnW3ISun2pZ8W5krVnLRTQtM/PCoDqfOBevytdj Bt3zxh+h2LrUrQXU8yI36y0vnNKiIryHhZIgiHA7VA5EE= X-Gm-Gg: Acq92OEY86I7s12mBvPHRrLuILVZS1rTj54m1haEQeNGdOR8qBjiMjpyFB5KPSA2Eqt O9VWINXs6ohPpredQJcEBUxu1A3a1J2HvOgLKhVx0SUlTC4wxLimvu5SdzorBCv4bmKWIkPib6o McDKewCk1iY3dSbWP2pLjgLrAcKdKH1VuRSd1svJHq4SL+A30OGMXHpCM4DNcEjDe2kuPLIflX/ XYzeoa6gUDRMFlpHzRjU2vj6anZuTvy1dOwTTQRotatr5g+AwzAlNgoM2VnAlWk8BfcyQgonj02 CrsyHQHcLUHzPGrEv2443X2BDigmYOmO/IQ8YqEHMRdNo5DvlVoKF+UqaZTQ0n12fOn6W8adTsE uN2Z2ku4Pj9SUso2l5clocTjRVxcYKB1TiGjadrIhhYWmrEB24aMb2w== X-Received: by 2002:a05:600c:630f:b0:490:845d:652d with SMTP id 5b1f17b1804b1-490a2948eedmr1400695e9.15.1780068284353; Fri, 29 May 2026 08:24:44 -0700 (PDT) X-Received: by 2002:a05:600c:630f:b0:490:845d:652d with SMTP id 5b1f17b1804b1-490a2948eedmr1399385e9.15.1780068283514; Fri, 29 May 2026 08:24:43 -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-4909d7002e8sm58813385e9.15.2026.05.29.08.24.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 May 2026 08:24:43 -0700 (PDT) Date: Fri, 29 May 2026 11:24:38 -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 27/37] 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. 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