 
	
| [Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [Xen-devel] [early RFC] ARM PCI Passthrough design document
 Hi Roger, On 06/01/17 15:12, Roger Pau Monné wrote: On Thu, Dec 29, 2016 at 02:04:15PM +0000, Julien Grall wrote: The number is chosen by the software. In the case of ACPI, it is "hardcoded" in the MCFG table, but for Device Tree this number could be chosen by the OS unless the property "linux,pci-domain" is present. So given a specific SBDF, it would be possible to find the host bridge and the RID associated to a PCI device. # Interaction of the PCI subsystem with other subsystems In order to have a PCI device fully working, Xen will need to configure other subsystems subsytems such as the SMMU and the Interrupt Controller. By "other" I meant "IOMMU and Interrupt Controller". Would the wording "and the other subsystems" be better? 
 I am planning to details the root complex emulation in a separate section. I sent the design document before writing it. In brief, I would expect the registration of a new bridge to setup the trap to emulation access to the PCI configuration space. On ARM, the first approach will rely on the OS to setup the BARs and ROMs. So they will be mapped by the PCI configuration space emulation. The reason on relying on the OS to setup the BARs/ROMs reducing the work to do for a first version. Otherwise we would have to add code in the toolstack to decide where to place the BARs/ROMs. I don't think it is a lot of work, but it is not that important because it does not require a stable ABI (this is an interaction between the hypervisor and the toolstack). Furthermore, Linux (at least on ARM) is assigning the BARs at the setup. From my understanding, this is the expected behavior with both DT (the DT has a property to skip the scan) and ACPI. The following subsections will briefly describe the interaction from an higher level perspective. Implementation details (callback, structure...) is out of scope. ## SMMU The SMMU will be used to isolate the PCI device when accessing the memory (for instance DMA and MSI Doorbells). Often the SMMU will be configured using a StreamID (SID) that can be deduced from the RID with the help of the firmware tables (see below). Whilst in theory all the memory transaction issued by a PCI device should go through the SMMU, on certain platforms some of the memory transaction may not reach the SMMU because they are interpreted by the host bridge. For instance this could happen if the MSI doorbell is built into the PCI hostI would elaborate on what is a MSI doorbell. I can add an explanation in the glossary. bridge. See [6] for more details. XXX: I think this could be solved by using the host memory layout when creating a guest with PCI devices => Detail it.I'm not really sure I follow here, but if this write to the MSI doorbell doesn't go through the SMMU, and instead is handled by the bridge, isn't there a chance that a gust might be able to write anywhere in physical memory? The problem is more subtle. On some platform the MSI doorbell is built-in the host bridge. Some of those host bridges will intercept any access to this doorbell coming from the PCI devices and interpret it directly rather than going through the SMMU. This mean that the physical address of the MSI doorbell is always be interpreted. Even if the guest is using a intermediate address, this will be considered as a physical address because the SMMU has been by-passed. Furthermore, some platform may have other set of address not going through the SMMU (such as P2P traffic). So we have to prevent mapping anything on those regions. Or this only happens when a guest writes to a MSI doorbell that's trapped by the bridge and not forwarded anywhere else? See above. ## Interrupt controller PCI supports three kind of interrupts: legacy interrupt, MSI and MSI-X. On ARM legacy interrupts will be mapped to SPIs. MSI and MSI-x will be either mapped to SPIs or LPIs. Whilst SPIs can be programmed using an interrupt number, LPIs can be identified via a pair (DeviceID, EventID) when configure through the ITS. All the host bridges will be described in ASL. Only the one available at boot will be described in the MCFG. So it looks more sensible to rely on the ASL from Linux POV. 
 I am not expecting to emulate the configuration space access for DOM0. I know you mentioned that it would be necessary to hide PCI used by Xen (such as the UART) to DOM0 or configuring MSI. But for ARM, the UART is integrated in the SOC and MSI will be configured through the interrupt controller. The former is straight forward to solve, the latter will require more thought. Instantiation of a specific driver for the host controller can be easily done if Xen has the information to detect it. However, those drivers may require resources described in ASL (see [4] for instance). XXX: Need more investigation to know whether the missing information should be passed by DOM0 or hardcoded in the driver.... or poke the ThunderX guys with a pointy stick until they get their act together. I would love to do that, but platform is already out. So I am afraid that we have to deal with that. Although I am hoping *fingers crossed* that future platform will be fully ECAM compliant. 
 I am not the one who decided the name of those properties. This is from the existing binding in Linux (I though it was obvious with the link [8] to the binding). Usually any property that are added by the Linux community (i.e not part of the Open Firmware standards) will be prefixed by "linux,". So I would rather avoid to The lack of bus-ranges is not an issue because it has been formalized in the binding: "If absent, defaults to <0 255> (i.e all buses)". ### Finding the StreamID and DeviceID ### StreamID The first binding existing (see [9]) for SMMU didn't have a way to describe the relationship between RID and StreamID, it was assumed that StreamID == RequesterID. This bindins has now been deprecated in favor of a generic binding (see [10]) which will use the property "iommu-map" to describe the relationship between an RID, the associated IOMMU and the StreamID. ### DeviceID The relationship between the RID and the DeviceID can be found using the property "msi-map" (see [11]). # Discovering PCI devices Whilst PCI devices are currently available in DOM0, the hypervisor does not have any knowledge of them. The first step of supporting PCI passthrough is to make Xen aware of the PCI devices. Xen will require access to the PCI configuration space to retrieve information for the PCI devices or access it on behalf of the guest via the emulatedI know this is not the intention, but the above sentence makes it look like Xen is using an emulated host bridge IMHO (although I'm not a native speaker anyway, so I can be wrong). How about "Xen will require access to the host PCI configuration space..."? host bridge. ## Discovering and register hostbridge Both ACPI and Device Tree do not provide enough information to fully instantiate an host bridge driver. In the case of ACPI, some data may come from ASL, whilst for Device Tree the segment number is not available.For device-tree can't you just add a pci-domain to each bridge device on the DT if none is specified? The "linux,pci-domain" is a Linux specific property. We've been avoided to re-use linux specific property recently (see the case of xen,uefi-*). So we would have to introduce a new one. For ACPI I understand that it's harder. Maybe ARM can somehow assure that MCFG tables completely describe the system, so that you don't need this anymore. This is not ARM but the spec. The PCI spec specifies that MCFG will only describe host bridges available at boot. The rest will be in ASL. 
 The cfg_size is here to help us to match the corresponding node in the device tree. The cfg_size may differ depending on how the hardware has implemented the access to the configuration space. But to be fair, I think we can deal without this property. For ACPI, the size will vary following the number of bus handled and can be deduced. For DT, the base address and bus range should be enough to find the associated node. If that field is removed you could use the PHYSDEVOP_pci_mmcfg_reserved hypercalls.DOM0 will issue the hypercall PHYSDEVOP_pci_host_bridge_add for each host bridge available on the platform. When Xen is receiving the hypercall, the the driver associated to the host bridge will be instantiated. XXX: Shall we limit DOM0 the access to the configuration space from that moment?Most definitely yes, you should instantiate an emulated bridge over the real one, in order to proxy Dom0 accesses to the PCI configuration space. You for example don't want Dom0 moving the position of the BARs of PCI devices without Xen being aware (and properly changing the second stage translation). The problem is on ARM we don't have a single way to access the configuration space. So we would need different emulator in Xen, which I don't like unless there is a strong reason to do it. We could avoid DOM0s to modify the position of the BARs after setup. I also remembered you mention about MSI configuration, for ARM this is done via the interrupt controller. ## Discovering and register PCI Similarly to x86, PCI devices will be discovered by DOM0 and register using the hypercalls PHYSDEVOP_pci_add_device or PHYSDEVOP_manage_pci_add_ext.Why do you need this? If you have access to the bridges you can scan them from Xen and discover the devices AFAICT. I am a bit confused. Are you saying that you plan to ditch them for PVH? If so, why are they called by Linux today? By default all the PCI devices will be assigned to DOM0. So Xen would have to configure the SMMU and Interrupt Controller to allow DOM0 to use the PCI devices. As mentioned earlier, those subsystems will require the StreamID and DeviceID. Both can be deduced from the RID. XXX: How to hide PCI devices from DOM0?By adding the ACPI namespace of the device to the STAO and blocking Dom0 access to this device in the emulated bridge that Dom0 will have access to (returning 0xFFFF when Dom0 tries to read the vendor ID from the PCI header). Sorry I was not clear here. By hiding, I meant DOM0 not instantiating a driver (similarly to xen-pciback.hide). We still want DOM0 to access the PCI config space in order to reset the device. Unless you plan to import all the reset quirks in Xen? Cheers, -- Julien Grall _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxx https://lists.xen.org/xen-devel 
 
 
 | 
|  | Lists.xenproject.org is hosted with RackSpace, monitoring our |