qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
To: Alexey <a.perevalov@samsung.com>
Cc: i.maximets@samsung.com, qemu-devel@nongnu.org, peterx@redhat.com
Subject: Re: [Qemu-devel] [PATCH V5 4/9] migration: split ufd_version_check onto receive/request features part
Date: Fri, 19 May 2017 19:46:16 +0100	[thread overview]
Message-ID: <20170519184615.GV2081@work-vm> (raw)
In-Reply-To: <20170518065518.GA8752@aperevalov-ubuntu>

* Alexey (a.perevalov@samsung.com) wrote:
> On Tue, May 16, 2017 at 11:32:51AM +0100, Dr. David Alan Gilbert wrote:
> > * Alexey Perevalov (a.perevalov@samsung.com) wrote:
> > > This modification is necessary for userfault fd features which are
> > > required to be requested from userspace.
> > > UFFD_FEATURE_THREAD_ID is a one of such "on demand" feature, which will
> > > be introduced in the next patch.
> > > 
> > > QEMU need to use separate userfault file descriptor, due to
> > > userfault context has internal state, and after first call of
> > > ioctl UFFD_API it changes its state to UFFD_STATE_RUNNING (in case of
> > > success), but
> > > kernel while handling ioctl UFFD_API expects UFFD_STATE_WAIT_API. So
> > > only one ioctl with UFFD_API is possible per ufd.
> > > 
> > > Signed-off-by: Alexey Perevalov <a.perevalov@samsung.com>
> > > ---
> > >  migration/postcopy-ram.c | 82 ++++++++++++++++++++++++++++++++++++++++++------
> > >  1 file changed, 73 insertions(+), 9 deletions(-)
> > > 
> > > diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c
> > > index 0f75700..c96d5f5 100644
> > > --- a/migration/postcopy-ram.c
> > > +++ b/migration/postcopy-ram.c
> > > @@ -60,32 +60,96 @@ struct PostcopyDiscardState {
> > >  #include <sys/eventfd.h>
> > >  #include <linux/userfaultfd.h>
> > >  
> > > -static bool ufd_version_check(int ufd, MigrationIncomingState *mis)
> > > +
> > > +/*
> > > + * Check userfault fd features, to request only supported features in
> > > + * future.
> > > + * __NR_userfaultfd - should be checked before
> > > + * Return obtained features
> > 
> > That's not quite right;
> >  * Returns: True on success, sets *features to supported features
> >             False on failure or if kernel doesn't support ufd
> > 
> yes, obtained features is out parameter,
> but I want to keep false uncommented and just add error_report into
> syscall check, because the possible reason of failure is:
> 1. No syscall userfaultfd, but function expects that syscall, it reflects in
> comment
> 2  Within syscall:  exhausted fd or out of memory (file in kernel
> is allocating)
> 3. Problem in ioctl due to internal state of UFFD, as example
> UFFDIO_API after UFFDIO_REGISTER

I don't think we're allowed to depend on error pointers, but either
way we should comment it to make sure it's clear, so if you have a
boolean return at least say it's true for success and explain features
etc.

> Also I would prefer follow migration/ram.c comment style.

Yes, that's fine - it's the content of the comment I was more
worried about (and the one below).

Dave

> > > + */
> > > +static bool receive_ufd_features(uint64_t *features)
> > >  {
> > > -    struct uffdio_api api_struct;
> > > -    uint64_t ioctl_mask;
> > > +    struct uffdio_api api_struct = {0};
> > > +    int ufd;
> > > +    bool ret = true;
> > > +
> > > +    /* if we are here __NR_userfaultfd should exists */
> > > +    ufd = syscall(__NR_userfaultfd, O_CLOEXEC);
> > > +    if (ufd == -1) {
> > > +        return false;
> > > +    }
> > >  
> > > +    /* ask features */
> > >      api_struct.api = UFFD_API;
> > >      api_struct.features = 0;
> > >      if (ioctl(ufd, UFFDIO_API, &api_struct)) {
> > > -        error_report("%s: UFFDIO_API failed: %s", __func__
> > > +        error_report("%s: UFFDIO_API failed: %s", __func__,
> > >                       strerror(errno));
> > > +        ret = false;
> > > +        goto release_ufd;
> > > +    }
> > > +
> > > +    *features = api_struct.features;
> > > +
> > > +release_ufd:
> > > +    close(ufd);
> > > +    return ret;
> > > +}
> > 
> > Needs a comment; perhaps something like:
> >   * Called once on a newly opened ufd, can request specific features.
> >   * Returns: True on success
> > 
> > > +static bool request_ufd_features(int ufd, uint64_t features)
> > > +{
> > > +    struct uffdio_api api_struct = {0};
> > > +    uint64_t ioctl_mask;
> > > +
> > > +    api_struct.api = UFFD_API;
> > > +    api_struct.features = features;
> > > +    if (ioctl(ufd, UFFDIO_API, &api_struct)) {
> > > +        error_report("%s failed: UFFDIO_API failed: %s", __func__,
> > > +                strerror(errno));
> > >          return false;
> > >      }
> > >  
> > > -    ioctl_mask = (__u64)1 << _UFFDIO_REGISTER |
> > > -                 (__u64)1 << _UFFDIO_UNREGISTER;
> > > +    ioctl_mask = 1 << _UFFDIO_REGISTER |
> > > +                 1 << _UFFDIO_UNREGISTER;
> > >      if ((api_struct.ioctls & ioctl_mask) != ioctl_mask) {
> > >          error_report("Missing userfault features: %" PRIx64,
> > >                       (uint64_t)(~api_struct.ioctls & ioctl_mask));
> > >          return false;
> > >      }
> > >  
> > > +    return true;
> > > +}
> > > +
> > > +static bool ufd_check_and_apply(int ufd, MigrationIncomingState *mis)
> > > +{
> > > +    uint64_t asked_features = 0;
> > > +    uint64_t supported_features;
> > > +
> > > +    /*
> > > +     * it's not possible to
> > > +     * request UFFD_API twice per one fd
> > > +     */
> > > +    if (!receive_ufd_features(&supported_features)) {
> > > +        error_report("%s failed", __func__);
> > > +        return false;
> > > +    }
> > > +
> > > +    /*
> > > +     * request features, even if asked_features is 0, due to
> > > +     * kernel expects UFFD_API before UFFDIO_REGISTER, per
> > > +     * userfault file descriptor
> > > +     */
> > > +    if (!request_ufd_features(ufd, asked_features)) {
> > > +        error_report("%s failed: features %" PRIu64, __func__,
> > > +                asked_features);
> > > +        return false;
> > > +    }
> > > +
> > >      if (getpagesize() != ram_pagesize_summary()) {
> > >          bool have_hp = false;
> > >          /* We've got a huge page */
> > >  #ifdef UFFD_FEATURE_MISSING_HUGETLBFS
> > > -        have_hp = api_struct.features & UFFD_FEATURE_MISSING_HUGETLBFS;
> > > +        have_hp = supported_features & UFFD_FEATURE_MISSING_HUGETLBFS;
> > >  #endif
> > >          if (!have_hp) {
> > >              error_report("Userfault on this host does not support huge pages");
> > > @@ -136,7 +200,7 @@ bool postcopy_ram_supported_by_host(MigrationIncomingState *mis)
> > >      }
> > >  
> > >      /* Version and features check */
> > > -    if (!ufd_version_check(ufd, mis)) {
> > > +    if (!ufd_check_and_apply(ufd, mis)) {
> > >          goto out;
> > >      }
> > >  
> > > @@ -513,7 +577,7 @@ int postcopy_ram_enable_notify(MigrationIncomingState *mis)
> > >       * Although the host check already tested the API, we need to
> > >       * do the check again as an ABI handshake on the new fd.
> > >       */
> > > -    if (!ufd_version_check(mis->userfault_fd, mis)) {
> > > +    if (!ufd_check_and_apply(mis->userfault_fd, mis)) {
> > >          return -1;
> > >      }
> > >  
> > > -- 
> > > 1.9.1
> > 
> > Dave
> > 
> > --
> > Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK
> > 
> 
> -- 
> 
> BR
> Alexey
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK

  reply	other threads:[~2017-05-19 18:46 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20170512133144eucas1p23502fd953ee73bda5b2afb25e65604f9@eucas1p2.samsung.com>
2017-05-12 13:31 ` [Qemu-devel] [PATCH V5 0/9] calculate blocktime for postcopy live migration Alexey Perevalov
     [not found]   ` <CGME20170512133144eucas1p288cde3bd6faefb16cbb0d3790885783d@eucas1p2.samsung.com>
2017-05-12 13:31     ` [Qemu-devel] [PATCH V5 1/9] userfault: add pid into uffd_msg & update UFFD_FEATURE_* Alexey Perevalov
     [not found]   ` <CGME20170512133144eucas1p25b4275feb4126a21415242c5085382fd@eucas1p2.samsung.com>
2017-05-12 13:31     ` [Qemu-devel] [PATCH V5 2/9] migration: pass ptr to MigrationIncomingState into migration ufd_version_check & postcopy_ram_supported_by_host Alexey Perevalov
2017-05-18 14:09       ` Eric Blake
     [not found]   ` <CGME20170512133145eucas1p2cad4c4efe46e6f1b757d97dd9d301dbe@eucas1p2.samsung.com>
2017-05-12 13:31     ` [Qemu-devel] [PATCH V5 3/9] migration: fix hardcoded function name in error report Alexey Perevalov
2017-05-16  9:46       ` Dr. David Alan Gilbert
     [not found]   ` <CGME20170512133146eucas1p17df48bb6b5fcefe3717e18cd9afd84b7@eucas1p1.samsung.com>
2017-05-12 13:31     ` [Qemu-devel] [PATCH V5 4/9] migration: split ufd_version_check onto receive/request features part Alexey Perevalov
2017-05-16 10:32       ` Dr. David Alan Gilbert
2017-05-18  6:55         ` Alexey
2017-05-19 18:46           ` Dr. David Alan Gilbert [this message]
     [not found]   ` <CGME20170512133146eucas1p2ba4841cabf508b66410fae6784952eaa@eucas1p2.samsung.com>
2017-05-12 13:31     ` [Qemu-devel] [PATCH V5 5/9] migration: introduce postcopy-blocktime capability Alexey Perevalov
2017-05-16 10:33       ` Dr. David Alan Gilbert
2017-05-22 16:20       ` Eric Blake
2017-05-22 16:42         ` Alexey
2017-05-30 11:26         ` Dr. David Alan Gilbert
     [not found]   ` <CGME20170512133147eucas1p1aca0281fc864bf6f3beb610e7ce2695b@eucas1p1.samsung.com>
2017-05-12 13:31     ` [Qemu-devel] [PATCH V5 6/9] migration: add postcopy vcpu blocktime context into MigrationIncomingState Alexey Perevalov
     [not found]   ` <CGME20170512133147eucas1p1eaa21aac3a0b9d45be0ef8ea903b6824@eucas1p1.samsung.com>
2017-05-12 13:31     ` [Qemu-devel] [PATCH V5 7/9] migration: calculate vCPU blocktime on dst side Alexey Perevalov
2017-05-16 11:34       ` Dr. David Alan Gilbert
2017-05-16 15:19         ` Alexey
2017-05-18  7:18         ` Alexey
2017-05-19 19:05           ` Dr. David Alan Gilbert
2017-05-22  7:43             ` Alexey Perevalov
     [not found]   ` <CGME20170512133148eucas1p2c04111d415b1fbd6fb702cfc2a3ed6f9@eucas1p2.samsung.com>
2017-05-12 13:31     ` [Qemu-devel] [PATCH V5 8/9] migration: add postcopy total blocktime into query-migrate Alexey Perevalov
2017-05-19 19:23       ` Dr. David Alan Gilbert
2017-05-22 16:15         ` Eric Blake
2017-05-22 16:14       ` Eric Blake
     [not found]   ` <CGME20170512133149eucas1p2b4c448fe763975cf11cf96801857d42e@eucas1p2.samsung.com>
2017-05-12 13:31     ` [Qemu-devel] [PATCH V5 9/9] migration: postcopy_blocktime documentation Alexey Perevalov
2017-05-12 20:09   ` [Qemu-devel] [PATCH V5 0/9] calculate blocktime for postcopy live migration Eric Blake

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170519184615.GV2081@work-vm \
    --to=dgilbert@redhat.com \
    --cc=a.perevalov@samsung.com \
    --cc=i.maximets@samsung.com \
    --cc=peterx@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).