From patchwork Tue Dec 13 08:12:07 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yuri Benditovich X-Patchwork-Id: 9471885 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 08869607EE for ; Tue, 13 Dec 2016 08:17:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EC154284C3 for ; Tue, 13 Dec 2016 08:17:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E069F284EA; Tue, 13 Dec 2016 08:17:06 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 60907284C3 for ; Tue, 13 Dec 2016 08:17:06 +0000 (UTC) Received: from localhost ([::1]:36092 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cGiGn-0003mK-Eg for patchwork-qemu-devel@patchwork.kernel.org; Tue, 13 Dec 2016 03:17:05 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52116) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cGiDh-0001kH-5i for qemu-devel@nongnu.org; Tue, 13 Dec 2016 03:13:54 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cGiDg-0003zb-7E for qemu-devel@nongnu.org; Tue, 13 Dec 2016 03:13:53 -0500 Received: from mail-wm0-f66.google.com ([74.125.82.66]:35817) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cGiDg-0003v6-14 for qemu-devel@nongnu.org; Tue, 13 Dec 2016 03:13:52 -0500 Received: by mail-wm0-f66.google.com with SMTP id a20so16643915wme.2 for ; Tue, 13 Dec 2016 00:13:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references; bh=003RNZdpZD7+hYXFzey8OmV2h+d/kaUBFt8eoeQhh+A=; b=JQPh8BmtR9QGAZEJcVi8Hv3aM4dyVI/NatvHJ/MVkbYJLacmLWDTEOob94v18P+6GI Qsu9Ji74BDHXucwG5tuCg1wAMFzGY1rfmGxCyb3Z2O2vOxZF/jWdEArflsCujIA8iA+7 T0yEvPdX98yVfte5w0pkS28Bim/am6pJRrl2PYPsEMRFNo5oXXjkRg8f1VC5nAiLmrQk 5du5DMtNPWqqDdx2XdMzWt6hPQaUQBcF6bserpOvek2QocJJEtXG8zad4Ss7p9XQFITK n6w3QQt8KMVAOpr5gVHfMkoOqJlJ3fMGYLUu3CuGUpxzh0ckak1/KERhnXBaXGU2fVY2 t7Aw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=003RNZdpZD7+hYXFzey8OmV2h+d/kaUBFt8eoeQhh+A=; b=ZyUhOFNCnMHn1BQOPbNsiLi7hDtOBk0PTOHTmJhJTmYl3NzPfHIK5NGH+qOjr6eW2B wnv9+sUJ79xacgg9QgLqVRTY92NNLO67LgEWJuuuGa7lrNyI9gSoQLbZcO8Uo0FS3zfw zFqm7MtlghVx43hQ897rZy+XwxDZKH7Nq57KFlvySS0FFrKEPklrMM234gI0ih9zj3gp zOOl2kdrtJFDKw70OIaXbbJgQo4uBBh7nRGypUv+gJBaeJPiZqvuynz8Vn6IZTwbRnOf waW2GG44q2C0W6Unni+H36C/yOzzaWk8M0SUzQsyMlaSI7zvpGhkBaKBRZgPEeRwqFsQ iFUA== X-Gm-Message-State: AKaTC03pwXiGfq9wNiwpydlhTDpYaC0uyYfqqcFM1ky6Pvbb30BDsyRRWTn9BooU/H+amg== X-Received: by 10.28.18.129 with SMTP id 123mr1338030wms.2.1481616748328; Tue, 13 Dec 2016 00:12:28 -0800 (PST) Received: from localhost.localdomain ([141.226.163.133]) by smtp.gmail.com with ESMTPSA id d17sm60996111wjr.14.2016.12.13.00.12.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 13 Dec 2016 00:12:27 -0800 (PST) From: Yuri Benditovich To: qemu-devel@nongnu.org, Jason Wang , "Michael S . Tsirkin" Date: Tue, 13 Dec 2016 10:12:07 +0200 Message-Id: <1481616728-148412-4-git-send-email-yuri.benditovich@daynix.com> X-Mailer: git-send-email 2.7.0.windows.1 In-Reply-To: <1481616728-148412-1-git-send-email-yuri.benditovich@daynix.com> References: <1481616728-148412-1-git-send-email-yuri.benditovich@daynix.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 74.125.82.66 Subject: [Qemu-devel] [PATCH v3 3/4] virtio: Introduce virtqueue_drop_all procedure X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Add procedure for fast drop of queued packets, acting like pop and push without mapping the buffers into memory. Signed-off-by: Yuri Benditovich --- hw/virtio/virtio.c | 38 ++++++++++++++++++++++++++++++++++++++ include/hw/virtio/virtio.h | 1 + 2 files changed, 39 insertions(+) diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 45536e4..6fdba50 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -765,6 +765,44 @@ err_undo_map: return NULL; } +/* virtqueue_drop_all: + * @vq: The #VirtQueue + * Drops all queued buffers and indicates them to the guest + * as if they are done. Useful when buffers can not be + * processed but must be returned to the guest. + */ +unsigned int virtqueue_drop_all(VirtQueue *vq) +{ + unsigned int dropped = 0; + VirtQueueElement elem = {}; + VirtIODevice *vdev = vq->vdev; + bool fEventIdx = virtio_vdev_has_feature(vdev, VIRTIO_RING_F_EVENT_IDX); + + if (unlikely(vdev->broken)) { + return 0; + } + + while (!virtio_queue_empty(vq) && vq->inuse < vq->vring.num) { + /* works similar to virtqueue_pop but does not map buffers + * and does not allocate any memory */ + smp_rmb(); + if (!virtqueue_get_head(vq, vq->last_avail_idx, &elem.index)) { + break; + } + vq->inuse++; + vq->last_avail_idx++; + if (fEventIdx) { + vring_set_avail_event(vq, vq->last_avail_idx); + } + /* immediately push the element, nothing to unmap + * as both in_num and out_num are set to 0 */ + virtqueue_push(vq, &elem, 0); + dropped++; + } + + return dropped; +} + /* Reading and writing a structure directly to QEMUFile is *awful*, but * it is what QEMU has always done by mistake. We can change it sooner * or later by bumping the version number of the affected vm states. diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h index a1a75ed..eb0ea4c 100644 --- a/include/hw/virtio/virtio.h +++ b/include/hw/virtio/virtio.h @@ -172,6 +172,7 @@ void virtqueue_fill(VirtQueue *vq, const VirtQueueElement *elem, void virtqueue_map(VirtQueueElement *elem); void *virtqueue_pop(VirtQueue *vq, size_t sz); +unsigned int virtqueue_drop_all(VirtQueue *vq); void *qemu_get_virtqueue_element(QEMUFile *f, size_t sz); void qemu_put_virtqueue_element(QEMUFile *f, VirtQueueElement *elem); int virtqueue_avail_bytes(VirtQueue *vq, unsigned int in_bytes,