Skip to contentSkip to conversation

PCI Passthru: fn0 exported but not fn1

DISCUSSION Jambunathan K 3 participants 6 messages Aug 29, 2007 – Aug 30, 2007 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): C2FA6F3A.D05F%[email protected]

#1 lore raw
Quoted 14 lines · Keir Fraser
Quoted 8 lines

As I worte accidently direct to Keir and not to the list, I face the same problem. I'd like to have option 1, because it worked fine and I don't see a benefit of having a dummy device in the domU.

Dedecating single fnX to a domain is very usefull for example to give the domUs ethernets of a four port card. I'm also running one domU that is only using one of the USB 1.x controllers of a USB PCI addon card.

Okay, if you want to check out the 'fix' to revert behaviour to that of 3.0.4 for yourselves, it is to edit linux/include/asm-i386/mach-xen/asm/pci.h and to change the definition therein of pcibios_scan_all_fns() from 0 to 1.

Quoted 5 lines

If you are building a 64-bit kernel then of course it is the file in include/asm-x86_64 that you need to edit.

Make that change and rebuild you domU. Additionally, make sure you build dom0 with pciback in passthrough mode. Hopefully your problems will be gone!

I am using x86_64.

Just to be sure I 'fixed' linux-2.6-xen-sparse/include/asm-x86_64/mach-xen/asm/pci.h and made a clean build from xen source tar. I ensured that BACKEND_PASS is set to yes.

I am using the same vmlinuz both on Dom0 and Dom1. I am seeing that lspci in Dom1 *doesn't* report the exported non-zero function.

XEN-PROTO-SUSE $ cat linux-2.6.18-xen/include/asm-x86_64/mach-xen/asm/pci.h | grep scan /* Can be used to override the logic in pci_scan_bus for skipping
#define pcibios_scan_all_fns(a, b) 1
struct pci_bus * pcibios_scan_root(int bus);

XEN-PROTO-SUSE $ cat linux-2.6-xen-sparse/include/asm-x86_64/mach-xen/asm/pci.h | grep scan /* Can be used to override the logic in pci_scan_bus for skipping
#define pcibios_scan_all_fns(a, b) 1
struct pci_bus * pcibios_scan_root(int bus);

XEN-PROTO-SUSE $ uname -a
Linux xen2 2.6.18-xen-310-new-xen #2 SMP Wed Aug 29 08:44:29 EDT 2007 x86_64 x86_64 x86_64 GNU/Linux

XEN-PROTO-RHEL $ dmesg | grep pcifront

Bootdata ok (command line is root=/dev/sda10 pcifront.verbose_request=1) Kernel command line: root=/dev/sda10 pcifront.verbose_request=1 pcifront pci-0: Installing PCI frontend
pcifront pci-0: Creating PCI Frontend Bus 0000:04
pcifront pci-0: read dev=0000:04:00.0 - offset 0 size 4 pcifront pci-0: read dev=0000:04:01.0 - offset 0 size 4 pcifront pci-0: read dev=0000:04:02.0 - offset 0 size 4 pcifront pci-0: read dev=0000:04:03.0 - offset 0 size 4 pcifront pci-0: read dev=0000:04:04.0 - offset 0 size 4 pcifront pci-0: read dev=0000:04:05.0 - offset 0 size 4 pcifront pci-0: read dev=0000:04:06.0 - offset 0 size 4 pcifront pci-0: read dev=0000:04:07.0 - offset 0 size 4 pcifront pci-0: read dev=0000:04:08.0 - offset 0 size 4 pcifront pci-0: read dev=0000:04:09.0 - offset 0 size 4 pcifront pci-0: read dev=0000:04:0a.0 - offset 0 size 4 pcifront pci-0: read dev=0000:04:0b.0 - offset 0 size 4 pcifront pci-0: read dev=0000:04:0c.0 - offset 0 size 4 pcifront pci-0: read dev=0000:04:0d.0 - offset 0 size 4 pcifront pci-0: read dev=0000:04:0e.0 - offset 0 size 4 pcifront pci-0: read dev=0000:04:0f.0 - offset 0 size 4 pcifront pci-0: read dev=0000:04:10.0 - offset 0 size 4 pcifront pci-0: read dev=0000:04:11.0 - offset 0 size 4 pcifront pci-0: read dev=0000:04:12.0 - offset 0 size 4 pcifront pci-0: read dev=0000:04:13.0 - offset 0 size 4 pcifront pci-0: read dev=0000:04:14.0 - offset 0 size 4 pcifront pci-0: read dev=0000:04:15.0 - offset 0 size 4 pcifront pci-0: read dev=0000:04:16.0 - offset 0 size 4 pcifront pci-0: read dev=0000:04:17.0 - offset 0 size 4 pcifront pci-0: read dev=0000:04:18.0 - offset 0 size 4 pcifront pci-0: read dev=0000:04:19.0 - offset 0 size 4 pcifront pci-0: read dev=0000:04:1a.0 - offset 0 size 4 pcifront pci-0: read dev=0000:04:1b.0 - offset 0 size 4 pcifront pci-0: read dev=0000:04:1c.0 - offset 0 size 4 pcifront pci-0: read dev=0000:04:1d.0 - offset 0 size 4 pcifront pci-0: read dev=0000:04:1e.0 - offset 0 size 4 pcifront pci-0: read dev=0000:04:1f.0 - offset 0 size 4

XEN-PROTO-SUSE $ xenstore-ls /local/domain/0/backend/pci 13 = ""
0 = ""
domain = "pvm-guest-1"
frontend = "/local/domain/13/device/pci/0" uuid = "e294e348-fc0a-9bf1-fcf9-93f9665505bd" dev-0 = "0000:04:00.01"
state = "4"
online = "1"
frontend-id = "13"
num_devs = "1"
root-0 = "0000:04"
root_num = "1"

XEN-PROTO-SUSE $ xenstore-ls /local/domain/13/device/pci 0 = ""
state = "4"
backend-id = "0"
backend = "/local/domain/0/backend/pci/13/0" pci-op-ref = "8"
event-channel = "6"
magic = "7"

XEN-PROTO-SUSE $ xm list --long
(domain

    (domid 0)
    (on_crash restart)
    (uuid 00000000-0000-0000-0000-000000000000)
    (bootloader_args )
    (vcpus 8)
    (name Domain-0)
    (on_poweroff destroy)
    (on_reboot restart)
    (bootloader )
    (maxmem 16777215)
    (memory 1600)
    (shadow_memory 0)
    (cpu_weight 256)
    (cpu_cap 0)
    (features )
    (on_xend_start ignore)
    (on_xend_stop ignore)
    (cpu_time 301.173107752)
    (online_vcpus 8)
    (image (linux (kernel ) (rtc_timeoffset 0)))
    (status 2)
    (state r-----)
)
(domain
    (domid 13)
    (on_crash restart)
    (uuid 0b2b804f-e5ed-f046-ae7e-819037019c21)
    (bootloader_args )
    (vcpus 1)
    (name pvm-guest-1)
    (on_poweroff destroy)
    (on_reboot restart)
    (bootloader )
    (maxmem 1700)
    (memory 1700)
    (shadow_memory 0)
    (cpu_weight 256)
    (cpu_cap 0)
    (features )
    (on_xend_start ignore)
    (on_xend_stop ignore)
    (start_time 1188396494.65)
    (cpu_time 7.201405283)
    (online_vcpus 1)
    (image
        (linux
            (kernel /boot/xen310-new/vmlinuz-2.6.18-xen-310-new-xen)
            (ramdisk /boot/xen310-new/initrd-2.6.18-xen-310-new-xen.img)
            (args 'root=/dev/sda10 pcifront.verbose_request=1')
            (rtc_timeoffset 0)
            (notes
                (FEATURES

'writable_page_tables|writable_descriptor_tables|auto_translated_physmap|pae_pgdir_above_4gb|supervisor_mode_kernel'

                )
                (VIRT_BASE -2147483648)
                (GUEST_VERSION 2.6)
                (PADDR_OFFSET -2147483648)
                (GUEST_OS linux)
                (HYPERCALL_PAGE -2145361920)
                (LOADER generic)
                (SUSPEND_CANCEL 1)
                (ENTRY -2145386496)
                (XEN_VERSION xen-3.0)
            )
        )
    )
    (status 2)
    (state -b----)
    (store_mfn 1400305)
    (console_mfn 1400304)
    (device
        (vif
            (bridge xenbr0)
            (uuid 65d1b021-70ff-d673-d59c-15a1432edfd4)
            (script vif-bridge)
            (mac aa:cc:00:00:00:01)
            (type netfront)
            (backend 0)
        )
    )
    (device
        (vbd
            (uname phy:VolGroup00/LogVol01)
            (uuid f1abc318-00cf-8d70-4a98-7b6b3c8e7630)
            (mode w)
            (dev sda10:disk)
            (backend 0)
            (bootable 1)
        )
    )
    (device
        (vbd
            (uname phy:VolGroup00/LogVol00)
            (uuid 04fb2c99-e334-5efe-40e5-8fba96340f74)
            (mode w)
            (dev sda11:disk)
            (backend 0)
            (bootable 0)
        )
    )
    (device
        (console
            (protocol vt100)
            (location 2)
            (uuid 42e6c974-c273-7225-edf3-1812c2410fd1)
        )
    )
    (device
        (pci
            (dev (slot 0x00) (bus 0x04) (domain 0x0000) (func 0x01))
            (uuid e294e348-fc0a-9bf1-fcf9-93f9665505bd)
            (backend 0)
        )
    )

)

Regards,
Jambunathan K.

#2 lore raw
Quoted 6 lines · Jambunathan K

Just to be sure I 'fixed' linux-2.6-xen-sparse/include/asm-x86_64/mach-xen/asm/pci.h and made a clean build from xen source tar. I ensured that BACKEND_PASS is set to yes.

I am using the same vmlinuz both on Dom0 and Dom1. I am seeing that lspci in Dom1 *doesn't* report the exported non-zero function.

Very odd. The tracing you provide clearly shows that the kernel is *not* scanning every fn. It is only scanning every fn==0.

The function of interest here is, I think, linux/drivers/pci/probe.c:pci_scan_slot(). Notice how it iterates on every fn but bails early if no device is found at fn 0 and !scan_all_fns. I suggest you add some tracing to that function to check that:
A. It is being called; and
B. Exactly how it is bailing without checking fns != 0, if it ireally is
the case that scan_all_fns==1.

-- Keir

#3 lore raw
Quoted 10 lines
Quoted 10 lines

Very odd. The tracing you provide clearly shows that the kernel is *not* scanning every fn. It is only scanning every fn==0.

The function of interest here is, I think, linux/drivers/pci/probe.c:pci_scan_slot(). Notice how it iterates on every fn but bails early if no device is found at fn 0 and !scan_all_fns. I suggest you add some tracing to that function to check that:
A. It is being called; and
B. Exactly how it is bailing without checking fns != 0, if it ireally is
the case that scan_all_fns==1.

This is the broad outline of a fix.

--- ws1/xen-3.1.0-src/linux-2.6.18-xen/include/asm-x86_64/mach-xen/asm/pci.h

2007-08-29 07:22:52.000000000 -0400
+++ ws/xen-3.1.0-src/linux-2.6.18-xen/include/asm-x86_64/mach-xen/asm/pci.h
2007-08-30 05:37:46.000000000 -0400

@@ -16,7 +16,9 @@
#else
#define pcibios_assign_all_busses() 0
#endif
+
#define pcibios_scan_all_fns(a, b) 1
+#define HAVE_PCIBIOS_SCAN_ALL_FNS

extern unsigned long pci_mem_start;
#define PCIBIOS_MIN_IO 0x1000
--- ws1/xen-3.1.0-src/linux-2.6.18-xen/include/asm-generic/pci.h 2006-09-19
23:42:06.000000000 -0400
+++ ws/xen-3.1.0-src/linux-2.6.18-xen/include/asm-generic/pci.h 2007-08-30
05:37:03.000000000 -0400
@@ -43,7 +43,11 @@
return root;
}

+
+#ifndef HAVE_PCIBIOS_SCAN_ALL_FNS
+#error "Fix not OK"
#define pcibios_scan_all_fns(a, b) 0
+#endif

#ifndef HAVE_ARCH_PCI_GET_LEGACY_IDE_IRQ
static inline int pci_get_legacy_ide_irq(struct pci_dev *dev, int channel)

Compiler log below justifies the above fix.

In file included from /root/src/ws/xen-3.1.0-src/linux-2.6.18-xen/include/linux/pci.h:691,
from
/root/src/ws/xen-3.1.0-src/linux-2.6.18-xen/arch/x86_64/kernel/../../i386/kernel/pci-dma-xen.c:13:
include2/asm/mach-xen/asm/pci.h:21:2: error: #error "Including this definition"
In file included from include2/asm/mach-xen/asm/pci.h:167,
from
/root/src/ws/xen-3.1.0-src/linux-2.6.18-xen/include/linux/pci.h:691,
from
/root/src/ws/xen-3.1.0-src/linux-2.6.18-xen/arch/x86_64/kernel/../../i386/kernel/pci-dma-xen.c:13:
/root/src/ws/xen-3.1.0-src/linux-2.6.18-xen/include/asm-generic/pci.h:46:1:
warning: "pcibios_scan_all_fns" redefined
In file included from /root/src/ws/xen-3.1.0-src/linux-2.6.18-xen/include/linux/pci.h:691,
from
/root/src/ws/xen-3.1.0-src/linux-2.6.18-xen/arch/x86_64/kernel/../../i386/kernel/pci-dma-xen.c:13:
include2/asm/mach-xen/asm/pci.h:22:1: warning: this is the location of the previous definition

#4 lore raw
Quoted 1 line · Jambunathan K

This is the broad outline of a fix.

Oh, that is pretty gross. I guess we can just comment out asm-generic's definition of that macro, as pretty much every architecture is defining it for itself anyway.

Can you try that? Just have it defined to 1 in asm-x86_64/mach-xen/asm/pci.h, and comment out the definition in asm-generic/pci.h.

If that works I'll apply the fix to our tree with appropriate comments.

This isn't going to fly upstream, or probably even in vendor kernels, so longer term the dummy device in pciback is probably going to be required.

-- Keir

#5 lore raw
Quoted 4 lines
Quoted 4 lines

Oh, that is pretty gross. I guess we can just comment out asm-generic's definition of that macro, as pretty much every architecture is defining it for itself anyway.

Quoted 8 lines
Quoted 8 lines

Can you try that? Just have it defined to 1 in asm-x86_64/mach-xen/asm/pci.h, and comment out the definition in asm-generic/pci.h.

If that works I'll apply the fix to our tree with appropriate comments.

This isn't going to fly upstream, or probably even in vendor kernels, so longer term the dummy device in pciback is probably going to be required.

The changes work well.
Please include these changes in the next stable release of Xen31 tree.

Jambunathan K.

#6 lore raw
In reply to Jambunathan K
Quoted 15 lines · Jambunathan K
Quoted 14 lines · Keir Fraser
Quoted 8 lines

As I worte accidently direct to Keir and not to the list, I face the same problem. I'd like to have option 1, because it worked fine and I don't see a benefit of having a dummy device in the domU.

Dedecating single fnX to a domain is very usefull for example to give the domUs ethernets of a four port card. I'm also running one domU that is only using one of the USB 1.x controllers of a USB PCI addon card.

Okay, if you want to check out the 'fix' to revert behaviour to that of 3.0.4 for yourselves, it is to edit linux/include/asm-i386/mach-xen/asm/pci.h and to change the definition therein of pcibios_scan_all_fns() from 0 to 1.

Quoted 8 lines
Quoted 5 lines

If you are building a 64-bit kernel then of course it is the file in include/asm-x86_64 that you need to edit.

Make that change and rebuild you domU. Additionally, make sure you build dom0 with pciback in passthrough mode. Hopefully your problems will be gone!

I am using x86_64.

Same here.

Quoted 6 lines

Just to be sure I 'fixed' linux-2.6-xen-sparse/include/asm-x86_64/mach-xen/asm/pci.h and made a clean build from xen source tar. I ensured that BACKEND_PASS is set to yes.

I am using the same vmlinuz both on Dom0 and Dom1. I am seeing that lspci in Dom1 *doesn't* report the exported non-zero function.

Same here, furthermore the system was unresponsive to my serial device with the fix applied.

Stefan