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 133DE2FDC3D for ; Tue, 30 Dec 2025 06:47:56 +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=1767077341; cv=none; b=Nz4ki+GDx1S6Yef0UuFjtwmSskyv3y/2XLXam8NGSXuflG6TEZksQqUbgOTXSStUsxBTU5+oV058nXaYnD0cDAhweos4BRK/kJYe2xD7u76kMQoSIhShjtcQVfGxjjpLY2eOk/Ncz1RF+mQYCPw89q6VwHvSl8PvK0cDP52T+Cw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767077341; c=relaxed/simple; bh=h5BSZKgj+acTNsFvAjwJJJ3zRVV/k4vnKOTMrurvSqw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=UZVJm3l4Pjtz6+lNiKFR+A+YongZ9NRgpewg+JCBwYtNWiBm6/pYGHvvEPOTxYW1It2/jR0UN7SzaenWP1xQBiC+lnjI7q/7qZf85zyZcKk/77iF2Fx+Qv9ILZ+5v9SvbG0CQfR+gNenERPgGmD6RXjWI8KAU6gcDaSaRg4oT9g= 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=YEhM7HH9; 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="YEhM7HH9" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1767077276; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XykLdeypK6IM0kkjqZ/K4gOfhaWmVqdrNwu6i75cuSk=; b=YEhM7HH9Xc03dLcbwjzp47YkkJfWt7Mb33DTSPjkTlpAkaQG9JK0Ws2gJZtjMGJFqaCfk+ Ys7xkBrC+Ag88gJqCvVH7iZsgSqr/AKzO+dCArhikslEA6vbM7rLCtiv4i7ToHj1plfH2i T+YfzHzNjtSNnrR0VUnerHwBG7sFA90= 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-90-9kFt0q_MPcqxXO8JOOlvbA-1; Tue, 30 Dec 2025 01:47:54 -0500 X-MC-Unique: 9kFt0q_MPcqxXO8JOOlvbA-1 X-Mimecast-MFC-AGG-ID: 9kFt0q_MPcqxXO8JOOlvbA_1767077273 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 3133F1956089; Tue, 30 Dec 2025 06:47:53 +0000 (UTC) Received: from localhost.localdomain (unknown [10.72.112.134]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 1819519560AB; Tue, 30 Dec 2025 06:47:49 +0000 (UTC) From: Jason Wang To: mst@redhat.com, jasowang@redhat.com Cc: xuanzhuo@linux.alibaba.com, eperezma@redhat.com, virtualization@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH V11 15/19] virtio_ring: factor out core logic of buffer detaching Date: Tue, 30 Dec 2025 14:46:45 +0800 Message-ID: <20251230064649.55597-16-jasowang@redhat.com> In-Reply-To: <20251230064649.55597-1-jasowang@redhat.com> References: <20251230064649.55597-1-jasowang@redhat.com> Precedence: bulk X-Mailing-List: virtualization@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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érez 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 33fa7fcdbd8a..0a63a79c33dc 100644 --- a/drivers/virtio/virtio_ring.c +++ b/drivers/virtio/virtio_ring.c @@ -1666,8 +1666,8 @@ static bool virtqueue_kick_prepare_packed(struct vring_virtqueue *vq) return needs_kick; } -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 = NULL; struct vring_packed_desc *desc; @@ -1678,8 +1678,6 @@ static void detach_buf_packed(struct vring_virtqueue *vq, /* Clear data ptr. */ state->data = NULL; - vq->packed.desc_extra[state->last].next = vq->free_head; - vq->free_head = id; vq->vq.num_free += state->num; if (unlikely(vq->use_map_api)) { @@ -1716,6 +1714,17 @@ static void detach_buf_packed(struct vring_virtqueue *vq, } } +static void detach_buf_packed(struct vring_virtqueue *vq, + unsigned int id, void **ctx) +{ + struct vring_desc_state_packed *state = &vq->packed.desc_state[id]; + + vq->packed.desc_extra[state->last].next = vq->free_head; + vq->free_head = 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) { -- 2.31.1