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

Re: [RFC] xen/arm: introduce XENFEAT_ARM_dom0_iommu


  • To: Stefano Stabellini <sstabellini@xxxxxxxxxx>
  • From: Bertrand Marquis <Bertrand.Marquis@xxxxxxx>
  • Date: Wed, 17 Feb 2021 15:34:03 +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=+FFOxwcZQWPFVOqUytxRxL4okfTTAXoZjcIiUuYeV6M=; b=ZzcT2IA58AMH5cFT93ylLbI61+I+WrgqiXnFjIpE6k3Y7TRmZH1zJac0LXuxdx7KUIzigY/ONCGfAf+Ip4hTGo2HsCyb3i5DYXSM9QIGewRSRMy3gik6t2FyVFeCS2RAmgp5ViyGwSbS7+xTXhLoyX2wM732uXatn+f6JmQK3gWNQqsadwzEnUPmjzSlLqFdMedI1vYCzAX3qxV7FKKKRbJG2JWaee2wvOHaAHv4Rb8MyJ8y8za1LW8ab4p6jWY6veS58+iM6EKsGb1gjkEym6Bhyy1L1dQ0OmXCQ1rapUDFf57sWC0QHkaL6KTa1hoyY5fKzt1IvYnz9NLapWqH1w==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cITNV7LyOe7PKrfxu3okr3WWp3/0mIHf4VUwMy/b4D1a07y6JoiGcYpsb9EaPnu44PvLKXnZaksqGVOGdVMtSJUnKArVJyzpIFTEhYZx7nNzCpz+d19Ar8kobyuJcMhUNGB/I6VvAsk66+PdURhRn1GozqBIFAuCE1boWdVLc3CPe5ZY9c0TV6ZnOLuneASR6gQLiNRXz8ZeK1L30q/cHNF12+OKoKHF9GuY20o6IfwOMD3VcXYJSuFmlIHuSwfYumq67LGDPNW6ykqd4OMXucznbPd9thglhfJ5unalCRH2/gPt+6591uRlejantn3ztyMbJoFisk3WKlGPB1A1vg==
  • Authentication-results-original: kernel.org; dkim=none (message not signed) header.d=none;kernel.org; dmarc=none action=none header.from=arm.com;
  • Cc: Julien Grall <julien@xxxxxxx>, "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>, "Volodymyr_Babchuk@xxxxxxxx" <Volodymyr_Babchuk@xxxxxxxx>, Rahul Singh <Rahul.Singh@xxxxxxx>
  • Delivery-date: Wed, 17 Feb 2021 15:34:56 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Nodisclaimer: true
  • Original-authentication-results: kernel.org; dkim=none (message not signed) header.d=none;kernel.org; dmarc=none action=none header.from=arm.com;
  • Thread-index: AQHXBNDUDoMffJM9X0qFA5iW4kfZOqpcev+A
  • Thread-topic: [RFC] xen/arm: introduce XENFEAT_ARM_dom0_iommu

Hi Stefano,

> On 17 Feb 2021, at 02:00, Stefano Stabellini <sstabellini@xxxxxxxxxx> 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.

Wouldn’t it be easier to name the flag XENFEAT_ARM_swiotlb_needed ?

> 
> 
> 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. 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.

Would it be realistic to say that cache coloring cannot be used without an 
IOMMU ?

Having a flag for the swiotlb is a good idea because in the current status the 
switch
to use or not swiotlb is more or less implicit. 
But somehow there are use cases where we should simply say “not supported” as
we do for example for passthrough right now. Maybe cache coloring is a case like
that.

> 
> 
> 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).

Any system where you have an IOMMU but not covering all devices is
almost impossible to magically handle smoothly and will require some
carefull configuration. Sadly as you stated, we do not have a way to
auto-detect such a case.

> 
> 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.
> 
> 
> 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.
> 
> See appended patch as a reference.

I really think the naming of the flag will need to be modified.

Cheers
Bertrand

> 
> 
> Cheers,
> 
> Stefano
> 
> 
> diff --git a/xen/common/kernel.c b/xen/common/kernel.c
> index 7a345ae45e..4dbef48199 100644
> --- a/xen/common/kernel.c
> +++ b/xen/common/kernel.c
> @@ -16,6 +16,7 @@
> #include <xen/hypfs.h>
> #include <xsm/xsm.h>
> #include <asm/current.h>
> +#include <asm/platform.h>
> #include <public/version.h>
> 
> #ifndef COMPAT
> @@ -549,6 +550,9 @@ DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
>                 fi.submap |= 1U << XENFEAT_dom0;
> #ifdef CONFIG_ARM
>             fi.submap |= (1U << XENFEAT_ARM_SMCCC_supported);
> +            if ( !platform_has_quirk(PLATFORM_QUIRK_DOM0_IOMMU) &&
> +                 is_hardware_domain(d) && is_iommu_enabled(d) )
> +                fi.submap |= (1U << XENFEAT_ARM_dom0_iommu);
> #endif
> #ifdef CONFIG_X86
>             if ( is_pv_domain(d) )
> diff --git a/xen/include/asm-arm/platform.h b/xen/include/asm-arm/platform.h
> index 997eb25216..094a76d677 100644
> --- a/xen/include/asm-arm/platform.h
> +++ b/xen/include/asm-arm/platform.h
> @@ -48,6 +48,11 @@ struct platform_desc {
>  * stride.
>  */
> #define PLATFORM_QUIRK_GIC_64K_STRIDE (1 << 0)
> +/*
> + * Quirk for platforms where the IOMMU is present but doesn't protect
> + * all DMA-capable devices.
> + */
> +#define PLATFORM_QUIRK_DOM0_IOMMU (1 << 1)
> 
> void platform_init(void);
> int platform_init_time(void);
> diff --git a/xen/include/asm-x86/platform.h b/xen/include/asm-x86/platform.h
> new file mode 100644
> index 0000000000..5427e8b851
> --- /dev/null
> +++ b/xen/include/asm-x86/platform.h
> @@ -0,0 +1,13 @@
> +#ifndef __ASM_X86_PLATFORM_H
> +#define __ASM_X86_PLATFORM_H
> +
> +#endif /* __ASM_X86_PLATFORM_H */
> +
> +/*
> + * Local variables:
> + * mode: C
> + * c-file-style: "BSD"
> + * c-basic-offset: 4
> + * indent-tabs-mode: nil
> + * End:
> + */
> diff --git a/xen/include/public/features.h b/xen/include/public/features.h
> index 1613b2aab8..adaa2a995d 100644
> --- a/xen/include/public/features.h
> +++ b/xen/include/public/features.h
> @@ -114,6 +114,11 @@
>  */
> #define XENFEAT_linux_rsdp_unrestricted   15
> 
> +/*
> + * arm: dom0 is started with IOMMU protection.
> + */
> +#define XENFEAT_ARM_dom0_iommu            16
> +
> #define XENFEAT_NR_SUBMAPS 1
> 
> #endif /* __XEN_PUBLIC_FEATURES_H__ */


 


Rackspace

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