All of lore.kernel.org
 help / color / mirror / Atom feed
From: Paul Durrant <Paul.Durrant@citrix.com>
To: "xen-devel@lists.xenproject.org" <xen-devel@lists.xenproject.org>
Cc: Kevin Tian <kevin.tian@intel.com>,
	Stefano Stabellini <sstabellini@kernel.org>,
	Wei Liu <wei.liu2@citrix.com>,
	Andrew Cooper <Andrew.Cooper3@citrix.com>,
	"Tim (Xen.org)" <tim@xen.org>,
	George Dunlap <George.Dunlap@citrix.com>,
	Julien Grall <julien.grall@arm.com>,
	Jan Beulich <jbeulich@suse.com>,
	Ian Jackson <Ian.Jackson@citrix.com>,
	Roger Pau Monne <roger.pau@citrix.com>
Subject: Re: [PATCH 2/4] iommu: generalize iommu_inclusive_mapping
Date: Tue, 31 Jul 2018 07:18:36 +0000	[thread overview]
Message-ID: <49a6cf5a90074f56b4eb691c2bcf7a8a@AMSPEX02CL03.citrite.net> (raw)
In-Reply-To: <20180727153149.25094-3-roger.pau@citrix.com>

> -----Original Message-----
> From: Xen-devel [mailto:xen-devel-bounces@lists.xenproject.org] On Behalf
> Of Roger Pau Monne
> Sent: 27 July 2018 16:32
> To: xen-devel@lists.xenproject.org
> Cc: Kevin Tian <kevin.tian@intel.com>; Stefano Stabellini
> <sstabellini@kernel.org>; Wei Liu <wei.liu2@citrix.com>; George Dunlap
> <George.Dunlap@citrix.com>; Andrew Cooper
> <Andrew.Cooper3@citrix.com>; Ian Jackson <Ian.Jackson@citrix.com>; Tim
> (Xen.org) <tim@xen.org>; Julien Grall <julien.grall@arm.com>; Jan Beulich
> <jbeulich@suse.com>; Roger Pau Monne <roger.pau@citrix.com>
> Subject: [Xen-devel] [PATCH 2/4] iommu: generalize
> iommu_inclusive_mapping
> 
> Introduce a new iommu=inclusive generic option that supersedes
> iommu_inclusive_mapping. This should be a non-functional change on
> Intel hardware, while AMD hardware will gain the same functionality of
> mapping almost everything below the 4GB boundary.
> 
> Note that is a noop for ARM hardware.
> 
> Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
> ---
> Cc: Andrew Cooper <andrew.cooper3@citrix.com>
> Cc: George Dunlap <George.Dunlap@eu.citrix.com>
> Cc: Ian Jackson <ian.jackson@eu.citrix.com>
> Cc: Jan Beulich <jbeulich@suse.com>
> Cc: Julien Grall <julien.grall@arm.com>
> Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
> Cc: Stefano Stabellini <sstabellini@kernel.org>
> Cc: Tim Deegan <tim@xen.org>
> Cc: Wei Liu <wei.liu2@citrix.com>
> Cc: Kevin Tian <kevin.tian@intel.com>
> ---
>  docs/misc/xen-command-line.markdown   | 14 ++++++
>  xen/drivers/passthrough/arm/iommu.c   |  4 ++
>  xen/drivers/passthrough/iommu.c       |  6 +++
>  xen/drivers/passthrough/vtd/extern.h  |  2 -
>  xen/drivers/passthrough/vtd/iommu.c   |  6 ---
>  xen/drivers/passthrough/vtd/x86/vtd.c | 66 +------------------------
>  xen/drivers/passthrough/x86/iommu.c   | 70
> +++++++++++++++++++++++++++
>  xen/include/xen/iommu.h               |  2 +
>  8 files changed, 97 insertions(+), 73 deletions(-)
> 
> diff --git a/docs/misc/xen-command-line.markdown b/docs/misc/xen-
> command-line.markdown
> index 65b4754418..91a8bfc9a6 100644
> --- a/docs/misc/xen-command-line.markdown
> +++ b/docs/misc/xen-command-line.markdown
> @@ -1198,6 +1198,17 @@ detection of systems known to misbehave upon
> accesses to that port.
> 
>  >> Enable IOMMU debugging code (implies `verbose`).
> 
> +> `inclusive`

This is a dom0 (or hwdom) specific setting so perhaps dom0-inclusive?

Actually the dom0 iommu options are starting to get unwieldy as they are conflated with the general host iommu options so I think it may be worthwhile splitting things out into a separate 'dom0-iommu=' top level parameter at this stage. (My reasons are slightly selfish as I intend to add another dom0 iommu option to give it just reserved regions, to avoid unnecessary set-up if we know it will be using PV-IOMMU).

Cheers,

  Paul

> +
> +> Default: `true`
> +
> +>> Use this to work around firmware issues providing incorrect RMRR or
> IVMD
> +>> entries. Rather than only mapping RAM pages for IOMMU accesses for
> Dom0,
> +>> with this option all pages up to 4GB, not marked as unusable in the E820
> +>> table, will get a mapping established. Note that this option is only
> +>> applicable to a PV dom0. Also note that if `dom0-strict` mode is enabled
> +>> then conventional RAM pages not assigned to dom0 will not be mapped.
> +
>  ### iommu\_dev\_iotlb\_timeout
>  > `= <integer>`
> 
> @@ -1212,6 +1223,9 @@ wait descriptor timed out', try increasing this value.
> 
>  > Default: `true`
> 
> +**WARNING: This command line option is deprecated, and superseded by
> +_iommu=inclusive_ - using both options in combination is undefined.**
> +
>  Use this to work around firmware issues providing incorrect RMRR entries.
>  Rather than only mapping RAM pages for IOMMU accesses for Dom0, with
> this
>  option all pages up to 4GB, not marked as unusable in the E820 table, will
> diff --git a/xen/drivers/passthrough/arm/iommu.c
> b/xen/drivers/passthrough/arm/iommu.c
> index 95b1abb972..325997b19f 100644
> --- a/xen/drivers/passthrough/arm/iommu.c
> +++ b/xen/drivers/passthrough/arm/iommu.c
> @@ -73,3 +73,7 @@ int arch_iommu_populate_page_table(struct domain
> *d)
>      /* The IOMMU shares the p2m with the CPU */
>      return -ENOSYS;
>  }
> +
> +void __hwdom_init arch_iommu_hwdom_init(struct domain *d)
> +{
> +}
> diff --git a/xen/drivers/passthrough/iommu.c
> b/xen/drivers/passthrough/iommu.c
> index 70d218f910..3f3aa71b2c 100644
> --- a/xen/drivers/passthrough/iommu.c
> +++ b/xen/drivers/passthrough/iommu.c
> @@ -47,6 +47,9 @@ integer_param("iommu_dev_iotlb_timeout",
> iommu_dev_iotlb_timeout);
>   *   no-igfx                    Disable VT-d for IGD devices (insecure)
>   *   no-amd-iommu-perdev-intremap Don't use per-device interrupt
> remapping
>   *                              tables (insecure)
> + *   inclusive                  Map additional regions into the IOMMU page
> + *                              tables in order to workaround bugs in ACPI
> + *                              tables.
>   */
>  custom_param("iommu", parse_iommu_param);
>  bool_t __initdata iommu_enable = 1;
> @@ -60,6 +63,7 @@ bool_t __read_mostly iommu_passthrough;
>  bool_t __read_mostly iommu_snoop = 1;
>  bool_t __read_mostly iommu_qinval = 1;
>  bool_t __read_mostly iommu_intremap = 1;
> +bool __hwdom_initdata iommu_inclusive = true;
> 
>  /*
>   * In the current implementation of VT-d posted interrupts, in some
> extreme
> @@ -208,6 +212,8 @@ void __hwdom_init iommu_hwdom_init(struct
> domain *d)
>      }
> 
>      hd->platform_ops->hwdom_init(d);
> +
> +    arch_iommu_hwdom_init(d);
>  }
> 
>  void iommu_teardown(struct domain *d)
> diff --git a/xen/drivers/passthrough/vtd/extern.h
> b/xen/drivers/passthrough/vtd/extern.h
> index fb7edfaef9..91cadc602e 100644
> --- a/xen/drivers/passthrough/vtd/extern.h
> +++ b/xen/drivers/passthrough/vtd/extern.h
> @@ -99,6 +99,4 @@ void pci_vtd_quirk(const struct pci_dev *);
>  bool_t platform_supports_intremap(void);
>  bool_t platform_supports_x2apic(void);
> 
> -void vtd_set_hwdom_mapping(struct domain *d);
> -
>  #endif // _VTD_EXTERN_H_
> diff --git a/xen/drivers/passthrough/vtd/iommu.c
> b/xen/drivers/passthrough/vtd/iommu.c
> index 1710256823..569ec4aec2 100644
> --- a/xen/drivers/passthrough/vtd/iommu.c
> +++ b/xen/drivers/passthrough/vtd/iommu.c
> @@ -1304,12 +1304,6 @@ static void __hwdom_init
> intel_iommu_hwdom_init(struct domain *d)
>  {
>      struct acpi_drhd_unit *drhd;
> 
> -    if ( !iommu_passthrough && is_pv_domain(d) )
> -    {
> -        /* Set up 1:1 page table for hardware domain. */
> -        vtd_set_hwdom_mapping(d);
> -    }
> -
>      setup_hwdom_pci_devices(d, setup_hwdom_device);
>      setup_hwdom_rmrr(d);
> 
> diff --git a/xen/drivers/passthrough/vtd/x86/vtd.c
> b/xen/drivers/passthrough/vtd/x86/vtd.c
> index cc2bfea162..55d74a97e2 100644
> --- a/xen/drivers/passthrough/vtd/x86/vtd.c
> +++ b/xen/drivers/passthrough/vtd/x86/vtd.c
> @@ -35,8 +35,7 @@
>   * iommu_inclusive_mapping: when set, all memory below 4GB is included in
> dom0
>   * 1:1 iommu mappings except xen and unusable regions.
>   */
> -static bool_t __hwdom_initdata iommu_inclusive_mapping = 1;
> -boolean_param("iommu_inclusive_mapping", iommu_inclusive_mapping);
> +boolean_param("iommu_inclusive_mapping", iommu_inclusive);
> 
>  void *map_vtd_domain_page(u64 maddr)
>  {
> @@ -108,66 +107,3 @@ void hvm_dpci_isairq_eoi(struct domain *d,
> unsigned int isairq)
>      spin_unlock(&d->event_lock);
>  }
> 
> -void __hwdom_init vtd_set_hwdom_mapping(struct domain *d)
> -{
> -    unsigned long i, j, tmp, top, max_pfn;
> -
> -    BUG_ON(!is_hardware_domain(d));
> -
> -    max_pfn = (GB(4) >> PAGE_SHIFT) - 1;
> -    top = max(max_pdx, pfn_to_pdx(max_pfn) + 1);
> -
> -    for ( i = 0; i < top; i++ )
> -    {
> -        unsigned long pfn = pdx_to_pfn(i);
> -        bool map;
> -        int rc = 0;
> -
> -        /*
> -         * Set up 1:1 mapping for dom0. Default to include only
> -         * conventional RAM areas and let RMRRs include needed reserved
> -         * regions. When set, the inclusive mapping additionally maps in
> -         * every pfn up to 4GB except those that fall in unusable ranges.
> -         */
> -        if ( pfn > max_pfn && !mfn_valid(_mfn(pfn)) )
> -            continue;
> -
> -        if ( iommu_inclusive_mapping && pfn <= max_pfn )
> -            map = !page_is_ram_type(pfn, RAM_TYPE_UNUSABLE);
> -        else
> -            map = page_is_ram_type(pfn, RAM_TYPE_CONVENTIONAL);
> -
> -        if ( !map )
> -            continue;
> -
> -        /* Exclude Xen bits */
> -        if ( xen_in_range(pfn) )
> -            continue;
> -
> -        /*
> -         * If dom0-strict mode is enabled then exclude conventional RAM
> -         * and let the common code map dom0's pages.
> -         */
> -        if ( iommu_dom0_strict &&
> -             page_is_ram_type(pfn, RAM_TYPE_CONVENTIONAL) )
> -            continue;
> -
> -        tmp = 1 << (PAGE_SHIFT - PAGE_SHIFT_4K);
> -        for ( j = 0; j < tmp; j++ )
> -        {
> -            int ret = iommu_map_page(d, pfn * tmp + j, pfn * tmp + j,
> -                                     IOMMUF_readable|IOMMUF_writable);
> -
> -            if ( !rc )
> -               rc = ret;
> -        }
> -
> -        if ( rc )
> -            printk(XENLOG_WARNING VTDPREFIX " d%d: IOMMU mapping failed:
> %d\n",
> -                   d->domain_id, rc);
> -
> -        if (!(i & (0xfffff >> (PAGE_SHIFT - PAGE_SHIFT_4K))))
> -            process_pending_softirqs();
> -    }
> -}
> -
> diff --git a/xen/drivers/passthrough/x86/iommu.c
> b/xen/drivers/passthrough/x86/iommu.c
> index 68182afd91..ba0bbd9a15 100644
> --- a/xen/drivers/passthrough/x86/iommu.c
> +++ b/xen/drivers/passthrough/x86/iommu.c
> @@ -20,6 +20,8 @@
>  #include <xen/softirq.h>
>  #include <xsm/xsm.h>
> 
> +#include <asm/setup.h>
> +
>  void iommu_update_ire_from_apic(
>      unsigned int apic, unsigned int reg, unsigned int value)
>  {
> @@ -132,6 +134,74 @@ void arch_iommu_domain_destroy(struct domain
> *d)
>  {
>  }
> 
> +void __hwdom_init arch_iommu_hwdom_init(struct domain *d)
> +{
> +    unsigned long i, j, tmp, top, max_pfn;
> +
> +    if ( iommu_passthrough || !is_pv_domain(d) )
> +        return;
> +
> +    BUG_ON(!is_hardware_domain(d));
> +
> +    max_pfn = (GB(4) >> PAGE_SHIFT) - 1;
> +    top = max(max_pdx, pfn_to_pdx(max_pfn) + 1);
> +
> +    for ( i = 0; i < top; i++ )
> +    {
> +        unsigned long pfn = pdx_to_pfn(i);
> +        bool map;
> +        int rc = 0;
> +
> +        /*
> +         * Set up 1:1 mapping for dom0. Default to include only
> +         * conventional RAM areas and let RMRRs include needed reserved
> +         * regions. When set, the inclusive mapping additionally maps in
> +         * every pfn up to 4GB except those that fall in unusable ranges.
> +         */
> +        if ( pfn > max_pfn && !mfn_valid(_mfn(pfn)) )
> +            continue;
> +
> +        if ( iommu_inclusive && pfn <= max_pfn )
> +            map = !page_is_ram_type(pfn, RAM_TYPE_UNUSABLE);
> +        else
> +            map = page_is_ram_type(pfn, RAM_TYPE_CONVENTIONAL);
> +
> +        if ( !map )
> +            continue;
> +
> +        /* Exclude Xen bits */
> +        if ( xen_in_range(pfn) )
> +            continue;
> +
> +        /*
> +         * If dom0-strict mode is enabled then exclude conventional RAM
> +         * and let the common code map dom0's pages.
> +         */
> +        if ( iommu_dom0_strict &&
> +             page_is_ram_type(pfn, RAM_TYPE_CONVENTIONAL) )
> +            continue;
> +
> +        tmp = 1 << (PAGE_SHIFT - PAGE_SHIFT_4K);
> +        for ( j = 0; j < tmp; j++ )
> +        {
> +            int ret = iommu_map_page(d, pfn * tmp + j, pfn * tmp + j,
> +                                     IOMMUF_readable|IOMMUF_writable);
> +
> +            if ( !rc )
> +               rc = ret;
> +        }
> +
> +        if ( rc )
> +            printk(XENLOG_WARNING "d%d: IOMMU mapping failed: %d\n",
> +                   d->domain_id, rc);
> +
> +        if (!(i & (0xfffff >> (PAGE_SHIFT - PAGE_SHIFT_4K))))
> +            process_pending_softirqs();
> +    }
> +
> +
> +}
> +
>  /*
>   * Local variables:
>   * mode: C
> diff --git a/xen/include/xen/iommu.h b/xen/include/xen/iommu.h
> index 6b42e3b876..787566a4e7 100644
> --- a/xen/include/xen/iommu.h
> +++ b/xen/include/xen/iommu.h
> @@ -35,6 +35,7 @@ extern bool_t iommu_snoop, iommu_qinval,
> iommu_intremap, iommu_intpost;
>  extern bool_t iommu_hap_pt_share;
>  extern bool_t iommu_debug;
>  extern bool_t amd_iommu_perdev_intremap;
> +extern bool iommu_inclusive;
> 
>  extern unsigned int iommu_dev_iotlb_timeout;
> 
> @@ -49,6 +50,7 @@ void arch_iommu_domain_destroy(struct domain *d);
>  int arch_iommu_domain_init(struct domain *d);
>  int arch_iommu_populate_page_table(struct domain *d);
>  void arch_iommu_check_autotranslated_hwdom(struct domain *d);
> +void arch_iommu_hwdom_init(struct domain *d);
> 
>  int iommu_construct(struct domain *d);
> 
> --
> 2.18.0
> 
> 
> _______________________________________________
> Xen-devel mailing list
> Xen-devel@lists.xenproject.org
> https://lists.xenproject.org/mailman/listinfo/xen-devel
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

  reply	other threads:[~2018-07-31  7:18 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-27 15:31 [PATCH 0/4] x86/iommu: PVH Dom0 workarounds for missing RMRR/IRSV entries Roger Pau Monne
2018-07-27 15:31 ` [PATCH 1/4] iommu: remove unneeded return from iommu_hwdom_init Roger Pau Monne
2018-07-31  7:19   ` Paul Durrant
2018-07-27 15:31 ` [PATCH 2/4] iommu: generalize iommu_inclusive_mapping Roger Pau Monne
2018-07-31  7:18   ` Paul Durrant [this message]
2018-07-31  8:16     ` Roger Pau Monné
2018-07-31  8:27       ` Paul Durrant
2018-07-31  8:33         ` Roger Pau Monné
2018-07-31  8:37           ` Paul Durrant
2018-07-31  8:49             ` Jan Beulich
2018-07-31  9:05               ` Roger Pau Monné
2018-07-31  9:14                 ` Jan Beulich
2018-07-31  9:34                   ` Roger Pau Monné
2018-07-31  9:37                     ` Paul Durrant
2018-07-31  9:41                     ` Jan Beulich
2018-07-31  9:45                       ` Paul Durrant
2018-07-31  8:45         ` Jan Beulich
2018-07-31 14:39   ` Jan Beulich
2018-07-31 15:33     ` Roger Pau Monné
2018-08-01  8:20       ` Jan Beulich
2018-08-01  8:32         ` Andrew Cooper
2018-08-01  9:10           ` Jan Beulich
2018-08-01  9:20             ` Andrew Cooper
2018-08-01  9:59               ` Jan Beulich
2018-08-01 10:25                 ` Andrew Cooper
2018-08-01  8:33         ` Paul Durrant
2018-08-01  9:11           ` Jan Beulich
2018-08-02  6:53           ` Tian, Kevin
2018-08-01  8:47         ` Roger Pau Monné
2018-07-27 15:31 ` [PATCH 3/4] x86/iommu: reorder conditions used in the inclusive iommu mappings Roger Pau Monne
2018-07-31  7:29   ` Paul Durrant
2018-07-31  8:26     ` Roger Pau Monné
2018-07-27 15:31 ` [PATCH 4/4] x86/iommu: add PVH support to the inclusive options Roger Pau Monne
2018-07-31  7:36   ` Paul Durrant
2018-07-31  8:28     ` Roger Pau Monné
2018-07-31 14:52   ` Jan Beulich
2018-07-31 15:15     ` Roger Pau Monné
2018-07-31 15:27       ` Roger Pau Monné
2018-07-31 15:34         ` Jan Beulich
2018-07-31 15:33       ` Jan Beulich

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=49a6cf5a90074f56b4eb691c2bcf7a8a@AMSPEX02CL03.citrite.net \
    --to=paul.durrant@citrix.com \
    --cc=Andrew.Cooper3@citrix.com \
    --cc=George.Dunlap@citrix.com \
    --cc=Ian.Jackson@citrix.com \
    --cc=jbeulich@suse.com \
    --cc=julien.grall@arm.com \
    --cc=kevin.tian@intel.com \
    --cc=roger.pau@citrix.com \
    --cc=sstabellini@kernel.org \
    --cc=tim@xen.org \
    --cc=wei.liu2@citrix.com \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.