virtualization.lists.linux-foundation.org archive mirror
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@redhat.com>
To: Rusty Russell <rusty@rustcorp.com.au>
Cc: virtualization@lists.linux-foundation.org,
	"H. Peter Anvin" <hpa@zytor.com>
Subject: Re: [PATCH 16/22] virtio_pci: use separate notification offsets for each vq.
Date: Thu, 4 Apr 2013 11:25:59 +0300	[thread overview]
Message-ID: <20130404082559.GA10369@redhat.com> (raw)
In-Reply-To: <87obdu3kz0.fsf@rustcorp.com.au>

On Thu, Apr 04, 2013 at 04:18:03PM +1030, Rusty Russell wrote:
> "Michael S. Tsirkin" <mst@redhat.com> writes:
> > On Wed, Apr 03, 2013 at 04:40:29PM +1030, Rusty Russell wrote:
> >> Current proposal is a 16 bit 'offset' field in the queue data for each
> >> queue, ie.
> >>         addr = dev->notify_base + vq->notify_off;
> >> 
> >> You propose a per-device 'shift' field:
> >>         addr = dev->notify_base + (vq->index << dev->notify_shift);
> >> 
> >> Which allows greater offsets, but insists on a unique offset per queue.
> >> Might be a fair trade-off...
> >> 
> >> Cheers,
> >> Rusty.
> >
> > Or even
> >          addr = dev->notify_base + (vq->notify_off << dev->notify_shift);
> >
> > since notify_base is per capability, shift can be per capability too.
> > And for IO we can allow it to be 32 to mean "always use base".
> >
> > This is a bit more elegant than just saying "no offsets for IO".
> 
> Yes, I shied away from this because it makes the capabilities different
> sizes, but per capability is elegant.  Except it really needs to be a
> multiplier, not a shift, since we want a "0".  And magic numbers are
> horrible.
> Since the multiply can be done at device init time, I don't think it's a
> big issue.
> 
> The results looks something like this...
> 
> Cheers,
> Rusty.

Looks good, I'm implementing the wildcard MMIO to check that
this actually works as fast as PIO.

By the way, Gleb pointed out that on older hosts MMIO will
always be slower since we need to do a shadow page walk to
translate virtual to physical address.
Hopefully not a big concern, and after all we are still
keeping PIO around for use by BIOS ...

> diff --git a/drivers/virtio/virtio_pci.c b/drivers/virtio/virtio_pci.c
> index c917e3a..f2ce171 100644
> --- a/drivers/virtio/virtio_pci.c
> +++ b/drivers/virtio/virtio_pci.c
> @@ -46,8 +46,8 @@ struct virtio_pci_device {
>  	size_t notify_len;
>  	size_t device_len;
>  
> -	/* We use the queue_notify_moff only for MEM bars. */
> -	bool notify_use_offset;
> +	/* We use the queue_notify_off only for MEM bars. */
> +	u32 notify_offset_multiplier;
>  
>  	/* a list of queues so we can dispatch IRQs */
>  	spinlock_t lock;
> @@ -469,7 +469,7 @@ static struct virtqueue *setup_vq(struct virtio_device *vdev, unsigned index,
>  	struct virtio_pci_device *vp_dev = to_vp_device(vdev);
>  	struct virtio_pci_vq_info *info;
>  	struct virtqueue *vq;
> -	u16 num;
> +	u16 num, off;
>  	int err;
>  
>  	if (index >= ioread16(&vp_dev->common->num_queues))
> @@ -502,19 +502,16 @@ static struct virtqueue *setup_vq(struct virtio_device *vdev, unsigned index,
>  
>  	info->msix_vector = msix_vec;
>  
> -	if (vp_dev->notify_use_offset) {
> -		/* get offset of notification byte for this virtqueue */
> -		u16 off = ioread16(&vp_dev->common->queue_notify_moff);
> -		if (off > vp_dev->notify_len) {
> -			dev_warn(&vp_dev->pci_dev->dev,
> -				 "bad notification offset %u for queue %u (> %u)",
> -				 off, index, vp_dev->notify_len);
> -			err = -EINVAL;
> -			goto out_info;
> -		}
> -		info->notify = vp_dev->notify_base + off;
> -	} else
> -		info->notify = vp_dev->notify_base;
> +	/* get offset of notification byte for this virtqueue */
> +	off = ioread16(&vp_dev->common->queue_notify_off);
> +	if (off * vp_dev->notify_offset_multiplier > vp_dev->notify_len) {

maybe check there's no overflow too?
if (UINT32_MAX / vp_dev->notify_offset_multiplier > off)
	return -EINVAL;

> +		dev_warn(&vp_dev->pci_dev->dev,
> +			 "bad notification offset %u for queue %u (> %u)",
> +			 off, index, vp_dev->notify_len);
> +		err = -EINVAL;
> +		goto out_info;
> +	}

I don't know if you want to limit this to "0 or power of two",
if yes you'd do
	if (vp_dev->notify_offset_multiplier & (vp_dev->notify_offset_multiplier - 1))
		return -EINVAL;

> +	info->notify = vp_dev->notify_base + off * vp_dev->notify_offset_multiplier;
>  
>  	info->queue = alloc_virtqueue_pages(&num);
>  	if (info->queue == NULL) {
> @@ -812,7 +809,7 @@ static void virtio_pci_release_dev(struct device *_d)
>  }
>  
>  static void __iomem *map_capability(struct pci_dev *dev, int off, size_t minlen,
> -				    size_t *len, bool *is_mem)
> +				    size_t *len)
>  {
>  	u8 bar;
>  	u32 offset, length;
> @@ -834,8 +831,6 @@ static void __iomem *map_capability(struct pci_dev *dev, int off, size_t minlen,
>  
>  	if (len)
>  		*len = length;
> -	if (is_mem)
> -		*is_mem = pci_resource_flags(dev, bar) & IORESOURCE_MEM;
>  
>  	/* We want uncachable mapping, even if bar is cachable. */
>  	p = pci_iomap_range(dev, bar, offset, length, PAGE_SIZE, true);
> @@ -914,19 +909,23 @@ static int virtio_pci_probe(struct pci_dev *pci_dev,
>  	err = -EINVAL;
>  	vp_dev->common = map_capability(pci_dev, common,
>  					sizeof(struct virtio_pci_common_cfg),
> -					NULL, NULL);
> +					NULL);
>  	if (!vp_dev->common)
>  		goto out_req_regions;
> -	vp_dev->isr = map_capability(pci_dev, isr, sizeof(u8), NULL, NULL);
> +	vp_dev->isr = map_capability(pci_dev, isr, sizeof(u8), NULL);
>  	if (!vp_dev->isr)
>  		goto out_map_common;
> +
> +	/* Read notify_off_multiplier from config space. */
> +	pci_read_config_dword(pci_dev,
> +			      notify + offsetof(struct virtio_pci_notify_cap,
> +						notify_off_multiplier),
> +			      &vp_dev->notify_offset_multiplier);
>  	vp_dev->notify_base = map_capability(pci_dev, notify, sizeof(u8),
> -					     &vp_dev->notify_len,
> -					     &vp_dev->notify_use_offset);
> +					     &vp_dev->notify_len);
>  	if (!vp_dev->notify_len)
>  		goto out_map_isr;
> -	vp_dev->device = map_capability(pci_dev, device, 0,
> -					&vp_dev->device_len, NULL);
> +	vp_dev->device = map_capability(pci_dev, device, 0, &vp_dev->device_len);
>  	if (!vp_dev->device)
>  		goto out_map_notify;
>  
> diff --git a/include/uapi/linux/virtio_pci.h b/include/uapi/linux/virtio_pci.h
> index 942135a..3e61d55 100644
> --- a/include/uapi/linux/virtio_pci.h
> +++ b/include/uapi/linux/virtio_pci.h
> @@ -133,6 +133,11 @@ struct virtio_pci_cap {
>  	__le32 length;	/* Length. */
>  };
>  
> +struct virtio_pci_notify_cap {
> +	struct virtio_pci_cap cap;
> +	__le32 notify_off_multiplier;	/* Multiplier for queue_notify_off. */
> +};
> +
>  /* Fields in VIRTIO_PCI_CAP_COMMON_CFG: */
>  struct virtio_pci_common_cfg {
>  	/* About the whole device. */
> @@ -146,13 +151,13 @@ struct virtio_pci_common_cfg {
>  	__u8 unused1;
>  
>  	/* About a specific virtqueue. */
> -	__le16 queue_select;	/* read-write */
> -	__le16 queue_size;	/* read-write, power of 2. */
> -	__le16 queue_msix_vector;/* read-write */
> -	__le16 queue_enable;	/* read-write */
> -	__le16 queue_notify_moff; /* read-only */
> -	__le64 queue_desc;	/* read-write */
> -	__le64 queue_avail;	/* read-write */
> -	__le64 queue_used;	/* read-write */
> +	__le16 queue_select;		/* read-write */
> +	__le16 queue_size;		/* read-write, power of 2. */
> +	__le16 queue_msix_vector;	/* read-write */
> +	__le16 queue_enable;		/* read-write */
> +	__le16 queue_notify_off;	/* read-only */
> +	__le64 queue_desc;		/* read-write */
> +	__le64 queue_avail;		/* read-write */
> +	__le64 queue_used;		/* read-write */
>  };
>  #endif /* _UAPI_LINUX_VIRTIO_PCI_H */
> 

  reply	other threads:[~2013-04-04  8:25 UTC|newest]

Thread overview: 94+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-21  8:29 [PATCH 00/22] New virtio PCI layout Rusty Russell
2013-03-21  8:29 ` [PATCH 01/22] virtio_config: introduce size-based accessors Rusty Russell
2013-03-21  8:29 ` [PATCH 02/22] virtio_config: use " Rusty Russell
2013-03-21  8:29 ` [PATCH 03/22] virtio_config: make transports implement accessors Rusty Russell
2013-03-21  9:09   ` Cornelia Huck
2013-03-22  0:31     ` Rusty Russell
2013-03-22  9:13       ` Cornelia Huck
2013-03-22 14:43   ` Sjur Brændeland
2013-03-24  4:24     ` Rusty Russell
2013-04-03 15:58       ` Sjur Brændeland
2013-04-02 17:16   ` Pawel Moll
2013-03-21  8:29 ` [PATCH 04/22] virtio: use u32, not bitmap for struct virtio_device's features Rusty Russell
2013-03-21 10:00   ` Cornelia Huck
2013-03-22  0:48     ` Rusty Russell
2013-03-21  8:29 ` [PATCH 05/22] virtio: add support for 64 bit features Rusty Russell
2013-03-21 10:06   ` Cornelia Huck
2013-03-22  0:50     ` Rusty Russell
2013-03-22  9:15       ` Cornelia Huck
2013-03-22 14:50     ` Sjur Brændeland
2013-03-22 20:12       ` Ohad Ben-Cohen
2013-03-25  8:30         ` Rusty Russell
2013-04-02 17:09   ` Pawel Moll
2013-03-21  8:29 ` [PATCH 06/22] virtio: move vring structure into struct virtqueue Rusty Russell
2013-03-21  8:29 ` [PATCH 07/22] pci: add pci_iomap_range Rusty Russell
2013-03-21  8:29 ` [PATCH 08/22] virtio-pci: define layout for virtio vendor-specific capabilities Rusty Russell
2013-03-21  8:29 ` [PATCH 09/22] virtio_pci: move old defines to legacy, introduce new structure Rusty Russell
2013-03-21  8:29 ` [PATCH 10/22] virtio_pci: use _LEGACY_ defines in virtio_pci_legacy.c Rusty Russell
2013-03-21  8:29 ` [PATCH 11/22] virtio_pci: don't use the legacy driver if we find the new PCI capabilities Rusty Russell
2013-03-21  8:29 ` [PATCH 12/22] virtio_pci: allow duplicate capabilities Rusty Russell
2013-03-21 10:28   ` Michael S. Tsirkin
2013-03-21 14:26     ` H. Peter Anvin
2013-03-21 14:43       ` Michael S. Tsirkin
2013-03-21 14:45         ` H. Peter Anvin
2013-03-21 15:19           ` Michael S. Tsirkin
2013-03-21 15:26             ` H. Peter Anvin
2013-03-21 15:58               ` Michael S. Tsirkin
2013-03-21 16:04                 ` H. Peter Anvin
2013-03-21 16:11                   ` Michael S. Tsirkin
2013-03-21 16:15                     ` H. Peter Anvin
2013-03-21 16:26                       ` Michael S. Tsirkin
2013-03-21 16:32                         ` H. Peter Anvin
2013-03-21 17:07                           ` Michael S. Tsirkin
2013-03-21 17:09                             ` H. Peter Anvin
2013-03-21 17:13                               ` Michael S. Tsirkin
2013-03-21 17:49                                 ` Michael S. Tsirkin
2013-03-21 17:54                                   ` H. Peter Anvin
2013-03-21 18:01                                     ` Michael S. Tsirkin
2013-03-22  0:57                                     ` Rusty Russell
2013-03-22  3:17                                       ` H. Peter Anvin
2013-03-24 13:14                                       ` Michael S. Tsirkin
2013-03-24 23:23                                         ` H. Peter Anvin
2013-03-25  6:53                                           ` Michael S. Tsirkin
2013-03-25  6:54                                             ` H. Peter Anvin
2013-03-25 10:03                                               ` Rusty Russell
2013-03-21  8:29 ` [PATCH 13/22] virtio_pci: new, capability-aware driver Rusty Russell
2013-03-21 10:24   ` Michael S. Tsirkin
2013-03-22  1:02     ` Rusty Russell
2013-03-24 13:08       ` Michael S. Tsirkin
2013-03-21  8:29 ` [PATCH 14/22] virtio_pci: layout changes as per hpa's suggestions Rusty Russell
2013-03-21  8:29 ` [PATCH 15/22] virtio_pci: use little endian for config space Rusty Russell
2013-03-21  8:29 ` [PATCH 16/22] virtio_pci: use separate notification offsets for each vq Rusty Russell
2013-03-21 10:13   ` Michael S. Tsirkin
2013-03-21 10:35     ` Michael S. Tsirkin
2013-03-22  2:52     ` Rusty Russell
2013-03-24 14:38       ` Michael S. Tsirkin
2013-03-24 20:19       ` Michael S. Tsirkin
2013-03-24 23:27         ` H. Peter Anvin
2013-03-25  7:05           ` Michael S. Tsirkin
2013-03-25 10:00         ` Rusty Russell
2013-03-26 19:39           ` Michael S. Tsirkin
2013-03-27  0:07             ` Rusty Russell
2013-03-27  0:22               ` H. Peter Anvin
2013-03-27  2:31                 ` H. Peter Anvin
2013-03-27 11:26                   ` Michael S. Tsirkin
2013-03-27 14:21                     ` H. Peter Anvin
2013-03-27 11:25               ` Michael S. Tsirkin
2013-03-28  4:50                 ` H. Peter Anvin
2013-03-30  3:19                   ` Rusty Russell
2013-04-02 22:51                     ` H. Peter Anvin
2013-04-03  6:10                       ` Rusty Russell
2013-04-03 11:22                         ` Michael S. Tsirkin
2013-04-03 14:10                           ` H. Peter Anvin
2013-04-03 14:35                             ` Michael S. Tsirkin
2013-04-03 14:35                               ` H. Peter Anvin
2013-04-03 17:02                                 ` Michael S. Tsirkin
2013-04-04  5:48                           ` Rusty Russell
2013-04-04  8:25                             ` Michael S. Tsirkin [this message]
2013-04-05  1:25                               ` Rusty Russell
2013-03-21  8:29 ` [PATCH 17/22] virtio_pci_legacy: cleanup struct virtio_pci_vq_info Rusty Russell
2013-03-21  8:29 ` [PATCH 18/22] virtio_pci: share structure between legacy and modern Rusty Russell
2013-03-21  8:29 ` [PATCH 19/22] virtio_pci: share interrupt/notify handlers " Rusty Russell
2013-03-21  8:29 ` [PATCH 20/22] virtio_pci: share virtqueue setup/teardown between modern and legacy driver Rusty Russell
2013-03-21  8:29 ` [PATCH 21/22] virtio_pci: simplify common helpers Rusty Russell
2013-03-21  8:29 ` [PATCH 22/22] virtio_pci: fix finalize_features in modern driver Rusty Russell

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=20130404082559.GA10369@redhat.com \
    --to=mst@redhat.com \
    --cc=hpa@zytor.com \
    --cc=rusty@rustcorp.com.au \
    --cc=virtualization@lists.linux-foundation.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).