[06/12] vhost: register new regions with userfaultfd

Message ID 20180926072705.22641-7-maxime.coquelin@redhat.com (mailing list archive)
State Superseded, archived
Delegated to: Maxime Coquelin
Headers
Series vhost: add postcopy live-migration support |

Checks

Context Check Description
ci/Intel-compilation success Compilation OK

Commit Message

Maxime Coquelin Sept. 26, 2018, 7:26 a.m. UTC
  Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
---
 lib/librte_vhost/vhost_user.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)
  

Comments

Alejandro Lucero Sept. 26, 2018, 3:31 p.m. UTC | #1
On Wed, Sep 26, 2018 at 8:28 AM Maxime Coquelin <maxime.coquelin@redhat.com>
wrote:

> Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
> Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
> ---
>  lib/librte_vhost/vhost_user.c | 22 ++++++++++++++++++++++
>  1 file changed, 22 insertions(+)
>
> diff --git a/lib/librte_vhost/vhost_user.c b/lib/librte_vhost/vhost_user.c
> index d9ef5bca8..cbbfbdf00 100644
> --- a/lib/librte_vhost/vhost_user.c
> +++ b/lib/librte_vhost/vhost_user.c
> @@ -928,6 +928,28 @@ vhost_user_set_mem_table(struct virtio_net **pdev,
> struct VhostUserMsg *pmsg)
>                         mmap_size,
>                         alignment,
>                         mmap_offset);
> +
> +               if (dev->postcopy_listening) {
> +                       struct uffdio_register reg_struct;
> +
> +                       reg_struct.range.start =
> (uint64_t)(uintptr_t)mmap_addr;
> +                       reg_struct.range.len = mmap_size;
> +                       reg_struct.mode = UFFDIO_REGISTER_MODE_MISSING;
> +
> +                       if (ioctl(dev->postcopy_ufd, UFFDIO_REGISTER,
> +                                               &reg_struct)) {
> +                               RTE_LOG(ERR, VHOST_CONFIG,
> +                                               "Failed to register ufd
> for region %d: (ufd = %d) %s\n",
> +                                               i, dev->postcopy_ufd,
> +                                               strerror(errno));
> +                               continue;
>

is it not a registration error a serious problem for supporting migration
properly?


> +                       }
> +                       RTE_LOG(INFO, VHOST_CONFIG,
> +                                       "\t userfaultfd registered for
> range : %llx - %llx\n",
> +                                       reg_struct.range.start,
> +                                       reg_struct.range.start +
> +                                       reg_struct.range.len - 1);
> +               }
>         }
>
>         for (i = 0; i < dev->nr_vring; i++) {
> --
> 2.17.1
>
>
  
Maxime Coquelin Sept. 27, 2018, 9:37 a.m. UTC | #2
On 09/26/2018 05:31 PM, Alejandro Lucero wrote:
> 
> 
> On Wed, Sep 26, 2018 at 8:28 AM Maxime Coquelin 
> <maxime.coquelin@redhat.com <mailto:maxime.coquelin@redhat.com>> wrote:
> 
>     Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com
>     <mailto:dgilbert@redhat.com>>
>     Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com
>     <mailto:maxime.coquelin@redhat.com>>
>     ---
>       lib/librte_vhost/vhost_user.c | 22 ++++++++++++++++++++++
>       1 file changed, 22 insertions(+)
> 
>     diff --git a/lib/librte_vhost/vhost_user.c
>     b/lib/librte_vhost/vhost_user.c
>     index d9ef5bca8..cbbfbdf00 100644
>     --- a/lib/librte_vhost/vhost_user.c
>     +++ b/lib/librte_vhost/vhost_user.c
>     @@ -928,6 +928,28 @@ vhost_user_set_mem_table(struct virtio_net
>     **pdev, struct VhostUserMsg *pmsg)
>                              mmap_size,
>                              alignment,
>                              mmap_offset);
>     +
>     +               if (dev->postcopy_listening) {
>     +                       struct uffdio_register reg_struct;
>     +
>     +                       reg_struct.range.start =
>     (uint64_t)(uintptr_t)mmap_addr;
>     +                       reg_struct.range.len = mmap_size;
>     +                       reg_struct.mode = UFFDIO_REGISTER_MODE_MISSING;
>     +
>     +                       if (ioctl(dev->postcopy_ufd, UFFDIO_REGISTER,
>     +                                               &reg_struct)) {
>     +                               RTE_LOG(ERR, VHOST_CONFIG,
>     +                                               "Failed to register
>     ufd for region %d: (ufd = %d) %s\n",
>     +                                               i, dev->postcopy_ufd,
>     +                                               strerror(errno));
>     +                               continue;
> 
> 
> is it not a registration error a serious problem for supporting 
> migration properly?

Yes it is, I missed to fix that.

Thanks for reporting it.
Maxime

>     +                       }
>     +                       RTE_LOG(INFO, VHOST_CONFIG,
>     +                                       "\t userfaultfd registered
>     for range : %llx - %llx\n",
>     +                                       reg_struct.range.start,
>     +                                       reg_struct.range.start +
>     +                                       reg_struct.range.len - 1);
>     +               }
>              }
> 
>              for (i = 0; i < dev->nr_vring; i++) {
>     -- 
>     2.17.1
>
  

Patch

diff --git a/lib/librte_vhost/vhost_user.c b/lib/librte_vhost/vhost_user.c
index d9ef5bca8..cbbfbdf00 100644
--- a/lib/librte_vhost/vhost_user.c
+++ b/lib/librte_vhost/vhost_user.c
@@ -928,6 +928,28 @@  vhost_user_set_mem_table(struct virtio_net **pdev, struct VhostUserMsg *pmsg)
 			mmap_size,
 			alignment,
 			mmap_offset);
+
+		if (dev->postcopy_listening) {
+			struct uffdio_register reg_struct;
+
+			reg_struct.range.start = (uint64_t)(uintptr_t)mmap_addr;
+			reg_struct.range.len = mmap_size;
+			reg_struct.mode = UFFDIO_REGISTER_MODE_MISSING;
+
+			if (ioctl(dev->postcopy_ufd, UFFDIO_REGISTER,
+						&reg_struct)) {
+				RTE_LOG(ERR, VHOST_CONFIG,
+						"Failed to register ufd for region %d: (ufd = %d) %s\n",
+						i, dev->postcopy_ufd,
+						strerror(errno));
+				continue;
+			}
+			RTE_LOG(INFO, VHOST_CONFIG,
+					"\t userfaultfd registered for range : %llx - %llx\n",
+					reg_struct.range.start,
+					reg_struct.range.start +
+					reg_struct.range.len - 1);
+		}
 	}
 
 	for (i = 0; i < dev->nr_vring; i++) {