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 C4A983D34A6 for ; Mon, 11 May 2026 09:03:56 +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=1778490238; cv=none; b=UDhEyxqBy/7WJKalzF7eSEP3RYfXSBYn6h0nWVUd0U+YTUCVOAnKO/CcanvMKf1Nr2C+v0DQxPCxMJWe8JljZKeCgQLb2eEZZTMbjUU818lk1UuNseZdR88MuDiZBsVEof3rv7qheXLTyKGc23k5u/2yfM+2mQFubo7KglO+nzo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778490238; c=relaxed/simple; bh=oYf8Ac6ioZ/fyq4O92mQTh5p7Zvk+J/G+lE9Pf1TUvg=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=ucENbClFZPceE4a6h9gshjp1lcCrSd6zgdyl1n4HGAFqw1Rrfz23auAxPFdNmfCPsxGPuujcvrrv9sS4qKNyQT/NU6zEQH8j7v+jpGxQurJKdyAra8rSW52A3GnPj240si7IFKK+bEoSYSAiOF/IKvZdarYr3W2bJzcLmMP6uws= 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=UiDsfoAP; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=M2XhiRpE; 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="UiDsfoAP"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="M2XhiRpE" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1778490236; 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=kJvki5d0ND9UiDEat7+4BM/+FuHUbmXzqDz6vRDL3g0=; b=UiDsfoAPyh8DvlsmbwlwZkFoMwSXBRWCKPbpkGlR7MaTVfgJFhYHtASf2KppEH0FqljApE cZC/5YU5LJloStxPsySLWnLOQS7Qixrc+KrtR7Tgyd2tLp5tkjNrE7YvlAA98TZr1ZUSQp cMvRmpEj5vq8DSbL+SbkruoXigPy+7U= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-635-A8DbqIKENGO7Hh4MTiI79A-1; Mon, 11 May 2026 05:03:54 -0400 X-MC-Unique: A8DbqIKENGO7Hh4MTiI79A-1 X-Mimecast-MFC-AGG-ID: A8DbqIKENGO7Hh4MTiI79A_1778490234 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-43fe791a398so3726920f8f.0 for ; Mon, 11 May 2026 02:03:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1778490233; x=1779095033; 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=kJvki5d0ND9UiDEat7+4BM/+FuHUbmXzqDz6vRDL3g0=; b=M2XhiRpEUXE8491wCsbLdTmkIH37fEp1bj3ucw3+L01XO9aniDNi9VahR9EMQN0iBF F5l2wWRDLe1Ugx6ekObqcVkNyIi2G0kQ91ToyS5Rc13gVpJHlAfjznCoGIy2ev/ZIn+Y DqK7xymuSlTIqxdcAO+PSrsliEYlqLdL7PFVGFSke6gXL2Rx6N0wSWzD/mAtgIRDte0S MA6eiNBw4Hqx6EKzj8nDUyhcxM/dEGZkgxOrkKwLE9/1xy4eYHU+ugNajaNtVqQr4cTo dDFqnzvkONU8UtoZk/yzAyDdo53+b0jYAkKZ/Du9KxIkxBqF1Om6hwMwAKbUTr4PYhCG dBVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778490233; x=1779095033; 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=kJvki5d0ND9UiDEat7+4BM/+FuHUbmXzqDz6vRDL3g0=; b=Ms/WziiZc074S9Egw2eow1zLY9XVVyT9sK+Njly5+C5oNvd2/ddTwyz7iZNb7ORyK/ x/hsSJPLpy9OVqzxsqHDiUIZC8xlWt8PTqS5dSG5Qxr9FLgg6a+y+APZKcfTs9M4jGDV +LFphCmPy4Gyc6PvFwLT0RktTpfFHam3pp6c2FCDK+WcenTklStDw6ejbXDG94GiTQ0l 796YWki0DDcedVMHK0BfCRdkXJ8cgn19xNmas2tIMtCkvKTjkXo2WtJu4O3T/Mwd13XZ HUvVH4hVMGNxsxX84xtFVHhumA5iZyLIsLqu9YtIxGD/G1gvgg7Ya9stwyQoBcH1+Qug 8kvw== X-Gm-Message-State: AOJu0YxK3dDii1TNiFXIBB3Nm8xxlTQwRLdeYY5tAcu8kGy6CBvE39hs HqurkDSeqd0oAeCUxg41FX1EpWwhgFN/MOFl9DnmpTvCp1ky2GJDd/YNTKADqL9qK4BCSY41BZv odPF1/np52VrsEkyPZeRbpWanI7Bd237wB2Z7VmSOcRPrMEXDQHvxQ7AbvR5w+5e6l9sAnhr2p0 1CKkjmoCdFFkL6ELhv3z5cZ86MMwWl/UGX15nKbmRRHhc= X-Gm-Gg: Acq92OHAmING6kHOMXhqQp1+v3rSXDqsXwGdvn4bnbNfcMIPuHPtD/sgkEjyypwW9at 4GL5cHRiGv1EC4C3FBmXHkEXXjVyWSwsbOSldVeqdwYi5p8G8GdtHXnQH3NC+S2gJ7PgJXdk1Ey RQ4yIpZvsN6noObxmo1KBk+cz0SvB538U1sxNbzXKv5RxytSz8MD5OeHOIL/bZRk/tf90bKUR8+ uqNX0w+8Y+LO9BgWjiOW9DWfz45cKyVGFTt57XVDhtEiaeqmLYn2UcwktbgzcGhgYHY4HM4Zp9o QHpX8si7+B2Ua8+1ju84V4x+U/iOwSP3VD2g8ErYXG8OdC+uG576Q8ssDZFWgtMTiNYXJrwm2KR vYkaGaYZNieBowS9BUdZ/sY2R04F14D3MgBZD4mw1 X-Received: by 2002:a05:6000:2909:b0:44b:e349:e6bc with SMTP id ffacd0b85a97d-4515b056ac1mr37167889f8f.3.1778490232971; Mon, 11 May 2026 02:03:52 -0700 (PDT) X-Received: by 2002:a05:6000:2909:b0:44b:e349:e6bc with SMTP id ffacd0b85a97d-4515b056ac1mr37167751f8f.3.1778490232034; Mon, 11 May 2026 02:03:52 -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-45491304387sm23431955f8f.21.2026.05.11.02.03.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 May 2026 02:03:51 -0700 (PDT) Date: Mon, 11 May 2026 05:03:46 -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 resend v6 22/30] 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..fdfd828657dd 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; /* 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