<?xml version="1.0" encoding="UTF-8"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://purl.org/rss/1.0/" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:syn="http://purl.org/rss/1.0/modules/syndication/" xmlns:admin="http://webns.net/mvcb/">
  <channel rdf:about="http://blog.gmane.org/gmane.comp.emulators.kvm.devel">
    <title>gmane.comp.emulators.kvm.devel</title>
    <link>http://blog.gmane.org/gmane.comp.emulators.kvm.devel</link>
    <description/>
    <syn:updatePeriod>hourly</syn:updatePeriod>
    <syn:updateFrequency>1</syn:updateFrequency>
    <syn:updateBase>1901-01-01T00:00+00:00</syn:updateBase>
    <items>
      <rdf:Seq>
        <rdf:li rdf:resource="http://comments.gmane.org/gmane.comp.emulators.kvm.devel/25548"/>
        <rdf:li rdf:resource="http://comments.gmane.org/gmane.comp.emulators.kvm.devel/25545"/>
        <rdf:li rdf:resource="http://comments.gmane.org/gmane.comp.emulators.kvm.devel/25544"/>
        <rdf:li rdf:resource="http://comments.gmane.org/gmane.comp.emulators.kvm.devel/25538"/>
        <rdf:li rdf:resource="http://comments.gmane.org/gmane.comp.emulators.kvm.devel/25534"/>
        <rdf:li rdf:resource="http://comments.gmane.org/gmane.comp.emulators.kvm.devel/25527"/>
        <rdf:li rdf:resource="http://comments.gmane.org/gmane.comp.emulators.kvm.devel/25519"/>
        <rdf:li rdf:resource="http://comments.gmane.org/gmane.comp.emulators.kvm.devel/25517"/>
        <rdf:li rdf:resource="http://comments.gmane.org/gmane.comp.emulators.kvm.devel/25516"/>
        <rdf:li rdf:resource="http://comments.gmane.org/gmane.comp.emulators.kvm.devel/25506"/>
        <rdf:li rdf:resource="http://comments.gmane.org/gmane.comp.emulators.kvm.devel/25492"/>
        <rdf:li rdf:resource="http://comments.gmane.org/gmane.comp.emulators.kvm.devel/25475"/>
        <rdf:li rdf:resource="http://comments.gmane.org/gmane.comp.emulators.kvm.devel/25471"/>
        <rdf:li rdf:resource="http://comments.gmane.org/gmane.comp.emulators.kvm.devel/25468"/>
        <rdf:li rdf:resource="http://comments.gmane.org/gmane.comp.emulators.kvm.devel/25467"/>
        <rdf:li rdf:resource="http://comments.gmane.org/gmane.comp.emulators.kvm.devel/25466"/>
        <rdf:li rdf:resource="http://comments.gmane.org/gmane.comp.emulators.kvm.devel/25465"/>
        <rdf:li rdf:resource="http://comments.gmane.org/gmane.comp.emulators.kvm.devel/25464"/>
        <rdf:li rdf:resource="http://comments.gmane.org/gmane.comp.emulators.kvm.devel/25463"/>
        <rdf:li rdf:resource="http://comments.gmane.org/gmane.comp.emulators.kvm.devel/25462"/>
      </rdf:Seq>
    </items>
    <image rdf:resource="http://gmane.org/img/gmane-25t.png"/>
    <textinput rdf:resource=""/>
  </channel>
  <image rdf:about="http://gmane.org/img/gmane-25t.png">
    <title>Gmane</title>
    <url>http://gmane.org/img/gmane-25t.png</url>
    <link>http://gmane.org</link>
  </image>
  <item rdf:about="http://comments.gmane.org/gmane.comp.emulators.kvm.devel/25548">
    <title>[ kvm-Bugs-2386363 ] virtio-net doesn't set vc-&gt;info_str</title>
    <link>http://comments.gmane.org/gmane.comp.emulators.kvm.devel/25548</link>
    <description>Bugs item #2386363, was opened at 2008-12-03 19:43
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&amp;atid=893831&amp;aid=2386363&amp;group_id=180599

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: qemu
Group: None
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: Nolan (sf-nolan)
Assigned to: Nobody/Anonymous (nobody)
Summary: virtio-net doesn't set vc-&gt;info_str

Initial Comment:
Which makes "info network" not show the devices, which makes it difficult to figure out what NIC model a running VM is using via the monitor.

The fix is simple, just add the following to virtio-net.c::virtio_net_init right after the call to qemu_new_vlan_client:
 snprintf(n-&gt;vc-&gt;info_str, sizeof(n-&gt;vc-&gt;info_str),
          "%s macaddr=%02x:%02x:%02x:%02x:%02x:%02x", "virtio",
          n-&gt;nd-&gt;macaddr[0], n-&gt;nd-&gt;macaddr[1], n-&gt;nd-&gt;macaddr[2],
          n-&gt;nd-&gt;macaddr[3], n-&gt;nd-&gt;macaddr[4], n-&gt;nd-&gt;macaddr[5]);
Note that the string should probably be "virtio" not "virtio-net" so that it matches the model= command line parameter.

Ideally all of this should be factored up into qemu's generic network code, but the trivial change above at least brings virtio-net to parity with all the other NIC models.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&amp;atid=893831&amp;aid=2386363&amp;group_id=180599
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo&lt; at &gt;vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

</description>
    <dc:creator>SourceForge.net</dc:creator>
    <dc:date>2008-12-04T03:43:34</dc:date>
  </item>
  <item rdf:about="http://comments.gmane.org/gmane.comp.emulators.kvm.devel/25545">
    <title>[PATCH] Use guards in virtio-net for easier upstream merging</title>
    <link>http://comments.gmane.org/gmane.comp.emulators.kvm.devel/25545</link>
    <description>This gets virtio-net into an upstream acceptable state.  This includes
introducing USE_KVM guards for IO thread notification (where did
qemu_service_io() go?).  It also includes introducing TAP_VNET_HDR which is for
code that relies on the tap vnet support that is not currently in upstream QEMU.

Finally, it drops packets if not ready to receive.  This is unnecessary in
kvm-userspace but necessary in QEMU.

Signed-off-by: Anthony Liguori &lt;aliguori&lt; at &gt;us.ibm.com&gt;

diff --git a/qemu/hw/virtio-net.c b/qemu/hw/virtio-net.c
index 6493ff6..b53feb3 100644
--- a/qemu/hw/virtio-net.c
+++ b/qemu/hw/virtio-net.c
&lt; at &gt;&lt; at &gt; -15,7 +15,11 &lt; at &gt;&lt; at &gt;
 #include "net.h"
 #include "qemu-timer.h"
 #include "virtio-net.h"
+#ifdef USE_KVM
 #include "qemu-kvm.h"
+#endif
+
+//#define TAP_VNET_HDR
 
 typedef struct VirtIONet
 {
&lt; at &gt;&lt; at &gt; -49,9 +53,10 &lt; at &gt;&lt; at &gt; static void virtio_net_update_config(VirtIODevice *vdev, uint8_t *config)
 
 static uint32_t virtio_net_get_features(VirtIODevice *vdev)
 {
+    uint32_t features = (1 &lt;&lt; VIRTIO_NET_F_MAC);
+#ifdef TAP_VNET_HDR
     VirtIONet *n = to_virtio_net(vdev);
     VLANClientState *host = n-&gt;vc-&gt;vlan-&gt;first_client;
-    uint32_t features = (1 &lt;&lt; VIRTIO_NET_F_MAC);
 
     if (tap_has_vnet_hdr(host)) {
         tap_using_vnet_hdr(host, 1);
&lt; at &gt;&lt; at &gt; -66,6 +71,7 &lt; at &gt;&lt; at &gt; static uint32_t virtio_net_get_features(VirtIODevice *vdev)
         features |= (1 &lt;&lt; VIRTIO_NET_F_MRG_RXBUF);
         /* Kernel can't actually handle UFO in software currently. */
     }
+#endif
 
     return features;
 }
&lt; at &gt;&lt; at &gt; -73,10 +79,13 &lt; at &gt;&lt; at &gt; static uint32_t virtio_net_get_features(VirtIODevice *vdev)
 static void virtio_net_set_features(VirtIODevice *vdev, uint32_t features)
 {
     VirtIONet *n = to_virtio_net(vdev);
+#ifdef TAP_VNET_HDR
     VLANClientState *host = n-&gt;vc-&gt;vlan-&gt;first_client;
+#endif
 
     n-&gt;mergeable_rx_bufs = !!(features &amp; (1 &lt;&lt; VIRTIO_NET_F_MRG_RXBUF));
 
+#ifdef TAP_VNET_HDR
     if (!tap_has_vnet_hdr(host) || !host-&gt;set_offload)
         return;
 
&lt; at &gt;&lt; at &gt; -85,16 +94,19 &lt; at &gt;&lt; at &gt; static void virtio_net_set_features(VirtIODevice *vdev, uint32_t features)
                       (features &gt;&gt; VIRTIO_NET_F_GUEST_TSO4) &amp; 1,
                       (features &gt;&gt; VIRTIO_NET_F_GUEST_TSO6) &amp; 1,
                       (features &gt;&gt; VIRTIO_NET_F_GUEST_ECN)  &amp; 1);
+#endif
 }
 
 /* RX */
 
 static void virtio_net_handle_rx(VirtIODevice *vdev, VirtQueue *vq)
 {
+#ifdef USE_KVM
     /* We now have RX buffers, signal to the IO thread to break out of the
        select to re-poll the tap file descriptor */
     if (kvm_enabled())
         qemu_kvm_notify_work();
+#endif
 }
 
 static int virtio_net_can_receive(void *opaque)
&lt; at &gt;&lt; at &gt; -116,6 +128,7 &lt; at &gt;&lt; at &gt; static int virtio_net_can_receive(void *opaque)
     return 1;
 }
 
+#ifdef TAP_VNET_HDR
 /* dhclient uses AF_PACKET but doesn't pass auxdata to the kernel so
  * it never finds out that the packets don't have valid checksums.  This
  * causes dhclient to get upset.  Fedora's carried a patch for ages to
&lt; at &gt;&lt; at &gt; -143,6 +156,7 &lt; at &gt;&lt; at &gt; static void work_around_broken_dhclient(struct virtio_net_hdr *hdr,
         hdr-&gt;flags &amp;= ~VIRTIO_NET_HDR_F_NEEDS_CSUM;
     }
 }
+#endif
 
 static int iov_fill(struct iovec *iov, int iovcnt, const void *buf, int count)
 {
&lt; at &gt;&lt; at &gt; -168,11 +182,13 &lt; at &gt;&lt; at &gt; static int receive_header(VirtIONet *n, struct iovec *iov, int iovcnt,
     hdr-&gt;flags = 0;
     hdr-&gt;gso_type = VIRTIO_NET_HDR_GSO_NONE;
 
+#ifdef TAP_VNET_HDR
     if (tap_has_vnet_hdr(n-&gt;vc-&gt;vlan-&gt;first_client)) {
         memcpy(hdr, buf, sizeof(*hdr));
         offset = sizeof(*hdr);
         work_around_broken_dhclient(hdr, buf + offset, size - offset);
     }
+#endif
 
     /* We only ever receive a struct virtio_net_hdr from the tapfd,
      * but we may be passing along a larger header to the guest.
&lt; at &gt;&lt; at &gt; -189,6 +205,9 &lt; at &gt;&lt; at &gt; static void virtio_net_receive(void *opaque, const uint8_t *buf, int size)
     struct virtio_net_hdr_mrg_rxbuf *mhdr = NULL;
     int hdr_len, offset, i;
 
+    if (!virtio_net_can_receive(opaque))
+        return;
+
     /* hdr_len refers to the header we supply to the guest */
     hdr_len = n-&gt;mergeable_rx_bufs ?
         sizeof(struct virtio_net_hdr_mrg_rxbuf) : sizeof(struct virtio_net_hdr);
&lt; at &gt;&lt; at &gt; -253,7 +272,11 &lt; at &gt;&lt; at &gt; static void virtio_net_receive(void *opaque, const uint8_t *buf, int size)
 static void virtio_net_flush_tx(VirtIONet *n, VirtQueue *vq)
 {
     VirtQueueElement elem;
+#ifdef TAP_VNET_HDR
     int has_vnet_hdr = tap_has_vnet_hdr(n-&gt;vc-&gt;vlan-&gt;first_client);
+#else
+    int has_vnet_hdr = 0;
+#endif
 
     if (!(n-&gt;vdev.status &amp; VIRTIO_CONFIG_S_DRIVER_OK))
         return;
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo&lt; at &gt;vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

</description>
    <dc:creator>Anthony Liguori</dc:creator>
    <dc:date>2008-12-03T20:32:10</dc:date>
  </item>
  <item rdf:about="http://comments.gmane.org/gmane.comp.emulators.kvm.devel/25544">
    <title>[PATCH] Fix unitialized offset in virtio-net receive_header</title>
    <link>http://comments.gmane.org/gmane.comp.emulators.kvm.devel/25544</link>
    <description>If vnet support is not available on the tap device, offset is uninitialized and
badness ensues.

Signed-off-by: Anthony Liguori &lt;aliguori&lt; at &gt;us.ibm.com&gt;

diff --git a/qemu/hw/virtio-net.c b/qemu/hw/virtio-net.c
index b5d5f9e..4d7e6ad 100644
--- a/qemu/hw/virtio-net.c
+++ b/qemu/hw/virtio-net.c
&lt; at &gt;&lt; at &gt; -219,7 +219,7 &lt; at &gt;&lt; at &gt; static int receive_header(VirtIONet *n, struct iovec *iov, int iovcnt,
   const void *buf, int size, int hdr_len)
 {
     struct virtio_net_hdr *hdr = iov[0].iov_base;
-    int offset;
+    int offset = 0;
 
     hdr-&gt;flags = 0;
     hdr-&gt;gso_type = VIRTIO_NET_HDR_GSO_NONE;
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo&lt; at &gt;vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

</description>
    <dc:creator>Anthony Liguori</dc:creator>
    <dc:date>2008-12-03T20:27:06</dc:date>
  </item>
  <item rdf:about="http://comments.gmane.org/gmane.comp.emulators.kvm.devel/25538">
    <title>Virtio network performance problem</title>
    <link>http://comments.gmane.org/gmane.comp.emulators.kvm.devel/25538</link>
    <description>I'm having a problem with virtio networking. I mentioned this in a
previous thread, but I'm starting a new one since Dor solved the problem
I reported in the original thread. This appears to be a new problem.

Iperf shows throughput of ~120 Mb/s between a Windows Server 2003 x64
guest and the br0 interface on the host. Also, a ping between the same
two interfaces looks pretty bad:

Pinging 10.10.10.128 with 32 bytes of data:
Reply from 10.10.10.128: bytes=32 time=-389ms TTL=64
Reply from 10.10.10.128: bytes=32 time&lt;1ms TTL=64
Reply from 10.10.10.128: bytes=32 time=392ms TTL=64
Reply from 10.10.10.128: bytes=32 time=392ms TTL=64
Reply from 10.10.10.128: bytes=32 time=377ms TTL=64
Reply from 10.10.10.128: bytes=32 time=392ms TTL=64
Reply from 10.10.10.128: bytes=32 time&lt;1ms TTL=64
Reply from 10.10.10.128: bytes=32 time=401ms TTL=64
Reply from 10.10.10.128: bytes=32 time=1ms TTL=64

Using e1000 driver on this guest, iperf shows 320+ Mb/s throughput, and
latency looks like it should.

Host kernel:2.6.18
KVM Version:79 (modules and tools built and
installed from source)
Guest OS:   Win2k3 x64 with all service packs and
patches
Guest virtio drivers:Version 3 (received from Dor Laor
yesterday.. these fixed the guest OS crashes I was having with version
2)

Any suggestions are greatly appreciated. If there's additional info I
can provide, please let me know.
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo&lt; at &gt;vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

</description>
    <dc:creator>Adrian Schmitz</dc:creator>
    <dc:date>2008-12-03T19:11:45</dc:date>
  </item>
  <item rdf:about="http://comments.gmane.org/gmane.comp.emulators.kvm.devel/25534">
    <title>kvm-userspace ppc fixes</title>
    <link>http://comments.gmane.org/gmane.comp.emulators.kvm.devel/25534</link>
    <description>Hi Avi, among these patches are fixes for a number of bugs in kvm-userspace,
including the qemu build break and bugs in the "user" directory. Please apply.

-Hollis


--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo&lt; at &gt;vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

</description>
    <dc:creator>Hollis Blanchard</dc:creator>
    <dc:date>2008-12-03T19:07:26</dc:date>
  </item>
  <item rdf:about="http://comments.gmane.org/gmane.comp.emulators.kvm.devel/25527">
    <title>[PATCH 1/7] Fix whitespace in virtio</title>
    <link>http://comments.gmane.org/gmane.comp.emulators.kvm.devel/25527</link>
    <description>Whoever originally wrote the virtio code quite rudely didn't configure their
editor to use spaces instead of tabs.  This patch corrects this for all virtio
related files.

Signed-off-by: Anthony Liguori &lt;aliguori&lt; at &gt;us.ibm.com&gt;

diff --git a/qemu/hw/virtio-balloon.c b/qemu/hw/virtio-balloon.c
index 111f27d..9b34e87 100644
--- a/qemu/hw/virtio-balloon.c
+++ b/qemu/hw/virtio-balloon.c
&lt; at &gt;&lt; at &gt; -79,26 +79,26 &lt; at &gt;&lt; at &gt; static void virtio_balloon_handle_output(VirtIODevice *vdev, VirtQueue *vq)
     VirtQueueElement elem;
 
     while (virtqueue_pop(vq, &amp;elem)) {
-size_t offset = 0;
-uint32_t pfn;
+        size_t offset = 0;
+        uint32_t pfn;
 
-while (memcpy_from_iovector(&amp;pfn, offset, 4,
+        while (memcpy_from_iovector(&amp;pfn, offset, 4,
                                     elem.out_sg, elem.out_num) == 4) {
-    ram_addr_t pa;
-    ram_addr_t addr;
+            ram_addr_t pa;
+            ram_addr_t addr;
 
-    pa = (ram_addr_t)ldl_p(&amp;pfn) &lt;&lt; VIRTIO_BALLOON_PFN_SHIFT;
-    offset += 4;
+            pa = (ram_addr_t)ldl_p(&amp;pfn) &lt;&lt; VIRTIO_BALLOON_PFN_SHIFT;
+            offset += 4;
 
-    addr = cpu_get_physical_page_desc(pa);
-    if ((addr &amp; ~TARGET_PAGE_MASK) != IO_MEM_RAM)
-continue;
+            addr = cpu_get_physical_page_desc(pa);
+            if ((addr &amp; ~TARGET_PAGE_MASK) != IO_MEM_RAM)
+                continue;
 
-    balloon_page(phys_ram_base + addr, !!(vq == s-&gt;dvq));
-}
+            balloon_page(phys_ram_base + addr, !!(vq == s-&gt;dvq));
+        }
 
-virtqueue_push(vq, &amp;elem, offset);
-virtio_notify(vdev, vq);
+        virtqueue_push(vq, &amp;elem, offset);
+        virtio_notify(vdev, vq);
     }
 }
 
&lt; at &gt;&lt; at &gt; -114,7 +114,7 &lt; at &gt;&lt; at &gt; static void virtio_balloon_get_config(VirtIODevice *vdev, uint8_t *config_data)
 }
 
 static void virtio_balloon_set_config(VirtIODevice *vdev,
-      const uint8_t *config_data)
+                                      const uint8_t *config_data)
 {
     VirtIOBalloon *dev = to_virtio_balloon(vdev);
     struct virtio_balloon_config config;
&lt; at &gt;&lt; at &gt; -132,11 +132,11 &lt; at &gt;&lt; at &gt; static ram_addr_t virtio_balloon_to_target(void *opaque, ram_addr_t target)
     VirtIOBalloon *dev = opaque;
 
     if (target &gt; ram_size)
-target = ram_size;
+        target = ram_size;
 
     if (target) {
-dev-&gt;num_pages = (ram_size - target) &gt;&gt; VIRTIO_BALLOON_PFN_SHIFT;
-virtio_notify_config(&amp;dev-&gt;vdev);
+        dev-&gt;num_pages = (ram_size - target) &gt;&gt; VIRTIO_BALLOON_PFN_SHIFT;
+        virtio_notify_config(&amp;dev-&gt;vdev);
     }
 
     return ram_size - (dev-&gt;actual &lt;&lt; VIRTIO_BALLOON_PFN_SHIFT);
&lt; at &gt;&lt; at &gt; -172,10 +172,10 &lt; at &gt;&lt; at &gt; void *virtio_balloon_init(PCIBus *bus)
     VirtIOBalloon *s;
 
     s = (VirtIOBalloon *)virtio_init_pci(bus, "virtio-balloon",
- 6900, 0x1002,
- 0, VIRTIO_ID_BALLOON,
- 0x05, 0x00, 0x00,
- 8, sizeof(VirtIOBalloon));
+                                         6900, 0x1002,
+                                         0, VIRTIO_ID_BALLOON,
+                                         0x05, 0x00, 0x00,
+                                         8, sizeof(VirtIOBalloon));
     if (s == NULL)
         return NULL;
 
diff --git a/qemu/hw/virtio-balloon.h b/qemu/hw/virtio-balloon.h
index 0466a48..45e4b03 100644
--- a/qemu/hw/virtio-balloon.h
+++ b/qemu/hw/virtio-balloon.h
&lt; at &gt;&lt; at &gt; -18,10 +18,10 &lt; at &gt;&lt; at &gt;
 /* from Linux's linux/virtio_balloon.h */
 
 /* The ID for virtio_balloon */
-#define VIRTIO_ID_BALLOON5
+#define VIRTIO_ID_BALLOON 5
 
 /* The feature bitmap for virtio balloon */
-#define VIRTIO_BALLOON_F_MUST_TELL_HOST0 /* Tell before reclaiming pages */
+#define VIRTIO_BALLOON_F_MUST_TELL_HOST 0 /* Tell before reclaiming pages */
 
 /* Size of a PFN in the balloon interface. */
 #define VIRTIO_BALLOON_PFN_SHIFT 12
diff --git a/qemu/hw/virtio-blk.c b/qemu/hw/virtio-blk.c
index 727119b..c9a91ba 100644
--- a/qemu/hw/virtio-blk.c
+++ b/qemu/hw/virtio-blk.c
&lt; at &gt;&lt; at &gt; -19,13 +19,13 &lt; at &gt;&lt; at &gt;
 /* from Linux's linux/virtio_blk.h */
 
 /* The ID for virtio_block */
-#define VIRTIO_ID_BLOCK2
+#define VIRTIO_ID_BLOCK 2
 
 /* Feature bits */
-#define VIRTIO_BLK_F_BARRIER0/* Does host support barriers? */
-#define VIRTIO_BLK_F_SIZE_MAX1/* Indicates maximum segment size */
-#define VIRTIO_BLK_F_SEG_MAX2/* Indicates maximum # of segments */
-#define VIRTIO_BLK_F_GEOMETRY4/* Indicates support of legacy geometry */
+#define VIRTIO_BLK_F_BARRIER    0       /* Does host support barriers? */
+#define VIRTIO_BLK_F_SIZE_MAX   1       /* Indicates maximum segment size */
+#define VIRTIO_BLK_F_SEG_MAX    2       /* Indicates maximum # of segments */
+#define VIRTIO_BLK_F_GEOMETRY   4       /* Indicates support of legacy geometry */
 
 struct virtio_blk_config
 {
&lt; at &gt;&lt; at &gt; -38,14 +38,14 &lt; at &gt;&lt; at &gt; struct virtio_blk_config
 } __attribute__((packed));
 
 /* These two define direction. */
-#define VIRTIO_BLK_T_IN0
-#define VIRTIO_BLK_T_OUT1
+#define VIRTIO_BLK_T_IN         0
+#define VIRTIO_BLK_T_OUT        1
 
 /* This bit says it's a scsi command, not an actual read or write. */
-#define VIRTIO_BLK_T_SCSI_CMD2
+#define VIRTIO_BLK_T_SCSI_CMD   2
 
 /* Barrier before this op. */
-#define VIRTIO_BLK_T_BARRIER0x80000000
+#define VIRTIO_BLK_T_BARRIER    0x80000000
 
 /* This is the first element of the read scatter-gather list. */
 struct virtio_blk_outhdr
&lt; at &gt;&lt; at &gt; -58,9 +58,9 &lt; at &gt;&lt; at &gt; struct virtio_blk_outhdr
     uint64_t sector;
 };
 
-#define VIRTIO_BLK_S_OK0
-#define VIRTIO_BLK_S_IOERR1
-#define VIRTIO_BLK_S_UNSUPP2
+#define VIRTIO_BLK_S_OK         0
+#define VIRTIO_BLK_S_IOERR      1
+#define VIRTIO_BLK_S_UNSUPP     2
 
 /* This is the first element of the write scatter-gather list */
 struct virtio_blk_inhdr
&lt; at &gt;&lt; at &gt; -97,21 +97,21 &lt; at &gt;&lt; at &gt; static void virtio_blk_rw_complete(void *opaque, int ret)
 
     /* Copy read data to the guest */
     if (!ret &amp;&amp; !(req-&gt;out-&gt;type &amp; VIRTIO_BLK_T_OUT)) {
-size_t offset = 0;
-int i;
+        size_t offset = 0;
+        int i;
 
-for (i = 0; i &lt; req-&gt;elem.in_num - 1; i++) {
-    size_t len;
+        for (i = 0; i &lt; req-&gt;elem.in_num - 1; i++) {
+            size_t len;
 
-    /* Be pretty defensive wrt malicious guests */
-    len = MIN(req-&gt;elem.in_sg[i].iov_len,
-      req-&gt;size - offset);
+            /* Be pretty defensive wrt malicious guests */
+            len = MIN(req-&gt;elem.in_sg[i].iov_len,
+                      req-&gt;size - offset);
 
-    memcpy(req-&gt;elem.in_sg[i].iov_base,
-   req-&gt;buffer + offset,
-   len);
-    offset += len;
-}
+            memcpy(req-&gt;elem.in_sg[i].iov_base,
+                   req-&gt;buffer + offset,
+                   len);
+            offset += len;
+        }
     }
 
     req-&gt;in-&gt;status = ret ? VIRTIO_BLK_S_IOERR : VIRTIO_BLK_S_OK;
&lt; at &gt;&lt; at &gt; -128,12 +128,12 &lt; at &gt;&lt; at &gt; static VirtIOBlockReq *virtio_blk_get_request(VirtIOBlock *s)
 
     req = qemu_mallocz(sizeof(*req));
     if (req == NULL)
-return NULL;
+        return NULL;
 
     req-&gt;dev = s;
     if (!virtqueue_pop(s-&gt;vq, &amp;req-&gt;elem)) {
-qemu_free(req);
-return NULL;
+        qemu_free(req);
+        return NULL;
     }
 
     return req;
&lt; at &gt;&lt; at &gt; -145,76 +145,76 &lt; at &gt;&lt; at &gt; static void virtio_blk_handle_output(VirtIODevice *vdev, VirtQueue *vq)
     VirtIOBlockReq *req;
 
     while ((req = virtio_blk_get_request(s))) {
-int i;
-
-if (req-&gt;elem.out_num &lt; 1 || req-&gt;elem.in_num &lt; 1) {
-    fprintf(stderr, "virtio-blk missing headers\n");
-    exit(1);
-}
-
-if (req-&gt;elem.out_sg[0].iov_len &lt; sizeof(*req-&gt;out) ||
-    req-&gt;elem.in_sg[req-&gt;elem.in_num - 1].iov_len &lt; sizeof(*req-&gt;in)) {
-    fprintf(stderr, "virtio-blk header not in correct element\n");
-    exit(1);
-}
-
-req-&gt;out = (void *)req-&gt;elem.out_sg[0].iov_base;
-req-&gt;in = (void *)req-&gt;elem.in_sg[req-&gt;elem.in_num - 1].iov_base;
-
-if (req-&gt;out-&gt;type &amp; VIRTIO_BLK_T_SCSI_CMD) {
-    unsigned int len = sizeof(*req-&gt;in);
-
-    req-&gt;in-&gt;status = VIRTIO_BLK_S_UNSUPP;
-    virtqueue_push(vq, &amp;req-&gt;elem, len);
-    virtio_notify(vdev, vq);
-    qemu_free(req);
-} else if (req-&gt;out-&gt;type &amp; VIRTIO_BLK_T_OUT) {
-    size_t offset;
-
-    for (i = 1; i &lt; req-&gt;elem.out_num; i++)
-req-&gt;size += req-&gt;elem.out_sg[i].iov_len;
-
-    req-&gt;buffer = qemu_memalign(512, req-&gt;size);
-    if (req-&gt;buffer == NULL) {
-qemu_free(req);
-break;
-    }
-
-    /* We copy the data from the SG list to avoid splitting up the request.  This helps
-       performance a lot until we can pass full sg lists as AIO operations */
-    offset = 0;
-    for (i = 1; i &lt; req-&gt;elem.out_num; i++) {
-size_t len;
-
-len = MIN(req-&gt;elem.out_sg[i].iov_len,
-  req-&gt;size - offset);
-memcpy(req-&gt;buffer + offset,
-       req-&gt;elem.out_sg[i].iov_base,
-       len);
-offset += len;
-    }
-
-    bdrv_aio_write(s-&gt;bs, req-&gt;out-&gt;sector,
-   req-&gt;buffer,
-   req-&gt;size / 512,
-   virtio_blk_rw_complete,
-   req);
-} else {
-    for (i = 0; i &lt; req-&gt;elem.in_num - 1; i++)
-req-&gt;size += req-&gt;elem.in_sg[i].iov_len;
-
-    req-&gt;buffer = qemu_memalign(512, req-&gt;size);
-    if (req-&gt;buffer == NULL) {
-qemu_free(req);
-break;
-    }
-
-    bdrv_aio_read(s-&gt;bs, req-&gt;out-&gt;sector,
-  req-&gt;buffer,
-  req-&gt;size / 512,
-  virtio_blk_rw_complete,
-  req);
-}
+        int i;
+
+        if (req-&gt;elem.out_num &lt; 1 || req-&gt;elem.in_num &lt; 1) {
+            fprintf(stderr, "virtio-blk missing headers\n");
+            exit(1);
+        }
+
+        if (req-&gt;elem.out_sg[0].iov_len &lt; sizeof(*req-&gt;out) ||
+            req-&gt;elem.in_sg[req-&gt;elem.in_num - 1].iov_len &lt; sizeof(*req-&gt;in)) {
+            fprintf(stderr, "virtio-blk header not in correct element\n");
+            exit(1);
+        }
+
+        req-&gt;out = (void *)req-&gt;elem.out_sg[0].iov_base;
+        req-&gt;in = (void *)req-&gt;elem.in_sg[req-&gt;elem.in_num - 1].iov_base;
+
+        if (req-&gt;out-&gt;type &amp; VIRTIO_BLK_T_SCSI_CMD) {
+            unsigned int len = sizeof(*req-&gt;in);
+
+            req-&gt;in-&gt;status = VIRTIO_BLK_S_UNSUPP;
+            virtqueue_push(vq, &amp;req-&gt;elem, len);
+            virtio_notify(vdev, vq);
+            qemu_free(req);
+        } else if (req-&gt;out-&gt;type &amp; VIRTIO_BLK_T_OUT) {
+            size_t offset;
+
+            for (i = 1; i &lt; req-&gt;elem.out_num; i++)
+                req-&gt;size += req-&gt;elem.out_sg[i].iov_len;
+
+            req-&gt;buffer = qemu_memalign(512, req-&gt;size);
+            if (req-&gt;buffer == NULL) {
+                qemu_free(req);
+                break;
+            }
+
+            /* We copy the data from the SG list to avoid splitting up the request.  This helps
+               performance a lot until we can pass full sg lists as AIO operations */
+            offset = 0;
+            for (i = 1; i &lt; req-&gt;elem.out_num; i++) {
+                size_t len;
+
+                len = MIN(req-&gt;elem.out_sg[i].iov_len,
+                          req-&gt;size - offset);
+                memcpy(req-&gt;buffer + offset,
+                       req-&gt;elem.out_sg[i].iov_base,
+                       len);
+                offset += len;
+            }
+
+            bdrv_aio_write(s-&gt;bs, req-&gt;out-&gt;sector,
+                           req-&gt;buffer,
+                           req-&gt;size / 512,
+                           virtio_blk_rw_complete,
+                           req);
+        } else {
+            for (i = 0; i &lt; req-&gt;elem.in_num - 1; i++)
+                req-&gt;size += req-&gt;elem.in_sg[i].iov_len;
+
+            req-&gt;buffer = qemu_memalign(512, req-&gt;size);
+            if (req-&gt;buffer == NULL) {
+                qemu_free(req);
+                break;
+            }
+
+            bdrv_aio_read(s-&gt;bs, req-&gt;out-&gt;sector,
+                          req-&gt;buffer,
+                          req-&gt;size / 512,
+                          virtio_blk_rw_complete,
+                          req);
+        }
     }
     /*
      * FIXME: Want to check for completions before returning to guest mode,
&lt; at &gt;&lt; at &gt; -265,7 +265,7 &lt; at &gt;&lt; at &gt; static int virtio_blk_load(QEMUFile *f, void *opaque, int version_id)
     VirtIOBlock *s = opaque;
 
     if (version_id != 1)
-return -EINVAL;
+        return -EINVAL;
 
     virtio_load(&amp;s-&gt;vdev, f);
 
&lt; at &gt;&lt; at &gt; -273,18 +273,18 &lt; at &gt;&lt; at &gt; static int virtio_blk_load(QEMUFile *f, void *opaque, int version_id)
 }
 
 void *virtio_blk_init(PCIBus *bus, uint16_t vendor, uint16_t device,
-      BlockDriverState *bs)
+                      BlockDriverState *bs)
 {
     VirtIOBlock *s;
     int cylinders, heads, secs;
     static int virtio_blk_id;
 
     s = (VirtIOBlock *)virtio_init_pci(bus, "virtio-blk", vendor, device,
-       0, VIRTIO_ID_BLOCK,
-       0x01, 0x80, 0x00,
-       sizeof(struct virtio_blk_config), sizeof(VirtIOBlock));
+                                       0, VIRTIO_ID_BLOCK,
+                                       0x01, 0x80, 0x00,
+                                       sizeof(struct virtio_blk_config), sizeof(VirtIOBlock));
     if (!s)
-return NULL;
+        return NULL;
 
     s-&gt;vdev.get_config = virtio_blk_update_config;
     s-&gt;vdev.get_features = virtio_blk_get_features;
&lt; at &gt;&lt; at &gt; -297,7 +297,7 &lt; at &gt;&lt; at &gt; void *virtio_blk_init(PCIBus *bus, uint16_t vendor, uint16_t device,
     s-&gt;vq = virtio_add_queue(&amp;s-&gt;vdev, 128, virtio_blk_handle_output);
 
     register_savevm("virtio-blk", virtio_blk_id++, 1,
-    virtio_blk_save, virtio_blk_load, s);
+                    virtio_blk_save, virtio_blk_load, s);
 
     return s;
 }
diff --git a/qemu/hw/virtio-net.c b/qemu/hw/virtio-net.c
index b5d5f9e..b179fcc 100644
--- a/qemu/hw/virtio-net.c
+++ b/qemu/hw/virtio-net.c
&lt; at &gt;&lt; at &gt; -19,27 +19,27 &lt; at &gt;&lt; at &gt;
 /* from Linux's virtio_net.h */
 
 /* The ID for virtio_net */
-#define VIRTIO_ID_NET1
+#define VIRTIO_ID_NET   1
 
 /* The feature bitmap for virtio net */
-#define VIRTIO_NET_F_CSUM0/* Host handles pkts w/ partial csum */
-#define VIRTIO_NET_F_GUEST_CSUM1/* Guest handles pkts w/ partial csum */
-#define VIRTIO_NET_F_MAC5/* Host has given MAC address. */
-#define VIRTIO_NET_F_GSO6/* Host handles pkts w/ any GSO type */
-#define VIRTIO_NET_F_GUEST_TSO47/* Guest can handle TSOv4 in. */
-#define VIRTIO_NET_F_GUEST_TSO68/* Guest can handle TSOv6 in. */
-#define VIRTIO_NET_F_GUEST_ECN9/* Guest can handle TSO[6] w/ ECN in. */
-#define VIRTIO_NET_F_GUEST_UFO10/* Guest can handle UFO in. */
-#define VIRTIO_NET_F_HOST_TSO411/* Host can handle TSOv4 in. */
-#define VIRTIO_NET_F_HOST_TSO612/* Host can handle TSOv6 in. */
-#define VIRTIO_NET_F_HOST_ECN13/* Host can handle TSO[6] w/ ECN in. */
-#define VIRTIO_NET_F_HOST_UFO14/* Host can handle UFO in. */
-#define VIRTIO_NET_F_MRG_RXBUF15/* Host can merge receive buffers. */
+#define VIRTIO_NET_F_CSUM       0       /* Host handles pkts w/ partial csum */
+#define VIRTIO_NET_F_GUEST_CSUM 1       /* Guest handles pkts w/ partial csum */
+#define VIRTIO_NET_F_MAC        5       /* Host has given MAC address. */
+#define VIRTIO_NET_F_GSO        6       /* Host handles pkts w/ any GSO type */
+#define VIRTIO_NET_F_GUEST_TSO4 7       /* Guest can handle TSOv4 in. */
+#define VIRTIO_NET_F_GUEST_TSO6 8       /* Guest can handle TSOv6 in. */
+#define VIRTIO_NET_F_GUEST_ECN  9       /* Guest can handle TSO[6] w/ ECN in. */
+#define VIRTIO_NET_F_GUEST_UFO  10      /* Guest can handle UFO in. */
+#define VIRTIO_NET_F_HOST_TSO4  11      /* Host can handle TSOv4 in. */
+#define VIRTIO_NET_F_HOST_TSO6  12      /* Host can handle TSOv6 in. */
+#define VIRTIO_NET_F_HOST_ECN   13      /* Host can handle TSO[6] w/ ECN in. */
+#define VIRTIO_NET_F_HOST_UFO   14      /* Host can handle UFO in. */
+#define VIRTIO_NET_F_MRG_RXBUF  15      /* Host can merge receive buffers. */
 
 #define TX_TIMER_INTERVAL 150000 /* 150 us */
 
 /* Maximum packet size we can receive from tap device: header + 64k */
-#define VIRTIO_NET_MAX_BUFSIZE(sizeof(struct virtio_net_hdr) + (64 &lt;&lt; 10))
+#define VIRTIO_NET_MAX_BUFSIZE (sizeof(struct virtio_net_hdr) + (64 &lt;&lt; 10))
 
 /* The config defining mac address (6 bytes) */
 struct virtio_net_config
&lt; at &gt;&lt; at &gt; -51,13 +51,13 &lt; at &gt;&lt; at &gt; struct virtio_net_config
  * specify GSO or CSUM features, you can simply ignore the header. */
 struct virtio_net_hdr
 {
-#define VIRTIO_NET_HDR_F_NEEDS_CSUM1// Use csum_start, csum_offset
+#define VIRTIO_NET_HDR_F_NEEDS_CSUM     1       // Use csum_start, csum_offset
     uint8_t flags;
-#define VIRTIO_NET_HDR_GSO_NONE0// Not a GSO frame
-#define VIRTIO_NET_HDR_GSO_TCPV41// GSO frame, IPv4 TCP (TSO)
-#define VIRTIO_NET_HDR_GSO_UDP3// GSO frame, IPv4 UDP (UFO)
-#define VIRTIO_NET_HDR_GSO_TCPV64// GSO frame, IPv6 TCP
-#define VIRTIO_NET_HDR_GSO_ECN0x80// TCP has ECN set
+#define VIRTIO_NET_HDR_GSO_NONE         0       // Not a GSO frame
+#define VIRTIO_NET_HDR_GSO_TCPV4        1       // GSO frame, IPv4 TCP (TSO)
+#define VIRTIO_NET_HDR_GSO_UDP          3       // GSO frame, IPv4 UDP (UFO)
+#define VIRTIO_NET_HDR_GSO_TCPV6        4       // GSO frame, IPv6 TCP
+#define VIRTIO_NET_HDR_GSO_ECN          0x80    // TCP has ECN set
     uint8_t gso_type;
     uint16_t hdr_len;
     uint16_t gso_size;
&lt; at &gt;&lt; at &gt; -110,17 +110,17 &lt; at &gt;&lt; at &gt; static uint32_t virtio_net_get_features(VirtIODevice *vdev)
     uint32_t features = (1 &lt;&lt; VIRTIO_NET_F_MAC);
 
     if (tap_has_vnet_hdr(host)) {
-tap_using_vnet_hdr(host, 1);
-features |= (1 &lt;&lt; VIRTIO_NET_F_CSUM);
-features |= (1 &lt;&lt; VIRTIO_NET_F_GUEST_CSUM);
-features |= (1 &lt;&lt; VIRTIO_NET_F_GUEST_TSO4);
-features |= (1 &lt;&lt; VIRTIO_NET_F_GUEST_TSO6);
-features |= (1 &lt;&lt; VIRTIO_NET_F_GUEST_ECN);
-features |= (1 &lt;&lt; VIRTIO_NET_F_HOST_TSO4);
-features |= (1 &lt;&lt; VIRTIO_NET_F_HOST_TSO6);
-features |= (1 &lt;&lt; VIRTIO_NET_F_HOST_ECN);
-features |= (1 &lt;&lt; VIRTIO_NET_F_MRG_RXBUF);
-/* Kernel can't actually handle UFO in software currently. */
+        tap_using_vnet_hdr(host, 1);
+        features |= (1 &lt;&lt; VIRTIO_NET_F_CSUM);
+        features |= (1 &lt;&lt; VIRTIO_NET_F_GUEST_CSUM);
+        features |= (1 &lt;&lt; VIRTIO_NET_F_GUEST_TSO4);
+        features |= (1 &lt;&lt; VIRTIO_NET_F_GUEST_TSO6);
+        features |= (1 &lt;&lt; VIRTIO_NET_F_GUEST_ECN);
+        features |= (1 &lt;&lt; VIRTIO_NET_F_HOST_TSO4);
+        features |= (1 &lt;&lt; VIRTIO_NET_F_HOST_TSO6);
+        features |= (1 &lt;&lt; VIRTIO_NET_F_HOST_ECN);
+        features |= (1 &lt;&lt; VIRTIO_NET_F_MRG_RXBUF);
+        /* Kernel can't actually handle UFO in software currently. */
     }
 
     return features;
&lt; at &gt;&lt; at &gt; -134,13 +134,13 &lt; at &gt;&lt; at &gt; static void virtio_net_set_features(VirtIODevice *vdev, uint32_t features)
     n-&gt;mergeable_rx_bufs = !!(features &amp; (1 &lt;&lt; VIRTIO_NET_F_MRG_RXBUF));
 
     if (!tap_has_vnet_hdr(host) || !host-&gt;set_offload)
-return;
+        return;
 
     host-&gt;set_offload(host,
-      (features &gt;&gt; VIRTIO_NET_F_GUEST_CSUM) &amp; 1,
-      (features &gt;&gt; VIRTIO_NET_F_GUEST_TSO4) &amp; 1,
-      (features &gt;&gt; VIRTIO_NET_F_GUEST_TSO6) &amp; 1,
-      (features &gt;&gt; VIRTIO_NET_F_GUEST_ECN)  &amp; 1);
+                      (features &gt;&gt; VIRTIO_NET_F_GUEST_CSUM) &amp; 1,
+                      (features &gt;&gt; VIRTIO_NET_F_GUEST_TSO4) &amp; 1,
+                      (features &gt;&gt; VIRTIO_NET_F_GUEST_TSO6) &amp; 1,
+                      (features &gt;&gt; VIRTIO_NET_F_GUEST_ECN)  &amp; 1);
 }
 
 /* RX */
&lt; at &gt;&lt; at &gt; -150,7 +150,7 &lt; at &gt;&lt; at &gt; static void virtio_net_handle_rx(VirtIODevice *vdev, VirtQueue *vq)
     /* We now have RX buffers, signal to the IO thread to break out of the
        select to re-poll the tap file descriptor */
     if (kvm_enabled())
-qemu_kvm_notify_work();
+        qemu_kvm_notify_work();
 }
 
 static int virtio_net_can_receive(void *opaque)
&lt; at &gt;&lt; at &gt; -158,14 +158,14 &lt; at &gt;&lt; at &gt; static int virtio_net_can_receive(void *opaque)
     VirtIONet *n = opaque;
 
     if (n-&gt;rx_vq-&gt;vring.avail == NULL ||
-!(n-&gt;vdev.status &amp; VIRTIO_CONFIG_S_DRIVER_OK))
-return 0;
+        !(n-&gt;vdev.status &amp; VIRTIO_CONFIG_S_DRIVER_OK))
+        return 0;
 
     if (n-&gt;rx_vq-&gt;vring.avail-&gt;idx == n-&gt;rx_vq-&gt;last_avail_idx ||
-(n-&gt;mergeable_rx_bufs &amp;&amp;
- !virtqueue_avail_bytes(n-&gt;rx_vq, VIRTIO_NET_MAX_BUFSIZE, 0))) {
-n-&gt;rx_vq-&gt;vring.used-&gt;flags &amp;= ~VRING_USED_F_NO_NOTIFY;
-return 0;
+        (n-&gt;mergeable_rx_bufs &amp;&amp;
+         !virtqueue_avail_bytes(n-&gt;rx_vq, VIRTIO_NET_MAX_BUFSIZE, 0))) {
+        n-&gt;rx_vq-&gt;vring.used-&gt;flags &amp;= ~VRING_USED_F_NO_NOTIFY;
+        return 0;
     }
 
     n-&gt;rx_vq-&gt;vring.used-&gt;flags |= VRING_USED_F_NO_NOTIFY;
&lt; at &gt;&lt; at &gt; -206,17 +206,17 &lt; at &gt;&lt; at &gt; static int iov_fill(struct iovec *iov, int iovcnt, const void *buf, int count)
 
     offset = i = 0;
     while (offset &lt; count &amp;&amp; i &lt; iovcnt) {
-int len = MIN(iov[i].iov_len, count - offset);
-memcpy(iov[i].iov_base, buf + offset, len);
-offset += len;
-i++;
+        int len = MIN(iov[i].iov_len, count - offset);
+        memcpy(iov[i].iov_base, buf + offset, len);
+        offset += len;
+        i++;
     }
 
     return offset;
 }
 
 static int receive_header(VirtIONet *n, struct iovec *iov, int iovcnt,
-  const void *buf, int size, int hdr_len)
+                          const void *buf, int size, int hdr_len)
 {
     struct virtio_net_hdr *hdr = iov[0].iov_base;
     int offset;
&lt; at &gt;&lt; at &gt; -225,9 +225,9 &lt; at &gt;&lt; at &gt; static int receive_header(VirtIONet *n, struct iovec *iov, int iovcnt,
     hdr-&gt;gso_type = VIRTIO_NET_HDR_GSO_NONE;
 
     if (tap_has_vnet_hdr(n-&gt;vc-&gt;vlan-&gt;first_client)) {
-memcpy(hdr, buf, sizeof(*hdr));
-offset = sizeof(*hdr);
-work_around_broken_dhclient(hdr, buf + offset, size - offset);
+        memcpy(hdr, buf, sizeof(*hdr));
+        offset = sizeof(*hdr);
+        work_around_broken_dhclient(hdr, buf + offset, size - offset);
     }
 
     /* We only ever receive a struct virtio_net_hdr from the tapfd,
&lt; at &gt;&lt; at &gt; -247,56 +247,56 &lt; at &gt;&lt; at &gt; static void virtio_net_receive(void *opaque, const uint8_t *buf, int size)
 
     /* hdr_len refers to the header we supply to the guest */
     hdr_len = n-&gt;mergeable_rx_bufs ?
-sizeof(struct virtio_net_hdr_mrg_rxbuf) : sizeof(struct virtio_net_hdr);
+        sizeof(struct virtio_net_hdr_mrg_rxbuf) : sizeof(struct virtio_net_hdr);
 
     offset = i = 0;
 
     while (offset &lt; size) {
-VirtQueueElement elem;
-int len, total;
-
-len = total = 0;
-
-if ((i != 0 &amp;&amp; !n-&gt;mergeable_rx_bufs) ||
-    virtqueue_pop(n-&gt;rx_vq, &amp;elem) == 0) {
-    if (i == 0)
-return;
-    fprintf(stderr, "virtio-net truncating packet\n");
-    exit(1);
-}
-
-if (elem.in_num &lt; 1) {
-    fprintf(stderr, "virtio-net receive queue contains no in buffers\n");
-    exit(1);
-}
-
-if (!n-&gt;mergeable_rx_bufs &amp;&amp; elem.in_sg[0].iov_len != hdr_len) {
-    fprintf(stderr, "virtio-net header not in first element\n");
-    exit(1);
-}
-
-if (i == 0) {
-    if (n-&gt;mergeable_rx_bufs)
-mhdr = (struct virtio_net_hdr_mrg_rxbuf *)elem.in_sg[0].iov_base;
-
-    offset += receive_header(n, &amp;elem.in_sg[0], elem.in_num,
-     buf + offset, size - offset, hdr_len);
-    total += hdr_len;
-}
-
-/* copy in packet.  ugh */
-len = iov_fill(&amp;elem.in_sg[0], elem.in_num,
-       buf + offset, size - offset);
-total += len;
-
-/* signal other side */
-virtqueue_fill(n-&gt;rx_vq, &amp;elem, total, i++);
-
-offset += len;
+        VirtQueueElement elem;
+        int len, total;
+
+        len = total = 0;
+
+        if ((i != 0 &amp;&amp; !n-&gt;mergeable_rx_bufs) ||
+            virtqueue_pop(n-&gt;rx_vq, &amp;elem) == 0) {
+            if (i == 0)
+                return;
+            fprintf(stderr, "virtio-net truncating packet\n");
+            exit(1);
+        }
+
+        if (elem.in_num &lt; 1) {
+            fprintf(stderr, "virtio-net receive queue contains no in buffers\n");
+            exit(1);
+        }
+
+        if (!n-&gt;mergeable_rx_bufs &amp;&amp; elem.in_sg[0].iov_len != hdr_len) {
+            fprintf(stderr, "virtio-net header not in first element\n");
+            exit(1);
+        }
+
+        if (i == 0) {
+            if (n-&gt;mergeable_rx_bufs)
+                mhdr = (struct virtio_net_hdr_mrg_rxbuf *)elem.in_sg[0].iov_base;
+
+            offset += receive_header(n, &amp;elem.in_sg[0], elem.in_num,
+                                     buf + offset, size - offset, hdr_len);
+            total += hdr_len;
+        }
+
+        /* copy in packet.  ugh */
+        len = iov_fill(&amp;elem.in_sg[0], elem.in_num,
+                       buf + offset, size - offset);
+        total += len;
+
+        /* signal other side */
+        virtqueue_fill(n-&gt;rx_vq, &amp;elem, total, i++);
+
+        offset += len;
     }
 
     if (mhdr)
-mhdr-&gt;num_buffers = i;
+        mhdr-&gt;num_buffers = i;
 
     virtqueue_flush(n-&gt;rx_vq, i);
     virtio_notify(&amp;n-&gt;vdev, n-&gt;rx_vq);
&lt; at &gt;&lt; at &gt; -312,37 +312,37 &lt; at &gt;&lt; at &gt; static void virtio_net_flush_tx(VirtIONet *n, VirtQueue *vq)
         return;
 
     while (virtqueue_pop(vq, &amp;elem)) {
-ssize_t len = 0;
-unsigned int out_num = elem.out_num;
-struct iovec *out_sg = &amp;elem.out_sg[0];
-unsigned hdr_len;
+        ssize_t len = 0;
+        unsigned int out_num = elem.out_num;
+        struct iovec *out_sg = &amp;elem.out_sg[0];
+        unsigned hdr_len;
 
         /* hdr_len refers to the header received from the guest */
-hdr_len = n-&gt;mergeable_rx_bufs ?
-    sizeof(struct virtio_net_hdr_mrg_rxbuf) :
-    sizeof(struct virtio_net_hdr);
-
-if (out_num &lt; 1 || out_sg-&gt;iov_len != hdr_len) {
-    fprintf(stderr, "virtio-net header not in first element\n");
-    exit(1);
-}
-
-/* ignore the header if GSO is not supported */
-if (!has_vnet_hdr) {
-    out_num--;
-    out_sg++;
-    len += hdr_len;
-} else if (n-&gt;mergeable_rx_bufs) {
-    /* tapfd expects a struct virtio_net_hdr */
-    hdr_len -= sizeof(struct virtio_net_hdr);
-    out_sg-&gt;iov_len -= hdr_len;
-    len += hdr_len;
-}
-
-len += qemu_sendv_packet(n-&gt;vc, out_sg, out_num);
-
-virtqueue_push(vq, &amp;elem, len);
-virtio_notify(&amp;n-&gt;vdev, vq);
+        hdr_len = n-&gt;mergeable_rx_bufs ?
+            sizeof(struct virtio_net_hdr_mrg_rxbuf) :
+            sizeof(struct virtio_net_hdr);
+
+        if (out_num &lt; 1 || out_sg-&gt;iov_len != hdr_len) {
+            fprintf(stderr, "virtio-net header not in first element\n");
+            exit(1);
+        }
+
+        /* ignore the header if GSO is not supported */
+        if (!has_vnet_hdr) {
+            out_num--;
+            out_sg++;
+            len += hdr_len;
+        } else if (n-&gt;mergeable_rx_bufs) {
+            /* tapfd expects a struct virtio_net_hdr */
+            hdr_len -= sizeof(struct virtio_net_hdr);
+            out_sg-&gt;iov_len -= hdr_len;
+            len += hdr_len;
+        }
+
+        len += qemu_sendv_packet(n-&gt;vc, out_sg, out_num);
+
+        virtqueue_push(vq, &amp;elem, len);
+        virtio_notify(&amp;n-&gt;vdev, vq);
     }
 }
 
&lt; at &gt;&lt; at &gt; -351,15 +351,15 &lt; at &gt;&lt; at &gt; static void virtio_net_handle_tx(VirtIODevice *vdev, VirtQueue *vq)
     VirtIONet *n = to_virtio_net(vdev);
 
     if (n-&gt;tx_timer_active) {
-vq-&gt;vring.used-&gt;flags &amp;= ~VRING_USED_F_NO_NOTIFY;
-qemu_del_timer(n-&gt;tx_timer);
-n-&gt;tx_timer_active = 0;
-virtio_net_flush_tx(n, vq);
+        vq-&gt;vring.used-&gt;flags &amp;= ~VRING_USED_F_NO_NOTIFY;
+        qemu_del_timer(n-&gt;tx_timer);
+        n-&gt;tx_timer_active = 0;
+        virtio_net_flush_tx(n, vq);
     } else {
-qemu_mod_timer(n-&gt;tx_timer,
-       qemu_get_clock(vm_clock) + TX_TIMER_INTERVAL);
-n-&gt;tx_timer_active = 1;
-vq-&gt;vring.used-&gt;flags |= VRING_USED_F_NO_NOTIFY;
+        qemu_mod_timer(n-&gt;tx_timer,
+                       qemu_get_clock(vm_clock) + TX_TIMER_INTERVAL);
+        n-&gt;tx_timer_active = 1;
+        vq-&gt;vring.used-&gt;flags |= VRING_USED_F_NO_NOTIFY;
     }
 }
 
&lt; at &gt;&lt; at &gt; -392,7 +392,7 &lt; at &gt;&lt; at &gt; static int virtio_net_load(QEMUFile *f, void *opaque, int version_id)
     VirtIONet *n = opaque;
 
     if (version_id != 1)
-return -EINVAL;
+        return -EINVAL;
 
     virtio_load(&amp;n-&gt;vdev, f);
 
&lt; at &gt;&lt; at &gt; -400,8 +400,8 &lt; at &gt;&lt; at &gt; static int virtio_net_load(QEMUFile *f, void *opaque, int version_id)
     n-&gt;tx_timer_active = qemu_get_be32(f);
 
     if (n-&gt;tx_timer_active) {
-qemu_mod_timer(n-&gt;tx_timer,
-       qemu_get_clock(vm_clock) + TX_TIMER_INTERVAL);
+        qemu_mod_timer(n-&gt;tx_timer,
+                       qemu_get_clock(vm_clock) + TX_TIMER_INTERVAL);
     }
 
     return 0;
&lt; at &gt;&lt; at &gt; -413,11 +413,11 &lt; at &gt;&lt; at &gt; PCIDevice *virtio_net_init(PCIBus *bus, NICInfo *nd, int devfn)
     static int virtio_net_id;
 
     n = (VirtIONet *)virtio_init_pci(bus, "virtio-net", 6900, 0x1000,
-     0, VIRTIO_ID_NET,
-     0x02, 0x00, 0x00,
-     6, sizeof(VirtIONet));
+                                     0, VIRTIO_ID_NET,
+                                     0x02, 0x00, 0x00,
+                                     6, sizeof(VirtIONet));
     if (!n)
-return NULL;
+        return NULL;
 
     n-&gt;vdev.get_config = virtio_net_update_config;
     n-&gt;vdev.get_features = virtio_net_get_features;
&lt; at &gt;&lt; at &gt; -433,7 +433,7 &lt; at &gt;&lt; at &gt; PCIDevice *virtio_net_init(PCIBus *bus, NICInfo *nd, int devfn)
     n-&gt;mergeable_rx_bufs = 0;
 
     register_savevm("virtio-net", virtio_net_id++, 1,
-    virtio_net_save, virtio_net_load, n);
+                    virtio_net_save, virtio_net_load, n);
 
     return (PCIDevice *)n;
 }
diff --git a/qemu/hw/virtio.c b/qemu/hw/virtio.c
index 303f5e7..6d7425c 100644
--- a/qemu/hw/virtio.c
+++ b/qemu/hw/virtio.c
&lt; at &gt;&lt; at &gt; -20,35 +20,35 &lt; at &gt;&lt; at &gt;
 /* from Linux's linux/virtio_pci.h */
 
 /* A 32-bit r/o bitmask of the features supported by the host */
-#define VIRTIO_PCI_HOST_FEATURES0
+#define VIRTIO_PCI_HOST_FEATURES        0
 
 /* A 32-bit r/w bitmask of features activated by the guest */
-#define VIRTIO_PCI_GUEST_FEATURES4
+#define VIRTIO_PCI_GUEST_FEATURES       4
 
 /* A 32-bit r/w PFN for the currently selected queue */
-#define VIRTIO_PCI_QUEUE_PFN8
+#define VIRTIO_PCI_QUEUE_PFN            8
 
 /* A 16-bit r/o queue size for the currently selected queue */
-#define VIRTIO_PCI_QUEUE_NUM12
+#define VIRTIO_PCI_QUEUE_NUM            12
 
 /* A 16-bit r/w queue selector */
-#define VIRTIO_PCI_QUEUE_SEL14
+#define VIRTIO_PCI_QUEUE_SEL            14
 
 /* A 16-bit r/w queue notifier */
-#define VIRTIO_PCI_QUEUE_NOTIFY16
+#define VIRTIO_PCI_QUEUE_NOTIFY         16
 
 /* An 8-bit device status register.  */
-#define VIRTIO_PCI_STATUS18
+#define VIRTIO_PCI_STATUS               18
 
 /* An 8-bit r/o interrupt status register.  Reading the value will return the
  * current contents of the ISR and will also clear it.  This is effectively
  * a read-and-acknowledge. */
-#define VIRTIO_PCI_ISR19
+#define VIRTIO_PCI_ISR                  19
 
-#define VIRTIO_PCI_CONFIG20
+#define VIRTIO_PCI_CONFIG               20
 
 /* Virtio ABI version, if we increment this, we break the guest driver. */
-#define VIRTIO_PCI_ABI_VERSION0
+#define VIRTIO_PCI_ABI_VERSION          0
 
 /* QEMU doesn't strictly need write barriers since everything runs in
  * lock-step.  We'll leave the calls to wmb() in though to make it obvious for
&lt; at &gt;&lt; at &gt; -65,29 +65,29 &lt; at &gt;&lt; at &gt; static void *virtio_map_gpa(target_phys_addr_t addr, size_t size)
 
     off = cpu_get_physical_page_desc(addr);
     if ((off &amp; ~TARGET_PAGE_MASK) != IO_MEM_RAM) {
-fprintf(stderr, "virtio DMA to IO ram\n");
-exit(1);
+        fprintf(stderr, "virtio DMA to IO ram\n");
+        exit(1);
     }
 
     off = (off &amp; TARGET_PAGE_MASK) | (addr &amp; ~TARGET_PAGE_MASK);
 
     for (addr1 = addr + TARGET_PAGE_SIZE;
- addr1 &lt; TARGET_PAGE_ALIGN(addr + size);
- addr1 += TARGET_PAGE_SIZE) {
-ram_addr_t off1;
-
-off1 = cpu_get_physical_page_desc(addr1);
-if ((off1 &amp; ~TARGET_PAGE_MASK) != IO_MEM_RAM) {
-    fprintf(stderr, "virtio DMA to IO ram\n");
-    exit(1);
-}
-
-off1 = (off1 &amp; TARGET_PAGE_MASK) | (addr1 &amp; ~TARGET_PAGE_MASK);
-
-if (off1 != (off + (addr1 - addr))) {
-    fprintf(stderr, "discontigous virtio memory\n");
-    exit(1);
-}
+         addr1 &lt; TARGET_PAGE_ALIGN(addr + size);
+         addr1 += TARGET_PAGE_SIZE) {
+        ram_addr_t off1;
+
+        off1 = cpu_get_physical_page_desc(addr1);
+        if ((off1 &amp; ~TARGET_PAGE_MASK) != IO_MEM_RAM) {
+            fprintf(stderr, "virtio DMA to IO ram\n");
+            exit(1);
+        }
+
+        off1 = (off1 &amp; TARGET_PAGE_MASK) | (addr1 &amp; ~TARGET_PAGE_MASK);
+
+        if (off1 != (off + (addr1 - addr))) {
+            fprintf(stderr, "discontigous virtio memory\n");
+            exit(1);
+        }
     }
 
     return phys_ram_base + off;
&lt; at &gt;&lt; at &gt; -96,8 +96,8 &lt; at &gt;&lt; at &gt; static void *virtio_map_gpa(target_phys_addr_t addr, size_t size)
 static size_t virtqueue_size(int num)
 {
     return TARGET_PAGE_ALIGN((sizeof(VRingDesc) * num) +
-     (sizeof(VRingAvail) + sizeof(uint16_t) * num)) +
-(sizeof(VRingUsed) + sizeof(VRingUsedElem) * num);
+                             (sizeof(VRingAvail) + sizeof(uint16_t) * num)) +
+        (sizeof(VRingUsed) + sizeof(VRingUsedElem) * num);
 }
 
 static void virtqueue_init(VirtQueue *vq, void *p)
&lt; at &gt;&lt; at &gt; -108,7 +108,7 &lt; at &gt;&lt; at &gt; static void virtqueue_init(VirtQueue *vq, void *p)
 }
 
 void virtqueue_fill(VirtQueue *vq, const VirtQueueElement *elem,
-    unsigned int len, unsigned int idx)
+                    unsigned int len, unsigned int idx)
 {
     VRingUsedElem *used;
 
&lt; at &gt;&lt; at &gt; -129,7 +129,7 &lt; at &gt;&lt; at &gt; void virtqueue_flush(VirtQueue *vq, unsigned int count)
 }
 
 void virtqueue_push(VirtQueue *vq, const VirtQueueElement *elem,
-    unsigned int len)
+                    unsigned int len)
 {
     virtqueue_fill(vq, elem, len, 0);
     virtqueue_flush(vq, 1);
&lt; at &gt;&lt; at &gt; -141,8 +141,8 &lt; at &gt;&lt; at &gt; static int virtqueue_num_heads(VirtQueue *vq, unsigned int idx)
 
     /* Check it isn't doing very strange things with descriptor numbers. */
     if (num_heads &gt; vq-&gt;vring.num)
-errx(1, "Guest moved used index from %u to %u",
-     idx, vq-&gt;vring.avail-&gt;idx);
+        errx(1, "Guest moved used index from %u to %u",
+             idx, vq-&gt;vring.avail-&gt;idx);
 
     return num_heads;
 }
&lt; at &gt;&lt; at &gt; -157,7 +157,7 &lt; at &gt;&lt; at &gt; static unsigned int virtqueue_get_head(VirtQueue *vq, unsigned int idx)
 
     /* If their number is silly, that's a fatal mistake. */
     if (head &gt;= vq-&gt;vring.num)
-errx(1, "Guest says index %u is available", head);
+        errx(1, "Guest says index %u is available", head);
 
     return head;
 }
&lt; at &gt;&lt; at &gt; -168,7 +168,7 &lt; at &gt;&lt; at &gt; static unsigned virtqueue_next_desc(VirtQueue *vq, unsigned int i)
 
     /* If this descriptor says it doesn't chain, we're done. */
     if (!(vq-&gt;vring.desc[i].flags &amp; VRING_DESC_F_NEXT))
-return vq-&gt;vring.num;
+        return vq-&gt;vring.num;
 
     /* Check they're not leading us off end of descriptors. */
     next = vq-&gt;vring.desc[i].next;
&lt; at &gt;&lt; at &gt; -176,7 +176,7 &lt; at &gt;&lt; at &gt; static unsigned virtqueue_next_desc(VirtQueue *vq, unsigned int i)
     wmb();
 
     if (next &gt;= vq-&gt;vring.num)
-errx(1, "Desc next is %u", next);
+        errx(1, "Desc next is %u", next);
 
     return next;
 }
&lt; at &gt;&lt; at &gt; -190,24 +190,24 &lt; at &gt;&lt; at &gt; int virtqueue_avail_bytes(VirtQueue *vq, int in_bytes, int out_bytes)
 
     num_bufs = in_total = out_total = 0;
     while (virtqueue_num_heads(vq, idx)) {
-int i;
-
-i = virtqueue_get_head(vq, idx++);
-do {
-    /* If we've got too many, that implies a descriptor loop. */
-    if (++num_bufs &gt; vq-&gt;vring.num)
-errx(1, "Looped descriptor");
-
-    if (vq-&gt;vring.desc[i].flags &amp; VRING_DESC_F_WRITE) {
-if (in_bytes &gt; 0 &amp;&amp;
-    (in_total += vq-&gt;vring.desc[i].len) &gt;= in_bytes)
-    return 1;
-    } else {
-if (out_bytes &gt; 0 &amp;&amp;
-    (out_total += vq-&gt;vring.desc[i].len) &gt;= out_bytes)
-    return 1;
-    }
-} while ((i = virtqueue_next_desc(vq, i)) != vq-&gt;vring.num);
+        int i;
+
+        i = virtqueue_get_head(vq, idx++);
+        do {
+            /* If we've got too many, that implies a descriptor loop. */
+            if (++num_bufs &gt; vq-&gt;vring.num)
+                errx(1, "Looped descriptor");
+
+            if (vq-&gt;vring.desc[i].flags &amp; VRING_DESC_F_WRITE) {
+                if (in_bytes &gt; 0 &amp;&amp;
+                    (in_total += vq-&gt;vring.desc[i].len) &gt;= in_bytes)
+                    return 1;
+            } else {
+                if (out_bytes &gt; 0 &amp;&amp;
+                    (out_total += vq-&gt;vring.desc[i].len) &gt;= out_bytes)
+                    return 1;
+            }
+        } while ((i = virtqueue_next_desc(vq, i)) != vq-&gt;vring.num);
     }
 
     return 0;
&lt; at &gt;&lt; at &gt; -218,29 +218,29 &lt; at &gt;&lt; at &gt; int virtqueue_pop(VirtQueue *vq, VirtQueueElement *elem)
     unsigned int i, head;
 
     if (!virtqueue_num_heads(vq, vq-&gt;last_avail_idx))
-return 0;
+        return 0;
 
     /* When we start there are none of either input nor output. */
     elem-&gt;out_num = elem-&gt;in_num = 0;
 
     i = head = virtqueue_get_head(vq, vq-&gt;last_avail_idx++);
     do {
-struct iovec *sg;
-
-if (vq-&gt;vring.desc[i].flags &amp; VRING_DESC_F_WRITE)
-    sg = &amp;elem-&gt;in_sg[elem-&gt;in_num++];
-else
-    sg = &amp;elem-&gt;out_sg[elem-&gt;out_num++];
-
-/* Grab the first descriptor, and check it's OK. */
-sg-&gt;iov_len = vq-&gt;vring.desc[i].len;
-sg-&gt;iov_base = virtio_map_gpa(vq-&gt;vring.desc[i].addr, sg-&gt;iov_len);
-if (sg-&gt;iov_base == NULL)
-    errx(1, "Invalid mapping\n");
-
-/* If we've got too many, that implies a descriptor loop. */
-if ((elem-&gt;in_num + elem-&gt;out_num) &gt; vq-&gt;vring.num)
-    errx(1, "Looped descriptor");
+        struct iovec *sg;
+
+        if (vq-&gt;vring.desc[i].flags &amp; VRING_DESC_F_WRITE)
+            sg = &amp;elem-&gt;in_sg[elem-&gt;in_num++];
+        else
+            sg = &amp;elem-&gt;out_sg[elem-&gt;out_num++];
+
+        /* Grab the first descriptor, and check it's OK. */
+        sg-&gt;iov_len = vq-&gt;vring.desc[i].len;
+        sg-&gt;iov_base = virtio_map_gpa(vq-&gt;vring.desc[i].addr, sg-&gt;iov_len);
+        if (sg-&gt;iov_base == NULL)
+            errx(1, "Invalid mapping\n");
+
+        /* If we've got too many, that implies a descriptor loop. */
+        if ((elem-&gt;in_num + elem-&gt;out_num) &gt; vq-&gt;vring.num)
+            errx(1, "Looped descriptor");
     } while ((i = virtqueue_next_desc(vq, i)) != vq-&gt;vring.num);
 
     elem-&gt;index = head;
&lt; at &gt;&lt; at &gt; -294,34 +294,34 &lt; at &gt;&lt; at &gt; static void virtio_ioport_write(void *opaque, uint32_t addr, uint32_t val)
 
     switch (addr) {
     case VIRTIO_PCI_GUEST_FEATURES:
-if (vdev-&gt;set_features)
-    vdev-&gt;set_features(vdev, val);
-vdev-&gt;features = val;
-break;
+        if (vdev-&gt;set_features)
+            vdev-&gt;set_features(vdev, val);
+        vdev-&gt;features = val;
+        break;
     case VIRTIO_PCI_QUEUE_PFN:
-pa = (ram_addr_t)val &lt;&lt; TARGET_PAGE_BITS;
-vdev-&gt;vq[vdev-&gt;queue_sel].pfn = val;
-if (pa == 0) {
+        pa = (ram_addr_t)val &lt;&lt; TARGET_PAGE_BITS;
+        vdev-&gt;vq[vdev-&gt;queue_sel].pfn = val;
+        if (pa == 0) {
             virtio_reset(vdev);
-} else {
-    size_t size = virtqueue_size(vdev-&gt;vq[vdev-&gt;queue_sel].vring.num);
-    virtqueue_init(&amp;vdev-&gt;vq[vdev-&gt;queue_sel],
-   virtio_map_gpa(pa, size));
-}
-break;
+        } else {
+            size_t size = virtqueue_size(vdev-&gt;vq[vdev-&gt;queue_sel].vring.num);
+            virtqueue_init(&amp;vdev-&gt;vq[vdev-&gt;queue_sel],
+                           virtio_map_gpa(pa, size));
+        }
+        break;
     case VIRTIO_PCI_QUEUE_SEL:
-if (val &lt; VIRTIO_PCI_QUEUE_MAX)
-    vdev-&gt;queue_sel = val;
-break;
+        if (val &lt; VIRTIO_PCI_QUEUE_MAX)
+            vdev-&gt;queue_sel = val;
+        break;
     case VIRTIO_PCI_QUEUE_NOTIFY:
-if (val &lt; VIRTIO_PCI_QUEUE_MAX &amp;&amp; vdev-&gt;vq[val].vring.desc)
-    vdev-&gt;vq[val].handle_output(vdev, &amp;vdev-&gt;vq[val]);
-break;
+        if (val &lt; VIRTIO_PCI_QUEUE_MAX &amp;&amp; vdev-&gt;vq[val].vring.desc)
+            vdev-&gt;vq[val].handle_output(vdev, &amp;vdev-&gt;vq[val]);
+        break;
     case VIRTIO_PCI_STATUS:
-vdev-&gt;status = val &amp; 0xFF;
-if (vdev-&gt;status == 0)
-    virtio_reset(vdev);
-break;
+        vdev-&gt;status = val &amp; 0xFF;
+        if (vdev-&gt;status == 0)
+            virtio_reset(vdev);
+        break;
     }
 }
 
&lt; at &gt;&lt; at &gt; -334,32 +334,32 &lt; at &gt;&lt; at &gt; static uint32_t virtio_ioport_read(void *opaque, uint32_t addr)
 
     switch (addr) {
     case VIRTIO_PCI_HOST_FEATURES:
-ret = vdev-&gt;get_features(vdev);
-ret |= (1 &lt;&lt; VIRTIO_F_NOTIFY_ON_EMPTY);
-break;
+        ret = vdev-&gt;get_features(vdev);
+        ret |= (1 &lt;&lt; VIRTIO_F_NOTIFY_ON_EMPTY);
+        break;
     case VIRTIO_PCI_GUEST_FEATURES:
-ret = vdev-&gt;features;
-break;
+        ret = vdev-&gt;features;
+        break;
     case VIRTIO_PCI_QUEUE_PFN:
-ret = vdev-&gt;vq[vdev-&gt;queue_sel].pfn;
-break;
+        ret = vdev-&gt;vq[vdev-&gt;queue_sel].pfn;
+        break;
     case VIRTIO_PCI_QUEUE_NUM:
-ret = vdev-&gt;vq[vdev-&gt;queue_sel].vring.num;
-break;
+        ret = vdev-&gt;vq[vdev-&gt;queue_sel].vring.num;
+        break;
     case VIRTIO_PCI_QUEUE_SEL:
-ret = vdev-&gt;queue_sel;
-break;
+        ret = vdev-&gt;queue_sel;
+        break;
     case VIRTIO_PCI_STATUS:
-ret = vdev-&gt;status;
-break;
+        ret = vdev-&gt;status;
+        break;
     case VIRTIO_PCI_ISR:
-/* reading from the ISR also clears it. */
-ret = vdev-&gt;isr;
-vdev-&gt;isr = 0;
-virtio_update_irq(vdev);
-break;
+        /* reading from the ISR also clears it. */
+        ret = vdev-&gt;isr;
+        vdev-&gt;isr = 0;
+        virtio_update_irq(vdev);
+        break;
     default:
-break;
+        break;
     }
 
     return ret;
&lt; at &gt;&lt; at &gt; -374,7 +374,7 &lt; at &gt;&lt; at &gt; static uint32_t virtio_config_readb(void *opaque, uint32_t addr)
 
     addr -= vdev-&gt;addr + VIRTIO_PCI_CONFIG;
     if (addr &gt; (vdev-&gt;config_len - sizeof(val)))
-return (uint32_t)-1;
+        return (uint32_t)-1;
 
     memcpy(&amp;val, vdev-&gt;config + addr, sizeof(val));
     return val;
&lt; at &gt;&lt; at &gt; -389,7 +389,7 &lt; at &gt;&lt; at &gt; static uint32_t virtio_config_readw(void *opaque, uint32_t addr)
 
     addr -= vdev-&gt;addr + VIRTIO_PCI_CONFIG;
     if (addr &gt; (vdev-&gt;config_len - sizeof(val)))
-return (uint32_t)-1;
+        return (uint32_t)-1;
 
     memcpy(&amp;val, vdev-&gt;config + addr, sizeof(val));
     return val;
&lt; at &gt;&lt; at &gt; -404,7 +404,7 &lt; at &gt;&lt; at &gt; static uint32_t virtio_config_readl(void *opaque, uint32_t addr)
 
     addr -= vdev-&gt;addr + VIRTIO_PCI_CONFIG;
     if (addr &gt; (vdev-&gt;config_len - sizeof(val)))
-return (uint32_t)-1;
+        return (uint32_t)-1;
 
     memcpy(&amp;val, vdev-&gt;config + addr, sizeof(val));
     return val;
&lt; at &gt;&lt; at &gt; -417,7 +417,7 &lt; at &gt;&lt; at &gt; static void virtio_config_writeb(void *opaque, uint32_t addr, uint32_t data)
 
     addr -= vdev-&gt;addr + VIRTIO_PCI_CONFIG;
     if (addr &gt; (vdev-&gt;config_len - sizeof(val)))
-return;
+        return;
 
     memcpy(vdev-&gt;config + addr, &amp;val, sizeof(val));
 
&lt; at &gt;&lt; at &gt; -432,7 +432,7 &lt; at &gt;&lt; at &gt; static void virtio_config_writew(void *opaque, uint32_t addr, uint32_t data)
 
     addr -= vdev-&gt;addr + VIRTIO_PCI_CONFIG;
     if (addr &gt; (vdev-&gt;config_len - sizeof(val)))
-return;
+        return;
 
     memcpy(vdev-&gt;config + addr, &amp;val, sizeof(val));
 
&lt; at &gt;&lt; at &gt; -447,7 +447,7 &lt; at &gt;&lt; at &gt; static void virtio_config_writel(void *opaque, uint32_t addr, uint32_t data)
 
     addr -= vdev-&gt;addr + VIRTIO_PCI_CONFIG;
     if (addr &gt; (vdev-&gt;config_len - sizeof(val)))
-return;
+        return;
 
     memcpy(vdev-&gt;config + addr, &amp;val, sizeof(val));
 
&lt; at &gt;&lt; at &gt; -456,47 +456,47 &lt; at &gt;&lt; at &gt; static void virtio_config_writel(void *opaque, uint32_t addr, uint32_t data)
 }
 
 static void virtio_map(PCIDevice *pci_dev, int region_num,
-       uint32_t addr, uint32_t size, int type)
+                       uint32_t addr, uint32_t size, int type)
 {
     VirtIODevice *vdev = to_virtio_device(pci_dev);
     int i;
 
     vdev-&gt;addr = addr;
     for (i = 0; i &lt; 3; i++) {
-register_ioport_write(addr, 20, 1 &lt;&lt; i, virtio_ioport_write, vdev);
-register_ioport_read(addr, 20, 1 &lt;&lt; i, virtio_ioport_read, vdev);
+        register_ioport_write(addr, 20, 1 &lt;&lt; i, virtio_ioport_write, vdev);
+        register_ioport_read(addr, 20, 1 &lt;&lt; i, virtio_ioport_read, vdev);
     }
 
     if (vdev-&gt;config_len) {
-register_ioport_write(addr + 20, vdev-&gt;config_len, 1,
-      virtio_config_writeb, vdev);
-register_ioport_write(addr + 20, vdev-&gt;config_len, 2,
-      virtio_config_writew, vdev);
-register_ioport_write(addr + 20, vdev-&gt;config_len, 4,
-      virtio_config_writel, vdev);
-register_ioport_read(addr + 20, vdev-&gt;config_len, 1,
-     virtio_config_readb, vdev);
-register_ioport_read(addr + 20, vdev-&gt;config_len, 2,
-     virtio_config_readw, vdev);
-register_ioport_read(addr + 20, vdev-&gt;config_len, 4,
-     virtio_config_readl, vdev);
-
-vdev-&gt;get_config(vdev, vdev-&gt;config);
+        register_ioport_write(addr + 20, vdev-&gt;config_len, 1,
+                              virtio_config_writeb, vdev);
+        register_ioport_write(addr + 20, vdev-&gt;config_len, 2,
+                              virtio_config_writew, vdev);
+        register_ioport_write(addr + 20, vdev-&gt;config_len, 4,
+                              virtio_config_writel, vdev);
+        register_ioport_read(addr + 20, vdev-&gt;config_len, 1,
+                             virtio_config_readb, vdev);
+        register_ioport_read(addr + 20, vdev-&gt;config_len, 2,
+                             virtio_config_readw, vdev);
+        register_ioport_read(addr + 20, vdev-&gt;config_len, 4,
+                             virtio_config_readl, vdev);
+
+        vdev-&gt;get_config(vdev, vdev-&gt;config);
     }
 }
 
 VirtQueue *virtio_add_queue(VirtIODevice *vdev, int queue_size,
-    void (*handle_output)(VirtIODevice *, VirtQueue *))
+                            void (*handle_output)(VirtIODevice *, VirtQueue *))
 {
     int i;
 
     for (i = 0; i &lt; VIRTIO_PCI_QUEUE_MAX; i++) {
-if (vdev-&gt;vq[i].vring.num == 0)
-    break;
+        if (vdev-&gt;vq[i].vring.num == 0)
+            break;
     }
 
     if (i == VIRTIO_PCI_QUEUE_MAX || queue_size &gt; VIRTQUEUE_MAX_SIZE)
-abort();
+        abort();
 
     vdev-&gt;vq[i].vring.num = queue_size;
     vdev-&gt;vq[i].handle_output = handle_output;
&lt; at &gt;&lt; at &gt; -508,8 +508,8 &lt; at &gt;&lt; at &gt; void virtio_notify(VirtIODevice *vdev, VirtQueue *vq)
 {
     /* Always notify when queue is empty */
     if ((vq-&gt;inuse || vq-&gt;vring.avail-&gt;idx != vq-&gt;last_avail_idx) &amp;&amp;
-(vq-&gt;vring.avail-&gt;flags &amp; VRING_AVAIL_F_NO_INTERRUPT))
-return;
+        (vq-&gt;vring.avail-&gt;flags &amp; VRING_AVAIL_F_NO_INTERRUPT))
+        return;
 
     vdev-&gt;isr |= 0x01;
     virtio_update_irq(vdev);
&lt; at &gt;&lt; at &gt; -536,19 +536,19 &lt; at &gt;&lt; at &gt; void virtio_save(VirtIODevice *vdev, QEMUFile *f)
     qemu_put_buffer(f, vdev-&gt;config, vdev-&gt;config_len);
 
     for (i = 0; i &lt; VIRTIO_PCI_QUEUE_MAX; i++) {
-if (vdev-&gt;vq[i].vring.num == 0)
-    break;
+        if (vdev-&gt;vq[i].vring.num == 0)
+            break;
     }
 
     qemu_put_be32(f, i);
 
     for (i = 0; i &lt; VIRTIO_PCI_QUEUE_MAX; i++) {
-if (vdev-&gt;vq[i].vring.num == 0)
-    break;
+        if (vdev-&gt;vq[i].vring.num == 0)
+            break;
 
-qemu_put_be32(f, vdev-&gt;vq[i].vring.num);
-qemu_put_be32s(f, &amp;vdev-&gt;vq[i].pfn);
-qemu_put_be16s(f, &amp;vdev-&gt;vq[i].last_avail_idx);
+        qemu_put_be32(f, vdev-&gt;vq[i].vring.num);
+        qemu_put_be32s(f, &amp;vdev-&gt;vq[i].pfn);
+        qemu_put_be16s(f, &amp;vdev-&gt;vq[i].last_avail_idx);
     }
 }
 
&lt; at &gt;&lt; at &gt; -569,29 +569,29 &lt; at &gt;&lt; at &gt; void virtio_load(VirtIODevice *vdev, QEMUFile *f)
     num = qemu_get_be32(f);
 
     for (i = 0; i &lt; num; i++) {
-vdev-&gt;vq[i].vring.num = qemu_get_be32(f);
-qemu_get_be32s(f, &amp;vdev-&gt;vq[i].pfn);
-qemu_get_be16s(f, &amp;vdev-&gt;vq[i].last_avail_idx);
-
-if (vdev-&gt;vq[i].pfn) {
-    size_t size;
-    target_phys_addr_t pa;
-
-    pa = (ram_addr_t)vdev-&gt;vq[i].pfn &lt;&lt; TARGET_PAGE_BITS;
-    size = virtqueue_size(vdev-&gt;vq[i].vring.num);
-    virtqueue_init(&amp;vdev-&gt;vq[i], virtio_map_gpa(pa, size));
-}
+        vdev-&gt;vq[i].vring.num = qemu_get_be32(f);
+        qemu_get_be32s(f, &amp;vdev-&gt;vq[i].pfn);
+        qemu_get_be16s(f, &amp;vdev-&gt;vq[i].last_avail_idx);
+
+        if (vdev-&gt;vq[i].pfn) {
+            size_t size;
+            target_phys_addr_t pa;
+
+            pa = (ram_addr_t)vdev-&gt;vq[i].pfn &lt;&lt; TARGET_PAGE_BITS;
+            size = virtqueue_size(vdev-&gt;vq[i].vring.num);
+            virtqueue_init(&amp;vdev-&gt;vq[i], virtio_map_gpa(pa, size));
+        }
     }
 
     virtio_update_irq(vdev);
 }
 
 VirtIODevice *virtio_init_pci(PCIBus *bus, const char *name,
-      uint16_t vendor, uint16_t device,
-      uint16_t subvendor, uint16_t subdevice,
-      uint8_t class_code, uint8_t subclass_code,
-      uint8_t pif, size_t config_size,
-      size_t struct_size)
+                              uint16_t vendor, uint16_t device,
+                              uint16_t subvendor, uint16_t subdevice,
+                              uint8_t class_code, uint8_t subclass_code,
+                              uint8_t pif, size_t config_size,
+                              size_t struct_size)
 {
     VirtIODevice *vdev;
     PCIDevice *pci_dev;
&lt; at &gt;&lt; at &gt; -599,9 +599,9 &lt; at &gt;&lt; at &gt; VirtIODevice *virtio_init_pci(PCIBus *bus, const char *name,
     uint32_t size;
 
     pci_dev = pci_register_device(bus, name, struct_size,
-  -1, NULL, NULL);
+                                  -1, NULL, NULL);
     if (!pci_dev)
-return NULL;
+        return NULL;
 
     vdev = to_virtio_device(pci_dev);
 
&lt; at &gt;&lt; at &gt; -633,16 +633,16 &lt; at &gt;&lt; at &gt; VirtIODevice *virtio_init_pci(PCIBus *bus, const char *name,
     vdev-&gt;name = name;
     vdev-&gt;config_len = config_size;
     if (vdev-&gt;config_len)
-vdev-&gt;config = qemu_mallocz(config_size);
+        vdev-&gt;config = qemu_mallocz(config_size);
     else
-vdev-&gt;config = NULL;
+        vdev-&gt;config = NULL;
 
     size = 20 + config_size;
     if (size &amp; (size-1))
         size = 1 &lt;&lt; fls(size);
 
     pci_register_io_region(pci_dev, 0, size, PCI_ADDRESS_SPACE_IO,
-   virtio_map);
+                           virtio_map);
     qemu_register_reset(virtio_reset, vdev);
 
     return vdev;
diff --git a/qemu/hw/virtio.h b/qemu/hw/virtio.h
index 15f020b..40c9e14 100644
--- a/qemu/hw/virtio.h
+++ b/qemu/hw/virtio.h
&lt; at &gt;&lt; at &gt; -22,13 +22,13 &lt; at &gt;&lt; at &gt;
 
 /* Status byte for guest to report progress, and synchronize features. */
 /* We have seen device and processed generic fields (VIRTIO_CONFIG_F_VIRTIO) */
-#define VIRTIO_CONFIG_S_ACKNOWLEDGE1
+#define VIRTIO_CONFIG_S_ACKNOWLEDGE     1
 /* We have found a driver for the device. */
-#define VIRTIO_CONFIG_S_DRIVER2
+#define VIRTIO_CONFIG_S_DRIVER          2
 /* Driver has used its parts of the config, and is happy */
-#define VIRTIO_CONFIG_S_DRIVER_OK4
+#define VIRTIO_CONFIG_S_DRIVER_OK       4
 /* We've given up on this device. */
-#define VIRTIO_CONFIG_S_FAILED0x80
+#define VIRTIO_CONFIG_S_FAILED          0x80
 
 /* We notify when the ring is completely used, even if the guest is supressing
  * callbacks */
&lt; at &gt;&lt; at &gt; -37,14 +37,14 &lt; at &gt;&lt; at &gt;
 /* from Linux's linux/virtio_ring.h */
 
 /* This marks a buffer as continuing via the next field. */
-#define VRING_DESC_F_NEXT1
+#define VRING_DESC_F_NEXT       1
 /* This marks a buffer as write-only (otherwise read-only). */
-#define VRING_DESC_F_WRITE2
+#define VRING_DESC_F_WRITE      2
 
 /* This means don't notify other side when buffer added. */
-#define VRING_USED_F_NO_NOTIFY1
+#define VRING_USED_F_NO_NOTIFY  1
 /* This means don't interrupt guest when buffer consumed. */
-#define VRING_AVAIL_F_NO_INTERRUPT1
+#define VRING_AVAIL_F_NO_INTERRUPT      1
 
 typedef struct VirtQueue VirtQueue;
 typedef struct VirtIODevice VirtIODevice;
&lt; at &gt;&lt; at &gt; -105,7 +105,7 &lt; at &gt;&lt; at &gt; typedef struct VirtQueueElement
     struct iovec out_sg[VIRTQUEUE_MAX_SIZE];
 } VirtQueueElement;
 
-#define VIRTIO_PCI_QUEUE_MAX16
+#define VIRTIO_PCI_QUEUE_MAX 16
 
 struct VirtIODevice
 {
&lt; at &gt;&lt; at &gt; -127,21 +127,21 &lt; at &gt;&lt; at &gt; struct VirtIODevice
 };
 
 VirtIODevice *virtio_init_pci(PCIBus *bus, const char *name,
-      uint16_t vendor, uint16_t device,
-      uint16_t subvendor, uint16_t subdevice,
-      uint8_t class_code, uint8_t subclass_code,
-      uint8_t pif, size_t config_size,
-      size_t struct_size);
+                              uint16_t vendor, uint16_t device,
+                              uint16_t subvendor, uint16_t subdevice,
+                              uint8_t class_code, uint8_t subclass_code,
+                              uint8_t pif, size_t config_size,
+                              size_t struct_size);
 
 VirtQueue *virtio_add_queue(VirtIODevice *vdev, int queue_size,
-    void (*handle_output)(VirtIODevice *,
-  VirtQueue *));
+                            void (*handle_output)(VirtIODevice *,
+                                                  VirtQueue *));
 
 void virtqueue_push(VirtQueue *vq, const VirtQueueElement *elem,
-    unsigned int len);
+                    unsigned int len);
 void virtqueue_flush(VirtQueue *vq, unsigned int count);
 void virtqueue_fill(VirtQueue *vq, const VirtQueueElement *elem,
-    unsigned int len, unsigned int idx);
+                    unsigned int len, unsigned int idx);
 
 int virtqueue_pop(VirtQueue *vq, VirtQueueElement *elem);
 int virtqueue_avail_bytes(VirtQueue *vq, int in_bytes, int out_bytes);
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo&lt; at &gt;vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

</description>
    <dc:creator>Anthony Liguori</dc:creator>
    <dc:date>2008-12-03T17:26:55</dc:date>
  </item>
  <item rdf:about="http://comments.gmane.org/gmane.comp.emulators.kvm.devel/25519">
    <title>[PATCH] really remove a slow when a user ask us so</title>
    <link>http://comments.gmane.org/gmane.comp.emulators.kvm.devel/25519</link>
    <description>Right now, KVM does not remove a slot when we do a
register ioctl for size 0 (would be the expected behaviour).

Instead, we only mark it as empty, but keep all bitmaps
and allocated data structures present. It completely
nullifies our chances of reusing that same slot again
for mapping a different piece of memory.

In this patch, we destroy rmaps, and vfree() the
pointers that used to hold the dirty bitmap, rmap
and lpage_info structures.

qemu's VGA optimization won't work without this patch

Signed-off-by: Glauber Costa &lt;glommer&lt; at &gt;redhat.com&gt;
---
 virt/kvm/kvm_main.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index e41d39d..fd9cc79 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
&lt; at &gt;&lt; at &gt; -1020,7 +1020,10 &lt; at &gt;&lt; at &gt; int __kvm_set_memory_region(struct kvm *kvm,
 goto out_free;
 }
 
-kvm_free_physmem_slot(&amp;old, &amp;new);
+kvm_free_physmem_slot(&amp;old, npages ? &amp;new : NULL);
+/* Slot deletion case: we have to update the current slot */
+if (!npages)
+*memslot = old;
 #ifdef CONFIG_DMAR
 /* map the pages in iommu page table */
 r = kvm_iommu_map_pages(kvm, base_gfn, npages);
</description>
    <dc:creator>Glauber Costa</dc:creator>
    <dc:date>2008-12-03T15:40:51</dc:date>
  </item>
  <item rdf:about="http://comments.gmane.org/gmane.comp.emulators.kvm.devel/25517">
    <title>virtio_pci module refcount?</title>
    <link>http://comments.gmane.org/gmane.comp.emulators.kvm.devel/25517</link>
    <description>Hello.

Yesterday I experimented with kvm guests (the "hangs"
issue), and by a chance rmmod'ed the "wrong" module -
it was virtio_pci.  Which resulted in an immediate
OOPs and hang, like this:

WARNING: at drivers/base/core.c:122 device_release+0x5f/0x70()
Device 'virtio1' does not have a release() function, it is broken and must be
fixed.
Modules linked in: ext3 jbd mbcache acpiphp dock pci_hotplug virtio_net
virtio_blk virtio_pci(-) virtio_ring virtio

Pid: 361, comm: rmmod Tainted: G S        2.6.27-i686smp #2.6.27.7
 [&lt;c012b81f&gt;] warn_slowpath+0x6f/0xa0
 [&lt;c0110030&gt;] prepare_set+0x30/0x80
 [&lt;c012067e&gt;] __wake_up+0x3e/0x60
 [&lt;c01d1d25&gt;] release_sysfs_dirent+0x45/0xb0
 ...


It looks like virtio_pci module should either use proper refcounting
as other modules, or really should be unloadable...

Thanks!

/mjt
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo&lt; at &gt;vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

</description>
    <dc:creator>Michael Tokarev</dc:creator>
    <dc:date>2008-12-03T12:51:33</dc:date>
  </item>
  <item rdf:about="http://comments.gmane.org/gmane.comp.emulators.kvm.devel/25516">
    <title>[ kvm-Bugs-2353811 ] Solaris 10 guest unstable</title>
    <link>http://comments.gmane.org/gmane.comp.emulators.kvm.devel/25516</link>
    <description>Bugs item #2353811, was opened at 2008-11-27 16:44
Message generated for change (Comment added) made by krwi
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&amp;atid=893831&amp;aid=2353811&amp;group_id=180599

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: None
Group: None
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: krwi (krwi)
Assigned to: Nobody/Anonymous (nobody)
Summary: Solaris 10 guest unstable

Initial Comment:
After several minutes of normal work Solaris guest hangs for few seconds. Sometimes system hangs completely and kvm proccess must be killed. Besides this host CPU utilization ist much higher than could be expected from guest uasage.

Host:
2x Quad Core Opteron 8356
64GB RAM
OS: Gentoo 64bit
kernel: 2.6.26
KVM-79 (modules from package not from kernel)

Guest:
Solaris 10u5 started with command:
kvm -M pc -m 4096 -smp 2 -name despina -monitor pty -boot c -drive file=/dev/MDvg_SystemVM/despina,if=ide,index=0,boot=on -drive file=/dev/MDvg_DataVM/despina30,if=ide,index=1 -net nic,macaddr=00:16:3e:5f:64:10,vlan=0,model=e1000 -net tap,fd=38,script=,vlan=0,ifname=vnet8 -serial pty -parallel none

Usind -no-acpi switch doesn't help.

On the same host I running several other guests systems including Win2003
Server sp2 32 and 64bit, WinXP sp2 32bit, Gentoo 64bit and Debian Lenny 32bit without problem
like this.

----------------------------------------------------------------------

Comment By: krwi (krwi)
Date: 2008-12-03 13:25

Message:
Yes it's 64bit.

KVM was installed from Gentoo portage with following patches:
01_all_qemu-configure.patch
02_all_qemu-kvm-cmdline.patch
03_all_qemu-kvm.patch
04_all_libkvm-no-kernel.patch
05_all_qemu-ifup_ifdown.patch
07_all_kernel-longmode.patch
08_all_qemu-kvm-doc.patch
09_all_qemu-no-blobs.patch

I'll try with 32bit verision, thanks for suggestion.

----------------------------------------------------------------------

Comment By: Technologov (technologov)
Date: 2008-12-02 14:46

Message:
From my testing, Yes, 64-bit Solaris guest is problematic, and requires
patching for KVM to work, but Solaris 32-bit guest should work fine.

Can you tell us which Solaris you use ? (32 or 64-bit)

-Alexey

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&amp;atid=893831&amp;aid=2353811&amp;group_id=180599
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo&lt; at &gt;vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

</description>
    <dc:creator>SourceForge.net</dc:creator>
    <dc:date>2008-12-03T12:25:27</dc:date>
  </item>
  <item rdf:about="http://comments.gmane.org/gmane.comp.emulators.kvm.devel/25506">
    <title>[PATCH] register page alignment memory for MMIO of assigned device</title>
    <link>http://comments.gmane.org/gmane.comp.emulators.kvm.devel/25506</link>
    <description>MMIO of assigned device is registered as memory slot. Size of memory slot in KVM must be page size multiple. But MMIO of some devices (e.g. EHCI controller) is not page size mutiple, so it fails to register these MMIOs, thus device assignment fails. In order to solve it, need to register target page alignment memory for these MMIOs.

Signed-off-by: Weidong Han &lt;weidong.han&lt; at &gt;intel.com&gt;
---
 qemu/hw/device-assignment.c |   12 +++++++++---
 1 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/qemu/hw/device-assignment.c b/qemu/hw/device-assignment.c
index eaff09e..4a38a22 100644
--- a/qemu/hw/device-assignment.c
+++ b/qemu/hw/device-assignment.c
&lt; at &gt;&lt; at &gt; -157,12 +157,18 &lt; at &gt;&lt; at &gt; static void assigned_dev_iomem_map(PCIDevice *pci_dev, int region_num,
     region-&gt;e_physbase = e_phys;
     region-&gt;e_size = e_size;
 
-    if (!first_map)
-kvm_destroy_phys_mem(kvm_context, old_ephys, old_esize);
+    if (!first_map) {
+        int slot = get_slot(old_ephys);
+        if (slot != -1)
+    kvm_destroy_phys_mem(kvm_context, old_ephys,
+                                 TARGET_PAGE_ALIGN(old_esize));
+    }
 
     if (e_size &gt; 0)
 ret = kvm_register_phys_mem(kvm_context, e_phys,
-                                        region-&gt;u.r_virtbase, e_size, 0);
+                                    region-&gt;u.r_virtbase,
+                                    TARGET_PAGE_ALIGN(e_size), 0);
+
     if (ret != 0) {
 fprintf(stderr, "%s: Error: create new mapping failed\n", __func__);
 exit(1);
</description>
    <dc:creator>Han, Weidong</dc:creator>
    <dc:date>2008-12-03T07:25:55</dc:date>
  </item>
  <item rdf:about="http://comments.gmane.org/gmane.comp.emulators.kvm.devel/25492">
    <title>[PATCH 0 of 6] PowerPC KVM patches for 2.6.29</title>
    <link>http://comments.gmane.org/gmane.comp.emulators.kvm.devel/25492</link>
    <description>Hi Avi, here's the latest batch of PowerPC kernel patches.

The first set dramatically improve performance. Most importantly, we add
support for large host pages with KVM (i.e. PAGE_SHIFT &gt; 12). (Large *guest*
pages have already been supported since day 1, since the guest kernel uses
them for the linear map.) Followup patches further improve performance by
changing how we manage the shadow TLB.

The last two add some accounting code to easily discover performance
bottlenecks. This is especially important since the 440 core lacks performance
monitoring hardware.

These patches, in conjunction with 64KB pages on guest and host, get us to 96%
of native performance for compute-bound workloads, which I'm pretty happy
with. See http://kvm.qumranet.com/kvmwiki/PowerPC_Exittimings for more
details (those statistics were gathered using the accounting patches).

These have been tested pretty thoroughly for several weeks. Please apply for
2.6.29. Thanks!

-Hollis
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo&lt; at &gt;vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

</description>
    <dc:creator>Hollis Blanchard</dc:creator>
    <dc:date>2008-12-02T21:51:52</dc:date>
  </item>
  <item rdf:about="http://comments.gmane.org/gmane.comp.emulators.kvm.devel/25475">
    <title>[BUG] virtio-pci queue allocation not page-aligned</title>
    <link>http://comments.gmane.org/gmane.comp.emulators.kvm.devel/25475</link>
    <description>I just spent a number of hours tracking this one down, and I'm not too
thrilled about it. vp_find_vq() does the memory allocation for virtio
PCI rings, and it uses kzalloc() to do it. This is bad because the ring
memory *must* be page-aligned.

According to Anthony, at the time this code was written, various slab
allocators were checked and all happened to return page-aligned buffers.
So how did I hit a problem? I had enabled CONFIG_SLUB_DEBUG_ON while
investigating an unrelated problem, which offset the address by 64
bytes.

One option is to add a BUG_ON(addr &amp; ~PAGE_MASK) to vp_find_vq(). That's
better than nothing, but still stinks.

Another is to use Kconfig to express that slab debugging breaks virtio.
Also pretty lame IMHO, will look pretty funny in the Kconfig file, and
that only solves today's problem. Another slab allocator or a change in
behavior of an existing allocator could mean that "ordinary" allocations
also become non-page-aligned.

Finally, we could use the interface intended for exactly this purpose:
the page allocator. If there's some problem with high memory, don't
allocate it with GFP_HIGHMEM.

</description>
    <dc:creator>Hollis Blanchard</dc:creator>
    <dc:date>2008-12-02T19:08:21</dc:date>
  </item>
  <item rdf:about="http://comments.gmane.org/gmane.comp.emulators.kvm.devel/25471">
    <title>powerpc kvm-userspace build fixes</title>
    <link>http://comments.gmane.org/gmane.comp.emulators.kvm.devel/25471</link>
    <description>
These patches fix the kvm-userspace qemu build after a recent merge with
upstream qemu.

I'm also seeing a build dependency issue with dyngen-opc.h that I don't see
upstream. I haven't sorted that out yet, but "make qemu/ppcemb-softmmu/dyngen-opc.h" first works around the problem.

-Hollis
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo&lt; at &gt;vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

</description>
    <dc:creator>Hollis Blanchard</dc:creator>
    <dc:date>2008-12-02T15:37:07</dc:date>
  </item>
  <item rdf:about="http://comments.gmane.org/gmane.comp.emulators.kvm.devel/25468">
    <title>[ kvm-Bugs-2318236 ] SCSI debug</title>
    <link>http://comments.gmane.org/gmane.comp.emulators.kvm.devel/25468</link>
    <description>Bugs item #2318236, was opened at 2008-11-20 13:41
Message generated for change (Comment added) made by ryandbair
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&amp;atid=893831&amp;aid=2318236&amp;group_id=180599

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: None
Group: None
Priority: 5
Private: No
Submitted By: Ryan Bair (ryandbair)
Assigned to: Nobody/Anonymous (nobody)
Summary: SCSI debug

Initial Comment:
Here is the stdout with SCSI_DEBUG enabled. The guest is Windows Server 2003 R2 x64 with an emulated scsi device being served from a 36GB raw file on a Debian Lenny host with KVM-79. I get the mentioned error on both quick and full format.

Let me know if there is anything else I can provide that would be of assistance.

----------------------------------------------------------------------

Date: 2008-12-02 09:52

Message:
Sorry, I meant to reply to bug 2171940 but got a bit confused while
attempting to attach a file. 

I'm seeing the same issue as in that bug. Setup is extremely unstable with
SCSI drives and formatting the drive always results in an error saying that
the drive could not be formatted and it may be faulty. I've also tried
preformatting the drive, in that case it eventually gives a BSOD while
copying files with ntfs.sys being the faulting module. I've retried a the
setup about 6 times and the results are consistent. 

----------------------------------------------------------------------

Comment By: Avi Kivity (avik)
Date: 2008-11-23 13:46

Message:
What exactly is the problem you're seeing?

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&amp;atid=893831&amp;aid=2318236&amp;group_id=180599
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo&lt; at &gt;vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

</description>
    <dc:creator>SourceForge.net</dc:creator>
    <dc:date>2008-12-02T14:52:15</dc:date>
  </item>
  <item rdf:about="http://comments.gmane.org/gmane.comp.emulators.kvm.devel/25467">
    <title>[PATCH 13/13] KVM: support device assignment</title>
    <link>http://comments.gmane.org/gmane.comp.emulators.kvm.devel/25467</link>
    <description>Support device assignment, it can be used in device hotplug.

Signed-off-by: Weidong Han &lt;weidong.han&lt; at &gt;intel.com&gt;
---
 include/linux/kvm.h      |    5 +++++
 include/linux/kvm_host.h |    8 ++++++++
 virt/kvm/kvm_main.c      |   42 ++++++++++++++++++++++++++++++++++++++++++
 virt/kvm/vtd.c           |   24 ++++++++++++++++++++++++
 4 files changed, 79 insertions(+), 0 deletions(-)

diff --git a/include/linux/kvm.h b/include/linux/kvm.h
index 0997e6f..2904276 100644
--- a/include/linux/kvm.h
+++ b/include/linux/kvm.h
&lt; at &gt;&lt; at &gt; -395,6 +395,9 &lt; at &gt;&lt; at &gt; struct kvm_trace_rec {
 #if defined(CONFIG_X86)
 #define KVM_CAP_DEVICE_MSI 20
 #endif
+#if defined(CONFIG_X86)||defined(CONFIG_IA64)
+#define KVM_CAP_DEVICE_DEASSIGNMENT 21
+#endif
 
 /*
  * ioctls for VM fds
&lt; at &gt;&lt; at &gt; -428,6 +431,8 &lt; at &gt;&lt; at &gt; struct kvm_trace_rec {
    struct kvm_assigned_pci_dev)
 #define KVM_ASSIGN_IRQ _IOR(KVMIO, 0x70, \
     struct kvm_assigned_irq)
+#define KVM_DEASSIGN_PCI_DEVICE _IOR(KVMIO, 0x71, \
+     struct kvm_assigned_pci_dev)
 
 /*
  * ioctls for vcpu fds
diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
index aeabd32..cb1d404 100644
--- a/include/linux/kvm_host.h
+++ b/include/linux/kvm_host.h
&lt; at &gt;&lt; at &gt; -333,6 +333,8 &lt; at &gt;&lt; at &gt; int kvm_iommu_map_guest(struct kvm *kvm);
 int kvm_iommu_unmap_guest(struct kvm *kvm);
 int kvm_assign_device(struct kvm *kvm,
       struct kvm_assigned_dev_kernel *assigned_dev);
+int kvm_deassign_device(struct kvm *kvm,
+struct kvm_assigned_dev_kernel *assigned_dev);
 #else /* CONFIG_DMAR */
 static inline int kvm_iommu_map_pages(struct kvm *kvm,
       gfn_t base_gfn,
&lt; at &gt;&lt; at &gt; -356,6 +358,12 &lt; at &gt;&lt; at &gt; static inline int kvm_assign_device(struct kvm *kvm,
 {
 return 0;
 }
+
+static inline int kvm_deassign_device(struct kvm *kvm,
+struct kvm_assigned_dev_kernel *assigned_dev)
+{
+return 0;
+}
 #endif /* CONFIG_DMAR */
 
 static inline void kvm_guest_enter(void)
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 43a5236..fe6aba0 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
&lt; at &gt;&lt; at &gt; -499,6 +499,35 &lt; at &gt;&lt; at &gt; out_free:
 }
 #endif
 
+#ifdef KVM_CAP_DEVICE_DEASSIGNMENT
+static int kvm_vm_ioctl_deassign_device(struct kvm *kvm,
+struct kvm_assigned_pci_dev *assigned_dev)
+{
+int r = 0;
+struct kvm_assigned_dev_kernel *match;
+
+mutex_lock(&amp;kvm-&gt;lock);
+
+match = kvm_find_assigned_dev(&amp;kvm-&gt;arch.assigned_dev_head,
+      assigned_dev-&gt;assigned_dev_id);
+if (!match) {
+printk(KERN_INFO "%s: device hasn't been assigned before, "
+  "so cannot be deassigned\n", __func__);
+r = -EINVAL;
+goto out;
+}
+
+if (assigned_dev-&gt;flags &amp; KVM_DEV_ASSIGN_ENABLE_IOMMU)
+kvm_deassign_device(kvm, match);
+
+kvm_free_assigned_device(kvm, match);
+
+out:
+mutex_unlock(&amp;kvm-&gt;lock);
+return r;
+}
+#endif
+
 static inline int valid_vcpu(int n)
 {
 return likely(n &gt;= 0 &amp;&amp; n &lt; KVM_MAX_VCPUS);
&lt; at &gt;&lt; at &gt; -1838,6 +1867,19 &lt; at &gt;&lt; at &gt; static long kvm_vm_ioctl(struct file *filp,
 break;
 }
 #endif
+#ifdef KVM_CAP_DEVICE_DEASSIGNMENT
+case KVM_DEASSIGN_PCI_DEVICE: {
+struct kvm_assigned_pci_dev assigned_dev;
+
+r = -EFAULT;
+if (copy_from_user(&amp;assigned_dev, argp, sizeof assigned_dev))
+goto out;
+r = kvm_vm_ioctl_deassign_device(kvm, &amp;assigned_dev);
+if (r)
+goto out;
+break;
+}
+#endif
 default:
 r = kvm_arch_vm_ioctl(filp, ioctl, arg);
 }
diff --git a/virt/kvm/vtd.c b/virt/kvm/vtd.c
index 44bb58a..174ea1f 100644
--- a/virt/kvm/vtd.c
+++ b/virt/kvm/vtd.c
&lt; at &gt;&lt; at &gt; -116,6 +116,30 &lt; at &gt;&lt; at &gt; int kvm_assign_device(struct kvm *kvm,
 return 0;
 }
 
+int kvm_deassign_device(struct kvm *kvm,
+struct kvm_assigned_dev_kernel *assigned_dev)
+{
+struct dmar_domain *domain = kvm-&gt;arch.intel_iommu_domain;
+struct pci_dev *pdev = NULL;
+
+/* check if iommu exists and in use */
+if (!domain)
+return 0;
+
+pdev = assigned_dev-&gt;dev;
+if (pdev == NULL)
+return -ENODEV;
+
+intel_iommu_detach_device(domain, pdev);
+
+printk(KERN_DEBUG "deassign device: host bdf = %x:%x:%x\n",
+assigned_dev-&gt;host_busnr,
+PCI_SLOT(assigned_dev-&gt;host_devfn),
+PCI_FUNC(assigned_dev-&gt;host_devfn));
+
+return 0;
+}
+
 int kvm_iommu_map_guest(struct kvm *kvm)
 {
 int r;
</description>
    <dc:creator>Han, Weidong</dc:creator>
    <dc:date>2008-12-02T14:23:12</dc:date>
  </item>
  <item rdf:about="http://comments.gmane.org/gmane.comp.emulators.kvm.devel/25466">
    <title>[PATCH 11/13] check agaw is sufficient for mapped memory</title>
    <link>http://comments.gmane.org/gmane.comp.emulators.kvm.devel/25466</link>
    <description>virtual machine domain may own multiple devices from different iommus, and agaw may be different across iommus. Because one domain used one VT-d page table, it's necessary to check if agaw is sufficient for mapped memory.

Signed-off-by: Weidong Han &lt;weidong.han&lt; at &gt;intel.com&gt;
---
 drivers/pci/intel-iommu.c     |   63 +++++++++++++++++++++++++++++++++++++++++
 include/linux/dma_remapping.h |    1 +
 2 files changed, 64 insertions(+), 0 deletions(-)

diff --git a/drivers/pci/intel-iommu.c b/drivers/pci/intel-iommu.c
index 0db77e2..a8c2e58 100644
--- a/drivers/pci/intel-iommu.c
+++ b/drivers/pci/intel-iommu.c
&lt; at &gt;&lt; at &gt; -2552,6 +2552,25 &lt; at &gt;&lt; at &gt; static void vm_domain_remove_all_dev_info(struct dmar_domain *domain)
 /* domain id for virtual machine, it won't be set in context */
 static unsigned long vm_domid;
 
+static int vm_domain_min_agaw(struct dmar_domain *domain)
+{
+struct dmar_drhd_unit *drhd;
+struct intel_iommu *iommu;
+int min_agaw = domain-&gt;agaw;
+
+for_each_drhd_unit(drhd) {
+if (drhd-&gt;ignored)
+continue;
+iommu = drhd-&gt;iommu;
+
+if (test_bit(iommu-&gt;seq_id, &amp;domain-&gt;iommu_bmp))
+if (min_agaw &gt; iommu-&gt;agaw)
+min_agaw = iommu-&gt;agaw;
+}
+
+return min_agaw;
+}
+
 static struct dmar_domain *iommu_alloc_vm_domain(void)
 {
 struct dmar_domain *domain;
&lt; at &gt;&lt; at &gt; -2563,6 +2582,7 &lt; at &gt;&lt; at &gt; static struct dmar_domain *iommu_alloc_vm_domain(void)
 domain-&gt;id = vm_domid++;
 domain-&gt;iommu_count = 0;
 domain-&gt;iommu_coherency = 0;
+domain-&gt;max_addr = 0;
 memset(&amp;domain-&gt;iommu_bmp, 0, sizeof(unsigned long));
 domain-&gt;flags = DOMAIN_FLAG_VIRTUAL_MACHINE;
 
&lt; at &gt;&lt; at &gt; -2675,6 +2695,9 &lt; at &gt;&lt; at &gt; EXPORT_SYMBOL_GPL(intel_iommu_free_domain);
 int intel_iommu_attach_device(struct dmar_domain *domain,
       struct pci_dev *pdev)
 {
+struct intel_iommu *iommu;
+int addr_width;
+u64 end;
 int ret;
 
 /* normally pdev is not mapped */
&lt; at &gt;&lt; at &gt; -2690,6 +2713,21 &lt; at &gt;&lt; at &gt; int intel_iommu_attach_device(struct dmar_domain *domain,
 }
 }
 
+iommu = device_find_matched_iommu(pdev-&gt;bus-&gt;number, pdev-&gt;devfn);
+if (!iommu)
+return -ENODEV;
+
+/* check if this iommu agaw is sufficient for max mapped address */
+addr_width = agaw_to_width(iommu-&gt;agaw);
+end = DOMAIN_MAX_ADDR(addr_width);
+end = end &amp; VTD_PAGE_MASK;
+if (end &lt; domain-&gt;max_addr) {
+printk(KERN_ERR "%s: iommu agaw (%d) is not "
+       "sufficient for the mapped address (%llx)\n",
+       __func__, iommu-&gt;agaw, domain-&gt;max_addr);
+return -EFAULT;
+}
+
 ret = domain_context_mapping(domain, pdev);
 if (ret)
 return ret;
&lt; at &gt;&lt; at &gt; -2709,7 +2747,29 &lt; at &gt;&lt; at &gt; EXPORT_SYMBOL_GPL(intel_iommu_detach_device);
 int intel_iommu_map_address(struct dmar_domain *domain, dma_addr_t iova,
     u64 hpa, size_t size, int prot)
 {
+u64 max_addr;
+int addr_width;
 int ret;
+
+max_addr = (iova &amp; VTD_PAGE_MASK) + VTD_PAGE_ALIGN(size);
+if (domain-&gt;max_addr &lt; max_addr) {
+int min_agaw;
+u64 end;
+
+/* check if minimum agaw is sufficient for mapped address */
+min_agaw = vm_domain_min_agaw(domain);
+addr_width = agaw_to_width(min_agaw);
+end = DOMAIN_MAX_ADDR(addr_width);
+end = end &amp; VTD_PAGE_MASK;
+if (end &lt; max_addr) {
+printk(KERN_ERR "%s: iommu agaw (%d) is not "
+       "sufficient for the mapped address (%llx)\n",
+       __func__, min_agaw, max_addr);
+return -EFAULT;
+}
+domain-&gt;max_addr = max_addr;
+}
+
 ret = domain_page_mapping(domain, iova, hpa, size, prot);
 return ret;
 }
&lt; at &gt;&lt; at &gt; -2724,6 +2784,9 &lt; at &gt;&lt; at &gt; void intel_iommu_unmap_address(struct dmar_domain *domain,
 base = iova &amp; VTD_PAGE_MASK;
 size = VTD_PAGE_ALIGN(size);
 dma_pte_clear_range(domain, base, base + size);
+
+if (domain-&gt;max_addr == base + size)
+domain-&gt;max_addr = base;
 }
 EXPORT_SYMBOL_GPL(intel_iommu_unmap_address);
 
diff --git a/include/linux/dma_remapping.h b/include/linux/dma_remapping.h
index f6925c5..880fa17 100644
--- a/include/linux/dma_remapping.h
+++ b/include/linux/dma_remapping.h
&lt; at &gt;&lt; at &gt; -187,6 +187,7 &lt; at &gt;&lt; at &gt; struct dmar_domain {
 
 intiommu_coherency;/* iommu access is coherent or not */
 intiommu_count;/* reference count of iommu */
+u64max_addr;/* maximum mapped address */
 };
 
 /* PCI domain-device relationship */
</description>
    <dc:creator>Han, Weidong</dc:creator>
    <dc:date>2008-12-02T14:23:04</dc:date>
  </item>
  <item rdf:about="http://comments.gmane.org/gmane.comp.emulators.kvm.devel/25465">
    <title>[PATCH 12/13] KVM: use the new intel iommu APIs</title>
    <link>http://comments.gmane.org/gmane.comp.emulators.kvm.devel/25465</link>
    <description>intel iommu APIs are updated, use the new APIs.

In addition, change kvm_iommu_map_guest() to just create the domain, let kvm_iommu_assign_device() assign device.

Signed-off-by: Weidong Han &lt;weidong.han&lt; at &gt;intel.com&gt;
---
 include/linux/kvm_host.h |   15 +++++--
 virt/kvm/kvm_main.c      |    7 +++-
 virt/kvm/vtd.c           |   98 ++++++++++++++++++++++++++--------------------
 3 files changed, 71 insertions(+), 49 deletions(-)

diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
index 8091a4d..aeabd32 100644
--- a/include/linux/kvm_host.h
+++ b/include/linux/kvm_host.h
&lt; at &gt;&lt; at &gt; -329,9 +329,10 &lt; at &gt;&lt; at &gt; void kvm_free_irq_source_id(struct kvm *kvm, int irq_source_id);
 #ifdef CONFIG_DMAR
 int kvm_iommu_map_pages(struct kvm *kvm, gfn_t base_gfn,
 unsigned long npages);
-int kvm_iommu_map_guest(struct kvm *kvm,
-struct kvm_assigned_dev_kernel *assigned_dev);
+int kvm_iommu_map_guest(struct kvm *kvm);
 int kvm_iommu_unmap_guest(struct kvm *kvm);
+int kvm_assign_device(struct kvm *kvm,
+      struct kvm_assigned_dev_kernel *assigned_dev);
 #else /* CONFIG_DMAR */
 static inline int kvm_iommu_map_pages(struct kvm *kvm,
       gfn_t base_gfn,
&lt; at &gt;&lt; at &gt; -340,9 +341,7 &lt; at &gt;&lt; at &gt; static inline int kvm_iommu_map_pages(struct kvm *kvm,
 return 0;
 }
 
-static inline int kvm_iommu_map_guest(struct kvm *kvm,
-      struct kvm_assigned_dev_kernel
-      *assigned_dev)
+static inline int kvm_iommu_map_guest(struct kvm *kvm)
 {
 return -ENODEV;
 }
&lt; at &gt;&lt; at &gt; -351,6 +350,12 &lt; at &gt;&lt; at &gt; static inline int kvm_iommu_unmap_guest(struct kvm *kvm)
 {
 return 0;
 }
+
+static inline int kvm_assign_device(struct kvm *kvm,
+struct kvm_assigned_dev_kernel *assigned_dev)
+{
+return 0;
+}
 #endif /* CONFIG_DMAR */
 
 static inline void kvm_guest_enter(void)
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 8dab7ce..43a5236 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
&lt; at &gt;&lt; at &gt; -472,7 +472,12 &lt; at &gt;&lt; at &gt; static int kvm_vm_ioctl_assign_device(struct kvm *kvm,
 list_add(&amp;match-&gt;list, &amp;kvm-&gt;arch.assigned_dev_head);
 
 if (assigned_dev-&gt;flags &amp; KVM_DEV_ASSIGN_ENABLE_IOMMU) {
-r = kvm_iommu_map_guest(kvm, match);
+if (!kvm-&gt;arch.intel_iommu_domain) {
+r = kvm_iommu_map_guest(kvm);
+if (r)
+goto out_list_del;
+}
+r = kvm_assign_device(kvm, match);
 if (r)
 goto out_list_del;
 }
diff --git a/virt/kvm/vtd.c b/virt/kvm/vtd.c
index a770874..44bb58a 100644
--- a/virt/kvm/vtd.c
+++ b/virt/kvm/vtd.c
&lt; at &gt;&lt; at &gt; -45,20 +45,18 &lt; at &gt;&lt; at &gt; int kvm_iommu_map_pages(struct kvm *kvm,
 
 for (i = 0; i &lt; npages; i++) {
 /* check if already mapped */
-pfn = (pfn_t)intel_iommu_iova_to_pfn(domain,
-     gfn_to_gpa(gfn));
-if (pfn)
+if (intel_iommu_iova_to_phys(domain,
+     gfn_to_gpa(gfn)))
 continue;
 
 pfn = gfn_to_pfn(kvm, gfn);
-r = intel_iommu_page_mapping(domain,
-     gfn_to_gpa(gfn),
-     pfn_to_hpa(pfn),
-     PAGE_SIZE,
-     DMA_PTE_READ |
-     DMA_PTE_WRITE);
+r = intel_iommu_map_address(domain,
+    gfn_to_gpa(gfn),
+    pfn_to_hpa(pfn),
+    PAGE_SIZE,
+    DMA_PTE_READ | DMA_PTE_WRITE);
 if (r) {
-printk(KERN_ERR "kvm_iommu_map_pages:"
+printk(KERN_ERR "kvm_iommu_map_address:"
        "iommu failed to map pfn=%lx\n", pfn);
 goto unmap_pages;
 }
&lt; at &gt;&lt; at &gt; -86,50 +84,55 &lt; at &gt;&lt; at &gt; static int kvm_iommu_map_memslots(struct kvm *kvm)
 return r;
 }
 
-int kvm_iommu_map_guest(struct kvm *kvm,
-struct kvm_assigned_dev_kernel *assigned_dev)
+int kvm_assign_device(struct kvm *kvm,
+      struct kvm_assigned_dev_kernel *assigned_dev)
 {
 struct pci_dev *pdev = NULL;
+struct dmar_domain *domain = kvm-&gt;arch.intel_iommu_domain;
 int r;
 
-if (!intel_iommu_found()) {
-printk(KERN_ERR "%s: intel iommu not found\n", __func__);
+/* check if iommu exists and in use */
+if (!domain)
+return 0;
+
+pdev = assigned_dev-&gt;dev;
+if (pdev == NULL)
 return -ENODEV;
+
+r = intel_iommu_attach_device(domain, pdev);
+if (r) {
+printk(KERN_ERR "assign device %x:%x.%x failed",
+pdev-&gt;bus-&gt;number,
+PCI_SLOT(pdev-&gt;devfn),
+PCI_FUNC(pdev-&gt;devfn));
+return r;
 }
 
-printk(KERN_DEBUG "VT-d direct map: host bdf = %x:%x:%x\n",
-       assigned_dev-&gt;host_busnr,
-       PCI_SLOT(assigned_dev-&gt;host_devfn),
-       PCI_FUNC(assigned_dev-&gt;host_devfn));
+printk(KERN_DEBUG "assign device: host bdf = %x:%x:%x\n",
+assigned_dev-&gt;host_busnr,
+PCI_SLOT(assigned_dev-&gt;host_devfn),
+PCI_FUNC(assigned_dev-&gt;host_devfn));
 
-pdev = assigned_dev-&gt;dev;
+return 0;
+}
 
-if (pdev == NULL) {
-if (kvm-&gt;arch.intel_iommu_domain) {
-intel_iommu_domain_exit(kvm-&gt;arch.intel_iommu_domain);
-kvm-&gt;arch.intel_iommu_domain = NULL;
-}
+int kvm_iommu_map_guest(struct kvm *kvm)
+{
+int r;
+
+if (!intel_iommu_found()) {
+printk(KERN_ERR "%s: intel iommu not found\n", __func__);
 return -ENODEV;
 }
 
-kvm-&gt;arch.intel_iommu_domain = intel_iommu_domain_alloc(pdev);
+kvm-&gt;arch.intel_iommu_domain = intel_iommu_alloc_domain();
 if (!kvm-&gt;arch.intel_iommu_domain)
-return -ENODEV;
+return -ENOMEM;
 
 r = kvm_iommu_map_memslots(kvm);
 if (r)
 goto out_unmap;
 
-intel_iommu_detach_dev(kvm-&gt;arch.intel_iommu_domain,
-       pdev-&gt;bus-&gt;number, pdev-&gt;devfn);
-
-r = intel_iommu_context_mapping(kvm-&gt;arch.intel_iommu_domain,
-pdev);
-if (r) {
-printk(KERN_ERR "Domain context map for %s failed",
-       pci_name(pdev));
-goto out_unmap;
-}
 return 0;
 
 out_unmap:
&lt; at &gt;&lt; at &gt; -138,19 +141,29 &lt; at &gt;&lt; at &gt; out_unmap:
 }
 
 static void kvm_iommu_put_pages(struct kvm *kvm,
-       gfn_t base_gfn, unsigned long npages)
+gfn_t base_gfn, unsigned long npages)
 {
 gfn_t gfn = base_gfn;
 pfn_t pfn;
 struct dmar_domain *domain = kvm-&gt;arch.intel_iommu_domain;
-int i;
+unsigned long i;
+u64 phys;
+
+/* check if iommu exists and in use */
+if (!domain)
+return;
 
 for (i = 0; i &lt; npages; i++) {
-pfn = (pfn_t)intel_iommu_iova_to_pfn(domain,
-     gfn_to_gpa(gfn));
+phys = intel_iommu_iova_to_phys(domain,
+gfn_to_gpa(gfn));
+pfn = phys &gt;&gt; PAGE_SHIFT;
 kvm_release_pfn_clean(pfn);
 gfn++;
 }
+
+intel_iommu_unmap_address(domain,
+  gfn_to_gpa(base_gfn),
+  PAGE_SIZE * npages);
 }
 
 static int kvm_iommu_unmap_memslots(struct kvm *kvm)
&lt; at &gt;&lt; at &gt; -182,10 +195,9 &lt; at &gt;&lt; at &gt; int kvm_iommu_unmap_guest(struct kvm *kvm)
        PCI_FUNC(entry-&gt;host_devfn));
 
 /* detach kvm dmar domain */
-intel_iommu_detach_dev(domain, entry-&gt;host_busnr,
-       entry-&gt;host_devfn);
+intel_iommu_detach_device(domain, entry-&gt;dev);
 }
 kvm_iommu_unmap_memslots(kvm);
-intel_iommu_domain_exit(domain);
+intel_iommu_free_domain(domain);
 return 0;
 }
</description>
    <dc:creator>Han, Weidong</dc:creator>
    <dc:date>2008-12-02T14:23:08</dc:date>
  </item>
  <item rdf:about="http://comments.gmane.org/gmane.comp.emulators.kvm.devel/25464">
    <title>[PATCH 09/13] change domain_context_mapping_one for virtual machine domain</title>
    <link>http://comments.gmane.org/gmane.comp.emulators.kvm.devel/25464</link>
    <description>vm_domid won't be set in context, find available domain id for a device from its iommu.

For a virtual machine domain, a default agaw will be set, and skip top levels of page tables for iommu which has less agaw than default.

Signed-off-by: Weidong Han &lt;weidong.han&lt; at &gt;intel.com&gt;
---
 drivers/pci/intel-iommu.c |   57 ++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 54 insertions(+), 3 deletions(-)

diff --git a/drivers/pci/intel-iommu.c b/drivers/pci/intel-iommu.c
index e96b3bc..3f987d7 100644
--- a/drivers/pci/intel-iommu.c
+++ b/drivers/pci/intel-iommu.c
&lt; at &gt;&lt; at &gt; -1168,6 +1168,11 &lt; at &gt;&lt; at &gt; static int domain_context_mapping_one(struct dmar_domain *domain,
 struct context_entry *context;
 struct intel_iommu *iommu;
 unsigned long flags;
+struct dma_pte *pgd;
+unsigned long num;
+unsigned long ndomains;
+int id;
+int agaw;
 
 pr_debug("Set context mapping for %02x:%02x.%d\n",
 bus, PCI_SLOT(devfn), PCI_FUNC(devfn));
&lt; at &gt;&lt; at &gt; -1185,9 +1190,55 &lt; at &gt;&lt; at &gt; static int domain_context_mapping_one(struct dmar_domain *domain,
 return 0;
 }
 
-context_set_domain_id(*context, domain-&gt;id);
-context_set_address_width(*context, domain-&gt;agaw);
-context_set_address_root(*context, virt_to_phys(domain-&gt;pgd));
+id = domain-&gt;id;
+pgd = domain-&gt;pgd;
+
+if (domain-&gt;flags &amp; DOMAIN_FLAG_VIRTUAL_MACHINE) {
+int found = 0;
+
+/* find an available domain id for this device in iommu */
+ndomains = cap_ndoms(iommu-&gt;cap);
+num = find_first_bit(iommu-&gt;domain_ids, ndomains);
+for (; num &lt; ndomains; ) {
+if (iommu-&gt;domains[num] == domain) {
+id = num;
+found = 1;
+break;
+}
+num = find_next_bit(iommu-&gt;domain_ids,
+    cap_ndoms(iommu-&gt;cap), num+1);
+}
+
+if (found == 0) {
+num = find_first_zero_bit(iommu-&gt;domain_ids, ndomains);
+if (num &gt;= ndomains) {
+spin_unlock_irqrestore(&amp;iommu-&gt;lock, flags);
+printk(KERN_ERR "IOMMU: no free domain ids\n");
+return -EFAULT;
+}
+
+set_bit(num, iommu-&gt;domain_ids);
+iommu-&gt;domains[num] = domain;
+id = num;
+}
+
+/* Skip top levels of page tables for
+ * iommu which has less agaw than default.
+ */
+for (agaw = domain-&gt;agaw; agaw != iommu-&gt;agaw; agaw--) {
+pgd = phys_to_virt(dma_pte_addr(*pgd));
+if (!dma_pte_present(*pgd)) {
+spin_unlock_irqrestore(&amp;iommu-&gt;lock, flags);
+return -ENOMEM;
+}
+}
+
+set_bit(iommu-&gt;seq_id, &amp;domain-&gt;iommu_bmp);
+}
+
+context_set_domain_id(*context, id);
+context_set_address_width(*context, iommu-&gt;agaw);
+context_set_address_root(*context, virt_to_phys(pgd));
 context_set_translation_type(*context, CONTEXT_TT_MULTI_LEVEL);
 context_set_fault_enable(*context);
 context_set_present(*context);
</description>
    <dc:creator>Han, Weidong</dc:creator>
    <dc:date>2008-12-02T14:22:56</dc:date>
  </item>
  <item rdf:about="http://comments.gmane.org/gmane.comp.emulators.kvm.devel/25463">
    <title>[PATCH 10/13] change intel iommu APIs</title>
    <link>http://comments.gmane.org/gmane.comp.emulators.kvm.devel/25463</link>
    <description>These APIs will be used by kvm VT-d. The domain used by these APIs is virtual machine domain (domain flag is DOMAIN_FLAG_VIRTUAL_MACHINE).

Signed-off-by: Weidong Han &lt;weidong.han&lt; at &gt;intel.com&gt;
---
 drivers/pci/intel-iommu.c   |  128 ++++++++++++++++++++-----------------------
 include/linux/intel-iommu.h |   20 ++++---
 2 files changed, 71 insertions(+), 77 deletions(-)

diff --git a/drivers/pci/intel-iommu.c b/drivers/pci/intel-iommu.c
index 3f987d7..0db77e2 100644
--- a/drivers/pci/intel-iommu.c
+++ b/drivers/pci/intel-iommu.c
&lt; at &gt;&lt; at &gt; -2645,93 +2645,87 &lt; at &gt;&lt; at &gt; static void vm_domain_exit(struct dmar_domain *domain)
 free_domain_mem(domain);
 }
 
-void intel_iommu_domain_exit(struct dmar_domain *domain)
+struct dmar_domain *intel_iommu_alloc_domain(void)
 {
-u64 end;
-
-/* Domain 0 is reserved, so dont process it */
-if (!domain)
-return;
-
-end = DOMAIN_MAX_ADDR(domain-&gt;gaw);
-end = end &amp; (~VTD_PAGE_MASK);
-
-/* clear ptes */
-dma_pte_clear_range(domain, 0, end);
-
-/* free page tables */
-dma_pte_free_pagetable(domain, 0, end);
-
-iommu_free_domain(domain);
-free_domain_mem(domain);
-}
-EXPORT_SYMBOL_GPL(intel_iommu_domain_exit);
-
-struct dmar_domain *intel_iommu_domain_alloc(struct pci_dev *pdev)
-{
-struct dmar_drhd_unit *drhd;
 struct dmar_domain *domain;
-struct intel_iommu *iommu;
 
-drhd = dmar_find_matched_drhd_unit(pdev);
-if (!drhd) {
-printk(KERN_ERR "intel_iommu_domain_alloc: drhd == NULL\n");
-return NULL;
-}
-
-iommu = drhd-&gt;iommu;
-if (!iommu) {
-printk(KERN_ERR
-"intel_iommu_domain_alloc: iommu == NULL\n");
-return NULL;
-}
-domain = iommu_alloc_domain(iommu);
+domain = iommu_alloc_vm_domain();
 if (!domain) {
 printk(KERN_ERR
 "intel_iommu_domain_alloc: domain == NULL\n");
 return NULL;
 }
-if (domain_init(domain, DEFAULT_DOMAIN_ADDRESS_WIDTH)) {
+if (vm_domain_init(domain, DEFAULT_DOMAIN_ADDRESS_WIDTH)) {
 printk(KERN_ERR
 "intel_iommu_domain_alloc: domain_init() failed\n");
-intel_iommu_domain_exit(domain);
+vm_domain_exit(domain);
 return NULL;
 }
+
 return domain;
 }
-EXPORT_SYMBOL_GPL(intel_iommu_domain_alloc);
+EXPORT_SYMBOL_GPL(intel_iommu_alloc_domain);
 
-int intel_iommu_context_mapping(
-struct dmar_domain *domain, struct pci_dev *pdev)
+void intel_iommu_free_domain(struct dmar_domain *domain)
 {
-int rc;
-rc = domain_context_mapping(domain, pdev);
-return rc;
+vm_domain_exit(domain);
 }
-EXPORT_SYMBOL_GPL(intel_iommu_context_mapping);
+EXPORT_SYMBOL_GPL(intel_iommu_free_domain);
 
-int intel_iommu_page_mapping(
-struct dmar_domain *domain, dma_addr_t iova,
-u64 hpa, size_t size, int prot)
+int intel_iommu_attach_device(struct dmar_domain *domain,
+      struct pci_dev *pdev)
 {
-int rc;
-rc = domain_page_mapping(domain, iova, hpa, size, prot);
-return rc;
+int ret;
+
+/* normally pdev is not mapped */
+if (unlikely(domain_context_mapped(pdev))) {
+struct dmar_domain *old_domain;
+
+old_domain = find_domain(pdev);
+if (old_domain) {
+if (domain-&gt;flags &amp; DOMAIN_FLAG_VIRTUAL_MACHINE)
+vm_domain_remove_one_dev_info(old_domain, pdev);
+else
+domain_remove_dev_info(old_domain);
+}
+}
+
+ret = domain_context_mapping(domain, pdev);
+if (ret)
+return ret;
+
+ret = vm_domain_add_dev_info(domain, pdev);
+return ret;
 }
-EXPORT_SYMBOL_GPL(intel_iommu_page_mapping);
+EXPORT_SYMBOL_GPL(intel_iommu_attach_device);
 
-void intel_iommu_detach_dev(struct dmar_domain *domain, u8 bus, u8 devfn)
+void intel_iommu_detach_device(struct dmar_domain *domain,
+       struct pci_dev *pdev)
 {
-iommu_detach_dev(bus, devfn);
+vm_domain_remove_one_dev_info(domain, pdev);
 }
-EXPORT_SYMBOL_GPL(intel_iommu_detach_dev);
+EXPORT_SYMBOL_GPL(intel_iommu_detach_device);
 
-struct dmar_domain *
-intel_iommu_find_domain(struct pci_dev *pdev)
+int intel_iommu_map_address(struct dmar_domain *domain, dma_addr_t iova,
+    u64 hpa, size_t size, int prot)
 {
-return find_domain(pdev);
+int ret;
+ret = domain_page_mapping(domain, iova, hpa, size, prot);
+return ret;
 }
-EXPORT_SYMBOL_GPL(intel_iommu_find_domain);
+EXPORT_SYMBOL_GPL(intel_iommu_map_address);
+
+void intel_iommu_unmap_address(struct dmar_domain *domain,
+       dma_addr_t iova, size_t size)
+{
+dma_addr_t base;
+
+/* The address might not be aligned */
+base = iova &amp; VTD_PAGE_MASK;
+size = VTD_PAGE_ALIGN(size);
+dma_pte_clear_range(domain, base, base + size);
+}
+EXPORT_SYMBOL_GPL(intel_iommu_unmap_address);
 
 int intel_iommu_found(void)
 {
&lt; at &gt;&lt; at &gt; -2739,17 +2733,15 &lt; at &gt;&lt; at &gt; int intel_iommu_found(void)
 }
 EXPORT_SYMBOL_GPL(intel_iommu_found);
 
-u64 intel_iommu_iova_to_pfn(struct dmar_domain *domain, u64 iova)
+u64 intel_iommu_iova_to_phys(struct dmar_domain *domain, u64 iova)
 {
 struct dma_pte *pte;
-u64 pfn;
+u64 phys = 0;
 
-pfn = 0;
 pte = addr_to_dma_pte(domain, iova);
-
 if (pte)
-pfn = dma_pte_addr(*pte);
+phys = dma_pte_addr(*pte);
 
-return pfn &gt;&gt; VTD_PAGE_SHIFT;
+return phys;
 }
-EXPORT_SYMBOL_GPL(intel_iommu_iova_to_pfn);
+EXPORT_SYMBOL_GPL(intel_iommu_iova_to_phys);
diff --git a/include/linux/intel-iommu.h b/include/linux/intel-iommu.h
index 24a2945..39a68b3 100644
--- a/include/linux/intel-iommu.h
+++ b/include/linux/intel-iommu.h
&lt; at &gt;&lt; at &gt; -335,15 +335,17 &lt; at &gt;&lt; at &gt; extern int qi_flush_iotlb(struct intel_iommu *iommu, u16 did, u64 addr,
 
 extern void qi_submit_sync(struct qi_desc *desc, struct intel_iommu *iommu);
 
-void intel_iommu_domain_exit(struct dmar_domain *domain);
-struct dmar_domain *intel_iommu_domain_alloc(struct pci_dev *pdev);
-int intel_iommu_context_mapping(struct dmar_domain *domain,
-struct pci_dev *pdev);
-int intel_iommu_page_mapping(struct dmar_domain *domain, dma_addr_t iova,
-     u64 hpa, size_t size, int prot);
-void intel_iommu_detach_dev(struct dmar_domain *domain, u8 bus, u8 devfn);
-struct dmar_domain *intel_iommu_find_domain(struct pci_dev *pdev);
-u64 intel_iommu_iova_to_pfn(struct dmar_domain *domain, u64 iova);
+struct dmar_domain *intel_iommu_alloc_domain(void);
+void intel_iommu_free_domain(struct dmar_domain *domain);
+int intel_iommu_attach_device(struct dmar_domain *domain,
+      struct pci_dev *pdev);
+void intel_iommu_detach_device(struct dmar_domain *domain,
+       struct pci_dev *pdev);
+int intel_iommu_map_address(struct dmar_domain *domain, dma_addr_t iova,
+    u64 hpa, size_t size, int prot);
+void intel_iommu_unmap_address(struct dmar_domain *domain,
+       dma_addr_t iova, size_t size);
+u64 intel_iommu_iova_to_phys(struct dmar_domain *domain, u64 iova);
 
 #ifdef CONFIG_DMAR
 int intel_iommu_found(void);
</description>
    <dc:creator>Han, Weidong</dc:creator>
    <dc:date>2008-12-02T14:23:00</dc:date>
  </item>
  <item rdf:about="http://comments.gmane.org/gmane.comp.emulators.kvm.devel/25462">
    <title>[PATCH 08/13] allocation and free functions of virtual machine domain</title>
    <link>http://comments.gmane.org/gmane.comp.emulators.kvm.devel/25462</link>
    <description>
Signed-off-by: Weidong Han &lt;weidong.han&lt; at &gt;intel.com&gt;
---
 drivers/pci/intel-iommu.c |  104 ++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 103 insertions(+), 1 deletions(-)

diff --git a/drivers/pci/intel-iommu.c b/drivers/pci/intel-iommu.c
index b00a8f2..e96b3bc 100644
--- a/drivers/pci/intel-iommu.c
+++ b/drivers/pci/intel-iommu.c
&lt; at &gt;&lt; at &gt; -947,6 +947,7 &lt; at &gt;&lt; at &gt; static int iommu_init_domains(struct intel_iommu *iommu)
 
 
 static void domain_exit(struct dmar_domain *domain);
+static void vm_domain_exit(struct dmar_domain *domain);
 
 void free_dmar_iommu(struct intel_iommu *iommu)
 {
&lt; at &gt;&lt; at &gt; -957,8 +958,13 &lt; at &gt;&lt; at &gt; void free_dmar_iommu(struct intel_iommu *iommu)
 for (; i &lt; cap_ndoms(iommu-&gt;cap); ) {
 domain = iommu-&gt;domains[i];
 clear_bit(i, iommu-&gt;domain_ids);
-if (--domain-&gt;iommu_count == 0)
+
+if (domain-&gt;flags &amp; DOMAIN_FLAG_VIRTUAL_MACHINE) {
+if (--domain-&gt;iommu_count == 0)
+vm_domain_exit(domain);
+} else
 domain_exit(domain);
+
 i = find_next_bit(iommu-&gt;domain_ids,
 cap_ndoms(iommu-&gt;cap), i+1);
 }
&lt; at &gt;&lt; at &gt; -2492,6 +2498,102 &lt; at &gt;&lt; at &gt; static void vm_domain_remove_all_dev_info(struct dmar_domain *domain)
 spin_unlock_irqrestore(&amp;device_domain_lock, flags);
 }
 
+/* domain id for virtual machine, it won't be set in context */
+static unsigned long vm_domid;
+
+static struct dmar_domain *iommu_alloc_vm_domain(void)
+{
+struct dmar_domain *domain;
+
+domain = alloc_domain_mem();
+if (!domain)
+return NULL;
+
+domain-&gt;id = vm_domid++;
+domain-&gt;iommu_count = 0;
+domain-&gt;iommu_coherency = 0;
+memset(&amp;domain-&gt;iommu_bmp, 0, sizeof(unsigned long));
+domain-&gt;flags = DOMAIN_FLAG_VIRTUAL_MACHINE;
+
+return domain;
+}
+
+static int vm_domain_init(struct dmar_domain *domain, int guest_width)
+{
+int adjust_width;
+
+init_iova_domain(&amp;domain-&gt;iovad, DMA_32BIT_PFN);
+spin_lock_init(&amp;domain-&gt;mapping_lock);
+
+domain_reserve_special_ranges(domain);
+
+/* calculate AGAW */
+domain-&gt;gaw = guest_width;
+adjust_width = guestwidth_to_adjustwidth(guest_width);
+domain-&gt;agaw = width_to_agaw(adjust_width);
+
+INIT_LIST_HEAD(&amp;domain-&gt;devices);
+
+/* always allocate the top pgd */
+domain-&gt;pgd = (struct dma_pte *)alloc_pgtable_page();
+if (!domain-&gt;pgd)
+return -ENOMEM;
+domain_flush_cache(domain, domain-&gt;pgd, PAGE_SIZE);
+return 0;
+}
+
+static void iommu_free_vm_domain(struct dmar_domain *domain)
+{
+unsigned long flags;
+struct dmar_drhd_unit *drhd;
+struct intel_iommu *iommu;
+unsigned long i;
+unsigned long ndomains;
+
+for_each_drhd_unit(drhd) {
+if (drhd-&gt;ignored)
+continue;
+iommu = drhd-&gt;iommu;
+
+ndomains = cap_ndoms(iommu-&gt;cap);
+i = find_first_bit(iommu-&gt;domain_ids, ndomains);
+for (; i &lt; ndomains; ) {
+if (iommu-&gt;domains[i] == domain) {
+spin_lock_irqsave(&amp;iommu-&gt;lock, flags);
+clear_bit(i, iommu-&gt;domain_ids);
+iommu-&gt;domains[i] = NULL;
+spin_unlock_irqrestore(&amp;iommu-&gt;lock, flags);
+break;
+}
+i = find_next_bit(iommu-&gt;domain_ids, ndomains, i+1);
+}
+}
+}
+
+static void vm_domain_exit(struct dmar_domain *domain)
+{
+u64 end;
+
+/* Domain 0 is reserved, so dont process it */
+if (!domain)
+return;
+
+vm_domain_remove_all_dev_info(domain);
+/* destroy iovas */
+put_iova_domain(&amp;domain-&gt;iovad);
+end = DOMAIN_MAX_ADDR(domain-&gt;gaw);
+end = end &amp; (~VTD_PAGE_MASK);
+
+/* clear ptes */
+dma_pte_clear_range(domain, 0, end);
+
+/* free page tables */
+dma_pte_free_pagetable(domain, 0, end);
+
+iommu_free_vm_domain(domain);
+free_domain_mem(domain);
+}
+
 void intel_iommu_domain_exit(struct dmar_domain *domain)
 {
 u64 end;
</description>
    <dc:creator>Han, Weidong</dc:creator>
    <dc:date>2008-12-02T14:22:50</dc:date>
  </item>
  <item rdf:about="http://comments.gmane.org/gmane.comp.emulators.kvm.devel/25461">
    <title>[PATCH 04/13] iommu coherency</title>
    <link>http://comments.gmane.org/gmane.comp.emulators.kvm.devel/25461</link>
    <description>in dmar_domain, more than one iommus may be included in iommu_bmp. Due to "Coherency" capability may be different across iommus, set this variable to indicate iommu access is coherent or not. Only when all related iommus in a dmar_domain are all coherent, iommu access of this domain is coherent.

Signed-off-by: Weidong Han &lt;weidong.han&lt; at &gt;intel.com&gt;
---
 drivers/pci/intel-iommu.c     |    6 ++++++
 include/linux/dma_remapping.h |    2 ++
 2 files changed, 8 insertions(+), 0 deletions(-)

diff --git a/drivers/pci/intel-iommu.c b/drivers/pci/intel-iommu.c
index a18e0b4..fa1507b 100644
--- a/drivers/pci/intel-iommu.c
+++ b/drivers/pci/intel-iommu.c
&lt; at &gt;&lt; at &gt; -982,6 +982,12 &lt; at &gt;&lt; at &gt; static struct dmar_domain * iommu_alloc_domain(struct intel_iommu *iommu)
 domain-&gt;id = num;
 memset(&amp;domain-&gt;iommu_bmp, 0, sizeof(unsigned long));
 set_bit(iommu-&gt;seq_id, &amp;domain-&gt;iommu_bmp);
+
+if (ecap_coherent(iommu-&gt;ecap))
+domain-&gt;iommu_coherency = 1;
+else
+domain-&gt;iommu_coherency = 0;
+
 iommu-&gt;domains[num] = domain;
 spin_unlock_irqrestore(&amp;iommu-&gt;lock, flags);
 
diff --git a/include/linux/dma_remapping.h b/include/linux/dma_remapping.h
index c9d99c9..add2111 100644
--- a/include/linux/dma_remapping.h
+++ b/include/linux/dma_remapping.h
&lt; at &gt;&lt; at &gt; -175,6 +175,8 &lt; at &gt;&lt; at &gt; struct dmar_domain {
 
 #define DOMAIN_FLAG_MULTIPLE_DEVICES 1
 intflags;
+
+intiommu_coherency;/* iommu access is coherent or not */
 };
 
 /* PCI domain-device relationship */
</description>
    <dc:creator>Han, Weidong</dc:creator>
    <dc:date>2008-12-02T14:22:27</dc:date>
  </item>
  <textinput rdf:about="http://search.gmane.org/?group=$group=gmane.comp.emulators.kvm.devel">
    <title>Search Engine</title>
    <description>Search the mailing list at Gmane</description>
    <name>query</name>
    <link>http://search.gmane.org/?group=$group=gmane.comp.emulators.kvm.devel</link>
  </textinput>
</rdf:RDF>
