mbox series

[RFC,0/2] Introduce MMIO/PIO dispatch file descriptors (ioregionfd)

Message ID cover.1609231373.git.eafanasova@gmail.com (mailing list archive)
Headers show
Series Introduce MMIO/PIO dispatch file descriptors (ioregionfd) | expand

Message

Elena Afanasova Dec. 29, 2020, 10:02 a.m. UTC
This patchset introduces a KVM dispatch mechanism which can be used 
for handling MMIO/PIO accesses over file descriptors without returning 
from ioctl(KVM_RUN). This allows device emulation to run in another task 
separate from the vCPU task.

This is achieved through KVM vm ioctl for registering MMIO/PIO regions and 
a wire protocol that KVM uses to communicate with a task handling an 
MMIO/PIO access.

ioregionfd relies on kmemcg in order to limit the amount of kernel memory 
that userspace can consume. Can NR_IOBUS_DEVS hardcoded limit be enforced 
only in case kmemcg is disabled?

Elena Afanasova (2):
  KVM: add initial support for KVM_SET_IOREGION
  KVM: add initial support for ioregionfd blocking read/write operations

 arch/x86/kvm/Kconfig     |   1 +
 arch/x86/kvm/Makefile    |   1 +
 arch/x86/kvm/x86.c       |   1 +
 include/linux/kvm_host.h |  17 ++
 include/uapi/linux/kvm.h |  23 +++
 virt/kvm/Kconfig         |   3 +
 virt/kvm/eventfd.c       |  25 +++
 virt/kvm/eventfd.h       |  14 ++
 virt/kvm/ioregion.c      | 390 +++++++++++++++++++++++++++++++++++++++
 virt/kvm/ioregion.h      |  15 ++
 virt/kvm/kvm_main.c      |  20 +-
 11 files changed, 507 insertions(+), 3 deletions(-)
 create mode 100644 virt/kvm/eventfd.h
 create mode 100644 virt/kvm/ioregion.c
 create mode 100644 virt/kvm/ioregion.h

Comments

Stefan Hajnoczi Dec. 29, 2020, 12:06 p.m. UTC | #1
On Tue, Dec 29, 2020 at 01:02:42PM +0300, Elena Afanasova wrote:
> This patchset introduces a KVM dispatch mechanism which can be used 
> for handling MMIO/PIO accesses over file descriptors without returning 
> from ioctl(KVM_RUN). This allows device emulation to run in another task 
> separate from the vCPU task.
> 
> This is achieved through KVM vm ioctl for registering MMIO/PIO regions and 
> a wire protocol that KVM uses to communicate with a task handling an 
> MMIO/PIO access.
> 
> ioregionfd relies on kmemcg in order to limit the amount of kernel memory 
> that userspace can consume. Can NR_IOBUS_DEVS hardcoded limit be enforced 
> only in case kmemcg is disabled?

Thanks for sharing this! Can you describe the todos? I noticed some in
Patch 1 and highlighted them. In addition:
 * Signal handling when the vCPU thread is interrupted in
   kernel_read()/kernel_write()

> Elena Afanasova (2):
>   KVM: add initial support for KVM_SET_IOREGION
>   KVM: add initial support for ioregionfd blocking read/write operations
> 
>  arch/x86/kvm/Kconfig     |   1 +
>  arch/x86/kvm/Makefile    |   1 +
>  arch/x86/kvm/x86.c       |   1 +
>  include/linux/kvm_host.h |  17 ++
>  include/uapi/linux/kvm.h |  23 +++
>  virt/kvm/Kconfig         |   3 +
>  virt/kvm/eventfd.c       |  25 +++
>  virt/kvm/eventfd.h       |  14 ++
>  virt/kvm/ioregion.c      | 390 +++++++++++++++++++++++++++++++++++++++
>  virt/kvm/ioregion.h      |  15 ++
>  virt/kvm/kvm_main.c      |  20 +-
>  11 files changed, 507 insertions(+), 3 deletions(-)
>  create mode 100644 virt/kvm/eventfd.h
>  create mode 100644 virt/kvm/ioregion.c
>  create mode 100644 virt/kvm/ioregion.h
> 
> -- 
> 2.25.1
>
Elena Afanasova Dec. 30, 2020, 5:56 p.m. UTC | #2
On Tue, 2020-12-29 at 12:06 +0000, Stefan Hajnoczi wrote:
> On Tue, Dec 29, 2020 at 01:02:42PM +0300, Elena Afanasova wrote:
> > This patchset introduces a KVM dispatch mechanism which can be
> > used 
> > for handling MMIO/PIO accesses over file descriptors without
> > returning 
> > from ioctl(KVM_RUN). This allows device emulation to run in another
> > task 
> > separate from the vCPU task.
> > 
> > This is achieved through KVM vm ioctl for registering MMIO/PIO
> > regions and 
> > a wire protocol that KVM uses to communicate with a task handling
> > an 
> > MMIO/PIO access.
> > 
> > ioregionfd relies on kmemcg in order to limit the amount of kernel
> > memory 
> > that userspace can consume. Can NR_IOBUS_DEVS hardcoded limit be
> > enforced 
> > only in case kmemcg is disabled?
> 
> Thanks for sharing this! Can you describe the todos? I noticed some
> in
> Patch 1 and highlighted them. In addition:
>  * Signal handling when the vCPU thread is interrupted in
>    kernel_read()/kernel_write()
> 
TODOs:

* Signal handling when the vCPU thread is interrupted in
   kernel_read()/kernel_write()
* Add ioregionfd cmds/replies serialization
* Implement KVM_EXIT_IOREGIONFD_FAILURE
* Add non-x86 arch support
* Add kvm-unittests

> > Elena Afanasova (2):
> >   KVM: add initial support for KVM_SET_IOREGION
> >   KVM: add initial support for ioregionfd blocking read/write
> > operations
> > 
> >  arch/x86/kvm/Kconfig     |   1 +
> >  arch/x86/kvm/Makefile    |   1 +
> >  arch/x86/kvm/x86.c       |   1 +
> >  include/linux/kvm_host.h |  17 ++
> >  include/uapi/linux/kvm.h |  23 +++
> >  virt/kvm/Kconfig         |   3 +
> >  virt/kvm/eventfd.c       |  25 +++
> >  virt/kvm/eventfd.h       |  14 ++
> >  virt/kvm/ioregion.c      | 390
> > +++++++++++++++++++++++++++++++++++++++
> >  virt/kvm/ioregion.h      |  15 ++
> >  virt/kvm/kvm_main.c      |  20 +-
> >  11 files changed, 507 insertions(+), 3 deletions(-)
> >  create mode 100644 virt/kvm/eventfd.h
> >  create mode 100644 virt/kvm/ioregion.c
> >  create mode 100644 virt/kvm/ioregion.h
> > 
> > -- 
> > 2.25.1
> >