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

Re: [RFC PATCH 21/21] xen/arm: vIOMMU: Modify the partial device tree for dom0less


  • To: Rahul Singh <rahul.singh@xxxxxxx>, <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Michal Orzel <michal.orzel@xxxxxxx>
  • Date: Fri, 2 Dec 2022 15:49:16 +0100
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=arm.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=G4pOKOEfP6FBR6fBVQNAbtjElKPPEKFpz84xFOABCAs=; b=Q9o5b4zh+LorPzNa2+/wsYOVXwe3ESpP0beHjfNsgKUkHsBk/a/5DQ6gYlaY1mHenGeOUHLIj1JEbBd3t5QlTtU4Cc7EyK8lPa4NRtRXB/efiixqURs19ZLZgCBr8dP3llf3w5WfT11ocOLGyJEo3/jTX0whroJ0mDtUzk2dZFZ20ysyqlWOD/erobt9kFrVnpFB+EoGoOrDgVLwaJYWxC2aiv0Nx/yNLayioPIEeUGqJ+rQbGumf0EFTWTwRKrPiVqxx1ZJzC4VeBjjC44dhlKLSIjQF/TYPZzrdR3+feu7A/thRfZpNHchWzqrG2pHI8xOEGdDbaIvczq4IuOBdQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=d2qjx4jsigROle6nYzX8UCqv2/ydHea0hJFz/cSdNdyuDgEpdl31rI1psAjUZ/am9VRuf3/wm3UVWtV4P9Sh/L89rTO+ER1QjcynRPSZ1tpxJgHReBjTLlgpxzzI1nH7pXp0yovPP4tvxwR5MHGCrDkuY0bvD3XcDDdj7piLrHXaCgm95V5VaU/HrHRaOrrW17MDICvw9B4gFYbye39myaqU04ArbWlO9kqjgWyjPVFapm/3MRFrDdIiNTPpjULn0RAWfVaI4+ubL5umkD+mEXBYOSDLdqVDip3TvfVCLmwx4d+oOKbW2seA9qX81h6Tb7gnkE3LO6vCimx7s13mAw==
  • Cc: Stefano Stabellini <sstabellini@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Bertrand Marquis <bertrand.marquis@xxxxxxx>, "Volodymyr Babchuk" <Volodymyr_Babchuk@xxxxxxxx>
  • Delivery-date: Fri, 02 Dec 2022 14:49:42 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

Hi Rahul,

On 01/12/2022 17:02, Rahul Singh wrote:
> 
> 
> To configure IOMMU in guest for passthrough devices, user will need to
> copy the unmodified "iommus" property from host device tree to partial
> device tree. To enable the dom0 linux kernel to confiure the IOMMU
> correctly replace the phandle in partial device tree with virtual
> IOMMU phandle when "iommus" property is set.
> 
> Signed-off-by: Rahul Singh <rahul.singh@xxxxxxx>
> ---
>  xen/arch/arm/domain_build.c | 31 ++++++++++++++++++++++++++++++-
>  1 file changed, 30 insertions(+), 1 deletion(-)
> 
> diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c
> index 7cd99a6771..afb3e76409 100644
> --- a/xen/arch/arm/domain_build.c
> +++ b/xen/arch/arm/domain_build.c
> @@ -3235,7 +3235,35 @@ static int __init handle_prop_pfdt(struct kernel_info 
> *kinfo,
>      return ( propoff != -FDT_ERR_NOTFOUND ) ? propoff : 0;
>  }
> 
> -static int __init scan_pfdt_node(struct kernel_info *kinfo, const void *pfdt,
> +static void modify_pfdt_node(void *pfdt, int nodeoff)
> +{
> +    int proplen, i, rc;
> +    const fdt32_t *prop;
> +    fdt32_t *prop_c;
> +
> +    prop = fdt_getprop(pfdt, nodeoff, "iommus", &proplen);
> +    if ( !prop )
> +        return;
> +
> +    prop_c = xzalloc_bytes(proplen);
> +
> +    for ( i = 0; i < proplen / 8; ++i )
> +    {
> +        prop_c[i * 2] = cpu_to_fdt32(GUEST_PHANDLE_VSMMUV3);
> +        prop_c[i * 2 + 1] = prop[i * 2 + 1];
> +    }
> +
> +    rc = fdt_setprop(pfdt, nodeoff, "iommus", prop_c, proplen);
> +    if ( rc )
> +    {
> +        dprintk(XENLOG_ERR, "Can't set the iommus property in partial FDT");
> +        return;
> +    }
> +
> +    return;
> +}
> +
> +static int __init scan_pfdt_node(struct kernel_info *kinfo, void *pfdt,
>                                   int nodeoff,
>                                   uint32_t address_cells, uint32_t size_cells,
>                                   bool scan_passthrough_prop)
> @@ -3261,6 +3289,7 @@ static int __init scan_pfdt_node(struct kernel_info 
> *kinfo, const void *pfdt,
>      node_next = fdt_first_subnode(pfdt, nodeoff);
>      while ( node_next > 0 )
>      {
> +        modify_pfdt_node(pfdt, node_next);
You do not protect this call in any way and there is no check inside it whether 
viommu is enabled or not.
This means that even with viommu disabled, if a user copies the iommus property 
to partial dtb
(which is understandable as the flow is to copy almost everything), you will 
perform the phandle replacement.
I do not think we should do that (no need for an extra code).

>          scan_pfdt_node(kinfo, pfdt, node_next, address_cells, size_cells,
>                         scan_passthrough_prop);
>          node_next = fdt_next_subnode(pfdt, node_next);
> --
> 2.25.1
> 
> 

~Michal




 


Rackspace

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