All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@redhat.com>
To: Rusty Russell <rusty@rustcorp.com.au>
Cc: Peter Maydell <peter.maydell@linaro.org>,
	Anthony Liguori <aliguori@us.ibm.com>,
	kvm@vger.kernel.org, virtualization@lists.linux-foundation.org,
	Stefan Hajnoczi <stefanha@redhat.com>,
	Paolo Bonzini <pbonzini@redhat.com>,
	KONRAD Frederic <fred.konrad@greensocs.com>
Subject: Re: [PATCH RFC] virtio-pci: new config layout: using memory BAR
Date: Wed, 5 Jun 2013 13:22:32 +0300	[thread overview]
Message-ID: <20130605102232.GB31830@redhat.com> (raw)
In-Reply-To: <87hahdrpmt.fsf@rustcorp.com.au>

On Wed, Jun 05, 2013 at 04:49:22PM +0930, Rusty Russell wrote:
> "Michael S. Tsirkin" <mst@redhat.com> writes:
> >> By my count, net still has 7 feature bits left, so I don't think the
> >> feature bits are likely to be a limitation in the next 6 months?
> >
> > Yes but you wanted a generic transport feature bit
> > for flexible SG layout.
> > Are you happy with VIRTIO_NET_F_ANY_HEADER_SG then?
> 
> If we need it within 6 months, I'd rather do that: this feature would
> then be assumed for 1.0, and reserved.  We may do that for other
> features, too (the committee will have to review).
> 
> >> MMIO is a bigger problem.  Linux guests are happy with it: does it break
> >> the Windows drivers?
> >> 
> >> Thanks,
> >> Rusty.
> >
> > You mean make BAR0 an MMIO BAR?
> > Yes, it would break current windows guests.
> > Further, as long as we use same address to notify all queues,
> > we would also need to decode the instruction on x86 and that's
> > measureably slower than PIO.
> > We could go back to discussing hypercall use for notifications,
> > but that has its own set of issues...
> 
> We might have something ready to deploy in 3 months,
> but realistically,
> I'd rather have it ready and tested outside the main git tree(s) and
> push it once the standard is committed.
> 
> Cheers,
> Rusty.


We have working code already. We don't need 3 months out of tree,
this gets us no progress. To make it ready to deploy
we need it upstream and people testing it.

I think the issue is the layout change, you don't want
the new config layout before we get standartization rolling, right?
Okay how about this small patch to the linux guest
(completely untested, just to give you the idea):


diff --git a/drivers/virtio/virtio_pci.c b/drivers/virtio/virtio_pci.c
index a7ce730..0e34862 100644
--- a/drivers/virtio/virtio_pci.c
+++ b/drivers/virtio/virtio_pci.c
@@ -675,6 +675,33 @@ static void virtio_pci_release_dev(struct device *_d)
 	 */
 }
 
+/* Map a BAR. But carefully: make sure we don't overlap the MSI-X table */
+static void __iomem * virtio_pci_iomap(struct pci_dev *pci_dev, int bar)
+{
+	int msix_cap = pci_find_capability(pci_dev, PCI_CAP_ID_MSIX);
+	if (msix_cap) {
+		u32 offset;
+		u8 bir;
+		pci_read_config_dword(pci_dev, msix_cap + PCI_MSIX_TABLE,
+				      &offset);
+		bir = (u8)(offset & PCI_MSIX_TABLE_BIR);
+		offset &= PCI_MSIX_TABLE_OFFSET;
+		/* Spec says table offset is in a 4K page all by itself */
+		if (bir == bar && offset < 4096)
+			return NULL;
+
+		pci_read_config_dword(pci_dev, msix_cap + PCI_MSIX_PBA,
+				      &offset);
+		bir = (u8)(offset & PCI_MSIX_PBA_BIR);
+		offset &= PCI_MSIX_PBA_OFFSET;
+		/* Spec says table offset is in a 4K page all by itself. */
+		if (bir == bar && offset < 4096)
+			return NULL;
+	}
+	/* 4K is enough for all devices at the moment. */
+	return pci_iomap(pci_dev, 0, 4096);
+}
+
 /* the PCI probing function */
 static int virtio_pci_probe(struct pci_dev *pci_dev,
 			    const struct pci_device_id *id)
@@ -716,7 +743,10 @@ static int virtio_pci_probe(struct pci_dev *pci_dev,
 	if (err)
 		goto out_enable_device;
 
-	vp_dev->ioaddr = pci_iomap(pci_dev, 0, 0);
+	vp_dev->ioaddr = virtio_pci_iomap(pci_dev, 0);
+	/* Failed to map BAR0? Try with BAR1. */
+	if (vp_dev->ioaddr == NULL) {
+		vp_dev->ioaddr = virtio_pci_iomap(pci_dev, 1);
 	if (vp_dev->ioaddr == NULL) {
 		err = -ENOMEM;
 		goto out_req_regions;


In other words: put a copy of IO config at start of MMIO BAR1,
making sure we don't overlap the MSIX table that's there.

This does not break windows guests, and makes us compliant to the
PCI express spec.

Is this small enough to start going immediately, without waiting
3+ months?

I really think it's a good idea to put something like this
in the field: we might discover more issues around MMIO
and we'll address them in the new config layout.
This way we don't get two changes: new layout and switch to MMIO
all at once.

If you like this, I can make the appropriate spec and qemu changes in a
couple of days.

-- 
MST

  reply	other threads:[~2013-06-05 10:22 UTC|newest]

Thread overview: 109+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-28 16:03 [PATCH RFC] virtio-pci: new config layout: using memory BAR Michael S. Tsirkin
2013-05-28 17:15 ` Anthony Liguori
2013-05-28 17:15 ` Anthony Liguori
2013-05-28 17:32   ` Michael S. Tsirkin
2013-05-28 17:43     ` Paolo Bonzini
2013-05-29  2:02       ` Laszlo Ersek
2013-05-29  2:02         ` Laszlo Ersek
2013-05-29  4:33       ` Rusty Russell
2013-05-29  4:33       ` Rusty Russell
2013-05-29  7:27         ` Paolo Bonzini
2013-05-29  8:05           ` Michael S. Tsirkin
2013-05-29 10:07           ` Laszlo Ersek
2013-05-28 18:53     ` Anthony Liguori
2013-05-28 19:27       ` Michael S. Tsirkin
2013-05-29  4:31   ` Rusty Russell
2013-05-29  4:31     ` Rusty Russell
2013-05-29  8:24     ` Michael S. Tsirkin
2013-05-29  8:52       ` Paolo Bonzini
2013-05-29  9:00       ` Peter Maydell
2013-05-29 10:08         ` Michael S. Tsirkin
2013-05-29 10:53           ` Peter Maydell
2013-05-29 12:16             ` Michael S. Tsirkin
2013-05-29 12:28               ` Paolo Bonzini
2013-05-29 12:37                 ` Michael S. Tsirkin
2013-05-29 12:52     ` Anthony Liguori
2013-05-29 12:52       ` Anthony Liguori
2013-05-29 13:24       ` Michael S. Tsirkin
2013-05-29 13:35         ` Peter Maydell
2013-05-29 13:35         ` Peter Maydell
2013-05-29 13:41         ` Paolo Bonzini
2013-05-29 14:02           ` Michael S. Tsirkin
2013-05-29 14:18           ` Anthony Liguori
2013-05-29 14:18           ` Anthony Liguori
2013-05-30  7:43           ` Michael S. Tsirkin
2013-05-29 14:16         ` Anthony Liguori
2013-05-29 14:16         ` Anthony Liguori
2013-05-29 14:30           ` Michael S. Tsirkin
2013-05-29 14:32             ` Paolo Bonzini
2013-05-29 14:52               ` Michael S. Tsirkin
2013-05-29 14:55             ` Anthony Liguori
2013-05-29 16:12               ` Michael S. Tsirkin
2013-05-29 18:16               ` Michael S. Tsirkin
2013-05-29 14:55             ` Anthony Liguori
2013-05-30  3:58       ` Rusty Russell
2013-05-30  3:58         ` Rusty Russell
2013-05-30  5:55         ` Michael S. Tsirkin
2013-05-30  7:55         ` Michael S. Tsirkin
2013-06-03  0:17           ` Rusty Russell
2013-05-30 13:53         ` Anthony Liguori
2013-05-30 13:53           ` Anthony Liguori
2013-05-30 14:01           ` Michael S. Tsirkin
2013-06-03  0:26             ` Rusty Russell
2013-06-03 10:11               ` Michael S. Tsirkin
2013-06-04  5:31                 ` Rusty Russell
2013-06-04  6:42                   ` Michael S. Tsirkin
2013-06-05  7:19                     ` Rusty Russell
2013-06-05 10:22                       ` Michael S. Tsirkin [this message]
2013-06-05 12:59                     ` Anthony Liguori
2013-06-05 14:09                       ` Michael S. Tsirkin
2013-06-05 15:08                         ` Anthony Liguori
2013-06-05 15:19                           ` Michael S. Tsirkin
2013-06-05 15:46                             ` Anthony Liguori
2013-06-05 15:46                             ` Anthony Liguori
2013-06-05 16:20                               ` Michael S. Tsirkin
2013-06-05 18:57                                 ` Anthony Liguori
2013-06-05 19:43                                   ` Michael S. Tsirkin
2013-06-05 19:52                                     ` Michael S. Tsirkin
2013-06-05 20:45                                       ` Anthony Liguori
2013-06-05 21:15                                         ` H. Peter Anvin
2013-06-05 21:15                                         ` Michael S. Tsirkin
2013-06-05 20:42                                     ` Anthony Liguori
2013-06-05 21:14                                       ` Michael S. Tsirkin
2013-06-05 21:53                                         ` Anthony Liguori
2013-06-05 21:53                                         ` Anthony Liguori
2013-06-05 22:19                                           ` Benjamin Herrenschmidt
2013-06-05 22:53                                             ` Anthony Liguori
2013-06-05 23:27                                               ` Benjamin Herrenschmidt
2013-06-05 19:54                                   ` Michael S. Tsirkin
2013-06-06  3:42                                   ` Rusty Russell
2013-06-06 14:59                                     ` Anthony Liguori
2013-06-07  1:58                                       ` Rusty Russell
2013-06-07  8:25                                       ` Peter Maydell
2013-06-05 21:10                                 ` H. Peter Anvin
2013-06-05 21:17                                   ` Michael S. Tsirkin
2013-06-05 21:50                                   ` Anthony Liguori
2013-06-05 21:55                                     ` H. Peter Anvin
2013-06-05 22:08                                       ` Anthony Liguori
2013-06-05 23:07                                         ` H. Peter Anvin
2013-06-06  0:41                                           ` Anthony Liguori
2013-06-06  6:34                                             ` Gleb Natapov
2013-06-06 13:53                                               ` H. Peter Anvin
2013-06-06 15:02                                               ` Anthony Liguori
2013-06-07 11:30                                                 ` Gleb Natapov
2013-06-11  7:10                                                 ` Michael S. Tsirkin
2013-06-11  7:53                                                   ` Gleb Natapov
2013-06-11  8:02                                                     ` Michael S. Tsirkin
2013-06-11  8:03                                                       ` Gleb Natapov
2013-06-11  8:19                                                         ` Michael S. Tsirkin
2013-06-11  8:22                                                           ` Gleb Natapov
2013-06-11  8:30                                                             ` Michael S. Tsirkin
2013-06-11  8:32                                                               ` Gleb Natapov
2013-06-11  8:04                                                       ` Michael S. Tsirkin
2013-06-06 15:02                                               ` Anthony Liguori
2013-06-06 15:06                                               ` Gerd Hoffmann
2013-06-06 15:10                                                 ` Gleb Natapov
2013-06-06 15:19                                                   ` H. Peter Anvin
2013-06-06 15:22                                                   ` Gerd Hoffmann
2013-07-08  4:25                                                   ` Kevin O'Connor
2013-06-06  8:02                   ` 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=20130605102232.GB31830@redhat.com \
    --to=mst@redhat.com \
    --cc=aliguori@us.ibm.com \
    --cc=fred.konrad@greensocs.com \
    --cc=kvm@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=rusty@rustcorp.com.au \
    --cc=stefanha@redhat.com \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.