kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Cornelia Huck <cornelia.huck@de.ibm.com>
To: Jason Wang <jasowang@redhat.com>
Cc: gleb@kernel.org, pbonzini@redhat.com, kvm@vger.kernel.org,
	linux-kernel@vger.kernel.org, mst@redhat.com
Subject: Re: [PATCH V4 1/4] kvm: factor out core eventfd assign/deassign logic
Date: Fri, 11 Sep 2015 09:39:28 +0200	[thread overview]
Message-ID: <20150911093928.5cb7173c.cornelia.huck@de.ibm.com> (raw)
In-Reply-To: <1441941457-23630-2-git-send-email-jasowang@redhat.com>

On Fri, 11 Sep 2015 11:17:34 +0800
Jason Wang <jasowang@redhat.com> wrote:

> This patch factors out core eventfd assign/deassign logic and leave
> the argument checking and bus index selection to callers.
> 
> Cc: Gleb Natapov <gleb@kernel.org>
> Cc: Paolo Bonzini <pbonzini@redhat.com>
> Signed-off-by: Jason Wang <jasowang@redhat.com>
> ---
>  virt/kvm/eventfd.c | 83 ++++++++++++++++++++++++++++++++----------------------
>  1 file changed, 49 insertions(+), 34 deletions(-)
> 
> diff --git a/virt/kvm/eventfd.c b/virt/kvm/eventfd.c
> index 9ff4193..163258d 100644
> --- a/virt/kvm/eventfd.c
> +++ b/virt/kvm/eventfd.c
> @@ -771,40 +771,14 @@ static enum kvm_bus ioeventfd_bus_from_flags(__u32 flags)
>  	return KVM_MMIO_BUS;
>  }
> 
> -static int
> -kvm_assign_ioeventfd(struct kvm *kvm, struct kvm_ioeventfd *args)
> +static int kvm_assign_ioeventfd_idx(struct kvm *kvm,
> +				enum kvm_bus bus_idx,
> +				struct kvm_ioeventfd *args)
>  {
> -	enum kvm_bus              bus_idx;
> -	struct _ioeventfd        *p;
> -	struct eventfd_ctx       *eventfd;
> -	int                       ret;
> -
> -	bus_idx = ioeventfd_bus_from_flags(args->flags);
> -	/* must be natural-word sized, or 0 to ignore length */
> -	switch (args->len) {
> -	case 0:
> -	case 1:
> -	case 2:
> -	case 4:
> -	case 8:
> -		break;
> -	default:
> -		return -EINVAL;
> -	}
> 
> -	/* check for range overflow */
> -	if (args->addr + args->len < args->addr)
> -		return -EINVAL;
> -
> -	/* check for extra flags that we don't understand */
> -	if (args->flags & ~KVM_IOEVENTFD_VALID_FLAG_MASK)
> -		return -EINVAL;
> -
> -	/* ioeventfd with no length can't be combined with DATAMATCH */
> -	if (!args->len &&
> -	    args->flags & (KVM_IOEVENTFD_FLAG_PIO |
> -			   KVM_IOEVENTFD_FLAG_DATAMATCH))
> -		return -EINVAL;
> +	struct eventfd_ctx *eventfd;
> +	struct _ioeventfd *p;
> +	int ret;
> 
>  	eventfd = eventfd_ctx_fdget(args->fd);
>  	if (IS_ERR(eventfd))
> @@ -873,14 +847,48 @@ fail:
>  }
> 
>  static int
> -kvm_deassign_ioeventfd(struct kvm *kvm, struct kvm_ioeventfd *args)
> +kvm_assign_ioeventfd(struct kvm *kvm, struct kvm_ioeventfd *args)

You'll move this function to below the deassign function in patch 2.
Maybe do it already here?

>  {
>  	enum kvm_bus              bus_idx;
> +
> +	bus_idx = ioeventfd_bus_from_flags(args->flags);
> +	/* must be natural-word sized, or 0 to ignore length */
> +	switch (args->len) {
> +	case 0:
> +	case 1:
> +	case 2:
> +	case 4:
> +	case 8:
> +		break;
> +	default:
> +		return -EINVAL;
> +	}
> +
> +	/* check for range overflow */
> +	if (args->addr + args->len < args->addr)
> +		return -EINVAL;
> +
> +	/* check for extra flags that we don't understand */
> +	if (args->flags & ~KVM_IOEVENTFD_VALID_FLAG_MASK)
> +		return -EINVAL;
> +
> +	/* ioeventfd with no length can't be combined with DATAMATCH */
> +	if (!args->len &&
> +	    args->flags & (KVM_IOEVENTFD_FLAG_PIO |
> +			   KVM_IOEVENTFD_FLAG_DATAMATCH))
> +		return -EINVAL;
> +
> +	return kvm_assign_ioeventfd_idx(kvm, bus_idx, args);
> +}
> +
> +static int
> +kvm_deassign_ioeventfd_idx(struct kvm *kvm, enum kvm_bus bus_idx,
> +			   struct kvm_ioeventfd *args)

While this file uses newline before function name quite often, putting
it on the same line seems more common - don't know which one the
maintainers prefer.

> +{
>  	struct _ioeventfd        *p, *tmp;
>  	struct eventfd_ctx       *eventfd;
>  	int                       ret = -ENOENT;
> 
> -	bus_idx = ioeventfd_bus_from_flags(args->flags);
>  	eventfd = eventfd_ctx_fdget(args->fd);
>  	if (IS_ERR(eventfd))
>  		return PTR_ERR(eventfd);
> @@ -918,6 +926,13 @@ kvm_deassign_ioeventfd(struct kvm *kvm, struct kvm_ioeventfd *args)
>  	return ret;
>  }
> 
> +static int kvm_deassign_ioeventfd(struct kvm *kvm, struct kvm_ioeventfd *args)
> +{
> +	enum kvm_bus bus_idx = ioeventfd_bus_from_flags(args->flags);
> +
> +	return kvm_deassign_ioeventfd_idx(kvm, bus_idx, args);
> +}
> +
>  int
>  kvm_ioeventfd(struct kvm *kvm, struct kvm_ioeventfd *args)
>  {

  reply	other threads:[~2015-09-11  7:39 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-11  3:17 [PATCH V4 0/4] Fast MMIO eventfd fixes Jason Wang
2015-09-11  3:17 ` [PATCH V4 1/4] kvm: factor out core eventfd assign/deassign logic Jason Wang
2015-09-11  7:39   ` Cornelia Huck [this message]
2015-09-11  8:17     ` Paolo Bonzini
2015-09-11  9:14     ` Jason Wang
2015-09-11  3:17 ` [PATCH V4 2/4] kvm: fix double free for fast mmio eventfd Jason Wang
2015-09-11  7:46   ` Cornelia Huck
2015-09-11  9:25     ` Jason Wang
2015-09-11 10:19       ` Cornelia Huck
2015-09-11  3:17 ` [PATCH V4 3/4] kvm: fix zero length mmio searching Jason Wang
2015-09-11  8:26   ` Paolo Bonzini
2015-09-11  8:31     ` Cornelia Huck
2015-09-11  9:26       ` Jason Wang
2015-09-11  3:17 ` [PATCH V4 4/4] kvm: add tracepoint for fast mmio Jason Wang
2015-09-11  8:15 ` [PATCH V4 0/4] Fast MMIO eventfd fixes Michael S. Tsirkin
2015-09-11  8:33   ` Paolo Bonzini
2015-09-11  9:28     ` Jason Wang
2015-09-13  8:51       ` Michael S. Tsirkin
2015-09-13  8:52     ` Michael S. Tsirkin

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=20150911093928.5cb7173c.cornelia.huck@de.ibm.com \
    --to=cornelia.huck@de.ibm.com \
    --cc=gleb@kernel.org \
    --cc=jasowang@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mst@redhat.com \
    --cc=pbonzini@redhat.com \
    /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).