All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] Avoid CPU endian memory accesses in devices
@ 2011-07-14 19:34 Blue Swirl
  2011-07-14 21:56 ` Alexander Graf
  0 siblings, 1 reply; 5+ messages in thread
From: Blue Swirl @ 2011-07-14 19:34 UTC (permalink / raw)
  To: Alexander Graf, qemu-devel

[-- Attachment #1: Type: text/plain, Size: 4065 bytes --]

Don't compile virtio.c in hwlib, it depends on memory accesses
performed in CPU endianness.

Make loads and stores in CPU endianness unavailable to devices
and poison them to avoid further bugs.

Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
---
 Makefile.objs   |    2 +-
 Makefile.target |    2 +-
 cpu-common.h    |   19 +++++++++++--------
 poison.h        |    9 +++++++++
 4 files changed, 22 insertions(+), 10 deletions(-)

diff --git a/Makefile.objs b/Makefile.objs
index cea15e4..86ebcec 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -171,7 +171,7 @@ user-obj-y += cutils.o cache-utils.o

 hw-obj-y =
 hw-obj-y += vl.o loader.o
-hw-obj-$(CONFIG_VIRTIO) += virtio.o virtio-console.o
+hw-obj-$(CONFIG_VIRTIO) += virtio-console.o
 hw-obj-$(CONFIG_VIRTIO_PCI) += virtio-pci.o
 hw-obj-y += fw_cfg.o
 hw-obj-$(CONFIG_PCI) += pci.o pci_bridge.o
diff --git a/Makefile.target b/Makefile.target
index a53a2ff..f3070b3 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -190,7 +190,7 @@ obj-y = arch_init.o cpus.o monitor.o machine.o
gdbstub.o balloon.o
 # virtio has to be here due to weird dependency between PCI and virtio-net.
 # need to fix this properly
 obj-$(CONFIG_NO_PCI) += pci-stub.o
-obj-$(CONFIG_VIRTIO) += virtio-blk.o virtio-balloon.o virtio-net.o
virtio-serial-bus.o
+obj-$(CONFIG_VIRTIO) += virtio.o virtio-blk.o virtio-balloon.o
virtio-net.o virtio-serial-bus.o
 obj-y += vhost_net.o
 obj-$(CONFIG_VHOST_NET) += vhost.o
 obj-$(CONFIG_REALLY_VIRTFS) += 9pfs/virtio-9p-device.o
diff --git a/cpu-common.h b/cpu-common.h
index c6a2b5f..3203c67 100644
--- a/cpu-common.h
+++ b/cpu-common.h
@@ -134,28 +134,31 @@ void
qemu_unregister_coalesced_mmio(target_phys_addr_t addr, ram_addr_t
size);
 void qemu_flush_coalesced_mmio_buffer(void);

 uint32_t ldub_phys(target_phys_addr_t addr);
-uint32_t lduw_phys(target_phys_addr_t addr);
 uint32_t lduw_le_phys(target_phys_addr_t addr);
 uint32_t lduw_be_phys(target_phys_addr_t addr);
-uint32_t ldl_phys(target_phys_addr_t addr);
 uint32_t ldl_le_phys(target_phys_addr_t addr);
 uint32_t ldl_be_phys(target_phys_addr_t addr);
-uint64_t ldq_phys(target_phys_addr_t addr);
 uint64_t ldq_le_phys(target_phys_addr_t addr);
 uint64_t ldq_be_phys(target_phys_addr_t addr);
-void stl_phys_notdirty(target_phys_addr_t addr, uint32_t val);
-void stq_phys_notdirty(target_phys_addr_t addr, uint64_t val);
 void stb_phys(target_phys_addr_t addr, uint32_t val);
-void stw_phys(target_phys_addr_t addr, uint32_t val);
 void stw_le_phys(target_phys_addr_t addr, uint32_t val);
 void stw_be_phys(target_phys_addr_t addr, uint32_t val);
-void stl_phys(target_phys_addr_t addr, uint32_t val);
 void stl_le_phys(target_phys_addr_t addr, uint32_t val);
 void stl_be_phys(target_phys_addr_t addr, uint32_t val);
-void stq_phys(target_phys_addr_t addr, uint64_t val);
 void stq_le_phys(target_phys_addr_t addr, uint64_t val);
 void stq_be_phys(target_phys_addr_t addr, uint64_t val);

+#ifdef NEED_CPU_H
+uint32_t lduw_phys(target_phys_addr_t addr);
+uint32_t ldl_phys(target_phys_addr_t addr);
+uint64_t ldq_phys(target_phys_addr_t addr);
+void stl_phys_notdirty(target_phys_addr_t addr, uint32_t val);
+void stq_phys_notdirty(target_phys_addr_t addr, uint64_t val);
+void stw_phys(target_phys_addr_t addr, uint32_t val);
+void stl_phys(target_phys_addr_t addr, uint32_t val);
+void stq_phys(target_phys_addr_t addr, uint64_t val);
+#endif
+
 void cpu_physical_memory_write_rom(target_phys_addr_t addr,
                                    const uint8_t *buf, int len);

diff --git a/poison.h b/poison.h
index 2b18232..5354e77 100644
--- a/poison.h
+++ b/poison.h
@@ -37,6 +37,15 @@
 #pragma GCC poison CPUState
 #pragma GCC poison env

+#pragma GCC poison lduw_phys
+#pragma GCC poison ldl_phys
+#pragma GCC poison ldq_phys
+#pragma GCC poison stl_phys_notdirty
+#pragma GCC poison stq_phys_notdirty
+#pragma GCC poison stw_phys
+#pragma GCC poison stl_phys
+#pragma GCC poison stq_phys
+
 #pragma GCC poison CPU_INTERRUPT_HARD
 #pragma GCC poison CPU_INTERRUPT_EXITTB
 #pragma GCC poison CPU_INTERRUPT_HALT
-- 
1.6.2.4

[-- Attachment #2: 0001-Avoid-CPU-endian-memory-accesses-in-devices.patch --]
[-- Type: text/x-patch, Size: 4373 bytes --]

From 7cdbaae2953cf492f1c101858185483c1c9b2026 Mon Sep 17 00:00:00 2001
Message-Id: <7cdbaae2953cf492f1c101858185483c1c9b2026.1310671980.git.blauwirbel@gmail.com>
From: Blue Swirl <blauwirbel@gmail.com>
Date: Thu, 14 Jul 2011 15:22:20 +0000
Subject: [PATCH] Avoid CPU endian memory accesses in devices

Don't compile virtio.c in hwlib, it depends on memory accesses
performed in CPU endianness.

Make loads and stores in CPU endianness unavailable to devices
and poison them to avoid further bugs.

Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
---
 Makefile.objs   |    2 +-
 Makefile.target |    2 +-
 cpu-common.h    |   19 +++++++++++--------
 poison.h        |    9 +++++++++
 4 files changed, 22 insertions(+), 10 deletions(-)

diff --git a/Makefile.objs b/Makefile.objs
index cea15e4..86ebcec 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -171,7 +171,7 @@ user-obj-y += cutils.o cache-utils.o
 
 hw-obj-y =
 hw-obj-y += vl.o loader.o
-hw-obj-$(CONFIG_VIRTIO) += virtio.o virtio-console.o
+hw-obj-$(CONFIG_VIRTIO) += virtio-console.o
 hw-obj-$(CONFIG_VIRTIO_PCI) += virtio-pci.o
 hw-obj-y += fw_cfg.o
 hw-obj-$(CONFIG_PCI) += pci.o pci_bridge.o
diff --git a/Makefile.target b/Makefile.target
index a53a2ff..f3070b3 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -190,7 +190,7 @@ obj-y = arch_init.o cpus.o monitor.o machine.o gdbstub.o balloon.o
 # virtio has to be here due to weird dependency between PCI and virtio-net.
 # need to fix this properly
 obj-$(CONFIG_NO_PCI) += pci-stub.o
-obj-$(CONFIG_VIRTIO) += virtio-blk.o virtio-balloon.o virtio-net.o virtio-serial-bus.o
+obj-$(CONFIG_VIRTIO) += virtio.o virtio-blk.o virtio-balloon.o virtio-net.o virtio-serial-bus.o
 obj-y += vhost_net.o
 obj-$(CONFIG_VHOST_NET) += vhost.o
 obj-$(CONFIG_REALLY_VIRTFS) += 9pfs/virtio-9p-device.o
diff --git a/cpu-common.h b/cpu-common.h
index c6a2b5f..3203c67 100644
--- a/cpu-common.h
+++ b/cpu-common.h
@@ -134,28 +134,31 @@ void qemu_unregister_coalesced_mmio(target_phys_addr_t addr, ram_addr_t size);
 void qemu_flush_coalesced_mmio_buffer(void);
 
 uint32_t ldub_phys(target_phys_addr_t addr);
-uint32_t lduw_phys(target_phys_addr_t addr);
 uint32_t lduw_le_phys(target_phys_addr_t addr);
 uint32_t lduw_be_phys(target_phys_addr_t addr);
-uint32_t ldl_phys(target_phys_addr_t addr);
 uint32_t ldl_le_phys(target_phys_addr_t addr);
 uint32_t ldl_be_phys(target_phys_addr_t addr);
-uint64_t ldq_phys(target_phys_addr_t addr);
 uint64_t ldq_le_phys(target_phys_addr_t addr);
 uint64_t ldq_be_phys(target_phys_addr_t addr);
-void stl_phys_notdirty(target_phys_addr_t addr, uint32_t val);
-void stq_phys_notdirty(target_phys_addr_t addr, uint64_t val);
 void stb_phys(target_phys_addr_t addr, uint32_t val);
-void stw_phys(target_phys_addr_t addr, uint32_t val);
 void stw_le_phys(target_phys_addr_t addr, uint32_t val);
 void stw_be_phys(target_phys_addr_t addr, uint32_t val);
-void stl_phys(target_phys_addr_t addr, uint32_t val);
 void stl_le_phys(target_phys_addr_t addr, uint32_t val);
 void stl_be_phys(target_phys_addr_t addr, uint32_t val);
-void stq_phys(target_phys_addr_t addr, uint64_t val);
 void stq_le_phys(target_phys_addr_t addr, uint64_t val);
 void stq_be_phys(target_phys_addr_t addr, uint64_t val);
 
+#ifdef NEED_CPU_H
+uint32_t lduw_phys(target_phys_addr_t addr);
+uint32_t ldl_phys(target_phys_addr_t addr);
+uint64_t ldq_phys(target_phys_addr_t addr);
+void stl_phys_notdirty(target_phys_addr_t addr, uint32_t val);
+void stq_phys_notdirty(target_phys_addr_t addr, uint64_t val);
+void stw_phys(target_phys_addr_t addr, uint32_t val);
+void stl_phys(target_phys_addr_t addr, uint32_t val);
+void stq_phys(target_phys_addr_t addr, uint64_t val);
+#endif
+
 void cpu_physical_memory_write_rom(target_phys_addr_t addr,
                                    const uint8_t *buf, int len);
 
diff --git a/poison.h b/poison.h
index 2b18232..5354e77 100644
--- a/poison.h
+++ b/poison.h
@@ -37,6 +37,15 @@
 #pragma GCC poison CPUState
 #pragma GCC poison env
 
+#pragma GCC poison lduw_phys
+#pragma GCC poison ldl_phys
+#pragma GCC poison ldq_phys
+#pragma GCC poison stl_phys_notdirty
+#pragma GCC poison stq_phys_notdirty
+#pragma GCC poison stw_phys
+#pragma GCC poison stl_phys
+#pragma GCC poison stq_phys
+
 #pragma GCC poison CPU_INTERRUPT_HARD
 #pragma GCC poison CPU_INTERRUPT_EXITTB
 #pragma GCC poison CPU_INTERRUPT_HALT
-- 
1.7.2.5


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [PATCH] Avoid CPU endian memory accesses in devices
  2011-07-14 19:34 [Qemu-devel] [PATCH] Avoid CPU endian memory accesses in devices Blue Swirl
@ 2011-07-14 21:56 ` Alexander Graf
  2011-07-15 20:02   ` Blue Swirl
  2011-07-20 21:48   ` Blue Swirl
  0 siblings, 2 replies; 5+ messages in thread
From: Alexander Graf @ 2011-07-14 21:56 UTC (permalink / raw)
  To: Blue Swirl; +Cc: qemu-devel





Am 14.07.2011 um 21:34 schrieb Blue Swirl <blauwirbel@gmail.com>:

> Don't compile virtio.c in hwlib, it depends on memory accesses
> performed in CPU endianness.
> 
> Make loads and stores in CPU endianness unavailable to devices
> and poison them to avoid further bugs.

Very nice :). Couldn't test execute it, but:

Acked-by: Alexander Graf <agraf@suse.de>

Alex

> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [PATCH] Avoid CPU endian memory accesses in devices
  2011-07-14 21:56 ` Alexander Graf
@ 2011-07-15 20:02   ` Blue Swirl
  2011-07-15 20:56     ` Alexander Graf
  2011-07-20 21:48   ` Blue Swirl
  1 sibling, 1 reply; 5+ messages in thread
From: Blue Swirl @ 2011-07-15 20:02 UTC (permalink / raw)
  To: Alexander Graf; +Cc: qemu-devel

On Fri, Jul 15, 2011 at 12:56 AM, Alexander Graf <agraf@suse.de> wrote:
>
>
>
>
> Am 14.07.2011 um 21:34 schrieb Blue Swirl <blauwirbel@gmail.com>:
>
>> Don't compile virtio.c in hwlib, it depends on memory accesses
>> performed in CPU endianness.
>>
>> Make loads and stores in CPU endianness unavailable to devices
>> and poison them to avoid further bugs.
>
> Very nice :). Couldn't test execute it, but:
>
> Acked-by: Alexander Graf <agraf@suse.de>

By the way, another way would be to change virtio to always use LE
accesses. This would need changes to KVM on PPC and s390x. Would that
be possible?

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [PATCH] Avoid CPU endian memory accesses in devices
  2011-07-15 20:02   ` Blue Swirl
@ 2011-07-15 20:56     ` Alexander Graf
  0 siblings, 0 replies; 5+ messages in thread
From: Alexander Graf @ 2011-07-15 20:56 UTC (permalink / raw)
  To: Blue Swirl; +Cc: qemu-devel

On 07/15/2011 10:02 PM, Blue Swirl wrote:
> On Fri, Jul 15, 2011 at 12:56 AM, Alexander Graf<agraf@suse.de>  wrote:
>>
>>
>>
>> Am 14.07.2011 um 21:34 schrieb Blue Swirl<blauwirbel@gmail.com>:
>>
>>> Don't compile virtio.c in hwlib, it depends on memory accesses
>>> performed in CPU endianness.
>>>
>>> Make loads and stores in CPU endianness unavailable to devices
>>> and poison them to avoid further bugs.
>> Very nice :). Couldn't test execute it, but:
>>
>> Acked-by: Alexander Graf<agraf@suse.de>
> By the way, another way would be to change virtio to always use LE
> accesses. This would need changes to KVM on PPC and s390x. Would that
> be possible?

The code is already in Linux for quite a while, other OSs started 
implementing it (Solaris) and the spec is pretty specific on fields 
being in target endianness.

The virtio v2 spec will hopefully fix this, but that should end up in a 
different module then :)


Alex

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [PATCH] Avoid CPU endian memory accesses in devices
  2011-07-14 21:56 ` Alexander Graf
  2011-07-15 20:02   ` Blue Swirl
@ 2011-07-20 21:48   ` Blue Swirl
  1 sibling, 0 replies; 5+ messages in thread
From: Blue Swirl @ 2011-07-20 21:48 UTC (permalink / raw)
  To: Alexander Graf; +Cc: qemu-devel

On Fri, Jul 15, 2011 at 12:56 AM, Alexander Graf <agraf@suse.de> wrote:
>
>
>
>
> Am 14.07.2011 um 21:34 schrieb Blue Swirl <blauwirbel@gmail.com>:
>
>> Don't compile virtio.c in hwlib, it depends on memory accesses
>> performed in CPU endianness.
>>
>> Make loads and stores in CPU endianness unavailable to devices
>> and poison them to avoid further bugs.
>
> Very nice :). Couldn't test execute it, but:
>
> Acked-by: Alexander Graf <agraf@suse.de>

Thanks for the ack, applied.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2011-07-20 21:48 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-07-14 19:34 [Qemu-devel] [PATCH] Avoid CPU endian memory accesses in devices Blue Swirl
2011-07-14 21:56 ` Alexander Graf
2011-07-15 20:02   ` Blue Swirl
2011-07-15 20:56     ` Alexander Graf
2011-07-20 21:48   ` Blue Swirl

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.