From: "Mika Penttilä" <mika.penttila@nextfour.com>
To: Jason Wang <jasowang@redhat.com>, mst@redhat.com
Cc: kvm@vger.kernel.org, virtualization@lists.linux-foundation.org,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
rob.miller@broadcom.com, lingshan.zhu@intel.com,
eperezma@redhat.com, lulu@redhat.com, shahafs@mellanox.com,
hanand@xilinx.com, mhabets@solarflare.com, gdawar@xilinx.com,
saugatm@xilinx.com, vmireyno@marvell.com,
zhangweining@ruijie.com.cn, eli@mellanox.com
Subject: Re: [PATCH 4/6] vhost_vdpa: support doorbell mapping via mmap
Date: Fri, 29 May 2020 12:16:02 +0300 [thread overview]
Message-ID: <bab90a3f-f0b3-37d3-89bc-cd17d33f3208@nextfour.com> (raw)
In-Reply-To: <20200529080303.15449-5-jasowang@redhat.com>
Hi,
On 29.5.2020 11.03, Jason Wang wrote:
> Currently the doorbell is relayed via eventfd which may have
> significant overhead because of the cost of vmexits or syscall. This
> patch introduces mmap() based doorbell mapping which can eliminate the
> overhead caused by vmexit or syscall.
Just wondering. I know very little about vdpa. But how is such a "sw
doorbell" monitored or observed, if no fault or wmexit etc.
Is there some kind of polling used?
> To ease the userspace modeling of the doorbell layout (usually
> virtio-pci), this patch starts from a doorbell per page
> model. Vhost-vdpa only support the hardware doorbell that sit at the
> boundary of a page and does not share the page with other registers.
>
> Doorbell of each virtqueue must be mapped separately, pgoff is the
> index of the virtqueue. This allows userspace to map a subset of the
> doorbell which may be useful for the implementation of software
> assisted virtqueue (control vq) in the future.
>
> Signed-off-by: Jason Wang <jasowang@redhat.com>
> ---
> drivers/vhost/vdpa.c | 59 ++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 59 insertions(+)
>
> diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c
> index 6ff72289f488..bbe23cea139a 100644
> --- a/drivers/vhost/vdpa.c
> +++ b/drivers/vhost/vdpa.c
> @@ -15,6 +15,7 @@
> #include <linux/module.h>
> #include <linux/cdev.h>
> #include <linux/device.h>
> +#include <linux/mm.h>
> #include <linux/iommu.h>
> #include <linux/uuid.h>
> #include <linux/vdpa.h>
> @@ -741,12 +742,70 @@ static int vhost_vdpa_release(struct inode *inode, struct file *filep)
> return 0;
> }
>
> +static vm_fault_t vhost_vdpa_fault(struct vm_fault *vmf)
> +{
> + struct vhost_vdpa *v = vmf->vma->vm_file->private_data;
> + struct vdpa_device *vdpa = v->vdpa;
> + const struct vdpa_config_ops *ops = vdpa->config;
> + struct vdpa_notification_area notify;
> + struct vm_area_struct *vma = vmf->vma;
> + u16 index = vma->vm_pgoff;
> +
> + notify = ops->get_vq_notification(vdpa, index);
> +
> + vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
> + if (remap_pfn_range(vma, vmf->address & PAGE_MASK,
> + notify.addr >> PAGE_SHIFT, PAGE_SIZE,
> + vma->vm_page_prot))
> + return VM_FAULT_SIGBUS;
> +
> + return VM_FAULT_NOPAGE;
> +}
> +
> +static const struct vm_operations_struct vhost_vdpa_vm_ops = {
> + .fault = vhost_vdpa_fault,
> +};
> +
> +static int vhost_vdpa_mmap(struct file *file, struct vm_area_struct *vma)
> +{
> + struct vhost_vdpa *v = vma->vm_file->private_data;
> + struct vdpa_device *vdpa = v->vdpa;
> + const struct vdpa_config_ops *ops = vdpa->config;
> + struct vdpa_notification_area notify;
> + int index = vma->vm_pgoff;
> +
> + if (vma->vm_end - vma->vm_start != PAGE_SIZE)
> + return -EINVAL;
> + if ((vma->vm_flags & VM_SHARED) == 0)
> + return -EINVAL;
> + if (vma->vm_flags & VM_READ)
> + return -EINVAL;
> + if (index > 65535)
> + return -EINVAL;
> + if (!ops->get_vq_notification)
> + return -ENOTSUPP;
> +
> + /* To be safe and easily modelled by userspace, We only
> + * support the doorbell which sits on the page boundary and
> + * does not share the page with other registers.
> + */
> + notify = ops->get_vq_notification(vdpa, index);
> + if (notify.addr & (PAGE_SIZE - 1))
> + return -EINVAL;
> + if (vma->vm_end - vma->vm_start != notify.size)
> + return -ENOTSUPP;
> +
> + vma->vm_ops = &vhost_vdpa_vm_ops;
> + return 0;
> +}
> +
> static const struct file_operations vhost_vdpa_fops = {
> .owner = THIS_MODULE,
> .open = vhost_vdpa_open,
> .release = vhost_vdpa_release,
> .write_iter = vhost_vdpa_chr_write_iter,
> .unlocked_ioctl = vhost_vdpa_unlocked_ioctl,
> + .mmap = vhost_vdpa_mmap,
> .compat_ioctl = compat_ptr_ioctl,
> };
>
next prev parent reply other threads:[~2020-05-29 9:16 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-29 8:02 [PATCH 0/6] vDPA: doorbell mapping Jason Wang
2020-05-29 8:02 ` [PATCH 1/6] vhost: allow device that does not depend on vhost worker Jason Wang
2020-06-02 5:01 ` Michael S. Tsirkin
2020-06-02 7:04 ` Jason Wang
2020-05-29 8:02 ` [PATCH 2/6] vhost: use mmgrab() instead of mmget() for non worker device Jason Wang
2020-05-29 8:03 ` [PATCH 3/6] vdpa: introduce get_vq_notification method Jason Wang
2020-05-29 8:03 ` [PATCH 4/6] vhost_vdpa: support doorbell mapping via mmap Jason Wang
2020-05-29 9:16 ` Mika Penttilä [this message]
2020-05-29 9:24 ` Jason Wang
2020-06-01 19:22 ` kbuild test robot
2020-06-02 4:56 ` Michael S. Tsirkin
2020-06-02 6:49 ` Jason Wang
2020-06-02 13:31 ` Michael S. Tsirkin
2020-06-03 4:18 ` Jason Wang
2020-06-03 6:34 ` Michael S. Tsirkin
2020-06-03 6:37 ` Jason Wang
[not found] ` <CAJPjb1JGn-+Y2EHvn1S+=uX_cjPVEUmGGo7CmAM2kTqyn4NRYQ@mail.gmail.com>
2020-06-02 2:04 ` [virtio-dev] " Jason Wang
2020-05-29 8:03 ` [PATCH 5/6] vdpa: introduce virtio pci driver Jason Wang
2020-06-02 5:08 ` Michael S. Tsirkin
2020-06-02 7:08 ` Jason Wang
2020-06-05 8:54 ` Jason Wang
2020-06-07 13:51 ` Michael S. Tsirkin
2020-06-08 3:32 ` Jason Wang
2020-06-08 6:32 ` Michael S. Tsirkin
2020-06-08 9:18 ` Jason Wang
2020-06-08 9:31 ` Michael S. Tsirkin
2020-06-08 9:43 ` Jason Wang
2020-06-08 9:45 ` Michael S. Tsirkin
2020-06-08 9:46 ` Jason Wang
2020-06-08 9:54 ` Michael S. Tsirkin
2020-06-08 10:07 ` Jason Wang
2020-06-08 13:29 ` Michael S. Tsirkin
2020-06-09 5:55 ` Jason Wang
2020-06-02 5:09 ` Michael S. Tsirkin
2020-06-02 7:12 ` Jason Wang
2020-06-04 18:50 ` Michael S. Tsirkin
2020-05-29 8:03 ` [PATCH 6/6] vdpa: vp_vdpa: report doorbell location Jason Wang
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=bab90a3f-f0b3-37d3-89bc-cd17d33f3208@nextfour.com \
--to=mika.penttila@nextfour.com \
--cc=eli@mellanox.com \
--cc=eperezma@redhat.com \
--cc=gdawar@xilinx.com \
--cc=hanand@xilinx.com \
--cc=jasowang@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=lingshan.zhu@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lulu@redhat.com \
--cc=mhabets@solarflare.com \
--cc=mst@redhat.com \
--cc=netdev@vger.kernel.org \
--cc=rob.miller@broadcom.com \
--cc=saugatm@xilinx.com \
--cc=shahafs@mellanox.com \
--cc=virtualization@lists.linux-foundation.org \
--cc=vmireyno@marvell.com \
--cc=zhangweining@ruijie.com.cn \
/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).