From patchwork Fri Sep 13 15:35:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksandr Tyshchenko X-Patchwork-Id: 11144935 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0BC4A17E6 for ; Fri, 13 Sep 2019 15:37:28 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id DBA3A20717 for ; Fri, 13 Sep 2019 15:37:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="JVdllyDJ" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DBA3A20717 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1i8nc9-0001z7-Kw; Fri, 13 Sep 2019 15:36:01 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1i8nc8-0001z2-Ku for xen-devel@lists.xenproject.org; Fri, 13 Sep 2019 15:36:00 +0000 X-Inumbo-ID: 2ecfa270-d63c-11e9-978d-bc764e2007e4 Received: from mail-lj1-x243.google.com (unknown [2a00:1450:4864:20::243]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 2ecfa270-d63c-11e9-978d-bc764e2007e4; Fri, 13 Sep 2019 15:35:59 +0000 (UTC) Received: by mail-lj1-x243.google.com with SMTP id 7so27503348ljw.7 for ; Fri, 13 Sep 2019 08:35:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=bHuCaD36TKPyrVOJfjKPoRbVZhnhsLQU0qO5xsHc7j8=; b=JVdllyDJSPMZjIQLLKIyodF2myjWxFiRE8NucgTmwTcyD8IF2W/bQEeLLtZJHZGtrq L474Mpw8ErCpdgVe4pxEU9F2NOdFBszyGqIyvjqtRxXfdOXeu+YEOS0Elc22Rz2YhjJS 6ZBGg3oYh3xbHN+hYJjpewVGV39SxYZLzbNx/xQGAy3yQ0dRiFD1fKblV1gc3MddSg3+ /8T5FYdFs76UAhnZfnmyfJ0lm8u3BSwzQBqfvcZSOVhx4XswYBnXGNtVYtpqfPpUPhAi oCctsjKISp243d1KutTMiSqR7eaeH2zaM4jb5cMkPtrAKeHwREsKdQU/IGA/pK6m1iDR Qivw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=bHuCaD36TKPyrVOJfjKPoRbVZhnhsLQU0qO5xsHc7j8=; b=Gsga4ZBNac0iEnKd7WZhwkpLihZiamB0FL02/Vz8nDzURPNefqpjaVpO50VsZBtWHH wLXw+S5+NE6CaE2/gjB+Ze3geK99EUuNwpk8PFhnX6FviOSXpzOrPTsxGMUBslVxOa8b us2nydoBfTA4+Ejt5qWQ5Jm93VbV+B4J6VAharsAPA7cd8gngxZZ4K2qjqoPXXIM8rSZ IUoxDj9fzpmaKNBxBN5OqlRgYFCGPtMezwm4NwKyOulPugdQobIrpXmpcZT65/4L0Qug 9SHmuoEiFBGtxdFREkup8gidBVmbHJhR/VBaFJ+b4IzNJ3JtTMX9Izinn980k8OUI3x5 /Caw== X-Gm-Message-State: APjAAAVEv0tELsf6BaCdBt1VHd3g6uYk2ws2nIrFPgdxiMRrH/dNl/rM jsvhM/f3kB9kW7tNponiyHHC+y8Xygk= X-Google-Smtp-Source: APXvYqxCXxZm6+fZ3v4FwxVLi3ey3st6ZWUKTKev2RhzOtF9AEyChF4vhgBUL3qAJAgo3u4Qoqj8bQ== X-Received: by 2002:a2e:2c01:: with SMTP id s1mr30545486ljs.113.1568388957672; Fri, 13 Sep 2019 08:35:57 -0700 (PDT) Received: from otyshchenko.kyiv.epam.com (ll-74.141.223.85.sovam.net.ua. [85.223.141.74]) by smtp.gmail.com with ESMTPSA id c16sm6969765lfj.8.2019.09.13.08.35.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 13 Sep 2019 08:35:57 -0700 (PDT) From: Oleksandr Tyshchenko To: xen-devel@lists.xenproject.org Date: Fri, 13 Sep 2019 18:35:09 +0300 Message-Id: <1568388917-7287-1-git-send-email-olekstysh@gmail.com> X-Mailer: git-send-email 2.7.4 Subject: [Xen-devel] [PATCH V4 0/8] iommu/arm: Add Renesas IPMMU-VMSA support + Linux's iommu_fwspec X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Oleksandr Tyshchenko , julien.grall@arm.com, sstabellini@kernel.org, Volodymyr_Babchuk@epam.com, Yoshihiro Shimoda MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" From: Oleksandr Tyshchenko The purpose of this patch series is to add IPMMU-VMSA support to Xen on ARM. Besides new IOMMU driver, this series contains "iommu_fwspec" support and new API iommu_add_dt_device() for adding DT device to IOMMU and many other things. The IPMMU-VMSA is VMSA-compatible I/O Memory Management Unit (IOMMU) which provides address translation and access protection functionalities to processing units and interconnect networks. Please note, this driver is supposed to work only with newest R-Car Gen3 SoCs revisions which IPMMU hardware supports stage 2 translation table format and is able to use CPU's P2M table as is if one is 3-level page table (up to 40 bit IPA). ---------- This driver is based on Linux's IPMMU-VMSA driver from Renesas BSP: https://git.kernel.org/pub/scm/linux/kernel/git/horms/renesas-bsp.git/tree/drivers/iommu/ipmmu-vmsa.c?h=v4.14.75-ltsi/rcar-3.9.6 and Xen's SMMU driver: xen/drivers/passthrough/arm/smmu.c Although Xen driver has a lot in common with Linux driver, it is not a "direct ported" copy and should be treated as such. The major differences compare to the Linux driver are: 1. Stage 1/Stage 2 translation. Linux driver supports Stage 1 translation only (with Stage 1 translation table format). It manages page table by itself. But Xen driver supports Stage 2 translation (with Stage 2 translation table format) to be able to share the P2M with the CPU. Stage 1 translation is always bypassed in Xen driver. So, Xen driver is supposed to be used with newest R-Car Gen3 SoC revisions only (H3 ES3.0, M3-W+, etc.) which IPMMU H/W supports stage 2 translation table format. 2. AArch64 support. Linux driver uses VMSAv8-32 mode, while Xen driver enables Armv8 VMSAv8-64 mode to cover up to 40 bit input address. 3. Context bank (sets of page table) usage. In Xen, each context bank is mapped to one Xen domain. So, all devices being pass throughed to the same Xen domain share the same context bank. 4. IPMMU device tracking. In Xen, all IPMMU devices are managed by single driver instance. So, driver uses global list to keep track of registered devices. ---------- Series was tested on R-Car Gen3 H3 ES3.0 based boards using current staging (948a4f6 sysctl/libxl: choose a sane default for HAP) in a system with several DMA masters being assigned to different guest domains. Guest domain reboot, destroy/create are functional. Please note, the series depends on Julien's patch (on review): https://lists.xenproject.org/archives/html/xen-devel/2019-08/msg01924.html You can find the whole series (+ Julien's patch) here: repo: https://github.com/otyshchenko1/xen.git branch: ipmmu_upstream4 You can find previous discussions here: [V1] https://lists.xenproject.org/archives/html/xen-devel/2019-06/msg01755.html [V2] https://lists.xenproject.org/archives/html/xen-devel/2019-08/msg00253.html [V3] https://lists.xenproject.org/archives/html/xen-devel/2019-08/msg01948.html Also, please note, there is a patch in ML which is intended to address the main TODO in the IPMMU-VMSA driver: https://lists.xenproject.org/archives/html/xen-devel/2019-09/msg00973.html Oleksandr Tyshchenko (8): iommu/arm: Add iommu_helpers.c file to keep common for IOMMUs stuff iommu/arm: Add ability to handle deferred probing request iommu/arm: Order the headers alphabetically in iommu.c xen/common: Introduce _xrealloc function xen/common: Introduce xrealloc_flex_struct() helper macros iommu/arm: Add lightweight iommu_fwspec support iommu/arm: Introduce iommu_add_dt_device API iommu/arm: Add Renesas IPMMU-VMSA support xen/arch/arm/domain_build.c | 12 + xen/arch/arm/platforms/Kconfig | 1 + xen/common/xmalloc_tlsf.c | 52 ++ xen/drivers/passthrough/Kconfig | 13 + xen/drivers/passthrough/arm/Makefile | 3 +- xen/drivers/passthrough/arm/iommu.c | 124 ++- xen/drivers/passthrough/arm/iommu_fwspec.c | 93 ++ xen/drivers/passthrough/arm/iommu_helpers.c | 84 ++ xen/drivers/passthrough/arm/ipmmu-vmsa.c | 1332 +++++++++++++++++++++++++++ xen/drivers/passthrough/arm/smmu.c | 48 +- xen/include/asm-arm/device.h | 7 +- xen/include/asm-arm/iommu.h | 21 + xen/include/asm-arm/iommu_fwspec.h | 68 ++ xen/include/xen/device_tree.h | 7 + xen/include/xen/iommu.h | 10 + xen/include/xen/xmalloc.h | 10 + 16 files changed, 1833 insertions(+), 52 deletions(-) create mode 100644 xen/drivers/passthrough/arm/iommu_fwspec.c create mode 100644 xen/drivers/passthrough/arm/iommu_helpers.c create mode 100644 xen/drivers/passthrough/arm/ipmmu-vmsa.c create mode 100644 xen/include/asm-arm/iommu_fwspec.h