diff mbox

[23/28] kvm tools: Endian-sanitise pci.h and PCI device setup

Message ID 4EDD8F16.6060104@ozlabs.org
State New, archived
Headers show

Commit Message

Matt Evans Dec. 6, 2011, 3:42 a.m. UTC
vesa, pci-shmem and virtio-pci devices need to set up config space with
little-endian conversions (as config space is LE).  The pci_config_address
bitfield also needs to be reversed when building on BE systems.

Signed-off-by: Matt Evans <matt@ozlabs.org>
---
 tools/kvm/hw/pci-shmem.c       |   23 +++++++++++----------
 tools/kvm/hw/vesa.c            |   15 +++++++------
 tools/kvm/include/kvm/ioport.h |   11 +++++----
 tools/kvm/include/kvm/pci.h    |   24 +++++++++++++++++-----
 tools/kvm/pci.c                |    4 +-
 tools/kvm/virtio/pci.c         |   41 +++++++++++++++++++++------------------
 6 files changed, 68 insertions(+), 50 deletions(-)

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

Comments

Pekka Enberg Dec. 6, 2011, 10:25 a.m. UTC | #1
On Tue, Dec 6, 2011 at 5:42 AM, Matt Evans <matt@ozlabs.org> wrote:
> vesa, pci-shmem and virtio-pci devices need to set up config space with
> little-endian conversions (as config space is LE).  The pci_config_address
> bitfield also needs to be reversed when building on BE systems.
>
> Signed-off-by: Matt Evans <matt@ozlabs.org>

Looks OK to me. Sasha, Cyrill?
--
To unsubscribe from this list: send the line "unsubscribe kvm-ppc" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Cyrill Gorcunov Dec. 6, 2011, 10:28 a.m. UTC | #2
On Tue, Dec 06, 2011 at 12:25:29PM +0200, Pekka Enberg wrote:
> On Tue, Dec 6, 2011 at 5:42 AM, Matt Evans <matt@ozlabs.org> wrote:
> > vesa, pci-shmem and virtio-pci devices need to set up config space with
> > little-endian conversions (as config space is LE).  The pci_config_address
> > bitfield also needs to be reversed when building on BE systems.
> >
> > Signed-off-by: Matt Evans <matt@ozlabs.org>
> 
> Looks OK to me. Sasha, Cyrill?
> 

BIOS part looks pretty good to me. LE/BE part as well. Thanks Matt!

	Cyrill
--
To unsubscribe from this list: send the line "unsubscribe kvm-ppc" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Pekka Enberg Dec. 6, 2011, 11:41 a.m. UTC | #3
On Tue, Dec 6, 2011 at 12:28 PM, Cyrill Gorcunov <gorcunov@gmail.com> wrote:
> On Tue, Dec 06, 2011 at 12:25:29PM +0200, Pekka Enberg wrote:
>> On Tue, Dec 6, 2011 at 5:42 AM, Matt Evans <matt@ozlabs.org> wrote:
>> > vesa, pci-shmem and virtio-pci devices need to set up config space with
>> > little-endian conversions (as config space is LE).  The pci_config_address
>> > bitfield also needs to be reversed when building on BE systems.
>> >
>> > Signed-off-by: Matt Evans <matt@ozlabs.org>
>>
>> Looks OK to me. Sasha, Cyrill?
>>
>
> BIOS part looks pretty good to me. LE/BE part as well. Thanks Matt!

Hmm. This seems to break "make check" for me:

./kvm run -d tests/boot/boot_test.iso -p "init=init"
  # kvm run -k ../../arch/x86/boot/bzImage -m 448 -c 4 --name guest-2845
[    0.000000] Initializing cgroup subsys cpuset
[    0.000000] Initializing cgroup subsys cpu
[    0.000000] Linux version 3.2.0-rc3 (penberg@tux) (gcc version
4.6.0 20110603 (Red Hat 4.6.0-10) (GCC) ) #67 SMP Thu Nov 24 11:05:24
EET 2011
[    0.000000] Command line: noapic noacpi pci=conf1 reboot=k panic=1
i8042.direct=1 i8042.dumbkbd=1 i8042.nopnp=1 console=ttyS0
earlyprintk=serial i8042.noaux=1 init=init root=/dev/vda rw
[    0.000000] BIOS-provided physical RAM map:
[    0.000000]  BIOS-e820: 0000000000000000 - 000000000009fc00 (usable)
[    0.000000]  BIOS-e820: 000000000009fc00 - 00000000000a0000 (reserved)
[    0.000000]  BIOS-e820: 00000000000f0000 - 00000000000fffff (reserved)
[    0.000000]  BIOS-e820: 0000000000100000 - 000000001c000000 (usable)
[    0.000000] bootconsole [earlyser0] enabled
[    0.000000] NX (Execute Disable) protection: active
[    0.000000] DMI not present or invalid.
[    0.000000] No AGP bridge found
[    0.000000] last_pfn = 0x1c000 max_arch_pfn = 0x400000000
[    0.000000] x86 PAT enabled: cpu 0, old 0x70106, new 0x7010600070106
[    0.000000] CPU MTRRs all blank - virtualized system.
[    0.000000] found SMP MP-table at [ffff8800000f0390] f0390
[    0.000000] init_memory_mapping: 0000000000000000-000000001c000000
[    0.000000] ACPI Error: A valid RSDP was not found (20110623/tbxfroot-219)
[    0.000000] No NUMA configuration found
[    0.000000] Faking a node at 0000000000000000-000000001c000000
[    0.000000] Initmem setup node 0 0000000000000000-000000001c000000
[    0.000000]   NODE_DATA [000000001bfec000 - 000000001bffffff]
[    0.000000] kvm-clock: Using msrs 4b564d01 and 4b564d00
[    0.000000] kvm-clock: cpu 0, msr 0:1b71301, boot clock
[    0.000000] Zone PFN ranges:
[    0.000000]   DMA      0x00000010 -> 0x00001000
[    0.000000]   DMA32    0x00001000 -> 0x00100000
[    0.000000]   Normal   empty
[    0.000000] Movable zone start PFN for each node
[    0.000000] early_node_map[2] active PFN ranges
[    0.000000]     0: 0x00000010 -> 0x0000009f
[    0.000000]     0: 0x00000100 -> 0x0001c000
[    0.000000] SFI: Simple Firmware Interface v0.81 http://simplefirmware.org
[    0.000000] Intel MultiProcessor Specification v1.4
[    0.000000] MPTABLE: OEM ID: KVMCPU00
[    0.000000] MPTABLE: Product ID: 0.1
[    0.000000] MPTABLE: APIC at: 0xFEE00000
[    0.000000] Processor #0 (Bootup-CPU)
[    0.000000] Processor #1
[    0.000000] Processor #2
[    0.000000] Processor #3
[    0.000000] IOAPIC[0]: apic_id 5, version 17, address 0xfec00000, GSI 0-23
[    0.000000] Processors: 4
[    0.000000] SMP: Allowing 4 CPUs, 0 hotplug CPUs
[    0.000000] PM: Registered nosave memory: 000000000009f000 - 00000000000a0000
[    0.000000] PM: Registered nosave memory: 00000000000a0000 - 00000000000f0000
[    0.000000] PM: Registered nosave memory: 00000000000f0000 - 00000000000ff000
[    0.000000] PM: Registered nosave memory: 00000000000ff000 - 0000000000100000
[    0.000000] Allocating PCI resources starting at 1c000000 (gap:
1c000000:e4000000)
[    0.000000] Booting paravirtualized kernel on KVM
[    0.000000] setup_percpu: NR_CPUS:256 nr_cpumask_bits:256
nr_cpu_ids:4 nr_node_ids:1
[    0.000000] PERCPU: Embedded 27 pages/cpu @ffff88001bc00000 s77888
r8192 d24512 u524288
[    0.000000] kvm-clock: cpu 0, msr 0:1bc12301, primary cpu clock
[    0.000000] KVM setup async PF for cpu 0
[    0.000000] kvm-stealtime: cpu 0, msr 1bc0d000
[    0.000000] Built 1 zonelists in Node order, mobility grouping on.
Total pages: 112778
[    0.000000] Policy zone: DMA32
[    0.000000] Kernel command line: noapic noacpi pci=conf1 reboot=k
panic=1 i8042.direct=1 i8042.dumbkbd=1 i8042.nopnp=1 console=ttyS0
earlyprintk=serial i8042.noaux=1 init=init root=/dev/vda rw
[    0.000000] PID hash table entries: 2048 (order: 2, 16384 bytes)
[    0.000000] xsave/xrstor: enabled xstate_bv 0x7, cntxt size 0x340
[    0.000000] Checking aperture...
[    0.000000] No AGP bridge found
[    0.000000] Memory: 435408k/458752k available (4752k kernel code,
452k absent, 22892k reserved, 6886k data, 908k init)
[    0.000000] SLUB: Genslabs=15, HWalign=64, Order=0-3, MinObjects=0,
CPUs=4, Nodes=1
[    0.000000] Hierarchical RCU implementation.
[    0.000000] 	RCU dyntick-idle grace-period acceleration is enabled.
[    0.000000] NR_IRQS:16640 nr_irqs:712 16
[    0.000000] Console: colour *CGA 80x25
[    0.000000] console [ttyS0] enabled, bootconsole disabled
[    0.000000] console [ttyS0] enabled, bootconsole disabled
[    0.000000] allocated 4194304 bytes of page_cgroup
[    0.000000] please try 'cgroup_disable=memory' option if you don't
want memory cgroups
[    0.000000] Detected 2691.682 MHz processor.
[    0.000999] Calibrating delay loop (skipped) preset value.. 5383.36
BogoMIPS (lpj=2691682)
[    0.002009] pid_max: default: 32768 minimum: 301
[    0.002722] Security Framework initialized
[    0.003146] Dentry cache hash table entries: 65536 (order: 7, 524288 bytes)
[    0.005202] Inode-cache hash table entries: 32768 (order: 6, 262144 bytes)
[    0.006221] Mount-cache hash table entries: 256
[    0.007267] Initializing cgroup subsys cpuacct
[    0.007810] Initializing cgroup subsys memory
[    0.008042] Initializing cgroup subsys devices
[    0.008591] Initializing cgroup subsys freezer
[    0.009003] Initializing cgroup subsys net_cls
[    0.009452] Initializing cgroup subsys blkio
[    0.010015] Initializing cgroup subsys perf_event
[    0.010554] CPU: Physical Processor ID: 0
[    0.011002] CPU: Processor Core ID: 0
[    0.011390] mce: CPU supports 32 MCE banks
[    0.013371] ftrace: allocating 24096 entries in 95 pages
[    0.016161] CPU0: Intel 06/2a stepping 07
[    0.118022] Performance Events: unsupported p6 CPU model 42 no PMU
driver, software events only.
[    0.119085] NMI watchdog disabled (cpu0): hardware events not enabled
[    0.119886] Booting Node   0, Processors  #1
[    0.132990] kvm-clock: cpu 1, msr 0:1bc92301, secondary cpu clock
[    0.133013] NMI watchdog disabled (cpu1): hardware events not enabled
[    0.133155]  #2
[    0.133035] KVM setup async PF for cpu 1
[    0.133035] kvm-stealtime: cpu 1, msr 1bc8d000
[    0.146998] kvm-clock: cpu 2, msr 0:1bd12301, secondary cpu clock
[    0.147018] NMI watchdog disabled (cpu2): hardware events not enabled
[    0.147158]  #3 Ok.
[    0.147042] KVM setup async PF for cpu 2
[    0.147042] kvm-stealtime: cpu 2, msr 1bd0d000
[    0.159987] kvm-clock: cpu 3, msr 0:1bd92301, secondary cpu clock
[    0.160018] NMI watchdog disabled (cpu3): hardware events not enabled
[    0.160052] Brought up 4 CPUs
[    0.160054] Total of 4 processors activated (21533.45 BogoMIPS).
[    0.160050] KVM setup async PF for cpu 3
[    0.160050] kvm-stealtime: cpu 3, msr 1bd8d000
[    0.166066] devtmpfs: initialized
[    0.169332] atomic64 test passed for x86-64 platform with CX8 and with SSE
[    0.170095] RTC time: 11:40:38, date: 12/06/11
[    0.170631] NET: Registered protocol family 16
[    0.173092] PCI: Using configuration type 1 for base access
[    0.175422] bio: create slab <bio-0> at 0
[    0.176087] ACPI: Interpreter disabled.
[    0.177069] vgaarb: loaded
[    0.177585] SCSI subsystem initialized
[    0.178077] usbcore: registered new interface driver usbfs
[    0.179013] usbcore: registered new interface driver hub
[    0.180077] usbcore: registered new device driver usb
[    0.181129] PCI: Probing PCI hardware
[    0.182273] NetLabel: Initializing
[    0.182984] NetLabel:  domain hash size = 128
[    0.183675] NetLabel:  protocols = UNLABELED CIPSOv4
[    0.183994] NetLabel:  unlabeled traffic allowed by default
[    0.184986] Switching to clocksource kvm-clock
[    0.193502] pnp: PnP ACPI: disabled
[    0.201702] NET: Registered protocol family 2
[    0.202465] IP route cache hash table entries: 4096 (order: 3, 32768 bytes)
[    0.203701] TCP established hash table entries: 16384 (order: 6,
262144 bytes)
[    0.204975] TCP bind hash table entries: 16384 (order: 6, 262144 bytes)
[    0.206334] TCP: Hash tables configured (established 16384 bind 16384)
[    0.207420] TCP reno registered
[    0.207919] UDP hash table entries: 256 (order: 1, 8192 bytes)
[    0.208865] UDP-Lite hash table entries: 256 (order: 1, 8192 bytes)
[    0.209934] NET: Registered protocol family 1
[    0.210904] kvm: no hardware support
[    0.211689] platform rtc_cmos: registered platform RTC device (no
PNP device found)
[    0.217236] alg: No test for __gcm-aes-aesni (__driver-gcm-aes-aesni)
[    0.218979] audit: initializing netlink socket (disabled)
[    0.220207] type=2000 audit(1323171638.219:1): initialized
[    0.237755] HugeTLB registered 2 MB page size, pre-allocated 0 pages
[    0.240695] VFS: Disk quotas dquot_6.5.2
[    0.241409] Dquot-cache hash table entries: 512 (order 0, 4096 bytes)
[    0.242980] Installing v9fs 9p2000 file system support
[    0.243865] msgmni has been set to 850
[    0.245846] alg: No test for stdrng (krng)
[    0.246747] NET: Registered protocol family 38
[    0.247489] Block layer SCSI generic (bsg) driver version 0.4
loaded (major 253)
[    0.248841] io scheduler noop registered
[    0.249551] io scheduler deadline registered
[    0.250295] io scheduler cfq registered (default)
[    0.251156] pci_hotplug: PCI Hot Plug PCI Core version: 0.5
[    0.252108] pciehp: PCI Express Hot Plug Controller Driver version: 0.4
[    0.253206] acpiphp: ACPI Hot Plug PCI Controller Driver version: 0.5
[    0.254505] Serial: 8250/16550 driver, 4 ports, IRQ sharing enabled
[    0.276481] serial8250: ttyS0 at I/O 0x3f8 (irq = 4) is a 16550A
[    0.306891] serial8250: ttyS1 at I/O 0x2f8 (irq = 3) is a 16550A
[    0.333156] serial8250: ttyS2 at I/O 0x3e8 (irq = 4) is a 16550A
[    0.334767] Non-volatile memory driver v1.3
[    0.335276] Linux agpgart interface v0.103
[    0.338190] brd: module loaded
[    0.339946] loop: module loaded
[    0.340440] Fixed MDIO Bus: probed
[    0.340946] ehci_hcd: USB 2.0 'Enhanced' Host Controller (EHCI) Driver
[    0.341698] ohci_hcd: USB 1.1 'Open' Host Controller (OHCI) Driver
[    0.342413] uhci_hcd: USB Universal Host Controller Interface driver
[    0.343194] usbcore: registered new interface driver usbserial
[    0.343840] USB Serial support registered for generic
[    0.344436] usbcore: registered new interface driver usbserial_generic
[    0.345170] usbserial: USB Serial Driver core
[    0.345649] i8042: PNP detection disabled
[    0.346277] serio: i8042 KBD port at 0x60,0x64 irq 1
[    0.347061] mousedev: PS/2 mouse device common for all mice
[    0.348078] input: AT Raw Set 2 keyboard as
/devices/platform/i8042/serio0/input/input0
[    0.349770] rtc_cmos rtc_cmos: rtc core: registered rtc_cmos as rtc0
[    0.350818] rtc_cmos rtc_cmos: only 24-hr supported
[    0.351831] device-mapper: uevent: version 1.0.3
[    0.352788] device-mapper: ioctl: 4.22.0-ioctl (2011-10-19)
initialised: dm-devel@redhat.com
[    0.354096] cpuidle: using governor ladder
[    0.354554] cpuidle: using governor menu
[    0.354982] EFI Variables Facility v0.08 2004-May-17
[    0.355676] usbcore: registered new interface driver usbhid
[    0.356297] usbhid: USB HID core driver
[    0.356748] ip_tables: (C) 2000-2006 Netfilter Core Team
[    0.357344] TCP cubic registered
[    0.357705] NET: Registered protocol family 17
[    0.358214] Installing 9P2000 support
[    0.358627] Registering the dns_resolver key type
[    0.359358] registered taskstats version 1
[    0.359824] IMA: No TPM chip found, activating TPM-bypass!
[    0.360677]   Magic number: 7:784:680
[    0.361129] drivers/rtc/hctosys.c: unable to open rtc device (rtc0)
[    0.361841] Initializing network drop monitor service
[    0.362933] md: Waiting for all devices to be available before autodetect
[    0.363691] md: If you don't use raid, use raid=noautodetect
[    0.364537] md: Autodetecting RAID arrays.
[    0.364997] md: Scanned 0 and added 0 devices.
[    0.365502] md: autorun ...
[    0.365809] md: ... autorun DONE.
[    0.366234] VFS: Cannot open root device "vda" or unknown-block(0,0)
[    0.367056] Please append a correct "root=" boot option; here are
the available partitions:
[    0.368484] Kernel panic - not syncing: VFS: Unable to mount root
fs on unknown-block(0,0)
[    0.369907] Pid: 1, comm: swapper Not tainted 3.2.0-rc3 #67
[    0.370644] Call Trace:
[    0.370922]  [<ffffffff8148f63b>] panic+0x91/0x1a5
[    0.371450]  [<ffffffff81b73fc9>] mount_block_root+0x250/0x27b
[    0.372107]  [<ffffffff81b7417a>] mount_root+0x53/0x57
[    0.372662]  [<ffffffff81b742eb>] prepare_namespace+0x16d/0x1a6
[    0.373312]  [<ffffffff8109b4a3>] ? release_tgcred+0x2f/0x2f
[    0.373923]  [<ffffffff81b73cb5>] kernel_init+0x153/0x158
[    0.374527]  [<ffffffff81076758>] ? schedule_tail+0x27/0x6c
[    0.375147]  [<ffffffff814a0474>] kernel_thread_helper+0x4/0x10
[    0.375785]  [<ffffffff81b73b62>] ? start_kernel+0x3bd/0x3bd
[    0.376408]  [<ffffffff814a0470>] ? gs_change+0x13/0x13
[    0.377064] Rebooting in 1 seconds..

*** Compatibility Warning ***

	virtio-blk device was not detected

While you have requested a virtio-blk device, the guest kernel did not
initialize it.
Please make sure that the guest kernel was compiled with
CONFIG_VIRTIO_BLK=y enabled in its .config

  # KVM session ended normally.
--
To unsubscribe from this list: send the line "unsubscribe kvm-ppc" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Cyrill Gorcunov Dec. 6, 2011, 11:47 a.m. UTC | #4
On Tue, Dec 06, 2011 at 01:41:56PM +0200, Pekka Enberg wrote:
> On Tue, Dec 6, 2011 at 12:28 PM, Cyrill Gorcunov <gorcunov@gmail.com> wrote:
> > On Tue, Dec 06, 2011 at 12:25:29PM +0200, Pekka Enberg wrote:
> >> On Tue, Dec 6, 2011 at 5:42 AM, Matt Evans <matt@ozlabs.org> wrote:
> >> > vesa, pci-shmem and virtio-pci devices need to set up config space with
> >> > little-endian conversions (as config space is LE).  The pci_config_address
> >> > bitfield also needs to be reversed when building on BE systems.
> >> >
> >> > Signed-off-by: Matt Evans <matt@ozlabs.org>
> >>
> >> Looks OK to me. Sasha, Cyrill?
> >>
> >
> > BIOS part looks pretty good to me. LE/BE part as well. Thanks Matt!
> 
> Hmm. This seems to break "make check" for me:
>

If you change back to

 static struct pci_device_header pci_shmem_pci_device = {
	...
	.class          = 0xFF0000,     /* misc pci device */
	...
 };

does it help?

	Cyrill
--
To unsubscribe from this list: send the line "unsubscribe kvm-ppc" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Pekka Enberg Dec. 6, 2011, 11:58 a.m. UTC | #5
On Tue, 2011-12-06 at 15:47 +0400, Cyrill Gorcunov wrote:
> On Tue, Dec 06, 2011 at 01:41:56PM +0200, Pekka Enberg wrote:
> > On Tue, Dec 6, 2011 at 12:28 PM, Cyrill Gorcunov <gorcunov@gmail.com> wrote:
> > > On Tue, Dec 06, 2011 at 12:25:29PM +0200, Pekka Enberg wrote:
> > >> On Tue, Dec 6, 2011 at 5:42 AM, Matt Evans <matt@ozlabs.org> wrote:
> > >> > vesa, pci-shmem and virtio-pci devices need to set up config space with
> > >> > little-endian conversions (as config space is LE).  The pci_config_address
> > >> > bitfield also needs to be reversed when building on BE systems.
> > >> >
> > >> > Signed-off-by: Matt Evans <matt@ozlabs.org>
> > >>
> > >> Looks OK to me. Sasha, Cyrill?
> > >>
> > >
> > > BIOS part looks pretty good to me. LE/BE part as well. Thanks Matt!
> > 
> > Hmm. This seems to break "make check" for me:
> >
> 
> If you change back to
> 
>  static struct pci_device_header pci_shmem_pci_device = {
> 	...
> 	.class          = 0xFF0000,     /* misc pci device */
> 	...
>  };
> 
> does it help?

No but dropping these hunks fixes it for me:

@@ -17,7 +18,8 @@
 #define PCI_CONFIG_BUS_FORWARD 0xcfa
 #define PCI_IO_SIZE            0x100

-struct pci_config_address {
+union pci_config_address {
+#if __BYTE_ORDER == __LITTLE_ENDIAN
       unsigned        zeros           : 2;            /* 1  .. 0  */
       unsigned        register_number : 6;            /* 7  .. 2  */
       unsigned        function_number : 3;            /* 10 .. 8  */
@@ -25,6 +27,16 @@ struct pci_config_address {
       unsigned        bus_number      : 8;            /* 23 .. 16 */
       unsigned        reserved        : 7;            /* 30 .. 24 */
       unsigned        enable_bit      : 1;            /* 31       */
+#else
+       unsigned        enable_bit      : 1;            /* 31       */
+       unsigned        reserved        : 7;            /* 30 .. 24 */
+       unsigned        bus_number      : 8;            /* 23 .. 16 */
+       unsigned        device_number   : 5;            /* 15 .. 11 */
+       unsigned        function_number : 3;            /* 10 .. 8  */
+       unsigned        register_number : 6;            /* 7  .. 2  */
+       unsigned        zeros           : 2;            /* 1  .. 0  */
+#endif
+       u32 w;
 };

			Pekka

--
To unsubscribe from this list: send the line "unsubscribe kvm-ppc" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Cyrill Gorcunov Dec. 6, 2011, 12:10 p.m. UTC | #6
On Tue, Dec 06, 2011 at 01:58:24PM +0200, Pekka Enberg wrote:
> On Tue, 2011-12-06 at 15:47 +0400, Cyrill Gorcunov wrote:
> > On Tue, Dec 06, 2011 at 01:41:56PM +0200, Pekka Enberg wrote:
> > > On Tue, Dec 6, 2011 at 12:28 PM, Cyrill Gorcunov <gorcunov@gmail.com> wrote:
> > > > On Tue, Dec 06, 2011 at 12:25:29PM +0200, Pekka Enberg wrote:
> > > >> On Tue, Dec 6, 2011 at 5:42 AM, Matt Evans <matt@ozlabs.org> wrote:
> > > >> > vesa, pci-shmem and virtio-pci devices need to set up config space with
> > > >> > little-endian conversions (as config space is LE).  The pci_config_address
> > > >> > bitfield also needs to be reversed when building on BE systems.
> > > >> >
> > > >> > Signed-off-by: Matt Evans <matt@ozlabs.org>
> > > >>
> > > >> Looks OK to me. Sasha, Cyrill?
> > > >>
> > > >
> > > > BIOS part looks pretty good to me. LE/BE part as well. Thanks Matt!
> > > 
> > > Hmm. This seems to break "make check" for me:
> > >
> > 
> > If you change back to
> > 
> >  static struct pci_device_header pci_shmem_pci_device = {
> > 	...
> > 	.class          = 0xFF0000,     /* misc pci device */
> > 	...
> >  };
> > 
> > does it help?
> 
> No but dropping these hunks fixes it for me:
> 
> @@ -17,7 +18,8 @@
>  #define PCI_CONFIG_BUS_FORWARD 0xcfa
>  #define PCI_IO_SIZE            0x100
> 
> -struct pci_config_address {
> +union pci_config_address {
> +#if __BYTE_ORDER == __LITTLE_ENDIAN
>        unsigned        zeros           : 2;            /* 1  .. 0  */
>        unsigned        register_number : 6;            /* 7  .. 2  */
>        unsigned        function_number : 3;            /* 10 .. 8  */
> @@ -25,6 +27,16 @@ struct pci_config_address {
>        unsigned        bus_number      : 8;            /* 23 .. 16 */
>        unsigned        reserved        : 7;            /* 30 .. 24 */
>        unsigned        enable_bit      : 1;            /* 31       */
> +#else
> +       unsigned        enable_bit      : 1;            /* 31       */
> +       unsigned        reserved        : 7;            /* 30 .. 24 */
> +       unsigned        bus_number      : 8;            /* 23 .. 16 */
> +       unsigned        device_number   : 5;            /* 15 .. 11 */
> +       unsigned        function_number : 3;            /* 10 .. 8  */
> +       unsigned        register_number : 6;            /* 7  .. 2  */
> +       unsigned        zeros           : 2;            /* 1  .. 0  */
> +#endif
> +       u32 w;
>  };
> 
> 			Pekka
> 

Hehe, this is because it should be rtaher defined as

union pci_config_address {
 struct {
  #if __BYTE_ORDER == __LITTLE_ENDIAN
    unsigned        zeros           : 2;
    unsigned        register_number : 6;
  #else
    ...
  #endif
 }
 u32 w;
};

	Cyrill
--
To unsubscribe from this list: send the line "unsubscribe kvm-ppc" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Pekka Enberg Dec. 6, 2011, 1:29 p.m. UTC | #7
On Tue, 6 Dec 2011, Cyrill Gorcunov wrote:
> On Tue, Dec 06, 2011 at 01:58:24PM +0200, Pekka Enberg wrote:
>> On Tue, 2011-12-06 at 15:47 +0400, Cyrill Gorcunov wrote:
>>> On Tue, Dec 06, 2011 at 01:41:56PM +0200, Pekka Enberg wrote:
>>>> On Tue, Dec 6, 2011 at 12:28 PM, Cyrill Gorcunov <gorcunov@gmail.com> wrote:
>>>>> On Tue, Dec 06, 2011 at 12:25:29PM +0200, Pekka Enberg wrote:
>>>>>> On Tue, Dec 6, 2011 at 5:42 AM, Matt Evans <matt@ozlabs.org> wrote:
>>>>>>> vesa, pci-shmem and virtio-pci devices need to set up config space with
>>>>>>> little-endian conversions (as config space is LE).  The pci_config_address
>>>>>>> bitfield also needs to be reversed when building on BE systems.
>>>>>>>
>>>>>>> Signed-off-by: Matt Evans <matt@ozlabs.org>
>>>>>>
>>>>>> Looks OK to me. Sasha, Cyrill?
>>>>>>
>>>>>
>>>>> BIOS part looks pretty good to me. LE/BE part as well. Thanks Matt!
>>>>
>>>> Hmm. This seems to break "make check" for me:
>>>>
>>>
>>> If you change back to
>>>
>>>  static struct pci_device_header pci_shmem_pci_device = {
>>> 	...
>>> 	.class          = 0xFF0000,     /* misc pci device */
>>> 	...
>>>  };
>>>
>>> does it help?
>>
>> No but dropping these hunks fixes it for me:
>>
>> @@ -17,7 +18,8 @@
>>  #define PCI_CONFIG_BUS_FORWARD 0xcfa
>>  #define PCI_IO_SIZE            0x100
>>
>> -struct pci_config_address {
>> +union pci_config_address {
>> +#if __BYTE_ORDER == __LITTLE_ENDIAN
>>        unsigned        zeros           : 2;            /* 1  .. 0  */
>>        unsigned        register_number : 6;            /* 7  .. 2  */
>>        unsigned        function_number : 3;            /* 10 .. 8  */
>> @@ -25,6 +27,16 @@ struct pci_config_address {
>>        unsigned        bus_number      : 8;            /* 23 .. 16 */
>>        unsigned        reserved        : 7;            /* 30 .. 24 */
>>        unsigned        enable_bit      : 1;            /* 31       */
>> +#else
>> +       unsigned        enable_bit      : 1;            /* 31       */
>> +       unsigned        reserved        : 7;            /* 30 .. 24 */
>> +       unsigned        bus_number      : 8;            /* 23 .. 16 */
>> +       unsigned        device_number   : 5;            /* 15 .. 11 */
>> +       unsigned        function_number : 3;            /* 10 .. 8  */
>> +       unsigned        register_number : 6;            /* 7  .. 2  */
>> +       unsigned        zeros           : 2;            /* 1  .. 0  */
>> +#endif
>> +       u32 w;
>>  };
>>
>> 			Pekka
>>
>
> Hehe, this is because it should be rtaher defined as
>
> union pci_config_address {
> struct {
>  #if __BYTE_ORDER == __LITTLE_ENDIAN
>    unsigned        zeros           : 2;
>    unsigned        register_number : 6;
>  #else
>    ...
>  #endif
> }
> u32 w;
> };

Yup, that fixes it for me.

 			Pekka
--
To unsubscribe from this list: send the line "unsubscribe kvm-ppc" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Cyrill Gorcunov Dec. 6, 2011, 1:38 p.m. UTC | #8
On Tue, Dec 06, 2011 at 03:29:00PM +0200, Pekka Enberg wrote:
> >
> >Hehe, this is because it should be rtaher defined as
> >
> >union pci_config_address {
> >struct {
> > #if __BYTE_ORDER == __LITTLE_ENDIAN
> >   unsigned        zeros           : 2;
> >   unsigned        register_number : 6;
> > #else
> >   ...
> > #endif
> >}
> >u32 w;
> >};
> 
> Yup, that fixes it for me.
> 

Good. Matt, mind to update?

	Cyrill
--
To unsubscribe from this list: send the line "unsubscribe kvm-ppc" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Matt Evans Dec. 7, 2011, 2:58 a.m. UTC | #9
On 07/12/11 00:38, Cyrill Gorcunov wrote:
> On Tue, Dec 06, 2011 at 03:29:00PM +0200, Pekka Enberg wrote:
>>>
>>> Hehe, this is because it should be rtaher defined as
>>>
>>> union pci_config_address {
>>> struct {
>>> #if __BYTE_ORDER == __LITTLE_ENDIAN
>>>   unsigned        zeros           : 2;
>>>   unsigned        register_number : 6;
>>> #else
>>>   ...
>>> #endif
>>> }
>>> u32 w;
>>> };
>>
>> Yup, that fixes it for me.
>>
> 
> Good. Matt, mind to update?

Absolutely -- thank you for digging in and debugging that!  I'll repost a V2.


Cheers,


Matt
--
To unsubscribe from this list: send the line "unsubscribe kvm-ppc" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/tools/kvm/hw/pci-shmem.c b/tools/kvm/hw/pci-shmem.c
index 780a377..fd954c5 100644
--- a/tools/kvm/hw/pci-shmem.c
+++ b/tools/kvm/hw/pci-shmem.c
@@ -8,21 +8,22 @@ 
 #include "kvm/ioeventfd.h"
 
 #include <linux/kvm.h>
+#include <linux/byteorder.h>
 #include <sys/ioctl.h>
 #include <fcntl.h>
 #include <sys/mman.h>
 
 static struct pci_device_header pci_shmem_pci_device = {
-	.vendor_id	= PCI_VENDOR_ID_REDHAT_QUMRANET,
-	.device_id	= 0x1110,
+	.vendor_id	= cpu_to_le16(PCI_VENDOR_ID_REDHAT_QUMRANET),
+	.device_id	= cpu_to_le16(0x1110),
 	.header_type	= PCI_HEADER_TYPE_NORMAL,
-	.class		= 0xFF0000,	/* misc pci device */
-	.status		= PCI_STATUS_CAP_LIST,
+	.class[2]	= 0xFF,	/* misc pci device */
+	.status		= cpu_to_le16(PCI_STATUS_CAP_LIST),
 	.capabilities	= (void *)&pci_shmem_pci_device.msix - (void *)&pci_shmem_pci_device,
 	.msix.cap	= PCI_CAP_ID_MSIX,
-	.msix.ctrl	= 1,
-	.msix.table_offset = 1,		/* Use BAR 1 */
-	.msix.pba_offset = 0x1001,	/* Use BAR 1 */
+	.msix.ctrl	= cpu_to_le16(1),
+	.msix.table_offset = cpu_to_le32(1),		/* Use BAR 1 */
+	.msix.pba_offset = cpu_to_le32(0x1001),		/* Use BAR 1 */
 };
 
 /* registers for the Inter-VM shared memory device */
@@ -123,7 +124,7 @@  int pci_shmem__get_local_irqfd(struct kvm *kvm)
 		if (fd < 0)
 			return fd;
 
-		if (pci_shmem_pci_device.msix.ctrl & PCI_MSIX_FLAGS_ENABLE) {
+		if (pci_shmem_pci_device.msix.ctrl & cpu_to_le16(PCI_MSIX_FLAGS_ENABLE)) {
 			gsi = irq__add_msix_route(kvm, &msix_table[0].msg);
 		} else {
 			gsi = pci_shmem_pci_device.irq_line;
@@ -241,11 +242,11 @@  int pci_shmem__init(struct kvm *kvm)
 	 * 1 - MSI-X MMIO space
 	 * 2 - Shared memory block
 	 */
-	pci_shmem_pci_device.bar[0] = ivshmem_registers | PCI_BASE_ADDRESS_SPACE_IO;
+	pci_shmem_pci_device.bar[0] = cpu_to_le32(ivshmem_registers | PCI_BASE_ADDRESS_SPACE_IO);
 	pci_shmem_pci_device.bar_size[0] = shmem_region->size;
-	pci_shmem_pci_device.bar[1] = msix_block | PCI_BASE_ADDRESS_SPACE_MEMORY;
+	pci_shmem_pci_device.bar[1] = cpu_to_le32(msix_block | PCI_BASE_ADDRESS_SPACE_MEMORY);
 	pci_shmem_pci_device.bar_size[1] = 0x1010;
-	pci_shmem_pci_device.bar[2] = shmem_region->phys_addr | PCI_BASE_ADDRESS_SPACE_MEMORY;
+	pci_shmem_pci_device.bar[2] = cpu_to_le32(shmem_region->phys_addr | PCI_BASE_ADDRESS_SPACE_MEMORY);
 	pci_shmem_pci_device.bar_size[2] = shmem_region->size;
 
 	pci__register(&pci_shmem_pci_device, dev);
diff --git a/tools/kvm/hw/vesa.c b/tools/kvm/hw/vesa.c
index 22b1652..63f1082 100644
--- a/tools/kvm/hw/vesa.c
+++ b/tools/kvm/hw/vesa.c
@@ -8,6 +8,7 @@ 
 #include "kvm/irq.h"
 #include "kvm/kvm.h"
 #include "kvm/pci.h"
+#include <linux/byteorder.h>
 #include <sys/mman.h>
 
 #include <sys/types.h>
@@ -31,14 +32,14 @@  static struct ioport_operations vesa_io_ops = {
 };
 
 static struct pci_device_header vesa_pci_device = {
-	.vendor_id		= PCI_VENDOR_ID_REDHAT_QUMRANET,
-	.device_id		= PCI_DEVICE_ID_VESA,
+	.vendor_id		= cpu_to_le16(PCI_VENDOR_ID_REDHAT_QUMRANET),
+	.device_id		= cpu_to_le16(PCI_DEVICE_ID_VESA),
 	.header_type		= PCI_HEADER_TYPE_NORMAL,
 	.revision_id		= 0,
-	.class			= 0x030000,
-	.subsys_vendor_id	= PCI_SUBSYSTEM_VENDOR_ID_REDHAT_QUMRANET,
-	.subsys_id		= PCI_SUBSYSTEM_ID_VESA,
-	.bar[1]			= VESA_MEM_ADDR | PCI_BASE_ADDRESS_SPACE_MEMORY,
+	.class[2]		= 0x03,
+	.subsys_vendor_id	= cpu_to_le16(PCI_SUBSYSTEM_VENDOR_ID_REDHAT_QUMRANET),
+	.subsys_id		= cpu_to_le16(PCI_SUBSYSTEM_ID_VESA),
+	.bar[1]			= cpu_to_le32(VESA_MEM_ADDR | PCI_BASE_ADDRESS_SPACE_MEMORY),
 	.bar_size[1]		= VESA_MEM_SIZE,
 };
 
@@ -56,7 +57,7 @@  struct framebuffer *vesa__init(struct kvm *kvm)
 	vesa_pci_device.irq_pin		= pin;
 	vesa_pci_device.irq_line	= line;
 	vesa_base_addr			= ioport__register(IOPORT_EMPTY, &vesa_io_ops, IOPORT_SIZE, NULL);
-	vesa_pci_device.bar[0]		= vesa_base_addr | PCI_BASE_ADDRESS_SPACE_IO;
+	vesa_pci_device.bar[0]		= cpu_to_le32(vesa_base_addr | PCI_BASE_ADDRESS_SPACE_IO);
 	pci__register(&vesa_pci_device, dev);
 
 	mem = mmap(NULL, VESA_MEM_SIZE, PROT_RW, MAP_ANON_NORESERVE, -1, 0);
diff --git a/tools/kvm/include/kvm/ioport.h b/tools/kvm/include/kvm/ioport.h
index 61a70ec..09bf876 100644
--- a/tools/kvm/include/kvm/ioport.h
+++ b/tools/kvm/include/kvm/ioport.h
@@ -7,6 +7,7 @@ 
 #include <limits.h>
 #include <asm/types.h>
 #include <linux/types.h>
+#include <linux/byteorder.h>
 
 /* some ports we reserve for own use */
 #define IOPORT_DBG			0xe0
@@ -36,15 +37,15 @@  static inline u8 ioport__read8(u8 *data)
 {
 	return *data;
 }
-
+/* On BE platforms, PCI I/O is byteswapped, i.e. LE, so swap back. */
 static inline u16 ioport__read16(u16 *data)
 {
-	return *data;
+	return le16_to_cpu(*data);
 }
 
 static inline u32 ioport__read32(u32 *data)
 {
-	return *data;
+	return le32_to_cpu(*data);
 }
 
 static inline void ioport__write8(u8 *data, u8 value)
@@ -54,12 +55,12 @@  static inline void ioport__write8(u8 *data, u8 value)
 
 static inline void ioport__write16(u16 *data, u16 value)
 {
-	*data		 = value;
+	*data		 = cpu_to_le16(value);
 }
 
 static inline void ioport__write32(u32 *data, u32 value)
 {
-	*data		 = value;
+	*data		 = cpu_to_le32(value);
 }
 
 #endif /* KVM__IOPORT_H */
diff --git a/tools/kvm/include/kvm/pci.h b/tools/kvm/include/kvm/pci.h
index b578ad7..88e92dc 100644
--- a/tools/kvm/include/kvm/pci.h
+++ b/tools/kvm/include/kvm/pci.h
@@ -5,6 +5,7 @@ 
 #include <linux/kvm.h>
 #include <linux/pci_regs.h>
 #include <linux/msi.h>
+#include <endian.h>
 
 #define PCI_MAX_DEVICES			256
 /*
@@ -17,7 +18,8 @@ 
 #define PCI_CONFIG_BUS_FORWARD	0xcfa
 #define PCI_IO_SIZE		0x100
 
-struct pci_config_address {
+union pci_config_address {
+#if __BYTE_ORDER == __LITTLE_ENDIAN
 	unsigned	zeros		: 2;		/* 1  .. 0  */
 	unsigned	register_number	: 6;		/* 7  .. 2  */
 	unsigned	function_number	: 3;		/* 10 .. 8  */
@@ -25,6 +27,16 @@  struct pci_config_address {
 	unsigned	bus_number	: 8;		/* 23 .. 16 */
 	unsigned	reserved	: 7;		/* 30 .. 24 */
 	unsigned	enable_bit	: 1;		/* 31       */
+#else
+	unsigned	enable_bit	: 1;		/* 31       */
+	unsigned	reserved	: 7;		/* 30 .. 24 */
+	unsigned	bus_number	: 8;		/* 23 .. 16 */
+	unsigned	device_number	: 5;		/* 15 .. 11 */
+	unsigned	function_number	: 3;		/* 10 .. 8  */
+	unsigned	register_number	: 6;		/* 7  .. 2  */
+	unsigned	zeros		: 2;		/* 1  .. 0  */
+#endif
+	u32 w;
 };
 
 struct msix_table {
@@ -45,8 +57,8 @@  struct pci_device_header {
 	u16		device_id;
 	u16		command;
 	u16		status;
-	u16		revision_id		:  8;
-	u32		class			: 24;
+	u8		revision_id;
+	u8		class[3];
 	u8		cacheline_size;
 	u8		latency_timer;
 	u8		header_type;
@@ -56,8 +68,8 @@  struct pci_device_header {
 	u16		subsys_vendor_id;
 	u16		subsys_id;
 	u32		exp_rom_bar;
-	u32		capabilities		:  8;
-	u32		reserved1		: 24;
+	u8		capabilities;
+	u8		reserved1[3];
 	u32		reserved2;
 	u8		irq_line;
 	u8		irq_pin;
@@ -66,7 +78,7 @@  struct pci_device_header {
 	struct msix_cap msix;
 	u8		empty[136]; /* Rest of PCI config space */
 	u32		bar_size[6];
-};
+} __attribute__((packed));
 
 void pci__init(void);
 void pci__register(struct pci_device_header *dev, u8 dev_num);
diff --git a/tools/kvm/pci.c b/tools/kvm/pci.c
index 920e13e..5bbcbc7 100644
--- a/tools/kvm/pci.c
+++ b/tools/kvm/pci.c
@@ -9,7 +9,7 @@ 
 
 static struct pci_device_header		*pci_devices[PCI_MAX_DEVICES];
 
-static struct pci_config_address	pci_config_address;
+static union pci_config_address		pci_config_address;
 
 /* This is within our PCI gap - in an unused area */
 static u32 io_space_blocks		= KVM_32BIT_GAP_START + 0x1000000;
@@ -105,7 +105,7 @@  static bool pci_config_data_out(struct ioport *ioport, struct kvm *kvm, u16 port
 			 * When the kernel got the size it would write the address
 			 * back.
 			 */
-			if (ioport__read32(p + offset)) {
+			if (*(u32 *)(p + offset)) {
 				/* See if kernel tries to mask one of the BARs */
 				if ((offset >= PCI_BAR_OFFSET(0)) &&
 				    (offset <= PCI_BAR_OFFSET(6)) &&
diff --git a/tools/kvm/virtio/pci.c b/tools/kvm/virtio/pci.c
index 0737ae7..0ae93fb 100644
--- a/tools/kvm/virtio/pci.c
+++ b/tools/kvm/virtio/pci.c
@@ -9,6 +9,7 @@ 
 #include "kvm/virtio-trans.h"
 
 #include <linux/virtio_pci.h>
+#include <linux/byteorder.h>
 #include <string.h>
 
 struct virtio_trans_ops *virtio_pci__get_trans_ops(void)
@@ -59,7 +60,7 @@  static int virtio_pci__init_ioeventfd(struct kvm *kvm, struct virtio_trans *vtra
 
 static inline bool virtio_pci__msix_enabled(struct virtio_pci *vpci)
 {
-	return vpci->pci_hdr.msix.ctrl & PCI_MSIX_FLAGS_ENABLE;
+	return vpci->pci_hdr.msix.ctrl & cpu_to_le16(PCI_MSIX_FLAGS_ENABLE);
 }
 
 static bool virtio_pci__specific_io_in(struct kvm *kvm, struct virtio_trans *vtrans, u16 port,
@@ -245,8 +246,8 @@  int virtio_pci__signal_vq(struct kvm *kvm, struct virtio_trans *vtrans, u32 vq)
 	int tbl = vpci->vq_vector[vq];
 
 	if (virtio_pci__msix_enabled(vpci)) {
-		if (vpci->pci_hdr.msix.ctrl & PCI_MSIX_FLAGS_MASKALL ||
-			vpci->msix_table[tbl].ctrl & PCI_MSIX_ENTRY_CTRL_MASKBIT) {
+		if (vpci->pci_hdr.msix.ctrl & cpu_to_le16(PCI_MSIX_FLAGS_MASKALL) ||
+		    vpci->msix_table[tbl].ctrl & cpu_to_le16(PCI_MSIX_ENTRY_CTRL_MASKBIT)) {
 
 			vpci->msix_pba |= 1 << tbl;
 			return 0;
@@ -266,8 +267,8 @@  int virtio_pci__signal_config(struct kvm *kvm, struct virtio_trans *vtrans)
 	int tbl = vpci->config_vector;
 
 	if (virtio_pci__msix_enabled(vpci)) {
-		if (vpci->pci_hdr.msix.ctrl & PCI_MSIX_FLAGS_MASKALL ||
-			vpci->msix_table[tbl].ctrl & PCI_MSIX_ENTRY_CTRL_MASKBIT) {
+		if (vpci->pci_hdr.msix.ctrl & cpu_to_le16(PCI_MSIX_FLAGS_MASKALL) ||
+		    vpci->msix_table[tbl].ctrl & cpu_to_le16(PCI_MSIX_ENTRY_CTRL_MASKBIT)) {
 
 			vpci->msix_pba |= 1 << tbl;
 			return 0;
@@ -297,19 +298,21 @@  int virtio_pci__init(struct kvm *kvm, struct virtio_trans *vtrans, void *dev,
 	kvm__register_mmio(kvm, vpci->msix_pba_block, 0x100, callback_mmio_pba, vpci);
 
 	vpci->pci_hdr = (struct pci_device_header) {
-		.vendor_id		= PCI_VENDOR_ID_REDHAT_QUMRANET,
-		.device_id		= device_id,
+		.vendor_id		= cpu_to_le16(PCI_VENDOR_ID_REDHAT_QUMRANET),
+		.device_id		= cpu_to_le16(device_id),
 		.header_type		= PCI_HEADER_TYPE_NORMAL,
 		.revision_id		= 0,
-		.class			= class,
-		.subsys_vendor_id	= PCI_SUBSYSTEM_VENDOR_ID_REDHAT_QUMRANET,
-		.subsys_id		= subsys_id,
-		.bar[0]			= vpci->base_addr | PCI_BASE_ADDRESS_SPACE_IO,
-		.bar[1]			= vpci->msix_io_block | PCI_BASE_ADDRESS_SPACE_MEMORY
-					| PCI_BASE_ADDRESS_MEM_TYPE_64,
-		.bar[3]			= vpci->msix_pba_block | PCI_BASE_ADDRESS_SPACE_MEMORY
-					| PCI_BASE_ADDRESS_MEM_TYPE_64,
-		.status			= PCI_STATUS_CAP_LIST,
+		.class[0]		= class & 0xff,
+		.class[1]		= (class >> 8) & 0xff,
+		.class[2]		= (class >> 16) & 0xff,
+		.subsys_vendor_id	= cpu_to_le16(PCI_SUBSYSTEM_VENDOR_ID_REDHAT_QUMRANET),
+		.subsys_id		= cpu_to_le16(subsys_id),
+		.bar[0]			= cpu_to_le32(vpci->base_addr | PCI_BASE_ADDRESS_SPACE_IO),
+		.bar[1]			= cpu_to_le32(vpci->msix_io_block | PCI_BASE_ADDRESS_SPACE_MEMORY
+						      | PCI_BASE_ADDRESS_MEM_TYPE_64),
+		.bar[3]			= cpu_to_le32(vpci->msix_pba_block | PCI_BASE_ADDRESS_SPACE_MEMORY
+						      | PCI_BASE_ADDRESS_MEM_TYPE_64),
+		.status			= cpu_to_le16(PCI_STATUS_CAP_LIST),
 		.capabilities		= (void *)&vpci->pci_hdr.msix - (void *)&vpci->pci_hdr,
 	};
 
@@ -326,14 +329,14 @@  int virtio_pci__init(struct kvm *kvm, struct virtio_trans *vtrans, void *dev,
 	 * For example, a returned value of "00000000011"
 	 * indicates a table size of 4.
 	 */
-	vpci->pci_hdr.msix.ctrl = (VIRTIO_PCI_MAX_VQ + VIRTIO_PCI_MAX_CONFIG - 1);
+	vpci->pci_hdr.msix.ctrl = cpu_to_le16(VIRTIO_PCI_MAX_VQ + VIRTIO_PCI_MAX_CONFIG - 1);
 
 	/*
 	 * Both table and PBA could be mapped on the same BAR, but for now
 	 * we're not in short of BARs
 	 */
-	vpci->pci_hdr.msix.table_offset = 1; /* Use BAR 1 */
-	vpci->pci_hdr.msix.pba_offset = 3; /* Use BAR 3 */
+	vpci->pci_hdr.msix.table_offset = cpu_to_le32(1); /* Use BAR 1 */
+	vpci->pci_hdr.msix.pba_offset = cpu_to_le32(3); /* Use BAR 3 */
 	vpci->config_vector = 0;
 
 	if (irq__register_device(subsys_id, &ndev, &pin, &line) < 0)