From nobody Tue Dec 2 01:03:56 2025 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 DA0B62FDC43 for ; Tue, 25 Nov 2025 07:09:58 +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=1764054601; cv=none; b=cWDF1XO/LrM4BfjvTnZ7pn2KDwvub3xqhjvsEyV+11RkW17HqUoifd46rjd8BmXYsB2K0UnBhxui3fDGBMdrR5lSzHBSSiPuNGulApK767KXycDV3Unp/IZhSvWR9Ubi8sSuVwj8B9PBx6nLhcyR0X1Hyt4T8di3x/z75gKzAxA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764054601; c=relaxed/simple; bh=jT45+gYAZb3lmVZ0lmRdq+HBXPY+MsirmR4IBchEZEU=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=uxCDNz3APD66lz3herlsS/T5nud7Nxas4mhwrc4831YH4GL8qcIpHqaonE0Z4F4srFrQn/o2y8W2de6IxgDuPBJqpAvERqQCuJcNjWDEXPyMDBgGzVp940j1AiGaFoGgYGYrgM3BOxEOH2o3S086jHAEKIcfHoKPBNL02RX1JTU= 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=Dy+7X8gA; 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="Dy+7X8gA" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1764054597; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=LgjMqSGgSOscOTaLT7lOFtNx5D/azBRAkOh8QKI/gKQ=; b=Dy+7X8gAEVyfpPSiaV8sSYsqDUa/N7iRamOp3zUtJ4tEcnRQqOQYUFG7HCrIpKgAjqZgwG 57IAfj+5bCsH5Ut77nfq4E/OyZ4ZEkOleTpODm7hqlGkBfiX0+kERkSdXimsSZAbWp3XsG 4y36ImZocduiqXnzE/LgrDfoDNmwkTc= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-320-fUt4C1byOWWm55Ipi88xjw-1; Tue, 25 Nov 2025 02:09:56 -0500 X-MC-Unique: fUt4C1byOWWm55Ipi88xjw-1 X-Mimecast-MFC-AGG-ID: fUt4C1byOWWm55Ipi88xjw_1764054595 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id E229F19560A7; Tue, 25 Nov 2025 07:09:54 +0000 (UTC) Received: from localhost.localdomain (unknown [10.72.120.4]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 44BC21956056; Tue, 25 Nov 2025 07:09:50 +0000 (UTC) From: Jason Wang To: mst@redhat.com, jasowang@redhat.com, xuanzhuo@linux.alibaba.com, eperezma@redhat.com, virtualization@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH V9 15/19] virtio_ring: factor out core logic of buffer detaching Date: Tue, 25 Nov 2025 15:08:34 +0800 Message-ID: <20251125070838.70736-16-jasowang@redhat.com> In-Reply-To: <20251125070838.70736-1-jasowang@redhat.com> References: <20251125070838.70736-1-jasowang@redhat.com> 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="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Factor out core logic of buffer detaching and leave the free list management to the caller so in_order can just call the core logic. Acked-by: Eugenio P=C3=A9rez Reviewed-by: Xuan Zhuo Signed-off-by: Jason Wang --- drivers/virtio/virtio_ring.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c index dbcd6f26df7d..ca33af830f65 100644 --- a/drivers/virtio/virtio_ring.c +++ b/drivers/virtio/virtio_ring.c @@ -1667,8 +1667,8 @@ static bool virtqueue_kick_prepare_packed(struct vrin= g_virtqueue *vq) return needs_kick; } =20 -static void detach_buf_packed(struct vring_virtqueue *vq, - unsigned int id, void **ctx) +static void detach_buf_packed_in_order(struct vring_virtqueue *vq, + unsigned int id, void **ctx) { struct vring_desc_state_packed *state =3D NULL; struct vring_packed_desc *desc; @@ -1679,8 +1679,6 @@ static void detach_buf_packed(struct vring_virtqueue = *vq, /* Clear data ptr. */ state->data =3D NULL; =20 - vq->packed.desc_extra[state->last].next =3D vq->free_head; - vq->free_head =3D id; vq->vq.num_free +=3D state->num; =20 if (unlikely(vq->use_map_api)) { @@ -1717,6 +1715,17 @@ static void detach_buf_packed(struct vring_virtqueue= *vq, } } =20 +static void detach_buf_packed(struct vring_virtqueue *vq, + unsigned int id, void **ctx) +{ + struct vring_desc_state_packed *state =3D &vq->packed.desc_state[id]; + + vq->packed.desc_extra[state->last].next =3D vq->free_head; + vq->free_head =3D id; + + detach_buf_packed_in_order(vq, id, ctx); +} + static inline bool is_used_desc_packed(const struct vring_virtqueue *vq, u16 idx, bool used_wrap_counter) { --=20 2.31.1