From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 73E6FA04F3 for ; Thu, 19 Dec 2019 15:36:12 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 6AAAD1BF76; Thu, 19 Dec 2019 15:36:12 +0100 (CET) Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) by dpdk.org (Postfix) with ESMTP id 055401BF72 for ; Thu, 19 Dec 2019 15:36:11 +0100 (CET) Received: by mail-wm1-f42.google.com with SMTP id p9so5670171wmc.2 for ; Thu, 19 Dec 2019 06:36:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=p8oczU7DoMgozlEKpXLDhkurKtX20QZHChL57fbUSWc=; b=kpY7i8gFlgZQ1JjNLhC3Vk/PmvXr3crVRwDSvI/7u34/OxRg+BhiHY5RN6TAaRcUCK sZRcRF8JYVZQrbaTX80igz3tJ9bi0uyD6lzNKT+FeGIFe6c1doucuIMX84aRQuEay0l1 rEyR6hIVjqJivuoQupDNWgOQ6CG6JHiuvOzN26EeZgcCszZxbREdRvRYyTXlCf+6gK8c O6NVEmlohhTW65TcMbvSjlvf+pS/0Gpp/FQOGw4DQFONMx/dqxLCEuyJYD/TA/5Ga1nB ZdlSV6esAjHKC/FBh/+BxD2/0dEak6ESHtuzRk90OsnfqWRlVNYlhZtLuhCyNAyva7A5 0c2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=p8oczU7DoMgozlEKpXLDhkurKtX20QZHChL57fbUSWc=; b=CAdQA/mYskqGu/WTsvi0J1RBE6ToqB2NCNS7UU5qks8n6qzOMJaaP341sSNjmbHYi3 R6WaN5UwO3RmuF3FPbnweOjvCah2/PJ+jdbvygYK591FmuxhI4l5sp0aa6gMauYsERrf H5pxcZ6gUD+TZRjg/uHdWOCc2CHjrGWnDa4FS/P1hOBpPR9uH3eA9y2e26q5XAXT5adB CFoyhjkhVQRmXW3II4bB46cgsxtPAfR/UQxqLGZ/WU83jhWLnicbbph0O4CVvEMRE9EV U2Ipy/wk1DNR6CA8W7OoTYngDIdq+YgBCHIHQbF1RnNByohCyQqfeIKMS/yUBgIuCSEJ N7AA== X-Gm-Message-State: APjAAAWtCdUoQLO28HzhSOOSLhA/NfsYtmrgd4cgDPaK6d0zd7NI3muC PPNDQt8KBjL45ljCbSGamqE= X-Google-Smtp-Source: APXvYqy8vNpasZS+/JV/o8yuEe1KIIBz7vDbSnrbtFScidRv43zXV7j6LRvSJfcS0WdWbfwUpge2mQ== X-Received: by 2002:a05:600c:21ce:: with SMTP id x14mr9859141wmj.120.1576766170677; Thu, 19 Dec 2019 06:36:10 -0800 (PST) Received: from localhost ([88.98.246.218]) by smtp.gmail.com with ESMTPSA id u13sm6332545wmd.36.2019.12.19.06.36.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Dec 2019 06:36:10 -0800 (PST) From: luca.boccassi@gmail.com To: Tiwei Bie Cc: Yilong Lv , Maxime Coquelin , dpdk stable Date: Thu, 19 Dec 2019 14:32:58 +0000 Message-Id: <20191219143447.21506-31-luca.boccassi@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191219143447.21506-1-luca.boccassi@gmail.com> References: <20191219143447.21506-1-luca.boccassi@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-stable] patch 'vhost: fix vring address handling during live migration' has been queued to LTS release 17.11.10 X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org Sender: "stable" Hi, FYI, your patch has been queued to LTS release 17.11.10 Note it hasn't been pushed to http://dpdk.org/browse/dpdk-stable yet. It will be pushed if I get no objections before 12/21/19. So please shout if anyone has objections. Also note that after the patch there's a diff of the upstream commit vs the patch applied to the branch. This will indicate if there was any rebasing needed to apply to the stable branch. If there were code changes for rebasing (ie: not only metadata diffs), please double check that the rebase was correctly done. Thanks. Luca Boccassi --- >From ba71d193b21c16eea49649a2c6a71ad133e7dfa9 Mon Sep 17 00:00:00 2001 From: Tiwei Bie Date: Mon, 19 Aug 2019 19:34:56 +0800 Subject: [PATCH] vhost: fix vring address handling during live migration [ upstream commit 72d002b3ebda4686306cc5124b7a8bdf627dba0a ] When live migration starts, QEMU will set ring addrs again for each virtqueue. In this case, we should try to translate ring addrs after we invalidating the ring, otherwise virtqueues can be enabled with the addrs untranslated. Besides, also leverage the access_ok flag in non-IOMMU case to prevent the data path accessing invalidated virtqueues. Fixes: 5a4933e56be4 ("vhost: postpone ring address translations at kick time only") Reported-by: Yilong Lv Signed-off-by: Tiwei Bie Reviewed-by: Maxime Coquelin --- lib/librte_vhost/vhost.c | 3 +-- lib/librte_vhost/vhost_user.c | 11 +++++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/librte_vhost/vhost.c b/lib/librte_vhost/vhost.c index a8ed40b1f6..78fedc6a47 100644 --- a/lib/librte_vhost/vhost.c +++ b/lib/librte_vhost/vhost.c @@ -161,7 +161,7 @@ vring_translate(struct virtio_net *dev, struct vhost_virtqueue *vq) uint64_t req_size, size; if (!(dev->features & (1ULL << VIRTIO_F_IOMMU_PLATFORM))) - goto out; + return -1; req_size = sizeof(struct vring_desc) * vq->size; size = req_size; @@ -193,7 +193,6 @@ vring_translate(struct virtio_net *dev, struct vhost_virtqueue *vq) if (!vq->used || size != req_size) return -1; -out: vq->access_ok = 1; return 0; diff --git a/lib/librte_vhost/vhost_user.c b/lib/librte_vhost/vhost_user.c index 2440f14846..635b6f3ddd 100644 --- a/lib/librte_vhost/vhost_user.c +++ b/lib/librte_vhost/vhost_user.c @@ -521,6 +521,7 @@ translate_ring_addresses(struct virtio_net *dev, int vq_index) } vq->log_guest_addr = addr->log_guest_addr; + vq->access_ok = 1; LOG_DEBUG(VHOST_CONFIG, "(%d) mapped address desc: %p\n", dev->vid, vq->desc); @@ -544,6 +545,7 @@ vhost_user_set_vring_addr(struct virtio_net **pdev, VhostUserMsg *msg) struct vhost_virtqueue *vq; struct vhost_vring_addr *addr = &msg->payload.addr; struct virtio_net *dev = *pdev; + bool access_ok; if (dev->mem == NULL) return -1; @@ -551,6 +553,8 @@ vhost_user_set_vring_addr(struct virtio_net **pdev, VhostUserMsg *msg) /* addr->index refers to the queue index. The txq 1, rxq is 0. */ vq = dev->virtqueue[msg->payload.addr.index]; + access_ok = vq->access_ok; + /* * Rings addresses should not be interpreted as long as the ring is not * started and enabled @@ -559,8 +563,9 @@ vhost_user_set_vring_addr(struct virtio_net **pdev, VhostUserMsg *msg) vring_invalidate(dev, vq); - if (vq->enabled && (dev->features & - (1ULL << VHOST_USER_F_PROTOCOL_FEATURES))) { + if ((vq->enabled && (dev->features & + (1ULL << VHOST_USER_F_PROTOCOL_FEATURES))) || + access_ok) { dev = translate_ring_addresses(dev, msg->payload.addr.index); if (!dev) return -1; @@ -1014,6 +1019,8 @@ vhost_user_get_vring_base(struct virtio_net *dev, rte_free(vq->batch_copy_elems); vq->batch_copy_elems = NULL; + vring_invalidate(dev, vq); + return 0; } -- 2.20.1 --- Diff of the applied patch vs upstream commit (please double-check if non-empty: --- --- - 2019-12-19 14:32:27.589466638 +0000 +++ 0031-vhost-fix-vring-address-handling-during-live-migrati.patch 2019-12-19 14:32:25.773291242 +0000 @@ -1,8 +1,10 @@ -From 72d002b3ebda4686306cc5124b7a8bdf627dba0a Mon Sep 17 00:00:00 2001 +From ba71d193b21c16eea49649a2c6a71ad133e7dfa9 Mon Sep 17 00:00:00 2001 From: Tiwei Bie Date: Mon, 19 Aug 2019 19:34:56 +0800 Subject: [PATCH] vhost: fix vring address handling during live migration +[ upstream commit 72d002b3ebda4686306cc5124b7a8bdf627dba0a ] + When live migration starts, QEMU will set ring addrs again for each virtqueue. In this case, we should try to translate ring addrs after we invalidating the ring, otherwise virtqueues can @@ -11,66 +13,57 @@ accessing invalidated virtqueues. Fixes: 5a4933e56be4 ("vhost: postpone ring address translations at kick time only") -Cc: stable@dpdk.org Reported-by: Yilong Lv Signed-off-by: Tiwei Bie Reviewed-by: Maxime Coquelin --- lib/librte_vhost/vhost.c | 3 +-- - lib/librte_vhost/vhost_user.c | 12 ++++++++++-- - 2 files changed, 11 insertions(+), 4 deletions(-) + lib/librte_vhost/vhost_user.c | 11 +++++++++-- + 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/librte_vhost/vhost.c b/lib/librte_vhost/vhost.c -index 981837b5dd..77be160697 100644 +index a8ed40b1f6..78fedc6a47 100644 --- a/lib/librte_vhost/vhost.c +++ b/lib/librte_vhost/vhost.c -@@ -358,7 +358,7 @@ vring_translate(struct virtio_net *dev, struct vhost_virtqueue *vq) - { +@@ -161,7 +161,7 @@ vring_translate(struct virtio_net *dev, struct vhost_virtqueue *vq) + uint64_t req_size, size; if (!(dev->features & (1ULL << VIRTIO_F_IOMMU_PLATFORM))) - goto out; + return -1; - if (vq_is_packed(dev)) { - if (vring_translate_packed(dev, vq) < 0) -@@ -367,7 +367,6 @@ vring_translate(struct virtio_net *dev, struct vhost_virtqueue *vq) - if (vring_translate_split(dev, vq) < 0) - return -1; - } + req_size = sizeof(struct vring_desc) * vq->size; + size = req_size; +@@ -193,7 +193,6 @@ vring_translate(struct virtio_net *dev, struct vhost_virtqueue *vq) + if (!vq->used || size != req_size) + return -1; + -out: vq->access_ok = 1; return 0; diff --git a/lib/librte_vhost/vhost_user.c b/lib/librte_vhost/vhost_user.c -index e4ae027a05..3d2db6edff 100644 +index 2440f14846..635b6f3ddd 100644 --- a/lib/librte_vhost/vhost_user.c +++ b/lib/librte_vhost/vhost_user.c -@@ -622,6 +622,7 @@ translate_ring_addresses(struct virtio_net *dev, int vq_index) - return dev; - } - -+ vq->access_ok = 1; - return dev; - } - -@@ -680,6 +681,7 @@ translate_ring_addresses(struct virtio_net *dev, int vq_index) +@@ -521,6 +521,7 @@ translate_ring_addresses(struct virtio_net *dev, int vq_index) } vq->log_guest_addr = addr->log_guest_addr; + vq->access_ok = 1; - VHOST_LOG_DEBUG(VHOST_CONFIG, "(%d) mapped address desc: %p\n", + LOG_DEBUG(VHOST_CONFIG, "(%d) mapped address desc: %p\n", dev->vid, vq->desc); -@@ -704,6 +706,7 @@ vhost_user_set_vring_addr(struct virtio_net **pdev, struct VhostUserMsg *msg, - struct virtio_net *dev = *pdev; +@@ -544,6 +545,7 @@ vhost_user_set_vring_addr(struct virtio_net **pdev, VhostUserMsg *msg) struct vhost_virtqueue *vq; struct vhost_vring_addr *addr = &msg->payload.addr; + struct virtio_net *dev = *pdev; + bool access_ok; if (dev->mem == NULL) - return RTE_VHOST_MSG_RESULT_ERR; -@@ -711,6 +714,8 @@ vhost_user_set_vring_addr(struct virtio_net **pdev, struct VhostUserMsg *msg, + return -1; +@@ -551,6 +553,8 @@ vhost_user_set_vring_addr(struct virtio_net **pdev, VhostUserMsg *msg) /* addr->index refers to the queue index. The txq 1, rxq is 0. */ vq = dev->virtqueue[msg->payload.addr.index]; @@ -79,7 +72,7 @@ /* * Rings addresses should not be interpreted as long as the ring is not * started and enabled -@@ -719,8 +724,9 @@ vhost_user_set_vring_addr(struct virtio_net **pdev, struct VhostUserMsg *msg, +@@ -559,8 +563,9 @@ vhost_user_set_vring_addr(struct virtio_net **pdev, VhostUserMsg *msg) vring_invalidate(dev, vq); @@ -90,14 +83,14 @@ + access_ok) { dev = translate_ring_addresses(dev, msg->payload.addr.index); if (!dev) - return RTE_VHOST_MSG_RESULT_ERR; -@@ -1325,6 +1331,8 @@ vhost_user_get_vring_base(struct virtio_net **pdev, - msg->size = sizeof(msg->payload.state); - msg->fd_num = 0; + return -1; +@@ -1014,6 +1019,8 @@ vhost_user_get_vring_base(struct virtio_net *dev, + rte_free(vq->batch_copy_elems); + vq->batch_copy_elems = NULL; + vring_invalidate(dev, vq); + - return RTE_VHOST_MSG_RESULT_REPLY; + return 0; } --