From patchwork Tue Jun 5 19:07:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Xu X-Patchwork-Id: 10449113 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 8B59B6024A for ; Tue, 5 Jun 2018 19:09:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7AE7D29C1E for ; Tue, 5 Jun 2018 19:09:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6F46E29C20; Tue, 5 Jun 2018 19:09:38 +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=-7.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI 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 122DF29C1E for ; Tue, 5 Jun 2018 19:09:38 +0000 (UTC) Received: from localhost ([::1]:48639 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fQHKr-0003gE-3L for patchwork-qemu-devel@patchwork.kernel.org; Tue, 05 Jun 2018 15:09:37 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42473) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fQHJW-0001wi-4I for qemu-devel@nongnu.org; Tue, 05 Jun 2018 15:08:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fQHJU-0002x4-Rv for qemu-devel@nongnu.org; Tue, 05 Jun 2018 15:08:14 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:50264 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fQHJU-0002vn-Kz for qemu-devel@nongnu.org; Tue, 05 Jun 2018 15:08:12 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A96D640753AD; Tue, 5 Jun 2018 19:08:10 +0000 (UTC) Received: from dell-per430-12.lab.eng.pek2.redhat.com (dell-per430-12.lab.eng.pek2.redhat.com [10.73.196.55]) by smtp.corp.redhat.com (Postfix) with ESMTP id 503C9202698A; Tue, 5 Jun 2018 19:08:07 +0000 (UTC) From: wexu@redhat.com To: qemu-devel@nongnu.org Date: Tue, 5 Jun 2018 15:07:55 -0400 Message-Id: <1528225683-11413-1-git-send-email-wexu@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Tue, 05 Jun 2018 19:08:10 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Tue, 05 Jun 2018 19:08:10 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'wexu@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [RFC v2 0/8] packed ring virtio-net userspace backend support 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: , Cc: jasowang@redhat.com, jfreimann@redhat.com, wexu@redhat.com, tiwei.bie@intel.com, mst@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Wei Xu Todo: - address Rx slow performance - event index interrupt suppression test v1->v2 - sync to tiwei's v5 - reuse memory cache function with 1.0 - dropped detach patch and notification helper(04 & 05 in v1) - guest virtio-net driver unload/reload support - event suppression support(not tested) - addressed feedback from v1 About guest virtio-net load/unload: Since last_avail, avail_wrap_count, used_idx and used_wrap_count are all 16 or bool type variables, so I turned to merge them to 'vhost_vring_state.num' in stead of introducing a new case in handling ioctl, test has been done with a tweak in kernel side like: Wei Xu (8): virtio: feature bit, data structure, init for packed ring virtio: memory cache for packed ring virtio: empty check and desc read for packed ring virtio: get avail bytes check for packed ring virtio: queue pop support for packed ring virtio: flush/push support for packed ring virtio: event suppression support for packed ring virtio: support guest driver reload for vhost-net hw/net/vhost_net.c | 2 + hw/virtio/virtio.c | 677 +++++++++++++++++++++++-- include/hw/virtio/virtio.h | 4 +- include/standard-headers/linux/virtio_config.h | 15 + 4 files changed, 649 insertions(+), 49 deletions(-) --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -1439,10 +1439,16 @@ long vhost_vring_ioctl(struct vhost_dev *d, int ioctl, void __user *argp) r = -EFAULT; break; } - if (s.num > 0xffff) { - r = -EINVAL; - break; - } + if (vhost_has_feature(vq, VIRTIO_F_RING_PACKED)) { + vq->avail_wrap_counter = (bool)(uint16_t)(s.num >> 16); + vq->last_used_idx = (uint16_t)(s.num >> 32); + vq->used_wrap_counter = (bool)(uint16_t)(s.num >> 48); + } else { + if (s.num > 0xffff) { + r = -EINVAL; + break; + } + } vq->last_avail_idx = s.num; /* Forget the cached index value. */ vq->avail_idx = vq->last_avail_idx; @@ -1450,8 +1456,15 @@ long vhost_vring_ioctl(struct vhost_dev *d, int ioctl, void __user *argp) case VHOST_GET_VRING_BASE: s.index = idx; s.num = vq->last_avail_idx; + if (vhost_has_feature(vq, VIRTIO_F_RING_PACKED)) { + s.num |= vq->avail_wrap_counter << 16; + s.num |= vq->last_used_idx << 32; + s.num |= vq->used_wrap_counter << 48; + } if (copy_to_user(argp, &s, sizeof s)) r = -EFAULT; + if (vhost_has_feature(vq, VIRTIO_F_RING_PACKED)) + s.num |= vq->avail_wrap_counter << 31; break; case VHOST_SET_VRING_ADDR: if (copy_from_user(&a, argp, sizeof a)) {