From patchwork Thu Oct 1 17:23:54 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Patchwork-Id: 525230 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 679EE140D77 for ; Fri, 2 Oct 2015 04:20:18 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=yn9WJVM5; dkim-atps=neutral Received: from localhost ([::1]:55017 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZhiSm-0002uw-7n for incoming@patchwork.ozlabs.org; Thu, 01 Oct 2015 14:20:16 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38557) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zhhb2-0008Er-8M for qemu-devel@nongnu.org; Thu, 01 Oct 2015 13:24:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Zhhb1-0000Eu-7w for qemu-devel@nongnu.org; Thu, 01 Oct 2015 13:24:44 -0400 Received: from mail-qg0-x234.google.com ([2607:f8b0:400d:c04::234]:33375) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zhhb1-0000EW-3Z for qemu-devel@nongnu.org; Thu, 01 Oct 2015 13:24:43 -0400 Received: by qgev79 with SMTP id v79so73257676qge.0 for ; Thu, 01 Oct 2015 10:24:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type:content-transfer-encoding; bh=dQqw01eHLaA0nSomM0N+xmcmQwGVGC113aZGR92VCOc=; b=yn9WJVM5fB18rUmci5APkFFWyMk+by+oabR2VIxrEqQHv8PP/68o92f7BoIWy9rO19 CVJVbKUliOnfFX6teaQEOk2SCi7VASe7jgzUWthhyGDYbO4VN/Plv/+Nyh/INjvvnCw1 eN50k62SuZU0viJvaO1Jo8fsOLqQfpCjcWa3WImiU3uDHaSxmK03upmxPteYr6vQxz5a /f27vS94HIeKS6CUIkGCaCXqmQHMAVGsz3L7ObHL2R52ZA3lhRWT6vr6xTsXIsEm44mO iFAit/UnAEhG86eOGw2iBhNQrxcdIFUuH2c0IZmYAy8PJ8hFsm1bdmAAOgEOx5ae558W FKew== X-Received: by 10.140.20.168 with SMTP id 37mr13739031qgj.16.1443720282784; Thu, 01 Oct 2015 10:24:42 -0700 (PDT) Received: from localhost (bne75-h02-31-39-163-232.dsl.sta.abo.bbox.fr. [31.39.163.232]) by smtp.gmail.com with ESMTPSA id 200sm2785088qhh.26.2015.10.01.10.24.41 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Oct 2015 10:24:41 -0700 (PDT) From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Date: Thu, 1 Oct 2015 19:23:54 +0200 Message-Id: <1443720248-15482-11-git-send-email-marcandre.lureau@redhat.com> X-Mailer: git-send-email 2.4.3 In-Reply-To: <1443720248-15482-1-git-send-email-marcandre.lureau@redhat.com> References: <1443720248-15482-1-git-send-email-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:400d:c04::234 Cc: haifeng.lin@huawei.com, mst@redhat.com, thibaut.collet@6wind.com, jasowang@redhat.com, pbonzini@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Subject: [Qemu-devel] [PATCH v7 10/24] vhost-user: send log shm fd along with log_base X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Marc-André Lureau Send the shm for the dirty pages logging if the backend supports VHOST_USER_PROTOCOL_F_LOG_SHMFD. Wait for a reply to make sure the old log is no longer used. Signed-off-by: Marc-André Lureau --- hw/virtio/vhost-backend.c | 3 ++- hw/virtio/vhost-user.c | 27 +++++++++++++++++++++++++-- hw/virtio/vhost.c | 5 +++-- include/hw/virtio/vhost-backend.h | 4 +++- 4 files changed, 33 insertions(+), 6 deletions(-) diff --git a/hw/virtio/vhost-backend.c b/hw/virtio/vhost-backend.c index 88d33fd..87ab028 100644 --- a/hw/virtio/vhost-backend.c +++ b/hw/virtio/vhost-backend.c @@ -50,7 +50,8 @@ static int vhost_kernel_get_vq_index(struct vhost_dev *dev, int idx) return idx - dev->vq_index; } -static int vhost_set_log_base(struct vhost_dev *dev, uint64_t base) +static int vhost_set_log_base(struct vhost_dev *dev, uint64_t base, + struct vhost_log *log) { return vhost_kernel_call(dev, VHOST_SET_LOG_BASE, &base); } diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c index 01e51a0..cf14e38 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -367,8 +367,13 @@ static int vhost_user_call(struct vhost_dev *dev, unsigned long int request, return 0; } -static int vhost_set_log_base(struct vhost_dev *dev, uint64_t base) +static int vhost_set_log_base(struct vhost_dev *dev, uint64_t base, + struct vhost_log *log) { + int fds[VHOST_MEMORY_MAX_NREGIONS]; + size_t fd_num = 0; + bool shmfd = virtio_has_feature(dev->protocol_features, + VHOST_USER_PROTOCOL_F_LOG_SHMFD); VhostUserMsg msg = { .request = VHOST_USER_SET_LOG_BASE, .flags = VHOST_USER_VERSION, @@ -376,7 +381,25 @@ static int vhost_set_log_base(struct vhost_dev *dev, uint64_t base) .size = sizeof(m.u64), }; - vhost_user_write(dev, &msg, NULL, 0); + if (shmfd && log->fd != -1) { + fds[fd_num++] = log->fd; + } + + vhost_user_write(dev, &msg, fds, fd_num); + + if (shmfd) { + msg.size = 0; + if (vhost_user_read(dev, &msg) < 0) { + return 0; + } + + if (msg.request != VHOST_USER_SET_LOG_BASE) { + error_report("Received unexpected msg type. " + "Expected %d received %d", + VHOST_USER_SET_LOG_BASE, msg.request); + return -1; + } + } return 0; } diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index 63fa2bf..d1c0367 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -372,7 +372,7 @@ static inline void vhost_dev_log_resize(struct vhost_dev *dev, uint64_t size) /* inform backend of log switching, this must be done before releasing the current log, to ensure no logging is lost */ - r = dev->vhost_ops->vhost_set_log_base(dev, log_base); + r = dev->vhost_ops->vhost_set_log_base(dev, log_base, log); assert(r >= 0); vhost_log_put(dev, true); dev->log = log; @@ -1178,7 +1178,8 @@ int vhost_dev_start(struct vhost_dev *hdev, VirtIODevice *vdev) vhost_dev_log_is_shared(hdev)); log_base = (uintptr_t)hdev->log->log; r = hdev->vhost_ops->vhost_set_log_base(hdev, - hdev->log_size ? log_base : 0); + hdev->log_size ? log_base : 0, + hdev->log); if (r < 0) { r = -errno; goto fail_log; diff --git a/include/hw/virtio/vhost-backend.h b/include/hw/virtio/vhost-backend.h index 649766a..7064a12 100644 --- a/include/hw/virtio/vhost-backend.h +++ b/include/hw/virtio/vhost-backend.h @@ -21,6 +21,7 @@ typedef enum VhostBackendType { } VhostBackendType; struct vhost_dev; +struct vhost_log; typedef int (*vhost_call)(struct vhost_dev *dev, unsigned long int request, void *arg); @@ -29,7 +30,8 @@ typedef int (*vhost_backend_cleanup)(struct vhost_dev *dev); typedef int (*vhost_backend_get_vq_index)(struct vhost_dev *dev, int idx); typedef int (*vhost_backend_set_vring_enable)(struct vhost_dev *dev, int enable); -typedef int (*vhost_set_log_base_op)(struct vhost_dev *dev, uint64_t base); +typedef int (*vhost_set_log_base_op)(struct vhost_dev *dev, uint64_t base, + struct vhost_log *log); typedef bool (*vhost_requires_shm_log_op)(struct vhost_dev *dev); typedef struct VhostOps {