kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sean Christopherson <seanjc@google.com>
To: Ilias Stamatis <ilstam@amazon.com>
Cc: kvm@vger.kernel.org, pbonzini@redhat.com, pdurrant@amazon.co.uk,
	 dwmw@amazon.co.uk, nh-open-source@amazon.com,
	Paul Durrant <paul@xen.org>
Subject: Re: [PATCH v2 4/6] KVM: Add KVM_(UN)REGISTER_COALESCED_MMIO2 ioctls
Date: Fri, 16 Aug 2024 17:36:58 -0700	[thread overview]
Message-ID: <Zr_wqv7HiFNR2aCz@google.com> (raw)
In-Reply-To: <20240718193543.624039-5-ilstam@amazon.com>

On Thu, Jul 18, 2024, Ilias Stamatis wrote:
> Add 2 new ioctls, KVM_REGISTER_COALESCED_MMIO2 and
> KVM_UNREGISTER_COALESCED_MMIO2. These do the same thing as their v1
> equivalents except an fd returned by KVM_CREATE_COALESCED_MMIO_BUFFER
> needs to be passed as an argument to them.
> 
> The fd representing a ring buffer is associated with an MMIO region
> registered for coalescing and all writes to that region are accumulated
> there. This is in contrast to the v1 API where all regions have to share
> the same buffer. Nevertheless, userspace code can still use the same
> ring buffer for multiple zones if it wishes to do so.
> 
> Userspace can check for the availability of the new API by checking if
> the KVM_CAP_COALESCED_MMIO2 capability is supported.
> 
> Signed-off-by: Ilias Stamatis <ilstam@amazon.com>
> Reviewed-by: Paul Durrant <paul@xen.org>
> ---
> 
> v1->v2:
>   - Rebased on top of kvm/queue resolving the conflict in kvm.h
> 
>  include/uapi/linux/kvm.h  | 16 ++++++++++++++++
>  virt/kvm/coalesced_mmio.c | 37 +++++++++++++++++++++++++++++++------
>  virt/kvm/coalesced_mmio.h |  7 ++++---
>  virt/kvm/kvm_main.c       | 36 +++++++++++++++++++++++++++++++++++-
>  4 files changed, 86 insertions(+), 10 deletions(-)
> 
> diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h
> index 87f79a820fc0..7e8d5c879986 100644
> --- a/include/uapi/linux/kvm.h
> +++ b/include/uapi/linux/kvm.h
> @@ -480,6 +480,16 @@ struct kvm_coalesced_mmio_zone {
>  	};
>  };
>  
> +struct kvm_coalesced_mmio_zone2 {
> +	__u64 addr;
> +	__u32 size;
> +	union {
> +		__u32 pad;
> +		__u32 pio;
> +	};
> +	int buffer_fd;

Dunno if it matters, but KVM typically uses __u32 for file descriptors and then
does the verificaton on the backend (which needs to be there regardless).

> diff --git a/virt/kvm/coalesced_mmio.c b/virt/kvm/coalesced_mmio.c
> index 64428b0a4aad..729f3293f768 100644
> --- a/virt/kvm/coalesced_mmio.c
> +++ b/virt/kvm/coalesced_mmio.c
> @@ -17,6 +17,7 @@
>  #include <linux/kvm.h>
>  #include <linux/anon_inodes.h>
>  #include <linux/poll.h>
> +#include <linux/file.h>
>  
>  #include "coalesced_mmio.h"
>  
> @@ -279,19 +280,40 @@ int kvm_vm_ioctl_create_coalesced_mmio_buffer(struct kvm *kvm)
>  }
>  
>  int kvm_vm_ioctl_register_coalesced_mmio(struct kvm *kvm,
> -					 struct kvm_coalesced_mmio_zone *zone)
> +					 struct kvm_coalesced_mmio_zone2 *zone,
> +					 bool use_buffer_fd)
>  {
> -	int ret;
> +	int ret = 0;

Heh, init ret to zero, and then return a pile of error before ret is ever touched.
I assume ret can be set to '0' after mutex_unlock(&kvm->slots_lock); in the happy
path, which would also show that it is indeed the happy path.

> diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
> index 9eb22287384f..ef7dcce80136 100644
> --- a/virt/kvm/kvm_main.c
> +++ b/virt/kvm/kvm_main.c
> @@ -4892,6 +4892,7 @@ static int kvm_vm_ioctl_check_extension_generic(struct kvm *kvm, long arg)
>  #ifdef CONFIG_KVM_MMIO
>  	case KVM_CAP_COALESCED_MMIO:
>  		return KVM_COALESCED_MMIO_PAGE_OFFSET;
> +	case KVM_CAP_COALESCED_MMIO2:
>  	case KVM_CAP_COALESCED_PIO:
>  		return 1;
>  #endif
> @@ -5230,15 +5231,48 @@ static long kvm_vm_ioctl(struct file *filp,
>  #ifdef CONFIG_KVM_MMIO
>  	case KVM_REGISTER_COALESCED_MMIO: {
>  		struct kvm_coalesced_mmio_zone zone;
> +		struct kvm_coalesced_mmio_zone2 zone2;
>  
>  		r = -EFAULT;
>  		if (copy_from_user(&zone, argp, sizeof(zone)))
>  			goto out;
> -		r = kvm_vm_ioctl_register_coalesced_mmio(kvm, &zone);
> +
> +		zone2.addr = zone.addr;
> +		zone2.size = zone.size;
> +		zone2.pio = zone.pio;
> +		zone2.buffer_fd = -1;
> +
> +		r = kvm_vm_ioctl_register_coalesced_mmio(kvm, &zone2, false);
> +		break;
> +	}
> +	case KVM_REGISTER_COALESCED_MMIO2: {

Ah, the curly braces were just early :-)

> +		struct kvm_coalesced_mmio_zone2 zone;
> +
> +		r = -EFAULT;
> +		if (copy_from_user(&zone, argp, sizeof(zone)))
> +			goto out;
> +
> +		r = kvm_vm_ioctl_register_coalesced_mmio(kvm, &zone, true);

  reply	other threads:[~2024-08-17  0:37 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-18 19:35 [PATCH v2 0/6] KVM: Improve MMIO Coalescing API Ilias Stamatis
2024-07-18 19:35 ` [PATCH v2 1/6] KVM: Fix coalesced_mmio_has_room() Ilias Stamatis
2024-07-18 19:35 ` [PATCH v2 2/6] KVM: Add KVM_CREATE_COALESCED_MMIO_BUFFER ioctl Ilias Stamatis
2024-08-17  0:32   ` Sean Christopherson
2024-07-18 19:35 ` [PATCH v2 3/6] KVM: Support poll() on coalesced mmio buffer fds Ilias Stamatis
2024-07-20  1:35   ` kernel test robot
2024-07-22 14:26     ` Stamatis, Ilias
2024-07-20 21:10   ` kernel test robot
2024-07-18 19:35 ` [PATCH v2 4/6] KVM: Add KVM_(UN)REGISTER_COALESCED_MMIO2 ioctls Ilias Stamatis
2024-08-17  0:36   ` Sean Christopherson [this message]
2024-07-18 19:35 ` [PATCH v2 5/6] KVM: Documentation: Document v2 of coalesced MMIO API Ilias Stamatis
2024-07-18 19:35 ` [PATCH v2 6/6] KVM: selftests: Add coalesced_mmio_test Ilias Stamatis
2024-08-17  0:40 ` [PATCH v2 0/6] KVM: Improve MMIO Coalescing API Sean Christopherson
2024-08-23 23:47 ` Sean Christopherson
2024-08-27 10:35   ` Stamatis, Ilias
2024-08-27 13:45     ` Sean Christopherson

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=Zr_wqv7HiFNR2aCz@google.com \
    --to=seanjc@google.com \
    --cc=dwmw@amazon.co.uk \
    --cc=ilstam@amazon.com \
    --cc=kvm@vger.kernel.org \
    --cc=nh-open-source@amazon.com \
    --cc=paul@xen.org \
    --cc=pbonzini@redhat.com \
    --cc=pdurrant@amazon.co.uk \
    /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).