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

RE: [PATCH v4 14/24] xen/domctl: wrap pci-subset iommu-related domctl op with CONFIG_MGMT_HYPERCALLS


  • To: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>, Jan Beulich <jbeulich@xxxxxxxx>, "Garcia Vallejo, Alejandro" <Alejandro.GarciaVallejo@xxxxxxx>, "Stabellini, Stefano" <stefano.stabellini@xxxxxxx>
  • From: "Penny, Zheng" <penny.zheng@xxxxxxx>
  • Date: Wed, 4 Feb 2026 07:50:35 +0000
  • Accept-language: en-US
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=z/DaDuW9xn5BQkXZOqtpozaSlTtRhFTkrJ6t6ZCV/b0=; b=LbffrGlyoQUcxrL3knmV8cs/BeYwgKkrMJ2i1539rDk30ALt3G494yhKqoOA85e5Uxi+835aowBOGPHLylwYqlvAfJdO3oSXiXWflhCqy28rhfD8MRQrYrdhLxQisj/6cpUr0zMlYuVHcnSwKRaab82OL96jiNaCGm8aNQU0vqqPpVbk7a6eHCeC/K2mLWcBbrLT2GT/Jg3UWRqjpaR6J5LLXNZRVB0JZQk4Uc7thGHW8UCiXFyI3dxjXK0bJVoZwACBxfD3+VFl+RC57rEytabaBdyb4YE10najqI1HX/+5F3PZA/y3BPYhdVq6toXTjNfbVtcvpeCBwMh/ZWDKYw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=xffjuuLZDBThTEhPjOirc9bOTQjsEH7/3jxBsdqRClhKpNaQyONbEFHTqxnhtYj6PIsiQyFfeMuwx6+o7D9dcppRv1jPZTibycmQd42zoHJwWs66e6QaZWu93j7OElUTVmoIK4j27hW0Qzn1Vlz1S0XNxH7P2paM96b77mb5EOKnZ65cq5x01obH2i1wfyS4sGYN0wJC4l5gv9WrVeNyYIZ+tVqlh4md8HXfl2lITTCvdO1FZtbAyw/9IQka3HDAfhWGR1hpIvNis+5W+oIPpcJ6lJLYaL4+NhFqfqRcGk1Rlq+3WJjG42Mj8NHfMo6CL+XylSpU7PLNXFrY7K8P9w==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=amd.com;
  • Cc: "Huang, Ray" <Ray.Huang@xxxxxxx>, "grygorii_strashko@xxxxxxxx" <grygorii_strashko@xxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>, "Andryuk, Jason" <Jason.Andryuk@xxxxxxx>, "Daniel P. Smith" <dpsmith@xxxxxxxxxxxxxxxxxxxx>
  • Delivery-date: Wed, 04 Feb 2026 07:50:55 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Msip_labels: MSIP_Label_f265efc6-e181-49d6-80f4-fae95cf838a0_Enabled=True;MSIP_Label_f265efc6-e181-49d6-80f4-fae95cf838a0_SiteId=3dd8961f-e488-4e60-8e11-a82d994e183d;MSIP_Label_f265efc6-e181-49d6-80f4-fae95cf838a0_SetDate=2026-02-04T07:50:25.0000000Z;MSIP_Label_f265efc6-e181-49d6-80f4-fae95cf838a0_Name=Open Source;MSIP_Label_f265efc6-e181-49d6-80f4-fae95cf838a0_ContentBits=3;MSIP_Label_f265efc6-e181-49d6-80f4-fae95cf838a0_Method=Privileged
  • Thread-index: AQHcWtXdwWaFTRetvk29bNPbH/CVXLVylQnw
  • Thread-topic: [PATCH v4 14/24] xen/domctl: wrap pci-subset iommu-related domctl op with CONFIG_MGMT_HYPERCALLS

[Public]

> -----Original Message-----
> From: Penny, Zheng <penny.zheng@xxxxxxx>
> Sent: Friday, November 21, 2025 6:58 PM
> To: xen-devel@xxxxxxxxxxxxxxxxxxxx
> Cc: Huang, Ray <Ray.Huang@xxxxxxx>; grygorii_strashko@xxxxxxxx; Penny,
> Zheng <penny.zheng@xxxxxxx>; Jan Beulich <jbeulich@xxxxxxxx>; Andrew
> Cooper <andrew.cooper3@xxxxxxxxxx>; Roger Pau Monné <roger.pau@xxxxxxxxxx>;
> Andryuk, Jason <Jason.Andryuk@xxxxxxx>; Daniel P. Smith
> <dpsmith@xxxxxxxxxxxxxxxxxxxx>
> Subject: [PATCH v4 14/24] xen/domctl: wrap pci-subset iommu-related domctl op
> with CONFIG_MGMT_HYPERCALLS
>
> Function iommu_do_pci_domctl() is the main entry for pci-subset iommu-related
> domctl-op, and shall be wrapped with CONFIG_MGMT_HYPERCALLS.
> Tracking its calling chain, the following functions shall all be wrapped with
> CONFIG_MGMT_HYPERCALLS:
> - iommu_do_pci_domctl
>   - iommu_get_device_group
>     - xsm_get_device_group
>     - iommu_ops.get_device_group_id
>       - amd_iommu_group_id/intel_iommu_group_id
>   - device_assigned
>   - xsm_assign_device
>   - assign_device
>     - iommu_ops.assign_device
>       - intel_iommu_assign_device/amd_iommu_assign_device
>   - xsm_deassign_device
>   - deassign_device
>     - iommu_ops.reassign_device
>       - reassign_device_ownership/reassign_device
> Otherwise all the functions will become unreachable when
> MGMT_HYPERCALLS=n, and hence violating Misra rule 2.1
>
> Signed-off-by: Penny Zheng <Penny.Zheng@xxxxxxx>
> ---
> v1 -> v2:
> - adapt to changes of "unify DOMCTL to MGMT_HYPERCALLS"
> - wrap XEN_DOMCTL_assign_device{test_assign_device,deassign_device,
>  get_device_group}-case transiently
> ---
> v2 -> v3:
> - make PCI_PASSTHROUGH(, then HAS_VPCI_GUEST_SUPPORT) depend on
> MGMT_HYPERCALLS
> - add wrapping for
> iommu_remove_dt_device/iommu_dt_device_is_assigned_locked/
> arm_smmu_detach_dev/arm_smmu_domain_remove_master
> - fold commit
> "xen/xsm: wrap xsm-iommu-related functions with
> CONFIG_MGMT_HYPERCALLS" in
> - fix overly long #ifdef
> - add missing wrapping in xsm/dummy.h
> - address "violating Misra rule 2.1" in commit message
> - remove transient wrapping of
> XEN_DOMCTL_assign_device{test_assign_device,deassign_device,get_device_gr
> oup}-case
> ---
> v3 -> v4:
> - move codes to wrap with a single #ifdef
> - split into PCI related subset and DT subset
> ---
>  xen/drivers/passthrough/amd/pci_amd_iommu.c | 20 ++++----
>  xen/drivers/passthrough/pci.c               | 52 +++++++++++----------
>  xen/drivers/passthrough/vtd/iommu.c         |  6 ++-
>  xen/include/xsm/dummy.h                     |  6 ++-
>  xen/include/xsm/xsm.h                       | 12 +++--
>  xen/xsm/dummy.c                             |  6 ++-
>  xen/xsm/flask/hooks.c                       | 12 +++--
>  7 files changed, 68 insertions(+), 46 deletions(-)
>
> diff --git a/xen/drivers/passthrough/amd/pci_amd_iommu.c
> b/xen/drivers/passthrough/amd/pci_amd_iommu.c
> index 3a14770855..576b36af92 100644
> --- a/xen/drivers/passthrough/amd/pci_amd_iommu.c
> +++ b/xen/drivers/passthrough/amd/pci_amd_iommu.c
> @@ -461,6 +461,7 @@ static void amd_iommu_disable_domain_device(const
> struct domain *domain,
>          spin_unlock_irqrestore(&iommu->lock, flags);  }
>
> +#ifdef CONFIG_MGMT_HYPERCALLS
>  static int cf_check reassign_device(
>      struct domain *source, struct domain *target, u8 devfn,
>      struct pci_dev *pdev)
> @@ -551,6 +552,14 @@ static int cf_check amd_iommu_assign_device(
>      return rc;
>  }
>
> +static int cf_check amd_iommu_group_id(u16 seg, u8 bus, u8 devfn) {
> +    unsigned int bdf = PCI_BDF(bus, devfn);
> +
> +    return (bdf < ivrs_bdf_entries) ? get_dma_requestor_id(seg, bdf) :
> +bdf; } #endif /* CONFIG_MGMT_HYPERCALLS */
> +
>  static void cf_check amd_iommu_clear_root_pgtable(struct domain *d)  {
>      struct domain_iommu *hd = dom_iommu(d); @@ -698,13 +707,6 @@ static int
> cf_check amd_iommu_remove_device(u8 devfn, struct pci_dev *pdev)
>      return 0;
>  }
>
> -static int cf_check amd_iommu_group_id(u16 seg, u8 bus, u8 devfn) -{
> -    unsigned int bdf = PCI_BDF(bus, devfn);
> -
> -    return (bdf < ivrs_bdf_entries) ? get_dma_requestor_id(seg, bdf) : bdf;
> -}
> -
>  #include <asm/io_apic.h>
>
>  static void amd_dump_page_table_level(struct page_info *pg, int level, @@ -
> 772,14 +774,16 @@ static const struct iommu_ops __initconst_cf_clobber
> _iommu_ops = {
>      .quarantine_init = amd_iommu_quarantine_init,
>      .add_device = amd_iommu_add_device,
>      .remove_device = amd_iommu_remove_device,
> -    .assign_device  = amd_iommu_assign_device,
>      .teardown = amd_iommu_domain_destroy,
>      .clear_root_pgtable = amd_iommu_clear_root_pgtable,
>      .map_page = amd_iommu_map_page,
>      .unmap_page = amd_iommu_unmap_page,
>      .iotlb_flush = amd_iommu_flush_iotlb_pages,
> +#ifdef CONFIG_MGMT_HYPERCALLS
> +    .assign_device  = amd_iommu_assign_device,
>      .reassign_device = reassign_device,
>      .get_device_group_id = amd_iommu_group_id,
> +#endif

FWIS, Alejandro has come up a more clever way to DCE these kinds of op, staying 
conditionally as callback. Here, I just took this commit as example to show the 
methodology:
```
         .assign_device  = IS_ENABLED(CONFIG_MGMT_HYPERCALLS)
                                        ? amd_iommu_assign_device
                                        : NULL,
```
The compiler has enough visibility to know that 
static(amd_iommu_assign_device()) is used, and is droppable when 
MGMT_HYPERCALLS=n. So there is no need to do ifdef-wrapping around these 
statics now. Later when jason's "--gc-section" patch serie in,  --gc-section 
will help linker identify them unused when MGMT_HYPERCALLS=n, then remove them 
automatically.

If we all agreed to use above methodology to do DCE.
Alejandro also recommended that since we will do this assignments in enough 
places in this patch serie, we probably want something like MAYBE_OP() 
somewhere in xen/macros.h:

#define MAYBE_OP(c, fn) (IS_ENABLED(c) ? fn : NULL)

I'd like to listen from your opinions on whether I shall do such update for v5, 
since it is quite a big update

> diff --git a/xen/xsm/dummy.c b/xen/xsm/dummy.c index 9774bb3bdb..0026a0963b
> 100644
> --- a/xen/xsm/dummy.c
> +++ b/xen/xsm/dummy.c
> @@ -80,11 +80,13 @@ static const struct xsm_ops __initconst_cf_clobber
> dummy_ops = {
>      .pci_config_permission         = xsm_pci_config_permission,
>      .get_vnumainfo                 = xsm_get_vnumainfo,
>
> -#if defined(CONFIG_HAS_PASSTHROUGH) && defined(CONFIG_HAS_PCI)
> +#if defined(CONFIG_HAS_PASSTHROUGH) &&
> defined(CONFIG_MGMT_HYPERCALLS)
> +#ifdef CONFIG_HAS_PCI
>      .get_device_group              = xsm_get_device_group,
>      .assign_device                 = xsm_assign_device,
>      .deassign_device               = xsm_deassign_device,
> -#endif

The same thing we shall do for XSM-changes too:
        .get_device_group              = IS_ENABLED(CONFIG_MGMT_HYPERCALLS)
                                                ? xsm_get_device_group
                                                : NULL,

Many thanks
Penny Zheng



 


Rackspace

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