[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [RFC] xen/arm: introduce XENFEAT_ARM_dom0_iommu

  • To: Julien Grall <julien@xxxxxxx>
  • From: Bertrand Marquis <Bertrand.Marquis@xxxxxxx>
  • Date: Wed, 17 Feb 2021 15:37:53 +0000
  • Accept-language: en-GB, en-US
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=N9z5DojfRds/MZyMmVcgqQxaHneUZe/0lwMvjpw8rlo=; b=K96aGYuJSVaKAE0OmEgLJgVqua0JxsOJJ/oRe7O2nh8DieLquBHb2EHGYivVyn3zN++tvu4HbU0ty2QRlzoh/+iE5ReG5QUtWm36Hbl4Hx3NfZrMu/1PsO/Y1Ig7H1kdJ63ZWTtFV7fKLQKbNfZkInitwOHaPzaMydFCcJhRySQia7ZRc2RN1p9wHhekD03yCz6yhjv63Dcd2pR8DOQIzn7NGQy1HuAKvw9l+m8biCJxmjDExHt+SpbxIGlht1kfHEkRJLr1sQ4uaIikrJZDEYzhfaMQmQx4PstMybTYi3yHN49XEEnlze0NeK7nUvvFfYnSnPqjJE2HO5tAJmaPPw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=g+AU3WQZN4708/B7WWGopUp9Kk4tXntb5D0LtGzTQ9U1ds6tZZFso5Q84zHxC81N348cwwBJKxz6Ct9BxFggkkHZpzYq36Gi5mBYz8EiWja3f0LwFglKikEkro/4RWzL88gDRztY+xI0daH+0Jvi5LTp+AxBUhNEw52Q68c8VEKzMDEuw5iRRRJASTL+shTUaFXSSrzwqD52tbSp+gybkhVc483SYGk828iLPduDbgASnkA9P4Dg9UoKhuoCjTNXA0YLpiMG3qHdmxZhNhPMXsdlzWdCMiS5ncaUMjE6MAxuw8S2CpBT/oQALAq0l91C+igkKO4AIiAJN6NvdrKN8Q==
  • Authentication-results-original: xen.org; dkim=none (message not signed) header.d=none;xen.org; dmarc=none action=none header.from=arm.com;
  • Cc: Stefano Stabellini <sstabellini@xxxxxxxxxx>, "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>, "Volodymyr_Babchuk@xxxxxxxx" <Volodymyr_Babchuk@xxxxxxxx>, Rahul Singh <Rahul.Singh@xxxxxxx>
  • Delivery-date: Wed, 17 Feb 2021 15:38:20 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Nodisclaimer: true
  • Original-authentication-results: xen.org; dkim=none (message not signed) header.d=none;xen.org; dmarc=none action=none header.from=arm.com;
  • Thread-index: AQHXBNDUDoMffJM9X0qFA5iW4kfZOqpcCj0AgABx1gA=
  • Thread-topic: [RFC] xen/arm: introduce XENFEAT_ARM_dom0_iommu

Hi Julien,

> On 17 Feb 2021, at 08:50, Julien Grall <julien@xxxxxxx> wrote:
> On 17/02/2021 02:00, Stefano Stabellini wrote:
>> Hi all,
>> Today Linux uses the swiotlb-xen driver (drivers/xen/swiotlb-xen.c) to
>> translate addresses for DMA operations in Dom0. Specifically,
>> swiotlb-xen is used to translate the address of a foreign page (a page
>> belonging to a domU) mapped into Dom0 before using it for DMA.
>> This is important because although Dom0 is 1:1 mapped, DomUs are not. On
>> systems without an IOMMU swiotlb-xen enables PV drivers to work as long
>> as the backends are in Dom0. Thanks to swiotlb-xen, the DMA operation
>> ends up using the MFN, rather than the GFN.
>> On systems with an IOMMU, this is not necessary: when a foreign page is
>> mapped in Dom0, it is added to the Dom0 p2m. A new GFN->MFN translation
>> is enstablished for both MMU and SMMU. Dom0 could safely use the GFN
>> address (instead of the MFN) for DMA operations and they would work. It
>> would be more efficient than using swiotlb-xen.
>> If you recall my presentation from Xen Summit 2020, Xilinx is working on
>> cache coloring. With cache coloring, no domain is 1:1 mapped, not even
>> Dom0. In a scenario where Dom0 is not 1:1 mapped, swiotlb-xen does not
>> work as intended.
>> The suggested solution for both these issues is to add a new feature
>> flag "XENFEAT_ARM_dom0_iommu" that tells Dom0 that it is safe not to use
>> swiotlb-xen because IOMMU translations are available for Dom0. If
>> XENFEAT_ARM_dom0_iommu is set, Linux should skip the swiotlb-xen
>> initialization. I have tested this scheme with and without cache
>> coloring (hence with and without 1:1 mapping of Dom0) on ZCU102 and it
>> works as expected: DMA operations succeed.
>> What about systems where an IOMMU is present but not all devices are
>> protected?
>> There is no way for Xen to know which devices are protected and which
>> ones are not: devices that do not have the "iommus" property could or
>> could not be DMA masters.
>> Perhaps Xen could populate a whitelist of devices protected by the IOMMU
>> based on the "iommus" property. It would require some added complexity
>> in Xen and especially in the swiotlb-xen driver in Linux to use it,
>> which is not ideal.
> You are trading a bit more complexity in Xen and Linux with a user will may 
> not be able to use the hypervisor on his/her platform without a quirk in Xen 
> (see more below).
>> However, this approach would not work for cache
>> coloring where dom0 is not 1:1 mapped so the swiotlb-xen should not be
>> used either way
> Not all the Dom0 Linux kernel will be able to work with cache colouring. So 
> you will need a way for the kernel to say "Hey I am can avoid using swiotlb".

I fully agree and from my current understanding the condition is “having an 

>> For these reasons, I would like to propose a single flag
>> XENFEAT_ARM_dom0_iommu which says that the IOMMU can be relied upon for
>> DMA translations. In situations where a DMA master is not SMMU
>> protected, XENFEAT_ARM_dom0_iommu should not be set. For example, on a
>> platform where an IOMMU is present and protects most DMA masters but it
>> is leaving out the MMC controller, then XENFEAT_ARM_dom0_iommu should
>> not be set (because PV block is not going to work without swiotlb-xen.)
>> This also means that cache coloring won't be usable on such a system (at
>> least not usable with the MMC controller so the system integrator should
>> pay special care to setup the system).
>> It is worth noting that if we wanted to extend the interface to add a
>> list of protected devices in the future, it would still be possible. It
>> would be compatible with XENFEAT_ARM_dom0_iommu.
> I imagine by compatible, you mean XENFEAT_ARM_dom0_iommu would be cleared and 
> instead the device-tree list would be used. Is that correct?

What do you mean by device tree list here ?

>> How to set XENFEAT_ARM_dom0_iommu?
>> We could set XENFEAT_ARM_dom0_iommu automatically when
>> is_iommu_enabled(d) for Dom0. We could also have a platform specific
>> (xen/arch/arm/platforms/) override so that a specific platform can
>> disable XENFEAT_ARM_dom0_iommu. For debugging purposes and advanced
>> users, it would also be useful to be able to override it via a Xen
>> command line parameter.
> Platform quirks should be are limited to a small set of platforms.
> In this case, this would not be only per-platform but also per-firmware table 
> as a developer can decide to remove/add IOMMU nodes in the DT at any time.
> In addition to that, it means we are introducing a regression for those users 
> as Xen 4.14 would have worked on there platform but not anymore. They would 
> need to go through all the nodes and find out which one is not protected.

I am not sure i understand your point here as we cannot detect if a device is 
protected or not by an IOMMU as we do not know which device requires one.
Could you explain what use case working before would not work here ?

> This is a bit of a daunting task and we are going to end up having a lot of 
> per-platform quirk in Xen.

From my understanding the quirks here would be in Linux as it would have to 
decide for what to use swiotlb or not.
What quirk do you imagine we could implement in Xen ?


> So this approach selecting the flag is a no-go for me. FAOD, the inverted 
> idea (i.e. only setting XENFEAT_ARM_dom0_iommu per-platform) is a no go as 
> well.
> I don't have a good idea how to set the flag automatically. My requirement is 
> newer Xen should continue to work on all supported platforms without any 
> additional per-platform effort.
> Cheers,
> -- 
> Julien Grall



Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.