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 A36B53BFAD1 for ; Mon, 8 Jun 2026 08:40:14 +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=1780908016; cv=none; b=SSzseJuHzy9yxW8++AiIdIED1mtZteLdRm0RCS5MBp/iMvldemv29qVK1Dq1wqUWWHMhMbHmOQ5jN+L4igeUapscUQNrsoLg1b5wt0CT/pdiG1S4G1g5XKQrhpxbJVsKJde6mTamypPd7aCUxVTWit870NnFYhHPcloPf2YsHFo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780908016; c=relaxed/simple; bh=JiJWE7l+ip28dmS9nLt+boIUyEWSXna1gjhWeHw0vBg=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=OvpQUsbyawHSGyt5kLNQUd9toJ9tHDFTV1vD0KcAzdDga3IwfdDxXCkYJHSg2CfcfbK/5uw2Yt4uwQVM9wHEY1Gf4gLIvp9lSMz7ZsrehVRL3nJH6KQiC41bz68bm0W8HJYNSQ/MRx0g6YIECLkx7LPKISJJpGCUkU6NFRkPy7I= 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=B0K0T8O/; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=sANmSgM6; 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="B0K0T8O/"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="sANmSgM6" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1780908013; 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=jJIh5LHG5pOtGoQVym0SRNgbl1Zw+eEBG1qiVMPIhiA=; b=B0K0T8O/K8KJfRdqn5yhcSG5YUD2kOxaHXIFu+rOGvTHNugGjxRrGz7smFuXTEl2AXpKS+ rM8XSkLAHzpc8DyPBkQvuUIRO14XFw64X/n8psAnlOu+Cgz59VFvj/WodA9h8aGu4FVNP0 FGHSw7b7Su2BeqpXKhJb4sEbNJwNx8I= 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-433-sEqNWKnZMxOBgR-v7ks1OA-1; Mon, 08 Jun 2026 04:40:07 -0400 X-MC-Unique: sEqNWKnZMxOBgR-v7ks1OA-1 X-Mimecast-MFC-AGG-ID: sEqNWKnZMxOBgR-v7ks1OA_1780908006 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-46016bedbaaso1388387f8f.1 for ; Mon, 08 Jun 2026 01:40:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1780908006; x=1781512806; 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=jJIh5LHG5pOtGoQVym0SRNgbl1Zw+eEBG1qiVMPIhiA=; b=sANmSgM6ZMQPSHvo4un0bOA/5FJYUkzS79ckGlPQPePZbxrw9rMAJ1qWpVtYWATuth xJqJH/n/cUTQXaBNaNbOOBYY5IZhFATPjL0laSQg1HaqHwkwhiDs+mibOpImVRwWvMBG VeX1TCkEGBO/0Lok7lnzfdVcKnVEJ8goDyXnZm9hXt4M8EUxMzGXxZ0P+JZ3SjDpKRO4 Q7ixs7rUF76ikY4Kvcjs8X4QMUuc3IYrDZnGzXAlMm2WHfIVP4TveVhEJJSn7I4EDbb9 SXPXeAGfOmWSCdTjnQE5N7jSjW1s9Eg5+guYjmgLcHf7knufPzAnFrVmh/J5YNYJYBKU 7QJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780908006; x=1781512806; 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=jJIh5LHG5pOtGoQVym0SRNgbl1Zw+eEBG1qiVMPIhiA=; b=hhQyb5VrZgv2WuACL6BlJiPDKPiQZ9rcwa1oMDNEa6/9gZtoUGlXrpjDpSaq3OmzKN sWAMnC4pllaAeOFXBs2Bok5gomATEH9G92yqzKFtNl3PfXdQeM+1W8Tbwm4vzmSN816G ugTIrHhDgvYxm1CZ7ZFHkm8h8qOBevOONt2XYFf5ECnVvLIRYzjlqfuMuaBtf/JWXTne cVhXAKsYqVF4cgtF6/R3nk5CavIzL0TwwjTqEfekT9N8Dd2O3h6w3QfSOPqh7Z6jOJye NLLomZhKQhC6mds0uKSB748gl3Kl5gmtYHI1uyaMW5FDA2vgYdE4aj+Mlfk1BFATD8fQ +Dng== X-Gm-Message-State: AOJu0YxRrEp0BFoMrx55ZHI3+vtOUCsC38Dgb6zq7FHO/B+J+cYANP3x DYhP5XAUGjwO0fq8RhI2Vc0P96UeEQ3e0YkmoiunoujLfDf9Vmi7NmoABe0r/LGI0nTkWtuIfsF 3Xb0nnb7auMUDwvNpGZgf19IcRaBB0/x2ac2Y/mQDiBzSz+oEO2LDKqLZqfRHlUpHObmnbeuP6f y+bY+/A5g9DJ9Xs9kANaXx+gCjV4Wq/MnCy1Z+iyAAEno= X-Gm-Gg: Acq92OF68SoOXBzhdhSwuUUFz16JgVZqahTLLFeXte+eIMZbqH5YBvapRRnwNQ0fdsl MQwEC07NmgNGqdT47HUJGDCRdrkjCSld1V2E46u8OzRWDz874uo2Wmi/lG1zvQqXsxOdZiB+EPT kpagnvErQUoEVXKNGWMHAPE2mJ3q7LU/5/XiQlNFFsDYw1bsp1brUgTPGxqa0RTfx0XTHlwt1M0 +y36sjSzHpsHbuFDxtC1DWrkXGBSab/RxLL6stRp7dGfO3HkgNPkfCrNdBmiywdBKJQlgvxkSgA SqtBhdTNa2GM2qQGyRoazIy7/jPjwNSgSMn4q9J4k/NlvtbepdCZ8e7f/jsBCcgb+UbHr5VUoZt qbJ1HELoDDaRyNV8G8Je7QUQ= X-Received: by 2002:a5d:64e6:0:b0:460:3233:6700 with SMTP id ffacd0b85a97d-460323367c8mr22945834f8f.43.1780908006248; Mon, 08 Jun 2026 01:40:06 -0700 (PDT) X-Received: by 2002:a5d:64e6:0:b0:460:3233:6700 with SMTP id ffacd0b85a97d-460323367c8mr22945715f8f.43.1780908005559; Mon, 08 Jun 2026 01:40:05 -0700 (PDT) Received: from redhat.com ([31.152.37.159]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4602cda363bsm38411715f8f.31.2026.06.08.01.39.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Jun 2026 01:40:04 -0700 (PDT) Date: Mon, 8 Jun 2026 04:39:57 -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 v10 31/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.51.2.2891.g4157995a80.dirty 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