From nobody Sat May 18 11:26:09 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1653944842; cv=none; d=zohomail.com; s=zohoarc; b=c0T8mAZLJRTKAIz4QwZVESUNlRkJ1ohq8csoS/mB6UaL+l6nhDqxdGYFhh8UkMeG+7fRDq7UFpCkvFOC0E0xVRwfT/ejhJQfkH2PTM/08CxaQsYzubYc1bjvsD0PbdaUJpi+N37pg9ewX+10CJdyOs1AdCvjQLNVyn06j6ceDY4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1653944842; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=yCj6CjDNcsvJy/tFMBx1tpvD/zYHLbLEZ8yli7AQ6SI=; b=DJahYSCJyt1PY7plkfA5MZ+zxzYPUlmTDSFGD2zo+2s7M+H/jIQU7ZfeC77wSGXpbIiq0Hgv0iJ2Xo5lrYoiow3X1pmH6sFN2+QkkemzM3zzIh0ElhBoN8lMdV/cwjk+e8I5EoTYAedu5BCNeVOXyI7PXdGuLMwynZ5sYz13QKU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 165394484281988.0308873945578; Mon, 30 May 2022 14:07:22 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.338822.563650 (Exim 4.92) (envelope-from ) id 1nvmbJ-0004Mj-Tx; Mon, 30 May 2022 21:06:57 +0000 Received: by outflank-mailman (output) from mailman id 338822.563650; Mon, 30 May 2022 21:06:57 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nvmbJ-0004Mc-QR; Mon, 30 May 2022 21:06:57 +0000 Received: by outflank-mailman (input) for mailman id 338822; Mon, 30 May 2022 21:06:57 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nvmbJ-0004MW-41 for xen-devel@lists.xenproject.org; Mon, 30 May 2022 21:06:57 +0000 Received: from mail-lj1-x232.google.com (mail-lj1-x232.google.com [2a00:1450:4864:20::232]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 6fca2476-e05c-11ec-837f-e5687231ffcc; Mon, 30 May 2022 23:06:56 +0200 (CEST) Received: by mail-lj1-x232.google.com with SMTP id a23so12738371ljd.9 for ; Mon, 30 May 2022 14:06:55 -0700 (PDT) Received: from otyshchenko.router ([212.22.223.21]) by smtp.gmail.com with ESMTPSA id h1-20020a056512220100b0047255d211b2sm2508931lfu.225.2022.05.30.14.06.54 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 30 May 2022 14:06:54 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 6fca2476-e05c-11ec-837f-e5687231ffcc DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=yCj6CjDNcsvJy/tFMBx1tpvD/zYHLbLEZ8yli7AQ6SI=; b=IKxzkKOU44sZ/QR6lYJIszLKZPgyf3YMlXOaWcR/JafuI31OSawpfxMqkMCZCxv9Vd QR96mdbSFUaQtpbKMHB7QoPI1CDBafFfQZ/sAV48A4DemTZRNsqkLmBIr4PN40PGeKPE nNg6pfLF7ejgYP4UcNWfY6fYIiQH82wh7FZPdjBOXINxdjKaR0Dpg7eUO5n+MLb9HkG8 /nJQeyphbRqYbLvZUCNQwWtY+ECLv5FTghobkNH//WMJYLFqnTRKHCxI7OtXIBq0o7rf 4Wg+9fBEjUdsdjDTSgLsObFn41dED6t6Aii2ChkYtg5prnmLCFhW92wvSOohw8VPyDYU Q5fQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=yCj6CjDNcsvJy/tFMBx1tpvD/zYHLbLEZ8yli7AQ6SI=; b=e7Hn/NoUTStuH38HdqGjb5mfl4aHZZWxn77Jb8/nA/2PZPo0sjTLTgqznh2fzptXVN V8TunhPgNzXzypzLk73fRSxufg+S0pgrxpEgKJj8QfB5nqB4cmsqTm13mRedBm9IwMS3 ePAFQGIr2yzSyO82SSL6f+XdEtSryDY+d7nwIphWYGbz7PD66pOc/6sV9DNVsW5Zk2Gp 1xHmOSJh+C52YjXtFg8DcKpRkCgdk0NGBeSO758B33qQcCeZMDw8hbVRVdeudSuUvg/4 mHQC9YUUg9IMEgwFhe7blV6vYg9EPqJq+cCPfL2ldMrIpRcVrzueDyAMMrYn2Jbuqd1C 1aXw== X-Gm-Message-State: AOAM531e7LAMH7m8ZJm+bG1qnKM0G6M8zjv4hzBUgzyCIehvhSR3LRlC pG3xhmLcs36Yp02rWCbNSCCDUSUXFMA= X-Google-Smtp-Source: ABdhPJwDqUfiK4FskpnJXVLIzTWuR2ZWMexcpjUyUOMUpDsPdBehARKygsXbdF+kzl31knxhY5H0yw== X-Received: by 2002:a2e:84c7:0:b0:24b:6842:1923 with SMTP id q7-20020a2e84c7000000b0024b68421923mr34895089ljh.166.1653944815285; Mon, 30 May 2022 14:06:55 -0700 (PDT) From: Oleksandr Tyshchenko To: xen-devel@lists.xenproject.org Cc: Oleksandr Tyshchenko , Wei Liu , Anthony PERARD , Juergen Gross , Andrew Cooper , George Dunlap , Jan Beulich , Julien Grall , Stefano Stabellini Subject: [PATCH V2] libxl/arm: Create specific IOMMU node to be referred by virtio-mmio device Date: Tue, 31 May 2022 00:06:53 +0300 Message-Id: <1653944813-17970-1-git-send-email-olekstysh@gmail.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1653944844651100001 From: Oleksandr Tyshchenko Reuse generic IOMMU device tree bindings to communicate Xen specific information for the virtio devices for which the restricted memory access using Xen grant mappings need to be enabled. Insert "iommus" property pointed to the IOMMU node with "xen,grant-dma" compatible to all virtio devices which backends are going to run in non-hardware domains (which are non-trusted by default). Based on device-tree binding from Linux: Documentation/devicetree/bindings/iommu/xen,grant-dma.yaml The example of generated nodes: xen_iommu { compatible =3D "xen,grant-dma"; #iommu-cells =3D <0x01>; phandle =3D <0xfde9>; }; virtio@2000000 { compatible =3D "virtio,mmio"; reg =3D <0x00 0x2000000 0x00 0x200>; interrupts =3D <0x00 0x01 0xf01>; interrupt-parent =3D <0xfde8>; dma-coherent; iommus =3D <0xfde9 0x01>; }; virtio@2000200 { compatible =3D "virtio,mmio"; reg =3D <0x00 0x2000200 0x00 0x200>; interrupts =3D <0x00 0x02 0xf01>; interrupt-parent =3D <0xfde8>; dma-coherent; iommus =3D <0xfde9 0x01>; }; Signed-off-by: Oleksandr Tyshchenko Reviewed-by: Stefano Stabellini --- !!! This patch is based on non upstreamed yet =E2=80=9CVirtio support for t= oolstack on Arm=E2=80=9D V8 series which is on review now: https://lore.kernel.org/xen-devel/1651598763-12162-1-git-send-email-oleksty= sh@gmail.com/ New device-tree binding (commit #5) is a part of solution to restrict memory access under Xen using xen-grant DMA-mapping layer (which is also on review= ): https://lore.kernel.org/xen-devel/1653944417-17168-1-git-send-email-oleksty= sh@gmail.com/ Changes RFC -> V1: - update commit description - rebase according to the recent changes to "libxl: Introduce basic virtio-mmio support on Arm" Changes V1 -> V2: - Henry already gave his Reviewed-by, I dropped it due to the changes - use generic IOMMU device tree bindings instead of custom property "xen,dev-domid" - change commit subject and description, was "libxl/arm: Insert "xen,dev-domid" property to virtio-mmio device node" --- tools/libs/light/libxl_arm.c | 49 +++++++++++++++++++++++++++++++= +--- xen/include/public/device_tree_defs.h | 1 + 2 files changed, 47 insertions(+), 3 deletions(-) diff --git a/tools/libs/light/libxl_arm.c b/tools/libs/light/libxl_arm.c index 9be9b2a..72da3b1 100644 --- a/tools/libs/light/libxl_arm.c +++ b/tools/libs/light/libxl_arm.c @@ -865,9 +865,32 @@ static int make_vpci_node(libxl__gc *gc, void *fdt, return 0; } =20 +static int make_xen_iommu_node(libxl__gc *gc, void *fdt) +{ + int res; + + /* See Linux Documentation/devicetree/bindings/iommu/xen,grant-dma.yam= l */ + res =3D fdt_begin_node(fdt, "xen_iommu"); + if (res) return res; + + res =3D fdt_property_compat(gc, fdt, 1, "xen,grant-dma"); + if (res) return res; + + res =3D fdt_property_cell(fdt, "#iommu-cells", 1); + if (res) return res; + + res =3D fdt_property_cell(fdt, "phandle", GUEST_PHANDLE_IOMMU); + if (res) return res; + + res =3D fdt_end_node(fdt); + if (res) return res; + + return 0; +} =20 static int make_virtio_mmio_node(libxl__gc *gc, void *fdt, - uint64_t base, uint32_t irq) + uint64_t base, uint32_t irq, + uint32_t backend_domid) { int res; gic_interrupt intr; @@ -890,6 +913,16 @@ static int make_virtio_mmio_node(libxl__gc *gc, void *= fdt, res =3D fdt_property(fdt, "dma-coherent", NULL, 0); if (res) return res; =20 + if (backend_domid !=3D LIBXL_TOOLSTACK_DOMID) { + uint32_t iommus_prop[2]; + + iommus_prop[0] =3D cpu_to_fdt32(GUEST_PHANDLE_IOMMU); + iommus_prop[1] =3D cpu_to_fdt32(backend_domid); + + res =3D fdt_property(fdt, "iommus", iommus_prop, sizeof(iommus_pro= p)); + if (res) return res; + } + res =3D fdt_end_node(fdt); if (res) return res; =20 @@ -1097,6 +1130,7 @@ static int libxl__prepare_dtb(libxl__gc *gc, libxl_do= main_config *d_config, size_t fdt_size =3D 0; int pfdt_size =3D 0; libxl_domain_build_info *const info =3D &d_config->b_info; + bool iommu_created; unsigned int i; =20 const libxl_version_info *vers; @@ -1204,11 +1238,20 @@ next_resize: if (d_config->num_pcidevs) FDT( make_vpci_node(gc, fdt, ainfo, dom) ); =20 + iommu_created =3D false; for (i =3D 0; i < d_config->num_disks; i++) { libxl_device_disk *disk =3D &d_config->disks[i]; =20 - if (disk->specification =3D=3D LIBXL_DISK_SPECIFICATION_VIRTIO) - FDT( make_virtio_mmio_node(gc, fdt, disk->base, disk->irq)= ); + if (disk->specification =3D=3D LIBXL_DISK_SPECIFICATION_VIRTIO= ) { + if (disk->backend_domid !=3D LIBXL_TOOLSTACK_DOMID && + !iommu_created) { + FDT( make_xen_iommu_node(gc, fdt) ); + iommu_created =3D true; + } + + FDT( make_virtio_mmio_node(gc, fdt, disk->base, disk->irq, + disk->backend_domid) ); + } } =20 if (pfdt) diff --git a/xen/include/public/device_tree_defs.h b/xen/include/public/dev= ice_tree_defs.h index 209d43d..df58944 100644 --- a/xen/include/public/device_tree_defs.h +++ b/xen/include/public/device_tree_defs.h @@ -7,6 +7,7 @@ * onwards. Reserve a high value for the GIC phandle. */ #define GUEST_PHANDLE_GIC (65000) +#define GUEST_PHANDLE_IOMMU (GUEST_PHANDLE_GIC + 1) =20 #define GUEST_ROOT_ADDRESS_CELLS 2 #define GUEST_ROOT_SIZE_CELLS 2 --=20 2.7.4