From nobody Mon Oct 6 08:24:23 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 4D97B24DD11 for ; Thu, 24 Jul 2025 06:41:33 +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=1753339296; cv=none; b=sg/pO0lKISnP9V0KEoH20GXrr6aYrhUBqD4lDLPDkg3j40aOo2B1KLovbuTcfIs8306KFMuuDZmKqzPnGzMdY7qEO6piHeaG2iiJnqsL/bnAfURgXpWHNgBbQNVOMy0fqIBKEpSZHYzbQ65+p5r2Hb6QhFwa6UQd0MsjTkio5Uo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753339296; c=relaxed/simple; bh=h2Qp87PI0h1xjsXyVE7VBnmnVfNlPemFMuexCczlqIk=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=hh341PEdWr97ovSQ/36XyLQZBJ62gxkfuLS6Bh/swVrpYv8t4yKUwBYvFqxD+rpaAfF2W8hXzr3Vzo13ctfb08taUkDV43IkuXTbsEAm+bCbaws0qWo3MPkTmsi6vYO6GY6YNVOQthdYXfyeXnoQ/YAoARXrfCMitamF8UKeOyM= 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=guBW8RDc; 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="guBW8RDc" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1753339292; 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=uLj4vQ76k5rdjrHpOoONiDq/brYcC+kkPUOFiNuUnfI=; b=guBW8RDceqKVvN5ixeyV+x+ppZWO9k1L9aweZjckt0ivhtYTexl9OTidBuFi8+QgOhDFIL HXz8cRw63eNzv0GM7H3s+jxKQ4VcFMqJHFc3yX1Og3gm9xAKtndI3WQaV8vciz75IqTkSp wpnsZPq+oBhGEUEAuHcQqm2fFZ0Mrbk= Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-298-BF6AXSlwPv-Pkf0uhWb2-A-1; Thu, 24 Jul 2025 02:41:29 -0400 X-MC-Unique: BF6AXSlwPv-Pkf0uhWb2-A-1 X-Mimecast-MFC-AGG-ID: BF6AXSlwPv-Pkf0uhWb2-A_1753339288 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (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-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 28EF5180028C; Thu, 24 Jul 2025 06:41:28 +0000 (UTC) Received: from localhost.localdomain (unknown [10.72.112.231]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id EE40F180035E; Thu, 24 Jul 2025 06:41:24 +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 V4 15/19] virtio_ring: factor out core logic of buffer detaching Date: Thu, 24 Jul 2025 14:40:13 +0800 Message-ID: <20250724064017.26058-16-jasowang@redhat.com> In-Reply-To: <20250724064017.26058-1-jasowang@redhat.com> References: <20250724064017.26058-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.4.1 on 10.30.177.111 Factor out core logic of buffer detaching and leave the id population 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 01bbbcd65417..b0eb68efb535 100644 --- a/drivers/virtio/virtio_ring.c +++ b/drivers/virtio/virtio_ring.c @@ -1663,8 +1663,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; @@ -1675,8 +1675,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_dma_api)) { @@ -1713,6 +1711,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; + + return 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.39.5