Skip to contentSkip to conversation

virtio: add virtio-over-PCI driver

RFC Superseded Ira Snyder 4 participants 13 messages Feb 17, 2009 – Feb 20, 2009

Subsystems (6)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Ira Snyder

author
#0 lore raw

RFC 1/1 virtio: add virtio-over-PCI driver

This adds support to Linux for using virtio between two computers linked by a PCI interface. This allows the use of virtio_net to create a familiar, fast interface for communication. It should be possible to use other virtio devices in the future, but this has not been tested.

I have implemented guest support for the Freescale MPC8349EMDS board, which is capable of running in PCI agent mode (It acts like a PCI card, but is a complete computer system, running Linux). The driver is trivial to port to any MPC83xx system.

It was developed to work in a CompactPCI crate of computers, one of which is a standard x86 system (acting as the host) and many PowerPC systems (acting as guests).

I have only tested this driver with a single board in my system. The host is a 1066MHz Pentium3-M, and the guest is a 533MHz PowerPC. I am able achieve transfer rates of about 150 mbit using standard 1500 byte packets. Not especially fast, but ok for a first try, though I eventually need more speed. My previous attempt, the PCINet driver, is capable of about 300 mbit, using 64K packets. Performance of PCINet with 1500 byte packets is less than 50 mbit, so this is a definite improvement.

I have kept the implementation as simple as I found possible. I chose not to support any of the advanced features of virtio_net, because they made pairing up transfers between the host and guest queues much harder (if not impossible?). Any suggestions are welcome. Code would be even better :)

I have included a short document explaining what I think is the most complicated part of the driver: using the DMA engine to transfer data. I hope everything else is readily obvious from the code. Questions are welcome.

I will not be able to work on this full time for at least a few weeks, so I would appreciate actual review of this driver. Nitpicks are fine, I just won't be able to respond to them quickly.

---

Yes, the commit message has too much information. This is an RFC after all. I fully expect to have to make changes. In fact, I posting this more to "get it out there" than anything else, since I have other tasks that need doing.

I'd appreciate a serious review of the design by the people who have been pressuring me to use virtio. I'm very happy to answer any questions you have.

 Documentation/virtio-over-PCI.txt     |   61 ++
 arch/powerpc/boot/dts/mpc834x_mds.dts |    7 +
 drivers/virtio/Kconfig                |   22 +
 drivers/virtio/Makefile               |    2 +
 drivers/virtio/vop.h                  |  119 ++
 drivers/virtio/vop_fsl.c              | 1911 +++++++++++++++++++++++++++++++++
 drivers/virtio/vop_host.c             | 1028 ++++++++++++++++++
 drivers/virtio/vop_hw.h               |   80 ++
 8 files changed, 3230 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/virtio-over-PCI.txt
 create mode 100644 drivers/virtio/vop.h
 create mode 100644 drivers/virtio/vop_fsl.c
 create mode 100644 drivers/virtio/vop_host.c
 create mode 100644 drivers/virtio/vop_hw.h
Documentation/virtio-over-PCI.txt new file +61 -0
new file mode 100644
index 0000000..aea1e7d
@@ -0,0 +1,61 @@
+The implementation of virtio-over-PCI was driven with the following goals:
+* Avoid MMIO reads, try to use only MMIO writes
+* Use the onboard DMA engine, for speed
+
+The implementation also borrows many of the details from the only other
+implementation, virtio_ring.
+
+It succeeds in avoiding all MMIO reads on the critical paths. I did not
+see any reason to avoid the use of MMIO reads during device probing, since
+it is not a critical path.
+
+=== Avoiding MMIO reads ===
+To avoid MMIO reads, both the host and guest systems have a copy of the
+descriptors. Both sides need to read the descriptors after they have been
+written, but only the host system writes to them. This allows us to keep a
+local copy for later use.
+
+=== Using the DMA engine ===
+This is the only truly complicated part of the system. Since this
+implementation was designed for use with virtio_net, it may be biased
+towards virtio_net's usage of the virtio interface.
+
+The virtio_net driver provides a receive ring, which it fills with empty
+packets. The code sets up DMA transfers directly from the guest transmit
+queue to the empty packets in the host receive queue. Data transfer in the
+other direction works in a similar fashion.
+
+The guest (PowerPC) system keeps its own local set of descriptors, which are
+filled by the virtio add_buf() call. Whenever this happens, the avail ring is
+changed, and therefore we try to transfer data.
+
+The algorithm is essentially as follows:
+1) Check for an available local and remote entry
+2) For each link in the chain, set up a DMA transfer
+3) Move the entries to the used ring, do not update the used index
+4) Schedule a DMA callback to happen when the DMA finishes
+5) Start the DMA transfer
+6) When the DMA finishes, the callback updates the used indices and
+   triggers any necessary callbacks
+
+You will notice that the algorithm has no way of handling chains that are
+not exactly the same on the host and guest system. Without setting any of
+the fancier virtio_net features, this is the case.
+
+The chains currently have an entry which is 10 bytes long, for virtio_net
+metadata, and then a 1518 byte entry, for the actual packet data.
+
+=== Startup Sequence ===
+There are currently problems in the startup sequence between the host and
+guest drivers. The current scheme assumes that the guest is up and waiting
+before the host is ready. I am having a very hard time coming up with a scheme
+that is perfectly safe, where either side could win the race and be ready
+first.
+
+Even harder is a situation where you would like to use the "network device"
+from your bootloader to tftp a kernel, then boot Linux. In this case,
+Linux has no knowledge of where the device descriptors were before it booted.
+You'd need to stop and re-start the host driver to make sure it re-initializes
+the new descriptor memory after Linux has booted.
+
+This is a definite "needs work" item.
arch/powerpc/boot/dts/mpc834x_mds.dts +7 -0
index d9adba0..5c7617d 100644
@@ -104,6 +104,13 @@
 			mode = "cpu";
 		};
 
+		message-unit@8030 {
+			compatible = "fsl,mpc8349-mu";
+			reg = <0x8030 0xd0>;
+			interrupts = <69 0x8>;
+			interrupt-parent = <&ipic>;
+		};
+
 		dma@82a8 {
 			#address-cells = <1>;
 			#size-cells = <1>;
drivers/virtio/Kconfig +22 -0
index 3dd6294..efcf56b 100644
@@ -33,3 +33,25 @@ config VIRTIO_BALLOON
 
 	 If unsure, say M.
 
+config VIRTIO_OVER_PCI_HOST
+	tristate "Virtio-over-PCI Host support (EXPERIMENTAL)"
+	depends on PCI && EXPERIMENTAL
+	select VIRTIO
+	---help---
+	  This driver provides the host support necessary for using virtio
+	  over the PCI bus with a Freescale MPC8349EMDS evaluation board.
+
+	  If unsure, say N.
+
+config VIRTIO_OVER_PCI_FSL
+	tristate "Virtio-over-PCI Guest support (EXPERIMENTAL)"
+	depends on MPC834x_MDS && EXPERIMENTAL
+	select VIRTIO
+	select DMA_ENGINE
+	select FSL_DMA
+	---help---
+	  This driver provides the guest support necessary for using virtio
+	  over the PCI bus.
+
+	  If unsure, say N.
+
drivers/virtio/Makefile +2 -0
index 6738c44..f31afaa 100644
@@ -2,3 +2,5 @@ obj-$(CONFIG_VIRTIO) += virtio.o
 obj-$(CONFIG_VIRTIO_RING) += virtio_ring.o
 obj-$(CONFIG_VIRTIO_PCI) += virtio_pci.o
 obj-$(CONFIG_VIRTIO_BALLOON) += virtio_balloon.o
+obj-$(CONFIG_VIRTIO_OVER_PCI_HOST) += vop_host.o
+obj-$(CONFIG_VIRTIO_OVER_PCI_FSL) += vop_fsl.o
drivers/virtio/vop.h new file +119 -0

119 lines not on this page · raw message

drivers/virtio/vop_fsl.c new file +1911 -0

1,911 lines not on this page · raw message

drivers/virtio/vop_host.c new file +1028 -0

866 lines not on this page · raw message

drivers/virtio/vop_hw.h new file +80 -0

80 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Signature · 1 line
1.5.4.3

Part of the diff is not shown here. View the raw message.

#1 lore raw
Quoted 4 lines · On Wednesday 18 February 2009 08:54:25 Ira Snyder wrote:

This adds support to Linux for using virtio between two computers linked by a PCI interface. This allows the use of virtio_net to create a familiar, fast interface for communication. It should be possible to use other virtio devices in the future, but this has not been tested.

Hi Ira,

It's only first glance, but this looks sane. Two things on first note:
don't restrict yourself to 32 feature bits (only PCI does this, and they're going to have to hack when we reach feature 32).

Secondly:

Documentation/virtio-over-PCI.txt line 43

Quoted 3 lines
Documentation/virtio-over-PCI.txt new file +3 -0
+You will notice that the algorithm has no way of handling chains that are
+not exactly the same on the host and guest system. Without setting any of
+the fancier virtio_net features, this is the case.

Hmm, I think we can do slightly better than this.

How about prepending a 4 byte length on the host buffers? Allows host to specify length (for host->guest), and guest writes it to allow truncated buffers on guest->host.

That won't allow you to transfer *more* than one buffersize to the host, but you could use a different method (perhaps the 4 bytes indicates the *total* length?).

Do 4-byte DMA's suck for some reason?

Cheers,
Rusty.

author
#2 lore raw
Quoted 6 lines · Rusty Russell
Quoted 4 lines · On Wednesday 18 February 2009 08:54:25 Ira Snyder wrote:

This adds support to Linux for using virtio between two computers linked by a PCI interface. This allows the use of virtio_net to create a familiar, fast interface for communication. It should be possible to use other virtio devices in the future, but this has not been tested.

Quoted 6 lines

Hi Ira,

It's only first glance, but this looks sane. Two things on first note:
don't restrict yourself to 32 feature bits (only PCI does this, and they're going to have to hack when we reach feature 32).

There isn't any problem adding more feature bits. Do you think 128 bits is enough?

Quoted 7 lines

Secondly:

Documentation/virtio-over-PCI.txt line 43

Quoted 3 lines
Documentation/virtio-over-PCI.txt new file +3 -0
+You will notice that the algorithm has no way of handling chains that are
+not exactly the same on the host and guest system. Without setting any of
+the fancier virtio_net features, this is the case.

Hmm, I think we can do slightly better than this.

I think so too :) I just wasn't able to come up with an algorithm to make it work. And I wanted input from more experienced people.

Quoted 8 lines

How about prepending a 4 byte length on the host buffers? Allows host to specify length (for host->guest), and guest writes it to allow truncated buffers on guest->host.

That won't allow you to transfer *more* than one buffersize to the host, but you could use a different method (perhaps the 4 bytes indicates the *total* length?).

I don't understand how this will help.

I looked at virtio_net's implemention with VIRTIO_NET_F_MRG_RXBUF, which seems like it could really help performance. The problems with that are:
1) virtio_net doesn't write the merged header's num_buffers field
2) virtio_net doesn't actually split packets in xmit

The problem with 1 is that one instance of virtio_net cannot talk to another, if they're using that feature. The sender never sets the field, so the receiver doesn't know how many buffers to expect.

I'm using two instances of virtio_net to talk to each other, rather than a special userspace implementation like lguest and kvm use. Is this a good approach?

The problem with 2 is that xmit may add the following to the
descriptors: (the network stack doesn't have to split the packet)

idx address len flags next

0   XXXXXXX   12     N    1
1   XXXXXXX 8000     -    2

With VIRTIO_NET_F_MRG_RXBUF, the other side's recv ring will look like the following:

idx address len flags next

0   YYYYYYY 4096     -    1
1   YYYYYYY 4096     -    2
2   YYYYYYY 4096     -    3

....

So how do we pair up buffers to do DMA? Do I munge the header from virtio_net to set the num_headers field, and split the 8000 bytes of data into two parts? (Giving 12 bytes in desc 0, 4096 bytes in desc 1, and 3904 bytes in desc 2)

The current implementation only handles something like the following, which would be an ARP:

xmit descriptors:
idx address len flags next

0   XXXXXXX   10     N    1
1   XXXXXXX   42     -    2

recv descriptors:
idx address len flags next

0   YYYYYYY   10     N    1
1   YYYYYYY 1518     -    2

....

Then the algorithm is simple, no munging necessary. All chains are the same length (2 entries) and the length of each buffer is suffient to handle the data. The network stack splits the packets into <= 1518 byte chunks for us (as long as MTU isn't changed).

Quoted 2 lines

Do 4-byte DMA's suck for some reason?

I don't think it would hurt much. Some of the fancier features might offset any overhead that is added.

Thanks, I appreciate the feedback.
Ira

#5 lore raw
In reply to Ira Snyder
Quoted 3 lines · Ira Snyder

Documentation/virtio-over-PCI.txt | 61 ++
arch/powerpc/boot/dts/mpc834x_mds.dts | 7 +

we'll have to review the .dts and expect a documentation update for the node. But that's pretty minor at this point.

Quoted 5 lines
drivers/virtio/Kconfig                |   22 +
drivers/virtio/Makefile               |    2 +
drivers/virtio/vop.h                  |  119 ++
drivers/virtio/vop_fsl.c              | 1911 ++++++++++++++++++++++++ 

+++++++++

make this vop_fsl_mpc83xx.c or something along those lines.

Quoted 9 lines

drivers/virtio/vop_host.c | 1028 ++++++++++++++++++
drivers/virtio/vop_hw.h | 80 ++

8 files changed, 3230 insertions(+), 0 deletions(-)

create mode 100644 Documentation/virtio-over-PCI.txt create mode 100644 drivers/virtio/vop.h create mode 100644 drivers/virtio/vop_fsl.c create mode 100644 drivers/virtio/vop_host.c create mode 100644 drivers/virtio/vop_hw.h

- k

#10 lore raw
In reply to Ira Snyder
Quoted 12 lines

-----Original Message-----
From:
[email protected] [mailto:linuxppc-dev-bounces+tie-fei.zang=freescale.com@ozlabs .org] On Behalf Of Ira Snyder
Sent: Wednesday, February 18, 2009 6:24 AM
To: [email protected]
Cc: [email protected]; [email protected]; Rusty Russell; Arnd Bergmann; Jan-Bernd Themann
Subject: [RFC v1] virtio: add virtio-over-PCI driver

snip

Quoted 38 lines
drivers/virtio/Kconfig +6 -0
index 3dd6294..efcf56b 100644
@@ -33,3 +33,25 @@ config VIRTIO_BALLOON
 
 	 If unsure, say M.
 
+config VIRTIO_OVER_PCI_HOST
+	tristate "Virtio-over-PCI Host support (EXPERIMENTAL)"
+	depends on PCI && EXPERIMENTAL
+	select VIRTIO
+	---help---
+	  This driver provides the host support necessary for 

using virtio

drivers/virtio/Kconfig +1 -0
+	  over the PCI bus with a Freescale MPC8349EMDS 

evaluation board.

drivers/virtio/Kconfig +11 -0
+
+	  If unsure, say N.
+
+config VIRTIO_OVER_PCI_FSL
+	tristate "Virtio-over-PCI Guest support (EXPERIMENTAL)"
+	depends on MPC834x_MDS && EXPERIMENTAL
+	select VIRTIO
+	select DMA_ENGINE
+	select FSL_DMA
+	---help---
+	  This driver provides the guest support necessary for 

using virtio

drivers/virtio/Kconfig +4 -0
+	  over the PCI bus.
+
+	  If unsure, say N.
+
drivers/virtio/Makefile +0 -0
index 6738c44..f31afaa 100644

drivers/virtio/Makefile obj-$(CONFIG_VIRTIO) += virtio.o · line 6

Quoted 5 lines
drivers/virtio/Makefile +2 -0
@@ -2,3 +2,5 @@ obj-$(CONFIG_VIRTIO) += virtio.o
 obj-$(CONFIG_VIRTIO_RING) += virtio_ring.o
 obj-$(CONFIG_VIRTIO_PCI) += virtio_pci.o
 obj-$(CONFIG_VIRTIO_BALLOON) += virtio_balloon.o
+obj-$(CONFIG_VIRTIO_OVER_PCI_HOST) += vop_host.o
+obj-$(CONFIG_VIRTIO_OVER_PCI_FSL) += vop_fsl.o

I suppose we need to build the kernel twice. one for vop_host (on host with pci enabled) and the
other is for vop_fsl ( on agent with pci disabled). Is it possible to build one image for both host and
agent. We do not scan the pci bus if the controller is configured to agent.

Also, is it possible to include mpc85xx architecture? They should be same.
There is some code for 85xx in Fresscale BSP.
http://www.bitshrine.org/gpp/linux-fsl-2.6.23-MPC8568MDS_PCI_Agent_PCIe_
EP_Drvier.patch
Roy

#6 lore raw
In reply to Kumar Gala

=20

Quoted 21 lines

-----Original Message-----
From:=20 [email protected]=20 [mailto:linuxppc-dev-bounces+tie-fei.zang=3Dfreescale.com@ozlabs .org] On Behalf Of Kumar Gala
Sent: Thursday, February 19, 2009 0:47 AM
To: Ira Snyder
Cc: Arnd Bergmann; Jan-Bernd Themann; [email protected];=20 Rusty Russell; [email protected]; [email protected]
Subject: Re: [RFC v1] virtio: add virtio-over-PCI driver =20
=20
On Feb 17, 2009, at 4:24 PM, Ira Snyder wrote:
=20

Quoted 3 lines

Documentation/virtio-over-PCI.txt | 61 ++
arch/powerpc/boot/dts/mpc834x_mds.dts | 7 +

=20
we'll have to review the .dts and expect a documentation update for =20 the node. But that's pretty minor at this point.
=20

Quoted 8 lines
Quoted 4 lines
drivers/virtio/Kconfig                |   22 +
drivers/virtio/Makefile               |    2 +
drivers/virtio/vop.h                  |  119 ++
drivers/virtio/vop_fsl.c              | 1911=20

++++++++++++++++++++++++=20

Quoted 1 line

+++++++++

=20
make this vop_fsl_mpc83xx.c or something along those lines.

why?
Roy

#3 lore raw
In reply to Ira Snyder
Quoted 6 lines · On Thursday 19 February 2009 03:08:35 Ira Snyder wrote:
Quoted 2 lines · Rusty Russell

don't restrict yourself to 32 feature bits (only PCI does this, and they're going to have to hack when we reach feature 32).

There isn't any problem adding more feature bits. Do you think 128 bits is enough?

Probably. We have unlimited bits in lguest and s390, but 128 is reasonable for the forseeable future (if not, you end up using bit 128 to mean "look somewhere else for the rest of the bits).

Quoted 14 lines
Quoted 7 lines

How about prepending a 4 byte length on the host buffers? Allows host to specify length (for host->guest), and guest writes it to allow truncated buffers on guest->host.

That won't allow you to transfer *more* than one buffersize to the host, but you could use a different method (perhaps the 4 bytes indicates the *total* length?).

I don't understand how this will help.

I looked at virtio_net's implemention with VIRTIO_NET_F_MRG_RXBUF, which seems like it could really help performance. The problems with that are:
1) virtio_net doesn't write the merged header's num_buffers field
2) virtio_net doesn't actually split packets in xmit

...

Quoted 3 lines

I'm using two instances of virtio_net to talk to each other, rather than a special userspace implementation like lguest and kvm use. Is this a good approach?

Well, virtio in general is guest-host asymmetric. I originally explored symmetry, but it didn't seem to offer any concrete advantages, so we didn't require it. You aren't actually directly connecting two guests, are you? So this is just a simplification for your implementation?

You could always add a VIRTIO_NET_F_MRG_TXBUF which did what you want, but note that symmetry breaks down for other virtio uses, too: block definitely isn't symmetric of course, but I haven't audited the others.

So I'd recommend asymmetry; hack your host to understand chained buffers.

Cheers,
Rusty.

author
#11 lore raw
In reply to Zang Roy-R61911
Quoted 54 lines · On Thu, Feb 19, 2009 at 02:10:08PM +0800, Zang Roy-R61911 wrote:
Quoted 12 lines

-----Original Message-----
From:
[email protected] [mailto:linuxppc-dev-bounces+tie-fei.zang=freescale.com@ozlabs .org] On Behalf Of Ira Snyder
Sent: Wednesday, February 18, 2009 6:24 AM
To: [email protected]
Cc: [email protected]; [email protected]; Rusty Russell; Arnd Bergmann; Jan-Bernd Themann
Subject: [RFC v1] virtio: add virtio-over-PCI driver

snip

Quoted 41 lines
drivers/virtio/Kconfig +6 -0
index 3dd6294..efcf56b 100644
@@ -33,3 +33,25 @@ config VIRTIO_BALLOON
 
 	 If unsure, say M.
 
+config VIRTIO_OVER_PCI_HOST
+	tristate "Virtio-over-PCI Host support (EXPERIMENTAL)"
+	depends on PCI && EXPERIMENTAL
+	select VIRTIO
+	---help---
+	  This driver provides the host support necessary for 

using virtio

drivers/virtio/Kconfig +1 -0
+	  over the PCI bus with a Freescale MPC8349EMDS 

evaluation board.

drivers/virtio/Kconfig +11 -0
+
+	  If unsure, say N.
+
+config VIRTIO_OVER_PCI_FSL
+	tristate "Virtio-over-PCI Guest support (EXPERIMENTAL)"
+	depends on MPC834x_MDS && EXPERIMENTAL
+	select VIRTIO
+	select DMA_ENGINE
+	select FSL_DMA
+	---help---
+	  This driver provides the guest support necessary for 

using virtio

drivers/virtio/Kconfig +4 -0
+	  over the PCI bus.
+
+	  If unsure, say N.
+
drivers/virtio/Makefile +0 -0
index 6738c44..f31afaa 100644
@@ -2,3 +2,5 @@ obj-$(CONFIG_VIRTIO) += virtio.o
 obj-$(CONFIG_VIRTIO_RING) += virtio_ring.o
 obj-$(CONFIG_VIRTIO_PCI) += virtio_pci.o
 obj-$(CONFIG_VIRTIO_BALLOON) += virtio_balloon.o
Quoted 9 lines

drivers/virtio/Makefile obj-$(CONFIG_VIRTIO) += virtio.o · line 6

Quoted 2 lines
drivers/virtio/Makefile +2 -0
+obj-$(CONFIG_VIRTIO_OVER_PCI_HOST) += vop_host.o
+obj-$(CONFIG_VIRTIO_OVER_PCI_FSL) += vop_fsl.o

I suppose we need to build the kernel twice. one for vop_host (on host with pci enabled) and the
other is for vop_fsl ( on agent with pci disabled). Is it possible to build one image for both host and
agent. We do not scan the pci bus if the controller is configured to agent.

You should be able to build a kernel with support for both host and guest operation, and then use the device tree to switch which driver you get. The host driver won't be used without a PCI bus, and the guest driver won't be used without the message unit.

Quoted 5 lines

Also, is it possible to include mpc85xx architecture? They should be same.
There is some code for 85xx in Fresscale BSP.
http://www.bitshrine.org/gpp/linux-fsl-2.6.23-MPC8568MDS_PCI_Agent_PCIe_
EP_Drvier.patch

I looked at the cardnet driver before I implemented my PCINet driver. I hunch it would be rejected for the same reasons, but maybe not. Also, it makes no use of DMA, which is critical for good transfer speed. Using memcpy() in PCINet gives performance around 10 mbit/sec, which is terrible.

I'm sure the driver isn't very hard to port to 85xx, I just don't have any 85xx boards to test with. The driver only directly interacts with the messaging unit, which is a pretty simple piece of hardware.

Thanks,
Ira

author
#4 lore raw
In reply to Rusty Russell
Quoted 5 lines · Rusty Russell
Quoted 4 lines · On Thursday 19 February 2009 03:08:35 Ira Snyder wrote:
Quoted 2 lines · Rusty Russell

don't restrict yourself to 32 feature bits (only PCI does this, and they're going to have to hack when we reach feature 32).

Quoted 7 lines
Quoted 2 lines

There isn't any problem adding more feature bits. Do you think 128 bits is enough?

Probably. We have unlimited bits in lguest and s390, but 128 is reasonable for the forseeable future (if not, you end up using bit 128 to mean "look somewhere else for the rest of the bits).

Ok. There currently isn't an interface to access more than 32 bits anyway.

Quoted 15 lines
Quoted 14 lines
Quoted 7 lines

How about prepending a 4 byte length on the host buffers? Allows host to specify length (for host->guest), and guest writes it to allow truncated buffers on guest->host.

That won't allow you to transfer *more* than one buffersize to the host, but you could use a different method (perhaps the 4 bytes indicates the *total* length?).

I don't understand how this will help.

I looked at virtio_net's implemention with VIRTIO_NET_F_MRG_RXBUF, which seems like it could really help performance. The problems with that are:
1) virtio_net doesn't write the merged header's num_buffers field
2) virtio_net doesn't actually split packets in xmit

...

Quoted 9 lines
Quoted 3 lines

I'm using two instances of virtio_net to talk to each other, rather than a special userspace implementation like lguest and kvm use. Is this a good approach?

Well, virtio in general is guest-host asymmetric. I originally explored symmetry, but it didn't seem to offer any concrete advantages, so we didn't require it. You aren't actually directly connecting two guests, are you? So this is just a simplification for your implementation?

I'm not connecting two guests directly. My eventual setup will have a single x86 computer (the host) and many guest systems. I don't care if the guests cannot communicate between each other, just that they can communicate with the host.

I wanted to avoid the extra trip to userspace, so I just connected two instances of virtio_net together. This way you just recv packets in the kernel, rather than jumping to userspace and then using TAP/TUN to drive packets back into the kernel. Plus, I have no idea how I would do a userspace interface. I'd definitely need help.

Quoted 4 lines

You could always add a VIRTIO_NET_F_MRG_TXBUF which did what you want, but note that symmetry breaks down for other virtio uses, too: block definitely isn't symmetric of course, but I haven't audited the others.

I have no need to use virtio_blk, so I pretty much ignored it. In fact, I didn't make any attempt to support RO and WO buffers in the same queue. Virtio_net only uses queues this way, and it was much easier for me to wrap my head around.

I don't think that virtio_console is symmetric either, but I haven't really studied it. I was thinking about implementing a virtio_uart which would be symmetric. That would be plenty for my needs.

Quoted 2 lines

So I'd recommend asymmetry; hack your host to understand chained buffers.

It's not that virtio_net doesn't understand chained buffers, it just doesn't write them. Grep for uses of the num_buffers field in virtio_net. It uses them in recv, it just doesn't write them in xmit.

It assumes that add_buf() can accept something like:
idx address len flags next

0   XXXXXXX   12     N    1
1   XXXXXXX 8000     -    2

That would mean it can shove an 8000 byte packet into the virtqueue. It doesn't have any way of knowing to split packets up into chunks, nor how many chunks are available. It assumes that the receiver can read from any address on the sender.

I think that this is a perfectly reasonable assumption in a shared memory system, but it breaks down in my case. I cannot just tell the host "the packet data is at this address" because it cannot do DMA. I have to use the guest system to do DMA. The host has to have pre-allocated the recv memory so the DMA engine has somewhere to copy the data to.

Maybe I'm explaining this poorly, but try to think about it this way:
1) Unlike a virtual machine, both systems are NOT sharing memory
2) Both systems have some limited access to each other's memory
3) Both systems can write descriptors equally fast
4) Copying payload data is extremely slow for the host
5) Copying payload data is extremely fast for the guest

It would be possible to just alter virtio_net's headers in-flight to set the number of buffers actually used. This would split the 8000 byte packet up into two chunks, 4096 byte and 3904 byte, then set num_buffers to 2. This would add some complexity, but I think it is probably reasonable.

Ira

#7 lore raw
In reply to Zang Roy-R61911
Quoted 27 lines · On Feb 19, 2009, at 12:13 AM, Zang Roy-R61911 wrote:
Quoted 27 lines

-----Original Message-----
From:
[email protected] [mailto:linuxppc-dev-bounces+tie-fei.zang=freescale.com@ozlabs .org] On Behalf Of Kumar Gala
Sent: Thursday, February 19, 2009 0:47 AM
To: Ira Snyder
Cc: Arnd Bergmann; Jan-Bernd Themann; [email protected]; Rusty Russell; [email protected]; [email protected]
Subject: Re: [RFC v1] virtio: add virtio-over-PCI driver

Quoted 3 lines · Ira Snyder

Documentation/virtio-over-PCI.txt | 61 ++
arch/powerpc/boot/dts/mpc834x_mds.dts | 7 +

we'll have to review the .dts and expect a documentation update for the node. But that's pretty minor at this point.

Quoted 4 lines
drivers/virtio/Kconfig                |   22 +
drivers/virtio/Makefile               |    2 +
drivers/virtio/vop.h                  |  119 ++
drivers/virtio/vop_fsl.c              | 1911
Quoted 5 lines
Quoted 4 lines

++++++++++++++++++++++++

Quoted 1 line

+++++++++

make this vop_fsl_mpc83xx.c or something along those lines.

why?

so we can deal with 85xx as well. We just need to isolate the 83xx specific bits (message usage)

- k

author
#8 lore raw
Quoted 30 lines · Kumar Gala
Quoted 27 lines · On Feb 19, 2009, at 12:13 AM, Zang Roy-R61911 wrote:
Quoted 27 lines

-----Original Message-----
From:
[email protected] [mailto:linuxppc-dev-bounces+tie-fei.zang=freescale.com@ozlabs .org] On Behalf Of Kumar Gala
Sent: Thursday, February 19, 2009 0:47 AM
To: Ira Snyder
Cc: Arnd Bergmann; Jan-Bernd Themann; [email protected]; Rusty Russell; [email protected]; [email protected]
Subject: Re: [RFC v1] virtio: add virtio-over-PCI driver

Quoted 3 lines · Ira Snyder

Documentation/virtio-over-PCI.txt | 61 ++
arch/powerpc/boot/dts/mpc834x_mds.dts | 7 +

we'll have to review the .dts and expect a documentation update for the node. But that's pretty minor at this point.

Quoted 4 lines
drivers/virtio/Kconfig                |   22 +
drivers/virtio/Makefile               |    2 +
drivers/virtio/vop.h                  |  119 ++
drivers/virtio/vop_fsl.c              | 1911
Quoted 9 lines
Quoted 5 lines
Quoted 4 lines

++++++++++++++++++++++++

Quoted 1 line

+++++++++

make this vop_fsl_mpc83xx.c or something along those lines.

why?

so we can deal with 85xx as well. We just need to isolate the 83xx specific bits (message usage)

In fact, most of the driver has nothing to do with hardware, and everything to do with managing memory.

Most of the driver could be shared between implementations. The only things that would be hardware specific are setting up the descriptor memory, and raising/handling interrupts.

I just wanted to get something working and out here to discuss. I figured that more hardware support, features, etc. could come later. Just like everything else in the kernel, I'm sure this will have to evolve over time as well.

Thanks,
Ira

#12 lore raw
In reply to Ira Snyder

=20

Quoted 74 lines

-----Original Message-----
From: Ira Snyder [mailto:[email protected]]=20
Sent: Friday, February 20, 2009 0:15 AM
To: Zang Roy-R61911
Cc: [email protected]; [email protected];=20 [email protected]; Rusty Russell; Arnd Bergmann;=20 Jan-Bernd Themann
Subject: Re: [RFC v1] virtio: add virtio-over-PCI driver =20

Quoted 49 lines · On Thu, Feb 19, 2009 at 02:10:08PM +0800, Zang Roy-R61911 wrote:

=20
=20

Quoted 10 lines

-----Original Message-----
From:=20 [email protected]=20 [mailto:linuxppc-dev-bounces+tie-fei.zang=3Dfreescale.com@ozlabs .org] On Behalf Of Ira Snyder
Sent: Wednesday, February 18, 2009 6:24 AM
To: [email protected]
Cc: [email protected]; [email protected]; Rusty=20 Russell; Arnd Bergmann; Jan-Bernd Themann
Subject: [RFC v1] virtio: add virtio-over-PCI driver

snip

Quoted 36 lines
drivers/virtio/Kconfig +0 -0
index 3dd6294..efcf56b 100644
@@ -33,3 +33,25 @@ config VIRTIO_BALLOON

=20
If unsure, say M.
=20

drivers/virtio/Kconfig +6 -0
+config VIRTIO_OVER_PCI_HOST
+	tristate "Virtio-over-PCI Host support (EXPERIMENTAL)"
+	depends on PCI && EXPERIMENTAL
+	select VIRTIO
+	---help---
+	  This driver provides the host support necessary for=20

using virtio

drivers/virtio/Kconfig +1 -0
+	  over the PCI bus with a Freescale MPC8349EMDS=20

evaluation board.

drivers/virtio/Kconfig +11 -0
+
+	  If unsure, say N.
+
+config VIRTIO_OVER_PCI_FSL
+	tristate "Virtio-over-PCI Guest support (EXPERIMENTAL)"
+	depends on MPC834x_MDS && EXPERIMENTAL
+	select VIRTIO
+	select DMA_ENGINE
+	select FSL_DMA
+	---help---
+	  This driver provides the guest support necessary for=20

using virtio

drivers/virtio/Kconfig +4 -0
+	  over the PCI bus.
+
+	  If unsure, say N.
+
drivers/virtio/Makefile +0 -1
index 6738c44..f31afaa 100644
--- a/drivers/virtio/Makefile
Quoted 8 lines

drivers/virtio/Makefile obj-$(CONFIG_VIRTIO) +=3D virtio.o · line 6

Quoted 7 lines

+++ b/drivers/virtio/Makefile

drivers/virtio/Makefile +2 -0
@@ -2,3 +2,5 @@ obj-$(CONFIG_VIRTIO) +=3D virtio.o
 obj-$(CONFIG_VIRTIO_RING) +=3D virtio_ring.o
 obj-$(CONFIG_VIRTIO_PCI) +=3D virtio_pci.o
 obj-$(CONFIG_VIRTIO_BALLOON) +=3D virtio_balloon.o
+obj-$(CONFIG_VIRTIO_OVER_PCI_HOST) +=3D vop_host.o
+obj-$(CONFIG_VIRTIO_OVER_PCI_FSL) +=3D vop_fsl.o

I suppose we need to build the kernel twice. one for=20

vop_host (on host

Quoted 2 lines

with pci enabled) and the
other is for vop_fsl ( on agent with pci disabled). Is it=20

possible to

Quoted 2 lines

build one image for both host and=20
agent. We do not scan the pci bus if the controller is=20

configured to

Quoted 8 lines
Quoted 2 lines

agent.
=20

=20
You should be able to build a kernel with support for both host and guest operation, and then use the device tree to switch which=20 driver you
get. The host driver won't be used without a PCI bus, and the guest driver won't be used without the message unit.

Good.
Is it necssary to commit a extra dts for the agent mode? or just document it?

Quoted 5 lines

=20

Quoted 4 lines

Also, is it possible to include mpc85xx architecture? They should be same.
There is some code for 85xx in Fresscale BSP.
=20

Quoted 8 lines

http://www.bitshrine.org/gpp/linux-fsl-2.6.23-MPC8568MDS_PCI_A
gent_PCIe_

Quoted 1 line

EP_Drvier.patch

=20
I looked at the cardnet driver before I implemented my PCINet=20 driver. I
hunch it would be rejected for the same reasons, but maybe=20 not.=20

That is also our concern :-(

Quoted 4 lines

Also, it
makes no use of DMA, which is critical for good transfer speed. Using memcpy() in PCINet gives performance around 10 mbit/sec, which is terrible.

I can see your improvement for performance.

Quoted 4 lines

=20
I'm sure the driver isn't very hard to port to 85xx, I just don't have any 85xx boards to test with. The driver only directly interacts with the messaging unit, which is a pretty simple piece of hardware.

No matter. It is OK to just support 83xx boards currently. 85xx baords can be dealed with later.
Finally, I hope this driver can support 83xx /85xx boards pci and pci express mode.
Roy

#9 lore raw
In reply to Kumar Gala
Quoted 42 lines

-----Original Message-----
From: Kumar Gala [mailto:[email protected]]
Sent: Friday, February 20, 2009 0:52 AM
To: Zang Roy-R61911
Cc: Ira Snyder; Arnd Bergmann; Jan-Bernd Themann; [email protected]; Rusty Russell; [email protected]; [email protected]
Subject: Re: [RFC v1] virtio: add virtio-over-PCI driver

Quoted 11 lines · On Feb 19, 2009, at 12:13 AM, Zang Roy-R61911 wrote:
Quoted 11 lines

-----Original Message-----
From:
[email protected] [mailto:linuxppc-dev-bounces+tie-fei.zang=freescale.com@ozlabs .org] On Behalf Of Kumar Gala
Sent: Thursday, February 19, 2009 0:47 AM
To: Ira Snyder
Cc: Arnd Bergmann; Jan-Bernd Themann; [email protected]; Rusty Russell; [email protected];

[email protected]

Quoted 16 lines
Quoted 16 lines

Subject: Re: [RFC v1] virtio: add virtio-over-PCI driver

Quoted 3 lines · Ira Snyder

Documentation/virtio-over-PCI.txt | 61 ++
arch/powerpc/boot/dts/mpc834x_mds.dts | 7 +

we'll have to review the .dts and expect a documentation update for the node. But that's pretty minor at this point.

Quoted 4 lines
drivers/virtio/Kconfig                |   22 +
drivers/virtio/Makefile               |    2 +
drivers/virtio/vop.h                  |  119 ++
drivers/virtio/vop_fsl.c              | 1911
Quoted 7 lines
Quoted 5 lines
Quoted 4 lines

++++++++++++++++++++++++

Quoted 1 line

+++++++++

make this vop_fsl_mpc83xx.c or something along those lines.

why?

so we can deal with 85xx as well.

After some modificaiton, the driver should be used on 85xx. For 85xx, most of the cases are for pci express.

Quoted 2 lines

We just need to isolate the 83xx
specific bits (message usage)

Yes.
Roy