From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F0169C41514 for ; Fri, 9 Aug 2019 06:49:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C33252171F for ; Fri, 9 Aug 2019 06:49:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2405654AbfHIGtH (ORCPT ); Fri, 9 Aug 2019 02:49:07 -0400 Received: from mx1.redhat.com ([209.132.183.28]:39386 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2405239AbfHIGtH (ORCPT ); Fri, 9 Aug 2019 02:49:07 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 493D7C074111; Fri, 9 Aug 2019 06:49:07 +0000 (UTC) Received: from dhcp201-121.englab.pnq.redhat.com (unknown [10.65.16.3]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7870C1001925; Fri, 9 Aug 2019 06:48:59 +0000 (UTC) From: Pankaj Gupta To: amit@kernel.org, mst@redhat.com Cc: arnd@arndb.de, gregkh@linuxfoundation.org, virtualization@lists.linux-foundation.org, jasowang@redhat.com, linux-kernel@vger.kernel.org, pagupta@redhat.com, xiaohli@redhat.com Subject: [PATCH v3 2/2] virtio: decrement avail idx with buffer detach for packed ring Date: Fri, 9 Aug 2019 12:18:47 +0530 Message-Id: <20190809064847.28918-3-pagupta@redhat.com> In-Reply-To: <20190809064847.28918-1-pagupta@redhat.com> References: <20190809064847.28918-1-pagupta@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Fri, 09 Aug 2019 06:49:07 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch decrements 'next_avail_idx' count when detaching a buffer from vq for packed ring code. Split ring code already does this in virtqueue_detach_unused_buf_split function. This updates the 'next_avail_idx' to the previous correct index after an unused buffer is detatched from the vq. Signed-off-by: Pankaj Gupta --- drivers/virtio/virtio_ring.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c index c8be1c4f5b55..7c69181113e2 100644 --- a/drivers/virtio/virtio_ring.c +++ b/drivers/virtio/virtio_ring.c @@ -1537,6 +1537,12 @@ static void *virtqueue_detach_unused_buf_packed(struct virtqueue *_vq) /* detach_buf clears data, so grab it now. */ buf = vq->packed.desc_state[i].data; detach_buf_packed(vq, i, NULL); + vq->packed.next_avail_idx--; + if (vq->packed.next_avail_idx < 0) { + vq->packed.next_avail_idx = vq->packed.vring.num - 1; + vq->packed.avail_wrap_counter ^= 1; + } + END_USE(vq); return buf; } -- 2.20.1